- sounds are on both channels
authormathnerd314 <mathnerd314@837edb03-e0f3-0310-88ca-d4d4e8b29345>
Thu, 24 Dec 2009 16:26:47 +0000 (16:26 +0000)
committermathnerd314 <mathnerd314@837edb03-e0f3-0310-88ca-d4d4e8b29345>
Thu, 24 Dec 2009 16:26:47 +0000 (16:26 +0000)
- break snail to make SpriteData::Action const
- player_status is local
- optimized tilemap::draw a bit (might do some more later)

git-svn-id: http://supertux.lethargik.org/svn/supertux/trunk/supertux@6223 837edb03-e0f3-0310-88ca-d4d4e8b29345

34 files changed:
CMakeLists.txt
data/images/creatures/snail/snail.sprite
src/audio/dummy_sound_source.cpp
src/audio/openal_sound_source.cpp
src/audio/openal_sound_source.hpp
src/audio/sound_manager.cpp
src/audio/sound_source.hpp
src/badguy/snail.cpp
src/badguy/snail.hpp
src/object/player.cpp
src/object/rock.cpp
src/object/tilemap.cpp
src/scripting/functions.cpp
src/sprite/sprite.cpp
src/sprite/sprite.hpp
src/sprite/sprite_data.cpp
src/sprite/sprite_data.hpp
src/supertux/game_session.cpp
src/supertux/game_session.hpp
src/supertux/globals.hpp
src/supertux/main.cpp
src/supertux/menu/contrib_world_menu.cpp
src/supertux/player_status.hpp
src/supertux/resources.cpp
src/supertux/sector.cpp
src/supertux/sector.hpp
src/supertux/tile_set.hpp
src/supertux/title_screen.cpp
src/supertux/title_screen.hpp
src/supertux/world.cpp
src/supertux/world.hpp
src/worldmap/tux.cpp
src/worldmap/worldmap.cpp
src/worldmap/worldmap.hpp

index 2657d9f..8f60072 100644 (file)
@@ -58,8 +58,9 @@ TEST_BIG_ENDIAN(WORDS_BIGENDIAN)
 
 ## Add lots of dependencies to compiler switches
 
+SET(Boost_ADDITIONAL_VERSIONS "1.41" "1.41.0")
 FIND_PACKAGE(Boost REQUIRED)
-INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIR})
+INCLUDE_DIRECTORIES(SYSTEM ${Boost_INCLUDE_DIR})
 LINK_DIRECTORIES(${Boost_LIBRARY_DIRS})
 
 FIND_PACKAGE(SDL REQUIRED)
@@ -189,11 +190,11 @@ ENDIF(PRECOMPILE_HEADERS)
 OPTION(WERROR "Stop on first compiler warning" OFF)
 OPTION(WARNINGS "Enable long list of warnings for compiler to check" ON)
 IF(CMAKE_COMPILER_IS_GNUCC)
-  SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g")
-  SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")
-  SET(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_DEBUG} -pg")
-  SET(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_DEBUG} -pg")
-  SET(CMAKE_LD_FLAGS_PROFILE "${CMAKE_LD_FLAGS_DEBUG} -pg")
+  SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g" CACHE STRING "Debug flags")
+  SET(CMAKE_C_FLAGS_DEBUG "-O0 -g" CACHE STRING "Debug flags")
+  SET(CMAKE_CXX_FLAGS_PROFILE "-pg" CACHE STRING "Profile flags")
+  SET(CMAKE_C_FLAGS_PROFILE "-pg" CACHE STRING "Profile flags")
+  SET(CMAKE_LD_FLAGS_PROFILE "-lgmon" CACHE STRING "Profile flags")
   ADD_DEFINITIONS(-Wall -Wextra -funit-at-a-time)
   IF(WERROR)
     ADD_DEFINITIONS(-Werror)
@@ -202,7 +203,7 @@ IF(CMAKE_COMPILER_IS_GNUCC)
   ENDIF(WERROR)
   IF(WARNINGS)
     ADD_DEFINITIONS(-fdiagnostics-show-option -pedantic -Wno-long-long -Wcast-align -Wdisabled-optimization -Winit-self -Winvalid-pch -Wlogical-op -Wmissing-include-dirs -Wmissing-noreturn -Wpacked -Wredundant-decls -Wstack-protector)
-    SET(CMAKE_CXX_FLAGS "-Weffc++ -Wabi -Wctor-dtor-privacy -Wstrict-null-sentinel ${CMAKE_CXX_FLAGS}")
+    SET(CMAKE_CXX_FLAGS "-Weffc++ -Wabi -Wctor-dtor-privacy -Wstrict-null-sentinel" CACHE STRING "CXX Flags")
     # -ansi fails in MinGW
     # still left:  -Wold-style-cast -Wpadded -Wconversion -Wundef -Wsign-conversion -Wshadow -Winline -Wunsafe-loop-optimizations -Wfloat-equal -Wswitch-default -Wswitch-enum -Wcast-qual -Wsign-promo -Woverloaded-virtual -Wmissing-format-attribute -Wstrict-overflow=5 -Wformat=2
   ENDIF(WARNINGS)
index 56efd7d..e2d1435 100644 (file)
                (hitbox 2 3 31.8 31.8)
                (mirror-action "left"))
 
