pingus-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Pingus-CVS] r2924 - in branches/pingus_sdl: . src/components src/worldm


From: grumbel at BerliOS
Subject: [Pingus-CVS] r2924 - in branches/pingus_sdl: . src/components src/worldmap
Date: Wed, 15 Aug 2007 15:31:03 +0200

Author: grumbel
Date: 2007-08-15 15:31:01 +0200 (Wed, 15 Aug 2007)
New Revision: 2924

Modified:
   branches/pingus_sdl/TODO
   branches/pingus_sdl/src/components/playfield.cpp
   branches/pingus_sdl/src/components/playfield.hpp
   branches/pingus_sdl/src/worldmap/manager.cpp
   branches/pingus_sdl/src/worldmap/manager.hpp
   branches/pingus_sdl/src/worldmap/worldmap.cpp
   branches/pingus_sdl/src/worldmap/worldmap.hpp
Log:
- fixed issue with worldmap not being centered on larger resolution

Modified: branches/pingus_sdl/TODO
===================================================================
--- branches/pingus_sdl/TODO    2007-08-15 12:56:01 UTC (rev 2923)
+++ branches/pingus_sdl/TODO    2007-08-15 13:31:01 UTC (rev 2924)
@@ -48,12 +48,12 @@
 Important:
 ==========
 
+- grep for all the FIXME's and '#if 0' and find those that might be important
+
 - update INSTALL.* file
 
 - remove all the remaining unneeded debuging std::cout's
 
-- separate gfx/colmap surfaces aren't used
-
 - Latin1 clean (also Latin-2 and Latin-9, see:
   http://kapsa.cz/~tomasb/pingus/intl-patch.tgz)
 
@@ -62,9 +62,10 @@
 Nice to Have:
 =============
 
-- worldmap looks somewhat ugly on larger resolutions, should either be
-  scaled or simply be centered like the levels
+- worldmap scrolling seems to be broken when using small resolutions (-g 
400x300)
 
+- separate gfx/colmap surfaces aren't used
+
 - CollisionMask can't handle RGBA images and likely shouldn't (due to
   them being animated and stuff like that), we however don't have
   seperate colmask for those images

Modified: branches/pingus_sdl/src/components/playfield.cpp
===================================================================
--- branches/pingus_sdl/src/components/playfield.cpp    2007-08-15 12:56:01 UTC 
(rev 2923)
+++ branches/pingus_sdl/src/components/playfield.cpp    2007-08-15 13:31:01 UTC 
(rev 2924)
@@ -259,15 +259,6 @@
 }
 
 void
-Playfield::generate_clipping_rects(int x1, int y1, int x2, int y2)
-{
-  clipping_rectangles.push_back(Rect(0, 0, Display::get_width() - 1, y1));
-  clipping_rectangles.push_back(Rect(0, y1, x1, y2+1));
-  clipping_rectangles.push_back(Rect(x2+1, y1, Display::get_width() - 1, 
y2+1));
-  clipping_rectangles.push_back(Rect(0, y2+1, Display::get_width() - 1, 
Display::get_height() - 1));
-}
-
-void
 Playfield::scroll (int x, int y)
 {
   state.set_pos(state.get_pos() + Vector2f((float)x, (float)y));

Modified: branches/pingus_sdl/src/components/playfield.hpp
===================================================================
--- branches/pingus_sdl/src/components/playfield.hpp    2007-08-15 12:56:01 UTC 
(rev 2923)
+++ branches/pingus_sdl/src/components/playfield.hpp    2007-08-15 13:31:01 UTC 
(rev 2924)
@@ -88,8 +88,6 @@
   void do_scrolling();
   void disable_scroll_mode();
 
-  void generate_clipping_rects(int, int, int, int);
-
   /// Members used to communicate between different screen objs
   void set_server(Server*);
 

Modified: branches/pingus_sdl/src/worldmap/manager.cpp
===================================================================
--- branches/pingus_sdl/src/worldmap/manager.cpp        2007-08-15 12:56:01 UTC 
(rev 2923)
+++ branches/pingus_sdl/src/worldmap/manager.cpp        2007-08-15 13:31:01 UTC 
(rev 2924)
@@ -27,6 +27,8 @@
 #include "../res_descriptor.hpp"
 #include "../sound/sound.hpp"
 #include "../stat_manager.hpp"
+#include "../display/scene_context.hpp"
+#include "../math.hpp"
 #include "worldmap.hpp"
 #include "worldmap_story.hpp"
 #include "pingus.hpp"
@@ -295,40 +297,103 @@
     }
 }
 
