intermediate commit: still working on view state managing

This commit is contained in:
2010-11-27 08:38:32 +01:00
parent 3cbbedde7e
commit f8e5b7e873
9 changed files with 110 additions and 52 deletions
+2 -1
View File
@@ -44,6 +44,7 @@ class Logging;
class Commands;
class Variables;
class Variable;
class Timer;
/** \brief The outermost class which contains just everything!
*
@@ -74,7 +75,7 @@ class Engine : public Module {
mSoundManager = NULL;
}
virtual void MainLoop () {
void MainLoop () {
OnMainLoop ();
}
+24 -1
View File
@@ -49,7 +49,7 @@ void ModelBase::OnDestroy () {
*/
void ModelBase::Process () {
// Process the controllers and state of all entities
std::map<unsigned int, EntityBase*>::iterator entity_iter = mEntities.begin();
EntityIter entity_iter = mEntities.begin();
do {
if (entity_iter->second == NULL) {
LogError ("Entity with id %d does not exist!", entity_iter->first);
@@ -58,6 +58,12 @@ void ModelBase::Process () {
entity_iter++;
} while (entity_iter != mEntities.end());
// Update the timers
for (TimerIter timer_iter = mTimers.begin(); timer_iter != mTimers.end(); timer_iter++) {
timer_iter->second.Update(mDeltaSec);
timer_iter++;
}
// simulate the world
mPhysics->Simulate (mDeltaSec, this);
@@ -285,6 +291,23 @@ EntityPhysicState * GetEntityPhysicState (unsigned int id) {
return NULL;
}
void StartTimer(const std::string &id, float sec) {
if (!ModelInstance) {
LogError ("Couldn't execute GetEntity(): Model not initialized!");
}
ModelInstance->StartTimer(id, sec);
}
bool CheckTimer(const std::string &id) {
if (!ModelInstance) {
LogError ("Couldn't execute GetEntity(): Model not initialized!");
}
return ModelInstance->CheckTimer(id);
}
}
+29
View File
@@ -3,6 +3,7 @@
#include "Engine.h"
#include "EntityBase.h"
#include "Timer.h"
namespace Engine {
@@ -79,6 +80,29 @@ class ModelBase : public Module {
};
unsigned int GetGameState () { return mGameState; };
void StartTimer(const std::string &id, float msec) {
TimerIter cur_timer = mTimers.find(id);
if (cur_timer != mTimers.end()) {
cur_timer->second.Set(msec);
cur_timer->second.Start();
return;
}
mTimers[id] = Timer(id, msec);
assert (mTimers.size() > 0);
assert (mTimers[id].IsActive() == true);
}
bool CheckTimer(const std::string &id) {
TimerIter cur_timer = mTimers.find(id);
if (cur_timer == mTimers.end()) {
return false;
}
return cur_timer->second.Query();
}
protected:
/** \brief Initializes the system */
virtual int OnInit (int argc, char* argv[]);
@@ -99,9 +123,14 @@ class ModelBase : public Module {
/** \brief contains all Engine::Entities */
std::map<unsigned int, EntityBase *> mEntities;
typedef std::map<unsigned int, EntityBase *>::iterator EntityIter;
/** \brief contains all Engine::Entities that ceased to exist */
std::vector<unsigned int> mKilledEntities;
std::map<std::string, Timer> mTimers;
typedef std::map<std::string, Timer>::iterator TimerIter;
unsigned int mEntityIdCounter;
unsigned int mPlayerEntityId;
+6
View File
@@ -9,6 +9,12 @@ unsigned int GetPlayerEntityId ();
/** \brief Returns the duration of the frame in seconds */
float GetFrameDuration ();
/** \brief Starts a timer with the given id that expires after sec seconds */
void StartTimer(const std::string &id, float sec);
/** \brief Checks whether a timer expired */
bool CheckTimer(const std::string &id);
}
#endif /* _MODELGLOBAL_H */