Finally upgraded the strings to const& since I'm about to pull guecs out and distribute it. Oh well, the joke's finally over.
This commit is contained in:
parent
82ce3cb6be
commit
438bd8ab8a
8 changed files with 53 additions and 74 deletions
11
dinkyecs.hpp
11
dinkyecs.hpp
|
@ -203,11 +203,14 @@ namespace DinkyECS
|
|||
* return pointers (assuming optional can handle pointers)
|
||||
*/
|
||||
template <typename Comp>
|
||||
std::optional<Comp> get_if(DinkyECS::Entity entity) {
|
||||
if(has<Comp>(entity)) {
|
||||
return std::make_optional<Comp>(get<Comp>(entity));
|
||||
Comp* get_if(DinkyECS::Entity entity) {
|
||||
EntityMap &map = entity_map_for<Comp>();
|
||||
auto &storage = component_storage_for<Comp>();
|
||||
if(map.contains(entity)) {
|
||||
auto index = map.at(entity);
|
||||
return &storage.data[index];
|
||||
} else {
|
||||
return std::nullopt;
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue