Browse Source

Slightly improved NinjaSnowWar touch controls.
Fixed low quality OpenGL ES shadow mapping shader.

Lasse Öörni 13 years ago
parent
commit
d8a975811f

+ 16 - 14
Bin/Data/Scripts/NinjaSnowWar.as

@@ -31,7 +31,7 @@ Text@ messageText;
 BorderImage@ healthBar;
 BorderImage@ sight;
 BorderImage@ moveButton;
-BorderImage@ shootButton;
+BorderImage@ fireButton;
 SoundSource@ musicSource;
 
 Controls playerControls;
@@ -49,6 +49,7 @@ int clientScore = 0;
 
 bool touchEnabled = false;
 int touchButtonSize = 96;
+int touchButtonBorder = 12;
 int moveTouchID = -1;
 int rotateTouchID = -1;
 int fireTouchID = -1;
@@ -244,16 +245,17 @@ void CreateOverlays()
         moveButton = BorderImage();
         moveButton.texture = cache.GetResource("Texture2D", "Textures/TouchInput.png");
         moveButton.imageRect = IntRect(0, 0, 96, 96);
-        moveButton.SetPosition(0, graphics.height - touchButtonSize);
+        moveButton.SetPosition(touchButtonBorder, graphics.height - touchButtonSize - touchButtonBorder);
         moveButton.SetSize(touchButtonSize, touchButtonSize);
         ui.root.AddChild(moveButton);
 
-        shootButton = BorderImage();
-        shootButton.texture = cache.GetResource("Texture2D", "Textures/TouchInput.png");
-        shootButton.imageRect = IntRect(96, 0, 192, 96);
-        shootButton.SetPosition(graphics.width - touchButtonSize, graphics.height - touchButtonSize);
-        shootButton.SetSize(touchButtonSize, touchButtonSize);
-        ui.root.AddChild(shootButton);
+        fireButton = BorderImage();
+        fireButton.texture = cache.GetResource("Texture2D", "Textures/TouchInput.png");
+        fireButton.imageRect = IntRect(96, 0, 192, 96);
+        fireButton.SetPosition(graphics.width - touchButtonSize - touchButtonBorder, graphics.height - touchButtonSize -
+            touchButtonBorder);
+        fireButton.SetSize(touchButtonSize, touchButtonSize);
+        ui.root.AddChild(fireButton);
     }
 }
 
@@ -767,17 +769,18 @@ void UpdateControls()
 
         if (touchEnabled)
         {
-            for (int i = 0; i < input.numTouches; ++i)
+            for (uint i = 0; i < input.numTouches; ++i)
             {
                 TouchState touch = input.touches[i];
-                if (touch.touchID == rotateTouchID || (touch.position.y < graphics.height - touchButtonSize || 
-                    (touch.position.x >= touchButtonSize && touch.position.x < graphics.width - touchButtonSize)))
+                UIElement@ element = ui.GetElementAt(touch.position, false);
+
+                if (touch.touchID == rotateTouchID || (element !is moveButton && element !is fireButton))
                 {
                     rotateTouchID = touch.touchID;
                     playerControls.yaw += touchSensitivity * gameCamera.fov / graphics.height * touch.delta.x;
                     playerControls.pitch += touchSensitivity * gameCamera.fov / graphics.height * touch.delta.y;
                 }
-                else if (touch.position.y >= graphics.height - touchButtonSize && touch.position.x < touchButtonSize)
+                else if (element is moveButton || touch.touchID == moveTouchID)
                 {
                     moveTouchID = touch.touchID;
                     int relX = touch.position.x - touchButtonSize / 2;
@@ -791,8 +794,7 @@ void UpdateControls()
                     if (relX > 0 && Abs(relY * 3 / 2) < Abs(relX))
                         playerControls.Set(CTRL_RIGHT, true);
                 }
-                else if (touch.position.y >= graphics.height - touchButtonSize && touch.position.x >= graphics.width - 
-                    touchButtonSize)
+                else if (element is fireButton)
                 {
                     fireTouchID = touch.touchID;
                     playerControls.Set(CTRL_FIRE, true);

+ 2 - 1
Engine/Graphics/OpenGL/OGLGraphics.cpp

@@ -2163,7 +2163,8 @@ void Graphics::CleanupFramebuffers(bool deleteAll)
     for (Map<unsigned long long, FrameBufferObject>::Iterator i = impl_->frameBuffers_.Begin(); i != impl_->frameBuffers_.End();)
     {
         Map<unsigned long long, FrameBufferObject>::Iterator current = i++;
-        if (deleteAll || (current->second_.fbo_ != impl_->boundFbo_ && current->second_.useTimer_.GetMSec(false) > MAX_FRAMEBUFFER_AGE))
+        if (deleteAll || (current->second_.fbo_ != impl_->boundFbo_ && current->second_.useTimer_.GetMSec(false) >
+            MAX_FRAMEBUFFER_AGE))
         {
             glDeleteFramebuffersEXT(1, &current->second_.fbo_);
             impl_->frameBuffers_.Erase(current);

+ 1 - 1
SourceAssets/GLSLShaders/Lighting.frag

@@ -68,7 +68,7 @@ float GetShadow(vec4 shadowPos)
         #ifndef GL_ES
             float inLight = shadow2DProj(sShadowMap, shadowPos).r;
         #else
-            float inLight = texture2DProj(sShadowMap, shadowPos).r * shadowPos.w > shadowPos.z;
+            float inLight = texture2DProj(sShadowMap, shadowPos).r * shadowPos.w > shadowPos.z ? 1.0 : 0.0;
         #endif
         return cShadowIntensity.y + cShadowIntensity.x * inLight;
     #endif