X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Finit.c;h=17a1cbdbf3d4a2224e0886cbfd72c2c40e06bbd7;hb=7b47ce7ba0f673f0de5130daf5726104d0b38902;hp=8e60cfeb3a94b6778d5fa9bc79b922ce8eceb57e;hpb=49dab46aa55cb43233c7f9a310593f8bd8debc29;p=rocksndiamonds.git diff --git a/src/init.c b/src/init.c index 8e60cfeb..2b7836e2 100644 --- a/src/init.c +++ b/src/init.c @@ -1,96 +1,163 @@ /*********************************************************** -* Rocks'n'Diamonds -- McDuffin Strikes Back! * +* Rocks'n'Diamonds -- McDuffin Strikes Back! * *----------------------------------------------------------* -* (c) 1995-98 Artsoft Entertainment * -* Holger Schemel * -* Oststrasse 11a * -* 33604 Bielefeld * -* phone: ++49 +521 290471 * -* email: aeglos@valinor.owl.de * +* (c) 1995-2002 Artsoft Entertainment * +* Holger Schemel * +* Detmolder Strasse 189 * +* 33604 Bielefeld * +* Germany * +* e-mail: info@artsoft.org * *----------------------------------------------------------* -* init.c * +* init.c * ***********************************************************/ -#include +#include "libgame/libgame.h" #include "init.h" -#include "misc.h" -#include "sound.h" +#include "events.h" #include "screens.h" +#include "editor.h" +#include "game.h" +#include "tape.h" #include "tools.h" #include "files.h" -#include "joystick.h" -#include "gfxload.h" -#include "gifload.h" #include "network.h" #include "netserv.h" +#include "cartoons.h" +#include "config.h" -#ifdef DEBUG -/* -#define DEBUG_TIMING -*/ -#endif +#include "conf_e2g.c" /* include auto-generated data structure definitions */ -struct PictureFileInfo -{ - char *picture_filename; - boolean picture_with_mask; -}; -struct IconFileInfo +static char *image_filename[NUM_PICTURES] = { - char *picture_filename; - char *picturemask_filename; -}; +#if 0 + "RocksScreen.pcx", + "RocksDoor.pcx", + "RocksToons.pcx", + "RocksFontBig.pcx", + "RocksFontSmall.pcx", + "RocksFontMedium.pcx", + "RocksFontEM.pcx" +#else + "RocksScreen.pcx", + "RocksElements.pcx", + "RocksDoor.pcx", + "RocksHeroes.pcx", + "RocksToons.pcx", + "RocksSP.pcx", + "RocksDC.pcx", + "RocksMore.pcx", + "RocksFontBig.pcx", + "RocksFontSmall.pcx", + "RocksFontMedium.pcx", + "RocksFontEM.pcx" +#endif +}; -static int sound_process_id = 0; +static Bitmap *bitmap_font_initial = NULL; -static void InitLevelAndPlayerInfo(void); +static void InitGlobal(void); +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 InitDisplay(void); +static void InitArtworkConfig(void); +static void InitImages(void); +static void InitMixer(void); static void InitSound(void); -static void InitSoundServer(void); -static void InitWindow(int, char **); +static void InitMusic(void); static void InitGfx(void); -static void LoadGfx(int, struct PictureFileInfo *); +static void InitGfxBackground(void); +static void InitGadgets(void); static void InitElementProperties(void); +static void InitElementInfo(void); +static void InitGraphicInfo(void); +static void InitSoundInfo(); +static void Execute_Command(char *); -void OpenAll(int argc, char *argv[]) +void OpenAll(void) { + InitGlobal(); /* initialize some global variables */ + + if (options.execute_command) + Execute_Command(options.execute_command); + if (options.serveronly) { +#if defined(PLATFORM_UNIX) NetworkServer(options.server_port, options.serveronly); - - /* never reached */ - exit(0); +#else + Error(ERR_WARN, "networking only supported in Unix version"); +#endif + exit(0); /* never reached */ } - InitLevelAndPlayerInfo(); + InitProgramInfo(UNIX_USERDATA_DIRECTORY, + PROGRAM_TITLE_STRING, getWindowTitleString(), + ICON_TITLE_STRING, X11_ICON_FILENAME, X11_ICONMASK_FILENAME, + MSDOS_POINTER_FILENAME, + COOKIE_PREFIX, FILENAME_PREFIX, GAME_VERSION_ACTUAL); + + InitSetup(); + InitPlayerInfo(); + InitArtworkInfo(); /* needed before loading gfx, sound & music */ + InitArtworkConfig(); /* needed before forking sound child process */ + InitMixer(); InitCounter(); - InitSound(); - InitSoundServer(); + InitJoysticks(); InitRND(NEW_RANDOMIZE); - signal(SIGINT, CloseAllAndExit); - signal(SIGTERM, CloseAllAndExit); + InitVideoDisplay(); + InitVideoBuffer(&backbuffer, &window, WIN_XSIZE, WIN_YSIZE, DEFAULT_DEPTH, + setup.fullscreen); - InitDisplay(); - InitWindow(argc, argv); + InitEventFilter(FilterMouseMotionEvents); - XMapWindow(display, window); - XFlush(display); + InitElementProperties(); + InitElementInfo(); InitGfx(); - InitElementProperties(); + + InitLevelInfo(); + InitLevelArtworkInfo(); + + InitImages(); /* needs to know current level directory */ + InitSound(); /* needs to know current level directory */ + InitMusic(); /* needs to know current level directory */ + + InitGfxBackground(); + + if (global.autoplay_leveldir) + { + AutoPlayTape(); + return; + } DrawMainMenu(); InitNetworkServer(); } -void InitLevelAndPlayerInfo() +static void InitGlobal() +{ + global.autoplay_leveldir = NULL; + + global.frames_per_second = 0; + global.fps_slowdown = FALSE; + global.fps_slowdown_factor = 1; +} + +static void InitSetup() +{ + LoadSetup(); /* global setup info */ +} + +static void InitPlayerInfo() { int i; @@ -98,369 +165,132 @@ void InitLevelAndPlayerInfo() local_player = &stored_player[0]; for (i=0; iconnected = TRUE; +} + +static void InitLevelInfo() +{ + LoadLevelInfo(); /* global level info */ + LoadLevelSetup_LastSeries(); /* last played series info */ + LoadLevelSetup_SeriesInfo(); /* last played level info */ +} + +static void InitArtworkInfo() +{ + LoadArtworkInfo(); +} + +static void InitArtworkConfig() +{ + static struct ConfigInfo action_suffix[NUM_ACTIONS + 1]; + static struct ConfigInfo direction_suffix[NUM_DIRECTIONS + 1]; + static struct ConfigInfo empty[1]; + int i; + + for (i=0; ivisual; - XFree((void *)vinfo); - } - - /* got appropriate visual? */ - if (depth < 8) - { - printf("Sorry, displays with less than 8 bits per pixel not supported.\n"); - exit(-1); - } - else if ((depth ==8 && visual->class != PseudoColor) || - (depth > 8 && visual->class != TrueColor && - visual->class != DirectColor)) - { - printf("Sorry, cannot get appropriate visual.\n"); - exit(-1); - } + /* currently nothing to do */ } -void InitWindow(int argc, char *argv[]) +static void InitImages() { - unsigned int border_width = 4; - Pixmap icon_pixmap, iconmask_pixmap; - unsigned int icon_width,icon_height; - int icon_hot_x,icon_hot_y; - char icon_filename[256]; - XSizeHints size_hints; - XWMHints wm_hints; - XClassHint class_hints; - XTextProperty windowName, iconName; - XGCValues gc_values; - unsigned long gc_valuemask; - char *window_name = WINDOWTITLE_STRING; - char *icon_name = WINDOWTITLE_STRING; - long window_event_mask; - Atom proto_atom = None, delete_atom = None; - int screen_width, screen_height; - int win_xpos = WIN_XPOS, win_ypos = WIN_YPOS; - unsigned long pen_fg = WhitePixel(display,screen); - unsigned long pen_bg = BlackPixel(display,screen); - -#ifndef MSDOS - static struct IconFileInfo icon_pic = - { - "rocks_icon.xbm", - "rocks_iconmask.xbm" - }; -#endif - - screen_width = XDisplayWidth(display, screen); - screen_height = XDisplayHeight(display, screen); - - width = WIN_XSIZE; - height = WIN_YSIZE; - - win_xpos = (screen_width - width) / 2; - win_ypos = (screen_height - height) / 2; - - window = XCreateSimpleWindow(display, RootWindow(display, screen), - win_xpos, win_ypos, width, height, border_width, - pen_fg, pen_bg); - -#ifndef MSDOS - proto_atom = XInternAtom(display, "WM_PROTOCOLS", FALSE); - delete_atom = XInternAtom(display, "WM_DELETE_WINDOW", FALSE); - if ((proto_atom != None) && (delete_atom != None)) - XChangeProperty(display, window, proto_atom, XA_ATOM, 32, - PropModePrepend, (unsigned char *) &delete_atom, 1); - - sprintf(icon_filename, "%s/%s/%s", - options.base_directory, GRAPHICS_DIRECTORY, - icon_pic.picture_filename); - XReadBitmapFile(display,window,icon_filename, - &icon_width,&icon_height, - &icon_pixmap,&icon_hot_x,&icon_hot_y); - if (!icon_pixmap) - Error(ERR_EXIT, "cannot read icon bitmap file '%s'", icon_filename); - - sprintf(icon_filename, "%s/%s/%s", - options.base_directory, GRAPHICS_DIRECTORY, - icon_pic.picturemask_filename); - XReadBitmapFile(display,window,icon_filename, - &icon_width,&icon_height, - &iconmask_pixmap,&icon_hot_x,&icon_hot_y); - if (!iconmask_pixmap) - Error(ERR_EXIT, "cannot read icon bitmap file '%s'", icon_filename); - - size_hints.width = size_hints.min_width = size_hints.max_width = width; - size_hints.height = size_hints.min_height = size_hints.max_height = height; - size_hints.flags = PSize | PMinSize | PMaxSize; - - if (win_xpos || win_ypos) - { - size_hints.x = win_xpos; - size_hints.y = win_ypos; - size_hints.flags |= PPosition; - } - - if (!XStringListToTextProperty(&window_name, 1, &windowName)) - Error(ERR_EXIT, "structure allocation for windowName failed"); - - if (!XStringListToTextProperty(&icon_name, 1, &iconName)) - Error(ERR_EXIT, "structure allocation for iconName failed"); - - wm_hints.initial_state = NormalState; - wm_hints.input = True; - wm_hints.icon_pixmap = icon_pixmap; - wm_hints.icon_mask = iconmask_pixmap; - wm_hints.flags = StateHint | IconPixmapHint | IconMaskHint | InputHint; - - class_hints.res_name = program_name; - class_hints.res_class = "Rocks'n'Diamonds"; - - XSetWMProperties(display, window, &windowName, &iconName, - argv, argc, &size_hints, &wm_hints, - &class_hints); - - XFree(windowName.value); - XFree(iconName.value); - - /* Select event types wanted */ - window_event_mask = ExposureMask | StructureNotifyMask | FocusChangeMask | - ButtonPressMask | ButtonReleaseMask | ButtonMotionMask | - KeyPressMask | KeyReleaseMask; - XSelectInput(display, window, window_event_mask); -#endif + ReloadCustomImages(); + ReinitializeGraphics(); +} - /* create GC for drawing with window depth */ - gc_values.graphics_exposures = False; - gc_values.foreground = pen_bg; - gc_values.background = pen_bg; - gc_valuemask = GCGraphicsExposures | GCForeground | GCBackground; - gc = XCreateGC(display, window, gc_valuemask, &gc_values); +static void InitSound() +{ + InitReloadCustomSounds(artwork.snd_current->identifier); + ReinitializeSounds(); } -void DrawInitText(char *text, int ypos, int color) +static void InitMusic() { - if (display && window && pix[PIX_SMALLFONT]) - { - XFillRectangle(display,window,gc,0,ypos, WIN_XSIZE,FONT2_YSIZE); - DrawTextExt(window,gc,(WIN_XSIZE-strlen(text)*FONT2_XSIZE)/2, - ypos,text,FS_SMALL,color); - XFlush(display); - } + InitReloadCustomMusic(artwork.mus_current->identifier); + ReinitializeMusic(); } -void InitGfx() +static void InitTileClipmasks() { - int i,j; - GC copy_clipmask_gc; +#if 0 +#if defined(TARGET_X11) XGCValues clip_gc_values; unsigned long clip_gc_valuemask; -#ifdef MSDOS - static struct PictureFileInfo pic[NUM_PICTURES] = - { - { "Screen", TRUE }, - { "Door", TRUE }, - { "Heroes", TRUE }, - { "Toons", TRUE }, - { "Font", FALSE }, - { "Font2", FALSE } - }; -#else - static struct PictureFileInfo pic[NUM_PICTURES] = - { - { "RocksScreen", TRUE }, - { "RocksDoor", TRUE }, - { "RocksHeroes", TRUE }, - { "RocksToons", TRUE }, - { "RocksFont", FALSE }, - { "RocksFont2", FALSE } - }; -#endif +#if defined(TARGET_X11_NATIVE) + +#if 0 + GC copy_clipmask_gc; static struct { @@ -493,6 +323,15 @@ void InitGfx() { GFX_SPIELER4_RIGHT, 4 }, { GFX_SPIELER4_PUSH_LEFT, 4 }, { GFX_SPIELER4_PUSH_RIGHT, 4 }, + { GFX_SP_MURPHY, 1 }, + { GFX_MURPHY_GO_LEFT, 3 }, + { GFX_MURPHY_GO_RIGHT, 3 }, + { GFX_MURPHY_SNAP_UP, 1 }, + { GFX_MURPHY_SNAP_DOWN, 1 }, + { GFX_MURPHY_SNAP_RIGHT, 1 }, + { GFX_MURPHY_SNAP_LEFT, 1 }, + { GFX_MURPHY_PUSH_RIGHT, 1 }, + { GFX_MURPHY_PUSH_LEFT, 1 }, { GFX_GEBLUBBER, 4 }, { GFX_DYNAMIT, 7 }, { GFX_DYNABOMB, 4 }, @@ -500,745 +339,1808 @@ void InitGfx() { GFX_SOKOBAN_OBJEKT, 1 }, { GFX_FUNKELN_BLAU, 3 }, { GFX_FUNKELN_WEISS, 3 }, + { GFX2_SHIELD_PASSIVE, 3 }, + { GFX2_SHIELD_ACTIVE, 3 }, { -1, 0 } }; - -#ifdef DEBUG_TIMING - long count1, count2; - count1 = Counter(); #endif - LoadGfx(PIX_SMALLFONT,&pic[PIX_SMALLFONT]); - DrawInitText(WINDOWTITLE_STRING,20,FC_YELLOW); - DrawInitText(COPYRIGHT_STRING,50,FC_RED); -#ifdef MSDOS - DrawInitText("MSDOS version done by Guido Schulz",210,FC_BLUE); - rest(200); -#endif MSDOS - DrawInitText("Loading graphics:",120,FC_GREEN); - - for(i=0; idrawable, + clip_gc_valuemask, &clip_gc_values); + +#if 0 + for (i=0; iclip_mask) + { + clip_gc_values.graphics_exposures = False; + 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); + } + } +#endif + +#if defined(TARGET_X11_NATIVE) +#if 0 + /* create graphic context structures needed for clipping */ clip_gc_values.graphics_exposures = False; clip_gc_valuemask = GCGraphicsExposures; - tile_clip_gc = - XCreateGC(display,window,clip_gc_valuemask,&clip_gc_values); - - /* initialize pixmap array to Pixmap 'None' */ - for(i=0; iclip_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++) + for (i=0; tile_needs_clipping[i].start>=0; i++) { - for(j=0; j= GFX_START_ROCKSSCREEN && - graphic <= GFX_END_ROCKSSCREEN) - { - src_pixmap = clipmask[PIX_BACK]; - graphic -= GFX_START_ROCKSSCREEN; - src_x = SX + (graphic % GFX_PER_LINE) * TILEX; - src_y = SY + (graphic / GFX_PER_LINE) * TILEY; - } - else if (graphic >= GFX_START_ROCKSHEROES && - graphic <= GFX_END_ROCKSHEROES) - { - src_pixmap = clipmask[PIX_HEROES]; - graphic -= GFX_START_ROCKSHEROES; - src_x = (graphic % HEROES_PER_LINE) * TILEX; - src_y = (graphic / HEROES_PER_LINE) * TILEY; - } - else if (graphic >= GFX_START_ROCKSFONT && - graphic <= GFX_END_ROCKSFONT) - { - src_pixmap = clipmask[PIX_BIGFONT]; - graphic -= GFX_START_ROCKSFONT; - src_x = (graphic % FONT_CHARS_PER_LINE) * TILEX; - src_y = (graphic / FONT_CHARS_PER_LINE) * TILEY + - FC_SPECIAL1 * FONT_LINES_PER_FONT * TILEY; - } - else - break; + getGraphicSource(graphic, &src_bitmap, &src_x, &src_y); + src_pixmap = src_bitmap->clip_mask; - tile_clipmask[tile] = XCreatePixmap(display, window, TILEX,TILEY, 1); + tile_clipmask[tile] = XCreatePixmap(display, window->drawable, + TILEX, TILEY, 1); - XCopyArea(display,src_pixmap,tile_clipmask[tile],copy_clipmask_gc, - src_x,src_y, TILEX,TILEY, 0,0); + XCopyArea(display, src_pixmap, tile_clipmask[tile], copy_clipmask_gc, + src_x, src_y, TILEX, TILEY, 0, 0); } } - if (!pix[PIX_DB_BACK] || !pix[PIX_DB_DOOR]) - Error(ERR_EXIT, "cannot create additional pixmaps"); + XFreeGC(display, copy_clipmask_gc); +#endif + +#endif /* TARGET_X11_NATIVE */ +#endif /* TARGET_X11 */ +#endif +} + +void FreeTileClipmasks() +{ +#if 0 +#if defined(TARGET_X11) + int i; - for(i=0; istored_clip_gc) + { + XFreeGC(display, pix[i]->stored_clip_gc); + pix[i]->stored_clip_gc = None; + } + } +#endif + +#endif /* TARGET_X11 */ +#endif +} + +void InitGfx() +{ +#if 0 + int i; +#endif + + /* 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 */ + bitmap_db_field = CreateBitmap(FXSIZE, FYSIZE, DEFAULT_DEPTH); + bitmap_db_door = CreateBitmap(3 * DXSIZE, DYSIZE + VYSIZE, DEFAULT_DEPTH); + +#if 0 + pix[PIX_FONT_SMALL] = LoadCustomImage(image_filename[PIX_FONT_SMALL]); + + InitFontInfo(NULL, NULL, pix[PIX_FONT_SMALL], NULL); +#else + bitmap_font_initial = LoadCustomImage(image_filename[PIX_FONT_SMALL]); + + InitFontInfo(bitmap_font_initial, NULL, NULL, NULL, NULL); +#endif + + DrawInitText(WINDOW_TITLE_STRING, 20, FC_YELLOW); + DrawInitText(WINDOW_SUBTITLE_STRING, 50, FC_RED); + + DrawInitText("Loading graphics:", 120, FC_GREEN); + +#if 0 + for (i=0; iidentifier; + char *snd_new_identifier = artwork.snd_current->identifier; + char *mus_new_identifier = artwork.mus_current->identifier; + boolean redraw_screen = FALSE; + + if (leveldir_current_identifier == NULL) + leveldir_current_identifier = leveldir_current->identifier; + +#if 0 + printf("CURRENT GFX: '%s' ['%s']\n", artwork.gfx_current->identifier, + leveldir_current->graphics_set); + printf("CURRENT LEV: '%s' / '%s'\n", leveldir_current_identifier, + leveldir_current->identifier); #endif -#ifdef DEBUG_TIMING - long count1, count2; +#if 0 + printf("graphics --> '%s' ('%s')\n", + artwork.gfx_current_identifier, artwork.gfx_current->filename); + printf("sounds --> '%s' ('%s')\n", + artwork.snd_current_identifier, artwork.snd_current->filename); + printf("music --> '%s' ('%s')\n", + artwork.mus_current_identifier, artwork.mus_current->filename); #endif - /* Grafik laden */ - if (pic->picture_filename) + /* leveldir_current may be invalid (level group, parent link) */ + if (!validLevelSeries(leveldir_current)) + return; + + /* when a new level series was selected, check if there was a change + in custom artwork stored in level series directory */ + if (leveldir_current_identifier != leveldir_current->identifier) { - sprintf(basefilename, "%s%s", pic->picture_filename, picture_ext); - DrawInitText(basefilename, 150, FC_YELLOW); - sprintf(filename, "%s/%s/%s", - options.base_directory, GRAPHICS_DIRECTORY, basefilename); + char *identifier_old = leveldir_current_identifier; + char *identifier_new = leveldir_current->identifier; + + if (getTreeInfoFromIdentifier(artwork.gfx_first, identifier_old) != + getTreeInfoFromIdentifier(artwork.gfx_first, identifier_new)) + gfx_new_identifier = identifier_new; + if (getTreeInfoFromIdentifier(artwork.snd_first, identifier_old) != + getTreeInfoFromIdentifier(artwork.snd_first, identifier_new)) + snd_new_identifier = identifier_new; + if (getTreeInfoFromIdentifier(artwork.mus_first, identifier_new) != + getTreeInfoFromIdentifier(artwork.mus_first, identifier_new)) + mus_new_identifier = identifier_new; + + leveldir_current_identifier = leveldir_current->identifier; + } -#ifdef MSDOS - rest(100); -#endif MSDOS + /* custom level artwork configured in level series configuration file + always overrides custom level artwork stored in level series directory + and (level independant) custom artwork configured in setup menue */ + if (leveldir_current->graphics_set != NULL) + gfx_new_identifier = leveldir_current->graphics_set; + if (leveldir_current->sounds_set != NULL) + snd_new_identifier = leveldir_current->sounds_set; + if (leveldir_current->music_set != NULL) + mus_new_identifier = leveldir_current->music_set; + + if (strcmp(artwork.gfx_current_identifier, gfx_new_identifier) != 0 || + last_override_level_graphics != setup.override_level_graphics) + { +#if 0 + printf("RELOADING GRAPHICS '%s' -> '%s' ('%s')\n", + artwork.gfx_current_identifier, + artwork.gfx_current->identifier, + gfx_new_identifier); +#endif + + setLevelArtworkDir(artwork.gfx_first); + + ClearRectangle(window, 0, 0, WIN_XSIZE, WIN_YSIZE); + + ReloadCustomImages(); + ReinitializeGraphics(); -#ifdef DEBUG_TIMING - count1 = Counter(); + FreeTileClipmasks(); + InitTileClipmasks(); + + artwork.gfx_current_identifier = artwork.gfx_current->identifier; + last_override_level_graphics = setup.override_level_graphics; + + redraw_screen = TRUE; + } + + if (strcmp(artwork.snd_current_identifier, snd_new_identifier) != 0 || + last_override_level_sounds != setup.override_level_sounds) + { +#if 0 + printf("RELOADING SOUNDS '%s' -> '%s' ('%s')\n", + artwork.snd_current_identifier, + artwork.snd_current->identifier, + snd_new_identifier); #endif -#ifdef XPM_INCLUDE_FILE + /* set artwork path to send it to the sound server process */ + setLevelArtworkDir(artwork.snd_first); + + InitReloadCustomSounds(snd_new_identifier); + ReinitializeSounds(); + + artwork.snd_current_identifier = artwork.snd_current->identifier; + last_override_level_sounds = setup.override_level_sounds; + + redraw_screen = TRUE; + } + + if (strcmp(artwork.mus_current_identifier, mus_new_identifier) != 0 || + last_override_level_music != setup.override_level_music) + { + /* set artwork path to send it to the sound server process */ + setLevelArtworkDir(artwork.mus_first); + + InitReloadCustomMusic(mus_new_identifier); + ReinitializeMusic(); + + artwork.mus_current_identifier = artwork.mus_current->identifier; + last_override_level_music = setup.override_level_music; + + redraw_screen = TRUE; + } + + if (redraw_screen) + { + InitGfxBackground(); + + /* force redraw of (open or closed) door graphics */ + SetDoorState(DOOR_OPEN_ALL); + CloseDoor(DOOR_CLOSE_ALL | DOOR_NO_DELAY); + } +} + +void FreeGadgets() +{ + FreeLevelEditorGadgets(); + FreeGameButtons(); + FreeTapeButtons(); + FreeToolButtons(); + FreeScreenGadgets(); +} + +void InitGadgets() +{ + static boolean gadgets_initialized = FALSE; + + if (gadgets_initialized) + FreeGadgets(); - xpm_att[pos].valuemask = XpmCloseness; - xpm_att[pos].closeness = 20000; - xpm_err = XpmReadFileToPixmap(display,window,filename, - &pix[pos],&shapemask,&xpm_att[pos]); + CreateLevelEditorGadgets(); + CreateGameButtons(); + CreateTapeButtons(); + CreateToolButtons(); + CreateScreenGadgets(); - switch(xpm_err) + gadgets_initialized = TRUE; +} + +void InitElementInfo() +{ + int i, act, dir; + + /* set values to -1 to identify later as "uninitialized" values */ + for (i=0; i -1) + { + int element = element_to_graphic[i].element; + int direction = element_to_graphic[i].direction; + int action = element_to_graphic[i].action; + int graphic = element_to_graphic[i].graphic; - gif_err = Read_GIF_to_Pixmaps(display, window, filename, - &pix[pos], &clipmask[pos]); + if (action < 0) + action = ACTION_DEFAULT; - switch(gif_err) + if (direction > -1) { - case GIF_Success: - break; - case GIF_OpenFailed: - Error(ERR_EXIT, "cannot open GIF file '%s'", filename); - case GIF_ReadFailed: - Error(ERR_EXIT, "cannot read GIF file '%s'", filename); - case GIF_FileInvalid: - Error(ERR_EXIT, "invalid GIF file '%s'", filename); - case GIF_NoMemory: - Error(ERR_EXIT, "not enough memory for GIF file '%s'", filename); - case GIF_ColorFailed: - Error(ERR_EXIT, "cannot get colors for GIF file '%s'", filename); - default: - break; + direction = MV_DIR_BIT(direction); + + element_info[element].direction_graphic[action][direction] = graphic; } + else + element_info[element].graphic[action] = graphic; -#ifdef DEBUG_TIMING - count2 = Counter(); - printf("GIF LOADING %s IN %.2f SECONDS\n", - filename,(float)(count2-count1)/1000.0); -#endif + i++; + } -#endif + /* now set all '-1' values to element specific default values */ + for (i=0; ipicture_filename); + /* no graphic for this specific action -- use default action graphic */ + if (element_info[i].graphic[act] == -1) + element_info[i].graphic[act] = default_action_graphic; + } } +} - /* zugehörige Maske laden (wenn vorhanden) */ - if (pic->picture_with_mask) +static void set_graphic_parameters(int graphic, int *parameter) +{ + Bitmap *src_bitmap = getBitmapFromImageID(graphic); + int num_xtiles = (src_bitmap ? src_bitmap->width : TILEX) / TILEX; + int num_ytiles = (src_bitmap ? src_bitmap->height * 2 / 3 : TILEY) / TILEY; + + graphic_info[graphic].bitmap = src_bitmap; + + graphic_info[graphic].src_x = parameter[GFX_ARG_XPOS] * TILEX; + graphic_info[graphic].src_y = parameter[GFX_ARG_YPOS] * TILEY; + graphic_info[graphic].offset_x = parameter[GFX_ARG_OFFSET]; + graphic_info[graphic].offset_y = 0; + + /* animation frames are ordered vertically instead of horizontally */ + if (parameter[GFX_ARG_VERTICAL]) { + graphic_info[graphic].offset_x = 0; + graphic_info[graphic].offset_y = parameter[GFX_ARG_OFFSET]; + } + + /* optionally, the x and y offset of frames can be specified directly */ + if (parameter[GFX_ARG_XOFFSET] != ARG_UNDEFINED_VALUE) + graphic_info[graphic].offset_x = parameter[GFX_ARG_XOFFSET]; + if (parameter[GFX_ARG_YOFFSET] != ARG_UNDEFINED_VALUE) + graphic_info[graphic].offset_y = parameter[GFX_ARG_YOFFSET]; + + /* automatically determine correct number of frames, if not defined */ + if (parameter[GFX_ARG_FRAMES] != ARG_UNDEFINED_VALUE) + graphic_info[graphic].anim_frames = parameter[GFX_ARG_FRAMES]; + else if (parameter[GFX_ARG_XPOS] == 0 && !parameter[GFX_ARG_VERTICAL]) + graphic_info[graphic].anim_frames = num_xtiles; + else if (parameter[GFX_ARG_YPOS] == 0 && parameter[GFX_ARG_VERTICAL]) + graphic_info[graphic].anim_frames = num_ytiles; + else + graphic_info[graphic].anim_frames = 1; + + graphic_info[graphic].anim_delay = parameter[GFX_ARG_DELAY]; + if (graphic_info[graphic].anim_delay == 0) /* delay must be at least 1 */ + graphic_info[graphic].anim_delay = 1; + + /* set mode for animation frame order */ + if (parameter[GFX_ARG_MODE_LOOP]) + graphic_info[graphic].anim_mode = ANIM_LOOP; + else if (parameter[GFX_ARG_MODE_LINEAR]) + graphic_info[graphic].anim_mode = ANIM_LINEAR; + else if (parameter[GFX_ARG_MODE_PINGPONG]) + graphic_info[graphic].anim_mode = ANIM_PINGPONG; + else if (parameter[GFX_ARG_MODE_PINGPONG2]) + graphic_info[graphic].anim_mode = ANIM_PINGPONG2; + else if (parameter[GFX_ARG_MODE_RANDOM]) + graphic_info[graphic].anim_mode = ANIM_RANDOM; + else if (graphic_info[graphic].anim_frames > 1) + graphic_info[graphic].anim_mode = ANIM_LOOP; + else + graphic_info[graphic].anim_mode = ANIM_NONE; + + /* set additional flag to play animation frames in reverse order */ + if (parameter[GFX_ARG_MODE_REVERSE]) + graphic_info[graphic].anim_mode |= ANIM_REVERSE; + + /* automatically determine correct start frame, if not defined */ + if (parameter[GFX_ARG_START_FRAME] == ARG_UNDEFINED_VALUE) + graphic_info[graphic].anim_start_frame = 0; + else if (graphic_info[graphic].anim_mode & ANIM_REVERSE) + graphic_info[graphic].anim_start_frame = + graphic_info[graphic].anim_frames - parameter[GFX_ARG_START_FRAME] - 1; + else + graphic_info[graphic].anim_start_frame = parameter[GFX_ARG_START_FRAME]; + + /* animation synchronized with global frame counter, not move position */ + graphic_info[graphic].anim_global_sync = parameter[GFX_ARG_GLOBAL_SYNC]; +} -#ifdef XPM_INCLUDE_FILE +static void InitGraphicInfo() +{ + static boolean clipmasks_initialized = FALSE; + int i; +#if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND) + Pixmap src_pixmap; + XGCValues clip_gc_values; + unsigned long clip_gc_valuemask; + GC copy_clipmask_gc = None; +#endif - sprintf(basefilename, "%s%s", pic->picture_filename, picturemask_ext); - DrawInitText(basefilename, 150, FC_YELLOW); - sprintf(filename, "%s/%s/%s", - options.base_directory, GRAPHICS_DIRECTORY, basefilename); + image_files = getCurrentImageList(); -#ifdef DEBUG_TIMING - count1 = Counter(); +#if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND) + if (clipmasks_initialized) + { + for (i=0; i src_bitmap->width || + src_y + TILEY > src_bitmap->height) + { + Error(ERR_RETURN_LINE, "-"); + Error(ERR_RETURN, "warning: error found in config file:"); + Error(ERR_RETURN, "- config file: '%s'", + getImageConfigFilename()); + Error(ERR_RETURN, "- config token: '%s'", + getTokenFromImageID(i)); + Error(ERR_RETURN, "- image file: '%s'", + src_bitmap->source_filename); + Error(ERR_RETURN, + "error: first animation frame out of bounds (%d, %d)", + src_x, src_y); + Error(ERR_RETURN, "custom graphic rejected for this element/action"); + Error(ERR_RETURN_LINE, "-"); + + set_graphic_parameters(i, image_files[i].default_parameter); + } + + last_frame = graphic_info[i].anim_frames - 1; + getGraphicSource(i, last_frame, &src_bitmap, &src_x, &src_y); + if (src_x < 0 || src_y < 0 || + src_x + TILEX > src_bitmap->width || + src_y + TILEY > src_bitmap->height) { - case BitmapSuccess: - break; - case BitmapOpenFailed: - Error(ERR_EXIT, "cannot open XBM file '%s'", filename); - case BitmapFileInvalid: - Error(ERR_EXIT, "invalid XBM file '%s'", filename); - case BitmapNoMemory: - Error(ERR_EXIT, "not enough memory for XBM file '%s'", filename); - break; - default: - break; + Error(ERR_RETURN_LINE, "-"); + Error(ERR_RETURN, "warning: error found in config file:"); + Error(ERR_RETURN, "- config file: '%s'", + getImageConfigFilename()); + Error(ERR_RETURN, "- config token: '%s'", + getTokenFromImageID(i)); + Error(ERR_RETURN, "- image file: '%s'", + src_bitmap->source_filename); + Error(ERR_RETURN, + "error: last animation frame (%d) out of bounds (%d, %d)", + last_frame, src_x, src_y); + Error(ERR_RETURN, "custom graphic rejected for this element/action"); + Error(ERR_RETURN_LINE, "-"); + + set_graphic_parameters(i, image_files[i].default_parameter); } -#ifdef DEBUG_TIMING - count2 = Counter(); - printf("XBM LOADING %s IN %.2f SECONDS\n", - filename,(float)(count2-count1)/1000.0); +#if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND) + /* currently we need only a tile clip mask from the first frame */ + getGraphicSource(i, first_frame, &src_bitmap, &src_x, &src_y); + + if (copy_clipmask_gc == None) + { + clip_gc_values.graphics_exposures = False; + clip_gc_valuemask = GCGraphicsExposures; + copy_clipmask_gc = XCreateGC(display, src_bitmap->clip_mask, + clip_gc_valuemask, &clip_gc_values); + } + + graphic_info[i].clip_mask = + XCreatePixmap(display, window->drawable, TILEX, TILEY, 1); + + src_pixmap = src_bitmap->clip_mask; + XCopyArea(display, src_pixmap, graphic_info[i].clip_mask, + copy_clipmask_gc, src_x, src_y, TILEX, TILEY, 0, 0); + + clip_gc_values.graphics_exposures = False; + clip_gc_values.clip_mask = graphic_info[i].clip_mask; + clip_gc_valuemask = GCGraphicsExposures | GCClipMask; + graphic_info[i].clip_gc = + XCreateGC(display, window->drawable, clip_gc_valuemask, &clip_gc_values); #endif + } +#if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND) + if (copy_clipmask_gc) + XFreeGC(display, copy_clipmask_gc); #endif - if (!clipmask[pos]) - Error(ERR_EXIT, "cannot get clipmask for '%s'", pic->picture_filename); + clipmasks_initialized = TRUE; +} + +static void set_sound_parameters(int sound, int *parameter) +{ + /* explicit loop mode setting in configuration overrides default value */ + if (parameter[SND_ARG_MODE_LOOP] != ARG_UNDEFINED_VALUE) + sound_info[sound].loop = parameter[SND_ARG_MODE_LOOP]; +} + +static void InitSoundInfo() +{ + int sound_effect_properties[NUM_SOUND_FILES]; + int i, j; + + sound_files = getCurrentSoundList(); + + /* initialize sound effect for all elements to "no sound" */ + for (i=0; i