windstille-devel
[Top][All Lists]
Advanced

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

[Windstille-devel] rev 405 - in trunk/src: . scripting


From: Ingo Ruhnke
Subject: [Windstille-devel] rev 405 - in trunk/src: . scripting
Date: Tue, 15 Jun 2004 15:52:11 +0200

Author: grumbel
Date: 2004-06-15 15:52:11 +0200 (Tue, 15 Jun 2004)
New Revision: 405

Added:
   trunk/src/helper.cxx
   trunk/src/helper.hxx
Modified:
   trunk/src/SConstruct
   trunk/src/blitter.cxx
   trunk/src/blitter.hxx
   trunk/src/flexlay_wrap.i
   trunk/src/gui.rb
   trunk/src/scripting/editor.cxx
   trunk/src/scripting/editor.hxx
   trunk/src/supertux.rb
   trunk/src/tile.cxx
   trunk/src/tile.hxx
   trunk/src/window.cxx
Log:
- added subimage support

Modified: trunk/src/SConstruct
===================================================================
--- trunk/src/SConstruct        2004-06-09 11:12:36 UTC (rev 404)
+++ trunk/src/SConstruct        2004-06-15 13:52:11 UTC (rev 405)
@@ -78,6 +78,7 @@
     'flexlay.cxx',
     'globals.cxx',
     'layer.cxx',
+    'helper.cxx', 
     'graphic_context_state.cxx',
     'gui_manager.cxx',
     'icon.cxx',
@@ -132,20 +133,20 @@
           'clanGUI',
           'clanGUIStyleSilver'])
 
-env.SharedLibrary(
-    target = '_flexlay_wrap.so',
-    source = [
-    'flexlay_python_wrap.cxx',
-    'scripting/editor.cxx',
-    'python_functor.cxx',
-    'python_object.cxx',
-    'python_meta_data.cxx',
-    'sexpr_parser.cxx'],
-    CPPPATH=['/home/ingo/run/ClanLib-0.7-current//include/ClanLib-0.7/',
-             '/usr/include/python2.2/',
-             '..'],
-    LIBPATH=['.', '/home/ingo/run/ClanLib-0.7-current//lib/'],
-    LIBS=['flexlay'])
+# env.SharedLibrary(
+#     target = '_flexlay_wrap.so',
+#     source = [
+#     'flexlay_python_wrap.cxx',
+#     'scripting/editor.cxx',
+#     'python_functor.cxx',
+#     'python_object.cxx',
+#     'python_meta_data.cxx',
+#     'sexpr_parser.cxx'],
+#     CPPPATH=['/home/ingo/run/ClanLib-0.7-current//include/ClanLib-0.7/',
+#              '/usr/include/python2.2/',
+#              '..'],
+#     LIBPATH=['.', '/home/ingo/run/ClanLib-0.7-current//lib/'],
+#     LIBS=['flexlay'])
 
 env.SharedLibrary(
     target = '_flexlay_ruby_wrap.so',

Modified: trunk/src/blitter.cxx
===================================================================
--- trunk/src/blitter.cxx       2004-06-09 11:12:36 UTC (rev 404)
+++ trunk/src/blitter.cxx       2004-06-15 13:52:11 UTC (rev 405)
@@ -115,4 +115,14 @@
   target.unlock();
 }
 
+void clear(CL_PixelBuffer canvas)
+{
+  unsigned char* buffer;
+
+  canvas.lock();
+  buffer = static_cast<unsigned char*>(canvas.get_data());
+  memset(buffer, 0, sizeof(unsigned char) * canvas.get_pitch() * 
canvas.get_height());
+  canvas.unlock();
+}
+
 /* EOF */

Modified: trunk/src/blitter.hxx
===================================================================
--- trunk/src/blitter.hxx       2004-06-09 11:12:36 UTC (rev 404)
+++ trunk/src/blitter.hxx       2004-06-15 13:52:11 UTC (rev 405)
@@ -23,6 +23,7 @@
 #include <ClanLib/Display/pixel_buffer.h>
 
 void blit(CL_PixelBuffer target, CL_PixelBuffer brush, int x_pos, int y_pos);
+void clear(CL_PixelBuffer target);
 
 #endif
 

