Skip to content

Commit

Permalink
initialize player object data on player pool entry create
Browse files Browse the repository at this point in the history
  • Loading branch information
AmyrAhmady committed Oct 7, 2023
1 parent 40a8127 commit e8d636a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 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

0 comments on commit e8d636a

Please sign in to comment.