rnd-20001205-2-src
[rocksndiamonds.git] / src / init.c
index 08bbb05bdfe968f051c0a73041496c48d4c5bb0b..ae65640f67f152bd51070ef2da3027a9a0a7c10b 100644 (file)
 #include "network.h"
 #include "netserv.h"
 
-struct PictureFileInfo
-{
-  char *picture_filename;
-  boolean picture_with_mask;
-};
-
 static void InitPlayerInfo(void);
 static void InitLevelInfo(void);
 static void InitNetworkServer(void);
@@ -41,11 +35,10 @@ static void InitSoundServer(void);
 static void InitDisplay(void);
 static void InitGfx(void);
 static void InitGfxBackground(void);
-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 +56,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 +141,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 +310,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);
@@ -337,32 +326,32 @@ void InitGfx()
 #endif
 
 #if !defined(PLATFORM_MSDOS)
-  static struct PictureFileInfo pic[NUM_PICTURES] =
+  static char *image_filename[NUM_PICTURES] =
   {
-    { "RocksScreen",   TRUE },
-    { "RocksDoor",     TRUE },
-    { "RocksHeroes",   TRUE },
-    { "RocksToons",    TRUE },
-    { "RocksSP",       TRUE },
-    { "RocksDC",       TRUE },
-    { "RocksMore",     TRUE },
-    { "RocksFont",     FALSE },
-    { "RocksFont2",    FALSE },
-    { "RocksFont3",    FALSE }
+    "RocksScreen.pcx",
+    "RocksDoor.pcx",
+    "RocksHeroes.pcx",
+    "RocksToons.pcx",
+    "RocksSP.pcx",
+    "RocksDC.pcx",
+    "RocksMore.pcx",
+    "RocksFont.pcx",
+    "RocksFont2.pcx",
+    "RocksFont3.pcx"
   }; 
 #else
-  static struct PictureFileInfo pic[NUM_PICTURES] =
+  static char *image_filename[NUM_PICTURES] =
   {
-    { "Screen",        TRUE },
-    { "Door",  TRUE },
-    { "Heroes",        TRUE },
-    { "Toons", TRUE },
-    { "SP",    TRUE },
-    { "DC",    TRUE },
-    { "More",  TRUE },
-    { "Font",  FALSE },
-    { "Font2", FALSE },
-    { "Font3", FALSE }
+    "Screen.pcx",
+    "Door.pcx",
+    "Heroes.pcx",
+    "Toons.pcx",
+    "SP.pcx",
+    "DC.pcx",
+    "More.pcx",
+    "Font.pcx",
+    "Font2.pcx",
+    "Font3.pcx"
   }; 
 #endif
 
@@ -420,20 +409,23 @@ void InitGfx()
   };
 #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);
 
-  LoadGfx(PIX_SMALLFONT, &pic[PIX_SMALLFONT]);
+  pix[PIX_SMALLFONT] = LoadImage(image_filename[PIX_SMALLFONT]);
   InitFontInfo(NULL, NULL, pix[PIX_SMALLFONT]);
 
   DrawInitText(WINDOW_TITLE_STRING, 20, FC_YELLOW);
@@ -445,8 +437,13 @@ void InitGfx()
   DrawInitText("Loading graphics:",120,FC_GREEN);
 
   for(i=0; i<NUM_PICTURES; i++)
+  {
     if (i != PIX_SMALLFONT)
-      LoadGfx(i,&pic[i]);
+    {
+      DrawInitText(image_filename[i], 150, FC_YELLOW);
+      pix[i] = LoadImage(image_filename[i]);
+    }
+  }
 
   InitFontInfo(pix[PIX_BIGFONT], pix[PIX_MEDIUMFONT], pix[PIX_SMALLFONT]);
 
@@ -569,92 +566,6 @@ void InitGfxBackground()
   redraw_mask = REDRAW_ALL;
 }
 
-void LoadGfx(int pos, struct PictureFileInfo *pic)
-{
-  char basefilename[256];
-  char filename[256];
-
-#if defined(TARGET_SDL)
-  SDL_Surface *sdl_image_tmp;
-#else
-  int pcx_err;
-#endif
-  char *picture_ext = ".pcx";
-
-  /* Grafik laden */
-  if (pic->picture_filename)
-  {
-    sprintf(basefilename, "%s%s", pic->picture_filename, picture_ext);
-    DrawInitText(basefilename, 150, FC_YELLOW);
-    sprintf(filename, "%s/%s/%s",
-           options.ro_base_directory, GRAPHICS_DIRECTORY, basefilename);
-
-#if defined(PLATFORM_MSDOS)
-    rest(100);
-#endif
-
-    pix[pos] = CreateBitmapStruct();
-
-#if defined(TARGET_SDL)
-    /* load image to temporary surface */
-    if ((sdl_image_tmp = IMG_Load(filename)) == NULL)
-      Error(ERR_EXIT, "IMG_Load() failed: %s", SDL_GetError());
-
-    /* create native non-transparent surface for current image */
-    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[pos]->surface_masked = SDL_DisplayFormat(sdl_image_tmp)) == NULL)
-      Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s", SDL_GetError());
-
-    /* free temporary surface */
-    SDL_FreeSurface(sdl_image_tmp);
-
-#else /* !TARGET_SDL */
-
-    pcx_err = Read_PCX_to_Pixmap(display, window->drawable, window->gc,
-                                filename,
-                                &pix[pos]->drawable, &pix[pos]->clip_mask);
-    switch(pcx_err)
-    {
-      case PCX_Success:
-        break;
-      case PCX_OpenFailed:
-        Error(ERR_EXIT, "cannot open PCX file '%s'", filename);
-      case PCX_ReadFailed:
-        Error(ERR_EXIT, "cannot read PCX file '%s'", filename);
-      case PCX_FileInvalid:
-       Error(ERR_EXIT, "invalid PCX file '%s'", filename);
-      case PCX_NoMemory:
-       Error(ERR_EXIT, "not enough memory for PCX file '%s'", filename);
-      case PCX_ColorFailed:
-       Error(ERR_EXIT, "cannot get colors for PCX file '%s'", filename);
-      default:
-       break;
-    }
-
-    if (!pix[pos]->drawable)
-      Error(ERR_EXIT, "cannot get graphics for '%s'", pic->picture_filename);
-
-#if 0
-    /* 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
-
-#endif /* !TARGET_SDL */
-  }
-
-#if defined(TARGET_X11)
-  /* check if clip mask was correctly created */
-  if (pic->picture_with_mask && !pix[pos]->clip_mask)
-    Error(ERR_EXIT, "cannot get clipmask for '%s'", pic->picture_filename);
-#endif
-}
-
 void InitGadgets()
 {
   CreateLevelEditorGadgets();