pingus-cvs
[Top][All Lists]
Advanced

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

[Pingus-CVS] r3660 - in trunk/pingus: . src


From: grumbel at BerliOS
Subject: [Pingus-CVS] r3660 - in trunk/pingus: . src
Date: Fri, 4 Jul 2008 07:39:53 +0200

Author: grumbel
Date: 2008-07-04 07:39:52 +0200 (Fri, 04 Jul 2008)
New Revision: 3660

Added:
   trunk/pingus/src/sprite_impl.cpp
   trunk/pingus/src/sprite_impl.hpp
Modified:
   trunk/pingus/SConstruct
   trunk/pingus/src/sprite.cpp
Log:
Moved SpriteImpl into its own file

Modified: trunk/pingus/SConstruct
===================================================================
--- trunk/pingus/SConstruct     2008-07-04 05:25:49 UTC (rev 3659)
+++ trunk/pingus/SConstruct     2008-07-04 05:39:52 UTC (rev 3660)
@@ -116,6 +116,7 @@
 'src/font_test_screen.cpp',
 'src/font_description.cpp',
 'src/sprite.cpp',
+'src/sprite_impl.cpp',
 'src/fps_counter.cpp', 
 'src/game_session.cpp', 
 'src/game_time.cpp', 

Modified: trunk/pingus/src/sprite.cpp
===================================================================
--- trunk/pingus/src/sprite.cpp 2008-07-04 05:25:49 UTC (rev 3659)
+++ trunk/pingus/src/sprite.cpp 2008-07-04 05:39:52 UTC (rev 3660)
@@ -26,156 +26,8 @@
 #include "surface.hpp"
 #include "pathname.hpp"
 #include "resource.hpp"
+#include "sprite_impl.hpp"
 #include "sprite_description.hpp"
