一旦您的游戏设置为接受来自 Navigation Lab 的连接,则可以将自己的数据、形状和体积发送到 Navigation Lab。Navigation Lab 会显示您的数据,正如 Gameware Navigation 原有类发送的调试数据。可以像任何其他数据一样记录您的数据,将其保存到片段,并重新播放。
下面的代码样例将创建和发送单帧寿命的显示列表,并会在每一帧重复该过程。但是,如果显示列表中包含的数据不经常更改,您就可以创建用户定义寿命的显示列表,并将其发送一次。然后,其数据会显示在每个帧,直到您更改其数据或将其删除。有关此替代方法的详细信息,请参见可视调试。
跳过这些建议不会导致错误,但会浪费创建内部对象(实际上永远不会发送到 Navigation Lab)所涉及的计算。
[Tutorial_FirstIntegration.cpp 中的代码]
#include "gwnavruntime/visualsystem/displaylist.h" ... void MyGameWorld::TestVisualDebugger() { // Visual debugging is disabled in Shipping builds. Even though the symbols and functions are available, they do nothing. // Guarding this code is not necessary, but is recommended in order to prevent useless computations. #ifndef KY_BUILD_SHIPPING Kaim::VisualDebugServer* visualDebugServer = m_world->GetVisualDebugServer(); // always check the state of the VisualDebugServer // to avoid costly construction of messages for nothing if (visualDebugServer->IsConnected() == false) return; const char* myCategoryName = "MyGame"; // Sends a message to the Log window of the Navigation Lab static KyUInt32 framecount = 0; KY_LOG_MESSAGE(("FrameCount: %d", framecount)); framecount++; // Sends a single data value KyUInt32 someKindOfInformation = 1256; visualDebugServer->SendUInt32("SomeKindOfInformation", someKindOfInformation, myCategoryName); // Sends current, average, max, and min stats computed by the game const char* someKindOfStat = "SomeKindOfStat"; KyFloat32 currentValue = 2.56f; KyFloat32 averageValue = 2.56f; KyFloat32 maxValue = 3.026f; KyFloat32 minValue = 0.21f; visualDebugServer->SendStats(someKindOfStat, currentValue, averageValue, maxValue, minValue, myCategoryName); // Visual information is sent using a display list Kaim::Vec3f boxLowerCornerPosition = Kaim::Vec3f(-5.0f, -5.0f, 0.0f); Kaim::Vec3f boxExtents = Kaim::Vec3f(3.0f, 2.0f, 1.0f); Kaim::Vec3f positionA = Kaim::Vec3f(0.0f, 2.0f, 0.0f); Kaim::Vec3f positionB = Kaim::Vec3f(10.0f, 10.0f, 0.0f); KyFloat32 radius = 0.4f; KyFloat32 height = 2.0f; // The Gameware Navigation coordinate system is Z-up, right-handed, // in meters. Always convert positions, vectors and sizes from the coordinate // system you use in your game. You can set up a Kaim::CoordSystem object, and use // its methods to do the conversions for you, as shown below. boxLowerCornerPosition = m_coordSystem.ClientToNavigation_Pos( boxLowerCornerPosition ); boxExtents = m_coordSystem.ClientToNavigation_Pos( boxExtents ); positionA = m_coordSystem.ClientToNavigation_Pos( positionA ); positionB = m_coordSystem.ClientToNavigation_Pos( positionB ); radius = m_coordSystem.ClientToNavigation_Dist( radius ); height = m_coordSystem.ClientToNavigation_Dist( height ); { // Create a display list and send a line Kaim::ScopedDisplayList displayList(m_world, Kaim::DisplayList_Enable); displayList.InitSingleFrameLifespan("Simple Display List", myCategoryName); displayList.PushLine(positionB, positionB + Kaim::Vec3f::UnitZ(), Kaim::VisualColor::White); // The ScopedDisplayList is automatically sent to the Navigation Lab // when it goes out of scope. } { // Create a second display list and send more shapes Kaim::ScopedDisplayList displayList(m_world, Kaim::DisplayList_Enable); displayList.InitSingleFrameLifespan("Complex Display List", myCategoryName); Kaim::VisualShapeColor shapeColor; shapeColor.m_triangleColor = Kaim::VisualColor(255, 255, 0); shapeColor.m_lineColor = Kaim::VisualColor(175, 175, 0); displayList.PushVerticalCylinder( positionA, radius, height, 10, shapeColor); displayList.PushLine( positionA, positionB, Kaim::VisualColor::Red); shapeColor.m_triangleColor = Kaim::VisualColor(0, 255, 0, 128); shapeColor.m_lineColor = Kaim::VisualColor(0, 128, 0, 255); Kaim::Box3f someBox(boxLowerCornerPosition, boxLowerCornerPosition + boxExtents); displayList.PushBox(someBox, shapeColor); displayList.PushText( positionB + Kaim::Vec3f::UnitZ(), Kaim::VisualColor(0, 255, 255), "Some text"); // Again, the ScopedDisplayList is automatically sent to the Navigation Lab // when it goes out of scope. } #endif }
当您将 Navigation Lab 连接到游戏时,现在应该可以看到:
您也可以在 Visual debug 面板中显示和隐藏在显示列表中发送的数据。您为显示列表指定的类别名称显示在面板底部,位于标题“Display lists”下。如果展开此类别,您可以显示和隐藏各个显示列表。