- Fixed a possible crash when multiple event-regrowth structures are simultaneouslydestroyed in the same area

- Fixed the issue that mandrakes don't respawn
This commit is contained in:
secXsQuared 2018-01-29 15:24:22 -05:00
parent 6161bc2885
commit fd8a256870
4 changed files with 39 additions and 33 deletions

View File

@ -1,6 +1,6 @@
name = "World Regrowth++" name = "World Regrowth++"
version = "0.1.4" version = "0.1.5"
description = "Version "..version.."\n\nAdvanced world regrowth including caves! See the Steam Workshop page for more information.\n\nHappy hunting and do starve!" description = "Version "..version.."\n\nAdvanced world regrowth including caves! Please see the Steam Workshop page for the update notes.\n\nHappy hunting and do starve!"
author = "lolo" author = "lolo"
forumthread = "" forumthread = ""
@ -48,7 +48,7 @@ local config_table =
{"red_mushroom","Red Mushroom",REGROWTH_TYPE.NATURAL, 240}, {"red_mushroom","Red Mushroom",REGROWTH_TYPE.NATURAL, 240},
{"green_mushroom","Green Mushroom",REGROWTH_TYPE.NATURAL, 240}, {"green_mushroom","Green Mushroom",REGROWTH_TYPE.NATURAL, 240},
{"cactus","Cactus",REGROWTH_TYPE.NATURAL, 479}, {"cactus","Cactus",REGROWTH_TYPE.NATURAL, 479},
{"mandrake","Mandrake",REGROWTH_TYPE.EVENT, 969}, {"mandrake_planted","Mandrake",REGROWTH_TYPE.EVENT, 969},
{"reeds","Reeds",REGROWTH_TYPE.NATURAL, 480}, {"reeds","Reeds",REGROWTH_TYPE.NATURAL, 480},
{"sapling","Sapling",REGROWTH_TYPE.NATURAL, 240}, {"sapling","Sapling",REGROWTH_TYPE.NATURAL, 240},

View File

@ -34,7 +34,7 @@ local config_table =
{"red_mushroom","Red Mushroom",REGROWTH_TYPE.NATURAL, 240}, {"red_mushroom","Red Mushroom",REGROWTH_TYPE.NATURAL, 240},
{"green_mushroom","Green Mushroom",REGROWTH_TYPE.NATURAL, 240}, {"green_mushroom","Green Mushroom",REGROWTH_TYPE.NATURAL, 240},
{"cactus","Cactus",REGROWTH_TYPE.NATURAL, 479}, {"cactus","Cactus",REGROWTH_TYPE.NATURAL, 479},
{"mandrake","Mandrake",REGROWTH_TYPE.EVENT, 969}, {"mandrake_planted","Mandrake",REGROWTH_TYPE.EVENT, 969},
{"reeds","Reeds",REGROWTH_TYPE.NATURAL, 480}, {"reeds","Reeds",REGROWTH_TYPE.NATURAL, 480},
{"sapling","Sapling",REGROWTH_TYPE.NATURAL, 240}, {"sapling","Sapling",REGROWTH_TYPE.NATURAL, 240},

View File