-       (action (name "falling-left")
-               (hitbox 2 3 31.8 31.8)
-               (images "snowsnail_flip1.png"
-                       "snowsnail_flip2.png"
-                       "snowsnail_flip3.png"
-                       "snowsnail_flip4.png"
-                       "snowsnail_flip5.png"
-                       "snowsnail_flip6.png"
-                       "snowsnail_flip7.png"
-                       ))
-
-       (action (name "falling-right")
-               (hitbox 2 3 31.8 31.8)
-               (mirror-action "falling-left"))
-
        (action (name "flat-left")
+               (anim-fps 64.0)
                (hitbox 2 3 31.8 31.8)
-               (images "snowsnail_flip1.png"
-                       "snowsnail_flip2.png"
-                       "snowsnail_flip3.png"
-                       "snowsnail_flip4.png"
-                       "snowsnail_flip5.png"
-                       "snowsnail_flip6.png"
-                       "snowsnail_flip7.png"
+               (images
+"snowsnail_flip1.png"
+"snowsnail_flip2.png"
+"snowsnail_flip3.png"
+"snowsnail_flip4.png"
+"snowsnail_flip5.png"
+"snowsnail_flip6.png"
+"snowsnail_flip7.png"
+"snowsnail_flip1.png"
+"snowsnail_flip2.png"
+"snowsnail_flip3.png"
+"snowsnail_flip4.png"
+"snowsnail_flip5.png"
+"snowsnail_flip6.png"
+"snowsnail_flip7.png"
+"snowsnail_flip1.png"
+"snowsnail_flip2.png"
+"snowsnail_flip3.png"
+"snowsnail_flip4.png"
+"snowsnail_flip5.png"
+"snowsnail_flip6.png"
+"snowsnail_flip7.png"
+"snowsnail_flip1.png"
+"snowsnail_flip2.png"
+"snowsnail_flip2.png"
+"snowsnail_flip3.png"
+"snowsnail_flip4.png"
+"snowsnail_flip5.png"
+"snowsnail_flip6.png"
+"snowsnail_flip7.png"
+"snowsnail_flip1.png"
+"snowsnail_flip2.png"
+"snowsnail_flip3.png"
+"snowsnail_flip4.png"
+"snowsnail_flip4.png"
+"snowsnail_flip5.png"
+"snowsnail_flip6.png"
+"snowsnail_flip7.png"
+"snowsnail_flip1.png"
+"snowsnail_flip2.png"
+"snowsnail_flip3.png"
+"snowsnail_flip3.png"
+"snowsnail_flip4.png"
+"snowsnail_flip5.png"
+"snowsnail_flip6.png"
+"snowsnail_flip7.png"
+"snowsnail_flip1.png"
+"snowsnail_flip2.png"
+"snowsnail_flip2.png"
+"snowsnail_flip3.png"
+"snowsnail_flip4.png"
+"snowsnail_flip5.png"
+"snowsnail_flip6.png"
+"snowsnail_flip6.png"
+"snowsnail_flip7.png"
+"snowsnail_flip1.png"
+"snowsnail_flip2.png"
+"snowsnail_flip3.png"
+"snowsnail_flip3.png"
+"snowsnail_flip4.png"
+"snowsnail_flip5.png"
+"snowsnail_flip6.png"
+"snowsnail_flip7.png"
+"snowsnail_flip7.png"
+"snowsnail_flip1.png"
+"snowsnail_flip2.png"
+"snowsnail_flip3.png"
+"snowsnail_flip3.png"
+"snowsnail_flip4.png"
+"snowsnail_flip5.png"
+"snowsnail_flip6.png"
+"snowsnail_flip6.png"
+"snowsnail_flip7.png"
+"snowsnail_flip1.png"
+"snowsnail_flip2.png"
+"snowsnail_flip2.png"
+"snowsnail_flip3.png"
+"snowsnail_flip4.png"
+"snowsnail_flip5.png"
+"snowsnail_flip5.png"
+"snowsnail_flip6.png"
+"snowsnail_flip7.png"
+"snowsnail_flip7.png"
+"snowsnail_flip1.png"
+"snowsnail_flip2.png"
+"snowsnail_flip2.png"
+"snowsnail_flip3.png"
+"snowsnail_flip4.png"
+"snowsnail_flip4.png"
+"snowsnail_flip5.png"
+"snowsnail_flip6.png"
+"snowsnail_flip7.png"
+"snowsnail_flip7.png"
+"snowsnail_flip1.png"
+"snowsnail_flip1.png"
+"snowsnail_flip2.png"
+"snowsnail_flip3.png"
+"snowsnail_flip3.png"
+"snowsnail_flip4.png"
+"snowsnail_flip5.png"
+"snowsnail_flip5.png"
+"snowsnail_flip6.png"
+"snowsnail_flip7.png"
+"snowsnail_flip7.png"
+"snowsnail_flip1.png"
+"snowsnail_flip2.png"
+"snowsnail_flip2.png"
+"snowsnail_flip3.png"
+"snowsnail_flip3.png"
+"snowsnail_flip4.png"
+"snowsnail_flip5.png"
+"snowsnail_flip5.png"
+"snowsnail_flip6.png"
+"snowsnail_flip6.png"
+"snowsnail_flip7.png"
+"snowsnail_flip7.png"
+"snowsnail_flip1.png"
+"snowsnail_flip2.png"
+"snowsnail_flip2.png"
+"snowsnail_flip3.png"
+"snowsnail_flip3.png"
+"snowsnail_flip4.png"
+"snowsnail_flip4.png"
+"snowsnail_flip5.png"
+"snowsnail_flip6.png"
+"snowsnail_flip6.png"
+"snowsnail_flip7.png"
+"snowsnail_flip7.png"
+"snowsnail_flip1.png"
+"snowsnail_flip1.png"
+"snowsnail_flip2.png"
+"snowsnail_flip2.png"
+"snowsnail_flip3.png"
+"snowsnail_flip3.png"
+"snowsnail_flip4.png"
+"snowsnail_flip4.png"
+"snowsnail_flip5.png"
+"snowsnail_flip5.png"
+"snowsnail_flip6.png"
+"snowsnail_flip6.png"
+"snowsnail_flip7.png"
+"snowsnail_flip7.png"
+"snowsnail_flip1.png"
+"snowsnail_flip1.png"
+"snowsnail_flip2.png"
+"snowsnail_flip2.png"
+"snowsnail_flip2.png"
+"snowsnail_flip3.png"
+"snowsnail_flip3.png"
+"snowsnail_flip4.png"
+"snowsnail_flip4.png"
+"snowsnail_flip4.png"
+"snowsnail_flip5.png"
+"snowsnail_flip5.png"
+"snowsnail_flip6.png"
+"snowsnail_flip6.png"
+"snowsnail_flip6.png"
+"snowsnail_flip7.png"
+"snowsnail_flip7.png"
+"snowsnail_flip7.png"
+"snowsnail_flip1.png"
+"snowsnail_flip1.png"
+"snowsnail_flip1.png"
+"snowsnail_flip2.png"
+"snowsnail_flip2.png"
+"snowsnail_flip3.png"
+"snowsnail_flip3.png"
+"snowsnail_flip3.png"
+"snowsnail_flip4.png"
+"snowsnail_flip4.png"
+"snowsnail_flip4.png"
+"snowsnail_flip4.png"
+"snowsnail_flip5.png"
+"snowsnail_flip5.png"
+"snowsnail_flip5.png"
+"snowsnail_flip6.png"
+"snowsnail_flip6.png"
+"snowsnail_flip6.png"
+"snowsnail_flip7.png"
+"snowsnail_flip7.png"
+"snowsnail_flip7.png"
+"snowsnail_flip1.png"
+"snowsnail_flip1.png"
+"snowsnail_flip1.png"
+"snowsnail_flip1.png"
+"snowsnail_flip2.png"
+"snowsnail_flip2.png"
+"snowsnail_flip2.png"
+"snowsnail_flip2.png"
+"snowsnail_flip3.png"
+"snowsnail_flip3.png"
+"snowsnail_flip3.png"
+"snowsnail_flip3.png"
+"snowsnail_flip4.png"
+"snowsnail_flip4.png"
+"snowsnail_flip4.png"
+"snowsnail_flip4.png"
+"snowsnail_flip5.png"
+"snowsnail_flip5.png"
+"snowsnail_flip5.png"
+"snowsnail_flip5.png"
+"snowsnail_flip5.png"
+"snowsnail_flip6.png"
+"snowsnail_flip6.png"
+"snowsnail_flip6.png"
+"snowsnail_flip6.png"
+"snowsnail_flip6.png"
+"snowsnail_flip7.png"
+"snowsnail_flip7.png"
+"snowsnail_flip7.png"
+"snowsnail_flip7.png"
+"snowsnail_flip1.png"
+"snowsnail_flip1.png"
+"snowsnail_flip1.png"
+"snowsnail_flip1.png"
+"snowsnail_flip1.png"
+"snowsnail_flip1.png"
+"snowsnail_flip2.png"
+"snowsnail_flip2.png"
+"snowsnail_flip2.png"
+"snowsnail_flip2.png"
+"snowsnail_flip2.png"
+"snowsnail_flip2.png"
+"snowsnail_flip2.png"
+"snowsnail_flip2.png"
+"snowsnail_flip3.png"
+"snowsnail_flip3.png"
+"snowsnail_flip3.png"
+"snowsnail_flip3.png"
+"snowsnail_flip3.png"
+"snowsnail_flip3.png"
+"snowsnail_flip3.png"
+"snowsnail_flip3.png"
+"snowsnail_flip3.png"
+"snowsnail_flip4.png"
+"snowsnail_flip4.png"
+"snowsnail_flip4.png"
+"snowsnail_flip4.png"
+"snowsnail_flip4.png"
+"snowsnail_flip4.png"
+"snowsnail_flip4.png"
+"snowsnail_flip4.png"
                        ))
 
        (action (name "flat-right")
                (hitbox 2 3 31.8 31.8)
-               (mirror-action "falling-left")))
+               (mirror-action "flat-left")))
index 979b740..178baa7 100644 (file)
@@ -44,6 +44,10 @@ public:
   {
   }
 
