Change a "magic number" to a preprocessor macro. Also don't store and
authorparasti <parasti@78b8d119-cf0a-0410-b17c-f493084dd1d7>
Sun, 8 Oct 2006 17:46:58 +0000 (17:46 +0000)
committerparasti <parasti@78b8d119-cf0a-0410-b17c-f493084dd1d7>
Sun, 8 Oct 2006 17:46:58 +0000 (17:46 +0000)
retrieve Neverball version to/from replays.

git-svn-id: https://s.snth.net/svn/neverball/trunk@570 78b8d119-cf0a-0410-b17c-f493084dd1d7

ball/demo.c
ball/demo.h

index 2d132c9..51b2e6b 100644 (file)
@@ -27,7 +27,9 @@
 /*---------------------------------------------------------------------------*/
 
 #define MAGIC           0x52424EAF
-#define DEMO_VERSION    1
+#define DEMO_VERSION    2
+
+#define DATELEN 20         
 
 static FILE *demo_fp;
 
@@ -40,7 +42,6 @@ void demo_dump_info(const struct demo *d)
 {
     printf("Name:         %s\n"
            "File:         %s\n"
-           "NB Version:   %s\n"
            "Time:         %d\n"
            "Coins:        %d\n"
            "Mode:         %d\n"
@@ -58,7 +59,6 @@ void demo_dump_info(const struct demo *d)
            "Balls:        %d\n"
            "Total Time:   %d\n",
            d->name, d->filename,
-           d->nb_version,
            d->timer, d->coins, d->mode, d->state, ctime(&d->date),
            d->player,
            d->shot, d->file, d->back, d->grad, d->song,
@@ -92,7 +92,7 @@ static int demo_header_read(FILE *fp, struct demo *d)
     int t;
 
     struct tm date;
-    char datestr[20];
+    char datestr[DATELEN];
 
     get_index(fp, &magic);
     get_index(fp, &version);
@@ -110,7 +110,7 @@ static int demo_header_read(FILE *fp, struct demo *d)
 #if 0
         get_index(fp, (int *) &d->date);
 #endif
-        fread(datestr, 1, 20, fp);
+        fread(datestr, 1, DATELEN, fp);
         sscanf(datestr,
                "%d-%d-%dT%d:%d:%d",
                &date.tm_year,
@@ -141,8 +141,6 @@ static int demo_header_read(FILE *fp, struct demo *d)
         get_index(fp, &d->balls);
         get_index(fp, &d->times);
 
-        fread(d->nb_version, 1, 20, fp);
-
         return 1;
     }
     return 0;
@@ -185,9 +183,9 @@ static void demo_header_write(FILE *fp, struct demo *d)
     int version = DEMO_VERSION;
     int zero  = 0;
 
-    char datestr[20];
+    char datestr[DATELEN];
 
-    strftime(datestr, 20, "%Y-%m-%dT%H:%M:%S", gmtime(&d->date));
+    strftime(datestr, DATELEN, "%Y-%m-%dT%H:%M:%S", gmtime(&d->date));
 
     put_index(fp, &magic);
     put_index(fp, &version);
@@ -199,7 +197,7 @@ static void demo_header_write(FILE *fp, struct demo *d)
 #if 0
     put_index(fp, (int *) &d->date);
 #endif
-    fwrite(datestr, 1, 20, fp);
+    fwrite(datestr, 1, DATELEN, fp);
 
     fwrite(d->player, 1, MAXNAM, fp);
 
@@ -214,8 +212,6 @@ static void demo_header_write(FILE *fp, struct demo *d)
     put_index(fp, &d->score);
     put_index(fp, &d->balls);
     put_index(fp, &d->times);
-
-    fwrite(d->nb_version, 1, 20, fp);
 }
 
 /* Update the demo header using the final level state. */
@@ -381,8 +377,6 @@ int demo_play_init(const char *name,
     demo.balls = lg->balls;
     demo.times = lg->times;
 
-    strncpy(demo.nb_version, VERSION, 20);
-
     if (demo.filename && (demo_fp = fopen(demo.filename, FMODE_WB)))
     {
         demo_header_write(demo_fp, &demo);
index 7da5e17..f2c59dd 100644 (file)
@@ -32,7 +32,6 @@ struct demo
     int    score;           /* sum of coins (challenge mode) */
     int    balls;           /* number of balls (challenge mode) */
     int    times;           /* total time (challenge mode) */
-    char   nb_version[20];  /* neverball version used */
 };