performance/Tutorial_MultiThreading.cpp

performance/Tutorial_MultiThreading.cpp
/*
* Copyright 2015 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"
//RUN_THIS_FILE
namespace
{
#define TEST_ENV_CLASS OneWorldEnv
TEST_ENV {}
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.");
CHECK(env.LoadAndAddNavData("GeneratedNavData/canyon/canyon_1m_zup.NavData") != KY_NULL);
Kaim::World* navWorld = env.GetWorld();
LabEngine::ScopedUseWorkerThread workerThread(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.
CHECK(query->IsSafeToReadResult() == true);
CHECK(query->GetResult() == Kaim::ASTAR_DONE_PATH_FOUND);
}
}