pingus-cvs
[Top][All Lists]
Advanced

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

[Pingus-CVS] rev 2303 - in trunk/src: . editor worldobjs worldobjsdata


From: Ingo Ruhnke
Subject: [Pingus-CVS] rev 2303 - in trunk/src: . editor worldobjs worldobjsdata
Date: Thu, 06 May 2004 18:15:41 +0200

Author: grumbel
Date: 2004-05-06 18:15:41 +0200 (Thu, 06 May 2004)
New Revision: 2303

Modified:
   trunk/src/blitter.cxx
   trunk/src/editor/object_manager.cxx
   trunk/src/editor/sprite_editorobj.cxx
   trunk/src/loading.cxx
   trunk/src/pingus_resource.cxx
   trunk/src/sprite.cxx
   trunk/src/sprite.hxx
   trunk/src/worldobjs/surface_background.cxx
   trunk/src/worldobjsdata/groundpiece_data.cxx
   trunk/src/worldobjsdata/groundpiece_data.hxx
Log:
- some more clanlib related stuff

Modified: trunk/src/blitter.cxx
===================================================================
--- trunk/src/blitter.cxx       2004-05-06 13:21:56 UTC (rev 2302)
+++ trunk/src/blitter.cxx       2004-05-06 16:15:41 UTC (rev 2303)
@@ -69,7 +69,6 @@
 Blitter::put_surface_8bit(CL_PixelBuffer& provider, const CL_PixelBuffer& 
sprovider_,
                          int x, int y)
 {
-#if CLANLIB_0_6
   CL_PixelBuffer sprovider = sprovider_;
 
   int start_i;
@@ -89,18 +88,11 @@
 
   //std::cout << "Colorkey: " << sprovider.get_src_colorkey() << std::endl;
 
-  CL_Palette cl_palette = sprovider.get_palette();
+  CL_Palette palette = sprovider.get_palette();
 
-  if (!cl_palette)
-    {
-      char str[128];
-      snprintf(str, 128, "Couldn't find palette: %d", 
sprovider.get_format().get_depth());
-      PingusError::raise(str);
-    }
-
-  twidth = provider.get_width();
+  twidth  = provider.get_width();
   theight = provider.get_height();
-  tpitch = provider.get_pitch();
+  tpitch  = provider.get_pitch();
 
   swidth  = sprovider.get_width();
   sheight = sprovider.get_height();
@@ -116,9 +108,9 @@
   else
     x_offset = 0;
 
-  if (sprovider.uses_src_colorkey ())
+  if (sprovider.get_format().has_colorkey ())
     {
-      unsigned int colorkey = sprovider.get_src_colorkey();
+      unsigned int colorkey = sprovider.get_format().get_colorkey();
 
       for(int line=y_offset;
          line < sheight && (line + y) < theight;
@@ -164,7 +156,6 @@
 
   sprovider.unlock();
   provider.unlock();
-#endif
 }
 
 void
@@ -196,20 +187,19 @@
       for(int y = Math::max(0, -y_pos); y < sheight && (y + y_pos) < theight; 
++y)
        for(int x = Math::max(0,-x_pos); x < swidth && (x + x_pos) < twidth; 
++x)
          {
-#if CLANLIB_0_6
-            float red, green, blue, alpha;
-            float tred, tgreen, tblue, talpha;
+            CL_Color sc = provider.get_pixel(x, y);
+            CL_Color tc = canvas.get_pixel(x + x_pos, y + y_pos);
 
-           provider.get_pixel(x, y, &red, &green, &blue, &alpha);
-           canvas.get_pixel(x + x_pos, y + y_pos, &tred, &tgreen, &tblue, 
&talpha);
-
-           // FIXME: This doesn't give correct alpha values
+            // FIXME: This doesn't give correct alpha values
            canvas.draw_pixel(x + x_pos, y + y_pos,
-                              Math::mid(0.0f, 1.0f, (red   * alpha) + (tred   
* (1.0f - alpha))),
-                              Math::mid(0.0f, 1.0f, (green * alpha) + (tgreen 
* (1.0f - alpha))),
-                              Math::mid(0.0f, 1.0f, (blue  * alpha) + (tblue  
* (1.0f - alpha))),
-                              Math::mid(0.0f, 1.0f,  alpha * alpha  + (talpha 
* (1.0f - alpha))));
-#endif
+                              CL_Color(Math::mid(0, 255, 
+                                                 int((sc.get_red()   * 
sc.get_alpha()) + (tc.get_red()   * (255 - sc.get_alpha())))),
+                                       Math::mid(0, 255, 
+                                                 int((sc.get_green() * 
sc.get_alpha()) + (tc.get_green() * (255 - sc.get_alpha())))),
+                                       Math::mid(0, 255,
+                                                 int((sc.get_blue()  * 
sc.get_alpha()) + (tc.get_blue()  * (255 - sc.get_alpha())))),
+                                       Math::mid(0, 255,
+                                                 int((sc.get_alpha() * 
sc.get_alpha()  + (tc.get_alpha() * (255 - sc.get_alpha())))))));
          }
     }
   else // fast?!

