Skip to content

Commit

Permalink
use static and override when useful
Browse files Browse the repository at this point in the history
  • Loading branch information
Morel Bérenger authored and illwieckz committed Sep 12, 2023
1 parent 4e2d075 commit a2cda8d
Show file tree
Hide file tree
Showing 23 changed files with 235 additions and 179 deletions.
14 changes: 8 additions & 6 deletions DebugUtils/Include/DebugDraw.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#ifndef DEBUGDRAW_H
#define DEBUGDRAW_H

#include "DetourModernCpp.h"

// Some math headers don't have PI defined.
static const float DU_PI = 3.14159265f;

Expand Down Expand Up @@ -207,12 +209,12 @@ class duDisplayList : public duDebugDraw

public:
duDisplayList(int cap = 512);
virtual ~duDisplayList();
virtual void depthMask(bool state);
virtual void begin(duDebugDrawPrimitives prim, float size = 1.0f);
virtual void vertex(const float x, const float y, const float z, unsigned int color);
virtual void vertex(const float* pos, unsigned int color);
virtual void end();
virtual ~duDisplayList() DT_OVERRIDE;
virtual void depthMask(bool state) DT_OVERRIDE;
virtual void begin(duDebugDrawPrimitives prim, float size = 1.0f) DT_OVERRIDE;
virtual void vertex(const float x, const float y, const float z, unsigned int color) DT_OVERRIDE;
virtual void vertex(const float* pos, unsigned int color) DT_OVERRIDE;
virtual void end() DT_OVERRIDE;
void clear();
void draw(struct duDebugDraw* dd);
private:
Expand Down
2 changes: 1 addition & 1 deletion DebugUtils/Source/DebugDraw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ inline float vdistSqr(const float* v1, const float* v2)
}


void appendArrowHead(struct duDebugDraw* dd, const float* p, const float* q,
static void appendArrowHead(struct duDebugDraw* dd, const float* p, const float* q,
const float s, unsigned int col)
{
const float eps = 0.001f;
Expand Down
22 changes: 22 additions & 0 deletions Detour/Include/DetourModernCpp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef DETOURMODERNCPP_H
#define DETOURMODERNCPP_H

#include <limits>

#include "DetourAssert.h"

#if defined(__cplusplus) && __cplusplus >= 201103L
#define DT_OVERRIDE override
#else
#include <stddef.h>
#define DT_OVERRIDE
#endif

template <typename TO, typename FROM>
inline TO dtCast( FROM val )
{
dtAssert( std::numeric_limits<TO>::min() <= val && val <= std::numeric_limits<TO>::max() );
return static_cast<TO>( val );
}

#endif
5 changes: 4 additions & 1 deletion Detour/Include/DetourNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
#ifndef DETOURNODE_H
#define DETOURNODE_H

#include <stdint.h>

#include "DetourModernCpp.h"
#include "DetourNavMesh.h"

enum dtNodeFlags
Expand All @@ -29,7 +32,7 @@ enum dtNodeFlags
};

typedef unsigned short dtNodeIndex;
static const dtNodeIndex DT_NULL_IDX = (dtNodeIndex)~0;
static const dtNodeIndex DT_NULL_IDX = std::numeric_limits<unsigned short>::max();

static const int DT_NODE_PARENT_BITS = 24;
static const int DT_NODE_STATE_BITS = 2;
Expand Down
1 change: 1 addition & 0 deletions Detour/Source/DetourAssert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// 3. This notice may not be removed or altered from any source distribution.
//

#include "DetourModernCpp.h"
#include "DetourAssert.h"

#ifndef RC_DISABLE_ASSERTS
Expand Down
9 changes: 5 additions & 4 deletions Detour/Source/DetourNavMeshQuery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "DetourMath.h"
#include "DetourAlloc.h"
#include "DetourAssert.h"
#include "DetourModernCpp.h"
#include <new>

/// @class dtQueryFilter
Expand Down Expand Up @@ -635,13 +636,13 @@ class dtFindNearestPolyQuery : public dtPolyQuery
{
}

virtual ~dtFindNearestPolyQuery();
virtual ~dtFindNearestPolyQuery() DT_OVERRIDE;

dtPolyRef nearestRef() const { return m_nearestRef; }
const float* nearestPoint() const { return m_nearestPoint; }
bool isOverPoly() const { return m_overPoly; }

void process(const dtMeshTile* tile, dtPoly** polys, dtPolyRef* refs, int count)
void process(const dtMeshTile* tile, dtPoly** polys, dtPolyRef* refs, int count) DT_OVERRIDE
{
dtIgnoreUnused(polys);

Expand Down Expand Up @@ -859,12 +860,12 @@ class dtCollectPolysQuery : public dtPolyQuery
{
}

virtual ~dtCollectPolysQuery();
virtual ~dtCollectPolysQuery() DT_OVERRIDE;

int numCollected() const { return m_numCollected; }
bool overflowed() const { return m_overflow; }

void process(const dtMeshTile* tile, dtPoly** polys, dtPolyRef* refs, int count)
void process(const dtMeshTile* tile, dtPoly** polys, dtPolyRef* refs, int count) DT_OVERRIDE
{
dtIgnoreUnused(tile);
dtIgnoreUnused(polys);
Expand Down
3 changes: 3 additions & 0 deletions Recast/Include/RecastAlloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
#include <stdlib.h>
#include <stdint.h>

#include "RecastAssert.h"
#include "RecastModernCpp.h"

/// Provides hint values to the memory allocator on how long the
/// memory is expected to be used.
enum rcAllocHint
Expand Down
22 changes: 22 additions & 0 deletions Recast/Include/RecastModernCpp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef RECASTMODERNCPP_H
#define RECASTMODERNCPP_H

#include <limits>

#include "RecastAssert.h"

#if defined(__cplusplus) && __cplusplus >= 201103L
#define RC_OVERRIDE override
#else
#include <stddef.h>
#define RC_OVERRIDE
#endif

template <typename TO, typename FROM>
inline TO rcCast( FROM val )
{
rcAssert( std::numeric_limits<TO>::min() <= val && val <= std::numeric_limits<TO>::max() );
return static_cast<TO>( val );
}

#endif
20 changes: 10 additions & 10 deletions RecastDemo/Include/ConvexVolumeTool.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ class ConvexVolumeTool : public SampleTool
public:
ConvexVolumeTool();

virtual int type() { return TOOL_CONVEX_VOLUME; }
virtual void init(Sample* sample);
virtual void reset();
virtual void handleMenu();
virtual void handleClick(const float* s, const float* p, bool shift);
virtual void handleToggle();
virtual void handleStep();
virtual void handleUpdate(const float dt);
virtual void handleRender();
virtual void handleRenderOverlay(double* proj, double* model, int* view);
virtual int type() RC_OVERRIDE { return TOOL_CONVEX_VOLUME; }
virtual void init(Sample* sample) RC_OVERRIDE;
virtual void reset() RC_OVERRIDE;
virtual void handleMenu() RC_OVERRIDE;
virtual void handleClick(const float* s, const float* p, bool shift) RC_OVERRIDE;
virtual void handleToggle() RC_OVERRIDE;
virtual void handleStep() RC_OVERRIDE;
virtual void handleUpdate(const float dt) RC_OVERRIDE;
virtual void handleRender() RC_OVERRIDE;
virtual void handleRenderOverlay(double* proj, double* model, int* view) RC_OVERRIDE;
};

#endif // CONVEXVOLUMETOOL_H
32 changes: 16 additions & 16 deletions RecastDemo/Include/CrowdTool.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ class CrowdToolState : public SampleToolState

public:
CrowdToolState();
virtual ~CrowdToolState();
virtual ~CrowdToolState() RC_OVERRIDE;

virtual void init(class Sample* sample);
virtual void reset();
virtual void handleRender();
virtual void handleRenderOverlay(double* proj, double* model, int* view);
virtual void handleUpdate(const float dt);
virtual void init(class Sample* sample) RC_OVERRIDE;
virtual void reset() RC_OVERRIDE;
virtual void handleRender() RC_OVERRIDE;
virtual void handleRenderOverlay(double* proj, double* model, int* view) RC_OVERRIDE;
virtual void handleUpdate(const float dt) RC_OVERRIDE;

inline bool isRunning() const { return m_run; }
inline void setRunning(const bool s) { m_run = s; }
Expand Down Expand Up @@ -129,16 +129,16 @@ class CrowdTool : public SampleTool
public:
CrowdTool();

virtual int type() { return TOOL_CROWD; }
virtual void init(Sample* sample);
virtual void reset();
virtual void handleMenu();
virtual void handleClick(const float* s, const float* p, bool shift);
virtual void handleToggle();
virtual void handleStep();
virtual void handleUpdate(const float dt);
virtual void handleRender();
virtual void handleRenderOverlay(double* proj, double* model, int* view);
virtual int type() RC_OVERRIDE { return TOOL_CROWD; }
virtual void init(Sample* sample) RC_OVERRIDE;
virtual void reset() RC_OVERRIDE;
virtual void handleMenu() RC_OVERRIDE;
virtual void handleClick(const float* s, const float* p, bool shift) RC_OVERRIDE;
virtual void handleToggle() RC_OVERRIDE;
virtual void handleStep() RC_OVERRIDE;
virtual void handleUpdate(const float dt) RC_OVERRIDE;
virtual void handleRender() RC_OVERRIDE;
virtual void handleRenderOverlay(double* proj, double* model, int* view) RC_OVERRIDE;
};

#endif // CROWDTOOL_H
22 changes: 11 additions & 11 deletions RecastDemo/Include/NavMeshPruneTool.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,18 @@ class NavMeshPruneTool : public SampleTool

public:
NavMeshPruneTool();
virtual ~NavMeshPruneTool();
virtual ~NavMeshPruneTool() RC_OVERRIDE;

virtual int type() { return TOOL_NAVMESH_PRUNE; }
virtual void init(Sample* sample);
virtual void reset();
virtual void handleMenu();
virtual void handleClick(const float* s, const float* p, bool shift);
virtual void handleToggle();
virtual void handleStep();
virtual void handleUpdate(const float dt);
virtual void handleRender();
virtual void handleRenderOverlay(double* proj, double* model, int* view);
virtual int type() RC_OVERRIDE { return TOOL_NAVMESH_PRUNE; }
virtual void init(Sample* sample) RC_OVERRIDE;
virtual void reset() RC_OVERRIDE;
virtual void handleMenu() RC_OVERRIDE;
virtual void handleClick(const float* s, const float* p, bool shift) RC_OVERRIDE;
virtual void handleToggle() RC_OVERRIDE;
virtual void handleStep() RC_OVERRIDE;
virtual void handleUpdate(const float dt) RC_OVERRIDE;
virtual void handleRender() RC_OVERRIDE;
virtual void handleRenderOverlay(double* proj, double* model, int* view) RC_OVERRIDE;

private:
// Explicitly disabled copy constructor and copy assignment operator.
Expand Down
20 changes: 10 additions & 10 deletions RecastDemo/Include/NavMeshTesterTool.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,16 @@ class NavMeshTesterTool : public SampleTool
public:
NavMeshTesterTool();

virtual int type() { return TOOL_NAVMESH_TESTER; }
virtual void init(Sample* sample);
virtual void reset();
virtual void handleMenu();
virtual void handleClick(const float* s, const float* p, bool shift);
virtual void handleToggle();
virtual void handleStep();
virtual void handleUpdate(const float dt);
virtual void handleRender();
virtual void handleRenderOverlay(double* proj, double* model, int* view);
virtual int type() RC_OVERRIDE { return TOOL_NAVMESH_TESTER; }
virtual void init(Sample* sample) RC_OVERRIDE;
virtual void reset() RC_OVERRIDE;
virtual void handleMenu() RC_OVERRIDE;
virtual void handleClick(const float* s, const float* p, bool shift) RC_OVERRIDE;
virtual void handleToggle() RC_OVERRIDE;
virtual void handleStep() RC_OVERRIDE;
virtual void handleUpdate(const float dt) RC_OVERRIDE;
virtual void handleRender() RC_OVERRIDE;
virtual void handleRenderOverlay(double* proj, double* model, int* view) RC_OVERRIDE;

void recalc();
void drawAgent(const float* pos, float r, float h, float c, const unsigned int col);
Expand Down
22 changes: 11 additions & 11 deletions RecastDemo/Include/OffMeshConnectionTool.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@ class OffMeshConnectionTool : public SampleTool

public:
OffMeshConnectionTool();
~OffMeshConnectionTool();
~OffMeshConnectionTool() RC_OVERRIDE;

virtual int type() { return TOOL_OFFMESH_CONNECTION; }
virtual void init(Sample* sample);
virtual void reset();
virtual void handleMenu();
virtual void handleClick(const float* s, const float* p, bool shift);
virtual void handleToggle();
virtual void handleStep();
virtual void handleUpdate(const float dt);
virtual void handleRender();
virtual void handleRenderOverlay(double* proj, double* model, int* view);
virtual int type() RC_OVERRIDE { return TOOL_OFFMESH_CONNECTION; }
virtual void init(Sample* sample) RC_OVERRIDE;
virtual void reset() RC_OVERRIDE;
virtual void handleMenu() RC_OVERRIDE;
virtual void handleClick(const float* s, const float* p, bool shift) RC_OVERRIDE;
virtual void handleToggle() RC_OVERRIDE;
virtual void handleStep() RC_OVERRIDE;
virtual void handleUpdate(const float dt) RC_OVERRIDE;
virtual void handleRender() RC_OVERRIDE;
virtual void handleRenderOverlay(double* proj, double* model, int* view) RC_OVERRIDE;
};

#endif // OFFMESHCONNECTIONTOOL_H
4 changes: 2 additions & 2 deletions RecastDemo/Include/Sample.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#include "Recast.h"
#include "SampleInterfaces.h"

#include "RecastModernCpp.h"

/// Tool types.
enum SampleToolType
Expand Down Expand Up @@ -62,7 +62,7 @@ enum SamplePolyFlags
class SampleDebugDraw : public DebugDrawGL
{
public:
virtual unsigned int areaToCol(unsigned int area);
virtual unsigned int areaToCol(unsigned int area) RC_OVERRIDE;
};

enum SamplePartitionType
Expand Down
Loading

0 comments on commit a2cda8d

Please sign in to comment.