windstille-devel
[Top][All Lists]
Advanced

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

[Windstille-devel] rev 374 - in trunk: data data/images/icons24 src src/


From: Ingo Ruhnke
Subject: [Windstille-devel] rev 374 - in trunk: data data/images/icons24 src src/scripting
Date: Mon, 31 May 2004 15:11:27 +0200

Author: grumbel
Date: 2004-05-31 15:11:26 +0200 (Mon, 31 May 2004)
New Revision: 374

Added:
   trunk/data/images/icons24/background.png
   trunk/data/images/icons24/downarrow.png
   trunk/data/images/icons24/eye.png
   trunk/data/images/icons24/foreground.png
   trunk/data/images/icons24/interactive.png
   trunk/data/images/icons24/minimap.png
   trunk/src/netpanzer.cxx
   trunk/src/netpanzer.hxx
   trunk/src/netpanzer.py
Removed:
   trunk/src/scripting/netpanzer.cxx
   trunk/src/scripting/netpanzer.hxx
Modified:
   trunk/data/mknetpanzertiles.sh
   trunk/src/SConstruct
   trunk/src/editor.py
   trunk/src/flexlay.i
Log:
- fixed up netpanzer support a bit

Added: trunk/data/images/icons24/background.png
===================================================================
(Binary files differ)


Property changes on: trunk/data/images/icons24/background.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: trunk/data/images/icons24/downarrow.png
===================================================================
(Binary files differ)


Property changes on: trunk/data/images/icons24/downarrow.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: trunk/data/images/icons24/eye.png
===================================================================
(Binary files differ)


Property changes on: trunk/data/images/icons24/eye.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: trunk/data/images/icons24/foreground.png
===================================================================
(Binary files differ)


Property changes on: trunk/data/images/icons24/foreground.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: trunk/data/images/icons24/interactive.png
===================================================================
(Binary files differ)


Property changes on: trunk/data/images/icons24/interactive.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: trunk/data/images/icons24/minimap.png
===================================================================
(Binary files differ)


Property changes on: trunk/data/images/icons24/minimap.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Modified: trunk/data/mknetpanzertiles.sh
===================================================================
--- trunk/data/mknetpanzertiles.sh      2004-05-31 10:51:40 UTC (rev 373)
+++ trunk/data/mknetpanzertiles.sh      2004-05-31 13:11:26 UTC (rev 374)
@@ -1,28 +1,23 @@
 #! /bin/sh
 
