From c4d9b5e489f38f7e6f42039cce9bca0ecafc0992 Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Tue, 23 Oct 2007 01:33:20 +0200 Subject: [PATCH] rnd-20071023-1-src * added command line function to write level sketch images to directory --- ChangeLog | 3 +++ Makefile | 5 +++- src/conftime.h | 2 +- src/files.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++--- src/files.h | 3 ++- src/init.c | 18 +++++++++++++ src/main.c | 1 + src/main.h | 2 ++ 8 files changed, 96 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5f4d6475..49ec71e1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2007-10-23 + * added command line function to write level sketch images to directory + 2007-10-20 * merged override and auto-override options into new override options with a new data type than can take the values "no", "yes" and "auto" diff --git a/Makefile b/Makefile index ea1154ef..65ea127a 100644 --- a/Makefile +++ b/Makefile @@ -42,7 +42,7 @@ CROSS_PATH_MSDOS = /usr/local/cross-msdos/i386-msdosdjgpp CROSS_PATH_WIN32 = /usr/local/cross-tools/i386-mingw32msvc # compile special edition of R'n'D instead of the normal (classic) version -SPECIAL_EDITION = rnd_jue +# SPECIAL_EDITION = rnd_jue # ----------------------------------------------------------------------------- @@ -130,6 +130,9 @@ enginetestnew: all leveltest: all ./Scripts/make_enginetest.sh leveltest +levelsketch_images: all + ./Scripts/make_levelsketch_images.sh + backup: ./Scripts/make_backup.sh src 1 diff --git a/src/conftime.h b/src/conftime.h index 2968c64d..aa4d27cf 100644 --- a/src/conftime.h +++ b/src/conftime.h @@ -1 +1 @@ -#define COMPILE_DATE_STRING "2007-10-20 02:03" +#define COMPILE_DATE_STRING "2007-10-23 00:44" diff --git a/src/files.c b/src/files.c index 45dec406..54d75d6c 100644 --- a/src/files.c +++ b/src/files.c @@ -9625,9 +9625,9 @@ void LoadHelpTextInfo() } -/* ------------------------------------------------------------------------- * - * convert levels - * ------------------------------------------------------------------------- */ +/* ------------------------------------------------------------------------- */ +/* convert levels */ +/* ------------------------------------------------------------------------- */ #define MAX_NUM_CONVERT_LEVELS 1000 @@ -9737,3 +9737,65 @@ void ConvertLevels() CloseAllAndExit(0); } + + +/* ------------------------------------------------------------------------- */ +/* create images for use in level sketches (raw BMP format) */ +/* ------------------------------------------------------------------------- */ + +void CreateLevelSketchImages() +{ +#if defined(TARGET_SDL) + Bitmap *bitmap1; + Bitmap *bitmap2; + int i; + + bitmap1 = CreateBitmap(TILEX, TILEY, DEFAULT_DEPTH); + bitmap2 = CreateBitmap(MINI_TILEX, MINI_TILEY, DEFAULT_DEPTH); + + for (i = 0; i < NUM_FILE_ELEMENTS; i++) + { + Bitmap *src_bitmap; + int src_x, src_y; + int graphic = el2edimg(i); + char basename1[16]; + char basename2[16]; + char *filename1; + char *filename2; + + sprintf(basename1, "%03d.bmp", i); + sprintf(basename2, "%03ds.bmp", i); + + filename1 = getPath2(global.create_images_dir, basename1); + filename2 = getPath2(global.create_images_dir, basename2); + + getGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y); + BlitBitmap(src_bitmap, bitmap1, src_x, src_y, TILEX, TILEY, 0, 0); + + if (SDL_SaveBMP(bitmap1->surface, filename1) != 0) + Error(ERR_EXIT, "cannot save level sketch image file '%s'", filename1); + + getMiniGraphicSource(graphic, &src_bitmap, &src_x, &src_y); + BlitBitmap(src_bitmap, bitmap2, src_x, src_y, MINI_TILEX, MINI_TILEY, 0, 0); + + if (SDL_SaveBMP(bitmap2->surface, filename2) != 0) + Error(ERR_EXIT, "cannot save level sketch image file '%s'", filename2); + + free(filename1); + free(filename2); + + if (options.debug) + printf("%03d `%03d%c", i, i, (i % 10 < 9 ? ' ' : '\n')); + } + + FreeBitmap(bitmap1); + FreeBitmap(bitmap2); + + if (options.debug) + printf("\n"); + + Error(ERR_INFO, "%d normal and small images created", NUM_FILE_ELEMENTS); + + CloseAllAndExit(0); +#endif +} diff --git a/src/files.h b/src/files.h index 51509f8c..75dc3460 100644 --- a/src/files.h +++ b/src/files.h @@ -68,6 +68,7 @@ void LoadMusicInfo(); void LoadHelpAnimInfo(); void LoadHelpTextInfo(); -void ConvertLevels(void); +void ConvertLevels(); +void CreateLevelSketchImages(); #endif /* FILES_H */ diff --git a/src/init.c b/src/init.c index 6ef48aee..8f2fdf7d 100644 --- a/src/init.c +++ b/src/init.c @@ -4976,6 +4976,7 @@ static void InitGlobal() global.autoplay_leveldir = NULL; global.convert_leveldir = NULL; + global.create_images_dir = NULL; global.frames_per_second = 0; global.fps_slowdown = FALSE; @@ -5157,6 +5158,18 @@ void Execute_Command(char *command) global.convert_level_nr = atoi(str_ptr); /* get level_nr value */ } } + else if (strncmp(command, "create images ", 14) == 0) + { +#if defined(TARGET_SDL) + global.create_images_dir = getStringCopy(&command[14]); + + if (access(global.create_images_dir, W_OK) != 0) + Error(ERR_EXIT, "image target directory '%s' not found or not writable", + global.create_images_dir); +#else + Error(ERR_EXIT, "command only available for SDL target"); +#endif + } #if DEBUG #if defined(TARGET_SDL) @@ -6178,6 +6191,11 @@ void OpenAll() ConvertLevels(); return; } + else if (global.create_images_dir) + { + CreateLevelSketchImages(); + return; + } game_status = GAME_MODE_MAIN; diff --git a/src/main.c b/src/main.c index aae4944a..e1612f53 100644 --- a/src/main.c +++ b/src/main.c @@ -5538,6 +5538,7 @@ static void print_usage() " \"dump tape FILE\" dump tape data from FILE\n" " \"autoplay LEVELDIR [NR ...]\" play level tapes for LEVELDIR\n" " \"convert LEVELDIR [NR]\" convert levels in LEVELDIR\n" + " \"create images DIRECTORY\" write BMP images to DIRECTORY\n" "\n", program.command_basename); } diff --git a/src/main.h b/src/main.h index 763195b9..aac5a59c 100644 --- a/src/main.h +++ b/src/main.h @@ -2346,6 +2346,8 @@ struct GlobalInfo char *convert_leveldir; int convert_level_nr; + char *create_images_dir; + int num_toons; float frames_per_second; -- 2.34.1