Page Menu
Home
Phabricator (Chris)
Search
Configure Global Search
Log In
Files
F628984
Entity.h
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Authored By
Unknown
Size
1 KB
Referenced Files
None
Subscribers
None
Entity.h
View Options
//
// Created by Ido Mozes on 20/06/2019.
//
#ifndef SDL2_GAME_ENTITY_H
#define SDL2_GAME_ENTITY_H
#include
<bitset>
#include
<vector>
#include
<memory>
#include
"Component.h"
constexpr
int
maxComponents
=
64
;
typedef
std
::
size_t
EntityId
;
class
Entity
{
static
EntityId
getNewId
()
{
static
EntityId
id_counter
=
0
;
return
id_counter
++
;
}
bool
active
=
true
;
EntityId
id
;
std
::
bitset
<
ComponentType
::
LENGTH
>
componentsMask
;
std
::
array
<
Component
*
,
ComponentType
::
LENGTH
>
components
;
public
:
Entity
();
~
Entity
()
=
default
;
EntityId
getId
()
{
return
id
;
}
bool
isActive
()
{
return
active
;
}
void
destroy
()
{
active
=
false
;
}
bool
hasComponents
(
uint64_t
mask
)
{
return
(
componentsMask
.
to_ullong
()
&
mask
)
==
mask
;
}
template
<
class
T
>
T
&
getComponent
()
{
return
*
(
T
*
)
(
components
[
T
::
getComponentType
()]);
}
template
<
typename
T
,
typename
...
Targs
>
Component
&
addComponent
(
Targs
&&
...
args
){
T
*
c
=
new
T
(
this
,
std
::
forward
<
Targs
>
(
args
)...);
components
[
T
::
getComponentType
()]
=
c
;
componentsMask
[
T
::
getComponentType
()]
=
true
;
return
*
c
;
}
};
#endif
//SDL2_GAME_ENTITY_H
File Metadata
Details
Attached
Mime Type
text/x-c++
Expires
Sun, Nov 15, 5:38 AM (1 d, 22 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
133630
Default Alt Text
Entity.h (1 KB)
Attached To
Mode
R74 BloonsTD
Attached
Detach File
Event Timeline