Browse Source

- After a discussion on usability the following changes have been made:
> All SceneObject and SceneObject-behavior collision callbacks are named "onCollision()" & "onEndCollision()".
> All Scene and Scene-behavior collision callbacks are named "onSceneCollision()" & "onEndSceneCollision()".

The two differences are that the SceneObject collision callbacks only reference the object being collided with and the collision details whereas the Scene collision callbacks reference both objects that are colliding and the collision details.

MelvMay-GG 12 years ago
parent
commit
6c675d7

+ 22 - 27
engine/source/2d/scene/Scene.cc

@@ -626,10 +626,10 @@ void Scene::dispatchBeginContactCallbacks( void )
         {
         {
             // Yes, so does the scene handle the collision callback?
             // Yes, so does the scene handle the collision callback?
             Namespace* pNamespace = getNamespace();
             Namespace* pNamespace = getNamespace();
-            if ( pNamespace != NULL && pNamespace->lookup( StringTable->insert( "onCollision" ) ) != NULL )
+            if ( pNamespace != NULL && pNamespace->lookup( StringTable->insert( "onSceneCollision" ) ) != NULL )
             {
             {
                 // Yes, so perform script callback on the Scene.
                 // Yes, so perform script callback on the Scene.
-                Con::executef( this, 4, "onCollision",
+                Con::executef( this, 4, "onSceneCollision",
                     pSceneObjectABuffer,
                     pSceneObjectABuffer,
                     pSceneObjectBBuffer,
                     pSceneObjectBBuffer,
                     pMiscInfoBuffer );
                     pMiscInfoBuffer );
@@ -637,7 +637,7 @@ void Scene::dispatchBeginContactCallbacks( void )
             else
             else
             {
             {
                 // No, so call it on its behaviors.
                 // No, so call it on its behaviors.
-                const char* args[5] = { "onCollision", this->getIdString(), pSceneObjectABuffer, pSceneObjectBBuffer, pMiscInfoBuffer };
+                const char* args[5] = { "onSceneCollision", this->getIdString(), pSceneObjectABuffer, pSceneObjectBBuffer, pMiscInfoBuffer };
                 callOnBehaviors( 5, args );
                 callOnBehaviors( 5, args );
             }
             }
         }
         }
@@ -645,18 +645,18 @@ void Scene::dispatchBeginContactCallbacks( void )
         // Does object A have collision callback active?
         // Does object A have collision callback active?
         if ( sceneObjectACallback )
         if ( sceneObjectACallback )
         {
         {
-            // Yes, so does it handle the self-collision callback?
-            if ( pSceneObjectA->isMethod("onSelfCollision") )            
+            // Yes, so does it handle the collision callback?
+            if ( pSceneObjectA->isMethod("onCollision") )            
             {
             {
                 // Yes, so perform the script callback on it.
                 // Yes, so perform the script callback on it.
-                Con::executef( pSceneObjectA, 3, "onSelfCollision",
+                Con::executef( pSceneObjectA, 3, "onCollision",
                     pSceneObjectBBuffer,
                     pSceneObjectBBuffer,
                     pMiscInfoBuffer );
                     pMiscInfoBuffer );
             }
             }
             else
             else
             {
             {
                 // No, so call it on its behaviors.
                 // No, so call it on its behaviors.
-                const char* args[4] = { "onSelfCollision", pSceneObjectABuffer, pSceneObjectBBuffer, pMiscInfoBuffer };
+                const char* args[4] = { "onCollision", pSceneObjectABuffer, pSceneObjectBBuffer, pMiscInfoBuffer };
                 pSceneObjectA->callOnBehaviors( 4, args );
                 pSceneObjectA->callOnBehaviors( 4, args );
             }
             }
         }
         }
@@ -664,18 +664,18 @@ void Scene::dispatchBeginContactCallbacks( void )
         // Does object B have collision callback active?
         // Does object B have collision callback active?
         if ( sceneObjectBCallback )
         if ( sceneObjectBCallback )
         {
         {
-            // Yes, so does it handle the self-collision callback?
-            if ( pSceneObjectB->isMethod("onSelfCollision") )            
+            // Yes, so does it handle the collision callback?
+            if ( pSceneObjectB->isMethod("onCollision") )            
             {
             {
                 // Yes, so perform the script callback on it.
                 // Yes, so perform the script callback on it.
-                Con::executef( pSceneObjectB, 3, "onSelfCollision",
+                Con::executef( pSceneObjectB, 3, "onCollision",
                     pSceneObjectABuffer,
                     pSceneObjectABuffer,
                     pMiscInfoBuffer );
                     pMiscInfoBuffer );
             }
             }
             else
             else
             {
             {
                 // No, so call it on its behaviors.
                 // No, so call it on its behaviors.
-                const char* args[4] = { "onSelfCollision", pSceneObjectBBuffer, pSceneObjectABuffer, pMiscInfoBuffer };
+                const char* args[4] = { "onCollision", pSceneObjectBBuffer, pSceneObjectABuffer, pMiscInfoBuffer };
                 pSceneObjectB->callOnBehaviors( 4, args );
                 pSceneObjectB->callOnBehaviors( 4, args );
             }
             }
         }
         }
@@ -699,11 +699,6 @@ void Scene::dispatchEndContactCallbacks( void )
     if ( contactCount == 0 )
     if ( contactCount == 0 )
         return;
         return;
 
 
-    // Finish if no collision method exists on scene.
-    Namespace* pNamespace = getNamespace();
-    if ( pNamespace != NULL && pNamespace->lookup( StringTable->insert( "onEndCollision" ) ) == NULL )
-        return;
-
     // Iterate all contacts.
     // Iterate all contacts.
     for ( typeContactVector::iterator contactItr = mEndContacts.begin(); contactItr != mEndContacts.end(); ++contactItr )
     for ( typeContactVector::iterator contactItr = mEndContacts.begin(); contactItr != mEndContacts.end(); ++contactItr )
     {
     {
@@ -749,10 +744,10 @@ void Scene::dispatchEndContactCallbacks( void )
         {
         {
             // Yes, so does the scene handle the collision callback?
             // Yes, so does the scene handle the collision callback?
             Namespace* pNamespace = getNamespace();
             Namespace* pNamespace = getNamespace();
-            if ( pNamespace != NULL && pNamespace->lookup( StringTable->insert( "onCollision" ) ) != NULL )
+            if ( pNamespace != NULL && pNamespace->lookup( StringTable->insert( "onSceneEndCollision" ) ) != NULL )
             {
             {
                 // Yes, so does the scene handle the collision callback?
                 // Yes, so does the scene handle the collision callback?
-                Con::executef( this, 4, "onEndCollision",
+                Con::executef( this, 4, "onSceneEndCollision",
                     pSceneObjectABuffer,
                     pSceneObjectABuffer,
                     pSceneObjectBBuffer,
                     pSceneObjectBBuffer,
                     pMiscInfoBuffer );
                     pMiscInfoBuffer );
@@ -760,7 +755,7 @@ void Scene::dispatchEndContactCallbacks( void )
             else
             else
             {
             {
                 // No, so call it on its behaviors.
                 // No, so call it on its behaviors.
-                const char* args[5] = { "onEndCollision", this->getIdString(), pSceneObjectABuffer, pSceneObjectBBuffer, pMiscInfoBuffer };
+                const char* args[5] = { "onSceneEndCollision", this->getIdString(), pSceneObjectABuffer, pSceneObjectBBuffer, pMiscInfoBuffer };
                 callOnBehaviors( 5, args );
                 callOnBehaviors( 5, args );
             }
             }
         }
         }
@@ -768,18 +763,18 @@ void Scene::dispatchEndContactCallbacks( void )
         // Does object A have collision callback active?
         // Does object A have collision callback active?
         if ( sceneObjectACallback )
         if ( sceneObjectACallback )
         {
         {
-            // Yes, so does it handle the self-collision callback?
-            if ( pSceneObjectA->isMethod("onSelfEndCollision") )            
+            // Yes, so does it handle the collision callback?
+            if ( pSceneObjectA->isMethod("onEndCollision") )            
             {
             {
                 // Yes, so perform the script callback on it.
                 // Yes, so perform the script callback on it.
-                Con::executef( pSceneObjectA, 3, "onSelfEndCollision",
+                Con::executef( pSceneObjectA, 3, "onEndCollision",
                     pSceneObjectBBuffer,
                     pSceneObjectBBuffer,
                     pMiscInfoBuffer );
                     pMiscInfoBuffer );
             }
             }
             else
             else
             {
             {
                 // No, so call it on its behaviors.
                 // No, so call it on its behaviors.
-                const char* args[3] = { "onSelfEndCollision", pSceneObjectBBuffer, pMiscInfoBuffer };
+                const char* args[3] = { "onEndCollision", pSceneObjectBBuffer, pMiscInfoBuffer };
                 pSceneObjectA->callOnBehaviors( 3, args );
                 pSceneObjectA->callOnBehaviors( 3, args );
             }
             }
         }
         }
@@ -787,18 +782,18 @@ void Scene::dispatchEndContactCallbacks( void )
         // Does object B have collision callback active?
         // Does object B have collision callback active?
         if ( sceneObjectBCallback )
         if ( sceneObjectBCallback )
         {
         {
-            // Yes, so does it handle the self-collision callback?
-            if ( pSceneObjectB->isMethod("onSelfEndCollision") )            
+            // Yes, so does it handle the collision callback?
+            if ( pSceneObjectB->isMethod("onEndCollision") )            
             {
             {
                 // Yes, so perform the script callback on it.
                 // Yes, so perform the script callback on it.
-                Con::executef( pSceneObjectB, 3, "onSelfEndCollision",
+                Con::executef( pSceneObjectB, 3, "onEndCollision",
                     pSceneObjectABuffer,
                     pSceneObjectABuffer,
                     pMiscInfoBuffer );
                     pMiscInfoBuffer );
             }
             }
             else
             else
             {
             {
                 // No, so call it on its behaviors.
                 // No, so call it on its behaviors.
-                const char* args[3] = { "onSelfEndCollision", pSceneObjectABuffer, pMiscInfoBuffer };
+                const char* args[3] = { "onEndCollision", pSceneObjectABuffer, pMiscInfoBuffer };
                 pSceneObjectB->callOnBehaviors( 3, args );
                 pSceneObjectB->callOnBehaviors( 3, args );
             }
             }
         }
         }

+ 1 - 1
modules/AquariumToy/1/scripts/aquarium.cs

@@ -141,7 +141,7 @@ function buildAquarium()
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 
 
-function AquariumBoundary::onSelfCollision(%this, %object, %collisionDetails)
+function AquariumBoundary::onCollision(%this, %object, %collisionDetails)
 {
 {
     if (%object.class $= "FishClass")
     if (%object.class $= "FishClass")
         %object.recycle(%this.side);
         %object.recycle(%this.side);

+ 1 - 1
modules/CollisionToy/1/main.cs

@@ -173,7 +173,7 @@ function CollisionToy::createBalls( %this )
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 
 
-function CollisionToyBall::onSelfCollision(%this, %object, %collisionDetails)
+function CollisionToyBall::onCollision(%this, %object, %collisionDetails)
 {
 {
     // Finish if there are no contact points (this happens with sensors).
     // Finish if there are no contact points (this happens with sensors).
     if ( %collisionDetails.count <= 2 )
     if ( %collisionDetails.count <= 2 )

+ 1 - 1
modules/DeathBallToy/1/scripts/dealsDamageBehavior.cs

@@ -61,7 +61,7 @@ function DealsDamageBehavior::explode(%this, %position)
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 
 
-function DealsDamageBehavior::onSelfCollision(%this, %object, %collisionDetails)
+function DealsDamageBehavior::onCollision(%this, %object, %collisionDetails)
 {
 {
     %this.dealDamage(%this.strength, %object);
     %this.dealDamage(%this.strength, %object);
    
    

+ 1 - 1
modules/TruckToy/1/main.cs

@@ -663,7 +663,7 @@ function TruckToy::createProjectile(%this)
 
 
 // -----------------------------------------------------------------------------
 // -----------------------------------------------------------------------------
 
 
-function TruckProjectile::onSelfCollision(%this, %object, %collisionDetails)
+function TruckProjectile::onCollision(%this, %object, %collisionDetails)
 {   
 {   
     // Create an impact explosion at the projectiles position.
     // Create an impact explosion at the projectiles position.
     %particlePlayer = new ParticlePlayer();
     %particlePlayer = new ParticlePlayer();