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. -- 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. -- Up must come last, so that things above self will also fall all at once.
local nodeupdate_neighbors = { 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 = 0, y = -1, z = 0},
{x = -1, y = 0, z = 0}, {x = -1, y = 0, z = 0},
{x = 1, y = 0, z = 0}, {x = 1, y = 0, z = 0},
@ -226,10 +230,10 @@ function nodeupdate(p)
n = n - 1 n = n - 1
-- If there's nothing left on the stack, and no -- If there's nothing left on the stack, and no
-- more sides to walk to, we're done and can exit -- 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 return
end end
until v < 7 until v < 11
-- The next round walk the next neighbor in list. -- The next round walk the next neighbor in list.
v = v + 1 v = v + 1
else else

View File

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

View File

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

View File

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

View File

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

View File

@ -34,9 +34,13 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <cerrno> #include <cerrno>
#include <cstring> #include <cstring>
const int BUFFER_LENGTH = 256;
class StringBuffer : public std::streambuf { class StringBuffer : public std::streambuf {
public: public:
StringBuffer() {} StringBuffer() {
buffer_index = 0;
}
int overflow(int c); int overflow(int c);
virtual void flush(const std::string &buf) = 0; virtual void flush(const std::string &buf) = 0;
@ -44,7 +48,8 @@ public:
void push_back(char c); void push_back(char c);
private: 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) void StringBuffer::push_back(char c)
{ {
if (c == '\n' || c == '\r') { if (c == '\n' || c == '\r') {
if (!buffer.empty()) if (buffer_index)
flush(buffer); flush(std::string(buffer, buffer_index));
buffer.clear(); buffer_index = 0;
} else { } 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 //// amount of elements to skip for the next index
//// for noise/height/biome maps (not vmanip) //// for noise/height/biome maps (not vmanip)
this->ystride = csize.X; this->ystride = csize.X;
// 1-up 1-down overgeneration
this->zstride_1u1d = csize.X * (csize.Y + 2);
// 1-down overgeneration // 1-down overgeneration
this->zstride_1d = csize.X * (csize.Y + 1); this->zstride_1d = csize.X * (csize.Y + 1);
@ -263,10 +265,13 @@ void MapgenV7::makeChunk(BlockMakeData *data)
// Make some noise // Make some noise
calculateNoise(); calculateNoise();
// Generate base terrain, mountains, and ridges with initial heightmaps // Generate terrain and ridges with initial heightmaps
s16 stone_surface_max_y = generateTerrain(); s16 stone_surface_max_y = generateTerrain();
// Create heightmap if (spflags & MGV7_RIDGES)
generateRidgeTerrain();
// Update heightmap to include mountain terrain
updateHeightmap(node_min, node_max); updateHeightmap(node_min, node_max);
// Create biomemap at heightmap surface // Create biomemap at heightmap surface
@ -361,6 +366,11 @@ void MapgenV7::calculateNoise()
noise_terrain_alt->perlinMap2D(x, z, persistmap); noise_terrain_alt->perlinMap2D(x, z, persistmap);
noise_height_select->perlinMap2D(x, z); 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) { if ((spflags & MGV7_RIDGES) && node_max.Y >= water_level) {
noise_ridge->perlinMap3D(x, y, z); noise_ridge->perlinMap3D(x, y, z);
noise_ridge_uwater->perlinMap2D(x, z); noise_ridge_uwater->perlinMap2D(x, z);
@ -369,9 +379,6 @@ void MapgenV7::calculateNoise()
// Cave noises are calculated in generateCaves() // Cave noises are calculated in generateCaves()
// only if solid terrain is present in mapchunk // 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_filler_depth->perlinMap2D(x, z);
noise_heat->perlinMap2D(x, z); noise_heat->perlinMap2D(x, z);
noise_humidity->perlinMap2D(x, z); noise_humidity->perlinMap2D(x, z);
@ -400,7 +407,7 @@ Biome *MapgenV7::getBiomeAtPoint(v3s16 p)
return bmgr->getBiome(heat, humidity, groundlevel); return bmgr->getBiome(heat, humidity, groundlevel);
} }
//needs to be updated
float MapgenV7::baseTerrainLevelAtPoint(s16 x, s16 z) float MapgenV7::baseTerrainLevelAtPoint(s16 x, s16 z)
{ {
float hselect = NoisePerlin2D(&noise_height_select->np, x, z, seed); 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() 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_air(CONTENT_AIR);
MapNode n_stone(c_stone); MapNode n_stone(c_stone);
MapNode n_water(c_water_source); MapNode n_water(c_water_source);
v3s16 em = vm->m_area.getExtent(); v3s16 em = vm->m_area.getExtent();
s16 surface_min_y = MAX_MAP_GENERATION_LIMIT; s16 stone_surface_max_y = -MAX_MAP_GENERATION_LIMIT;
s16 surface_max_y = -MAX_MAP_GENERATION_LIMIT; u32 index2d = 0;
u32 index = 0; bool mountain_flag = spflags & MGV7_MOUNTAINS;
for (s16 z = node_min.Z; z <= node_max.Z; z++) for (s16 z = node_min.Z; z <= node_max.Z; z++)
for (s16 x = node_min.X; x <= node_max.X; x++, index++) { for (s16 x = node_min.X; x <= node_max.X; x++, index2d++) {
float surface_height = baseTerrainLevelFromMap(index); s16 surface_y = baseTerrainLevelFromMap(index2d);
s16 surface_y = (s16)surface_height; heightmap[index2d] = surface_y; // Create base terrain heightmap
ridge_heightmap[index2d] = surface_y;
heightmap[index] = surface_y; if (surface_y > stone_surface_max_y)
ridge_heightmap[index] = surface_y; stone_surface_max_y = surface_y;
if (surface_y < surface_min_y)
surface_min_y = surface_y;
if (surface_y > surface_max_y)
surface_max_y = surface_y;
u32 vi = vm->m_area.index(x, node_min.Y - 1, z); 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++) { for (s16 y = node_min.Y - 1; y <= node_max.Y + 1; y++) {
if (vm->m_data[vi].getContent() == CONTENT_IGNORE) { if (vm->m_data[vi].getContent() == CONTENT_IGNORE) {
if (y <= surface_y) if (y <= surface_y) {
vm->m_data[vi] = n_stone; vm->m_data[vi] = n_stone; // Base terrain
else if (y <= water_level) } 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; vm->m_data[vi] = n_water;
else } else {
vm->m_data[vi] = n_air; vm->m_data[vi] = n_air;
}
} }
vm->m_area.add_y(em, vi, 1); vm->m_area.add_y(em, vi, 1);
index3d += ystride;
} }
} }
*stone_surface_min_y = surface_min_y; return stone_surface_max_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;
} }
void MapgenV7::generateRidgeTerrain() void MapgenV7::generateRidgeTerrain()
{ {
if (node_max.Y < water_level) if (node_max.Y < water_level - 16)
return; return;
MapNode n_water(c_water_source); 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++) { 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); 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; continue;
float uwatern = noise_ridge_uwater->result[j] * 2; 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 #if 0
void MapgenV7::carveRivers() { void MapgenV7::carveRivers() {
MapNode n_air(CONTENT_AIR), n_water_source(c_water_source); MapNode n_air(CONTENT_AIR), n_water_source(c_water_source);

View File

@ -59,6 +59,7 @@ public:
BiomeManager *bmgr; BiomeManager *bmgr;
int ystride; int ystride;
int zstride_1u1d;
int zstride_1d; int zstride_1d;
u32 spflags; u32 spflags;
@ -113,16 +114,12 @@ public:
void calculateNoise(); void calculateNoise();
virtual int generateTerrain(); int generateTerrain();
void generateBaseTerrain(s16 *stone_surface_min_y, s16 *stone_surface_max_y);
int generateMountainTerrain(s16 ymax);
void generateRidgeTerrain(); void generateRidgeTerrain();
MgStoneType generateBiomes(float *heat_map, float *humidity_map); MgStoneType generateBiomes(float *heat_map, float *humidity_map);
void dustTopNodes(); void dustTopNodes();
//void addTopNodes();
void generateCaves(s16 max_stone_y); 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_water_source"); b->m_nodenames.push_back("mapgen_water_source");
b->m_nodenames.push_back("mapgen_river_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); m_ndef->pendNodeResolve(b);
add(b); add(b);
@ -138,5 +138,5 @@ void Biome::resolveNodeNames()
getIdFromNrBacklog(&c_water_top, "mapgen_water_source", CONTENT_AIR); getIdFromNrBacklog(&c_water_top, "mapgen_water_source", CONTENT_AIR);
getIdFromNrBacklog(&c_water, "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_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