-echo "Generating netpanzertiles.xml"
-echo "<resources>" > netpanzertiles.xml
-echo "  <section name=\"tiles\">" >> netpanzertiles.xml
+echo "Generating netpanzertiles.py"
+echo "# Automatically generated by 'mknetpanzertiles.sh'" > netpanzertiles.py
+echo "from flexlay import *" >> netpanzertiles.py
+echo "def load_netpanzer_tiles(tileset):" >> netpanzertiles.py
 for i in images/netpanzertiles/*.png; 
 do
 #  BASENAME=`basename $i`
   BASENAME=${i##images/netpanzertiles/tile}
-  echo "<sprite name=\"${BASENAME%%.png}\"><image file=\"$i\"/></sprite>";
-done >> netpanzertiles.xml
-echo "  </section>" >> netpanzertiles.xml
-echo "</resources>" >> netpanzertiles.xml
-
-echo "Generating netpanzertiles.scm"
-echo "(windstille-tiles" > netpanzertiles.scm
-for i in images/netpanzertiles/*.png; 
-do
-#  BASENAME=`basename $i`
-  BASENAME=${i##images/netpanzertiles/tile}
   BASENAME=${BASENAME%%.png}
-  echo "(tile (id ${BASENAME})"
-  echo "      (image \"tiles/${BASENAME}\")"
-  echo "      (colmap 255 255 255 255 255 255 255 255))"
-done >> netpanzertiles.scm
-echo ")" >> netpanzertiles.scm
+  BASENAME=${BASENAME##0}
+  BASENAME=${BASENAME##0}
+  BASENAME=${BASENAME##0}
+  echo "   tileset.add_tile(${BASENAME},"
+  echo "                    Tile(\"../data/$i\","
+  echo "                         CL_Color(254, 254, 254, 254),"
+  echo "                         CL_Color(255,   0,   0, 128)))"
+done >> netpanzertiles.py
+echo "" >> netpanzertiles.py
+echo "# EOF #" >> netpanzertiles.py
 
 # EOF #

Modified: trunk/src/SConstruct
===================================================================
--- trunk/src/SConstruct        2004-05-31 10:51:40 UTC (rev 373)
+++ trunk/src/SConstruct        2004-05-31 13:11:26 UTC (rev 374)
@@ -93,6 +93,7 @@
     'objmap_sprite_object.cxx',
     'paint_command.cxx',
     'panel.cxx',
+    'netpanzer.cxx', # fixme: move into seperate library
     'menu.cxx',
     'menubar.cxx',
     'popup_menu.cxx',

Modified: trunk/src/editor.py
===================================================================
--- trunk/src/editor.py 2004-05-31 10:51:40 UTC (rev 373)
+++ trunk/src/editor.py 2004-05-31 13:11:26 UTC (rev 374)
@@ -24,7 +24,8 @@
 flexlay = Flexlay()
 flexlay.init()
 
-from supertux import *
+from   supertux import *
+# import netpanzer
 
 screen_w = 800
 screen_h = 600
@@ -61,6 +62,7 @@
 workspace.set_tool(tilemap_paint_tool.to_tool());
 
 startlevel = SuperTuxLevel(100, 50)
+# startlevel = netpanzer.Level(256, 256)
 startlevel.activate(workspace)
 
 def do_quit():
@@ -310,6 +312,7 @@
 layer_menu.add_item(mysprite, "Show only current", gui_show_only_current)
 
 supertux = SuperTuxGUI(load_supertux_tiles(), gui)
+# supertux.tileselector.set_tileset(netpanzer.tileset)
 
 level = None
 def menu_file_open():
@@ -333,6 +336,9 @@
             return True
     return False
 
+def netpanzer_load_level(filename):
+    NetPanzerFileStruct(filename)
+
 def supertux_load_level(filename):   
     print "Loading: ", filename
     level = SuperTuxLevel(filename)

Modified: trunk/src/flexlay.i
===================================================================
--- trunk/src/flexlay.i 2004-05-31 10:51:40 UTC (rev 373)
+++ trunk/src/flexlay.i 2004-05-31 13:11:26 UTC (rev 374)
@@ -50,6 +50,8 @@
 #include "tilemap_select_tool.hxx"
 #include "objmap_select_tool.hxx"
 #include "zoom_tool.hxx"
+
+#include "netpanzer.hxx" 
 %}
 
 %include "std_string.i"
@@ -93,12 +95,13 @@
 %include "menu.hxx"
 %include "menubar.hxx"
 %include "scrollbar.hxx"
-
 %include "tilemap_paint_tool.hxx"
 %include "tilemap_select_tool.hxx"
 %include "objmap_select_tool.hxx"
 %include "zoom_tool.hxx" 
 %include "graphic_context_state.hxx"
 
+%include "netpanzer.hxx" 
 
+
 /* EOF */

