Skip to content

Commit

Permalink
move the worlds check in actor/pickup creation
Browse files Browse the repository at this point in the history
  • Loading branch information
Tiaansu committed Feb 7, 2025
1 parent bc52d44 commit 3fe12e4
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 109 deletions.
16 changes: 2 additions & 14 deletions src/manipulation/float.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1110,13 +1110,7 @@ int Manipulation::setFloatData(AMX *amx, cell *params)
}
if (update)
{
std::unordered_set<int> worlds = p->second->worlds;
if (worlds.empty())
{
worlds.insert(-1);
}

for (std::unordered_set<int>::const_iterator w = worlds.begin(); w != worlds.end(); ++w)
for (std::unordered_set<int>::const_iterator w = p->second->worlds.begin(); w != p->second->worlds.end(); ++w)
{
std::unordered_map<std::pair<int, int>, int, pair_hash>::iterator i = core->getData()->internalPickups.find(std::make_pair(p->first, *w));
if (i != core->getData()->internalPickups.end())
Expand Down Expand Up @@ -1781,13 +1775,7 @@ int Manipulation::setFloatData(AMX *amx, cell *params)
}
if (update)
{
std::unordered_set<int> worlds = a->second->worlds;
if (worlds.empty())
{
worlds.insert(-1);
}

for (std::unordered_set<int>::const_iterator w = worlds.begin(); w != worlds.end(); ++w)
for (std::unordered_set<int>::const_iterator w = a->second->worlds.begin(); w != a->second->worlds.end(); ++w)
{
std::unordered_map<std::pair<int, int>, int, pair_hash>::iterator i = core->getData()->internalActors.find(std::make_pair(a->first, *w));
if (i != core->getData()->internalActors.end())
Expand Down
16 changes: 2 additions & 14 deletions src/manipulation/int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1225,13 +1225,7 @@ int Manipulation::setIntData(AMX *amx, cell *params)
}
if (update)
{
std::unordered_set<int> worlds = p->second->worlds;
if (worlds.empty())
{
worlds.insert(-1);
}

for (std::unordered_set<int>::const_iterator w = worlds.begin(); w != worlds.end(); ++w)
for (std::unordered_set<int>::const_iterator w = p->second->worlds.begin(); w != p->second->worlds.end(); ++w)
{
std::unordered_map<std::pair<int, int>, int, pair_hash>::iterator i = core->getData()->internalPickups.find(std::make_pair(p->first, *w));
if (i != core->getData()->internalPickups.end())
Expand Down Expand Up @@ -1742,13 +1736,7 @@ int Manipulation::setIntData(AMX *amx, cell *params)
}
if (update)
{
std::unordered_set<int> worlds = a->second->worlds;
if (worlds.empty())
{
worlds.insert(-1);
}

for (std::unordered_set<int>::const_iterator w = worlds.begin(); w != worlds.end(); ++w)
for (std::unordered_set<int>::const_iterator w = a->second->worlds.begin(); w != a->second->worlds.end(); ++w)
{
std::unordered_map<std::pair<int, int>, int, pair_hash>::iterator i = core->getData()->internalActors.find(std::make_pair(a->first, *w));
if (i != core->getData()->internalActors.end())
Expand Down
60 changes: 11 additions & 49 deletions src/natives/actors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ cell AMX_NATIVE_CALL Natives::CreateDynamicActor(AMX *amx, cell *params)
actor->invulnerable = static_cast<int>(params[6]) != 0;
actor->health = amx_ctof(params[7]);
Utility::addToContainer(actor->worlds, static_cast<int>(params[8]));
if (actor->worlds.empty())
{
actor->worlds.insert(-1);
}
Utility::addToContainer(actor->interiors, static_cast<int>(params[9]));
Utility::addToContainer(actor->players, static_cast<int>(params[10]));
actor->comparableStreamDistance = amx_ctof(params[11]) < STREAMER_STATIC_DISTANCE_CUTOFF ? amx_ctof(params[11]) : amx_ctof(params[11]) * amx_ctof(params[11]);
Expand Down Expand Up @@ -85,13 +89,7 @@ cell AMX_NATIVE_CALL Natives::IsDynamicActorStreamedIn(AMX *amx, cell *params)
std::unordered_map<int, Item::SharedActor>::iterator a = core->getData()->actors.find(actorId);
if (a != core->getData()->actors.end())
{
std::unordered_set<int> worlds = a->second->worlds;
if (worlds.empty())
{
worlds.insert(-1);
}

for (std::unordered_set<int>::const_iterator w = worlds.begin(); w != worlds.end(); ++w)
for (std::unordered_set<int>::const_iterator w = a->second->worlds.begin(); w != a->second->worlds.end(); ++w)
{
std::unordered_map<std::pair<int, int>, int, pair_hash>::iterator i = core->getData()->internalActors.find(std::make_pair(actorId, *w));
if (i != core->getData()->internalActors.end())
Expand Down Expand Up @@ -175,13 +173,7 @@ cell AMX_NATIVE_CALL Natives::ApplyDynamicActorAnimation(AMX *amx, cell *params)
a->second->anim->freeze = static_cast<int>(params[8]) != 0;
a->second->anim->time = static_cast<int>(params[9]);

std::unordered_set<int> worlds = a->second->worlds;
if (worlds.empty())
{
worlds.insert(-1);
}

for (std::unordered_set<int>::const_iterator w = worlds.begin(); w != worlds.end(); ++w)
for (std::unordered_set<int>::const_iterator w = a->second->worlds.begin(); w != a->second->worlds.end(); ++w)
{
std::unordered_map<std::pair<int, int>, int, pair_hash>::iterator i = core->getData()->internalActors.find(std::make_pair(a->first, *w));
if (i != core->getData()->internalActors.end())
Expand All @@ -202,13 +194,7 @@ cell AMX_NATIVE_CALL Natives::ClearDynamicActorAnimations(AMX *amx, cell *params
{
a->second->anim = NULL;

std::unordered_set<int> worlds = a->second->worlds;
if (worlds.empty())
{
worlds.insert(-1);
}

for (std::unordered_set<int>::const_iterator w = worlds.begin(); w != worlds.end(); ++w)
for (std::unordered_set<int>::const_iterator w = a->second->worlds.begin(); w != a->second->worlds.end(); ++w)
{
std::unordered_map<std::pair<int, int>, int, pair_hash>::iterator i = core->getData()->internalActors.find(std::make_pair(a->first, *w));
if (i != core->getData()->internalActors.end())
Expand Down Expand Up @@ -241,13 +227,7 @@ cell AMX_NATIVE_CALL Natives::SetDynamicActorFacingAngle(AMX *amx, cell *params)
{
a->second->rotation = amx_ctof(params[2]);

std::unordered_set<int> worlds = a->second->worlds;
if (worlds.empty())
{
worlds.insert(-1);
}

for (std::unordered_set<int>::const_iterator w = worlds.begin(); w != worlds.end(); ++w)
for (std::unordered_set<int>::const_iterator w = a->second->worlds.begin(); w != a->second->worlds.end(); ++w)
{
std::unordered_map<std::pair<int, int>, int, pair_hash>::iterator i = core->getData()->internalActors.find(std::make_pair(a->first, *w));
if (i != core->getData()->internalActors.end())
Expand Down Expand Up @@ -292,13 +272,7 @@ cell AMX_NATIVE_CALL Natives::SetDynamicActorPos(AMX *amx, cell *params)
a->second->position[1] = amx_ctof(params[3]);
a->second->position[2] = amx_ctof(params[4]);

std::unordered_set<int> worlds = a->second->worlds;
if (worlds.empty())
{
worlds.insert(-1);
}

for (std::unordered_set<int>::const_iterator w = worlds.begin(); w != worlds.end(); ++w)
for (std::unordered_set<int>::const_iterator w = a->second->worlds.begin(); w != a->second->worlds.end(); ++w)
{
std::unordered_map<std::pair<int, int>, int, pair_hash>::iterator i = core->getData()->internalActors.find(std::make_pair(a->first, *w));
if (i != core->getData()->internalActors.end())
Expand Down Expand Up @@ -334,13 +308,7 @@ cell AMX_NATIVE_CALL Natives::SetDynamicActorHealth(AMX *amx, cell *params)
{
a->second->health = amx_ctof(params[2]);

std::unordered_set<int> worlds = a->second->worlds;
if (worlds.empty())
{
worlds.insert(-1);
}

for (std::unordered_set<int>::const_iterator w = worlds.begin(); w != worlds.end(); ++w)
for (std::unordered_set<int>::const_iterator w = a->second->worlds.begin(); w != a->second->worlds.end(); ++w)
{
std::unordered_map<std::pair<int, int>, int, pair_hash>::iterator i = core->getData()->internalActors.find(std::make_pair(a->first, *w));
if (i != core->getData()->internalActors.end())
Expand All @@ -362,13 +330,7 @@ cell AMX_NATIVE_CALL Natives::SetDynamicActorInvulnerable(AMX *amx, cell *params
{
a->second->invulnerable = static_cast<int>(params[2]) != 0;

std::unordered_set<int> worlds = a->second->worlds;
if (worlds.empty())
{
worlds.insert(-1);
}

for (std::unordered_set<int>::const_iterator w = worlds.begin(); w != worlds.end(); ++w)
for (std::unordered_set<int>::const_iterator w = a->second->worlds.begin(); w != a->second->worlds.end(); ++w)
{
std::unordered_map<std::pair<int, int>, int, pair_hash>::iterator i = core->getData()->internalActors.find(std::make_pair(a->first, *w));
if (i != core->getData()->internalActors.end())
Expand Down
18 changes: 2 additions & 16 deletions src/natives/miscellaneous.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2092,14 +2092,7 @@ cell AMX_NATIVE_CALL Natives::Streamer_SetItemPos(AMX *amx, cell *params)
core->getGrid()->removePickup(p->second, true);
}
}

std::unordered_set<int> worlds = p->second->worlds;
if (worlds.empty())
{
worlds.insert(-1);
}

for (std::unordered_set<int>::const_iterator w = worlds.begin(); w != worlds.end(); ++w)
for (std::unordered_set<int>::const_iterator w = p->second->worlds.begin(); w != p->second->worlds.end(); ++w)
{
std::unordered_map<std::pair<int, int>, int, pair_hash>::iterator i = core->getData()->internalPickups.find(std::make_pair(p->first, *w));
if (i != core->getData()->internalPickups.end())
Expand Down Expand Up @@ -2262,14 +2255,7 @@ cell AMX_NATIVE_CALL Natives::Streamer_SetItemPos(AMX *amx, cell *params)
core->getGrid()->removeActor(a->second, true);
}
}

std::unordered_set<int> worlds = a->second->worlds;
if (worlds.empty())
{
worlds.insert(-1);
}

for (std::unordered_set<int>::const_iterator w = worlds.begin(); w != worlds.end(); ++w)
for (std::unordered_set<int>::const_iterator w = a->second->worlds.begin(); w != a->second->worlds.end(); ++w)
{
std::unordered_map<std::pair<int, int>, int, pair_hash>::iterator i = core->getData()->internalActors.find(std::make_pair(a->first, *w));
if (i != core->getData()->internalActors.end())
Expand Down
4 changes: 4 additions & 0 deletions src/natives/pickups.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ cell AMX_NATIVE_CALL Natives::CreateDynamicPickup(AMX *amx, cell *params)
pickup->type = static_cast<int>(params[2]);
pickup->position = Eigen::Vector3f(amx_ctof(params[3]), amx_ctof(params[4]), amx_ctof(params[5]));
Utility::addToContainer(pickup->worlds, static_cast<int>(params[6]));
if (pickup->worlds.empty())
{
pickup->worlds.insert(-1);
}
Utility::addToContainer(pickup->interiors, static_cast<int>(params[7]));
Utility::addToContainer(pickup->players, static_cast<int>(params[8]));
pickup->comparableStreamDistance = amx_ctof(params[9]) < STREAMER_STATIC_DISTANCE_CUTOFF ? amx_ctof(params[9]) : amx_ctof(params[9]) * amx_ctof(params[9]);
Expand Down
18 changes: 2 additions & 16 deletions src/utility/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,7 @@ using namespace Utility;
std::unordered_map<int, Item::SharedActor>::iterator Utility::destroyActor(std::unordered_map<int, Item::SharedActor>::iterator a)
{
Item::Actor::identifier.remove(a->first, core->getData()->actors.size());

std::unordered_set<int> worlds = a->second->worlds;
if (worlds.empty())
{
worlds.insert(-1);
}

for (std::unordered_set<int>::const_iterator w = worlds.begin(); w != worlds.end(); ++w)
for (std::unordered_set<int>::const_iterator w = a->second->worlds.begin(); w != a->second->worlds.end(); ++w)
{
std::unordered_map<std::pair<int, int>, int, pair_hash>::iterator i = core->getData()->internalActors.find(std::make_pair(a->first, *w));
if (i != core->getData()->internalActors.end())
Expand Down Expand Up @@ -146,14 +139,7 @@ std::unordered_map<int, Item::SharedObject>::iterator Utility::destroyObject(std
std::unordered_map<int, Item::SharedPickup>::iterator Utility::destroyPickup(std::unordered_map<int, Item::SharedPickup>::iterator p)
{
Item::Pickup::identifier.remove(p->first, core->getData()->pickups.size());

std::unordered_set<int> worlds = p->second->worlds;
if (worlds.empty())
{
worlds.insert(-1);
}

for (std::unordered_set<int>::const_iterator w = worlds.begin(); w != worlds.end(); ++w)
for (std::unordered_set<int>::const_iterator w = p->second->worlds.begin(); w != p->second->worlds.end(); ++w)
{
std::unordered_map<std::pair<int, int>, int, pair_hash>::iterator i = core->getData()->internalPickups.find(std::make_pair(p->first, *w));
if (i != core->getData()->internalPickups.end())
Expand Down

0 comments on commit 3fe12e4

Please sign in to comment.