Tactics: Western Philosophers Vs. Musicians  0.12
A turn-based tactical game combining rules and gameplay elements inspired by Final Fantasy Tactics and the Mayfair Exponential Game System. Unlike most games of this type, motion is in full, grid-less 3D.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CUpdater.h
Go to the documentation of this file.
1 // Copyright (C) 2004-2013 Dylan Blair
3 //
4 // email: dblair@alumni.cs.utexas.edu
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 
21 #ifndef CUPDATER_H
22 #define CUPDATER_H
23 
24 #include "IObject.h"
25 
26 #include <list>
27 #include <map>
28 
29 namespace OpenSkyNet {
30  namespace Core {
31  class UpdateManager;
32 
40  class CORE_DLL Updater {
41  public:
43  enum UPDATER_TYPE { BASE, AI, CAMERA, PATH_FINDER, PATH, TRANSFORM_INTERPOLATOR, PHYSICS, ANIMATION, COLLISION_DETECTOR, PHYS_VIS, TRANSFORM_CHANGE_DETECTOR, CORE_MAX, MAX=32 };
44 
46  enum UPDATER_PRIORITY { UPD_DISABLED, UPD_1, UPD_2, UPD_3, UPD_4, UPD_5, UPD_6, UPD_7, UPD_8, UPD_NUM_PRIORITIES };
47 
49  enum OBJECT_PRIORITY { OBJ_DISABLED, OBJ_1, OBJ_2, OBJ_3, OBJ_NUM_PRIORITIES };
50 
54  struct UpdateInfo {
55  OBJECT_PRIORITY _prio, _prevPrio;
57  bool _isOneShot;
58  UpdateInfo(OBJECT_PRIORITY prio_=OBJ_DISABLED, bool isOneShot_=false) : _prio(prio_),
59  _prevPrio(prio_), _prevUpdateTimeAfterReset(0), _isOneShot(isOneShot_) {}
60  virtual ~UpdateInfo() {}
61  };
62 
63  typedef std::map<Object*, UpdateInfo*> ObjMap;
64 
65  friend class Core::UpdateManager;
66  protected:
67  std::list<Object*> _objLists[OBJ_NUM_PRIORITIES];
69 
71  std::string _typeName;
73  float _interval;
77 
78  int _currPrio;
79  std::list<Object*>::iterator _currObj;
80 
82  virtual bool addObject(Object* obj_, OBJECT_PRIORITY prio_=OBJ_1, bool isOneShot_=false);
83 
85  virtual bool removeObject(Object* obj_);
86 
87  virtual void removeAllObjects();
88 
89  int getNumToUpdate(float dt_);
90  void allObjectsUpdated();
91  inline void setPriority(UPDATER_PRIORITY prio_) { _prio = prio_; }
92  public:
93  Updater() : _type(BASE), _typeName("BASE"), _prio(UPD_1), _interval(0),
94  _dtSinceAllWereUpdated(0), _prevTotalTimeForAllUpdates(0), _partialUpdate(0),
95  _currPrio(OBJ_NUM_PRIORITIES-1), _currObj(_objLists[OBJ_NUM_PRIORITIES-1].begin()) {}
96  Updater(UPDATER_TYPE type_, const char* typeName_, UPDATER_PRIORITY prio_, float interval_) : _type(type_),
97  _typeName(typeName_), _prio(prio_), _interval(interval_),
98  _dtSinceAllWereUpdated(0), _prevTotalTimeForAllUpdates(0), _partialUpdate(0),
99  _currPrio(OBJ_NUM_PRIORITIES-1), _currObj(_objLists[OBJ_NUM_PRIORITIES-1].begin()) {}
100  virtual ~Updater() {}
101 
102  inline UPDATER_TYPE getType() const { return _type; }
103  inline const std::string& getTypeName() const { return _typeName; }
104 
110  virtual bool update(float dt_);
111 
112  inline float getInterval() const { return _interval; }
113 
116  inline void setInterval(float interval_) { _interval = interval_; }
117 
119  inline Utils::uint getNumObjects() const { return static_cast<Utils::uint>(_objMap.size()); }
120 
123  Utils::uint numObjectsThatCanUpdate = 0;
124  for (ObjMap::const_iterator i = _objMap.begin(); i != _objMap.end(); i++)
125  if (i->second->_prio > OBJ_DISABLED)
126  ++numObjectsThatCanUpdate;
127  return numObjectsThatCanUpdate;
128  }
129 
130  inline bool find(Object* obj_) const {
131  if (_objMap.find(obj_) != _objMap.end())
132  return true;
133  return false;
134  }
135 
136  inline UPDATER_PRIORITY getPriority() const { return _prio; }
137 
139  OBJECT_PRIORITY getPriority(Object* obj_) const;
140 
141  virtual bool setPriority(Object* obj_, OBJECT_PRIORITY prio_);
142  };
143  }
144 }
145 
146 #define UPDATE_METHOD_COMMON_VARS \
147  _dtSinceAllWereUpdated += dt_; \
148  float objDt = 0; \
149  int numToUpdate = getNumToUpdate(dt_); \
150  int numUpdated = 0; \
151  std::list<Object*>::iterator initObj = _currObj; \
152  std::list<Object*>::iterator j(initObj); \
153  std::list<Object*>::iterator k(j);
154 
155 #endif //CUPDATER_H
float _prevUpdateTimeAfterReset
Definition: CUpdater.h:56
bool _isOneShot
Definition: CUpdater.h:57
ObjMap _objMap
Definition: CUpdater.h:68
std::list< Object * >::iterator _currObj
Definition: CUpdater.h:79
float _interval
Definition: CUpdater.h:73
virtual ~UpdateInfo()
Definition: CUpdater.h:60
Definition: CCamera.h:32
UPDATER_PRIORITY getPriority() const
Definition: CUpdater.h:136
bool find(Object *obj_) const
Definition: CUpdater.h:130
void setInterval(float interval_)
Definition: CUpdater.h:116
Utils::uint getNumObjects() const
Definition: CUpdater.h:119
UPDATER_PRIORITY
Definition: CUpdater.h:46
float getInterval() const
Definition: CUpdater.h:112
UPDATER_TYPE _type
Definition: CUpdater.h:70
UPDATER_TYPE getType() const
Definition: CUpdater.h:102
void setPriority(UPDATER_PRIORITY prio_)
Definition: CUpdater.h:91
Updater()
Definition: CUpdater.h:93
virtual ~Updater()
Definition: CUpdater.h:100
UPDATER_TYPE
Definition: CUpdater.h:43
Definition: CUpdater.h:40
int _currPrio
Definition: CUpdater.h:78
UPDATER_PRIORITY _prio
Definition: CUpdater.h:72
Utils::uint getNumObjectsThatCanUpdate() const
Definition: CUpdater.h:122
const std::string & getTypeName() const
Definition: CUpdater.h:103
float _dtSinceAllWereUpdated
Definition: CUpdater.h:74
unsigned int uint
Definition: UTypes.h:39
OBJECT_PRIORITY
Definition: CUpdater.h:49
float _prevTotalTimeForAllUpdates
Definition: CUpdater.h:75
#define CORE_DLL
Definition: CCoreDLL.h:57
float _partialUpdate
Definition: CUpdater.h:76
Definition: IObject.h:36
OBJECT_PRIORITY _prio
Definition: CUpdater.h:55
UpdateInfo(OBJECT_PRIORITY prio_=OBJ_DISABLED, bool isOneShot_=false)
Definition: CUpdater.h:58
std::map< Object *, UpdateInfo * > ObjMap
Definition: CUpdater.h:63
std::string _typeName
Definition: CUpdater.h:71
Updater(UPDATER_TYPE type_, const char *typeName_, UPDATER_PRIORITY prio_, float interval_)
Definition: CUpdater.h:96
Definition: CUpdater.h:54
Definition: CUpdateManager.h:34