pingus-cvs
[Top][All Lists]
Advanced

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

[Pingus-CVS] r2670 - in branches/pingus_sdl/src: . components lisp world


From: grumbel at BerliOS
Subject: [Pingus-CVS] r2670 - in branches/pingus_sdl/src: . components lisp worldobjs
Date: Tue, 16 Jan 2007 08:40:42 +0100

Author: grumbel
Date: 2007-01-16 08:40:41 +0100 (Tue, 16 Jan 2007)
New Revision: 2670

Modified:
   branches/pingus_sdl/src/components/button_panel.cxx
   branches/pingus_sdl/src/lisp/lisp.hpp
   branches/pingus_sdl/src/pingus_level.cxx
   branches/pingus_sdl/src/pingus_main.cxx
   branches/pingus_sdl/src/plf_res_mgr.cxx
   branches/pingus_sdl/src/sexpr_file_reader.cpp
   branches/pingus_sdl/src/sprite.cpp
   branches/pingus_sdl/src/worldobj.hxx
   branches/pingus_sdl/src/worldobj_factory.cxx
   branches/pingus_sdl/src/worldobjs/solid_color_background.hxx
   branches/pingus_sdl/src/worldobjs/surface_background.cxx
Log:
- multiple fixes in the file parsing, levels now load and show up, at least 
some parts of them

Modified: branches/pingus_sdl/src/components/button_panel.cxx
===================================================================
--- branches/pingus_sdl/src/components/button_panel.cxx 2007-01-16 06:56:05 UTC 
(rev 2669)
+++ branches/pingus_sdl/src/components/button_panel.cxx 2007-01-16 07:40:41 UTC 
(rev 2670)
@@ -61,6 +61,11 @@
                                                    0)); 
//FIXMEcontroller->get_owner ()));
     }
 
+  if (a_buttons.empty())
+    {
+      std::cout << "Error: ButtonPanel: No a_buttons! " << std::endl;
+    }
+
   pressed_button = 0;
   ////wheel_slot = CL_Mouse::sig_key_down().connect(this, 
&ButtonPanel::on_wheel_move);
 }

Modified: branches/pingus_sdl/src/lisp/lisp.hpp
===================================================================
--- branches/pingus_sdl/src/lisp/lisp.hpp       2007-01-16 06:56:05 UTC (rev 
2669)
+++ branches/pingus_sdl/src/lisp/lisp.hpp       2007-01-16 07:40:41 UTC (rev 
2670)
@@ -86,8 +86,16 @@
   float get_float() const
   {
     if(type != TYPE_FLOAT)
-      throw std::runtime_error("Lisp is not a float");
-    return v.float_;
+      {
+        if(type != TYPE_INT)
+          throw std::runtime_error("Lisp is not a float");
+        else
+          return v.int_;
+      }
+    else
+      {    
+        return v.float_;
+      }
   }
 
   bool get_bool() const

Modified: branches/pingus_sdl/src/pingus_level.cxx
===================================================================
--- branches/pingus_sdl/src/pingus_level.cxx    2007-01-16 06:56:05 UTC (rev 
2669)
+++ branches/pingus_sdl/src/pingus_level.cxx    2007-01-16 07:40:41 UTC (rev 
2670)
@@ -49,8 +49,13 @@
         std::cout << "Unknown Levelfile Version: " << version << std::endl;
 
       FileReader head;
