pingus-cvs
[Top][All Lists]
Advanced

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

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


From: jsalmon3
Subject: [Pingus-CVS] r2718 - branches/pingus_sdl/src
Date: Fri, 13 Jul 2007 09:27:03 +0200

Author: jsalmon3
Date: 2007-07-13 09:26:53 +0200 (Fri, 13 Jul 2007)
New Revision: 2718

Modified:
   branches/pingus_sdl/src/col_map.cpp
   branches/pingus_sdl/src/ground_map.cpp
   branches/pingus_sdl/src/pingus_main.cpp
   branches/pingus_sdl/src/pingus_main.hpp
   branches/pingus_sdl/src/pixel_buffer.cpp
   branches/pingus_sdl/src/pixel_buffer.hpp
Log:
Added PixelBufferImpl, implemented ColMap::draw, removed unused clanlib code

Modified: branches/pingus_sdl/src/col_map.cpp
===================================================================
--- branches/pingus_sdl/src/col_map.cpp 2007-07-13 04:45:39 UTC (rev 2717)
+++ branches/pingus_sdl/src/col_map.cpp 2007-07-13 07:26:53 UTC (rev 2718)
@@ -26,6 +26,7 @@
 #include "pixel_buffer.hpp"
 #include "pingus_error.hpp"
 #include "gettext.h"
+#include "sprite.hpp"
 
 #define COLMAP_WITH_MEMORY_HOLE 1
 
@@ -253,7 +254,6 @@
 void
 ColMap::draw(DrawingContext& gc)
 {
-#if 0
   PixelBuffer canvas(width, height);
   unsigned char* buffer;
 
@@ -297,9 +297,7 @@
   canvas.unlock();
 
   Sprite sprite(canvas);
-
-  //FIXME:gc.draw(sprite, 0, 0);
-#endif
+  gc.draw(sprite, 0, 0);
 }
 
 unsigned

Modified: branches/pingus_sdl/src/ground_map.cpp
===================================================================
--- branches/pingus_sdl/src/ground_map.cpp      2007-07-13 04:45:39 UTC (rev 
2717)
+++ branches/pingus_sdl/src/ground_map.cpp      2007-07-13 07:26:53 UTC (rev 
2718)
@@ -40,16 +40,10 @@
 void
 MapTile::prepare()
 {
-#if 0
   if (!pixelbuffer)
     {
-      pixelbuffer = PixelBuffer(tile_size, tile_size, tile_size*4, 
CL_PixelFormat::rgba8888);
-      Blitter::clear_canvas(pixelbuffer);
-    }
-#endif
-  if (!pixelbuffer)
-    {
       pixelbuffer = PixelBuffer(tile_size, tile_size);
+      //Blitter::clear_canvas(pixelbuffer);
     }
 }
 

Modified: branches/pingus_sdl/src/pingus_main.cpp
===================================================================
--- branches/pingus_sdl/src/pingus_main.cpp     2007-07-13 04:45:39 UTC (rev 
2717)
+++ branches/pingus_sdl/src/pingus_main.cpp     2007-07-13 07:26:53 UTC (rev 
2718)
@@ -836,7 +836,6 @@
   }
 
   deinit_pingus();
-  deinit_clanlib();
 
   PHYSFS_deinit();
 
@@ -861,48 +860,6 @@
 }
 
 void
-PingusMain::init_clanlib()
-{
-#if 0
-  if (render_preview)
-    {
-      CL_SetupCore::init ();
-      // Register only the resource types
-      CL_SetupDisplay::init(true);
-    }
-  else
-    {
-      CL_SetupCore::init ();
-
-      if (use_opengl) CL_SetupGL::init();
-      else            CL_SetupSDL::init();
-
-      CL_SetupDisplay::init();
-
-      if (verbose) {
-        std::cout << "Using resolution: "
-                  << screen_width << "x" << screen_height << std::endl;
-      }
-
-      CL_DisplayWindowDescription window_desc;
-      window_desc.set_size(CL_Size(screen_width, screen_height));
-      window_desc.set_title(PACKAGE_STRING);
-      window_desc.set_fullscreen(fullscreen_enabled);
-      window_desc.set_allow_resize(false);
-      window_desc.set_refresh_rate(refresh_rate);
-      
-      window = new CL_DisplayWindow(window_desc);
-     
-  //CL_Display::clear();
-  //  CL_Display::flip();
-    }
-  CL_SetupGUI::init ();
-  
-  on_exit_press_slot = window->sig_window_close().connect(this, 
&PingusMain::on_exit_press);
-#endif 
-}
-
-void
 PingusMain::on_exit_press()
 {
   std::cout << "Exit pressed" << std::endl;
@@ -910,22 +867,6 @@
 }
 
 void
