대부분의 게임 개발 프로젝트에는 게임 자산 패키징 및 런타임 시 필요할 때 메모리로 스트리밍을 처리하는 잘 개발된 파이프라인이 있습니다. 이와 같은 시스템이 있는 경우 텍스처 및 모델과 같은 동일한 섹터에서 사용되는 다른 유형의 게임 자산과 함께 쉽게 NavData를 패키지할 수 있습니다.
성공적으로 생성이 실행된 다음 아래 코드를 사용하여 원시 데이터로 각 섹터의 NavData에 액세스하여 unsigned int 8 또는 char 배열로 복사할 수 있습니다. 그런 다음 파이프라인에 부합하는 방법으로 이 원시 데이터를 패키지할 수 있습니다.
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;
}