pingus-cvs
[Top][All Lists]
Advanced

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

[Pingus-CVS] r2647 - in branches/pingus_sdl: . src


From: grumbel at BerliOS
Subject: [Pingus-CVS] r2647 - in branches/pingus_sdl: . src
Date: Sun, 14 Jan 2007 18:27:55 +0100

Author: grumbel
Date: 2007-01-14 18:27:53 +0100 (Sun, 14 Jan 2007)
New Revision: 2647

Added:
   branches/pingus_sdl/src/resource_manager.cpp
   branches/pingus_sdl/src/resource_manager.hpp
Modified:
   branches/pingus_sdl/clanlib_2_sexpr.rb
   branches/pingus_sdl/src/SConscript
   branches/pingus_sdl/src/path_manager.cxx
   branches/pingus_sdl/src/pingus_main.cxx
   branches/pingus_sdl/src/resource.cxx
   branches/pingus_sdl/src/resource.hxx
   branches/pingus_sdl/src/sexpr_file_reader.cpp
Log:
- some more work on the resource converter script

Modified: branches/pingus_sdl/clanlib_2_sexpr.rb
===================================================================
--- branches/pingus_sdl/clanlib_2_sexpr.rb      2007-01-14 10:10:10 UTC (rev 
2646)
+++ branches/pingus_sdl/clanlib_2_sexpr.rb      2007-01-14 17:27:53 UTC (rev 
2647)
@@ -2,26 +2,65 @@
 
 require "rexml/document"
 
+def parse_surface(prefix, dir, sprite)
+  # convert surfaces to sprites, since we don't really use surfaces anyway
+  print "\n#{prefix}(sprite"
+  print "\n#{prefix}  (name \"#{sprite.attribute("name").value}\")"
+  print "\n#{prefix}  (images \"#{sprite.attribute("file").value}\")"
+  puts ")\n"
+end
+
 def parse_sprite(prefix, dir, sprite)
-  puts ";; data/images/#{dir[1..-1]}/#{sprite.attribute("name")}.sprite"
-  puts "(sprite"
+  # puts ";; data/images/#{dir[1..-1]}/#{sprite.attribute("name")}.sprite"
+  print "\n#{prefix}(sprite"
+  print "\n#{prefix}  (name \"#{sprite.attribute("name").value}\")"
   sprite.elements.each{|el|
     case el.name
     when "image"
-      puts "  (images \"#{File.basename(el.attribute("file").value)}\")"
+      if not el.has_elements? then
+        print "\n#{prefix}  (image (file \"#{el.attribute("file").value}\"))"
+      elsif el.elements["grid"] then
+        print "\n#{prefix}  (image (file  \"#{el.attribute("file").value}\")"
+
+        if el.elements["grid"].attribute("array") then
+          print "\n#{prefix}         (array 
#{el.elements["grid"].attribute("array").value.gsub(",", " ")})" 
+        end
+
+        if el.elements["grid"].attribute("size") then
+          print "\n#{prefix}         (size 
#{el.elements["grid"].attribute("size").value.gsub(",", " ")})"  
+        end
+
+        if el.elements["grid"].attribute("pos") then
+          print "\n#{prefix}         (pos 
#{el.elements["grid"].attribute("pos").value.gsub(",", " ")})"
+        end
+        print ")"
+      else
+        puts "unknown font element: "
+      end
     when "translation"
-      puts "  (origin \"#{el.attribute("origin")}\")"
-      puts "  (offset #{el.attribute("x") or 0} #{el.attribute("y") or 0})"
+      print "\n#{prefix}  (origin \"#{el.attribute("origin")}\")"
+      print "\n#{prefix}  (offset #{el.attribute("x") or 0} 
#{el.attribute("y") or 0})"
     when "animation"
-      
+      if el.attribute("loop") and el.attribute("loop").value == "no" then
+        print "\n#{prefix}  (loop #f)"
+      end
+
+      if el.attribute("speed") then
+        print "\n#{prefix}  (speed #{el.attribute("speed")})"
+      end
     else
       raise "Unhandled tag: #{el.name}"
-    end      
+    end    
   }
-  puts " )\n\n"
-  puts ";; EOF ;;\n\n"
+  puts ")\n"
 end
 
