More optimization, add constants file for eventual descructible scenery.

This commit is contained in:
Anna Rose Wiggins 2019-12-09 16:51:15 -05:00
parent 130c393c51
commit 3a9fac53f0
5 changed files with 52 additions and 6 deletions

View file

@ -2,8 +2,6 @@
function init_mapgen()
uid_seed = 2229 -- arbitrarily chosen number
-- block_size = 64
-- biome_size = 128
-- Metadata for different biomes
-- frequencies don't have to add up to 100, but they should by convention
@ -36,7 +34,7 @@ function init_mapgen()
local biome = biome_list[i]
-- add the biome's name N times to the biome metadata 'hat'
for i=1,biome_data[biome]["biome_frequency"] do
for i=1,biome_data[biome].biome_frequency do
add(biome_metadata, biome)
end
@ -47,7 +45,7 @@ end
-- build the lookup table for a given biome, based on the biome_meta data for
-- that string.
function build_biome(biome_name, data)
local meta_frequencies = data["tile_frequencies"]
local meta_frequencies = data.tile_frequencies
local tile_lookup = {}
for i=1,#meta_frequencies do
@ -57,7 +55,7 @@ function build_biome(biome_name, data)
end
end
data["tile_lookup"] = tile_lookup
data.tile_lookup = tile_lookup
end
-- generates a unique identifier for a position
@ -90,7 +88,7 @@ function get_tile(pos_x, pos_y)
local biome = biome_data[biome_name]
local uid = generate_uid(pos_x, pos_y)
return biome["tile_lookup"][(uid % #biome["tile_lookup"]) + 1]
return biome.tile_lookup[(uid % #biome.tile_lookup) + 1]
end
-- generate the map and writes to the map area from 0 - block_size,