Changeset 264 for trunk


Ignore:
Timestamp:
06/19/14 01:57:53 (11 years ago)
Author:
epyon
Message:
  • decoupling - root doesn't have to be an object
  • decoupling - gui::environment doesn't need a root object at all
Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/nv/gui/gui_environment.hh

    r257 r264  
    3333                };
    3434
    35                 class environment : public root
     35                class environment
    3636                {
    3737                public:
     
    4444                        void update();
    4545                        void draw();
    46                         virtual void add_child( object* child );
     46                        void add_child( element* child );
     47                        void destroy_element( element* e );
     48                        void destroy_children( element* e );
    4749                        virtual ~environment();
    4850                protected:
     51
    4952                        renderer*    m_renderer;
    5053                        window*      m_window;
  • trunk/nv/root.hh

    r262 r264  
    1717         * Implements the root of a object tree-like structure.
    1818         */
    19         class root : public object
     19        class root
    2020        {
    2121        public:
    22                 root() : object( "" ), m_lua_state( nullptr ), m_uid_store( nullptr ) {}
     22                root() : m_lua_state( nullptr ), m_uid_store( nullptr ) {}
    2323                lua::state*    get_lua_state()     const { return m_lua_state; }
    2424                uid_store*     get_uid_store()     const { return m_uid_store; }
     
    3333                void destroy_children( object* o );
    3434                virtual void destroy_object( object* o );
    35                 virtual ~root() { destroy_object( this ); }
     35                virtual ~root() {}
    3636        protected:
    3737                virtual void object_created( object* o );
     
    4040                uid_store*     m_uid_store;
    4141        };
    42 
     42       
    4343} // namespace nv
    4444
  • trunk/src/gui/gui_environment.cc

    r257 r264  
    3636        m_screen = new screen( m_area );
    3737        m_renderer = new renderer( w, shader_path );
    38         root::add_child( m_screen );
    3938}
    4039
     
    4746{
    4847        element* result = new element( r );
    49         object_created( result );
    5048        if ( parent == nullptr ) parent = m_screen;
    5149        parent->add_child( result );
    5250        return result;
     51}
     52
     53void nv::gui::environment::destroy_element( element* e )
     54{
     55        destroy_children( e );
     56        e->detach();
     57        delete e;
    5358}
    5459
     
    9499}
    95100
    96 void environment::add_child( object* child )
     101void environment::add_child( element* child )
    97102{
    98         // TODO: check if element
    99103        m_screen->add_child( child );
    100104}
    101105
     106void environment::destroy_children( element* e )
     107{
     108        while ( !e->m_children.empty() )
     109        {
     110                destroy_element( (element*)e->m_children.front() );
     111        }
     112}
     113
     114
    102115environment::~environment()
    103116{
    104         destroy_children( this );
     117        destroy_element( m_screen );
    105118        delete m_renderer;
    106119}
  • trunk/src/root.cc

    r262 r264  
    3030                m_uid_store->remove( o->m_uid );
    3131        }
    32         if ( o != this) delete o;
     32        delete o;
    3333}
    3434
Note: See TracChangeset for help on using the changeset viewer.