@@ -63,8 +63,8 @@ class W3DRenderObjectSnapshot : public Snapshot
6363 ~W3DRenderObjectSnapshot () {REF_PTR_RELEASE (m_robj);}
6464
6565 inline void update (RenderObjClass *robj, DrawableInfo *drawInfo, Bool cloneParentRobj = TRUE ); // /<refresh the current snapshot with latest state
66- inline void addToScene (void ); // /< add this fogged render object to the scene.
67- inline void removeFromScene (); // /< remove this fogged render object from the scene.
66+ inline Bool addToScene (void ); // /< add this fogged render object to the scene.
67+ inline Bool removeFromScene (); // /< remove this fogged render object from the scene.
6868
6969protected:
7070
@@ -151,17 +151,21 @@ void W3DRenderObjectSnapshot::update(RenderObjClass *robj, DrawableInfo *drawInf
151151
152152// ------------------------------------------------------------------------------------------------
153153// ------------------------------------------------------------------------------------------------
154- void W3DRenderObjectSnapshot::addToScene (void )
154+ Bool W3DRenderObjectSnapshot::addToScene (void )
155155{
156156 if (!m_robj->Is_In_Scene ())
157+ {
157158 W3DDisplay::m_3DScene->Add_Render_Object (m_robj);
159+ return true ;
160+ }
161+ return false ;
158162}
159163
160164// ------------------------------------------------------------------------------------------------
161165// ------------------------------------------------------------------------------------------------
162- void W3DRenderObjectSnapshot::removeFromScene ()
166+ Bool W3DRenderObjectSnapshot::removeFromScene ()
163167{
164- m_robj->Remove ();
168+ return m_robj->Remove ();
165169}
166170
167171// ------------------------------------------------------------------------------------------------
@@ -531,29 +535,37 @@ void W3DGhostObject::updateParentObject(Object *object, PartitionData *mod)
531535// ------------------------------------------------------------------------------------------------
532536/* *Remove the dummy render objects from scene that belong to given player*/
533537// ------------------------------------------------------------------------------------------------
534- void W3DGhostObject::removeFromScene (int playerIndex)
538+ Bool W3DGhostObject::removeFromScene (int playerIndex)
535539{
536540 W3DRenderObjectSnapshot *snap = m_parentSnapshots[playerIndex];
537541
542+ Bool removed = false ;
543+
538544 while (snap)
539545 {
540- snap->removeFromScene ();
546+ removed |= snap->removeFromScene ();
541547 snap = snap->m_next ;
542548 }
549+
550+ return removed;
543551}
544552
545553// ------------------------------------------------------------------------------------------------
546554/* *Add the dummy render objects to scene so player sees the correct version within the fog*/
547555// ------------------------------------------------------------------------------------------------
548- void W3DGhostObject::addToScene (int playerIndex)
556+ Bool W3DGhostObject::addToScene (int playerIndex)
549557{
550558 W3DRenderObjectSnapshot *snap = m_parentSnapshots[playerIndex];
551559
560+ Bool added = false ;
561+
552562 while (snap)
553563 {
554- snap->addToScene ();
564+ added |= snap->addToScene ();
555565 snap = snap->m_next ;
556566 }
567+
568+ return added;
557569}
558570
559571// ------------------------------------------------------------------------------------------------
@@ -923,38 +935,57 @@ GhostObject *W3DGhostObjectManager::addGhostObject(Object *object, PartitionData
923935// ------------------------------------------------------------------------------------------------
924936void W3DGhostObjectManager::setLocalPlayerIndex (int playerIndex)
925937{
938+ const int oldPlayerIndex = getLocalPlayerIndex ();
939+
940+ if (playerIndex == oldPlayerIndex)
941+ return ;
942+
943+ GhostObjectManager::setLocalPlayerIndex (playerIndex);
944+
926945 // Whenever we switch local players, we need to remove all ghost objects belonging
927946 // to another player from the map. We then insert the current local player's
928947 // ghost objects into the map.
948+ // TheSuperHackers @bugfix xezon 06/09/2025 This function now properly
949+ // updates ghost objects and real objects when changing players.
929950
930951 W3DGhostObject *mod = m_usedModules;
931952
932953 while (mod)
933954 {
934- mod->removeFromScene (m_localPlayer);
955+ const Bool oldGhostRemoved = mod->removeFromScene (oldPlayerIndex);
956+ const ObjectShroudStatus newShroudStatus = mod->getShroudStatus (playerIndex);
957+ Bool newGhostAdded = false ;
935958
936- if (mod-> m_parentSnapshots [playerIndex] )
959+ if (newShroudStatus >= OBJECTSHROUD_FOGGED )
937960 {
938- // new player has his own snapshot
939- if (!mod->m_parentSnapshots [m_localPlayer])
940- {
941- // previous player didn't have a snapshot so real object must
942- // have been in the scene. Replace it with our snapshot.
943- mod->removeParentObject ();
944- }
945- mod->addToScene (playerIndex);
961+ newGhostAdded = mod->addToScene (playerIndex);
946962 }
947- else if (mod->m_parentSnapshots [m_localPlayer])
963+
964+ if (oldGhostRemoved && !newGhostAdded)
948965 {
949- // new player doesn't have a snapshot which means restore original object
950- // if it was replaced by a snapshot by the previous player.
951966 mod->restoreParentObject ();
952967 }
968+ else if (!oldGhostRemoved && newGhostAdded)
969+ {
970+ mod->removeParentObject ();
971+ }
953972
954973 mod = mod->m_nextSystem ;
955974 }
956975
957- GhostObjectManager::setLocalPlayerIndex (playerIndex);
976+ // TheSuperHackers @bugfix xezon 06/09/2025 This function now properly updates
977+ // all real objects when changing players without waiting for another logic step.
978+ // This is particularly noticeable when changing the player while the game is paused.
979+ for (Drawable* draw = TheGameClient->firstDrawable (); draw != NULL ; draw = draw->getNextDrawable ())
980+ {
981+ Object* obj = draw->getObject ();
982+ if (obj == NULL )
983+ continue ;
984+
985+ const ObjectShroudStatus shroudStatus = obj->getShroudedStatus (playerIndex);
986+ const Bool shrouded = shroudStatus >= OBJECTSHROUD_FOGGED;
987+ draw->setFullyObscuredByShroud (shrouded);
988+ }
958989}
959990
960991// ------------------------------------------------------------------------------------------------
0 commit comments