#include "common/oneworldenv.h"
#include "GwNavTestFwk/TestSystem.h"
#include "LabEngine/commands/textualcommandreceiver.h"
#include "LabEngine/commands/commands.h"
#include "LabEngine/base/kaimfileopener.h"
namespace
{
#define TEST_ENV_CLASS OneWorldEnv
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;
};
TUTORIAL
{
KT_LOG_TITLE_BEGIN("TUTORIAL - Visual Debug a world");
#ifndef KY_BUILD_SHIPPING
CHECK(env.LoadAndAddNavData(
"GeneratedNavData/plan/plan.NavData") !=
KY_NULL);
CHECK(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";
CHECK(false);
}
navWorld->GetVisualDebugServer()->WaitWhileEstablishingConnection(1);
for (
KyUInt32 gameFrame = 0; gameFrame < 10; ++gameFrame)
{
if (navWorld->GetVisualDebugServer())
navWorld->GetVisualDebugServer()->NewFrame();
navWorld->Update();
}
navWorld->StopVisualDebug();
#endif
env.CleanUpWorld();
}
TUTORIAL
{
KT_LOG_TITLE_BEGIN("TUTORIAL - Send custom information through Kaim::VisualDebugServer");
#ifndef KY_BUILD_SHIPPING
CHECK(env.LoadAndAddNavData(
"GeneratedNavData/plan/plan.NavData") !=
KY_NULL);
CHECK(env.AddRandomBots(1) == 1);
LabEngine::GameBot* gameBot = env.GetGameWorld()->GetBots()[0];
KyUInt32 serverPort = Kaim::VisualDebugServerConfig::DefaultServerPort();
KyUInt32 broadcastPort = Kaim::VisualDebugServerConfig::DefaultBroadcastPort();
{
TestLog() << "Failed to start visual debug\n";
CHECK(false);
}
const char* tutroialCategoryName = "Tutorial_World";
for (
KyUInt32 gameFrame = 0; gameFrame < 10; ++gameFrame)
{
if (navWorld->GetVisualDebugServer())
navWorld->GetVisualDebugServer()->
NewFrame();
if (navWorld->GetVisualDebugServer()->
IsConnected() ==
false)
continue;
visualDebugServer->
SendUInt32(
"GameFrame", gameFrame, tutroialCategoryName);
visualDebugServer->
SendStats(gameStats, tutroialCategoryName);
{
}
{
Kaim::Vec3f destination = gameBot->GetRoute().GetCurrentWayPoint();
Kaim::VisualShapeColor shapeColor;
displayList.
PushPoint(destination, displayRadius, shapeColor);
displayList.
PushArrow(gameBot->GetPosition(), destination, displayRadius, shapeColor);
}
}
#endif
env.CleanUpWorld();
}
TUTORIAL
{
KT_LOG_TITLE_BEGIN("TUTORIAL - Send a ScopedDisplayList once, but keep it alive several frames in the NavigationLab");
#ifndef KY_BUILD_SHIPPING
KyUInt32 serverPort = Kaim::VisualDebugServerConfig::DefaultServerPort();
KyUInt32 broadcastPort = Kaim::VisualDebugServerConfig::DefaultBroadcastPort();
visualDebugServerConfig.SetWaitOnStart(waitOnStart);
{
TestLog() << "Failed to start visual debug\n";
CHECK(false);
}
{
while (1)
{
if (navWorld->GetVisualDebugServer())
navWorld->GetVisualDebugServer()->
NewFrame();
break;
}
}
const char* tutorialCategoryName = "Tutorial_World";
for (
KyUInt32 gameFrame = 0; gameFrame < 1000; ++gameFrame)
{
if (navWorld->GetVisualDebugServer())
navWorld->GetVisualDebugServer()->
NewFrame();
{
if (gameFrame == 4)
{
}
else if (gameFrame == 8)
{
}
else if (gameFrame == 16)
{
}
else if (gameFrame == 20)
{
}
else if (gameFrame == 24)
{
}
else if (gameFrame == 30)
{
}
}
}
#endif
env.CleanUpWorld();
}
TUTORIAL
{
KT_LOG_TITLE_BEGIN("TUTORIAL - Use Kaim::VisualDebugServer for testing");
#ifndef KY_BUILD_SHIPPING
CHECK(env.LoadAndAddNavData(
"GeneratedNavData/plan/plan.NavData") !=
KY_NULL);
CHECK(env.AddRandomBots(1) == 1);
std::string filename = 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";
CHECK(false);
}
for (
KyUInt32 gameFrame = 0; gameFrame < 10; ++gameFrame)
{
if (navWorld->GetVisualDebugServer())
navWorld->GetVisualDebugServer()->NewFrame();
env.Update();
}
#endif
env.CleanUpWorld();
}
TUTORIAL
{
KT_LOG_TITLE_BEGIN("TUTORIAL - Custom messages reception in Kaim::VisualDebugServer");
#ifndef KY_BUILD_SHIPPING
CHECK(env.LoadAndAddNavData(
"GeneratedNavData/plan/plan.NavData") !=
KY_NULL);
CHECK(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";
CHECK(false);
}
for (
KyUInt32 gameFrame = 0; gameFrame < 10 && exitCommandProcessor->m_doExit ==
false; ++gameFrame)
{
if (navWorld->GetVisualDebugServer())
navWorld->GetVisualDebugServer()->NewFrame();
navWorld->Update();
KY_LOG_MESSAGE_IF(navWorld->GetVisualDebugServer()->IsConnected(),
("==== Type exit in the NavigationLab Console in order to close this tutorial ===="));
}
navWorld->StopVisualDebug();
#endif
env.CleanUpWorld();
}
}