Modified: trunk/src/flexlay_wrap.i
===================================================================
--- trunk/src/flexlay_wrap.i    2004-06-09 11:12:36 UTC (rev 404)
+++ trunk/src/flexlay_wrap.i    2004-06-15 13:52:11 UTC (rev 405)
@@ -50,7 +50,7 @@
 #include "objmap_path_node.hxx"
 
 #include "netpanzer.hxx" 
-#include "scripting/editor.hxx"
+#include "helper.hxx"
 
 #ifdef SWIGPYTHON
 #include "sexpr_parser.hxx"
@@ -121,6 +121,7 @@
 %include "scripting/editor.hxx"
 
 %include "netpanzer.hxx" 
+%include "helper.hxx"
 
 #ifdef SWIGPYTHON
 %include "python_meta_data.hxx"

Modified: trunk/src/gui.rb
===================================================================
--- trunk/src/gui.rb    2004-06-09 11:12:36 UTC (rev 404)
+++ trunk/src/gui.rb    2004-06-15 13:52:11 UTC (rev 405)
@@ -11,7 +11,7 @@
                                  $gui.get_component())
     @tileselector = TileSelector.new(CL_Rect.new(CL_Point.new(3, 3), 
CL_Size.new(128, 552)), @selector_window)
     @tileselector.set_tileset(tileset)
-    @tileselector.set_tiles((1..150).to_a)
+    @tileselector.set_tiles(tileset.get_tiles())
     @tileselector.show(false)
     
     @objectselector = ObjectSelector.new(CL_Rect.new(0, 0, 128, 256), 42, 42, 
@selector_window)

Added: trunk/src/helper.cxx
===================================================================
--- trunk/src/helper.cxx        2004-06-09 11:12:36 UTC (rev 404)
+++ trunk/src/helper.cxx        2004-06-15 13:52:11 UTC (rev 405)
@@ -0,0 +1,75 @@
+//  $Id$
+//
+//  Pingus - A free Lemmings clone
+//  Copyright (C) 2002 Ingo Ruhnke <address@hidden>
+//
+//  This program is free software; you can redistribute it and/or
+//  modify it under the terms of the GNU General Public License
+//  as published by the Free Software Foundation; either version 2
+//  of the License, or (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+
+#include <ClanLib/Display/sprite_description.h>
+#include <ClanLib/Display/pixel_format.h>
+#include <ClanLib/Display/Providers/provider_factory.h>
+#include <ClanLib/core.h>
+#include "blitter.hxx"
+#include "helper.hxx"
+
+CL_Sprite
+make_sprite(const std::string& filename)
+{
+  try {
+    CL_SpriteDescription desc;
+    desc.add_frame(CL_ProviderFactory::load(filename), true);
+    return CL_Sprite(desc);
+  } catch (CL_Error& err) {
+    std::cout << "CL_Error: " << err.message << std::endl;
+    return CL_Sprite();
+  }
+}
+
+CL_PixelBuffer
+make_pixelbuffer(const std::string& filename)
+{
+  try {
+    CL_PixelBuffer* ptr = CL_ProviderFactory::load(filename);
+    CL_PixelBuffer buffer(*ptr);
+    delete ptr;
+
+    return buffer;
+  } catch (CL_Error& err) {
+    std::cout << "CL_Error: " << err.message << std::endl;
+    return CL_PixelBuffer();
+  }
+}
+
+CL_PixelBuffer
+make_region_pixelbuffer(const std::string& filename, int x, int y, int w, int 
h)
+{
+  try {
+    CL_PixelBuffer* ptr = CL_ProviderFactory::load(filename);
+    CL_PixelBuffer buffer(*ptr);
+    delete ptr;
+
+    CL_PixelBuffer target(w, h, w * (buffer.get_format().get_depth()/8), 
buffer.get_format());
+    clear(target);
+    blit(target, buffer, -x, -y);
+
+    return target;
+  } catch (CL_Error& err) {
+    std::cout << "CL_Error: " << err.message << std::endl;
+    return CL_PixelBuffer();
+  }
+
+}
+
+/* EOF */

