From: Holger Schemel Date: Tue, 21 Sep 2004 00:10:09 +0000 (+0200) Subject: rnd-20040921-1-src X-Git-Tag: 3.1.1^2~62 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=c5321d9d36d0a74062651d0352fbbaccbe125eca;p=rocksndiamonds.git rnd-20040921-1-src * added SDL support to graphics functions in native EM engine (by always using generic libgame interface functions) * fixed bug in frame synchronization in native EM engine * added code to convert levels between R'n'D and native EM engine * new Emerald Mine engine can now play levels selected in main menu --- diff --git a/ChangeLog b/ChangeLog index eebef01e..b80352d9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,9 +1,25 @@ +2004-09-21 + * added SDL support to graphics functions in native EM engine + (by always using generic libgame interface functions) + +2004-09-20 + * fixed bug in frame synchronization in native EM engine + +2004-09-18 + * added code to convert levels between R'n'D and native EM engine + +2004-08-23 + * new Emerald Mine engine can now play levels selected in main menu + 2004-08-16 * fixed big memory leak in function "CreateBitmapWithSmallBitmaps()" (which creates scaled down graphics for level editor and preview); there's still a memory leak somewhere in the artwork handling code * added "scale image up" functionality to X11 version of zoom function +2004-08-14 + * first attempts to integrate new, native Emerald Mine Club engine + 2004-08-07 * fixed bug in gadget code which caused reset of CEs in level editor (example: pressing 'b' [grab brush] on CE config page erased values) diff --git a/src/conf_gfx.c b/src/conf_gfx.c index cf8be2c5..59926438 100644 --- a/src/conf_gfx.c +++ b/src/conf_gfx.c @@ -3774,15 +3774,9 @@ struct ConfigInfo image_config[] = { "emc_object", "emc_object.pcx" }, { "emc_object.scale_up", "2" }, - { "emc_score", "emc_score.pcx" }, - { "emc_score.scale_up", "2" }, - { "emc_sprite", "emc_sprite.pcx" }, { "emc_sprite.scale_up", "2" }, - { "emc_title", "emc_title.pcx" }, - { "emc_title.scale_up", "2" }, - /* the following directives are not associated with an image, but probably make sense to be defined in "graphicsinfo.conf", too */ diff --git a/src/conf_gfx.h b/src/conf_gfx.h index c21fcc00..78930f59 100644 --- a/src/conf_gfx.h +++ b/src/conf_gfx.h @@ -1421,10 +1421,8 @@ #define IMG_BACKGROUND_SETUP 1400 #define IMG_BACKGROUND_DOOR 1401 #define IMG_EMC_OBJECT 1402 -#define IMG_EMC_SCORE 1403 -#define IMG_EMC_SPRITE 1404 -#define IMG_EMC_TITLE 1405 +#define IMG_EMC_SPRITE 1403 -#define NUM_IMAGE_FILES 1406 +#define NUM_IMAGE_FILES 1404 #endif /* CONF_GFX_H */ diff --git a/src/conftime.h b/src/conftime.h index f688d3be..5afa999d 100644 --- a/src/conftime.h +++ b/src/conftime.h @@ -1 +1 @@ -#define COMPILE_DATE_STRING "[2004-09-18 04:09]" +#define COMPILE_DATE_STRING "[2004-09-21 01:56]" diff --git a/src/game.c b/src/game.c index cb8a7974..8bf48184 100644 --- a/src/game.c +++ b/src/game.c @@ -8529,8 +8529,8 @@ void AdvanceFrameAndPlayerCounters(int player_nr) void GameActions() { - static unsigned long action_delay = 0; - unsigned long action_delay_value; + static unsigned long game_frame_delay = 0; + unsigned long game_frame_delay_value; int magic_wall_x = 0, magic_wall_y = 0; int i, x, y, element, graphic; byte *recorded_player_action; @@ -8542,15 +8542,15 @@ void GameActions() if (game_status != GAME_MODE_PLAYING) return; - action_delay_value = + game_frame_delay_value = (tape.playing && tape.fast_forward ? FfwdFrameDelay : GameFrameDelay); if (tape.playing && tape.warp_forward && !tape.pausing) - action_delay_value = 0; + game_frame_delay_value = 0; /* ---------- main game synchronization point ---------- */ - WaitUntilDelayReached(&action_delay, action_delay_value); + WaitUntilDelayReached(&game_frame_delay, game_frame_delay_value); if (network_playing && !network_player_action_received) { diff --git a/src/game_em/cave.c b/src/game_em/cave.c index a6c2a33b..6bd46220 100644 --- a/src/game_em/cave.c +++ b/src/game_em/cave.c @@ -3,21 +3,12 @@ * cave data structures */ -#include -#include -#include -#include -#include -#include - #include "global.h" #include "tile.h" #include "level.h" #include "file.h" -#if defined(TARGET_X11) - struct cave_node *cave_list; static void setLevelInfoToDefaults_EM(void) @@ -41,59 +32,6 @@ static void setLevelInfoToDefaults_EM(void) * * completely initializes the level structure, ready for a game */ -int OLD_cave_convert(char *filename) -{ - int result; - FILE *file; - int actual; - int length; - unsigned char buffer[16384]; - - /* always start with reliable default values */ - setLevelInfoToDefaults_EM(); - - file = fopen(filename, "rb"); - if (file == 0) - { - fprintf(stderr, "%s: \"%s\": %s: %s\n", progname, filename, "open error", - strerror(errno)); - result = 1; - goto fail; - } - - actual = fread(buffer, 1, 16384, file); - if (actual == -1) - { - fprintf(stderr, "%s: \"%s\": %s: %s\n", progname, filename, "read error", - strerror(errno)); - result = 1; - goto fail; - } - - length = actual; - fclose(file); - file = 0; - - if (!cleanup_em_level(buffer, &length)) - { - fprintf(stderr, "%s: \"%s\": %s\n", progname, filename, - "unrecognized format"); - result = 1; - goto fail; - } - - convert_em_level(buffer); - prepare_em_level(); - - result = 0; - - fail: - - if (file) - fclose(file); - - return(result); -} #define MAX_EM_LEVEL_SIZE 16384 @@ -136,80 +74,3 @@ boolean LoadNativeLevel_EM(char *filename) return TRUE; } - -void read_cave_list(void) -{ - char name[MAXNAME+2]; - struct cave_node *node, **prev; - DIR *dir; - struct dirent *entry; - char *cut; - int len; - - free_cave_list(); /* delete old list if i forgot to before */ - - name[MAXNAME] = 0; - if (arg_basedir) - { - snprintf(name, MAXNAME+2, "%s/%s", arg_basedir, EM_LVL_DIR); - } - else - { - snprintf(name, MAXNAME+2, "%s", EM_LVL_DIR); - } - - if (name[MAXNAME]) - snprintf_overflow("read cave/ directory"); - - dir = opendir(name); - if (dir) - { - prev = &cave_list; - while ((entry = readdir(dir))) - { - if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) - continue; - - node = malloc(sizeof(*node)); if (node == 0) break; - *prev = node; prev = &node->next; - - node->path[MAXNAME] = 0; - snprintf(node->path, MAXNAME+2, "%s/%s", name, entry->d_name); - if (node->path[MAXNAME]) - snprintf_overflow("read cave/ directory"); - - cut = strrchr(node->path, '/'); cut = cut ? cut + 1 : node->path; - len = strlen(cut); - if (len <= 32) - { - strncpy(node->name, cut, 32); - } - else - { - snprintf(node->name, 32, "%.8s..%s", cut, cut + len - 16); - } - } - - *prev = 0; - closedir(dir); - } - else - { - fprintf(stderr, "%s: \"%s\": %s: %s\n", progname, name, - "failed to open directory", strerror(errno)); - } -} - -void free_cave_list(void) -{ - struct cave_node *node, *next; - - for (node = cave_list; node; node = next) - { - next = node->next; - free(node); - } - cave_list = 0; -} - -#endif diff --git a/src/game_em/convert.c b/src/game_em/convert.c index aa6df647..245922f7 100644 --- a/src/game_em/convert.c +++ b/src/game_em/convert.c @@ -13,8 +13,6 @@ #include "level.h" -#if defined(TARGET_X11) - static unsigned char remap_v6[256] = { /* filter crap for v6 */ @@ -851,5 +849,3 @@ void prepare_em_level(void) ply2.joy_n = ply2.joy_e = ply2.joy_s = ply2.joy_w = ply2.joy_fire = 0; ply2.joy_stick = ply2.joy_spin = 0; } - -#endif diff --git a/src/game_em/display.h b/src/game_em/display.h index 0eb026a6..e5e5f55e 100644 --- a/src/game_em/display.h +++ b/src/game_em/display.h @@ -1,11 +1,6 @@ #ifndef DISPLAY_H #define DISPLAY_H -#include -#include -#include -#include - #include "game_em.h" #define ORIG_TILEX 16 @@ -46,20 +41,6 @@ #define SXSIZE (SCR_FIELDX * TILEX) #define SYSIZE (SCR_FIELDY * TILEY) -#if 0 - -extern Display *display; -extern Window window; -#define xwindow window - -#else - -#define xwindow (window->drawable) - -#endif - -#if 1 - extern Bitmap *screenBitmap; extern Bitmap *scoreBitmap; @@ -68,35 +49,13 @@ extern Bitmap *sprBitmap; extern Bitmap *ttlBitmap; extern Bitmap *botBitmap; -#endif - extern Pixmap screenPixmap; extern Pixmap scorePixmap; extern Pixmap spriteBitmap; -extern Pixmap objPixmap; extern Pixmap objmaskBitmap; -extern Pixmap sprPixmap; extern Pixmap sprmaskBitmap; -extern Pixmap ttlPixmap; -extern Pixmap ttlmaskBitmap; -extern Pixmap botPixmap; -extern Pixmap botmaskBitmap; -extern GC screenGC; -extern GC scoreGC; extern GC spriteGC; -extern GC antsGC; - -extern Atom deleteAtom; - -extern KeySym lastKeySym; - -extern KeyCode northKeyCode[]; -extern KeyCode eastKeyCode[]; -extern KeyCode southKeyCode[]; -extern KeyCode westKeyCode[]; -extern KeyCode fireKeyCode[]; -extern KeyCode escKeyCode[]; #endif diff --git a/src/game_em/game_em.h b/src/game_em/game_em.h index 4b05c49c..14400ffc 100644 --- a/src/game_em/game_em.h +++ b/src/game_em/game_em.h @@ -25,6 +25,7 @@ extern void SetBitmaps_EM(Bitmap **); extern void DrawGameDoorValues_EM(int, int, int, int); +extern int getGameFrameDelay_EM(int); /* ========================================================================= */ diff --git a/src/game_em/global.h b/src/game_em/global.h index c168a62b..2f53c3bc 100644 --- a/src/game_em/global.h +++ b/src/game_em/global.h @@ -10,15 +10,9 @@ /* arbitrary maximum length of filenames (cos i am lazy) */ #define MAXNAME 1024 -extern void snprintf_overflow(char *); - extern int debug; extern char *progname; extern char *arg_basedir; -extern char *arg_display; -extern char *arg_geometry; -extern int arg_install; -extern int arg_silence; extern unsigned int frame; diff --git a/src/game_em/graphics.c b/src/game_em/graphics.c index 2de3e170..3dcbb778 100644 --- a/src/game_em/graphics.c +++ b/src/game_em/graphics.c @@ -3,16 +3,11 @@ * graphics manipulation crap */ -#include -#include - #include "global.h" #include "display.h" #include "level.h" -#if defined(TARGET_X11) - unsigned int frame; /* current screen frame */ unsigned int screen_x; /* current scroll position */ unsigned int screen_y; @@ -69,8 +64,6 @@ void blitscreen(void) x - 2 * TILEX, y - 2 * TILEY, SX + MAX_BUF_XSIZE * TILEX - x, SY + MAX_BUF_YSIZE * TILEY - y); } - - XFlush(display); } @@ -117,122 +110,112 @@ static void blitplayer(struct PLAYER *ply) { unsigned int x, y, dx, dy; unsigned short obj, spr; + int src_x, src_y, dest_x, dest_y; - if (ply->alive) - { - x = (frame * ply->oldx + (8 - frame) * ply->x) * TILEX / 8; - y = (frame * ply->oldy + (8 - frame) * ply->y) * TILEY / 8; - dx = x + TILEX - 1; - dy = y + TILEY - 1; - - if ((unsigned int)(dx - screen_x) < ((MAX_BUF_XSIZE - 1) * TILEX - 1) && - (unsigned int)(dy - screen_y) < ((MAX_BUF_YSIZE - 1) * TILEY - 1)) - { - spr = map_spr[ply->num][frame][ply->anim]; - x %= MAX_BUF_XSIZE * TILEX; - y %= MAX_BUF_YSIZE * TILEY; - dx %= MAX_BUF_XSIZE * TILEX; - dy %= MAX_BUF_YSIZE * TILEY; - - if (objmaskBitmap) - { - obj = screentiles[y / TILEY][x / TILEX]; - XCopyArea(display, objmaskBitmap, spriteBitmap, spriteGC, - (obj / 512) * TILEX, (obj % 512) * TILEY / 16, TILEX, TILEY, - -(x % TILEX), -(y % TILEY)); - - obj = screentiles[dy / TILEY][dx / TILEX]; - XCopyArea(display, objmaskBitmap, spriteBitmap, spriteGC, - (obj / 512) * TILEX, (obj % 512) * TILEY / 16, TILEX, TILEY, - (MAX_BUF_XSIZE * TILEX - x) % TILEX, - (MAX_BUF_YSIZE * TILEY - y) % TILEY); - } - else if (sprmaskBitmap) - { - XCopyArea(display, sprmaskBitmap, spriteBitmap, spriteGC, - (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY, 0, 0); - } - else - { - XFillRectangle(display, spriteBitmap, spriteGC, 0, 0, TILEX, TILEY); - } - - screentiles[y / TILEY][x / TILEX] = -1; /* mark screen as dirty */ - screentiles[dy / TILEY][dx / TILEX] = -1; + if (!ply->alive) + return; -#if 1 + x = (frame * ply->oldx + (8 - frame) * ply->x) * TILEX / 8; + y = (frame * ply->oldy + (8 - frame) * ply->y) * TILEY / 8; + dx = x + TILEX - 1; + dy = y + TILEY - 1; + if ((unsigned int)(dx - screen_x) < ((MAX_BUF_XSIZE - 1) * TILEX - 1) && + (unsigned int)(dy - screen_y) < ((MAX_BUF_YSIZE - 1) * TILEY - 1)) + { + spr = map_spr[ply->num][frame][ply->anim]; + x %= MAX_BUF_XSIZE * TILEX; + y %= MAX_BUF_YSIZE * TILEY; + dx %= MAX_BUF_XSIZE * TILEX; + dy %= MAX_BUF_YSIZE * TILEY; #if 1 - - SetClipMask(sprBitmap, sprBitmap->stored_clip_gc, spriteBitmap); - - SetClipOrigin(sprBitmap, sprBitmap->stored_clip_gc, x, y); - BlitBitmapMasked(sprBitmap, screenBitmap, - (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY, - x, y); - - SetClipOrigin(sprBitmap, sprBitmap->stored_clip_gc, - x - MAX_BUF_XSIZE * TILEX, y); - BlitBitmapMasked(sprBitmap, screenBitmap, - (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY, - x - MAX_BUF_XSIZE * TILEX, y); - - SetClipOrigin(sprBitmap, sprBitmap->stored_clip_gc, - x, y - MAX_BUF_YSIZE * TILEY); - BlitBitmapMasked(sprBitmap, screenBitmap, - (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY, - x, y - MAX_BUF_YSIZE * TILEY); - - SetClipMask(sprBitmap, sprBitmap->stored_clip_gc, None); + /* draw the player to current location */ + BlitBitmap(sprBitmap, screenBitmap, + (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY, + x, y); + /* draw the player to opposite wrap-around column */ + BlitBitmap(sprBitmap, screenBitmap, + (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY, + x - MAX_BUF_XSIZE * TILEX, y), + /* draw the player to opposite wrap-around row */ + BlitBitmap(sprBitmap, screenBitmap, + (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY, + x, y - MAX_BUF_YSIZE * TILEY); + + /* draw the field the player is moving from (masked over the player) */ + obj = screentiles[y / TILEY][x / TILEX]; + src_x = (obj / 512) * TILEX; + src_y = (obj % 512) * TILEY / 16; + dest_x = (x / TILEX) * TILEX; + dest_y = (y / TILEY) * TILEY; + + SetClipOrigin(objBitmap, objBitmap->stored_clip_gc, + dest_x - src_x, dest_y - src_y); + BlitBitmapMasked(objBitmap, screenBitmap, + src_x, src_y, TILEX, TILEY, dest_x, dest_y); + + /* draw the field the player is moving to (masked over the player) */ + obj = screentiles[dy / TILEY][dx / TILEX]; + src_x = (obj / 512) * TILEX; + src_y = (obj % 512) * TILEY / 16; + dest_x = (dx / TILEX) * TILEX; + dest_y = (dy / TILEY) * TILEY; + + SetClipOrigin(objBitmap, objBitmap->stored_clip_gc, + dest_x - src_x, dest_y - src_y); + BlitBitmapMasked(objBitmap, screenBitmap, + src_x, src_y, TILEX, TILEY, dest_x, dest_y); #else - XSetClipMask(display, sprBitmap->stored_clip_gc, spriteBitmap); + if (objmaskBitmap) + { + obj = screentiles[y / TILEY][x / TILEX]; + XCopyArea(display, objmaskBitmap, spriteBitmap, spriteGC, + (obj / 512) * TILEX, (obj % 512) * TILEY / 16, TILEX, TILEY, + -(x % TILEX), -(y % TILEY)); + + obj = screentiles[dy / TILEY][dx / TILEX]; + XCopyArea(display, objmaskBitmap, spriteBitmap, spriteGC, + (obj / 512) * TILEX, (obj % 512) * TILEY / 16, TILEX, TILEY, + (MAX_BUF_XSIZE * TILEX - x) % TILEX, + (MAX_BUF_YSIZE * TILEY - y) % TILEY); + } + else if (sprmaskBitmap) + { + XCopyArea(display, sprmaskBitmap, spriteBitmap, spriteGC, + (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY, 0, 0); + } + else + { + XFillRectangle(display, spriteBitmap, spriteGC, 0, 0, TILEX, TILEY); + } + + SetClipMask(sprBitmap, sprBitmap->stored_clip_gc, spriteBitmap); - XSetClipOrigin(display, sprBitmap->stored_clip_gc, x, y); - XCopyArea(display, sprBitmap->drawable, screenBitmap->drawable, - sprBitmap->stored_clip_gc, - (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY, - x, y); + SetClipOrigin(sprBitmap, sprBitmap->stored_clip_gc, x, y); + BlitBitmapMasked(sprBitmap, screenBitmap, + (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY, + x, y); - XSetClipOrigin(display, sprBitmap->stored_clip_gc, + SetClipOrigin(sprBitmap, sprBitmap->stored_clip_gc, + x - MAX_BUF_XSIZE * TILEX, y); + BlitBitmapMasked(sprBitmap, screenBitmap, + (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY, x - MAX_BUF_XSIZE * TILEX, y); - XCopyArea(display, sprBitmap->drawable, screenBitmap->drawable, - sprBitmap->stored_clip_gc, - (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY, - x - MAX_BUF_XSIZE * TILEX, y); - XSetClipOrigin(display, sprBitmap->stored_clip_gc, + SetClipOrigin(sprBitmap, sprBitmap->stored_clip_gc, + x, y - MAX_BUF_YSIZE * TILEY); + BlitBitmapMasked(sprBitmap, screenBitmap, + (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY, x, y - MAX_BUF_YSIZE * TILEY); - XCopyArea(display, sprBitmap->drawable, screenBitmap->drawable, - sprBitmap->stored_clip_gc, - (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY, - x, y - MAX_BUF_YSIZE * TILEY); - - XSetClipMask(display, sprBitmap->stored_clip_gc, None); + SetClipMask(sprBitmap, sprBitmap->stored_clip_gc, None); #endif -#else - - XSetClipMask(display, screenGC, spriteBitmap); - XSetClipOrigin(display, screenGC, x, y); - XCopyArea(display, sprPixmap, screenPixmap, screenGC, - (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY, - x, y); - XSetClipOrigin(display, screenGC, x - MAX_BUF_XSIZE * TILEX, y); - XCopyArea(display, sprPixmap, screenPixmap, screenGC, - (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY, - x - MAX_BUF_XSIZE * TILEX, y); - XSetClipOrigin(display, screenGC, x, y - MAX_BUF_YSIZE * TILEY); - XCopyArea(display, sprPixmap, screenPixmap, screenGC, - (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY, - x, y - MAX_BUF_YSIZE * TILEY); - XSetClipMask(display, screenGC, None); - -#endif - } + screentiles[y / TILEY][x / TILEX] = -1; /* mark screen as dirty */ + screentiles[dy / TILEY][dx / TILEX] = -1; } } @@ -279,7 +262,5 @@ void game_animscreen(void) blitplayer(&ply2); blitscreen(); - XFlush(display); + FlushDisplay(); } - -#endif diff --git a/src/game_em/init.c b/src/game_em/init.c index 972e262d..31ada8d8 100644 --- a/src/game_em/init.c +++ b/src/game_em/init.c @@ -3,23 +3,8 @@ * open X11 display and sound */ -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include -#include -#include #include -#include -#include +#include #include "game_em.h" @@ -28,59 +13,32 @@ #include "sample.h" -#if defined(TARGET_X11) - -#if 1 Bitmap *objBitmap; -Bitmap *botBitmap; Bitmap *sprBitmap; -Bitmap *ttlBitmap; -#endif -#if 1 Bitmap *screenBitmap; -Bitmap *scoreBitmap; -#endif -Pixmap screenPixmap; -Pixmap scorePixmap; +#if 0 Pixmap spriteBitmap; +#endif Pixmap objPixmap; -Pixmap objmaskBitmap; -Pixmap botPixmap; -Pixmap botmaskBitmap; Pixmap sprPixmap; + +#if 0 +Pixmap objmaskBitmap; Pixmap sprmaskBitmap; -Pixmap ttlPixmap; -Pixmap ttlmaskBitmap; -GC screenGC; -GC scoreGC; GC spriteGC; +#endif char play[SAMPLE_MAX]; +#if defined(AUDIO_UNIX_NATIVE) static int sound_pid = -1; -int sound_pipe[2] = { -1, -1 }; /* for communication */ -short *sound_data[SAMPLE_MAX]; /* pointer to sound data */ -long sound_length[SAMPLE_MAX]; /* length of sound data */ - -static Screen *defaultScreen; -static Visual *defaultVisual; -static Colormap defaultColourmap; -static Window defaultRootWindow; -static unsigned int screenDepth; -static unsigned int screenWidth; -static unsigned int screenHeight; -static unsigned long screenBlackPixel; -static unsigned long screenWhitePixel; - -static XGCValues gcValues; - -#if 1 -static Bitmap *pcxBitmapsX2[4]; -#endif +int sound_pipe[2] = { -1, -1 }; /* for communication */ +short *sound_data[SAMPLE_MAX]; /* pointer to sound data */ +long sound_length[SAMPLE_MAX]; /* length of sound data */ static const char *sound_names[SAMPLE_MAX] = { @@ -99,76 +57,43 @@ static const int sound_volume[SAMPLE_MAX] = 100,20,100,100,100,100,100,20,100,100, 100 }; +#endif + +char *progname; +char *arg_basedir; + +extern void tab_generate(); +extern void ulaw_generate(); int open_all(void) { - char name[MAXNAME+2]; - int i; - - defaultScreen = DefaultScreenOfDisplay(display); - defaultVisual = DefaultVisualOfScreen(defaultScreen); - defaultColourmap = DefaultColormapOfScreen(defaultScreen); - defaultRootWindow = RootWindowOfScreen(defaultScreen); - screenDepth = DefaultDepthOfScreen(defaultScreen); - screenWidth = WidthOfScreen(defaultScreen); - screenHeight = HeightOfScreen(defaultScreen); - screenBlackPixel = BlackPixelOfScreen(defaultScreen); - screenWhitePixel = WhitePixelOfScreen(defaultScreen); + Bitmap *emc_bitmaps[2]; +#if 0 + XGCValues gcValues; +#endif #if 1 - SetBitmaps_EM(pcxBitmapsX2); + SetBitmaps_EM(emc_bitmaps); - objBitmap = pcxBitmapsX2[0]; - botBitmap = pcxBitmapsX2[1]; - sprBitmap = pcxBitmapsX2[2]; - ttlBitmap = pcxBitmapsX2[3]; + objBitmap = emc_bitmaps[0]; + sprBitmap = emc_bitmaps[1]; - objPixmap = pcxBitmapsX2[0]->drawable; - botPixmap = pcxBitmapsX2[1]->drawable; - sprPixmap = pcxBitmapsX2[2]->drawable; - ttlPixmap = pcxBitmapsX2[3]->drawable; +#if 0 + objPixmap = emc_bitmaps[0]->drawable; + sprPixmap = emc_bitmaps[1]->drawable; - objmaskBitmap = pcxBitmapsX2[0]->clip_mask; - botmaskBitmap = pcxBitmapsX2[1]->clip_mask; - sprmaskBitmap = pcxBitmapsX2[2]->clip_mask; - ttlmaskBitmap = pcxBitmapsX2[3]->clip_mask; + objmaskBitmap = emc_bitmaps[0]->clip_mask; + sprmaskBitmap = emc_bitmaps[1]->clip_mask; +#endif screenBitmap = CreateBitmap(MAX_BUF_XSIZE * TILEX, MAX_BUF_YSIZE * TILEY, DEFAULT_DEPTH); - scoreBitmap = CreateBitmap(20 * TILEX, SCOREY, DEFAULT_DEPTH); - - screenPixmap = screenBitmap->drawable; - scorePixmap = scoreBitmap->drawable; #endif - spriteBitmap = XCreatePixmap(display, xwindow, TILEX, TILEY, 1); +#if 0 + spriteBitmap = XCreatePixmap(display, window->drawable, TILEX, TILEY, 1); if (spriteBitmap == 0) - { - fprintf(stderr, "%s: \"%s\": %s: %s\n", progname, - XDisplayName(arg_display), "failed to create pixmap", - strerror(errno)); - return(1); - } - - gcValues.graphics_exposures = False; - screenGC = XCreateGC(display, screenPixmap, GCGraphicsExposures, &gcValues); - if (screenGC == 0) - { - fprintf(stderr, "%s: \"%s\": %s: %s\n", progname, - XDisplayName(arg_display), "failed to create graphics context", - strerror(errno)); - return(1); - } - - gcValues.graphics_exposures = False; - scoreGC = XCreateGC(display, scorePixmap, GCGraphicsExposures, &gcValues); - if (scoreGC == 0) - { - fprintf(stderr, "%s: \"%s\": %s: %s\n", progname, - XDisplayName(arg_display), "failed to create graphics context", - strerror(errno)); - return(1); - } + Error(ERR_EXIT, "failed to create sprite pixmap for EM engine"); gcValues.function = objmaskBitmap ? GXcopyInverted : sprmaskBitmap ? GXcopy : GXset; @@ -176,24 +101,20 @@ int open_all(void) spriteGC = XCreateGC(display, spriteBitmap, GCFunction | GCGraphicsExposures, &gcValues); if (spriteGC == 0) - { - fprintf(stderr, "%s: \"%s\": %s: %s\n", progname, - XDisplayName(arg_display), "failed to create graphics context", - strerror(errno)); - return(1); - } + Error(ERR_EXIT, "failed to create sprite GC for EM engine"); +#endif /* ----------------------------------------------------------------- */ -#if defined(PLATFORM_LINUX) || defined(PLATFORM_BSD) +#if defined(AUDIO_UNIX_NATIVE) -#if 1 - /* disable sound */ - arg_silence = 1; -#endif +#if defined(PLATFORM_LINUX) || defined(PLATFORM_BSD) - if (arg_silence == 0) + if (1) { + char name[MAXNAME+2]; + int i; + for (i = 0; i < SAMPLE_MAX; i++) { name[MAXNAME] = 0; @@ -208,7 +129,8 @@ int open_all(void) snprintf(name, MAXNAME+2, "%s/%s", EM_SND_DIR, sound_names[i]); } - if (name[MAXNAME]) snprintf_overflow("read sounds/ directory"); + if (name[MAXNAME]) + Error(ERR_EXIT, "buffer overflow when reading sounds directory"); if (read_sample(name, &sound_data[i], &sound_length[i])) return(1); @@ -224,16 +146,16 @@ int open_all(void) if (pipe(sound_pipe) == -1) { - fprintf(stderr, "%s: %s: %s\n", progname, "unable to create sound pipe", - strerror(errno)); + Error(ERR_WARN, "unable to create sound pipe for EM engine -- no sound"); + return(1); } sound_pid = fork(); if (sound_pid == -1) { - fprintf(stderr, "%s: %s: %s\n", progname, "unable to fork sound thread", - strerror(errno)); + Error(ERR_WARN, "unable to fork sound thread for EM engine -- no sound"); + return(1); } @@ -244,13 +166,30 @@ int open_all(void) signal(SIGPIPE, SIG_IGN); /* dont crash if sound process dies */ } -#endif /* defined(PLATFORM_LINUX) || defined(PLATFORM_BSD) */ +#endif /* defined(PLATFORM_LINUX) || defined(PLATFORM_BSD) */ + +#endif /* AUDIO_UNIX_NATIVE */ return(0); } -void close_all(void) +void em_open_all() +{ + /* pre-calculate some data */ + tab_generate(); + ulaw_generate(); + + progname = "emerald mine"; + + if (open_all() != 0) + Error(ERR_EXIT, "em_open_all(): open_all() failed"); + + game_init_vars(); +} + +void em_close_all(void) { +#if defined(AUDIO_UNIX_NATIVE) int i; if (sound_pid != -1) @@ -267,28 +206,27 @@ void close_all(void) for (i = 0; i < SAMPLE_MAX; i++) if (sound_data[i]) free(sound_data[i]); +#endif - if (screenGC) - XFreeGC(display, screenGC); - if (scoreGC) - XFreeGC(display, scoreGC); +#if 0 if (spriteGC) XFreeGC(display, spriteGC); if (spriteBitmap) XFreePixmap(display, spriteBitmap); +#endif } /* ---------------------------------------------------------------------- */ void sound_play(void) { +#if defined(AUDIO_UNIX_NATIVE) if (sound_pipe[1] != -1) { if (write(sound_pipe[1], &play, sizeof(play)) == -1) { - fprintf(stderr, "%s: %s: %s\n", progname, "write sound", - strerror(errno)); + Error(ERR_WARN, "cannot write into pipe to child process -- no sounds"); if (sound_pipe[0] != -1) { @@ -305,6 +243,5 @@ void sound_play(void) } memset(play, 0, sizeof(play)); -} - #endif +} diff --git a/src/game_em/input.c b/src/game_em/input.c index 86feeb4d..a6ddcfab 100644 --- a/src/game_em/input.c +++ b/src/game_em/input.c @@ -3,25 +3,11 @@ * handle input from x11 and keyboard and joystick */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - #include "global.h" #include "display.h" #include "level.h" -#if defined(TARGET_X11) - unsigned long Random; struct PLAYER ply1; @@ -82,7 +68,15 @@ void InitGameEngine_EM() void GameActions_EM(byte action) { - input_eventloop(); + static unsigned long game_frame_delay = 0; + unsigned long game_frame_delay_value = getGameFrameDelay_EM(25); + +#if 0 + /* this is done in screens.c/HandleGameActions() by calling BackToFront() */ + XSync(display, False); /* block until all graphics are drawn */ +#endif + + WaitUntilDelayReached(&game_frame_delay, game_frame_delay_value); game_animscreen(); @@ -139,36 +133,3 @@ void readjoy(byte action) ply1.joy_w = west; } } - - -/* handle events from x windows and block until the next frame */ - -void input_eventloop(void) -{ - static struct timeval tv1 = { 0, 0 }; - static struct timeval tv2 = { 0, 0 }; - unsigned long count; - - XSync(display, False); /* block until all graphics are drawn */ - - if (gettimeofday(&tv2, 0) == -1) - tv2.tv_usec = 0; - - count = tv2.tv_usec + 1000000 - tv1.tv_usec; - if (count >= 1000000) - count -= 1000000; - - tv1.tv_usec = tv2.tv_usec; - if (count < 25000) - { - tv2.tv_sec = 0; - tv2.tv_usec = 25000 - count; -#if 1 - select(0, 0, 0, 0, &tv2); /* sleep a bit */ -#else - usleep(tv2.tv_usec); -#endif - } -} - -#endif diff --git a/src/game_em/main.c b/src/game_em/main.c index 874bc780..85f92c91 100644 --- a/src/game_em/main.c +++ b/src/game_em/main.c @@ -6,68 +6,3 @@ * * set everything up and close everything down */ - -#include -#include -#include -#include -#include - -#include "global.h" - - -#if defined(TARGET_X11) - -char *progname; -char *arg_basedir; -char *arg_display; -char *arg_geometry; -int arg_install; -int arg_silence; - -extern void tab_generate(); -extern void ulaw_generate(); - -extern void game_menu_init(); - -void em_open_all() -{ - /* pre-calculate some data */ - tab_generate(); - ulaw_generate(); - - progname = "emerald mine"; - - if (open_all() != 0) - Error(ERR_EXIT, "em_open_all(): open_all() failed"); - - game_init_vars(); -} - -void em_close_all() -{ - close_all(); -} - -/* massive kludge for buffer overflows - * i cant think of an elegant way to handle this situation. - * oh wait yes i can. dynamically allocate each string. oh well - */ -void snprintf_overflow(char *description) -{ - fprintf(stderr, "%s: %s\n", progname, - "buffer overflow; check EMERALD_BASE environment variable"); - fprintf(stderr, "%s %s\n", "Fault occured while attempting to", description); - - abort(); -} - -#else - -int em_main() -{ - /* temporary dummy until X11->SDL conversion finished */ - return 0; -} - -#endif diff --git a/src/game_em/sample.h b/src/game_em/sample.h index e35d7e5f..91ff0453 100644 --- a/src/game_em/sample.h +++ b/src/game_em/sample.h @@ -44,10 +44,14 @@ extern long sound_length[SAMPLE_MAX]; #define MIXER_MAX 4 /* maximum number of samples we can play at once */ +#if defined(AUDIO_UNIX_NATIVE) + enum { AUDIO_ULAW = 0, AUDIO_U8 }; -#endif +#endif /* AUDIO_UNIX_NATIVE */ + +#endif /* SAMPLE_H */ diff --git a/src/game_em/sound.c b/src/game_em/sound.c index c949abb5..afaabcd4 100644 --- a/src/game_em/sound.c +++ b/src/game_em/sound.c @@ -6,29 +6,20 @@ #include "game_em.h" -#if defined(TARGET_X11) +#if defined(AUDIO_UNIX_NATIVE) #if defined(PLATFORM_LINUX) || defined(PLATFORM_BSD) #ifdef PLATFORM_LINUX +#include #include #endif #ifdef PLATFORM_BSD +#include #include #endif -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - #include "global.h" #include "sample.h" @@ -107,8 +98,8 @@ int sound_thread(void) if (i == -1) { - fprintf(stderr, "%s: %s: %s\n", progname, "select failed", - strerror(errno)); + Error(ERR_WARN, "select() failed in sound thread"); + goto fail; } @@ -121,20 +112,22 @@ int sound_thread(void) if (i == -1) { - fprintf(stderr, "%s: %s: %s\n", progname, "read failed", - strerror(errno)); + Error(ERR_WARN, "read() failed in sound thread"); + goto fail; } if (i == 0) { - fprintf(stderr, "%s: %s: %s\n", progname, "read sound", "Broken pipe"); + Error(ERR_WARN, "reading sound failed in sound thread"); + goto fail; } if (i != sizeof(play)) { - fprintf(stderr, "%s: %s\n", progname, "bad message length"); + Error(ERR_WARN, "bad message length in sound thread"); + goto fail; } @@ -161,15 +154,15 @@ int sound_thread(void) if (ioctl(audio_fd, SNDCTL_DSP_SETFRAGMENT, &i) == -1) { - fprintf(stderr, "%s: \"%s\": %s (%d): %s\n", progname, audioname, - "unable to set fragment size", 512, strerror(errno)); + Error(ERR_WARN, "unable to set fragment size in sound thread"); + goto reset; } if (ioctl(audio_fd, SNDCTL_DSP_GETFMTS, &i) == -1) { - fprintf(stderr, "%s: \"%s\": %s: %s\n", progname, audioname, - "unable to query audio format", strerror(errno)); + Error(ERR_WARN, "unable to query audio format in sound thread"); + goto reset; } @@ -179,8 +172,8 @@ int sound_thread(void) i = audio_format; if (ioctl(audio_fd, SNDCTL_DSP_SETFMT, &i) == -1) { - fprintf(stderr, "%s: \"%s\": %s (%d): %s\n", progname, audioname, - "unable to set audio format", audio_format, strerror(errno)); + Error(ERR_WARN, "unable to set audio format in sound thread"); + goto reset; } @@ -194,39 +187,39 @@ int sound_thread(void) } else { - fprintf(stderr, "%s: \"%s\": %s (%d)\n", progname, audioname, - "audio format required by device not supported", i); + Error(ERR_WARN, "audio format required by device not supported"); + goto reset; } i = 1; if (ioctl(audio_fd, SNDCTL_DSP_CHANNELS, &i) == -1) { - fprintf(stderr, "%s: \"%s\": %s: %s\n", progname, audioname, - "unable to set channels to mono", strerror(errno)); + Error(ERR_WARN, "unable to set channels to mono in sound thread"); + goto reset; } if (i != 1) { - fprintf(stderr, "%s: \"%s\": %s (%d)\n", progname, audioname, - "channels required by device not supported", i); + Error(ERR_WARN, "channels required by device not supported"); + goto reset; } i = 8000; if (ioctl(audio_fd, SNDCTL_DSP_SPEED, &i) == -1) { - fprintf(stderr, "%s: \"%s\": %s: %s\n", progname, audioname, - "unable to set sampling rate", strerror(errno)); + Error(ERR_WARN, "unable to set sampling rate in sound thread"); + goto reset; } sample_rate = i; if (ioctl(audio_fd, SNDCTL_DSP_GETBLKSIZE, &i) == -1) { - fprintf(stderr, "%s: \"%s\": %s: %s\n", progname, audioname, - "unable to get block size", strerror(errno)); + Error(ERR_WARN, "unable to get block size in sound thread"); + goto reset; } @@ -235,8 +228,8 @@ int sound_thread(void) #else if (fcntl(audio_fd, F_SETFL, O_NONBLOCK) == -1) { - fprintf(stderr, "%s: \"%s\": %s: %s\n", progname, audioname, - "unable to make audio non blocking", strerror(errno)); + Error(ERR_WARN, "unable to make audio non blocking in sound thread"); + goto reset; } @@ -245,18 +238,16 @@ int sound_thread(void) audio_buffer = malloc(fragment_size * sizeof(*audio_buffer)); if (audio_buffer == 0) { - fprintf(stderr, "%s: %s (%d): %s\n", progname, - "unable to malloc audio buffer", - fragment_size * sizeof(*audio_buffer), strerror(errno)); + Error(ERR_WARN, "unable to malloc audio buffer in sound thread"); + goto fail; } mix_buffer = malloc(fragment_size * sizeof(*mix_buffer)); if (mix_buffer == 0) { - fprintf(stderr, "%s: %s (%d): %s\n", progname, - "unable to malloc mixing buffer", - fragment_size * sizeof(*mix_buffer), strerror(errno)); + Error(ERR_WARN, "unable to malloc mixing buffer in sound thread"); + goto fail; } } @@ -326,14 +317,15 @@ int sound_thread(void) i = write(audio_fd, audio_buffer, fragment_size); if (i == -1) { - fprintf(stderr, "%s: %s: %s\n", progname, "write error", - strerror(errno)); + Error(ERR_WARN, "cannot write to audio device in sound thread"); + goto reset; } if (i != fragment_size) { - fprintf(stderr, "%s: %s\n", progname, "bad write length"); + Error(ERR_WARN, "bad write length to audio device in sound thread"); + goto reset; } } @@ -374,8 +366,8 @@ int read_sample(char *name, short **data, long *length) file = fopen(name, "rb"); if (file == 0) { - fprintf(stderr, "%s: \"%s\": %s: %s\n", progname, name, "open error", - strerror(errno)); + Error(ERR_WARN, "cannot open file '%s' in sound thread", name); + result = 1; goto fail; } @@ -383,15 +375,16 @@ int read_sample(char *name, short **data, long *length) actual = fread(buffer, 1, 24, file); if (actual == -1) { - fprintf(stderr, "%s: \"%s\": %s: %s\n", progname, name, "read error", - strerror(errno)); + Error(ERR_WARN, "cannot read file '%s' in sound thread", name); + result = 1; goto fail; } if (actual < 24) { - fprintf(stderr, "%s: \"%s\": %s\n", progname, name, "premature eof"); + Error(ERR_WARN, "premature eof of file '%s' in sound thread", name); + result = 1; goto fail; } @@ -400,8 +393,8 @@ int read_sample(char *name, short **data, long *length) temp = buffer[0] << 24 | buffer[1] << 16 | buffer[2] << 8 | buffer[3]; if (temp != 0x2e736e64) { - fprintf(stderr, "%s: \"%s\": %s\n", progname, name, - "unrecognized file format"); + Error(ERR_WARN, "unrecognized format of file '%s' in sound thread", name); + result = 1; goto fail; } @@ -410,7 +403,8 @@ int read_sample(char *name, short **data, long *length) temp = buffer[4] << 24 | buffer[5] << 16 | buffer[6] << 8 | buffer[7]; if (temp < 24) { - fprintf(stderr, "%s: \"%s\": %s\n", progname, name, "bad header length"); + Error(ERR_WARN, "bad header length of file '%s' in sound thread", name); + result = 1; goto fail; } @@ -461,9 +455,9 @@ int read_sample(char *name, short **data, long *length) dataptr = malloc(datalength * sizeof(*dataptr)); if (dataptr == 0) { - fprintf(stderr, "%s: \"%s\": %s (%ld): %s\n", progname, name, - "unable to malloc buffer", datalength * sizeof(*dataptr), - strerror(errno)); + Error(ERR_WARN, "unable to malloc buffer for file '%s' in sound thread", + name); + result = 1; goto fail; } @@ -492,4 +486,4 @@ int read_sample(char *name, short **data, long *length) #endif /* defined(PLATFORM_LINUX) || defined(PLATFORM_BSD) */ -#endif +#endif /* AUDIO_UNIX_NATIVE */ diff --git a/src/game_em/synchro_1.c b/src/game_em/synchro_1.c index 3af35743..695d52f3 100644 --- a/src/game_em/synchro_1.c +++ b/src/game_em/synchro_1.c @@ -10,8 +10,6 @@ #include "sample.h" -#if defined(TARGET_X11) - static void player(struct PLAYER *); static int test(struct PLAYER *); static void die(struct PLAYER *); @@ -1070,5 +1068,3 @@ static void player(struct PLAYER *ply) } } } - -#endif diff --git a/src/game_em/synchro_2.c b/src/game_em/synchro_2.c index 4fbf2d9f..68567235 100644 --- a/src/game_em/synchro_2.c +++ b/src/game_em/synchro_2.c @@ -14,8 +14,6 @@ #include "sample.h" -#if defined(TARGET_X11) - #define RANDOM (random = random << 31 | random >> 1) #define PLAY(sample) { if ((unsigned int)(y - top) <= 12 && (unsigned int)(x - left) <= 20) play[sample] = 1; } @@ -4795,5 +4793,3 @@ void synchro_2(void) Draw = temp; } } - -#endif diff --git a/src/game_em/synchro_3.c b/src/game_em/synchro_3.c index d47741f9..230a907c 100644 --- a/src/game_em/synchro_3.c +++ b/src/game_em/synchro_3.c @@ -10,8 +10,6 @@ #include "sample.h" -#if defined(TARGET_X11) - void synchro_3(void) { register unsigned int x; @@ -119,5 +117,3 @@ void synchro_3(void) for (x = 0; x < WIDTH; x++) Next[y][x] = Cave[y][x]; } - -#endif diff --git a/src/game_em/tab_generate.c b/src/game_em/tab_generate.c index a2f2c901..5039f5ab 100644 --- a/src/game_em/tab_generate.c +++ b/src/game_em/tab_generate.c @@ -11,12 +11,9 @@ * modify. */ -#include #include "tile.h" -#if defined(TARGET_X11) - /* ---------------------------------------------------------------------- */ /* 0=stop 1=blank */ @@ -4499,5 +4496,3 @@ void tab_generate() create_obj(); create_spr(); } - -#endif diff --git a/src/game_em/ulaw_generate.c b/src/game_em/ulaw_generate.c index b094b5d1..1c8017c9 100644 --- a/src/game_em/ulaw_generate.c +++ b/src/game_em/ulaw_generate.c @@ -7,12 +7,8 @@ #include "game_em.h" -#if defined(TARGET_X11) - #if defined(PLATFORM_LINUX) || defined(PLATFORM_BSD) -#include - int calc_ulaw_to_linear(unsigned char); unsigned char calc_linear_to_ulaw(int); @@ -138,5 +134,3 @@ unsigned char calc_linear_to_ulaw(int sample) } #endif /* defined(PLATFORM_LINUX) || defined(PLATFORM_BSD) */ - -#endif diff --git a/src/init.c b/src/init.c index 27acb33a..175c063a 100644 --- a/src/init.c +++ b/src/init.c @@ -265,7 +265,7 @@ void InitElementSmallImages() #if 1 /* !!! FIX THIS (CHANGE TO USING NORMAL ELEMENT GRAPHIC DEFINITIONS) !!! */ - for (i = IMG_EMC_OBJECT; i <= IMG_EMC_TITLE; i++) + for (i = IMG_EMC_OBJECT; i <= IMG_EMC_SPRITE; i++) InitElementSmallImagesScaledUp(i); #endif } @@ -275,9 +275,7 @@ void InitElementSmallImages() void SetBitmaps_EM(Bitmap **em_bitmap) { em_bitmap[0] = graphic_info[IMG_EMC_OBJECT].bitmap; - em_bitmap[1] = graphic_info[IMG_EMC_SCORE].bitmap; - em_bitmap[2] = graphic_info[IMG_EMC_SPRITE].bitmap; - em_bitmap[3] = graphic_info[IMG_EMC_TITLE].bitmap; + em_bitmap[1] = graphic_info[IMG_EMC_SPRITE].bitmap; } #endif diff --git a/src/tools.c b/src/tools.c index f714b184..9a924824 100644 --- a/src/tools.c +++ b/src/tools.c @@ -2969,3 +2969,9 @@ int el2preimg(int element) return element_info[element].special_graphic[GFX_SPECIAL_ARG_PREVIEW]; } + +int getGameFrameDelay_EM(int native_em_game_frame_delay) +{ + return (GameFrameDelay == GAME_FRAME_DELAY ? native_em_game_frame_delay : + GameFrameDelay); +}