diff --git a/builtin/mainmenu/init.lua b/builtin/mainmenu/init.lua index 4f89a0d79..6ad2aa88a 100644 --- a/builtin/mainmenu/init.lua +++ b/builtin/mainmenu/init.lua @@ -38,21 +38,25 @@ dofile(menupath .. DIR_DELIM .. "gamemgr.lua") dofile(menupath .. DIR_DELIM .. "modmgr.lua") dofile(menupath .. DIR_DELIM .. "store.lua") dofile(menupath .. DIR_DELIM .. "dlg_config_world.lua") -dofile(menupath .. DIR_DELIM .. "dlg_create_world.lua") -dofile(menupath .. DIR_DELIM .. "dlg_delete_mod.lua") -dofile(menupath .. DIR_DELIM .. "dlg_delete_world.lua") -dofile(menupath .. DIR_DELIM .. "dlg_rename_modpack.lua") dofile(menupath .. DIR_DELIM .. "tab_credits.lua") dofile(menupath .. DIR_DELIM .. "tab_mods.lua") -dofile(menupath .. DIR_DELIM .. "tab_multiplayer.lua") -dofile(menupath .. DIR_DELIM .. "tab_server.lua") dofile(menupath .. DIR_DELIM .. "tab_settings.lua") -dofile(menupath .. DIR_DELIM .. "tab_singleplayer.lua") -dofile(menupath .. DIR_DELIM .. "tab_texturepacks.lua") -dofile(menupath .. DIR_DELIM .. "textures.lua") +if PLATFORM ~= "Android" then + dofile(menupath .. DIR_DELIM .. "dlg_create_world.lua") + dofile(menupath .. DIR_DELIM .. "dlg_delete_mod.lua") + dofile(menupath .. DIR_DELIM .. "dlg_delete_world.lua") + dofile(menupath .. DIR_DELIM .. "dlg_rename_modpack.lua") + dofile(menupath .. DIR_DELIM .. "tab_multiplayer.lua") + dofile(menupath .. DIR_DELIM .. "tab_server.lua") + dofile(menupath .. DIR_DELIM .. "tab_singleplayer.lua") + dofile(menupath .. DIR_DELIM .. "tab_texturepacks.lua") + dofile(menupath .. DIR_DELIM .. "textures.lua") +else + dofile(menupath .. DIR_DELIM .. "tab_simple_main.lua") +end -------------------------------------------------------------------------------- -local function main_event_handler(tabview,event) +local function main_event_handler(tabview, event) if event == "MenuQuit" then core.close() end @@ -61,55 +65,95 @@ end -------------------------------------------------------------------------------- local function init_globals() - --init gamedata + -- Init gamedata gamedata.worldindex = 0 - menudata.worldlist = filterlist.create( - core.get_worlds, - compare_worlds, - function(element,uid) - if element.name == uid then - return true - end - return false - end, --unique id compare fct - function(element,gameid) - if element.gameid == gameid then - return true - end - return false - end --filter fct - ) - menudata.worldlist:add_sort_mechanism("alphabetic",sort_worlds_alphabetic) - menudata.worldlist:set_sortmode("alphabetic") + if PLATFORM ~= "Android" then + menudata.worldlist = filterlist.create( + core.get_worlds, + compare_worlds, + -- Unique id comparison function + function(element, uid) + return element.name == uid + end, + -- Filter function + function(element, gameid) + return element.gameid == gameid + end + ) - if not core.setting_get("menu_last_game") then - local default_game = core.setting_get("default_game") or "minetest" - core.setting_set("menu_last_game", default_game ) + menudata.worldlist:add_sort_mechanism("alphabetic", sort_worlds_alphabetic) + menudata.worldlist:set_sortmode("alphabetic") + + if not core.setting_get("menu_last_game") then + local default_game = core.setting_get("default_game") or "minetest" + core.setting_set("menu_last_game", default_game ) + end + + mm_texture.init() + else + local world_list = core.get_worlds() + + local found_singleplayerworld = false + + for world in pairs(world_list) do + if world.name == "singleplayerworld" then + found_singleplayerworld = true + gamedata.worldindex = i + break + end + end + + if not found_singleplayerworld then + core.create_world("singleplayerworld", 1) + + local world_list = core.get_worlds() + + for world in pairs(world_list) do + if world.name == "singleplayerworld" then + gamedata.worldindex = i + return + end + end + end end - mm_texture.init() - - --create main tabview + -- Create main tabview local tv_main = tabview_create("maintab",{x=12,y=5.2},{x=0,y=0}) - tv_main:set_autosave_tab(true) - tv_main:add(tab_singleplayer) - tv_main:add(tab_multiplayer) - tv_main:add(tab_server) + if PLATFORM ~= "Android" then + tv_main:set_autosave_tab(true) + end + if PLATFORM ~= "Android" then + tv_main:add(tab_singleplayer) + tv_main:add(tab_multiplayer) + tv_main:add(tab_server) + else + tv_main:add(tab_simple_main) + end tv_main:add(tab_settings) - tv_main:add(tab_texturepacks) + if PLATFORM ~= "Android" then + tv_main:add(tab_texturepacks) + end tv_main:add(tab_mods) tv_main:add(tab_credits) tv_main:set_global_event_handler(main_event_handler) - tv_main:set_tab(core.setting_get("maintab_LAST")) + if PLATFORM == "Android" then + tv_main:set_fixed_size(false) + else + tv_main:set_tab(core.setting_get("maintab_LAST")) + end ui.set_default("maintab") tv_main:show() - --create modstore ui - modstore.init({x=12,y=8},4,3) + -- Create modstore ui + if PLATFORM == "Android" then + modstore.init({x=12, y=6}, 3, 2) + else + modstore.init({x=12, y=8}, 4, 3) + end ui.update() @@ -117,3 +161,4 @@ local function init_globals() end init_globals() + diff --git a/builtin/mainmenu/init_android.lua b/builtin/mainmenu/init_android.lua deleted file mode 100644 index 348923fa5..000000000 --- a/builtin/mainmenu/init_android.lua +++ /dev/null @@ -1,102 +0,0 @@ ---Minetest ---Copyright (C) 2014 sapier --- ---This program is free software; you can redistribute it and/or modify ---it under the terms of the GNU Lesser General Public License as published by ---the Free Software Foundation; either version 2.1 of the License, or ---(at your option) any later version. --- ---This program is distributed in the hope that it will be useful, ---but WITHOUT ANY WARRANTY; without even the implied warranty of ---MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ---GNU Lesser General Public License for more details. --- ---You should have received a copy of the GNU Lesser General Public License along ---with this program; if not, write to the Free Software Foundation, Inc., ---51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -mt_color_grey = "#AAAAAA" -mt_color_blue = "#0000DD" -mt_color_green = "#00DD00" -mt_color_dark_green = "#003300" - ---marker for android specific code -ANDROID = true - -local menupath = core.get_mainmenu_path() -local basepath = core.get_builtin_path() -defaulttexturedir = core.get_texturepath_share() .. DIR_DELIM .. "base" .. - DIR_DELIM .. "pack" .. DIR_DELIM - -dofile(basepath .. DIR_DELIM .. "common" .. DIR_DELIM .. "async_event.lua") -dofile(basepath .. DIR_DELIM .. "common" .. DIR_DELIM .. "filterlist.lua") -dofile(basepath .. DIR_DELIM .. "fstk" .. DIR_DELIM .. "buttonbar.lua") -dofile(basepath .. DIR_DELIM .. "fstk" .. DIR_DELIM .. "dialog.lua") -dofile(basepath .. DIR_DELIM .. "fstk" .. DIR_DELIM .. "tabview.lua") -dofile(basepath .. DIR_DELIM .. "fstk" .. DIR_DELIM .. "ui.lua") -dofile(menupath .. DIR_DELIM .. "common.lua") -dofile(menupath .. DIR_DELIM .. "gamemgr.lua") -dofile(menupath .. DIR_DELIM .. "modmgr.lua") -dofile(menupath .. DIR_DELIM .. "store.lua") -dofile(menupath .. DIR_DELIM .. "dlg_config_world.lua") -dofile(menupath .. DIR_DELIM .. "tab_simple_main.lua") -dofile(menupath .. DIR_DELIM .. "tab_credits.lua") -dofile(menupath .. DIR_DELIM .. "tab_mods.lua") -dofile(menupath .. DIR_DELIM .. "tab_settings.lua") - --------------------------------------------------------------------------------- -local function main_event_handler(tabview,event) - if event == "MenuQuit" then - core.close() - end - return true -end - -local function init_globals() - --init gamedata - gamedata.worldindex = 0 - - local worldlist = core.get_worlds() - - local found_singleplayerworld = false - - for i=1,#worldlist,1 do - if worldlist[i].name == "singleplayerworld" then - found_singleplayerworld = true - gamedata.worldindex = i - end - end - - if not found_singleplayerworld then - core.create_world("singleplayerworld", 1) - - local worldlist = core.get_worlds() - - for i=1,#worldlist,1 do - if worldlist[i].name == "singleplayerworld" then - gamedata.worldindex = i - end - end - end - - --create main tabview - local tv_main = tabview_create("maintab",{x=12,y=5.2},{x=-0,y=-0}) - tv_main:add(tab_simple_main) - tv_main:add(tab_mods) - tv_main:add(tab_settings) - tv_main:add(tab_credits) - tv_main:set_global_event_handler(main_event_handler) - tv_main:set_fixed_size(false) - ui.set_default("maintab") - tv_main:show() - - --create modstore ui - modstore.init({x=12,y=6},3,2) - - ui.update() - - core.sound_play("main_menu", true) -end - -init_globals() - diff --git a/builtin/mainmenu/tab_credits.lua b/builtin/mainmenu/tab_credits.lua index cc9eaa3d3..7c378dc0b 100644 --- a/builtin/mainmenu/tab_credits.lua +++ b/builtin/mainmenu/tab_credits.lua @@ -31,7 +31,6 @@ tab_credits = { "Perttu Ahola (celeron55) ,".. "Ryan Kwolek (kwolekr) ,".. "PilzAdam ," .. - "Ilya Zhuravlev (xyz) ,".. "Lisa Milne (darkrose) ,".. "Maciej Kasatkin (RealBadAngel) ,".. "sfan5 ,".. @@ -40,16 +39,22 @@ tab_credits = { "ShadowNinja ,".. "Nathanael Courant (Nore/Novatux) ,".. "BlockMen,".. + "Craig Robbins (Zeno),".. ",".. "#FFFF00" .. fgettext("Active Contributors") .. "," .. + "TriBlade9 ,".. + "SmallJoker ,".. + "Zefram ,".. + "," .. + "#FFFF00" .. fgettext("Previous Contributors") .. "," .. "Vanessa Ezekowitz (VanessaE) ,".. "Jurgen Doser (doserj) ,".. "Jeija ,".. "MirceaKitsune ,".. "dannydark ,".. "0gb.us <0gb.us@0gb.us>,".. - "," .. - "#FFFF00" .. fgettext("Previous Contributors") .. "," .. + "proller ,".. + "Ilya Zhuravlev (xyz) ,".. "Guiseppe Bilotta (Oblomov) ,".. "Jonathan Neuschafer ,".. "Nils Dagsson Moskopp (erlehmann) ,".. diff --git a/builtin/mainmenu/tab_settings.lua b/builtin/mainmenu/tab_settings.lua index 630267478..1f8743140 100644 --- a/builtin/mainmenu/tab_settings.lua +++ b/builtin/mainmenu/tab_settings.lua @@ -160,7 +160,7 @@ local function formspec(tabview, name, tabdata) "box[7.75,0;4,4;#999999]" .. "checkbox[8,0;cb_shaders;".. fgettext("Shaders") .. ";" .. dump(core.setting_getbool("enable_shaders")) .. "]" - if not ANDROID then + if PLATFORM ~= "Android" then tab_string = tab_string .. "button[8,4.75;3.75,0.5;btn_change_keys;".. fgettext("Change keys") .. "]" else @@ -176,7 +176,7 @@ local function formspec(tabview, name, tabdata) fgettext("Scaling factor applied to menu elements: ") .. dump(core.setting_get("gui_scaling")) .. "]" - if ANDROID then + if PLATFORM == "Android" then tab_string = tab_string .. "box[4.25,2.75;3.25,2.15;#999999]" .. "checkbox[4.5,2.75;cb_touchscreen_target;".. fgettext("Touch free target") .. ";" diff --git a/builtin/mainmenu/tab_texturepacks.lua b/builtin/mainmenu/tab_texturepacks.lua index 784480415..97f96fb1b 100644 --- a/builtin/mainmenu/tab_texturepacks.lua +++ b/builtin/mainmenu/tab_texturepacks.lua @@ -17,10 +17,10 @@ -------------------------------------------------------------------------------- local function filter_texture_pack_list(list) - retval = {"None"} - for _,i in ipairs(list) do - if i~="base" then - table.insert(retval, i) + local retval = {"None"} + for _, item in ipairs(list) do + if item ~= "base" then + table.insert(retval, item) end end return retval diff --git a/minetest.conf.example b/minetest.conf.example index 6bd2e00b4..3c00b6f4b 100644 --- a/minetest.conf.example +++ b/minetest.conf.example @@ -54,7 +54,7 @@ # Double-tapping the jump key toggles fly mode #doubletap_jump = false # If false aux1 is used to fly fast -#always_fly_fast = true +#always_fly_fast = false # Some (temporary) keys for debugging #keymap_print_debug_stacks = KEY_KEY_P #keymap_quicktune_prev = KEY_HOME @@ -70,9 +70,10 @@ #fps_max = 60 # Maximum FPS when game is paused #pause_fps_max = 20 -# The allowed adjustment range for the automatic rendering range adjustment -#viewing_range_nodes_max = 160 -#viewing_range_nodes_min = 35 +# The allowed adjustment range for the automatic rendering range adjustment. +# You can change this option on gameplay too. Press "-" to reduce and "+" to increase the minimum viewing range. +#viewing_range_nodes_max = 120 +#viewing_range_nodes_min = 30 # Initial window size #screenW = 800 #screenH = 600 @@ -88,7 +89,7 @@ # Enable random user input, for testing #random_input = false # Timeout for client to remove unused map data from memory -#client_unload_unused_data_timeout = 600 +#client_unload_unused_data_timeout = 300 # Whether to fog out the end of the visible area #enable_fog = true # Whether to show the client debug info (has the same effect as hitting F5) @@ -130,7 +131,7 @@ # Amount of view bobbing (0 = no view bobbing, 1.0 = normal, 2.0 = double) #view_bobbing_amount = 1.0 # Amount of fall bobbing (0 = no fall bobbing, 1.0 = normal, 2.0 = double) -#fall_bobbing_amount = 0.0 +#fall_bobbing_amount = 0.6 # 3d support, # right now: # "none" = no 3d output, @@ -215,7 +216,7 @@ # Default timeout for cURL, in milliseconds # Only has an effect if compiled with cURL -#curl_timeout = 5000 +#curl_timeout = 4000 # Limits number of parallel HTTP requests. Affects: # - Media fetch if server uses remote_media setting # - Serverlist download and server announcement diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b1fd26247..ec6c7fbac 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -2,6 +2,7 @@ project(minetest) cmake_minimum_required( VERSION 2.6 ) INCLUDE(CheckCSourceRuns) +INCLUDE(CheckIncludeFiles) # Set some random things default to not being visible in the GUI mark_as_advanced(EXECUTABLE_OUTPUT_PATH LIBRARY_OUTPUT_PATH) @@ -313,6 +314,8 @@ if(ENABLE_REDIS) endif(REDIS_LIBRARY AND REDIS_INCLUDE_DIR) endif(ENABLE_REDIS) +CHECK_INCLUDE_FILES(endian.h HAVE_ENDIAN_H) + configure_file( "${PROJECT_SOURCE_DIR}/cmake_config.h.in" "${PROJECT_BINARY_DIR}/cmake_config.h" diff --git a/src/cmake_config.h.in b/src/cmake_config.h.in index 64a4c002b..e111a650d 100644 --- a/src/cmake_config.h.in +++ b/src/cmake_config.h.in @@ -20,6 +20,7 @@ #define CMAKE_VERSION_PATCH @VERSION_PATCH@ #define CMAKE_VERSION_PATCH_ORIG @VERSION_PATCH_ORIG@ #define CMAKE_VERSION_EXTRA_STRING "@VERSION_EXTRA@" +#define CMAKE_HAVE_ENDIAN_H @HAVE_ENDIAN_H@ #ifdef NDEBUG #define CMAKE_BUILD_TYPE "Release" diff --git a/src/config.h b/src/config.h index f1aef03aa..b07aa5d22 100644 --- a/src/config.h +++ b/src/config.h @@ -36,6 +36,8 @@ #define USE_REDIS 0 #endif +#define HAVE_ENDIAN_H 0 + #ifdef USE_CMAKE_CONFIG_H #include "cmake_config.h" #undef PROJECT_NAME @@ -72,6 +74,8 @@ #define PRODUCT_VERSION_STRING CMAKE_PRODUCT_VERSION_STRING #undef VERSION_EXTRA_STRING #define VERSION_EXTRA_STRING CMAKE_VERSION_EXTRA_STRING + #undef HAVE_ENDIAN_H + #define HAVE_ENDIAN_H CMAKE_HAVE_ENDIAN_H #endif #ifdef __ANDROID__ diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp index 4f297c099..472d5693b 100644 --- a/src/defaultsettings.cpp +++ b/src/defaultsettings.cpp @@ -62,7 +62,7 @@ void set_default_settings(Settings *settings) settings->setDefault("3d_paralax_strength", "0.025"); settings->setDefault("aux1_descends", "false"); settings->setDefault("doubletap_jump", "false"); - settings->setDefault("always_fly_fast", "true"); + settings->setDefault("always_fly_fast", "false"); settings->setDefault("directional_colored_fog", "true"); settings->setDefault("tooltip_show_delay", "400"); @@ -84,8 +84,8 @@ void set_default_settings(Settings *settings) settings->setDefault("fps_max", "60"); settings->setDefault("pause_fps_max", "20"); // A bit more than the server will send around the player, to make fog blend well - settings->setDefault("viewing_range_nodes_max", "240"); - settings->setDefault("viewing_range_nodes_min", "35"); + settings->setDefault("viewing_range_nodes_max", "120"); + settings->setDefault("viewing_range_nodes_min", "30"); settings->setDefault("screenW", "800"); settings->setDefault("screenH", "600"); settings->setDefault("fullscreen", "false"); @@ -94,7 +94,7 @@ void set_default_settings(Settings *settings) settings->setDefault("vsync", "false"); settings->setDefault("address", ""); settings->setDefault("random_input", "false"); - settings->setDefault("client_unload_unused_data_timeout", "600"); + settings->setDefault("client_unload_unused_data_timeout", "300"); settings->setDefault("enable_fog", "true"); settings->setDefault("fov", "72"); settings->setDefault("view_bobbing", "true"); @@ -113,7 +113,7 @@ void set_default_settings(Settings *settings) settings->setDefault("enable_clouds", "true"); settings->setDefault("screenshot_path", "."); settings->setDefault("view_bobbing_amount", "1.0"); - settings->setDefault("fall_bobbing_amount", "0.0"); + settings->setDefault("fall_bobbing_amount", "0.6"); settings->setDefault("enable_3d_clouds", "true"); settings->setDefault("cloud_height", "120"); settings->setDefault("menu_clouds", "true"); @@ -156,7 +156,7 @@ void set_default_settings(Settings *settings) settings->setDefault("enable_particles", "true"); settings->setDefault("enable_mesh_cache", "true"); - settings->setDefault("curl_timeout", "5000"); + settings->setDefault("curl_timeout", "4000"); settings->setDefault("curl_parallel_limit", "8"); settings->setDefault("curl_file_download_timeout", "300000"); settings->setDefault("curl_verify_cert", "true"); @@ -289,7 +289,6 @@ void set_default_settings(Settings *settings) settings->setDefault("enable_particles", "false"); settings->setDefault("video_driver", "ogles1"); settings->setDefault("touchtarget", "true"); - settings->setDefault("main_menu_script","/sdcard/Minetest/builtin/mainmenu/init_android.lua"); settings->setDefault("TMPFolder","/sdcard/Minetest/tmp/"); settings->setDefault("touchscreen_threshold","20"); settings->setDefault("smooth_lighting", "false"); diff --git a/src/mapblock_mesh.cpp b/src/mapblock_mesh.cpp index 99a5ce0dd..193fea328 100644 --- a/src/mapblock_mesh.cpp +++ b/src/mapblock_mesh.cpp @@ -65,8 +65,9 @@ void MeshMakeData::fill(MapBlock *block) // Allocate this block + neighbors m_vmanip.clear(); - m_vmanip.addArea(VoxelArea(blockpos_nodes-v3s16(1,1,1)*MAP_BLOCKSIZE, - blockpos_nodes+v3s16(1,1,1)*MAP_BLOCKSIZE*2-v3s16(1,1,1))); + VoxelArea voxel_area(blockpos_nodes - v3s16(1,1,1) * MAP_BLOCKSIZE, + blockpos_nodes + v3s16(1,1,1) * MAP_BLOCKSIZE*2-v3s16(1,1,1)); + m_vmanip.addArea(voxel_area); { //TimeTaker timer("copy central block data"); @@ -221,11 +222,11 @@ u16 getFaceLight(MapNode n, MapNode n2, v3s16 face_dir, INodeDefManager *ndef) /* Calculate smooth lighting at the XYZ- corner of p. - Single light bank. + Both light banks */ -static u8 getSmoothLight(enum LightBank bank, v3s16 p, MeshMakeData *data) +static u16 getSmoothLightCombined(v3s16 p, MeshMakeData *data) { - static v3s16 dirs8[8] = { + static const v3s16 dirs8[8] = { v3s16(0,0,0), v3s16(0,0,1), v3s16(0,1,0), @@ -239,10 +240,12 @@ static u8 getSmoothLight(enum LightBank bank, v3s16 p, MeshMakeData *data) INodeDefManager *ndef = data->m_gamedef->ndef(); u16 ambient_occlusion = 0; - u16 light = 0; u16 light_count = 0; u8 light_source_max = 0; - for(u32 i=0; i<8; i++) + u16 light_day = 0; + u16 light_night = 0; + + for(u32 i = 0; i < 8; i++) { MapNode n = data->m_vmanip.getNodeNoEx(p - dirs8[i]); @@ -256,48 +259,44 @@ static u8 getSmoothLight(enum LightBank bank, v3s16 p, MeshMakeData *data) light_source_max = f.light_source; // Check f.solidness because fast-style leaves look // better this way - if(f.param_type == CPT_LIGHT && f.solidness != 2) - { - light += decode_light(n.getLight(bank, ndef)); + if (f.param_type == CPT_LIGHT && f.solidness != 2) { + light_day += decode_light(n.getLight(LIGHTBANK_DAY, ndef)); + light_night += decode_light(n.getLight(LIGHTBANK_NIGHT, ndef)); light_count++; - } - else { + } else { ambient_occlusion++; } } if(light_count == 0) - return 255; + return 0xffff; - light /= light_count; + light_day /= light_count; + light_night /= light_count; // Boost brightness around light sources - if(decode_light(light_source_max) >= light) - //return decode_light(undiminish_light(light_source_max)); - return decode_light(light_source_max); + bool skip_ambient_occlusion = false; + if(decode_light(light_source_max) >= light_day) { + light_day = decode_light(light_source_max); + skip_ambient_occlusion = true; + } + if(decode_light(light_source_max) >= light_night) { + light_night = decode_light(light_source_max); + skip_ambient_occlusion = true; + } - if(ambient_occlusion > 4) + if(ambient_occlusion > 4 && !skip_ambient_occlusion) { //calculate table index for gamma space multiplier ambient_occlusion -= 5; //table of precalculated gamma space multiply factors //light^2.2 * factor (0.75, 0.5, 0.25, 0.0), so table holds factor ^ (1 / 2.2) - const float light_amount[4] = {0.877424315, 0.729740053, 0.532520545, 0.0}; - light = core::clamp(core::round32(light*light_amount[ambient_occlusion]), 0, 255); + static const float light_amount[4] = {0.877424315, 0.729740053, 0.532520545, 0.0}; + light_day = rangelim(core::round32(light_day*light_amount[ambient_occlusion]), 0, 255); + light_night = rangelim(core::round32(light_night*light_amount[ambient_occlusion]), 0, 255); } - return light; -} - -/* - Calculate smooth lighting at the XYZ- corner of p. - Both light banks. -*/ -static u16 getSmoothLight(v3s16 p, MeshMakeData *data) -{ - u16 day = getSmoothLight(LIGHTBANK_DAY, p, data); - u16 night = getSmoothLight(LIGHTBANK_NIGHT, p, data); - return day | (night << 8); + return light_day | (light_night << 8); } /* @@ -307,13 +306,13 @@ static u16 getSmoothLight(v3s16 p, MeshMakeData *data) u16 getSmoothLight(v3s16 p, v3s16 corner, MeshMakeData *data) { if(corner.X == 1) p.X += 1; - else assert(corner.X == -1); + // else corner.X == -1 if(corner.Y == 1) p.Y += 1; - else assert(corner.Y == -1); + // else corner.Y == -1 if(corner.Z == 1) p.Z += 1; - else assert(corner.Z == -1); + // else corner.Z == -1 - return getSmoothLight(p, data); + return getSmoothLightCombined(p, data); } /* diff --git a/src/mapgen_v5.cpp b/src/mapgen_v5.cpp index bb8c703cc..ebc5e5719 100644 --- a/src/mapgen_v5.cpp +++ b/src/mapgen_v5.cpp @@ -63,7 +63,7 @@ MapgenV5::MapgenV5(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; - this->zstride = csize.X * csize.Y; + this->zstride = csize.X * (csize.Y + 2); this->biomemap = new u8[csize.X * csize.Z]; this->heightmap = new s16[csize.X * csize.Z]; @@ -78,11 +78,11 @@ MapgenV5::MapgenV5(int mapgenid, MapgenParams *params, EmergeManager *emerge_) { noise_height = new Noise(&sp->np_height, seed, csize.X, csize.Z); // 3D terrain noise - noise_cave1 = new Noise(&sp->np_cave1, seed, csize.X, csize.Y, csize.Z); - noise_cave2 = new Noise(&sp->np_cave2, seed, csize.X, csize.Y, csize.Z); - noise_ground = new Noise(&sp->np_ground, seed, csize.X, csize.Y, csize.Z); - noise_crumble = new Noise(&sp->np_crumble, seed, csize.X, csize.Y, csize.Z); - noise_wetness = new Noise(&sp->np_wetness, seed, csize.X, csize.Y, csize.Z); + noise_cave1 = new Noise(&sp->np_cave1, seed, csize.X, csize.Y + 2, csize.Z); + noise_cave2 = new Noise(&sp->np_cave2, seed, csize.X, csize.Y + 2, csize.Z); + noise_ground = new Noise(&sp->np_ground, seed, csize.X, csize.Y + 2, csize.Z); + noise_crumble = new Noise(&sp->np_crumble, seed, csize.X, csize.Y + 2, csize.Z); + noise_wetness = new Noise(&sp->np_wetness, seed, csize.X, csize.Y + 2, csize.Z); // Biome noise noise_heat = new Noise(bmgr->np_heat, seed, csize.X, csize.Z); @@ -192,15 +192,48 @@ void MapgenV5Params::writeParams(Settings *settings) { } +int MapgenV5::getGroundLevelAtPoint(v2s16 p) { + //TimeTaker t("getGroundLevelAtPoint", NULL, PRECISION_MICRO); + + float f = 0.55 + NoisePerlin2D(noise_factor->np, p.X, p.Y, seed); + if(f < 0.01) + f = 0.01; + else if(f >= 1.0) + f *= 1.6; + float h = water_level + NoisePerlin2D(noise_height->np, p.X, p.Y, seed); + + s16 search_top = water_level + 15; + s16 search_base = water_level; + // Use these 2 lines instead for a slower search returning highest ground level + //s16 search_top = h + f * noise_ground->np->octaves * noise_ground->np->scale; + //s16 search_base = h - f * noise_ground->np->octaves * noise_ground->np->scale; + + s16 level = -31000; + for (s16 y = search_top; y >= search_base; y--) { + float n_ground = NoisePerlin3DEased(noise_ground->np, p.X, y, p.Y, seed); + if(n_ground * f > y - h) { + if(y >= search_top - 7) + break; + else + level = y; + break; + } + } + + //printf("getGroundLevelAtPoint: %dus\n", t.stop()); + return level; +} + + void MapgenV5::makeChunk(BlockMakeData *data) { assert(data->vmanip); assert(data->nodedef); assert(data->blockpos_requested.X >= data->blockpos_min.X && - data->blockpos_requested.Y >= data->blockpos_min.Y && - data->blockpos_requested.Z >= data->blockpos_min.Z); + data->blockpos_requested.Y >= data->blockpos_min.Y && + data->blockpos_requested.Z >= data->blockpos_min.Z); assert(data->blockpos_requested.X <= data->blockpos_max.X && - data->blockpos_requested.Y <= data->blockpos_max.Y && - data->blockpos_requested.Z <= data->blockpos_max.Z); + data->blockpos_requested.Y <= data->blockpos_max.Y && + data->blockpos_requested.Z <= data->blockpos_max.Z); generating = true; vm = data->vmanip; @@ -258,8 +291,8 @@ void MapgenV5::makeChunk(BlockMakeData *data) { // Calculate lighting if (flags & MG_LIGHT) - calcLighting(node_min - v3s16(1, 0, 1) * MAP_BLOCKSIZE, - node_max + v3s16(1, 0, 1) * MAP_BLOCKSIZE); + calcLighting(node_min - v3s16(0, 1, 0) - v3s16(1, 0, 1) * MAP_BLOCKSIZE, + node_max + v3s16(0, 1, 0) + v3s16(1, 0, 1) * MAP_BLOCKSIZE); this->generating = false; } @@ -268,7 +301,7 @@ void MapgenV5::makeChunk(BlockMakeData *data) { void MapgenV5::calculateNoise() { //TimeTaker t("calculateNoise", NULL, PRECISION_MICRO); int x = node_min.X; - int y = node_min.Y; + int y = node_min.Y - 1; int z = node_min.Z; noise_filler_depth->perlinMap2D(x, z); @@ -319,7 +352,7 @@ void MapgenV5::generateBaseTerrain() { u32 index2d = 0; for(s16 z=node_min.Z; z<=node_max.Z; z++) { - for(s16 y=node_min.Y; y<=node_max.Y; y++) { + for(s16 y=node_min.Y - 1; y<=node_max.Y + 1; y++) { u32 i = vm->m_area.index(node_min.X, y, z); for(s16 x=node_min.X; x<=node_max.X; x++, i++, index++, index2d++) { if(vm->m_data[i].getContent() != CONTENT_IGNORE) @@ -333,6 +366,7 @@ void MapgenV5::generateBaseTerrain() { float h = water_level + noise_height->result[index2d]; float d1 = contour(noise_cave1->result[index]); float d2 = contour(noise_cave2->result[index]); + if(noise_ground->result[index] * f < y - h) { if(y <= water_level) vm->m_data[i] = MapNode(c_water_source); @@ -356,7 +390,7 @@ void MapgenV5::generateBlobs() { u32 index = 0; for(s16 z=node_min.Z; z<=node_max.Z; z++) { - for(s16 y=node_min.Y; y<=node_max.Y; y++) { + for(s16 y=node_min.Y - 1; y<=node_max.Y + 1; y++) { u32 i = vm->m_area.index(node_min.X, y, z); for(s16 x=node_min.X; x<=node_max.X; x++, i++, index++) { content_t c = vm->m_data[i].getContent(); @@ -398,7 +432,7 @@ void MapgenV5::generateBiomes() { Biome *biome = (Biome *)bmgr->get(biomemap[index]); s16 dfiller = biome->depth_filler + noise_filler_depth->result[index]; s16 y0_top = biome->depth_top; - s16 y0_filler = biome->depth_filler + biome->depth_top + dfiller; + s16 y0_filler = biome->depth_top + dfiller; s16 nplaced = 0; u32 i = vm->m_area.index(x, node_max.Y, z); @@ -462,7 +496,7 @@ void MapgenV5::dustTopNodes() { if (biome->c_dust == CONTENT_IGNORE) continue; - s16 y = node_max.Y; + s16 y = node_max.Y + 1; u32 vi = vm->m_area.index(x, y, z); for (; y >= node_min.Y; y--) { if (vm->m_data[vi].getContent() != CONTENT_AIR) @@ -473,12 +507,13 @@ void MapgenV5::dustTopNodes() { content_t c = vm->m_data[vi].getContent(); if (c == biome->c_water && biome->c_dust_water != CONTENT_IGNORE) { - if (y < node_min.Y) + if (y < node_min.Y - 1) continue; vm->m_data[vi] = MapNode(biome->c_dust_water); - } else if (!ndef->get(c).buildable_to && c != CONTENT_IGNORE) { - if (y == node_max.Y) + } else if (!ndef->get(c).buildable_to && c != CONTENT_IGNORE + && c != biome->c_dust) { + if (y == node_max.Y + 1) continue; vm->m_area.add_y(em, vi, 1); diff --git a/src/mapgen_v5.h b/src/mapgen_v5.h index f50afc42d..84e63672b 100644 --- a/src/mapgen_v5.h +++ b/src/mapgen_v5.h @@ -94,6 +94,7 @@ public: ~MapgenV5(); virtual void makeChunk(BlockMakeData *data); + int getGroundLevelAtPoint(v2s16 p); void calculateNoise(); void generateBaseTerrain(); void generateBlobs(); diff --git a/src/mapnode.cpp b/src/mapnode.cpp index 786224240..fbf0ac8c9 100644 --- a/src/mapnode.cpp +++ b/src/mapnode.cpp @@ -26,6 +26,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "serialization.h" // For ser_ver_supported #include "util/serialize.h" #include "log.h" +#include "util/numeric.h" #include #include @@ -77,19 +78,14 @@ u8 MapNode::getLight(enum LightBank bank, INodeDefManager *nodemgr) const { // Select the brightest of [light source, propagated light] const ContentFeatures &f = nodemgr->get(*this); - u8 light = 0; + + u8 light; if(f.param_type == CPT_LIGHT) - { - if(bank == LIGHTBANK_DAY) - light = param1 & 0x0f; - else if(bank == LIGHTBANK_NIGHT) - light = (param1>>4)&0x0f; - else - assert(0); - } - if(f.light_source > light) - light = f.light_source; - return light; + light = bank == LIGHTBANK_DAY ? param1 & 0x0f : (param1 >> 4) & 0x0f; + else + light = 0; + + return MYMAX(f.light_source, light); } bool MapNode::getLightBanks(u8 &lightday, u8 &lightnight, INodeDefManager *nodemgr) const diff --git a/src/nodedef.cpp b/src/nodedef.cpp index 51e71a052..deb08fda9 100644 --- a/src/nodedef.cpp +++ b/src/nodedef.cpp @@ -389,8 +389,8 @@ public: virtual ~CNodeDefManager(); void clear(); virtual IWritableNodeDefManager *clone(); - virtual const ContentFeatures& get(content_t c) const; - virtual const ContentFeatures& get(const MapNode &n) const; + inline virtual const ContentFeatures& get(content_t c) const; + inline virtual const ContentFeatures& get(const MapNode &n) const; virtual bool getId(const std::string &name, content_t &result) const; virtual content_t getId(const std::string &name) const; virtual void getIds(const std::string &name, std::set &result) const; @@ -530,16 +530,14 @@ IWritableNodeDefManager *CNodeDefManager::clone() } -const ContentFeatures& CNodeDefManager::get(content_t c) const +inline const ContentFeatures& CNodeDefManager::get(content_t c) const { - if (c < m_content_features.size()) - return m_content_features[c]; - else - return m_content_features[CONTENT_UNKNOWN]; + return c < m_content_features.size() + ? m_content_features[c] : m_content_features[CONTENT_UNKNOWN]; } -const ContentFeatures& CNodeDefManager::get(const MapNode &n) const +inline const ContentFeatures& CNodeDefManager::get(const MapNode &n) const { return get(n.getContent()); } diff --git a/src/nodemetadata.cpp b/src/nodemetadata.cpp index 4cdd61767..0631d974a 100644 --- a/src/nodemetadata.cpp +++ b/src/nodemetadata.cpp @@ -130,12 +130,12 @@ void NodeMetadataList::deSerialize(std::istream &is, IGameDef *gamedef) { u16 p16 = readU16(is); - v3s16 p(0,0,0); - p.Z += p16 / MAP_BLOCKSIZE / MAP_BLOCKSIZE; - p16 -= p.Z * MAP_BLOCKSIZE * MAP_BLOCKSIZE; - p.Y += p16 / MAP_BLOCKSIZE; - p16 -= p.Y * MAP_BLOCKSIZE; - p.X += p16; + v3s16 p; + p.Z = p16 / MAP_BLOCKSIZE / MAP_BLOCKSIZE; + p16 &= MAP_BLOCKSIZE * MAP_BLOCKSIZE - 1; + p.Y = p16 / MAP_BLOCKSIZE; + p16 &= MAP_BLOCKSIZE - 1; + p.X = p16; if(m_data.find(p) != m_data.end()) { diff --git a/src/nodetimer.cpp b/src/nodetimer.cpp index 5fc652bb7..d4971c873 100644 --- a/src/nodetimer.cpp +++ b/src/nodetimer.cpp @@ -96,12 +96,12 @@ void NodeTimerList::deSerialize(std::istream &is, u8 map_format_version) { u16 p16 = readU16(is); - v3s16 p(0,0,0); - p.Z += p16 / MAP_BLOCKSIZE / MAP_BLOCKSIZE; - p16 -= p.Z * MAP_BLOCKSIZE * MAP_BLOCKSIZE; - p.Y += p16 / MAP_BLOCKSIZE; - p16 -= p.Y * MAP_BLOCKSIZE; - p.X += p16; + v3s16 p; + p.Z = p16 / MAP_BLOCKSIZE / MAP_BLOCKSIZE; + p16 &= MAP_BLOCKSIZE * MAP_BLOCKSIZE - 1; + p.Y = p16 / MAP_BLOCKSIZE; + p16 &= MAP_BLOCKSIZE - 1; + p.X = p16; NodeTimer t; t.deSerialize(is); diff --git a/src/porting.h b/src/porting.h index 9be09da75..b6f71103d 100644 --- a/src/porting.h +++ b/src/porting.h @@ -371,6 +371,46 @@ v2u32 getDisplaySize(); v2u32 getWindowSize(); #endif +inline const char * getPlatformName() +{ + return +#if defined(ANDROID) + "Android" +#elif defined(linux) || defined(__linux) || defined(__linux__) + "Linux" +#elif defined(_WIN32) || defined(_WIN64) + "Windows" +#elif defined(__DragonFly__) || defined(__FreeBSD__) || \ + defined(__NetBSD__) || defined(__OpenBSD__) + "BSD" +#elif defined(__APPLE__) && defined(__MACH__) + #if TARGET_OS_MAC + "OSX" + #elif TARGET_OS_IPHONE + "iOS" + #else + "Apple" + #endif +#elif defined(_AIX) + "AIX" +#elif defined(__hpux) + "HP-UX" +#elif defined(__sun) && defined(__SVR4) + "Solaris" +#elif defined(__CYGWIN__) + "Cygwin" +#elif defined(__unix__) || defined(__unix) + #if defined(_POSIX_VERSION) + "Posix" + #else + "Unix" + #endif +#else + "?" +#endif + ; +} + } // namespace porting #ifdef __ANDROID__ diff --git a/src/script/cpp_api/s_base.cpp b/src/script/cpp_api/s_base.cpp index 779819007..1f96373dc 100644 --- a/src/script/cpp_api/s_base.cpp +++ b/src/script/cpp_api/s_base.cpp @@ -25,6 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "filesys.h" #include "log.h" #include "mods.h" +#include "porting.h" #include "util/string.h" @@ -98,6 +99,9 @@ ScriptApiBase::ScriptApiBase() lua_pushstring(m_luastack, DIR_DELIM); lua_setglobal(m_luastack, "DIR_DELIM"); + lua_pushstring(m_luastack, porting::getPlatformName()); + lua_setglobal(m_luastack, "PLATFORM"); + m_server = NULL; m_environment = NULL; m_guiengine = NULL; diff --git a/src/staticobject.cpp b/src/staticobject.cpp index 973257fcf..16d98605b 100644 --- a/src/staticobject.cpp +++ b/src/staticobject.cpp @@ -22,42 +22,31 @@ with this program; if not, write to the Free Software Foundation, Inc., void StaticObject::serialize(std::ostream &os) { - char buf[12]; // type - buf[0] = type; - os.write(buf, 1); + writeU8(os, type); // pos - writeV3S32((u8*)buf, v3s32(pos.X*1000,pos.Y*1000,pos.Z*1000)); - os.write(buf, 12); + writeV3F1000(os, pos); // data os<::iterator i = m_stored.begin(); i != m_stored.end(); ++i) @@ -75,13 +64,10 @@ void StaticObjectList::serialize(std::ostream &os) } void StaticObjectList::deSerialize(std::istream &is) { - char buf[12]; // version - is.read(buf, 1); - u8 version = buf[0]; + u8 version = readU8(is); // count - is.read(buf, 2); - u16 count = readU16((u8*)buf); + u16 count = readU16(is); for(u16 i=0; i buf2(s_size); is.read(&buf2[0], s_size); - std::string s; s.reserve(s_size); s.append(&buf2[0], s_size); return s; @@ -86,9 +86,9 @@ std::wstring deSerializeWideString(std::istream &is) if(is.gcount() != 2) throw SerializationError("deSerializeString: size not read"); u16 s_size = readU16((u8*)buf); - if(s_size == 0) - return L""; std::wstring s; + if(s_size == 0) + return s; s.reserve(s_size); for(u32 i=0; i buf2(s_size); is.read(&buf2[0], s_size); - std::string s; s.reserve(s_size); s.append(&buf2[0], s_size); return s; diff --git a/src/util/serialize.h b/src/util/serialize.h index 3f9925287..79907799f 100644 --- a/src/util/serialize.h +++ b/src/util/serialize.h @@ -21,9 +21,63 @@ with this program; if not, write to the Free Software Foundation, Inc., #define UTIL_SERIALIZE_HEADER #include "../irrlichttypes_bloated.h" +#include "config.h" +#if HAVE_ENDIAN_H +#include +#include // for memcpy +#endif #include #include +#define FIXEDPOINT_FACTOR 1000.0f +#define FIXEDPOINT_INVFACTOR (1.0f/FIXEDPOINT_FACTOR) + +#if HAVE_ENDIAN_H +// use machine native byte swapping routines +// Note: memcpy below is optimized out by modern compilers + +inline void writeU64(u8* data, u64 i) +{ + u64 val = htobe64(i); + memcpy(data, &val, 8); +} + +inline void writeU32(u8* data, u32 i) +{ + u32 val = htobe32(i); + memcpy(data, &val, 4); +} + +inline void writeU16(u8* data, u16 i) +{ + u16 val = htobe16(i); + memcpy(data, &val, 2); +} + +inline u64 readU64(const u8* data) +{ + u64 val; + memcpy(&val, data, 8); + return be64toh(val); +} + +inline u32 readU32(const u8* data) +{ + u32 val; + memcpy(&val, data, 4); + return be32toh(val); +} + +inline u16 readU16(const u8* data) +{ + u16 val; + memcpy(&val, data, 2); + return be16toh(val); +} + +#else +// generic byte-swapping implementation + inline void writeU64(u8 *data, u64 i) { data[0] = ((i>>56)&0xff); @@ -50,11 +104,6 @@ inline void writeU16(u8 *data, u16 i) data[1] = ((i>> 0)&0xff); } -inline void writeU8(u8 *data, u8 i) -{ - data[0] = ((i>> 0)&0xff); -} - inline u64 readU64(const u8 *data) { return ((u64)data[0]<<56) | ((u64)data[1]<<48) @@ -73,6 +122,13 @@ inline u16 readU16(const u8 *data) return (data[0]<<8) | (data[1]<<0); } +#endif + +inline void writeU8(u8 *data, u8 i) +{ + data[0] = ((i>> 0)&0xff); +} + inline u8 readU8(const u8 *data) { return (data[0]<<0); @@ -100,10 +156,10 @@ inline s8 readS8(const u8 *data){ } inline void writeF1000(u8 *data, f32 i){ - writeS32(data, i*1000); + writeS32(data, i*FIXEDPOINT_FACTOR); } inline f32 readF1000(const u8 *data){ - return (f32)readS32(data)/1000.; + return (f32)readS32(data)*FIXEDPOINT_INVFACTOR; } inline void writeV3S32(u8 *data, v3s32 p) @@ -195,20 +251,12 @@ inline v3s16 readV3S16(const u8 *data) inline void writeARGB8(u8 *data, video::SColor p) { - writeU8(&data[0], p.getAlpha()); - writeU8(&data[1], p.getRed()); - writeU8(&data[2], p.getGreen()); - writeU8(&data[3], p.getBlue()); + writeU32(data, p.color); } inline video::SColor readARGB8(const u8 *data) { - video::SColor p( - readU8(&data[0]), - readU8(&data[1]), - readU8(&data[2]), - readU8(&data[3]) - ); + video::SColor p(readU32(data)); return p; } @@ -218,7 +266,7 @@ inline video::SColor readARGB8(const u8 *data) inline void writeU8(std::ostream &os, u8 p) { - char buf[1] = {0}; + char buf[1]; writeU8((u8*)buf, p); os.write(buf, 1); } @@ -231,7 +279,7 @@ inline u8 readU8(std::istream &is) inline void writeU16(std::ostream &os, u16 p) { - char buf[2] = {0}; + char buf[2]; writeU16((u8*)buf, p); os.write(buf, 2); } @@ -244,7 +292,7 @@ inline u16 readU16(std::istream &is) inline void writeU32(std::ostream &os, u32 p) { - char buf[4] = {0}; + char buf[4]; writeU32((u8*)buf, p); os.write(buf, 4); } @@ -257,46 +305,34 @@ inline u32 readU32(std::istream &is) inline void writeS32(std::ostream &os, s32 p) { - char buf[4] = {0}; - writeS32((u8*)buf, p); - os.write(buf, 4); + writeU32(os, (u32) p); } inline s32 readS32(std::istream &is) { - char buf[4] = {0}; - is.read(buf, 4); - return readS32((u8*)buf); + return (s32)readU32(is); } inline void writeS16(std::ostream &os, s16 p) { - char buf[2] = {0}; - writeS16((u8*)buf, p); - os.write(buf, 2); + writeU16(os, (u16) p); } inline s16 readS16(std::istream &is) { - char buf[2] = {0}; - is.read(buf, 2); - return readS16((u8*)buf); + return (s16)readU16(is); } inline void writeS8(std::ostream &os, s8 p) { - char buf[1] = {0}; - writeS8((u8*)buf, p); - os.write(buf, 1); + writeU8(os, (u8) p); } inline s8 readS8(std::istream &is) { - char buf[1] = {0}; - is.read(buf, 1); - return readS8((u8*)buf); + return (s8)readU8(is); } inline void writeF1000(std::ostream &os, f32 p) { - char buf[4] = {0}; + char buf[4]; writeF1000((u8*)buf, p); os.write(buf, 4); } @@ -322,7 +358,7 @@ inline v3f readV3F1000(std::istream &is) inline void writeV2F1000(std::ostream &os, v2f p) { - char buf[8] = {0}; + char buf[8]; writeV2F1000((u8*)buf, p); os.write(buf, 8); } @@ -335,7 +371,7 @@ inline v2f readV2F1000(std::istream &is) inline void writeV2S16(std::ostream &os, v2s16 p) { - char buf[4] = {0}; + char buf[4]; writeV2S16((u8*)buf, p); os.write(buf, 4); } @@ -348,7 +384,7 @@ inline v2s16 readV2S16(std::istream &is) inline void writeV2S32(std::ostream &os, v2s32 p) { - char buf[8] = {0}; + char buf[8]; writeV2S32((u8*)buf, p); os.write(buf, 8); } @@ -361,7 +397,7 @@ inline v2s32 readV2S32(std::istream &is) inline void writeV3S16(std::ostream &os, v3s16 p) { - char buf[6] = {0}; + char buf[6]; writeV3S16((u8*)buf, p); os.write(buf, 6); } @@ -374,7 +410,7 @@ inline v3s16 readV3S16(std::istream &is) inline void writeARGB8(std::ostream &os, video::SColor p) { - char buf[4] = {0}; + char buf[4]; writeARGB8((u8*)buf, p); os.write(buf, 4); } diff --git a/src/voxel.cpp b/src/voxel.cpp index 19f2deb32..13711d1a1 100644 --- a/src/voxel.cpp +++ b/src/voxel.cpp @@ -142,7 +142,7 @@ void VoxelManipulator::print(std::ostream &o, INodeDefManager *ndef, } } -void VoxelManipulator::addArea(VoxelArea area) +void VoxelManipulator::addArea(const VoxelArea &area) { // Cancel if requested area has zero volume if(area.getExtent() == v3s16(0,0,0)) @@ -310,7 +310,8 @@ void VoxelManipulator::unspreadLight(enum LightBank bank, v3s16 p, u8 oldlight, v3s16(-1,0,0), // left }; - addArea(VoxelArea(p - v3s16(1,1,1), p + v3s16(1,1,1))); + VoxelArea voxel_area(p - v3s16(1,1,1), p + v3s16(1,1,1)); + addArea(voxel_area); // Loop through 6 neighbors for(u16 i=0; i<6; i++) @@ -515,7 +516,8 @@ void VoxelManipulator::spreadLight(enum LightBank bank, v3s16 p, v3s16(-1,0,0), // left }; - addArea(VoxelArea(p - v3s16(1,1,1), p + v3s16(1,1,1))); + VoxelArea voxel_area(p - v3s16(1,1,1), p + v3s16(1,1,1)); + addArea(voxel_area); u32 i = m_area.index(p); @@ -619,7 +621,8 @@ void VoxelManipulator::spreadLight(enum LightBank bank, { v3s16 pos = *j; - addArea(VoxelArea(pos - v3s16(1,1,1), pos + v3s16(1,1,1))); + VoxelArea voxel_area(pos - v3s16(1,1,1), pos + v3s16(1,1,1)); + addArea(voxel_area); u32 i = m_area.index(pos); diff --git a/src/voxel.h b/src/voxel.h index 033ad3e45..53b6edbc7 100644 --- a/src/voxel.h +++ b/src/voxel.h @@ -80,7 +80,7 @@ public: Modifying methods */ - void addArea(VoxelArea &a) + void addArea(const VoxelArea &a) { if(getExtent() == v3s16(0,0,0)) { @@ -94,7 +94,7 @@ public: if(a.MaxEdge.Y > MaxEdge.Y) MaxEdge.Y = a.MaxEdge.Y; if(a.MaxEdge.Z > MaxEdge.Z) MaxEdge.Z = a.MaxEdge.Z; } - void addPoint(v3s16 p) + void addPoint(const v3s16 &p) { if(getExtent() == v3s16(0,0,0)) { @@ -111,7 +111,7 @@ public: } // Pad with d nodes - void pad(v3s16 d) + void pad(const v3s16 &d) { MinEdge -= d; MaxEdge += d; @@ -366,7 +366,8 @@ public: */ MapNode getNode(v3s16 p) { - addArea(p); + VoxelArea voxel_area(p); + addArea(voxel_area); if(m_flags[m_area.index(p)] & VOXELFLAG_NO_DATA) { @@ -383,7 +384,8 @@ public: } MapNode getNodeNoEx(v3s16 p) { - addArea(p); + VoxelArea voxel_area(p); + addArea(voxel_area); if(m_flags[m_area.index(p)] & VOXELFLAG_NO_DATA) { @@ -417,7 +419,8 @@ public: } MapNode & getNodeRef(v3s16 p) { - addArea(p); + VoxelArea voxel_area(p); + addArea(voxel_area); if(getFlagsRefUnsafe(p) & VOXELFLAG_NO_DATA) { /*dstream<<"EXCEPT: VoxelManipulator::getNode(): " @@ -432,7 +435,8 @@ public: } void setNode(v3s16 p, const MapNode &n) { - addArea(p); + VoxelArea voxel_area(p); + addArea(voxel_area); m_data[m_area.index(p)] = n; m_flags[m_area.index(p)] &= ~VOXELFLAG_NO_DATA; @@ -499,7 +503,7 @@ public: void print(std::ostream &o, INodeDefManager *nodemgr, VoxelPrintMode mode=VOXELPRINT_MATERIAL); - void addArea(VoxelArea area); + void addArea(const VoxelArea &area); /* Copy data and set flags to 0