summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2005-04-02 23:47:10 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2005-04-02 23:47:10 +0000
commit53120c1bcd812d7036ab3303e0682781f03e42cb (patch)
tree0faa1c8efded2380cffd2ea618bd2f795485e9eb
parentd98bd419b419be1d5069c0fe77fa2a7b6379e45f (diff)
downloadmana-53120c1bcd812d7036ab3303e0682781f03e42cb.tar.gz
mana-53120c1bcd812d7036ab3303e0682781f03e42cb.tar.bz2
mana-53120c1bcd812d7036ab3303e0682781f03e42cb.tar.xz
mana-53120c1bcd812d7036ab3303e0682781f03e42cb.zip
Fixed whobbly walking by separating some logic from the framerate.
-rw-r--r--src/engine.cpp47
-rw-r--r--src/engine.h1
-rw-r--r--src/game.cpp21
3 files changed, 49 insertions, 20 deletions
diff --git a/src/engine.cpp b/src/engine.cpp
index c15d1964..e20e453e 100644
--- a/src/engine.cpp
+++ b/src/engine.cpp
@@ -242,6 +242,36 @@ Engine::~Engine()
delete itemset;
}
+void Engine::logic()
+{
+ // Update beings
+ std::list<Being*>::iterator beingIterator = beings.begin();
+ while (beingIterator != beings.end())
+ {
+ Being *being = (*beingIterator);
+
+ if (being->job < 10) { // A player
+ if (being->action != STAND && being->action != SIT
+ && being->action != DEAD) {
+ being->frame =
+ (get_elapsed_time(being->walk_time) * 4) / (being->speed);
+
+ if (being->frame >= 4) {
+ being->nextStep();
+ }
+ }
+ }
+
+ if (being->action == MONSTER_DEAD && being->frame >= 20) {
+ delete being;
+ beingIterator = beings.erase(beingIterator);
+ }
+ else {
+ beingIterator++;
+ }
+ }
+}
+
void Engine::draw()
{
// Get the current mouse position
@@ -349,15 +379,6 @@ void Engine::draw()
being->emotion = 0;
}
}
- if (being->action != STAND && being->action != SIT
- && being->action != DEAD) {
- being->frame =
- (get_elapsed_time(being->walk_time) * 4) / (being->speed);
-
- if (being->frame >= 4) {
- being->nextStep();
- }
- }
}
else if (being->job == 45) { // Draw a warp
} else { // Draw a monster
@@ -389,13 +410,7 @@ void Engine::draw()
}
}
- if (being->action == MONSTER_DEAD && being->frame >= 20) {
- delete being;
- beingIterator = beings.erase(beingIterator);
- }
- else {
- beingIterator++;
- }
+ beingIterator++;
// nodes are ordered so if the next being y is > then the
// last drawed for fringe layer, draw the missing lines
diff --git a/src/engine.h b/src/engine.h
index 6454e890..72ecf4b7 100644
--- a/src/engine.h
+++ b/src/engine.h
@@ -84,6 +84,7 @@ class Engine {
Engine();
~Engine();
+ void logic();
void draw();
};
diff --git a/src/game.cpp b/src/game.cpp
index 19a4c88f..62f15abe 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -51,6 +51,7 @@ int server_tick;
int fps = 0, frame = 0, current_npc = 0;
bool displayPathToMouse = false;
int startX = 0, startY = 0;
+int gameTime = 0;
OkDialog *deathNotice = NULL;
@@ -96,7 +97,8 @@ Uint32 second(Uint32 interval, void *param)
return interval;
}
-short get_elapsed_time(short start_time) {
+short get_elapsed_time(short start_time)
+{
if (start_time <= tick_time) {
return (tick_time - start_time) * 10;
}
@@ -105,13 +107,23 @@ short get_elapsed_time(short start_time) {
}
}
-void game() {
+void game()
+{
do_init();
Engine *engine = new Engine();
+ gameTime = tick_time;
+
while (state != EXIT)
{
- do_input();
+ while (get_elapsed_time(gameTime) > 0)
+ {
+ do_input();
+ engine->logic();
+ gameTime++;
+ }
+ gameTime = tick_time;
+
gui->logic();
engine->draw();
graphics->updateScreen();
@@ -172,7 +184,8 @@ void do_init()
remove("./docs/packet.list");
}
-void do_exit() {
+void do_exit()
+{
}
void do_input()