Debian Codegraph @

RecastDemo/Include/SampleInterfaces.h

raw symbols SCIP
1 //
2 // Copyright (c) 2009-2010 Mikko Mononen [email protected]
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
29 /// Recast build context.
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
45 /// Dumps the log to stdout.
46 void dumpLog(const char* format, ...);
47 /// Returns number of log messages.
48 int getLogCount() const;
49 /// Returns log message text.
50 const char* getLogText(const int i) const;
51
52 protected:
53 /// Virtual functions for custom implementations.
54 ///@{
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;
61 ///@}
62 };
63
64 /// OpenGL debug draw implementation.
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
78 /// stdio file implementation.
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