Recast Navigation
Navigation-mesh Toolset for Games
Loading...
Searching...
No Matches
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#pragma once
20
21#include "DebugDraw.h"
22#include "PerfTimer.h"
23#include "Recast.h"
24#include "RecastDump.h"
25
26#include <array>
27#include <string>
28#include <vector>
29
30// These are example implementations of various interfaces used in Recast and Detour.
31
33class BuildContext final : public rcContext
34{
35 std::array<TimeVal, RC_MAX_TIMERS> startTime;
36 std::array<TimeVal, RC_MAX_TIMERS> accTime;
37
38 std::vector<std::string> logMessages;
39
40public:
42
44 void dumpLog(const char* format, ...);
46 [[nodiscard]] int getLogCount() const;
48 [[nodiscard]] const char* getLogText(int i) const;
49
50protected:
51 void doResetLog() override;
52 void doLog(rcLogCategory category, const char* msg, const int len) override;
53 void doResetTimers() override;
54 void doStartTimer(rcTimerLabel label) override;
55 void doStopTimer(rcTimerLabel label) override;
56 [[nodiscard]] int doGetAccumulatedTime(rcTimerLabel label) const override;
57};
58
61{
62public:
63 void depthMask(bool state) override;
64 void texture(bool state) override;
65 void begin(duDebugDrawPrimitives prim, float size = 1.0f) override;
66 void vertex(const float* pos, unsigned int color) override;
67 void vertex(const float* pos, unsigned int color, const float* uv) override;
68 void vertex(float x, float y, float z, unsigned int color) override;
69 void vertex(float x, float y, float z, unsigned int color, float u, float v) override;
70 void end() override;
71};
72
74class FileIO final : public duFileIO
75{
76public:
77 FileIO() = default;
78 FileIO(const FileIO&) = delete;
79 FileIO& operator=(const FileIO&) = delete;
80 FileIO(FileIO&&) = default;
81 FileIO& operator=(FileIO&&) = default;
82 ~FileIO() override;
83
84 bool openForWrite(const char* path);
85 bool openForRead(const char* path);
86 [[nodiscard]] bool isWriting() const override;
87 [[nodiscard]] bool isReading() const override;
88 bool write(const void* ptr, size_t size) override;
89 bool read(void* ptr, size_t size) override;
90 size_t getFileSize() const;
91
92 static void scanDirectory(const std::string& path, const std::string& ext, std::vector<std::string>& fileList);
93private:
94 FILE* fp = nullptr;
95 enum class Mode { none, reading, writing };
96 Mode mode = Mode::none;
97};
duDebugDrawPrimitives
Definition DebugDraw.h:26
rcTimerLabel
Recast performance timer categories.
Definition Recast.h:40
rcLogCategory
Recast log categories.
Definition Recast.h:31
Recast build context.
Definition SampleInterfaces.h:34
BuildContext()
Definition SampleInterfaces.cpp:17
void doStartTimer(rcTimerLabel label) override
Starts the specified performance timer.
Definition SampleInterfaces.cpp:58
int getLogCount() const
Returns number of log messages.
Definition SampleInterfaces.cpp:128
void doLog(rcLogCategory category, const char *msg, const int len) override
Logs a message.
Definition SampleInterfaces.cpp:27
const char * getLogText(int i) const
Returns log message text.
Definition SampleInterfaces.cpp:133
void doResetTimers() override
Clears all timers. (Resets all to unused.)
Definition SampleInterfaces.cpp:50
void doResetLog() override
Clears all log entries.
Definition SampleInterfaces.cpp:22
int doGetAccumulatedTime(rcTimerLabel label) const override
Returns the total accumulated time of the specified performance timer.
Definition SampleInterfaces.cpp:77
void dumpLog(const char *format,...)
Dumps the log to stdout.
Definition SampleInterfaces.cpp:82
void doStopTimer(rcTimerLabel label) override
Stops the specified performance timer.
Definition SampleInterfaces.cpp:63
OpenGL debug draw implementation.
Definition SampleInterfaces.h:61
void begin(duDebugDrawPrimitives prim, float size=1.0f) override
Begin drawing primitives.
Definition SampleInterfaces.cpp:211
void end() override
End drawing primitives.
Definition SampleInterfaces.cpp:258
void texture(bool state) override
Definition SampleInterfaces.cpp:198
void vertex(const float *pos, unsigned int color) override
Submit a vertex.
Definition SampleInterfaces.cpp:232
void depthMask(bool state) override
Definition SampleInterfaces.cpp:193
stdio file implementation.
Definition SampleInterfaces.h:75
FileIO & operator=(const FileIO &)=delete
bool isWriting() const override
Definition SampleInterfaces.cpp:305
bool openForRead(const char *path)
Definition SampleInterfaces.cpp:290
bool write(const void *ptr, size_t size) override
Definition SampleInterfaces.cpp:315
bool isReading() const override
Definition SampleInterfaces.cpp:310
size_t getFileSize() const
Definition SampleInterfaces.cpp:335
FileIO(const FileIO &)=delete
~FileIO() override
Definition SampleInterfaces.cpp:267
FileIO(FileIO &&)=default
FileIO & operator=(FileIO &&)=default
bool read(void *ptr, size_t size) override
Definition SampleInterfaces.cpp:325
FileIO()=default
bool openForWrite(const char *path)
Definition SampleInterfaces.cpp:275
static void scanDirectory(const std::string &path, const std::string &ext, std::vector< std::string > &fileList)
Definition SampleInterfaces.cpp:354
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:25