[airstrike] bug in timing code
Erik Auerswald
auerswal at unix-ag.uni-kl.de
Fri Sep 2 15:16:30 EDT 2005
Hi,
> My suggested changes can be seperated in 2 steps:
>
> 1) The changes suggested above to make the timing code consistent (incl.
> updating the comments) with a time base of 100ms (what seems to be
> the intended time base at the moment, i.e. delay values would not be
> changed, actual timing would be about 10% slower).
> 2) Changing the time base to 10ms, adjusting the comments and the
> values.
>
> Step 1) does not seem to be controversial, I do not insist on step 2),
> but I would prefer it this way. If no one objects I will implement step
> 1) during the weekend.
The attached patch implements step 1...
Erik
-------------- next part --------------
diff -uNrB trunk/src/core/display.c timing-step1/src/core/display.c
--- trunk/src/core/display.c 2005-08-19 22:31:15.000000000 +0200
+++ timing-step1/src/core/display.c 2005-09-02 20:47:17.000000000 +0200
@@ -5,7 +5,7 @@
struct display display =
{
- .frame_time = FRAMERATE,
+ .frame_time = 1000/FRAMERATE, /* duration of one frame in ms */
.use_alpha = 1
};
diff -uNrB trunk/src/engine/schedule.c timing-step1/src/engine/schedule.c
--- trunk/src/engine/schedule.c 2005-08-31 07:28:41.000000000 +0200
+++ timing-step1/src/engine/schedule.c 2005-09-02 20:54:53.000000000 +0200
@@ -93,8 +93,7 @@
{
if (now >= *timer)
{
- /* convert milliseconds to frames */
- *timer = now + delay * FRAMERATE / 10;
+ *timer = now + delay_to_frames(delay);
return 1;
}
else
diff -uNrB trunk/src/engine/schedule.h timing-step1/src/engine/schedule.h
--- trunk/src/engine/schedule.h 2005-08-19 22:31:03.000000000 +0200
+++ timing-step1/src/engine/schedule.h 2005-09-02 20:58:43.000000000 +0200
@@ -16,11 +16,16 @@
void schedule(unsigned int delay, int priority, void (*f)(msg_t msg, void *target), msg_t msg, void *target);
void schedule_advance(unsigned int step, int priority);
int frame_nr(void);
+
/* Return 1 and set the timer if more than delay passed since last time,
else return 0 (meaning "try later").
- 'delay' is in milliseconds.
+ 'delay' is in 100 milliseconds.
*/
int rate_limit(unsigned int delay, unsigned int *timer);
-
+/* convert delay (in 100 milliseconds) to game frames */
+static INLINE unsigned int delay_to_frames(unsigned int delay)
+{
+ return (delay * FRAMERATE) / 10;
+}
#endif
diff -uNrB trunk/src/engine/sprite.c timing-step1/src/engine/sprite.c
--- trunk/src/engine/sprite.c 2005-08-19 22:31:03.000000000 +0200
+++ timing-step1/src/engine/sprite.c 2005-09-02 20:58:17.000000000 +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_to_frames(delay),SCHED_NORMAL,send_alarm,msg,target);
}
/* Frame checklist
diff -uNrB trunk/src/sprites/biplane.c timing-step1/src/sprites/biplane.c
--- trunk/src/sprites/biplane.c 2005-08-19 22:31:28.000000000 +0200
+++ timing-step1/src/sprites/biplane.c 2005-09-02 21:02:09.000000000 +0200
@@ -19,7 +19,7 @@
#define FUEL_MAX_AMOUNT 1000
#define BOMB_MAX_COUNT 12
-/* how often (in 10 ms) plane can do something */
+/* how often (in 100 ms) plane can do something */
#define PLANE_SAY_DELAY 5
#define PLANE_PUFF_DELAY 2
@@ -47,7 +47,7 @@
{
.engine_strength = 0.0,
.turn_amount = 0.001,
- .bomb_delay = 1200000, /* N * 10ms */
+ .bomb_delay = 1200000, /* N * 100ms */
.bullet_delay = 30000000,
.hitpoints = 0,
.mass = 1,
@@ -62,7 +62,7 @@
{
.engine_strength = 0.08,
.turn_amount = 0.05,
- .bomb_delay = 12, /* N * 10ms */
+ .bomb_delay = 12, /* N * 100ms */
.bullet_delay = 3,
.hitpoints = 30,
.mass = 1,
@@ -78,7 +78,7 @@
{
.engine_strength = 0.0,
.turn_amount = 0.02,
- .bomb_delay = 1200, /* N * 10ms */
+ .bomb_delay = 1200, /* N * 100ms */
.bullet_delay = 3000,
.hitpoints = 30,
.mass = 1,
@@ -93,7 +93,7 @@
{
.engine_strength = 0.08,
.turn_amount = 0.05,
- .bomb_delay = 12, /* N * 10ms */
+ .bomb_delay = 12, /* N * 100ms */
.bullet_delay = 3,
.hitpoints = 30,
.mass = 1,
diff -uNrB trunk/src/tests/testengine.c timing-step1/src/tests/testengine.c
--- trunk/src/tests/testengine.c 2005-08-19 22:30:42.000000000 +0200
+++ timing-step1/src/tests/testengine.c 2005-09-02 21:04:41.000000000 +0200
@@ -58,7 +58,8 @@
if (reason) {
ui_message(reason,400,300,ALIGN_CENTER,big_font,20);
}
- for (idx = 0; idx < 2*FRAMERATE; idx++) {
+ /* wait 2s */
+ for (idx = 0; idx < (int)delay_to_frames(20); idx++) {
/* update screen while waiting */
draw_frame();
game_frame();
More information about the airstrike
mailing list