Skip to content

Commit

Permalink
mods/predict-rain: significant performance improvements
Browse files Browse the repository at this point in the history
The latest beta introduces persistent global map icons throughout the
entirety of the rift's lifespan, which can be used to efficiently
simulate lunar hail level.

Currently, only a single rift is supported at this time, as there does
not seem to be a way to determine what global map icons originate from.
Thus, a moonlens brought to a rift could trick the implemented logic
into thinking it is the rift portal.

An array of rifts and periodic turf checks can be used to mitigate this,
at the cost of potential performance. However, this would still be
insignificant compared to the high cost of the previous method.
  • Loading branch information
Crestwave committed Mar 12, 2024
1 parent e5c98e2 commit 1959465
Showing 1 changed file with 17 additions and 51 deletions.
68 changes: 17 additions & 51 deletions mods/predict-rain/modmain.lua
Original file line number Diff line number Diff line change
Expand Up @@ -189,59 +189,25 @@ Modes: 0 for global chat, 1 for whisper chat, 2 for local chat.
})

if GetModConfigData("predicthail") then
local lunarrift = nil

AddPrefabPostInit("globalmapicon", function(inst)
inst:DoTaskInTime(0, function(inst)
if (lunarrift == nil or not lunarrift:IsValid()) and
_G.TheWorld:HasTag("forest") and
_G.TheWorld.Map:GetTileAtPoint(inst.Transform:GetWorldPosition()) then
lunarrift = inst
end
end)
end)

AddPrefabPostInit("world", function(inst)
inst:DoTaskInTime(1, function(inst)
if inst:HasTag("forest") then
local GOOD_ARENA_SQUARE_SIZE = 6
local w, h = inst.Map:GetSize()

w = w * _G.TILE_SCALE / 2
h = h * _G.TILE_SCALE / 2

local tiles = {}
local cache = false
local time = 0
local pt = nil

for x=-w,w,4 do
for y=-h,h,4 do
if inst.Map:IsAboveGroundInSquare(x, 0, y, GOOD_ARENA_SQUARE_SIZE, inst.Map.IsTileLandNoDocks) then
table.insert(tiles, _G.Vector3(x, 0, y))
end
end
inst:DoTaskInTime(0, function(inst)
inst.components.riftspawner = {
IsLunarPortalActive = function()
return lunarrift ~= nil and lunarrift:IsValid()
end

inst.components.riftspawner = {
IsLunarPortalActive = function()
if cache then
if inst.Map:GetTileAtPoint(pt:Get()) ~= _G.WORLD_TILES.RIFT_MOON then
cache = false
time = _G.GetTime()
pt = nil
return false
else
return true
end
else
if _G.GetTime() - time < 1 then
return false
end

for k, v in pairs(tiles) do
if inst.Map:GetTileAtPoint(v:Get()) == _G.WORLD_TILES.RIFT_MOON then
cache = true
time = _G.GetTime()
pt = v
return true
end
end

time = _G.GetTime()
return false
end
end
}
end
}
end)
end)

Expand Down

0 comments on commit 1959465

Please sign in to comment.