Added: trunk/src/helper.hxx
===================================================================
--- trunk/src/helper.hxx        2004-06-09 11:12:36 UTC (rev 404)
+++ trunk/src/helper.hxx        2004-06-15 13:52:11 UTC (rev 405)
@@ -0,0 +1,32 @@
+//  $Id$
+// 
+//  Pingus - A free Lemmings clone
+//  Copyright (C) 2002 Ingo Ruhnke <address@hidden>
+//
+//  This program is free software; you can redistribute it and/or
+//  modify it under the terms of the GNU General Public License
+//  as published by the Free Software Foundation; either version 2
+//  of the License, or (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+// 
+//  You should have received a copy of the GNU General Public License
+//  along with this program; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+
+#ifndef HEADER_HELPER_HXX
+#define HEADER_HELPER_HXX
+
+#include <ClanLib/Display/sprite.h>
+#include <ClanLib/Display/pixel_buffer.h>
+
+CL_Sprite      make_sprite(const std::string& filename);
+CL_PixelBuffer make_pixelbuffer(const std::string& filename);
+CL_PixelBuffer make_region_pixelbuffer(const std::string& filename, int x, int 
y, int w, int h);
+
+#endif
+
+/* EOF */

Modified: trunk/src/scripting/editor.cxx
===================================================================
--- trunk/src/scripting/editor.cxx      2004-06-09 11:12:36 UTC (rev 404)
+++ trunk/src/scripting/editor.cxx      2004-06-15 13:52:11 UTC (rev 405)
@@ -17,9 +17,8 @@
 //  along with this program; if not, write to the Free Software
 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
-#include <ClanLib/Display/sprite_description.h>
-#include <ClanLib/Display/Providers/provider_factory.h>
 #include <ClanLib/Signals/signal_v0.h>
+#include "../blitter.hxx"
 #include "../python_functor.hxx"
 #include "editor.hxx"
 
@@ -43,15 +42,6 @@
   new CL_Slot(sig.connect_functor(PythonFunctor(obj)));
 }
 
-CL_Sprite
-make_sprite(const std::string& filename)
-{
-  CL_SpriteDescription desc;
-  desc.add_frame(CL_ProviderFactory::load(filename), true);
-  return CL_Sprite(desc);
-}
-
-
 /*
 Tile
 make_tile(const char* filename, 

Modified: trunk/src/scripting/editor.hxx
===================================================================
--- trunk/src/scripting/editor.hxx      2004-06-09 11:12:36 UTC (rev 404)
+++ trunk/src/scripting/editor.hxx      2004-06-15 13:52:11 UTC (rev 405)
@@ -35,7 +35,6 @@
 void connect_v2(CL_Signal_v2<int, int>& sig, PyObject* obj);
 #endif
 
-CL_Sprite make_sprite(const std::string& filename);
 /*Tile make_tile(const char* filename, 
   unsigned char red, unsigned char green, unsigned char blue, unsigned char 
alpha);*/
 

Modified: trunk/src/supertux.rb
===================================================================
--- trunk/src/supertux.rb       2004-06-09 11:12:36 UTC (rev 404)
+++ trunk/src/supertux.rb       2004-06-15 13:52:11 UTC (rev 405)
@@ -125,7 +125,7 @@
   def load(filename)
     tree = sexpr_read_from_file(filename)
     tree = tree[1..-1]
-    for i in tree
+    tree.each do |i|
       if i[0] == "tile"
         data  = i[1..-1]
         id    = get_value_from_tree(['id', '_'], data, -1)
@@ -136,9 +136,16 @@
         end
         
         if id != 0 # leave tile 0 transparent
-          add_tile(id,
-                   Tile.new($datadir + 'images/tilesets/' + image,
-                            CL_Color.new(255,   0,   0, 128)))
+          if image.is_a?(String) then
+            pixelbuffer = make_pixelbuffer($datadir + 'images/tilesets/' + 
image)
+          elsif image.is_a?(Array) then
+            if image[0] == "region" then
+              pixelbuffer = make_region_pixelbuffer($datadir + 
'images/tilesets/' + image[1],
+                                                    image[2], image[3], 
image[4], image[5])
+            end
+          end
+          
+          add_tile(id, Tile.new(pixelbuffer))
         end
       end
     end
@@ -160,7 +167,7 @@
   ["bouncingsnowball", "images/shared/bouncingsnowball-left-0.png", 
proc{|data| BadGuy.new("bouncingsnowball")}],
   ["spiky", "images/shared/spiky-left-0.png", proc{|data| 
BadGuy.new("spiky")}],
   ["playerspawn", "images/shared/resetpoint.png", proc{|data| 
SpawnPoint.new(data)}],
-  ["door", "images/shared/door.png", proc{|data| Door.new(data)}],
+  ["door", "images/shared/door-1.png", proc{|data| Door.new(data)}],
   ["trampoline", "images/shared/trampoline-1.png", proc{|data| 
BadGuy.new("trampoline")}]
 ]
 