+  virtual void set_relative(bool )
+  {
+  }
+
   virtual void set_gain(float )
   {
   }
@@ -64,10 +68,6 @@ public:
   {
   }
 
-  virtual void set_rollof_factor(float )
-  {
-  }
-
 private:
   bool is_playing;
 };
index 530f905..52cf090 100644 (file)
@@ -66,6 +66,12 @@ OpenALSoundSource::set_looping(bool looping)
 }
 
 void
+OpenALSoundSource::set_relative(bool relative)
+{
+  alSourcei(source, AL_SOURCE_RELATIVE, relative ? AL_TRUE : AL_FALSE);
+}
+
+void
 OpenALSoundSource::set_position(const Vector& position)
 {
   alSource3f(source, AL_POSITION, position.x, position.y, 0);
@@ -95,10 +101,4 @@ OpenALSoundSource::set_reference_distance(float distance)
   alSourcef(source, AL_REFERENCE_DISTANCE, distance);
 }
 
-void
-OpenALSoundSource::set_rollof_factor(float factor)
-{
-  alSourcef(source, AL_ROLLOFF_FACTOR, factor);
-}
-
 /* EOF */
index 66f5519..42e1279 100644 (file)
@@ -34,12 +34,12 @@ public:
   virtual void update();
 
   virtual void set_looping(bool looping);
