DEADSOFTWARE

portability: avoid errors on some compilers
[flatwaifu.git] / src / map.c
index 1bdb4d3c145c643f19ac9ca207b9012c6fe95230..d70a4fb3cce021c46cf39b16140f794106ddf0c7 100644 (file)
--- a/src/map.c
+++ b/src/map.c
 #include "view.h"
 
 #include "music.h"
-#include "files.h"
 #include "render.h"
 
-#include <stdio.h>
 #include <string.h>
 #include <assert.h>
-#include "my.h"
 #include "error.h"
-#include "cp866.h"
 
 #include "common/streams.h"
 #include "common/files.h"
+#include "common/cp866.h"
 
 enum {
   MB_COMMENT = -1, MB_END = 0,
@@ -65,7 +62,7 @@ typedef struct old_thing_t {
 
 static map_block_t blk;
 
-static int G_load (Reader *h) {
+static int G_load (Stream *h) {
   switch (blk.t) {
     case MB_MUSIC:
       stream_read(g_music, 8, 1, h);
@@ -78,7 +75,7 @@ static int G_load (Reader *h) {
   return 0;
 }
 
-static int IT_load (Reader *h) {
+static int IT_load (Stream *h) {
   int m, i, j;
   old_thing_t t;
   switch (blk.t) {
@@ -174,7 +171,7 @@ static int IT_load (Reader *h) {
   return 0;
 }
 
-static int SW_load (Reader *h) {
+static int SW_load (Stream *h) {
   int i;
   switch(blk.t) {
     case MB_SWITCH2:
@@ -220,7 +217,7 @@ static void unpack (void *buf, int len, void *obuf) {
   }
 }
 
-static int read_array (void *p, Reader *h) {
+static int read_array (void *p, Stream *h) {
   void *buf;
   switch (blk.st) {
     case 0:
@@ -242,7 +239,7 @@ static int read_array (void *p, Reader *h) {
   return 1;
 }
 
-static int W_load (Reader *h) {
+static int W_load (Stream *h) {
   int i;
   char s[8];
   switch (blk.t) {
@@ -273,10 +270,11 @@ static int W_load (Reader *h) {
   return 0;
 }
 
-int MAP_load (Reader *r) {
-  assert(r != NULL);
+int MAP_load (Stream *r) {
   int ok = 0;
+  long off;
   map_header_t hdr;
+  assert(r != NULL);
   W_init(); // reset all game data
   stream_read(hdr.id, 8, 1, r);
   hdr.ver = stream_read16(r);
@@ -286,7 +284,7 @@ int MAP_load (Reader *r) {
       blk.t = stream_read16(r);
       blk.st = stream_read16(r);
       blk.sz = stream_read32(r);
-      long off = r->getpos(r) + blk.sz;
+      off = stream_getpos(r) + blk.sz;
       switch (blk.t) {
         case MB_MUSIC:
           ok = G_load(r);
@@ -313,22 +311,12 @@ int MAP_load (Reader *r) {
           logo("Unknown block %d(%d)\n", blk.t, blk.st);
           return 0; // error
       }
-      r->setpos(r, off);
+      stream_setpos(r, off);
     }
   } else {
     logo("Invalid map header\n");
+    abort();
     ok = 0;
   }
   return ok;
 }
-
-void F_loadmap (char n[8]) {
-  FILE_Reader rd;
-  int r = F_getresid(n);
-  FILE *h = wadh[wad[r].f];
-  fseek(h, wad[r].o, SEEK_SET);
-  FILE_AssignReader(&rd, h);
-  if (!MAP_load(&rd.base)) {
-    ERR_fatal("Failed to load map");
-  }
-}