From: mathnerd314 Date: Tue, 29 Dec 2009 18:01:42 +0000 (+0000) Subject: * Revert breaking changes from last revision X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=2afac92aaac4df79cab09877f2d70b58cbaa46a8;p=supertux.git * Revert breaking changes from last revision * Update CMakeLists.txt with a new option COMPILE_AMALGATION (still needs some more work with magic constants) * TODO updates to make it clearer/more informative git-svn-id: http://supertux.lethargik.org/svn/supertux/trunk/supertux@6230 837edb03-e0f3-0310-88ca-d4d4e8b29345 --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 8f60072c3..ed23aa636 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -153,42 +153,47 @@ IF(HAVE_OPENGL) SET(SUPERTUX_SOURCES_CXX ${SUPERTUX_SOURCES_CXX} ${SUPERTUX_OPENGL_SOURCES}) ENDIF(HAVE_OPENGL) -## Precompile "a few" headers in GCC -OPTION(PRECOMPILE_HEADERS "Precompile headers (experimental)" OFF) -IF(PRECOMPILE_HEADERS) - FILE(GLOB PRECOMPILED_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} src/badguy/badguy.hpp - src/scripting/wrapper.hpp src/video/*.hpp src/math/*.hpp) - FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/precompile.hh "// Precompiled headers\n") - FILE(APPEND ${CMAKE_CURRENT_BINARY_DIR}/precompile.hh "#ifndef __SUPERTUX_PRECOMPILED_HEADER\n") - FILE(APPEND ${CMAKE_CURRENT_BINARY_DIR}/precompile.hh "#define __SUPERTUX_PRECOMPILED_HEADER\n") - FOREACH(PRECOMPILED_HEADER ${PRECOMPILED_HEADERS}) - FILE(RELATIVE_PATH PRECOMPILED_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/src "${CMAKE_CURRENT_SOURCE_DIR}/${PRECOMPILED_HEADER}") - FILE(APPEND ${CMAKE_CURRENT_BINARY_DIR}/precompile.hh "#include \"${PRECOMPILED_HEADER}\"\n") - ENDFOREACH(PRECOMPILED_HEADER) - FILE(APPEND ${CMAKE_CURRENT_BINARY_DIR}/precompile.hh "#endif /*__SUPERTUX_PRECOMPILED_HEADER*/\n") +## Build miniswig and generate miniswig wrapper + +OPTION(GENERATE_WRAPPER "Build miniswig and generate the wrapper" ${DEBUG}) +IF(GENERATE_WRAPPER) + ADD_SUBDIRECTORY(tools/miniswig) ADD_CUSTOM_COMMAND( - OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/precompile.hh.gch - COMMAND ${CMAKE_CXX_COMPILER} -x "c++-header" $(CXX_FLAGS) ${CMAKE_CURRENT_BINARY_DIR}/precompile.hh - DEPENDS ${PRECOMPILED_HEADERS} - COMMENT "Building precompiled header..." + OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/src/scripting/wrapper.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/scripting/wrapper.hpp + COMMAND cd ${CMAKE_CURRENT_SOURCE_DIR} && ${CMAKE_CXX_COMPILER} + ARGS -x "c++" -E -CC -DSCRIPTING_API src/scripting/wrapper.interface.hpp -o ${CMAKE_CURRENT_BINARY_DIR}/miniswig.tmp -I${CMAKE_CURRENT_SOURCE_DIR}/src + COMMAND tools/miniswig/miniswig + ARGS --input miniswig.tmp --output-cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/scripting/wrapper.cpp --output-hpp ${CMAKE_CURRENT_SOURCE_DIR}/src/scripting/wrapper.hpp --module supertux --select-namespace scripting + DEPENDS tools/miniswig/miniswig + IMPLICIT_DEPENDS CXX ${CMAKE_CURRENT_SOURCE_DIR}/src/scripting/wrapper.interface.hpp ) - ## Make certain it is built - SET(SUPERTUX_SOURCES_CXX ${CMAKE_CURRENT_BINARY_DIR}/precompile.hh.gch ${SUPERTUX_SOURCES_CXX}) - SET(CMAKE_CXX_FLAGS "-include ${CMAKE_CURRENT_BINARY_DIR}/precompile.hh ${CMAKE_CXX_FLAGS}") -ELSE(PRECOMPILE_HEADERS) - IF(EXISTS ${CMAKE_CURRENT_BINARY_DIR}/precompile.hh) - FILE(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/precompile.hh) - ENDIF(EXISTS ${CMAKE_CURRENT_BINARY_DIR}/precompile.hh) - IF(EXISTS ${CMAKE_CURRENT_BINARY_DIR}/precompile.hh.gch) - FILE(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/precompile.hh.gch) - ENDIF(EXISTS ${CMAKE_CURRENT_BINARY_DIR}/precompile.hh.gch) -ENDIF(PRECOMPILE_HEADERS) +ENDIF(GENERATE_WRAPPER) +IF(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/src/scripting/wrapper.cpp) + SET(SUPERTUX_SOURCES_CXX ${SUPERTUX_SOURCES_CXX} ${CMAKE_CURRENT_SOURCE_DIR}/src/scripting/wrapper.cpp) +ENDIF(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/src/scripting/wrapper.cpp) + +## Compile everything at once (roughly equivalent to cat *.cpp | gcc) + +OPTION(COMPILE_AMALGATION "Compile all the files together at once (experimental)" OFF) +IF(COMPILE_AMALGATION) + FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/amalgation.cpp "// Includes all source files of the project\n") + FOREACH(ST_FILE ${SUPERTUX_SOURCES_CXX}) + FILE(RELATIVE_PATH CXX_FILE ${CMAKE_CURRENT_SOURCE_DIR}/src "${CMAKE_CURRENT_SOURCE_DIR}/${ST_FILE}") + FILE(APPEND ${CMAKE_CURRENT_BINARY_DIR}/amalgation.cpp "#include \"${CXX_FILE}\"\n") + ENDFOREACH(ST_FILE) + ## Build instead of CXX sources + SET(SUPERTUX_SOURCES_CXX ${CMAKE_CURRENT_BINARY_DIR}/amalgation.cpp) +ELSE(COMPILE_AMALGATION) + IF(EXISTS ${CMAKE_CURRENT_BINARY_DIR}/amalgation.cpp) + FILE(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/amalgation.cpp) + ENDIF(EXISTS ${CMAKE_CURRENT_BINARY_DIR}/amalgation.cpp) +ENDIF(COMPILE_AMALGATION) ## Debug options OPTION(WERROR "Stop on first compiler warning" OFF) -OPTION(WARNINGS "Enable long list of warnings for compiler to check" ON) +OPTION(WARNINGS "Enable long list of warnings for compiler to check" ${DEBUG}) IF(CMAKE_COMPILER_IS_GNUCC) SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g" CACHE STRING "Debug flags") SET(CMAKE_C_FLAGS_DEBUG "-O0 -g" CACHE STRING "Debug flags") @@ -202,33 +207,12 @@ IF(CMAKE_COMPILER_IS_GNUCC) REMOVE_DEFINITIONS(-Werror) 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" CACHE STRING "CXX Flags") + 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 -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-Weffc++ -Wabi -Wctor-dtor-privacy -Wstrict-null-sentinel) # -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 + # still left: -Wold-style-cast -Wpadded ENDIF(WARNINGS) ENDIF(CMAKE_COMPILER_IS_GNUCC) -## Build miniswig and generate miniswig wrapper - -OPTION(GENERATE_WRAPPER "Build miniswig and generate the wrapper" ${DEBUG}) -IF(GENERATE_WRAPPER) - ADD_SUBDIRECTORY(tools/miniswig) - ADD_CUSTOM_COMMAND( - OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/src/scripting/wrapper.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/scripting/wrapper.hpp - COMMAND cd ${CMAKE_CURRENT_SOURCE_DIR} && ${CMAKE_CXX_COMPILER} - ARGS -x "c++" -E -CC -DSCRIPTING_API src/scripting/wrapper.interface.hpp -o ${CMAKE_CURRENT_BINARY_DIR}/miniswig.tmp -I${CMAKE_CURRENT_SOURCE_DIR}/src - COMMAND tools/miniswig/miniswig - ARGS --input miniswig.tmp --output-cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/scripting/wrapper.cpp --output-hpp ${CMAKE_CURRENT_SOURCE_DIR}/src/scripting/wrapper.hpp --module supertux --select-namespace scripting - DEPENDS tools/miniswig/miniswig - IMPLICIT_DEPENDS CXX ${CMAKE_CURRENT_SOURCE_DIR}/src/scripting/wrapper.interface.hpp - ) -ENDIF(GENERATE_WRAPPER) - -IF(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/src/scripting/wrapper.cpp) - SET(SUPERTUX_SOURCES_CXX ${SUPERTUX_SOURCES_CXX} ${CMAKE_CURRENT_SOURCE_DIR}/src/scripting/wrapper.cpp) -ENDIF(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/src/scripting/wrapper.cpp) - ## If xgettext is available, generate messages.pot for sources OPTION(GENERATE_MESSAGESPOT "Generate messages.pot files" ${DEBUG}) diff --git a/TODO b/TODO index b0540b238..29d011b45 100644 --- a/TODO +++ b/TODO @@ -35,24 +35,23 @@ Coding Standard Stuff * split files with multiple classes into multiple files with one class each -* static vs anonymous namespace +* Decide what to do with magic constants of objects (static vs anonymous namespace vs lisp property) -* check the code with Valgrind +* check the code with Valgrind and profilers * use Vector in Physics for 'a' and 'v' -* replace random generator with mersene twister and/or move to external/ - -* write/finish scripts for include sorting and include guard checking that - can be run automatically +* replace random generator with mersenne twister and/or move to external/ * md5.hpp and random_generator.hpp could go to external/ -* write scripts to automatically check for: +* write/finish scripts to automatically: + + - make all includes relative to top level dir - - all includes are relative to top level dir + - sort includes (.hpp file, then system includes, then other project files) - - include guards are proper + - include guards proper and of the form HEADER_SUPERTUX_${PATH_TO_FILE}_HPP TODO ==== @@ -62,35 +61,27 @@ TODO * add --datadir DIR (data/) and --userdir DIR (~/.supertux/) -* make gravity a constant - -* funky side effect of too much global variables: when having a - savegame with large or firetux and then starting that game, Tux in - the menu background will grow and be visible that way for a fraction - of a second +* make gravity constant * rename Vector -> Vector2f * get rid of global SDL_Screen* screen variable -* identify all global variables and make them ugly (g_ or globals::) - -* get rid of SCREEN_WIDTH/SCREEN_HEIGHT - -* is version.h actually needed? +* get rid of SCREEN_WIDTH/SCREEN_HEIGHT overuse * resolution menu entry moves the wrong way around * having dictionary_manager in Lisp is extremely ugly -* enforce proper naming of files to match their class +* enforce proper naming of files to match their class (SomeClass -> some_class.?pp or so) + +* file naming is inconsistent: some times we use '_' to separate + words, sometimes we don't * get rid of NDEBUG and conditional compilation, these should be reserved for a few tiny cases, not spread all over the code -* split particlesystem_interactive - -* collect all manager classe into globals.hpp +* collect all manager classes into globals.hpp * more moving directories around? @@ -118,7 +109,7 @@ supertux/ * having hitbox in Sprite is fugly -* write decal object +* write decal object that doesn't have hitbox * implement surface and/or sprite scaling (MipMaps?) @@ -127,9 +118,6 @@ supertux/ * last line has been repeated X times -* file naming is inconsistent: some times we use '_' to separate - words, sometimes we don't - * implement: http://standards.freedesktop.org/basedir-spec/basedir-spec-0.6.html * workaround for Ubuntu pulseaudio/OpenAL brokeness: @@ -143,15 +131,15 @@ drivers = oss * add pipe graphics that makes a 90 degree turn -* keep possible future SDL1.3 upgrade in mind +* keep possible future SDL1.3 upgrade in mind (what has changed?) * cleanup scripting interface -* remove cloud tiles, replace with decal +* replace cloud tiles with decals * option menu has text overlap in "aspect ratio" -* jumping up from an enemy doesn't make a sound +* jumping up from an enemy doesn't make a sound? * add support for automatic scrolling backgrounds @@ -205,7 +193,7 @@ Scenegraph and Physics Engine Restructuring =========================================== * random idea to restructure engine stuff (might lead to nicer code - and easier scriptability and a need to rewrite lots of stuff...): + and easier scriptability (and a need to rewrite lots of stuff...): class SomeBadGuy : public PhysicsCallbackListener // or use boost::function { @@ -249,7 +237,7 @@ Subversion->Git/Mercurial/Bzr Move * right now a switch doesn't seem to be worth it * core issue right now isn't SVN, but old SVN version on lethargik.org - (lacks merge tracking and issues with viewvc) + (lacks merge tracking, issues with viewvc) * cleanup SVN to make import into other version control systems possible: @@ -301,11 +289,7 @@ Potential Git Issues * lack of sparse/narrow/shallow checkout, this means initial checkout will be 200MB instead of 100MB -* no free hoster that allows >1GB repositories (haven't checked all, - but those I did came out way short) -> could use lethargik.org - -* some free hosters that might allow >1GB repositories don't allow - having multiple repositories +* no free hoster that allow multiple >1GB repositories -> could use lethargik.org * git submodule doesn't seem to be quite ready to replace our trunk/supertux, trunk/supertux-editor, trunk/media/, ... layout as @@ -356,7 +340,7 @@ def calc(parallax, screen, tiles): return (1 - parallax) * screen + parallax * tiles * 32 -Supported Resolution +Supported Resolutions ==================== SuperTux shall support resolutions from 640x480 to 1280x800 at a magnification of 1x. diff --git a/src/badguy/angrystone.cpp b/src/badguy/angrystone.cpp index b6defc4af..a45692da4 100644 --- a/src/badguy/angrystone.cpp +++ b/src/badguy/angrystone.cpp @@ -20,7 +20,7 @@ #include "sprite/sprite.hpp" #include "supertux/object_factory.hpp" -static const float SPEED = 240; +static const float CHARGE_SPEED = 240; static const float CHARGE_TIME = .5; static const float ATTACK_TIME = 1; @@ -132,8 +132,8 @@ AngryStone::active_update(float elapsed_time) { timer.start(ATTACK_TIME); state = ATTACKING; physic.enable_gravity(false); - physic.set_velocity_x(SPEED * attackDirection.x); - physic.set_velocity_y(SPEED * attackDirection.y); + physic.set_velocity_x(CHARGE_SPEED * attackDirection.x); + physic.set_velocity_y(CHARGE_SPEED * attackDirection.y); oldWallDirection.x = 0; oldWallDirection.y = 0; } diff --git a/src/badguy/bouncing_snowball.cpp b/src/badguy/bouncing_snowball.cpp index 72995bf1a..64f49f7ca 100644 --- a/src/badguy/bouncing_snowball.cpp +++ b/src/badguy/bouncing_snowball.cpp @@ -20,7 +20,7 @@ #include "supertux/object_factory.hpp" static const float JUMPSPEED = -450; -static const float WALKSPEED = 80; +static const float BSNOWBALL_WALKSPEED = 80; BouncingSnowball::BouncingSnowball(const Reader& reader) : BadGuy(reader, "images/creatures/bouncing_snowball/bouncing_snowball.sprite") @@ -35,7 +35,7 @@ BouncingSnowball::BouncingSnowball(const Vector& pos, Direction d) void BouncingSnowball::initialize() { - physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED); + physic.set_velocity_x(dir == LEFT ? -BSNOWBALL_WALKSPEED : BSNOWBALL_WALKSPEED); sprite->set_action(dir == LEFT ? "left" : "right"); } diff --git a/src/badguy/dart.cpp b/src/badguy/dart.cpp index 10f8ea11a..be6123dd2 100644 --- a/src/badguy/dart.cpp +++ b/src/badguy/dart.cpp @@ -22,10 +22,10 @@ #include "supertux/object_factory.hpp" namespace { -const float SPEED = 200; +const float DART_SPEED = 200; } -static const std::string SOUNDFILE = "sounds/flame.wav"; +static const std::string DART_SOUND = "sounds/flame.wav"; Dart::Dart(const Reader& reader) : BadGuy(reader, "images/creatures/dart/dart.sprite"), @@ -34,7 +34,7 @@ Dart::Dart(const Reader& reader) : { physic.enable_gravity(false); countMe = false; - sound_manager->preload(SOUNDFILE); + sound_manager->preload(DART_SOUND); sound_manager->preload("sounds/darthit.wav"); sound_manager->preload("sounds/stomp.wav"); } @@ -46,7 +46,7 @@ Dart::Dart(const Vector& pos, Direction d, const BadGuy* parent = 0) : { physic.enable_gravity(false); countMe = false; - sound_manager->preload(SOUNDFILE); + sound_manager->preload(DART_SOUND); sound_manager->preload("sounds/darthit.wav"); sound_manager->preload("sounds/stomp.wav"); } @@ -68,14 +68,14 @@ Dart::updatePointers(const GameObject* from_object, GameObject* to_object) void Dart::initialize() { - physic.set_velocity_x(dir == LEFT ? -::SPEED : ::SPEED); + physic.set_velocity_x(dir == LEFT ? -::DART_SPEED : ::DART_SPEED); sprite->set_action(dir == LEFT ? "flying-left" : "flying-right"); } void Dart::activate() { - sound_source.reset(sound_manager->create_sound_source(SOUNDFILE)); + sound_source.reset(sound_manager->create_sound_source(DART_SOUND)); sound_source->set_position(get_pos()); sound_source->set_looping(true); sound_source->set_gain(1.0); diff --git a/src/badguy/igel.cpp b/src/badguy/igel.cpp index 2eaa0abff..857023d83 100644 --- a/src/badguy/igel.cpp +++ b/src/badguy/igel.cpp @@ -22,7 +22,7 @@ namespace { -const float WALKSPEED = 80; /**< speed at which we walk around */ +const float IGEL_SPEED = 80; /**< speed at which we walk around */ const float TURN_RECOVER_TIME = 0.5; /**< seconds before we will again turn around when shot at */ const float RANGE_OF_VISION = 256; /**< range in px at which we can see bullets */ @@ -32,7 +32,7 @@ Igel::Igel(const Reader& reader) : WalkingBadguy(reader, "images/creatures/igel/igel.sprite", "walking-left", "walking-right"), turn_recover_timer() { - walk_speed = WALKSPEED; + walk_speed = IGEL_SPEED; max_drop_height = 16; } @@ -40,7 +40,7 @@ Igel::Igel(const Vector& pos, Direction d) : WalkingBadguy(pos, d, "images/creatures/igel/igel.sprite", "walking-left", "walking-right"), turn_recover_timer() { - walk_speed = WALKSPEED; + walk_speed = IGEL_SPEED; max_drop_height = 16; } diff --git a/src/badguy/jumpy.cpp b/src/badguy/jumpy.cpp index 6e4e92e5c..1117d64c8 100644 --- a/src/badguy/jumpy.cpp +++ b/src/badguy/jumpy.cpp @@ -20,7 +20,7 @@ #include "sprite/sprite.hpp" #include "supertux/object_factory.hpp" -static const float JUMPSPEED=-600; +static const float JUMPYSPEED=-600; static const float JUMPY_MID_TOLERANCE=4; static const float JUMPY_LOW_TOLERANCE=2; @@ -55,7 +55,7 @@ Jumpy::hit(const CollisionHit& chit) groundhit_pos_set = true; } - physic.set_velocity_y((frozen || get_state() == STATE_FALLING) ? 0 : JUMPSPEED); + physic.set_velocity_y((frozen || get_state() == STATE_FALLING) ? 0 : JUMPYSPEED); // TODO create a nice sound for this... //sound_manager->play("sounds/skid.wav"); } else if(chit.top) { diff --git a/src/badguy/kamikazesnowball.cpp b/src/badguy/kamikazesnowball.cpp index daadd9393..0b88f7f3d 100644 --- a/src/badguy/kamikazesnowball.cpp +++ b/src/badguy/kamikazesnowball.cpp @@ -25,7 +25,7 @@ * On impact he is destroyed, trying to kill what he hit or hit him. */ namespace{ - static const float SPEED = 200; + static const float KAMIKAZE_SPEED = 200; const std::string SPLAT_SOUND = "sounds/splat.wav"; } @@ -44,7 +44,7 @@ KamikazeSnowball::KamikazeSnowball(const Vector& pos, Direction d) void KamikazeSnowball::initialize() { - physic.set_velocity_x(dir == LEFT ? -SPEED : SPEED); + physic.set_velocity_x(dir == LEFT ? -KAMIKAZE_SPEED : KAMIKAZE_SPEED); physic.enable_gravity(false); sprite->set_action(dir == LEFT ? "left" : "right"); } diff --git a/src/badguy/kugelblitz.cpp b/src/badguy/kugelblitz.cpp index 14b0239c5..b3eee3723 100644 --- a/src/badguy/kugelblitz.cpp +++ b/src/badguy/kugelblitz.cpp @@ -15,6 +15,9 @@ // along with this program. If not, see . #include "badguy/kugelblitz.hpp" + +#include + #include "math/random_generator.hpp" #include "object/camera.hpp" #include "object/player.hpp" @@ -28,9 +31,6 @@ #define BASE_SPEED 200 #define RAND_SPEED 150 -static const float X_OFFSCREEN_DISTANCE = 1600; -static const float Y_OFFSCREEN_DISTANCE = 1200; - Kugelblitz::Kugelblitz(const Reader& reader) : BadGuy(reader, "images/creatures/kugelblitz/kugelblitz.sprite"), pos_groundhit(), @@ -168,43 +168,30 @@ Kugelblitz::explode() void Kugelblitz::try_activate() { - //FIXME: Don't activate Kugelblitz before it's on-screen - float scroll_x = Sector::current()->camera->get_translation().x; - float scroll_y = Sector::current()->camera->get_translation().y; - - /* Activate badguys if they're just around the screen to avoid - * the effect of having badguys suddenly popping up from nowhere. - */ - if (start_position.x > scroll_x - X_OFFSCREEN_DISTANCE && - start_position.x < scroll_x - bbox.get_width() && - start_position.y > scroll_y - Y_OFFSCREEN_DISTANCE && - start_position.y < scroll_y + Y_OFFSCREEN_DISTANCE) { - dir = RIGHT; - set_state(STATE_ACTIVE); - activate(); - } else if (start_position.x > scroll_x && - start_position.x < scroll_x + X_OFFSCREEN_DISTANCE && - start_position.y > scroll_y - Y_OFFSCREEN_DISTANCE && - start_position.y < scroll_y + Y_OFFSCREEN_DISTANCE) { - dir = LEFT; - set_state(STATE_ACTIVE); - activate(); - } else if (start_position.x > scroll_x - X_OFFSCREEN_DISTANCE && - start_position.x < scroll_x + X_OFFSCREEN_DISTANCE && - ((start_position.y > scroll_y && - start_position.y < scroll_y + Y_OFFSCREEN_DISTANCE) || - (start_position.y > scroll_y - Y_OFFSCREEN_DISTANCE && - start_position.y < scroll_y))) { - dir = start_position.x < scroll_x ? RIGHT : LEFT; - set_state(STATE_ACTIVE); - activate(); - } else if(state == STATE_INIT - && start_position.x > scroll_x - X_OFFSCREEN_DISTANCE - && start_position.x < scroll_x + X_OFFSCREEN_DISTANCE - && start_position.y > scroll_y - Y_OFFSCREEN_DISTANCE - && start_position.y < scroll_y + Y_OFFSCREEN_DISTANCE) { - dir = LEFT; + // Much smaller offscreen distances to pop out of nowhere and surprise Tux + float X_OFFSCREEN_DISTANCE = 400; + float Y_OFFSCREEN_DISTANCE = 600; + + Player* player = get_nearest_player(); + if (!player) return; + Vector dist = player->get_bbox().get_middle() - get_bbox().get_middle(); + if ((fabsf(dist.x) <= X_OFFSCREEN_DISTANCE) && (fabsf(dist.y) <= Y_OFFSCREEN_DISTANCE)) { set_state(STATE_ACTIVE); + if (!is_initialized) { + + // if starting direction was set to AUTO, this is our chance to re-orient the badguy + if (start_dir == AUTO) { + Player* player = get_nearest_player(); + if (player && (player->get_bbox().p1.x > get_bbox().p2.x)) { + dir = RIGHT; + } else { + dir = LEFT; + } + } + + initialize(); + is_initialized = true; + } activate(); } } diff --git a/src/badguy/mrtree.cpp b/src/badguy/mrtree.cpp index 65f81aa1e..f21a926ec 100644 --- a/src/badguy/mrtree.cpp +++ b/src/badguy/mrtree.cpp @@ -27,7 +27,7 @@ #include -static const float WALKSPEED = 100; +static const float TREE_SPEED = 100; static const float POISONIVY_WIDTH = 32; static const float POISONIVY_HEIGHT = 32; @@ -36,7 +36,7 @@ static const float POISONIVY_Y_OFFSET = 24; MrTree::MrTree(const Reader& reader) : WalkingBadguy(reader, "images/creatures/mr_tree/mr_tree.sprite","left","right") { - walk_speed = WALKSPEED; + walk_speed = TREE_SPEED; max_drop_height = 16; sound_manager->preload("sounds/mr_tree.ogg"); } diff --git a/src/badguy/plant.cpp b/src/badguy/plant.cpp index 9b98f63e1..2ddcd2892 100644 --- a/src/badguy/plant.cpp +++ b/src/badguy/plant.cpp @@ -20,7 +20,7 @@ #include "sprite/sprite.hpp" #include "supertux/object_factory.hpp" -static const float WALKSPEED = 80; +static const float PLANT_SPEED = 80; static const float WAKE_TIME = .5; Plant::Plant(const Reader& reader) : @@ -97,7 +97,7 @@ Plant::active_update(float elapsed_time) { if(timer.check()) { // start walking sprite->set_action(dir == LEFT ? "left" : "right"); - physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED); + physic.set_velocity_x(dir == LEFT ? -PLANT_SPEED : PLANT_SPEED); state = PLANT_WALKING; } } diff --git a/src/badguy/snail.cpp b/src/badguy/snail.cpp index 1efedc003..cff4b6304 100644 --- a/src/badguy/snail.cpp +++ b/src/badguy/snail.cpp @@ -24,9 +24,9 @@ #include namespace { -const float KICKSPEED = 500; -const int MAXSQUISHES = 10; -const float KICKSPEED_Y = -500; /**< y-velocity gained when kicked */ +const float SNAIL_KICK_SPEED = 500; +const int MAX_SNAIL_SQUISHES = 10; +const float SNAIL_KICK_SPEED_Y = -500; /**< y-velocity gained when kicked */ } Snail::Snail(const Reader& reader) : @@ -116,8 +116,8 @@ Snail::active_update(float elapsed_time) case STATE_KICKED_DELAY: if (kicked_delay_timer.check()) { - physic.set_velocity_x(dir == LEFT ? -KICKSPEED : KICKSPEED); - physic.set_velocity_y(KICKSPEED_Y); + physic.set_velocity_x(dir == LEFT ? -SNAIL_KICK_SPEED : SNAIL_KICK_SPEED); + physic.set_velocity_y(SNAIL_KICK_SPEED_Y); state = STATE_KICKED; } break; @@ -192,7 +192,7 @@ Snail::collision_squished(GameObject& object) { Player* player = dynamic_cast(&object); squishcount++; - if ((squishcount >= MAXSQUISHES) || (player && player->does_buttjump)) { + if ((squishcount >= MAX_SNAIL_SQUISHES) || (player && player->does_buttjump)) { kill_fall(); return true; } diff --git a/src/gui/button.cpp b/src/gui/button.cpp index 1a89d34d6..587b1e315 100644 --- a/src/gui/button.cpp +++ b/src/gui/button.cpp @@ -78,7 +78,7 @@ void Button::draw(DrawingContext &context, bool selected) if(state == BT_SHOW_INFO) { Vector offset; - if(pos.x + tanslation.x < 100 && pos.y + tanslation.y > SCREEN_SIZE.height - 20) + if(pos.x + tanslation.x < 100 && pos.y + tanslation.y > SCREEN_HEIGHT - 20) offset = Vector(size.x, - 10); else if(pos.x + tanslation.x < 100) offset = Vector(size.x, 0); diff --git a/src/gui/button_group.cpp b/src/gui/button_group.cpp index 9727fb8cd..0a2c7edd1 100644 --- a/src/gui/button_group.cpp +++ b/src/gui/button_group.cpp @@ -103,8 +103,8 @@ ButtonGroup::event(SDL_Event &event) if(mouse_left_button) { - pos.x += int(event.motion.xrel * float(SCREEN_SIZE.width)/g_screen->w); - pos.y += int(event.motion.yrel * float(SCREEN_SIZE.height)/g_screen->h); + pos.x += int(event.motion.xrel * float(SCREEN_WIDTH)/g_screen->w); + pos.y += int(event.motion.yrel * float(SCREEN_HEIGHT)/g_screen->h); caught_event = true; } if(event.button.x > pos.x-12 && event.button.x < pos.x+16 + buttons_box.x*buttons_size.x && diff --git a/src/gui/menu.cpp b/src/gui/menu.cpp index 01be2c79b..4715cd8fb 100644 --- a/src/gui/menu.cpp +++ b/src/gui/menu.cpp @@ -60,7 +60,8 @@ Menu::Menu() : delete_character = 0; mn_input_char = '\0'; - pos = SCREEN_SIZE/2.0f; + pos.x = SCREEN_WIDTH/2; + pos.y = SCREEN_HEIGHT/2; arrange_left = 0; active_item = -1; @@ -92,9 +93,10 @@ Menu::~Menu() } void -Menu::set_pos(Vector loc, Vector r) +Menu::set_pos(float x, float y, float rw, float rh) { - pos = loc + get_size() * r; + pos.x = x + get_width() * rw; + pos.y = y + get_height() * rh; } /* Add an item to a menu */ @@ -218,7 +220,7 @@ Menu::update() if (menu_height > SCREEN_HEIGHT) { // Scrolling int scroll_offset = (menu_height - SCREEN_HEIGHT) / 2 + 32; - pos_y = SCREEN_HEIGHT/2 - scroll_offset * ((float(active_item) / (items.size()-1)) - 0.5f) * 2.0f; + pos.y = SCREEN_HEIGHT/2 - scroll_offset * ((float(active_item) / (items.size()-1)) - 0.5f) * 2.0f; } effect_progress = (real_time - effect_start_time) * 6.0f; @@ -448,15 +450,15 @@ Menu::draw_item(DrawingContext& context, int index) MenuItem& pitem = *(items[index]); Color text_color = default_color; - float x_pos = pos_x; - float y_pos = pos_y + 24*index - menu_height/2 + 12; + float x_pos = pos.x; + float y_pos = pos.y + 24*index - menu_height/2 + 12; int shadow_size = 2; int text_width = int(Resources::normal_font->get_text_width(pitem.text)); int input_width = int(Resources::normal_font->get_text_width(pitem.input) + 10); int list_width = 0; - float left = pos_x - menu_width/2 + 16; - float right = pos_x + menu_width/2 - 16; + float left = pos.x - menu_width/2 + 16; + float right = pos.x + menu_width/2 - 16; if(pitem.list.size() > 0) { list_width = (int) Resources::normal_font->get_text_width(pitem.list[pitem.selected]); @@ -474,13 +476,13 @@ Menu::draw_item(DrawingContext& context, int index) if(active_item == index) { float blink = (sinf(real_time * M_PI * 1.0f)/2.0f + 0.5f) * 0.5f + 0.25f; - context.draw_filled_rect(Rectf(Vector(pos_x - menu_width/2 + 10 - 2, y_pos - 12 - 2), - Vector(pos_x + menu_width/2 - 10 + 2, y_pos + 12 + 2)), + context.draw_filled_rect(Rectf(Vector(pos.x - menu_width/2 + 10 - 2, y_pos - 12 - 2), + Vector(pos.x + menu_width/2 - 10 + 2, y_pos + 12 + 2)), Color(1.0f, 1.0f, 1.0f, blink), 14.0f, LAYER_GUI-10); - context.draw_filled_rect(Rectf(Vector(pos_x - menu_width/2 + 10, y_pos - 12), - Vector(pos_x + menu_width/2 - 10, y_pos + 12)), + context.draw_filled_rect(Rectf(Vector(pos.x - menu_width/2 + 10, y_pos - 12), + Vector(pos.x + menu_width/2 - 10, y_pos + 12)), Color(1.0f, 1.0f, 1.0f, 0.5f), 12.0f, LAYER_GUI-10); @@ -491,7 +493,7 @@ Menu::draw_item(DrawingContext& context, int index) case MN_INACTIVE: { context.draw_text(Resources::normal_font, pitem.text, - Vector(pos_x, y_pos - int(Resources::normal_font->get_height()/2)), + Vector(pos.x, y_pos - int(Resources::normal_font->get_height()/2)), ALIGN_CENTER, LAYER_GUI, inactive_color); break; } @@ -499,7 +501,7 @@ Menu::draw_item(DrawingContext& context, int index) case MN_HL: { // TODO - float x = pos_x - menu_width/2; + float x = pos.x - menu_width/2; float y = y_pos - 12; /* Draw a horizontal line with a little 3d effect */ context.draw_filled_rect(Vector(x, y + 6), @@ -513,7 +515,7 @@ Menu::draw_item(DrawingContext& context, int index) case MN_LABEL: { context.draw_text(Resources::big_font, pitem.text, - Vector(pos_x, y_pos - int(Resources::big_font->get_height()/2)), + Vector(pos.x, y_pos - int(Resources::big_font->get_height()/2)), ALIGN_CENTER, LAYER_GUI, label_color); break; } @@ -567,7 +569,7 @@ Menu::draw_item(DrawingContext& context, int index) case MN_BACK: { context.draw_text(Resources::Resources::normal_font, pitem.text, - Vector(pos_x, y_pos - int(Resources::normal_font->get_height()/2)), + Vector(pos.x, y_pos - int(Resources::normal_font->get_height()/2)), ALIGN_CENTER, LAYER_GUI, text_color); context.draw_surface(back, Vector(x_pos + text_width/2 + 16, y_pos - 8), @@ -578,7 +580,7 @@ Menu::draw_item(DrawingContext& context, int index) case MN_TOGGLE: { context.draw_text(Resources::normal_font, pitem.text, - Vector(pos_x - menu_width/2 + 16, y_pos - (Resources::normal_font->get_height()/2)), + Vector(pos.x - menu_width/2 + 16, y_pos - (Resources::normal_font->get_height()/2)), ALIGN_LEFT, LAYER_GUI, text_color); if(pitem.toggled) @@ -593,13 +595,13 @@ Menu::draw_item(DrawingContext& context, int index) } case MN_ACTION: context.draw_text(Resources::normal_font, pitem.text, - Vector(pos_x, y_pos - int(Resources::normal_font->get_height()/2)), + Vector(pos.x, y_pos - int(Resources::normal_font->get_height()/2)), ALIGN_CENTER, LAYER_GUI, text_color); break; case MN_GOTO: context.draw_text(Resources::normal_font, pitem.text, - Vector(pos_x, y_pos - int(Resources::normal_font->get_height()/2)), + Vector(pos.x, y_pos - int(Resources::normal_font->get_height()/2)), ALIGN_CENTER, LAYER_GUI, text_color); break; } @@ -667,14 +669,14 @@ Menu::draw(DrawingContext& context) } /* Draw a transparent background */ - context.draw_filled_rect(Rectf(Vector(pos_x - menu_width/2-4, pos_y - menu_height/2 - 10-4), - Vector(pos_x + menu_width/2+4, pos_y - menu_height/2 + 10 + menu_height+4)), + context.draw_filled_rect(Rectf(Vector(pos.x - menu_width/2-4, pos.y - menu_height/2 - 10-4), + Vector(pos.x + menu_width/2+4, pos.y - menu_height/2 + 10 + menu_height+4)), Color(0.2f, 0.3f, 0.4f, 0.8f), 20.0f, LAYER_GUI-10); - context.draw_filled_rect(Rectf(Vector(pos_x - menu_width/2, pos_y - menu_height/2 - 10), - Vector(pos_x + menu_width/2, pos_y - menu_height/2 + 10 + menu_height)), + context.draw_filled_rect(Rectf(Vector(pos.x - menu_width/2, pos.y - menu_height/2 - 10), + Vector(pos.x + menu_width/2, pos.y - menu_height/2 + 10 + menu_height)), Color(0.6f, 0.7f, 0.8f, 0.5f), 16.0f, LAYER_GUI-10); @@ -684,9 +686,9 @@ Menu::draw(DrawingContext& context) int text_width = (int) Resources::normal_font->get_text_width(items[active_item]->help); int text_height = (int) Resources::normal_font->get_text_height(items[active_item]->help); - Rectf text_rect(pos_x - text_width/2 - 8, + Rectf text_rect(pos.x - text_width/2 - 8, SCREEN_HEIGHT - 48 - text_height/2 - 4, - pos_x + text_width/2 + 8, + pos.x + text_width/2 + 8, SCREEN_HEIGHT - 48 + text_height/2 + 4); context.draw_filled_rect(Rectf(text_rect.p1 - Vector(4,4), @@ -701,7 +703,7 @@ Menu::draw(DrawingContext& context) LAYER_GUI-10); context.draw_text(Resources::normal_font, items[active_item]->help, - Vector(pos_x, SCREEN_HEIGHT - 48 - text_height/2), + Vector(pos.x, SCREEN_HEIGHT - 48 - text_height/2), ALIGN_CENTER, LAYER_GUI); } @@ -779,10 +781,10 @@ Menu::event(const SDL_Event& event) int x = int(event.motion.x * float(SCREEN_WIDTH)/g_screen->w); int y = int(event.motion.y * float(SCREEN_HEIGHT)/g_screen->h); - if(x > pos_x - get_width()/2 && - x < pos_x + get_width()/2 && - y > pos_y - get_height()/2 && - y < pos_y + get_height()/2) + if(x > pos.x - get_width()/2 && + x < pos.x + get_width()/2 && + y > pos.y - get_height()/2 && + y < pos.y + get_height()/2) { menuaction = MENU_ACTION_HIT; } @@ -794,13 +796,13 @@ Menu::event(const SDL_Event& event) float x = event.motion.x * SCREEN_WIDTH/g_screen->w; float y = event.motion.y * SCREEN_HEIGHT/g_screen->h; - if(x > pos_x - get_width()/2 && - x < pos_x + get_width()/2 && - y > pos_y - get_height()/2 && - y < pos_y + get_height()/2) + if(x > pos.x - get_width()/2 && + x < pos.x + get_width()/2 && + y > pos.y - get_height()/2 && + y < pos.y + get_height()/2) { int new_active_item - = static_cast ((y - (pos_y - get_height()/2)) / 24); + = static_cast ((y - (pos.y - get_height()/2)) / 24); /* only change the mouse focus to a selectable item */ if ((items[new_active_item]->kind != MN_HL) diff --git a/src/gui/menu.hpp b/src/gui/menu.hpp index 0ab66c6cc..b00c9c890 100644 --- a/src/gui/menu.hpp +++ b/src/gui/menu.hpp @@ -21,7 +21,7 @@ #include #include -#include "math/sizef.hpp" +#include "math/vector.hpp" #include "video/color.hpp" #include "video/surface_ptr.hpp" @@ -91,7 +91,7 @@ public: void set_active_item(int id); void draw(DrawingContext& context); - void set_pos(Vector loc, Vector r = Vector(0,0)); + void set_pos(float x, float y, float rw = 0, float rh = 0); void event(const SDL_Event& event); @@ -102,7 +102,8 @@ public: protected: void additem(MenuItem* pmenu_item); - Sizef get_size() const; + float get_width() const; + float get_height() const; private: void check_controlfield_change_event(const SDL_Event& event); diff --git a/src/math/size.hpp b/src/math/size.hpp index 91a7868e1..81983d6f5 100644 --- a/src/math/size.hpp +++ b/src/math/size.hpp @@ -19,7 +19,7 @@ #include -#include "math/vector.hpp" +class Sizef; class Size { @@ -92,12 +92,6 @@ inline Size operator/(const Size& lhs, int divisor) lhs.height / divisor); } -inline Vector operator/(const Size& lhs, float divisor) -{ - return Vector(lhs.width / divisor, - lhs.height / divisor); -} - inline Size operator+(const Size& lhs, const Size& rhs) { return Size(lhs.width + rhs.width, diff --git a/src/math/sizef.hpp b/src/math/sizef.hpp index e9580f6eb..e03aeb03c 100644 --- a/src/math/sizef.hpp +++ b/src/math/sizef.hpp @@ -19,8 +19,6 @@ #include -#include "math/vector.hpp" - class Size; class Sizef @@ -100,24 +98,6 @@ inline Sizef operator+(const Sizef& lhs, const Sizef& rhs) lhs.height + rhs.height); } -inline Vector operator+(const Vector& lhs, const Sizef& rhs) const -{ - return Vector(lhs.x + rhs.width, - lhs.y + rhs.height); -} - -inline Vector operator*(const Vector& lhs, const Sizef& rhs) const -{ - return Vector(lhs.x * rhs.width, - lhs.y * rhs.height); -} - -inline Vector operator*(const Sizefr& lhs, const Vector& rhs) const -{ - return Vector(lhs.width * rhs.x, - lhs.height * rhs.y); -} - inline Sizef operator-(const Sizef& lhs, const Sizef& rhs) { return Sizef(lhs.width - rhs.width, diff --git a/src/object/tilemap.cpp b/src/object/tilemap.cpp index b43ee331c..a4c851093 100644 --- a/src/object/tilemap.cpp +++ b/src/object/tilemap.cpp @@ -207,12 +207,12 @@ TileMap::draw(DrawingContext& context) int(trans_y * speed_y))); } - float start_x = context.get_translation().x; - float start_y = context.get_translation().y; + int tsx = int((context.get_translation().x - x_offset) / 32); // tilestartindex x + int tsy = int((context.get_translation().y - y_offset) / 32); // tilestartindex y + float start_x = tsx * 32 + x_offset; + float start_y = tsy * 32 + y_offset; float end_x = start_x + SCREEN_WIDTH + 32; float end_y = start_y + SCREEN_HEIGHT + 32; - int tsx = std::max(int((start_x - x_offset) / 32), 0); // tilestartindex x - int tsy = std::max(int((start_y - y_offset) / 32), 0); // tilestartindex y Vector pos; int tx, ty; diff --git a/src/scripting/camera.cpp b/src/scripting/camera.cpp index cb04acf88..a2a180ef3 100644 --- a/src/scripting/camera.cpp +++ b/src/scripting/camera.cpp @@ -19,8 +19,6 @@ #include "scripting/camera.hpp" #include "util/log.hpp" -#define NOIMPL log_fatal << __FUNCTION__ << " not implemented." - namespace scripting { Camera::Camera(::Camera* camera) : camera(camera) diff --git a/src/scripting/candle.cpp b/src/scripting/candle.cpp index 3bec7d55d..018ddb58c 100644 --- a/src/scripting/candle.cpp +++ b/src/scripting/candle.cpp @@ -17,8 +17,6 @@ #include "object/candle.hpp" #include "scripting/candle.hpp" -#define NOIMPL log_fatal << __PRETTY_FUNCTION__ << " not implemented." - namespace scripting { Candle::Candle(::Candle* candle) diff --git a/src/supertux/globals.hpp b/src/supertux/globals.hpp index 0fe3f794c..08a48304e 100644 --- a/src/supertux/globals.hpp +++ b/src/supertux/globals.hpp @@ -23,17 +23,21 @@ class Config; class JoystickKeyboardController; class PlayerStatus; class ScreenManager; -class Size; class SoundManager; class SpriteManager; class TextureManager; class TileManager; class TileSet; -/** The width/height of the display (this is a logical value, not the +/** The width of the display (this is a logical value, not the physical value, since aspect_ration and projection_area might shrink or scale things) */ -extern Size SCREEN_SIZE; +extern int SCREEN_WIDTH; + +/** The width of the display (this is a logical value, not the + physical value, since aspect_ration and projection_area might + shrink or scale things) */ +extern int SCREEN_HEIGHT; // global variables extern JoystickKeyboardController* g_main_controller;