[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pingus-CVS] r2642 - in branches/pingus_sdl: . data/data src src/math
From: |
grumbel at BerliOS |
Subject: |
[Pingus-CVS] r2642 - in branches/pingus_sdl: . data/data src src/math |
Date: |
Sun, 14 Jan 2007 06:09:37 +0100 |
Author: grumbel
Date: 2007-01-14 06:09:37 +0100 (Sun, 14 Jan 2007)
New Revision: 2642
Added:
branches/pingus_sdl/src/sexpr_file_reader.cpp
branches/pingus_sdl/src/sexpr_file_reader.hpp
Modified:
branches/pingus_sdl/clanlib_2_sexpr.rb
branches/pingus_sdl/data/data/core.xml
branches/pingus_sdl/src/SConscript
branches/pingus_sdl/src/file_reader.cxx
branches/pingus_sdl/src/file_reader.hxx
branches/pingus_sdl/src/file_reader_impl.hxx
branches/pingus_sdl/src/math/
branches/pingus_sdl/src/pingus_level.hxx
branches/pingus_sdl/src/pingus_main.cxx
branches/pingus_sdl/src/xml_file_reader.cxx
Log:
- some more work on the SExprParser thingy
Modified: branches/pingus_sdl/clanlib_2_sexpr.rb
===================================================================
--- branches/pingus_sdl/clanlib_2_sexpr.rb 2007-01-13 23:42:24 UTC (rev
2641)
+++ branches/pingus_sdl/clanlib_2_sexpr.rb 2007-01-14 05:09:37 UTC (rev
2642)
@@ -2,15 +2,27 @@
require "rexml/document"
-def parse_sprite(prefix, sprite)
+def parse_sprite(prefix, dir, sprite)
+ puts ";; data/images/#{dir[1..-1]}/#{sprite.attribute("name")}.sprite"
puts "(sprite"
- puts " (name \"#{sprite.attribute("name")}\")"
- sprite.elements.each("image") {|el|
- puts " (file \"#{el.attribute("file")}\"))"
+ sprite.elements.each{|el|
+ case el.name
+ when "image"
+ puts " (images \"#{File.basename(el.attribute("file").value)}\")"
+ when "translation"
+ puts " (origin \"#{el.attribute("origin")}\")"
+ puts " (offset #{el.attribute("x") or 0} #{el.attribute("y") or 0})"
+ when "animation"
+
+ else
+ raise "Unhandled tag: #{el.name}"
+ end
}
+ puts " )\n\n"
+ puts ";; EOF ;;\n\n"
end
-def parse_section(prefix, section)
+def parse_section(prefix, dir, section)
section.each{|el|
if el.is_a?(REXML::Text) then
# skip text nodes, just indention junk
@@ -18,9 +30,12 @@
elsif el.is_a?(REXML::Element) then
case el.name
when "section"
- parse_section("#{prefix}/#{el.attribute("name")}", el)
+ #puts "(section"
+ #puts " (name \"#{el.attribute("name")}\")"
+ parse_section(" ", dir + "/#{el.attribute("name")}" , el)
+ #puts " )"
when "sprite"
- parse_sprite(prefix, el)
+ parse_sprite(prefix, dir, el)
when "surface"
puts "surface: #{prefix}/#{el.attribute("name")}"
else
@@ -34,12 +49,13 @@
ARGV.each{|arg|
i = 0
- puts "### Parsing #{arg}"
+ puts ";; File: #{arg}"
dir = File.dirname(arg)
doc = REXML::Document.new(File.new(arg))
doc.elements.each("resources") { |el|
- parse_section("", el)
+ parse_section("", "", el)
}
+ puts "\n;; EOF ;;"
}
# EOF #
Modified: branches/pingus_sdl/data/data/core.xml
===================================================================
--- branches/pingus_sdl/data/data/core.xml 2007-01-13 23:42:24 UTC (rev
2641)
+++ branches/pingus_sdl/data/data/core.xml 2007-01-14 05:09:37 UTC (rev
2642)
@@ -1,4 +1,4 @@
-<resources>
+<resources>
<section name="core">
<section name="cursors">
<sprite name="editor">
@@ -125,13 +125,13 @@
<sprite name="armageddon_anim">
<image file="../images/core/buttons/armageddon_anim.png">
<grid array="14,1" size="36,57" pos="0,0"/>
- </image>
+ </image>
</sprite>
</section>
<section name="menu">
- <sprite name="filedialog">
- <image file="../images/core/menu/filedialog.png" />
- </sprite>
+ <sprite name="filedialog">
+ <image file="../images/core/menu/filedialog.png" />
+ </sprite>
<sprite name="folder">
<image file="../images/core/menu/folder.png" />
</sprite>
@@ -220,9 +220,9 @@
</section>
<section name="misc">
- <sprite name="checkbox_clicked">
- <image file="../images/core/misc/checkbox_clicked.png"/>
- </sprite>
+ <sprite name="checkbox_clicked">
+ <image file="../images/core/misc/checkbox_clicked.png"/>
+ </sprite>
<sprite name="next">
<image file="../images/core/misc/next.png"/>
</sprite>
Modified: branches/pingus_sdl/src/SConscript
===================================================================
--- branches/pingus_sdl/src/SConscript 2007-01-13 23:42:24 UTC (rev 2641)
+++ branches/pingus_sdl/src/SConscript 2007-01-14 05:09:37 UTC (rev 2642)
@@ -135,7 +135,8 @@
'exit_menu.cxx',
# 'file_dialog.cxx',
# 'file_dialog_item.cxx',
-# 'file_reader.cxx',
+'file_reader.cxx',
+'sexpr_file_reader.cpp',
'fonts.cxx',
'font.cpp',
'sprite.cpp',
Modified: branches/pingus_sdl/src/file_reader.cxx
===================================================================
--- branches/pingus_sdl/src/file_reader.cxx 2007-01-13 23:42:24 UTC (rev
2641)
+++ branches/pingus_sdl/src/file_reader.cxx 2007-01-14 05:09:37 UTC (rev
2642)
@@ -22,7 +22,7 @@
namespace Pingus {
-FileReader::FileReader(CL_SharedPtr<FileReaderImpl> impl_)
+FileReader::FileReader(SharedPtr<FileReaderImpl> impl_)
: impl(impl_)
{
}
@@ -35,7 +35,7 @@
std::string
FileReader::get_name() const
{
- if (impl)
+ if (impl.get())
return impl->get_name();
else
return "";
@@ -44,7 +44,7 @@
bool
FileReader::read_int(const char* name, int& value) const
{
- if (impl)
+ if (impl.get())
return impl->read_int(name, value);
else
return false;
@@ -53,7 +53,7 @@
bool
FileReader::read_float (const char* name, float& value) const
{
- if (impl)
+ if (impl.get())
return impl->read_float(name, value);
else
return false;
@@ -62,7 +62,7 @@
bool
FileReader::read_bool (const char* name, bool& value) const
{
- if (impl)
+ if (impl.get())
return impl->read_bool(name, value);
else
return false;
@@ -71,7 +71,7 @@
bool
FileReader::read_string(const char* name, std::string& value) const
{
- if (impl)
+ if (impl.get())
return impl->read_string(name, value);
else
return false;
@@ -80,16 +80,16 @@
bool
FileReader::read_vector(const char* name, Vector& value) const
{
- if (impl)
+ if (impl.get())
return impl->read_vector(name, value);
else
return false;
}
bool
-FileReader::read_color(const char* name, CL_Colorf& value) const
+FileReader::read_color(const char* name, Color& value) const
{
- if (impl)
+ if (impl.get())
return impl->read_color(name, value);
else
return false;
@@ -98,25 +98,27 @@
bool
FileReader::read_desc(const char* name, ResDescriptor& desc) const
{
- if (impl)
+ if (impl.get())
return impl->read_desc(name, desc);
else
return false;
}
+#if 0
bool
FileReader::read_size (const char* name, CL_Size& value) const
{
- if (impl)
+ if (impl.get())
return impl->read_size(name, value);
else
return false;
}
+#endif
bool
FileReader::read_section(const char* name, FileReader& reader) const
{
- if (impl)
+ if (impl.get())
return impl->read_section(name, reader);
else
return false;
@@ -125,7 +127,7 @@
std::vector<std::string>
FileReader::get_section_names() const
{
- if (impl)
+ if (impl.get())
return impl->get_section_names();
else
return std::vector<std::string>();
@@ -134,7 +136,7 @@
std::vector<FileReader>
FileReader::get_sections() const
{
- if (impl)
+ if (impl.get())
return impl->get_sections();
else
return std::vector<FileReader>();
Modified: branches/pingus_sdl/src/file_reader.hxx
===================================================================
--- branches/pingus_sdl/src/file_reader.hxx 2007-01-13 23:42:24 UTC (rev
2641)
+++ branches/pingus_sdl/src/file_reader.hxx 2007-01-14 05:09:37 UTC (rev
2642)
@@ -26,7 +26,7 @@
class CL_Size;
class CL_Sizef;
-class CL_Colorf;
+class Color;
namespace Pingus {
@@ -51,8 +51,8 @@
bool read_bool (const char* name, bool&) const;
bool read_string(const char* name, std::string&) const;
bool read_vector(const char* name, Vector&) const;
- bool read_color (const char* name, CL_Colorf&) const;
- bool read_size (const char* name, CL_Size&) const;
+ bool read_color (const char* name, Color&) const;
+ //// bool read_size (const char* name, CL_Size&) const;
bool read_desc (const char* name, ResDescriptor&) const;
bool read_section(const char* name, FileReader&) const;
FileReader read_section(const char* name) const;
Modified: branches/pingus_sdl/src/file_reader_impl.hxx
===================================================================
--- branches/pingus_sdl/src/file_reader_impl.hxx 2007-01-13 23:42:24 UTC
(rev 2641)
+++ branches/pingus_sdl/src/file_reader_impl.hxx 2007-01-14 05:09:37 UTC
(rev 2642)
@@ -20,11 +20,12 @@
#ifndef HEADER_FILE_READER_IMPL_HXX
#define HEADER_FILE_READER_IMPL_HXX
+#include <vector>
#include <string>
class CL_Size;
class CL_Sizef;
-class CL_Colorf;
+class Color;
namespace Pingus {
@@ -45,9 +46,9 @@
virtual bool read_bool (const char* name, bool&) const =0;
virtual bool read_string(const char* name, std::string&) const =0;
virtual bool read_vector(const char* name, Vector&) const =0;
- virtual bool read_color (const char* name, CL_Colorf&) const =0;
+ virtual bool read_color (const char* name, Color&) const =0;
virtual bool read_desc (const char* name, ResDescriptor&) const =0;
- virtual bool read_size (const char* name, CL_Size&) const =0;
+ //// virtual bool read_size (const char* name, CL_Size&) const =0;
virtual bool read_section(const char* name, FileReader&) const =0;
virtual std::vector<FileReader> get_sections() const =0;
virtual std::vector<std::string> get_section_names() const =0;
Property changes on: branches/pingus_sdl/src/math
___________________________________________________________________
Name: svn:ignore
+
old/
.sconsign
semantic.cache
Modified: branches/pingus_sdl/src/pingus_level.hxx
===================================================================
--- branches/pingus_sdl/src/pingus_level.hxx 2007-01-13 23:42:24 UTC (rev
2641)
+++ branches/pingus_sdl/src/pingus_level.hxx 2007-01-14 05:09:37 UTC (rev
2642)
@@ -72,7 +72,7 @@
const std::string& get_music() const;
/** Returns the light to be used in this level */
- const CL_Colorf& get_ambient_light() const;
+ const Color& get_ambient_light() const;
/** Returns the body of this file */
const std::vector<FileReader>& get_objects() const;
Modified: branches/pingus_sdl/src/pingus_main.cxx
===================================================================
--- branches/pingus_sdl/src/pingus_main.cxx 2007-01-13 23:42:24 UTC (rev
2641)
+++ branches/pingus_sdl/src/pingus_main.cxx 2007-01-14 05:09:37 UTC (rev
2642)
@@ -29,6 +29,10 @@
#include <signal.h>
#include <locale.h>
#include <iostream>
+#include <physfs.h>
+#include "lisp/lisp.hpp"
+#include "lisp/parser.hpp"
+#include "sexpr_file_reader.hpp"
#include "SDL.h"
@@ -584,13 +588,13 @@
std::list<std::string> file_list;
file_list.push_back ("data/core.xml");
-// if (!path_manager.find_path (file_list))
-// {
-// std::cout << "Error: Couldn't find 'data/core.xml', please set the
enviroment variable\n"
-// << "PINGUS_DATADIR to the path of the file `data/core.scr'
or use the\n"
-// << "-d option." << std::endl;
-// exit(EXIT_FAILURE);
-// }
+ // if (!path_manager.find_path (file_list))
+ // {
+ // std::cout << "Error: Couldn't find 'data/core.xml', please set the
enviroment variable\n"
+ // << "PINGUS_DATADIR to the path of the file
`data/core.scr' or use the\n"
+ // << "-d option." << std::endl;
+ // exit(EXIT_FAILURE);
+ // }
dictionary_manager.add_directory(path_manager.complete("po/"));
// Language is automatically picked from env variable
@@ -679,6 +683,27 @@
void
PingusMain::start_game ()
{
+ { // SExpr Parser Test code
+ std::cout << "Parser Test" << std::endl;
+ lisp::Lisp* sexpr = lisp::Parser::parse("test.scm");
+ std::cout << "Parser Test..." << std::endl;
+ std::cout << sexpr->get_type() << " " << sexpr->get_list_size() <<
std::endl;
+ sexpr = sexpr->get_list_elem(0);
+ if (sexpr)
+ {
+ SExprFileReader reader(sexpr);
+
+ int t = 0;
+ reader.read_int("test", t);
+
+ std::cout << reader.get_name() << ": t == " << t << std::endl;
+ }
+ else
+ {
+ std::cout << "Not found" << std::endl;
+ }
+ }
+
if (verbose) {
pout << _("PingusMain: Starting Main: ") << SDL_GetTicks() << std::endl;
}
@@ -777,6 +802,9 @@
int
PingusMain::main(int argc, char** argv)
{
+ PHYSFS_init(argv[0]);
+ PHYSFS_addToSearchPath("data/", 0);
+
executable_name = argv[0];
// Register the segfault_handler
@@ -847,6 +875,8 @@
deinit_pingus();
deinit_clanlib();
+ PHYSFS_deinit();
+
return 0;
}
Added: branches/pingus_sdl/src/sexpr_file_reader.cpp
===================================================================
--- branches/pingus_sdl/src/sexpr_file_reader.cpp 2007-01-13 23:42:24 UTC
(rev 2641)
+++ branches/pingus_sdl/src/sexpr_file_reader.cpp 2007-01-14 05:09:37 UTC
(rev 2642)
@@ -0,0 +1,145 @@
+/* $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 <assert.h>
+#include "file_reader_impl.hxx"
+#include "sexpr_file_reader.hpp"
+
+namespace Pingus {
+
+class SExprFileReaderImpl: public FileReaderImpl
+{
+public:
+ lisp::Lisp* sexpr;
+
+ SExprFileReaderImpl(lisp::Lisp* sexpr_)
+ : sexpr(sexpr_)
+ {
+ assert(sexpr->get_type() == lisp::Lisp::TYPE_LIST &&
+ sexpr->get_list_size() >= 1);
+
+ for(size_t i = 1; i < sexpr->get_list_size(); ++i)
+ { // iterate over subsections
+ sexpr->get_list_elem(i);
+ }
+ }
+
+ ~SExprFileReaderImpl()
+ {
+
+ }
+
+ std::string get_name() const
+ {
+ return sexpr->get_list_elem(0)->get_symbol();
+ }
+
+ bool read_int (const char* name, int& v) const
+ {
+ lisp::Lisp* sub = get_subsection(name);
+ if (sub && sub->get_list_size() == 2)
+ {
+ if (sub->get_list_elem(1)->get_type() == lisp::Lisp::TYPE_INT)
+ {
+ v = sub->get_list_elem(1)->get_int();
+ return true;
+ }
+ }
+ return false;
+ }
+
+ bool read_float (const char* name, float&) const
+ {
+ return false;
+ }
+
+ bool read_bool (const char* name, bool&) const
+ {
+ return false;
+ }
+
+ bool read_string(const char* name, std::string&) const
+ {
+ return false;
+ }
+
+ bool read_vector(const char* name, Vector&) const
+ {
+ return false;
+ }
+
+ bool read_color (const char* name, Color&) const
+ {
+ return false;
+ }
+
+ bool read_desc (const char* name, ResDescriptor&) const
+ {
+ return false;
+ }
+
+ bool read_size (const char* name, CL_Size&) const
+ {
+ return false;
+ }
+
+ bool read_section(const char* name, FileReader&) const
+ {
+ return false;
+ }
+
+ std::vector<FileReader> get_sections() const
+ {
+ return std::vector<FileReader>();
+ }
+
+ std::vector<std::string> get_section_names() const
+ {
+ return std::vector<std::string>();
+ }
+
+private:
+ lisp::Lisp* get_subsection(const char* name) const
+ {
+ for(size_t i = 1; i < sexpr->get_list_size(); ++i)
+ { // iterate over subsections
+ lisp::Lisp* sub = sexpr->get_list_elem(i);
+ if (strcmp(sub->get_list_elem(0)->get_symbol(), name) == 0)
+ return sub;
+ }
+ return 0;
+ }
+
+};
+
+SExprFileReader::SExprFileReader(lisp::Lisp* lisp)
+ : FileReader(SharedPtr<FileReaderImpl>(new SExprFileReaderImpl(lisp)))
+{
+
+}
+
+} // namespace Pingus
+
+/* EOF */
Added: branches/pingus_sdl/src/sexpr_file_reader.hpp
===================================================================
--- branches/pingus_sdl/src/sexpr_file_reader.hpp 2007-01-13 23:42:24 UTC
(rev 2641)
+++ branches/pingus_sdl/src/sexpr_file_reader.hpp 2007-01-14 05:09:37 UTC
(rev 2642)
@@ -0,0 +1,46 @@
+/* $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_SEXPR_FILE_READER_HPP
+#define HEADER_SEXPR_FILE_READER_HPP
+
+#include "file_reader.hxx"
+#include "lisp/lisp.hpp"
+
+namespace Pingus {
+
+/** */
+class SExprFileReader : public FileReader
+{
+private:
+public:
+ SExprFileReader(lisp::Lisp* lisp);
+};
+
+} // namespace Pingus
+
+#endif
+
+/* EOF */
Modified: branches/pingus_sdl/src/xml_file_reader.cxx
===================================================================
--- branches/pingus_sdl/src/xml_file_reader.cxx 2007-01-13 23:42:24 UTC (rev
2641)
+++ branches/pingus_sdl/src/xml_file_reader.cxx 2007-01-14 05:09:37 UTC (rev
2642)
@@ -206,7 +206,7 @@
};
XMLFileReader::XMLFileReader(CL_DomElement element)
- : FileReader(CL_SharedPtr<FileReaderImpl>(new XMLFileReaderImpl(element)))
+ : FileReader(SharedPtr<FileReaderImpl>(new XMLFileReaderImpl(element)))
{
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pingus-CVS] r2642 - in branches/pingus_sdl: . data/data src src/math,
grumbel at BerliOS <=