Răsfoiți Sursa

Merge remote-tracking branch 'upstream/next'

Joilnen Leite 13 ani în urmă
părinte
comite
e18ee25928

+ 1 - 1
gameplay-newproject.sh

@@ -173,7 +173,7 @@ fi
 # Copy Microsoft Visual Studio project files
 # Copy Microsoft Visual Studio project files
 #############################################
 #############################################
 cp "gameplay-template/gameplay-template.vcxproj" "$projPath/$projName.vcxproj"
 cp "gameplay-template/gameplay-template.vcxproj" "$projPath/$projName.vcxproj"
-aliassedinplace "s*TEMPLATE_PROJECT*$projectName*g" "$projPath/$projName.vcxproj"
+aliassedinplace "s*TEMPLATE_PROJECT*$projName*g" "$projPath/$projName.vcxproj"
 aliassedinplace "s*TemplateGame*$className*g" "$projPath/$projName.vcxproj"
 aliassedinplace "s*TemplateGame*$className*g" "$projPath/$projName.vcxproj"
 aliassedinplace "s*GAMEPLAY_PATH*$gpPath*g" "$projPath/$projName.vcxproj"
 aliassedinplace "s*GAMEPLAY_PATH*$gpPath*g" "$projPath/$projName.vcxproj"
 
 

+ 7 - 14
gameplay/.cproject

@@ -20,11 +20,10 @@
 							<builder buildPath="${workspace_loc:/gameplay/Device-Debug}" id="org.eclipse.cdt.build.core.internal.builder.159190287" keepEnvironmentInBuildfile="false" name="CDT Internal Builder" superClass="org.eclipse.cdt.build.core.internal.builder"/>
 							<builder buildPath="${workspace_loc:/gameplay/Device-Debug}" id="org.eclipse.cdt.build.core.internal.builder.159190287" keepEnvironmentInBuildfile="false" name="CDT Internal Builder" superClass="org.eclipse.cdt.build.core.internal.builder"/>
 							<tool id="com.qnx.qcc.tool.compiler.96907942" name="QCC Compiler" superClass="com.qnx.qcc.tool.compiler">
 							<tool id="com.qnx.qcc.tool.compiler.96907942" name="QCC Compiler" superClass="com.qnx.qcc.tool.compiler">
 								<option id="com.qnx.qcc.option.compile.debug.1765481355" name="Debug (-g)" superClass="com.qnx.qcc.option.compile.debug" value="true" valueType="boolean"/>
 								<option id="com.qnx.qcc.option.compile.debug.1765481355" name="Debug (-g)" superClass="com.qnx.qcc.option.compile.debug" value="true" valueType="boolean"/>
-								<option id="com.qnx.qcc.option.compiler.security.311918799" name="Enhanced Security (-fstack-protector-strong)" superClass="com.qnx.qcc.option.compiler.security" value="true" valueType="boolean"/>
+								<option id="com.qnx.qcc.option.compiler.security.311918799" name="Enhanced Security (-fstack-protector-strong)" superClass="com.qnx.qcc.option.compiler.security" value="false" valueType="boolean"/>
 								<option id="com.qnx.qcc.option.compiler.defines.1481323494" name="Defines (-D)" superClass="com.qnx.qcc.option.compiler.defines" valueType="definedSymbols">
 								<option id="com.qnx.qcc.option.compiler.defines.1481323494" name="Defines (-D)" superClass="com.qnx.qcc.option.compiler.defines" valueType="definedSymbols">
 									<listOptionValue builtIn="false" value="_FORTIFY_SOURCE=2"/>
 									<listOptionValue builtIn="false" value="_FORTIFY_SOURCE=2"/>
 									<listOptionValue builtIn="false" value="BT_USE_NEON"/>
 									<listOptionValue builtIn="false" value="BT_USE_NEON"/>
-									<listOptionValue builtIn="false" value="BLACKBERRY_USE_GAMEPAD"/>
 								</option>
 								</option>
 								<option id="com.qnx.qcc.option.compiler.includePath.2133604142" name="Include Directories (-I)" superClass="com.qnx.qcc.option.compiler.includePath" valueType="includePath">
 								<option id="com.qnx.qcc.option.compiler.includePath.2133604142" name="Include Directories (-I)" superClass="com.qnx.qcc.option.compiler.includePath" valueType="includePath">
 									<listOptionValue builtIn="false" value="&quot;../../external-deps/lua/include&quot;"/>
 									<listOptionValue builtIn="false" value="&quot;../../external-deps/lua/include&quot;"/>
@@ -84,11 +83,10 @@
 							<builder buildPath="${workspace_loc:/gameplay/Device-Release}" id="cdt.managedbuild.target.gnu.builder.base.1199322737" keepEnvironmentInBuildfile="false" name="Gnu Make Builder" superClass="cdt.managedbuild.target.gnu.builder.base"/>
 							<builder buildPath="${workspace_loc:/gameplay/Device-Release}" id="cdt.managedbuild.target.gnu.builder.base.1199322737" keepEnvironmentInBuildfile="false" name="Gnu Make Builder" superClass="cdt.managedbuild.target.gnu.builder.base"/>
 							<tool id="com.qnx.qcc.tool.compiler.1345567866" name="QCC Compiler" superClass="com.qnx.qcc.tool.compiler">
 							<tool id="com.qnx.qcc.tool.compiler.1345567866" name="QCC Compiler" superClass="com.qnx.qcc.tool.compiler">
 								<option id="com.qnx.qcc.option.compiler.optlevel.1056793982" name="Optimization Level" superClass="com.qnx.qcc.option.compiler.optlevel" value="com.qnx.qcc.option.compiler.optlevel.1" valueType="enumerated"/>
 								<option id="com.qnx.qcc.option.compiler.optlevel.1056793982" name="Optimization Level" superClass="com.qnx.qcc.option.compiler.optlevel" value="com.qnx.qcc.option.compiler.optlevel.1" valueType="enumerated"/>
-								<option id="com.qnx.qcc.option.compiler.security.324540233" name="Enhanced Security (-fstack-protector-strong)" superClass="com.qnx.qcc.option.compiler.security" value="true" valueType="boolean"/>
+								<option id="com.qnx.qcc.option.compiler.security.324540233" name="Enhanced Security (-fstack-protector-strong)" superClass="com.qnx.qcc.option.compiler.security" value="false" valueType="boolean"/>
 								<option id="com.qnx.qcc.option.compiler.defines.398688299" name="Defines (-D)" superClass="com.qnx.qcc.option.compiler.defines" valueType="definedSymbols">
 								<option id="com.qnx.qcc.option.compiler.defines.398688299" name="Defines (-D)" superClass="com.qnx.qcc.option.compiler.defines" valueType="definedSymbols">
 									<listOptionValue builtIn="false" value="_FORTIFY_SOURCE=2"/>
 									<listOptionValue builtIn="false" value="_FORTIFY_SOURCE=2"/>
 									<listOptionValue builtIn="false" value="BT_USE_NEON"/>
 									<listOptionValue builtIn="false" value="BT_USE_NEON"/>
-									<listOptionValue builtIn="false" value="BLACKBERRY_USE_GAMEPAD"/>
 								</option>
 								</option>
 								<option id="com.qnx.qcc.option.compiler.includePath.1670164593" name="Include Directories (-I)" superClass="com.qnx.qcc.option.compiler.includePath" valueType="includePath">
 								<option id="com.qnx.qcc.option.compiler.includePath.1670164593" name="Include Directories (-I)" superClass="com.qnx.qcc.option.compiler.includePath" valueType="includePath">
 									<listOptionValue builtIn="false" value="&quot;../../external-deps/bullet/include&quot;"/>
 									<listOptionValue builtIn="false" value="&quot;../../external-deps/bullet/include&quot;"/>
@@ -146,11 +144,10 @@
 							<tool id="com.qnx.qcc.tool.compiler.1281156842" name="QCC Compiler" superClass="com.qnx.qcc.tool.compiler">
 							<tool id="com.qnx.qcc.tool.compiler.1281156842" name="QCC Compiler" superClass="com.qnx.qcc.tool.compiler">
 								<option id="com.qnx.qcc.option.compile.debug.626405189" name="Debug (-g)" superClass="com.qnx.qcc.option.compile.debug" value="true" valueType="boolean"/>
 								<option id="com.qnx.qcc.option.compile.debug.626405189" name="Debug (-g)" superClass="com.qnx.qcc.option.compile.debug" value="true" valueType="boolean"/>
 								<option id="com.qnx.qcc.option.compiler.profile2.1207899085" name="Build for Profiling (Function Instrumentation) (-finstrument-functions)" superClass="com.qnx.qcc.option.compiler.profile2" value="true" valueType="boolean"/>
 								<option id="com.qnx.qcc.option.compiler.profile2.1207899085" name="Build for Profiling (Function Instrumentation) (-finstrument-functions)" superClass="com.qnx.qcc.option.compiler.profile2" value="true" valueType="boolean"/>
-								<option id="com.qnx.qcc.option.compiler.security.1649809766" name="Enhanced Security (-fstack-protector-strong)" superClass="com.qnx.qcc.option.compiler.security" value="true" valueType="boolean"/>
+								<option id="com.qnx.qcc.option.compiler.security.1649809766" name="Enhanced Security (-fstack-protector-strong)" superClass="com.qnx.qcc.option.compiler.security" value="false" valueType="boolean"/>
 								<option id="com.qnx.qcc.option.compiler.defines.276653249" name="Defines (-D)" superClass="com.qnx.qcc.option.compiler.defines" valueType="definedSymbols">
 								<option id="com.qnx.qcc.option.compiler.defines.276653249" name="Defines (-D)" superClass="com.qnx.qcc.option.compiler.defines" valueType="definedSymbols">
 									<listOptionValue builtIn="false" value="_FORTIFY_SOURCE=2"/>
 									<listOptionValue builtIn="false" value="_FORTIFY_SOURCE=2"/>
 									<listOptionValue builtIn="false" value="BT_USE_NEON"/>
 									<listOptionValue builtIn="false" value="BT_USE_NEON"/>
-									<listOptionValue builtIn="false" value="BLACKBERRY_USE_GAMEPAD"/>
 								</option>
 								</option>
 								<option id="com.qnx.qcc.option.compiler.includePath.1503059677" name="Include Directories (-I)" superClass="com.qnx.qcc.option.compiler.includePath" valueType="includePath">
 								<option id="com.qnx.qcc.option.compiler.includePath.1503059677" name="Include Directories (-I)" superClass="com.qnx.qcc.option.compiler.includePath" valueType="includePath">
 									<listOptionValue builtIn="false" value="&quot;../../external-deps/bullet/include&quot;"/>
 									<listOptionValue builtIn="false" value="&quot;../../external-deps/bullet/include&quot;"/>
