windstille-devel
[Top][All Lists]
Advanced

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

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


From: Ingo Ruhnke
Subject: [Windstille-devel] rev 317 - in trunk/src: . scripting
Date: Fri, 14 May 2004 02:04:06 +0200

Author: grumbel
Date: 2004-05-14 02:04:06 +0200 (Fri, 14 May 2004)
New Revision: 317

Modified:
   trunk/src/SConstruct
   trunk/src/editor_main.cxx
   trunk/src/editor_tilemap.cxx
   trunk/src/editor_tilemap.hxx
   trunk/src/flexlay_python.cxx
   trunk/src/minimap.cxx
   trunk/src/objmap_select_tool.cxx
   trunk/src/objmap_sprite_object.hxx
   trunk/src/scm_functor.cxx
   trunk/src/scm_helper.hxx
   trunk/src/scm_obj.hxx
   trunk/src/scripting/editor.cxx
   trunk/src/scripting/editor.hxx
   trunk/src/scripting/netpanzer.cxx
   trunk/src/tile.cxx
   trunk/src/tile.hxx
   trunk/src/tilemap_paint_tool.cxx
   trunk/src/tileset.cxx
   trunk/src/tileset.hxx
Log:
- some more fixing for the python bindings, moved guile specific stuff into 
defines

Modified: trunk/src/SConstruct
===================================================================
--- trunk/src/SConstruct        2004-05-13 18:49:34 UTC (rev 316)
+++ trunk/src/SConstruct        2004-05-14 00:04:06 UTC (rev 317)
@@ -1,8 +1,8 @@
 ## -*- mode: python -*-
 
 BuildDir('build', '.', duplicate=0)