+def parse_alias(prefix, dir, section)
+  print "\n#{prefix}(alias (name \"#{section.attribute("name").value}\")"
+  print "\n#{prefix}       (link \"#{section.attribute("link").value}\"))"
+  puts
+end
+
 def parse_section(prefix, dir, section)
   section.each{|el|
     if el.is_a?(REXML::Text) then
@@ -30,30 +69,34 @@
     elsif el.is_a?(REXML::Element) then
       case el.name
       when "section"
-        #puts "(section"
-        #puts "  (name \"#{el.attribute("name")}\")"
-        parse_section("  ", dir + "/#{el.attribute("name")}" , el)
-        #puts " )"
+        print "\n#{prefix}(section (name \"#{el.attribute("name")}\")"
+        parse_section("#{prefix}  ", dir + "/#{el.attribute("name")}" , el)
+        puts "#{prefix} )"
       when "sprite"
         parse_sprite(prefix, dir, el)
       when "surface"
-        puts "surface: #{prefix}/#{el.attribute("name")}"
+        parse_surface(prefix, dir, el)
+      when "alias"
+        parse_alias(prefix, dir, el)
       else
-        puts "Unknown element: #{el.name}"
+        puts "unknown element: #{el.name}"
       end
+    elsif el.is_a?(REXML::Comment) then
+      print "\n#{prefix};; #{el.to_s}"
     else
-      put "<unknown>"
+      puts "<unknown>: #{el.inspect}"
     end
   }
 end
 
 ARGV.each{|arg|
   i = 0
-  puts ";; File: #{arg}"
   dir = File.dirname(arg)
   doc = REXML::Document.new(File.new(arg))
   doc.elements.each("resources") { |el|
-    parse_section("", "", el)
+    print ";; #{arg}\n(pingus-resource"
+    parse_section("  ", "", el)
+    puts " )"
   }
   puts "\n;; EOF ;;"
 }

Modified: branches/pingus_sdl/src/SConscript
===================================================================
--- branches/pingus_sdl/src/SConscript  2007-01-14 10:10:10 UTC (rev 2646)
+++ branches/pingus_sdl/src/SConscript  2007-01-14 17:27:53 UTC (rev 2647)
@@ -228,7 +228,8 @@
 # 'preview_renderer.cxx', 
 # 'range.cxx', 
 'res_descriptor.cxx', 
-'resource.cxx', 
+'resource.cxx',
+'resource_manager.cpp', 
 'resource_modifier.cxx', 
 # 'result.cxx', 
 # 'result_screen.cxx', 

Modified: branches/pingus_sdl/src/path_manager.cxx
===================================================================
--- branches/pingus_sdl/src/path_manager.cxx    2007-01-14 10:10:10 UTC (rev 
2646)
+++ branches/pingus_sdl/src/path_manager.cxx    2007-01-14 17:27:53 UTC (rev 
2647)
@@ -45,10 +45,13 @@
 std::string
 PathManager::complete (const std::string& relative_path)
 {
+  return relative_path;
+#if 0
   std::string comp_path = base_path + "/" + relative_path;
   pout(PINGUS_DEBUG_PATHMGR) << "PathManager: " << relative_path << " -> " << 
comp_path << std::endl;
 
   return comp_path;
+#endif
 }
 
 bool

Modified: branches/pingus_sdl/src/pingus_main.cxx
===================================================================
--- branches/pingus_sdl/src/pingus_main.cxx     2007-01-14 10:10:10 UTC (rev 
2646)
+++ branches/pingus_sdl/src/pingus_main.cxx     2007-01-14 17:27:53 UTC (rev 
2647)
@@ -69,7 +69,7 @@
 #include "debug.hxx"
 //#include "fonts.hxx"
 #include "pingus_menu_manager.hxx"
-// #include "resource.hxx"
+#include "resource.hxx"
 // #include "pingu_action_factory.hxx"
 // #include "credits.hxx"
 #include "sound/sound.hxx"
@@ -969,8 +969,7 @@
 {
 ////   SavegameManager::instance();
 ////   StatManager::init();
-
-////   Resource::init();
+  Resource::init();
   Fonts::init();
 ////   ScreenManager::init();
 ////   PingusMenuManager::init();
@@ -999,7 +998,7 @@
 ////  ScreenManager::deinit();
 ////  StatManager::deinit();
 ////  SavegameManager::deinit();
-////  Resource::deinit();
+  Resource::deinit();
 }
 
 } // namespace Pingus

