www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: araghavan on February 26, 2013, 04:19:41 pm

Title: Problem with fps in a randomized 3d world
Post by: araghavan on February 26, 2013, 04:19:41 pm
I'm having trouble finding the best way to create my world. Right now, I created a random 2-D map generator which outputs a bunch of rooms. When I start the game, I create a NxM floor of cubes from primitives, then from there wherever there's a wall shown in my 2D map, I add a few blocks at that position above the floor to gain some height.

It's creating the world fine, and I can navigate it... except that its giving me very few FPS. I'm using cubes of size five, and a 20x20 base 2D map:

Code: [Select]
/*Load World Map Floor*/
for (int row = 0; row < r.length; row++)
for (int col = 0; col < r[0].length; col++)
{
worldMap[row][col][0] = block.cloneObject();
}

MemoryHelper.compact();
boolean player_location_set = false;
//Load rest of map
for (int h = 1; h < 3; h++)
for (int row = 0; row < r.length; row++)
for (int col = 0; col < r[0].length; col++)
{
if (r[row][col] == RoomData.WALL || r[row][col] == RoomData.PERMWALL){

worldMap[row][col][h] = block.cloneObject();

}
if (r[row][col] == RoomData.ENTRANCE && player_location_set == false){
player_location_set = true;
initial_player_position = new SimpleVector(row * 10, h * 10 + 5, col * 10);
}
}

^Here is how I am creating my map. In the onSurfaceChanged function, I have:

Code: [Select]
for (int h = 0; h < worldMap[0][0].length; h++)
for (int row = 0; row < worldMap.length; row++)
for (int col = 0; col < worldMap[0].length; col++)
{
//If there is a block
if (worldMap[row][col][h] != null){
block = worldMap[row][col][h];
block.translate(SimpleVector.create(row * 10, h * 10 + 5, col * 10));
block.rotateY((float) (Math.PI/4));
block.setCollisionMode(Object3D.COLLISION_CHECK_OTHERS);
block.build();
block.strip();
world.addObject(block);
}
}

world.buildAllObjects();
MemoryHelper.compact();

Any advice on how I should go about this? I can't really pre-create the world because it's randomized

Thanks
Title: Re: Problem with fps in a randomized 3d world
Post by: EgonOlsen on February 26, 2013, 08:11:22 pm
Many (visible) objects in a scene cause an overhead because they require at least as many draw calls as there are objects. How many objects are you using? There are several solutions to this:

Title: Re: Problem with fps in a randomized 3d world
Post by: araghavan on February 26, 2013, 09:35:36 pm
Right, that makes a lot of sense. With this method I'm probably creating over 100 cubes...

A combination of using full walls and merging objects will hopefully smooth things out

Thanks