Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
Game Library
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Onuralp SEZER
Game Library
Commits
54ba8d3d
Commit
54ba8d3d
authored
2 years ago
by
Joseph Walton-Rivers
Browse files
Options
Downloads
Patches
Plain Diff
minor interface cleanup
parent
ae7fed04
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
demo/demo/rollball.cpp
+2
-2
2 additions, 2 deletions
demo/demo/rollball.cpp
include/fggl/ecs3/prototype/world.h
+26
-30
26 additions, 30 deletions
include/fggl/ecs3/prototype/world.h
with
28 additions
and
32 deletions
demo/demo/rollball.cpp
+
2
−
2
View file @
54ba8d3d
...
...
@@ -36,13 +36,13 @@ static void setupPrefabs(fggl::ecs3::World& world, Prefabs& prefabs) {
{
// player (cube because my sphere function doesn't exist yet
prefabs
.
player
=
world
.
findProtoype
(
"player"
);
prefabs
.
player
=
world
.
findProto
t
ype
(
"player"
);
world
.
add
<
fggl
::
phys
::
Dynamics
>
(
prefabs
.
player
);
}
{
// collectable
prefabs
.
collectable
=
world
.
findProtoype
(
"collectable"
);
prefabs
.
collectable
=
world
.
findProto
t
ype
(
"collectable"
);
// we need both of these for callbacks to trigger.
world
.
add
<
fggl
::
phys
::
CollisionCallbacks
>
(
prefabs
.
collectable
);
...
...
This diff is collapsed.
Click to expand it.
include/fggl/ecs3/prototype/world.h
+
26
−
30
View file @
54ba8d3d
...
...
@@ -19,7 +19,7 @@
*/
namespace
fggl
::
ecs3
::
prototype
{
using
e
ntity
_cb
=
std
::
function
<
void
(
const
entity_t
)
>
;
using
E
ntity
Callback
=
std
::
function
<
void
(
const
entity_t
)
>
;
class
Entity
{
public:
...
...
@@ -124,7 +124,7 @@ namespace fggl::ecs3::prototype {
}
inline
entity_t
createFromPrototype
(
const
std
::
string
&
name
)
{
return
copy
(
findProtoype
(
name
)
);
return
copy
(
findProto
t
ype
(
name
)
);
}
entity_t
copy
(
entity_t
prototype
)
{
...
...
@@ -150,9 +150,9 @@ namespace fggl::ecs3::prototype {
void
createFromSpec
(
entity_t
entity
,
const
YAML
::
Node
&
compConfig
)
{
if
(
compConfig
)
{
for
(
const
auto
&
it
:
compConfig
)
{
const
auto
name
=
it
.
first
.
as
<
std
::
string
>
();
auto
&
config
=
it
.
second
;
for
(
const
auto
&
it
r
:
compConfig
)
{
const
auto
name
=
it
r
.
first
.
as
<
std
::
string
>
();
const
auto
&
config
=
it
r
.
second
;
auto
compType
=
m_types
.
find
(
name
.
c_str
()
);
addFromConfig
(
entity
,
compType
,
config
);
...
...
@@ -160,23 +160,19 @@ namespace fggl::ecs3::prototype {
}
}
bool
alive
(
entity_t
entity
)
const
{
if
(
entity
==
NULL_ENTITY
)
{
// tis a silly question, but can be asked by accident.
return
false
;
}
if
(
m_killList
.
find
(
entity
)
!=
m_killList
.
end
()
)
{
// getting reaped
return
false
;
}
inline
auto
alive
(
entity_t
entity
)
const
->
bool
{
return
entity
!=
NULL_ENTITY
&&
m_killList
.
find
(
entity
)
==
m_killList
.
end
()
&&
m_entities
.
find
(
entity
)
!=
m_entities
.
end
();
}
// check liveness
return
m_entities
.
find
(
entity
)
!=
m_entities
.
end
();
inline
auto
exists
(
entity_t
entity
)
const
->
bool
{
return
entity
!=
NULL_ENTITY
&&
m_entities
.
find
(
entity
)
!=
m_entities
.
end
();
}
void
destroy
(
entity_t
entity
)
{
assert
(
entity
!=
NULL_ENTITY
&&
"attempted to kill null entity"
);
assert
(
alive
(
entity
)
&&
"attempted to kill null entity"
);
// TOOD resolve and clean components
//m_entities.erase(entity);
m_killList
.
insert
(
entity
);
...
...
@@ -238,7 +234,7 @@ namespace fggl::ecs3::prototype {
template
<
typename
C
>
C
*
add
(
entity_t
entity_id
)
{
assert
(
entity_id
!=
NULL_ENTITY
&&
"attempted to add component on null entity"
);
assert
(
alive
(
entity_id
)
&&
"attempted to add component on null entity"
);
//spdlog::info("component '{}' added to '{}'", C::name, entity_id);
auto
&
entity
=
m_entities
.
at
(
entity_id
);
...
...
@@ -249,7 +245,7 @@ namespace fggl::ecs3::prototype {
}
void
*
add
(
entity_t
entity_id
,
component_type_t
component_id
)
{
assert
(
entity_id
!=
NULL_ENTITY
&&
"attempted to add component on null entity"
);
assert
(
alive
(
entity_id
)
&&
"attempted to add component on null entity"
);
auto
meta
=
m_types
.
meta
(
component_id
);
auto
&
entity
=
m_entities
.
at
(
entity_id
);
...
...
@@ -261,7 +257,7 @@ namespace fggl::ecs3::prototype {
template
<
typename
C
>
C
*
set
(
entity_t
entity_id
,
const
C
*
ptr
)
{
assert
(
entity_id
!=
NULL_ENTITY
&&
"attempted to set component on null entity"
);
assert
(
alive
(
entity_id
)
&&
"attempted to set component on null entity"
);
//spdlog::info("component '{}' set on '{}'", C::name, entity_id);
auto
&
entity
=
m_entities
.
at
(
entity_id
);
...
...
@@ -272,7 +268,7 @@ namespace fggl::ecs3::prototype {
}
void
*
set
(
entity_t
entity_id
,
component_type_t
cid
,
const
void
*
ptr
)
{
assert
(
entity_id
!=
NULL_ENTITY
&&
"attempted to set component on null entity"
);
assert
(
alive
(
entity_id
)
&&
"attempted to set component on null entity"
);
auto
&
entity
=
m_entities
.
at
(
entity_id
);
auto
cMeta
=
m_types
.
meta
(
cid
);
...
...
@@ -301,8 +297,7 @@ namespace fggl::ecs3::prototype {
template
<
typename
C
>
C
*
get
(
entity_t
entity_id
)
const
{
assert
(
entity_id
!=
NULL_ENTITY
&&
"attempted to get component on null entity"
);
assert
(
exists
(
entity_id
)
&&
"attempted to get component on null entity"
);
C
*
ptr
=
tryGet
<
C
>
(
entity_id
);
if
(
ptr
==
nullptr
)
{
std
::
cerr
<<
"entity "
<<
entity_id
<<
" does not have component "
<<
C
::
name
<<
std
::
endl
;
...
...
@@ -312,7 +307,7 @@ namespace fggl::ecs3::prototype {
template
<
typename
C
>
void
remove
(
entity_t
entity_id
)
{
assert
(
entity_id
!=
NULL_ENTITY
&&
"attempted to remove component on null entity"
);
assert
(
alive
(
entity_id
)
&&
"attempted to remove component on null entity"
);
try
{
auto
&
entity
=
m_entities
.
at
(
entity_id
);
...
...
@@ -326,16 +321,17 @@ namespace fggl::ecs3::prototype {
}
}
void
*
get
(
entity_t
entity_id
,
component_type_t
t
)
{
void
*
get
(
entity_t
entity_id
,
component_type_t
componentType
)
{
assert
(
exists
(
entity_id
)
&&
"attempted to get component on null entity"
);
auto
&
entity
=
m_entities
.
at
(
entity_id
);
return
entity
.
get
(
t
);
return
entity
.
get
(
componentType
);
}
void
addDeathListener
(
const
e
ntity
_cb
&
callback
)
{
void
addDeathListener
(
const
E
ntity
Callback
&
callback
)
{
m_deathListeners
.
emplace_back
(
callback
);
}
entity_t
findProtoype
(
const
std
::
string
&
name
)
const
{
entity_t
findProto
t
ype
(
const
std
::
string
&
name
)
const
{
for
(
const
auto
&
[
entity
,
obj
]
:
m_entities
)
{
if
(
!
obj
.
m_abstract
){
continue
;
...
...
@@ -351,7 +347,7 @@ namespace fggl::ecs3::prototype {
}
private
:
std
::
vector
<
e
ntity
_cb
>
m_deathListeners
;
std
::
vector
<
E
ntity
Callback
>
m_deathListeners
;
TypeRegistry
&
m_types
;
entity_t
m_next
;
std
::
map
<
entity_t
,
Entity
>
m_entities
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment