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