performance/Tutorial_MultiThreading.cpp

performance/Tutorial_MultiThreading.cpp
/*
* Copyright 2016 Autodesk, Inc. All rights reserved.
* Use of this software is subject to the terms of the Autodesk license agreement and any attachments or Appendices thereto provided at the time of installation or download,
* or which otherwise accompanies this software in either electronic or hard copy form, or which is signed by you and accepted by Autodesk.
*/
#include "common/oneworldenv.h"
#include "labengine/threading/workerthread.h"
namespace
{
#define KT_TEST_ENV_CLASS OneWorldEnv
KT_TEST_ENV {}
KT_TUTORIAL
{
KT_LOG_TITLE_BEGIN("TUTORIAL - How to perform a single time-sliced query using the default queue of the world with processing on a worker thread.");
KT_ASSERT(KT_ENV.AddNavData("generated/canyon/canyon.NavData") != nullptr);
Kaim::World* navWorld = KT_ENV.GetNavWorld();
LabEngine::ScopedUseWorkerThread workerThread(KT_ENV.GetGameWorld());
// Setup Query.
Kaim::Ptr< Kaim::AStarQuery<Kaim::DefaultTraverseLogic> > query = *KY_NEW Kaim::AStarQuery<Kaim::DefaultTraverseLogic>;
query->BindToDatabase(navWorld->GetDatabase(0));
query->Initialize(Kaim::Vec3f(-480.f,-480.f,-17.f), Kaim::Vec3f(-400.0f,270.f,-96.f));
// Push it to the world.
navWorld->PushAsyncQuery(query, Kaim::AsyncQueryDispatchId_PathFinder);
while (query->IsSafeToReadResult() == false)
{
navWorld->Update();
}
// Check results.
KT_ASSERT(query->IsSafeToReadResult() == true);
KT_ASSERT(query->GetResult() == Kaim::ASTAR_DONE_PATH_FOUND);
}
}