1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2024-12-14 10:13:13 +02:00

Small optimizations

This commit is contained in:
Lynn 2018-11-06 18:48:38 +01:00
parent bee981f367
commit e132765537
6 changed files with 36 additions and 30 deletions

View File

@ -43,7 +43,7 @@ function AlienSpawner.register(config)
local x = event.old_tile.position.x local x = event.old_tile.position.x
local y = event.old_tile.position.y local y = event.old_tile.position.y
if (x^2 + y^2 < alien_minimum_distance_square or config.alien_probability < random()) then if (x * x + y * y < alien_minimum_distance_square or config.alien_probability < random()) then
return return
end end

View File

@ -144,7 +144,7 @@ local function spawn_cracking_sound_text(surface, position)
local color = { local color = {
r = 1, r = 1,
g = random(1, 100) / 100, g = random(1, 100) * 0.01,
b = 0 b = 0
} }
@ -157,7 +157,7 @@ local function spawn_cracking_sound_text(surface, position)
name = 'flying-text', name = 'flying-text',
color = color, color = color,
text = char, text = char,
position = {x = position.x + x_offset, y = position.y - ((i + 1) % 2) / 4} position = {x = position.x + x_offset, y = position.y - ((i + 1) % 2) * 0.25}
}.active = true }.active = true
end end
end end
@ -416,8 +416,8 @@ end
@return number sum of old fraction + new fraction @return number sum of old fraction + new fraction
]] ]]
local function add_fraction(stress_map, x, y, fraction) local function add_fraction(stress_map, x, y, fraction)
x = 2 * floor(x / 2) x = 2 * floor(x * 0.5)
y = 2 * floor(y / 2) y = 2 * floor(y * 0.5)
local x_t = stress_map[x] local x_t = stress_map[x]
if not x_t then if not x_t then
@ -519,7 +519,7 @@ function mask_init(config)
disc_weight = config.mask_relative_ring_weights[2] disc_weight = config.mask_relative_ring_weights[2]
center_weight = config.mask_relative_ring_weights[3] center_weight = config.mask_relative_ring_weights[3]
radius = floor(n / 2) radius = floor(n * 0.5)
radius_sq = (radius + 0.2) * (radius + 0.2) radius_sq = (radius + 0.2) * (radius + 0.2)
center_radius_sq = radius_sq / 9 center_radius_sq = radius_sq / 9

View File

