Browse Source

Use matching else-if construct in AngelScript & Lua Sample code.
Changed ErrorDialogs in the Lua subsystem to error logging (subsystems should not pop up dialogs on their own.)

Lasse Öörni 12 years ago
parent
commit
ccdd318eff

+ 18 - 27
Bin/Data/LuaScripts/Utilities/Sample.lua

@@ -90,18 +90,16 @@ function HandleKeyDown(eventType, eventData)
             local console = GetConsole()
             local console = GetConsole()
             console:SetVisible(false)
             console:SetVisible(false)
         end
         end
-    end
-    
-    if key == KEY_F1 then
+
+    elseif key == KEY_F1 then
         local console = GetConsole()
         local console = GetConsole()
         console:Toggle()
         console:Toggle()
-    end
-    
-    if key == KEY_F2 then
+
+    elseif key == KEY_F2 then
         local debugHud = GetDebugHud()
         local debugHud = GetDebugHud()
         debugHud:ToggleAll()
         debugHud:ToggleAll()
     end
     end
-    
+
     local ui = GetUI()
     local ui = GetUI()
     if ui.focusElement == nil then
     if ui.focusElement == nil then
         local renderer = GetRenderer()
         local renderer = GetRenderer()
@@ -113,50 +111,44 @@ function HandleKeyDown(eventType, eventData)
                 quality = QUALITY_LOW
                 quality = QUALITY_LOW
             end
             end
             renderer.textureQuality = quality
             renderer.textureQuality = quality
-        end
-        
+
         -- Material quality
         -- Material quality
-        if key == KEY_2 then
+        elseif key == KEY_2 then
             local quality = renderer.materialQuality
             local quality = renderer.materialQuality
             quality = quality + 1
             quality = quality + 1
             if quality > QUALITY_HIGH then
             if quality > QUALITY_HIGH then
                 quality = QUALITY_LOW
                 quality = QUALITY_LOW
             end
             end
             renderer.materialQuality = quality
             renderer.materialQuality = quality
-        end
 
 
         -- Specular lighting
         -- Specular lighting
-        if key == KEY_3 then
+        elseif key == KEY_3 then
             renderer.specularLighting = not renderer.specularLighting
             renderer.specularLighting = not renderer.specularLighting
-        end
-        
+
         -- Shadow rendering
         -- Shadow rendering
-        if key == KEY_4 then
+        elseif key == KEY_4 then
             renderer.drawShadows = not renderer.drawShadows
             renderer.drawShadows = not renderer.drawShadows
-        end
-        
+
         -- Shadow map resolution
         -- Shadow map resolution
-        if key == KEY_5 then
+        elseif key == KEY_5 then
             local shadowMapSize = renderer.shadowMapSize
             local shadowMapSize = renderer.shadowMapSize
             shadowMapSize = shadowMapSize * 2
             shadowMapSize = shadowMapSize * 2
             if shadowMapSize > 2048 then
             if shadowMapSize > 2048 then
                 shadowMapSize = 512
                 shadowMapSize = 512
             end
             end
             renderer.shadowMapSize = shadowMapSize
             renderer.shadowMapSize = shadowMapSize
-        end
-        
+
         -- Shadow depth and filtering quality
         -- Shadow depth and filtering quality
-        if key == KEY_6 then
+        elseif key == KEY_6 then
             local quality = renderer.shadowQuality
             local quality = renderer.shadowQuality
             quality = quality + 1
             quality = quality + 1
             if quality > SHADOWQUALITY_HIGH_24BIT then
             if quality > SHADOWQUALITY_HIGH_24BIT then
                 quality = SHADOWQUALITY_LOW_16BIT
                 quality = SHADOWQUALITY_LOW_16BIT
             end
             end
             renderer.shadowQuality = quality
             renderer.shadowQuality = quality
-        end
-        
+
         -- Occlusion culling
         -- Occlusion culling
-        if key == KEY_7 then
+        elseif key == KEY_7 then
             local occlusion = renderer.maxOccluderTriangles > 0
             local occlusion = renderer.maxOccluderTriangles > 0
             occlusion = not occlusion
             occlusion = not occlusion
             if occlusion then
             if occlusion then
@@ -164,10 +156,9 @@ function HandleKeyDown(eventType, eventData)
             else
             else
                 renderer.maxOccluderTriangles = 0
                 renderer.maxOccluderTriangles = 0
             end
             end
-        end
-        
+
         -- Instancing
         -- Instancing
-        if key == KEY_8 then
+        elseif key == KEY_8 then
             renderer.dynamicInstancing = not renderer.dynamicInstancing
             renderer.dynamicInstancing = not renderer.dynamicInstancing
         end
         end
     end
     end

+ 13 - 13
Bin/Data/Scripts/Utilities/Sample.as

