diff --git a/src/kos32/main.c b/src/kos32/main.c
index 3ccbb5bce6d8930d297fe3a4ab420a8a66420694..dc29252ae4974231831827eb147977b634db2973 100644 (file)
--- a/src/kos32/main.c
+++ b/src/kos32/main.c
#include "system.h"
#include "input.h"
-#include "my.h" // fexists
#include "player.h" // pl1 pl2
#include "menu.h" // G_keyf
#include "error.h" // logo
#include "music.h" // S_initmusic S_updatemusic S_donemusic
#include "render.h" // R_init R_draw R_done
-static int ticks = 0;
static int quit = 0;
static videomode_size_t wlist[3] = {
{ 320, 200, 0 },
R_done();
MUS_done();
S_done();
- M_shutdown();
puts("\nCRITICAL ERROR:");
va_start(ap, s);
vprintf(s, ap);
static void poll_events (void) {
int ev, key, button, code, ch, k;
- while(!!(ev = CheckEvent())) {
+ while((ev = CheckEvent()) != KOS32_EVENT_NONE) {
switch (ev) {
case KOS32_EVENT_REDRAW:
- return; /* force redraw */
+ if (buf != NULL) {
+ Y_repaint(); /* redraw window */
+ }
+ break;
case KOS32_EVENT_KEYBOARD:
key = GetKey();
if ((key & 0xff) == 0) {
}
}
-static void step (void) {
- poll_events();
- MUS_update();
- long t = GetTimeCountPro(); /* ns */
- if (t - ticks > DELAY * 1000000) {
- ticks = t;
- G_act();
+static void game_loop (void) {
+ static long ticks; /* ns */
+ ticks = GetTimeCountPro();
+ while (!quit) {
+ poll_events();
+ MUS_update();
+ long t = GetTimeCountPro(); /* ns */
+ int n = (t - ticks) / ((DELAY + 1) * 1000000);
+ ticks = ticks + n * ((DELAY + 1) * 1000000);
+ if (n > 0) {
+ while (n) {
+ G_act();
+ n -= 1;
+ }
+ R_draw();
+ }
+ Delay(1);
}
- R_draw();
}
int main (int argc, char **argv) {
- char *pw;
CFG_args(argc, argv);
logo("system: initialize engine\n");
SetEventsMask(KOS32_EVENT_FLAG_REDRAW | KOS32_EVENT_FLAG_KEYBOARD | KOS32_EVENT_FLAG_BUTTON);
pl2.kwr = KEY_2;
pl2.kp = KEY_E;
srand(GetIdleCount());
- F_startup();
CFG_load();
- pw = "doom2d.wad";
- if (fexists(pw)) {
- F_addwad(pw);
- } else {
- F_addwad("doom2d.wad");
- }
+ F_addwad("doom2d.wad");
F_initwads();
- M_startup();
- F_allocres();
S_init();
MUS_init();
R_init();
G_init();
- ticks = GetTimeCountPro();
logo("system: game loop\n");
- while (!quit) {
- step();
- }
+ game_loop();
logo("system: finalize engine\n");
CFG_save();
R_done();
MUS_done();
S_done();
- M_shutdown();
logo("system: halt\n");
return 0;
}