Changeset 257 for trunk/src/object.cc


Ignore:
Timestamp:
06/14/14 22:40:25 (11 years ago)
Author:
epyon
Message:
  • object can now only created from root
  • all registration is done root side
  • gui::element draw and update logic fully in environment
  • root removed from object - a lot less coupling
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/object.cc

    r256 r257  
    88
    99#include <algorithm>
    10 #include "nv/root.hh"
    1110#include "nv/types.hh"
    1211#include "nv/lua/lua_state.hh"
     
    1514using namespace nv;
    1615
    17 object::object()
    18         : m_root( nullptr )
    19         , m_id()
     16object::object( const string& aid )
     17        : m_id( aid )
    2018        , m_name()
    2119        , m_uid(0)
     
    2624        , m_child_count(0)
    2725{
    28 }
    29 
    30 object::object( root* aroot, const string& aid )
    31         : m_root( aroot )
    32         , m_id( aid )
    33         , m_name()
    34         , m_uid(0)
    35         , m_lua_index(lua::ref_none)
    36         , m_lua_proto_index(lua::ref_none)
    37         , m_parent( nullptr )
    38         , m_children()
    39         , m_child_count(0)
    40 {
    41         if ( m_root )
    42         {
    43                 m_root->object_created( this );
    44         }
    4526}
    4627
     
    5637                m_children.push_back( child );
    5738                m_child_count++;
    58                 m_root->child_added( child );
    5939        }
    6040}
     
    7151                (*it)->m_parent = nullptr;
    7252                m_children.erase(it);
    73                 m_root->child_removed( child );
    7453        }       
    7554}
     
    8968}
    9069
    91 void object::destroy_children()
    92 {
    93         while ( !m_children.empty() )
    94         {
    95                 delete m_children.front();
    96         }
    97 }
    98 
    9970object::~object()
    10071{
    101         if ( m_root )
    102         {
    103                 m_root->object_destroyed( this );
    104         }
    105         detach();
    106         destroy_children();
    10772}
    10873
     
    195160//      db->create_type<object>("object").fields(fields);
    196161// }
    197 
    198 void nv::object::register_with_lua( const char* lua_name, const char* storage )
    199 {
    200         lua::state* state = get_root()->get_lua_state();
    201         if (state)
    202         {
    203                 if ( lua_name != nullptr )
    204                 {
    205                         m_lua_index       = state->register_object( this, lua_name );
    206                 }
    207                 if ( storage != nullptr )
    208                 {
    209                         m_lua_proto_index = state->register_proto( this, storage );
    210                 }
    211         }
    212 }
Note: See TracChangeset for help on using the changeset viewer.