#include <signal.h>
#include "init.h"
+#include "events.h"
#include "misc.h"
#include "sound.h"
#include "screens.h"
char *picturemask_filename;
};
+#ifndef USE_SDL_LIBRARY
static int sound_process_id = 0;
+#endif
-static void InitLevelAndPlayerInfo(void);
+static void InitPlayerInfo(void);
+static void InitLevelInfo(void);
static void InitNetworkServer(void);
static void InitDisplay(void);
static void InitSound(void);
void OpenAll(int argc, char *argv[])
{
-#ifdef MSDOS
+#if defined(MSDOS) || defined(WIN32)
initErrorFile();
#endif
if (options.serveronly)
{
+#ifdef WIN32
+ Error(ERR_WARN, "networking not supported in Windows version");
+#else
NetworkServer(options.server_port, options.serveronly);
+#endif
/* never reached */
exit(0);
}
+ InitPlayerInfo();
+
InitCounter();
InitSound();
InitSoundServer();
#ifndef USE_SDL_LIBRARY
XMapWindow(display, window);
- XFlush(display);
+ FlushDisplay();
#endif
InitGfx();
InitElementProperties(); /* initializes IS_CHAR() for el2gfx() */
- InitLevelAndPlayerInfo();
- return;
+ InitLevelInfo();
InitGadgets(); /* needs to know number of level series */
DrawMainMenu();
InitNetworkServer();
}
-void InitLevelAndPlayerInfo()
+void InitPlayerInfo()
{
int i;
local_player->connected = TRUE;
- LoadLevelInfo(); /* global level info */
LoadSetup(); /* global setup info */
+}
+
+void InitLevelInfo()
+{
+ LoadLevelInfo(); /* global level info */
LoadLevelSetup_LastSeries(); /* last played series info */
LoadLevelSetup_SeriesInfo(); /* last played level info */
}
void InitNetworkServer()
{
-#ifndef MSDOS
+#if !defined(MSDOS) && !defined(WIN32)
int nr_wanted;
#endif
if (!options.network)
return;
-#ifndef MSDOS
+#if !defined(MSDOS) && !defined(WIN32)
nr_wanted = Request("Choose player", REQ_PLAYER | REQ_STAY_CLOSED);
if (!ConnectToServer(options.server_host, options.server_port))
if (sound_status == SOUND_OFF)
return;
-#ifndef MSDOS
+#ifdef USE_SDL_LIBRARY
+ /* initialize SDL audio */
+
+ if (SDL_Init(SDL_INIT_AUDIO) < 0)
+ {
+ Error(ERR_WARN, "SDL_Init() failed: %s", SDL_GetError());
+ sound_status = SOUND_OFF;
+ return;
+ }
+
+ if (Mix_OpenAudio(22050, AUDIO_S16, 2, 512) < 0)
+ {
+ Error(ERR_WARN, "Mix_OpenAudio() failed: %s", SDL_GetError());
+ sound_status = SOUND_OFF;
+ return;
+ }
+
+ Mix_Volume(-1, SDL_MIX_MAXVOLUME / 4);
+ Mix_VolumeMusic(SDL_MIX_MAXVOLUME / 4);
+
+ sound_status = SOUND_AVAILABLE;
+ sound_loops_allowed = TRUE;
+
+#else /* !USE_SDL_LIBRARY */
+
+#if !defined(MSDOS) && !defined(WIN32)
if (access(sound_device_name, W_OK) != 0)
{
Error(ERR_WARN, "cannot access sound device - no sounds");
*/
#endif
-#else /* MSDOS */
+#else /* MSDOS || WIN32 */
sound_loops_allowed = TRUE;
/*
setup.sound_loops_on = TRUE;
*/
-#endif /* MSDOS */
+#endif /* MSDOS || WIN32 */
+#endif /* !USE_SDL_LIBRARY */
for(i=0; i<NUM_SOUNDS; i++)
{
-#ifdef MSDOS
- sprintf(sound_name[i], "%d", i + 1);
-#endif
-
Sound[i].name = sound_name[i];
+
if (!LoadSound(&Sound[i]))
{
sound_status = SOUND_OFF;
+ sound_loops_allowed = FALSE;
return;
}
}
+
+#if 0
+ sound_status = SOUND_OFF;
+#endif
+
}
void InitSoundServer()
if (sound_status == SOUND_OFF)
return;
-#ifndef MSDOS
+#ifndef USE_SDL_LIBRARY
+
+#if !defined(MSDOS) && !defined(WIN32)
if (pipe(sound_pipe)<0)
{
else /* we are parent */
close(sound_pipe[0]); /* no reading from pipe needed */
-#else /* MSDOS */
+#else /* MSDOS || WIN32 */
SoundServer();
#endif /* MSDOS */
+
+#endif /* !USE_SDL_LIBRARY */
}
void InitJoysticks()
{
+#ifdef USE_SDL_JOYSTICK
+ static boolean sdl_joystick_subsystem_initialized = FALSE;
+#endif
+
int i;
if (global_joystick_status == JOYSTICK_OFF)
joystick_status = JOYSTICK_OFF;
+#ifdef USE_SDL_JOYSTICK
+
+ if (!sdl_joystick_subsystem_initialized)
+ {
+ sdl_joystick_subsystem_initialized = TRUE;
+
+ if (SDL_Init(SDL_INIT_JOYSTICK) < 0)
+ {
+ Error(ERR_EXIT, "SDL_Init() failed: %s", SDL_GetError());
+ return;
+ }
+ }
+
+ for (i=0; i<MAX_PLAYERS; i++)
+ {
+ char *device_name = setup.input[i].joy.device_name;
+ int joystick_nr = getJoystickNrFromDeviceName(device_name);
+
+ if (joystick_nr >= SDL_NumJoysticks())
+ joystick_nr = -1;
+
+ /* misuse joystick file descriptor variable to store joystick number */
+ stored_player[i].joystick_fd = joystick_nr;
+
+ /* this allows subsequent calls to 'InitJoysticks' for re-initialization */
+ if (Check_SDL_JoystickOpened(joystick_nr))
+ Close_SDL_Joystick(joystick_nr);
+
+ if (!setup.input[i].use_joystick)
+ continue;
+
+ if (!Open_SDL_Joystick(joystick_nr))
+ {
+ Error(ERR_WARN, "cannot open joystick %d", joystick_nr);
+ continue;
+ }
+
+ joystick_status = JOYSTICK_AVAILABLE;
+ }
+
+#else /* !USE_SDL_JOYSTICK */
+
#ifndef MSDOS
for (i=0; i<MAX_PLAYERS; i++)
{
stored_player[i].joystick_fd = joystick_nr;
}
#endif
+
+#endif /* !USE_SDL_LIBRARY */
}
void InitDisplay()
{
#ifdef USE_SDL_LIBRARY
- /* initialize SDL */
+ /* initialize SDL video */
if (SDL_Init(SDL_INIT_VIDEO) < 0)
- Error(ERR_EXIT, "SDL_Init() failed: %s\n", SDL_GetError());
+ Error(ERR_EXIT, "SDL_Init() failed: %s", SDL_GetError());
/* automatically cleanup SDL stuff after exit() */
atexit(SDL_Quit);
{
#ifdef USE_SDL_LIBRARY
/* open SDL video output device (window or fullscreen mode) */
- if ((sdl_window = SDL_SetVideoMode(WIN_XSIZE, WIN_YSIZE, WIN_SDL_DEPTH,
- SDL_HWSURFACE))
+#if 0
+ if ((window = SDL_SetVideoMode(WIN_XSIZE, WIN_YSIZE, WIN_SDL_DEPTH,
+ SDL_HWSURFACE))
== NULL)
- Error(ERR_EXIT, "SDL_SetVideoMode() failed: %s\n", SDL_GetError());
+ Error(ERR_EXIT, "SDL_SetVideoMode() failed: %s", SDL_GetError());
+#else
+ if (!SetVideoMode())
+ Error(ERR_EXIT, "setting video mode failed");
+#endif
/* set window and icon title */
SDL_WM_SetCaption(WINDOW_TITLE_STRING, WINDOW_TITLE_STRING);
- /* select event types: initially no mouse motion events */
- SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE);
+ /* set event filter to filter out certain mouse motion events */
+ SDL_SetEventFilter(EventFilter);
#else /* !USE_SDL_LIBRARY */
XSelectInput(display, window, window_event_mask);
#endif
- /* create GC for drawing with window depth */
+ /* create GC for drawing with window depth and background color (black) */
gc_values.graphics_exposures = False;
gc_values.foreground = pen_bg;
gc_values.background = pen_bg;
#endif
#endif
- LoadGfx(PIX_SMALLFONT,&pic[PIX_SMALLFONT]);
- DrawInitText(WINDOW_TITLE_STRING,20,FC_YELLOW);
- DrawInitText(COPYRIGHT_STRING,50,FC_RED);
+ LoadGfx(PIX_SMALLFONT, &pic[PIX_SMALLFONT]);
+ DrawInitText(WINDOW_TITLE_STRING, 20, FC_YELLOW);
+ DrawInitText(WINDOW_SUBTITLE_STRING, 50, FC_RED);
#ifdef MSDOS
- DrawInitText("MSDOS version done by Guido Schulz",210,FC_BLUE);
+ DrawInitText(PROGRAM_DOS_PORT_STRING, 210, FC_BLUE);
rest(200);
#endif /* MSDOS */
DrawInitText("Loading graphics:",120,FC_GREEN);
WIN_XSIZE, WIN_YSIZE,
WIN_SDL_DEPTH, 0, 0, 0, 0))
== NULL)
- Error(ERR_EXIT, "SDL_CreateRGBSurface() failed: %s\n", SDL_GetError());
+ Error(ERR_EXIT, "SDL_CreateRGBSurface() failed: %s", SDL_GetError());
- if ((sdl_pix[PIX_DB_BACK] = SDL_DisplayFormat(sdl_image_tmp)) == NULL)
- Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s\n", SDL_GetError());
+ if ((pix[PIX_DB_BACK] = SDL_DisplayFormat(sdl_image_tmp)) == NULL)
+ Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s", SDL_GetError());
SDL_FreeSurface(sdl_image_tmp);
3 * DXSIZE, DYSIZE + VYSIZE,
WIN_SDL_DEPTH, 0, 0, 0, 0))
== NULL)
- Error(ERR_EXIT, "SDL_CreateRGBSurface() failed: %s\n", SDL_GetError());
+ Error(ERR_EXIT, "SDL_CreateRGBSurface() failed: %s", SDL_GetError());
- if ((sdl_pix[PIX_DB_DOOR] = SDL_DisplayFormat(sdl_image_tmp)) == NULL)
- Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s\n", SDL_GetError());
+ if ((pix[PIX_DB_DOOR] = SDL_DisplayFormat(sdl_image_tmp)) == NULL)
+ Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s", SDL_GetError());
SDL_FreeSurface(sdl_image_tmp);
FXSIZE, FYSIZE,
WIN_SDL_DEPTH, 0, 0, 0, 0))
== NULL)
- Error(ERR_EXIT, "SDL_CreateRGBSurface() failed: %s\n", SDL_GetError());
+ Error(ERR_EXIT, "SDL_CreateRGBSurface() failed: %s", SDL_GetError());
- if ((sdl_pix[PIX_DB_FIELD] = SDL_DisplayFormat(sdl_image_tmp)) == NULL)
- Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s\n", SDL_GetError());
+ if ((pix[PIX_DB_FIELD] = SDL_DisplayFormat(sdl_image_tmp)) == NULL)
+ Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s", SDL_GetError());
SDL_FreeSurface(sdl_image_tmp);
/* initialize surface array to 'NULL' */
for(i=0; i<NUM_TILES; i++)
- sdl_tile_masked[i] = NULL;
+ tile_masked[i] = NULL;
/* create only those masked surfaces we really need */
for(i=0; tile_needs_clipping[i].start>=0; i++)
for(j=0; j<tile_needs_clipping[i].count; j++)
{
int tile = tile_needs_clipping[i].start + j;
-#if 0
int graphic = tile;
int src_x, src_y;
- int pixmap_nr;
- Pixmap src_pixmap;
+ int bitmap_nr;
+ Bitmap src_bitmap;
- getGraphicSource(graphic, &pixmap_nr, &src_x, &src_y);
- src_pixmap = clipmask[pixmap_nr];
+ getGraphicSource(graphic, &bitmap_nr, &src_x, &src_y);
+ src_bitmap = pix_masked[bitmap_nr];
- tile_clipmask[tile] = XCreatePixmap(display, window, TILEX,TILEY, 1);
+ /* create surface for masked tile graphic */
+ if ((sdl_image_tmp = SDL_CreateRGBSurface(SDL_SWSURFACE, TILEX, TILEY,
+ WIN_SDL_DEPTH, 0, 0, 0, 0))
+ == NULL)
+ Error(ERR_EXIT, "SDL_CreateRGBSurface() failed: %s", SDL_GetError());
- XCopyArea(display,src_pixmap,tile_clipmask[tile],copy_clipmask_gc,
- src_x,src_y, TILEX,TILEY, 0,0);
-#endif
- }
- }
+ /* create native transparent surface for current image */
+ SDL_SetColorKey(sdl_image_tmp, SDL_SRCCOLORKEY,
+ SDL_MapRGB(sdl_image_tmp->format, 0x00, 0x00, 0x00));
+ if ((tile_masked[tile] = SDL_DisplayFormat(sdl_image_tmp)) == NULL)
+ Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s", SDL_GetError());
- sdl_drawto = sdl_backbuffer = sdl_pix[PIX_DB_BACK];
- sdl_fieldbuffer = sdl_pix[PIX_DB_FIELD];
- SetDrawtoField(DRAW_BACKBUFFER);
+ SDL_FreeSurface(sdl_image_tmp);
- SDLCopyArea(sdl_pix[PIX_BACK], sdl_backbuffer,
- 0,0, WIN_XSIZE,WIN_YSIZE, 0,0);
- SDLFillRectangle(sdl_pix[PIX_DB_BACK],
- REAL_SX,REAL_SY, FULL_SXSIZE,FULL_SYSIZE, 0x000000);
- SDLFillRectangle(sdl_pix[PIX_DB_DOOR],
- 0,0, 3*DXSIZE,DYSIZE+VYSIZE, 0x000000);
+ BlitBitmap(src_bitmap, tile_masked[tile], src_x,src_y, TILEX,TILEY, 0,0);
+ }
+ }
#else /* !USE_SDL_LIBRARY */
if (!pix[PIX_DB_BACK] || !pix[PIX_DB_DOOR])
Error(ERR_EXIT, "cannot create additional pixmaps");
- for(i=0; i<NUM_PIXMAPS; i++)
+ for(i=0; i<NUM_BITMAPS; i++)
{
if (clipmask[i])
{
}
}
+#endif /* !USE_SDL_LIBRARY */
+
drawto = backbuffer = pix[PIX_DB_BACK];
fieldbuffer = pix[PIX_DB_FIELD];
SetDrawtoField(DRAW_BACKBUFFER);
- XCopyArea(display, pix[PIX_BACK], backbuffer, gc,
- 0,0, WIN_XSIZE,WIN_YSIZE, 0,0);
- XFillRectangle(display, pix[PIX_DB_BACK], gc,
- REAL_SX,REAL_SY, FULL_SXSIZE,FULL_SYSIZE);
- XFillRectangle(display, pix[PIX_DB_DOOR], gc,
- 0,0, 3*DXSIZE,DYSIZE+VYSIZE);
-#endif /* !USE_SDL_LIBRARY */
+ BlitBitmap(pix[PIX_BACK], backbuffer, 0,0, WIN_XSIZE,WIN_YSIZE, 0,0);
+ ClearRectangle(pix[PIX_DB_BACK], REAL_SX,REAL_SY, FULL_SXSIZE,FULL_SYSIZE);
+ ClearRectangle(pix[PIX_DB_DOOR], 0,0, 3*DXSIZE,DYSIZE+VYSIZE);
for(i=0; i<MAX_BUF_XSIZE; i++)
for(j=0; j<MAX_BUF_YSIZE; j++)
#ifdef USE_SDL_LIBRARY
/* load image to temporary surface */
if ((sdl_image_tmp = IMG_Load(filename)) == NULL)
- Error(ERR_EXIT, "IMG_Load() failed: %s\n", SDL_GetError());
+ Error(ERR_EXIT, "IMG_Load() failed: %s", SDL_GetError());
/* create native non-transparent surface for current image */
- if ((sdl_pix[pos] = SDL_DisplayFormat(sdl_image_tmp)) == NULL)
- Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s\n", SDL_GetError());
+ if ((pix[pos] = SDL_DisplayFormat(sdl_image_tmp)) == NULL)
+ Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s", SDL_GetError());
/* create native transparent surface for current image */
SDL_SetColorKey(sdl_image_tmp, SDL_SRCCOLORKEY,
SDL_MapRGB(sdl_image_tmp->format, 0x00, 0x00, 0x00));
- if ((sdl_pix_masked[pos] = SDL_DisplayFormat(sdl_image_tmp)) == NULL)
- Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s\n", SDL_GetError());
+ if ((pix_masked[pos] = SDL_DisplayFormat(sdl_image_tmp)) == NULL)
+ Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s", SDL_GetError());
/* free temporary surface */
SDL_FreeSurface(sdl_image_tmp);
if (!pix[pos])
Error(ERR_EXIT, "cannot get graphics for '%s'", pic->picture_filename);
+
+ /* setting pix_masked[] to pix[] allows BlitBitmapMasked() to always
+ use pix_masked[], although they are the same when not using SDL */
+ pix_masked[pos] = pix[pos];
+
#endif /* !USE_SDL_LIBRARY */
}
for(j=0; j<*(ep2_num[i]); j++)
Elementeigenschaften2[(ep2_array[i])[j]] |= ep2_bit[i];
- for(i=EL_CHAR_START; i<EL_CHAR_END; i++)
+ for(i=EL_CHAR_START; i<=EL_CHAR_END; i++)
Elementeigenschaften1[i] |= (EP_BIT_CHAR | EP_BIT_INACTIVE);
}
{
int i;
+#ifdef USE_SDL_LIBRARY
+ StopSounds();
+ FreeSounds(NUM_SOUNDS);
+#else
if (sound_process_id)
{
StopSounds();
kill(sound_process_id, SIGTERM);
FreeSounds(NUM_SOUNDS);
}
+#endif
- for(i=0; i<NUM_PIXMAPS; i++)
+ for(i=0; i<NUM_BITMAPS; i++)
{
if (pix[i])
{
XpmFreeAttributes(&xpm_att[i]);
}
#endif
+
+#ifdef USE_SDL_LIBRARY
+ SDL_FreeSurface(pix[i]);
+#else
XFreePixmap(display,pix[i]);
+#endif
}
+
+#ifdef USE_SDL_LIBRARY
+ SDL_FreeSurface(pix_masked[i]);
+#else
if (clipmask[i])
XFreePixmap(display,clipmask[i]);
if (clip_gc[i])
XFreeGC(display, clip_gc[i]);
+#endif
}
+#ifdef USE_SDL_LIBRARY
+ KeyboardAutoRepeatOn();
+#else
if (gc)
XFreeGC(display, gc);
if (display)
{
- XAutoRepeatOn(display);
+ KeyboardAutoRepeatOn();
XCloseDisplay(display);
}
+#endif
-#ifdef MSDOS
+#if defined(MSDOS) || defined(WIN32)
dumpErrorFile();
#endif