- converted texture_type into a Surface class
authorIngo Ruhnke <grumbel@gmx.de>
Tue, 13 Apr 2004 02:19:13 +0000 (02:19 +0000)
committerIngo Ruhnke <grumbel@gmx.de>
Tue, 13 Apr 2004 02:19:13 +0000 (02:19 +0000)
SVN-Revision: 514

37 files changed:
src/Makefile.am
src/badguy.cpp
src/badguy.h
src/button.cpp
src/button.h
src/gameloop.cpp
src/gameobjs.cpp
src/gameobjs.h
src/high_scores.cpp
src/intro.cpp
src/level.cpp
src/level.h
src/leveleditor.cpp
src/menu.cpp
src/menu.h
src/mousecursor.cpp
src/mousecursor.h
src/particlesystem.cpp
src/particlesystem.h
src/player.cpp
src/player.h
src/resources.cpp
src/resources.h
src/setup.cpp
src/special.cpp
src/sprite.cpp
src/sprite.h
src/text.cpp
src/text.h
src/texture.cpp
src/texture.h
src/tile.cpp
src/tile.h
src/title.cpp
src/world.cpp
src/worldmap.cpp
src/worldmap.h

index e4fe095..81d52a6 100644 (file)
@@ -18,8 +18,6 @@ globals.cpp \
 globals.h \
 high_scores.cpp \
 high_scores.h \
-intro.cpp \
-intro.h \
 level.cpp \
 level.h \
 leveleditor.cpp \
index c1a2ddf..9a0e681 100644 (file)
 #include "world.h"
 #include "tile.h"
 
-texture_type img_bsod_squished_left[1];
-texture_type img_bsod_squished_right[1];
-texture_type img_bsod_falling_left[1];
-texture_type img_bsod_falling_right[1];
-texture_type img_laptop_flat_left[1];
-texture_type img_laptop_flat_right[1];
-texture_type img_laptop_falling_left[1];
-texture_type img_laptop_falling_right[1];
-texture_type img_bsod_left[4];
-texture_type img_bsod_right[4];
-texture_type img_laptop_left[4];
-texture_type img_laptop_right[4];
-texture_type img_money_left[2];
-texture_type img_money_right[2];
-texture_type img_mrbomb_left[4];
-texture_type img_mrbomb_right[4];
-texture_type img_mrbomb_ticking_left[1];
-texture_type img_mrbomb_ticking_right[1];
-texture_type img_mrbomb_explosion[1];
-texture_type img_stalactite[1];
-texture_type img_stalactite_broken[1];
-texture_type img_flame[2];
-texture_type img_fish[2];
-texture_type img_bouncingsnowball_left[6];
-texture_type img_bouncingsnowball_right[6];
-texture_type img_bouncingsnowball_squished[1];
-texture_type img_flyingsnowball[2];
-texture_type img_flyingsnowball_squished[1];
-texture_type img_spiky_left[3];
-texture_type img_spiky_right[3];
-texture_type img_snowball_left[4];
-texture_type img_snowball_right[4];
-texture_type img_snowball_squished_left[1];
-texture_type img_snowball_squished_right[1];
+Surface* img_bsod_squished_left[1];
+Surface* img_bsod_squished_right[1];
+Surface* img_bsod_falling_left[1];
+Surface* img_bsod_falling_right[1];
+Surface* img_laptop_flat_left[1];
+Surface* img_laptop_flat_right[1];
+Surface* img_laptop_falling_left[1];
+Surface* img_laptop_falling_right[1];
+Surface* img_bsod_left[4];
+Surface* img_bsod_right[4];
+Surface* img_laptop_left[4];
+Surface* img_laptop_right[4];
+Surface* img_money_left[2];
+Surface* img_money_right[2];
+Surface* img_mrbomb_left[4];
+Surface* img_mrbomb_right[4];
+Surface* img_mrbomb_ticking_left[1];
+Surface* img_mrbomb_ticking_right[1];
+Surface* img_mrbomb_explosion[1];
+Surface* img_stalactite[1];
+Surface* img_stalactite_broken[1];
+Surface* img_flame[2];
+Surface* img_fish[2];
+Surface* img_bouncingsnowball_left[6];
+Surface* img_bouncingsnowball_right[6];
+Surface* img_bouncingsnowball_squished[1];
+Surface* img_flyingsnowball[2];
+Surface* img_flyingsnowball_squished[1];
+Surface* img_spiky_left[3];
+Surface* img_spiky_right[3];
+Surface* img_snowball_left[4];
+Surface* img_snowball_right[4];
+Surface* img_snowball_squished_left[1];
+Surface* img_snowball_squished_right[1];
 
 BadGuyKind  badguykind_from_string(const std::string& str)
 {
@@ -741,27 +741,27 @@ BadGuy::draw()
   float global_frame = (float(global_frame_counter - animation_offset) / 10);
   global_frame *= animation_speed;
   size_t frame = size_t(global_frame) % animation_length;
-  texture_type* texture = 
-      (dir == LEFT) ? &texture_left[frame] : &texture_right[frame];
-  texture_draw(texture, base.x - scroll_x, base.y);
+  Surface* texture = 
+      (dir == LEFT) ? texture_left[frame] : texture_right[frame];
+  texture->draw(base.x - scroll_x, base.y);
 
   if (debug_mode)
     fillrect(base.x - scroll_x, base.y, 32, 32, 75,0,75, 150);
 }
 
 void
