Browse Source

- The "Scene::onCollision()" and "Scene::onEndCollision()" (mutial object collision callbacks) only get called when both objects involved have their collision callback active which hasn't changed however now the "self" collision callbacks on both SceneObject and their behaviors are called when the respective SceneObject has its collision callback active i.e. it does not require the other objects (the object it's colliding with) to be active.

An example of this would be not having to turn-on collision callbacks on static scenary to get a collision callback for a player.  In this case you could use the "onSelfCollision()" or "onSelfEndCollision()" callbacks but not the mutual scene callbacks if the other object(s) didn't have their collision callback turned-on.
MelvMay-GG 12 years ago
parent
commit
00814cd
1 changed files with 113 additions and 70 deletions
  1. 113 70
      engine/source/2d/scene/Scene.cc

+ 113 - 70
engine/source/2d/scene/Scene.cc

@@ -565,8 +565,12 @@ void Scene::dispatchBeginContactCallbacks( void )
         if ( pSceneObjectA->isBeingDeleted() || pSceneObjectB->isBeingDeleted() )
             continue;
 
-        // Skip if either object does not have collision callback active.
-        if ( !pSceneObjectA->getCollisionCallback() || !pSceneObjectB->getCollisionCallback() )
+        // Fetch collision callback status.
+        const bool sceneObjectACallback = pSceneObjectA->getCollisionCallback();
+        const bool sceneObjectBCallback = pSceneObjectB->getCollisionCallback();
+
+        // Skip if both objects don't have collision callback active.
+        if ( !sceneObjectACallback && !sceneObjectBCallback )
             continue;
 
         // Fetch normal and contact points.
@@ -625,51 +629,63 @@ void Scene::dispatchBeginContactCallbacks( void )
                 shapeIndexA, shapeIndexB );
 		}
 
-        // Does the scene handle the collision callback?
-        Namespace* pNamespace = getNamespace();
-        if ( pNamespace != NULL && pNamespace->lookup( StringTable->insert( "onCollision" ) ) != NULL )
-        {
-            // Yes, so perform script callback on the Scene.
-            Con::executef( this, 4, "onCollision",
-                pSceneObjectABuffer,
-                pSceneObjectBBuffer,
-                pMiscInfoBuffer );
-        }
-        else
+        // Do both objects have collision callback active?
+        if ( sceneObjectACallback && sceneObjectBCallback )
         {
-            // No, so call it on its behaviors.
-            const char* args[5] = { "onCollision", this->getIdString(), pSceneObjectABuffer, pSceneObjectBBuffer, pMiscInfoBuffer };
-            callOnBehaviors( 5, args );
+            // Yes, so does the scene handle the collision callback?
+            Namespace* pNamespace = getNamespace();
+            if ( pNamespace != NULL && pNamespace->lookup( StringTable->insert( "onCollision" ) ) != NULL )
+            {
+                // Yes, so perform script callback on the Scene.
+                Con::executef( this, 4, "onCollision",
+                    pSceneObjectABuffer,
+                    pSceneObjectBBuffer,
+                    pMiscInfoBuffer );
+            }
+            else
+            {
+                // No, so call it on its behaviors.
+                const char* args[5] = { "onCollision", this->getIdString(), pSceneObjectABuffer, pSceneObjectBBuffer, pMiscInfoBuffer };
+                callOnBehaviors( 5, args );
+            }
         }
 
-        // Does the scene object A handle the self-collision callback?
-        if ( pSceneObjectA->isMethod("onSelfCollision") )            
-        {
-            // Yes, so perform the script callback on it.
-            Con::executef( pSceneObjectA, 3, "onSelfCollision",
-                pSceneObjectBBuffer,
-                pMiscInfoBuffer );
-        }
-        else
+        // Does object A have collision callback active?
+        if ( sceneObjectACallback )
         {
-            // No, so call it on its behaviors.
-            const char* args[4] = { "onSelfCollision", pSceneObjectABuffer, pSceneObjectBBuffer, pMiscInfoBuffer };
-            pSceneObjectA->callOnBehaviors( 4, args );
+            // Yes, so does it handle the self-collision callback?
+            if ( pSceneObjectA->isMethod("onSelfCollision") )            
+            {
+                // Yes, so perform the script callback on it.
+                Con::executef( pSceneObjectA, 3, "onSelfCollision",
+                    pSceneObjectBBuffer,
+                    pMiscInfoBuffer );
+            }
+            else
+            {
+                // No, so call it on its behaviors.
+                const char* args[4] = { "onSelfCollision", pSceneObjectABuffer, pSceneObjectBBuffer, pMiscInfoBuffer };
+                pSceneObjectA->callOnBehaviors( 4, args );
+            }
         }
 
-        // Does the scene object B handle the self-collision callback?
-        if ( pSceneObjectB->isMethod("onSelfCollision") )            
-        {
-            // Yes, so perform the script callback on it.
-            Con::executef( pSceneObjectB, 3, "onSelfCollision",
-                pSceneObjectABuffer,
-                pMiscInfoBuffer );
-        }
-        else
+        // Does object B have collision callback active?
+        if ( sceneObjectBCallback )
         {
-            // No, so call it on its behaviors.
-            const char* args[4] = { "onSelfCollision", pSceneObjectBBuffer, pSceneObjectABuffer, pMiscInfoBuffer };
-            pSceneObjectB->callOnBehaviors( 4, args );
+            // Yes, so does it handle the self-collision callback?
+            if ( pSceneObjectB->isMethod("onSelfCollision") )            
+            {
+                // Yes, so perform the script callback on it.
+                Con::executef( pSceneObjectB, 3, "onSelfCollision",
+                    pSceneObjectABuffer,
+                    pMiscInfoBuffer );
+            }
+            else
+            {
+                // No, so call it on its behaviors.
+                const char* args[4] = { "onSelfCollision", pSceneObjectBBuffer, pSceneObjectABuffer, pMiscInfoBuffer };
+                pSceneObjectB->callOnBehaviors( 4, args );
+            }
         }
     }
 }
