+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)
{ "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 */
#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 */
-#define COMPILE_DATE_STRING "[2004-09-18 04:09]"
+#define COMPILE_DATE_STRING "[2004-09-21 01:56]"
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;
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)
{
* cave data structures
*/
-#include <sys/types.h>
-#include <dirent.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
-
#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)
*
* 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
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
#include "level.h"
-#if defined(TARGET_X11)
-
static unsigned char remap_v6[256] =
{
/* filter crap for v6 */
ply2.joy_n = ply2.joy_e = ply2.joy_s = ply2.joy_w = ply2.joy_fire = 0;
ply2.joy_stick = ply2.joy_spin = 0;
}
-
-#endif
#ifndef DISPLAY_H
#define DISPLAY_H
-#include <X11/Xlib.h>
-#include <X11/Xutil.h>
-#include <X11/Xatom.h>
-#include <X11/keysym.h>
-
#include "game_em.h"
#define ORIG_TILEX 16
#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;
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
extern void SetBitmaps_EM(Bitmap **);
extern void DrawGameDoorValues_EM(int, int, int, int);
+extern int getGameFrameDelay_EM(int);
/* ========================================================================= */
/* 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;
* graphics manipulation crap
*/
-#include <X11/Xlib.h>
-#include <X11/Xutil.h>
-
#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;
x - 2 * TILEX, y - 2 * TILEY,
SX + MAX_BUF_XSIZE * TILEX - x, SY + MAX_BUF_YSIZE * TILEY - y);
}
-
- XFlush(display);
}
{
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;
}
}
blitplayer(&ply2);
blitscreen();
- XFlush(display);
+ FlushDisplay();
}
-
-#endif
* open X11 display and sound
*/
-#include <X11/Xlib.h>
-#include <X11/Xutil.h>
-#include <X11/Xatom.h>
-#include <X11/Xos.h>
-#include <X11/Intrinsic.h>
-#include <X11/keysymdef.h>
-
-#include <X11/keysym.h>
-
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <stdio.h>
#include <signal.h>
-#include <string.h>
-#include <errno.h>
+#include <sys/wait.h>
#include "game_em.h"
#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] =
{
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;
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;
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);
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);
}
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)
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)
{
}
memset(play, 0, sizeof(play));
-}
-
#endif
+}
* handle input from x11 and keyboard and joystick
*/
-#include <X11/Xlib.h>
-#include <X11/Xutil.h>
-#include <X11/Xatom.h>
-#include <X11/keysym.h>
-#include <sys/time.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
-
#include "global.h"
#include "display.h"
#include "level.h"
-#if defined(TARGET_X11)
-
unsigned long Random;
struct PLAYER ply1;
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();
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
*
* set everything up and close everything down
*/
-
-#include <stdlib.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
-
-#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
#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 */
#include "game_em.h"
-#if defined(TARGET_X11)
+#if defined(AUDIO_UNIX_NATIVE)
#if defined(PLATFORM_LINUX) || defined(PLATFORM_BSD)
#ifdef PLATFORM_LINUX
+#include <sys/ioctl.h>
#include <sys/soundcard.h>
#endif
#ifdef PLATFORM_BSD
+#include <ioctl.h>
#include <soundcard.h>
#endif
-#include <sys/time.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/ioctl.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-
#include "global.h"
#include "sample.h"
if (i == -1)
{
- fprintf(stderr, "%s: %s: %s\n", progname, "select failed",
- strerror(errno));
+ Error(ERR_WARN, "select() failed in sound thread");
+
goto fail;
}
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;
}
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;
}
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;
}
}
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;
}
#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;
}
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;
}
}
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;
}
}
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;
}
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;
}
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;
}
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;
}
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;
}
#endif /* defined(PLATFORM_LINUX) || defined(PLATFORM_BSD) */
-#endif
+#endif /* AUDIO_UNIX_NATIVE */
#include "sample.h"
-#if defined(TARGET_X11)
-
static void player(struct PLAYER *);
static int test(struct PLAYER *);
static void die(struct PLAYER *);
}
}
}
-
-#endif
#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; }
Draw = temp;
}
}
-
-#endif
#include "sample.h"
-#if defined(TARGET_X11)
-
void synchro_3(void)
{
register unsigned int x;
for (x = 0; x < WIDTH; x++)
Next[y][x] = Cave[y][x];
}
-
-#endif
* modify.
*/
-#include <stdio.h>
#include "tile.h"
-#if defined(TARGET_X11)
-
/* ---------------------------------------------------------------------- */
/* 0=stop 1=blank */
create_obj();
create_spr();
}
-
-#endif
#include "game_em.h"
-#if defined(TARGET_X11)
-
#if defined(PLATFORM_LINUX) || defined(PLATFORM_BSD)
-#include <stdio.h>
-
int calc_ulaw_to_linear(unsigned char);
unsigned char calc_linear_to_ulaw(int);
}
#endif /* defined(PLATFORM_LINUX) || defined(PLATFORM_BSD) */
-
-#endif
#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
}
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
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);
+}