@@ -211,11 +208,10 @@
 							<tool id="com.qnx.qcc.tool.compiler.306557636" name="QCC Compiler" superClass="com.qnx.qcc.tool.compiler">
 							<tool id="com.qnx.qcc.tool.compiler.306557636" name="QCC Compiler" superClass="com.qnx.qcc.tool.compiler">
 								<option id="com.qnx.qcc.option.compile.debug.168813234" name="Debug (-g)" superClass="com.qnx.qcc.option.compile.debug" value="true" valueType="boolean"/>
 								<option id="com.qnx.qcc.option.compile.debug.168813234" name="Debug (-g)" superClass="com.qnx.qcc.option.compile.debug" value="true" valueType="boolean"/>
 								<option id="com.qnx.qcc.option.compiler.coverage.1032644527" name="Build for Code Coverage (-Wc,-ftest-coverage -Wc,-fprofile-arcs)" superClass="com.qnx.qcc.option.compiler.coverage" value="true" valueType="boolean"/>
 								<option id="com.qnx.qcc.option.compiler.coverage.1032644527" name="Build for Code Coverage (-Wc,-ftest-coverage -Wc,-fprofile-arcs)" superClass="com.qnx.qcc.option.compiler.coverage" value="true" valueType="boolean"/>
-								<option id="com.qnx.qcc.option.compiler.security.1227516972" name="Enhanced Security (-fstack-protector-strong)" superClass="com.qnx.qcc.option.compiler.security" value="true" valueType="boolean"/>
+								<option id="com.qnx.qcc.option.compiler.security.1227516972" name="Enhanced Security (-fstack-protector-strong)" superClass="com.qnx.qcc.option.compiler.security" value="false" valueType="boolean"/>
 								<option id="com.qnx.qcc.option.compiler.defines.374283024" name="Defines (-D)" superClass="com.qnx.qcc.option.compiler.defines" valueType="definedSymbols">
 								<option id="com.qnx.qcc.option.compiler.defines.374283024" name="Defines (-D)" superClass="com.qnx.qcc.option.compiler.defines" valueType="definedSymbols">
 									<listOptionValue builtIn="false" value="_FORTIFY_SOURCE=2"/>
 									<listOptionValue builtIn="false" value="_FORTIFY_SOURCE=2"/>
 									<listOptionValue builtIn="false" value="BT_USE_NEON"/>
 									<listOptionValue builtIn="false" value="BT_USE_NEON"/>
-									<listOptionValue builtIn="false" value="BLACKBERRY_USE_GAMEPAD"/>
 								</option>
 								</option>
 								<option id="com.qnx.qcc.option.compiler.includePath.1769677874" name="Include Directories (-I)" superClass="com.qnx.qcc.option.compiler.includePath" valueType="includePath">
 								<option id="com.qnx.qcc.option.compiler.includePath.1769677874" name="Include Directories (-I)" superClass="com.qnx.qcc.option.compiler.includePath" valueType="includePath">
 									<listOptionValue builtIn="false" value="&quot;../../external-deps/bullet/include&quot;"/>
 									<listOptionValue builtIn="false" value="&quot;../../external-deps/bullet/include&quot;"/>
@@ -274,11 +270,10 @@
 							<builder buildPath="${workspace_loc:/gameplay/Simulator}" id="cdt.managedbuild.target.gnu.builder.base.10075032" keepEnvironmentInBuildfile="false" name="Gnu Make Builder" superClass="cdt.managedbuild.target.gnu.builder.base"/>
 							<builder buildPath="${workspace_loc:/gameplay/Simulator}" id="cdt.managedbuild.target.gnu.builder.base.10075032" keepEnvironmentInBuildfile="false" name="Gnu Make Builder" superClass="cdt.managedbuild.target.gnu.builder.base"/>
 							<tool id="com.qnx.qcc.tool.compiler.1004416224" name="QCC Compiler" superClass="com.qnx.qcc.tool.compiler">
 							<tool id="com.qnx.qcc.tool.compiler.1004416224" name="QCC Compiler" superClass="com.qnx.qcc.tool.compiler">
 								<option id="com.qnx.qcc.option.compile.debug.1122485646" name="Debug (-g)" superClass="com.qnx.qcc.option.compile.debug" value="true" valueType="boolean"/>
 								<option id="com.qnx.qcc.option.compile.debug.1122485646" name="Debug (-g)" superClass="com.qnx.qcc.option.compile.debug" value="true" valueType="boolean"/>
-								<option id="com.qnx.qcc.option.compiler.security.1671403331" name="Enhanced Security (-fstack-protector-strong)" superClass="com.qnx.qcc.option.compiler.security" value="true" valueType="boolean"/>
+								<option id="com.qnx.qcc.option.compiler.security.1671403331" name="Enhanced Security (-fstack-protector-strong)" superClass="com.qnx.qcc.option.compiler.security" value="false" valueType="boolean"/>
 								<option id="com.qnx.qcc.option.compiler.defines.1863269886" name="Defines (-D)" superClass="com.qnx.qcc.option.compiler.defines" valueType="definedSymbols">
 								<option id="com.qnx.qcc.option.compiler.defines.1863269886" name="Defines (-D)" superClass="com.qnx.qcc.option.compiler.defines" valueType="definedSymbols">
 									<listOptionValue builtIn="false" value="_FORTIFY_SOURCE=2"/>
 									<listOptionValue builtIn="false" value="_FORTIFY_SOURCE=2"/>
 									<listOptionValue builtIn="false" value="BT_USE_NEON"/>
 									<listOptionValue builtIn="false" value="BT_USE_NEON"/>
-									<listOptionValue builtIn="false" value="BLACKBERRY_USE_GAMEPAD"/>
 								</option>
 								</option>
 								<option id="com.qnx.qcc.option.compiler.includePath.847642559" name="Include Directories (-I)" superClass="com.qnx.qcc.option.compiler.includePath" valueType="includePath">
 								<option id="com.qnx.qcc.option.compiler.includePath.847642559" name="Include Directories (-I)" superClass="com.qnx.qcc.option.compiler.includePath" valueType="includePath">
 									<listOptionValue builtIn="false" value="&quot;../../external-deps/bullet/include&quot;"/>
 									<listOptionValue builtIn="false" value="&quot;../../external-deps/bullet/include&quot;"/>
@@ -335,11 +330,10 @@
 							<tool id="com.qnx.qcc.tool.compiler.417488704" name="QCC Compiler" superClass="com.qnx.qcc.tool.compiler">
 							<tool id="com.qnx.qcc.tool.compiler.417488704" name="QCC Compiler" superClass="com.qnx.qcc.tool.compiler">
 								<option id="com.qnx.qcc.option.compile.debug.1290366598" name="Debug (-g)" superClass="com.qnx.qcc.option.compile.debug" value="true" valueType="boolean"/>
 								<option id="com.qnx.qcc.option.compile.debug.1290366598" name="Debug (-g)" superClass="com.qnx.qcc.option.compile.debug" value="true" valueType="boolean"/>
 								<option id="com.qnx.qcc.option.compiler.profile2.216911941" name="Build for Profiling (Function Instrumentation) (-finstrument-functions)" superClass="com.qnx.qcc.option.compiler.profile2" value="true" valueType="boolean"/>
 								<option id="com.qnx.qcc.option.compiler.profile2.216911941" name="Build for Profiling (Function Instrumentation) (-finstrument-functions)" superClass="com.qnx.qcc.option.compiler.profile2" value="true" valueType="boolean"/>
-								<option id="com.qnx.qcc.option.compiler.security.1329750381" name="Enhanced Security (-fstack-protector-strong)" superClass="com.qnx.qcc.option.compiler.security" value="true" valueType="boolean"/>
+								<option id="com.qnx.qcc.option.compiler.security.1329750381" name="Enhanced Security (-fstack-protector-strong)" superClass="com.qnx.qcc.option.compiler.security" value="false" valueType="boolean"/>
 								<option id="com.qnx.qcc.option.compiler.defines.1679396285" name="Defines (-D)" superClass="com.qnx.qcc.option.compiler.defines" valueType="definedSymbols">
 								<option id="com.qnx.qcc.option.compiler.defines.1679396285" name="Defines (-D)" superClass="com.qnx.qcc.option.compiler.defines" valueType="definedSymbols">
 									<listOptionValue builtIn="false" value="_FORTIFY_SOURCE=2"/>
 									<listOptionValue builtIn="false" value="_FORTIFY_SOURCE=2"/>
 									<listOptionValue builtIn="false" value="BT_USE_NEON"/>
 									<listOptionValue builtIn="false" value="BT_USE_NEON"/>
-									<listOptionValue builtIn="false" value="BLACKBERRY_USE_GAMEPAD"/>
 								</option>
 								</option>
 								<option id="com.qnx.qcc.option.compiler.includePath.513622172" name="Include Directories (-I)" superClass="com.qnx.qcc.option.compiler.includePath" valueType="includePath">
 								<option id="com.qnx.qcc.option.compiler.includePath.513622172" name="Include Directories (-I)" superClass="com.qnx.qcc.option.compiler.includePath" valueType="includePath">
 									<listOptionValue builtIn="false" value="&quot;../../external-deps/bullet/include&quot;"/>
 									<listOptionValue builtIn="false" value="&quot;../../external-deps/bullet/include&quot;"/>
@@ -397,11 +391,10 @@
 							<tool id="com.qnx.qcc.tool.compiler.563072865" name="QCC Compiler" superClass="com.qnx.qcc.tool.compiler">
 							<tool id="com.qnx.qcc.tool.compiler.563072865" name="QCC Compiler" superClass="com.qnx.qcc.tool.compiler">
 								<option id="com.qnx.qcc.option.compile.debug.1789973550" name="Debug (-g)" superClass="com.qnx.qcc.option.compile.debug" value="true" valueType="boolean"/>
 								<option id="com.qnx.qcc.option.compile.debug.1789973550" name="Debug (-g)" superClass="com.qnx.qcc.option.compile.debug" value="true" valueType="boolean"/>
 								<option id="com.qnx.qcc.option.compiler.coverage.1289221781" name="Build for Code Coverage (-Wc,-ftest-coverage -Wc,-fprofile-arcs)" superClass="com.qnx.qcc.option.compiler.coverage" value="true" valueType="boolean"/>
 								<option id="com.qnx.qcc.option.compiler.coverage.1289221781" name="Build for Code Coverage (-Wc,-ftest-coverage -Wc,-fprofile-arcs)" superClass="com.qnx.qcc.option.compiler.coverage" value="true" valueType="boolean"/>
