From 9b58f72e1c6900540c0ee00a800ed57d2c1f4974 Mon Sep 17 00:00:00 2001 From: Matthias Braun Date: Wed, 19 Apr 2006 09:35:49 +0000 Subject: [PATCH] 2 more evil mainloops are gone SVN-Revision: 3365 --- data/levels/world1/world.nut | 1 + src/audio/sound_manager.hpp | 3 - src/fadeout.cpp | 57 +++++++++++++++ src/fadeout.hpp | 47 ++++++++++++ src/game_session.cpp | 3 +- src/gui/menu.cpp | 1 - src/level.cpp | 4 -- src/log.hpp | 8 +-- src/mainloop.cpp | 58 ++++++++++----- src/mainloop.hpp | 11 +-- src/object/fireworks.cpp | 10 ++- src/object/player.cpp | 1 - src/{video/screen.hpp => screen_fade.hpp} | 30 ++++---- src/scripting/functions.cpp | 17 ++++- src/scripting/functions.hpp | 11 +++ src/scripting/wrapper.cpp | 68 ++++++++++++++++++ src/shrinkfade.cpp | 73 +++++++++++++++++++ src/shrinkfade.hpp | 47 ++++++++++++ src/textscroller.cpp | 8 +-- src/tile.cpp | 20 +----- src/tile.hpp | 5 -- src/title.cpp | 10 ++- src/trigger/sequence_trigger.cpp | 1 + src/video/screen.cpp | 116 ------------------------------ src/video/surface.cpp | 1 - src/worldmap/worldmap.cpp | 13 ++-- src/worldmap/worldmap.hpp | 1 - 27 files changed, 415 insertions(+), 210 deletions(-) create mode 100644 src/fadeout.cpp create mode 100644 src/fadeout.hpp rename src/{video/screen.hpp => screen_fade.hpp} (64%) create mode 100644 src/shrinkfade.cpp create mode 100644 src/shrinkfade.hpp delete mode 100644 src/video/screen.cpp diff --git a/data/levels/world1/world.nut b/data/levels/world1/world.nut index 41db5c98c..278e7ac85 100644 --- a/data/levels/world1/world.nut +++ b/data/levels/world1/world.nut @@ -6,6 +6,7 @@ if(! ("intro_displayed" in state)) { save_state(); } load_worldmap("levels/world1/worldmap.stwm"); +fadeout_screen(0.5); wait_for_screenswitch(); save_state(); wait_for_screenswitch(); diff --git a/src/audio/sound_manager.hpp b/src/audio/sound_manager.hpp index b2c5cc955..e93113bd9 100644 --- a/src/audio/sound_manager.hpp +++ b/src/audio/sound_manager.hpp @@ -16,7 +16,6 @@ // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - #ifndef __SOUND_MANAGER_H__ #define __SOUND_MANAGER_H__ @@ -28,8 +27,6 @@ #include #include "math/vector.hpp" -typedef void* SoundHandle; - class SoundFile; class SoundSource; class StreamSoundSource; diff --git a/src/fadeout.cpp b/src/fadeout.cpp new file mode 100644 index 000000000..f7b775215 --- /dev/null +++ b/src/fadeout.cpp @@ -0,0 +1,57 @@ +// $Id: screen.hpp 3327 2006-04-13 15:02:40Z ravu_al_hemio $ +// +// SuperTux +// Copyright (C) 2006 Matthias Braun +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +#include + +#include "fadeout.hpp" +#include "main.hpp" +#include "video/drawing_context.hpp" + +FadeOut::FadeOut(float fade_time, Color color) + : color(color), fade_time(fade_time), accum_time(0) +{ +} + +FadeOut::~FadeOut() +{ +} + +void +FadeOut::update(float elapsed_time) +{ + accum_time += elapsed_time; + if(accum_time > fade_time) + accum_time = fade_time; +} + +void +FadeOut::draw(DrawingContext& context) +{ + Color col = color; + col.alpha = accum_time / fade_time; + context.draw_filled_rect(Vector(0, 0), + Vector(SCREEN_WIDTH, SCREEN_HEIGHT), + col, LAYER_GUI+1); +} + +bool +FadeOut::done() +{ + return accum_time >= fade_time; +} + diff --git a/src/fadeout.hpp b/src/fadeout.hpp new file mode 100644 index 000000000..4afcdfadb --- /dev/null +++ b/src/fadeout.hpp @@ -0,0 +1,47 @@ +// $Id: screen.hpp 3327 2006-04-13 15:02:40Z ravu_al_hemio $ +// +// SuperTux +// Copyright (C) 2006 Matthias Braun +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +#ifndef __FADEOUT_HPP__ +#define __FADEOUT_HPP__ + +#include "video/color.hpp" +#include "screen_fade.hpp" + +/** + * Fades a screen towards a specific color + */ +class FadeOut : public ScreenFade +{ +public: + FadeOut(float fade_time, Color dest_color = Color(0, 0, 0)); + virtual ~FadeOut(); + + virtual void update(float elapsed_time); + virtual void draw(DrawingContext& context); + + /// returns true if the effect is completed + virtual bool done(); + +private: + Color color; + float fade_time; + float accum_time; +}; + +#endif + diff --git a/src/game_session.cpp b/src/game_session.cpp index 0e817deb6..2f6637276 100644 --- a/src/game_session.cpp +++ b/src/game_session.cpp @@ -36,7 +36,6 @@ #include "log.hpp" #include "worldmap/worldmap.hpp" #include "mainloop.hpp" -#include "video/screen.hpp" #include "audio/sound_manager.hpp" #include "gui/menu.hpp" #include "sector.hpp" @@ -138,7 +137,7 @@ GameSession::restart_level(bool fromBeginning) currentsector->activate("main"); } - levelintro(); + //levelintro(); currentsector->play_music(LEVEL_MUSIC); diff --git a/src/gui/menu.cpp b/src/gui/menu.cpp index 0045fbc77..7374ff7e9 100644 --- a/src/gui/menu.cpp +++ b/src/gui/menu.cpp @@ -32,7 +32,6 @@ #include "menu.hpp" #include "mainloop.hpp" -#include "video/screen.hpp" #include "video/drawing_context.hpp" #include "gettext.hpp" #include "math/vector.hpp" diff --git a/src/level.cpp b/src/level.cpp index 1ba57a4f4..abe01093c 100644 --- a/src/level.cpp +++ b/src/level.cpp @@ -29,7 +29,6 @@ #include #include -#include "video/screen.hpp" #include "log.hpp" #include "lisp/parser.hpp" #include "lisp/lisp.hpp" @@ -46,9 +45,6 @@ #include "object/tilemap.hpp" #include "object/coin.hpp" -// test -#include "flip_level_transformer.hpp" - using namespace std; Level::Level() diff --git a/src/log.hpp b/src/log.hpp index eb1406922..b26960a16 100644 --- a/src/log.hpp +++ b/src/log.hpp @@ -30,22 +30,22 @@ namespace { inline std::ostream& log_debug_f(const char* file, int line) { - Console::output << "[DEBUG] " << file << " l." << line << ": "; + Console::output << "[DEBUG] " << file << ":" << line << " "; return Console::output; } inline std::ostream& log_info_f(const char* file, int line) { - Console::output << "[INFO] " << file << " l." << line << ": "; + Console::output << "[INFO] " << file << ":" << line << " "; return Console::output; } inline std::ostream& log_warning_f(const char* file, int line) { - Console::output << "[WARNING] " << file << " l." << line << ": "; + Console::output << "[WARNING] " << file << ":" << line << " "; return Console::output; } inline std::ostream& log_fatal_f(const char* file, int line) { - Console::output << "[FATAL] " << file << " l." << line << ": "; + Console::output << "[FATAL] " << file << ":" << line << " "; return Console::output; } diff --git a/src/mainloop.cpp b/src/mainloop.cpp index 7e5a01bc5..98c8efc97 100644 --- a/src/mainloop.cpp +++ b/src/mainloop.cpp @@ -31,6 +31,7 @@ #include "resources.hpp" #include "script_manager.hpp" #include "screen.hpp" +#include "screen_fade.hpp" #include "timer.hpp" #include "player_status.hpp" @@ -55,30 +56,36 @@ MainLoop::~MainLoop() } void -MainLoop::push_screen(Screen* screen) +MainLoop::push_screen(Screen* screen, ScreenFade* screen_fade) { this->next_screen.reset(screen); - nextpush = true; + this->screen_fade.reset(screen_fade); + nextpop = false; speed = 1.0; } void -MainLoop::exit_screen() +MainLoop::exit_screen(ScreenFade* screen_fade) { - if (screen_stack.size() < 1) { - quit(); - return; - } - next_screen.reset(screen_stack.back()); - nextpush = false; - screen_stack.pop_back(); - speed = 1.0; + next_screen.reset(NULL); + this->screen_fade.reset(screen_fade); + nextpop = true; +} + +void +MainLoop::set_screen_fade(ScreenFade* screen_fade) +{ + this->screen_fade.reset(screen_fade); } void -MainLoop::quit() +MainLoop::quit(ScreenFade* screen_fade) { - running = false; + for(std::vector::iterator i = screen_stack.begin(); + i != screen_stack.end(); ++i) + delete *i; + + exit_screen(screen_fade); } void @@ -111,9 +118,22 @@ MainLoop::run() running = true; while(running) { - if(next_screen.get() != NULL) { - if(nextpush && current_screen.get() != NULL) { + if( (next_screen.get() != NULL || nextpop == true) && + (screen_fade.get() == NULL || screen_fade->done())) { + if(current_screen.get() != NULL) { current_screen->leave(); + } + + if(nextpop) { + if(screen_stack.empty()) { + running = false; + break; + } + next_screen.reset(screen_stack.back()); + screen_stack.pop_back(); + nextpop = false; + speed = 1.0; + } else if(current_screen.get() != NULL) { screen_stack.push_back(current_screen.release()); } @@ -121,7 +141,7 @@ MainLoop::run() ScriptManager::instance->fire_wakeup_event(ScriptManager::SCREEN_SWITCHED); current_screen.reset(next_screen.release()); next_screen.reset(NULL); - nextpush = false; + screen_fade.reset(NULL); } if(current_screen.get() == NULL) @@ -155,7 +175,9 @@ MainLoop::run() if(!skipdraw) { current_screen->draw(context); if(Menu::current() != NULL) - Menu::current()->draw(context); + Menu::current()->draw(context); + if(screen_fade.get() != NULL) + screen_fade->draw(context); Console::instance->draw(context); if(config->show_fps) @@ -182,6 +204,8 @@ MainLoop::run() game_time += elapsed_time; ScriptManager::instance->update(); current_screen->update(elapsed_time); + if(screen_fade.get() != NULL) + screen_fade->update(elapsed_time); Console::instance->update(elapsed_time); main_controller->update(); diff --git a/src/mainloop.hpp b/src/mainloop.hpp index dfb2f9ed4..5e51d2df1 100644 --- a/src/mainloop.hpp +++ b/src/mainloop.hpp @@ -24,6 +24,7 @@ class Screen; class Console; +class ScreenFade; class DrawingContext; class MainLoop @@ -33,22 +34,24 @@ public: ~MainLoop(); void run(); - void exit_screen(); - void quit(); + void exit_screen(ScreenFade* fade = NULL); + void quit(ScreenFade* fade = NULL); void set_speed(float speed); // push new screen on screen_stack - void push_screen(Screen* screen); + void push_screen(Screen* screen, ScreenFade* fade = NULL); + void set_screen_fade(ScreenFade* fade); private: void draw_fps(DrawingContext& context, float fps); bool running; float speed; - bool nextpush; + bool nextpop; std::auto_ptr next_screen; std::auto_ptr current_screen; std::auto_ptr console; + std::auto_ptr screen_fade; std::vector screen_stack; }; diff --git a/src/object/fireworks.cpp b/src/object/fireworks.cpp index 68ac1e0e0..acfa8815a 100644 --- a/src/object/fireworks.cpp +++ b/src/object/fireworks.cpp @@ -46,8 +46,14 @@ Fireworks::update(float ) pos += Vector(SCREEN_WIDTH * ((float) rand() / RAND_MAX), SCREEN_HEIGHT/2 * ((float) rand() / RAND_MAX)); - float red = static_cast(rand() % 255) / 255.0; - float green = static_cast(rand() % ((int) red*255)) / 255.0; + int r = rand() % 255; + int g = rand() % 255; + float red = r / 255.0; + float green = g / 255.0; + //float red = 0.7; + //float green = 0.9; + (void) red; + (void) green; sector->add_object(new Particles(pos, 0, 360, Vector(140, 140), Vector(0, 0), 45, Color(red, green, 0), 3, 1.3, LAYER_FOREGROUND1+1)); diff --git a/src/object/player.cpp b/src/object/player.cpp index 369ca83a8..1a60e53b3 100644 --- a/src/object/player.cpp +++ b/src/object/player.cpp @@ -32,7 +32,6 @@ #include "sprite/sprite.hpp" #include "sector.hpp" #include "resources.hpp" -#include "video/screen.hpp" #include "statistics.hpp" #include "game_session.hpp" #include "object/tilemap.hpp" diff --git a/src/video/screen.hpp b/src/screen_fade.hpp similarity index 64% rename from src/video/screen.hpp rename to src/screen_fade.hpp index ab21a5569..bd78e5986 100644 --- a/src/video/screen.hpp +++ b/src/screen_fade.hpp @@ -1,4 +1,4 @@ -// $Id$ +// $Id: screen.hpp 3327 2006-04-13 15:02:40Z ravu_al_hemio $ // // SuperTux // Copyright (C) 2006 Matthias Braun @@ -16,18 +16,24 @@ // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +#ifndef __SCREENFADE_HPP__ +#define __SCREENFADE_HPP__ -#ifndef SUPERTUX_SCREEN_H -#define SUPERTUX_SCREEN_H +#include "screen.hpp" -#include -#include -#include - -#include -#include "math/vector.hpp" - -void fadeout(float fade_time); -void shrink_fade(const Vector& point, float fade_time); +/** + * A ScreenFade screen is displayed simultaneously with another screen. This + * is intended to be used for transitional effects like fade-out or shrink-fade + */ +class ScreenFade : public Screen +{ +public: + virtual ~ScreenFade() + {} + + /// returns true if the effect is completed + virtual bool done() = 0; +}; #endif + diff --git a/src/scripting/functions.cpp b/src/scripting/functions.cpp index 9d4515427..f1a3715cb 100644 --- a/src/scripting/functions.cpp +++ b/src/scripting/functions.cpp @@ -41,6 +41,8 @@ #include "object/player.hpp" #include "object/tilemap.hpp" #include "main.hpp" +#include "fadeout.hpp" +#include "shrinkfade.hpp" #include "object/camera.hpp" #include "flip_level_transformer.hpp" @@ -75,6 +77,16 @@ void exit_screen() main_loop->exit_screen(); } +void fadeout_screen(float seconds) +{ + main_loop->set_screen_fade(new FadeOut(seconds)); +} + +void shrink_screen(float dest_x, float dest_y, float seconds) +{ + main_loop->set_screen_fade(new ShrinkFade(Vector(dest_x, dest_y), seconds)); +} + std::string translate(const std::string& text) { return dictionary_manager.get_dictionary().translate(text); @@ -107,7 +119,6 @@ static SQInteger squirrel_read_char(SQUserPointer file) return c; } - void import(HSQUIRRELVM vm, const std::string& filename) { IFileStream in(filename); @@ -146,9 +157,13 @@ void debug_draw_solids_only(bool enable) void save_state() { + using namespace WorldMapNS; + if(World::current() == NULL) throw std::runtime_error("Can't save state without active World"); + if(WorldMap::current() != NULL) + WorldMap::current()->save_state(); World::current()->save_state(); } diff --git a/src/scripting/functions.hpp b/src/scripting/functions.hpp index 4793cdbfa..9222c0ed1 100644 --- a/src/scripting/functions.hpp +++ b/src/scripting/functions.hpp @@ -74,6 +74,17 @@ void wait_for_screenswitch(HSQUIRRELVM vm) __suspend; void exit_screen(); /** + * Does a fadeout for the specified number of seconds before next screenchange + */ +void fadeout_screen(float seconds); + +/** + * Does a shrinking fade towards the destposition for the specified number of + * seconds before next screenchange + */ +void shrink_screen(float dest_x, float dest_y, float seconds); + +/** * Translate a text into the users language (by looking it up in the .po * files) */ diff --git a/src/scripting/wrapper.cpp b/src/scripting/wrapper.cpp index 1068071c4..4f2592e20 100644 --- a/src/scripting/wrapper.cpp +++ b/src/scripting/wrapper.cpp @@ -1612,6 +1612,62 @@ static int exit_screen_wrapper(HSQUIRRELVM vm) } +static int fadeout_screen_wrapper(HSQUIRRELVM vm) +{ + float arg0; + if(SQ_FAILED(sq_getfloat(vm, 2, &arg0))) { + sq_throwerror(vm, _SC("Argument 1 not a float")); + return SQ_ERROR; + } + + try { + Scripting::fadeout_screen(arg0); + + return 0; + + } catch(std::exception& e) { + sq_throwerror(vm, e.what()); + return SQ_ERROR; + } catch(...) { + sq_throwerror(vm, _SC("Unexpected exception while executing function 'fadeout_screen'")); + return SQ_ERROR; + } + +} + +static int shrink_screen_wrapper(HSQUIRRELVM vm) +{ + float arg0; + if(SQ_FAILED(sq_getfloat(vm, 2, &arg0))) { + sq_throwerror(vm, _SC("Argument 1 not a float")); + return SQ_ERROR; + } + float arg1; + if(SQ_FAILED(sq_getfloat(vm, 3, &arg1))) { + sq_throwerror(vm, _SC("Argument 2 not a float")); + return SQ_ERROR; + } + float arg2; + if(SQ_FAILED(sq_getfloat(vm, 4, &arg2))) { + sq_throwerror(vm, _SC("Argument 3 not a float")); + return SQ_ERROR; + } + + try { + Scripting::shrink_screen(arg0, arg1, arg2); + + return 0; + + } catch(std::exception& e) { + sq_throwerror(vm, e.what()); + return SQ_ERROR; + } catch(...) { + sq_throwerror(vm, _SC("Unexpected exception while executing function 'shrink_screen'")); + return SQ_ERROR; + } + +} + static int translate_wrapper(HSQUIRRELVM vm) { const char* arg0; @@ -2301,6 +2357,18 @@ void register_supertux_wrapper(HSQUIRRELVM v) throw SquirrelError(v, "Couldn't register function 'exit_screen'"); } + sq_pushstring(v, "fadeout_screen", -1); + sq_newclosure(v, &fadeout_screen_wrapper, 0); + if(SQ_FAILED(sq_createslot(v, -3))) { + throw SquirrelError(v, "Couldn't register function 'fadeout_screen'"); + } + + sq_pushstring(v, "shrink_screen", -1); + sq_newclosure(v, &shrink_screen_wrapper, 0); + if(SQ_FAILED(sq_createslot(v, -3))) { + throw SquirrelError(v, "Couldn't register function 'shrink_screen'"); + } + sq_pushstring(v, "translate", -1); sq_newclosure(v, &translate_wrapper, 0); if(SQ_FAILED(sq_createslot(v, -3))) { diff --git a/src/shrinkfade.cpp b/src/shrinkfade.cpp new file mode 100644 index 000000000..0b999004e --- /dev/null +++ b/src/shrinkfade.cpp @@ -0,0 +1,73 @@ +// $Id: screen.hpp 3327 2006-04-13 15:02:40Z ravu_al_hemio $ +// +// SuperTux +// Copyright (C) 2006 Matthias Braun +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +#include + +#include "shrinkfade.hpp" +#include "main.hpp" +#include "video/drawing_context.hpp" + +ShrinkFade::ShrinkFade(const Vector& dest, float fade_time) + : dest(dest), fade_time(fade_time), accum_time(0) +{ + speedleft = dest.x / fade_time; + speedright = (SCREEN_WIDTH - dest.x) / fade_time; + speedtop = dest.y / fade_time; + speedbottom = (SCREEN_HEIGHT - dest.y) / fade_time; +} + +ShrinkFade::~ShrinkFade() +{ +} + +void +ShrinkFade::update(float elapsed_time) +{ + accum_time += elapsed_time; + if(accum_time > fade_time) + accum_time = fade_time; +} + +void +ShrinkFade::draw(DrawingContext& context) +{ + Color black(0, 0, 0); + float left = speedleft * accum_time; + float top = speedtop * accum_time; + float right = SCREEN_WIDTH - speedright * accum_time; + float bottom = SCREEN_HEIGHT - speedbottom * accum_time; + + context.draw_filled_rect(Vector(0, 0), + Vector(left, SCREEN_HEIGHT), + black, LAYER_GUI+1); + context.draw_filled_rect(Vector(0, 0), + Vector(SCREEN_WIDTH, top), + black, LAYER_GUI+1); + context.draw_filled_rect(Vector(right, 0), + Vector(SCREEN_WIDTH, SCREEN_HEIGHT), + black, LAYER_GUI+1); + context.draw_filled_rect(Vector(0, bottom), + Vector(SCREEN_WIDTH, SCREEN_HEIGHT), + black, LAYER_GUI+1); +} + +bool +ShrinkFade::done() +{ + return accum_time >= fade_time; +} diff --git a/src/shrinkfade.hpp b/src/shrinkfade.hpp new file mode 100644 index 000000000..bbea97fdc --- /dev/null +++ b/src/shrinkfade.hpp @@ -0,0 +1,47 @@ +// $Id: screen.hpp 3327 2006-04-13 15:02:40Z ravu_al_hemio $ +// +// SuperTux +// Copyright (C) 2006 Matthias Braun +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +#ifndef __SHRINKFADE_HPP__ +#define __SHRINKFADE_HPP__ + +#include "screen_fade.hpp" +#include "math/vector.hpp" + +/** + * Shrinks a rectangle screen towards a specific position + */ +class ShrinkFade : public ScreenFade +{ +public: + ShrinkFade(const Vector& point, float fade_time); + virtual ~ShrinkFade(); + + virtual void update(float elapsed_time); + virtual void draw(DrawingContext& context); + + virtual bool done(); + +private: + Vector dest; + float fade_time; + float accum_time; + float speedleft, speedright, speedtop, speedbottom; +}; + +#endif + diff --git a/src/textscroller.cpp b/src/textscroller.cpp index dcafdc1c7..64ac04587 100644 --- a/src/textscroller.cpp +++ b/src/textscroller.cpp @@ -28,12 +28,12 @@ #include "video/font.hpp" #include "video/drawing_context.hpp" #include "video/surface.hpp" -#include "video/screen.hpp" #include "gui/menu.hpp" #include "lisp/parser.hpp" #include "lisp/lisp.hpp" #include "audio/sound_manager.hpp" #include "main.hpp" +#include "fadeout.hpp" #include "control/joystickkeyboardcontroller.hpp" static const float DEFAULT_SPEED = 20; @@ -136,8 +136,7 @@ TextScroller::update(float elapsed_time) || main_controller->pressed(Controller::MENU_SELECT)) scroll += SCROLL; if(main_controller->pressed(Controller::PAUSE_MENU)) { - fadeout(500); - main_loop->exit_screen(); + main_loop->exit_screen(new FadeOut(0.5)); } scroll += speed * elapsed_time; @@ -203,8 +202,7 @@ TextScroller::draw(DrawingContext& context) } if(y < 0) { - fadeout(500); - main_loop->exit_screen(); + main_loop->exit_screen(new FadeOut(0.5)); } } diff --git a/src/tile.cpp b/src/tile.cpp index 252cd6ea4..e31e5dece 100644 --- a/src/tile.cpp +++ b/src/tile.cpp @@ -35,12 +35,12 @@ Tile::Tile() - : id(0), editor_image(0), attributes(0), data(0), anim_fps(1) + : id(0), attributes(0), data(0), anim_fps(1) { } Tile::Tile(unsigned int id_, Uint32 attributes_, const ImageSpec& imagespec) - : id(id_), editor_image(0), attributes(attributes_), data(0), anim_fps(1) + : id(id_), attributes(attributes_), data(0), anim_fps(1) { imagespecs.push_back(imagespec); } @@ -51,7 +51,6 @@ Tile::~Tile() ++i) { delete *i; } - delete editor_image; } void @@ -102,7 +101,6 @@ Tile::parse(const lisp::Lisp& reader) const lisp::Lisp* images = reader.get_lisp("images"); if(images) parse_images(*images); - reader.get("editor-images", editor_imagefile); } void @@ -156,20 +154,6 @@ Tile::load_images(const std::string& tilesetpath) } images.push_back(surface); } - if(editor_imagefile != "") { - editor_image = new Surface(tilesetpath + editor_imagefile); - } -} - -Surface* -Tile::get_editor_image() const -{ - if(editor_image) - return editor_image; - if(images.size() > 0) - return images[0]; - - return 0; } void diff --git a/src/tile.hpp b/src/tile.hpp index 07b57d997..68f5308ad 100644 --- a/src/tile.hpp +++ b/src/tile.hpp @@ -99,9 +99,6 @@ private: std::vector imagespecs; std::vector images; - std::string editor_imagefile; - Surface* editor_image; - /** tile attributes */ uint32_t attributes; @@ -116,8 +113,6 @@ public: /** Draw a tile on the screen */ void draw(DrawingContext& context, const Vector& pos, int layer) const; - Surface* get_editor_image() const; - unsigned int getID() const { return id; } diff --git a/src/title.cpp b/src/title.cpp index da22b4936..edb44c6c3 100644 --- a/src/title.cpp +++ b/src/title.cpp @@ -35,7 +35,6 @@ #include "title.hpp" #include "mainloop.hpp" -#include "video/screen.hpp" #include "video/drawing_context.hpp" #include "video/surface.hpp" #include "audio/sound_manager.hpp" @@ -56,6 +55,7 @@ #include "resources.hpp" #include "gettext.hpp" #include "textscroller.hpp" +#include "fadeout.hpp" #include "file_system.hpp" #include "control/joystickkeyboardcontroller.hpp" #include "control/codecontroller.hpp" @@ -350,11 +350,11 @@ TitleScreen::update(float elapsed_time) Menu::push_current(contrib_menu.get()); break; case MNID_CREDITS: - fadeout(500); - main_loop->push_screen(new TextScroller("credits.txt")); + main_loop->push_screen(new TextScroller("credits.txt"), + new FadeOut(0.5)); break; case MNID_QUITMAINMENU: - main_loop->quit(); + main_loop->quit(new FadeOut(0.25)); break; } } else if(menu == load_game_menu.get()) { @@ -440,8 +440,6 @@ TitleScreen::process_load_game_menu() stream << "save/" << worlddirname << "_" << slot << ".stsg"; std::string slotfile = stream.str(); - fadeout(256); - try { current_world->set_savegame_filename(slotfile); current_world->run(); diff --git a/src/trigger/sequence_trigger.cpp b/src/trigger/sequence_trigger.cpp index 78e50d20a..0f66a838c 100644 --- a/src/trigger/sequence_trigger.cpp +++ b/src/trigger/sequence_trigger.cpp @@ -35,6 +35,7 @@ SequenceTrigger::SequenceTrigger(const lisp::Lisp& reader) reader.get("height", h); bbox.set_size(w, h); reader.get("sequence", sequence_name); + triggerevent = EVENT_TOUCH; } SequenceTrigger::SequenceTrigger(const Vector& pos, const std::string& sequence) diff --git a/src/video/screen.cpp b/src/video/screen.cpp deleted file mode 100644 index 59fc8e61f..000000000 --- a/src/video/screen.cpp +++ /dev/null @@ -1,116 +0,0 @@ -// $Id$ -// -// SuperTux -// Copyright (C) 2006 Matthias Braun -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -#include - -#include -#include -#include -#include -#include -#include - -#include - -#include - -#include "gameconfig.hpp" -#include "screen.hpp" -#include "main.hpp" -#include "video/drawing_context.hpp" -#include "audio/sound_manager.hpp" -#include "math/vector.hpp" - -static const float LOOP_DELAY = 20.0; - -void fillrect(float x, float y, float w, float h, const Color& col) -{ - if(w < 0) { - x += w; - w = -w; - } - if(h < 0) { - y += h; - h = -h; - } - - glColor4f(col.red, col.green, col.blue, col.alpha); - - glDisable(GL_TEXTURE_2D); - glBegin(GL_POLYGON); - glVertex2f(x, y); - glVertex2f(x+w, y); - glVertex2f(x+w, y+h); - glVertex2f(x, y+h); - glEnd(); - glEnable(GL_TEXTURE_2D); - - glColor4f(0, 0, 0, 1); -} - -void fadeout(float fade_time) -{ - float alpha_inc = LOOP_DELAY / fade_time; - Color c(0, 0, 0, alpha_inc); - float alpha = 1.0; - - while(alpha >= 0) { - alpha -= alpha_inc; - fillrect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, c); - // left side - - SDL_GL_SwapBuffers(); - sound_manager->update(); - - SDL_Delay(int(LOOP_DELAY)); - alpha -= alpha_inc; - } - - fillrect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, Color()); -} - -void shrink_fade(const Vector& point, float fade_time) -{ - float left_inc = point.x / (fade_time / LOOP_DELAY); - float right_inc = (SCREEN_WIDTH - point.x) / (fade_time / LOOP_DELAY); - float up_inc = point.y / (fade_time / LOOP_DELAY); - float down_inc = (SCREEN_HEIGHT - point.y) / (fade_time / LOOP_DELAY); - - float left_cor = 0, right_cor = 0, up_cor = 0, down_cor = 0; - Color c; - - while(left_cor < point.x && right_cor < SCREEN_WIDTH - point.x && - up_cor < point.y && down_cor < SCREEN_HEIGHT - point.y) { - left_cor += left_inc; - right_cor += right_inc; - up_cor += up_inc; - down_cor += down_inc; - - fillrect(0, 0, left_cor, SCREEN_HEIGHT, c); // left side - fillrect(SCREEN_WIDTH - right_cor, 0, right_cor, SCREEN_HEIGHT, c); // right side - fillrect(0, 0, SCREEN_WIDTH, up_cor, c); // up side - fillrect(0, SCREEN_HEIGHT - down_cor, SCREEN_WIDTH, down_cor+1, c); // down side - - SDL_GL_SwapBuffers(); - - sound_manager->update(); - SDL_Delay(int(LOOP_DELAY)); - } -} - diff --git a/src/video/surface.cpp b/src/video/surface.cpp index 145a1abf6..7414564bc 100644 --- a/src/video/surface.cpp +++ b/src/video/surface.cpp @@ -32,7 +32,6 @@ #include "gameconfig.hpp" #include "physfs/physfs_sdl.hpp" #include "video/surface.hpp" -#include "video/screen.hpp" #include "image_texture.hpp" #include "texture_manager.hpp" diff --git a/src/worldmap/worldmap.cpp b/src/worldmap/worldmap.cpp index 60158b856..d834fac1a 100644 --- a/src/worldmap/worldmap.cpp +++ b/src/worldmap/worldmap.cpp @@ -33,8 +33,8 @@ #include "gettext.hpp" #include "log.hpp" #include "mainloop.hpp" +#include "shrinkfade.hpp" #include "video/surface.hpp" -#include "video/screen.hpp" #include "video/drawing_context.hpp" #include "sprite/sprite_manager.hpp" #include "audio/sound_manager.hpp" @@ -502,13 +502,12 @@ WorldMap::update(float delta) } if (level->pos == tux->get_tile_pos()) { - // do a shriking fade to the level - shrink_fade(Vector((level->pos.x*32 + 16 + camera_offset.x), - (level->pos.y*32 + 16 + camera_offset.y)), 500); - try { - main_loop->push_screen(new GameSession( - levels_path + level->name, &level->statistics)); + Vector shrinkpos = Vector(level->pos.x*32 + 16 - camera_offset.x, + level->pos.y*32 + 16 - camera_offset.y); + std::string levelfile = levels_path + level->name; + main_loop->push_screen(new GameSession(levelfile, &level->statistics), + new ShrinkFade(shrinkpos, 0.5)); } catch(std::exception& e) { log_fatal << "Couldn't load level: " << e.what() << std::endl; } diff --git a/src/worldmap/worldmap.hpp b/src/worldmap/worldmap.hpp index e8f651aed..2be401baa 100644 --- a/src/worldmap/worldmap.hpp +++ b/src/worldmap/worldmap.hpp @@ -24,7 +24,6 @@ #include #include "math/vector.hpp" -#include "video/screen.hpp" #include "lisp/lisp.hpp" #include "control/controller.hpp" #include "statistics.hpp" -- 2.11.0