多くのゲーム開発プロジェクトには、ゲーム アセットをパッケージ化したり、実行時に必要になったときにこれらのゲーム アセットをメモリにストリーミングするための十分に開発されたパイプラインがあります。このようなシステムを導入している場合、同じセクタで使用される他のタイプのゲーム アセット(テクスチャ、モデルなど)と一緒にNavData を簡単にパッケージ化することができます。
生成が正常に実行されると、以下のコードを使用して、Raw データとして各セクタの NavData にアクセスし、unsigned int 8 または char の配列にコピーできます。その後、使用しているパイプラインに適した方法で、この Raw データをパッケージ化することができます
bool Generate()
{
...
// Launch the generation process using the configuration we set up.
if (Kaim::Result::Fail(generator.Generate(generatorInputOutput)))
{
return false;
}
// Get a GeneratorSector object for each sector.
// (we only generated one sector)
Kaim::GeneratorSector* generatorSector =
generatorInputOutput.GetSectorWithIndex(0);
// Get the NavData.
Kaim::NavData* pathDataPtr = generatorSector->GetNavData();
// Access the blob aggregate and retrieve its size.
Kaim::BlobAggregate& aggregate = *pathDataPtr->m_blobAggregate;
KyUInt32 aggregateSize = aggregate.ComputeByteSize();
// Allocate your own array.
char* myArray = new char[aggregateSize];
// Copy the NavData there.
aggregate.SaveToMemory(myArray);
// Embed your copy into your own actor, an entity, or into your system.
myLevel.m_navDataBlob = myArray;
return true;
}セクタの NavData が含まれているデータのブロックを実行時にメモリにロードすると、NavData::LoadFromMemory() を呼び出してバッファを渡すことで、このデータのブロックを使用して NavData オブジェクトを設定できます。
class MyGameLevel
{
public:
bool Initialize(Kaim::World* world);
protected:
Kaim::Ptr<Kaim::NavData> m_navData;
char* m_navDataBlob;
};
bool MyGameLevel::Initialize(Kaim::World* world)
{
// Instantiate and load the NavData from the buffer array
m_navData = *KY_NEW Kaim::NavData;
KyResult loadingResult = KY_ERROR;
loadingResult = m_navData->LoadFromMemory(m_navDataBlob);
// Check that the NavData have been correctly loaded
if (KY_FAILED(loadingResult))
return false;
// Add the NavData to the database
m_navData->Init(world->GetDatabase(0));
m_navData->AddToDatabaseImmediate();
return true;
}