@@ -24,6 +24,7 @@ class ObjectComponent final : public IObjectsComponent, public CoreEventHandler,
2424 std::list<uint16_t > slotsUsedByPlayerObjects;
2525 FlatPtrHashSet<PlayerObject> processedPlayerObjects;
2626 FlatPtrHashSet<Object> processedObjects;
27+ FlatPtrHashSet<Object> attachedToPlayer;
2728 bool defCameraCollision = true ;
2829
2930 ICustomModelsComponent* models = nullptr ;
@@ -414,54 +415,9 @@ class ObjectComponent final : public IObjectsComponent, public CoreEventHandler,
414415 return storage._entries ();
415416 }
416417
417- void onPoolEntryDestroyed (IPlayer& player) override
418- {
419- const int pid = player.getID ();
420- for (IObject* obj : storage)
421- {
422- const ObjectAttachmentData& data = obj->getAttachmentData ();
423- if (data.type == ObjectAttachmentData::Type::Player && data.ID == pid)
424- {
425- obj->resetAttachment ();
426- }
427- }
428- }
418+ void onPoolEntryDestroyed (IPlayer& player) override ;
429419
430- void onPlayerStreamIn (IPlayer& player, IPlayer& forPlayer) override
431- {
432- const int pid = player.getID ();
433- for (IObject* object : storage)
434- {
435- Object* obj = static_cast <Object*>(object);
436- const ObjectAttachmentData& attachment = obj->getAttachmentData ();
437- if (attachment.type == ObjectAttachmentData::Type::Player && attachment.ID == pid)
438- {
439- NetCode::RPC::AttachObjectToPlayer attachObjectToPlayerRPC;
440- attachObjectToPlayerRPC.ObjectID = obj->poolID ;
441- attachObjectToPlayerRPC.PlayerID = attachment.ID ;
442- attachObjectToPlayerRPC.Offset = attachment.offset ;
443- attachObjectToPlayerRPC.Rotation = attachment.rotation ;
444- PacketHelper::send (attachObjectToPlayerRPC, forPlayer);
445- }
446- }
447-
448- IPlayerObjectData* objectData = queryExtension<IPlayerObjectData>(player);
449- if (objectData)
450- {
451- for (int i = 0 ; i < MAX_ATTACHED_OBJECT_SLOTS; ++i)
452- {
453- if (objectData->hasAttachedObject (i))
454- {
455- NetCode::RPC::SetPlayerAttachedObject setPlayerAttachedObjectRPC;
456- setPlayerAttachedObjectRPC.PlayerID = player.getID ();
457- setPlayerAttachedObjectRPC.Index = i;
458- setPlayerAttachedObjectRPC.Create = true ;
459- setPlayerAttachedObjectRPC.AttachmentData = objectData->getAttachedObject (i);
460- PacketHelper::send (setPlayerAttachedObjectRPC, forPlayer);
461- }
462- }
463- }
464- }
420+ void onPlayerStreamIn (IPlayer& player, IPlayer& forPlayer) override ;
465421
466422 // Pre-spawn so you can safely attach onPlayerSpawn
467423 void onPlayerSpawn (IPlayer& player) override
@@ -499,13 +455,17 @@ class ObjectComponent final : public IObjectsComponent, public CoreEventHandler,
499455 storage.clear ();
500456 isPlayerObject.fill (0 );
501457 defCameraCollision = true ;
458+ attachedToPlayer.clear ();
502459 }
503460
504461 bool is037CompatModeEnabled () const { return compatModeEnabled; }
505462 void onPlayerFinishedDownloading (IPlayer& player) override ;
506463
507464 inline const std::list<uint16_t >& getSlotsUsedByPlayerObjects () const { return slotsUsedByPlayerObjects; }
508465 bool isGroupPlayerObjects () const { return groupPlayerObjects ? *groupPlayerObjects : false ; }
466+
467+ void onPlayerStreamOut (IPlayer& player, IPlayer& forPlayer) override ;
468+ inline FlatPtrHashSet<Object>& getAttachedToPlayers () { return attachedToPlayer; }
509469};
510470
511471class PlayerObjectData final : public IPlayerObjectData
@@ -516,6 +476,7 @@ class PlayerObjectData final : public IPlayerObjectData
516476 StaticBitset<MAX_ATTACHED_OBJECT_SLOTS> slotsOccupied_;
517477 StaticArray<ObjectAttachmentSlotData, MAX_ATTACHED_OBJECT_SLOTS> slots_;
518478 MarkedDynamicPoolStorage<PlayerObject, IPlayerObject, 1 , OBJECT_POOL_SIZE> storage;
479+ FlatPtrHashSet<PlayerObject> attachedToPlayer_;
519480 bool inObjectSelection_;
520481 bool inObjectEdit_;
521482 bool streamedGlobalObjects_;
@@ -635,6 +596,7 @@ class PlayerObjectData final : public IPlayerObjectData
635596 component_.decrementPlayerCounter (index);
636597 obj->destream ();
637598 storage.release (index, false );
599+ attachedToPlayer_.erase (obj);
638600 }
639601 }
640602
@@ -677,6 +639,7 @@ class PlayerObjectData final : public IPlayerObjectData
677639 streamedGlobalObjects_ = false ;
678640 slotsOccupied_.reset ();
679641 storage.clear ();
642+ attachedToPlayer_.clear ();
680643 }
681644
682645 void beginSelecting () override
@@ -795,4 +758,14 @@ class PlayerObjectData final : public IPlayerObjectData
795758 {
796759 streamedGlobalObjects_ = value;
797760 }
761+
762+ ObjectComponent& getComponent ()
763+ {
764+ return component_;
765+ }
766+
767+ inline FlatPtrHashSet<PlayerObject>& getAttachedToPlayerObjects ()
768+ {
769+ return attachedToPlayer_;
770+ }
798771};
0 commit comments