This commit is contained in:
Tilmann Hars 2014-11-13 16:03:35 +01:00
commit 49a1e33c56
5 changed files with 12 additions and 9 deletions

View File

@ -51,7 +51,7 @@ end
-- returns a deep copy of `other'
local function clone(other)
return include({}, other)
return setmetatable(include({}, other), getmetatable(other))
end
local function new(class)

View File

@ -36,6 +36,7 @@ function GS.new(t) return t or {} end -- constructor - deprecated!
function GS.switch(to, ...)
assert(to, "Missing argument: Gamestate to switch to")
assert(to ~= GS, "Can't call switch with colon operator")
local pre = stack[#stack]
;(pre.leave or __NULL__)(pre)
;(to.init or __NULL__)(to)
@ -46,6 +47,7 @@ end
function GS.push(to, ...)
assert(to, "Missing argument: Gamestate to switch to")
assert(to ~= GS, "Can't call push with colon operator")
local pre = stack[#stack]
;(to.init or __NULL__)(to)
to.init = nil
@ -53,11 +55,12 @@ function GS.push(to, ...)
return (to.enter or __NULL__)(to, pre, ...)
end
function GS.pop()
function GS.pop(...)
assert(#stack > 1, "No more states to pop!")
local pre = stack[#stack]
stack[#stack] = nil
return (pre.leave or __NULL__)(pre)
;(pre.leave or __NULL__)(pre)
return (stack[#stack].resume or __NULL__)(pre, ...)
end
function GS.current()

View File

@ -83,7 +83,7 @@ local default = new()
return setmetatable({
new = new,
register = function(...) default:register(...) end,
register = function(...) return default:register(...) end,
emit = function(...) default:emit(...) end,
remove = function(...) default:remove(...) end,
clear = function(...) default:clear(...) end,

View File

@ -116,7 +116,7 @@ end
-- ref.: http://blog.signalsondisplay.com/?p=336
local function trim(maxLen, x, y)
local s = maxLen * maxLen / len2(x, y)
s = s < 1 and 1 or math.sqrt(s)
s = s > 1 and 1 or math.sqrt(s)
return x * s, y * s
end

View File

@ -36,7 +36,7 @@ end
local zero = new(0,0)
local function isvector(v)
return getmetatable(v) == vector
return type(v) == 'table' and type(v.x) == 'number' and type(v.y) == 'number'
end
function vector:clone()
@ -169,16 +169,16 @@ end
-- ref.: http://blog.signalsondisplay.com/?p=336
function vector:trim_inplace(maxLen)
local s = maxLen * maxLen / self:len2()
s = s < 1 and 1 or math.sqrt(s)
s = (s > 1 and 1) or math.sqrt(s)
self.x, self.y = self.x * s, self.y * s
return self
end
function vector:angleTo(other)
if other then
return atan2(self.y, self.y) - atan2(other.y, other.x)
return atan2(self.y, self.x) - atan2(other.y, other.x)
end
return atan2(self.y, self.y)
return atan2(self.y, self.x)
end
function vector:trimmed(maxLen)