-      if (reader.read_section("head", head))
+      if (!reader.read_section("head", head))
         {
+          PingusError::raise("Error: (head) section not found in '" + filename 
+ "'");
+        }
+      else
+        {
+          std::cout << "Reading head" << std::endl;
           head.read_string("levelname",        impl->levelname);
           head.read_string("description",      impl->description);
           head.read_size  ("levelsize",        impl->size);
@@ -61,24 +66,31 @@
           head.read_int   ("number-to-save",   impl->number_to_save);
           head.read_color ("ambient-light",    impl->ambient_light);
           head.read_string("author",           impl->author);
+
+          std::cout << "Size: " << impl->size.width << " " << 
impl->size.height << std::endl;
           
           FileReader actions;
-          if (reader.read_section("actions", actions))
+          if (head.read_section("actions", actions))
             {
-              std::vector<std::string> lst = reader.get_section_names();
+              std::vector<std::string> lst = actions.get_section_names();
               for(std::vector<std::string>::iterator i = lst.begin(); i != 
lst.end(); ++i)
                 {
                   int count = 0;
+                  std::cout << "Actions: " << i->c_str() << std::endl;
                   if (actions.read_int(i->c_str(), count))
                     impl->actions[*i] = count;
                 }
             }
+          else
+            {
+              PingusError::raise("Error: (pingus-level head actions) not found 
in '" + filename + "'"); 
+            }
         }
       
       FileReader objects;
       if (reader.read_section("objects", objects))
         {
-          std::vector<FileReader> object_lst = reader.get_sections();
+          std::vector<FileReader> object_lst = objects.get_sections();
           for(std::vector<FileReader>::iterator i = object_lst.begin(); i != 
object_lst.end(); ++i)
             {
               impl->objects.push_back(*i);

Modified: branches/pingus_sdl/src/pingus_main.cxx
===================================================================
--- branches/pingus_sdl/src/pingus_main.cxx     2007-01-16 06:56:05 UTC (rev 
2669)
+++ branches/pingus_sdl/src/pingus_main.cxx     2007-01-16 07:40:41 UTC (rev 
2670)
@@ -786,6 +786,7 @@
 {
   PHYSFS_init(argv[0]);
   PHYSFS_addToSearchPath("data", 0);
+  PHYSFS_addToSearchPath(".", 0);
 
   executable_name = argv[0];
 

Modified: branches/pingus_sdl/src/plf_res_mgr.cxx
===================================================================
--- branches/pingus_sdl/src/plf_res_mgr.cxx     2007-01-16 06:56:05 UTC (rev 
2669)
+++ branches/pingus_sdl/src/plf_res_mgr.cxx     2007-01-16 07:40:41 UTC (rev 
2670)
@@ -39,10 +39,10 @@
     { // Entry not cached, so load it and add it to cache
       pout(PINGUS_DEBUG_LOADING) << "PLFResMgr: Loading level from DISK: '" << 
res_name << "' -> '" << filename << "'" << std::endl;
 
-      //PingusLevel plf = XMLPingusLevel(res_name, filename);
+      PingusLevel plf(res_name, filename);
 
       PLFEntry entry;
-      ////entry.plf   = plf;
+      entry.plf   = plf;
       entry.mtime = System::get_mtime(filename);
 
       plf_map[res_name]  = entry;

Modified: branches/pingus_sdl/src/sexpr_file_reader.cpp
===================================================================
--- branches/pingus_sdl/src/sexpr_file_reader.cpp       2007-01-16 06:56:05 UTC 
(rev 2669)
+++ branches/pingus_sdl/src/sexpr_file_reader.cpp       2007-01-16 07:40:41 UTC 
(rev 2670)
@@ -74,10 +74,22 @@
   bool read_float (const char* name, float& v) const 
   {
     lisp::Lisp* item = get_subsection_item(name);
-    if (item && item->get_type() == lisp::Lisp::TYPE_FLOAT)
+    if (item)
       {
-        v = item->get_float();
-        return true;
+        if (item->get_type() == lisp::Lisp::TYPE_FLOAT)
+          {
+            v = item->get_float();
+            return true;
+          }
+        else if (item->get_type() == lisp::Lisp::TYPE_INT)
+          {
+            v = item->get_int();
+            return true;
+          }
+        else
+          {
+            return false;
+          }
       }
     return false;
   }
@@ -95,6 +107,7 @@
 
   bool read_string(const char* name, std::string& v) const 
   {
+    // FIXME: add multiline reading here
     lisp::Lisp* item = get_subsection_item(name);
     if (item)
       {
@@ -114,7 +127,7 @@
 
   bool read_vector(const char* name, Vector3f& v) const
   {
-    lisp::Lisp* sub = get_subsection_item(name);
+    lisp::Lisp* sub = get_subsection(name);
     if (sub && sub->get_list_size() == 4)
       {
         v = Vector3f(sub->get_list_elem(1)->get_float(),
@@ -127,19 +140,21 @@
 
   bool read_size(const char* name, Size& v) const
   {
-    lisp::Lisp* sub = get_subsection_item(name);
+    lisp::Lisp* sub = get_subsection(name);
     if (sub && sub->get_list_size() == 3)
       {
         v.width  = sub->get_list_elem(1)->get_int();
         v.height = sub->get_list_elem(2)->get_int();
         return true;
       }    
+    std::cout << "Reading size: " << v.width << " " << v.height << std::endl;
+
     return false;
   }
 
   bool read_vector2i(const char* name, Vector2i& v) const
   {
-    lisp::Lisp* sub = get_subsection_item(name);
+    lisp::Lisp* sub = get_subsection(name);
     if (sub && sub->get_list_size() == 3)
       {
         v.x = sub->get_list_elem(1)->get_int();
@@ -151,7 +166,7 @@
 
   bool read_color (const char* name, Color& v) const
   {
-    lisp::Lisp* sub = get_subsection_item(name);
+    lisp::Lisp* sub = get_subsection(name);
     if (sub && sub->get_list_size() == 5)
       {
         v = Color(int(sub->get_list_elem(1)->get_float() * 255),
@@ -205,6 +220,7 @@
       { // iterate over subsections
         lisp::Lisp* sub = sexpr->get_list_elem(i);
         lst.push_back(sub->get_list_elem(0)->get_symbol());
+        std::cout << sub->get_list_elem(0)->get_symbol() << std::endl;
       }
 
     return lst;

Modified: branches/pingus_sdl/src/sprite.cpp
===================================================================
--- branches/pingus_sdl/src/sprite.cpp  2007-01-16 06:56:05 UTC (rev 2669)
+++ branches/pingus_sdl/src/sprite.cpp  2007-01-16 07:40:41 UTC (rev 2670)
@@ -71,8 +71,6 @@
       }
     
     offset = calc_origin(origin, Size(surface->w, surface->h)) + offset;
-
-    std::cout << "offset: " << offset.x << ", " << offset.y << std::endl;
   }
 
   ~SpriteImpl()
@@ -116,19 +114,26 @@
 Sprite::draw(float x, float y, SDL_Surface* target)
 {
   //std::cout << "Sprite: draw; " << x << ", " << y << std::endl;
-  impl->draw(x, y, target);
+  if (impl.get())
+    impl->draw(x, y, target);
 }
 
 int
 Sprite::get_width()
 {
-  return impl->surface->w;
+  if (impl.get() && impl->surface)
+    return impl->surface->w;
+  else
+    return 0;
 }
 
 int
 Sprite::get_height()
 {
-  return impl->surface->h;
+  if (impl.get() && impl->surface)
+    return impl->surface->h;
+  else
+    return 0;
 }
 
 Sprite::operator bool()

Modified: branches/pingus_sdl/src/worldobj.hxx
===================================================================
--- branches/pingus_sdl/src/worldobj.hxx        2007-01-16 06:56:05 UTC (rev 
2669)
+++ branches/pingus_sdl/src/worldobj.hxx        2007-01-16 07:40:41 UTC (rev 
2670)
@@ -22,8 +22,8 @@
 
 #include "pingus.hxx"
 #include "file_reader.hxx"
+#include "sprite.hpp"
 
-
 class SceneContext;
 class SmallMap;
 class World;

Modified: branches/pingus_sdl/src/worldobj_factory.cxx
===================================================================
--- branches/pingus_sdl/src/worldobj_factory.cxx        2007-01-16 06:56:05 UTC 
(rev 2669)
+++ branches/pingus_sdl/src/worldobj_factory.cxx        2007-01-16 07:40:41 UTC 
(rev 2670)
@@ -20,7 +20,7 @@
 #include <iostream>
 #include "pingus_error.hxx"
 #include "worldobj_factory.hxx"
-#if 0
+
 #include "worldobjs/conveyor_belt.hxx"
 #include "worldobjs/entrance.hxx"
 #include "worldobjs/exit.hxx"
@@ -46,7 +46,6 @@
 #include "worldobjs/woodthing.hxx"
 
 using namespace WorldObjs;
-#endif
 
 WorldObjFactory* WorldObjFactory::instance_ = 0;
 
@@ -97,7 +96,6 @@
     {
       instance_ = new WorldObjFactory ();
 
-#if 0
       // Registring Factories
       new WorldObjFactoryImpl<Liquid>("liquid");
       new WorldObjFactoryImpl<Hotspot>("hotspot");
@@ -135,7 +133,6 @@
 
       // Groundpieces
       new WorldObjFactoryImpl<Groundpiece>("groundpiece");
-#endif
     }
 
   return instance_;

Modified: branches/pingus_sdl/src/worldobjs/solid_color_background.hxx
===================================================================
--- branches/pingus_sdl/src/worldobjs/solid_color_background.hxx        
2007-01-16 06:56:05 UTC (rev 2669)
+++ branches/pingus_sdl/src/worldobjs/solid_color_background.hxx        
2007-01-16 07:40:41 UTC (rev 2670)
@@ -20,6 +20,8 @@
 #ifndef HEADER_PINGUS_WORLDOBJS_SOLID_COLOR_BACKGROUND_HXX
 #define HEADER_PINGUS_WORLDOBJS_SOLID_COLOR_BACKGROUND_HXX
 
+#include "../math/color.hpp"
+#include "../pixel_buffer.hpp"
 #include "../worldobj.hxx"
 
 namespace WorldObjsData {

Modified: branches/pingus_sdl/src/worldobjs/surface_background.cxx
===================================================================
--- branches/pingus_sdl/src/worldobjs/surface_background.cxx    2007-01-16 
06:56:05 UTC (rev 2669)
+++ branches/pingus_sdl/src/worldobjs/surface_background.cxx    2007-01-16 
07:40:41 UTC (rev 2670)
@@ -123,6 +123,9 @@
 void
 SurfaceBackground::update()
 {
+  if (!bg_surface)
+    return;
+
   if (scroll_x) 
     {
       scroll_ox += scroll_x;
@@ -147,6 +150,9 @@
 void
 SurfaceBackground::draw (SceneContext& gc)
 {
+  if (!bg_surface)
+    return;
+
   if (fast_mode)
     {
       ////Display::clear();





reply via email to

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