update interval setting and optimization (> 0.1)

This commit is contained in:
Joey De Pauw 2019-12-06 19:40:51 +01:00
parent a3afe85909
commit 33dd2b9bfd
5 changed files with 57 additions and 46 deletions

View File

@ -1,4 +1,15 @@
--------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------
Version: 0.1.4
Date: 2019.11.16
Features:
- Improved performance thanks to Elrood (https://mods.factorio.com/mod/better-air-filtering/discussion/5de458a8b40f56000b3ca43c)
- Setting for update interval (can be changed for better UPS).
---------------------------------------------------------------------------------------------------
Version: 0.1.3
Date: 2019.11.16
Locale:
- EN for pollution filter fuel category.
---------------------------------------------------------------------------------------------------
Version: 0.1.2 Version: 0.1.2
Date: 2019.10.12 Date: 2019.10.12
Features: Features:

View File

@ -2,7 +2,7 @@
-- # Constants # -- # Constants #
-- ################# -- #################
local INTERVAL = 20 local INTERVAL = settings.global["baf-update-interval"].value
@ -104,45 +104,6 @@ end
-- # Update script # -- # Update script #
-- ##################### -- #####################
--function updateInserters(event)
--for _, surface in pairs(game.surfaces) do
-- local inserters = surface.find_entities_filtered({type="inserter"})
-- for _, inserter in pairs(inserters) do
-- updateInserter(inserter)
-- end
--end
--end
--function updateInserter(inserter)
--game.print(serpent.line(inserter.position))
--local drop_target = inserter.drop_target
--if drop_target == nil then return end
--local pickup_target = inserter.pickup_target
--if pickup_target == nil then return end
--local burnt_result_inventory = pickup_target.get_burnt_result_inventory()
--if burnt_result_inventory == nil then return end
--if burnt_result_inventory.is_empty() then return end
--if inserter.get_item_count() > 0 then return end
--
--
--local contents = burnt_result_inventory.get_contents()
--
--
--for item_name, count in pairs (contents) do
-- fuel_item_name = item_name
--end
--
--if inserter.get_item_count() < 1 then
-- if inserter.held_stack.valid_for_read == false then
-- if pickup_target.get_item_count(fuel_item_name) > 0 then
-- inserter.held_stack.set_stack({name = fuel_item_name, count = 1})
-- pickup_target.remove_item({name = fuel_item_name, count = 1})
-- return
-- end
-- end
--end
--end
function absorbPollution(event) function absorbPollution(event)
-- game.print("insertPollution") -- game.print("insertPollution")
@ -209,7 +170,7 @@ function suctionUpdateChunk(chunkTo, dx, dy)
local chunkFrom = getFilteredChunk(chunkTo.surface, chunkTo.x + dx, chunkTo.y + dy) local chunkFrom = getFilteredChunk(chunkTo.surface, chunkTo.x + dx, chunkTo.y + dy)
local test = chunkFrom:getTotalSuctionRate(0) local test = chunkFrom:getTotalSuctionRate(0)
local pollution = chunkFrom:get_pollution() local pollution = chunkFrom:get_pollution()
if pollution > 0 then if pollution > 0.1 then
local toPollute = math.min(pollution, totalSuction) local toPollute = math.min(pollution, totalSuction)
local chunksVia = {} local chunksVia = {}
for _, step in pairs(stepsToOrigin(dx, dy)) do for _, step in pairs(stepsToOrigin(dx, dy)) do
@ -270,6 +231,8 @@ end
function generateFunctions() function generateFunctions()
local functions = {} local functions = {}
table.insert(functions, function(event) game.print(event.tick) end)
table.insert(functions, absorbPollution) table.insert(functions, absorbPollution)
for radius = 1, 4 do for radius = 1, 4 do
@ -601,14 +564,14 @@ end
-- Set up callbacks -- Set up callbacks
script.on_event({ defines.events.on_built_entity, defines.events.on_robot_built_entity }, onEntityCreated) script.on_event({ defines.events.on_built_entity, defines.events.on_robot_built_entity }, onEntityCreated)
-- on_entity_died should trigger both functions -> called manually -- on_entity_died should trigger both functions -> called manually
script.on_event({ defines.events.on_player_mined_entity, defines.events.on_robot_mined_entity, defines.events.on_entity_died }, onEntityRemoved) script.on_event({ defines.events.on_player_mined_entity, defines.events.on_robot_mined_entity, defines.events.on_entity_died }, onEntityRemoved)
script.on_event({ defines.events.on_pre_player_mined_item, defines.events.on_pre_robot_mined_item, defines.events.on_entity_died }, preEntityRemoved) script.on_event({ defines.events.on_pre_player_mined_item, defines.events.on_pre_robot_mined_item, defines.events.on_entity_died }, preEntityRemoved)
local functions = generateFunctions() functions = generateFunctions()
local onTick = spreadOverTicks(functions, INTERVAL) local onTick = spreadOverTicks(functions, INTERVAL)
script.on_event(defines.events.on_tick, onTick) script.on_event(defines.events.on_tick, onTick)
@ -617,5 +580,17 @@ script.on_init(init)
script.on_configuration_changed(init) script.on_configuration_changed(init)
function onSettingsChanged(event)
game.print("Settings changed")
game.print(serpent.line(event))
INTERVAL = settings.global["baf-update-interval"].value
game.print("Interval: " .. INTERVAL)
local onTick = spreadOverTicks(functions, INTERVAL)
script.on_event(defines.events.on_tick, onTick)
end
script.on_event(defines.events.on_runtime_mod_setting_changed, onSettingsChanged)

View File

@ -1,6 +1,6 @@
{ {
"name": "better-air-filtering", "name": "better-air-filtering",
"version": "0.1.2", "version": "0.1.4",
"title": "Better Air Filtering", "title": "Better Air Filtering",
"author": "Joey De Pauw", "author": "Joey De Pauw",
"contact": "joeydepauw@gmail.com", "contact": "joeydepauw@gmail.com",
@ -9,7 +9,8 @@
"dependencies": [ "dependencies": [
"base >= 0.17", "base >= 0.17",
"!air-filtering", "!air-filtering",
"!NauvisDay" "!NauvisDay",
"!CW-carbon-capture"
], ],
"description": "An overhaul of the air filtering mod by Schorty. Includes complex air filtering steps to remove pollution." "description": "An overhaul of the air filtering mod by Schorty. Includes complex air filtering steps to remove pollution."
} }

View File

@ -17,6 +17,10 @@ liquid-filter=Liquid filter
used-liquid-filter=Used liquid filter used-liquid-filter=Used liquid filter
[fuel-category-name]
pollution-filter=Air filter
[fluid-name] [fluid-name]
pollution=Pollution pollution=Pollution
polluted-water=Polluted Water polluted-water=Polluted Water
@ -29,6 +33,7 @@ filter-air-expendable=Filter air
liquid-pollution=Condense pollution liquid-pollution=Condense pollution
air-filter-recycling=Recycle used air filter air-filter-recycling=Recycle used air filter
[technology-name] [technology-name]
air-filtering=Air filtering air-filtering=Air filtering
air-filter-recycling=Recycle used air filters air-filter-recycling=Recycle used air filters
@ -39,4 +44,13 @@ air-filtering-1=Enables the crafting of passive Air Filter Machines to improve a
air-filtering-2=A stronger air filter that uses electricity to pull pollution towards it from a 2 chunk radius. air-filtering-2=A stronger air filter that uses electricity to pull pollution towards it from a 2 chunk radius.
air-filtering-3=An even stronger air filter, capable of cleaning pollution in a 3 chunk radius. air-filtering-3=An even stronger air filter, capable of cleaning pollution in a 3 chunk radius.
reusable-air-filters=More strudy air filters that can be recycled with future technology. reusable-air-filters=More strudy air filters that can be recycled with future technology.
air-filter-recycling=Used air filters can be reused after being recycled by using a bit of coal to refill them. air-filter-recycling=Used air filters can be reused after being recycled by using a bit of coal to refill them.
[mod-setting-name]
baf-update-interval=Update interval
[mod-setting-description]
baf-update-interval=Updates are implemented efficiently and are spread over an UPDATE INTERVAL amount of ticks. The default of 20 gives three updates per second. 30 would result in 2 updates per second for example.

View File

@ -0,0 +1,10 @@
data:extend({
{
type = "int-setting",
name = "baf-update-interval",
setting_type = "runtime-global",
minimum_value = 5,
maximum_value = 120,
default_value = 20
}
})