+WorldMapComponent::WorldMapComponent()
+{
+  scene_context = new SceneContext();
+}
+
+WorldMapComponent::~WorldMapComponent()
+{
+  delete scene_context;
+}
+
 void
-WorldMapManager::WorldMapComponent::draw (DrawingContext& gc)
+WorldMapComponent::draw (DrawingContext& gc)
 {
-  WorldMapManager::instance()->worldmap->draw(gc);
+  WorldMap* worldmap = WorldMapManager::instance()->worldmap;
+
+  Rect cliprect(Vector2i(Math::max((Display::get_width()  - 
worldmap->get_width())/2,  0),
+                         Math::max((Display::get_height() - 
worldmap->get_height())/2, 0)), 
+                Size(Math::min(Display::get_width(),  worldmap->get_width()),
+                 Math::min(Display::get_height(), worldmap->get_height())));
+
+  scene_context->clear();
+  scene_context->push_modelview();
+  scene_context->translate(cliprect.left, cliprect.top);
+
+  scene_context->set_cliprect(cliprect);
+
+  //scene_context->color().draw_fillrect(-100, -100, 2000, 2000, 
Color(255,0,0,0), -10000);
+  worldmap->draw(scene_context->color());
+
+  gc.draw(new SceneContextDrawingRequest(scene_context, Vector3f(0,0,-1000)));
+
+  scene_context->pop_modelview();
+
+  // Draw border
+  if (cliprect != Rect(Vector2i(0,0), Size(Display::get_width(), 
Display::get_height())))
+  {
+    Color border_color(50, 65, 75);
+    // top
+    gc.draw_fillrect(0, 0, (float)Display::get_width(), (float)cliprect.top,
+                     border_color);
+    // bottom
+    gc.draw_fillrect(0, (float)cliprect.bottom, (float)Display::get_width(), 
(float)Display::get_height(),
+                 border_color);
+    // left
+    gc.draw_fillrect(0, (float)cliprect.top, (float)cliprect.left, 
(float)cliprect.bottom,
+                 border_color);
+    // right
+    gc.draw_fillrect((float)cliprect.right, (float)cliprect.top, 
(float)Display::get_width(), (float)cliprect.bottom,
+                 border_color);
+  }
 }
 
 void
-WorldMapManager::WorldMapComponent::update (float delta)
+WorldMapComponent::update (float delta)
 {
   WorldMapManager::instance()->worldmap->update(delta);
   UNUSED_ARG(delta);
 }
 
 void
-WorldMapManager::WorldMapComponent::on_primary_button_press (int x, int y)
+WorldMapComponent::on_primary_button_press (int x, int y)
 {
-  //std::cout << "Buton press" << std::endl;
-  /** Fixme: insert Co. translation here */
-  WorldMapManager::instance ()->worldmap->on_primary_button_press (x, y);
+  WorldMap* worldmap = WorldMapManager::instance ()->worldmap;
+  Rect cliprect(Vector2i(Math::max((Display::get_width()  - 
worldmap->get_width())/2,  0),
+                         Math::max((Display::get_height() - 
worldmap->get_height())/2, 0)), 
+                Size(Math::min(Display::get_width(),  worldmap->get_width()),
+                 Math::min(Display::get_height(), worldmap->get_height())));
+
+  WorldMapManager::instance ()->worldmap->on_primary_button_press(x - 
cliprect.left,
+                                                                  y - 
cliprect.top);
 }
 
 
 void