Modified: trunk/src/tile.cxx
===================================================================
--- trunk/src/tile.cxx  2004-06-09 11:12:36 UTC (rev 404)
+++ trunk/src/tile.cxx  2004-06-15 13:52:11 UTC (rev 405)
@@ -47,6 +47,13 @@
   std::string filename;
 };
 
+Tile::Tile(const CL_PixelBuffer& pixelbuffer)
+  : impl(new TileImpl())
+{
+  impl->pixelbuffer = pixelbuffer;
+  impl->has_color = false;
+}
+
 Tile::Tile(const std::string& filename_, 
            const CL_Color& attribute_color_)
   : impl(new TileImpl())
@@ -90,23 +97,11 @@
     }
   else
     {
-      try {
-        //std::cout << "Loading Tile: " << filename << std::endl;
-        if (has_suffix(impl->filename, ".png") || has_suffix(impl->filename, 
".jpg"))
-          {
-            CL_SpriteDescription desc;
-            desc.add_frame(new CL_PixelBuffer(get_pixelbuffer()), true);
-            impl->sur = CL_Sprite(desc);
-          }
-        else
-          {
-            assert(0);  //impl->sur = CL_Sprite(impl->filename, resources);
-          }
-        return impl->sur;
-      } catch (CL_Error& err) {
-        std::cout << "Tile: CL_Error: " << err.message << std::endl;
-        assert(0);
-      }
+      CL_SpriteDescription desc;
+      desc.add_frame(new CL_PixelBuffer(get_pixelbuffer()), true);
+      impl->sur = CL_Sprite(desc);
+      
+      return impl->sur;
     }
 }
 
@@ -115,20 +110,23 @@
 {      
   try {
     if (impl->pixelbuffer)
-      return impl->pixelbuffer;
-    {
-      if (has_suffix(impl->filename, ".png") || has_suffix(impl->filename, 
".jpg"))
-        {
-          impl->pixelbuffer = 
CL_PixelBuffer(*CL_ProviderFactory::load(impl->filename));
-        }
-      else
-        {
-          //CL_SpriteDescription descr(impl->filename, resources);
-          //impl->pixelbuffer = 
CL_PixelBuffer(*(descr.get_frames().begin()->first));
-          assert(0);
-        }
-      return impl->pixelbuffer;
-    }
+      {
+        return impl->pixelbuffer;
+      }
+    else 
+      {
+        if (has_suffix(impl->filename, ".png") || has_suffix(impl->filename, 
".jpg"))
+          {
+            impl->pixelbuffer = 
CL_PixelBuffer(*CL_ProviderFactory::load(impl->filename));
+          }
+        else
+          {
+            //CL_SpriteDescription descr(impl->filename, resources);
+            //impl->pixelbuffer = 
CL_PixelBuffer(*(descr.get_frames().begin()->first));
+            assert(0);
+          }
+        return impl->pixelbuffer;
+      }
   } catch(CL_Error& err) {
     std::cout << "CL_Error: " << err.message << std::endl;
     std::cout << "          filename = " << impl->filename << std::endl;

Modified: trunk/src/tile.hxx
===================================================================
--- trunk/src/tile.hxx  2004-06-09 11:12:36 UTC (rev 404)
+++ trunk/src/tile.hxx  2004-06-15 13:52:11 UTC (rev 405)
@@ -32,6 +32,8 @@
 class Tile
 {
 public:
+  Tile(const CL_PixelBuffer& pixelbuffer);
+
   /** @param filename Surface to use 
    *  @param arg_colmap a 8 char long array */
   Tile(const std::string& filename, 

Modified: trunk/src/window.cxx
===================================================================
--- trunk/src/window.cxx        2004-06-09 11:12:36 UTC (rev 404)
+++ trunk/src/window.cxx        2004-06-15 13:52:11 UTC (rev 405)
@@ -27,17 +27,10 @@
 #include "box.hxx"
 #include "fonts.hxx"
 #include "icon.hxx"
+#include "helper.hxx"
 #include "titlebar.hxx"
 #include "window.hxx"
 
-CL_Sprite
-make_sprite(const std::string& filename)
-{
-  CL_SpriteDescription desc;
-  desc.add_frame(CL_ProviderFactory::load(filename), true);
-  return CL_Sprite(desc);
-}
-
 class WindowImpl
 {
 public:





reply via email to

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