rnd-20001204-3-src
[rocksndiamonds.git] / src / init.c
index 1c56fc0a3d9b7f6cfc782690452bc007333b5ae0..d83b754235cc37dce7569864cbae08d712a1bc94 100644 (file)
@@ -45,7 +45,7 @@ static void LoadGfx(int, struct PictureFileInfo *);
 static void InitGadgets(void);
 static void InitElementProperties(void);
 
-void OpenAll(int argc, char *argv[])
+void OpenAll(void)
 {
 #if !defined(PLATFORM_UNIX)
   initErrorFile();
@@ -63,6 +63,11 @@ void OpenAll(int argc, char *argv[])
     exit(0);
   }
 
+  InitProgramInfo(UNIX_USERDATA_DIRECTORY,
+                 PROGRAM_TITLE_STRING, WINDOW_TITLE_STRING,
+                 ICON_TITLE_STRING, X11_ICON_FILENAME, X11_ICONMASK_FILENAME,
+                 MSDOS_POINTER_FILENAME);
+
   InitPlayerInfo();
 
   InitCounter();
@@ -143,14 +148,16 @@ void InitSound()
 
   OpenAudio(&audio);
 
+  AllocSoundArray(NUM_SOUNDS);
+
   for(i=0; i<NUM_SOUNDS; i++)
   {
-    Sound[i].name = sound_name[i];
-
-    if (!LoadSound(&Sound[i]))
+    if (!LoadSound(i, sound_name[i]))
     {
       audio.sound_available = FALSE;
       audio.loops_available = FALSE;
+      audio.sound_enabled = FALSE;
+
       return;
     }
   }
@@ -310,17 +317,6 @@ void InitJoysticks()
 
 void InitDisplay()
 {
-  char *gfx_dir = getPath2(options.ro_base_directory, GRAPHICS_DIRECTORY);
-  char *x11_icon_filename = getPath2(gfx_dir, X11_ICON_FILENAME);
-  char *x11_iconmask_filename = getPath2(gfx_dir, X11_ICONMASK_FILENAME);
-  char *msdos_pointer_filename = getPath2(gfx_dir, MSDOS_POINTER_FILENAME);
-
-  free(gfx_dir);
-
-  InitProgramInfo(program_name, PROGRAM_TITLE_STRING, WINDOW_TITLE_STRING,
-                 ICON_TITLE_STRING, x11_icon_filename, x11_iconmask_filename,
-                 msdos_pointer_filename);
-
   InitVideoDisplay();
   InitVideoBuffer(&backbuffer, &window, WIN_XSIZE, WIN_YSIZE, DEFAULT_DEPTH,
                  setup.fullscreen);
@@ -328,11 +324,9 @@ void InitDisplay()
 
 void InitGfx()
 {
-  int i, j;
+  int i;
 
-#if defined(TARGET_SDL)
-  SDL_Surface *sdl_image_tmp;
-#else
+#if defined(TARGET_X11)
   GC copy_clipmask_gc;
   XGCValues clip_gc_values;
   unsigned long clip_gc_valuemask;
@@ -368,6 +362,7 @@ void InitGfx()
   }; 
 #endif
 
+#ifdef TARGET_X11
   static struct
   {
     int start;
@@ -419,17 +414,21 @@ void InitGfx()
     { GFX2_SHIELD_ACTIVE, 3 },
     { -1, 0 }
   };
+#endif
 
-  /* initialize playfield properties */
+  /* initialize some global variables */
+  global.frames_per_second = 0;
+  global.fps_slowdown = FALSE;
+  global.fps_slowdown_factor = 1;
 
-  InitPlayfieldInfo(SX, SY, SXSIZE, SYSIZE,
-                   REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE);
-  InitDoor1Info(DX, DY, DXSIZE, DYSIZE);
-  InitDoor2Info(VX, VY, VXSIZE, VYSIZE);
-  InitScrollbufferInfo(FXSIZE, FYSIZE);
+  /* 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);
 
@@ -454,6 +453,7 @@ void InitGfx()
 
 #if defined(TARGET_SDL)
 
+#if 0
   /* initialize surface array to 'NULL' */
   for(i=0; i<NUM_TILES; i++)
     tile_masked[i] = NULL;
@@ -463,6 +463,7 @@ void InitGfx()
   {
     for(j=0; j<tile_needs_clipping[i].count; j++)
     {
+      SDL_Surface *sdl_image_tmp;
       int tile = tile_needs_clipping[i].start + j;
       int graphic = tile;
       int src_x, src_y;
@@ -470,7 +471,7 @@ void InitGfx()
       Bitmap src_bitmap;
 
       getGraphicSource(graphic, &bitmap_nr, &src_x, &src_y);
-      src_bitmap = pix_masked[bitmap_nr];
+      src_bitmap = pix[bitmap_nr];
 
       /* create surface for masked tile graphic */
       if ((sdl_image_tmp = SDL_CreateRGBSurface(SDL_SWSURFACE, TILEX, TILEY,
@@ -489,6 +490,7 @@ void InitGfx()
       BlitBitmap(src_bitmap, tile_masked[tile], src_x,src_y, TILEX,TILEY, 0,0);
     }
   }
+#endif
 
 #else /* !TARGET_SDL */
 
@@ -523,6 +525,8 @@ void InitGfx()
   /* create only those clipping Pixmaps we really need */
   for(i=0; tile_needs_clipping[i].start>=0; i++)
   {
+    int j;
+
     for(j=0; j<tile_needs_clipping[i].count; j++)
     {
       int tile = tile_needs_clipping[i].start + j;
@@ -596,13 +600,13 @@ void LoadGfx(int pos, struct PictureFileInfo *pic)
       Error(ERR_EXIT, "IMG_Load() failed: %s", SDL_GetError());
 
     /* create native non-transparent surface for current image */
-    if ((pix[pos] = SDL_DisplayFormat(sdl_image_tmp)) == NULL)
+    if ((pix[pos]->surface = 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 ((pix_masked[pos] = SDL_DisplayFormat(sdl_image_tmp)) == NULL)
+    if ((pix[pos]->surface_masked = SDL_DisplayFormat(sdl_image_tmp)) == NULL)
       Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s", SDL_GetError());
 
     /* free temporary surface */
@@ -634,6 +638,8 @@ void LoadGfx(int pos, struct PictureFileInfo *pic)
     if (!pix[pos]->drawable)
       Error(ERR_EXIT, "cannot get graphics for '%s'", pic->picture_filename);
 
+    pix[pos]->gc = window->gc;
+
 #if 0
     /* setting pix_masked[] to pix[] allows BlitBitmapMasked() to always
        use pix_masked[], although they are the same when not using SDL */