performance/Tutorial_NoTimeSlicing.cpp

performance/Tutorial_NoTimeSlicing.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"
//RUN_THIS_FILE
namespace
{
#define TEST_ENV_CLASS OneWorldEnv
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.
TUTORIAL
{
KT_LOG_TITLE_BEGIN("TUTORIAL - How to perform a single time-sliced query using the default queue of the world with no TimeSlicing");
CHECK(env.LoadAndAddNavData("GeneratedNavData/canyon/canyon_1m_zup.NavData") != KY_NULL);
Kaim::World* navWorld = env.GetWorld();
// 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.
CHECK(query->IsSafeToReadResult() == true);
CHECK(query->GetResult() == Kaim::ASTAR_DONE_PATH_FOUND);
}
TUTORIAL
{
KT_LOG_TITLE_BEGIN("TUTORIAL - How to perform a single time-sliced query without using any Queue.");
CHECK(env.LoadAndAddNavData("GeneratedNavData/canyon/canyon_1m_zup.NavData") != KY_NULL);
Kaim::World* navWorld = env.GetWorld();
// 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.
CHECK(query->IsSafeToReadResult() == true);
CHECK(query->GetResult() == Kaim::ASTAR_DONE_PATH_FOUND);
}
}