Fix extensive disk I/O when in worldmap (found using profiler)
authorTobias Markus <tobbi@mozilla-uk.org>
Sat, 1 Feb 2014 19:28:34 +0000 (20:28 +0100)
committerTobias Markus <tobbi@mozilla-uk.org>
Sat, 1 Feb 2014 19:28:58 +0000 (20:28 +0100)
src/worldmap/worldmap.cpp
src/worldmap/worldmap.hpp

index 3061a95..ef05003 100644 (file)
@@ -367,6 +367,11 @@ WorldMap::get_level_title(LevelTile& level)
 void
 WorldMap::get_level_target_time(LevelTile& level)
 {
+  if(last_position == tux->get_tile_pos()) {
+    level.target_time = last_target_time;
+    return;
+  }
+  
   try {
     lisp::Parser parser;
     const lisp::Lisp* root = parser.parse(levels_path + level.get_name());
@@ -376,6 +381,9 @@ WorldMap::get_level_target_time(LevelTile& level)
       return;
 
     level_lisp->get("target-time", level.target_time);
+
+    last_position = level.pos;
+    last_target_time = level.target_time;
   } catch(std::exception& e) {
     log_warning << "Problem when reading level target time: " << e.what() << std::endl;
     return;
index 29cd50f..af7c104 100644 (file)
@@ -234,6 +234,8 @@ private:
 
   Vector get_camera_pos_for_tux();
   void clamp_camera_position(Vector& c);
+  Vector last_position;
+  float last_target_time;
 
 private:
   WorldMap(const WorldMap&);