pingus-cvs
[Top][All Lists]
Advanced

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

[Pingus-CVS] r2770 - in branches/pingus_sdl: . src src/worldobjs


From: jsalmon3
Subject: [Pingus-CVS] r2770 - in branches/pingus_sdl: . src src/worldobjs
Date: Thu, 2 Aug 2007 04:44:39 +0200

Author: jsalmon3
Date: 2007-08-02 04:44:11 +0200 (Thu, 02 Aug 2007)
New Revision: 2770

Modified:
   branches/pingus_sdl/pingus.vcproj
   branches/pingus_sdl/src/collision_mask.cpp
   branches/pingus_sdl/src/collision_mask.hpp
   branches/pingus_sdl/src/ground_map.cpp
   branches/pingus_sdl/src/pixel_buffer.cpp
   branches/pingus_sdl/src/pixel_buffer.hpp
   branches/pingus_sdl/src/resource.cpp
   branches/pingus_sdl/src/resource.hpp
   branches/pingus_sdl/src/smallmap_image.cpp
   branches/pingus_sdl/src/worldobjs/groundpiece.cpp
Log:
Added global_event.* to vcproj
Fixed pitch/width issues
Added CollisionMask constructor that takes a ResDescriptor so it can eventually 
support rotations/flips



Modified: branches/pingus_sdl/pingus.vcproj
===================================================================
--- branches/pingus_sdl/pingus.vcproj   2007-08-02 02:24:58 UTC (rev 2769)
+++ branches/pingus_sdl/pingus.vcproj   2007-08-02 02:44:11 UTC (rev 2770)
@@ -463,6 +463,10 @@
                                >
                        </File>
                        <File
+                               RelativePath=".\src\global_event.cpp"
+                               >
+                       </File>
+                       <File
                                RelativePath=".\src\global_event.hpp"
                                >
                        </File>

Modified: branches/pingus_sdl/src/collision_mask.cpp
===================================================================
--- branches/pingus_sdl/src/collision_mask.cpp  2007-08-02 02:24:58 UTC (rev 
2769)
+++ branches/pingus_sdl/src/collision_mask.cpp  2007-08-02 02:44:11 UTC (rev 
2770)
@@ -31,30 +31,43 @@
 CollisionMask::CollisionMask()
   : buffer(0)
 {
+}
 
+CollisionMask::CollisionMask(const std::string& name)
+{
+  ResDescriptor res_desc(name);
+  init(res_desc);
 }
 
