pingus-cvs
[Top][All Lists]
Advanced

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

[Pingus-CVS] CVS: Games/Pingus/src Makefile.am,1.79,1.80 blitter.cxx,1.9


From: grumbel
Subject: [Pingus-CVS] CVS: Games/Pingus/src Makefile.am,1.79,1.80 blitter.cxx,1.9,1.10 blitter.hxx,1.4,1.5 pingus_resource.cxx,1.9,1.10 pingus_resource.hxx,1.4,1.5 res_descriptor.cxx,1.2,1.3 res_descriptor.hxx,1.4,1.5 sprite.cxx,1.3,1.4 sprite.hxx,1.2,1.3
Date: 25 Jun 2002 21:31:42 -0000

Update of /usr/local/cvsroot/Games/Pingus/src
In directory dark:/tmp/cvs-serv6646

Modified Files:
        Makefile.am blitter.cxx blitter.hxx pingus_resource.cxx 
        pingus_resource.hxx res_descriptor.cxx res_descriptor.hxx 
        sprite.cxx sprite.hxx 
Log Message:
- implemented horz/vert flipping of groundpieces
- implemented rotating of groundpieces (90 degree)
- saving of modified groundpieces is *not* implemented
- horz/vert/rot is buggy and incorrect
- it compiles and runs
- I am tired, rest will follow tomorrow... good night

Index: Makefile.am
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/Makefile.am,v
retrieving revision 1.79
retrieving revision 1.80
diff -u -d -r1.79 -r1.80
--- Makefile.am 22 Jun 2002 17:40:55 -0000      1.79
+++ Makefile.am 25 Jun 2002 21:31:40 -0000      1.80
@@ -202,6 +202,7 @@
 multiplayer_config.cxx       xml_helper.cxx \
 multiplayer_game.cxx         xml_plf.cxx \
 math.hxx \
-html_browser.hxx              html_browser.cxx
+html_browser.hxx              html_browser.cxx \
+resource_modifier.hxx         resource_modifier.cxx
 
 ## EOF ##

Index: blitter.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/blitter.cxx,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- blitter.cxx 24 Jun 2002 09:40:58 -0000      1.9
+++ blitter.cxx 25 Jun 2002 21:31:40 -0000      1.10
@@ -548,4 +548,73 @@
 }
 */ 
 
+/** Flip a surface horizontal */
+CL_Surface
+Blitter::flip_horizontal (const CL_Surface& sur)
+{
+  CL_SurfaceProvider* prov = sur.get_provider ();
+  CL_Canvas* canvas = new CL_Canvas (sur.get_width (), sur.get_height ());
+
+  prov->lock ();
+  canvas->lock ();
+
+  float r, b, g, a;
+  for (unsigned int y = 0; y < sur.get_height (); ++y)
+    for (unsigned int x = 0; x < sur.get_width (); ++x)
+      {
+       prov->get_pixel (sur.get_width () - x - 1, y, &r, &g, &b, &a);
+       canvas->draw_pixel (x, y, r, g, b, a);
+      }
+
+  canvas->unlock ();
+  prov->unlock ();
+  return CL_Surface(canvas, true);
+}
+
+/** Flip a surface vertical */
+CL_Surface
+Blitter::flip_vertical (const CL_Surface& sur)
+{
+  CL_SurfaceProvider* prov = sur.get_provider ();
+  CL_Canvas* canvas = new CL_Canvas (sur.get_width (), sur.get_height ());
+
+  prov->lock ();
+  canvas->lock ();
+
+  float r, b, g, a;
+  for (unsigned int y = 0; y < sur.get_height (); ++y)
+    for (unsigned int x = 0; x < sur.get_width (); ++x)
+      {
+       prov->get_pixel (x, sur.get_height () - y - 1, &r, &g, &b, &a);
+       canvas->draw_pixel (x, y, r, g, b, a);
+      }
+
+  canvas->unlock ();
+  prov->unlock ();
+  return CL_Surface(canvas, true);
+}
+
+/** Rotate a surface 90 degrees */
+CL_Surface
+Blitter::rotate_90 (const CL_Surface& sur)
+{
+  CL_SurfaceProvider* prov = sur.get_provider ();
+  CL_Canvas* canvas = new CL_Canvas (sur.get_height (), sur.get_width ());
+
+  prov->lock ();
+  canvas->lock ();
+
+  float r, b, g, a;
+  for (unsigned int y = 0; y < sur.get_height (); ++y)
+    for (unsigned int x = 0; x < sur.get_width (); ++x)
+      {
+       prov->get_pixel (x, y, &r, &g, &b, &a);
+       canvas->draw_pixel (sur.get_height () - 1 - y, x , r, g, b, a);
+      }
+
+  canvas->unlock ();
+  prov->unlock ();
+  return CL_Surface(canvas, true);
+}
+
 /* EOF */

