usata-commits
[Top][All Lists]
Advanced

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

[Usata-commits] Changes to usata2/src/scene-manager.cpp


From: David Lau
Subject: [Usata-commits] Changes to usata2/src/scene-manager.cpp
Date: Fri, 07 Jan 2005 01:25:08 -0500

Index: usata2/src/scene-manager.cpp
diff -u usata2/src/scene-manager.cpp:1.6 usata2/src/scene-manager.cpp:1.7
--- usata2/src/scene-manager.cpp:1.6    Mon Jan  3 07:43:49 2005
+++ usata2/src/scene-manager.cpp        Fri Jan  7 06:13:11 2005
@@ -10,19 +10,42 @@
 // included in the software distribution, or visit
 // http://www.fsf.org/licenses/gpl.html.
 //
-// $Id: scene-manager.cpp,v 1.6 2005/01/03 07:43:49 skunix Exp $
+// $Id: scene-manager.cpp,v 1.7 2005/01/07 06:13:11 skunix Exp $
 
 #include "scene-manager.hpp"
 #include <boost/bind.hpp>
+#include <utility>
+#include <functional>
 #include <map>
+#include <vector>
 #include <iostream>
 namespace
 usata
 {
 
-
 namespace SM_internal
 {
+       template <typename compare=std::less<int> >
+       struct DrawOrderCompare : public std::binary_function<Object*,Object*, 
bool>
+       {
+
+               bool 
+               operator()(Object * lhs, Object*rhs)
+               {
+                       NodeInterface * ni = dynamic_cast<NodeInterface*>(lhs);
+                       int lhs_do = USATA_DRAW_ORDER_DEFAULT;
+                       int rhs_do = USATA_DRAW_ORDER_DEFAULT;
+                       if (ni)
+                               ni->query(Node::QUERY_DRAW_ORDER,lhs_do);
+
+                       ni = dynamic_cast<NodeInterface*>(rhs);
+                       if (ni)
+                               ni->query(Node::QUERY_DRAW_ORDER,rhs_do);       
        
+                       
+                       return compare()(lhs_do, rhs_do);       
+               }
+
+       };
 
 struct Impl
 {
@@ -30,63 +53,87 @@
        enum AddStatus { OK, DUPLICATE_NAME, BAD_NAME };
 
        //! \todo make this optionaly a hash_map instead
-       typedef std::map<std::string, Object_sp> ChildrenMap;
-       ChildrenMap children;
+       typedef std::vector<Object_sp> DrawList;
+
+       DrawList        drawlist;
        Object* get_ptr(const std::string&);
 
        void draw()
        {
                using boost::bind;
-               std::for_each(children.begin(), children.end(),
-                                               bind(&Object::draw, 
bind(&Object_sp::get, 
-                                                       
bind(&ChildrenMap::value_type::second, _1))));
+               std::for_each(drawlist.begin(),drawlist.end(),
+                               bind(&Object::draw, bind (&Object_sp::get, 
_1)));
     }
-
+       
 
        void update()
        {
                using std::for_each;
                using boost::bind;
-               for_each(children.begin(), children.end(),
-                       bind(&Object::update, 
-                               bind(&Object_sp::get, 
-                                       
bind(&ChildrenMap::value_type::second,_1)
-                               )
-                       ));
-
+               
+               for_each(drawlist.begin(), drawlist.end(),
+                               bind(&Object::update, 
bind(&Object_sp::get,_1)));
+               return;
        }
                
        AddStatus add(const Object_sp& obj)
        {
-               ChildrenMap::iterator it( children.find(obj->name()));
-               if (it != children.end())
-               {
-                       return DUPLICATE_NAME;
-               }
+
+               DrawList::iterator it= 
+               std::find_if(drawlist.begin(), drawlist.end(),
+                       boost::bind(std::equal_to<std::string>(),
+                                               obj->name(),  
+                                               boost::bind(&Object::name, 
boost::bind(&Object_sp::get, _1)) 
+                                         ));
+
                //! \todo verify valid name
-               children.insert(std::make_pair(obj->name(), obj));
+               drawlist.push_back(obj);
+
+               // sorting here is acceptable because there are probably always 
only going to be 2
+               // children so, a check every cycle whether the list needs to 
be sorted would be
+               // less efficiant.
+               std::sort(drawlist.begin(), drawlist.end(),
+                                       boost::bind(DrawOrderCompare<>(), 
+                                                       
boost::bind(&Object_sp::get,_1),
+                                                       
boost::bind(&Object_sp::get,_2)));
+
                return OK;
        }       
 
+       DrawList::iterator
+       find(const std::string& name)
+       {
+               DrawList::iterator retval= 
+               std::find_if(drawlist.begin(), drawlist.end(),
+                       boost::bind(std::equal_to<std::string>(),
+                                               name,  
+                                               boost::bind(&Object::name, 
boost::bind(&Object_sp::get, _1)) 
+                                         ));
+               return retval;
+       }
+
        Object* 
        lookup_ptr(const std::string& name)
        {
+               using boost::bind;      
                Object* retval=0;
-               ChildrenMap::iterator it(children.find(name));
-               if (it != children.end())
-               {
-                       retval=it->second.get();
-               }
+               DrawList::iterator it = 
+               std::find_if(drawlist.begin(),
+                                        drawlist.end(),
+                                        bind(std::equal_to<std::string>(), 
name,
+                                                       bind(&Object::name, 
bind( &Object_sp::get, _1))));
+               if (it != drawlist.end())
+                       retval = it->get();
                return retval;
        }
        Object_sp
        lookup(const std::string& name)
        {
-               Object_sp retval;       
-               ChildrenMap::iterator it(children.find(name));
-               if (it != children.end())
+               Object_sp retval;
+               DrawList::iterator it(find(name));
+               if (it != drawlist.end())
                {
-                       retval = it->second;
+                       retval = *it;
                }
                return retval;
        }
@@ -105,7 +152,7 @@
 SceneManager::SceneManager()
 :      impl(new Impl)
 {
-
+       name("SceneManager");
 }
 
 SceneManager::~SceneManager()
@@ -135,7 +182,7 @@
        std::string cpy(path);
        std::string     
        name=NodeInterface::NodePathPop(cpy);
-       
+
        Object *child = impl->lookup_ptr(name);
        if (child == 0)
        {




reply via email to

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