pingus-cvs
[Top][All Lists]
Advanced

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

[Pingus-CVS] CVS: Games/Pingus/src/backgrounds surface_background.cxx,1.


From: grumbel
Subject: [Pingus-CVS] CVS: Games/Pingus/src/backgrounds surface_background.cxx,1.3,1.4
Date: 24 Jun 2002 09:41:01 -0000

Update of /usr/local/cvsroot/Games/Pingus/src/backgrounds
In directory dark:/tmp/cvs-serv27281/backgrounds

Modified Files:
        surface_background.cxx 
Log Message:
- fixed a bug in the blitter code which caused some backgrounds to become 
completly transparent
- added background scaling support
- rewrote some parts of the walker code, should be less stucky now
- fixed the bridger so that it doesn't get stuck in walls and so that walkers 
can walk over a bridge which was stopped by a headbump

Index: surface_background.cxx
===================================================================
RCS file: 
/usr/local/cvsroot/Games/Pingus/src/backgrounds/surface_background.cxx,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- surface_background.cxx      22 Jun 2002 14:29:18 -0000      1.3
+++ surface_background.cxx      24 Jun 2002 09:40:59 -0000      1.4
@@ -19,6 +19,7 @@
 
 #include <ClanLib/Display/SurfaceProviders/canvas.h>
 #include <ClanLib/Display/Display/display.h>
+#include "../world.hxx"
 #include "../timer.hxx"
 #include "../pingus_resource.hxx"
 #include "../globals.hxx"
@@ -26,6 +27,7 @@
 #include "surface_background.hxx"
 
 SurfaceBackground::SurfaceBackground(const SurfaceBackgroundData& bg_data)
