This commit is contained in:
Maksim Gamarnik 2016-04-21 13:20:11 +03:00
commit 966f919a4c
11 changed files with 298 additions and 357 deletions

View File

@ -182,6 +182,10 @@ end
-- Down first as likely case, but always before self. The same with sides.
-- Up must come last, so that things above self will also fall all at once.
local nodeupdate_neighbors = {
{x = -1, y = -1, z = 0},
{x = 1, y = -1, z = 0},
{x = 0, y = -1, z = -1},
{x = 0, y = -1, z = 1},
{x = 0, y = -1, z = 0},
{x = -1, y = 0, z = 0},
{x = 1, y = 0, z = 0},
@ -226,10 +230,10 @@ function nodeupdate(p)
n = n - 1
-- If there's nothing left on the stack, and no
-- more sides to walk to, we're done and can exit
if n == 0 and v == 7 then
if n == 0 and v == 11 then
return
end
until v < 7
until v < 11
-- The next round walk the next neighbor in list.
v = v + 1
else

View File

@ -6,7 +6,7 @@
local jobs = {}
local time = 0.0
local last = 0.0
local last = core.get_us_time() / 1000000
core.register_globalstep(function(dtime)
local new = core.get_us_time() / 1000000

View File

@ -22,8 +22,7 @@ menudata = {}
--------------------------------------------------------------------------------
-- Local cached values
--------------------------------------------------------------------------------
local min_supp_proto
local max_supp_proto
local min_supp_proto, max_supp_proto
function common_update_cached_supp_proto()
min_supp_proto = core.get_min_supp_proto()
@ -36,31 +35,24 @@ common_update_cached_supp_proto()
--------------------------------------------------------------------------------
local function render_client_count(n)
if n > 99 then
return '99+'
elseif n >= 0 then
return tostring(n)
else
return '?'
end
if n > 99 then return '99+'
elseif n >= 0 then return tostring(n)
else return '?' end
end
local function configure_selected_world_params(idx)
local worldconfig = modmgr.get_worldconfig(
menudata.worldlist:get_list()[idx].path)
if worldconfig.creative_mode ~= nil then
local worldconfig = modmgr.get_worldconfig(menudata.worldlist:get_list()[idx].path)
if worldconfig.creative_mode then
core.setting_set("creative_mode", worldconfig.creative_mode)
end
if worldconfig.enable_damage ~= nil then
if worldconfig.enable_damage then
core.setting_set("enable_damage", worldconfig.enable_damage)
end
end
--------------------------------------------------------------------------------
function image_column(tooltip, flagname)
return "image," ..
"tooltip=" .. core.formspec_escape(tooltip) .. "," ..
return "image,tooltip=" .. core.formspec_escape(tooltip) .. "," ..
"0=" .. core.formspec_escape(defaulttexturedir .. "blank.png") .. "," ..
"1=" .. core.formspec_escape(defaulttexturedir .. "server_flags_" .. flagname .. ".png")
end
@ -69,13 +61,13 @@ end
function order_favorite_list(list)
local res = {}
--orders the favorite list after support
for i=1,#list,1 do
for i = 1, #list do
local fav = list[i]
if is_server_protocol_compat(fav.proto_min, fav.proto_max) then
res[#res + 1] = fav
end
end
for i=1,#list,1 do
for i = 1, #list do
local fav = list[i]
if not is_server_protocol_compat(fav.proto_min, fav.proto_max) then
res[#res + 1] = fav
@ -85,60 +77,44 @@ function order_favorite_list(list)
end
--------------------------------------------------------------------------------
function render_favorite(spec,render_details)
function render_favorite(spec, is_favorite)
local text = ""
if spec.name ~= nil then
if spec.name then
text = text .. core.formspec_escape(spec.name:trim())
-- if spec.description ~= nil and
-- core.formspec_escape(spec.description):trim() ~= "" then
-- text = text .. " (" .. core.formspec_escape(spec.description) .. ")"
-- end
else
if spec.address ~= nil then
elseif spec.address then
text = text .. spec.address:trim()
if spec.port ~= nil then
if spec.port then
text = text .. ":" .. spec.port
end
end
end
if not render_details then
return text
end
local details = ""
local grey_out = not is_server_protocol_compat(spec.proto_min, spec.proto_max)
if spec.clients ~= nil and spec.clients_max ~= nil then
if is_favorite then
details = "1,"
else
details = "0,"
end
if spec.clients and spec.clients_max then
local clients_color = ''
local clients_percent = 100 * spec.clients / spec.clients_max
-- Choose a color depending on how many clients are connected
-- (relatively to clients_max)
if spec.clients == 0 then
clients_color = '' -- 0 players: default/white
elseif spec.clients == spec.clients_max then
clients_color = '#dd5b5b' -- full server: red (darker)
elseif clients_percent <= 60 then
clients_color = '#a1e587' -- 0-60%: green
elseif clients_percent <= 90 then
clients_color = '#ffdc97' -- 60-90%: yellow
else
clients_color = '#ffba97' -- 90-100%: orange
if grey_out then clients_color = '#aaaaaa'
elseif spec.clients == 0 then clients_color = '' -- 0 players: default/white
elseif clients_percent <= 60 then clients_color = '#a1e587' -- 0-60%: green
elseif clients_percent <= 90 then clients_color = '#ffdc97' -- 60-90%: yellow
elseif clients_percent == 100 then clients_color = '#dd5b5b' -- full server: red (darker)
else clients_color = '#ffba97' -- 90-100%: orange
end
if grey_out then
clients_color = '#aaaaaa'
end
details = details ..
clients_color .. ',' ..
render_client_count(spec.clients) .. ',' ..
'/,' ..
details = details .. clients_color .. ',' ..
render_client_count(spec.clients) .. ',/,' ..
render_client_count(spec.clients_max) .. ','
elseif grey_out then
details = details .. '#aaaaaa,?,/,?,'
else
@ -189,14 +165,10 @@ end
--------------------------------------------------------------------------------
function menu_render_worldlist()
local retval = ""
local current_worldlist = menudata.worldlist:get_list()
for i,v in ipairs(current_worldlist) do
if retval ~= "" then
retval = retval ..","
end
for i, v in ipairs(current_worldlist) do
if retval ~= "" then retval = retval .. "," end
retval = retval .. core.formspec_escape(v.name) .. ""
end
@ -204,40 +176,24 @@ function menu_render_worldlist()
end
--------------------------------------------------------------------------------
function menu_handle_key_up_down(fields,textlist,settingname)
if fields["key_up"] then
local oldidx = core.get_textlist_index(textlist)
if oldidx ~= nil and oldidx > 1 then
local newidx = oldidx -1
core.setting_set(settingname,
menudata.worldlist:get_raw_index(newidx))
configure_selected_world_params(newidx)
function menu_handle_key_up_down(fields, textlist, settingname)
local oldidx, newidx = core.get_textlist_index(textlist)
if fields.key_up or fields.key_down then
if fields.key_up and oldidx and oldidx > 1 then
newidx = oldidx - 1
elseif fields.key_down and oldidx and
oldidx < menudata.worldlist:size() then
newidx = oldidx + 1
end
core.setting_set(settingname, menudata.worldlist:get_raw_index(newidx))
configure_selected_world_params(newidx)
return true
end
if fields["key_down"] then
local oldidx = core.get_textlist_index(textlist)
if oldidx ~= nil and oldidx < menudata.worldlist:size() then
local newidx = oldidx + 1
core.setting_set(settingname,
menudata.worldlist:get_raw_index(newidx))
configure_selected_world_params(newidx)
end
return true
end
return false
end
--------------------------------------------------------------------------------
function asyncOnlineFavourites()
if not menudata.public_known then
menudata.public_known = {{
name = fgettext("Loading..."),
@ -245,43 +201,37 @@ function asyncOnlineFavourites()
}}
end
menudata.favorites = menudata.public_known
menudata.favorites_is_public = true
core.handle_async(
function(param)
return core.get_favorites("online")
end,
nil,
function(result)
if core.setting_getbool("public_serverlist") then
local favs = order_favorite_list(result)
if favs[1] then
menudata.public_known = favs
menudata.favorites = menudata.public_known
menudata.favorites_is_public = true
end
core.event_handler("Refresh")
end
end
)
end
--------------------------------------------------------------------------------
function text2textlist(xpos,ypos,width,height,tl_name,textlen,text,transparency)
local textlines = core.splittext(text,textlen)
function text2textlist(xpos, ypos, width, height, tl_name, textlen, text, transparency)
local textlines = core.splittext(text, textlen)
local retval = "textlist[" .. xpos .. "," .. ypos .. ";" .. width ..
"," .. height .. ";" .. tl_name .. ";"
local retval = "textlist[" .. xpos .. "," .. ypos .. ";"
.. width .. "," .. height .. ";"
.. tl_name .. ";"
for i=1, #textlines, 1 do
textlines[i] = textlines[i]:gsub("\r","")
for i = 1, #textlines do
textlines[i] = textlines[i]:gsub("\r", "")
retval = retval .. core.formspec_escape(textlines[i]) .. ","
end
retval = retval .. ";0;"
if transparency then
retval = retval .. "true"
end
if transparency then retval = retval .. "true" end
retval = retval .. "]"
return retval
@ -294,14 +244,16 @@ end
--------------------------------------------------------------------------------
function is_server_protocol_compat_or_error(server_proto_min, server_proto_max)
if not is_server_protocol_compat(server_proto_min, server_proto_max) then
local server_prot_ver_info
local client_prot_ver_info
if server_proto_min ~= server_proto_max then
local server_prot_ver_info, client_prot_ver_info
local s_p_min = server_proto_min or 13
local s_p_max = server_proto_max or 24
if s_p_min ~= s_p_max then
server_prot_ver_info = fgettext_ne("Server supports protocol versions between $1 and $2. ",
server_proto_min or 13, server_proto_max or 24)
s_p_min, s_p_max)
else
server_prot_ver_info = fgettext_ne("Server enforces protocol version $1. ",
server_proto_min or 13)
s_p_min)
end
if min_supp_proto ~= max_supp_proto then
client_prot_ver_info= fgettext_ne("We support protocol versions between version $1 and $2.",
@ -324,7 +276,7 @@ function menu_worldmt(selected, setting, value)
local filename = world.path .. DIR_DELIM .. "world.mt"
local world_conf = Settings(filename)
if value ~= nil then
if value then
if not world_conf:write() then
core.log("error", "Failed to write world config file")
end
@ -342,7 +294,7 @@ function menu_worldmt_legacy(selected)
local modes_names = {"creative_mode", "enable_damage", "server_announce"}
for _, mode_name in pairs(modes_names) do
local mode_val = menu_worldmt(selected, mode_name)
if mode_val ~= nil then
if mode_val then
core.setting_set(mode_name, mode_val)
else
menu_worldmt(selected, mode_name, core.setting_get(mode_name))

View File

@ -20,45 +20,35 @@ local function get_formspec(tabview, name, tabdata)
-- Update the cached supported proto info,
-- it may have changed after a change by the settings menu.
common_update_cached_supp_proto()
local render_details = core.is_yes(core.setting_getbool("public_serverlist"))
local fav_selected = menudata.favorites[tabdata.fav_selected]
local retval =
"label[7.75,-0.15;" .. fgettext("Address / Port :") .. "]" ..
"label[7.75,1.05;" .. fgettext("Name / Password :") .. "]" ..
"field[8,0.75;3.4,0.5;te_address;;" ..
"label[7.75,-0.15;" .. fgettext("Address / Port") .. "]" ..
"label[7.75,1.05;" .. fgettext("Name / Password") .. "]" ..
"field[8,0.75;3.3,0.5;te_address;;" ..
core.formspec_escape(core.setting_get("address")) .. "]" ..
"field[11.25,0.75;1.3,0.5;te_port;;" ..
"field[11.15,0.75;1.4,0.5;te_port;;" ..
core.formspec_escape(core.setting_get("remote_port")) .. "]" ..
"checkbox[0,4.85;cb_public_serverlist;" .. fgettext("Public Serverlist") .. ";" ..
dump(core.setting_getbool("public_serverlist")) .. "]"
if not core.setting_getbool("public_serverlist") then
retval = retval ..
"button[8,4.9;2,0.5;btn_delete_favorite;" .. fgettext("Delete") .. "]"
end
retval = retval ..
"button[10,4.9;2,0.5;btn_mp_connect;" .. fgettext("Connect") .. "]" ..
"button[10.1,4.9;2,0.5;btn_mp_connect;" .. fgettext("Connect") .. "]" ..
"field[8,1.95;2.95,0.5;te_name;;" ..
core.formspec_escape(core.setting_get("name")) .. "]" ..
"pwdfield[10.78,1.95;1.77,0.5;te_pwd;]" ..
"box[7.73,2.35;4.3,2.28;#999999]" ..
"textarea[8.1,2.4;4.26,2.6;;"
"box[7.73,2.35;4.3,2.28;#999999]"
if tabdata.fav_selected ~= nil and
menudata.favorites[tabdata.fav_selected] ~= nil and
menudata.favorites[tabdata.fav_selected].description ~= nil then
retval = retval ..
core.formspec_escape(menudata.favorites[tabdata.fav_selected].description,true)
if tabdata.fav_selected and fav_selected then
if gamedata.fav then
retval = retval .. "button[7.85,4.9;2.3,0.5;btn_delete_favorite;" ..
fgettext("Del. Favorite") .. "]"
end
if fav_selected.description then
retval = retval .. "textarea[8.1,2.4;4.26,2.6;;" ..
core.formspec_escape((gamedata.serverdescription or ""), true) .. ";]"
end
end
retval = retval ..
";]"
--favourites
if render_details then
retval = retval .. "tablecolumns[" ..
image_column(fgettext("Favorite"), "favorite") .. ";" ..
"color,span=3;" ..
"text,align=right;" .. -- clients
"text,align=center,padding=0.25;" .. -- "/"
@ -67,22 +57,31 @@ local function get_formspec(tabview, name, tabdata)
image_column(fgettext("Damage enabled"), "damage") .. ",padding=0.25;" ..
image_column(fgettext("PvP enabled"), "pvp") .. ",padding=0.25;" ..
"color,span=1;" ..
"text,padding=1]" -- name
else
retval = retval .. "tablecolumns[text]"
end
retval = retval ..
"table[-0.15,-0.1;7.75,5;favourites;"
"text,padding=1]" ..
"table[-0.15,-0.1;7.75,5.5;favourites;"
if #menudata.favorites > 0 then
retval = retval .. render_favorite(menudata.favorites[1],render_details)
for i=2,#menudata.favorites,1 do
retval = retval .. "," .. render_favorite(menudata.favorites[i],render_details)
local favs = core.get_favorites("local")
if #favs > 0 then
for i = 1, #favs do
for j = 1, #menudata.favorites do
if menudata.favorites[j].address == favs[i].address and
menudata.favorites[j].port == favs[i].port then
table.insert(menudata.favorites, i, table.remove(menudata.favorites, j))
end
end
if favs[i].address ~= menudata.favorites[i].address then
table.insert(menudata.favorites, i, favs[i])
end
end
end
retval = retval .. render_favorite(menudata.favorites[1], (#favs > 0))
for i = 2, #menudata.favorites do
retval = retval .. "," .. render_favorite(menudata.favorites[i], (i <= #favs))
end
end
if tabdata.fav_selected ~= nil then
if tabdata.fav_selected then
retval = retval .. ";" .. tabdata.fav_selected .. "]"
else
retval = retval .. ";0]"
@ -93,36 +92,38 @@ end
--------------------------------------------------------------------------------
local function main_button_handler(tabview, fields, name, tabdata)
if fields["te_name"] ~= nil then
gamedata.playername = fields["te_name"]
core.setting_set("name", fields["te_name"])
if fields.te_name then
gamedata.playername = fields.te_name
core.setting_set("name", fields.te_name)
end
if fields["favourites"] ~= nil then
local event = core.explode_table_event(fields["favourites"])
if fields.favourites then
local event = core.explode_table_event(fields.favourites)
local fav = menudata.favorites[event.row]
if event.type == "DCL" then
if event.row <= #menudata.favorites then
if not is_server_protocol_compat_or_error(menudata.favorites[event.row].proto_min,
menudata.favorites[event.row].proto_max) then
if menudata.favorites_is_public and
not is_server_protocol_compat_or_error(
fav.proto_min, fav.proto_max) then
return true
end
gamedata.address = menudata.favorites[event.row].address
gamedata.port = menudata.favorites[event.row].port
gamedata.playername = fields["te_name"]
if fields["te_pwd"] ~= nil then
gamedata.password = fields["te_pwd"]
end
gamedata.address = fav.address
gamedata.port = fav.port
gamedata.playername = fields.te_name
gamedata.selected_world = 0
if menudata.favorites ~= nil then
gamedata.servername = menudata.favorites[event.row].name
gamedata.serverdescription = menudata.favorites[event.row].description
if fields.te_pwd then
gamedata.password = fields.te_pwd
end
if gamedata.address ~= nil and
gamedata.port ~= nil then
core.setting_set("address",gamedata.address)
core.setting_set("remote_port",gamedata.port)
gamedata.servername = fav.name
gamedata.serverdescription = fav.description
if gamedata.address and gamedata.port then
core.setting_set("address", gamedata.address)
core.setting_set("remote_port", gamedata.port)
core.start()
end
end
@ -131,101 +132,92 @@ local function main_button_handler(tabview, fields, name, tabdata)
if event.type == "CHG" then
if event.row <= #menudata.favorites then
local address = menudata.favorites[event.row].address
local port = menudata.favorites[event.row].port
gamedata.fav = false
local favs = core.get_favorites("local")
local address = fav.address
local port = fav.port
gamedata.serverdescription = fav.description
if address ~= nil and
port ~= nil then
core.setting_set("address",address)
core.setting_set("remote_port",port)
for i = 1, #favs do
if fav.address == favs[i].address and
fav.port == favs[i].port then
gamedata.fav = true
end
end
if address and port then
core.setting_set("address", address)
core.setting_set("remote_port", port)
end
tabdata.fav_selected = event.row
end
return true
end
end
if fields["key_up"] ~= nil or
fields["key_down"] ~= nil then
if fields.key_up or fields.key_down then
local fav_idx = core.get_table_index("favourites")
local fav = menudata.favorites[fav_idx]
if fav_idx ~= nil then
if fields["key_up"] ~= nil and fav_idx > 1 then
fav_idx = fav_idx -1
else if fields["key_down"] and fav_idx < #menudata.favorites then
fav_idx = fav_idx +1
end end
if fav_idx then
if fields.key_up and fav_idx > 1 then
fav_idx = fav_idx - 1
elseif fields.key_down and fav_idx < #menudata.favorites then
fav_idx = fav_idx + 1
end
else
fav_idx = 1
end
if menudata.favorites == nil or
menudata.favorites[fav_idx] == nil then
if not menudata.favorites or not fav then
tabdata.fav_selected = 0
return true
end
local address = menudata.favorites[fav_idx].address
local port = menudata.favorites[fav_idx].port
local address = fav.address
local port = fav.port
if address ~= nil and
port ~= nil then
core.setting_set("address",address)
core.setting_set("remote_port",port)
if address and port then
core.setting_set("address", address)
core.setting_set("remote_port", port)
end
tabdata.fav_selected = fav_idx
return true
end
if fields["cb_public_serverlist"] ~= nil then
core.setting_set("public_serverlist", fields["cb_public_serverlist"])
if core.setting_getbool("public_serverlist") then
asyncOnlineFavourites()
else
menudata.favorites = core.get_favorites("local")
end
tabdata.fav_selected = nil
return true
end
if fields["btn_delete_favorite"] ~= nil then
if fields.btn_delete_favorite then
local current_favourite = core.get_table_index("favourites")
if current_favourite == nil then return end
if not current_favourite then return end
core.delete_favorite(current_favourite)
menudata.favorites = order_favorite_list(core.get_favorites())
asyncOnlineFavourites()
tabdata.fav_selected = nil
core.setting_set("address","")
core.setting_set("remote_port","30000")
core.setting_set("address", "")
core.setting_set("remote_port", "30000")
return true
end
if (fields["btn_mp_connect"] ~= nil or
fields["key_enter"] ~= nil) and fields["te_address"] ~= nil and
fields["te_port"] ~= nil then
gamedata.playername = fields["te_name"]
gamedata.password = fields["te_pwd"]
gamedata.address = fields["te_address"]
gamedata.port = fields["te_port"]
if (fields.btn_mp_connect or fields.key_enter) and fields.te_address and fields.te_port then
gamedata.playername = fields.te_name
gamedata.password = fields.te_pwd
gamedata.address = fields.te_address
gamedata.port = fields.te_port
gamedata.selected_world = 0
local fav_idx = core.get_table_index("favourites")
local fav = menudata.favorites[fav_idx]
if fav_idx ~= nil and fav_idx <= #menudata.favorites and
menudata.favorites[fav_idx].address == fields["te_address"] and
menudata.favorites[fav_idx].port == fields["te_port"] then
if fav_idx and fav_idx <= #menudata.favorites and
fav.address == fields.te_address and
fav.port == fields.te_port then
gamedata.servername = menudata.favorites[fav_idx].name
gamedata.serverdescription = menudata.favorites[fav_idx].description
gamedata.servername = fav.name
gamedata.serverdescription = fav.description
if not is_server_protocol_compat_or_error(menudata.favorites[fav_idx].proto_min,
menudata.favorites[fav_idx].proto_max)then
if menudata.favorites_is_public and
not is_server_protocol_compat_or_error(
fav.proto_min, fav.proto_max) then
return true
end
else
@ -233,10 +225,8 @@ local function main_button_handler(tabview, fields, name, tabdata)
gamedata.serverdescription = ""
end
gamedata.selected_world = 0
core.setting_set("address", fields["te_address"])
core.setting_set("remote_port",fields["te_port"])
core.setting_set("address", fields.te_address)
core.setting_set("remote_port", fields.te_port)
core.start()
return true
@ -244,15 +234,9 @@ local function main_button_handler(tabview, fields, name, tabdata)
return false
end
local function on_change(type,old_tab,new_tab)
if type == "LEAVE" then
return
end
if core.setting_getbool("public_serverlist") then
local function on_change(type, old_tab, new_tab)
if type == "LEAVE" then return end
asyncOnlineFavourites()
else
menudata.favorites = core.get_favorites("local")
end
end
--------------------------------------------------------------------------------

View File

@ -179,7 +179,7 @@ function mm_texture.set_dirt_bg()
end
end
--use base pack
-- Use universal fallback texture in textures/base/pack
local minimalpath = defaulttexturedir .. "bg.png"
core.set_background("background", minimalpath, true, 128)
end

View File

@ -34,9 +34,13 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <cerrno>
#include <cstring>
const int BUFFER_LENGTH = 256;
class StringBuffer : public std::streambuf {
public:
StringBuffer() {}
StringBuffer() {
buffer_index = 0;
}
int overflow(int c);
virtual void flush(const std::string &buf) = 0;
@ -44,7 +48,8 @@ public:
void push_back(char c);
private:
std::string buffer;
char buffer[BUFFER_LENGTH];
int buffer_index;
};
@ -338,11 +343,18 @@ std::streamsize StringBuffer::xsputn(const char *s, std::streamsize n)
void StringBuffer::push_back(char c)
{
if (c == '\n' || c == '\r') {
if (!buffer.empty())
flush(buffer);
buffer.clear();
if (buffer_index)
flush(std::string(buffer, buffer_index));
buffer_index = 0;
} else {
buffer.push_back(c);
int index = buffer_index;
buffer[index++] = c;
if (index >= BUFFER_LENGTH) {
flush(std::string(buffer, buffer_index));
buffer_index = 0;
} else {
buffer_index = index;
}
}
}

View File

@ -59,6 +59,8 @@ MapgenV7::MapgenV7(int mapgenid, MapgenParams *params, EmergeManager *emerge)
//// amount of elements to skip for the next index
//// for noise/height/biome maps (not vmanip)
this->ystride = csize.X;
// 1-up 1-down overgeneration
this->zstride_1u1d = csize.X * (csize.Y + 2);
// 1-down overgeneration
this->zstride_1d = csize.X * (csize.Y + 1);
@ -263,10 +265,13 @@ void MapgenV7::makeChunk(BlockMakeData *data)
// Make some noise
calculateNoise();
// Generate base terrain, mountains, and ridges with initial heightmaps
// Generate terrain and ridges with initial heightmaps
s16 stone_surface_max_y = generateTerrain();
// Create heightmap
if (spflags & MGV7_RIDGES)
generateRidgeTerrain();
// Update heightmap to include mountain terrain
updateHeightmap(node_min, node_max);
// Create biomemap at heightmap surface
@ -361,6 +366,11 @@ void MapgenV7::calculateNoise()
noise_terrain_alt->perlinMap2D(x, z, persistmap);
noise_height_select->perlinMap2D(x, z);
if (spflags & MGV7_MOUNTAINS) {
noise_mountain->perlinMap3D(x, y, z);
noise_mount_height->perlinMap2D(x, z);
}
if ((spflags & MGV7_RIDGES) && node_max.Y >= water_level) {
noise_ridge->perlinMap3D(x, y, z);
noise_ridge_uwater->perlinMap2D(x, z);
@ -369,9 +379,6 @@ void MapgenV7::calculateNoise()
// Cave noises are calculated in generateCaves()
// only if solid terrain is present in mapchunk
// Mountain noises are calculated in generateMountainTerrain()
// only if solid terrain surface dips into mapchunk
noise_filler_depth->perlinMap2D(x, z);
noise_heat->perlinMap2D(x, z);
noise_humidity->perlinMap2D(x, z);
@ -400,7 +407,7 @@ Biome *MapgenV7::getBiomeAtPoint(v3s16 p)
return bmgr->getBiome(heat, humidity, groundlevel);
}
//needs to be updated
float MapgenV7::baseTerrainLevelAtPoint(s16 x, s16 z)
{
float hselect = NoisePerlin2D(&noise_height_select->np, x, z, seed);
@ -455,100 +462,55 @@ bool MapgenV7::getMountainTerrainFromMap(int idx_xyz, int idx_xz, s16 y)
int MapgenV7::generateTerrain()
{
s16 stone_surface_min_y;
s16 stone_surface_max_y;
generateBaseTerrain(&stone_surface_min_y, &stone_surface_max_y);
if ((spflags & MGV7_MOUNTAINS) && stone_surface_min_y < node_max.Y)
stone_surface_max_y = generateMountainTerrain(stone_surface_max_y);
if (spflags & MGV7_RIDGES)
generateRidgeTerrain();
return stone_surface_max_y;
}
void MapgenV7::generateBaseTerrain(s16 *stone_surface_min_y, s16 *stone_surface_max_y)
{
MapNode n_air(CONTENT_AIR);
MapNode n_stone(c_stone);
MapNode n_water(c_water_source);
v3s16 em = vm->m_area.getExtent();
s16 surface_min_y = MAX_MAP_GENERATION_LIMIT;
s16 surface_max_y = -MAX_MAP_GENERATION_LIMIT;
u32 index = 0;
s16 stone_surface_max_y = -MAX_MAP_GENERATION_LIMIT;
u32 index2d = 0;
bool mountain_flag = spflags & MGV7_MOUNTAINS;
for (s16 z = node_min.Z; z <= node_max.Z; z++)
for (s16 x = node_min.X; x <= node_max.X; x++, index++) {
float surface_height = baseTerrainLevelFromMap(index);
s16 surface_y = (s16)surface_height;
for (s16 x = node_min.X; x <= node_max.X; x++, index2d++) {
s16 surface_y = baseTerrainLevelFromMap(index2d);
heightmap[index2d] = surface_y; // Create base terrain heightmap
ridge_heightmap[index2d] = surface_y;
heightmap[index] = surface_y;
ridge_heightmap[index] = surface_y;
if (surface_y < surface_min_y)
surface_min_y = surface_y;
if (surface_y > surface_max_y)
surface_max_y = surface_y;
if (surface_y > stone_surface_max_y)
stone_surface_max_y = surface_y;
u32 vi = vm->m_area.index(x, node_min.Y - 1, z);
u32 index3d = (z - node_min.Z) * zstride_1u1d + (x - node_min.X);
for (s16 y = node_min.Y - 1; y <= node_max.Y + 1; y++) {
if (vm->m_data[vi].getContent() == CONTENT_IGNORE) {
if (y <= surface_y)
vm->m_data[vi] = n_stone;
else if (y <= water_level)
if (y <= surface_y) {
vm->m_data[vi] = n_stone; // Base terrain
} else if (mountain_flag &&
getMountainTerrainFromMap(index3d, index2d, y)) {
vm->m_data[vi] = n_stone; // Mountain terrain
if (y > stone_surface_max_y)
stone_surface_max_y = y;
} else if (y <= water_level) {
vm->m_data[vi] = n_water;
else
} else {
vm->m_data[vi] = n_air;
}
}
vm->m_area.add_y(em, vi, 1);
index3d += ystride;
}
}
*stone_surface_min_y = surface_min_y;
*stone_surface_max_y = surface_max_y;
}
int MapgenV7::generateMountainTerrain(s16 ymax)
{
noise_mountain->perlinMap3D(node_min.X, node_min.Y - 1, node_min.Z);
noise_mount_height->perlinMap2D(node_min.X, node_min.Z);
MapNode n_stone(c_stone);
u32 j = 0;
for (s16 z = node_min.Z; z <= node_max.Z; z++)
for (s16 y = node_min.Y - 1; y <= node_max.Y + 1; y++) {
u32 vi = vm->m_area.index(node_min.X, y, z);
for (s16 x = node_min.X; x <= node_max.X; x++) {
int index = (z - node_min.Z) * csize.X + (x - node_min.X);
content_t c = vm->m_data[vi].getContent();
if (getMountainTerrainFromMap(j, index, y)
&& (c == CONTENT_AIR || c == c_water_source)) {
vm->m_data[vi] = n_stone;
if (y > ymax)
ymax = y;
}
vi++;
j++;
}
}
return ymax;
return stone_surface_max_y;
}
void MapgenV7::generateRidgeTerrain()
{
if (node_max.Y < water_level)
if (node_max.Y < water_level - 16)
return;
MapNode n_water(c_water_source);
@ -562,7 +524,7 @@ void MapgenV7::generateRidgeTerrain()
for (s16 x = node_min.X; x <= node_max.X; x++, index++, vi++) {
int j = (z - node_min.Z) * csize.X + (x - node_min.X);
if (heightmap[j] < water_level - 16)
if (heightmap[j] < water_level - 16) // Use base terrain heightmap
continue;
float uwatern = noise_ridge_uwater->result[j] * 2;
@ -805,6 +767,36 @@ void MapgenV7::generateCaves(s16 max_stone_y)
///////////////////////////////////////////////////////////////
#if 0
int MapgenV7::generateMountainTerrain(s16 ymax)
{
MapNode n_stone(c_stone);
u32 j = 0;
for (s16 z = node_min.Z; z <= node_max.Z; z++)
for (s16 y = node_min.Y - 1; y <= node_max.Y + 1; y++) {
u32 vi = vm->m_area.index(node_min.X, y, z);
for (s16 x = node_min.X; x <= node_max.X; x++) {
int index = (z - node_min.Z) * csize.X + (x - node_min.X);
content_t c = vm->m_data[vi].getContent();
if (getMountainTerrainFromMap(j, index, y)
&& (c == CONTENT_AIR || c == c_water_source)) {
vm->m_data[vi] = n_stone;
if (y > ymax)
ymax = y;
}
vi++;
j++;
}
}
return ymax;
}
#endif
#if 0
void MapgenV7::carveRivers() {
MapNode n_air(CONTENT_AIR), n_water_source(c_water_source);

View File

@ -59,6 +59,7 @@ public:
BiomeManager *bmgr;
int ystride;
int zstride_1u1d;
int zstride_1d;
u32 spflags;
@ -113,16 +114,12 @@ public:
void calculateNoise();
virtual int generateTerrain();
void generateBaseTerrain(s16 *stone_surface_min_y, s16 *stone_surface_max_y);
int generateMountainTerrain(s16 ymax);
int generateTerrain();
void generateRidgeTerrain();
MgStoneType generateBiomes(float *heat_map, float *humidity_map);
void dustTopNodes();
//void addTopNodes();
void generateCaves(s16 max_stone_y);
};

View File

@ -56,7 +56,7 @@ BiomeManager::BiomeManager(IGameDef *gamedef) :
b->m_nodenames.push_back("mapgen_water_source");
b->m_nodenames.push_back("mapgen_water_source");
b->m_nodenames.push_back("mapgen_river_water_source");
b->m_nodenames.push_back("air");
b->m_nodenames.push_back("ignore");
m_ndef->pendNodeResolve(b);
add(b);
@ -138,5 +138,5 @@ void Biome::resolveNodeNames()
getIdFromNrBacklog(&c_water_top, "mapgen_water_source", CONTENT_AIR);
getIdFromNrBacklog(&c_water, "mapgen_water_source", CONTENT_AIR);
getIdFromNrBacklog(&c_river_water, "mapgen_river_water_source", CONTENT_AIR);
getIdFromNrBacklog(&c_dust, "air", CONTENT_IGNORE);
getIdFromNrBacklog(&c_dust, "ignore", CONTENT_IGNORE);
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 124 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 916 B