i6engine  1.0
ModuleController.h
Go to the documentation of this file.
1 /*
2  * i6engine
3  * Copyright (2016) Daniel Bonrath, Michael Baer, All rights reserved.
4  *
5  * This file is part of i6engine; i6engine is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
25 #ifndef __I6ENGINE_CORE_MODULECONTROLLER_H__
26 #define __I6ENGINE_CORE_MODULECONTROLLER_H__
27 
28 #include <condition_variable>
29 #include <cstdint>
30 #include <mutex>
31 #include <string>
32 
34 
36 
37 namespace boost {
38  class thread;
39 } /* boost */
40 
41 namespace i6e {
42 namespace core {
43 
44  class EngineCoreController;
45  class MessagingController;
46  class SubSystemController;
47  class Timer;
48 
49  enum class Subsystem;
50 
51  enum class SubsystemType {
52  Ticking,
53  Waiting
54  };
55 
60  friend class SubSystemController;
61 
62  public:
67 
71  virtual ~ModuleController();
72 
78  void startThreadTicking(const uint32_t lngFrameTime);
79 
85  void startThreadWaiting(const std::set<Subsystem> & waitingFor);
86 
91  inline uint32_t getFrameTime() const {
92  return _frameTime;
93  }
94 
99  _subsystemController = ssc;
100  _ctrl = ecc;
101  _messagingController = mc;
102  }
103 
107  virtual void OnThreadStart() = 0;
108 
112  virtual void Tick() = 0;
113 
117  virtual void ShutDown() = 0;
118 
120  return _subsystem;
121  }
122 
123  protected:
128 
132  uint32_t _frameTime;
133 
138 
142  void processMessages() override;
143 
144  private:
149  inline void setTimer(Timer * ptrTimer) {
150  _ptrTimer = ptrTimer;
151  }
152 
157  inline Timer * getTimer() const {
158  return _ptrTimer;
159  }
160 
164  void runLoopTicking();
165  void runLoopWaiting();
166 
170  EngineCoreController * _ctrl;
171 
175  Timer * _ptrTimer;
176 
180  bool _isRunning;
181 
185  SubSystemController * _subsystemController;
186 
190  SubsystemType _type;
191 
195  std::set<Subsystem> _waitingSubsystems;
196 
200  std::set<Subsystem> _notifiedSubsystems;
201 
205  std::map<Subsystem, std::vector<Message::Ptr>> _waitingMessages;
206 
210  std::vector<Message::Ptr> _messages;
211 
212  mutable std::mutex _lock;
213  std::condition_variable _conditionVariable;
214 
215 #ifdef ISIXE_WITH_PROFILING
216 
219  uint64_t _lastTime;
220 
224  uint16_t _fps;
225 
229  uint16_t _expectedFps;
230 #endif /* ISIXE_WITH_PROFILING */
231 
235  inline void setRunning(bool b) {
236  _isRunning = b;
237  }
238 
242  inline bool getRunning() const {
243  return _isRunning;
244  }
245 
246  void deliverMessageInternal(const ReceivedMessagePtr & msg) override;
247 
248  void stop() {
249  std::unique_lock<std::mutex> ul(_lock);
250  _conditionVariable.notify_one();
251  }
252 
256  ModuleController(const ModuleController &) = delete;
257 
261  ModuleController & operator=(const ModuleController &) = delete;
262  };
263 
264 } /* namespace core */
265 } /* namespace i6e */
266 
267 #endif /* __I6ENGINE_CORE_MODULECONTROLLER_H__ */
268 
Subsystem getSubsystem() const
MessagingController * _messagingController
pointer to MessagingController
Part of the Subsystem that keeps the whole module running.
uint32_t getFrameTime() const
Gets the frametime of this Subsystem.
Interface for every class that wants to subscribe to the messaging system.
Central controller for messaging between subsystems and subsystems of different clients.
this class is used as an abstraction layer
void setController(SubSystemController *ssc, EngineCoreController *ecc, MessagingController *mc)
registers necessary controllers for this Subsystem
Subsystem _subsystem
the Subsystem
boost::shared_ptr< ReceivedMessage > ReceivedMessagePtr
#define ISIXE_CORE_API
uint32_t _frameTime
the frame time of the Subsystem
This class is used as an abstraction layer.
This class provides gametime-synchronized Timers. They are controlled by the Scheduler.
Definition: Timer.h:49