Modified: trunk/src/editor/object_manager.cxx
===================================================================
--- trunk/src/editor/object_manager.cxx 2004-05-06 13:21:56 UTC (rev 2302)
+++ trunk/src/editor/object_manager.cxx 2004-05-06 16:15:41 UTC (rev 2303)
@@ -140,7 +140,9 @@
        i != temp_surfaces.end();
        i++)
     {
+#ifdef CLANLIB_0_6
       i->surface = PingusResource::load_sprite(i->desc);
+#endif
     }
 
   std::vector<WorldObjData*> temp_worldobj = plf->get_worldobjs_data();

Modified: trunk/src/editor/sprite_editorobj.cxx
===================================================================
--- trunk/src/editor/sprite_editorobj.cxx       2004-05-06 13:21:56 UTC (rev 
2302)
+++ trunk/src/editor/sprite_editorobj.cxx       2004-05-06 16:15:41 UTC (rev 
2303)
@@ -101,7 +101,11 @@
 {
   assert (pos_ref);
   Vector pos(*pos_ref);
+#ifdef CLANLIB_0_6
   return pos + Vector(sprite.get_x_align (), sprite.get_y_align ());
+#else
+  return pos + Vector(0, 0);
+#endif
 }
 
 bool

Modified: trunk/src/loading.cxx
===================================================================
--- trunk/src/loading.cxx       2004-05-06 13:21:56 UTC (rev 2302)
+++ trunk/src/loading.cxx       2004-05-06 16:15:41 UTC (rev 2303)
@@ -70,11 +70,11 @@
   sur.draw((CL_Display::get_width() - sur.get_width())/2,
                 (CL_Display::get_height() - sur.get_height())/2);
 
-#ifdef CLANLIB_0_6
-  font.print_center(CL_Display::get_width() / 2,
-                    CL_Display::get_height() - 130,
-                    str.c_str());
-#endif
+  CL_Font myfont = font;
+  myfont.set_alignment(origin_top_center);
+  myfont.draw(CL_Display::get_width() / 2,
+              CL_Display::get_height() - 130,
+              str);
 
   CL_Display::fill_rect(CL_Rect(50, CL_Display::get_height() - 100,
                                 CL_Display::get_width() - 50, 
CL_Display::get_height() - 50),

Modified: trunk/src/pingus_resource.cxx
===================================================================
--- trunk/src/pingus_resource.cxx       2004-05-06 13:21:56 UTC (rev 2302)
+++ trunk/src/pingus_resource.cxx       2004-05-06 16:15:41 UTC (rev 2303)
@@ -121,18 +121,20 @@
 }
 
 CL_PixelBuffer
-PingusResource::load_surface_provider(const ResDescriptor&)
+PingusResource::load_surface_provider(const ResDescriptor& desc)
 {
-  assert(0);
-  return CL_PixelBuffer();
+  CL_Sprite sprite = load_sprite(desc);
+  assert(sprite.get_frame_count() > 0);
+  return sprite.get_frame_surface(0).get_pixeldata();
 }
 
 CL_PixelBuffer
 PingusResource::load_surface_provider(const std::string& res_name,
                                       const std::string& datafile)
 {
-  assert(0);
-  return CL_PixelBuffer(); 
+  CL_Sprite sprite = load_sprite(res_name, datafile);
+  assert(sprite.get_frame_count() > 0);
+  return sprite.get_frame_surface(0).get_pixeldata();
 }
 
 CL_Surface