Copied: trunk/src/netpanzer.cxx (from rev 342, 
trunk/src/scripting/netpanzer.cxx)
===================================================================
--- trunk/src/scripting/netpanzer.cxx   2004-05-18 19:35:22 UTC (rev 342)
+++ trunk/src/netpanzer.cxx     2004-05-31 13:11:26 UTC (rev 374)
@@ -0,0 +1,263 @@
+//  $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 <iostream>
+#include <fstream>
+#include <ClanLib/Display/palette.h>
+#include "globals.hxx"
+#include "tile.hxx"
+#include "tileset.hxx"
+#include "tilemap_layer.hxx"
+#include "editor_map.hxx"
+#include "netpanzer.hxx"
+
+CL_Palette netpanzer_load_palette(const char* filename)
+{
+  CL_Palette palette;
+  unsigned char color_array[256 * 3];
+
+  std::ifstream in(filename);
+
+  if (!in)
+    {
+      std::cout << "Couldn't load palette" << std::endl;
+      return palette;
+    }
+
+  in.read(reinterpret_cast<char*>(color_array), sizeof(color_array));
+
+  for(int i = 0; i < 256; ++i)
+    {
+      palette.colors[i].set_red  (color_array[3*i + 0]);
+      palette.colors[i].set_green(color_array[3*i + 1]);
+      palette.colors[i].set_blue (color_array[3*i + 2]);
+    }
+
+  return palette;
+}
+
+unsigned char find_nearest_color(const CL_Palette& palette, const CL_Color& 
rgb)
+{ // Copyright (C) 1998 Pyrosoft Inc. (www.pyrosoftgames.com), Matthew Bogue
+  float bestDist = 10000000.0f;
+  int   best     = 0;
+                                                                               
                                 
+  float vPic = sqrt(rgb.get_red() * rgb.get_red() 
+                    + rgb.get_green() * rgb.get_green()
+                    + rgb.get_blue() * rgb.get_blue()) * 0.57735027;
+ 
+  for (int i = 0; i < 256; i++) {
+    float vPal = sqrt(palette.colors[i].get_red()     * 
palette.colors[i].get_red()
+                      + palette.colors[i].get_green() * 
palette.colors[i].get_green()
+                      + palette.colors[i].get_blue()  * 
palette.colors[i].get_blue()) * 0.57735027;
+                                                                               
                                 
+    float dr = palette.colors[i].get_red()   - rgb.get_red();
+    float dg = palette.colors[i].get_green() - rgb.get_green();
+    float db = palette.colors[i].get_blue()  - rgb.get_blue();
+    float dv = vPal-vPic;
+    float dist = dr * dr * 0.3 + dg * dg * 0.59 + db * db * 0.11 + dv * dv * 
0.7;
+                                                                               
                                 
+    if (dist < bestDist) {
+      bestDist = dist;
+      best = i;
+    }
+  }
+                                                                               
                                 
+  return best;
+                                                                               
                                 
+}
+
+class NetPanzerFileStructImpl
+{
+public:
+  std::string id_header;
+  std::string name;
+  std::string description;
+  TilemapLayer tilemap; 
+  Tileset tileset;
+};
+
+std::string
+NetPanzerFileStruct::get_id_header()
+{
+  return impl->id_header;
+}
+
+std::string
+NetPanzerFileStruct::get_name()
+{
+  return impl->name;
+}
+
+std::string
+NetPanzerFileStruct::get_description()
+{
+  return impl->description;
+}
+
+TilemapLayer
+NetPanzerFileStruct::get_tilemap()
+{
+  return impl->tilemap;
+}
+
+void
+NetPanzerFileStruct::set_id_header(const std::string& id)
+{
+  impl->id_header = id;
+}
+
+void
+NetPanzerFileStruct::set_name(const std::string& name)
+{
+  impl->name = name;
+}
+
+void
+NetPanzerFileStruct::set_description(const std::string& description)
+{
+  impl->description = description;
+}
+
+void
+NetPanzerFileStruct::set_tilemap(TilemapLayer l)
+{
+  impl->tilemap = l;
+}
+
+
+void
+NetPanzerFileStruct::save(const std::string& filename)
+{
+  if (impl->tilemap.is_null())
+    return;
+    
+  unsigned char   netp_id_header[64];
+  strcpy(reinterpret_cast<char*>(netp_id_header), impl->id_header.c_str());
+  unsigned short  id       = 0; // ?
+  char   name[256];
+  strcpy(name, impl->name.c_str());
+  char   description[1024];
+  strcpy(description, impl->description.c_str());
+  unsigned short  x_size   = impl->tilemap.get_width();
+  unsigned short  y_size   = impl->tilemap.get_height();
+  char            tile_set[256] = "summer12mb.tls";
+ 
+  unsigned short  thumbnail_x_pix = impl->tilemap.get_width();
+  unsigned short  thumbnail_y_pix = impl->tilemap.get_height();
+    
+  std::ofstream out(filename.c_str());
+
+  out.write(reinterpret_cast<char*>(&netp_id_header), sizeof(netp_id_header));
+  out.write(reinterpret_cast<char*>(&id), sizeof(short));
+  out.write(reinterpret_cast<char*>(&name), sizeof(name));
+  out.write(reinterpret_cast<char*>(&description), sizeof(description));
+  out.write(reinterpret_cast<char*>(&x_size), sizeof(short));
+  out.write(reinterpret_cast<char*>(&y_size), sizeof(short));
+  out.write(reinterpret_cast<char*>(&tile_set), sizeof(tile_set));
+  out.write(reinterpret_cast<char*>(&thumbnail_x_pix), sizeof(short));
+  out.write(reinterpret_cast<char*>(&thumbnail_y_pix), sizeof(short));
+
+  std::vector<unsigned short> vec(x_size * y_size);
+
+  Field<int>* field = impl->tilemap.get_field();
+  for(int i = 0; i < x_size * y_size; ++i)
+    {
+      vec[i] = (*field)[i];
+    }
+  out.write(reinterpret_cast<char*>(&(*vec.begin())), 
+            sizeof(unsigned short)*vec.size());
+
+  // Generate thumbnail
+  CL_Palette palette = netpanzer_load_palette((datadir + "netp.act").c_str());
+  
+  std::vector<unsigned char> thumbnail(x_size * y_size);
+  for(int i = 0; i < int(thumbnail.size()); ++i)
+    {
+      Tile* tile = impl->tileset.create((*field)[i]);
+      if (tile)
+        thumbnail[i] = find_nearest_color(palette, tile->get_color());
+    }
+
+  out.write(reinterpret_cast<char*>(&(*thumbnail.begin())), 
+            sizeof(unsigned char)*thumbnail.size());
+}
+
+NetPanzerFileStruct::NetPanzerFileStruct(Tileset tileset, int w, int h)
+  : impl(new NetPanzerFileStructImpl())
+{
+  impl->tileset = tileset;
+  impl->id_header = "<Id Header>";
+  impl->name = "<Name>";
+  impl->description = "<Description>";
+  impl->tilemap = TilemapLayer(tileset, w, h);
+}
+
+NetPanzerFileStruct::NetPanzerFileStruct(Tileset tileset, const std::string& 
filename)
+  : impl(new NetPanzerFileStructImpl())
+{
+  impl->tileset = tileset;
+  
+  // FIXME: endian issues
+  unsigned char   netp_id_header[64]; // Copyright PyroSoft Inc....
+  unsigned short  id; // What is this?
+  char            name[256];
+  char            description[1024];
+  unsigned short  x_size; // width
+  unsigned short  y_size; // height
+  char            tile_set[256]; // name of the tileset: "summer12mb.tls"
+ 
+  unsigned short  thumbnail_x_pix;
+  unsigned short  thumbnail_y_pix;
+
+  std::ifstream file(filename.c_str());
+
+  if (!file)
+    {
+      std::cout << "NetPanzerFileStructImpl: Error: " << filename << std::endl;
+    }
+
+  file.read(reinterpret_cast<char*>(&netp_id_header), sizeof(netp_id_header));
+  file.read(reinterpret_cast<char*>(&id), sizeof(short));
+  file.read(reinterpret_cast<char*>(&name), sizeof(name));
+  file.read(reinterpret_cast<char*>(&description), sizeof(description));
+  file.read(reinterpret_cast<char*>(&x_size), sizeof(short));
+  file.read(reinterpret_cast<char*>(&y_size), sizeof(short));
+  file.read(reinterpret_cast<char*>(&tile_set), sizeof(tile_set));
+  file.read(reinterpret_cast<char*>(&thumbnail_x_pix), sizeof(short));
+  file.read(reinterpret_cast<char*>(&thumbnail_y_pix), sizeof(short));
+
+  TilemapLayer tilemap(tileset, x_size, y_size);
+  Field<int>* field      = tilemap.get_field();
+
+  std::vector<unsigned short> vec;
+  vec.resize(x_size * y_size);
+  file.read(reinterpret_cast<char*>(&(*vec.begin())), sizeof(unsigned 
short)*vec.size());
+
+  for(int i = 0; i < x_size*y_size; ++i)
+    (*field)[i] = vec[i];
+
+  std::cout << "Thumbnail: " << thumbnail_x_pix << " " << thumbnail_y_pix << 
std::endl;
+
+  impl->tilemap     = tilemap;
+  impl->id_header   = reinterpret_cast<char*>(netp_id_header);
+  impl->name        = name;
+  impl->description = description;
+}
+
+/* EOF */