-env = Environment(CC = 'g++',
-                  CCFLAGS = '-O2 -Wall')
+env = Environment(CXX = 'g++-3.3',
+                  CCFLAGS = '-g -O2 -Wall')
 
 env.SharedLibrary(
     'hellopy',
@@ -15,6 +15,7 @@
     source = [
     'build/command_group.cxx',
     'build/editor.cxx',
+    'build/scripting/editor.cxx',
     'build/editor_grid_layer.cxx',
     'build/editor_map.cxx',
     'build/editor_map_component.cxx',

Modified: trunk/src/editor_main.cxx
===================================================================
--- trunk/src/editor_main.cxx   2004-05-13 18:49:34 UTC (rev 316)
+++ trunk/src/editor_main.cxx   2004-05-14 00:04:06 UTC (rev 317)
@@ -23,7 +23,9 @@
 #include <ClanLib/gl.h>
 #include <ClanLib/sdl.h>
 #include <ClanLib/display.h>
-#include <guile/gh.h>
+#ifdef SWIGGUILE
+#  include <guile/gh.h>
+#endif
 #include "editor.hxx"
 #include "globals.hxx"
 #include "tileset.hxx"

Modified: trunk/src/editor_tilemap.cxx
===================================================================
--- trunk/src/editor_tilemap.cxx        2004-05-13 18:49:34 UTC (rev 316)
+++ trunk/src/editor_tilemap.cxx        2004-05-14 00:04:06 UTC (rev 317)
@@ -36,8 +36,8 @@
 
 EditorTileMap* EditorTileMap::current_ = 0;
 
-EditorTileMap::EditorTileMap(Tileset* tileset_, int w, int h, int tile_size_)
-  : tile_size(tile_size_), field(w, h)
+EditorTileMap::EditorTileMap(Tileset* tileset_, int w, int h)
+  : field(w, h)
 {
   // FIXME: Move this to the widget or to some more generic
   // map-properties thingy
@@ -77,7 +77,8 @@
       sprite.draw (x, y);
       
       if (attribute)
-        CL_Display::fill_rect(CL_Rect(CL_Point(x, y), CL_Size(tile_size, 
tile_size)),
+        CL_Display::fill_rect(CL_Rect(CL_Point(x, y), 
CL_Size(tileset->get_tile_size(),
+                                                              
tileset->get_tile_size())),
                               tile->get_attribute_color());
     }
 }
@@ -85,48 +86,45 @@
 void
 EditorTileMap::draw(EditorMapComponent* parent)
 {
+  int tile_size = tileset->get_tile_size();
+
   if (background_color.get_alpha() != 0)
     CL_Display::fill_rect(CL_Rect(CL_Point(0,0),
-                                  CL_Size(field.get_width() * tile_size,
+                                  CL_Size(field.get_width()  * tile_size,
                                           field.get_height() * tile_size)),
                           background_color);
   CL_Display::flush();
 
   CL_Rect rect = parent->get_clip_rect();
 
-  int start_x = std::max(0, rect.left/tile_size);
-  int start_y = std::max(0, rect.top/tile_size);
-  int end_x   = std::min(field.get_width(),  rect.right/tile_size + 1);
-  int end_y   = std::min(field.get_height(), rect.bottom/tile_size + 1);
+  int start_x = std::max(0, rect.left / tile_size);
+  int start_y = std::max(0, rect.top  / tile_size);
+  int end_x   = std::min(field.get_width(),  rect.right  / tile_size + 1);
+  int end_y   = std::min(field.get_height(), rect.bottom / tile_size + 1);
 
   for (int y = start_y; y < end_y; ++y)
     for (int x = start_x; x < end_x; ++x)
       {
         draw_tile(field.at(x, y), 
-                  x * tile_size, y * tile_size, 
+                  x * tile_size, y * tile_size,
                   draw_attribute);
       }
 
-  if (draw_grid)
+  if (1 || draw_grid)
     {
       for (int y = start_y; y <= end_y; ++y)
         CL_Display::draw_line(start_x * tile_size,
-                              y * tile_size,
+                              y       * tile_size,
                               end_x   * tile_size,
-                              y * tile_size, 
-                              y % 5 ?
-                              CL_Color(150, 150, 150) :
-                              CL_Color(255, 255, 255)
-                              );
+                              y       * tile_size, 
+                              y % 5 ? CL_Color(150, 150, 150) : CL_Color(255, 
255, 255));
   
       for (int x = start_x; x <= end_x; ++x)
-        CL_Display::draw_line(x * tile_size,
+        CL_Display::draw_line(x       * tile_size,
                               start_y * tile_size,
-                              x   * tile_size,
-                              end_y * tile_size, 
-                              x % 5 ?
-                              CL_Color(150, 150, 150) :
-                              CL_Color(255, 255, 255));
+                              x       * tile_size,
+                              end_y   * tile_size, 
+                              x % 5 ? CL_Color(150, 150, 150) : CL_Color(255, 
255, 255));
     }
 
   CL_Display::flush();
@@ -298,20 +296,22 @@
   target.unlock();
 }
 
-CL_PixelBuffer*
+CL_PixelBuffer
 EditorTileMap::create_pixelbuffer()
 {
-  CL_PixelBuffer* pixelbuffer = new CL_PixelBuffer(get_width()  * tile_size,
-                                                   get_height() * tile_size,
-                                                   get_width()  * tile_size * 
4,
-                                                   CL_PixelFormat::rgba8888);
+  int tile_size = tileset->get_tile_size();
 
+  CL_PixelBuffer pixelbuffer(get_width()  * tile_size,
+                             get_height() * tile_size,
+                             get_width()  * tile_size * 4,
+                             CL_PixelFormat::rgba8888);
+
   {
-    pixelbuffer->lock();
-    unsigned char* buf = static_cast<unsigned char*>(pixelbuffer->get_data());
+    pixelbuffer.lock();
+    unsigned char* buf = static_cast<unsigned char*>(pixelbuffer.get_data());
 
-    int width  = pixelbuffer->get_width();
-    int height = pixelbuffer->get_height();
+    int width  = pixelbuffer.get_width();
+    int height = pixelbuffer.get_height();
 
     // Draw a nice gradient
     for(int y = 0; y < height; ++y)
@@ -324,7 +324,7 @@
             buf[4*(y*width + x) + 3] = 255*y/height;
           }
       }
-    pixelbuffer->unlock();
+    pixelbuffer.unlock();
   }
 
   for (int y = 0; y < get_height(); ++y)
@@ -334,10 +334,10 @@
 
         if (tile)
           {
-            CL_PixelBuffer* buf = tile->get_pixelbuffer();
+            CL_PixelBuffer buf = tile->get_pixelbuffer();
             if (buf)
               {
-                blit(*pixelbuffer, *buf, x*tile_size, y*tile_size);
+                blit(pixelbuffer, buf, x*tile_size, y*tile_size);
               }
           }
       }