@ -167,7 +167,7 @@ end
local function on_research_finished(event) local function on_research_finished(event)
local force = game.forces.player local force = game.forces.player
local current_modifier = mining_efficiency.research_modifier local current_modifier = mining_efficiency.research_modifier
local new_modifier = force.mining_drill_productivity_bonus * config.mining_speed_productivity_multiplier / 2 local new_modifier = force.mining_drill_productivity_bonus * config.mining_speed_productivity_multiplier * 0.5
if (current_modifier == new_modifier) then if (current_modifier == new_modifier) then
-- something else was researched -- something else was researched
@ -236,16 +236,10 @@ local function redraw_heading(data)
local frame = data.market_list_heading local frame = data.market_list_heading
Gui.clear(frame) Gui.clear(frame)
local heading_table = frame.add {type = 'table', column_count = 3} local heading_table = frame.add({type = 'table', column_count = 3})
apply_heading_style(heading_table.add({type = 'label', name = tag_label_stone, caption = 'Name'}).style, 90)
local label = heading_table.add {type = 'label', name = tag_label_stone, caption = 'Name'} apply_heading_style(heading_table.add({type = 'label', name = tag_label_buff, caption = 'Buff'}).style, 200)
apply_heading_style(label.style, 90) apply_heading_style(heading_table.add({type = 'label', name = tag_label_item, caption = 'Item'}).style, 200)
local label = heading_table.add {type = 'label', name = tag_label_buff, caption = 'Buff'}
apply_heading_style(label.style, 200)
local label = heading_table.add {type = 'label', name = tag_label_item, caption = 'Item'}
apply_heading_style(label.style, 200)
end end
local function redraw_progressbar(data) local function redraw_progressbar(data)
@ -260,8 +254,7 @@ local function redraw_progressbar(data)
-- calc % of stones sent -- calc % of stones sent
local stone_sent = stone_tracker.stone_sent_to_surface / highest_amount local stone_sent = stone_tracker.stone_sent_to_surface / highest_amount
local overall_descr = flow.add({type = 'label', name = 'Diggy.MarketExchange.Frame.Progress.Overall', caption = 'Overall progress:'}) apply_heading_style(flow.add({type = 'label', name = 'Diggy.MarketExchange.Frame.Progress.Overall', caption = 'Overall progress:'}).style)
apply_heading_style(overall_descr.style)
local overall_progressbar = flow.add({type = 'progressbar', tooltip = stone_sent * 100 .. '% stone sent'}) local overall_progressbar = flow.add({type = 'progressbar', tooltip = stone_sent * 100 .. '% stone sent'})
overall_progressbar.style.width = 540 overall_progressbar.style.width = 540
overall_progressbar.value = stone_sent overall_progressbar.value = stone_sent
@ -276,15 +269,13 @@ local function redraw_progressbar(data)
local sent = stone_tracker.stone_sent_to_surface - act_stone local sent = stone_tracker.stone_sent_to_surface - act_stone
local percentage = sent / range local percentage = sent / range
local level_descr = flow.add({type = 'label', name = 'Diggy.MarketExchange.Frame.Progress.Level', caption = 'Progress to next level:'}) apply_heading_style(flow.add({type = 'label', name = 'Diggy.MarketExchange.Frame.Progress.Level', caption = 'Progress to next level:'}).style)
apply_heading_style(level_descr.style)
local level_progressbar = flow.add({type = 'progressbar', tooltip = percentage * 100 .. '% stone to next level'}) local level_progressbar = flow.add({type = 'progressbar', tooltip = percentage * 100 .. '% stone to next level'})
level_progressbar.style.width = 540 level_progressbar.style.width = 540
level_progressbar.value = percentage level_progressbar.value = percentage
end end
local function redraw_table(data) local function redraw_table(data)
local market_scroll_pane = data.market_scroll_pane local market_scroll_pane = data.market_scroll_pane
Gui.clear(market_scroll_pane) Gui.clear(market_scroll_pane)
@ -302,7 +293,6 @@ local function redraw_table(data)
-- create table -- create table
for i = 1, #config.unlockables do for i = 1, #config.unlockables do
if config.unlockables[i].stone ~= last_stone then if config.unlockables[i].stone ~= last_stone then
-- get items and buffs for each stone value -- get items and buffs for each stone value
@ -370,7 +360,6 @@ local function redraw_table(data)
-- print table -- print table
for _, unlockable in pairs(row) do for _, unlockable in pairs(row) do
local is_unlocked = unlockable[1] <= stone_tracker.stone_sent_to_surface local is_unlocked = unlockable[1] <= stone_tracker.stone_sent_to_surface
local list = market_scroll_pane.add {type = 'table', column_count = 3 } local list = market_scroll_pane.add {type = 'table', column_count = 3 }
list.style.horizontal_spacing = 16 list.style.horizontal_spacing = 16
@ -447,7 +436,6 @@ local function toggle(event)
frame = center.add({name = 'Diggy.MarketExchange.Frame', type = 'frame', direction = 'vertical'}) frame = center.add({name = 'Diggy.MarketExchange.Frame', type = 'frame', direction = 'vertical'})
local market_progressbars = frame.add({type = 'flow', direction = 'vertical'}) local market_progressbars = frame.add({type = 'flow', direction = 'vertical'})
local market_list_heading = frame.add({type = 'flow', direction = 'horizontal'}) local market_list_heading = frame.add({type = 'flow', direction = 'horizontal'})
local market_scroll_pane = frame.add({type = 'scroll-pane'}) local market_scroll_pane = frame.add({type = 'scroll-pane'})

View File