+  virtual void set_relative(bool relative);
   virtual void set_gain(float gain);
   virtual void set_pitch(float pitch);
   virtual void set_position(const Vector& position);
   virtual void set_velocity(const Vector& position);
   virtual void set_reference_distance(float distance);
-  virtual void set_rollof_factor(float factor);
 
 protected:
   friend class SoundManager;
index ce1579f..a65f38f 100644 (file)
@@ -122,8 +122,7 @@ SoundManager::load_file_into_buffer(SoundFile* file)
 OpenALSoundSource*
 SoundManager::intern_create_sound_source(const std::string& filename)
 {
-  if(!sound_enabled)
-    throw std::runtime_error("sound disabled");
+  assert(sound_enabled);
 
   std::auto_ptr<OpenALSoundSource> source (new OpenALSoundSource());
 
@@ -200,8 +199,8 @@ SoundManager::play(const std::string& filename, const Vector& pos)
     std::auto_ptr<OpenALSoundSource> source
       (intern_create_sound_source(filename));
 
-    if(pos == Vector(-1, -1)) {
-      source->set_rollof_factor(0);
+    if(pos.x < 0 || pos.y < 0) {
+      source->set_relative(true);
     } else {
       source->set_position(pos);
     }
@@ -301,9 +300,9 @@ SoundManager::play_music(const std::string& filename, bool fade)
 
   try {
     std::auto_ptr<StreamSoundSource> newmusic (new StreamSoundSource());
-    alSourcef(newmusic->source, AL_ROLLOFF_FACTOR, 0);
     newmusic->set_sound_file(load_sound_file(filename));
     newmusic->set_looping(true);
+    newmusic->set_relative(true);
     if(fade)
       newmusic->set_fading(StreamSoundSource::FadingOn, .5f);
     newmusic->play();
index 266f941..e473e04 100644 (file)
@@ -35,13 +35,13 @@ public:
   virtual bool playing() = 0;
 
   virtual void set_looping(bool looping) = 0;
+  virtual void set_relative(bool relative) = 0;
   /// Set volume (0.0 is silent, 1.0 is normal)
   virtual void set_gain(float gain) = 0;
   virtual void set_pitch(float pitch) = 0;
   virtual void set_position(const Vector& position) = 0;
-  virtual void set_velocity(const Vector& position) = 0;
+  virtual void set_velocity(const Vector& velocity) = 0;
   virtual void set_reference_distance(float distance) = 0;
-  virtual void set_rollof_factor(float factor) = 0;
 };
 
 #endif
index 95d1dcd..1efedc0 100644 (file)
@@ -32,7 +32,6 @@ const float KICKSPEED_Y = -500; /**< y-velocity gained when kicked */
 Snail::Snail(const Reader& reader) :
   WalkingBadguy(reader, "images/creatures/snail/snail.sprite", "left", "right"), 
   state(STATE_NORMAL), 
-  flat_timer(),
   kicked_delay_timer(),
   squishcount(0)
 {
@@ -46,7 +45,6 @@ Snail::Snail(const Reader& reader) :
 Snail::Snail(const Vector& pos, Direction d) :
   WalkingBadguy(pos, d, "images/creatures/snail/snail.sprite", "left", "right"), 
   state(STATE_NORMAL), 
-  flat_timer(),
   kicked_delay_timer(),
   squishcount(0)
 {
@@ -77,21 +75,17 @@ void
 Snail::be_flat()
 {
   state = STATE_FLAT;
-  sprite->set_action(dir == LEFT ? "flat-left" : "flat-right");
-  sprite->set_fps(64);
+  sprite->set_action(dir == LEFT ? "flat-left" : "flat-right", 1);
 
   physic.set_velocity_x(0);
   physic.set_velocity_y(0);
-
-  flat_timer.start(4);
 }
 
 void
 Snail::be_kicked()
 {
   state = STATE_KICKED_DELAY;
-  sprite->set_action(dir == LEFT ? "flat-left" : "flat-right");
-  sprite->set_fps(64);
+  sprite->set_action(dir == LEFT ? "flat-left" : "flat-right", 1);
 
   physic.set_velocity_x(0);
   physic.set_velocity_y(0);
@@ -112,16 +106,12 @@ Snail::active_update(float elapsed_time)
 
     case STATE_NORMAL:
       WalkingBadguy::active_update(elapsed_time);
-      break;
+      return;
 
     case STATE_FLAT:
-      if (flat_timer.started()) {
-        sprite->set_fps(64 - 15 * flat_timer.get_timegone());
-      }
-      if (flat_timer.check()) {
+      if (sprite->animation_done()) {
         be_normal();
       }
-      BadGuy::active_update(elapsed_time);
       break;
 
     case STATE_KICKED_DELAY:
@@ -130,46 +120,26 @@ Snail::active_update(float elapsed_time)
         physic.set_velocity_y(KICKSPEED_Y);
         state = STATE_KICKED;
       }
-      BadGuy::active_update(elapsed_time);
       break;
 
     case STATE_KICKED:
       physic.set_velocity_x(physic.get_velocity_x() * pow(0.99, elapsed_time/0.02));
-      if (fabsf(physic.get_velocity_x()) < walk_speed) be_normal();
-      BadGuy::active_update(elapsed_time);
+      if (sprite->animation_done() || (fabsf(physic.get_velocity_x()) < walk_speed)) be_normal();
       break;
 
   }
+
+  BadGuy::active_update(elapsed_time);
 }
 
 void
 Snail::collision_solid(const CollisionHit& hit)
 {
-  update_on_ground_flag(hit);
-
   switch (state) {
     case STATE_NORMAL:
       WalkingBadguy::collision_solid(hit);
-      break;
-    case STATE_FLAT:
-      if(hit.top || hit.bottom) {
-        physic.set_velocity_y(0);
-      }
-      if(hit.left || hit.right) {
-      }
-      break;
-    case STATE_KICKED_DELAY:
-      if(hit.top || hit.bottom) {
-        physic.set_velocity_y(0);
-      }
-      if(hit.left || hit.right) {
-        physic.set_velocity_x(0);
-      }
-      break;
+      return;
     case STATE_KICKED:
-      if(hit.top || hit.bottom) {
-        physic.set_velocity_y(0);
-      }
       if(hit.left || hit.right) {
         sound_manager->play("sounds/iceblock_bump.wav", get_pos());
 
@@ -177,14 +147,20 @@ Snail::collision_solid(const CollisionHit& hit)
           dir = (dir == LEFT) ? RIGHT : LEFT;
           sprite->set_action(dir == LEFT ? "flat-left" : "flat-right");
 
-          physic.set_velocity_x(-physic.get_velocity_x()*0.75);
-          if (fabsf(physic.get_velocity_x()) < walk_speed) be_normal();
+          physic.set_velocity_x(-physic.get_velocity_x());
         }
-
+      }
+      /* fall-through */
+    case STATE_FLAT:
+    case STATE_KICKED_DELAY:
+      if(hit.top || hit.bottom) {
+        physic.set_velocity_y(0);
       }
       break;
   }
 
+  update_on_ground_flag(hit);
+
 }
 
 HitResponse
index 6e5471a..9b482d3 100644 (file)
@@ -51,7 +51,6 @@ private:
 
 private:
   State state;
-  Timer flat_timer; /**< wait time until flipping right-side-up again */
   Timer kicked_delay_timer; /**< wait time until switching from STATE_KICKED_DELAY to STATE_KICKED */
   int   squishcount;
 };
index a8b7cca..1f3b0cd 100644 (file)
@@ -758,6 +758,7 @@ Player::handle_input()
     if(Sector::current()->add_bullet(
          get_pos() + ((dir == LEFT)? Vector(0, bbox.get_height()/2)
                       : Vector(32, bbox.get_height()/2)),
+         player_status,
          physic.get_velocity_x(), dir))
       shooting_timer.start(SHOOTING_TIME);
   }
