Browse Source

reformulation of subscriber message consumer
add extra safeties to subscriber message recipts

and just for good measure, don't bother listening for an event that will never be triggered

AzaezelX 2 days ago
parent
commit
6389b32f9b

+ 16 - 14
Engine/source/util/messaging/eventManager.cpp

@@ -79,24 +79,26 @@ bool EventManagerListener::onMessageReceived( StringTableEntry queue, const char
    if( subscribers == NULL )
       return true;
 
-   for( Vector<Subscriber>::iterator iter = subscribers->begin(); iter != subscribers->end(); iter++ )
+   for (U32 i = 0; i < subscribers->size(); i++)
    {
-      if( iter->listener == NULL )
+      Subscriber* itter = &((*subscribers)[i]);
+      if (itter->listener == NULL)
       {
-         subscribers->erase_fast( iter -- );
-         continue;
+         (*subscribers).erase(i);
+      }
+      else if (!itter->removeFlag)
+      {
+         itter->callDepth++;
+         Con::executef(itter->listener, itter->callback, data);
+         itter->callDepth--;
+         if (itter->removeFlag && itter->callDepth == 0)
+         {
+            (*subscribers).erase(i);
+         }
       }
 
-      if (!iter->removeFlag)
-	   {
-		   iter->callDepth++;
-		   Con::executef( iter->listener, iter->callback, data );
-		   iter->callDepth--;
-		   if (iter->removeFlag && iter->callDepth==0)
-		   {
-			   subscribers->erase_fast(iter--);
-		   }
-	   }
+      if (subscribers->size() == 0)
+         return true;
    }
 
    return true;

+ 10 - 5
Templates/BaseGame/game/core/clientServer/scripts/server/connectionToClient.tscript

@@ -136,8 +136,6 @@ function GameConnectionListener::onSetSpawnObjectTypeComplete( %this, %client )
         return; //continue to wait  
    %client.GetEventManager().remove( %client.listener, "setSpawnObjectTypeComplete" ); 
    %client.GetEventManager().remove( %client.listener, "setSpawnObjectTypeFailed" );
-   %client.GetEventManager().subscribe( %client.listener, "setSpawnPointComplete" );
-   %client.GetEventManager().subscribe( %client.listener, "setSpawnPointFailed" ); 
     
     if (isObject(%client.player))
     {
@@ -177,7 +175,11 @@ function GameConnection::setSpawnPoint( %this )
     %this.numModsNeedingLoaded = getNumCanCallOnObjectList("setSpawnPoint", %modulesIDList);
     
     if (%this.numModsNeedingLoaded)
-        callOnObjectList("setSpawnPoint", %modulesIdList, %this);
+    {
+        %this.GetEventManager().subscribe( %this.listener, "setSpawnPointComplete" );
+        %this.GetEventManager().subscribe( %this.listener, "setSpawnPointFailed" );      
+        callOnObjectList("setSpawnPoint", %modulesIdList, %this);        
+    }
     else
         %this.listener.onSetSpawnPointComplete(%this);   
 }
@@ -189,8 +191,7 @@ function GameConnectionListener::onSetSpawnPointComplete( %this, %client )
         return; //continue to wait 
         
    %client.GetEventManager().remove( %client.listener, "setSpawnPointComplete" ); 
-   %client.GetEventManager().remove( %client.listener, "setSpawnPointFailed" );   
-   %client.GetEventManager().subscribe( %client.listener, "postSpawnComplete" );
+   %client.GetEventManager().remove( %client.listener, "setSpawnPointFailed" ); 
    
     // Spawn with the engine's Sim::spawnObject() function
     %client.player = spawnObject(%client.spawnClass, %client.spawnDataBlock, %client.spawnProperties, %client.spawnScript);
@@ -278,9 +279,13 @@ function GameConnection::onPostSpawn( %this )
     %this.numModsNeedingLoaded = getNumCanCallOnObjectList("onPostSpawn", %modulesIDList);
     
     if (%this.numModsNeedingLoaded)
+    {
+        %this.GetEventManager().subscribe( %this.listener, "postSpawnComplete" );
         callOnObjectList("onPostSpawn", %modulesIdList, %this);
+    }
     else
         %this.listener.onPostSpawnComplete(%this);
+        
     if (isObject(%this.player.getDatablock().controlMap))
         commandToClient(%this, 'setMoveMap', %this.player.getDatablock().controlMap);
 }