Last change
on this file since 257 was
257,
checked in by epyon, 11 years ago
|
- 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 size:
1.2 KB
|
Rev | Line | |
---|
[256] | 1 | // Copyright (C) 2012-2014 ChaosForge Ltd
|
---|
| 2 | // http://chaosforge.org/
|
---|
| 3 | //
|
---|
| 4 | // This file is part of NV Libraries.
|
---|
| 5 | // For conditions of distribution and use, see copyright notice in nv.hh
|
---|
| 6 |
|
---|
| 7 | #include "nv/root.hh"
|
---|
| 8 |
|
---|
| 9 | #include "nv/uid.hh"
|
---|
| 10 | #include "nv/lua/lua_state.hh"
|
---|
| 11 |
|
---|
| 12 | void nv::root::object_created( object* o )
|
---|
| 13 | {
|
---|
| 14 | if ( m_uid_store )
|
---|
| 15 | {
|
---|
| 16 | o->m_uid = m_uid_store->insert( o );
|
---|
| 17 | }
|
---|
| 18 | }
|
---|
| 19 |
|
---|
[257] | 20 | void nv::root::destroy_object( object* o )
|
---|
[256] | 21 | {
|
---|
[257] | 22 | destroy_children( o );
|
---|
| 23 | o->detach();
|
---|
[256] | 24 | if ( m_lua_state && o->m_lua_index != lua::ref_none )
|
---|
| 25 | {
|
---|
| 26 | m_lua_state->unregister_object( o );
|
---|
| 27 | }
|
---|
| 28 | if ( m_uid_store && o->m_uid != 0 )
|
---|
| 29 | {
|
---|
| 30 | m_uid_store->remove( o->m_uid );
|
---|
| 31 | }
|
---|
[257] | 32 | if ( o != this) delete o;
|
---|
[256] | 33 | }
|
---|
[257] | 34 |
|
---|
| 35 | void nv::root::destroy_children( object* o )
|
---|
| 36 | {
|
---|
| 37 | while ( !o->m_children.empty() )
|
---|
| 38 | {
|
---|
| 39 | destroy_object( o->m_children.front() );
|
---|
| 40 | }
|
---|
| 41 | }
|
---|
| 42 |
|
---|
| 43 | void nv::root::register_with_lua( object* o, const char* lua_name, const char* storage )
|
---|
| 44 | {
|
---|
| 45 | if ( m_lua_state )
|
---|
| 46 | {
|
---|
| 47 | if ( lua_name != nullptr )
|
---|
| 48 | {
|
---|
| 49 | o->m_lua_index = m_lua_state->register_object( o, lua_name );
|
---|
| 50 | }
|
---|
| 51 | if ( storage != nullptr )
|
---|
| 52 | {
|
---|
| 53 | o->m_lua_proto_index = m_lua_state->register_proto( o, storage );
|
---|
| 54 | }
|
---|
| 55 | }
|
---|
| 56 |
|
---|
| 57 | }
|
---|
| 58 |
|
---|
Note: See
TracBrowser
for help on using the repository browser.