index fd59162..48dee00 100644 (file)
@@ -117,7 +117,7 @@ Rock::grab(MovingObject& , const Vector& pos, Direction)
 {
   movement = pos - get_pos();
   last_movement = movement;
-  set_group(COLGROUP_DISABLED);
+  set_group(COLGROUP_TOUCHABLE); //needed for lanterns catching willowisps
   on_ground = false;
   grabbed = true;
 }
index 3825545..0adbb86 100644 (file)
@@ -192,8 +192,10 @@ TileMap::draw(DrawingContext& context)
   if (current_alpha == 0.0) return;
 
   context.push_transform();
-  context.push_target();
-  context.set_target(draw_target);
+  if(draw_target != DrawingContext::NORMAL) {
+    context.push_target();
+    context.set_target(draw_target);
+  }
 
   if(drawing_effect != 0) context.set_drawing_effect(drawing_effect);
   if(current_alpha != 1.0) context.set_alpha(current_alpha);
@@ -216,14 +218,16 @@ TileMap::draw(DrawingContext& context)
   int tx, ty;
   for(pos.x = start_x, tx = tsx; pos.x < end_x; pos.x += 32, ++tx) {
     for(pos.y = start_y, ty = tsy; pos.y < end_y; pos.y += 32, ++ty) {
-      if ((tx < 0) || (ty < 0)) continue;
+      if ((tx < 0) || (ty < 0) || (tiles[ty*width + tx] == 0)) continue;
       const Tile* tile = tileset->get(tiles[ty*width + tx]);
       assert(tile != 0);
       tile->draw(context, pos, z_pos);
     }
   }
 
-  context.pop_target();
+  if(draw_target != DrawingContext::NORMAL) {
+    context.pop_target();
+  }
   context.pop_transform();
 }
 
index b88070c..21b33bd 100644 (file)
@@ -99,12 +99,18 @@ void load_worldmap(const std::string& filename)
 {
   using namespace worldmap;
 
-  g_screen_manager->push_screen(new WorldMap(filename));
+  if(World::current() == NULL)
+    throw std::runtime_error("Can't start WorldMap without active world.");
+
+  g_screen_manager->push_screen(new WorldMap(filename, World::current()->get_player_status()));
 }
 
 void load_level(const std::string& filename)
 {
-  g_screen_manager->push_screen(new GameSession(filename));
+  if(GameSession::current() == NULL)
+    throw std::runtime_error("Can't start level without active level.");
+
+  g_screen_manager->push_screen(new GameSession(filename, GameSession::current()->get_player_status()));
 }
 
 static SQInteger squirrel_read_char(SQUserPointer file)
