[Tux4kids-commits] r1404 - branches/commonification/tuxtype/trunk/src

Bolesław Kulbabiński bolekk-guest at alioth.debian.org
Sun Aug 9 18:58:22 UTC 2009


Author: bolekk-guest
Date: 2009-08-09 18:58:22 +0000 (Sun, 09 Aug 2009)
New Revision: 1404

Modified:
   branches/commonification/tuxtype/trunk/src/SDL_extras.h
   branches/commonification/tuxtype/trunk/src/fileops_media.c
   branches/commonification/tuxtype/trunk/src/fileops_media.h
   branches/commonification/tuxtype/trunk/src/funcs.h
   branches/commonification/tuxtype/trunk/src/laser.c
   branches/commonification/tuxtype/trunk/src/loaders.c
   branches/commonification/tuxtype/trunk/src/playgame.c
   branches/commonification/tuxtype/trunk/src/practice.c
   branches/commonification/tuxtype/trunk/src/scripting.c
   branches/commonification/tuxtype/trunk/src/theme.c
   branches/commonification/tuxtype/trunk/src/titlescreen.c
Log:
all backgrounds in TuxType are now loaded via fileops_media

Modified: branches/commonification/tuxtype/trunk/src/SDL_extras.h
===================================================================
--- branches/commonification/tuxtype/trunk/src/SDL_extras.h	2009-08-09 00:04:36 UTC (rev 1403)
+++ branches/commonification/tuxtype/trunk/src/SDL_extras.h	2009-08-09 18:58:22 UTC (rev 1404)
@@ -72,6 +72,9 @@
 SDL_Surface* Flip(SDL_Surface *in, int x, int y);
 int  inRect(SDL_Rect r, int x, int y);
 void DarkenScreen(Uint8 bits);
+void SetRect(SDL_Rect* rect, const float* pos);
+void UpdateRect(SDL_Surface* surf, SDL_Rect* rect);
+void FreeSurfaceArray(SDL_Surface** surfs, int length);
 void SwitchScreenMode(void);
 int WaitForKeypress(void);
 SDL_Surface* Blend(SDL_Surface *S1, SDL_Surface *S2, float gamma);

Modified: branches/commonification/tuxtype/trunk/src/fileops_media.c
===================================================================
--- branches/commonification/tuxtype/trunk/src/fileops_media.c	2009-08-09 00:04:36 UTC (rev 1403)
+++ branches/commonification/tuxtype/trunk/src/fileops_media.c	2009-08-09 18:58:22 UTC (rev 1404)
@@ -1,11 +1,35 @@
 #include "fileops_media.h"
 #include "globals.h"
+#include "funcs.h"
 
 Mix_Chunk* sounds[NUM_SOUNDS] = {NULL};
 Mix_Music* musics[NUM_MUSICS] = {NULL};
 
 static char fn[1024];
 
+static char* background_filenames[NUM_BKGS] = {
+  "/images/pract.png",
+  "/images/kcas1_1.jpg",
+  "/images/kcas1_2.jpg",
+  "/images/kcas1_3.jpg",
+  "/images/kcas1_4.jpg",
+  "/images/kcas2_1.jpg",
+  "/images/kcas2_2.jpg",
+  "/images/kcas2_3.jpg",
+  "/images/kcas2_4.jpg",
+  "/images/kcas3_1.jpg",
+  "/images/kcas3_2.jpg",
+  "/images/kcas3_3.jpg",
+  "/images/kcas3_4.jpg",
+  "/images/hidden.jpg",
+  "/images/main_bkg.jpg",
+  "/images/backgrounds/0.jpg",
+  "/images/backgrounds/1.jpg",
+  "/images/backgrounds/2.jpg",
+  "/images/backgrounds/3.jpg",
+  "/images/backgrounds/4.jpg"
+};
+
 static char* sound_filenames[NUM_SOUNDS] = {
   "/sounds/harp.wav",
   "/sounds/pop.wav",
@@ -36,7 +60,96 @@
   "/sounds/kmus4.wav"
 };
 
+static SDL_Surface* win_bkgd = NULL;
+static SDL_Surface* fullscr_bkgd = NULL;
 