-								<option id="com.qnx.qcc.option.compiler.security.1296061040" name="Enhanced Security (-fstack-protector-strong)" superClass="com.qnx.qcc.option.compiler.security" value="true" valueType="boolean"/>
+								<option id="com.qnx.qcc.option.compiler.security.1296061040" name="Enhanced Security (-fstack-protector-strong)" superClass="com.qnx.qcc.option.compiler.security" value="false" valueType="boolean"/>
 								<option id="com.qnx.qcc.option.compiler.defines.1925901823" name="Defines (-D)" superClass="com.qnx.qcc.option.compiler.defines" valueType="definedSymbols">
 								<option id="com.qnx.qcc.option.compiler.defines.1925901823" name="Defines (-D)" superClass="com.qnx.qcc.option.compiler.defines" valueType="definedSymbols">
 									<listOptionValue builtIn="false" value="_FORTIFY_SOURCE=2"/>
 									<listOptionValue builtIn="false" value="_FORTIFY_SOURCE=2"/>
 									<listOptionValue builtIn="false" value="BT_USE_NEON"/>
 									<listOptionValue builtIn="false" value="BT_USE_NEON"/>
-									<listOptionValue builtIn="false" value="BLACKBERRY_USE_GAMEPAD"/>
 								</option>
 								</option>
 								<option id="com.qnx.qcc.option.compiler.includePath.1685994750" name="Include Directories (-I)" superClass="com.qnx.qcc.option.compiler.includePath" valueType="includePath">
 								<option id="com.qnx.qcc.option.compiler.includePath.1685994750" name="Include Directories (-I)" superClass="com.qnx.qcc.option.compiler.includePath" valueType="includePath">
 									<listOptionValue builtIn="false" value="&quot;../../external-deps/bullet/include&quot;"/>
 									<listOptionValue builtIn="false" value="&quot;../../external-deps/bullet/include&quot;"/>

+ 1 - 1
gameplay/src/Base.h

@@ -279,7 +279,7 @@ typedef GLuint FrameBufferHandle;
 typedef GLuint RenderBufferHandle;
 typedef GLuint RenderBufferHandle;
 
 
 /** Gamepad handle definitions vary by platform. */
 /** Gamepad handle definitions vary by platform. */
-#ifdef __QNX__
+#if defined(__QNX__) && defined (USE_BLACKBERRY_GAMEPAD)
     typedef screen_device_t GamepadHandle;
     typedef screen_device_t GamepadHandle;
 #elif USE_XINPUT
 #elif USE_XINPUT
     typedef unsigned long GamepadHandle;
     typedef unsigned long GamepadHandle;

+ 2 - 0
gameplay/src/Control.cpp

@@ -43,6 +43,8 @@ void Control::initialize(Theme::Style* style, Properties* properties)
 
 
     _consumeInputEvents = properties->getBool("consumeInputEvents", true);
     _consumeInputEvents = properties->getBool("consumeInputEvents", true);
 
 
+    _visible = properties->getBool("visible", true);
+
     if (properties->exists("zIndex"))
     if (properties->exists("zIndex"))
     {
     {
         _zIndex = properties->getInt("zIndex");
         _zIndex = properties->getInt("zIndex");

+ 17 - 15
gameplay/src/Form.cpp

@@ -233,7 +233,7 @@ void Form::setSize(float width, float height)
         _u2 = width / (float)w;
         _u2 = width / (float)w;
         _v1 = height / (float)h;
         _v1 = height / (float)h;
 
 
-        // Create framebuffer if necessary.
+        // Create framebuffer if necessary. TODO: Use pool to cache.
         if (_frameBuffer)
         if (_frameBuffer)
             SAFE_RELEASE(_frameBuffer)
             SAFE_RELEASE(_frameBuffer)
         
         
@@ -250,16 +250,17 @@ void Form::setSize(float width, float height)
 
 
         // Clear the framebuffer black
         // Clear the framebuffer black
         Game* game = Game::getInstance();
         Game* game = Game::getInstance();
-        _frameBuffer->bind();
-        Rectangle prevViewport = game->getViewport();
+        FrameBuffer* previousFrameBuffer = _frameBuffer->bind();
+        Rectangle previousViewport = game->getViewport();
+
         game->setViewport(Rectangle(0, 0, width, height));
         game->setViewport(Rectangle(0, 0, width, height));
         _theme->setProjectionMatrix(_projectionMatrix);
         _theme->setProjectionMatrix(_projectionMatrix);
         game->clear(Game::CLEAR_COLOR, Vector4::zero(), 1.0, 0);
         game->clear(Game::CLEAR_COLOR, Vector4::zero(), 1.0, 0);
         _theme->setProjectionMatrix(_defaultProjectionMatrix);
         _theme->setProjectionMatrix(_defaultProjectionMatrix);
-        FrameBuffer::bindDefault();
-        game->setViewport(prevViewport);
+
+        previousFrameBuffer->bind();
+        game->setViewport(previousViewport);
     }
     }
-    
     _bounds.width = width;
     _bounds.width = width;
     _bounds.height = height;
     _bounds.height = height;
     _dirty = true;
     _dirty = true;
@@ -481,10 +482,9 @@ void Form::updateBounds()
         }
         }
  
  
         _viewportClipBounds.set(x, y, width, height);
         _viewportClipBounds.set(x, y, width, height);
-
         _absoluteClipBounds.set(x - border.left - padding.left, y - border.top - padding.top,
         _absoluteClipBounds.set(x - border.left - padding.left, y - border.top - padding.top,
-            width + border.left + padding.left + border.right + padding.right,
-            height + border.top + padding.top + border.bottom + padding.bottom);
+                                width + border.left + padding.left + border.right + padding.right,
+                                height + border.top + padding.top + border.bottom + padding.bottom);
         if (_clearBounds.isEmpty())
         if (_clearBounds.isEmpty())
         {
         {
             _clearBounds.set(_absoluteClipBounds);
             _clearBounds.set(_absoluteClipBounds);
@@ -515,9 +515,13 @@ void Form::updateBounds()
 
 
         GP_ASSERT(_layout);
         GP_ASSERT(_layout);
         if (_scroll != SCROLL_NONE)
         if (_scroll != SCROLL_NONE)
+        {
             updateScroll();
             updateScroll();
+        }
         else
         else
+        {
             _layout->update(this, Vector2::zero());
             _layout->update(this, Vector2::zero());
+        }
     }
     }
 }
 }
 
 
@@ -535,7 +539,7 @@ void Form::draw()
     if (isDirty())
     if (isDirty())
     {
     {
         GP_ASSERT(_frameBuffer);
         GP_ASSERT(_frameBuffer);
-        _frameBuffer->bind();
+        FrameBuffer* previousFrameBuffer = _frameBuffer->bind();
 
 
         Game* game = Game::getInstance();
         Game* game = Game::getInstance();
         Rectangle prevViewport = game->getViewport();
         Rectangle prevViewport = game->getViewport();
@@ -543,15 +547,13 @@ void Form::draw()
 
 
         GP_ASSERT(_theme);
         GP_ASSERT(_theme);
         _theme->setProjectionMatrix(_projectionMatrix);
         _theme->setProjectionMatrix(_projectionMatrix);
-        Container::draw(_theme->getSpriteBatch(), Rectangle(0, 0, _bounds.width, _bounds.height),
-                        true/*WAS _skin!=NULL*/, false, _bounds.height);
+        Container::draw(_theme->getSpriteBatch(), Rectangle(0, 0, _bounds.width, _bounds.height),  true/*WAS _skin!=NULL*/, false, _bounds.height);
         _theme->setProjectionMatrix(_defaultProjectionMatrix);
         _theme->setProjectionMatrix(_defaultProjectionMatrix);
 
 
-        // Rebind the default framebuffer and game viewport.
-        FrameBuffer::bindDefault();
-
         // restore the previous game viewport
         // restore the previous game viewport
         game->setViewport(prevViewport);
         game->setViewport(prevViewport);
+        // Rebind the previous framebuffer and game viewport.
+        previousFrameBuffer->bind();
     }
     }
 
 
     // Draw either with a 3D quad or sprite batch
     // Draw either with a 3D quad or sprite batch

+ 22 - 29
gameplay/src/FrameBuffer.cpp

@@ -4,17 +4,19 @@
 
 
 #include "Base.h"
 #include "Base.h"
 #include "FrameBuffer.h"
 #include "FrameBuffer.h"