Copied: trunk/src/netpanzer.hxx (from rev 342, 
trunk/src/scripting/netpanzer.hxx)
===================================================================
--- trunk/src/scripting/netpanzer.hxx   2004-05-18 19:35:22 UTC (rev 342)
+++ trunk/src/netpanzer.hxx     2004-05-31 13:11:26 UTC (rev 374)
@@ -0,0 +1,51 @@
+//  $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_SCRIPTING_NETPANZER_HXX
+#define HEADER_SCRIPTING_NETPANZER_HXX
+
+#include <string>
+#include "shared_ptr.hxx"
+
+class NetPanzerFileStructImpl;
+
+class NetPanzerFileStruct
+{
+public:
+  NetPanzerFileStruct(Tileset tileset, int w, int h);
+  NetPanzerFileStruct(Tileset tileset, const std::string& filename);
+
+  std::string get_id_header();
+  std::string get_name();
+  std::string get_description();
+  TilemapLayer get_tilemap(); 
+
+  void set_id_header(const std::string& id);
+  void set_name(const std::string& name);
+  void set_description(const std::string& description);
+  void set_tilemap(TilemapLayer l); 
+
+  void save(const std::string& filename);
+private:
+  SharedPtr<NetPanzerFileStructImpl> impl;
+};
+
+#endif
+
+/* EOF */

