2 more evil mainloops are gone
authorMatthias Braun <matze@braunis.de>
Wed, 19 Apr 2006 09:35:49 +0000 (09:35 +0000)
committerMatthias Braun <matze@braunis.de>
Wed, 19 Apr 2006 09:35:49 +0000 (09:35 +0000)
SVN-Revision: 3365

28 files changed:
data/levels/world1/world.nut
src/audio/sound_manager.hpp
src/fadeout.cpp [new file with mode: 0644]
src/fadeout.hpp [new file with mode: 0644]
src/game_session.cpp
src/gui/menu.cpp
src/level.cpp
src/log.hpp
src/mainloop.cpp
src/mainloop.hpp
src/object/fireworks.cpp
src/object/player.cpp
src/screen_fade.hpp [new file with mode: 0644]
src/scripting/functions.cpp
src/scripting/functions.hpp
src/scripting/wrapper.cpp
src/shrinkfade.cpp [new file with mode: 0644]
src/shrinkfade.hpp [new file with mode: 0644]
src/textscroller.cpp
src/tile.cpp
src/tile.hpp
src/title.cpp
src/trigger/sequence_trigger.cpp
src/video/screen.cpp [deleted file]
src/video/screen.hpp [deleted file]
src/video/surface.cpp
src/worldmap/worldmap.cpp
src/worldmap/worldmap.hpp

index 41db5c9..278e7ac 100644 (file)
@@ -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();
index b2c5cc9..e93113b 100644 (file)
@@ -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 <AL/al.h>
 #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 (file)
index 0000000..f7b7752
--- /dev/null
@@ -0,0 +1,57 @@
+//  $Id: screen.hpp 3327 2006-04-13 15:02:40Z ravu_al_hemio $
+//
+//  SuperTux
+//  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
+//
+//  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 <config.h>
+
+#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 (file)
index 0000000..4afcdfa
--- /dev/null
@@ -0,0 +1,47 @@
+//  $Id: screen.hpp 3327 2006-04-13 15:02:40Z ravu_al_hemio $
+//
+//  SuperTux
+//  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
+//
+//  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
+
index 0e817de..2f66372 100644 (file)
@@ -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);
 
index 0045fbc..7374ff7 100644 (file)
@@ -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"
index 1ba57a4..abe0109 100644 (file)
@@ -29,7 +29,6 @@
 #include <memory>
 #include <stdexcept>
 
-#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()
index eb14069..b26960a 100644 (file)
 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;
 }
 
index 7e5a01b..98c8efc 100644 (file)
@@ -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<Screen*>::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();
index dfb2f9e..5e51d2d 100644 (file)
@@ -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<Screen> next_screen;
   std::auto_ptr<Screen> current_screen;
   std::auto_ptr<Console> console;
+  std::auto_ptr<ScreenFade> screen_fade;
   std::vector<Screen*> screen_stack;
 };
 
index 68ac1e0..acfa881 100644 (file)
@@ -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<float>(rand() % 255) / 255.0;
-        float green = static_cast<float>(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));
index 369ca83..1a60e53 100644 (file)
@@ -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/screen_fade.hpp b/src/screen_fade.hpp
new file mode 100644 (file)
index 0000000..bd78e59
--- /dev/null
@@ -0,0 +1,39 @@
+//  $Id: screen.hpp 3327 2006-04-13 15:02:40Z ravu_al_hemio $
+//
+//  SuperTux
+//  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
+//
+//  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 __SCREENFADE_HPP__
+#define __SCREENFADE_HPP__
+
+#include "screen.hpp"
+
+/**
+ * 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
+
index 9d45154..f1a3715 100644 (file)
@@ -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();
 }
 
index 4793cdb..9222c0e 100644 (file)
@@ -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)
  */
index 1068071..4f2592e 100644 (file)
@@ -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 (file)
index 0000000..0b99900
--- /dev/null
@@ -0,0 +1,73 @@
+//  $Id: screen.hpp 3327 2006-04-13 15:02:40Z ravu_al_hemio $
+//
+//  SuperTux
+//  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
+//
+//  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 <config.h>
+
+#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 (file)
index 0000000..bbea97f
--- /dev/null
@@ -0,0 +1,47 @@
+//  $Id: screen.hpp 3327 2006-04-13 15:02:40Z ravu_al_hemio $
+//
+//  SuperTux
+//  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
+//
+//  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
+
index dcafdc1..64ac045 100644 (file)
 #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));
   }
 }
 
index 252cd6e..e31e5de 100644 (file)
 
 
 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
index 07b57d9..68f5308 100644 (file)
@@ -99,9 +99,6 @@ private:
   std::vector<ImageSpec> imagespecs;
   std::vector<Surface*> 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; }
 
index da22b49..edb44c6 100644 (file)
@@ -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();
index 78e50d2..0f66a83 100644 (file)
@@ -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 (file)
index 59fc8e6..0000000
+++ /dev/null
@@ -1,116 +0,0 @@
-//  $Id$
-//
-//  SuperTux
-//  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
-//
-//  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 <config.h>
-
-#include <iostream>
-#include <cstdio>
-#include <cstdlib>
-#include <cstring>
-#include <cerrno>
-#include <assert.h>
-
-#include <unistd.h>
-
-#include <SDL.h>
-
-#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/screen.hpp b/src/video/screen.hpp
deleted file mode 100644 (file)
index ab21a55..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-//  $Id$
-//
-//  SuperTux
-//  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
-//
-//  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 SUPERTUX_SCREEN_H
-#define SUPERTUX_SCREEN_H
-
-#include <SDL.h>
-#include <GL/gl.h>
-#include <iostream>
-
-#include <vector>
-#include "math/vector.hpp"
-
-void fadeout(float fade_time);
-void shrink_fade(const Vector& point, float fade_time);
-
-#endif
index 145a1ab..7414564 100644 (file)
@@ -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"
 
index 60158b8..d834fac 100644 (file)
@@ -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;
         }
index e8f651a..2be401b 100644 (file)
@@ -24,7 +24,6 @@
 #include <string>
 
 #include "math/vector.hpp"
-#include "video/screen.hpp"
 #include "lisp/lisp.hpp"
 #include "control/controller.hpp"
 #include "statistics.hpp"