@@ -90,13 +90,13 @@ void HandleKeyDown(StringHash eventType, VariantMap& eventData)
     }
     }
 
 
     // Toggle console with F1
     // Toggle console with F1
-    if (key == KEY_F1)
+    else if (key == KEY_F1)
         console.Toggle();
         console.Toggle();
-    
+
     // Toggle debug HUD with F2
     // Toggle debug HUD with F2
-    if (key == KEY_F2)
+    else if (key == KEY_F2)
         debugHud.ToggleAll();
         debugHud.ToggleAll();
-    
+
     // Common rendering quality controls, only when UI has no focused element
     // Common rendering quality controls, only when UI has no focused element
     if (ui.focusElement is null)
     if (ui.focusElement is null)
     {
     {
@@ -109,9 +109,9 @@ void HandleKeyDown(StringHash eventType, VariantMap& eventData)
                 quality = QUALITY_LOW;
                 quality = QUALITY_LOW;
             renderer.textureQuality = quality;
             renderer.textureQuality = quality;
         }
         }
-        
+
         // Material quality
         // Material quality
-        if (key == '2')
+        else if (key == '2')
         {
         {
             int quality = renderer.materialQuality;
             int quality = renderer.materialQuality;
             ++quality;
             ++quality;
@@ -121,15 +121,15 @@ void HandleKeyDown(StringHash eventType, VariantMap& eventData)
         }
         }
         
         
         // Specular lighting
         // Specular lighting
-        if (key == '3')
+        else if (key == '3')
             renderer.specularLighting = !renderer.specularLighting;
             renderer.specularLighting = !renderer.specularLighting;
-        
+
         // Shadow rendering
         // Shadow rendering
-        if (key == '4')
+        else if (key == '4')
             renderer.drawShadows = !renderer.drawShadows;
             renderer.drawShadows = !renderer.drawShadows;
 
 
         // Shadow map resolution
         // Shadow map resolution
-        if (key == '5')
+        else if (key == '5')
         {
         {
             int shadowMapSize = renderer.shadowMapSize;
             int shadowMapSize = renderer.shadowMapSize;
             shadowMapSize *= 2;
             shadowMapSize *= 2;
@@ -139,7 +139,7 @@ void HandleKeyDown(StringHash eventType, VariantMap& eventData)
         }
         }
         
         
         // Shadow depth and filtering quality
         // Shadow depth and filtering quality
-        if (key == '6')
+        else if (key == '6')
         {
         {
             int quality = renderer.shadowQuality;
             int quality = renderer.shadowQuality;
             ++quality;
             ++quality;
@@ -149,7 +149,7 @@ void HandleKeyDown(StringHash eventType, VariantMap& eventData)
         }
         }
         
         
         // Occlusion culling
         // Occlusion culling
-        if (key == '7')
+        else if (key == '7')
         {
         {
             bool occlusion = renderer.maxOccluderTriangles > 0;
             bool occlusion = renderer.maxOccluderTriangles > 0;
             occlusion = !occlusion;
             occlusion = !occlusion;
@@ -157,7 +157,7 @@ void HandleKeyDown(StringHash eventType, VariantMap& eventData)
         }
         }
         
         
         // Instancing
         // Instancing
-        if (key == '8')
+        else if (key == '8')
             renderer.dynamicInstancing = !renderer.dynamicInstancing;
             renderer.dynamicInstancing = !renderer.dynamicInstancing;
     }
     }
 }
 }

+ 5 - 2
Source/Extras/LuaScript/LuaFile.cpp

@@ -23,6 +23,7 @@
 #include "Precompiled.h"
 #include "Precompiled.h"
 #include "Context.h"
 #include "Context.h"
 #include "Deserializer.h"
 #include "Deserializer.h"
+#include "Log.h"
 #include "LuaFile.h"
 #include "LuaFile.h"
 #include "ProcessUtils.h"
 #include "ProcessUtils.h"
 #include "Serializer.h"
 #include "Serializer.h"
@@ -34,6 +35,8 @@ extern "C"
 #include <lauxlib.h>
 #include <lauxlib.h>
 }
 }
 
 