@@ -349,14 +349,15 @@
 EditorTileMap::get_bounding_rect()
 {
   return CL_Rect(CL_Point(0, 0),
-                 CL_Size(field.get_width() * tile_size, field.get_height() * 
tile_size));
+                 CL_Size(field.get_width()  * tileset->get_tile_size(), 
+                         field.get_height() * tileset->get_tile_size()));
 }
 
 CL_Point
 EditorTileMap::world2tile(const CL_Point& pos) const
 {
-  int x = pos.x/tile_size;
-  int y = pos.y/tile_size;
+  int x = pos.x / tileset->get_tile_size();
+  int y = pos.y / tileset->get_tile_size();
 
   return CL_Point(pos.x < 0 ? x-1 : x,
                   pos.y < 0 ? y-1 : y);

Modified: trunk/src/editor_tilemap.hxx
===================================================================
--- trunk/src/editor_tilemap.hxx        2004-05-13 18:49:34 UTC (rev 316)
+++ trunk/src/editor_tilemap.hxx        2004-05-14 00:04:06 UTC (rev 317)
@@ -37,7 +37,6 @@
   Tileset* tileset;
   CL_Color background_color;
   CL_Color foreground_color;
-  int tile_size;
   bool hex_mode;
 
   Field<int> field;
@@ -50,7 +49,7 @@
   static EditorTileMap* current() { return current_; }
   static void set_current(EditorTileMap* c) { current_ = c; }
   
-  EditorTileMap(Tileset* tileset, int w,  int h, int tile_size_);
+  EditorTileMap(Tileset* tileset, int w,  int h);
   ~EditorTileMap();
 
   void draw (EditorMapComponent* parent);
@@ -90,12 +89,10 @@
   void set_draw_grid(bool t);
   bool get_draw_grid() const;
 
-  CL_PixelBuffer* create_pixelbuffer();
+  CL_PixelBuffer create_pixelbuffer();
 
   static void draw_tile(Field<int>* field, const TileBrush& brush, const 
CL_Point& pos);
 
-  int get_tile_size() const { return tile_size; }
-
   bool has_bounding_rect() const { return true; }
   CL_Rect get_bounding_rect();
 

Modified: trunk/src/flexlay_python.cxx
===================================================================
--- trunk/src/flexlay_python.cxx        2004-05-13 18:49:34 UTC (rev 316)
+++ trunk/src/flexlay_python.cxx        2004-05-14 00:04:06 UTC (rev 317)
@@ -7,6 +7,8 @@
 #include <boost/python.hpp>
 #include <iostream>
 
+#include "scripting/editor.hxx"
+#include "tile.hxx"
 #include "editor.hxx"
 #include "editor_map.hxx"
 #include "workspace.hxx"
@@ -38,7 +40,8 @@
 
   def("flexlay_init",   &flexlay_init);
   def("flexlay_deinit", &flexlay_deinit);
-
+  def("editor_set_brush_tile", editor_set_brush_tile);
+  
   register_exception_translator<CL_Error>(&clerror_translator);
 
   class_<GUIManager>("GUIManager")
@@ -99,13 +102,25 @@
     .def("set_zoom",      &EditorMapComponent::set_zoom)
     .def("set_workspace", &EditorMapComponent::set_workspace);
 
+  class_<CL_Color>("Color", init<int, int, int, int>())
+    .add_property("red",   &CL_Color::set_red,   &CL_Color::set_red)
+    .add_property("green", &CL_Color::set_green, &CL_Color::set_green)
+    .add_property("blue",  &CL_Color::set_blue,  &CL_Color::set_blue)
+    .add_property("alpha", &CL_Color::set_alpha, &CL_Color::set_alpha);
+
+  class_<Tile>("Tile", init<std::string, CL_Color, CL_Color>());
+
   class_<Tileset>("Tileset", init<int>())
-    .def("get_tilesize", &Tileset::get_tile_size);
+    .def("get_tilesize", &Tileset::get_tile_size)
+    .def("add_tile",     &Tileset::add_tile);
 
   class_<EditorTileMap, bases<EditorMapLayer>, EditorTileMap, 
boost::noncopyable>
-    ("TileMap", init<Tileset*, int, int, int>())
+    ("TileMap", init<Tileset*, int, int>())
     .def("get_tile", &EditorTileMap::get_tile)
     .def("resize",   &EditorTileMap::resize);
+
+  def("tilemap_set_current", &EditorTileMap::set_current);
+  def("tilemap_paint_tool_set_tilemap", &tilemap_paint_tool_set_tilemap);
 }
 
 /* EOF */

Modified: trunk/src/minimap.cxx
===================================================================
--- trunk/src/minimap.cxx       2004-05-13 18:49:34 UTC (rev 316)
+++ trunk/src/minimap.cxx       2004-05-14 00:04:06 UTC (rev 317)
@@ -67,7 +67,7 @@
 
   // FIXME: This doesn't work all that well
   EditorTileMap* tilemap = EditorTileMap::current();