+  : SurfaceBackgroundData (bg_data)
 {
   Timer timer;
 
@@ -43,33 +45,40 @@
   /*std::cout << "Res: " << bg_data.desc.res_name << std::endl
     << "file: " << bg_data.desc.datafile << std::endl;*/
 
-  if (background_manipulation_enabled && bg_data.color.alpha != 0.0
-      && bg_data.color != Color (0, 0, 0, 1.0f)) // Workaround for a
-                                                // bug which caused
-                                                // all levels to have
-                                                // the wrong
-                                                // background color
+  if (background_manipulation_enabled)
     {
       std::cout << "------ SurfaceBackground:: Manipulating background ------" 
<< std::endl;
-      // FIXME: This is extremly buggy and it will crash, no idea why....
       CL_Surface source_surface = PingusResource::load_surface(bg_data.desc);
       
-      // FIXME: Scaling not implemented
+      CL_Canvas* canvas;
+
+      // Scaling Code
+      if (stretch_x && stretch_y)
+       canvas = Blitter::scale_surface_to_canvas(source_surface, 
world->get_width (), world->get_height ());
+      else if (stretch_x && !stretch_y)
+       canvas = Blitter::scale_surface_to_canvas(source_surface, 
world->get_width (), source_surface.get_height ());
+      else if (!stretch_x && stretch_y)
+       canvas = Blitter::scale_surface_to_canvas(source_surface, 
source_surface.get_width (), world->get_height ());
+      else
+       canvas = Blitter::create_canvas(source_surface);
 
-      CL_Canvas* canvas = Blitter::create_canvas(source_surface);
       /* FIXME: fill_rect doesn't work with RGB images
         FIXME: seems to work fine with indexed images
         FIXME: not tested with RGBA images
         FIXME: the bug might be in create_canvas() and not in fill_rect()
-       */
-      canvas->fill_rect(0, 0, 
-                       canvas->get_width(), canvas->get_height(),
-                       bg_data.color.red, bg_data.color.green, 
bg_data.color.blue, 
-                       bg_data.color.alpha);
+      */
+    
+      if (bg_data.color.alpha != 0.0 && bg_data.color != Color (0, 0, 0, 1.0f))
+       { // Workaround for a bug which caused all levels to have the
+         // wrong background color
+         canvas->fill_rect(0, 0, 
+                           canvas->get_width(), canvas->get_height(),
+                           bg_data.color.red, bg_data.color.green, 
bg_data.color.blue, 
+                           bg_data.color.alpha);
+       }
       
-      // FIXME: Sat Jul 21 21:57:15 2001
-      //std::cout << "BUG: Stuff removed because of linker error" << std::endl;
       bg_surface = CL_Surface (canvas, true);
+      std::cout << "Surface: " << bg_surface.get_width () << " " << 
bg_surface.get_height () << std::endl;
     }
   else
     {
@@ -80,17 +89,6 @@
   counter.set_size(bg_surface.get_num_frames());
   counter.set_speed(1.0);
 
-  stretch_x = bg_data.stretch_x;
-  stretch_y = bg_data.stretch_y;
-
-  scroll_x = bg_data.scroll_x;
-  scroll_y = bg_data.scroll_y;
-
-  para_x = bg_data.para_x;
-  para_y = bg_data.para_y;
-
-  pos = bg_data.pos;
-
   scroll_ox = 0;
   scroll_oy = 0;
 
@@ -107,64 +105,64 @@
 SurfaceBackground::~SurfaceBackground()
 {
   /*
-  std::cout << "Background:~Background" << std::endl;
+    std::cout << "Background:~Background" << std::endl;
 
-  if (surface_need_deletion) {
+    if (surface_need_deletion) {
     //std::cout << "Background: Deleting background surface" << std::endl;
     // FIXME: We are /not/ deleting the surface here cause that gives
     // a segfault if the next level is loaded, I have absolutly no
     // idea why. So we have a memory hole here
     //delete bg_surface;
-  }
+    }
   */
 }
 
 /*
-void
-SurfaceBackground::load (SurfaceBackgroundData bg_data)
-{
+  void
+  SurfaceBackground::load (SurfaceBackgroundData bg_data)
+  {
   surface_need_deletion = false;
 
   if (bg_data.color.alpha > 1.0) 
-    std::cout << "Background: Warning dim larger than 1.0 are no longer 
supported" << std::endl;
+  std::cout << "Background: Warning dim larger than 1.0 are no longer 
supported" << std::endl;
   
   // Testing animatied backgrounds...
   std::cout << "Res: " << bg_data.desc.res_name << std::endl
-           << "file: " << bg_data.desc.datafile << std::endl;
+  << "file: " << bg_data.desc.datafile << std::endl;
 
   if (bg_data.desc.res_name == "none")
-    {
-      std::cout << "Background: No surface set..." << std::endl;
-      bg_surface = 0;
-    }
+  {
+  std::cout << "Background: No surface set..." << std::endl;
+  bg_surface = 0;
+  }
   else
-    {
-      if (background_manipulation_enabled)
-       {
-         // FIXME: This is extremly buggy and it will crash, no idea why....
-         CL_Surface* source_surface = 
PingusResource::load_surface(bg_data.desc);
+  {
+  if (background_manipulation_enabled)
+  {
+  // FIXME: This is extremly buggy and it will crash, no idea why....
+  CL_Surface* source_surface = PingusResource::load_surface(bg_data.desc);
 
-         CL_Canvas* canvas = new CL_Canvas(source_surface->get_width(),
-                                           source_surface->get_height());/// 
Blitter::create_canvas(source_surface);
-         source_surface->put_target(0, 0, 0, canvas);
-         canvas->fill_rect(0, 0, canvas->get_width(), canvas->get_height(),
-                           bg_data.color.red, bg_data.color.green, 
bg_data.color.blue, 
-                           bg_data.color.alpha);
-         bg_surface = CL_Surface::create(canvas, true);
-       }
-      else
-       {
-         bg_surface = PingusResource::load_surface(bg_data.desc);
-       }
-    }
+  CL_Canvas* canvas = new CL_Canvas(source_surface->get_width(),
+  source_surface->get_height());/// Blitter::create_canvas(source_surface);
+  source_surface->put_target(0, 0, 0, canvas);
+  canvas->fill_rect(0, 0, canvas->get_width(), canvas->get_height(),
+  bg_data.color.red, bg_data.color.green, bg_data.color.blue, 
+  bg_data.color.alpha);
+  bg_surface = CL_Surface::create(canvas, true);
+  }
+  else
+  {
+  bg_surface = PingusResource::load_surface(bg_data.desc);
+  }
+  }
 
   if (bg_surface) 
-    {
-      //bg_surface = CAImageManipulation::changeHSV(bg_surface, 150, 100, 0);
+  {
+  //bg_surface = CAImageManipulation::changeHSV(bg_surface, 150, 100, 0);
 
-      counter.set_size(bg_surface->get_num_frames());
-      counter.set_speed(1.0);
-    }
+  counter.set_size(bg_surface->get_num_frames());
+  counter.set_speed(1.0);
+  }
 
   stretch_x = bg_data.stretch_x;
   stretch_y = bg_data.stretch_y;
@@ -179,11 +177,11 @@
   scroll_oy = 0;
 
   if (verbose > 1)
-    {
-      std::cout << "Background: Stretch_X: " << stretch_x << std::endl;
-      std::cout << "Background: Stretch_Y: " << stretch_y << std::endl;
-    }
-}
+  {
+  std::cout << "Background: Stretch_X: " << stretch_x << std::endl;
+  std::cout << "Background: Stretch_Y: " << stretch_y << std::endl;
+  }
+  }
 */
 void
 SurfaceBackground::update(float /*delta*/)




reply via email to

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