Added: trunk/src/netpanzer.py
===================================================================
--- trunk/src/netpanzer.py      2004-05-31 10:51:40 UTC (rev 373)
+++ trunk/src/netpanzer.py      2004-05-31 13:11:26 UTC (rev 374)
@@ -0,0 +1,54 @@
+##  $Id$
+## 
+##  Flexlay - A Generic 2D Game Editor
+##  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.
+
+from flexlay import *
+import netpanzertiles
+
+tileset = Tileset(32)
+netpanzertiles.load_netpanzer_tiles(tileset)
+
+class Level:
+    filename  = None
+    data      = None
+    editormap = None
+    objects   = None
+
+    def __init__(self, *params):
+        if len(params) == 2:
+            (width, height) = params
+            self.data = NetPanzerFileStruct(tileset, width, height)
+
+        elif len(params) == 1:
+            (self.filename,) = params
+            self.data = NetPanzerFileStruct(tileset, self.filename)
+
+        self.objects = ObjectLayer()
+        self.editormap = EditorMap()
+        self.editormap.add_layer(self.data.get_tilemap().to_layer())
+        self.editormap.add_layer(self.objects.to_layer())
+
+        # FIXME: Data might not get freed since its 'recursively' refcounted
+        self.editormap.set_metadata(make_metadata(self))
+
+    def activate(self, workspace):
+        workspace.set_map(self.editormap)
+        TilemapLayer.set_current(self.data.get_tilemap())
+        ObjectLayer.set_current(self.objects)
+
+# EOF #