-PingusMain::deinit_clanlib()
-{
-#if 0
-  CL_SetupCore::deinit();
-  CL_SetupGUI::deinit ();
-
-  if (use_opengl)
-    CL_SetupGL::deinit();
-  else
-    CL_SetupSDL::deinit();
-
-  CL_SetupDisplay::deinit ();
-#endif 
-}
-
-void
 PingusMain::init_pingus()
 {
   SavegameManager::instance();

Modified: branches/pingus_sdl/src/pingus_main.hpp
===================================================================
--- branches/pingus_sdl/src/pingus_main.hpp     2007-07-13 04:45:39 UTC (rev 
2717)
+++ branches/pingus_sdl/src/pingus_main.hpp     2007-07-13 07:26:53 UTC (rev 
2718)
@@ -67,9 +67,6 @@
 
   void print_greeting_message();
 
-  void init_clanlib();
-  void deinit_clanlib();
-
   void init_sdl();
   void deinit_sdl();
 

Modified: branches/pingus_sdl/src/pixel_buffer.cpp
===================================================================
--- branches/pingus_sdl/src/pixel_buffer.cpp    2007-07-13 04:45:39 UTC (rev 
2717)
+++ branches/pingus_sdl/src/pixel_buffer.cpp    2007-07-13 07:26:53 UTC (rev 
2718)
@@ -29,14 +29,15 @@
 #include "pixel_buffer.hpp"
 
 PixelBuffer::PixelBuffer()
-  : surface(0)
+  : impl(0)
 {
 }
 
 PixelBuffer::PixelBuffer(const std::string& name_)
+  : impl(new PixelBufferImpl())
 {
-  surface = IMG_Load(name_.c_str());
-  if (!surface)
+  impl->surface = IMG_Load(name_.c_str());
+  if (!impl->surface)
     std::cout << "XXXXXX Failed to load: " << name_ << std::endl;
   ///else
   //std::cout << "Loaded pixelbuffer: " << name << ": " << surface->w << "x" 
<< surface->h << std::endl;
@@ -44,8 +45,9 @@
 }
 
 PixelBuffer::PixelBuffer(int width, int height)
+  : impl(new PixelBufferImpl())
 {
-  surface = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 32,
+  impl->surface = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 32,
                                  0x000000ff,
                                  0x0000ff00,
                                  0x00ff0000,
@@ -55,17 +57,16 @@
 
 PixelBuffer::~PixelBuffer()
 {
-  ////delete[] data;
 }
 
 void
 PixelBuffer::blit(const PixelBuffer& src, int x, int y)
 {
-  if (!surface)
+  if (!get_surface())
     {
       std::cout << "PixelBuffer: Trying to blit to empty surface" << std::endl;
     }
-  else if (!src.surface)
+  else if (!src.get_surface())
     {
       std::cout << "PixelBuffer: Trying to blit with an empty surface" << 
std::endl;
     }
@@ -76,33 +77,33 @@
       dstrect.x = x;
       dstrect.y = y;
 
-      SDL_BlitSurface(src.surface, NULL, surface, &dstrect);
+      SDL_BlitSurface(src.get_surface(), NULL, get_surface(), &dstrect);
     }
 }
 
 void
 PixelBuffer::lock()
 {
-  SDL_LockSurface(surface);
+  SDL_LockSurface(get_surface());
 }
 
 void
 PixelBuffer::unlock()
 {
-  SDL_UnlockSurface(surface);
+  SDL_UnlockSurface(get_surface());
 }
 
 uint8_t*
 PixelBuffer::get_data() const
 {
-  return static_cast<uint8_t*>(surface->pixels);
+  return static_cast<uint8_t*>(get_surface()->pixels);
 }
 
 int
 PixelBuffer::get_width()  const
 {
-  if (surface)
-    return surface->w;
+  if (get_surface())
+    return get_surface()->w;
   else
     return 0;
 }
@@ -110,8 +111,8 @@
 int
 PixelBuffer::get_height() const
 {
-  if (surface)
-    return surface->h;
+  if (get_surface())
+    return get_surface()->h;
   else
     return 0;
 }
@@ -119,21 +120,21 @@
 SDL_Surface* 
 PixelBuffer::get_surface() const
 {
-  return surface;
+  return impl ? impl->surface : 0;
 }
 
 PixelBuffer::operator bool() const
 {
-  return surface != NULL;
+  return impl ? impl->surface != NULL : false;
 }
 
 Color
 PixelBuffer::get_pixel(int x, int y) const
 {
-  Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * 
surface->format->BytesPerPixel;
+  Uint8 *p = (Uint8 *)get_surface()->pixels + y * get_surface()->pitch + x * 
get_surface()->format->BytesPerPixel;
   Uint32 pixel;
 
-  switch(surface->format->BytesPerPixel)
+  switch(get_surface()->format->BytesPerPixel)
     {
     case 1:
       pixel = *p;
@@ -151,7 +152,7 @@
     } 
 
   Color color;
-  SDL_GetRGBA(pixel, surface->format, &color.r, &color.g, &color.b, &color.a);
+  SDL_GetRGBA(pixel, get_surface()->format, &color.r, &color.g, &color.b, 
&color.a);
   return color;
 }
 

Modified: branches/pingus_sdl/src/pixel_buffer.hpp
===================================================================
--- branches/pingus_sdl/src/pixel_buffer.hpp    2007-07-13 04:45:39 UTC (rev 
2717)
+++ branches/pingus_sdl/src/pixel_buffer.hpp    2007-07-13 07:26:53 UTC (rev 
2718)
@@ -29,12 +29,23 @@
 #include "SDL.h"
 #include <string>
 #include "math/color.hpp"
+#include "shared_ptr.hpp"
 
+class PixelBufferImpl
+{
+public:
+  PixelBufferImpl(SDL_Surface* surface = NULL) : surface(surface) {}
+  ~PixelBufferImpl() {
+    SDL_FreeSurface(surface);
+  }
+  SDL_Surface* surface;
+};
+
 /** */
 class PixelBuffer
 {
 private:
-  SDL_Surface* surface;
+  SharedPtr<PixelBufferImpl> impl;
 
 public:
   PixelBuffer();





reply via email to

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