-
-class SpriteImpl
-{
-private:
-  friend class Sprite;
-
-  Surface  surface;
-  bool     optimized;
-  Vector2i offset;
-
-  Vector2i frame_pos;
-  Size     frame_size;
-  int      frame_delay;
-
-  Size     array;
-
-  bool     loop;
-  bool     loop_last_cycle;
-  bool     finished;
-
-  /** Current frame */
-  int frame; 
-  int tick_count;
-
-public:
-  SpriteImpl()
-  {
-  }
-
-  SpriteImpl(const SpriteDescription& desc, 
ResourceModifierNS::ResourceModifier mod = ResourceModifierNS::ROT0)
-    : optimized(false),
-      finished(false),
-      frame(0),
-      tick_count(0)
-  {
-    surface = Surface(desc.filename);
-    if (mod != ResourceModifierNS::ROT0)
-      surface = surface.mod(mod);
-
-    if (!surface)
-      {
-        std::cout << "Error: Sprite: couldn't load '" << desc.filename << "'" 
<< std::endl;
-        surface = Surface(Pathname("images/core/misc/404.png", 
Pathname::DATA_PATH));
-        if (!surface) assert(!"Surface Couldn't find 404");
-      }
-
-    frame_pos = desc.frame_pos;
-
-    array = desc.array;
-
-    frame_size.width  = (desc.frame_size.width  == -1) ? 
surface.get_width()/array.width   : desc.frame_size.width;
-    frame_size.height = (desc.frame_size.height == -1) ? 
surface.get_height()/array.height : desc.frame_size.height;
-
-    frame_delay  = desc.speed;
-
-    loop = desc.loop;
-    loop_last_cycle = false;
-
-    offset = calc_origin(desc.origin, frame_size) - desc.offset;
-    
-  }
-
-  SpriteImpl(const Surface& surface_)
-    : surface(surface_),
-      optimized(false),
-      offset(0,0),
-      frame_pos(0,0),
-      frame_size(surface.get_width(), surface.get_height()),
-      frame_delay(0),
-      array(1,1),
-      loop(true),
-      loop_last_cycle(false),
-      finished(false),
-      frame(0),
-      tick_count(0)
-  {
-  }
-
-  ~SpriteImpl()
-  {
-  }
-
-  void optimize()
-  {
-    surface.optimize();
-    optimized = true;
-  }
-
-  void update(float delta)
-  {
-    if (finished)
-      return;
-
-    int total_time = frame_delay * (array.width * array.height);
-    tick_count += int(delta * 1000.0f);
-    if (tick_count >= total_time)
-      {
-       if (loop)
-         {
-           loop_last_cycle = true;
-           tick_count = tick_count % total_time;
-           frame = tick_count / frame_delay;
-         }
-       else
-         {
-           finished = true;
-         }
-      }
-    else
-      {
-       loop_last_cycle = false;
-       frame = tick_count / frame_delay;
-      }
-  }
-
-  void draw(float x, float y, SDL_Surface* dst)
-  {
-    if (!optimized)
-      optimize();
-
-    SDL_Rect dstrect;
-    dstrect.x = (Sint16)(x - offset.x);
-    dstrect.y = (Sint16)(y - offset.y);
-    dstrect.w = 0;
-    dstrect.h = 0;  
-
-    SDL_Rect srcrect;
-    srcrect.w = frame_size.width;
-    srcrect.h = frame_size.height;
-
-    srcrect.x = frame_pos.x + (srcrect.w * (frame%array.width));
-    srcrect.y = frame_pos.y + (srcrect.h * (frame/array.width));
-
-    SDL_BlitSurface(surface.get_surface(), &srcrect, dst, &dstrect);
-  }
-
-  void restart()
-  {
-    finished = false;
-    loop_last_cycle = false;
-    frame = 0;
-    tick_count = 0;
-  }
-
-  void finish()
-  {
-    finished = true;
-  }
-};
 
 Sprite::Sprite()
 {

Added: trunk/pingus/src/sprite_impl.cpp
===================================================================
--- trunk/pingus/src/sprite_impl.cpp    2008-07-04 05:25:49 UTC (rev 3659)
+++ trunk/pingus/src/sprite_impl.cpp    2008-07-04 05:39:52 UTC (rev 3660)
@@ -0,0 +1,149 @@
+//  Pingus - A free Lemmings clone
+//  Copyright (C) 2005-2008 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 as published by
+//  the Free Software Foundation, either version 3 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, see <http://www.gnu.org/licenses/>.
+
+#include "sprite_description.hpp"
+#include "sprite_impl.hpp"
+
+SpriteImpl::SpriteImpl()
+{
+}
+
+SpriteImpl::SpriteImpl(const SpriteDescription& desc, 
ResourceModifierNS::ResourceModifier mod)
+  : optimized(false),
+    finished(false),
+    frame(0),
+    tick_count(0)
+{
+  surface = Surface(desc.filename);
+  if (mod != ResourceModifierNS::ROT0)
+    surface = surface.mod(mod);
+
+  if (!surface)
+    {
+      std::cout << "Error: Sprite: couldn't load '" << desc.filename << "'" << 
std::endl;
+      surface = Surface(Pathname("images/core/misc/404.png", 
Pathname::DATA_PATH));
+      if (!surface) assert(!"Surface Couldn't find 404");
+    }
+
+  frame_pos = desc.frame_pos;
+
+  array = desc.array;
+
+  frame_size.width  = (desc.frame_size.width  == -1) ? 
surface.get_width()/array.width   : desc.frame_size.width;
+  frame_size.height = (desc.frame_size.height == -1) ? 
surface.get_height()/array.height : desc.frame_size.height;
+
+  frame_delay  = desc.speed;
+
+  loop = desc.loop;
+  loop_last_cycle = false;
+
+  offset = calc_origin(desc.origin, frame_size) - desc.offset;
+    
+}
+
+SpriteImpl::SpriteImpl(const Surface& surface_)
+  : surface(surface_),
+    optimized(false),
+    offset(0,0),
+    frame_pos(0,0),
+    frame_size(surface.get_width(), surface.get_height()),
+    frame_delay(0),
+    array(1,1),
+    loop(true),
+    loop_last_cycle(false),
+    finished(false),
+    frame(0),
+    tick_count(0)
+{
+}
+
+SpriteImpl::~SpriteImpl()
+{
+}
+
+void
+SpriteImpl::optimize()
+{
+  surface.optimize();
+  optimized = true;
+}
+
+void
+SpriteImpl::update(float delta)
+{
+  if (finished)
+    return;
+
+  int total_time = frame_delay * (array.width * array.height);
+  tick_count += int(delta * 1000.0f);
+  if (tick_count >= total_time)
+    {
+      if (loop)
+        {
+          loop_last_cycle = true;
+          tick_count = tick_count % total_time;
+          frame = tick_count / frame_delay;
+        }
+      else
+        {
+          finished = true;
+        }
+    }
+  else
+    {
+      loop_last_cycle = false;
+      frame = tick_count / frame_delay;
+    }
+}
+
+void 
+SpriteImpl::draw(float x, float y, SDL_Surface* dst)
+{
+  if (!optimized)
+    optimize();
+
+  SDL_Rect dstrect;
+  dstrect.x = (Sint16)(x - offset.x);
+  dstrect.y = (Sint16)(y - offset.y);
+  dstrect.w = 0;
+  dstrect.h = 0;  
+
+  SDL_Rect srcrect;
+  srcrect.w = frame_size.width;
+  srcrect.h = frame_size.height;
+
+  srcrect.x = frame_pos.x + (srcrect.w * (frame%array.width));
+  srcrect.y = frame_pos.y + (srcrect.h * (frame/array.width));
+
+  SDL_BlitSurface(surface.get_surface(), &srcrect, dst, &dstrect);
+}
+
+void
+SpriteImpl::restart()
+{
+  finished = false;
+  loop_last_cycle = false;
+  frame = 0;
+  tick_count = 0;
+}
+
+void
+SpriteImpl::finish()
+{
+  finished = true;
+}
+
+/* EOF */


Property changes on: trunk/pingus/src/sprite_impl.cpp
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: trunk/pingus/src/sprite_impl.hpp
===================================================================
--- trunk/pingus/src/sprite_impl.hpp    2008-07-04 05:25:49 UTC (rev 3659)
+++ trunk/pingus/src/sprite_impl.hpp    2008-07-04 05:39:52 UTC (rev 3660)
@@ -0,0 +1,65 @@
+//  Pingus - A free Lemmings clone
+//  Copyright (C) 2005-2008 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 as published by
+//  the Free Software Foundation, either version 3 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, see <http://www.gnu.org/licenses/>.
+
+#ifndef HEADER_PINGUS_SPRITE_IMPL_HPP
+#define HEADER_PINGUS_SPRITE_IMPL_HPP
+
+#include "surface.hpp"
+#include "math/vector2i.hpp"
+
+class SpriteDescription;
+
+class SpriteImpl
+{
+private:
+  friend class Sprite;
+
+  Surface  surface;
+  bool     optimized;
+  Vector2i offset;
+
+  Vector2i frame_pos;
+  Size     frame_size;
+  int      frame_delay;
+
+  Size     array;
+
+  bool     loop;
+  bool     loop_last_cycle;
+  bool     finished;
+
+  /** Current frame */
+  int frame; 
+  int tick_count;
+
+public:
+  SpriteImpl();
+  SpriteImpl(const SpriteDescription& desc, 
ResourceModifierNS::ResourceModifier mod = ResourceModifierNS::ROT0);
+  SpriteImpl(const Surface& surface_);
+  ~SpriteImpl();
+
+  void optimize();
+  void update(float delta);
+
+  void draw(float x, float y, SDL_Surface* dst);
+
+  void restart();
+  void finish();
+};
+
+#endif
+
+/* EOF */


Property changes on: trunk/pingus/src/sprite_impl.hpp
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native





reply via email to

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