Deleted: trunk/src/scripting/netpanzer.cxx
===================================================================
--- trunk/src/scripting/netpanzer.cxx   2004-05-31 10:51:40 UTC (rev 373)
+++ trunk/src/scripting/netpanzer.cxx   2004-05-31 13:11:26 UTC (rev 374)
@@ -1,208 +0,0 @@
-//  $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 <iostream>
-#include <fstream>
-#include <ClanLib/Display/palette.h>
-#include "globals.hxx"
-#include "tile.hxx"
-#include "../tileset.hxx"
-#include "../editor_tilemap.hxx"
-#include "../editor_map.hxx"
-#include "../editor_names.hxx"
-#include "netpanzer.hxx"
-
-void netpanzer_set_id_header(NetPanzerFileStruct* npm, std::string s)   { 
npm->id_header = s; }
-void netpanzer_set_name(NetPanzerFileStruct* npm, std::string s)        { 
npm->name = s; }
-void netpanzer_set_description(NetPanzerFileStruct* npm, std::string s) { 
npm->description = s; }
-void netpanzer_set_tilemap(NetPanzerFileStruct* npm, EditorMapLayer* t)     { 
npm->tilemap = t; }
-
-std::string netpanzer_get_id_header(NetPanzerFileStruct* npm) { return 
npm->id_header; }
-std::string netpanzer_get_name(NetPanzerFileStruct* npm) { return npm->name; }
-std::string netpanzer_get_description(NetPanzerFileStruct* npm) { return 
npm->description; }
-EditorMapLayer* netpanzer_get_tilemap(NetPanzerFileStruct* npm) { return 
npm->tilemap; }
-
-CL_Palette netpanzer_load_palette(const char* filename)
-{
-  CL_Palette palette;
-  unsigned char color_array[256 * 3];
-
-  std::ifstream in(filename);
-
-  if (!in)
-    {
-      std::cout << "Couldn't load palette" << std::endl;
-      return palette;
-    }
-
-  in.read(reinterpret_cast<char*>(color_array), sizeof(color_array));
-
-  for(int i = 0; i < 256; ++i)
-    {
-      palette.colors[i].set_red  (color_array[3*i + 0]);
-      palette.colors[i].set_green(color_array[3*i + 1]);
-      palette.colors[i].set_blue (color_array[3*i + 2]);
-    }
-
-  return palette;
-}
-
-unsigned char find_nearest_color(const CL_Palette& palette, const CL_Color& 
rgb)
-{ // Copyright (C) 1998 Pyrosoft Inc. (www.pyrosoftgames.com), Matthew Bogue
-  float bestDist = 10000000.0f;
-  int   best     = 0;
-                                                                               
                                 
-  float vPic = sqrt(rgb.get_red() * rgb.get_red() 
-                    + rgb.get_green() * rgb.get_green()
-                    + rgb.get_blue() * rgb.get_blue()) * 0.57735027;
- 
-  for (int i = 0; i < 256; i++) {
-    float vPal = sqrt(palette.colors[i].get_red()     * 
palette.colors[i].get_red()
-                      + palette.colors[i].get_green() * 
palette.colors[i].get_green()
-                      + palette.colors[i].get_blue()  * 
palette.colors[i].get_blue()) * 0.57735027;
-                                                                               
                                 
-    float dr = palette.colors[i].get_red()   - rgb.get_red();
-    float dg = palette.colors[i].get_green() - rgb.get_green();
-    float db = palette.colors[i].get_blue()  - rgb.get_blue();
-    float dv = vPal-vPic;
-    float dist = dr * dr * 0.3 + dg * dg * 0.59 + db * db * 0.11 + dv * dv * 
0.7;
-                                                                               
                                 
-    if (dist < bestDist) {
-      bestDist = dist;
-      best = i;
-    }
-  }
-                                                                               
                                 
-  return best;
-                                                                               
                                 
-}
-
-void
-save_netpanzer_map(const char* filename, EditorMap* m, 
-                   const char* id_header_, const char* name_, const char* 
description_)
-{
-  EditorTileMap* tilemap = 
dynamic_cast<EditorTileMap*>(m->get_layer_by_name(TILEMAP_NAME));
-
-  if (!tilemap)
-    return;
-    
-  unsigned char   netp_id_header[64];
-  strcpy(reinterpret_cast<char*>(netp_id_header), id_header_);
-  unsigned short  id       = 0; // ?
-  char   name[256];
-  strcpy(name, name_);
-  char   description[1024];
-  strcpy(description, description_);
-  unsigned short  x_size   = tilemap->get_width();
-  unsigned short  y_size   = tilemap->get_height();
-  char            tile_set[256] = "summer12mb.tls";
- 
-  unsigned short  thumbnail_x_pix = tilemap->get_width();
-  unsigned short  thumbnail_y_pix = tilemap->get_height();
-    
-  std::ofstream out(filename);
-
-  out.write(reinterpret_cast<char*>(&netp_id_header), sizeof(netp_id_header));
-  out.write(reinterpret_cast<char*>(&id), sizeof(short));
-  out.write(reinterpret_cast<char*>(&name), sizeof(name));
-  out.write(reinterpret_cast<char*>(&description), sizeof(description));
-  out.write(reinterpret_cast<char*>(&x_size), sizeof(short));
-  out.write(reinterpret_cast<char*>(&y_size), sizeof(short));
-  out.write(reinterpret_cast<char*>(&tile_set), sizeof(tile_set));
-  out.write(reinterpret_cast<char*>(&thumbnail_x_pix), sizeof(short));
-  out.write(reinterpret_cast<char*>(&thumbnail_y_pix), sizeof(short));
-
-  std::vector<unsigned short> vec(x_size * y_size);
-
-  Field<int>* field = tilemap->get_map();
-  for(int i = 0; i < x_size * y_size; ++i)
-    {
-      vec[i] = (*field)[i];
-    }
-  out.write(reinterpret_cast<char*>(&(*vec.begin())), 
-            sizeof(unsigned short)*vec.size());
-
-  // Generate thumbnail
-  CL_Palette palette = netpanzer_load_palette((datadir + "netp.act").c_str());
-  
-  std::vector<unsigned char> thumbnail(x_size * y_size);
-  for(int i = 0; i < int(thumbnail.size()); ++i)
-    {
-      Tile* tile = Tileset::current()->create((*field)[i]);
-      if (tile)
-        thumbnail[i] = find_nearest_color(palette, tile->get_color());
-    }
-
-  out.write(reinterpret_cast<char*>(&(*thumbnail.begin())), 
-            sizeof(unsigned char)*thumbnail.size());
-}
-
-NetPanzerFileStruct*
-load_netpanzer_map(const char* filename)
-{
-  // FIXME: endian issues
-  unsigned char   netp_id_header[64]; // Copyright PyroSoft Inc....
-  unsigned short  id; // What is this?
-  char   name[256];
-  char   description[1024];
-  unsigned short  x_size; // width
-  unsigned short  y_size; // height
-  char            tile_set[256]; // name of the tileset: "summer12mb.tls"
- 
-  unsigned short  thumbnail_x_pix;
-  unsigned short  thumbnail_y_pix;
-
-  std::ifstream file(filename);
-
-  if (!file)
-    return 0;
-
-  file.read(reinterpret_cast<char*>(&netp_id_header), sizeof(netp_id_header));
-  file.read(reinterpret_cast<char*>(&id), sizeof(short));
-  file.read(reinterpret_cast<char*>(&name), sizeof(name));
-  file.read(reinterpret_cast<char*>(&description), sizeof(description));
-  file.read(reinterpret_cast<char*>(&x_size), sizeof(short));
-  file.read(reinterpret_cast<char*>(&y_size), sizeof(short));
-  file.read(reinterpret_cast<char*>(&tile_set), sizeof(tile_set));
-  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);
-  Field<int>* field      = tilemap->get_map();
-
-  std::vector<unsigned short> vec;
-  vec.resize(x_size * y_size);
-  file.read(reinterpret_cast<char*>(&(*vec.begin())), sizeof(unsigned 
short)*vec.size());
-
-  for(int i = 0; i < x_size*y_size; ++i)
-    (*field)[i] = vec[i];
-
-  std::cout << "Thumbnail: " << thumbnail_x_pix << " " << thumbnail_y_pix << 
std::endl;
-
-  NetPanzerFileStruct* netpanzer_file = new NetPanzerFileStruct;
-
-  netpanzer_file->tilemap     = tilemap;
-  netpanzer_file->id_header   = reinterpret_cast<char*>(netp_id_header);
-  netpanzer_file->name        = name;
-  netpanzer_file->description = description;
-
-  return netpanzer_file;
-}
-
-/* EOF */

