Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

field generator automatic retry implementation #3623

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 64 additions & 2 deletions objects/pilch_shieldgenerator/pilch_shieldgenerator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ function removeField()
end
setStatus("Error: Failed to load field region", "red")
incDirty()

handleRemoveFail()
else
world.setDungeonId(storage.fieldActive, 65531)
if (storage.dungeonId ~= -1) then
Expand All @@ -213,6 +215,8 @@ function removeField()
storage.fieldActive = nil
world.setProperty(tostring(storage.dungeonId), propertyRecord())
setActive(false)

handleEitherSuccess()
end
end
end
Expand All @@ -225,6 +229,8 @@ function applyField()
end
setStatus("Error: Failed to load field region", "red")
incDirty()

handleApplyFail()
else
world.setDungeonId(storage.targetRect, storage.dungeonId)
world.setTileProtection(storage.dungeonId, storage.applyProtected)
Expand All @@ -237,6 +243,8 @@ function applyField()
storage.fieldActive = storage.targetRect
world.setProperty(tostring(storage.dungeonId), propertyRecord())
setActive(true)

handleEitherSuccess()
end
end

Expand Down Expand Up @@ -321,6 +329,60 @@ function setGravity(msgName, isLocal, gravity, level)
incDirty()
end

function handleQueueRetries(dt)
if (self.reApplyTimer) then
self.reApplyTimer=self.reApplyTimer+dt
if (self.reApplyTimer>=(dt*2)) then
applyField()
end
end
if (self.reRemoveTimer) then
self.reRemoveTimer=self.reRemoveTimer+dt
if (self.reRemoveTimer>=(dt*2)) then
removeField()
end
end
end

function handleEitherSuccess()
self.reRemoveRetries=nil
self.reApplyTimer=nil
self.reApplyRetries=nil
self.reRemoveTimer=nil
end

function handleApplyFail()
self.reRemoveRetries=nil
if (self.reApplyRetries==2) then
object.setAllOutputNodes(false)
self.reApplyTimer=nil
else
if(self.reApplyRetries==nil) then
self.reApplyRetries=0
else
self.reApplyRetries=self.reApplyRetries+1
end
self.reApplyTimer=0.0
object.setAllOutputNodes(true)
end
end

function handleRemoveFail()
self.reApplyRetries=nil
if (self.reRemoveRetries==2) then
object.setAllOutputNodes(true)
self.reRemoveTimer=nil
else
if(self.reRemoveRetries==nil) then
self.reRemoveRetries=0
else
self.reRemoveRetries=self.reRemoveRetries+1
end
self.reRemoveTimer=0.0
object.setAllOutputNodes(true)
end
end

function setActive(isActive)
object.setConfigParameter("pilch_shieldgenerator_active", isActive)
if (isActive) then
Expand Down Expand Up @@ -350,8 +412,7 @@ function setStatus(message, colour)
end

function incDirty()
self.dirtyCounter = self.dirtyCounter or 0
self.dirtyCounter = self.dirtyCounter + 1
self.dirtyCounter = (self.dirtyCounter or 0) + 1
object.setConfigParameter("pilch_shieldgenerator_dirty", self.dirtyCounter)
end

Expand All @@ -360,6 +421,7 @@ function update(dt)
if (coroutine.status(self.cor) == "suspended") then
assert(coroutine.resume(self.cor))
end
handleQueueRetries(dt)
end

-- ping for markers when wires are connected/disconnected
Expand Down
68 changes: 65 additions & 3 deletions objects/pilch_shieldgenerator/pilch_shieldgeneratorasteroid.lua
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ function removeField()
end
setStatus("Error: Failed to load field region", "red")
incDirty()

handleRemoveFail()
else
world.setDungeonId(storage.fieldActive, 65531)
if (storage.dungeonId ~= -1) then
Expand All @@ -207,6 +209,8 @@ function removeField()
storage.fieldActive = nil
world.setProperty(tostring(storage.dungeonId), propertyRecord())
setActive(false)

handleEitherSuccess()
end
end
end
Expand All @@ -219,6 +223,8 @@ function applyField()
end
setStatus("Error: Failed to load field region", "red")
incDirty()

handleApplyFail()
else
world.setDungeonId(storage.targetRect, storage.dungeonId)
world.setTileProtection(storage.dungeonId, storage.applyProtected)
Expand All @@ -231,6 +237,8 @@ function applyField()
storage.fieldActive = storage.targetRect
world.setProperty(tostring(storage.dungeonId), propertyRecord())
setActive(true)

handleEitherSuccess()
end
end

Expand All @@ -249,7 +257,7 @@ function checkArea()
if (dId >= LOWID) and (dId <= HIGHID) then
overlaps = overlaps + 1
if storage.debugMode then
table.insert("\n"..overlapList,tostring(dId) .. " @ " .. tostring(x) .. ", " .. tostring(y))
table.insert(overlapList,"\n"..tostring(dId) .. " @ " .. tostring(x) .. ", " .. tostring(y))
end
end
iterations = iterations + 1
Expand Down Expand Up @@ -311,6 +319,60 @@ function setGravity(msgName, isLocal, gravity, level)
incDirty()
end

function handleQueueRetries(dt)
if (self.reApplyTimer) then
self.reApplyTimer=self.reApplyTimer+dt
if (self.reApplyTimer>=(dt*2)) then
applyField()
end
end
if (self.reRemoveTimer) then
self.reRemoveTimer=self.reRemoveTimer+dt
if (self.reRemoveTimer>=(dt*2)) then
removeField()
end
end
end

function handleEitherSuccess()
self.reRemoveRetries=nil
self.reApplyTimer=nil
self.reApplyRetries=nil
self.reRemoveTimer=nil
end

function handleApplyFail()
self.reRemoveRetries=nil
if (self.reApplyRetries==2) then
object.setAllOutputNodes(false)
self.reApplyTimer=nil
else
if(self.reApplyRetries==nil) then
self.reApplyRetries=0
else
self.reApplyRetries=self.reApplyRetries+1
end
self.reApplyTimer=0.0
object.setAllOutputNodes(true)
end
end

function handleRemoveFail()
self.reApplyRetries=nil
if (self.reRemoveRetries==2) then
object.setAllOutputNodes(true)
self.reRemoveTimer=nil
else
if(self.reRemoveRetries==nil) then
self.reRemoveRetries=0
else
self.reRemoveRetries=self.reRemoveRetries+1
end
self.reRemoveTimer=0.0
object.setAllOutputNodes(true)
end
end

function setActive(isActive)
object.setConfigParameter("pilch_shieldgenerator_active", isActive)
if (isActive) then
Expand Down Expand Up @@ -340,8 +402,7 @@ function setStatus(message, colour)
end

function incDirty()
self.dirtyCounter = self.dirtyCounter or 0
self.dirtyCounter = self.dirtyCounter + 1
self.dirtyCounter = (self.dirtyCounter or 0) + 1
object.setConfigParameter("pilch_shieldgenerator_dirty", self.dirtyCounter)
end

Expand All @@ -350,6 +411,7 @@ function update(dt)
if (coroutine.status(self.cor) == "suspended") then
assert(coroutine.resume(self.cor))
end
handleQueueRetries(dt)
end

-- ping for markers when wires are connected/disconnected
Expand Down