Toggle navigation
ivorium
iv_components
Example project
GitHub
Main Page
Modules
Classes
Files
File List
iv_components
Entity2D
Entity2D.cpp
Go to the documentation of this file.
1
#include "
Entity2D.hpp
"
2
3
namespace
comp
4
{
5
6
//------------- Entity2D_TypeId --------------------------------------------------
7
iv::RuntimeIdDictionary
Entity2D_TypeId::Dictionary
;
8
9
//------------- Entity2D ---------------------------------------------------------
10
Entity2D::Entity2D
(
iv::ClientMarker
* cm ) :
11
type(
Entity2D_TypeId
() ),
12
v_entity(
iv
::VLink() ),
13
position( cm,
iv
::
float2
( 0, 0 ) ),
14
cm( cm ),
15
_world( nullptr )
16
{
17
}
18
19
Entity2D::~Entity2D
()
20
{
21
this->
Unregister
();
22
}
23
24
void
Entity2D::Register
(
Entity2D_World
* world )
25
{
26
if
( this->_world )
27
{
28
this->
owner
()->
warning
(
SRC_INFO
,
"This Entity2D is already registered to a world."
);
29
return
;
30
}
31
32
this->
position
.Index(
this
, world );
33
34
this->_world =
world
;
35
this->_world->
Register
(
this
);
36
}
37
38
void
Entity2D::Unregister
()
39
{
40
if
( !this->_world )
41
return
;
42
43
this->_world->
Unregister
(
this
);
44
this->_world =
nullptr
;
45
46
this->
position
.Index();
47
}
48
49
bool
Entity2D::registered
()
50
{
51
return
this->_world;
52
}
53
54
Entity2D_World
*
Entity2D::world
()
55
{
56
return
this->_world;
57
}
58
59
iv::ClientMarker
*
Entity2D::owner
()
60
{
61
return
this->cm;
62
}
63
64
//------------- Entity2D_Listener -------------------------------------------------
65
Entity2D_Listener::Entity2D_Listener
(
iv::Instance
* inst,
Entity2D_World
* world ) :
66
iv
::GenericListener<
Entity2D_Listener
>( inst, world ),
67
cm( inst, this,
"Entity2D_Listener"
)
68
{
69
this->
cm
.
inherits
( this->
iv::GenericListener< Entity2D_Listener >::cm
);
70
}
71
72
//------------- Entity2D_World -------------------------------------------------
73
Entity2D_World::Entity2D_World
(
iv::Instance
* inst ) :
74
iv
::World<
Entity2D
>( inst ),
75
iv
::GenericListener_Index<
Entity2D_Listener
>( inst ),
76
iv
::ComponentAttr_Index<
Entity2D
>( inst ),
77
cm( inst, this,
"Entity2D_World"
)
78
{
79
this->
cm
.
inherits
( this->
iv::GenericListener_Index< Entity2D_Listener >::cm
, this->
iv::World< Entity2D >::cm
, this->
iv::ComponentAttr_Index< Entity2D >::cm
);
80
}
81
82
void
Entity2D_World::Listener_Initialize
(
Entity2D_Listener
* listener )
83
{
84
for
(
Entity2D
* component : this->
components
() )
85
listener->
Entity2D_Registered
( component );
86
}
87
88
void
Entity2D_World::Component_Registered
(
Entity2D
* entity )
89
{
90
this->
InvokeListeners
( &
Entity2D_Listener::Entity2D_Registered
, entity );
91
}
92
93
void
Entity2D_World::Component_Unregistered
(
Entity2D
* entity )
94
{
95
this->
InvokeListeners
( &
Entity2D_Listener::Entity2D_Unregistered
, entity );
96
}
97
98
void
Entity2D_World::Component_AttrChanged
(
Entity2D
* entity,
iv::Attribute
* attr )
99
{
100
this->
InvokeListeners
( &
Entity2D_Listener::Entity2D_Moved
, entity );
101
}
102
103
}