1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-03-17 20:58:13 +02:00

terrain generation performance fix

This commit is contained in:
MewMew 2019-09-14 03:00:43 +02:00
parent 4f3d870e0d
commit 9dee0c699b
5 changed files with 88 additions and 64 deletions

View File

@ -11,17 +11,9 @@ local event = require 'utils.event'
local function init_surface()
local map_gen_settings = {}
map_gen_settings.water = math.random(40, 60) * 0.01
map_gen_settings.starting_area = "2.5"
--map_gen_settings.cliff_settings = {cliff_elevation_interval = 12, cliff_elevation_0 = 32}
--map_gen_settings.property_expression_names = {
-- ["moisture"] = math.random(1, 100) * 0.01,
-- ["aux"] = math.random(1, 100) * 0.01,
-- ["temperature"] = math.random(1, 100) * 0.01,
--}
map_gen_settings.terrain_segmentation = math.random(50, 100) * 0.1
--map_gen_settings.terrain_segmentation = 10
map_gen_settings.water = math.random(30, 40) * 0.01
map_gen_settings.starting_area = 2.5
map_gen_settings.terrain_segmentation = math.random(30, 40) * 0.1
map_gen_settings.cliff_settings = {cliff_elevation_interval = math.random(8, 48), cliff_elevation_0 = math.random(8, 48)}
map_gen_settings.autoplace_controls = {
["coal"] = {frequency = math.random(10, 30) * 0.1, size = math.random(5, 15) * 0.1, richness = math.random(5, 15) * 0.1},
@ -31,7 +23,7 @@ local function init_surface()
["uranium-ore"] = {frequency = math.random(10, 20) * 0.1, size = math.random(5, 15) * 0.1, richness = math.random(5, 15) * 0.1},
["crude-oil"] = {frequency = math.random(15, 30) * 0.1, size = math.random(5, 15) * 0.1, richness = math.random(10, 20) * 0.1},
["trees"] = {frequency = math.random(5, 25) * 0.1, size = math.random(5, 15) * 0.1, richness = math.random(3, 10) * 0.1},
["enemy-base"] = {frequency = "256", size = "0.61", richness = "1"}
["enemy-base"] = {frequency = 256, size = 0.61, richness = 1}
}
game.create_surface("biter_battles", map_gen_settings)

View File

@ -90,6 +90,8 @@ local function on_player_joined_game(event)
poll_difficulty(player)
end
end
else
if player.gui.center["difficulty_poll"] then player.gui.center["difficulty_poll"].destroy() end
end
difficulty_gui()

View File

