Enhance network state management: skip broadcasting if state has not changed and update state version on configuration changes

This commit is contained in:
MayaTheShy
2026-03-22 01:41:44 -04:00
parent 1198c2e73a
commit d80b0b155e

View File

@@ -3423,10 +3423,12 @@ local function main()
end
end,
-- Task 10: Network state broadcast
-- Task 10: Network state broadcast (skips if nothing changed)
function()
while true do
pcall(broadcastState)
if stateVersion ~= lastBroadcastVersion then
pcall(broadcastState)
end
sleep(BROADCAST_INTERVAL)
end
end,
@@ -3471,6 +3473,7 @@ local function main()
pcall(broadcastState)
elseif message.type == "scan" then
print("[NET] Scan request from client")
configDirty = true -- resend full config after scan
pcall(refreshCache)
pcall(checkAlerts)
needsRedraw = true
@@ -3480,6 +3483,7 @@ local function main()
smeltingPaused = not smeltingPaused
print("[NET] Smelting " .. (smeltingPaused and "PAUSED" or "RESUMED"))
saveDisabledRecipes()
bumpStateVersion()
smelterNeedsRedraw = true
needsRedraw = true
pcall(broadcastState)
@@ -3491,12 +3495,16 @@ local function main()
end
print("[NET] Recipe toggle: " .. message.recipe)
saveDisabledRecipes()
configDirty = true
bumpStateVersion()
smelterNeedsRedraw = true
pcall(broadcastState)
elseif message.type == "enable_all" then
disabledRecipes = {}
print("[NET] All recipes enabled")
saveDisabledRecipes()
configDirty = true
bumpStateVersion()
smelterNeedsRedraw = true
pcall(broadcastState)
elseif message.type == "disable_all" then
@@ -3505,6 +3513,8 @@ local function main()
end
print("[NET] All recipes disabled")
saveDisabledRecipes()
configDirty = true
bumpStateVersion()
smelterNeedsRedraw = true
pcall(broadcastState)
elseif message.type == "sort_barrel" and message.barrelName then