pingus-cvs
[Top][All Lists]
Advanced

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

[Pingus-CVS] r2677 - branches/pingus_sdl/src


From: grumbel at BerliOS
Subject: [Pingus-CVS] r2677 - branches/pingus_sdl/src
Date: Wed, 17 Jan 2007 14:43:51 +0100

Author: grumbel
Date: 2007-01-17 14:43:50 +0100 (Wed, 17 Jan 2007)
New Revision: 2677

Modified:
   branches/pingus_sdl/src/col_map.cxx
   branches/pingus_sdl/src/pixel_buffer.cpp
   branches/pingus_sdl/src/pixel_buffer.hpp
   branches/pingus_sdl/src/world.cxx
Log:
- collision map drawing now works

Modified: branches/pingus_sdl/src/col_map.cxx
===================================================================
--- branches/pingus_sdl/src/col_map.cxx 2007-01-17 13:16:56 UTC (rev 2676)
+++ branches/pingus_sdl/src/col_map.cxx 2007-01-17 13:43:50 UTC (rev 2677)
@@ -18,6 +18,7 @@
 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 #include <iostream>
+#include "SDL.h"
 #include "display/drawing_context.hxx"
 #include "globals.hxx"
 #include "col_map.hxx"
@@ -164,7 +165,6 @@
 void
 ColMap::put(PixelBuffer provider, int sur_x, int sur_y, Groundtype::GPType 
pixel)
 {
-#if 0
   // transparent groundpieces are only drawn on the gfx map, not on the colmap
   if (pixel == Groundtype::GP_TRANSPARENT)
     return;
@@ -179,22 +179,22 @@
       return;
     }
 
+  // FIXME: Little slow
   provider.lock();
+  // Rewritting blitter for 32bit depth (using get_pixel())
+  for (int y=0; y < provider.get_height(); ++y)
+    for (int x=0; x < provider.get_width(); ++x)
+      {
+        Color color = provider.get_pixel(x, y);
+        if (color.a > 32) // Alpha threshold
+          {
+            if (blit_allowed (x + sur_x, y + sur_y, pixel))
+              put(x + sur_x, y + sur_y, pixel);
+          }
+      }
+  provider.unlock();
 
-  if (provider.get_format().get_depth() == 32)
-    {
-      // Rewritting blitter for 32bit depth (using get_pixel())
-      for (int y=0; y < provider.get_height(); ++y)
-       for (int x=0; x < provider.get_width(); ++x)
-         {
-           Color color = provider.get_pixel(x, y);
-           if (color.get_alpha() > 0.1) // Alpha threshold
-             {
-               if (blit_allowed (x + sur_x, y + sur_y, pixel))
-                 put(x + sur_x, y + sur_y, pixel);
-             }
-         }
-    }
+#if 0
   else if (provider.get_format().get_depth() == 8)
     {
       unsigned char* buffer;

Modified: branches/pingus_sdl/src/pixel_buffer.cpp
===================================================================
--- branches/pingus_sdl/src/pixel_buffer.cpp    2007-01-17 13:16:56 UTC (rev 
2676)
+++ branches/pingus_sdl/src/pixel_buffer.cpp    2007-01-17 13:43:50 UTC (rev 
2677)
@@ -129,4 +129,32 @@
   return surface;
 }
 
+Color
+PixelBuffer::get_pixel(int x, int y) const
+{
+  Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * 
surface->format->BytesPerPixel;
+  Uint32 pixel;
+
+  switch(surface->format->BytesPerPixel)
+    {
+    case 1:
+      pixel = *p;
+    case 2: /* This will cause some problems ... */
+      pixel = *(Uint16 *)p;
+    case 3:
+      if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
+       pixel = p[0] << 16 | p[1] << 8 | p[2];
+      else
+       pixel = p[0] | p[1] << 8 | p[2] << 16;
+    case 4:
+      pixel = *(Uint32 *)p;
+    default:
+      pixel = 0;       /* shouldn't happen, but avoids warnings */
+    } 
+
+  Color color;
+  SDL_GetRGBA(pixel, surface->format, &color.r, &color.g, &color.b, &color.a);
+  return color;
+}
+
 /* EOF */

Modified: branches/pingus_sdl/src/pixel_buffer.hpp
===================================================================
--- branches/pingus_sdl/src/pixel_buffer.hpp    2007-01-17 13:16:56 UTC (rev 
2676)
+++ branches/pingus_sdl/src/pixel_buffer.hpp    2007-01-17 13:43:50 UTC (rev 
2677)
@@ -28,6 +28,7 @@
 
 #include "SDL.h"
 #include <string>
+#include "math/color.hpp"
 
 /** */
 class PixelBuffer
@@ -50,6 +51,8 @@
 
   void blit(const PixelBuffer& source, int x, int y);
 
+  Color get_pixel(int x, int y) const;
+
   SDL_Surface* get_surface() const;
 
   operator bool() const;

Modified: branches/pingus_sdl/src/world.cxx
===================================================================
--- branches/pingus_sdl/src/world.cxx   2007-01-17 13:16:56 UTC (rev 2676)
+++ branches/pingus_sdl/src/world.cxx   2007-01-17 13:43:50 UTC (rev 2677)
@@ -33,6 +33,7 @@
 #include "display/scene_context.hxx"
 #include "pingus_level.hxx"
 #include "worldobj_factory.hxx"
+#include "col_map.hxx"
 #include "game_time.hxx"
 
 
@@ -277,6 +278,7 @@
 World::put(const CollisionMask& mask, int x, int y, Groundtype::GPType type)
 {
   gfx_map->put(mask.get_pixelbuffer(), x, y);
+  colmap->put(mask.get_pixelbuffer(), x, y, type);
 }
 
 void





reply via email to

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