Sharing NavData between Multiple Worlds
If your game uses multiple simultaneous Worlds that need to load the same terrain, such as an MMO game with multiple independent
servers or rooms, you can conserve memory by setting up all of your Worlds to share the same static pre-generated NavData.
However, each NavData object that you create can only be added to a single Database within a single World. To share the same NavData between multiple Worlds, you must therefore create one
NavData object for each World, and set up each of those NavData objects to use the same raw data.
To access the raw data:
- If you load your NavData from files, you can get a pointer to the raw data from the
NavData::m_blobAggregate class member of a NavData object. Retrieve this member after you load the data from a .NavData file.
- If you load your NavData from raw data that you package in your own asset management
system (as shown under Integration Phase 6a: Integrating NavData into your Asset Pipeline), you already obtained the raw data from the NavData::m_blobAggregate member during your data generation process. You should already have a pointer to
the raw data you need.
To set up each NavData instance, pass the raw data buffer in a call to NavData::LoadFromMemory():
for(KyUInt32 worldIdx = 0; worldIdx < worldCount; worldIdx++) // for each World
{
Kaim::Ptr<Kaim::NavData> navData = *KY_NEW Kaim::NavData;
navData->LoadFromMemory(myDataBuffer);
... // Add your NavData in the World with index worldIdx
}
NOTE:Any changes that you make to the NavData maintained by a single
Database at runtime during your game, such as adding TagVolumes or NavGraphs, happen locally
within that
Database. The static, pre-generated data that is being shared with the other worlds is not
affected.
NOTE:If you choose to use this approach, you must make sure that the raw data remains in
memory as long as it is used by any
World. Do not release the raw data from memory until you have removed it from all
Databases.