-WorldMapManager::WorldMapComponent::on_pointer_move (int x, int y)
+WorldMapComponent::on_pointer_move (int x, int y)
 {
-  WorldMapManager::instance ()->worldmap->on_pointer_move (x, y);
+  WorldMap* worldmap = WorldMapManager::instance ()->worldmap;
+  Rect cliprect(Vector2i(Math::max((Display::get_width()  - 
worldmap->get_width())/2,  0),
+                         Math::max((Display::get_height() - 
worldmap->get_height())/2, 0)), 
+                Size(Math::min(Display::get_width(),  worldmap->get_width()),
+                 Math::min(Display::get_height(), worldmap->get_height())));
+
+  WorldMapManager::instance ()->worldmap->on_pointer_move(x - cliprect.left,
+                                                          y - cliprect.top);
 }
 
 void
-WorldMapManager::WorldMapComponent::on_secondary_button_press (int x, int y)
+WorldMapComponent::on_secondary_button_press (int x, int y)
 {
-  //std::cout << "Buton press" << std::endl;
-  /** Fixme: insert Co. translation here */
-  WorldMapManager::instance ()->worldmap->on_secondary_button_press (x, y);
+  WorldMap* worldmap = WorldMapManager::instance ()->worldmap;
+  Rect cliprect(Vector2i(Math::max((Display::get_width()  - 
worldmap->get_width())/2,  0),
+                         Math::max((Display::get_height() - 
worldmap->get_height())/2, 0)), 
+                Size(Math::min(Display::get_width(),  worldmap->get_width()),
+                 Math::min(Display::get_height(), worldmap->get_height())));
+
+  WorldMapManager::instance ()->worldmap->on_secondary_button_press(x - 
cliprect.left,
+                                                                    y - 
cliprect.top);
 }
 
 void

Modified: branches/pingus_sdl/src/worldmap/manager.hpp
===================================================================
--- branches/pingus_sdl/src/worldmap/manager.hpp        2007-08-15 12:56:01 UTC 
(rev 2923)
+++ branches/pingus_sdl/src/worldmap/manager.hpp        2007-08-15 13:31:01 UTC 
(rev 2924)
@@ -1,7 +1,7 @@
 //  $Id: manager.hxx,v 1.24 2003/10/18 23:17:28 grumbel Exp $
 //
 //  Pingus - A free Lemmings clone
-//  Copyright (C) 2000 Ingo Ruhnke <address@hidden>
+//  Copyright (C) 2000,2007 Ingo Ruhnke <address@hidden>
 //
 //  This program is free software; you can redistribute it and/or
 //  modify it under the terms of the GNU General Public License
@@ -24,38 +24,42 @@
 #include "../gui/gui_manager.hpp"
 #include "../gui/gui_screen.hpp"
 
