Add better color settings

This commit is contained in:
Wuzzy 2022-04-20 16:47:58 +02:00
parent feddf7273f
commit 77645e6667
2 changed files with 29 additions and 14 deletions

View File

@ -1,22 +1,33 @@
-- If true, the Perlin test nodes will support color -- If true, the Perlin test nodes will support color
-- (set to false in case of performance problems) -- (set to false in case of performance problems)
local colorize_nodes = minetest.settings:get_bool("perlin_explorer_colorize", true) local COLORIZE_NODES = true
-- If true, will use the grayscale color palette. -- If true, will use the grayscale color palette.
-- If false, will use the default colors. -- If false, will use the default colors.
local grayscale_colors = minetest.settings:get_bool("perlin_explorer_grayscale", false) local grayscale_colors = minetest.settings:get_bool("perlin_explorer_grayscale", false)
-- The number of available test node colors is divided by this number. -- The number of available test node colors.
-- A number between 1 to 256 -- Higher values lead to worse performance but a coarse color scheme.
-- * 1 = Full 256 palette.
-- * 2 = 128 colors.
-- * 4 = 64 colors.
-- etc.
-- Higher values lead to less colors but increased performance.
-- This value is only used for performance reason, because Minetest -- This value is only used for performance reason, because Minetest
-- has a sharp performance drop when there are many different node colors on screen. -- has a sharp performance drop when there are many different node colors on screen.
-- Consider removing this one when Minetest's performance problem has been solved. -- Consider removing this one when Minetest's performance problem has been solved.
local COLOR_PRECISION = 4 local color_count = tonumber(minetest.settings:get("perlin_explorer_color_count")) or 64
local color_lookup = {
[256] = 1, -- full color palette
[128] = 2,
[64] = 4,
[32] = 8,
[16] = 16,
[8] = 32,
[4] = 64,
[2] = 128,
[1] = 256,
}
-- This value is used for the calculation of the simplified color.
local color_precision = color_lookup[color_count]
if not color_precision then
color_precision = 4 -- default: 64 colors
end
-- Time to wait in seconds before checking and generating new nodes in autobuild mode. -- Time to wait in seconds before checking and generating new nodes in autobuild mode.
local AUTOBUILD_UPDATE_TIME = 0.1 local AUTOBUILD_UPDATE_TIME = 0.1
@ -271,7 +282,7 @@ end)
-- Test nodes to generate a map based on a perlin noise -- Test nodes to generate a map based on a perlin noise
local paramtype2, palette local paramtype2, palette
if colorize_nodes then if COLORIZE_NODES then
paramtype2 = "color" paramtype2 = "color"
end end
if grayscale_colors then if grayscale_colors then
@ -625,7 +636,7 @@ local update_map = function(pos, noise, noiseparams, options, stats_mode)
node_param2 = math.floor(math.abs(node_param2)) node_param2 = math.floor(math.abs(node_param2))
node_param2 = math.max(0, math.min(255, node_param2)) node_param2 = math.max(0, math.min(255, node_param2))
if node_param2 < 255 then if node_param2 < 255 then
node_param2 = node_param2 - (node_param2 % COLOR_PRECISION) node_param2 = node_param2 - (node_param2 % color_precision)
end end
end end

View File

@ -1,6 +1,10 @@
# If enabled, generated nodes will be colorized. # Number of available colors to use per node color palette,
# Disable this if you have performance problems. # ignoring the special “extreme” colors (which are always used).
perlin_explorer_colorize_nodes (Colorize nodes) bool true # High values lead to a smoother color gradient but also might
# cause performance issues when viewing many nodes.
# Note you need to regenerate the nodes for this change to
# take effect.
perlin_explorer_color_count (Palette color count) enum 64 256,128,64,32,16,8,4,2,1
# If enabled, will use the grayscale color palette for the nodes. # If enabled, will use the grayscale color palette for the nodes.
# If disabled, will use the default colors instead. # If disabled, will use the default colors instead.