@ -48,7 +48,7 @@ local function annihilate_base_v2(center_pos, surface, force_name)
for y = -80, 80, 1 do
local pos = {x = center_pos.x + x, y = center_pos.y + y}
local distance_to_center = math.ceil(math.sqrt((pos.x - center_pos.x)^2 + (pos.y - center_pos.y)^2))
if distance_to_center < 42 and math.random(1,7) == 1 then
if distance_to_center < 35 and math.random(1,7) == 1 then
if not positions[distance_to_center] then positions[distance_to_center] = {} end
positions[distance_to_center][#positions[distance_to_center] + 1] = pos
end

View File

@ -64,7 +64,7 @@ local function process_chunk(surface)
local surface = game.surfaces["biter_battles"]
if not surface then return end
local force_chunk_requests = 2
local force_chunk_requests = 3
if bb_config.fast_pregen then force_chunk_requests = 16 end
for i = #global.chunk_gen_coords, 1, -1 do

View File

@ -45,6 +45,48 @@ local function get_noise(name, pos)
end
end
local function get_replacement_tile(surface, position)
for i = 1, 128, 1 do
local vectors = {{0, i}, {0, i * -1}, {i, 0}, {i * -1, 0}}
table.shuffle_table(vectors)
for k, v in pairs(vectors) do
local tile = surface.get_tile(position.x + v[1], position.y + v[2])
if not tile.collides_with("resource-layer") then
if tile.name ~= "stone-path" then
return tile.name
end
end
end
end
return "grass-1"
end
local function get_chunk_position(position)
local chunk_position = {}
position.x = math.floor(position.x, 0)
position.y = math.floor(position.y, 0)
for x = 0, 31, 1 do
if (position.x - x) % 32 == 0 then chunk_position.x = (position.x - x) / 32 end
end
for y = 0, 31, 1 do
if (position.y - y) % 32 == 0 then chunk_position.y = (position.y - y) / 32 end
end
return chunk_position
end
local function regenerate_decoratives(surface, position)
local chunk = get_chunk_position(position)
if not chunk then return end
surface.destroy_decoratives({area = {{chunk.x * 32, chunk.y * 32}, {chunk.x * 32 + 32, chunk.y * 32 + 32}}})
local decorative_names = {}
for k,v in pairs(game.decorative_prototypes) do
if v.autoplace_specification then
decorative_names[#decorative_names+1] = k
end
end
surface.regenerate_decorative(decorative_names, {chunk})
end
local function draw_noise_ore_patch(position, name, surface, radius, richness)
if not position then return end
if not name then return end
@ -90,18 +132,13 @@ function is_horizontal_border_river(pos)
end
local function generate_circle_spawn(event)
if event.area.left_top.y < -160 then return end
if event.area.left_top.x < -160 then return end
if event.area.left_top.x > 160 then return end
if global.bb_circle_spawn_generated then return end
--if bb_config.builders_area then
-- if event.area.left_top.x > 32 then return end
--end
local r = 101
local surface = event.surface
local surface = event.surface
if surface.is_chunk_generated({6, 6}) then global.bb_circle_spawn_generated = true end
local left_top_x = event.area.left_top.x
local left_top_y = event.area.left_top.y
local r = 101
for x = 0, 31, 1 do
for y = 0, 31, 1 do
local pos = {x = left_top_x + x, y = left_top_y + y}
@ -115,20 +152,19 @@ local function generate_circle_spawn(event)
end
if distance_to_center < 9.5 then tile = "refined-concrete" end
if distance_to_center < 7 then tile = "sand-1" end
if distance_to_center + noise < r - r * 0.5 and distance_to_center > spawn_circle_size and not is_horizontal_border_river(pos) then
if distance_to_center + noise < r - 10 and distance_to_center > spawn_circle_size and not is_horizontal_border_river(pos) then
local tile_name = surface.get_tile(pos).name
if tile_name == "water" or tile_name == "deepwater" then
surface.set_tiles({{name = "grass-2", position = pos}}, true)
surface.set_tiles({{name = "stone-path", position = pos}}, true)
surface.set_tiles({{name = get_replacement_tile(surface, pos), position = pos}}, true)
--surface.set_tiles({{name = "stone-path", position = pos}}, true)
--if math_random(1,256) == 1 then
-- local wrecks = {"big-ship-wreck-1", "big-ship-wreck-2", "big-ship-wreck-3"}
-- surface.create_entity({name = wrecks[math_random(1, #wrecks)], position = pos, force = "north"})
--end
if bb_config.random_scrap and math_random(1,64) == 1 then
surface.create_entity({name = "mineable-wreckage", position = pos})
end
--if bb_config.random_scrap and math_random(1,64) == 1 then
-- surface.create_entity({name = "mineable-wreckage", position = pos})
--end
end
end
@ -141,7 +177,7 @@ local function generate_circle_spawn(event)
end
if distance_to_center + noise < r - 4 and distance_to_center + noise > r - 6 then
if math_random(1,50) == 1 then
if math_random(1,56) == 1 then
if surface.can_place_entity({name = "gun-turret", position = pos}) then
local t = surface.create_entity({name = "gun-turret", position = pos, force = "north"})
t.insert({name = "firearm-magazine", count = math_random(6,12)})
@ -149,34 +185,35 @@ local function generate_circle_spawn(event)
end
end
if distance_to_center + noise < r - 3 and distance_to_center + noise > r - 7 then
if math_random(1,3) ~= 1 then
surface.set_tiles({{name = "stone-path", position = pos}}, true)
end
end
--if distance_to_center + noise < r - 3 and distance_to_center + noise > r - 7 then
--if math_random(1,3) ~= 1 then
--surface.set_tiles({{name = "stone-path", position = pos}}, true)
--end
--end
if distance_to_center + noise < r - 3 and distance_to_center + noise > r - 20 then
if math_random(1, 256) == 1 then
if surface.can_place_entity({name = "mineable-wreckage", position = pos}) then
surface.create_entity({name = "mineable-wreckage", position = pos, force = "neutral"})
end
end
end
--if distance_to_center + noise < r - 3 and distance_to_center + noise > r - 20 then
--if math_random(1, 256) == 1 then
--if surface.can_place_entity({name = "mineable-wreckage", position = pos}) then
--surface.create_entity({name = "mineable-wreckage", position = pos, force = "neutral"})
--end
--end
--end
end
end
end
regenerate_decoratives(surface, event.area.left_top)
end
local function generate_silos(event)
if global.bb_game_won_by_team then return end
if global.rocket_silo["north"] then
if global.rocket_silo["north"].valid then return end
end
if event.area.left_top.y > -128 then return end
if global.bb_silos_generated then return end
if event.area.left_top.x ~= -128 then return end
if event.area.left_top.y ~= -128 then return end
global.bb_silos_generated = true
local surface = event.surface
local pos = surface.find_non_colliding_position("rocket-silo", {0,-64}, 32, 1)
if not pos then pos = {x = 0, y = -64} end
local surface = event.surface
local pos = surface.find_non_colliding_position("rocket-silo", {x = -16 + math.random(0, 24), y = -64 + math.random(0, 16)}, 20, 1)
if not pos then pos = {0,-64} end
global.rocket_silo["north"] = surface.create_entity({
name = "rocket-silo",
position = pos,
@ -187,15 +224,10 @@ local function generate_silos(event)
for i = 1, 32, 1 do
create_tile_chain(surface, {name = "stone-path", position = global.rocket_silo["north"].position}, 32, 10)
end
for i = 1, 4, 1 do
create_tile_chain(surface, {name = "stone-path", position = global.rocket_silo["north"].position}, 48, 50)
end
end
local function generate_river(event)
if event.area.left_top.y < -64 then return end
if event.area.left_top.y < -32 then return end
local surface = event.surface
local left_top_x = event.area.left_top.x
local left_top_y = event.area.left_top.y
@ -241,10 +273,7 @@ local function rainbow_ore_and_ponds(event)
end
end
local function generate_potential_spawn_ore(event)
if event.area.left_top.x ~= -320 then return end
if event.area.left_top.y ~= -320 then return end
local surface = event.surface
local function generate_potential_spawn_ore(surface)
local r = 130
local area = {{r * -1, r * -1}, {r, 0}}
local ores = {}
@ -261,7 +290,7 @@ local function generate_potential_spawn_ore(event)
break
end
end
draw_noise_ore_patch(pos, ore, surface, math_random(18, 28), math_random(1500, 2500))
draw_noise_ore_patch(pos, ore, surface, math_random(18, 28), math_random(1000, 2000))
end
end
end
@ -397,7 +426,6 @@ local function on_chunk_generated(event)
rainbow_ore_and_ponds(event)
generate_river(event)
generate_circle_spawn(event)
generate_potential_spawn_ore(event)
generate_silos(event)
if bb_config.builders_area then
@ -416,6 +444,8 @@ local function on_chunk_generated(event)
end
if event.area.left_top.y == -320 and event.area.left_top.x == -320 then
generate_potential_spawn_ore(surface)
local area = {{-10,-10},{10,10}}
for _, e in pairs(surface.find_entities_filtered({area = area})) do
if e.name ~= "character" then e.destroy() end