Browse Source

Merge branch 'development' of github.com:GarageGames/Torque2D into development

capnlove 12 years ago
parent
commit
bf1b1b2

+ 75 - 43
engine/source/2d/controllers/BuoyancyController.cc

@@ -34,14 +34,13 @@ IMPLEMENT_CONOBJECT(BuoyancyController);
 //------------------------------------------------------------------------------
 
 BuoyancyController::BuoyancyController() :
-    mSurfaceNormal( 0.0f, 1.0f ),
-    mSurfaceOffset( 0.0f ),
     mFlowVelocity( 0.0f, 0.0f ),
     mFluidDensity( 2.0f ),
     mLinearDrag( 0.0f ),
     mAngularDrag( 0.0f ),
     mFluidGravity( 0.0f, -9.8f ),
-    mUseShapeDensity( true )
+    mUseShapeDensity( true ),
+    mSurfaceNormal( 0.0f, 1.0f )
 {
 }
 
@@ -59,8 +58,7 @@ void BuoyancyController::initPersistFields()
     // Call parent.
     Parent::initPersistFields();
 
-    addField( "SurfaceNormal", TypeVector2, Offset(mSurfaceNormal, BuoyancyController), "The outer surface normal." );
-    addField( "SurfaceOffset", TypeF32, Offset(mSurfaceOffset, BuoyancyController), "The height of the fluid surface along the normal." );
+    addField( "FluidArea", Typeb2AABB, Offset(mFluidArea, BuoyancyController), "The fluid area." );
     addField( "FluidDensity", TypeF32, Offset(mFluidDensity, BuoyancyController), "The fluid density." );
     addField( "FlowVelocity", TypeVector2, Offset(mFlowVelocity, BuoyancyController), "The fluid flow velocity for drag calculations." );
     addField( "LinearDrag", TypeF32, Offset(mLinearDrag, BuoyancyController), "The linear drag co-efficient for the fluid." );
@@ -111,27 +109,30 @@ void BuoyancyController::integrate( Scene* pScene, const F32 totalTime, const F3
         // Fetch the scene object.
         SceneObject* pSceneObject = *itr;
 
-        // Ignore sleeping bodies.
+        // Skip if asleep.
         if ( !pSceneObject->getAwake() )
             continue;
 
         // Fetch the shape count.
         const U32 shapeCount = pSceneObject->getCollisionShapeCount();
 
+        // Skip if no collision shapes.
+        if ( shapeCount == 0 )
+            continue;
+
+        // Fetch the body transform.
+        const b2Transform& bodyTransform = pSceneObject->getBody()->GetTransform();;
+
 		Vector2 areaCenter(0.0f, 0.0f);
 		Vector2 massCenter(0.0f, 0.0f);
 		F32 area = 0.0f;
 		F32 mass = 0.0f;
 
-        // Skip if we have no collision shapes.
-        if ( shapeCount == 0 )
-            continue;
-
         // Yes, so iterate them.
         for( U32 i = 0; i < shapeCount; ++i )
         {
             // Fetch the fixture definition.
-            b2FixtureDef fixtureDef = pSceneObject->getCollisionShapeDefinition( i );
+            const b2FixtureDef fixtureDef = pSceneObject->getCollisionShapeDefinition( i );
 
             // Fetch the shape.
             const b2Shape* pShape = fixtureDef.shape;
@@ -140,19 +141,16 @@ void BuoyancyController::integrate( Scene* pScene, const F32 totalTime, const F3
             
 			F32 shapeArea = 0.0f;
 
+            // Calculate the area for the shape type.
             if ( pShape->GetType() == b2Shape::e_circle )
             {
-                shapeArea = ComputeCircleSubmergedArea( pSceneObject->getBody(), dynamic_cast<const b2CircleShape*>(pShape), shapeCenter );
+                shapeArea = ComputeCircleSubmergedArea( bodyTransform, dynamic_cast<const b2CircleShape*>(pShape), shapeCenter );
             }
             else if ( pShape->GetType() == b2Shape::e_polygon)
             {
-                shapeArea = ComputePolygonSubmergedArea( pSceneObject->getBody(), dynamic_cast<const b2PolygonShape*>(pShape), shapeCenter );
+                shapeArea = ComputePolygonSubmergedArea( bodyTransform, dynamic_cast<const b2PolygonShape*>(pShape), shapeCenter );
             }
-            else if ( pShape->GetType() == b2Shape::e_edge)
-            {
-                shapeArea = 0.0f;
-            }
-            else if ( pShape->GetType() == b2Shape::e_chain)
+            else if ( pShape->GetType() == b2Shape::e_edge || pShape->GetType() == b2Shape::e_chain )
             {
                 shapeArea = 0.0f;
             }
@@ -162,32 +160,34 @@ void BuoyancyController::integrate( Scene* pScene, const F32 totalTime, const F3
                 continue;
             }
 
+            // Calculate area.
 			area += shapeArea;
 			areaCenter.x += shapeArea * shapeCenter.x;
 			areaCenter.y += shapeArea * shapeCenter.y;
+
+            // Calculate mass.
 			const F32 shapeDensity = mUseShapeDensity ? fixtureDef.density : 1.0f;
 			mass += shapeArea*shapeDensity;
 			massCenter.x += shapeArea * shapeCenter.x * shapeDensity;
 			massCenter.y += shapeArea * shapeCenter.y * shapeDensity;
         }
 
+        // Skip not in water.
+		if( area < b2_epsilon )
+			continue;
+
+        // Calculate area/mass centers.
 		areaCenter.x /= area;
 		areaCenter.y /= area;
-        //const b2Vec2 localCentroid = b2MulT(pSceneObject->getTransform(), areaCenter);
 		massCenter.x /= mass;
 		massCenter.y /= mass;
 
-        // Skip not in water.
-		if( area < b2_epsilon )
-			continue;
-
 		// Buoyancy
-		Vector2 buoyancyForce = -mFluidDensity * area * mFluidGravity;
+		const Vector2 buoyancyForce = -mFluidDensity * area * mFluidGravity;
         pSceneObject->applyForce(buoyancyForce, massCenter);
 
 		// Linear drag
-        Vector2 dragForce = pSceneObject->getLinearVelocityFromWorldPoint(areaCenter) - mFlowVelocity;
-		dragForce *= -mLinearDrag*area;
+        const Vector2 dragForce = (pSceneObject->getLinearVelocityFromWorldPoint(areaCenter) - mFlowVelocity) * (-mLinearDrag * area);
 		pSceneObject->applyForce(dragForce, areaCenter );
 
 		// Angular drag
@@ -197,27 +197,39 @@ void BuoyancyController::integrate( Scene* pScene, const F32 totalTime, const F3
 
 //------------------------------------------------------------------------------
 
-F32 BuoyancyController::ComputeCircleSubmergedArea( const b2Body* pBody, const b2CircleShape* pShape, Vector2& center )
+F32 BuoyancyController::ComputeCircleSubmergedArea( const b2Transform& bodyTransform, const b2CircleShape* pShape, Vector2& center )
 {
     // Sanity!
-    AssertFatal( pBody != NULL, "BuoyancyController::ComputeCircleSubmergedArea() - Invalid body." );
     AssertFatal( pShape != NULL, "BuoyancyController::ComputeCircleSubmergedArea() - Invalid shape." );
 
+    // Calculate the shape AABB.
+    b2AABB shapeAABB;
+    pShape->ComputeAABB( &shapeAABB, bodyTransform, 0 );
+
+    // If no overlap then the object cannot be submerged at all so return zero area submerged.
+    if ( !b2TestOverlap( mFluidArea, shapeAABB ) )
+        return 0.0f;
+
+    // Calculate the world shape center.
+    const b2Vec2 worldShapeCenter = b2Mul( bodyTransform, pShape->m_p );
+
+    const F32 l = -(b2Dot( mSurfaceNormal, worldShapeCenter ) - mFluidArea.upperBound.y);
+
     // Fetch the circle radius.
     const F32 radius = pShape->m_radius;
 
-    const b2Vec2 p = b2Mul( pBody->GetTransform(), pShape->m_p );
-    const F32 l = -(b2Dot( mSurfaceNormal, p ) - mSurfaceOffset);
-		
+    // Submerged?
     if (l < - radius + FLT_MIN)
 	{
-		// Completely dry
+        // No, so return zero area submerged.
 		return 0.0f;
 	}
+
+	// Completely wet?
 	if (l > pShape->m_radius)
 	{
-		// Completely wet
-		center = p;
+        // Yes!
+		center = worldShapeCenter;
 		return  b2_pi * radius * radius;
 	}
 		
@@ -227,23 +239,31 @@ F32 BuoyancyController::ComputeCircleSubmergedArea( const b2Body* pBody, const b
     const F32 area = r2 *( mAsin(l / radius) + b2_pi / 2.0f) + l * mSqrt( r2 - l2 );
     const F32 com = -2.0f / 3.0f * mPow(r2 - l2, 1.5f) / area;
 	
-	center.x = p.x + mSurfaceNormal.x * com;
-	center.y = p.y + mSurfaceNormal.y * com;
+    // Calculate center.
+	center.x = worldShapeCenter.x + mSurfaceNormal.x * com;
+	center.y = worldShapeCenter.y + mSurfaceNormal.y * com;
 		
 	return area;
 }
 
 //------------------------------------------------------------------------------
 
-F32 BuoyancyController::ComputePolygonSubmergedArea( const b2Body* pBody, const b2PolygonShape* pShape, Vector2& center )
+F32 BuoyancyController::ComputePolygonSubmergedArea( const b2Transform& bodyTransform, const b2PolygonShape* pShape, Vector2& center )
 {
     // Sanity!
-    AssertFatal( pBody != NULL, "BuoyancyController::ComputePolygonSubmergedArea() - Invalid body." );
     AssertFatal( pShape != NULL, "BuoyancyController::ComputePolygonSubmergedArea() - Invalid shape." );
 
-    //Transform plane into shape co-ordinates
-    b2Vec2 normalL = b2MulT( pBody->GetTransform().q, mSurfaceNormal);
-    F32 offsetL = mSurfaceOffset - b2Dot(mSurfaceNormal, pBody->GetTransform().p);
+    // Calculate the shape AABB.
+    b2AABB shapeAABB;
+    pShape->ComputeAABB( &shapeAABB, bodyTransform, 0 );
+
+    // If no overlap then the object cannot be submerged at all so return zero area submerged.
+    if ( !b2TestOverlap( mFluidArea, shapeAABB ) )
+        return 0.0f;
+
+    // Transform plane into shape co-ordinates
+    b2Vec2 normalL = b2MulT( bodyTransform.q, mSurfaceNormal);
+    F32 offsetL = mFluidArea.upperBound.y - b2Dot(mSurfaceNormal, bodyTransform.p);
         
     F32 depths[b2_maxPolygonVertices];
     S32 diveCount = 0;
@@ -289,7 +309,7 @@ F32 BuoyancyController::ComputePolygonSubmergedArea( const b2Body* pBody, const
                 // Completely submerged
                 b2MassData md;
                 pShape->ComputeMass(&md, 1.0f);
-                center = b2Mul(pBody->GetTransform(), md.center);
+                center = b2Mul(bodyTransform, md.center);
                 return md.mass;
             }
             else
@@ -355,7 +375,19 @@ F32 BuoyancyController::ComputePolygonSubmergedArea( const b2Body* pBody, const
         
     // Normalize and transform centroid
     center *= 1.0f / area;        
-    center = b2Mul(pBody->GetTransform(), center);
+    center = b2Mul(bodyTransform, center);
         
     return area;
 }
+
+
+//------------------------------------------------------------------------------
+
+void BuoyancyController::renderOverlay( Scene* pScene, const SceneRenderState* pSceneRenderState, BatchRender* pBatchRenderer )
+{
+    // Call parent.
+    Parent::renderOverlay( pScene, pSceneRenderState, pBatchRenderer );
+
+    // Draw fluid area.
+    pScene->mDebugDraw.DrawAABB( mFluidArea, ColorF(0.7f, 0.7f, 0.9f) );
+}

+ 10 - 7
engine/source/2d/controllers/BuoyancyController.h

@@ -38,11 +38,8 @@ class BuoyancyController : public SceneController
 private:
     typedef SceneController Parent;
 
-	/// The outer fluid surface normal.
-	Vector2 mSurfaceNormal;
-
-	/// The height of the fluid surface along the normal.
-	F32 mSurfaceOffset;
+    /// The fluid area.
+    b2AABB mFluidArea;
 
 	/// The fluid density.
 	F32 mFluidDensity;
@@ -62,9 +59,12 @@ private:
 	/// Whether to use the collision shape densities or assume a uniform density.
 	bool mUseShapeDensity;
 
+	/// The outer fluid surface normal.
+	Vector2 mSurfaceNormal;
+
 protected:
-    F32 ComputeCircleSubmergedArea( const b2Body* pBody, const b2CircleShape* pShape, Vector2& center );
-    F32 ComputePolygonSubmergedArea( const b2Body* pBody, const b2PolygonShape* pShape, Vector2& center );
+    F32 ComputeCircleSubmergedArea( const b2Transform& bodyTransform, const b2CircleShape* pShape, Vector2& center );
+    F32 ComputePolygonSubmergedArea( const b2Transform& bodyTransform, const b2PolygonShape* pShape, Vector2& center );
 
 public:
     BuoyancyController();
@@ -76,6 +76,9 @@ public:
     /// Integration.
     virtual void integrate( Scene* pScene, const F32 totalTime, const F32 elapsedTime, DebugStats* pDebugStats );
 
+    // Scene render.
+    virtual void renderOverlay( Scene* pScene, const SceneRenderState* pSceneRenderState, BatchRender* pBatchRenderer );
+
     /// Declare Console Object.
     DECLARE_CONOBJECT( BuoyancyController );
 };

+ 2 - 2
engine/source/2d/controllers/PointForceController.cc

@@ -136,6 +136,6 @@ void PointForceController::renderOverlay( Scene* pScene, const SceneRenderState*
     // Call parent.
     Parent::renderOverlay( pScene, pSceneRenderState, pBatchRenderer );
 
-    // Draw camera pause distance.
-    pScene->mDebugDraw.DrawCircle( mPosition, mRadius, b2Color(1.0f, 1.0f, 0.0f ) );
+    // Draw force radius.
+    pScene->mDebugDraw.DrawCircle( mPosition, mRadius, ColorF(1.0f, 1.0f, 0.0f ) );
 }

+ 43 - 0
engine/source/2d/core/Utility.cc

@@ -30,6 +30,49 @@
 
 //-----------------------------------------------------------------------------
 
+ConsoleType( b2AABB, Typeb2AABB, sizeof(b2AABB), "" )
+
+ConsoleGetType( Typeb2AABB )
+{
+    // Fetch AABB.
+    const b2AABB* pAABB = (b2AABB*)dptr;
+
+    // Format AABB.
+    char* pBuffer = Con::getReturnBuffer(64);
+    dSprintf(pBuffer, 64, "%.5g %.5g", pAABB->lowerBound.x, pAABB->lowerBound.y, pAABB->upperBound.x, pAABB->upperBound.y );
+    return pBuffer;
+}
+
+ConsoleSetType( Typeb2AABB )
+{
+    // Fetch AABB.
+    b2AABB* pAABB = (b2AABB*)dptr;
+
+    // "lowerX lowerY upperX upperY".
+    if( argc == 1 )
+    {
+        if ( dSscanf(argv[0], "%g %g %g %g", &(pAABB->lowerBound.x), &(pAABB->lowerBound.y), &(pAABB->upperBound.x), &(pAABB->upperBound.y) ) == 4 )
+            return;
+    }
+    
+    // "lowerX,lowerY,upperX,upperY".
+    else if( argc == 4 )
+    {
+        pAABB->lowerBound.Set( dAtof(argv[0]), dAtof(argv[1] ) );
+        pAABB->upperBound.Set( dAtof(argv[2]), dAtof(argv[3] ) );
+        return;
+    }
+
+    // Reset the AABB.
+    pAABB->lowerBound.SetZero();
+    pAABB->upperBound.SetZero();
+
+    // Warn.
+    Con::printf("Typeb2AABB must be set as { lowerX, lowerY, upperX, upperY } or \"lowerX lowerY upperX upperY\"");
+}
+
+//-----------------------------------------------------------------------------
+
 namespace Utility
 {
 

+ 6 - 8
engine/source/2d/core/Utility.h

@@ -39,7 +39,6 @@
 #include "math/mMath.h"
 #endif
 
-
 //-----------------------------------------------------------------------------
 // Miscellaneous Defines.
 //-----------------------------------------------------------------------------
@@ -47,25 +46,24 @@
 #define MASK_ALL                        (U32_MAX)
 #define MASK_BITCOUNT                   (32)
 #define DEBUG_MODE_COUNT                (8)
-
 #define MAX_LAYERS_SUPPORTED            (32)
-
-#define MAX_CONTACTPOINTS_SUPPORTED     (1024)
-
 #define CANNOT_RENDER_PROXY_NAME        "CannotRenderProxy"
 #define b2_pi2                          (b2_pi * 2.0f)
 
 //-----------------------------------------------------------------------------
 
-class Scene; // Yuk!
 class SceneObject;
 struct Vector2;
 
-//-----------------------------------------------------------------------------
-
 typedef Vector<SceneObject*> typeSceneObjectVector;
 typedef const Vector<SceneObject*>& typeSceneObjectVectorConstRef;
 
+///-----------------------------------------------------------------------------
+
+DefineConsoleType( Typeb2AABB )
+
+//-----------------------------------------------------------------------------
+
 namespace Utility
 {
 

+ 3 - 5
engine/source/2d/core/Vector2.cc

@@ -38,20 +38,18 @@ ConsoleSetType( TypeVector2 )
 {
     // Fetch vector.
     Vector2* pVector = (Vector2*)dptr;
+
     // "x y".
     if( argc == 1 )
     {
-        if ( dSscanf(argv[0], "%g %g", &(pVector->x), &(pVector->y)) == 2 )
-            return;
-
-        pVector->y = pVector->x;
+        pVector->setString( argv[0] );
         return;
     }
 
     // "x,y".
     if( argc == 2 )
     {
-        *((Vector2*)dptr) = Vector2(dAtof(argv[0]), dAtof(argv[1]));
+        pVector->Set(dAtof(argv[0]), dAtof(argv[1]));
         return;
     }
 

+ 20 - 19
engine/source/2d/core/Vector2.h

@@ -59,25 +59,7 @@ struct Vector2 : b2Vec2
     inline Vector2( const Point2I& point ) : b2Vec2( F32(point.x), F32(point.y) ) {}
     inline Vector2( const Point2F& point ) : b2Vec2( point.x, point.y ) {}
     inline Vector2( const Point2D& point ) : b2Vec2( F32(point.x), F32(point.y) ) {}
-    inline Vector2( const char* pString )
-    {
-        const U32 elementCount = Utility::mGetStringElementCount(pString);
-
-        if ( elementCount == 0 )
-        {
-            SetZero();
-            return;
-        }
-
-        if ( elementCount == 1 )
-        {
-            x = y = dAtof(Utility::mGetStringElement(pString,0));
-            return;
-        }
-
-        x = dAtof(Utility::mGetStringElement(pString,0));
-        y = dAtof(Utility::mGetStringElement(pString,1));
-    }
+    inline Vector2( const char* pString ) { setString( pString ); }
 
     /// Operators.
     inline Vector2& operator /= (const F32 s)                           { x /= s; y /= s; return *this; }
@@ -106,6 +88,25 @@ struct Vector2 : b2Vec2
     /// Utility.
     inline void setAngle(const F32 radians)                             { x = mSin(radians); y = mCos(radians); }
     inline void setPolar(const F32 radians,F32 length)                  { x = mSin(radians)*length; y = mCos(radians)*length; }
+    inline void setString(const char* pString )
+    {
+        const U32 elementCount = Utility::mGetStringElementCount(pString);
+
+        if ( elementCount == 0 )
+        {
+            SetZero();
+            return;
+        }
+
+        if ( elementCount == 1 )
+        {
+            x = y = dAtof(Utility::mGetStringElement(pString,0));
+            return;
+        }
+
+        x = dAtof(Utility::mGetStringElement(pString,0));
+        y = dAtof(Utility::mGetStringElement(pString,1));
+    }
     inline const Vector2& setZero()                                     { (*this) = getZero(); return *this; }
     inline const Vector2& setOne()                                      { (*this) = getOne(); return *this; }
     inline static const Vector2& getZero()                              { static const Vector2 v(0.0f, 0.0f); return v; }

+ 31 - 31
engine/source/2d/scene/DebugDraw.cc

@@ -28,7 +28,7 @@
 
 //-----------------------------------------------------------------------------
 
-void DebugDraw::DrawAABB( const b2AABB& aabb )
+void DebugDraw::DrawAABB( const b2AABB& aabb, const ColorF& color )
 {
     // Debug Profiling.
     PROFILE_SCOPE(DebugDraw_DrawAABB);
@@ -40,28 +40,28 @@ void DebugDraw::DrawAABB( const b2AABB& aabb )
     aabbVertex[2].Set(aabb.upperBound.x, aabb.upperBound.y);
     aabbVertex[3].Set(aabb.lowerBound.x, aabb.upperBound.y);
 
-    DrawPolygon( aabbVertex, 4, b2Color(0.7f, 0.7f, 0.9f) );
+    DrawPolygon( aabbVertex, 4, color );
 }
 
 //-----------------------------------------------------------------------------
 
-void DebugDraw::DrawOOBB( const b2Vec2* pOOBB )
+void DebugDraw::DrawOOBB( const b2Vec2* pOOBB, const ColorF& color )
 {
     // Debug Profiling.
     PROFILE_SCOPE(DebugDraw_DrawOOBB);
 
-    DrawPolygon( pOOBB, 4, b2Color(0.9f, 0.9f, 1.0f) );
+    DrawPolygon( pOOBB, 4, color );
 }
 
 //-----------------------------------------------------------------------------
 
-void DebugDraw::DrawAsleep( const b2Vec2* pOOBB )
+void DebugDraw::DrawAsleep( const b2Vec2* pOOBB, const ColorF& color )
 {
     // Debug Profiling.
     PROFILE_SCOPE(DebugDraw_DrawAsleep);
 
-    DrawSegment( pOOBB[0], pOOBB[2], b2Color( 0.0f, 1.0f, 0.0f ) );
-    DrawSegment( pOOBB[1], pOOBB[3], b2Color( 0.0f, 1.0f, 0.0f ) );
+    DrawSegment( pOOBB[0], pOOBB[2], color );
+    DrawSegment( pOOBB[1], pOOBB[3], color );
 }
 
 //-----------------------------------------------------------------------------
@@ -77,27 +77,27 @@ void DebugDraw::DrawCollisionShapes( const b2Transform& xf, b2Body* pBody )
         // Inactive fixture.
         if ( pBody->IsActive() == false )
         {
-            DrawShape(pFixture, xf, b2Color(0.5f, 0.5f, 0.5f));
+            DrawShape(pFixture, xf, ColorF(0.5f, 0.5f, 0.5f));
         }
         // Active static fixture.
         else if ( pBody->GetType() == b2_staticBody )
         {
-            DrawShape(pFixture, xf, b2Color(0.5f, 0.9f, 0.5f));
+            DrawShape(pFixture, xf, ColorF(0.5f, 0.9f, 0.5f));
         }
         // Active kinematic fixture.
         else if ( pBody->GetType() == b2_kinematicBody )
         {
-            DrawShape(pFixture, xf, b2Color(0.5f, 0.5f, 0.9f));
+            DrawShape(pFixture, xf, ColorF(0.5f, 0.5f, 0.9f));
         }
         // Active, asleep dynamic fixture.
         else if ( pBody->IsAwake() == false )
         {
-            DrawShape(pFixture, xf, b2Color(0.6f, 0.6f, 0.2f));
+            DrawShape(pFixture, xf, ColorF(0.6f, 0.6f, 0.2f));
         }
         // Active, awake dynamic fixture.
         else
         {
-            DrawShape(pFixture, xf, b2Color(0.9f, 0.9f, 0.2f));
+            DrawShape(pFixture, xf, ColorF(0.9f, 0.9f, 0.2f));
         }
     }
 }
@@ -124,13 +124,13 @@ void DebugDraw::DrawSortPoint( const b2Vec2& worldPosition, const b2Vec2& size,
     worldSortPoint[2].Set( worldPoint.x - markerSize, worldPoint.y + markerSize );
     worldSortPoint[3].Set( worldPoint.x + markerSize, worldPoint.y - markerSize );
 
-    DrawSegment( worldSortPoint[0], worldSortPoint[1], b2Color( 0.0f, 1.0f, 0.8f ) );
-    DrawSegment( worldSortPoint[2], worldSortPoint[3], b2Color( 0.0f, 1.0f, 0.8f ) );
+    DrawSegment( worldSortPoint[0], worldSortPoint[1], ColorF( 0.0f, 1.0f, 0.8f ) );
+    DrawSegment( worldSortPoint[2], worldSortPoint[3], ColorF( 0.0f, 1.0f, 0.8f ) );
 }
 
 //-----------------------------------------------------------------------------
 
-void DebugDraw::DrawShape( b2Fixture* fixture, const b2Transform& xf, const b2Color& color )
+void DebugDraw::DrawShape( b2Fixture* fixture, const b2Transform& xf, const ColorF& color )
 {
     // Debug Profiling.
     PROFILE_SCOPE(DebugDraw_DrawShape);
@@ -216,7 +216,7 @@ void DebugDraw::DrawJoints( b2World* pWorld )
         b2Vec2 p1 = pJoint->GetAnchorA();
         b2Vec2 p2 = pJoint->GetAnchorB();
 
-        b2Color color( 0.5f, 0.8f, 0.8f );
+        ColorF color( 0.5f, 0.8f, 0.8f );
 
         switch ( pJoint->GetType() )
         {
@@ -259,12 +259,12 @@ void DebugDraw::DrawJoints( b2World* pWorld )
 
 //-----------------------------------------------------------------------------
 
-void DebugDraw::DrawPolygon( const b2Vec2* vertices, int32 vertexCount, const b2Color& color)
+void DebugDraw::DrawPolygon( const b2Vec2* vertices, int32 vertexCount, const ColorF& color )
 {
     // Debug Profiling.
     PROFILE_SCOPE(DebugDraw_DrawPolygon);
 
-    glColor3f(color.r, color.g, color.b);
+    glColor3f(color.red, color.green, color.blue);
     glBegin(GL_LINE_LOOP);
     for (int32 i = 0; i < vertexCount; ++i)
     {
@@ -275,14 +275,14 @@ void DebugDraw::DrawPolygon( const b2Vec2* vertices, int32 vertexCount, const b2
 
 //-----------------------------------------------------------------------------
 
-void DebugDraw::DrawSolidPolygon( const b2Vec2* vertices, int32 vertexCount, const b2Color& color)
+void DebugDraw::DrawSolidPolygon( const b2Vec2* vertices, int32 vertexCount, const ColorF& color )
 {
     // Debug Profiling.
     PROFILE_SCOPE(DebugDraw_DrawSolidPolygon);
 
     glEnable(GL_BLEND);
     glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-    glColor4f(0.5f * color.r, 0.5f * color.g, 0.5f * color.b, 0.15f);
+    glColor4f(0.5f * color.red, 0.5f * color.green, 0.5f * color.blue, 0.15f);
     glBegin(GL_TRIANGLE_FAN);
     for (int32 i = 0; i < vertexCount; ++i)
     {
@@ -291,7 +291,7 @@ void DebugDraw::DrawSolidPolygon( const b2Vec2* vertices, int32 vertexCount, con
     glEnd();
     glDisable(GL_BLEND);
 
-    glColor4f(color.r, color.g, color.b, 1.0f);
+    glColor4f(color.red, color.green, color.blue, 1.0f);
     glBegin(GL_LINE_LOOP);
     for (int32 i = 0; i < vertexCount; ++i)
     {
@@ -302,7 +302,7 @@ void DebugDraw::DrawSolidPolygon( const b2Vec2* vertices, int32 vertexCount, con
 
 //-----------------------------------------------------------------------------
 
-void DebugDraw::DrawCircle( const b2Vec2& center, float32 radius, const b2Color& color)
+void DebugDraw::DrawCircle( const b2Vec2& center, float32 radius, const ColorF& color )
 {
     // Debug Profiling.
     PROFILE_SCOPE(DebugDraw_DrawCircle);
@@ -310,7 +310,7 @@ void DebugDraw::DrawCircle( const b2Vec2& center, float32 radius, const b2Color&
     const float32 k_segments = 16.0f;
     const float32 k_increment = 2.0f * b2_pi / k_segments;
     float32 theta = 0.0f;
-    glColor3f(color.r, color.g, color.b);
+    glColor3f(color.red, color.green, color.blue);
     glBegin(GL_LINE_LOOP);
     for (int32 i = 0; i < k_segments; ++i)
     {
@@ -323,7 +323,7 @@ void DebugDraw::DrawCircle( const b2Vec2& center, float32 radius, const b2Color&
     
 //-----------------------------------------------------------------------------
 
-void DebugDraw::DrawSolidCircle( const b2Vec2& center, float32 radius, const b2Vec2& axis, const b2Color& color)
+void DebugDraw::DrawSolidCircle( const b2Vec2& center, float32 radius, const b2Vec2& axis, const ColorF& color )
 {
     // Debug Profiling.
     PROFILE_SCOPE(DebugDraw_DrawSolidCircle);
@@ -333,7 +333,7 @@ void DebugDraw::DrawSolidCircle( const b2Vec2& center, float32 radius, const b2V
     float32 theta = 0.0f;
     glEnable(GL_BLEND);
     glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-    glColor4f(0.5f * color.r, 0.5f * color.g, 0.5f * color.b, 0.15f);
+    glColor4f(0.5f * color.red, 0.5f * color.green, 0.5f * color.blue, 0.15f);
     glBegin(GL_TRIANGLE_FAN);
     for (int32 i = 0; i < k_segments; ++i)
     {
@@ -345,7 +345,7 @@ void DebugDraw::DrawSolidCircle( const b2Vec2& center, float32 radius, const b2V
     glDisable(GL_BLEND);
 
     theta = 0.0f;
-    glColor4f(color.r, color.g, color.b, 1.0f);
+    glColor4f(color.red, color.green, color.blue, 1.0f);
     glBegin(GL_LINE_LOOP);
     for (int32 i = 0; i < k_segments; ++i)
     {
@@ -364,9 +364,9 @@ void DebugDraw::DrawSolidCircle( const b2Vec2& center, float32 radius, const b2V
     
 //-----------------------------------------------------------------------------
 
-void DebugDraw::DrawSegment( const b2Vec2& p1, const b2Vec2& p2, const b2Color& color)
+void DebugDraw::DrawSegment( const b2Vec2& p1, const b2Vec2& p2, const ColorF& color )
 {
-    glColor3f(color.r, color.g, color.b);
+    glColor3f(color.red, color.green, color.blue);
     glBegin(GL_LINES);
     glVertex2f(p1.x, p1.y);
     glVertex2f(p2.x, p2.y);
@@ -375,7 +375,7 @@ void DebugDraw::DrawSegment( const b2Vec2& p1, const b2Vec2& p2, const b2Color&
 
 //-----------------------------------------------------------------------------
 
-void DebugDraw::DrawTransform(const b2Transform& xf)
+void DebugDraw::DrawTransform( const b2Transform& xf )
 {
     b2Vec2 p1 = xf.p, p2;
     const float32 k_axisScale = 0.4f;
@@ -396,11 +396,11 @@ void DebugDraw::DrawTransform(const b2Transform& xf)
 
 //-----------------------------------------------------------------------------
 
-void DebugDraw::DrawPoint(const b2Vec2& p, float32 size, const b2Color& color)
+void DebugDraw::DrawPoint( const b2Vec2& p, float32 size, const ColorF& color )
 {
     glPointSize(size);
     glBegin(GL_POINTS);
-    glColor3f(color.r, color.g, color.b);
+    glColor3f(color.red, color.green, color.blue);
     glVertex2f(p.x, p.y);
     glEnd();
     glPointSize(1.0f);

+ 14 - 10
engine/source/2d/scene/DebugDraw.h

@@ -31,6 +31,10 @@
 #include "math/mMath.h"
 #endif
 
+#ifndef _COLOR_H_
+#include "graphics/color.h"
+#endif
+
 //-----------------------------------------------------------------------------
 
 class DebugDraw
@@ -39,22 +43,22 @@ public:
     DebugDraw() {}
     virtual ~DebugDraw() {}
 
-    void DrawAABB( const b2AABB& aabb );
-    void DrawOOBB( const b2Vec2* pOOBB );
-    void DrawAsleep( const b2Vec2* pOOBB );
+    void DrawAABB( const b2AABB& aabb, const ColorF& color );
+    void DrawOOBB( const b2Vec2* pOOBB, const ColorF& color );
+    void DrawAsleep( const b2Vec2* pOOBB, const ColorF& color );
     void DrawCollisionShapes( const b2Transform& xf, b2Body* pBody );
     void DrawSortPoint( const b2Vec2& worldPosition, const b2Vec2& size, const b2Vec2& localSortPoint );
 
     void DrawJoints( b2World* pWorld );
 
-    void DrawShape( b2Fixture* fixture, const b2Transform& xf, const b2Color& color );
-    void DrawPolygon( const b2Vec2* vertices, int32 vertexCount, const b2Color& color);
-    void DrawSolidPolygon( const b2Vec2* vertices, int32 vertexCount, const b2Color& color);
-    void DrawCircle( const b2Vec2& center, float32 radius, const b2Color& color);
-    void DrawSolidCircle( const b2Vec2& center, float32 radius, const b2Vec2& axis, const b2Color& color);
-    void DrawSegment( const b2Vec2& p1, const b2Vec2& p2, const b2Color& color);
+    void DrawShape( b2Fixture* fixture, const b2Transform& xf, const ColorF& color );
+    void DrawPolygon( const b2Vec2* vertices, int32 vertexCount, const ColorF& color);
+    void DrawSolidPolygon( const b2Vec2* vertices, int32 vertexCount, const ColorF& color);
+    void DrawCircle( const b2Vec2& center, float32 radius, const ColorF& color);
+    void DrawSolidCircle( const b2Vec2& center, float32 radius, const b2Vec2& axis, const ColorF& color);
+    void DrawSegment( const b2Vec2& p1, const b2Vec2& p2, const ColorF& color);
     void DrawTransform(const b2Transform& xf);
-    void DrawPoint(const b2Vec2& p, float32 size, const b2Color& color);
+    void DrawPoint(const b2Vec2& p, float32 size, const ColorF& color);
 };
 
 #endif // _DEBUG_DRAW_H_

+ 11 - 2
engine/source/2d/scene/Scene.cc

@@ -389,7 +389,7 @@ void Scene::initPersistFields()
     Parent::initPersistFields();
 
     // Physics.
-    addProtectedField("Gravity", TypeT2DVector, Offset(mWorldGravity, Scene), &setGravity, &getGravity, &writeGravity, "" );
+    addProtectedField("Gravity", TypeVector2, Offset(mWorldGravity, Scene), &setGravity, &getGravity, &writeGravity, "" );
     addField("VelocityIterations", TypeS32, Offset(mVelocityIterations, Scene), &writeVelocityIterations, "" );
     addField("PositionIterations", TypeS32, Offset(mPositionIterations, Scene), &writePositionIterations, "" );
 
@@ -972,8 +972,17 @@ void Scene::sceneRender( const SceneRenderState* pSceneRenderState )
     // Clear the background color if requested.
     if ( mUseBackgroundColor )
     {
+        // Enable the scissor.
+        const RectI& clipRect = dglGetClipRect();
+        glEnable(GL_SCISSOR_TEST );
+        glScissor( clipRect.point.x, clipRect.point.y, clipRect.len_x(), clipRect.len_y() );
+
+        // Clear the background.
         glClearColor( mBackgroundColor.red, mBackgroundColor.green, mBackgroundColor.blue, mBackgroundColor.alpha );
-        glClear(GL_COLOR_BUFFER_BIT);	
+        glClear(GL_COLOR_BUFFER_BIT);
+
+        // Disable the scissor.
+        glDisable( GL_SCISSOR_TEST );
     }
 
     // Debug Profiling.

+ 1 - 1
engine/source/2d/sceneobject/ImageFont.cc

@@ -114,7 +114,7 @@ void ImageFont::initPersistFields()
     addProtectedField("image", TypeImageAssetPtr, Offset(mImageAsset, ImageFont), &setImage, &getImage, &writeImage, "");
     addProtectedField("text", TypeString, 0, setText, getText, &writeText, "The text to be displayed." );  
     addProtectedField("textAlignment", TypeEnum, Offset(mTextAlignment, ImageFont), &setTextAlignment, &defaultProtectedGetFn, &writeTextAlignment, 1, &gTextAlignmentTable, "");
-    addProtectedField("fontSize", TypeT2DVector, Offset(mFontSize, ImageFont), &setFontSize, &defaultProtectedGetFn,&writeFontSize, "" );
+    addProtectedField("fontSize", TypeVector2, Offset(mFontSize, ImageFont), &setFontSize, &defaultProtectedGetFn,&writeFontSize, "" );
     addProtectedField("fontPadding", TypeF32, Offset(mFontPadding, ImageFont), &setFontPadding, &defaultProtectedGetFn, &writeFontPadding, "" );
 }
 

+ 1 - 1
engine/source/2d/sceneobject/ParticlePlayer.cc

@@ -705,7 +705,7 @@ void ParticlePlayer::sceneRenderOverlay( const SceneRenderState* sceneRenderStat
         return;
 
     // Draw camera pause distance.
-    pScene->mDebugDraw.DrawCircle( getRenderPosition(), mCameraIdleDistance, b2Color(1.0f, 1.0f, 0.0f ) );
+    pScene->mDebugDraw.DrawCircle( getRenderPosition(), mCameraIdleDistance, ColorF(1.0f, 1.0f, 0.0f ) );
 }
 
 //-----------------------------------------------------------------------------

+ 5 - 30
engine/source/2d/sceneobject/SceneObject.cc

@@ -806,19 +806,19 @@ void SceneObject::sceneRenderOverlay( const SceneRenderState* sceneRenderState )
     // AABB debug draw.
     if ( debugMask & Scene::SCENE_DEBUG_AABB )
     {
-        pScene->mDebugDraw.DrawAABB( mCurrentAABB );
+        pScene->mDebugDraw.DrawAABB( mCurrentAABB, ColorF(0.7f, 0.7f, 0.9f) );
     }
 
     // OOBB debug draw.
     if ( debugMask & Scene::SCENE_DEBUG_OOBB )
     {
-        pScene->mDebugDraw.DrawOOBB( mRenderOOBB );
+        pScene->mDebugDraw.DrawOOBB( mRenderOOBB, ColorF(0.9f, 0.9f, 1.0f) );
     }
 
     // Asleep debug draw.
     if ( !getAwake() && debugMask & Scene::SCENE_DEBUG_SLEEP )
     {
-        pScene->mDebugDraw.DrawAsleep( mRenderOOBB );
+        pScene->mDebugDraw.DrawAsleep( mRenderOOBB, ColorF( 0.0f, 1.0f, 0.0f ) );
     }
 
     // Collision Shapes.
@@ -832,8 +832,8 @@ void SceneObject::sceneRenderOverlay( const SceneRenderState* sceneRenderState )
     {
         const b2Vec2 renderPosition = getRenderPosition();
 
-        pScene->mDebugDraw.DrawPoint( renderPosition + getLocalCenter(), 6, b2Color( 0.0f, 1.0f, 0.4f ) );
-        pScene->mDebugDraw.DrawPoint( renderPosition, 4, b2Color( 0.0f, 0.4f, 1.0f ) );
+        pScene->mDebugDraw.DrawPoint( renderPosition + getLocalCenter(), 6, ColorF( 0.0f, 1.0f, 0.4f ) );
+        pScene->mDebugDraw.DrawPoint( renderPosition, 4, ColorF( 0.0f, 0.4f, 1.0f ) );
     }
 
     // Sort Points.
@@ -3322,31 +3322,6 @@ void SceneObject::notifyComponentsUpdate( void )
 
 //-----------------------------------------------------------------------------
 
-BehaviorInstance* SceneObject::behavior(const char *name)
-{
-    // Debug Profiling.
-    PROFILE_SCOPE(SceneObject_BehaviorName);
-
-    StringTableEntry stName = StringTable->insert(name);
-    VectorPtr<SimComponent *>&componentList = lockComponentList();
-
-    for( SimComponentIterator nItr = componentList.begin(); nItr != componentList.end(); nItr++ )
-    {
-        BehaviorInstance* pComponent = dynamic_cast<BehaviorInstance*>(*nItr);
-        if( pComponent && StringTable->insert(pComponent->getTemplateName()) == stName )
-        {
-            unlockComponentList();
-            return pComponent;
-        }
-    }
-
-    unlockComponentList();
-
-    return NULL;
-}
-
-//-----------------------------------------------------------------------------
-
 U32 SceneObject::getGlobalSceneObjectCount( void )
 {
     return sGlobalSceneObjectCount;

+ 0 - 1
engine/source/2d/sceneobject/SceneObject.h

@@ -565,7 +565,6 @@ public:
     inline bool             getIsAlwaysInScope(void) const              { return mAlwaysInScope; }
     inline void             setWorldQueryKey( const U32 key )           { mWorldQueryKey = key; }
     inline U32              getWorldQueryKey( void ) const              { return mWorldQueryKey; }
-    BehaviorInstance*       behavior(const char *name);
     static U32              getGlobalSceneObjectCount( void );
     inline U32              getSerialId( void ) const                   { return mSerialId; }
 

+ 11 - 10
engine/source/2d/sceneobject/SceneObject_ScriptBinding.h

@@ -2380,13 +2380,23 @@ ConsoleMethod( SceneObject, createPolygonCollisionShape, S32, 3, 3,  "(localPoin
 
 //-----------------------------------------------------------------------------
 
-ConsoleMethod( SceneObject, createPolygonBoxCollisionShape, S32, 3, 7,  "(width, height, [localCentroidX, localCentroidY], [angle]) Creates a polygon box collision shape.\n"
+ConsoleMethod( SceneObject, createPolygonBoxCollisionShape, S32, 2, 7,  "(width, height, [localCentroidX, localCentroidY], [angle]) Creates a polygon box collision shape.\n"
                                                                             "@param width The width of the box."
                                                                             "@param height The height of the box."
                                                                             "@param localCentroidX/Y The local position of the box centroid."
                                                                             "@param angle The angle of the box."
                                                                             "@return (int shapeIndex) The index of the collision shape or (-1) if not created.")
 {
+    // Were any dimensions specified?
+    if( argc == 2 )
+    {
+        // No, so fetch the objects size.
+        const Vector2& size = object->getSize();
+
+        // Create a box surrounding the object.
+        return object->createPolygonBoxCollisionShape( size.x, size.y );
+    }
+
     // Width and height.
     const U32 widthHeightElementCount = Utility::mGetStringElementCount(argv[2]);
 
@@ -3725,12 +3735,3 @@ ConsoleMethod(SceneObject, safeDelete, void, 2, 2, "() - Safely deletes object.\
     object->safeDelete();
 }
 
-//-----------------------------------------------------------------------------
-
-ConsoleMethod(SceneObject, behavior, S32, 3, 3, "(string behaviorName) - Gets the behavior instance ID off of the object based on the behavior name passed.\n"
-                                                   "@param behaviorName The name of the behavior you want to get the instance ID of.\n"
-                                                   "@return (integer behaviorID) The id of the behavior instance.")
-{
-   BehaviorInstance *inst = object->behavior(argv[2]);
-   return inst ? inst->getId() : 0;
-}

+ 0 - 50
engine/source/console/consoleTypes.cc

@@ -33,56 +33,6 @@
 #include "2d/core/Vector2.h"
 #endif
 
-//////////////////////////////////////////////////////////////////////////
-// TypeString
-//////////////////////////////////////////////////////////////////////////
-ConsoleType( Vector2, TypeT2DVector, sizeof(Vector2), "" )
-
-ConsoleGetType( TypeT2DVector )
-{
-    Vector2* pVector = (Vector2*)dptr;  
-    return pVector->scriptThis();
-}
-
-ConsoleSetType( TypeT2DVector )
-{
-    Vector2* pVector = (Vector2*)dptr;  
-    F32 x;
-    F32 y;
-    if( argc == 1 )
-    {
-        S32 args = dSscanf(argv[0], "%g %g", &x, &y);
-        if ( args == 2 )
-        {
-            pVector->Set( x, y );
-            return;
-        }
-        else if ( args == 1 )
-        {
-            pVector->Set( x, x );
-            return;
-        }
-        else
-        {
-            // Warn.
-            Con::warnf("Vector2 must be set as { x [,y] }");
-            return;
-        }
-
-    }
-    else if ( argc == 2 )
-    {
-        pVector->Set( dAtof(argv[0]), dAtof(argv[1]) );
-        return;
-    }
-    else
-    {
-        // Warn.
-        Con::warnf("Vector2 must be set as { x [,y] }");
-        return;
-    }
-}
-
 //////////////////////////////////////////////////////////////////////////
 // TypeString
 //////////////////////////////////////////////////////////////////////////

+ 0 - 1
engine/source/console/consoleTypes.h

@@ -52,6 +52,5 @@ DefineConsoleType( TypeFlag )
 DefineConsoleType( TypeSimObjectPtr )
 DefineConsoleType( TypeSimObjectName )
 DefineConsoleType( TypeSimObjectId )
-DefineConsoleType( TypeT2DVector )
 
 #endif

+ 2 - 0
modules/BuoyancyControllerToy/1/main.cs

@@ -33,6 +33,7 @@ function BuoyancyControllerToy::create( %this )
     SandboxScene.setGravity( 0, -29.8 );
     
     // Configure settings.
+    BuoyancyControllerToy.FluidArea = "-30 -30 30 0";
     BuoyancyControllerToy.SurfaceNormal = "0 1";
     BuoyancyControllerToy.SurfaceOffset = 0;
     BuoyancyControllerToy.FluidDensity = 2.5;
@@ -402,6 +403,7 @@ function BuoyancyControllerToy::updateBuoyancyController( %this )
     %controller = BuoyancyControllerToy.SceneController;
     
     // Update the controller.
+    %controller.FluidArea = BuoyancyControllerToy.FluidArea;
     %controller.SurfaceNormal = BuoyancyControllerToy.SurfaceNormal;
     %controller.SurfaceOffset = BuoyancyControllerToy.SurfaceOffset;
     %controller.FluidDensity = BuoyancyControllerToy.FluidDensity;

+ 0 - 85
modules/Sandbox/1/scripts/defaultPreferences.cs

@@ -1,85 +0,0 @@
-//-----------------------------------------------------------------------------
-// Copyright (c) 2013 GarageGames, LLC
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to
-// deal in the Software without restriction, including without limitation the
-// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
-// sell copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
-// IN THE SOFTWARE.
-//-----------------------------------------------------------------------------
-
-/// Game
-$Game::CompanyName              = "GarageGames LLC";
-$Game::ProductName              = "Torque 2D Sandbox";
-
-// Sandbox.
-$pref::Sandbox::defaultToyId           = "TruckToy";
-$pref::Sandbox::defaultToyVersionId    = 1;
-$pref::Sandbox::defaultBackgroundColor = "Black";
-$pref::Sandbox::metricsOption   = false;
-$pref::Sandbox::fpsmetricsOption = true;
-$pref::Sandbox::controllersOption = false;
-$pref::Sandbox::jointsOption    = false;
-$pref::Sandbox::wireframeOption = false;
-$pref::Sandbox::aabbOption      = false;
-$pref::Sandbox::oobbOption      = false;
-$pref::Sandbox::sleepOption     = false;
-$pref::Sandbox::collisionOption = false;
-$pref::Sandbox::positionOption  = false;
-$pref::Sandbox::sortOption      = false;
-$pref::Sandbox::cameraMouseZoomRate = 0.1;
-$pref::Sandbox::cameraTouchZoomRate = 0.001;
-
-/// iOS
-$pref::iOS::ScreenOrientation   = $iOS::constant::Landscape;
-$pref::iOS::ScreenDepth		    = 32;
-$pref::iOS::UseGameKit          = 0;
-$pref::iOS::UseMusic            = 0;
-$pref::iOS::UseMoviePlayer      = 0;
-$pref::iOS::UseAutoRotate       = 1;
-$pref::iOS::EnableOrientationRotation = 1;
-$pref::iOS::EnableOtherOrientationRotation = 1;   
-$pref::iOS::StatusBarType       = 0;
-
-/// Audio
-$pref::Audio::driver = "OpenAL";
-$pref::Audio::forceMaxDistanceUpdate = 0;
-$pref::Audio::environmentEnabled = 0;
-$pref::Audio::masterVolume   = 1.0;
-$pref::Audio::channelVolume1 = 1.0;
-$pref::Audio::channelVolume2 = 1.0;
-$pref::Audio::channelVolume3 = 1.0;
-$pref::Audio::sfxVolume = 1.0;
-$pref::Audio::musicVolume = 1.0;
-
-/// T2D
-$pref::T2D::ParticlePlayerEmissionRateScale = 1.0;
-$pref::T2D::ParticlePlayerSizeScale = 1.0;
-$pref::T2D::ParticlePlayerForceScale = 1.0;
-$pref::T2D::warnFileDeprecated = 1;
-$pref::T2D::warnSceneOccupancy = 1;
-
-/// Video
-$pref::Video::appliedPref = 0;
-$pref::Video::disableVerticalSync = 1;
-$pref::Video::displayDevice = "OpenGL";
-$pref::Video::preferOpenGL = 1;
-$pref::Video::fullScreen = 0;
-$pref::Video::defaultResolution = "1024 768";
-$pref::Video::windowedRes = "1024 768 32";
-$pref::OpenGL::gammaCorrection = 0.5;
-
-/// Fonts.
-$Gui::fontCacheDirectory = expandPath( "^Sandbox/fonts" );

+ 601 - 601
modules/Sandbox/1/scripts/toolbox.cs

@@ -1,601 +1,601 @@
-//-----------------------------------------------------------------------------
-// Copyright (c) 2013 GarageGames, LLC
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to
-// deal in the Software without restriction, including without limitation the
-// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
-// sell copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
-// IN THE SOFTWARE.
-//-----------------------------------------------------------------------------
-
-$toyAllCategoryIndex = 1;
-$defaultToySelected = false;
-
-//-----------------------------------------------------------------------------
-
-function ToyCategorySelectList::onSelect(%this)
-{
-    // Fetch the index.
-    %index = %this.currentToyCategory;
-
-    $defaultToySelected = false;
-
-    ToyListArray.initialize(%index);
-    ToyListScroller.computeSizes();
-    ToyListScroller.scrollToTop();
-    
-    // Unload the active toy.
-    unloadToy();
-
-    // Flag as the default toy selected.
-    if ($defaultToySelected)
-    {
-        loadToy($defaultModuleID);
-    }
-    else
-    {
-        if ( ToyListArray.getCount() > 0 )
-        {
-            %firstToyButton = ToyListArray.getObject(0);
-            if (isObject(%firstToyButton))
-                %firstToyButton.performSelect();
-        }
-    }
-}
-
-//-----------------------------------------------------------------------------
-
-function ToyCategorySelectList::initialize(%this)
-{
-     %this.toyCategories[$toyAllCategoryIndex] = "All";
-     %this.toyCategories[$toyAllCategoryIndex+1] = "Physics";
-     %this.toyCategories[$toyAllCategoryIndex+2] = "Features";
-     %this.toyCategories[$toyAllCategoryIndex+3] = "Stress Testing";
-     %this.toyCategories[$toyAllCategoryIndex+4] = "Fun and Games";
-     %this.toyCategories[$toyAllCategoryIndex+5] = "Custom";
-     %this.maxToyCategories = $toyAllCategoryIndex + 6;
-
-     // Set the "All" category as the default.
-     // NOTE:    This is important to use so that the user-configurable default toy
-     //          can be selected at start-up.
-     %this.currentToyCategory = $toyAllCategoryIndex;
-
-     %this.setText("All");
-     %this.onSelect();
-}
-
-//-----------------------------------------------------------------------------
-
-function ToyCategorySelectList::nextCategory(%this)
-{
-    if (%this.currentToyCategory >= %this.maxToyCategories)
-        return;
-
-    %this.currentToyCategory++;
-
-    %text = %this.toyCategories[%this.currentToyCategory];
-    %this.setText(%text);
-    %this.onSelect();
-}
-
-//-----------------------------------------------------------------------------
-
-function ToyCategorySelectList::previousCategory(%this)
-{
-    if (%this.currentToyCategory <= $toyAllCategoryIndex)
-        return;
-
-    %this.currentToyCategory--;
-
-    %text = %this.toyCategories[%this.currentToyCategory];
-    %this.setText(%text);
-    %this.onSelect();
-}
-
-//-----------------------------------------------------------------------------
-
-function initializeToolbox()
-{   
-    // Populate the stock colors.
-    %colorCount = getStockColorCount();
-    for ( %i = 0; %i < %colorCount; %i++ )
-    {
-        // Fetch stock color name.
-        %colorName = getStockColorName(%i);
-        
-        // Add to the list.        
-        BackgroundColorSelectList.add( getStockColorName(%i), %i );
-        
-        // Select the color if it's the default one.
-        if ( %colorName $= $pref::Sandbox::defaultBackgroundColor )
-            BackgroundColorSelectList.setSelected( %i );
-    }
-    BackgroundColorSelectList.sort();
-
-    ToyCategorySelectList.initialize();
-
-    // Is this on the desktop?
-    if ( $platform $= "windows" || $platform $= "macos" )
-    {
-        // Yes, so make the controls screen controls visible.
-        ResolutionSelectLabel.Visible = true;
-        ResolutionSelectList.Visible = true;
-        FullscreenOptionLabel.Visible = true;
-        FullscreenOptionButton.Visible = true;
-        
-        // Fetch the active resolution.
-        %activeResolution = getRes();
-        %activeWidth = getWord(%activeResolution, 0);
-        %activeHeight = getWord(%activeResolution, 1);
-        %activeBpp = getWord(%activeResolution, 2);
-        
-        // Fetch the resolutions.
-        %resolutionList = getResolutionList( $pref::Video::displayDevice );
-        %resolutionCount = getWordCount( %resolutionList ) / 3;
-        %inputIndex = 0;
-        %outputIndex = 0;
-        for( %i = 0; %i < %resolutionCount; %i++ )
-        {
-            // Fetch the resolution entry.
-            %width = getWord( %resolutionList, %inputIndex );
-            %height = getWord( %resolutionList, %inputIndex+1 );
-            %bpp = getWord( %resolutionList, %inputIndex+2 );
-            %inputIndex += 3;
-            
-            // Skip the 16-bit ones.
-            if ( %bpp == 16 )
-                continue;
-                
-            // Store the resolution.
-            $sandboxResolutions[%outputIndex] = %width SPC %height SPC %bpp;
-            
-            // Add to the list.
-            ResolutionSelectList.add( %width @ "x" @ %height SPC "(" @ %bpp @ ")", %outputIndex );
-            
-            // Select the resolution if it's the default one.
-            if ( %width == %activeWidth && %height == %activeHeight && %bpp == %activeBpp )
-                ResolutionSelectList.setSelected( %outputIndex );
-                
-            %outputIndex++;
-        }
-    }
-    
-    // Configure the main overlay.
-    SandboxWindow.add(MainOverlay);    
-    %horizPosition = getWord(SandboxWindow.Extent, 0) - getWord(MainOverlay.Extent, 0);
-    %verticalPosition = getWord(SandboxWindow.Extent, 1) - getWord(MainOverlay.Extent, 1);    
-    MainOverlay.position = %horizPosition SPC %verticalPosition;    
-}
-
-//-----------------------------------------------------------------------------
-
-function toggleToolbox(%make)
-{
-    // Finish if being released.
-    if ( !%make )
-        return;
-        
-    // Finish if the console is awake.
-    if ( ConsoleDialog.isAwake() )
-        return;       
-        
-    // Is the toolbox awake?
-    if ( ToolboxDialog.isAwake() )
-    {
-        // Yes, so deactivate it.
-        if ( $enableDirectInput )
-            activateKeyboard();
-        Canvas.popDialog(ToolboxDialog);
-        MainOverlay.setVisible(1);
-        return;
-    }
-    
-    // Activate it.
-    if ( $enableDirectInput )
-        deactivateKeyboard();
-
-    MainOverlay.setVisible(0);
-    Canvas.pushDialog(ToolboxDialog);
-}
-
-//-----------------------------------------------------------------------------
-
-function BackgroundColorSelectList::onSelect(%this)
-{           
-    // Fetch the index.
-    $activeBackgroundColor = %this.getSelected();
- 
-    // Finish if the sandbox scene is not available.
-    if ( !isObject(SandboxScene) )
-        return;
-            
-    // Set the scene color.
-    Canvas.BackgroundColor = getStockColorName($activeBackgroundColor);
-    Canvas.UseBackgroundColor = true;
-}
-
-//-----------------------------------------------------------------------------
-
-function ResolutionSelectList::onSelect(%this)
-{
-    // Finish if the sandbox scene is not available.
-    if ( !isObject(SandboxScene) )
-        return;
-            
-    // Fetch the index.
-    %index = %this.getSelected();
-
-    // Fetch resolution.
-    %resolution = $sandboxResolutions[%index];
-    
-    // Set the screen mode.    
-    setScreenMode( GetWord( %resolution , 0 ), GetWord( %resolution, 1 ), GetWord( %resolution, 2 ), $pref::Video::fullScreen );
-}
-
-//-----------------------------------------------------------------------------
-
-function PauseSceneModeButton::onClick(%this)
-{
-    // Sanity!
-    if ( !isObject(SandboxScene) )
-    {
-        error( "Cannot pause/unpause the Sandbox scene as it does not exist." );
-        return;
-    }
-    
-    // Toggle the scene pause.
-    SandboxScene.setScenePause( !SandboxScene.getScenePause() );   
-}
-
-//-----------------------------------------------------------------------------
-
-function ReloadToyOverlayButton::onClick(%this)
-{
-    // Finish if no toy is loaded.
-    if ( !isObject(Sandbox.ActiveToy) )
-        return;
-
-    // Reset custom controls.
-    resetCustomControls();
-
-    // Reload the toy.
-    loadToy( Sandbox.ActiveToy ); 
-}
-
-//-----------------------------------------------------------------------------
-
-function RestartToyOverlayButton::onClick(%this)
-{
-    // Finish if no toy is loaded.
-    if ( !isObject(Sandbox.ActiveToy) )
-        return;
-
-    // Reset the toy.
-    if ( Sandbox.ActiveToy.ScopeSet.isMethod("reset") )
-        Sandbox.ActiveToy.ScopeSet.reset();
-}
-
-//-----------------------------------------------------------------------------
-
-function updateToolboxOptions()
-{
-    // Finish if the sandbox scene is not available.
-    if ( !isObject(SandboxScene) )
-        return;
-        
-    // Set the scene color.
-    Canvas.BackgroundColor = getStockColorName($activeBackgroundColor);
-    Canvas.UseBackgroundColor = true;        
-       
-    // Set option.
-    if ( $pref::Sandbox::metricsOption )
-        SandboxScene.setDebugOn( "metrics" );
-    else
-        SandboxScene.setDebugOff( "metrics" );
-
-    // Set option.
-    if ( $pref::Sandbox::fpsmetricsOption )
-        SandboxScene.setDebugOn( "fps" );
-    else
-        SandboxScene.setDebugOff( "fps" );
-
-    // Set option.
-    if ( $pref::Sandbox::controllersOption )
-        SandboxScene.setDebugOn( "controllers" );
-    else
-        SandboxScene.setDebugOff( "controllers" );
-                    
-    // Set option.
-    if ( $pref::Sandbox::jointsOption )
-        SandboxScene.setDebugOn( "joints" );
-    else
-        SandboxScene.setDebugOff( "joints" );
-
-    // Set option.
-    if ( $pref::Sandbox::wireframeOption )
-        SandboxScene.setDebugOn( "wireframe" );
-    else
-        SandboxScene.setDebugOff( "wireframe" );
-        
-    // Set option.
-    if ( $pref::Sandbox::aabbOption )
-        SandboxScene.setDebugOn( "aabb" );
-    else
-        SandboxScene.setDebugOff( "aabb" );
-
-    // Set option.
-    if ( $pref::Sandbox::oobbOption )
-        SandboxScene.setDebugOn( "oobb" );
-    else
-        SandboxScene.setDebugOff( "oobb" );
-        
-    // Set option.
-    if ( $pref::Sandbox::sleepOption )
-        SandboxScene.setDebugOn( "sleep" );
-    else
-        SandboxScene.setDebugOff( "sleep" );                
-
-    // Set option.
-    if ( $pref::Sandbox::collisionOption )
-        SandboxScene.setDebugOn( "collision" );
-    else
-        SandboxScene.setDebugOff( "collision" );
-        
-    // Set option.
-    if ( $pref::Sandbox::positionOption )
-        SandboxScene.setDebugOn( "position" );
-    else
-        SandboxScene.setDebugOff( "position" );
-        
-    // Set option.
-    if ( $pref::Sandbox::sortOption )
-        SandboxScene.setDebugOn( "sort" );
-    else
-        SandboxScene.setDebugOff( "sort" );        
-                          
-    // Set the options check-boxe.
-    MetricsOptionCheckBox.setStateOn( $pref::Sandbox::metricsOption );
-    FpsMetricsOptionCheckBox.setStateOn( $pref::Sandbox::fpsmetricsOption );
-    ControllersOptionCheckBox.setStateOn( $pref::Sandbox::controllersOption );
-    JointsOptionCheckBox.setStateOn( $pref::Sandbox::jointsOption );
-    WireframeOptionCheckBox.setStateOn( $pref::Sandbox::wireframeOption );
-    AABBOptionCheckBox.setStateOn( $pref::Sandbox::aabbOption );
-    OOBBOptionCheckBox.setStateOn( $pref::Sandbox::oobbOption );
-    SleepOptionCheckBox.setStateOn( $pref::Sandbox::sleepOption );
-    CollisionOptionCheckBox.setStateOn( $pref::Sandbox::collisionOption );
-    PositionOptionCheckBox.setStateOn( $pref::Sandbox::positionOption );
-    SortOptionCheckBox.setStateOn( $pref::Sandbox::sortOption );
-    BatchOptionCheckBox.setStateOn( SandboxScene.getBatchingEnabled() );
-    
-    // Is this on the desktop?
-    //if ( $platform $= "windows" || $platform $= "macos" )
-    if ( $platform !$= "iOS" )
-    {
-        // Set the fullscreen check-box.
-        FullscreenOptionButton.setStateOn( $pref::Video::fullScreen );
-        
-        // Set the full-screen mode appropriately.
-        if ( isFullScreen() != $pref::Video::fullScreen )
-            toggleFullScreen();            
-    }  
-}
-
-//-----------------------------------------------------------------------------
-
-function setFullscreenOption( %flag )
-{
-    $pref::Video::fullScreen = %flag;
-    updateToolboxOptions();
-}
-
-//-----------------------------------------------------------------------------
-
-function setMetricsOption( %flag )
-{
-    $pref::Sandbox::metricsOption = %flag;
-    updateToolboxOptions();
-}
-
-//-----------------------------------------------------------------------------
-
-function setFPSMetricsOption( %flag )
-{
-    $pref::Sandbox::fpsmetricsOption = %flag;
-    updateToolboxOptions();
-}
-
-//-----------------------------------------------------------------------------
-
-function setMetricsOption( %flag )
-{
-    $pref::Sandbox::metricsOption = %flag;
-    updateToolboxOptions();
-}
-
-//-----------------------------------------------------------------------------
-
-function setControllersOption( %flag )
-{
-    $pref::Sandbox::controllersOption = %flag;
-    updateToolboxOptions();
-}
-
-//-----------------------------------------------------------------------------
-
-function setJointsOption( %flag )
-{
-    $pref::Sandbox::jointsOption = %flag;
-    updateToolboxOptions();
-}
-
-//-----------------------------------------------------------------------------
-
-function setWireframeOption( %flag )
-{
-    $pref::Sandbox::wireframeOption = %flag;
-    updateToolboxOptions();
-}
-
-//-----------------------------------------------------------------------------
-
-function setAABBOption( %flag )
-{
-    $pref::Sandbox::aabbOption = %flag;
-    updateToolboxOptions();
-}
-
-//-----------------------------------------------------------------------------
-
-function setOOBBOption( %flag )
-{
-    $pref::Sandbox::oobbOption = %flag;
-    updateToolboxOptions();
-}
-
-//-----------------------------------------------------------------------------
-
-function setSleepOption( %flag )
-{
-    $pref::Sandbox::sleepOption = %flag;
-    updateToolboxOptions();
-}
-
-//-----------------------------------------------------------------------------
-
-function setCollisionOption( %flag )
-{
-    $pref::Sandbox::collisionOption = %flag;
-    updateToolboxOptions();
-}
-
-//-----------------------------------------------------------------------------
-
-function setPositionOption( %flag )
-{
-    $pref::Sandbox::positionOption = %flag;
-    updateToolboxOptions();
-}
-
-//-----------------------------------------------------------------------------
-
-function setSortOption( %flag )
-{
-    $pref::Sandbox::sortOption = %flag;
-    updateToolboxOptions();
-}
-
-//-----------------------------------------------------------------------------
-
-function ToyListScroller::scrollToNext(%this)
-{
-    %currentScroll = %this.getScrollPositionY();
-    %currentScroll += 85;
-    %this.setScrollPosition(0, %currentScroll);
-}
-
-//-----------------------------------------------------------------------------
-
-function ToyListScroller::scrollToPrevious(%this)
-{
-    %currentScroll = %this.getScrollPositionY();
-    %currentScroll -= 85;
-    %this.setScrollPosition(0, %currentScroll);
-}
-
-//-----------------------------------------------------------------------------
-
-function ToyListArray::initialize(%this, %index)
-{
-    %this.clear();
-    %currentExtent = %this.extent;
-    %newExtent = getWord(%currentExtent, 0) SPC "20";
-    %this.Extent = %newExtent;
-    
-    // Fetch the toy count.
-    %toyCount = SandboxToys.getCount();
-
-    // Populate toys in the selected category.
-    for ( %toyIndex = 0; %toyIndex < %toyCount; %toyIndex++ )
-    {
-        // Fetch the toy module.
-        %moduleDefinition = SandboxToys.getObject( %toyIndex );
-
-        // Skip the toy module if the "all" category is not selected and if the toy is not in the selected category.
-        if ( %index != $toyAllCategoryIndex && %moduleDefinition.ToyCategoryIndex != %index )
-            continue;
-
-        // Fetch the module version.
-        %versionId = %moduleDefinition.versionId;
-
-        // Format module title so that version#1 doesn't show version but all other versions do.
-        if ( %versionId == 1 )
-            %moduleTitle = %moduleDefinition.moduleId;
-        else
-            %moduleTitle = %moduleDefinition.moduleId SPC "(v" @ %moduleDefinition.versionId @ ")";
-
-        // Add the toy GUI list.
-        %this.addToyButton(%moduleTitle, %moduleDefinition);
-        
-        // Select the toy if it's the default and we've not selected a toy yet.
-        if (!$defaultToySelected && %moduleDefinition.moduleId $= $pref::Sandbox::defaultToyId && %moduleDefinition.versionId == $pref::Sandbox::defaultToyVersionId )
-        {
-            $defaultToySelected = true;
-            $defaultModuleID = %moduleDefinition.getId();
-        }
-    }
-}
-
-//-----------------------------------------------------------------------------
-
-function ToyListArray::addToyButton(%this, %moduleTitle, %moduleDefintion)
-{
-    %button = new GuiButtonCtrl()
-    {
-        canSaveDynamicFields = "0";
-        HorizSizing = "relative";
-        class = "ToySelectButton";
-        VertSizing = "relative";
-        isContainer = "0";
-        Profile = "BlueButtonProfile";
-        toolTipProfile = "GuiToolTipProfile";
-        toolTip = %moduleDefintion.Description;
-        Position = "0 0";
-        Extent = "160 80";
-        Visible = "1";
-        toy = %moduleDefintion.getId();
-        isContainer = "0";
-        Active = "1";
-        text = %moduleTitle;
-        groupNum = "-1";
-        buttonType = "PushButton";
-        useMouseEvents = "0";
-    };
-     
-    %button.command = %button @ ".performSelect();";
-    
-    %this.add(%button);
-}
-
-//-----------------------------------------------------------------------------
-
-function ToySelectButton::performSelect(%this)
-{
-    // Finish if already selected.
-    if ( %this.toy == Sandbox.ActiveToy )
-        return;
-    
-    // Load the selected toy.
-    loadToy( %this.toy );
-}
+//-----------------------------------------------------------------------------
+// Copyright (c) 2013 GarageGames, LLC
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to
+// deal in the Software without restriction, including without limitation the
+// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+// sell copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+// IN THE SOFTWARE.
+//-----------------------------------------------------------------------------
+
+$toyAllCategoryIndex = 1;
+$defaultToySelected = false;
+
+//-----------------------------------------------------------------------------
+
+function ToyCategorySelectList::onSelect(%this)
+{
+    // Fetch the index.
+    %index = %this.currentToyCategory;
+
+    $defaultToySelected = false;
+
+    ToyListArray.initialize(%index);
+    ToyListScroller.computeSizes();
+    ToyListScroller.scrollToTop();
+    
+    // Unload the active toy.
+    unloadToy();
+
+    // Flag as the default toy selected.
+    if ($defaultToySelected)
+    {
+        loadToy($defaultModuleID);
+    }
+    else
+    {
+        if ( ToyListArray.getCount() > 0 )
+        {
+            %firstToyButton = ToyListArray.getObject(0);
+            if (isObject(%firstToyButton))
+                %firstToyButton.performSelect();
+        }
+    }
+}
+
+//-----------------------------------------------------------------------------
+
+function ToyCategorySelectList::initialize(%this)
+{
+     %this.toyCategories[$toyAllCategoryIndex] = "All";
+     %this.toyCategories[$toyAllCategoryIndex+1] = "Physics";
+     %this.toyCategories[$toyAllCategoryIndex+2] = "Features";
+     %this.toyCategories[$toyAllCategoryIndex+3] = "Stress Testing";
+     %this.toyCategories[$toyAllCategoryIndex+4] = "Fun and Games";
+     %this.toyCategories[$toyAllCategoryIndex+5] = "Custom";
+     %this.maxToyCategories = $toyAllCategoryIndex + 6;
+
+     // Set the "All" category as the default.
+     // NOTE:    This is important to use so that the user-configurable default toy
+     //          can be selected at start-up.
+     %this.currentToyCategory = $toyAllCategoryIndex;
+
+     %this.setText("All");
+     %this.onSelect();
+}
+
+//-----------------------------------------------------------------------------
+
+function ToyCategorySelectList::nextCategory(%this)
+{
+    if (%this.currentToyCategory >= %this.maxToyCategories)
+        return;
+
+    %this.currentToyCategory++;
+
+    %text = %this.toyCategories[%this.currentToyCategory];
+    %this.setText(%text);
+    %this.onSelect();
+}
+
+//-----------------------------------------------------------------------------
+
+function ToyCategorySelectList::previousCategory(%this)
+{
+    if (%this.currentToyCategory <= $toyAllCategoryIndex)
+        return;
+
+    %this.currentToyCategory--;
+
+    %text = %this.toyCategories[%this.currentToyCategory];
+    %this.setText(%text);
+    %this.onSelect();
+}
+
+//-----------------------------------------------------------------------------
+
+function initializeToolbox()
+{   
+    // Populate the stock colors.
+    %colorCount = getStockColorCount();
+    for ( %i = 0; %i < %colorCount; %i++ )
+    {
+        // Fetch stock color name.
+        %colorName = getStockColorName(%i);
+        
+        // Add to the list.        
+        BackgroundColorSelectList.add( getStockColorName(%i), %i );
+        
+        // Select the color if it's the default one.
+        if ( %colorName $= $pref::Sandbox::defaultBackgroundColor )
+            BackgroundColorSelectList.setSelected( %i );
+    }
+    BackgroundColorSelectList.sort();
+
+    ToyCategorySelectList.initialize();
+
+    // Is this on the desktop?
+    if ( $platform $= "windows" || $platform $= "macos" )
+    {
+        // Yes, so make the controls screen controls visible.
+        ResolutionSelectLabel.Visible = true;
+        ResolutionSelectList.Visible = true;
+        FullscreenOptionLabel.Visible = true;
+        FullscreenOptionButton.Visible = true;
+        
+        // Fetch the active resolution.
+        %activeResolution = getRes();
+        %activeWidth = getWord(%activeResolution, 0);
+        %activeHeight = getWord(%activeResolution, 1);
+        %activeBpp = getWord(%activeResolution, 2);
+        
+        // Fetch the resolutions.
+        %resolutionList = getResolutionList( $pref::Video::displayDevice );
+        %resolutionCount = getWordCount( %resolutionList ) / 3;
+        %inputIndex = 0;
+        %outputIndex = 0;
+        for( %i = 0; %i < %resolutionCount; %i++ )
+        {
+            // Fetch the resolution entry.
+            %width = getWord( %resolutionList, %inputIndex );
+            %height = getWord( %resolutionList, %inputIndex+1 );
+            %bpp = getWord( %resolutionList, %inputIndex+2 );
+            %inputIndex += 3;
+            
+            // Skip the 16-bit ones.
+            if ( %bpp == 16 )
+                continue;
+                
+            // Store the resolution.
+            $sandboxResolutions[%outputIndex] = %width SPC %height SPC %bpp;
+            
+            // Add to the list.
+            ResolutionSelectList.add( %width @ "x" @ %height SPC "(" @ %bpp @ ")", %outputIndex );
+            
+            // Select the resolution if it's the default one.
+            if ( %width == %activeWidth && %height == %activeHeight && %bpp == %activeBpp )
+                ResolutionSelectList.setSelected( %outputIndex );
+                
+            %outputIndex++;
+        }
+    }
+    
+    // Configure the main overlay.
+    SandboxWindow.add(MainOverlay);    
+    %horizPosition = getWord(SandboxWindow.Extent, 0) - getWord(MainOverlay.Extent, 0);
+    %verticalPosition = getWord(SandboxWindow.Extent, 1) - getWord(MainOverlay.Extent, 1);    
+    MainOverlay.position = %horizPosition SPC %verticalPosition;    
+}
+
+//-----------------------------------------------------------------------------
+
+function toggleToolbox(%make)
+{
+    // Finish if being released.
+    if ( !%make )
+        return;
+        
+    // Finish if the console is awake.
+    if ( ConsoleDialog.isAwake() )
+        return;       
+        
+    // Is the toolbox awake?
+    if ( ToolboxDialog.isAwake() )
+    {
+        // Yes, so deactivate it.
+        if ( $enableDirectInput )
+            activateKeyboard();
+        Canvas.popDialog(ToolboxDialog);
+        MainOverlay.setVisible(1);
+        return;
+    }
+    
+    // Activate it.
+    if ( $enableDirectInput )
+        deactivateKeyboard();
+
+    MainOverlay.setVisible(0);
+    Canvas.pushDialog(ToolboxDialog);
+}
+
+//-----------------------------------------------------------------------------
+
+function BackgroundColorSelectList::onSelect(%this)
+{           
+    // Fetch the index.
+    $activeBackgroundColor = %this.getSelected();
+ 
+    // Finish if the sandbox scene is not available.
+    if ( !isObject(SandboxScene) )
+        return;
+            
+    // Set the scene color.
+    SandboxScene.BackgroundColor = getStockColorName($activeBackgroundColor);
+    SandboxScene.UseBackgroundColor = true;
+}
+
+//-----------------------------------------------------------------------------
+
+function ResolutionSelectList::onSelect(%this)
+{
+    // Finish if the sandbox scene is not available.
+    if ( !isObject(SandboxScene) )
+        return;
+            
+    // Fetch the index.
+    %index = %this.getSelected();
+
+    // Fetch resolution.
+    %resolution = $sandboxResolutions[%index];
+    
+    // Set the screen mode.    
+    setScreenMode( GetWord( %resolution , 0 ), GetWord( %resolution, 1 ), GetWord( %resolution, 2 ), $pref::Video::fullScreen );
+}
+
+//-----------------------------------------------------------------------------
+
+function PauseSceneModeButton::onClick(%this)
+{
+    // Sanity!
+    if ( !isObject(SandboxScene) )
+    {
+        error( "Cannot pause/unpause the Sandbox scene as it does not exist." );
+        return;
+    }
+    
+    // Toggle the scene pause.
+    SandboxScene.setScenePause( !SandboxScene.getScenePause() );   
+}
+
+//-----------------------------------------------------------------------------
+
+function ReloadToyOverlayButton::onClick(%this)
+{
+    // Finish if no toy is loaded.
+    if ( !isObject(Sandbox.ActiveToy) )
+        return;
+
+    // Reset custom controls.
+    resetCustomControls();
+
+    // Reload the toy.
+    loadToy( Sandbox.ActiveToy ); 
+}
+
+//-----------------------------------------------------------------------------
+
+function RestartToyOverlayButton::onClick(%this)
+{
+    // Finish if no toy is loaded.
+    if ( !isObject(Sandbox.ActiveToy) )
+        return;
+
+    // Reset the toy.
+    if ( Sandbox.ActiveToy.ScopeSet.isMethod("reset") )
+        Sandbox.ActiveToy.ScopeSet.reset();
+}
+
+//-----------------------------------------------------------------------------
+
+function updateToolboxOptions()
+{
+    // Finish if the sandbox scene is not available.
+    if ( !isObject(SandboxScene) )
+        return;
+        
+    // Set the scene color.
+    SandboxScene.BackgroundColor = getStockColorName($activeBackgroundColor);
+    SandboxScene.UseBackgroundColor = true;        
+       
+    // Set option.
+    if ( $pref::Sandbox::metricsOption )
+        SandboxScene.setDebugOn( "metrics" );
+    else
+        SandboxScene.setDebugOff( "metrics" );
+
+    // Set option.
+    if ( $pref::Sandbox::fpsmetricsOption )
+        SandboxScene.setDebugOn( "fps" );
+    else
+        SandboxScene.setDebugOff( "fps" );
+
+    // Set option.
+    if ( $pref::Sandbox::controllersOption )
+        SandboxScene.setDebugOn( "controllers" );
+    else
+        SandboxScene.setDebugOff( "controllers" );
+                    
+    // Set option.
+    if ( $pref::Sandbox::jointsOption )
+        SandboxScene.setDebugOn( "joints" );
+    else
+        SandboxScene.setDebugOff( "joints" );
+
+    // Set option.
+    if ( $pref::Sandbox::wireframeOption )
+        SandboxScene.setDebugOn( "wireframe" );
+    else
+        SandboxScene.setDebugOff( "wireframe" );
+        
+    // Set option.
+    if ( $pref::Sandbox::aabbOption )
+        SandboxScene.setDebugOn( "aabb" );
+    else
+        SandboxScene.setDebugOff( "aabb" );
+
+    // Set option.
+    if ( $pref::Sandbox::oobbOption )
+        SandboxScene.setDebugOn( "oobb" );
+    else
+        SandboxScene.setDebugOff( "oobb" );
+        
+    // Set option.
+    if ( $pref::Sandbox::sleepOption )
+        SandboxScene.setDebugOn( "sleep" );
+    else
+        SandboxScene.setDebugOff( "sleep" );                
+
+    // Set option.
+    if ( $pref::Sandbox::collisionOption )
+        SandboxScene.setDebugOn( "collision" );
+    else
+        SandboxScene.setDebugOff( "collision" );
+        
+    // Set option.
+    if ( $pref::Sandbox::positionOption )
+        SandboxScene.setDebugOn( "position" );
+    else
+        SandboxScene.setDebugOff( "position" );
+        
+    // Set option.
+    if ( $pref::Sandbox::sortOption )
+        SandboxScene.setDebugOn( "sort" );
+    else
+        SandboxScene.setDebugOff( "sort" );        
+                          
+    // Set the options check-boxe.
+    MetricsOptionCheckBox.setStateOn( $pref::Sandbox::metricsOption );
+    FpsMetricsOptionCheckBox.setStateOn( $pref::Sandbox::fpsmetricsOption );
+    ControllersOptionCheckBox.setStateOn( $pref::Sandbox::controllersOption );
+    JointsOptionCheckBox.setStateOn( $pref::Sandbox::jointsOption );
+    WireframeOptionCheckBox.setStateOn( $pref::Sandbox::wireframeOption );
+    AABBOptionCheckBox.setStateOn( $pref::Sandbox::aabbOption );
+    OOBBOptionCheckBox.setStateOn( $pref::Sandbox::oobbOption );
+    SleepOptionCheckBox.setStateOn( $pref::Sandbox::sleepOption );
+    CollisionOptionCheckBox.setStateOn( $pref::Sandbox::collisionOption );
+    PositionOptionCheckBox.setStateOn( $pref::Sandbox::positionOption );
+    SortOptionCheckBox.setStateOn( $pref::Sandbox::sortOption );
+    BatchOptionCheckBox.setStateOn( SandboxScene.getBatchingEnabled() );
+    
+    // Is this on the desktop?
+    //if ( $platform $= "windows" || $platform $= "macos" )
+    if ( $platform !$= "iOS" )
+    {
+        // Set the fullscreen check-box.
+        FullscreenOptionButton.setStateOn( $pref::Video::fullScreen );
+        
+        // Set the full-screen mode appropriately.
+        if ( isFullScreen() != $pref::Video::fullScreen )
+            toggleFullScreen();            
+    }  
+}
+
+//-----------------------------------------------------------------------------
+
+function setFullscreenOption( %flag )
+{
+    $pref::Video::fullScreen = %flag;
+    updateToolboxOptions();
+}
+
+//-----------------------------------------------------------------------------
+
+function setMetricsOption( %flag )
+{
+    $pref::Sandbox::metricsOption = %flag;
+    updateToolboxOptions();
+}
+
+//-----------------------------------------------------------------------------
+
+function setFPSMetricsOption( %flag )
+{
+    $pref::Sandbox::fpsmetricsOption = %flag;
+    updateToolboxOptions();
+}
+
+//-----------------------------------------------------------------------------
+
+function setMetricsOption( %flag )
+{
+    $pref::Sandbox::metricsOption = %flag;
+    updateToolboxOptions();
+}
+
+//-----------------------------------------------------------------------------
+
+function setControllersOption( %flag )
+{
+    $pref::Sandbox::controllersOption = %flag;
+    updateToolboxOptions();
+}
+
+//-----------------------------------------------------------------------------
+
+function setJointsOption( %flag )
+{
+    $pref::Sandbox::jointsOption = %flag;
+    updateToolboxOptions();
+}
+
+//-----------------------------------------------------------------------------
+
+function setWireframeOption( %flag )
+{
+    $pref::Sandbox::wireframeOption = %flag;
+    updateToolboxOptions();
+}
+
+//-----------------------------------------------------------------------------
+
+function setAABBOption( %flag )
+{
+    $pref::Sandbox::aabbOption = %flag;
+    updateToolboxOptions();
+}
+
+//-----------------------------------------------------------------------------
+
+function setOOBBOption( %flag )
+{
+    $pref::Sandbox::oobbOption = %flag;
+    updateToolboxOptions();
+}
+
+//-----------------------------------------------------------------------------
+
+function setSleepOption( %flag )
+{
+    $pref::Sandbox::sleepOption = %flag;
+    updateToolboxOptions();
+}
+
+//-----------------------------------------------------------------------------
+
+function setCollisionOption( %flag )
+{
+    $pref::Sandbox::collisionOption = %flag;
+    updateToolboxOptions();
+}
+
+//-----------------------------------------------------------------------------
+
+function setPositionOption( %flag )
+{
+    $pref::Sandbox::positionOption = %flag;
+    updateToolboxOptions();
+}
+
+//-----------------------------------------------------------------------------
+
+function setSortOption( %flag )
+{
+    $pref::Sandbox::sortOption = %flag;
+    updateToolboxOptions();
+}
+
+//-----------------------------------------------------------------------------
+
+function ToyListScroller::scrollToNext(%this)
+{
+    %currentScroll = %this.getScrollPositionY();
+    %currentScroll += 85;
+    %this.setScrollPosition(0, %currentScroll);
+}
+
+//-----------------------------------------------------------------------------
+
+function ToyListScroller::scrollToPrevious(%this)
+{
+    %currentScroll = %this.getScrollPositionY();
+    %currentScroll -= 85;
+    %this.setScrollPosition(0, %currentScroll);
+}
+
+//-----------------------------------------------------------------------------
+
+function ToyListArray::initialize(%this, %index)
+{
+    %this.clear();
+    %currentExtent = %this.extent;
+    %newExtent = getWord(%currentExtent, 0) SPC "20";
+    %this.Extent = %newExtent;
+    
+    // Fetch the toy count.
+    %toyCount = SandboxToys.getCount();
+
+    // Populate toys in the selected category.
+    for ( %toyIndex = 0; %toyIndex < %toyCount; %toyIndex++ )
+    {
+        // Fetch the toy module.
+        %moduleDefinition = SandboxToys.getObject( %toyIndex );
+
+        // Skip the toy module if the "all" category is not selected and if the toy is not in the selected category.
+        if ( %index != $toyAllCategoryIndex && %moduleDefinition.ToyCategoryIndex != %index )
+            continue;
+
+        // Fetch the module version.
+        %versionId = %moduleDefinition.versionId;
+
+        // Format module title so that version#1 doesn't show version but all other versions do.
+        if ( %versionId == 1 )
+            %moduleTitle = %moduleDefinition.moduleId;
+        else
+            %moduleTitle = %moduleDefinition.moduleId SPC "(v" @ %moduleDefinition.versionId @ ")";
+
+        // Add the toy GUI list.
+        %this.addToyButton(%moduleTitle, %moduleDefinition);
+        
+        // Select the toy if it's the default and we've not selected a toy yet.
+        if (!$defaultToySelected && %moduleDefinition.moduleId $= $pref::Sandbox::defaultToyId && %moduleDefinition.versionId == $pref::Sandbox::defaultToyVersionId )
+        {
+            $defaultToySelected = true;
+            $defaultModuleID = %moduleDefinition.getId();
+        }
+    }
+}
+
+//-----------------------------------------------------------------------------
+
+function ToyListArray::addToyButton(%this, %moduleTitle, %moduleDefintion)
+{
+    %button = new GuiButtonCtrl()
+    {
+        canSaveDynamicFields = "0";
+        HorizSizing = "relative";
+        class = "ToySelectButton";
+        VertSizing = "relative";
+        isContainer = "0";
+        Profile = "BlueButtonProfile";
+        toolTipProfile = "GuiToolTipProfile";
+        toolTip = %moduleDefintion.Description;
+        Position = "0 0";
+        Extent = "160 80";
+        Visible = "1";
+        toy = %moduleDefintion.getId();
+        isContainer = "0";
+        Active = "1";
+        text = %moduleTitle;
+        groupNum = "-1";
+        buttonType = "PushButton";
+        useMouseEvents = "0";
+    };
+     
+    %button.command = %button @ ".performSelect();";
+    
+    %this.add(%button);
+}
+
+//-----------------------------------------------------------------------------
+
+function ToySelectButton::performSelect(%this)
+{
+    // Finish if already selected.
+    if ( %this.toy == Sandbox.ActiveToy )
+        return;
+    
+    // Load the selected toy.
+    loadToy( %this.toy );
+}

BIN
modules/ToyAssets/1/assets/images/Blank.png


+ 3 - 0
modules/ToyAssets/1/assets/images/blank.asset.taml

@@ -0,0 +1,3 @@
+<ImageAsset
+    AssetName="Blank"
+    ImageFile="Blank.png"/>