nice level intros

This commit is contained in:
2011-03-22 23:01:44 +01:00
parent e2fd3393d3
commit 3e17f56760
13 changed files with 235 additions and 19 deletions
-1
View File
@@ -147,7 +147,6 @@ void LabelCentered (int id, const char* caption, int x, int y) {
view = EngineGetView ();
assert (view);
SelectFont("console.ttf size=23");
view->DrawGLStringMeasure(caption, &width, &height);
view->DrawGLString(x - 0.5 * width, y + height * 0.5, caption);
}
+27
View File
@@ -377,6 +377,33 @@ bool CheckTimer(const std::string &id) {
}
*/
// /** \brief Starts a timer with the given id that expires after sec seconds */
void StartTimer(const std::string &id, float sec) {
if (!ModelInstance) {
LogError ("Couldn't query Timer: Model not initialized!");
}
ModelInstance->StartTimer(id, sec);
}
// /** \brief Checks whether a timer expired */
bool CheckTimer(const std::string &id) {
if (!ModelInstance) {
LogError ("Couldn't query Timer: Model not initialized!");
}
return ModelInstance->CheckTimer(id);
}
// /** \brief Checks whether a timer expired */
float GetTimer(const std::string &id) {
if (!ModelInstance) {
LogError ("Couldn't query Timer: Model not initialized!");
}
return ModelInstance->GetTimer(id);
}
}
+90 -9
View File
@@ -16,6 +16,55 @@ const unsigned int NullEntityId = std::numeric_limits<unsigned int>::max() - 1;
struct EntityBase;
struct Timer {
Timer() :
mRunning(false),
mCurrentValue(0.)
{}
Timer (float sec_value) :
mRunning(true),
mCurrentValue (sec_value)
{}
Timer (const Timer& timer) :
mRunning (timer.mRunning),
mCurrentValue (timer.mCurrentValue)
{}
Timer& operator= (const Timer& timer) {
if (this != &timer) {
mRunning = timer.mRunning;
mCurrentValue = timer.mCurrentValue;
}
return *this;
}
void Set (float sec_value) {
mCurrentValue = sec_value;
}
float Get () {
return mCurrentValue;
}
bool Query() {
if (mCurrentValue <= 0.)
return true;
return false;
}
void Start() {
mRunning = true;
}
void Pause() {
mRunning = false;
}
bool Update(float sec_value) {
if (mRunning)
mCurrentValue -= sec_value;
return Query();
}
bool mRunning;
float mCurrentValue;
};
/** \brief Represents the current state of the Engine
*
* Represents the State of the Engine and is unaware of anything except itself.
@@ -42,6 +91,7 @@ class ModelBase : public Module {
mDurationApplicationStart = current_frame;
mDeltaSec = current_frame - last_frame;
last_frame = current_frame;
UpdateTimers (mDeltaSec);
}
float GetFrameDuration () {
return mDeltaSec;
@@ -103,30 +153,63 @@ class ModelBase : public Module {
};
unsigned int GetGameState () { return mGameState; };
/*
void StartTimer(const std::string &id, float msec) {
void StartTimer(const std::string &id, float sec) {
TimerIter cur_timer = mTimers.find(id);
if (cur_timer != mTimers.end()) {
cur_timer->second.Set(msec);
cur_timer->second.Set(sec);
cur_timer->second.Start();
return;
}
mTimers[id] = Timer(id, msec);
mTimers[id] = Timer(sec);
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 true;
}
return cur_timer->second.Query();
}
*/
float GetTimer (const std::string &id) {
TimerIter cur_timer = mTimers.find(id);
if (cur_timer == mTimers.end()) {
return 0.;
}
return cur_timer->second.Get();
}
void PauseTimers () {
for (TimerIter iter = mTimers.begin(); iter != mTimers.end(); iter++) {
iter->second.Pause();
}
}
void ResumeTimers () {
for (TimerIter iter = mTimers.begin(); iter != mTimers.end(); iter++) {
iter->second.Start();
}
}
void UpdateTimers (float sec) {
TimerIter iter = mTimers.begin();
while (iter != mTimers.end()) {
bool timer_running = iter->second.Update(sec);
if (timer_running) {
LogDebug ("Erasing expired timer %s", iter->first.c_str());
mTimers.erase(iter++);
}
else
++iter;
}
}
protected:
/** \brief Initializes the system */
@@ -153,10 +236,8 @@ class ModelBase : public Module {
/** \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 -3
View File
@@ -26,10 +26,13 @@ float GetFrameDuration ();
float GetDurationApplicationStart ();
// /** \brief Starts a timer with the given id that expires after sec seconds */
// void StartTimer(const std::string &id, float sec);
//
void StartTimer(const std::string &id, float sec);
// /** \brief Checks whether a timer expired */
// bool CheckTimer(const std::string &id);
bool CheckTimer(const std::string &id);
// /** \brief Checks whether a timer expired */
float GetTimer(const std::string &id);
}