performance/Tutorial_NoTimeSlicing.cpp

performance/Tutorial_NoTimeSlicing.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"
namespace
{
#define KT_TEST_ENV_CLASS OneWorldEnv
KT_TEST_ENV {}
// Sometimes you may wish to execute Queries with no timeslicing, in other words you want the queries to be executed in a single frame, even if this means a potential peak.
// Reasons for this might include debugging, or running in an environment where peaks are not so important. Or you may just need a result instantly.
// This Tutorial shows how you can do this easily with Navigation.
KT_TUTORIAL
{
KT_LOG_TITLE_BEGIN("TUTORIAL - How to perform a single time-sliced query using the default queue of the world with no TimeSlicing");
KT_ASSERT(KT_ENV.AddNavData("generated/canyon/canyon.NavData") != nullptr);
Kaim::World* navWorld = KT_ENV.GetNavWorld();
// 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));
// Set the queue to have NO timeslicing.
Kaim::QueryQueue* queryQueue = navWorld->GetAsyncQueryDispatcher()->GetQueue(query, Kaim::AsyncQueryDispatchId_PathFinder);
queryQueue->SetBudgetMs(KyFloat32MAXVAL);
// Push it to the world.
navWorld->PushAsyncQuery(query, Kaim::AsyncQueryDispatchId_PathFinder);
// We only need to call Update() once. Since there is not timeslicing, the query will be processed in one frame.
navWorld->Update();
// Check results.
KT_ASSERT(query->IsSafeToReadResult() == true);
KT_ASSERT(query->GetResult() == Kaim::ASTAR_DONE_PATH_FOUND);
}
KT_TUTORIAL
{
KT_LOG_TITLE_BEGIN("TUTORIAL - How to perform a single time-sliced query without using any Queue.");
KT_ASSERT(KT_ENV.AddNavData("generated/canyon/canyon.NavData") != nullptr);
Kaim::World* navWorld = KT_ENV.GetNavWorld();
// 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));
// Performs the Query with the database and it's default WorkingMemory.
query->PerformQueryBlocking();
// Check results.
KT_ASSERT(query->IsSafeToReadResult() == true);
KT_ASSERT(query->GetResult() == Kaim::ASTAR_DONE_PATH_FOUND);
}
}