+#include "DebugNew.h"
+
 namespace Urho3D
 namespace Urho3D
 {
 {
 
 
@@ -100,7 +103,7 @@ bool LuaFile::Execute(lua_State* luaState)
     if (error)
     if (error)
     {
     {
         const char* message = lua_tostring(luaState, -1);
         const char* message = lua_tostring(luaState, -1);
-        ErrorDialog("Load Buffer Failed", message);
+        LOGERROR("Load Buffer Failed: " + String(message));
         lua_settop(luaState, top);
         lua_settop(luaState, top);
         return false;
         return false;
     }
     }
@@ -108,7 +111,7 @@ bool LuaFile::Execute(lua_State* luaState)
     if (lua_pcall(luaState, 0, 0, 0))
     if (lua_pcall(luaState, 0, 0, 0))
     {
     {
         const char* message = lua_tostring(luaState, -1);
         const char* message = lua_tostring(luaState, -1);
-        ErrorDialog("Lua Execute Failed", message);
+        LOGERROR("Lua Execute Failed: " + String(message));
         lua_settop(luaState, top);
         lua_settop(luaState, top);
         return false;
         return false;
     }
     }

+ 8 - 8
Source/Extras/LuaScript/LuaScript.cpp

@@ -73,7 +73,7 @@ LuaScript::LuaScript(Context* context) :
     luaState_ = luaL_newstate();
     luaState_ = luaL_newstate();
     if (!luaState_)
     if (!luaState_)
     {
     {
-        ErrorDialog("Lua Error", "Could not create Lua state.");
+        LOGERROR("Could not create Lua state.");
         return;
         return;
     }
     }
 
 
@@ -131,7 +131,7 @@ bool LuaScript::ExecuteString(const String& string)
     if (luaL_dostring(luaState_, string.CString()) != 0)
     if (luaL_dostring(luaState_, string.CString()) != 0)
     {
     {
         const char* message = lua_tostring(luaState_, -1);
         const char* message = lua_tostring(luaState_, -1);
-        ErrorDialog("Execute Lua String Failed", message);
+        LOGERROR("Execute Lua String Failed: " + String(message));
         lua_settop(luaState_, top);
         lua_settop(luaState_, top);
         return false;
         return false;
     }
     }
@@ -154,7 +154,7 @@ bool LuaScript::ExecuteFunction(const String& functionName)
     if (lua_pcall(luaState_, 0, 0, 0))
     if (lua_pcall(luaState_, 0, 0, 0))
     {
     {
         const char* message = lua_tostring(luaState_, -1);
         const char* message = lua_tostring(luaState_, -1);
-        ErrorDialog("Execute Lua Function Failed", message);
+        LOGERROR("Execute Lua Function Failed: " + String(message));
         lua_settop(luaState_, top);
         lua_settop(luaState_, top);
         return false;
         return false;
     }
     }
@@ -223,7 +223,7 @@ int LuaScript::Loader(lua_State* L)
     if (error)
     if (error)
     {
     {
         const char* message = lua_tostring(L, -1);
         const char* message = lua_tostring(L, -1);
-        ErrorDialog("Execute Lua File Failed", message);
+        LOGERROR("Execute Lua File Failed: " + String(message));
         lua_settop(L, top);
         lua_settop(L, top);
         return 0;
         return 0;
     }
     }
@@ -282,7 +282,7 @@ bool LuaScript::FindFunction(const String& functionName)
     {
     {
         if (!lua_istable(luaState_, -1))
         if (!lua_istable(luaState_, -1))
         {
         {
-            ErrorDialog("Can Not Find Lua Table", String("Table Name = '") + currentName + "'.");
+            LOGERROR("Can Not Find Lua Table: " + String("Table Name = '") + currentName + "'.");
             return false;
             return false;
         }
         }
 
 
@@ -292,7 +292,7 @@ bool LuaScript::FindFunction(const String& functionName)
             lua_getfield(luaState_, -1, splitedNames[i].CString());
             lua_getfield(luaState_, -1, splitedNames[i].CString());
             if (!lua_istable(luaState_, -1))
             if (!lua_istable(luaState_, -1))
             {
             {
-                ErrorDialog("Can Not Find Lua Table", String("Table Name = '") + currentName + "'.");
+                LOGERROR("Can Not Find Lua Table: " + String("Table Name = '") + currentName + "'.");
                 return false;
                 return false;
             }
             }
         }
         }
@@ -303,7 +303,7 @@ bool LuaScript::FindFunction(const String& functionName)
 
 
     if (!lua_isfunction(luaState_, -1))
     if (!lua_isfunction(luaState_, -1))
     {
     {
-        ErrorDialog("Can Not Find Lua Function", String("Function Name = '") + currentName + "'.");
+        LOGERROR("Can Not Find Lua Function: " + String("Function Name = '") + currentName + "'.");
         return false;
         return false;
     }
     }
 
 
@@ -346,7 +346,7 @@ void LuaScript::CallEventHandler(const String& functionName, StringHash eventTyp
     if (lua_pcall(luaState_, 2, 0, 0) != 0)
     if (lua_pcall(luaState_, 2, 0, 0) != 0)
     {
     {
         const char* message = lua_tostring(luaState_, -1);
         const char* message = lua_tostring(luaState_, -1);
-        ErrorDialog("Execute Lua Function Failed", message);
+        LOGERROR("Execute Lua Function Failed: " + String(message));
         lua_settop(luaState_, top);
         lua_settop(luaState_, top);
         return;
         return;
     }
     }