Fixes regarding dynamic and seq behavior nodes

This commit is contained in:
DBotThePony 2025-01-01 09:40:11 +07:00
parent f9b339c0e4
commit b223d6ea6c
Signed by: DBot
GPG Key ID: DCC23B5715498507

View File

@ -71,7 +71,13 @@ local function blackboardSet(self, t, key, value)
end
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
function blackboardPrototype:setRaw(t, key, value)
@ -263,21 +269,18 @@ do
return FAILURE
end
if nodeStatus == nil then
--table.remove(stack)
return RUNNING
end
if nodeExtra ~= nil then
blackboard:setOutput(self, nodeExtra)
end
--table.remove(stack)
if nodeStatus then
return SUCCESS
else
if nodeStatus == nil then
return RUNNING
elseif nodeStatus == false then
return FAILURE
else
return SUCCESS
end
end
end
@ -342,22 +345,12 @@ do
return FAILURE
end
if nodeStatus == nil 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)
if nodeStatus == true then
return SUCCESS
else
--table.remove(stack)
elseif nodeStatus == false then
return FAILURE
else
self.coroutine = coroutine
end
end
@ -377,27 +370,10 @@ do
return FAILURE
end
if nodeStatus == nil then
-- another yield OR unexpected return?
local s = coroutine_status(self.coroutine)
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
if nodeStatus == true then
return SUCCESS
elseif nodeStatus == false then
return FAILURE
end
end
end
@ -461,6 +437,9 @@ function seqNode:run(delta, blackboard, stack)
self.index = self.index + 1
end
if isSelector then return FAILURE end
return SUCCESS
end
function seqNode:reset()
@ -594,13 +573,19 @@ function dynNode:run(delta, blackboard, stack)
self.calls = self.calls + 1
--table.insert(stack, 'DynamicNode')
for i, node in ipairs(self.children) do
local status = runAndReset(node, delta, blackboard, stack)
local i = 1
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
elseif status ~= RUNNING and i < self.index then
node:reset()
end
if i < self.index and (status == SUCCESS or status == RUNNING) then
child:reset()
self.index = i
end
@ -608,6 +593,8 @@ function dynNode:run(delta, blackboard, stack)
--table.remove(stack)
return status
end
i = i + 1
end
--table.remove(stack)
@ -692,9 +679,10 @@ end
local statePrototype = {}
statePrototype.__index = statePrototype
function statePrototype:ctor(blackboard, root)
function statePrototype:ctor(blackboard, root, name)
self.root = root
self._blackboard = blackboard
self.name = name or 'unnamed'
return self
end