pingus-cvs
[Top][All Lists]
Advanced

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

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


From: grumbel at BerliOS
Subject: [Pingus-CVS] r2701 - in branches/pingus_sdl/src: . worldobjs
Date: Fri, 23 Mar 2007 19:02:16 +0100

Author: grumbel
Date: 2007-03-23 19:02:14 +0100 (Fri, 23 Mar 2007)
New Revision: 2701

Modified:
   branches/pingus_sdl/src/col_map.cpp
   branches/pingus_sdl/src/col_map.hpp
   branches/pingus_sdl/src/collision_mask.cpp
   branches/pingus_sdl/src/collision_mask.hpp
   branches/pingus_sdl/src/system.cpp
   branches/pingus_sdl/src/system.hpp
   branches/pingus_sdl/src/world.cpp
   branches/pingus_sdl/src/worldobjs/liquid.cpp
Log:
- stuff

Modified: branches/pingus_sdl/src/col_map.cpp
===================================================================
--- branches/pingus_sdl/src/col_map.cpp 2007-03-23 17:53:02 UTC (rev 2700)
+++ branches/pingus_sdl/src/col_map.cpp 2007-03-23 18:02:14 UTC (rev 2701)
@@ -22,6 +22,7 @@
 #include "display/drawing_context.hpp"
 #include "globals.hpp"
 #include "col_map.hpp"
+#include "collision_mask.hpp"
 #include "pixel_buffer.hpp"
 #include "pingus_error.hpp"
 #include "gettext.h"
@@ -75,7 +76,7 @@
 }
 
 void
-ColMap::remove(PixelBuffer provider, int x, int y)
+ColMap::remove(const CollisionMask& mask, int x, int y)
 {
 #if 0
        ++serial;
@@ -163,7 +164,7 @@
 
 // Puts a surface on the colmap
 void
-ColMap::put(PixelBuffer provider, int sur_x, int sur_y, Groundtype::GPType 
pixel)
+ColMap::put(const CollisionMask& mask, int sur_x, int sur_y, 
Groundtype::GPType pixel)
 {
   // transparent groundpieces are only drawn on the gfx map, not on the colmap
   if (pixel == Groundtype::GP_TRANSPARENT)
@@ -179,6 +180,17 @@
       return;
     }
 
+  uint8_t* source = mask.get_data();
+  for (int y=0; y < mask.get_height(); ++y)
+    for (int x=0; x < mask.get_width(); ++x)
+      {
+        if (source[y * mask.get_width() + x])
+          if (blit_allowed(x + sur_x, y + sur_y, pixel))
+            put(x + sur_x, y + sur_y, pixel);
+      }
+
+#if 0 
+
   // FIXME: Little slow
   provider.lock();
   // Rewritting blitter for 32bit depth (using get_pixel())
@@ -194,7 +206,6 @@
       }
   provider.unlock();
 
-#if 0
   else if (provider.get_format().get_depth() == 8)
     {
       unsigned char* buffer;
@@ -245,8 +256,7 @@
 ColMap::draw(DrawingContext& gc)
 {
 #if 0
-  PixelBuffer canvas(width, height, width*4, CL_PixelFormat::rgba8888);
-  CL_Surface sur;
+  PixelBuffer canvas(width, height);
   unsigned char* buffer;
 
   canvas.lock();
@@ -288,9 +298,9 @@
 
   canvas.unlock();
 
-  sur = CL_Surface(canvas);
+  Sprite sprite(canvas);
 
-  //FIXME:gc.draw(sur, 0, 0);
+  //FIXME:gc.draw(sprite, 0, 0);
 #endif
 }
 

Modified: branches/pingus_sdl/src/col_map.hpp
===================================================================
--- branches/pingus_sdl/src/col_map.hpp 2007-03-23 17:53:02 UTC (rev 2700)
+++ branches/pingus_sdl/src/col_map.hpp 2007-03-23 18:02:14 UTC (rev 2701)
@@ -22,8 +22,7 @@
 
 #include "groundtype.hpp"
 
-class CL_Surface;
-class PixelBuffer;
+class CollisionMask;
 
 class DrawingContext;
 class ResDescriptor;
@@ -77,10 +76,10 @@
   bool blit_allowed (int x, int y,  Groundtype::GPType);
 
   void put(int x, int y, Groundtype::GPType p = Groundtype::GP_GROUND);
-  void put(PixelBuffer, int x, int y, Groundtype::GPType);
+  void put(const CollisionMask& mask, int x, int y, Groundtype::GPType);
 
   void remove(int x, int y);
-  void remove(PixelBuffer, int x, int y);
+  void remove(const CollisionMask& mask, int x, int y);
 
   void draw(DrawingContext& gc);
 

Modified: branches/pingus_sdl/src/collision_mask.cpp
===================================================================
--- branches/pingus_sdl/src/collision_mask.cpp  2007-03-23 17:53:02 UTC (rev 
2700)
+++ branches/pingus_sdl/src/collision_mask.cpp  2007-03-23 18:02:14 UTC (rev 
2701)
@@ -25,33 +25,66 @@
 
 #include <iostream>
 #include "resource.hpp"
+#include "system.hpp"
 #include "collision_mask.hpp"
 
 CollisionMask::CollisionMask()
+  : buffer(0)
 {
 
 }
 
 CollisionMask::CollisionMask(const std::string& name)
+  : buffer(0)
 {
   //std::cout << "CollisionMask: " << name << std::endl;
   pixelbuffer = Resource::load_pixelbuffer(name);
+  //PixelBuffer cmap = pixelbuffer; // 
Resource::load_pixelbuffer(System::cut_ext(name) + "_cmap");
+
+  width  = pixelbuffer.get_width();
+  height = pixelbuffer.get_height();
+  
+  buffer = new uint8_t[width * height];
+
+  SDL_Surface* surface = pixelbuffer.get_surface();
+  SDL_LockSurface(surface);
+
+  if (surface->format->BytesPerPixel == 1)
+    {
+      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 * width + x] == surface->format->colorkey)
+              buffer[y * width + x] = 0;
+            else
+              buffer[y * width + x] = 1;
+          }
+    }
+  else
+    {
+      std::cout << "CollisionMask: unsupported image format: " 
+                << surface->format->BytesPerPixel << std::endl;     
+    }
+
+  SDL_UnlockSurface(surface);
 }
 
 CollisionMask::~CollisionMask()
 {
+  delete buffer;
 }  
 
 int
 CollisionMask::get_width() const
 {
-  return pixelbuffer.get_width();
+  return width;
 }
 
 int
 CollisionMask::get_height() const
 {
-  return pixelbuffer.get_height();
+  return height;
 }
 
 PixelBuffer
