소스 검색

- More console error print, less asserts
- Console : misc cleaning
- Utils : misc cleaning

Eiyeron Fulmincendii 8 년 전
부모
커밋
4c4f680e09
5개의 변경된 파일40개의 추가작업 그리고 43개의 파일을 삭제
  1. 0 8
      debug_overlay/console/commands.lua
  2. 27 31
      debug_overlay/console/init.lua
  3. 4 1
      debug_overlay/init.lua
  4. 9 2
      ecs/ECS.lua
  5. 0 1
      utils.lua

+ 0 - 8
debug_overlay/console/commands.lua

@@ -31,15 +31,7 @@ Commands = {
             collectgarbage(opt, arg)
         end,
         help = "[opt][, arg] : calls lua's collectgarbage'"
-    },
-    spawn = {
-        fun = function(console)
-            local entity = engine.world:createEntity()
-            console:log("Created entity id : "..entity.__eid)
-        end,
-        help = "Spawn a new entity"
     }
-
 }
 
 -- Aliases

+ 27 - 31
debug_overlay/console/init.lua

@@ -113,24 +113,37 @@ function Console:render()
     end
 
     if status then
-        self:enterCommand()
+        if self.input_text == "" then return end
+        local command_line = self.input_text
+        local parts = splitArgs(command_line)
+        local args = {}
+        for i=2,#parts do
+            args[i-1] = parts[i]
+        end
+        self:log("> "..self.input_text, 1)
+
+        local fun_name = parts[1]:lower()
+        local command = self.commands[fun_name]
+        if not command then
+            self:log("Command not found : "..fun_name, ERROR)
+        else
+            local processed_commands = {}
+            local f = function()
+                command(unpack(args))
+            end
+            local success, result = xpcall(f, function(err) return debug.traceback(err) end)
+            if not success then
+                self:log(result, ERROR)
+            end
+
+        end
+
+        self.input_text = ""
+        self.take_focus = true
     end
     imgui.End()
 end
 
-function Console:enterCommand()
-    if self.input_text == "" then return end
-    local command_line = self.input_text
-    local parts = splitArgs(command_line)
-    local args = {}
-    for i=2,#parts do
-        args[i-1] = parts[i]
-    end
-    self:log("> "..self.input_text, 1)
-    self:processCommand(parts[1]:lower(), args)
-    self.input_text = ""
-    self.take_focus = true
-end
 
 function Console:toggle()
     DebugWindow.toggle(self)
@@ -171,21 +184,4 @@ function Console:registerCommand(name, fun, help)
     end
 end
 
-function Console:processCommand(fun_name, args)
-    local command = self.commands[fun_name]
-    if not command then
-        self:log("Command not found : "..fun_name, ERROR)
-        return
-    end
-
-    local processed_commands = {}
-    local f = function()
-        command(unpack(args))
-    end
-    local success, result = xpcall(f, function(err) return debug.traceback(err) end)
-    if not success then
-        self:log(result, ERROR)
-    end
-end
-
 return Console

+ 4 - 1
debug_overlay/init.lua

@@ -21,7 +21,10 @@ function Debug:init()
 end
 
 function Debug:register_menu(menu_name, windows)
-    assert(not self.debug_menus[menu_name])
+    if self.debug_menus[menu_name] then
+        self.console:error('Debug : '..menu_name.." debug menu is already registered.")
+        return
+    end
     self.debug_menus[menu_name] = windows
 end
 

+ 9 - 2
ecs/ECS.lua

@@ -24,7 +24,11 @@ function ECS.debug_register()
 end
 
 function ECS:create_ffi_component(name, structdef)
-    assert(not self.components_classes[name])
+    if self.components_classes[name] then
+        debug_overlay.console:error('ECS : '..name.." compoenent is already created.")
+        return
+    end
+
     local new_component = fficlass("bool _alive;"..structdef)
     self.components_classes[name] = new_component
     self.components[name] = new_component:new_array(ECS.N_ENTITIES)
@@ -33,7 +37,10 @@ function ECS:create_ffi_component(name, structdef)
 end
 
 function ECS:create_lua_component(name, ...)
-    assert(not self.components_classes[name])
+    if self.components_classes[name] then
+        debug_overlay.console:error('ECS : '..name.." compoenent is already created.")
+        return
+    end
     local new_component = class(... or LuaComponent)
     self.components_classes[name] = new_component
     self.components[name] = {}

+ 0 - 1
utils.lua

@@ -1,5 +1,4 @@
 function math.clamp(val, lower, upper)
-    assert(val and lower and upper, "not very useful error message here")
     if lower > upper then lower, upper = upper, lower end -- swap if boundaries supplied the wrong way
     return math.max(lower, math.min(upper, val))
 end