Vergessene Dinge eingecheckt.
[hackover2013-badge-firmware.git] / badge / jumpnrun / levels.h
index fa7b1a3..182cafd 100644 (file)
@@ -5,9 +5,7 @@
 #include "items.h"
 #include "tiles.h"
 
 #include "items.h"
 #include "tiles.h"
 
-#include <badge/util/rectangle.h>
-
-#include <drivers/fatfs/ff.h>
+#include "../util/rectangle.h"
 
 #include <stddef.h>
 #include <stdio.h>
 
 #include <stddef.h>
 #include <stdio.h>
@@ -36,9 +34,6 @@ enum {
 size_t jumpnrun_level_count(void);
 void jumpnrun_levels_dump(void);
 
 size_t jumpnrun_level_count(void);
 void jumpnrun_levels_dump(void);
 
-int jumpnrun_load_level_header_from_file(jumpnrun_level *dest, FIL *fd);
-int jumpnrun_load_level_from_file       (jumpnrun_level *dest, FIL *fd);
-
 // Use stack-local VLAs to store dynamic content.
 #define JUMPNRUN_LEVEL_MAKE_SPACE(var)                    \
   jumpnrun_tile  var ## _tiles  [var.header.tile_count];  \
 // Use stack-local VLAs to store dynamic content.
 #define JUMPNRUN_LEVEL_MAKE_SPACE(var)                    \
   jumpnrun_tile  var ## _tiles  [var.header.tile_count];  \
@@ -48,5 +43,48 @@ int jumpnrun_load_level_from_file       (jumpnrun_level *dest, FIL *fd);
   var.tiles   = var ## _tiles;                            \
   var.items   = var ## _items;                            \
   var.enemies = var ## _enemies;
   var.tiles   = var ## _tiles;                            \
   var.items   = var ## _items;                            \
   var.enemies = var ## _enemies;
+#else 
+
+#ifdef __linux__
+
+int jumpnrun_load_level_header_from_file(jumpnrun_level *dest, FILE *fd);
+int jumpnrun_load_level_from_file       (jumpnrun_level *dest, FILE *fd);
+
+#define JUMPNRUN_LEVEL_LOAD(lv, lvname)                                \
+  memset(&(lv), 0, sizeof(lv));                                        \
+  FILE *fd = fopen((lvname), "r");                             \
+  if(fd == NULL) return JUMPNRUN_ERROR;                                \
+  int err = jumpnrun_load_level_header_from_file(&(lv), fd);   \
+  if(err != 0) {                                               \
+    fclose(fd);                                                        \
+    return JUMPNRUN_ERROR;                                     \
+  }                                                            \
+  JUMPNRUN_LEVEL_MAKE_SPACE(lv);                               \
+  err = jumpnrun_load_level_from_file(&(lv), fd);              \
+  fclose(fd);                                                  \
+  if(err != 0) return JUMPNRUN_ERROR;
+#else
+#include <drivers/fatfs/ff.h>
+
+int jumpnrun_load_level_header_from_file(jumpnrun_level *dest, FIL *fd);
+int jumpnrun_load_level_from_file       (jumpnrun_level *dest, FIL *fd);
+
+#define JUMPNRUN_LEVEL_LOAD(lv, lvname)                                        \
+  memset(&(lv), 0, sizeof(lv));                                                \
+  FIL fd;                                                              \
+  if(FR_OK != f_open(&fd, (lvname), FA_OPEN_EXISTING | FA_READ)) {     \
+    return JUMPNRUN_ERROR;                                             \
+  }                                                                    \
+  if(0 != jumpnrun_load_level_header_from_file(&(lv), &fd)) {          \
+    f_close(&fd);                                                      \
+    return JUMPNRUN_ERROR;                                             \
+  }                                                                    \
+  JUMPNRUN_LEVEL_MAKE_SPACE(lv);                                       \
+  int err = jumpnrun_load_level_from_file(&(lv), &fd);                 \
+  f_close(&fd);                                                                \
+  if(err != 0) {                                                       \
+    return JUMPNRUN_ERROR;                                             \
+  }
+#endif
 
 #endif
 
 #endif
This page took 0.022844 seconds and 4 git commands to generate.