#include "files.h"
#include "network.h"
#include "netserv.h"
+#include "cartoons.h"
+#include "config.h"
+static char *image_filename[NUM_PICTURES] =
+{
+ "RocksScreen.pcx",
+ "RocksDoor.pcx",
+ "RocksHeroes.pcx",
+ "RocksToons.pcx",
+ "RocksSP.pcx",
+ "RocksDC.pcx",
+ "RocksMore.pcx",
+ "RocksFont.pcx",
+ "RocksFont2.pcx",
+ "RocksFont3.pcx"
+};
+
+static void InitSetup(void);
static void InitPlayerInfo(void);
static void InitLevelInfo(void);
+static void InitArtworkInfo(void);
+static void InitLevelArtworkInfo(void);
static void InitNetworkServer(void);
+static void InitMixer(void);
static void InitSound(void);
static void InitGfx(void);
static void InitGfxBackground(void);
static void InitGadgets(void);
static void InitElementProperties(void);
+static void Execute_Debug_Command(char *);
void OpenAll(void)
{
+ if (options.debug_command)
+ {
+ Execute_Debug_Command(options.debug_command);
+
+ exit(0);
+ }
+
if (options.serveronly)
{
#if defined(PLATFORM_UNIX)
}
InitProgramInfo(UNIX_USERDATA_DIRECTORY,
- PROGRAM_TITLE_STRING, WINDOW_TITLE_STRING,
+ PROGRAM_TITLE_STRING, getWindowTitleString(),
ICON_TITLE_STRING, X11_ICON_FILENAME, X11_ICONMASK_FILENAME,
- MSDOS_POINTER_FILENAME);
+ MSDOS_POINTER_FILENAME,
+ COOKIE_PREFIX, FILENAME_PREFIX, GAME_VERSION_ACTUAL);
+ InitSetup();
InitPlayerInfo();
+ InitArtworkInfo(); /* needed before loading gfx, sound & music */
InitCounter();
- InitSound();
+ InitMixer();
InitJoysticks();
InitRND(NEW_RANDOMIZE);
InitElementProperties(); /* initializes IS_CHAR() for el2gfx() */
InitLevelInfo();
+ InitLevelArtworkInfo();
InitGadgets(); /* needs to know number of level series */
+ InitSound(); /* needs to know current level directory */
InitGfxBackground();
+ InitToons();
+
+ InitGameEngine();
+
DrawMainMenu();
InitNetworkServer();
}
+void InitSetup()
+{
+ LoadSetup(); /* global setup info */
+}
+
void InitPlayerInfo()
{
int i;
stored_player[i].connected = FALSE;
local_player->connected = TRUE;
-
- LoadSetup(); /* global setup info */
}
void InitLevelInfo()
LoadLevelSetup_SeriesInfo(); /* last played level info */
}
+void InitArtworkInfo()
+{
+ LoadArtworkInfo();
+}
+
+void InitLevelArtworkInfo()
+{
+ LoadLevelArtworkInfo();
+}
+
void InitNetworkServer()
{
#if defined(PLATFORM_UNIX)
#endif
}
-void InitSound()
+static void InitMixer()
{
- int i;
-
OpenAudio();
+ InitSoundList(sound_effects, NUM_SOUND_EFFECTS);
- for(i=0; i<NUM_SOUNDS; i++)
- {
- if (!LoadSound(sound_name[i]))
- {
- audio.sound_available = FALSE;
- audio.loops_available = FALSE;
- audio.sound_enabled = FALSE;
-
- return;
- }
- }
-
- num_bg_loops = LoadMusic();
-
- StartSoundserver();
+ StartMixer();
}
-void InitJoysticks()
+static void InitSound()
{
-#if defined(TARGET_SDL)
- static boolean sdl_joystick_subsystem_initialized = FALSE;
-#endif
-
- int i;
-
- /* always start with reliable default values */
- joystick.status = JOYSTICK_NOT_AVAILABLE;
- for (i=0; i<MAX_PLAYERS; i++)
- joystick.fd[i] = -1; /* joystick device closed */
-
- if (global_joystick_status == JOYSTICK_NOT_AVAILABLE)
- return;
-
-#if defined(TARGET_SDL)
-
- 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 */
- joystick.fd[i] = 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_ACTIVATED;
- }
-
-#else /* !TARGET_SDL */
-
-#if defined(PLATFORM_UNIX)
- for (i=0; i<MAX_PLAYERS; i++)
- {
- char *device_name = setup.input[i].joy.device_name;
-
- /* this allows subsequent calls to 'InitJoysticks' for re-initialization */
- if (joystick.fd[i] != -1)
- {
- close(joystick.fd[i]);
- joystick.fd[i] = -1;
- }
-
- if (!setup.input[i].use_joystick)
- continue;
-
- if (access(device_name, R_OK) != 0)
- {
- Error(ERR_WARN, "cannot access joystick device '%s'", device_name);
- continue;
- }
-
- if ((joystick.fd[i] = open(device_name, O_RDONLY)) < 0)
- {
- Error(ERR_WARN, "cannot open joystick device '%s'", device_name);
- continue;
- }
-
- joystick.status = JOYSTICK_ACTIVATED;
- }
-
-#else /* !PLATFORM_UNIX */
-
- /* try to access two joysticks; if that fails, try to access just one */
- if (install_joystick(JOY_TYPE_2PADS) == 0 ||
- install_joystick(JOY_TYPE_AUTODETECT) == 0)
- joystick.status = JOYSTICK_ACTIVATED;
-
- /*
- load_joystick_data(JOYSTICK_FILENAME);
- */
-
- 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 >= num_joysticks)
- joystick_nr = -1;
-
- /* misuse joystick file descriptor variable to store joystick number */
- joystick.fd[i] = joystick_nr;
- }
-#endif
-
-#endif /* !TARGET_SDL */
+ InitReloadSounds(artwork.snd_current->name);
+ InitReloadMusic(artwork.mus_current->name);
}
-void InitGfx()
+static void InitTileClipmasks()
{
- int i;
-
#if defined(TARGET_X11)
- GC copy_clipmask_gc;
XGCValues clip_gc_values;
unsigned long clip_gc_valuemask;
-#endif
-
-#if !defined(PLATFORM_MSDOS)
- static char *image_filename[NUM_PICTURES] =
- {
- "RocksScreen.pcx",
- "RocksDoor.pcx",
- "RocksHeroes.pcx",
- "RocksToons.pcx",
- "RocksSP.pcx",
- "RocksDC.pcx",
- "RocksMore.pcx",
- "RocksFont.pcx",
- "RocksFont2.pcx",
- "RocksFont3.pcx"
- };
-#else
- static char *image_filename[NUM_PICTURES] =
- {
- "Screen.pcx",
- "Door.pcx",
- "Heroes.pcx",
- "Toons.pcx",
- "SP.pcx",
- "DC.pcx",
- "More.pcx",
- "Font.pcx",
- "Font2.pcx",
- "Font3.pcx"
- };
-#endif
#if defined(TARGET_X11_NATIVE)
+ GC copy_clipmask_gc;
+
static struct
{
int start;
{ GFX2_SHIELD_ACTIVE, 3 },
{ -1, 0 }
};
-#endif
-
- /* initialize some global variables */
- global.frames_per_second = 0;
- global.fps_slowdown = FALSE;
- global.fps_slowdown_factor = 1;
-
- /* initialize screen properties */
- InitGfxFieldInfo(SX, SY, SXSIZE, SYSIZE,
- REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE);
- InitGfxDoor1Info(DX, DY, DXSIZE, DYSIZE);
- InitGfxDoor2Info(VX, VY, VXSIZE, VYSIZE);
- InitGfxScrollbufferInfo(FXSIZE, FYSIZE);
-
- /* create additional image buffers for double-buffering */
- pix[PIX_DB_DOOR] = CreateBitmap(3 * DXSIZE, DYSIZE + VYSIZE, DEFAULT_DEPTH);
- pix[PIX_DB_FIELD] = CreateBitmap(FXSIZE, FYSIZE, DEFAULT_DEPTH);
-
- pix[PIX_SMALLFONT] = LoadImage(image_filename[PIX_SMALLFONT]);
- InitFontInfo(NULL, NULL, pix[PIX_SMALLFONT]);
-
- DrawInitText(WINDOW_TITLE_STRING, 20, FC_YELLOW);
- DrawInitText(WINDOW_SUBTITLE_STRING, 50, FC_RED);
-#if defined(PLATFORM_MSDOS)
- DrawInitText(PROGRAM_DOS_PORT_STRING, 210, FC_BLUE);
- rest(200);
-#endif
- DrawInitText("Loading graphics:",120,FC_GREEN);
-
- for(i=0; i<NUM_PICTURES; i++)
- {
- if (i != PIX_SMALLFONT)
- {
- DrawInitText(image_filename[i], 150, FC_YELLOW);
- pix[i] = LoadImage(image_filename[i]);
- }
- }
+#endif /* TARGET_X11_NATIVE */
+#endif /* TARGET_X11 */
- InitFontInfo(pix[PIX_BIGFONT], pix[PIX_MEDIUMFONT], pix[PIX_SMALLFONT]);
+ int i;
/* initialize pixmap array for special X11 tile clipping to Pixmap 'None' */
for(i=0; i<NUM_TILES; i++)
To prevent this, create small (tile-sized) mask Pixmaps which will then
be set much faster with XSetClipOrigin() and speed things up a lot. */
- /* create graphic context structures needed for clipping */
- clip_gc_values.graphics_exposures = False;
- clip_gc_valuemask = GCGraphicsExposures;
- copy_clipmask_gc =
- XCreateGC(display, pix[PIX_BACK]->clip_mask,
- clip_gc_valuemask, &clip_gc_values);
-
clip_gc_values.graphics_exposures = False;
clip_gc_valuemask = GCGraphicsExposures;
tile_clip_gc =
clip_gc_values.clip_mask = pix[i]->clip_mask;
clip_gc_valuemask = GCGraphicsExposures | GCClipMask;
pix[i]->stored_clip_gc = XCreateGC(display, window->drawable,
- clip_gc_valuemask,&clip_gc_values);
+ clip_gc_valuemask, &clip_gc_values);
}
}
#if defined(TARGET_X11_NATIVE)
+
+ /* create graphic context structures needed for clipping */
+ clip_gc_values.graphics_exposures = False;
+ clip_gc_valuemask = GCGraphicsExposures;
+ copy_clipmask_gc =
+ XCreateGC(display, pix[PIX_BACK]->clip_mask,
+ clip_gc_valuemask, &clip_gc_values);
+
/* create only those clipping Pixmaps we really need */
for(i=0; tile_needs_clipping[i].start>=0; i++)
{
src_x, src_y, TILEX, TILEY, 0, 0);
}
}
+
+ XFreeGC(display, copy_clipmask_gc);
+
#endif /* TARGET_X11_NATIVE */
#endif /* TARGET_X11 */
}
+void FreeTileClipmasks()
+{
+#if defined(TARGET_X11)
+ int i;
+
+ for(i=0; i<NUM_TILES; i++)
+ {
+ if (tile_clipmask[i] != None)
+ {
+ XFreePixmap(display, tile_clipmask[i]);
+ tile_clipmask[i] = None;
+ }
+ }
+
+ if (tile_clip_gc)
+ XFreeGC(display, tile_clip_gc);
+ tile_clip_gc = None;
+
+ for(i=0; i<NUM_BITMAPS; i++)
+ {
+ if (pix[i] != NULL && pix[i]->stored_clip_gc)
+ {
+ XFreeGC(display, pix[i]->stored_clip_gc);
+ pix[i]->stored_clip_gc = None;
+ }
+ }
+#endif /* TARGET_X11 */
+}
+
+void InitGfx()
+{
+ int i;
+
+ /* initialize some global variables */
+ global.frames_per_second = 0;
+ global.fps_slowdown = FALSE;
+ global.fps_slowdown_factor = 1;
+
+ /* initialize screen properties */
+ InitGfxFieldInfo(SX, SY, SXSIZE, SYSIZE,
+ REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE);
+ InitGfxDoor1Info(DX, DY, DXSIZE, DYSIZE);
+ InitGfxDoor2Info(VX, VY, VXSIZE, VYSIZE);
+ InitGfxScrollbufferInfo(FXSIZE, FYSIZE);
+
+ /* create additional image buffers for double-buffering */
+ pix[PIX_DB_DOOR] = CreateBitmap(3 * DXSIZE, DYSIZE + VYSIZE, DEFAULT_DEPTH);
+ pix[PIX_DB_FIELD] = CreateBitmap(FXSIZE, FYSIZE, DEFAULT_DEPTH);
+
+ pix[PIX_SMALLFONT] = LoadCustomImage(image_filename[PIX_SMALLFONT]);
+
+ InitFontInfo(NULL, NULL, pix[PIX_SMALLFONT]);
+
+ DrawInitText(WINDOW_TITLE_STRING, 20, FC_YELLOW);
+ DrawInitText(WINDOW_SUBTITLE_STRING, 50, FC_RED);
+
+ DrawInitText("Loading graphics:", 120, FC_GREEN);
+
+ for(i=0; i<NUM_PICTURES; i++)
+ {
+ if (i != PIX_SMALLFONT)
+ {
+ DrawInitText(image_filename[i], 150, FC_YELLOW);
+
+ pix[i] = LoadCustomImage(image_filename[i]);
+ }
+ }
+
+ InitFontInfo(pix[PIX_BIGFONT], pix[PIX_MEDIUMFONT], pix[PIX_SMALLFONT]);
+
+ InitTileClipmasks();
+}
+
void InitGfxBackground()
{
int x, y;
fieldbuffer = pix[PIX_DB_FIELD];
SetDrawtoField(DRAW_BACKBUFFER);
- BlitBitmap(pix[PIX_BACK], backbuffer, 0,0, WIN_XSIZE,WIN_YSIZE, 0,0);
- ClearRectangle(backbuffer, REAL_SX,REAL_SY, FULL_SXSIZE,FULL_SYSIZE);
- ClearRectangle(pix[PIX_DB_DOOR], 0,0, 3*DXSIZE,DYSIZE+VYSIZE);
+ BlitBitmap(pix[PIX_BACK], backbuffer, 0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0);
+ ClearRectangle(backbuffer, REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE);
+ ClearRectangle(pix[PIX_DB_DOOR], 0, 0, 3 * DXSIZE, DYSIZE + VYSIZE);
for(x=0; x<MAX_BUF_XSIZE; x++)
for(y=0; y<MAX_BUF_YSIZE; y++)
redraw_mask = REDRAW_ALL;
}
+void ReloadCustomArtwork()
+{
+ static char *leveldir_current_name = NULL;
+ static boolean last_override_level_graphics = FALSE;
+ static boolean last_override_level_sounds = FALSE;
+ static boolean last_override_level_music = FALSE;
+
+ if (leveldir_current_name != leveldir_current->name)
+ {
+ /* force reload of custom artwork after new level series was selected */
+ artwork.graphics_set_current_name = NULL;
+ artwork.sounds_set_current_name = NULL;
+ artwork.music_set_current_name = NULL;
+
+ leveldir_current_name = leveldir_current->name;
+ }
+
+ if (artwork.graphics_set_current_name != artwork.gfx_current->name ||
+ last_override_level_graphics != setup.override_level_graphics)
+ {
+ int i;
+
+ ClearRectangle(window, 0, 0, WIN_XSIZE, WIN_YSIZE);
+
+ for(i=0; i<NUM_PICTURES; i++)
+ {
+ DrawInitText(image_filename[i], 150, FC_YELLOW);
+ ReloadCustomImage(pix[i], image_filename[i]);
+ }
+
+ FreeTileClipmasks();
+ InitTileClipmasks();
+ InitGfxBackground();
+
+ SetDoorState(DOOR_OPEN_1 | DOOR_CLOSE_2);
+
+ artwork.graphics_set_current_name = artwork.gfx_current->name;
+ last_override_level_graphics = setup.override_level_graphics;
+ }
+
+ if (artwork.sounds_set_current_name != artwork.snd_current->name ||
+ last_override_level_sounds != setup.override_level_sounds)
+ {
+ InitReloadSounds(artwork.snd_current->name);
+
+ artwork.sounds_set_current_name = artwork.snd_current->name;
+ last_override_level_sounds = setup.override_level_sounds;
+ }
+
+ if (artwork.music_set_current_name != artwork.mus_current->name ||
+ last_override_level_music != setup.override_level_music)
+ {
+ InitReloadMusic(artwork.mus_current->name);
+
+ artwork.music_set_current_name = artwork.mus_current->name;
+ last_override_level_music = setup.override_level_music;
+ }
+}
+
void InitGadgets()
{
CreateLevelEditorGadgets();
Elementeigenschaften1[i] |= (EP_BIT_CHAR | EP_BIT_INACTIVE);
}
+void Execute_Debug_Command(char *command)
+{
+ if (strcmp(command, "create soundinfo.conf") == 0)
+ {
+ int i;
+
+ printf("# You can configure additional/alternative sound effects here\n");
+ printf("# (The sounds below are default and therefore commented out.)\n");
+ printf("\n");
+
+ for (i=0; i<NUM_SOUND_EFFECTS; i++)
+ printf("# %s\n",
+ getFormattedSetupEntry(sound_effects[i].text,
+ sound_effects[i].default_filename));
+ }
+}
+
void CloseAllAndExit(int exit_value)
{
int i;
StopSounds();
- FreeSounds(NUM_SOUNDS);
- CloseAudio();
+ FreeAllSounds();
+ FreeAllMusic();
+ CloseAudio(); /* called after freeing sounds (needed for SDL) */
+ FreeTileClipmasks();
for(i=0; i<NUM_BITMAPS; i++)
FreeBitmap(pix[i]);
- CloseVideoDisplay();
+ CloseVideoDisplay();
ClosePlatformDependantStuff();
exit(exit_value);