+#include "Game.h"
+
+#define FRAMEBUFFER_ID_DEFAULT "org.gameplay3d.framebuffer.default"
 
 
 namespace gameplay
 namespace gameplay
 {
 {
-
 static unsigned int __maxRenderTargets = 0;
 static unsigned int __maxRenderTargets = 0;
 static std::vector<FrameBuffer*> __frameBuffers;
 static std::vector<FrameBuffer*> __frameBuffers;
-static FrameBufferHandle __defaultHandle = 0;
-static FrameBufferHandle __currentHandle = 0;
+static FrameBuffer* __defaultFrameBuffer = NULL;
+static FrameBuffer* __currentFrameBuffer = NULL;
 
 
-FrameBuffer::FrameBuffer(const char* id, unsigned int width, unsigned int height) :
-    _id(id ? id : ""), _width(width), _height(height), _handle(0), 
+FrameBuffer::FrameBuffer(const char* id, unsigned int width, unsigned int height, FrameBufferHandle handle) :
+    _id(id ? id : ""), _width(width), _height(height), _handle(handle), 
     _renderTargets(NULL), _depthStencilTarget(NULL)
     _renderTargets(NULL), _depthStencilTarget(NULL)
 {
 {
 }
 }
@@ -57,8 +59,8 @@ void FrameBuffer::initialize()
     // On many platforms this will simply be the zero (0) handle, but this is not always the case.
     // On many platforms this will simply be the zero (0) handle, but this is not always the case.
     GLint fbo;
     GLint fbo;
     glGetIntegerv(GL_FRAMEBUFFER_BINDING, &fbo);
     glGetIntegerv(GL_FRAMEBUFFER_BINDING, &fbo);
-    __defaultHandle = (FrameBufferHandle)fbo;
-    __currentHandle = __defaultHandle;
+    __defaultFrameBuffer = new FrameBuffer(FRAMEBUFFER_ID_DEFAULT, 0, 0, (FrameBufferHandle)fbo);
+    __currentFrameBuffer = __defaultFrameBuffer;
 
 
     // Query the max supported color attachments. This glGet operation is not supported
     // Query the max supported color attachments. This glGet operation is not supported
     // on GL ES 2.x, so if the define does not exist, assume a value of 1.
     // on GL ES 2.x, so if the define does not exist, assume a value of 1.
@@ -78,9 +80,6 @@ FrameBuffer* FrameBuffer::create(const char* id)
 
 
 FrameBuffer* FrameBuffer::create(const char* id, unsigned int width, unsigned int height)
 FrameBuffer* FrameBuffer::create(const char* id, unsigned int width, unsigned int height)
 {
 {
-    // Call getMaxRenderTargets() to force __maxRenderTargets to be set
-    getMaxRenderTargets();
-
     RenderTarget* renderTarget = NULL;
     RenderTarget* renderTarget = NULL;
     if (width > 0 && height > 0)
     if (width > 0 && height > 0)
     {
     {
@@ -96,8 +95,7 @@ FrameBuffer* FrameBuffer::create(const char* id, unsigned int width, unsigned in
     // Create the frame buffer
     // Create the frame buffer
     GLuint handle = 0;
     GLuint handle = 0;
     GL_ASSERT( glGenFramebuffers(1, &handle) );
     GL_ASSERT( glGenFramebuffers(1, &handle) );
-    FrameBuffer* frameBuffer = new FrameBuffer(id, width, height);
-    frameBuffer->_handle = handle;
+    FrameBuffer* frameBuffer = new FrameBuffer(id, width, height, handle);
     
     
     // Create the render target array for the new frame buffer
     // Create the render target array for the new frame buffer
     frameBuffer->_renderTargets = new RenderTarget*[__maxRenderTargets];
     frameBuffer->_renderTargets = new RenderTarget*[__maxRenderTargets];
@@ -157,11 +155,9 @@ void FrameBuffer::setRenderTarget(RenderTarget* target, unsigned int index)
     GP_ASSERT(index < __maxRenderTargets);
     GP_ASSERT(index < __maxRenderTargets);
     GP_ASSERT(_renderTargets);
     GP_ASSERT(_renderTargets);
 
 
+    // No change
     if (_renderTargets[index] == target)
     if (_renderTargets[index] == target)
-    {
-        // No change.
         return;
         return;
-    }
 
 
     // Release our reference to the current RenderTarget at this index.
     // Release our reference to the current RenderTarget at this index.
     SAFE_RELEASE(_renderTargets[index]);
     SAFE_RELEASE(_renderTargets[index]);
@@ -186,8 +182,9 @@ void FrameBuffer::setRenderTarget(RenderTarget* target, unsigned int index)
         }
         }
 
 
         // Restore the FBO binding
         // Restore the FBO binding
-        GL_ASSERT( glBindFramebuffer(GL_FRAMEBUFFER, __currentHandle) );
+        GL_ASSERT( glBindFramebuffer(GL_FRAMEBUFFER, __currentFrameBuffer->_handle) );
     }
     }
+
 }
 }
 
 
 RenderTarget* FrameBuffer::getRenderTarget(unsigned int index) const
 RenderTarget* FrameBuffer::getRenderTarget(unsigned int index) const
@@ -197,7 +194,6 @@ RenderTarget* FrameBuffer::getRenderTarget(unsigned int index) const
     {
     {
         return _renderTargets[index];
         return _renderTargets[index];
     }
     }
-
     return NULL;
     return NULL;
 }
 }
 
 
@@ -234,7 +230,7 @@ void FrameBuffer::setDepthStencilTarget(DepthStencilTarget* target)
         }
         }
 
 
         // Restore the FBO binding
         // Restore the FBO binding
-        GL_ASSERT( glBindFramebuffer(GL_FRAMEBUFFER, __currentHandle) );
+        GL_ASSERT( glBindFramebuffer(GL_FRAMEBUFFER, __currentFrameBuffer->_handle) );
     }
     }
 }
 }
 
 
@@ -243,22 +239,19 @@ DepthStencilTarget* FrameBuffer::getDepthStencilTarget() const
     return _depthStencilTarget;
     return _depthStencilTarget;
 }
 }
 
 
-void FrameBuffer::bind()
+FrameBuffer* FrameBuffer::bind()
 {
 {
-    // Bind this FrameBuffer for rendering.
     GL_ASSERT( glBindFramebuffer(GL_FRAMEBUFFER, _handle) );
     GL_ASSERT( glBindFramebuffer(GL_FRAMEBUFFER, _handle) );
-
-    // Update the current FBO handle
-    __currentHandle = _handle;
+    FrameBuffer* previousFrameBuffer = __currentFrameBuffer;
+    __currentFrameBuffer = this;
+    return previousFrameBuffer;
 }
 }
 
 
-void FrameBuffer::bindDefault()
+FrameBuffer* FrameBuffer::bindDefault()
 {
 {
-    GL_ASSERT( glBindFramebuffer(GL_FRAMEBUFFER, __defaultHandle) );
-
-    // Update the current FBO handle
-    __currentHandle = __defaultHandle;
+    GL_ASSERT( glBindFramebuffer(GL_FRAMEBUFFER, __defaultFrameBuffer->_handle) );
+    __currentFrameBuffer = __defaultFrameBuffer;
+    return __defaultFrameBuffer;
 }
 }
 
 
-
 }
 }

+ 21 - 12
gameplay/src/FrameBuffer.h

@@ -9,13 +9,17 @@ namespace gameplay
 {
 {
 
 
 /**
 /**
- * Defines a video output off all graphics buffer containing a complete frame of data.
- * This consists of a RenderTarget and DepthStencilTarget holding the color, depth and
- * stencil data in the rendering frame. 
- * 
- * to change the default Game framebuffer call Game::setFrameBuffer(myFrameBuffer);
- * To restore back to the default call Game::setFrameBuffer(NULL).
- * This is useful for rendering shadows and other post-processing effects.
+ * Defines a frame buffer object that may contain one or more render targets and optionally
+ * a depth-stencil target.
+ *
+ * Frame buffers can be created and used for off-screen rendering, which is useful for 
+ * techniques such as shadow mapping and post-processing. Render targets within a frame
+ * buffer can be both written to and read (by calling RenderTarget::getTexture).
+ *
+ * When binding a custom frame buffer, you should always store the return value of 
+ * FrameBuffer::bind and restore it when you are finished drawing to your frame buffer.
+ *
+ * To bind the default frame buffer, call FrameBuffer::bindDefault.
  */
  */
 class FrameBuffer : public Ref
 class FrameBuffer : public Ref
 {
 {
@@ -125,22 +129,27 @@ public:
     DepthStencilTarget* getDepthStencilTarget() const;
     DepthStencilTarget* getDepthStencilTarget() const;
  
  
     /**
     /**
-     * Binds this FrameBuffer for off-screen rendering.
+     * Binds this FrameBuffer for off-screen rendering and return you the curently bound one.
+     *
+     * You should keep the return FrameBuffer and store it and call bind() when you rendering is complete.
+     *
+     * @ return The currently bound framebuffer.
      */
      */
-    void bind();
+    FrameBuffer* bind();
 
 
     /**
     /**
      * Binds the default FrameBuffer for rendering to the display.
      * Binds the default FrameBuffer for rendering to the display.
+     *
+     * @ return The default framebuffer.
      */
      */
-    static void bindDefault(); 
+    static FrameBuffer* bindDefault(); 
      
      
 private:
 private:
 
 
-
     /**
     /**
      * Constructor.
      * Constructor.
      */
      */
-    FrameBuffer(const char* id, unsigned int width, unsigned int height);
+    FrameBuffer(const char* id, unsigned int width, unsigned int height, FrameBufferHandle handle);
 
 
     /**
     /**
      * Destructor.
      * Destructor.

+ 6 - 3
gameplay/src/Gamepad.cpp

@@ -2,6 +2,7 @@
 #include "Gamepad.h"
 #include "Gamepad.h"
 #include "Game.h"
 #include "Game.h"
 #include "Button.h"
 #include "Button.h"
+#include "Platform.h"
 
 
 namespace gameplay
 namespace gameplay
 {
 {
@@ -9,7 +10,8 @@ namespace gameplay
 static std::vector<Gamepad*> __gamepads;
 static std::vector<Gamepad*> __gamepads;
 
 
 Gamepad::Gamepad(const char* formPath)
 Gamepad::Gamepad(const char* formPath)
-    : _handle(INT_MAX), _vendorId(0), _productId(0), _buttonCount(0), _joystickCount(0), _triggerCount(0), _form(NULL), _buttons(0)
+    : _handle((GamepadHandle)INT_MAX), _buttonCount(0), _joystickCount(0), _triggerCount(0), _vendorId(0), _productId(0),
+      _form(NULL), _buttons(0)
 {
 {
     GP_ASSERT(formPath);
     GP_ASSERT(formPath);
     _form = Form::create(formPath);
     _form = Form::create(formPath);
@@ -33,8 +35,9 @@ Gamepad::Gamepad(const char* formPath)
 
 
 Gamepad::Gamepad(GamepadHandle handle, unsigned int buttonCount, unsigned int joystickCount, unsigned int triggerCount,
 Gamepad::Gamepad(GamepadHandle handle, unsigned int buttonCount, unsigned int joystickCount, unsigned int triggerCount,
                  unsigned int vendorId, unsigned int productId, const char* vendorString, const char* productString)
                  unsigned int vendorId, unsigned int productId, const char* vendorString, const char* productString)
-    : _handle(handle), _vendorId(vendorId), _productId(productId), _vendorString(vendorString), _productString(productString),
-      _buttonCount(buttonCount), _joystickCount(joystickCount), _triggerCount(triggerCount), _form(NULL), _buttons(0)
+    : _handle(handle), _buttonCount(buttonCount), _joystickCount(joystickCount), _triggerCount(triggerCount),
+      _vendorId(vendorId), _productId(productId), _vendorString(vendorString), _productString(productString),
+      _form(NULL), _buttons(0)
 {
 {
 }
 }
 
 

+ 1 - 1
gameplay/src/PhysicsCollisionObject.cpp

@@ -35,7 +35,7 @@ struct CollidesWithCallback : public btCollisionWorld::ContactResultCallback
 };
 };
 
 
 PhysicsCollisionObject::PhysicsCollisionObject(Node* node)
 PhysicsCollisionObject::PhysicsCollisionObject(Node* node)
-    : _node(node), _motionState(NULL), _collisionShape(NULL), _enabled(true), _scriptListeners(NULL)
+    : _node(node), _collisionShape(NULL), _enabled(true), _scriptListeners(NULL), _motionState(NULL)
 {
 {
 }
 }
 
 

+ 45 - 40
gameplay/src/PhysicsCollisionObject.h

@@ -21,6 +21,8 @@ class PhysicsCollisionObject
 {
 {
     friend class PhysicsController;
     friend class PhysicsController;
     friend class PhysicsConstraint;
     friend class PhysicsConstraint;
+    friend class PhysicsRigidBody;
+    friend class PhysicsGhostObject;
 
 
 public:
 public:
 
 
@@ -289,6 +291,7 @@ public:
     PhysicsVehicleWheel* asVehicleWheel();
     PhysicsVehicleWheel* asVehicleWheel();
 
 
 protected:
 protected:
+
     /**
     /**
      * Handles collision event callbacks to Lua script functions.
      * Handles collision event callbacks to Lua script functions.
      */
      */
@@ -311,6 +314,40 @@ protected:
         std::string function;
         std::string function;
     };
     };
 
 
+    /**
+     * Constructor.
+     */
+    PhysicsCollisionObject(Node* node);
+
+    /**
+     * Returns the Bullet Physics collision object.
+     *
+     * @return The Bullet collision object.
+     */
+    virtual btCollisionObject* getCollisionObject() const = 0;
+
+    /**
+     * Pointer to Node contained by this collision object.
+     */ 
+    Node* _node;
+    
+    /**
+     * The PhysicsCollisionObject's collision shape.
+     */
+    PhysicsCollisionShape* _collisionShape;
+
+    /**
+     * If the collision object is enabled or not.
+     */
+    bool _enabled;
+
+    /**
+     * The list of script listeners.
+     */
+    std::vector<ScriptListener*>* _scriptListeners;
+
+private:
+
     /**
     /**
      * Interface between GamePlay and Bullet to keep object transforms synchronized properly.
      * Interface between GamePlay and Bullet to keep object transforms synchronized properly.
      * 
      * 
@@ -321,7 +358,7 @@ protected:
         friend class PhysicsConstraint;
         friend class PhysicsConstraint;
         
         
     public:
     public:
-
+        
         /**
         /**
          * Creates a physics motion state for a rigid body.
          * Creates a physics motion state for a rigid body.
          * 
          * 
@@ -330,76 +367,44 @@ protected:
          * @param centerOfMassOffset The translation offset to the center of mass of the rigid body.
          * @param centerOfMassOffset The translation offset to the center of mass of the rigid body.
          */
          */
         PhysicsMotionState(Node* node, PhysicsCollisionObject* collisionObject, const Vector3* centerOfMassOffset = NULL);
         PhysicsMotionState(Node* node, PhysicsCollisionObject* collisionObject, const Vector3* centerOfMassOffset = NULL);
-
+        
         /**
         /**
          * Destructor.
          * Destructor.
          */
          */
         virtual ~PhysicsMotionState();
         virtual ~PhysicsMotionState();
-
+        
         /**
         /**
          * @see btMotionState::getWorldTransform
          * @see btMotionState::getWorldTransform
          */
          */
         virtual void getWorldTransform(btTransform &transform) const;
         virtual void getWorldTransform(btTransform &transform) const;
-
+        
         /**
         /**
          * @see btMotionState::setWorldTransform
          * @see btMotionState::setWorldTransform
          */
          */
         virtual void setWorldTransform(const btTransform &transform);
         virtual void setWorldTransform(const btTransform &transform);
-
+        
         /**
         /**
          * Updates the motion state's world transform from the GamePlay Node object's world transform.
          * Updates the motion state's world transform from the GamePlay Node object's world transform.
          */
          */
         void updateTransformFromNode() const;
         void updateTransformFromNode() const;
-
+        
         /**
         /**
          * Sets the center of mass offset for the associated collision shape.
          * Sets the center of mass offset for the associated collision shape.
          */
          */
         void setCenterOfMassOffset(const Vector3& centerOfMassOffset);
         void setCenterOfMassOffset(const Vector3& centerOfMassOffset);
-
+        
     private:
     private:
-
+        
         Node* _node;
         Node* _node;
         PhysicsCollisionObject* _collisionObject;
         PhysicsCollisionObject* _collisionObject;
         btTransform _centerOfMassOffset;
         btTransform _centerOfMassOffset;
         mutable btTransform _worldTransform;
         mutable btTransform _worldTransform;
     };
     };
 
 
