windstille-devel
[Top][All Lists]
Advanced

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

[Windstille-devel] rev 389 - trunk/src


From: Ingo Ruhnke
Subject: [Windstille-devel] rev 389 - trunk/src
Date: Fri, 04 Jun 2004 14:58:51 +0200

Author: grumbel
Date: 2004-06-04 14:58:51 +0200 (Fri, 04 Jun 2004)
New Revision: 389

Added:
   trunk/src/objmap_path_node.cxx
   trunk/src/objmap_path_node.hxx
Modified:
   trunk/src/SConstruct
   trunk/src/flexlay_wrap.i
   trunk/src/objmap_object.cxx
   trunk/src/objmap_object.hxx
   trunk/src/shared_ptr.hxx
   trunk/src/supertux.py
Log:
- added some primitiv path support

Modified: trunk/src/SConstruct
===================================================================
--- trunk/src/SConstruct        2004-06-03 23:42:17 UTC (rev 388)
+++ trunk/src/SConstruct        2004-06-04 12:58:51 UTC (rev 389)
@@ -92,6 +92,7 @@
     'object_selector.cxx',
     'object_transform_command.cxx',
     'objmap_object.cxx',
+    'objmap_path_node.cxx',
     'objmap_object_impl.cxx',
     'objmap_select_tool.cxx',
     'objmap_sprite_object.cxx',

Modified: trunk/src/flexlay_wrap.i
===================================================================
--- trunk/src/flexlay_wrap.i    2004-06-03 23:42:17 UTC (rev 388)
+++ trunk/src/flexlay_wrap.i    2004-06-04 12:58:51 UTC (rev 389)
@@ -52,6 +52,7 @@
 #include "objmap_sprite_object.hxx"
 #include "objmap_object.hxx"
 #include "zoom_tool.hxx"
+#include "objmap_path_node.hxx"
 
 #include "netpanzer.hxx" 
 %}
@@ -105,8 +106,8 @@
 %include "objmap_object.hxx"
 %include "zoom_tool.hxx" 
 %include "graphic_context_state.hxx"
+%include "objmap_path_node.hxx"
 
 %include "netpanzer.hxx" 
 
-
 /* EOF */

Modified: trunk/src/objmap_object.cxx
===================================================================
--- trunk/src/objmap_object.cxx 2004-06-03 23:42:17 UTC (rev 388)
+++ trunk/src/objmap_object.cxx 2004-06-04 12:58:51 UTC (rev 389)
@@ -62,6 +62,13 @@
 }
 
 void