-BadGuy::set_texture(texture_type* left, texture_type* right,
+BadGuy::set_texture(Surface** left, Surface** right,
     int nanimlength, float nanimspeed)
 {
   if(left != 0) {
     if(base.width == 0 && base.height == 0) {
-      base.width = left->w;
-      base.height = left->h;
-    } else if(base.width != left->w || base.height != left->h) {
-      base.x -= (left->w - base.width) / 2;
-      base.y -= left->h - base.height;
-      base.width = left->w;
-      base.height = left->h;
+      base.width = left[0]->w;
+      base.height = left[0]->h;
+    } else if(base.width != left[0]->w || base.height != left[0]->h) {
+      base.x -= (left[0]->w - base.width) / 2;
+      base.y -= left[0]->h - base.height;
+      base.width = left[0]->w;
+      base.height = left[0]->h;
       old_base = base;
     }
   } else {
@@ -949,99 +949,97 @@ BadGuy::collision(void *p_c_object, int c_object, CollisionType type)
 void load_badguy_gfx()
 {
   /* (BSOD) */
-  texture_load(&img_bsod_left[0], datadir +
-               "/images/shared/bsod-left-0.png",
-               USE_ALPHA);
+  img_bsod_left[0] = new Surface(datadir + "/images/shared/bsod-left-0.png", USE_ALPHA);
 
-  texture_load(&img_bsod_left[1], datadir +
+  img_bsod_left[1] = new Surface(datadir +
                "/images/shared/bsod-left-1.png",
                USE_ALPHA);
 
-  texture_load(&img_bsod_left[2], datadir +
+  img_bsod_left[2] = new Surface(datadir +
                "/images/shared/bsod-left-2.png",
                USE_ALPHA);
 
-  texture_load(&img_bsod_left[3], datadir +
+  img_bsod_left[3] = new Surface(datadir +
                "/images/shared/bsod-left-3.png",
                USE_ALPHA);
 
-  texture_load(&img_bsod_right[0], datadir +
+  img_bsod_right[0] = new Surface(datadir +
                "/images/shared/bsod-right-0.png",
                USE_ALPHA);
 
-  texture_load(&img_bsod_right[1], datadir +
+  img_bsod_right[1] = new Surface(datadir +
                "/images/shared/bsod-right-1.png",
                USE_ALPHA);
 
-  texture_load(&img_bsod_right[2], datadir +
+  img_bsod_right[2] = new Surface(datadir +
                "/images/shared/bsod-right-2.png",
                USE_ALPHA);
 
-  texture_load(&img_bsod_right[3], datadir +
+  img_bsod_right[3] = new Surface(datadir +
                "/images/shared/bsod-right-3.png",
                USE_ALPHA);
 
-  texture_load(&img_bsod_squished_left[0], datadir +
+  img_bsod_squished_left[0] = new Surface(datadir +
                "/images/shared/bsod-squished-left.png",
                USE_ALPHA);
 
-  texture_load(&img_bsod_squished_right[0], datadir +
+  img_bsod_squished_right[0] = new Surface(datadir +
                "/images/shared/bsod-squished-right.png",
                USE_ALPHA);
 
-  texture_load(&img_bsod_falling_left[0], datadir +
+  img_bsod_falling_left[0] = new Surface(datadir +
                "/images/shared/bsod-falling-left.png",
                USE_ALPHA);
 
-  texture_load(&img_bsod_falling_right[0], datadir +
+  img_bsod_falling_right[0] = new Surface(datadir +
                "/images/shared/bsod-falling-right.png",
                USE_ALPHA);
 
 
   /* (Laptop) */
 
-  texture_load(&img_laptop_left[0], datadir + "/images/shared/mriceblock-left-0.png", USE_ALPHA);
-  texture_load(&img_laptop_left[1], datadir + "/images/shared/mriceblock-left-1.png", USE_ALPHA);
-  texture_load(&img_laptop_left[2], datadir + "/images/shared/mriceblock-left-2.png", USE_ALPHA);
-  texture_load(&img_laptop_left[3], datadir + "/images/shared/mriceblock-left-1.png", USE_ALPHA);
+  img_laptop_left[0] = new Surface(datadir + "/images/shared/mriceblock-left-0.png", USE_ALPHA);
+  img_laptop_left[1] = new Surface(datadir + "/images/shared/mriceblock-left-1.png", USE_ALPHA);
+  img_laptop_left[2] = new Surface(datadir + "/images/shared/mriceblock-left-2.png", USE_ALPHA);
+  img_laptop_left[3] = new Surface(datadir + "/images/shared/mriceblock-left-1.png", USE_ALPHA);
 
-  texture_load(&img_laptop_right[0], datadir + "/images/shared/mriceblock-right-0.png", USE_ALPHA);
-  texture_load(&img_laptop_right[1], datadir + "/images/shared/mriceblock-right-1.png", USE_ALPHA);
-  texture_load(&img_laptop_right[2], datadir + "/images/shared/mriceblock-right-2.png", USE_ALPHA);
-  texture_load(&img_laptop_right[3], datadir + "/images/shared/mriceblock-right-1.png", USE_ALPHA);
+  img_laptop_right[0] = new Surface(datadir + "/images/shared/mriceblock-right-0.png", USE_ALPHA);
+  img_laptop_right[1] = new Surface(datadir + "/images/shared/mriceblock-right-1.png", USE_ALPHA);
+  img_laptop_right[2] = new Surface(datadir + "/images/shared/mriceblock-right-2.png", USE_ALPHA);
+  img_laptop_right[3] = new Surface(datadir + "/images/shared/mriceblock-right-1.png", USE_ALPHA);
   
-  texture_load(&img_laptop_flat_left[0], 
+  img_laptop_flat_left[0] = new Surface(
                datadir + "/images/shared/laptop-flat-left.png",
                USE_ALPHA);
 
-  texture_load(&img_laptop_flat_right[0], datadir +
+  img_laptop_flat_right[0] = new Surface(datadir +
                "/images/shared/laptop-flat-right.png",
                USE_ALPHA);
 
-  texture_load(&img_laptop_falling_left[0], datadir +
+  img_laptop_falling_left[0] = new Surface(datadir +
                "/images/shared/laptop-falling-left.png",
                USE_ALPHA);
 
-  texture_load(&img_laptop_falling_right[0], datadir +
+  img_laptop_falling_right[0] = new Surface(datadir +
                "/images/shared/laptop-falling-right.png",
                USE_ALPHA);
 
 
   /* (Money) */
 
-  texture_load(&img_money_left[0], datadir +
+  img_money_left[0] = new Surface(datadir +
                "/images/shared/bag-left-0.png",
                USE_ALPHA);
 
-  texture_load(&img_money_left[1], datadir +
+  img_money_left[1] = new Surface(datadir +
                "/images/shared/bag-left-1.png",
                USE_ALPHA);
 
-  texture_load(&img_money_right[0], datadir +
+  img_money_right[0] = new Surface(datadir +
                "/images/shared/bag-right-0.png",
                USE_ALPHA);
 
-  texture_load(&img_money_right[1], datadir +
+  img_money_right[1] = new Surface(datadir +
                "/images/shared/bag-right-1.png",
                USE_ALPHA);
 
@@ -1049,84 +1047,84 @@ void load_badguy_gfx()
   for(int i=0; i<4; ++i) {
       char num[4];
       snprintf(num, 4, "%d", i);
-      texture_load(&img_mrbomb_left[i],
+      img_mrbomb_left[i] = new Surface(
               datadir + "/images/shared/mrbomb-left-" + num + ".png", USE_ALPHA);
-      texture_load(&img_mrbomb_right[i],
+      img_mrbomb_right[i] = new Surface(
               datadir + "/images/shared/mrbomb-right-" + num + ".png", USE_ALPHA);
   }
-  texture_load(&img_mrbomb_ticking_left[0],
+  img_mrbomb_ticking_left[0] = new Surface(
           datadir + "/images/shared/mrbombx-left-0.png", USE_ALPHA);
-  texture_load(&img_mrbomb_ticking_right[0],
+  img_mrbomb_ticking_right[0] = new Surface(
           datadir + "/images/shared/mrbombx-right-0.png", USE_ALPHA);
-  texture_load(&img_mrbomb_explosion[0],
+  img_mrbomb_explosion[0] = new Surface(
           datadir + "/images/shared/mrbomb-explosion.png", USE_ALPHA);
 
   /* stalactite */
-  texture_load(&img_stalactite[0], 
+  img_stalactite[0] = new Surface(
           datadir + "/images/shared/stalactite.png", USE_ALPHA);
-  texture_load(&img_stalactite_broken[0],
+  img_stalactite_broken[0] = new Surface(
           datadir + "/images/shared/stalactite-broken.png", USE_ALPHA);
 
   /* flame */
-  texture_load(&img_flame[0],
+  img_flame[0] = new Surface(
           datadir + "/images/shared/flame-0.png", USE_ALPHA);
-  texture_load(&img_flame[1],
+  img_flame[1] = new Surface(
           datadir + "/images/shared/flame-1.png", USE_ALPHA);  
 
   /* fish */
-  texture_load(&img_fish[0],
+  img_fish[0] = new Surface(
           datadir + "/images/shared/fish-left-0.png", USE_ALPHA);
-  texture_load(&img_fish[1],
+  img_fish[1] = new Surface(
           datadir + "/images/shared/fish-left-1.png", USE_ALPHA);
 
   /* bouncing snowball */
   for(int i=0; i<6; ++i) {
       char num[4];
       snprintf(num, 4, "%d", i);
-      texture_load(&img_bouncingsnowball_left[i],
+      img_bouncingsnowball_left[i] = new Surface(
               datadir + "/images/shared/bouncingsnowball-left-" + num + ".png",
               USE_ALPHA);
-      texture_load(&img_bouncingsnowball_right[i],
+      img_bouncingsnowball_right[i] = new Surface(
               datadir + "/images/shared/bouncingsnowball-right-" + num + ".png",
               USE_ALPHA);
   } 
-  texture_load(&img_bouncingsnowball_squished[0],
+  img_bouncingsnowball_squished[0] = new Surface(
           datadir + "/images/shared/bsod-squished-left.png", USE_ALPHA);
 
   /* flying snowball */
-  texture_load(&img_flyingsnowball[0],
+  img_flyingsnowball[0] = new Surface(
           datadir + "/images/shared/flyingsnowball-left-0.png", USE_ALPHA);
-  texture_load(&img_flyingsnowball[1],
+  img_flyingsnowball[1] = new Surface(
           datadir + "/images/shared/flyingsnowball-left-1.png", USE_ALPHA);  
-  texture_load(&img_flyingsnowball_squished[0],
+  img_flyingsnowball_squished[0] = new Surface(
           datadir + "/images/shared/bsod-squished-left.png", USE_ALPHA);
 
   /* spiky */
   for(int i = 0; i < 3; ++i) {
         char num[4];
         snprintf(num, 4, "%d", i);
-        texture_load(&img_spiky_left[i],                                 
+        img_spiky_left[i] = new Surface(                                
                 datadir + "/images/shared/spiky-left-" + num + ".png",   
                 USE_ALPHA);
-        texture_load(&img_spiky_right[i],
+        img_spiky_right[i] = new Surface(
                 datadir + "/images/shared/spiky-right-" + num + ".png",
                 USE_ALPHA);
   }
 
   /** snowball */
-  texture_load(&img_snowball_left[0], datadir + "/images/shared/snowball-left-0.png", USE_ALPHA);
-  texture_load(&img_snowball_left[1], datadir + "/images/shared/snowball-left-1.png", USE_ALPHA);
-  texture_load(&img_snowball_left[2], datadir + "/images/shared/snowball-left-2.png", USE_ALPHA);
-  texture_load(&img_snowball_left[3], datadir + "/images/shared/snowball-left-1.png", USE_ALPHA);
+  img_snowball_left[0] = new Surface(datadir + "/images/shared/snowball-left-0.png", USE_ALPHA);
+  img_snowball_left[1] = new Surface(datadir + "/images/shared/snowball-left-1.png", USE_ALPHA);
+  img_snowball_left[2] = new Surface(datadir + "/images/shared/snowball-left-2.png", USE_ALPHA);
+  img_snowball_left[3] = new Surface(datadir + "/images/shared/snowball-left-1.png", USE_ALPHA);
 
-  texture_load(&img_snowball_right[0], datadir + "/images/shared/snowball-right-0.png", USE_ALPHA);
-  texture_load(&img_snowball_right[1], datadir + "/images/shared/snowball-right-1.png", USE_ALPHA);
-  texture_load(&img_snowball_right[2], datadir + "/images/shared/snowball-right-2.png", USE_ALPHA);
-  texture_load(&img_snowball_right[3], datadir + "/images/shared/snowball-right-1.png", USE_ALPHA);
+  img_snowball_right[0] = new Surface(datadir + "/images/shared/snowball-right-0.png", USE_ALPHA);
+  img_snowball_right[1] = new Surface(datadir + "/images/shared/snowball-right-1.png", USE_ALPHA);
+  img_snowball_right[2] = new Surface(datadir + "/images/shared/snowball-right-2.png", USE_ALPHA);
+  img_snowball_right[3] = new Surface(datadir + "/images/shared/snowball-right-1.png", USE_ALPHA);
 
-  texture_load(&img_snowball_squished_left[0],
+  img_snowball_squished_left[0] = new Surface(
           datadir + "/images/shared/bsod-squished-left.png", USE_ALPHA);
-  texture_load(&img_snowball_squished_right[0],
+  img_snowball_squished_right[0] = new Surface(
           datadir + "/images/shared/bsod-squished-right.png", USE_ALPHA);  
 }
 
@@ -1134,72 +1132,72 @@ void free_badguy_gfx()
 {
   for (int i = 0; i < 4; i++)
     {
-      texture_free(&img_bsod_left[i]);
-      texture_free(&img_bsod_right[i]);
+      delete img_bsod_left[i];
+      delete img_bsod_right[i];
     }
 
-  texture_free(&img_bsod_squished_left[0]);
-  texture_free(&img_bsod_squished_right[0]);
+  delete img_bsod_squished_left[0];
+  delete img_bsod_squished_right[0];
 
-  texture_free(&img_bsod_falling_left[0]);
-  texture_free(&img_bsod_falling_right[0]);
+  delete img_bsod_falling_left[0];
+  delete img_bsod_falling_right[0];
 
   for (int i = 0; i < 4; i++)
     {
-      texture_free(&img_laptop_left[i]);
-      texture_free(&img_laptop_right[i]);
+      delete img_laptop_left[i];
+      delete img_laptop_right[i];
     }
 
-  texture_free(&img_laptop_flat_left[0]);
-  texture_free(&img_laptop_flat_right[0]);
+  delete img_laptop_flat_left[0];
+  delete img_laptop_flat_right[0];
 
-  texture_free(&img_laptop_falling_left[0]);
-  texture_free(&img_laptop_falling_right[0]);
+  delete img_laptop_falling_left[0];
+  delete img_laptop_falling_right[0];
 
   for (int i = 0; i < 2; i++)
     {
-      texture_free(&img_money_left[i]);
-      texture_free(&img_money_right[i]);
+      delete img_money_left[i];
+      delete img_money_right[i];
     }
 
   for(int i = 0; i < 4; i++) {
-      texture_free(&img_mrbomb_left[i]);
-      texture_free(&img_mrbomb_right[i]);
+      delete img_mrbomb_left[i];
+      delete img_mrbomb_right[i];
   }
 
-  texture_free(&img_mrbomb_ticking_left[0]);
-  texture_free(&img_mrbomb_ticking_right[0]);
-  texture_free(&img_mrbomb_explosion[0]);
+  delete img_mrbomb_ticking_left[0];
+  delete img_mrbomb_ticking_right[0];
+  delete img_mrbomb_explosion[0];
 
-  texture_free(&img_stalactite[0]);
-  texture_free(&img_stalactite_broken[0]);
+  delete img_stalactite[0];
+  delete img_stalactite_broken[0];
 
-  texture_free(&img_flame[0]);
-  texture_free(&img_flame[1]);
+  delete img_flame[0];
+  delete img_flame[1];
 
-  texture_free(&img_fish[0]);
-  texture_free(&img_fish[1]);
+  delete img_fish[0];
+  delete img_fish[1];
 
   for(int i=0; i<6; ++i) {
-    texture_free(&img_bouncingsnowball_left[i]);
-    texture_free(&img_bouncingsnowball_right[i]);
+    delete img_bouncingsnowball_left[i];
+    delete img_bouncingsnowball_right[i];
   }
-  texture_free(&img_bouncingsnowball_squished[0]);
+  delete img_bouncingsnowball_squished[0];
 
-  texture_free(&img_flyingsnowball[0]);
-  texture_free(&img_flyingsnowball[1]);
-  texture_free(&img_flyingsnowball_squished[0]);
+  delete img_flyingsnowball[0];
+  delete img_flyingsnowball[1];
+  delete img_flyingsnowball_squished[0];
 
   for(int i = 0; i<3; ++i) {
-    texture_free(&img_spiky_left[i]);
-    texture_free(&img_spiky_right[i]);
+    delete img_spiky_left[i];
+    delete img_spiky_right[i];
   }
   for(int i = 0; i<4; ++i) {
-    texture_free(&img_snowball_left[i]);
-    texture_free(&img_snowball_right[i]);
+    delete img_snowball_left[i];
+    delete img_snowball_right[i];
   }
-  texture_free(&img_snowball_squished_left[0]);
-  texture_free(&img_snowball_squished_right[0])
+  delete img_snowball_squished_left[0];
+  delete img_snowball_squished_right[0]
 }
 
 // EOF //
index 93c9356..f5c93af 100644 (file)
 #include "physic.h"
 #include "collision.h"
 
-extern texture_type img_bsod_left[4];
-extern texture_type img_bsod_right[4];
-extern texture_type img_laptop_left[4];
-extern texture_type img_money_left[2];
+extern Surface* img_bsod_left[4];
+extern Surface* img_bsod_right[4];
+extern Surface* img_laptop_left[4];
+extern Surface* img_money_left[2];
 
 /* Enemy modes: */
 enum {
@@ -99,8 +99,8 @@ private:
   Timer timer;
   Physic physic;
 
-  texture_type* texture_left;
-  texture_type* texture_right;
+  Surface** texture_left;
+  Surface** texture_right;
   int animation_offset;
   size_t animation_length;
   float animation_speed;
@@ -154,7 +154,7 @@ private:
   /** squish ourself, give player score and set dying to DYING_SQICHED */
   void squish_me(Player* player);
   /** set image of the badguy */
-  void set_texture(texture_type* left, texture_type* right,
+  void set_texture(Surface** left, Surface** right,
         int animlength = 1, float animspeed = 1);
 };
 
index d2c184f..6042292 100644 (file)
@@ -38,21 +38,21 @@ Button::Button(std::string icon_file, std::string ninfo, SDLKey nshortcut, int x
 
   if(mw != -1 || mh != -1)
     {
-      texture_load(&icon,filename,USE_ALPHA);
+      icon = new Surface(filename,USE_ALPHA);
       if(mw != -1)
-        icon.w = mw;
+        icon->w = mw;
       if(mh != -1)
-        icon.h = mh;
+        icon->h = mh;
 
       SDL_Rect dest;
       dest.x = 0;
       dest.y = 0;
-      dest.w = icon.w;
-      dest.h = icon.h;
-      SDL_SoftStretch(icon.sdl_surface, NULL, icon.sdl_surface, &dest);
+      dest.w = icon->w;
+      dest.h = icon->h;
+      SDL_SoftStretch(icon->impl->sdl_surface, NULL, icon->impl->sdl_surface, &dest);
     }
   else
-    texture_load(&icon,filename,USE_ALPHA);
+    icon = new Surface(filename,USE_ALPHA);
 
   info = ninfo;
 
@@ -60,8 +60,8 @@ Button::Button(std::string icon_file, std::string ninfo, SDLKey nshortcut, int x
 
   rect.x = x;
   rect.y = y;
-  rect.w = icon.w;
-  rect.h = icon.h;
+  rect.w = icon->w;
+  rect.h = icon->h;
   tag = -1;
   state = BUTTON_NONE;
   show_info = false;
@@ -83,8 +83,8 @@ void Button::change_icon(std::string icon_file, int /*mw*/, int /*mh*/)
       snprintf(filename, 1024, "%s/images/icons/default-icon.png", datadir.c_str());
     }
 
-  texture_free(&icon);
-  texture_load(&icon,filename,USE_ALPHA);
+  delete icon;
+  icon = new Surface(filename,USE_ALPHA);
 }
 
 void Button::draw()
@@ -97,9 +97,9 @@ void Button::draw()
   fillrect(rect.x+1,rect.y+1,rect.w-2,rect.h-2,175,175,175,200);
   if(bkgd != NULL)
     {
-      texture_draw(bkgd,rect.x,rect.y);
+      bkgd->draw(rect.x,rect.y);
     }
-  texture_draw(&icon,rect.x,rect.y);
+  icon->draw(rect.x,rect.y);
   if(show_info)
     {
       char str[80];
@@ -121,7 +121,7 @@ void Button::draw()
 
 Button::~Button()
 {
-  texture_free(&icon);
+  delete icon;
 }
 
 void Button::event(SDL_Event &event)
index a6850fe..69af7f3 100644 (file)
@@ -43,8 +43,8 @@ class Button
 
   private:
     static Timer popup_timer;
-    texture_type icon;
-    texture_type* bkgd;
+    Surface* icon;
+    Surface* bkgd;
     std::string info;
     SDLKey shortcut;
     SDL_Rect rect;
index fa5dbbf..8f637f4 100644 (file)
@@ -698,7 +698,7 @@ GameSession::drawstatus()
 
   for(int i= 0; i < tux.lives; ++i)
     {
-      texture_draw(&tux_life,565+(18*i),20);
+      tux_life->draw(565+(18*i),20);
     }
 }
 
index 8c6bf66..00e2543 100644 (file)
@@ -44,9 +44,8 @@ BouncyDistro::action(double frame_ratio)
 void
 BouncyDistro::draw()
 {
-  texture_draw(&img_distro[0],
-               base.x - scroll_x,
-               base.y);
+  img_distro[0]->draw(base.x - scroll_x,
+                      base.y);
 }
 
 
@@ -88,8 +87,7 @@ BrokenBrick::draw()
   dest.h = 16;
   
   if (tile->images.size() > 0)
-    texture_draw_part(&tile->images[0],
-                      src.x,src.y,dest.x,dest.y,dest.w,dest.h);
+    tile->images[0]->draw_part(src.x,src.y,dest.x,dest.y,dest.w,dest.h);
 }
 
 void
@@ -145,8 +143,8 @@ BouncyBrick::draw()
       else
         {
           s = (int)scroll_x / 30;
-          texture_draw_part(&plevel->img_bkgd, dest.x + s, dest.y, 
-                            dest.x, dest.y,dest.w,dest.h);
+          plevel->img_bkgd->draw_part(dest.x + s, dest.y, 
+                                      dest.x, dest.y,dest.w,dest.h);
         }
 
       Tile::draw(base.x - scroll_x,
index 87ab2be..8865891 100644 (file)
@@ -39,7 +39,7 @@ class BouncyDistro
   void draw(); 
 };
 
-extern texture_type img_distro[4];
+extern Surface* img_distro[4];
 
 #define BOUNCY_BRICK_MAX_OFFSET 8
 #define BOUNCY_BRICK_SPEED 0.9
index 97108e0..27c011e 100644 (file)
@@ -82,12 +82,11 @@ void save_hs(int score)
 {
   char str[80];
 
-  texture_type bkgd;
+  Surface* bkgd;
   SDL_Event event;
   FILE * fi;
 
-
-  texture_load(&bkgd, datadir + "/images/highscore/highscore.png", IGNORE_ALPHA);
+  bkgd = new Surface(datadir + "/images/highscore/highscore.png", IGNORE_ALPHA);
 
   hs_score = score;
 
@@ -103,7 +102,7 @@ void save_hs(int score)
   show_menu = 1;
   while(show_menu)
     {
-      texture_draw_bg(&bkgd);
+      bkgd->draw_bg();
 
       text_drawf(&blue_text, "Congratulations", 0, 130, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
       text_draw(&blue_text, "Your score:", 150, 180, 1, NO_UPDATE);
index 369716b..823ebb7 100644 (file)
@@ -41,7 +41,7 @@ char * intro_text[] = {
 int intro(void)
 {
   SDL_Event event;
-  texture_type bkgd,  copter_squish,  copter_stretch, beam,
+  texture_type bkgd, copter_squish,  copter_stretch, beam,
   gown_sit,  gown_lookup,  gown_upset,
   tux_sit, tux_upset, tux_mad;
   texture_type copter[2];
@@ -277,18 +277,18 @@ int intro(void)
 
   /* Free surfaces: */
 
-  texture_free(&bkgd);
-  texture_free(&gown_sit);
-  texture_free(&gown_lookup);
-  texture_free(&gown_upset);
-  texture_free(&tux_sit);
-  texture_free(&tux_upset);
-  texture_free(&tux_mad);
-  texture_free(&copter[0]);
-  texture_free(&copter[1]);
-  texture_free(&copter_squish);
-  texture_free(&copter_stretch);
-  texture_free(&beam);
+  delete bkgd;
+  delete gown_sit;
+  delete gown_lookup;
+  delete gown_upset;
+  delete tux_sit;
+  delete tux_upset;
+  delete tux_mad;
+  delete copter[0];
+  delete copter[1];
+  delete copter_squish;
+  delete copter_stretch;
+  delete beam;
 
 
   /* Free array buffers: */
index bdc3f53..4a3b084 100644 (file)
@@ -122,12 +122,12 @@ void st_subset::load(char *subset)
       snprintf(str, 1024, "%s.png", filename);
       if(faccessible(str))
         {
-          texture_load(&image,str,IGNORE_ALPHA);
+          image = new Surface(str,IGNORE_ALPHA);
         }
       else
         {
           snprintf(filename, 1024, "%s/images/status/level-subset-info.png", datadir.c_str());
-          texture_load(&image,filename,IGNORE_ALPHA);
+          image = new Surface(filename,IGNORE_ALPHA);
         }
     }
 
@@ -186,7 +186,7 @@ void st_subset::free()
   title.clear();
   description.clear();
   name.clear();
-  texture_free(&image);
+  delete image;
   levels = 0;
 }
 
@@ -557,7 +557,7 @@ Level::load_gfx()
       snprintf(fname, 1024, "%s/background/%s", st_dir, bkgd_image.c_str());
       if(!faccessible(fname))
         snprintf(fname, 1024, "%s/images/background/%s", datadir.c_str(), bkgd_image.c_str());
-      texture_load(&img_bkgd, fname, IGNORE_ALPHA);
+      img_bkgd = new Surface(fname, IGNORE_ALPHA);
     }
   else
     {
@@ -569,12 +569,12 @@ Level::load_gfx()
 void
 Level::free_gfx()
 {
-  texture_free(&img_bkgd);
+  delete img_bkgd;
 }
 
 /* Load a level-specific graphic... */
 void
-Level::load_image(texture_type* ptexture, string theme,const  char * file, int use_alpha)
+Level::load_image(Surface** ptexture, string theme,const  char * file, int use_alpha)
 {
   char fname[1024];
 
@@ -582,7 +582,7 @@ Level::load_image(texture_type* ptexture, string theme,const  char * file, int u
   if(!faccessible(fname))
     snprintf(fname, 1024, "%s/images/themes/%s/%s", datadir.c_str(), theme.c_str(), file);
 
-  texture_load(ptexture, fname, use_alpha);
+  *ptexture = new Surface(fname, use_alpha);
 }
 
 void tilemap_change_size(unsigned int** tilemap[15], int w, int old_w)
index 503a0da..389555a 100644 (file)
@@ -34,7 +34,7 @@ class st_subset
     std::string name;
     std::string title;
     std::string description;
-    texture_type image;
+    Surface* image;
     int levels;
  
   private:
@@ -53,7 +53,7 @@ enum TileMapType {
 class Level 
 {
  public:
-  texture_type img_bkgd;
+  Surface* img_bkgd;
 
   std::string name;
   std::string author;
@@ -109,7 +109,7 @@ class Level
 
   void free_gfx();
 
-  void load_image(texture_type* ptexture, std::string theme, const char * file, int use_alpha);
+  void load_image(Surface** ptexture, std::string theme, const char * file, int use_alpha);
 };
 
 #endif /*SUPERTUX_LEVEL_H*/
index ea96354..6185882 100644 (file)
@@ -89,7 +89,7 @@ static World le_world;
 static st_subset le_level_subset;
 static int le_show_grid;
 static int le_frame;
-static texture_type le_selection;
+static Surface* le_selection;
 static int done;
 static unsigned int le_current_tile;
 static bool le_mouse_pressed[2];
@@ -352,7 +352,7 @@ int le_init()
   le_mouse_pressed[LEFT] = false;
   le_mouse_pressed[RIGHT] = false;
 
-  texture_load(&le_selection, datadir + "/images/leveleditor/select.png", USE_ALPHA);
+  le_selection = new Surface(datadir + "/images/leveleditor/select.png", USE_ALPHA);
 
   select_tilegroup_menu_effect.init(false);
 
@@ -583,7 +583,7 @@ void le_quit(void)
 
   SDL_EnableKeyRepeat(0, 0);    // disables key repeating
 
-  texture_free(&le_selection);
+  delete le_selection;
   delete leveleditor_menu;
   delete subset_load_menu;
   delete subset_new_menu;
@@ -630,7 +630,7 @@ void le_drawinterface()
     }
 
   if(le_selection_mode == CURSOR)
-    texture_draw(&le_selection, cursor_x - pos_x, cursor_y);
+    le_selection->draw( cursor_x - pos_x, cursor_y);
   else if(le_selection_mode == SQUARE)
     {
       int w, h;
@@ -650,7 +650,7 @@ void le_drawinterface()
   Tile::draw(19 * 32, 14 * 32, le_current_tile);
   
        if(TileManager::instance()->get(le_current_tile)->editor_images.size() > 0)
-       texture_draw(&TileManager::instance()->get(le_current_tile)->editor_images[0], 19 * 32, 14 * 32);
+       TileManager::instance()->get(le_current_tile)->editor_images[0]->draw( 19 * 32, 14 * 32);
 
   if(le_current_level != NULL)
     {
@@ -694,10 +694,10 @@ void le_drawlevel()
   if(le_current_level->bkgd_image[0] != '\0')
     {
       s = pos_x / 30;
-      texture_draw_part(&le_current_level->img_bkgd,s,0,0,0,
-                        le_current_level->img_bkgd.w - s - 32, le_current_level->img_bkgd.h);
-      texture_draw_part(&le_current_level->img_bkgd,0,0,screen->w - s - 32 ,0,s,
-                        le_current_level->img_bkgd.h);
+      le_current_level->img_bkgd->draw_part(s,0,0,0,
+                                            le_current_level->img_bkgd->w - s - 32, le_current_level->img_bkgd->h);
+      le_current_level->img_bkgd->draw_part(0,0,screen->w - s - 32 ,0,s,
+                                            le_current_level->img_bkgd->h);
     }
   else
     {
@@ -735,7 +735,7 @@ void le_drawlevel()
         /* draw whats inside stuff when cursor is selecting those */
         /* (draw them all the time - is this the right behaviour?) */
        if(TileManager::instance()->get(le_current_level->ia_tiles[y][x + (int)(pos_x / 32)])->editor_images.size() > 0)
-       texture_draw(&TileManager::instance()->get(le_current_level->ia_tiles[y][x + (int)(pos_x / 32)])->editor_images[0], x * 32 - ((int)pos_x % 32), y*32);
+       TileManager::instance()->get(le_current_level->ia_tiles[y][x + (int)(pos_x / 32)])->editor_images[0]->draw( x * 32 - ((int)pos_x % 32), y*32);
 
       }
 
@@ -751,7 +751,7 @@ void le_drawlevel()
 
   /* Draw the player: */
   /* for now, the position is fixed at (100, 240) */
-  texture_draw(&tux_right[(global_frame_counter / 5) % 3], 100 - pos_x, 240);
+  tux_right[(global_frame_counter / 5) % 3]->draw( 100 - pos_x, 240);
 }
 
 void le_checkevents()
index 97ea5fc..5a49001 100644 (file)
 MenuAction menuaction = MENU_ACTION_NONE;
 bool show_menu;
 bool menu_change;
-texture_type checkbox, checkbox_checked, back, arrow_left, arrow_right;
+
+Surface* checkbox;
+Surface* checkbox_checked;
+Surface* back;
+Surface* arrow_left;
+Surface* arrow_right;
 
 Menu* main_menu      = 0;
 Menu* game_menu      = 0;
@@ -425,8 +430,8 @@ Menu::draw_item(int index, // Position of the current item in the menu
         int text_pos   = (text_width + font_width)/2;
 
         /* Draw arrows */
-        texture_draw(&arrow_left,  x_pos - list_pos + text_pos - 17, y_pos - 8);
-        texture_draw(&arrow_right, x_pos - list_pos + text_pos - 1 + list_pos_2, y_pos - 8);
+        arrow_left->draw(  x_pos - list_pos + text_pos - 17, y_pos - 8);
+        arrow_right->draw( x_pos - list_pos + text_pos - 1 + list_pos_2, y_pos - 8);
 
         /* Draw input background */
         fillrect(x_pos - list_pos + text_pos - 1, y_pos - 10,
@@ -448,7 +453,7 @@ Menu::draw_item(int index, // Position of the current item in the menu
     case MN_BACK:
       {
         text_draw_align(text_font, pitem.text, x_pos, y_pos, A_HMIDDLE, A_VMIDDLE, shadow_size);
-        texture_draw(&back, x_pos + text_width/2  + font_width, y_pos - 8);
+        back->draw( x_pos + text_width/2  + font_width, y_pos - 8);
         break;
       }
 
@@ -457,11 +462,11 @@ Menu::draw_item(int index, // Position of the current item in the menu
         text_draw_align(text_font, pitem.text, x_pos, y_pos, A_HMIDDLE, A_VMIDDLE, shadow_size);
 
         if(pitem.toggled)
-          texture_draw(&checkbox_checked,
+          checkbox_checked->draw(
                        x_pos + (text_width+font_width)/2,
                        y_pos - 8);
         else
-          texture_draw(&checkbox,
+          checkbox->draw(
                        x_pos + (text_width+font_width)/2,
                        y_pos - 8);
         break;
index 4301d4e..50d459d 100644 (file)
@@ -110,11 +110,11 @@ extern MenuAction menuaction;
 extern bool show_menu;
 extern bool menu_change;
 
-extern texture_type checkbox;
-extern texture_type checkbox_checked;
-extern texture_type back;
-extern texture_type arrow_left;
-extern texture_type arrow_right;
+extern Surface* checkbox;
+extern Surface* checkbox_checked;
+extern Surface* back;
+extern Surface* arrow_left;
+extern Surface* arrow_right;
 
 extern Menu* contrib_menu;
 extern Menu* contrib_subset_menu;
index f7a5993..91f727b 100644 (file)
@@ -15,7 +15,7 @@
 
 MouseCursor::MouseCursor(std::string cursor_file, int frames)
 {
-  texture_load(&cursor,cursor_file.c_str(),USE_ALPHA);
+  cursor = new Surface(cursor_file, USE_ALPHA);
 
   cur_state = MC_NORMAL;
   cur_frame = 0;
@@ -29,7 +29,7 @@ MouseCursor::MouseCursor(std::string cursor_file, int frames)
 
 MouseCursor::~MouseCursor()
 {
-  texture_free(&cursor);
+  delete cursor;
 
   SDL_ShowCursor(SDL_ENABLE);
 }
@@ -48,8 +48,8 @@ void MouseCursor::draw()
 {
   int x,y,w,h;
   Uint8 ispressed = SDL_GetMouseState(&x,&y);
-  w = cursor.w / tot_frames;
-  h = cursor.h / MC_STATES_NB;
+  w = cursor->w / tot_frames;
+  h = cursor->h / MC_STATES_NB;
   if(ispressed &SDL_BUTTON(1) || ispressed &SDL_BUTTON(2))
     {
       if(cur_state != MC_CLICK)
@@ -73,5 +73,5 @@ void MouseCursor::draw()
       timer.start(MC_FRAME_PERIOD);
     }
 
-  texture_draw_part(&cursor, w*cur_frame, h*cur_state , x, y, w, h);
+  cursor->draw_part(w*cur_frame, h*cur_state , x, y, w, h);
 }
index cc9c6a3..35a417b 100644 (file)
@@ -39,7 +39,7 @@ class MouseCursor
     int state_before_click;
     int cur_state;
     int cur_frame, tot_frames;
-    texture_type cursor;
+    Surface* cursor;
     Timer timer;
   };
 
index 2cd42da..e18dd03 100644 (file)
@@ -63,15 +63,15 @@ void ParticleSystem::draw(float scrollx, float scrolly, int layer)
         
         if(x > screen->w) x -= virtual_width;
         if(y > screen->h) y -= virtual_height;
-        texture_draw(particle->texture, x, y);
+        particle->texture->draw(x, y);
     }
 }
 
 SnowParticleSystem::SnowParticleSystem()
 {
-    texture_load(&snowimages[0], datadir+"/images/shared/snow0.png", USE_ALPHA);
-    texture_load(&snowimages[1], datadir+"/images/shared/snow1.png", USE_ALPHA);
-    texture_load(&snowimages[2], datadir+"/images/shared/snow2.png", USE_ALPHA);
+    snowimages[0] = new Surface(datadir+"/images/shared/snow0.png", USE_ALPHA);
+    snowimages[1] = new Surface(datadir+"/images/shared/snow1.png", USE_ALPHA);
+    snowimages[2] = new Surface(datadir+"/images/shared/snow2.png", USE_ALPHA);
 
     virtual_width = screen->w * 2;
 
@@ -83,7 +83,7 @@ SnowParticleSystem::SnowParticleSystem()
         particle->y = rand() % screen->h;
         particle->layer = i % 2;
         int snowsize = rand() % 3;
-        particle->texture = &snowimages[snowsize];
+        particle->texture = snowimages[snowsize];
         do {
             particle->speed = snowsize/60.0 + (float(rand()%10)/300.0);
         } while(particle->speed < 0.01);
@@ -95,8 +95,8 @@ SnowParticleSystem::SnowParticleSystem()
 
 SnowParticleSystem::~SnowParticleSystem()
 {
-    for(int i=0;i<3;++i)
-        texture_free(&snowimages[i]);
+  for(int i=0;i<3;++i)
+    delete snowimages[i];
 }
 
 void SnowParticleSystem::simulate(float elapsed_time)
@@ -114,7 +114,7 @@ void SnowParticleSystem::simulate(float elapsed_time)
 
 CloudParticleSystem::CloudParticleSystem()
 {
-    texture_load(&cloudimage, datadir + "/images/shared/cloud.png", USE_ALPHA);
+    cloudimage = new Surface(datadir + "/images/shared/cloud.png", USE_ALPHA);
 
     virtual_width = 2000.0;
 
@@ -124,7 +124,7 @@ CloudParticleSystem::CloudParticleSystem()
         particle->x = rand() % int(virtual_width);
         particle->y = rand() % int(virtual_height);
         particle->layer = 0;
-        particle->texture = &cloudimage;
+        particle->texture = cloudimage;
         particle->speed = -float(250 + rand() % 200) / 1000.0;
 
         particles.push_back(particle);
@@ -133,7 +133,7 @@ CloudParticleSystem::CloudParticleSystem()
 
 CloudParticleSystem::~CloudParticleSystem()
 {
-    texture_free(&cloudimage);
+  delete cloudimage;
 }
 
 void CloudParticleSystem::simulate(float elapsed_time)
index 8efdf95..b90b277 100644 (file)
@@ -56,7 +56,7 @@ protected:
 
         float x, y;
         int layer;
-        texture_type* texture;
+        Surface* texture;
     };
     
     std::vector<Particle*> particles;
@@ -78,7 +78,7 @@ private:
         float speed;
     };
     
-    texture_type snowimages[3];
+    Surface* snowimages[3];
 };
 
 class CloudParticleSystem : public ParticleSystem
@@ -96,7 +96,7 @@ private:
         float speed;
     };
     
-    texture_type cloudimage;
+    Surface* cloudimage;
 };
 
 #endif
index 337c52f..817c5ea 100644 (file)
 #include "tile.h"
 #include "screen.h"
 
-texture_type tux_life;
-std::vector<texture_type> tux_right;
-std::vector<texture_type> tux_left;
-texture_type smalltux_jump_left;
-texture_type smalltux_jump_right;
-texture_type smalltux_stand_left;
-texture_type smalltux_stand_right;
-
-texture_type bigtux_right[3];
-texture_type bigtux_left[3];
-texture_type bigtux_right_jump;
-texture_type bigtux_left_jump;
-texture_type ducktux_right;
-texture_type ducktux_left;
-texture_type skidtux_right;
-texture_type skidtux_left;
-texture_type firetux_right[3];
-texture_type firetux_left[3];
-texture_type bigfiretux_right[3];
-texture_type bigfiretux_left[3];
-texture_type bigfiretux_right_jump;
-texture_type bigfiretux_left_jump;
-texture_type duckfiretux_right;
-texture_type duckfiretux_left;
-texture_type skidfiretux_right;
-texture_type skidfiretux_left;
-texture_type cape_right[2];
-texture_type cape_left[2];
-texture_type bigcape_right[2];
-texture_type bigcape_left[2];
+Surface* tux_life;
+std::vector<Surface*> tux_right;
+std::vector<Surface*> tux_left;
+Surface* smalltux_jump_left;
+Surface* smalltux_jump_right;
+Surface* smalltux_stand_left;
+Surface* smalltux_stand_right;
+
+Surface* bigtux_right[3];
+Surface* bigtux_left[3];
+Surface* bigtux_right_jump;
+Surface* bigtux_left_jump;
+Surface* ducktux_right;
+Surface* ducktux_left;
+Surface* skidtux_right;
+Surface* skidtux_left;
+Surface* firetux_right[3];
+Surface* firetux_left[3];
+Surface* bigfiretux_right[3];
+Surface* bigfiretux_left[3];
+Surface* bigfiretux_right_jump;
+Surface* bigfiretux_left_jump;
+Surface* duckfiretux_right;
+Surface* duckfiretux_left;
+Surface* skidfiretux_right;
+Surface* skidfiretux_left;
+Surface* cape_right[2];
+Surface* cape_left[2];
+Surface* bigcape_right[2];
+Surface* bigcape_left[2];
 
 void player_input_init(player_input_type* pplayer_input)
 {
@@ -532,12 +532,11 @@ Player::draw()
 
               if (dir == RIGHT)
                 {
-                  texture_draw(&cape_right[global_frame_counter % 2],
-                               base.x- scroll_x, base.y);
+                 cape_right[global_frame_counter % 2]->draw(base.x- scroll_x, base.y);
                 }
               else
                 {
-                  texture_draw(&cape_left[global_frame_counter % 2],
+                  cape_left[global_frame_counter % 2]->draw(
                                base.x- scroll_x, base.y);
                 }
             }
@@ -548,26 +547,26 @@ Player::draw()
               if (physic.get_velocity_y() != 0)
                 {
                   if (dir == RIGHT)
-                    texture_draw(&smalltux_jump_right, base.x - scroll_x, base.y - 10);
+                    smalltux_jump_right->draw( base.x - scroll_x, base.y - 10);
                   else
-                    texture_draw(&smalltux_jump_left, base.x - scroll_x, base.y - 10);                   
+                    smalltux_jump_left->draw( base.x - scroll_x, base.y - 10);                   
                 }
               else
                 {
                   if (fabsf(physic.get_velocity_x()) < 1.0f) // standing
                     {
                       if (dir == RIGHT)
-                        texture_draw(&smalltux_stand_right, base.x - scroll_x, base.y - 9);
+                        smalltux_stand_right->draw( base.x - scroll_x, base.y - 9);
                       else
-                        texture_draw(&smalltux_stand_left, base.x - scroll_x, base.y - 9);
+                        smalltux_stand_left->draw( base.x - scroll_x, base.y - 9);
                     }
                   else // moving
                     {
                       if (dir == RIGHT)
-                        texture_draw(&tux_right[(global_frame_counter/2) % tux_right.size()], 
+                        tux_right[(global_frame_counter/2) % tux_right.size()]->draw( 
                                      base.x - scroll_x, base.y - 9);
                       else
-                        texture_draw(&tux_left[(global_frame_counter/2) % tux_left.size()], 
+                        tux_left[(global_frame_counter/2) % tux_left.size()]->draw( 
                                      base.x - scroll_x, base.y - 9);
                     }
                 }
@@ -578,11 +577,11 @@ Player::draw()
 
               if (dir == RIGHT)
                 {
-                  texture_draw(&firetux_right[frame_], base.x- scroll_x, base.y);
+                  firetux_right[frame_]->draw( base.x- scroll_x, base.y);
                 }
               else
                 {
-                  texture_draw(&firetux_left[frame_], base.x- scroll_x, base.y);
+                  firetux_left[frame_]->draw( base.x- scroll_x, base.y);
                 }
             }
         }
@@ -590,19 +589,19 @@ Player::draw()
         {
           if (invincible_timer.started())
             {
-              float capex = base.x + (base.width - bigcape_right[0].w) / 2;
+              float capex = base.x + (base.width - bigcape_right[0]->w) / 2;
               capex -= scroll_x;
-              float capey = base.y + (base.height - bigcape_right[0].h) / 2;
+              float capey = base.y + (base.height - bigcape_right[0]->h) / 2;
                 
               /* Draw cape (just not in ducked mode since that looks silly): */
               if (dir == RIGHT)
                 {
-                  texture_draw(&bigcape_right[global_frame_counter % 2],
+                  bigcape_right[global_frame_counter % 2]->draw(
                           capex, capey);
                 }
               else
                 {
-                  texture_draw(&bigcape_left[global_frame_counter % 2],
+                  bigcape_left[global_frame_counter % 2]->draw(
                           capex, capey);
                 }
             }
@@ -617,12 +616,12 @@ Player::draw()
                         {
                           if (dir == RIGHT)
                             {
-                              texture_draw(&bigtux_right[frame_],
+                              bigtux_right[frame_]->draw(
                                            base.x- scroll_x - 8, base.y);
                             }
                           else
                             {
-                              texture_draw(&bigtux_left[frame_],
+                              bigtux_left[frame_]->draw(
                                            base.x- scroll_x - 8, base.y);
                             }
                         }
@@ -630,12 +629,12 @@ Player::draw()
                         {
                           if (dir == RIGHT)
                             {
-                              texture_draw(&bigtux_right_jump,
+                              bigtux_right_jump->draw(
                                            base.x- scroll_x - 8, base.y);
                             }
                           else
                             {
-                              texture_draw(&bigtux_left_jump,
+                              bigtux_left_jump->draw(
                                            base.x- scroll_x - 8, base.y);
                             }
                         }
@@ -644,12 +643,12 @@ Player::draw()
                     {
                       if (dir == RIGHT)
                         {
-                          texture_draw(&skidtux_right,
+                          skidtux_right->draw(
                                        base.x- scroll_x - 8, base.y);
                         }
                       else
                         {
-                          texture_draw(&skidtux_left,
+                          skidtux_left->draw(
                                        base.x- scroll_x - 8, base.y);
                         }
                     }
@@ -658,11 +657,11 @@ Player::draw()
                 {
                   if (dir == RIGHT)
                     {
-                      texture_draw(&ducktux_right, base.x- scroll_x - 8, base.y - 16);
+                      ducktux_right->draw( base.x- scroll_x - 8, base.y - 16);
                     }
                   else
                     {
-                      texture_draw(&ducktux_left, base.x- scroll_x - 8, base.y - 16);
+                      ducktux_left->draw( base.x- scroll_x - 8, base.y - 16);
                     }
                 }
             }
@@ -677,12 +676,12 @@ Player::draw()
                         {
                           if (dir == RIGHT)
                             {
-                              texture_draw(&bigfiretux_right[frame_],
+                              bigfiretux_right[frame_]->draw(
                                            base.x- scroll_x - 8, base.y);
                             }
                           else
                             {
-                              texture_draw(&bigfiretux_left[frame_],
+                              bigfiretux_left[frame_]->draw(
                                            base.x- scroll_x - 8, base.y);
                             }
                         }
@@ -690,12 +689,12 @@ Player::draw()
                         {
                           if (dir == RIGHT)
                             {
-                              texture_draw(&bigfiretux_right_jump,
+                              bigfiretux_right_jump->draw(
                                            base.x- scroll_x - 8, base.y);
                             }
                           else
                             {
-                              texture_draw(&bigfiretux_left_jump,
+                              bigfiretux_left_jump->draw(
                                            base.x- scroll_x - 8, base.y);
                             }
                         }
@@ -704,12 +703,12 @@ Player::draw()
                     {
                       if (dir == RIGHT)
                         {
-                          texture_draw(&skidfiretux_right,
+                          skidfiretux_right->draw(
                                        base.x- scroll_x - 8, base.y);
                         }
                       else
                         {
-                          texture_draw(&skidfiretux_left,
+                          skidfiretux_left->draw(
                                        base.x- scroll_x - 8, base.y);
                         }
                     }
@@ -718,11 +717,11 @@ Player::draw()
                 {
                   if (dir == RIGHT)
                     {
-                      texture_draw(&duckfiretux_right, base.x- scroll_x - 8, base.y - 16);
+                      duckfiretux_right->draw( base.x- scroll_x - 8, base.y - 16);
                     }
                   else
                     {
-                      texture_draw(&duckfiretux_left, base.x- scroll_x - 8, base.y - 16);
+                      duckfiretux_left->draw( base.x- scroll_x - 8, base.y - 16);
                     }
                 }
             }
index ecf0185..62237d2 100644 (file)
@@ -60,35 +60,35 @@ struct player_input_type
 
 void player_input_init(player_input_type* pplayer_input);
 
-extern texture_type tux_life;
-extern std::vector<texture_type> tux_right;
-extern std::vector<texture_type> tux_left;
-extern texture_type smalltux_jump_left;
-extern texture_type smalltux_jump_right;
-extern texture_type smalltux_stand_left;
-extern texture_type smalltux_stand_right;
-extern texture_type bigtux_right[3];
-extern texture_type bigtux_left[3];
-extern texture_type bigtux_right_jump;
-extern texture_type bigtux_left_jump;
-extern texture_type ducktux_right;
-extern texture_type ducktux_left;
-extern texture_type skidtux_right;
-extern texture_type skidtux_left;
-extern texture_type firetux_right[3];
-extern texture_type firetux_left[3];
-extern texture_type bigfiretux_right[3];
-extern texture_type bigfiretux_left[3];
-extern texture_type bigfiretux_right_jump;
-extern texture_type bigfiretux_left_jump;
-extern texture_type duckfiretux_right;
-extern texture_type duckfiretux_left;
-extern texture_type skidfiretux_right;
-extern texture_type skidfiretux_left;
-extern texture_type cape_right[2];
-extern texture_type cape_left[2];
-extern texture_type bigcape_right[2];
-extern texture_type bigcape_left[2];
+extern Surface* tux_life;
+extern std::vector<Surface*> tux_right;
+extern std::vector<Surface*> tux_left;
+extern Surface* smalltux_jump_left;
+extern Surface* smalltux_jump_right;
+extern Surface* smalltux_stand_left;
+extern Surface* smalltux_stand_right;
+extern Surface* bigtux_right[3];
+extern Surface* bigtux_left[3];
+extern Surface* bigtux_right_jump;
+extern Surface* bigtux_left_jump;
+extern Surface* ducktux_right;
+extern Surface* ducktux_left;
+extern Surface* skidtux_right;
+extern Surface* skidtux_left;
+extern Surface* firetux_right[3];
+extern Surface* firetux_left[3];
+extern Surface* bigfiretux_right[3];
+extern Surface* bigfiretux_left[3];
+extern Surface* bigfiretux_right_jump;
+extern Surface* bigfiretux_left_jump;
+extern Surface* duckfiretux_right;
+extern Surface* duckfiretux_left;
+extern Surface* skidfiretux_right;
+extern Surface* skidfiretux_left;
+extern Surface* cape_right[2];
+extern Surface* cape_left[2];
+extern Surface* bigcape_right[2];
+extern Surface* bigcape_left[2];
 
 class Player
 {
index f4b6340..9dc9d22 100644 (file)
@@ -6,16 +6,16 @@
 #include "special.h"
 #include "resources.h"
 
-texture_type img_waves[3]; 
-texture_type img_water;
-texture_type img_pole;
-texture_type img_poletop;
-texture_type img_flag[2];
-texture_type img_cloud[2][4];
+Surface* img_waves[3]; 
+Surface* img_water;
+Surface* img_pole;
+Surface* img_poletop;
+Surface* img_flag[2];
+Surface* img_cloud[2][4];
 
-texture_type img_box_full;
-texture_type img_box_empty;
-texture_type img_red_glow;
+Surface* img_box_full;
+Surface* img_box_empty;
+Surface* img_red_glow;
 
 /* Load graphics/sounds shared between all levels: */
 void loadshared()
@@ -23,218 +23,218 @@ void loadshared()
   int i;
 
   /* Tuxes: */
-  texture_load(&smalltux_stand_left, datadir + "/images/shared/smalltux-left-6.png", USE_ALPHA);
-  texture_load(&smalltux_stand_right, datadir + "/images/shared/smalltux-right-6.png", USE_ALPHA);
+  smalltux_stand_left = new Surface(datadir + "/images/shared/smalltux-left-6.png", USE_ALPHA);
+  smalltux_stand_right = new Surface(datadir + "/images/shared/smalltux-right-6.png", USE_ALPHA);
 
-  texture_load(&smalltux_jump_left, datadir + "/images/shared/smalltux-jump-left.png", USE_ALPHA);
-  texture_load(&smalltux_jump_right, datadir + "/images/shared/smalltux-jump-right.png", USE_ALPHA);
+  smalltux_jump_left = new Surface(datadir + "/images/shared/smalltux-jump-left.png", USE_ALPHA);
+  smalltux_jump_right = new Surface(datadir + "/images/shared/smalltux-jump-right.png", USE_ALPHA);
 
   tux_right.resize(8);
-  texture_load(&tux_right[0], datadir + "/images/shared/smalltux-right-1.png", USE_ALPHA);
-  texture_load(&tux_right[1], datadir + "/images/shared/smalltux-right-2.png", USE_ALPHA);
-  texture_load(&tux_right[2], datadir + "/images/shared/smalltux-right-3.png", USE_ALPHA);
-  texture_load(&tux_right[3], datadir + "/images/shared/smalltux-right-4.png", USE_ALPHA);
-  texture_load(&tux_right[4], datadir + "/images/shared/smalltux-right-5.png", USE_ALPHA);
-  texture_load(&tux_right[5], datadir + "/images/shared/smalltux-right-6.png", USE_ALPHA);
-  texture_load(&tux_right[6], datadir + "/images/shared/smalltux-right-7.png", USE_ALPHA);
-  texture_load(&tux_right[7], datadir + "/images/shared/smalltux-right-8.png", USE_ALPHA);
+  tux_right[0] = new Surface(datadir + "/images/shared/smalltux-right-1.png", USE_ALPHA);
+  tux_right[1] = new Surface(datadir + "/images/shared/smalltux-right-2.png", USE_ALPHA);
+  tux_right[2] = new Surface(datadir + "/images/shared/smalltux-right-3.png", USE_ALPHA);
+  tux_right[3] = new Surface(datadir + "/images/shared/smalltux-right-4.png", USE_ALPHA);
+  tux_right[4] = new Surface(datadir + "/images/shared/smalltux-right-5.png", USE_ALPHA);
+  tux_right[5] = new Surface(datadir + "/images/shared/smalltux-right-6.png", USE_ALPHA);
+  tux_right[6] = new Surface(datadir + "/images/shared/smalltux-right-7.png", USE_ALPHA);
+  tux_right[7] = new Surface(datadir + "/images/shared/smalltux-right-8.png", USE_ALPHA);
 
   tux_left.resize(8);
-  texture_load(&tux_left[0], datadir + "/images/shared/smalltux-left-1.png", USE_ALPHA);
-  texture_load(&tux_left[1], datadir + "/images/shared/smalltux-left-2.png", USE_ALPHA);
-  texture_load(&tux_left[2], datadir + "/images/shared/smalltux-left-3.png", USE_ALPHA);
-  texture_load(&tux_left[3], datadir + "/images/shared/smalltux-left-4.png", USE_ALPHA);
-  texture_load(&tux_left[4], datadir + "/images/shared/smalltux-left-5.png", USE_ALPHA);
-  texture_load(&tux_left[5], datadir + "/images/shared/smalltux-left-6.png", USE_ALPHA);
-  texture_load(&tux_left[6], datadir + "/images/shared/smalltux-left-7.png", USE_ALPHA);
-  texture_load(&tux_left[7], datadir + "/images/shared/smalltux-left-8.png", USE_ALPHA);
+  tux_left[0] = new Surface(datadir + "/images/shared/smalltux-left-1.png", USE_ALPHA);
+  tux_left[1] = new Surface(datadir + "/images/shared/smalltux-left-2.png", USE_ALPHA);
+  tux_left[2] = new Surface(datadir + "/images/shared/smalltux-left-3.png", USE_ALPHA);
+  tux_left[3] = new Surface(datadir + "/images/shared/smalltux-left-4.png", USE_ALPHA);
+  tux_left[4] = new Surface(datadir + "/images/shared/smalltux-left-5.png", USE_ALPHA);
+  tux_left[5] = new Surface(datadir + "/images/shared/smalltux-left-6.png", USE_ALPHA);
+  tux_left[6] = new Surface(datadir + "/images/shared/smalltux-left-7.png", USE_ALPHA);
+  tux_left[7] = new Surface(datadir + "/images/shared/smalltux-left-8.png", USE_ALPHA);
 
-  texture_load(&firetux_right[0], datadir + "/images/shared/firetux-right-0.png", USE_ALPHA);
-  texture_load(&firetux_right[1], datadir + "/images/shared/firetux-right-1.png", USE_ALPHA);
-  texture_load(&firetux_right[2], datadir + "/images/shared/firetux-right-2.png", USE_ALPHA);
+  firetux_right[0] = new Surface(datadir + "/images/shared/firetux-right-0.png", USE_ALPHA);
+  firetux_right[1] = new Surface(datadir + "/images/shared/firetux-right-1.png", USE_ALPHA);
+  firetux_right[2] = new Surface(datadir + "/images/shared/firetux-right-2.png", USE_ALPHA);
 
-  texture_load(&firetux_left[0], datadir + "/images/shared/firetux-left-0.png", USE_ALPHA);
-  texture_load(&firetux_left[1], datadir + "/images/shared/firetux-left-1.png", USE_ALPHA);
-  texture_load(&firetux_left[2], datadir + "/images/shared/firetux-left-2.png", USE_ALPHA);
+  firetux_left[0] = new Surface(datadir + "/images/shared/firetux-left-0.png", USE_ALPHA);
+  firetux_left[1] = new Surface(datadir + "/images/shared/firetux-left-1.png", USE_ALPHA);
+  firetux_left[2] = new Surface(datadir + "/images/shared/firetux-left-2.png", USE_ALPHA);
 
 
-  texture_load(&cape_right[0], datadir + "/images/shared/cape-right-0.png",
+  cape_right[0] = new Surface(datadir + "/images/shared/cape-right-0.png",
                USE_ALPHA);
 
-  texture_load(&cape_right[1], datadir + "/images/shared/cape-right-1.png",
+  cape_right[1] = new Surface(datadir + "/images/shared/cape-right-1.png",
                USE_ALPHA);
 
-  texture_load(&cape_left[0], datadir + "/images/shared/cape-left-0.png",
+  cape_left[0] = new Surface(datadir + "/images/shared/cape-left-0.png",
                USE_ALPHA);
 
-  texture_load(&cape_left[1], datadir + "/images/shared/cape-left-1.png",
+  cape_left[1] = new Surface(datadir + "/images/shared/cape-left-1.png",
                USE_ALPHA);
 
-  texture_load(&bigtux_right[0], datadir + "/images/shared/bigtux-right-0.png",
+  bigtux_right[0] = new Surface(datadir + "/images/shared/bigtux-right-0.png",
                USE_ALPHA);
 
-  texture_load(&bigtux_right[1], datadir + "/images/shared/bigtux-right-1.png",
+  bigtux_right[1] = new Surface(datadir + "/images/shared/bigtux-right-1.png",
                USE_ALPHA);
 
-  texture_load(&bigtux_right[2], datadir + "/images/shared/bigtux-right-2.png",
+  bigtux_right[2] = new Surface(datadir + "/images/shared/bigtux-right-2.png",
                USE_ALPHA);
 
-  texture_load(&bigtux_right_jump, datadir + "/images/shared/bigtux-right-jump.png", USE_ALPHA);
+  bigtux_right_jump = new Surface(datadir + "/images/shared/bigtux-right-jump.png", USE_ALPHA);
 
-  texture_load(&bigtux_left[0], datadir + "/images/shared/bigtux-left-0.png",
+  bigtux_left[0] = new Surface(datadir + "/images/shared/bigtux-left-0.png",
                USE_ALPHA);
 
-  texture_load(&bigtux_left[1], datadir + "/images/shared/bigtux-left-1.png",
+  bigtux_left[1] = new Surface(datadir + "/images/shared/bigtux-left-1.png",
                USE_ALPHA);
 
-  texture_load(&bigtux_left[2], datadir + "/images/shared/bigtux-left-2.png",
+  bigtux_left[2] = new Surface(datadir + "/images/shared/bigtux-left-2.png",
                USE_ALPHA);
 
-  texture_load(&bigtux_left_jump, datadir + "/images/shared/bigtux-left-jump.png", USE_ALPHA);
+  bigtux_left_jump = new Surface(datadir + "/images/shared/bigtux-left-jump.png", USE_ALPHA);
 
-  texture_load(&bigcape_right[0], datadir + "/images/shared/bigcape-right-0.png",
+  bigcape_right[0] = new Surface(datadir + "/images/shared/bigcape-right-0.png",
                USE_ALPHA);
 
-  texture_load(&bigcape_right[1], datadir + "/images/shared/bigcape-right-1.png",
+  bigcape_right[1] = new Surface(datadir + "/images/shared/bigcape-right-1.png",
                USE_ALPHA);
 
-  texture_load(&bigcape_left[0], datadir + "/images/shared/bigcape-left-0.png",
+  bigcape_left[0] = new Surface(datadir + "/images/shared/bigcape-left-0.png",
                USE_ALPHA);
 
-  texture_load(&bigcape_left[1], datadir + "/images/shared/bigcape-left-1.png",
+  bigcape_left[1] = new Surface(datadir + "/images/shared/bigcape-left-1.png",
                USE_ALPHA);
 
-  texture_load(&bigfiretux_right[0], datadir + "/images/shared/bigfiretux-right-0.png",
+  bigfiretux_right[0] = new Surface(datadir + "/images/shared/bigfiretux-right-0.png",
                USE_ALPHA);
 
-  texture_load(&bigfiretux_right[1], datadir + "/images/shared/bigfiretux-right-1.png",
+  bigfiretux_right[1] = new Surface(datadir + "/images/shared/bigfiretux-right-1.png",
                USE_ALPHA);
 
-  texture_load(&bigfiretux_right[2], datadir + "/images/shared/bigfiretux-right-2.png",
+  bigfiretux_right[2] = new Surface(datadir + "/images/shared/bigfiretux-right-2.png",
                USE_ALPHA);
 
-  texture_load(&bigfiretux_right_jump, datadir + "/images/shared/bigfiretux-right-jump.png", USE_ALPHA);
+  bigfiretux_right_jump = new Surface(datadir + "/images/shared/bigfiretux-right-jump.png", USE_ALPHA);
 
-  texture_load(&bigfiretux_left[0], datadir + "/images/shared/bigfiretux-left-0.png",
+  bigfiretux_left[0] = new Surface(datadir + "/images/shared/bigfiretux-left-0.png",
                USE_ALPHA);
 
-  texture_load(&bigfiretux_left[1], datadir + "/images/shared/bigfiretux-left-1.png",
+  bigfiretux_left[1] = new Surface(datadir + "/images/shared/bigfiretux-left-1.png",
                USE_ALPHA);
 
-  texture_load(&bigfiretux_left[2], datadir + "/images/shared/bigfiretux-left-2.png",
+  bigfiretux_left[2] = new Surface(datadir + "/images/shared/bigfiretux-left-2.png",
                USE_ALPHA);
 
-  texture_load(&bigfiretux_left_jump, datadir + "/images/shared/bigfiretux-left-jump.png", USE_ALPHA);
+  bigfiretux_left_jump = new Surface(datadir + "/images/shared/bigfiretux-left-jump.png", USE_ALPHA);
 
-  texture_load(&bigcape_right[0], datadir + "/images/shared/bigcape-right-0.png",
+  bigcape_right[0] = new Surface(datadir + "/images/shared/bigcape-right-0.png",
                USE_ALPHA);
 
-  texture_load(&bigcape_right[1], datadir + "/images/shared/bigcape-right-1.png",
+  bigcape_right[1] = new Surface(datadir + "/images/shared/bigcape-right-1.png",
                USE_ALPHA);
 
-  texture_load(&bigcape_left[0], datadir + "/images/shared/bigcape-left-0.png",
+  bigcape_left[0] = new Surface(datadir + "/images/shared/bigcape-left-0.png",
                USE_ALPHA);
 
-  texture_load(&bigcape_left[1], datadir + "/images/shared/bigcape-left-1.png",
+  bigcape_left[1] = new Surface(datadir + "/images/shared/bigcape-left-1.png",
                USE_ALPHA);
 
 
-  texture_load(&ducktux_right, datadir +
+  ducktux_right = new Surface(datadir +
                "/images/shared/ducktux-right.png",
                USE_ALPHA);
 
-  texture_load(&ducktux_left, datadir +
+  ducktux_left = new Surface(datadir +
                "/images/shared/ducktux-left.png",
                USE_ALPHA);
 
-  texture_load(&skidtux_right, datadir +
+  skidtux_right = new Surface(datadir +
                "/images/shared/skidtux-right.png",
                USE_ALPHA);
 
-  texture_load(&skidtux_left, datadir +
+  skidtux_left = new Surface(datadir +
                "/images/shared/skidtux-left.png",
                USE_ALPHA);
 
-  texture_load(&duckfiretux_right, datadir +
+  duckfiretux_right = new Surface(datadir +
                "/images/shared/duckfiretux-right.png",
                USE_ALPHA);
 
-  texture_load(&duckfiretux_left, datadir +
+  duckfiretux_left = new Surface(datadir +
                "/images/shared/duckfiretux-left.png",
                USE_ALPHA);
 
-  texture_load(&skidfiretux_right, datadir +
+  skidfiretux_right = new Surface(datadir +
                "/images/shared/skidfiretux-right.png",
                USE_ALPHA);
 
-  texture_load(&skidfiretux_left, datadir +
+  skidfiretux_left = new Surface(datadir +
                "/images/shared/skidfiretux-left.png",
                USE_ALPHA);
 
 
   /* Boxes: */
 
-  texture_load(&img_box_full, datadir + "/images/shared/box-full.png",
+  img_box_full = new Surface(datadir + "/images/shared/box-full.png",
                IGNORE_ALPHA);
-  texture_load(&img_box_empty, datadir + "/images/shared/box-empty.png",
+  img_box_empty = new Surface(datadir + "/images/shared/box-empty.png",
                IGNORE_ALPHA);
 
 
   /* Water: */
 
 
-  texture_load(&img_water, datadir + "/images/shared/water.png", IGNORE_ALPHA);
+  img_water = new Surface(datadir + "/images/shared/water.png", IGNORE_ALPHA);
 
-  texture_load(&img_waves[0], datadir + "/images/shared/waves-0.png",
+  img_waves[0] = new Surface(datadir + "/images/shared/waves-0.png",
                USE_ALPHA);
 
-  texture_load(&img_waves[1], datadir + "/images/shared/waves-1.png",
+  img_waves[1] = new Surface(datadir + "/images/shared/waves-1.png",
                USE_ALPHA);
 
-  texture_load(&img_waves[2], datadir + "/images/shared/waves-2.png",
+  img_waves[2] = new Surface(datadir + "/images/shared/waves-2.png",
                USE_ALPHA);
 
 
   /* Pole: */
 
-  texture_load(&img_pole, datadir + "/images/shared/pole.png", USE_ALPHA);
-  texture_load(&img_poletop, datadir + "/images/shared/poletop.png",
+  img_pole = new Surface(datadir + "/images/shared/pole.png", USE_ALPHA);
+  img_poletop = new Surface(datadir + "/images/shared/poletop.png",
                USE_ALPHA);
 
 
   /* Flag: */
 
-  texture_load(&img_flag[0], datadir + "/images/shared/flag-0.png",
+  img_flag[0] = new Surface(datadir + "/images/shared/flag-0.png",
                USE_ALPHA);
-  texture_load(&img_flag[1], datadir + "/images/shared/flag-1.png",
+  img_flag[1] = new Surface(datadir + "/images/shared/flag-1.png",
                USE_ALPHA);
 
 
   /* Cloud: */
 
-  texture_load(&img_cloud[0][0], datadir + "/images/shared/cloud-00.png",
+  img_cloud[0][0] = new Surface(datadir + "/images/shared/cloud-00.png",
                USE_ALPHA);
 
-  texture_load(&img_cloud[0][1], datadir + "/images/shared/cloud-01.png",
+  img_cloud[0][1] = new Surface(datadir + "/images/shared/cloud-01.png",
                USE_ALPHA);
 
-  texture_load(&img_cloud[0][2], datadir + "/images/shared/cloud-02.png",
+  img_cloud[0][2] = new Surface(datadir + "/images/shared/cloud-02.png",
                USE_ALPHA);
 
-  texture_load(&img_cloud[0][3], datadir + "/images/shared/cloud-03.png",
+  img_cloud[0][3] = new Surface(datadir + "/images/shared/cloud-03.png",
                USE_ALPHA);
 
 
-  texture_load(&img_cloud[1][0], datadir + "/images/shared/cloud-10.png",
+  img_cloud[1][0] = new Surface(datadir + "/images/shared/cloud-10.png",
                USE_ALPHA);
 
-  texture_load(&img_cloud[1][1], datadir + "/images/shared/cloud-11.png",
+  img_cloud[1][1] = new Surface(datadir + "/images/shared/cloud-11.png",
                USE_ALPHA);
 
-  texture_load(&img_cloud[1][2], datadir + "/images/shared/cloud-12.png",
+  img_cloud[1][2] = new Surface(datadir + "/images/shared/cloud-12.png",
                USE_ALPHA);
 
-  texture_load(&img_cloud[1][3], datadir + "/images/shared/cloud-13.png",
+  img_cloud[1][3] = new Surface(datadir + "/images/shared/cloud-13.png",
                USE_ALPHA);
 
 
@@ -245,27 +245,27 @@ void loadshared()
   load_special_gfx();
 
   /* Weapons: */
-  texture_load(&img_red_glow, datadir + "/images/shared/red-glow.png",
+  img_red_glow = new Surface(datadir + "/images/shared/red-glow.png",
                USE_ALPHA);
 
   /* Distros: */
-  texture_load(&img_distro[0], datadir + "/images/shared/distro-0.png",
+  img_distro[0] = new Surface(datadir + "/images/shared/distro-0.png",
                USE_ALPHA);
 
-  texture_load(&img_distro[1], datadir + "/images/shared/distro-1.png",
+  img_distro[1] = new Surface(datadir + "/images/shared/distro-1.png",
                USE_ALPHA);
 
-  texture_load(&img_distro[2], datadir + "/images/shared/distro-2.png",
+  img_distro[2] = new Surface(datadir + "/images/shared/distro-2.png",
                USE_ALPHA);
 
-  texture_load(&img_distro[3], datadir + "/images/shared/distro-3.png",
+  img_distro[3] = new Surface(datadir + "/images/shared/distro-3.png",
                USE_ALPHA);
 
 
   /* Tux life: */
 
-  texture_load(&tux_life, datadir + "/images/shared/tux-life.png",
-               USE_ALPHA);
+  tux_life = new Surface(datadir + "/images/shared/tux-life.png",
+                         USE_ALPHA);
 
   /* Sound effects: */
 
@@ -293,49 +293,49 @@ void unloadshared(void)
 
   for (i = 0; i < 3; i++)
     {
-      texture_free(&tux_right[i]);
-      texture_free(&tux_left[i]);
-      texture_free(&bigtux_right[i]);
-      texture_free(&bigtux_left[i]);
+      delete tux_right[i];
+      delete tux_left[i];
+      delete bigtux_right[i];
+      delete bigtux_left[i];
     }
 
-  texture_free(&bigtux_right_jump);
-  texture_free(&bigtux_left_jump);
+  delete bigtux_right_jump;
+  delete bigtux_left_jump;
 
   for (i = 0; i < 2; i++)
     {
-      texture_free(&cape_right[i]);
-      texture_free(&cape_left[i]);
-      texture_free(&bigcape_right[i]);
-      texture_free(&bigcape_left[i]);
+      delete cape_right[i];
+      delete cape_left[i];
+      delete bigcape_right[i];
+      delete bigcape_left[i];
     }
 
-  texture_free(&ducktux_left);
-  texture_free(&ducktux_right);
+  delete ducktux_left;
+  delete ducktux_right;
 
-  texture_free(&skidtux_left);
-  texture_free(&skidtux_right);
+  delete skidtux_left;
+  delete skidtux_right;
 
   free_badguy_gfx();
 
-  texture_free(&img_box_full);
-  texture_free(&img_box_empty);
+  delete img_box_full;
+  delete img_box_empty;
 
-  texture_free(&img_water);
+  delete img_water;
   for (i = 0; i < 3; i++)
-    texture_free(&img_waves[i]);
+    delete img_waves[i];
 
-  texture_free(&img_pole);
-  texture_free(&img_poletop);
+  delete img_pole;
+  delete img_poletop;
 
   for (i = 0; i < 2; i++)
-    texture_free(&img_flag[i]);
+    delete img_flag[i];
 
   for (i = 0; i < 4; i++)
     {
-      texture_free(&img_distro[i]);
-      texture_free(&img_cloud[0][i]);
-      texture_free(&img_cloud[1][i]);
+      delete img_distro[i];
+      delete img_cloud[0][i];
+      delete img_cloud[1][i];
     }
 
   for (i = 0; i < NUM_SOUNDS; i++)
index e82b077..c4d2340 100644 (file)
@@ -1,17 +1,17 @@
 #ifndef SUPERTUX_RESOURCES_H
 #define SUPERTUX_RESOURCES_H
 
-extern texture_type img_waves[3]; 
-extern texture_type img_water;
-extern texture_type img_pole;
-extern texture_type img_poletop;
-extern texture_type img_flag[2];
-extern texture_type img_cloud[2][4];
+extern Surface* img_waves[3]; 
+extern Surface* img_water;
+extern Surface* img_pole;
+extern Surface* img_poletop;
+extern Surface* img_flag[2];
+extern Surface* img_cloud[2][4];
 
-extern texture_type img_box_full;
-extern texture_type img_box_empty;
-extern texture_type img_super_bkgd;
-extern texture_type img_red_glow;
+extern Surface* img_box_full;
+extern Surface* img_box_empty;
+extern Surface* img_super_bkgd;
+extern Surface* img_red_glow;
 
 void loadshared();
 void unloadshared();
index dba7cf0..7751d23 100644 (file)
@@ -583,11 +583,11 @@ void st_general_setup(void)
   text_load(&yellow_nums,datadir + "/images/status/numbers.png", TEXT_NUM, 32,32);
 
   /* Load GUI/menu images: */
-  texture_load(&checkbox, datadir + "/images/status/checkbox.png", USE_ALPHA);
-  texture_load(&checkbox_checked, datadir + "/images/status/checkbox-checked.png", USE_ALPHA);
-  texture_load(&back, datadir + "/images/status/back.png", USE_ALPHA);
-  texture_load(&arrow_left, datadir + "/images/icons/left.png", USE_ALPHA);
-  texture_load(&arrow_right, datadir + "/images/icons/right.png", USE_ALPHA);
+  checkbox = new Surface(datadir + "/images/status/checkbox.png", USE_ALPHA);
+  checkbox_checked = new Surface(datadir + "/images/status/checkbox-checked.png", USE_ALPHA);
+  back = new Surface(datadir + "/images/status/back.png", USE_ALPHA);
+  arrow_left = new Surface(datadir + "/images/icons/left.png", USE_ALPHA);
+  arrow_right = new Surface(datadir + "/images/icons/right.png", USE_ALPHA);
 
   /* Load the mouse-cursor */
   mouse_cursor = new MouseCursor( datadir + "/images/status/mousecursor.png",1);
@@ -608,11 +608,11 @@ void st_general_free(void)
   text_free(&white_big_text);
 
   /* Free GUI/menu images: */
-  texture_free(&checkbox);
-  texture_free(&checkbox_checked);
-  texture_free(&back);
-  texture_free(&arrow_left);
-  texture_free(&arrow_right);
+  delete checkbox;
+  delete checkbox_checked;
+  delete back;
+  delete arrow_left;
+  delete arrow_right;
 
   /* Free mouse-cursor */
   delete mouse_cursor;
@@ -644,16 +644,12 @@ void st_video_setup(void)
     }
 
   /* Open display: */
-
   if(use_gl)
     st_video_setup_gl();
   else
     st_video_setup_sdl();
 
-  texture_setup();
-
   /* Set window manager stuff: */
-
   SDL_WM_SetCaption("SuperTux " VERSION, "SuperTux");
 
 }
index 9adb971..6bcea59 100644 (file)
 #include "player.h"
 #include "resources.h"
 
-texture_type img_bullet;
-texture_type img_golden_herring;
-texture_type img_growup;
-texture_type img_iceflower;
-texture_type img_1up;
+Surface* img_bullet;
+Surface* img_golden_herring;
+Surface* img_growup;
+Surface* img_iceflower;
+Surface* img_1up;
 
 void
 Bullet::init(float x, float y, float xm, int dir)
@@ -99,7 +99,7 @@ Bullet::draw()
   if (base.x >= scroll_x - base.width &&
       base.x <= scroll_x + screen->w)
     {
-      texture_draw(&img_bullet, base.x - scroll_x, base.y, 255,
+      img_bullet->draw( base.x - scroll_x, base.y, 255,
                    NO_UPDATE);
     }
 }
@@ -230,34 +230,34 @@ Upgrade::draw()
       dest.h = (int)base.height;
 
       if (kind == UPGRADE_GROWUP)
-        texture_draw_part(&img_growup,0,0,dest.x,dest.y,dest.w,dest.h);
+        img_growup->draw_part(0,0,dest.x,dest.y,dest.w,dest.h);
       else if (kind == UPGRADE_ICEFLOWER)
-        texture_draw_part(&img_iceflower,0,0,dest.x,dest.y,dest.w,dest.h);
+        img_iceflower->draw_part(0,0,dest.x,dest.y,dest.w,dest.h);
       else if (kind == UPGRADE_HERRING)
-        texture_draw_part(&img_golden_herring,0,0,dest.x,dest.y,dest.w,dest.h);
+        img_golden_herring->draw_part(0,0,dest.x,dest.y,dest.w,dest.h);
       else if (kind == UPGRADE_1UP)
-        texture_draw_part(&img_1up, 0, 0, dest.x, dest.y, dest.w, dest.h);
+        img_1up->draw_part( 0, 0, dest.x, dest.y, dest.w, dest.h);
     }
   else
     {
       if (kind == UPGRADE_GROWUP)
         {
-          texture_draw(&img_growup,
+          img_growup->draw(
                        base.x - scroll_x, base.y);
         }
       else if (kind == UPGRADE_ICEFLOWER)
         {
-          texture_draw(&img_iceflower,
+          img_iceflower->draw(
                        base.x - scroll_x, base.y);
         }
       else if (kind == UPGRADE_HERRING)
         {
-          texture_draw(&img_golden_herring,
+          img_golden_herring->draw(
                        base.x - scroll_x, base.y);
         }
       else if (kind == UPGRADE_1UP)
         {
-          texture_draw(&img_1up, base.x - scroll_x, base.y);
+          img_1up->draw( base.x - scroll_x, base.y);
         }
     }
 }
@@ -321,24 +321,24 @@ Upgrade::collision(void* p_c_object, int c_object)
 
 void load_special_gfx()
 {
-    texture_load(&img_growup, datadir + "/images/shared/egg.png", USE_ALPHA);
-    texture_load(&img_iceflower, datadir + "/images/shared/iceflower.png",
+    img_growup = new Surface(datadir + "/images/shared/egg.png", USE_ALPHA);
+    img_iceflower = new Surface(datadir + "/images/shared/iceflower.png",
             USE_ALPHA);
-    texture_load(&img_golden_herring, datadir +
+    img_golden_herring = new Surface(datadir +
             "/images/shared/star.png", USE_ALPHA);
-    texture_load(&img_1up, datadir + "/images/shared/1up.png",
+    img_1up = new Surface(datadir + "/images/shared/1up.png",
             USE_ALPHA);
 
-    texture_load(&img_bullet, datadir + "/images/shared/bullet.png",
+    img_bullet = new Surface(datadir + "/images/shared/bullet.png",
             USE_ALPHA);
 }
 
 void free_special_gfx()
 {
-    texture_free(&img_growup);
-    texture_free(&img_iceflower);
-    texture_free(&img_1up);
-    texture_free(&img_golden_herring);
-    texture_free(&img_bullet);
+    delete img_growup;
+    delete img_iceflower;
+    delete img_1up;
+    delete img_golden_herring;
+    delete img_bullet;
 }
 
index f7aed2c..871006f 100644 (file)
@@ -36,7 +36,7 @@ Sprite::Sprite(lisp_object_t* cur)
 
   for(std::vector<std::string>::size_type i = 0; i < images.size(); ++i)
     {
-      texture_load(&surfaces[i], datadir + "/images/" + images[i], USE_ALPHA);
+      surfaces[i] = new Surface(datadir + "/images/" + images[i], USE_ALPHA);
     }        
 }
 
@@ -70,7 +70,7 @@ Sprite::draw(int x, int y)
             << frame_delay << " "
             << static_cast<int>(fmodf(time, surfaces.size()*frame_delay)/frame_delay) << std::endl;*/
   if (frame < surfaces.size())
-    texture_draw(&surfaces[frame], x - x_hotspot, y - y_hotspot);
+    surfaces[frame]->draw(x - x_hotspot, y - y_hotspot);
 }
 
 /* EOF */
index dcd4b72..6b02548 100644 (file)
@@ -40,7 +40,7 @@ class Sprite
 
   float time;
 
-  std::vector<texture_type> surfaces;
+  std::vector<Surface*> surfaces;
 
   void init_defaults();
  public:
index 8258b74..f095ab5 100644 (file)
@@ -43,10 +43,10 @@ void text_load(text_type* ptext, const std::string& file, int kind, int w, int h
   ptext->w = w;
   ptext->h = h;
 
-  texture_load(&ptext->chars, file, USE_ALPHA);
+  ptext->chars = new Surface(file, USE_ALPHA);
 
   /* Load shadow font. */
-  conv = SDL_DisplayFormatAlpha(ptext->chars.sdl_surface);
+  conv = SDL_DisplayFormatAlpha(ptext->chars->impl->sdl_surface);
   pixels = conv->w * conv->h;
   SDL_LockSurface(conv);
   for(i = 0; i < pixels; ++i)
@@ -56,7 +56,7 @@ void text_load(text_type* ptext, const std::string& file, int kind, int w, int h
     }
   SDL_UnlockSurface(conv);
   SDL_SetAlpha(conv, SDL_SRCALPHA, 128);
-  texture_from_sdl_surface(&ptext->shadow_chars,conv,USE_ALPHA);
+  ptext->shadow_chars = new Surface(conv, USE_ALPHA);
 
   SDL_FreeSurface(conv);
 }
@@ -66,13 +66,13 @@ void text_draw(text_type* ptext,const  char* text, int x, int y, int shadowsize,
   if(text != NULL)
     {
       if(shadowsize != 0)
-        text_draw_chars(ptext,&ptext->shadow_chars, text,x+shadowsize,y+shadowsize, update);
+        text_draw_chars(ptext, ptext->shadow_chars, text,x+shadowsize,y+shadowsize, update);
 
-      text_draw_chars(ptext,&ptext->chars, text,x,y, update);
+      text_draw_chars(ptext, ptext->chars, text,x,y, update);
     }
 }
 
-void text_draw_chars(text_type* ptext, texture_type* pchars,const  char* text, int x, int y, int update)
+void text_draw_chars(text_type* ptext, Surface* pchars,const  char* text, int x, int y, int update)
 {
   int i,j,len;
   int w, h;
@@ -86,13 +86,13 @@ void text_draw_chars(text_type* ptext, texture_type* pchars,const  char* text, i
       for( i = 0, j = 0; i < len; ++i,++j)
         {
           if( text[i] >= 'A' && text[i] <= 'Z')
-            texture_draw_part(pchars, (int)(text[i] - 'A')*w, 0, x+(j*w), y, ptext->w, ptext->h, 255,  update);
+            pchars->draw_part((int)(text[i] - 'A')*w, 0, x+(j*w), y, ptext->w, ptext->h, 255,  update);
           else if( text[i] >= 'a' && text[i] <= 'z')
-            texture_draw_part(pchars, (int)(text[i] - 'a')*w, h, x+(j*w), y, ptext->w, ptext->h, 255,  update);
+            pchars->draw_part((int)(text[i] - 'a')*w, h, x+(j*w), y, ptext->w, ptext->h, 255,  update);
           else if ( text[i] >= '!' && text[i] <= '9')
-            texture_draw_part(pchars, (int)(text[i] - '!')*w, h*2, x+(j*w), y, ptext->w, ptext->h, 255,  update);
+            pchars->draw_part((int)(text[i] - '!')*w, h*2, x+(j*w), y, ptext->w, ptext->h, 255,  update);
           else if ( text[i] == '?')
-            texture_draw_part(pchars, 25*w, h*2, x+(j*w), y, ptext->w, ptext->h, 255,  update);
+            pchars->draw_part(25*w, h*2, x+(j*w), y, ptext->w, ptext->h, 255,  update);
           else if ( text[i] == '\n')
             {
               y += ptext->h + 2;
@@ -105,7 +105,7 @@ void text_draw_chars(text_type* ptext, texture_type* pchars,const  char* text, i
       for( i = 0, j = 0; i < len; ++i, ++j)
         {
           if ( text[i] >= '0' && text[i] <= '9')
-            texture_draw_part(pchars, (int)(text[i] - '0')*w, 0, x+(j*w), y, w, h, 255, update);
+            pchars->draw_part((int)(text[i] - '0')*w, 0, x+(j*w), y, w, h, 255, update);
           else if ( text[i] == '\n')
             {
               y += ptext->h + 2;
@@ -172,14 +172,14 @@ void text_drawf(text_type* ptext,const  char* text, int x, int y, TextHAlign hal
 void text_free(text_type* ptext)
 {
   if(ptext->kind == TEXT_TEXT)
-    texture_free(&ptext->chars);
+    delete ptext->chars;
   else if(ptext->kind == TEXT_NUM)
-    texture_free(&ptext->chars);
+    delete ptext->chars;
 }
 
 /* --- ERASE TEXT: --- */
 
-void erasetext(text_type* ptext,const  char * text, int x, int y, texture_type * ptexture, int update, int shadowsize)
+void erasetext(text_type* ptext,const  char * text, int x, int y, Surface * ptexture, int update, int shadowsize)
 {
   SDL_Rect dest;
 
@@ -192,7 +192,7 @@ void erasetext(text_type* ptext,const  char * text, int x, int y, texture_type *
   if (dest.w > screen->w)
     dest.w = screen->w;
 
-  texture_draw_part(ptexture,dest.x,dest.y,dest.x,dest.y,dest.w,dest.h, 255, update);
+  ptexture->draw_part(dest.x,dest.y,dest.x,dest.y,dest.w,dest.h, 255, update);
 
   if (update == UPDATE)
     update_rect(screen, dest.x, dest.y, dest.w, dest.h);
@@ -201,7 +201,7 @@ void erasetext(text_type* ptext,const  char * text, int x, int y, texture_type *
 
 /* --- ERASE CENTERED TEXT: --- */
 
-void erasecenteredtext(text_type* ptext,const  char * text, int y, texture_type * ptexture, int update, int shadowsize)
+void erasecenteredtext(text_type* ptext,const  char * text, int y, Surface * ptexture, int update, int shadowsize)
 {
   erasetext(ptext, text, screen->w / 2 - (strlen(text) * 8), y, ptexture, update, shadowsize);
 }
index f14343f..d6f52e1 100644 (file)
@@ -18,8 +18,8 @@
 /* Text type */
 struct text_type
 {
-  texture_type chars;
-  texture_type shadow_chars;
+  Surface* chars;
+  Surface* shadow_chars;
   int kind;
   int w;
   int h;
@@ -45,12 +45,12 @@ enum TextVAlign {
 
 void text_load(text_type* ptext, const std::string& file, int kind, int w, int h);
 void text_draw(text_type* ptext, const char* text, int x, int y, int shadowsize, int update = NO_UPDATE);
-void text_draw_chars(text_type* ptext, texture_type* pchars, const char* text, int x, int y, int update = NO_UPDATE);
+void text_draw_chars(text_type* ptext, Surface* pchars, const char* text, int x, int y, int update = NO_UPDATE);
 void text_drawf(text_type* ptext, const char* text, int x, int y, TextHAlign halign, TextVAlign valign, int shadowsize, int update = NO_UPDATE);
 void text_draw_align(text_type* ptext, const char* text, int x, int y, TextHAlign halign, TextVAlign valign, int shadowsize, int update = NO_UPDATE);
 void text_free(text_type* ptext);
-void erasetext(text_type* ptext, const char * text, int x, int y, texture_type * surf, int update, int shadowsize);
-void erasecenteredtext(text_type* ptext, const char * text, int y, texture_type * surf, int update, int shadowsize);
+void erasetext(text_type* ptext, const char * text, int x, int y, Surface* surf, int update, int shadowsize);
+void erasecenteredtext(text_type* ptext, const char * text, int y, Surface* surf, int update, int shadowsize);
 
 #endif /*SUPERTUX_TEXT_H*/
 
index ea6ce13..ae7cec4 100644 (file)
 
 #include "SDL.h"
 #include "SDL_image.h"
+#include "texture.h"
 #include "globals.h"
-#include "screen.h"
 #include "setup.h"
-#include "texture.h"
 
-#define NO_TEXTURE 0
+/* Quick utility function for texture creation */
+static int power_of_two(int input)
+{
+  int value = 1;
 
-void (*texture_load)     (texture_type* ptexture, const std::string& file, int use_alpha);
-void (*texture_load_part)(texture_type* ptexture, const std::string& file, int x, int y, int w, int h, int use_alpha);
-void (*texture_free)     (texture_type* ptexture);  
-void (*texture_draw)     (texture_type* ptexture, float x, float y, Uint8 alpha, bool update);  
-void (*texture_draw_bg)  (texture_type* ptexture, Uint8 alpha,  bool update);  
-void (*texture_draw_part)(texture_type* ptexture, float sx, float sy, float x, float y, float w, float h, Uint8 alpha, bool update);
+  while ( value < input ) {
+    value <<= 1;
+  }
+  return value;
+}
 
+Surface::Surface(SDL_Surface* surf, int use_alpha)
+{
+  if (use_gl)
+    impl = new SurfaceOpenGL(surf, use_alpha);
+  else
+    impl = new SurfaceSDL(surf, use_alpha);
+
+  w = impl->w;
+ h = impl->h;
+}
 
-void texture_setup(void)
+Surface::Surface(const std::string& file, int use_alpha)
 {
-#ifdef NOOPENGL
-  texture_load = texture_load_sdl;
-  texture_load_part = texture_load_part_sdl;
-  texture_free = texture_free_sdl;
-  texture_draw = texture_draw_sdl;
-  texture_draw_bg = texture_draw_bg_sdl;
-  texture_draw_part = texture_draw_part_sdl;
-#else
+  if (use_gl)
+    impl = new SurfaceOpenGL(file, use_alpha);
+  else
+    impl = new SurfaceSDL(file, use_alpha);
+
+  w = impl->w;
+  h = impl->h;
+}
+
+Surface::Surface(const std::string& file, int x, int y, int w, int h, int use_alpha)
+{
+  if (use_gl)
+    impl = new SurfaceOpenGL(file, x, y, w, h, use_alpha);
+  else
+    impl = new SurfaceSDL(file, x, y, w, h, use_alpha);
+
+  w = impl->w;
+  h = impl->h;
+}
+
+Surface::~Surface()
+{
+  delete impl;
+}
+
+void
+Surface::draw(float x, float y, Uint8 alpha, bool update)
+{
+  if (impl) impl->draw(x, y, alpha, update);
+}
+
+void
+Surface::draw_bg(Uint8 alpha, bool update)
+{
+  if (impl) impl->draw_bg(alpha, update);
+}
+
+void
+Surface::draw_part(float sx, float sy, float x, float y, float w, float h,  Uint8 alpha, bool update)
+{
+  if (impl) impl->draw_part(sx, sy, x, y, w, h, alpha, update);
+}
+
+SDL_Surface*
+sdl_surface_part_from_file(const std::string& file, int x, int y, int w, int h,  int use_alpha)
+{
+  SDL_Rect src;
+  SDL_Surface * sdl_surface;
+  SDL_Surface * temp;
+  SDL_Surface * conv;
+
+  temp = IMG_Load(file.c_str());
+
+  if (temp == NULL)
+    st_abort("Can't load", file);
+
+  /* Set source rectangle for conv: */
+
+  src.x = x;
+  src.y = y;
+  src.w = w;
+  src.h = h;
+
+  conv = SDL_CreateRGBSurface(temp->flags, w, h, temp->format->BitsPerPixel,
+                              temp->format->Rmask,
+                              temp->format->Gmask,
+                              temp->format->Bmask,
+                              temp->format->Amask);
+
+  /* #if SDL_BYTEORDER == SDL_BIG_ENDIAN
+     0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff);
+     #else
+
+     0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000);
+     #endif*/
+
+  SDL_SetAlpha(temp,0,0);
+
+  SDL_BlitSurface(temp, &src, conv, NULL);
+  if(use_alpha == IGNORE_ALPHA && !use_gl)
+    sdl_surface = SDL_DisplayFormat(conv);
+  else
+    sdl_surface = SDL_DisplayFormatAlpha(conv);
+
+  if (sdl_surface == NULL)
+    st_abort("Can't covert to display format", file);
+
+  if (use_alpha == IGNORE_ALPHA && !use_gl)
+    SDL_SetAlpha(sdl_surface, 0, 0);
+
+  SDL_FreeSurface(temp);
+  SDL_FreeSurface(conv);
+  
+  return sdl_surface;
+}
+
+SDL_Surface*
+sdl_surface_from_file(const std::string& file, int use_alpha)
+{
+  SDL_Surface* sdl_surface;
+  SDL_Surface* temp;
+  
+  temp = IMG_Load(file.c_str());
+
+  if (temp == NULL)
+    st_abort("Can't load", file);
+
+  if(use_alpha == IGNORE_ALPHA && !use_gl)
+    sdl_surface = SDL_DisplayFormat(temp);
+  else
+    sdl_surface = SDL_DisplayFormatAlpha(temp);
+  
+  if (sdl_surface == NULL)
+    st_abort("Can't covert to display format", file);
+
+  if (use_alpha == IGNORE_ALPHA && !use_gl)
+    SDL_SetAlpha(sdl_surface, 0, 0);
+
+  SDL_FreeSurface(temp);
+
+  return sdl_surface;
+}
 
-  if(use_gl)
+SDL_Surface* 
+sdl_surface_from_sdl_surface(SDL_Surface* sdl_surf, int use_alpha)
+{
+  SDL_Surface* sdl_surface;
+  Uint32 saved_flags;
+  Uint8  saved_alpha;
+  
+  /* Save the alpha blending attributes */
+  saved_flags = sdl_surf->flags&(SDL_SRCALPHA|SDL_RLEACCELOK);
+  saved_alpha = sdl_surf->format->alpha;
+  if ( (saved_flags & SDL_SRCALPHA)
+       == SDL_SRCALPHA )
     {
-      texture_load = texture_load_gl;
-      texture_load_part = texture_load_part_gl;
-      texture_free = texture_free_gl;
-      texture_draw = texture_draw_gl;
-      texture_draw_bg = texture_draw_bg_gl;
-      texture_draw_part = texture_draw_part_gl;
+      SDL_SetAlpha(sdl_surf, 0, 0);
     }
+   
+  if(use_alpha == IGNORE_ALPHA && !use_gl)
+    sdl_surface = SDL_DisplayFormat(sdl_surf);
   else
+    sdl_surface = SDL_DisplayFormatAlpha(sdl_surf);
+
+  /* Restore the alpha blending attributes */
+  if ( (saved_flags & SDL_SRCALPHA)
+       == SDL_SRCALPHA )
     {
-      texture_load = texture_load_sdl;
-      texture_load_part = texture_load_part_sdl;
-      texture_free = texture_free_sdl;
-      texture_draw = texture_draw_sdl;
-      texture_draw_bg = texture_draw_bg_sdl;
-      texture_draw_part = texture_draw_part_sdl;
+      SDL_SetAlpha(sdl_surface, saved_flags, saved_alpha);
     }
-#endif
+  
+  if (sdl_surface == NULL)
+    st_abort("Can't covert to display format", "SURFACE");
+
+  if (use_alpha == IGNORE_ALPHA && !use_gl)
+    SDL_SetAlpha(sdl_surface, 0, 0);
+
+  return sdl_surface;
 }
 
 #ifndef NOOPENGL
-void texture_load_gl(texture_type* ptexture, const std::string& file, int use_alpha)
+SurfaceOpenGL::SurfaceOpenGL(SDL_Surface* surf, int use_alpha)
 {
-  texture_load_sdl(ptexture,file,use_alpha);
-  texture_create_gl(ptexture->sdl_surface,&ptexture->gl_texture);
+  sdl_surface = sdl_surface_from_sdl_surface(surf, use_alpha);
+  create_gl(sdl_surface,&gl_texture);
+
+  w = sdl_surface->w;
+  h = sdl_surface->h;
 }
 
-void texture_load_part_gl(texture_type* ptexture, const std::string& file, int x, int y, int w, int h, int use_alpha)
+SurfaceOpenGL::SurfaceOpenGL(const std::string& file, int use_alpha) 
 {
-  texture_load_part_sdl(ptexture,file,x,y,w,h,use_alpha);
-  texture_create_gl(ptexture->sdl_surface,&ptexture->gl_texture);
+  sdl_surface = sdl_surface_from_file(file, use_alpha);
+  create_gl(sdl_surface,&gl_texture);
+
+  w = sdl_surface->w;
+  h = sdl_surface->h;
 }
 
-/* Quick utility function for texture creation */
-static int power_of_two(int input)
+SurfaceOpenGL::SurfaceOpenGL(const std::string& file, int x, int y, int w, int h, int use_alpha)
 {
-  int value = 1;
+  sdl_surface = sdl_surface_part_from_file(file,x,y,w,h,use_alpha);
+  create_gl(sdl_surface, &gl_texture);
 
-  while ( value < input ) {
-    value <<= 1;
-  }
-  return value;
+  w = sdl_surface->w;
+  h = sdl_surface->h;
 }
 
-void texture_create_gl(SDL_Surface * surf, GLuint * tex)
+SurfaceOpenGL::~SurfaceOpenGL()
+{
+  SDL_FreeSurface(sdl_surface);
+  glDeleteTextures(1, &gl_texture);
+}
+
+void
+SurfaceOpenGL::create_gl(SDL_Surface * surf, GLuint * tex)
 {
   Uint32 saved_flags;
   Uint8  saved_alpha;
   int w, h;
   SDL_Surface *conv;
-  
+
   w = power_of_two(surf->w);
   h = power_of_two(surf->h),
-  conv = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, surf->format->BitsPerPixel,
+
 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
-                              0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff);
+    conv = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, surf->format->BitsPerPixel,
+                                0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff);
 #else
-
+  conv = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, surf->format->BitsPerPixel,
                               0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000);
 #endif
 
@@ -131,19 +284,11 @@ void texture_create_gl(SDL_Surface * surf, GLuint * tex)
   SDL_FreeSurface(conv);
 }
 
-void texture_free_gl(texture_type* ptexture)
-{
-  SDL_FreeSurface(ptexture->sdl_surface);
-  glDeleteTextures(1, &ptexture->gl_texture);
-}
-
-void texture_draw_gl(texture_type* ptexture, float x, float y, Uint8 alpha, bool update)
+void
+SurfaceOpenGL::draw(float x, float y, Uint8 alpha, bool update)
 {
-if(ptexture->gl_texture == NO_TEXTURE)
-  texture_create_gl(ptexture->sdl_surface,&ptexture->gl_texture);
-
-float pw = power_of_two(ptexture->w);
-float ph = power_of_two(ptexture->h);
+  float pw = power_of_two(w);
+  float ph = power_of_two(h);
 
   glEnable(GL_TEXTURE_2D);
   glEnable(GL_BLEND);
@@ -151,66 +296,62 @@ float ph = power_of_two(ptexture->h);
 
   glColor4ub(alpha, alpha, alpha, alpha);
 
-  glBindTexture(GL_TEXTURE_2D, ptexture->gl_texture);
+  glBindTexture(GL_TEXTURE_2D, gl_texture);
 
   glBegin(GL_QUADS);
   glTexCoord2f(0, 0);
   glVertex2f(x, y);
-  glTexCoord2f((float)ptexture->w / pw, 0);
-  glVertex2f((float)ptexture->w+x, y);
-  glTexCoord2f((float)ptexture->w / pw, (float)ptexture->h / ph);  glVertex2f((float)ptexture->w+x, (float)ptexture->h+y);
-  glTexCoord2f(0, (float)ptexture->h / ph);
-  glVertex2f(x, (float)ptexture->h+y);
+  glTexCoord2f((float)w / pw, 0);
+  glVertex2f((float)w+x, y);
+  glTexCoord2f((float)w / pw, (float)h / ph);  glVertex2f((float)w+x, (float)h+y);
+  glTexCoord2f(0, (float)h / ph);
+  glVertex2f(x, (float)h+y);
   glEnd();
   
   glDisable(GL_TEXTURE_2D);
   glDisable(GL_BLEND);
   
-/* Avoid compiler warnings */
-if(update)
-{}
+  /* Avoid compiler warnings */
+  if(update)
+    {}
 }
 
-void texture_draw_bg_gl(texture_type* ptexture, Uint8 alpha, bool update)
+void
+SurfaceOpenGL::draw_bg(Uint8 alpha, bool update)
 {
-if(ptexture->gl_texture == NO_TEXTURE)
-  texture_create_gl(ptexture->sdl_surface,&ptexture->gl_texture);
-
-float pw = power_of_two(ptexture->w);
-float ph = power_of_two(ptexture->h);
+  float pw = power_of_two(w);
+  float ph = power_of_two(h);
 
   glColor3ub(alpha, alpha, alpha);
 
   glEnable(GL_TEXTURE_2D);
-  glBindTexture(GL_TEXTURE_2D, ptexture->gl_texture);
+  glBindTexture(GL_TEXTURE_2D, gl_texture);
 
   glBegin(GL_QUADS);
   glTexCoord2f(0, 0);
   glVertex2f(0, 0);
-  glTexCoord2f((float)ptexture->w / pw, 0);
+  glTexCoord2f((float)w / pw, 0);
   glVertex2f(screen->w, 0);
-  glTexCoord2f((float)ptexture->w / pw, (float)ptexture->h / ph);
+  glTexCoord2f((float)w / pw, (float)h / ph);
   glVertex2f(screen->w, screen->h);
-  glTexCoord2f(0, (float)ptexture->h / ph);
+  glTexCoord2f(0, (float)h / ph);
   glVertex2f(0, screen->h);
   glEnd();
   
   glDisable(GL_TEXTURE_2D);
 
-/* Avoid compiler warnings */
-if(update)
-{}
+  /* Avoid compiler warnings */
+  if(update)
+    {}
 }
 
-void texture_draw_part_gl(texture_type* ptexture,float sx, float sy, float x, float y, float w, float h, Uint8 alpha, bool update)
+void
+SurfaceOpenGL::draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, bool update)
 {
-if(ptexture->gl_texture == NO_TEXTURE)
-  texture_create_gl(ptexture->sdl_surface,&ptexture->gl_texture);
+  float pw = power_of_two(int(this->w));
+  float ph = power_of_two(int(this->h));
 
-float pw = power_of_two(ptexture->w);
-float ph = power_of_two(ptexture->h);
-
-  glBindTexture(GL_TEXTURE_2D, ptexture->gl_texture);
+  glBindTexture(GL_TEXTURE_2D, gl_texture);
 
   glEnable(GL_BLEND);
   glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@@ -234,158 +375,55 @@ float ph = power_of_two(ptexture->h);
   glDisable(GL_TEXTURE_2D);
   glDisable(GL_BLEND);
 
-/* Avoid compiler warnings */
-if(update)
-{}
+  /* Avoid compiler warnings */
+  if(update)
+    {}
 }
 #endif
 
-void texture_load_sdl(texture_type* ptexture, const std::string& file, int use_alpha)
+SurfaceSDL::SurfaceSDL(SDL_Surface* surf, int use_alpha)
 {
-  SDL_Surface * temp;
-  
-  temp = IMG_Load(file.c_str());
-
-  if (temp == NULL)
-    st_abort("Can't load", file);
-
-  if(use_alpha == IGNORE_ALPHA && !use_gl)
-  ptexture->sdl_surface = SDL_DisplayFormat(temp);
-  else
-  ptexture->sdl_surface = SDL_DisplayFormatAlpha(temp);
-  
-  if (ptexture->sdl_surface == NULL)
-    st_abort("Can't covert to display format", file);
-
-  if (use_alpha == IGNORE_ALPHA && !use_gl)
-    SDL_SetAlpha(ptexture->sdl_surface, 0, 0);
-
-  SDL_FreeSurface(temp);
-
-  ptexture->w = ptexture->sdl_surface->w;
-  ptexture->h = ptexture->sdl_surface->h;
-  
-  ptexture->gl_texture = NO_TEXTURE;
+  sdl_surface = sdl_surface_from_sdl_surface(surf, use_alpha);
+  w = sdl_surface->w;
+  h = sdl_surface->h;
 }
 
-void texture_load_part_sdl(texture_type* ptexture, const std::string& file, int x, int y, int w, int h,  int use_alpha)
+SurfaceSDL::SurfaceSDL(const std::string& file, int use_alpha)
 {
-
-  SDL_Rect src;
-  SDL_Surface * temp;
-  SDL_Surface * conv;
-
-  temp = IMG_Load(file.c_str());
-
-  if (temp == NULL)
-    st_abort("Can't load", file);
-
-  /* Set source rectangle for conv: */
-
-  src.x = x;
-  src.y = y;
-  src.w = w;
-  src.h = h;
-
-  conv = SDL_CreateRGBSurface(temp->flags, w, h, temp->format->BitsPerPixel,
-                              temp->format->Rmask,
-                              temp->format->Gmask,
-                              temp->format->Bmask,
-                              temp->format->Amask);
-
-  /* #if SDL_BYTEORDER == SDL_BIG_ENDIAN
-                               0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff);
-  #else
-
-                               0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000);
-  #endif*/
-
-  SDL_SetAlpha(temp,0,0);
-
-  SDL_BlitSurface(temp, &src, conv, NULL);
-  if(use_alpha == IGNORE_ALPHA && !use_gl)
-  ptexture->sdl_surface = SDL_DisplayFormat(conv);
-  else
-  ptexture->sdl_surface = SDL_DisplayFormatAlpha(conv);
-
-  if (ptexture->sdl_surface == NULL)
-    st_abort("Can't covert to display format", file);
-
-  if (use_alpha == IGNORE_ALPHA && !use_gl)
-    SDL_SetAlpha(ptexture->sdl_surface, 0, 0);
-
-  SDL_FreeSurface(temp);
-  SDL_FreeSurface(conv);
-
-  ptexture->w = ptexture->sdl_surface->w;
-  ptexture->h = ptexture->sdl_surface->h;
+  sdl_surface = sdl_surface_from_file(file, use_alpha);
+  w = sdl_surface->w;
+  h = sdl_surface->h;
 }
 
-void texture_from_sdl_surface(texture_type* ptexture, SDL_Surface* sdl_surf, int use_alpha)
+SurfaceSDL::SurfaceSDL(const std::string& file, int x, int y, int w, int h,  int use_alpha)
 {
-  Uint32 saved_flags;
-  Uint8  saved_alpha;
-  
-  /* Save the alpha blending attributes */
-  saved_flags = sdl_surf->flags&(SDL_SRCALPHA|SDL_RLEACCELOK);
-  saved_alpha = sdl_surf->format->alpha;
-  if ( (saved_flags & SDL_SRCALPHA)
-       == SDL_SRCALPHA )
-    {
-      SDL_SetAlpha(sdl_surf, 0, 0);
-    }
-   
-  if(use_alpha == IGNORE_ALPHA && !use_gl)
-  ptexture->sdl_surface = SDL_DisplayFormat(sdl_surf);
-  else
-  ptexture->sdl_surface = SDL_DisplayFormatAlpha(sdl_surf);
-
-  /* Restore the alpha blending attributes */
-  if ( (saved_flags & SDL_SRCALPHA)
-       == SDL_SRCALPHA )
-    {
-      SDL_SetAlpha(ptexture->sdl_surface, saved_flags, saved_alpha);
-    }
-  
-  if (ptexture->sdl_surface == NULL)
-    st_abort("Can't covert to display format", "SURFACE");
-
-  if (use_alpha == IGNORE_ALPHA && !use_gl)
-    SDL_SetAlpha(ptexture->sdl_surface, 0, 0);
-
-  ptexture->w = ptexture->sdl_surface->w;
-  ptexture->h = ptexture->sdl_surface->h;
-
-#ifndef NOOPENGL
-
-  if(use_gl)
-    {
-      texture_create_gl(ptexture->sdl_surface,&ptexture->gl_texture);
-    }
-#endif
+  sdl_surface = sdl_surface_part_from_file(file, x, y, w, h, use_alpha);
+  w = sdl_surface->w;
+  h = sdl_surface->h;
 }
 
-void texture_draw_sdl(texture_type* ptexture, float x, float y, Uint8 alpha, bool update)
+void
+SurfaceSDL::draw(float x, float y, Uint8 alpha, bool update)
 {
   SDL_Rect dest;
 
   dest.x = (int)x;
   dest.y = (int)y;
-  dest.w = ptexture->w;
-  dest.h = ptexture->h;
+  dest.w = w;
+  dest.h = h;
   
   if(alpha != 255) /* SDL isn't capable of this kind of alpha :( therefore we'll leave now. */
   return;
   
-  SDL_SetAlpha(ptexture->sdl_surface ,SDL_SRCALPHA,alpha);
-  SDL_BlitSurface(ptexture->sdl_surface, NULL, screen, &dest);
+  SDL_SetAlpha(sdl_surface ,SDL_SRCALPHA,alpha);
+  SDL_BlitSurface(sdl_surface, NULL, screen, &dest);
   
   if (update == UPDATE)
     SDL_UpdateRect(screen, dest.x, dest.y, dest.w, dest.h);
 }
 
-
-void texture_draw_bg_sdl(texture_type* ptexture, Uint8 alpha, bool update)
+void
+SurfaceSDL::draw_bg(Uint8 alpha, bool update)
 {
   SDL_Rect dest;
   
@@ -395,14 +433,15 @@ void texture_draw_bg_sdl(texture_type* ptexture, Uint8 alpha, bool update)
   dest.h = screen->h;
 
   if(alpha != 255)
-  SDL_SetAlpha(ptexture->sdl_surface ,SDL_SRCALPHA,alpha);
-  SDL_SoftStretch(ptexture->sdl_surface, NULL, screen, &dest);
+  SDL_SetAlpha(sdl_surface ,SDL_SRCALPHA,alpha);
+  SDL_SoftStretch(sdl_surface, NULL, screen, &dest);
   
   if (update == UPDATE)
     SDL_UpdateRect(screen, dest.x, dest.y, dest.w, dest.h);
 }
 
-void texture_draw_part_sdl(texture_type* ptexture, float sx, float sy, float x, float y, float w, float h, Uint8 alpha, bool update)
+void
+SurfaceSDL::draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, bool update)
 {
   SDL_Rect src, dest;
 
@@ -417,20 +456,17 @@ void texture_draw_part_sdl(texture_type* ptexture, float sx, float sy, float x,
   dest.h = (int)h;
 
   if(alpha != 255)
-  SDL_SetAlpha(ptexture->sdl_surface ,SDL_SRCALPHA,alpha);
+  SDL_SetAlpha(sdl_surface ,SDL_SRCALPHA,alpha);
   
-  SDL_BlitSurface(ptexture->sdl_surface, &src, screen, &dest);
+  SDL_BlitSurface(sdl_surface, &src, screen, &dest);
 
   if (update == UPDATE)
     update_rect(screen, dest.x, dest.y, dest.w, dest.h);
 }
 
-void texture_free_sdl(texture_type* ptexture)
+SurfaceSDL::~SurfaceSDL()
 {
-  SDL_FreeSurface(ptexture->sdl_surface);
-#ifndef NOOPENGL
-  if(ptexture->gl_texture != NO_TEXTURE)
-    glDeleteTextures(1, &ptexture->gl_texture);
-#endif
+  SDL_FreeSurface(sdl_surface);
 }
 
+/* EOF */
index 1efd6e5..36567f5 100644 (file)
 
 #include "screen.h"
 
-/* Texture type */
-struct texture_type
+class SurfaceImpl;
+
+/** Container class that holds a surface, necessary so that we can
+    switch Surface implementations (OpenGL, SDL) on the fly */
+class Surface
+{
+public:
+  SurfaceImpl* impl;
+  int w; 
+  int h;
+public:
+  Surface(SDL_Surface* surf, int use_alpha);  
+  Surface(const std::string& file, int use_alpha);  
+  Surface(const std::string& file, int x, int y, int w, int h, int use_alpha);
+  ~Surface();
+
+  void draw(float x, float y, Uint8 alpha = 255, bool update = false);
+  void draw_bg(Uint8 alpha = 255, bool update = false);
+  void draw_part(float sx, float sy, float x, float y, float w, float h,  Uint8 alpha = 255, bool update = false);
+};
+
+/** Surface implementation, all implementation have to inherit from
+    this class */
+class SurfaceImpl
 {
+public:
   SDL_Surface* sdl_surface;
-  unsigned gl_texture;
   int w;
   int h;
+
+public:
+  virtual void draw(float x, float y, Uint8 alpha, bool update) = 0;
+  virtual void draw_bg(Uint8 alpha, bool update) = 0;
+  virtual void draw_part(float sx, float sy, float x, float y, float w, float h,  Uint8 alpha, bool update) = 0;
 };
 
-void texture_setup(void);
-extern void (*texture_load) (texture_type* ptexture, const std::string& file, int use_alpha);  
-extern void (*texture_load_part) (texture_type* ptexture, const std::string& file, int x, int y, int w, int h, int use_alpha);
-extern void (*texture_free) (texture_type* ptexture);  
-extern void (*texture_draw) (texture_type* ptexture, float x, float y, Uint8 alpha = 255, bool update = false);
-extern void (*texture_draw_bg) (texture_type* ptexture,  Uint8 alpha = 255, bool update = false);
-extern void (*texture_draw_part) (texture_type* ptexture, float sx, float sy, float x, float y, float w, float h,  Uint8 alpha = 255, bool update = false);
-void texture_load_sdl(texture_type* ptexture, const std::string&, int use_alpha);
-void texture_load_part_sdl(texture_type* ptexture, const std::string& file, int x, int y, int w, int h, int use_alpha);
-void texture_free_sdl(texture_type* ptexture);
-void texture_draw_sdl(texture_type* ptexture, float x, float y, Uint8 alpha, bool update);
-void texture_draw_bg_sdl(texture_type* ptexture,  Uint8 alpha, bool update);
-void texture_draw_part_sdl(texture_type* ptexture,float sx, float sy, float x, float y, float w, float h,  Uint8 alpha, bool update);
-void texture_from_sdl_surface(texture_type* ptexture, SDL_Surface * sdl_surf, int use_alpha);
-#ifndef NOOPENGL
-void texture_load_gl(texture_type* ptexture, const std::string& file, int use_alpha);
-void texture_load_part_gl(texture_type* ptexture, const std::string& file, int x, int y, int w, int h, int use_alpha);
-void texture_free_gl(texture_type* ptexture);
-void texture_draw_gl(texture_type* ptexture, float x, float y,  Uint8 alpha, bool update);
-void texture_draw_bg_gl(texture_type* ptexture,  Uint8 alpha, bool update);
-void texture_draw_part_gl(texture_type* ptexture, float sx, float sy, float x, float y, float w, float h,  Uint8 alpha, bool update);
-void texture_create_gl(SDL_Surface * surf, GLuint * tex);
-#endif
+class SurfaceSDL : public SurfaceImpl
+{
+public:
+  
+public:
+  SurfaceSDL(SDL_Surface* surf, int use_alpha);
+  SurfaceSDL(const std::string& file, int use_alpha);  
+  SurfaceSDL(const std::string& file, int x, int y, int w, int h, int use_alpha);
+  virtual ~SurfaceSDL();
+
+  void draw(float x, float y, Uint8 alpha, bool update);
+  void draw_bg(Uint8 alpha, bool update);
+  void draw_part(float sx, float sy, float x, float y, float w, float h,  Uint8 alpha, bool update);
+};
+
+class SurfaceOpenGL : public SurfaceImpl
+{
+public:
+  unsigned gl_texture;
+
+public:
+  SurfaceOpenGL(SDL_Surface* surf, int use_alpha);
+  SurfaceOpenGL(const std::string& file, int use_alpha);  
+  SurfaceOpenGL(const std::string& file, int x, int y, int w, int h, int use_alpha);
+  virtual ~SurfaceOpenGL();
+
+  void draw(float x, float y, Uint8 alpha, bool update);
+  void draw_bg(Uint8 alpha, bool update);
+  void draw_part(float sx, float sy, float x, float y, float w, float h,  Uint8 alpha, bool update);
+
+private:
+  void create_gl(SDL_Surface * surf, GLuint * tex);
+};
 
 #endif /*SUPERTUX_TEXTURE_H*/
 
+/* Local Variables: */
+/* mode: c++ */
+/* End */
index daa63f9..e212d49 100644 (file)
@@ -73,9 +73,9 @@ void TileManager::load_tileset(std::string filename)
                   it != tile->filenames.end();
                   ++it)
                 {
-                  texture_type cur_image;
+                  Surface* cur_image;
                   tile->images.push_back(cur_image);
-                  texture_load(&tile->images[tile->images.size()-1],
+                  tile->images[tile->images.size()-1] = new Surface(
                                datadir +  "images/tilesets/" + (*it),
                                USE_ALPHA);
                 }
@@ -83,9 +83,9 @@ void TileManager::load_tileset(std::string filename)
                   it != editor_filenames.end();
                   ++it)
                 {
-                  texture_type cur_image;
+                  Surface* cur_image;
                   tile->editor_images.push_back(cur_image);
-                  texture_load(&tile->editor_images[tile->editor_images.size()-1],
+                  tile->editor_images[tile->editor_images.size()-1] = new Surface(
                                datadir +  "images/tilesets/" + (*it),
                                USE_ALPHA);
                 }
@@ -145,11 +145,11 @@ Tile::draw(float x, float y, unsigned int c, Uint8 alpha)
         {
           if(ptile->images.size() > 1)
             {
-              texture_draw(&ptile->images[( ((global_frame_counter*25) / ptile->anim_speed) % (ptile->images.size()))],x,y, alpha);
+              ptile->images[( ((global_frame_counter*25) / ptile->anim_speed) % (ptile->images.size()))]->draw(x,y, alpha);
             }
           else if (ptile->images.size() == 1)
             {
-              texture_draw(&ptile->images[0],x,y, alpha);
+              ptile->images[0]->draw(x,y, alpha);
             }
           else
             {
index 047bd70..40feb80 100644 (file)
@@ -26,8 +26,8 @@ struct Tile
 {
   int id;
 
-  std::vector<texture_type> images;
-  std::vector<texture_type> editor_images;
+  std::vector<Surface*> images;
+  std::vector<Surface*> editor_images;
   
   std::vector<std::string>  filenames;
 
index da135d9..0a8e2a2 100644 (file)
@@ -42,9 +42,9 @@
 #include "tile.h"
 #include "resources.h"
 
-static texture_type bkg_title;
-static texture_type logo;
-static texture_type img_choose_subset;
+static Surface* bkg_title;
+static Surface* logo;
+static Surface* img_choose_subset;
 
 static bool walking;
 static Timer random_timer;
@@ -149,7 +149,7 @@ void draw_background()
 {
   /* Draw the title background: */
 
-  texture_draw_bg(&bkg_title);
+  bkg_title->draw_bg();
 }
 
 void draw_demo(GameSession* session, double frame_ratio)
@@ -243,9 +243,9 @@ bool title(void)
 
   /* Load images: */
 
-  texture_load(&bkg_title,datadir + "/images/title/background.jpg", IGNORE_ALPHA);
-  texture_load(&logo,datadir + "/images/title/logo.png", USE_ALPHA);
-  texture_load(&img_choose_subset,datadir + "/images/status/choose-level-subset.png", USE_ALPHA);
+  bkg_title = new Surface(datadir + "/images/title/background.jpg", IGNORE_ALPHA);
+  logo = new Surface(datadir + "/images/title/logo.png", USE_ALPHA);
+  img_choose_subset = new Surface(datadir + "/images/status/choose-level-subset.png", USE_ALPHA);
 
   /* --- Main title loop: --- */
   bool done = 0;
@@ -253,7 +253,7 @@ bool title(void)
   frame = 0;
 
   /* Draw the title background: */
-  texture_draw_bg(&bkg_title);
+  bkg_title->draw_bg();
   load_hs();
 
   update_time = st_get_ticks();
@@ -298,7 +298,7 @@ bool title(void)
       draw_demo(&session, frame_ratio);
       
       if (current_menu == main_menu)
-        texture_draw(&logo, 160, 30);
+        logo->draw( 160, 30);
 
       text_draw(&white_small_text, 
                 " SuperTux " VERSION "\n"
@@ -338,16 +338,16 @@ bool title(void)
                   subset.load(level_subsets.item[0]);
                   while(!done)
                     {
-                      texture_draw(&img_choose_subset,(screen->w - img_choose_subset.w) / 2, 0);
+                      img_choose_subset->draw((screen->w - img_choose_subset.w) / 2, 0);
                       if(level_subsets.num_items != 0)
                         {
-                          texture_draw(&subset.image,(screen->w - subset.image.w) / 2 + 25,78);
+                          subset.image->draw((screen->w - subset.image.w) / 2 + 25,78);
                           if(level_subsets.num_items > 1)
                             {
                               if(i > 0)
-                                texture_draw(&arrow_left,(screen->w / 2) - ((subset.title.length()+2)*16)/2,20);
+                                arrow_left->draw((screen->w / 2) - ((subset.title.length()+2)*16)/2,20);
                               if(i < level_subsets.num_items-1)
-                                texture_draw(&arrow_right,(screen->w / 2) + ((subset.description.length())*16)/2,20);
+                                arrow_right->draw((screen->w / 2) + ((subset.description.length())*16)/2,20);
                             }
                           text_drawf(&gold_text, subset.title.c_str(), 0, 20, A_HMIDDLE, A_TOP, 1);
                           text_drawf(&gold_text, subset.description.c_str(), 20, -20, A_HMIDDLE, A_BOTTOM, 1);
@@ -468,8 +468,8 @@ bool title(void)
     }
   /* Free surfaces: */
 
-  texture_free(&bkg_title);
-  texture_free(&logo);
+  delete bkg_title;
+  delete logo;
   
   /* Return to main! */
   return done;
index e9d44cc..7c44e55 100644 (file)
@@ -29,7 +29,7 @@
 #include "tile.h"
 #include "resources.h"
 
-texture_type img_distro[4];
+Surface* img_distro[4];
 
 World* World::current_ = 0;
 
@@ -129,8 +129,8 @@ World::draw()
   if(get_level()->bkgd_image[0] != '\0')
     {
       int s = (int)scroll_x / 30;
-      texture_draw_part(&level->img_bkgd, s, 0,0,0,level->img_bkgd.w - s, level->img_bkgd.h);
-      texture_draw_part(&level->img_bkgd, 0, 0,screen->w - s ,0,s,level->img_bkgd.h);
+      level->img_bkgd->draw_part(s, 0,0,0,level->img_bkgd->w - s, level->img_bkgd->h);
+      level->img_bkgd->draw_part(0, 0,screen->w - s ,0,s,level->img_bkgd->h);
     }
   else
     {
index ae83fed..e1d3109 100644 (file)
@@ -69,7 +69,7 @@ TileManager::TileManager()
               reader.read_bool("stop",  &tile->stop);
               reader.read_string("image",  &filename);
 
-              texture_load(&tile->sprite, 
+              tile->sprite = new Surface(
                            datadir +  "/images/worldmap/" + filename, 
                            USE_ALPHA);
 
@@ -102,7 +102,7 @@ TileManager::get(int i)
 Tux::Tux(WorldMap* worldmap_)
   : worldmap(worldmap_)
 {
-  texture_load(&sprite, datadir +  "/images/worldmap/tux.png", USE_ALPHA);
+  sprite = new Surface(datadir +  "/images/worldmap/tux.png", USE_ALPHA);
   offset = 0;
   moving = false;
   tile_pos.x = 5;
@@ -135,7 +135,7 @@ Tux::draw()
       break;
     }
 
-  texture_draw(&sprite, (int)x, (int)y);
+  sprite->draw((int)x, (int)y);
 }
 
 void
@@ -200,9 +200,9 @@ WorldMap::WorldMap()
   width  = 20;
   height = 15;
 
-  texture_load(&level_sprite, datadir +  "/images/worldmap/levelmarker.png", USE_ALPHA);
-  texture_load(&leveldot_green, datadir +  "/images/worldmap/leveldot_green.png", USE_ALPHA);
-  texture_load(&leveldot_red, datadir +  "/images/worldmap/leveldot_red.png", USE_ALPHA);
+  level_sprite = new Surface(datadir +  "/images/worldmap/levelmarker.png", USE_ALPHA);
+  leveldot_green = new Surface(datadir +  "/images/worldmap/leveldot_green.png", USE_ALPHA);
+  leveldot_red = new Surface(datadir +  "/images/worldmap/leveldot_red.png", USE_ALPHA);
 
   input_direction = NONE;
   enter_level = false;
@@ -479,12 +479,12 @@ WorldMap::draw()
     for(int x = 0; x < width; ++x)
       {
         Tile* tile = at(Point(x, y));
-        texture_draw(&tile->sprite, x*32, y*32);
+        tile->sprite->draw(x*32, y*32);
       }
   
   for(Levels::iterator i = levels.begin(); i != levels.end(); ++i)
     {
-      texture_draw(&leveldot_green, i->x*32, i->y*32);
+      leveldot_green->draw(i->x*32, i->y*32);
     }
 
   tux->draw();
index 71e9d26..2e728bb 100644 (file)
@@ -48,7 +48,7 @@ struct Point
 
 struct Tile
 {
-  texture_type sprite;
+  Surface* sprite;
 
   // Directions in which Tux is allowed to walk from this tile
   bool north;
@@ -83,7 +83,7 @@ class Tux
 {
 private:
   WorldMap* worldmap;
-  texture_type sprite;
+  Surface* sprite;
 
   Direction input_direction;
   Direction direction;
@@ -113,9 +113,9 @@ class WorldMap
 private:
   Tux* tux;
 
-  texture_type level_sprite;
-  texture_type leveldot_green;
-  texture_type leveldot_red;
+  Surface* level_sprite;
+  Surface* leveldot_green;
+  Surface* leveldot_red;
 
   bool quit;