Skip to content

Commit

Permalink
busting out the multimap ig (#1602)
Browse files Browse the repository at this point in the history
  • Loading branch information
EmosewaMC authored May 31, 2024
1 parent 342da92 commit a54600b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 13 deletions.
7 changes: 4 additions & 3 deletions dGame/dBehaviors/BehaviorContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ void BehaviorContext::ExecuteUpdates() {
this->scheduledUpdates.clear();
}

void BehaviorContext::SyncBehavior(const uint32_t syncId, RakNet::BitStream& bitStream) {
bool BehaviorContext::SyncBehavior(const uint32_t syncId, RakNet::BitStream& bitStream) {
BehaviorSyncEntry entry;
auto found = false;

Expand All @@ -128,7 +128,7 @@ void BehaviorContext::SyncBehavior(const uint32_t syncId, RakNet::BitStream& bit
if (!found) {
LOG("Failed to find behavior sync entry with sync id (%i)!", syncId);

return;
return false;
}

auto* behavior = entry.behavior;
Expand All @@ -137,10 +137,11 @@ void BehaviorContext::SyncBehavior(const uint32_t syncId, RakNet::BitStream& bit
if (behavior == nullptr) {
LOG("Invalid behavior for sync id (%i)!", syncId);

return;
return false;
}

behavior->Sync(this, bitStream, branch);
return true;
}


Expand Down
2 changes: 1 addition & 1 deletion dGame/dBehaviors/BehaviorContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ struct BehaviorContext

void ExecuteUpdates();

void SyncBehavior(uint32_t syncId, RakNet::BitStream& bitStream);
bool SyncBehavior(uint32_t syncId, RakNet::BitStream& bitStream);

void Update(float deltaTime);

Expand Down
23 changes: 15 additions & 8 deletions dGame/dComponents/SkillComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ bool SkillComponent::CastPlayerSkill(const uint32_t behaviorId, const uint32_t s

context->skillID = skillID;

this->m_managedBehaviors.insert_or_assign(skillUid, context);
this->m_managedBehaviors.insert({ skillUid, context });

auto* behavior = Behavior::CreateBehavior(behaviorId);

Expand All @@ -52,17 +52,24 @@ bool SkillComponent::CastPlayerSkill(const uint32_t behaviorId, const uint32_t s
}

void SkillComponent::SyncPlayerSkill(const uint32_t skillUid, const uint32_t syncId, RakNet::BitStream& bitStream) {
const auto index = this->m_managedBehaviors.find(skillUid);
const auto index = this->m_managedBehaviors.equal_range(skillUid);

if (index == this->m_managedBehaviors.end()) {
if (index.first == this->m_managedBehaviors.end()) {
LOG("Failed to find skill with uid (%i)!", skillUid, syncId);

return;
}

auto* context = index->second;
bool foundSyncId = false;
for (auto it = index.first; it != index.second && !foundSyncId; ++it) {
const auto& context = it->second;

context->SyncBehavior(syncId, bitStream);
foundSyncId = context->SyncBehavior(syncId, bitStream);
}

if (!foundSyncId) {
LOG("Failed to find sync id (%i) for skill with uid (%i)!", syncId, skillUid);
}
}


Expand Down Expand Up @@ -138,7 +145,7 @@ void SkillComponent::Update(const float deltaTime) {
for (const auto& pair : this->m_managedBehaviors) pair.second->UpdatePlayerSyncs(deltaTime);
}

std::map<uint32_t, BehaviorContext*> keep{};
std::multimap<uint32_t, BehaviorContext*> keep{};

for (const auto& pair : this->m_managedBehaviors) {
auto* context = pair.second;
Expand Down Expand Up @@ -176,7 +183,7 @@ void SkillComponent::Update(const float deltaTime) {
}
}

keep.insert_or_assign(pair.first, context);
keep.insert({ pair.first, context });
}

this->m_managedBehaviors = keep;
Expand Down Expand Up @@ -285,7 +292,7 @@ SkillExecutionResult SkillComponent::CalculateBehavior(
return { false, 0 };
}

this->m_managedBehaviors.insert_or_assign(context->skillUId, context);
this->m_managedBehaviors.insert({ context->skillUId, context });

if (!clientInitalized) {
// Echo start skill
Expand Down
2 changes: 1 addition & 1 deletion dGame/dComponents/SkillComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ class SkillComponent final : public Component {
/**
* All of the active skills mapped by their unique ID.
*/
std::map<uint32_t, BehaviorContext*> m_managedBehaviors;
std::multimap<uint32_t, BehaviorContext*> m_managedBehaviors;

/**
* All active projectiles.
Expand Down

0 comments on commit a54600b

Please sign in to comment.