From 692f5e9f1c7cbbf472794300f6898e6316098253 Mon Sep 17 00:00:00 2001 From: mathnerd314 Date: Thu, 24 Dec 2009 16:26:47 +0000 Subject: [PATCH] - sounds are on both channels - 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 --- CMakeLists.txt | 15 +- data/images/creatures/snail/snail.sprite | 267 ++++++++++++++++++++++++++++--- src/audio/dummy_sound_source.cpp | 8 +- src/audio/openal_sound_source.cpp | 12 +- src/audio/openal_sound_source.hpp | 2 +- src/audio/sound_manager.cpp | 9 +- src/audio/sound_source.hpp | 4 +- src/badguy/snail.cpp | 58 ++----- src/badguy/snail.hpp | 1 - src/object/player.cpp | 1 + src/object/rock.cpp | 2 +- src/object/tilemap.cpp | 12 +- src/scripting/functions.cpp | 10 +- src/sprite/sprite.cpp | 10 +- src/sprite/sprite.hpp | 5 +- src/sprite/sprite_data.cpp | 6 +- src/sprite/sprite_data.hpp | 2 +- src/supertux/game_session.cpp | 3 +- src/supertux/game_session.hpp | 7 +- src/supertux/globals.hpp | 3 - src/supertux/main.cpp | 17 +- src/supertux/menu/contrib_world_menu.cpp | 2 +- src/supertux/player_status.hpp | 2 +- src/supertux/resources.cpp | 5 - src/supertux/sector.cpp | 6 +- src/supertux/sector.hpp | 3 +- src/supertux/tile_set.hpp | 2 +- src/supertux/title_screen.cpp | 6 +- src/supertux/title_screen.hpp | 3 +- src/supertux/world.cpp | 5 +- src/supertux/world.hpp | 6 + src/worldmap/tux.cpp | 2 +- src/worldmap/worldmap.cpp | 7 +- src/worldmap/worldmap.hpp | 8 +- 34 files changed, 363 insertions(+), 148 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2657d9f8a..8f60072c3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/data/images/creatures/snail/snail.sprite b/data/images/creatures/snail/snail.sprite index 56efd7dfd..e2d14359a 100644 --- a/data/images/creatures/snail/snail.sprite +++ b/data/images/creatures/snail/snail.sprite @@ -11,32 +11,253 @@ (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"))) diff --git a/src/audio/dummy_sound_source.cpp b/src/audio/dummy_sound_source.cpp index 979b740b1..178baa71f 100644 --- a/src/audio/dummy_sound_source.cpp +++ b/src/audio/dummy_sound_source.cpp @@ -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; }; diff --git a/src/audio/openal_sound_source.cpp b/src/audio/openal_sound_source.cpp index 530f905fb..52cf09013 100644 --- a/src/audio/openal_sound_source.cpp +++ b/src/audio/openal_sound_source.cpp @@ -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 */ diff --git a/src/audio/openal_sound_source.hpp b/src/audio/openal_sound_source.hpp index 66f551924..42e127960 100644 --- a/src/audio/openal_sound_source.hpp +++ b/src/audio/openal_sound_source.hpp @@ -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; diff --git a/src/audio/sound_manager.cpp b/src/audio/sound_manager.cpp index ce1579fe7..a65f38f25 100644 --- a/src/audio/sound_manager.cpp +++ b/src/audio/sound_manager.cpp @@ -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 source (new OpenALSoundSource()); @@ -200,8 +199,8 @@ SoundManager::play(const std::string& filename, const Vector& pos) std::auto_ptr 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 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(); diff --git a/src/audio/sound_source.hpp b/src/audio/sound_source.hpp index 266f941e0..e473e0495 100644 --- a/src/audio/sound_source.hpp +++ b/src/audio/sound_source.hpp @@ -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 diff --git a/src/badguy/snail.cpp b/src/badguy/snail.cpp index 95d1dcd60..1efedc003 100644 --- a/src/badguy/snail.cpp +++ b/src/badguy/snail.cpp @@ -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 diff --git a/src/badguy/snail.hpp b/src/badguy/snail.hpp index 6e5471ac1..9b482d334 100644 --- a/src/badguy/snail.hpp +++ b/src/badguy/snail.hpp @@ -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; }; diff --git a/src/object/player.cpp b/src/object/player.cpp index a8b7cca7a..1f3b0cd02 100644 --- a/src/object/player.cpp +++ b/src/object/player.cpp @@ -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); } diff --git a/src/object/rock.cpp b/src/object/rock.cpp index fd591623f..48dee0040 100644 --- a/src/object/rock.cpp +++ b/src/object/rock.cpp @@ -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; } diff --git a/src/object/tilemap.cpp b/src/object/tilemap.cpp index 3825545ec..0adbb86ab 100644 --- a/src/object/tilemap.cpp +++ b/src/object/tilemap.cpp @@ -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(); } diff --git a/src/scripting/functions.cpp b/src/scripting/functions.cpp index b88070c4c..21b33bdbc 100644 --- a/src/scripting/functions.cpp +++ b/src/scripting/functions.cpp @@ -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) diff --git a/src/sprite/sprite.cpp b/src/sprite/sprite.cpp index 2e63074cc..2ee515a96 100644 --- a/src/sprite/sprite.cpp +++ b/src/sprite/sprite.cpp @@ -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; diff --git a/src/sprite/sprite.hpp b/src/sprite/sprite.hpp index a82f05e78..79d12ae71 100644 --- a/src/sprite/sprite.hpp +++ b/src/sprite/sprite.hpp @@ -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); diff --git a/src/sprite/sprite_data.cpp b/src/sprite/sprite_data.cpp index 4225de00c..b777cdadb 100644 --- a/src/sprite/sprite_data.cpp +++ b/src/sprite/sprite_data.cpp @@ -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()) { diff --git a/src/sprite/sprite_data.hpp b/src/sprite/sprite_data.hpp index d5e3a86ee..7a8945ed0 100644 --- a/src/sprite/sprite_data.hpp +++ b/src/sprite/sprite_data.hpp @@ -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; diff --git a/src/supertux/game_session.cpp b/src/supertux/game_session.cpp index b7d52ba5d..c907896e4 100644 --- a/src/supertux/game_session.cpp +++ b/src/supertux/game_session.cpp @@ -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), diff --git a/src/supertux/game_session.hpp b/src/supertux/game_session.hpp index 57d613f2c..22160a39b 100644 --- a/src/supertux/game_session.hpp +++ b/src/supertux/game_session.hpp @@ -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 { 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; diff --git a/src/supertux/globals.hpp b/src/supertux/globals.hpp index f6b9dfc8a..08a48304e 100644 --- a/src/supertux/globals.hpp +++ b/src/supertux/globals.hpp @@ -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; diff --git a/src/supertux/main.cpp b/src/supertux/main.cpp index 0d88d3102..a544fd68d 100644 --- a/src/supertux/main.cpp +++ b/src/supertux/main.cpp @@ -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 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 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; diff --git a/src/supertux/menu/contrib_world_menu.cpp b/src/supertux/menu/contrib_world_menu.cpp index bed2e9f26..5d22b8e05 100644 --- a/src/supertux/menu/contrib_world_menu.cpp +++ b/src/supertux/menu/contrib_world_menu.cpp @@ -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); } } diff --git a/src/supertux/player_status.hpp b/src/supertux/player_status.hpp index aebee1792..7b320de75 100644 --- a/src/supertux/player_status.hpp +++ b/src/supertux/player_status.hpp @@ -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 diff --git a/src/supertux/resources.cpp b/src/supertux/resources.cpp index 6e4c203cd..7d2e14784 100644 --- a/src/supertux/resources.cpp +++ b/src/supertux/resources.cpp @@ -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 */ diff --git a/src/supertux/sector.cpp b/src/supertux/sector.cpp index 9f978d9d5..126253af0 100644 --- a/src/supertux/sector.cpp +++ b/src/supertux/sector.cpp @@ -49,9 +49,11 @@ #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... diff --git a/src/supertux/sector.hpp b/src/supertux/sector.hpp index 996de3ef2..595d85735 100644 --- a/src/supertux/sector.hpp +++ b/src/supertux/sector.hpp @@ -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. */ diff --git a/src/supertux/tile_set.hpp b/src/supertux/tile_set.hpp index cc303d253..18db0ad74 100644 --- a/src/supertux/tile_set.hpp +++ b/src/supertux/tile_set.hpp @@ -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]; diff --git a/src/supertux/title_screen.cpp b/src/supertux/title_screen.cpp index 8d3013993..e5ea2915c 100644 --- a/src/supertux/title_screen.cpp +++ b/src/supertux/title_screen.cpp @@ -41,14 +41,14 @@ #include -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); diff --git a/src/supertux/title_screen.hpp b/src/supertux/title_screen.hpp index 19c66adec..f80e1bf6f 100644 --- a/src/supertux/title_screen.hpp +++ b/src/supertux/title_screen.hpp @@ -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(); diff --git a/src/supertux/world.cpp b/src/supertux/world.cpp index e41fb3de7..399816cec 100644 --- a/src/supertux/world.cpp +++ b/src/supertux/world.cpp @@ -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())); } } diff --git a/src/supertux/world.hpp b/src/supertux/world.hpp index 8ab62629f..596ec2c70 100644 --- a/src/supertux/world.hpp +++ b/src/supertux/world.hpp @@ -21,6 +21,8 @@ #include #include +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 player_status; public: bool hide_from_contribs; diff --git a/src/worldmap/tux.cpp b/src/worldmap/tux.cpp index 7ecfb12d1..bce207ae1 100644 --- a/src/worldmap/tux.cpp +++ b/src/worldmap/tux.cpp @@ -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; diff --git a/src/worldmap/worldmap.cpp b/src/worldmap/worldmap.cpp index 7f3a71d83..05004ed2a 100644 --- a/src/worldmap/worldmap.cpp +++ b/src/worldmap/worldmap.cpp @@ -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) { diff --git a/src/worldmap/worldmap.hpp b/src/worldmap/worldmap.hpp index f206ad1cc..1fbf85875 100644 --- a/src/worldmap/worldmap.hpp +++ b/src/worldmap/worldmap.hpp @@ -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); -- 2.11.0