-CollisionMask::CollisionMask(const std::string& name)
+CollisionMask::CollisionMask(const ResDescriptor& res_desc)
   : buffer(0)
 {
+  init(res_desc);
+}
+
+void
+CollisionMask::init(const ResDescriptor& res_desc)
+{
   //std::cout << "CollisionMask: " << name << std::endl;
-  pixelbuffer = Resource::load_pixelbuffer(name);
+  pixelbuffer = Resource::load_pixelbuffer(res_desc);
   //PixelBuffer cmap = pixelbuffer; // 
Resource::load_pixelbuffer(System::cut_ext(name) + "_cmap");
 
+  int pitch = pixelbuffer.get_pitch();
+  width  = pixelbuffer.get_width();
+  height = pixelbuffer.get_height();
+  
+  buffer = new uint8_t[width * height];
+
   SDL_Surface* surface = pixelbuffer.get_surface();
   SDL_LockSurface(surface);
 
-  width  = surface->w;
-  height = surface->h;
-  buffer = new uint8_t[width * height];
-
   if (surface->format->palette)
     {
       uint8_t* source = static_cast<uint8_t*>(surface->pixels);
       for(int y = 0; y < height; ++y)
         for(int x = 0; x < width; ++x)
           {
-            if (source[y*surface->pitch+x] == surface->format->colorkey)
+            if (source[y*pitch + x] == surface->format->colorkey)
               buffer[y*width + x] = 0;
             else
               buffer[y*width + x] = 1;

Modified: branches/pingus_sdl/src/collision_mask.hpp
===================================================================
--- branches/pingus_sdl/src/collision_mask.hpp  2007-08-02 02:24:58 UTC (rev 
2769)
+++ branches/pingus_sdl/src/collision_mask.hpp  2007-08-02 02:44:11 UTC (rev 
2770)
@@ -28,6 +28,7 @@
 
 #include <string>
 #include "pixel_buffer.hpp"
+#include "res_descriptor.hpp"
 
 /** */
 class CollisionMask
@@ -41,6 +42,7 @@
 public:
   CollisionMask();
   CollisionMask(const std::string& name);
+  CollisionMask(const ResDescriptor& res_desc);
   ~CollisionMask();
   
   int get_width() const;
@@ -49,6 +51,9 @@
   
   PixelBuffer get_pixelbuffer() const;
   uint8_t* get_data() const;
+
+private:
+  void init(const ResDescriptor& res_desc);
 };
 
 #endif

Modified: branches/pingus_sdl/src/ground_map.cpp
===================================================================
--- branches/pingus_sdl/src/ground_map.cpp      2007-08-02 02:24:58 UTC (rev 
2769)
+++ branches/pingus_sdl/src/ground_map.cpp      2007-08-02 02:44:11 UTC (rev 
2770)
@@ -201,6 +201,9 @@
   int swidth  = sprovider.get_width();
   int twidth  = provider.get_width();
 
+  int spitch = sprovider.get_pitch();
+  int tpitch = sprovider.get_pitch();
+
   int start_x = std::max(0, -x_pos);
   int start_y = std::max(0, -y_pos);
 
@@ -219,8 +222,8 @@
 
       for (int y = start_y; y < end_y; ++y)
         {
-          Uint8* tptr = target_buf + 4*((twidth*(y+y_pos)) + x_pos + start_x);
-          Uint8* sptr = source_buf + swidth*y + start_x;
+          Uint8* tptr = target_buf + tpitch*(y+y_pos) + 4*(x_pos + start_x);
+          Uint8* sptr = source_buf + spitch*y + start_x;
 
           for (int x = start_x; x < end_x; ++x)
             { 
@@ -242,8 +245,8 @@
     {
       for (int y = start_y; y < end_y; ++y)
         {
-          Uint8* tptr = target_buf + 4*((twidth*(y+y_pos)) + x_pos + start_x);
-          Uint8* sptr = source_buf + swidth*y + start_x;
+          Uint8* tptr = target_buf + tpitch*(y+y_pos) + 4*(x_pos + start_x);
+          Uint8* sptr = source_buf + spitch*y + start_x;
 
           for (int x = start_x; x < end_x; ++x)
             { 

Modified: branches/pingus_sdl/src/pixel_buffer.cpp
===================================================================
--- branches/pingus_sdl/src/pixel_buffer.cpp    2007-08-02 02:24:58 UTC (rev 
2769)
+++ branches/pingus_sdl/src/pixel_buffer.cpp    2007-08-02 02:44:11 UTC (rev 
2770)
@@ -116,6 +116,15 @@
     return 0;
 }
 
+int
+PixelBuffer::get_pitch() const
+{
+  if (get_surface())
+    return get_surface()->pitch;
+  else
+    return 0;
+}
+
 SDL_Surface* 
 PixelBuffer::get_surface() const
 {

Modified: branches/pingus_sdl/src/pixel_buffer.hpp
===================================================================
--- branches/pingus_sdl/src/pixel_buffer.hpp    2007-08-02 02:24:58 UTC (rev 
2769)
+++ branches/pingus_sdl/src/pixel_buffer.hpp    2007-08-02 02:44:11 UTC (rev 
2770)
@@ -56,6 +56,7 @@
 
   int get_width()  const;
   int get_height() const;
+  int get_pitch()  const;
 
   void blit(const PixelBuffer& source, int x, int y);
 

Modified: branches/pingus_sdl/src/resource.cpp
===================================================================
--- branches/pingus_sdl/src/resource.cpp        2007-08-02 02:24:58 UTC (rev 
2769)
+++ branches/pingus_sdl/src/resource.cpp        2007-08-02 02:44:11 UTC (rev 
2770)
@@ -176,6 +176,12 @@
   return CollisionMask(name);
 }
 
+CollisionMask
+Resource::load_collision_mask(const ResDescriptor& res_desc)
+{
+  return CollisionMask(res_desc);
+}
+
 PixelBuffer
 Resource::load_pixelbuffer(const ResDescriptor& desc_)
 {

Modified: branches/pingus_sdl/src/resource.hpp
===================================================================
--- branches/pingus_sdl/src/resource.hpp        2007-08-02 02:24:58 UTC (rev 
2769)
+++ branches/pingus_sdl/src/resource.hpp        2007-08-02 02:44:11 UTC (rev 
2770)
@@ -75,6 +75,7 @@
   static Sprite        load_sprite(const ResDescriptor&);
   static Sprite        load_sprite(const std::string& res_name);
   static CollisionMask load_collision_mask(const std::string& res_name);
+  static CollisionMask load_collision_mask(const ResDescriptor&);
   static PixelBuffer   load_pixelbuffer(const std::string& res_name);
   static PixelBuffer   load_pixelbuffer(const ResDescriptor&);
 

Modified: branches/pingus_sdl/src/smallmap_image.cpp
===================================================================
--- branches/pingus_sdl/src/smallmap_image.cpp  2007-08-02 02:24:58 UTC (rev 
2769)
+++ branches/pingus_sdl/src/smallmap_image.cpp  2007-08-02 02:44:11 UTC (rev 
2770)
@@ -88,12 +88,13 @@
 
   int width  = canvas.get_width();
   int height = canvas.get_height();
+  int pitch = canvas.get_pitch();
   for(int y = 0; y < height; ++y)
     {
       for (int x = 0; x < width; ++x)
        {
           // Index on the smallmap canvas
-          int i = 4 * ((y * width) + x);
+          int i = y * pitch + 4 * x;
 
          int tx = x * cmap_width / width;
          int ty = y * cmap_height / height;

Modified: branches/pingus_sdl/src/worldobjs/groundpiece.cpp
===================================================================
--- branches/pingus_sdl/src/worldobjs/groundpiece.cpp   2007-08-02 02:24:58 UTC 
(rev 2769)
+++ branches/pingus_sdl/src/worldobjs/groundpiece.cpp   2007-08-02 02:44:11 UTC 
(rev 2770)
@@ -38,11 +38,9 @@
 void
 Groundpiece::on_startup ()
 {
-  //// FIXME: We discard rotation here!
-  CollisionMask mask = Resource::load_collision_mask(desc.res_name);
+  CollisionMask mask = Resource::load_collision_mask(desc);
 
-  // FIXME: overdrawing of bridges and similar things aren't handled
-  // FIXME: here
+  // FIXME: overdrawing of bridges and similar things aren't handled here
   if (gptype == Groundtype::GP_REMOVE)
     get_world()->remove(mask, static_cast<int>(pos.x), 
static_cast<int>(pos.y));
   else





reply via email to

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