gwnavruntime/visualsystem/displaylist.h Source File

displaylist.h
Go to the documentation of this file.
1 /*
2 * Copyright 2015 Autodesk, Inc. All rights reserved.
3 * 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,
4 * or which otherwise accompanies this software in either electronic or hard copy form, or which is signed by you and accepted by Autodesk.
5 */
6 
7 // primary contact: BRGR - secondary contact: GUAL
8 #ifndef Navigation_DisplayList_H
9 #define Navigation_DisplayList_H
10 
16 
17 namespace Kaim
18 {
19 
20 class DisplayListData;
21 class IVisualGeometry;
22 class VisualDebugServer;
23 class World;
24 class Triangle3f;
25 class Vec3f;
26 class Box3f;
27 class Box2i;
28 class Transform;
29 class OrientedBox2d;
30 class DatabaseGenMetrics;
31 
32 
37 {
40 };
41 
42 } // namespace Kaim
43 // we close the namespace Kaim here to reopen it cleanly inside
44 // - #ifndef KY_DISABLE_DISPLAYLIST
45 // - #else // KY_DISABLE_DISPLAYLIST
46 
47 
48 
49 // Define KY_DISABLE_DISPLAYLIST to disable ScopedDisplayList and DisplayListManager
50 // In that case these classes will be replaced by fully inlined classes, DisabledScopedDisplayList and DisabledDisplayListManager,
51 // thanks to the define at the end of this file.
52 // If ScopedDisplayList and DisplayListManager are modified, please apply the changes into disableddisplaylist.inl as well.
53 #ifdef KY_BUILD_SHIPPING
54 # define KY_DISABLE_DISPLAYLIST
55 #endif
56 
57 #ifndef KY_DISABLE_DISPLAYLIST
58 
59 namespace Kaim
60 {
61 
62 class DisplayListManager;
63 
131 class ScopedDisplayList
132 {
133  KY_DEFINE_NEW_DELETE_OPERATORS(MemStat_VisualSystem)
134  KY_CLASS_WITHOUT_COPY(ScopedDisplayList)
135 
136 public:
137  // --------------- Constructors -------------
143 
145  ScopedDisplayList(World* world, DisplayListActivation activation = DisplayList_Enable);
146 
147  // --------------- Init for ScopedDisplayList stored only in the frame it was sent -------------
151 
152  void InitSingleFrameLifespan(const char listName[64], const char groupName[64]);
153  void InitSingleFrameLifespan(const char listName[64], KyUInt32 worldElementId);
154  void InitSingleFrameLifespan(const char listName[64], const char groupName[64], KyUInt32 worldElementId);
155 
156 
157  // --------------- Init for ScopedDisplayList with User-Controlled Lifespan -------------
181 
182  KyUInt32 InitUserControlledLifespan(const char listName[64], const char groupName[64], KyUInt32 displayListId);
183  KyUInt32 InitUserControlledLifespan(const char listName[64], KyUInt32 worldElementId, KyUInt32 displayListId);
184  KyUInt32 InitUserControlledLifespan(const char listName[64], const char groupName[64], KyUInt32 worldElementId, KyUInt32 displayListId);
185 
187  void InitUserControlledLifespan(const char listName[64], const char groupName[64]);
188 
194  void InitUserControlledLifespan_AssociateWithWorldElement(const char listName[64], const char groupName[64], KyUInt32 worldElementId);
195 
196  // --------------- Optional post-Init functions -------------
197 
201  void ShowInLabWhenSelected(bool showInLabWhenSelected);
202 
206  void ShowInLabWhenNotSelected(bool showInLabWhenNotSelected);
207 
209  void ShowInLab(bool showInLab);
210 
211  // --------------- Shapes -------------
212 
214  void PushTextVarg( const Vec3f& pos, const VisualColor& color, const char* textFmt, ...);
215  void PushText(const Vec3f& pos, const VisualColor& color, const char* text, KyUInt32 textLength = 0);
216 
218  void PushLine(const Vec3f& P, const Vec3f& Q, const VisualColor& color, KyFloat32 pixelWidth = 1.f);
219 
221  void PushTriangle(const Vec3f& A, const Vec3f& B, const Vec3f& C, const VisualShapeColor& color);
222 
224  void PushTriangle(const Triangle3f& triangle, const VisualShapeColor& color);
225 
227  void PushVerticalCylinder(const Vec3f& P, KyFloat32 radius, KyFloat32 height, KyUInt32 subdivisions, const VisualShapeColor& color);
228 
230  void PushSegment(const Vec3f& A, const Vec3f& B, KyFloat32 radius, const VisualShapeColor& color);
231 
233  void PushQuad(const Vec3f& A, const Vec3f& B, KyFloat32 radius, const VisualShapeColor& color);
234 
236  void PushQuad(const Vec3f& A, const Vec3f& B, const Vec3f& C, const Vec3f& D, const VisualShapeColor& color);
237 
239  void PushPoint(const Vec3f& P, const VisualShapeColor& color) { PushPoint(P, 0.1f, color); }
240 
242  void PushPoint(const Vec3f& P, KyFloat32 radius, const VisualShapeColor& color);
243 
245  void PushPyramid(const Vec3f& P, const Vec3f& Q, KyFloat32 halfWidth, const VisualShapeColor& color);
246 
249  void PushSquareTubeSegment( const Vec3f& P, const Vec3f& Q, KyFloat32 halfWidth, const VisualShapeColor& color);
250 
262  void PushArrow(const Vec3f& P, const Vec3f& Q, KyFloat32 bodyHalfWidth, const VisualShapeColor& color, KyFloat32 headWidthRatio = 3.0f, KyFloat32 headLengthRatio = 0.33f);
263 
274  void PushBezierArrow(const Vec3f& P, const Vec3f& Q, KyFloat32 bodyHalfWidth, const VisualShapeColor& color, KyFloat32 headWidthRatio = 3.0f, KyUInt32 directionnality = 0);
279  void PushChristmasTree(const Vec3f& P, const Vec3f& Q, KyFloat32 bodyHalfWidth, const VisualShapeColor& color);
280 
282  void PushSilex(const Vec3f& P, const Vec3f& Q, KyFloat32 bodyHalfWidth, const VisualShapeColor& color);
283 
286  void PushDoubleSilex(const Vec3f& P, const Vec3f& Q, KyFloat32 bodyHalfWidth, const VisualShapeColor& color);
287 
291  void PushCrossedRectangles(const Vec3f& P, const Vec3f& Q, KyFloat32 bodyHalfWidth, const VisualShapeColor& color);
292 
294  void PushColumn(const Vec3f& P, KyFloat32 halfWidth, KyFloat32 height, const VisualShapeColor& color);
295 
296  void PushOrientedBox(const Transform& transform, const Box3f& extents, const VisualShapeColor& color);
297  void PushOrientedBox2d(const OrientedBox2d& orientedBox2d, const VisualShapeColor& color);
298 
300  void PushPoint_Tetrahedron(const Vec3f& P, KyFloat32 halfWidth, const VisualShapeColor& color);
301 
303  void PushDisk(const Vec3f& P, KyFloat32 radius, KyUInt32 subdivisions, const VisualShapeColor& color);
304 
306  void PushDiskSector(const Vec3f& P, KyFloat32 radius, const Vec3f& startPos, const Vec3f& endPos, const RotationDirection rotDir, KyUInt32 subdivisionCount, const VisualShapeColor& color);
307 
309  void PushCorona(const Vec3f& P, KyFloat32 innerRadius, KyFloat32 outerRadius, KyUInt32 subdivisions, const VisualShapeColor& color);
310 
311  void PushStadium(const Vec3f& P, const Vec3f& Q, KyFloat32 radius, KyUInt32 subdivisions, const VisualShapeColor& color);
312 
314  void PushBox(const Box3f& box, const VisualShapeColor& color);
315 
317  void PushCellBox(const Box2i& cellBox, const KyFloat32 altitudeMinMax[/*2*/], const DatabaseGenMetrics& genMetrics, const VisualShapeColor& color);
318 
321  void PushTriangleTubeSegment(const Vec3f& P, const Vec3f& Q, KyFloat32 halfWidth, const VisualShapeColor& color);
322 
330  void PushWall(const Vec3f& P, const Vec3f& Q, KyFloat32 upHeight, KyFloat32 downHeight, KyFloat32 halfWidth, const VisualShapeColor& color);
331 
332  void PushLadder(const Transform& transform, const Box3f& entrances, KyFloat32 ladderWidth, KyFloat32 rungsThickness, KyFloat32 rungsGapSize, const VisualShapeColor& shapeColor);
333 
334  void PushParabola(const Kaim::Vec3f& P, const Kaim::Vec3f& Q, KyFloat32 heightBias, KyUInt32 subdivisions, const VisualShapeColor& color);
335 
336  void PushFlag(const Vec3f& P, KyFloat32 height, KyFloat32 radius, const VisualShapeColor& color);
337 
338  // ...
339 
340 
341 private:
342  void PushSegmentBasedShape(const Vec3f& P, const Vec3f& Q, KyFloat32 size, const VisualShapeColor& color, KyUInt32 displayShapeType);
343  void PushCurveBasedShape(const Vec3f& P, const Vec3f& Q, KyFloat32 size, KyFloat32 subdivisions, const VisualShapeColor& color, KyUInt32 displayShapeType);
344  void PushText(DisplayText& text);
345  void PushShape(DisplayShape& shape);
346  KyUInt32 SetLifespanIdentifier(KyUInt32 displayListId);
347 
348 private:
349  KyArrayPOD<char> m_tmpTextBuffer;
350 
351 public: // internal
352  ~ScopedDisplayList(); // call SendDisplayListData() and ReleaseDisplayListData()
353  void Flush(); // call SendDisplayListData()
354  DisplayListManager* GetManager() { return m_displayListManager; }
355 
356 public: // internal
357  DisplayListManager* m_displayListManager;
358  DisplayListData* m_displayListData;
359 };
360 
361 
364 class DisplayListManager
365 {
366  KY_DEFINE_NEW_DELETE_OPERATORS(MemStat_VisualSystem)
367 
368 public:
369  DisplayListManager();
370  ~DisplayListManager();
371 
372  void SetVisualDebugServer(VisualDebugServer* visualDebugServer) { m_visualDebugServer = visualDebugServer; }
373  bool IsVisualDebugSupported();
374 
377 
379  void RemoveDisplayList(KyUInt32 displayListId);
380 
382  void RemoveDisplayList(const char* displayListName, const char* displayListGroupName, KyUInt32 worldElementId = KyUInt32MAXVAL);
383 
384 private:
385  // Game side
386  VisualDebugServer* m_visualDebugServer;
387  KyUInt32 m_currentDisplayListId;
388  BlobHandler<DisplayListBlob> m_workingDisplayListBlobHandler; // reusable handler used to create all display list blobs
389  KyArray<DisplayListData*> m_displayListDataPool;
390 
391  // NavigationLab side
392  // buffer containing all the display list blobs packed one after each other
393  KyArrayPOD<char> m_displayListBlobsToRenderBuffer; // [blobSize_1 : KyUInt32][blob_1....][blobSize_2 : KyUInt32][blob_2....]...
394  Ptr<IVisualGeometry> m_visualGeometry;
395 
396 public: // internal
397  DisplayListData* GetNewDisplayListData(); // return the first unused DisplayListData in m_displayListDataPool
398  void SendDisplayListData(DisplayListData* displayListData); // Send DisplayListData to the VisualDebug (and possibly to the VisualGeometry if m_visualGeometry!=NULL)
399  void ReleaseDisplayListData(DisplayListData* displayListData); // Clear this displayListData so that it can be reused by another display list
400 
401  // NavigationLab side : DisplayListBlobToRender management
402  void AddDisplayListBlobToRender(const char* displayListBlob, KyUInt32 blobsize);
403  DisplayListBlob* GetNextDisplayListBlobToRender(KyUInt32& sizeRead);
404  void ClearDisplayListBlobsToRender();
405 
406  // NavigationLab side : DisplayListBlobToRender => VisualGeometry
407  void SetVisualGeometry(IVisualGeometry* visualGeometry); // in cpp to avoid including IVisualGeometry
408  IVisualGeometry* GetVisualGeometry() { return m_visualGeometry; }
409  bool IsVisualGeometrySupported() { return m_visualGeometry != KY_NULL; }
410 
411  void BuildVisualGeometry(); // fill the m_visualGeometry with the content of m_displayLists.
412 
413 public: // DEPRECATED
414  KY_DEPRECATED(void SubmitToRenderer()) { BuildVisualGeometry(); }
415 };
416 
417 } // namespace Kaim
418 
419 //------------------------------------------------------------------------------------------------------------------------------------------------
420 #else // KY_DISABLE_DISPLAYLIST
421 
422 // Here we use a separated file in order to easily maintain both versions by comparing the two files (displaylist.h and disableddisplaylist.inl)
423 // Note that disableddisplaylist.inl has its own namespace Kaim {}
425 
426 // This allows to forward declare DisplayListManager and ScopedDisplayList
427 // and to use DisabledDisplayListManager and DisabledScopedDisplayList separately in unit tests
428 namespace Kaim
429 {
430 
431 class DisplayListManager : public DisabledDisplayListManager
432 {
433 };
434 
435 class ScopedDisplayList : public DisabledScopedDisplayList
436 {
437  KY_CLASS_WITHOUT_COPY(ScopedDisplayList)
438 
439 public:
440  ScopedDisplayList(DisplayListManager* manager, DisplayListActivation activation = DisplayList_Disable)
441  : DisabledScopedDisplayList(manager, activation)
442  {}
443 
444  ScopedDisplayList(World* world, DisplayListActivation activation = DisplayList_Disable)
445  : DisabledScopedDisplayList(world, activation)
446  {}
447 
448  ~ScopedDisplayList()
449  {}
450 };
451 
452 } // namespace Kaim
453 
454 #endif // KY_DISABLE_DISPLAYLIST
455 //------------------------------------------------------------------------------------------------------------------------------------------------
456 
457 #endif // Navigation_DisplayList_H
void PushCorona(const Vec3f &P, KyFloat32 innerRadius, KyFloat32 outerRadius, KyUInt32 subdivisions, const VisualShapeColor &color)
Pushes a 2D flat corona centered on P.
void InitUserControlledLifespan_AssociateWithWorldElement(const char listName[64], const char groupName[64], KyUInt32 worldElementId)
Associate the displayList to the given world element and so the list can then be turned on/off under ...
void PushDiskSector(const Vec3f &P, KyFloat32 radius, const Vec3f &startPos, const Vec3f &endPos, const RotationDirection rotDir, KyUInt32 subdivisionCount, const VisualShapeColor &color)
Pushes a 2D flat disk sector centered on P, between start and end positions (on the circle)...
void PushColumn(const Vec3f &P, KyFloat32 halfWidth, KyFloat32 height, const VisualShapeColor &color)
Pushes an axis-aligned box whose base is centered on P.
Game side: Manages all DisplayListData, send them to the NavigationLab.
Definition: displaylist.h:409
void PushDisk(const Vec3f &P, KyFloat32 radius, KyUInt32 subdivisions, const VisualShapeColor &color)
Pushes a 2D flat disk centered on P.
This class represents a two-dimensional axis-aligned bounding box whose dimensions are stored using 3...
Definition: box2i.h:119
void PushTextVarg(const Vec3f &pos, const VisualColor &color, const char *textFmt,...)
Pushes a text.
This class represents a three-dimensional bounding box with a free orientation on the (X...
Definition: orientedbox2d.h:53
void ShowInLabWhenSelected(bool showInLabWhenSelected)
Makes the NavigationLab display or hide the displayList when the corresponding Element (Bot...
void PushVerticalCylinder(const Vec3f &P, KyFloat32 radius, KyFloat32 height, KyUInt32 subdivisions, const VisualShapeColor &color)
Pushes a cylinder whose base is centered on P.
void PushChristmasTree(const Vec3f &P, const Vec3f &Q, KyFloat32 bodyHalfWidth, const VisualShapeColor &color)
Pushes a Christmas tree: two orthogonal triangles with the same central axes.
void ShowInLabWhenNotSelected(bool showInLabWhenNotSelected)
Makes the NavigationLab display or hide the displayList when the corresponding Element (Bot...
This class represents a triangle in three-dimensional space, whose dimensions are stored using float ...
Definition: triangle3f.h:22
KyUInt32 GenerateDisplayListId()
Returns a unique display list ID, which you can use when creating a new ScopedDisplayList with a user...
Calls on the ScopedDisplayList will do nothing.
Definition: displaylist.h:39
#define KY_NULL
Null value.
Definition: types.h:247
KyUInt32 InitUserControlledLifespan(const char listName[64], const char groupName[64], KyUInt32 displayListId)
group all displayLists with the same groupName under the same label
The display list is activated.
Definition: displaylist.h:40
void PushPyramid(const Vec3f &P, const Vec3f &Q, KyFloat32 halfWidth, const VisualShapeColor &color)
Push a pyramid composed of a base and four sides. P the is center of the base, Q is the peak...
void PushQuad(const Vec3f &A, const Vec3f &B, KyFloat32 radius, const VisualShapeColor &color)
Pushes a flat Quad.
Represents a single RGBA color.
Definition: visualcolor.h:19
#define KY_CLASS_WITHOUT_COPY(ClassName)
Define to forbid copy constructor and copy assignment.
Definition: types.h:387
This class is a runtime container for Gameware Navigation WorldElements such as NavData, Bots, BoxObstacles, TagVolumes...
Definition: world.h:54
RotationDirection
Defines the 4 possible cases of possibly constrained rotation in the horizontal plane for a given ele...
Definition: rotation.h:20
void PushTriangle(const Vec3f &A, const Vec3f &B, const Vec3f &C, const VisualShapeColor &color)
Pushes a single triangle.
This class represents a three-dimensional axis-aligned bounding box whose dimensions are stored using...
Definition: box3f.h:25
void PushBezierArrow(const Vec3f &P, const Vec3f &Q, KyFloat32 bodyHalfWidth, const VisualShapeColor &color, KyFloat32 headWidthRatio=3.0f, KyUInt32 directionnality=0)
Pushes a bezier arrow from P to Q.
void PushArrow(const Vec3f &P, const Vec3f &Q, KyFloat32 bodyHalfWidth, const VisualShapeColor &color, KyFloat32 headWidthRatio=3.0f, KyFloat32 headLengthRatio=0.33f)
Pushes an arrow from P to Q.
void PushDoubleSilex(const Vec3f &P, const Vec3f &Q, KyFloat32 bodyHalfWidth, const VisualShapeColor &color)
Pushes a double silex from P to Q with the specified bodyHalfWidth.
void InitSingleFrameLifespan(const char listName[64], const char groupName[64])
group all displayLists with the same groupName under the same label
Definition: gamekitcrowddispersion.h:20
void PushWall(const Vec3f &P, const Vec3f &Q, KyFloat32 upHeight, KyFloat32 downHeight, KyFloat32 halfWidth, const VisualShapeColor &color)
Pushes a three-dimensional oriented box.
void PushSilex(const Vec3f &P, const Vec3f &Q, KyFloat32 bodyHalfWidth, const VisualShapeColor &color)
Pushes a silex from P to Q with the specified bodyHalfWidth.
void PushPoint(const Vec3f &P, const VisualShapeColor &color)
Pushes an axis-aligned box centered on P. Or, a cross made of lines.
Definition: displaylist.h:275
void PushCrossedRectangles(const Vec3f &P, const Vec3f &Q, KyFloat32 bodyHalfWidth, const VisualShapeColor &color)
Pushes two orthogonal rectangles with the same central axes.
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:137
#define KY_DEPRECATED(f)
Macro to mark a function, class or method as deprecated.
Definition: types.h:289
void SubmitToRenderer()
Changed for consistency, please use BuildVisualGeometry instead.
Definition: displaylist.h:465
ScopedDisplayList is used to push text, lines or shapes for rendering in the NavigationLab e...
Definition: displaylist.h:136
void RemoveDisplayList(KyUInt32 displayListId)
Stops rendering the display list with the specified ID.
unsigned int KyUInt32
Type used internally to represent an unsigned 32-bit integer.
Definition: types.h:36
void PushBox(const Box3f &box, const VisualShapeColor &color)
Pushes an axis-aligned box.
void PushLine(const Vec3f &P, const Vec3f &Q, const VisualColor &color, KyFloat32 pixelWidth=1.f)
Pushes a line.
void PushCellBox(const Box2i &cellBox, const KyFloat32 altitudeMinMax[], const DatabaseGenMetrics &genMetrics, const VisualShapeColor &color)
Pushes a Box from a CellBox using -altitude and +altitude for z values for min and max...
This class represents a three-dimensional 6 freedom degrees unit transform.
Definition: transform.h:20
void PushPoint_Tetrahedron(const Vec3f &P, KyFloat32 halfWidth, const VisualShapeColor &color)
Pushes an axis-aligned tetrahedron centered on P and pointing down.
void PushSquareTubeSegment(const Vec3f &P, const Vec3f &Q, KyFloat32 halfWidth, const VisualShapeColor &color)
Pushes a hollow tube with a square cross-section.
#define KyUInt32MAXVAL
The maximum value that can be stored in the KyUInt32 variable type.
Definition: types.h:226
void ShowInLab(bool showInLab)
Makes the NavigationLab hide the displayList whether it's selected or NOT selected. The NavigationLab UI allows to override this.
This class gathers a set of generation parameters of one Database and manages the conversion between ...
Definition: databasegenmetrics.h:24
float KyFloat32
Type used internally to represent a 32-bit floating-point number.
Definition: types.h:43
This class defines a three-dimensional vector whose coordinates are stored using floating-point numbe...
Definition: vec3f.h:23
void PushTriangleTubeSegment(const Vec3f &P, const Vec3f &Q, KyFloat32 halfWidth, const VisualShapeColor &color)
Pushes a hollow tube with a triangular cross-section.
DisplayListActivation
Indicates if the display list is active or not.
Definition: displaylist.h:37
void PushSegment(const Vec3f &A, const Vec3f &B, KyFloat32 radius, const VisualShapeColor &color)
Pushes a segment. P and Q are the centers of the two opposite ends, and halfWidth is half the width o...