Reoptimize some variables.
This commit is contained in:
parent
65a6df1e44
commit
fac68f46a5
4 changed files with 40 additions and 52 deletions
15
abms.lua
15
abms.lua
|
@ -21,19 +21,17 @@ local find_nodes_in_area = minetest.find_nodes_in_area
|
|||
local get_item_group = minetest.get_item_group
|
||||
|
||||
minetest.register_globalstep(function(dtime)
|
||||
local minp, maxp, counts
|
||||
local time = get_us_time()
|
||||
|
||||
if last_dps_check and time - last_dps_check < dps_delay then
|
||||
return
|
||||
end
|
||||
|
||||
local pos, factor, mob
|
||||
for _, mob in pairs(minetest.luaentities) do
|
||||
if not mob.initial_promotion then
|
||||
pos = mob.object:getpos()
|
||||
local pos = mob.object:getpos()
|
||||
if mob.hp_max and mob.object and mob.health and mob.damage then
|
||||
factor = 1 + (max(abs(pos.x), abs(pos.y), abs(pos.z)) / 6200)
|
||||
local factor = 1 + (max(abs(pos.x), abs(pos.y), abs(pos.z)) / 6200)
|
||||
if fun_caves.is_fortress(pos) then
|
||||
factor = factor * 1.5
|
||||
end
|
||||
|
@ -49,13 +47,12 @@ minetest.register_globalstep(function(dtime)
|
|||
end
|
||||
|
||||
local players = get_connected_players()
|
||||
local player
|
||||
for i = 1, #players do
|
||||
player = players[i]
|
||||
minp = vector.subtract(player:getpos(), 0.5)
|
||||
maxp = vector.add(player:getpos(), 0.5)
|
||||
local player = players[i]
|
||||
local minp = vector.subtract(player:getpos(), 0.5)
|
||||
local maxp = vector.add(player:getpos(), 0.5)
|
||||
|
||||
counts = find_nodes_in_area(minp, maxp, {"group:surface_hot"})
|
||||
local counts = find_nodes_in_area(minp, maxp, {"group:surface_hot"})
|
||||
if #counts > 1 then
|
||||
player:set_hp(player:get_hp() - 1)
|
||||
end
|
||||
|
|
|
@ -13,13 +13,11 @@ end
|
|||
plant_noise = {offset = 0.0, scale = 1.0, spread = {x = 200, y = 200, z = 200}, seed = 33, octaves = 3, persist = 0.7, lacunarity = 2.0}
|
||||
|
||||
local function surround(node, data, area, ivm)
|
||||
local n
|
||||
|
||||
-- Check to make sure that a plant root is fully surrounded.
|
||||
-- This is due to the kludgy way you have to make water plants
|
||||
-- in minetest, to avoid bubbles.
|
||||
for x1 = -1,1,2 do
|
||||
n = data[ivm+x1]
|
||||
local n = data[ivm+x1]
|
||||
if n == node("default:river_water_source") or n == node("default:water_source") or n == node("air") then
|
||||
return false
|
||||
end
|
||||
|
@ -68,7 +66,6 @@ function fun_caves.decorate_water(node, data, area, minp, maxp, pos, ivm, biome_
|
|||
return
|
||||
end
|
||||
|
||||
local posm, count
|
||||
for _, desc in pairs(fun_caves.water_plants) do
|
||||
if desc.content_id then
|
||||
if not node_match_cache[desc.content_id] then
|
||||
|
@ -80,7 +77,7 @@ function fun_caves.decorate_water(node, data, area, minp, maxp, pos, ivm, biome_
|
|||
-- against a given node (or nodes). However, it's slow.
|
||||
-- To speed it up, we cache the results for each plant
|
||||
-- on each node, and avoid calling find_nodes every time.
|
||||
posm, count = minetest.find_nodes_in_area(pos, pos, desc.place_on)
|
||||
local posm, count = minetest.find_nodes_in_area(pos, pos, desc.place_on)
|
||||
if #posm > 0 then
|
||||
node_match_cache[desc.content_id][data[ivm]] = "good"
|
||||
else
|
||||
|
|
29
fortress.lua
29
fortress.lua
|
@ -8,7 +8,6 @@
|
|||
fun_caves.fortress = function(node, data, area, minp, maxp, level)
|
||||
local n = 16
|
||||
local walls = {}
|
||||
local a, b, c, i, j, u, v, x, y, z, ivm, set, dox, doz
|
||||
local floor = node('fun_caves:dungeon_floor_1')
|
||||
local outer_wall = node('fun_caves:dungeon_wall_2')
|
||||
local inner_wall = node('fun_caves:dungeon_wall_1')
|
||||
|
@ -21,10 +20,10 @@ fun_caves.fortress = function(node, data, area, minp, maxp, level)
|
|||
end
|
||||
table.shuffle(walls)
|
||||
|
||||
dox, doz = math.random(0, n-1), math.random(0, n-1)
|
||||
local dox, doz = math.random(0, n-1), math.random(0, n-1)
|
||||
for z = minp.z, maxp.z do
|
||||
for y = minp.y + y2 * 5, minp.y + y2 * 5 + 4 do
|
||||
ivm = area:index(minp.x, y, z)
|
||||
local ivm = area:index(minp.x, y, z)
|
||||
for x = minp.x, maxp.x do
|
||||
if (y - minp.y) % 5 == 0 then
|
||||
if math.floor((z - minp.z) / 5) == doz and math.floor((x - minp.x) / 5) == dox and (z - minp.z) % 5 ~= 0 and (x - minp.x) % 5 ~= 0 and y ~= minp.y then
|
||||
|
@ -44,21 +43,21 @@ fun_caves.fortress = function(node, data, area, minp, maxp, level)
|
|||
end
|
||||
end
|
||||
|
||||
set = unionfind(n * n)
|
||||
local set = unionfind(n * n)
|
||||
|
||||
for m = 0, #walls do
|
||||
c = walls[m]
|
||||
a = math.floor(c / 2)
|
||||
i = a % n
|
||||
j = math.floor(a / n)
|
||||
u = c % 2 == 0 and 1 or 0
|
||||
v = c % 2 == 1 and 1 or 0
|
||||
b = a + u + n * v
|
||||
local c = walls[m]
|
||||
local a = math.floor(c / 2)
|
||||
local i = a % n
|
||||
local j = math.floor(a / n)
|
||||
local u = c % 2 == 0 and 1 or 0
|
||||
local v = c % 2 == 1 and 1 or 0
|
||||
local b = a + u + n * v
|
||||
if i < n - u and j < n - v and set:find(a) ~= set:find(b) then
|
||||
set:union(a, b)
|
||||
x = (i + u) * 5 + minp.x
|
||||
y = minp.y + y2 * 5
|
||||
z = (j + v) * 5 + minp.z
|
||||
local x = (i + u) * 5 + minp.x
|
||||
local y = minp.y + y2 * 5
|
||||
local z = (j + v) * 5 + minp.z
|
||||
--if y > minp.y and math.random(20) == 1 then
|
||||
-- for z1 = z + 1, z + 4 do
|
||||
-- ivm = area:index(x+1, y, z1)
|
||||
|
@ -71,7 +70,7 @@ fun_caves.fortress = function(node, data, area, minp, maxp, level)
|
|||
|
||||
for z1 = z + (1-v), z + (1-v) * 4 do
|
||||
for y1 = y + 1, y + 4 do
|
||||
ivm = area:index(x + (1-u), y1, z1)
|
||||
local ivm = area:index(x + (1-u), y1, z1)
|
||||
for x1 = x + (1-u), x + (1-u) * 4 do
|
||||
if x1 < maxp.x and z1 < maxp.z and x1 > minp.x and z1 > minp.z then
|
||||
data[ivm] = node("air")
|
||||
|
|
41
mapgen.lua
41
mapgen.lua
|
@ -29,7 +29,6 @@ local deco_depth = 30
|
|||
|
||||
local data = {}
|
||||
--local p2data = {} -- vm rotation data buffer
|
||||
local vm, emin, emax, area, noise_area, csize, minp, maxp, heightmap, biomemap
|
||||
|
||||
-- Create a table of biome ids, so I can use the biomemap.
|
||||
local biome_ids = {}
|
||||
|
@ -104,7 +103,7 @@ end
|
|||
-- end
|
||||
--end
|
||||
|
||||
fun_caves.is_fortress = function(pos)
|
||||
fun_caves.is_fortress = function(pos, csize)
|
||||
local cs = csize
|
||||
if not cs then
|
||||
-- Fix this to get csize, somehow.
|
||||
|
@ -131,15 +130,15 @@ end
|
|||
|
||||
|
||||
local function generate(p_minp, p_maxp, seed)
|
||||
minp, maxp = p_minp, p_maxp
|
||||
vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
|
||||
local minp, maxp = p_minp, p_maxp
|
||||
local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
|
||||
vm:get_data(data)
|
||||
--p2data = vm:get_param2_data()
|
||||
heightmap = minetest.get_mapgen_object("heightmap")
|
||||
biomemap = minetest.get_mapgen_object("biomemap")
|
||||
area = VoxelArea:new({MinEdge = emin, MaxEdge = emax})
|
||||
csize = vector.add(vector.subtract(maxp, minp), 1)
|
||||
noise_area = VoxelArea:new({MinEdge={x=0,y=0,z=0}, MaxEdge=vector.subtract(csize, 1)})
|
||||
local heightmap = minetest.get_mapgen_object("heightmap")
|
||||
local biomemap = minetest.get_mapgen_object("biomemap")
|
||||
local area = VoxelArea:new({MinEdge = emin, MaxEdge = emax})
|
||||
local csize = vector.add(vector.subtract(maxp, minp), 1)
|
||||
local noise_area = VoxelArea:new({MinEdge={x=0,y=0,z=0}, MaxEdge=vector.subtract(csize, 1)})
|
||||
|
||||
local write = false
|
||||
|
||||
|
@ -147,7 +146,7 @@ local function generate(p_minp, p_maxp, seed)
|
|||
math.randomseed(minetest.get_perlin(seed_noise):get2d({x=minp.x, y=minp.z}))
|
||||
|
||||
local fortress = maxp.y / 3100
|
||||
if fun_caves.is_fortress(minp) then
|
||||
if fun_caves.is_fortress(minp, csize) then
|
||||
fun_caves.fortress(node, data, area, minp, maxp, math.ceil(maxp.y / 3100))
|
||||
write = true
|
||||
else
|
||||
|
@ -156,7 +155,6 @@ local function generate(p_minp, p_maxp, seed)
|
|||
local cave_3 = minetest.get_perlin_map(cave_noise_3, {x=csize.x, y=csize.z}):get2dMap_flat({x=minp.x, y=minp.z})
|
||||
local biome_n = minetest.get_perlin_map(biome_noise, csize):get3dMap_flat(minp)
|
||||
|
||||
local ivm, ivm2, height, new_node
|
||||
|
||||
local index = 0
|
||||
local index3d = 0
|
||||
|
@ -164,9 +162,9 @@ local function generate(p_minp, p_maxp, seed)
|
|||
for x = minp.x, maxp.x do
|
||||
index = index + 1
|
||||
index3d = noise_area:index(x - minp.x, 0, z - minp.z)
|
||||
ivm = area:index(x, minp.y, z)
|
||||
local ivm = area:index(x, minp.y, z)
|
||||
|
||||
height = heightmap[index]
|
||||
local height = heightmap[index]
|
||||
if height >= maxp.y - 1 and data[area:index(x, maxp.y, z)] ~= node('air') then
|
||||
height = 31000
|
||||
heightmap[index] = height
|
||||
|
@ -182,7 +180,7 @@ local function generate(p_minp, p_maxp, seed)
|
|||
|
||||
if y > 0 and cave_3[index] < 1 and y == height then
|
||||
-- Clear the air above a cave mouth.
|
||||
ivm2 = ivm
|
||||
local ivm2 = ivm
|
||||
for y2 = y + 1, maxp.y + 8 do
|
||||
ivm2 = ivm2 + area.ystride
|
||||
if data[ivm2] ~= node("default:water_source") then
|
||||
|
@ -201,18 +199,17 @@ local function generate(p_minp, p_maxp, seed)
|
|||
-- Air needs to be placed prior to decorations.
|
||||
local index = 0
|
||||
local index3d = 0
|
||||
local pn, biome
|
||||
for z = minp.z, maxp.z do
|
||||
for x = minp.x, maxp.x do
|
||||
index = index + 1
|
||||
index3d = noise_area:index(x - minp.x, 0, z - minp.z)
|
||||
ivm = area:index(x, minp.y, z)
|
||||
local ivm = area:index(x, minp.y, z)
|
||||
|
||||
height = heightmap[index]
|
||||
local height = heightmap[index]
|
||||
|
||||
for y = minp.y, maxp.y do
|
||||
if y <= height - deco_depth and (height < 31000 or y < 0) then
|
||||
new_node = fun_caves.decorate_cave(node, data, area, minp, y, ivm, biome_n[index3d])
|
||||
local new_node = fun_caves.decorate_cave(node, data, area, minp, y, ivm, biome_n[index3d])
|
||||
if new_node then
|
||||
data[ivm] = new_node
|
||||
write = true
|
||||
|
@ -223,9 +220,9 @@ local function generate(p_minp, p_maxp, seed)
|
|||
write = true
|
||||
end
|
||||
else
|
||||
pn = minetest.get_perlin(plant_noise):get2d({x=x, y=z})
|
||||
biome = biome_ids[biomemap[index]]
|
||||
new_node = fun_caves.decorate_water(node, data, area, minp, maxp, {x=x,y=y,z=z}, ivm, biome, pn)
|
||||
local pn = minetest.get_perlin(plant_noise):get2d({x=x, y=z})
|
||||
local biome = biome_ids[biomemap[index]]
|
||||
local new_node = fun_caves.decorate_water(node, data, area, minp, maxp, {x=x,y=y,z=z}, ivm, biome, pn)
|
||||
if new_node then
|
||||
data[ivm] = new_node
|
||||
write = true
|
||||
|
@ -252,8 +249,6 @@ local function generate(p_minp, p_maxp, seed)
|
|||
vm:write_to_map()
|
||||
end
|
||||
|
||||
vm, area, noise_area, heightmap, biomemap = nil, nil, nil, nil, nil
|
||||
|
||||
-- Deal with memory issues. This, of course, is supposed to be automatic.
|
||||
if math.floor(collectgarbage("count")/1024) > 400 then
|
||||
print("Fun Caves: Manually collecting garbage...")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue