pingus-cvs
[Top][All Lists]
Advanced

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

[Pingus-CVS] r3912 - in trunk/pingus/src: . components display editor pa


From: grumbel at BerliOS
Subject: [Pingus-CVS] r3912 - in trunk/pingus/src: . components display editor particles worldmap worldobjs
Date: Sun, 27 Jul 2008 16:02:09 +0200

Author: grumbel
Date: 2008-07-27 16:02:05 +0200 (Sun, 27 Jul 2008)
New Revision: 3912

Modified:
   trunk/pingus/src/components/playfield.cpp
   trunk/pingus/src/components/playfield.hpp
   trunk/pingus/src/display/drawing_context.cpp
   trunk/pingus/src/display/drawing_context.hpp
   trunk/pingus/src/editor/editor_screen.cpp
   trunk/pingus/src/editor/viewport.cpp
   trunk/pingus/src/editor/viewport.hpp
   trunk/pingus/src/font.cpp
   trunk/pingus/src/graphic_context_state.cpp
   trunk/pingus/src/graphic_context_state.hpp
   trunk/pingus/src/particles/rain_particle_holder.cpp
   trunk/pingus/src/particles/rain_particle_holder.hpp
   trunk/pingus/src/sprite.cpp
   trunk/pingus/src/sprite.hpp
   trunk/pingus/src/sprite_impl.cpp
   trunk/pingus/src/sprite_impl.hpp
   trunk/pingus/src/worldmap/level_dot.cpp
   trunk/pingus/src/worldmap/worldmap.cpp
   trunk/pingus/src/worldobjs/surface_background.cpp
Log:
Replaced some float with int

Modified: trunk/pingus/src/components/playfield.cpp
===================================================================
--- trunk/pingus/src/components/playfield.cpp   2008-07-27 04:00:29 UTC (rev 
3911)
+++ trunk/pingus/src/components/playfield.cpp   2008-07-27 14:02:05 UTC (rev 
3912)
@@ -131,8 +131,8 @@
         }
       else
         { 
-          state.set_pos(Vector2f(state.get_pos().x - float(scroll_center.x - 
mouse_pos.x) * 0.2f,
-                                 state.get_pos().y - float(scroll_center.y - 
mouse_pos.y) * 0.2f));
+          state.set_pos(Vector2i(static_cast<int>(state.get_pos().x - 
(scroll_center.x - mouse_pos.x) * 0.2f),
+                                 static_cast<int>(state.get_pos().y - 
(scroll_center.y - mouse_pos.y) * 0.2f)));
         }
     }
 
@@ -251,13 +251,13 @@
 void
 Playfield::set_viewpoint(int x, int y)
 {
-  state.set_pos(Vector2f(x, y));
+  state.set_pos(Vector2i(x, y));
 }
 
 void
 Playfield::scroll (int x, int y)
 {
-  state.set_pos(state.get_pos() + Vector2f((float)x, (float)y));
+  state.set_pos(state.get_pos() + Vector2i(x, y));
 }
 
 void

Modified: trunk/pingus/src/components/playfield.hpp
===================================================================
--- trunk/pingus/src/components/playfield.hpp   2008-07-27 04:00:29 UTC (rev 
3911)
+++ trunk/pingus/src/components/playfield.hpp   2008-07-27 14:02:05 UTC (rev 
3912)
@@ -50,7 +50,7 @@
   std::vector<Rect> clipping_rectangles;
   
   Vector2i mouse_pos;
-  Vector2f old_state_pos;
+  Vector2i old_state_pos;
 
 public:
   Playfield(Server*, GameSession*, const Rect& rect);

Modified: trunk/pingus/src/display/drawing_context.cpp
===================================================================
--- trunk/pingus/src/display/drawing_context.cpp        2008-07-27 04:00:29 UTC 
(rev 3911)
+++ trunk/pingus/src/display/drawing_context.cpp        2008-07-27 14:02:05 UTC 
(rev 3912)
@@ -384,20 +384,6 @@
                               z));
 }
 
