This is how the scene is started.
Code:
mWorldManager = new WorldManager(mKeyDevices);
mWorldManager->initialize(4);
mWorldManager->createTestWorld();
The constructor stores the devices pointer and creates the second thread class.
Code:
WorldManager(device_info pSystem)
{
mSystemDevices = pSystem;
mDecimator = new MeshManager(pSystem, mWorldVoxels);
}
The constructor for the thread class takes a pointer to the unitialized world. This could be a problem, but I thought the pointer would contain the address and when the world is initialized this pointer would be pointing to the initialized value.
Code:
MeshManager::MeshManager(device_info pSystem, LargeVolume<MaterialDensityPair44>*& pWorldVoxels, list<string>* pMeshPool)
{
mSystemDevices = pSystem;
programStop = false;
mWorldVoxels = pWorldVoxels;
mMeshPool = pMeshPool;
}
Then Initialize is called. This sets some test values, binds the paging functions, initializes the LargeVolume, and then starts the second thread. At this point I expect the pointer in the thread to be pointing to this now initialized LargeVolume.
Code:
void WorldManager::initialize(int worldSize)
{
//Currently does not load player location from disc
mPlayerLocation.x = 5;
mPlayerLocation.y = 30;
mPlayerLocation.z = 5;
mViewSize = worldSize;
mSystemDevices.mSceneMgr->getCamera("FirstPerson")->setPosition(mPlayerLocation);
oldCameraPosition.x = 0;
oldCameraPosition.y = 0;
oldCameraPosition.z = 0;
//These functions are used by PolyVox for paging. Need to be bound to avoid object issues.
boost::function<void (const ConstVolumeProxy<MaterialDensityPair44>&, const Region&)> polySaver (boost::bind( &WorldManager::saveChunk, this, _1, _2 ));
boost::function<void (const ConstVolumeProxy<MaterialDensityPair44>&, const Region&)> polyLoader (boost::bind( &WorldManager::loadChunk, this, _1, _2 ));
mWorldVoxels = new LargeVolume<MaterialDensityPair44>(polyLoader,polySaver,32);
//Start Decimator Thread
boost::thread mMeshManager(*mDecimator);
}
Lastly the create world function is called. This is why I have some areas loaded. As I have not finished the extractor thread I have left the test code in for building the initial area. It calls a function that extracts an area and creates a manual object from it. I am moving this functionality to the thread once it is working, but I have left this here as it is stable and helps testing. My load function is called when generating these pieces of terrain.
Code:
void WorldManager::createTestWorld()
{
//Create a world of 5 blocks for testing purposes
createManObj(*(new Region(*(new Vector3DInt32(0,0,0)), *(new Vector3DInt32(32,31,32)))), "0x0y0z");
meshPool.push_back("0x0y0z");
createManObj(*(new Region(*(new Vector3DInt32(0,0,-32)), *(new Vector3DInt32(32,31,0)))), "0x0y-1z");
meshPool.push_back("0x0y-1z");
createManObj(*(new Region(*(new Vector3DInt32(31,0,0)), *(new Vector3DInt32(64,31,32)))), "1x0y0z");
meshPool.push_back("1x0y0z");
createManObj(*(new Region(*(new Vector3DInt32(-32,0,0)), *(new Vector3DInt32(0,31,32)))), "-1x0y0z");
meshPool.push_back("-1x0y0z");
createManObj(*(new Region(*(new Vector3DInt32(0,0,31)), *(new Vector3DInt32(32,31,64)))), "0x0y1z");
meshPool.push_back("0x0y1z");
}
the createManObj function they are calling is what I based the code in my thread off of. It shouldn't be any different. I can post it if someone thinks it would help.
I hope this answered all the questions. Could this be related to my initialization?, or did I pass the pointer incorrectly? I thought I used this pattern successfully before, but perhaps not.
I'm at a loss as to whats wrong. The code looks good (to me) in theory. If this ends up having nothing to do with Polyvox I'm sorry, but I'm trying to rule out ignorance of some LargeVolume aspect.