@ -4,6 +4,7 @@
-- dependencies -- dependencies
local Event = require 'utils.event' local Event = require 'utils.event'
local Global = require 'utils.global'
local Debug = require 'map_gen.Diggy.Debug' local Debug = require 'map_gen.Diggy.Debug'
local Template = require 'map_gen.Diggy.Template' local Template = require 'map_gen.Diggy.Template'
local Perlin = require 'map_gen.shared.perlin_noise' local Perlin = require 'map_gen.shared.perlin_noise'
@ -15,6 +16,14 @@ local floor = math.floor
-- this -- this
local ScatteredResources = {} local ScatteredResources = {}
local seed
Global.register({
seed = seed,
}, function(tbl)
seed = tbl.seed
end)
local function get_name_by_random(collection) local function get_name_by_random(collection)
local pre_calculated = random() local pre_calculated = random()
local current = 0 local current = 0
@ -66,7 +75,7 @@ function ScatteredResources.register(config)
end end
local function get_noise(surface, x, y) local function get_noise(surface, x, y)
local seed = surface.map_gen_settings.seed + surface.index + 100 seed = seed or surface.map_gen_settings.seed + surface.index + 200
return Perlin.noise(x * config.noise_variance, y * config.noise_variance, seed) return Perlin.noise(x * config.noise_variance, y * config.noise_variance, seed)
end end

View File

@ -6,6 +6,7 @@
local Template = require 'map_gen.Diggy.Template' local Template = require 'map_gen.Diggy.Template'
local Perlin = require 'map_gen.shared.perlin_noise' local Perlin = require 'map_gen.shared.perlin_noise'
local Event = require 'utils.event' local Event = require 'utils.event'
local Global = require 'utils.global'
local Debug = require'map_gen.Diggy.Debug' local Debug = require'map_gen.Diggy.Debug'
local Task = require 'utils.Task' local Task = require 'utils.Task'
local Token = require 'utils.global_token' local Token = require 'utils.global_token'
@ -13,6 +14,14 @@ local Token = require 'utils.global_token'
-- this -- this
local SimpleRoomGenerator = {} local SimpleRoomGenerator = {}
local seed
Global.register({
seed = seed,
}, function(tbl)
seed = tbl.seed
end)
local do_spawn_tile = Token.register(function(params) local do_spawn_tile = Token.register(function(params)
Template.insert(params.surface, {params.tile}, {}) Template.insert(params.surface, {params.tile}, {})
end) end)
@ -54,7 +63,7 @@ function SimpleRoomGenerator.register(config)
local room_noise_minimum_distance_sq = config.room_noise_minimum_distance * config.room_noise_minimum_distance local room_noise_minimum_distance_sq = config.room_noise_minimum_distance * config.room_noise_minimum_distance
local function get_noise(surface, x, y) local function get_noise(surface, x, y)
local seed = surface.map_gen_settings.seed + surface.index + 200 seed = seed or surface.map_gen_settings.seed + surface.index + 100
return Perlin.noise(x * config.noise_variance, y * config.noise_variance, seed) return Perlin.noise(x * config.noise_variance, y * config.noise_variance, seed)
end end
@ -63,7 +72,7 @@ function SimpleRoomGenerator.register(config)
local x = position.x local x = position.x
local y = position.y local y = position.y
local distance_sq = x^2 + y^2 local distance_sq = x * x + y * y
if (distance_sq <= room_noise_minimum_distance_sq) then if (distance_sq <= room_noise_minimum_distance_sq) then
return return

View File

@ -40,9 +40,9 @@ function StartingZone.register(config)
local tiles = {} local tiles = {}
local rocks = {} local rocks = {}
local dirt_range = floor(starting_zone_size / 2) local dirt_range = floor(starting_zone_size * 0.5)
local rock_range = starting_zone_size - 2 local rock_range = starting_zone_size - 2
local stress_hack = floor(starting_zone_size / 10) local stress_hack = floor(starting_zone_size * 0.1)
for x = -starting_zone_size, starting_zone_size do for x = -starting_zone_size, starting_zone_size do
for y = -starting_zone_size, starting_zone_size do for y = -starting_zone_size, starting_zone_size do