+class SceneContext;
+
 namespace WorldMapNS {
 
 typedef int NodeId;
 class WorldMap;
 
-/** The WorldMapManager manages the worldmaps and the translation
-    between two worldmaps, it also holds the GUI elements that are
-    accessible in the WorldMap Screen */
-class WorldMapManager : public GUIScreen
+class WorldMapComponent : public GUI::Component
 {
-  /** FIXME: Workaround class to let the worldmap play with well
-      FIXME: with the Screen, should be deleted at a later point. */
-  class WorldMapComponent : public GUI::Component
-  {
-  public:
-    WorldMapComponent () { }
+private:
+  SceneContext* scene_context;
 
-    void on_primary_button_press (int x, int y);
-    void on_secondary_button_press (int x, int y);
-    void on_pointer_move(int x, int y);
+public:
+  WorldMapComponent();
+  ~WorldMapComponent();
 
-    void draw (DrawingContext& gc);
-    void update (float delta);
+  void on_primary_button_press (int x, int y);
+  void on_secondary_button_press (int x, int y);
+  void on_pointer_move(int x, int y);
 
-    bool is_at (int, int) { return true; }
+  void draw (DrawingContext& gc);
+  void update (float delta);
 
-  private:
-    WorldMapComponent (const WorldMapComponent&);
-    WorldMapComponent& operator= (const WorldMapComponent&);
+  bool is_at (int, int) { return true; }
 
-  };
+private:
+  WorldMapComponent (const WorldMapComponent&);
+  WorldMapComponent& operator= (const WorldMapComponent&);
 
+};
+
+/** The WorldMapManager manages the worldmaps and the translation
+    between two worldmaps, it also holds the GUI elements that are
+    accessible in the WorldMap Screen */
+class WorldMapManager : public GUIScreen
+{
   WorldMapComponent* worldmap_component;
 
   friend class WorldMapComponent;
@@ -96,14 +100,15 @@
 
   /** Change the current map to the given map
 
-  @param filename the filename of the new map, filename must be
-  @param filename relative to the worldmap directory
-  @param filename Example: "volcano.pingus" */
+      @param filename the filename of the new map, filename must be
+      @param filename relative to the worldmap directory
+      @param filename Example: "volcano.pingus" */
   void change_map (const std::string& filename, NodeId node);
 
   /** Singleton access function */
   static WorldMapManager* instance ();
   static void deinit();
+
 private:
   /** Startup Hook of the Screen */
   void on_startup ();

Modified: branches/pingus_sdl/src/worldmap/worldmap.cpp
===================================================================
--- branches/pingus_sdl/src/worldmap/worldmap.cpp       2007-08-15 12:56:01 UTC 
(rev 2923)
+++ branches/pingus_sdl/src/worldmap/worldmap.cpp       2007-08-15 13:31:01 UTC 
(rev 2924)
@@ -88,7 +88,7 @@
       parse_objects(reader.read_section("objects"));
       parse_properties(reader.read_section("head"));
       intro_story = new WorldMapStory(reader.read_section("intro_story"));
-      end_story = new WorldMapStory(reader.read_section("end_story"));
+      end_story   = new WorldMapStory(reader.read_section("end_story"));
     }
   else
     {
@@ -149,7 +149,7 @@
 }
 
 void
-WorldMap::draw (DrawingContext& gc)
+WorldMap::draw(DrawingContext& gc)
 {
   Vector3f pingu_pos = pingus->get_pos();
   float min, max;
@@ -178,26 +178,26 @@
     }
   pingu_pos.y = Math::clamp(min, pingu_pos.x, max);
 
-  DrawingContext* display_gc = new DrawingContext();
-
   gc_state.set_pos(Vector2f(pingu_pos.x, pingu_pos.y));
        
-  gc_state.push(*display_gc);
+  gc_state.push(gc);
   
-  // Blank out the screen in case the screen resolution is larger than
-  // the worldmap picture.
-  // FIXME:  Should probably scale everything to match the resolution instead.
-  gc.draw_fillrect(0, 0, (float)Display::get_width(), 
(float)Display::get_height(),
-                   Color(0,0,0), -15000);
-               
+  
   for (DrawableLst::iterator i = drawables.begin (); i != drawables.end (); 
++i)
-    {
-      (*i)->draw(*display_gc);
-    }
+      (*i)->draw(gc);
 
+  Vector3f mpos = gc.screen_to_world(Vector3f((float)mouse_x, (float)mouse_y));
+  Dot* dot = path_graph->get_dot(mpos.x, mpos.y);
+  if (dot)
+    dot->draw_hover(gc);
+  
+  gc_state.pop(gc);
+
+  // Draw the levelname
+  // FIXME: Should be moved to a higher level
   gc.draw(levelname_bg,
           Vector3f(gc.get_width()/2 - levelname_bg.get_width()/2,
-                 gc.get_height() - levelname_bg.get_height()));
+                   gc.get_height() - levelname_bg.get_height()));
 
   if (pingus->get_node() != NoNode)
     {
@@ -205,37 +205,25 @@
 
       if (leveldot)
         {
-          gc.print_center(Fonts::chalk_small,
-                          display_gc->get_width ()/2,
-                          display_gc->get_height() - 20,
+          gc.print_center(Fonts::chalk_small, gc.get_width()/2, 
gc.get_height() - 20,
                           _(leveldot->get_plf().get_levelname()));
           
         }
       else
         {
           gc.print_center(Fonts::chalk_small,
-                          display_gc->get_width ()/2,
-                          display_gc->get_height() - 20,
+                          gc.get_width()/2,
+                          gc.get_height() - 20,
                           "---");
         }
     }
   else
     {
       gc.print_center(Fonts::chalk_small,
-                      display_gc->get_width ()/2,
-                      display_gc->get_height() - 20,
+                      gc.get_width()/2,
+                      gc.get_height() - 20,
                       _("...walking..."));
     }
-
-  Vector3f mpos = display_gc->screen_to_world(Vector3f((float)mouse_x, 
(float)mouse_y));
-  Dot* dot = path_graph->get_dot(mpos.x, mpos.y);
-  if (dot)
-    {
-      dot->draw_hover(*display_gc);
-    }
-  gc.draw(display_gc);
-
-  gc_state.pop(*display_gc);
 }
 
 void

