DEADSOFTWARE

files: remove my.h
[flatwaifu.git] / src / kos32 / main.c
index 3ccbb5bce6d8930d297fe3a4ab420a8a66420694..c9ebfffe31f0b4b22ba9f9d2e537b4700fb23012 100644 (file)
@@ -23,7 +23,6 @@
 #include "system.h"
 #include "input.h"
 
-#include "my.h" // fexists
 #include "player.h" // pl1 pl2
 #include "menu.h" // G_keyf
 #include "error.h" // logo
@@ -38,7 +37,6 @@
 #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 },
@@ -486,10 +484,13 @@ static void handle_scancode (int code) {
 
 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) {
@@ -521,19 +522,27 @@ static void poll_events (void) {
   }
 }
 
-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);
@@ -561,12 +570,7 @@ int main (int argc, char **argv) {
   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();
@@ -574,11 +578,8 @@ int main (int argc, char **argv) {
   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();