-  int tile_size = tilemap->get_tile_size();
+  int tile_size = tilemap->get_tileset()->get_tile_size();
 
   if (tilemap && tilemap->get_height() != 0 && tilemap->get_width() != 0)
     {
@@ -156,7 +156,7 @@
 {
   // FIXME: This doesn't work all that well
   EditorTileMap* tilemap = EditorTileMap::current();
-  int tile_size  = tilemap->get_tile_size();
+  int tile_size  = tilemap->get_tileset()->get_tile_size();
   int map_width  = tilemap->get_width()  * tile_size;
   int map_height = tilemap->get_height() * tile_size;
 
@@ -170,7 +170,7 @@
 {
   // FIXME: This doesn't work all that well
   EditorTileMap* tilemap = EditorTileMap::current();
-  int tile_size  = tilemap->get_tile_size();
+  int tile_size  = tilemap->get_tileset()->get_tile_size();
   int map_width  = tilemap->get_width()  * tile_size;
   int map_height = tilemap->get_height() * tile_size;
 

Modified: trunk/src/objmap_select_tool.cxx
===================================================================
--- trunk/src/objmap_select_tool.cxx    2004-05-13 18:49:34 UTC (rev 316)
+++ trunk/src/objmap_select_tool.cxx    2004-05-14 00:04:06 UTC (rev 317)
@@ -25,7 +25,9 @@
 #include "editor_map.hxx"
 #include "editor_map_component.hxx"
 #include "gui_manager.hxx"
+#ifdef SWIGGUILE
 #include "scm_obj.hxx"
+#endif
 #include "editor_names.hxx"
 #include "popup_menu.hxx"
 #include "editor.hxx"

Modified: trunk/src/objmap_sprite_object.hxx
===================================================================
--- trunk/src/objmap_sprite_object.hxx  2004-05-13 18:49:34 UTC (rev 316)
+++ trunk/src/objmap_sprite_object.hxx  2004-05-14 00:04:06 UTC (rev 317)
@@ -32,8 +32,8 @@
 public:
   ObjMapSpriteObject(int handle_, 
                      const CL_Point& pos_, 
-#ifdef SWIGGUILEconst 
-                     SCMObj& data_, 
+#ifdef SWIGGUILE
+                     const SCMObj& data_, 
 #endif
                      const CL_Sprite& s);
   ObjMapSpriteObject(int handle_, const ObjMapSpriteObject& obj);

Modified: trunk/src/scm_functor.cxx
===================================================================
--- trunk/src/scm_functor.cxx   2004-05-13 18:49:34 UTC (rev 316)
+++ trunk/src/scm_functor.cxx   2004-05-14 00:04:06 UTC (rev 317)
@@ -18,7 +18,9 @@
 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 #include <iostream>
+#ifdef SWIGGUILE
 #include <libguile.h>
+#endif
 #include "scm_functor.hxx"
 
 SCMFunctor::SCMFunctor(SCM arg_func)

Modified: trunk/src/scm_helper.hxx
===================================================================
--- trunk/src/scm_helper.hxx    2004-05-13 18:49:34 UTC (rev 316)
+++ trunk/src/scm_helper.hxx    2004-05-14 00:04:06 UTC (rev 317)
@@ -20,10 +20,14 @@
 #ifndef HEADER_SCM_HELPER_HXX
 #define HEADER_SCM_HELPER_HXX
 
-#include <guile/gh.h>
+#ifdef SWIGGUILE
+# include <guile/gh.h>
+#endif
 #include <string>
 
+#ifdef SWIGGUILE
 std::string scm2string(SCM str);
+#endif
 
 #endif
 

Modified: trunk/src/scm_obj.hxx
===================================================================
--- trunk/src/scm_obj.hxx       2004-05-13 18:49:34 UTC (rev 316)
+++ trunk/src/scm_obj.hxx       2004-05-14 00:04:06 UTC (rev 317)
@@ -20,7 +20,9 @@
 #ifndef SCMOBJ_HXX
 #define SCMOBJ_HXX
 
+#ifdef SWIGGUILE
 #include <guile/gh.h>
+#endif
 
 /** SCM Wrapper class which handles protect/unprotect operations. Use
     this for SCM which are on the heap and not for SCM's on the

Modified: trunk/src/scripting/editor.cxx
===================================================================
--- trunk/src/scripting/editor.cxx      2004-05-13 18:49:34 UTC (rev 316)
+++ trunk/src/scripting/editor.cxx      2004-05-14 00:04:06 UTC (rev 317)
@@ -45,12 +45,12 @@
 #include "../tilemap_paint_tool.hxx"
 #include "../minimap.hxx"
 #include "../editor_names.hxx"
-#include "tileset.hxx"
-#include "tile.hxx"
+#include "../tileset.hxx"
+#include "../tile.hxx"
 #include "../tool_manager.hxx"
 #include "../object_delete_command.hxx"
 #include "../object_add_command.hxx"
-#include "gui_manager.hxx"
+#include "../gui_manager.hxx"
 #include "../workspace.hxx"
 
 #include "../editor_map.hxx"
@@ -66,7 +66,7 @@
 
 extern CL_ResourceManager* resources;
 
-
+#ifdef SWIGGUILE
 std::vector<int>
 scm2vector(SCM lst)
 {
@@ -86,6 +86,7 @@
   }
   return gh_reverse(lst);
 }
+#endif
 
 void
 game_load_resources(const char* resourcefile)
@@ -149,52 +150,10 @@
 }
 #endif
 
+#ifdef SWIGGUILE
 int
-objectmap_add_object(EditorMapLayer* obj, const char* filename, int x, int y, 
SCM userdata)
+objectmap_add_object(EditorMapLayer* layer, const char* filename, int x, int 
y, SCM userdata)
 {
-  EditorObjMap* objmap = dynamic_cast<EditorObjMap*>(obj);
-
-  if (objmap)
-    {
-      try {
-        CL_Sprite sprite;
-
-        if (has_suffix(filename, ".png") || has_suffix(filename, ".jpg"))
-          {
-            CL_SpriteDescription desc;
-            desc.add_frame(CL_ProviderFactory::load(filename), true);
-            sprite = CL_Sprite(desc);
-            //sprite.set_alignment(origin_bottom_center, -16, -32);
-          }
-        else
-          {
-            sprite = CL_Sprite(filename, resources);
-          }        
-
-        ObjMapObject* obj 
-          = new ObjMapSpriteObject(objmap->get_next_object_handle(), 
-                                   CL_Point(x, y), 
-                                   SCMObj(userdata), 
-                                   sprite);
-
-        ObjectAddCommand* command = new ObjectAddCommand(objmap, obj);
-        Editor::current()->execute(command);
-      
-        return command->get_handle();
-      } catch(CL_Error& err) {
-        std::cout << "Error: " << err.message << std::endl;
-        return -1;
-      }
-
-    }
-  else
-    {
-      return -1;
-    }
-}
-
-int editor_objectmap_add_object(EditorMapLayer* layer, const char* filename, 
int x, int y, SCM userdata)
-{
   EditorObjMap* objmap = dynamic_cast<EditorObjMap*>(layer);
   try {
     if (objmap)
@@ -224,6 +183,7 @@
 
   return -1;
 }
+#endif
 
 void
 editor_set_brush_tile(int i)
@@ -260,6 +220,7 @@
     tilemap->set_draw_attribute(!tilemap->get_draw_attribute());
 }
 
+#ifdef SWIGGUILE
 SCM
 obj2scm(const EditorObjMap::Obj& obj)
 {
@@ -344,6 +305,7 @@
 
   return brush;
 }
+#endif
 
 void
 editor_objectmap_set_current(EditorMapLayer* layer)
@@ -370,6 +332,7 @@
   return -1;
 }  
 
+#ifdef SWIGGUILE
 void
 editor_objectmap_delete_objects(EditorMapLayer* layer, SCM lst)
 {
@@ -412,6 +375,7 @@
       tool->set_selection(selection);
     }
 }
+#endif
 
 void
 editor_objectmap_set_pos(EditorMapLayer* layer, int id, int x, int y)
@@ -424,6 +388,7 @@
     }
 }
 
+#ifdef SWIGGUILE
 SCM
 editor_objectmap_get_objects(EditorMapLayer* layer)
 {
@@ -443,6 +408,7 @@
     }
   return SCM_EOL;
 }
+#endif
 
 void
 tilemap_object_tool_clear_selection()
@@ -454,6 +420,7 @@
   tool->clear_selection();
 }
 
+#ifdef SWIGGUILE
 SCM
 tilemap_object_tool_get_objects()
 {
@@ -486,6 +453,7 @@
 
   return SCM_BOOL_F;
 }
+#endif
 
 void
 objmap_sprite_object_flip(EditorMapLayer* layer, int id)
@@ -521,6 +489,7 @@
   
TileMapPaintTool::current()->set_tilemap(dynamic_cast<EditorTileMap*>(layer));
 }
 
+#ifdef SWIGGUILE
 SCM
 editor_get_tile_selection()
 {
@@ -534,6 +503,7 @@
   else
     return SCM_BOOL_F;
 }
+#endif 
 
 int
 editor_get_brush_tile()
@@ -625,13 +595,14 @@
     tileeditor->set_tile(Tileset::current()->create(id));
 }
 
+#ifdef SWIGGUILE
 SCM get_tile_def(Tile* tile)
 {
   SCM lst = gh_cons(scm_str2symbol("tile"), SCM_EOL);
 
   if (tile)
     {
-      lst = gh_cons(gh_list(scm_str2symbol("id"), SCM_MAKINUM(tile->id), 
(SCM_UNDEFINED)),
+      lst = gh_cons(gh_list(scm_str2symbol("id"), 0 /*FIXME: 
SCM_MAKINUM(tile->id)*/, (SCM_UNDEFINED)),
                     lst);
 
       lst = gh_cons(gh_list(scm_str2symbol("image"),
@@ -782,6 +753,7 @@
     return SCM_BOOL_F;
   }
 }
+#endif
 
 void 
 editor_map_component_set_zoom(CL_Component* c, float z)
@@ -838,32 +810,30 @@
 EditorMapLayer* 
 editor_tilemap_create(Tileset* tileset, int w, int h, int tile_size)
 {
-  return new EditorTileMap(tileset, w, h, tile_size);
+  return new EditorTileMap(tileset, w, h);
 }
 
 void
 editor_tilemap_save_png(EditorMapLayer* l, const char* filename)
 {
   EditorTileMap* tilemap = dynamic_cast<EditorTileMap*>(l);
-  CL_PixelBuffer* pixelbuffer = tilemap->create_pixelbuffer();
+  CL_PixelBuffer pixelbuffer = tilemap->create_pixelbuffer();
 
-  pixelbuffer->lock();
+  pixelbuffer.lock();
   std::ofstream out(filename);
 
   out << "P6\n"
-      << pixelbuffer->get_width() << " " << pixelbuffer->get_height() << "\n"
+      << pixelbuffer.get_width() << " " << pixelbuffer.get_height() << "\n"
       << "255\n";
-  char* buf = static_cast<char*>(pixelbuffer->get_data());
-  for(int i = 0; i < int(pixelbuffer->get_pitch() * 
pixelbuffer->get_height()); i += 4)
+  char* buf = static_cast<char*>(pixelbuffer.get_data());
+  for(int i = 0; i < int(pixelbuffer.get_pitch() * pixelbuffer.get_height()); 
i += 4)
     {
       out.write(&buf[i + 3], 1);
       out.write(&buf[i + 2], 1);
       out.write(&buf[i + 1], 1);
     }
 
-  pixelbuffer->unlock();
-
-  delete pixelbuffer;
+  pixelbuffer.unlock();
 }
 
 int
@@ -906,6 +876,7 @@
     }
 }
 
