Tutorial_QueryQueue.cpp

Tutorial_QueryQueue.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 {}
KT_TUTORIAL
{
KT_LOG_TITLE_BEGIN("TUTORIAL - How to perform a single atomic query using the default queue of the world");
KT_ASSERT(KT_ENV.AddNavData("generated/plane200x200_80ktri/plane200x200_80ktri.NavData") != nullptr);
Kaim::World* navWorld = KT_ENV.GetNavWorld();
// Setup Query.
Kaim::Ptr<Kaim::RayCanGoQuery<Kaim::DefaultTraverseLogic> > query = *KY_NEW Kaim::RayCanGoQuery<Kaim::DefaultTraverseLogic>;
query->BindToDatabase(navWorld->GetDatabase(0));
query->Initialize(Kaim::Vec3f(0.f,0.f,0.f), Kaim::Vec3f(1.0f,0.f,0.f));
// Push it to the world.
navWorld->PushAsyncQuery(query);
// Note that no work will occur if we do not call World::Update.
navWorld->Update();
// Query is atomic, therefore should have been performed and finished.
KT_ASSERT(query->IsSafeToReadResult() == true);
KT_ASSERT(query->GetResult() == Kaim::RAYCANGO_DONE_SUCCESS);
}
KT_TUTORIAL
{
KT_LOG_TITLE_BEGIN("TUTORIAL - How to perform a single time-sliced query using the default queue of the world");
KT_ASSERT(KT_ENV.AddNavData("generated/plane200x200_80ktri/plane200x200_80ktri.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(0.f,0.f,0.f), Kaim::Vec3f(1.0f,0.f,0.f));
// Push it to the world.
navWorld->PushAsyncQuery(query);
// Note that no work will occur if we do not call World::Update. This is a time-sliced query so may take several Updates to complete.
while (query->IsSafeToReadResult() == false)
{
navWorld->Update();
}
KT_ASSERT(query->GetResult() == Kaim::ASTAR_DONE_PATH_FOUND);
}
KT_TUTORIAL
{
KT_LOG_TITLE_BEGIN("TUTORIAL - How to perform a single time-sliced query using the default queue of the world");
KT_ASSERT(KT_ENV.AddNavData("generated/plane200x200_80ktri/plane200x200_80ktri.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(0.f,0.f,0.f), Kaim::Vec3f(1.0f,0.f,0.f));
// Push it to the world.
navWorld->PushAsyncQuery(query);
// Note that no work will occur if we do not call World::Update. This is a time-sliced query so may take several Updates to complete.
while (query->IsSafeToReadResult() == false)
{
navWorld->Update();
}
KT_ASSERT(query->GetResult() == Kaim::ASTAR_DONE_PATH_FOUND);
}
}