#include "solid.h"
#include "config.h"
#include "binary.h"
+#include "text.h"
/*---------------------------------------------------------------------------*/
#define MAGIC 0x52424EAF
-#define DEMO_VERSION 1
+#define DEMO_VERSION 4
+
+#define DATELEN 20
static FILE *demo_fp;
{
printf("Name: %s\n"
"File: %s\n"
- "NB Version: %s\n"
"Time: %d\n"
"Coins: %d\n"
"Mode: %d\n"
"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->timer, d->coins, d->mode, d->status, ctime(&d->date),
d->player,
d->shot, d->file, d->back, d->grad, d->song,
d->time, d->goal, d->score, d->balls, d->times);
int t;
struct tm date;
- char datestr[20];
+ char datestr[DATELEN];
get_index(fp, &magic);
get_index(fp, &version);
d->timer = t;
get_index(fp, &d->coins);
- get_index(fp, &d->state);
+ get_index(fp, &d->status);
get_index(fp, &d->mode);
-#if 0
- get_index(fp, (int *) &d->date);
-#endif
- fread(datestr, 1, 20, fp);
+ get_string(fp, d->player, MAXNAM);
+
+ get_string(fp, datestr, DATELEN);
sscanf(datestr,
"%d-%d-%dT%d:%d:%d",
&date.tm_year,
d->date = make_time_from_utc(&date);
- fread(d->player, 1, MAXNAM, fp);
-
- fread(d->shot, 1, PATHMAX, fp);
- fread(d->file, 1, PATHMAX, fp);
- fread(d->back, 1, PATHMAX, fp);
- fread(d->grad, 1, PATHMAX, fp);
- fread(d->song, 1, PATHMAX, fp);
+ get_string(fp, d->shot, PATHMAX);
+ get_string(fp, d->file, PATHMAX);
get_index(fp, &d->time);
get_index(fp, &d->goal);
get_index(fp, &d->balls);
get_index(fp, &d->times);
- fread(d->nb_version, 1, 20, fp);
-
return 1;
}
return 0;
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);
put_index(fp, &zero);
put_index(fp, &d->mode);
-#if 0
- put_index(fp, (int *) &d->date);
-#endif
- fwrite(datestr, 1, 20, fp);
-
- fwrite(d->player, 1, MAXNAM, fp);
+ put_string(fp, d->player);
+ put_string(fp, datestr);
- fwrite(d->shot, 1, PATHMAX, fp);
- fwrite(d->file, 1, PATHMAX, fp);
- fwrite(d->back, 1, PATHMAX, fp);
- fwrite(d->grad, 1, PATHMAX, fp);
- fwrite(d->song, 1, PATHMAX, fp);
+ put_string(fp, d->shot);
+ put_string(fp, d->file);
put_index(fp, &d->time);
put_index(fp, &d->goal);
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. */
-
-void demo_header_stop(FILE *fp, int coins, int timer, int state)
-{
- long pos = ftell(fp);
-
- fseek(fp, 8, SEEK_SET);
- put_index(fp, &timer);
- put_index(fp, &coins);
- put_index(fp, &state);
- fseek(fp, pos, SEEK_SET);
}
/*---------------------------------------------------------------------------*/
{
if (demo_header_read(fp, d))
{
- strncpy(d->filename, config_user(filename), MAXSTR);
- strncpy(d->name, bname(filename, REPLAY_EXT), PATHMAX);
+ strncpy(d->filename, config_user(filename), MAXSTR);
+ strncpy(d->name, bname(text_from_locale(d->filename), REPLAY_EXT),
+ PATHMAX);
d->name[PATHMAX - 1] = '\0';
count++;
const char *date_to_str(time_t i)
{
static char str[MAXSTR];
+ const char *fmt;
+
+ /* TRANSLATORS: here is the format of the date shown at the
+ replay selection screen (and possibly elsewhere). The default
+ format is necessarily locale-independent. See strftime(3) for
+ details on the format.
+ */
- strftime(str, MAXSTR, "%c", localtime(&i));
- return str;
+ fmt = /* xgettext:no-c-format */ L_("%Y-%m-%d %H:%M:%S");
+ strftime(str, MAXSTR, fmt, localtime(&i));
+ return text_from_locale(str);
}
/*---------------------------------------------------------------------------*/
-int demo_exists(char *name)
+int demo_exists(const char *name)
{
FILE *fp;
char buf[MAXSTR];
for (i = 1; i < 100; i++)
{
- sprintf(name, _("replay%02d"), i);
+ sprintf(name, "replay%02d", i);
if (!demo_exists(name))
return;
demo.balls = lg->balls;
demo.times = lg->times;
- strncpy(demo.nb_version, VERSION, 20);
-
- if (demo.filename && (demo_fp = fopen(demo.filename, FMODE_WB)))
+ if ((demo_fp = fopen(demo.filename, FMODE_WB)))
{
demo_header_write(demo_fp, &demo);
audio_music_fade_to(2.0f, level->song);
}
}
-/* Update the demo header using the final level state. */
+void demo_play_stat(const struct level_game *lg)
+{
+ if (demo_fp)
+ {
+ long pos = ftell(demo_fp);
+
+ fseek(demo_fp, 8, SEEK_SET);
+
+ put_index(demo_fp, &lg->timer);
+ put_index(demo_fp, &lg->coins);
+ put_index(demo_fp, &lg->status);
+
+ fseek(demo_fp, pos, SEEK_SET);
+ }
+}
-void demo_play_stop(const struct level_game *lg)
+void demo_play_stop(void)
{
if (demo_fp)
{
- demo_header_stop(demo_fp, lg->coins, lg->timer, lg->state);
fclose(demo_fp);
demo_fp = NULL;
}
}
-int demo_play_saved(void)
+int demo_saved(void)
{
return demo_exists(USER_REPLAY_FILE);
}
-void demo_play_save(const char *name)
+void demo_rename(const char *name)
{
- char src[PATHMAX];
- char dst[PATHMAX];
+ char src[MAXSTR];
+ char dst[MAXSTR];
- if (name && demo_exists(USER_REPLAY_FILE)
- && strcmp(name, USER_REPLAY_FILE) != 0)
+ if (name &&
+ demo_exists(USER_REPLAY_FILE) &&
+ strcmp(name, USER_REPLAY_FILE) != 0)
{
- strncpy(src, config_user(USER_REPLAY_FILE), PATHMAX);
+ strcpy(src, config_user(USER_REPLAY_FILE));
strcat(src, REPLAY_EXT);
- strncpy(dst, config_user(name), PATHMAX);
+
+ strcpy(dst, config_user(name));
strcat(dst, REPLAY_EXT);
#ifdef _WIN32
return &demo_replay;
}
-/* Internally load a replay and fill the lg structure (if not NULL) */
+static int demo_status = GAME_NONE;
int demo_replay_init(const char *name, struct level_game *lg)
{
- demo_fp = fopen(name, FMODE_RB);
+ demo_status = GAME_NONE;
+ demo_fp = fopen(name, FMODE_RB);
if (demo_fp && demo_header_read(demo_fp, &demo_replay))
{
- strncpy(demo_replay.filename, name, MAXSTR);
- strncpy(demo_replay.name, bname(name, REPLAY_EXT), PATHMAX);
+ strncpy(demo_replay.filename, name, MAXSTR);
+ strncpy(demo_replay.name, bname(text_from_locale(demo_replay.filename),
+ REPLAY_EXT), PATHMAX);
if (!demo_load_level(&demo_replay, &demo_level_replay))
return 0;
lg->goal = demo_replay.goal;
/* A normal replay demo */
- audio_music_fade_to(0.5f, demo_replay.song);
+ audio_music_fade_to(0.5f, demo_level_replay.song);
return game_init(&demo_level_replay, demo_replay.time,
demo_replay.goal);
}
int demo_replay_step(float *dt)
{
const float g[3] = { 0.0f, -9.8f, 0.0f };
- int sv;
if (demo_fp)
{
{
/* Play out current game state for particles, clock, etc. */
- game_step(g, *dt, &sv);
+ if (demo_status == GAME_NONE)
+ demo_status = game_step(g, *dt, 1);
+ else
+ game_step(g, *dt, 0);
/* Load real current game state from file. */