Skip to content

Commit

Permalink
fix pickup restream issues and fix possible bug on actors
Browse files Browse the repository at this point in the history
  • Loading branch information
Tiaansu committed Sep 17, 2024
1 parent ce28f82 commit bc52d44
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 17 deletions.
16 changes: 14 additions & 2 deletions src/manipulation/float.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1110,7 +1110,13 @@ int Manipulation::setFloatData(AMX *amx, cell *params)
}
if (update)
{
for (std::unordered_set<int>::const_iterator w = p->second->worlds.begin(); w != p->second->worlds.end(); ++w)
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)
{
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 @@ -1775,7 +1781,13 @@ int Manipulation::setFloatData(AMX *amx, cell *params)
}
if (update)
{
for (std::unordered_set<int>::const_iterator w = a->second->worlds.begin(); w != a->second->worlds.end(); ++w)
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)
{
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: 14 additions & 2 deletions src/manipulation/int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1225,7 +1225,13 @@ int Manipulation::setIntData(AMX *amx, cell *params)
}
if (update)
{
for (std::unordered_set<int>::const_iterator w = p->second->worlds.begin(); w != p->second->worlds.end(); ++w)
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)
{
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 @@ -1736,7 +1742,13 @@ int Manipulation::setIntData(AMX *amx, cell *params)
}
if (update)
{
for (std::unordered_set<int>::const_iterator w = a->second->worlds.begin(); w != a->second->worlds.end(); ++w)
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)
{
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
56 changes: 49 additions & 7 deletions src/natives/actors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,13 @@ 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())
{
for (std::unordered_set<int>::const_iterator w = a->second->worlds.begin(); w != a->second->worlds.end(); ++w)
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)
{
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 @@ -169,7 +175,13 @@ 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]);

for (std::unordered_set<int>::const_iterator w = a->second->worlds.begin(); w != a->second->worlds.end(); ++w)
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)
{
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 @@ -190,7 +202,13 @@ cell AMX_NATIVE_CALL Natives::ClearDynamicActorAnimations(AMX *amx, cell *params
{
a->second->anim = NULL;

for (std::unordered_set<int>::const_iterator w = a->second->worlds.begin(); w != a->second->worlds.end(); ++w)
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)
{
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 @@ -223,7 +241,13 @@ cell AMX_NATIVE_CALL Natives::SetDynamicActorFacingAngle(AMX *amx, cell *params)
{
a->second->rotation = amx_ctof(params[2]);

for (std::unordered_set<int>::const_iterator w = a->second->worlds.begin(); w != a->second->worlds.end(); ++w)
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)
{
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 @@ -268,7 +292,13 @@ 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]);

for (std::unordered_set<int>::const_iterator w = a->second->worlds.begin(); w != a->second->worlds.end(); ++w)
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)
{
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 @@ -304,7 +334,13 @@ cell AMX_NATIVE_CALL Natives::SetDynamicActorHealth(AMX *amx, cell *params)
{
a->second->health = amx_ctof(params[2]);

for (std::unordered_set<int>::const_iterator w = a->second->worlds.begin(); w != a->second->worlds.end(); ++w)
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)
{
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 @@ -326,7 +362,13 @@ cell AMX_NATIVE_CALL Natives::SetDynamicActorInvulnerable(AMX *amx, cell *params
{
a->second->invulnerable = static_cast<int>(params[2]) != 0;

for (std::unordered_set<int>::const_iterator w = a->second->worlds.begin(); w != a->second->worlds.end(); ++w)
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)
{
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: 16 additions & 2 deletions src/natives/miscellaneous.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2092,7 +2092,14 @@ cell AMX_NATIVE_CALL Natives::Streamer_SetItemPos(AMX *amx, cell *params)
core->getGrid()->removePickup(p->second, true);
}
}
for (std::unordered_set<int>::const_iterator w = p->second->worlds.begin(); w != p->second->worlds.end(); ++w)

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)
{
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 @@ -2255,7 +2262,14 @@ cell AMX_NATIVE_CALL Natives::Streamer_SetItemPos(AMX *amx, cell *params)
core->getGrid()->removeActor(a->second, true);
}
}
for (std::unordered_set<int>::const_iterator w = a->second->worlds.begin(); w != a->second->worlds.end(); ++w)

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)
{
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: 2 additions & 2 deletions src/streamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ void Streamer::discoverActors(Player &player, const std::vector<SharedCell> &cel
if (d == core->getData()->discoveredActors.end())
{
const int playerWorldId = *w == -1 ? -1 : player.worldId;
if (doesPlayerSatisfyConditions(a->second->players, player.playerId, a->second->interiors, player.interiorId, a->second->worlds, playerWorldId, a->second->areas, player.internalAreas, a->second->inverseAreaChecking))
if (doesPlayerSatisfyConditions(a->second->players, player.playerId, a->second->interiors, player.interiorId, worlds, playerWorldId, a->second->areas, player.internalAreas, a->second->inverseAreaChecking))
{
if (a->second->comparableStreamDistance < STREAMER_STATIC_DISTANCE_CUTOFF || boost::geometry::comparable_distance(player.position, Eigen::Vector3f(a->second->position + a->second->positionOffset)) < (a->second->comparableStreamDistance * player.radiusMultipliers[STREAMER_TYPE_ACTOR]))
{
Expand Down Expand Up @@ -1088,7 +1088,7 @@ void Streamer::discoverPickups(Player &player, const std::vector<SharedCell> &ce
if (d == core->getData()->discoveredPickups.end())
{
const int playerWorldId = *w == -1 ? -1 : player.worldId;
if (doesPlayerSatisfyConditions(p->second->players, player.playerId, p->second->interiors, player.interiorId, p->second->worlds, playerWorldId, p->second->areas, player.internalAreas, p->second->inverseAreaChecking))
if (doesPlayerSatisfyConditions(p->second->players, player.playerId, p->second->interiors, player.interiorId, worlds, playerWorldId, p->second->areas, player.internalAreas, p->second->inverseAreaChecking))
{
if (p->second->comparableStreamDistance < STREAMER_STATIC_DISTANCE_CUTOFF || boost::geometry::comparable_distance(player.position, Eigen::Vector3f(p->second->position + p->second->positionOffset)) < (p->second->comparableStreamDistance * player.radiusMultipliers[STREAMER_TYPE_PICKUP]))
{
Expand Down
18 changes: 16 additions & 2 deletions src/utility/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,14 @@ 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());
for (std::unordered_set<int>::const_iterator w = a->second->worlds.begin(); w != a->second->worlds.end(); ++w)

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)
{
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 @@ -139,7 +146,14 @@ 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());
for (std::unordered_set<int>::const_iterator w = p->second->worlds.begin(); w != p->second->worlds.end(); ++w)

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)
{
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 bc52d44

Please sign in to comment.