bug in timing code
Erik Auerswald
auerswal at unix-ag.uni-kl.de
Wed Aug 31 05:09:38 EDT 2005
Hi,
there is a bug in engine/schedule.c, function rate_limit(): The
transformation from delay in units of 10ms to gameframes is not correct.
The same wrong formula is used in engine/sprite.c, function
sprite_alarm(). The correct formula is delay*10/time_for_one_frame.
Using the name FRAMERATE for the time of one frame is a litte bit
confusing, I suggest using the name FRAMETIME.
The attached patch corrects these errors and renames FRAMERATE to
FRAMETIME. I did not apply it to svn because all timing values in the
code are tailored to this incorrect behaviour, therefore the delay
values need to be multiplied by 9 to keep the current timing. I did not
(yet) search for all the places where delays are specified...
Erik
-------------- next part --------------
diff -uNrB airstrike/src/core/display.c airstrike-timing/src/core/display.c
--- airstrike/src/core/display.c 2005-08-31 10:26:46.021276848 +0200
+++ airstrike-timing/src/core/display.c 2005-08-31 10:41:42.785113642 +0200
@@ -5,7 +5,7 @@
struct display display =
{
- .frame_time = FRAMERATE,
+ .frame_time = FRAMETIME,
.use_alpha = 1
};
diff -uNrB airstrike/src/core/display.h airstrike-timing/src/core/display.h
--- airstrike/src/core/display.h 2005-08-31 10:26:46.121251471 +0200
+++ airstrike-timing/src/core/display.h 2005-08-31 10:41:42.796110841 +0200
@@ -4,7 +4,7 @@
#include <SDL.h>
#include "image.h"
-#define FRAMERATE 30
+#define FRAMETIME 30
#define DIRTY_TILE_SIZE 64
extern struct display
diff -uNrB airstrike/src/engine/schedule.c airstrike-timing/src/engine/schedule.c
--- airstrike/src/engine/schedule.c 2005-08-31 10:26:44.666620716 +0200
+++ airstrike-timing/src/engine/schedule.c 2005-08-31 10:42:31.240771642 +0200
@@ -94,7 +94,7 @@
if (now >= *timer)
{
/* convert milliseconds to frames */
- *timer = now + delay * FRAMERATE / 10;
+ *timer = now + (delay * 10) / FRAMETIME;
return 1;
}
else
diff -uNrB airstrike/src/engine/sprite.c airstrike-timing/src/engine/sprite.c
--- airstrike/src/engine/sprite.c 2005-08-31 10:26:43.423936160 +0200
+++ airstrike-timing/src/engine/sprite.c 2005-08-31 10:43:01.355101264 +0200
@@ -63,7 +63,7 @@
void sprite_alarm(unsigned int delay, sprite_t *target, msg_t msg)
{
- schedule(delay*FRAMERATE/10,SCHED_NORMAL,send_alarm,msg,target);
+ schedule((delay*10)/FRAMETIME,SCHED_NORMAL,send_alarm,msg,target);
}
/* Frame checklist
diff -uNrB airstrike/src/tests/testengine.c airstrike-timing/src/tests/testengine.c
--- airstrike/src/tests/testengine.c 2005-08-31 10:26:41.786351845 +0200
+++ airstrike-timing/src/tests/testengine.c 2005-08-31 10:41:43.974810619 +0200
@@ -58,7 +58,7 @@
if (reason) {
ui_message(reason,400,300,ALIGN_CENTER,big_font,20);
}
- for (idx = 0; idx < 2*FRAMERATE; idx++) {
+ for (idx = 0; idx < 2*FRAMETIME; idx++) {
/* update screen while waiting */
draw_frame();
game_frame();
More information about the airstrike
mailing list