+ObjMapObject::set_metadata(MetaData data_)
+{
+  if (impl.get())
+    impl->data = data_;
+}
+
+void
 ObjMapObject::draw()
 {
   if (impl.get())

Modified: trunk/src/objmap_object.hxx
===================================================================
--- trunk/src/objmap_object.hxx 2004-06-03 23:42:17 UTC (rev 388)
+++ trunk/src/objmap_object.hxx 2004-06-04 12:58:51 UTC (rev 389)
@@ -39,6 +39,7 @@
   void     set_pos(const CL_Point& p);
 
   MetaData get_metadata() const;
+  void     set_metadata(MetaData data_);
 
   void draw();
   CL_Rect get_bound_rect() const;

Added: trunk/src/objmap_path_node.cxx
===================================================================
--- trunk/src/objmap_path_node.cxx      2004-06-03 23:42:17 UTC (rev 388)
+++ trunk/src/objmap_path_node.cxx      2004-06-04 12:58:51 UTC (rev 389)
@@ -0,0 +1,105 @@
+//  $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 <ClanLib/Display/display.h>
+#include "objmap_object_impl.hxx"
+#include "objmap_path_node.hxx"
+
+class ObjMapPathNodeImpl : public ObjMapObjectImpl
+{
+public:
+  ObjMapPathNodeImpl* prev;
+  ObjMapPathNodeImpl* next;
+  
+  ObjMapPathNodeImpl();
+
+  void draw();
+  CL_Rect get_bound_rect() const;
+};
+
+ObjMapPathNodeImpl::ObjMapPathNodeImpl()
+{
+  next = 0;
+  prev = 0;
+}
+
+void
+ObjMapPathNodeImpl::draw()
+{
+  CL_Display::fill_rect(CL_Rect(pos-CL_Point(16,16), CL_Size(32, 32)), 
+                        CL_Color(200, 255, 200));
+  if (next)
+    {
+      CL_Display::draw_line(pos.x, pos.y,
+                            (pos.x + next->pos.x)/2, (pos.y+next->pos.y)/2,
+                            CL_Color(255, 255, 0));
+
+      CL_Display::draw_line((pos.x + next->pos.x)/2, (pos.y+next->pos.y)/2,
+                            next->pos.x, next->pos.y, 
+                            CL_Color(255, 0, 0));
+    }
+}
+
+CL_Rect
+ObjMapPathNodeImpl::get_bound_rect() const
+{
+  return CL_Rect(pos-CL_Point(16,16), CL_Size(32, 32));
+}
+
+ObjMapPathNode::ObjMapPathNode(const CL_Point& pos_, 
+                               const MetaData& data_)
+  : impl(new ObjMapPathNodeImpl())
+{  
+  impl->pos  = pos_;
+  impl->data = data_;
+}
+
+void
+ObjMapPathNode::disconnect()
+{
+  impl->next = 0;
+  impl->prev = 0;
+
+  impl->next->prev = 0;
+  impl->prev->next = 0;
+}
+
+void
+ObjMapPathNode::connect(ObjMapPathNode next)
+{
+  if (next.impl->next != impl.get()) // avoid circular link between two nodes
+    {
+      if (next.impl->prev) // ensure that each node links exactly to one prev 
and one next node 
+        {
+          next.impl->prev->next = 0;
+          next.impl->prev = 0;
+        }
+
+      impl->next = next.impl.get();
+      next.impl->prev = impl.get();
+    }
+}
+
+ObjMapObject
+ObjMapPathNode::to_object()
+{
+  return ObjMapObject(impl);
+}
+
+/* EOF */

Added: trunk/src/objmap_path_node.hxx
===================================================================
--- trunk/src/objmap_path_node.hxx      2004-06-03 23:42:17 UTC (rev 388)
+++ trunk/src/objmap_path_node.hxx      2004-06-04 12:58:51 UTC (rev 389)
@@ -0,0 +1,44 @@
+//  $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_OBJMAP_PATH_NODE_HXX
+#define HEADER_OBJMAP_PATH_NODE_HXX
+
+#include "objmap_object.hxx"
+
+class ObjMapPathNodeImpl;
+
+/** */
+class ObjMapPathNode
+{
+public:
+  ObjMapPathNode(const CL_Point& pos_, 
+                 const MetaData& data_);
+  
+  void connect(ObjMapPathNode next);
+  void disconnect();
+
+  ObjMapObject to_object();
+private:
+  SharedPtr<ObjMapPathNodeImpl> impl;
+};
+
+#endif
+
+/* EOF */

Modified: trunk/src/shared_ptr.hxx
===================================================================
--- trunk/src/shared_ptr.hxx    2004-06-03 23:42:17 UTC (rev 388)
+++ trunk/src/shared_ptr.hxx    2004-06-04 12:58:51 UTC (rev 389)
@@ -40,8 +40,8 @@
   T& operator*() { assert(ptr); return *ptr; }
   T const& operator*() const { assert(ptr); return *ptr; }
 
-  T* operator->() { return ptr; }
-  T const* operator->() const { return ptr; }
+  T* operator->() { assert(ptr); return ptr; }
+  T const* operator->() const { assert(ptr); return ptr; }
 
   T* get() const { return ptr; }
 };