+#ifdef SWIGGUILE
 SCM
 editor_tilemap_get_data(EditorMapLayer* l)
 {
@@ -942,6 +913,7 @@
         }
     }
 }
+#endif
 
 std::string
 editor_map_get_filename(EditorMap* m)
@@ -977,6 +949,7 @@
   return tmp;
 }*/
 
+#ifdef SWIGGUILE
 SCM string2scm(const std::string& str)
 {
   return gh_str02scm(str.c_str());
@@ -1019,6 +992,7 @@
 {
   return m->get_metadata().get_scm();
 }
+#endif
 
 
 Tileset*
@@ -1027,6 +1001,7 @@
   return new Tileset(tile_size);
 }
 
+#ifdef SWIGGUILE
 Tileset*
 tileset_create_from_file(const char* resourcefile)
 {
@@ -1039,11 +1014,12 @@
 tileset_add_tile(Tileset* tileset, SCM data)
 {
   try {
-    tileset->add_tile(data);
+    tileset->add_tile_from_scm(data);
   } catch (CL_Error& err) {
     std::cout << "Error: " << err.message << std::endl;
   }
 }
+#endif
 
 void
 tileset_set_current(Tileset* tileset)

Modified: trunk/src/scripting/editor.hxx
===================================================================
--- trunk/src/scripting/editor.hxx      2004-05-13 18:49:34 UTC (rev 316)
+++ trunk/src/scripting/editor.hxx      2004-05-14 00:04:06 UTC (rev 317)
@@ -22,8 +22,11 @@
 
 #include <string>
 #include <vector>
-#include <guile/gh.h>
 
+#ifdef SWIGGUILE
+#  include <guile/gh.h>
+#endif
+
 class Workspace;
 class EditorMap;
 class EditorObjMap;
@@ -112,6 +115,7 @@
 EditorMapLayer* editor_mapsize_layer_create(int w, int h);
 void editor_mapsize_layer_set_size(EditorMapLayer*, int w, int h);
 
+#ifdef SWIGGUILE
 // Guile Specific Stuff
 SCM  editor_get_tile_selection();
 void object_selector_add_brush(CL_Component* comp, const char* name, SCM 
brush);
@@ -131,6 +135,7 @@
 void            editor_tilemap_set_data(EditorMapLayer* l, SCM data);
 SCM             editor_tilemap_get_data(EditorMapLayer* l);
 void tileset_add_tile(Tileset* tileset, SCM data);
+#endif
 
 #endif
 

Modified: trunk/src/scripting/netpanzer.cxx
===================================================================
--- trunk/src/scripting/netpanzer.cxx   2004-05-13 18:49:34 UTC (rev 316)
+++ trunk/src/scripting/netpanzer.cxx   2004-05-14 00:04:06 UTC (rev 317)
@@ -183,7 +183,7 @@
   file.read(reinterpret_cast<char*>(&thumbnail_x_pix), sizeof(short));
   file.read(reinterpret_cast<char*>(&thumbnail_y_pix), sizeof(short));
 
-  EditorTileMap* tilemap = new EditorTileMap(0, x_size, y_size, 32);
+  EditorTileMap* tilemap = new EditorTileMap(0, x_size, y_size);
   Field<int>* field      = tilemap->get_map();
 
   std::vector<unsigned short> vec;

Modified: trunk/src/tile.cxx
===================================================================
--- trunk/src/tile.cxx  2004-05-13 18:49:34 UTC (rev 316)
+++ trunk/src/tile.cxx  2004-05-14 00:04:06 UTC (rev 317)
@@ -32,9 +32,8 @@
 Tile::Tile(const std::string& filename_, 
            const CL_Color& color_, 
            const CL_Color& attribute_color_, 
-           unsigned char arg_colmap[])
-  : pixelbuffer(0),
-    color(color_),
+           unsigned char* arg_colmap)
+  : color(color_),
     attribute_color(attribute_color_),
     filename(filename_)
 {
@@ -45,12 +44,12 @@
     }
   
   //sur.set_alignment(origin_center, 0, 0);