@@ -60,4 +93,10 @@
   return pixelbuffer;
 }
 
+uint8_t*
+CollisionMask::get_data() const
+{
+  return buffer;
+}
+
 /* EOF */

Modified: branches/pingus_sdl/src/collision_mask.hpp
===================================================================
--- branches/pingus_sdl/src/collision_mask.hpp  2007-03-23 17:53:02 UTC (rev 
2700)
+++ branches/pingus_sdl/src/collision_mask.hpp  2007-03-23 18:02:14 UTC (rev 
2701)
@@ -34,6 +34,9 @@
 {
 public:
   PixelBuffer pixelbuffer;
+  uint8_t*    buffer;
+  int         width;
+  int         height;
 
 public:
   CollisionMask();
@@ -44,6 +47,7 @@
   int get_height() const;
   
   PixelBuffer get_pixelbuffer() const;
+  uint8_t* get_data() const;
 };
 
 #endif

Modified: branches/pingus_sdl/src/system.cpp
===================================================================
--- branches/pingus_sdl/src/system.cpp  2007-03-23 17:53:02 UTC (rev 2700)
+++ branches/pingus_sdl/src/system.cpp  2007-03-23 18:02:14 UTC (rev 2701)
@@ -147,6 +147,21 @@
 }
 
 std::string
+System::cut_ext (std::string filename)
+{
+  std::string::size_type idx = filename.find_last_of('.');
+  if (idx != std::string::npos)
+    {
+      std::cout << "CutExt: " << filename << " -> " << filename.substr(0, idx) 
 << std::endl;
+      return filename.substr(0, idx);
+    }
+  else
+    {
+      return filename;
+    }
+}
+
+std::string
 System::extension (std::string filename)
 {
   const char* str = filename.c_str ();

Modified: branches/pingus_sdl/src/system.hpp
===================================================================
--- branches/pingus_sdl/src/system.hpp  2007-03-23 17:53:02 UTC (rev 2700)
+++ branches/pingus_sdl/src/system.hpp  2007-03-23 18:02:14 UTC (rev 2701)
@@ -82,6 +82,7 @@
       System::extension ("/bla/blabl") => ""
   */
   static std::string extension (std::string filename);
+  static std::string cut_ext (std::string filename);
 
   /** Returns the directory where Pingus can store its user specific
       state and config data (savegames, config files, demos, etc.) */

Modified: branches/pingus_sdl/src/world.cpp
===================================================================
--- branches/pingus_sdl/src/world.cpp   2007-03-23 17:53:02 UTC (rev 2700)
+++ branches/pingus_sdl/src/world.cpp   2007-03-23 18:02:14 UTC (rev 2701)
@@ -278,7 +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);
+  colmap->put(mask, x, y, type);
 }
 
 void

Modified: branches/pingus_sdl/src/worldobjs/liquid.cpp
===================================================================
--- branches/pingus_sdl/src/worldobjs/liquid.cpp        2007-03-23 17:53:02 UTC 
(rev 2700)
+++ branches/pingus_sdl/src/worldobjs/liquid.cpp        2007-03-23 18:02:14 UTC 
(rev 2701)
@@ -58,7 +58,7 @@
 void
 Liquid::on_startup ()
 {
-  CollisionMask mask = Resource::load_collision_mask("liquids/water_cmap");
+  CollisionMask mask = Resource::load_collision_mask("liquids/water");
 
   for(int i=0; i < width; ++i)
     world->put(mask,





reply via email to

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