-Vector3f
-DrawingContext::screen_to_world(Vector3f pos)
-{
-  return pos - Vector3f(translate_stack.back().x + rect.left,
-                        translate_stack.back().y + rect.top);
-}
-
-Vector3f
-DrawingContext::world_to_screen(Vector3f pos)
-{
-  return pos + Vector3f(translate_stack.back().x + rect.left, 
-                        translate_stack.back().y + rect.top);
-}
-
 Vector2i
 DrawingContext::screen_to_world(const Vector2i pos)
 {

Modified: trunk/pingus/src/display/drawing_context.hpp
===================================================================
--- trunk/pingus/src/display/drawing_context.hpp        2008-07-27 04:00:29 UTC 
(rev 3911)
+++ trunk/pingus/src/display/drawing_context.hpp        2008-07-27 14:02:05 UTC 
(rev 3912)
@@ -105,9 +105,6 @@
   /** Print a text right aligned */
   void print_right(const Font& font, const Vector2i& pos, const std::string& 
str, float z = 0.0f);
 
-  Vector3f screen_to_world (Vector3f pos);
-  Vector3f world_to_screen (Vector3f pos);
-
   Vector2i screen_to_world(const Vector2i pos);
   Vector2i world_to_screen(const Vector2i pos);
 

Modified: trunk/pingus/src/editor/editor_screen.cpp
===================================================================
--- trunk/pingus/src/editor/editor_screen.cpp   2008-07-27 04:00:29 UTC (rev 
3911)
+++ trunk/pingus/src/editor/editor_screen.cpp   2008-07-27 14:02:05 UTC (rev 
3912)
@@ -250,7 +250,7 @@
     {
       case Input::SCROLLER_EVENT_TYPE:
         viewport->set_scroll_pos(viewport->get_scroll_pos() -
-                                 Vector2f(event.scroll.x_delta,
+                                 Vector2i(event.scroll.x_delta,
                                           event.scroll.y_delta));
         break;
 

Modified: trunk/pingus/src/editor/viewport.cpp
===================================================================
--- trunk/pingus/src/editor/viewport.cpp        2008-07-27 04:00:29 UTC (rev 
3911)
+++ trunk/pingus/src/editor/viewport.cpp        2008-07-27 14:02:05 UTC (rev 
3912)
@@ -345,7 +345,7 @@
   UNUSED_ARG(delta);
 
   if (current_action == SCROLLING)
-    state.set_pos(state.get_pos() + Vector2f(mouse_screen_pos - 
drag_screen_pos) * delta * 5.0f);
+    state.set_pos(state.get_pos() + Vector2i(mouse_screen_pos - 
drag_screen_pos) * delta * 5.0f);
 
   // Autoscroll if necessary
   if (autoscroll)
@@ -354,13 +354,13 @@
       if (autoscroll)
         {
           if (mouse_screen_pos.x < autoscroll_border)
-            state.set_pos(state.get_pos() - Vector2f(5, 0));
+            state.set_pos(state.get_pos() - Vector2i(5, 0));
           else if (Display::get_width() - mouse_screen_pos.x < 
autoscroll_border)
-            state.set_pos(state.get_pos() + Vector2f(5, 0));
+            state.set_pos(state.get_pos() + Vector2i(5, 0));
           else if (mouse_screen_pos.y < autoscroll_border)
-            state.set_pos(state.get_pos() - Vector2f(0, 5));
+            state.set_pos(state.get_pos() - Vector2i(0, 5));
           else if (Display::get_height() - mouse_screen_pos.y < 
autoscroll_border)
-            state.set_pos(state.get_pos() + Vector2f(0, 5));
+            state.set_pos(state.get_pos() + Vector2i(0, 5));
         }
     }
 }
@@ -446,7 +446,7 @@
 Vector2i
 Viewport::screen2world(int x, int y) const
 {
-  return 
Vector2i(state.screen2world(drawing_context->screen_to_world(Vector2i(x, y))));
+  return state.screen2world(drawing_context->screen_to_world(Vector2i(x, y)));
 }
 
 void
@@ -507,14 +507,14 @@
     }
 }
 
-Vector2f
+Vector2i
 Viewport::get_scroll_pos() const
 {
   return state.get_pos();
 }
 
 void
-Viewport::set_scroll_pos(const Vector2f& pos)
+Viewport::set_scroll_pos(const Vector2i& pos)
 {
   state.set_pos(pos);
 }

