#include "GwNavTestFwk/GwNavTestFwk.h"
#include "common/basesystemenv.h"
#include "LabEngine/gameworld.h"
#if !defined (KY_OS_WIN32) && !defined(KY_OS_LINUX) && !defined(KY_OS_MAC)
DONT_RUN_THIS_FILE
#endif
namespace
{
class MultiWorldThread : public Kaim::Thread
{
public:
explicit MultiWorldThread(
const Kaim::KyArray<Kaim::Ptr<Kaim::BlobAggregate> > sharedMemoryNavData)
: m_numWorlds(5)
, m_numBots(10)
, m_secondsToUpdate(2)
, m_sharedMemoryNavData(sharedMemoryNavData) {}
virtual int Run()
{
const KyUInt32 navDataCount = m_sharedMemoryNavData.
GetCount();
navDataLoadedStatus.
Resize(m_numWorlds * navDataCount);
navDatas.
Resize(m_numWorlds * navDataCount);
for (
KyUInt32 worldIndex = 0; worldIndex < m_numWorlds; ++worldIndex)
{
worlds.
PushBack(*KY_NEW LabEngine::GameWorld);
worlds.
Back()->Initialize(1, LabEngine::WorkerThreadDeactivated);
for (
KyUInt32 navDataIndex = 0; navDataIndex < m_sharedMemoryNavData.GetCount(); ++navDataIndex)
{
worlds.Back()->AddToDatabase(navData);
navDatas[worldIndex*navDataCount + navDataIndex] = navData;
navDataLoadedStatus[worldIndex*navDataCount + navDataIndex] = true;
}
while ((database->
IsThereNavDataToBeAddedOrRemoved() ==
true || database->
IsDatabaseUpdatingNavData() ==
true))
worlds.Back()->Update(0.016f);
if (m_numBots > 0)
{
LabEngine::GameBotInitConfig config;
config.m_botInitConfig.m_database = worlds.Back()->GetWorld()->GetDatabase(0);
worlds.Back()->AddRandomBots(m_numBots, config);
}
}
while (profiler.
GetSeconds() < m_secondsToUpdate)
{
for (
KyUInt32 worldIndex = 0; worldIndex < worlds.
GetCount(); worldIndex++)
worlds[worldIndex]->Update(0.0166f);
}
return 0;
}
private:
};
class AsyncMultiWordTutorialEnv : public BaseSystemEnv
{
bool LoadNavData(
const std::string& rootFolder,
const std::string& indexFileName,
Kaim::KyArray<Kaim::Ptr<Kaim::BlobAggregate> >& navDataLoaded)
{
Kaim::Ptr< Kaim::BlobHandler<Kaim::NavDataIndex> > navDataIndexHandler = Kaim::NavDataIndexLoader::LoadNavDataIndex(
GetAbsoluteInputFileName(rootFolder + indexFileName).c_str(), &m_fileOpener);
if (navDataIndexHandler ==
KY_NULL)
return false;
Kaim::NavDataIndex* navDataIndex = navDataIndexHandler->Blob();
return false;
for (
KyUInt32 i = 0; i < navDataIndex->GetDescriptorsCount(); ++i)
{
navDataLoaded.PushBack(*KY_NEW Kaim::BlobAggregate);
const std::string sectorFileName(navDataIndex->GetDescriptor(i).m_fileName.GetValues());
if (
Kaim::Result::Fail(navDataLoaded[i]->Load(GetAbsoluteInputFileName(rootFolder + sectorFileName).c_str(), &m_fileOpener)))
{
navDataLoaded.Clear();
return false;
}
}
return true;
}
public:
bool Run()
{
KT_LOG_TITLE_BEGIN("TUTORIAL - AsyncMultiWorld");
const std::string rootFolder("GeneratedNavData/city_9SectorsAndSeeds/");
const std::string indexFileName("city_9SectorsAndSeeds.GenIO");
if (!LoadNavData(rootFolder, indexFileName, loadedNavData))
return false;
for(
KyUInt32 i = 0; i < numThreads; ++i)
{
threadHandles.
PushBack( *KY_NEW MultiWorldThread(loadedNavData) );
threadHandles[i]->Start();
}
for(
KyUInt32 i = 0; i < numThreads; ++i)
{
threadHandles[i]->Wait();
}
return true;
}
};
#define TEST_ENV_CLASS AsyncMultiWordTutorialEnv
TEST_ENV {}
TEST
{
CHECK( env.Run() );
}
}