lazily load tile images to speedup startup times
[supertux.git] / src / worldmap.cpp
index 360cc3c..299fff5 100644 (file)
@@ -17,6 +17,8 @@
 //  along with this program; if not, write to the Free Software
 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
+#include <config.h>
+
 #include <iostream>
 #include <fstream>
 #include <vector>
@@ -38,8 +40,9 @@
 #include "resources.h"
 #include "app/gettext.h"
 #include "misc.h"
+#include "scene.h"
 
-#define map_message_TIME 2800
+#define map_message_TIME 2.8
 
 Menu* worldmap_menu  = 0;
 
@@ -176,8 +179,8 @@ TileManager::TileManager()
                 tile->images.push_back(image);
                 }
 
-              tile->anim_speed = 25;
-              reader.read_int("anim-speed", tile->anim_speed);
+              tile->anim_fps = 1;
+              reader.read_float("anim-fps", tile->anim_fps);
 
 
               if (id >= int(tiles.size()))
@@ -359,7 +362,7 @@ Tux::action(float delta)
             {
               if(special_tile && !special_tile->map_message.empty() &&
                 !special_tile->passive_message)
-                worldmap->passive_message_timer.stop();
+                worldmap->passive_message_timer.start(0);
               stop();
             }
           else
@@ -451,8 +454,7 @@ Tile::draw(DrawingContext& context, Vector pos)
 
   if(images.size() > 1)
     {
-    size_t frame 
-      = ((global_frame_counter*25) / anim_speed) % images.size();
+    size_t frame = size_t(global_time * anim_fps) % images.size();
 
     context.draw_surface(images[frame], pos, LAYER_TILES);
     }
@@ -485,10 +487,7 @@ WorldMap::WorldMap()
   enter_level = false;
 
   name = "<no title>";
-  music = "SALCON.MOD";
-
-  global_frame_counter = 0;
-  frame_timer.init(true);
+  music = "salcon.mod";
 
   total_stats.reset();
 }
@@ -829,12 +828,6 @@ std::cerr << "one way only\n";
 void
 WorldMap::update(float delta)
 {
-  if(!frame_timer.check())
-    {
-    frame_timer.start(25);
-    global_frame_counter++;
-    }
-
   if (enter_level && !tux->is_moving())
     {
       /* Check special tile action */
@@ -870,9 +863,9 @@ WorldMap::update(float delta)
               // do a shriking fade to the level
               shrink_fade(Vector((level->pos.x*32 + 16 + offset.x),(level->pos.y*32 + 16
                       + offset.y)), 500);
-              GameSession session(level->name,
-                                  ST_GL_LOAD_LEVEL_FILE, level->vertical_flip,
-                                  &level->statistics);
+              GameSession session(
+                  get_resource_filename(std::string("levels/" + level->name)),
+                                  ST_GL_LOAD_LEVEL_FILE, &level->statistics);
 
               switch (session.run())
                 {