Modified: branches/pingus_sdl/src/worldmap/worldmap.hpp
===================================================================
--- branches/pingus_sdl/src/worldmap/worldmap.hpp       2007-08-15 12:56:01 UTC 
(rev 2923)
+++ branches/pingus_sdl/src/worldmap/worldmap.hpp       2007-08-15 13:31:01 UTC 
(rev 2924)
@@ -52,8 +52,8 @@
   /** name of the file to parse */
   std::string filename;
 
-       WorldMapStory *intro_story;
-       WorldMapStory *end_story;
+  WorldMapStory *intro_story;
+  WorldMapStory *end_story;
 
   typedef std::vector<Drawable*>   ObjectLst;
   typedef std::vector<Drawable*> DrawableLst;
@@ -61,15 +61,15 @@
   int width;
   int height;
 
-       std::string name;
-       std::string short_name;
-       std::string author;
-       std::string email;
-       std::string music;
+  std::string name;
+  std::string short_name;
+  std::string author;
+  std::string email;
+  std::string music;
 
-       // Beginning and ending nodes are configurable by the XML file.
-       NodeId default_node;
-       NodeId final_node;
+  // Beginning and ending nodes are configurable by the XML file.
+  NodeId default_node;
+  NodeId final_node;
 
   Pingus* pingus;
 
@@ -89,21 +89,22 @@
 
   int mouse_x;
   int mouse_y;
+
 public:
   /** Load the given*/
   WorldMap(const std::string& filename);
   ~WorldMap();
 
   Pingus* get_pingus() { return pingus; }
-       WorldMapStory* get_intro_story() const { return intro_story; }
-       WorldMapStory* get_end_story() const { return end_story; }
+  WorldMapStory* get_intro_story() const { return intro_story; }
+  WorldMapStory* get_end_story() const { return end_story; }
 
   void on_startup();
 
-       std::string get_filename() const { return filename; }
-       std::string get_shortname() const { return short_name; }
+  std::string get_filename() const { return filename; }
+  std::string get_shortname() const { return short_name; }
 
-       bool is_final_map();
+  bool is_final_map();
 
   void draw (DrawingContext& gc);
   void update (float delta);
@@ -126,6 +127,9 @@
   void on_secondary_button_press(int x, int y);
   void on_pointer_move(int x, int y);
 
+  int get_width()  const { return width; }
+  int get_height() const { return height; }
+
 private:
   /** Parses a WorldMap XML file */
   void parse_file(FileReader reader);
@@ -145,9 +149,9 @@
   /** Unlock nodes according to the finished ones */
   void update_locked_nodes();
 
-       /** Sets the starting level on the worldmap.  Either take it from the 
StatManager
-                       or use the "default-node" option from the XML file */
-       void set_starting_node();
+  /** Sets the starting level on the worldmap.  Either take it from the 
StatManager
+      or use the "default-node" option from the XML file */
+  void set_starting_node();
 };
 
 } // namespace WorldMapNS





reply via email to

[Prev in Thread] Current Thread [Next in Thread]