+2010-03-09
+ * added (hidden) function to save native Supaplex levels with tape as
+ native *.sp file containing level with demo (saved with a file name
+ similar to native R'n'D levels, but with ".sp" extension instead of
+ ".level"); to use this functionality, enter ":save-native-level" or
+ ":snl" from the main menu with the native Supaplex level loaded and
+ the appropriate tape loaded to the tape recorder
+
+2010-03-03
+ * added updating of game values on the panel to Supaplex game engine
+
2010-02-23
* finished integrating R'n'D graphics engine into Supaplex game engine
(although some animations do not support full customizability yet)
-#define COMPILE_DATE_STRING "2010-03-02 23:49"
+#define COMPILE_DATE_STRING "2010-03-09 14:59"
{
DumpTape(&tape);
}
+ else if (is_string_suffix(cheat_input, ":save-native-level") ||
+ is_string_suffix(cheat_input, ":snl"))
+ {
+ SaveNativeLevel(&level);
+ }
}
else if (game_status == GAME_MODE_PLAYING)
{
return (getFileTypeFromBasename(basename) != LEVEL_FILE_TYPE_UNKNOWN);
}
-static char *getSingleLevelBasename(int nr)
+static char *getSingleLevelBasenameExt(int nr, char *extension)
{
static char basename[MAX_FILENAME_LEN];
if (nr < 0)
- sprintf(basename, "template.%s", LEVELFILE_EXTENSION);
+ sprintf(basename, "template.%s", extension);
else
- sprintf(basename, "%03d.%s", nr, LEVELFILE_EXTENSION);
+ sprintf(basename, "%03d.%s", nr, extension);
return basename;
}
+static char *getSingleLevelBasename(int nr)
+{
+ return getSingleLevelBasenameExt(nr, LEVELFILE_EXTENSION);
+}
+
static char *getPackedLevelBasename(int type)
{
static char basename[MAX_FILENAME_LEN];
level->yamyam_content[i].e[x][y] = EL_EMPTY;
}
+static void CopyNativeTape_RND_to_SP(struct LevelInfo *level)
+{
+ struct LevelInfo_SP *level_sp = level->native_sp_level;
+ struct DemoInfo_SP *demo = &level_sp->demo;
+ int i, j;
+
+ /* always start with reliable default values */
+ demo->is_available = FALSE;
+ demo->length = 0;
+
+ if (TAPE_IS_EMPTY(tape))
+ return;
+
+ demo->level_nr = tape.level_nr; /* (currently not used) */
+
+ level_sp->header.DemoRandomSeed = tape.random_seed;
+
+ demo->length = 0;
+ for (i = 0; i < tape.length; i++)
+ {
+ int demo_action = map_key_RND_to_SP(tape.pos[i].action[0]);
+ int demo_repeat = tape.pos[i].delay;
+
+ for (j = 0; j < demo_repeat / 16; j++)
+ demo->data[demo->length++] = 0xf0 | demo_action;
+
+ if (demo_repeat % 16)
+ demo->data[demo->length++] = ((demo_repeat % 16 - 1) << 4) | demo_action;
+ }
+
+ demo->data[demo->length++] = 0xff;
+
+ demo->is_available = TRUE;
+}
+
static void setTapeInfoToDefaults();
static void CopyNativeTape_SP_to_RND(struct LevelInfo *level)
{
struct LevelInfo_SP *level_sp = level->native_sp_level;
struct DemoInfo_SP *demo = &level_sp->demo;
+ char *filename = level->file_info.filename;
int i;
/* always start with reliable default values */
setTapeInfoToDefaults();
+ if (!demo->is_available)
+ return;
+
tape.level_nr = demo->level_nr; /* (currently not used) */
tape.length = demo->length - 1; /* without "end of demo" byte */
tape.random_seed = level_sp->header.DemoRandomSeed;
- // tape.date = <SET FROM FILE DATE OF *.SP FILE>
+ TapeSetDateFromEpochSeconds(getFileTimestampEpochSeconds(filename));
for (i = 0; i < demo->length - 1; i++)
{
CopyNativeLevel_SP_to_RND(level);
}
+void SaveNativeLevel(struct LevelInfo *level)
+{
+ if (level->game_engine_type == GAME_ENGINE_TYPE_SP)
+ {
+ char *basename = getSingleLevelBasenameExt(level->file_info.nr, "sp");
+ char *filename = getLevelFilenameFromBasename(basename);
+
+ CopyNativeLevel_RND_to_SP(level);
+ CopyNativeTape_RND_to_SP(level);
+
+ SaveNativeLevel_SP(filename);
+ }
+}
+
/* ------------------------------------------------------------------------- */
/* functions for loading generic level */
void LoadLevelTemplate(int);
void SaveLevel(int);
void SaveLevelTemplate();
+void SaveNativeLevel(struct LevelInfo *);
void DumpLevel(struct LevelInfo *);
boolean SaveLevelChecked(int);
extern void setLevelInfoToDefaults_SP();
extern void copyInternalEngineVars_SP();
extern boolean LoadNativeLevel_SP(char *, int);
+extern void SaveNativeLevel_SP(char *);
extern void BackToFront_SP(void);
extern void BlitScreenToBitmap_SP(Bitmap *);
/* functions for loading Supaplex level */
/* ------------------------------------------------------------------------- */
+void setTapeInfoToDefaults_SP()
+{
+ native_sp_level.demo.is_available = FALSE;
+ native_sp_level.demo.length = 0;
+}
+
void setLevelInfoToDefaults_SP()
{
LevelInfoType *header = &native_sp_level.header;
for (i = 0; i < SP_HEADER_SIZE; i++)
native_sp_level.header_raw_bytes[i] = 0x20;
- native_sp_level.demo.is_available = FALSE;
- native_sp_level.demo.length = 0;
+ setTapeInfoToDefaults_SP();
}
void copyInternalEngineVars_SP()
return TRUE;
}
+
+void SaveNativeLevel_SP(char *filename)
+{
+ LevelInfoType *header = &native_sp_level.header;
+ FILE *file;
+ int i, x, y;
+
+ if (!(file = fopen(filename, MODE_WRITE)))
+ {
+ Error(ERR_WARN, "cannot save native level file '%s'", filename);
+
+ return;
+ }
+
+ /* write level playfield (width * height == 60 * 24 tiles == 1440 bytes) */
+ for (y = 0; y < native_sp_level.height; y++)
+ for (x = 0; x < native_sp_level.width; x++)
+ putFile8Bit(file, native_sp_level.playfield[x][y]);
+
+ /* write level header (96 bytes) */
+
+ WriteUnusedBytesToFile(file, 4);
+
+ putFile8Bit(file, header->InitialGravity);
+ putFile8Bit(file, header->Version);
+
+ for (i = 0; i < SP_LEVEL_NAME_LEN; i++)
+ putFile8Bit(file, header->LevelTitle[i]);
+
+ putFile8Bit(file, header->InitialFreezeZonks);
+ putFile8Bit(file, header->InfotronsNeeded);
+ putFile8Bit(file, header->SpecialPortCount);
+
+ for (i = 0; i < SP_MAX_SPECIAL_PORTS; i++)
+ {
+ SpecialPortType *port = &header->SpecialPort[i];
+
+ putFile16BitBE(file, port->PortLocation);
+ putFile8Bit(file, port->Gravity);
+ putFile8Bit(file, port->FreezeZonks);
+ putFile8Bit(file, port->FreezeEnemies);
+
+ WriteUnusedBytesToFile(file, 1);
+ }
+
+ putFile8Bit(file, header->SpeedByte);
+ putFile8Bit(file, header->CheckSumByte);
+ putFile16BitLE(file, header->DemoRandomSeed);
+
+ /* also save demo tape, if available */
+
+ if (native_sp_level.demo.is_available)
+ {
+ putFile8Bit(file, native_sp_level.demo.level_nr);
+
+ for (i = 0; i < native_sp_level.demo.length; i++)
+ putFile8Bit(file, native_sp_level.demo.data[i]);
+ }
+
+ fclose(file);
+}
#include <time.h>
#include <sys/time.h>
#include <sys/types.h>
+#include <sys/stat.h>
#include <stdarg.h>
#include <ctype.h>
#include <string.h>
return real_name;
}
+time_t getFileTimestampEpochSeconds(char *filename)
+{
+ struct stat file_status;
+
+ if (stat(filename, &file_status) != 0) /* cannot stat file */
+ return 0;
+
+ return file_status.st_mtime;
+}
+
/* ------------------------------------------------------------------------- */
/* path manipulation functions */
char *getLoginName(void);
char *getRealName(void);
+time_t getFileTimestampEpochSeconds(char *);
+
char *getBasePath(char *);
char *getBaseName(char *);
char *getBaseNamePtr(char *);
return token;
}
-static char *getFileTimestamp(char *filename)
+static char *getFileTimestampString(char *filename)
{
+#if 1
+ return getStringCopy(i_to_a(getFileTimestampEpochSeconds(filename)));
+#else
struct stat file_status;
if (stat(filename, &file_status) != 0) /* cannot stat file */
return getStringCopy(i_to_a(0));
return getStringCopy(i_to_a(file_status.st_mtime));
+#endif
}
static boolean modifiedFileTimestamp(char *filename, char *timestamp_string)
LEVELINFO_FILENAME);
char *filename_artworkinfo = getPath2(getSetupArtworkDir(artwork_info),
ARTWORKINFO_FILENAME(type));
- char *timestamp_levelinfo = getFileTimestamp(filename_levelinfo);
- char *timestamp_artworkinfo = getFileTimestamp(filename_artworkinfo);
+ char *timestamp_levelinfo = getFileTimestampString(filename_levelinfo);
+ char *timestamp_artworkinfo = getFileTimestampString(filename_artworkinfo);
token_main = getCacheToken(token_prefix, "TIMESTAMP_LEVELINFO");
setHashEntry(artworkinfo_cache_new, token_main, timestamp_levelinfo);
/* tape control functions */
/* ========================================================================= */
-static void TapeSetDate()
+void TapeSetDateFromEpochSeconds(time_t epoch_seconds)
{
- time_t epoch_seconds = time(NULL);
- struct tm *now = localtime(&epoch_seconds);
+ struct tm *lt = localtime(&epoch_seconds);
- tape.date = 10000 * (now->tm_year % 100) + 100 * now->tm_mon + now->tm_mday;
+ tape.date = 10000 * (lt->tm_year % 100) + 100 * lt->tm_mon + lt->tm_mday;
+}
+
+void TapeSetDateFromNow()
+{
+ TapeSetDateFromEpochSeconds(time(NULL));
}
void TapeErase()
tape.game_version = GAME_VERSION_ACTUAL;
tape.engine_version = level.game_version;
- TapeSetDate();
+ TapeSetDateFromNow();
for (i = 0; i < MAX_PLAYERS; i++)
tape.player_participates[i] = FALSE;
tape.recording = TRUE;
tape.changed = TRUE;
- TapeSetDate();
+ TapeSetDateFromNow();
DrawVideoDisplay(VIDEO_STATE_DATE_ON, tape.date);
DrawVideoDisplay(VIDEO_STATE_PLAY_OFF | VIDEO_STATE_REC_ON, 0);
void TapeDeactivateDisplayOn();
void TapeDeactivateDisplayOff(boolean);
+void TapeSetDateFromEpochSeconds(time_t);
+void TapeSetDateFromNow();
+
void TapeStartRecording(long);
void TapeHaltRecording(void);
void TapeStopRecording(void);