-  memcpy(colmap, arg_colmap, 8);
+  if (arg_colmap)
+    memcpy(colmap, arg_colmap, 8);
 }
 
 Tile::~Tile()
 {
-  delete pixelbuffer;
 }
 
 CL_Color
@@ -77,7 +76,7 @@
         if (has_suffix(filename, ".png") || has_suffix(filename, ".jpg"))
           {
             CL_SpriteDescription desc;
-            desc.add_frame(get_pixelbuffer(), false);
+            desc.add_frame(new CL_PixelBuffer(get_pixelbuffer()), true);
             sur = CL_Sprite(desc);
           }
         else
@@ -92,7 +91,7 @@
     }
 }
 
-CL_PixelBuffer*
+CL_PixelBuffer
 Tile::get_pixelbuffer()
 {      
   if (pixelbuffer)
@@ -100,12 +99,12 @@
   {
     if (has_suffix(filename, ".png") || has_suffix(filename, ".jpg"))
       {
-        pixelbuffer = CL_ProviderFactory::load(filename);
+        pixelbuffer = CL_PixelBuffer(*CL_ProviderFactory::load(filename));
       }
     else
       {
         CL_SpriteDescription descr(filename, resources);
-        pixelbuffer = new CL_PixelBuffer(*(descr.get_frames().begin()->first));
+        pixelbuffer = CL_PixelBuffer(*(descr.get_frames().begin()->first));
       }
     return pixelbuffer;
   }
@@ -114,21 +113,21 @@
 CL_Color
 Tile::calc_color()
 {
-  CL_PixelBuffer* buffer = get_pixelbuffer();
-  buffer->lock();
-  unsigned char* buf = static_cast<unsigned char*>(buffer->get_data());
-  int len = buffer->get_height() * buffer->get_width();
+  CL_PixelBuffer buffer = get_pixelbuffer();
+  buffer.lock();
+  unsigned char* buf = static_cast<unsigned char*>(buffer.get_data());
+  int len = buffer.get_height() * buffer.get_width();
 
   int red   = 0;
   int green = 0;
   int blue  = 0;
   int alpha = 0;
   
-  switch (buffer->get_format().get_depth())
+  switch (buffer.get_format().get_depth())
     {
     case 8:
       {
-        CL_Palette palette = buffer->get_palette();
+        CL_Palette palette = buffer.get_palette();
         for(int i = 0; i < len; ++i)
           {
             red   += palette.colors[buf[i]].get_red();
@@ -159,7 +158,7 @@
       break;
     }
 
-  buffer->unlock();
+  buffer.unlock();
 
   return CL_Color(static_cast<int>(red   / len),
                   static_cast<int>(green / len),

Modified: trunk/src/tile.hxx
===================================================================
--- trunk/src/tile.hxx  2004-05-13 18:49:34 UTC (rev 316)
+++ trunk/src/tile.hxx  2004-05-14 00:04:06 UTC (rev 317)
@@ -22,6 +22,7 @@
 
 #include <assert.h>
 #include <ClanLib/Display/sprite.h>
+#include <ClanLib/Display/pixel_buffer.h>
 
 /** A Tile is a surface or sprite together with information for
  *  collision detection (aka colmap). The collision map is at a
@@ -31,7 +32,7 @@
 {
 private:
   CL_Sprite sur;
-  CL_PixelBuffer* pixelbuffer;
+  CL_PixelBuffer pixelbuffer;
 
   /** Color used for the minimap to represent this tile */
   CL_Color  color;
@@ -42,13 +43,14 @@
 
   std::string filename;
 public:
-  int id; 
   unsigned char colmap[8];
 
   /** @param filename Surface to use 
    *  @param arg_colmap a 8 char long array */
   Tile(const std::string& filename, 
-       const CL_Color& color, const CL_Color& attribute_color, unsigned char 
arg_colmap[]);
+       const CL_Color& color, 
+       const CL_Color& attribute_color, 
+       unsigned char* arg_colmap = NULL);
   
   ~Tile();
 
@@ -56,7 +58,7 @@
 
   /** Return a pixelbuffer associated with this tile, caller must not
       delete the pixelbuffer, the Tile will take care of that */
-  CL_PixelBuffer* get_pixelbuffer();
+  CL_PixelBuffer get_pixelbuffer();
 
   CL_Color   get_color();
   CL_Color   get_attribute_color();

Modified: trunk/src/tilemap_paint_tool.cxx
===================================================================
--- trunk/src/tilemap_paint_tool.cxx    2004-05-13 18:49:34 UTC (rev 316)
+++ trunk/src/tilemap_paint_tool.cxx    2004-05-14 00:04:06 UTC (rev 317)
@@ -72,7 +72,7 @@
       break;
       
     default:
-      int tile_size = tilemap->get_tile_size();
+      int tile_size = tilemap->get_tileset()->get_tile_size();
 
       // Draw the brush:
       for(int y = 0; y < brush.get_height(); ++y)

Modified: trunk/src/tileset.cxx
===================================================================
--- trunk/src/tileset.cxx       2004-05-13 18:49:34 UTC (rev 316)
+++ trunk/src/tileset.cxx       2004-05-14 00:04:06 UTC (rev 317)
@@ -42,6 +42,16 @@
   std::cout << "Tileset: destroy" << std::endl;
 }
 
+void
+Tileset::add_tile(int id, Tile* tile)
+{
+  // FIXME: Memleaky
+  if (id >= int(tiles.size()))
+    tiles.resize(id+1, 0);
+
+  tiles[id] = tile;
+}
+
 #ifdef SWIGGUILE
 void
 Tileset::load_tile_file(const std::string& filename)
@@ -69,7 +79,7 @@
       
               if (gh_equal_p(gh_symbol2scm("tile"), name)) 
                 {
-                  add_tile(data);
+                  add_tile_from_scm(data);
                 }
               else
                 {
@@ -86,7 +96,7 @@
 }
 
 void
-Tileset::add_tile(SCM data)
+Tileset::add_tile_from_scm(SCM data)
 {
   // FIXME: Move this to scripting and add a Tileset::add()
   int id = 0;
@@ -173,7 +183,6 @@
           tiles.resize(id+1);
         }
       tiles[id] = new Tile(image, color, attribute_color, colmap);
-      tiles[id]->id = id;
     }
 }
 #endif

Modified: trunk/src/tileset.hxx
===================================================================
--- trunk/src/tileset.hxx       2004-05-13 18:49:34 UTC (rev 316)
+++ trunk/src/tileset.hxx       2004-05-14 00:04:06 UTC (rev 317)
@@ -63,6 +63,8 @@
   Tile* create(int id);
 
   int get_tile_size() const { return tile_size; }
+  
+  void add_tile(int id, Tile* tile);
 
   /** Create the default TileFactor*/
   static void init();
@@ -76,7 +78,7 @@
 
 #ifdef SWIGGUILE
   void load_tile_file(const std::string& filename);
-  void add_tile(SCM data);
+  void add_tile_from_scm(SCM data);
 #endif
 };
 





reply via email to

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