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:
Zed A. Shaw 2025-05-03 14:52:56 -04:00
parent 82ce3cb6be
commit 438bd8ab8a
8 changed files with 53 additions and 74 deletions

View file

@ -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;
}
}
};