vibe3d
25-08-2007 17:00:44
Hey guys
I thought i would post a significant speed increase fix for some code i found on these forums that uses the TerrainPageSourceListener::pageConstructed to create the collision tree. Here are the results(using a heightmap 512x512):
Original Way
Build Time:45 seconds
Max Memory: 227,000K
Finished Memory: 80,000k
Faster Way
Build Time: 11
Max Memory: 110,000K
Finished Memory: 80,000k
The original code can be found here http://www.ogre3d.org/phpBB2addons/viewtopic.php?t=1819&start=40
here is the small fix to decrease the loading time and max memory usage
i don't think it needs too much explaining as you can easily see what i am doing here, instead of creating 1 huge collision tree we are creating multiple smaller one's, which is not only faster but cut's the max mem usage in half (note the max memory is only the peak memory you get when building the collision tree, after that they both return the exact same amount)
hopefully someone finds it usefull
I thought i would post a significant speed increase fix for some code i found on these forums that uses the TerrainPageSourceListener::pageConstructed to create the collision tree. Here are the results(using a heightmap 512x512):
Original Way
Build Time:45 seconds
Max Memory: 227,000K
Finished Memory: 80,000k
Faster Way
Build Time: 11
Max Memory: 110,000K
Finished Memory: 80,000k
The original code can be found here http://www.ogre3d.org/phpBB2addons/viewtopic.php?t=1819&start=40
here is the small fix to decrease the loading time and max memory usage
const bool optimize = false;
int polyId = 0;
for (int z = 0; z < manager->getPageSize()-1; z++)
{
OgreNewt::CollisionPrimitives::TreeCollision terrainCollision(world_);
terrainCollision.start();
for (int x = 0; x < manager->getPageSize()-1; x++)
{
Vector3 va[3];
va[0] = terrainCalc.v(x , z );
va[1] = terrainCalc.v(x , z+1);
va[2] = terrainCalc.v(x+1, z );
terrainCollision.addPoly(va, polyId++);
va[0] = terrainCalc.v(x+1, z );
va[1] = terrainCalc.v(x , z+1);
va[2] = terrainCalc.v(x+1, z+1);
terrainCollision.addPoly(va, polyId++);
}
terrainCollision.finish(optimize);
new OgreNewt::Body(world_, &terrainCollision);
}
i don't think it needs too much explaining as you can easily see what i am doing here, instead of creating 1 huge collision tree we are creating multiple smaller one's, which is not only faster but cut's the max mem usage in half (note the max memory is only the peak memory you get when building the collision tree, after that they both return the exact same amount)
hopefully someone finds it usefull