Deleted: trunk/src/scripting/netpanzer.hxx
===================================================================
--- trunk/src/scripting/netpanzer.hxx   2004-05-31 10:51:40 UTC (rev 373)
+++ trunk/src/scripting/netpanzer.hxx   2004-05-31 13:11:26 UTC (rev 374)
@@ -1,57 +0,0 @@
-//  $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_SCRIPTING_NETPANZER_HXX
-#define HEADER_SCRIPTING_NETPANZER_HXX
-
-#include <string>
-
-class EditorMap;
-class EditorMapLayer;
-struct NetPanzerFileStruct;
-
-#ifndef SWIG
-struct NetPanzerFileStruct
-{
-  std::string id_header;
-  std::string name;
-  std::string description;
-
-  EditorMapLayer* tilemap; 
-};
-#endif
-
-void netpanzer_set_id_header(NetPanzerFileStruct* npm, std::string s);
-void netpanzer_set_name(NetPanzerFileStruct* npm, std::string s);
-void netpanzer_set_description(NetPanzerFileStruct* npm, std::string s);
-void netpanzer_set_tilemap(NetPanzerFileStruct* npm, EditorMapLayer* t);
-
-std::string netpanzer_get_id_header(NetPanzerFileStruct* npm);
-std::string netpanzer_get_name(NetPanzerFileStruct* npm);
-std::string netpanzer_get_description(NetPanzerFileStruct* npm);
-EditorMapLayer* netpanzer_get_tilemap(NetPanzerFileStruct* npm);
-
-NetPanzerFileStruct* load_netpanzer_map(const char* filename);
-void save_netpanzer_map(const char* filename, 
-                        EditorMap* m, 
-                        const char* id_header_, const char* name_, const char* 
description_);
-
-#endif
-
-/* EOF */





reply via email to

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