Hi!
I made a script to generate a box world.
I give it an 3D array, and then all it does is:
[java]for (each block){
for (all sides of the block) {
check if there is a block next to current face by checking the 3D int array.
If not, then create a 3d face.
}
}[/java]
Problem is, it can’t handle arrays bigger than 553 (takes about 2-3 seconds) or else it will take more exponentially more time!
Even tho it does the SAME thing for everyblock, the more block it makes, the more time it takes to process 1 block!
Using a 27274 map:
First block 100 blocks takes about 60 micro seconds. But after going throw 2 or 3 layers the time is all the way up to half a second PER BLOCK!
What is wrong?!
Am I running out of jme3’s java memory?
I meen, nothing in the ekvation is difficult really. As you’v seen, all I do is check for neighbour blocks using an array, nothing complex!
Still, it takes such ridicules much time. Why does it do this to me? ;(
Something is wrong. Mythruna uses basically that algorithm on sections 32x32x32 and generates them in fractions of a second.
You should do some timing or profiling to see where the time goes. Is it in that nested loop or when merging into the batch?
Using this method on a maximum of 6 faces (but in moste cases only 2-3 times):
[java]private static void createFace(Vector3f position, Mesh mesh, String texture){
Geometry geo = new Geometry ("ColoredMesh", mesh);
Material matVC = Texture(texture+".png");
geo.setMaterial(matVC);
geo.setLocalTranslation(position);
MainGame.getRoot().attachChild(geo);
}
private static Material getLight(String name){
Material mat = new Material(MainGame.getAsset(),"Common/MatDefs/Light/Lighting.j3md");
mat.setTransparent(true);
mat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
Texture img = ImageLoader.Load(name);
//img.setWrap(WrapMode.Repeat);
img.setMagFilter(Texture.MagFilter.Nearest);
img.setMinFilter(Texture.MinFilter.NearestNearestMipMap);
mat.setTexture("DiffuseMap", img);
String nor = name.substring(0,name.length()-4)+"Normal"+name.substring(name.length()-4);
Texture normal = ImageLoader.Load(nor);
if (normal != null){
System.out.println("–>—>--->—");
normal.setWrap(WrapMode.Repeat);
mat.setTexture("m_NormalMap", normal);
}
mat.setBoolean("m_UseMaterialColors", true);
mat.setColor("m_Ambient", ColorRGBA.White);
mat.setColor("m_Diffuse", ColorRGBA.Gray);
mat.setColor("m_Specular", ColorRGBA.White);
mat.setFloat("m_Shininess", 1);
return mat;
}
[/java]
Takes approx 0,3 seconds.
But WAIT! I think I might see the problem! I load the images everytime I need a texture!
If I instead create a libary of the images then i would not have to load it all the time…
Humm… Could I instead create a libary of the materials? or do I need separate materials for separate faces?
YEEES!!
INCREDIBLE!! That worked!!
Now it load the whole stage in matter of micro seconds!!
EPIC!!!
Thanks SO MUCH for the brainwave pspeed!
The forum is blessed to have you here
Aw, shucks. Thanks.
And yeah, an index of materials is the way Mythruna does it too.