DEADSOFTWARE

menu: remove data field from menu_t
[flatwaifu.git] / src / soft / render.c
index 363a058264c44f6d50006811acbee118658af243..bf0ca079c2684f103e47f176c067e43f2be97d4f 100644 (file)
@@ -72,18 +72,22 @@ static int w_o, w_x, w_y;
 static vgaimg *walp[256];
 static int walh[256];
 static byte walani[256];
+static byte walswp[256];
 static int anih[ANIT][5];
 static byte anic[ANIT];
 static int max_textures;
+static byte w_horiz = 1;
 static vgaimg *horiz;
 
+static int init_screen_width = 0;
+static int init_screen_height = 0;
+static byte init_screen_full = 0xFF;
+static int init_screen_gammaa = -1;
+
 /* --- misc --- */
 
 static void *Z_getspr (char n[4], int s, int d, char *dir) {
-  int h = F_getsprid(n, s, d);
-  if (dir) {
-    *dir = (h & 0x8000) ? 1 : 0;
-  }
+  int h = F_getsprid(n, s, d, dir);
   return V_getvgaimg(h);
 }
 
@@ -352,58 +356,59 @@ static void get_entry_size (const menu_t *m, int i, int *w, int *h) {
   int type = 0;
   menu_msg_t msg;
   msg.type = GM_GETENTRY;
-  assert(GM_send(m, i, &msg));
-  type = msg.integer.i;
-  switch (type) {
-    case GM_BUTTON:
-    case GM_SCROLLER:
-    case GM_TEXTFIELD:
-    case GM_TEXTFIELD_BUTTON:
-      msg.type = GM_GETCAPTION;
-      if (GM_send(m, i, &msg)) {
-        x = Z_get_big_string_width("%.*s", msg.string.maxlen, msg.string.s);
-      }
-      break;
-    case GM_SMALL_BUTTON:
-      msg.type = GM_GETCAPTION;
-      if (GM_send(m, i, &msg)) {
-        x = Z_get_small_string_width("%.*s", msg.string.maxlen, msg.string.s);
-      }
-      break;
-    default:
-      assert(0);
-  }
-  switch (type) {
-    case GM_BUTTON:
-      msg.type = GM_GETSTR;
-      if (GM_send(m, i, &msg)) {
-        x += Z_get_big_string_width("%.*s", msg.string.maxlen, msg.string.s);
-      }
-      y = 16;
-      break;
-    case GM_SMALL_BUTTON:
-      msg.type = GM_GETSTR;
-      if (GM_send(m, i, &msg)) {
-        x += Z_get_big_string_width("%.*s", msg.string.maxlen, msg.string.s);
-      }
-      y = 12;
-      break;
-    case GM_SCROLLER:
-      x += (SCROLLER_MIDDLE + 2) * 8;
-      y = 16;
-      break;
-    case GM_TEXTFIELD:
-    case GM_TEXTFIELD_BUTTON:
-      msg.type = GM_GETSTR;
-      if (GM_send(m, i, &msg)) {
-        x += (msg.string.maxlen + 2) * 8;
-      } else {
-        x += (TEXTFIELD_MIDDLE + 2) * 8;
-      }
-      y = 16;
-      break;
-    default:
-      assert(0);
+  if (GM_send(m, i, &msg)) {
+    type = msg.integer.i;
+    switch (type) {
+      case GM_BUTTON:
+      case GM_SCROLLER:
+      case GM_TEXTFIELD:
+      case GM_TEXTFIELD_BUTTON:
+        msg.type = GM_GETCAPTION;
+        if (GM_send(m, i, &msg)) {
+          x = Z_get_big_string_width("%.*s", msg.string.maxlen, msg.string.s);
+        }
+        break;
+      case GM_SMALL_BUTTON:
+        msg.type = GM_GETCAPTION;
+        if (GM_send(m, i, &msg)) {
+          x = Z_get_small_string_width("%.*s", msg.string.maxlen, msg.string.s);
+        }
+        break;
+      default:
+        assert(0);
+    }
+    switch (type) {
+      case GM_BUTTON:
+        msg.type = GM_GETSTR;
+        if (GM_send(m, i, &msg)) {
+          x += Z_get_big_string_width("%.*s", msg.string.maxlen, msg.string.s);
+        }
+        y = 16;
+        break;
+      case GM_SMALL_BUTTON:
+        msg.type = GM_GETSTR;
+        if (GM_send(m, i, &msg)) {
+          x += Z_get_big_string_width("%.*s", msg.string.maxlen, msg.string.s);
+        }
+        y = 12;
+        break;
+      case GM_SCROLLER:
+        x += (SCROLLER_MIDDLE + 2) * 8;
+        y = 16;
+        break;
+      case GM_TEXTFIELD:
+      case GM_TEXTFIELD_BUTTON:
+        msg.type = GM_GETSTR;
+        if (GM_send(m, i, &msg)) {
+          x += (msg.string.maxlen + 2) * 8;
+        } else {
+          x += (TEXTFIELD_MIDDLE + 2) * 8;
+        }
+        y = 16;
+        break;
+      default:
+        assert(0);
+    }
   }
   *w = x;
   *h = y;
@@ -1405,7 +1410,7 @@ void R_begin_load (void) {
   max_textures = 1;
 }
 
-void R_load (char s[8], int f) {
+void R_load (char s[8]) {
   assert(max_textures < 256);
   if (!s[0]) {
     walh[max_textures] = -1;
@@ -1417,9 +1422,6 @@ void R_load (char s[8], int f) {
     } else {
       walh[max_textures] = F_getresid(s);
       walp[max_textures] = V_getvgaimg(walh[max_textures]);
-      if (f) {
-        walh[max_textures] |= 0x8000;
-      }
       if (s[0] == 'S' && s[1] == 'W' && s[4] == '_') {
         walswp[max_textures] = 0;
       }
@@ -1437,7 +1439,7 @@ void R_end_load (void) {
     if (walswp[i] == 0) {
       R_get_name(i, s);
       s[5] ^= 1;
-      g = F_getresid(s) | (walh[i] & 0x8000);
+      g = F_getresid(s);
       k = 1;
       while (k < 256 && walh[k] != g) {
         k += 1;
@@ -1447,7 +1449,7 @@ void R_end_load (void) {
         j += 1;
         walh[k] = g;
         walp[k] = V_getvgaimg(g);
-        walf[k] = g & 0x8000 ? 1 : 0;
+        walf[k] = walf[i];
       }
       walswp[i] = k;
       walswp[k] = i;
@@ -1564,12 +1566,33 @@ static int video_menu_handler (menu_msg_t *msg, const menu_t *m, void *data, int
   return simple_menu_handler(msg, i, __NUM__, &sm, &cur);
 }
 
-static const menu_t video_menu = {
-  NULL, &video_menu_handler
-};
-
 const menu_t *R_menu (void) {
-  return &video_menu;
+  static const menu_t m = { video_menu_handler };
+  return &m;
+}
+
+const cfg_t *R_args (void) {
+  static const cfg_t args[] = {
+    { "fullscr", &init_screen_full, Y_SW_ON },
+    { "window", &init_screen_full, Y_SW_OFF },
+    { "width", &init_screen_width, Y_DWORD },
+    { "height", &init_screen_height, Y_DWORD },
+    { "gamma", &init_screen_gammaa, Y_DWORD },
+    { NULL, NULL, 0 } // end
+  };
+  return args;
+}
+
+const cfg_t *R_conf (void) {
+  static const cfg_t conf[] = {
+    { "sky", &w_horiz, Y_SW_ON },
+    { "fullscreen", &fullscreen, Y_SW_ON },
+    { "screen_width", &SCRW, Y_DWORD },
+    { "screen_height", &SCRH, Y_DWORD },
+    { "gamma", &gammaa, Y_DWORD },
+    { NULL, NULL, 0 } // end
+  };
+  return conf;
 }
 
 void R_init () {
@@ -1581,6 +1604,10 @@ void R_init () {
   }
   F_loadres(F_getresid("MIXMAP"), mixmap, 0, 0x10000);
   F_loadres(F_getresid("COLORMAP"), clrmap, 0, 256*12);
+  SCRW = init_screen_width > 0 ? init_screen_width : SCRW;
+  SCRH = init_screen_height > 0 ? init_screen_height : SCRH;
+  fullscreen = init_screen_full != 0xFF ? init_screen_full : fullscreen;
+  gammaa = init_screen_gammaa >= 0 ? init_screen_gammaa : gammaa;
   R_set_videomode(SCRW, SCRH, fullscreen);
   V_setrect(0, SCRW, 0, SCRH);
   V_clr(0, SCRW, 0, SCRH, 0);
@@ -1594,3 +1621,14 @@ void R_done (void) {
   pitch = 0;
   Y_unset_videomode();
 }
+
+void R_switch_texture (int x, int y) {
+  assert(x >= 0 && x < FLDW);
+  assert(y >= 0 && y < FLDH);
+  fldb[y][x] = walswp[fldb[y][x]];
+}
+
+int R_get_swp (int n) {
+  assert(n >= 0 && n < 256);
+  return walswp[n];
+}