+/**********************
+LoadBothBkgds() : loads two scaled images: one for the user's native
+resolution and one for 640x480 fullscreen.
+Returns: the number of images that were scaled
+**********************/
+int LoadBothBkgds(int id)
+{
+  int ret = 0;
+  SDL_Surface* orig = NULL;
+  char path[PATH_MAX];
+
+  //Avoid memory leak in case something else already loaded:
+  FreeBothBkgds();
+
+  LOG("Entering LoadBothBkgds()\n");
+
+  if(!settings.use_english)
+  {
+    sprintf(path, "%s%s", settings.theme_data_path, background_filenames[id]);
+    orig = LoadImage(path, IMG_REGULAR);
+  }
+
+  if(NULL == orig)
+  {
+    sprintf(path, "%s%s", settings.default_data_path, background_filenames[id]);
+    orig = LoadImage(path, IMG_REGULAR);
+  }
+
+  DEBUGCODE(debug_loaders)
+  {
+     printf("Scaling %dx%d to: %dx%d, %dx%d\n",
+           orig->w, orig->h, RES_X, RES_Y, fs_res_x, fs_res_y);
+  }
+
+  if (orig->w == RES_X && orig->h == RES_Y)
+  {
+    win_bkgd = orig;
+  }
+  else
+  {
+    win_bkgd = zoom(orig, RES_X, RES_Y);
+    ++ret;
+  }
+
+  if (orig->w == fs_res_x && orig->h == fs_res_y)
+  {
+    fullscr_bkgd = orig;
+  }
+  else
+  {
+    fullscr_bkgd = zoom(orig, fs_res_x, fs_res_y);
+    ++ret;
+  }
+
+  if (ret == 2) //orig won't be used at all
+    SDL_FreeSurface(orig);
+
+  DEBUGCODE(debug_loaders)
+  {
+    printf("%d images scaled\nLeaving LoadBothBkgds()\n", ret);
+  }
+  return ret;
+}
+
+
+SDL_Surface* CurrentBkgd(void)
+{
+  if (!screen)
+    return NULL;
+  if (screen->flags & SDL_FULLSCREEN)
+    return fullscr_bkgd;
+  else
+    return win_bkgd;
+}
+
+void FreeBothBkgds(void)
+{
+  if (win_bkgd)
+    SDL_FreeSurface(win_bkgd);
+  win_bkgd = NULL;
+
+  if (fullscr_bkgd)
+    SDL_FreeSurface(fullscr_bkgd);
+  fullscr_bkgd = NULL;
+}
+
+
 int LoadSoundData()
 {
   int i;

Modified: branches/commonification/tuxtype/trunk/src/fileops_media.h
===================================================================
--- branches/commonification/tuxtype/trunk/src/fileops_media.h	2009-08-09 00:04:36 UTC (rev 1403)
+++ branches/commonification/tuxtype/trunk/src/fileops_media.h	2009-08-09 18:58:22 UTC (rev 1404)
@@ -1,9 +1,34 @@
 #ifndef FILEOPS_MEDIA_H
 #define FILEOPS_MEDIA_H
 
+#include "SDL.h"
 #include "SDL_mixer.h"
 
 enum {
+  BKG_PRACTICE,
+  BKG_CAS_11,
+  BKG_CAS_12,
+  BKG_CAS_13,
+  BKG_CAS_14,
+  BKG_CAS_21,
+  BKG_CAS_22,
+  BKG_CAS_23,
+  BKG_CAS_24,
+  BKG_CAS_31,
+  BKG_CAS_32,
+  BKG_CAS_33,
+  BKG_CAS_34,
+  BKG_HIDDEN,
+  BKG_MAIN,
+  BKG_0,
+  BKG_1,
+  BKG_2,
+  BKG_3,
+  BKG_4,
+  NUM_BKGS
+};
+
+enum {
   SND_HARP,
   SND_POP,
   SND_LASER,
@@ -38,7 +63,11 @@
 extern Mix_Chunk* sounds[NUM_SOUNDS];
 extern Mix_Music* musics[NUM_MUSICS];
 
-int LoadSoundData();
-void UnloadSoundData();
+int          LoadSoundData();
+void         UnloadSoundData();
 
+int          LoadBothBkgds(int id);
+SDL_Surface* CurrentBkgd(void);
+void         FreeBothBkgds(void);
+
 #endif

Modified: branches/commonification/tuxtype/trunk/src/funcs.h
===================================================================
--- branches/commonification/tuxtype/trunk/src/funcs.h	2009-08-09 00:04:36 UTC (rev 1403)
+++ branches/commonification/tuxtype/trunk/src/funcs.h	2009-08-09 18:58:22 UTC (rev 1404)
@@ -86,9 +86,6 @@
 Mix_Chunk*   LoadSoundNoPrefix( char *datafile);
 Mix_Music*   LoadMusicNoPrefix(char *datafile);
 
-int          LoadBothBkgds(const char* datafile);
-SDL_Surface* CurrentBkgd(void);
-void         FreeBothBkgds(void);
 void         LoadLang(void);
 
 #ifndef HAVE_LIBT4KCOMMON

Modified: branches/commonification/tuxtype/trunk/src/laser.c
===================================================================
--- branches/commonification/tuxtype/trunk/src/laser.c	2009-08-09 00:04:36 UTC (rev 1403)
+++ branches/commonification/tuxtype/trunk/src/laser.c	2009-08-09 18:58:22 UTC (rev 1404)
@@ -733,7 +733,6 @@
 
 static void laser_reset_level(int diff_level)
 {
-  char fname[1024];
   static int last_bkgd = -1;
   int i;
   
@@ -755,23 +754,8 @@
 
   DOUT(i);
 
-  sprintf(fname, "/images/backgrounds/%d.jpg", i);
+  LoadBothBkgds(BKG_0 + i);
 
-  DEBUGCODE(debug_laser) { fprintf(stderr, "Will try to load file:\t%s", fname); }
-
-  FreeBothBkgds(); // LoadBothBkgds() actually does this just in case
-
-  LoadBothBkgds(fname);
-
-  if (CurrentBkgd() == NULL)
-  {
-    fprintf(stderr,
-     "\nWarning: Could not load background image:\n"
-     "%s\n"
-     "The Simple DirectMedia error that ocurred was: %s\n",
-     fname, SDL_GetError());
-  }
-
   /* Record score before this wave: */
 
   pre_wave_score = score;

Modified: branches/commonification/tuxtype/trunk/src/loaders.c
===================================================================
--- branches/commonification/tuxtype/trunk/src/loaders.c	2009-08-09 00:04:36 UTC (rev 1403)
+++ branches/commonification/tuxtype/trunk/src/loaders.c	2009-08-09 18:58:22 UTC (rev 1404)
@@ -48,8 +48,6 @@
 sprite*         load_sprite(const char* name, int mode, int w, int h, bool proportional);
 
 
-static SDL_Surface* win_bkgd = NULL;
-static SDL_Surface* fullscr_bkgd = NULL;
 
 /* FIXME: these functions are just ugly workarounds for loading images without
    given data prefix. Data Prefixes are handled differently in TuxType and TuxMath,
@@ -193,82 +191,6 @@
 
   return;
 }
-
-/**********************
-LoadBothBkgds() : loads two scaled images: one for the user's native 
-resolution and one for 640x480 fullscreen. 
-Returns: the number of images that were scaled
-**********************/
-int LoadBothBkgds(const char* datafile)
-{
-  int ret = 0;
-  SDL_Surface* orig = NULL;
-  
-  //Avoid memory leak in case something else already loaded:
-  FreeBothBkgds();
-
-  LOG("Entering LoadBothBkgds()\n");
-
-  orig = LoadImageNoPrefix(datafile, IMG_REGULAR);
-
-  DEBUGCODE(debug_loaders)
-  {
-     printf("Scaling %dx%d to: %dx%d, %dx%d\n", 
-           orig->w, orig->h, RES_X, RES_Y, fs_res_x, fs_res_y);
-  }
-
-  if (orig->w == RES_X && orig->h == RES_Y)
-  {
-    win_bkgd = orig;
-  }
-  else
-  {
-    win_bkgd = zoom(orig, RES_X, RES_Y);
-    ++ret;
-  }
-  
-  if (orig->w == fs_res_x && orig->h == fs_res_y)
-  {
-    fullscr_bkgd = orig;
-  }
-  else
-  {
-    fullscr_bkgd = zoom(orig, fs_res_x, fs_res_y);
-    ++ret;
-  }
-  
-  if (ret == 2) //orig won't be used at all
-    SDL_FreeSurface(orig);
-    
-  DEBUGCODE(debug_loaders)
-  {
-    printf("%d images scaled\nLeaving LoadBothBkgds()\n", ret);
-  }
-  return ret;
-}
-
-
-SDL_Surface* CurrentBkgd(void)
-{
-  if (!screen)
-    return NULL;
-  if (screen->flags & SDL_FULLSCREEN)
-    return fullscr_bkgd;
-  else
-    return win_bkgd;
-}
-
-void FreeBothBkgds(void)
-{
-  if (win_bkgd)
-    SDL_FreeSurface(win_bkgd);
-  win_bkgd = NULL;
-
-  if (fullscr_bkgd)
-    SDL_FreeSurface(fullscr_bkgd);
-  fullscr_bkgd = NULL;
-}
-
 #ifndef HAVE_LIBT4KCOMMON
 
 int CheckFile(const char* file)

Modified: branches/commonification/tuxtype/trunk/src/playgame.c
===================================================================
--- branches/commonification/tuxtype/trunk/src/playgame.c	2009-08-09 00:04:36 UTC (rev 1403)
+++ branches/commonification/tuxtype/trunk/src/playgame.c	2009-08-09 18:58:22 UTC (rev 1404)
@@ -125,7 +125,7 @@
 
 //	SNOW_init();
 
-  LoadTuxAnims(); 
+  LoadTuxAnims();
   LoadFishies();
   LoadOthers();
 
@@ -185,27 +185,18 @@
       /* ------- Load and draw background: ----------------- */
 
       if (curlevel != 0)
-      {
         FreeBothBkgds();
-      }
 
       if (diflevel == INF_PRACT)
-        sprintf(filename, "/images/pract.png");
+        LoadBothBkgds(BKG_PRACTICE);
       else
-        sprintf(filename, "/images/kcas%i_%i.jpg", diflevel+1, curlevel+1);
+        LoadBothBkgds(BKG_CAS_11 + diflevel * 4 + curlevel);
 
       /* ---  Special Hidden Code  --- */
 
       if (settings.hidden && curlevel == 3)
-        sprintf(filename, "/images/hidden.jpg");
+        LoadBothBkgds(BKG_HIDDEN);
 
-      DEBUGCODE(debug_game)
-      {
-        fprintf(stderr, "->>Loading background: %s\n", filename);
-      }
-        LoadBothBkgds(filename);
-//			SNOW_setBkg( background );
-
       DrawBackground();
 
       ResetObjects();

Modified: branches/commonification/tuxtype/trunk/src/practice.c
===================================================================
--- branches/commonification/tuxtype/trunk/src/practice.c	2009-08-09 00:04:36 UTC (rev 1403)
+++ branches/commonification/tuxtype/trunk/src/practice.c	2009-08-09 18:58:22 UTC (rev 1404)
@@ -856,7 +856,7 @@
 
 
   /* load needed SDL_Surfaces: */
-  LoadBothBkgds("/images/main_bkg.png");
+  LoadBothBkgds(BKG_MAIN);
   hands = LoadImageNoPrefix("/images/hands/hands.png", IMG_ALPHA);
   hand_shift[0] = LoadImageNoPrefix("/images/hands/none.png", IMG_ALPHA);
   hand_shift[1] = LoadImageNoPrefix("/images/hands/lshift.png", IMG_ALPHA);

Modified: branches/commonification/tuxtype/trunk/src/scripting.c
===================================================================
--- branches/commonification/tuxtype/trunk/src/scripting.c	2009-08-09 00:04:36 UTC (rev 1403)
+++ branches/commonification/tuxtype/trunk/src/scripting.c	2009-08-09 18:58:22 UTC (rev 1404)
@@ -20,6 +20,7 @@
 #define MAX_LESSONS 100
 #include "SDL_extras.h"
 #include "convert_utf.h"
+#include "fileops_media.h"
 
 /* Local function prototypes: */
 static void clear_items(itemType* i);
@@ -220,7 +221,7 @@
 
   left = LoadImageNoPrefix("/images/left.png", IMG_ALPHA);
   right = LoadImageNoPrefix("/images/right.png", IMG_ALPHA);
-  LoadBothBkgds("/images/main_bkg.png");
+  LoadBothBkgds(BKG_MAIN);
 
   /* Get out if needed surface not loaded successfully: */
   if (!CurrentBkgd() || !left || !right)

Modified: branches/commonification/tuxtype/trunk/src/theme.c
===================================================================
--- branches/commonification/tuxtype/trunk/src/theme.c	2009-08-09 00:04:36 UTC (rev 1403)
+++ branches/commonification/tuxtype/trunk/src/theme.c	2009-08-09 18:58:22 UTC (rev 1404)
@@ -19,6 +19,7 @@
 #include "globals.h"
 #include "funcs.h"
 #include "SDL_extras.h"
+#include "fileops_media.h"
 
 
 #define MAX_LANGUAGES 100
@@ -105,7 +106,7 @@
     select[i] = BlackOutline( themeNames[i], DEFAULT_MENU_FONT_SIZE, &yellow);
   }
 
-  LoadBothBkgds("/images/main_bkg.png");
+  LoadBothBkgds(BKG_MAIN);
 
   world = LoadImageNoPrefix("/images/world.png", IMG_ALPHA);
   left = LoadImageNoPrefix("/images/left.png", IMG_ALPHA);

Modified: branches/commonification/tuxtype/trunk/src/titlescreen.c
===================================================================
--- branches/commonification/tuxtype/trunk/src/titlescreen.c	2009-08-09 00:04:36 UTC (rev 1403)
+++ branches/commonification/tuxtype/trunk/src/titlescreen.c	2009-08-09 18:58:22 UTC (rev 1404)
@@ -59,7 +59,6 @@
   (together with menu.c constants ? ) */
 const float title_pos[4] = {0.0, 0.0, 0.3, 0.25};
 const float tux_pos[4]   = {0.0, 0.6, 0.3, 0.4};
-const char* bkg_path     = "/images/main_bkg.jpg";
 const char* standby_path = "/images/status/standby.svg";
 const char* title_path   = "/images/title1.svg";
 const char* egg_path     = "/images/title/egg.svg";
@@ -90,9 +89,6 @@
 /* --- other media --- */
 static SDL_Surface* speaker = NULL;
 static SDL_Surface* speakeroff = NULL;
-static Mix_Chunk* snd_move = NULL;
-static Mix_Chunk* snd_select = NULL;
-static Mix_Chunk* snd_welcome = NULL; 
 
 /* Local function prototypes: */
 static void    show_logo(void);
@@ -157,7 +153,7 @@
 
   LOG( "->Now Animating Tux and Title onto the screen\n" );
 
-  LoadBothBkgds(bkg_path);
+  LoadBothBkgds(BKG_MAIN);
 
   /* load menus */
   SetActivitiesList(N_OF_ACTIVITIES, activities);
@@ -283,7 +279,6 @@
    returns 1 on success, 0 on failure */
 int RenderTitleScreen(void)
 {
-  SDL_Surface* new_bkg = NULL;
   char* path;
 
   if(curr_res_x != screen->w || curr_res_y != screen->h)
@@ -293,19 +288,7 @@
 
     /* we keep two backgrounds to make screen mode switch faster */
     if(CurrentBkgd()->w != screen->w || CurrentBkgd()->h != screen->h)
-    {
-      new_bkg = LoadBkgd(bkg_path, screen->w, screen->h);
-      if(new_bkg == NULL)
-      {
-        DEBUGMSG(debug_titlescreen, "RenderTitleScreen(): Failed to load new background.\n");
-        return 0;
-      }
-      else
-      {
-        DEBUGMSG(debug_titlescreen, "RenderTitleScreen(): New background loaded.\n");
-        //set_current_bkg(new_bkg);
-      }
-    }
+      LoadBothBkgds(BKG_MAIN);
 
     DEBUGMSG(debug_titlescreen, "Re-rendering titlescreen items.\n");
     bkg_rect = CurrentBkgd()->clip_rect;
@@ -442,13 +425,13 @@
             break;
           case 1:
             PlayCascade(MEDIUM);
-           break;
-         case 2:
-           PlayCascade(HARD);
-           break;
-         case 3:
-           PlayCascade(INSANE);
-           break;
+            break;
+          case 2:
+            PlayCascade(HARD);
+            break;
+          case 3:
+            PlayCascade(INSANE);
+            break;
         }
       }
       break;
@@ -483,7 +466,7 @@
   }
 
   FreeBothBkgds();
-  LoadBothBkgds(bkg_path);
+  LoadBothBkgds(BKG_MAIN);
   SDL_ShowCursor(1);
   AudioMusicLoad(full_menu_music_path, -1);
   return 0;




More information about the Tux4kids-commits mailing list