Modified: branches/pingus_sdl/src/resource.cxx
===================================================================
--- branches/pingus_sdl/src/resource.cxx        2007-01-14 10:10:10 UTC (rev 
2646)
+++ branches/pingus_sdl/src/resource.cxx        2007-01-14 17:27:53 UTC (rev 
2647)
@@ -33,42 +33,40 @@
 #include "debug.hxx"
 
 namespace Pingus {
+ResourceManager Resource::resmgr;
 #if 0
-CL_ResourceManager Resource::resmgr;
 std::map<ResDescriptor, CL_Surface>       Resource::surface_map;
 #endif
+
 void
 Resource::init()
 {
-#if 0
-  
resmgr.add_resources(CL_ResourceManager(path_manager.complete("data/core.xml")));
-  
resmgr.add_resources(CL_ResourceManager(path_manager.complete("data/entrances.xml")));
-  
resmgr.add_resources(CL_ResourceManager(path_manager.complete("data/exits.xml")));
-  
resmgr.add_resources(CL_ResourceManager(path_manager.complete("data/fonts.xml")));
-  
resmgr.add_resources(CL_ResourceManager(path_manager.complete("data/game.xml")));
-  
resmgr.add_resources(CL_ResourceManager(path_manager.complete("data/groundpieces-bridge.xml")));
-  
resmgr.add_resources(CL_ResourceManager(path_manager.complete("data/groundpieces-ground.xml")));
-  
resmgr.add_resources(CL_ResourceManager(path_manager.complete("data/groundpieces-remove.xml")));
-  
resmgr.add_resources(CL_ResourceManager(path_manager.complete("data/groundpieces-solid.xml")));
-  
resmgr.add_resources(CL_ResourceManager(path_manager.complete("data/groundpieces-transparent.xml")));
-  
resmgr.add_resources(CL_ResourceManager(path_manager.complete("data/hotspots.xml")));
-  
resmgr.add_resources(CL_ResourceManager(path_manager.complete("data/liquids.xml")));
-  
resmgr.add_resources(CL_ResourceManager(path_manager.complete("data/pingus-player0.xml")));
-  
resmgr.add_resources(CL_ResourceManager(path_manager.complete("data/pingus-player1.xml")));
-  
resmgr.add_resources(CL_ResourceManager(path_manager.complete("data/pingus-player2.xml")));
-  
resmgr.add_resources(CL_ResourceManager(path_manager.complete("data/pingus-player3.xml")));
-  
resmgr.add_resources(CL_ResourceManager(path_manager.complete("data/pingus-common.xml")));
-  
resmgr.add_resources(CL_ResourceManager(path_manager.complete("data/particles.xml")));
-  
resmgr.add_resources(CL_ResourceManager(path_manager.complete("data/story.xml")));
-  
resmgr.add_resources(CL_ResourceManager(path_manager.complete("data/textures.xml")));
-  
resmgr.add_resources(CL_ResourceManager(path_manager.complete("data/traps.xml")));
-  
resmgr.add_resources(CL_ResourceManager(path_manager.complete("data/worldmaps.xml")));
-  
resmgr.add_resources(CL_ResourceManager(path_manager.complete("data/worldobjs.xml")));
-  
resmgr.add_resources(CL_ResourceManager(path_manager.complete("data/alias.xml")));
-#endif
+  resmgr.add_resources(path_manager.complete("data/core.res"));
+  resmgr.add_resources(path_manager.complete("data/entrances.res"));
+  resmgr.add_resources(path_manager.complete("data/exits.res"));
+  resmgr.add_resources(path_manager.complete("data/fonts.res"));
+  resmgr.add_resources(path_manager.complete("data/game.res"));
+  resmgr.add_resources(path_manager.complete("data/groundpieces-bridge.res"));
+  resmgr.add_resources(path_manager.complete("data/groundpieces-ground.res"));
+  resmgr.add_resources(path_manager.complete("data/groundpieces-remove.res"));
+  resmgr.add_resources(path_manager.complete("data/groundpieces-solid.res"));
+  
resmgr.add_resources(path_manager.complete("data/groundpieces-transparent.res"));
+  resmgr.add_resources(path_manager.complete("data/hotspots.res"));
+  resmgr.add_resources(path_manager.complete("data/liquids.res"));
+  resmgr.add_resources(path_manager.complete("data/pingus-player0.res"));
+  resmgr.add_resources(path_manager.complete("data/pingus-player1.res"));
+  resmgr.add_resources(path_manager.complete("data/pingus-player2.res"));
+  resmgr.add_resources(path_manager.complete("data/pingus-player3.res"));
+  resmgr.add_resources(path_manager.complete("data/pingus-common.res"));
+  resmgr.add_resources(path_manager.complete("data/particles.res"));
+  resmgr.add_resources(path_manager.complete("data/story.res"));
+  resmgr.add_resources(path_manager.complete("data/textures.res"));
+  resmgr.add_resources(path_manager.complete("data/traps.res"));
+  resmgr.add_resources(path_manager.complete("data/worldmaps.res"));
+  resmgr.add_resources(path_manager.complete("data/worldobjs.res"));
+  resmgr.add_resources(path_manager.complete("data/alias.res"));
 }
 
-
 // Returns all resources in the given section
 #if 0
 std::vector<std::string>

Modified: branches/pingus_sdl/src/resource.hxx
===================================================================
--- branches/pingus_sdl/src/resource.hxx        2007-01-14 10:10:10 UTC (rev 
2646)
+++ branches/pingus_sdl/src/resource.hxx        2007-01-14 17:27:53 UTC (rev 
2647)
@@ -24,6 +24,7 @@
 #include <vector>
 #include "sprite.hpp"
 #include "res_descriptor.hxx"
+#include "resource_manager.hpp"
 
 class CL_ResourceManager;
 
@@ -35,8 +36,8 @@
 class Resource
 {
 public:
+  static ResourceManager resmgr;
 #if 0
-  static CL_ResourceManager resmgr;
   static std::map<ResDescriptor, CL_Surface> surface_map;
 
   static CL_Surface load_from_source (const ResDescriptor& res_desc);
@@ -53,6 +54,7 @@
       Returns all sections if blank */
   static std::vector<std::string> get_sections(const std::string &section = 
std::string());
 #endif
+
 public:
   static void init();
   static void deinit();

Added: branches/pingus_sdl/src/resource_manager.cpp
===================================================================
--- branches/pingus_sdl/src/resource_manager.cpp        2007-01-14 10:10:10 UTC 
(rev 2646)
+++ branches/pingus_sdl/src/resource_manager.cpp        2007-01-14 17:27:53 UTC 
(rev 2647)
@@ -0,0 +1,43 @@
+/*  $Id$
+**   __      __ __             ___        __   __ __   __
+**  /  \    /  \__| ____    __| _/_______/  |_|__|  | |  |   ____
+**  \   \/\/   /  |/    \  / __ |/  ___/\   __\  |  | |  | _/ __ \
+**   \        /|  |   |  \/ /_/ |\___ \  |  | |  |  |_|  |_\  ___/
+**    \__/\  / |__|___|  /\____ /____  > |__| |__|____/____/\___  >
+**         \/          \/      \/    \/                         \/
+**  Copyright (C) 2005 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 "resource_manager.hpp"
+
+ResourceManager::ResourceManager()
+{
+}
+
+ResourceManager::~ResourceManager()
+{
+}
+
+void
+ResourceManager::add_resources(const std::string& filename)
+{
+  std::cout << "ResourceManager: " << filename << std::endl;
+}
+
+/* EOF */

Added: branches/pingus_sdl/src/resource_manager.hpp
===================================================================
--- branches/pingus_sdl/src/resource_manager.hpp        2007-01-14 10:10:10 UTC 
(rev 2646)
+++ branches/pingus_sdl/src/resource_manager.hpp        2007-01-14 17:27:53 UTC 
(rev 2647)
@@ -0,0 +1,50 @@
+/*  $Id$
+**   __      __ __             ___        __   __ __   __
+**  /  \    /  \__| ____    __| _/_______/  |_|__|  | |  |   ____
+**  \   \/\/   /  |/    \  / __ |/  ___/\   __\  |  | |  | _/ __ \
+**   \        /|  |   |  \/ /_/ |\___ \  |  | |  |  |_|  |_\  ___/
+**    \__/\  / |__|___|  /\____ /____  > |__| |__|____/____/\___  >
+**         \/          \/      \/    \/                         \/
+**  Copyright (C) 2005 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_RESOURCE_MANAGER_HPP
+#define HEADER_RESOURCE_MANAGER_HPP
+
+#include <string>
+
+/** */
+class ResourceManager
+{
+private:
+  
+
+public:
+  ResourceManager();
+  ~ResourceManager();
+
+  void add_resources(const std::string& filename);
+
+private:
+  ResourceManager (const ResourceManager&);
+  ResourceManager& operator= (const ResourceManager&);
+};
+
+#endif
+
+/* EOF */

Modified: branches/pingus_sdl/src/sexpr_file_reader.cpp
===================================================================
--- branches/pingus_sdl/src/sexpr_file_reader.cpp       2007-01-14 10:10:10 UTC 
(rev 2646)
+++ branches/pingus_sdl/src/sexpr_file_reader.cpp       2007-01-14 17:27:53 UTC 
(rev 2647)
@@ -51,7 +51,7 @@
 
   ~SExprFileReaderImpl()
   {
-    
+    // FIXME: Do we have to free the lisp pointer here or outside of the code?
   }
 
   std::string get_name() const 
@@ -178,8 +178,17 @@
 
   std::vector<std::string> get_section_names() const 
   {
-    return std::vector<std::string>();
+    std::vector<std::string> lst;
+
+    for(size_t i = 1; i < sexpr->get_list_size(); ++i)
+      { // iterate over subsections
+        lisp::Lisp* sub = sexpr->get_list_elem(i);
+        lst.push_back(sub->get_list_elem(0)->get_symbol());
+      }
+
+    return lst;
   }
+
 private:
   lisp::Lisp* get_subsection_item(const char* name) const
   {





reply via email to

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