Modified: trunk/src/sprite.cxx
===================================================================
--- trunk/src/sprite.cxx        2004-05-06 13:21:56 UTC (rev 2302)
+++ trunk/src/sprite.cxx        2004-05-06 16:15:41 UTC (rev 2303)
@@ -42,14 +42,15 @@
     frames_per_second (arg_frames_per_second),
     direction (dir),
     looptype (arg_loop_type),
-    is_finished (false),
-    x_align (0), y_align (0)
+    is_finished (false)
 {
 }
 
 void
 Sprite::draw (int x, int y)
 {
+  if (sprite)
+{
   // FIXME: HACK
   update (0.0f);
 
@@ -57,95 +58,103 @@
     {
     case Sprite::NONE:
       sprite.set_frame(Math::round(frame));
-      sprite.draw(x + x_align, y + y_align);
+      sprite.draw(x, y);
       break;
     case Sprite::LEFT:
       sprite.set_frame(Math::round(frame));
-      sprite.draw(x + x_align, y + y_align);
+      sprite.draw(x, y);
       break;
     case Sprite::RIGHT:
       sprite.set_frame(Math::round(frame) + max_frames ());
-      sprite.draw (x + x_align, y + y_align);
+      sprite.draw (x, y);
       break;
     default:
       std::cout << "Direction: " << direction << std::endl;
       assert(0);
     }
 }
+}
 
 void
 Sprite::draw (const Vector& pos)
 {
-  draw (int(pos.x), int(pos.y));
+  if (sprite)
+    draw (int(pos.x), int(pos.y));
 }
 
 void
 Sprite::draw(GraphicContext& gc, const Vector& pos)
 {
-  if (!sprite)
-    return;
+  if (sprite)
+    {
+      // FIXME: HACK <- hack for what?
+      update (0.0f);
 
-  // FIXME: HACK <- hack for what?
-  update (0.0f);
+      int x = int(pos.x);
+      int y = int(pos.y);
 
-  int x = int(pos.x);
-  int y = int(pos.y);
+      switch (direction)
+        {
+        case Sprite::NONE:
+        case Sprite::LEFT:
+          gc.draw(sprite, Vector(x, y), Math::round(frame));
+          break;
 
-  switch (direction)
-    {
-    case Sprite::NONE:
-    case Sprite::LEFT:
-      gc.draw(sprite, Vector(x + x_align, y + y_align), Math::round(frame));
-      break;
+        case Sprite::RIGHT:
+          gc.draw(sprite, Vector(x, y), Math::round(frame) + max_frames ());
+          break;
 
-    case Sprite::RIGHT:
-      gc.draw(sprite, Vector(x + x_align, y + y_align), Math::round(frame) + 
max_frames ());
-      break;
-
-    default:
-      std::cout << "Direction: " << direction << std::endl;
-      assert(0);
+        default:
+          std::cout << "Direction: " << direction << std::endl;
+          assert(0);
+        }
     }
 }
 
 void
 Sprite::set_align (int arg_x, int arg_y)
 {
-  x_align = arg_x;
-  y_align = arg_y;
+  if (sprite)
+    sprite.set_alignment(origin_top_left, arg_x, arg_y);
 }
 
 void
 Sprite::set_align_center ()
 {
-  x_align = -int(sprite.get_width ())/2;
-  y_align = -int(sprite.get_height ())/2;
+  if (sprite)
+    sprite.set_alignment(origin_center);
 }
 
 void
 Sprite::set_align_center_bottom ()
 {
-  x_align = -int(sprite.get_width ())/2;
-  y_align = -int(sprite.get_height ());
+  if (sprite)
+    sprite.set_alignment(origin_bottom_center);
 }
 
 
 void
 Sprite::next_frame ()
 {
-  ++frame;
+  if (sprite)
+    {
+      ++frame;
 
-  if (Math::round(frame) >= int(sprite.get_frame_count()))
-    frame = 0;
+      if (Math::round(frame) >= int(sprite.get_frame_count()))
+        frame = 0;
+    }
 }
 
 void
 Sprite::previous_frame ()
 {
-  --frame;
+  if (sprite)
+    {
+      --frame;
 
-  if (Math::round(frame) < 0)
-    frame = sprite.get_frame_count() - 1;
+      if (Math::round(frame) < 0)
+        frame = sprite.get_frame_count() - 1;
+    }
 }
 
 
@@ -164,15 +173,22 @@
 int
 Sprite::max_frames ()
 {
-  switch (direction)
+  if (sprite)
     {
-    case NONE:
-      return sprite.get_frame_count();
-    case LEFT:
-    case RIGHT:
-      return sprite.get_frame_count()/2;
-    default:
-      assert (0);
+      switch (direction)
+        {
+        case NONE:
+          return sprite.get_frame_count();
+        case LEFT:
+        case RIGHT:
+          return sprite.get_frame_count()/2;
+        default:
+          assert (0);
+          return 0;
+        }
+    }
+  else
+    {
       return 0;
     }
 }

Modified: trunk/src/sprite.hxx
===================================================================
--- trunk/src/sprite.hxx        2004-05-06 13:21:56 UTC (rev 2302)
+++ trunk/src/sprite.hxx        2004-05-06 16:15:41 UTC (rev 2303)
@@ -43,9 +43,6 @@
   LoopType looptype;
   bool is_finished;
 
-  int x_align;
-  int y_align;
-
   int max_frames ();
 
 public:
@@ -82,12 +79,6 @@
       the bottom of the y-axis. */
   void set_align_center_bottom ();
 
-  /** Return the x alignment */
-  int get_x_align () { return x_align; }
-
-  /** Return the y alignment */
-  int get_y_align () { return y_align; }
-
   /** Go to the next frame */
   void next_frame ();
 

Modified: trunk/src/worldobjs/surface_background.cxx
===================================================================
--- trunk/src/worldobjs/surface_background.cxx  2004-05-06 13:21:56 UTC (rev 
2302)
+++ trunk/src/worldobjs/surface_background.cxx  2004-05-06 16:15:41 UTC (rev 
2303)
@@ -44,6 +44,7 @@
     std::cout << "Background: Warning dim larger than 1.0 are no longer 
supported" << std::endl;
 
   CL_Surface source_surface = PingusResource::load_surface(data->desc);
+#ifdef CLANLIB_0_6
 
   CL_PixelBuffer canvas;
 
@@ -91,7 +92,6 @@
      FIXME: the bug might be in create_canvas() and not in fill_rect()
   */
 
-#ifdef CLANLIB_0_6
   if (data->color.alpha != 0.0 && data->color != Color(0, 0, 0, 1.0f))
     { // Workaround for a bug which caused all levels to have the
       // wrong background color
@@ -100,10 +100,10 @@
                         data->color.red, data->color.green, data->color.blue,
                         data->color.alpha);
     }
