Debug commit: added debug markers to show nearby liquid corners

This commit is contained in:
WillConker 2024-06-09 09:19:49 +01:00
parent 6898aa919c
commit a8d5831bf7
2 changed files with 164 additions and 0 deletions

View File

@ -151,3 +151,136 @@ local function move_centre(pos, realpos, node, radius)
end
flowlib.move_centre = move_centre
--BEGIN getCornerLevel
local function get_corner_level(x, z, cur_liquid, neighbors)
local sum = 0
local count = 0
local air_count = 0
for dz=0,1 do
for dx=0,1 do
local neighbor_data = neighbors[z + dz][x + dx]
if neighbor_data.top_is_same_liquid then
minetest.debug("Full liquid at corner:", x + dx - 2, z + dz - 2)
return 0.5 --- REPLACE returns
end
if neighbor_data.content == cur_liquid.c_source then
minetest.debug("Full liquid at corner:", x + dx - 2, z + dz - 2)
return 0.5
end
if neighbor_data.content == cur_liquid.c_flowing then
sum = sum + neighbor_data.level
count = count + 1
elseif neighbor_data.content == "air" then
air_count = air_count + 1
end
end
end
if air_count >= 2 then
return -0.5 + (0.2/10)
end
if count > 0 then
return sum/count
end
return 0
end
--END getCornerLevel
-- Based on https://github.com/minetest/minetest/blob/master/src/client/content_mapblock.cpp#L536-L813
local function get_liquid_corner_heights(pos)
local cur_liquid = {}
local node = get_node(pos)
local ndef = registered_nodes[node.name]
if not (get_item_group(node.name, "liquid") > 0) then return end
local node_above = get_node({x=pos.x, y=pos.y+1, z=pos.z})
local node_below = get_node({x=pos.x, y=pos.y+1, z=pos.z})
-- BEGIN prepareLiquidNodeDrawing
cur_liquid.content = node.name
cur_liquid.c_flowing = ndef.liquid_alternative_flowing
cur_liquid.c_source = ndef.liquid_alternative_source
minetest.debug("liquid forms", cur_liquid.c_flowing, cur_liquid.c_source)
cur_liquid.top_is_same_liquid = (node_above.name == cur_liquid.c_flowing or node_above.name == cur_liquid.c_source)
-- cur_liquid.draw_bottom and lighting skipped
-- END prepareLiquidNodeDrawing
local c_flowing_ndef = registered_nodes[cur_liquid.c_flowing]
minetest.debug("c_flowing_ndef", c_flowing_ndef)
--BEGIN getLiquidNeighborhood
local range = math.max(1, math.min(c_flowing_ndef.liquid_range, 8))
local neighbors = {
{{}, {}, {}},
{{}, {}, {}},
{{}, {}, {}},
}
for w = -1,1 do
for u = -1,1 do
neighbor = neighbors[w+2][u+2]
local neighbor_node = get_node({x=pos.x + u, y=pos.y, z=pos.z + w})
neighbor.content = neighbor_node.name
neighbor.level = -0.5
neighbor.is_same_liquid = false
neighbor.top_is_same_liquid = false
if neighbor.content == cur_liquid.c_source then
neighbor.is_same_liquid = true
neighbor.level = 0.5
elseif neighbor.content == cur_liquid.c_flowing then
neighbor.is_same_liquid = true
local liquid_level = bit.band(neighbor_node.param2, 7)
if liquid_level <= (8 - range) then
liquid_level = 0
else
liquid_level = liquid_level - (8 - range)
end
neighbor.level = (-0.5 + (liquid_level + 0.5) / range)
end
if neighbor.content ~= "ignore" then
local above_neighbor_node = get_node({x=pos.x + u, y=pos.y + 1, z=pos.z + w})
if above_neighbor_node.name == cur_liquid.c_source or above_neighbor_node.name == cur_liquid.c_flowing then
neighbor.top_is_same_liquid = true
end
end
end
end
--END getLiquidNeighborhood
cur_liquid.corner_levels = {{}, {}}
--BEGIN calculateCornerLevels
for z=1,2 do
for x=1,2 do
cur_liquid.corner_levels[z][x] = get_corner_level(x, z, cur_liquid, neighbors)
end
end
--END calculateCornerLevels
--BEGIN drawLiquidTop
local corner_resolve = {{0, 1}, {1, 1}, {1, 0}, {0, 0}}
local vertices = {
{x=-5, y=0, z= 5},
{x= 5, y=0, z= 5},
{x= 5, y=0, z=-5},
{x=-5, y=0, z=-5},
}
for i=1,4 do
local u = corner_resolve[i][1]
local w = corner_resolve[i][2]
if cur_liquid.top_is_same_liquid then
vertices[i].y = 0.5 * 10
else
vertices[i].y = vertices[i].y + cur_liquid.corner_levels[w+1][u+1] * 10
end
end
--first 3 vertices are connected, so are last 3
--END drawLiquidTop
return vertices
end
flowlib.get_liquid_corner_heights = get_liquid_corner_heights

View File

@ -61,6 +61,26 @@ local function get_player_nodes(player)
infotable.node_stand = node_ok(part_pos).name
part_pos = get_playerpart_pos("head", player_pos, collisionbox, eye_height)
local lch = flowlib.get_liquid_corner_heights(part_pos)
--infotable.debug_markers = mcl_playerinfo[player:get_player_name()].debug_markers
--minetest.debug("Debug markers: ", infotable.debug_markers)
if lch then
minetest.debug("current liquid corner heights: ", "-+", lch[1].y , "++", lch[2].y , "+-", lch[3].y , "--", lch[4].y)
end
for i,v in ipairs(minetest.get_objects_inside_radius(player_pos, 2)) do
if (v:get_luaentity() or {}).name == "mcl_playerinfo:debug_marker" then
v:remove()
end
end
for i=1,4 do
--if infotable.debug_markers[i] ~= nil then infotable.debug_markers[i]:remove() end
if lch then
minetest.add_entity(vector.add(vector.round(part_pos), vector.divide(lch[i], 10)), "mcl_playerinfo:debug_marker")
end
end
infotable.node_head = node_ok(part_pos).name
part_pos = get_playerpart_pos("head_top", player_pos, collisionbox, eye_height)
@ -75,6 +95,14 @@ local function get_player_nodes(player)
return infotable
end
minetest.register_entity("mcl_playerinfo:debug_marker", { initial_properties = {
visual = "sprite",
textures = {"mcl_crimson_warped_fence_top.png"},
pointable = true,
visual_size = {x = 0.1, y = 0.1, z = 0.1},
}})
minetest.register_globalstep(function(dtime)
time = time + dtime
@ -92,6 +120,7 @@ minetest.register_globalstep(function(dtime)
for _,player in pairs(minetest.get_connected_players()) do
local name = player:get_player_name()
minetest.debug("mcl_playerinfo", name)
mcl_playerinfo[name] = get_player_nodes(player)
end
@ -113,6 +142,8 @@ minetest.register_on_joinplayer(function(player)
ndef_stand_below = "",
ndef_head_top = "",
}
mcl_playerinfo[name].debug_markers = {}
minetest.debug("Player info cleared")
end)