-    /**
-     * Constructor.
-     */
-    PhysicsCollisionObject(Node* node);
-
-    /**
-     * Returns the Bullet Physics collision object.
-     *
-     * @return The Bullet collision object.
-     */
-    virtual btCollisionObject* getCollisionObject() const = 0;
-
-    /**
-     * Pointer to Node contained by this collision object.
-     */ 
-    Node* _node;
-
     /** 
     /** 
      * The PhysicsCollisionObject's motion state.
      * The PhysicsCollisionObject's motion state.
      */
      */
     PhysicsMotionState* _motionState;
     PhysicsMotionState* _motionState;
-    
-    /**
-     * The PhysicsCollisionObject's collision shape.
-     */
-    PhysicsCollisionShape* _collisionShape;
-
-    /**
-     * If the collision object is enabled or not.
-     */
-    bool _enabled;
-
-    /**
-     * The list of script listeners.
-     */
-    std::vector<ScriptListener*>* _scriptListeners;
 };
 };
 
 
 }
 }

+ 0 - 2
gameplay/src/PhysicsGhostObject.h

@@ -8,8 +8,6 @@
 namespace gameplay
 namespace gameplay
 {
 {
 
 
-class PhysicsMotionState;
-
 /**
 /**
  * Defines a class for physics ghost objects.
  * Defines a class for physics ghost objects.
  */
  */

+ 9 - 7
gameplay/src/Platform.h

@@ -231,13 +231,6 @@ private:
      */
      */
     static bool isGestureRegistered(Gesture::GestureEvent evt);
     static bool isGestureRegistered(Gesture::GestureEvent evt);
 
 
-    /**
-     * Polls the platform for the updated Gamepad states such as joysticks, buttons and trigger values.
-     *
-     * @param gamepad The gamepad to be returned with the latest polled values populated.
-     */
-    static void pollGamepadState(Gamepad* gamepad);
-
     /**
     /**
      * Opens an URL in an external browser, if available.
      * Opens an URL in an external browser, if available.
      *
      *
@@ -295,6 +288,15 @@ public:
      */
      */
     static void gamepadEventDisconnectedInternal(GamepadHandle handle);
     static void gamepadEventDisconnectedInternal(GamepadHandle handle);
 
 
+    /**
+     * Internal metehod used by Gamepad that polls the platform for the updated Gamepad
+     * states such as joysticks, buttons and trigger values.
+     *
+     * @param gamepad The gamepad to be returned with the latest polled values populated.
+     * @script{ignore}
+     */
+    static void pollGamepadState(Gamepad* gamepad);
+
 private:
 private:
 
 
     Game* _game;                // The game this platform is interfacing with.
     Game* _game;                // The game this platform is interfacing with.

+ 11 - 10
gameplay/src/PlatformBlackBerry.cpp

@@ -491,35 +491,31 @@ void gesture_callback(gesture_base_t* gesture, mtouch_event_t* event, void* para
     }
     }
 }
 }
 
 
-#ifdef BLACKBERRY_USE_GAMEPAD
+#ifdef USE_BLACKBERRY_GAMEPAD
 
 
 static const char* __vendorStrings[] =
 static const char* __vendorStrings[] =
 {
 {
     "SteelSeries",
     "SteelSeries",
     "Nintendo",
     "Nintendo",
-    "Fructel"
 };
 };
 
 
 static const char* __productStrings[] =
 static const char* __productStrings[] =
 {
 {
     "FREE",
     "FREE",
     "Wii Remote",
     "Wii Remote",
-    "Gametel"
 };
 };
 
 
 static const int __VIDs[] = {
 static const int __VIDs[] = {
     0x1038,
     0x1038,
     0x057e,
     0x057e,
-    0x25b6
 };
 };
 
 
 static const int __PIDs[] = {
 static const int __PIDs[] = {
     0x1412,
     0x1412,
     0x0306,
     0x0306,
-    0x0001
 };
 };
 
 
-static const unsigned int __knownGamepads = 3;
+static const unsigned int __knownGamepads = 2;
 
 
 void queryGamepad(GamepadHandle handle, int* buttonCount, int* joystickCount, int* productId, int* vendorId, char* productString, char* vendorString)
 void queryGamepad(GamepadHandle handle, int* buttonCount, int* joystickCount, int* productId, int* vendorId, char* productString, char* vendorString)
 {
 {
@@ -627,6 +623,10 @@ void Platform::pollGamepadState(Gamepad* gamepad)
         gamepad->_triggers[i] = value;
         gamepad->_triggers[i] = value;
     }
     }
 }
 }
+#else
+void Platform::pollGamepadState(Gamepad* gamepad)
+{
+}
 #endif
 #endif
 
 
 Platform::Platform(Game* game)
 Platform::Platform(Game* game)
@@ -683,8 +683,6 @@ Platform* Platform::create(Game* game, void* attachToWindow)
     FileSystem::setResourcePath("./app/native/");
     FileSystem::setResourcePath("./app/native/");
     Platform* platform = new Platform(game);
     Platform* platform = new Platform(game);
 
 
-    screen_device_t* screenDevs;
-
     // Query game config
     // Query game config
     int samples = 0;
     int samples = 0;
     Properties* config = Game::getInstance()->getConfig()->getNamespace("window", true);
     Properties* config = Game::getInstance()->getConfig()->getNamespace("window", true);
@@ -972,7 +970,10 @@ Platform* Platform::create(Game* game, void* attachToWindow)
         glIsVertexArray = (PFNGLISVERTEXARRAYOESPROC)eglGetProcAddress("glIsVertexArrayOES");
         glIsVertexArray = (PFNGLISVERTEXARRAYOESPROC)eglGetProcAddress("glIsVertexArrayOES");
     }
     }
 
 
- #ifdef BLACKBERRY_USE_GAMEPAD
+ #ifdef USE_BLACKBERRY_GAMEPAD
+
+    screen_device_t* screenDevs;
+
     // Discover initial gamepad devices.
     // Discover initial gamepad devices.
     int count;
     int count;
     screen_get_context_property_iv(__screenContext, SCREEN_PROPERTY_DEVICE_COUNT, &count);
     screen_get_context_property_iv(__screenContext, SCREEN_PROPERTY_DEVICE_COUNT, &count);
@@ -1220,7 +1221,7 @@ int Platform::enterMessagePump()
                         }
                         }
                         break;
                         break;
                     }
                     }
-#ifdef BLACKBERRY_USE_GAMEPAD
+#ifdef USE_BLACKBERRY_GAMEPAD
                     case SCREEN_EVENT_DEVICE:
                     case SCREEN_EVENT_DEVICE:
                     {
                     {
                         // A device was attached or removed.
                         // A device was attached or removed.

+ 80 - 60
gameplay/src/PlatformMacOSX.mm

@@ -23,7 +23,7 @@ using namespace std;
 using namespace gameplay;
 using namespace gameplay;
 
 
 @class View;
 @class View;
-@class OSXGamepad;
+@class HIDGamepad;
 
 
 // Default to 720p
 // Default to 720p
 static int __width = 1280;
 static int __width = 1280;
@@ -58,9 +58,9 @@ static NSMutableArray *__gamepads = NULL;
 static IOHIDManagerRef __hidManagerRef = NULL;
 static IOHIDManagerRef __hidManagerRef = NULL;
 
 
 // Gamepad Helper Function
 // Gamepad Helper Function
-OSXGamepad *gamepadForLocationID(NSNumber *locationID);
-OSXGamepad *gamepadForLocationIDValue(unsigned int locationIDValue);
-OSXGamepad *gamepadForGameHandle(int gameHandle);
+HIDGamepad *gamepadForLocationID(NSNumber *locationID);
+HIDGamepad *gamepadForLocationIDValue(unsigned int locationIDValue);
+HIDGamepad *gamepadForGameHandle(int gameHandle);
 
 
 
 
 // IOHid Helper Functions
 // IOHid Helper Functions
@@ -89,7 +89,7 @@ double getMachTimeInMilliseconds()
 }
 }
 
 
 
 
-@interface OSXGamepadAxis : NSObject
+@interface HIDGamepadAxis : NSObject
 {
 {
     IOHIDElementRef e;
     IOHIDElementRef e;
     CFIndex v;
     CFIndex v;
@@ -109,7 +109,7 @@ double getMachTimeInMilliseconds()
 - (CFIndex)value;
 - (CFIndex)value;
 - (void)setValue:(CFIndex)value;
 - (void)setValue:(CFIndex)value;
 @end
 @end
-@implementation OSXGamepadAxis
+@implementation HIDGamepadAxis
 + gamepadAxisWithAxisElement:(IOHIDElementRef)element
 + gamepadAxisWithAxisElement:(IOHIDElementRef)element
 {
 {
     return [[[[self class] alloc] initWithAxisElement:element] autorelease];
     return [[[[self class] alloc] initWithAxisElement:element] autorelease];
@@ -170,7 +170,7 @@ double getMachTimeInMilliseconds()
 }
 }
 @end
 @end
 
 
-@interface OSXGamepadButton : NSObject
+@interface HIDGamepadButton : NSObject
 {
 {
     IOHIDElementRef e;
     IOHIDElementRef e;
     IOHIDElementRef te;
     IOHIDElementRef te;
@@ -194,7 +194,7 @@ double getMachTimeInMilliseconds()
 - (bool)state;
 - (bool)state;
 - (void)setState:(bool)state;
 - (void)setState:(bool)state;
 @end
 @end
-@implementation OSXGamepadButton
+@implementation HIDGamepadButton
 + gamepadButtonWithButtonElement:(IOHIDElementRef)element
 + gamepadButtonWithButtonElement:(IOHIDElementRef)element
 {
 {
     return [[[[self class] alloc] initWithButtonElement:element] autorelease];
     return [[[[self class] alloc] initWithButtonElement:element] autorelease];
@@ -263,7 +263,7 @@ double getMachTimeInMilliseconds()
 }
 }
 - (float)calibratedStateValue
 - (float)calibratedStateValue
 {
 {
-    return (float)triggerValue; // TODO: Need to figure out expected range
+    return (float)triggerValue / 255.0f;
 }
 }
 - (bool)state
 - (bool)state
 {
 {
@@ -275,7 +275,7 @@ double getMachTimeInMilliseconds()
 }
 }
 @end
 @end
 
 
-@interface OSXGamepad : NSObject
+@interface HIDGamepad : NSObject
 {
 {
     IOHIDDeviceRef hidDeviceRef;
     IOHIDDeviceRef hidDeviceRef;
     IOHIDQueueRef queueRef;
     IOHIDQueueRef queueRef;
@@ -294,7 +294,7 @@ double getMachTimeInMilliseconds()
 - (NSNumber*)locationID;
 - (NSNumber*)locationID;
 
 
 - (void)initializeGamepadElements;
 - (void)initializeGamepadElements;
-- (OSXGamepadButton*)buttonWithCookie:(IOHIDElementCookie)cookie;
+- (HIDGamepadButton*)buttonWithCookie:(IOHIDElementCookie)cookie;
 
 
 - (bool)startListening;
 - (bool)startListening;
 - (void)stopListening;
 - (void)stopListening;
@@ -310,12 +310,12 @@ double getMachTimeInMilliseconds()
 - (NSUInteger)numberOfSticks;
 - (NSUInteger)numberOfSticks;
 - (NSUInteger)numberOfButtons;
 - (NSUInteger)numberOfButtons;
 - (NSUInteger)numberOfTriggerButtons;
 - (NSUInteger)numberOfTriggerButtons;
-- (OSXGamepadAxis*)axisAtIndex:(NSUInteger)index;
-- (OSXGamepadButton*)buttonAtIndex:(NSUInteger)index;
-- (OSXGamepadButton*)triggerButtonAtIndex:(NSUInteger)index;
+- (HIDGamepadAxis*)axisAtIndex:(NSUInteger)index;
+- (HIDGamepadButton*)buttonAtIndex:(NSUInteger)index;
+- (HIDGamepadButton*)triggerButtonAtIndex:(NSUInteger)index;
 @end
 @end
 
 
-@implementation OSXGamepad
+@implementation HIDGamepad
 
 
 @synthesize hidDeviceRef;
 @synthesize hidDeviceRef;
 @synthesize queueRef;
 @synthesize queueRef;
@@ -386,7 +386,7 @@ double getMachTimeInMilliseconds()
                 case kHIDUsage_GD_Ry:
                 case kHIDUsage_GD_Ry:
                 case kHIDUsage_GD_Rz:
                 case kHIDUsage_GD_Rz:
                 {
                 {
-                    OSXGamepadAxis *axis = [OSXGamepadAxis gamepadAxisWithAxisElement:hidElement];
+                    HIDGamepadAxis *axis = [HIDGamepadAxis gamepadAxisWithAxisElement:hidElement];
                     [[self axes] addObject:axis];
                     [[self axes] addObject:axis];
                 }
                 }
                     break;
                     break;
@@ -400,7 +400,7 @@ double getMachTimeInMilliseconds()
         }
         }
         if(type == kIOHIDElementTypeInput_Button)
         if(type == kIOHIDElementTypeInput_Button)
         {
         {
-            OSXGamepadButton *button = [OSXGamepadButton gamepadButtonWithButtonElement:hidElement];
+            HIDGamepadButton *button = [HIDGamepadButton gamepadButtonWithButtonElement:hidElement];
             [[self buttons] addObject:button];
             [[self buttons] addObject:button];
         }
         }
     }
     }
@@ -420,32 +420,35 @@ double getMachTimeInMilliseconds()
         {
         {
             if((unsigned long)cookie == 39)
             if((unsigned long)cookie == 39)
             {
             {
-                OSXGamepadButton *leftTriggerButton = [self buttonWithCookie:(IOHIDElementCookie)9];
+                //[self buttonAtIndex:8]; 
+                HIDGamepadButton *leftTriggerButton = [self buttonWithCookie:(IOHIDElementCookie)9];
                 if(leftTriggerButton)
                 if(leftTriggerButton)
                 {
                 {
                     [leftTriggerButton setTriggerElement:hidElement];
                     [leftTriggerButton setTriggerElement:hidElement];
                     [[self triggerButtons] addObject:leftTriggerButton];
                     [[self triggerButtons] addObject:leftTriggerButton];
-                    [[self buttons] removeObject:leftTriggerButton]; // Defer to gamepad team on this line..  not sure how they intend to tackle
+                    // I would have thought this would work but it seems to mess things up, even after re-mapping the buttons.
+                    //[[self buttons] removeObject:leftTriggerButton];
                 }
                 }
             }
             }
             if((unsigned long)cookie == 40)
             if((unsigned long)cookie == 40)
             {
             {
-                OSXGamepadButton *rightTriggerButton = [self buttonWithCookie:(IOHIDElementCookie)10];
+                //[self buttonAtIndex:9];
+                HIDGamepadButton *rightTriggerButton = [self buttonWithCookie:(IOHIDElementCookie)10];
                 if(rightTriggerButton)
                 if(rightTriggerButton)
                 {
                 {
                     [rightTriggerButton setTriggerElement:hidElement];
                     [rightTriggerButton setTriggerElement:hidElement];
                     [[self triggerButtons] addObject:rightTriggerButton];
                     [[self triggerButtons] addObject:rightTriggerButton];
-                    [[self buttons] removeObject:rightTriggerButton];
+                    //[[self buttons] removeObject:rightTriggerButton];
                 }
                 }
             }
             }
         }
         }
     }
     }
-    
 }
 }
 
 
-- (OSXGamepadButton*)buttonWithCookie:(IOHIDElementCookie)cookie {
-    for(OSXGamepadButton *b in [self buttons]) {
-        if([b cookie] == cookie) return b;
+- (HIDGamepadButton*)buttonWithCookie:(IOHIDElementCookie)cookie {
+    for(HIDGamepadButton *b in [self buttons]) {
+        if([b cookie] == cookie)
+            return b;
     }
     }
     return NULL;
     return NULL;
 }
 }
@@ -541,9 +544,9 @@ double getMachTimeInMilliseconds()
     return [[self triggerButtons] count];
     return [[self triggerButtons] count];
 }
 }
 
 
-- (OSXGamepadButton*)triggerButtonAtIndex:(NSUInteger)index
+- (HIDGamepadButton*)triggerButtonAtIndex:(NSUInteger)index
 {
 {
-    OSXGamepadButton *b = NULL;
+    HIDGamepadButton *b = NULL;
     if(index < [[self triggerButtons] count])
     if(index < [[self triggerButtons] count])
     {
     {
         b = [[self triggerButtons] objectAtIndex:index];
         b = [[self triggerButtons] objectAtIndex:index];
@@ -551,18 +554,18 @@ double getMachTimeInMilliseconds()
     return b;
     return b;
 }
 }
 
 
-- (OSXGamepadAxis*)axisAtIndex:(NSUInteger)index
+- (HIDGamepadAxis*)axisAtIndex:(NSUInteger)index
 {
 {
-    OSXGamepadAxis *a = NULL;
+    HIDGamepadAxis *a = NULL;
     if(index < [[self axes] count])
     if(index < [[self axes] count])
     {
     {
         a = [[self axes] objectAtIndex:index];
         a = [[self axes] objectAtIndex:index];
     }
     }
     return a;
     return a;
 }
 }
-- (OSXGamepadButton*)buttonAtIndex:(NSUInteger)index
+- (HIDGamepadButton*)buttonAtIndex:(NSUInteger)index
 {
 {
-    OSXGamepadButton *b = NULL;
+    HIDGamepadButton *b = NULL;
     if(index < [[self buttons] count])
     if(index < [[self buttons] count])
     {
     {
         b = [[self buttons] objectAtIndex:index];
         b = [[self buttons] objectAtIndex:index];
@@ -572,20 +575,21 @@ double getMachTimeInMilliseconds()
 - (NSArray*)watchedElements
 - (NSArray*)watchedElements
 {
 {
     NSMutableArray *r = [NSMutableArray array];
     NSMutableArray *r = [NSMutableArray array];
-    for(OSXGamepadButton *b in [self buttons])
+    for(HIDGamepadButton *b in [self buttons])
     {
     {
         [r addObject:(id)[b element]];
         [r addObject:(id)[b element]];
     }
     }
-    for(OSXGamepadAxis *a in [self axes])
+    for(HIDGamepadAxis *a in [self axes])
     {
     {
         [r addObject:(id)[a element]];
         [r addObject:(id)[a element]];
     }
     }
-    for(OSXGamepadButton* t in [self triggerButtons])
+    for(HIDGamepadButton* t in [self triggerButtons])
     {
     {
-        [r addObject:(id)[t element]];
+        [r addObject:(id)[t triggerElement]];
     }
     }
     return [NSArray arrayWithArray:r];
     return [NSArray arrayWithArray:r];
 }
 }
+
 - (void)hidValueAvailable:(IOHIDValueRef)value
 - (void)hidValueAvailable:(IOHIDValueRef)value
 {
 {
     IOHIDElementRef element = IOHIDValueGetElement(value);
     IOHIDElementRef element = IOHIDValueGetElement(value);
@@ -594,7 +598,7 @@ double getMachTimeInMilliseconds()
     if(IOHIDValueGetLength(value) > 4) return; // saftey precaution for PS3 cotroller
     if(IOHIDValueGetLength(value) > 4) return; // saftey precaution for PS3 cotroller
     CFIndex integerValue = IOHIDValueGetIntegerValue(value);
     CFIndex integerValue = IOHIDValueGetIntegerValue(value);
     
     
-    for(OSXGamepadAxis *a in [self axes])
+    for(HIDGamepadAxis *a in [self axes])
     {
     {
         if([a cookie] == cookie)
         if([a cookie] == cookie)
         {
         {
@@ -602,7 +606,7 @@ double getMachTimeInMilliseconds()
         }
         }
     }
     }
     
     
-    for(OSXGamepadButton *b in [self buttons])
+    for(HIDGamepadButton *b in [self buttons])
     {
     {
         if([b cookie] == cookie)
         if([b cookie] == cookie)
         {
         {
@@ -611,7 +615,7 @@ double getMachTimeInMilliseconds()
         }
         }
     }
     }
     
     
-    for(OSXGamepadButton *b in [self triggerButtons])
+    for(HIDGamepadButton *b in [self triggerButtons])
     {
     {
         if([b triggerCookie] == cookie)
         if([b triggerCookie] == cookie)
         {
         {
@@ -667,7 +671,7 @@ double getMachTimeInMilliseconds()
 - (void) detectGamepads: (Game*) game
 - (void) detectGamepads: (Game*) game
 {
 {
     // Locate any newly connected devices
     // Locate any newly connected devices
-    for(OSXGamepad* gamepad in __gamepads)
+    for(HIDGamepad* gamepad in __gamepads)
     {
     {
         NSNumber* locationID = [gamepad locationID];
         NSNumber* locationID = [gamepad locationID];
         if([__activeGamepads objectForKey:locationID] == NULL)
         if([__activeGamepads objectForKey:locationID] == NULL)
@@ -676,7 +680,7 @@ double getMachTimeInMilliseconds()
             Platform::gamepadEventConnectedInternal((unsigned int)[locationID intValue],
             Platform::gamepadEventConnectedInternal((unsigned int)[locationID intValue],
                                                     [gamepad numberOfButtons],
                                                     [gamepad numberOfButtons],
                                                     [gamepad numberOfSticks],
                                                     [gamepad numberOfSticks],
-                                                    0, //[gamepad numberOfTriggerButtons], PS3 triggers are not working yet
+                                                    [gamepad numberOfTriggerButtons],
                                                     [gamepad vendorID],
                                                     [gamepad vendorID],
                                                     [gamepad productID],
                                                     [gamepad productID],
                                                     [[gamepad manufacturerName] cStringUsingEncoding:NSASCIIStringEncoding],
                                                     [[gamepad manufacturerName] cStringUsingEncoding:NSASCIIStringEncoding],
@@ -690,7 +694,7 @@ double getMachTimeInMilliseconds()
     NSMutableArray* deadGamepads = [NSMutableArray array];
     NSMutableArray* deadGamepads = [NSMutableArray array];
     for(NSNumber* locationID in __activeGamepads)
     for(NSNumber* locationID in __activeGamepads)
     {
     {
-        OSXGamepad* gamepad = gamepadForLocationID(locationID);
+        HIDGamepad* gamepad = gamepadForLocationID(locationID);
         if(gamepad == NULL)
         if(gamepad == NULL)
         {
         {
             NSNumber* gameHandle = [__activeGamepads objectForKey:locationID];
             NSNumber* gameHandle = [__activeGamepads objectForKey:locationID];
@@ -1810,11 +1814,13 @@ bool Platform::isGestureRegistered(Gesture::GestureEvent evt)
 
 
 void Platform::pollGamepadState(Gamepad* gamepad)
 void Platform::pollGamepadState(Gamepad* gamepad)
 {
 {
-    OSXGamepad* gp = gamepadForGameHandle(gamepad->_handle);
+    HIDGamepad* gp = gamepadForGameHandle(gamepad->_handle);
     
     
     if (gp)
     if (gp)
     {
     {
-        static const unsigned int PS3Mapping[17] = {
+        // Haven't figured out how to have the triggers not also show up in the buttons array.
+        // So for now a value of -1 means "Don't map this button."
+        static const int PS3Mapping[17] = {
             Gamepad::BUTTON_MENU1,  // 0x0001
             Gamepad::BUTTON_MENU1,  // 0x0001
             Gamepad::BUTTON_L3,     // 0x0002
             Gamepad::BUTTON_L3,     // 0x0002
             Gamepad::BUTTON_R3,     // 0x0004
             Gamepad::BUTTON_R3,     // 0x0004
@@ -1823,8 +1829,8 @@ void Platform::pollGamepadState(Gamepad* gamepad)
             Gamepad::BUTTON_RIGHT,  // 0x0020
             Gamepad::BUTTON_RIGHT,  // 0x0020
             Gamepad::BUTTON_DOWN,   // 0x0040
             Gamepad::BUTTON_DOWN,   // 0x0040
             Gamepad::BUTTON_LEFT,   // 0x0080
             Gamepad::BUTTON_LEFT,   // 0x0080
-            Gamepad::BUTTON_L2,     // 0x0100
-            Gamepad::BUTTON_R2,     // 0x0200
+            -1,                     // Gamepad::BUTTON_L2,     // 0x0100
+            -1,                     // Gamepad::BUTTON_R2,     // 0x0200
             Gamepad::BUTTON_L1,     // 0x0400
             Gamepad::BUTTON_L1,     // 0x0400
             Gamepad::BUTTON_R1,     // 0x0800
             Gamepad::BUTTON_R1,     // 0x0800
             Gamepad::BUTTON_Y,      // 0x1000
             Gamepad::BUTTON_Y,      // 0x1000
@@ -1834,7 +1840,7 @@ void Platform::pollGamepadState(Gamepad* gamepad)
             Gamepad::BUTTON_MENU3   // 0x10000
             Gamepad::BUTTON_MENU3   // 0x10000
         };
         };
         
         
-        const unsigned int* mapping = NULL;
+        const int* mapping = NULL;
         if (gamepad->_vendorId == SONY_USB_VENDOR_ID &&
         if (gamepad->_vendorId == SONY_USB_VENDOR_ID &&
             gamepad->_productId == SONY_USB_PS3_PRODUCT_ID)
             gamepad->_productId == SONY_USB_PS3_PRODUCT_ID)
         {
         {
@@ -1842,21 +1848,35 @@ void Platform::pollGamepadState(Gamepad* gamepad)
         }
         }
         
         
         gamepad->_buttons = 0;
         gamepad->_buttons = 0;
-        //for (OSXGamepadButton *b in [gp buttons])
+        
         for (int i = 0; i < [gp numberOfButtons]; ++i)
         for (int i = 0; i < [gp numberOfButtons]; ++i)
         {
         {
-            OSXGamepadButton* b = [gp buttonAtIndex: i];
+            HIDGamepadButton* b = [gp buttonAtIndex: i];
             if ([b state])
             if ([b state])
             {
             {
                 // This button is down.
                 // This button is down.
-                gamepad->_buttons |= (1 << mapping[i]);
+                if (mapping)
+                {
+                    if (mapping[i] >= 0)
+                        gamepad->_buttons |= (1 << mapping[i]);
+                }
+                else
+                {
+                    gamepad->_buttons |= (1 << i);
+                }
             }
             }
         }
         }
 
 
         for (unsigned int i = 0; i < [gp numberOfSticks]; ++i)
         for (unsigned int i = 0; i < [gp numberOfSticks]; ++i)
         {
         {
-            gamepad->_joysticks[i].x = [[gp axisAtIndex: i*2] calibratedValue];
-            gamepad->_joysticks[i].y = [[gp axisAtIndex: i*2 + 1] calibratedValue];
+            float rawX = [[gp axisAtIndex: i*2] calibratedValue];
+            float rawY = -[[gp axisAtIndex: i*2 + 1] calibratedValue];
+            if (std::fabs(rawX) <= 0.07f)
+                rawX = 0;
+            if (std::fabs(rawY) <= 0.07f)
+                rawY = 0;
+            gamepad->_joysticks[i].x = rawX;
+            gamepad->_joysticks[i].y = rawY;
         }
         }
         
         
         for (unsigned int i = 0; i < [gp numberOfTriggerButtons]; ++i)
         for (unsigned int i = 0; i < [gp numberOfTriggerButtons]; ++i)
@@ -1868,10 +1888,10 @@ void Platform::pollGamepadState(Gamepad* gamepad)
 
 
 }
 }
 
 
-OSXGamepad* gamepadForLocationID(NSNumber* locationID)
+HIDGamepad* gamepadForLocationID(NSNumber* locationID)
 {
 {
-    OSXGamepad* fgamepad = NULL;
-    for(OSXGamepad* gamepad in __gamepads)
+    HIDGamepad* fgamepad = NULL;
+    for(HIDGamepad* gamepad in __gamepads)
     {
     {
         if([[gamepad locationID] isEqual:locationID])
         if([[gamepad locationID] isEqual:locationID])
         {
         {
@@ -1882,14 +1902,14 @@ OSXGamepad* gamepadForLocationID(NSNumber* locationID)
     return fgamepad;
     return fgamepad;
 }
 }
 
 
-OSXGamepad* gamepadForLocationIDValue(unsigned int locationIDValue)
+HIDGamepad* gamepadForLocationIDValue(unsigned int locationIDValue)
 {
 {
     return gamepadForLocationID([NSNumber numberWithUnsignedInt:locationIDValue]);
     return gamepadForLocationID([NSNumber numberWithUnsignedInt:locationIDValue]);
 }
 }
 
 
-OSXGamepad* gamepadForGameHandle(int gameHandle)
+HIDGamepad* gamepadForGameHandle(int gameHandle)
 {
 {
-    OSXGamepad* gamepad = NULL;
+    HIDGamepad* gamepad = NULL;
     for(NSNumber* locationID in __activeGamepads)
     for(NSNumber* locationID in __activeGamepads)
     {
     {
         NSNumber* handleID = [__activeGamepads objectForKey:locationID];
         NSNumber* handleID = [__activeGamepads objectForKey:locationID];
@@ -1972,7 +1992,7 @@ static void hidDeviceDiscoveredCallback(void* inContext, IOReturn inResult, void
     CFNumberRef locID = (CFNumberRef)IOHIDDeviceGetProperty(inIOHIDDeviceRef, CFSTR(kIOHIDLocationIDKey));
     CFNumberRef locID = (CFNumberRef)IOHIDDeviceGetProperty(inIOHIDDeviceRef, CFSTR(kIOHIDLocationIDKey));
     if(locID)
     if(locID)
     {
     {
-        OSXGamepad* gamepad = [[OSXGamepad alloc] initWithDevice:inIOHIDDeviceRef];
+        HIDGamepad* gamepad = [[HIDGamepad alloc] initWithDevice:inIOHIDDeviceRef];
         [__gamepads addObject:gamepad];
         [__gamepads addObject:gamepad];
     }
     }
     
     
@@ -1986,7 +2006,7 @@ static void hidDeviceRemovalCallback(void* inContext, IOReturn inResult, void* i
     {
     {
         for(int i = 0; i < [__gamepads count]; i++)
         for(int i = 0; i < [__gamepads count]; i++)
         {
         {
-            OSXGamepad* gamepad = [__gamepads objectAtIndex:i];
+            HIDGamepad* gamepad = [__gamepads objectAtIndex:i];
             if([[gamepad locationID] isEqual:locID])
             if([[gamepad locationID] isEqual:locID])
             {
             {
                 removeIndex = i;
                 removeIndex = i;
@@ -2002,7 +2022,7 @@ static void hidDeviceRemovalCallback(void* inContext, IOReturn inResult, void* i
 
 
 static void hidDeviceValueAvailableCallback(void* inContext, IOReturn inResult,  void* inSender)
 static void hidDeviceValueAvailableCallback(void* inContext, IOReturn inResult,  void* inSender)
 {
 {
-    OSXGamepad* d = (OSXGamepad*)inContext;
+    HIDGamepad* d = (HIDGamepad*)inContext;
     do
     do
     {
     {
         IOHIDValueRef valueRef = IOHIDQueueCopyNextValueWithTimeout( ( IOHIDQueueRef ) inSender, 0. );
         IOHIDValueRef valueRef = IOHIDQueueCopyNextValueWithTimeout( ( IOHIDQueueRef ) inSender, 0. );

+ 6 - 6
gameplay/src/PlatformWindows.cpp

@@ -982,6 +982,12 @@ int Platform::enterMessagePump()
                     Platform::gamepadEventConnectedInternal(i, XINPUT_BUTTON_COUNT, XINPUT_JOYSTICK_COUNT, XINPUT_TRIGGER_COUNT, 0, 0, "Microsoft", "XBox360 Controller");
                     Platform::gamepadEventConnectedInternal(i, XINPUT_BUTTON_COUNT, XINPUT_JOYSTICK_COUNT, XINPUT_TRIGGER_COUNT, 0, 0, "Microsoft", "XBox360 Controller");
                     __connectedXInput[i] = true;
                     __connectedXInput[i] = true;
                 }
                 }
+                else if (XInputGetState(i, &__xInputState) != NO_ERROR && __connectedXInput[i])
+                {
+                    // Gamepad was just disconnected.
+                    __connectedXInput[i] = false;
+                    Platform::gamepadEventDisconnectedInternal(i);
+                }
             }
             }
 #endif
 #endif
 
 
@@ -1232,12 +1238,6 @@ void Platform::pollGamepadState(Gamepad* gamepad)
             }
             }
         }
         }
     }
     }
-    else
-    {
-        // Gamepad was disconnected.
-        __connectedXInput[gamepad->_handle] = false;
-        Platform::gamepadEventDisconnectedInternal(gamepad->_handle);
-    }
 }
 }
 #else
 #else
 void Platform::pollGamepadState(Gamepad* gamepad)
 void Platform::pollGamepadState(Gamepad* gamepad)

+ 1 - 0
gameplay/src/Terrain.cpp

@@ -1,5 +1,6 @@
 #include "Base.h"
 #include "Base.h"
 #include "Terrain.h"
 #include "Terrain.h"
+#include "TerrainPatch.h"
 #include "Node.h"
 #include "Node.h"
 #include "FileSystem.h"
 #include "FileSystem.h"
 
 

+ 3 - 1
gameplay/src/Terrain.h

@@ -1,10 +1,12 @@
 #ifndef TERRAIN_H_
 #ifndef TERRAIN_H_
 #define TERRAIN_H_
 #define TERRAIN_H_
 
 
-#include "TerrainPatch.h"
 #include "Transform.h"
 #include "Transform.h"
 #include "Properties.h"
 #include "Properties.h"
 #include "HeightField.h"
 #include "HeightField.h"
+#include "Texture.h"
+#include "BoundingBox.h"
+#include "TerrainPatch.h"
 
 
 namespace gameplay
 namespace gameplay
 {
 {

+ 5 - 2
gameplay/src/TerrainPatch.cpp

@@ -561,8 +561,11 @@ unsigned int TerrainPatch::getVisibleTriangleCount() const
 
 
     // Does the current camera intersect this patch at all?
     // Does the current camera intersect this patch at all?
     BoundingBox bounds = getBoundingBox(true);
     BoundingBox bounds = getBoundingBox(true);
-    if (!camera->getFrustum().intersects(bounds))
-        return 0;
+    if (_terrain->_flags & Terrain::FRUSTUM_CULLING)
+    {
+        if (!camera->getFrustum().intersects(bounds))
+            return 0;
+    }
 
 
     // Return the triangle count of the LOD level depending on the camera
     // Return the triangle count of the LOD level depending on the camera
     size_t lod = computeLOD(camera, bounds);
     size_t lod = computeLOD(camera, bounds);

+ 2 - 2
gameplay/src/gameplay.h

@@ -38,8 +38,6 @@
 #include "VertexFormat.h"
 #include "VertexFormat.h"
 #include "VertexAttributeBinding.h"
 #include "VertexAttributeBinding.h"
 #include "Model.h"
 #include "Model.h"
-#include "HeightField.h"
-#include "Terrain.h"
 #include "Camera.h"
 #include "Camera.h"
 #include "Light.h"
 #include "Light.h"
 #include "Scene.h"
 #include "Scene.h"
@@ -52,6 +50,8 @@
 #include "RenderTarget.h"
 #include "RenderTarget.h"
 #include "DepthStencilTarget.h"
 #include "DepthStencilTarget.h"
 #include "ScreenDisplayer.h"
 #include "ScreenDisplayer.h"
+#include "HeightField.h"
+#include "Terrain.h"
 
 
 // Audio
 // Audio
 #include "AudioController.h"
 #include "AudioController.h"

+ 30 - 6
gameplay/src/lua/lua_FrameBuffer.cpp

@@ -129,9 +129,21 @@ int lua_FrameBuffer_bind(lua_State* state)
             if ((lua_type(state, 1) == LUA_TUSERDATA))
             if ((lua_type(state, 1) == LUA_TUSERDATA))
             {
             {
                 FrameBuffer* instance = getInstance(state);
                 FrameBuffer* instance = getInstance(state);
-                instance->bind();
-                
-                return 0;
+                void* returnPtr = (void*)instance->bind();
+                if (returnPtr)
+                {
+                    ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "FrameBuffer");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
+
+                return 1;
             }
             }
 
 
             lua_pushstring(state, "lua_FrameBuffer_bind - Failed to match the given parameters to a valid function signature.");
             lua_pushstring(state, "lua_FrameBuffer_bind - Failed to match the given parameters to a valid function signature.");
@@ -560,9 +572,21 @@ int lua_FrameBuffer_static_bindDefault(lua_State* state)
     {
     {
         case 0:
         case 0:
         {
         {
-            FrameBuffer::bindDefault();
-            
-            return 0;
+            void* returnPtr = (void*)FrameBuffer::bindDefault();
+            if (returnPtr)
+            {
+                ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
+                object->instance = returnPtr;
+                object->owns = false;
+                luaL_getmetatable(state, "FrameBuffer");
+                lua_setmetatable(state, -2);
+            }
+            else
+            {
+                lua_pushnil(state);
+            }
+
+            return 1;
             break;
             break;
         }
         }
         default:
         default: