Skip to content

Commit

Permalink
Merge pull request #731 from openmultiplayer/amir/fix-objects
Browse files Browse the repository at this point in the history
Fix object data initialization and event priority conflict with pawn
  • Loading branch information
AmyrAhmady authored Oct 7, 2023
2 parents b3fb252 + e8d636a commit 7b22bb0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
2 changes: 2 additions & 0 deletions Server/Components/Objects/objects_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,8 @@ class ObjectComponent final : public IObjectsComponent, public CoreEventHandler,

void onPoolEntryDestroyed(IPlayer& player) override;

void onPoolEntryCreated(IPlayer& player) override;

void onPlayerStreamIn(IPlayer& player, IPlayer& forPlayer) override;

// Pre-spawn so you can safely attach onPlayerSpawn
Expand Down
21 changes: 14 additions & 7 deletions Server/Components/Objects/objects_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,21 @@ void ObjectComponent::onTick(Microseconds elapsed, TimePoint now)

void ObjectComponent::onPlayerConnect(IPlayer& player)
{
auto player_data = new PlayerObjectData(*this, player);
player.addExtension(player_data, true);

// If client is using 0.3.7 or artwork isn't enabled we can create objects right on connect.
// If not we need to wait for client to download custom models before creating objects.
static bool artwork = (core->getConfig().getBool("artwork.enable")) ? (*core->getConfig().getBool("artwork.enable")) : false;
if (artwork && player.getClientVersion() == ClientVersion::ClientVersion_SAMP_03DL)
return;

player_data->setStreamedGlobalObjects(true);
for (IObject* o : storage)
auto playerData = reinterpret_cast<PlayerObjectData*>(queryExtension<IPlayerObjectData>(player));
if (playerData)
{
Object* obj = static_cast<Object*>(o);
obj->createForPlayer(player);
playerData->setStreamedGlobalObjects(true);
for (IObject* o : storage)
{
Object* obj = static_cast<Object*>(o);
obj->createForPlayer(player);
}
}
}

Expand Down Expand Up @@ -168,6 +169,12 @@ void ObjectComponent::onPoolEntryDestroyed(IPlayer& player)
}
}

void ObjectComponent::onPoolEntryCreated(IPlayer& player)
{
auto playerData = new PlayerObjectData(*this, player);
player.addExtension(playerData, true);
}

COMPONENT_ENTRY_POINT()
{
return new ObjectComponent();
Expand Down
2 changes: 1 addition & 1 deletion Server/Components/Pawn/Scripting/Impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ void Scripting::addEvents() const
if (mgr->players)
{
mgr->players->getPlayerSpawnDispatcher().addEventHandler(PlayerEvents::Get());
mgr->players->getPlayerConnectDispatcher().addEventHandler(PlayerEvents::Get(), EventPriority_FairlyLow);
mgr->players->getPlayerConnectDispatcher().addEventHandler(PlayerEvents::Get());
mgr->players->getPlayerStreamDispatcher().addEventHandler(PlayerEvents::Get());
mgr->players->getPlayerTextDispatcher().addEventHandler(PlayerEvents::Get());
mgr->players->getPlayerShotDispatcher().addEventHandler(PlayerEvents::Get());
Expand Down

0 comments on commit 7b22bb0

Please sign in to comment.