@ -54,7 +54,7 @@ return Class(function(self, inst)
end end
local position = ent:GetPosition() local position = ent:GetPosition()
entity_list[ent.prefab][#entity_list[ent.prefab]+1] = {position = position, interval = regrowth_table[ent.prefab].interval} entity_list[ent.prefab][#entity_list[ent.prefab]+1] = {position = position, interval = regrowth_table[ent.prefab].interval, remove=false}
ent:RemoveEventCallback("onremove", EntityDeathEventHandler, nil) ent:RemoveEventCallback("onremove", EntityDeathEventHandler, nil)
if DEBUG then if DEBUG then
@ -244,14 +244,10 @@ return Class(function(self, inst)
-------------------------------------------------------------------------- --------------------------------------------------------------------------
--[[ Update ]] --[[ Update ]]
-------------------------------------------------------------------------- --------------------------------------------------------------------------
local function RegrowPrefabTask(prefab, position) local function RegrowPrefabTask(prefab, data)
for i = #entity_list[prefab],1,-1 do local success = TryRegrowth(prefab, regrowth_table[prefab].product, data.position)
local success = TryRegrowth(prefab, regrowth_table[prefab].product, position) if success then
data.remove = true
if success then
-- remove from the list if it's success or failed
table.remove(entity_list[prefab], i)
end
end end
end end
@ -272,27 +268,36 @@ return Class(function(self, inst)
-- if we don't have it registered, discard -- if we don't have it registered, discard
entity_list[prefab] = nil entity_list[prefab] = nil
else else
for i = 1, #entity_list[prefab] do for i = #entity_list[prefab], 1, -1 do
-- decrease the interval if entity_list[prefab][i].remove then
if entity_list[prefab][i].interval > UPDATE_PERIOD then -- handle expired objects first
entity_list[prefab][i].interval = entity_list[prefab][i].interval - UPDATE_PERIOD if DEBUG then
print("[EventRegrowth] Removed ", i, "th" , prefab, " at ", entity_list[prefab][i].position, " from entity list - successfully respawned")
end
table.remove(entity_list[prefab], i)
else else
-- else set to 0 and regen -- decrease the interval
entity_list[prefab][i].interval = 0 if entity_list[prefab][i].interval > UPDATE_PERIOD then
end entity_list[prefab][i].interval = entity_list[prefab][i].interval - UPDATE_PERIOD
else
-- else set to 0 and regen
entity_list[prefab][i].interval = 0
end
if DEBUG then if DEBUG then
print("[EventRegrowth]", prefab, " at ", entity_list[prefab][i].position, " has interval ", entity_list[prefab][i].interval ) print("[EventRegrowth]", prefab, " at ", entity_list[prefab][i].position, " has interval ", entity_list[prefab][i].interval )
end end
if entity_list[prefab][i].interval == 0 then if entity_list[prefab][i].interval == 0 then
-- different threads -- different threads
inst:DoTaskInTime(delay, function() RegrowPrefabTask(prefab, entity_list[prefab][i].position) end) local data = entity_list[prefab][i]
inst:DoTaskInTime(delay, function() RegrowPrefabTask(prefab, data) end)
-- try not to flood the server with threads -- try not to flood the server with threads
count = count + 1 count = count + 1
if math.fmod( count,THREADS_PER_BATCH ) == 0 then if math.fmod( count,THREADS_PER_BATCH ) == 0 then
delay = delay + 1 delay = delay + 1
end
end end
end end
end end
@ -314,7 +319,7 @@ return Class(function(self, inst)
-- could be nil (set in the event loop) -- could be nil (set in the event loop)
data.entities[prefab] = {} data.entities[prefab] = {}
for i = 1, #entity_list[prefab] do for i = 1, #entity_list[prefab] do
data.entities[prefab][#data.entities[prefab] + 1] = {interval = entity_list[prefab][i].interval, position = entity_list[prefab][i].position} data.entities[prefab][#data.entities[prefab] + 1] = {interval = entity_list[prefab][i].interval, position = entity_list[prefab][i].position, remove = entity_list[prefab][i].remove}
end end
if DEBUG then if DEBUG then
print("[EventRegrowth] Saved ", #data.entities[prefab]," entities for ", prefab) print("[EventRegrowth] Saved ", #data.entities[prefab]," entities for ", prefab)
@ -329,7 +334,7 @@ return Class(function(self, inst)
if entity_list[prefab] == nil then if entity_list[prefab] == nil then
entity_list[prefab] = {} entity_list[prefab] = {}
for i = 1, #data.entities[prefab] do for i = 1, #data.entities[prefab] do
entity_list[prefab][#entity_list[prefab] + 1] = {interval = data.entities[prefab][i].interval, position = data.entities[prefab][i].position} entity_list[prefab][#entity_list[prefab] + 1] = {interval = data.entities[prefab][i].interval, position = data.entities[prefab][i].position, remove = data.entities[prefab][i].remove}
end end
if DEBUG then if DEBUG then
print("[EventRegrowth] Loaded ", #entity_list[prefab]," entities for ", prefab) print("[EventRegrowth] Loaded ", #entity_list[prefab]," entities for ", prefab)

View File

@ -241,8 +241,9 @@ return Class(function(self, inst)
end end
if intervals[prefab] == 0 then if intervals[prefab] == 0 then
local area = area_data[prefab]
-- use multiple threads? In the future a threadpool maybe? -- use multiple threads? In the future a threadpool maybe?
inst:DoTaskInTime(delay, function() RegrowPrefabTask(area_data[prefab], prefab) end) inst:DoTaskInTime(delay, function() RegrowPrefabTask(area, prefab) end)
-- try not to flood the server with threads -- try not to flood the server with threads
count = count + 1 count = count + 1
if math.fmod( count,THREADS_PER_BATCH ) == 0 then if math.fmod( count,THREADS_PER_BATCH ) == 0 then