Modified: trunk/pingus/src/editor/viewport.hpp
===================================================================
--- trunk/pingus/src/editor/viewport.hpp        2008-07-27 04:00:29 UTC (rev 
3911)
+++ trunk/pingus/src/editor/viewport.hpp        2008-07-27 14:02:05 UTC (rev 
3912)
@@ -24,7 +24,6 @@
 #include <vector>
 #include <string>
 
-class Vector3f;
 class DrawingContext;
 class SceneContext;
 
@@ -100,8 +99,8 @@
   /** Turns the "snap-to-grid" option on or off */
   void set_snap_to(bool s) { snap_to = s; }
 
-  Vector2f get_scroll_pos() const;
-  void     set_scroll_pos(const Vector2f& pos);
+  Vector2i get_scroll_pos() const;
+  void     set_scroll_pos(const Vector2i& pos);
 
   /// Mouse actions
   void on_primary_button_press(int x, int y);

Modified: trunk/pingus/src/font.cpp
===================================================================
--- trunk/pingus/src/font.cpp   2008-07-27 04:00:29 UTC (rev 3911)
+++ trunk/pingus/src/font.cpp   2008-07-27 14:02:05 UTC (rev 3912)
@@ -91,7 +91,7 @@
         if (it != glyphs.end())
           {
             const GlyphDescription& glyph = it->second;
-            fb.draw_surface(framebuffer_surface, glyph.rect, Vector2i(dstx, 
dsty) + glyph.offset);
+            fb.draw_surface(framebuffer_surface, glyph.rect, 
Vector2i(static_cast<int>(dstx), static_cast<int>(dsty)) + glyph.offset);
             dstx += glyph.advance + char_spacing;
           }
         else

Modified: trunk/pingus/src/graphic_context_state.cpp
===================================================================
--- trunk/pingus/src/graphic_context_state.cpp  2008-07-27 04:00:29 UTC (rev 
3911)
+++ trunk/pingus/src/graphic_context_state.cpp  2008-07-27 14:02:05 UTC (rev 
3912)
@@ -23,7 +23,7 @@
 public:
   Rect rect;
   
-  Vector2f offset;
+  Vector2i offset;
   float zoom;
   float rotation;
 