+  bg_surface = CL_Surface(&canvas, false);
 #endif
+  bg_surface = source_surface;
 
-  bg_surface = CL_Surface(&canvas, false);
-
 #ifdef CLANLIB_0_6
   //bg_surface = CAImageManipulation::changeHSV(bg_surface, 150, 100, 0);
   counter.set_size(bg_surface.get_frame_count());

Modified: trunk/src/worldobjsdata/groundpiece_data.cxx
===================================================================
--- trunk/src/worldobjsdata/groundpiece_data.cxx        2004-05-06 13:21:56 UTC 
(rev 2302)
+++ trunk/src/worldobjsdata/groundpiece_data.cxx        2004-05-06 16:15:41 UTC 
(rev 2303)
@@ -59,7 +59,6 @@
 
 GroundpieceData::GroundpieceData (const GroundpieceData& old)
   : WorldObjData(old),
-    surface(old.surface),
     desc(old.desc),
     pos(old.pos),
     gptype(old.gptype)
@@ -74,7 +73,6 @@
 
   WorldObjData::operator=(old);
 
-  surface = old.surface;
   desc    = old.desc;
   pos     = old.pos;
   gptype  = old.gptype;

Modified: trunk/src/worldobjsdata/groundpiece_data.hxx
===================================================================
--- trunk/src/worldobjsdata/groundpiece_data.hxx        2004-05-06 13:21:56 UTC 
(rev 2302)
+++ trunk/src/worldobjsdata/groundpiece_data.hxx        2004-05-06 16:15:41 UTC 
(rev 2303)
@@ -37,7 +37,6 @@
 class GroundpieceData : public WorldObjData
 {
 public:
-  CL_Sprite surface;
   ResDescriptor desc;
   Vector pos;
 





reply via email to

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