Modified: trunk/src/supertux.py
===================================================================
--- trunk/src/supertux.py       2004-06-03 23:42:17 UTC (rev 388)
+++ trunk/src/supertux.py       2004-06-04 12:58:51 UTC (rev 389)
@@ -245,20 +245,31 @@
             f.write("%d " % i)
         f.write("  )\n\n")
 
+        f.write("  (camera\n")
+        f.write("    (mode \"autoscroll\")\n")
+        f.write("    (path\n")
+        for obj in self.objects.get_objects():
+            pathnode = get_python_object(obj.get_metadata())
+            if (pathnode.__class__ == PathNode):
+                f.write("     (point (x %d) (y %d) (speed 1))\n" % 
(obj.get_pos().x, obj.get_pos().y))
+        f.write("  ))\n\n")
+
         f.write("  (objects\n")
         for obj in self.objects.get_objects():
             badguy = get_python_object(obj.get_metadata())
-            pos    = obj.get_pos()
-            if (badguy.type != "resetpoint"):
-                f.write("     (%s (x %d) (y %d))\n" % (badguy.type, 
int(pos.x), int(pos.y)))
+            if (badguy.__class__ == BadGuy):
+                pos    = obj.get_pos()
+                if (badguy.type != "resetpoint"):
+                    f.write("     (%s (x %d) (y %d))\n" % (badguy.type, 
int(pos.x), int(pos.y)))
         f.write("  )\n\n")
 
         f.write("  (reset-points\n")
         for obj in self.objects.get_objects():
             badguy = get_python_object(obj.get_metadata())
-            pos    = obj.get_pos()
-            if (badguy.type == "resetpoint"):
-                f.write("     (point (x %d) (y %d))\n" % (int(pos.x), 
int(pos.y)))
+            if (badguy.__class__ == BadGuy):
+                pos    = obj.get_pos()
+                if (badguy.type == "resetpoint"):
+                    f.write("     (point (x %d) (y %d))\n" % (int(pos.x), 
int(pos.y)))
         f.write("  )\n\n")
         
         f.write(" )\n\n;; EOF ;;\n")
@@ -728,6 +739,34 @@
 gui_show_current()
 set_tilemap_paint_tool()
 
+class PathNode:
+    node = None
+    
+    def __init__(self, node):
+        self.node = node
+
+def insert_path_node(x,y):
+    print "Insert path Node"
+    m = workspace.get_map().get_metadata()
+    pathnode = ObjMapPathNode(editor_map.screen2world(CL_Point(x, y)),
+                              make_metadata("PathNode"))
+    pathnode.to_object().set_metadata(make_metadata(PathNode(pathnode)))
+    m.objects.add_object(pathnode.to_object())
+
+def connect_path_nodes():
+    print "Connecting path nodes"
+    pathnodes = []
+    for i in objmap_select_tool.get_selection():
+        obj = get_python_object(i.get_metadata())
+        if obj.__class__ == PathNode:
+            pathnodes.append(obj.node)
+
+    last = None
+    for i in pathnodes:
+        if last != None:
+            last.connect(i)
+        last = i
+            
 connect_v2(editor_map.sig_on_key("f1"), lambda x, y: gui_toggle_minimap())
 connect_v2(editor_map.sig_on_key("m"), lambda x, y: gui_toggle_minimap())
 connect_v2(editor_map.sig_on_key("g"), lambda x, y: gui_toggle_grid())
@@ -739,6 +778,9 @@
 connect_v2(editor_map.sig_on_key("5"), lambda x, y: 
editor_map.zoom_in(CL_Point(x, y)))
 connect_v2(editor_map.sig_on_key("6"), lambda x, y: 
editor_map.zoom_out(CL_Point(x, y)))
 
+connect_v2(editor_map.sig_on_key("i"), lambda x, y: insert_path_node(x,y))
+connect_v2(editor_map.sig_on_key("c"), lambda x, y: connect_path_nodes())
+
 gui.run()
 
 del config





reply via email to

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