@@ -35,7 +35,7 @@
   : impl(new GraphicContextStateImpl())
 {
   impl->rect       = Rect(Vector2i(0,0), Size(Display::get_width(), 
Display::get_height()));
-  impl->offset     = Vector2f(0,0);
+  impl->offset     = Vector2i(0,0);
   impl->zoom       = 1.0f;
   impl->rotation   = 0;
   impl->have_limit = false;
@@ -45,7 +45,7 @@
   : impl(new GraphicContextStateImpl())
 {  
   impl->rect       = Rect(Vector2i(0,0), Size(w, h));
-  impl->offset     = Vector2f(0,0); 
+  impl->offset     = Vector2i(0,0); 
   impl->zoom       = 1.0f;
   impl->rotation   = 0;
   impl->have_limit = false;
@@ -55,7 +55,7 @@
   : impl(new GraphicContextStateImpl())
 {
   impl->rect       = rect;
-  impl->offset     = Vector2f(0,0); 
+  impl->offset     = Vector2i(0,0); 
   impl->zoom       = 1.0f;
   impl->rotation   = 0;
   impl->have_limit = false;  
@@ -120,7 +120,7 @@
 }
 
 void
-GraphicContextState::set_pos(const Vector2f& pos)
+GraphicContextState::set_pos(const Vector2i& pos)
 {
   impl->offset.x = -pos.x + (get_width()/2  / impl->zoom);
   impl->offset.y = -pos.y + (get_height()/2 / impl->zoom);
@@ -153,63 +153,17 @@
     }
 }
 
-Vector2f
+Vector2i
 GraphicContextState::get_pos() const
 {
-  return Vector2f(-impl->offset.x + (get_width()/2  / impl->zoom),
+  return Vector2i(-impl->offset.x + (get_width()/2  / impl->zoom),
                   -impl->offset.y + (get_height()/2  / impl->zoom));
 }
 
-void
-GraphicContextState::set_zoom(Vector2f pos, float z)
-{
-  float old_zoom = impl->zoom;
-  set_zoom(z);
-  impl->offset.x = pos.x/impl->zoom - pos.x/old_zoom + impl->offset.x;
-  impl->offset.y = pos.y/impl->zoom - pos.y/old_zoom + impl->offset.y;
-}
-
-void
-GraphicContextState::set_zoom(float z)
-{
-  impl->zoom = z;
-}
-
-float
-GraphicContextState::get_zoom()
-{
-  return impl->zoom;
-}
-
-void
-GraphicContextState::zoom_to (const Rectf& rect)
-{
-  float center_x = (rect.left + rect.right) / 2.0f;
-  float center_y = (rect.top + rect.bottom) / 2.0f;
-
-  float width  = rect.right - rect.left;
-  float height = rect.bottom - rect.top;
-  float screen_relation = float(get_height())/float(get_width ());
-  float rect_relation   = height/width; 
-  
-  //std::cout << "Screen: " << screen_relation << " Zoom: " << rect_relation 
<< std::endl;
-  if (rect_relation < screen_relation) // take width, ignore height
-    {
-      impl->zoom = get_width()/width; 
-    }
-  else // take height, ignore width
-    {
-      impl->zoom = get_height()/height;
-    }
-
-  impl->offset.x = (get_width()  / (2*impl->zoom)) - center_x;
-  impl->offset.y = (get_height() / (2*impl->zoom)) - center_y;
-}
-
-Vector2f
+Vector2i
 GraphicContextState::screen2world(const Vector2i& pos_) const
 {
-  Vector2f pos(float(pos_.x - impl->rect.left),
+  Vector2i pos(float(pos_.x - impl->rect.left),
                float(pos_.y - impl->rect.top));
 
   float sa = Math::sin(-impl->rotation/180.0f*Math::pi);
@@ -221,24 +175,12 @@
   pos.x = get_width()/2  + (ca * dx - sa * dy);
   pos.y = get_height()/2 + (sa * dx + ca * dy);
 
-  Vector2f p((float(pos.x) / impl->zoom) - impl->offset.x, 
+  Vector2i p((float(pos.x) / impl->zoom) - impl->offset.x, 
              (float(pos.y) / impl->zoom) - impl->offset.y);
 
   return p;
 }
 
-void
-GraphicContextState::set_rotation(float angle)
-{
-  impl->rotation = angle;
-}
-
-float
-GraphicContextState::get_rotation()
-{
-  return impl->rotation;
-}
-
 int
 GraphicContextState::get_width()  const 
 {

Modified: trunk/pingus/src/graphic_context_state.hpp
===================================================================
--- trunk/pingus/src/graphic_context_state.hpp  2008-07-27 04:00:29 UTC (rev 
3911)
+++ trunk/pingus/src/graphic_context_state.hpp  2008-07-27 14:02:05 UTC (rev 
3912)
@@ -58,27 +58,12 @@
   int get_width()  const;
   int get_height() const;
 
-  /** Set the current rotation angel */
-  void  set_rotation(float angle);
-
-  /** Return the current rotation angel */
-  float get_rotation();
-
   /** Move the center of the visible area to pos */
-  void      set_pos(const Vector2f& pos);
-  Vector2f  get_pos() const;
+  void      set_pos(const Vector2i& pos);
+  Vector2i  get_pos() const;
 
-  /** Set zoom to z, while ensuring that the screen position \a pos
-      (normaly the position of the mouse pointer) stays in the same
-      position even after zoomed in/out */
-  void  set_zoom(Vector2f pos, float z);
-  void  set_zoom(float z);
-  float get_zoom(); 
+  Vector2i screen2world(const Vector2i& pos) const;
 
-  void zoom_to (const Rectf& rect);
-
-  Vector2f screen2world(const Vector2i& pos) const;
-
 private:
   boost::shared_ptr<GraphicContextStateImpl> impl;
 };

Modified: trunk/pingus/src/particles/rain_particle_holder.cpp
===================================================================
--- trunk/pingus/src/particles/rain_particle_holder.cpp 2008-07-27 04:00:29 UTC 
(rev 3911)
+++ trunk/pingus/src/particles/rain_particle_holder.cpp 2008-07-27 14:02:05 UTC 
(rev 3912)
@@ -23,7 +23,7 @@
 #include "rain_particle_holder.hpp"
 
 namespace Particles {
-
+
 RainParticleHolder::RainParticle::RainParticle(int x, int y)
   : alive(true), splash(false), use_rain2_surf(false), splash_counter(0), 
splash_frame(0), pos(Vector3f((float)x, (float)y))
 {
@@ -117,12 +117,14 @@
         }
       else
         if (it->use_rain2_surf)
-          gc.color().draw(rain2_surf, Vector2i(it->pos.x, it->pos.y - 
rain1_surf.get_height()));
+          gc.color().draw(rain2_surf, Vector2i(static_cast<int>(it->pos.x), 
+                                               static_cast<int>(it->pos.y - 
rain1_surf.get_height())));
         else
-          gc.color().draw(rain1_surf, Vector2i(it->pos.x, it->pos.y - 
rain1_surf.get_height()));
+          gc.color().draw(rain1_surf, Vector2i(static_cast<int>(it->pos.x),
+                                               static_cast<int>(it->pos.y - 
rain1_surf.get_height())));
     }
 }
-
+
 } // namespace Particles
 
 /* EOF */

Modified: trunk/pingus/src/particles/rain_particle_holder.hpp
===================================================================
--- trunk/pingus/src/particles/rain_particle_holder.hpp 2008-07-27 04:00:29 UTC 
(rev 3911)
+++ trunk/pingus/src/particles/rain_particle_holder.hpp 2008-07-27 14:02:05 UTC 
(rev 3912)
@@ -26,7 +26,7 @@
 class GraphicContext;
 
 namespace Particles {
-
+
 class RainParticleHolder : public WorldObj
 {
   struct RainParticle {
@@ -66,7 +66,7 @@
   RainParticleHolder (const RainParticleHolder&);
   RainParticleHolder& operator= (const RainParticleHolder&);
 };
-
+
 } // namespace Particles
 
 #endif

Modified: trunk/pingus/src/sprite.cpp
===================================================================
--- trunk/pingus/src/sprite.cpp 2008-07-27 04:00:29 UTC (rev 3911)
+++ trunk/pingus/src/sprite.cpp 2008-07-27 14:02:05 UTC (rev 3912)
@@ -85,7 +85,7 @@
 }
 
 void
-Sprite::render(float x, float y, Framebuffer& fb)
+Sprite::render(int x, int y, Framebuffer& fb)
 {
   if (impl.get())
     impl->render(x, y, fb);

Modified: trunk/pingus/src/sprite.hpp
===================================================================
--- trunk/pingus/src/sprite.hpp 2008-07-27 04:00:29 UTC (rev 3911)
+++ trunk/pingus/src/sprite.hpp 2008-07-27 14:02:05 UTC (rev 3912)
@@ -45,7 +45,7 @@
   int get_width()  const;
   int get_height() const;
 
-  void render(float x, float y, Framebuffer& target);
+  void render(int x, int y, Framebuffer& target);
   void update(float delta = 0.033f);
 
   void set_hotspot(Origin origin, int x, int y);

Modified: trunk/pingus/src/sprite_impl.cpp
===================================================================
--- trunk/pingus/src/sprite_impl.cpp    2008-07-27 04:00:29 UTC (rev 3911)
+++ trunk/pingus/src/sprite_impl.cpp    2008-07-27 14:02:05 UTC (rev 3912)
@@ -148,13 +148,13 @@
 }
 
 void 
-SpriteImpl::render(float x, float y, Framebuffer& fb)
+SpriteImpl::render(int x, int y, Framebuffer& fb)
 {
   fb.draw_surface(framebuffer_surface,
                   Rect(frame_pos + Vector2i(frame_size.width  * 
(frame%array.width),
                                             frame_size.height * 
(frame/array.width)),
                        frame_size),
-                  Vector2i(static_cast<int>(x - offset.x), static_cast<int>(y 
- offset.y)));
+                  Vector2i(x - offset.x, y - offset.y));
 }
 
 void

Modified: trunk/pingus/src/sprite_impl.hpp
===================================================================
--- trunk/pingus/src/sprite_impl.hpp    2008-07-27 04:00:29 UTC (rev 3911)
+++ trunk/pingus/src/sprite_impl.hpp    2008-07-27 14:02:05 UTC (rev 3912)
@@ -55,7 +55,7 @@
 
   void update(float delta);
 
-  void render(float x, float y, Framebuffer& fb);
+  void render(int x, int y, Framebuffer& fb);
 
   void restart();
   void finish();

Modified: trunk/pingus/src/worldmap/level_dot.cpp
===================================================================
--- trunk/pingus/src/worldmap/level_dot.cpp     2008-07-27 04:00:29 UTC (rev 
3911)
+++ trunk/pingus/src/worldmap/level_dot.cpp     2008-07-27 14:02:05 UTC (rev 
3912)
@@ -51,8 +51,8 @@
 void
 LevelDot::draw(DrawingContext& gc)
 {
-  Vector3f mpos
-    = 
gc.screen_to_world(Vector3f(Input::Controller::current()->get_pointer(Input::STANDARD_POINTER)->get_pos()));
+  Vector2i mpos
+    = 
gc.screen_to_world(Vector2i(Input::Controller::current()->get_pointer(Input::STANDARD_POINTER)->get_pos()));
 
   float x = mpos.x - pos.x;
   float y = mpos.y - pos.y;
@@ -130,7 +130,7 @@
   if (accessible())
     {
       int length = Fonts::pingus_small.bounding_rect(0, 0, 
_(get_plf().get_levelname())).get_width() / 2;
-      int realpos = static_cast<int>(gc.world_to_screen(Vector3f(pos.x, pos.y, 
0)).x);
+      int realpos = static_cast<int>(gc.world_to_screen(Vector2i(pos.x, 
pos.y)).x);
       if (realpos - length < 0)
         pos_correction = realpos - length;
       else if (realpos + length > gc.get_width())
@@ -145,7 +145,7 @@
   else
     {
       int length  = Fonts::pingus_small.bounding_rect(0, 0, 
_("locked")).get_width() / 2;
-      int realpos = static_cast<int>(gc.world_to_screen(Vector3f(pos.x, pos.y, 
0)).x);
+      int realpos = static_cast<int>(gc.world_to_screen(Vector2i(pos.x, 
pos.y)).x);
       if (realpos - length < 0)
         pos_correction = realpos - length;
       else if (realpos + length > gc.get_width())

Modified: trunk/pingus/src/worldmap/worldmap.cpp
===================================================================
--- trunk/pingus/src/worldmap/worldmap.cpp      2008-07-27 04:00:29 UTC (rev 
3911)
+++ trunk/pingus/src/worldmap/worldmap.cpp      2008-07-27 14:02:05 UTC (rev 
3912)
@@ -100,8 +100,9 @@
 void
 Worldmap::draw(DrawingContext& gc)
 {
-  Vector3f pingu_pos = pingus->get_pos();
-  float min, max;
+  Vector2i pingu_pos(static_cast<int>(pingus->get_pos().x), 
+                     static_cast<int>(pingus->get_pos().y));
+  int min, max;
   int width  = worldmap.get_width();
   int height = worldmap.get_height();
 
@@ -129,7 +130,7 @@
     }
   pingu_pos.y = Math::clamp(min, pingu_pos.y, max);
 
-  gc_state.set_pos(Vector2f(pingu_pos.x, pingu_pos.y));
+  gc_state.set_pos(Vector2i(pingu_pos.x, pingu_pos.y));
        
   gc_state.push(gc);
   

Modified: trunk/pingus/src/worldobjs/surface_background.cpp
===================================================================
--- trunk/pingus/src/worldobjs/surface_background.cpp   2008-07-27 04:00:29 UTC 
(rev 3911)
+++ trunk/pingus/src/worldobjs/surface_background.cpp   2008-07-27 14:02:05 UTC 
(rev 3912)
@@ -132,9 +132,8 @@
 {
   if (!bg_sprite)
     return;
-
   
-  Vector3f offset = gc.color().world_to_screen(Vector3f(0,0));
+  Vector2i offset = gc.color().world_to_screen(Vector2i(0,0));
 
   offset.x -= gc.color().get_rect().left;
   offset.y -= gc.color().get_rect().top;





reply via email to

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