#include "common/oneworldenv.h"
#include "testfwk/System.h"
#include "labengine/commands/textualcommandreceiver.h"
#include "labengine/commands/commands.h"
#include "labengine/base/kaimfileopener.h"
namespace
{
#define KT_TEST_ENV_CLASS OneWorldEnv
KT_TEST_ENV {}
class ExitCommandProcessor : public LabEngine::ICommandProcessor
{
public:
ExitCommandProcessor() : m_doExit(false) {}
virtual void Process(const LabEngine::CommandInstance&) { m_doExit = true; }
public:
bool m_doExit;
};
KT_TUTORIAL
{
KT_LOG_TITLE_BEGIN("TUTORIAL - Visual Debug a world");
#if defined(KY_CONFIG_DEBUG_OR_DEV)
KT_ASSERT(KT_ENV.AddNavData("generated/plane200x200_80ktri/plane200x200_80ktri.NavData") != nullptr);
KT_ASSERT(KT_ENV.AddRandomBots(1) == 1);
KyUInt32 serverPort = Kaim::VisualDebugServerConfig::DefaultServerPort();
KyUInt32 broadcastPort = Kaim::VisualDebugServerConfig::DefaultBroadcastPort();
KyResult startResult = navWorld->StartVisualDebug(visualDebugServerConfig);
{
TestLog() << "Failed to start visual debug\n";
KT_ASSERT(false);
}
navWorld->GetVisualDebugServer()->WaitWhileEstablishingConnection(1);
for (
KyUInt32 gameFrame = 0; gameFrame < 10; ++gameFrame)
{
navWorld->NewVisualDebugFrame();
navWorld->Update();
}
navWorld->StopVisualDebug();
#endif
KT_ENV.CleanUpWorld();
}
KT_TUTORIAL
{
KT_LOG_TITLE_BEGIN("TUTORIAL - Send custom information through Kaim::VisualDebugServer");
#if defined(KY_CONFIG_DEBUG_OR_DEV)
KT_ASSERT(KT_ENV.AddNavData("generated/plane200x200_80ktri/plane200x200_80ktri.NavData") != nullptr);
KT_ASSERT(KT_ENV.AddRandomBots(1) == 1);
LabEngine::GameBot* gameBot = KT_ENV.GetGameWorld()->GetBots()[0];
KyUInt32 serverPort = Kaim::VisualDebugServerConfig::DefaultServerPort();
KyUInt32 broadcastPort = Kaim::VisualDebugServerConfig::DefaultBroadcastPort();
{
TestLog() << "Failed to start visual debug\n";
KT_ASSERT(false);
}
Kaim::VisualDebugServer* visualDebugServer = navWorld->
GetVisualDebugServer();
const char* tutroialCategoryName = "Tutorial_World";
for (
KyUInt32 gameFrame = 0; gameFrame < 10; ++gameFrame)
{
visualDebugServer->NewFrame();
if (visualDebugServer->IsReadyToSend() == false)
continue;
visualDebugServer->SendUInt32("GameFrame", gameFrame, tutroialCategoryName);
visualDebugServer->SendStats(gameStats, tutroialCategoryName);
{
displayList.PushLine(gameBot->GetPosition(),
Kaim::Vec3f::Zero(), Kaim::Color::White);
}
{
Kaim::Vec3f destination = gameBot->GetRoute().GetCurrentWayPoint();
displayList.PushPoint(destination, displayRadius, Kaim::Color::Yellow);
displayList.PushArrowTube(gameBot->GetPosition(), destination, displayRadius, Kaim::ShapeColor::FillAndLine(Kaim::Color::Magenta));
displayList.PushText(destination +
Kaim::Vec3f::UnitZ(),Kaim::Color::Magenta,
"Destination");
}
}
#endif
KT_ENV.CleanUpWorld();
}
KT_TUTORIAL
{
KT_LOG_TITLE_BEGIN("TUTORIAL - Send a DisplayList once, but keep it alive several frames in the NavigationLab");
#if defined(KY_CONFIG_DEBUG_OR_DEV)
KyUInt32 serverPort = Kaim::VisualDebugServerConfig::DefaultServerPort();
KyUInt32 broadcastPort = Kaim::VisualDebugServerConfig::DefaultBroadcastPort();
visualDebugServerConfig.SetWaitOnStart(waitOnStart);
{
TestLog() << "Failed to start visual debug\n";
KT_ASSERT(false);
}
const char* tutorialCategoryName = "Tutorial_World";
for (
KyUInt32 gameFrame = 0; gameFrame < 1000; ++gameFrame)
{
navWorld->
NewVisualDebugFrame();
if (navWorld->GetVisualDebugServer()->IsReadyToSend())
{
if (gameFrame == 4)
{
displayListId = displayList.
InitUserControlledLifespan(
"UserControlledLifespan", tutorialCategoryName, displayListId);
}
else if (gameFrame == 8)
{
displayListId = displayList.InitUserControlledLifespan("UserControlledLifespan", tutorialCategoryName, displayListId);
displayList.PushText(
Kaim::Vec3f::Zero(), Kaim::Color::Red,
"Changed at frame 8, will be removed at frame 16");
}
else if (gameFrame == 16)
{
}
else if (gameFrame == 20)
{
displayList.InitUserControlledLifespan("UserControlledLifespanNoId", tutorialCategoryName);
displayList.PushText(
Kaim::Vec3f::Zero(), Kaim::Color::Red,
"Sent without Id at frame 20.");
}
else if (gameFrame == 24)
{
displayList.InitUserControlledLifespan("UserControlledLifespanNoId", tutorialCategoryName);
displayList.PushText(
Kaim::Vec3f::Zero(), Kaim::Color::Red,
"Updated at frame 24, will be removed at frame 30");
}
else if (gameFrame == 30)
{
}
}
}
#endif
KT_ENV.CleanUpWorld();
}
KT_TUTORIAL
{
KT_LOG_TITLE_BEGIN("TUTORIAL - Use Kaim::VisualDebugServer for testing");
#if defined(KY_CONFIG_DEBUG_OR_DEV)
KT_ASSERT(KT_ENV.AddNavData("generated/plane200x200_80ktri/plane200x200_80ktri.NavData") != nullptr);
KT_ASSERT(KT_ENV.AddRandomBots(1) == 1);
std::string filename = KT_ENV.GetAbsoluteOutputFileName("UsefulForAutomatedTesing.VisualDebug");
visualDebugServerConfig.
UseLocalFile(filename.c_str(), &fileOpener);
KyResult startResult = navWorld->StartVisualDebug(visualDebugServerConfig);
{
TestLog() << "==== Failed to start visual debug through file: " << filename.c_str() << " ====\n";
KT_ASSERT(false);
}
for (
KyUInt32 gameFrame = 0; gameFrame < 10; ++gameFrame)
{
navWorld->NewVisualDebugFrame();
KT_ENV.Update();
}
#endif
KT_ENV.CleanUpWorld();
}
KT_TUTORIAL
{
KT_LOG_TITLE_BEGIN("TUTORIAL - Custom messages reception in Kaim::VisualDebugServer");
#if defined(KY_CONFIG_DEBUG_OR_DEV)
KT_ASSERT(KT_ENV.AddNavData("generated/plane200x200_80ktri/plane200x200_80ktri.NavData") != nullptr);
KT_ASSERT(KT_ENV.AddRandomBots(1) == 1);
Kaim::MessageReceiverRegistry registry;
LabEngine::CommandRegistry commands;
Kaim::Ptr<LabEngine::CommandContract> exitCmdContract = *KY_NEW LabEngine::CommandContract("exit");
Kaim::Ptr<ExitCommandProcessor> exitCommandProcessor = *KY_NEW ExitCommandProcessor;
exitCmdContract->SetCommandProcessor(exitCommandProcessor);
commands.AddCommand(exitCmdContract);
registry.SetVal(Kaim::TextualCommandBlob::GetBlobTypeId(), KY_NEW LabEngine::TextualCommandReceiver(&commands));
KyUInt32 serverPort = Kaim::VisualDebugServerConfig::DefaultServerPort();
KyUInt32 broadcastPort = Kaim::VisualDebugServerConfig::DefaultBroadcastPort();
KyResult startResult = navWorld->StartVisualDebug(visualDebugServerConfig);
{
TestLog() << "Failed to start visual debug\n";
KT_ASSERT(false);
}
for (
KyUInt32 gameFrame = 0; gameFrame < 10 && exitCommandProcessor->m_doExit ==
false; ++gameFrame)
{
navWorld->NewVisualDebugFrame();
navWorld->Update();
KY_LOG_MESSAGE_IF(navWorld->GetVisualDebugServer()->IsReadyToSend(),
("==== Type exit in the NavigationLab Console in order to close this tutorial ===="));
}
navWorld->StopVisualDebug();
exitCommandProcessor = nullptr;
exitCmdContract = nullptr;
#endif
KT_ENV.CleanUpWorld();
}
}