Fixes regarding dynamic and seq behavior nodes
This commit is contained in:
parent
f9b339c0e4
commit
b223d6ea6c
@ -71,7 +71,13 @@ local function blackboardSet(self, t, key, value)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function blackboardPrototype:set(t, key, value)
|
function blackboardPrototype:set(t, key, value)
|
||||||
blackboardSet(self, mappedParameterTypes[t], key, value)
|
local lookup = mappedParameterTypes[t]
|
||||||
|
|
||||||
|
if not lookup then
|
||||||
|
error('unknown blackboard value type ' .. tostring(t))
|
||||||
|
end
|
||||||
|
|
||||||
|
blackboardSet(self, lookup, key, value)
|
||||||
end
|
end
|
||||||
|
|
||||||
function blackboardPrototype:setRaw(t, key, value)
|
function blackboardPrototype:setRaw(t, key, value)
|
||||||
@ -263,21 +269,18 @@ do
|
|||||||
return FAILURE
|
return FAILURE
|
||||||
end
|
end
|
||||||
|
|
||||||
if nodeStatus == nil then
|
|
||||||
--table.remove(stack)
|
|
||||||
return RUNNING
|
|
||||||
end
|
|
||||||
|
|
||||||
if nodeExtra ~= nil then
|
if nodeExtra ~= nil then
|
||||||
blackboard:setOutput(self, nodeExtra)
|
blackboard:setOutput(self, nodeExtra)
|
||||||
end
|
end
|
||||||
|
|
||||||
--table.remove(stack)
|
--table.remove(stack)
|
||||||
|
|
||||||
if nodeStatus then
|
if nodeStatus == nil then
|
||||||
return SUCCESS
|
return RUNNING
|
||||||
else
|
elseif nodeStatus == false then
|
||||||
return FAILURE
|
return FAILURE
|
||||||
|
else
|
||||||
|
return SUCCESS
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -342,22 +345,12 @@ do
|
|||||||
return FAILURE
|
return FAILURE
|
||||||
end
|
end
|
||||||
|
|
||||||
if nodeStatus == nil then
|
if nodeStatus == true then
|
||||||
local s = coroutine_status(coroutine)
|
|
||||||
|
|
||||||
if s == 'dead' then
|
|
||||||
-- quite unexpected, but whatever
|
|
||||||
--table.remove(stack)
|
|
||||||
return SUCCESS
|
|
||||||
else
|
|
||||||
self.coroutine = coroutine
|
|
||||||
end
|
|
||||||
elseif nodeStatus then
|
|
||||||
--table.remove(stack)
|
|
||||||
return SUCCESS
|
return SUCCESS
|
||||||
else
|
elseif nodeStatus == false then
|
||||||
--table.remove(stack)
|
|
||||||
return FAILURE
|
return FAILURE
|
||||||
|
else
|
||||||
|
self.coroutine = coroutine
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -377,27 +370,10 @@ do
|
|||||||
return FAILURE
|
return FAILURE
|
||||||
end
|
end
|
||||||
|
|
||||||
if nodeStatus == nil then
|
if nodeStatus == true then
|
||||||
-- another yield OR unexpected return?
|
return SUCCESS
|
||||||
|
elseif nodeStatus == false then
|
||||||
local s = coroutine_status(self.coroutine)
|
return FAILURE
|
||||||
|
|
||||||
if s == 'dead' then
|
|
||||||
self.coroutine = nil
|
|
||||||
--table.remove(stack)
|
|
||||||
return SUCCESS
|
|
||||||
end
|
|
||||||
else
|
|
||||||
-- yield or return with status
|
|
||||||
self.coroutine = nil
|
|
||||||
|
|
||||||
if nodeStatus then
|
|
||||||
--table.remove(stack)
|
|
||||||
return SUCCESS
|
|
||||||
else
|
|
||||||
--table.remove(stack)
|
|
||||||
return FAILURE
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -461,6 +437,9 @@ function seqNode:run(delta, blackboard, stack)
|
|||||||
|
|
||||||
self.index = self.index + 1
|
self.index = self.index + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if isSelector then return FAILURE end
|
||||||
|
return SUCCESS
|
||||||
end
|
end
|
||||||
|
|
||||||
function seqNode:reset()
|
function seqNode:reset()
|
||||||
@ -594,13 +573,19 @@ function dynNode:run(delta, blackboard, stack)
|
|||||||
self.calls = self.calls + 1
|
self.calls = self.calls + 1
|
||||||
--table.insert(stack, 'DynamicNode')
|
--table.insert(stack, 'DynamicNode')
|
||||||
|
|
||||||
for i, node in ipairs(self.children) do
|
local i = 1
|
||||||
local status = runAndReset(node, delta, blackboard, stack)
|
local children = self.children
|
||||||
|
|
||||||
if stauts == FAILURE and self.index == i then
|
while i <= self.index do
|
||||||
|
local child = children[i]
|
||||||
|
local status = runAndReset(child, delta, blackboard, stack)
|
||||||
|
|
||||||
|
if status == FAILURE and i == self.index then
|
||||||
self.index = self.index + 1
|
self.index = self.index + 1
|
||||||
elseif status ~= RUNNING and i < self.index then
|
end
|
||||||
node:reset()
|
|
||||||
|
if i < self.index and (status == SUCCESS or status == RUNNING) then
|
||||||
|
child:reset()
|
||||||
self.index = i
|
self.index = i
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -608,6 +593,8 @@ function dynNode:run(delta, blackboard, stack)
|
|||||||
--table.remove(stack)
|
--table.remove(stack)
|
||||||
return status
|
return status
|
||||||
end
|
end
|
||||||
|
|
||||||
|
i = i + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
--table.remove(stack)
|
--table.remove(stack)
|
||||||
@ -692,9 +679,10 @@ end
|
|||||||
local statePrototype = {}
|
local statePrototype = {}
|
||||||
statePrototype.__index = statePrototype
|
statePrototype.__index = statePrototype
|
||||||
|
|
||||||
function statePrototype:ctor(blackboard, root)
|
function statePrototype:ctor(blackboard, root, name)
|
||||||
self.root = root
|
self.root = root
|
||||||
self._blackboard = blackboard
|
self._blackboard = blackboard
|
||||||
|
self.name = name or 'unnamed'
|
||||||
|
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user