9
3

SampleInterfaces.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. #ifndef SAMPLEINTERFACES_H
  19. #define SAMPLEINTERFACES_H
  20. #include "DebugDraw.h"
  21. #include "Recast.h"
  22. #include "RecastDump.h"
  23. #include "PerfTimer.h"
  24. // These are example implementations of various interfaces used in Recast and Detour.
  25. /// Recast build context.
  26. class BuildContext : public rcContext
  27. {
  28. TimeVal m_startTime[RC_MAX_TIMERS];
  29. TimeVal m_accTime[RC_MAX_TIMERS];
  30. static const int MAX_MESSAGES = 1000;
  31. const char* m_messages[MAX_MESSAGES];
  32. int m_messageCount;
  33. static const int TEXT_POOL_SIZE = 8000;
  34. char m_textPool[TEXT_POOL_SIZE];
  35. int m_textPoolSize;
  36. public:
  37. BuildContext();
  38. /// Dumps the log to stdout.
  39. void dumpLog(const char* format, ...);
  40. /// Returns number of log messages.
  41. int getLogCount() const;
  42. /// Returns log message text.
  43. const char* getLogText(const int i) const;
  44. protected:
  45. /// Virtual functions for custom implementations.
  46. ///@{
  47. virtual void doResetLog();
  48. virtual void doLog(const rcLogCategory category, const char* msg, const int len);
  49. virtual void doResetTimers();
  50. virtual void doStartTimer(const rcTimerLabel label);
  51. virtual void doStopTimer(const rcTimerLabel label);
  52. virtual int doGetAccumulatedTime(const rcTimerLabel label) const;
  53. ///@}
  54. };
  55. /// OpenGL debug draw implementation.
  56. class DebugDrawGL : public duDebugDraw
  57. {
  58. public:
  59. virtual void depthMask(bool state);
  60. virtual void texture(bool state);
  61. virtual void begin(duDebugDrawPrimitives prim, float size = 1.0f);
  62. virtual void vertex(const float* pos, unsigned int color);
  63. virtual void vertex(const float x, const float y, const float z, unsigned int color);
  64. virtual void vertex(const float* pos, unsigned int color, const float* uv);
  65. virtual void vertex(const float x, const float y, const float z, unsigned int color, const float u, const float v);
  66. virtual void end();
  67. };
  68. /// stdio file implementation.
  69. class FileIO : public duFileIO
  70. {
  71. FILE* m_fp;
  72. int m_mode;
  73. public:
  74. FileIO();
  75. virtual ~FileIO();
  76. bool openForWrite(const char* path);
  77. bool openForRead(const char* path);
  78. virtual bool isWriting() const;
  79. virtual bool isReading() const;
  80. virtual bool write(const void* ptr, const size_t size);
  81. virtual bool read(void* ptr, const size_t size);
  82. private:
  83. // Explicitly disabled copy constructor and copy assignment operator.
  84. FileIO(const FileIO&);
  85. FileIO& operator=(const FileIO&);
  86. };
  87. #endif // SAMPLEINTERFACES_H