Atoms Crowd  7.0.0
RecastContext.h
1 #pragma once
2 // ===========================================================================
3 // Copyright (c) 2015 Toolchefs Ltd. All rights reserved.
4 //
5 // Use of this software is subject to the terms of the Toolchefs license
6 // agreement provided at the time of installation or download, or which
7 // otherwise accompanies this software in either electronic or hard copy form.
8 // ===========================================================================
9 #ifndef ATOMS_UNREAL
10 #include <AtomsUtils/Globals.h>
11 #include <AtomsUtils/NavigationMesh/Recast/Recast.h>
12 #include <AtomsUtils/Logger.h>
13 #include <chrono>
14 #include <map>
15 
16 namespace AtomsUtils
17 {
19  class RecastContext: public rcContext
20  {
21  typedef std::pair<std::chrono::high_resolution_clock::time_point, std::chrono::high_resolution_clock::time_point> Timer;
22 
23  public:
24  inline RecastContext(bool state = true) : rcContext(state) {}
25  virtual ~RecastContext() {}
26 
27  private:
28 
29  virtual void doLog(const rcLogCategory category, const char* msg, const int len)
30  {
31  switch (category)
32  {
33  case rcLogCategory::RC_LOG_ERROR:
34  {
35  Logger::error() << msg;
36  break;
37  }
38  case rcLogCategory::RC_LOG_WARNING:
39  {
40  Logger::warning() << msg;
41  break;
42  }
43  case rcLogCategory::RC_LOG_PROGRESS:
44  {
45  Logger::info() << msg;
46  break;
47  }
48  default:
49  break;
50  }
51  }
52 
54  virtual void doResetTimers() { m_timers.clear();}
55 
58  virtual void doStartTimer(const rcTimerLabel label)
59  {
60  m_timers[label] = Timer(std::chrono::high_resolution_clock::now(), std::chrono::high_resolution_clock::now());
61  }
62 
65  virtual void doStopTimer(const rcTimerLabel label)
66  {
67  m_timers[label].second = std::chrono::high_resolution_clock::now();
68  }
69 
73  virtual int doGetAccumulatedTime(const rcTimerLabel label) const {
74  auto it = m_timers.find(label);
75  if (it == m_timers.end())
76  return -1;
77  return static_cast<int>(std::chrono::duration_cast<std::chrono::microseconds>(it->second.second - it->second.first).count());
78  }
79 
80  std::map<rcTimerLabel, Timer> m_timers;
81 
82  };
83 }
84 #endif
static LogProxy warning()
Get logger proxy warning.
static LogProxy error()
Get logger proxy error.
static LogProxy info()
Get logger proxy info.
Base64 encode/decode.
Definition: RecastContext.h:20
Definition: Recast.h:113
rcContext(bool state=true)
Definition: Recast.h:118
AtomsCore namespace.
Definition: Base64.h:13
rcTimerLabel
Definition: Recast.h:46
rcLogCategory
Definition: Recast.h:37