@@ -710,8 +726,12 @@ void Scene::dispatchEndContactCallbacks( void )
         if ( pSceneObjectA->isBeingDeleted() || pSceneObjectB->isBeingDeleted() )
             continue;
 
-        // Skip if either object does not have collision callback active.
-        if ( !pSceneObjectA->getCollisionCallback() || !pSceneObjectB->getCollisionCallback() )
+        // Fetch collision callback status.
+        const bool sceneObjectACallback = pSceneObjectA->getCollisionCallback();
+        const bool sceneObjectBCallback = pSceneObjectB->getCollisionCallback();
+
+        // Skip if both objects don't have collision callback active.
+        if ( !sceneObjectACallback && !sceneObjectBCallback )
             continue;
 
         // Fetch shape index.
@@ -732,40 +752,63 @@ void Scene::dispatchEndContactCallbacks( void )
         char* pMiscInfoBuffer = Con::getArgBuffer(32);
         dSprintf(pMiscInfoBuffer, 32, "%d %d", shapeIndexA, shapeIndexB );
 
-        // Perform the script callback on the Scene.
-        Con::executef( this, 4, "onEndCollision",
-            pSceneObjectABuffer,
-            pSceneObjectBBuffer,
-            pMiscInfoBuffer );
-
-        // Does scene object A handle the collision?
-        if ( pSceneObjectA->isMethod("onSelfEndCollision") )            
-        {
-            // Yes, so perform the script callback on it.
-            Con::executef( pSceneObjectA, 3, "onSelfEndCollision",
-                pSceneObjectBBuffer,
-                pMiscInfoBuffer );
-        }
-        else
+        // Do both objects have collision callback active?
+        if ( sceneObjectACallback && sceneObjectBCallback )
         {
-            // No, so call it on its behaviors.
-            const char* args[3] = { "onSelfEndCollision", pSceneObjectBBuffer, pMiscInfoBuffer };
-            pSceneObjectA->callOnBehaviors( 3, args );
+            // Yes, so does the scene handle the collision callback?
+            Namespace* pNamespace = getNamespace();
+            if ( pNamespace != NULL && pNamespace->lookup( StringTable->insert( "onCollision" ) ) != NULL )
+            {
+                // Yes, so does the scene handle the collision callback?
+                Con::executef( this, 4, "onEndCollision",
+                    pSceneObjectABuffer,
+                    pSceneObjectBBuffer,
+                    pMiscInfoBuffer );
+            }
+            else
+            {
+                // No, so call it on its behaviors.
+                const char* args[5] = { "onEndCollision", this->getIdString(), pSceneObjectABuffer, pSceneObjectBBuffer, pMiscInfoBuffer };
+                callOnBehaviors( 5, args );
+            }
         }
 
-        // Does scene object B handle the collision?
-        if ( pSceneObjectB->isMethod("onSelfEndCollision") )            
+        // Does object A have collision callback active?
+        if ( sceneObjectACallback )
         {
-            // Yes, so perform the script callback on it.
-            Con::executef( pSceneObjectB, 3, "onSelfEndCollision",
-                pSceneObjectABuffer,
-                pMiscInfoBuffer );
+            // Yes, so does it handle the self-collision callback?
+            if ( pSceneObjectA->isMethod("onSelfEndCollision") )            
+            {
+                // Yes, so perform the script callback on it.
+                Con::executef( pSceneObjectA, 3, "onSelfEndCollision",
+                    pSceneObjectBBuffer,
+                    pMiscInfoBuffer );
+            }
+            else
+            {
+                // No, so call it on its behaviors.
+                const char* args[3] = { "onSelfEndCollision", pSceneObjectBBuffer, pMiscInfoBuffer };
+                pSceneObjectA->callOnBehaviors( 3, args );
+            }
         }
-        else
+
+        // Does object B have collision callback active?
+        if ( sceneObjectBCallback )
         {
-            // No, so call it on its behaviors.
-            const char* args[3] = { "onSelfEndCollision", pSceneObjectABuffer, pMiscInfoBuffer };
-            pSceneObjectB->callOnBehaviors( 3, args );
+            // Yes, so does it handle the self-collision callback?
+            if ( pSceneObjectB->isMethod("onSelfEndCollision") )            
+            {
+                // Yes, so perform the script callback on it.
+                Con::executef( pSceneObjectB, 3, "onSelfEndCollision",
+                    pSceneObjectABuffer,
+                    pMiscInfoBuffer );
+            }
+            else
+            {
+                // No, so call it on its behaviors.
+                const char* args[3] = { "onSelfEndCollision", pSceneObjectABuffer, pMiscInfoBuffer };
+                pSceneObjectB->callOnBehaviors( 3, args );
+            }
         }
     }
 }