rnd-20020421-1-src
[rocksndiamonds.git] / src / init.c
index fe585257360fc68d0dc3785be8dbf0f4761013b4..69008db67a887ed0e384734734f3c99ca2f9c24f 100644 (file)
@@ -71,6 +71,7 @@ void OpenAll(void)
 
   InitSetup();
   InitPlayerInfo();
+  InitArtworkInfo();           /* needed before loading gfx, sound & music */
 
   InitCounter();
   InitSound();
@@ -83,7 +84,6 @@ void OpenAll(void)
 
   InitEventFilter(FilterMouseMotionEvents);
 
-  InitArtworkInfo();
   InitGfx();
   InitElementProperties();     /* initializes IS_CHAR() for el2gfx() */
 
@@ -159,8 +159,10 @@ void InitSound()
 
   for(i=0; i<NUM_SOUNDS; i++)
   {
-    if (!LoadSound(sound_name[i]))
+    if (!LoadCustomSound(sound_name[i]))
     {
+      Error(ERR_WARN, "sounds deactivated");
+
       audio.sound_available = FALSE;
       audio.loops_available = FALSE;
       audio.sound_enabled = FALSE;
@@ -180,7 +182,6 @@ void InitTileClipmasks()
   GC copy_clipmask_gc;
   XGCValues clip_gc_values;
   unsigned long clip_gc_valuemask;
-#endif
 
 #if defined(TARGET_X11_NATIVE)
   static struct
@@ -234,7 +235,8 @@ void InitTileClipmasks()
     { GFX2_SHIELD_ACTIVE, 3 },
     { -1, 0 }
   };
-#endif
+#endif /* TARGET_X11_NATIVE */
+#endif /* TARGET_X11 */
 
   int i;
 
@@ -248,13 +250,6 @@ void InitTileClipmasks()
      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 =
@@ -268,11 +263,19 @@ void InitTileClipmasks()
       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++)
   {
@@ -296,10 +299,42 @@ void InitTileClipmasks()
                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]->stored_clip_gc)
+    {
+      XFreeGC(display, pix[i]->stored_clip_gc);
+      pix[i]->stored_clip_gc = None;
+    }
+  }
+#endif /* TARGET_X11 */
+}
+
 void InitGfx()
 {
   int i;
@@ -355,9 +390,9 @@ void InitGfxBackground()
   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++)
@@ -366,6 +401,44 @@ void InitGfxBackground()
   redraw_mask = REDRAW_ALL;
 }
 
+void ReloadCustomArtwork()
+{
+  if (artwork.graphics_set_current != artwork.gfx_current->name)
+  {
+    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 = artwork.gfx_current->name;
+  }
+
+  if (artwork.sounds_set_current != artwork.snd_current->name)
+  {
+    InitReloadSounds(artwork.snd_current->name);
+
+    artwork.sounds_set_current = artwork.snd_current->name;
+  }
+
+  if (artwork.music_set_current != artwork.mus_current->name)
+  {
+    InitReloadMusic(artwork.mus_current->name);
+
+    artwork.music_set_current = artwork.mus_current->name;
+  }
+}
+
 void InitGadgets()
 {
   CreateLevelEditorGadgets();
@@ -1532,6 +1605,7 @@ void CloseAllAndExit(int exit_value)
   FreeSounds(NUM_SOUNDS);
   CloseAudio();
 
+  FreeTileClipmasks();
   for(i=0; i<NUM_BITMAPS; i++)
     FreeBitmap(pix[i]);