index 2e63074..2ee515a 100644 (file)
@@ -63,7 +63,7 @@ Sprite::set_action(const std::string& name, int loops)
   if(action && action->name == name)
     return;
 
-  SpriteData::Action* newaction = data.get_action(name);
+  const SpriteData::Action* newaction = data.get_action(name);
   if(!newaction) {
     log_debug << "Action '" << name << "' not found." << std::endl;
     return;
@@ -80,7 +80,7 @@ Sprite::set_action_continued(const std::string& name)
   if(action && action->name == name)
     return;
 
-  SpriteData::Action* newaction = data.get_action(name);
+  const SpriteData::Action* newaction = data.get_action(name);
   if(!newaction) {
     log_debug << "Action '" << name << "' not found." << std::endl;
     return;
@@ -221,12 +221,6 @@ Sprite::get_current_hitbox() const
 }
 
 void
-Sprite::set_fps(float new_fps)
-{
-  action->fps = new_fps;
-}
-
-void
 Sprite::set_angle(float a)
 {
   angle = a;
index a82f05e..79d12ae 100644 (file)
@@ -49,9 +49,6 @@ public:
   void set_animation_loops(int loops = -1)
   { animation_loops = loops; }
 
-  /** Set framerate */
-  void set_fps(float new_fps);
-
   /* Stop animation */
   void stop_animation()
   { animation_loops = 0; }
@@ -124,7 +121,7 @@ private:
   Color color;
   Blend blend;
 
-  SpriteData::Action* action;
+  const SpriteData::Action* action;
 
 private:
   Sprite(const Sprite& other);
index 4225de0..b777cda 100644 (file)
@@ -102,7 +102,7 @@ SpriteData::parse_action(const Reader& lisp, const std::string& basedir)
   std::string mirror_action;
   lisp.get("mirror-action", mirror_action);
   if(!mirror_action.empty()) {
-    Action* act_tmp = get_action(mirror_action);
+    const Action* act_tmp = get_action(mirror_action);
     if(act_tmp == NULL) {
       throw std::runtime_error("Could not mirror action. Action not found.\n"
                                "Mirror actions must be defined after the real one!");
@@ -142,8 +142,8 @@ SpriteData::parse_action(const Reader& lisp, const std::string& basedir)
   actions[action->name] = action;
 }
 
-SpriteData::Action*
-SpriteData::get_action(std::string act)
+const SpriteData::Action*
+SpriteData::get_action(const std::string act)
 {
   Actions::iterator i = actions.find(act);
   if(i == actions.end()) {
index d5e3a86..7a8945e 100644 (file)
@@ -68,7 +68,7 @@ private:
 
   void parse_action(const Reader& lispreader, const std::string& basedir);
   /** Get an action */
-  Action* get_action(std::string act);
+  const Action* get_action(const std::string act);
 
   Actions actions;
   std::string name;
index b7d52ba..c907896 100644 (file)
@@ -43,7 +43,7 @@
 #include "util/gettext.hpp"
 #include "worldmap/worldmap.hpp"
 
-GameSession::GameSession(const std::string& levelfile_, Statistics* statistics) :
+GameSession::GameSession(const std::string& levelfile_, PlayerStatus* player_status, Statistics* statistics) :
   level(0), 
   statistics_backdrop(),
   scripts(),
@@ -59,6 +59,7 @@ GameSession::GameSession(const std::string& levelfile_, Statistics* statistics)
   newsector(),
   newspawnpoint(),
   best_level_statistics(statistics),
+  player_status(player_status),
   capture_demo_stream(0), 
   capture_file(),
   playback_demo_stream(0), 
index 57d613f..22160a3 100644 (file)
@@ -29,6 +29,7 @@
 class Level;
 class Sector;
 class Statistics;
+class PlayerStatus;
 class DrawingContext;
 class CodeController;
 class Menu;
@@ -40,7 +41,7 @@ class GameSession : public Screen,
                     public Currenton<GameSession>
 {
 public:
-  GameSession(const std::string& levelfile, Statistics* statistics = NULL);
+  GameSession(const std::string& levelfile, PlayerStatus* player_status, Statistics* statistics = NULL);
   ~GameSession();
 
   void record_demo(const std::string& filename);
@@ -67,6 +68,9 @@ public:
   Level* get_current_level()
   { return level.get(); }
 
+  PlayerStatus* get_player_status()
+  { return player_status; }
+
   void start_sequence(const std::string& sequencename);
 
   /**
@@ -129,6 +133,7 @@ private:
   std::string newspawnpoint;
 
   Statistics* best_level_statistics;
+  PlayerStatus* player_status;
 
   std::ostream* capture_demo_stream;
   std::string capture_file;
index f6b9dfc..08a4830 100644 (file)
@@ -62,9 +62,6 @@ extern TileManager *tile_manager;
 /** this is only set while loading a map */
 extern TileSet     *current_tileset;
 
-// global player state
-extern PlayerStatus* player_status;
-
 extern SpriteManager* sprite_manager;
 
 extern float g_game_speed;
index 0d88d31..a544fd6 100644 (file)
@@ -41,6 +41,7 @@ namespace supertux_apple {
 #include "scripting/squirrel_util.hpp"
 #include "supertux/gameconfig.hpp"
 #include "supertux/globals.hpp"
+#include "supertux/player_status.hpp"
 #include "supertux/screen_manager.hpp"
 #include "supertux/resources.hpp"
 #include "supertux/title_screen.hpp"
@@ -573,7 +574,12 @@ Main::run(int argc, char** argv)
 
     timelog(0);
 
+    const std::auto_ptr<PlayerStatus> default_playerstatus(new PlayerStatus());
+
     g_screen_manager = new ScreenManager();
+
+    init_rand();
+
     if(g_config->start_level != "") {
       // we have a normal path specified at commandline, not a physfs path.
       // So we simply mount that path here...
@@ -583,14 +589,11 @@ Main::run(int argc, char** argv)
 
       if(g_config->start_level.size() > 4 &&
          g_config->start_level.compare(g_config->start_level.size() - 5, 5, ".stwm") == 0) {
-        init_rand();
         g_screen_manager->push_screen(new worldmap::WorldMap(
-                                 FileSystem::basename(g_config->start_level)));
+                                 FileSystem::basename(g_config->start_level), default_playerstatus.get()));
       } else {
-        init_rand();//If level uses random eg. for
-        // rain particles before we do this:
         std::auto_ptr<GameSession> session (
-          new GameSession(FileSystem::basename(g_config->start_level)));
+          new GameSession(FileSystem::basename(g_config->start_level), default_playerstatus.get()));
 
         g_config->random_seed =session->get_demo_random_seed(g_config->start_demo);
         init_rand();//initialise generator with seed from session
@@ -603,11 +606,9 @@ Main::run(int argc, char** argv)
         g_screen_manager->push_screen(session.release());
       }
     } else {
-      init_rand();
-      g_screen_manager->push_screen(new TitleScreen());
+      g_screen_manager->push_screen(new TitleScreen(default_playerstatus.get()));
     }
 
-    //init_rand(); PAK: this call might subsume the above 3, but I'm chicken!
     g_screen_manager->run(context);
   } catch(std::exception& e) {
     log_fatal << "Unexpected exception: " << e.what() << std::endl;
index bed2e9f..5d22b8e 100644 (file)
@@ -50,7 +50,7 @@ ContribWorldMenu::check_menu()
     if (get_item_by_id(index).kind == MN_ACTION) 
     {
       sound_manager->stop_music();
-      GameSession* session = new GameSession(m_current_world.get_level_filename(index));
+      GameSession* session = new GameSession(m_current_world.get_level_filename(index), m_current_world.get_player_status());
       g_screen_manager->push_screen(session);
     }
   }
index aebee17..7b320de 100644 (file)
@@ -34,7 +34,7 @@ enum BonusType {
 class DrawingContext;
 
 /**
- * This class memorizes player status between different game sessions (for
+ * This class keeps player status between different game sessions (for
  * example when switching maps in the worldmap)
  */
 class PlayerStatus
index 6e4c203..7d2e147 100644 (file)
@@ -46,8 +46,6 @@ Resources::load_shared()
 
   tile_manager   = new TileManager();
   sprite_manager = new SpriteManager();
-
-  player_status = new PlayerStatus();
 }
 
 /* Free shared data: */
@@ -65,9 +63,6 @@ Resources::unload_shared()
 
   /* Free mouse-cursor */
   delete mouse_cursor;
-
-  delete player_status;
-  player_status = NULL;
 }
 
 /* EOF */
index 9f978d9..126253a 100644 (file)
 #include "scripting/squirrel_util.hpp"
 #include "supertux/collision.hpp"
 #include "supertux/constants.hpp"
+#include "supertux/game_session.hpp"
 #include "supertux/globals.hpp"
 #include "supertux/level.hpp"
 #include "supertux/object_factory.hpp"
+#include "supertux/player_status.hpp"
 #include "supertux/spawn_point.hpp"
 #include "supertux/tile.hpp"
 #include "trigger/sequence_trigger.hpp"
@@ -83,7 +85,7 @@ Sector::Sector(Level* parent) :
   camera(0), 
   effect(0)
 {
-  add_object(new Player(player_status, "Tux"));
+  add_object(new Player(GameSession::current()->get_player_status(), "Tux"));
   add_object(new DisplayEffect("Effect"));
   add_object(new TextObject("Text"));
 
@@ -1416,7 +1418,7 @@ Sector::is_free_of_movingstatics(const Rectf& rect, const MovingObject* ignore_o
 }
 
 bool
-Sector::add_bullet(const Vector& pos, float xm, Direction dir)
+Sector::add_bullet(const Vector& pos, const PlayerStatus* player_status, float xm, Direction dir)
 {
   // TODO remove this function and move these checks elsewhere...
 
index 996de3e..595d857 100644 (file)
@@ -37,6 +37,7 @@ class Rectf;
 class Sprite;
 class GameObject;
 class Player;
+class PlayerStatus;
 class Camera;
 class TileMap;
 class Bullet;
@@ -107,7 +108,7 @@ public:
   void play_music(MusicType musictype);
   MusicType get_music_type();
 
-  bool add_bullet(const Vector& pos, float xm, Direction dir);
+  bool add_bullet(const Vector& pos, const PlayerStatus* player_status, float xm, Direction dir);
   bool add_smoke_cloud(const Vector& pos);
 
   /** get currently activated sector. */
index cc303d2..18db0ad 100644 (file)
@@ -45,7 +45,7 @@ public:
   void merge(const TileSet *tileset, uint32_t start, uint32_t end,
              uint32_t offset);
 
-  const Tile* get(uint32_t id) const
+  const Tile* get(const uint32_t id) const
   {
     assert(id < tiles.size());
     Tile* tile = tiles[id];
index 8d30139..e5ea291 100644 (file)
 
 #include <version.h>
 
-TitleScreen::TitleScreen() :
+TitleScreen::TitleScreen(PlayerStatus* player_status) :
   main_menu(new MainMenu()),
   frame(),
   controller(),
   titlesession()
 {
   controller.reset(new CodeController());
-  titlesession.reset(new GameSession("levels/misc/menu.stl"));
+  titlesession.reset(new GameSession("levels/misc/menu.stl", player_status));
 
   Player* player = titlesession->get_current_sector()->player;
   player->set_controller(controller.get());
@@ -113,8 +113,6 @@ TitleScreen::~TitleScreen()
 void
 TitleScreen::setup()
 {
-  player_status->reset();
-
   Sector* sector = titlesession->get_current_sector();
   if(Sector::current() != sector) {
     sector->play_music(LEVEL_MUSIC);
index 19c66ad..f80e1bf 100644 (file)
@@ -26,6 +26,7 @@ class ContribMenu;
 class ContribWorldMenu;
 class MainMenu;
 class Menu;
+class PlayerStatus;
 class World;
 
 /**
@@ -37,7 +38,7 @@ public:
   static std::string get_level_name(const std::string& levelfile);
 
 public:
-  TitleScreen();
+  TitleScreen(PlayerStatus* player_status);
   virtual ~TitleScreen();
 
   virtual void setup();
index e41fb3d..399816c 100644 (file)
@@ -38,9 +38,12 @@ World::World() :
   world_thread(),
   title(),
   description(),
+  player_status(),
   hide_from_contribs(),
   is_levelset()
 {
+  player_status.reset(new PlayerStatus());
+
   is_levelset = true;
   hide_from_contribs = false;
   sq_resetobject(&world_thread);
@@ -145,7 +148,7 @@ World::run()
   } catch(std::exception& ) {
     // fallback: try to load worldmap worldmap.stwm
     using namespace worldmap;
-    g_screen_manager->push_screen(new WorldMap(basedir + "worldmap.stwm"));
+    g_screen_manager->push_screen(new WorldMap(basedir + "worldmap.stwm", get_player_status()));
   }
 }
 
index 8ab6262..596ec2c 100644 (file)
@@ -21,6 +21,8 @@
 #include <string>
 #include <vector>
 
+class PlayerStatus;
+
 class World
 {
 public:
@@ -47,6 +49,9 @@ public:
   const std::string& get_level_filename(unsigned int i) const;
   const std::string& get_basedir() const;
   const std::string& get_title() const;
+  /** returns player status */
+  PlayerStatus* get_player_status() const { return player_status.get(); }
+
 
   void run();
 
@@ -59,6 +64,7 @@ private:
   HSQOBJECT world_thread;
   std::string title;
   std::string description;
+  std::auto_ptr<PlayerStatus> player_status;
 
 public:
   bool hide_from_contribs;
index 7ecfb12..bce207a 100644 (file)
@@ -59,7 +59,7 @@ Tux::~Tux()
 void
 Tux::draw(DrawingContext& context)
 {
-  switch (player_status->bonus) {
+  switch (worldmap->get_player_status()->bonus) {
     case GROWUP_BONUS:
       sprite->set_action(moving ? "large-walking" : "large-stop");
       break;
index 7f3a71d..05004ed 100644 (file)
@@ -76,8 +76,9 @@ namespace worldmap {
 
 WorldMap* WorldMap::current_ = NULL;
 
-WorldMap::WorldMap(const std::string& filename, const std::string& force_spawnpoint) :
+WorldMap::WorldMap(const std::string& filename, PlayerStatus* player_status, const std::string& force_spawnpoint) :
   tux(0),
+  player_status(player_status),
   tileset(NULL), 
   free_tileset(false),
   worldmap_menu(),
@@ -238,7 +239,7 @@ void
 WorldMap::change(const std::string& filename, const std::string& force_spawnpoint)
 {
   g_screen_manager->exit_screen();
-  g_screen_manager->push_screen(new WorldMap(filename, force_spawnpoint));
+  g_screen_manager->push_screen(new WorldMap(filename, player_status, force_spawnpoint));
 }
 
 void
@@ -666,7 +667,7 @@ WorldMap::update(float delta)
           // update state and savegame
           save_state();
 
-          g_screen_manager->push_screen(new GameSession(levelfile, &level->statistics),
+          g_screen_manager->push_screen(new GameSession(levelfile, player_status, &level->statistics),
                                    new ShrinkFade(shrinkpos, 1.0f));
           in_level = true;
         } catch(std::exception& e) {
index f206ad1..1fbf858 100644 (file)
@@ -41,6 +41,7 @@ class Sprite;
 class Menu;
 class GameObject;
 class TileMap;
+class PlayerStatus;
 
 namespace worldmap {
 
@@ -77,6 +78,8 @@ private:
 
   Tux* tux;
 
+  PlayerStatus* player_status;
+
   TileSet *tileset;
   bool     free_tileset;
 
@@ -123,7 +126,7 @@ private:
   bool panning;
 
 public:
-  WorldMap(const std::string& filename, const std::string& force_spawnpoint = "");
+  WorldMap(const std::string& filename, PlayerStatus* player_status, const std::string& force_spawnpoint = "");
   ~WorldMap();
 
   void add_object(GameObject* object);
@@ -168,6 +171,9 @@ public:
   /** returns current Tux incarnation */
   Tux* get_tux() { return tux; }
 
+  /** returns player status */
+  PlayerStatus* get_player_status() { return player_status; }
+
   LevelTile* at_level();
   SpecialTile* at_special_tile();
   SpriteChange* at_sprite_change(const Vector& pos);