Index: blitter.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/blitter.hxx,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- blitter.hxx 24 Jun 2002 22:52:53 -0000      1.4
+++ blitter.hxx 25 Jun 2002 21:31:40 -0000      1.5
@@ -76,6 +76,15 @@
       @return A newly created surface, the caller is responsible to delete it. 
*/
   static CL_Surface scale_surface (const CL_Surface& sur, int width, int 
height);
 
+  /** Flip a surface horizontal */
+  static CL_Surface flip_horizontal (const CL_Surface& sur);
+
+  /** Flip a surface vertical */
+  static CL_Surface flip_vertical (const CL_Surface& sur);
+
+  /** Rotate a surface 90 degrees */
+  static CL_Surface rotate_90 (const CL_Surface& sur);
+
   /** Creates a new canvas with the given width and height and
       stretches the source surface onto it, the caller is responsible
       to delete the returned CL_Canvas.

Index: pingus_resource.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/pingus_resource.cxx,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- pingus_resource.cxx 24 Jun 2002 12:09:22 -0000      1.9
+++ pingus_resource.cxx 25 Jun 2002 21:31:40 -0000      1.10
@@ -30,8 +30,11 @@
 #include "path_manager.hxx"
 #include "globals.hxx"
 #include "pingus_resource.hxx"
+#include "blitter.hxx"
 #include "debug.hxx"
 
+using namespace Pingus;
+
 std::map<std::string, CL_ResourceManager*> PingusResource::resource_map;
 std::map<ResDescriptor, CL_Surface>       PingusResource::surface_map;
 std::map<ResDescriptor, CL_Font*>          PingusResource::font_map;
@@ -109,10 +112,12 @@
 
 CL_Surface
 PingusResource::load_surface(const std::string& res_name, 
-                            const std::string& datafile)
+                            const std::string& datafile,
+                            ResourceModifier modifier)
 {
   return load_surface(ResDescriptor(res_name, datafile, 
-                                   ResDescriptor::RD_RESOURCE));
+                                   ResDescriptor::RD_RESOURCE,
+                                   modifier));
 }
 
 CL_Surface
@@ -124,7 +129,38 @@
   
   if (surf) 
     {
-      return surf;
+      // FIXME: buggy... and in the wrong place
+      switch (res_desc.modifier)
+       {
+         // FIXME: muahhhaa... I write slower code than you....
+       case ROT0:
+         return surf;
+      
+       case ROT90:
+         return Blitter::rotate_90(surf);
+
+       case ROT180:
+         return Blitter::rotate_90(Blitter::rotate_90(surf));
+
+       case ROT270:
+         return 
Blitter::rotate_90(Blitter::rotate_90(Blitter::rotate_90(surf)));
+
+       case ROT0FLIP:
+         return Blitter::flip_horizontal(Blitter::rotate_90(surf));
+
+       case ROT90FLIP:
+         return Blitter::flip_horizontal(Blitter::rotate_90(surf));
+
+       case ROT180FLIP:
+         return 
Blitter::flip_horizontal(Blitter::rotate_90(Blitter::rotate_90(surf)));
+
+       case ROT270FLIP:
+         return 
Blitter::flip_horizontal(Blitter::rotate_90(Blitter::rotate_90(Blitter::rotate_90(surf))));
+
+       default:
+         std::cout << "PingusResource: Unhandled modifier: " << 
res_desc.modifier << std::endl;
+         return surf;
+       }
     }
   else
     {

Index: pingus_resource.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/pingus_resource.hxx,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- pingus_resource.hxx 24 Jun 2002 22:52:55 -0000      1.4
+++ pingus_resource.hxx 25 Jun 2002 21:31:40 -0000      1.5
@@ -23,6 +23,7 @@
 #include <map>
 
 #include <ClanLib/Display/Display/surface.h>
+#include "resource_modifier.hxx"
 #include "res_descriptor.hxx"
 
 class CL_Font;
@@ -39,16 +40,6 @@
   static std::map<ResDescriptor, CL_Font*> font_map;
 
 public:
-  /** This array contains possible modifications of a surface */
-  typedef enum {
-    VFLIP  = (1<<0),
-    HVLIP  = (1<<1),
-    
-    ROT90  = (1<<2),
-    ROT180 = (1<<3),
-    ROT270 = (1<<4)
-  } Modifier;
-
   ///
   PingusResource();
   
@@ -58,7 +49,8 @@
 
   /** Load a surface with res_name from datafile */
   static CL_Surface load_surface(const std::string& res_name,
-                                const std::string& datafile);
+                                const std::string& datafile,
+                                Pingus::ResourceModifier modifier = 
Pingus::ROT0);
   
   /** Load a surface from the ResDescriptor */
   static CL_Surface load_surface(const ResDescriptor&);

Index: res_descriptor.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/res_descriptor.cxx,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- res_descriptor.cxx  21 Jun 2002 07:45:35 -0000      1.2
+++ res_descriptor.cxx  25 Jun 2002 21:31:40 -0000      1.3
@@ -34,19 +34,24 @@
   type     = res_desc.type;
   datafile = res_desc.datafile;
   res_name = res_desc.res_name;
+  modifier = Pingus::ROT0;
 }
 
 ResDescriptor::ResDescriptor(const std::string& arg_res_name,
                             const std::string& arg_datafile,
-                            ResourceType arg_type)
+                            ResourceType arg_type,
+                            Pingus::ResourceModifier arg_modifier)
 {
   res_name = arg_res_name;
   datafile = arg_datafile;
   type     = arg_type;
+  modifier = arg_modifier;
 }
 
 ResDescriptor::ResDescriptor(const std::string& str) 
 {
+  modifier = Pingus::ROT0;
+
   std::string::size_type pos1;
   std::string::size_type pos2;
 
@@ -71,6 +76,7 @@
 
 ResDescriptor::ResDescriptor(const std::string& c_cast, const std::string& 
value) 
 {
+  modifier = Pingus::ROT0;
   std::string cast;
 
   if (c_cast.find_first_of(":") == std::string::npos) {

Index: res_descriptor.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/res_descriptor.hxx,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- res_descriptor.hxx  24 Jun 2002 22:52:56 -0000      1.4
+++ res_descriptor.hxx  25 Jun 2002 21:31:40 -0000      1.5
@@ -21,6 +21,7 @@
 #define HEADER_PINGUS_RES_DESCRIPTOR_HXX
 
 #include <string>
+#include "resource_modifier.hxx"
 
 /// Resource descriptor, tells were to find a resource.
 class ResDescriptor
@@ -36,12 +37,14 @@
   
   /// The name of the data, filename or resourcename ("Textures/desert")
   std::string res_name;
+  
+  Pingus::ResourceModifier modifier;
 
   ResDescriptor();
   ResDescriptor(const ResDescriptor&);
 
   ResDescriptor(const std::string& res_name, const std::string& datafile,
-               ResourceType type);
+               ResourceType type, Pingus::ResourceModifier modifier = 
Pingus::ROT0);
   ResDescriptor(const std::string& cast, const std::string& value);
   ResDescriptor(const std::string& str);
 

Index: sprite.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/sprite.cxx,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- sprite.cxx  21 Jun 2002 07:45:35 -0000      1.3
+++ sprite.cxx  25 Jun 2002 21:31:40 -0000      1.4
@@ -249,7 +249,7 @@
   is_finished = false;
 }
 
-CL_Surface
+CL_Surface&
 Sprite::get_surface ()
 {
   return sur;

Index: sprite.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/sprite.hxx,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- sprite.hxx  24 Jun 2002 22:52:57 -0000      1.2
+++ sprite.hxx  25 Jun 2002 21:31:40 -0000      1.3
@@ -133,7 +133,7 @@
   void reset ();
 
   /// @return the surface which is used internally
-  CL_Surface get_surface ();
+  CL_Surface& get_surface ();
 };
 
 #endif




reply via email to

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