Skip to content

Commit

Permalink
Tweaked: 2 less hash calculation when adding an Is pair
Browse files Browse the repository at this point in the history
  • Loading branch information
richardbiely committed Sep 24, 2024
1 parent 3f8130b commit 0f1e78a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 15 deletions.
2 changes: 1 addition & 1 deletion include/gaia/core/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ namespace gaia {
// >::value
//
// This way we could drop GAIA_DEFINE_HAS. However, the issue is that std::declval<Args>
// would have to be replaced with a variadic macro that expands into a seriers
// would have to be replaced with a variadic macro that expands into a series
// of std::declval<Arg> which is very inconvenient to do and always has a hard limit
// on the number of arguments which is super limiting.

Expand Down
11 changes: 7 additions & 4 deletions include/gaia/ecs/world.h
Original file line number Diff line number Diff line change
Expand Up @@ -554,12 +554,15 @@ namespace gaia {
if (entity.pair() && entity.id() == Is.id()) {
auto tgt = m_world.get(entity.gen());

EntityLookupKey entityKey(m_entity);
EntityLookupKey tgtKey(tgt);

// m_entity -> {..., e}
auto& entity_to_e = m_world.m_entityToAsTargets[EntityLookupKey(m_entity)];
entity_to_e.insert(EntityLookupKey{tgt});
auto& entity_to_e = m_world.m_entityToAsTargets[entityKey];
entity_to_e.insert(tgtKey);
// e -> {..., m_entity}
auto& e_to_entity = m_world.m_entityToAsRelations[EntityLookupKey(tgt)];
e_to_entity.insert(EntityLookupKey{m_entity});
auto& e_to_entity = m_world.m_entityToAsRelations[tgtKey];
e_to_entity.insert(entityKey);

// Make sure the relation entity is registered as archetype so queries can find it
// auto& ec = m_world.fetch(tgt);
Expand Down
19 changes: 11 additions & 8 deletions single_include/gaia.h
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ namespace gaia {
// Smaller changes and features
#define GAIA_VERSION_MINOR 8
// Fixes and tweaks
#define GAIA_VERSION_PATCH 7
#define GAIA_VERSION_PATCH 8

//------------------------------------------------------------------------------
// General settings.
Expand Down Expand Up @@ -2108,7 +2108,7 @@ namespace gaia {
// >::value
//
// This way we could drop GAIA_DEFINE_HAS. However, the issue is that std::declval<Args>
// would have to be replaced with a variadic macro that expands into a seriers
// would have to be replaced with a variadic macro that expands into a series
// of std::declval<Arg> which is very inconvenient to do and always has a hard limit
// on the number of arguments which is super limiting.

Expand Down Expand Up @@ -15466,7 +15466,7 @@ namespace gaia {

struct JobHandle final {
static constexpr JobInternalType IdBits = 20;
static constexpr JobInternalType GenBits = 12;
static constexpr JobInternalType GenBits = 11;
static constexpr JobInternalType PrioBits = 1;
static constexpr JobInternalType AllBits = IdBits + GenBits + PrioBits;
static constexpr JobInternalType IdMask = (uint32_t)(uint64_t(1) << IdBits) - 1;
Expand All @@ -15483,7 +15483,7 @@ namespace gaia {
struct JobData {
//! Index in entity array
JobInternalType id: IdBits;
//! Generation index. Incremented every time an entity is deleted
//! Generation index. Incremented every time an item is deleted
JobInternalType gen: GenBits;
//! Job priority. 1-priority, 0-background
JobInternalType prio: PrioBits;
Expand Down Expand Up @@ -25430,12 +25430,15 @@ namespace gaia {
if (entity.pair() && entity.id() == Is.id()) {
auto tgt = m_world.get(entity.gen());

EntityLookupKey entityKey(m_entity);
EntityLookupKey tgtKey(tgt);

// m_entity -> {..., e}
auto& entity_to_e = m_world.m_entityToAsTargets[EntityLookupKey(m_entity)];
entity_to_e.insert(EntityLookupKey{tgt});
auto& entity_to_e = m_world.m_entityToAsTargets[entityKey];
entity_to_e.insert(tgtKey);
// e -> {..., m_entity}
auto& e_to_entity = m_world.m_entityToAsRelations[EntityLookupKey(tgt)];
e_to_entity.insert(EntityLookupKey{m_entity});
auto& e_to_entity = m_world.m_entityToAsRelations[tgtKey];
e_to_entity.insert(entityKey);

// Make sure the relation entity is registered as archetype so queries can find it
// auto& ec = m_world.fetch(tgt);
Expand Down
4 changes: 2 additions & 2 deletions src/examples/example_roguelike/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ class OrientationSystem final: public ecs::System {

void OnUpdate() override {
// Update orientation based on the current velocity
m_q.each([&](Orientation& o, const Velocity& v) {
m_q.each([](Orientation& o, const Velocity& v) {
if (v.x != 0) {
o.x = v.x > 0 ? 1 : -1;
o.y = 0;
Expand All @@ -695,7 +695,7 @@ class MoveSystem final: public ecs::System {

void OnUpdate() override {
// Update position based on current velocity
m_q.each([&](Position& p, const Velocity& v) {
m_q.each([](Position& p, const Velocity& v) {
p.x += v.x;
p.y += v.y;
});
Expand Down

0 comments on commit 0f1e78a

Please sign in to comment.