Recast Navigation
Navigation-mesh Toolset for Games
SampleInterfaces.h
Go to the documentation of this file.
1 //
2 // Copyright (c) 2009-2010 Mikko Mononen memon@inside.org
3 //
4 // This software is provided 'as-is', without any express or implied
5 // warranty. In no event will the authors be held liable for any damages
6 // arising from the use of this software.
7 // Permission is granted to anyone to use this software for any purpose,
8 // including commercial applications, and to alter it and redistribute it
9 // freely, subject to the following restrictions:
10 // 1. The origin of this software must not be misrepresented; you must not
11 // claim that you wrote the original software. If you use this software
12 // in a product, an acknowledgment in the product documentation would be
13 // appreciated but is not required.
14 // 2. Altered source versions must be plainly marked as such, and must not be
15 // misrepresented as being the original software.
16 // 3. This notice may not be removed or altered from any source distribution.
17 //
18 
19 #ifndef SAMPLEINTERFACES_H
20 #define SAMPLEINTERFACES_H
21 
22 #include "DebugDraw.h"
23 #include "Recast.h"
24 #include "RecastDump.h"
25 #include "PerfTimer.h"
26 
27 // These are example implementations of various interfaces used in Recast and Detour.
28 
30 class BuildContext : public rcContext
31 {
32  TimeVal m_startTime[RC_MAX_TIMERS];
33  TimeVal m_accTime[RC_MAX_TIMERS];
34 
35  static const int MAX_MESSAGES = 1000;
36  const char* m_messages[MAX_MESSAGES];
37  int m_messageCount;
38  static const int TEXT_POOL_SIZE = 8000;
39  char m_textPool[TEXT_POOL_SIZE];
40  int m_textPoolSize;
41 
42 public:
43  BuildContext();
44 
46  void dumpLog(const char* format, ...);
48  int getLogCount() const;
50  const char* getLogText(const int i) const;
51 
52 protected:
55  virtual void doResetLog();
56  virtual void doLog(const rcLogCategory category, const char* msg, const int len);
57  virtual void doResetTimers();
58  virtual void doStartTimer(const rcTimerLabel label);
59  virtual void doStopTimer(const rcTimerLabel label);
60  virtual int doGetAccumulatedTime(const rcTimerLabel label) const;
62 };
63 
65 class DebugDrawGL : public duDebugDraw
66 {
67 public:
68  virtual void depthMask(bool state);
69  virtual void texture(bool state);
70  virtual void begin(duDebugDrawPrimitives prim, float size = 1.0f);
71  virtual void vertex(const float* pos, unsigned int color);
72  virtual void vertex(const float x, const float y, const float z, unsigned int color);
73  virtual void vertex(const float* pos, unsigned int color, const float* uv);
74  virtual void vertex(const float x, const float y, const float z, unsigned int color, const float u, const float v);
75  virtual void end();
76 };
77 
79 class FileIO : public duFileIO
80 {
81  FILE* m_fp;
82  int m_mode;
83 public:
84  FileIO();
85  virtual ~FileIO();
86  bool openForWrite(const char* path);
87  bool openForRead(const char* path);
88  virtual bool isWriting() const;
89  virtual bool isReading() const;
90  virtual bool write(const void* ptr, const size_t size);
91  virtual bool read(void* ptr, const size_t size);
92 private:
93  // Explicitly disabled copy constructor and copy assignment operator.
94  FileIO(const FileIO&);
95  FileIO& operator=(const FileIO&);
96 };
97 
98 #endif // SAMPLEINTERFACES_H
99 
duDebugDrawPrimitives
Definition: DebugDraw.h:26
__int64 TimeVal
Definition: PerfTimer.h:26
rcTimerLabel
Recast performance timer categories.
Definition: Recast.h:40
@ RC_MAX_TIMERS
The maximum number of timers. (Used for iterating timers.)
Definition: Recast.h:98
rcLogCategory
Recast log categories.
Definition: Recast.h:31
Recast build context.
Definition: SampleInterfaces.h:31
BuildContext()
Definition: SampleInterfaces.cpp:18
virtual void doStopTimer(const rcTimerLabel label)
Stops the specified performance timer.
Definition: SampleInterfaces.cpp:67
virtual void doResetLog()
Virtual functions for custom implementations.
Definition: SampleInterfaces.cpp:28
virtual void doResetTimers()
Clears all timers. (Resets all to unused.)
Definition: SampleInterfaces.cpp:56
int getLogCount() const
Returns number of log messages.
Definition: SampleInterfaces.cpp:127
virtual void doLog(const rcLogCategory category, const char *msg, const int len)
Logs a message.
Definition: SampleInterfaces.cpp:34
virtual void doStartTimer(const rcTimerLabel label)
Starts the specified performance timer.
Definition: SampleInterfaces.cpp:62
void dumpLog(const char *format,...)
Dumps the log to stdout.
Definition: SampleInterfaces.cpp:82
const char * getLogText(const int i) const
Returns log message text.
Definition: SampleInterfaces.cpp:132
virtual int doGetAccumulatedTime(const rcTimerLabel label) const
Returns the total accumulated time of the specified performance timer.
Definition: SampleInterfaces.cpp:77
OpenGL debug draw implementation.
Definition: SampleInterfaces.h:66
virtual void end()
End drawing primitives.
Definition: SampleInterfaces.cpp:254
virtual void vertex(const float *pos, unsigned int color)
Submit a vertex.
Definition: SampleInterfaces.cpp:228
virtual void texture(bool state)
Definition: SampleInterfaces.cpp:194
virtual void begin(duDebugDrawPrimitives prim, float size=1.0f)
Begin drawing primitives.
Definition: SampleInterfaces.cpp:207
virtual void depthMask(bool state)
Definition: SampleInterfaces.cpp:189
stdio file implementation.
Definition: SampleInterfaces.h:80
virtual bool isWriting() const
Definition: SampleInterfaces.cpp:292
virtual bool read(void *ptr, const size_t size)
Definition: SampleInterfaces.cpp:309
bool openForRead(const char *path)
Definition: SampleInterfaces.cpp:283
FileIO()
Definition: SampleInterfaces.cpp:263
virtual bool write(const void *ptr, const size_t size)
Definition: SampleInterfaces.cpp:302
virtual bool isReading() const
Definition: SampleInterfaces.cpp:297
virtual ~FileIO()
Definition: SampleInterfaces.cpp:269
bool openForWrite(const char *path)
Definition: SampleInterfaces.cpp:274
Provides an interface for optional logging and performance tracking of the Recast build process.
Definition: Recast.h:115
Abstract debug draw interface.
Definition: DebugDraw.h:35
Definition: RecastDump.h:23