From bc7b07af1057c38ce998085aa511a62cfdb8c115 Mon Sep 17 00:00:00 2001 From: proller Date: Tue, 7 Dec 2021 03:08:37 +0300 Subject: [PATCH 01/36] Breaking world limits. Part 1 --- .gitignore | 1 + builtin/game/chat.lua | 2 +- src/CMakeLists.txt | 1 + src/client/camera.cpp | 6 +- src/client/camera.h | 4 +- src/client/client.cpp | 72 +++--- src/client/client.h | 30 +-- src/client/clientenvironment.cpp | 4 +- src/client/clientenvironment.h | 6 +- src/client/clientlauncher.cpp | 6 +- src/client/clientmap.cpp | 56 ++--- src/client/clientmap.h | 32 +-- src/client/clouds.cpp | 2 +- src/client/clouds.h | 4 +- src/client/content_cao.cpp | 12 +- src/client/content_cao.h | 2 +- src/client/content_mapblock.cpp | 104 ++++----- src/client/content_mapblock.h | 10 +- src/client/game.cpp | 82 +++---- src/client/hud.cpp | 20 +- src/client/hud.h | 14 +- src/client/localplayer.cpp | 74 +++--- src/client/localplayer.h | 12 +- src/client/mapblock_mesh.cpp | 166 ++++++------- src/client/mapblock_mesh.h | 22 +- src/client/mesh_generator_thread.cpp | 24 +- src/client/mesh_generator_thread.h | 22 +- src/client/minimap.cpp | 48 ++-- src/client/minimap.h | 22 +- src/client/particles.cpp | 10 +- src/client/particles.h | 6 +- src/client/shadows/dynamicshadows.cpp | 2 +- src/client/shadows/dynamicshadows.h | 2 +- src/client/tile.cpp | 2 +- src/clientiface.cpp | 28 +-- src/clientiface.h | 28 +-- src/cmake_config.h.in | 1 + src/collision.cpp | 14 +- src/collision.h | 2 +- src/constants.h | 6 + src/content_nodemeta.cpp | 2 +- src/database/database-dummy.cpp | 18 +- src/database/database-dummy.h | 10 +- src/database/database-leveldb.cpp | 16 +- src/database/database-leveldb.h | 8 +- src/database/database-postgresql.cpp | 10 +- src/database/database-postgresql.h | 12 +- src/database/database-redis.cpp | 16 +- src/database/database-redis.h | 8 +- src/database/database-sqlite3.cpp | 10 +- src/database/database-sqlite3.h | 10 +- src/database/database.cpp | 56 ++++- src/database/database.h | 16 +- src/defaultsettings.cpp | 2 +- src/emerge.cpp | 60 ++--- src/emerge.h | 26 +-- src/environment.cpp | 18 +- src/environment.h | 2 +- src/face_position_cache.cpp | 12 +- src/face_position_cache.h | 6 +- src/gui/guiHyperText.cpp | 8 +- src/gui/guiHyperText.h | 4 +- src/inventorymanager.h | 4 +- src/irr_v2d.h | 3 + src/irr_v3d.h | 3 + src/irrlichttypes.h | 14 ++ src/main.cpp | 8 +- src/map.cpp | 312 +++++++++++++------------ src/map.h | 125 +++++----- src/mapblock.cpp | 22 +- src/mapblock.h | 57 ++--- src/mapgen/cavegen.cpp | 102 ++++---- src/mapgen/cavegen.h | 48 ++-- src/mapgen/dungeongen.cpp | 176 +++++++------- src/mapgen/dungeongen.h | 46 ++-- src/mapgen/mapgen.cpp | 138 +++++------ src/mapgen/mapgen.h | 74 +++--- src/mapgen/mapgen_carpathian.cpp | 42 ++-- src/mapgen/mapgen_carpathian.h | 12 +- src/mapgen/mapgen_flat.cpp | 66 +++--- src/mapgen/mapgen_flat.h | 18 +- src/mapgen/mapgen_fractal.cpp | 46 ++-- src/mapgen/mapgen_fractal.h | 12 +- src/mapgen/mapgen_singlenode.cpp | 16 +- src/mapgen/mapgen_singlenode.h | 2 +- src/mapgen/mapgen_v5.cpp | 44 ++-- src/mapgen/mapgen_v5.h | 12 +- src/mapgen/mapgen_v6.cpp | 188 +++++++-------- src/mapgen/mapgen_v6.h | 46 ++-- src/mapgen/mapgen_v7.cpp | 84 +++---- src/mapgen/mapgen_v7.h | 40 ++-- src/mapgen/mapgen_valleys.cpp | 52 ++--- src/mapgen/mapgen_valleys.h | 12 +- src/mapgen/mg_biome.cpp | 24 +- src/mapgen/mg_biome.h | 50 ++-- src/mapgen/mg_decoration.cpp | 74 +++--- src/mapgen/mg_decoration.h | 18 +- src/mapgen/mg_ore.cpp | 16 +- src/mapgen/mg_ore.h | 22 +- src/mapgen/mg_schematic.cpp | 44 ++-- src/mapgen/mg_schematic.h | 14 +- src/mapgen/treegen.cpp | 82 +++---- src/mapgen/treegen.h | 10 +- src/mapnode.cpp | 34 +-- src/mapnode.h | 4 +- src/mapsector.cpp | 20 +- src/mapsector.h | 18 +- src/network/clientpackethandler.cpp | 22 +- src/network/networkprotocol.h | 14 +- src/network/serverpackethandler.cpp | 38 +-- src/nodedef.h | 4 +- src/nodemetadata.cpp | 26 +-- src/nodemetadata.h | 11 +- src/nodetimer.cpp | 4 +- src/nodetimer.h | 20 +- src/pathfinder.cpp | 220 ++++++++--------- src/pathfinder.h | 6 +- src/raycast.cpp | 2 +- src/raycast.h | 6 +- src/reflowscan.cpp | 12 +- src/reflowscan.h | 6 +- src/rollback.cpp | 18 +- src/rollback.h | 12 +- src/rollback_interface.cpp | 4 +- src/rollback_interface.h | 12 +- src/script/common/c_content.cpp | 8 +- src/script/common/c_converter.cpp | 33 +++ src/script/common/c_converter.h | 30 +++ src/script/cpp_api/s_client.cpp | 8 +- src/script/cpp_api/s_client.h | 4 +- src/script/cpp_api/s_env.cpp | 20 +- src/script/cpp_api/s_env.h | 6 +- src/script/cpp_api/s_item.cpp | 2 +- src/script/cpp_api/s_item.h | 2 +- src/script/cpp_api/s_node.cpp | 32 +-- src/script/cpp_api/s_node.h | 16 +- src/script/cpp_api/s_nodemeta.cpp | 12 +- src/script/lua_api/l_areastore.cpp | 12 +- src/script/lua_api/l_client.cpp | 4 +- src/script/lua_api/l_env.cpp | 152 ++++++------ src/script/lua_api/l_env.h | 14 +- src/script/lua_api/l_inventory.cpp | 4 +- src/script/lua_api/l_mapgen.cpp | 66 +++--- src/script/lua_api/l_minimap.cpp | 4 +- src/script/lua_api/l_nodemeta.cpp | 4 +- src/script/lua_api/l_nodemeta.h | 6 +- src/script/lua_api/l_nodetimer.cpp | 2 +- src/script/lua_api/l_nodetimer.h | 6 +- src/script/lua_api/l_noise.cpp | 8 +- src/script/lua_api/l_noise.h | 2 +- src/script/lua_api/l_object.cpp | 2 +- src/script/lua_api/l_rollback.cpp | 4 +- src/script/lua_api/l_vmanip.cpp | 40 ++-- src/script/lua_api/l_vmanip.h | 4 +- src/server.cpp | 36 +-- src/server.h | 10 +- src/server/player_sao.cpp | 10 +- src/server/player_sao.h | 8 +- src/server/serveractiveobject.h | 2 +- src/serverenvironment.cpp | 106 ++++----- src/serverenvironment.h | 40 ++-- src/settings.cpp | 19 ++ src/settings.h | 3 + src/unittest/test.cpp | 112 ++++----- src/unittest/test_areastore.cpp | 49 ++-- src/unittest/test_schematic.cpp | 6 +- src/unittest/test_voxelalgorithms.cpp | 10 +- src/unittest/test_voxelarea.cpp | 218 ++++++++--------- src/unittest/test_voxelmanipulator.cpp | 22 +- src/util/areastore.cpp | 32 +-- src/util/areastore.h | 22 +- src/util/basic_macros.h | 2 +- src/util/directiontables.cpp | 140 +++++------ src/util/directiontables.h | 8 +- src/util/numeric.cpp | 4 +- src/util/numeric.h | 64 ++--- src/util/pointedthing.cpp | 18 +- src/util/pointedthing.h | 14 +- src/util/serialize.h | 32 +++ src/voxel.cpp | 10 +- src/voxel.h | 90 +++---- src/voxelalgorithms.cpp | 126 +++++----- src/voxelalgorithms.h | 18 +- 183 files changed, 2977 insertions(+), 2743 deletions(-) diff --git a/.gitignore b/.gitignore index 2e1e68157a..22b28586fa 100644 --- a/.gitignore +++ b/.gitignore @@ -28,6 +28,7 @@ gtags.files # Visual Studio Code & plugins .vscode/ build/.cmake/ +.cache # Gradle .gradle diff --git a/builtin/game/chat.lua b/builtin/game/chat.lua index 99296f7824..915b0e79e7 100644 --- a/builtin/game/chat.lua +++ b/builtin/game/chat.lua @@ -524,7 +524,7 @@ end -- Teleports player to

if possible local function teleport_to_pos(name, p) - local lm = 31000 + local lm = tonumber(core.settings:get("mapgen_limit")) if p.x < -lm or p.x > lm or p.y < -lm or p.y > lm or p.z < -lm or p.z > lm then return false, S("Cannot teleport out of map bounds!") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4803b475bf..3632ebb868 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -31,6 +31,7 @@ if(NOT (BUILD_CLIENT OR BUILD_SERVER)) set(BUILD_SERVER TRUE) endif() +option(USE_POS32 "32 bit positions (experimental, not compatible with 16 bit)" FALSE) option(ENABLE_CURL "Enable cURL support for fetching media" TRUE) set(USE_CURL FALSE) diff --git a/src/client/camera.cpp b/src/client/camera.cpp index 3712d77eae..534e3e8a2f 100644 --- a/src/client/camera.cpp +++ b/src/client/camera.cpp @@ -452,11 +452,11 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 busytime, f32 tool_r // Update offset if too far away from the center of the map m_camera_offset.X += CAMERA_OFFSET_STEP* - (((s16)(my_cp.X/BS) - m_camera_offset.X)/CAMERA_OFFSET_STEP); + (((POS)(my_cp.X/BS) - m_camera_offset.X)/CAMERA_OFFSET_STEP); m_camera_offset.Y += CAMERA_OFFSET_STEP* - (((s16)(my_cp.Y/BS) - m_camera_offset.Y)/CAMERA_OFFSET_STEP); + (((POS)(my_cp.Y/BS) - m_camera_offset.Y)/CAMERA_OFFSET_STEP); m_camera_offset.Z += CAMERA_OFFSET_STEP* - (((s16)(my_cp.Z/BS) - m_camera_offset.Z)/CAMERA_OFFSET_STEP); + (((POS)(my_cp.Z/BS) - m_camera_offset.Z)/CAMERA_OFFSET_STEP); // Set camera node transformation m_cameranode->setPosition(my_cp-intToFloat(m_camera_offset, BS)); diff --git a/src/client/camera.h b/src/client/camera.h index 3e1cb4fdff..c293156cd5 100644 --- a/src/client/camera.h +++ b/src/client/camera.h @@ -110,7 +110,7 @@ class Camera } // Get the camera offset - inline v3s16 getOffset() const + inline v3POS getOffset() const { return m_camera_offset; } @@ -213,7 +213,7 @@ class Camera // Absolute camera direction v3f m_camera_direction; // Camera offset - v3s16 m_camera_offset; + v3POS m_camera_offset; bool m_stepheight_smooth_active = false; diff --git a/src/client/client.cpp b/src/client/client.cpp index 3ee1298ff1..a7a0abff77 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -384,7 +384,7 @@ void Client::step(float dtime) */ const float map_timer_and_unload_dtime = 5.25; if(m_map_timer_and_unload_interval.step(dtime, map_timer_and_unload_dtime)) { - std::vector deleted_blocks; + std::vector deleted_blocks; m_env.getMap().timerUpdate(map_timer_and_unload_dtime, g_settings->getFloat("client_unload_unused_data_timeout"), g_settings->getS32("client_mapblock_limit"), @@ -395,8 +395,8 @@ void Client::step(float dtime) NOTE: This loop is intentionally iterated the way it is. */ - std::vector::iterator i = deleted_blocks.begin(); - std::vector sendlist; + std::vector::iterator i = deleted_blocks.begin(); + std::vector sendlist; for(;;) { if(sendlist.size() == 255 || i == deleted_blocks.end()) { if(sendlist.empty()) @@ -404,8 +404,8 @@ void Client::step(float dtime) /* [0] u16 command [2] u8 count - [3] v3s16 pos_0 - [3+6] v3s16 pos_1 + [3] v3POS pos_0 + [3+6] v3POS pos_1 ... */ @@ -489,7 +489,7 @@ void Client::step(float dtime) */ { int num_processed_meshes = 0; - std::vector blocks_to_ack; + std::vector blocks_to_ack; while (!m_mesh_update_thread.m_queue_out.empty()) { num_processed_meshes++; @@ -1097,24 +1097,24 @@ void Client::startAuth(AuthMechanism chosen_auth_mechanism) } } -void Client::sendDeletedBlocks(std::vector &blocks) +void Client::sendDeletedBlocks(std::vector &blocks) { - NetworkPacket pkt(TOSERVER_DELETEDBLOCKS, 1 + sizeof(v3s16) * blocks.size()); + NetworkPacket pkt(TOSERVER_DELETEDBLOCKS, 1 + sizeof(v3POS) * blocks.size()); pkt << (u8) blocks.size(); - for (const v3s16 &block : blocks) { + for (const v3POS &block : blocks) { pkt << block; } Send(&pkt); } -void Client::sendGotBlocks(const std::vector &blocks) +void Client::sendGotBlocks(const std::vector &blocks) { NetworkPacket pkt(TOSERVER_GOTBLOCKS, 1 + 6 * blocks.size()); pkt << (u8) blocks.size(); - for (const v3s16 &block : blocks) + for (const v3POS &block : blocks) pkt << block; Send(&pkt); @@ -1135,7 +1135,7 @@ void Client::sendRemovedSounds(std::vector &soundList) Send(&pkt); } -void Client::sendNodemetaFields(v3s16 p, const std::string &formname, +void Client::sendNodemetaFields(v3POS p, const std::string &formname, const StringMap &fields) { size_t fields_size = fields.size(); @@ -1332,9 +1332,9 @@ void Client::sendHaveMedia(const std::vector &tokens) Send(&pkt); } -void Client::removeNode(v3s16 p) +void Client::removeNode(v3POS p) { - std::map modified_blocks; + std::map modified_blocks; try { m_env.getMap().removeNodeAndUpdate(p, modified_blocks); @@ -1354,10 +1354,10 @@ void Client::removeNode(v3s16 p) * @param is_valid_position * @return */ -MapNode Client::CSMGetNode(v3s16 p, bool *is_valid_position) +MapNode Client::CSMGetNode(v3POS p, bool *is_valid_position) { if (checkCSMRestrictionFlag(CSMRestrictionFlags::CSM_RF_LOOKUP_NODES)) { - v3s16 ppos = floatToInt(m_env.getLocalPlayer()->getPosition(), BS); + v3POS ppos = floatToInt(m_env.getLocalPlayer()->getPosition(), BS); if ((u32) ppos.getDistanceFrom(p) > m_csm_restriction_noderange) { *is_valid_position = false; return {}; @@ -1366,36 +1366,36 @@ MapNode Client::CSMGetNode(v3s16 p, bool *is_valid_position) return m_env.getMap().getNode(p, is_valid_position); } -int Client::CSMClampRadius(v3s16 pos, int radius) +int Client::CSMClampRadius(v3POS pos, int radius) { if (!checkCSMRestrictionFlag(CSMRestrictionFlags::CSM_RF_LOOKUP_NODES)) return radius; // This is approximate and will cause some allowed nodes to be excluded - v3s16 ppos = floatToInt(m_env.getLocalPlayer()->getPosition(), BS); + v3POS ppos = floatToInt(m_env.getLocalPlayer()->getPosition(), BS); u32 distance = ppos.getDistanceFrom(pos); if (distance >= m_csm_restriction_noderange) return 0; return std::min(radius, m_csm_restriction_noderange - distance); } -v3s16 Client::CSMClampPos(v3s16 pos) +v3POS Client::CSMClampPos(v3POS pos) { if (!checkCSMRestrictionFlag(CSMRestrictionFlags::CSM_RF_LOOKUP_NODES)) return pos; - v3s16 ppos = floatToInt(m_env.getLocalPlayer()->getPosition(), BS); + v3POS ppos = floatToInt(m_env.getLocalPlayer()->getPosition(), BS); const int range = m_csm_restriction_noderange; - return v3s16( + return v3POS( core::clamp(pos.X, (int)ppos.X - range, (int)ppos.X + range), core::clamp(pos.Y, (int)ppos.Y - range, (int)ppos.Y + range), core::clamp(pos.Z, (int)ppos.Z - range, (int)ppos.Z + range) ); } -void Client::addNode(v3s16 p, MapNode n, bool remove_metadata) +void Client::addNode(v3POS p, MapNode n, bool remove_metadata) { //TimeTaker timer1("Client::addNode()"); - std::map modified_blocks; + std::map modified_blocks; try { //TimeTaker timer3("Client::addNode(): addNodeAndUpdate"); @@ -1520,15 +1520,15 @@ int Client::getCrackLevel() return m_crack_level; } -v3s16 Client::getCrackPos() +v3POS Client::getCrackPos() { return m_crack_pos; } -void Client::setCrack(int level, v3s16 pos) +void Client::setCrack(int level, v3POS pos) { int old_crack_level = m_crack_level; - v3s16 old_crack_pos = m_crack_pos; + v3POS old_crack_pos = m_crack_pos; m_crack_level = level; m_crack_pos = pos; @@ -1597,7 +1597,7 @@ void Client::typeChatMessage(const std::wstring &message) sendChatMessage(message); } -void Client::addUpdateMeshTask(v3s16 p, bool ack_to_server, bool urgent) +void Client::addUpdateMeshTask(v3BPOS p, bool ack_to_server, bool urgent) { // Check if the block exists to begin with. In the case when a non-existing // neighbor is automatically added, it may not. In that case we don't want @@ -1609,7 +1609,7 @@ void Client::addUpdateMeshTask(v3s16 p, bool ack_to_server, bool urgent) m_mesh_update_thread.updateBlock(&m_env.getMap(), p, ack_to_server, urgent); } -void Client::addUpdateMeshTaskWithEdge(v3s16 blockpos, bool ack_to_server, bool urgent) +void Client::addUpdateMeshTaskWithEdge(v3BPOS blockpos, bool ack_to_server, bool urgent) { try{ addUpdateMeshTask(blockpos, ack_to_server, urgent); @@ -1620,24 +1620,24 @@ void Client::addUpdateMeshTaskWithEdge(v3s16 blockpos, bool ack_to_server, bool for (int i=0;i<6;i++) { try{ - v3s16 p = blockpos + g_6dirs[i]; + v3BPOS p = blockpos + g_6dirs[i]; addUpdateMeshTask(p, false, urgent); } catch(InvalidPositionException &e){} } } -void Client::addUpdateMeshTaskForNode(v3s16 nodepos, bool ack_to_server, bool urgent) +void Client::addUpdateMeshTaskForNode(v3POS nodepos, bool ack_to_server, bool urgent) { { - v3s16 p = nodepos; + v3POS p = nodepos; infostream<<"Client::addUpdateMeshTaskForNode(): " <<"("< &blocks); - void sendGotBlocks(const std::vector &blocks); + void sendDeletedBlocks(std::vector &blocks); + void sendGotBlocks(const std::vector &blocks); void sendRemovedSounds(std::vector &soundList); // Helper function @@ -509,7 +509,7 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef // Block mesh animation parameters float m_animation_time = 0.0f; int m_crack_level = -1; - v3s16 m_crack_pos; + v3POS m_crack_pos; // 0 <= m_daynight_i < DAYNIGHT_CACHE_COUNT //s32 m_daynight_i; //u32 m_daynight_ratio; diff --git a/src/client/clientenvironment.cpp b/src/client/clientenvironment.cpp index 448af36c65..c7e3824036 100644 --- a/src/client/clientenvironment.cpp +++ b/src/client/clientenvironment.cpp @@ -301,7 +301,7 @@ void ClientEnvironment::step(float dtime) // (day: LIGHT_SUN, night: 0) MapNode node_at_lplayer(CONTENT_AIR, 0x0f, 0); - v3s16 p = lplayer->getLightPosition(); + v3POS p = lplayer->getLightPosition(); node_at_lplayer = m_map->getNode(p); u16 light = getInteriorLight(node_at_lplayer, 0, m_client->ndef()); @@ -504,7 +504,7 @@ void ClientEnvironment::getSelectedActiveObjects( selection_box.MaxEdge + pos); v3f current_intersection; - v3s16 current_normal; + v3POS current_normal; if (boxLineCollision(offsetted_box, shootline_on_map.start, line_vector, ¤t_intersection, ¤t_normal)) { objects.emplace_back((s16) obj->getId(), current_intersection, current_normal, diff --git a/src/client/clientenvironment.h b/src/client/clientenvironment.h index 864496a415..d433b98a87 100644 --- a/src/client/clientenvironment.h +++ b/src/client/clientenvironment.h @@ -138,9 +138,9 @@ class ClientEnvironment : public Environment const std::list &getPlayerNames() { return m_player_names; } void addPlayerName(const std::string &name) { m_player_names.push_back(name); } void removePlayerName(const std::string &name) { m_player_names.remove(name); } - void updateCameraOffset(const v3s16 &camera_offset) + void updateCameraOffset(const v3POS &camera_offset) { m_camera_offset = camera_offset; } - v3s16 getCameraOffset() const { return m_camera_offset; } + v3POS getCameraOffset() const { return m_camera_offset; } private: ClientMap *m_map; LocalPlayer *m_local_player = nullptr; @@ -152,5 +152,5 @@ class ClientEnvironment : public Environment std::queue m_client_event_queue; IntervalLimiter m_active_object_light_update_interval; std::list m_player_names; - v3s16 m_camera_offset; + v3POS m_camera_offset; }; diff --git a/src/client/clientlauncher.cpp b/src/client/clientlauncher.cpp index 95be72ca04..3d8740cbfb 100644 --- a/src/client/clientlauncher.cpp +++ b/src/client/clientlauncher.cpp @@ -619,18 +619,18 @@ void ClientLauncher::speed_tests() { TimeTaker timer("Testing std::map speed"); - std::map map1; + std::map map1; tempf = -324; const s16 ii = 300; for (s16 y = 0; y < ii; y++) { for (s16 x = 0; x < ii; x++) { - map1[v2s16(x, y)] = tempf; + map1[v2POS(x, y)] = tempf; tempf += 1; } } for (s16 y = ii - 1; y >= 0; y--) { for (s16 x = 0; x < ii; x++) { - tempf = map1[v2s16(x, y)]; + tempf = map1[v2POS(x, y)]; } } } diff --git a/src/client/clientmap.cpp b/src/client/clientmap.cpp index 1a024e464b..fa3fca79bb 100644 --- a/src/client/clientmap.cpp +++ b/src/client/clientmap.cpp @@ -38,7 +38,7 @@ void MeshBufListList::clear() list.clear(); } -void MeshBufListList::add(scene::IMeshBuffer *buf, v3s16 position, u8 layer) +void MeshBufListList::add(scene::IMeshBuffer *buf, v3BPOS position, u8 layer) { // Append to the correct layer std::vector &list = lists[layer]; @@ -74,7 +74,7 @@ ClientMap::ClientMap( m_client(client), m_rendering_engine(rendering_engine), m_control(control), - m_drawlist(MapBlockComparer(v3s16(0,0,0))) + m_drawlist(MapBlockComparer(v3BPOS(0,0,0))) { /* @@ -100,7 +100,7 @@ ClientMap::ClientMap( } -MapSector * ClientMap::emergeSector(v2s16 p2d) +MapSector * ClientMap::emergeSector(v2BPOS p2d) { // Check that it doesn't exist already MapSector *sector = getSectorNoGenerate(p2d); @@ -131,15 +131,15 @@ void ClientMap::OnRegisterSceneNode() } } -void ClientMap::getBlocksInViewRange(v3s16 cam_pos_nodes, - v3s16 *p_blocks_min, v3s16 *p_blocks_max, float range) +void ClientMap::getBlocksInViewRange(v3POS cam_pos_nodes, + v3POS *p_blocks_min, v3POS *p_blocks_max, float range) { if (range <= 0.0f) range = m_control.wanted_range; - v3s16 box_nodes_d = range * v3s16(1, 1, 1); + v3POS box_nodes_d = range * v3POS(1, 1, 1); // Define p_nodes_min/max as v3s32 because 'cam_pos_nodes -/+ box_nodes_d' - // can exceed the range of v3s16 when a large view range is used near the + // can exceed the range of v3POS when a large view range is used near the // world edges. v3s32 p_nodes_min( cam_pos_nodes.X - box_nodes_d.X, @@ -151,11 +151,11 @@ void ClientMap::getBlocksInViewRange(v3s16 cam_pos_nodes, cam_pos_nodes.Z + box_nodes_d.Z); // Take a fair amount as we will be dropping more out later // Umm... these additions are a bit strange but they are needed. - *p_blocks_min = v3s16( + *p_blocks_min = v3POS( p_nodes_min.X / MAP_BLOCKSIZE - 3, p_nodes_min.Y / MAP_BLOCKSIZE - 3, p_nodes_min.Z / MAP_BLOCKSIZE - 3); - *p_blocks_max = v3s16( + *p_blocks_max = v3POS( p_nodes_max.X / MAP_BLOCKSIZE + 1, p_nodes_max.Y / MAP_BLOCKSIZE + 1, p_nodes_max.Z / MAP_BLOCKSIZE + 1); @@ -180,10 +180,10 @@ void ClientMap::updateDrawList() // Blocks are cropped better when they are drawn. const f32 camera_fov = m_camera_fov * 1.1f; - v3s16 cam_pos_nodes = floatToInt(camera_position, BS); + v3POS cam_pos_nodes = floatToInt(camera_position, BS); - v3s16 p_blocks_min; - v3s16 p_blocks_max; + v3POS p_blocks_min; + v3POS p_blocks_max; getBlocksInViewRange(cam_pos_nodes, &p_blocks_min, &p_blocks_max); // Read the vision range, unless unlimited range is enabled. @@ -206,8 +206,8 @@ void ClientMap::updateDrawList() occlusion_culling_enabled = false; } - v3s16 camera_block = getContainerPos(cam_pos_nodes, MAP_BLOCKSIZE); - m_drawlist = std::map(MapBlockComparer(camera_block)); + v3BPOS camera_block = getContainerPos(cam_pos_nodes, MAP_BLOCKSIZE); + m_drawlist = std::map(MapBlockComparer(camera_block)); // Uncomment to debug occluded blocks in the wireframe mode // TODO: Include this as a flag for an extended debugging setting @@ -216,7 +216,7 @@ void ClientMap::updateDrawList() for (const auto §or_it : m_sectors) { MapSector *sector = sector_it.second; - v2s16 sp = sector->getPos(); + v2BPOS sp = sector->getPos(); blocks_loaded += sector->size(); if (!m_control.range_all) { @@ -245,8 +245,8 @@ void ClientMap::updateDrawList() continue; } - v3s16 block_coord = block->getPos(); - v3s16 block_position = block->getPosRelative() + MAP_BLOCKSIZE / 2; + v3BPOS block_coord = block->getPos(); + v3POS block_position = block->getPosRelative() + MAP_BLOCKSIZE / 2; // First, perform a simple distance check, with a padding of one extra block. if (!m_control.range_all && @@ -330,11 +330,11 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass) MeshBufListList grouped_buffers; struct DrawDescriptor { - v3s16 m_pos; + v3POS m_pos; scene::IMeshBuffer *m_buffer; bool m_reuse_material; - DrawDescriptor(const v3s16 &pos, scene::IMeshBuffer *buffer, bool reuse_material) : + DrawDescriptor(const v3POS &pos, scene::IMeshBuffer *buffer, bool reuse_material) : m_pos(pos), m_buffer(buffer), m_reuse_material(reuse_material) {} }; @@ -343,7 +343,7 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass) video::SMaterial previous_material; for (auto &i : m_drawlist) { - v3s16 block_pos = i.first; + v3BPOS block_pos = i.first; MapBlock *block = i.second; // If the mesh of the block happened to get deleted, ignore it @@ -511,7 +511,7 @@ static bool getVisibleBrightness(Map *map, const v3f &p0, v3f dir, float step, bool allow_non_sunlight_propagates = false; // Check content nearly at camera position { - v3s16 p = floatToInt(p0 /*+ dir * 3*BS*/, BS); + v3POS p = floatToInt(p0 /*+ dir * 3*BS*/, BS); MapNode n = map->getNode(p); if(ndef->get(n).param_type == CPT_LIGHT && !ndef->get(n).sunlight_propagates) @@ -519,7 +519,7 @@ static bool getVisibleBrightness(Map *map, const v3f &p0, v3f dir, float step, } // If would start at CONTENT_IGNORE, start closer { - v3s16 p = floatToInt(pf, BS); + v3POS p = floatToInt(pf, BS); MapNode n = map->getNode(p); if(n.getContent() == CONTENT_IGNORE){ float newd = 2*BS; @@ -533,7 +533,7 @@ static bool getVisibleBrightness(Map *map, const v3f &p0, v3f dir, float step, distance += step; step *= step_multiplier; - v3s16 p = floatToInt(pf, BS); + v3POS p = floatToInt(pf, BS); MapNode n = map->getNode(p); if (allow_allowing_non_sunlight_propagates && i == 0 && ndef->get(n).param_type == CPT_LIGHT && @@ -717,7 +717,7 @@ void ClientMap::renderMapShadows(video::IVideoDriver *driver, if (count > high_bound) break; - v3s16 block_pos = i.first; + v3BPOS block_pos = i.first; MapBlock *block = i.second; // If the mesh of the block happened to get deleted, ignore it @@ -811,12 +811,12 @@ void ClientMap::updateDrawListShadow(const v3f &shadow_light_pos, const v3f &sha // projection. const f32 camera_fov = m_camera_fov * 1.9f; - v3s16 cam_pos_nodes = floatToInt(camera_position, BS); - v3s16 p_blocks_min; - v3s16 p_blocks_max; + v3POS cam_pos_nodes = floatToInt(camera_position, BS); + v3POS p_blocks_min; + v3POS p_blocks_max; getBlocksInViewRange(cam_pos_nodes, &p_blocks_min, &p_blocks_max, shadow_range); - std::vector blocks_in_range; + std::vector blocks_in_range; for (auto &i : m_drawlist_shadow) { MapBlock *block = i.second; diff --git a/src/client/clientmap.h b/src/client/clientmap.h index b4dc423950..288c2b0eea 100644 --- a/src/client/clientmap.h +++ b/src/client/clientmap.h @@ -38,7 +38,7 @@ struct MapDrawControl struct MeshBufList { video::SMaterial m; - std::vector> bufs; + std::vector> bufs; }; struct MeshBufListList @@ -51,7 +51,7 @@ struct MeshBufListList std::vector lists[MAX_TILE_LAYERS]; void clear(); - void add(scene::IMeshBuffer *buf, v3s16 position, u8 layer); + void add(scene::IMeshBuffer *buf, v3BPOS position, u8 layer); }; class Client; @@ -85,16 +85,16 @@ class ClientMap : public Map, public scene::ISceneNode ISceneNode::drop(); } - void updateCamera(const v3f &pos, const v3f &dir, f32 fov, const v3s16 &offset) + void updateCamera(const v3f &pos, const v3f &dir, f32 fov, const v3POS &offset) { - v3s16 previous_block = getContainerPos(floatToInt(m_camera_position, BS) + m_camera_offset, MAP_BLOCKSIZE); + v3BPOS previous_block = getContainerPos(floatToInt(m_camera_position, BS) + m_camera_offset, MAP_BLOCKSIZE); m_camera_position = pos; m_camera_direction = dir; m_camera_fov = fov; m_camera_offset = offset; - v3s16 current_block = getContainerPos(floatToInt(m_camera_position, BS) + m_camera_offset, MAP_BLOCKSIZE); + v3BPOS current_block = getContainerPos(floatToInt(m_camera_position, BS) + m_camera_offset, MAP_BLOCKSIZE); // reorder the blocks when camera crosses block boundary if (previous_block != current_block) @@ -104,9 +104,9 @@ class ClientMap : public Map, public scene::ISceneNode /* Forcefully get a sector from somewhere */ - MapSector * emergeSector(v2s16 p); + MapSector * emergeSector(v2BPOS p); - //void deSerializeSector(v2s16 p2d, std::istream &is); + //void deSerializeSector(v2POS p2d, std::istream &is); /* ISceneNode methods @@ -126,8 +126,8 @@ class ClientMap : public Map, public scene::ISceneNode return m_box; } - void getBlocksInViewRange(v3s16 cam_pos_nodes, - v3s16 *p_blocks_min, v3s16 *p_blocks_max, float range=-1.0f); + void getBlocksInViewRange(v3POS cam_pos_nodes, + v3POS *p_blocks_min, v3POS *p_blocks_max, float range=-1.0f); void updateDrawList(); void updateDrawListShadow(const v3f &shadow_light_pos, const v3f &shadow_light_dir, float shadow_range); // Returns true if draw list needs updating before drawing the next frame. @@ -154,9 +154,9 @@ class ClientMap : public Map, public scene::ISceneNode class MapBlockComparer { public: - MapBlockComparer(const v3s16 &camera_block) : m_camera_block(camera_block) {} + MapBlockComparer(const v3BPOS &camera_block) : m_camera_block(camera_block) {} - bool operator() (const v3s16 &left, const v3s16 &right) const + bool operator() (const v3BPOS &left, const v3BPOS &right) const { auto distance_left = left.getDistanceFromSQ(m_camera_block); auto distance_right = right.getDistanceFromSQ(m_camera_block); @@ -164,7 +164,7 @@ class ClientMap : public Map, public scene::ISceneNode } private: - v3s16 m_camera_block; + v3BPOS m_camera_block; }; Client *m_client; @@ -178,13 +178,13 @@ class ClientMap : public Map, public scene::ISceneNode v3f m_camera_position = v3f(0,0,0); v3f m_camera_direction = v3f(0,0,1); f32 m_camera_fov = M_PI; - v3s16 m_camera_offset; + v3POS m_camera_offset; - std::map m_drawlist; - std::map m_drawlist_shadow; + std::map m_drawlist; + std::map m_drawlist_shadow; bool m_needs_update_drawlist; - std::set m_last_drawn_sectors; + std::set m_last_drawn_sectors; bool m_cache_trilinear_filter; bool m_cache_bilinear_filter; diff --git a/src/client/clouds.cpp b/src/client/clouds.cpp index 383a1d799e..d01f932e1a 100644 --- a/src/client/clouds.cpp +++ b/src/client/clouds.cpp @@ -120,7 +120,7 @@ void Clouds::render() // The center point of drawing in the noise v2f center_of_drawing_in_noise_f = -cloud_origin_from_camera_f; // The integer center point of drawing in the noise - v2s16 center_of_drawing_in_noise_i( + v2POS center_of_drawing_in_noise_i( std::floor(center_of_drawing_in_noise_f.X / cloud_size), std::floor(center_of_drawing_in_noise_f.Y / cloud_size) ); diff --git a/src/client/clouds.h b/src/client/clouds.h index c009a05b76..e9c5d0f61b 100644 --- a/src/client/clouds.h +++ b/src/client/clouds.h @@ -72,7 +72,7 @@ class Clouds : public scene::ISceneNode void update(const v3f &camera_p, const video::SColorf &color); - void updateCameraOffset(const v3s16 &camera_offset) + void updateCameraOffset(const v3POS &camera_offset) { m_camera_offset = camera_offset; updateBox(); @@ -135,7 +135,7 @@ class Clouds : public scene::ISceneNode u32 m_seed; v3f m_camera_pos; v2f m_origin; - v3s16 m_camera_offset; + v3POS m_camera_offset; video::SColorf m_color = video::SColorf(1.0f, 1.0f, 1.0f, 1.0f); CloudParams m_params; bool m_camera_inside_cloud = false; diff --git a/src/client/content_cao.cpp b/src/client/content_cao.cpp index a80a3ce4ee..62d5cc5030 100644 --- a/src/client/content_cao.cpp +++ b/src/client/content_cao.cpp @@ -427,7 +427,7 @@ const v3f GenericCAO::getPosition() const // Calculate real position in world based on MatrixNode if (m_matrixnode) { - v3s16 camera_offset = m_env->getCameraOffset(); + v3POS camera_offset = m_env->getCameraOffset(); return m_matrixnode->getAbsolutePosition() + intToFloat(camera_offset, BS); } @@ -868,7 +868,7 @@ void GenericCAO::updateLight(u32 day_night_ratio) u8 light_at_pos = 0; bool pos_ok = false; - v3s16 pos[3]; + v3POS pos[3]; u16 npos = getLightPosition(pos); for (u16 i = 0; i < npos; i++) { bool this_ok; @@ -930,7 +930,7 @@ void GenericCAO::setNodeLight(u8 light) } } -u16 GenericCAO::getLightPosition(v3s16 *pos) +u16 GenericCAO::getLightPosition(v3POS *pos) { const auto &box = m_prop.collisionbox; pos[0] = floatToInt(m_position + box.MinEdge * BS, BS); @@ -1005,7 +1005,7 @@ void GenericCAO::updateNodePos() scene::ISceneNode *node = getSceneNode(); if (node) { - v3s16 camera_offset = m_env->getCameraOffset(); + v3POS camera_offset = m_env->getCameraOffset(); v3f pos = pos_translator.val_current - intToFloat(camera_offset, BS); getPosRotMatrix().setTranslation(pos); @@ -1169,7 +1169,7 @@ void GenericCAO::step(float dtime, ClientEnvironment *env) m_step_distance_counter = 0.0f; if (!m_is_local_player && m_prop.makes_footstep_sound) { const NodeDefManager *ndef = m_client->ndef(); - v3s16 p = floatToInt(getPosition() + + v3POS p = floatToInt(getPosition() + v3f(0.0f, (m_prop.collisionbox.MinEdge.Y - 0.5f) * BS, 0.0f), BS); MapNode n = m_env->getMap().getNode(p); SimpleSoundSpec spec = ndef->get(n).sound_footstep; @@ -1596,7 +1596,7 @@ void GenericCAO::updateAttachments() if (!parent) { // Detach or don't attach if (m_matrixnode) { - v3s16 camera_offset = m_env->getCameraOffset(); + v3POS camera_offset = m_env->getCameraOffset(); v3f old_pos = getPosition(); m_matrixnode->setParent(m_smgr->getRootSceneNode()); diff --git a/src/client/content_cao.h b/src/client/content_cao.h index 4bbba91342..72bb8c3c47 100644 --- a/src/client/content_cao.h +++ b/src/client/content_cao.h @@ -250,7 +250,7 @@ class GenericCAO : public ClientActiveObject /* Get light position(s). * returns number of positions written into pos[], which must have space * for at least 3 vectors. */ - u16 getLightPosition(v3s16 *pos); + u16 getLightPosition(v3POS *pos); void updateNametag(); diff --git a/src/client/content_mapblock.cpp b/src/client/content_mapblock.cpp index bb2d6398f1..5ba915ea70 100644 --- a/src/client/content_mapblock.cpp +++ b/src/client/content_mapblock.cpp @@ -44,15 +44,15 @@ with this program; if not, write to the Free Software Foundation, Inc., // Corresponding offsets are listed in g_27dirs #define FRAMED_NEIGHBOR_COUNT 18 -static const v3s16 light_dirs[8] = { - v3s16(-1, -1, -1), - v3s16(-1, -1, 1), - v3s16(-1, 1, -1), - v3s16(-1, 1, 1), - v3s16( 1, -1, -1), - v3s16( 1, -1, 1), - v3s16( 1, 1, -1), - v3s16( 1, 1, 1), +static const v3POS light_dirs[8] = { + v3POS(-1, -1, -1), + v3POS(-1, -1, 1), + v3POS(-1, 1, -1), + v3POS(-1, 1, 1), + v3POS( 1, -1, -1), + v3POS( 1, -1, 1), + v3POS( 1, 1, -1), + v3POS( 1, 1, 1), }; // Standard index set to make a quad on 4 vertices @@ -94,7 +94,7 @@ void MapblockMeshGenerator::getTile(int index, TileSpec *tile) } // Returns a tile, ready for use, rotated according to the node facedir. -void MapblockMeshGenerator::getTile(v3s16 direction, TileSpec *tile) +void MapblockMeshGenerator::getTile(v3POS direction, TileSpec *tile) { getNodeTile(n, p, direction, data, *tile); } @@ -118,13 +118,13 @@ void MapblockMeshGenerator::getSpecialTile(int index, TileSpec *tile, bool apply top_layer->material_flags |= MATERIAL_FLAG_CRACK; } -void MapblockMeshGenerator::drawQuad(v3f *coords, const v3s16 &normal, +void MapblockMeshGenerator::drawQuad(v3f *coords, const v3POS &normal, float vertical_tiling) { const v2f tcoords[4] = {v2f(0.0, 0.0), v2f(1.0, 0.0), v2f(1.0, vertical_tiling), v2f(0.0, vertical_tiling)}; video::S3DVertex vertices[4]; - bool shade_face = !f->light_source && (normal != v3s16(0, 0, 0)); + bool shade_face = !f->light_source && (normal != v3POS(0, 0, 0)); v3f normal2(normal.X, normal.Y, normal.Z); for (int j = 0; j < 4; j++) { vertices[j].Pos = coords[j] + origin; @@ -411,8 +411,8 @@ void MapblockMeshGenerator::prepareLiquidNodeDrawing() getSpecialTile(0, &tile_liquid_top); getSpecialTile(1, &tile_liquid); - MapNode ntop = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(p.X, p.Y + 1, p.Z)); - MapNode nbottom = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(p.X, p.Y - 1, p.Z)); + MapNode ntop = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3POS(p.X, p.Y + 1, p.Z)); + MapNode nbottom = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3POS(p.X, p.Y - 1, p.Z)); c_flowing = f->liquid_alternative_flowing_id; c_source = f->liquid_alternative_source_id; top_is_same_liquid = (ntop.getContent() == c_flowing) || (ntop.getContent() == c_source); @@ -447,7 +447,7 @@ void MapblockMeshGenerator::getLiquidNeighborhood() for (int w = -1; w <= 1; w++) for (int u = -1; u <= 1; u++) { NeighborData &neighbor = liquid_neighbors[w + 1][u + 1]; - v3s16 p2 = p + v3s16(u, 0, w); + v3POS p2 = p + v3POS(u, 0, w); MapNode n2 = data->m_vmanip.getNodeNoEx(blockpos_nodes + p2); neighbor.content = n2.getContent(); neighbor.level = -0.5 * BS; @@ -522,17 +522,17 @@ f32 MapblockMeshGenerator::getCornerLevel(int i, int k) namespace { struct LiquidFaceDesc { - v3s16 dir; // XZ - v3s16 p[2]; // XZ only; 1 means +, 0 means - + v3POS dir; // XZ + v3POS p[2]; // XZ only; 1 means +, 0 means - }; struct UV { int u, v; }; static const LiquidFaceDesc liquid_base_faces[4] = { - {v3s16( 1, 0, 0), {v3s16(1, 0, 1), v3s16(1, 0, 0)}}, - {v3s16(-1, 0, 0), {v3s16(0, 0, 0), v3s16(0, 0, 1)}}, - {v3s16( 0, 0, 1), {v3s16(0, 0, 1), v3s16(1, 0, 1)}}, - {v3s16( 0, 0, -1), {v3s16(1, 0, 0), v3s16(0, 0, 0)}}, + {v3POS( 1, 0, 0), {v3POS(1, 0, 1), v3POS(1, 0, 0)}}, + {v3POS(-1, 0, 0), {v3POS(0, 0, 0), v3POS(0, 0, 1)}}, + {v3POS( 0, 0, 1), {v3POS(0, 0, 1), v3POS(1, 0, 1)}}, + {v3POS( 0, 0, -1), {v3POS(1, 0, 0), v3POS(0, 0, 0)}}, }; static const UV liquid_base_vertices[4] = { {0, 1}, @@ -565,7 +565,7 @@ void MapblockMeshGenerator::drawLiquidSides() video::S3DVertex vertices[4]; for (int j = 0; j < 4; j++) { const UV &vertex = liquid_base_vertices[j]; - const v3s16 &base = face.p[vertex.u]; + const v3POS &base = face.p[vertex.u]; float v = vertex.v; v3f pos; @@ -674,8 +674,8 @@ void MapblockMeshGenerator::drawGlasslikeNode() for (int face = 0; face < 6; face++) { // Check this neighbor - v3s16 dir = g_6dirs[face]; - v3s16 neighbor_pos = blockpos_nodes + p + dir; + v3POS dir = g_6dirs[face]; + v3POS neighbor_pos = blockpos_nodes + p + dir; MapNode neighbor = data->m_vmanip.getNodeNoExNoEmerge(neighbor_pos); // Don't make face if neighbor is of same type if (neighbor.getContent() == n.getContent()) @@ -771,7 +771,7 @@ void MapblockMeshGenerator::drawGlasslikeFramedNode() for (int i = 0; i < FRAMED_NEIGHBOR_COUNT; i++) { if (!check_nb[i]) continue; - v3s16 n2p = blockpos_nodes + p + g_26dirs[i]; + v3POS n2p = blockpos_nodes + p + g_26dirs[i]; MapNode n2 = data->m_vmanip.getNodeNoEx(n2p); content_t n2c = n2.getContent(); if (n2c == current) @@ -828,7 +828,7 @@ void MapblockMeshGenerator::drawGlasslikeFramedNode() vertex.rotateXZBy(-90); break; } } - v3s16 dir = g_6dirs[face]; + v3POS dir = g_6dirs[face]; drawQuad(vertices, dir); } @@ -986,7 +986,7 @@ void MapblockMeshGenerator::drawPlantlikeQuad(float rotation, float quad_offset, } } - drawQuad(vertices, v3s16(0, 0, 0), plant_height); + drawQuad(vertices, v3POS(0, 0, 0), plant_height); } void MapblockMeshGenerator::drawPlantlike(bool is_rooted) @@ -1125,7 +1125,7 @@ void MapblockMeshGenerator::drawFirelikeNode() bool neighbor[6] = {0, 0, 0, 0, 0, 0}; content_t current = n.getContent(); for (int i = 0; i < 6; i++) { - v3s16 n2p = blockpos_nodes + p + g_6dirs[i]; + v3POS n2p = blockpos_nodes + p + g_6dirs[i]; MapNode n2 = data->m_vmanip.getNodeNoEx(n2p); content_t n2c = n2.getContent(); if (n2c != CONTENT_IGNORE && n2c != CONTENT_AIR && n2c != current) { @@ -1195,7 +1195,7 @@ void MapblockMeshGenerator::drawFencelikeNode() tile = tile_nocrack; // Now a section of fence, +X, if there's a post there - v3s16 p2 = p; + v3POS p2 = p; p2.X++; MapNode n2 = data->m_vmanip.getNodeNoEx(blockpos_nodes + p2); const ContentFeatures *f2 = &nodedef->get(n2); @@ -1239,7 +1239,7 @@ void MapblockMeshGenerator::drawFencelikeNode() } } -bool MapblockMeshGenerator::isSameRail(v3s16 dir) +bool MapblockMeshGenerator::isSameRail(v3POS dir) { MapNode node2 = data->m_vmanip.getNodeNoEx(blockpos_nodes + p + dir); if (node2.getContent() == n.getContent()) @@ -1250,11 +1250,11 @@ bool MapblockMeshGenerator::isSameRail(v3s16 dir) } namespace { - static const v3s16 rail_direction[4] = { - v3s16( 0, 0, 1), - v3s16( 0, 0, -1), - v3s16(-1, 0, 0), - v3s16( 1, 0, 0), + static const v3POS rail_direction[4] = { + v3POS( 0, 0, 1), + v3POS( 0, 0, -1), + v3POS(-1, 0, 0), + v3POS( 1, 0, 0), }; static const int rail_slope_angle[4] = {0, 180, 90, -90}; @@ -1299,14 +1299,14 @@ void MapblockMeshGenerator::drawRaillikeNode() int tile_index; bool sloped = false; for (int dir = 0; dir < 4; dir++) { - bool rail_above = isSameRail(rail_direction[dir] + v3s16(0, 1, 0)); + bool rail_above = isSameRail(rail_direction[dir] + v3POS(0, 1, 0)); if (rail_above) { sloped = true; angle = rail_slope_angle[dir]; } if (rail_above || isSameRail(rail_direction[dir]) || - isSameRail(rail_direction[dir] + v3s16(0, -1, 0))) + isSameRail(rail_direction[dir] + v3POS(0, -1, 0))) code |= 1 << dir; } @@ -1335,23 +1335,23 @@ void MapblockMeshGenerator::drawRaillikeNode() } namespace { - static const v3s16 nodebox_tile_dirs[6] = { - v3s16(0, 1, 0), - v3s16(0, -1, 0), - v3s16(1, 0, 0), - v3s16(-1, 0, 0), - v3s16(0, 0, 1), - v3s16(0, 0, -1) + static const v3POS nodebox_tile_dirs[6] = { + v3POS(0, 1, 0), + v3POS(0, -1, 0), + v3POS(1, 0, 0), + v3POS(-1, 0, 0), + v3POS(0, 0, 1), + v3POS(0, 0, -1) }; // we have this order for some reason... - static const v3s16 nodebox_connection_dirs[6] = { - v3s16( 0, 1, 0), // top - v3s16( 0, -1, 0), // bottom - v3s16( 0, 0, -1), // front - v3s16(-1, 0, 0), // left - v3s16( 0, 0, 1), // back - v3s16( 1, 0, 0), // right + static const v3POS nodebox_connection_dirs[6] = { + v3POS( 0, 1, 0), // top + v3POS( 0, -1, 0), // bottom + v3POS( 0, 0, -1), // front + v3POS(-1, 0, 0), // left + v3POS( 0, 0, 1), // back + v3POS( 1, 0, 0), // right }; } @@ -1368,7 +1368,7 @@ void MapblockMeshGenerator::drawNodeboxNode() if (f->node_box.type == NODEBOX_CONNECTED) { for (int dir = 0; dir != 6; dir++) { u8 flag = 1 << dir; - v3s16 p2 = blockpos_nodes + p + nodebox_connection_dirs[dir]; + v3POS p2 = blockpos_nodes + p + nodebox_connection_dirs[dir]; MapNode n2 = data->m_vmanip.getNodeNoEx(p2); if (nodedef->nodeboxConnects(n, n2, flag)) neighbors_set |= flag; diff --git a/src/client/content_mapblock.h b/src/client/content_mapblock.h index 7344f05ee2..77562f4943 100644 --- a/src/client/content_mapblock.h +++ b/src/client/content_mapblock.h @@ -71,8 +71,8 @@ class MapblockMeshGenerator bool enable_mesh_cache; // current node - v3s16 blockpos_nodes; - v3s16 p; + v3POS blockpos_nodes; + v3POS p; v3f origin; MapNode n; const ContentFeatures *f; @@ -91,11 +91,11 @@ class MapblockMeshGenerator void useTile(int index = 0, u8 set_flags = MATERIAL_FLAG_CRACK_OVERLAY, u8 reset_flags = 0, bool special = false); void getTile(int index, TileSpec *tile); - void getTile(v3s16 direction, TileSpec *tile); + void getTile(v3POS direction, TileSpec *tile); void getSpecialTile(int index, TileSpec *tile, bool apply_crack = false); // face drawing - void drawQuad(v3f *vertices, const v3s16 &normal = v3s16(0, 0, 0), + void drawQuad(v3f *vertices, const v3POS &normal = v3POS(0, 0, 0), float vertical_tiling = 1.0); // cuboid drawing! @@ -134,7 +134,7 @@ class MapblockMeshGenerator // name of the group that enables connecting to raillike nodes of different kind static const std::string raillike_groupname; int raillike_group; - bool isSameRail(v3s16 dir); + bool isSameRail(v3POS dir); // plantlike-specific PlantlikeStyle draw_style; diff --git a/src/client/game.cpp b/src/client/game.cpp index 54028fd1d1..6aa620139e 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -84,7 +84,7 @@ with this program; if not, write to the Free Software Foundation, Inc., struct TextDestNodeMetadata : public TextDest { - TextDestNodeMetadata(v3s16 p, Client *client) + TextDestNodeMetadata(v3POS p, Client *client) { m_p = p; m_client = client; @@ -104,7 +104,7 @@ struct TextDestNodeMetadata : public TextDest m_client->sendNodemetaFields(m_p, "", fields); } - v3s16 m_p; + v3POS m_p; Client *m_client; }; @@ -193,7 +193,7 @@ struct LocalFormspecHandler : public TextDest class NodeMetadataFormSource: public IFormSource { public: - NodeMetadataFormSource(ClientMap *map, v3s16 p): + NodeMetadataFormSource(ClientMap *map, v3POS p): m_map(map), m_p(p) { @@ -220,7 +220,7 @@ class NodeMetadataFormSource: public IFormSource } ClientMap *m_map; - v3s16 m_p; + v3POS m_p; }; class PlayerInventoryFormSource: public IFormSource @@ -243,10 +243,10 @@ class PlayerInventoryFormSource: public IFormSource class NodeDugEvent: public MtEvent { public: - v3s16 p; + v3POS p; MapNode n; - NodeDugEvent(v3s16 p, MapNode n): + NodeDugEvent(v3POS p, MapNode n): p(p), n(n) {} @@ -730,13 +730,13 @@ class Game { */ PointedThing updatePointedThing( const core::line3d &shootline, bool liquids_pointable, - bool look_for_object, const v3s16 &camera_offset); + bool look_for_object, const v3POS &camera_offset); void handlePointingAtNothing(const ItemStack &playerItem); void handlePointingAtNode(const PointedThing &pointed, const ItemStack &selected_item, const ItemStack &hand_item, f32 dtime); void handlePointingAtObject(const PointedThing &pointed, const ItemStack &playeritem, const v3f &player_position, bool show_debug); - void handleDigging(const PointedThing &pointed, const v3s16 &nodepos, + void handleDigging(const PointedThing &pointed, const v3POS &nodepos, const ItemStack &selected_item, const ItemStack &hand_item, f32 dtime); void updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime, const CameraOrientation &cam); @@ -807,7 +807,7 @@ class Game { void updateChat(f32 dtime); bool nodePlacement(const ItemDefinition &selected_def, const ItemStack &selected_item, - const v3s16 &nodepos, const v3s16 &neighbourpos, const PointedThing &pointed, + const v3POS &nodepos, const v3POS &neighbourpos, const PointedThing &pointed, const NodeMetadata *meta); static const ClientEventHandler clientEventHandler[CLIENTEVENT_MAX]; @@ -2336,8 +2336,8 @@ void Game::toggleUpdateCamera() void Game::increaseViewRange() { - s16 range = g_settings->getS16("viewing_range"); - s16 range_new = range + 10; + POS range = g_settings->getPOS("viewing_range"); + POS range_new = range + 10; if (range_new > 4000) { range_new = 4000; @@ -2353,8 +2353,8 @@ void Game::increaseViewRange() void Game::decreaseViewRange() { - s16 range = g_settings->getS16("viewing_range"); - s16 range_new = range - 10; + POS range = g_settings->getPOS("viewing_range"); + POS range_new = range - 10; if (range_new < 20) { range_new = 20; @@ -2966,7 +2966,7 @@ void Game::updateCamera(u32 busy_time, f32 dtime) ToolCapabilities playeritem_toolcap = playeritem.getToolCapabilities(itemdef_manager); - v3s16 old_camera_offset = camera->getOffset(); + v3POS old_camera_offset = camera->getOffset(); if (wasKeyDown(KeyType::CAMERA_MODE)) { GenericCAO *playercao = player->getCAO(); @@ -2992,7 +2992,7 @@ void Game::updateCamera(u32 busy_time, f32 dtime) v3f camera_position = camera->getPosition(); v3f camera_direction = camera->getDirection(); f32 camera_fov = camera->getFovMax(); - v3s16 camera_offset = camera->getOffset(); + v3POS camera_offset = camera->getOffset(); m_camera_offset_changed = (camera_offset != old_camera_offset); @@ -3014,7 +3014,7 @@ void Game::updateCamera(u32 busy_time, f32 dtime) void Game::updateSound(f32 dtime) { // Update sound listener - v3s16 camera_offset = camera->getOffset(); + v3POS camera_offset = camera->getOffset(); sound->updateListener(camera->getCameraNode()->getPosition() + intToFloat(camera_offset, BS), v3f(0, 0, 0), // velocity camera->getDirection(), @@ -3054,7 +3054,7 @@ void Game::processPlayerInteraction(f32 dtime, bool show_hud, bool show_debug) LocalPlayer *player = client->getEnv().getLocalPlayer(); const v3f camera_direction = camera->getDirection(); - const v3s16 camera_offset = camera->getOffset(); + const v3POS camera_offset = camera->getOffset(); /* Calculate what block is the crosshair pointing to @@ -3137,7 +3137,7 @@ void Game::processPlayerInteraction(f32 dtime, bool show_hud, bool show_debug) if (!runData.digging) { client->interact(INTERACT_STOP_DIGGING, runData.pointed_old); - client->setCrack(-1, v3s16(0, 0, 0)); + client->setCrack(-1, v3POS(0, 0, 0)); runData.dig_time = 0.0; } } else if (runData.dig_instantly && wasKeyReleased(KeyType::DIG)) { @@ -3201,7 +3201,7 @@ PointedThing Game::updatePointedThing( const core::line3d &shootline, bool liquids_pointable, bool look_for_object, - const v3s16 &camera_offset) + const v3POS &camera_offset) { std::vector *selectionboxes = hud->getSelectionBoxes(); selectionboxes->clear(); @@ -3256,14 +3256,14 @@ PointedThing Game::updatePointedThing( // Update selection mesh light level and vertex colors if (!selectionboxes->empty()) { v3f pf = hud->getSelectionPos(); - v3s16 p = floatToInt(pf, BS); + v3POS p = floatToInt(pf, BS); // Get selection mesh light level MapNode n = map.getNode(p); u16 node_light = getInteriorLight(n, -1, nodedef); u16 light_level = node_light; - for (const v3s16 &dir : g_6dirs) { + for (const v3POS &dir : g_6dirs) { n = map.getNode(p + dir); node_light = getInteriorLight(n, -1, nodedef); if (node_light > light_level) @@ -3303,8 +3303,8 @@ void Game::handlePointingAtNothing(const ItemStack &playerItem) void Game::handlePointingAtNode(const PointedThing &pointed, const ItemStack &selected_item, const ItemStack &hand_item, f32 dtime) { - v3s16 nodepos = pointed.node_undersurface; - v3s16 neighbourpos = pointed.node_abovesurface; + v3POS nodepos = pointed.node_undersurface; + v3POS neighbourpos = pointed.node_abovesurface; /* Check information text of node @@ -3357,7 +3357,7 @@ void Game::handlePointingAtNode(const PointedThing &pointed, } bool Game::nodePlacement(const ItemDefinition &selected_def, - const ItemStack &selected_item, const v3s16 &nodepos, const v3s16 &neighbourpos, + const ItemStack &selected_item, const v3POS &nodepos, const v3POS &neighbourpos, const PointedThing &pointed, const NodeMetadata *meta) { const auto &prediction = selected_def.node_placement_prediction; @@ -3407,7 +3407,7 @@ bool Game::nodePlacement(const ItemDefinition &selected_def, verbosestream << "Node placement prediction for " << selected_def.name << " is " << prediction << std::endl; - v3s16 p = neighbourpos; + v3POS p = neighbourpos; // Place inside node itself if buildable_to MapNode n_under = map.getNode(nodepos, &is_valid_position); @@ -3451,7 +3451,7 @@ bool Game::nodePlacement(const ItemDefinition &selected_def, param2 = place_param2; } else if (predicted_f.param_type_2 == CPT2_WALLMOUNTED || predicted_f.param_type_2 == CPT2_COLORED_WALLMOUNTED) { - v3s16 dir = nodepos - neighbourpos; + v3POS dir = nodepos - neighbourpos; if (abs(dir.Y) > MYMAX(abs(dir.X), abs(dir.Z))) { param2 = dir.Y < 0 ? 1 : 0; @@ -3462,7 +3462,7 @@ bool Game::nodePlacement(const ItemDefinition &selected_def, } } else if (predicted_f.param_type_2 == CPT2_FACEDIR || predicted_f.param_type_2 == CPT2_COLORED_FACEDIR) { - v3s16 dir = nodepos - floatToInt(client->getEnv().getLocalPlayer()->getPosition(), BS); + v3POS dir = nodepos - floatToInt(client->getEnv().getLocalPlayer()->getPosition(), BS); if (abs(dir.X) > abs(dir.Z)) { param2 = dir.X < 0 ? 3 : 1; @@ -3473,21 +3473,21 @@ bool Game::nodePlacement(const ItemDefinition &selected_def, // Check attachment if node is in group attached_node if (itemgroup_get(predicted_f.groups, "attached_node") != 0) { - const static v3s16 wallmounted_dirs[8] = { - v3s16(0, 1, 0), - v3s16(0, -1, 0), - v3s16(1, 0, 0), - v3s16(-1, 0, 0), - v3s16(0, 0, 1), - v3s16(0, 0, -1), + const static v3POS wallmounted_dirs[8] = { + v3POS(0, 1, 0), + v3POS(0, -1, 0), + v3POS(1, 0, 0), + v3POS(-1, 0, 0), + v3POS(0, 0, 1), + v3POS(0, 0, -1), }; - v3s16 pp; + v3POS pp; if (predicted_f.param_type_2 == CPT2_WALLMOUNTED || predicted_f.param_type_2 == CPT2_COLORED_WALLMOUNTED) pp = p + wallmounted_dirs[param2]; else - pp = p + v3s16(0, -1, 0); + pp = p + v3POS(0, -1, 0); if (!nodedef->get(map.getNode(pp)).walkable) { soundmaker->m_player_rightpunch_sound = selected_def.sound_place_failed; @@ -3529,8 +3529,8 @@ bool Game::nodePlacement(const ItemDefinition &selected_def, g_settings->getBool("enable_build_where_you_stand") || (client->checkPrivilege("noclip") && g_settings->getBool("noclip")) || (nodedef->get(n).walkable && - neighbourpos != player->getStandingNodePos() + v3s16(0, 1, 0) && - neighbourpos != player->getStandingNodePos() + v3s16(0, 2, 0))) { + neighbourpos != player->getStandingNodePos() + v3POS(0, 1, 0) && + neighbourpos != player->getStandingNodePos() + v3POS(0, 2, 0))) { // This triggers the required mesh update too client->addNode(p, n); // Report to server @@ -3603,7 +3603,7 @@ void Game::handlePointingAtObject(const PointedThing &pointed, } -void Game::handleDigging(const PointedThing &pointed, const v3s16 &nodepos, +void Game::handleDigging(const PointedThing &pointed, const v3POS &nodepos, const ItemStack &selected_item, const ItemStack &hand_item, f32 dtime) { // See also: serverpackethandle.cpp, action == 2 @@ -3679,7 +3679,7 @@ void Game::handleDigging(const PointedThing &pointed, const v3s16 &nodepos, client->setCrack(runData.dig_index, nodepos); } else { infostream << "Digging completed" << std::endl; - client->setCrack(-1, v3s16(0, 0, 0)); + client->setCrack(-1, v3POS(0, 0, 0)); runData.dig_time = 0; runData.digging = false; @@ -3809,7 +3809,7 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime, clouds->step(dtime); // camera->getPosition is not enough for 3rd person views v3f camera_node_position = camera->getCameraNode()->getPosition(); - v3s16 camera_offset = camera->getOffset(); + v3POS camera_offset = camera->getOffset(); camera_node_position.X = camera_node_position.X + camera_offset.X * BS; camera_node_position.Y = camera_node_position.Y + camera_offset.Y * BS; camera_node_position.Z = camera_node_position.Z + camera_offset.Z * BS; diff --git a/src/client/hud.cpp b/src/client/hud.cpp index e08d2ef026..5814d41a28 100644 --- a/src/client/hud.cpp +++ b/src/client/hud.cpp @@ -312,7 +312,7 @@ bool Hud::hasElementOfType(HudElementType type) } // Calculates screen position of waypoint. Returns true if waypoint is visible (in front of the player), else false. -bool Hud::calculateScreenPos(const v3s16 &camera_offset, HudElement *e, v2s32 *pos) +bool Hud::calculateScreenPos(const v3POS &camera_offset, HudElement *e, v2s32 *pos) { v3f w_pos = e->world_pos * BS; scene::ICameraSceneNode* camera = @@ -331,7 +331,7 @@ bool Hud::calculateScreenPos(const v3s16 &camera_offset, HudElement *e, v2s32 *p return true; } -void Hud::drawLuaElements(const v3s16 &camera_offset) +void Hud::drawLuaElements(const v3POS &camera_offset) { const u32 text_height = g_fontengine->getTextHeight(); gui::IGUIFont *const font = g_fontengine->getFont(); @@ -813,7 +813,7 @@ void Hud::drawCrosshair() } } -void Hud::setSelectionPos(const v3f &pos, const v3s16 &camera_offset) +void Hud::setSelectionPos(const v3f &pos, const v3POS &camera_offset) { m_camera_offset = camera_offset; m_selection_pos = pos; @@ -887,9 +887,9 @@ void Hud::drawBlockBounds() video::SMaterial old_material = driver->getMaterial2D(); driver->setMaterial(m_selection_material); - v3s16 pos = player->getStandingNodePos(); + v3POS pos = player->getStandingNodePos(); - v3s16 blockPos( + v3POS blockPos( floorf((float) pos.X / MAP_BLOCKSIZE), floorf((float) pos.Y / MAP_BLOCKSIZE), floorf((float) pos.Z / MAP_BLOCKSIZE) @@ -904,7 +904,7 @@ void Hud::drawBlockBounds() for (s8 x = -radius; x <= radius; x++) for (s8 y = -radius; y <= radius; y++) for (s8 z = -radius; z <= radius; z++) { - v3s16 blockOffset(x, y, z); + v3POS blockOffset(x, y, z); aabb3f box( intToFloat((blockPos + blockOffset) * MAP_BLOCKSIZE, BS) - offset - halfNode, @@ -917,7 +917,7 @@ void Hud::drawBlockBounds() driver->setMaterial(old_material); } -void Hud::updateSelectionMesh(const v3s16 &camera_offset) +void Hud::updateSelectionMesh(const v3POS &camera_offset) { m_camera_offset = camera_offset; if (m_mode != HIGHLIGHT_HALO) @@ -988,8 +988,8 @@ void drawItemStack( const core::rect *clip, Client *client, ItemRotationKind rotation_kind, - const v3s16 &angle, - const v3s16 &rotation_speed) + const v3POS &angle, + const v3POS &rotation_speed) { static MeshTimeInfo rotation_time_infos[IT_ROT_NONE]; @@ -1208,5 +1208,5 @@ void drawItemStack( ItemRotationKind rotation_kind) { drawItemStack(driver, font, item, rect, clip, client, rotation_kind, - v3s16(0, 0, 0), v3s16(0, 100, 0)); + v3POS(0, 0, 0), v3POS(0, 100, 0)); } diff --git a/src/client/hud.h b/src/client/hud.h index fd79183a00..c5a738fb96 100644 --- a/src/client/hud.h +++ b/src/client/hud.h @@ -67,11 +67,11 @@ class Hud void resizeHotbar(); void drawCrosshair(); void drawSelectionMesh(); - void updateSelectionMesh(const v3s16 &camera_offset); + void updateSelectionMesh(const v3POS &camera_offset); std::vector *getSelectionBoxes() { return &m_selection_boxes; } - void setSelectionPos(const v3f &pos, const v3s16 &camera_offset); + void setSelectionPos(const v3f &pos, const v3POS &camera_offset); v3f getSelectionPos() const { return m_selection_pos; } @@ -87,10 +87,10 @@ class Hud bool hasElementOfType(HudElementType type); - void drawLuaElements(const v3s16 &camera_offset); + void drawLuaElements(const v3POS &camera_offset); private: - bool calculateScreenPos(const v3s16 &camera_offset, HudElement *e, v2s32 *pos); + bool calculateScreenPos(const v3POS &camera_offset, HudElement *e, v2s32 *pos); void drawStatbar(v2s32 pos, u16 corner, u16 drawdir, const std::string &texture, const std::string& bgtexture, s32 count, s32 maxcount, v2s32 offset, v2s32 size = v2s32()); @@ -115,7 +115,7 @@ class Hud float m_hud_scaling; // cached minetest setting float m_scale_factor; - v3s16 m_camera_offset; + v3POS m_camera_offset; v2u32 m_screensize; v2s32 m_displaycenter; s32 m_hotbar_imagesize; // Takes hud_scaling into account, updated by resizeHotbar() @@ -168,6 +168,6 @@ void drawItemStack( const core::rect *clip, Client *client, ItemRotationKind rotation_kind, - const v3s16 &angle, - const v3s16 &rotation_speed); + const v3POS &angle, + const v3POS &rotation_speed); diff --git a/src/client/localplayer.cpp b/src/client/localplayer.cpp index 3f78d201d3..d2b6ba20ce 100644 --- a/src/client/localplayer.cpp +++ b/src/client/localplayer.cpp @@ -58,16 +58,16 @@ static aabb3f getNodeBoundingBox(const std::vector &nodeboxes) bool LocalPlayer::updateSneakNode(Map *map, const v3f &position, const v3f &sneak_max) { - static const v3s16 dir9_center[9] = { - v3s16( 0, 0, 0), - v3s16( 1, 0, 0), - v3s16(-1, 0, 0), - v3s16( 0, 0, 1), - v3s16( 0, 0, -1), - v3s16( 1, 0, 1), - v3s16(-1, 0, 1), - v3s16( 1, 0, -1), - v3s16(-1, 0, -1) + static const v3POS dir9_center[9] = { + v3POS( 0, 0, 0), + v3POS( 1, 0, 0), + v3POS(-1, 0, 0), + v3POS( 0, 0, 1), + v3POS( 0, 0, -1), + v3POS( 1, 0, 1), + v3POS(-1, 0, 1), + v3POS( 1, 0, -1), + v3POS(-1, 0, -1) }; const NodeDefManager *nodemgr = m_client->ndef(); @@ -81,7 +81,7 @@ bool LocalPlayer::updateSneakNode(Map *map, const v3f &position, position_y_mod = m_sneak_node_bb_top.MaxEdge.Y - position_y_mod; // Get position of current standing node - const v3s16 current_node = floatToInt(position - v3f(0.0f, position_y_mod, 0.0f), BS); + const v3POS current_node = floatToInt(position - v3f(0.0f, position_y_mod, 0.0f), BS); if (current_node != m_sneak_node) { new_sneak_node_exists = false; @@ -100,7 +100,7 @@ bool LocalPlayer::updateSneakNode(Map *map, const v3f &position, f32 min_distance_f = 100000.0f * BS; for (const auto &d : dir9_center) { - const v3s16 p = current_node + d; + const v3POS p = current_node + d; const v3f pf = intToFloat(p, BS); const v2f diff(position.X - pf.X, position.Z - pf.Z); f32 distance_f = diff.getLength(); @@ -121,7 +121,7 @@ bool LocalPlayer::updateSneakNode(Map *map, const v3f &position, u16 height = ceilf((m_collisionbox.MaxEdge.Y - m_collisionbox.MinEdge.Y) / BS); for (u16 y = 1; y <= height; y++) { - node = map->getNode(p + v3s16(0, y, 0), &is_valid_position); + node = map->getNode(p + v3POS(0, y, 0), &is_valid_position); if (!is_valid_position || nodemgr->get(node).walkable) { ok = false; break; @@ -129,7 +129,7 @@ bool LocalPlayer::updateSneakNode(Map *map, const v3f &position, } } else { // legacy behaviour: check just one node - node = map->getNode(p + v3s16(0, 1, 0), &is_valid_position); + node = map->getNode(p + v3POS(0, 1, 0), &is_valid_position); ok = is_valid_position && !nodemgr->get(node).walkable; } if (!ok) @@ -152,11 +152,11 @@ bool LocalPlayer::updateSneakNode(Map *map, const v3f &position, if (physics_override_sneak_glitch) { // Detect sneak ladder: // Node two meters above sneak node must be solid - node = map->getNode(m_sneak_node + v3s16(0, 2, 0), + node = map->getNode(m_sneak_node + v3POS(0, 2, 0), &is_valid_position); if (is_valid_position && nodemgr->get(node).walkable) { // Node three meters above: must be non-solid - node = map->getNode(m_sneak_node + v3s16(0, 3, 0), + node = map->getNode(m_sneak_node + v3POS(0, 3, 0), &is_valid_position); m_sneak_ladder_detected = is_valid_position && !nodemgr->get(node).walkable; @@ -215,7 +215,7 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d, bool is_valid_position; MapNode node; - v3s16 pp; + v3POS pp; /* Check if player is in liquid (the oscillating value) @@ -264,7 +264,7 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d, */ pp = floatToInt(position + v3f(0.0f, 0.5f * BS, 0.0f), BS); - v3s16 pp2 = floatToInt(position + v3f(0.0f, -0.2f * BS, 0.0f), BS); + v3POS pp2 = floatToInt(position + v3f(0.0f, -0.2f * BS, 0.0f), BS); node = map->getNode(pp, &is_valid_position); bool is_valid_position2; MapNode node2 = map->getNode(pp2, &is_valid_position2); @@ -428,7 +428,7 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d, { camera_barely_in_ceiling = false; - v3s16 camera_np = floatToInt(getEyePosition(), BS); + v3POS camera_np = floatToInt(getEyePosition(), BS); MapNode n = map->getNode(camera_np); if (n.getContent() != CONTENT_IGNORE) { if (nodemgr->get(n).walkable && nodemgr->get(n).solidness == 2) @@ -440,7 +440,7 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d, Check properties of the node on which the player is standing */ const ContentFeatures &f = nodemgr->get(map->getNode(m_standing_node)); - const ContentFeatures &f1 = nodemgr->get(map->getNode(m_standing_node + v3s16(0, 1, 0))); + const ContentFeatures &f1 = nodemgr->get(map->getNode(m_standing_node + v3POS(0, 1, 0))); // Determine if jumping is possible m_disable_jump = itemgroup_get(f.groups, "disable_jump") || @@ -662,7 +662,7 @@ void LocalPlayer::applyControl(float dtime, Environment *env) pitch_move); } -v3s16 LocalPlayer::getStandingNodePos() +v3POS LocalPlayer::getStandingNodePos() { if (m_sneak_node_exists) return m_sneak_node; @@ -670,7 +670,7 @@ v3s16 LocalPlayer::getStandingNodePos() return m_standing_node; } -v3s16 LocalPlayer::getFootstepNodePos() +v3POS LocalPlayer::getFootstepNodePos() { // Emit swimming sound if the player is in liquid if (in_liquid_stable) @@ -687,7 +687,7 @@ v3s16 LocalPlayer::getFootstepNodePos() return floatToInt(getPosition() - v3f(0.0f, BS * 0.5f, 0.0f), BS); } -v3s16 LocalPlayer::getLightPosition() const +v3POS LocalPlayer::getLightPosition() const { return floatToInt(m_position + v3f(0.0f, BS * 1.5f, 0.0f), BS); } @@ -792,7 +792,7 @@ void LocalPlayer::old_move(f32 dtime, Environment *env, f32 pos_max_d, */ bool is_valid_position; MapNode node; - v3s16 pp; + v3POS pp; /* Check if player is in liquid (the oscillating value) @@ -835,7 +835,7 @@ void LocalPlayer::old_move(f32 dtime, Environment *env, f32 pos_max_d, Check if player is climbing */ pp = floatToInt(position + v3f(0.0f, 0.5f * BS, 0.0f), BS); - v3s16 pp2 = floatToInt(position + v3f(0.0f, -0.2f * BS, 0.0f), BS); + v3POS pp2 = floatToInt(position + v3f(0.0f, -0.2f * BS, 0.0f), BS); node = map->getNode(pp, &is_valid_position); bool is_valid_position2; MapNode node2 = map->getNode(pp2, &is_valid_position2); @@ -921,7 +921,7 @@ void LocalPlayer::old_move(f32 dtime, Environment *env, f32 pos_max_d, f32 position_y_mod = 0.05f * BS; if (m_sneak_node_bb_ymax > 0.0f) position_y_mod = m_sneak_node_bb_ymax - position_y_mod; - v3s16 current_node = floatToInt(position - v3f(0.0f, position_y_mod, 0.0f), BS); + v3POS current_node = floatToInt(position - v3f(0.0f, position_y_mod, 0.0f), BS); if (m_sneak_node_exists && nodemgr->get(map->getNode(m_old_node_below)).name == "air" && m_old_node_below_type != "air") { @@ -937,14 +937,14 @@ void LocalPlayer::old_move(f32 dtime, Environment *env, f32 pos_max_d, if (m_need_to_get_new_sneak_node && physics_override_sneak) { m_sneak_node_bb_ymax = 0.0f; - v3s16 pos_i_bottom = floatToInt(position - v3f(0.0f, position_y_mod, 0.0f), BS); + v3POS pos_i_bottom = floatToInt(position - v3f(0.0f, position_y_mod, 0.0f), BS); v2f player_p2df(position.X, position.Z); f32 min_distance_f = 100000.0f * BS; // If already seeking from some node, compare to it. - v3s16 new_sneak_node = m_sneak_node; + v3POS new_sneak_node = m_sneak_node; for (s16 x= -1; x <= 1; x++) for (s16 z= -1; z <= 1; z++) { - v3s16 p = pos_i_bottom + v3s16(x, 0, z); + v3POS p = pos_i_bottom + v3POS(x, 0, z); v3f pf = intToFloat(p, BS); v2f node_p2df(pf.X, pf.Z); f32 distance_f = player_p2df.getDistanceFrom(node_p2df); @@ -961,12 +961,12 @@ void LocalPlayer::old_move(f32 dtime, Environment *env, f32 pos_max_d, if (!is_valid_position || !nodemgr->get(node).walkable) continue; // And the node above it has to be nonwalkable - node = map->getNode(p + v3s16(0, 1, 0), &is_valid_position); + node = map->getNode(p + v3POS(0, 1, 0), &is_valid_position); if (!is_valid_position || nodemgr->get(node).walkable) continue; // If not 'sneak_glitch' the node 2 nodes above it has to be nonwalkable if (!physics_override_sneak_glitch) { - node = map->getNode(p + v3s16(0, 2, 0), &is_valid_position); + node = map->getNode(p + v3POS(0, 2, 0), &is_valid_position); if (!is_valid_position || nodemgr->get(node).walkable) continue; } @@ -1025,7 +1025,7 @@ void LocalPlayer::old_move(f32 dtime, Environment *env, f32 pos_max_d, { camera_barely_in_ceiling = false; - v3s16 camera_np = floatToInt(getEyePosition(), BS); + v3POS camera_np = floatToInt(getEyePosition(), BS); MapNode n = map->getNode(camera_np); if (n.getContent() != CONTENT_IGNORE) { if (nodemgr->get(n).walkable && nodemgr->get(n).solidness == 2) @@ -1120,13 +1120,13 @@ void LocalPlayer::handleAutojump(f32 dtime, Environment *env, v3f headpos_min = m_position + m_collisionbox.MinEdge * 0.99f; v3f headpos_max = m_position + m_collisionbox.MaxEdge * 0.99f; headpos_min.Y = headpos_max.Y; // top face of collision box - v3s16 ceilpos_min = floatToInt(headpos_min, BS) + v3s16(0, 1, 0); - v3s16 ceilpos_max = floatToInt(headpos_max, BS) + v3s16(0, 1, 0); + v3POS ceilpos_min = floatToInt(headpos_min, BS) + v3POS(0, 1, 0); + v3POS ceilpos_max = floatToInt(headpos_max, BS) + v3POS(0, 1, 0); const NodeDefManager *ndef = env->getGameDef()->ndef(); bool is_position_valid; - for (s16 z = ceilpos_min.Z; z <= ceilpos_max.Z; ++z) { - for (s16 x = ceilpos_min.X; x <= ceilpos_max.X; ++x) { - MapNode n = env->getMap().getNode(v3s16(x, ceilpos_max.Y, z), &is_position_valid); + for (POS z = ceilpos_min.Z; z <= ceilpos_max.Z; ++z) { + for (POS x = ceilpos_min.X; x <= ceilpos_max.X; ++x) { + MapNode n = env->getMap().getNode(v3POS(x, ceilpos_max.Y, z), &is_position_valid); if (!is_position_valid) break; // won't collide with the void outside diff --git a/src/client/localplayer.h b/src/client/localplayer.h index 13b35ae4e1..dd71ec2784 100644 --- a/src/client/localplayer.h +++ b/src/client/localplayer.h @@ -78,8 +78,8 @@ class LocalPlayer : public Player void applyControl(float dtime, Environment *env); - v3s16 getStandingNodePos(); - v3s16 getFootstepNodePos(); + v3POS getStandingNodePos(); + v3POS getFootstepNodePos(); // Used to check if anything changed and prevent sending packets if not v3f last_position; @@ -120,7 +120,7 @@ class LocalPlayer : public Player u16 getBreath() const { return m_breath; } void setBreath(u16 breath) { m_breath = breath; } - v3s16 getLightPosition() const; + v3POS getLightPosition() const; void setYaw(f32 yaw) { m_yaw = yaw; } f32 getYaw() const { return m_yaw; } @@ -169,9 +169,9 @@ class LocalPlayer : public Player f32 pos_max_d); v3f m_position; - v3s16 m_standing_node; + v3POS m_standing_node; - v3s16 m_sneak_node = v3s16(32767, 32767, 32767); + v3POS m_sneak_node = v3POS(32767, 32767, 32767); // Stores the top bounding box of m_sneak_node aabb3f m_sneak_node_bb_top = aabb3f(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f); // Whether the player is allowed to sneak @@ -187,7 +187,7 @@ class LocalPlayer : public Player bool m_need_to_get_new_sneak_node = true; // Node below player, used to determine whether it has been removed, // and its old type - v3s16 m_old_node_below = v3s16(32767, 32767, 32767); + v3POS m_old_node_below = v3POS(32767, 32767, 32767); std::string m_old_node_below_type = "air"; // ***** End of variables for temporary option ***** diff --git a/src/client/mapblock_mesh.cpp b/src/client/mapblock_mesh.cpp index 03522eca93..2042627809 100644 --- a/src/client/mapblock_mesh.cpp +++ b/src/client/mapblock_mesh.cpp @@ -40,46 +40,46 @@ MeshMakeData::MeshMakeData(Client *client, bool use_shaders): m_use_shaders(use_shaders) {} -void MeshMakeData::fillBlockDataBegin(const v3s16 &blockpos) +void MeshMakeData::fillBlockDataBegin(const v3POS &blockpos) { m_blockpos = blockpos; - v3s16 blockpos_nodes = m_blockpos*MAP_BLOCKSIZE; + v3POS blockpos_nodes = m_blockpos*MAP_BLOCKSIZE; m_vmanip.clear(); - VoxelArea voxel_area(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 - v3POS(1,1,1) * MAP_BLOCKSIZE, + blockpos_nodes + v3POS(1,1,1) * MAP_BLOCKSIZE*2-v3POS(1,1,1)); m_vmanip.addArea(voxel_area); } -void MeshMakeData::fillBlockData(const v3s16 &block_offset, MapNode *data) +void MeshMakeData::fillBlockData(const v3POS &block_offset, MapNode *data) { - v3s16 data_size(MAP_BLOCKSIZE, MAP_BLOCKSIZE, MAP_BLOCKSIZE); - VoxelArea data_area(v3s16(0,0,0), data_size - v3s16(1,1,1)); + v3POS data_size(MAP_BLOCKSIZE, MAP_BLOCKSIZE, MAP_BLOCKSIZE); + VoxelArea data_area(v3POS(0,0,0), data_size - v3POS(1,1,1)); - v3s16 bp = m_blockpos + block_offset; - v3s16 blockpos_nodes = bp * MAP_BLOCKSIZE; - m_vmanip.copyFrom(data, data_area, v3s16(0,0,0), blockpos_nodes, data_size); + v3POS bp = m_blockpos + block_offset; + v3POS blockpos_nodes = bp * MAP_BLOCKSIZE; + m_vmanip.copyFrom(data, data_area, v3POS(0,0,0), blockpos_nodes, data_size); } void MeshMakeData::fill(MapBlock *block) { fillBlockDataBegin(block->getPos()); - fillBlockData(v3s16(0,0,0), block->getData()); + fillBlockData(v3POS(0,0,0), block->getData()); // Get map for reading neighbor blocks Map *map = block->getParent(); - for (const v3s16 &dir : g_26dirs) { - v3s16 bp = m_blockpos + dir; + for (const v3POS &dir : g_26dirs) { + v3POS bp = m_blockpos + dir; MapBlock *b = map->getBlockNoCreateNoEx(bp); if(b) fillBlockData(dir, b->getData()); } } -void MeshMakeData::setCrack(int crack_level, v3s16 crack_pos) +void MeshMakeData::setCrack(int crack_level, v3POS crack_pos) { if (crack_level >= 0) m_crack_pos_relative = crack_pos - m_blockpos*MAP_BLOCKSIZE; @@ -123,7 +123,7 @@ u16 getInteriorLight(MapNode n, s32 increment, const NodeDefManager *ndef) Single light bank. */ static u8 getFaceLight(enum LightBank bank, MapNode n, MapNode n2, - v3s16 face_dir, const NodeDefManager *ndef) + v3POS face_dir, const NodeDefManager *ndef) { u8 light; u8 l1 = n.getLight(bank, ndef); @@ -146,7 +146,7 @@ static u8 getFaceLight(enum LightBank bank, MapNode n, MapNode n2, Calculate non-smooth lighting at face of node. Both light banks. */ -u16 getFaceLight(MapNode n, MapNode n2, const v3s16 &face_dir, +u16 getFaceLight(MapNode n, MapNode n2, const v3POS &face_dir, const NodeDefManager *ndef) { u16 day = getFaceLight(LIGHTBANK_DAY, n, n2, face_dir, ndef); @@ -158,8 +158,8 @@ u16 getFaceLight(MapNode n, MapNode n2, const v3s16 &face_dir, Calculate smooth lighting at the XYZ- corner of p. Both light banks */ -static u16 getSmoothLightCombined(const v3s16 &p, - const std::array &dirs, MeshMakeData *data) +static u16 getSmoothLightCombined(const v3POS &p, + const std::array &dirs, MeshMakeData *data) { const NodeDefManager *ndef = data->m_client->ndef(); @@ -267,7 +267,7 @@ static u16 getSmoothLightCombined(const v3s16 &p, Both light banks. Node at p is solid, and thus the lighting is face-dependent. */ -u16 getSmoothLightSolid(const v3s16 &p, const v3s16 &face_dir, const v3s16 &corner, MeshMakeData *data) +u16 getSmoothLightSolid(const v3POS &p, const v3POS &face_dir, const v3POS &corner, MeshMakeData *data) { return getSmoothLightTransparent(p + face_dir, corner - 2 * face_dir, data); } @@ -277,20 +277,20 @@ u16 getSmoothLightSolid(const v3s16 &p, const v3s16 &face_dir, const v3s16 &corn Both light banks. Node at p is not solid, and the lighting is not face-dependent. */ -u16 getSmoothLightTransparent(const v3s16 &p, const v3s16 &corner, MeshMakeData *data) +u16 getSmoothLightTransparent(const v3POS &p, const v3POS &corner, MeshMakeData *data) { - const std::array dirs = {{ + const std::array dirs = {{ // Always shine light - v3s16(0,0,0), - v3s16(corner.X,0,0), - v3s16(0,corner.Y,0), - v3s16(0,0,corner.Z), + v3POS(0,0,0), + v3POS(corner.X,0,0), + v3POS(0,corner.Y,0), + v3POS(0,0,corner.Z), // Can be obstructed - v3s16(corner.X,corner.Y,0), - v3s16(corner.X,0,corner.Z), - v3s16(0,corner.Y,corner.Z), - v3s16(corner.X,corner.Y,corner.Z) + v3POS(corner.X,corner.Y,0), + v3POS(corner.X,0,corner.Z), + v3POS(0,corner.Y,corner.Z), + v3POS(corner.X,corner.Y,corner.Z) }}; return getSmoothLightCombined(p, dirs, data); } @@ -346,33 +346,33 @@ void final_color_blend(video::SColor *result, // This table is moved outside getNodeVertexDirs to avoid the compiler using // a mutex to initialize this table at runtime right in the hot path. // For details search the internet for "cxa_guard_acquire". -static const v3s16 vertex_dirs_table[] = { +static const v3POS vertex_dirs_table[] = { // ( 1, 0, 0) - v3s16( 1,-1, 1), v3s16( 1,-1,-1), - v3s16( 1, 1,-1), v3s16( 1, 1, 1), + v3POS( 1,-1, 1), v3POS( 1,-1,-1), + v3POS( 1, 1,-1), v3POS( 1, 1, 1), // ( 0, 1, 0) - v3s16( 1, 1,-1), v3s16(-1, 1,-1), - v3s16(-1, 1, 1), v3s16( 1, 1, 1), + v3POS( 1, 1,-1), v3POS(-1, 1,-1), + v3POS(-1, 1, 1), v3POS( 1, 1, 1), // ( 0, 0, 1) - v3s16(-1,-1, 1), v3s16( 1,-1, 1), - v3s16( 1, 1, 1), v3s16(-1, 1, 1), + v3POS(-1,-1, 1), v3POS( 1,-1, 1), + v3POS( 1, 1, 1), v3POS(-1, 1, 1), // invalid - v3s16(), v3s16(), v3s16(), v3s16(), + v3POS(), v3POS(), v3POS(), v3POS(), // ( 0, 0,-1) - v3s16( 1,-1,-1), v3s16(-1,-1,-1), - v3s16(-1, 1,-1), v3s16( 1, 1,-1), + v3POS( 1,-1,-1), v3POS(-1,-1,-1), + v3POS(-1, 1,-1), v3POS( 1, 1,-1), // ( 0,-1, 0) - v3s16( 1,-1, 1), v3s16(-1,-1, 1), - v3s16(-1,-1,-1), v3s16( 1,-1,-1), + v3POS( 1,-1, 1), v3POS(-1,-1, 1), + v3POS(-1,-1,-1), v3POS( 1,-1,-1), // (-1, 0, 0) - v3s16(-1,-1,-1), v3s16(-1,-1, 1), - v3s16(-1, 1, 1), v3s16(-1, 1,-1) + v3POS(-1,-1,-1), v3POS(-1,-1, 1), + v3POS(-1, 1, 1), v3POS(-1, 1,-1) }; /* - vertex_dirs: v3s16[4] + vertex_dirs: v3POS[4] */ -static void getNodeVertexDirs(const v3s16 &dir, v3s16 *vertex_dirs) +static void getNodeVertexDirs(const v3POS &dir, v3POS *vertex_dirs) { /* If looked from outside the node towards the face, the corners are: @@ -396,32 +396,32 @@ static void getNodeVertexDirs(const v3s16 &dir, v3s16 *vertex_dirs) #pragma GCC diagnostic ignored "-Wclass-memaccess" #endif #endif - memcpy(vertex_dirs, &vertex_dirs_table[idx], 4 * sizeof(v3s16)); + memcpy(vertex_dirs, &vertex_dirs_table[idx], 4 * sizeof(v3POS)); #if defined(__GNUC__) && !defined(__clang__) #pragma GCC diagnostic pop #endif } -static void getNodeTextureCoords(v3f base, const v3f &scale, const v3s16 &dir, float *u, float *v) +static void getNodeTextureCoords(v3f base, const v3f &scale, const v3POS &dir, float *u, float *v) { if (dir.X > 0 || dir.Y != 0 || dir.Z < 0) base -= scale; - if (dir == v3s16(0,0,1)) { + if (dir == v3POS(0,0,1)) { *u = -base.X; *v = -base.Y; - } else if (dir == v3s16(0,0,-1)) { + } else if (dir == v3POS(0,0,-1)) { *u = base.X + 1; *v = -base.Y - 1; - } else if (dir == v3s16(1,0,0)) { + } else if (dir == v3POS(1,0,0)) { *u = base.Z + 1; *v = -base.Y - 1; - } else if (dir == v3s16(-1,0,0)) { + } else if (dir == v3POS(-1,0,0)) { *u = -base.Z; *v = -base.Y; - } else if (dir == v3s16(0,1,0)) { + } else if (dir == v3POS(0,1,0)) { *u = base.X + 1; *v = -base.Z - 1; - } else if (dir == v3s16(0,-1,0)) { + } else if (dir == v3POS(0,-1,0)) { *u = base.X + 1; *v = base.Z + 1; } @@ -440,7 +440,7 @@ struct FastFace }; static void makeFastFace(const TileSpec &tile, u16 li0, u16 li1, u16 li2, u16 li3, - const v3f &tp, const v3f &p, const v3s16 &dir, const v3f &scale, std::vector &dest) + const v3f &tp, const v3f &p, const v3POS &dir, const v3f &scale, std::vector &dest) { // Position is at the center of the cube. v3f pos = p * BS; @@ -451,12 +451,12 @@ static void makeFastFace(const TileSpec &tile, u16 li0, u16 li1, u16 li2, u16 li float h = 1.0f; v3f vertex_pos[4]; - v3s16 vertex_dirs[4]; + v3POS vertex_dirs[4]; getNodeVertexDirs(dir, vertex_dirs); if (tile.world_aligned) getNodeTextureCoords(tp, scale, dir, &x0, &y0); - v3s16 t; + v3POS t; u16 t1; switch (tile.rotation) { case 0: @@ -682,7 +682,7 @@ static u8 face_contents(content_t m1, content_t m2, bool *equivalent, /* Gets nth node tile (0 <= n <= 5). */ -void getNodeTileN(MapNode mn, const v3s16 &p, u8 tileindex, MeshMakeData *data, TileSpec &tile) +void getNodeTileN(MapNode mn, const v3POS &p, u8 tileindex, MeshMakeData *data, TileSpec &tile) { const NodeDefManager *ndef = data->m_client->ndef(); const ContentFeatures &f = ndef->get(mn); @@ -702,7 +702,7 @@ void getNodeTileN(MapNode mn, const v3s16 &p, u8 tileindex, MeshMakeData *data, /* Gets node tile given a face direction. */ -void getNodeTile(MapNode mn, const v3s16 &p, const v3s16 &dir, MeshMakeData *data, TileSpec &tile) +void getNodeTile(MapNode mn, const v3POS &p, const v3POS &dir, MeshMakeData *data, TileSpec &tile) { const NodeDefManager *ndef = data->m_client->ndef(); @@ -766,12 +766,12 @@ void getNodeTile(MapNode mn, const v3s16 &p, const v3s16 &dir, MeshMakeData *dat static void getTileInfo( // Input: MeshMakeData *data, - const v3s16 &p, - const v3s16 &face_dir, + const v3POS &p, + const v3POS &face_dir, // Output: bool &makes_face, - v3s16 &p_corrected, - v3s16 &face_dir_corrected, + v3POS &p_corrected, + v3POS &face_dir_corrected, u16 *lights, u8 &waving, TileSpec &tile @@ -779,7 +779,7 @@ static void getTileInfo( { VoxelManipulator &vmanip = data->m_vmanip; const NodeDefManager *ndef = data->m_client->ndef(); - v3s16 blockpos_nodes = data->m_blockpos * MAP_BLOCKSIZE; + v3POS blockpos_nodes = data->m_blockpos * MAP_BLOCKSIZE; const MapNode &n0 = vmanip.getNodeRefUnsafe(blockpos_nodes + p); @@ -834,10 +834,10 @@ static void getTileInfo( lights[0] = lights[1] = lights[2] = lights[3] = getFaceLight(n0, n1, face_dir, ndef); } else { - v3s16 vertex_dirs[4]; + v3POS vertex_dirs[4]; getNodeVertexDirs(face_dir_corrected, vertex_dirs); - v3s16 light_p = blockpos_nodes + p_corrected; + v3POS light_p = blockpos_nodes + p_corrected; for (u16 i = 0; i < 4; i++) lights[i] = getSmoothLightSolid(light_p, face_dir_corrected, vertex_dirs[i], data); } @@ -850,10 +850,10 @@ static void getTileInfo( */ static void updateFastFaceRow( MeshMakeData *data, - const v3s16 &&startpos, - v3s16 translate_dir, + const v3POS &&startpos, + v3POS translate_dir, const v3f &&translate_dir_f, - const v3s16 &&face_dir, + const v3POS &&face_dir, std::vector &dest) { static thread_local const bool waving_liquids = @@ -863,13 +863,13 @@ static void updateFastFaceRow( static thread_local const bool force_not_tiling = g_settings->getBool("enable_dynamic_shadows"); - v3s16 p = startpos; + v3POS p = startpos; u16 continuous_tiles_count = 1; bool makes_face = false; - v3s16 p_corrected; - v3s16 face_dir_corrected; + v3POS p_corrected; + v3POS face_dir_corrected; u16 lights[4] = {0, 0, 0, 0}; u8 waving = 0; TileSpec tile; @@ -886,8 +886,8 @@ static void updateFastFaceRow( bool next_is_different = true; bool next_makes_face = false; - v3s16 next_p_corrected; - v3s16 next_face_dir_corrected; + v3POS next_p_corrected; + v3POS next_face_dir_corrected; u16 next_lights[4] = {0, 0, 0, 0}; // If at last position, there is nothing to compare to and @@ -958,10 +958,10 @@ static void updateAllFastFaceRows(MeshMakeData *data, for (s16 y = 0; y < MAP_BLOCKSIZE; y++) for (s16 z = 0; z < MAP_BLOCKSIZE; z++) updateFastFaceRow(data, - v3s16(0, y, z), - v3s16(1, 0, 0), //dir + v3POS(0, y, z), + v3POS(1, 0, 0), //dir v3f (1, 0, 0), - v3s16(0, 1, 0), //face dir + v3POS(0, 1, 0), //face dir dest); /* @@ -970,10 +970,10 @@ static void updateAllFastFaceRows(MeshMakeData *data, for (s16 x = 0; x < MAP_BLOCKSIZE; x++) for (s16 y = 0; y < MAP_BLOCKSIZE; y++) updateFastFaceRow(data, - v3s16(x, y, 0), - v3s16(0, 0, 1), //dir + v3POS(x, y, 0), + v3POS(0, 0, 1), //dir v3f (0, 0, 1), - v3s16(1, 0, 0), //face dir + v3POS(1, 0, 0), //face dir dest); /* @@ -982,10 +982,10 @@ static void updateAllFastFaceRows(MeshMakeData *data, for (s16 z = 0; z < MAP_BLOCKSIZE; z++) for (s16 y = 0; y < MAP_BLOCKSIZE; y++) updateFastFaceRow(data, - v3s16(0, y, z), - v3s16(1, 0, 0), //dir + v3POS(0, y, z), + v3POS(1, 0, 0), //dir v3f (1, 0, 0), - v3s16(0, 0, 1), //face dir + v3POS(0, 0, 1), //face dir dest); } @@ -1007,7 +1007,7 @@ static void applyTileColor(PreMeshBuffer &pmb) MapBlockMesh */ -MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset): +MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3POS camera_offset): m_minimap_mapblock(NULL), m_tsrc(data->m_client->getTextureSource()), m_shdrsrc(data->m_client->getShaderSource()), diff --git a/src/client/mapblock_mesh.h b/src/client/mapblock_mesh.h index 3b17c4af98..2c90d19366 100644 --- a/src/client/mapblock_mesh.h +++ b/src/client/mapblock_mesh.h @@ -39,8 +39,8 @@ struct MinimapMapblock; struct MeshMakeData { VoxelManipulator m_vmanip; - v3s16 m_blockpos = v3s16(-1337,-1337,-1337); - v3s16 m_crack_pos_relative = v3s16(-1337,-1337,-1337); + v3POS m_blockpos = v3POS(-1337,-1337,-1337); + v3POS m_crack_pos_relative = v3POS(-1337,-1337,-1337); bool m_smooth_lighting = false; Client *m_client; @@ -51,8 +51,8 @@ struct MeshMakeData /* Copy block data manually (to allow optimizations by the caller) */ - void fillBlockDataBegin(const v3s16 &blockpos); - void fillBlockData(const v3s16 &block_offset, MapNode *data); + void fillBlockDataBegin(const v3POS &blockpos); + void fillBlockData(const v3POS &block_offset, MapNode *data); /* Copy central data directly from block, and other data from @@ -63,7 +63,7 @@ struct MeshMakeData /* Set the (node) position of a crack */ - void setCrack(int crack_level, v3s16 crack_pos); + void setCrack(int crack_level, v3POS crack_pos); /* Enable or disable smooth lighting @@ -86,7 +86,7 @@ class MapBlockMesh { public: // Builds the mesh given - MapBlockMesh(MeshMakeData *data, v3s16 camera_offset); + MapBlockMesh(MeshMakeData *data, v3POS camera_offset); ~MapBlockMesh(); // Main animation function, parameters: @@ -176,10 +176,10 @@ video::SColor encode_light(u16 light, u8 emissive_light); // Compute light at node u16 getInteriorLight(MapNode n, s32 increment, const NodeDefManager *ndef); -u16 getFaceLight(MapNode n, MapNode n2, const v3s16 &face_dir, +u16 getFaceLight(MapNode n, MapNode n2, const v3POS &face_dir, const NodeDefManager *ndef); -u16 getSmoothLightSolid(const v3s16 &p, const v3s16 &face_dir, const v3s16 &corner, MeshMakeData *data); -u16 getSmoothLightTransparent(const v3s16 &p, const v3s16 &corner, MeshMakeData *data); +u16 getSmoothLightSolid(const v3POS &p, const v3POS &face_dir, const v3POS &corner, MeshMakeData *data); +u16 getSmoothLightTransparent(const v3POS &p, const v3POS &corner, MeshMakeData *data); /*! * Returns the sunlight's color from the current @@ -211,5 +211,5 @@ void final_color_blend(video::SColor *result, // Adds MATERIAL_FLAG_CRACK if the node is cracked // TileSpec should be passed as reference due to the underlying TileFrame and its vector // TileFrame vector copy cost very much to client -void getNodeTileN(MapNode mn, const v3s16 &p, u8 tileindex, MeshMakeData *data, TileSpec &tile); -void getNodeTile(MapNode mn, const v3s16 &p, const v3s16 &dir, MeshMakeData *data, TileSpec &tile); +void getNodeTileN(MapNode mn, const v3POS &p, u8 tileindex, MeshMakeData *data, TileSpec &tile); +void getNodeTile(MapNode mn, const v3POS &p, const v3POS &dir, MeshMakeData *data, TileSpec &tile); diff --git a/src/client/mesh_generator_thread.cpp b/src/client/mesh_generator_thread.cpp index c8d1cba265..9ac3f0410f 100644 --- a/src/client/mesh_generator_thread.cpp +++ b/src/client/mesh_generator_thread.cpp @@ -69,7 +69,7 @@ MeshUpdateQueue::~MeshUpdateQueue() } } -void MeshUpdateQueue::addBlock(Map *map, v3s16 p, bool ack_block_to_server, bool urgent) +void MeshUpdateQueue::addBlock(Map *map, v3POS p, bool ack_block_to_server, bool urgent) { MutexAutoLock lock(m_mutex); @@ -82,13 +82,13 @@ void MeshUpdateQueue::addBlock(Map *map, v3s16 p, bool ack_block_to_server, bool std::vector cached_blocks; size_t cache_hit_counter = 0; cached_blocks.reserve(3*3*3); - v3s16 dp; + v3POS dp; for (dp.X = -1; dp.X <= 1; dp.X++) for (dp.Y = -1; dp.Y <= 1; dp.Y++) for (dp.Z = -1; dp.Z <= 1; dp.Z++) { - v3s16 p1 = p + dp; + v3POS p1 = p + dp; CachedMapBlockData *cached_block; - if (dp == v3s16(0, 0, 0)) + if (dp == v3POS(0, 0, 0)) cached_block = cacheBlock(map, p1, FORCE_UPDATE); else cached_block = cacheBlock(map, p1, SKIP_UPDATE_IF_ALREADY_CACHED, @@ -156,11 +156,11 @@ QueuedMeshUpdate *MeshUpdateQueue::pop() return NULL; } -CachedMapBlockData* MeshUpdateQueue::cacheBlock(Map *map, v3s16 p, UpdateMode mode, +CachedMapBlockData* MeshUpdateQueue::cacheBlock(Map *map, v3POS p, UpdateMode mode, size_t *cache_hit_counter) { CachedMapBlockData *cached_block = nullptr; - std::map::iterator it = + std::map::iterator it = m_cache.find(p); if (it != m_cache.end()) { @@ -193,9 +193,9 @@ CachedMapBlockData* MeshUpdateQueue::cacheBlock(Map *map, v3s16 p, UpdateMode mo return cached_block; } -CachedMapBlockData* MeshUpdateQueue::getCachedBlock(const v3s16 &p) +CachedMapBlockData* MeshUpdateQueue::getCachedBlock(const v3POS &p) { - std::map::iterator it = m_cache.find(p); + std::map::iterator it = m_cache.find(p); if (it != m_cache.end()) { return it->second; } @@ -212,11 +212,11 @@ void MeshUpdateQueue::fillDataFromMapBlockCache(QueuedMeshUpdate *q) std::time_t t_now = std::time(0); // Collect data for 3*3*3 blocks from cache - v3s16 dp; + v3POS dp; for (dp.X = -1; dp.X <= 1; dp.X++) for (dp.Y = -1; dp.Y <= 1; dp.Y++) for (dp.Z = -1; dp.Z <= 1; dp.Z++) { - v3s16 p = q->p + dp; + v3POS p = q->p + dp; CachedMapBlockData *cached_block = getCachedBlock(p); if (cached_block) { cached_block->refcount_from_queue--; @@ -246,7 +246,7 @@ void MeshUpdateQueue::cleanupCache() int t_now = time(0); - for (std::map::iterator it = m_cache.begin(); + for (std::map::iterator it = m_cache.begin(); it != m_cache.end(); ) { CachedMapBlockData *cached_block = it->second; if (cached_block->refcount_from_queue == 0 && @@ -271,7 +271,7 @@ MeshUpdateThread::MeshUpdateThread(Client *client): m_generation_interval = rangelim(m_generation_interval, 0, 50); } -void MeshUpdateThread::updateBlock(Map *map, v3s16 p, bool ack_block_to_server, +void MeshUpdateThread::updateBlock(Map *map, v3POS p, bool ack_block_to_server, bool urgent) { // Allow the MeshUpdateQueue to do whatever it wants diff --git a/src/client/mesh_generator_thread.h b/src/client/mesh_generator_thread.h index 4371b83909..a44b4dbd04 100644 --- a/src/client/mesh_generator_thread.h +++ b/src/client/mesh_generator_thread.h @@ -27,7 +27,7 @@ with this program; if not, write to the Free Software Foundation, Inc., struct CachedMapBlockData { - v3s16 p = v3s16(-1337, -1337, -1337); + v3POS p = v3POS(-1337, -1337, -1337); MapNode *data = nullptr; // A copy of the MapBlock's data member int refcount_from_queue = 0; std::time_t last_used_timestamp = std::time(0); @@ -38,10 +38,10 @@ struct CachedMapBlockData struct QueuedMeshUpdate { - v3s16 p = v3s16(-1337, -1337, -1337); + v3POS p = v3POS(-1337, -1337, -1337); bool ack_block_to_server = false; int crack_level = -1; - v3s16 crack_pos; + v3POS crack_pos; MeshMakeData *data = nullptr; // This is generated in MeshUpdateQueue::pop() QueuedMeshUpdate() = default; @@ -66,7 +66,7 @@ class MeshUpdateQueue // Caches the block at p and its neighbors (if needed) and queues a mesh // update for the block at p - void addBlock(Map *map, v3s16 p, bool ack_block_to_server, bool urgent); + void addBlock(Map *map, v3POS p, bool ack_block_to_server, bool urgent); // Returned pointer must be deleted // Returns NULL if queue is empty @@ -81,8 +81,8 @@ class MeshUpdateQueue private: Client *m_client; std::vector m_queue; - std::set m_urgents; - std::map m_cache; + std::set m_urgents; + std::map m_cache; std::mutex m_mutex; // TODO: Add callback to update these when g_settings changes @@ -90,16 +90,16 @@ class MeshUpdateQueue bool m_cache_smooth_lighting; int m_meshgen_block_cache_size; - CachedMapBlockData *cacheBlock(Map *map, v3s16 p, UpdateMode mode, + CachedMapBlockData *cacheBlock(Map *map, v3POS p, UpdateMode mode, size_t *cache_hit_counter = NULL); - CachedMapBlockData *getCachedBlock(const v3s16 &p); + CachedMapBlockData *getCachedBlock(const v3POS &p); void fillDataFromMapBlockCache(QueuedMeshUpdate *q); void cleanupCache(); }; struct MeshUpdateResult { - v3s16 p = v3s16(-1338, -1338, -1338); + v3POS p = v3POS(-1338, -1338, -1338); MapBlockMesh *mesh = nullptr; bool ack_block_to_server = false; @@ -113,9 +113,9 @@ class MeshUpdateThread : public UpdateThread // Caches the block at p and its neighbors (if needed) and queues a mesh // update for the block at p - void updateBlock(Map *map, v3s16 p, bool ack_block_to_server, bool urgent); + void updateBlock(Map *map, v3POS p, bool ack_block_to_server, bool urgent); - v3s16 m_camera_offset; + v3POS m_camera_offset; MutexedQueue m_queue_out; private: diff --git a/src/client/minimap.cpp b/src/client/minimap.cpp index f26aa1c70e..13d9074718 100644 --- a/src/client/minimap.cpp +++ b/src/client/minimap.cpp @@ -42,7 +42,7 @@ MinimapUpdateThread::~MinimapUpdateThread() } } -bool MinimapUpdateThread::pushBlockUpdate(v3s16 pos, MinimapMapblock *data) +bool MinimapUpdateThread::pushBlockUpdate(v3POS pos, MinimapMapblock *data) { MutexAutoLock lock(m_queue_mutex); @@ -78,7 +78,7 @@ bool MinimapUpdateThread::popBlockUpdate(QueuedMinimapUpdate *update) return true; } -void MinimapUpdateThread::enqueueBlock(v3s16 pos, MinimapMapblock *data) +void MinimapUpdateThread::enqueueBlock(v3POS pos, MinimapMapblock *data) { pushBlockUpdate(pos, data); deferUpdate(); @@ -92,14 +92,14 @@ void MinimapUpdateThread::doUpdate() while (popBlockUpdate(&update)) { if (update.data) { // Swap two values in the map using single lookup - std::pair::iterator, bool> + std::pair::iterator, bool> result = m_blocks_cache.insert(std::make_pair(update.pos, update.data)); if (!result.second) { delete result.first->second; result.first->second = update.data; } } else { - std::map::iterator it; + std::map::iterator it; it = m_blocks_cache.find(update.pos); if (it != m_blocks_cache.end()) { delete it->second; @@ -117,12 +117,12 @@ void MinimapUpdateThread::doUpdate() } } -void MinimapUpdateThread::getMap(v3s16 pos, s16 size, s16 height) +void MinimapUpdateThread::getMap(v3POS pos, s16 size, POS height) { - v3s16 pos_min(pos.X - size / 2, pos.Y - height / 2, pos.Z - size / 2); - v3s16 pos_max(pos_min.X + size - 1, pos.Y + height / 2, pos_min.Z + size - 1); - v3s16 blockpos_min = getNodeBlockPos(pos_min); - v3s16 blockpos_max = getNodeBlockPos(pos_max); + v3POS pos_min(pos.X - size / 2, pos.Y - height / 2, pos.Z - size / 2); + v3POS pos_max(pos_min.X + size - 1, pos.Y + height / 2, pos_min.Z + size - 1); + v3BPOS blockpos_min = getNodeBlockPos(pos_min); + v3BPOS blockpos_max = getNodeBlockPos(pos_max); // clear the map for (int z = 0; z < size; z++) @@ -134,31 +134,31 @@ void MinimapUpdateThread::getMap(v3s16 pos, s16 size, s16 height) } // draw the map - v3s16 blockpos; + v3BPOS blockpos; for (blockpos.Z = blockpos_min.Z; blockpos.Z <= blockpos_max.Z; ++blockpos.Z) for (blockpos.Y = blockpos_min.Y; blockpos.Y <= blockpos_max.Y; ++blockpos.Y) for (blockpos.X = blockpos_min.X; blockpos.X <= blockpos_max.X; ++blockpos.X) { - std::map::const_iterator pblock = + std::map::const_iterator pblock = m_blocks_cache.find(blockpos); if (pblock == m_blocks_cache.end()) continue; const MinimapMapblock &block = *pblock->second; - v3s16 block_node_min(blockpos * MAP_BLOCKSIZE); - v3s16 block_node_max(block_node_min + MAP_BLOCKSIZE - 1); + v3POS block_node_min(blockpos * MAP_BLOCKSIZE); + v3POS block_node_max(block_node_min + MAP_BLOCKSIZE - 1); // clip - v3s16 range_min = componentwise_max(block_node_min, pos_min); - v3s16 range_max = componentwise_min(block_node_max, pos_max); + v3POS range_min = componentwise_max(block_node_min, pos_min); + v3POS range_max = componentwise_min(block_node_max, pos_max); - v3s16 pos; + v3POS pos; pos.Y = range_min.Y; for (pos.Z = range_min.Z; pos.Z <= range_max.Z; ++pos.Z) for (pos.X = range_min.X; pos.X <= range_max.X; ++pos.X) { - v3s16 inblock_pos = pos - block_node_min; + v3POS inblock_pos = pos - block_node_min; const MinimapPixel &in_pixel = block.data[inblock_pos.Z * MAP_BLOCKSIZE + inblock_pos.X]; - v3s16 inmap_pos = pos - pos_min; + v3POS inmap_pos = pos - pos_min; MinimapPixel &out_pixel = data->minimap_scan[inmap_pos.X + inmap_pos.Z * size]; @@ -260,7 +260,7 @@ Minimap::~Minimap() delete m_minimap_update_thread; } -void Minimap::addBlock(v3s16 pos, MinimapMapblock *data) +void Minimap::addBlock(v3POS pos, MinimapMapblock *data) { m_minimap_update_thread->enqueueBlock(pos, data); } @@ -394,7 +394,7 @@ void Minimap::nextMode() setModeIndex(m_current_mode_index); } -void Minimap::setPos(v3s16 pos) +void Minimap::setPos(v3POS pos) { bool do_update = false; @@ -705,12 +705,12 @@ void Minimap::updateActiveMarkers() m_active_markers.clear(); v3f cam_offset = intToFloat(client->getCamera()->getOffset(), BS); - v3s16 pos_offset = data->pos - v3s16(data->mode.map_size / 2, + v3POS pos_offset = data->pos - v3POS(data->mode.map_size / 2, data->mode.scan_height / 2, data->mode.map_size / 2); for (MinimapMarker *marker : m_markers) { - v3s16 pos = floatToInt(marker->parent_node->getAbsolutePosition() + + v3POS pos = floatToInt(marker->parent_node->getAbsolutePosition() + cam_offset, BS) - pos_offset; if (pos.X < 0 || pos.X > data->mode.map_size || pos.Y < 0 || pos.Y > data->mode.scan_height || @@ -733,7 +733,7 @@ void Minimap::updateActiveMarkers() //// MinimapMapblock //// -void MinimapMapblock::getMinimapNodes(VoxelManipulator *vmanip, const v3s16 &pos) +void MinimapMapblock::getMinimapNodes(VoxelManipulator *vmanip, const v3POS &pos) { for (s16 x = 0; x < MAP_BLOCKSIZE; x++) @@ -743,7 +743,7 @@ void MinimapMapblock::getMinimapNodes(VoxelManipulator *vmanip, const v3s16 &pos MinimapPixel *mmpixel = &data[z * MAP_BLOCKSIZE + x]; for (s16 y = MAP_BLOCKSIZE -1; y >= 0; y--) { - v3s16 p(x, y, z); + v3POS p(x, y, z); MapNode n = vmanip->getNodeNoEx(pos + p); if (!surface_found && n.getContent() != CONTENT_AIR) { mmpixel->height = y; diff --git a/src/client/minimap.h b/src/client/minimap.h index 87c9668eef..cfa595b26e 100644 --- a/src/client/minimap.h +++ b/src/client/minimap.h @@ -63,15 +63,15 @@ struct MinimapPixel { }; struct MinimapMapblock { - void getMinimapNodes(VoxelManipulator *vmanip, const v3s16 &pos); + void getMinimapNodes(VoxelManipulator *vmanip, const v3POS &pos); MinimapPixel data[MAP_BLOCKSIZE * MAP_BLOCKSIZE]; }; struct MinimapData { MinimapModeDef mode; - v3s16 pos; - v3s16 old_pos; + v3POS pos; + v3POS old_pos; MinimapPixel minimap_scan[MINIMAP_MAX_SX * MINIMAP_MAX_SY]; bool map_invalidated; bool minimap_shape_round; @@ -86,7 +86,7 @@ struct MinimapData { }; struct QueuedMinimapUpdate { - v3s16 pos; + v3BPOS pos; MinimapMapblock *data = nullptr; }; @@ -95,9 +95,9 @@ class MinimapUpdateThread : public UpdateThread { MinimapUpdateThread() : UpdateThread("Minimap") {} virtual ~MinimapUpdateThread(); - void getMap(v3s16 pos, s16 size, s16 height); - void enqueueBlock(v3s16 pos, MinimapMapblock *data); - bool pushBlockUpdate(v3s16 pos, MinimapMapblock *data); + void getMap(v3BPOS pos, s16 size, POS height); + void enqueueBlock(v3BPOS pos, MinimapMapblock *data); + bool pushBlockUpdate(v3BPOS pos, MinimapMapblock *data); bool popBlockUpdate(QueuedMinimapUpdate *update); MinimapData *data = nullptr; @@ -108,7 +108,7 @@ class MinimapUpdateThread : public UpdateThread { private: std::mutex m_queue_mutex; std::deque m_update_queue; - std::map m_blocks_cache; + std::map m_blocks_cache; }; class Minimap { @@ -116,12 +116,12 @@ class Minimap { Minimap(Client *client); ~Minimap(); - void addBlock(v3s16 pos, MinimapMapblock *data); + void addBlock(v3BPOS pos, MinimapMapblock *data); v3f getYawVec(); - void setPos(v3s16 pos); - v3s16 getPos() const { return data->pos; } + void setPos(v3POS pos); + v3POS getPos() const { return data->pos; } void setAngle(f32 angle); f32 getAngle() const { return m_angle; } void toggleMinimapShape(); diff --git a/src/client/particles.cpp b/src/client/particles.cpp index 288826a5f2..0e09f62243 100644 --- a/src/client/particles.cpp +++ b/src/client/particles.cpp @@ -177,7 +177,7 @@ void Particle::updateLight() u8 light = 0; bool pos_ok; - v3s16 p = v3s16( + v3POS p = v3POS( floor(m_pos.X+0.5), floor(m_pos.Y+0.5), floor(m_pos.Z+0.5) @@ -227,7 +227,7 @@ void Particle::updateVertices() m_vertices[3] = video::S3DVertex(-m_size / 2, m_size / 2, 0, 0, 0, 0, m_color, tx0, ty0); - v3s16 camera_offset = m_env->getCameraOffset(); + v3POS camera_offset = m_env->getCameraOffset(); for (video::S3DVertex &vertex : m_vertices) { if (m_vertical) { v3f ppos = m_player->getPosition()/BS; @@ -281,7 +281,7 @@ void ParticleSpawner::spawnParticle(ClientEnvironment *env, float radius, pos *= BS; attached_absolute_pos_rot_matrix->transformVect(pos); pos /= BS; - v3s16 camera_offset = m_particlemanager->m_env->getCameraOffset(); + v3POS camera_offset = m_particlemanager->m_env->getCameraOffset(); pos.X += camera_offset.X; pos.Y += camera_offset.Y; pos.Z += camera_offset.Z; @@ -559,7 +559,7 @@ bool ParticleManager::getNodeParticleParams(const MapNode &n, // spawned during the digging of a node. void ParticleManager::addDiggingParticles(IGameDef *gamedef, - LocalPlayer *player, v3s16 pos, const MapNode &n, const ContentFeatures &f) + LocalPlayer *player, v3POS pos, const MapNode &n, const ContentFeatures &f) { // No particles for "airlike" nodes if (f.drawtype == NDT_AIRLIKE) @@ -574,7 +574,7 @@ void ParticleManager::addDiggingParticles(IGameDef *gamedef, // function, called from Game::handleDigging() in game.cpp. void ParticleManager::addNodeParticle(IGameDef *gamedef, - LocalPlayer *player, v3s16 pos, const MapNode &n, const ContentFeatures &f) + LocalPlayer *player, v3POS pos, const MapNode &n, const ContentFeatures &f) { ParticleParameters p; video::ITexture *texture; diff --git a/src/client/particles.h b/src/client/particles.h index 2011f02626..965d229014 100644 --- a/src/client/particles.h +++ b/src/client/particles.h @@ -97,7 +97,7 @@ class Particle : public scene::ISceneNode bool m_collision_removal; bool m_object_collision; bool m_vertical; - v3s16 m_camera_offset; + v3POS m_camera_offset; struct TileAnimationParams m_animation; float m_animation_time = 0.0f; int m_animation_frame = 0; @@ -150,10 +150,10 @@ friend class ParticleSpawner; void handleParticleEvent(ClientEvent *event, Client *client, LocalPlayer *player); - void addDiggingParticles(IGameDef *gamedef, LocalPlayer *player, v3s16 pos, + void addDiggingParticles(IGameDef *gamedef, LocalPlayer *player, v3POS pos, const MapNode &n, const ContentFeatures &f); - void addNodeParticle(IGameDef *gamedef, LocalPlayer *player, v3s16 pos, + void addNodeParticle(IGameDef *gamedef, LocalPlayer *player, v3POS pos, const MapNode &n, const ContentFeatures &f); /** diff --git a/src/client/shadows/dynamicshadows.cpp b/src/client/shadows/dynamicshadows.cpp index 6ef5a4f1db..b69c963b31 100644 --- a/src/client/shadows/dynamicshadows.cpp +++ b/src/client/shadows/dynamicshadows.cpp @@ -110,7 +110,7 @@ void DirectionalLight::update_frustum(const Camera *cam, Client *client, bool fo dirty = true; // when camera offset changes, adjust the current frustum view matrix to avoid flicker - v3s16 cam_offset = cam->getOffset(); + v3POS cam_offset = cam->getOffset(); if (cam_offset != shadow_frustum.camera_offset) { v3f rotated_offset; shadow_frustum.ViewMat.rotateVect(rotated_offset, intToFloat(cam_offset - shadow_frustum.camera_offset, BS)); diff --git a/src/client/shadows/dynamicshadows.h b/src/client/shadows/dynamicshadows.h index d8be66be89..69d894a3e8 100644 --- a/src/client/shadows/dynamicshadows.h +++ b/src/client/shadows/dynamicshadows.h @@ -34,7 +34,7 @@ struct shadowFrustum core::matrix4 ProjOrthMat; core::matrix4 ViewMat; v3f position; - v3s16 camera_offset; + v3POS camera_offset; }; class DirectionalLight diff --git a/src/client/tile.cpp b/src/client/tile.cpp index da03ff5c8c..97191152fb 100644 --- a/src/client/tile.cpp +++ b/src/client/tile.cpp @@ -848,7 +848,7 @@ static video::IImage *createInventoryCubeImage( auto draw_image = [=] (video::IImage *image, float shade_factor, s16 xu, s16 xv, s16 x1, s16 yu, s16 yv, s16 y1, - std::initializer_list offsets) -> void { + std::initializer_list offsets) -> void { u32 brightness = core::clamp(256 * shade_factor, 0, 256); const u32 *source = lock_image(image); for (u16 v = 0; v < size; v++) { diff --git a/src/clientiface.cpp b/src/clientiface.cpp index a1c3e11873..bdc6b11b9e 100644 --- a/src/clientiface.cpp +++ b/src/clientiface.cpp @@ -64,7 +64,7 @@ RemoteClient::RemoteClient() : { } -void RemoteClient::ResendBlockIfOnWire(v3s16 p) +void RemoteClient::ResendBlockIfOnWire(v3POS p) { // if this block is on wire, mark it for sending again as soon as possible if (m_blocks_sending.find(p) != m_blocks_sending.end()) { @@ -128,9 +128,9 @@ void RemoteClient::GetNextBlocks ( // Predict to next block v3f playerpos_predicted = playerpos + playerspeeddir * (MAP_BLOCKSIZE * BS); - v3s16 center_nodepos = floatToInt(playerpos_predicted, BS); + v3POS center_nodepos = floatToInt(playerpos_predicted, BS); - v3s16 center = getNodeBlockPos(center_nodepos); + v3BPOS center = getNodeBlockPos(center_nodepos); // Camera position and direction v3f camera_pos = sao->getEyePosition(); @@ -184,7 +184,7 @@ void RemoteClient::GetNextBlocks ( } if (m_nearest_unsent_d > 0) { // make sure any blocks modified since the last time we sent blocks are resent - for (const v3s16 &p : m_blocks_modified) { + for (const v3POS &p : m_blocks_modified) { m_nearest_unsent_d = std::min(m_nearest_unsent_d, center.getDistanceFrom(p)); } } @@ -229,7 +229,7 @@ void RemoteClient::GetNextBlocks ( s32 nearest_sent_d = -1; //bool queue_is_full = false; - const v3s16 cam_pos_nodes = floatToInt(camera_pos, BS); + const v3POS cam_pos_nodes = floatToInt(camera_pos, BS); s16 d; for (d = d_start; d <= d_max; d++) { @@ -237,11 +237,11 @@ void RemoteClient::GetNextBlocks ( Get the border/face dot coordinates of a "d-radiused" box */ - std::vector list = FacePositionCache::getFacePositions(d); + std::vector list = FacePositionCache::getFacePositions(d); - std::vector::iterator li; + std::vector::iterator li; for (li = list.begin(); li != list.end(); ++li) { - v3s16 p = *li + center; + v3BPOS p = *li + center; /* Send throttling @@ -395,7 +395,7 @@ void RemoteClient::GetNextBlocks ( m_nearest_unsent_d = new_nearest_unsent_d; } -void RemoteClient::GotBlock(v3s16 p) +void RemoteClient::GotBlock(v3BPOS p) { if (m_blocks_sending.find(p) != m_blocks_sending.end()) { m_blocks_sending.erase(p); @@ -407,7 +407,7 @@ void RemoteClient::GotBlock(v3s16 p) } } -void RemoteClient::SentBlock(v3s16 p) +void RemoteClient::SentBlock(v3BPOS p) { if (m_blocks_sending.find(p) == m_blocks_sending.end()) m_blocks_sending[p] = 0.0f; @@ -416,7 +416,7 @@ void RemoteClient::SentBlock(v3s16 p) " already in m_blocks_sending"< &blocks) +void RemoteClient::SetBlocksNotSent(std::map &blocks) { m_nothing_to_send_pause_timer = 0; for (auto &block : blocks) { - v3s16 p = block.first; + v3POS p = block.first; // remove the block from sending and sent sets, // and mark as modified if found if (m_blocks_sending.erase(p) + m_blocks_sent.erase(p) > 0) @@ -637,7 +637,7 @@ std::vector ClientInterface::getClientIDs(ClientState min_state) return reply; } -void ClientInterface::markBlockposAsNotSent(const v3s16 &pos) +void ClientInterface::markBlockposAsNotSent(const v3POS &pos) { RecursiveMutexAutoLock clientslock(m_clients_mutex); for (const auto &client : m_clients) { diff --git a/src/clientiface.h b/src/clientiface.h index b1591ddb02..f67c0cdedd 100644 --- a/src/clientiface.h +++ b/src/clientiface.h @@ -206,7 +206,7 @@ enum ClientStateEvent */ struct PrioritySortedBlockTransfer { - PrioritySortedBlockTransfer(float a_priority, const v3s16 &a_pos, session_t a_peer_id) + PrioritySortedBlockTransfer(float a_priority, const v3BPOS &a_pos, session_t a_peer_id) { priority = a_priority; pos = a_pos; @@ -217,7 +217,7 @@ struct PrioritySortedBlockTransfer return priority < other.priority; } float priority; - v3s16 pos; + v3BPOS pos; session_t peer_id; }; @@ -258,12 +258,12 @@ class RemoteClient void GetNextBlocks(ServerEnvironment *env, EmergeManager* emerge, float dtime, std::vector &dest); - void GotBlock(v3s16 p); + void GotBlock(v3POS p); - void SentBlock(v3s16 p); + void SentBlock(v3POS p); - void SetBlockNotSent(v3s16 p); - void SetBlocksNotSent(std::map &blocks); + void SetBlockNotSent(v3POS p); + void SetBlocksNotSent(std::map &blocks); /** * tell client about this block being modified right now. @@ -271,11 +271,11 @@ class RemoteClient * while modification is processed by server * @param p position of modified block */ - void ResendBlockIfOnWire(v3s16 p); + void ResendBlockIfOnWire(v3POS p); u32 getSendingCount() const { return m_blocks_sending.size(); } - bool isBlockSent(v3s16 p) const + bool isBlockSent(v3POS p) const { return m_blocks_sent.find(p) != m_blocks_sent.end(); } @@ -369,9 +369,9 @@ class RemoteClient List of block positions. No MapBlock* is stored here because the blocks can get deleted. */ - std::set m_blocks_sent; - s16 m_nearest_unsent_d = 0; - v3s16 m_last_center; + std::set m_blocks_sent; + POS m_nearest_unsent_d = 0; + v3POS m_last_center; v3f m_last_camera_dir; const u16 m_max_simul_sends; @@ -389,7 +389,7 @@ class RemoteClient Block is removed when GOTBLOCKS is received. Value is time from sending. (not used at the moment) */ - std::map m_blocks_sending; + std::map m_blocks_sending; /* Blocks that have been modified since blocks were @@ -399,7 +399,7 @@ class RemoteClient List of block positions. */ - std::set m_blocks_modified; + std::set m_blocks_modified; /* Count of excess GotBlocks(). @@ -452,7 +452,7 @@ class ClientInterface { std::vector getClientIDs(ClientState min_state=CS_Active); /* mark block as not sent to active client sessions */ - void markBlockposAsNotSent(const v3s16 &pos); + void markBlockposAsNotSent(const v3POS &pos); /* verify is server user limit was reached */ bool isUserLimitReached(); diff --git a/src/cmake_config.h.in b/src/cmake_config.h.in index cfcee4b585..60afb5da37 100644 --- a/src/cmake_config.h.in +++ b/src/cmake_config.h.in @@ -36,3 +36,4 @@ #cmakedefine01 CURSES_HAVE_NCURSESW_NCURSES_H #cmakedefine01 CURSES_HAVE_NCURSESW_CURSES_H #cmakedefine01 BUILD_UNITTESTS +#cmakedefine01 USE_POS32 diff --git a/src/collision.cpp b/src/collision.cpp index d85a568843..3c1a7b80a4 100644 --- a/src/collision.cpp +++ b/src/collision.cpp @@ -38,7 +38,7 @@ with this program; if not, write to the Free Software Foundation, Inc., struct NearbyCollisionInfo { // node - NearbyCollisionInfo(bool is_ul, int bouncy, const v3s16 &pos, + NearbyCollisionInfo(bool is_ul, int bouncy, const v3POS &pos, const aabb3f &box) : is_unloaded(is_ul), obj(nullptr), @@ -62,7 +62,7 @@ struct NearbyCollisionInfo { bool is_step_up = false; ActiveObject *obj; int bouncy; - v3s16 position; + v3POS position; aabb3f box; }; @@ -214,7 +214,7 @@ bool wouldCollideWithCeiling( return false; } -static inline void getNeighborConnectingFace(const v3s16 &p, +static inline void getNeighborConnectingFace(const v3POS &p, const NodeDefManager *nodedef, Map *map, MapNode n, int v, int *neighbors) { MapNode n2 = map->getNode(p); @@ -281,12 +281,12 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef, MYMAX(pos_f->Y, newpos_f.Y), MYMAX(pos_f->Z, newpos_f.Z) ); - v3s16 min = floatToInt(minpos_f + box_0.MinEdge, BS) - v3s16(1, 1, 1); - v3s16 max = floatToInt(maxpos_f + box_0.MaxEdge, BS) + v3s16(1, 1, 1); + v3POS min = floatToInt(minpos_f + box_0.MinEdge, BS) - v3POS(1, 1, 1); + v3POS max = floatToInt(maxpos_f + box_0.MaxEdge, BS) + v3POS(1, 1, 1); bool any_position_valid = false; - v3s16 p; + v3POS p; for (p.X = min.X; p.X <= max.X; p.X++) for (p.Y = min.Y; p.Y <= max.Y; p.Y++) for (p.Z = min.Z; p.Z <= max.Z; p.Z++) { @@ -308,7 +308,7 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef, int neighbors = 0; if (f.drawtype == NDT_NODEBOX && f.node_box.type == NODEBOX_CONNECTED) { - v3s16 p2 = p; + v3POS p2 = p; p2.Y++; getNeighborConnectingFace(p2, nodedef, map, n, 1, &neighbors); diff --git a/src/collision.h b/src/collision.h index 87a5028287..31cf92ff1d 100644 --- a/src/collision.h +++ b/src/collision.h @@ -47,7 +47,7 @@ struct CollisionInfo CollisionType type = COLLISION_NODE; CollisionAxis axis = COLLISION_AXIS_NONE; - v3s16 node_p = v3s16(-32768,-32768,-32768); // COLLISION_NODE + v3POS node_p = v3POS(-32768,-32768,-32768); // COLLISION_NODE ActiveObject *object = nullptr; // COLLISION_OBJECT v3f old_speed; v3f new_speed; diff --git a/src/constants.h b/src/constants.h index 3cc3af0945..d2497feb13 100644 --- a/src/constants.h +++ b/src/constants.h @@ -19,6 +19,8 @@ with this program; if not, write to the Free Software Foundation, Inc., #pragma once +#include "config.h" + /* All kinds of constants. @@ -64,7 +66,11 @@ with this program; if not, write to the Free Software Foundation, Inc., // I really don't want to make every algorithm to check if it's going near // the limit or not, so this is lower. // This is the maximum value the setting map_generation_limit can be +#if USE_POS32 +#define MAX_MAP_GENERATION_LIMIT (2147483008) +#else #define MAX_MAP_GENERATION_LIMIT (31000) +#endif // Size of node in floating-point units // The original idea behind this is to disallow plain casts between diff --git a/src/content_nodemeta.cpp b/src/content_nodemeta.cpp index 39743c11f7..0c05abc1a5 100644 --- a/src/content_nodemeta.cpp +++ b/src/content_nodemeta.cpp @@ -165,7 +165,7 @@ void content_nodemeta_deserialize_legacy(std::istream &is, { u16 p16 = readU16(is); - v3s16 p(0,0,0); + v3POS p(0,0,0); p.Z += p16 / MAP_BLOCKSIZE / MAP_BLOCKSIZE; p16 -= p.Z * MAP_BLOCKSIZE * MAP_BLOCKSIZE; p.Y += p16 / MAP_BLOCKSIZE; diff --git a/src/database/database-dummy.cpp b/src/database/database-dummy.cpp index b56f341c5b..4881ab708f 100644 --- a/src/database/database-dummy.cpp +++ b/src/database/database-dummy.cpp @@ -25,15 +25,15 @@ Dummy database class #include "remoteplayer.h" -bool Database_Dummy::saveBlock(const v3s16 &pos, const std::string &data) +bool Database_Dummy::saveBlock(const v3BPOS &pos, const std::string &data) { - m_database[getBlockAsInteger(pos)] = data; + m_database[getBlockAsString(pos)] = data; return true; } -void Database_Dummy::loadBlock(const v3s16 &pos, std::string *block) +void Database_Dummy::loadBlock(const v3BPOS &pos, std::string *block) { - s64 i = getBlockAsInteger(pos); + std::string i = getBlockAsString(pos); auto it = m_database.find(i); if (it == m_database.end()) { *block = ""; @@ -43,18 +43,18 @@ void Database_Dummy::loadBlock(const v3s16 &pos, std::string *block) *block = it->second; } -bool Database_Dummy::deleteBlock(const v3s16 &pos) +bool Database_Dummy::deleteBlock(const v3BPOS &pos) { - m_database.erase(getBlockAsInteger(pos)); + m_database.erase(getBlockAsString(pos)); return true; } -void Database_Dummy::listAllLoadableBlocks(std::vector &dst) +void Database_Dummy::listAllLoadableBlocks(std::vector &dst) { dst.reserve(m_database.size()); - for (std::map::const_iterator x = m_database.begin(); + for (std::map::const_iterator x = m_database.begin(); x != m_database.end(); ++x) { - dst.push_back(getIntegerAsBlock(x->first)); + dst.push_back(getStringAsBlock(x->first)); } } diff --git a/src/database/database-dummy.h b/src/database/database-dummy.h index b69919f845..0b9620dc06 100644 --- a/src/database/database-dummy.h +++ b/src/database/database-dummy.h @@ -27,10 +27,10 @@ with this program; if not, write to the Free Software Foundation, Inc., class Database_Dummy : public MapDatabase, public PlayerDatabase { public: - bool saveBlock(const v3s16 &pos, const std::string &data); - void loadBlock(const v3s16 &pos, std::string *block); - bool deleteBlock(const v3s16 &pos); - void listAllLoadableBlocks(std::vector &dst); + bool saveBlock(const v3BPOS &pos, const std::string &data); + void loadBlock(const v3BPOS &pos, std::string *block); + bool deleteBlock(const v3BPOS &pos); + void listAllLoadableBlocks(std::vector &dst); void savePlayer(RemotePlayer *player); bool loadPlayer(RemotePlayer *player, PlayerSAO *sao); @@ -41,6 +41,6 @@ class Database_Dummy : public MapDatabase, public PlayerDatabase void endSave() {} private: - std::map m_database; + std::map m_database; std::set m_player_database; }; diff --git a/src/database/database-leveldb.cpp b/src/database/database-leveldb.cpp index 39f4c84423..a393e1edb4 100644 --- a/src/database/database-leveldb.cpp +++ b/src/database/database-leveldb.cpp @@ -55,10 +55,10 @@ Database_LevelDB::~Database_LevelDB() delete m_database; } -bool Database_LevelDB::saveBlock(const v3s16 &pos, const std::string &data) +bool Database_LevelDB::saveBlock(const v3BPOS &pos, const std::string &data) { leveldb::Status status = m_database->Put(leveldb::WriteOptions(), - i64tos(getBlockAsInteger(pos)), data); + getBlockAsStringCompatible(pos), data); if (!status.ok()) { warningstream << "saveBlock: LevelDB error saving block " << PP(pos) << ": " << status.ToString() << std::endl; @@ -68,19 +68,19 @@ bool Database_LevelDB::saveBlock(const v3s16 &pos, const std::string &data) return true; } -void Database_LevelDB::loadBlock(const v3s16 &pos, std::string *block) +void Database_LevelDB::loadBlock(const v3BPOS &pos, std::string *block) { leveldb::Status status = m_database->Get(leveldb::ReadOptions(), - i64tos(getBlockAsInteger(pos)), block); + getBlockAsStringCompatible(pos), block); if (!status.ok()) block->clear(); } -bool Database_LevelDB::deleteBlock(const v3s16 &pos) +bool Database_LevelDB::deleteBlock(const v3BPOS &pos) { leveldb::Status status = m_database->Delete(leveldb::WriteOptions(), - i64tos(getBlockAsInteger(pos))); + getBlockAsStringCompatible(pos)); if (!status.ok()) { warningstream << "deleteBlock: LevelDB error deleting block " << PP(pos) << ": " << status.ToString() << std::endl; @@ -90,11 +90,11 @@ bool Database_LevelDB::deleteBlock(const v3s16 &pos) return true; } -void Database_LevelDB::listAllLoadableBlocks(std::vector &dst) +void Database_LevelDB::listAllLoadableBlocks(std::vector &dst) { leveldb::Iterator* it = m_database->NewIterator(leveldb::ReadOptions()); for (it->SeekToFirst(); it->Valid(); it->Next()) { - dst.push_back(getIntegerAsBlock(stoi64(it->key().ToString()))); + dst.push_back(getStringAsBlock(it->key().ToString())); } ENSURE_STATUS_OK(it->status()); // Check for any errors found during the scan delete it; diff --git a/src/database/database-leveldb.h b/src/database/database-leveldb.h index 61def12569..b1ffe270f5 100644 --- a/src/database/database-leveldb.h +++ b/src/database/database-leveldb.h @@ -33,10 +33,10 @@ class Database_LevelDB : public MapDatabase Database_LevelDB(const std::string &savedir); ~Database_LevelDB(); - bool saveBlock(const v3s16 &pos, const std::string &data); - void loadBlock(const v3s16 &pos, std::string *block); - bool deleteBlock(const v3s16 &pos); - void listAllLoadableBlocks(std::vector &dst); + bool saveBlock(const v3BPOS &pos, const std::string &data); + void loadBlock(const v3BPOS &pos, std::string *block); + bool deleteBlock(const v3BPOS &pos); + void listAllLoadableBlocks(std::vector &dst); void beginSave() {} void endSave() {} diff --git a/src/database/database-postgresql.cpp b/src/database/database-postgresql.cpp index 3469f42428..cd7bc536b2 100644 --- a/src/database/database-postgresql.cpp +++ b/src/database/database-postgresql.cpp @@ -226,7 +226,7 @@ void MapDatabasePostgreSQL::initStatements() "SELECT posX, posY, posZ FROM blocks"); } -bool MapDatabasePostgreSQL::saveBlock(const v3s16 &pos, const std::string &data) +bool MapDatabasePostgreSQL::saveBlock(const v3BPOS &pos, const std::string &data) { // Verify if we don't overflow the platform integer with the mapblock size if (data.size() > INT_MAX) { @@ -258,7 +258,7 @@ bool MapDatabasePostgreSQL::saveBlock(const v3s16 &pos, const std::string &data) return true; } -void MapDatabasePostgreSQL::loadBlock(const v3s16 &pos, std::string *block) +void MapDatabasePostgreSQL::loadBlock(const v3BPOS &pos, std::string *block) { verifyDatabase(); @@ -282,7 +282,7 @@ void MapDatabasePostgreSQL::loadBlock(const v3s16 &pos, std::string *block) PQclear(results); } -bool MapDatabasePostgreSQL::deleteBlock(const v3s16 &pos) +bool MapDatabasePostgreSQL::deleteBlock(const v3BPOS &pos) { verifyDatabase(); @@ -300,7 +300,7 @@ bool MapDatabasePostgreSQL::deleteBlock(const v3s16 &pos) return true; } -void MapDatabasePostgreSQL::listAllLoadableBlocks(std::vector &dst) +void MapDatabasePostgreSQL::listAllLoadableBlocks(std::vector &dst) { verifyDatabase(); @@ -310,7 +310,7 @@ void MapDatabasePostgreSQL::listAllLoadableBlocks(std::vector &dst) int numrows = PQntuples(results); for (int row = 0; row < numrows; ++row) - dst.push_back(pg_to_v3s16(results, row, 0)); + dst.push_back(pg_to_v3BPOS(results, row, 0)); PQclear(results); } diff --git a/src/database/database-postgresql.h b/src/database/database-postgresql.h index 81b4a2b10a..83f565c5ed 100644 --- a/src/database/database-postgresql.h +++ b/src/database/database-postgresql.h @@ -56,9 +56,9 @@ class Database_PostgreSQL: public Database return (float) atof(PQgetvalue(res, row, col)); } - inline v3s16 pg_to_v3s16(PGresult *res, int row, int col) + inline v3BPOS pg_to_v3BPOS(PGresult *res, int row, int col) { - return v3s16( + return v3BPOS( pg_to_int(res, row, col), pg_to_int(res, row, col + 1), pg_to_int(res, row, col + 2) @@ -114,10 +114,10 @@ class MapDatabasePostgreSQL : private Database_PostgreSQL, public MapDatabase MapDatabasePostgreSQL(const std::string &connect_string); virtual ~MapDatabasePostgreSQL() = default; - bool saveBlock(const v3s16 &pos, const std::string &data); - void loadBlock(const v3s16 &pos, std::string *block); - bool deleteBlock(const v3s16 &pos); - void listAllLoadableBlocks(std::vector &dst); + bool saveBlock(const v3BPOS &pos, const std::string &data); + void loadBlock(const v3BPOS &pos, std::string *block); + bool deleteBlock(const v3BPOS &pos); + void listAllLoadableBlocks(std::vector &dst); void beginSave() { Database_PostgreSQL::beginSave(); } void endSave() { Database_PostgreSQL::endSave(); } diff --git a/src/database/database-redis.cpp b/src/database/database-redis.cpp index 5ffff67b7e..689da316e1 100644 --- a/src/database/database-redis.cpp +++ b/src/database/database-redis.cpp @@ -90,9 +90,9 @@ void Database_Redis::endSave() { freeReplyObject(reply); } -bool Database_Redis::saveBlock(const v3s16 &pos, const std::string &data) +bool Database_Redis::saveBlock(const v3BPOS &pos, const std::string &data) { - std::string tmp = i64tos(getBlockAsInteger(pos)); + std::string tmp = getBlockAsStringCompatible(pos); redisReply *reply = static_cast(redisCommand(ctx, "HSET %s %s %b", hash.c_str(), tmp.c_str(), data.c_str(), data.size())); @@ -114,9 +114,9 @@ bool Database_Redis::saveBlock(const v3s16 &pos, const std::string &data) return true; } -void Database_Redis::loadBlock(const v3s16 &pos, std::string *block) +void Database_Redis::loadBlock(const v3BPOS &pos, std::string *block) { - std::string tmp = i64tos(getBlockAsInteger(pos)); + std::string tmp = getBlockAsStringCompatible(pos); redisReply *reply = static_cast(redisCommand(ctx, "HGET %s %s", hash.c_str(), tmp.c_str())); @@ -154,9 +154,9 @@ void Database_Redis::loadBlock(const v3s16 &pos, std::string *block) "Redis command 'HGET %s %s' gave invalid reply.")); } -bool Database_Redis::deleteBlock(const v3s16 &pos) +bool Database_Redis::deleteBlock(const v3BPOS &pos) { - std::string tmp = i64tos(getBlockAsInteger(pos)); + std::string tmp = getBlockAsStringCompatible(pos); redisReply *reply = static_cast(redisCommand(ctx, "HDEL %s %s", hash.c_str(), tmp.c_str())); @@ -174,7 +174,7 @@ bool Database_Redis::deleteBlock(const v3s16 &pos) return true; } -void Database_Redis::listAllLoadableBlocks(std::vector &dst) +void Database_Redis::listAllLoadableBlocks(std::vector &dst) { redisReply *reply = static_cast(redisCommand(ctx, "HKEYS %s", hash.c_str())); if (!reply) { @@ -186,7 +186,7 @@ void Database_Redis::listAllLoadableBlocks(std::vector &dst) dst.reserve(reply->elements); for (size_t i = 0; i < reply->elements; i++) { assert(reply->element[i]->type == REDIS_REPLY_STRING); - dst.push_back(getIntegerAsBlock(stoi64(reply->element[i]->str))); + dst.push_back(getStringAsBlock(reply->element[i]->str)); } break; case REDIS_REPLY_ERROR: diff --git a/src/database/database-redis.h b/src/database/database-redis.h index 6bea563bc1..edd0fff86b 100644 --- a/src/database/database-redis.h +++ b/src/database/database-redis.h @@ -38,10 +38,10 @@ class Database_Redis : public MapDatabase void beginSave(); void endSave(); - bool saveBlock(const v3s16 &pos, const std::string &data); - void loadBlock(const v3s16 &pos, std::string *block); - bool deleteBlock(const v3s16 &pos); - void listAllLoadableBlocks(std::vector &dst); + bool saveBlock(const v3BPOS &pos, const std::string &data); + void loadBlock(const v3BPOS &pos, std::string *block); + bool deleteBlock(const v3BPOS &pos); + void listAllLoadableBlocks(std::vector &dst); private: redisContext *ctx = nullptr; diff --git a/src/database/database-sqlite3.cpp b/src/database/database-sqlite3.cpp index 898acc265d..a60f9ec390 100644 --- a/src/database/database-sqlite3.cpp +++ b/src/database/database-sqlite3.cpp @@ -239,13 +239,13 @@ void MapDatabaseSQLite3::initStatements() verbosestream << "ServerMap: SQLite3 database opened." << std::endl; } -inline void MapDatabaseSQLite3::bindPos(sqlite3_stmt *stmt, const v3s16 &pos, int index) +inline void MapDatabaseSQLite3::bindPos(sqlite3_stmt *stmt, const v3BPOS &pos, int index) { SQLOK(sqlite3_bind_int64(stmt, index, getBlockAsInteger(pos)), "Internal error: failed to bind query at " __FILE__ ":" TOSTRING(__LINE__)); } -bool MapDatabaseSQLite3::deleteBlock(const v3s16 &pos) +bool MapDatabaseSQLite3::deleteBlock(const v3BPOS &pos) { verifyDatabase(); @@ -261,7 +261,7 @@ bool MapDatabaseSQLite3::deleteBlock(const v3s16 &pos) return good; } -bool MapDatabaseSQLite3::saveBlock(const v3s16 &pos, const std::string &data) +bool MapDatabaseSQLite3::saveBlock(const v3BPOS &pos, const std::string &data) { verifyDatabase(); @@ -288,7 +288,7 @@ bool MapDatabaseSQLite3::saveBlock(const v3s16 &pos, const std::string &data) return true; } -void MapDatabaseSQLite3::loadBlock(const v3s16 &pos, std::string *block) +void MapDatabaseSQLite3::loadBlock(const v3BPOS &pos, std::string *block) { verifyDatabase(); @@ -312,7 +312,7 @@ void MapDatabaseSQLite3::loadBlock(const v3s16 &pos, std::string *block) sqlite3_reset(m_stmt_read); } -void MapDatabaseSQLite3::listAllLoadableBlocks(std::vector &dst) +void MapDatabaseSQLite3::listAllLoadableBlocks(std::vector &dst) { verifyDatabase(); diff --git a/src/database/database-sqlite3.h b/src/database/database-sqlite3.h index d7202a9186..cc93581c1c 100644 --- a/src/database/database-sqlite3.h +++ b/src/database/database-sqlite3.h @@ -146,10 +146,10 @@ class MapDatabaseSQLite3 : private Database_SQLite3, public MapDatabase MapDatabaseSQLite3(const std::string &savedir); virtual ~MapDatabaseSQLite3(); - bool saveBlock(const v3s16 &pos, const std::string &data); - void loadBlock(const v3s16 &pos, std::string *block); - bool deleteBlock(const v3s16 &pos); - void listAllLoadableBlocks(std::vector &dst); + bool saveBlock(const v3BPOS &pos, const std::string &data); + void loadBlock(const v3BPOS &pos, std::string *block); + bool deleteBlock(const v3BPOS &pos); + void listAllLoadableBlocks(std::vector &dst); void beginSave() { Database_SQLite3::beginSave(); } void endSave() { Database_SQLite3::endSave(); } @@ -158,7 +158,7 @@ class MapDatabaseSQLite3 : private Database_SQLite3, public MapDatabase virtual void initStatements(); private: - void bindPos(sqlite3_stmt *stmt, const v3s16 &pos, int index = 1); + void bindPos(sqlite3_stmt *stmt, const v3BPOS &pos, int index = 1); // Map sqlite3_stmt *m_stmt_read = nullptr; diff --git a/src/database/database.cpp b/src/database/database.cpp index 12e0e1a0f9..9c14494997 100644 --- a/src/database/database.cpp +++ b/src/database/database.cpp @@ -18,7 +18,11 @@ with this program; if not, write to the Free Software Foundation, Inc., */ #include "database.h" +#include "constants.h" #include "irrlichttypes.h" +#include +#include "util/string.h" + /**************** @@ -48,7 +52,7 @@ static inline s64 pythonmodulo(s64 i, s16 mod) } -s64 MapDatabase::getBlockAsInteger(const v3s16 &pos) +s64 MapDatabase::getBlockAsInteger(const v3BPOS &pos) { return (u64) pos.Z * 0x1000000 + (u64) pos.Y * 0x1000 + @@ -56,9 +60,9 @@ s64 MapDatabase::getBlockAsInteger(const v3s16 &pos) } -v3s16 MapDatabase::getIntegerAsBlock(s64 i) +v3BPOS MapDatabase::getIntegerAsBlock(s64 i) { - v3s16 pos; + v3BPOS pos; pos.X = unsigned_to_signed(pythonmodulo(i, 4096), 2048); i = (i - pos.X) / 4096; pos.Y = unsigned_to_signed(pythonmodulo(i, 4096), 2048); @@ -67,3 +71,49 @@ v3s16 MapDatabase::getIntegerAsBlock(s64 i) return pos; } +std::string MapDatabase::getBlockAsString(const v3BPOS &pos) const +{ + // 'a' is like version marker. In future other letters or words can be used. + std::ostringstream os; + os << "a" << pos.X << "," << pos.Y << "," << pos.Z; + return os.str().c_str(); +} + +std::string MapDatabase::getBlockAsStringCompatible(const v3BPOS &pos) const +{ +#if USE_POS32 + const BPOS max_limit_bp = 31000 / MAP_BLOCKSIZE; + if (pos.X < -max_limit_bp || + pos.X > max_limit_bp || + pos.Y < -max_limit_bp || + pos.Y > max_limit_bp || + pos.Z < -max_limit_bp || + pos.Z > max_limit_bp) + return getBlockAsString(pos); + return std::to_string(getBlockAsInteger(pos)); +#else + return getBlockAsString(pos); +#endif +} + +v3BPOS MapDatabase::getStringAsBlock(const std::string &i) const +{ +#if USE_POS32 + std::istringstream is(i); + v3BPOS pos; + char c; + if (i[0] == 'a') { + is >> c; // 'a' + is >> pos.X; + is >> c; // ',' + is >> pos.Y; + is >> c; // ',' + is >> pos.Z; + } else { // old format + return getIntegerAsBlock(stoi64(i)); + } + return pos; +#else + return getIntegerAsBlock(stoi64(i)); +#endif +} diff --git a/src/database/database.h b/src/database/database.h index b7d5519350..402d9fef9a 100644 --- a/src/database/database.h +++ b/src/database/database.h @@ -39,14 +39,18 @@ class MapDatabase : public Database public: virtual ~MapDatabase() = default; - virtual bool saveBlock(const v3s16 &pos, const std::string &data) = 0; - virtual void loadBlock(const v3s16 &pos, std::string *block) = 0; - virtual bool deleteBlock(const v3s16 &pos) = 0; + virtual bool saveBlock(const v3BPOS &pos, const std::string &data) = 0; + virtual void loadBlock(const v3BPOS &pos, std::string *block) = 0; + virtual bool deleteBlock(const v3BPOS &pos) = 0; - static s64 getBlockAsInteger(const v3s16 &pos); - static v3s16 getIntegerAsBlock(s64 i); + static s64 getBlockAsInteger(const v3BPOS &pos); + static v3BPOS getIntegerAsBlock(s64 i); - virtual void listAllLoadableBlocks(std::vector &dst) = 0; + std::string getBlockAsString(const v3BPOS &pos) const; + std::string getBlockAsStringCompatible(const v3BPOS &pos) const; + v3BPOS getStringAsBlock(const std::string &i) const; + + virtual void listAllLoadableBlocks(std::vector &dst) = 0; }; class PlayerSAO; diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp index d705552d69..2977a9d152 100644 --- a/src/defaultsettings.cpp +++ b/src/defaultsettings.cpp @@ -441,7 +441,7 @@ void set_default_settings() // Mapgen settings->setDefault("mg_name", "v7"); settings->setDefault("water_level", "1"); - settings->setDefault("mapgen_limit", "31000"); + settings->setDefault("mapgen_limit", std::to_string(MAX_MAP_GENERATION_LIMIT)); settings->setDefault("chunksize", "5"); settings->setDefault("fixed_map_seed", ""); settings->setDefault("max_block_generate_distance", "10"); diff --git a/src/emerge.cpp b/src/emerge.cpp index 619b1fa8e8..46c8481dd3 100644 --- a/src/emerge.cpp +++ b/src/emerge.cpp @@ -57,12 +57,12 @@ class EmergeThread : public Thread { void signal(); // Requires queue mutex held - bool pushBlock(const v3s16 &pos); + bool pushBlock(const v3BPOS &pos); void cancelPendingItems(); static void runCompletionCallbacks( - const v3s16 &pos, EmergeAction action, + const v3BPOS &pos, EmergeAction action, const EmergeCallbackList &callbacks); private: @@ -72,14 +72,14 @@ class EmergeThread : public Thread { Mapgen *m_mapgen; Event m_queue_event; - std::queue m_block_queue; + std::queue m_block_queue; - bool popBlockEmerge(v3s16 *pos, BlockEmergeData *bedata); + bool popBlockEmerge(v3BPOS *pos, BlockEmergeData *bedata); EmergeAction getBlockOrStartGen( - const v3s16 &pos, bool allow_gen, MapBlock **block, BlockMakeData *data); - MapBlock *finishGen(v3s16 pos, BlockMakeData *bmdata, - std::map *modified_blocks); + const v3BPOS &pos, bool allow_gen, MapBlock **block, BlockMakeData *data); + MapBlock *finishGen(v3BPOS pos, BlockMakeData *bmdata, + std::map *modified_blocks); friend class EmergeManager; }; @@ -244,7 +244,7 @@ void EmergeManager::initMapgens(MapgenParams *params) mgparams = params; - v3s16 csize = v3s16(1, 1, 1) * (params->chunksize * MAP_BLOCKSIZE); + v3POS csize = v3POS(1, 1, 1) * (params->chunksize * MAP_BLOCKSIZE); biomegen = biomemgr->createBiomeGen(BIOMEGEN_ORIGINAL, params->bparams, csize); for (u32 i = 0; i != m_threads.size(); i++) { @@ -311,7 +311,7 @@ bool EmergeManager::isRunning() bool EmergeManager::enqueueBlockEmerge( session_t peer_id, - v3s16 blockpos, + v3BPOS blockpos, bool allow_generate, bool ignore_queue_limits) { @@ -326,7 +326,7 @@ bool EmergeManager::enqueueBlockEmerge( bool EmergeManager::enqueueBlockEmergeEx( - v3s16 blockpos, + v3BPOS blockpos, session_t peer_id, u16 flags, EmergeCompletionCallback callback, @@ -355,7 +355,7 @@ bool EmergeManager::enqueueBlockEmergeEx( } -bool EmergeManager::isBlockInQueue(v3s16 pos) +bool EmergeManager::isBlockInQueue(v3BPOS pos) { MutexAutoLock queuelock(m_queue_mutex); return m_blocks_enqueued.find(pos) != m_blocks_enqueued.end(); @@ -368,17 +368,17 @@ bool EmergeManager::isBlockInQueue(v3s16 pos) // TODO(hmmmm): Move this to ServerMap -v3s16 EmergeManager::getContainingChunk(v3s16 blockpos, s16 chunksize) +v3BPOS EmergeManager::getContainingChunk(v3BPOS blockpos, s16 chunksize) { s16 coff = -chunksize / 2; - v3s16 chunk_offset(coff, coff, coff); + v3BPOS chunk_offset(coff, coff, coff); return getContainerPos(blockpos - chunk_offset, chunksize) * chunksize + chunk_offset; } -int EmergeManager::getSpawnLevelAtPoint(v2s16 p) +int EmergeManager::getSpawnLevelAtPoint(v2POS p) { if (m_mapgens.empty() || !m_mapgens[0]) { errorstream << "EmergeManager: getSpawnLevelAtPoint() called" @@ -391,14 +391,14 @@ int EmergeManager::getSpawnLevelAtPoint(v2s16 p) // TODO(hmmmm): Move this to ServerMap -bool EmergeManager::isBlockUnderground(v3s16 blockpos) +bool EmergeManager::isBlockUnderground(v3BPOS blockpos) { // Use a simple heuristic return blockpos.Y * (MAP_BLOCKSIZE + 1) <= mgparams->water_level; } bool EmergeManager::pushBlockEmergeData( - v3s16 pos, + v3BPOS pos, u16 peer_requested, u16 flags, EmergeCompletionCallback callback, @@ -423,7 +423,7 @@ bool EmergeManager::pushBlockEmergeData( } } - std::pair::iterator, bool> findres; + std::pair::iterator, bool> findres; findres = m_blocks_enqueued.insert(std::make_pair(pos, BlockEmergeData())); BlockEmergeData &bedata = findres.first->second; @@ -445,7 +445,7 @@ bool EmergeManager::pushBlockEmergeData( } -bool EmergeManager::popBlockEmergeData(v3s16 pos, BlockEmergeData *bedata) +bool EmergeManager::popBlockEmergeData(v3BPOS pos, BlockEmergeData *bedata) { auto it = m_blocks_enqueued.find(pos); if (it == m_blocks_enqueued.end()) @@ -511,7 +511,7 @@ void EmergeThread::signal() } -bool EmergeThread::pushBlock(const v3s16 &pos) +bool EmergeThread::pushBlock(const v3BPOS &pos) { m_block_queue.push(pos); return true; @@ -524,7 +524,7 @@ void EmergeThread::cancelPendingItems() while (!m_block_queue.empty()) { BlockEmergeData bedata; - v3s16 pos; + v3BPOS pos; pos = m_block_queue.front(); m_block_queue.pop(); @@ -536,7 +536,7 @@ void EmergeThread::cancelPendingItems() } -void EmergeThread::runCompletionCallbacks(const v3s16 &pos, EmergeAction action, +void EmergeThread::runCompletionCallbacks(const v3BPOS &pos, EmergeAction action, const EmergeCallbackList &callbacks) { for (size_t i = 0; i != callbacks.size(); i++) { @@ -551,7 +551,7 @@ void EmergeThread::runCompletionCallbacks(const v3s16 &pos, EmergeAction action, } -bool EmergeThread::popBlockEmerge(v3s16 *pos, BlockEmergeData *bedata) +bool EmergeThread::popBlockEmerge(v3BPOS *pos, BlockEmergeData *bedata) { MutexAutoLock queuelock(m_emerge->m_queue_mutex); @@ -568,7 +568,7 @@ bool EmergeThread::popBlockEmerge(v3s16 *pos, BlockEmergeData *bedata) EmergeAction EmergeThread::getBlockOrStartGen( - const v3s16 &pos, bool allow_gen, MapBlock **block, BlockMakeData *bmdata) + const v3BPOS &pos, bool allow_gen, MapBlock **block, BlockMakeData *bmdata) { MutexAutoLock envlock(m_server->m_env_mutex); @@ -593,8 +593,8 @@ EmergeAction EmergeThread::getBlockOrStartGen( } -MapBlock *EmergeThread::finishGen(v3s16 pos, BlockMakeData *bmdata, - std::map *modified_blocks) +MapBlock *EmergeThread::finishGen(v3BPOS pos, BlockMakeData *bmdata, + std::map *modified_blocks) { MutexAutoLock envlock(m_server->m_env_mutex); ScopeProfiler sp(g_profiler, @@ -613,9 +613,9 @@ MapBlock *EmergeThread::finishGen(v3s16 pos, BlockMakeData *bmdata, return NULL; } - v3s16 minp = bmdata->blockpos_min * MAP_BLOCKSIZE; - v3s16 maxp = bmdata->blockpos_max * MAP_BLOCKSIZE + - v3s16(1,1,1) * (MAP_BLOCKSIZE - 1); + v3POS minp = bmdata->blockpos_min * MAP_BLOCKSIZE; + v3POS maxp = bmdata->blockpos_max * MAP_BLOCKSIZE + + v3POS(1,1,1) * (MAP_BLOCKSIZE - 1); // Ignore map edit events, they will not need to be sent // to anybody because the block hasn't been sent to anybody @@ -655,8 +655,8 @@ void *EmergeThread::run() { BEGIN_DEBUG_EXCEPTION_HANDLER - v3s16 pos; - std::map modified_blocks; + v3BPOS pos; + std::map modified_blocks; m_map = &m_server->m_env->getServerMap(); m_emerge = m_server->m_emerge; diff --git a/src/emerge.h b/src/emerge.h index 61e7bda63e..0d74a954a4 100644 --- a/src/emerge.h +++ b/src/emerge.h @@ -50,9 +50,9 @@ class ModApiMapgen; struct BlockMakeData { MMVManip *vmanip = nullptr; u64 seed = 0; - v3s16 blockpos_min; - v3s16 blockpos_max; - UniqueQueue transforming_liquid; + v3BPOS blockpos_min; + v3BPOS blockpos_max; + UniqueQueue transforming_liquid; const NodeDefManager *nodedef = nullptr; BlockMakeData() = default; @@ -71,7 +71,7 @@ enum EmergeAction { // Callback typedef void (*EmergeCompletionCallback)( - v3s16 blockpos, EmergeAction action, void *param); + v3BPOS blockpos, EmergeAction action, void *param); typedef std::vector< std::pair< @@ -163,26 +163,26 @@ class EmergeManager { bool enqueueBlockEmerge( session_t peer_id, - v3s16 blockpos, + v3BPOS blockpos, bool allow_generate, bool ignore_queue_limits=false); bool enqueueBlockEmergeEx( - v3s16 blockpos, + v3BPOS blockpos, session_t peer_id, u16 flags, EmergeCompletionCallback callback, void *callback_param); - bool isBlockInQueue(v3s16 pos); + bool isBlockInQueue(v3BPOS pos); Mapgen *getCurrentMapgen(); // Mapgen helpers methods - int getSpawnLevelAtPoint(v2s16 p); - bool isBlockUnderground(v3s16 blockpos); + int getSpawnLevelAtPoint(v2POS p); + bool isBlockUnderground(v3BPOS blockpos); - static v3s16 getContainingChunk(v3s16 blockpos, s16 chunksize); + static v3BPOS getContainingChunk(v3BPOS blockpos, s16 chunksize); private: std::vector m_mapgens; @@ -190,7 +190,7 @@ class EmergeManager { bool m_threads_active = false; std::mutex m_queue_mutex; - std::map m_blocks_enqueued; + std::map m_blocks_enqueued; std::unordered_map m_peer_queue_count; u32 m_qlimit_total; @@ -209,14 +209,14 @@ class EmergeManager { EmergeThread *getOptimalThread(); bool pushBlockEmergeData( - v3s16 pos, + v3BPOS pos, u16 peer_requested, u16 flags, EmergeCompletionCallback callback, void *callback_param, bool *entry_already_exists); - bool popBlockEmergeData(v3s16 pos, BlockEmergeData *bedata); + bool popBlockEmergeData(v3BPOS pos, BlockEmergeData *bedata); friend class EmergeThread; }; diff --git a/src/environment.cpp b/src/environment.cpp index 06f2b8bf9d..4277a48136 100644 --- a/src/environment.cpp +++ b/src/environment.cpp @@ -83,7 +83,7 @@ float Environment::getTimeOfDayF() return m_time_of_day_f; } -bool Environment::line_of_sight(v3f pos1, v3f pos2, v3s16 *p) +bool Environment::line_of_sight(v3f pos1, v3f pos2, v3POS *p) { // Iterate trough nodes on the line voxalgo::VoxelLineIterator iterator(pos1 / BS, (pos2 - pos1) / BS); @@ -125,7 +125,7 @@ void Environment::continueRaycast(RaycastState *state, PointedThing *result) } } // Set search range - core::aabbox3d maximal_exceed = nodedef->getSelectionBoxIntUnion(); + core::aabbox3d maximal_exceed = nodedef->getSelectionBoxIntUnion(); state->m_search_range.MinEdge = -maximal_exceed.MaxEdge; state->m_search_range.MaxEdge = -maximal_exceed.MinEdge; // Setting is done @@ -145,7 +145,7 @@ void Environment::continueRaycast(RaycastState *state, PointedThing *result) // first nodebox the shootline meets. v3f found_boxcenter(0, 0, 0); // The untested nodes are in this range. - core::aabbox3d new_nodes; + core::aabbox3d new_nodes; while (state->m_iterator.m_current_index <= lastIndex) { // Test the nodes around the current node in search_range. new_nodes = state->m_search_range; @@ -153,7 +153,7 @@ void Environment::continueRaycast(RaycastState *state, PointedThing *result) new_nodes.MaxEdge += state->m_iterator.m_current_node_pos; // Only check new nodes - v3s16 delta = state->m_iterator.m_current_node_pos + v3POS delta = state->m_iterator.m_current_node_pos - state->m_previous_node; if (delta.X > 0) { new_nodes.MinEdge.X = new_nodes.MaxEdge.X; @@ -170,11 +170,11 @@ void Environment::continueRaycast(RaycastState *state, PointedThing *result) } // For each untested node - for (s16 x = new_nodes.MinEdge.X; x <= new_nodes.MaxEdge.X; x++) - for (s16 y = new_nodes.MinEdge.Y; y <= new_nodes.MaxEdge.Y; y++) - for (s16 z = new_nodes.MinEdge.Z; z <= new_nodes.MaxEdge.Z; z++) { + for (POS x = new_nodes.MinEdge.X; x <= new_nodes.MaxEdge.X; x++) + for (POS y = new_nodes.MinEdge.Y; y <= new_nodes.MaxEdge.Y; y++) + for (POS z = new_nodes.MinEdge.Z; z <= new_nodes.MaxEdge.Z; z++) { MapNode n; - v3s16 np(x, y, z); + v3POS np(x, y, z); bool is_valid_position; n = map.getNode(np, &is_valid_position); @@ -203,7 +203,7 @@ void Environment::continueRaycast(RaycastState *state, PointedThing *result) box.MaxEdge += npf; v3f intersection_point; - v3s16 intersection_normal; + v3POS intersection_normal; if (!boxLineCollision(box, state->m_shootline.start, state->m_shootline.getVector(), &intersection_point, &intersection_normal)) { diff --git a/src/environment.h b/src/environment.h index b4884fdb38..8f4d9bd79a 100644 --- a/src/environment.h +++ b/src/environment.h @@ -84,7 +84,7 @@ class Environment * \param p output, position of the first non-air node * the line intersects */ - bool line_of_sight(v3f pos1, v3f pos2, v3s16 *p = nullptr); + bool line_of_sight(v3f pos1, v3f pos2, v3POS *p = nullptr); /*! * Gets the objects pointed by the shootline as diff --git a/src/face_position_cache.cpp b/src/face_position_cache.cpp index 7a8f235fa4..dfa5be027e 100644 --- a/src/face_position_cache.cpp +++ b/src/face_position_cache.cpp @@ -21,24 +21,24 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "threading/mutex_auto_lock.h" -std::unordered_map> FacePositionCache::cache; +std::unordered_map> FacePositionCache::cache; std::mutex FacePositionCache::cache_mutex; // Calculate the borders of a "d-radius" cube -const std::vector &FacePositionCache::getFacePositions(u16 d) +const std::vector &FacePositionCache::getFacePositions(u16 d) { MutexAutoLock lock(cache_mutex); - std::unordered_map>::const_iterator it = cache.find(d); + std::unordered_map>::const_iterator it = cache.find(d); if (it != cache.end()) return it->second; return generateFacePosition(d); } -const std::vector &FacePositionCache::generateFacePosition(u16 d) +const std::vector &FacePositionCache::generateFacePosition(u16 d) { - cache[d] = std::vector(); - std::vector &c = cache[d]; + cache[d] = std::vector(); + std::vector &c = cache[d]; if (d == 0) { c.emplace_back(0,0,0); return c; diff --git a/src/face_position_cache.h b/src/face_position_cache.h index 36cb06484f..816e566df5 100644 --- a/src/face_position_cache.h +++ b/src/face_position_cache.h @@ -32,10 +32,10 @@ with this program; if not, write to the Free Software Foundation, Inc., */ class FacePositionCache { public: - static const std::vector &getFacePositions(u16 d); + static const std::vector &getFacePositions(u16 d); private: - static const std::vector &generateFacePosition(u16 d); - static std::unordered_map> cache; + static const std::vector &generateFacePosition(u16 d); + static std::unordered_map> cache; static std::mutex cache_mutex; }; diff --git a/src/gui/guiHyperText.cpp b/src/gui/guiHyperText.cpp index ccfdcb81d4..d135d0ceb8 100644 --- a/src/gui/guiHyperText.cpp +++ b/src/gui/guiHyperText.cpp @@ -524,22 +524,22 @@ u32 ParsedText::parseTag(const wchar_t *text, u32 cursor) std::string str = attrs["angle"]; std::vector parts = split(str, ','); if (parts.size() == 3) { - m_element->angle = v3s16( + m_element->angle = v3POS( rangelim(stoi(parts[0]), -180, 180), rangelim(stoi(parts[1]), -180, 180), rangelim(stoi(parts[2]), -180, 180)); - m_element->rotation = v3s16(0, 0, 0); + m_element->rotation = v3POS(0, 0, 0); } } if (attrs.count("rotate")) { if (attrs["rotate"] == "yes") { - m_element->rotation = v3s16(0, 100, 0); + m_element->rotation = v3POS(0, 100, 0); } else { std::string str = attrs["rotate"]; std::vector parts = split(str, ','); if (parts.size() == 3) { - m_element->rotation = v3s16 ( + m_element->rotation = v3POS ( rangelim(stoi(parts[0]), -1000, 1000), rangelim(stoi(parts[1]), -1000, 1000), rangelim(stoi(parts[2]), -1000, 1000)); diff --git a/src/gui/guiHyperText.h b/src/gui/guiHyperText.h index 5b936262e8..184769a1cf 100644 --- a/src/gui/guiHyperText.h +++ b/src/gui/guiHyperText.h @@ -106,8 +106,8 @@ class ParsedText // img & item specific attributes std::string name; - v3s16 angle{0, 0, 0}; - v3s16 rotation{0, 0, 0}; + v3POS angle{0, 0, 0}; + v3POS rotation{0, 0, 0}; s32 margin = 10; diff --git a/src/inventorymanager.h b/src/inventorymanager.h index 4ad5d3f49a..9c9f990a5e 100644 --- a/src/inventorymanager.h +++ b/src/inventorymanager.h @@ -35,7 +35,7 @@ struct InventoryLocation } type; std::string name; // PLAYER, DETACHED - v3s16 p; // NODEMETA + v3POS p; // NODEMETA InventoryLocation() { @@ -54,7 +54,7 @@ struct InventoryLocation type = PLAYER; name = name_; } - void setNodeMeta(const v3s16 &p_) + void setNodeMeta(const v3POS &p_) { type = NODEMETA; p = p_; diff --git a/src/irr_v2d.h b/src/irr_v2d.h index a9065766be..11666bee2d 100644 --- a/src/irr_v2d.h +++ b/src/irr_v2d.h @@ -28,3 +28,6 @@ typedef core::vector2d v2s16; typedef core::vector2d v2s32; typedef core::vector2d v2u32; typedef core::vector2d v2f32; + +using v2POS = core::vector2d; +using v2BPOS = core::vector2d; \ No newline at end of file diff --git a/src/irr_v3d.h b/src/irr_v3d.h index 3e95c7913c..977ace7b0c 100644 --- a/src/irr_v3d.h +++ b/src/irr_v3d.h @@ -28,3 +28,6 @@ typedef core::vector3d v3d; typedef core::vector3d v3s16; typedef core::vector3d v3u16; typedef core::vector3d v3s32; + +using v3POS = core::vector3d; +using v3BPOS = core::vector3d; diff --git a/src/irrlichttypes.h b/src/irrlichttypes.h index 93c2d105b9..47e51491ed 100644 --- a/src/irrlichttypes.h +++ b/src/irrlichttypes.h @@ -26,6 +26,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include +#include "config.h" using namespace irr; @@ -60,3 +61,16 @@ namespace core { #define U16_MAX 0xFFFF #define U32_MAX 0xFFFFFFFF #define U64_MAX 0xFFFFFFFFFFFFFFFF + +#if USE_POS32 + +// Node position +using POS = irr::s32; + +// Block position. In future can be renamed to POS +using BPOS = irr::s32; + +#else +using POS = irr::s16; +using BPOS = irr::s16; +#endif diff --git a/src/main.cpp b/src/main.cpp index 1044b327a5..e0de988d44 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1003,10 +1003,10 @@ static bool migrate_map_database(const GameParams &game_params, const Settings & time_t last_update_time = 0; bool &kill = *porting::signal_handler_killstatus(); - std::vector blocks; + std::vector blocks; old_db->listAllLoadableBlocks(blocks); new_db->beginSave(); - for (std::vector::const_iterator it = blocks.begin(); it != blocks.end(); ++it) { + for (std::vector::const_iterator it = blocks.begin(); it != blocks.end(); ++it) { if (kill) return false; std::string data; @@ -1058,7 +1058,7 @@ static bool recompress_map_database(const GameParams &game_params, const Setting const u8 serialize_as_ver = SER_FMT_VER_HIGHEST_WRITE; // This is ok because the server doesn't actually run - std::vector blocks; + std::vector blocks; db->listAllLoadableBlocks(blocks); db->beginSave(); std::istringstream iss(std::ios_base::binary); @@ -1076,7 +1076,7 @@ static bool recompress_map_database(const GameParams &game_params, const Setting iss.str(data); iss.clear(); - MapBlock mb(nullptr, v3s16(0,0,0), &server); + MapBlock mb(nullptr, v3POS(0,0,0), &server); u8 ver = readU8(iss); mb.deSerialize(iss, ver, true); diff --git a/src/map.cpp b/src/map.cpp index 77031e17df..4f49293a78 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -18,6 +18,8 @@ with this program; if not, write to the Free Software Foundation, Inc., */ #include "map.h" +#include "irr_v3d.h" +#include "irrlichttypes.h" #include "mapsector.h" #include "mapblock.h" #include "filesys.h" @@ -95,14 +97,14 @@ void Map::dispatchEvent(const MapEditEvent &event) } } -MapSector * Map::getSectorNoGenerateNoLock(v2s16 p) +MapSector * Map::getSectorNoGenerateNoLock(v2BPOS p) { if(m_sector_cache != NULL && p == m_sector_cache_p){ MapSector * sector = m_sector_cache; return sector; } - std::map::iterator n = m_sectors.find(p); + std::map::iterator n = m_sectors.find(p); if (n == m_sectors.end()) return NULL; @@ -116,14 +118,14 @@ MapSector * Map::getSectorNoGenerateNoLock(v2s16 p) return sector; } -MapSector * Map::getSectorNoGenerate(v2s16 p) +MapSector * Map::getSectorNoGenerate(v2BPOS p) { return getSectorNoGenerateNoLock(p); } -MapBlock * Map::getBlockNoCreateNoEx(v3s16 p3d) +MapBlock * Map::getBlockNoCreateNoEx(v3BPOS p3d) { - v2s16 p2d(p3d.X, p3d.Z); + v2BPOS p2d(p3d.X, p3d.Z); MapSector * sector = getSectorNoGenerate(p2d); if(sector == NULL) return NULL; @@ -131,7 +133,7 @@ MapBlock * Map::getBlockNoCreateNoEx(v3s16 p3d) return block; } -MapBlock * Map::getBlockNoCreate(v3s16 p3d) +MapBlock * Map::getBlockNoCreate(v3BPOS p3d) { MapBlock *block = getBlockNoCreateNoEx(p3d); if(block == NULL) @@ -139,17 +141,17 @@ MapBlock * Map::getBlockNoCreate(v3s16 p3d) return block; } -bool Map::isValidPosition(v3s16 p) +bool Map::isValidPosition(v3POS p) { - v3s16 blockpos = getNodeBlockPos(p); + v3BPOS blockpos = getNodeBlockPos(p); MapBlock *block = getBlockNoCreateNoEx(blockpos); return (block != NULL); } // Returns a CONTENT_IGNORE node if not found -MapNode Map::getNode(v3s16 p, bool *is_valid_position) +MapNode Map::getNode(v3POS p, bool *is_valid_position) { - v3s16 blockpos = getNodeBlockPos(p); + v3BPOS blockpos = getNodeBlockPos(p); MapBlock *block = getBlockNoCreateNoEx(blockpos); if (block == NULL) { if (is_valid_position != NULL) @@ -157,7 +159,7 @@ MapNode Map::getNode(v3s16 p, bool *is_valid_position) return {CONTENT_IGNORE}; } - v3s16 relpos = p - blockpos*MAP_BLOCKSIZE; + v3POS relpos = p - blockpos*MAP_BLOCKSIZE; bool is_valid_p; MapNode node = block->getNodeNoCheck(relpos, &is_valid_p); if (is_valid_position != NULL) @@ -166,11 +168,11 @@ MapNode Map::getNode(v3s16 p, bool *is_valid_position) } // throws InvalidPositionException if not found -void Map::setNode(v3s16 p, MapNode & n) +void Map::setNode(v3POS p, MapNode & n) { - v3s16 blockpos = getNodeBlockPos(p); + v3BPOS blockpos = getNodeBlockPos(p); MapBlock *block = getBlockNoCreate(blockpos); - v3s16 relpos = p - blockpos*MAP_BLOCKSIZE; + v3POS relpos = p - blockpos*MAP_BLOCKSIZE; // Never allow placing CONTENT_IGNORE, it causes problems if(n.getContent() == CONTENT_IGNORE){ bool temp_bool; @@ -183,8 +185,8 @@ void Map::setNode(v3s16 p, MapNode & n) block->setNodeNoCheck(relpos, n); } -void Map::addNodeAndUpdate(v3s16 p, MapNode n, - std::map &modified_blocks, +void Map::addNodeAndUpdate(v3POS p, MapNode n, + std::map &modified_blocks, bool remove_metadata) { // Collect old node for rollback @@ -205,7 +207,7 @@ void Map::addNodeAndUpdate(v3s16 p, MapNode n, setNode(p, n); // Update lighting - std::vector > oldnodes; + std::vector > oldnodes; oldnodes.emplace_back(p, oldnode); voxalgo::update_lighting_nodes(this, oldnodes, modified_blocks); @@ -227,8 +229,8 @@ void Map::addNodeAndUpdate(v3s16 p, MapNode n, (it's vital for the node itself to get updated last, if it was removed.) */ - for (const v3s16 &dir : g_7dirs) { - v3s16 p2 = p + dir; + for (const v3POS &dir : g_7dirs) { + v3POS p2 = p + dir; bool is_valid_position; MapNode n2 = getNode(p2, &is_valid_position); @@ -239,13 +241,13 @@ void Map::addNodeAndUpdate(v3s16 p, MapNode n, } } -void Map::removeNodeAndUpdate(v3s16 p, - std::map &modified_blocks) +void Map::removeNodeAndUpdate(v3POS p, + std::map &modified_blocks) { addNodeAndUpdate(p, MapNode(CONTENT_AIR), modified_blocks, true); } -bool Map::addNodeWithEvent(v3s16 p, MapNode n, bool remove_metadata) +bool Map::addNodeWithEvent(v3POS p, MapNode n, bool remove_metadata) { MapEditEvent event; event.type = remove_metadata ? MEET_ADDNODE : MEET_SWAPNODE; @@ -254,7 +256,7 @@ bool Map::addNodeWithEvent(v3s16 p, MapNode n, bool remove_metadata) bool succeeded = true; try{ - std::map modified_blocks; + std::map modified_blocks; addNodeAndUpdate(p, n, modified_blocks, remove_metadata); // Copy modified_blocks to event @@ -271,7 +273,7 @@ bool Map::addNodeWithEvent(v3s16 p, MapNode n, bool remove_metadata) return succeeded; } -bool Map::removeNodeWithEvent(v3s16 p) +bool Map::removeNodeWithEvent(v3POS p) { MapEditEvent event; event.type = MEET_REMOVENODE; @@ -279,7 +281,7 @@ bool Map::removeNodeWithEvent(v3s16 p) bool succeeded = true; try{ - std::map modified_blocks; + std::map modified_blocks; removeNodeAndUpdate(p, modified_blocks); // Copy modified_blocks to event @@ -315,14 +317,14 @@ struct TimeOrderedMapBlock { Updates usage timers */ void Map::timerUpdate(float dtime, float unload_timeout, u32 max_loaded_blocks, - std::vector *unloaded_blocks) + std::vector *unloaded_blocks) { bool save_before_unloading = (mapType() == MAPTYPE_SERVER); // Profile modified reasons Profiler modprofiler; - std::vector sector_deletion_queue; + std::vector sector_deletion_queue; u32 deleted_blocks_count = 0; u32 saved_blocks_count = 0; u32 block_count_all = 0; @@ -344,7 +346,7 @@ void Map::timerUpdate(float dtime, float unload_timeout, u32 max_loaded_blocks, if (block->refGet() == 0 && block->getUsageTimer() > unload_timeout) { - v3s16 p = block->getPos(); + v3BPOS p = block->getPos(); // Save if modified if (block->getModified() != MOD_STATE_CLEAN @@ -397,7 +399,7 @@ void Map::timerUpdate(float dtime, float unload_timeout, u32 max_loaded_blocks, if (block->refGet() != 0) continue; - v3s16 p = block->getPos(); + v3BPOS p = block->getPos(); // Save if modified if (block->getModified() != MOD_STATE_CLEAN && save_before_unloading) { @@ -445,14 +447,14 @@ void Map::timerUpdate(float dtime, float unload_timeout, u32 max_loaded_blocks, } } -void Map::unloadUnreferencedBlocks(std::vector *unloaded_blocks) +void Map::unloadUnreferencedBlocks(std::vector *unloaded_blocks) { timerUpdate(0.0, -1.0, 0, unloaded_blocks); } -void Map::deleteSectors(std::vector §orList) +void Map::deleteSectors(std::vector §orList) { - for (v2s16 j : sectorList) { + for (v2BPOS j : sectorList) { MapSector *sector = m_sectors[j]; // If sector is in sector cache, remove it from there if(m_sector_cache == sector) @@ -470,14 +472,14 @@ void Map::PrintInfo(std::ostream &out) #define WATER_DROP_BOOST 4 -const static v3s16 liquid_6dirs[6] = { +const static v3POS liquid_6dirs[6] = { // order: upper before same level before lower - v3s16( 0, 1, 0), - v3s16( 0, 0, 1), - v3s16( 1, 0, 0), - v3s16( 0, 0,-1), - v3s16(-1, 0, 0), - v3s16( 0,-1, 0) + v3POS( 0, 1, 0), + v3POS( 0, 0, 1), + v3POS( 1, 0, 0), + v3POS( 0, 0,-1), + v3POS(-1, 0, 0), + v3POS( 0,-1, 0) }; enum NeighborType : u8 { @@ -489,24 +491,24 @@ enum NeighborType : u8 { struct NodeNeighbor { MapNode n; NeighborType t; - v3s16 p; + v3POS p; NodeNeighbor() : n(CONTENT_AIR), t(NEIGHBOR_SAME_LEVEL) { } - NodeNeighbor(const MapNode &node, NeighborType n_type, const v3s16 &pos) + NodeNeighbor(const MapNode &node, NeighborType n_type, const v3POS &pos) : n(node), t(n_type), p(pos) { } }; -void Map::transforming_liquid_add(v3s16 p) { +void Map::transforming_liquid_add(v3POS p) { m_transforming_liquid.push_back(p); } -void Map::transformLiquids(std::map &modified_blocks, +void Map::transformLiquids(std::map &modified_blocks, ServerEnvironment *env) { u32 loopcount = 0; @@ -516,9 +518,9 @@ void Map::transformLiquids(std::map &modified_blocks, infostream<<"transformLiquids(): initial_size="< must_reflow; + std::deque must_reflow; - std::vector > changed_nodes; + std::vector > changed_nodes; u32 liquid_loop_max = g_settings->getS32("liquid_loop_max"); u32 loop_max = liquid_loop_max; @@ -533,7 +535,7 @@ void Map::transformLiquids(std::map &modified_blocks, /* Get a queued transforming liquid node */ - v3s16 p0 = m_transforming_liquid.front(); + v3POS p0 = m_transforming_liquid.front(); m_transforming_liquid.pop_front(); MapNode n0 = getNode(p0); @@ -594,7 +596,7 @@ void Map::transformLiquids(std::map &modified_blocks, default: break; } - v3s16 npos = p0 + liquid_6dirs[i]; + v3POS npos = p0 + liquid_6dirs[i]; NodeNeighbor nb(getNode(npos), nt, npos); const ContentFeatures &cfnb = m_nodedef->get(nb.n); switch (m_nodedef->get(nb.n.getContent()).liquid_type) { @@ -788,7 +790,7 @@ void Map::transformLiquids(std::map &modified_blocks, setNode(p0, n0); } - v3s16 blockpos = getNodeBlockPos(p0); + v3BPOS blockpos = getNodeBlockPos(p0); MapBlock *block = getBlockNoCreateNoEx(blockpos); if (block != NULL) { modified_blocks[blockpos] = block; @@ -873,20 +875,20 @@ void Map::transformLiquids(std::map &modified_blocks, } } -std::vector Map::findNodesWithMetadata(v3s16 p1, v3s16 p2) +std::vector Map::findNodesWithMetadata(v3POS p1, v3POS p2) { - std::vector positions_with_meta; + std::vector positions_with_meta; sortBoxVerticies(p1, p2); - v3s16 bpmin = getNodeBlockPos(p1); - v3s16 bpmax = getNodeBlockPos(p2); + v3BPOS bpmin = getNodeBlockPos(p1); + v3BPOS bpmax = getNodeBlockPos(p2); VoxelArea area(p1, p2); - for (s16 z = bpmin.Z; z <= bpmax.Z; z++) - for (s16 y = bpmin.Y; y <= bpmax.Y; y++) - for (s16 x = bpmin.X; x <= bpmax.X; x++) { - v3s16 blockpos(x, y, z); + for (BPOS z = bpmin.Z; z <= bpmax.Z; z++) + for (BPOS y = bpmin.Y; y <= bpmax.Y; y++) + for (BPOS x = bpmin.X; x <= bpmax.X; x++) { + v3BPOS blockpos(x, y, z); MapBlock *block = getBlockNoCreateNoEx(blockpos); if (!block) { @@ -900,10 +902,10 @@ std::vector Map::findNodesWithMetadata(v3s16 p1, v3s16 p2) continue; } - v3s16 p_base = blockpos * MAP_BLOCKSIZE; - std::vector keys = block->m_node_metadata.getAllKeys(); + v3POS p_base = blockpos * MAP_BLOCKSIZE; + std::vector keys = block->m_node_metadata.getAllKeys(); for (size_t i = 0; i != keys.size(); i++) { - v3s16 p(keys[i] + p_base); + v3POS p(keys[i] + p_base); if (!area.contains(p)) continue; @@ -914,10 +916,10 @@ std::vector Map::findNodesWithMetadata(v3s16 p1, v3s16 p2) return positions_with_meta; } -NodeMetadata *Map::getNodeMetadata(v3s16 p) +NodeMetadata *Map::getNodeMetadata(v3POS p) { - v3s16 blockpos = getNodeBlockPos(p); - v3s16 p_rel = p - blockpos*MAP_BLOCKSIZE; + v3BPOS blockpos = getNodeBlockPos(p); + v3POS p_rel = p - blockpos*MAP_BLOCKSIZE; MapBlock *block = getBlockNoCreateNoEx(blockpos); if(!block){ infostream<<"Map::getNodeMetadata(): Need to emerge " @@ -933,10 +935,10 @@ NodeMetadata *Map::getNodeMetadata(v3s16 p) return meta; } -bool Map::setNodeMetadata(v3s16 p, NodeMetadata *meta) +bool Map::setNodeMetadata(v3POS p, NodeMetadata *meta) { - v3s16 blockpos = getNodeBlockPos(p); - v3s16 p_rel = p - blockpos*MAP_BLOCKSIZE; + v3BPOS blockpos = getNodeBlockPos(p); + v3POS p_rel = p - blockpos*MAP_BLOCKSIZE; MapBlock *block = getBlockNoCreateNoEx(blockpos); if(!block){ infostream<<"Map::setNodeMetadata(): Need to emerge " @@ -952,10 +954,10 @@ bool Map::setNodeMetadata(v3s16 p, NodeMetadata *meta) return true; } -void Map::removeNodeMetadata(v3s16 p) +void Map::removeNodeMetadata(v3POS p) { - v3s16 blockpos = getNodeBlockPos(p); - v3s16 p_rel = p - blockpos*MAP_BLOCKSIZE; + v3BPOS blockpos = getNodeBlockPos(p); + v3POS p_rel = p - blockpos*MAP_BLOCKSIZE; MapBlock *block = getBlockNoCreateNoEx(blockpos); if(block == NULL) { @@ -966,10 +968,10 @@ void Map::removeNodeMetadata(v3s16 p) block->m_node_metadata.remove(p_rel); } -NodeTimer Map::getNodeTimer(v3s16 p) +NodeTimer Map::getNodeTimer(v3POS p) { - v3s16 blockpos = getNodeBlockPos(p); - v3s16 p_rel = p - blockpos*MAP_BLOCKSIZE; + v3BPOS blockpos = getNodeBlockPos(p); + v3POS p_rel = p - blockpos*MAP_BLOCKSIZE; MapBlock *block = getBlockNoCreateNoEx(blockpos); if(!block){ infostream<<"Map::getNodeTimer(): Need to emerge " @@ -988,9 +990,9 @@ NodeTimer Map::getNodeTimer(v3s16 p) void Map::setNodeTimer(const NodeTimer &t) { - v3s16 p = t.position; - v3s16 blockpos = getNodeBlockPos(p); - v3s16 p_rel = p - blockpos*MAP_BLOCKSIZE; + v3POS p = t.position; + v3BPOS blockpos = getNodeBlockPos(p); + v3POS p_rel = p - blockpos*MAP_BLOCKSIZE; MapBlock *block = getBlockNoCreateNoEx(blockpos); if(!block){ infostream<<"Map::setNodeTimer(): Need to emerge " @@ -1006,10 +1008,10 @@ void Map::setNodeTimer(const NodeTimer &t) block->m_node_timers.set(nt); } -void Map::removeNodeTimer(v3s16 p) +void Map::removeNodeTimer(v3POS p) { - v3s16 blockpos = getNodeBlockPos(p); - v3s16 p_rel = p - blockpos*MAP_BLOCKSIZE; + v3BPOS blockpos = getNodeBlockPos(p); + v3POS p_rel = p - blockpos*MAP_BLOCKSIZE; MapBlock *block = getBlockNoCreateNoEx(blockpos); if(block == NULL) { @@ -1020,8 +1022,8 @@ void Map::removeNodeTimer(v3s16 p) block->m_node_timers.remove(p_rel); } -bool Map::determineAdditionalOcclusionCheck(const v3s16 &pos_camera, - const core::aabbox3d &block_bounds, v3s16 &check) +bool Map::determineAdditionalOcclusionCheck(const v3POS &pos_camera, + const core::aabbox3d &block_bounds, v3POS &check) { /* This functions determines the node inside the target block that is @@ -1049,32 +1051,32 @@ bool Map::determineAdditionalOcclusionCheck(const v3s16 &pos_camera, // straight if (x_inside && y_inside) { - check = v3s16(pos_camera.X, pos_camera.Y, 0); + check = v3POS(pos_camera.X, pos_camera.Y, 0); check.Z = CLOSEST_EDGE(pos_camera, block_bounds, Z); return true; } else if (y_inside && z_inside) { - check = v3s16(0, pos_camera.Y, pos_camera.Z); + check = v3POS(0, pos_camera.Y, pos_camera.Z); check.X = CLOSEST_EDGE(pos_camera, block_bounds, X); return true; } else if (x_inside && z_inside) { - check = v3s16(pos_camera.X, 0, pos_camera.Z); + check = v3POS(pos_camera.X, 0, pos_camera.Z); check.Y = CLOSEST_EDGE(pos_camera, block_bounds, Y); return true; } // diagonal if (x_inside) { - check = v3s16(pos_camera.X, 0, 0); + check = v3POS(pos_camera.X, 0, 0); check.Y = CLOSEST_EDGE(pos_camera, block_bounds, Y); check.Z = CLOSEST_EDGE(pos_camera, block_bounds, Z); return true; } else if (y_inside) { - check = v3s16(0, pos_camera.Y, 0); + check = v3POS(0, pos_camera.Y, 0); check.X = CLOSEST_EDGE(pos_camera, block_bounds, X); check.Z = CLOSEST_EDGE(pos_camera, block_bounds, Z); return true; } else if (z_inside) { - check = v3s16(0, 0, pos_camera.Z); + check = v3POS(0, 0, pos_camera.Z); check.X = CLOSEST_EDGE(pos_camera, block_bounds, X); check.Y = CLOSEST_EDGE(pos_camera, block_bounds, Y); return true; @@ -1084,7 +1086,7 @@ bool Map::determineAdditionalOcclusionCheck(const v3s16 &pos_camera, return false; } -bool Map::isOccluded(const v3s16 &pos_camera, const v3s16 &pos_target, +bool Map::isOccluded(const v3POS &pos_camera, const v3POS &pos_target, float step, float stepfac, float offset, float end_offset, u32 needed_count) { v3f direction = intToFloat(pos_target - pos_camera, BS); @@ -1100,7 +1102,7 @@ bool Map::isOccluded(const v3s16 &pos_camera, const v3s16 &pos_target, for (; offset < distance + end_offset; offset += step) { v3f pos_node_f = pos_origin_f + direction * offset; - v3s16 pos_node = floatToInt(pos_node_f, BS); + v3POS pos_node = floatToInt(pos_node_f, BS); MapNode node = getNode(pos_node, &is_valid_position); @@ -1116,24 +1118,24 @@ bool Map::isOccluded(const v3s16 &pos_camera, const v3s16 &pos_target, return false; } -bool Map::isBlockOccluded(MapBlock *block, v3s16 cam_pos_nodes) +bool Map::isBlockOccluded(MapBlock *block, v3POS cam_pos_nodes) { // Check occlusion for center and all 8 corners of the mapblock // Overshoot a little for less flickering static const s16 bs2 = MAP_BLOCKSIZE / 2 + 1; - static const v3s16 dir9[9] = { - v3s16( 0, 0, 0), - v3s16( 1, 1, 1) * bs2, - v3s16( 1, 1, -1) * bs2, - v3s16( 1, -1, 1) * bs2, - v3s16( 1, -1, -1) * bs2, - v3s16(-1, 1, 1) * bs2, - v3s16(-1, 1, -1) * bs2, - v3s16(-1, -1, 1) * bs2, - v3s16(-1, -1, -1) * bs2, + static const v3POS dir9[9] = { + v3POS( 0, 0, 0), + v3POS( 1, 1, 1) * bs2, + v3POS( 1, 1, -1) * bs2, + v3POS( 1, -1, 1) * bs2, + v3POS( 1, -1, -1) * bs2, + v3POS(-1, 1, 1) * bs2, + v3POS(-1, 1, -1) * bs2, + v3POS(-1, -1, 1) * bs2, + v3POS(-1, -1, -1) * bs2, }; - v3s16 pos_blockcenter = block->getPosRelative() + (MAP_BLOCKSIZE / 2); + v3POS pos_blockcenter = block->getPosRelative() + (MAP_BLOCKSIZE / 2); // Starting step size, value between 1m and sqrt(3)m float step = BS * 1.2f; @@ -1155,7 +1157,7 @@ bool Map::isBlockOccluded(MapBlock *block, v3s16 cam_pos_nodes) u32 needed_count = 2; // Additional occlusion check, see comments in that function - v3s16 check; + v3POS check; if (determineAdditionalOcclusionCheck(cam_pos_nodes, block->getBox(), check)) { // node is always on a side facing the camera, end_offset can be lower if (!isOccluded(cam_pos_nodes, check, step, stepfac, start_offset, @@ -1163,7 +1165,7 @@ bool Map::isBlockOccluded(MapBlock *block, v3s16 cam_pos_nodes) return false; } - for (const v3s16 &dir : dir9) { + for (const v3POS &dir : dir9) { if (!isOccluded(cam_pos_nodes, pos_blockcenter + dir, step, stepfac, start_offset, end_offset, needed_count)) return false; @@ -1292,9 +1294,9 @@ u64 ServerMap::getSeed() return getMapgenParams()->seed; } -bool ServerMap::blockpos_over_mapgen_limit(v3s16 p) +bool ServerMap::blockpos_over_mapgen_limit(v3BPOS p) { - const s16 mapgen_limit_bp = rangelim( + const BPOS mapgen_limit_bp = rangelim( getMapgenParams()->mapgen_limit, 0, MAX_MAP_GENERATION_LIMIT) / MAP_BLOCKSIZE; return p.X < -mapgen_limit_bp || @@ -1305,11 +1307,11 @@ bool ServerMap::blockpos_over_mapgen_limit(v3s16 p) p.Z > mapgen_limit_bp; } -bool ServerMap::initBlockMake(v3s16 blockpos, BlockMakeData *data) +bool ServerMap::initBlockMake(v3BPOS blockpos, BlockMakeData *data) { s16 csize = getMapgenParams()->chunksize; - v3s16 bpmin = EmergeManager::getContainingChunk(blockpos, csize); - v3s16 bpmax = bpmin + v3s16(1, 1, 1) * (csize - 1); + v3BPOS bpmin = EmergeManager::getContainingChunk(blockpos, csize); + v3BPOS bpmax = bpmin + v3BPOS(1, 1, 1) * (csize - 1); if (!m_chunks_in_progress.insert(bpmin).second) return false; @@ -1317,9 +1319,9 @@ bool ServerMap::initBlockMake(v3s16 blockpos, BlockMakeData *data) bool enable_mapgen_debug_info = m_emerge->enable_mapgen_debug_info; EMERGE_DBG_OUT("initBlockMake(): " PP(bpmin) " - " PP(bpmax)); - v3s16 extra_borders(1, 1, 1); - v3s16 full_bpmin = bpmin - extra_borders; - v3s16 full_bpmax = bpmax + extra_borders; + v3BPOS extra_borders(1, 1, 1); + v3BPOS full_bpmin = bpmin - extra_borders; + v3BPOS full_bpmax = bpmax + extra_borders; // Do nothing if not inside mapgen limits (+-1 because of neighbors) if (blockpos_over_mapgen_limit(full_bpmin) || @@ -1334,15 +1336,15 @@ bool ServerMap::initBlockMake(v3s16 blockpos, BlockMakeData *data) /* Create the whole area of this and the neighboring blocks */ - for (s16 x = full_bpmin.X; x <= full_bpmax.X; x++) - for (s16 z = full_bpmin.Z; z <= full_bpmax.Z; z++) { - v2s16 sectorpos(x, z); + for (BPOS x = full_bpmin.X; x <= full_bpmax.X; x++) + for (BPOS z = full_bpmin.Z; z <= full_bpmax.Z; z++) { + v2BPOS sectorpos(x, z); // Sector metadata is loaded from disk if not already loaded. MapSector *sector = createSector(sectorpos); FATAL_ERROR_IF(sector == NULL, "createSector() failed"); - for (s16 y = full_bpmin.Y; y <= full_bpmax.Y; y++) { - v3s16 p(x, y, z); + for (BPOS y = full_bpmin.Y; y <= full_bpmax.Y; y++) { + v3BPOS p(x, y, z); MapBlock *block = emergeBlock(p, false); if (block == NULL) { @@ -1371,10 +1373,10 @@ bool ServerMap::initBlockMake(v3s16 blockpos, BlockMakeData *data) } void ServerMap::finishBlockMake(BlockMakeData *data, - std::map *changed_blocks) + std::map *changed_blocks) { - v3s16 bpmin = data->blockpos_min; - v3s16 bpmax = data->blockpos_max; + v3BPOS bpmin = data->blockpos_min; + v3BPOS bpmax = data->blockpos_max; bool enable_mapgen_debug_info = m_emerge->enable_mapgen_debug_info; EMERGE_DBG_OUT("finishBlockMake(): " PP(bpmin) " - " PP(bpmax)); @@ -1414,10 +1416,10 @@ void ServerMap::finishBlockMake(BlockMakeData *data, /* Set central blocks as generated */ - for (s16 x = bpmin.X; x <= bpmax.X; x++) - for (s16 z = bpmin.Z; z <= bpmax.Z; z++) - for (s16 y = bpmin.Y; y <= bpmax.Y; y++) { - MapBlock *block = getBlockNoCreateNoEx(v3s16(x, y, z)); + for (BPOS x = bpmin.X; x <= bpmax.X; x++) + for (BPOS z = bpmin.Z; z <= bpmax.Z; z++) + for (BPOS y = bpmin.Y; y <= bpmax.Y; y++) { + MapBlock *block = getBlockNoCreateNoEx(v3BPOS(x, y, z)); if (!block) continue; @@ -1432,7 +1434,7 @@ void ServerMap::finishBlockMake(BlockMakeData *data, m_chunks_in_progress.erase(bpmin); } -MapSector *ServerMap::createSector(v2s16 p2d) +MapSector *ServerMap::createSector(v2BPOS p2d) { /* Check if it exists already in memory @@ -1444,7 +1446,7 @@ MapSector *ServerMap::createSector(v2s16 p2d) /* Do not create over max mapgen limit */ - const s16 max_limit_bp = MAX_MAP_GENERATION_LIMIT / MAP_BLOCKSIZE; + const BPOS max_limit_bp = MAX_MAP_GENERATION_LIMIT / MAP_BLOCKSIZE; if (p2d.X < -max_limit_bp || p2d.X > max_limit_bp || p2d.Y < -max_limit_bp || @@ -1458,7 +1460,7 @@ MapSector *ServerMap::createSector(v2s16 p2d) sector = new MapSector(this, p2d, m_gamedef); // Sector position on map in nodes - //v2s16 nodepos2d = p2d * MAP_BLOCKSIZE; + //v2POS nodepos2d = p2d * MAP_BLOCKSIZE; /* Insert to container @@ -1468,7 +1470,7 @@ MapSector *ServerMap::createSector(v2s16 p2d) return sector; } -MapBlock * ServerMap::createBlock(v3s16 p) +MapBlock * ServerMap::createBlock(v3BPOS p) { /* Do not create over max mapgen limit @@ -1476,8 +1478,8 @@ MapBlock * ServerMap::createBlock(v3s16 p) if (blockpos_over_max_limit(p)) throw InvalidPositionException("createBlock(): pos. over max mapgen limit"); - v2s16 p2d(p.X, p.Z); - s16 block_y = p.Y; + v2BPOS p2d(p.X, p.Z); + BPOS block_y = p.Y; /* This will create or load a sector if not found in memory. If block exists on disk, it will be loaded. @@ -1509,7 +1511,7 @@ MapBlock * ServerMap::createBlock(v3s16 p) return block; } -MapBlock * ServerMap::emergeBlock(v3s16 p, bool create_blank) +MapBlock * ServerMap::emergeBlock(v3BPOS p, bool create_blank) { { MapBlock *block = getBlockNoCreateNoEx(p); @@ -1524,7 +1526,7 @@ MapBlock * ServerMap::emergeBlock(v3s16 p, bool create_blank) } if (create_blank) { - MapSector *sector = createSector(v2s16(p.X, p.Z)); + MapSector *sector = createSector(v2BPOS(p.X, p.Z)); MapBlock *block = sector->createBlankBlock(p.Y); return block; @@ -1533,7 +1535,7 @@ MapBlock * ServerMap::emergeBlock(v3s16 p, bool create_blank) return NULL; } -MapBlock *ServerMap::getBlockOrEmerge(v3s16 p3d) +MapBlock *ServerMap::getBlockOrEmerge(v3BPOS p3d) { MapBlock *block = getBlockNoCreateNoEx(p3d); if (block == NULL) @@ -1542,14 +1544,14 @@ MapBlock *ServerMap::getBlockOrEmerge(v3s16 p3d) return block; } -bool ServerMap::isBlockInQueue(v3s16 pos) +bool ServerMap::isBlockInQueue(v3BPOS pos) { return m_emerge && m_emerge->isBlockInQueue(pos); } // N.B. This requires no synchronization, since data will not be modified unless // the VoxelManipulator being updated belongs to the same thread. -void ServerMap::updateVManip(v3s16 pos) +void ServerMap::updateVManip(v3POS pos) { Mapgen *mg = m_emerge->getCurrentMapgen(); if (!mg) @@ -1641,14 +1643,14 @@ void ServerMap::save(ModifiedState save_level) m_save_time_counter->increment(end_time - start_time); } -void ServerMap::listAllLoadableBlocks(std::vector &dst) +void ServerMap::listAllLoadableBlocks(std::vector &dst) { dbase->listAllLoadableBlocks(dst); if (dbase_ro) dbase_ro->listAllLoadableBlocks(dst); } -void ServerMap::listAllLoadedBlocks(std::vector &dst) +void ServerMap::listAllLoadedBlocks(std::vector &dst) { for (auto §or_it : m_sectors) { MapSector *sector = sector_it.second; @@ -1657,7 +1659,7 @@ void ServerMap::listAllLoadedBlocks(std::vector &dst) sector->getBlocks(blocks); for (MapBlock *block : blocks) { - v3s16 p = block->getPos(); + v3BPOS p = block->getPos(); dst.push_back(p); } } @@ -1708,7 +1710,7 @@ bool ServerMap::saveBlock(MapBlock *block) bool ServerMap::saveBlock(MapBlock *block, MapDatabase *db, int compression_level) { - v3s16 p3d = block->getPos(); + v3BPOS p3d = block->getPos(); // Dummy blocks are not written if (block->isDummy()) { @@ -1736,7 +1738,7 @@ bool ServerMap::saveBlock(MapBlock *block, MapDatabase *db, int compression_leve return ret; } -void ServerMap::loadBlock(std::string *blob, v3s16 p3d, MapSector *sector, bool save_after_load) +void ServerMap::loadBlock(std::string *blob, v3BPOS p3d, MapSector *sector, bool save_after_load) { try { std::istringstream is(*blob, std::ios_base::binary); @@ -1797,11 +1799,11 @@ void ServerMap::loadBlock(std::string *blob, v3s16 p3d, MapSector *sector, bool } } -MapBlock* ServerMap::loadBlock(v3s16 blockpos) +MapBlock* ServerMap::loadBlock(v3BPOS blockpos) { bool created_new = (getBlockNoCreateNoEx(blockpos) == NULL); - v2s16 p2d(blockpos.X, blockpos.Z); + v2BPOS p2d(blockpos.X, blockpos.Z); std::string ret; dbase->loadBlock(blockpos, &ret); @@ -1818,14 +1820,14 @@ MapBlock* ServerMap::loadBlock(v3s16 blockpos) MapBlock *block = getBlockNoCreateNoEx(blockpos); if (created_new && (block != NULL)) { - std::map modified_blocks; + std::map modified_blocks; // Fix lighting if necessary voxalgo::update_block_border_lighting(this, block, modified_blocks); if (!modified_blocks.empty()) { //Modified lighting, send event MapEditEvent event; event.type = MEET_OTHER; - std::map::iterator it; + std::map::iterator it; for (it = modified_blocks.begin(); it != modified_blocks.end(); ++it) event.modified_blocks.insert(it->first); @@ -1835,14 +1837,14 @@ MapBlock* ServerMap::loadBlock(v3s16 blockpos) return block; } -bool ServerMap::deleteBlock(v3s16 blockpos) +bool ServerMap::deleteBlock(v3BPOS blockpos) { if (!dbase->deleteBlock(blockpos)) return false; MapBlock *block = getBlockNoCreateNoEx(blockpos); if (block) { - v2s16 p2d(blockpos.X, blockpos.Z); + v2BPOS p2d(blockpos.X, blockpos.Z); MapSector *sector = getSectorNoGenerate(p2d); if (!sector) return false; @@ -1857,8 +1859,8 @@ void ServerMap::PrintInfo(std::ostream &out) out<<"ServerMap: "; } -bool ServerMap::repairBlockLight(v3s16 blockpos, - std::map *modified_blocks) +bool ServerMap::repairBlockLight(v3BPOS blockpos, + std::map *modified_blocks) { MapBlock *block = emergeBlock(blockpos, false); if (!block || !block->isGenerated()) @@ -1873,17 +1875,17 @@ MMVManip::MMVManip(Map *map): { } -void MMVManip::initialEmerge(v3s16 blockpos_min, v3s16 blockpos_max, +void MMVManip::initialEmerge(v3BPOS blockpos_min, v3BPOS blockpos_max, bool load_if_inexistent) { TimeTaker timer1("initialEmerge", &emerge_time); // Units of these are MapBlocks - v3s16 p_min = blockpos_min; - v3s16 p_max = blockpos_max; + v3BPOS p_min = blockpos_min; + v3BPOS p_max = blockpos_max; VoxelArea block_area_nodes - (p_min*MAP_BLOCKSIZE, (p_max+1)*MAP_BLOCKSIZE-v3s16(1,1,1)); + (p_min*MAP_BLOCKSIZE, (p_max+1)*MAP_BLOCKSIZE-v3POS(1,1,1)); u32 size_MB = block_area_nodes.getVolume()*4/1000000; if(size_MB >= 1) @@ -1902,8 +1904,8 @@ void MMVManip::initialEmerge(v3s16 blockpos_min, v3s16 blockpos_max, { u8 flags = 0; MapBlock *block; - v3s16 p(x,y,z); - std::map::iterator n; + v3BPOS p(x,y,z); + std::map::iterator n; n = m_loaded_blocks.find(p); if(n != m_loaded_blocks.end()) continue; @@ -1934,7 +1936,7 @@ void MMVManip::initialEmerge(v3s16 blockpos_min, v3s16 blockpos_max, /* Mark area inexistent */ - VoxelArea a(p*MAP_BLOCKSIZE, (p+1)*MAP_BLOCKSIZE-v3s16(1,1,1)); + VoxelArea a(p*MAP_BLOCKSIZE, (p+1)*MAP_BLOCKSIZE-v3POS(1,1,1)); // Fill with VOXELFLAG_NO_DATA for(s32 z=a.MinEdge.Z; z<=a.MaxEdge.Z; z++) for(s32 y=a.MinEdge.Y; y<=a.MaxEdge.Y; y++) @@ -1956,17 +1958,17 @@ void MMVManip::initialEmerge(v3s16 blockpos_min, v3s16 blockpos_max, m_is_dirty = false; } -void MMVManip::blitBackAll(std::map *modified_blocks, +void MMVManip::blitBackAll(std::map *modified_blocks, bool overwrite_generated) { - if(m_area.getExtent() == v3s16(0,0,0)) + if(m_area.getExtent() == v3POS(0,0,0)) return; /* Copy data of all blocks */ for (auto &loaded_block : m_loaded_blocks) { - v3s16 p = loaded_block.first; + v3BPOS p = loaded_block.first; MapBlock *block = m_map->getBlockNoCreateNoEx(p); bool existed = !(loaded_block.second & VMANIP_BLOCK_DATA_INEXIST); if (!existed || (block == NULL) || diff --git a/src/map.h b/src/map.h index fe580b20f8..4b1560b5ee 100644 --- a/src/map.h +++ b/src/map.h @@ -25,6 +25,8 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include +#include "irr_v2d.h" +#include "irr_v3d.h" #include "irrlichttypes_bloated.h" #include "mapnode.h" #include "constants.h" @@ -32,6 +34,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "modifiedstate.h" #include "util/container.h" #include "util/metricsbackend.h" +#include "util/numeric.h" #include "nodetimer.h" #include "map_settings_manager.h" #include "debug.h" @@ -74,9 +77,9 @@ enum MapEditEventType{ struct MapEditEvent { MapEditEventType type = MEET_OTHER; - v3s16 p; + v3POS p; MapNode n = CONTENT_AIR; - std::set modified_blocks; + std::set modified_blocks; bool is_private_change = false; MapEditEvent() = default; @@ -92,16 +95,16 @@ struct MapEditEvent return VoxelArea(p); case MEET_BLOCK_NODE_METADATA_CHANGED: { - v3s16 np1 = p*MAP_BLOCKSIZE; - v3s16 np2 = np1 + v3s16(1,1,1)*MAP_BLOCKSIZE - v3s16(1,1,1); + v3POS np1 = p*MAP_BLOCKSIZE; + v3POS np2 = np1 + v3POS(1,1,1)*MAP_BLOCKSIZE - v3POS(1,1,1); return VoxelArea(np1, np2); } case MEET_OTHER: { VoxelArea a; - for (v3s16 p : modified_blocks) { - v3s16 np1 = p*MAP_BLOCKSIZE; - v3s16 np2 = np1 + v3s16(1,1,1)*MAP_BLOCKSIZE - v3s16(1,1,1); + for (v3BPOS p : modified_blocks) { + v3POS np1 = getContainerPos(p, MAP_BLOCKSIZE); + v3POS np2 = np1 + v3POS(1,1,1)*MAP_BLOCKSIZE - v3POS(1,1,1); a.addPoint(np1); a.addPoint(np2); } @@ -146,53 +149,53 @@ class Map /*: public NodeContainer*/ void dispatchEvent(const MapEditEvent &event); // On failure returns NULL - MapSector * getSectorNoGenerateNoLock(v2s16 p2d); + MapSector * getSectorNoGenerateNoLock(v2BPOS p2d); // Same as the above (there exists no lock anymore) - MapSector * getSectorNoGenerate(v2s16 p2d); + MapSector * getSectorNoGenerate(v2BPOS p2d); /* This is overloaded by ClientMap and ServerMap to allow their differing fetch methods. */ - virtual MapSector * emergeSector(v2s16 p){ return NULL; } + virtual MapSector * emergeSector(v2BPOS p){ return NULL; } // Returns InvalidPositionException if not found - MapBlock * getBlockNoCreate(v3s16 p); + MapBlock * getBlockNoCreate(v3BPOS p); // Returns NULL if not found - MapBlock * getBlockNoCreateNoEx(v3s16 p); + MapBlock * getBlockNoCreateNoEx(v3BPOS p); /* Server overrides */ - virtual MapBlock * emergeBlock(v3s16 p, bool create_blank=true) + virtual MapBlock * emergeBlock(v3BPOS p, bool create_blank=true) { return getBlockNoCreateNoEx(p); } inline const NodeDefManager * getNodeDefManager() { return m_nodedef; } - bool isValidPosition(v3s16 p); + bool isValidPosition(v3POS p); // throws InvalidPositionException if not found - void setNode(v3s16 p, MapNode & n); + void setNode(v3POS p, MapNode & n); // Returns a CONTENT_IGNORE node if not found // If is_valid_position is not NULL then this will be set to true if the // position is valid, otherwise false - MapNode getNode(v3s16 p, bool *is_valid_position = NULL); + MapNode getNode(v3POS p, bool *is_valid_position = NULL); /* These handle lighting but not faces. */ - void addNodeAndUpdate(v3s16 p, MapNode n, - std::map &modified_blocks, + void addNodeAndUpdate(v3POS p, MapNode n, + std::map &modified_blocks, bool remove_metadata = true); - void removeNodeAndUpdate(v3s16 p, - std::map &modified_blocks); + void removeNodeAndUpdate(v3POS p, + std::map &modified_blocks); /* Wrappers for the latter ones. These emit events. Return true if succeeded, false if not. */ - bool addNodeWithEvent(v3s16 p, MapNode n, bool remove_metadata = true); - bool removeNodeWithEvent(v3s16 p); + bool addNodeWithEvent(v3POS p, MapNode n, bool remove_metadata = true); + bool removeNodeWithEvent(v3POS p); // Call these before and after saving of many blocks virtual void beginSave() {} @@ -203,30 +206,30 @@ class Map /*: public NodeContainer*/ // Server implements these. // Client leaves them as no-op. virtual bool saveBlock(MapBlock *block) { return false; } - virtual bool deleteBlock(v3s16 blockpos) { return false; } + virtual bool deleteBlock(v3BPOS blockpos) { return false; } /* Updates usage timers and unloads unused blocks and sectors. Saves modified blocks before unloading on MAPTYPE_SERVER. */ void timerUpdate(float dtime, float unload_timeout, u32 max_loaded_blocks, - std::vector *unloaded_blocks=NULL); + std::vector *unloaded_blocks=NULL); /* Unloads all blocks with a zero refCount(). Saves modified blocks before unloading on MAPTYPE_SERVER. */ - void unloadUnreferencedBlocks(std::vector *unloaded_blocks=NULL); + void unloadUnreferencedBlocks(std::vector *unloaded_blocks=NULL); // Deletes sectors and their blocks from memory // Takes cache into account // If deleted sector is in sector cache, clears cache - void deleteSectors(std::vector &list); + void deleteSectors(std::vector &list); // For debug printing. Prints "Map: ", "ServerMap: " or "ClientMap: " virtual void PrintInfo(std::ostream &out); - void transformLiquids(std::map & modified_blocks, + void transformLiquids(std::map & modified_blocks, ServerEnvironment *env); /* @@ -234,8 +237,8 @@ class Map /*: public NodeContainer*/ These are basically coordinate wrappers to MapBlock */ - std::vector findNodesWithMetadata(v3s16 p1, v3s16 p2); - NodeMetadata *getNodeMetadata(v3s16 p); + std::vector findNodesWithMetadata(v3POS p1, v3POS p2); + NodeMetadata *getNodeMetadata(v3POS p); /** * Sets metadata for a node. @@ -251,25 +254,25 @@ class Map /*: public NodeContainer*/ * @param meta pointer to @c NodeMetadata object * @return @c true on success, false on failure */ - bool setNodeMetadata(v3s16 p, NodeMetadata *meta); - void removeNodeMetadata(v3s16 p); + bool setNodeMetadata(v3POS p, NodeMetadata *meta); + void removeNodeMetadata(v3POS p); /* Node Timers These are basically coordinate wrappers to MapBlock */ - NodeTimer getNodeTimer(v3s16 p); + NodeTimer getNodeTimer(v3POS p); void setNodeTimer(const NodeTimer &t); - void removeNodeTimer(v3s16 p); + void removeNodeTimer(v3POS p); /* Variables */ - void transforming_liquid_add(v3s16 p); + void transforming_liquid_add(v3POS p); - bool isBlockOccluded(MapBlock *block, v3s16 cam_pos_nodes); + bool isBlockOccluded(MapBlock *block, v3POS cam_pos_nodes); protected: friend class LuaVoxelManip; @@ -277,21 +280,21 @@ class Map /*: public NodeContainer*/ std::set m_event_receivers; - std::map m_sectors; + std::map m_sectors; // Be sure to set this to NULL when the cached sector is deleted MapSector *m_sector_cache = nullptr; - v2s16 m_sector_cache_p; + v2BPOS m_sector_cache_p; // Queued transforming water nodes - UniqueQueue m_transforming_liquid; + UniqueQueue m_transforming_liquid; // This stores the properties of the nodes on the map. const NodeDefManager *m_nodedef; - bool determineAdditionalOcclusionCheck(const v3s16 &pos_camera, - const core::aabbox3d &block_bounds, v3s16 &check); - bool isOccluded(const v3s16 &pos_camera, const v3s16 &pos_target, + bool determineAdditionalOcclusionCheck(const v3POS &pos_camera, + const core::aabbox3d &block_bounds, v3POS &check); + bool isOccluded(const v3POS &pos_camera, const v3POS &pos_target, float step, float stepfac, float start_offset, float end_offset, u32 needed_count); @@ -328,22 +331,22 @@ class ServerMap : public Map - Check disk (doesn't load blocks) - Create blank one */ - MapSector *createSector(v2s16 p); + MapSector *createSector(v2BPOS p); /* Blocks are generated by using these and makeBlock(). */ - bool blockpos_over_mapgen_limit(v3s16 p); - bool initBlockMake(v3s16 blockpos, BlockMakeData *data); + bool blockpos_over_mapgen_limit(v3BPOS p); + bool initBlockMake(v3BPOS blockpos, BlockMakeData *data); void finishBlockMake(BlockMakeData *data, - std::map *changed_blocks); + std::map *changed_blocks); /* Get a block from somewhere. - Memory - Create blank */ - MapBlock *createBlock(v3s16 p); + MapBlock *createBlock(v3BPOS p); /* Forcefully get a block from somewhere. @@ -352,7 +355,7 @@ class ServerMap : public Map - Create blank filled with CONTENT_IGNORE */ - MapBlock *emergeBlock(v3s16 p, bool create_blank=true); + MapBlock *emergeBlock(v3BPOS p, bool create_blank=true); /* Try to get a block. @@ -360,9 +363,9 @@ class ServerMap : public Map - Memory - Emerge Queue (deferred disk or generate) */ - MapBlock *getBlockOrEmerge(v3s16 p3d); + MapBlock *getBlockOrEmerge(v3BPOS p3d); - bool isBlockInQueue(v3s16 pos); + bool isBlockInQueue(v3BPOS pos); /* Database functions @@ -374,20 +377,20 @@ class ServerMap : public Map void endSave(); void save(ModifiedState save_level); - void listAllLoadableBlocks(std::vector &dst); - void listAllLoadedBlocks(std::vector &dst); + void listAllLoadableBlocks(std::vector &dst); + void listAllLoadedBlocks(std::vector &dst); MapgenParams *getMapgenParams(); bool saveBlock(MapBlock *block); static bool saveBlock(MapBlock *block, MapDatabase *db, int compression_level = -1); - MapBlock* loadBlock(v3s16 p); + MapBlock* loadBlock(v3BPOS p); // Database version - void loadBlock(std::string *blob, v3s16 p3d, MapSector *sector, bool save_after_load=false); + void loadBlock(std::string *blob, v3BPOS p3d, MapSector *sector, bool save_after_load=false); - bool deleteBlock(v3s16 blockpos); + bool deleteBlock(v3BPOS blockpos); - void updateVManip(v3s16 pos); + void updateVManip(v3POS pos); // For debug printing virtual void PrintInfo(std::ostream &out); @@ -403,8 +406,8 @@ class ServerMap : public Map * Returns false if the block is not generated (so nothing * changed), true otherwise. */ - bool repairBlockLight(v3s16 blockpos, - std::map *modified_blocks); + bool repairBlockLight(v3BPOS blockpos, + std::map *modified_blocks); MapSettingsManager settings_mgr; @@ -417,7 +420,7 @@ class ServerMap : public Map int m_map_compression_level; - std::set m_chunks_in_progress; + std::set m_chunks_in_progress; /* Metadata is re-written on disk only if this is true. @@ -446,11 +449,11 @@ class MMVManip : public VoxelManipulator m_loaded_blocks.clear(); } - void initialEmerge(v3s16 blockpos_min, v3s16 blockpos_max, + void initialEmerge(v3BPOS blockpos_min, v3BPOS blockpos_max, bool load_if_inexistent = true); // This is much faster with big chunks of generated data - void blitBackAll(std::map * modified_blocks, + void blitBackAll(std::map * modified_blocks, bool overwrite_generated = true); bool m_is_dirty = false; @@ -461,5 +464,5 @@ class MMVManip : public VoxelManipulator key = blockpos value = flags describing the block */ - std::map m_loaded_blocks; + std::map m_loaded_blocks; }; diff --git a/src/mapblock.cpp b/src/mapblock.cpp index e3a6caa199..14371e38d5 100644 --- a/src/mapblock.cpp +++ b/src/mapblock.cpp @@ -66,7 +66,7 @@ static const char *modified_reason_strings[] = { MapBlock */ -MapBlock::MapBlock(Map *parent, v3s16 pos, IGameDef *gamedef, bool dummy): +MapBlock::MapBlock(Map *parent, v3POS pos, IGameDef *gamedef, bool dummy): m_parent(parent), m_pos(pos), m_pos_relative(pos * MAP_BLOCKSIZE), @@ -88,7 +88,7 @@ MapBlock::~MapBlock() delete[] data; } -bool MapBlock::isValidPositionParent(v3s16 p) +bool MapBlock::isValidPositionParent(v3POS p) { if (isValidPosition(p)) { return true; @@ -97,7 +97,7 @@ bool MapBlock::isValidPositionParent(v3s16 p) return m_parent->isValidPosition(getPosRelative() + p); } -MapNode MapBlock::getNodeParent(v3s16 p, bool *is_valid_position) +MapNode MapBlock::getNodeParent(v3POS p, bool *is_valid_position) { if (!isValidPosition(p)) return m_parent->getNode(getPosRelative() + p, is_valid_position); @@ -136,21 +136,21 @@ std::string MapBlock::getModifiedReasonString() void MapBlock::copyTo(VoxelManipulator &dst) { - v3s16 data_size(MAP_BLOCKSIZE, MAP_BLOCKSIZE, MAP_BLOCKSIZE); - VoxelArea data_area(v3s16(0,0,0), data_size - v3s16(1,1,1)); + v3POS data_size(MAP_BLOCKSIZE, MAP_BLOCKSIZE, MAP_BLOCKSIZE); + VoxelArea data_area(v3POS(0,0,0), data_size - v3POS(1,1,1)); // Copy from data to VoxelManipulator - dst.copyFrom(data, data_area, v3s16(0,0,0), + dst.copyFrom(data, data_area, v3POS(0,0,0), getPosRelative(), data_size); } void MapBlock::copyFrom(VoxelManipulator &dst) { - v3s16 data_size(MAP_BLOCKSIZE, MAP_BLOCKSIZE, MAP_BLOCKSIZE); - VoxelArea data_area(v3s16(0,0,0), data_size - v3s16(1,1,1)); + v3POS data_size(MAP_BLOCKSIZE, MAP_BLOCKSIZE, MAP_BLOCKSIZE); + VoxelArea data_area(v3POS(0,0,0), data_size - v3POS(1,1,1)); // Copy from VoxelManipulator to data - dst.copyTo(data, data_area, v3s16(0,0,0), + dst.copyTo(data, data_area, v3POS(0,0,0), getPosRelative(), data_size); } @@ -825,7 +825,7 @@ std::string analyze_block(MapBlock *block) std::ostringstream desc; - v3s16 p = block->getPos(); + v3POS p = block->getPos(); char spos[25]; porting::mt_snprintf(spos, sizeof(spos), "(%2d,%2d,%2d), ", p.X, p.Y, p.Z); desc<getNodeNoEx(p); content_t c = n.getContent(); if(c == CONTENT_IGNORE) diff --git a/src/mapblock.h b/src/mapblock.h index e729fdb1cc..d0f9c82e09 100644 --- a/src/mapblock.h +++ b/src/mapblock.h @@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include "irr_v3d.h" +#include "irrlichttypes.h" #include "mapnode.h" #include "exceptions.h" #include "constants.h" @@ -73,7 +74,7 @@ class VoxelManipulator; class MapBlock { public: - MapBlock(Map *parent, v3s16 pos, IGameDef *gamedef, bool dummy=false); + MapBlock(Map *parent, v3POS pos, IGameDef *gamedef, bool dummy=false); ~MapBlock(); /*virtual u16 nodeContainerId() const @@ -218,22 +219,22 @@ class MapBlock //// Position stuff //// - inline v3s16 getPos() + inline v3BPOS getPos() { return m_pos; } - inline v3s16 getPosRelative() + inline v3POS getPosRelative() { return m_pos_relative; } - inline core::aabbox3d getBox() + inline core::aabbox3d getBox() { - return core::aabbox3d(getPosRelative(), + return core::aabbox3d(getPosRelative(), getPosRelative() - + v3s16(MAP_BLOCKSIZE, MAP_BLOCKSIZE, MAP_BLOCKSIZE) - - v3s16(1,1,1)); + + v3POS(MAP_BLOCKSIZE, MAP_BLOCKSIZE, MAP_BLOCKSIZE) + - v3POS(1,1,1)); } //// @@ -248,7 +249,7 @@ class MapBlock && z >= 0 && z < MAP_BLOCKSIZE; } - inline bool isValidPosition(v3s16 p) + inline bool isValidPosition(v3POS p) { return isValidPosition(p.X, p.Y, p.Z); } @@ -263,12 +264,12 @@ class MapBlock return data[z * zstride + y * ystride + x]; } - inline MapNode getNode(v3s16 p, bool *valid_position) + inline MapNode getNode(v3POS p, bool *valid_position) { return getNode(p.X, p.Y, p.Z, valid_position); } - inline MapNode getNodeNoEx(v3s16 p) + inline MapNode getNodeNoEx(v3POS p) { bool is_valid; return getNode(p.X, p.Y, p.Z, &is_valid); @@ -283,7 +284,7 @@ class MapBlock raiseModified(MOD_STATE_WRITE_NEEDED, MOD_REASON_SET_NODE); } - inline void setNode(v3s16 p, MapNode & n) + inline void setNode(v3POS p, MapNode & n) { setNode(p.X, p.Y, p.Z, n); } @@ -292,7 +293,7 @@ class MapBlock //// Non-checking variants of the above //// - inline MapNode getNodeNoCheck(s16 x, s16 y, s16 z, bool *valid_position) + inline MapNode getNodeNoCheck(POS x, POS y, POS z, bool *valid_position) { *valid_position = data != nullptr; if (!*valid_position) @@ -301,7 +302,7 @@ class MapBlock return data[z * zstride + y * ystride + x]; } - inline MapNode getNodeNoCheck(v3s16 p, bool *valid_position) + inline MapNode getNodeNoCheck(v3POS p, bool *valid_position) { return getNodeNoCheck(p.X, p.Y, p.Z, valid_position); } @@ -312,17 +313,17 @@ class MapBlock //// Caller must ensure that this is not a dummy block (by calling isDummy()) //// - inline const MapNode &getNodeUnsafe(s16 x, s16 y, s16 z) + inline const MapNode &getNodeUnsafe(POS x, POS y, POS z) { return data[z * zstride + y * ystride + x]; } - inline const MapNode &getNodeUnsafe(v3s16 &p) + inline const MapNode &getNodeUnsafe(v3POS &p) { return getNodeUnsafe(p.X, p.Y, p.Z); } - inline void setNodeNoCheck(s16 x, s16 y, s16 z, MapNode & n) + inline void setNodeNoCheck(POS x, POS y, POS z, MapNode & n) { if (!data) throw InvalidPositionException(); @@ -331,15 +332,15 @@ class MapBlock raiseModified(MOD_STATE_WRITE_NEEDED, MOD_REASON_SET_NODE_NO_CHECK); } - inline void setNodeNoCheck(v3s16 p, MapNode & n) + inline void setNodeNoCheck(v3POS p, MapNode & n) { setNodeNoCheck(p.X, p.Y, p.Z, n); } // These functions consult the parent container if the position // is not valid on this MapBlock. - bool isValidPositionParent(v3s16 p); - MapNode getNodeParent(v3s16 p, bool *is_valid_position = NULL); + bool isValidPositionParent(v3POS p); + MapNode getNodeParent(v3POS p, bool *is_valid_position = NULL); // Copies data to VoxelManipulator to getPosRelative() void copyTo(VoxelManipulator &dst); @@ -432,12 +433,12 @@ class MapBlock //// Node Timers //// - inline NodeTimer getNodeTimer(const v3s16 &p) + inline NodeTimer getNodeTimer(const v3POS &p) { return m_node_timers.get(p); } - inline void removeNodeTimer(const v3s16 &p) + inline void removeNodeTimer(const v3POS &p) { m_node_timers.remove(p); } @@ -485,7 +486,7 @@ class MapBlock return data[z * zstride + y * ystride + x]; } - inline MapNode &getNodeRef(v3s16 &p) + inline MapNode &getNodeRef(v3POS &p) { return getNodeRef(p.X, p.Y, p.Z); } @@ -524,7 +525,7 @@ class MapBlock // NOTE: Lots of things rely on this being the Map Map *m_parent; // Position in blocks on parent - v3s16 m_pos; + v3BPOS m_pos; /* This is the precalculated m_pos_relative value * This caches the value, improving performance by removing 3 s16 multiplications @@ -532,7 +533,7 @@ class MapBlock * For a 5 minutes runtime with valgrind this removes 3 * 19M s16 multiplications * The gain can be estimated in Release Build to 3 * 100M multiply operations for 5 mins */ - v3s16 m_pos_relative; + v3POS m_pos_relative; IGameDef *m_gamedef; @@ -610,9 +611,9 @@ inline bool objectpos_over_limit(v3f p) p.Z > max_limit_bs; } -inline bool blockpos_over_max_limit(v3s16 p) +inline bool blockpos_over_max_limit(v3BPOS p) { - const s16 max_limit_bp = MAX_MAP_GENERATION_LIMIT / MAP_BLOCKSIZE; + const BPOS max_limit_bp = MAX_MAP_GENERATION_LIMIT / MAP_BLOCKSIZE; return p.X < -max_limit_bp || p.X > max_limit_bp || p.Y < -max_limit_bp || @@ -624,12 +625,12 @@ inline bool blockpos_over_max_limit(v3s16 p) /* Returns the position of the block where the node is located */ -inline v3s16 getNodeBlockPos(const v3s16 &p) +inline v3BPOS getNodeBlockPos(const v3POS &p) { return getContainerPos(p, MAP_BLOCKSIZE); } -inline void getNodeBlockPosWithOffset(const v3s16 &p, v3s16 &block, v3s16 &offset) +inline void getNodeBlockPosWithOffset(const v3POS &p, v3BPOS &block, v3POS &offset) { getContainerPosWithOffset(p, MAP_BLOCKSIZE, block, offset); } diff --git a/src/mapgen/cavegen.cpp b/src/mapgen/cavegen.cpp index 340079821d..6dd0b5bde4 100644 --- a/src/mapgen/cavegen.cpp +++ b/src/mapgen/cavegen.cpp @@ -38,7 +38,7 @@ static NoiseParams nparams_caveliquids(0, 1, v3f(150.0, 150.0, 150.0), 776, 3, 0 //// CavesNoiseIntersection::CavesNoiseIntersection( - const NodeDefManager *nodedef, BiomeManager *biomemgr, v3s16 chunksize, + const NodeDefManager *nodedef, BiomeManager *biomemgr, v3POS chunksize, NoiseParams *np_cave1, NoiseParams *np_cave2, s32 seed, float cave_width) { assert(nodedef); @@ -69,7 +69,7 @@ CavesNoiseIntersection::~CavesNoiseIntersection() void CavesNoiseIntersection::generateCaves(MMVManip *vm, - v3s16 nmin, v3s16 nmax, biome_t *biomemap) + v3POS nmin, v3POS nmax, biome_t *biomemap) { assert(vm); assert(biomemap); @@ -77,11 +77,11 @@ void CavesNoiseIntersection::generateCaves(MMVManip *vm, noise_cave1->perlinMap3D(nmin.X, nmin.Y - 1, nmin.Z); noise_cave2->perlinMap3D(nmin.X, nmin.Y - 1, nmin.Z); - const v3s16 &em = vm->m_area.getExtent(); + const v3POS &em = vm->m_area.getExtent(); u32 index2d = 0; // Biomemap index - for (s16 z = nmin.Z; z <= nmax.Z; z++) - for (s16 x = nmin.X; x <= nmax.X; x++, index2d++) { + for (POS z = nmin.Z; z <= nmax.Z; z++) + for (POS x = nmin.X; x <= nmax.X; x++, index2d++) { bool column_is_open = false; // Is column open to overground bool is_under_river = false; // Is column under river water bool is_under_tunnel = false; // Is tunnel or is under tunnel @@ -100,7 +100,7 @@ void CavesNoiseIntersection::generateCaves(MMVManip *vm, // this creates a 'roof' over the tunnel, preventing light in // tunnels at mapchunk borders when generating mapchunks upwards. // This 'roof' is removed when the mapchunk above is generated. - for (s16 y = nmax.Y; y >= nmin.Y - 1; y--, + for (POS y = nmax.Y; y >= nmin.Y - 1; y--, index3d -= m_ystride, VoxelArea::add_y(em, vi, -1)) { content_t c = vm->m_data[vi].getContent(); @@ -176,7 +176,7 @@ void CavesNoiseIntersection::generateCaves(MMVManip *vm, //// CavernsNoise::CavernsNoise( - const NodeDefManager *nodedef, v3s16 chunksize, NoiseParams *np_cavern, + const NodeDefManager *nodedef, v3POS chunksize, NoiseParams *np_cavern, s32 seed, float cavern_limit, float cavern_taper, float cavern_threshold) { assert(nodedef); @@ -212,7 +212,7 @@ CavernsNoise::~CavernsNoise() } -bool CavernsNoise::generateCaverns(MMVManip *vm, v3s16 nmin, v3s16 nmax) +bool CavernsNoise::generateCaverns(MMVManip *vm, v3POS nmin, v3POS nmax) { assert(vm); @@ -222,18 +222,18 @@ bool CavernsNoise::generateCaverns(MMVManip *vm, v3s16 nmin, v3s16 nmax) // Cache cavern_amp values float *cavern_amp = new float[m_csize.Y + 1]; u8 cavern_amp_index = 0; // Index zero at column top - for (s16 y = nmax.Y; y >= nmin.Y - 1; y--, cavern_amp_index++) { + for (POS y = nmax.Y; y >= nmin.Y - 1; y--, cavern_amp_index++) { cavern_amp[cavern_amp_index] = MYMIN((m_cavern_limit - y) / (float)m_cavern_taper, 1.0f); } //// Place nodes bool near_cavern = false; - const v3s16 &em = vm->m_area.getExtent(); + const v3POS &em = vm->m_area.getExtent(); u32 index2d = 0; - for (s16 z = nmin.Z; z <= nmax.Z; z++) - for (s16 x = nmin.X; x <= nmax.X; x++, index2d++) { + for (POS z = nmin.Z; z <= nmax.Z; z++) + for (POS x = nmin.X; x <= nmax.X; x++, index2d++) { // Reset cave_amp index to column top cavern_amp_index = 0; // Initial voxelmanip index at column top @@ -245,7 +245,7 @@ bool CavernsNoise::generateCaverns(MMVManip *vm, v3s16 nmin, v3s16 nmax) // this creates a 'roof' over the cavern, preventing light in // caverns at mapchunk borders when generating mapchunks upwards. // This 'roof' is excavated when the mapchunk above is generated. - for (s16 y = nmax.Y; y >= nmin.Y - 1; y--, + for (POS y = nmax.Y; y >= nmin.Y - 1; y--, index3d -= m_ystride, VoxelArea::add_y(em, vi, -1), cavern_amp_index++) { @@ -307,8 +307,8 @@ CavesRandomWalk::CavesRandomWalk( } -void CavesRandomWalk::makeCave(MMVManip *vm, v3s16 nmin, v3s16 nmax, - PseudoRandom *ps, bool is_large_cave, int max_stone_height, s16 *heightmap) +void CavesRandomWalk::makeCave(MMVManip *vm, v3POS nmin, v3POS nmax, + PseudoRandom *ps, bool is_large_cave, int max_stone_height, POS *heightmap) { assert(vm); assert(ps); @@ -329,7 +329,7 @@ void CavesRandomWalk::makeCave(MMVManip *vm, v3s16 nmin, v3s16 nmax, // If defined liquid is "air", disable 'flooded' to avoid placing "air". use_biome_liquid = false; if (flooded && bmgn) { - v3s16 midp = node_min + (node_max - node_min) / v3s16(2, 2, 2); + v3POS midp = node_min + (node_max - node_min) / v3POS(2, 2, 2); Biome *biome = (Biome *)bmgn->getBiomeAtPoint(midp); if (biome->c_cave_liquid[0] != CONTENT_IGNORE) { use_biome_liquid = true; @@ -360,7 +360,7 @@ void CavesRandomWalk::makeCave(MMVManip *vm, v3s16 nmin, v3s16 nmax, main_direction = v3f(0, 0, 0); // Allowed route area size in nodes - ar = node_max - node_min + v3s16(1, 1, 1); + ar = node_max - node_min + v3POS(1, 1, 1); // Area starting point in nodes of = node_min; @@ -369,8 +369,8 @@ void CavesRandomWalk::makeCave(MMVManip *vm, v3s16 nmin, v3s16 nmax, // 'insure' is needed to avoid many 'out of voxelmanip' cave nodes. const s16 insure = 2; s16 more = MYMAX(MAP_BLOCKSIZE - max_tunnel_diameter / 2 - insure, 1); - ar += v3s16(1, 1, 1) * more * 2; - of -= v3s16(1, 1, 1) * more; + ar += v3POS(1, 1, 1) * more * 2; + of -= v3POS(1, 1, 1) * more; route_y_min = 0; // Allow half a diameter + 7 over stone surface @@ -380,7 +380,7 @@ void CavesRandomWalk::makeCave(MMVManip *vm, v3s16 nmin, v3s16 nmax, route_y_max = rangelim(route_y_max, 0, ar.Y - 1); if (large_cave) { - s16 minpos = 0; + POS minpos = 0; if (node_min.Y < water_level && node_max.Y > water_level) { minpos = water_level - max_tunnel_diameter / 3 - of.Y; route_y_max = water_level + max_tunnel_diameter / 3 - of.Y; @@ -389,8 +389,8 @@ void CavesRandomWalk::makeCave(MMVManip *vm, v3s16 nmin, v3s16 nmax, route_y_min = rangelim(route_y_min, 0, route_y_max); } - s16 route_start_y_min = route_y_min; - s16 route_start_y_max = route_y_max; + POS route_start_y_min = route_y_min; + POS route_start_y_max = route_y_max; route_start_y_min = rangelim(route_start_y_min, 0, ar.Y - 1); route_start_y_max = rangelim(route_start_y_max, route_start_y_min, ar.Y - 1); @@ -402,7 +402,7 @@ void CavesRandomWalk::makeCave(MMVManip *vm, v3s16 nmin, v3s16 nmax, // Add generation notify begin event if (gennotify) { - v3s16 abs_pos(of.X + orp.X, of.Y + orp.Y, of.Z + orp.Z); + v3POS abs_pos(of.X + orp.X, of.Y + orp.Y, of.Z + orp.Z); GenNotifyType notifytype = large_cave ? GENNOTIFY_LARGECAVE_BEGIN : GENNOTIFY_CAVE_BEGIN; gennotify->addEvent(notifytype, abs_pos); @@ -414,7 +414,7 @@ void CavesRandomWalk::makeCave(MMVManip *vm, v3s16 nmin, v3s16 nmax, // Add generation notify end event if (gennotify) { - v3s16 abs_pos(of.X + orp.X, of.Y + orp.Y, of.Z + orp.Z); + v3POS abs_pos(of.X + orp.X, of.Y + orp.Y, of.Z + orp.Z); GenNotifyType notifytype = large_cave ? GENNOTIFY_LARGECAVE_END : GENNOTIFY_CAVE_END; gennotify->addEvent(notifytype, abs_pos); @@ -438,15 +438,15 @@ void CavesRandomWalk::makeTunnel(bool dirswitch) rs = ps->range(min_d, max_d); s16 rs_part_max_length_rs = rs * part_max_length_rs; - v3s16 maxlen; + v3POS maxlen; if (large_cave) { - maxlen = v3s16( + maxlen = v3POS( rs_part_max_length_rs, rs_part_max_length_rs / 2, rs_part_max_length_rs ); } else { - maxlen = v3s16( + maxlen = v3POS( rs_part_max_length_rs, ps->range(1, rs_part_max_length_rs), rs_part_max_length_rs @@ -467,8 +467,8 @@ void CavesRandomWalk::makeTunnel(bool dirswitch) // Do not make caves that are above ground. // It is only necessary to check the startpoint and endpoint. - v3s16 p1 = v3s16(orp.X, orp.Y, orp.Z) + of + rs / 2; - v3s16 p2 = v3s16(vec.X, vec.Y, vec.Z) + p1; + v3POS p1 = v3POS(orp.X, orp.Y, orp.Z) + of + rs / 2; + v3POS p2 = v3POS(vec.X, vec.Y, vec.Z) + p1; if (isPosAboveSurface(p1) || isPosAboveSurface(p2)) return; @@ -513,13 +513,13 @@ void CavesRandomWalk::carveRoute(v3f vec, float f, bool randomize_xz) MapNode waternode(c_water_source); MapNode lavanode(c_lava_source); - v3s16 startp(orp.X, orp.Y, orp.Z); + v3POS startp(orp.X, orp.Y, orp.Z); startp += of; v3f fp = orp + vec * f; fp.X += 0.1f * ps->range(-10, 10); fp.Z += 0.1f * ps->range(-10, 10); - v3s16 cp(fp.X, fp.Y, fp.Z); + v3POS cp(fp.X, fp.Y, fp.Z); // Choose cave liquid MapNode liquidnode = CONTENT_IGNORE; @@ -565,7 +565,7 @@ void CavesRandomWalk::carveRoute(v3f vec, float f, bool randomize_xz) continue; } - v3s16 p(cp.X + x0, cp.Y + y0, cp.Z + z0); + v3POS p(cp.X + x0, cp.Y + y0, cp.Z + z0); p += of; if (!vm->m_area.contains(p)) @@ -596,7 +596,7 @@ void CavesRandomWalk::carveRoute(v3f vec, float f, bool randomize_xz) } -inline bool CavesRandomWalk::isPosAboveSurface(v3s16 p) +inline bool CavesRandomWalk::isPosAboveSurface(v3POS p) { if (heightmap != NULL && p.Z >= node_min.Z && p.Z <= node_max.Z && @@ -639,9 +639,9 @@ CavesV6::CavesV6(const NodeDefManager *ndef, GenerateNotifier *gennotify, } -void CavesV6::makeCave(MMVManip *vm, v3s16 nmin, v3s16 nmax, +void CavesV6::makeCave(MMVManip *vm, v3POS nmin, v3POS nmax, PseudoRandom *ps, PseudoRandom *ps2, - bool is_large_cave, int max_stone_height, s16 *heightmap) + bool is_large_cave, int max_stone_height, POS *heightmap) { assert(vm); assert(ps); @@ -675,7 +675,7 @@ void CavesV6::makeCave(MMVManip *vm, v3s16 nmin, v3s16 nmax, main_direction = v3f(0, 0, 0); // Allowed route area size in nodes - ar = node_max - node_min + v3s16(1, 1, 1); + ar = node_max - node_min + v3POS(1, 1, 1); // Area starting point in nodes of = node_min; @@ -684,8 +684,8 @@ void CavesV6::makeCave(MMVManip *vm, v3s16 nmin, v3s16 nmax, const s16 max_spread_amount = MAP_BLOCKSIZE; const s16 insure = 10; s16 more = MYMAX(max_spread_amount - max_tunnel_diameter / 2 - insure, 1); - ar += v3s16(1, 0, 1) * more * 2; - of -= v3s16(1, 0, 1) * more; + ar += v3POS(1, 0, 1) * more * 2; + of -= v3POS(1, 0, 1) * more; route_y_min = 0; // Allow half a diameter + 7 over stone surface @@ -704,8 +704,8 @@ void CavesV6::makeCave(MMVManip *vm, v3s16 nmin, v3s16 nmax, route_y_min = rangelim(route_y_min, 0, route_y_max); } - s16 route_start_y_min = route_y_min; - s16 route_start_y_max = route_y_max; + POS route_start_y_min = route_y_min; + POS route_start_y_max = route_y_max; route_start_y_min = rangelim(route_start_y_min, 0, ar.Y - 1); route_start_y_max = rangelim(route_start_y_max, route_start_y_min, ar.Y - 1); @@ -717,7 +717,7 @@ void CavesV6::makeCave(MMVManip *vm, v3s16 nmin, v3s16 nmax, // Add generation notify begin event if (gennotify != NULL) { - v3s16 abs_pos(of.X + orp.X, of.Y + orp.Y, of.Z + orp.Z); + v3POS abs_pos(of.X + orp.X, of.Y + orp.Y, of.Z + orp.Z); GenNotifyType notifytype = large_cave ? GENNOTIFY_LARGECAVE_BEGIN : GENNOTIFY_CAVE_BEGIN; gennotify->addEvent(notifytype, abs_pos); @@ -729,7 +729,7 @@ void CavesV6::makeCave(MMVManip *vm, v3s16 nmin, v3s16 nmax, // Add generation notify end event if (gennotify != NULL) { - v3s16 abs_pos(of.X + orp.X, of.Y + orp.Y, of.Z + orp.Z); + v3POS abs_pos(of.X + orp.X, of.Y + orp.Y, of.Z + orp.Z); GenNotifyType notifytype = large_cave ? GENNOTIFY_LARGECAVE_END : GENNOTIFY_CAVE_END; gennotify->addEvent(notifytype, abs_pos); @@ -753,15 +753,15 @@ void CavesV6::makeTunnel(bool dirswitch) rs = ps->range(min_d, max_d); s16 rs_part_max_length_rs = rs * part_max_length_rs; - v3s16 maxlen; + v3POS maxlen; if (large_cave) { - maxlen = v3s16( + maxlen = v3POS( rs_part_max_length_rs, rs_part_max_length_rs / 2, rs_part_max_length_rs ); } else { - maxlen = v3s16( + maxlen = v3POS( rs_part_max_length_rs, ps->range(1, rs_part_max_length_rs), rs_part_max_length_rs @@ -783,8 +783,8 @@ void CavesV6::makeTunnel(bool dirswitch) // Do not make caves that are entirely above ground, to fix shadow bugs // caused by overgenerated large caves. // It is only necessary to check the startpoint and endpoint. - v3s16 p1 = v3s16(orp.X, orp.Y, orp.Z) + of + rs / 2; - v3s16 p2 = v3s16(vec.X, vec.Y, vec.Z) + p1; + v3POS p1 = v3POS(orp.X, orp.Y, orp.Z) + of + rs / 2; + v3POS p2 = v3POS(vec.X, vec.Y, vec.Z) + p1; // If startpoint and endpoint are above ground, disable placement of nodes // in carveRoute while still running all PseudoRandom calls to ensure caves @@ -836,13 +836,13 @@ void CavesV6::carveRoute(v3f vec, float f, bool randomize_xz, MapNode waternode(c_water_source); MapNode lavanode(c_lava_source); - v3s16 startp(orp.X, orp.Y, orp.Z); + v3POS startp(orp.X, orp.Y, orp.Z); startp += of; v3f fp = orp + vec * f; fp.X += 0.1f * ps->range(-10, 10); fp.Z += 0.1f * ps->range(-10, 10); - v3s16 cp(fp.X, fp.Y, fp.Z); + v3POS cp(fp.X, fp.Y, fp.Z); s16 d0 = -rs / 2; s16 d1 = d0 + rs; @@ -866,7 +866,7 @@ void CavesV6::carveRoute(v3f vec, float f, bool randomize_xz, continue; } - v3s16 p(cp.X + x0, cp.Y + y0, cp.Z + z0); + v3POS p(cp.X + x0, cp.Y + y0, cp.Z + z0); p += of; if (!vm->m_area.contains(p)) @@ -901,7 +901,7 @@ void CavesV6::carveRoute(v3f vec, float f, bool randomize_xz, } -inline s16 CavesV6::getSurfaceFromHeightmap(v3s16 p) +inline POS CavesV6::getSurfaceFromHeightmap(v3POS p) { if (heightmap != NULL && p.Z >= node_min.Z && p.Z <= node_max.Z && diff --git a/src/mapgen/cavegen.h b/src/mapgen/cavegen.h index d678d365bc..45d145e41b 100644 --- a/src/mapgen/cavegen.h +++ b/src/mapgen/cavegen.h @@ -42,18 +42,18 @@ class CavesNoiseIntersection { public: CavesNoiseIntersection(const NodeDefManager *nodedef, - BiomeManager *biomemgr, v3s16 chunksize, NoiseParams *np_cave1, + BiomeManager *biomemgr, v3POS chunksize, NoiseParams *np_cave1, NoiseParams *np_cave2, s32 seed, float cave_width); ~CavesNoiseIntersection(); - void generateCaves(MMVManip *vm, v3s16 nmin, v3s16 nmax, biome_t *biomemap); + void generateCaves(MMVManip *vm, v3POS nmin, v3POS nmax, biome_t *biomemap); private: const NodeDefManager *m_ndef; BiomeManager *m_bmgr; // configurable parameters - v3s16 m_csize; + v3POS m_csize; float m_cave_width; // intermediate state variables @@ -70,18 +70,18 @@ class CavesNoiseIntersection class CavernsNoise { public: - CavernsNoise(const NodeDefManager *nodedef, v3s16 chunksize, + CavernsNoise(const NodeDefManager *nodedef, v3POS chunksize, NoiseParams *np_cavern, s32 seed, float cavern_limit, float cavern_taper, float cavern_threshold); ~CavernsNoise(); - bool generateCaverns(MMVManip *vm, v3s16 nmin, v3s16 nmax); + bool generateCaverns(MMVManip *vm, v3POS nmin, v3POS nmax); private: const NodeDefManager *m_ndef; // configurable parameters - v3s16 m_csize; + v3POS m_csize; float m_cavern_limit; float m_cavern_taper; float m_cavern_threshold; @@ -115,7 +115,7 @@ class CavesRandomWalk MMVManip *vm; const NodeDefManager *ndef; GenerateNotifier *gennotify; - s16 *heightmap; + POS *heightmap; BiomeGen *bmgn; s32 seed; @@ -137,17 +137,17 @@ class CavesRandomWalk bool flooded; bool use_biome_liquid; - v3s16 node_min; - v3s16 node_max; + v3POS node_min; + v3POS node_max; v3f orp; // starting point, relative to caved space - v3s16 of; // absolute coordinates of caved space - v3s16 ar; // allowed route area + v3POS of; // absolute coordinates of caved space + v3POS ar; // allowed route area s16 rs; // tunnel radius size v3f main_direction; - s16 route_y_min; - s16 route_y_max; + POS route_y_min; + POS route_y_max; PseudoRandom *ps; @@ -166,14 +166,14 @@ class CavesRandomWalk // vm and ps are mandatory parameters. // If heightmap is NULL, the surface level at all points is assumed to // be water_level. - void makeCave(MMVManip *vm, v3s16 nmin, v3s16 nmax, PseudoRandom *ps, - bool is_large_cave, int max_stone_height, s16 *heightmap); + void makeCave(MMVManip *vm, v3POS nmin, v3POS nmax, PseudoRandom *ps, + bool is_large_cave, int max_stone_height, POS *heightmap); private: void makeTunnel(bool dirswitch); void carveRoute(v3f vec, float f, bool randomize_xz); - inline bool isPosAboveSurface(v3s16 p); + inline bool isPosAboveSurface(v3POS p); }; /* @@ -199,7 +199,7 @@ class CavesV6 PseudoRandom *ps2; // configurable parameters - s16 *heightmap; + POS *heightmap; content_t c_water_source; content_t c_lava_source; int water_level; @@ -215,12 +215,12 @@ class CavesV6 bool large_cave; bool large_cave_is_flat; - v3s16 node_min; - v3s16 node_max; + v3POS node_min; + v3POS node_max; v3f orp; // starting point, relative to caved space - v3s16 of; // absolute coordinates of caved space - v3s16 ar; // allowed route area + v3POS of; // absolute coordinates of caved space + v3POS ar; // allowed route area s16 rs; // tunnel radius size v3f main_direction; @@ -236,13 +236,13 @@ class CavesV6 // vm, ps, and ps2 are mandatory parameters. // If heightmap is NULL, the surface level at all points is assumed to // be water_level. - void makeCave(MMVManip *vm, v3s16 nmin, v3s16 nmax, PseudoRandom *ps, + void makeCave(MMVManip *vm, v3POS nmin, v3POS nmax, PseudoRandom *ps, PseudoRandom *ps2, bool is_large_cave, int max_stone_height, - s16 *heightmap = NULL); + POS *heightmap = NULL); private: void makeTunnel(bool dirswitch); void carveRoute(v3f vec, float f, bool randomize_xz, bool tunnel_above_ground); - inline s16 getSurfaceFromHeightmap(v3s16 p); + inline POS getSurfaceFromHeightmap(v3POS p); }; diff --git a/src/mapgen/dungeongen.cpp b/src/mapgen/dungeongen.cpp index acdb1a0f0f..8a53e73fba 100644 --- a/src/mapgen/dungeongen.cpp +++ b/src/mapgen/dungeongen.cpp @@ -59,13 +59,13 @@ DungeonGen::DungeonGen(const NodeDefManager *ndef, dp.diagonal_dirs = false; dp.only_in_ground = true; - dp.holesize = v3s16(1, 2, 1); + dp.holesize = v3POS(1, 2, 1); dp.corridor_len_min = 1; dp.corridor_len_max = 13; - dp.room_size_min = v3s16(4, 4, 4); - dp.room_size_max = v3s16(8, 6, 8); - dp.room_size_large_min = v3s16(8, 8, 8); - dp.room_size_large_max = v3s16(16, 16, 16); + dp.room_size_min = v3POS(4, 4, 4); + dp.room_size_max = v3POS(8, 6, 8); + dp.room_size_large_min = v3POS(8, 8, 8); + dp.room_size_large_max = v3POS(16, 16, 16); dp.large_room_chance = 1; dp.num_rooms = 8; dp.num_dungeons = 1; @@ -77,7 +77,7 @@ DungeonGen::DungeonGen(const NodeDefManager *ndef, } -void DungeonGen::generate(MMVManip *vm, u32 bseed, v3s16 nmin, v3s16 nmax) +void DungeonGen::generate(MMVManip *vm, u32 bseed, v3POS nmin, v3POS nmax) { if (dp.num_dungeons == 0) return; @@ -101,10 +101,10 @@ void DungeonGen::generate(MMVManip *vm, u32 bseed, v3s16 nmin, v3s16 nmax) // Like randomwalk caves, preserve nodes that have 'is_ground_content = false', // to avoid dungeons that generate out beyond the edge of a mapchunk destroying // nodes added by mods in 'register_on_generated()'. - for (s16 z = nmin.Z; z <= nmax.Z; z++) { - for (s16 y = nmin.Y; y <= nmax.Y; y++) { + for (POS z = nmin.Z; z <= nmax.Z; z++) { + for (POS y = nmin.Y; y <= nmax.Y; y++) { u32 i = vm->m_area.index(nmin.X, y, z); - for (s16 x = nmin.X; x <= nmax.X; x++) { + for (POS x = nmin.X; x <= nmax.X; x++) { content_t c = vm->m_data[i].getContent(); NodeDrawType dtype = ndef->get(c).drawtype; if (dtype == NDT_AIRLIKE || dtype == NDT_LIQUID || @@ -118,16 +118,16 @@ void DungeonGen::generate(MMVManip *vm, u32 bseed, v3s16 nmin, v3s16 nmax) // Add them for (u32 i = 0; i < dp.num_dungeons; i++) - makeDungeon(v3s16(1, 1, 1) * MAP_BLOCKSIZE); + makeDungeon(v3POS(1, 1, 1) * MAP_BLOCKSIZE); // Optionally convert some structure to alternative structure if (dp.c_alt_wall == CONTENT_IGNORE) return; - for (s16 z = nmin.Z; z <= nmax.Z; z++) - for (s16 y = nmin.Y; y <= nmax.Y; y++) { + for (POS z = nmin.Z; z <= nmax.Z; z++) + for (POS y = nmin.Y; y <= nmax.Y; y++) { u32 i = vm->m_area.index(nmin.X, y, z); - for (s16 x = nmin.X; x <= nmax.X; x++) { + for (POS x = nmin.X; x <= nmax.X; x++) { if (vm->m_data[i].getContent() == dp.c_wall) { if (NoisePerlin3D(&dp.np_alt_wall, x, y, z, blockseed) > 0.0f) vm->m_data[i].setContent(dp.c_alt_wall); @@ -140,11 +140,11 @@ void DungeonGen::generate(MMVManip *vm, u32 bseed, v3s16 nmin, v3s16 nmax) } -void DungeonGen::makeDungeon(v3s16 start_padding) +void DungeonGen::makeDungeon(v3POS start_padding) { - const v3s16 &areasize = vm->m_area.getExtent(); - v3s16 roomsize; - v3s16 roomplace; + const v3POS &areasize = vm->m_area.getExtent(); + v3POS roomsize; + v3POS roomplace; /* Find place for first room. @@ -176,7 +176,7 @@ void DungeonGen::makeDungeon(v3s16 start_padding) for (s16 z = 0; z < roomsize.Z; z++) for (s16 y = 0; y < roomsize.Y; y++) for (s16 x = 0; x < roomsize.X; x++) { - v3s16 p = roomplace + v3s16(x, y, z); + v3POS p = roomplace + v3POS(x, y, z); u32 vi = vm->m_area.index(p); if ((vm->m_flags[vi] & VMANIP_FLAG_DUNGEON_UNTOUCHABLE) || vm->m_data[vi].getContent() == CONTENT_IGNORE) { @@ -194,13 +194,13 @@ void DungeonGen::makeDungeon(v3s16 start_padding) a new corridor can be started from the last room instead of the new room, if chosen so. */ - v3s16 last_room_center = roomplace + v3s16(roomsize.X / 2, 1, roomsize.Z / 2); + v3POS last_room_center = roomplace + v3POS(roomsize.X / 2, 1, roomsize.Z / 2); for (u32 i = 0; i < dp.num_rooms; i++) { // Make a room to the determined place makeRoom(roomsize, roomplace); - v3s16 room_center = roomplace + v3s16(roomsize.X / 2, 1, roomsize.Z / 2); + v3POS room_center = roomplace + v3POS(roomsize.X / 2, 1, roomsize.Z / 2); if (gennotify) gennotify->addEvent(dp.notifytype, room_center); @@ -217,7 +217,7 @@ void DungeonGen::makeDungeon(v3s16 start_padding) bool start_in_last_room = (random.range(0, 2) != 0); - v3s16 walker_start_place; + v3POS walker_start_place; if (start_in_last_room) { walker_start_place = last_room_center; @@ -228,8 +228,8 @@ void DungeonGen::makeDungeon(v3s16 start_padding) } // Create walker and find a place for a door - v3s16 doorplace; - v3s16 doordir; + v3POS doorplace; + v3POS doordir; m_pos = walker_start_place; if (!findPlaceForDoor(doorplace, doordir)) @@ -243,8 +243,8 @@ void DungeonGen::makeDungeon(v3s16 start_padding) doorplace -= doordir; // Make a random corridor starting from the door - v3s16 corridor_end; - v3s16 corridor_end_dir; + v3POS corridor_end; + v3POS corridor_end_dir; makeCorridor(doorplace, doordir, corridor_end, corridor_end_dir); // Find a place for a random sized room @@ -274,7 +274,7 @@ void DungeonGen::makeDungeon(v3s16 start_padding) } -void DungeonGen::makeRoom(v3s16 roomsize, v3s16 roomplace) +void DungeonGen::makeRoom(v3POS roomsize, v3POS roomplace) { MapNode n_wall(dp.c_wall); MapNode n_air(CONTENT_AIR); @@ -283,7 +283,7 @@ void DungeonGen::makeRoom(v3s16 roomsize, v3s16 roomplace) for (s16 z = 0; z < roomsize.Z; z++) for (s16 y = 0; y < roomsize.Y; y++) { { - v3s16 p = roomplace + v3s16(0, y, z); + v3POS p = roomplace + v3POS(0, y, z); if (!vm->m_area.contains(p)) continue; u32 vi = vm->m_area.index(p); @@ -292,7 +292,7 @@ void DungeonGen::makeRoom(v3s16 roomsize, v3s16 roomplace) vm->m_data[vi] = n_wall; } { - v3s16 p = roomplace + v3s16(roomsize.X - 1, y, z); + v3POS p = roomplace + v3POS(roomsize.X - 1, y, z); if (!vm->m_area.contains(p)) continue; u32 vi = vm->m_area.index(p); @@ -306,7 +306,7 @@ void DungeonGen::makeRoom(v3s16 roomsize, v3s16 roomplace) for (s16 x = 0; x < roomsize.X; x++) for (s16 y = 0; y < roomsize.Y; y++) { { - v3s16 p = roomplace + v3s16(x, y, 0); + v3POS p = roomplace + v3POS(x, y, 0); if (!vm->m_area.contains(p)) continue; u32 vi = vm->m_area.index(p); @@ -315,7 +315,7 @@ void DungeonGen::makeRoom(v3s16 roomsize, v3s16 roomplace) vm->m_data[vi] = n_wall; } { - v3s16 p = roomplace + v3s16(x, y, roomsize.Z - 1); + v3POS p = roomplace + v3POS(x, y, roomsize.Z - 1); if (!vm->m_area.contains(p)) continue; u32 vi = vm->m_area.index(p); @@ -329,7 +329,7 @@ void DungeonGen::makeRoom(v3s16 roomsize, v3s16 roomplace) for (s16 z = 0; z < roomsize.Z; z++) for (s16 x = 0; x < roomsize.X; x++) { { - v3s16 p = roomplace + v3s16(x, 0, z); + v3POS p = roomplace + v3POS(x, 0, z); if (!vm->m_area.contains(p)) continue; u32 vi = vm->m_area.index(p); @@ -338,7 +338,7 @@ void DungeonGen::makeRoom(v3s16 roomsize, v3s16 roomplace) vm->m_data[vi] = n_wall; } { - v3s16 p = roomplace + v3s16(x,roomsize. Y - 1, z); + v3POS p = roomplace + v3POS(x,roomsize. Y - 1, z); if (!vm->m_area.contains(p)) continue; u32 vi = vm->m_area.index(p); @@ -352,7 +352,7 @@ void DungeonGen::makeRoom(v3s16 roomsize, v3s16 roomplace) for (s16 z = 1; z < roomsize.Z - 1; z++) for (s16 y = 1; y < roomsize.Y - 1; y++) for (s16 x = 1; x < roomsize.X - 1; x++) { - v3s16 p = roomplace + v3s16(x, y, z); + v3POS p = roomplace + v3POS(x, y, z); if (!vm->m_area.contains(p)) continue; u32 vi = vm->m_area.index(p); @@ -362,13 +362,13 @@ void DungeonGen::makeRoom(v3s16 roomsize, v3s16 roomplace) } -void DungeonGen::makeFill(v3s16 place, v3s16 size, +void DungeonGen::makeFill(v3POS place, v3POS size, u8 avoid_flags, MapNode n, u8 or_flags) { - for (s16 z = 0; z < size.Z; z++) - for (s16 y = 0; y < size.Y; y++) - for (s16 x = 0; x < size.X; x++) { - v3s16 p = place + v3s16(x, y, z); + for (POS z = 0; z < size.Z; z++) + for (POS y = 0; y < size.Y; y++) + for (POS x = 0; x < size.X; x++) { + v3POS p = place + v3POS(x, y, z); if (!vm->m_area.contains(p)) continue; u32 vi = vm->m_area.index(p); @@ -380,14 +380,14 @@ void DungeonGen::makeFill(v3s16 place, v3s16 size, } -void DungeonGen::makeHole(v3s16 place) +void DungeonGen::makeHole(v3POS place) { makeFill(place, dp.holesize, 0, MapNode(CONTENT_AIR), VMANIP_FLAG_DUNGEON_INSIDE); } -void DungeonGen::makeDoor(v3s16 doorplace, v3s16 doordir) +void DungeonGen::makeDoor(v3POS doorplace, v3POS doordir) { makeHole(doorplace); @@ -398,12 +398,12 @@ void DungeonGen::makeDoor(v3s16 doorplace, v3s16 doordir) } -void DungeonGen::makeCorridor(v3s16 doorplace, v3s16 doordir, - v3s16 &result_place, v3s16 &result_dir) +void DungeonGen::makeCorridor(v3POS doorplace, v3POS doordir, + v3POS &result_place, v3POS &result_dir) { makeHole(doorplace); - v3s16 p0 = doorplace; - v3s16 dir = doordir; + v3POS p0 = doorplace; + v3POS dir = doordir; u32 length = random.range(dp.corridor_len_min, dp.corridor_len_max); u32 partlength = random.range(dp.corridor_len_min, dp.corridor_len_max); u32 partcount = 0; @@ -413,15 +413,15 @@ void DungeonGen::makeCorridor(v3s16 doorplace, v3s16 doordir, make_stairs = random.next() % 2 ? 1 : -1; for (u32 i = 0; i < length; i++) { - v3s16 p = p0 + dir; + v3POS p = p0 + dir; if (partcount != 0) p.Y += make_stairs; // Check segment of minimum size corridor is in voxelmanip - if (vm->m_area.contains(p) && vm->m_area.contains(p + v3s16(0, 1, 0))) { + if (vm->m_area.contains(p) && vm->m_area.contains(p + v3POS(0, 1, 0))) { if (make_stairs) { - makeFill(p + v3s16(-1, -1, -1), - dp.holesize + v3s16(2, 3, 2), + makeFill(p + v3POS(-1, -1, -1), + dp.holesize + v3POS(2, 3, 2), VMANIP_FLAG_DUNGEON_UNTOUCHABLE, MapNode(dp.c_wall), 0); @@ -441,22 +441,22 @@ void DungeonGen::makeCorridor(v3s16 doorplace, v3s16 doordir, // rotate face 180 deg if // making stairs backwards int facedir = dir_to_facedir(dir * make_stairs); - v3s16 ps = p; + v3POS ps = p; u16 stair_width = (dir.Z != 0) ? dp.holesize.X : dp.holesize.Z; // Stair width direction vector - v3s16 swv = (dir.Z != 0) ? v3s16(1, 0, 0) : v3s16(0, 0, 1); + v3POS swv = (dir.Z != 0) ? v3POS(1, 0, 0) : v3POS(0, 0, 1); for (u16 st = 0; st < stair_width; st++) { if (make_stairs == -1) { u32 vi = vm->m_area.index(ps.X - dir.X, ps.Y - 1, ps.Z - dir.Z); - if (vm->m_area.contains(ps + v3s16(-dir.X, -1, -dir.Z)) && + if (vm->m_area.contains(ps + v3POS(-dir.X, -1, -dir.Z)) && vm->m_data[vi].getContent() == dp.c_wall) { vm->m_flags[vi] |= VMANIP_FLAG_DUNGEON_UNTOUCHABLE; vm->m_data[vi] = MapNode(dp.c_stair, 0, facedir); } } else if (make_stairs == 1) { u32 vi = vm->m_area.index(ps.X, ps.Y - 1, ps.Z); - if (vm->m_area.contains(ps + v3s16(0, -1, 0)) && + if (vm->m_area.contains(ps + v3POS(0, -1, 0)) && vm->m_data[vi].getContent() == dp.c_wall) { vm->m_flags[vi] |= VMANIP_FLAG_DUNGEON_UNTOUCHABLE; vm->m_data[vi] = MapNode(dp.c_stair, 0, facedir); @@ -466,8 +466,8 @@ void DungeonGen::makeCorridor(v3s16 doorplace, v3s16 doordir, } } } else { - makeFill(p + v3s16(-1, -1, -1), - dp.holesize + v3s16(2, 2, 2), + makeFill(p + v3POS(-1, -1, -1), + dp.holesize + v3POS(2, 2, 2), VMANIP_FLAG_DUNGEON_UNTOUCHABLE, MapNode(dp.c_wall), 0); @@ -502,11 +502,11 @@ void DungeonGen::makeCorridor(v3s16 doorplace, v3s16 doordir, } -bool DungeonGen::findPlaceForDoor(v3s16 &result_place, v3s16 &result_dir) +bool DungeonGen::findPlaceForDoor(v3POS &result_place, v3POS &result_dir) { for (u32 i = 0; i < 100; i++) { - v3s16 p = m_pos + m_dir; - v3s16 p1 = p + v3s16(0, 1, 0); + v3POS p = m_pos + m_dir; + v3POS p1 = p + v3POS(0, 1, 0); if (!vm->m_area.contains(p) || !vm->m_area.contains(p1) || i % 4 == 0) { randomizeDir(); continue; @@ -525,24 +525,24 @@ bool DungeonGen::findPlaceForDoor(v3s16 &result_place, v3s16 &result_dir) */ // Jump one up if the actual space is there if (vm->getNodeNoExNoEmerge(p + - v3s16(0, 0, 0)).getContent() == dp.c_wall && + v3POS(0, 0, 0)).getContent() == dp.c_wall && vm->getNodeNoExNoEmerge(p + - v3s16(0, 1, 0)).getContent() == CONTENT_AIR && + v3POS(0, 1, 0)).getContent() == CONTENT_AIR && vm->getNodeNoExNoEmerge(p + - v3s16(0, 2, 0)).getContent() == CONTENT_AIR) - p += v3s16(0,1,0); + v3POS(0, 2, 0)).getContent() == CONTENT_AIR) + p += v3POS(0,1,0); // Jump one down if the actual space is there if (vm->getNodeNoExNoEmerge(p + - v3s16(0, 1, 0)).getContent() == dp.c_wall && + v3POS(0, 1, 0)).getContent() == dp.c_wall && vm->getNodeNoExNoEmerge(p + - v3s16(0, 0, 0)).getContent() == CONTENT_AIR && + v3POS(0, 0, 0)).getContent() == CONTENT_AIR && vm->getNodeNoExNoEmerge(p + - v3s16(0, -1, 0)).getContent() == CONTENT_AIR) - p += v3s16(0, -1, 0); + v3POS(0, -1, 0)).getContent() == CONTENT_AIR) + p += v3POS(0, -1, 0); // Check if walking is now possible if (vm->getNodeNoExNoEmerge(p).getContent() != CONTENT_AIR || vm->getNodeNoExNoEmerge(p + - v3s16(0, 1, 0)).getContent() != CONTENT_AIR) { + v3POS(0, 1, 0)).getContent() != CONTENT_AIR) { // Cannot continue walking here randomizeDir(); continue; @@ -554,36 +554,36 @@ bool DungeonGen::findPlaceForDoor(v3s16 &result_place, v3s16 &result_dir) } -bool DungeonGen::findPlaceForRoomDoor(v3s16 roomsize, v3s16 &result_doorplace, - v3s16 &result_doordir, v3s16 &result_roomplace) +bool DungeonGen::findPlaceForRoomDoor(v3POS roomsize, v3POS &result_doorplace, + v3POS &result_doordir, v3POS &result_roomplace) { for (s16 trycount = 0; trycount < 30; trycount++) { - v3s16 doorplace; - v3s16 doordir; + v3POS doorplace; + v3POS doordir; bool r = findPlaceForDoor(doorplace, doordir); if (!r) continue; - v3s16 roomplace; + v3POS roomplace; // X east, Z north, Y up - if (doordir == v3s16(1, 0, 0)) // X+ + if (doordir == v3POS(1, 0, 0)) // X+ roomplace = doorplace + - v3s16(0, -1, random.range(-roomsize.Z + 2, -2)); - if (doordir == v3s16(-1, 0, 0)) // X- + v3POS(0, -1, random.range(-roomsize.Z + 2, -2)); + if (doordir == v3POS(-1, 0, 0)) // X- roomplace = doorplace + - v3s16(-roomsize.X + 1, -1, random.range(-roomsize.Z + 2, -2)); - if (doordir == v3s16(0, 0, 1)) // Z+ + v3POS(-roomsize.X + 1, -1, random.range(-roomsize.Z + 2, -2)); + if (doordir == v3POS(0, 0, 1)) // Z+ roomplace = doorplace + - v3s16(random.range(-roomsize.X + 2, -2), -1, 0); - if (doordir == v3s16(0, 0, -1)) // Z- + v3POS(random.range(-roomsize.X + 2, -2), -1, 0); + if (doordir == v3POS(0, 0, -1)) // Z- roomplace = doorplace + - v3s16(random.range(-roomsize.X + 2, -2), -1, -roomsize.Z + 1); + v3POS(random.range(-roomsize.X + 2, -2), -1, -roomsize.Z + 1); // Check fit bool fits = true; for (s16 z = 1; z < roomsize.Z - 1; z++) for (s16 y = 1; y < roomsize.Y - 1; y++) for (s16 x = 1; x < roomsize.X - 1; x++) { - v3s16 p = roomplace + v3s16(x, y, z); + v3POS p = roomplace + v3POS(x, y, z); if (!vm->m_area.contains(p)) { fits = false; break; @@ -606,11 +606,11 @@ bool DungeonGen::findPlaceForRoomDoor(v3s16 roomsize, v3s16 &result_doorplace, } -v3s16 rand_ortho_dir(PseudoRandom &random, bool diagonal_dirs) +v3POS rand_ortho_dir(PseudoRandom &random, bool diagonal_dirs) { // Make diagonal directions somewhat rare if (diagonal_dirs && (random.next() % 4 == 0)) { - v3s16 dir; + v3POS dir; int trycount = 0; do { @@ -625,15 +625,15 @@ v3s16 rand_ortho_dir(PseudoRandom &random, bool diagonal_dirs) } if (random.next() % 2 == 0) - return random.next() % 2 ? v3s16(-1, 0, 0) : v3s16(1, 0, 0); + return random.next() % 2 ? v3POS(-1, 0, 0) : v3POS(1, 0, 0); - return random.next() % 2 ? v3s16(0, 0, -1) : v3s16(0, 0, 1); + return random.next() % 2 ? v3POS(0, 0, -1) : v3POS(0, 0, 1); } -v3s16 turn_xz(v3s16 olddir, int t) +v3POS turn_xz(v3POS olddir, int t) { - v3s16 dir; + v3POS dir; if (t == 0) { // Turn right dir.X = olddir.Z; @@ -649,7 +649,7 @@ v3s16 turn_xz(v3s16 olddir, int t) } -void random_turn(PseudoRandom &random, v3s16 &dir) +void random_turn(PseudoRandom &random, v3POS &dir) { int turn = random.range(0, 2); if (turn == 0) { @@ -665,7 +665,7 @@ void random_turn(PseudoRandom &random, v3s16 &dir) } -int dir_to_facedir(v3s16 d) +int dir_to_facedir(v3POS d) { if (abs(d.X) > abs(d.Z)) return d.X < 0 ? 3 : 1; diff --git a/src/mapgen/dungeongen.h b/src/mapgen/dungeongen.h index 35e6beef5d..631d636fad 100644 --- a/src/mapgen/dungeongen.h +++ b/src/mapgen/dungeongen.h @@ -32,10 +32,10 @@ with this program; if not, write to the Free Software Foundation, Inc., class MMVManip; class NodeDefManager; -v3s16 rand_ortho_dir(PseudoRandom &random, bool diagonal_dirs); -v3s16 turn_xz(v3s16 olddir, int t); -void random_turn(PseudoRandom &random, v3s16 &dir); -int dir_to_facedir(v3s16 d); +v3POS rand_ortho_dir(PseudoRandom &random, bool diagonal_dirs); +v3POS turn_xz(v3POS olddir, int t); +void random_turn(PseudoRandom &random, v3POS &dir); +int dir_to_facedir(v3POS d); struct DungeonParams { @@ -57,11 +57,11 @@ struct DungeonParams { // Number of rooms u16 num_rooms; // Room size random range. Includes walls / floor / ceilng - v3s16 room_size_min; - v3s16 room_size_max; + v3POS room_size_min; + v3POS room_size_max; // Large room size random range. Includes walls / floor / ceilng - v3s16 room_size_large_min; - v3s16 room_size_large_max; + v3POS room_size_large_min; + v3POS room_size_large_max; // Value 0 disables large rooms. // Value 1 results in 1 large room, the first generated room. // Value > 1 makes the first generated room large, all other rooms have a @@ -71,7 +71,7 @@ struct DungeonParams { // Dimensions are of the empty space, not including walls / floor / ceilng. // Diagonal corridors must have hole width >=2 to be passable. // Currently, hole width >= 3 causes stair corridor bugs. - v3s16 holesize; + v3POS holesize; // Corridor length random range u16 corridor_len_min; u16 corridor_len_max; @@ -90,31 +90,31 @@ class DungeonGen { u32 blockseed; PseudoRandom random; - v3s16 csize; + v3POS csize; content_t c_torch; DungeonParams dp; // RoomWalker - v3s16 m_pos; - v3s16 m_dir; + v3POS m_pos; + v3POS m_dir; DungeonGen(const NodeDefManager *ndef, GenerateNotifier *gennotify, DungeonParams *dparams); - void generate(MMVManip *vm, u32 bseed, v3s16 full_node_min, v3s16 full_node_max); + void generate(MMVManip *vm, u32 bseed, v3POS full_node_min, v3POS full_node_max); - void makeDungeon(v3s16 start_padding); - void makeRoom(v3s16 roomsize, v3s16 roomplace); - void makeCorridor(v3s16 doorplace, v3s16 doordir, - v3s16 &result_place, v3s16 &result_dir); - void makeDoor(v3s16 doorplace, v3s16 doordir); - void makeFill(v3s16 place, v3s16 size, u8 avoid_flags, MapNode n, u8 or_flags); - void makeHole(v3s16 place); + void makeDungeon(v3POS start_padding); + void makeRoom(v3POS roomsize, v3POS roomplace); + void makeCorridor(v3POS doorplace, v3POS doordir, + v3POS &result_place, v3POS &result_dir); + void makeDoor(v3POS doorplace, v3POS doordir); + void makeFill(v3POS place, v3POS size, u8 avoid_flags, MapNode n, u8 or_flags); + void makeHole(v3POS place); - bool findPlaceForDoor(v3s16 &result_place, v3s16 &result_dir); - bool findPlaceForRoomDoor(v3s16 roomsize, v3s16 &result_doorplace, - v3s16 &result_doordir, v3s16 &result_roomplace); + bool findPlaceForDoor(v3POS &result_place, v3POS &result_dir); + bool findPlaceForRoomDoor(v3POS roomsize, v3POS &result_doorplace, + v3POS &result_doordir, v3POS &result_roomplace); inline void randomizeDir() { diff --git a/src/mapgen/mapgen.cpp b/src/mapgen/mapgen.cpp index 7984ff6092..10773a293a 100644 --- a/src/mapgen/mapgen.cpp +++ b/src/mapgen/mapgen.cpp @@ -114,7 +114,7 @@ Mapgen::Mapgen(int mapgenid, MapgenParams *params, EmergeParams *emerge) : water_level = params->water_level; mapgen_limit = params->mapgen_limit; flags = params->flags; - csize = v3s16(1, 1, 1) * (params->chunksize * MAP_BLOCKSIZE); + csize = v3POS(1, 1, 1) * (params->chunksize * MAP_BLOCKSIZE); /* We are losing half our entropy by doing this, but it is necessary to @@ -227,7 +227,7 @@ void Mapgen::setDefaultSettings(Settings *settings) } } -u32 Mapgen::getBlockSeed(v3s16 p, s32 seed) +u32 Mapgen::getBlockSeed(v3POS p, s32 seed) { return (u32)seed + p.Z * 38134234 + @@ -236,7 +236,7 @@ u32 Mapgen::getBlockSeed(v3s16 p, s32 seed) } -u32 Mapgen::getBlockSeed2(v3s16 p, s32 seed) +u32 Mapgen::getBlockSeed2(v3POS p, s32 seed) { u32 n = 1619 * p.X + 31337 * p.Y + 52591 * p.Z + 1013 * seed; n = (n >> 13) ^ n; @@ -245,11 +245,11 @@ u32 Mapgen::getBlockSeed2(v3s16 p, s32 seed) // Returns -MAX_MAP_GENERATION_LIMIT if not found -s16 Mapgen::findGroundLevel(v2s16 p2d, s16 ymin, s16 ymax) +POS Mapgen::findGroundLevel(v2POS p2d, POS ymin, POS ymax) { - const v3s16 &em = vm->m_area.getExtent(); + const v3POS &em = vm->m_area.getExtent(); u32 i = vm->m_area.index(p2d.X, ymax, p2d.Y); - s16 y; + POS y; for (y = ymax; y >= ymin; y--) { MapNode &n = vm->m_data[i]; @@ -263,11 +263,11 @@ s16 Mapgen::findGroundLevel(v2s16 p2d, s16 ymin, s16 ymax) // Returns -MAX_MAP_GENERATION_LIMIT if not found or if ground is found first -s16 Mapgen::findLiquidSurface(v2s16 p2d, s16 ymin, s16 ymax) +POS Mapgen::findLiquidSurface(v2POS p2d, POS ymin, POS ymax) { - const v3s16 &em = vm->m_area.getExtent(); + const v3POS &em = vm->m_area.getExtent(); u32 i = vm->m_area.index(p2d.X, ymax, p2d.Y); - s16 y; + POS y; for (y = ymax; y >= ymin; y--) { MapNode &n = vm->m_data[i]; @@ -283,16 +283,16 @@ s16 Mapgen::findLiquidSurface(v2s16 p2d, s16 ymin, s16 ymax) } -void Mapgen::updateHeightmap(v3s16 nmin, v3s16 nmax) +void Mapgen::updateHeightmap(v3POS nmin, v3POS nmax) { if (!heightmap) return; //TimeTaker t("Mapgen::updateHeightmap", NULL, PRECISION_MICRO); int index = 0; - for (s16 z = nmin.Z; z <= nmax.Z; z++) { - for (s16 x = nmin.X; x <= nmax.X; x++, index++) { - s16 y = findGroundLevel(v2s16(x, z), nmin.Y, nmax.Y); + for (POS z = nmin.Z; z <= nmax.Z; z++) { + for (POS x = nmin.X; x <= nmax.X; x++, index++) { + POS y = findGroundLevel(v2POS(x, z), nmin.Y, nmax.Y); heightmap[index] = y; } @@ -300,10 +300,10 @@ void Mapgen::updateHeightmap(v3s16 nmin, v3s16 nmax) } -void Mapgen::getSurfaces(v2s16 p2d, s16 ymin, s16 ymax, - std::vector &floors, std::vector &ceilings) +void Mapgen::getSurfaces(v2POS p2d, POS ymin, POS ymax, + std::vector &floors, std::vector &ceilings) { - const v3s16 &em = vm->m_area.getExtent(); + const v3POS &em = vm->m_area.getExtent(); bool is_walkable = false; u32 vi = vm->m_area.index(p2d.X, ymax, p2d.Y); @@ -311,7 +311,7 @@ void Mapgen::getSurfaces(v2s16 p2d, s16 ymin, s16 ymax, bool walkable_above = ndef->get(mn_max).walkable; VoxelArea::add_y(em, vi, -1); - for (s16 y = ymax - 1; y >= ymin; y--) { + for (POS y = ymax - 1; y >= ymin; y--) { MapNode mn = vm->m_data[vi]; is_walkable = ndef->get(mn).walkable; @@ -327,7 +327,7 @@ void Mapgen::getSurfaces(v2s16 p2d, s16 ymin, s16 ymax, } -inline bool Mapgen::isLiquidHorizontallyFlowable(u32 vi, v3s16 em) +inline bool Mapgen::isLiquidHorizontallyFlowable(u32 vi, v3POS em) { u32 vi_neg_x = vi; VoxelArea::add_x(em, vi_neg_x, -1); @@ -360,20 +360,20 @@ inline bool Mapgen::isLiquidHorizontallyFlowable(u32 vi, v3s16 em) return false; } -void Mapgen::updateLiquid(UniqueQueue *trans_liquid, v3s16 nmin, v3s16 nmax) +void Mapgen::updateLiquid(UniqueQueue *trans_liquid, v3POS nmin, v3POS nmax) { bool isignored, isliquid, wasignored, wasliquid, waschecked, waspushed; - const v3s16 &em = vm->m_area.getExtent(); + const v3POS &em = vm->m_area.getExtent(); - for (s16 z = nmin.Z + 1; z <= nmax.Z - 1; z++) - for (s16 x = nmin.X + 1; x <= nmax.X - 1; x++) { + for (POS z = nmin.Z + 1; z <= nmax.Z - 1; z++) + for (POS x = nmin.X + 1; x <= nmax.X - 1; x++) { wasignored = true; wasliquid = false; waschecked = false; waspushed = false; u32 vi = vm->m_area.index(x, nmax.Y, z); - for (s16 y = nmax.Y; y >= nmin.Y; y--) { + for (POS y = nmax.Y; y >= nmin.Y; y--) { isignored = vm->m_data[vi].getContent() == CONTENT_IGNORE; isliquid = ndef->get(vm->m_data[vi]).isLiquid(); @@ -385,7 +385,7 @@ void Mapgen::updateLiquid(UniqueQueue *trans_liquid, v3s16 nmin, v3s16 nm // This is the topmost node in the column bool ispushed = false; if (isLiquidHorizontallyFlowable(vi, em)) { - trans_liquid->push_back(v3s16(x, y, z)); + trans_liquid->push_back(v3POS(x, y, z)); ispushed = true; } // Remember waschecked and waspushed to avoid repeated @@ -400,7 +400,7 @@ void Mapgen::updateLiquid(UniqueQueue *trans_liquid, v3s16 nmin, v3s16 nm (!waschecked && isLiquidHorizontallyFlowable(vi_above, em)))) { // Push back the lowest node in the column which is one // node above this one - trans_liquid->push_back(v3s16(x, y + 1, z)); + trans_liquid->push_back(v3POS(x, y + 1, z)); } } @@ -412,7 +412,7 @@ void Mapgen::updateLiquid(UniqueQueue *trans_liquid, v3s16 nmin, v3s16 nm } -void Mapgen::setLighting(u8 light, v3s16 nmin, v3s16 nmax) +void Mapgen::setLighting(u8 light, v3POS nmin, v3POS nmax) { ScopeProfiler sp(g_profiler, "EmergeThread: update lighting", SPT_AVG); VoxelArea a(nmin, nmax); @@ -427,8 +427,8 @@ void Mapgen::setLighting(u8 light, v3s16 nmin, v3s16 nmax) } -void Mapgen::lightSpread(VoxelArea &a, std::queue> &queue, - const v3s16 &p, u8 light) +void Mapgen::lightSpread(VoxelArea &a, std::queue> &queue, + const v3POS &p, u8 light) { if (light <= 1 || !a.contains(p)) return; @@ -465,7 +465,7 @@ void Mapgen::lightSpread(VoxelArea &a, std::queue> &queue, } -void Mapgen::calcLighting(v3s16 nmin, v3s16 nmax, v3s16 full_nmin, v3s16 full_nmax, +void Mapgen::calcLighting(v3POS nmin, v3POS nmax, v3POS full_nmin, v3POS full_nmax, bool propagate_shadow) { ScopeProfiler sp(g_profiler, "EmergeThread: update lighting", SPT_AVG); @@ -478,12 +478,12 @@ void Mapgen::calcLighting(v3s16 nmin, v3s16 nmax, v3s16 full_nmin, v3s16 full_nm } -void Mapgen::propagateSunlight(v3s16 nmin, v3s16 nmax, bool propagate_shadow) +void Mapgen::propagateSunlight(v3POS nmin, v3POS nmax, bool propagate_shadow) { //TimeTaker t("propagateSunlight"); VoxelArea a(nmin, nmax); bool block_is_underground = (water_level >= nmax.Y); - const v3s16 &em = vm->m_area.getExtent(); + const v3POS &em = vm->m_area.getExtent(); // NOTE: Direct access to the low 4 bits of param1 is okay here because, // by definition, sunlight will never be in the night lightbank. @@ -514,10 +514,10 @@ void Mapgen::propagateSunlight(v3s16 nmin, v3s16 nmax, bool propagate_shadow) } -void Mapgen::spreadLight(const v3s16 &nmin, const v3s16 &nmax) +void Mapgen::spreadLight(const v3POS &nmin, const v3POS &nmax) { //TimeTaker t("spreadLight"); - std::queue> queue; + std::queue> queue; VoxelArea a(nmin, nmax); for (int z = a.MinEdge.Z; z <= a.MaxEdge.Z; z++) { @@ -541,7 +541,7 @@ void Mapgen::spreadLight(const v3s16 &nmin, const v3s16 &nmax) u8 light = n.param1; if (light) { - const v3s16 p(x, y, z); + const v3POS p(x, y, z); // spread to all 6 neighbor nodes for (const auto &dir : g_6dirs) lightSpread(a, queue, p + dir, light); @@ -592,7 +592,7 @@ MapgenBasic::MapgenBasic(int mapgenid, MapgenParams *params, EmergeParams *emerg this->zstride_1u1d = csize.X * (csize.Y + 2); //// Allocate heightmap - this->heightmap = new s16[csize.X * csize.Z]; + this->heightmap = new POS[csize.X * csize.Z]; //// Initialize biome generator biomegen = emerge->biomegen; @@ -634,20 +634,20 @@ void MapgenBasic::generateBiomes() assert(biomegen); assert(biomemap); - const v3s16 &em = vm->m_area.getExtent(); + const v3POS &em = vm->m_area.getExtent(); u32 index = 0; noise_filler_depth->perlinMap2D(node_min.X, node_min.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 (POS z = node_min.Z; z <= node_max.Z; z++) + for (POS x = node_min.X; x <= node_max.X; x++, index++) { Biome *biome = NULL; biome_t water_biome_index = 0; - u16 depth_top = 0; + POS depth_top = 0; u16 base_filler = 0; u16 depth_water_top = 0; u16 depth_riverbed = 0; - s16 biome_y_min = -MAX_MAP_GENERATION_LIMIT; + POS biome_y_min = -MAX_MAP_GENERATION_LIMIT; u32 vi = vm->m_area.index(x, node_max.Y, z); // Check node at base of mapchunk above, either a node of a previously @@ -663,7 +663,7 @@ void MapgenBasic::generateBiomes() // nplaced to stone level by setting a number exceeding any possible filler depth. u16 nplaced = (air_above || water_above) ? 0 : U16_MAX; - for (s16 y = node_max.Y; y >= node_min.Y; y--) { + for (POS y = node_max.Y; y >= node_min.Y; y--) { content_t c = vm->m_data[vi].getContent(); // Biome is (re)calculated: // 1. At the surface of stone below air or water. @@ -679,7 +679,7 @@ void MapgenBasic::generateBiomes() if (is_stone_surface || is_water_surface) { // (Re)calculate biome - biome = biomegen->getBiomeAtIndex(index, v3s16(x, y, z)); + biome = biomegen->getBiomeAtIndex(index, v3POS(x, y, z)); // Add biome to biomemap at first stone surface detected if (biomemap[index] == BIOME_NONE && is_stone_surface) @@ -770,11 +770,11 @@ void MapgenBasic::dustTopNodes() if (node_max.Y < water_level) return; - const v3s16 &em = vm->m_area.getExtent(); + const v3POS &em = vm->m_area.getExtent(); u32 index = 0; - for (s16 z = node_min.Z; z <= node_max.Z; z++) - for (s16 x = node_min.X; x <= node_max.X; x++, index++) { + for (POS z = node_min.Z; z <= node_max.Z; z++) + for (POS x = node_min.X; x <= node_max.X; x++, index++) { Biome *biome = (Biome *)m_bmgr->getRaw(biomemap[index]); if (biome->c_dust == CONTENT_IGNORE) @@ -786,7 +786,7 @@ void MapgenBasic::dustTopNodes() // will provide this required dust when it does. u32 vi = vm->m_area.index(x, full_node_max.Y, z); content_t c_full_max = vm->m_data[vi].getContent(); - s16 y_start; + POS y_start; if (c_full_max == CONTENT_AIR) { y_start = full_node_max.Y - 1; @@ -803,7 +803,7 @@ void MapgenBasic::dustTopNodes() } vi = vm->m_area.index(x, y_start, z); - for (s16 y = y_start; y >= node_min.Y - 1; y--) { + for (POS y = y_start; y >= node_min.Y - 1; y--) { if (vm->m_data[vi].getContent() != CONTENT_AIR) break; @@ -829,7 +829,7 @@ void MapgenBasic::dustTopNodes() } -void MapgenBasic::generateCavesNoiseIntersection(s16 max_stone_y) +void MapgenBasic::generateCavesNoiseIntersection(POS max_stone_y) { // cave_width >= 10 is used to disable generation and avoid the intensive // 3D noise calculations. Tunnels already have zero width when cave_width > 1. @@ -843,7 +843,7 @@ void MapgenBasic::generateCavesNoiseIntersection(s16 max_stone_y) } -void MapgenBasic::generateCavesRandomWalk(s16 max_stone_y, s16 large_cave_ymax) +void MapgenBasic::generateCavesRandomWalk(POS max_stone_y, POS large_cave_ymax) { if (node_min.Y > max_stone_y) return; @@ -874,7 +874,7 @@ void MapgenBasic::generateCavesRandomWalk(s16 max_stone_y, s16 large_cave_ymax) } -bool MapgenBasic::generateCavernsNoise(s16 max_stone_y) +bool MapgenBasic::generateCavernsNoise(POS max_stone_y) { if (node_min.Y > max_stone_y || node_min.Y > cavern_limit) return false; @@ -886,7 +886,7 @@ bool MapgenBasic::generateCavernsNoise(s16 max_stone_y) } -void MapgenBasic::generateDungeons(s16 max_stone_y) +void MapgenBasic::generateDungeons(POS max_stone_y) { if (node_min.Y > max_stone_y || node_min.Y > dungeon_ymax || node_max.Y < dungeon_ymin) @@ -909,20 +909,20 @@ void MapgenBasic::generateDungeons(s16 max_stone_y) dp.num_dungeons = num_dungeons; dp.notifytype = GENNOTIFY_DUNGEON; dp.num_rooms = ps.range(2, 16); - dp.room_size_min = v3s16(5, 5, 5); - dp.room_size_max = v3s16(12, 6, 12); - dp.room_size_large_min = v3s16(12, 6, 12); - dp.room_size_large_max = v3s16(16, 16, 16); + dp.room_size_min = v3POS(5, 5, 5); + dp.room_size_max = v3POS(12, 6, 12); + dp.room_size_large_min = v3POS(12, 6, 12); + dp.room_size_large_max = v3POS(16, 16, 16); dp.large_room_chance = (ps.range(1, 4) == 1) ? 8 : 0; dp.diagonal_dirs = ps.range(1, 8) == 1; // Diagonal corridors must have 'hole' width >=2 to be passable u8 holewidth = (dp.diagonal_dirs) ? 2 : ps.range(1, 2); - dp.holesize = v3s16(holewidth, 3, holewidth); + dp.holesize = v3POS(holewidth, 3, holewidth); dp.corridor_len_min = 1; dp.corridor_len_max = 13; // Get biome at mapchunk midpoint - v3s16 chunk_mid = node_min + (node_max - node_min) / v3s16(2, 2, 2); + v3POS chunk_mid = node_min + (node_max - node_min) / v3POS(2, 2, 2); Biome *biome = (Biome *)biomegen->getBiomeAtPoint(chunk_mid); // Use biome-defined dungeon nodes if defined @@ -964,7 +964,7 @@ GenerateNotifier::GenerateNotifier(u32 notify_on, } -bool GenerateNotifier::addEvent(GenNotifyType type, v3s16 pos, u32 id) +bool GenerateNotifier::addEvent(GenNotifyType type, v3POS pos, u32 id) { if (!(m_notify_on & (1 << type))) return false; @@ -984,7 +984,7 @@ bool GenerateNotifier::addEvent(GenNotifyType type, v3s16 pos, u32 id) void GenerateNotifier::getEvents( - std::map > &event_map) + std::map > &event_map) { std::list::iterator it; @@ -1035,8 +1035,8 @@ void MapgenParams::readParams(const Settings *settings) mgtype = MAPGEN_DEFAULT; } - settings->getS16NoEx("water_level", water_level); - settings->getS16NoEx("mapgen_limit", mapgen_limit); + settings->getPOSNoEx("water_level", water_level); + settings->getPOSNoEx("mapgen_limit", mapgen_limit); settings->getS16NoEx("chunksize", chunksize); settings->getFlagStrNoEx("mg_flags", flags, flagdesc_mapgen); @@ -1053,8 +1053,8 @@ void MapgenParams::writeParams(Settings *settings) const { settings->set("mg_name", Mapgen::getMapgenName(mgtype)); settings->setU64("seed", seed); - settings->setS16("water_level", water_level); - settings->setS16("mapgen_limit", mapgen_limit); + settings->setPOS("water_level", water_level); + settings->setPOS("mapgen_limit", mapgen_limit); settings->setS16("chunksize", chunksize); settings->setFlagStr("mg_flags", flags, flagdesc_mapgen); @@ -1078,16 +1078,16 @@ void MapgenParams::calcMapgenEdges() s16 ccfmin = ccmin - MAP_BLOCKSIZE; s16 ccfmax = ccmax + MAP_BLOCKSIZE; // Effective mapgen limit, in blocks - // Uses same calculation as ServerMap::blockpos_over_mapgen_limit(v3s16 p) - s16 mapgen_limit_b = rangelim(mapgen_limit, + // Uses same calculation as ServerMap::blockpos_over_mapgen_limit(v3POS p) + POS mapgen_limit_b = rangelim(mapgen_limit, 0, MAX_MAP_GENERATION_LIMIT) / MAP_BLOCKSIZE; // Effective mapgen limits, in nodes - s16 mapgen_limit_min = -mapgen_limit_b * MAP_BLOCKSIZE; - s16 mapgen_limit_max = (mapgen_limit_b + 1) * MAP_BLOCKSIZE - 1; + POS mapgen_limit_min = -mapgen_limit_b * MAP_BLOCKSIZE; + POS mapgen_limit_max = (mapgen_limit_b + 1) * MAP_BLOCKSIZE - 1; // Number of complete chunks from central chunk fullminp/fullmaxp // to effective mapgen limits. - s16 numcmin = MYMAX((ccfmin - mapgen_limit_min) / csize_n, 0); - s16 numcmax = MYMAX((mapgen_limit_max - ccfmax) / csize_n, 0); + POS numcmin = MYMAX((ccfmin - mapgen_limit_min) / csize_n, 0); + POS numcmax = MYMAX((mapgen_limit_max - ccfmax) / csize_n, 0); // Mapgen edges, in nodes mapgen_edge_min = ccmin - numcmin * csize_n; mapgen_edge_max = ccmax + numcmax * csize_n; diff --git a/src/mapgen/mapgen.h b/src/mapgen/mapgen.h index 61db4f3b97..6df2119ad0 100644 --- a/src/mapgen/mapgen.h +++ b/src/mapgen/mapgen.h @@ -80,7 +80,7 @@ enum GenNotifyType { struct GenNotifyEvent { GenNotifyType type; - v3s16 pos; + v3POS pos; u32 id; }; @@ -90,8 +90,8 @@ class GenerateNotifier { GenerateNotifier() = default; GenerateNotifier(u32 notify_on, const std::set *notify_on_deco_ids); - bool addEvent(GenNotifyType type, v3s16 pos, u32 id=0); - void getEvents(std::map > &event_map); + bool addEvent(GenNotifyType type, v3POS pos, u32 id=0); + void getEvents(std::map > &event_map); void clearEvents(); private: @@ -120,16 +120,16 @@ struct MapgenParams { MapgenType mgtype = MAPGEN_DEFAULT; s16 chunksize = 5; u64 seed = 0; - s16 water_level = 1; - s16 mapgen_limit = MAX_MAP_GENERATION_LIMIT; + POS water_level = 1; + POS mapgen_limit = MAX_MAP_GENERATION_LIMIT; // Flags set in readParams u32 flags = 0; u32 spflags = 0; BiomeParams *bparams = nullptr; - s16 mapgen_edge_min = -MAX_MAP_GENERATION_LIMIT; - s16 mapgen_edge_max = MAX_MAP_GENERATION_LIMIT; + POS mapgen_edge_min = -MAX_MAP_GENERATION_LIMIT; + POS mapgen_edge_max = MAX_MAP_GENERATION_LIMIT; virtual void readParams(const Settings *settings); virtual void writeParams(Settings *settings) const; @@ -166,9 +166,9 @@ class Mapgen { const NodeDefManager *ndef = nullptr; u32 blockseed; - s16 *heightmap = nullptr; + POS *heightmap = nullptr; biome_t *biomemap = nullptr; - v3s16 csize; + v3POS csize; BiomeGen *biomegen = nullptr; GenerateNotifier gennotify; @@ -180,33 +180,33 @@ class Mapgen { virtual MapgenType getType() const { return MAPGEN_INVALID; } - static u32 getBlockSeed(v3s16 p, s32 seed); - static u32 getBlockSeed2(v3s16 p, s32 seed); - s16 findGroundLevel(v2s16 p2d, s16 ymin, s16 ymax); - s16 findLiquidSurface(v2s16 p2d, s16 ymin, s16 ymax); - void updateHeightmap(v3s16 nmin, v3s16 nmax); - void getSurfaces(v2s16 p2d, s16 ymin, s16 ymax, - std::vector &floors, std::vector &ceilings); + static u32 getBlockSeed(v3POS p, s32 seed); + static u32 getBlockSeed2(v3POS p, s32 seed); + POS findGroundLevel(v2POS p2d, POS ymin, POS ymax); + POS findLiquidSurface(v2POS p2d, POS ymin, POS ymax); + void updateHeightmap(v3POS nmin, v3POS nmax); + void getSurfaces(v2POS p2d, POS ymin, POS ymax, + std::vector &floors, std::vector &ceilings); - void updateLiquid(UniqueQueue *trans_liquid, v3s16 nmin, v3s16 nmax); + void updateLiquid(UniqueQueue *trans_liquid, v3POS nmin, v3POS nmax); - void setLighting(u8 light, v3s16 nmin, v3s16 nmax); - void lightSpread(VoxelArea &a, std::queue> &queue, - const v3s16 &p, u8 light); - void calcLighting(v3s16 nmin, v3s16 nmax, v3s16 full_nmin, v3s16 full_nmax, + void setLighting(u8 light, v3POS nmin, v3POS nmax); + void lightSpread(VoxelArea &a, std::queue> &queue, + const v3POS &p, u8 light); + void calcLighting(v3POS nmin, v3POS nmax, v3POS full_nmin, v3POS full_nmax, bool propagate_shadow = true); - void propagateSunlight(v3s16 nmin, v3s16 nmax, bool propagate_shadow); - void spreadLight(const v3s16 &nmin, const v3s16 &nmax); + void propagateSunlight(v3POS nmin, v3POS nmax, bool propagate_shadow); + void spreadLight(const v3POS &nmin, const v3POS &nmax); virtual void makeChunk(BlockMakeData *data) {} - virtual int getGroundLevelAtPoint(v2s16 p) { return 0; } + virtual int getGroundLevelAtPoint(v2POS p) { return 0; } // getSpawnLevelAtPoint() is a function within each mapgen that returns a // suitable y co-ordinate for player spawn ('suitable' usually meaning // within 16 nodes of water_level). If a suitable spawn level cannot be // found at the specified (X, Z) 'MAX_MAP_GENERATION_LIMIT' is returned to // signify this and to cause Server::findSpawnPos() to try another (X, Z). - virtual int getSpawnLevelAtPoint(v2s16 p) { return 0; } + virtual int getSpawnLevelAtPoint(v2POS p) { return 0; } // Mapgen management functions static MapgenType getMapgenType(const std::string &mgname); @@ -221,7 +221,7 @@ class Mapgen { // isLiquidHorizontallyFlowable() is a helper function for updateLiquid() // that checks whether there are floodable nodes without liquid beneath // the node at index vi. - inline bool isLiquidHorizontallyFlowable(u32 vi, v3s16 em); + inline bool isLiquidHorizontallyFlowable(u32 vi, v3POS em); }; /* @@ -245,10 +245,10 @@ class MapgenBasic : public Mapgen { virtual void generateBiomes(); virtual void dustTopNodes(); - virtual void generateCavesNoiseIntersection(s16 max_stone_y); - virtual void generateCavesRandomWalk(s16 max_stone_y, s16 large_cave_ymax); - virtual bool generateCavernsNoise(s16 max_stone_y); - virtual void generateDungeons(s16 max_stone_y); + virtual void generateCavesNoiseIntersection(POS max_stone_y); + virtual void generateCavesRandomWalk(POS max_stone_y, POS large_cave_ymax); + virtual bool generateCavernsNoise(POS max_stone_y); + virtual void generateDungeons(POS max_stone_y); protected: EmergeParams *m_emerge; @@ -256,10 +256,10 @@ class MapgenBasic : public Mapgen { Noise *noise_filler_depth; - v3s16 node_min; - v3s16 node_max; - v3s16 full_node_min; - v3s16 full_node_max; + v3POS node_min; + v3POS node_max; + v3POS full_node_min; + v3POS full_node_max; content_t c_stone; content_t c_water_source; @@ -287,7 +287,7 @@ class MapgenBasic : public Mapgen { int large_cave_num_min; int large_cave_num_max; float large_cave_flooded; - s16 large_cave_depth; - s16 dungeon_ymin; - s16 dungeon_ymax; + POS large_cave_depth; + POS dungeon_ymin; + POS dungeon_ymax; }; diff --git a/src/mapgen/mapgen_carpathian.cpp b/src/mapgen/mapgen_carpathian.cpp index b3a0bd2707..9f47e1de19 100644 --- a/src/mapgen/mapgen_carpathian.cpp +++ b/src/mapgen/mapgen_carpathian.cpp @@ -152,17 +152,17 @@ void MapgenCarpathianParams::readParams(const Settings *settings) settings->getFloatNoEx("mgcarpathian_valley_width", valley_width); settings->getFloatNoEx("mgcarpathian_cave_width", cave_width); - settings->getS16NoEx("mgcarpathian_large_cave_depth", large_cave_depth); + settings->getPOSNoEx("mgcarpathian_large_cave_depth", large_cave_depth); settings->getU16NoEx("mgcarpathian_small_cave_num_min", small_cave_num_min); settings->getU16NoEx("mgcarpathian_small_cave_num_max", small_cave_num_max); settings->getU16NoEx("mgcarpathian_large_cave_num_min", large_cave_num_min); settings->getU16NoEx("mgcarpathian_large_cave_num_max", large_cave_num_max); settings->getFloatNoEx("mgcarpathian_large_cave_flooded", large_cave_flooded); - settings->getS16NoEx("mgcarpathian_cavern_limit", cavern_limit); - settings->getS16NoEx("mgcarpathian_cavern_taper", cavern_taper); + settings->getPOSNoEx("mgcarpathian_cavern_limit", cavern_limit); + settings->getPOSNoEx("mgcarpathian_cavern_taper", cavern_taper); settings->getFloatNoEx("mgcarpathian_cavern_threshold", cavern_threshold); - settings->getS16NoEx("mgcarpathian_dungeon_ymin", dungeon_ymin); - settings->getS16NoEx("mgcarpathian_dungeon_ymax", dungeon_ymax); + settings->getPOSNoEx("mgcarpathian_dungeon_ymin", dungeon_ymin); + settings->getPOSNoEx("mgcarpathian_dungeon_ymax", dungeon_ymax); settings->getNoiseParams("mgcarpathian_np_filler_depth", np_filler_depth); settings->getNoiseParams("mgcarpathian_np_height1", np_height1); @@ -194,7 +194,7 @@ void MapgenCarpathianParams::writeParams(Settings *settings) const settings->setFloat("mgcarpathian_valley_width", valley_width); settings->setFloat("mgcarpathian_cave_width", cave_width); - settings->setS16("mgcarpathian_large_cave_depth", large_cave_depth); + settings->setPOS("mgcarpathian_large_cave_depth", large_cave_depth); settings->setU16("mgcarpathian_small_cave_num_min", small_cave_num_min); settings->setU16("mgcarpathian_small_cave_num_max", small_cave_num_max); settings->setU16("mgcarpathian_large_cave_num_min", large_cave_num_min); @@ -203,8 +203,8 @@ void MapgenCarpathianParams::writeParams(Settings *settings) const settings->setS16("mgcarpathian_cavern_limit", cavern_limit); settings->setS16("mgcarpathian_cavern_taper", cavern_taper); settings->setFloat("mgcarpathian_cavern_threshold", cavern_threshold); - settings->setS16("mgcarpathian_dungeon_ymin", dungeon_ymin); - settings->setS16("mgcarpathian_dungeon_ymax", dungeon_ymax); + settings->setPOS("mgcarpathian_dungeon_ymin", dungeon_ymin); + settings->setPOS("mgcarpathian_dungeon_ymax", dungeon_ymax); settings->setNoiseParams("mgcarpathian_np_filler_depth", np_filler_depth); settings->setNoiseParams("mgcarpathian_np_height1", np_height1); @@ -265,18 +265,18 @@ void MapgenCarpathian::makeChunk(BlockMakeData *data) this->vm = data->vmanip; this->ndef = data->nodedef; - v3s16 blockpos_min = data->blockpos_min; - v3s16 blockpos_max = data->blockpos_max; + v3POS blockpos_min = data->blockpos_min; + v3POS blockpos_max = data->blockpos_max; node_min = blockpos_min * MAP_BLOCKSIZE; - node_max = (blockpos_max + v3s16(1, 1, 1)) * MAP_BLOCKSIZE - v3s16(1, 1, 1); + node_max = (blockpos_max + v3POS(1, 1, 1)) * MAP_BLOCKSIZE - v3POS(1, 1, 1); full_node_min = (blockpos_min - 1) * MAP_BLOCKSIZE; - full_node_max = (blockpos_max + 2) * MAP_BLOCKSIZE - v3s16(1, 1, 1); + full_node_max = (blockpos_max + 2) * MAP_BLOCKSIZE - v3POS(1, 1, 1); // Create a block-specific seed blockseed = getBlockSeed2(full_node_min, seed); // Generate terrain - s16 stone_surface_max_y = generateTerrain(); + POS stone_surface_max_y = generateTerrain(); // Create heightmap updateHeightmap(node_min, node_max); @@ -329,7 +329,7 @@ void MapgenCarpathian::makeChunk(BlockMakeData *data) // Calculate lighting if (flags & MG_LIGHT) { - calcLighting(node_min - v3s16(0, 1, 0), node_max + v3s16(0, 1, 0), + calcLighting(node_min - v3POS(0, 1, 0), node_max + v3POS(0, 1, 0), full_node_min, full_node_max); } @@ -340,7 +340,7 @@ void MapgenCarpathian::makeChunk(BlockMakeData *data) //////////////////////////////////////////////////////////////////////////////// -int MapgenCarpathian::getSpawnLevelAtPoint(v2s16 p) +int MapgenCarpathian::getSpawnLevelAtPoint(v2POS p) { // If rivers are enabled, first check if in a river channel if (spflags & MGCARPATHIAN_RIVERS) { @@ -390,7 +390,7 @@ int MapgenCarpathian::getSpawnLevelAtPoint(v2s16 p) bool solid_below = false; u8 cons_non_solid = 0; // consecutive non-solid nodes - for (s16 y = water_level; y <= water_level + 32; y++) { + for (POS y = water_level; y <= water_level + 32; y++) { float mnt_var = NoisePerlin3D(&noise_mnt_var->np, p.X, y, p.Y, seed); float hill1 = getLerp(height1, height2, mnt_var); float hill2 = getLerp(height3, height4, mnt_var); @@ -460,12 +460,12 @@ int MapgenCarpathian::generateTerrain() noise_rivers->perlinMap2D(node_min.X, node_min.Z); //// Place nodes - const v3s16 &em = vm->m_area.getExtent(); - s16 stone_surface_max_y = -MAX_MAP_GENERATION_LIMIT; + const v3POS &em = vm->m_area.getExtent(); + POS stone_surface_max_y = -MAX_MAP_GENERATION_LIMIT; u32 index2d = 0; - for (s16 z = node_min.Z; z <= node_max.Z; z++) - for (s16 x = node_min.X; x <= node_max.X; x++, index2d++) { + for (POS z = node_min.Z; z <= node_max.Z; z++) + for (POS x = node_min.X; x <= node_max.X; x++, index2d++) { // Hill/Mountain height (hilliness) float height1 = noise_height1->result[index2d]; float height2 = noise_height2->result[index2d]; @@ -513,7 +513,7 @@ int MapgenCarpathian::generateTerrain() u32 index3d = (z - node_min.Z) * zstride_1u1d + (x - node_min.X); u32 vi = vm->m_area.index(x, node_min.Y - 1, z); - for (s16 y = node_min.Y - 1; y <= node_max.Y + 1; + for (POS y = node_min.Y - 1; y <= node_max.Y + 1; y++, index3d += ystride, VoxelArea::add_y(em, vi, 1)) { diff --git a/src/mapgen/mapgen_carpathian.h b/src/mapgen/mapgen_carpathian.h index 31b2b91d8d..f38ce67304 100644 --- a/src/mapgen/mapgen_carpathian.h +++ b/src/mapgen/mapgen_carpathian.h @@ -38,17 +38,17 @@ struct MapgenCarpathianParams : public MapgenParams float valley_width = 0.25f; float cave_width = 0.09f; - s16 large_cave_depth = -33; + POS large_cave_depth = -33; u16 small_cave_num_min = 0; u16 small_cave_num_max = 0; u16 large_cave_num_min = 0; u16 large_cave_num_max = 2; float large_cave_flooded = 0.5f; - s16 cavern_limit = -256; - s16 cavern_taper = 256; + POS cavern_limit = -256; + POS cavern_taper = 256; float cavern_threshold = 0.7f; - s16 dungeon_ymin = -31000; - s16 dungeon_ymax = 31000; + POS dungeon_ymin = -MAX_MAP_GENERATION_LIMIT; + POS dungeon_ymax = MAX_MAP_GENERATION_LIMIT; NoiseParams np_filler_depth; NoiseParams np_height1; @@ -85,7 +85,7 @@ class MapgenCarpathian : public MapgenBasic virtual MapgenType getType() const { return MAPGEN_CARPATHIAN; } virtual void makeChunk(BlockMakeData *data); - int getSpawnLevelAtPoint(v2s16 p); + int getSpawnLevelAtPoint(v2POS p); private: float base_level; diff --git a/src/mapgen/mapgen_flat.cpp b/src/mapgen/mapgen_flat.cpp index 3424550291..85a23693bf 100644 --- a/src/mapgen/mapgen_flat.cpp +++ b/src/mapgen/mapgen_flat.cpp @@ -108,8 +108,8 @@ MapgenFlatParams::MapgenFlatParams(): void MapgenFlatParams::readParams(const Settings *settings) { settings->getFlagStrNoEx("mgflat_spflags", spflags, flagdesc_mapgen_flat); - settings->getS16NoEx("mgflat_ground_level", ground_level); - settings->getS16NoEx("mgflat_large_cave_depth", large_cave_depth); + settings->getPOSNoEx("mgflat_ground_level", ground_level); + settings->getPOSNoEx("mgflat_large_cave_depth", large_cave_depth); settings->getU16NoEx("mgflat_small_cave_num_min", small_cave_num_min); settings->getU16NoEx("mgflat_small_cave_num_max", small_cave_num_max); settings->getU16NoEx("mgflat_large_cave_num_min", large_cave_num_min); @@ -120,11 +120,11 @@ void MapgenFlatParams::readParams(const Settings *settings) settings->getFloatNoEx("mgflat_lake_steepness", lake_steepness); settings->getFloatNoEx("mgflat_hill_threshold", hill_threshold); settings->getFloatNoEx("mgflat_hill_steepness", hill_steepness); - settings->getS16NoEx("mgflat_cavern_limit", cavern_limit); - settings->getS16NoEx("mgflat_cavern_taper", cavern_taper); + settings->getPOSNoEx("mgflat_cavern_limit", cavern_limit); + settings->getPOSNoEx("mgflat_cavern_taper", cavern_taper); settings->getFloatNoEx("mgflat_cavern_threshold", cavern_threshold); - settings->getS16NoEx("mgflat_dungeon_ymin", dungeon_ymin); - settings->getS16NoEx("mgflat_dungeon_ymax", dungeon_ymax); + settings->getPOSNoEx("mgflat_dungeon_ymin", dungeon_ymin); + settings->getPOSNoEx("mgflat_dungeon_ymax", dungeon_ymax); settings->getNoiseParams("mgflat_np_terrain", np_terrain); settings->getNoiseParams("mgflat_np_filler_depth", np_filler_depth); @@ -138,8 +138,8 @@ void MapgenFlatParams::readParams(const Settings *settings) void MapgenFlatParams::writeParams(Settings *settings) const { settings->setFlagStr("mgflat_spflags", spflags, flagdesc_mapgen_flat); - settings->setS16("mgflat_ground_level", ground_level); - settings->setS16("mgflat_large_cave_depth", large_cave_depth); + settings->setPOS("mgflat_ground_level", ground_level); + settings->setPOS("mgflat_large_cave_depth", large_cave_depth); settings->setU16("mgflat_small_cave_num_min", small_cave_num_min); settings->setU16("mgflat_small_cave_num_max", small_cave_num_max); settings->setU16("mgflat_large_cave_num_min", large_cave_num_min); @@ -150,11 +150,11 @@ void MapgenFlatParams::writeParams(Settings *settings) const settings->setFloat("mgflat_lake_steepness", lake_steepness); settings->setFloat("mgflat_hill_threshold", hill_threshold); settings->setFloat("mgflat_hill_steepness", hill_steepness); - settings->setS16("mgflat_cavern_limit", cavern_limit); - settings->setS16("mgflat_cavern_taper", cavern_taper); + settings->setPOS("mgflat_cavern_limit", cavern_limit); + settings->setPOS("mgflat_cavern_taper", cavern_taper); settings->setFloat("mgflat_cavern_threshold", cavern_threshold); - settings->setS16("mgflat_dungeon_ymin", dungeon_ymin); - settings->setS16("mgflat_dungeon_ymax", dungeon_ymax); + settings->setPOS("mgflat_dungeon_ymin", dungeon_ymin); + settings->setPOS("mgflat_dungeon_ymax", dungeon_ymax); settings->setNoiseParams("mgflat_np_terrain", np_terrain); settings->setNoiseParams("mgflat_np_filler_depth", np_filler_depth); @@ -174,19 +174,19 @@ void MapgenFlatParams::setDefaultSettings(Settings *settings) ///////////////////////////////////////////////////////////////// -int MapgenFlat::getSpawnLevelAtPoint(v2s16 p) +int MapgenFlat::getSpawnLevelAtPoint(v2POS p) { - s16 stone_level = ground_level; + POS stone_level = ground_level; float n_terrain = ((spflags & MGFLAT_LAKES) || (spflags & MGFLAT_HILLS)) ? NoisePerlin2D(&noise_terrain->np, p.X, p.Y, seed) : 0.0f; if ((spflags & MGFLAT_LAKES) && n_terrain < lake_threshold) { - s16 depress = (lake_threshold - n_terrain) * lake_steepness; + POS depress = (lake_threshold - n_terrain) * lake_steepness; stone_level = ground_level - depress; } else if ((spflags & MGFLAT_HILLS) && n_terrain > hill_threshold) { - s16 rise = (n_terrain - hill_threshold) * hill_steepness; + POS rise = (n_terrain - hill_threshold) * hill_steepness; stone_level = ground_level + rise; } @@ -215,17 +215,17 @@ void MapgenFlat::makeChunk(BlockMakeData *data) this->ndef = data->nodedef; //TimeTaker t("makeChunk"); - v3s16 blockpos_min = data->blockpos_min; - v3s16 blockpos_max = data->blockpos_max; + v3POS blockpos_min = data->blockpos_min; + v3POS blockpos_max = data->blockpos_max; node_min = blockpos_min * MAP_BLOCKSIZE; - node_max = (blockpos_max + v3s16(1, 1, 1)) * MAP_BLOCKSIZE - v3s16(1, 1, 1); + node_max = (blockpos_max + v3POS(1, 1, 1)) * MAP_BLOCKSIZE - v3POS(1, 1, 1); full_node_min = (blockpos_min - 1) * MAP_BLOCKSIZE; - full_node_max = (blockpos_max + 2) * MAP_BLOCKSIZE - v3s16(1, 1, 1); + full_node_max = (blockpos_max + 2) * MAP_BLOCKSIZE - v3POS(1, 1, 1); blockseed = getBlockSeed2(full_node_min, seed); // Generate base terrain, mountains, and ridges with initial heightmaps - s16 stone_surface_max_y = generateTerrain(); + POS stone_surface_max_y = generateTerrain(); // Create heightmap updateHeightmap(node_min, node_max); @@ -277,45 +277,45 @@ void MapgenFlat::makeChunk(BlockMakeData *data) updateLiquid(&data->transforming_liquid, full_node_min, full_node_max); if (flags & MG_LIGHT) - calcLighting(node_min - v3s16(0, 1, 0), node_max + v3s16(0, 1, 0), + calcLighting(node_min - v3POS(0, 1, 0), node_max + v3POS(0, 1, 0), full_node_min, full_node_max); - //setLighting(node_min - v3s16(1, 0, 1) * MAP_BLOCKSIZE, - // node_max + v3s16(1, 0, 1) * MAP_BLOCKSIZE, 0xFF); + //setLighting(node_min - v3POS(1, 0, 1) * MAP_BLOCKSIZE, + // node_max + v3POS(1, 0, 1) * MAP_BLOCKSIZE, 0xFF); this->generating = false; } -s16 MapgenFlat::generateTerrain() +POS MapgenFlat::generateTerrain() { MapNode n_air(CONTENT_AIR); MapNode n_stone(c_stone); MapNode n_water(c_water_source); - const v3s16 &em = vm->m_area.getExtent(); - s16 stone_surface_max_y = -MAX_MAP_GENERATION_LIMIT; + const v3POS &em = vm->m_area.getExtent(); + POS stone_surface_max_y = -MAX_MAP_GENERATION_LIMIT; u32 ni2d = 0; bool use_noise = (spflags & MGFLAT_LAKES) || (spflags & MGFLAT_HILLS); if (use_noise) noise_terrain->perlinMap2D(node_min.X, node_min.Z); - for (s16 z = node_min.Z; z <= node_max.Z; z++) - for (s16 x = node_min.X; x <= node_max.X; x++, ni2d++) { - s16 stone_level = ground_level; + for (POS z = node_min.Z; z <= node_max.Z; z++) + for (POS x = node_min.X; x <= node_max.X; x++, ni2d++) { + POS stone_level = ground_level; float n_terrain = use_noise ? noise_terrain->result[ni2d] : 0.0f; if ((spflags & MGFLAT_LAKES) && n_terrain < lake_threshold) { - s16 depress = (lake_threshold - n_terrain) * lake_steepness; + POS depress = (lake_threshold - n_terrain) * lake_steepness; stone_level = ground_level - depress; } else if ((spflags & MGFLAT_HILLS) && n_terrain > hill_threshold) { - s16 rise = (n_terrain - hill_threshold) * hill_steepness; + POS rise = (n_terrain - hill_threshold) * hill_steepness; stone_level = ground_level + rise; } u32 vi = vm->m_area.index(x, node_min.Y - 1, z); - for (s16 y = node_min.Y - 1; y <= node_max.Y + 1; y++) { + for (POS y = node_min.Y - 1; y <= node_max.Y + 1; y++) { if (vm->m_data[vi].getContent() == CONTENT_IGNORE) { if (y <= stone_level) { vm->m_data[vi] = n_stone; diff --git a/src/mapgen/mapgen_flat.h b/src/mapgen/mapgen_flat.h index 4b46aff273..82070210c0 100644 --- a/src/mapgen/mapgen_flat.h +++ b/src/mapgen/mapgen_flat.h @@ -33,7 +33,7 @@ extern FlagDesc flagdesc_mapgen_flat[]; struct MapgenFlatParams : public MapgenParams { - s16 ground_level = 8; + POS ground_level = 8; float lake_threshold = -0.45f; float lake_steepness = 48.0f; float hill_threshold = 0.45f; @@ -44,13 +44,13 @@ struct MapgenFlatParams : public MapgenParams u16 small_cave_num_max = 0; u16 large_cave_num_min = 0; u16 large_cave_num_max = 2; - s16 large_cave_depth = -33; + POS large_cave_depth = -33; float large_cave_flooded = 0.5f; - s16 cavern_limit = -256; - s16 cavern_taper = 256; + POS cavern_limit = -256; + POS cavern_taper = 256; float cavern_threshold = 0.7f; - s16 dungeon_ymin = -31000; - s16 dungeon_ymax = 31000; + POS dungeon_ymin = -MAX_MAP_GENERATION_LIMIT; + POS dungeon_ymax = MAX_MAP_GENERATION_LIMIT; NoiseParams np_terrain; NoiseParams np_filler_depth; @@ -76,11 +76,11 @@ class MapgenFlat : public MapgenBasic virtual MapgenType getType() const { return MAPGEN_FLAT; } virtual void makeChunk(BlockMakeData *data); - int getSpawnLevelAtPoint(v2s16 p); - s16 generateTerrain(); + int getSpawnLevelAtPoint(v2POS p); + POS generateTerrain(); private: - s16 ground_level; + POS ground_level; float lake_threshold; float lake_steepness; float hill_threshold; diff --git a/src/mapgen/mapgen_fractal.cpp b/src/mapgen/mapgen_fractal.cpp index fabb1b2b19..6d0c2ce01f 100644 --- a/src/mapgen/mapgen_fractal.cpp +++ b/src/mapgen/mapgen_fractal.cpp @@ -108,14 +108,14 @@ void MapgenFractalParams::readParams(const Settings *settings) { settings->getFlagStrNoEx("mgfractal_spflags", spflags, flagdesc_mapgen_fractal); settings->getFloatNoEx("mgfractal_cave_width", cave_width); - settings->getS16NoEx("mgfractal_large_cave_depth", large_cave_depth); + settings->getPOSNoEx("mgfractal_large_cave_depth", large_cave_depth); settings->getU16NoEx("mgfractal_small_cave_num_min", small_cave_num_min); settings->getU16NoEx("mgfractal_small_cave_num_max", small_cave_num_max); settings->getU16NoEx("mgfractal_large_cave_num_min", large_cave_num_min); settings->getU16NoEx("mgfractal_large_cave_num_max", large_cave_num_max); settings->getFloatNoEx("mgfractal_large_cave_flooded", large_cave_flooded); - settings->getS16NoEx("mgfractal_dungeon_ymin", dungeon_ymin); - settings->getS16NoEx("mgfractal_dungeon_ymax", dungeon_ymax); + settings->getPOSNoEx("mgfractal_dungeon_ymin", dungeon_ymin); + settings->getPOSNoEx("mgfractal_dungeon_ymax", dungeon_ymax); settings->getU16NoEx("mgfractal_fractal", fractal); settings->getU16NoEx("mgfractal_iterations", iterations); settings->getV3FNoEx("mgfractal_scale", scale); @@ -138,14 +138,14 @@ void MapgenFractalParams::writeParams(Settings *settings) const { settings->setFlagStr("mgfractal_spflags", spflags, flagdesc_mapgen_fractal); settings->setFloat("mgfractal_cave_width", cave_width); - settings->setS16("mgfractal_large_cave_depth", large_cave_depth); + settings->setPOS("mgfractal_large_cave_depth", large_cave_depth); settings->setU16("mgfractal_small_cave_num_min", small_cave_num_min); settings->setU16("mgfractal_small_cave_num_max", small_cave_num_max); settings->setU16("mgfractal_large_cave_num_min", large_cave_num_min); settings->setU16("mgfractal_large_cave_num_max", large_cave_num_max); settings->setFloat("mgfractal_large_cave_flooded", large_cave_flooded); - settings->setS16("mgfractal_dungeon_ymin", dungeon_ymin); - settings->setS16("mgfractal_dungeon_ymax", dungeon_ymax); + settings->setPOS("mgfractal_dungeon_ymin", dungeon_ymin); + settings->setPOS("mgfractal_dungeon_ymax", dungeon_ymax); settings->setU16("mgfractal_fractal", fractal); settings->setU16("mgfractal_iterations", iterations); settings->setV3F("mgfractal_scale", scale); @@ -174,19 +174,19 @@ void MapgenFractalParams::setDefaultSettings(Settings *settings) ///////////////////////////////////////////////////////////////// -int MapgenFractal::getSpawnLevelAtPoint(v2s16 p) +int MapgenFractal::getSpawnLevelAtPoint(v2POS p) { bool solid_below = false; // Fractal node is present below to spawn on u8 air_count = 0; // Consecutive air nodes above a fractal node - s16 search_start = 0; // No terrain search start + POS search_start = 0; // No terrain search start // If terrain present, don't start search below terrain or water level if (noise_seabed) { - s16 seabed_level = NoisePerlin2D(&noise_seabed->np, p.X, p.Y, seed); + POS seabed_level = NoisePerlin2D(&noise_seabed->np, p.X, p.Y, seed); search_start = MYMAX(search_start, MYMAX(seabed_level, water_level)); } - for (s16 y = search_start; y <= search_start + 4096; y++) { + for (POS y = search_start; y <= search_start + 4096; y++) { if (getFractalAtPoint(p.X, y, p.Y)) { // Fractal node solid_below = true; @@ -216,17 +216,17 @@ void MapgenFractal::makeChunk(BlockMakeData *data) this->vm = data->vmanip; this->ndef = data->nodedef; - v3s16 blockpos_min = data->blockpos_min; - v3s16 blockpos_max = data->blockpos_max; + v3POS blockpos_min = data->blockpos_min; + v3POS blockpos_max = data->blockpos_max; node_min = blockpos_min * MAP_BLOCKSIZE; - node_max = (blockpos_max + v3s16(1, 1, 1)) * MAP_BLOCKSIZE - v3s16(1, 1, 1); + node_max = (blockpos_max + v3POS(1, 1, 1)) * MAP_BLOCKSIZE - v3POS(1, 1, 1); full_node_min = (blockpos_min - 1) * MAP_BLOCKSIZE; - full_node_max = (blockpos_max + 2) * MAP_BLOCKSIZE - v3s16(1, 1, 1); + full_node_max = (blockpos_max + 2) * MAP_BLOCKSIZE - v3POS(1, 1, 1); blockseed = getBlockSeed2(full_node_min, seed); // Generate fractal and optional terrain - s16 stone_surface_max_y = generateTerrain(); + POS stone_surface_max_y = generateTerrain(); // Create heightmap updateHeightmap(node_min, node_max); @@ -265,7 +265,7 @@ void MapgenFractal::makeChunk(BlockMakeData *data) // Calculate lighting if (flags & MG_LIGHT) - calcLighting(node_min - v3s16(0, 1, 0), node_max + v3s16(0, 1, 0), + calcLighting(node_min - v3POS(0, 1, 0), node_max + v3POS(0, 1, 0), full_node_min, full_node_max); this->generating = false; @@ -274,7 +274,7 @@ void MapgenFractal::makeChunk(BlockMakeData *data) } -bool MapgenFractal::getFractalAtPoint(s16 x, s16 y, s16 z) +bool MapgenFractal::getFractalAtPoint(POS x, POS y, POS z) { float cx, cy, cz, cw, ox, oy, oz, ow; @@ -404,26 +404,26 @@ bool MapgenFractal::getFractalAtPoint(s16 x, s16 y, s16 z) } -s16 MapgenFractal::generateTerrain() +POS MapgenFractal::generateTerrain() { MapNode n_air(CONTENT_AIR); MapNode n_stone(c_stone); MapNode n_water(c_water_source); - s16 stone_surface_max_y = -MAX_MAP_GENERATION_LIMIT; + POS stone_surface_max_y = -MAX_MAP_GENERATION_LIMIT; u32 index2d = 0; if (noise_seabed) noise_seabed->perlinMap2D(node_min.X, node_min.Z); - for (s16 z = node_min.Z; z <= node_max.Z; z++) { - for (s16 y = node_min.Y - 1; y <= node_max.Y + 1; y++) { + for (POS z = node_min.Z; z <= node_max.Z; z++) { + for (POS 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++, vi++, index2d++) { + for (POS x = node_min.X; x <= node_max.X; x++, vi++, index2d++) { if (vm->m_data[vi].getContent() != CONTENT_IGNORE) continue; - s16 seabed_height = -MAX_MAP_GENERATION_LIMIT; + POS seabed_height = -MAX_MAP_GENERATION_LIMIT; if (noise_seabed) seabed_height = noise_seabed->result[index2d]; diff --git a/src/mapgen/mapgen_fractal.h b/src/mapgen/mapgen_fractal.h index 23af925bcc..0e14e5c04c 100644 --- a/src/mapgen/mapgen_fractal.h +++ b/src/mapgen/mapgen_fractal.h @@ -36,14 +36,14 @@ extern FlagDesc flagdesc_mapgen_fractal[]; struct MapgenFractalParams : public MapgenParams { float cave_width = 0.09f; - s16 large_cave_depth = -33; + POS large_cave_depth = -33; u16 small_cave_num_min = 0; u16 small_cave_num_max = 0; u16 large_cave_num_min = 0; u16 large_cave_num_max = 2; float large_cave_flooded = 0.5f; - s16 dungeon_ymin = -31000; - s16 dungeon_ymax = 31000; + POS dungeon_ymin = -MAX_MAP_GENERATION_LIMIT; + POS dungeon_ymax = MAX_MAP_GENERATION_LIMIT; u16 fractal = 1; u16 iterations = 11; v3f scale = v3f(4096.0, 1024.0, 4096.0); @@ -78,9 +78,9 @@ class MapgenFractal : public MapgenBasic virtual MapgenType getType() const { return MAPGEN_FRACTAL; } virtual void makeChunk(BlockMakeData *data); - int getSpawnLevelAtPoint(v2s16 p); - bool getFractalAtPoint(s16 x, s16 y, s16 z); - s16 generateTerrain(); + int getSpawnLevelAtPoint(v2POS p); + bool getFractalAtPoint(POS x, POS y, POS z); + POS generateTerrain(); private: u16 formula; diff --git a/src/mapgen/mapgen_singlenode.cpp b/src/mapgen/mapgen_singlenode.cpp index 5382423fa1..421fde5709 100644 --- a/src/mapgen/mapgen_singlenode.cpp +++ b/src/mapgen/mapgen_singlenode.cpp @@ -55,21 +55,21 @@ void MapgenSinglenode::makeChunk(BlockMakeData *data) this->vm = data->vmanip; this->ndef = data->nodedef; - v3s16 blockpos_min = data->blockpos_min; - v3s16 blockpos_max = data->blockpos_max; + v3BPOS blockpos_min = data->blockpos_min; + v3BPOS blockpos_max = data->blockpos_max; // Area of central chunk - v3s16 node_min = blockpos_min * MAP_BLOCKSIZE; - v3s16 node_max = (blockpos_max + v3s16(1, 1, 1)) * MAP_BLOCKSIZE - v3s16(1, 1, 1); + v3POS node_min = blockpos_min * MAP_BLOCKSIZE; + v3POS node_max = (blockpos_max + v3POS(1, 1, 1)) * MAP_BLOCKSIZE - v3POS(1, 1, 1); blockseed = getBlockSeed2(node_min, data->seed); MapNode n_node(c_node); - for (s16 z = node_min.Z; z <= node_max.Z; z++) - for (s16 y = node_min.Y; y <= node_max.Y; y++) { + for (POS z = node_min.Z; z <= node_max.Z; z++) + for (POS y = node_min.Y; y <= node_max.Y; y++) { u32 i = vm->m_area.index(node_min.X, y, z); - for (s16 x = node_min.X; x <= node_max.X; x++) { + for (POS x = node_min.X; x <= node_max.X; x++) { if (vm->m_data[i].getContent() == CONTENT_IGNORE) vm->m_data[i] = n_node; i++; @@ -87,7 +87,7 @@ void MapgenSinglenode::makeChunk(BlockMakeData *data) } -int MapgenSinglenode::getSpawnLevelAtPoint(v2s16 p) +int MapgenSinglenode::getSpawnLevelAtPoint(v2POS p) { return 0; } diff --git a/src/mapgen/mapgen_singlenode.h b/src/mapgen/mapgen_singlenode.h index e056d9ab16..dcb6f39803 100644 --- a/src/mapgen/mapgen_singlenode.h +++ b/src/mapgen/mapgen_singlenode.h @@ -44,5 +44,5 @@ class MapgenSinglenode : public Mapgen virtual MapgenType getType() const { return MAPGEN_SINGLENODE; } void makeChunk(BlockMakeData *data); - int getSpawnLevelAtPoint(v2s16 p); + int getSpawnLevelAtPoint(v2POS p); }; diff --git a/src/mapgen/mapgen_v5.cpp b/src/mapgen/mapgen_v5.cpp index 87e54755fe..2479aae377 100644 --- a/src/mapgen/mapgen_v5.cpp +++ b/src/mapgen/mapgen_v5.cpp @@ -103,17 +103,17 @@ void MapgenV5Params::readParams(const Settings *settings) { settings->getFlagStrNoEx("mgv5_spflags", spflags, flagdesc_mapgen_v5); settings->getFloatNoEx("mgv5_cave_width", cave_width); - settings->getS16NoEx("mgv5_large_cave_depth", large_cave_depth); + settings->getPOSNoEx("mgv5_large_cave_depth", large_cave_depth); settings->getU16NoEx("mgv5_small_cave_num_min", small_cave_num_min); settings->getU16NoEx("mgv5_small_cave_num_max", small_cave_num_max); settings->getU16NoEx("mgv5_large_cave_num_min", large_cave_num_min); settings->getU16NoEx("mgv5_large_cave_num_max", large_cave_num_max); settings->getFloatNoEx("mgv5_large_cave_flooded", large_cave_flooded); - settings->getS16NoEx("mgv5_cavern_limit", cavern_limit); - settings->getS16NoEx("mgv5_cavern_taper", cavern_taper); + settings->getPOSNoEx("mgv5_cavern_limit", cavern_limit); + settings->getPOSNoEx("mgv5_cavern_taper", cavern_taper); settings->getFloatNoEx("mgv5_cavern_threshold", cavern_threshold); - settings->getS16NoEx("mgv5_dungeon_ymin", dungeon_ymin); - settings->getS16NoEx("mgv5_dungeon_ymax", dungeon_ymax); + settings->getPOSNoEx("mgv5_dungeon_ymin", dungeon_ymin); + settings->getPOSNoEx("mgv5_dungeon_ymax", dungeon_ymax); settings->getNoiseParams("mgv5_np_filler_depth", np_filler_depth); settings->getNoiseParams("mgv5_np_factor", np_factor); @@ -130,17 +130,17 @@ void MapgenV5Params::writeParams(Settings *settings) const { settings->setFlagStr("mgv5_spflags", spflags, flagdesc_mapgen_v5); settings->setFloat("mgv5_cave_width", cave_width); - settings->setS16("mgv5_large_cave_depth", large_cave_depth); + settings->setPOS("mgv5_large_cave_depth", large_cave_depth); settings->setU16("mgv5_small_cave_num_min", small_cave_num_min); settings->setU16("mgv5_small_cave_num_max", small_cave_num_max); settings->setU16("mgv5_large_cave_num_min", large_cave_num_min); settings->setU16("mgv5_large_cave_num_max", large_cave_num_max); settings->setFloat("mgv5_large_cave_flooded", large_cave_flooded); - settings->setS16("mgv5_cavern_limit", cavern_limit); - settings->setS16("mgv5_cavern_taper", cavern_taper); + settings->setPOS("mgv5_cavern_limit", cavern_limit); + settings->setPOS("mgv5_cavern_taper", cavern_taper); settings->setFloat("mgv5_cavern_threshold", cavern_threshold); - settings->setS16("mgv5_dungeon_ymin", dungeon_ymin); - settings->setS16("mgv5_dungeon_ymax", dungeon_ymax); + settings->setPOS("mgv5_dungeon_ymin", dungeon_ymin); + settings->setPOS("mgv5_dungeon_ymax", dungeon_ymax); settings->setNoiseParams("mgv5_np_filler_depth", np_filler_depth); settings->setNoiseParams("mgv5_np_factor", np_factor); @@ -162,7 +162,7 @@ void MapgenV5Params::setDefaultSettings(Settings *settings) ///////////////////////////////////////////////////////////////// -int MapgenV5::getSpawnLevelAtPoint(v2s16 p) +int MapgenV5::getSpawnLevelAtPoint(v2POS p) { float f = 0.55 + NoisePerlin2D(&noise_factor->np, p.X, p.Y, seed); @@ -176,11 +176,11 @@ int MapgenV5::getSpawnLevelAtPoint(v2s16 p) // terrain will be below this. // Raising the maximum spawn level above 'water_level + 16' is necessary // for when noise_height 'offset' is set much higher than water_level. - s16 max_spawn_y = MYMAX(noise_height->np.offset, water_level + 16); + POS max_spawn_y = MYMAX(noise_height->np.offset, water_level + 16); // Starting spawn search at max_spawn_y + 128 ensures 128 nodes of open // space above spawn position. Avoids spawning in possibly sealed voids. - for (s16 y = max_spawn_y + 128; y >= water_level; y--) { + for (POS y = max_spawn_y + 128; y >= water_level; y--) { float n_ground = NoisePerlin3D(&noise_ground->np, p.X, y, p.Y, seed); if (n_ground * f > y - h) { // If solid @@ -207,18 +207,18 @@ void MapgenV5::makeChunk(BlockMakeData *data) this->ndef = data->nodedef; //TimeTaker t("makeChunk"); - v3s16 blockpos_min = data->blockpos_min; - v3s16 blockpos_max = data->blockpos_max; + v3POS blockpos_min = data->blockpos_min; + v3POS blockpos_max = data->blockpos_max; node_min = blockpos_min * MAP_BLOCKSIZE; - node_max = (blockpos_max + v3s16(1, 1, 1)) * MAP_BLOCKSIZE - v3s16(1, 1, 1); + node_max = (blockpos_max + v3POS(1, 1, 1)) * MAP_BLOCKSIZE - v3POS(1, 1, 1); full_node_min = (blockpos_min - 1) * MAP_BLOCKSIZE; - full_node_max = (blockpos_max + 2) * MAP_BLOCKSIZE - v3s16(1, 1, 1); + full_node_max = (blockpos_max + 2) * MAP_BLOCKSIZE - v3POS(1, 1, 1); // Create a block-specific seed blockseed = getBlockSeed2(full_node_min, seed); // Generate base terrain - s16 stone_surface_max_y = generateBaseTerrain(); + POS stone_surface_max_y = generateBaseTerrain(); // Create heightmap updateHeightmap(node_min, node_max); @@ -273,7 +273,7 @@ void MapgenV5::makeChunk(BlockMakeData *data) // Calculate lighting if (flags & MG_LIGHT) { - calcLighting(node_min - v3s16(0, 1, 0), node_max + v3s16(0, 1, 0), + calcLighting(node_min - v3POS(0, 1, 0), node_max + v3POS(0, 1, 0), full_node_min, full_node_max); } @@ -291,10 +291,10 @@ int MapgenV5::generateBaseTerrain() noise_height->perlinMap2D(node_min.X, node_min.Z); noise_ground->perlinMap3D(node_min.X, node_min.Y - 1, node_min.Z); - for (s16 z=node_min.Z; z<=node_max.Z; z++) { - for (s16 y=node_min.Y - 1; y<=node_max.Y + 1; y++) { + for (POS z=node_min.Z; z<=node_max.Z; z++) { + for (POS 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++, vi++, index++, index2d++) { + for (POS x=node_min.X; x<=node_max.X; x++, vi++, index++, index2d++) { if (vm->m_data[vi].getContent() != CONTENT_IGNORE) continue; diff --git a/src/mapgen/mapgen_v5.h b/src/mapgen/mapgen_v5.h index cf4ee48999..cbefb6e9ed 100644 --- a/src/mapgen/mapgen_v5.h +++ b/src/mapgen/mapgen_v5.h @@ -32,17 +32,17 @@ extern FlagDesc flagdesc_mapgen_v5[]; struct MapgenV5Params : public MapgenParams { float cave_width = 0.09f; - s16 large_cave_depth = -256; + POS large_cave_depth = -256; u16 small_cave_num_min = 0; u16 small_cave_num_max = 0; u16 large_cave_num_min = 0; u16 large_cave_num_max = 2; float large_cave_flooded = 0.5f; - s16 cavern_limit = -256; - s16 cavern_taper = 256; + POS cavern_limit = -256; + POS cavern_taper = 256; float cavern_threshold = 0.7f; - s16 dungeon_ymin = -31000; - s16 dungeon_ymax = 31000; + POS dungeon_ymin = -MAX_MAP_GENERATION_LIMIT; + POS dungeon_ymax = MAX_MAP_GENERATION_LIMIT; NoiseParams np_filler_depth; NoiseParams np_factor; @@ -70,7 +70,7 @@ class MapgenV5 : public MapgenBasic virtual MapgenType getType() const { return MAPGEN_V5; } virtual void makeChunk(BlockMakeData *data); - int getSpawnLevelAtPoint(v2s16 p); + int getSpawnLevelAtPoint(v2POS p); int generateBaseTerrain(); private: diff --git a/src/mapgen/mapgen_v6.cpp b/src/mapgen/mapgen_v6.cpp index a418acacea..54cddb18ee 100644 --- a/src/mapgen/mapgen_v6.cpp +++ b/src/mapgen/mapgen_v6.cpp @@ -60,7 +60,7 @@ MapgenV6::MapgenV6(MapgenV6Params *params, EmergeParams *emerge) m_emerge = emerge; ystride = csize.X; - heightmap = new s16[csize.X * csize.Z]; + heightmap = new POS[csize.X * csize.Z]; spflags = params->spflags; freq_desert = params->freq_desert; @@ -186,8 +186,8 @@ void MapgenV6Params::readParams(const Settings *settings) settings->getFlagStrNoEx("mgv6_spflags", spflags, flagdesc_mapgen_v6); settings->getFloatNoEx("mgv6_freq_desert", freq_desert); settings->getFloatNoEx("mgv6_freq_beach", freq_beach); - settings->getS16NoEx("mgv6_dungeon_ymin", dungeon_ymin); - settings->getS16NoEx("mgv6_dungeon_ymax", dungeon_ymax); + settings->getPOSNoEx("mgv6_dungeon_ymin", dungeon_ymin); + settings->getPOSNoEx("mgv6_dungeon_ymax", dungeon_ymax); settings->getNoiseParams("mgv6_np_terrain_base", np_terrain_base); settings->getNoiseParams("mgv6_np_terrain_higher", np_terrain_higher); @@ -208,8 +208,8 @@ void MapgenV6Params::writeParams(Settings *settings) const settings->setFlagStr("mgv6_spflags", spflags, flagdesc_mapgen_v6); settings->setFloat("mgv6_freq_desert", freq_desert); settings->setFloat("mgv6_freq_beach", freq_beach); - settings->setS16("mgv6_dungeon_ymin", dungeon_ymin); - settings->setS16("mgv6_dungeon_ymax", dungeon_ymax); + settings->setPOS("mgv6_dungeon_ymin", dungeon_ymin); + settings->setPOS("mgv6_dungeon_ymax", dungeon_ymax); settings->setNoiseParams("mgv6_np_terrain_base", np_terrain_base); settings->setNoiseParams("mgv6_np_terrain_higher", np_terrain_higher); @@ -236,13 +236,13 @@ void MapgenV6Params::setDefaultSettings(Settings *settings) // Returns Y one under area minimum if not found -s16 MapgenV6::find_stone_level(v2s16 p2d) +POS MapgenV6::find_stone_level(v2POS p2d) { - const v3s16 &em = vm->m_area.getExtent(); - s16 y_nodes_max = vm->m_area.MaxEdge.Y; - s16 y_nodes_min = vm->m_area.MinEdge.Y; + const v3POS &em = vm->m_area.getExtent(); + POS y_nodes_max = vm->m_area.MaxEdge.Y; + POS y_nodes_min = vm->m_area.MinEdge.Y; u32 i = vm->m_area.index(p2d.X, y_nodes_max, p2d.Y); - s16 y; + POS y; for (y = y_nodes_max; y >= y_nodes_min; y--) { content_t c = vm->m_data[i].getContent(); @@ -256,12 +256,12 @@ s16 MapgenV6::find_stone_level(v2s16 p2d) // Required by mapgen.h -bool MapgenV6::block_is_underground(u64 seed, v3s16 blockpos) +bool MapgenV6::block_is_underground(u64 seed, v3POS blockpos) { /*s16 minimum_groundlevel = (s16)get_sector_minimum_ground_level( - seed, v2s16(blockpos.X, blockpos.Z));*/ + seed, v2POS(blockpos.X, blockpos.Z));*/ // Nah, this is just a heuristic, just return something - s16 minimum_groundlevel = water_level; + POS minimum_groundlevel = water_level; if(blockpos.Y * MAP_BLOCKSIZE + MAP_BLOCKSIZE <= minimum_groundlevel) return true; @@ -300,7 +300,7 @@ float MapgenV6::baseTerrainLevel(float terrain_base, float terrain_higher, } -float MapgenV6::baseTerrainLevelFromNoise(v2s16 p) +float MapgenV6::baseTerrainLevelFromNoise(v2POS p) { if (spflags & MGV6_FLAT) return water_level; @@ -319,7 +319,7 @@ float MapgenV6::baseTerrainLevelFromNoise(v2s16 p) } -float MapgenV6::baseTerrainLevelFromMap(v2s16 p) +float MapgenV6::baseTerrainLevelFromMap(v2POS p) { int index = (p.Y - node_min.Z) * ystride + (p.X - node_min.X); return baseTerrainLevelFromMap(index); @@ -341,15 +341,15 @@ float MapgenV6::baseTerrainLevelFromMap(int index) } -int MapgenV6::getGroundLevelAtPoint(v2s16 p) +int MapgenV6::getGroundLevelAtPoint(v2POS p) { return baseTerrainLevelFromNoise(p) + MGV6_AVERAGE_MUD_AMOUNT; } -int MapgenV6::getSpawnLevelAtPoint(v2s16 p) +int MapgenV6::getSpawnLevelAtPoint(v2POS p) { - s16 level_at_point = baseTerrainLevelFromNoise(p) + MGV6_AVERAGE_MUD_AMOUNT; + POS level_at_point = baseTerrainLevelFromNoise(p) + MGV6_AVERAGE_MUD_AMOUNT; if (level_at_point <= water_level || level_at_point > water_level + 16) return MAX_MAP_GENERATION_LIMIT; // Unsuitable spawn point @@ -361,7 +361,7 @@ int MapgenV6::getSpawnLevelAtPoint(v2s16 p) //////////////////////// Noise functions -BiomeV6Type MapgenV6::getBiome(v2s16 p) +BiomeV6Type MapgenV6::getBiome(v2POS p) { int index = (p.Y - full_node_min.Z) * (ystride + 2 * MAP_BLOCKSIZE) + (p.X - full_node_min.X); @@ -369,7 +369,7 @@ BiomeV6Type MapgenV6::getBiome(v2s16 p) } -float MapgenV6::getHumidity(v2s16 p) +float MapgenV6::getHumidity(v2POS p) { /*double noise = noise2d_perlin( 0.5+(float)p.X/500, 0.5+(float)p.Y/500, @@ -388,7 +388,7 @@ float MapgenV6::getHumidity(v2s16 p) } -float MapgenV6::getTreeAmount(v2s16 p) +float MapgenV6::getTreeAmount(v2POS p) { /*double noise = noise2d_perlin( 0.5+(float)p.X/125, 0.5+(float)p.Y/125, @@ -403,7 +403,7 @@ float MapgenV6::getTreeAmount(v2s16 p) } -bool MapgenV6::getHaveAppleTree(v2s16 p) +bool MapgenV6::getHaveAppleTree(v2POS p) { /*is_apple_tree = noise2d_perlin( 0.5+(float)p.X/100, 0.5+(float)p.Z/100, @@ -440,7 +440,7 @@ bool MapgenV6::getHaveBeach(int index) } -BiomeV6Type MapgenV6::getBiome(int index, v2s16 p) +BiomeV6Type MapgenV6::getBiome(int index, v2POS p) { // Just do something very simple as for now /*double d = noise2d_perlin( @@ -485,7 +485,7 @@ BiomeV6Type MapgenV6::getBiome(int index, v2s16 p) } -u32 MapgenV6::get_blockseed(u64 seed, v3s16 p) +u32 MapgenV6::get_blockseed(u64 seed, v3POS p) { s32 x = p.X, y = p.Y, z = p.Z; return (u32)(seed % 0x100000000ULL) + z * 38134234 + y * 42123 + x * 23; @@ -505,18 +505,18 @@ void MapgenV6::makeChunk(BlockMakeData *data) this->ndef = data->nodedef; // Hack: use minimum block coords for old code that assumes a single block - v3s16 blockpos_min = data->blockpos_min; - v3s16 blockpos_max = data->blockpos_max; + v3BPOS blockpos_min = data->blockpos_min; + v3BPOS blockpos_max = data->blockpos_max; // Area of central chunk node_min = blockpos_min * MAP_BLOCKSIZE; - node_max = (blockpos_max + v3s16(1, 1, 1)) * MAP_BLOCKSIZE - v3s16(1, 1, 1); + node_max = (blockpos_max + v3POS(1, 1, 1)) * MAP_BLOCKSIZE - v3POS(1, 1, 1); // Full allocated area full_node_min = (blockpos_min - 1) * MAP_BLOCKSIZE; - full_node_max = (blockpos_max + 2) * MAP_BLOCKSIZE - v3s16(1, 1, 1); + full_node_max = (blockpos_max + 2) * MAP_BLOCKSIZE - v3POS(1, 1, 1); - central_area_size = node_max - node_min + v3s16(1, 1, 1); + central_area_size = node_max - node_min + v3POS(1, 1, 1); assert(central_area_size.X == central_area_size.Z); // Create a block-specific seed @@ -527,7 +527,7 @@ void MapgenV6::makeChunk(BlockMakeData *data) // Maximum height of the stone surface and obstacles. // This is used to guide the cave generation - s16 stone_surface_max_y; + POS stone_surface_max_y; // Generate general ground level to full area stone_surface_max_y = generateGround(); @@ -537,8 +537,8 @@ void MapgenV6::makeChunk(BlockMakeData *data) const s16 max_spread_amount = MAP_BLOCKSIZE; // Limit dirt flow area by 1 because mud is flowed into neighbors - s16 mudflow_minpos = -max_spread_amount + 1; - s16 mudflow_maxpos = central_area_size.X + max_spread_amount - 2; + POS mudflow_minpos = -max_spread_amount + 1; + POS mudflow_maxpos = central_area_size.X + max_spread_amount - 2; // Loop this part, it will make stuff look older and newer nicely const u32 age_loops = 2; @@ -581,17 +581,17 @@ void MapgenV6::makeChunk(BlockMakeData *data) dp.np_alt_wall = NoiseParams(-0.4, 1.0, v3f(40.0, 40.0, 40.0), 32474, 6, 1.1, 2.0); - if (getBiome(0, v2s16(node_min.X, node_min.Z)) == BT_DESERT) { + if (getBiome(0, v2POS(node_min.X, node_min.Z)) == BT_DESERT) { dp.c_wall = c_desert_stone; dp.c_alt_wall = CONTENT_IGNORE; dp.c_stair = c_stair_desert_stone; dp.diagonal_dirs = true; - dp.holesize = v3s16(2, 3, 2); - dp.room_size_min = v3s16(6, 9, 6); - dp.room_size_max = v3s16(10, 11, 10); - dp.room_size_large_min = v3s16(10, 13, 10); - dp.room_size_large_max = v3s16(18, 21, 18); + dp.holesize = v3POS(2, 3, 2); + dp.room_size_min = v3POS(6, 9, 6); + dp.room_size_max = v3POS(10, 11, 10); + dp.room_size_large_min = v3POS(10, 13, 10); + dp.room_size_large_max = v3POS(18, 21, 18); dp.notifytype = GENNOTIFY_TEMPLE; } else { dp.c_wall = c_cobble; @@ -599,11 +599,11 @@ void MapgenV6::makeChunk(BlockMakeData *data) dp.c_stair = c_stair_cobble; dp.diagonal_dirs = false; - dp.holesize = v3s16(1, 2, 1); - dp.room_size_min = v3s16(4, 4, 4); - dp.room_size_max = v3s16(8, 6, 8); - dp.room_size_large_min = v3s16(8, 8, 8); - dp.room_size_large_max = v3s16(16, 16, 16); + dp.holesize = v3POS(1, 2, 1); + dp.room_size_min = v3POS(4, 4, 4); + dp.room_size_max = v3POS(8, 6, 8); + dp.room_size_large_min = v3POS(8, 8, 8); + dp.room_size_large_max = v3POS(16, 16, 16); dp.notifytype = GENNOTIFY_DUNGEON; } @@ -632,8 +632,8 @@ void MapgenV6::makeChunk(BlockMakeData *data) // Calculate lighting if (flags & MG_LIGHT) - calcLighting(node_min - v3s16(1, 1, 1) * MAP_BLOCKSIZE, - node_max + v3s16(1, 0, 1) * MAP_BLOCKSIZE, + calcLighting(node_min - v3POS(1, 1, 1) * MAP_BLOCKSIZE, + node_max + v3POS(1, 0, 1) * MAP_BLOCKSIZE, full_node_min, full_node_max); this->generating = false; @@ -673,21 +673,21 @@ int MapgenV6::generateGround() int stone_surface_max_y = -MAX_MAP_GENERATION_LIMIT; u32 index = 0; - for (s16 z = node_min.Z; z <= node_max.Z; z++) - for (s16 x = node_min.X; x <= node_max.X; x++, index++) { + for (POS z = node_min.Z; z <= node_max.Z; z++) + for (POS x = node_min.X; x <= node_max.X; x++, index++) { // Surface height - s16 surface_y = (s16)baseTerrainLevelFromMap(index); + POS surface_y = (POS)baseTerrainLevelFromMap(index); // Log it if (surface_y > stone_surface_max_y) stone_surface_max_y = surface_y; - BiomeV6Type bt = getBiome(v2s16(x, z)); + BiomeV6Type bt = getBiome(v2POS(x, z)); // Fill ground with stone - const v3s16 &em = vm->m_area.getExtent(); + const v3POS &em = vm->m_area.getExtent(); u32 i = vm->m_area.index(x, node_min.Y, z); - for (s16 y = node_min.Y; y <= node_max.Y; y++) { + for (POS y = node_min.Y; y <= node_max.Y; y++) { if (vm->m_data[i].getContent() == CONTENT_IGNORE) { if (y <= surface_y) { vm->m_data[i] = (y >= MGV6_DESERT_STONE_BASE @@ -718,19 +718,19 @@ void MapgenV6::addMud() MapNode addnode; u32 index = 0; - for (s16 z = node_min.Z; z <= node_max.Z; z++) - for (s16 x = node_min.X; x <= node_max.X; x++, index++) { + for (POS z = node_min.Z; z <= node_max.Z; z++) + for (POS x = node_min.X; x <= node_max.X; x++, index++) { // Randomize mud amount s16 mud_add_amount = getMudAmount(index) / 2.0 + 0.5; // Find ground level - s16 surface_y = find_stone_level(v2s16(x, z)); /////////////////optimize this! + POS surface_y = find_stone_level(v2POS(x, z)); /////////////////optimize this! // Handle area not found if (surface_y == vm->m_area.MinEdge.Y - 1) continue; - BiomeV6Type bt = getBiome(v2s16(x, z)); + BiomeV6Type bt = getBiome(v2POS(x, z)); addnode = (bt == BT_DESERT) ? n_desert_sand : n_dirt; if (bt == BT_DESERT && surface_y + mud_add_amount <= water_level + 1) { @@ -754,10 +754,10 @@ void MapgenV6::addMud() // Add mud on ground s16 mudcount = 0; - const v3s16 &em = vm->m_area.getExtent(); - s16 y_start = surface_y + 1; + const v3POS &em = vm->m_area.getExtent(); + POS y_start = surface_y + 1; u32 i = vm->m_area.index(x, y_start, z); - for (s16 y = y_start; y <= node_max.Y; y++) { + for (POS y = y_start; y <= node_max.Y; y++) { if (mudcount >= mud_add_amount) break; @@ -770,30 +770,30 @@ void MapgenV6::addMud() } -void MapgenV6::flowMud(s16 &mudflow_minpos, s16 &mudflow_maxpos) +void MapgenV6::flowMud(POS &mudflow_minpos, POS &mudflow_maxpos) { - const v3s16 &em = vm->m_area.getExtent(); - static const v3s16 dirs4[4] = { - v3s16(0, 0, 1), // Back - v3s16(1, 0, 0), // Right - v3s16(0, 0, -1), // Front - v3s16(-1, 0, 0), // Left + const v3POS &em = vm->m_area.getExtent(); + static const v3POS dirs4[4] = { + v3POS(0, 0, 1), // Back + v3POS(1, 0, 0), // Right + v3POS(0, 0, -1), // Front + v3POS(-1, 0, 0), // Left }; // Iterate twice for (s16 k = 0; k < 2; k++) { - for (s16 z = mudflow_minpos; z <= mudflow_maxpos; z++) - for (s16 x = mudflow_minpos; x <= mudflow_maxpos; x++) { + for (POS z = mudflow_minpos; z <= mudflow_maxpos; z++) + for (POS x = mudflow_minpos; x <= mudflow_maxpos; x++) { // Node column position - v2s16 p2d; + v2POS p2d; // Invert coordinates on second iteration to process columns in // opposite order, to avoid a directional bias. if (k == 1) - p2d = v2s16(node_max.X, node_max.Z) - v2s16(x, z); + p2d = v2POS(node_max.X, node_max.Z) - v2POS(x, z); else - p2d = v2s16(node_min.X, node_min.Z) + v2s16(x, z); + p2d = v2POS(node_min.X, node_min.Z) + v2POS(x, z); - s16 y = node_max.Y; + POS y = node_max.Y; while (y >= node_min.Y) { for (;; y--) { @@ -838,7 +838,7 @@ void MapgenV6::flowMud(s16 &mudflow_minpos, s16 &mudflow_maxpos) continue; // Drop mud on one side - for (const v3s16 &dirp : dirs4) { + for (const v3POS &dirp : dirs4) { u32 i2 = i; // Move to side VoxelArea::add_p(em, i2, dirp); @@ -854,7 +854,7 @@ void MapgenV6::flowMud(s16 &mudflow_minpos, s16 &mudflow_maxpos) continue; // Loop further down until not air - s16 y2 = y - 1; // y of i2 + POS y2 = y - 1; // y of i2 bool dropped_to_unknown = false; do { y2--; @@ -885,7 +885,7 @@ void MapgenV6::flowMud(s16 &mudflow_minpos, s16 &mudflow_maxpos) void MapgenV6::moveMud(u32 remove_index, u32 place_index, - u32 above_remove_index, v2s16 pos, v3s16 em) + u32 above_remove_index, v2POS pos, v3POS em) { MapNode n_air(CONTENT_AIR); // Copy mud from old place to new place @@ -935,7 +935,7 @@ void MapgenV6::placeTreesAndJungleGrass() if (c_junglegrass == CONTENT_IGNORE) c_junglegrass = CONTENT_AIR; MapNode n_junglegrass(c_junglegrass); - const v3s16 &em = vm->m_area.getExtent(); + const v3POS &em = vm->m_area.getExtent(); // Divide area into parts s16 div = 8; @@ -947,17 +947,17 @@ void MapgenV6::placeTreesAndJungleGrass() for (s16 z0 = 0; z0 < div; z0++) for (s16 x0 = 0; x0 < div; x0++) { // Center position of part of division - v2s16 p2d_center( + v2POS p2d_center( node_min.X + sidelen / 2 + sidelen * x0, node_min.Z + sidelen / 2 + sidelen * z0 ); // Minimum edge of part of division - v2s16 p2d_min( + v2POS p2d_min( node_min.X + sidelen * x0, node_min.Z + sidelen * z0 ); // Maximum edge of part of division - v2s16 p2d_max( + v2POS p2d_max( node_min.X + sidelen + sidelen * x0 - 1, node_min.Z + sidelen + sidelen * z0 - 1 ); @@ -980,11 +980,11 @@ void MapgenV6::placeTreesAndJungleGrass() float humidity = getHumidity(p2d_center); u32 grass_count = 5 * humidity * tree_count; for (u32 i = 0; i < grass_count; i++) { - s16 x = grassrandom.range(p2d_min.X, p2d_max.X); - s16 z = grassrandom.range(p2d_min.Y, p2d_max.Y); + POS x = grassrandom.range(p2d_min.X, p2d_max.X); + POS z = grassrandom.range(p2d_min.Y, p2d_max.Y); int mapindex = central_area_size.X * (z - node_min.Z) + (x - node_min.X); - s16 y = heightmap[mapindex]; + POS y = heightmap[mapindex]; if (y < water_level) continue; @@ -999,17 +999,17 @@ void MapgenV6::placeTreesAndJungleGrass() // Put trees in random places on part of division for (u32 i = 0; i < tree_count; i++) { - s16 x = myrand_range(p2d_min.X, p2d_max.X); - s16 z = myrand_range(p2d_min.Y, p2d_max.Y); + POS x = myrand_range(p2d_min.X, p2d_max.X); + POS z = myrand_range(p2d_min.Y, p2d_max.Y); int mapindex = central_area_size.X * (z - node_min.Z) + (x - node_min.X); - s16 y = heightmap[mapindex]; + POS y = heightmap[mapindex]; // Don't make a tree under water level // Don't make a tree so high that it doesn't fit if (y < water_level || y > node_max.Y - 6) continue; - v3s16 p(x, y, z); + v3POS p(x, y, z); // Trees grow only on mud and grass { u32 i = vm->m_area.index(p); @@ -1025,10 +1025,10 @@ void MapgenV6::placeTreesAndJungleGrass() if (bt == BT_JUNGLE) { treegen::make_jungletree(*vm, p, ndef, myrand()); } else if (bt == BT_TAIGA) { - treegen::make_pine_tree(*vm, p - v3s16(0, 1, 0), ndef, myrand()); + treegen::make_pine_tree(*vm, p - v3POS(0, 1, 0), ndef, myrand()); } else if (bt == BT_NORMAL) { bool is_apple_tree = (myrand_range(0, 3) == 0) && - getHaveAppleTree(v2s16(x, z)); + getHaveAppleTree(v2POS(x, z)); treegen::make_tree(*vm, p, is_apple_tree, ndef, myrand()); } } @@ -1042,17 +1042,17 @@ void MapgenV6::growGrass() // Add surface nodes MapNode n_dirt_with_grass(c_dirt_with_grass); MapNode n_dirt_with_snow(c_dirt_with_snow); MapNode n_snowblock(c_snowblock); - const v3s16 &em = vm->m_area.getExtent(); + const v3POS &em = vm->m_area.getExtent(); u32 index = 0; - for (s16 z = full_node_min.Z; z <= full_node_max.Z; z++) - for (s16 x = full_node_min.X; x <= full_node_max.X; x++, index++) { + for (POS z = full_node_min.Z; z <= full_node_max.Z; z++) + for (POS x = full_node_min.X; x <= full_node_max.X; x++, index++) { // Find the lowest surface to which enough light ends up to make // grass grow. Basically just wait until not air and not leaves. - s16 surface_y = 0; + POS surface_y = 0; { u32 i = vm->m_area.index(x, node_max.Y, z); - s16 y; + POS y; // Go to ground level for (y = node_max.Y; y >= full_node_min.Y; y--) { MapNode &n = vm->m_data[i]; @@ -1065,7 +1065,7 @@ void MapgenV6::growGrass() // Add surface nodes surface_y = (y >= full_node_min.Y) ? y : full_node_min.Y; } - BiomeV6Type bt = getBiome(index, v2s16(x, z)); + BiomeV6Type bt = getBiome(index, v2POS(x, z)); u32 i = vm->m_area.index(x, surface_y, z); content_t c = vm->m_data[i].getContent(); if (surface_y >= water_level - 20) { @@ -1102,7 +1102,7 @@ void MapgenV6::generateCaves(int max_stone_y) if (ps.range(1, 6) == 1) bruises_count = ps.range(0, ps.range(0, 2)); - if (getBiome(v2s16(node_min.X, node_min.Z)) == BT_DESERT) { + if (getBiome(v2POS(node_min.X, node_min.Z)) == BT_DESERT) { caves_count /= 3; bruises_count /= 3; } diff --git a/src/mapgen/mapgen_v6.h b/src/mapgen/mapgen_v6.h index b0eb67893c..445505bd6d 100644 --- a/src/mapgen/mapgen_v6.h +++ b/src/mapgen/mapgen_v6.h @@ -57,8 +57,8 @@ enum BiomeV6Type struct MapgenV6Params : public MapgenParams { float freq_desert = 0.45f; float freq_beach = 0.15f; - s16 dungeon_ymin = -31000; - s16 dungeon_ymax = 31000; + POS dungeon_ymin = -MAX_MAP_GENERATION_LIMIT; + POS dungeon_ymax = MAX_MAP_GENERATION_LIMIT; NoiseParams np_terrain_base; NoiseParams np_terrain_higher; @@ -88,11 +88,11 @@ class MapgenV6 : public Mapgen { int ystride; u32 spflags; - v3s16 node_min; - v3s16 node_max; - v3s16 full_node_min; - v3s16 full_node_max; - v3s16 central_area_size; + v3POS node_min; + v3POS node_max; + v3POS full_node_min; + v3POS full_node_max; + v3POS central_area_size; Noise *noise_terrain_base; Noise *noise_terrain_higher; @@ -111,8 +111,8 @@ class MapgenV6 : public Mapgen { float freq_desert; float freq_beach; - s16 dungeon_ymin; - s16 dungeon_ymax; + POS dungeon_ymin; + POS dungeon_ymax; content_t c_stone; content_t c_dirt; @@ -139,34 +139,34 @@ class MapgenV6 : public Mapgen { virtual MapgenType getType() const { return MAPGEN_V6; } void makeChunk(BlockMakeData *data); - int getGroundLevelAtPoint(v2s16 p); - int getSpawnLevelAtPoint(v2s16 p); + int getGroundLevelAtPoint(v2POS p); + int getSpawnLevelAtPoint(v2POS p); float baseTerrainLevel(float terrain_base, float terrain_higher, float steepness, float height_select); - virtual float baseTerrainLevelFromNoise(v2s16 p); - virtual float baseTerrainLevelFromMap(v2s16 p); + virtual float baseTerrainLevelFromNoise(v2POS p); + virtual float baseTerrainLevelFromMap(v2POS p); virtual float baseTerrainLevelFromMap(int index); - s16 find_stone_level(v2s16 p2d); - bool block_is_underground(u64 seed, v3s16 blockpos); + POS find_stone_level(v2POS p2d); + bool block_is_underground(u64 seed, v3POS blockpos); - float getHumidity(v2s16 p); - float getTreeAmount(v2s16 p); - bool getHaveAppleTree(v2s16 p); + float getHumidity(v2POS p); + float getTreeAmount(v2POS p); + bool getHaveAppleTree(v2POS p); float getMudAmount(int index); bool getHaveBeach(int index); - BiomeV6Type getBiome(v2s16 p); - BiomeV6Type getBiome(int index, v2s16 p); + BiomeV6Type getBiome(v2POS p); + BiomeV6Type getBiome(int index, v2POS p); - u32 get_blockseed(u64 seed, v3s16 p); + u32 get_blockseed(u64 seed, v3POS p); virtual void calculateNoise(); int generateGround(); void addMud(); - void flowMud(s16 &mudflow_minpos, s16 &mudflow_maxpos); + void flowMud(POS &mudflow_minpos, POS &mudflow_maxpos); void moveMud(u32 remove_index, u32 place_index, - u32 above_remove_index, v2s16 pos, v3s16 em); + u32 above_remove_index, v2POS pos, v3POS em); void growGrass(); void placeTreesAndJungleGrass(); virtual void generateCaves(int max_stone_y); diff --git a/src/mapgen/mapgen_v7.cpp b/src/mapgen/mapgen_v7.cpp index 91f004518a..d81f3388a3 100644 --- a/src/mapgen/mapgen_v7.cpp +++ b/src/mapgen/mapgen_v7.cpp @@ -172,26 +172,26 @@ MapgenV7Params::MapgenV7Params(): void MapgenV7Params::readParams(const Settings *settings) { settings->getFlagStrNoEx("mgv7_spflags", spflags, flagdesc_mapgen_v7); - settings->getS16NoEx("mgv7_mount_zero_level", mount_zero_level); - settings->getS16NoEx("mgv7_floatland_ymin", floatland_ymin); - settings->getS16NoEx("mgv7_floatland_ymax", floatland_ymax); - settings->getS16NoEx("mgv7_floatland_taper", floatland_taper); + settings->getPOSNoEx("mgv7_mount_zero_level", mount_zero_level); + settings->getPOSNoEx("mgv7_floatland_ymin", floatland_ymin); + settings->getPOSNoEx("mgv7_floatland_ymax", floatland_ymax); + settings->getPOSNoEx("mgv7_floatland_taper", floatland_taper); settings->getFloatNoEx("mgv7_float_taper_exp", float_taper_exp); settings->getFloatNoEx("mgv7_floatland_density", floatland_density); - settings->getS16NoEx("mgv7_floatland_ywater", floatland_ywater); + settings->getPOSNoEx("mgv7_floatland_ywater", floatland_ywater); settings->getFloatNoEx("mgv7_cave_width", cave_width); - settings->getS16NoEx("mgv7_large_cave_depth", large_cave_depth); + settings->getPOSNoEx("mgv7_large_cave_depth", large_cave_depth); settings->getU16NoEx("mgv7_small_cave_num_min", small_cave_num_min); settings->getU16NoEx("mgv7_small_cave_num_max", small_cave_num_max); settings->getU16NoEx("mgv7_large_cave_num_min", large_cave_num_min); settings->getU16NoEx("mgv7_large_cave_num_max", large_cave_num_max); settings->getFloatNoEx("mgv7_large_cave_flooded", large_cave_flooded); - settings->getS16NoEx("mgv7_cavern_limit", cavern_limit); - settings->getS16NoEx("mgv7_cavern_taper", cavern_taper); + settings->getPOSNoEx("mgv7_cavern_limit", cavern_limit); + settings->getPOSNoEx("mgv7_cavern_taper", cavern_taper); settings->getFloatNoEx("mgv7_cavern_threshold", cavern_threshold); - settings->getS16NoEx("mgv7_dungeon_ymin", dungeon_ymin); - settings->getS16NoEx("mgv7_dungeon_ymax", dungeon_ymax); + settings->getPOSNoEx("mgv7_dungeon_ymin", dungeon_ymin); + settings->getPOSNoEx("mgv7_dungeon_ymax", dungeon_ymax); settings->getNoiseParams("mgv7_np_terrain_base", np_terrain_base); settings->getNoiseParams("mgv7_np_terrain_alt", np_terrain_alt); @@ -213,26 +213,26 @@ void MapgenV7Params::readParams(const Settings *settings) void MapgenV7Params::writeParams(Settings *settings) const { settings->setFlagStr("mgv7_spflags", spflags, flagdesc_mapgen_v7); - settings->setS16("mgv7_mount_zero_level", mount_zero_level); - settings->setS16("mgv7_floatland_ymin", floatland_ymin); - settings->setS16("mgv7_floatland_ymax", floatland_ymax); - settings->setS16("mgv7_floatland_taper", floatland_taper); + settings->setPOS("mgv7_mount_zero_level", mount_zero_level); + settings->setPOS("mgv7_floatland_ymin", floatland_ymin); + settings->setPOS("mgv7_floatland_ymax", floatland_ymax); + settings->setPOS("mgv7_floatland_taper", floatland_taper); settings->setFloat("mgv7_float_taper_exp", float_taper_exp); settings->setFloat("mgv7_floatland_density", floatland_density); - settings->setS16("mgv7_floatland_ywater", floatland_ywater); + settings->setPOS("mgv7_floatland_ywater", floatland_ywater); settings->setFloat("mgv7_cave_width", cave_width); - settings->setS16("mgv7_large_cave_depth", large_cave_depth); + settings->setPOS("mgv7_large_cave_depth", large_cave_depth); settings->setU16("mgv7_small_cave_num_min", small_cave_num_min); settings->setU16("mgv7_small_cave_num_max", small_cave_num_max); settings->setU16("mgv7_large_cave_num_min", large_cave_num_min); settings->setU16("mgv7_large_cave_num_max", large_cave_num_max); settings->setFloat("mgv7_large_cave_flooded", large_cave_flooded); - settings->setS16("mgv7_cavern_limit", cavern_limit); - settings->setS16("mgv7_cavern_taper", cavern_taper); + settings->setPOS("mgv7_cavern_limit", cavern_limit); + settings->setPOS("mgv7_cavern_taper", cavern_taper); settings->setFloat("mgv7_cavern_threshold", cavern_threshold); - settings->setS16("mgv7_dungeon_ymin", dungeon_ymin); - settings->setS16("mgv7_dungeon_ymax", dungeon_ymax); + settings->setPOS("mgv7_dungeon_ymin", dungeon_ymin); + settings->setPOS("mgv7_dungeon_ymax", dungeon_ymax); settings->setNoiseParams("mgv7_np_terrain_base", np_terrain_base); settings->setNoiseParams("mgv7_np_terrain_alt", np_terrain_alt); @@ -261,7 +261,7 @@ void MapgenV7Params::setDefaultSettings(Settings *settings) //////////////////////////////////////////////////////////////////////////////// -int MapgenV7::getSpawnLevelAtPoint(v2s16 p) +int MapgenV7::getSpawnLevelAtPoint(v2POS p) { // If rivers are enabled, first check if in a river if (spflags & MGV7_RIDGES) { @@ -277,11 +277,11 @@ int MapgenV7::getSpawnLevelAtPoint(v2s16 p) // 'offset's. // Raising the maximum spawn level above 'water_level + 16' is necessary // for when terrain 'offset's are set much higher than water_level. - s16 max_spawn_y = std::fmax(std::fmax(noise_terrain_alt->np.offset, + POS max_spawn_y = std::fmax(std::fmax(noise_terrain_alt->np.offset, noise_terrain_base->np.offset), water_level + 16); // Base terrain calculation - s16 y = baseTerrainLevelAtPoint(p.X, p.Y); + POS y = baseTerrainLevelAtPoint(p.X, p.Y); // If mountains are disabled, terrain level is base terrain level. // Avoids mid-air spawn where mountain terrain would have been. @@ -324,17 +324,17 @@ void MapgenV7::makeChunk(BlockMakeData *data) this->vm = data->vmanip; this->ndef = data->nodedef; - v3s16 blockpos_min = data->blockpos_min; - v3s16 blockpos_max = data->blockpos_max; + v3POS blockpos_min = data->blockpos_min; + v3POS blockpos_max = data->blockpos_max; node_min = blockpos_min * MAP_BLOCKSIZE; - node_max = (blockpos_max + v3s16(1, 1, 1)) * MAP_BLOCKSIZE - v3s16(1, 1, 1); + node_max = (blockpos_max + v3POS(1, 1, 1)) * MAP_BLOCKSIZE - v3POS(1, 1, 1); full_node_min = (blockpos_min - 1) * MAP_BLOCKSIZE; - full_node_max = (blockpos_max + 2) * MAP_BLOCKSIZE - v3s16(1, 1, 1); + full_node_max = (blockpos_max + 2) * MAP_BLOCKSIZE - v3POS(1, 1, 1); blockseed = getBlockSeed2(full_node_min, seed); // Generate base and mountain terrain - s16 stone_surface_max_y = generateTerrain(); + POS stone_surface_max_y = generateTerrain(); // Create heightmap updateHeightmap(node_min, node_max); @@ -391,7 +391,7 @@ void MapgenV7::makeChunk(BlockMakeData *data) node_max.Y >= floatland_ymin - csize.Y * 2 && node_min.Y <= floatland_ymax); if (flags & MG_LIGHT) - calcLighting(node_min - v3s16(0, 1, 0), node_max + v3s16(0, 1, 0), + calcLighting(node_min - v3POS(0, 1, 0), node_max + v3POS(0, 1, 0), full_node_min, full_node_max, propagate_shadow); this->generating = false; @@ -403,7 +403,7 @@ void MapgenV7::makeChunk(BlockMakeData *data) //////////////////////////////////////////////////////////////////////////////// -float MapgenV7::baseTerrainLevelAtPoint(s16 x, s16 z) +float MapgenV7::baseTerrainLevelAtPoint(POS x, POS z) { float hselect = NoisePerlin2D(&noise_height_select->np, x, z, seed); hselect = rangelim(hselect, 0.0f, 1.0f); @@ -436,7 +436,7 @@ float MapgenV7::baseTerrainLevelFromMap(int index) } -bool MapgenV7::getMountainTerrainAtPoint(s16 x, s16 y, s16 z) +bool MapgenV7::getMountainTerrainAtPoint(POS x, POS y, POS z) { float mnt_h_n = std::fmax(NoisePerlin2D(&noise_mount_height->np, x, z, seed), 1.0f); @@ -447,7 +447,7 @@ bool MapgenV7::getMountainTerrainAtPoint(s16 x, s16 y, s16 z) } -bool MapgenV7::getMountainTerrainFromMap(int idx_xyz, int idx_xz, s16 y) +bool MapgenV7::getMountainTerrainFromMap(int idx_xyz, int idx_xz, POS y) { float mounthn = std::fmax(noise_mount_height->result[idx_xz], 1.0f); float density_gradient = -((float)(y - mount_zero_level) / mounthn); @@ -457,7 +457,7 @@ bool MapgenV7::getMountainTerrainFromMap(int idx_xyz, int idx_xz, s16 y) } -bool MapgenV7::getRiverChannelFromMap(int idx_xyz, int idx_xz, s16 y) +bool MapgenV7::getRiverChannelFromMap(int idx_xyz, int idx_xz, POS y) { // Maximum width of river channel. Creates the vertical canyon walls float width = 0.2f; @@ -505,8 +505,8 @@ int MapgenV7::generateTerrain() bool gen_floatlands = false; u8 cache_index = 0; // Y values where floatland tapering starts - s16 float_taper_ymax = floatland_ymax - floatland_taper; - s16 float_taper_ymin = floatland_ymin + floatland_taper; + POS float_taper_ymax = floatland_ymax - floatland_taper; + POS float_taper_ymin = floatland_ymin + floatland_taper; if ((spflags & MGV7_FLOATLANDS) && node_max.Y >= floatland_ymin && node_min.Y <= floatland_ymax) { @@ -515,7 +515,7 @@ int MapgenV7::generateTerrain() noise_floatland->perlinMap3D(node_min.X, node_min.Y - 1, node_min.Z); // Cache floatland noise offset values, for floatland tapering - for (s16 y = node_min.Y - 1; y <= node_max.Y + 1; y++, cache_index++) { + for (POS y = node_min.Y - 1; y <= node_max.Y + 1; y++, cache_index++) { float float_offset = 0.0f; if (y > float_taper_ymax) { float_offset = std::pow((y - float_taper_ymax) / (float)floatland_taper, @@ -538,13 +538,13 @@ int MapgenV7::generateTerrain() } //// Place nodes - const v3s16 &em = vm->m_area.getExtent(); - s16 stone_surface_max_y = -MAX_MAP_GENERATION_LIMIT; + const v3POS &em = vm->m_area.getExtent(); + POS stone_surface_max_y = -MAX_MAP_GENERATION_LIMIT; u32 index2d = 0; - for (s16 z = node_min.Z; z <= node_max.Z; z++) - for (s16 x = node_min.X; x <= node_max.X; x++, index2d++) { - s16 surface_y = baseTerrainLevelFromMap(index2d); + for (POS z = node_min.Z; z <= node_max.Z; z++) + for (POS x = node_min.X; x <= node_max.X; x++, index2d++) { + POS surface_y = baseTerrainLevelFromMap(index2d); if (surface_y > stone_surface_max_y) stone_surface_max_y = surface_y; @@ -552,7 +552,7 @@ int MapgenV7::generateTerrain() 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; + for (POS y = node_min.Y - 1; y <= node_max.Y + 1; y++, index3d += ystride, VoxelArea::add_y(em, vi, 1), diff --git a/src/mapgen/mapgen_v7.h b/src/mapgen/mapgen_v7.h index 5db10a3049..c1fc864d03 100644 --- a/src/mapgen/mapgen_v7.h +++ b/src/mapgen/mapgen_v7.h @@ -35,26 +35,26 @@ extern FlagDesc flagdesc_mapgen_v7[]; struct MapgenV7Params : public MapgenParams { - s16 mount_zero_level = 0; - s16 floatland_ymin = 1024; - s16 floatland_ymax = 4096; - s16 floatland_taper = 256; + POS mount_zero_level = 0; + POS floatland_ymin = 1024; + POS floatland_ymax = 4096; + POS floatland_taper = 256; float float_taper_exp = 2.0f; float floatland_density = -0.6f; - s16 floatland_ywater = -31000; + POS floatland_ywater = -MAX_MAP_GENERATION_LIMIT; float cave_width = 0.09f; - s16 large_cave_depth = -33; + POS large_cave_depth = -33; u16 small_cave_num_min = 0; u16 small_cave_num_max = 0; u16 large_cave_num_min = 0; u16 large_cave_num_max = 2; float large_cave_flooded = 0.5f; - s16 cavern_limit = -256; - s16 cavern_taper = 256; + POS cavern_limit = -256; + POS cavern_taper = 256; float cavern_threshold = 0.7f; - s16 dungeon_ymin = -31000; - s16 dungeon_ymax = 31000; + POS dungeon_ymin = -MAX_MAP_GENERATION_LIMIT; + POS dungeon_ymax = MAX_MAP_GENERATION_LIMIT; NoiseParams np_terrain_base; NoiseParams np_terrain_alt; @@ -88,25 +88,25 @@ class MapgenV7 : public MapgenBasic { virtual MapgenType getType() const { return MAPGEN_V7; } virtual void makeChunk(BlockMakeData *data); - int getSpawnLevelAtPoint(v2s16 p); + int getSpawnLevelAtPoint(v2POS p); - float baseTerrainLevelAtPoint(s16 x, s16 z); + float baseTerrainLevelAtPoint(POS x, POS z); float baseTerrainLevelFromMap(int index); - bool getMountainTerrainAtPoint(s16 x, s16 y, s16 z); - bool getMountainTerrainFromMap(int idx_xyz, int idx_xz, s16 y); - bool getRiverChannelFromMap(int idx_xyz, int idx_xz, s16 y); + bool getMountainTerrainAtPoint(POS x, POS y, POS z); + bool getMountainTerrainFromMap(int idx_xyz, int idx_xz, POS y); + bool getRiverChannelFromMap(int idx_xyz, int idx_xz, POS y); bool getFloatlandTerrainFromMap(int idx_xyz, float float_offset); int generateTerrain(); private: - s16 mount_zero_level; - s16 floatland_ymin; - s16 floatland_ymax; - s16 floatland_taper; + POS mount_zero_level; + POS floatland_ymin; + POS floatland_ymax; + POS floatland_taper; float float_taper_exp; float floatland_density; - s16 floatland_ywater; + POS floatland_ywater; float *float_offset_cache = nullptr; diff --git a/src/mapgen/mapgen_valleys.cpp b/src/mapgen/mapgen_valleys.cpp index 80a99b1f0f..8c659244e4 100644 --- a/src/mapgen/mapgen_valleys.cpp +++ b/src/mapgen/mapgen_valleys.cpp @@ -131,7 +131,7 @@ void MapgenValleysParams::readParams(const Settings *settings) { settings->getFlagStrNoEx("mgvalleys_spflags", spflags, flagdesc_mapgen_valleys); settings->getU16NoEx("mgvalleys_altitude_chill", altitude_chill); - settings->getS16NoEx("mgvalleys_large_cave_depth", large_cave_depth); + settings->getPOSNoEx("mgvalleys_large_cave_depth", large_cave_depth); settings->getU16NoEx("mgvalleys_small_cave_num_min", small_cave_num_min); settings->getU16NoEx("mgvalleys_small_cave_num_max", small_cave_num_max); settings->getU16NoEx("mgvalleys_large_cave_num_min", large_cave_num_min); @@ -140,11 +140,11 @@ void MapgenValleysParams::readParams(const Settings *settings) settings->getU16NoEx("mgvalleys_river_depth", river_depth); settings->getU16NoEx("mgvalleys_river_size", river_size); settings->getFloatNoEx("mgvalleys_cave_width", cave_width); - settings->getS16NoEx("mgvalleys_cavern_limit", cavern_limit); - settings->getS16NoEx("mgvalleys_cavern_taper", cavern_taper); + settings->getPOSNoEx("mgvalleys_cavern_limit", cavern_limit); + settings->getPOSNoEx("mgvalleys_cavern_taper", cavern_taper); settings->getFloatNoEx("mgvalleys_cavern_threshold", cavern_threshold); - settings->getS16NoEx("mgvalleys_dungeon_ymin", dungeon_ymin); - settings->getS16NoEx("mgvalleys_dungeon_ymax", dungeon_ymax); + settings->getPOSNoEx("mgvalleys_dungeon_ymin", dungeon_ymin); + settings->getPOSNoEx("mgvalleys_dungeon_ymax", dungeon_ymax); settings->getNoiseParams("mgvalleys_np_filler_depth", np_filler_depth); settings->getNoiseParams("mgvalleys_np_inter_valley_fill", np_inter_valley_fill); @@ -165,7 +165,7 @@ void MapgenValleysParams::writeParams(Settings *settings) const { settings->setFlagStr("mgvalleys_spflags", spflags, flagdesc_mapgen_valleys); settings->setU16("mgvalleys_altitude_chill", altitude_chill); - settings->setS16("mgvalleys_large_cave_depth", large_cave_depth); + settings->setPOS("mgvalleys_large_cave_depth", large_cave_depth); settings->setU16("mgvalleys_small_cave_num_min", small_cave_num_min); settings->setU16("mgvalleys_small_cave_num_max", small_cave_num_max); settings->setU16("mgvalleys_large_cave_num_min", large_cave_num_min); @@ -174,11 +174,11 @@ void MapgenValleysParams::writeParams(Settings *settings) const settings->setU16("mgvalleys_river_depth", river_depth); settings->setU16("mgvalleys_river_size", river_size); settings->setFloat("mgvalleys_cave_width", cave_width); - settings->setS16("mgvalleys_cavern_limit", cavern_limit); - settings->setS16("mgvalleys_cavern_taper", cavern_taper); + settings->setPOS("mgvalleys_cavern_limit", cavern_limit); + settings->setPOS("mgvalleys_cavern_taper", cavern_taper); settings->setFloat("mgvalleys_cavern_threshold", cavern_threshold); - settings->setS16("mgvalleys_dungeon_ymin", dungeon_ymin); - settings->setS16("mgvalleys_dungeon_ymax", dungeon_ymax); + settings->setPOS("mgvalleys_dungeon_ymin", dungeon_ymin); + settings->setPOS("mgvalleys_dungeon_ymax", dungeon_ymax); settings->setNoiseParams("mgvalleys_np_filler_depth", np_filler_depth); settings->setNoiseParams("mgvalleys_np_inter_valley_fill", np_inter_valley_fill); @@ -218,12 +218,12 @@ void MapgenValleys::makeChunk(BlockMakeData *data) this->vm = data->vmanip; this->ndef = data->nodedef; - v3s16 blockpos_min = data->blockpos_min; - v3s16 blockpos_max = data->blockpos_max; + v3POS blockpos_min = data->blockpos_min; + v3POS blockpos_max = data->blockpos_max; node_min = blockpos_min * MAP_BLOCKSIZE; - node_max = (blockpos_max + v3s16(1, 1, 1)) * MAP_BLOCKSIZE - v3s16(1, 1, 1); + node_max = (blockpos_max + v3POS(1, 1, 1)) * MAP_BLOCKSIZE - v3POS(1, 1, 1); full_node_min = (blockpos_min - 1) * MAP_BLOCKSIZE; - full_node_max = (blockpos_max + 2) * MAP_BLOCKSIZE - v3s16(1, 1, 1); + full_node_max = (blockpos_max + 2) * MAP_BLOCKSIZE - v3POS(1, 1, 1); blockseed = getBlockSeed2(full_node_min, seed); @@ -233,7 +233,7 @@ void MapgenValleys::makeChunk(BlockMakeData *data) m_bgen->calcBiomeNoise(node_min); // Generate terrain - s16 stone_surface_max_y = generateTerrain(); + POS stone_surface_max_y = generateTerrain(); // Create heightmap updateHeightmap(node_min, node_max); @@ -281,7 +281,7 @@ void MapgenValleys::makeChunk(BlockMakeData *data) updateLiquid(&data->transforming_liquid, full_node_min, full_node_max); if (flags & MG_LIGHT) - calcLighting(node_min - v3s16(0, 1, 0), node_max + v3s16(0, 1, 0), + calcLighting(node_min - v3POS(0, 1, 0), node_max + v3POS(0, 1, 0), full_node_min, full_node_max); this->generating = false; @@ -290,7 +290,7 @@ void MapgenValleys::makeChunk(BlockMakeData *data) } -int MapgenValleys::getSpawnLevelAtPoint(v2s16 p) +int MapgenValleys::getSpawnLevelAtPoint(v2POS p) { // Check if in a river channel float n_rivers = NoisePerlin2D(&noise_rivers->np, p.X, p.Y, seed); @@ -314,14 +314,14 @@ int MapgenValleys::getSpawnLevelAtPoint(v2s16 p) // Raising the maximum spawn level above 'water_level + 16' is necessary for custom // parameters that set average terrain level much higher than water_level. - s16 max_spawn_y = std::fmax( + POS max_spawn_y = std::fmax( noise_terrain_height->np.offset + noise_valley_depth->np.offset * noise_valley_depth->np.offset, water_level + 16); // Starting spawn search at max_spawn_y + 128 ensures 128 nodes of open // space above spawn position. Avoids spawning in possibly sealed voids. - for (s16 y = max_spawn_y + 128; y >= water_level; y--) { + for (POS y = max_spawn_y + 128; y >= water_level; y--) { float n_fill = NoisePerlin3D(&noise_inter_valley_fill->np, p.X, y, p.Y, seed); float surface_delta = (float)y - surface_y; float density = slope * n_fill - surface_delta; @@ -357,12 +357,12 @@ int MapgenValleys::generateTerrain() noise_inter_valley_fill->perlinMap3D(node_min.X, node_min.Y - 1, node_min.Z); - const v3s16 &em = vm->m_area.getExtent(); - s16 surface_max_y = -MAX_MAP_GENERATION_LIMIT; + const v3POS &em = vm->m_area.getExtent(); + POS surface_max_y = -MAX_MAP_GENERATION_LIMIT; u32 index_2d = 0; - for (s16 z = node_min.Z; z <= node_max.Z; z++) - for (s16 x = node_min.X; x <= node_max.X; x++, index_2d++) { + for (POS z = node_min.Z; z <= node_max.Z; z++) + for (POS x = node_min.X; x <= node_max.X; x++, index_2d++) { float n_slope = noise_inter_valley_slope->result[index_2d]; float n_rivers = noise_rivers->result[index_2d]; float n_terrain_height = noise_terrain_height->result[index_2d]; @@ -415,11 +415,11 @@ int MapgenValleys::generateTerrain() } // Highest solid node in column - s16 column_max_y = surface_y; + POS column_max_y = surface_y; u32 index_3d = (z - node_min.Z) * zstride_1u1d + (x - node_min.X); u32 index_data = vm->m_area.index(x, node_min.Y - 1, z); - for (s16 y = node_min.Y - 1; y <= node_max.Y + 1; y++) { + for (POS y = node_min.Y - 1; y <= node_max.Y + 1; y++) { if (vm->m_data[index_data].getContent() == CONTENT_IGNORE) { float n_fill = noise_inter_valley_fill->result[index_3d]; float surface_delta = (float)y - surface_y; @@ -434,7 +434,7 @@ int MapgenValleys::generateTerrain() column_max_y = y; } else if (y <= water_level) { vm->m_data[index_data] = n_water; // Water - } else if (y <= (s16)river_y) { + } else if (y <= (POS)river_y) { vm->m_data[index_data] = n_river_water; // River water } else { vm->m_data[index_data] = n_air; // Air diff --git a/src/mapgen/mapgen_valleys.h b/src/mapgen/mapgen_valleys.h index 34a923dfa9..d74fc6c44c 100644 --- a/src/mapgen/mapgen_valleys.h +++ b/src/mapgen/mapgen_valleys.h @@ -46,17 +46,17 @@ struct MapgenValleysParams : public MapgenParams { u16 river_size = 5; float cave_width = 0.09f; - s16 large_cave_depth = -33; + POS large_cave_depth = -33; u16 small_cave_num_min = 0; u16 small_cave_num_max = 0; u16 large_cave_num_min = 0; u16 large_cave_num_max = 2; float large_cave_flooded = 0.5f; - s16 cavern_limit = -256; - s16 cavern_taper = 192; + POS cavern_limit = -256; + POS cavern_taper = 192; float cavern_threshold = 0.6f; - s16 dungeon_ymin = -31000; - s16 dungeon_ymax = 63; + POS dungeon_ymin = -MAX_MAP_GENERATION_LIMIT; + POS dungeon_ymax = 63; NoiseParams np_filler_depth; NoiseParams np_inter_valley_fill; @@ -90,7 +90,7 @@ class MapgenValleys : public MapgenBasic { virtual MapgenType getType() const { return MAPGEN_VALLEYS; } virtual void makeChunk(BlockMakeData *data); - int getSpawnLevelAtPoint(v2s16 p); + int getSpawnLevelAtPoint(v2POS p); private: BiomeGenOriginal *m_bgen; diff --git a/src/mapgen/mg_biome.cpp b/src/mapgen/mg_biome.cpp index f08cc190f7..8c3eaf9327 100644 --- a/src/mapgen/mg_biome.cpp +++ b/src/mapgen/mg_biome.cpp @@ -46,9 +46,9 @@ BiomeManager::BiomeManager(Server *server) : b->depth_filler = -MAX_MAP_GENERATION_LIMIT; b->depth_water_top = 0; b->depth_riverbed = 0; - b->min_pos = v3s16(-MAX_MAP_GENERATION_LIMIT, + b->min_pos = v3POS(-MAX_MAP_GENERATION_LIMIT, -MAX_MAP_GENERATION_LIMIT, -MAX_MAP_GENERATION_LIMIT); - b->max_pos = v3s16(MAX_MAP_GENERATION_LIMIT, + b->max_pos = v3POS(MAX_MAP_GENERATION_LIMIT, MAX_MAP_GENERATION_LIMIT, MAX_MAP_GENERATION_LIMIT); b->heat_point = 0.0; b->humidity_point = 0.0; @@ -124,7 +124,7 @@ void BiomeParamsOriginal::writeParams(Settings *settings) const //////////////////////////////////////////////////////////////////////////////// BiomeGenOriginal::BiomeGenOriginal(BiomeManager *biomemgr, - const BiomeParamsOriginal *params, v3s16 chunksize) + const BiomeParamsOriginal *params, v3POS chunksize) { m_bmgr = biomemgr; m_params = params; @@ -164,25 +164,25 @@ BiomeGen *BiomeGenOriginal::clone(BiomeManager *biomemgr) const return new BiomeGenOriginal(biomemgr, m_params, m_csize); } -float BiomeGenOriginal::calcHeatAtPoint(v3s16 pos) const +float BiomeGenOriginal::calcHeatAtPoint(v3POS pos) const { return NoisePerlin2D(&m_params->np_heat, pos.X, pos.Z, m_params->seed) + NoisePerlin2D(&m_params->np_heat_blend, pos.X, pos.Z, m_params->seed); } -float BiomeGenOriginal::calcHumidityAtPoint(v3s16 pos) const +float BiomeGenOriginal::calcHumidityAtPoint(v3POS pos) const { return NoisePerlin2D(&m_params->np_humidity, pos.X, pos.Z, m_params->seed) + NoisePerlin2D(&m_params->np_humidity_blend, pos.X, pos.Z, m_params->seed); } -Biome *BiomeGenOriginal::calcBiomeAtPoint(v3s16 pos) const +Biome *BiomeGenOriginal::calcBiomeAtPoint(v3POS pos) const { return calcBiomeFromNoise(calcHeatAtPoint(pos), calcHumidityAtPoint(pos), pos); } -void BiomeGenOriginal::calcBiomeNoise(v3s16 pmin) +void BiomeGenOriginal::calcBiomeNoise(v3POS pmin) { m_pmin = pmin; @@ -198,7 +198,7 @@ void BiomeGenOriginal::calcBiomeNoise(v3s16 pmin) } -biome_t *BiomeGenOriginal::getBiomes(s16 *heightmap, v3s16 pmin) +biome_t *BiomeGenOriginal::getBiomes(POS *heightmap, v3POS pmin) { for (s16 zr = 0; zr < m_csize.Z; zr++) for (s16 xr = 0; xr < m_csize.X; xr++) { @@ -206,7 +206,7 @@ biome_t *BiomeGenOriginal::getBiomes(s16 *heightmap, v3s16 pmin) Biome *biome = calcBiomeFromNoise( noise_heat->result[i], noise_humidity->result[i], - v3s16(pmin.X + xr, heightmap[i], pmin.Z + zr)); + v3POS(pmin.X + xr, heightmap[i], pmin.Z + zr)); biomemap[i] = biome->index; } @@ -215,7 +215,7 @@ biome_t *BiomeGenOriginal::getBiomes(s16 *heightmap, v3s16 pmin) } -Biome *BiomeGenOriginal::getBiomeAtPoint(v3s16 pos) const +Biome *BiomeGenOriginal::getBiomeAtPoint(v3POS pos) const { return getBiomeAtIndex( (pos.Z - m_pmin.Z) * m_csize.X + (pos.X - m_pmin.X), @@ -223,7 +223,7 @@ Biome *BiomeGenOriginal::getBiomeAtPoint(v3s16 pos) const } -Biome *BiomeGenOriginal::getBiomeAtIndex(size_t index, v3s16 pos) const +Biome *BiomeGenOriginal::getBiomeAtIndex(size_t index, v3POS pos) const { return calcBiomeFromNoise( noise_heat->result[index], @@ -232,7 +232,7 @@ Biome *BiomeGenOriginal::getBiomeAtIndex(size_t index, v3s16 pos) const } -Biome *BiomeGenOriginal::calcBiomeFromNoise(float heat, float humidity, v3s16 pos) const +Biome *BiomeGenOriginal::calcBiomeFromNoise(float heat, float humidity, v3POS pos) const { Biome *biome_closest = nullptr; Biome *biome_closest_blend = nullptr; diff --git a/src/mapgen/mg_biome.h b/src/mapgen/mg_biome.h index c85afc3a0d..3e5024a975 100644 --- a/src/mapgen/mg_biome.h +++ b/src/mapgen/mg_biome.h @@ -59,16 +59,16 @@ class Biome : public ObjDef, public NodeResolver { content_t c_dungeon_alt; content_t c_dungeon_stair; - s16 depth_top; - s16 depth_filler; - s16 depth_water_top; - s16 depth_riverbed; + POS depth_top; + POS depth_filler; + POS depth_water_top; + POS depth_riverbed; - v3s16 min_pos; - v3s16 max_pos; + v3POS min_pos; + v3POS max_pos; float heat_point; float humidity_point; - s16 vertical_blend; + POS vertical_blend; virtual void resolveNodeNames(); }; @@ -101,7 +101,7 @@ class BiomeGen { virtual BiomeGen *clone(BiomeManager *biomemgr) const = 0; // Check that the internal chunk size is what the mapgen expects, just to be sure. - inline void assertChunkSize(v3s16 expect) const + inline void assertChunkSize(v3POS expect) const { FATAL_ERROR_IF(m_csize != expect, "Chunk size mismatches"); } @@ -109,32 +109,32 @@ class BiomeGen { // Calculates the biome at the exact position provided. This function can // be called at any time, but may be less efficient than the latter methods, // depending on implementation. - virtual Biome *calcBiomeAtPoint(v3s16 pos) const = 0; + virtual Biome *calcBiomeAtPoint(v3POS pos) const = 0; // Computes any intermediate results needed for biome generation. Must be // called before using any of: getBiomes, getBiomeAtPoint, or getBiomeAtIndex. // Calling this invalidates the previous results stored in biomemap. - virtual void calcBiomeNoise(v3s16 pmin) = 0; + virtual void calcBiomeNoise(v3POS pmin) = 0; // Gets all biomes in current chunk using each corresponding element of // heightmap as the y position, then stores the results by biome index in // biomemap (also returned) - virtual biome_t *getBiomes(s16 *heightmap, v3s16 pmin) = 0; + virtual biome_t *getBiomes(POS *heightmap, v3POS pmin) = 0; // Gets a single biome at the specified position, which must be contained // in the region formed by m_pmin and (m_pmin + m_csize - 1). - virtual Biome *getBiomeAtPoint(v3s16 pos) const = 0; + virtual Biome *getBiomeAtPoint(v3POS pos) const = 0; // Same as above, but uses a raw numeric index correlating to the (x,z) position. - virtual Biome *getBiomeAtIndex(size_t index, v3s16 pos) const = 0; + virtual Biome *getBiomeAtIndex(size_t index, v3POS pos) const = 0; // Result of calcBiomes bulk computation. biome_t *biomemap = nullptr; protected: BiomeManager *m_bmgr = nullptr; - v3s16 m_pmin; - v3s16 m_csize; + v3POS m_pmin; + v3POS m_csize; }; @@ -167,7 +167,7 @@ struct BiomeParamsOriginal : public BiomeParams { class BiomeGenOriginal : public BiomeGen { public: BiomeGenOriginal(BiomeManager *biomemgr, - const BiomeParamsOriginal *params, v3s16 chunksize); + const BiomeParamsOriginal *params, v3POS chunksize); virtual ~BiomeGenOriginal(); BiomeGenType getType() const { return BIOMEGEN_ORIGINAL; } @@ -175,17 +175,17 @@ class BiomeGenOriginal : public BiomeGen { BiomeGen *clone(BiomeManager *biomemgr) const; // Slower, meant for Script API use - float calcHeatAtPoint(v3s16 pos) const; - float calcHumidityAtPoint(v3s16 pos) const; - Biome *calcBiomeAtPoint(v3s16 pos) const; + float calcHeatAtPoint(v3POS pos) const; + float calcHumidityAtPoint(v3POS pos) const; + Biome *calcBiomeAtPoint(v3POS pos) const; - void calcBiomeNoise(v3s16 pmin); + void calcBiomeNoise(v3POS pmin); - biome_t *getBiomes(s16 *heightmap, v3s16 pmin); - Biome *getBiomeAtPoint(v3s16 pos) const; - Biome *getBiomeAtIndex(size_t index, v3s16 pos) const; + biome_t *getBiomes(POS *heightmap, v3POS pmin); + Biome *getBiomeAtPoint(v3POS pos) const; + Biome *getBiomeAtIndex(size_t index, v3POS pos) const; - Biome *calcBiomeFromNoise(float heat, float humidity, v3s16 pos) const; + Biome *calcBiomeFromNoise(float heat, float humidity, v3POS pos) const; float *heatmap; float *humidmap; @@ -221,7 +221,7 @@ class BiomeManager : public ObjDefManager { return new Biome; } - BiomeGen *createBiomeGen(BiomeGenType type, BiomeParams *params, v3s16 chunksize) + BiomeGen *createBiomeGen(BiomeGenType type, BiomeParams *params, v3POS chunksize) { switch (type) { case BIOMEGEN_ORIGINAL: diff --git a/src/mapgen/mg_decoration.cpp b/src/mapgen/mg_decoration.cpp index a4cada396d..25ed2f55f3 100644 --- a/src/mapgen/mg_decoration.cpp +++ b/src/mapgen/mg_decoration.cpp @@ -51,7 +51,7 @@ DecorationManager::DecorationManager(IGameDef *gamedef) : size_t DecorationManager::placeAllDecos(Mapgen *mg, u32 blockseed, - v3s16 nmin, v3s16 nmax) + v3POS nmin, v3POS nmax) { size_t nplaced = 0; @@ -85,7 +85,7 @@ void Decoration::resolveNodeNames() } -bool Decoration::canPlaceDecoration(MMVManip *vm, v3s16 p) +bool Decoration::canPlaceDecoration(MMVManip *vm, v3POS p) { // Check if the decoration can be placed on this node u32 vi = vm->m_area.index(p); @@ -97,24 +97,24 @@ bool Decoration::canPlaceDecoration(MMVManip *vm, v3s16 p) return true; int nneighs = 0; - static const v3s16 dirs[16] = { - v3s16( 0, 0, 1), - v3s16( 0, 0, -1), - v3s16( 1, 0, 0), - v3s16(-1, 0, 0), - v3s16( 1, 0, 1), - v3s16(-1, 0, 1), - v3s16(-1, 0, -1), - v3s16( 1, 0, -1), - - v3s16( 0, 1, 1), - v3s16( 0, 1, -1), - v3s16( 1, 1, 0), - v3s16(-1, 1, 0), - v3s16( 1, 1, 1), - v3s16(-1, 1, 1), - v3s16(-1, 1, -1), - v3s16( 1, 1, -1) + static const v3POS dirs[16] = { + v3POS( 0, 0, 1), + v3POS( 0, 0, -1), + v3POS( 1, 0, 0), + v3POS(-1, 0, 0), + v3POS( 1, 0, 1), + v3POS(-1, 0, 1), + v3POS(-1, 0, -1), + v3POS( 1, 0, -1), + + v3POS( 0, 1, 1), + v3POS( 0, 1, -1), + v3POS( 1, 1, 0), + v3POS(-1, 1, 0), + v3POS( 1, 1, 1), + v3POS(-1, 1, 1), + v3POS(-1, 1, -1), + v3POS( 1, 1, -1) }; // Check these 16 neighbouring nodes for enough spawnby nodes @@ -134,7 +134,7 @@ bool Decoration::canPlaceDecoration(MMVManip *vm, v3s16 p) } -size_t Decoration::placeDeco(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax) +size_t Decoration::placeDeco(Mapgen *mg, u32 blockseed, v3POS nmin, v3POS nmax) { PcgRandom ps(blockseed + 53); int carea_size = nmax.X - nmin.X + 1; @@ -149,15 +149,15 @@ size_t Decoration::placeDeco(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax) for (s16 z0 = 0; z0 < divlen; z0++) for (s16 x0 = 0; x0 < divlen; x0++) { - v2s16 p2d_center( // Center position of part of division + v2POS p2d_center( // Center position of part of division nmin.X + sidelen / 2 + sidelen * x0, nmin.Z + sidelen / 2 + sidelen * z0 ); - v2s16 p2d_min( // Minimum edge of part of division + v2POS p2d_min( // Minimum edge of part of division nmin.X + sidelen * x0, nmin.Z + sidelen * z0 ); - v2s16 p2d_max( // Maximum edge of part of division + v2POS p2d_max( // Maximum edge of part of division nmin.X + sidelen + sidelen * x0 - 1, nmin.Z + sidelen + sidelen * z0 - 1 ); @@ -213,12 +213,12 @@ size_t Decoration::placeDeco(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax) // Get all floors and ceilings in node column u16 size = (nmax.Y - nmin.Y + 1) / 2; - std::vector floors; - std::vector ceilings; + std::vector floors; + std::vector ceilings; floors.reserve(size); ceilings.reserve(size); - mg->getSurfaces(v2s16(x, z), nmin.Y, nmax.Y, floors, ceilings); + mg->getSurfaces(v2POS(x, z), nmin.Y, nmax.Y, floors, ceilings); if (flags & DECO_ALL_FLOORS) { // Floor decorations @@ -226,7 +226,7 @@ size_t Decoration::placeDeco(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax) if (y < y_min || y > y_max) continue; - v3s16 pos(x, y, z); + v3POS pos(x, y, z); if (generate(mg->vm, &ps, pos, false)) mg->gennotify.addEvent( GENNOTIFY_DECORATION, pos, index); @@ -235,24 +235,24 @@ size_t Decoration::placeDeco(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax) if (flags & DECO_ALL_CEILINGS) { // Ceiling decorations - for (const s16 y : ceilings) { + for (const POS y : ceilings) { if (y < y_min || y > y_max) continue; - v3s16 pos(x, y, z); + v3POS pos(x, y, z); if (generate(mg->vm, &ps, pos, true)) mg->gennotify.addEvent( GENNOTIFY_DECORATION, pos, index); } } } else { // Heightmap decorations - s16 y = -MAX_MAP_GENERATION_LIMIT; + POS y = -MAX_MAP_GENERATION_LIMIT; if (flags & DECO_LIQUID_SURFACE) - y = mg->findLiquidSurface(v2s16(x, z), nmin.Y, nmax.Y); + y = mg->findLiquidSurface(v2POS(x, z), nmin.Y, nmax.Y); else if (mg->heightmap) y = mg->heightmap[mapindex]; else - y = mg->findGroundLevel(v2s16(x, z), nmin.Y, nmax.Y); + y = mg->findGroundLevel(v2POS(x, z), nmin.Y, nmax.Y); if (y < y_min || y > y_max || y < nmin.Y || y > nmax.Y) continue; @@ -263,7 +263,7 @@ size_t Decoration::placeDeco(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax) continue; } - v3s16 pos(x, y, z); + v3POS pos(x, y, z); if (generate(mg->vm, &ps, pos, false)) mg->gennotify.addEvent(GENNOTIFY_DECORATION, pos, index); } @@ -317,7 +317,7 @@ void DecoSimple::resolveNodeNames() } -size_t DecoSimple::generate(MMVManip *vm, PcgRandom *pr, v3s16 p, bool ceiling) +size_t DecoSimple::generate(MMVManip *vm, PcgRandom *pr, v3POS p, bool ceiling) { // Don't bother if there aren't any decorations to place if (c_decos.empty()) @@ -353,7 +353,7 @@ size_t DecoSimple::generate(MMVManip *vm, PcgRandom *pr, v3s16 p, bool ceiling) pr->range(deco_param2, deco_param2_max) : deco_param2; bool force_placement = (flags & DECO_FORCE_PLACEMENT); - const v3s16 &em = vm->m_area.getExtent(); + const v3POS &em = vm->m_area.getExtent(); u32 vi = vm->m_area.index(p); if (ceiling) { @@ -414,7 +414,7 @@ ObjDef *DecoSchematic::clone() const } -size_t DecoSchematic::generate(MMVManip *vm, PcgRandom *pr, v3s16 p, bool ceiling) +size_t DecoSchematic::generate(MMVManip *vm, PcgRandom *pr, v3POS p, bool ceiling) { // Schematic could have been unloaded but not the decoration // In this case generate() does nothing (but doesn't *fail*) diff --git a/src/mapgen/mg_decoration.h b/src/mapgen/mg_decoration.h index 1ea02a527d..0aea942ea1 100644 --- a/src/mapgen/mg_decoration.h +++ b/src/mapgen/mg_decoration.h @@ -57,17 +57,17 @@ class Decoration : public ObjDef, public NodeResolver { virtual void resolveNodeNames(); - bool canPlaceDecoration(MMVManip *vm, v3s16 p); - size_t placeDeco(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax); + bool canPlaceDecoration(MMVManip *vm, v3POS p); + size_t placeDeco(Mapgen *mg, u32 blockseed, v3POS nmin, v3POS nmax); - virtual size_t generate(MMVManip *vm, PcgRandom *pr, v3s16 p, bool ceiling) = 0; + virtual size_t generate(MMVManip *vm, PcgRandom *pr, v3POS p, bool ceiling) = 0; u32 flags = 0; int mapseed = 0; std::vector c_place_on; s16 sidelen = 1; - s16 y_min; - s16 y_max; + POS y_min; + POS y_max; float fill_ratio = 0.0f; NoiseParams np; std::vector c_spawnby; @@ -86,7 +86,7 @@ class DecoSimple : public Decoration { ObjDef *clone() const; virtual void resolveNodeNames(); - virtual size_t generate(MMVManip *vm, PcgRandom *pr, v3s16 p, bool ceiling); + virtual size_t generate(MMVManip *vm, PcgRandom *pr, v3POS p, bool ceiling); std::vector c_decos; s16 deco_height; @@ -103,7 +103,7 @@ class DecoSchematic : public Decoration { DecoSchematic() = default; virtual ~DecoSchematic(); - virtual size_t generate(MMVManip *vm, PcgRandom *pr, v3s16 p, bool ceiling); + virtual size_t generate(MMVManip *vm, PcgRandom *pr, v3POS p, bool ceiling); Rotation rotation; Schematic *schematic = nullptr; @@ -114,7 +114,7 @@ class DecoSchematic : public Decoration { /* class DecoLSystem : public Decoration { public: - virtual void generate(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax); + virtual void generate(Mapgen *mg, u32 blockseed, v3POS nmin, v3POS nmax); }; */ @@ -145,7 +145,7 @@ class DecorationManager : public ObjDefManager { } } - size_t placeAllDecos(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax); + size_t placeAllDecos(Mapgen *mg, u32 blockseed, v3POS nmin, v3POS nmax); private: DecorationManager() {}; diff --git a/src/mapgen/mg_ore.cpp b/src/mapgen/mg_ore.cpp index 5814f433a8..944e10429c 100644 --- a/src/mapgen/mg_ore.cpp +++ b/src/mapgen/mg_ore.cpp @@ -45,7 +45,7 @@ OreManager::OreManager(IGameDef *gamedef) : } -size_t OreManager::placeAllOres(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax) +size_t OreManager::placeAllOres(Mapgen *mg, u32 blockseed, v3POS nmin, v3POS nmax) { size_t nplaced = 0; @@ -96,7 +96,7 @@ void Ore::resolveNodeNames() } -size_t Ore::placeOre(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax) +size_t Ore::placeOre(Mapgen *mg, u32 blockseed, v3POS nmin, v3POS nmax) { if (nmin.Y > y_max || nmax.Y < y_min) return 0; @@ -146,7 +146,7 @@ ObjDef *OreScatter::clone() const void OreScatter::generate(MMVManip *vm, int mapseed, u32 blockseed, - v3s16 nmin, v3s16 nmax, biome_t *biomemap) + v3POS nmin, v3POS nmax, biome_t *biomemap) { PcgRandom pr(blockseed); MapNode n_ore(c_ore, 0, ore_param2); @@ -208,7 +208,7 @@ ObjDef *OreSheet::clone() const void OreSheet::generate(MMVManip *vm, int mapseed, u32 blockseed, - v3s16 nmin, v3s16 nmax, biome_t *biomemap) + v3POS nmin, v3POS nmax, biome_t *biomemap) { PcgRandom pr(blockseed + 4234); MapNode n_ore(c_ore, 0, ore_param2); @@ -285,7 +285,7 @@ ObjDef *OrePuff::clone() const void OrePuff::generate(MMVManip *vm, int mapseed, u32 blockseed, - v3s16 nmin, v3s16 nmax, biome_t *biomemap) + v3POS nmin, v3POS nmax, biome_t *biomemap) { PcgRandom pr(blockseed + 4234); MapNode n_ore(c_ore, 0, ore_param2); @@ -366,7 +366,7 @@ ObjDef *OreBlob::clone() const void OreBlob::generate(MMVManip *vm, int mapseed, u32 blockseed, - v3s16 nmin, v3s16 nmax, biome_t *biomemap) + v3POS nmin, v3POS nmax, biome_t *biomemap) { PcgRandom pr(blockseed + 2404); MapNode n_ore(c_ore, 0, ore_param2); @@ -451,7 +451,7 @@ ObjDef *OreVein::clone() const void OreVein::generate(MMVManip *vm, int mapseed, u32 blockseed, - v3s16 nmin, v3s16 nmax, biome_t *biomemap) + v3POS nmin, v3POS nmax, biome_t *biomemap) { PcgRandom pr(blockseed + 520); MapNode n_ore(c_ore, 0, ore_param2); @@ -536,7 +536,7 @@ ObjDef *OreStratum::clone() const void OreStratum::generate(MMVManip *vm, int mapseed, u32 blockseed, - v3s16 nmin, v3s16 nmax, biome_t *biomemap) + v3POS nmin, v3POS nmax, biome_t *biomemap) { PcgRandom pr(blockseed + 4234); MapNode n_ore(c_ore, 0, ore_param2); diff --git a/src/mapgen/mg_ore.h b/src/mapgen/mg_ore.h index a757fa6d03..ca017bf037 100644 --- a/src/mapgen/mg_ore.h +++ b/src/mapgen/mg_ore.h @@ -59,8 +59,8 @@ class Ore : public ObjDef, public NodeResolver { u32 clust_scarcity; // ore cluster has a 1-in-clust_scarcity chance of appearing at a node s16 clust_num_ores; // how many ore nodes are in a chunk s16 clust_size; // how large (in nodes) a chunk of ore is - s16 y_min; - s16 y_max; + POS y_min; + POS y_max; u8 ore_param2; // to set node-specific attributes u32 flags = 0; // attributes for this ore float nthresh; // threshold for noise at which an ore is placed @@ -73,9 +73,9 @@ class Ore : public ObjDef, public NodeResolver { virtual void resolveNodeNames(); - size_t placeOre(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax); + size_t placeOre(Mapgen *mg, u32 blockseed, v3POS nmin, v3POS nmax); virtual void generate(MMVManip *vm, int mapseed, u32 blockseed, - v3s16 nmin, v3s16 nmax, biome_t *biomemap) = 0; + v3POS nmin, v3POS nmax, biome_t *biomemap) = 0; protected: void cloneTo(Ore *def) const; @@ -88,7 +88,7 @@ class OreScatter : public Ore { ObjDef *clone() const override; void generate(MMVManip *vm, int mapseed, u32 blockseed, - v3s16 nmin, v3s16 nmax, biome_t *biomemap) override; + v3POS nmin, v3POS nmax, biome_t *biomemap) override; }; class OreSheet : public Ore { @@ -102,7 +102,7 @@ class OreSheet : public Ore { float column_midpoint_factor; void generate(MMVManip *vm, int mapseed, u32 blockseed, - v3s16 nmin, v3s16 nmax, biome_t *biomemap) override; + v3POS nmin, v3POS nmax, biome_t *biomemap) override; }; class OrePuff : public Ore { @@ -118,7 +118,7 @@ class OrePuff : public Ore { virtual ~OrePuff(); void generate(MMVManip *vm, int mapseed, u32 blockseed, - v3s16 nmin, v3s16 nmax, biome_t *biomemap) override; + v3POS nmin, v3POS nmax, biome_t *biomemap) override; }; class OreBlob : public Ore { @@ -127,7 +127,7 @@ class OreBlob : public Ore { OreBlob() : Ore(true) {} void generate(MMVManip *vm, int mapseed, u32 blockseed, - v3s16 nmin, v3s16 nmax, biome_t *biomemap) override; + v3POS nmin, v3POS nmax, biome_t *biomemap) override; }; class OreVein : public Ore { @@ -142,7 +142,7 @@ class OreVein : public Ore { virtual ~OreVein(); void generate(MMVManip *vm, int mapseed, u32 blockseed, - v3s16 nmin, v3s16 nmax, biome_t *biomemap) override; + v3POS nmin, v3POS nmax, biome_t *biomemap) override; }; class OreStratum : public Ore { @@ -157,7 +157,7 @@ class OreStratum : public Ore { virtual ~OreStratum(); void generate(MMVManip *vm, int mapseed, u32 blockseed, - v3s16 nmin, v3s16 nmax, biome_t *biomemap) override; + v3POS nmin, v3POS nmax, biome_t *biomemap) override; }; class OreManager : public ObjDefManager { @@ -194,7 +194,7 @@ class OreManager : public ObjDefManager { void clear(); - size_t placeAllOres(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax); + size_t placeAllOres(Mapgen *mg, u32 blockseed, v3POS nmin, v3POS nmax); private: OreManager() {}; diff --git a/src/mapgen/mg_schematic.cpp b/src/mapgen/mg_schematic.cpp index b9ba70302a..ee8a3a37c8 100644 --- a/src/mapgen/mg_schematic.cpp +++ b/src/mapgen/mg_schematic.cpp @@ -121,7 +121,7 @@ void Schematic::resolveNodeNames() } -void Schematic::blitToVManip(MMVManip *vm, v3s16 p, Rotation rot, bool force_place) +void Schematic::blitToVManip(MMVManip *vm, v3POS p, Rotation rot, bool force_place) { assert(schemdata && slice_probs); sanity_check(m_ndef != NULL); @@ -168,7 +168,7 @@ void Schematic::blitToVManip(MMVManip *vm, v3s16 p, Rotation rot, bool force_pla for (s16 z = 0; z != sz; z++) { u32 i = z * i_step_z + y * ystride + i_start; for (s16 x = 0; x != sx; x++, i += i_step_x) { - v3s16 pos(p.X + x, y_map, p.Z + z); + v3POS pos(p.X + x, y_map, p.Z + z); if (!vm->m_area.contains(pos)) continue; @@ -204,7 +204,7 @@ void Schematic::blitToVManip(MMVManip *vm, v3s16 p, Rotation rot, bool force_pla } -bool Schematic::placeOnVManip(MMVManip *vm, v3s16 p, u32 flags, +bool Schematic::placeOnVManip(MMVManip *vm, v3POS p, u32 flags, Rotation rot, bool force_place) { assert(vm != NULL); @@ -215,8 +215,8 @@ bool Schematic::placeOnVManip(MMVManip *vm, v3s16 p, u32 flags, if (rot == ROTATE_RAND) rot = (Rotation)myrand_range(ROTATE_0, ROTATE_270); - v3s16 s = (rot == ROTATE_90 || rot == ROTATE_270) ? - v3s16(size.Z, size.Y, size.X) : size; + v3POS s = (rot == ROTATE_90 || rot == ROTATE_270) ? + v3POS(size.Z, size.Y, size.X) : size; //// Adjust placement position if necessary if (flags & DECO_PLACE_CENTER_X) @@ -228,15 +228,15 @@ bool Schematic::placeOnVManip(MMVManip *vm, v3s16 p, u32 flags, blitToVManip(vm, p, rot, force_place); - return vm->m_area.contains(VoxelArea(p, p + s - v3s16(1, 1, 1))); + return vm->m_area.contains(VoxelArea(p, p + s - v3POS(1, 1, 1))); } -void Schematic::placeOnMap(ServerMap *map, v3s16 p, u32 flags, +void Schematic::placeOnMap(ServerMap *map, v3POS p, u32 flags, Rotation rot, bool force_place) { - std::map lighting_modified_blocks; - std::map modified_blocks; - std::map::iterator it; + std::map lighting_modified_blocks; + std::map modified_blocks; + std::map::iterator it; assert(map != NULL); assert(schemdata != NULL); @@ -246,8 +246,8 @@ void Schematic::placeOnMap(ServerMap *map, v3s16 p, u32 flags, if (rot == ROTATE_RAND) rot = (Rotation)myrand_range(ROTATE_0, ROTATE_270); - v3s16 s = (rot == ROTATE_90 || rot == ROTATE_270) ? - v3s16(size.Z, size.Y, size.X) : size; + v3POS s = (rot == ROTATE_90 || rot == ROTATE_270) ? + v3POS(size.Z, size.Y, size.X) : size; //// Adjust placement position if necessary if (flags & DECO_PLACE_CENTER_X) @@ -259,8 +259,8 @@ void Schematic::placeOnMap(ServerMap *map, v3s16 p, u32 flags, //// Create VManip for effected area, emerge our area, modify area //// inside VManip, then blit back. - v3s16 bp1 = getNodeBlockPos(p); - v3s16 bp2 = getNodeBlockPos(p + s - v3s16(1, 1, 1)); + v3BPOS bp1 = getNodeBlockPos(p); + v3BPOS bp2 = getNodeBlockPos(p + s - v3POS(1, 1, 1)); MMVManip vm(map); vm.initialEmerge(bp1, bp2); @@ -304,7 +304,7 @@ bool Schematic::deserializeFromMts(std::istream *is) } //// Read size - size = readV3S16(ss); + size = readV3POS(ss); //// Read Y-slice probability values delete []slice_probs; @@ -375,7 +375,7 @@ bool Schematic::serializeToMts(std::ostream *os) const writeU32(ss, MTSCHEM_FILE_SIGNATURE); // signature writeU16(ss, MTSCHEM_FILE_VER_HIGHEST_WRITE); // version - writeV3S16(ss, size); // schematic size + writeV3POS(ss, size); // schematic size for (int y = 0; y != size.Y; y++) // Y slice probabilities writeU8(ss, slice_probs[y]); @@ -548,12 +548,12 @@ bool Schematic::saveSchematicToFile(const std::string &filename, } -bool Schematic::getSchematicFromMap(Map *map, v3s16 p1, v3s16 p2) +bool Schematic::getSchematicFromMap(Map *map, v3POS p1, v3POS p2) { MMVManip *vm = new MMVManip(map); - v3s16 bp1 = getNodeBlockPos(p1); - v3s16 bp2 = getNodeBlockPos(p2); + v3BPOS bp1 = getNodeBlockPos(p1); + v3BPOS bp2 = getNodeBlockPos(p2); vm->initialEmerge(bp1, bp2); size = p2 - p1 + 1; @@ -583,12 +583,12 @@ bool Schematic::getSchematicFromMap(Map *map, v3s16 p1, v3s16 p2) } -void Schematic::applyProbabilities(v3s16 p0, - std::vector > *plist, +void Schematic::applyProbabilities(v3POS p0, + std::vector > *plist, std::vector > *splist) { for (size_t i = 0; i != plist->size(); i++) { - v3s16 p = (*plist)[i].first - p0; + v3POS p = (*plist)[i].first - p0; int index = p.Z * (size.Y * size.X) + p.Y * size.X + p.X; if (index < size.Z * size.Y * size.X) { u8 prob = (*plist)[i].second; diff --git a/src/mapgen/mg_schematic.h b/src/mapgen/mg_schematic.h index 9189bb3a79..faa3ca9352 100644 --- a/src/mapgen/mg_schematic.h +++ b/src/mapgen/mg_schematic.h @@ -104,23 +104,23 @@ class Schematic : public ObjDef, public NodeResolver { const NodeDefManager *ndef, StringMap *replace_names = NULL); bool saveSchematicToFile(const std::string &filename, const NodeDefManager *ndef); - bool getSchematicFromMap(Map *map, v3s16 p1, v3s16 p2); + bool getSchematicFromMap(Map *map, v3POS p1, v3POS p2); bool deserializeFromMts(std::istream *is); bool serializeToMts(std::ostream *os) const; bool serializeToLua(std::ostream *os, bool use_comments, u32 indent_spaces) const; - void blitToVManip(MMVManip *vm, v3s16 p, Rotation rot, bool force_place); - bool placeOnVManip(MMVManip *vm, v3s16 p, u32 flags, Rotation rot, bool force_place); - void placeOnMap(ServerMap *map, v3s16 p, u32 flags, Rotation rot, bool force_place); + void blitToVManip(MMVManip *vm, v3POS p, Rotation rot, bool force_place); + bool placeOnVManip(MMVManip *vm, v3POS p, u32 flags, Rotation rot, bool force_place); + void placeOnMap(ServerMap *map, v3POS p, u32 flags, Rotation rot, bool force_place); - void applyProbabilities(v3s16 p0, - std::vector > *plist, + void applyProbabilities(v3POS p0, + std::vector > *plist, std::vector > *splist); std::vector c_nodes; u32 flags = 0; - v3s16 size; + v3POS size; MapNode *schemdata = nullptr; u8 *slice_probs = nullptr; diff --git a/src/mapgen/treegen.cpp b/src/mapgen/treegen.cpp index ec7771439f..f5580ae270 100644 --- a/src/mapgen/treegen.cpp +++ b/src/mapgen/treegen.cpp @@ -32,7 +32,7 @@ with this program; if not, write to the Free Software Foundation, Inc., namespace treegen { -void make_tree(MMVManip &vmanip, v3s16 p0, bool is_apple_tree, +void make_tree(MMVManip &vmanip, v3POS p0, bool is_apple_tree, const NodeDefManager *ndef, s32 seed) { /* @@ -52,7 +52,7 @@ void make_tree(MMVManip &vmanip, v3s16 p0, bool is_apple_tree, PseudoRandom pr(seed); s16 trunk_h = pr.range(4, 5); - v3s16 p1 = p0; + v3POS p1 = p0; for (s16 ii = 0; ii < trunk_h; ii++) { if (vmanip.m_area.contains(p1)) { u32 vi = vmanip.m_area.index(p1); @@ -64,7 +64,7 @@ void make_tree(MMVManip &vmanip, v3s16 p0, bool is_apple_tree, // p1 is now the last piece of the trunk p1.Y -= 1; - VoxelArea leaves_a(v3s16(-2, -1, -2), v3s16(2, 2, 2)); + VoxelArea leaves_a(v3POS(-2, -1, -2), v3POS(2, 2, 2)); Buffer leaves_d(leaves_a.getVolume()); for (s32 i = 0; i < leaves_a.getVolume(); i++) leaves_d[i] = 0; @@ -74,12 +74,12 @@ void make_tree(MMVManip &vmanip, v3s16 p0, bool is_apple_tree, for (s16 z = -d; z <= d; z++) for (s16 y = -d; y <= d; y++) for (s16 x = -d; x <= d; x++) { - leaves_d[leaves_a.index(v3s16(x, y, z))] = 1; + leaves_d[leaves_a.index(v3POS(x, y, z))] = 1; } // Add leaves randomly for (u32 iii = 0; iii < 7; iii++) { - v3s16 p( + v3POS p( pr.range(leaves_a.MinEdge.X, leaves_a.MaxEdge.X - d), pr.range(leaves_a.MinEdge.Y, leaves_a.MaxEdge.Y - d), pr.range(leaves_a.MinEdge.Z, leaves_a.MaxEdge.Z - d) @@ -88,18 +88,18 @@ void make_tree(MMVManip &vmanip, v3s16 p0, bool is_apple_tree, for (s16 z = 0; z <= d; z++) for (s16 y = 0; y <= d; y++) for (s16 x = 0; x <= d; x++) { - leaves_d[leaves_a.index(p + v3s16(x, y, z))] = 1; + leaves_d[leaves_a.index(p + v3POS(x, y, z))] = 1; } } // Blit leaves to vmanip for (s16 z = leaves_a.MinEdge.Z; z <= leaves_a.MaxEdge.Z; z++) for (s16 y = leaves_a.MinEdge.Y; y <= leaves_a.MaxEdge.Y; y++) { - v3s16 pmin(leaves_a.MinEdge.X, y, z); + v3POS pmin(leaves_a.MinEdge.X, y, z); u32 i = leaves_a.index(pmin); u32 vi = vmanip.m_area.index(pmin + p1); for (s16 x = leaves_a.MinEdge.X; x <= leaves_a.MaxEdge.X; x++) { - v3s16 p(x, y, z); + v3POS p(x, y, z); if (vmanip.m_area.contains(p + p1) && (vmanip.m_data[vi].getContent() == CONTENT_AIR || vmanip.m_data[vi].getContent() == CONTENT_IGNORE)) { @@ -119,15 +119,15 @@ void make_tree(MMVManip &vmanip, v3s16 p0, bool is_apple_tree, // L-System tree LUA spawner -treegen::error spawn_ltree(ServerMap *map, v3s16 p0, +treegen::error spawn_ltree(ServerMap *map, v3POS p0, const NodeDefManager *ndef, const TreeDef &tree_definition) { - std::map modified_blocks; + std::map modified_blocks; MMVManip vmanip(map); - v3s16 tree_blockp = getNodeBlockPos(p0); + v3BPOS tree_blockp = getNodeBlockPos(p0); treegen::error e; - vmanip.initialEmerge(tree_blockp - v3s16(1, 1, 1), tree_blockp + v3s16(1, 3, 1)); + vmanip.initialEmerge(tree_blockp - v3POS(1, 1, 1), tree_blockp + v3POS(1, 3, 1)); e = make_ltree(vmanip, p0, ndef, tree_definition); if (e != SUCCESS) return e; @@ -145,7 +145,7 @@ treegen::error spawn_ltree(ServerMap *map, v3s16 p0, //L-System tree generator -treegen::error make_ltree(MMVManip &vmanip, v3s16 p0, +treegen::error make_ltree(MMVManip &vmanip, v3POS p0, const NodeDefManager *ndef, TreeDef tree_definition) { s32 seed; @@ -530,7 +530,7 @@ treegen::error make_ltree(MMVManip &vmanip, v3s16 p0, void tree_trunk_placement(MMVManip &vmanip, v3f p0, TreeDef &tree_definition) { - v3s16 p1 = v3s16(myround(p0.X), myround(p0.Y), myround(p0.Z)); + v3POS p1 = v3POS(myround(p0.X), myround(p0.Y), myround(p0.Z)); if (!vmanip.m_area.contains(p1)) return; u32 vi = vmanip.m_area.index(p1); @@ -550,7 +550,7 @@ void tree_leaves_placement(MMVManip &vmanip, v3f p0, MapNode leavesnode = tree_definition.leavesnode; if (ps.range(1, 100) > 100 - tree_definition.leaves2_chance) leavesnode = tree_definition.leaves2node; - v3s16 p1 = v3s16(myround(p0.X), myround(p0.Y), myround(p0.Z)); + v3POS p1 = v3POS(myround(p0.X), myround(p0.Y), myround(p0.Z)); if (!vmanip.m_area.contains(p1)) return; u32 vi = vmanip.m_area.index(p1); @@ -574,7 +574,7 @@ void tree_single_leaves_placement(MMVManip &vmanip, v3f p0, MapNode leavesnode = tree_definition.leavesnode; if (ps.range(1, 100) > 100 - tree_definition.leaves2_chance) leavesnode = tree_definition.leaves2node; - v3s16 p1 = v3s16(myround(p0.X), myround(p0.Y), myround(p0.Z)); + v3POS p1 = v3POS(myround(p0.X), myround(p0.Y), myround(p0.Z)); if (!vmanip.m_area.contains(p1)) return; u32 vi = vmanip.m_area.index(p1); @@ -587,7 +587,7 @@ void tree_single_leaves_placement(MMVManip &vmanip, v3f p0, void tree_fruit_placement(MMVManip &vmanip, v3f p0, TreeDef &tree_definition) { - v3s16 p1 = v3s16(myround(p0.X), myround(p0.Y), myround(p0.Z)); + v3POS p1 = v3POS(myround(p0.X), myround(p0.Y), myround(p0.Z)); if (!vmanip.m_area.contains(p1)) return; u32 vi = vmanip.m_area.index(p1); @@ -639,7 +639,7 @@ v3f transposeMatrix(irr::core::matrix4 M, v3f v) } -void make_jungletree(MMVManip &vmanip, v3s16 p0, const NodeDefManager *ndef, +void make_jungletree(MMVManip &vmanip, v3POS p0, const NodeDefManager *ndef, s32 seed) { /* @@ -666,8 +666,8 @@ void make_jungletree(MMVManip &vmanip, v3s16 p0, const NodeDefManager *ndef, for (s16 z= -1; z <= 1; z++) { if (pr.range(0, 2) == 0) continue; - v3s16 p1 = p0 + v3s16(x, 0, z); - v3s16 p2 = p0 + v3s16(x, -1, z); + v3POS p1 = p0 + v3POS(x, 0, z); + v3POS p2 = p0 + v3POS(x, -1, z); u32 vi1 = vmanip.m_area.index(p1); u32 vi2 = vmanip.m_area.index(p2); @@ -681,7 +681,7 @@ void make_jungletree(MMVManip &vmanip, v3s16 p0, const NodeDefManager *ndef, vmanip.m_data[vmanip.m_area.index(p0)] = treenode; s16 trunk_h = pr.range(8, 12); - v3s16 p1 = p0; + v3POS p1 = p0; for (s16 ii = 0; ii < trunk_h; ii++) { if (vmanip.m_area.contains(p1)) { u32 vi = vmanip.m_area.index(p1); @@ -693,7 +693,7 @@ void make_jungletree(MMVManip &vmanip, v3s16 p0, const NodeDefManager *ndef, // p1 is now the last piece of the trunk p1.Y -= 1; - VoxelArea leaves_a(v3s16(-3, -2, -3), v3s16(3, 2, 3)); + VoxelArea leaves_a(v3POS(-3, -2, -3), v3POS(3, 2, 3)); //SharedPtr leaves_d(new u8[leaves_a.getVolume()]); Buffer leaves_d(leaves_a.getVolume()); for (s32 i = 0; i < leaves_a.getVolume(); i++) @@ -704,12 +704,12 @@ void make_jungletree(MMVManip &vmanip, v3s16 p0, const NodeDefManager *ndef, for (s16 z = -d; z <= d; z++) for (s16 y = -d; y <= d; y++) for (s16 x = -d; x <= d; x++) { - leaves_d[leaves_a.index(v3s16(x,y,z))] = 1; + leaves_d[leaves_a.index(v3POS(x,y,z))] = 1; } // Add leaves randomly for (u32 iii = 0; iii < 30; iii++) { - v3s16 p( + v3POS p( pr.range(leaves_a.MinEdge.X, leaves_a.MaxEdge.X - d), pr.range(leaves_a.MinEdge.Y, leaves_a.MaxEdge.Y - d), pr.range(leaves_a.MinEdge.Z, leaves_a.MaxEdge.Z - d) @@ -718,18 +718,18 @@ void make_jungletree(MMVManip &vmanip, v3s16 p0, const NodeDefManager *ndef, for (s16 z = 0; z <= d; z++) for (s16 y = 0; y <= d; y++) for (s16 x = 0; x <= d; x++) { - leaves_d[leaves_a.index(p + v3s16(x, y, z))] = 1; + leaves_d[leaves_a.index(p + v3POS(x, y, z))] = 1; } } // Blit leaves to vmanip for (s16 z = leaves_a.MinEdge.Z; z <= leaves_a.MaxEdge.Z; z++) for (s16 y = leaves_a.MinEdge.Y; y <= leaves_a.MaxEdge.Y; y++) { - v3s16 pmin(leaves_a.MinEdge.X, y, z); + v3POS pmin(leaves_a.MinEdge.X, y, z); u32 i = leaves_a.index(pmin); u32 vi = vmanip.m_area.index(pmin + p1); for (s16 x = leaves_a.MinEdge.X; x <= leaves_a.MaxEdge.X; x++) { - v3s16 p(x, y, z); + v3POS p(x, y, z); if (vmanip.m_area.contains(p + p1) && (vmanip.m_data[vi].getContent() == CONTENT_AIR || vmanip.m_data[vi].getContent() == CONTENT_IGNORE)) { @@ -743,7 +743,7 @@ void make_jungletree(MMVManip &vmanip, v3s16 p0, const NodeDefManager *ndef, } -void make_pine_tree(MMVManip &vmanip, v3s16 p0, const NodeDefManager *ndef, +void make_pine_tree(MMVManip &vmanip, v3POS p0, const NodeDefManager *ndef, s32 seed) { /* @@ -771,7 +771,7 @@ void make_pine_tree(MMVManip &vmanip, v3s16 p0, const NodeDefManager *ndef, PseudoRandom pr(seed); u16 trunk_h = pr.range(9, 13); - v3s16 p1 = p0; + v3POS p1 = p0; for (u16 ii = 0; ii < trunk_h; ii++) { if (vmanip.m_area.contains(p1)) { u32 vi = vmanip.m_area.index(p1); @@ -783,7 +783,7 @@ void make_pine_tree(MMVManip &vmanip, v3s16 p0, const NodeDefManager *ndef, // Make p1 the top node of the trunk p1.Y -= 1; - VoxelArea leaves_a(v3s16(-3, -6, -3), v3s16(3, 3, 3)); + VoxelArea leaves_a(v3POS(-3, -6, -3), v3POS(3, 3, 3)); Buffer leaves_d(leaves_a.getVolume()); for (s32 i = 0; i < leaves_a.getVolume(); i++) leaves_d[i] = 0; @@ -792,8 +792,8 @@ void make_pine_tree(MMVManip &vmanip, v3s16 p0, const NodeDefManager *ndef, u16 dev = 3; for (s16 yy = -1; yy <= 1; yy++) { for (s16 zz = -dev; zz <= dev; zz++) { - u32 i = leaves_a.index(v3s16(-dev, yy, zz)); - u32 ia = leaves_a.index(v3s16(-dev, yy+1, zz)); + u32 i = leaves_a.index(v3POS(-dev, yy, zz)); + u32 ia = leaves_a.index(v3POS(-dev, yy+1, zz)); for (s16 xx = -dev; xx <= dev; xx++) { if (pr.range(0, 20) <= 19 - dev) { leaves_d[i] = 1; @@ -807,9 +807,9 @@ void make_pine_tree(MMVManip &vmanip, v3s16 p0, const NodeDefManager *ndef, } // Centre top nodes - leaves_d[leaves_a.index(v3s16(0, 1, 0))] = 1; - leaves_d[leaves_a.index(v3s16(0, 2, 0))] = 1; - leaves_d[leaves_a.index(v3s16(0, 3, 0))] = 2; + leaves_d[leaves_a.index(v3POS(0, 1, 0))] = 1; + leaves_d[leaves_a.index(v3POS(0, 2, 0))] = 1; + leaves_d[leaves_a.index(v3POS(0, 3, 0))] = 2; // Lower branches s16 my = -6; @@ -820,8 +820,8 @@ void make_pine_tree(MMVManip &vmanip, v3s16 p0, const NodeDefManager *ndef, if (yy > my) my = yy; for (s16 zz = zi; zz <= zi + 1; zz++) { - u32 i = leaves_a.index(v3s16(xi, yy, zz)); - u32 ia = leaves_a.index(v3s16(xi, yy + 1, zz)); + u32 i = leaves_a.index(v3POS(xi, yy, zz)); + u32 ia = leaves_a.index(v3POS(xi, yy + 1, zz)); for (s32 xx = xi; xx <= xi + 1; xx++) { leaves_d[i] = 1; if (leaves_d[ia] == 0) @@ -835,8 +835,8 @@ void make_pine_tree(MMVManip &vmanip, v3s16 p0, const NodeDefManager *ndef, dev = 2; for (s16 yy = my + 1; yy <= my + 2; yy++) { for (s16 zz = -dev; zz <= dev; zz++) { - u32 i = leaves_a.index(v3s16(-dev, yy, zz)); - u32 ia = leaves_a.index(v3s16(-dev, yy + 1, zz)); + u32 i = leaves_a.index(v3POS(-dev, yy, zz)); + u32 ia = leaves_a.index(v3POS(-dev, yy + 1, zz)); for (s16 xx = -dev; xx <= dev; xx++) { if (pr.range(0, 20) <= 19 - dev) { leaves_d[i] = 1; @@ -852,11 +852,11 @@ void make_pine_tree(MMVManip &vmanip, v3s16 p0, const NodeDefManager *ndef, // Blit leaves to vmanip for (s16 z = leaves_a.MinEdge.Z; z <= leaves_a.MaxEdge.Z; z++) for (s16 y = leaves_a.MinEdge.Y; y <= leaves_a.MaxEdge.Y; y++) { - v3s16 pmin(leaves_a.MinEdge.X, y, z); + v3POS pmin(leaves_a.MinEdge.X, y, z); u32 i = leaves_a.index(pmin); u32 vi = vmanip.m_area.index(pmin + p1); for (s16 x = leaves_a.MinEdge.X; x <= leaves_a.MaxEdge.X; x++) { - v3s16 p(x, y, z); + v3POS p(x, y, z); if (vmanip.m_area.contains(p + p1) && (vmanip.m_data[vi].getContent() == CONTENT_AIR || vmanip.m_data[vi].getContent() == CONTENT_IGNORE || diff --git a/src/mapgen/treegen.h b/src/mapgen/treegen.h index 59a4188241..34e955a9be 100644 --- a/src/mapgen/treegen.h +++ b/src/mapgen/treegen.h @@ -59,20 +59,20 @@ namespace treegen { }; // Add default tree - void make_tree(MMVManip &vmanip, v3s16 p0, + void make_tree(MMVManip &vmanip, v3POS p0, bool is_apple_tree, const NodeDefManager *ndef, s32 seed); // Add jungle tree - void make_jungletree(MMVManip &vmanip, v3s16 p0, + void make_jungletree(MMVManip &vmanip, v3POS p0, const NodeDefManager *ndef, s32 seed); // Add pine tree - void make_pine_tree(MMVManip &vmanip, v3s16 p0, + void make_pine_tree(MMVManip &vmanip, v3POS p0, const NodeDefManager *ndef, s32 seed); // Add L-Systems tree (used by engine) - treegen::error make_ltree(MMVManip &vmanip, v3s16 p0, + treegen::error make_ltree(MMVManip &vmanip, v3POS p0, const NodeDefManager *ndef, TreeDef tree_definition); // Spawn L-systems tree from LUA - treegen::error spawn_ltree (ServerMap *map, v3s16 p0, + treegen::error spawn_ltree (ServerMap *map, v3POS p0, const NodeDefManager *ndef, const TreeDef &tree_definition); // L-System tree gen helper functions diff --git a/src/mapnode.cpp b/src/mapnode.cpp index 73bd620fba..539014af73 100644 --- a/src/mapnode.cpp +++ b/src/mapnode.cpp @@ -169,16 +169,16 @@ u8 MapNode::getWallMounted(const NodeDefManager *nodemgr) const return 0; } -v3s16 MapNode::getWallMountedDir(const NodeDefManager *nodemgr) const +v3POS MapNode::getWallMountedDir(const NodeDefManager *nodemgr) const { switch(getWallMounted(nodemgr)) { - case 0: default: return v3s16(0,1,0); - case 1: return v3s16(0,-1,0); - case 2: return v3s16(1,0,0); - case 3: return v3s16(-1,0,0); - case 4: return v3s16(0,0,1); - case 5: return v3s16(0,0,-1); + case 0: default: return v3POS(0,1,0); + case 1: return v3POS(0,-1,0); + case 2: return v3POS(1,0,0); + case 3: return v3POS(-1,0,0); + case 4: return v3POS(0,0,1); + case 5: return v3POS(0,0,-1); } } @@ -396,15 +396,15 @@ void transformNodeBox(const MapNode &n, const NodeBox &nodebox, } else if(nodebox.type == NODEBOX_WALLMOUNTED) { - v3s16 dir = n.getWallMountedDir(nodemgr); + v3POS dir = n.getWallMountedDir(nodemgr); // top - if(dir == v3s16(0,1,0)) + if(dir == v3POS(0,1,0)) { boxes.push_back(nodebox.wall_top); } // bottom - else if(dir == v3s16(0,-1,0)) + else if(dir == v3POS(0,-1,0)) { boxes.push_back(nodebox.wall_bottom); } @@ -418,13 +418,13 @@ void transformNodeBox(const MapNode &n, const NodeBox &nodebox, }; for (v3f &vertex : vertices) { - if(dir == v3s16(-1,0,0)) + if(dir == v3POS(-1,0,0)) vertex.rotateXZBy(0); - if(dir == v3s16(1,0,0)) + if(dir == v3POS(1,0,0)) vertex.rotateXZBy(180); - if(dir == v3s16(0,0,-1)) + if(dir == v3POS(0,0,-1)) vertex.rotateXZBy(90); - if(dir == v3s16(0,0,1)) + if(dir == v3POS(0,0,1)) vertex.rotateXZBy(-90); } @@ -535,7 +535,7 @@ void transformNodeBox(const MapNode &n, const NodeBox &nodebox, } static inline void getNeighborConnectingFace( - const v3s16 &p, const NodeDefManager *nodedef, + const v3POS &p, const NodeDefManager *nodedef, Map *map, MapNode n, u8 bitmask, u8 *neighbors) { MapNode n2 = map->getNode(p); @@ -543,14 +543,14 @@ static inline void getNeighborConnectingFace( *neighbors |= bitmask; } -u8 MapNode::getNeighbors(v3s16 p, Map *map) const +u8 MapNode::getNeighbors(v3POS p, Map *map) const { const NodeDefManager *nodedef = map->getNodeDefManager(); u8 neighbors = 0; const ContentFeatures &f = nodedef->get(*this); // locate possible neighboring nodes to connect to if (f.drawtype == NDT_NODEBOX && f.node_box.type == NODEBOX_CONNECTED) { - v3s16 p2 = p; + v3POS p2 = p; p2.Y++; getNeighborConnectingFace(p2, nodedef, map, *this, 1, &neighbors); diff --git a/src/mapnode.h b/src/mapnode.h index afd3a96be3..b53ce7604b 100644 --- a/src/mapnode.h +++ b/src/mapnode.h @@ -239,7 +239,7 @@ struct MapNode u8 getFaceDir(const NodeDefManager *nodemgr, bool allow_wallmounted = false) const; u8 getWallMounted(const NodeDefManager *nodemgr) const; - v3s16 getWallMountedDir(const NodeDefManager *nodemgr) const; + v3POS getWallMountedDir(const NodeDefManager *nodemgr) const; /// @returns Rotation in range 0–239 (in 1.5° steps) u8 getDegRotate(const NodeDefManager *nodemgr) const; @@ -251,7 +251,7 @@ struct MapNode * * \param p coordinates of the node */ - u8 getNeighbors(v3s16 p, Map *map) const; + u8 getNeighbors(v3POS p, Map *map) const; /* Gets list of node boxes (used for rendering (NDT_NODEBOX)) diff --git a/src/mapsector.cpp b/src/mapsector.cpp index 3eefa54107..7af2e112d0 100644 --- a/src/mapsector.cpp +++ b/src/mapsector.cpp @@ -22,7 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "mapblock.h" #include "serialization.h" -MapSector::MapSector(Map *parent, v2s16 pos, IGameDef *gamedef): +MapSector::MapSector(Map *parent, v2POS pos, IGameDef *gamedef): m_parent(parent), m_pos(pos), m_gamedef(gamedef) @@ -48,7 +48,7 @@ void MapSector::deleteBlocks() m_blocks.clear(); } -MapBlock * MapSector::getBlockBuffered(s16 y) +MapBlock * MapSector::getBlockBuffered(BPOS y) { MapBlock *block; @@ -57,7 +57,7 @@ MapBlock * MapSector::getBlockBuffered(s16 y) } // If block doesn't exist, return NULL - std::unordered_map::const_iterator n = m_blocks.find(y); + std::unordered_map::const_iterator n = m_blocks.find(y); block = (n != m_blocks.end() ? n->second : nullptr); // Cache the last result @@ -67,23 +67,23 @@ MapBlock * MapSector::getBlockBuffered(s16 y) return block; } -MapBlock * MapSector::getBlockNoCreateNoEx(s16 y) +MapBlock * MapSector::getBlockNoCreateNoEx(BPOS y) { return getBlockBuffered(y); } -MapBlock * MapSector::createBlankBlockNoInsert(s16 y) +MapBlock * MapSector::createBlankBlockNoInsert(BPOS y) { assert(getBlockBuffered(y) == NULL); // Pre-condition - v3s16 blockpos_map(m_pos.X, y, m_pos.Y); + v3BPOS blockpos_map(m_pos.X, y, m_pos.Y); MapBlock *block = new MapBlock(m_parent, blockpos_map, m_gamedef); return block; } -MapBlock * MapSector::createBlankBlock(s16 y) +MapBlock * MapSector::createBlankBlock(BPOS y) { MapBlock *block = createBlankBlockNoInsert(y); @@ -94,14 +94,14 @@ MapBlock * MapSector::createBlankBlock(s16 y) void MapSector::insertBlock(MapBlock *block) { - s16 block_y = block->getPos().Y; + BPOS block_y = block->getPos().Y; MapBlock *block2 = getBlockBuffered(block_y); if (block2) { throw AlreadyExistsException("Block already exists"); } - v2s16 p2d(block->getPos().X, block->getPos().Z); + v2BPOS p2d(block->getPos().X, block->getPos().Z); assert(p2d == m_pos); // Insert into container @@ -110,7 +110,7 @@ void MapSector::insertBlock(MapBlock *block) void MapSector::deleteBlock(MapBlock *block) { - s16 block_y = block->getPos().Y; + BPOS block_y = block->getPos().Y; // Clear from cache m_block_cache = nullptr; diff --git a/src/mapsector.h b/src/mapsector.h index ffd4cdd1da..3220a2539a 100644 --- a/src/mapsector.h +++ b/src/mapsector.h @@ -40,19 +40,19 @@ class MapSector { public: - MapSector(Map *parent, v2s16 pos, IGameDef *gamedef); + MapSector(Map *parent, v2BPOS pos, IGameDef *gamedef); virtual ~MapSector(); void deleteBlocks(); - v2s16 getPos() + v2BPOS getPos() { return m_pos; } - MapBlock * getBlockNoCreateNoEx(s16 y); - MapBlock * createBlankBlockNoInsert(s16 y); - MapBlock * createBlankBlock(s16 y); + MapBlock * getBlockNoCreateNoEx(BPOS y); + MapBlock * createBlankBlockNoInsert(BPOS y); + MapBlock * createBlankBlock(BPOS y); void insertBlock(MapBlock *block); @@ -66,22 +66,22 @@ class MapSector protected: // The pile of MapBlocks - std::unordered_map m_blocks; + std::unordered_map m_blocks; Map *m_parent; // Position on parent (in MapBlock widths) - v2s16 m_pos; + v2BPOS m_pos; IGameDef *m_gamedef; // Last-used block is cached here for quicker access. // Be sure to set this to nullptr when the cached block is deleted MapBlock *m_block_cache = nullptr; - s16 m_block_cache_y; + BPOS m_block_cache_y; /* Private methods */ - MapBlock *getBlockBuffered(s16 y); + MapBlock *getBlockBuffered(BPOS y); }; diff --git a/src/network/clientpackethandler.cpp b/src/network/clientpackethandler.cpp index d20a80fb7a..88ffb19dc5 100644 --- a/src/network/clientpackethandler.cpp +++ b/src/network/clientpackethandler.cpp @@ -227,27 +227,27 @@ void Client::handleCommand_AccessDenied(NetworkPacket* pkt) void Client::handleCommand_RemoveNode(NetworkPacket* pkt) { - if (pkt->getSize() < 6) + if (pkt->getSize() < sizeof(v3POS)) return; - v3s16 p; + v3POS p; *pkt >> p; removeNode(p); } void Client::handleCommand_AddNode(NetworkPacket* pkt) { - if (pkt->getSize() < 6 + MapNode::serializedLength(m_server_ser_ver)) + if (pkt->getSize() < sizeof(v3POS) + MapNode::serializedLength(m_server_ser_ver)) return; - v3s16 p; + v3POS p; *pkt >> p; MapNode n; - n.deSerialize(pkt->getU8Ptr(6), m_server_ser_ver); + n.deSerialize(pkt->getU8Ptr(sizeof(v3POS)), m_server_ser_ver); bool remove_metadata = true; - u32 index = 6 + MapNode::serializedLength(m_server_ser_ver); + u32 index = sizeof(v3POS) + MapNode::serializedLength(m_server_ser_ver); if ((pkt->getSize() >= index + 1) && pkt->getU8(index)) { remove_metadata = false; } @@ -270,7 +270,7 @@ void Client::handleCommand_NodemetaChanged(NetworkPacket *pkt) Map &map = m_env.getMap(); for (NodeMetadataMap::const_iterator i = meta_updates_list.begin(); i != meta_updates_list.end(); ++i) { - v3s16 pos = i->first; + v3POS pos = i->first; if (map.isValidPosition(pos) && map.setNodeMetadata(pos, i->second)) @@ -284,19 +284,19 @@ void Client::handleCommand_NodemetaChanged(NetworkPacket *pkt) void Client::handleCommand_BlockData(NetworkPacket* pkt) { // Ignore too small packet - if (pkt->getSize() < 6) + if (pkt->getSize() < sizeof(v3POS)) return; - v3s16 p; + v3POS p; *pkt >> p; - std::string datastring(pkt->getString(6), pkt->getSize() - 6); + std::string datastring(pkt->getString(sizeof(p)), pkt->getSize() - sizeof(p)); std::istringstream istr(datastring, std::ios_base::binary); MapSector *sector; MapBlock *block; - v2s16 p2d(p.X, p.Z); + v2BPOS p2d(p.X, p.Z); sector = m_env.getMap().emergeSector(p2d); assert(sector->getPos() == p2d); diff --git a/src/network/networkprotocol.h b/src/network/networkprotocol.h index 8214cc5b14..7b04345bd1 100644 --- a/src/network/networkprotocol.h +++ b/src/network/networkprotocol.h @@ -252,7 +252,7 @@ enum ToClientCommand /* Message from server to accept auth. - v3s16 player's position + v3f(0,BS/2,0) floatToInt'd + v3POS player's position + v3f(0,BS/2,0) floatToInt'd u64 map seed f1000 recommended send interval u32 : supported auth methods for sudo mode @@ -278,7 +278,7 @@ enum ToClientCommand TOCLIENT_BLOCKDATA = 0x20, //TODO: Multiple blocks TOCLIENT_ADDNODE = 0x21, /* - v3s16 position + v3POS position serialized mapnode u8 keep_metadata // Added in protocol version 22 */ @@ -829,8 +829,8 @@ enum ToServerCommand /* [0] u16 command [2] u8 count - [3] v3s16 pos_0 - [3+6] v3s16 pos_1 + [3] v3POS pos_0 + [3+6] v3POS pos_1 ... */ @@ -838,8 +838,8 @@ enum ToServerCommand /* [0] u16 command [2] u8 count - [3] v3s16 pos_0 - [3+6] v3s16 pos_1 + [3] v3POS pos_0 + [3+6] v3POS pos_1 ... */ @@ -906,7 +906,7 @@ enum ToServerCommand TOSERVER_NODEMETA_FIELDS = 0x3b, /* - v3s16 p + v3POS p u16 len u8[len] form name (reserved for future use) u16 number of fields diff --git a/src/network/serverpackethandler.cpp b/src/network/serverpackethandler.cpp index c1ddb50052..f22a0fd299 100644 --- a/src/network/serverpackethandler.cpp +++ b/src/network/serverpackethandler.cpp @@ -439,15 +439,15 @@ void Server::handleCommand_GotBlocks(NetworkPacket* pkt) /* [0] u16 command [2] u8 count - [3] v3s16 pos_0 - [3+6] v3s16 pos_1 + [3] v3POS pos_0 + [3+6] v3POS pos_1 ... */ u8 count; *pkt >> count; - if ((s16)pkt->getSize() < 1 + (int)count * 6) { + if ((s16)pkt->getSize() < 1 + (int)count * (int)sizeof(v3BPOS)) { throw con::InvalidIncomingDataException ("GOTBLOCKS length is too short"); } @@ -456,7 +456,7 @@ void Server::handleCommand_GotBlocks(NetworkPacket* pkt) RemoteClient *client = m_clients.lockedGetClientNoEx(pkt->getPeerId()); for (u16 i = 0; i < count; i++) { - v3s16 p; + v3BPOS p; *pkt >> p; client->GotBlock(p); } @@ -562,8 +562,8 @@ void Server::handleCommand_DeletedBlocks(NetworkPacket* pkt) /* [0] u16 command [2] u8 count - [3] v3s16 pos_0 - [3+6] v3s16 pos_1 + [3] v3POS pos_0 + [3+6] v3POS pos_1 ... */ @@ -572,13 +572,13 @@ void Server::handleCommand_DeletedBlocks(NetworkPacket* pkt) RemoteClient *client = getClient(pkt->getPeerId()); - if ((s16)pkt->getSize() < 1 + (int)count * 6) { + if ((s16)pkt->getSize() < 1 + (int)count * (int)sizeof(v3BPOS)) { throw con::InvalidIncomingDataException ("DELETEDBLOCKS length is too short"); } for (u16 i = 0; i < count; i++) { - v3s16 p; + v3BPOS p; *pkt >> p; client->SetBlockNotSent(p); } @@ -978,7 +978,7 @@ void Server::handleCommand_Interact(NetworkPacket *pkt) if (pointed.type == POINTEDTHING_NODE) { // Re-send block to revert change on client-side RemoteClient *client = getClient(peer_id); - v3s16 blockpos = getNodeBlockPos(pointed.node_undersurface); + v3BPOS blockpos = getNodeBlockPos(pointed.node_undersurface); client->SetBlockNotSent(blockpos); } // Call callbacks @@ -1029,12 +1029,12 @@ void Server::handleCommand_Interact(NetworkPacket *pkt) RemoteClient *client = getClient(peer_id); // Digging completed -> under if (action == INTERACT_DIGGING_COMPLETED) { - v3s16 blockpos = getNodeBlockPos(pointed.node_undersurface); + v3BPOS blockpos = getNodeBlockPos(pointed.node_undersurface); client->SetBlockNotSent(blockpos); } // Placement -> above else if (action == INTERACT_PLACE) { - v3s16 blockpos = getNodeBlockPos(pointed.node_abovesurface); + v3BPOS blockpos = getNodeBlockPos(pointed.node_abovesurface); client->SetBlockNotSent(blockpos); } return; @@ -1067,7 +1067,7 @@ void Server::handleCommand_Interact(NetworkPacket *pkt) if (pointed.type == POINTEDTHING_NODE) { // Re-send block to revert change on client-side RemoteClient *client = getClient(peer_id); - v3s16 blockpos = getNodeBlockPos(pointed.node_undersurface); + v3BPOS blockpos = getNodeBlockPos(pointed.node_undersurface); client->SetBlockNotSent(blockpos); } return; @@ -1087,7 +1087,7 @@ void Server::handleCommand_Interact(NetworkPacket *pkt) MapNode n(CONTENT_IGNORE); bool pos_ok; - v3s16 p_under = pointed.node_undersurface; + v3POS p_under = pointed.node_undersurface; n = m_env->getMap().getNode(p_under, &pos_ok); if (!pos_ok) { infostream << "Server: Not punching: Node not found. " @@ -1140,7 +1140,7 @@ void Server::handleCommand_Interact(NetworkPacket *pkt) if (pointed.type != POINTEDTHING_NODE) return; bool pos_ok; - v3s16 p_under = pointed.node_undersurface; + v3POS p_under = pointed.node_undersurface; MapNode n = m_env->getMap().getNode(p_under, &pos_ok); if (!pos_ok) { infostream << "Server: Not finishing digging: Node not found. " @@ -1152,7 +1152,7 @@ void Server::handleCommand_Interact(NetworkPacket *pkt) /* Cheat prevention */ bool is_valid_dig = true; if (enable_anticheat && !isSingleplayer()) { - v3s16 nocheat_p = playersao->getNoCheatDigPos(); + v3POS nocheat_p = playersao->getNoCheatDigPos(); float nocheat_t = playersao->getNoCheatDigTime(); playersao->noCheatDigEnd(); // If player didn't start digging this, ignore dig @@ -1222,7 +1222,7 @@ void Server::handleCommand_Interact(NetworkPacket *pkt) if (is_valid_dig && n.getContent() != CONTENT_IGNORE) m_script->node_on_dig(p_under, n, playersao); - v3s16 blockpos = getNodeBlockPos(p_under); + v3BPOS blockpos = getNodeBlockPos(p_under); RemoteClient *client = getClient(peer_id); // Send unusual result (that is, node not being removed) if (m_env->getMap().getNode(p_under).getContent() != CONTENT_AIR) @@ -1279,8 +1279,8 @@ void Server::handleCommand_Interact(NetworkPacket *pkt) // If item has node placement prediction, always send the // blocks to make sure the client knows what exactly happened RemoteClient *client = getClient(peer_id); - v3s16 blockpos = getNodeBlockPos(pointed.node_abovesurface); - v3s16 blockpos2 = getNodeBlockPos(pointed.node_undersurface); + v3BPOS blockpos = getNodeBlockPos(pointed.node_abovesurface); + v3BPOS blockpos2 = getNodeBlockPos(pointed.node_undersurface); if (had_prediction) { client->SetBlockNotSent(blockpos); if (blockpos2 != blockpos) @@ -1358,7 +1358,7 @@ void Server::handleCommand_RemovedSounds(NetworkPacket* pkt) void Server::handleCommand_NodeMetaFields(NetworkPacket* pkt) { - v3s16 p; + v3POS p; std::string formname; u16 num; diff --git a/src/nodedef.h b/src/nodedef.h index ea50d42813..d5fff2a5ac 100644 --- a/src/nodedef.h +++ b/src/nodedef.h @@ -586,7 +586,7 @@ class NodeDefManager { * contains all nodes' selection boxes. The returned box might be larger * than the minimal size if the largest node is removed from the manager. */ - inline core::aabbox3d getSelectionBoxIntUnion() const { + inline core::aabbox3d getSelectionBoxIntUnion() const { return m_selection_box_int_union; } @@ -785,7 +785,7 @@ class NodeDefManager { * contains all nodes' selection boxes. * Might be larger if big nodes are removed from the manager. */ - core::aabbox3d m_selection_box_int_union; + core::aabbox3d m_selection_box_int_union; /*! * NodeResolver instances to notify once node registration has finished. diff --git a/src/nodemetadata.cpp b/src/nodemetadata.cpp index b5052c3b87..e48cd1c245 100644 --- a/src/nodemetadata.cpp +++ b/src/nodemetadata.cpp @@ -132,15 +132,15 @@ void NodeMetadataList::serialize(std::ostream &os, u8 blockver, bool disk, for (NodeMetadataMap::const_iterator i = m_data.begin(); i != m_data.end(); ++i) { - v3s16 p = i->first; + v3POS p = i->first; NodeMetadata *data = i->second; if (!include_empty && data->empty()) continue; if (absolute_pos) { - writeS16(os, p.X); - writeS16(os, p.Y); - writeS16(os, p.Z); + writePOS(os, p.X); + writePOS(os, p.Y); + writePOS(os, p.Z); } else { // Serialize positions within a mapblock u16 p16 = (p.Z * MAP_BLOCKSIZE + p.Y) * MAP_BLOCKSIZE + p.X; @@ -172,11 +172,11 @@ void NodeMetadataList::deSerialize(std::istream &is, u16 count = readU16(is); for (u16 i = 0; i < count; i++) { - v3s16 p; + v3POS p; if (absolute_pos) { - p.X = readS16(is); - p.Y = readS16(is); - p.Z = readS16(is); + p.X = readPOS(is); + p.Y = readPOS(is); + p.Z = readPOS(is); } else { u16 p16 = readU16(is); p.X = p16 & (MAP_BLOCKSIZE - 1); @@ -203,9 +203,9 @@ NodeMetadataList::~NodeMetadataList() clear(); } -std::vector NodeMetadataList::getAllKeys() +std::vector NodeMetadataList::getAllKeys() { - std::vector keys; + std::vector keys; keys.reserve(m_data.size()); for (const auto &it : m_data) keys.push_back(it.first); @@ -213,7 +213,7 @@ std::vector NodeMetadataList::getAllKeys() return keys; } -NodeMetadata *NodeMetadataList::get(v3s16 p) +NodeMetadata *NodeMetadataList::get(v3POS p) { NodeMetadataMap::const_iterator n = m_data.find(p); if (n == m_data.end()) @@ -221,7 +221,7 @@ NodeMetadata *NodeMetadataList::get(v3s16 p) return n->second; } -void NodeMetadataList::remove(v3s16 p) +void NodeMetadataList::remove(v3POS p) { NodeMetadata *olddata = get(p); if (olddata) { @@ -231,7 +231,7 @@ void NodeMetadataList::remove(v3s16 p) } } -void NodeMetadataList::set(v3s16 p, NodeMetadata *d) +void NodeMetadataList::set(v3POS p, NodeMetadata *d) { remove(p); m_data.emplace(p, d); diff --git a/src/nodemetadata.h b/src/nodemetadata.h index 4b5b4d887d..b659b50f45 100644 --- a/src/nodemetadata.h +++ b/src/nodemetadata.h @@ -20,6 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #pragma once #include +#include "irr_v3d.h" #include "metadata.h" /* @@ -70,7 +71,7 @@ class NodeMetadata : public Metadata List of metadata of all the nodes of a block */ -typedef std::map NodeMetadataMap; +typedef std::map NodeMetadataMap; class NodeMetadataList { @@ -87,13 +88,13 @@ class NodeMetadataList bool absolute_pos = false); // Add all keys in this list to the vector keys - std::vector getAllKeys(); + std::vector getAllKeys(); // Get pointer to data - NodeMetadata *get(v3s16 p); + NodeMetadata *get(v3POS p); // Deletes data - void remove(v3s16 p); + void remove(v3POS p); // Deletes old data and sets a new one - void set(v3s16 p, NodeMetadata *d); + void set(v3POS p, NodeMetadata *d); // Deletes all void clear(); diff --git a/src/nodetimer.cpp b/src/nodetimer.cpp index ec8611a013..d139ffedec 100644 --- a/src/nodetimer.cpp +++ b/src/nodetimer.cpp @@ -64,7 +64,7 @@ void NodeTimerList::serialize(std::ostream &os, u8 map_format_version) const NodeTimer t = timer.second; NodeTimer nt = NodeTimer(t.timeout, t.timeout - (f32)(timer.first - m_time), t.position); - v3s16 p = t.position; + v3POS p = t.position; u16 p16 = p.Z * MAP_BLOCKSIZE * MAP_BLOCKSIZE + p.Y * MAP_BLOCKSIZE + p.X; writeU16(os, p16); @@ -95,7 +95,7 @@ void NodeTimerList::deSerialize(std::istream &is, u8 map_format_version) for (u16 i = 0; i < count; i++) { u16 p16 = readU16(is); - v3s16 p; + v3POS p; p.Z = p16 / MAP_BLOCKSIZE / MAP_BLOCKSIZE; p16 &= MAP_BLOCKSIZE * MAP_BLOCKSIZE - 1; p.Y = p16 / MAP_BLOCKSIZE; diff --git a/src/nodetimer.h b/src/nodetimer.h index 40e54ccc56..29a6163735 100644 --- a/src/nodetimer.h +++ b/src/nodetimer.h @@ -36,9 +36,9 @@ class NodeTimer { public: NodeTimer() = default; - NodeTimer(const v3s16 &position_): + NodeTimer(const v3POS &position_): position(position_) {} - NodeTimer(f32 timeout_, f32 elapsed_, v3s16 position_): + NodeTimer(f32 timeout_, f32 elapsed_, v3POS position_): timeout(timeout_), elapsed(elapsed_), position(position_) {} ~NodeTimer() = default; @@ -47,7 +47,7 @@ class NodeTimer f32 timeout = 0.0f; f32 elapsed = 0.0f; - v3s16 position; + v3POS position; }; /* @@ -64,8 +64,8 @@ class NodeTimerList void deSerialize(std::istream &is, u8 map_format_version); // Get timer - NodeTimer get(const v3s16 &p) { - std::map::iterator>::iterator n = + NodeTimer get(const v3POS &p) { + std::map::iterator>::iterator n = m_iterators.find(p); if (n == m_iterators.end()) return NodeTimer(); @@ -74,8 +74,8 @@ class NodeTimerList return t; } // Deletes timer - void remove(v3s16 p) { - std::map::iterator>::iterator n = + void remove(v3POS p) { + std::map::iterator>::iterator n = m_iterators.find(p); if(n != m_iterators.end()) { double removed_time = n->second->first; @@ -94,14 +94,14 @@ class NodeTimerList } // Undefined behaviour if there already is a timer void insert(NodeTimer timer) { - v3s16 p = timer.position; + v3POS p = timer.position; double trigger_time = m_time + (double)(timer.timeout - timer.elapsed); std::multimap::iterator it = m_timers.insert(std::pair( trigger_time, timer )); m_iterators.insert( - std::pair::iterator>(p, it)); + std::pair::iterator>(p, it)); if (m_next_trigger_time == -1. || trigger_time < m_next_trigger_time) m_next_trigger_time = trigger_time; } @@ -122,7 +122,7 @@ class NodeTimerList private: std::multimap m_timers; - std::map::iterator> m_iterators; + std::map::iterator> m_iterators; double m_next_trigger_time = -1.0; double m_time = 0.0; }; diff --git a/src/pathfinder.cpp b/src/pathfinder.cpp index c45ce9158b..bb4083a102 100644 --- a/src/pathfinder.cpp +++ b/src/pathfinder.cpp @@ -105,22 +105,22 @@ class PathGridnode { * read cost in a specific direction * @param dir direction of cost to fetch */ - PathCost getCost(v3s16 dir); + PathCost getCost(v3POS dir); /** * set cost value for movement * @param dir direction to set cost for * @cost cost to set */ - void setCost(v3s16 dir, const PathCost &cost); + void setCost(v3POS dir, const PathCost &cost); bool valid = false; /**< node is on surface */ bool target = false; /**< node is target position */ bool source = false; /**< node is stating position */ int totalcost = -1; /**< cost to move here from starting point */ int estimated_cost = -1; /**< totalcost + heuristic cost to end */ - v3s16 sourcedir; /**< origin of movement for current cost */ - v3s16 pos; /**< real position of node */ + v3POS sourcedir; /**< origin of movement for current cost */ + v3POS pos; /**< real position of node */ PathCost directions[4]; /**< cost in different directions */ bool is_closed = false; /**< for A* search: if true, is in closed list */ bool is_open = false; /**< for A* search: if true, is in open list */ @@ -142,21 +142,21 @@ class PathfinderCompareHeuristic; /** Abstract class to manage the map data */ class GridNodeContainer { public: - virtual PathGridnode &access(v3s16 p)=0; + virtual PathGridnode &access(v3POS p)=0; virtual ~GridNodeContainer() = default; protected: Pathfinder *m_pathf; - void initNode(v3s16 ipos, PathGridnode *p_node); + void initNode(v3POS ipos, PathGridnode *p_node); }; class ArrayGridNodeContainer : public GridNodeContainer { public: virtual ~ArrayGridNodeContainer() = default; - ArrayGridNodeContainer(Pathfinder *pathf, v3s16 dimensions); - virtual PathGridnode &access(v3s16 p); + ArrayGridNodeContainer(Pathfinder *pathf, v3POS dimensions); + virtual PathGridnode &access(v3POS p); private: int m_x_stride; @@ -169,9 +169,9 @@ class MapGridNodeContainer : public GridNodeContainer { virtual ~MapGridNodeContainer() = default; MapGridNodeContainer(Pathfinder *pathf); - virtual PathGridnode &access(v3s16 p); + virtual PathGridnode &access(v3POS p); private: - std::map m_nodes; + std::map m_nodes; }; /** class doing pathfinding */ @@ -193,8 +193,8 @@ class Pathfinder { * @param max_drop maximum number of blocks a path may drop * @param algo Algorithm to use for finding a path */ - std::vector getPath(v3s16 source, - v3s16 destination, + std::vector getPath(v3POS source, + v3POS destination, unsigned int searchdistance, unsigned int max_jump, unsigned int max_drop, @@ -208,41 +208,41 @@ class Pathfinder { * @param ipos a index position * @return map position */ - v3s16 getRealPos(v3s16 ipos); + v3POS getRealPos(v3POS ipos); /** * transform mappos to index pos * @param pos a real pos * @return index position */ - v3s16 getIndexPos(v3s16 pos); + v3POS getIndexPos(v3POS pos); /** * get gridnode at a specific index position * @param ipos index position * @return gridnode for index */ - PathGridnode &getIndexElement(v3s16 ipos); + PathGridnode &getIndexElement(v3POS ipos); /** * Get gridnode at a specific index position * @return gridnode for index */ - PathGridnode &getIdxElem(s16 x, s16 y, s16 z); + PathGridnode &getIdxElem(POS x, POS y, POS z); /** * invert a 3D position (change sign of coordinates) * @param pos 3D position * @return pos *-1 */ - v3s16 invert(v3s16 pos); + v3POS invert(v3POS pos); /** * check if a index is within current search area * @param index position to validate * @return true/false */ - bool isValidIndex(v3s16 index); + bool isValidIndex(v3POS index); /* algorithm functions */ @@ -252,7 +252,7 @@ class Pathfinder { * @param pos position to calc distance * @return integer distance */ - int getXZManhattanDist(v3s16 pos); + int getXZManhattanDist(v3POS pos); /** * calculate cost of movement @@ -260,7 +260,7 @@ class Pathfinder { * @param dir direction to move to * @return cost information */ - PathCost calcCost(v3s16 pos, v3s16 dir); + PathCost calcCost(v3POS pos, v3POS dir); /** * recursive update whole search areas total cost information @@ -270,7 +270,7 @@ class Pathfinder { * @param level current recursion depth * @return true/false path to destination has been found */ - bool updateAllCosts(v3s16 ipos, v3s16 srcdir, int current_cost, int level); + bool updateAllCosts(v3POS ipos, v3POS srcdir, int current_cost, int level); /** * try to find a path to destination using a heuristic function @@ -279,7 +279,7 @@ class Pathfinder { * @param idestination end position (index pos) * @return true/false path to destination has been found */ - bool updateCostHeuristic(v3s16 isource, v3s16 idestination); + bool updateCostHeuristic(v3POS isource, v3POS idestination); /** * build a vector containing all nodes from destination to source; @@ -288,7 +288,7 @@ class Pathfinder { * @param ipos initial pos to check (index pos) * @return true/false path has been fully built */ - bool buildPath(std::vector &path, v3s16 ipos); + bool buildPath(std::vector &path, v3POS ipos); /** * go downwards from a position until some barrier @@ -298,7 +298,7 @@ class Pathfinder { * @return new position after movement; if too far down, * pos is returned */ - v3s16 walkDownwards(v3s16 pos, unsigned int max_down); + v3POS walkDownwards(v3POS pos, unsigned int max_down); /* variables */ int m_max_index_x = 0; /**< max index of search area in x direction */ @@ -311,10 +311,10 @@ class Pathfinder { bool m_prefetch = true; /**< prefetch cost data */ - v3s16 m_start; /**< source position */ - v3s16 m_destination; /**< destination position */ + v3POS m_start; /**< source position */ + v3POS m_destination; /**< destination position */ - core::aabbox3d m_limits; /**< position limits in real map coordinates */ + core::aabbox3d m_limits; /**< position limits in real map coordinates */ /** contains all map data already collected and analyzed. Access it via the getIndexElement/getIdxElem methods. */ @@ -354,7 +354,7 @@ class Pathfinder { * print a path * @param path path to show */ - void printPath(std::vector path); + void printPath(std::vector path); /** * print y direction for all movements @@ -388,9 +388,9 @@ class PathfinderCompareHeuristic { myPathfinder = pf; } - bool operator() (v3s16 pos1, v3s16 pos2) { - v3s16 ipos1 = myPathfinder->getIndexPos(pos1); - v3s16 ipos2 = myPathfinder->getIndexPos(pos2); + bool operator() (v3POS pos1, v3POS pos2) { + v3POS ipos1 = myPathfinder->getIndexPos(pos1); + v3POS ipos2 = myPathfinder->getIndexPos(pos2); PathGridnode &g_pos1 = myPathfinder->getIndexElement(ipos1); PathGridnode &g_pos2 = myPathfinder->getIndexElement(ipos2); if (!g_pos1.valid) @@ -405,9 +405,9 @@ class PathfinderCompareHeuristic /* implementation */ /******************************************************************************/ -std::vector get_path(Map* map, const NodeDefManager *ndef, - v3s16 source, - v3s16 destination, +std::vector get_path(Map* map, const NodeDefManager *ndef, + v3POS source, + v3POS destination, unsigned int searchdistance, unsigned int max_jump, unsigned int max_drop, @@ -476,7 +476,7 @@ PathGridnode &PathGridnode::operator= (const PathGridnode &b) } /******************************************************************************/ -PathCost PathGridnode::getCost(v3s16 dir) +PathCost PathGridnode::getCost(v3POS dir) { if (dir.X > 0) { return directions[DIR_XP]; @@ -495,7 +495,7 @@ PathCost PathGridnode::getCost(v3s16 dir) } /******************************************************************************/ -void PathGridnode::setCost(v3s16 dir, const PathCost &cost) +void PathGridnode::setCost(v3POS dir, const PathCost &cost) { if (dir.X > 0) { directions[DIR_XP] = cost; @@ -511,15 +511,15 @@ void PathGridnode::setCost(v3s16 dir, const PathCost &cost) } } -void GridNodeContainer::initNode(v3s16 ipos, PathGridnode *p_node) +void GridNodeContainer::initNode(v3POS ipos, PathGridnode *p_node) { const NodeDefManager *ndef = m_pathf->m_ndef; PathGridnode &elem = *p_node; - v3s16 realpos = m_pathf->getRealPos(ipos); + v3POS realpos = m_pathf->getRealPos(ipos); MapNode current = m_pathf->m_map->getNode(realpos); - MapNode below = m_pathf->m_map->getNode(realpos + v3s16(0, -1, 0)); + MapNode below = m_pathf->m_map->getNode(realpos + v3POS(0, -1, 0)); if ((current.param0 == CONTENT_IGNORE) || @@ -553,14 +553,14 @@ void GridNodeContainer::initNode(v3s16 ipos, PathGridnode *p_node) DEBUG_OUT(PP(ipos) << ": " << 'a' << std::endl); if (m_pathf->m_prefetch) { - elem.directions[DIR_XP] = m_pathf->calcCost(realpos, v3s16( 1, 0, 0)); - elem.directions[DIR_XM] = m_pathf->calcCost(realpos, v3s16(-1, 0, 0)); - elem.directions[DIR_ZP] = m_pathf->calcCost(realpos, v3s16( 0, 0, 1)); - elem.directions[DIR_ZM] = m_pathf->calcCost(realpos, v3s16( 0, 0,-1)); + elem.directions[DIR_XP] = m_pathf->calcCost(realpos, v3POS( 1, 0, 0)); + elem.directions[DIR_XM] = m_pathf->calcCost(realpos, v3POS(-1, 0, 0)); + elem.directions[DIR_ZP] = m_pathf->calcCost(realpos, v3POS( 0, 0, 1)); + elem.directions[DIR_ZM] = m_pathf->calcCost(realpos, v3POS( 0, 0,-1)); } } -ArrayGridNodeContainer::ArrayGridNodeContainer(Pathfinder *pathf, v3s16 dimensions) : +ArrayGridNodeContainer::ArrayGridNodeContainer(Pathfinder *pathf, v3POS dimensions) : m_x_stride(dimensions.Y * dimensions.Z), m_y_stride(dimensions.Z) { @@ -571,14 +571,14 @@ ArrayGridNodeContainer::ArrayGridNodeContainer(Pathfinder *pathf, v3s16 dimensio for (int x = 0; x < dimensions.X; x++) { for (int y = 0; y < dimensions.Y; y++) { for (int z= 0; z < dimensions.Z; z++) { - v3s16 ipos(x, y, z); + v3POS ipos(x, y, z); initNode(ipos, &access(ipos)); } } } } -PathGridnode &ArrayGridNodeContainer::access(v3s16 p) +PathGridnode &ArrayGridNodeContainer::access(v3POS p) { return m_nodes_array[p.X * m_x_stride + p.Y * m_y_stride + p.Z]; } @@ -588,9 +588,9 @@ MapGridNodeContainer::MapGridNodeContainer(Pathfinder *pathf) m_pathf = pathf; } -PathGridnode &MapGridNodeContainer::access(v3s16 p) +PathGridnode &MapGridNodeContainer::access(v3POS p) { - std::map::iterator it = m_nodes.find(p); + std::map::iterator it = m_nodes.find(p); if (it != m_nodes.end()) { return it->second; } @@ -602,8 +602,8 @@ PathGridnode &MapGridNodeContainer::access(v3s16 p) /******************************************************************************/ -std::vector Pathfinder::getPath(v3s16 source, - v3s16 destination, +std::vector Pathfinder::getPath(v3POS source, + v3POS destination, unsigned int searchdistance, unsigned int max_jump, unsigned int max_drop, @@ -613,7 +613,7 @@ std::vector Pathfinder::getPath(v3s16 source, timespec ts; clock_gettime(CLOCK_REALTIME, &ts); #endif - std::vector retval; + std::vector retval; //initialization m_maxjump = max_jump; @@ -645,7 +645,7 @@ std::vector Pathfinder::getPath(v3s16 source, m_limits.MaxEdge.Y = max_y + searchdistance; m_limits.MaxEdge.Z = max_z + searchdistance; - v3s16 diff = m_limits.MaxEdge - m_limits.MinEdge; + v3POS diff = m_limits.MaxEdge - m_limits.MinEdge; m_max_index_x = diff.X; m_max_index_y = diff.Y; @@ -681,20 +681,20 @@ std::vector Pathfinder::getPath(v3s16 source, //to the first walkable node (up to m_maxdrop). //All algorithms expect the source pos to be *directly* above //a walkable node. - v3s16 true_source = v3s16(source); + v3POS true_source = v3POS(source); source = walkDownwards(source, m_maxdrop); //If destination pos is hovering above air, go downwards //to the first walkable node (up to m_maxjump). //This means a hovering destination pos could be reached //by a final upwards jump. - v3s16 true_destination = v3s16(destination); + v3POS true_destination = v3POS(destination); destination = walkDownwards(destination, m_maxjump); //validate and mark start and end pos - v3s16 StartIndex = getIndexPos(source); - v3s16 EndIndex = getIndexPos(destination); + v3POS StartIndex = getIndexPos(source); + v3POS EndIndex = getIndexPos(destination); PathGridnode &startpos = getIndexElement(StartIndex); PathGridnode &endpos = getIndexElement(EndIndex); @@ -721,7 +721,7 @@ std::vector Pathfinder::getPath(v3s16 source, //calculate node costs switch (algo) { case PA_DIJKSTRA: - update_cost_retval = updateAllCosts(StartIndex, v3s16(0, 0, 0), 0, 0); + update_cost_retval = updateAllCosts(StartIndex, v3POS(0, 0, 0), 0, 0); break; case PA_PLAIN_NP: case PA_PLAIN: @@ -740,7 +740,7 @@ std::vector Pathfinder::getPath(v3s16 source, #endif //find path - std::vector index_path; + std::vector index_path; buildPath(index_path, EndIndex); //Now we have a path of index positions, //and it's in reverse. @@ -752,7 +752,7 @@ std::vector Pathfinder::getPath(v3s16 source, printPath(index_path); #endif //from here we'll make the final changes to the path - std::vector full_path; + std::vector full_path; //calculate required size int full_path_size = index_path.size(); @@ -770,7 +770,7 @@ std::vector Pathfinder::getPath(v3s16 source, } //convert all index positions to "normal" positions and insert //them into full_path in reverse - std::vector::reverse_iterator rit = index_path.rbegin(); + std::vector::reverse_iterator rit = index_path.rbegin(); for (; rit != index_path.rend(); ++rit) { full_path.push_back(getIndexElement(*rit).pos); } @@ -817,19 +817,19 @@ Pathfinder::~Pathfinder() delete m_nodes_container; } /******************************************************************************/ -v3s16 Pathfinder::getRealPos(v3s16 ipos) +v3POS Pathfinder::getRealPos(v3POS ipos) { return m_limits.MinEdge + ipos; } /******************************************************************************/ -PathCost Pathfinder::calcCost(v3s16 pos, v3s16 dir) +PathCost Pathfinder::calcCost(v3POS pos, v3POS dir) { PathCost retval; retval.updated = true; - v3s16 pos2 = pos + dir; + v3POS pos2 = pos + dir; //check limits if (!m_limits.isPointInside(pos2)) { @@ -849,12 +849,12 @@ PathCost Pathfinder::calcCost(v3s16 pos, v3s16 dir) if (!m_ndef->get(node_at_pos2).walkable) { MapNode node_below_pos2 = - m_map->getNode(pos2 + v3s16(0, -1, 0)); + m_map->getNode(pos2 + v3POS(0, -1, 0)); //did we get information about node? if (node_below_pos2.param0 == CONTENT_IGNORE ) { VERBOSE_TARGET << "Pathfinder: (2) area at pos: " - << PP((pos2 + v3s16(0, -1, 0))) << " not loaded"; + << PP((pos2 + v3POS(0, -1, 0))) << " not loaded"; return retval; } @@ -869,13 +869,13 @@ PathCost Pathfinder::calcCost(v3s16 pos, v3s16 dir) } else { //test if we can fall a couple of nodes (m_maxdrop) - v3s16 testpos = pos2 + v3s16(0, -1, 0); + v3POS testpos = pos2 + v3POS(0, -1, 0); MapNode node_at_pos = m_map->getNode(testpos); while ((node_at_pos.param0 != CONTENT_IGNORE) && (!m_ndef->get(node_at_pos).walkable) && (testpos.Y > m_limits.MinEdge.Y)) { - testpos += v3s16(0, -1, 0); + testpos += v3POS(0, -1, 0); node_at_pos = m_map->getNode(testpos); } @@ -906,8 +906,8 @@ PathCost Pathfinder::calcCost(v3s16 pos, v3s16 dir) else { //test if we can jump upwards (m_maxjump) - v3s16 targetpos = pos2; // position for jump target - v3s16 jumppos = pos; // position for checking if jumping space is free + v3POS targetpos = pos2; // position for jump target + v3POS jumppos = pos; // position for checking if jumping space is free MapNode node_target = m_map->getNode(targetpos); MapNode node_jump = m_map->getNode(jumppos); bool headbanger = false; // true if anything blocks jumppath @@ -921,8 +921,8 @@ PathCost Pathfinder::calcCost(v3s16 pos, v3s16 dir) headbanger = true; break; } - targetpos += v3s16(0, 1, 0); - jumppos += v3s16(0, 1, 0); + targetpos += v3POS(0, 1, 0); + jumppos += v3POS(0, 1, 0); node_target = m_map->getNode(targetpos); node_jump = m_map->getNode(jumppos); @@ -958,25 +958,25 @@ PathCost Pathfinder::calcCost(v3s16 pos, v3s16 dir) } /******************************************************************************/ -v3s16 Pathfinder::getIndexPos(v3s16 pos) +v3POS Pathfinder::getIndexPos(v3POS pos) { return pos - m_limits.MinEdge; } /******************************************************************************/ -PathGridnode &Pathfinder::getIndexElement(v3s16 ipos) +PathGridnode &Pathfinder::getIndexElement(v3POS ipos) { return m_nodes_container->access(ipos); } /******************************************************************************/ -inline PathGridnode &Pathfinder::getIdxElem(s16 x, s16 y, s16 z) +inline PathGridnode &Pathfinder::getIdxElem(POS x, POS y, POS z) { - return m_nodes_container->access(v3s16(x,y,z)); + return m_nodes_container->access(v3POS(x,y,z)); } /******************************************************************************/ -bool Pathfinder::isValidIndex(v3s16 index) +bool Pathfinder::isValidIndex(v3POS index) { if ( (index.X < m_max_index_x) && (index.Y < m_max_index_y) && @@ -990,9 +990,9 @@ bool Pathfinder::isValidIndex(v3s16 index) } /******************************************************************************/ -v3s16 Pathfinder::invert(v3s16 pos) +v3POS Pathfinder::invert(v3POS pos) { - v3s16 retval = pos; + v3POS retval = pos; retval.X *=-1; retval.Y *=-1; @@ -1002,8 +1002,8 @@ v3s16 Pathfinder::invert(v3s16 pos) } /******************************************************************************/ -bool Pathfinder::updateAllCosts(v3s16 ipos, - v3s16 srcdir, +bool Pathfinder::updateAllCosts(v3POS ipos, + v3POS srcdir, int current_cost, int level) { @@ -1023,21 +1023,21 @@ bool Pathfinder::updateAllCosts(v3s16 ipos, bool retval = false; // the 4 cardinal directions - const static v3s16 directions[4] = { - v3s16(1,0, 0), - v3s16(-1,0, 0), - v3s16(0,0, 1), - v3s16(0,0,-1) + const static v3POS directions[4] = { + v3POS(1,0, 0), + v3POS(-1,0, 0), + v3POS(0,0, 1), + v3POS(0,0,-1) }; - for (v3s16 direction : directions) { + for (v3POS direction : directions) { if (direction != srcdir) { PathCost cost = g_pos.getCost(direction); if (cost.valid) { direction.Y = cost.y_change; - v3s16 ipos2 = ipos + direction; + v3POS ipos2 = ipos + direction; if (!isValidIndex(ipos2)) { DEBUG_OUT(LVL " Pathfinder: " << PP(ipos2) << @@ -1090,7 +1090,7 @@ bool Pathfinder::updateAllCosts(v3s16 ipos, } /******************************************************************************/ -int Pathfinder::getXZManhattanDist(v3s16 pos) +int Pathfinder::getXZManhattanDist(v3POS pos) { int min_x = MYMIN(pos.X, m_destination.X); int max_x = MYMAX(pos.X, m_destination.X); @@ -1103,31 +1103,31 @@ int Pathfinder::getXZManhattanDist(v3s16 pos) /******************************************************************************/ -bool Pathfinder::updateCostHeuristic(v3s16 isource, v3s16 idestination) +bool Pathfinder::updateCostHeuristic(v3POS isource, v3POS idestination) { // A* search algorithm. // The open list contains the pathfinder nodes that still need to be // checked. The priority queue sorts the pathfinder nodes by // estimated cost, with lowest cost on the top. - std::priority_queue, PathfinderCompareHeuristic> + std::priority_queue, PathfinderCompareHeuristic> openList(PathfinderCompareHeuristic(this)); - v3s16 source = getRealPos(isource); - v3s16 destination = getRealPos(idestination); + v3POS source = getRealPos(isource); + v3POS destination = getRealPos(idestination); // initial position openList.push(source); // the 4 cardinal directions - const static v3s16 directions[4] = { - v3s16(1,0, 0), - v3s16(-1,0, 0), - v3s16(0,0, 1), - v3s16(0,0,-1) + const static v3POS directions[4] = { + v3POS(1,0, 0), + v3POS(-1,0, 0), + v3POS(0,0, 1), + v3POS(0,0,-1) }; - v3s16 current_pos; + v3POS current_pos; PathGridnode& s_pos = getIndexElement(isource); s_pos.source = true; s_pos.totalcost = 0; @@ -1141,7 +1141,7 @@ bool Pathfinder::updateCostHeuristic(v3s16 isource, v3s16 idestination) // The "cheapest" node is always on top. current_pos = openList.top(); openList.pop(); - v3s16 ipos = getIndexPos(current_pos); + v3POS ipos = getIndexPos(current_pos); // check if node is inside searchdistance and valid if (!isValidIndex(ipos)) { @@ -1164,7 +1164,7 @@ bool Pathfinder::updateCostHeuristic(v3s16 isource, v3s16 idestination) } // for this node, check the 4 cardinal directions - for (v3s16 direction_flat : directions) { + for (v3POS direction_flat : directions) { int current_totalcost = g_pos.totalcost; // get cost from current node to currently checked direction @@ -1174,12 +1174,12 @@ bool Pathfinder::updateCostHeuristic(v3s16 isource, v3s16 idestination) g_pos.setCost(direction_flat, cost); } // update Y component of direction if neighbor requires jump or fall - v3s16 direction_3d = v3s16(direction_flat); + v3POS direction_3d = v3POS(direction_flat); direction_3d.Y = cost.y_change; // get position of true neighbor - v3s16 neighbor = current_pos + direction_3d; - v3s16 ineighbor = getIndexPos(neighbor); + v3POS neighbor = current_pos + direction_3d; + v3POS ineighbor = getIndexPos(neighbor); PathGridnode &n_pos = getIndexElement(ineighbor); if (cost.valid && !n_pos.is_closed && !n_pos.is_open) { @@ -1200,7 +1200,7 @@ bool Pathfinder::updateCostHeuristic(v3s16 isource, v3s16 idestination) } /******************************************************************************/ -bool Pathfinder::buildPath(std::vector &path, v3s16 ipos) +bool Pathfinder::buildPath(std::vector &path, v3POS ipos) { // The cost calculation should have set a source direction for all relevant nodes. // To build the path, we go backwards from the destination until we reach the start. @@ -1231,17 +1231,17 @@ bool Pathfinder::buildPath(std::vector &path, v3s16 ipos) } /******************************************************************************/ -v3s16 Pathfinder::walkDownwards(v3s16 pos, unsigned int max_down) { +v3POS Pathfinder::walkDownwards(v3POS pos, unsigned int max_down) { if (max_down == 0) return pos; - v3s16 testpos = v3s16(pos); + v3POS testpos = v3POS(pos); MapNode node_at_pos = m_map->getNode(testpos); unsigned int down = 0; while ((node_at_pos.param0 != CONTENT_IGNORE) && (!m_ndef->get(node_at_pos).walkable) && (testpos.Y > m_limits.MinEdge.Y) && (down <= max_down)) { - testpos += v3s16(0, -1, 0); + testpos += v3POS(0, -1, 0); down++; node_at_pos = m_map->getNode(testpos); } @@ -1253,7 +1253,7 @@ v3s16 Pathfinder::walkDownwards(v3s16 pos, unsigned int max_down) { pos = testpos; } else if ((down - 1) <= max_down) { //difference of y-pos +1 (target node is ABOVE solid node) - testpos += v3s16(0, 1, 0); + testpos += v3POS(0, 1, 0); pos = testpos; } else { @@ -1428,10 +1428,10 @@ std::string Pathfinder::dirToName(PathDirections dir) } /******************************************************************************/ -void Pathfinder::printPath(const std::vector &path) +void Pathfinder::printPath(const std::vector &path) { unsigned int current = 0; - for (std::vector::iterator i = path.begin(); + for (std::vector::iterator i = path.begin(); i != path.end(); ++i) { std::cout << std::setw(3) << current << ":" << PP((*i)) << std::endl; current++; diff --git a/src/pathfinder.h b/src/pathfinder.h index 526aa0ee8d..cfde4f63d8 100644 --- a/src/pathfinder.h +++ b/src/pathfinder.h @@ -55,9 +55,9 @@ typedef enum { /******************************************************************************/ /** c wrapper function to use from scriptapi */ -std::vector get_path(Map *map, const NodeDefManager *ndef, - v3s16 source, - v3s16 destination, +std::vector get_path(Map *map, const NodeDefManager *ndef, + v3POS source, + v3POS destination, unsigned int searchdistance, unsigned int max_jump, unsigned int max_drop, diff --git a/src/raycast.cpp b/src/raycast.cpp index ebc40235db..4e2148bd79 100644 --- a/src/raycast.cpp +++ b/src/raycast.cpp @@ -68,7 +68,7 @@ RaycastState::RaycastState(const core::line3d &shootline, bool boxLineCollision(const aabb3f &box, const v3f &start, - const v3f &dir, v3f *collision_point, v3s16 *collision_normal) + const v3f &dir, v3f *collision_point, v3POS *collision_normal) { if (box.isPointInside(start)) { *collision_point = start; diff --git a/src/raycast.h b/src/raycast.h index 734efd6ad4..c950a2a16f 100644 --- a/src/raycast.h +++ b/src/raycast.h @@ -45,7 +45,7 @@ class RaycastState //! Iterator to store the progress of the raycast. voxalgo::VoxelLineIterator m_iterator; //! Previous tested node during the raycast. - v3s16 m_previous_node; + v3POS m_previous_node; /*! * This priority queue stores the found pointed things @@ -57,7 +57,7 @@ class RaycastState bool m_liquids_pointable; //! The code needs to search these nodes around the center node. - core::aabbox3d m_search_range { 0, 0, 0, 0, 0, 0 }; + core::aabbox3d m_search_range { 0, 0, 0, 0, 0, 0 }; //! If true, the Environment will initialize this state. bool m_initialization_needed = true; @@ -74,4 +74,4 @@ class RaycastState * @returns true if a collision point was found */ bool boxLineCollision(const aabb3f &box, const v3f &start, const v3f &dir, - v3f *collision_point, v3s16 *collision_normal); + v3f *collision_point, v3POS *collision_normal); diff --git a/src/reflowscan.cpp b/src/reflowscan.cpp index 9d5c965d8c..b76a654a90 100644 --- a/src/reflowscan.cpp +++ b/src/reflowscan.cpp @@ -30,7 +30,7 @@ ReflowScan::ReflowScan(Map *map, const NodeDefManager *ndef) : { } -void ReflowScan::scan(MapBlock *block, UniqueQueue *liquid_queue) +void ReflowScan::scan(MapBlock *block, UniqueQueue *liquid_queue) { m_block_pos = block->getPos(); m_rel_block_pos = block->getPosRelative(); @@ -75,7 +75,7 @@ inline MapBlock *ReflowScan::lookupBlock(int x, int y, int z) if (!result && (m_lookup_state_bitset & (1 << idx)) == 0) { // The block wasn't requested yet so fetch it from Map and store it // in the lookup - v3s16 pos = m_block_pos + v3s16(bx - 1, by - 1, bz - 1); + v3POS pos = m_block_pos + v3POS(bx - 1, by - 1, bz - 1); m_lookup[idx] = result = m_map->getBlockNoCreateNoEx(pos); m_lookup_state_bitset |= (1 << idx); } @@ -155,7 +155,7 @@ void ReflowScan::scanColumn(int x, int z) bool is_pushed = false; if (f.liquid_type == LIQUID_FLOWING || isLiquidHorizontallyFlowable(x, y, z)) { - m_liquid_queue->push_back(m_rel_block_pos + v3s16(x, y, z)); + m_liquid_queue->push_back(m_rel_block_pos + v3POS(x, y, z)); is_pushed = true; } // Remember waschecked and waspushed to avoid repeated @@ -168,7 +168,7 @@ void ReflowScan::scanColumn(int x, int z) (!was_checked && isLiquidHorizontallyFlowable(x, y + 1, z)))) { // Activate the lowest node in the column which is one // node above this one - m_liquid_queue->push_back(m_rel_block_pos + v3s16(x, y + 1, z)); + m_liquid_queue->push_back(m_rel_block_pos + v3POS(x, y + 1, z)); } } @@ -190,7 +190,7 @@ void ReflowScan::scanColumn(int x, int z) // This is the topmost node in the column and might want to flow away if (f.liquid_type == LIQUID_FLOWING || isLiquidHorizontallyFlowable(x, -1, z)) { - m_liquid_queue->push_back(m_rel_block_pos + v3s16(x, -1, z)); + m_liquid_queue->push_back(m_rel_block_pos + v3POS(x, -1, z)); } } else { // This is the topmost node below a liquid column @@ -198,7 +198,7 @@ void ReflowScan::scanColumn(int x, int z) (!was_checked && isLiquidHorizontallyFlowable(x, 0, z)))) { // Activate the lowest node in the column which is one // node above this one - m_liquid_queue->push_back(m_rel_block_pos + v3s16(x, 0, z)); + m_liquid_queue->push_back(m_rel_block_pos + v3POS(x, 0, z)); } } } diff --git a/src/reflowscan.h b/src/reflowscan.h index 7961432bd4..21ab82099d 100644 --- a/src/reflowscan.h +++ b/src/reflowscan.h @@ -29,7 +29,7 @@ class MapBlock; class ReflowScan { public: ReflowScan(Map *map, const NodeDefManager *ndef); - void scan(MapBlock *block, UniqueQueue *liquid_queue); + void scan(MapBlock *block, UniqueQueue *liquid_queue); private: MapBlock *lookupBlock(int x, int y, int z); @@ -40,8 +40,8 @@ class ReflowScan { private: Map *m_map = nullptr; const NodeDefManager *m_ndef = nullptr; - v3s16 m_block_pos, m_rel_block_pos; - UniqueQueue *m_liquid_queue = nullptr; + v3POS m_block_pos, m_rel_block_pos; + UniqueQueue *m_liquid_queue = nullptr; MapBlock *m_lookup[3 * 3 * 3]; u32 m_lookup_state_bitset; }; diff --git a/src/rollback.cpp b/src/rollback.cpp index 33b7958b9a..c0851b58b8 100644 --- a/src/rollback.cpp +++ b/src/rollback.cpp @@ -596,7 +596,7 @@ const std::list RollbackManager::rollbackActionsFromActionRows( break; case RollbackAction::TYPE_SET_NODE: - action.p = v3s16(row.x, row.y, row.z); + action.p = v3POS(row.x, row.y, row.z); action.n_old.name = getNodeName(row.oldNode); action.n_old.param1 = row.oldParam1; action.n_old.param2 = row.oldParam2; @@ -636,7 +636,7 @@ const std::list RollbackManager::getRowsSince(time_t firstTime, const const std::list RollbackManager::getRowsSince_range( - time_t start_time, v3s16 p, int range, int limit) + time_t start_time, v3POS p, int range, int limit) { sqlite3_bind_int64(stmt_select_range, 1, start_time); @@ -656,7 +656,7 @@ const std::list RollbackManager::getRowsSince_range( const std::list RollbackManager::getActionsSince_range( - time_t start_time, v3s16 p, int range, int limit) + time_t start_time, v3POS p, int range, int limit) { return rollbackActionsFromActionRows(getRowsSince_range(start_time, p, range, limit)); } @@ -794,8 +794,8 @@ void RollbackManager::migrate(const std::string & file_path) // Get nearness factor for subject's action for this action // Return value: 0 = impossible, >0 = factor -float RollbackManager::getSuspectNearness(bool is_guess, v3s16 suspect_p, - time_t suspect_t, v3s16 action_p, time_t action_t) +float RollbackManager::getSuspectNearness(bool is_guess, v3POS suspect_p, + time_t suspect_t, v3POS action_p, time_t action_t) { // Suspect cannot cause things in the past if (action_t < suspect_t) { @@ -834,7 +834,7 @@ void RollbackManager::reportAction(const RollbackAction &action_) action.actor_is_guess = current_actor_is_guess; if (action.actor.empty()) { // If actor is not known, find out suspect or cancel - v3s16 p; + v3POS p; if (!action.getPosition(&p)) { return; } @@ -866,7 +866,7 @@ void RollbackManager::setActor(const std::string & actor, bool is_guess) current_actor_is_guess = is_guess; } -std::string RollbackManager::getSuspect(v3s16 p, float nearness_shortcut, +std::string RollbackManager::getSuspect(v3POS p, float nearness_shortcut, float min_nearness) { if (!current_actor.empty()) { @@ -886,7 +886,7 @@ std::string RollbackManager::getSuspect(v3s16 p, float nearness_shortcut, continue; } // Find position of suspect or continue - v3s16 suspect_p; + v3POS suspect_p; if (!i->getPosition(&suspect_p)) { continue; } @@ -941,7 +941,7 @@ void RollbackManager::addAction(const RollbackAction & action) } } -std::list RollbackManager::getNodeActors(v3s16 pos, int range, +std::list RollbackManager::getNodeActors(v3POS pos, int range, time_t seconds, int limit) { flush(); diff --git a/src/rollback.h b/src/rollback.h index ff96e513f5..5b7646c665 100644 --- a/src/rollback.h +++ b/src/rollback.h @@ -41,12 +41,12 @@ class RollbackManager: public IRollbackManager std::string getActor(); bool isActorGuess(); void setActor(const std::string & actor, bool is_guess); - std::string getSuspect(v3s16 p, float nearness_shortcut, + std::string getSuspect(v3POS p, float nearness_shortcut, float min_nearness); void flush(); void addAction(const RollbackAction & action); - std::list getNodeActors(v3s16 pos, int range, + std::list getNodeActors(v3POS pos, int range, time_t seconds, int limit); std::list getRevertActions( const std::string & actor_filter, time_t seconds); @@ -67,15 +67,15 @@ class RollbackManager: public IRollbackManager const std::list & rows); const std::list getRowsSince(time_t firstTime, const std::string & actor); - const std::list getRowsSince_range(time_t firstTime, v3s16 p, + const std::list getRowsSince_range(time_t firstTime, v3POS p, int range, int limit); - const std::list getActionsSince_range(time_t firstTime, v3s16 p, + const std::list getActionsSince_range(time_t firstTime, v3POS p, int range, int limit); const std::list getActionsSince(time_t firstTime, const std::string & actor = ""); void migrate(const std::string & filepath); - static float getSuspectNearness(bool is_guess, v3s16 suspect_p, - time_t suspect_t, v3s16 action_p, time_t action_t); + static float getSuspectNearness(bool is_guess, v3POS suspect_p, + time_t suspect_t, v3POS action_p, time_t action_t); IGameDef *gamedef = nullptr; diff --git a/src/rollback_interface.cpp b/src/rollback_interface.cpp index c00206e984..9cdf5b40b5 100644 --- a/src/rollback_interface.cpp +++ b/src/rollback_interface.cpp @@ -34,7 +34,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "mapblock.h" -RollbackNode::RollbackNode(Map *map, v3s16 p, IGameDef *gamedef) +RollbackNode::RollbackNode(Map *map, v3POS p, IGameDef *gamedef) { const NodeDefManager *ndef = gamedef->ndef(); MapNode n = map->getNode(p); @@ -101,7 +101,7 @@ bool RollbackAction::isImportant(IGameDef *gamedef) const } -bool RollbackAction::getPosition(v3s16 *dst) const +bool RollbackAction::getPosition(v3POS *dst) const { switch (type) { case TYPE_SET_NODE: diff --git a/src/rollback_interface.h b/src/rollback_interface.h index 94b800579c..e8c6134778 100644 --- a/src/rollback_interface.h +++ b/src/rollback_interface.h @@ -47,7 +47,7 @@ struct RollbackNode RollbackNode() = default; - RollbackNode(Map *map, v3s16 p, IGameDef *gamedef); + RollbackNode(Map *map, v3POS p, IGameDef *gamedef); }; @@ -63,7 +63,7 @@ struct RollbackAction std::string actor; bool actor_is_guess = false; - v3s16 p; + v3POS p; RollbackNode n_old; RollbackNode n_new; @@ -75,7 +75,7 @@ struct RollbackAction RollbackAction() = default; - void setSetNode(v3s16 p_, const RollbackNode &n_old_, + void setSetNode(v3POS p_, const RollbackNode &n_old_, const RollbackNode &n_new_) { type = TYPE_SET_NODE; @@ -102,7 +102,7 @@ struct RollbackAction // Eg. flowing water level changes are not important bool isImportant(IGameDef *gamedef) const; - bool getPosition(v3s16 *dst) const; + bool getPosition(v3POS *dst) const; bool applyRevert(Map *map, InventoryManager *imgr, IGameDef *gamedef) const; }; @@ -115,14 +115,14 @@ class IRollbackManager virtual std::string getActor() = 0; virtual bool isActorGuess() = 0; virtual void setActor(const std::string &actor, bool is_guess) = 0; - virtual std::string getSuspect(v3s16 p, float nearness_shortcut, + virtual std::string getSuspect(v3POS p, float nearness_shortcut, float min_nearness) = 0; virtual ~IRollbackManager() = default;; virtual void flush() = 0; // Get all actors that did something to position p, but not further than // in history - virtual std::list getNodeActors(v3s16 pos, int range, + virtual std::list getNodeActors(v3POS pos, int range, time_t seconds, int limit) = 0; // Get actions to revert of history made by virtual std::list getRevertActions(const std::string &actor, diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp index 8a5a3fe711..015279efc8 100644 --- a/src/script/common/c_content.cpp +++ b/src/script/common/c_content.cpp @@ -1861,9 +1861,9 @@ void push_pointed_thing(lua_State *L, const PointedThing &pointed, bool csm, if (pointed.type == POINTEDTHING_NODE) { lua_pushstring(L, "node"); lua_setfield(L, -2, "type"); - push_v3s16(L, pointed.node_undersurface); + push_v3POS(L, pointed.node_undersurface); lua_setfield(L, -2, "under"); - push_v3s16(L, pointed.node_abovesurface); + push_v3POS(L, pointed.node_abovesurface); lua_setfield(L, -2, "above"); } else if (pointed.type == POINTEDTHING_OBJECT) { lua_pushstring(L, "object"); @@ -1883,7 +1883,7 @@ void push_pointed_thing(lua_State *L, const PointedThing &pointed, bool csm, if (hitpoint && (pointed.type != POINTEDTHING_NOTHING)) { push_v3f(L, pointed.intersection_point / BS); // convert to node coords lua_setfield(L, -2, "intersection_point"); - push_v3s16(L, pointed.intersection_normal); + push_v3POS(L, pointed.intersection_normal); lua_setfield(L, -2, "intersection_normal"); lua_pushinteger(L, pointed.box_id + 1); // change to Lua array index lua_setfield(L, -2, "box_id"); @@ -2123,7 +2123,7 @@ void push_collision_move_result(lua_State *L, const collisionMoveResult &res) lua_setfield(L, -2, "axis"); if (c.type == COLLISION_NODE) { - push_v3s16(L, c.node_p); + push_v3POS(L, c.node_p); lua_setfield(L, -2, "node_pos"); } else if (c.type == COLLISION_OBJECT) { push_objectRef(L, c.object->getId()); diff --git a/src/script/common/c_converter.cpp b/src/script/common/c_converter.cpp index 19734b913b..3337074b7c 100644 --- a/src/script/common/c_converter.cpp +++ b/src/script/common/c_converter.cpp @@ -305,6 +305,18 @@ void push_v3s16(lua_State *L, v3s16 p) set_vector_metatable(L); } +void push_v3s32(lua_State *L, v3s32 p) +{ + lua_createtable(L, 0, 3); + lua_pushinteger(L, p.X); + lua_setfield(L, -2, "x"); + lua_pushinteger(L, p.Y); + lua_setfield(L, -2, "y"); + lua_pushinteger(L, p.Z); + lua_setfield(L, -2, "z"); + set_vector_metatable(L); +} + v3s16 read_v3s16(lua_State *L, int index) { // Correct rounding at <0 @@ -312,6 +324,13 @@ v3s16 read_v3s16(lua_State *L, int index) return doubleToInt(pf, 1.0); } +v3POS read_v3POS(lua_State *L, int index) +{ + // Correct rounding at <0 + v3d pf = read_v3d(L, index); + return doubleToPos(pf, 1.0); +} + v3s16 check_v3s16(lua_State *L, int index) { // Correct rounding at <0 @@ -319,6 +338,13 @@ v3s16 check_v3s16(lua_State *L, int index) return doubleToInt(pf, 1.0); } +v3POS check_v3POS(lua_State *L, int index) +{ + // Correct rounding at <0 + v3d pf = check_v3d(L, index); + return doubleToPos(pf, 1.0); +} + bool read_color(lua_State *L, int index, video::SColor *color) { if (lua_istable(L, index)) { @@ -617,6 +643,13 @@ v3s16 getv3s16field_default(lua_State *L, int table, return default_; } +v3POS getv3POSfield_default(lua_State *L, int table, + const char *fieldname, v3POS default_) +{ + getv3intfield(L, table, fieldname, default_); + return default_; +} + void setstringfield(lua_State *L, int table, const char *fieldname, const std::string &value) { diff --git a/src/script/common/c_converter.h b/src/script/common/c_converter.h index 6ad6f32121..c4b82bd2d3 100644 --- a/src/script/common/c_converter.h +++ b/src/script/common/c_converter.h @@ -78,6 +78,8 @@ bool getv3intfield(lua_State *L, int index, v3s16 getv3s16field_default(lua_State *L, int table, const char *fieldname, v3s16 default_); +v3POS getv3POSfield_default(lua_State *L, int table, + const char *fieldname, v3POS default_); bool getstringfield(lua_State *L, int table, const char *fieldname, std::string &result); size_t getstringlistfield(lua_State *L, int table, @@ -102,11 +104,20 @@ void setboolfield(lua_State *L, int table, v3f checkFloatPos (lua_State *L, int index); v3f check_v3f (lua_State *L, int index); v3s16 check_v3s16 (lua_State *L, int index); +v3POS check_v3POS (lua_State *L, int index); v3f read_v3f (lua_State *L, int index); v2f read_v2f (lua_State *L, int index); v2s16 read_v2s16 (lua_State *L, int index); v2s32 read_v2s32 (lua_State *L, int index); +inline v2POS read_v2POS (lua_State *L, int index) { + #if USE_POS32 + return read_v2s32(L, index); + #else + return read_v2s16(L, index); + #endif +} + video::SColor read_ARGB8 (lua_State *L, int index); bool read_color (lua_State *L, int index, video::SColor *color); @@ -114,6 +125,9 @@ bool is_color_table (lua_State *L, int index); aabb3f read_aabb3f (lua_State *L, int index, f32 scale); v3s16 read_v3s16 (lua_State *L, int index); +v3s32 read_v3s32 (lua_State *L, int index); +v3POS read_v3POS (lua_State *L, int index); + std::vector read_aabb3f_vector (lua_State *L, int index, f32 scale); size_t read_stringlist (lua_State *L, int index, std::vector *result); @@ -123,7 +137,23 @@ void push_v3_float_string(lua_State *L, v3f p); void push_v2_float_string(lua_State *L, v2f p); void push_v2s16 (lua_State *L, v2s16 p); void push_v2s32 (lua_State *L, v2s32 p); +inline void push_v2POS (lua_State *L, v2POS p) { + #if USE_POS32 + return push_v2s32(L, p); + #else + return push_v2s16(L, p); + #endif +} + void push_v3s16 (lua_State *L, v3s16 p); +void push_v3s32 (lua_State *L, v3s32 p); +inline void push_v3POS (lua_State *L, v3POS p) { + #if USE_POS32 + return push_v3s32(L, p); + #else + return push_v3s16(L, p); + #endif +} void push_aabb3f (lua_State *L, aabb3f box); void push_ARGB8 (lua_State *L, video::SColor color); void pushFloatPos (lua_State *L, v3f p); diff --git a/src/script/cpp_api/s_client.cpp b/src/script/cpp_api/s_client.cpp index c889fffa08..327aafbab4 100644 --- a/src/script/cpp_api/s_client.cpp +++ b/src/script/cpp_api/s_client.cpp @@ -182,7 +182,7 @@ void ScriptApiClient::on_formspec_input(const std::string &formname, } } -bool ScriptApiClient::on_dignode(v3s16 p, MapNode node) +bool ScriptApiClient::on_dignode(v3POS p, MapNode node) { SCRIPTAPI_PRECHECKHEADER @@ -193,7 +193,7 @@ bool ScriptApiClient::on_dignode(v3s16 p, MapNode node) lua_getfield(L, -1, "registered_on_dignode"); // Push data - push_v3s16(L, p); + push_v3POS(L, p); pushnode(L, node, ndef); // Call functions @@ -206,7 +206,7 @@ bool ScriptApiClient::on_dignode(v3s16 p, MapNode node) return lua_toboolean(L, -1); } -bool ScriptApiClient::on_punchnode(v3s16 p, MapNode node) +bool ScriptApiClient::on_punchnode(v3POS p, MapNode node) { SCRIPTAPI_PRECHECKHEADER @@ -217,7 +217,7 @@ bool ScriptApiClient::on_punchnode(v3s16 p, MapNode node) lua_getfield(L, -1, "registered_on_punchnode"); // Push data - push_v3s16(L, p); + push_v3POS(L, p); pushnode(L, node, ndef); // Call functions diff --git a/src/script/cpp_api/s_client.h b/src/script/cpp_api/s_client.h index 93fe96791c..edc240271f 100644 --- a/src/script/cpp_api/s_client.h +++ b/src/script/cpp_api/s_client.h @@ -53,8 +53,8 @@ class ScriptApiClient : virtual public ScriptApiBase void environment_step(float dtime); void on_formspec_input(const std::string &formname, const StringMap &fields); - bool on_dignode(v3s16 p, MapNode node); - bool on_punchnode(v3s16 p, MapNode node); + bool on_dignode(v3POS p, MapNode node); + bool on_punchnode(v3POS p, MapNode node); bool on_placenode(const PointedThing &pointed, const ItemDefinition &item); bool on_item_use(const ItemStack &item, const PointedThing &pointed); diff --git a/src/script/cpp_api/s_env.cpp b/src/script/cpp_api/s_env.cpp index 874c37b6eb..5631cdd0a0 100644 --- a/src/script/cpp_api/s_env.cpp +++ b/src/script/cpp_api/s_env.cpp @@ -28,7 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "script/common/c_content.h" -void ScriptApiEnv::environment_OnGenerated(v3s16 minp, v3s16 maxp, +void ScriptApiEnv::environment_OnGenerated(v3POS minp, v3POS maxp, u32 blockseed) { SCRIPTAPI_PRECHECKHEADER @@ -37,8 +37,8 @@ void ScriptApiEnv::environment_OnGenerated(v3s16 minp, v3s16 maxp, lua_getglobal(L, "core"); lua_getfield(L, -1, "registered_on_generateds"); // Call callbacks - push_v3s16(L, minp); - push_v3s16(L, maxp); + push_v3POS(L, minp); + push_v3POS(L, maxp); lua_pushnumber(L, blockseed); runCallbacks(3, RUN_CALLBACKS_MODE_FIRST); } @@ -141,10 +141,10 @@ void ScriptApiEnv::initializeEnvironment(ServerEnvironment *env) bool simple_catch_up = true; getboolfield(L, current_abm, "catch_up", simple_catch_up); - s16 min_y = INT16_MIN; + POS min_y = INT16_MIN; getintfield(L, current_abm, "min_y", min_y); - s16 max_y = INT16_MAX; + POS max_y = INT16_MAX; getintfield(L, current_abm, "max_y", max_y); lua_getfield(L, current_abm, "action"); @@ -216,7 +216,7 @@ void ScriptApiEnv::initializeEnvironment(ServerEnvironment *env) } void ScriptApiEnv::on_emerge_area_completion( - v3s16 blockpos, int action, ScriptCallbackState *state) + v3POS blockpos, int action, ScriptCallbackState *state) { Server *server = getServer(); @@ -235,7 +235,7 @@ void ScriptApiEnv::on_emerge_area_completion( lua_rawgeti(L, LUA_REGISTRYINDEX, state->callback_ref); luaL_checktype(L, -1, LUA_TFUNCTION); - push_v3s16(L, blockpos); + push_v3POS(L, blockpos); lua_pushinteger(L, action); lua_pushinteger(L, state->refcount); lua_rawgeti(L, LUA_REGISTRYINDEX, state->args_ref); @@ -258,7 +258,7 @@ void ScriptApiEnv::on_emerge_area_completion( } void ScriptApiEnv::on_liquid_transformed( - const std::vector> &list) + const std::vector> &list) { SCRIPTAPI_PRECHECKHEADER @@ -277,9 +277,9 @@ void ScriptApiEnv::on_liquid_transformed( const NodeDefManager *ndef = getEnv()->getGameDef()->ndef(); lua_createtable(L, list.size(), 0); lua_createtable(L, list.size(), 0); - for(std::pair p : list) { + for(std::pair p : list) { lua_pushnumber(L, index); - push_v3s16(L, p.first); + push_v3POS(L, p.first); lua_rawset(L, -4); lua_pushnumber(L, index++); pushnode(L, p.second, ndef); diff --git a/src/script/cpp_api/s_env.h b/src/script/cpp_api/s_env.h index 090858f172..620ea6a698 100644 --- a/src/script/cpp_api/s_env.h +++ b/src/script/cpp_api/s_env.h @@ -34,17 +34,17 @@ class ScriptApiEnv : virtual public ScriptApiBase void environment_Step(float dtime); // Called after generating a piece of map - void environment_OnGenerated(v3s16 minp, v3s16 maxp, u32 blockseed); + void environment_OnGenerated(v3POS minp, v3POS maxp, u32 blockseed); // Called on player event void player_event(ServerActiveObject *player, const std::string &type); // Called after emerge of a block queued from core.emerge_area() - void on_emerge_area_completion(v3s16 blockpos, int action, + void on_emerge_area_completion(v3POS blockpos, int action, ScriptCallbackState *state); // Called after liquid transform changes - void on_liquid_transformed(const std::vector> &list); + void on_liquid_transformed(const std::vector> &list); void initializeEnvironment(ServerEnvironment *env); }; diff --git a/src/script/cpp_api/s_item.cpp b/src/script/cpp_api/s_item.cpp index b1916070e5..26e34f3986 100644 --- a/src/script/cpp_api/s_item.cpp +++ b/src/script/cpp_api/s_item.cpp @@ -223,7 +223,7 @@ bool ScriptApiItem::item_CraftPredict(ItemStack &item, ServerActiveObject *user, // If core.registered_items[name] doesn't exist, core.nodedef_default // is tried instead so unknown items can still be manipulated to some degree bool ScriptApiItem::getItemCallback(const char *name, const char *callbackname, - const v3s16 *p) + const v3POS *p) { lua_State* L = getStack(); diff --git a/src/script/cpp_api/s_item.h b/src/script/cpp_api/s_item.h index 5015d8bd45..e929dce5bb 100644 --- a/src/script/cpp_api/s_item.h +++ b/src/script/cpp_api/s_item.h @@ -60,7 +60,7 @@ class ScriptApiItem friend class LuaItemStack; friend class ModApiItemMod; - bool getItemCallback(const char *name, const char *callbackname, const v3s16 *p = nullptr); + bool getItemCallback(const char *name, const char *callbackname, const v3POS *p = nullptr); /*! * Pushes a `pointed_thing` tabe to the stack. * \param hitpoint If true, the exact pointing location is also pushed diff --git a/src/script/cpp_api/s_node.cpp b/src/script/cpp_api/s_node.cpp index 029cb6308c..a16caba999 100644 --- a/src/script/cpp_api/s_node.cpp +++ b/src/script/cpp_api/s_node.cpp @@ -102,7 +102,7 @@ struct EnumString ScriptApiNode::es_TextureAlphaMode[] = {0, NULL}, }; -bool ScriptApiNode::node_on_punch(v3s16 p, MapNode node, +bool ScriptApiNode::node_on_punch(v3POS p, MapNode node, ServerActiveObject *puncher, const PointedThing &pointed) { SCRIPTAPI_PRECHECKHEADER @@ -116,7 +116,7 @@ bool ScriptApiNode::node_on_punch(v3s16 p, MapNode node, return false; // Call function - push_v3s16(L, p); + push_v3POS(L, p); pushnode(L, node, ndef); objectrefGetOrCreate(L, puncher); pushPointedThing(pointed); @@ -125,7 +125,7 @@ bool ScriptApiNode::node_on_punch(v3s16 p, MapNode node, return true; } -bool ScriptApiNode::node_on_dig(v3s16 p, MapNode node, +bool ScriptApiNode::node_on_dig(v3POS p, MapNode node, ServerActiveObject *digger) { SCRIPTAPI_PRECHECKHEADER @@ -139,7 +139,7 @@ bool ScriptApiNode::node_on_dig(v3s16 p, MapNode node, return false; // Call function - push_v3s16(L, p); + push_v3POS(L, p); pushnode(L, node, ndef); objectrefGetOrCreate(L, digger); PCALL_RES(lua_pcall(L, 3, 1, error_handler)); @@ -152,7 +152,7 @@ bool ScriptApiNode::node_on_dig(v3s16 p, MapNode node, return result; } -void ScriptApiNode::node_on_construct(v3s16 p, MapNode node) +void ScriptApiNode::node_on_construct(v3POS p, MapNode node) { SCRIPTAPI_PRECHECKHEADER @@ -165,12 +165,12 @@ void ScriptApiNode::node_on_construct(v3s16 p, MapNode node) return; // Call function - push_v3s16(L, p); + push_v3POS(L, p); PCALL_RES(lua_pcall(L, 1, 0, error_handler)); lua_pop(L, 1); // Pop error handler } -void ScriptApiNode::node_on_destruct(v3s16 p, MapNode node) +void ScriptApiNode::node_on_destruct(v3POS p, MapNode node) { SCRIPTAPI_PRECHECKHEADER @@ -183,12 +183,12 @@ void ScriptApiNode::node_on_destruct(v3s16 p, MapNode node) return; // Call function - push_v3s16(L, p); + push_v3POS(L, p); PCALL_RES(lua_pcall(L, 1, 0, error_handler)); lua_pop(L, 1); // Pop error handler } -bool ScriptApiNode::node_on_flood(v3s16 p, MapNode node, MapNode newnode) +bool ScriptApiNode::node_on_flood(v3POS p, MapNode node, MapNode newnode) { SCRIPTAPI_PRECHECKHEADER @@ -201,7 +201,7 @@ bool ScriptApiNode::node_on_flood(v3s16 p, MapNode node, MapNode newnode) return false; // Call function - push_v3s16(L, p); + push_v3POS(L, p); pushnode(L, node, ndef); pushnode(L, newnode, ndef); PCALL_RES(lua_pcall(L, 3, 1, error_handler)); @@ -209,7 +209,7 @@ bool ScriptApiNode::node_on_flood(v3s16 p, MapNode node, MapNode newnode) return readParam(L, -1, false); } -void ScriptApiNode::node_after_destruct(v3s16 p, MapNode node) +void ScriptApiNode::node_after_destruct(v3POS p, MapNode node) { SCRIPTAPI_PRECHECKHEADER @@ -222,13 +222,13 @@ void ScriptApiNode::node_after_destruct(v3s16 p, MapNode node) return; // Call function - push_v3s16(L, p); + push_v3POS(L, p); pushnode(L, node, ndef); PCALL_RES(lua_pcall(L, 2, 0, error_handler)); lua_pop(L, 1); // Pop error handler } -bool ScriptApiNode::node_on_timer(v3s16 p, MapNode node, f32 dtime) +bool ScriptApiNode::node_on_timer(v3POS p, MapNode node, f32 dtime) { SCRIPTAPI_PRECHECKHEADER @@ -241,14 +241,14 @@ bool ScriptApiNode::node_on_timer(v3s16 p, MapNode node, f32 dtime) return false; // Call function - push_v3s16(L, p); + push_v3POS(L, p); lua_pushnumber(L,dtime); PCALL_RES(lua_pcall(L, 2, 1, error_handler)); lua_remove(L, error_handler); return readParam(L, -1, false); } -void ScriptApiNode::node_on_receive_fields(v3s16 p, +void ScriptApiNode::node_on_receive_fields(v3POS p, const std::string &formname, const StringMap &fields, ServerActiveObject *sender) @@ -269,7 +269,7 @@ void ScriptApiNode::node_on_receive_fields(v3s16 p, return; // Call function - push_v3s16(L, p); // pos + push_v3POS(L, p); // pos lua_pushstring(L, formname.c_str()); // formname lua_newtable(L); // fields StringMap::const_iterator it; diff --git a/src/script/cpp_api/s_node.h b/src/script/cpp_api/s_node.h index 3c6a8445b2..73ac39263c 100644 --- a/src/script/cpp_api/s_node.h +++ b/src/script/cpp_api/s_node.h @@ -35,16 +35,16 @@ class ScriptApiNode ScriptApiNode() = default; virtual ~ScriptApiNode() = default; - bool node_on_punch(v3s16 p, MapNode node, + bool node_on_punch(v3POS p, MapNode node, ServerActiveObject *puncher, const PointedThing &pointed); - bool node_on_dig(v3s16 p, MapNode node, + bool node_on_dig(v3POS p, MapNode node, ServerActiveObject *digger); - void node_on_construct(v3s16 p, MapNode node); - void node_on_destruct(v3s16 p, MapNode node); - bool node_on_flood(v3s16 p, MapNode node, MapNode newnode); - void node_after_destruct(v3s16 p, MapNode node); - bool node_on_timer(v3s16 p, MapNode node, f32 dtime); - void node_on_receive_fields(v3s16 p, + void node_on_construct(v3POS p, MapNode node); + void node_on_destruct(v3POS p, MapNode node); + bool node_on_flood(v3POS p, MapNode node, MapNode newnode); + void node_after_destruct(v3POS p, MapNode node); + bool node_on_timer(v3POS p, MapNode node, f32 dtime); + void node_on_receive_fields(v3POS p, const std::string &formname, const StringMap &fields, ServerActiveObject *sender); diff --git a/src/script/cpp_api/s_nodemeta.cpp b/src/script/cpp_api/s_nodemeta.cpp index 7ab3757f3d..5d06af9701 100644 --- a/src/script/cpp_api/s_nodemeta.cpp +++ b/src/script/cpp_api/s_nodemeta.cpp @@ -48,7 +48,7 @@ int ScriptApiNodemeta::nodemeta_inventory_AllowMove( return count; // function(pos, from_list, from_index, to_list, to_index, count, player) - push_v3s16(L, ma.to_inv.p); // pos + push_v3POS(L, ma.to_inv.p); // pos lua_pushstring(L, ma.from_list.c_str()); // from_list lua_pushinteger(L, ma.from_i + 1); // from_index lua_pushstring(L, ma.to_list.c_str()); // to_list @@ -86,7 +86,7 @@ int ScriptApiNodemeta::nodemeta_inventory_AllowPut( return stack.count; // Call function(pos, listname, index, stack, player) - push_v3s16(L, ma.to_inv.p); // pos + push_v3POS(L, ma.to_inv.p); // pos lua_pushstring(L, ma.to_list.c_str()); // listname lua_pushinteger(L, ma.to_i + 1); // index LuaItemStack::create(L, stack); // stack @@ -122,7 +122,7 @@ int ScriptApiNodemeta::nodemeta_inventory_AllowTake( return stack.count; // Call function(pos, listname, index, count, player) - push_v3s16(L, ma.from_inv.p); // pos + push_v3POS(L, ma.from_inv.p); // pos lua_pushstring(L, ma.from_list.c_str()); // listname lua_pushinteger(L, ma.from_i + 1); // index LuaItemStack::create(L, stack); // stack @@ -158,7 +158,7 @@ void ScriptApiNodemeta::nodemeta_inventory_OnMove( return; // function(pos, from_list, from_index, to_list, to_index, count, player) - push_v3s16(L, ma.from_inv.p); // pos + push_v3POS(L, ma.from_inv.p); // pos lua_pushstring(L, ma.from_list.c_str()); // from_list lua_pushinteger(L, ma.from_i + 1); // from_index lua_pushstring(L, ma.to_list.c_str()); // to_list @@ -191,7 +191,7 @@ void ScriptApiNodemeta::nodemeta_inventory_OnPut( return; // Call function(pos, listname, index, stack, player) - push_v3s16(L, ma.to_inv.p); // pos + push_v3POS(L, ma.to_inv.p); // pos lua_pushstring(L, ma.to_list.c_str()); // listname lua_pushinteger(L, ma.to_i + 1); // index LuaItemStack::create(L, stack); // stack @@ -222,7 +222,7 @@ void ScriptApiNodemeta::nodemeta_inventory_OnTake( return; // Call function(pos, listname, index, stack, player) - push_v3s16(L, ma.from_inv.p); // pos + push_v3POS(L, ma.from_inv.p); // pos lua_pushstring(L, ma.from_list.c_str()); // listname lua_pushinteger(L, ma.from_i + 1); // index LuaItemStack::create(L, stack); // stack diff --git a/src/script/lua_api/l_areastore.cpp b/src/script/lua_api/l_areastore.cpp index 45724e604a..ddb023e775 100644 --- a/src/script/lua_api/l_areastore.cpp +++ b/src/script/lua_api/l_areastore.cpp @@ -47,9 +47,9 @@ static void push_area(lua_State *L, const Area *a, } lua_newtable(L); if (include_borders) { - push_v3s16(L, a->minedge); + push_v3POS(L, a->minedge); lua_setfield(L, -2, "min"); - push_v3s16(L, a->maxedge); + push_v3POS(L, a->maxedge); lua_setfield(L, -2, "max"); } if (include_data) { @@ -127,7 +127,7 @@ int LuaAreaStore::l_get_areas_for_pos(lua_State *L) LuaAreaStore *o = checkobject(L, 1); AreaStore *ast = o->as; - v3s16 pos = check_v3s16(L, 2); + v3POS pos = check_v3POS(L, 2); bool include_borders = true; bool include_data = false; @@ -149,8 +149,8 @@ int LuaAreaStore::l_get_areas_in_area(lua_State *L) LuaAreaStore *o = checkobject(L, 1); AreaStore *ast = o->as; - v3s16 minedge = check_v3s16(L, 2); - v3s16 maxedge = check_v3s16(L, 3); + v3POS minedge = check_v3POS(L, 2); + v3POS maxedge = check_v3POS(L, 3); bool include_borders = true; bool include_data = false; @@ -175,7 +175,7 @@ int LuaAreaStore::l_insert_area(lua_State *L) LuaAreaStore *o = checkobject(L, 1); AreaStore *ast = o->as; - Area a(check_v3s16(L, 2), check_v3s16(L, 3)); + Area a(check_v3POS(L, 2), check_v3POS(L, 3)); size_t d_len; const char *data = luaL_checklstring(L, 4, &d_len); diff --git a/src/script/lua_api/l_client.cpp b/src/script/lua_api/l_client.cpp index aaced7cd0a..eb828f5136 100644 --- a/src/script/lua_api/l_client.cpp +++ b/src/script/lua_api/l_client.cpp @@ -213,7 +213,7 @@ int ModApiClient::l_gettext(lua_State *L) int ModApiClient::l_get_node_or_nil(lua_State *L) { // pos - v3s16 pos = read_v3s16(L, 1); + v3POS pos = read_v3POS(L, 1); // Do it bool pos_ok; @@ -247,7 +247,7 @@ int ModApiClient::l_get_language(lua_State *L) // get_meta(pos) int ModApiClient::l_get_meta(lua_State *L) { - v3s16 p = read_v3s16(L, 1); + v3POS p = read_v3POS(L, 1); // check restrictions first bool pos_ok; diff --git a/src/script/lua_api/l_env.cpp b/src/script/lua_api/l_env.cpp index 18ee3a521a..fd80219867 100644 --- a/src/script/lua_api/l_env.cpp +++ b/src/script/lua_api/l_env.cpp @@ -65,7 +65,7 @@ const EnumString ModApiEnvMod::es_BlockStatusType[] = /////////////////////////////////////////////////////////////////////////////// -void LuaABM::trigger(ServerEnvironment *env, v3s16 p, MapNode n, +void LuaABM::trigger(ServerEnvironment *env, v3POS p, MapNode n, u32 active_object_count, u32 active_object_count_wider) { ServerScripting *scriptIface = env->getScriptIface(); @@ -97,7 +97,7 @@ void LuaABM::trigger(ServerEnvironment *env, v3s16 p, MapNode n, lua_getfield(L, -1, "action"); luaL_checktype(L, -1, LUA_TFUNCTION); lua_remove(L, -2); // Remove registered_abms[m_id] - push_v3s16(L, p); + push_v3POS(L, p); pushnode(L, n, env->getGameDef()->ndef()); lua_pushnumber(L, active_object_count); lua_pushnumber(L, active_object_count_wider); @@ -109,7 +109,7 @@ void LuaABM::trigger(ServerEnvironment *env, v3s16 p, MapNode n, lua_pop(L, 1); // Pop error handler } -void LuaLBM::trigger(ServerEnvironment *env, v3s16 p, MapNode n) +void LuaLBM::trigger(ServerEnvironment *env, v3POS p, MapNode n) { ServerScripting *scriptIface = env->getScriptIface(); scriptIface->realityCheck(); @@ -139,7 +139,7 @@ void LuaLBM::trigger(ServerEnvironment *env, v3s16 p, MapNode n) lua_getfield(L, -1, "action"); luaL_checktype(L, -1, LUA_TFUNCTION); lua_remove(L, -2); // Remove registered_lbms[m_id] - push_v3s16(L, p); + push_v3POS(L, p); pushnode(L, n, env->getGameDef()->ndef()); int result = lua_pcall(L, 2, 0, error_handler); @@ -250,7 +250,7 @@ const luaL_Reg LuaRaycast::methods[] = { 0, 0 } }; -void LuaEmergeAreaCallback(v3s16 blockpos, EmergeAction action, void *param) +void LuaEmergeAreaCallback(v3POS blockpos, EmergeAction action, void *param) { ScriptCallbackState *state = (ScriptCallbackState *)param; assert(state != NULL); @@ -279,7 +279,7 @@ int ModApiEnvMod::l_set_node(lua_State *L) const NodeDefManager *ndef = env->getGameDef()->ndef(); // parameters - v3s16 pos = read_v3s16(L, 1); + v3POS pos = read_v3POS(L, 1); MapNode n = readnode(L, 2, ndef); // Do it bool succeeded = env->setNode(pos, n); @@ -311,7 +311,7 @@ int ModApiEnvMod::l_bulk_set_node(lua_State *L) bool succeeded = true; for (s32 i = 1; i <= len; i++) { lua_rawgeti(L, 1, i); - if (!env->setNode(read_v3s16(L, -1), n)) + if (!env->setNode(read_v3POS(L, -1), n)) succeeded = false; lua_pop(L, 1); } @@ -332,7 +332,7 @@ int ModApiEnvMod::l_remove_node(lua_State *L) GET_ENV_PTR; // parameters - v3s16 pos = read_v3s16(L, 1); + v3POS pos = read_v3POS(L, 1); // Do it bool succeeded = env->removeNode(pos); lua_pushboolean(L, succeeded); @@ -347,7 +347,7 @@ int ModApiEnvMod::l_swap_node(lua_State *L) const NodeDefManager *ndef = env->getGameDef()->ndef(); // parameters - v3s16 pos = read_v3s16(L, 1); + v3POS pos = read_v3POS(L, 1); MapNode n = readnode(L, 2, ndef); // Do it bool succeeded = env->swapNode(pos, n); @@ -362,7 +362,7 @@ int ModApiEnvMod::l_get_node(lua_State *L) GET_ENV_PTR; // pos - v3s16 pos = read_v3s16(L, 1); + v3POS pos = read_v3POS(L, 1); // Do it MapNode n = env->getMap().getNode(pos); // Return node @@ -377,7 +377,7 @@ int ModApiEnvMod::l_get_node_or_nil(lua_State *L) GET_ENV_PTR; // pos - v3s16 pos = read_v3s16(L, 1); + v3POS pos = read_v3POS(L, 1); // Do it bool pos_ok; MapNode n = env->getMap().getNode(pos, &pos_ok); @@ -398,7 +398,7 @@ int ModApiEnvMod::l_get_node_light(lua_State *L) GET_PLAIN_ENV_PTR; // Do it - v3s16 pos = read_v3s16(L, 1); + v3POS pos = read_v3POS(L, 1); u32 time_of_day = env->getTimeOfDay(); if(lua_isnumber(L, 2)) time_of_day = 24000.0 * lua_tonumber(L, 2); @@ -424,7 +424,7 @@ int ModApiEnvMod::l_get_natural_light(lua_State *L) { GET_ENV_PTR; - v3s16 pos = read_v3s16(L, 1); + v3POS pos = read_v3POS(L, 1); bool is_position_ok; MapNode n = env->getMap().getNode(pos, &is_position_ok); @@ -467,7 +467,7 @@ int ModApiEnvMod::l_place_node(lua_State *L) const NodeDefManager *ndef = server->ndef(); IItemDefManager *idef = server->idef(); - v3s16 pos = read_v3s16(L, 1); + v3POS pos = read_v3POS(L, 1); MapNode n = readnode(L, 2, ndef); // Don't attempt to load non-loaded area as of now @@ -482,7 +482,7 @@ int ModApiEnvMod::l_place_node(lua_State *L) PointedThing pointed; pointed.type = POINTEDTHING_NODE; pointed.node_abovesurface = pos; - pointed.node_undersurface = pos + v3s16(0,-1,0); + pointed.node_undersurface = pos + v3POS(0,-1,0); // Place it with a NULL placer (appears in Lua as nil) bool success = scriptIfaceItem->item_OnPlace(item, nullptr, pointed); lua_pushboolean(L, success); @@ -497,7 +497,7 @@ int ModApiEnvMod::l_dig_node(lua_State *L) ScriptApiNode *scriptIfaceNode = getScriptApi(L); - v3s16 pos = read_v3s16(L, 1); + v3POS pos = read_v3POS(L, 1); // Don't attempt to load non-loaded area as of now MapNode n = env->getMap().getNode(pos); @@ -520,7 +520,7 @@ int ModApiEnvMod::l_punch_node(lua_State *L) ScriptApiNode *scriptIfaceNode = getScriptApi(L); - v3s16 pos = read_v3s16(L, 1); + v3POS pos = read_v3POS(L, 1); // Don't attempt to load non-loaded area as of now MapNode n = env->getMap().getNode(pos); @@ -541,7 +541,7 @@ int ModApiEnvMod::l_get_node_max_level(lua_State *L) { GET_PLAIN_ENV_PTR; - v3s16 pos = read_v3s16(L, 1); + v3POS pos = read_v3POS(L, 1); MapNode n = env->getMap().getNode(pos); lua_pushnumber(L, n.getMaxLevel(env->getGameDef()->ndef())); return 1; @@ -553,7 +553,7 @@ int ModApiEnvMod::l_get_node_level(lua_State *L) { GET_PLAIN_ENV_PTR; - v3s16 pos = read_v3s16(L, 1); + v3POS pos = read_v3POS(L, 1); MapNode n = env->getMap().getNode(pos); lua_pushnumber(L, n.getLevel(env->getGameDef()->ndef())); return 1; @@ -566,7 +566,7 @@ int ModApiEnvMod::l_set_node_level(lua_State *L) { GET_ENV_PTR; - v3s16 pos = read_v3s16(L, 1); + v3POS pos = read_v3POS(L, 1); u8 level = 1; if(lua_isnumber(L, 2)) level = lua_tonumber(L, 2); @@ -583,7 +583,7 @@ int ModApiEnvMod::l_add_node_level(lua_State *L) { GET_ENV_PTR; - v3s16 pos = read_v3s16(L, 1); + v3POS pos = read_v3POS(L, 1); s16 level = 1; if(lua_isnumber(L, 2)) level = lua_tonumber(L, 2); @@ -598,12 +598,12 @@ int ModApiEnvMod::l_find_nodes_with_meta(lua_State *L) { GET_PLAIN_ENV_PTR; - std::vector positions = env->getMap().findNodesWithMetadata( - check_v3s16(L, 1), check_v3s16(L, 2)); + std::vector positions = env->getMap().findNodesWithMetadata( + check_v3POS(L, 1), check_v3POS(L, 2)); lua_createtable(L, positions.size(), 0); for (size_t i = 0; i != positions.size(); i++) { - push_v3s16(L, positions[i]); + push_v3POS(L, positions[i]); lua_rawseti(L, -2, i + 1); } @@ -616,7 +616,7 @@ int ModApiEnvMod::l_get_meta(lua_State *L) GET_ENV_PTR; // Do it - v3s16 p = read_v3s16(L, 1); + v3POS p = read_v3POS(L, 1); NodeMetaRef::create(L, p, env); return 1; } @@ -627,7 +627,7 @@ int ModApiEnvMod::l_get_node_timer(lua_State *L) GET_ENV_PTR; // Do it - v3s16 p = read_v3s16(L, 1); + v3POS p = read_v3POS(L, 1); NodeTimerRef::create(L, p, &env->getServerMap()); return 1; } @@ -853,7 +853,7 @@ int ModApiEnvMod::l_find_node_near(lua_State *L) const NodeDefManager *ndef = env->getGameDef()->ndef(); Map &map = env->getMap(); - v3s16 pos = read_v3s16(L, 1); + v3POS pos = read_v3POS(L, 1); int radius = luaL_checkinteger(L, 2); std::vector filter; collectNodeIds(L, 3, ndef, filter); @@ -867,12 +867,12 @@ int ModApiEnvMod::l_find_node_near(lua_State *L) #endif for (int d = start_radius; d <= radius; d++) { - const std::vector &list = FacePositionCache::getFacePositions(d); - for (const v3s16 &i : list) { - v3s16 p = pos + i; + const std::vector &list = FacePositionCache::getFacePositions(d); + for (const v3POS &i : list) { + v3POS p = pos + i; content_t c = map.getNode(p).getContent(); if (CONTAINS(filter, c)) { - push_v3s16(L, p); + push_v3POS(L, p); return 1; } } @@ -880,7 +880,7 @@ int ModApiEnvMod::l_find_node_near(lua_State *L) return 0; } -static void checkArea(v3s16 &minp, v3s16 &maxp) +static void checkArea(v3POS &minp, v3POS &maxp) { auto volume = VoxelArea(minp, maxp).getVolume(); // Volume limit equal to 8 default mapchunks, (80 * 2) ^ 3 = 4,096,000 @@ -889,9 +889,9 @@ static void checkArea(v3s16 &minp, v3s16 &maxp) } // Clamp to map range to avoid problems -#define CLAMP(arg) core::clamp(arg, (s16)-MAX_MAP_GENERATION_LIMIT, (s16)MAX_MAP_GENERATION_LIMIT) - minp = v3s16(CLAMP(minp.X), CLAMP(minp.Y), CLAMP(minp.Z)); - maxp = v3s16(CLAMP(maxp.X), CLAMP(maxp.Y), CLAMP(maxp.Z)); +#define CLAMP(arg) core::clamp(arg, (POS)-MAX_MAP_GENERATION_LIMIT, (POS)MAX_MAP_GENERATION_LIMIT) + minp = v3POS(CLAMP(minp.X), CLAMP(minp.Y), CLAMP(minp.Z)); + maxp = v3POS(CLAMP(maxp.X), CLAMP(maxp.Y), CLAMP(maxp.Z)); #undef CLAMP } @@ -900,8 +900,8 @@ int ModApiEnvMod::l_find_nodes_in_area(lua_State *L) { GET_PLAIN_ENV_PTR; - v3s16 minp = read_v3s16(L, 1); - v3s16 maxp = read_v3s16(L, 2); + v3POS minp = read_v3POS(L, 1); + v3POS maxp = read_v3POS(L, 2); sortBoxVerticies(minp, maxp); const NodeDefManager *ndef = env->getGameDef()->ndef(); @@ -932,7 +932,7 @@ int ModApiEnvMod::l_find_nodes_in_area(lua_State *L) for (u32 i = 0; i < filter.size(); i++) lua_newtable(L); - v3s16 p; + v3POS p; for (p.X = minp.X; p.X <= maxp.X; p.X++) for (p.Y = minp.Y; p.Y <= maxp.Y; p.Y++) for (p.Z = minp.Z; p.Z <= maxp.Z; p.Z++) { @@ -942,7 +942,7 @@ int ModApiEnvMod::l_find_nodes_in_area(lua_State *L) if (it != filter.end()) { // Calculate index of the table and append the position u32 filt_index = it - filter.begin(); - push_v3s16(L, p); + push_v3POS(L, p); lua_rawseti(L, base + 1 + filt_index, ++idx[filt_index]); } } @@ -967,7 +967,7 @@ int ModApiEnvMod::l_find_nodes_in_area(lua_State *L) lua_newtable(L); u32 i = 0; - v3s16 p; + v3POS p; for (p.X = minp.X; p.X <= maxp.X; p.X++) for (p.Y = minp.Y; p.Y <= maxp.Y; p.Y++) for (p.Z = minp.Z; p.Z <= maxp.Z; p.Z++) { @@ -975,7 +975,7 @@ int ModApiEnvMod::l_find_nodes_in_area(lua_State *L) auto it = std::find(filter.begin(), filter.end(), c); if (it != filter.end()) { - push_v3s16(L, p); + push_v3POS(L, p); lua_rawseti(L, -2, ++i); u32 filt_index = it - filter.begin(); @@ -1005,8 +1005,8 @@ int ModApiEnvMod::l_find_nodes_in_area_under_air(lua_State *L) GET_PLAIN_ENV_PTR; - v3s16 minp = read_v3s16(L, 1); - v3s16 maxp = read_v3s16(L, 2); + v3POS minp = read_v3POS(L, 1); + v3POS maxp = read_v3POS(L, 2); sortBoxVerticies(minp, maxp); const NodeDefManager *ndef = env->getGameDef()->ndef(); @@ -1026,17 +1026,17 @@ int ModApiEnvMod::l_find_nodes_in_area_under_air(lua_State *L) lua_newtable(L); u32 i = 0; - v3s16 p; + v3POS p; for (p.X = minp.X; p.X <= maxp.X; p.X++) for (p.Z = minp.Z; p.Z <= maxp.Z; p.Z++) { p.Y = minp.Y; content_t c = map.getNode(p).getContent(); for (; p.Y <= maxp.Y; p.Y++) { - v3s16 psurf(p.X, p.Y + 1, p.Z); + v3POS psurf(p.X, p.Y + 1, p.Z); content_t csurf = map.getNode(psurf).getContent(); if (c != CONTENT_AIR && csurf == CONTENT_AIR && CONTAINS(filter, c)) { - push_v3s16(L, p); + push_v3POS(L, p); lua_rawseti(L, -2, ++i); } c = csurf; @@ -1080,7 +1080,7 @@ int ModApiEnvMod::l_get_perlin_map(lua_State *L) NoiseParams np; if (!read_noiseparams(L, 1, &np)) return 0; - v3s16 size = read_v3s16(L, 2); + v3POS size = read_v3POS(L, 2); s32 seed = (s32)(env->getServerMap().getSeed()); LuaPerlinNoiseMap *n = new LuaPerlinNoiseMap(&np, seed, size); @@ -1098,7 +1098,7 @@ int ModApiEnvMod::l_get_voxel_manip(lua_State *L) Map *map = &(env->getMap()); LuaVoxelManip *o = (lua_istable(L, 1) && lua_istable(L, 2)) ? - new LuaVoxelManip(map, read_v3s16(L, 1), read_v3s16(L, 2)) : + new LuaVoxelManip(map, read_v3POS(L, 1), read_v3POS(L, 2)) : new LuaVoxelManip(map); *(void **)(lua_newuserdata(L, sizeof(void *))) = o; @@ -1134,12 +1134,12 @@ int ModApiEnvMod::l_line_of_sight(lua_State *L) // read position 2 from lua v3f pos2 = checkFloatPos(L, 2); - v3s16 p; + v3POS p; bool success = env->line_of_sight(pos1, pos2, &p); lua_pushboolean(L, success); if (!success) { - push_v3s16(L, p); + push_v3POS(L, p); return 2; } return 1; @@ -1150,12 +1150,12 @@ int ModApiEnvMod::l_fix_light(lua_State *L) { GET_ENV_PTR; - v3s16 blockpos1 = getContainerPos(read_v3s16(L, 1), MAP_BLOCKSIZE); - v3s16 blockpos2 = getContainerPos(read_v3s16(L, 2), MAP_BLOCKSIZE); + v3POS blockpos1 = getContainerPos(read_v3POS(L, 1), MAP_BLOCKSIZE); + v3POS blockpos2 = getContainerPos(read_v3POS(L, 2), MAP_BLOCKSIZE); ServerMap &map = env->getServerMap(); - std::map modified_blocks; + std::map modified_blocks; bool success = true; - v3s16 blockpos; + v3POS blockpos; for (blockpos.X = blockpos1.X; blockpos.X <= blockpos2.X; blockpos.X++) for (blockpos.Y = blockpos1.Y; blockpos.Y <= blockpos2.Y; blockpos.Y++) for (blockpos.Z = blockpos1.Z; blockpos.Z <= blockpos2.Z; blockpos.Z++) { @@ -1187,16 +1187,16 @@ int ModApiEnvMod::l_load_area(lua_State *L) MAP_LOCK_REQUIRED; Map *map = &(env->getMap()); - v3s16 bp1 = getNodeBlockPos(check_v3s16(L, 1)); + v3BPOS bp1 = getNodeBlockPos(check_v3POS(L, 1)); if (!lua_istable(L, 2)) { map->emergeBlock(bp1); } else { - v3s16 bp2 = getNodeBlockPos(check_v3s16(L, 2)); + v3BPOS bp2 = getNodeBlockPos(check_v3POS(L, 2)); sortBoxVerticies(bp1, bp2); for (s16 z = bp1.Z; z <= bp2.Z; z++) for (s16 y = bp1.Y; y <= bp2.Y; y++) for (s16 x = bp1.X; x <= bp2.X; x++) { - map->emergeBlock(v3s16(x, y, z)); + map->emergeBlock(v3POS(x, y, z)); } } @@ -1214,8 +1214,8 @@ int ModApiEnvMod::l_emerge_area(lua_State *L) EmergeManager *emerge = getServer(L)->getEmergeManager(); - v3s16 bpmin = getNodeBlockPos(read_v3s16(L, 1)); - v3s16 bpmax = getNodeBlockPos(read_v3s16(L, 2)); + v3BPOS bpmin = getNodeBlockPos(read_v3POS(L, 1)); + v3BPOS bpmax = getNodeBlockPos(read_v3POS(L, 2)); sortBoxVerticies(bpmin, bpmax); size_t num_blocks = VoxelArea(bpmin, bpmax).getVolume(); @@ -1241,7 +1241,7 @@ int ModApiEnvMod::l_emerge_area(lua_State *L) for (s16 z = bpmin.Z; z <= bpmax.Z; z++) for (s16 y = bpmin.Y; y <= bpmax.Y; y++) for (s16 x = bpmin.X; x <= bpmax.X; x++) { - emerge->enqueueBlockEmergeEx(v3s16(x, y, z), PEER_ID_INEXISTENT, + emerge->enqueueBlockEmergeEx(v3POS(x, y, z), PEER_ID_INEXISTENT, BLOCK_EMERGE_ALLOW_GEN | BLOCK_EMERGE_FORCE_QUEUE, callback, state); } @@ -1254,8 +1254,8 @@ int ModApiEnvMod::l_delete_area(lua_State *L) { GET_ENV_PTR; - v3s16 bpmin = getNodeBlockPos(read_v3s16(L, 1)); - v3s16 bpmax = getNodeBlockPos(read_v3s16(L, 2)); + v3BPOS bpmin = getNodeBlockPos(read_v3POS(L, 1)); + v3BPOS bpmax = getNodeBlockPos(read_v3POS(L, 2)); sortBoxVerticies(bpmin, bpmax); ServerMap &map = env->getServerMap(); @@ -1264,10 +1264,10 @@ int ModApiEnvMod::l_delete_area(lua_State *L) event.type = MEET_OTHER; bool success = true; - for (s16 z = bpmin.Z; z <= bpmax.Z; z++) - for (s16 y = bpmin.Y; y <= bpmax.Y; y++) - for (s16 x = bpmin.X; x <= bpmax.X; x++) { - v3s16 bp(x, y, z); + for (BPOS z = bpmin.Z; z <= bpmax.Z; z++) + for (BPOS y = bpmin.Y; y <= bpmax.Y; y++) + for (BPOS x = bpmin.X; x <= bpmax.X; x++) { + v3BPOS bp(x, y, z); if (map.deleteBlock(bp)) { env->setStaticForActiveObjectsInBlock(bp, false); event.modified_blocks.insert(bp); @@ -1287,8 +1287,8 @@ int ModApiEnvMod::l_find_path(lua_State *L) { GET_ENV_PTR; - v3s16 pos1 = read_v3s16(L, 1); - v3s16 pos2 = read_v3s16(L, 2); + v3POS pos1 = read_v3POS(L, 1); + v3POS pos2 = read_v3POS(L, 2); unsigned int searchdistance = luaL_checkint(L, 3); unsigned int max_jump = luaL_checkint(L, 4); unsigned int max_drop = luaL_checkint(L, 5); @@ -1303,16 +1303,16 @@ int ModApiEnvMod::l_find_path(lua_State *L) algo = PA_DIJKSTRA; } - std::vector path = get_path(&env->getServerMap(), env->getGameDef()->ndef(), pos1, pos2, + std::vector path = get_path(&env->getServerMap(), env->getGameDef()->ndef(), pos1, pos2, searchdistance, max_jump, max_drop, algo); if (!path.empty()) { lua_createtable(L, path.size(), 0); int top = lua_gettop(L); unsigned int index = 1; - for (const v3s16 &i : path) { + for (const v3POS &i : path) { lua_pushnumber(L,index); - push_v3s16(L, i); + push_v3POS(L, i); lua_settable(L, top); index++; } @@ -1327,7 +1327,7 @@ int ModApiEnvMod::l_spawn_tree(lua_State *L) { GET_ENV_PTR; - v3s16 p0 = read_v3s16(L, 1); + v3POS p0 = read_v3POS(L, 1); treegen::TreeDef tree_def; std::string trunk,leaves,fruit; @@ -1385,7 +1385,7 @@ int ModApiEnvMod::l_transforming_liquid_add(lua_State *L) { GET_ENV_PTR; - v3s16 p0 = read_v3s16(L, 1); + v3POS p0 = read_v3POS(L, 1); env->getMap().transforming_liquid_add(p0); return 1; } @@ -1396,7 +1396,7 @@ int ModApiEnvMod::l_forceload_block(lua_State *L) { GET_ENV_PTR; - v3s16 blockpos = read_v3s16(L, 1); + v3POS blockpos = read_v3POS(L, 1); env->getForceloadedBlocks()->insert(blockpos); return 0; } @@ -1406,7 +1406,7 @@ int ModApiEnvMod::l_compare_block_status(lua_State *L) { GET_ENV_PTR; - v3s16 nodepos = check_v3s16(L, 1); + v3POS nodepos = check_v3POS(L, 1); std::string condition_s = luaL_checkstring(L, 2); auto status = env->getBlockStatus(getNodeBlockPos(nodepos)); @@ -1425,7 +1425,7 @@ int ModApiEnvMod::l_forceload_free_block(lua_State *L) { GET_ENV_PTR; - v3s16 blockpos = read_v3s16(L, 1); + v3POS blockpos = read_v3POS(L, 1); env->getForceloadedBlocks()->erase(blockpos); return 0; } diff --git a/src/script/lua_api/l_env.h b/src/script/lua_api/l_env.h index 67c76faae5..96780604f2 100644 --- a/src/script/lua_api/l_env.h +++ b/src/script/lua_api/l_env.h @@ -223,13 +223,13 @@ class LuaABM : public ActiveBlockModifier { float m_trigger_interval; u32 m_trigger_chance; bool m_simple_catch_up; - s16 m_min_y; - s16 m_max_y; + POS m_min_y; + POS m_max_y; public: LuaABM(lua_State *L, int id, const std::vector &trigger_contents, const std::vector &required_neighbors, - float trigger_interval, u32 trigger_chance, bool simple_catch_up, s16 min_y, s16 max_y): + float trigger_interval, u32 trigger_chance, bool simple_catch_up, POS min_y, POS max_y): m_id(id), m_trigger_contents(trigger_contents), m_required_neighbors(required_neighbors), @@ -260,15 +260,15 @@ class LuaABM : public ActiveBlockModifier { { return m_simple_catch_up; } - virtual s16 getMinY() + virtual POS getMinY() { return m_min_y; } - virtual s16 getMaxY() + virtual POS getMaxY() { return m_max_y; } - virtual void trigger(ServerEnvironment *env, v3s16 p, MapNode n, + virtual void trigger(ServerEnvironment *env, v3POS p, MapNode n, u32 active_object_count, u32 active_object_count_wider); }; @@ -287,7 +287,7 @@ class LuaLBM : public LoadingBlockModifierDef this->trigger_contents = trigger_contents; this->name = name; } - virtual void trigger(ServerEnvironment *env, v3s16 p, MapNode n); + virtual void trigger(ServerEnvironment *env, v3POS p, MapNode n); }; //! Lua wrapper for RaycastState objects diff --git a/src/script/lua_api/l_inventory.cpp b/src/script/lua_api/l_inventory.cpp index b0a4ee1943..82bfb7d5ed 100644 --- a/src/script/lua_api/l_inventory.cpp +++ b/src/script/lua_api/l_inventory.cpp @@ -385,7 +385,7 @@ int InvRef::l_get_location(lua_State *L) lua_newtable(L); lua_pushstring(L, "node"); lua_setfield(L, -2, "type"); - push_v3s16(L, loc.p); + push_v3POS(L, loc.p); lua_setfield(L, -2, "pos"); return 1; case InventoryLocation::DETACHED: @@ -483,7 +483,7 @@ int ModApiInventory::l_get_inventory(lua_State *L) if(type == "node"){ MAP_LOCK_REQUIRED; lua_getfield(L, 1, "pos"); - v3s16 pos = check_v3s16(L, -1); + v3POS pos = check_v3POS(L, -1); loc.setNodeMeta(pos); if (getServerInventoryMgr(L)->getInventory(loc) != NULL) diff --git a/src/script/lua_api/l_mapgen.cpp b/src/script/lua_api/l_mapgen.cpp index f173bd1622..8e4d80c606 100644 --- a/src/script/lua_api/l_mapgen.cpp +++ b/src/script/lua_api/l_mapgen.cpp @@ -228,7 +228,7 @@ bool read_schematic_def(lua_State *L, int index, //// Get schematic size lua_getfield(L, index, "size"); - v3s16 size = check_v3s16(L, -1); + v3POS size = check_v3POS(L, -1); lua_pop(L, 1); schem->size = size; @@ -381,7 +381,7 @@ Biome *read_biome_def(lua_State *L, int index, const NodeDefManager *ndef) b->name = getstringfield_default(L, index, "name", ""); b->depth_top = getintfield_default(L, index, "depth_top", 0); - b->depth_filler = getintfield_default(L, index, "depth_filler", -31000); + b->depth_filler = getintfield_default(L, index, "depth_filler", -MAX_MAP_GENERATION_LIMIT); b->depth_water_top = getintfield_default(L, index, "depth_water_top", 0); b->depth_riverbed = getintfield_default(L, index, "depth_riverbed", 0); b->heat_point = getfloatfield_default(L, index, "heat_point", 0.f); @@ -389,11 +389,11 @@ Biome *read_biome_def(lua_State *L, int index, const NodeDefManager *ndef) b->vertical_blend = getintfield_default(L, index, "vertical_blend", 0); b->flags = 0; // reserved - b->min_pos = getv3s16field_default( - L, index, "min_pos", v3s16(-31000, -31000, -31000)); + b->min_pos = getv3POSfield_default( + L, index, "min_pos", v3POS(-MAX_MAP_GENERATION_LIMIT, -MAX_MAP_GENERATION_LIMIT, -MAX_MAP_GENERATION_LIMIT)); getintfield(L, index, "y_min", b->min_pos.Y); - b->max_pos = getv3s16field_default( - L, index, "max_pos", v3s16(31000, 31000, 31000)); + b->max_pos = getv3POSfield_default( + L, index, "max_pos", v3POS(MAX_MAP_GENERATION_LIMIT, MAX_MAP_GENERATION_LIMIT, MAX_MAP_GENERATION_LIMIT)); getintfield(L, index, "y_max", b->max_pos.Y); std::vector &nn = b->m_nodenames; @@ -523,7 +523,7 @@ int ModApiMapgen::l_get_heat(lua_State *L) { NO_MAP_LOCK_REQUIRED; - v3s16 pos = read_v3s16(L, 1); + v3POS pos = read_v3POS(L, 1); const BiomeGen *biomegen = getServer(L)->getEmergeManager()->getBiomeGen(); @@ -544,7 +544,7 @@ int ModApiMapgen::l_get_humidity(lua_State *L) { NO_MAP_LOCK_REQUIRED; - v3s16 pos = read_v3s16(L, 1); + v3POS pos = read_v3POS(L, 1); const BiomeGen *biomegen = getServer(L)->getEmergeManager()->getBiomeGen(); @@ -565,7 +565,7 @@ int ModApiMapgen::l_get_biome_data(lua_State *L) { NO_MAP_LOCK_REQUIRED; - v3s16 pos = read_v3s16(L, 1); + v3POS pos = read_v3POS(L, 1); const BiomeGen *biomegen = getServer(L)->getEmergeManager()->getBiomeGen(); if (!biomegen) @@ -627,10 +627,10 @@ int ModApiMapgen::l_get_mapgen_object(lua_State *L) lua_setmetatable(L, -2); // emerged min pos - push_v3s16(L, vm->m_area.MinEdge); + push_v3POS(L, vm->m_area.MinEdge); // emerged max pos - push_v3s16(L, vm->m_area.MaxEdge); + push_v3POS(L, vm->m_area.MaxEdge); return 3; } @@ -688,7 +688,7 @@ int ModApiMapgen::l_get_mapgen_object(lua_State *L) return 1; } case MGOBJ_GENNOTIFY: { - std::map >event_map; + std::map >event_map; mg->gennotify.getEvents(event_map); @@ -697,7 +697,7 @@ int ModApiMapgen::l_get_mapgen_object(lua_State *L) lua_createtable(L, it->second.size(), 0); for (size_t j = 0; j != it->second.size(); j++) { - push_v3s16(L, it->second[j]); + push_v3POS(L, it->second[j]); lua_rawseti(L, -2, j + 1); } @@ -721,7 +721,7 @@ int ModApiMapgen::l_get_spawn_level(lua_State *L) s16 z = luaL_checkinteger(L, 2); EmergeManager *emerge = getServer(L)->getEmergeManager(); - int spawn_level = emerge->getSpawnLevelAtPoint(v2s16(x, z)); + int spawn_level = emerge->getSpawnLevelAtPoint(v2POS(x, z)); // Unsuitable spawn point if (spawn_level == MAX_MAP_GENERATION_LIMIT) return 0; @@ -1058,8 +1058,8 @@ int ModApiMapgen::l_register_decoration(lua_State *L) deco->name = getstringfield_default(L, index, "name", ""); deco->fill_ratio = getfloatfield_default(L, index, "fill_ratio", 0.02); - deco->y_min = getintfield_default(L, index, "y_min", -31000); - deco->y_max = getintfield_default(L, index, "y_max", 31000); + deco->y_min = getintfield_default(L, index, "y_min", -MAX_MAP_GENERATION_LIMIT); + deco->y_max = getintfield_default(L, index, "y_max", MAX_MAP_GENERATION_LIMIT); deco->nspawnby = getintfield_default(L, index, "num_spawn_by", -1); deco->place_offset_y = getintfield_default(L, index, "place_offset_y", 0); deco->sidelen = getintfield_default(L, index, "sidelen", 8); @@ -1238,10 +1238,10 @@ int ModApiMapgen::l_register_ore(lua_State *L) int ymin, ymax; if (!getintfield(L, index, "y_min", ymin) && !getintfield(L, index, "height_min", ymin)) - ymin = -31000; + ymin = -MAX_MAP_GENERATION_LIMIT; if (!getintfield(L, index, "y_max", ymax) && !getintfield(L, index, "height_max", ymax)) - ymax = 31000; + ymax = MAX_MAP_GENERATION_LIMIT; ore->y_min = ymin; ore->y_max = ymax; @@ -1432,10 +1432,10 @@ int ModApiMapgen::l_generate_ores(lua_State *L) mg.vm = LuaVoxelManip::checkobject(L, 1)->vm; mg.ndef = getServer(L)->getNodeDefManager(); - v3s16 pmin = lua_istable(L, 2) ? check_v3s16(L, 2) : - mg.vm->m_area.MinEdge + v3s16(1,1,1) * MAP_BLOCKSIZE; - v3s16 pmax = lua_istable(L, 3) ? check_v3s16(L, 3) : - mg.vm->m_area.MaxEdge - v3s16(1,1,1) * MAP_BLOCKSIZE; + v3POS pmin = lua_istable(L, 2) ? check_v3POS(L, 2) : + mg.vm->m_area.MinEdge + v3POS(1,1,1) * MAP_BLOCKSIZE; + v3POS pmax = lua_istable(L, 3) ? check_v3POS(L, 3) : + mg.vm->m_area.MaxEdge - v3POS(1,1,1) * MAP_BLOCKSIZE; sortBoxVerticies(pmin, pmax); u32 blockseed = Mapgen::getBlockSeed(pmin, mg.seed); @@ -1461,10 +1461,10 @@ int ModApiMapgen::l_generate_decorations(lua_State *L) mg.vm = LuaVoxelManip::checkobject(L, 1)->vm; mg.ndef = getServer(L)->getNodeDefManager(); - v3s16 pmin = lua_istable(L, 2) ? check_v3s16(L, 2) : - mg.vm->m_area.MinEdge + v3s16(1,1,1) * MAP_BLOCKSIZE; - v3s16 pmax = lua_istable(L, 3) ? check_v3s16(L, 3) : - mg.vm->m_area.MaxEdge - v3s16(1,1,1) * MAP_BLOCKSIZE; + v3POS pmin = lua_istable(L, 2) ? check_v3POS(L, 2) : + mg.vm->m_area.MinEdge + v3POS(1,1,1) * MAP_BLOCKSIZE; + v3POS pmax = lua_istable(L, 3) ? check_v3POS(L, 3) : + mg.vm->m_area.MaxEdge - v3POS(1,1,1) * MAP_BLOCKSIZE; sortBoxVerticies(pmin, pmax); u32 blockseed = Mapgen::getBlockSeed(pmin, mg.seed); @@ -1488,17 +1488,17 @@ int ModApiMapgen::l_create_schematic(lua_State *L) Map *map = &(getEnv(L)->getMap()); Schematic schem; - v3s16 p1 = check_v3s16(L, 1); - v3s16 p2 = check_v3s16(L, 2); + v3POS p1 = check_v3POS(L, 1); + v3POS p2 = check_v3POS(L, 2); sortBoxVerticies(p1, p2); - std::vector > prob_list; + std::vector > prob_list; if (lua_istable(L, 3)) { lua_pushnil(L); while (lua_next(L, 3)) { if (lua_istable(L, -1)) { lua_getfield(L, -1, "pos"); - v3s16 pos = check_v3s16(L, -1); + v3POS pos = check_v3POS(L, -1); lua_pop(L, 1); u8 prob = getintfield_default(L, -1, "prob", MTSCHEM_PROB_ALWAYS); @@ -1552,7 +1552,7 @@ int ModApiMapgen::l_place_schematic(lua_State *L) SchematicManager *schemmgr = getServer(L)->getEmergeManager()->schemmgr; //// Read position - v3s16 p = check_v3s16(L, 1); + v3POS p = check_v3POS(L, 1); //// Read rotation int rot = ROTATE_0; @@ -1600,7 +1600,7 @@ int ModApiMapgen::l_place_schematic_on_vmanip(lua_State *L) MMVManip *vm = LuaVoxelManip::checkobject(L, 1)->vm; //// Read position - v3s16 p = check_v3s16(L, 2); + v3POS p = check_v3POS(L, 2); //// Read rotation int rot = ROTATE_0; @@ -1718,7 +1718,7 @@ int ModApiMapgen::l_read_schematic(lua_State *L) lua_createtable(L, 0, (write_yslice == "none") ? 2 : 3); // Create the size field - push_v3s16(L, schem->size); + push_v3POS(L, schem->size); lua_setfield(L, 1, "size"); // Create the yslice_prob field diff --git a/src/script/lua_api/l_minimap.cpp b/src/script/lua_api/l_minimap.cpp index a135e0bd55..1fc7c31b1d 100644 --- a/src/script/lua_api/l_minimap.cpp +++ b/src/script/lua_api/l_minimap.cpp @@ -53,7 +53,7 @@ int LuaMinimap::l_get_pos(lua_State *L) LuaMinimap *ref = checkobject(L, 1); Minimap *m = getobject(ref); - push_v3s16(L, m->getPos()); + push_v3POS(L, m->getPos()); return 1; } @@ -62,7 +62,7 @@ int LuaMinimap::l_set_pos(lua_State *L) LuaMinimap *ref = checkobject(L, 1); Minimap *m = getobject(ref); - m->setPos(read_v3s16(L, 2)); + m->setPos(read_v3POS(L, 2)); return 1; } diff --git a/src/script/lua_api/l_nodemeta.cpp b/src/script/lua_api/l_nodemeta.cpp index 34760157d5..932f364367 100644 --- a/src/script/lua_api/l_nodemeta.cpp +++ b/src/script/lua_api/l_nodemeta.cpp @@ -171,7 +171,7 @@ bool NodeMetaRef::handleFromTable(lua_State *L, int table, Metadata *_meta) } -NodeMetaRef::NodeMetaRef(v3s16 p, ServerEnvironment *env): +NodeMetaRef::NodeMetaRef(v3POS p, ServerEnvironment *env): m_p(p), m_env(env) { @@ -185,7 +185,7 @@ NodeMetaRef::NodeMetaRef(Metadata *meta): // Creates an NodeMetaRef and leaves it on top of stack // Not callable from Lua; all references are created on the C side. -void NodeMetaRef::create(lua_State *L, v3s16 p, ServerEnvironment *env) +void NodeMetaRef::create(lua_State *L, v3POS p, ServerEnvironment *env) { NodeMetaRef *o = new NodeMetaRef(p, env); //infostream<<"NodeMetaRef::create: o="< 1; np = *params; @@ -304,8 +304,8 @@ int LuaPerlinNoiseMap::l_get_map_slice(lua_State *L) NO_MAP_LOCK_REQUIRED; LuaPerlinNoiseMap *o = checkobject(L, 1); - v3s16 slice_offset = read_v3s16(L, 2); - v3s16 slice_size = read_v3s16(L, 3); + v3POS slice_offset = read_v3POS(L, 2); + v3POS slice_size = read_v3POS(L, 3); bool use_buffer = lua_istable(L, 4); Noise *n = o->noise; @@ -329,7 +329,7 @@ int LuaPerlinNoiseMap::create_object(lua_State *L) NoiseParams np; if (!read_noiseparams(L, 1, &np)) return 0; - v3s16 size = read_v3s16(L, 2); + v3POS size = read_v3POS(L, 2); LuaPerlinNoiseMap *o = new LuaPerlinNoiseMap(&np, 0, size); *(void **)(lua_newuserdata(L, sizeof(void *))) = o; diff --git a/src/script/lua_api/l_noise.h b/src/script/lua_api/l_noise.h index 9f50dfd3fe..57d1ec7d12 100644 --- a/src/script/lua_api/l_noise.h +++ b/src/script/lua_api/l_noise.h @@ -80,7 +80,7 @@ class LuaPerlinNoiseMap : public ModApiBase static int l_get_map_slice(lua_State *L); public: - LuaPerlinNoiseMap(NoiseParams *np, s32 seed, v3s16 size); + LuaPerlinNoiseMap(NoiseParams *np, s32 seed, v3POS size); ~LuaPerlinNoiseMap(); diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp index 072b13d806..4ff76d092d 100644 --- a/src/script/lua_api/l_object.cpp +++ b/src/script/lua_api/l_object.cpp @@ -491,7 +491,7 @@ int ObjectRef::l_send_mapblock(lua_State *L) if (player == nullptr) return 0; - v3s16 pos = read_v3s16(L, 2); + v3POS pos = read_v3POS(L, 2); session_t peer_id = player->getPeerId(); bool r = getServer(L)->SendBlock(peer_id, pos); diff --git a/src/script/lua_api/l_rollback.cpp b/src/script/lua_api/l_rollback.cpp index 482b0cbf58..044e7f81f2 100644 --- a/src/script/lua_api/l_rollback.cpp +++ b/src/script/lua_api/l_rollback.cpp @@ -40,7 +40,7 @@ int ModApiRollback::l_rollback_get_node_actions(lua_State *L) { NO_MAP_LOCK_REQUIRED; - v3s16 pos = read_v3s16(L, 1); + v3POS pos = read_v3POS(L, 1); int range = luaL_checknumber(L, 2); time_t seconds = (time_t) luaL_checknumber(L, 3); int limit = luaL_checknumber(L, 4); @@ -60,7 +60,7 @@ int ModApiRollback::l_rollback_get_node_actions(lua_State *L) lua_pushstring(L, iter->actor.c_str()); lua_setfield(L, -2, "actor"); - push_v3s16(L, iter->p); + push_v3POS(L, iter->p); lua_setfield(L, -2, "pos"); lua_pushnumber(L, iter->unix_time); diff --git a/src/script/lua_api/l_vmanip.cpp b/src/script/lua_api/l_vmanip.cpp index e040e545bb..a624b0fd7a 100644 --- a/src/script/lua_api/l_vmanip.cpp +++ b/src/script/lua_api/l_vmanip.cpp @@ -46,14 +46,14 @@ int LuaVoxelManip::l_read_from_map(lua_State *L) LuaVoxelManip *o = checkobject(L, 1); MMVManip *vm = o->vm; - v3s16 bp1 = getNodeBlockPos(check_v3s16(L, 2)); - v3s16 bp2 = getNodeBlockPos(check_v3s16(L, 3)); + v3BPOS bp1 = getNodeBlockPos(check_v3POS(L, 2)); + v3BPOS bp2 = getNodeBlockPos(check_v3POS(L, 3)); sortBoxVerticies(bp1, bp2); vm->initialEmerge(bp1, bp2); - push_v3s16(L, vm->m_area.MinEdge); - push_v3s16(L, vm->m_area.MaxEdge); + push_v3POS(L, vm->m_area.MinEdge); + push_v3POS(L, vm->m_area.MaxEdge); return 2; } @@ -139,7 +139,7 @@ int LuaVoxelManip::l_get_node_at(lua_State *L) const NodeDefManager *ndef = getServer(L)->getNodeDefManager(); LuaVoxelManip *o = checkobject(L, 1); - v3s16 pos = check_v3s16(L, 2); + v3POS pos = check_v3POS(L, 2); pushnode(L, o->vm->getNodeNoExNoEmerge(pos), ndef); return 1; @@ -152,7 +152,7 @@ int LuaVoxelManip::l_set_node_at(lua_State *L) const NodeDefManager *ndef = getServer(L)->getNodeDefManager(); LuaVoxelManip *o = checkobject(L, 1); - v3s16 pos = check_v3s16(L, 2); + v3POS pos = check_v3POS(L, 2); MapNode n = readnode(L, 3, ndef); o->vm->setNodeNoEmerge(pos, n); @@ -195,11 +195,11 @@ int LuaVoxelManip::l_calc_lighting(lua_State *L) EmergeManager *emerge = getServer(L)->getEmergeManager(); MMVManip *vm = o->vm; - v3s16 yblock = v3s16(0, 1, 0) * MAP_BLOCKSIZE; - v3s16 fpmin = vm->m_area.MinEdge; - v3s16 fpmax = vm->m_area.MaxEdge; - v3s16 pmin = lua_istable(L, 2) ? check_v3s16(L, 2) : fpmin + yblock; - v3s16 pmax = lua_istable(L, 3) ? check_v3s16(L, 3) : fpmax - yblock; + v3POS yblock = v3POS(0, 1, 0) * MAP_BLOCKSIZE; + v3POS fpmin = vm->m_area.MinEdge; + v3POS fpmax = vm->m_area.MaxEdge; + v3POS pmin = lua_istable(L, 2) ? check_v3POS(L, 2) : fpmin + yblock; + v3POS pmax = lua_istable(L, 3) ? check_v3POS(L, 3) : fpmax - yblock; bool propagate_shadow = !lua_isboolean(L, 4) || readParam(L, 4); sortBoxVerticies(pmin, pmax); @@ -236,9 +236,9 @@ int LuaVoxelManip::l_set_lighting(lua_State *L) MMVManip *vm = o->vm; - v3s16 yblock = v3s16(0, 1, 0) * MAP_BLOCKSIZE; - v3s16 pmin = lua_istable(L, 3) ? check_v3s16(L, 3) : vm->m_area.MinEdge + yblock; - v3s16 pmax = lua_istable(L, 4) ? check_v3s16(L, 4) : vm->m_area.MaxEdge - yblock; + v3POS yblock = v3POS(0, 1, 0) * MAP_BLOCKSIZE; + v3POS pmin = lua_istable(L, 3) ? check_v3POS(L, 3) : vm->m_area.MinEdge + yblock; + v3POS pmax = lua_istable(L, 4) ? check_v3POS(L, 4) : vm->m_area.MaxEdge - yblock; sortBoxVerticies(pmin, pmax); if (!vm->m_area.contains(VoxelArea(pmin, pmax))) @@ -367,8 +367,8 @@ int LuaVoxelManip::l_get_emerged_area(lua_State *L) LuaVoxelManip *o = checkobject(L, 1); - push_v3s16(L, o->vm->m_area.MinEdge); - push_v3s16(L, o->vm->m_area.MaxEdge); + push_v3POS(L, o->vm->m_area.MinEdge); + push_v3POS(L, o->vm->m_area.MaxEdge); return 2; } @@ -383,12 +383,12 @@ LuaVoxelManip::LuaVoxelManip(Map *map) : vm(new MMVManip(map)) { } -LuaVoxelManip::LuaVoxelManip(Map *map, v3s16 p1, v3s16 p2) +LuaVoxelManip::LuaVoxelManip(Map *map, v3POS p1, v3POS p2) { vm = new MMVManip(map); - v3s16 bp1 = getNodeBlockPos(p1); - v3s16 bp2 = getNodeBlockPos(p2); + v3BPOS bp1 = getNodeBlockPos(p1); + v3BPOS bp2 = getNodeBlockPos(p2); sortBoxVerticies(bp1, bp2); vm->initialEmerge(bp1, bp2); } @@ -407,7 +407,7 @@ int LuaVoxelManip::create_object(lua_State *L) Map *map = &(env->getMap()); LuaVoxelManip *o = (lua_istable(L, 1) && lua_istable(L, 2)) ? - new LuaVoxelManip(map, check_v3s16(L, 1), check_v3s16(L, 2)) : + new LuaVoxelManip(map, check_v3POS(L, 1), check_v3POS(L, 2)) : new LuaVoxelManip(map); *(void **)(lua_newuserdata(L, sizeof(void *))) = o; diff --git a/src/script/lua_api/l_vmanip.h b/src/script/lua_api/l_vmanip.h index 15ab9eef8c..83dd14d717 100644 --- a/src/script/lua_api/l_vmanip.h +++ b/src/script/lua_api/l_vmanip.h @@ -33,7 +33,7 @@ class MMVManip; class LuaVoxelManip : public ModApiBase { private: - std::map modified_blocks; + std::map modified_blocks; bool is_mapgen_vm = false; static const char className[]; @@ -67,7 +67,7 @@ class LuaVoxelManip : public ModApiBase MMVManip *vm = nullptr; LuaVoxelManip(MMVManip *mmvm, bool is_mapgen_vm); - LuaVoxelManip(Map *map, v3s16 p1, v3s16 p2); + LuaVoxelManip(Map *map, v3POS p1, v3POS p2); LuaVoxelManip(Map *map); ~LuaVoxelManip(); diff --git a/src/server.cpp b/src/server.cpp index c175cbcd29..7e46a38f18 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -650,7 +650,7 @@ void Server::AsyncRunStep(bool initial_step) ScopeProfiler sp(g_profiler, "Server: liquid transform"); - std::map modified_blocks; + std::map modified_blocks; m_env->getMap().transformLiquids(modified_blocks, m_env); /* @@ -865,7 +865,7 @@ void Server::AsyncRunStep(bool initial_step) // We'll log the amount of each Profiler prof; - std::list node_meta_updates; + std::list node_meta_updates; while (!m_unsent_map_edit_queue.empty()) { MapEditEvent* event = m_unsent_map_edit_queue.front(); @@ -906,7 +906,7 @@ void Server::AsyncRunStep(bool initial_step) } case MEET_OTHER: prof.add("MEET_OTHER", 1); - for (const v3s16 &modified_block : event->modified_blocks) { + for (const v3POS &modified_block : event->modified_blocks) { m_clients.markBlockposAsNotSent(modified_block); } break; @@ -922,8 +922,8 @@ void Server::AsyncRunStep(bool initial_step) */ if (!far_players.empty()) { // Convert list format to that wanted by SetBlocksNotSent - std::map modified_blocks2; - for (const v3s16 &modified_block : event->modified_blocks) { + std::map modified_blocks2; + for (const v3POS &modified_block : event->modified_blocks) { modified_blocks2[modified_block] = m_env->getMap().getBlockNoCreateNoEx(modified_block); } @@ -1223,7 +1223,7 @@ void Server::onMapEditEvent(const MapEditEvent &event) m_unsent_map_edit_queue.push(new MapEditEvent(event)); } -void Server::SetBlocksNotSent(std::map& block) +void Server::SetBlocksNotSent(std::map& block) { std::vector clients = m_clients.getClientIDs(); m_clients.lock(); @@ -2209,12 +2209,12 @@ void Server::fadeSound(s32 handle, float step, float gain) } } -void Server::sendRemoveNode(v3s16 p, std::unordered_set *far_players, +void Server::sendRemoveNode(v3POS p, std::unordered_set *far_players, float far_d_nodes) { float maxd = far_d_nodes * BS; v3f p_f = intToFloat(p, BS); - v3s16 block_pos = getNodeBlockPos(p); + v3BPOS block_pos = getNodeBlockPos(p); NetworkPacket pkt(TOCLIENT_REMOVENODE, 6); pkt << p; @@ -2247,12 +2247,12 @@ void Server::sendRemoveNode(v3s16 p, std::unordered_set *far_players, m_clients.unlock(); } -void Server::sendAddNode(v3s16 p, MapNode n, std::unordered_set *far_players, +void Server::sendAddNode(v3POS p, MapNode n, std::unordered_set *far_players, float far_d_nodes, bool remove_metadata) { float maxd = far_d_nodes * BS; v3f p_f = intToFloat(p, BS); - v3s16 block_pos = getNodeBlockPos(p); + v3BPOS block_pos = getNodeBlockPos(p); NetworkPacket pkt(TOCLIENT_ADDNODE, 6 + 2 + 1 + 1 + 1); pkt << p << n.param0 << n.param1 << n.param2 @@ -2286,7 +2286,7 @@ void Server::sendAddNode(v3s16 p, MapNode n, std::unordered_set *far_player m_clients.unlock(); } -void Server::sendMetadataChanged(const std::list &meta_updates, float far_d_nodes) +void Server::sendMetadataChanged(const std::list &meta_updates, float far_d_nodes) { float maxd = far_d_nodes * BS; NodeMetadataList meta_updates_list(false); @@ -2302,13 +2302,13 @@ void Server::sendMetadataChanged(const std::list &meta_updates, float far ServerActiveObject *player = m_env->getActiveObject(i); v3f player_pos = player ? player->getBasePosition() : v3f(); - for (const v3s16 &pos : meta_updates) { + for (const v3POS &pos : meta_updates) { NodeMetadata *meta = m_env->getMap().getNodeMetadata(pos); if (!meta) continue; - v3s16 block_pos = getNodeBlockPos(pos); + v3BPOS block_pos = getNodeBlockPos(pos); if (!client->isBlockSent(block_pos) || (player && player_pos.getDistanceFrom(intToFloat(pos, BS)) > maxd)) { client->SetBlockNotSent(block_pos); @@ -2420,7 +2420,7 @@ void Server::SendBlocks(float dtime) m_clients.unlock(); } -bool Server::SendBlock(session_t peer_id, const v3s16 &blockpos) +bool Server::SendBlock(session_t peer_id, const v3POS &blockpos) { MapBlock *block = m_env->getMap().getBlockNoCreateNoEx(blockpos); if (!block) @@ -3708,18 +3708,18 @@ v3f Server::findSpawnPos() for (s32 i = 0; i < 4000 && !is_good; i++) { s32 range = MYMIN(1 + i, range_max); // We're going to try to throw the player to this position - v2s16 nodepos2d = v2s16( + v2POS nodepos2d = v2POS( -range + (myrand() % (range * 2)), -range + (myrand() % (range * 2))); // Get spawn level at point - s16 spawn_level = m_emerge->getSpawnLevelAtPoint(nodepos2d); + POS spawn_level = m_emerge->getSpawnLevelAtPoint(nodepos2d); // Continue if MAX_MAP_GENERATION_LIMIT was returned by the mapgen to // signify an unsuitable spawn position, or if outside limits. if (spawn_level >= MAX_MAP_GENERATION_LIMIT || spawn_level <= -MAX_MAP_GENERATION_LIMIT) continue; - v3s16 nodepos(nodepos2d.X, spawn_level, nodepos2d.Y); + v3POS nodepos(nodepos2d.X, spawn_level, nodepos2d.Y); // Consecutive empty nodes s32 air_count = 0; @@ -3729,7 +3729,7 @@ v3f Server::findSpawnPos() // no obstructions, but mapgen decorations are generated after spawn so // the player may end up inside one. for (s32 i = 0; i < 8; i++) { - v3s16 blockpos = getNodeBlockPos(nodepos); + v3BPOS blockpos = getNodeBlockPos(nodepos); map.emergeBlock(blockpos, true); content_t c = map.getNode(nodepos).getContent(); diff --git a/src/server.h b/src/server.h index c5db0fdfb4..15a97dd323 100644 --- a/src/server.h +++ b/src/server.h @@ -372,7 +372,7 @@ class Server : public con::PeerHandler, public MapEventReceiver, ModChannel *getModChannel(const std::string &channel); // Send block to specific player only - bool SendBlock(session_t peer_id, const v3s16 &blockpos); + bool SendBlock(session_t peer_id, const v3POS &blockpos); // Get or load translations for a language Translations *getTranslationLanguage(const std::string &lang_code); @@ -425,7 +425,7 @@ class Server : public con::PeerHandler, public MapEventReceiver, u16 protocol_version); /* mark blocks not sent for all clients */ - void SetBlocksNotSent(std::map& block); + void SetBlocksNotSent(std::map& block); virtual void SendChatMessage(session_t peer_id, const ChatMessage &message); @@ -460,13 +460,13 @@ class Server : public con::PeerHandler, public MapEventReceiver, far_d_nodes are ignored and their peer_ids are added to far_players */ // Envlock and conlock should be locked when calling these - void sendRemoveNode(v3s16 p, std::unordered_set *far_players = nullptr, + void sendRemoveNode(v3POS p, std::unordered_set *far_players = nullptr, float far_d_nodes = 100); - void sendAddNode(v3s16 p, MapNode n, + void sendAddNode(v3POS p, MapNode n, std::unordered_set *far_players = nullptr, float far_d_nodes = 100, bool remove_metadata = true); - void sendMetadataChanged(const std::list &meta_updates, + void sendMetadataChanged(const std::list &meta_updates, float far_d_nodes = 100); // Environment and Connection must be locked when called diff --git a/src/server/player_sao.cpp b/src/server/player_sao.cpp index 83e17f8308..6b330639fd 100644 --- a/src/server/player_sao.cpp +++ b/src/server/player_sao.cpp @@ -155,7 +155,7 @@ void PlayerSAO::step(float dtime, bool send_recommended) { if (!isImmortal() && m_drowning_interval.step(dtime, 2.0f)) { // Get nose/mouth position, approximate with eye position - v3s16 p = floatToInt(getEyePosition(), BS); + v3POS p = floatToInt(getEyePosition(), BS); MapNode n = m_env->getMap().getNode(p); const ContentFeatures &c = m_env->getGameDef()->ndef()->get(n); // If node generates drown @@ -173,7 +173,7 @@ void PlayerSAO::step(float dtime, bool send_recommended) if (m_breathing_interval.step(dtime, 0.5f) && !isImmortal()) { // Get nose/mouth position, approximate with eye position - v3s16 p = floatToInt(getEyePosition(), BS); + v3POS p = floatToInt(getEyePosition(), BS); MapNode n = m_env->getMap().getNode(p); const ContentFeatures &c = m_env->getGameDef()->ndef()->get(n); // If player is alive & not drowning & not in ignore & not immortal, breathe @@ -191,7 +191,7 @@ void PlayerSAO::step(float dtime, bool send_recommended) // Sequence of damage points, starting 0.1 above feet and progressing // upwards in 1 node intervals, stopping below top damage point. for (float dam_height = 0.1f; dam_height < dam_top; dam_height++) { - v3s16 p = floatToInt(m_base_position + + v3POS p = floatToInt(m_base_position + v3f(0.0f, dam_height * BS, 0.0f), BS); MapNode n = m_env->getMap().getNode(p); const ContentFeatures &c = m_env->getGameDef()->ndef()->get(n); @@ -202,7 +202,7 @@ void PlayerSAO::step(float dtime, bool send_recommended) } // Top damage point - v3s16 ptop = floatToInt(m_base_position + + v3POS ptop = floatToInt(m_base_position + v3f(0.0f, dam_top * BS, 0.0f), BS); MapNode ntop = m_env->getMap().getNode(ptop); const ContentFeatures &c = m_env->getGameDef()->ndef()->get(ntop); @@ -339,7 +339,7 @@ void PlayerSAO::setPos(const v3f &pos) return; // Send mapblock of target location - v3s16 blockpos = v3s16(pos.X / MAP_BLOCKSIZE, pos.Y / MAP_BLOCKSIZE, pos.Z / MAP_BLOCKSIZE); + v3POS blockpos = v3POS(pos.X / MAP_BLOCKSIZE, pos.Y / MAP_BLOCKSIZE, pos.Z / MAP_BLOCKSIZE); m_env->getGameDef()->SendBlock(m_peer_id, blockpos); setBasePosition(pos); diff --git a/src/server/player_sao.h b/src/server/player_sao.h index 47fe85413b..1a0f8e33de 100644 --- a/src/server/player_sao.h +++ b/src/server/player_sao.h @@ -150,14 +150,14 @@ class PlayerSAO : public UnitSAO m_time_from_last_punch = 0.0; return r; } - void noCheatDigStart(const v3s16 &p) + void noCheatDigStart(const v3POS &p) { m_nocheat_dig_pos = p; m_nocheat_dig_time = 0; } - v3s16 getNoCheatDigPos() { return m_nocheat_dig_pos; } + v3POS getNoCheatDigPos() { return m_nocheat_dig_pos; } float getNoCheatDigTime() { return m_nocheat_dig_time; } - void noCheatDigEnd() { m_nocheat_dig_pos = v3s16(32767, 32767, 32767); } + void noCheatDigEnd() { m_nocheat_dig_pos = v3POS(32767, 32767, 32767); } LagPool &getDigPool() { return m_dig_pool; } void setMaxSpeedOverride(const v3f &vel); // Returns true if cheated @@ -197,7 +197,7 @@ class PlayerSAO : public UnitSAO v3f m_last_good_position; float m_time_from_last_teleport = 0.0f; float m_time_from_last_punch = 0.0f; - v3s16 m_nocheat_dig_pos = v3s16(32767, 32767, 32767); + v3POS m_nocheat_dig_pos = v3POS(32767, 32767, 32767); float m_nocheat_dig_time = 0.0f; float m_max_speed_override_time = 0.0f; v3f m_max_speed_override = v3f(0.0f, 0.0f, 0.0f); diff --git a/src/server/serveractiveobject.h b/src/server/serveractiveobject.h index 5b0ee2d9b3..b7957c274e 100644 --- a/src/server/serveractiveobject.h +++ b/src/server/serveractiveobject.h @@ -233,7 +233,7 @@ class ServerActiveObject : public ActiveObject The block from which the object was loaded from, and in which a copy of the static data resides. */ - v3s16 m_static_block = v3s16(1337,1337,1337); + v3POS m_static_block = v3POS(1337,1337,1337); protected: virtual void onMarkedForDeactivation() {} diff --git a/src/serverenvironment.cpp b/src/serverenvironment.cpp index f3711652ca..0c1ca25e6d 100644 --- a/src/serverenvironment.cpp +++ b/src/serverenvironment.cpp @@ -254,8 +254,8 @@ void LBMManager::applyLBMs(ServerEnvironment *env, MapBlock *block, u32 stamp) // Precondition, we need m_lbm_lookup to be initialized FATAL_ERROR_IF(!m_query_mode, "attempted to query on non fully set up LBMManager"); - v3s16 pos_of_block = block->getPosRelative(); - v3s16 pos; + v3POS pos_of_block = block->getPosRelative(); + v3POS pos; MapNode n; content_t c; lbm_lookup_map::const_iterator it = getLBMsIntroducedAfter(stamp); @@ -291,9 +291,9 @@ void LBMManager::applyLBMs(ServerEnvironment *env, MapBlock *block, u32 stamp) ActiveBlockList */ -void fillRadiusBlock(v3s16 p0, s16 r, std::set &list) +void fillRadiusBlock(v3POS p0, s16 r, std::set &list) { - v3s16 p; + v3POS p; for(p.X=p0.X-r; p.X<=p0.X+r; p.X++) for(p.Y=p0.Y-r; p.Y<=p0.Y+r; p.Y++) for(p.Z=p0.Z-r; p.Z<=p0.Z+r; p.Z++) @@ -306,14 +306,14 @@ void fillRadiusBlock(v3s16 p0, s16 r, std::set &list) } } -void fillViewConeBlock(v3s16 p0, +void fillViewConeBlock(v3POS p0, const s16 r, const v3f camera_pos, const v3f camera_dir, const float camera_fov, - std::set &list) + std::set &list) { - v3s16 p; + v3POS p; const s16 r_nodes = r * BS * MAP_BLOCKSIZE; for (p.X = p0.X - r; p.X <= p0.X+r; p.X++) for (p.Y = p0.Y - r; p.Y <= p0.Y+r; p.Y++) @@ -327,16 +327,16 @@ void fillViewConeBlock(v3s16 p0, void ActiveBlockList::update(std::vector &active_players, s16 active_block_range, s16 active_object_range, - std::set &blocks_removed, - std::set &blocks_added) + std::set &blocks_removed, + std::set &blocks_added) { /* Create the new list */ - std::set newlist = m_forceloaded_list; + std::set newlist = m_forceloaded_list; m_abm_list = m_forceloaded_list; for (const PlayerSAO *playersao : active_players) { - v3s16 pos = getNodeBlockPos(floatToInt(playersao->getBasePosition(), BS)); + v3BPOS pos = getNodeBlockPos(floatToInt(playersao->getBasePosition(), BS)); fillRadiusBlock(pos, active_block_range, m_abm_list); fillRadiusBlock(pos, active_block_range, newlist); @@ -359,7 +359,7 @@ void ActiveBlockList::update(std::vector &active_players, Find out which blocks on the old list are not on the new list */ // Go through old list - for (v3s16 p : m_list) { + for (v3POS p : m_list) { // If not on new list, it's been removed if (newlist.find(p) == newlist.end()) blocks_removed.insert(p); @@ -369,7 +369,7 @@ void ActiveBlockList::update(std::vector &active_players, Find out which blocks on the new list are not on the old list */ // Go through new list - for (v3s16 p : newlist) { + for (v3POS p : newlist) { // If not on old list, it's been added if(m_list.find(p) == m_list.end()) blocks_added.insert(p); @@ -379,7 +379,7 @@ void ActiveBlockList::update(std::vector &active_players, Update m_list */ m_list.clear(); - for (v3s16 p : newlist) { + for (v3POS p : newlist) { m_list.insert(p); } } @@ -729,8 +729,8 @@ struct ActiveABM int chance; std::vector required_neighbors; bool check_required_neighbors; // false if required_neighbors is known to be empty - s16 min_y; - s16 max_y; + POS min_y; + POS max_y; }; class ABMHandler @@ -822,7 +822,7 @@ class ABMHandler for(s16 z=-1; z<=1; z++) { MapBlock *block2 = map->getBlockNoCreateNoEx( - block->getPos() + v3s16(x,y,z)); + block->getPos() + v3POS(x,y,z)); if(block2==NULL){ wider_unknown_count++; continue; @@ -868,7 +868,7 @@ class ABMHandler u32 active_object_count = this->countObjects(block, map, active_object_count_wider); m_env->m_added_objects = 0; - v3s16 p0; + v3POS p0; for(p0.X=0; p0.X= m_aabms.size() || !m_aabms[c]) continue; - v3s16 p = p0 + block->getPosRelative(); + v3POS p = p0 + block->getPosRelative(); for (ActiveABM &aabm : *m_aabms[c]) { if ((p.Y < aabm.min_y) || (p.Y > aabm.max_y)) continue; @@ -898,7 +898,7 @@ class ABMHandler // Check neighbors if (aabm.check_required_neighbors) { - v3s16 p1; + v3POS p1; for(p1.X = p0.X-1; p1.X <= p0.X+1; p1.X++) for(p1.Y = p0.Y-1; p1.Y <= p0.Y+1; p1.Y++) for(p1.Z = p0.Z-1; p1.Z <= p0.Z+1; p1.Z++) @@ -986,7 +986,7 @@ void ServerEnvironment::activateBlock(MapBlock *block, u32 additional_dtime) MapNode n; for (const NodeTimer &elapsed_timer : elapsed_timers) { n = block->getNodeNoEx(elapsed_timer.position); - v3s16 p = elapsed_timer.position + block->getPosRelative(); + v3POS p = elapsed_timer.position + block->getPosRelative(); if (m_script->node_on_timer(p, n, elapsed_timer.elapsed)) block->setNodeTimer(NodeTimer(elapsed_timer.timeout, 0, elapsed_timer.position)); @@ -1004,7 +1004,7 @@ void ServerEnvironment::addLoadingBlockModifierDef(LoadingBlockModifierDef *lbm) m_lbm_mgr.addLBMDef(lbm); } -bool ServerEnvironment::setNode(v3s16 p, const MapNode &n) +bool ServerEnvironment::setNode(v3POS p, const MapNode &n) { const NodeDefManager *ndef = m_server->ndef(); MapNode n_old = m_map->getNode(p); @@ -1037,7 +1037,7 @@ bool ServerEnvironment::setNode(v3s16 p, const MapNode &n) return true; } -bool ServerEnvironment::removeNode(v3s16 p) +bool ServerEnvironment::removeNode(v3POS p) { const NodeDefManager *ndef = m_server->ndef(); MapNode n_old = m_map->getNode(p); @@ -1062,7 +1062,7 @@ bool ServerEnvironment::removeNode(v3s16 p) return true; } -bool ServerEnvironment::swapNode(v3s16 p, const MapNode &n) +bool ServerEnvironment::swapNode(v3POS p, const MapNode &n) { if (!m_map->addNodeWithEvent(p, n, false)) return false; @@ -1073,12 +1073,12 @@ bool ServerEnvironment::swapNode(v3s16 p, const MapNode &n) return true; } -u8 ServerEnvironment::findSunlight(v3s16 pos) const +u8 ServerEnvironment::findSunlight(v3POS pos) const { // Directions for neighbouring nodes with specified order - static const v3s16 dirs[] = { - v3s16(-1, 0, 0), v3s16(1, 0, 0), v3s16(0, 0, -1), v3s16(0, 0, 1), - v3s16(0, -1, 0), v3s16(0, 1, 0) + static const v3POS dirs[] = { + v3POS(-1, 0, 0), v3POS(1, 0, 0), v3POS(0, 0, -1), v3POS(0, 0, 1), + v3POS(0, -1, 0), v3POS(0, 1, 0) }; const NodeDefManager *ndef = m_server->ndef(); @@ -1087,7 +1087,7 @@ u8 ServerEnvironment::findSunlight(v3s16 pos) const u8 found_light = 0; struct stack_entry { - v3s16 pos; + v3POS pos; s16 dist; }; std::stack stack; @@ -1100,11 +1100,11 @@ u8 ServerEnvironment::findSunlight(v3s16 pos) const struct stack_entry e = stack.top(); stack.pop(); - v3s16 currentPos = e.pos; + v3POS currentPos = e.pos; s8 dist = e.dist + 1; - for (const v3s16& off : dirs) { - v3s16 neighborPos = currentPos + off; + for (const v3POS& off : dirs) { + v3POS neighborPos = currentPos + off; s64 neighborHash = MapDatabase::getBlockAsInteger(neighborPos); // Do not walk neighborPos multiple times unless the distance to the start @@ -1190,7 +1190,7 @@ void ServerEnvironment::clearObjects(ClearObjectsMode mode) m_ao_manager.clear(cb_removal); // Get list of loaded blocks - std::vector loaded_blocks; + std::vector loaded_blocks; infostream << "ServerEnvironment::clearObjects(): " << "Listing all loaded blocks" << std::endl; m_map->listAllLoadedBlocks(loaded_blocks); @@ -1199,7 +1199,7 @@ void ServerEnvironment::clearObjects(ClearObjectsMode mode) << loaded_blocks.size()< loadable_blocks; + std::vector loadable_blocks; if (mode == CLEAR_OBJECTS_MODE_FULL) { infostream << "ServerEnvironment::clearObjects(): " << "Listing all loadable blocks" << std::endl; @@ -1216,7 +1216,7 @@ void ServerEnvironment::clearObjects(ClearObjectsMode mode) << " blocks" << std::endl; // Grab a reference on each loaded block to avoid unloading it - for (v3s16 p : loaded_blocks) { + for (v3POS p : loaded_blocks) { MapBlock *block = m_map->getBlockNoCreateNoEx(p); assert(block != NULL); block->refGrab(); @@ -1234,7 +1234,7 @@ void ServerEnvironment::clearObjects(ClearObjectsMode mode) u32 num_objs_cleared = 0; for (auto i = loadable_blocks.begin(); i != loadable_blocks.end(); ++i) { - v3s16 p = *i; + v3POS p = *i; MapBlock *block = m_map->emergeBlock(p, false); if (!block) { errorstream << "ServerEnvironment::clearObjects(): " @@ -1269,7 +1269,7 @@ void ServerEnvironment::clearObjects(ClearObjectsMode mode) m_map->unloadUnreferencedBlocks(); // Drop references that were added above - for (v3s16 p : loaded_blocks) { + for (v3POS p : loaded_blocks) { MapBlock *block = m_map->getBlockNoCreateNoEx(p); assert(block); block->refDrop(); @@ -1349,8 +1349,8 @@ void ServerEnvironment::step(float dtime) g_settings->getS16("active_object_send_range_blocks"); static thread_local const s16 active_block_range = g_settings->getS16("active_block_range"); - std::set blocks_removed; - std::set blocks_added; + std::set blocks_removed; + std::set blocks_added; m_active_blocks.update(players, active_block_range, active_object_range, blocks_removed, blocks_added); @@ -1361,7 +1361,7 @@ void ServerEnvironment::step(float dtime) // Convert active objects that are no more in active blocks to static deactivateFarObjects(false); - for (const v3s16 &p: blocks_removed) { + for (const v3POS &p: blocks_removed) { MapBlock *block = m_map->getBlockNoCreateNoEx(p); if (!block) continue; @@ -1374,7 +1374,7 @@ void ServerEnvironment::step(float dtime) Handle added blocks */ - for (const v3s16 &p: blocks_added) { + for (const v3POS &p: blocks_added) { MapBlock *block = m_map->getBlockOrEmerge(p); if (!block) { m_active_blocks.m_list.erase(p); @@ -1394,7 +1394,7 @@ void ServerEnvironment::step(float dtime) float dtime = m_cache_nodetimer_interval; - for (const v3s16 &p: m_active_blocks.m_list) { + for (const v3POS &p: m_active_blocks.m_list) { MapBlock *block = m_map->getBlockNoCreateNoEx(p); if (!block) continue; @@ -1414,7 +1414,7 @@ void ServerEnvironment::step(float dtime) std::vector elapsed_timers = block->m_node_timers.step(dtime); if (!elapsed_timers.empty()) { MapNode n; - v3s16 p2; + v3POS p2; for (const NodeTimer &elapsed_timer: elapsed_timers) { n = block->getNodeNoEx(elapsed_timer.position); p2 = elapsed_timer.position + block->getPosRelative(); @@ -1438,7 +1438,7 @@ void ServerEnvironment::step(float dtime) int abms_run = 0; int blocks_cached = 0; - std::vector output(m_active_blocks.m_abm_list.size()); + std::vector output(m_active_blocks.m_abm_list.size()); // Shuffle the active blocks so that each block gets an equal chance // of having its ABMs run. @@ -1448,7 +1448,7 @@ void ServerEnvironment::step(float dtime) int i = 0; // determine the time budget for ABMs u32 max_time_ms = m_cache_abm_interval * 1000 * m_cache_abm_time_budget; - for (const v3s16 &p : output) { + for (const v3POS &p : output) { MapBlock *block = m_map->getBlockNoCreateNoEx(p); if (!block) continue; @@ -1550,7 +1550,7 @@ void ServerEnvironment::step(float dtime) m_server->sendDetachedInventories(PEER_ID_INEXISTENT, true); } -ServerEnvironment::BlockStatus ServerEnvironment::getBlockStatus(v3s16 blockpos) +ServerEnvironment::BlockStatus ServerEnvironment::getBlockStatus(v3BPOS blockpos) { if (m_active_blocks.contains(blockpos)) return BS_ACTIVE; @@ -1683,7 +1683,7 @@ void ServerEnvironment::getRemovedActiveObjects(PlayerSAO *playersao, s16 radius } void ServerEnvironment::setStaticForActiveObjectsInBlock( - v3s16 blockpos, bool static_exists, v3s16 static_block) + v3POS blockpos, bool static_exists, v3POS static_block) { MapBlock *block = m_map->getBlockNoCreateNoEx(blockpos); if (!block) @@ -1737,7 +1737,7 @@ void ServerEnvironment::getSelectedActiveObjects( selection_box.MaxEdge + pos); v3f current_intersection; - v3s16 current_normal; + v3POS current_normal; if (boxLineCollision(offsetted_box, shootline_on_map.start, line_vector, ¤t_intersection, ¤t_normal)) { objects.emplace_back( @@ -1769,7 +1769,7 @@ u16 ServerEnvironment::addActiveObjectRaw(ServerActiveObject *object, v3f objectpos = object->getBasePosition(); StaticObject s_obj(object, objectpos); // Add to the block where the object is located in - v3s16 blockpos = getNodeBlockPos(floatToInt(objectpos, BS)); + v3BPOS blockpos = getNodeBlockPos(floatToInt(objectpos, BS)); MapBlock *block = m_map->emergeBlock(blockpos); if(block){ block->m_static_objects.m_active[object->getId()] = s_obj; @@ -1780,7 +1780,7 @@ u16 ServerEnvironment::addActiveObjectRaw(ServerActiveObject *object, block->raiseModified(MOD_STATE_WRITE_NEEDED, MOD_REASON_ADD_ACTIVE_OBJECT_RAW); } else { - v3s16 p = floatToInt(objectpos, BS); + v3POS p = floatToInt(objectpos, BS); errorstream<<"ServerEnvironment::addActiveObjectRaw(): " <<"could not emerge block for storing id="<getId() <<" statically (pos="<getBasePosition(); // The block in which the object resides in - v3s16 blockpos_o = getNodeBlockPos(floatToInt(objectpos, BS)); + v3BPOS blockpos_o = getNodeBlockPos(floatToInt(objectpos, BS)); // If object's static data is stored in a deactivated block and object // is actually located in an active block, re-save to the block in @@ -2085,7 +2085,7 @@ void ServerEnvironment::deactivateFarObjects(bool _force_delete) deleteStaticFromBlock(obj, id, reason, false); // Add to the block where the object is located in - v3s16 blockpos = getNodeBlockPos(floatToInt(objectpos, BS)); + v3BPOS blockpos = getNodeBlockPos(floatToInt(objectpos, BS)); u16 store_id = pending_delete ? id : 0; if (!saveStaticToBlock(blockpos, store_id, obj, s_obj, reason)) force_delete = true; @@ -2152,7 +2152,7 @@ void ServerEnvironment::deleteStaticFromBlock( } bool ServerEnvironment::saveStaticToBlock( - v3s16 blockpos, u16 store_id, + v3POS blockpos, u16 store_id, ServerActiveObject *obj, const StaticObject &s_obj, u32 mod_reason) { diff --git a/src/serverenvironment.h b/src/serverenvironment.h index 8733c2dd2e..bc628038b1 100644 --- a/src/serverenvironment.h +++ b/src/serverenvironment.h @@ -68,12 +68,12 @@ class ActiveBlockModifier // Whether to modify chance to simulate time lost by an unnattended block virtual bool getSimpleCatchUp() = 0; // get min Y for apply abm - virtual s16 getMinY() = 0; + virtual POS getMinY() = 0; // get max Y for apply abm - virtual s16 getMaxY() = 0; + virtual POS getMaxY() = 0; // This is called usually at interval for 1/chance of the nodes - virtual void trigger(ServerEnvironment *env, v3s16 p, MapNode n){}; - virtual void trigger(ServerEnvironment *env, v3s16 p, MapNode n, + virtual void trigger(ServerEnvironment *env, v3POS p, MapNode n){}; + virtual void trigger(ServerEnvironment *env, v3POS p, MapNode n, u32 active_object_count, u32 active_object_count_wider){}; }; @@ -94,7 +94,7 @@ struct LoadingBlockModifierDef virtual ~LoadingBlockModifierDef() = default; - virtual void trigger(ServerEnvironment *env, v3s16 p, MapNode n){}; + virtual void trigger(ServerEnvironment *env, v3POS p, MapNode n){}; }; struct LBMContentMapping @@ -164,10 +164,10 @@ class ActiveBlockList void update(std::vector &active_players, s16 active_block_range, s16 active_object_range, - std::set &blocks_removed, - std::set &blocks_added); + std::set &blocks_removed, + std::set &blocks_added); - bool contains(v3s16 p){ + bool contains(v3POS p){ return (m_list.find(p) != m_list.end()); } @@ -175,9 +175,9 @@ class ActiveBlockList m_list.clear(); } - std::set m_list; - std::set m_abm_list; - std::set m_forceloaded_list; + std::set m_list; + std::set m_abm_list; + std::set m_forceloaded_list; private: }; @@ -314,12 +314,12 @@ class ServerEnvironment : public Environment */ // Script-aware node setters - bool setNode(v3s16 p, const MapNode &n); - bool removeNode(v3s16 p); - bool swapNode(v3s16 p, const MapNode &n); + bool setNode(v3POS p, const MapNode &n); + bool removeNode(v3POS p); + bool swapNode(v3POS p, const MapNode &n); // Find the daylight value at pos with a Depth First Search - u8 findSunlight(v3s16 pos) const; + u8 findSunlight(v3POS pos) const; // Find all active objects inside a radius around a point void getObjectsInsideRadius(std::vector &objects, const v3f &pos, float radius, @@ -346,7 +346,7 @@ class ServerEnvironment : public Environment void reportMaxLagEstimate(float f) { m_max_lag_estimate = f; } float getMaxLagEstimate() { return m_max_lag_estimate; } - std::set* getForceloadedBlocks() { return &m_active_blocks.m_forceloaded_list; } + std::set* getForceloadedBlocks() { return &m_active_blocks.m_forceloaded_list; } // Sorted by how ready a mapblock is enum BlockStatus { @@ -355,12 +355,12 @@ class ServerEnvironment : public Environment BS_LOADED, BS_ACTIVE // always highest value }; - BlockStatus getBlockStatus(v3s16 blockpos); + BlockStatus getBlockStatus(v3POS blockpos); // Sets the static object status all the active objects in the specified block // This is only really needed for deleting blocks from the map - void setStaticForActiveObjectsInBlock(v3s16 blockpos, - bool static_exists, v3s16 static_block=v3s16(0,0,0)); + void setStaticForActiveObjectsInBlock(v3POS blockpos, + bool static_exists, v3POS static_block=v3POS(0,0,0)); RemotePlayer *getPlayer(const session_t peer_id); RemotePlayer *getPlayer(const char* name); @@ -427,7 +427,7 @@ class ServerEnvironment : public Environment */ void deleteStaticFromBlock( ServerActiveObject *obj, u16 id, u32 mod_reason, bool no_emerge); - bool saveStaticToBlock(v3s16 blockpos, u16 store_id, + bool saveStaticToBlock(v3POS blockpos, u16 store_id, ServerActiveObject *obj, const StaticObject &s_obj, u32 mod_reason); /* diff --git a/src/settings.cpp b/src/settings.cpp index cf7ec1b721..d17bbf92ee 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -527,6 +527,11 @@ s32 Settings::getS32(const std::string &name) const return stoi(get(name)); } +POS Settings::getPOS(const std::string &name) const +{ + return stoi(get(name)); +} + float Settings::getFloat(const std::string &name) const { @@ -772,6 +777,15 @@ bool Settings::getS32NoEx(const std::string &name, s32 &val) const } +bool Settings::getPOSNoEx(const std::string &name, POS &val) const +{ +#if USE_POS32 + return getS32NoEx(name, val); +#else + return getS16NoEx(name, val); +#endif +} + bool Settings::getU64NoEx(const std::string &name, u64 &val) const { try { @@ -907,6 +921,11 @@ bool Settings::setS32(const std::string &name, s32 value) return set(name, itos(value)); } +bool Settings::setPOS(const std::string &name, POS value) +{ + return set(name, itos(value)); +} + bool Settings::setU64(const std::string &name, u64 value) { diff --git a/src/settings.h b/src/settings.h index 4e32a34881..cd8a2117c9 100644 --- a/src/settings.h +++ b/src/settings.h @@ -163,6 +163,7 @@ class Settings { u32 getU32(const std::string &name) const; s32 getS32(const std::string &name) const; u64 getU64(const std::string &name) const; + POS getPOS(const std::string &name) const; float getFloat(const std::string &name) const; v2f getV2F(const std::string &name) const; v3f getV3F(const std::string &name) const; @@ -188,6 +189,7 @@ class Settings { bool getS16NoEx(const std::string &name, s16 &val) const; bool getU32NoEx(const std::string &name, u32 &val) const; bool getS32NoEx(const std::string &name, s32 &val) const; + bool getPOSNoEx(const std::string &name, POS &val) const; bool getU64NoEx(const std::string &name, u64 &val) const; bool getFloatNoEx(const std::string &name, float &val) const; bool getV2FNoEx(const std::string &name, v2f &val) const; @@ -216,6 +218,7 @@ class Settings { bool setU16(const std::string &name, u16 value); bool setS32(const std::string &name, s32 value); bool setU64(const std::string &name, u64 value); + bool setPOS(const std::string &name, POS value); bool setFloat(const std::string &name, float value); bool setV2F(const std::string &name, v2f value); bool setV3F(const std::string &name, v3f value); diff --git a/src/unittest/test.cpp b/src/unittest/test.cpp index af324e1b19..1eca5422db 100644 --- a/src/unittest/test.cpp +++ b/src/unittest/test.cpp @@ -356,18 +356,18 @@ struct TestMapBlock: public TestBase MapNode node; bool position_valid; - core::list validity_exceptions; + core::list validity_exceptions; TC() { position_valid = true; } - virtual bool isValidPosition(v3s16 p) + virtual bool isValidPosition(v3POS p) { //return position_valid ^ (p==position_valid_exception); bool exception = false; - for(core::list::Iterator i=validity_exceptions.begin(); + for(core::list::Iterator i=validity_exceptions.begin(); i != validity_exceptions.end(); i++) { if(p == *i) @@ -379,14 +379,14 @@ struct TestMapBlock: public TestBase return exception ? !position_valid : position_valid; } - virtual MapNode getNode(v3s16 p) + virtual MapNode getNode(v3POS p) { if(isValidPosition(p) == false) throw InvalidPositionException(); return node; } - virtual void setNode(v3s16 p, MapNode & n) + virtual void setNode(v3POS p, MapNode & n) { if(isValidPosition(p) == false) throw InvalidPositionException(); @@ -402,8 +402,8 @@ struct TestMapBlock: public TestBase { TC parent; - MapBlock b(&parent, v3s16(1,1,1)); - v3s16 relpos(MAP_BLOCKSIZE, MAP_BLOCKSIZE, MAP_BLOCKSIZE); + MapBlock b(&parent, v3POS(1,1,1)); + v3POS relpos(MAP_BLOCKSIZE, MAP_BLOCKSIZE, MAP_BLOCKSIZE); UASSERT(b.getPosRelative() == relpos); @@ -414,18 +414,18 @@ struct TestMapBlock: public TestBase UASSERT(b.getBox().MinEdge.Z == MAP_BLOCKSIZE); UASSERT(b.getBox().MaxEdge.Z == MAP_BLOCKSIZE*2-1); - UASSERT(b.isValidPosition(v3s16(0,0,0)) == true); - UASSERT(b.isValidPosition(v3s16(-1,0,0)) == false); - UASSERT(b.isValidPosition(v3s16(-1,-142,-2341)) == false); - UASSERT(b.isValidPosition(v3s16(-124,142,2341)) == false); - UASSERT(b.isValidPosition(v3s16(MAP_BLOCKSIZE-1,MAP_BLOCKSIZE-1,MAP_BLOCKSIZE-1)) == true); - UASSERT(b.isValidPosition(v3s16(MAP_BLOCKSIZE-1,MAP_BLOCKSIZE,MAP_BLOCKSIZE-1)) == false); + UASSERT(b.isValidPosition(v3POS(0,0,0)) == true); + UASSERT(b.isValidPosition(v3POS(-1,0,0)) == false); + UASSERT(b.isValidPosition(v3POS(-1,-142,-2341)) == false); + UASSERT(b.isValidPosition(v3POS(-124,142,2341)) == false); + UASSERT(b.isValidPosition(v3POS(MAP_BLOCKSIZE-1,MAP_BLOCKSIZE-1,MAP_BLOCKSIZE-1)) == true); + UASSERT(b.isValidPosition(v3POS(MAP_BLOCKSIZE-1,MAP_BLOCKSIZE,MAP_BLOCKSIZE-1)) == false); /* TODO: this method should probably be removed if the block size isn't going to be set variable */ - /*UASSERT(b.getSizeNodes() == v3s16(MAP_BLOCKSIZE, + /*UASSERT(b.getSizeNodes() == v3POS(MAP_BLOCKSIZE, MAP_BLOCKSIZE, MAP_BLOCKSIZE));*/ // Changed flag should be initially set @@ -439,10 +439,10 @@ struct TestMapBlock: public TestBase for(u16 y=0; y light_sources; + core::map light_sources; // The bottom block is invalid, because we have a shadowing node UASSERT(b.propagateSunlight(light_sources) == false); - UASSERT(b.getNode(v3s16(1,4,0)).getLight(LIGHTBANK_DAY) == LIGHT_SUN); - UASSERT(b.getNode(v3s16(1,3,0)).getLight(LIGHTBANK_DAY) == LIGHT_SUN); - UASSERT(b.getNode(v3s16(1,2,0)).getLight(LIGHTBANK_DAY) == 0); - UASSERT(b.getNode(v3s16(1,1,0)).getLight(LIGHTBANK_DAY) == 0); - UASSERT(b.getNode(v3s16(1,0,0)).getLight(LIGHTBANK_DAY) == 0); - UASSERT(b.getNode(v3s16(1,2,3)).getLight(LIGHTBANK_DAY) == LIGHT_SUN); - UASSERT(b.getFaceLight2(1000, p, v3s16(0,1,0)) == LIGHT_SUN); - UASSERT(b.getFaceLight2(1000, p, v3s16(0,-1,0)) == 0); - UASSERT(b.getFaceLight2(0, p, v3s16(0,-1,0)) == 0); + UASSERT(b.getNode(v3POS(1,4,0)).getLight(LIGHTBANK_DAY) == LIGHT_SUN); + UASSERT(b.getNode(v3POS(1,3,0)).getLight(LIGHTBANK_DAY) == LIGHT_SUN); + UASSERT(b.getNode(v3POS(1,2,0)).getLight(LIGHTBANK_DAY) == 0); + UASSERT(b.getNode(v3POS(1,1,0)).getLight(LIGHTBANK_DAY) == 0); + UASSERT(b.getNode(v3POS(1,0,0)).getLight(LIGHTBANK_DAY) == 0); + UASSERT(b.getNode(v3POS(1,2,3)).getLight(LIGHTBANK_DAY) == LIGHT_SUN); + UASSERT(b.getFaceLight2(1000, p, v3POS(0,1,0)) == LIGHT_SUN); + UASSERT(b.getFaceLight2(1000, p, v3POS(0,-1,0)) == 0); + UASSERT(b.getFaceLight2(0, p, v3POS(0,-1,0)) == 0); // According to MapBlock::getFaceLight, // The face on the z+ side should have double-diminished light - //UASSERT(b.getFaceLight(p, v3s16(0,0,1)) == diminish_light(diminish_light(LIGHT_MAX))); + //UASSERT(b.getFaceLight(p, v3POS(0,0,1)) == diminish_light(diminish_light(LIGHT_MAX))); // The face on the z+ side should have diminished light - UASSERT(b.getFaceLight2(1000, p, v3s16(0,0,1)) == diminish_light(LIGHT_MAX)); + UASSERT(b.getFaceLight2(1000, p, v3POS(0,0,1)) == diminish_light(LIGHT_MAX)); } /* Check how the block handles being in between blocks with some non-sunlight @@ -556,14 +556,14 @@ struct TestMapBlock: public TestBase parent.position_valid = true; b.setIsUnderground(true); parent.node.setLight(LIGHTBANK_DAY, LIGHT_MAX/2); - core::map light_sources; + core::map light_sources; // The block below should be valid because there shouldn't be // sunlight in there either UASSERT(b.propagateSunlight(light_sources, true) == true); // Should not touch nodes that are not affected (that is, all of them) - //UASSERT(b.getNode(v3s16(1,2,3)).getLight() == LIGHT_SUN); + //UASSERT(b.getNode(v3POS(1,2,3)).getLight() == LIGHT_SUN); // Should set light of non-sunlighted blocks to 0. - UASSERT(b.getNode(v3s16(1,2,3)).getLight(LIGHTBANK_DAY) == 0); + UASSERT(b.getNode(v3POS(1,2,3)).getLight(LIGHTBANK_DAY) == 0); } /* Set up a situation where: @@ -583,7 +583,7 @@ struct TestMapBlock: public TestBase MapNode n; n.setContent(CONTENT_AIR); n.setLight(LIGHTBANK_DAY, 0); - b.setNode(v3s16(x,y,z), n); + b.setNode(v3POS(x,y,z), n); } } } @@ -593,11 +593,11 @@ struct TestMapBlock: public TestBase for(u16 x=0; x light_sources; + core::map light_sources; // Bottom block is not valid UASSERT(b.propagateSunlight(light_sources) == false); } @@ -618,19 +618,19 @@ struct TestMapSector: public TestBase position_valid = true; } - virtual bool isValidPosition(v3s16 p) + virtual bool isValidPosition(v3POS p) { return position_valid; } - virtual MapNode getNode(v3s16 p) + virtual MapNode getNode(v3POS p) { if(position_valid == false) throw InvalidPositionException(); return node; } - virtual void setNode(v3s16 p, MapNode & n) + virtual void setNode(v3POS p, MapNode & n) { if(position_valid == false) throw InvalidPositionException(); @@ -648,7 +648,7 @@ struct TestMapSector: public TestBase parent.position_valid = false; // Create one with no heightmaps - ServerMapSector sector(&parent, v2s16(1,1)); + ServerMapSector sector(&parent, v2POS(1,1)); UASSERT(sector.getBlockNoCreateNoEx(0) == nullptr); UASSERT(sector.getBlockNoCreateNoEx(1) == nullptr); diff --git a/src/unittest/test_areastore.cpp b/src/unittest/test_areastore.cpp index 2af3ca90c7..7d09e56e5c 100644 --- a/src/unittest/test_areastore.cpp +++ b/src/unittest/test_areastore.cpp @@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "util/areastore.h" + class TestAreaStore : public TestBase { public: TestAreaStore() { TestManager::registerTestModule(this); } @@ -63,9 +64,9 @@ void TestAreaStore::testSpatialStore() void TestAreaStore::genericStoreTest(AreaStore *store) { - Area a(v3s16(-10, -3, 5), v3s16(0, 29, 7)); - Area b(v3s16(-5, -2, 5), v3s16(0, 28, 6)); - Area c(v3s16(-7, -3, 6), v3s16(-1, 27, 7)); + Area a(v3POS(-10, -3, 5), v3POS(0, 29, 7)); + Area b(v3POS(-5, -2, 5), v3POS(0, 28, 6)); + Area c(v3POS(-7, -3, 6), v3POS(-1, 27, 7)); std::vector res; UASSERTEQ(size_t, store->size(), 0); @@ -75,34 +76,34 @@ void TestAreaStore::genericStoreTest(AreaStore *store) store->insertArea(&c); UASSERTEQ(size_t, store->size(), 3); - store->getAreasForPos(&res, v3s16(-1, 0, 6)); + store->getAreasForPos(&res, v3POS(-1, 0, 6)); UASSERTEQ(size_t, res.size(), 3); res.clear(); - store->getAreasForPos(&res, v3s16(0, 0, 7)); + store->getAreasForPos(&res, v3POS(0, 0, 7)); UASSERTEQ(size_t, res.size(), 1); res.clear(); store->removeArea(a.id); - store->getAreasForPos(&res, v3s16(0, 0, 7)); + store->getAreasForPos(&res, v3POS(0, 0, 7)); UASSERTEQ(size_t, res.size(), 0); res.clear(); store->insertArea(&a); - store->getAreasForPos(&res, v3s16(0, 0, 7)); + store->getAreasForPos(&res, v3POS(0, 0, 7)); UASSERTEQ(size_t, res.size(), 1); res.clear(); - store->getAreasInArea(&res, v3s16(-10, -3, 5), v3s16(0, 29, 7), false); + store->getAreasInArea(&res, v3POS(-10, -3, 5), v3POS(0, 29, 7), false); UASSERTEQ(size_t, res.size(), 3); res.clear(); - store->getAreasInArea(&res, v3s16(-100, 0, 6), v3s16(200, 0, 6), false); + store->getAreasInArea(&res, v3POS(-100, 0, 6), v3POS(200, 0, 6), false); UASSERTEQ(size_t, res.size(), 0); res.clear(); - store->getAreasInArea(&res, v3s16(-100, 0, 6), v3s16(200, 0, 6), true); + store->getAreasInArea(&res, v3POS(-100, 0, 6), v3POS(200, 0, 6), true); UASSERTEQ(size_t, res.size(), 3); res.clear(); @@ -110,11 +111,11 @@ void TestAreaStore::genericStoreTest(AreaStore *store) store->removeArea(b.id); store->removeArea(c.id); - Area d(v3s16(-100, -300, -200), v3s16(-50, -200, -100)); + Area d(v3POS(-100, -300, -200), v3POS(-50, -200, -100)); d.data = "Hi!"; store->insertArea(&d); - store->getAreasForPos(&res, v3s16(-75, -250, -150)); + store->getAreasForPos(&res, v3POS(-75, -250, -150)); UASSERTEQ(size_t, res.size(), 1); UASSERTEQ(u16, res[0]->data.size(), 3); UASSERT(strncmp(res[0]->data.c_str(), "Hi!", 3) == 0); @@ -127,11 +128,11 @@ void TestAreaStore::testSerialization() { VectorAreaStore store; - Area a(v3s16(-1, 0, 1), v3s16(0, 1, 2)); + Area a(v3POS(-1, 0, 1), v3POS(0, 1, 2)); a.data = "Area AA"; store.insertArea(&a); - Area b(v3s16(123, 456, 789), v3s16(32000, 100, 10)); + Area b(v3POS(123, 456, 789), v3POS(32000, 100, 10)); b.data = "Area BB"; store.insertArea(&b); @@ -139,6 +140,23 @@ void TestAreaStore::testSerialization() store.serialize(os); std::string str = os.str(); +#if USE_POS32 + std::string str_wanted("\x00" // Version + "\x00\x02" // Count + "\x00\x00\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x01" // Area A min edge + "\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x02" // Area A max edge + "\x00\x07" // Area A data length + "Area AA" // Area A data + "\x00\x00\x00\x7B\x00\x00\x00\x64\x00\x00\x00\x0A" // Area B min edge (last two swapped with max edge for sorting) + "\x00\x00\x7D\x00\x00\x00\x01\xC8\x00\x00\x03\x15" // Area B max edge (^) + "\x00\x07" // Area B data length + "Area BB" // Area B data + "\x00\x00\x00\x00" // ID A = 0 + "\x00\x00\x00\x01", // ID B = 1 + 1 + 2 + + (12 + 12 + 2 + 7) * 2 + // min/max edge, length, data + 2 * 4); // Area IDs +#else std::string str_wanted("\x00" // Version "\x00\x02" // Count "\xFF\xFF\x00\x00\x00\x01" // Area A min edge @@ -154,6 +172,7 @@ void TestAreaStore::testSerialization() 1 + 2 + (6 + 6 + 2 + 7) * 2 + // min/max edge, length, data 2 * 4); // Area IDs +#endif UASSERTEQ(const std::string &, str, str_wanted); @@ -164,7 +183,7 @@ void TestAreaStore::testSerialization() // But existing IDs are overridden UASSERTEQ(size_t, store.size(), 2); - Area c(v3s16(33, -2, -6), v3s16(4, 77, -76)); + Area c(v3POS(33, -2, -6), v3POS(4, 77, -76)); c.data = "Area CC"; store.insertArea(&c); diff --git a/src/unittest/test_schematic.cpp b/src/unittest/test_schematic.cpp index d2f027eb4c..bc8fc6d15e 100644 --- a/src/unittest/test_schematic.cpp +++ b/src/unittest/test_schematic.cpp @@ -60,7 +60,7 @@ void TestSchematic::runTests(IGameDef *gamedef) void TestSchematic::testMtsSerializeDeserialize(const NodeDefManager *ndef) { - static const v3s16 size(7, 6, 4); + static const v3POS size(7, 6, 4); static const u32 volume = size.X * size.Y * size.Z; std::stringstream ss(std::ios_base::binary | @@ -110,7 +110,7 @@ void TestSchematic::testMtsSerializeDeserialize(const NodeDefManager *ndef) void TestSchematic::testLuaTableSerialize(const NodeDefManager *ndef) { - static const v3s16 size(3, 3, 3); + static const v3POS size(3, 3, 3); static const u32 volume = size.X * size.Y * size.Z; Schematic schem; @@ -138,7 +138,7 @@ void TestSchematic::testLuaTableSerialize(const NodeDefManager *ndef) void TestSchematic::testFileSerializeDeserialize(const NodeDefManager *ndef) { - static const v3s16 size(3, 3, 3); + static const v3POS size(3, 3, 3); static const u32 volume = size.X * size.Y * size.Z; static const content_t content_map[] = { CONTENT_AIR, diff --git a/src/unittest/test_voxelalgorithms.cpp b/src/unittest/test_voxelalgorithms.cpp index 0ffd24b7d9..28321f5fcb 100644 --- a/src/unittest/test_voxelalgorithms.cpp +++ b/src/unittest/test_voxelalgorithms.cpp @@ -67,21 +67,21 @@ void TestVoxelAlgorithms::testVoxelLineIterator(const NodeDefManager *ndef) voxalgo::VoxelLineIterator iterator(l.start, l.getVector()); //Test the first voxel - v3s16 start_voxel = floatToInt(l.start, 1); + v3POS start_voxel = floatToInt(l.start, 1); UASSERT(iterator.m_current_node_pos == start_voxel); // Values for testing - v3s16 end_voxel = floatToInt(l.end, 1); - v3s16 voxel_vector = end_voxel - start_voxel; + v3POS end_voxel = floatToInt(l.end, 1); + v3POS voxel_vector = end_voxel - start_voxel; int nodecount = abs(voxel_vector.X) + abs(voxel_vector.Y) + abs(voxel_vector.Z); int actual_nodecount = 0; - v3s16 old_voxel = iterator.m_current_node_pos; + v3POS old_voxel = iterator.m_current_node_pos; while (iterator.hasNext()) { iterator.next(); actual_nodecount++; - v3s16 new_voxel = iterator.m_current_node_pos; + v3POS new_voxel = iterator.m_current_node_pos; // This must be a neighbor of the old voxel UASSERTEQ(f32, (new_voxel - old_voxel).getLengthSQ(), 1); // The line must intersect with the voxel diff --git a/src/unittest/test_voxelarea.cpp b/src/unittest/test_voxelarea.cpp index 9826d2ee78..b046dfa13d 100644 --- a/src/unittest/test_voxelarea.cpp +++ b/src/unittest/test_voxelarea.cpp @@ -46,14 +46,14 @@ class TestVoxelArea : public TestBase void test_index_xyz_xz_neg(); void test_index_xyz_yz_neg(); void test_index_xyz_all_neg(); - void test_index_v3s16_all_pos(); - void test_index_v3s16_x_neg(); - void test_index_v3s16_y_neg(); - void test_index_v3s16_z_neg(); - void test_index_v3s16_xy_neg(); - void test_index_v3s16_xz_neg(); - void test_index_v3s16_yz_neg(); - void test_index_v3s16_all_neg(); + void test_index_v3POS_all_pos(); + void test_index_v3POS_x_neg(); + void test_index_v3POS_y_neg(); + void test_index_v3POS_z_neg(); + void test_index_v3POS_xy_neg(); + void test_index_v3POS_xz_neg(); + void test_index_v3POS_yz_neg(); + void test_index_v3POS_all_neg(); void test_add_x(); void test_add_y(); void test_add_z(); @@ -82,14 +82,14 @@ void TestVoxelArea::runTests(IGameDef *gamedef) TEST(test_index_xyz_xz_neg); TEST(test_index_xyz_yz_neg); TEST(test_index_xyz_all_neg); - TEST(test_index_v3s16_all_pos); - TEST(test_index_v3s16_x_neg); - TEST(test_index_v3s16_y_neg); - TEST(test_index_v3s16_z_neg); - TEST(test_index_v3s16_xy_neg); - TEST(test_index_v3s16_xz_neg); - TEST(test_index_v3s16_yz_neg); - TEST(test_index_v3s16_all_neg); + TEST(test_index_v3POS_all_pos); + TEST(test_index_v3POS_x_neg); + TEST(test_index_v3POS_y_neg); + TEST(test_index_v3POS_z_neg); + TEST(test_index_v3POS_xy_neg); + TEST(test_index_v3POS_xz_neg); + TEST(test_index_v3POS_yz_neg); + TEST(test_index_v3POS_all_neg); TEST(test_add_x); TEST(test_add_y); TEST(test_add_z); @@ -98,81 +98,81 @@ void TestVoxelArea::runTests(IGameDef *gamedef) void TestVoxelArea::test_addarea() { - VoxelArea v1(v3s16(-1447, 8854, -875), v3s16(-147, -9547, 669)); - VoxelArea v2(v3s16(-887, 4445, -5478), v3s16(447, -8779, 4778)); + VoxelArea v1(v3POS(-1447, 8854, -875), v3POS(-147, -9547, 669)); + VoxelArea v2(v3POS(-887, 4445, -5478), v3POS(447, -8779, 4778)); v1.addArea(v2); - UASSERT(v1.MinEdge == v3s16(-1447, 4445, -5478)); - UASSERT(v1.MaxEdge == v3s16(447, -8779, 4778)); + UASSERT(v1.MinEdge == v3POS(-1447, 4445, -5478)); + UASSERT(v1.MaxEdge == v3POS(447, -8779, 4778)); } void TestVoxelArea::test_pad() { - VoxelArea v1(v3s16(-1447, 8854, -875), v3s16(-147, -9547, 669)); - v1.pad(v3s16(100, 200, 300)); + VoxelArea v1(v3POS(-1447, 8854, -875), v3POS(-147, -9547, 669)); + v1.pad(v3POS(100, 200, 300)); - UASSERT(v1.MinEdge == v3s16(-1547, 8654, -1175)); - UASSERT(v1.MaxEdge == v3s16(-47, -9347, 969)); + UASSERT(v1.MinEdge == v3POS(-1547, 8654, -1175)); + UASSERT(v1.MaxEdge == v3POS(-47, -9347, 969)); } void TestVoxelArea::test_extent() { - VoxelArea v1(v3s16(-1337, -547, -789), v3s16(-147, 447, 669)); - UASSERT(v1.getExtent() == v3s16(1191, 995, 1459)); + VoxelArea v1(v3POS(-1337, -547, -789), v3POS(-147, 447, 669)); + UASSERT(v1.getExtent() == v3POS(1191, 995, 1459)); - VoxelArea v2(v3s16(32493, -32507, 32753), v3s16(32508, -32492, 32768)); - UASSERT(v2.getExtent() == v3s16(16, 16, 16)); + VoxelArea v2(v3POS(32493, -32507, 32753), v3POS(32508, -32492, 32768)); + UASSERT(v2.getExtent() == v3POS(16, 16, 16)); } void TestVoxelArea::test_volume() { - VoxelArea v1(v3s16(-1337, -547, -789), v3s16(-147, 447, 669)); + VoxelArea v1(v3POS(-1337, -547, -789), v3POS(-147, 447, 669)); UASSERTEQ(s32, v1.getVolume(), 1728980655); - VoxelArea v2(v3s16(32493, -32507, 32753), v3s16(32508, -32492, 32768)); + VoxelArea v2(v3POS(32493, -32507, 32753), v3POS(32508, -32492, 32768)); UASSERTEQ(s32, v2.getVolume(), 4096); } void TestVoxelArea::test_contains_voxelarea() { - VoxelArea v1(v3s16(-1337, -9547, -789), v3s16(-147, 750, 669)); - UASSERTEQ(bool, v1.contains(VoxelArea(v3s16(-200, 10, 10), v3s16(-150, 10, 10))), + VoxelArea v1(v3POS(-1337, -9547, -789), v3POS(-147, 750, 669)); + UASSERTEQ(bool, v1.contains(VoxelArea(v3POS(-200, 10, 10), v3POS(-150, 10, 10))), true); - UASSERTEQ(bool, v1.contains(VoxelArea(v3s16(-2550, 10, 10), v3s16(10, 10, 10))), + UASSERTEQ(bool, v1.contains(VoxelArea(v3POS(-2550, 10, 10), v3POS(10, 10, 10))), false); - UASSERTEQ(bool, v1.contains(VoxelArea(v3s16(-10, 10, 10), v3s16(3500, 10, 10))), + UASSERTEQ(bool, v1.contains(VoxelArea(v3POS(-10, 10, 10), v3POS(3500, 10, 10))), false); UASSERTEQ(bool, v1.contains(VoxelArea( - v3s16(-800, -400, 669), v3s16(-500, 200, 669))), + v3POS(-800, -400, 669), v3POS(-500, 200, 669))), true); UASSERTEQ(bool, v1.contains(VoxelArea( - v3s16(-800, -400, 670), v3s16(-500, 200, 670))), + v3POS(-800, -400, 670), v3POS(-500, 200, 670))), false); } void TestVoxelArea::test_contains_point() { - VoxelArea v1(v3s16(-1337, -9547, -789), v3s16(-147, 750, 669)); - UASSERTEQ(bool, v1.contains(v3s16(-200, 10, 10)), true); - UASSERTEQ(bool, v1.contains(v3s16(-10000, 10, 10)), false); - UASSERTEQ(bool, v1.contains(v3s16(-100, 10000, 10)), false); - UASSERTEQ(bool, v1.contains(v3s16(-100, 100, 10000)), false); - UASSERTEQ(bool, v1.contains(v3s16(-100, 100, -10000)), false); - UASSERTEQ(bool, v1.contains(v3s16(10000, 100, 10)), false); + VoxelArea v1(v3POS(-1337, -9547, -789), v3POS(-147, 750, 669)); + UASSERTEQ(bool, v1.contains(v3POS(-200, 10, 10)), true); + UASSERTEQ(bool, v1.contains(v3POS(-10000, 10, 10)), false); + UASSERTEQ(bool, v1.contains(v3POS(-100, 10000, 10)), false); + UASSERTEQ(bool, v1.contains(v3POS(-100, 100, 10000)), false); + UASSERTEQ(bool, v1.contains(v3POS(-100, 100, -10000)), false); + UASSERTEQ(bool, v1.contains(v3POS(10000, 100, 10)), false); } void TestVoxelArea::test_contains_i() { - VoxelArea v1(v3s16(-1337, -9547, -789), v3s16(-147, 750, 669)); + VoxelArea v1(v3POS(-1337, -9547, -789), v3POS(-147, 750, 669)); UASSERTEQ(bool, v1.contains(10), true); UASSERTEQ(bool, v1.contains(v1.getVolume()), false); UASSERTEQ(bool, v1.contains(v1.getVolume() - 1), true); UASSERTEQ(bool, v1.contains(v1.getVolume() + 1), false); UASSERTEQ(bool, v1.contains(-1), false) - VoxelArea v2(v3s16(10, 10, 10), v3s16(30, 30, 30)); + VoxelArea v2(v3POS(10, 10, 10), v3POS(30, 30, 30)); UASSERTEQ(bool, v2.contains(10), true); UASSERTEQ(bool, v2.contains(0), true); UASSERTEQ(bool, v2.contains(-1), false); @@ -180,34 +180,34 @@ void TestVoxelArea::test_contains_i() void TestVoxelArea::test_equal() { - VoxelArea v1(v3s16(-1337, -9547, -789), v3s16(-147, 750, 669)); - UASSERTEQ(bool, v1 == VoxelArea(v3s16(-1337, -9547, -789), v3s16(-147, 750, 669)), + VoxelArea v1(v3POS(-1337, -9547, -789), v3POS(-147, 750, 669)); + UASSERTEQ(bool, v1 == VoxelArea(v3POS(-1337, -9547, -789), v3POS(-147, 750, 669)), true); - UASSERTEQ(bool, v1 == VoxelArea(v3s16(0, 0, 0), v3s16(-147, 750, 669)), false); - UASSERTEQ(bool, v1 == VoxelArea(v3s16(0, 0, 0), v3s16(-147, 750, 669)), false); - UASSERTEQ(bool, v1 == VoxelArea(v3s16(0, 0, 0), v3s16(0, 0, 0)), false); + UASSERTEQ(bool, v1 == VoxelArea(v3POS(0, 0, 0), v3POS(-147, 750, 669)), false); + UASSERTEQ(bool, v1 == VoxelArea(v3POS(0, 0, 0), v3POS(-147, 750, 669)), false); + UASSERTEQ(bool, v1 == VoxelArea(v3POS(0, 0, 0), v3POS(0, 0, 0)), false); } void TestVoxelArea::test_plus() { - VoxelArea v1(v3s16(-10, -10, -10), v3s16(100, 100, 100)); - UASSERT(v1 + v3s16(10, 0, 0) == - VoxelArea(v3s16(0, -10, -10), v3s16(110, 100, 100))); - UASSERT(v1 + v3s16(10, -10, 0) == - VoxelArea(v3s16(0, -20, -10), v3s16(110, 90, 100))); - UASSERT(v1 + v3s16(0, 0, 35) == - VoxelArea(v3s16(-10, -10, 25), v3s16(100, 100, 135))); + VoxelArea v1(v3POS(-10, -10, -10), v3POS(100, 100, 100)); + UASSERT(v1 + v3POS(10, 0, 0) == + VoxelArea(v3POS(0, -10, -10), v3POS(110, 100, 100))); + UASSERT(v1 + v3POS(10, -10, 0) == + VoxelArea(v3POS(0, -20, -10), v3POS(110, 90, 100))); + UASSERT(v1 + v3POS(0, 0, 35) == + VoxelArea(v3POS(-10, -10, 25), v3POS(100, 100, 135))); } void TestVoxelArea::test_minor() { - VoxelArea v1(v3s16(-10, -10, -10), v3s16(100, 100, 100)); - UASSERT(v1 - v3s16(10, 0, 0) == - VoxelArea(v3s16(-20, -10, -10), v3s16(90, 100, 100))); - UASSERT(v1 - v3s16(10, -10, 0) == - VoxelArea(v3s16(-20, 0, -10), v3s16(90, 110, 100))); - UASSERT(v1 - v3s16(0, 0, 35) == - VoxelArea(v3s16(-10, -10, -45), v3s16(100, 100, 65))); + VoxelArea v1(v3POS(-10, -10, -10), v3POS(100, 100, 100)); + UASSERT(v1 - v3POS(10, 0, 0) == + VoxelArea(v3POS(-20, -10, -10), v3POS(90, 100, 100))); + UASSERT(v1 - v3POS(10, -10, 0) == + VoxelArea(v3POS(-20, 0, -10), v3POS(90, 110, 100))); + UASSERT(v1 - v3POS(0, 0, 35) == + VoxelArea(v3POS(-10, -10, -45), v3POS(100, 100, 65))); } void TestVoxelArea::test_index_xyz_all_pos() @@ -215,7 +215,7 @@ void TestVoxelArea::test_index_xyz_all_pos() VoxelArea v1; UASSERTEQ(s32, v1.index(156, 25, 236), 155); - VoxelArea v2(v3s16(756, 8854, -875), v3s16(-147, -9547, 669)); + VoxelArea v2(v3POS(756, 8854, -875), v3POS(-147, -9547, 669)); UASSERTEQ(s32, v2.index(156, 25, 236), 1267138774); } @@ -224,7 +224,7 @@ void TestVoxelArea::test_index_xyz_x_neg() VoxelArea v1; UASSERTEQ(s32, v1.index(-147, 25, 366), -148); - VoxelArea v2(v3s16(756, 8854, -875), v3s16(-147, -9547, 669)); + VoxelArea v2(v3POS(756, 8854, -875), v3POS(-147, -9547, 669)); UASSERTEQ(s32, v2.index(-147, 25, 366), -870244825); } @@ -233,7 +233,7 @@ void TestVoxelArea::test_index_xyz_y_neg() VoxelArea v1; UASSERTEQ(s32, v1.index(247, -269, 100), 246); - VoxelArea v2(v3s16(756, 8854, -875), v3s16(-147, -9547, 669)); + VoxelArea v2(v3POS(756, 8854, -875), v3POS(-147, -9547, 669)); UASSERTEQ(s32, v2.index(247, -269, 100), -989760747); } @@ -242,7 +242,7 @@ void TestVoxelArea::test_index_xyz_z_neg() VoxelArea v1; UASSERTEQ(s32, v1.index(244, 336, -887), 243); - VoxelArea v2(v3s16(756, 8854, -875), v3s16(-147, -9547, 669)); + VoxelArea v2(v3POS(756, 8854, -875), v3POS(-147, -9547, 669)); UASSERTEQ(s32, v2.index(244, 336, -887), -191478876); } @@ -251,7 +251,7 @@ void TestVoxelArea::test_index_xyz_xy_neg() VoxelArea v1; UASSERTEQ(s32, v1.index(-365, -47, 6978), -366); - VoxelArea v2(v3s16(756, 8854, -875), v3s16(-147, -9547, 669)); + VoxelArea v2(v3POS(756, 8854, -875), v3POS(-147, -9547, 669)); UASSERTEQ(s32, v2.index(-365, -47, 6978), 1493679101); } @@ -260,7 +260,7 @@ void TestVoxelArea::test_index_xyz_yz_neg() VoxelArea v1; UASSERTEQ(s32, v1.index(66, -58, -789), 65); - VoxelArea v2(v3s16(756, 8854, -875), v3s16(-147, -9547, 669)); + VoxelArea v2(v3POS(756, 8854, -875), v3POS(-147, -9547, 669)); UASSERTEQ(s32, v2.index(66, -58, -789), 1435362734); } @@ -269,7 +269,7 @@ void TestVoxelArea::test_index_xyz_xz_neg() VoxelArea v1; UASSERTEQ(s32, v1.index(-36, 589, -992), -37); - VoxelArea v2(v3s16(756, 8854, -875), v3s16(-147, -9547, 669)); + VoxelArea v2(v3POS(756, 8854, -875), v3POS(-147, -9547, 669)); UASSERTEQ(s32, v2.index(-36, 589, -992), -1934371362); } @@ -278,85 +278,85 @@ void TestVoxelArea::test_index_xyz_all_neg() VoxelArea v1; UASSERTEQ(s32, v1.index(-88, -99, -1474), -89); - VoxelArea v2(v3s16(756, 8854, -875), v3s16(-147, -9547, 669)); + VoxelArea v2(v3POS(756, 8854, -875), v3POS(-147, -9547, 669)); UASSERTEQ(s32, v2.index(-88, -99, -1474), -1343473846); } -void TestVoxelArea::test_index_v3s16_all_pos() +void TestVoxelArea::test_index_v3POS_all_pos() { VoxelArea v1; - UASSERTEQ(s32, v1.index(v3s16(156, 25, 236)), 155); + UASSERTEQ(s32, v1.index(v3POS(156, 25, 236)), 155); - VoxelArea v2(v3s16(756, 8854, -875), v3s16(-147, -9547, 669)); - UASSERTEQ(s32, v2.index(v3s16(156, 25, 236)), 1267138774); + VoxelArea v2(v3POS(756, 8854, -875), v3POS(-147, -9547, 669)); + UASSERTEQ(s32, v2.index(v3POS(156, 25, 236)), 1267138774); } -void TestVoxelArea::test_index_v3s16_x_neg() +void TestVoxelArea::test_index_v3POS_x_neg() { VoxelArea v1; - UASSERTEQ(s32, v1.index(v3s16(-147, 25, 366)), -148); + UASSERTEQ(s32, v1.index(v3POS(-147, 25, 366)), -148); - VoxelArea v2(v3s16(756, 8854, -875), v3s16(-147, -9547, 669)); - UASSERTEQ(s32, v2.index(v3s16(-147, 25, 366)), -870244825); + VoxelArea v2(v3POS(756, 8854, -875), v3POS(-147, -9547, 669)); + UASSERTEQ(s32, v2.index(v3POS(-147, 25, 366)), -870244825); } -void TestVoxelArea::test_index_v3s16_y_neg() +void TestVoxelArea::test_index_v3POS_y_neg() { VoxelArea v1; - UASSERTEQ(s32, v1.index(v3s16(247, -269, 100)), 246); + UASSERTEQ(s32, v1.index(v3POS(247, -269, 100)), 246); - VoxelArea v2(v3s16(756, 8854, -875), v3s16(-147, -9547, 669)); - UASSERTEQ(s32, v2.index(v3s16(247, -269, 100)), -989760747); + VoxelArea v2(v3POS(756, 8854, -875), v3POS(-147, -9547, 669)); + UASSERTEQ(s32, v2.index(v3POS(247, -269, 100)), -989760747); } -void TestVoxelArea::test_index_v3s16_z_neg() +void TestVoxelArea::test_index_v3POS_z_neg() { VoxelArea v1; - UASSERTEQ(s32, v1.index(v3s16(244, 336, -887)), 243); + UASSERTEQ(s32, v1.index(v3POS(244, 336, -887)), 243); - VoxelArea v2(v3s16(756, 8854, -875), v3s16(-147, -9547, 669)); - UASSERTEQ(s32, v2.index(v3s16(244, 336, -887)), -191478876); + VoxelArea v2(v3POS(756, 8854, -875), v3POS(-147, -9547, 669)); + UASSERTEQ(s32, v2.index(v3POS(244, 336, -887)), -191478876); } -void TestVoxelArea::test_index_v3s16_xy_neg() +void TestVoxelArea::test_index_v3POS_xy_neg() { VoxelArea v1; - UASSERTEQ(s32, v1.index(v3s16(-365, -47, 6978)), -366); + UASSERTEQ(s32, v1.index(v3POS(-365, -47, 6978)), -366); - VoxelArea v2(v3s16(756, 8854, -875), v3s16(-147, -9547, 669)); - UASSERTEQ(s32, v2.index(v3s16(-365, -47, 6978)), 1493679101); + VoxelArea v2(v3POS(756, 8854, -875), v3POS(-147, -9547, 669)); + UASSERTEQ(s32, v2.index(v3POS(-365, -47, 6978)), 1493679101); } -void TestVoxelArea::test_index_v3s16_yz_neg() +void TestVoxelArea::test_index_v3POS_yz_neg() { VoxelArea v1; - UASSERTEQ(s32, v1.index(v3s16(66, -58, -789)), 65); + UASSERTEQ(s32, v1.index(v3POS(66, -58, -789)), 65); - VoxelArea v2(v3s16(756, 8854, -875), v3s16(-147, -9547, 669)); - UASSERTEQ(s32, v2.index(v3s16(66, -58, -789)), 1435362734); + VoxelArea v2(v3POS(756, 8854, -875), v3POS(-147, -9547, 669)); + UASSERTEQ(s32, v2.index(v3POS(66, -58, -789)), 1435362734); } -void TestVoxelArea::test_index_v3s16_xz_neg() +void TestVoxelArea::test_index_v3POS_xz_neg() { VoxelArea v1; - UASSERTEQ(s32, v1.index(v3s16(-36, 589, -992)), -37); + UASSERTEQ(s32, v1.index(v3POS(-36, 589, -992)), -37); - VoxelArea v2(v3s16(756, 8854, -875), v3s16(-147, -9547, 669)); - UASSERTEQ(s32, v2.index(v3s16(-36, 589, -992)), -1934371362); + VoxelArea v2(v3POS(756, 8854, -875), v3POS(-147, -9547, 669)); + UASSERTEQ(s32, v2.index(v3POS(-36, 589, -992)), -1934371362); } -void TestVoxelArea::test_index_v3s16_all_neg() +void TestVoxelArea::test_index_v3POS_all_neg() { VoxelArea v1; - UASSERTEQ(s32, v1.index(v3s16(-88, -99, -1474)), -89); + UASSERTEQ(s32, v1.index(v3POS(-88, -99, -1474)), -89); - VoxelArea v2(v3s16(756, 8854, -875), v3s16(-147, -9547, 669)); - UASSERTEQ(s32, v2.index(v3s16(-88, -99, -1474)), -1343473846); + VoxelArea v2(v3POS(756, 8854, -875), v3POS(-147, -9547, 669)); + UASSERTEQ(s32, v2.index(v3POS(-88, -99, -1474)), -1343473846); } void TestVoxelArea::test_add_x() { - v3s16 extent; + v3POS extent; u32 i = 4; VoxelArea::add_x(extent, i, 8); UASSERTEQ(u32, i, 12) @@ -364,7 +364,7 @@ void TestVoxelArea::test_add_x() void TestVoxelArea::test_add_y() { - v3s16 extent(740, 16, 87); + v3POS extent(740, 16, 87); u32 i = 8; VoxelArea::add_y(extent, i, 88); UASSERTEQ(u32, i, 65128) @@ -372,7 +372,7 @@ void TestVoxelArea::test_add_y() void TestVoxelArea::test_add_z() { - v3s16 extent(114, 80, 256); + v3POS extent(114, 80, 256); u32 i = 4; VoxelArea::add_z(extent, i, 8); UASSERTEQ(u32, i, 72964) @@ -380,8 +380,8 @@ void TestVoxelArea::test_add_z() void TestVoxelArea::test_add_p() { - v3s16 extent(33, 14, 742); - v3s16 a(15, 12, 369); + v3POS extent(33, 14, 742); + v3POS a(15, 12, 369); u32 i = 4; VoxelArea::add_p(extent, i, a); UASSERTEQ(u32, i, 170893) diff --git a/src/unittest/test_voxelmanipulator.cpp b/src/unittest/test_voxelmanipulator.cpp index acc2707e76..028119a57b 100644 --- a/src/unittest/test_voxelmanipulator.cpp +++ b/src/unittest/test_voxelmanipulator.cpp @@ -48,21 +48,21 @@ void TestVoxelManipulator::runTests(IGameDef *gamedef) void TestVoxelManipulator::testVoxelArea() { - VoxelArea a(v3s16(-1,-1,-1), v3s16(1,1,1)); + VoxelArea a(v3POS(-1,-1,-1), v3POS(1,1,1)); UASSERT(a.index(0,0,0) == 1*3*3 + 1*3 + 1); UASSERT(a.index(-1,-1,-1) == 0); - VoxelArea c(v3s16(-2,-2,-2), v3s16(2,2,2)); + VoxelArea c(v3POS(-2,-2,-2), v3POS(2,2,2)); // An area that is 1 bigger in x+ and z- - VoxelArea d(v3s16(-2,-2,-3), v3s16(3,2,2)); + VoxelArea d(v3POS(-2,-2,-3), v3POS(3,2,2)); std::list aa; d.diff(c, aa); // Correct results std::vector results; - results.emplace_back(v3s16(-2,-2,-3), v3s16(3,2,-3)); - results.emplace_back(v3s16(3,-2,-2), v3s16(3,2,2)); + results.emplace_back(v3POS(-2,-2,-3), v3POS(3,2,-3)); + results.emplace_back(v3POS(3,-2,-2), v3POS(3,2,2)); UASSERT(aa.size() == results.size()); @@ -87,22 +87,22 @@ void TestVoxelManipulator::testVoxelManipulator(const NodeDefManager *nodedef) v.print(infostream, nodedef); infostream << "*** Setting (-1,0,-1)=2 ***" << std::endl; - v.setNodeNoRef(v3s16(-1,0,-1), MapNode(t_CONTENT_GRASS)); + v.setNodeNoRef(v3POS(-1,0,-1), MapNode(t_CONTENT_GRASS)); v.print(infostream, nodedef); - UASSERT(v.getNode(v3s16(-1,0,-1)).getContent() == t_CONTENT_GRASS); + UASSERT(v.getNode(v3POS(-1,0,-1)).getContent() == t_CONTENT_GRASS); infostream << "*** Reading from inexistent (0,0,-1) ***" << std::endl; - EXCEPTION_CHECK(InvalidPositionException, v.getNode(v3s16(0,0,-1))); + EXCEPTION_CHECK(InvalidPositionException, v.getNode(v3POS(0,0,-1))); v.print(infostream, nodedef); infostream << "*** Adding area ***" << std::endl; - VoxelArea a(v3s16(-1,-1,-1), v3s16(1,1,1)); + VoxelArea a(v3POS(-1,-1,-1), v3POS(1,1,1)); v.addArea(a); v.print(infostream, nodedef); - UASSERT(v.getNode(v3s16(-1,0,-1)).getContent() == t_CONTENT_GRASS); - EXCEPTION_CHECK(InvalidPositionException, v.getNode(v3s16(0,1,1))); + UASSERT(v.getNode(v3POS(-1,0,-1)).getContent() == t_CONTENT_GRASS); + EXCEPTION_CHECK(InvalidPositionException, v.getNode(v3POS(0,1,1))); } diff --git a/src/util/areastore.cpp b/src/util/areastore.cpp index 67bfef0c03..801f633de8 100644 --- a/src/util/areastore.cpp +++ b/src/util/areastore.cpp @@ -75,8 +75,8 @@ void AreaStore::serialize(std::ostream &os) const writeU16(os, areas_map.size()); for (const auto &it : areas_map) { const Area &a = it.second; - writeV3S16(os, a.minedge); - writeV3S16(os, a.maxedge); + writeV3POS(os, a.minedge); + writeV3POS(os, a.maxedge); writeU16(os, a.data.size()); os.write(a.data.data(), a.data.size()); } @@ -99,8 +99,8 @@ void AreaStore::deserialize(std::istream &is) areas.reserve(num_areas); for (u32 i = 0; i < num_areas; ++i) { Area a(U32_MAX); - a.minedge = readV3S16(is); - a.maxedge = readV3S16(is); + a.minedge = readV3POS(is); + a.maxedge = readV3POS(is); u16 data_len = readU16(is); a.data = std::string(data_len, '\0'); is.read(&a.data[0], data_len); @@ -144,14 +144,14 @@ void AreaStore::setCacheParams(bool enabled, u8 block_radius, size_t limit) invalidateCache(); } -void AreaStore::cacheMiss(void *data, const v3s16 &mpos, std::vector *dest) +void AreaStore::cacheMiss(void *data, const v3POS &mpos, std::vector *dest) { AreaStore *as = (AreaStore *)data; u8 r = as->m_cacheblock_radius; // get the points at the edges of the mapblock - v3s16 minedge(mpos.X * r, mpos.Y * r, mpos.Z * r); - v3s16 maxedge( + v3POS minedge(mpos.X * r, mpos.Y * r, mpos.Z * r); + v3POS maxedge( minedge.X + r - 1, minedge.Y + r - 1, minedge.Z + r - 1); @@ -165,10 +165,10 @@ void AreaStore::cacheMiss(void *data, const v3s16 &mpos, std::vector *de << ")" << std::endl; // */ } -void AreaStore::getAreasForPos(std::vector *result, v3s16 pos) +void AreaStore::getAreasForPos(std::vector *result, v3POS pos) { if (m_cache_enabled) { - v3s16 mblock = getContainerPos(pos, m_cacheblock_radius); + v3POS mblock = getContainerPos(pos, m_cacheblock_radius); const std::vector *pre_list = m_res_cache.lookupCache(mblock); size_t s_p_l = pre_list->size(); @@ -221,7 +221,7 @@ bool VectorAreaStore::removeArea(u32 id) return true; } -void VectorAreaStore::getAreasForPosImpl(std::vector *result, v3s16 pos) +void VectorAreaStore::getAreasForPosImpl(std::vector *result, v3POS pos) { for (Area *area : m_areas) { if (AST_CONTAINS_PT(area, pos)) { @@ -231,7 +231,7 @@ void VectorAreaStore::getAreasForPosImpl(std::vector *result, v3s16 pos) } void VectorAreaStore::getAreasInArea(std::vector *result, - v3s16 minedge, v3s16 maxedge, bool accept_overlap) + v3POS minedge, v3POS maxedge, bool accept_overlap) { for (Area *area : m_areas) { if (accept_overlap ? AST_AREAS_OVERLAP(minedge, maxedge, area) : @@ -243,8 +243,8 @@ void VectorAreaStore::getAreasInArea(std::vector *result, #if USE_SPATIAL -static inline SpatialIndex::Region get_spatial_region(const v3s16 minedge, - const v3s16 maxedge) +static inline SpatialIndex::Region get_spatial_region(const v3POS minedge, + const v3POS maxedge) { const double p_low[] = {(double)minedge.X, (double)minedge.Y, (double)minedge.Z}; @@ -253,7 +253,7 @@ static inline SpatialIndex::Region get_spatial_region(const v3s16 minedge, return SpatialIndex::Region(p_low, p_high, 3); } -static inline SpatialIndex::Point get_spatial_point(const v3s16 pos) +static inline SpatialIndex::Point get_spatial_point(const v3POS pos) { const double p[] = {(double)pos.X, (double)pos.Y, (double)pos.Z}; return SpatialIndex::Point(p, 3); @@ -287,14 +287,14 @@ bool SpatialAreaStore::removeArea(u32 id) } } -void SpatialAreaStore::getAreasForPosImpl(std::vector *result, v3s16 pos) +void SpatialAreaStore::getAreasForPosImpl(std::vector *result, v3POS pos) { VectorResultVisitor visitor(result, this); m_tree->pointLocationQuery(get_spatial_point(pos), visitor); } void SpatialAreaStore::getAreasInArea(std::vector *result, - v3s16 minedge, v3s16 maxedge, bool accept_overlap) + v3POS minedge, v3POS maxedge, bool accept_overlap) { VectorResultVisitor visitor(result, this); if (accept_overlap) { diff --git a/src/util/areastore.h b/src/util/areastore.h index 150a043dbf..75c4232c18 100644 --- a/src/util/areastore.h +++ b/src/util/areastore.h @@ -39,14 +39,14 @@ with this program; if not, write to the Free Software Foundation, Inc., struct Area { Area(u32 area_id) : id(area_id) {} - Area(const v3s16 &mine, const v3s16 &maxe, u32 area_id = U32_MAX) : + Area(const v3POS &mine, const v3POS &maxe, u32 area_id = U32_MAX) : id(area_id), minedge(mine), maxedge(maxe) { sortBoxVerticies(minedge, maxedge); } u32 id; - v3s16 minedge, maxedge; + v3POS minedge, maxedge; std::string data; }; @@ -75,13 +75,13 @@ class AreaStore { /// Finds areas that the passed position is contained in. /// Stores output in passed vector. - void getAreasForPos(std::vector *result, v3s16 pos); + void getAreasForPos(std::vector *result, v3POS pos); /// Finds areas that are completely contained inside the area defined /// by the passed edges. If @p accept_overlap is true this finds any /// areas that intersect with the passed area at any point. virtual void getAreasInArea(std::vector *result, - v3s16 minedge, v3s16 maxedge, bool accept_overlap) = 0; + v3POS minedge, v3POS maxedge, bool accept_overlap) = 0; /// Sets cache parameters. void setCacheParams(bool enabled, u8 block_radius, size_t limit); @@ -106,7 +106,7 @@ class AreaStore { /// Implementation of getAreasForPos. /// getAreasForPos calls this if the cache is disabled. - virtual void getAreasForPosImpl(std::vector *result, v3s16 pos) = 0; + virtual void getAreasForPosImpl(std::vector *result, v3POS pos) = 0; /// Returns the next area ID and increments it. u32 getNextId() const; @@ -118,13 +118,13 @@ class AreaStore { private: /// Called by the cache when a value isn't found in the cache. - static void cacheMiss(void *data, const v3s16 &mpos, std::vector *dest); + static void cacheMiss(void *data, const v3POS &mpos, std::vector *dest); bool m_cache_enabled = true; /// Range, in nodes, of the getAreasForPos cache. /// If you modify this, call invalidateCache() u8 m_cacheblock_radius = 64; - LRUCache > m_res_cache; + LRUCache > m_res_cache; }; @@ -134,10 +134,10 @@ class VectorAreaStore : public AreaStore { virtual bool insertArea(Area *a); virtual bool removeArea(u32 id); virtual void getAreasInArea(std::vector *result, - v3s16 minedge, v3s16 maxedge, bool accept_overlap); + v3POS minedge, v3POS maxedge, bool accept_overlap); protected: - virtual void getAreasForPosImpl(std::vector *result, v3s16 pos); + virtual void getAreasForPosImpl(std::vector *result, v3POS pos); private: std::vector m_areas; @@ -154,10 +154,10 @@ class SpatialAreaStore : public AreaStore { virtual bool insertArea(Area *a); virtual bool removeArea(u32 id); virtual void getAreasInArea(std::vector *result, - v3s16 minedge, v3s16 maxedge, bool accept_overlap); + v3POS minedge, v3POS maxedge, bool accept_overlap); protected: - virtual void getAreasForPosImpl(std::vector *result, v3s16 pos); + virtual void getAreasForPosImpl(std::vector *result, v3POS pos); private: SpatialIndex::ISpatialIndex *m_tree = nullptr; diff --git a/src/util/basic_macros.h b/src/util/basic_macros.h index 334e342e09..f1b50421d8 100644 --- a/src/util/basic_macros.h +++ b/src/util/basic_macros.h @@ -50,7 +50,7 @@ with this program; if not, write to the Free Software Foundation, Inc., // Macros to facilitate writing position vectors to a stream // Usage: -// v3s16 pos(1,2,3); +// v3POS pos(1,2,3); // mystream << "message " << PP(pos) << std::endl; #define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")" diff --git a/src/util/directiontables.cpp b/src/util/directiontables.cpp index 296585f909..3aed88e1f2 100644 --- a/src/util/directiontables.cpp +++ b/src/util/directiontables.cpp @@ -19,95 +19,95 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "directiontables.h" -const v3s16 g_6dirs[6] = +const v3POS g_6dirs[6] = { // +right, +top, +back - v3s16( 0, 0, 1), // back - v3s16( 0, 1, 0), // top - v3s16( 1, 0, 0), // right - v3s16( 0, 0,-1), // front - v3s16( 0,-1, 0), // bottom - v3s16(-1, 0, 0) // left + v3POS( 0, 0, 1), // back + v3POS( 0, 1, 0), // top + v3POS( 1, 0, 0), // right + v3POS( 0, 0,-1), // front + v3POS( 0,-1, 0), // bottom + v3POS(-1, 0, 0) // left }; -const v3s16 g_7dirs[7] = +const v3POS g_7dirs[7] = { - v3s16(0,0,1), // back - v3s16(0,1,0), // top - v3s16(1,0,0), // right - v3s16(0,0,-1), // front - v3s16(0,-1,0), // bottom - v3s16(-1,0,0), // left - v3s16(0,0,0), // self + v3POS(0,0,1), // back + v3POS(0,1,0), // top + v3POS(1,0,0), // right + v3POS(0,0,-1), // front + v3POS(0,-1,0), // bottom + v3POS(-1,0,0), // left + v3POS(0,0,0), // self }; -const v3s16 g_26dirs[26] = +const v3POS g_26dirs[26] = { // +right, +top, +back - v3s16( 0, 0, 1), // back - v3s16( 0, 1, 0), // top - v3s16( 1, 0, 0), // right - v3s16( 0, 0,-1), // front - v3s16( 0,-1, 0), // bottom - v3s16(-1, 0, 0), // left + v3POS( 0, 0, 1), // back + v3POS( 0, 1, 0), // top + v3POS( 1, 0, 0), // right + v3POS( 0, 0,-1), // front + v3POS( 0,-1, 0), // bottom + v3POS(-1, 0, 0), // left // 6 - v3s16(-1, 1, 0), // top left - v3s16( 1, 1, 0), // top right - v3s16( 0, 1, 1), // top back - v3s16( 0, 1,-1), // top front - v3s16(-1, 0, 1), // back left - v3s16( 1, 0, 1), // back right - v3s16(-1, 0,-1), // front left - v3s16( 1, 0,-1), // front right - v3s16(-1,-1, 0), // bottom left - v3s16( 1,-1, 0), // bottom right - v3s16( 0,-1, 1), // bottom back - v3s16( 0,-1,-1), // bottom front + v3POS(-1, 1, 0), // top left + v3POS( 1, 1, 0), // top right + v3POS( 0, 1, 1), // top back + v3POS( 0, 1,-1), // top front + v3POS(-1, 0, 1), // back left + v3POS( 1, 0, 1), // back right + v3POS(-1, 0,-1), // front left + v3POS( 1, 0,-1), // front right + v3POS(-1,-1, 0), // bottom left + v3POS( 1,-1, 0), // bottom right + v3POS( 0,-1, 1), // bottom back + v3POS( 0,-1,-1), // bottom front // 18 - v3s16(-1, 1, 1), // top back-left - v3s16( 1, 1, 1), // top back-right - v3s16(-1, 1,-1), // top front-left - v3s16( 1, 1,-1), // top front-right - v3s16(-1,-1, 1), // bottom back-left - v3s16( 1,-1, 1), // bottom back-right - v3s16(-1,-1,-1), // bottom front-left - v3s16( 1,-1,-1), // bottom front-right + v3POS(-1, 1, 1), // top back-left + v3POS( 1, 1, 1), // top back-right + v3POS(-1, 1,-1), // top front-left + v3POS( 1, 1,-1), // top front-right + v3POS(-1,-1, 1), // bottom back-left + v3POS( 1,-1, 1), // bottom back-right + v3POS(-1,-1,-1), // bottom front-left + v3POS( 1,-1,-1), // bottom front-right // 26 }; -const v3s16 g_27dirs[27] = +const v3POS g_27dirs[27] = { // +right, +top, +back - v3s16( 0, 0, 1), // back - v3s16( 0, 1, 0), // top - v3s16( 1, 0, 0), // right - v3s16( 0, 0,-1), // front - v3s16( 0,-1, 0), // bottom - v3s16(-1, 0, 0), // left + v3POS( 0, 0, 1), // back + v3POS( 0, 1, 0), // top + v3POS( 1, 0, 0), // right + v3POS( 0, 0,-1), // front + v3POS( 0,-1, 0), // bottom + v3POS(-1, 0, 0), // left // 6 - v3s16(-1, 1, 0), // top left - v3s16( 1, 1, 0), // top right - v3s16( 0, 1, 1), // top back - v3s16( 0, 1,-1), // top front - v3s16(-1, 0, 1), // back left - v3s16( 1, 0, 1), // back right - v3s16(-1, 0,-1), // front left - v3s16( 1, 0,-1), // front right - v3s16(-1,-1, 0), // bottom left - v3s16( 1,-1, 0), // bottom right - v3s16( 0,-1, 1), // bottom back - v3s16( 0,-1,-1), // bottom front + v3POS(-1, 1, 0), // top left + v3POS( 1, 1, 0), // top right + v3POS( 0, 1, 1), // top back + v3POS( 0, 1,-1), // top front + v3POS(-1, 0, 1), // back left + v3POS( 1, 0, 1), // back right + v3POS(-1, 0,-1), // front left + v3POS( 1, 0,-1), // front right + v3POS(-1,-1, 0), // bottom left + v3POS( 1,-1, 0), // bottom right + v3POS( 0,-1, 1), // bottom back + v3POS( 0,-1,-1), // bottom front // 18 - v3s16(-1, 1, 1), // top back-left - v3s16( 1, 1, 1), // top back-right - v3s16(-1, 1,-1), // top front-left - v3s16( 1, 1,-1), // top front-right - v3s16(-1,-1, 1), // bottom back-left - v3s16( 1,-1, 1), // bottom back-right - v3s16(-1,-1,-1), // bottom front-left - v3s16( 1,-1,-1), // bottom front-right + v3POS(-1, 1, 1), // top back-left + v3POS( 1, 1, 1), // top back-right + v3POS(-1, 1,-1), // top front-left + v3POS( 1, 1,-1), // top front-right + v3POS(-1,-1, 1), // bottom back-left + v3POS( 1,-1, 1), // bottom back-right + v3POS(-1,-1,-1), // bottom front-left + v3POS( 1,-1,-1), // bottom front-right // 26 - v3s16(0,0,0), + v3POS(0,0,0), }; const u8 wallmounted_to_facedir[6] = { diff --git a/src/util/directiontables.h b/src/util/directiontables.h index ef00e3bfee..97574dc175 100644 --- a/src/util/directiontables.h +++ b/src/util/directiontables.h @@ -22,14 +22,14 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "irrlichttypes.h" #include "irr_v3d.h" -extern const v3s16 g_6dirs[6]; +extern const v3POS g_6dirs[6]; -extern const v3s16 g_7dirs[7]; +extern const v3POS g_7dirs[7]; -extern const v3s16 g_26dirs[26]; +extern const v3POS g_26dirs[26]; // 26th is (0,0,0) -extern const v3s16 g_27dirs[27]; +extern const v3POS g_27dirs[27]; extern const u8 wallmounted_to_facedir[6]; diff --git a/src/util/numeric.cpp b/src/util/numeric.cpp index 702ddce951..540f8f70b8 100644 --- a/src/util/numeric.cpp +++ b/src/util/numeric.cpp @@ -103,10 +103,10 @@ u64 murmur_hash_64_ua(const void *key, int len, unsigned int seed) range: viewing range distance_ptr: return location for distance from the camera */ -bool isBlockInSight(v3s16 blockpos_b, v3f camera_pos, v3f camera_dir, +bool isBlockInSight(v3POS blockpos_b, v3f camera_pos, v3f camera_dir, f32 camera_fov, f32 range, f32 *distance_ptr) { - v3s16 blockpos_nodes = blockpos_b * MAP_BLOCKSIZE; + v3POS blockpos_nodes = blockpos_b * MAP_BLOCKSIZE; // Block center position v3f blockpos( diff --git a/src/util/numeric.h b/src/util/numeric.h index 32a6f4312b..e0687fe288 100644 --- a/src/util/numeric.h +++ b/src/util/numeric.h @@ -41,58 +41,58 @@ with this program; if not, write to the Free Software Foundation, Inc., // sqrt(3.0) / 2.0 in literal form. static constexpr const f32 BLOCK_MAX_RADIUS = 0.866025403784f * MAP_BLOCKSIZE * BS; -inline s16 getContainerPos(s16 p, s16 d) +inline BPOS getContainerPos(POS p, POS d) { return (p >= 0 ? p : p - d + 1) / d; } -inline v2s16 getContainerPos(v2s16 p, s16 d) +inline v2BPOS getContainerPos(v2POS p, POS d) { - return v2s16( + return v2BPOS( getContainerPos(p.X, d), getContainerPos(p.Y, d) ); } -inline v3s16 getContainerPos(v3s16 p, s16 d) +inline v3BPOS getContainerPos(v3POS p, POS d) { - return v3s16( + return v3BPOS( getContainerPos(p.X, d), getContainerPos(p.Y, d), getContainerPos(p.Z, d) ); } -inline v2s16 getContainerPos(v2s16 p, v2s16 d) +inline v2BPOS getContainerPos(v2POS p, v2POS d) { - return v2s16( + return v2BPOS( getContainerPos(p.X, d.X), getContainerPos(p.Y, d.Y) ); } -inline v3s16 getContainerPos(v3s16 p, v3s16 d) +inline v3BPOS getContainerPos(v3POS p, v3POS d) { - return v3s16( + return v3BPOS( getContainerPos(p.X, d.X), getContainerPos(p.Y, d.Y), getContainerPos(p.Z, d.Z) ); } -inline void getContainerPosWithOffset(s16 p, s16 d, s16 &container, s16 &offset) +inline void getContainerPosWithOffset(POS p, POS d, BPOS &container, POS &offset) { container = (p >= 0 ? p : p - d + 1) / d; offset = p & (d - 1); } -inline void getContainerPosWithOffset(const v2s16 &p, s16 d, v2s16 &container, v2s16 &offset) +inline void getContainerPosWithOffset(const v2POS &p, POS d, v2BPOS &container, v2POS &offset) { getContainerPosWithOffset(p.X, d, container.X, offset.X); getContainerPosWithOffset(p.Y, d, container.Y, offset.Y); } -inline void getContainerPosWithOffset(const v3s16 &p, s16 d, v3s16 &container, v3s16 &offset) +inline void getContainerPosWithOffset(const v3POS &p, POS d, v3BPOS &container, v3POS &offset) { getContainerPosWithOffset(p.X, d, container.X, offset.X); getContainerPosWithOffset(p.Y, d, container.Y, offset.Y); @@ -100,7 +100,7 @@ inline void getContainerPosWithOffset(const v3s16 &p, s16 d, v3s16 &container, v } -inline bool isInArea(v3s16 p, s16 d) +inline bool isInArea(v3POS p, POS d) { return ( p.X >= 0 && p.X < d && @@ -109,7 +109,7 @@ inline bool isInArea(v3s16 p, s16 d) ); } -inline bool isInArea(v2s16 p, s16 d) +inline bool isInArea(v2POS p, POS d) { return ( p.X >= 0 && p.X < d && @@ -117,7 +117,7 @@ inline bool isInArea(v2s16 p, s16 d) ); } -inline bool isInArea(v3s16 p, v3s16 d) +inline bool isInArea(v3POS p, v3POS d) { return ( p.X >= 0 && p.X < d.X && @@ -126,23 +126,23 @@ inline bool isInArea(v3s16 p, v3s16 d) ); } -inline void sortBoxVerticies(v3s16 &p1, v3s16 &p2) { +inline void sortBoxVerticies(v3POS &p1, v3POS &p2) { if (p1.X > p2.X) - SWAP(s16, p1.X, p2.X); + SWAP(POS, p1.X, p2.X); if (p1.Y > p2.Y) - SWAP(s16, p1.Y, p2.Y); + SWAP(POS, p1.Y, p2.Y); if (p1.Z > p2.Z) - SWAP(s16, p1.Z, p2.Z); + SWAP(POS, p1.Z, p2.Z); } -inline v3s16 componentwise_min(const v3s16 &a, const v3s16 &b) +inline v3POS componentwise_min(const v3POS &a, const v3POS &b) { - return v3s16(MYMIN(a.X, b.X), MYMIN(a.Y, b.Y), MYMIN(a.Z, b.Z)); + return v3POS(MYMIN(a.X, b.X), MYMIN(a.Y, b.Y), MYMIN(a.Z, b.Z)); } -inline v3s16 componentwise_max(const v3s16 &a, const v3s16 &b) +inline v3POS componentwise_max(const v3POS &a, const v3POS &b) { - return v3s16(MYMAX(a.X, b.X), MYMAX(a.Y, b.Y), MYMAX(a.Z, b.Z)); + return v3POS(MYMAX(a.X, b.X), MYMAX(a.Y, b.Y), MYMAX(a.Z, b.Z)); } @@ -252,7 +252,7 @@ inline u32 calc_parity(u32 v) u64 murmur_hash_64_ua(const void *key, int len, unsigned int seed); -bool isBlockInSight(v3s16 blockpos_b, v3f camera_pos, v3f camera_dir, +bool isBlockInSight(v3BPOS blockpos_b, v3f camera_pos, v3f camera_dir, f32 camera_fov, f32 range, f32 *distance_ptr=NULL); s16 adjustDist(s16 dist, float zoom_fov); @@ -274,9 +274,9 @@ inline constexpr f32 sqr(f32 f) /* Returns integer position of node in given floating point position */ -inline v3s16 floatToInt(v3f p, f32 d) +inline v3POS floatToInt(v3f p, f32 d) { - return v3s16( + return v3POS( (p.X + (p.X > 0 ? d / 2 : -d / 2)) / d, (p.Y + (p.Y > 0 ? d / 2 : -d / 2)) / d, (p.Z + (p.Z > 0 ? d / 2 : -d / 2)) / d); @@ -293,10 +293,18 @@ inline v3s16 doubleToInt(v3d p, double d) (p.Z + (p.Z > 0 ? d / 2 : -d / 2)) / d); } +inline v3POS doubleToPos(v3d p, double d) +{ + return v3POS( + (p.X + (p.X > 0 ? d / 2 : -d / 2)) / d, + (p.Y + (p.Y > 0 ? d / 2 : -d / 2)) / d, + (p.Z + (p.Z > 0 ? d / 2 : -d / 2)) / d); +} + /* Returns floating point position of node in given integer position */ -inline v3f intToFloat(v3s16 p, f32 d) +inline v3f intToFloat(v3POS p, f32 d) { return v3f( (f32)p.X * d, @@ -306,7 +314,7 @@ inline v3f intToFloat(v3s16 p, f32 d) } // Random helper. Usually d=BS -inline aabb3f getNodeBox(v3s16 p, float d) +inline aabb3f getNodeBox(v3POS p, float d) { return aabb3f( (float)p.X * d - 0.5f * d, diff --git a/src/util/pointedthing.cpp b/src/util/pointedthing.cpp index b906264d0a..180c9494b5 100644 --- a/src/util/pointedthing.cpp +++ b/src/util/pointedthing.cpp @@ -23,8 +23,8 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "exceptions.h" #include -PointedThing::PointedThing(const v3s16 &under, const v3s16 &above, - const v3s16 &real_under, const v3f &point, const v3s16 &normal, +PointedThing::PointedThing(const v3POS &under, const v3POS &above, + const v3POS &real_under, const v3f &point, const v3POS &normal, u16 box_id, f32 distSq): type(POINTEDTHING_NODE), node_undersurface(under), @@ -36,7 +36,7 @@ PointedThing::PointedThing(const v3s16 &under, const v3s16 &above, distanceSq(distSq) {} -PointedThing::PointedThing(s16 id, const v3f &point, const v3s16 &normal, +PointedThing::PointedThing(s16 id, const v3f &point, const v3POS &normal, f32 distSq) : type(POINTEDTHING_OBJECT), object_id(id), @@ -54,8 +54,8 @@ std::string PointedThing::dump() const break; case POINTEDTHING_NODE: { - const v3s16 &u = node_undersurface; - const v3s16 &a = node_abovesurface; + const v3POS &u = node_undersurface; + const v3POS &a = node_abovesurface; os << "[node under=" << u.X << "," << u.Y << "," << u.Z << " above=" << a.X << "," << a.Y << "," << a.Z << "]"; } @@ -77,8 +77,8 @@ void PointedThing::serialize(std::ostream &os) const case POINTEDTHING_NOTHING: break; case POINTEDTHING_NODE: - writeV3S16(os, node_undersurface); - writeV3S16(os, node_abovesurface); + writeV3POS(os, node_undersurface); + writeV3POS(os, node_abovesurface); break; case POINTEDTHING_OBJECT: writeS16(os, object_id); @@ -96,8 +96,8 @@ void PointedThing::deSerialize(std::istream &is) case POINTEDTHING_NOTHING: break; case POINTEDTHING_NODE: - node_undersurface = readV3S16(is); - node_abovesurface = readV3S16(is); + node_undersurface = readV3POS(is); + node_abovesurface = readV3POS(is); break; case POINTEDTHING_OBJECT: object_id = readS16(is); diff --git a/src/util/pointedthing.h b/src/util/pointedthing.h index 5b30ed0313..b02c47a589 100644 --- a/src/util/pointedthing.h +++ b/src/util/pointedthing.h @@ -43,20 +43,20 @@ struct PointedThing * This may differ from node_real_undersurface if * a nodebox exceeds the limits of its node. */ - v3s16 node_undersurface; + v3POS node_undersurface; /*! * Only valid if type is POINTEDTHING_NODE. * The coordinates of the last node the ray intersects * before node_undersurface. Same as node_undersurface * if the ray starts in a nodebox. */ - v3s16 node_abovesurface; + v3POS node_abovesurface; /*! * Only valid if type is POINTEDTHING_NODE. * The coordinates of the node which contains the * point of the collision and the nodebox of the node. */ - v3s16 node_real_undersurface; + v3POS node_real_undersurface; /*! * Only valid if type is POINTEDTHING_OBJECT. * The ID of the object the ray hit. @@ -74,7 +74,7 @@ struct PointedThing * This is perpendicular to the face the ray hits, * points outside of the box and it's length is 1. */ - v3s16 intersection_normal; + v3POS intersection_normal; /*! * Only valid if type isn't POINTEDTHING_NONE. * Indicates which selection box is selected, if there are more of them. @@ -89,11 +89,11 @@ struct PointedThing //! Constructor for POINTEDTHING_NOTHING PointedThing() = default; //! Constructor for POINTEDTHING_NODE - PointedThing(const v3s16 &under, const v3s16 &above, - const v3s16 &real_under, const v3f &point, const v3s16 &normal, + PointedThing(const v3POS &under, const v3POS &above, + const v3POS &real_under, const v3f &point, const v3POS &normal, u16 box_id, f32 distSq); //! Constructor for POINTEDTHING_OBJECT - PointedThing(s16 id, const v3f &point, const v3s16 &normal, f32 distSq); + PointedThing(s16 id, const v3f &point, const v3POS &normal, f32 distSq); std::string dump() const; void serialize(std::ostream &os) const; void deSerialize(std::istream &is); diff --git a/src/util/serialize.h b/src/util/serialize.h index 15bdd050da..8ef483eeb8 100644 --- a/src/util/serialize.h +++ b/src/util/serialize.h @@ -435,6 +435,38 @@ MAKE_STREAM_WRITE_FXN(v2f, V2F32, 8); MAKE_STREAM_WRITE_FXN(v3f, V3F32, 12); MAKE_STREAM_WRITE_FXN(video::SColor, ARGB8, 4); +inline POS readPOS(std::istream &is) { +#if USE_POS32 + return readS32(is); +#else + return readS16(is); +#endif +} + +inline void writePOS(std::ostream &os, POS i) { +#if USE_POS32 + return writeS32(os, i); +#else + return writeS16(os, i); +#endif +} + +inline v3POS readV3POS(std::istream &is) { +#if USE_POS32 + return readV3S32(is); +#else + return readV3S16(is); +#endif +} + +inline void writeV3POS(std::ostream &os, v3POS p) { +#if USE_POS32 + return writeV3S32(os, p); +#else + return writeV3S16(os, p); +#endif +} + //// //// More serialization stuff //// diff --git a/src/voxel.cpp b/src/voxel.cpp index 1f1d253731..8a24056c18 100644 --- a/src/voxel.cpp +++ b/src/voxel.cpp @@ -51,8 +51,8 @@ void VoxelManipulator::clear() void VoxelManipulator::print(std::ostream &o, const NodeDefManager *ndef, VoxelPrintMode mode) { - const v3s16 &em = m_area.getExtent(); - v3s16 of = m_area.MinEdge; + const v3POS &em = m_area.getExtent(); + v3POS of = m_area.MinEdge; o<<"size: "<= MinEdge.Z && a.MaxEdge.Z <= MaxEdge.Z ); } - bool contains(v3s16 p) const + bool contains(v3POS p) const { return( p.X >= MinEdge.X && p.X <= MaxEdge.X && @@ -173,12 +173,12 @@ class VoxelArea && MaxEdge == other.MaxEdge); } - VoxelArea operator+(const v3s16 &off) const + VoxelArea operator+(const v3POS &off) const { return {MinEdge+off, MaxEdge+off}; } - VoxelArea operator-(const v3s16 &off) const + VoxelArea operator-(const v3POS &off) const { return {MinEdge-off, MaxEdge-off}; } @@ -196,7 +196,7 @@ class VoxelArea */ // If a is an empty area, return the current area as a whole - if(a.getExtent() == v3s16(0,0,0)) + if(a.getExtent() == v3POS(0,0,0)) { VoxelArea b = *this; if(b.getVolume() != 0) @@ -208,8 +208,8 @@ class VoxelArea // Take back area, XY inclusive { - v3s16 min(MinEdge.X, MinEdge.Y, a.MaxEdge.Z+1); - v3s16 max(MaxEdge.X, MaxEdge.Y, MaxEdge.Z); + v3POS min(MinEdge.X, MinEdge.Y, a.MaxEdge.Z+1); + v3POS max(MaxEdge.X, MaxEdge.Y, MaxEdge.Z); VoxelArea b(min, max); if(b.getVolume() != 0) result.push_back(b); @@ -217,8 +217,8 @@ class VoxelArea // Take front area, XY inclusive { - v3s16 min(MinEdge.X, MinEdge.Y, MinEdge.Z); - v3s16 max(MaxEdge.X, MaxEdge.Y, a.MinEdge.Z-1); + v3POS min(MinEdge.X, MinEdge.Y, MinEdge.Z); + v3POS max(MaxEdge.X, MaxEdge.Y, a.MinEdge.Z-1); VoxelArea b(min, max); if(b.getVolume() != 0) result.push_back(b); @@ -226,8 +226,8 @@ class VoxelArea // Take top area, X inclusive { - v3s16 min(MinEdge.X, a.MaxEdge.Y+1, a.MinEdge.Z); - v3s16 max(MaxEdge.X, MaxEdge.Y, a.MaxEdge.Z); + v3POS min(MinEdge.X, a.MaxEdge.Y+1, a.MinEdge.Z); + v3POS max(MaxEdge.X, MaxEdge.Y, a.MaxEdge.Z); VoxelArea b(min, max); if(b.getVolume() != 0) result.push_back(b); @@ -235,8 +235,8 @@ class VoxelArea // Take bottom area, X inclusive { - v3s16 min(MinEdge.X, MinEdge.Y, a.MinEdge.Z); - v3s16 max(MaxEdge.X, a.MinEdge.Y-1, a.MaxEdge.Z); + v3POS min(MinEdge.X, MinEdge.Y, a.MinEdge.Z); + v3POS max(MaxEdge.X, a.MinEdge.Y-1, a.MaxEdge.Z); VoxelArea b(min, max); if(b.getVolume() != 0) result.push_back(b); @@ -244,8 +244,8 @@ class VoxelArea // Take left area, non-inclusive { - v3s16 min(MinEdge.X, a.MinEdge.Y, a.MinEdge.Z); - v3s16 max(a.MinEdge.X-1, a.MaxEdge.Y, a.MaxEdge.Z); + v3POS min(MinEdge.X, a.MinEdge.Y, a.MinEdge.Z); + v3POS max(a.MinEdge.X-1, a.MaxEdge.Y, a.MaxEdge.Z); VoxelArea b(min, max); if(b.getVolume() != 0) result.push_back(b); @@ -253,8 +253,8 @@ class VoxelArea // Take right area, non-inclusive { - v3s16 min(a.MaxEdge.X+1, a.MinEdge.Y, a.MinEdge.Z); - v3s16 max(MaxEdge.X, a.MaxEdge.Y, a.MaxEdge.Z); + v3POS min(a.MaxEdge.X+1, a.MinEdge.Y, a.MinEdge.Z); + v3POS max(MaxEdge.X, a.MaxEdge.Y, a.MaxEdge.Z); VoxelArea b(min, max); if(b.getVolume() != 0) result.push_back(b); @@ -265,14 +265,14 @@ class VoxelArea /* Translates position from virtual coordinates to array index */ - s32 index(s16 x, s16 y, s16 z) const + s32 index(POS x, POS y, POS z) const { s32 i = (s32)(z - MinEdge.Z) * m_cache_extent.Y * m_cache_extent.X + (y - MinEdge.Y) * m_cache_extent.X + (x - MinEdge.X); return i; } - s32 index(v3s16 p) const + s32 index(v3POS p) const { return index(p.X, p.Y, p.Z); } @@ -280,7 +280,7 @@ class VoxelArea /** * Translate index in the X coordinate */ - static void add_x(const v3s16 &extent, u32 &i, s16 a) + static void add_x(const v3POS &extent, u32 &i, POS a) { i += a; } @@ -288,7 +288,7 @@ class VoxelArea /** * Translate index in the Y coordinate */ - static void add_y(const v3s16 &extent, u32 &i, s16 a) + static void add_y(const v3POS &extent, u32 &i, POS a) { i += a * extent.X; } @@ -296,7 +296,7 @@ class VoxelArea /** * Translate index in the Z coordinate */ - static void add_z(const v3s16 &extent, u32 &i, s16 a) + static void add_z(const v3POS &extent, u32 &i, POS a) { i += a * extent.X * extent.Y; } @@ -304,7 +304,7 @@ class VoxelArea /** * Translate index in space */ - static void add_p(const v3s16 &extent, u32 &i, v3s16 a) + static void add_p(const v3POS &extent, u32 &i, v3POS a) { i += a.Z * extent.X * extent.Y + a.Y * extent.X + a.X; } @@ -320,15 +320,15 @@ class VoxelArea } // Edges are inclusive - v3s16 MinEdge = v3s16(1,1,1); - v3s16 MaxEdge; + v3POS MinEdge = v3POS(1,1,1); + v3POS MaxEdge; private: void cacheExtent() { - m_cache_extent = MaxEdge - MinEdge + v3s16(1,1,1); + m_cache_extent = MaxEdge - MinEdge + v3POS(1,1,1); } - v3s16 m_cache_extent = v3s16(0,0,0); + v3POS m_cache_extent = v3POS(0,0,0); }; // unused @@ -362,7 +362,7 @@ class VoxelManipulator These are a bit slow and shouldn't be used internally. Use m_data[m_area.index(p)] instead. */ - MapNode getNode(const v3s16 &p) + MapNode getNode(const v3POS &p) { VoxelArea voxel_area(p); addArea(voxel_area); @@ -379,7 +379,7 @@ class VoxelManipulator return m_data[m_area.index(p)]; } - MapNode getNodeNoEx(const v3s16 &p) + MapNode getNodeNoEx(const v3POS &p) { VoxelArea voxel_area(p); addArea(voxel_area); @@ -390,7 +390,7 @@ class VoxelManipulator return m_data[m_area.index(p)]; } - MapNode getNodeNoExNoEmerge(const v3s16 &p) + MapNode getNodeNoExNoEmerge(const v3POS &p) { if (!m_area.contains(p)) return {CONTENT_IGNORE}; @@ -400,12 +400,12 @@ class VoxelManipulator } // Stuff explodes if non-emerged area is touched with this. // Emerge first, and check VOXELFLAG_NO_DATA if appropriate. - MapNode & getNodeRefUnsafe(const v3s16 &p) + MapNode & getNodeRefUnsafe(const v3POS &p) { return m_data[m_area.index(p)]; } - const MapNode & getNodeRefUnsafeCheckFlags(const v3s16 &p) + const MapNode & getNodeRefUnsafeCheckFlags(const v3POS &p) { s32 index = m_area.index(p); @@ -415,18 +415,18 @@ class VoxelManipulator return m_data[index]; } - u8 & getFlagsRefUnsafe(const v3s16 &p) + u8 & getFlagsRefUnsafe(const v3POS &p) { return m_flags[m_area.index(p)]; } - bool exists(const v3s16 &p) + bool exists(const v3POS &p) { return m_area.contains(p) && !(getFlagsRefUnsafe(p) & VOXELFLAG_NO_DATA); } - void setNode(const v3s16 &p, const MapNode &n) + void setNode(const v3POS &p, const MapNode &n) { VoxelArea voxel_area(p); addArea(voxel_area); @@ -435,7 +435,7 @@ class VoxelManipulator m_flags[m_area.index(p)] &= ~VOXELFLAG_NO_DATA; } // TODO: Should be removed and replaced with setNode - void setNodeNoRef(const v3s16 &p, const MapNode &n) + void setNodeNoRef(const v3POS &p, const MapNode &n) { setNode(p, n); } @@ -446,7 +446,7 @@ class VoxelManipulator This is convenient but slower than playing around directly with the m_data table with indices. */ - bool setNodeNoEmerge(const v3s16 &p, MapNode n) + bool setNodeNoEmerge(const v3POS &p, MapNode n) { if(!m_area.contains(p)) return false; @@ -470,11 +470,11 @@ class VoxelManipulator dst_area.getExtent() <= src_area.getExtent() */ void copyFrom(MapNode *src, const VoxelArea& src_area, - v3s16 from_pos, v3s16 to_pos, const v3s16 &size); + v3POS from_pos, v3POS to_pos, const v3POS &size); // Copy data void copyTo(MapNode *dst, const VoxelArea& dst_area, - v3s16 dst_pos, v3s16 from_pos, const v3s16 &size); + v3POS dst_pos, v3POS from_pos, const v3POS &size); /* Algorithms @@ -488,7 +488,7 @@ class VoxelManipulator /* The area that is stored in m_data. - addInternalBox should not be used if getExtent() == v3s16(0,0,0) + addInternalBox should not be used if getExtent() == v3POS(0,0,0) MaxEdge is 1 higher than maximum allowed position */ VoxelArea m_area; diff --git a/src/voxelalgorithms.cpp b/src/voxelalgorithms.cpp index ffb70aa719..1abe7b6742 100644 --- a/src/voxelalgorithms.cpp +++ b/src/voxelalgorithms.cpp @@ -42,12 +42,12 @@ typedef u8 direction; * This represents a node's position in its map block. * All coordinates must be between 0 and 15. */ -typedef v3s16 relative_v3; +typedef v3POS relative_v3; /*! * Position of a map block (block coordinates). * One block_pos unit is as long as 16 node position units. */ -typedef v3s16 mapblock_v3; +typedef v3BPOS mapblock_v3; //! Contains information about a node whose light is about to change. struct ChangingLight { @@ -158,13 +158,13 @@ typedef LightQueue ReLightQueue; * the direction i. * See the definition of the type "direction" */ -const static v3s16 neighbor_dirs[6] = { - v3s16(1, 0, 0), // right - v3s16(0, 1, 0), // top - v3s16(0, 0, 1), // back - v3s16(0, 0, -1), // front - v3s16(0, -1, 0), // bottom - v3s16(-1, 0, 0), // left +const static v3POS neighbor_dirs[6] = { + v3POS(1, 0, 0), // right + v3POS(0, 1, 0), // top + v3POS(0, 0, 1), // back + v3POS(0, 0, -1), // front + v3POS(0, -1, 0), // bottom + v3POS(-1, 0, 0), // left }; /*! @@ -248,7 +248,7 @@ bool step_rel_block_pos(direction dir, relative_v3 &rel_pos, */ void unspread_light(Map *map, const NodeDefManager *nodemgr, LightBank bank, UnlightQueue &from_nodes, ReLightQueue &light_sources, - std::map &modified_blocks) + std::map &modified_blocks) { // Stores data popped from from_nodes u8 current_light; @@ -352,7 +352,7 @@ void unspread_light(Map *map, const NodeDefManager *nodemgr, LightBank bank, */ void spread_light(Map *map, const NodeDefManager *nodemgr, LightBank bank, LightQueue &light_sources, - std::map &modified_blocks) + std::map &modified_blocks) { // The light the current node can provide to its neighbors. u8 spreading_light; @@ -407,10 +407,10 @@ void spread_light(Map *map, const NodeDefManager *nodemgr, LightBank bank, } struct SunlightPropagationUnit{ - v2s16 relative_pos; + v2POS relative_pos; bool is_sunlit; - SunlightPropagationUnit(v2s16 relpos, bool sunlit): + SunlightPropagationUnit(v2POS relpos, bool sunlit): relative_pos(relpos), is_sunlit(sunlit) {} @@ -418,7 +418,7 @@ struct SunlightPropagationUnit{ struct SunlightPropagationData{ std::vector data; - v3s16 target_block; + v3POS target_block; }; /*! @@ -427,12 +427,12 @@ struct SunlightPropagationData{ * * \param pos position of the node. */ -bool is_sunlight_above(Map *map, v3s16 pos, const NodeDefManager *ndef) +bool is_sunlight_above(Map *map, v3POS pos, const NodeDefManager *ndef) { bool sunlight = true; mapblock_v3 source_block_pos; relative_v3 source_rel_pos; - getNodeBlockPosWithOffset(pos + v3s16(0, 1, 0), source_block_pos, + getNodeBlockPosWithOffset(pos + v3POS(0, 1, 0), source_block_pos, source_rel_pos); // If the node above has sunlight, this node also can get it. MapBlock *source_block = map->getBlockNoCreateNoEx(source_block_pos); @@ -467,8 +467,8 @@ bool is_sunlight_above(Map *map, v3s16 pos, const NodeDefManager *ndef) static const LightBank banks[] = { LIGHTBANK_DAY, LIGHTBANK_NIGHT }; void update_lighting_nodes(Map *map, - const std::vector> &oldnodes, - std::map &modified_blocks) + const std::vector> &oldnodes, + std::map &modified_blocks) { const NodeDefManager *ndef = map->getNodeDefManager(); // For node getter functions @@ -496,7 +496,7 @@ void update_lighting_nodes(Map *map, // For each changed node process sunlight and initialize for (auto it = oldnodes.cbegin(); it < oldnodes.cend(); ++it) { // Get position and block of the changed node - v3s16 p = it->first; + v3POS p = it->first; relative_v3 rel_pos; mapblock_v3 block_pos; getNodeBlockPosWithOffset(p, block_pos, rel_pos); @@ -524,8 +524,8 @@ void update_lighting_nodes(Map *map, new_light = LIGHT_SUN; } else { new_light = ndef->get(n).light_source; - for (const v3s16 &neighbor_dir : neighbor_dirs) { - v3s16 p2 = p + neighbor_dir; + for (const v3POS &neighbor_dir : neighbor_dirs) { + v3POS p2 = p + neighbor_dir; bool is_valid; MapNode n2 = map->getNode(p2, &is_valid); if (is_valid) { @@ -559,8 +559,8 @@ void update_lighting_nodes(Map *map, // Remove sunlight, if there was any if (bank == LIGHTBANK_DAY && old_light == LIGHT_SUN) { - for (s16 y = p.Y - 1;; y--) { - v3s16 n2pos(p.X, y, p.Z); + for (POS y = p.Y - 1;; y--) { + v3POS n2pos(p.X, y, p.Z); MapNode n2; @@ -591,8 +591,8 @@ void update_lighting_nodes(Map *map, // one, unlighting is not necessary. // Propagate sunlight if (bank == LIGHTBANK_DAY && new_light == LIGHT_SUN) { - for (s16 y = p.Y - 1;; y--) { - v3s16 n2pos(p.X, y, p.Z); + for (POS y = p.Y - 1;; y--) { + v3POS n2pos(p.X, y, p.Z); MapNode n2; @@ -646,12 +646,12 @@ void update_lighting_nodes(Map *map, * Compatible with type 'direction'. */ const VoxelArea block_borders[] = { - VoxelArea(v3s16(15, 0, 0), v3s16(15, 15, 15)), //X+ - VoxelArea(v3s16(0, 15, 0), v3s16(15, 15, 15)), //Y+ - VoxelArea(v3s16(0, 0, 15), v3s16(15, 15, 15)), //Z+ - VoxelArea(v3s16(0, 0, 0), v3s16(15, 15, 0)), //Z- - VoxelArea(v3s16(0, 0, 0), v3s16(15, 0, 15)), //Y- - VoxelArea(v3s16(0, 0, 0), v3s16(0, 15, 15)) //X- + VoxelArea(v3POS(15, 0, 0), v3POS(15, 15, 15)), //X+ + VoxelArea(v3POS(0, 15, 0), v3POS(15, 15, 15)), //Y+ + VoxelArea(v3POS(0, 0, 15), v3POS(15, 15, 15)), //Z+ + VoxelArea(v3POS(0, 0, 0), v3POS(15, 15, 0)), //Z- + VoxelArea(v3POS(0, 0, 0), v3POS(15, 0, 15)), //Y- + VoxelArea(v3POS(0, 0, 0), v3POS(0, 15, 15)) //X- }; /*! @@ -663,7 +663,7 @@ const VoxelArea block_borders[] = { * . */ bool is_light_locally_correct(Map *map, const NodeDefManager *ndef, - LightBank bank, v3s16 pos) + LightBank bank, v3POS pos) { bool is_valid_position; MapNode n = map->getNode(pos, &is_valid_position); @@ -674,7 +674,7 @@ bool is_light_locally_correct(Map *map, const NodeDefManager *ndef, u8 light = n.getLightNoChecks(bank, &f); assert(f.light_source <= LIGHT_MAX); u8 brightest_neighbor = f.light_source + 1; - for (const v3s16 &neighbor_dir : neighbor_dirs) { + for (const v3POS &neighbor_dir : neighbor_dirs) { MapNode n2 = map->getNode(pos + neighbor_dir, &is_valid_position); u8 light2 = n2.getLight(bank, ndef); @@ -687,7 +687,7 @@ bool is_light_locally_correct(Map *map, const NodeDefManager *ndef, } void update_block_border_lighting(Map *map, MapBlock *block, - std::map &modified_blocks) + std::map &modified_blocks) { const NodeDefManager *ndef = map->getNodeDefManager(); bool is_valid_position; @@ -700,7 +700,7 @@ void update_block_border_lighting(Map *map, MapBlock *block, for (direction d = 0; d < 6; d++) { // For each direction // Get neighbor block - v3s16 otherpos = block->getPos() + neighbor_dirs[d]; + v3POS otherpos = block->getPos() + neighbor_dirs[d]; MapBlock *other = map->getBlockNoCreateNoEx(otherpos); if (other == NULL) { continue; @@ -730,7 +730,7 @@ void update_block_border_lighting(Map *map, MapBlock *block, if (light < LIGHT_SUN) { // Unlight if not correct if (!is_light_locally_correct(map, ndef, bank, - v3s16(x, y, z) + b->getPosRelative())) { + v3POS(x, y, z) + b->getPosRelative())) { // Initialize for unlighting n.setLight(bank, 0, ndef); b->setNodeNoCheck(x, y, z, n); @@ -775,7 +775,7 @@ void update_block_border_lighting(Map *map, MapBlock *block, * After the procedure returns, this contains outgoing light at * the bottom of the voxel manipulator. */ -void fill_with_sunlight(MMVManip *vm, const NodeDefManager *ndef, v2s16 offset, +void fill_with_sunlight(MMVManip *vm, const NodeDefManager *ndef, v2POS offset, bool light[MAP_BLOCKSIZE][MAP_BLOCKSIZE]) { // Distance in array between two nodes on top of each other. @@ -786,7 +786,7 @@ void fill_with_sunlight(MMVManip *vm, const NodeDefManager *ndef, v2s16 offset, for (s16 z = 0; z < MAP_BLOCKSIZE; z++) for (s16 x = 0; x < MAP_BLOCKSIZE; x++) { // Position of the column on the map. - v2s16 realpos = offset + v2s16(x, z); + v2POS realpos = offset + v2POS(x, z); // Array indices in the voxel manipulator s32 maxindex = vm->m_area.index(realpos.X, vm->m_area.MaxEdge.Y, realpos.Y); @@ -829,7 +829,7 @@ void fill_with_sunlight(MMVManip *vm, const NodeDefManager *ndef, v2s16 offset, void is_sunlight_above_block(ServerMap *map, mapblock_v3 pos, const NodeDefManager *ndef, bool light[MAP_BLOCKSIZE][MAP_BLOCKSIZE]) { - mapblock_v3 source_block_pos = pos + v3s16(0, 1, 0); + mapblock_v3 source_block_pos = pos + v3POS(0, 1, 0); // Get or load source block. // It might take a while to load, but correcting incorrect // sunlight may be even slower. @@ -946,12 +946,12 @@ bool propagate_block_sunlight(Map *map, const NodeDefManager *ndef, * Compatible with type 'direction'. */ const VoxelArea block_pad[] = { - VoxelArea(v3s16(15, 0, 0), v3s16(15, 15, 15)), //X+ - VoxelArea(v3s16(1, 15, 0), v3s16(14, 15, 15)), //Y+ - VoxelArea(v3s16(1, 1, 15), v3s16(14, 14, 15)), //Z+ - VoxelArea(v3s16(1, 1, 0), v3s16(14, 14, 0)), //Z- - VoxelArea(v3s16(1, 0, 0), v3s16(14, 0, 15)), //Y- - VoxelArea(v3s16(0, 0, 0), v3s16(0, 15, 15)) //X- + VoxelArea(v3POS(15, 0, 0), v3POS(15, 15, 15)), //X+ + VoxelArea(v3POS(1, 15, 0), v3POS(14, 15, 15)), //Y+ + VoxelArea(v3POS(1, 1, 15), v3POS(14, 14, 15)), //Z+ + VoxelArea(v3POS(1, 1, 0), v3POS(14, 14, 0)), //Z- + VoxelArea(v3POS(1, 0, 0), v3POS(14, 0, 15)), //Y- + VoxelArea(v3POS(0, 0, 0), v3POS(0, 15, 15)) //X- }; /*! @@ -976,7 +976,7 @@ const VoxelArea block_pad[] = { */ void finish_bulk_light_update(Map *map, mapblock_v3 minblock, mapblock_v3 maxblock, UnlightQueue unlight[2], ReLightQueue relight[2], - std::map *modified_blocks) + std::map *modified_blocks) { const NodeDefManager *ndef = map->getNodeDefManager(); // dummy boolean @@ -993,8 +993,8 @@ void finish_bulk_light_update(Map *map, mapblock_v3 minblock, // --- STEP 2: Get all newly inserted light sources // For each block: - v3s16 blockpos; - v3s16 relpos; + v3POS blockpos; + v3POS relpos; for (blockpos.X = minblock.X; blockpos.X <= maxblock.X; blockpos.X++) for (blockpos.Y = minblock.Y; blockpos.Y <= maxblock.Y; blockpos.Y++) for (blockpos.Z = minblock.Z; blockpos.Z <= maxblock.Z; blockpos.Z++) { @@ -1045,7 +1045,7 @@ void finish_bulk_light_update(Map *map, mapblock_v3 minblock, } void blit_back_with_light(ServerMap *map, MMVManip *vm, - std::map *modified_blocks) + std::map *modified_blocks) { const NodeDefManager *ndef = map->getNodeDefManager(); mapblock_v3 minblock = getNodeBlockPos(vm->m_area.MinEdge); @@ -1062,19 +1062,19 @@ void blit_back_with_light(ServerMap *map, MMVManip *vm, // --- STEP 1: reset everything to sunlight // For each map block: - for (s16 x = minblock.X; x <= maxblock.X; x++) - for (s16 z = minblock.Z; z <= maxblock.Z; z++) { + for (BPOS x = minblock.X; x <= maxblock.X; x++) + for (BPOS z = minblock.Z; z <= maxblock.Z; z++) { // Extract sunlight above. - is_sunlight_above_block(map, v3s16(x, maxblock.Y, z), ndef, lights); - v2s16 offset(x, z); + is_sunlight_above_block(map, v3BPOS(x, maxblock.Y, z), ndef, lights); + v2POS offset(x, z); offset *= MAP_BLOCKSIZE; // Reset the voxel manipulator. fill_with_sunlight(vm, ndef, offset, lights); // Copy sunlight data - data.target_block = v3s16(x, minblock.Y - 1, z); + data.target_block = v3POS(x, minblock.Y - 1, z); for (s16 z = 0; z < MAP_BLOCKSIZE; z++) for (s16 x = 0; x < MAP_BLOCKSIZE; x++) - data.data.emplace_back(v2s16(x, z), lights[z][x]); + data.data.emplace_back(v2POS(x, z), lights[z][x]); // Propagate sunlight and shadow below the voxel manipulator. while (!data.data.empty()) { if (propagate_block_sunlight(map, ndef, &data, &unlight[0], @@ -1087,8 +1087,8 @@ void blit_back_with_light(ServerMap *map, MMVManip *vm, } // --- STEP 2: Get nodes from borders to unlight - v3s16 blockpos; - v3s16 relpos; + v3POS blockpos; + v3POS relpos; // In case there are unloaded holes in the voxel manipulator // unlight each block. @@ -1100,7 +1100,7 @@ void blit_back_with_light(ServerMap *map, MMVManip *vm, if (!block || block->isDummy()) // Skip not existing blocks. continue; - v3s16 offset = block->getPosRelative(); + v3POS offset = block->getPosRelative(); // For each border of the block: for (const VoxelArea &a : block_pad) { // For each node of the border: @@ -1188,7 +1188,7 @@ void fill_with_sunlight(MapBlock *block, const NodeDefManager *ndef, } void repair_block_light(ServerMap *map, MapBlock *block, - std::map *modified_blocks) + std::map *modified_blocks) { if (!block || block->isDummy()) return; @@ -1212,10 +1212,10 @@ void repair_block_light(ServerMap *map, MapBlock *block, // Reset the voxel manipulator. fill_with_sunlight(block, ndef, lights); // Copy sunlight data - data.target_block = v3s16(blockpos.X, blockpos.Y - 1, blockpos.Z); + data.target_block = v3POS(blockpos.X, blockpos.Y - 1, blockpos.Z); for (s16 z = 0; z < MAP_BLOCKSIZE; z++) for (s16 x = 0; x < MAP_BLOCKSIZE; x++) { - data.data.emplace_back(v2s16(x, z), lights[z][x]); + data.data.emplace_back(v2POS(x, z), lights[z][x]); } // Propagate sunlight and shadow below the voxel manipulator. while (!data.data.empty()) { @@ -1231,7 +1231,7 @@ void repair_block_light(ServerMap *map, MapBlock *block, // For each border of the block: for (const VoxelArea &a : block_pad) { - v3s16 relpos; + v3POS relpos; // For each node of the border: for (relpos.X = a.MinEdge.X; relpos.X <= a.MaxEdge.X; relpos.X++) for (relpos.Z = a.MinEdge.Z; relpos.Z <= a.MaxEdge.Z; relpos.Z++) @@ -1321,7 +1321,7 @@ void VoxelLineIterator::next() } } -s16 VoxelLineIterator::getIndex(v3s16 voxel){ +POS VoxelLineIterator::getIndex(v3POS voxel){ return abs(voxel.X - m_start_node_pos.X) + abs(voxel.Y - m_start_node_pos.Y) + diff --git a/src/voxelalgorithms.h b/src/voxelalgorithms.h index bcbd3b586b..c6b12a4e8c 100644 --- a/src/voxelalgorithms.h +++ b/src/voxelalgorithms.h @@ -45,8 +45,8 @@ namespace voxalgo */ void update_lighting_nodes( Map *map, - const std::vector> &oldnodes, - std::map &modified_blocks); + const std::vector> &oldnodes, + std::map &modified_blocks); /*! * Updates borders of the given mapblock. @@ -58,7 +58,7 @@ void update_lighting_nodes( * the function modified */ void update_block_border_lighting(Map *map, MapBlock *block, - std::map &modified_blocks); + std::map &modified_blocks); /*! * Copies back nodes from a voxel manipulator @@ -69,7 +69,7 @@ void update_block_border_lighting(Map *map, MapBlock *block, * the function modified */ void blit_back_with_light(ServerMap *map, MMVManip *vm, - std::map *modified_blocks); + std::map *modified_blocks); /*! * Corrects the light in a map block. @@ -78,7 +78,7 @@ void blit_back_with_light(ServerMap *map, MMVManip *vm, * \param block the block to update */ void repair_block_light(ServerMap *map, MapBlock *block, - std::map *modified_blocks); + std::map *modified_blocks); /*! * This class iterates trough voxels that intersect with @@ -108,13 +108,13 @@ struct VoxelLineIterator * Direction of the line. Each component can be -1 or 1 (if a * component of the line's vector is 0, then there will be 1). */ - v3s16 m_step_directions { 1, 1, 1 }; + v3POS m_step_directions { 1, 1, 1 }; //! Position of the current node. - v3s16 m_current_node_pos; + v3POS m_current_node_pos; //! Index of the current node s16 m_current_index = 0; //! Position of the start node. - v3s16 m_start_node_pos; + v3POS m_start_node_pos; //! Index of the last node s16 m_last_index; @@ -151,7 +151,7 @@ struct VoxelLineIterator * If voxel does not intersect with the line, * the result is undefined. */ - s16 getIndex(v3s16 voxel); + POS getIndex(v3POS voxel); }; } // namespace voxalgo From 489dfe2dce3e04e575c98a4d6ecd4429db5789d7 Mon Sep 17 00:00:00 2001 From: proller Date: Tue, 7 Dec 2021 05:20:13 +0300 Subject: [PATCH 02/36] Fix schematic --- src/mapgen/mg_schematic.cpp | 11 ++++++----- src/mapgen/mg_schematic.h | 2 +- src/script/lua_api/l_mapgen.cpp | 4 ++-- src/unittest/test_schematic.cpp | 6 +++--- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/mapgen/mg_schematic.cpp b/src/mapgen/mg_schematic.cpp index ee8a3a37c8..fa92ec6251 100644 --- a/src/mapgen/mg_schematic.cpp +++ b/src/mapgen/mg_schematic.cpp @@ -216,7 +216,7 @@ bool Schematic::placeOnVManip(MMVManip *vm, v3POS p, u32 flags, rot = (Rotation)myrand_range(ROTATE_0, ROTATE_270); v3POS s = (rot == ROTATE_90 || rot == ROTATE_270) ? - v3POS(size.Z, size.Y, size.X) : size; + v3POS(size.Z, size.Y, size.X) : v3POS(size.X, size.Y, size.Z); //// Adjust placement position if necessary if (flags & DECO_PLACE_CENTER_X) @@ -247,7 +247,7 @@ void Schematic::placeOnMap(ServerMap *map, v3POS p, u32 flags, rot = (Rotation)myrand_range(ROTATE_0, ROTATE_270); v3POS s = (rot == ROTATE_90 || rot == ROTATE_270) ? - v3POS(size.Z, size.Y, size.X) : size; + v3POS(size.Z, size.Y, size.X) : v3POS(size.X, size.Y, size.Z); //// Adjust placement position if necessary if (flags & DECO_PLACE_CENTER_X) @@ -304,7 +304,7 @@ bool Schematic::deserializeFromMts(std::istream *is) } //// Read size - size = readV3POS(ss); + size = readV3S16(ss); //// Read Y-slice probability values delete []slice_probs; @@ -375,7 +375,7 @@ bool Schematic::serializeToMts(std::ostream *os) const writeU32(ss, MTSCHEM_FILE_SIGNATURE); // signature writeU16(ss, MTSCHEM_FILE_VER_HIGHEST_WRITE); // version - writeV3POS(ss, size); // schematic size + writeV3S16(ss, size); // schematic size for (int y = 0; y != size.Y; y++) // Y slice probabilities writeU8(ss, slice_probs[y]); @@ -556,7 +556,8 @@ bool Schematic::getSchematicFromMap(Map *map, v3POS p1, v3POS p2) v3BPOS bp2 = getNodeBlockPos(p2); vm->initialEmerge(bp1, bp2); - size = p2 - p1 + 1; + v3BPOS size_pos = p2 - p1 + 1; + size = v3s16(size_pos.X, size_pos.Y, size_pos.Z); slice_probs = new u8[size.Y]; for (s16 y = 0; y != size.Y; y++) diff --git a/src/mapgen/mg_schematic.h b/src/mapgen/mg_schematic.h index faa3ca9352..e64120a1fb 100644 --- a/src/mapgen/mg_schematic.h +++ b/src/mapgen/mg_schematic.h @@ -120,7 +120,7 @@ class Schematic : public ObjDef, public NodeResolver { std::vector c_nodes; u32 flags = 0; - v3POS size; + v3s16 size; MapNode *schemdata = nullptr; u8 *slice_probs = nullptr; diff --git a/src/script/lua_api/l_mapgen.cpp b/src/script/lua_api/l_mapgen.cpp index 8e4d80c606..62672ac7be 100644 --- a/src/script/lua_api/l_mapgen.cpp +++ b/src/script/lua_api/l_mapgen.cpp @@ -228,7 +228,7 @@ bool read_schematic_def(lua_State *L, int index, //// Get schematic size lua_getfield(L, index, "size"); - v3POS size = check_v3POS(L, -1); + v3s16 size = check_v3s16(L, -1); lua_pop(L, 1); schem->size = size; @@ -1718,7 +1718,7 @@ int ModApiMapgen::l_read_schematic(lua_State *L) lua_createtable(L, 0, (write_yslice == "none") ? 2 : 3); // Create the size field - push_v3POS(L, schem->size); + push_v3s16(L, schem->size); lua_setfield(L, 1, "size"); // Create the yslice_prob field diff --git a/src/unittest/test_schematic.cpp b/src/unittest/test_schematic.cpp index bc8fc6d15e..d2f027eb4c 100644 --- a/src/unittest/test_schematic.cpp +++ b/src/unittest/test_schematic.cpp @@ -60,7 +60,7 @@ void TestSchematic::runTests(IGameDef *gamedef) void TestSchematic::testMtsSerializeDeserialize(const NodeDefManager *ndef) { - static const v3POS size(7, 6, 4); + static const v3s16 size(7, 6, 4); static const u32 volume = size.X * size.Y * size.Z; std::stringstream ss(std::ios_base::binary | @@ -110,7 +110,7 @@ void TestSchematic::testMtsSerializeDeserialize(const NodeDefManager *ndef) void TestSchematic::testLuaTableSerialize(const NodeDefManager *ndef) { - static const v3POS size(3, 3, 3); + static const v3s16 size(3, 3, 3); static const u32 volume = size.X * size.Y * size.Z; Schematic schem; @@ -138,7 +138,7 @@ void TestSchematic::testLuaTableSerialize(const NodeDefManager *ndef) void TestSchematic::testFileSerializeDeserialize(const NodeDefManager *ndef) { - static const v3POS size(3, 3, 3); + static const v3s16 size(3, 3, 3); static const u32 volume = size.X * size.Y * size.Z; static const content_t content_map[] = { CONTENT_AIR, From 17a32c268ea59e082127e0615d8113168422407c Mon Sep 17 00:00:00 2001 From: proller Date: Tue, 7 Dec 2021 16:21:52 +0300 Subject: [PATCH 03/36] Rename to *pos_t* --- src/client/camera.cpp | 6 +- src/client/camera.h | 4 +- src/client/client.cpp | 72 +++--- src/client/client.h | 30 +-- src/client/clientenvironment.cpp | 4 +- src/client/clientenvironment.h | 6 +- src/client/clientlauncher.cpp | 6 +- src/client/clientmap.cpp | 56 ++--- src/client/clientmap.h | 32 +-- src/client/clouds.cpp | 2 +- src/client/clouds.h | 4 +- src/client/content_cao.cpp | 12 +- src/client/content_cao.h | 2 +- src/client/content_mapblock.cpp | 104 ++++----- src/client/content_mapblock.h | 10 +- src/client/game.cpp | 82 +++---- src/client/hud.cpp | 20 +- src/client/hud.h | 14 +- src/client/localplayer.cpp | 74 +++--- src/client/localplayer.h | 12 +- src/client/mapblock_mesh.cpp | 166 ++++++------- src/client/mapblock_mesh.h | 22 +- src/client/mesh_generator_thread.cpp | 24 +- src/client/mesh_generator_thread.h | 22 +- src/client/minimap.cpp | 48 ++-- src/client/minimap.h | 22 +- src/client/particles.cpp | 10 +- src/client/particles.h | 6 +- src/client/shadows/dynamicshadows.cpp | 2 +- src/client/shadows/dynamicshadows.h | 2 +- src/client/tile.cpp | 2 +- src/clientiface.cpp | 28 +-- src/clientiface.h | 28 +-- src/collision.cpp | 14 +- src/collision.h | 2 +- src/content_nodemeta.cpp | 2 +- src/database/database-dummy.cpp | 8 +- src/database/database-dummy.h | 8 +- src/database/database-leveldb.cpp | 8 +- src/database/database-leveldb.h | 8 +- src/database/database-postgresql.cpp | 10 +- src/database/database-postgresql.h | 12 +- src/database/database-redis.cpp | 8 +- src/database/database-redis.h | 8 +- src/database/database-sqlite3.cpp | 10 +- src/database/database-sqlite3.h | 10 +- src/database/database.cpp | 16 +- src/database/database.h | 18 +- src/emerge.cpp | 60 ++--- src/emerge.h | 26 +-- src/environment.cpp | 18 +- src/environment.h | 2 +- src/face_position_cache.cpp | 12 +- src/face_position_cache.h | 6 +- src/gui/guiHyperText.cpp | 8 +- src/gui/guiHyperText.h | 4 +- src/inventorymanager.h | 4 +- src/irr_v2d.h | 4 +- src/irr_v3d.h | 4 +- src/irrlichttypes.h | 11 +- src/main.cpp | 8 +- src/map.cpp | 310 ++++++++++++------------- src/map.h | 122 +++++----- src/mapblock.cpp | 22 +- src/mapblock.h | 56 ++--- src/mapgen/cavegen.cpp | 102 ++++---- src/mapgen/cavegen.h | 48 ++-- src/mapgen/dungeongen.cpp | 176 +++++++------- src/mapgen/dungeongen.h | 46 ++-- src/mapgen/mapgen.cpp | 130 +++++------ src/mapgen/mapgen.h | 74 +++--- src/mapgen/mapgen_carpathian.cpp | 26 +-- src/mapgen/mapgen_carpathian.h | 12 +- src/mapgen/mapgen_flat.cpp | 42 ++-- src/mapgen/mapgen_flat.h | 18 +- src/mapgen/mapgen_fractal.cpp | 34 +-- src/mapgen/mapgen_fractal.h | 12 +- src/mapgen/mapgen_singlenode.cpp | 16 +- src/mapgen/mapgen_singlenode.h | 2 +- src/mapgen/mapgen_v5.cpp | 24 +- src/mapgen/mapgen_v5.h | 12 +- src/mapgen/mapgen_v6.cpp | 180 +++++++------- src/mapgen/mapgen_v6.h | 46 ++-- src/mapgen/mapgen_v7.cpp | 44 ++-- src/mapgen/mapgen_v7.h | 40 ++-- src/mapgen/mapgen_valleys.cpp | 32 +-- src/mapgen/mapgen_valleys.h | 12 +- src/mapgen/mg_biome.cpp | 24 +- src/mapgen/mg_biome.h | 50 ++-- src/mapgen/mg_decoration.cpp | 74 +++--- src/mapgen/mg_decoration.h | 18 +- src/mapgen/mg_ore.cpp | 16 +- src/mapgen/mg_ore.h | 22 +- src/mapgen/mg_schematic.cpp | 42 ++-- src/mapgen/mg_schematic.h | 12 +- src/mapgen/treegen.cpp | 82 +++---- src/mapgen/treegen.h | 10 +- src/mapnode.cpp | 34 +-- src/mapnode.h | 4 +- src/mapsector.cpp | 20 +- src/mapsector.h | 18 +- src/network/clientpackethandler.cpp | 20 +- src/network/networkprotocol.h | 16 +- src/network/serverpackethandler.cpp | 38 +-- src/nodedef.h | 4 +- src/nodemetadata.cpp | 14 +- src/nodemetadata.h | 10 +- src/nodetimer.cpp | 4 +- src/nodetimer.h | 20 +- src/pathfinder.cpp | 220 +++++++++--------- src/pathfinder.h | 6 +- src/raycast.cpp | 2 +- src/raycast.h | 6 +- src/reflowscan.cpp | 12 +- src/reflowscan.h | 6 +- src/rollback.cpp | 18 +- src/rollback.h | 12 +- src/rollback_interface.cpp | 4 +- src/rollback_interface.h | 12 +- src/script/common/c_content.cpp | 8 +- src/script/common/c_converter.cpp | 8 +- src/script/common/c_converter.h | 14 +- src/script/cpp_api/s_client.cpp | 8 +- src/script/cpp_api/s_client.h | 4 +- src/script/cpp_api/s_env.cpp | 20 +- src/script/cpp_api/s_env.h | 6 +- src/script/cpp_api/s_item.cpp | 2 +- src/script/cpp_api/s_item.h | 2 +- src/script/cpp_api/s_node.cpp | 32 +-- src/script/cpp_api/s_node.h | 16 +- src/script/cpp_api/s_nodemeta.cpp | 12 +- src/script/lua_api/l_areastore.cpp | 12 +- src/script/lua_api/l_client.cpp | 4 +- src/script/lua_api/l_env.cpp | 152 ++++++------ src/script/lua_api/l_env.h | 14 +- src/script/lua_api/l_inventory.cpp | 4 +- src/script/lua_api/l_mapgen.cpp | 52 ++--- src/script/lua_api/l_minimap.cpp | 4 +- src/script/lua_api/l_nodemeta.cpp | 4 +- src/script/lua_api/l_nodemeta.h | 6 +- src/script/lua_api/l_nodetimer.cpp | 2 +- src/script/lua_api/l_nodetimer.h | 6 +- src/script/lua_api/l_noise.cpp | 8 +- src/script/lua_api/l_noise.h | 2 +- src/script/lua_api/l_object.cpp | 2 +- src/script/lua_api/l_rollback.cpp | 4 +- src/script/lua_api/l_vmanip.cpp | 40 ++-- src/script/lua_api/l_vmanip.h | 4 +- src/server.cpp | 36 +-- src/server.h | 10 +- src/server/player_sao.cpp | 10 +- src/server/player_sao.h | 8 +- src/server/serveractiveobject.h | 2 +- src/serverenvironment.cpp | 106 ++++----- src/serverenvironment.h | 40 ++-- src/settings.cpp | 6 +- src/settings.h | 6 +- src/unittest/test.cpp | 112 ++++----- src/unittest/test_areastore.cpp | 30 +-- src/unittest/test_voxelalgorithms.cpp | 10 +- src/unittest/test_voxelarea.cpp | 218 ++++++++--------- src/unittest/test_voxelmanipulator.cpp | 22 +- src/util/areastore.cpp | 24 +- src/util/areastore.h | 22 +- src/util/basic_macros.h | 2 +- src/util/directiontables.cpp | 140 +++++------ src/util/directiontables.h | 8 +- src/util/numeric.cpp | 4 +- src/util/numeric.h | 60 ++--- src/util/pointedthing.cpp | 10 +- src/util/pointedthing.h | 14 +- src/util/serialize.h | 8 +- src/voxel.cpp | 10 +- src/voxel.h | 90 +++---- src/voxelalgorithms.cpp | 126 +++++----- src/voxelalgorithms.h | 18 +- 176 files changed, 2668 insertions(+), 2667 deletions(-) diff --git a/src/client/camera.cpp b/src/client/camera.cpp index 534e3e8a2f..1fc45927cf 100644 --- a/src/client/camera.cpp +++ b/src/client/camera.cpp @@ -452,11 +452,11 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 busytime, f32 tool_r // Update offset if too far away from the center of the map m_camera_offset.X += CAMERA_OFFSET_STEP* - (((POS)(my_cp.X/BS) - m_camera_offset.X)/CAMERA_OFFSET_STEP); + (((pos_t)(my_cp.X/BS) - m_camera_offset.X)/CAMERA_OFFSET_STEP); m_camera_offset.Y += CAMERA_OFFSET_STEP* - (((POS)(my_cp.Y/BS) - m_camera_offset.Y)/CAMERA_OFFSET_STEP); + (((pos_t)(my_cp.Y/BS) - m_camera_offset.Y)/CAMERA_OFFSET_STEP); m_camera_offset.Z += CAMERA_OFFSET_STEP* - (((POS)(my_cp.Z/BS) - m_camera_offset.Z)/CAMERA_OFFSET_STEP); + (((pos_t)(my_cp.Z/BS) - m_camera_offset.Z)/CAMERA_OFFSET_STEP); // Set camera node transformation m_cameranode->setPosition(my_cp-intToFloat(m_camera_offset, BS)); diff --git a/src/client/camera.h b/src/client/camera.h index c293156cd5..2195377200 100644 --- a/src/client/camera.h +++ b/src/client/camera.h @@ -110,7 +110,7 @@ class Camera } // Get the camera offset - inline v3POS getOffset() const + inline v3pos_t getOffset() const { return m_camera_offset; } @@ -213,7 +213,7 @@ class Camera // Absolute camera direction v3f m_camera_direction; // Camera offset - v3POS m_camera_offset; + v3pos_t m_camera_offset; bool m_stepheight_smooth_active = false; diff --git a/src/client/client.cpp b/src/client/client.cpp index a7a0abff77..478bca8271 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -384,7 +384,7 @@ void Client::step(float dtime) */ const float map_timer_and_unload_dtime = 5.25; if(m_map_timer_and_unload_interval.step(dtime, map_timer_and_unload_dtime)) { - std::vector deleted_blocks; + std::vector deleted_blocks; m_env.getMap().timerUpdate(map_timer_and_unload_dtime, g_settings->getFloat("client_unload_unused_data_timeout"), g_settings->getS32("client_mapblock_limit"), @@ -395,8 +395,8 @@ void Client::step(float dtime) NOTE: This loop is intentionally iterated the way it is. */ - std::vector::iterator i = deleted_blocks.begin(); - std::vector sendlist; + std::vector::iterator i = deleted_blocks.begin(); + std::vector sendlist; for(;;) { if(sendlist.size() == 255 || i == deleted_blocks.end()) { if(sendlist.empty()) @@ -404,8 +404,8 @@ void Client::step(float dtime) /* [0] u16 command [2] u8 count - [3] v3POS pos_0 - [3+6] v3POS pos_1 + [3] v3pos_t pos_0 + [3+6] v3pos_t pos_1 ... */ @@ -489,7 +489,7 @@ void Client::step(float dtime) */ { int num_processed_meshes = 0; - std::vector blocks_to_ack; + std::vector blocks_to_ack; while (!m_mesh_update_thread.m_queue_out.empty()) { num_processed_meshes++; @@ -1097,24 +1097,24 @@ void Client::startAuth(AuthMechanism chosen_auth_mechanism) } } -void Client::sendDeletedBlocks(std::vector &blocks) +void Client::sendDeletedBlocks(std::vector &blocks) { - NetworkPacket pkt(TOSERVER_DELETEDBLOCKS, 1 + sizeof(v3POS) * blocks.size()); + NetworkPacket pkt(TOSERVER_DELETEDBLOCKS, 1 + sizeof(v3pos_t) * blocks.size()); pkt << (u8) blocks.size(); - for (const v3POS &block : blocks) { + for (const v3pos_t &block : blocks) { pkt << block; } Send(&pkt); } -void Client::sendGotBlocks(const std::vector &blocks) +void Client::sendGotBlocks(const std::vector &blocks) { NetworkPacket pkt(TOSERVER_GOTBLOCKS, 1 + 6 * blocks.size()); pkt << (u8) blocks.size(); - for (const v3POS &block : blocks) + for (const v3pos_t &block : blocks) pkt << block; Send(&pkt); @@ -1135,7 +1135,7 @@ void Client::sendRemovedSounds(std::vector &soundList) Send(&pkt); } -void Client::sendNodemetaFields(v3POS p, const std::string &formname, +void Client::sendNodemetaFields(v3pos_t p, const std::string &formname, const StringMap &fields) { size_t fields_size = fields.size(); @@ -1332,9 +1332,9 @@ void Client::sendHaveMedia(const std::vector &tokens) Send(&pkt); } -void Client::removeNode(v3POS p) +void Client::removeNode(v3pos_t p) { - std::map modified_blocks; + std::map modified_blocks; try { m_env.getMap().removeNodeAndUpdate(p, modified_blocks); @@ -1354,10 +1354,10 @@ void Client::removeNode(v3POS p) * @param is_valid_position * @return */ -MapNode Client::CSMGetNode(v3POS p, bool *is_valid_position) +MapNode Client::CSMGetNode(v3pos_t p, bool *is_valid_position) { if (checkCSMRestrictionFlag(CSMRestrictionFlags::CSM_RF_LOOKUP_NODES)) { - v3POS ppos = floatToInt(m_env.getLocalPlayer()->getPosition(), BS); + v3pos_t ppos = floatToInt(m_env.getLocalPlayer()->getPosition(), BS); if ((u32) ppos.getDistanceFrom(p) > m_csm_restriction_noderange) { *is_valid_position = false; return {}; @@ -1366,36 +1366,36 @@ MapNode Client::CSMGetNode(v3POS p, bool *is_valid_position) return m_env.getMap().getNode(p, is_valid_position); } -int Client::CSMClampRadius(v3POS pos, int radius) +int Client::CSMClampRadius(v3pos_t pos, int radius) { if (!checkCSMRestrictionFlag(CSMRestrictionFlags::CSM_RF_LOOKUP_NODES)) return radius; // This is approximate and will cause some allowed nodes to be excluded - v3POS ppos = floatToInt(m_env.getLocalPlayer()->getPosition(), BS); + v3pos_t ppos = floatToInt(m_env.getLocalPlayer()->getPosition(), BS); u32 distance = ppos.getDistanceFrom(pos); if (distance >= m_csm_restriction_noderange) return 0; return std::min(radius, m_csm_restriction_noderange - distance); } -v3POS Client::CSMClampPos(v3POS pos) +v3pos_t Client::CSMClampPos(v3pos_t pos) { if (!checkCSMRestrictionFlag(CSMRestrictionFlags::CSM_RF_LOOKUP_NODES)) return pos; - v3POS ppos = floatToInt(m_env.getLocalPlayer()->getPosition(), BS); + v3pos_t ppos = floatToInt(m_env.getLocalPlayer()->getPosition(), BS); const int range = m_csm_restriction_noderange; - return v3POS( + return v3pos_t( core::clamp(pos.X, (int)ppos.X - range, (int)ppos.X + range), core::clamp(pos.Y, (int)ppos.Y - range, (int)ppos.Y + range), core::clamp(pos.Z, (int)ppos.Z - range, (int)ppos.Z + range) ); } -void Client::addNode(v3POS p, MapNode n, bool remove_metadata) +void Client::addNode(v3pos_t p, MapNode n, bool remove_metadata) { //TimeTaker timer1("Client::addNode()"); - std::map modified_blocks; + std::map modified_blocks; try { //TimeTaker timer3("Client::addNode(): addNodeAndUpdate"); @@ -1520,15 +1520,15 @@ int Client::getCrackLevel() return m_crack_level; } -v3POS Client::getCrackPos() +v3pos_t Client::getCrackPos() { return m_crack_pos; } -void Client::setCrack(int level, v3POS pos) +void Client::setCrack(int level, v3pos_t pos) { int old_crack_level = m_crack_level; - v3POS old_crack_pos = m_crack_pos; + v3pos_t old_crack_pos = m_crack_pos; m_crack_level = level; m_crack_pos = pos; @@ -1597,7 +1597,7 @@ void Client::typeChatMessage(const std::wstring &message) sendChatMessage(message); } -void Client::addUpdateMeshTask(v3BPOS p, bool ack_to_server, bool urgent) +void Client::addUpdateMeshTask(v3bpos_t p, bool ack_to_server, bool urgent) { // Check if the block exists to begin with. In the case when a non-existing // neighbor is automatically added, it may not. In that case we don't want @@ -1609,7 +1609,7 @@ void Client::addUpdateMeshTask(v3BPOS p, bool ack_to_server, bool urgent) m_mesh_update_thread.updateBlock(&m_env.getMap(), p, ack_to_server, urgent); } -void Client::addUpdateMeshTaskWithEdge(v3BPOS blockpos, bool ack_to_server, bool urgent) +void Client::addUpdateMeshTaskWithEdge(v3bpos_t blockpos, bool ack_to_server, bool urgent) { try{ addUpdateMeshTask(blockpos, ack_to_server, urgent); @@ -1620,24 +1620,24 @@ void Client::addUpdateMeshTaskWithEdge(v3BPOS blockpos, bool ack_to_server, bool for (int i=0;i<6;i++) { try{ - v3BPOS p = blockpos + g_6dirs[i]; + v3bpos_t p = blockpos + g_6dirs[i]; addUpdateMeshTask(p, false, urgent); } catch(InvalidPositionException &e){} } } -void Client::addUpdateMeshTaskForNode(v3POS nodepos, bool ack_to_server, bool urgent) +void Client::addUpdateMeshTaskForNode(v3pos_t nodepos, bool ack_to_server, bool urgent) { { - v3POS p = nodepos; + v3pos_t p = nodepos; infostream<<"Client::addUpdateMeshTaskForNode(): " <<"("< &blocks); - void sendGotBlocks(const std::vector &blocks); + void sendDeletedBlocks(std::vector &blocks); + void sendGotBlocks(const std::vector &blocks); void sendRemovedSounds(std::vector &soundList); // Helper function @@ -509,7 +509,7 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef // Block mesh animation parameters float m_animation_time = 0.0f; int m_crack_level = -1; - v3POS m_crack_pos; + v3pos_t m_crack_pos; // 0 <= m_daynight_i < DAYNIGHT_CACHE_COUNT //s32 m_daynight_i; //u32 m_daynight_ratio; diff --git a/src/client/clientenvironment.cpp b/src/client/clientenvironment.cpp index c7e3824036..e5867d09e1 100644 --- a/src/client/clientenvironment.cpp +++ b/src/client/clientenvironment.cpp @@ -301,7 +301,7 @@ void ClientEnvironment::step(float dtime) // (day: LIGHT_SUN, night: 0) MapNode node_at_lplayer(CONTENT_AIR, 0x0f, 0); - v3POS p = lplayer->getLightPosition(); + v3pos_t p = lplayer->getLightPosition(); node_at_lplayer = m_map->getNode(p); u16 light = getInteriorLight(node_at_lplayer, 0, m_client->ndef()); @@ -504,7 +504,7 @@ void ClientEnvironment::getSelectedActiveObjects( selection_box.MaxEdge + pos); v3f current_intersection; - v3POS current_normal; + v3pos_t current_normal; if (boxLineCollision(offsetted_box, shootline_on_map.start, line_vector, ¤t_intersection, ¤t_normal)) { objects.emplace_back((s16) obj->getId(), current_intersection, current_normal, diff --git a/src/client/clientenvironment.h b/src/client/clientenvironment.h index d433b98a87..1b64e26cbe 100644 --- a/src/client/clientenvironment.h +++ b/src/client/clientenvironment.h @@ -138,9 +138,9 @@ class ClientEnvironment : public Environment const std::list &getPlayerNames() { return m_player_names; } void addPlayerName(const std::string &name) { m_player_names.push_back(name); } void removePlayerName(const std::string &name) { m_player_names.remove(name); } - void updateCameraOffset(const v3POS &camera_offset) + void updateCameraOffset(const v3pos_t &camera_offset) { m_camera_offset = camera_offset; } - v3POS getCameraOffset() const { return m_camera_offset; } + v3pos_t getCameraOffset() const { return m_camera_offset; } private: ClientMap *m_map; LocalPlayer *m_local_player = nullptr; @@ -152,5 +152,5 @@ class ClientEnvironment : public Environment std::queue m_client_event_queue; IntervalLimiter m_active_object_light_update_interval; std::list m_player_names; - v3POS m_camera_offset; + v3pos_t m_camera_offset; }; diff --git a/src/client/clientlauncher.cpp b/src/client/clientlauncher.cpp index 3d8740cbfb..942ffb95f9 100644 --- a/src/client/clientlauncher.cpp +++ b/src/client/clientlauncher.cpp @@ -619,18 +619,18 @@ void ClientLauncher::speed_tests() { TimeTaker timer("Testing std::map speed"); - std::map map1; + std::map map1; tempf = -324; const s16 ii = 300; for (s16 y = 0; y < ii; y++) { for (s16 x = 0; x < ii; x++) { - map1[v2POS(x, y)] = tempf; + map1[v2pos_t(x, y)] = tempf; tempf += 1; } } for (s16 y = ii - 1; y >= 0; y--) { for (s16 x = 0; x < ii; x++) { - tempf = map1[v2POS(x, y)]; + tempf = map1[v2pos_t(x, y)]; } } } diff --git a/src/client/clientmap.cpp b/src/client/clientmap.cpp index fa3fca79bb..5fb7783c28 100644 --- a/src/client/clientmap.cpp +++ b/src/client/clientmap.cpp @@ -38,7 +38,7 @@ void MeshBufListList::clear() list.clear(); } -void MeshBufListList::add(scene::IMeshBuffer *buf, v3BPOS position, u8 layer) +void MeshBufListList::add(scene::IMeshBuffer *buf, v3bpos_t position, u8 layer) { // Append to the correct layer std::vector &list = lists[layer]; @@ -74,7 +74,7 @@ ClientMap::ClientMap( m_client(client), m_rendering_engine(rendering_engine), m_control(control), - m_drawlist(MapBlockComparer(v3BPOS(0,0,0))) + m_drawlist(MapBlockComparer(v3bpos_t(0,0,0))) { /* @@ -100,7 +100,7 @@ ClientMap::ClientMap( } -MapSector * ClientMap::emergeSector(v2BPOS p2d) +MapSector * ClientMap::emergeSector(v2bpos_t p2d) { // Check that it doesn't exist already MapSector *sector = getSectorNoGenerate(p2d); @@ -131,15 +131,15 @@ void ClientMap::OnRegisterSceneNode() } } -void ClientMap::getBlocksInViewRange(v3POS cam_pos_nodes, - v3POS *p_blocks_min, v3POS *p_blocks_max, float range) +void ClientMap::getBlocksInViewRange(v3pos_t cam_pos_nodes, + v3pos_t *p_blocks_min, v3pos_t *p_blocks_max, float range) { if (range <= 0.0f) range = m_control.wanted_range; - v3POS box_nodes_d = range * v3POS(1, 1, 1); + v3pos_t box_nodes_d = range * v3pos_t(1, 1, 1); // Define p_nodes_min/max as v3s32 because 'cam_pos_nodes -/+ box_nodes_d' - // can exceed the range of v3POS when a large view range is used near the + // can exceed the range of v3pos_t when a large view range is used near the // world edges. v3s32 p_nodes_min( cam_pos_nodes.X - box_nodes_d.X, @@ -151,11 +151,11 @@ void ClientMap::getBlocksInViewRange(v3POS cam_pos_nodes, cam_pos_nodes.Z + box_nodes_d.Z); // Take a fair amount as we will be dropping more out later // Umm... these additions are a bit strange but they are needed. - *p_blocks_min = v3POS( + *p_blocks_min = v3pos_t( p_nodes_min.X / MAP_BLOCKSIZE - 3, p_nodes_min.Y / MAP_BLOCKSIZE - 3, p_nodes_min.Z / MAP_BLOCKSIZE - 3); - *p_blocks_max = v3POS( + *p_blocks_max = v3pos_t( p_nodes_max.X / MAP_BLOCKSIZE + 1, p_nodes_max.Y / MAP_BLOCKSIZE + 1, p_nodes_max.Z / MAP_BLOCKSIZE + 1); @@ -180,10 +180,10 @@ void ClientMap::updateDrawList() // Blocks are cropped better when they are drawn. const f32 camera_fov = m_camera_fov * 1.1f; - v3POS cam_pos_nodes = floatToInt(camera_position, BS); + v3pos_t cam_pos_nodes = floatToInt(camera_position, BS); - v3POS p_blocks_min; - v3POS p_blocks_max; + v3pos_t p_blocks_min; + v3pos_t p_blocks_max; getBlocksInViewRange(cam_pos_nodes, &p_blocks_min, &p_blocks_max); // Read the vision range, unless unlimited range is enabled. @@ -206,8 +206,8 @@ void ClientMap::updateDrawList() occlusion_culling_enabled = false; } - v3BPOS camera_block = getContainerPos(cam_pos_nodes, MAP_BLOCKSIZE); - m_drawlist = std::map(MapBlockComparer(camera_block)); + v3bpos_t camera_block = getContainerPos(cam_pos_nodes, MAP_BLOCKSIZE); + m_drawlist = std::map(MapBlockComparer(camera_block)); // Uncomment to debug occluded blocks in the wireframe mode // TODO: Include this as a flag for an extended debugging setting @@ -216,7 +216,7 @@ void ClientMap::updateDrawList() for (const auto §or_it : m_sectors) { MapSector *sector = sector_it.second; - v2BPOS sp = sector->getPos(); + v2bpos_t sp = sector->getPos(); blocks_loaded += sector->size(); if (!m_control.range_all) { @@ -245,8 +245,8 @@ void ClientMap::updateDrawList() continue; } - v3BPOS block_coord = block->getPos(); - v3POS block_position = block->getPosRelative() + MAP_BLOCKSIZE / 2; + v3bpos_t block_coord = block->getPos(); + v3pos_t block_position = block->getPosRelative() + MAP_BLOCKSIZE / 2; // First, perform a simple distance check, with a padding of one extra block. if (!m_control.range_all && @@ -330,11 +330,11 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass) MeshBufListList grouped_buffers; struct DrawDescriptor { - v3POS m_pos; + v3pos_t m_pos; scene::IMeshBuffer *m_buffer; bool m_reuse_material; - DrawDescriptor(const v3POS &pos, scene::IMeshBuffer *buffer, bool reuse_material) : + DrawDescriptor(const v3pos_t &pos, scene::IMeshBuffer *buffer, bool reuse_material) : m_pos(pos), m_buffer(buffer), m_reuse_material(reuse_material) {} }; @@ -343,7 +343,7 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass) video::SMaterial previous_material; for (auto &i : m_drawlist) { - v3BPOS block_pos = i.first; + v3bpos_t block_pos = i.first; MapBlock *block = i.second; // If the mesh of the block happened to get deleted, ignore it @@ -511,7 +511,7 @@ static bool getVisibleBrightness(Map *map, const v3f &p0, v3f dir, float step, bool allow_non_sunlight_propagates = false; // Check content nearly at camera position { - v3POS p = floatToInt(p0 /*+ dir * 3*BS*/, BS); + v3pos_t p = floatToInt(p0 /*+ dir * 3*BS*/, BS); MapNode n = map->getNode(p); if(ndef->get(n).param_type == CPT_LIGHT && !ndef->get(n).sunlight_propagates) @@ -519,7 +519,7 @@ static bool getVisibleBrightness(Map *map, const v3f &p0, v3f dir, float step, } // If would start at CONTENT_IGNORE, start closer { - v3POS p = floatToInt(pf, BS); + v3pos_t p = floatToInt(pf, BS); MapNode n = map->getNode(p); if(n.getContent() == CONTENT_IGNORE){ float newd = 2*BS; @@ -533,7 +533,7 @@ static bool getVisibleBrightness(Map *map, const v3f &p0, v3f dir, float step, distance += step; step *= step_multiplier; - v3POS p = floatToInt(pf, BS); + v3pos_t p = floatToInt(pf, BS); MapNode n = map->getNode(p); if (allow_allowing_non_sunlight_propagates && i == 0 && ndef->get(n).param_type == CPT_LIGHT && @@ -717,7 +717,7 @@ void ClientMap::renderMapShadows(video::IVideoDriver *driver, if (count > high_bound) break; - v3BPOS block_pos = i.first; + v3bpos_t block_pos = i.first; MapBlock *block = i.second; // If the mesh of the block happened to get deleted, ignore it @@ -811,12 +811,12 @@ void ClientMap::updateDrawListShadow(const v3f &shadow_light_pos, const v3f &sha // projection. const f32 camera_fov = m_camera_fov * 1.9f; - v3POS cam_pos_nodes = floatToInt(camera_position, BS); - v3POS p_blocks_min; - v3POS p_blocks_max; + v3pos_t cam_pos_nodes = floatToInt(camera_position, BS); + v3pos_t p_blocks_min; + v3pos_t p_blocks_max; getBlocksInViewRange(cam_pos_nodes, &p_blocks_min, &p_blocks_max, shadow_range); - std::vector blocks_in_range; + std::vector blocks_in_range; for (auto &i : m_drawlist_shadow) { MapBlock *block = i.second; diff --git a/src/client/clientmap.h b/src/client/clientmap.h index 288c2b0eea..f53e3d8636 100644 --- a/src/client/clientmap.h +++ b/src/client/clientmap.h @@ -38,7 +38,7 @@ struct MapDrawControl struct MeshBufList { video::SMaterial m; - std::vector> bufs; + std::vector> bufs; }; struct MeshBufListList @@ -51,7 +51,7 @@ struct MeshBufListList std::vector lists[MAX_TILE_LAYERS]; void clear(); - void add(scene::IMeshBuffer *buf, v3BPOS position, u8 layer); + void add(scene::IMeshBuffer *buf, v3bpos_t position, u8 layer); }; class Client; @@ -85,16 +85,16 @@ class ClientMap : public Map, public scene::ISceneNode ISceneNode::drop(); } - void updateCamera(const v3f &pos, const v3f &dir, f32 fov, const v3POS &offset) + void updateCamera(const v3f &pos, const v3f &dir, f32 fov, const v3pos_t &offset) { - v3BPOS previous_block = getContainerPos(floatToInt(m_camera_position, BS) + m_camera_offset, MAP_BLOCKSIZE); + v3bpos_t previous_block = getContainerPos(floatToInt(m_camera_position, BS) + m_camera_offset, MAP_BLOCKSIZE); m_camera_position = pos; m_camera_direction = dir; m_camera_fov = fov; m_camera_offset = offset; - v3BPOS current_block = getContainerPos(floatToInt(m_camera_position, BS) + m_camera_offset, MAP_BLOCKSIZE); + v3bpos_t current_block = getContainerPos(floatToInt(m_camera_position, BS) + m_camera_offset, MAP_BLOCKSIZE); // reorder the blocks when camera crosses block boundary if (previous_block != current_block) @@ -104,9 +104,9 @@ class ClientMap : public Map, public scene::ISceneNode /* Forcefully get a sector from somewhere */ - MapSector * emergeSector(v2BPOS p); + MapSector * emergeSector(v2bpos_t p); - //void deSerializeSector(v2POS p2d, std::istream &is); + //void deSerializeSector(v2pos_t p2d, std::istream &is); /* ISceneNode methods @@ -126,8 +126,8 @@ class ClientMap : public Map, public scene::ISceneNode return m_box; } - void getBlocksInViewRange(v3POS cam_pos_nodes, - v3POS *p_blocks_min, v3POS *p_blocks_max, float range=-1.0f); + void getBlocksInViewRange(v3pos_t cam_pos_nodes, + v3pos_t *p_blocks_min, v3pos_t *p_blocks_max, float range=-1.0f); void updateDrawList(); void updateDrawListShadow(const v3f &shadow_light_pos, const v3f &shadow_light_dir, float shadow_range); // Returns true if draw list needs updating before drawing the next frame. @@ -154,9 +154,9 @@ class ClientMap : public Map, public scene::ISceneNode class MapBlockComparer { public: - MapBlockComparer(const v3BPOS &camera_block) : m_camera_block(camera_block) {} + MapBlockComparer(const v3bpos_t &camera_block) : m_camera_block(camera_block) {} - bool operator() (const v3BPOS &left, const v3BPOS &right) const + bool operator() (const v3bpos_t &left, const v3bpos_t &right) const { auto distance_left = left.getDistanceFromSQ(m_camera_block); auto distance_right = right.getDistanceFromSQ(m_camera_block); @@ -164,7 +164,7 @@ class ClientMap : public Map, public scene::ISceneNode } private: - v3BPOS m_camera_block; + v3bpos_t m_camera_block; }; Client *m_client; @@ -178,13 +178,13 @@ class ClientMap : public Map, public scene::ISceneNode v3f m_camera_position = v3f(0,0,0); v3f m_camera_direction = v3f(0,0,1); f32 m_camera_fov = M_PI; - v3POS m_camera_offset; + v3pos_t m_camera_offset; - std::map m_drawlist; - std::map m_drawlist_shadow; + std::map m_drawlist; + std::map m_drawlist_shadow; bool m_needs_update_drawlist; - std::set m_last_drawn_sectors; + std::set m_last_drawn_sectors; bool m_cache_trilinear_filter; bool m_cache_bilinear_filter; diff --git a/src/client/clouds.cpp b/src/client/clouds.cpp index d01f932e1a..af0f377d8a 100644 --- a/src/client/clouds.cpp +++ b/src/client/clouds.cpp @@ -120,7 +120,7 @@ void Clouds::render() // The center point of drawing in the noise v2f center_of_drawing_in_noise_f = -cloud_origin_from_camera_f; // The integer center point of drawing in the noise - v2POS center_of_drawing_in_noise_i( + v2pos_t center_of_drawing_in_noise_i( std::floor(center_of_drawing_in_noise_f.X / cloud_size), std::floor(center_of_drawing_in_noise_f.Y / cloud_size) ); diff --git a/src/client/clouds.h b/src/client/clouds.h index e9c5d0f61b..5788d6a787 100644 --- a/src/client/clouds.h +++ b/src/client/clouds.h @@ -72,7 +72,7 @@ class Clouds : public scene::ISceneNode void update(const v3f &camera_p, const video::SColorf &color); - void updateCameraOffset(const v3POS &camera_offset) + void updateCameraOffset(const v3pos_t &camera_offset) { m_camera_offset = camera_offset; updateBox(); @@ -135,7 +135,7 @@ class Clouds : public scene::ISceneNode u32 m_seed; v3f m_camera_pos; v2f m_origin; - v3POS m_camera_offset; + v3pos_t m_camera_offset; video::SColorf m_color = video::SColorf(1.0f, 1.0f, 1.0f, 1.0f); CloudParams m_params; bool m_camera_inside_cloud = false; diff --git a/src/client/content_cao.cpp b/src/client/content_cao.cpp index 62d5cc5030..e1f42d81e5 100644 --- a/src/client/content_cao.cpp +++ b/src/client/content_cao.cpp @@ -427,7 +427,7 @@ const v3f GenericCAO::getPosition() const // Calculate real position in world based on MatrixNode if (m_matrixnode) { - v3POS camera_offset = m_env->getCameraOffset(); + v3pos_t camera_offset = m_env->getCameraOffset(); return m_matrixnode->getAbsolutePosition() + intToFloat(camera_offset, BS); } @@ -868,7 +868,7 @@ void GenericCAO::updateLight(u32 day_night_ratio) u8 light_at_pos = 0; bool pos_ok = false; - v3POS pos[3]; + v3pos_t pos[3]; u16 npos = getLightPosition(pos); for (u16 i = 0; i < npos; i++) { bool this_ok; @@ -930,7 +930,7 @@ void GenericCAO::setNodeLight(u8 light) } } -u16 GenericCAO::getLightPosition(v3POS *pos) +u16 GenericCAO::getLightPosition(v3pos_t *pos) { const auto &box = m_prop.collisionbox; pos[0] = floatToInt(m_position + box.MinEdge * BS, BS); @@ -1005,7 +1005,7 @@ void GenericCAO::updateNodePos() scene::ISceneNode *node = getSceneNode(); if (node) { - v3POS camera_offset = m_env->getCameraOffset(); + v3pos_t camera_offset = m_env->getCameraOffset(); v3f pos = pos_translator.val_current - intToFloat(camera_offset, BS); getPosRotMatrix().setTranslation(pos); @@ -1169,7 +1169,7 @@ void GenericCAO::step(float dtime, ClientEnvironment *env) m_step_distance_counter = 0.0f; if (!m_is_local_player && m_prop.makes_footstep_sound) { const NodeDefManager *ndef = m_client->ndef(); - v3POS p = floatToInt(getPosition() + + v3pos_t p = floatToInt(getPosition() + v3f(0.0f, (m_prop.collisionbox.MinEdge.Y - 0.5f) * BS, 0.0f), BS); MapNode n = m_env->getMap().getNode(p); SimpleSoundSpec spec = ndef->get(n).sound_footstep; @@ -1596,7 +1596,7 @@ void GenericCAO::updateAttachments() if (!parent) { // Detach or don't attach if (m_matrixnode) { - v3POS camera_offset = m_env->getCameraOffset(); + v3pos_t camera_offset = m_env->getCameraOffset(); v3f old_pos = getPosition(); m_matrixnode->setParent(m_smgr->getRootSceneNode()); diff --git a/src/client/content_cao.h b/src/client/content_cao.h index 72bb8c3c47..7cd855b93a 100644 --- a/src/client/content_cao.h +++ b/src/client/content_cao.h @@ -250,7 +250,7 @@ class GenericCAO : public ClientActiveObject /* Get light position(s). * returns number of positions written into pos[], which must have space * for at least 3 vectors. */ - u16 getLightPosition(v3POS *pos); + u16 getLightPosition(v3pos_t *pos); void updateNametag(); diff --git a/src/client/content_mapblock.cpp b/src/client/content_mapblock.cpp index 5ba915ea70..544659651d 100644 --- a/src/client/content_mapblock.cpp +++ b/src/client/content_mapblock.cpp @@ -44,15 +44,15 @@ with this program; if not, write to the Free Software Foundation, Inc., // Corresponding offsets are listed in g_27dirs #define FRAMED_NEIGHBOR_COUNT 18 -static const v3POS light_dirs[8] = { - v3POS(-1, -1, -1), - v3POS(-1, -1, 1), - v3POS(-1, 1, -1), - v3POS(-1, 1, 1), - v3POS( 1, -1, -1), - v3POS( 1, -1, 1), - v3POS( 1, 1, -1), - v3POS( 1, 1, 1), +static const v3pos_t light_dirs[8] = { + v3pos_t(-1, -1, -1), + v3pos_t(-1, -1, 1), + v3pos_t(-1, 1, -1), + v3pos_t(-1, 1, 1), + v3pos_t( 1, -1, -1), + v3pos_t( 1, -1, 1), + v3pos_t( 1, 1, -1), + v3pos_t( 1, 1, 1), }; // Standard index set to make a quad on 4 vertices @@ -94,7 +94,7 @@ void MapblockMeshGenerator::getTile(int index, TileSpec *tile) } // Returns a tile, ready for use, rotated according to the node facedir. -void MapblockMeshGenerator::getTile(v3POS direction, TileSpec *tile) +void MapblockMeshGenerator::getTile(v3pos_t direction, TileSpec *tile) { getNodeTile(n, p, direction, data, *tile); } @@ -118,13 +118,13 @@ void MapblockMeshGenerator::getSpecialTile(int index, TileSpec *tile, bool apply top_layer->material_flags |= MATERIAL_FLAG_CRACK; } -void MapblockMeshGenerator::drawQuad(v3f *coords, const v3POS &normal, +void MapblockMeshGenerator::drawQuad(v3f *coords, const v3pos_t &normal, float vertical_tiling) { const v2f tcoords[4] = {v2f(0.0, 0.0), v2f(1.0, 0.0), v2f(1.0, vertical_tiling), v2f(0.0, vertical_tiling)}; video::S3DVertex vertices[4]; - bool shade_face = !f->light_source && (normal != v3POS(0, 0, 0)); + bool shade_face = !f->light_source && (normal != v3pos_t(0, 0, 0)); v3f normal2(normal.X, normal.Y, normal.Z); for (int j = 0; j < 4; j++) { vertices[j].Pos = coords[j] + origin; @@ -411,8 +411,8 @@ void MapblockMeshGenerator::prepareLiquidNodeDrawing() getSpecialTile(0, &tile_liquid_top); getSpecialTile(1, &tile_liquid); - MapNode ntop = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3POS(p.X, p.Y + 1, p.Z)); - MapNode nbottom = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3POS(p.X, p.Y - 1, p.Z)); + MapNode ntop = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3pos_t(p.X, p.Y + 1, p.Z)); + MapNode nbottom = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3pos_t(p.X, p.Y - 1, p.Z)); c_flowing = f->liquid_alternative_flowing_id; c_source = f->liquid_alternative_source_id; top_is_same_liquid = (ntop.getContent() == c_flowing) || (ntop.getContent() == c_source); @@ -447,7 +447,7 @@ void MapblockMeshGenerator::getLiquidNeighborhood() for (int w = -1; w <= 1; w++) for (int u = -1; u <= 1; u++) { NeighborData &neighbor = liquid_neighbors[w + 1][u + 1]; - v3POS p2 = p + v3POS(u, 0, w); + v3pos_t p2 = p + v3pos_t(u, 0, w); MapNode n2 = data->m_vmanip.getNodeNoEx(blockpos_nodes + p2); neighbor.content = n2.getContent(); neighbor.level = -0.5 * BS; @@ -522,17 +522,17 @@ f32 MapblockMeshGenerator::getCornerLevel(int i, int k) namespace { struct LiquidFaceDesc { - v3POS dir; // XZ - v3POS p[2]; // XZ only; 1 means +, 0 means - + v3pos_t dir; // XZ + v3pos_t p[2]; // XZ only; 1 means +, 0 means - }; struct UV { int u, v; }; static const LiquidFaceDesc liquid_base_faces[4] = { - {v3POS( 1, 0, 0), {v3POS(1, 0, 1), v3POS(1, 0, 0)}}, - {v3POS(-1, 0, 0), {v3POS(0, 0, 0), v3POS(0, 0, 1)}}, - {v3POS( 0, 0, 1), {v3POS(0, 0, 1), v3POS(1, 0, 1)}}, - {v3POS( 0, 0, -1), {v3POS(1, 0, 0), v3POS(0, 0, 0)}}, + {v3pos_t( 1, 0, 0), {v3pos_t(1, 0, 1), v3pos_t(1, 0, 0)}}, + {v3pos_t(-1, 0, 0), {v3pos_t(0, 0, 0), v3pos_t(0, 0, 1)}}, + {v3pos_t( 0, 0, 1), {v3pos_t(0, 0, 1), v3pos_t(1, 0, 1)}}, + {v3pos_t( 0, 0, -1), {v3pos_t(1, 0, 0), v3pos_t(0, 0, 0)}}, }; static const UV liquid_base_vertices[4] = { {0, 1}, @@ -565,7 +565,7 @@ void MapblockMeshGenerator::drawLiquidSides() video::S3DVertex vertices[4]; for (int j = 0; j < 4; j++) { const UV &vertex = liquid_base_vertices[j]; - const v3POS &base = face.p[vertex.u]; + const v3pos_t &base = face.p[vertex.u]; float v = vertex.v; v3f pos; @@ -674,8 +674,8 @@ void MapblockMeshGenerator::drawGlasslikeNode() for (int face = 0; face < 6; face++) { // Check this neighbor - v3POS dir = g_6dirs[face]; - v3POS neighbor_pos = blockpos_nodes + p + dir; + v3pos_t dir = g_6dirs[face]; + v3pos_t neighbor_pos = blockpos_nodes + p + dir; MapNode neighbor = data->m_vmanip.getNodeNoExNoEmerge(neighbor_pos); // Don't make face if neighbor is of same type if (neighbor.getContent() == n.getContent()) @@ -771,7 +771,7 @@ void MapblockMeshGenerator::drawGlasslikeFramedNode() for (int i = 0; i < FRAMED_NEIGHBOR_COUNT; i++) { if (!check_nb[i]) continue; - v3POS n2p = blockpos_nodes + p + g_26dirs[i]; + v3pos_t n2p = blockpos_nodes + p + g_26dirs[i]; MapNode n2 = data->m_vmanip.getNodeNoEx(n2p); content_t n2c = n2.getContent(); if (n2c == current) @@ -828,7 +828,7 @@ void MapblockMeshGenerator::drawGlasslikeFramedNode() vertex.rotateXZBy(-90); break; } } - v3POS dir = g_6dirs[face]; + v3pos_t dir = g_6dirs[face]; drawQuad(vertices, dir); } @@ -986,7 +986,7 @@ void MapblockMeshGenerator::drawPlantlikeQuad(float rotation, float quad_offset, } } - drawQuad(vertices, v3POS(0, 0, 0), plant_height); + drawQuad(vertices, v3pos_t(0, 0, 0), plant_height); } void MapblockMeshGenerator::drawPlantlike(bool is_rooted) @@ -1125,7 +1125,7 @@ void MapblockMeshGenerator::drawFirelikeNode() bool neighbor[6] = {0, 0, 0, 0, 0, 0}; content_t current = n.getContent(); for (int i = 0; i < 6; i++) { - v3POS n2p = blockpos_nodes + p + g_6dirs[i]; + v3pos_t n2p = blockpos_nodes + p + g_6dirs[i]; MapNode n2 = data->m_vmanip.getNodeNoEx(n2p); content_t n2c = n2.getContent(); if (n2c != CONTENT_IGNORE && n2c != CONTENT_AIR && n2c != current) { @@ -1195,7 +1195,7 @@ void MapblockMeshGenerator::drawFencelikeNode() tile = tile_nocrack; // Now a section of fence, +X, if there's a post there - v3POS p2 = p; + v3pos_t p2 = p; p2.X++; MapNode n2 = data->m_vmanip.getNodeNoEx(blockpos_nodes + p2); const ContentFeatures *f2 = &nodedef->get(n2); @@ -1239,7 +1239,7 @@ void MapblockMeshGenerator::drawFencelikeNode() } } -bool MapblockMeshGenerator::isSameRail(v3POS dir) +bool MapblockMeshGenerator::isSameRail(v3pos_t dir) { MapNode node2 = data->m_vmanip.getNodeNoEx(blockpos_nodes + p + dir); if (node2.getContent() == n.getContent()) @@ -1250,11 +1250,11 @@ bool MapblockMeshGenerator::isSameRail(v3POS dir) } namespace { - static const v3POS rail_direction[4] = { - v3POS( 0, 0, 1), - v3POS( 0, 0, -1), - v3POS(-1, 0, 0), - v3POS( 1, 0, 0), + static const v3pos_t rail_direction[4] = { + v3pos_t( 0, 0, 1), + v3pos_t( 0, 0, -1), + v3pos_t(-1, 0, 0), + v3pos_t( 1, 0, 0), }; static const int rail_slope_angle[4] = {0, 180, 90, -90}; @@ -1299,14 +1299,14 @@ void MapblockMeshGenerator::drawRaillikeNode() int tile_index; bool sloped = false; for (int dir = 0; dir < 4; dir++) { - bool rail_above = isSameRail(rail_direction[dir] + v3POS(0, 1, 0)); + bool rail_above = isSameRail(rail_direction[dir] + v3pos_t(0, 1, 0)); if (rail_above) { sloped = true; angle = rail_slope_angle[dir]; } if (rail_above || isSameRail(rail_direction[dir]) || - isSameRail(rail_direction[dir] + v3POS(0, -1, 0))) + isSameRail(rail_direction[dir] + v3pos_t(0, -1, 0))) code |= 1 << dir; } @@ -1335,23 +1335,23 @@ void MapblockMeshGenerator::drawRaillikeNode() } namespace { - static const v3POS nodebox_tile_dirs[6] = { - v3POS(0, 1, 0), - v3POS(0, -1, 0), - v3POS(1, 0, 0), - v3POS(-1, 0, 0), - v3POS(0, 0, 1), - v3POS(0, 0, -1) + static const v3pos_t nodebox_tile_dirs[6] = { + v3pos_t(0, 1, 0), + v3pos_t(0, -1, 0), + v3pos_t(1, 0, 0), + v3pos_t(-1, 0, 0), + v3pos_t(0, 0, 1), + v3pos_t(0, 0, -1) }; // we have this order for some reason... - static const v3POS nodebox_connection_dirs[6] = { - v3POS( 0, 1, 0), // top - v3POS( 0, -1, 0), // bottom - v3POS( 0, 0, -1), // front - v3POS(-1, 0, 0), // left - v3POS( 0, 0, 1), // back - v3POS( 1, 0, 0), // right + static const v3pos_t nodebox_connection_dirs[6] = { + v3pos_t( 0, 1, 0), // top + v3pos_t( 0, -1, 0), // bottom + v3pos_t( 0, 0, -1), // front + v3pos_t(-1, 0, 0), // left + v3pos_t( 0, 0, 1), // back + v3pos_t( 1, 0, 0), // right }; } @@ -1368,7 +1368,7 @@ void MapblockMeshGenerator::drawNodeboxNode() if (f->node_box.type == NODEBOX_CONNECTED) { for (int dir = 0; dir != 6; dir++) { u8 flag = 1 << dir; - v3POS p2 = blockpos_nodes + p + nodebox_connection_dirs[dir]; + v3pos_t p2 = blockpos_nodes + p + nodebox_connection_dirs[dir]; MapNode n2 = data->m_vmanip.getNodeNoEx(p2); if (nodedef->nodeboxConnects(n, n2, flag)) neighbors_set |= flag; diff --git a/src/client/content_mapblock.h b/src/client/content_mapblock.h index 77562f4943..c525679031 100644 --- a/src/client/content_mapblock.h +++ b/src/client/content_mapblock.h @@ -71,8 +71,8 @@ class MapblockMeshGenerator bool enable_mesh_cache; // current node - v3POS blockpos_nodes; - v3POS p; + v3pos_t blockpos_nodes; + v3pos_t p; v3f origin; MapNode n; const ContentFeatures *f; @@ -91,11 +91,11 @@ class MapblockMeshGenerator void useTile(int index = 0, u8 set_flags = MATERIAL_FLAG_CRACK_OVERLAY, u8 reset_flags = 0, bool special = false); void getTile(int index, TileSpec *tile); - void getTile(v3POS direction, TileSpec *tile); + void getTile(v3pos_t direction, TileSpec *tile); void getSpecialTile(int index, TileSpec *tile, bool apply_crack = false); // face drawing - void drawQuad(v3f *vertices, const v3POS &normal = v3POS(0, 0, 0), + void drawQuad(v3f *vertices, const v3pos_t &normal = v3pos_t(0, 0, 0), float vertical_tiling = 1.0); // cuboid drawing! @@ -134,7 +134,7 @@ class MapblockMeshGenerator // name of the group that enables connecting to raillike nodes of different kind static const std::string raillike_groupname; int raillike_group; - bool isSameRail(v3POS dir); + bool isSameRail(v3pos_t dir); // plantlike-specific PlantlikeStyle draw_style; diff --git a/src/client/game.cpp b/src/client/game.cpp index 6aa620139e..a7a8cb2172 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -84,7 +84,7 @@ with this program; if not, write to the Free Software Foundation, Inc., struct TextDestNodeMetadata : public TextDest { - TextDestNodeMetadata(v3POS p, Client *client) + TextDestNodeMetadata(v3pos_t p, Client *client) { m_p = p; m_client = client; @@ -104,7 +104,7 @@ struct TextDestNodeMetadata : public TextDest m_client->sendNodemetaFields(m_p, "", fields); } - v3POS m_p; + v3pos_t m_p; Client *m_client; }; @@ -193,7 +193,7 @@ struct LocalFormspecHandler : public TextDest class NodeMetadataFormSource: public IFormSource { public: - NodeMetadataFormSource(ClientMap *map, v3POS p): + NodeMetadataFormSource(ClientMap *map, v3pos_t p): m_map(map), m_p(p) { @@ -220,7 +220,7 @@ class NodeMetadataFormSource: public IFormSource } ClientMap *m_map; - v3POS m_p; + v3pos_t m_p; }; class PlayerInventoryFormSource: public IFormSource @@ -243,10 +243,10 @@ class PlayerInventoryFormSource: public IFormSource class NodeDugEvent: public MtEvent { public: - v3POS p; + v3pos_t p; MapNode n; - NodeDugEvent(v3POS p, MapNode n): + NodeDugEvent(v3pos_t p, MapNode n): p(p), n(n) {} @@ -730,13 +730,13 @@ class Game { */ PointedThing updatePointedThing( const core::line3d &shootline, bool liquids_pointable, - bool look_for_object, const v3POS &camera_offset); + bool look_for_object, const v3pos_t &camera_offset); void handlePointingAtNothing(const ItemStack &playerItem); void handlePointingAtNode(const PointedThing &pointed, const ItemStack &selected_item, const ItemStack &hand_item, f32 dtime); void handlePointingAtObject(const PointedThing &pointed, const ItemStack &playeritem, const v3f &player_position, bool show_debug); - void handleDigging(const PointedThing &pointed, const v3POS &nodepos, + void handleDigging(const PointedThing &pointed, const v3pos_t &nodepos, const ItemStack &selected_item, const ItemStack &hand_item, f32 dtime); void updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime, const CameraOrientation &cam); @@ -807,7 +807,7 @@ class Game { void updateChat(f32 dtime); bool nodePlacement(const ItemDefinition &selected_def, const ItemStack &selected_item, - const v3POS &nodepos, const v3POS &neighbourpos, const PointedThing &pointed, + const v3pos_t &nodepos, const v3pos_t &neighbourpos, const PointedThing &pointed, const NodeMetadata *meta); static const ClientEventHandler clientEventHandler[CLIENTEVENT_MAX]; @@ -2336,8 +2336,8 @@ void Game::toggleUpdateCamera() void Game::increaseViewRange() { - POS range = g_settings->getPOS("viewing_range"); - POS range_new = range + 10; + pos_t range = g_settings->getPOS("viewing_range"); + pos_t range_new = range + 10; if (range_new > 4000) { range_new = 4000; @@ -2353,8 +2353,8 @@ void Game::increaseViewRange() void Game::decreaseViewRange() { - POS range = g_settings->getPOS("viewing_range"); - POS range_new = range - 10; + pos_t range = g_settings->getPOS("viewing_range"); + pos_t range_new = range - 10; if (range_new < 20) { range_new = 20; @@ -2966,7 +2966,7 @@ void Game::updateCamera(u32 busy_time, f32 dtime) ToolCapabilities playeritem_toolcap = playeritem.getToolCapabilities(itemdef_manager); - v3POS old_camera_offset = camera->getOffset(); + v3pos_t old_camera_offset = camera->getOffset(); if (wasKeyDown(KeyType::CAMERA_MODE)) { GenericCAO *playercao = player->getCAO(); @@ -2992,7 +2992,7 @@ void Game::updateCamera(u32 busy_time, f32 dtime) v3f camera_position = camera->getPosition(); v3f camera_direction = camera->getDirection(); f32 camera_fov = camera->getFovMax(); - v3POS camera_offset = camera->getOffset(); + v3pos_t camera_offset = camera->getOffset(); m_camera_offset_changed = (camera_offset != old_camera_offset); @@ -3014,7 +3014,7 @@ void Game::updateCamera(u32 busy_time, f32 dtime) void Game::updateSound(f32 dtime) { // Update sound listener - v3POS camera_offset = camera->getOffset(); + v3pos_t camera_offset = camera->getOffset(); sound->updateListener(camera->getCameraNode()->getPosition() + intToFloat(camera_offset, BS), v3f(0, 0, 0), // velocity camera->getDirection(), @@ -3054,7 +3054,7 @@ void Game::processPlayerInteraction(f32 dtime, bool show_hud, bool show_debug) LocalPlayer *player = client->getEnv().getLocalPlayer(); const v3f camera_direction = camera->getDirection(); - const v3POS camera_offset = camera->getOffset(); + const v3pos_t camera_offset = camera->getOffset(); /* Calculate what block is the crosshair pointing to @@ -3137,7 +3137,7 @@ void Game::processPlayerInteraction(f32 dtime, bool show_hud, bool show_debug) if (!runData.digging) { client->interact(INTERACT_STOP_DIGGING, runData.pointed_old); - client->setCrack(-1, v3POS(0, 0, 0)); + client->setCrack(-1, v3pos_t(0, 0, 0)); runData.dig_time = 0.0; } } else if (runData.dig_instantly && wasKeyReleased(KeyType::DIG)) { @@ -3201,7 +3201,7 @@ PointedThing Game::updatePointedThing( const core::line3d &shootline, bool liquids_pointable, bool look_for_object, - const v3POS &camera_offset) + const v3pos_t &camera_offset) { std::vector *selectionboxes = hud->getSelectionBoxes(); selectionboxes->clear(); @@ -3256,14 +3256,14 @@ PointedThing Game::updatePointedThing( // Update selection mesh light level and vertex colors if (!selectionboxes->empty()) { v3f pf = hud->getSelectionPos(); - v3POS p = floatToInt(pf, BS); + v3pos_t p = floatToInt(pf, BS); // Get selection mesh light level MapNode n = map.getNode(p); u16 node_light = getInteriorLight(n, -1, nodedef); u16 light_level = node_light; - for (const v3POS &dir : g_6dirs) { + for (const v3pos_t &dir : g_6dirs) { n = map.getNode(p + dir); node_light = getInteriorLight(n, -1, nodedef); if (node_light > light_level) @@ -3303,8 +3303,8 @@ void Game::handlePointingAtNothing(const ItemStack &playerItem) void Game::handlePointingAtNode(const PointedThing &pointed, const ItemStack &selected_item, const ItemStack &hand_item, f32 dtime) { - v3POS nodepos = pointed.node_undersurface; - v3POS neighbourpos = pointed.node_abovesurface; + v3pos_t nodepos = pointed.node_undersurface; + v3pos_t neighbourpos = pointed.node_abovesurface; /* Check information text of node @@ -3357,7 +3357,7 @@ void Game::handlePointingAtNode(const PointedThing &pointed, } bool Game::nodePlacement(const ItemDefinition &selected_def, - const ItemStack &selected_item, const v3POS &nodepos, const v3POS &neighbourpos, + const ItemStack &selected_item, const v3pos_t &nodepos, const v3pos_t &neighbourpos, const PointedThing &pointed, const NodeMetadata *meta) { const auto &prediction = selected_def.node_placement_prediction; @@ -3407,7 +3407,7 @@ bool Game::nodePlacement(const ItemDefinition &selected_def, verbosestream << "Node placement prediction for " << selected_def.name << " is " << prediction << std::endl; - v3POS p = neighbourpos; + v3pos_t p = neighbourpos; // Place inside node itself if buildable_to MapNode n_under = map.getNode(nodepos, &is_valid_position); @@ -3451,7 +3451,7 @@ bool Game::nodePlacement(const ItemDefinition &selected_def, param2 = place_param2; } else if (predicted_f.param_type_2 == CPT2_WALLMOUNTED || predicted_f.param_type_2 == CPT2_COLORED_WALLMOUNTED) { - v3POS dir = nodepos - neighbourpos; + v3pos_t dir = nodepos - neighbourpos; if (abs(dir.Y) > MYMAX(abs(dir.X), abs(dir.Z))) { param2 = dir.Y < 0 ? 1 : 0; @@ -3462,7 +3462,7 @@ bool Game::nodePlacement(const ItemDefinition &selected_def, } } else if (predicted_f.param_type_2 == CPT2_FACEDIR || predicted_f.param_type_2 == CPT2_COLORED_FACEDIR) { - v3POS dir = nodepos - floatToInt(client->getEnv().getLocalPlayer()->getPosition(), BS); + v3pos_t dir = nodepos - floatToInt(client->getEnv().getLocalPlayer()->getPosition(), BS); if (abs(dir.X) > abs(dir.Z)) { param2 = dir.X < 0 ? 3 : 1; @@ -3473,21 +3473,21 @@ bool Game::nodePlacement(const ItemDefinition &selected_def, // Check attachment if node is in group attached_node if (itemgroup_get(predicted_f.groups, "attached_node") != 0) { - const static v3POS wallmounted_dirs[8] = { - v3POS(0, 1, 0), - v3POS(0, -1, 0), - v3POS(1, 0, 0), - v3POS(-1, 0, 0), - v3POS(0, 0, 1), - v3POS(0, 0, -1), + const static v3pos_t wallmounted_dirs[8] = { + v3pos_t(0, 1, 0), + v3pos_t(0, -1, 0), + v3pos_t(1, 0, 0), + v3pos_t(-1, 0, 0), + v3pos_t(0, 0, 1), + v3pos_t(0, 0, -1), }; - v3POS pp; + v3pos_t pp; if (predicted_f.param_type_2 == CPT2_WALLMOUNTED || predicted_f.param_type_2 == CPT2_COLORED_WALLMOUNTED) pp = p + wallmounted_dirs[param2]; else - pp = p + v3POS(0, -1, 0); + pp = p + v3pos_t(0, -1, 0); if (!nodedef->get(map.getNode(pp)).walkable) { soundmaker->m_player_rightpunch_sound = selected_def.sound_place_failed; @@ -3529,8 +3529,8 @@ bool Game::nodePlacement(const ItemDefinition &selected_def, g_settings->getBool("enable_build_where_you_stand") || (client->checkPrivilege("noclip") && g_settings->getBool("noclip")) || (nodedef->get(n).walkable && - neighbourpos != player->getStandingNodePos() + v3POS(0, 1, 0) && - neighbourpos != player->getStandingNodePos() + v3POS(0, 2, 0))) { + neighbourpos != player->getStandingNodePos() + v3pos_t(0, 1, 0) && + neighbourpos != player->getStandingNodePos() + v3pos_t(0, 2, 0))) { // This triggers the required mesh update too client->addNode(p, n); // Report to server @@ -3603,7 +3603,7 @@ void Game::handlePointingAtObject(const PointedThing &pointed, } -void Game::handleDigging(const PointedThing &pointed, const v3POS &nodepos, +void Game::handleDigging(const PointedThing &pointed, const v3pos_t &nodepos, const ItemStack &selected_item, const ItemStack &hand_item, f32 dtime) { // See also: serverpackethandle.cpp, action == 2 @@ -3679,7 +3679,7 @@ void Game::handleDigging(const PointedThing &pointed, const v3POS &nodepos, client->setCrack(runData.dig_index, nodepos); } else { infostream << "Digging completed" << std::endl; - client->setCrack(-1, v3POS(0, 0, 0)); + client->setCrack(-1, v3pos_t(0, 0, 0)); runData.dig_time = 0; runData.digging = false; @@ -3809,7 +3809,7 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime, clouds->step(dtime); // camera->getPosition is not enough for 3rd person views v3f camera_node_position = camera->getCameraNode()->getPosition(); - v3POS camera_offset = camera->getOffset(); + v3pos_t camera_offset = camera->getOffset(); camera_node_position.X = camera_node_position.X + camera_offset.X * BS; camera_node_position.Y = camera_node_position.Y + camera_offset.Y * BS; camera_node_position.Z = camera_node_position.Z + camera_offset.Z * BS; diff --git a/src/client/hud.cpp b/src/client/hud.cpp index 5814d41a28..7fdfb7e0ca 100644 --- a/src/client/hud.cpp +++ b/src/client/hud.cpp @@ -312,7 +312,7 @@ bool Hud::hasElementOfType(HudElementType type) } // Calculates screen position of waypoint. Returns true if waypoint is visible (in front of the player), else false. -bool Hud::calculateScreenPos(const v3POS &camera_offset, HudElement *e, v2s32 *pos) +bool Hud::calculateScreenPos(const v3pos_t &camera_offset, HudElement *e, v2s32 *pos) { v3f w_pos = e->world_pos * BS; scene::ICameraSceneNode* camera = @@ -331,7 +331,7 @@ bool Hud::calculateScreenPos(const v3POS &camera_offset, HudElement *e, v2s32 *p return true; } -void Hud::drawLuaElements(const v3POS &camera_offset) +void Hud::drawLuaElements(const v3pos_t &camera_offset) { const u32 text_height = g_fontengine->getTextHeight(); gui::IGUIFont *const font = g_fontengine->getFont(); @@ -813,7 +813,7 @@ void Hud::drawCrosshair() } } -void Hud::setSelectionPos(const v3f &pos, const v3POS &camera_offset) +void Hud::setSelectionPos(const v3f &pos, const v3pos_t &camera_offset) { m_camera_offset = camera_offset; m_selection_pos = pos; @@ -887,9 +887,9 @@ void Hud::drawBlockBounds() video::SMaterial old_material = driver->getMaterial2D(); driver->setMaterial(m_selection_material); - v3POS pos = player->getStandingNodePos(); + v3pos_t pos = player->getStandingNodePos(); - v3POS blockPos( + v3pos_t blockPos( floorf((float) pos.X / MAP_BLOCKSIZE), floorf((float) pos.Y / MAP_BLOCKSIZE), floorf((float) pos.Z / MAP_BLOCKSIZE) @@ -904,7 +904,7 @@ void Hud::drawBlockBounds() for (s8 x = -radius; x <= radius; x++) for (s8 y = -radius; y <= radius; y++) for (s8 z = -radius; z <= radius; z++) { - v3POS blockOffset(x, y, z); + v3pos_t blockOffset(x, y, z); aabb3f box( intToFloat((blockPos + blockOffset) * MAP_BLOCKSIZE, BS) - offset - halfNode, @@ -917,7 +917,7 @@ void Hud::drawBlockBounds() driver->setMaterial(old_material); } -void Hud::updateSelectionMesh(const v3POS &camera_offset) +void Hud::updateSelectionMesh(const v3pos_t &camera_offset) { m_camera_offset = camera_offset; if (m_mode != HIGHLIGHT_HALO) @@ -988,8 +988,8 @@ void drawItemStack( const core::rect *clip, Client *client, ItemRotationKind rotation_kind, - const v3POS &angle, - const v3POS &rotation_speed) + const v3pos_t &angle, + const v3pos_t &rotation_speed) { static MeshTimeInfo rotation_time_infos[IT_ROT_NONE]; @@ -1208,5 +1208,5 @@ void drawItemStack( ItemRotationKind rotation_kind) { drawItemStack(driver, font, item, rect, clip, client, rotation_kind, - v3POS(0, 0, 0), v3POS(0, 100, 0)); + v3pos_t(0, 0, 0), v3pos_t(0, 100, 0)); } diff --git a/src/client/hud.h b/src/client/hud.h index c5a738fb96..7f4beb91c3 100644 --- a/src/client/hud.h +++ b/src/client/hud.h @@ -67,11 +67,11 @@ class Hud void resizeHotbar(); void drawCrosshair(); void drawSelectionMesh(); - void updateSelectionMesh(const v3POS &camera_offset); + void updateSelectionMesh(const v3pos_t &camera_offset); std::vector *getSelectionBoxes() { return &m_selection_boxes; } - void setSelectionPos(const v3f &pos, const v3POS &camera_offset); + void setSelectionPos(const v3f &pos, const v3pos_t &camera_offset); v3f getSelectionPos() const { return m_selection_pos; } @@ -87,10 +87,10 @@ class Hud bool hasElementOfType(HudElementType type); - void drawLuaElements(const v3POS &camera_offset); + void drawLuaElements(const v3pos_t &camera_offset); private: - bool calculateScreenPos(const v3POS &camera_offset, HudElement *e, v2s32 *pos); + bool calculateScreenPos(const v3pos_t &camera_offset, HudElement *e, v2s32 *pos); void drawStatbar(v2s32 pos, u16 corner, u16 drawdir, const std::string &texture, const std::string& bgtexture, s32 count, s32 maxcount, v2s32 offset, v2s32 size = v2s32()); @@ -115,7 +115,7 @@ class Hud float m_hud_scaling; // cached minetest setting float m_scale_factor; - v3POS m_camera_offset; + v3pos_t m_camera_offset; v2u32 m_screensize; v2s32 m_displaycenter; s32 m_hotbar_imagesize; // Takes hud_scaling into account, updated by resizeHotbar() @@ -168,6 +168,6 @@ void drawItemStack( const core::rect *clip, Client *client, ItemRotationKind rotation_kind, - const v3POS &angle, - const v3POS &rotation_speed); + const v3pos_t &angle, + const v3pos_t &rotation_speed); diff --git a/src/client/localplayer.cpp b/src/client/localplayer.cpp index d2b6ba20ce..4bac49e886 100644 --- a/src/client/localplayer.cpp +++ b/src/client/localplayer.cpp @@ -58,16 +58,16 @@ static aabb3f getNodeBoundingBox(const std::vector &nodeboxes) bool LocalPlayer::updateSneakNode(Map *map, const v3f &position, const v3f &sneak_max) { - static const v3POS dir9_center[9] = { - v3POS( 0, 0, 0), - v3POS( 1, 0, 0), - v3POS(-1, 0, 0), - v3POS( 0, 0, 1), - v3POS( 0, 0, -1), - v3POS( 1, 0, 1), - v3POS(-1, 0, 1), - v3POS( 1, 0, -1), - v3POS(-1, 0, -1) + static const v3pos_t dir9_center[9] = { + v3pos_t( 0, 0, 0), + v3pos_t( 1, 0, 0), + v3pos_t(-1, 0, 0), + v3pos_t( 0, 0, 1), + v3pos_t( 0, 0, -1), + v3pos_t( 1, 0, 1), + v3pos_t(-1, 0, 1), + v3pos_t( 1, 0, -1), + v3pos_t(-1, 0, -1) }; const NodeDefManager *nodemgr = m_client->ndef(); @@ -81,7 +81,7 @@ bool LocalPlayer::updateSneakNode(Map *map, const v3f &position, position_y_mod = m_sneak_node_bb_top.MaxEdge.Y - position_y_mod; // Get position of current standing node - const v3POS current_node = floatToInt(position - v3f(0.0f, position_y_mod, 0.0f), BS); + const v3pos_t current_node = floatToInt(position - v3f(0.0f, position_y_mod, 0.0f), BS); if (current_node != m_sneak_node) { new_sneak_node_exists = false; @@ -100,7 +100,7 @@ bool LocalPlayer::updateSneakNode(Map *map, const v3f &position, f32 min_distance_f = 100000.0f * BS; for (const auto &d : dir9_center) { - const v3POS p = current_node + d; + const v3pos_t p = current_node + d; const v3f pf = intToFloat(p, BS); const v2f diff(position.X - pf.X, position.Z - pf.Z); f32 distance_f = diff.getLength(); @@ -121,7 +121,7 @@ bool LocalPlayer::updateSneakNode(Map *map, const v3f &position, u16 height = ceilf((m_collisionbox.MaxEdge.Y - m_collisionbox.MinEdge.Y) / BS); for (u16 y = 1; y <= height; y++) { - node = map->getNode(p + v3POS(0, y, 0), &is_valid_position); + node = map->getNode(p + v3pos_t(0, y, 0), &is_valid_position); if (!is_valid_position || nodemgr->get(node).walkable) { ok = false; break; @@ -129,7 +129,7 @@ bool LocalPlayer::updateSneakNode(Map *map, const v3f &position, } } else { // legacy behaviour: check just one node - node = map->getNode(p + v3POS(0, 1, 0), &is_valid_position); + node = map->getNode(p + v3pos_t(0, 1, 0), &is_valid_position); ok = is_valid_position && !nodemgr->get(node).walkable; } if (!ok) @@ -152,11 +152,11 @@ bool LocalPlayer::updateSneakNode(Map *map, const v3f &position, if (physics_override_sneak_glitch) { // Detect sneak ladder: // Node two meters above sneak node must be solid - node = map->getNode(m_sneak_node + v3POS(0, 2, 0), + node = map->getNode(m_sneak_node + v3pos_t(0, 2, 0), &is_valid_position); if (is_valid_position && nodemgr->get(node).walkable) { // Node three meters above: must be non-solid - node = map->getNode(m_sneak_node + v3POS(0, 3, 0), + node = map->getNode(m_sneak_node + v3pos_t(0, 3, 0), &is_valid_position); m_sneak_ladder_detected = is_valid_position && !nodemgr->get(node).walkable; @@ -215,7 +215,7 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d, bool is_valid_position; MapNode node; - v3POS pp; + v3pos_t pp; /* Check if player is in liquid (the oscillating value) @@ -264,7 +264,7 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d, */ pp = floatToInt(position + v3f(0.0f, 0.5f * BS, 0.0f), BS); - v3POS pp2 = floatToInt(position + v3f(0.0f, -0.2f * BS, 0.0f), BS); + v3pos_t pp2 = floatToInt(position + v3f(0.0f, -0.2f * BS, 0.0f), BS); node = map->getNode(pp, &is_valid_position); bool is_valid_position2; MapNode node2 = map->getNode(pp2, &is_valid_position2); @@ -428,7 +428,7 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d, { camera_barely_in_ceiling = false; - v3POS camera_np = floatToInt(getEyePosition(), BS); + v3pos_t camera_np = floatToInt(getEyePosition(), BS); MapNode n = map->getNode(camera_np); if (n.getContent() != CONTENT_IGNORE) { if (nodemgr->get(n).walkable && nodemgr->get(n).solidness == 2) @@ -440,7 +440,7 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d, Check properties of the node on which the player is standing */ const ContentFeatures &f = nodemgr->get(map->getNode(m_standing_node)); - const ContentFeatures &f1 = nodemgr->get(map->getNode(m_standing_node + v3POS(0, 1, 0))); + const ContentFeatures &f1 = nodemgr->get(map->getNode(m_standing_node + v3pos_t(0, 1, 0))); // Determine if jumping is possible m_disable_jump = itemgroup_get(f.groups, "disable_jump") || @@ -662,7 +662,7 @@ void LocalPlayer::applyControl(float dtime, Environment *env) pitch_move); } -v3POS LocalPlayer::getStandingNodePos() +v3pos_t LocalPlayer::getStandingNodePos() { if (m_sneak_node_exists) return m_sneak_node; @@ -670,7 +670,7 @@ v3POS LocalPlayer::getStandingNodePos() return m_standing_node; } -v3POS LocalPlayer::getFootstepNodePos() +v3pos_t LocalPlayer::getFootstepNodePos() { // Emit swimming sound if the player is in liquid if (in_liquid_stable) @@ -687,7 +687,7 @@ v3POS LocalPlayer::getFootstepNodePos() return floatToInt(getPosition() - v3f(0.0f, BS * 0.5f, 0.0f), BS); } -v3POS LocalPlayer::getLightPosition() const +v3pos_t LocalPlayer::getLightPosition() const { return floatToInt(m_position + v3f(0.0f, BS * 1.5f, 0.0f), BS); } @@ -792,7 +792,7 @@ void LocalPlayer::old_move(f32 dtime, Environment *env, f32 pos_max_d, */ bool is_valid_position; MapNode node; - v3POS pp; + v3pos_t pp; /* Check if player is in liquid (the oscillating value) @@ -835,7 +835,7 @@ void LocalPlayer::old_move(f32 dtime, Environment *env, f32 pos_max_d, Check if player is climbing */ pp = floatToInt(position + v3f(0.0f, 0.5f * BS, 0.0f), BS); - v3POS pp2 = floatToInt(position + v3f(0.0f, -0.2f * BS, 0.0f), BS); + v3pos_t pp2 = floatToInt(position + v3f(0.0f, -0.2f * BS, 0.0f), BS); node = map->getNode(pp, &is_valid_position); bool is_valid_position2; MapNode node2 = map->getNode(pp2, &is_valid_position2); @@ -921,7 +921,7 @@ void LocalPlayer::old_move(f32 dtime, Environment *env, f32 pos_max_d, f32 position_y_mod = 0.05f * BS; if (m_sneak_node_bb_ymax > 0.0f) position_y_mod = m_sneak_node_bb_ymax - position_y_mod; - v3POS current_node = floatToInt(position - v3f(0.0f, position_y_mod, 0.0f), BS); + v3pos_t current_node = floatToInt(position - v3f(0.0f, position_y_mod, 0.0f), BS); if (m_sneak_node_exists && nodemgr->get(map->getNode(m_old_node_below)).name == "air" && m_old_node_below_type != "air") { @@ -937,14 +937,14 @@ void LocalPlayer::old_move(f32 dtime, Environment *env, f32 pos_max_d, if (m_need_to_get_new_sneak_node && physics_override_sneak) { m_sneak_node_bb_ymax = 0.0f; - v3POS pos_i_bottom = floatToInt(position - v3f(0.0f, position_y_mod, 0.0f), BS); + v3pos_t pos_i_bottom = floatToInt(position - v3f(0.0f, position_y_mod, 0.0f), BS); v2f player_p2df(position.X, position.Z); f32 min_distance_f = 100000.0f * BS; // If already seeking from some node, compare to it. - v3POS new_sneak_node = m_sneak_node; + v3pos_t new_sneak_node = m_sneak_node; for (s16 x= -1; x <= 1; x++) for (s16 z= -1; z <= 1; z++) { - v3POS p = pos_i_bottom + v3POS(x, 0, z); + v3pos_t p = pos_i_bottom + v3pos_t(x, 0, z); v3f pf = intToFloat(p, BS); v2f node_p2df(pf.X, pf.Z); f32 distance_f = player_p2df.getDistanceFrom(node_p2df); @@ -961,12 +961,12 @@ void LocalPlayer::old_move(f32 dtime, Environment *env, f32 pos_max_d, if (!is_valid_position || !nodemgr->get(node).walkable) continue; // And the node above it has to be nonwalkable - node = map->getNode(p + v3POS(0, 1, 0), &is_valid_position); + node = map->getNode(p + v3pos_t(0, 1, 0), &is_valid_position); if (!is_valid_position || nodemgr->get(node).walkable) continue; // If not 'sneak_glitch' the node 2 nodes above it has to be nonwalkable if (!physics_override_sneak_glitch) { - node = map->getNode(p + v3POS(0, 2, 0), &is_valid_position); + node = map->getNode(p + v3pos_t(0, 2, 0), &is_valid_position); if (!is_valid_position || nodemgr->get(node).walkable) continue; } @@ -1025,7 +1025,7 @@ void LocalPlayer::old_move(f32 dtime, Environment *env, f32 pos_max_d, { camera_barely_in_ceiling = false; - v3POS camera_np = floatToInt(getEyePosition(), BS); + v3pos_t camera_np = floatToInt(getEyePosition(), BS); MapNode n = map->getNode(camera_np); if (n.getContent() != CONTENT_IGNORE) { if (nodemgr->get(n).walkable && nodemgr->get(n).solidness == 2) @@ -1120,13 +1120,13 @@ void LocalPlayer::handleAutojump(f32 dtime, Environment *env, v3f headpos_min = m_position + m_collisionbox.MinEdge * 0.99f; v3f headpos_max = m_position + m_collisionbox.MaxEdge * 0.99f; headpos_min.Y = headpos_max.Y; // top face of collision box - v3POS ceilpos_min = floatToInt(headpos_min, BS) + v3POS(0, 1, 0); - v3POS ceilpos_max = floatToInt(headpos_max, BS) + v3POS(0, 1, 0); + v3pos_t ceilpos_min = floatToInt(headpos_min, BS) + v3pos_t(0, 1, 0); + v3pos_t ceilpos_max = floatToInt(headpos_max, BS) + v3pos_t(0, 1, 0); const NodeDefManager *ndef = env->getGameDef()->ndef(); bool is_position_valid; - for (POS z = ceilpos_min.Z; z <= ceilpos_max.Z; ++z) { - for (POS x = ceilpos_min.X; x <= ceilpos_max.X; ++x) { - MapNode n = env->getMap().getNode(v3POS(x, ceilpos_max.Y, z), &is_position_valid); + for (pos_t z = ceilpos_min.Z; z <= ceilpos_max.Z; ++z) { + for (pos_t x = ceilpos_min.X; x <= ceilpos_max.X; ++x) { + MapNode n = env->getMap().getNode(v3pos_t(x, ceilpos_max.Y, z), &is_position_valid); if (!is_position_valid) break; // won't collide with the void outside diff --git a/src/client/localplayer.h b/src/client/localplayer.h index dd71ec2784..c862aceece 100644 --- a/src/client/localplayer.h +++ b/src/client/localplayer.h @@ -78,8 +78,8 @@ class LocalPlayer : public Player void applyControl(float dtime, Environment *env); - v3POS getStandingNodePos(); - v3POS getFootstepNodePos(); + v3pos_t getStandingNodePos(); + v3pos_t getFootstepNodePos(); // Used to check if anything changed and prevent sending packets if not v3f last_position; @@ -120,7 +120,7 @@ class LocalPlayer : public Player u16 getBreath() const { return m_breath; } void setBreath(u16 breath) { m_breath = breath; } - v3POS getLightPosition() const; + v3pos_t getLightPosition() const; void setYaw(f32 yaw) { m_yaw = yaw; } f32 getYaw() const { return m_yaw; } @@ -169,9 +169,9 @@ class LocalPlayer : public Player f32 pos_max_d); v3f m_position; - v3POS m_standing_node; + v3pos_t m_standing_node; - v3POS m_sneak_node = v3POS(32767, 32767, 32767); + v3pos_t m_sneak_node = v3pos_t(32767, 32767, 32767); // Stores the top bounding box of m_sneak_node aabb3f m_sneak_node_bb_top = aabb3f(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f); // Whether the player is allowed to sneak @@ -187,7 +187,7 @@ class LocalPlayer : public Player bool m_need_to_get_new_sneak_node = true; // Node below player, used to determine whether it has been removed, // and its old type - v3POS m_old_node_below = v3POS(32767, 32767, 32767); + v3pos_t m_old_node_below = v3pos_t(32767, 32767, 32767); std::string m_old_node_below_type = "air"; // ***** End of variables for temporary option ***** diff --git a/src/client/mapblock_mesh.cpp b/src/client/mapblock_mesh.cpp index 2042627809..8081ad79ef 100644 --- a/src/client/mapblock_mesh.cpp +++ b/src/client/mapblock_mesh.cpp @@ -40,46 +40,46 @@ MeshMakeData::MeshMakeData(Client *client, bool use_shaders): m_use_shaders(use_shaders) {} -void MeshMakeData::fillBlockDataBegin(const v3POS &blockpos) +void MeshMakeData::fillBlockDataBegin(const v3pos_t &blockpos) { m_blockpos = blockpos; - v3POS blockpos_nodes = m_blockpos*MAP_BLOCKSIZE; + v3pos_t blockpos_nodes = m_blockpos*MAP_BLOCKSIZE; m_vmanip.clear(); - VoxelArea voxel_area(blockpos_nodes - v3POS(1,1,1) * MAP_BLOCKSIZE, - blockpos_nodes + v3POS(1,1,1) * MAP_BLOCKSIZE*2-v3POS(1,1,1)); + VoxelArea voxel_area(blockpos_nodes - v3pos_t(1,1,1) * MAP_BLOCKSIZE, + blockpos_nodes + v3pos_t(1,1,1) * MAP_BLOCKSIZE*2-v3pos_t(1,1,1)); m_vmanip.addArea(voxel_area); } -void MeshMakeData::fillBlockData(const v3POS &block_offset, MapNode *data) +void MeshMakeData::fillBlockData(const v3pos_t &block_offset, MapNode *data) { - v3POS data_size(MAP_BLOCKSIZE, MAP_BLOCKSIZE, MAP_BLOCKSIZE); - VoxelArea data_area(v3POS(0,0,0), data_size - v3POS(1,1,1)); + v3pos_t data_size(MAP_BLOCKSIZE, MAP_BLOCKSIZE, MAP_BLOCKSIZE); + VoxelArea data_area(v3pos_t(0,0,0), data_size - v3pos_t(1,1,1)); - v3POS bp = m_blockpos + block_offset; - v3POS blockpos_nodes = bp * MAP_BLOCKSIZE; - m_vmanip.copyFrom(data, data_area, v3POS(0,0,0), blockpos_nodes, data_size); + v3pos_t bp = m_blockpos + block_offset; + v3pos_t blockpos_nodes = bp * MAP_BLOCKSIZE; + m_vmanip.copyFrom(data, data_area, v3pos_t(0,0,0), blockpos_nodes, data_size); } void MeshMakeData::fill(MapBlock *block) { fillBlockDataBegin(block->getPos()); - fillBlockData(v3POS(0,0,0), block->getData()); + fillBlockData(v3pos_t(0,0,0), block->getData()); // Get map for reading neighbor blocks Map *map = block->getParent(); - for (const v3POS &dir : g_26dirs) { - v3POS bp = m_blockpos + dir; + for (const v3pos_t &dir : g_26dirs) { + v3pos_t bp = m_blockpos + dir; MapBlock *b = map->getBlockNoCreateNoEx(bp); if(b) fillBlockData(dir, b->getData()); } } -void MeshMakeData::setCrack(int crack_level, v3POS crack_pos) +void MeshMakeData::setCrack(int crack_level, v3pos_t crack_pos) { if (crack_level >= 0) m_crack_pos_relative = crack_pos - m_blockpos*MAP_BLOCKSIZE; @@ -123,7 +123,7 @@ u16 getInteriorLight(MapNode n, s32 increment, const NodeDefManager *ndef) Single light bank. */ static u8 getFaceLight(enum LightBank bank, MapNode n, MapNode n2, - v3POS face_dir, const NodeDefManager *ndef) + v3pos_t face_dir, const NodeDefManager *ndef) { u8 light; u8 l1 = n.getLight(bank, ndef); @@ -146,7 +146,7 @@ static u8 getFaceLight(enum LightBank bank, MapNode n, MapNode n2, Calculate non-smooth lighting at face of node. Both light banks. */ -u16 getFaceLight(MapNode n, MapNode n2, const v3POS &face_dir, +u16 getFaceLight(MapNode n, MapNode n2, const v3pos_t &face_dir, const NodeDefManager *ndef) { u16 day = getFaceLight(LIGHTBANK_DAY, n, n2, face_dir, ndef); @@ -158,8 +158,8 @@ u16 getFaceLight(MapNode n, MapNode n2, const v3POS &face_dir, Calculate smooth lighting at the XYZ- corner of p. Both light banks */ -static u16 getSmoothLightCombined(const v3POS &p, - const std::array &dirs, MeshMakeData *data) +static u16 getSmoothLightCombined(const v3pos_t &p, + const std::array &dirs, MeshMakeData *data) { const NodeDefManager *ndef = data->m_client->ndef(); @@ -267,7 +267,7 @@ static u16 getSmoothLightCombined(const v3POS &p, Both light banks. Node at p is solid, and thus the lighting is face-dependent. */ -u16 getSmoothLightSolid(const v3POS &p, const v3POS &face_dir, const v3POS &corner, MeshMakeData *data) +u16 getSmoothLightSolid(const v3pos_t &p, const v3pos_t &face_dir, const v3pos_t &corner, MeshMakeData *data) { return getSmoothLightTransparent(p + face_dir, corner - 2 * face_dir, data); } @@ -277,20 +277,20 @@ u16 getSmoothLightSolid(const v3POS &p, const v3POS &face_dir, const v3POS &corn Both light banks. Node at p is not solid, and the lighting is not face-dependent. */ -u16 getSmoothLightTransparent(const v3POS &p, const v3POS &corner, MeshMakeData *data) +u16 getSmoothLightTransparent(const v3pos_t &p, const v3pos_t &corner, MeshMakeData *data) { - const std::array dirs = {{ + const std::array dirs = {{ // Always shine light - v3POS(0,0,0), - v3POS(corner.X,0,0), - v3POS(0,corner.Y,0), - v3POS(0,0,corner.Z), + v3pos_t(0,0,0), + v3pos_t(corner.X,0,0), + v3pos_t(0,corner.Y,0), + v3pos_t(0,0,corner.Z), // Can be obstructed - v3POS(corner.X,corner.Y,0), - v3POS(corner.X,0,corner.Z), - v3POS(0,corner.Y,corner.Z), - v3POS(corner.X,corner.Y,corner.Z) + v3pos_t(corner.X,corner.Y,0), + v3pos_t(corner.X,0,corner.Z), + v3pos_t(0,corner.Y,corner.Z), + v3pos_t(corner.X,corner.Y,corner.Z) }}; return getSmoothLightCombined(p, dirs, data); } @@ -346,33 +346,33 @@ void final_color_blend(video::SColor *result, // This table is moved outside getNodeVertexDirs to avoid the compiler using // a mutex to initialize this table at runtime right in the hot path. // For details search the internet for "cxa_guard_acquire". -static const v3POS vertex_dirs_table[] = { +static const v3pos_t vertex_dirs_table[] = { // ( 1, 0, 0) - v3POS( 1,-1, 1), v3POS( 1,-1,-1), - v3POS( 1, 1,-1), v3POS( 1, 1, 1), + v3pos_t( 1,-1, 1), v3pos_t( 1,-1,-1), + v3pos_t( 1, 1,-1), v3pos_t( 1, 1, 1), // ( 0, 1, 0) - v3POS( 1, 1,-1), v3POS(-1, 1,-1), - v3POS(-1, 1, 1), v3POS( 1, 1, 1), + v3pos_t( 1, 1,-1), v3pos_t(-1, 1,-1), + v3pos_t(-1, 1, 1), v3pos_t( 1, 1, 1), // ( 0, 0, 1) - v3POS(-1,-1, 1), v3POS( 1,-1, 1), - v3POS( 1, 1, 1), v3POS(-1, 1, 1), + v3pos_t(-1,-1, 1), v3pos_t( 1,-1, 1), + v3pos_t( 1, 1, 1), v3pos_t(-1, 1, 1), // invalid - v3POS(), v3POS(), v3POS(), v3POS(), + v3pos_t(), v3pos_t(), v3pos_t(), v3pos_t(), // ( 0, 0,-1) - v3POS( 1,-1,-1), v3POS(-1,-1,-1), - v3POS(-1, 1,-1), v3POS( 1, 1,-1), + v3pos_t( 1,-1,-1), v3pos_t(-1,-1,-1), + v3pos_t(-1, 1,-1), v3pos_t( 1, 1,-1), // ( 0,-1, 0) - v3POS( 1,-1, 1), v3POS(-1,-1, 1), - v3POS(-1,-1,-1), v3POS( 1,-1,-1), + v3pos_t( 1,-1, 1), v3pos_t(-1,-1, 1), + v3pos_t(-1,-1,-1), v3pos_t( 1,-1,-1), // (-1, 0, 0) - v3POS(-1,-1,-1), v3POS(-1,-1, 1), - v3POS(-1, 1, 1), v3POS(-1, 1,-1) + v3pos_t(-1,-1,-1), v3pos_t(-1,-1, 1), + v3pos_t(-1, 1, 1), v3pos_t(-1, 1,-1) }; /* - vertex_dirs: v3POS[4] + vertex_dirs: v3pos_t[4] */ -static void getNodeVertexDirs(const v3POS &dir, v3POS *vertex_dirs) +static void getNodeVertexDirs(const v3pos_t &dir, v3pos_t *vertex_dirs) { /* If looked from outside the node towards the face, the corners are: @@ -396,32 +396,32 @@ static void getNodeVertexDirs(const v3POS &dir, v3POS *vertex_dirs) #pragma GCC diagnostic ignored "-Wclass-memaccess" #endif #endif - memcpy(vertex_dirs, &vertex_dirs_table[idx], 4 * sizeof(v3POS)); + memcpy(vertex_dirs, &vertex_dirs_table[idx], 4 * sizeof(v3pos_t)); #if defined(__GNUC__) && !defined(__clang__) #pragma GCC diagnostic pop #endif } -static void getNodeTextureCoords(v3f base, const v3f &scale, const v3POS &dir, float *u, float *v) +static void getNodeTextureCoords(v3f base, const v3f &scale, const v3pos_t &dir, float *u, float *v) { if (dir.X > 0 || dir.Y != 0 || dir.Z < 0) base -= scale; - if (dir == v3POS(0,0,1)) { + if (dir == v3pos_t(0,0,1)) { *u = -base.X; *v = -base.Y; - } else if (dir == v3POS(0,0,-1)) { + } else if (dir == v3pos_t(0,0,-1)) { *u = base.X + 1; *v = -base.Y - 1; - } else if (dir == v3POS(1,0,0)) { + } else if (dir == v3pos_t(1,0,0)) { *u = base.Z + 1; *v = -base.Y - 1; - } else if (dir == v3POS(-1,0,0)) { + } else if (dir == v3pos_t(-1,0,0)) { *u = -base.Z; *v = -base.Y; - } else if (dir == v3POS(0,1,0)) { + } else if (dir == v3pos_t(0,1,0)) { *u = base.X + 1; *v = -base.Z - 1; - } else if (dir == v3POS(0,-1,0)) { + } else if (dir == v3pos_t(0,-1,0)) { *u = base.X + 1; *v = base.Z + 1; } @@ -440,7 +440,7 @@ struct FastFace }; static void makeFastFace(const TileSpec &tile, u16 li0, u16 li1, u16 li2, u16 li3, - const v3f &tp, const v3f &p, const v3POS &dir, const v3f &scale, std::vector &dest) + const v3f &tp, const v3f &p, const v3pos_t &dir, const v3f &scale, std::vector &dest) { // Position is at the center of the cube. v3f pos = p * BS; @@ -451,12 +451,12 @@ static void makeFastFace(const TileSpec &tile, u16 li0, u16 li1, u16 li2, u16 li float h = 1.0f; v3f vertex_pos[4]; - v3POS vertex_dirs[4]; + v3pos_t vertex_dirs[4]; getNodeVertexDirs(dir, vertex_dirs); if (tile.world_aligned) getNodeTextureCoords(tp, scale, dir, &x0, &y0); - v3POS t; + v3pos_t t; u16 t1; switch (tile.rotation) { case 0: @@ -682,7 +682,7 @@ static u8 face_contents(content_t m1, content_t m2, bool *equivalent, /* Gets nth node tile (0 <= n <= 5). */ -void getNodeTileN(MapNode mn, const v3POS &p, u8 tileindex, MeshMakeData *data, TileSpec &tile) +void getNodeTileN(MapNode mn, const v3pos_t &p, u8 tileindex, MeshMakeData *data, TileSpec &tile) { const NodeDefManager *ndef = data->m_client->ndef(); const ContentFeatures &f = ndef->get(mn); @@ -702,7 +702,7 @@ void getNodeTileN(MapNode mn, const v3POS &p, u8 tileindex, MeshMakeData *data, /* Gets node tile given a face direction. */ -void getNodeTile(MapNode mn, const v3POS &p, const v3POS &dir, MeshMakeData *data, TileSpec &tile) +void getNodeTile(MapNode mn, const v3pos_t &p, const v3pos_t &dir, MeshMakeData *data, TileSpec &tile) { const NodeDefManager *ndef = data->m_client->ndef(); @@ -766,12 +766,12 @@ void getNodeTile(MapNode mn, const v3POS &p, const v3POS &dir, MeshMakeData *dat static void getTileInfo( // Input: MeshMakeData *data, - const v3POS &p, - const v3POS &face_dir, + const v3pos_t &p, + const v3pos_t &face_dir, // Output: bool &makes_face, - v3POS &p_corrected, - v3POS &face_dir_corrected, + v3pos_t &p_corrected, + v3pos_t &face_dir_corrected, u16 *lights, u8 &waving, TileSpec &tile @@ -779,7 +779,7 @@ static void getTileInfo( { VoxelManipulator &vmanip = data->m_vmanip; const NodeDefManager *ndef = data->m_client->ndef(); - v3POS blockpos_nodes = data->m_blockpos * MAP_BLOCKSIZE; + v3pos_t blockpos_nodes = data->m_blockpos * MAP_BLOCKSIZE; const MapNode &n0 = vmanip.getNodeRefUnsafe(blockpos_nodes + p); @@ -834,10 +834,10 @@ static void getTileInfo( lights[0] = lights[1] = lights[2] = lights[3] = getFaceLight(n0, n1, face_dir, ndef); } else { - v3POS vertex_dirs[4]; + v3pos_t vertex_dirs[4]; getNodeVertexDirs(face_dir_corrected, vertex_dirs); - v3POS light_p = blockpos_nodes + p_corrected; + v3pos_t light_p = blockpos_nodes + p_corrected; for (u16 i = 0; i < 4; i++) lights[i] = getSmoothLightSolid(light_p, face_dir_corrected, vertex_dirs[i], data); } @@ -850,10 +850,10 @@ static void getTileInfo( */ static void updateFastFaceRow( MeshMakeData *data, - const v3POS &&startpos, - v3POS translate_dir, + const v3pos_t &&startpos, + v3pos_t translate_dir, const v3f &&translate_dir_f, - const v3POS &&face_dir, + const v3pos_t &&face_dir, std::vector &dest) { static thread_local const bool waving_liquids = @@ -863,13 +863,13 @@ static void updateFastFaceRow( static thread_local const bool force_not_tiling = g_settings->getBool("enable_dynamic_shadows"); - v3POS p = startpos; + v3pos_t p = startpos; u16 continuous_tiles_count = 1; bool makes_face = false; - v3POS p_corrected; - v3POS face_dir_corrected; + v3pos_t p_corrected; + v3pos_t face_dir_corrected; u16 lights[4] = {0, 0, 0, 0}; u8 waving = 0; TileSpec tile; @@ -886,8 +886,8 @@ static void updateFastFaceRow( bool next_is_different = true; bool next_makes_face = false; - v3POS next_p_corrected; - v3POS next_face_dir_corrected; + v3pos_t next_p_corrected; + v3pos_t next_face_dir_corrected; u16 next_lights[4] = {0, 0, 0, 0}; // If at last position, there is nothing to compare to and @@ -958,10 +958,10 @@ static void updateAllFastFaceRows(MeshMakeData *data, for (s16 y = 0; y < MAP_BLOCKSIZE; y++) for (s16 z = 0; z < MAP_BLOCKSIZE; z++) updateFastFaceRow(data, - v3POS(0, y, z), - v3POS(1, 0, 0), //dir + v3pos_t(0, y, z), + v3pos_t(1, 0, 0), //dir v3f (1, 0, 0), - v3POS(0, 1, 0), //face dir + v3pos_t(0, 1, 0), //face dir dest); /* @@ -970,10 +970,10 @@ static void updateAllFastFaceRows(MeshMakeData *data, for (s16 x = 0; x < MAP_BLOCKSIZE; x++) for (s16 y = 0; y < MAP_BLOCKSIZE; y++) updateFastFaceRow(data, - v3POS(x, y, 0), - v3POS(0, 0, 1), //dir + v3pos_t(x, y, 0), + v3pos_t(0, 0, 1), //dir v3f (0, 0, 1), - v3POS(1, 0, 0), //face dir + v3pos_t(1, 0, 0), //face dir dest); /* @@ -982,10 +982,10 @@ static void updateAllFastFaceRows(MeshMakeData *data, for (s16 z = 0; z < MAP_BLOCKSIZE; z++) for (s16 y = 0; y < MAP_BLOCKSIZE; y++) updateFastFaceRow(data, - v3POS(0, y, z), - v3POS(1, 0, 0), //dir + v3pos_t(0, y, z), + v3pos_t(1, 0, 0), //dir v3f (1, 0, 0), - v3POS(0, 0, 1), //face dir + v3pos_t(0, 0, 1), //face dir dest); } @@ -1007,7 +1007,7 @@ static void applyTileColor(PreMeshBuffer &pmb) MapBlockMesh */ -MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3POS camera_offset): +MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3pos_t camera_offset): m_minimap_mapblock(NULL), m_tsrc(data->m_client->getTextureSource()), m_shdrsrc(data->m_client->getShaderSource()), diff --git a/src/client/mapblock_mesh.h b/src/client/mapblock_mesh.h index 2c90d19366..39ea9ae158 100644 --- a/src/client/mapblock_mesh.h +++ b/src/client/mapblock_mesh.h @@ -39,8 +39,8 @@ struct MinimapMapblock; struct MeshMakeData { VoxelManipulator m_vmanip; - v3POS m_blockpos = v3POS(-1337,-1337,-1337); - v3POS m_crack_pos_relative = v3POS(-1337,-1337,-1337); + v3pos_t m_blockpos = v3pos_t(-1337,-1337,-1337); + v3pos_t m_crack_pos_relative = v3pos_t(-1337,-1337,-1337); bool m_smooth_lighting = false; Client *m_client; @@ -51,8 +51,8 @@ struct MeshMakeData /* Copy block data manually (to allow optimizations by the caller) */ - void fillBlockDataBegin(const v3POS &blockpos); - void fillBlockData(const v3POS &block_offset, MapNode *data); + void fillBlockDataBegin(const v3pos_t &blockpos); + void fillBlockData(const v3pos_t &block_offset, MapNode *data); /* Copy central data directly from block, and other data from @@ -63,7 +63,7 @@ struct MeshMakeData /* Set the (node) position of a crack */ - void setCrack(int crack_level, v3POS crack_pos); + void setCrack(int crack_level, v3pos_t crack_pos); /* Enable or disable smooth lighting @@ -86,7 +86,7 @@ class MapBlockMesh { public: // Builds the mesh given - MapBlockMesh(MeshMakeData *data, v3POS camera_offset); + MapBlockMesh(MeshMakeData *data, v3pos_t camera_offset); ~MapBlockMesh(); // Main animation function, parameters: @@ -176,10 +176,10 @@ video::SColor encode_light(u16 light, u8 emissive_light); // Compute light at node u16 getInteriorLight(MapNode n, s32 increment, const NodeDefManager *ndef); -u16 getFaceLight(MapNode n, MapNode n2, const v3POS &face_dir, +u16 getFaceLight(MapNode n, MapNode n2, const v3pos_t &face_dir, const NodeDefManager *ndef); -u16 getSmoothLightSolid(const v3POS &p, const v3POS &face_dir, const v3POS &corner, MeshMakeData *data); -u16 getSmoothLightTransparent(const v3POS &p, const v3POS &corner, MeshMakeData *data); +u16 getSmoothLightSolid(const v3pos_t &p, const v3pos_t &face_dir, const v3pos_t &corner, MeshMakeData *data); +u16 getSmoothLightTransparent(const v3pos_t &p, const v3pos_t &corner, MeshMakeData *data); /*! * Returns the sunlight's color from the current @@ -211,5 +211,5 @@ void final_color_blend(video::SColor *result, // Adds MATERIAL_FLAG_CRACK if the node is cracked // TileSpec should be passed as reference due to the underlying TileFrame and its vector // TileFrame vector copy cost very much to client -void getNodeTileN(MapNode mn, const v3POS &p, u8 tileindex, MeshMakeData *data, TileSpec &tile); -void getNodeTile(MapNode mn, const v3POS &p, const v3POS &dir, MeshMakeData *data, TileSpec &tile); +void getNodeTileN(MapNode mn, const v3pos_t &p, u8 tileindex, MeshMakeData *data, TileSpec &tile); +void getNodeTile(MapNode mn, const v3pos_t &p, const v3pos_t &dir, MeshMakeData *data, TileSpec &tile); diff --git a/src/client/mesh_generator_thread.cpp b/src/client/mesh_generator_thread.cpp index 9ac3f0410f..de658d4793 100644 --- a/src/client/mesh_generator_thread.cpp +++ b/src/client/mesh_generator_thread.cpp @@ -69,7 +69,7 @@ MeshUpdateQueue::~MeshUpdateQueue() } } -void MeshUpdateQueue::addBlock(Map *map, v3POS p, bool ack_block_to_server, bool urgent) +void MeshUpdateQueue::addBlock(Map *map, v3pos_t p, bool ack_block_to_server, bool urgent) { MutexAutoLock lock(m_mutex); @@ -82,13 +82,13 @@ void MeshUpdateQueue::addBlock(Map *map, v3POS p, bool ack_block_to_server, bool std::vector cached_blocks; size_t cache_hit_counter = 0; cached_blocks.reserve(3*3*3); - v3POS dp; + v3pos_t dp; for (dp.X = -1; dp.X <= 1; dp.X++) for (dp.Y = -1; dp.Y <= 1; dp.Y++) for (dp.Z = -1; dp.Z <= 1; dp.Z++) { - v3POS p1 = p + dp; + v3pos_t p1 = p + dp; CachedMapBlockData *cached_block; - if (dp == v3POS(0, 0, 0)) + if (dp == v3pos_t(0, 0, 0)) cached_block = cacheBlock(map, p1, FORCE_UPDATE); else cached_block = cacheBlock(map, p1, SKIP_UPDATE_IF_ALREADY_CACHED, @@ -156,11 +156,11 @@ QueuedMeshUpdate *MeshUpdateQueue::pop() return NULL; } -CachedMapBlockData* MeshUpdateQueue::cacheBlock(Map *map, v3POS p, UpdateMode mode, +CachedMapBlockData* MeshUpdateQueue::cacheBlock(Map *map, v3pos_t p, UpdateMode mode, size_t *cache_hit_counter) { CachedMapBlockData *cached_block = nullptr; - std::map::iterator it = + std::map::iterator it = m_cache.find(p); if (it != m_cache.end()) { @@ -193,9 +193,9 @@ CachedMapBlockData* MeshUpdateQueue::cacheBlock(Map *map, v3POS p, UpdateMode mo return cached_block; } -CachedMapBlockData* MeshUpdateQueue::getCachedBlock(const v3POS &p) +CachedMapBlockData* MeshUpdateQueue::getCachedBlock(const v3pos_t &p) { - std::map::iterator it = m_cache.find(p); + std::map::iterator it = m_cache.find(p); if (it != m_cache.end()) { return it->second; } @@ -212,11 +212,11 @@ void MeshUpdateQueue::fillDataFromMapBlockCache(QueuedMeshUpdate *q) std::time_t t_now = std::time(0); // Collect data for 3*3*3 blocks from cache - v3POS dp; + v3pos_t dp; for (dp.X = -1; dp.X <= 1; dp.X++) for (dp.Y = -1; dp.Y <= 1; dp.Y++) for (dp.Z = -1; dp.Z <= 1; dp.Z++) { - v3POS p = q->p + dp; + v3pos_t p = q->p + dp; CachedMapBlockData *cached_block = getCachedBlock(p); if (cached_block) { cached_block->refcount_from_queue--; @@ -246,7 +246,7 @@ void MeshUpdateQueue::cleanupCache() int t_now = time(0); - for (std::map::iterator it = m_cache.begin(); + for (std::map::iterator it = m_cache.begin(); it != m_cache.end(); ) { CachedMapBlockData *cached_block = it->second; if (cached_block->refcount_from_queue == 0 && @@ -271,7 +271,7 @@ MeshUpdateThread::MeshUpdateThread(Client *client): m_generation_interval = rangelim(m_generation_interval, 0, 50); } -void MeshUpdateThread::updateBlock(Map *map, v3POS p, bool ack_block_to_server, +void MeshUpdateThread::updateBlock(Map *map, v3pos_t p, bool ack_block_to_server, bool urgent) { // Allow the MeshUpdateQueue to do whatever it wants diff --git a/src/client/mesh_generator_thread.h b/src/client/mesh_generator_thread.h index a44b4dbd04..65ad89860c 100644 --- a/src/client/mesh_generator_thread.h +++ b/src/client/mesh_generator_thread.h @@ -27,7 +27,7 @@ with this program; if not, write to the Free Software Foundation, Inc., struct CachedMapBlockData { - v3POS p = v3POS(-1337, -1337, -1337); + v3pos_t p = v3pos_t(-1337, -1337, -1337); MapNode *data = nullptr; // A copy of the MapBlock's data member int refcount_from_queue = 0; std::time_t last_used_timestamp = std::time(0); @@ -38,10 +38,10 @@ struct CachedMapBlockData struct QueuedMeshUpdate { - v3POS p = v3POS(-1337, -1337, -1337); + v3pos_t p = v3pos_t(-1337, -1337, -1337); bool ack_block_to_server = false; int crack_level = -1; - v3POS crack_pos; + v3pos_t crack_pos; MeshMakeData *data = nullptr; // This is generated in MeshUpdateQueue::pop() QueuedMeshUpdate() = default; @@ -66,7 +66,7 @@ class MeshUpdateQueue // Caches the block at p and its neighbors (if needed) and queues a mesh // update for the block at p - void addBlock(Map *map, v3POS p, bool ack_block_to_server, bool urgent); + void addBlock(Map *map, v3pos_t p, bool ack_block_to_server, bool urgent); // Returned pointer must be deleted // Returns NULL if queue is empty @@ -81,8 +81,8 @@ class MeshUpdateQueue private: Client *m_client; std::vector m_queue; - std::set m_urgents; - std::map m_cache; + std::set m_urgents; + std::map m_cache; std::mutex m_mutex; // TODO: Add callback to update these when g_settings changes @@ -90,16 +90,16 @@ class MeshUpdateQueue bool m_cache_smooth_lighting; int m_meshgen_block_cache_size; - CachedMapBlockData *cacheBlock(Map *map, v3POS p, UpdateMode mode, + CachedMapBlockData *cacheBlock(Map *map, v3pos_t p, UpdateMode mode, size_t *cache_hit_counter = NULL); - CachedMapBlockData *getCachedBlock(const v3POS &p); + CachedMapBlockData *getCachedBlock(const v3pos_t &p); void fillDataFromMapBlockCache(QueuedMeshUpdate *q); void cleanupCache(); }; struct MeshUpdateResult { - v3POS p = v3POS(-1338, -1338, -1338); + v3pos_t p = v3pos_t(-1338, -1338, -1338); MapBlockMesh *mesh = nullptr; bool ack_block_to_server = false; @@ -113,9 +113,9 @@ class MeshUpdateThread : public UpdateThread // Caches the block at p and its neighbors (if needed) and queues a mesh // update for the block at p - void updateBlock(Map *map, v3POS p, bool ack_block_to_server, bool urgent); + void updateBlock(Map *map, v3pos_t p, bool ack_block_to_server, bool urgent); - v3POS m_camera_offset; + v3pos_t m_camera_offset; MutexedQueue m_queue_out; private: diff --git a/src/client/minimap.cpp b/src/client/minimap.cpp index 13d9074718..1e79339d43 100644 --- a/src/client/minimap.cpp +++ b/src/client/minimap.cpp @@ -42,7 +42,7 @@ MinimapUpdateThread::~MinimapUpdateThread() } } -bool MinimapUpdateThread::pushBlockUpdate(v3POS pos, MinimapMapblock *data) +bool MinimapUpdateThread::pushBlockUpdate(v3pos_t pos, MinimapMapblock *data) { MutexAutoLock lock(m_queue_mutex); @@ -78,7 +78,7 @@ bool MinimapUpdateThread::popBlockUpdate(QueuedMinimapUpdate *update) return true; } -void MinimapUpdateThread::enqueueBlock(v3POS pos, MinimapMapblock *data) +void MinimapUpdateThread::enqueueBlock(v3pos_t pos, MinimapMapblock *data) { pushBlockUpdate(pos, data); deferUpdate(); @@ -92,14 +92,14 @@ void MinimapUpdateThread::doUpdate() while (popBlockUpdate(&update)) { if (update.data) { // Swap two values in the map using single lookup - std::pair::iterator, bool> + std::pair::iterator, bool> result = m_blocks_cache.insert(std::make_pair(update.pos, update.data)); if (!result.second) { delete result.first->second; result.first->second = update.data; } } else { - std::map::iterator it; + std::map::iterator it; it = m_blocks_cache.find(update.pos); if (it != m_blocks_cache.end()) { delete it->second; @@ -117,12 +117,12 @@ void MinimapUpdateThread::doUpdate() } } -void MinimapUpdateThread::getMap(v3POS pos, s16 size, POS height) +void MinimapUpdateThread::getMap(v3pos_t pos, s16 size, pos_t height) { - v3POS pos_min(pos.X - size / 2, pos.Y - height / 2, pos.Z - size / 2); - v3POS pos_max(pos_min.X + size - 1, pos.Y + height / 2, pos_min.Z + size - 1); - v3BPOS blockpos_min = getNodeBlockPos(pos_min); - v3BPOS blockpos_max = getNodeBlockPos(pos_max); + v3pos_t pos_min(pos.X - size / 2, pos.Y - height / 2, pos.Z - size / 2); + v3pos_t pos_max(pos_min.X + size - 1, pos.Y + height / 2, pos_min.Z + size - 1); + v3bpos_t blockpos_min = getNodeBlockPos(pos_min); + v3bpos_t blockpos_max = getNodeBlockPos(pos_max); // clear the map for (int z = 0; z < size; z++) @@ -134,31 +134,31 @@ void MinimapUpdateThread::getMap(v3POS pos, s16 size, POS height) } // draw the map - v3BPOS blockpos; + v3bpos_t blockpos; for (blockpos.Z = blockpos_min.Z; blockpos.Z <= blockpos_max.Z; ++blockpos.Z) for (blockpos.Y = blockpos_min.Y; blockpos.Y <= blockpos_max.Y; ++blockpos.Y) for (blockpos.X = blockpos_min.X; blockpos.X <= blockpos_max.X; ++blockpos.X) { - std::map::const_iterator pblock = + std::map::const_iterator pblock = m_blocks_cache.find(blockpos); if (pblock == m_blocks_cache.end()) continue; const MinimapMapblock &block = *pblock->second; - v3POS block_node_min(blockpos * MAP_BLOCKSIZE); - v3POS block_node_max(block_node_min + MAP_BLOCKSIZE - 1); + v3pos_t block_node_min(blockpos * MAP_BLOCKSIZE); + v3pos_t block_node_max(block_node_min + MAP_BLOCKSIZE - 1); // clip - v3POS range_min = componentwise_max(block_node_min, pos_min); - v3POS range_max = componentwise_min(block_node_max, pos_max); + v3pos_t range_min = componentwise_max(block_node_min, pos_min); + v3pos_t range_max = componentwise_min(block_node_max, pos_max); - v3POS pos; + v3pos_t pos; pos.Y = range_min.Y; for (pos.Z = range_min.Z; pos.Z <= range_max.Z; ++pos.Z) for (pos.X = range_min.X; pos.X <= range_max.X; ++pos.X) { - v3POS inblock_pos = pos - block_node_min; + v3pos_t inblock_pos = pos - block_node_min; const MinimapPixel &in_pixel = block.data[inblock_pos.Z * MAP_BLOCKSIZE + inblock_pos.X]; - v3POS inmap_pos = pos - pos_min; + v3pos_t inmap_pos = pos - pos_min; MinimapPixel &out_pixel = data->minimap_scan[inmap_pos.X + inmap_pos.Z * size]; @@ -260,7 +260,7 @@ Minimap::~Minimap() delete m_minimap_update_thread; } -void Minimap::addBlock(v3POS pos, MinimapMapblock *data) +void Minimap::addBlock(v3pos_t pos, MinimapMapblock *data) { m_minimap_update_thread->enqueueBlock(pos, data); } @@ -394,7 +394,7 @@ void Minimap::nextMode() setModeIndex(m_current_mode_index); } -void Minimap::setPos(v3POS pos) +void Minimap::setPos(v3pos_t pos) { bool do_update = false; @@ -705,12 +705,12 @@ void Minimap::updateActiveMarkers() m_active_markers.clear(); v3f cam_offset = intToFloat(client->getCamera()->getOffset(), BS); - v3POS pos_offset = data->pos - v3POS(data->mode.map_size / 2, + v3pos_t pos_offset = data->pos - v3pos_t(data->mode.map_size / 2, data->mode.scan_height / 2, data->mode.map_size / 2); for (MinimapMarker *marker : m_markers) { - v3POS pos = floatToInt(marker->parent_node->getAbsolutePosition() + + v3pos_t pos = floatToInt(marker->parent_node->getAbsolutePosition() + cam_offset, BS) - pos_offset; if (pos.X < 0 || pos.X > data->mode.map_size || pos.Y < 0 || pos.Y > data->mode.scan_height || @@ -733,7 +733,7 @@ void Minimap::updateActiveMarkers() //// MinimapMapblock //// -void MinimapMapblock::getMinimapNodes(VoxelManipulator *vmanip, const v3POS &pos) +void MinimapMapblock::getMinimapNodes(VoxelManipulator *vmanip, const v3pos_t &pos) { for (s16 x = 0; x < MAP_BLOCKSIZE; x++) @@ -743,7 +743,7 @@ void MinimapMapblock::getMinimapNodes(VoxelManipulator *vmanip, const v3POS &pos MinimapPixel *mmpixel = &data[z * MAP_BLOCKSIZE + x]; for (s16 y = MAP_BLOCKSIZE -1; y >= 0; y--) { - v3POS p(x, y, z); + v3pos_t p(x, y, z); MapNode n = vmanip->getNodeNoEx(pos + p); if (!surface_found && n.getContent() != CONTENT_AIR) { mmpixel->height = y; diff --git a/src/client/minimap.h b/src/client/minimap.h index cfa595b26e..4c196f5a70 100644 --- a/src/client/minimap.h +++ b/src/client/minimap.h @@ -63,15 +63,15 @@ struct MinimapPixel { }; struct MinimapMapblock { - void getMinimapNodes(VoxelManipulator *vmanip, const v3POS &pos); + void getMinimapNodes(VoxelManipulator *vmanip, const v3pos_t &pos); MinimapPixel data[MAP_BLOCKSIZE * MAP_BLOCKSIZE]; }; struct MinimapData { MinimapModeDef mode; - v3POS pos; - v3POS old_pos; + v3pos_t pos; + v3pos_t old_pos; MinimapPixel minimap_scan[MINIMAP_MAX_SX * MINIMAP_MAX_SY]; bool map_invalidated; bool minimap_shape_round; @@ -86,7 +86,7 @@ struct MinimapData { }; struct QueuedMinimapUpdate { - v3BPOS pos; + v3bpos_t pos; MinimapMapblock *data = nullptr; }; @@ -95,9 +95,9 @@ class MinimapUpdateThread : public UpdateThread { MinimapUpdateThread() : UpdateThread("Minimap") {} virtual ~MinimapUpdateThread(); - void getMap(v3BPOS pos, s16 size, POS height); - void enqueueBlock(v3BPOS pos, MinimapMapblock *data); - bool pushBlockUpdate(v3BPOS pos, MinimapMapblock *data); + void getMap(v3bpos_t pos, s16 size, pos_t height); + void enqueueBlock(v3bpos_t pos, MinimapMapblock *data); + bool pushBlockUpdate(v3bpos_t pos, MinimapMapblock *data); bool popBlockUpdate(QueuedMinimapUpdate *update); MinimapData *data = nullptr; @@ -108,7 +108,7 @@ class MinimapUpdateThread : public UpdateThread { private: std::mutex m_queue_mutex; std::deque m_update_queue; - std::map m_blocks_cache; + std::map m_blocks_cache; }; class Minimap { @@ -116,12 +116,12 @@ class Minimap { Minimap(Client *client); ~Minimap(); - void addBlock(v3BPOS pos, MinimapMapblock *data); + void addBlock(v3bpos_t pos, MinimapMapblock *data); v3f getYawVec(); - void setPos(v3POS pos); - v3POS getPos() const { return data->pos; } + void setPos(v3pos_t pos); + v3pos_t getPos() const { return data->pos; } void setAngle(f32 angle); f32 getAngle() const { return m_angle; } void toggleMinimapShape(); diff --git a/src/client/particles.cpp b/src/client/particles.cpp index 0e09f62243..31a9cc83c3 100644 --- a/src/client/particles.cpp +++ b/src/client/particles.cpp @@ -177,7 +177,7 @@ void Particle::updateLight() u8 light = 0; bool pos_ok; - v3POS p = v3POS( + v3pos_t p = v3pos_t( floor(m_pos.X+0.5), floor(m_pos.Y+0.5), floor(m_pos.Z+0.5) @@ -227,7 +227,7 @@ void Particle::updateVertices() m_vertices[3] = video::S3DVertex(-m_size / 2, m_size / 2, 0, 0, 0, 0, m_color, tx0, ty0); - v3POS camera_offset = m_env->getCameraOffset(); + v3pos_t camera_offset = m_env->getCameraOffset(); for (video::S3DVertex &vertex : m_vertices) { if (m_vertical) { v3f ppos = m_player->getPosition()/BS; @@ -281,7 +281,7 @@ void ParticleSpawner::spawnParticle(ClientEnvironment *env, float radius, pos *= BS; attached_absolute_pos_rot_matrix->transformVect(pos); pos /= BS; - v3POS camera_offset = m_particlemanager->m_env->getCameraOffset(); + v3pos_t camera_offset = m_particlemanager->m_env->getCameraOffset(); pos.X += camera_offset.X; pos.Y += camera_offset.Y; pos.Z += camera_offset.Z; @@ -559,7 +559,7 @@ bool ParticleManager::getNodeParticleParams(const MapNode &n, // spawned during the digging of a node. void ParticleManager::addDiggingParticles(IGameDef *gamedef, - LocalPlayer *player, v3POS pos, const MapNode &n, const ContentFeatures &f) + LocalPlayer *player, v3pos_t pos, const MapNode &n, const ContentFeatures &f) { // No particles for "airlike" nodes if (f.drawtype == NDT_AIRLIKE) @@ -574,7 +574,7 @@ void ParticleManager::addDiggingParticles(IGameDef *gamedef, // function, called from Game::handleDigging() in game.cpp. void ParticleManager::addNodeParticle(IGameDef *gamedef, - LocalPlayer *player, v3POS pos, const MapNode &n, const ContentFeatures &f) + LocalPlayer *player, v3pos_t pos, const MapNode &n, const ContentFeatures &f) { ParticleParameters p; video::ITexture *texture; diff --git a/src/client/particles.h b/src/client/particles.h index 965d229014..2f027e118f 100644 --- a/src/client/particles.h +++ b/src/client/particles.h @@ -97,7 +97,7 @@ class Particle : public scene::ISceneNode bool m_collision_removal; bool m_object_collision; bool m_vertical; - v3POS m_camera_offset; + v3pos_t m_camera_offset; struct TileAnimationParams m_animation; float m_animation_time = 0.0f; int m_animation_frame = 0; @@ -150,10 +150,10 @@ friend class ParticleSpawner; void handleParticleEvent(ClientEvent *event, Client *client, LocalPlayer *player); - void addDiggingParticles(IGameDef *gamedef, LocalPlayer *player, v3POS pos, + void addDiggingParticles(IGameDef *gamedef, LocalPlayer *player, v3pos_t pos, const MapNode &n, const ContentFeatures &f); - void addNodeParticle(IGameDef *gamedef, LocalPlayer *player, v3POS pos, + void addNodeParticle(IGameDef *gamedef, LocalPlayer *player, v3pos_t pos, const MapNode &n, const ContentFeatures &f); /** diff --git a/src/client/shadows/dynamicshadows.cpp b/src/client/shadows/dynamicshadows.cpp index b69c963b31..6b4e6a5463 100644 --- a/src/client/shadows/dynamicshadows.cpp +++ b/src/client/shadows/dynamicshadows.cpp @@ -110,7 +110,7 @@ void DirectionalLight::update_frustum(const Camera *cam, Client *client, bool fo dirty = true; // when camera offset changes, adjust the current frustum view matrix to avoid flicker - v3POS cam_offset = cam->getOffset(); + v3pos_t cam_offset = cam->getOffset(); if (cam_offset != shadow_frustum.camera_offset) { v3f rotated_offset; shadow_frustum.ViewMat.rotateVect(rotated_offset, intToFloat(cam_offset - shadow_frustum.camera_offset, BS)); diff --git a/src/client/shadows/dynamicshadows.h b/src/client/shadows/dynamicshadows.h index 69d894a3e8..7c6cb02226 100644 --- a/src/client/shadows/dynamicshadows.h +++ b/src/client/shadows/dynamicshadows.h @@ -34,7 +34,7 @@ struct shadowFrustum core::matrix4 ProjOrthMat; core::matrix4 ViewMat; v3f position; - v3POS camera_offset; + v3pos_t camera_offset; }; class DirectionalLight diff --git a/src/client/tile.cpp b/src/client/tile.cpp index 97191152fb..97b5008a47 100644 --- a/src/client/tile.cpp +++ b/src/client/tile.cpp @@ -848,7 +848,7 @@ static video::IImage *createInventoryCubeImage( auto draw_image = [=] (video::IImage *image, float shade_factor, s16 xu, s16 xv, s16 x1, s16 yu, s16 yv, s16 y1, - std::initializer_list offsets) -> void { + std::initializer_list offsets) -> void { u32 brightness = core::clamp(256 * shade_factor, 0, 256); const u32 *source = lock_image(image); for (u16 v = 0; v < size; v++) { diff --git a/src/clientiface.cpp b/src/clientiface.cpp index bdc6b11b9e..635bf400e2 100644 --- a/src/clientiface.cpp +++ b/src/clientiface.cpp @@ -64,7 +64,7 @@ RemoteClient::RemoteClient() : { } -void RemoteClient::ResendBlockIfOnWire(v3POS p) +void RemoteClient::ResendBlockIfOnWire(v3pos_t p) { // if this block is on wire, mark it for sending again as soon as possible if (m_blocks_sending.find(p) != m_blocks_sending.end()) { @@ -128,9 +128,9 @@ void RemoteClient::GetNextBlocks ( // Predict to next block v3f playerpos_predicted = playerpos + playerspeeddir * (MAP_BLOCKSIZE * BS); - v3POS center_nodepos = floatToInt(playerpos_predicted, BS); + v3pos_t center_nodepos = floatToInt(playerpos_predicted, BS); - v3BPOS center = getNodeBlockPos(center_nodepos); + v3bpos_t center = getNodeBlockPos(center_nodepos); // Camera position and direction v3f camera_pos = sao->getEyePosition(); @@ -184,7 +184,7 @@ void RemoteClient::GetNextBlocks ( } if (m_nearest_unsent_d > 0) { // make sure any blocks modified since the last time we sent blocks are resent - for (const v3POS &p : m_blocks_modified) { + for (const v3pos_t &p : m_blocks_modified) { m_nearest_unsent_d = std::min(m_nearest_unsent_d, center.getDistanceFrom(p)); } } @@ -229,7 +229,7 @@ void RemoteClient::GetNextBlocks ( s32 nearest_sent_d = -1; //bool queue_is_full = false; - const v3POS cam_pos_nodes = floatToInt(camera_pos, BS); + const v3pos_t cam_pos_nodes = floatToInt(camera_pos, BS); s16 d; for (d = d_start; d <= d_max; d++) { @@ -237,11 +237,11 @@ void RemoteClient::GetNextBlocks ( Get the border/face dot coordinates of a "d-radiused" box */ - std::vector list = FacePositionCache::getFacePositions(d); + std::vector list = FacePositionCache::getFacePositions(d); - std::vector::iterator li; + std::vector::iterator li; for (li = list.begin(); li != list.end(); ++li) { - v3BPOS p = *li + center; + v3bpos_t p = *li + center; /* Send throttling @@ -395,7 +395,7 @@ void RemoteClient::GetNextBlocks ( m_nearest_unsent_d = new_nearest_unsent_d; } -void RemoteClient::GotBlock(v3BPOS p) +void RemoteClient::GotBlock(v3bpos_t p) { if (m_blocks_sending.find(p) != m_blocks_sending.end()) { m_blocks_sending.erase(p); @@ -407,7 +407,7 @@ void RemoteClient::GotBlock(v3BPOS p) } } -void RemoteClient::SentBlock(v3BPOS p) +void RemoteClient::SentBlock(v3bpos_t p) { if (m_blocks_sending.find(p) == m_blocks_sending.end()) m_blocks_sending[p] = 0.0f; @@ -416,7 +416,7 @@ void RemoteClient::SentBlock(v3BPOS p) " already in m_blocks_sending"< &blocks) +void RemoteClient::SetBlocksNotSent(std::map &blocks) { m_nothing_to_send_pause_timer = 0; for (auto &block : blocks) { - v3POS p = block.first; + v3pos_t p = block.first; // remove the block from sending and sent sets, // and mark as modified if found if (m_blocks_sending.erase(p) + m_blocks_sent.erase(p) > 0) @@ -637,7 +637,7 @@ std::vector ClientInterface::getClientIDs(ClientState min_state) return reply; } -void ClientInterface::markBlockposAsNotSent(const v3POS &pos) +void ClientInterface::markBlockposAsNotSent(const v3pos_t &pos) { RecursiveMutexAutoLock clientslock(m_clients_mutex); for (const auto &client : m_clients) { diff --git a/src/clientiface.h b/src/clientiface.h index f67c0cdedd..6d9f990d09 100644 --- a/src/clientiface.h +++ b/src/clientiface.h @@ -206,7 +206,7 @@ enum ClientStateEvent */ struct PrioritySortedBlockTransfer { - PrioritySortedBlockTransfer(float a_priority, const v3BPOS &a_pos, session_t a_peer_id) + PrioritySortedBlockTransfer(float a_priority, const v3bpos_t &a_pos, session_t a_peer_id) { priority = a_priority; pos = a_pos; @@ -217,7 +217,7 @@ struct PrioritySortedBlockTransfer return priority < other.priority; } float priority; - v3BPOS pos; + v3bpos_t pos; session_t peer_id; }; @@ -258,12 +258,12 @@ class RemoteClient void GetNextBlocks(ServerEnvironment *env, EmergeManager* emerge, float dtime, std::vector &dest); - void GotBlock(v3POS p); + void GotBlock(v3pos_t p); - void SentBlock(v3POS p); + void SentBlock(v3pos_t p); - void SetBlockNotSent(v3POS p); - void SetBlocksNotSent(std::map &blocks); + void SetBlockNotSent(v3pos_t p); + void SetBlocksNotSent(std::map &blocks); /** * tell client about this block being modified right now. @@ -271,11 +271,11 @@ class RemoteClient * while modification is processed by server * @param p position of modified block */ - void ResendBlockIfOnWire(v3POS p); + void ResendBlockIfOnWire(v3pos_t p); u32 getSendingCount() const { return m_blocks_sending.size(); } - bool isBlockSent(v3POS p) const + bool isBlockSent(v3pos_t p) const { return m_blocks_sent.find(p) != m_blocks_sent.end(); } @@ -369,9 +369,9 @@ class RemoteClient List of block positions. No MapBlock* is stored here because the blocks can get deleted. */ - std::set m_blocks_sent; - POS m_nearest_unsent_d = 0; - v3POS m_last_center; + std::set m_blocks_sent; + pos_t m_nearest_unsent_d = 0; + v3pos_t m_last_center; v3f m_last_camera_dir; const u16 m_max_simul_sends; @@ -389,7 +389,7 @@ class RemoteClient Block is removed when GOTBLOCKS is received. Value is time from sending. (not used at the moment) */ - std::map m_blocks_sending; + std::map m_blocks_sending; /* Blocks that have been modified since blocks were @@ -399,7 +399,7 @@ class RemoteClient List of block positions. */ - std::set m_blocks_modified; + std::set m_blocks_modified; /* Count of excess GotBlocks(). @@ -452,7 +452,7 @@ class ClientInterface { std::vector getClientIDs(ClientState min_state=CS_Active); /* mark block as not sent to active client sessions */ - void markBlockposAsNotSent(const v3POS &pos); + void markBlockposAsNotSent(const v3pos_t &pos); /* verify is server user limit was reached */ bool isUserLimitReached(); diff --git a/src/collision.cpp b/src/collision.cpp index 3c1a7b80a4..aed4301a50 100644 --- a/src/collision.cpp +++ b/src/collision.cpp @@ -38,7 +38,7 @@ with this program; if not, write to the Free Software Foundation, Inc., struct NearbyCollisionInfo { // node - NearbyCollisionInfo(bool is_ul, int bouncy, const v3POS &pos, + NearbyCollisionInfo(bool is_ul, int bouncy, const v3pos_t &pos, const aabb3f &box) : is_unloaded(is_ul), obj(nullptr), @@ -62,7 +62,7 @@ struct NearbyCollisionInfo { bool is_step_up = false; ActiveObject *obj; int bouncy; - v3POS position; + v3pos_t position; aabb3f box; }; @@ -214,7 +214,7 @@ bool wouldCollideWithCeiling( return false; } -static inline void getNeighborConnectingFace(const v3POS &p, +static inline void getNeighborConnectingFace(const v3pos_t &p, const NodeDefManager *nodedef, Map *map, MapNode n, int v, int *neighbors) { MapNode n2 = map->getNode(p); @@ -281,12 +281,12 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef, MYMAX(pos_f->Y, newpos_f.Y), MYMAX(pos_f->Z, newpos_f.Z) ); - v3POS min = floatToInt(minpos_f + box_0.MinEdge, BS) - v3POS(1, 1, 1); - v3POS max = floatToInt(maxpos_f + box_0.MaxEdge, BS) + v3POS(1, 1, 1); + v3pos_t min = floatToInt(minpos_f + box_0.MinEdge, BS) - v3pos_t(1, 1, 1); + v3pos_t max = floatToInt(maxpos_f + box_0.MaxEdge, BS) + v3pos_t(1, 1, 1); bool any_position_valid = false; - v3POS p; + v3pos_t p; for (p.X = min.X; p.X <= max.X; p.X++) for (p.Y = min.Y; p.Y <= max.Y; p.Y++) for (p.Z = min.Z; p.Z <= max.Z; p.Z++) { @@ -308,7 +308,7 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef, int neighbors = 0; if (f.drawtype == NDT_NODEBOX && f.node_box.type == NODEBOX_CONNECTED) { - v3POS p2 = p; + v3pos_t p2 = p; p2.Y++; getNeighborConnectingFace(p2, nodedef, map, n, 1, &neighbors); diff --git a/src/collision.h b/src/collision.h index 31cf92ff1d..23106752e4 100644 --- a/src/collision.h +++ b/src/collision.h @@ -47,7 +47,7 @@ struct CollisionInfo CollisionType type = COLLISION_NODE; CollisionAxis axis = COLLISION_AXIS_NONE; - v3POS node_p = v3POS(-32768,-32768,-32768); // COLLISION_NODE + v3pos_t node_p = v3pos_t(-32768,-32768,-32768); // COLLISION_NODE ActiveObject *object = nullptr; // COLLISION_OBJECT v3f old_speed; v3f new_speed; diff --git a/src/content_nodemeta.cpp b/src/content_nodemeta.cpp index 0c05abc1a5..640e1dee1c 100644 --- a/src/content_nodemeta.cpp +++ b/src/content_nodemeta.cpp @@ -165,7 +165,7 @@ void content_nodemeta_deserialize_legacy(std::istream &is, { u16 p16 = readU16(is); - v3POS p(0,0,0); + v3pos_t p(0,0,0); p.Z += p16 / MAP_BLOCKSIZE / MAP_BLOCKSIZE; p16 -= p.Z * MAP_BLOCKSIZE * MAP_BLOCKSIZE; p.Y += p16 / MAP_BLOCKSIZE; diff --git a/src/database/database-dummy.cpp b/src/database/database-dummy.cpp index 4881ab708f..ecbfb1ca2e 100644 --- a/src/database/database-dummy.cpp +++ b/src/database/database-dummy.cpp @@ -25,13 +25,13 @@ Dummy database class #include "remoteplayer.h" -bool Database_Dummy::saveBlock(const v3BPOS &pos, const std::string &data) +bool Database_Dummy::saveBlock(const v3bpos_t &pos, const std::string &data) { m_database[getBlockAsString(pos)] = data; return true; } -void Database_Dummy::loadBlock(const v3BPOS &pos, std::string *block) +void Database_Dummy::loadBlock(const v3bpos_t &pos, std::string *block) { std::string i = getBlockAsString(pos); auto it = m_database.find(i); @@ -43,13 +43,13 @@ void Database_Dummy::loadBlock(const v3BPOS &pos, std::string *block) *block = it->second; } -bool Database_Dummy::deleteBlock(const v3BPOS &pos) +bool Database_Dummy::deleteBlock(const v3bpos_t &pos) { m_database.erase(getBlockAsString(pos)); return true; } -void Database_Dummy::listAllLoadableBlocks(std::vector &dst) +void Database_Dummy::listAllLoadableBlocks(std::vector &dst) { dst.reserve(m_database.size()); for (std::map::const_iterator x = m_database.begin(); diff --git a/src/database/database-dummy.h b/src/database/database-dummy.h index 0b9620dc06..91919049fa 100644 --- a/src/database/database-dummy.h +++ b/src/database/database-dummy.h @@ -27,10 +27,10 @@ with this program; if not, write to the Free Software Foundation, Inc., class Database_Dummy : public MapDatabase, public PlayerDatabase { public: - bool saveBlock(const v3BPOS &pos, const std::string &data); - void loadBlock(const v3BPOS &pos, std::string *block); - bool deleteBlock(const v3BPOS &pos); - void listAllLoadableBlocks(std::vector &dst); + bool saveBlock(const v3bpos_t &pos, const std::string &data); + void loadBlock(const v3bpos_t &pos, std::string *block); + bool deleteBlock(const v3bpos_t &pos); + void listAllLoadableBlocks(std::vector &dst); void savePlayer(RemotePlayer *player); bool loadPlayer(RemotePlayer *player, PlayerSAO *sao); diff --git a/src/database/database-leveldb.cpp b/src/database/database-leveldb.cpp index a393e1edb4..4a86cd1d7b 100644 --- a/src/database/database-leveldb.cpp +++ b/src/database/database-leveldb.cpp @@ -55,7 +55,7 @@ Database_LevelDB::~Database_LevelDB() delete m_database; } -bool Database_LevelDB::saveBlock(const v3BPOS &pos, const std::string &data) +bool Database_LevelDB::saveBlock(const v3bpos_t &pos, const std::string &data) { leveldb::Status status = m_database->Put(leveldb::WriteOptions(), getBlockAsStringCompatible(pos), data); @@ -68,7 +68,7 @@ bool Database_LevelDB::saveBlock(const v3BPOS &pos, const std::string &data) return true; } -void Database_LevelDB::loadBlock(const v3BPOS &pos, std::string *block) +void Database_LevelDB::loadBlock(const v3bpos_t &pos, std::string *block) { leveldb::Status status = m_database->Get(leveldb::ReadOptions(), getBlockAsStringCompatible(pos), block); @@ -77,7 +77,7 @@ void Database_LevelDB::loadBlock(const v3BPOS &pos, std::string *block) block->clear(); } -bool Database_LevelDB::deleteBlock(const v3BPOS &pos) +bool Database_LevelDB::deleteBlock(const v3bpos_t &pos) { leveldb::Status status = m_database->Delete(leveldb::WriteOptions(), getBlockAsStringCompatible(pos)); @@ -90,7 +90,7 @@ bool Database_LevelDB::deleteBlock(const v3BPOS &pos) return true; } -void Database_LevelDB::listAllLoadableBlocks(std::vector &dst) +void Database_LevelDB::listAllLoadableBlocks(std::vector &dst) { leveldb::Iterator* it = m_database->NewIterator(leveldb::ReadOptions()); for (it->SeekToFirst(); it->Valid(); it->Next()) { diff --git a/src/database/database-leveldb.h b/src/database/database-leveldb.h index b1ffe270f5..7c868be11b 100644 --- a/src/database/database-leveldb.h +++ b/src/database/database-leveldb.h @@ -33,10 +33,10 @@ class Database_LevelDB : public MapDatabase Database_LevelDB(const std::string &savedir); ~Database_LevelDB(); - bool saveBlock(const v3BPOS &pos, const std::string &data); - void loadBlock(const v3BPOS &pos, std::string *block); - bool deleteBlock(const v3BPOS &pos); - void listAllLoadableBlocks(std::vector &dst); + bool saveBlock(const v3bpos_t &pos, const std::string &data); + void loadBlock(const v3bpos_t &pos, std::string *block); + bool deleteBlock(const v3bpos_t &pos); + void listAllLoadableBlocks(std::vector &dst); void beginSave() {} void endSave() {} diff --git a/src/database/database-postgresql.cpp b/src/database/database-postgresql.cpp index cd7bc536b2..d2f3cede83 100644 --- a/src/database/database-postgresql.cpp +++ b/src/database/database-postgresql.cpp @@ -226,7 +226,7 @@ void MapDatabasePostgreSQL::initStatements() "SELECT posX, posY, posZ FROM blocks"); } -bool MapDatabasePostgreSQL::saveBlock(const v3BPOS &pos, const std::string &data) +bool MapDatabasePostgreSQL::saveBlock(const v3bpos_t &pos, const std::string &data) { // Verify if we don't overflow the platform integer with the mapblock size if (data.size() > INT_MAX) { @@ -258,7 +258,7 @@ bool MapDatabasePostgreSQL::saveBlock(const v3BPOS &pos, const std::string &data return true; } -void MapDatabasePostgreSQL::loadBlock(const v3BPOS &pos, std::string *block) +void MapDatabasePostgreSQL::loadBlock(const v3bpos_t &pos, std::string *block) { verifyDatabase(); @@ -282,7 +282,7 @@ void MapDatabasePostgreSQL::loadBlock(const v3BPOS &pos, std::string *block) PQclear(results); } -bool MapDatabasePostgreSQL::deleteBlock(const v3BPOS &pos) +bool MapDatabasePostgreSQL::deleteBlock(const v3bpos_t &pos) { verifyDatabase(); @@ -300,7 +300,7 @@ bool MapDatabasePostgreSQL::deleteBlock(const v3BPOS &pos) return true; } -void MapDatabasePostgreSQL::listAllLoadableBlocks(std::vector &dst) +void MapDatabasePostgreSQL::listAllLoadableBlocks(std::vector &dst) { verifyDatabase(); @@ -310,7 +310,7 @@ void MapDatabasePostgreSQL::listAllLoadableBlocks(std::vector &dst) int numrows = PQntuples(results); for (int row = 0; row < numrows; ++row) - dst.push_back(pg_to_v3BPOS(results, row, 0)); + dst.push_back(pg_to_v3bpos_t(results, row, 0)); PQclear(results); } diff --git a/src/database/database-postgresql.h b/src/database/database-postgresql.h index 83f565c5ed..422d7d8b43 100644 --- a/src/database/database-postgresql.h +++ b/src/database/database-postgresql.h @@ -56,9 +56,9 @@ class Database_PostgreSQL: public Database return (float) atof(PQgetvalue(res, row, col)); } - inline v3BPOS pg_to_v3BPOS(PGresult *res, int row, int col) + inline v3bpos_t pg_to_v3bpos_t(PGresult *res, int row, int col) { - return v3BPOS( + return v3bpos_t( pg_to_int(res, row, col), pg_to_int(res, row, col + 1), pg_to_int(res, row, col + 2) @@ -114,10 +114,10 @@ class MapDatabasePostgreSQL : private Database_PostgreSQL, public MapDatabase MapDatabasePostgreSQL(const std::string &connect_string); virtual ~MapDatabasePostgreSQL() = default; - bool saveBlock(const v3BPOS &pos, const std::string &data); - void loadBlock(const v3BPOS &pos, std::string *block); - bool deleteBlock(const v3BPOS &pos); - void listAllLoadableBlocks(std::vector &dst); + bool saveBlock(const v3bpos_t &pos, const std::string &data); + void loadBlock(const v3bpos_t &pos, std::string *block); + bool deleteBlock(const v3bpos_t &pos); + void listAllLoadableBlocks(std::vector &dst); void beginSave() { Database_PostgreSQL::beginSave(); } void endSave() { Database_PostgreSQL::endSave(); } diff --git a/src/database/database-redis.cpp b/src/database/database-redis.cpp index 689da316e1..b3490b886d 100644 --- a/src/database/database-redis.cpp +++ b/src/database/database-redis.cpp @@ -90,7 +90,7 @@ void Database_Redis::endSave() { freeReplyObject(reply); } -bool Database_Redis::saveBlock(const v3BPOS &pos, const std::string &data) +bool Database_Redis::saveBlock(const v3bpos_t &pos, const std::string &data) { std::string tmp = getBlockAsStringCompatible(pos); @@ -114,7 +114,7 @@ bool Database_Redis::saveBlock(const v3BPOS &pos, const std::string &data) return true; } -void Database_Redis::loadBlock(const v3BPOS &pos, std::string *block) +void Database_Redis::loadBlock(const v3bpos_t &pos, std::string *block) { std::string tmp = getBlockAsStringCompatible(pos); redisReply *reply = static_cast(redisCommand(ctx, @@ -154,7 +154,7 @@ void Database_Redis::loadBlock(const v3BPOS &pos, std::string *block) "Redis command 'HGET %s %s' gave invalid reply.")); } -bool Database_Redis::deleteBlock(const v3BPOS &pos) +bool Database_Redis::deleteBlock(const v3bpos_t &pos) { std::string tmp = getBlockAsStringCompatible(pos); @@ -174,7 +174,7 @@ bool Database_Redis::deleteBlock(const v3BPOS &pos) return true; } -void Database_Redis::listAllLoadableBlocks(std::vector &dst) +void Database_Redis::listAllLoadableBlocks(std::vector &dst) { redisReply *reply = static_cast(redisCommand(ctx, "HKEYS %s", hash.c_str())); if (!reply) { diff --git a/src/database/database-redis.h b/src/database/database-redis.h index edd0fff86b..c0cb3c0416 100644 --- a/src/database/database-redis.h +++ b/src/database/database-redis.h @@ -38,10 +38,10 @@ class Database_Redis : public MapDatabase void beginSave(); void endSave(); - bool saveBlock(const v3BPOS &pos, const std::string &data); - void loadBlock(const v3BPOS &pos, std::string *block); - bool deleteBlock(const v3BPOS &pos); - void listAllLoadableBlocks(std::vector &dst); + bool saveBlock(const v3bpos_t &pos, const std::string &data); + void loadBlock(const v3bpos_t &pos, std::string *block); + bool deleteBlock(const v3bpos_t &pos); + void listAllLoadableBlocks(std::vector &dst); private: redisContext *ctx = nullptr; diff --git a/src/database/database-sqlite3.cpp b/src/database/database-sqlite3.cpp index a60f9ec390..854685c1e8 100644 --- a/src/database/database-sqlite3.cpp +++ b/src/database/database-sqlite3.cpp @@ -239,13 +239,13 @@ void MapDatabaseSQLite3::initStatements() verbosestream << "ServerMap: SQLite3 database opened." << std::endl; } -inline void MapDatabaseSQLite3::bindPos(sqlite3_stmt *stmt, const v3BPOS &pos, int index) +inline void MapDatabaseSQLite3::bindPos(sqlite3_stmt *stmt, const v3bpos_t &pos, int index) { SQLOK(sqlite3_bind_int64(stmt, index, getBlockAsInteger(pos)), "Internal error: failed to bind query at " __FILE__ ":" TOSTRING(__LINE__)); } -bool MapDatabaseSQLite3::deleteBlock(const v3BPOS &pos) +bool MapDatabaseSQLite3::deleteBlock(const v3bpos_t &pos) { verifyDatabase(); @@ -261,7 +261,7 @@ bool MapDatabaseSQLite3::deleteBlock(const v3BPOS &pos) return good; } -bool MapDatabaseSQLite3::saveBlock(const v3BPOS &pos, const std::string &data) +bool MapDatabaseSQLite3::saveBlock(const v3bpos_t &pos, const std::string &data) { verifyDatabase(); @@ -288,7 +288,7 @@ bool MapDatabaseSQLite3::saveBlock(const v3BPOS &pos, const std::string &data) return true; } -void MapDatabaseSQLite3::loadBlock(const v3BPOS &pos, std::string *block) +void MapDatabaseSQLite3::loadBlock(const v3bpos_t &pos, std::string *block) { verifyDatabase(); @@ -312,7 +312,7 @@ void MapDatabaseSQLite3::loadBlock(const v3BPOS &pos, std::string *block) sqlite3_reset(m_stmt_read); } -void MapDatabaseSQLite3::listAllLoadableBlocks(std::vector &dst) +void MapDatabaseSQLite3::listAllLoadableBlocks(std::vector &dst) { verifyDatabase(); diff --git a/src/database/database-sqlite3.h b/src/database/database-sqlite3.h index cc93581c1c..bfebf3de6b 100644 --- a/src/database/database-sqlite3.h +++ b/src/database/database-sqlite3.h @@ -146,10 +146,10 @@ class MapDatabaseSQLite3 : private Database_SQLite3, public MapDatabase MapDatabaseSQLite3(const std::string &savedir); virtual ~MapDatabaseSQLite3(); - bool saveBlock(const v3BPOS &pos, const std::string &data); - void loadBlock(const v3BPOS &pos, std::string *block); - bool deleteBlock(const v3BPOS &pos); - void listAllLoadableBlocks(std::vector &dst); + bool saveBlock(const v3bpos_t &pos, const std::string &data); + void loadBlock(const v3bpos_t &pos, std::string *block); + bool deleteBlock(const v3bpos_t &pos); + void listAllLoadableBlocks(std::vector &dst); void beginSave() { Database_SQLite3::beginSave(); } void endSave() { Database_SQLite3::endSave(); } @@ -158,7 +158,7 @@ class MapDatabaseSQLite3 : private Database_SQLite3, public MapDatabase virtual void initStatements(); private: - void bindPos(sqlite3_stmt *stmt, const v3BPOS &pos, int index = 1); + void bindPos(sqlite3_stmt *stmt, const v3bpos_t &pos, int index = 1); // Map sqlite3_stmt *m_stmt_read = nullptr; diff --git a/src/database/database.cpp b/src/database/database.cpp index 9c14494997..555d0a2ab8 100644 --- a/src/database/database.cpp +++ b/src/database/database.cpp @@ -52,7 +52,7 @@ static inline s64 pythonmodulo(s64 i, s16 mod) } -s64 MapDatabase::getBlockAsInteger(const v3BPOS &pos) +s64 MapDatabase::getBlockAsInteger(const v3bpos_t &pos) { return (u64) pos.Z * 0x1000000 + (u64) pos.Y * 0x1000 + @@ -60,9 +60,9 @@ s64 MapDatabase::getBlockAsInteger(const v3BPOS &pos) } -v3BPOS MapDatabase::getIntegerAsBlock(s64 i) +v3bpos_t MapDatabase::getIntegerAsBlock(s64 i) { - v3BPOS pos; + v3bpos_t pos; pos.X = unsigned_to_signed(pythonmodulo(i, 4096), 2048); i = (i - pos.X) / 4096; pos.Y = unsigned_to_signed(pythonmodulo(i, 4096), 2048); @@ -71,7 +71,7 @@ v3BPOS MapDatabase::getIntegerAsBlock(s64 i) return pos; } -std::string MapDatabase::getBlockAsString(const v3BPOS &pos) const +std::string MapDatabase::getBlockAsString(const v3bpos_t &pos) const { // 'a' is like version marker. In future other letters or words can be used. std::ostringstream os; @@ -79,10 +79,10 @@ std::string MapDatabase::getBlockAsString(const v3BPOS &pos) const return os.str().c_str(); } -std::string MapDatabase::getBlockAsStringCompatible(const v3BPOS &pos) const +std::string MapDatabase::getBlockAsStringCompatible(const v3bpos_t &pos) const { #if USE_POS32 - const BPOS max_limit_bp = 31000 / MAP_BLOCKSIZE; + const bpos_t max_limit_bp = 31000 / MAP_BLOCKSIZE; if (pos.X < -max_limit_bp || pos.X > max_limit_bp || pos.Y < -max_limit_bp || @@ -96,11 +96,11 @@ std::string MapDatabase::getBlockAsStringCompatible(const v3BPOS &pos) const #endif } -v3BPOS MapDatabase::getStringAsBlock(const std::string &i) const +v3bpos_t MapDatabase::getStringAsBlock(const std::string &i) const { #if USE_POS32 std::istringstream is(i); - v3BPOS pos; + v3bpos_t pos; char c; if (i[0] == 'a') { is >> c; // 'a' diff --git a/src/database/database.h b/src/database/database.h index 402d9fef9a..427ae41d16 100644 --- a/src/database/database.h +++ b/src/database/database.h @@ -39,18 +39,18 @@ class MapDatabase : public Database public: virtual ~MapDatabase() = default; - virtual bool saveBlock(const v3BPOS &pos, const std::string &data) = 0; - virtual void loadBlock(const v3BPOS &pos, std::string *block) = 0; - virtual bool deleteBlock(const v3BPOS &pos) = 0; + virtual bool saveBlock(const v3bpos_t &pos, const std::string &data) = 0; + virtual void loadBlock(const v3bpos_t &pos, std::string *block) = 0; + virtual bool deleteBlock(const v3bpos_t &pos) = 0; - static s64 getBlockAsInteger(const v3BPOS &pos); - static v3BPOS getIntegerAsBlock(s64 i); + static s64 getBlockAsInteger(const v3bpos_t &pos); + static v3bpos_t getIntegerAsBlock(s64 i); - std::string getBlockAsString(const v3BPOS &pos) const; - std::string getBlockAsStringCompatible(const v3BPOS &pos) const; - v3BPOS getStringAsBlock(const std::string &i) const; + std::string getBlockAsString(const v3bpos_t &pos) const; + std::string getBlockAsStringCompatible(const v3bpos_t &pos) const; + v3bpos_t getStringAsBlock(const std::string &i) const; - virtual void listAllLoadableBlocks(std::vector &dst) = 0; + virtual void listAllLoadableBlocks(std::vector &dst) = 0; }; class PlayerSAO; diff --git a/src/emerge.cpp b/src/emerge.cpp index 46c8481dd3..c4b5f59503 100644 --- a/src/emerge.cpp +++ b/src/emerge.cpp @@ -57,12 +57,12 @@ class EmergeThread : public Thread { void signal(); // Requires queue mutex held - bool pushBlock(const v3BPOS &pos); + bool pushBlock(const v3bpos_t &pos); void cancelPendingItems(); static void runCompletionCallbacks( - const v3BPOS &pos, EmergeAction action, + const v3bpos_t &pos, EmergeAction action, const EmergeCallbackList &callbacks); private: @@ -72,14 +72,14 @@ class EmergeThread : public Thread { Mapgen *m_mapgen; Event m_queue_event; - std::queue m_block_queue; + std::queue m_block_queue; - bool popBlockEmerge(v3BPOS *pos, BlockEmergeData *bedata); + bool popBlockEmerge(v3bpos_t *pos, BlockEmergeData *bedata); EmergeAction getBlockOrStartGen( - const v3BPOS &pos, bool allow_gen, MapBlock **block, BlockMakeData *data); - MapBlock *finishGen(v3BPOS pos, BlockMakeData *bmdata, - std::map *modified_blocks); + const v3bpos_t &pos, bool allow_gen, MapBlock **block, BlockMakeData *data); + MapBlock *finishGen(v3bpos_t pos, BlockMakeData *bmdata, + std::map *modified_blocks); friend class EmergeManager; }; @@ -244,7 +244,7 @@ void EmergeManager::initMapgens(MapgenParams *params) mgparams = params; - v3POS csize = v3POS(1, 1, 1) * (params->chunksize * MAP_BLOCKSIZE); + v3pos_t csize = v3pos_t(1, 1, 1) * (params->chunksize * MAP_BLOCKSIZE); biomegen = biomemgr->createBiomeGen(BIOMEGEN_ORIGINAL, params->bparams, csize); for (u32 i = 0; i != m_threads.size(); i++) { @@ -311,7 +311,7 @@ bool EmergeManager::isRunning() bool EmergeManager::enqueueBlockEmerge( session_t peer_id, - v3BPOS blockpos, + v3bpos_t blockpos, bool allow_generate, bool ignore_queue_limits) { @@ -326,7 +326,7 @@ bool EmergeManager::enqueueBlockEmerge( bool EmergeManager::enqueueBlockEmergeEx( - v3BPOS blockpos, + v3bpos_t blockpos, session_t peer_id, u16 flags, EmergeCompletionCallback callback, @@ -355,7 +355,7 @@ bool EmergeManager::enqueueBlockEmergeEx( } -bool EmergeManager::isBlockInQueue(v3BPOS pos) +bool EmergeManager::isBlockInQueue(v3bpos_t pos) { MutexAutoLock queuelock(m_queue_mutex); return m_blocks_enqueued.find(pos) != m_blocks_enqueued.end(); @@ -368,17 +368,17 @@ bool EmergeManager::isBlockInQueue(v3BPOS pos) // TODO(hmmmm): Move this to ServerMap -v3BPOS EmergeManager::getContainingChunk(v3BPOS blockpos, s16 chunksize) +v3bpos_t EmergeManager::getContainingChunk(v3bpos_t blockpos, s16 chunksize) { s16 coff = -chunksize / 2; - v3BPOS chunk_offset(coff, coff, coff); + v3bpos_t chunk_offset(coff, coff, coff); return getContainerPos(blockpos - chunk_offset, chunksize) * chunksize + chunk_offset; } -int EmergeManager::getSpawnLevelAtPoint(v2POS p) +int EmergeManager::getSpawnLevelAtPoint(v2pos_t p) { if (m_mapgens.empty() || !m_mapgens[0]) { errorstream << "EmergeManager: getSpawnLevelAtPoint() called" @@ -391,14 +391,14 @@ int EmergeManager::getSpawnLevelAtPoint(v2POS p) // TODO(hmmmm): Move this to ServerMap -bool EmergeManager::isBlockUnderground(v3BPOS blockpos) +bool EmergeManager::isBlockUnderground(v3bpos_t blockpos) { // Use a simple heuristic return blockpos.Y * (MAP_BLOCKSIZE + 1) <= mgparams->water_level; } bool EmergeManager::pushBlockEmergeData( - v3BPOS pos, + v3bpos_t pos, u16 peer_requested, u16 flags, EmergeCompletionCallback callback, @@ -423,7 +423,7 @@ bool EmergeManager::pushBlockEmergeData( } } - std::pair::iterator, bool> findres; + std::pair::iterator, bool> findres; findres = m_blocks_enqueued.insert(std::make_pair(pos, BlockEmergeData())); BlockEmergeData &bedata = findres.first->second; @@ -445,7 +445,7 @@ bool EmergeManager::pushBlockEmergeData( } -bool EmergeManager::popBlockEmergeData(v3BPOS pos, BlockEmergeData *bedata) +bool EmergeManager::popBlockEmergeData(v3bpos_t pos, BlockEmergeData *bedata) { auto it = m_blocks_enqueued.find(pos); if (it == m_blocks_enqueued.end()) @@ -511,7 +511,7 @@ void EmergeThread::signal() } -bool EmergeThread::pushBlock(const v3BPOS &pos) +bool EmergeThread::pushBlock(const v3bpos_t &pos) { m_block_queue.push(pos); return true; @@ -524,7 +524,7 @@ void EmergeThread::cancelPendingItems() while (!m_block_queue.empty()) { BlockEmergeData bedata; - v3BPOS pos; + v3bpos_t pos; pos = m_block_queue.front(); m_block_queue.pop(); @@ -536,7 +536,7 @@ void EmergeThread::cancelPendingItems() } -void EmergeThread::runCompletionCallbacks(const v3BPOS &pos, EmergeAction action, +void EmergeThread::runCompletionCallbacks(const v3bpos_t &pos, EmergeAction action, const EmergeCallbackList &callbacks) { for (size_t i = 0; i != callbacks.size(); i++) { @@ -551,7 +551,7 @@ void EmergeThread::runCompletionCallbacks(const v3BPOS &pos, EmergeAction action } -bool EmergeThread::popBlockEmerge(v3BPOS *pos, BlockEmergeData *bedata) +bool EmergeThread::popBlockEmerge(v3bpos_t *pos, BlockEmergeData *bedata) { MutexAutoLock queuelock(m_emerge->m_queue_mutex); @@ -568,7 +568,7 @@ bool EmergeThread::popBlockEmerge(v3BPOS *pos, BlockEmergeData *bedata) EmergeAction EmergeThread::getBlockOrStartGen( - const v3BPOS &pos, bool allow_gen, MapBlock **block, BlockMakeData *bmdata) + const v3bpos_t &pos, bool allow_gen, MapBlock **block, BlockMakeData *bmdata) { MutexAutoLock envlock(m_server->m_env_mutex); @@ -593,8 +593,8 @@ EmergeAction EmergeThread::getBlockOrStartGen( } -MapBlock *EmergeThread::finishGen(v3BPOS pos, BlockMakeData *bmdata, - std::map *modified_blocks) +MapBlock *EmergeThread::finishGen(v3bpos_t pos, BlockMakeData *bmdata, + std::map *modified_blocks) { MutexAutoLock envlock(m_server->m_env_mutex); ScopeProfiler sp(g_profiler, @@ -613,9 +613,9 @@ MapBlock *EmergeThread::finishGen(v3BPOS pos, BlockMakeData *bmdata, return NULL; } - v3POS minp = bmdata->blockpos_min * MAP_BLOCKSIZE; - v3POS maxp = bmdata->blockpos_max * MAP_BLOCKSIZE + - v3POS(1,1,1) * (MAP_BLOCKSIZE - 1); + v3pos_t minp = bmdata->blockpos_min * MAP_BLOCKSIZE; + v3pos_t maxp = bmdata->blockpos_max * MAP_BLOCKSIZE + + v3pos_t(1,1,1) * (MAP_BLOCKSIZE - 1); // Ignore map edit events, they will not need to be sent // to anybody because the block hasn't been sent to anybody @@ -655,8 +655,8 @@ void *EmergeThread::run() { BEGIN_DEBUG_EXCEPTION_HANDLER - v3BPOS pos; - std::map modified_blocks; + v3bpos_t pos; + std::map modified_blocks; m_map = &m_server->m_env->getServerMap(); m_emerge = m_server->m_emerge; diff --git a/src/emerge.h b/src/emerge.h index 0d74a954a4..0ce9c8a4b1 100644 --- a/src/emerge.h +++ b/src/emerge.h @@ -50,9 +50,9 @@ class ModApiMapgen; struct BlockMakeData { MMVManip *vmanip = nullptr; u64 seed = 0; - v3BPOS blockpos_min; - v3BPOS blockpos_max; - UniqueQueue transforming_liquid; + v3bpos_t blockpos_min; + v3bpos_t blockpos_max; + UniqueQueue transforming_liquid; const NodeDefManager *nodedef = nullptr; BlockMakeData() = default; @@ -71,7 +71,7 @@ enum EmergeAction { // Callback typedef void (*EmergeCompletionCallback)( - v3BPOS blockpos, EmergeAction action, void *param); + v3bpos_t blockpos, EmergeAction action, void *param); typedef std::vector< std::pair< @@ -163,26 +163,26 @@ class EmergeManager { bool enqueueBlockEmerge( session_t peer_id, - v3BPOS blockpos, + v3bpos_t blockpos, bool allow_generate, bool ignore_queue_limits=false); bool enqueueBlockEmergeEx( - v3BPOS blockpos, + v3bpos_t blockpos, session_t peer_id, u16 flags, EmergeCompletionCallback callback, void *callback_param); - bool isBlockInQueue(v3BPOS pos); + bool isBlockInQueue(v3bpos_t pos); Mapgen *getCurrentMapgen(); // Mapgen helpers methods - int getSpawnLevelAtPoint(v2POS p); - bool isBlockUnderground(v3BPOS blockpos); + int getSpawnLevelAtPoint(v2pos_t p); + bool isBlockUnderground(v3bpos_t blockpos); - static v3BPOS getContainingChunk(v3BPOS blockpos, s16 chunksize); + static v3bpos_t getContainingChunk(v3bpos_t blockpos, s16 chunksize); private: std::vector m_mapgens; @@ -190,7 +190,7 @@ class EmergeManager { bool m_threads_active = false; std::mutex m_queue_mutex; - std::map m_blocks_enqueued; + std::map m_blocks_enqueued; std::unordered_map m_peer_queue_count; u32 m_qlimit_total; @@ -209,14 +209,14 @@ class EmergeManager { EmergeThread *getOptimalThread(); bool pushBlockEmergeData( - v3BPOS pos, + v3bpos_t pos, u16 peer_requested, u16 flags, EmergeCompletionCallback callback, void *callback_param, bool *entry_already_exists); - bool popBlockEmergeData(v3BPOS pos, BlockEmergeData *bedata); + bool popBlockEmergeData(v3bpos_t pos, BlockEmergeData *bedata); friend class EmergeThread; }; diff --git a/src/environment.cpp b/src/environment.cpp index 4277a48136..22e0ab0379 100644 --- a/src/environment.cpp +++ b/src/environment.cpp @@ -83,7 +83,7 @@ float Environment::getTimeOfDayF() return m_time_of_day_f; } -bool Environment::line_of_sight(v3f pos1, v3f pos2, v3POS *p) +bool Environment::line_of_sight(v3f pos1, v3f pos2, v3pos_t *p) { // Iterate trough nodes on the line voxalgo::VoxelLineIterator iterator(pos1 / BS, (pos2 - pos1) / BS); @@ -125,7 +125,7 @@ void Environment::continueRaycast(RaycastState *state, PointedThing *result) } } // Set search range - core::aabbox3d maximal_exceed = nodedef->getSelectionBoxIntUnion(); + core::aabbox3d maximal_exceed = nodedef->getSelectionBoxIntUnion(); state->m_search_range.MinEdge = -maximal_exceed.MaxEdge; state->m_search_range.MaxEdge = -maximal_exceed.MinEdge; // Setting is done @@ -145,7 +145,7 @@ void Environment::continueRaycast(RaycastState *state, PointedThing *result) // first nodebox the shootline meets. v3f found_boxcenter(0, 0, 0); // The untested nodes are in this range. - core::aabbox3d new_nodes; + core::aabbox3d new_nodes; while (state->m_iterator.m_current_index <= lastIndex) { // Test the nodes around the current node in search_range. new_nodes = state->m_search_range; @@ -153,7 +153,7 @@ void Environment::continueRaycast(RaycastState *state, PointedThing *result) new_nodes.MaxEdge += state->m_iterator.m_current_node_pos; // Only check new nodes - v3POS delta = state->m_iterator.m_current_node_pos + v3pos_t delta = state->m_iterator.m_current_node_pos - state->m_previous_node; if (delta.X > 0) { new_nodes.MinEdge.X = new_nodes.MaxEdge.X; @@ -170,11 +170,11 @@ void Environment::continueRaycast(RaycastState *state, PointedThing *result) } // For each untested node - for (POS x = new_nodes.MinEdge.X; x <= new_nodes.MaxEdge.X; x++) - for (POS y = new_nodes.MinEdge.Y; y <= new_nodes.MaxEdge.Y; y++) - for (POS z = new_nodes.MinEdge.Z; z <= new_nodes.MaxEdge.Z; z++) { + for (pos_t x = new_nodes.MinEdge.X; x <= new_nodes.MaxEdge.X; x++) + for (pos_t y = new_nodes.MinEdge.Y; y <= new_nodes.MaxEdge.Y; y++) + for (pos_t z = new_nodes.MinEdge.Z; z <= new_nodes.MaxEdge.Z; z++) { MapNode n; - v3POS np(x, y, z); + v3pos_t np(x, y, z); bool is_valid_position; n = map.getNode(np, &is_valid_position); @@ -203,7 +203,7 @@ void Environment::continueRaycast(RaycastState *state, PointedThing *result) box.MaxEdge += npf; v3f intersection_point; - v3POS intersection_normal; + v3pos_t intersection_normal; if (!boxLineCollision(box, state->m_shootline.start, state->m_shootline.getVector(), &intersection_point, &intersection_normal)) { diff --git a/src/environment.h b/src/environment.h index 8f4d9bd79a..d6702e4343 100644 --- a/src/environment.h +++ b/src/environment.h @@ -84,7 +84,7 @@ class Environment * \param p output, position of the first non-air node * the line intersects */ - bool line_of_sight(v3f pos1, v3f pos2, v3POS *p = nullptr); + bool line_of_sight(v3f pos1, v3f pos2, v3pos_t *p = nullptr); /*! * Gets the objects pointed by the shootline as diff --git a/src/face_position_cache.cpp b/src/face_position_cache.cpp index dfa5be027e..c05c0621cd 100644 --- a/src/face_position_cache.cpp +++ b/src/face_position_cache.cpp @@ -21,24 +21,24 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "threading/mutex_auto_lock.h" -std::unordered_map> FacePositionCache::cache; +std::unordered_map> FacePositionCache::cache; std::mutex FacePositionCache::cache_mutex; // Calculate the borders of a "d-radius" cube -const std::vector &FacePositionCache::getFacePositions(u16 d) +const std::vector &FacePositionCache::getFacePositions(u16 d) { MutexAutoLock lock(cache_mutex); - std::unordered_map>::const_iterator it = cache.find(d); + std::unordered_map>::const_iterator it = cache.find(d); if (it != cache.end()) return it->second; return generateFacePosition(d); } -const std::vector &FacePositionCache::generateFacePosition(u16 d) +const std::vector &FacePositionCache::generateFacePosition(u16 d) { - cache[d] = std::vector(); - std::vector &c = cache[d]; + cache[d] = std::vector(); + std::vector &c = cache[d]; if (d == 0) { c.emplace_back(0,0,0); return c; diff --git a/src/face_position_cache.h b/src/face_position_cache.h index 816e566df5..7589910494 100644 --- a/src/face_position_cache.h +++ b/src/face_position_cache.h @@ -32,10 +32,10 @@ with this program; if not, write to the Free Software Foundation, Inc., */ class FacePositionCache { public: - static const std::vector &getFacePositions(u16 d); + static const std::vector &getFacePositions(u16 d); private: - static const std::vector &generateFacePosition(u16 d); - static std::unordered_map> cache; + static const std::vector &generateFacePosition(u16 d); + static std::unordered_map> cache; static std::mutex cache_mutex; }; diff --git a/src/gui/guiHyperText.cpp b/src/gui/guiHyperText.cpp index d135d0ceb8..ae30ad8d45 100644 --- a/src/gui/guiHyperText.cpp +++ b/src/gui/guiHyperText.cpp @@ -524,22 +524,22 @@ u32 ParsedText::parseTag(const wchar_t *text, u32 cursor) std::string str = attrs["angle"]; std::vector parts = split(str, ','); if (parts.size() == 3) { - m_element->angle = v3POS( + m_element->angle = v3pos_t( rangelim(stoi(parts[0]), -180, 180), rangelim(stoi(parts[1]), -180, 180), rangelim(stoi(parts[2]), -180, 180)); - m_element->rotation = v3POS(0, 0, 0); + m_element->rotation = v3pos_t(0, 0, 0); } } if (attrs.count("rotate")) { if (attrs["rotate"] == "yes") { - m_element->rotation = v3POS(0, 100, 0); + m_element->rotation = v3pos_t(0, 100, 0); } else { std::string str = attrs["rotate"]; std::vector parts = split(str, ','); if (parts.size() == 3) { - m_element->rotation = v3POS ( + m_element->rotation = v3pos_t ( rangelim(stoi(parts[0]), -1000, 1000), rangelim(stoi(parts[1]), -1000, 1000), rangelim(stoi(parts[2]), -1000, 1000)); diff --git a/src/gui/guiHyperText.h b/src/gui/guiHyperText.h index 184769a1cf..548084b31e 100644 --- a/src/gui/guiHyperText.h +++ b/src/gui/guiHyperText.h @@ -106,8 +106,8 @@ class ParsedText // img & item specific attributes std::string name; - v3POS angle{0, 0, 0}; - v3POS rotation{0, 0, 0}; + v3pos_t angle{0, 0, 0}; + v3pos_t rotation{0, 0, 0}; s32 margin = 10; diff --git a/src/inventorymanager.h b/src/inventorymanager.h index 9c9f990a5e..380b47daa0 100644 --- a/src/inventorymanager.h +++ b/src/inventorymanager.h @@ -35,7 +35,7 @@ struct InventoryLocation } type; std::string name; // PLAYER, DETACHED - v3POS p; // NODEMETA + v3pos_t p; // NODEMETA InventoryLocation() { @@ -54,7 +54,7 @@ struct InventoryLocation type = PLAYER; name = name_; } - void setNodeMeta(const v3POS &p_) + void setNodeMeta(const v3pos_t &p_) { type = NODEMETA; p = p_; diff --git a/src/irr_v2d.h b/src/irr_v2d.h index 11666bee2d..ca2399bea2 100644 --- a/src/irr_v2d.h +++ b/src/irr_v2d.h @@ -29,5 +29,5 @@ typedef core::vector2d v2s32; typedef core::vector2d v2u32; typedef core::vector2d v2f32; -using v2POS = core::vector2d; -using v2BPOS = core::vector2d; \ No newline at end of file +using v2pos_t = core::vector2d; +using v2bpos_t = core::vector2d; \ No newline at end of file diff --git a/src/irr_v3d.h b/src/irr_v3d.h index 977ace7b0c..7fe5871f9f 100644 --- a/src/irr_v3d.h +++ b/src/irr_v3d.h @@ -29,5 +29,5 @@ typedef core::vector3d v3s16; typedef core::vector3d v3u16; typedef core::vector3d v3s32; -using v3POS = core::vector3d; -using v3BPOS = core::vector3d; +using v3pos_t = core::vector3d; +using v3bpos_t = core::vector3d; diff --git a/src/irrlichttypes.h b/src/irrlichttypes.h index 47e51491ed..76e6357d6d 100644 --- a/src/irrlichttypes.h +++ b/src/irrlichttypes.h @@ -65,12 +65,13 @@ namespace core { #if USE_POS32 // Node position -using POS = irr::s32; +using pos_t = irr::s32; + +// Block position. In future can be renamed to pos_t +using bpos_t = irr::s32; -// Block position. In future can be renamed to POS -using BPOS = irr::s32; #else -using POS = irr::s16; -using BPOS = irr::s16; +using pos_t = irr::s16; +using bpos_t = irr::s16; #endif diff --git a/src/main.cpp b/src/main.cpp index e0de988d44..9ae4201419 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1003,10 +1003,10 @@ static bool migrate_map_database(const GameParams &game_params, const Settings & time_t last_update_time = 0; bool &kill = *porting::signal_handler_killstatus(); - std::vector blocks; + std::vector blocks; old_db->listAllLoadableBlocks(blocks); new_db->beginSave(); - for (std::vector::const_iterator it = blocks.begin(); it != blocks.end(); ++it) { + for (std::vector::const_iterator it = blocks.begin(); it != blocks.end(); ++it) { if (kill) return false; std::string data; @@ -1058,7 +1058,7 @@ static bool recompress_map_database(const GameParams &game_params, const Setting const u8 serialize_as_ver = SER_FMT_VER_HIGHEST_WRITE; // This is ok because the server doesn't actually run - std::vector blocks; + std::vector blocks; db->listAllLoadableBlocks(blocks); db->beginSave(); std::istringstream iss(std::ios_base::binary); @@ -1076,7 +1076,7 @@ static bool recompress_map_database(const GameParams &game_params, const Setting iss.str(data); iss.clear(); - MapBlock mb(nullptr, v3POS(0,0,0), &server); + MapBlock mb(nullptr, v3pos_t(0,0,0), &server); u8 ver = readU8(iss); mb.deSerialize(iss, ver, true); diff --git a/src/map.cpp b/src/map.cpp index 4f49293a78..87751cb297 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -97,14 +97,14 @@ void Map::dispatchEvent(const MapEditEvent &event) } } -MapSector * Map::getSectorNoGenerateNoLock(v2BPOS p) +MapSector * Map::getSectorNoGenerateNoLock(v2bpos_t p) { if(m_sector_cache != NULL && p == m_sector_cache_p){ MapSector * sector = m_sector_cache; return sector; } - std::map::iterator n = m_sectors.find(p); + std::map::iterator n = m_sectors.find(p); if (n == m_sectors.end()) return NULL; @@ -118,14 +118,14 @@ MapSector * Map::getSectorNoGenerateNoLock(v2BPOS p) return sector; } -MapSector * Map::getSectorNoGenerate(v2BPOS p) +MapSector * Map::getSectorNoGenerate(v2bpos_t p) { return getSectorNoGenerateNoLock(p); } -MapBlock * Map::getBlockNoCreateNoEx(v3BPOS p3d) +MapBlock * Map::getBlockNoCreateNoEx(v3bpos_t p3d) { - v2BPOS p2d(p3d.X, p3d.Z); + v2bpos_t p2d(p3d.X, p3d.Z); MapSector * sector = getSectorNoGenerate(p2d); if(sector == NULL) return NULL; @@ -133,7 +133,7 @@ MapBlock * Map::getBlockNoCreateNoEx(v3BPOS p3d) return block; } -MapBlock * Map::getBlockNoCreate(v3BPOS p3d) +MapBlock * Map::getBlockNoCreate(v3bpos_t p3d) { MapBlock *block = getBlockNoCreateNoEx(p3d); if(block == NULL) @@ -141,17 +141,17 @@ MapBlock * Map::getBlockNoCreate(v3BPOS p3d) return block; } -bool Map::isValidPosition(v3POS p) +bool Map::isValidPosition(v3pos_t p) { - v3BPOS blockpos = getNodeBlockPos(p); + v3bpos_t blockpos = getNodeBlockPos(p); MapBlock *block = getBlockNoCreateNoEx(blockpos); return (block != NULL); } // Returns a CONTENT_IGNORE node if not found -MapNode Map::getNode(v3POS p, bool *is_valid_position) +MapNode Map::getNode(v3pos_t p, bool *is_valid_position) { - v3BPOS blockpos = getNodeBlockPos(p); + v3bpos_t blockpos = getNodeBlockPos(p); MapBlock *block = getBlockNoCreateNoEx(blockpos); if (block == NULL) { if (is_valid_position != NULL) @@ -159,7 +159,7 @@ MapNode Map::getNode(v3POS p, bool *is_valid_position) return {CONTENT_IGNORE}; } - v3POS relpos = p - blockpos*MAP_BLOCKSIZE; + v3pos_t relpos = p - blockpos*MAP_BLOCKSIZE; bool is_valid_p; MapNode node = block->getNodeNoCheck(relpos, &is_valid_p); if (is_valid_position != NULL) @@ -168,11 +168,11 @@ MapNode Map::getNode(v3POS p, bool *is_valid_position) } // throws InvalidPositionException if not found -void Map::setNode(v3POS p, MapNode & n) +void Map::setNode(v3pos_t p, MapNode & n) { - v3BPOS blockpos = getNodeBlockPos(p); + v3bpos_t blockpos = getNodeBlockPos(p); MapBlock *block = getBlockNoCreate(blockpos); - v3POS relpos = p - blockpos*MAP_BLOCKSIZE; + v3pos_t relpos = p - blockpos*MAP_BLOCKSIZE; // Never allow placing CONTENT_IGNORE, it causes problems if(n.getContent() == CONTENT_IGNORE){ bool temp_bool; @@ -185,8 +185,8 @@ void Map::setNode(v3POS p, MapNode & n) block->setNodeNoCheck(relpos, n); } -void Map::addNodeAndUpdate(v3POS p, MapNode n, - std::map &modified_blocks, +void Map::addNodeAndUpdate(v3pos_t p, MapNode n, + std::map &modified_blocks, bool remove_metadata) { // Collect old node for rollback @@ -207,7 +207,7 @@ void Map::addNodeAndUpdate(v3POS p, MapNode n, setNode(p, n); // Update lighting - std::vector > oldnodes; + std::vector > oldnodes; oldnodes.emplace_back(p, oldnode); voxalgo::update_lighting_nodes(this, oldnodes, modified_blocks); @@ -229,8 +229,8 @@ void Map::addNodeAndUpdate(v3POS p, MapNode n, (it's vital for the node itself to get updated last, if it was removed.) */ - for (const v3POS &dir : g_7dirs) { - v3POS p2 = p + dir; + for (const v3pos_t &dir : g_7dirs) { + v3pos_t p2 = p + dir; bool is_valid_position; MapNode n2 = getNode(p2, &is_valid_position); @@ -241,13 +241,13 @@ void Map::addNodeAndUpdate(v3POS p, MapNode n, } } -void Map::removeNodeAndUpdate(v3POS p, - std::map &modified_blocks) +void Map::removeNodeAndUpdate(v3pos_t p, + std::map &modified_blocks) { addNodeAndUpdate(p, MapNode(CONTENT_AIR), modified_blocks, true); } -bool Map::addNodeWithEvent(v3POS p, MapNode n, bool remove_metadata) +bool Map::addNodeWithEvent(v3pos_t p, MapNode n, bool remove_metadata) { MapEditEvent event; event.type = remove_metadata ? MEET_ADDNODE : MEET_SWAPNODE; @@ -256,7 +256,7 @@ bool Map::addNodeWithEvent(v3POS p, MapNode n, bool remove_metadata) bool succeeded = true; try{ - std::map modified_blocks; + std::map modified_blocks; addNodeAndUpdate(p, n, modified_blocks, remove_metadata); // Copy modified_blocks to event @@ -273,7 +273,7 @@ bool Map::addNodeWithEvent(v3POS p, MapNode n, bool remove_metadata) return succeeded; } -bool Map::removeNodeWithEvent(v3POS p) +bool Map::removeNodeWithEvent(v3pos_t p) { MapEditEvent event; event.type = MEET_REMOVENODE; @@ -281,7 +281,7 @@ bool Map::removeNodeWithEvent(v3POS p) bool succeeded = true; try{ - std::map modified_blocks; + std::map modified_blocks; removeNodeAndUpdate(p, modified_blocks); // Copy modified_blocks to event @@ -317,14 +317,14 @@ struct TimeOrderedMapBlock { Updates usage timers */ void Map::timerUpdate(float dtime, float unload_timeout, u32 max_loaded_blocks, - std::vector *unloaded_blocks) + std::vector *unloaded_blocks) { bool save_before_unloading = (mapType() == MAPTYPE_SERVER); // Profile modified reasons Profiler modprofiler; - std::vector sector_deletion_queue; + std::vector sector_deletion_queue; u32 deleted_blocks_count = 0; u32 saved_blocks_count = 0; u32 block_count_all = 0; @@ -346,7 +346,7 @@ void Map::timerUpdate(float dtime, float unload_timeout, u32 max_loaded_blocks, if (block->refGet() == 0 && block->getUsageTimer() > unload_timeout) { - v3BPOS p = block->getPos(); + v3bpos_t p = block->getPos(); // Save if modified if (block->getModified() != MOD_STATE_CLEAN @@ -399,7 +399,7 @@ void Map::timerUpdate(float dtime, float unload_timeout, u32 max_loaded_blocks, if (block->refGet() != 0) continue; - v3BPOS p = block->getPos(); + v3bpos_t p = block->getPos(); // Save if modified if (block->getModified() != MOD_STATE_CLEAN && save_before_unloading) { @@ -447,14 +447,14 @@ void Map::timerUpdate(float dtime, float unload_timeout, u32 max_loaded_blocks, } } -void Map::unloadUnreferencedBlocks(std::vector *unloaded_blocks) +void Map::unloadUnreferencedBlocks(std::vector *unloaded_blocks) { timerUpdate(0.0, -1.0, 0, unloaded_blocks); } -void Map::deleteSectors(std::vector §orList) +void Map::deleteSectors(std::vector §orList) { - for (v2BPOS j : sectorList) { + for (v2bpos_t j : sectorList) { MapSector *sector = m_sectors[j]; // If sector is in sector cache, remove it from there if(m_sector_cache == sector) @@ -472,14 +472,14 @@ void Map::PrintInfo(std::ostream &out) #define WATER_DROP_BOOST 4 -const static v3POS liquid_6dirs[6] = { +const static v3pos_t liquid_6dirs[6] = { // order: upper before same level before lower - v3POS( 0, 1, 0), - v3POS( 0, 0, 1), - v3POS( 1, 0, 0), - v3POS( 0, 0,-1), - v3POS(-1, 0, 0), - v3POS( 0,-1, 0) + v3pos_t( 0, 1, 0), + v3pos_t( 0, 0, 1), + v3pos_t( 1, 0, 0), + v3pos_t( 0, 0,-1), + v3pos_t(-1, 0, 0), + v3pos_t( 0,-1, 0) }; enum NeighborType : u8 { @@ -491,24 +491,24 @@ enum NeighborType : u8 { struct NodeNeighbor { MapNode n; NeighborType t; - v3POS p; + v3pos_t p; NodeNeighbor() : n(CONTENT_AIR), t(NEIGHBOR_SAME_LEVEL) { } - NodeNeighbor(const MapNode &node, NeighborType n_type, const v3POS &pos) + NodeNeighbor(const MapNode &node, NeighborType n_type, const v3pos_t &pos) : n(node), t(n_type), p(pos) { } }; -void Map::transforming_liquid_add(v3POS p) { +void Map::transforming_liquid_add(v3pos_t p) { m_transforming_liquid.push_back(p); } -void Map::transformLiquids(std::map &modified_blocks, +void Map::transformLiquids(std::map &modified_blocks, ServerEnvironment *env) { u32 loopcount = 0; @@ -518,9 +518,9 @@ void Map::transformLiquids(std::map &modified_blocks, infostream<<"transformLiquids(): initial_size="< must_reflow; + std::deque must_reflow; - std::vector > changed_nodes; + std::vector > changed_nodes; u32 liquid_loop_max = g_settings->getS32("liquid_loop_max"); u32 loop_max = liquid_loop_max; @@ -535,7 +535,7 @@ void Map::transformLiquids(std::map &modified_blocks, /* Get a queued transforming liquid node */ - v3POS p0 = m_transforming_liquid.front(); + v3pos_t p0 = m_transforming_liquid.front(); m_transforming_liquid.pop_front(); MapNode n0 = getNode(p0); @@ -596,7 +596,7 @@ void Map::transformLiquids(std::map &modified_blocks, default: break; } - v3POS npos = p0 + liquid_6dirs[i]; + v3pos_t npos = p0 + liquid_6dirs[i]; NodeNeighbor nb(getNode(npos), nt, npos); const ContentFeatures &cfnb = m_nodedef->get(nb.n); switch (m_nodedef->get(nb.n.getContent()).liquid_type) { @@ -790,7 +790,7 @@ void Map::transformLiquids(std::map &modified_blocks, setNode(p0, n0); } - v3BPOS blockpos = getNodeBlockPos(p0); + v3bpos_t blockpos = getNodeBlockPos(p0); MapBlock *block = getBlockNoCreateNoEx(blockpos); if (block != NULL) { modified_blocks[blockpos] = block; @@ -875,20 +875,20 @@ void Map::transformLiquids(std::map &modified_blocks, } } -std::vector Map::findNodesWithMetadata(v3POS p1, v3POS p2) +std::vector Map::findNodesWithMetadata(v3pos_t p1, v3pos_t p2) { - std::vector positions_with_meta; + std::vector positions_with_meta; sortBoxVerticies(p1, p2); - v3BPOS bpmin = getNodeBlockPos(p1); - v3BPOS bpmax = getNodeBlockPos(p2); + v3bpos_t bpmin = getNodeBlockPos(p1); + v3bpos_t bpmax = getNodeBlockPos(p2); VoxelArea area(p1, p2); - for (BPOS z = bpmin.Z; z <= bpmax.Z; z++) - for (BPOS y = bpmin.Y; y <= bpmax.Y; y++) - for (BPOS x = bpmin.X; x <= bpmax.X; x++) { - v3BPOS blockpos(x, y, z); + for (bpos_t z = bpmin.Z; z <= bpmax.Z; z++) + for (bpos_t y = bpmin.Y; y <= bpmax.Y; y++) + for (bpos_t x = bpmin.X; x <= bpmax.X; x++) { + v3bpos_t blockpos(x, y, z); MapBlock *block = getBlockNoCreateNoEx(blockpos); if (!block) { @@ -902,10 +902,10 @@ std::vector Map::findNodesWithMetadata(v3POS p1, v3POS p2) continue; } - v3POS p_base = blockpos * MAP_BLOCKSIZE; - std::vector keys = block->m_node_metadata.getAllKeys(); + v3pos_t p_base = blockpos * MAP_BLOCKSIZE; + std::vector keys = block->m_node_metadata.getAllKeys(); for (size_t i = 0; i != keys.size(); i++) { - v3POS p(keys[i] + p_base); + v3pos_t p(keys[i] + p_base); if (!area.contains(p)) continue; @@ -916,10 +916,10 @@ std::vector Map::findNodesWithMetadata(v3POS p1, v3POS p2) return positions_with_meta; } -NodeMetadata *Map::getNodeMetadata(v3POS p) +NodeMetadata *Map::getNodeMetadata(v3pos_t p) { - v3BPOS blockpos = getNodeBlockPos(p); - v3POS p_rel = p - blockpos*MAP_BLOCKSIZE; + v3bpos_t blockpos = getNodeBlockPos(p); + v3pos_t p_rel = p - blockpos*MAP_BLOCKSIZE; MapBlock *block = getBlockNoCreateNoEx(blockpos); if(!block){ infostream<<"Map::getNodeMetadata(): Need to emerge " @@ -935,10 +935,10 @@ NodeMetadata *Map::getNodeMetadata(v3POS p) return meta; } -bool Map::setNodeMetadata(v3POS p, NodeMetadata *meta) +bool Map::setNodeMetadata(v3pos_t p, NodeMetadata *meta) { - v3BPOS blockpos = getNodeBlockPos(p); - v3POS p_rel = p - blockpos*MAP_BLOCKSIZE; + v3bpos_t blockpos = getNodeBlockPos(p); + v3pos_t p_rel = p - blockpos*MAP_BLOCKSIZE; MapBlock *block = getBlockNoCreateNoEx(blockpos); if(!block){ infostream<<"Map::setNodeMetadata(): Need to emerge " @@ -954,10 +954,10 @@ bool Map::setNodeMetadata(v3POS p, NodeMetadata *meta) return true; } -void Map::removeNodeMetadata(v3POS p) +void Map::removeNodeMetadata(v3pos_t p) { - v3BPOS blockpos = getNodeBlockPos(p); - v3POS p_rel = p - blockpos*MAP_BLOCKSIZE; + v3bpos_t blockpos = getNodeBlockPos(p); + v3pos_t p_rel = p - blockpos*MAP_BLOCKSIZE; MapBlock *block = getBlockNoCreateNoEx(blockpos); if(block == NULL) { @@ -968,10 +968,10 @@ void Map::removeNodeMetadata(v3POS p) block->m_node_metadata.remove(p_rel); } -NodeTimer Map::getNodeTimer(v3POS p) +NodeTimer Map::getNodeTimer(v3pos_t p) { - v3BPOS blockpos = getNodeBlockPos(p); - v3POS p_rel = p - blockpos*MAP_BLOCKSIZE; + v3bpos_t blockpos = getNodeBlockPos(p); + v3pos_t p_rel = p - blockpos*MAP_BLOCKSIZE; MapBlock *block = getBlockNoCreateNoEx(blockpos); if(!block){ infostream<<"Map::getNodeTimer(): Need to emerge " @@ -990,9 +990,9 @@ NodeTimer Map::getNodeTimer(v3POS p) void Map::setNodeTimer(const NodeTimer &t) { - v3POS p = t.position; - v3BPOS blockpos = getNodeBlockPos(p); - v3POS p_rel = p - blockpos*MAP_BLOCKSIZE; + v3pos_t p = t.position; + v3bpos_t blockpos = getNodeBlockPos(p); + v3pos_t p_rel = p - blockpos*MAP_BLOCKSIZE; MapBlock *block = getBlockNoCreateNoEx(blockpos); if(!block){ infostream<<"Map::setNodeTimer(): Need to emerge " @@ -1008,10 +1008,10 @@ void Map::setNodeTimer(const NodeTimer &t) block->m_node_timers.set(nt); } -void Map::removeNodeTimer(v3POS p) +void Map::removeNodeTimer(v3pos_t p) { - v3BPOS blockpos = getNodeBlockPos(p); - v3POS p_rel = p - blockpos*MAP_BLOCKSIZE; + v3bpos_t blockpos = getNodeBlockPos(p); + v3pos_t p_rel = p - blockpos*MAP_BLOCKSIZE; MapBlock *block = getBlockNoCreateNoEx(blockpos); if(block == NULL) { @@ -1022,8 +1022,8 @@ void Map::removeNodeTimer(v3POS p) block->m_node_timers.remove(p_rel); } -bool Map::determineAdditionalOcclusionCheck(const v3POS &pos_camera, - const core::aabbox3d &block_bounds, v3POS &check) +bool Map::determineAdditionalOcclusionCheck(const v3pos_t &pos_camera, + const core::aabbox3d &block_bounds, v3pos_t &check) { /* This functions determines the node inside the target block that is @@ -1051,32 +1051,32 @@ bool Map::determineAdditionalOcclusionCheck(const v3POS &pos_camera, // straight if (x_inside && y_inside) { - check = v3POS(pos_camera.X, pos_camera.Y, 0); + check = v3pos_t(pos_camera.X, pos_camera.Y, 0); check.Z = CLOSEST_EDGE(pos_camera, block_bounds, Z); return true; } else if (y_inside && z_inside) { - check = v3POS(0, pos_camera.Y, pos_camera.Z); + check = v3pos_t(0, pos_camera.Y, pos_camera.Z); check.X = CLOSEST_EDGE(pos_camera, block_bounds, X); return true; } else if (x_inside && z_inside) { - check = v3POS(pos_camera.X, 0, pos_camera.Z); + check = v3pos_t(pos_camera.X, 0, pos_camera.Z); check.Y = CLOSEST_EDGE(pos_camera, block_bounds, Y); return true; } // diagonal if (x_inside) { - check = v3POS(pos_camera.X, 0, 0); + check = v3pos_t(pos_camera.X, 0, 0); check.Y = CLOSEST_EDGE(pos_camera, block_bounds, Y); check.Z = CLOSEST_EDGE(pos_camera, block_bounds, Z); return true; } else if (y_inside) { - check = v3POS(0, pos_camera.Y, 0); + check = v3pos_t(0, pos_camera.Y, 0); check.X = CLOSEST_EDGE(pos_camera, block_bounds, X); check.Z = CLOSEST_EDGE(pos_camera, block_bounds, Z); return true; } else if (z_inside) { - check = v3POS(0, 0, pos_camera.Z); + check = v3pos_t(0, 0, pos_camera.Z); check.X = CLOSEST_EDGE(pos_camera, block_bounds, X); check.Y = CLOSEST_EDGE(pos_camera, block_bounds, Y); return true; @@ -1086,7 +1086,7 @@ bool Map::determineAdditionalOcclusionCheck(const v3POS &pos_camera, return false; } -bool Map::isOccluded(const v3POS &pos_camera, const v3POS &pos_target, +bool Map::isOccluded(const v3pos_t &pos_camera, const v3pos_t &pos_target, float step, float stepfac, float offset, float end_offset, u32 needed_count) { v3f direction = intToFloat(pos_target - pos_camera, BS); @@ -1102,7 +1102,7 @@ bool Map::isOccluded(const v3POS &pos_camera, const v3POS &pos_target, for (; offset < distance + end_offset; offset += step) { v3f pos_node_f = pos_origin_f + direction * offset; - v3POS pos_node = floatToInt(pos_node_f, BS); + v3pos_t pos_node = floatToInt(pos_node_f, BS); MapNode node = getNode(pos_node, &is_valid_position); @@ -1118,24 +1118,24 @@ bool Map::isOccluded(const v3POS &pos_camera, const v3POS &pos_target, return false; } -bool Map::isBlockOccluded(MapBlock *block, v3POS cam_pos_nodes) +bool Map::isBlockOccluded(MapBlock *block, v3pos_t cam_pos_nodes) { // Check occlusion for center and all 8 corners of the mapblock // Overshoot a little for less flickering static const s16 bs2 = MAP_BLOCKSIZE / 2 + 1; - static const v3POS dir9[9] = { - v3POS( 0, 0, 0), - v3POS( 1, 1, 1) * bs2, - v3POS( 1, 1, -1) * bs2, - v3POS( 1, -1, 1) * bs2, - v3POS( 1, -1, -1) * bs2, - v3POS(-1, 1, 1) * bs2, - v3POS(-1, 1, -1) * bs2, - v3POS(-1, -1, 1) * bs2, - v3POS(-1, -1, -1) * bs2, + static const v3pos_t dir9[9] = { + v3pos_t( 0, 0, 0), + v3pos_t( 1, 1, 1) * bs2, + v3pos_t( 1, 1, -1) * bs2, + v3pos_t( 1, -1, 1) * bs2, + v3pos_t( 1, -1, -1) * bs2, + v3pos_t(-1, 1, 1) * bs2, + v3pos_t(-1, 1, -1) * bs2, + v3pos_t(-1, -1, 1) * bs2, + v3pos_t(-1, -1, -1) * bs2, }; - v3POS pos_blockcenter = block->getPosRelative() + (MAP_BLOCKSIZE / 2); + v3pos_t pos_blockcenter = block->getPosRelative() + (MAP_BLOCKSIZE / 2); // Starting step size, value between 1m and sqrt(3)m float step = BS * 1.2f; @@ -1157,7 +1157,7 @@ bool Map::isBlockOccluded(MapBlock *block, v3POS cam_pos_nodes) u32 needed_count = 2; // Additional occlusion check, see comments in that function - v3POS check; + v3pos_t check; if (determineAdditionalOcclusionCheck(cam_pos_nodes, block->getBox(), check)) { // node is always on a side facing the camera, end_offset can be lower if (!isOccluded(cam_pos_nodes, check, step, stepfac, start_offset, @@ -1165,7 +1165,7 @@ bool Map::isBlockOccluded(MapBlock *block, v3POS cam_pos_nodes) return false; } - for (const v3POS &dir : dir9) { + for (const v3pos_t &dir : dir9) { if (!isOccluded(cam_pos_nodes, pos_blockcenter + dir, step, stepfac, start_offset, end_offset, needed_count)) return false; @@ -1294,9 +1294,9 @@ u64 ServerMap::getSeed() return getMapgenParams()->seed; } -bool ServerMap::blockpos_over_mapgen_limit(v3BPOS p) +bool ServerMap::blockpos_over_mapgen_limit(v3bpos_t p) { - const BPOS mapgen_limit_bp = rangelim( + const bpos_t mapgen_limit_bp = rangelim( getMapgenParams()->mapgen_limit, 0, MAX_MAP_GENERATION_LIMIT) / MAP_BLOCKSIZE; return p.X < -mapgen_limit_bp || @@ -1307,11 +1307,11 @@ bool ServerMap::blockpos_over_mapgen_limit(v3BPOS p) p.Z > mapgen_limit_bp; } -bool ServerMap::initBlockMake(v3BPOS blockpos, BlockMakeData *data) +bool ServerMap::initBlockMake(v3bpos_t blockpos, BlockMakeData *data) { s16 csize = getMapgenParams()->chunksize; - v3BPOS bpmin = EmergeManager::getContainingChunk(blockpos, csize); - v3BPOS bpmax = bpmin + v3BPOS(1, 1, 1) * (csize - 1); + v3bpos_t bpmin = EmergeManager::getContainingChunk(blockpos, csize); + v3bpos_t bpmax = bpmin + v3bpos_t(1, 1, 1) * (csize - 1); if (!m_chunks_in_progress.insert(bpmin).second) return false; @@ -1319,9 +1319,9 @@ bool ServerMap::initBlockMake(v3BPOS blockpos, BlockMakeData *data) bool enable_mapgen_debug_info = m_emerge->enable_mapgen_debug_info; EMERGE_DBG_OUT("initBlockMake(): " PP(bpmin) " - " PP(bpmax)); - v3BPOS extra_borders(1, 1, 1); - v3BPOS full_bpmin = bpmin - extra_borders; - v3BPOS full_bpmax = bpmax + extra_borders; + v3bpos_t extra_borders(1, 1, 1); + v3bpos_t full_bpmin = bpmin - extra_borders; + v3bpos_t full_bpmax = bpmax + extra_borders; // Do nothing if not inside mapgen limits (+-1 because of neighbors) if (blockpos_over_mapgen_limit(full_bpmin) || @@ -1336,15 +1336,15 @@ bool ServerMap::initBlockMake(v3BPOS blockpos, BlockMakeData *data) /* Create the whole area of this and the neighboring blocks */ - for (BPOS x = full_bpmin.X; x <= full_bpmax.X; x++) - for (BPOS z = full_bpmin.Z; z <= full_bpmax.Z; z++) { - v2BPOS sectorpos(x, z); + for (bpos_t x = full_bpmin.X; x <= full_bpmax.X; x++) + for (bpos_t z = full_bpmin.Z; z <= full_bpmax.Z; z++) { + v2bpos_t sectorpos(x, z); // Sector metadata is loaded from disk if not already loaded. MapSector *sector = createSector(sectorpos); FATAL_ERROR_IF(sector == NULL, "createSector() failed"); - for (BPOS y = full_bpmin.Y; y <= full_bpmax.Y; y++) { - v3BPOS p(x, y, z); + for (bpos_t y = full_bpmin.Y; y <= full_bpmax.Y; y++) { + v3bpos_t p(x, y, z); MapBlock *block = emergeBlock(p, false); if (block == NULL) { @@ -1373,10 +1373,10 @@ bool ServerMap::initBlockMake(v3BPOS blockpos, BlockMakeData *data) } void ServerMap::finishBlockMake(BlockMakeData *data, - std::map *changed_blocks) + std::map *changed_blocks) { - v3BPOS bpmin = data->blockpos_min; - v3BPOS bpmax = data->blockpos_max; + v3bpos_t bpmin = data->blockpos_min; + v3bpos_t bpmax = data->blockpos_max; bool enable_mapgen_debug_info = m_emerge->enable_mapgen_debug_info; EMERGE_DBG_OUT("finishBlockMake(): " PP(bpmin) " - " PP(bpmax)); @@ -1416,10 +1416,10 @@ void ServerMap::finishBlockMake(BlockMakeData *data, /* Set central blocks as generated */ - for (BPOS x = bpmin.X; x <= bpmax.X; x++) - for (BPOS z = bpmin.Z; z <= bpmax.Z; z++) - for (BPOS y = bpmin.Y; y <= bpmax.Y; y++) { - MapBlock *block = getBlockNoCreateNoEx(v3BPOS(x, y, z)); + for (bpos_t x = bpmin.X; x <= bpmax.X; x++) + for (bpos_t z = bpmin.Z; z <= bpmax.Z; z++) + for (bpos_t y = bpmin.Y; y <= bpmax.Y; y++) { + MapBlock *block = getBlockNoCreateNoEx(v3bpos_t(x, y, z)); if (!block) continue; @@ -1434,7 +1434,7 @@ void ServerMap::finishBlockMake(BlockMakeData *data, m_chunks_in_progress.erase(bpmin); } -MapSector *ServerMap::createSector(v2BPOS p2d) +MapSector *ServerMap::createSector(v2bpos_t p2d) { /* Check if it exists already in memory @@ -1446,7 +1446,7 @@ MapSector *ServerMap::createSector(v2BPOS p2d) /* Do not create over max mapgen limit */ - const BPOS max_limit_bp = MAX_MAP_GENERATION_LIMIT / MAP_BLOCKSIZE; + const bpos_t max_limit_bp = MAX_MAP_GENERATION_LIMIT / MAP_BLOCKSIZE; if (p2d.X < -max_limit_bp || p2d.X > max_limit_bp || p2d.Y < -max_limit_bp || @@ -1460,7 +1460,7 @@ MapSector *ServerMap::createSector(v2BPOS p2d) sector = new MapSector(this, p2d, m_gamedef); // Sector position on map in nodes - //v2POS nodepos2d = p2d * MAP_BLOCKSIZE; + //v2pos_t nodepos2d = p2d * MAP_BLOCKSIZE; /* Insert to container @@ -1470,7 +1470,7 @@ MapSector *ServerMap::createSector(v2BPOS p2d) return sector; } -MapBlock * ServerMap::createBlock(v3BPOS p) +MapBlock * ServerMap::createBlock(v3bpos_t p) { /* Do not create over max mapgen limit @@ -1478,8 +1478,8 @@ MapBlock * ServerMap::createBlock(v3BPOS p) if (blockpos_over_max_limit(p)) throw InvalidPositionException("createBlock(): pos. over max mapgen limit"); - v2BPOS p2d(p.X, p.Z); - BPOS block_y = p.Y; + v2bpos_t p2d(p.X, p.Z); + bpos_t block_y = p.Y; /* This will create or load a sector if not found in memory. If block exists on disk, it will be loaded. @@ -1511,7 +1511,7 @@ MapBlock * ServerMap::createBlock(v3BPOS p) return block; } -MapBlock * ServerMap::emergeBlock(v3BPOS p, bool create_blank) +MapBlock * ServerMap::emergeBlock(v3bpos_t p, bool create_blank) { { MapBlock *block = getBlockNoCreateNoEx(p); @@ -1526,7 +1526,7 @@ MapBlock * ServerMap::emergeBlock(v3BPOS p, bool create_blank) } if (create_blank) { - MapSector *sector = createSector(v2BPOS(p.X, p.Z)); + MapSector *sector = createSector(v2bpos_t(p.X, p.Z)); MapBlock *block = sector->createBlankBlock(p.Y); return block; @@ -1535,7 +1535,7 @@ MapBlock * ServerMap::emergeBlock(v3BPOS p, bool create_blank) return NULL; } -MapBlock *ServerMap::getBlockOrEmerge(v3BPOS p3d) +MapBlock *ServerMap::getBlockOrEmerge(v3bpos_t p3d) { MapBlock *block = getBlockNoCreateNoEx(p3d); if (block == NULL) @@ -1544,14 +1544,14 @@ MapBlock *ServerMap::getBlockOrEmerge(v3BPOS p3d) return block; } -bool ServerMap::isBlockInQueue(v3BPOS pos) +bool ServerMap::isBlockInQueue(v3bpos_t pos) { return m_emerge && m_emerge->isBlockInQueue(pos); } // N.B. This requires no synchronization, since data will not be modified unless // the VoxelManipulator being updated belongs to the same thread. -void ServerMap::updateVManip(v3POS pos) +void ServerMap::updateVManip(v3pos_t pos) { Mapgen *mg = m_emerge->getCurrentMapgen(); if (!mg) @@ -1643,14 +1643,14 @@ void ServerMap::save(ModifiedState save_level) m_save_time_counter->increment(end_time - start_time); } -void ServerMap::listAllLoadableBlocks(std::vector &dst) +void ServerMap::listAllLoadableBlocks(std::vector &dst) { dbase->listAllLoadableBlocks(dst); if (dbase_ro) dbase_ro->listAllLoadableBlocks(dst); } -void ServerMap::listAllLoadedBlocks(std::vector &dst) +void ServerMap::listAllLoadedBlocks(std::vector &dst) { for (auto §or_it : m_sectors) { MapSector *sector = sector_it.second; @@ -1659,7 +1659,7 @@ void ServerMap::listAllLoadedBlocks(std::vector &dst) sector->getBlocks(blocks); for (MapBlock *block : blocks) { - v3BPOS p = block->getPos(); + v3bpos_t p = block->getPos(); dst.push_back(p); } } @@ -1710,7 +1710,7 @@ bool ServerMap::saveBlock(MapBlock *block) bool ServerMap::saveBlock(MapBlock *block, MapDatabase *db, int compression_level) { - v3BPOS p3d = block->getPos(); + v3bpos_t p3d = block->getPos(); // Dummy blocks are not written if (block->isDummy()) { @@ -1738,7 +1738,7 @@ bool ServerMap::saveBlock(MapBlock *block, MapDatabase *db, int compression_leve return ret; } -void ServerMap::loadBlock(std::string *blob, v3BPOS p3d, MapSector *sector, bool save_after_load) +void ServerMap::loadBlock(std::string *blob, v3bpos_t p3d, MapSector *sector, bool save_after_load) { try { std::istringstream is(*blob, std::ios_base::binary); @@ -1799,11 +1799,11 @@ void ServerMap::loadBlock(std::string *blob, v3BPOS p3d, MapSector *sector, bool } } -MapBlock* ServerMap::loadBlock(v3BPOS blockpos) +MapBlock* ServerMap::loadBlock(v3bpos_t blockpos) { bool created_new = (getBlockNoCreateNoEx(blockpos) == NULL); - v2BPOS p2d(blockpos.X, blockpos.Z); + v2bpos_t p2d(blockpos.X, blockpos.Z); std::string ret; dbase->loadBlock(blockpos, &ret); @@ -1820,14 +1820,14 @@ MapBlock* ServerMap::loadBlock(v3BPOS blockpos) MapBlock *block = getBlockNoCreateNoEx(blockpos); if (created_new && (block != NULL)) { - std::map modified_blocks; + std::map modified_blocks; // Fix lighting if necessary voxalgo::update_block_border_lighting(this, block, modified_blocks); if (!modified_blocks.empty()) { //Modified lighting, send event MapEditEvent event; event.type = MEET_OTHER; - std::map::iterator it; + std::map::iterator it; for (it = modified_blocks.begin(); it != modified_blocks.end(); ++it) event.modified_blocks.insert(it->first); @@ -1837,14 +1837,14 @@ MapBlock* ServerMap::loadBlock(v3BPOS blockpos) return block; } -bool ServerMap::deleteBlock(v3BPOS blockpos) +bool ServerMap::deleteBlock(v3bpos_t blockpos) { if (!dbase->deleteBlock(blockpos)) return false; MapBlock *block = getBlockNoCreateNoEx(blockpos); if (block) { - v2BPOS p2d(blockpos.X, blockpos.Z); + v2bpos_t p2d(blockpos.X, blockpos.Z); MapSector *sector = getSectorNoGenerate(p2d); if (!sector) return false; @@ -1859,8 +1859,8 @@ void ServerMap::PrintInfo(std::ostream &out) out<<"ServerMap: "; } -bool ServerMap::repairBlockLight(v3BPOS blockpos, - std::map *modified_blocks) +bool ServerMap::repairBlockLight(v3bpos_t blockpos, + std::map *modified_blocks) { MapBlock *block = emergeBlock(blockpos, false); if (!block || !block->isGenerated()) @@ -1875,17 +1875,17 @@ MMVManip::MMVManip(Map *map): { } -void MMVManip::initialEmerge(v3BPOS blockpos_min, v3BPOS blockpos_max, +void MMVManip::initialEmerge(v3bpos_t blockpos_min, v3bpos_t blockpos_max, bool load_if_inexistent) { TimeTaker timer1("initialEmerge", &emerge_time); // Units of these are MapBlocks - v3BPOS p_min = blockpos_min; - v3BPOS p_max = blockpos_max; + v3bpos_t p_min = blockpos_min; + v3bpos_t p_max = blockpos_max; VoxelArea block_area_nodes - (p_min*MAP_BLOCKSIZE, (p_max+1)*MAP_BLOCKSIZE-v3POS(1,1,1)); + (p_min*MAP_BLOCKSIZE, (p_max+1)*MAP_BLOCKSIZE-v3pos_t(1,1,1)); u32 size_MB = block_area_nodes.getVolume()*4/1000000; if(size_MB >= 1) @@ -1904,8 +1904,8 @@ void MMVManip::initialEmerge(v3BPOS blockpos_min, v3BPOS blockpos_max, { u8 flags = 0; MapBlock *block; - v3BPOS p(x,y,z); - std::map::iterator n; + v3bpos_t p(x,y,z); + std::map::iterator n; n = m_loaded_blocks.find(p); if(n != m_loaded_blocks.end()) continue; @@ -1936,7 +1936,7 @@ void MMVManip::initialEmerge(v3BPOS blockpos_min, v3BPOS blockpos_max, /* Mark area inexistent */ - VoxelArea a(p*MAP_BLOCKSIZE, (p+1)*MAP_BLOCKSIZE-v3POS(1,1,1)); + VoxelArea a(p*MAP_BLOCKSIZE, (p+1)*MAP_BLOCKSIZE-v3pos_t(1,1,1)); // Fill with VOXELFLAG_NO_DATA for(s32 z=a.MinEdge.Z; z<=a.MaxEdge.Z; z++) for(s32 y=a.MinEdge.Y; y<=a.MaxEdge.Y; y++) @@ -1958,17 +1958,17 @@ void MMVManip::initialEmerge(v3BPOS blockpos_min, v3BPOS blockpos_max, m_is_dirty = false; } -void MMVManip::blitBackAll(std::map *modified_blocks, +void MMVManip::blitBackAll(std::map *modified_blocks, bool overwrite_generated) { - if(m_area.getExtent() == v3POS(0,0,0)) + if(m_area.getExtent() == v3pos_t(0,0,0)) return; /* Copy data of all blocks */ for (auto &loaded_block : m_loaded_blocks) { - v3BPOS p = loaded_block.first; + v3bpos_t p = loaded_block.first; MapBlock *block = m_map->getBlockNoCreateNoEx(p); bool existed = !(loaded_block.second & VMANIP_BLOCK_DATA_INEXIST); if (!existed || (block == NULL) || diff --git a/src/map.h b/src/map.h index 4b1560b5ee..4f56ec35d4 100644 --- a/src/map.h +++ b/src/map.h @@ -77,9 +77,9 @@ enum MapEditEventType{ struct MapEditEvent { MapEditEventType type = MEET_OTHER; - v3POS p; + v3pos_t p; MapNode n = CONTENT_AIR; - std::set modified_blocks; + std::set modified_blocks; bool is_private_change = false; MapEditEvent() = default; @@ -95,16 +95,16 @@ struct MapEditEvent return VoxelArea(p); case MEET_BLOCK_NODE_METADATA_CHANGED: { - v3POS np1 = p*MAP_BLOCKSIZE; - v3POS np2 = np1 + v3POS(1,1,1)*MAP_BLOCKSIZE - v3POS(1,1,1); + v3pos_t np1 = p*MAP_BLOCKSIZE; + v3pos_t np2 = np1 + v3pos_t(1,1,1)*MAP_BLOCKSIZE - v3pos_t(1,1,1); return VoxelArea(np1, np2); } case MEET_OTHER: { VoxelArea a; - for (v3BPOS p : modified_blocks) { - v3POS np1 = getContainerPos(p, MAP_BLOCKSIZE); - v3POS np2 = np1 + v3POS(1,1,1)*MAP_BLOCKSIZE - v3POS(1,1,1); + for (v3bpos_t p : modified_blocks) { + v3pos_t np1 = getContainerPos(p, MAP_BLOCKSIZE); + v3pos_t np2 = np1 + v3pos_t(1,1,1)*MAP_BLOCKSIZE - v3pos_t(1,1,1); a.addPoint(np1); a.addPoint(np2); } @@ -149,53 +149,53 @@ class Map /*: public NodeContainer*/ void dispatchEvent(const MapEditEvent &event); // On failure returns NULL - MapSector * getSectorNoGenerateNoLock(v2BPOS p2d); + MapSector * getSectorNoGenerateNoLock(v2bpos_t p2d); // Same as the above (there exists no lock anymore) - MapSector * getSectorNoGenerate(v2BPOS p2d); + MapSector * getSectorNoGenerate(v2bpos_t p2d); /* This is overloaded by ClientMap and ServerMap to allow their differing fetch methods. */ - virtual MapSector * emergeSector(v2BPOS p){ return NULL; } + virtual MapSector * emergeSector(v2bpos_t p){ return NULL; } // Returns InvalidPositionException if not found - MapBlock * getBlockNoCreate(v3BPOS p); + MapBlock * getBlockNoCreate(v3bpos_t p); // Returns NULL if not found - MapBlock * getBlockNoCreateNoEx(v3BPOS p); + MapBlock * getBlockNoCreateNoEx(v3bpos_t p); /* Server overrides */ - virtual MapBlock * emergeBlock(v3BPOS p, bool create_blank=true) + virtual MapBlock * emergeBlock(v3bpos_t p, bool create_blank=true) { return getBlockNoCreateNoEx(p); } inline const NodeDefManager * getNodeDefManager() { return m_nodedef; } - bool isValidPosition(v3POS p); + bool isValidPosition(v3pos_t p); // throws InvalidPositionException if not found - void setNode(v3POS p, MapNode & n); + void setNode(v3pos_t p, MapNode & n); // Returns a CONTENT_IGNORE node if not found // If is_valid_position is not NULL then this will be set to true if the // position is valid, otherwise false - MapNode getNode(v3POS p, bool *is_valid_position = NULL); + MapNode getNode(v3pos_t p, bool *is_valid_position = NULL); /* These handle lighting but not faces. */ - void addNodeAndUpdate(v3POS p, MapNode n, - std::map &modified_blocks, + void addNodeAndUpdate(v3pos_t p, MapNode n, + std::map &modified_blocks, bool remove_metadata = true); - void removeNodeAndUpdate(v3POS p, - std::map &modified_blocks); + void removeNodeAndUpdate(v3pos_t p, + std::map &modified_blocks); /* Wrappers for the latter ones. These emit events. Return true if succeeded, false if not. */ - bool addNodeWithEvent(v3POS p, MapNode n, bool remove_metadata = true); - bool removeNodeWithEvent(v3POS p); + bool addNodeWithEvent(v3pos_t p, MapNode n, bool remove_metadata = true); + bool removeNodeWithEvent(v3pos_t p); // Call these before and after saving of many blocks virtual void beginSave() {} @@ -206,30 +206,30 @@ class Map /*: public NodeContainer*/ // Server implements these. // Client leaves them as no-op. virtual bool saveBlock(MapBlock *block) { return false; } - virtual bool deleteBlock(v3BPOS blockpos) { return false; } + virtual bool deleteBlock(v3bpos_t blockpos) { return false; } /* Updates usage timers and unloads unused blocks and sectors. Saves modified blocks before unloading on MAPTYPE_SERVER. */ void timerUpdate(float dtime, float unload_timeout, u32 max_loaded_blocks, - std::vector *unloaded_blocks=NULL); + std::vector *unloaded_blocks=NULL); /* Unloads all blocks with a zero refCount(). Saves modified blocks before unloading on MAPTYPE_SERVER. */ - void unloadUnreferencedBlocks(std::vector *unloaded_blocks=NULL); + void unloadUnreferencedBlocks(std::vector *unloaded_blocks=NULL); // Deletes sectors and their blocks from memory // Takes cache into account // If deleted sector is in sector cache, clears cache - void deleteSectors(std::vector &list); + void deleteSectors(std::vector &list); // For debug printing. Prints "Map: ", "ServerMap: " or "ClientMap: " virtual void PrintInfo(std::ostream &out); - void transformLiquids(std::map & modified_blocks, + void transformLiquids(std::map & modified_blocks, ServerEnvironment *env); /* @@ -237,8 +237,8 @@ class Map /*: public NodeContainer*/ These are basically coordinate wrappers to MapBlock */ - std::vector findNodesWithMetadata(v3POS p1, v3POS p2); - NodeMetadata *getNodeMetadata(v3POS p); + std::vector findNodesWithMetadata(v3pos_t p1, v3pos_t p2); + NodeMetadata *getNodeMetadata(v3pos_t p); /** * Sets metadata for a node. @@ -254,25 +254,25 @@ class Map /*: public NodeContainer*/ * @param meta pointer to @c NodeMetadata object * @return @c true on success, false on failure */ - bool setNodeMetadata(v3POS p, NodeMetadata *meta); - void removeNodeMetadata(v3POS p); + bool setNodeMetadata(v3pos_t p, NodeMetadata *meta); + void removeNodeMetadata(v3pos_t p); /* Node Timers These are basically coordinate wrappers to MapBlock */ - NodeTimer getNodeTimer(v3POS p); + NodeTimer getNodeTimer(v3pos_t p); void setNodeTimer(const NodeTimer &t); - void removeNodeTimer(v3POS p); + void removeNodeTimer(v3pos_t p); /* Variables */ - void transforming_liquid_add(v3POS p); + void transforming_liquid_add(v3pos_t p); - bool isBlockOccluded(MapBlock *block, v3POS cam_pos_nodes); + bool isBlockOccluded(MapBlock *block, v3pos_t cam_pos_nodes); protected: friend class LuaVoxelManip; @@ -280,21 +280,21 @@ class Map /*: public NodeContainer*/ std::set m_event_receivers; - std::map m_sectors; + std::map m_sectors; // Be sure to set this to NULL when the cached sector is deleted MapSector *m_sector_cache = nullptr; - v2BPOS m_sector_cache_p; + v2bpos_t m_sector_cache_p; // Queued transforming water nodes - UniqueQueue m_transforming_liquid; + UniqueQueue m_transforming_liquid; // This stores the properties of the nodes on the map. const NodeDefManager *m_nodedef; - bool determineAdditionalOcclusionCheck(const v3POS &pos_camera, - const core::aabbox3d &block_bounds, v3POS &check); - bool isOccluded(const v3POS &pos_camera, const v3POS &pos_target, + bool determineAdditionalOcclusionCheck(const v3pos_t &pos_camera, + const core::aabbox3d &block_bounds, v3pos_t &check); + bool isOccluded(const v3pos_t &pos_camera, const v3pos_t &pos_target, float step, float stepfac, float start_offset, float end_offset, u32 needed_count); @@ -331,22 +331,22 @@ class ServerMap : public Map - Check disk (doesn't load blocks) - Create blank one */ - MapSector *createSector(v2BPOS p); + MapSector *createSector(v2bpos_t p); /* Blocks are generated by using these and makeBlock(). */ - bool blockpos_over_mapgen_limit(v3BPOS p); - bool initBlockMake(v3BPOS blockpos, BlockMakeData *data); + bool blockpos_over_mapgen_limit(v3bpos_t p); + bool initBlockMake(v3bpos_t blockpos, BlockMakeData *data); void finishBlockMake(BlockMakeData *data, - std::map *changed_blocks); + std::map *changed_blocks); /* Get a block from somewhere. - Memory - Create blank */ - MapBlock *createBlock(v3BPOS p); + MapBlock *createBlock(v3bpos_t p); /* Forcefully get a block from somewhere. @@ -355,7 +355,7 @@ class ServerMap : public Map - Create blank filled with CONTENT_IGNORE */ - MapBlock *emergeBlock(v3BPOS p, bool create_blank=true); + MapBlock *emergeBlock(v3bpos_t p, bool create_blank=true); /* Try to get a block. @@ -363,9 +363,9 @@ class ServerMap : public Map - Memory - Emerge Queue (deferred disk or generate) */ - MapBlock *getBlockOrEmerge(v3BPOS p3d); + MapBlock *getBlockOrEmerge(v3bpos_t p3d); - bool isBlockInQueue(v3BPOS pos); + bool isBlockInQueue(v3bpos_t pos); /* Database functions @@ -377,20 +377,20 @@ class ServerMap : public Map void endSave(); void save(ModifiedState save_level); - void listAllLoadableBlocks(std::vector &dst); - void listAllLoadedBlocks(std::vector &dst); + void listAllLoadableBlocks(std::vector &dst); + void listAllLoadedBlocks(std::vector &dst); MapgenParams *getMapgenParams(); bool saveBlock(MapBlock *block); static bool saveBlock(MapBlock *block, MapDatabase *db, int compression_level = -1); - MapBlock* loadBlock(v3BPOS p); + MapBlock* loadBlock(v3bpos_t p); // Database version - void loadBlock(std::string *blob, v3BPOS p3d, MapSector *sector, bool save_after_load=false); + void loadBlock(std::string *blob, v3bpos_t p3d, MapSector *sector, bool save_after_load=false); - bool deleteBlock(v3BPOS blockpos); + bool deleteBlock(v3bpos_t blockpos); - void updateVManip(v3POS pos); + void updateVManip(v3pos_t pos); // For debug printing virtual void PrintInfo(std::ostream &out); @@ -406,8 +406,8 @@ class ServerMap : public Map * Returns false if the block is not generated (so nothing * changed), true otherwise. */ - bool repairBlockLight(v3BPOS blockpos, - std::map *modified_blocks); + bool repairBlockLight(v3bpos_t blockpos, + std::map *modified_blocks); MapSettingsManager settings_mgr; @@ -420,7 +420,7 @@ class ServerMap : public Map int m_map_compression_level; - std::set m_chunks_in_progress; + std::set m_chunks_in_progress; /* Metadata is re-written on disk only if this is true. @@ -449,11 +449,11 @@ class MMVManip : public VoxelManipulator m_loaded_blocks.clear(); } - void initialEmerge(v3BPOS blockpos_min, v3BPOS blockpos_max, + void initialEmerge(v3bpos_t blockpos_min, v3bpos_t blockpos_max, bool load_if_inexistent = true); // This is much faster with big chunks of generated data - void blitBackAll(std::map * modified_blocks, + void blitBackAll(std::map * modified_blocks, bool overwrite_generated = true); bool m_is_dirty = false; @@ -464,5 +464,5 @@ class MMVManip : public VoxelManipulator key = blockpos value = flags describing the block */ - std::map m_loaded_blocks; + std::map m_loaded_blocks; }; diff --git a/src/mapblock.cpp b/src/mapblock.cpp index 14371e38d5..74e11a9f4e 100644 --- a/src/mapblock.cpp +++ b/src/mapblock.cpp @@ -66,7 +66,7 @@ static const char *modified_reason_strings[] = { MapBlock */ -MapBlock::MapBlock(Map *parent, v3POS pos, IGameDef *gamedef, bool dummy): +MapBlock::MapBlock(Map *parent, v3pos_t pos, IGameDef *gamedef, bool dummy): m_parent(parent), m_pos(pos), m_pos_relative(pos * MAP_BLOCKSIZE), @@ -88,7 +88,7 @@ MapBlock::~MapBlock() delete[] data; } -bool MapBlock::isValidPositionParent(v3POS p) +bool MapBlock::isValidPositionParent(v3pos_t p) { if (isValidPosition(p)) { return true; @@ -97,7 +97,7 @@ bool MapBlock::isValidPositionParent(v3POS p) return m_parent->isValidPosition(getPosRelative() + p); } -MapNode MapBlock::getNodeParent(v3POS p, bool *is_valid_position) +MapNode MapBlock::getNodeParent(v3pos_t p, bool *is_valid_position) { if (!isValidPosition(p)) return m_parent->getNode(getPosRelative() + p, is_valid_position); @@ -136,21 +136,21 @@ std::string MapBlock::getModifiedReasonString() void MapBlock::copyTo(VoxelManipulator &dst) { - v3POS data_size(MAP_BLOCKSIZE, MAP_BLOCKSIZE, MAP_BLOCKSIZE); - VoxelArea data_area(v3POS(0,0,0), data_size - v3POS(1,1,1)); + v3pos_t data_size(MAP_BLOCKSIZE, MAP_BLOCKSIZE, MAP_BLOCKSIZE); + VoxelArea data_area(v3pos_t(0,0,0), data_size - v3pos_t(1,1,1)); // Copy from data to VoxelManipulator - dst.copyFrom(data, data_area, v3POS(0,0,0), + dst.copyFrom(data, data_area, v3pos_t(0,0,0), getPosRelative(), data_size); } void MapBlock::copyFrom(VoxelManipulator &dst) { - v3POS data_size(MAP_BLOCKSIZE, MAP_BLOCKSIZE, MAP_BLOCKSIZE); - VoxelArea data_area(v3POS(0,0,0), data_size - v3POS(1,1,1)); + v3pos_t data_size(MAP_BLOCKSIZE, MAP_BLOCKSIZE, MAP_BLOCKSIZE); + VoxelArea data_area(v3pos_t(0,0,0), data_size - v3pos_t(1,1,1)); // Copy from VoxelManipulator to data - dst.copyTo(data, data_area, v3POS(0,0,0), + dst.copyTo(data, data_area, v3pos_t(0,0,0), getPosRelative(), data_size); } @@ -825,7 +825,7 @@ std::string analyze_block(MapBlock *block) std::ostringstream desc; - v3POS p = block->getPos(); + v3pos_t p = block->getPos(); char spos[25]; porting::mt_snprintf(spos, sizeof(spos), "(%2d,%2d,%2d), ", p.X, p.Y, p.Z); desc<getNodeNoEx(p); content_t c = n.getContent(); if(c == CONTENT_IGNORE) diff --git a/src/mapblock.h b/src/mapblock.h index d0f9c82e09..bda6e4ed24 100644 --- a/src/mapblock.h +++ b/src/mapblock.h @@ -74,7 +74,7 @@ class VoxelManipulator; class MapBlock { public: - MapBlock(Map *parent, v3POS pos, IGameDef *gamedef, bool dummy=false); + MapBlock(Map *parent, v3pos_t pos, IGameDef *gamedef, bool dummy=false); ~MapBlock(); /*virtual u16 nodeContainerId() const @@ -219,22 +219,22 @@ class MapBlock //// Position stuff //// - inline v3BPOS getPos() + inline v3bpos_t getPos() { return m_pos; } - inline v3POS getPosRelative() + inline v3pos_t getPosRelative() { return m_pos_relative; } - inline core::aabbox3d getBox() + inline core::aabbox3d getBox() { - return core::aabbox3d(getPosRelative(), + return core::aabbox3d(getPosRelative(), getPosRelative() - + v3POS(MAP_BLOCKSIZE, MAP_BLOCKSIZE, MAP_BLOCKSIZE) - - v3POS(1,1,1)); + + v3pos_t(MAP_BLOCKSIZE, MAP_BLOCKSIZE, MAP_BLOCKSIZE) + - v3pos_t(1,1,1)); } //// @@ -249,7 +249,7 @@ class MapBlock && z >= 0 && z < MAP_BLOCKSIZE; } - inline bool isValidPosition(v3POS p) + inline bool isValidPosition(v3pos_t p) { return isValidPosition(p.X, p.Y, p.Z); } @@ -264,12 +264,12 @@ class MapBlock return data[z * zstride + y * ystride + x]; } - inline MapNode getNode(v3POS p, bool *valid_position) + inline MapNode getNode(v3pos_t p, bool *valid_position) { return getNode(p.X, p.Y, p.Z, valid_position); } - inline MapNode getNodeNoEx(v3POS p) + inline MapNode getNodeNoEx(v3pos_t p) { bool is_valid; return getNode(p.X, p.Y, p.Z, &is_valid); @@ -284,7 +284,7 @@ class MapBlock raiseModified(MOD_STATE_WRITE_NEEDED, MOD_REASON_SET_NODE); } - inline void setNode(v3POS p, MapNode & n) + inline void setNode(v3pos_t p, MapNode & n) { setNode(p.X, p.Y, p.Z, n); } @@ -293,7 +293,7 @@ class MapBlock //// Non-checking variants of the above //// - inline MapNode getNodeNoCheck(POS x, POS y, POS z, bool *valid_position) + inline MapNode getNodeNoCheck(pos_t x, pos_t y, pos_t z, bool *valid_position) { *valid_position = data != nullptr; if (!*valid_position) @@ -302,7 +302,7 @@ class MapBlock return data[z * zstride + y * ystride + x]; } - inline MapNode getNodeNoCheck(v3POS p, bool *valid_position) + inline MapNode getNodeNoCheck(v3pos_t p, bool *valid_position) { return getNodeNoCheck(p.X, p.Y, p.Z, valid_position); } @@ -313,17 +313,17 @@ class MapBlock //// Caller must ensure that this is not a dummy block (by calling isDummy()) //// - inline const MapNode &getNodeUnsafe(POS x, POS y, POS z) + inline const MapNode &getNodeUnsafe(pos_t x, pos_t y, pos_t z) { return data[z * zstride + y * ystride + x]; } - inline const MapNode &getNodeUnsafe(v3POS &p) + inline const MapNode &getNodeUnsafe(v3pos_t &p) { return getNodeUnsafe(p.X, p.Y, p.Z); } - inline void setNodeNoCheck(POS x, POS y, POS z, MapNode & n) + inline void setNodeNoCheck(pos_t x, pos_t y, pos_t z, MapNode & n) { if (!data) throw InvalidPositionException(); @@ -332,15 +332,15 @@ class MapBlock raiseModified(MOD_STATE_WRITE_NEEDED, MOD_REASON_SET_NODE_NO_CHECK); } - inline void setNodeNoCheck(v3POS p, MapNode & n) + inline void setNodeNoCheck(v3pos_t p, MapNode & n) { setNodeNoCheck(p.X, p.Y, p.Z, n); } // These functions consult the parent container if the position // is not valid on this MapBlock. - bool isValidPositionParent(v3POS p); - MapNode getNodeParent(v3POS p, bool *is_valid_position = NULL); + bool isValidPositionParent(v3pos_t p); + MapNode getNodeParent(v3pos_t p, bool *is_valid_position = NULL); // Copies data to VoxelManipulator to getPosRelative() void copyTo(VoxelManipulator &dst); @@ -433,12 +433,12 @@ class MapBlock //// Node Timers //// - inline NodeTimer getNodeTimer(const v3POS &p) + inline NodeTimer getNodeTimer(const v3pos_t &p) { return m_node_timers.get(p); } - inline void removeNodeTimer(const v3POS &p) + inline void removeNodeTimer(const v3pos_t &p) { m_node_timers.remove(p); } @@ -486,7 +486,7 @@ class MapBlock return data[z * zstride + y * ystride + x]; } - inline MapNode &getNodeRef(v3POS &p) + inline MapNode &getNodeRef(v3pos_t &p) { return getNodeRef(p.X, p.Y, p.Z); } @@ -525,7 +525,7 @@ class MapBlock // NOTE: Lots of things rely on this being the Map Map *m_parent; // Position in blocks on parent - v3BPOS m_pos; + v3bpos_t m_pos; /* This is the precalculated m_pos_relative value * This caches the value, improving performance by removing 3 s16 multiplications @@ -533,7 +533,7 @@ class MapBlock * For a 5 minutes runtime with valgrind this removes 3 * 19M s16 multiplications * The gain can be estimated in Release Build to 3 * 100M multiply operations for 5 mins */ - v3POS m_pos_relative; + v3pos_t m_pos_relative; IGameDef *m_gamedef; @@ -611,9 +611,9 @@ inline bool objectpos_over_limit(v3f p) p.Z > max_limit_bs; } -inline bool blockpos_over_max_limit(v3BPOS p) +inline bool blockpos_over_max_limit(v3bpos_t p) { - const BPOS max_limit_bp = MAX_MAP_GENERATION_LIMIT / MAP_BLOCKSIZE; + const bpos_t max_limit_bp = MAX_MAP_GENERATION_LIMIT / MAP_BLOCKSIZE; return p.X < -max_limit_bp || p.X > max_limit_bp || p.Y < -max_limit_bp || @@ -625,12 +625,12 @@ inline bool blockpos_over_max_limit(v3BPOS p) /* Returns the position of the block where the node is located */ -inline v3BPOS getNodeBlockPos(const v3POS &p) +inline v3bpos_t getNodeBlockPos(const v3pos_t &p) { return getContainerPos(p, MAP_BLOCKSIZE); } -inline void getNodeBlockPosWithOffset(const v3POS &p, v3BPOS &block, v3POS &offset) +inline void getNodeBlockPosWithOffset(const v3pos_t &p, v3bpos_t &block, v3pos_t &offset) { getContainerPosWithOffset(p, MAP_BLOCKSIZE, block, offset); } diff --git a/src/mapgen/cavegen.cpp b/src/mapgen/cavegen.cpp index 6dd0b5bde4..b6e7ea3cc5 100644 --- a/src/mapgen/cavegen.cpp +++ b/src/mapgen/cavegen.cpp @@ -38,7 +38,7 @@ static NoiseParams nparams_caveliquids(0, 1, v3f(150.0, 150.0, 150.0), 776, 3, 0 //// CavesNoiseIntersection::CavesNoiseIntersection( - const NodeDefManager *nodedef, BiomeManager *biomemgr, v3POS chunksize, + const NodeDefManager *nodedef, BiomeManager *biomemgr, v3pos_t chunksize, NoiseParams *np_cave1, NoiseParams *np_cave2, s32 seed, float cave_width) { assert(nodedef); @@ -69,7 +69,7 @@ CavesNoiseIntersection::~CavesNoiseIntersection() void CavesNoiseIntersection::generateCaves(MMVManip *vm, - v3POS nmin, v3POS nmax, biome_t *biomemap) + v3pos_t nmin, v3pos_t nmax, biome_t *biomemap) { assert(vm); assert(biomemap); @@ -77,11 +77,11 @@ void CavesNoiseIntersection::generateCaves(MMVManip *vm, noise_cave1->perlinMap3D(nmin.X, nmin.Y - 1, nmin.Z); noise_cave2->perlinMap3D(nmin.X, nmin.Y - 1, nmin.Z); - const v3POS &em = vm->m_area.getExtent(); + const v3pos_t &em = vm->m_area.getExtent(); u32 index2d = 0; // Biomemap index - for (POS z = nmin.Z; z <= nmax.Z; z++) - for (POS x = nmin.X; x <= nmax.X; x++, index2d++) { + for (pos_t z = nmin.Z; z <= nmax.Z; z++) + for (pos_t x = nmin.X; x <= nmax.X; x++, index2d++) { bool column_is_open = false; // Is column open to overground bool is_under_river = false; // Is column under river water bool is_under_tunnel = false; // Is tunnel or is under tunnel @@ -100,7 +100,7 @@ void CavesNoiseIntersection::generateCaves(MMVManip *vm, // this creates a 'roof' over the tunnel, preventing light in // tunnels at mapchunk borders when generating mapchunks upwards. // This 'roof' is removed when the mapchunk above is generated. - for (POS y = nmax.Y; y >= nmin.Y - 1; y--, + for (pos_t y = nmax.Y; y >= nmin.Y - 1; y--, index3d -= m_ystride, VoxelArea::add_y(em, vi, -1)) { content_t c = vm->m_data[vi].getContent(); @@ -176,7 +176,7 @@ void CavesNoiseIntersection::generateCaves(MMVManip *vm, //// CavernsNoise::CavernsNoise( - const NodeDefManager *nodedef, v3POS chunksize, NoiseParams *np_cavern, + const NodeDefManager *nodedef, v3pos_t chunksize, NoiseParams *np_cavern, s32 seed, float cavern_limit, float cavern_taper, float cavern_threshold) { assert(nodedef); @@ -212,7 +212,7 @@ CavernsNoise::~CavernsNoise() } -bool CavernsNoise::generateCaverns(MMVManip *vm, v3POS nmin, v3POS nmax) +bool CavernsNoise::generateCaverns(MMVManip *vm, v3pos_t nmin, v3pos_t nmax) { assert(vm); @@ -222,18 +222,18 @@ bool CavernsNoise::generateCaverns(MMVManip *vm, v3POS nmin, v3POS nmax) // Cache cavern_amp values float *cavern_amp = new float[m_csize.Y + 1]; u8 cavern_amp_index = 0; // Index zero at column top - for (POS y = nmax.Y; y >= nmin.Y - 1; y--, cavern_amp_index++) { + for (pos_t y = nmax.Y; y >= nmin.Y - 1; y--, cavern_amp_index++) { cavern_amp[cavern_amp_index] = MYMIN((m_cavern_limit - y) / (float)m_cavern_taper, 1.0f); } //// Place nodes bool near_cavern = false; - const v3POS &em = vm->m_area.getExtent(); + const v3pos_t &em = vm->m_area.getExtent(); u32 index2d = 0; - for (POS z = nmin.Z; z <= nmax.Z; z++) - for (POS x = nmin.X; x <= nmax.X; x++, index2d++) { + for (pos_t z = nmin.Z; z <= nmax.Z; z++) + for (pos_t x = nmin.X; x <= nmax.X; x++, index2d++) { // Reset cave_amp index to column top cavern_amp_index = 0; // Initial voxelmanip index at column top @@ -245,7 +245,7 @@ bool CavernsNoise::generateCaverns(MMVManip *vm, v3POS nmin, v3POS nmax) // this creates a 'roof' over the cavern, preventing light in // caverns at mapchunk borders when generating mapchunks upwards. // This 'roof' is excavated when the mapchunk above is generated. - for (POS y = nmax.Y; y >= nmin.Y - 1; y--, + for (pos_t y = nmax.Y; y >= nmin.Y - 1; y--, index3d -= m_ystride, VoxelArea::add_y(em, vi, -1), cavern_amp_index++) { @@ -307,8 +307,8 @@ CavesRandomWalk::CavesRandomWalk( } -void CavesRandomWalk::makeCave(MMVManip *vm, v3POS nmin, v3POS nmax, - PseudoRandom *ps, bool is_large_cave, int max_stone_height, POS *heightmap) +void CavesRandomWalk::makeCave(MMVManip *vm, v3pos_t nmin, v3pos_t nmax, + PseudoRandom *ps, bool is_large_cave, int max_stone_height, pos_t *heightmap) { assert(vm); assert(ps); @@ -329,7 +329,7 @@ void CavesRandomWalk::makeCave(MMVManip *vm, v3POS nmin, v3POS nmax, // If defined liquid is "air", disable 'flooded' to avoid placing "air". use_biome_liquid = false; if (flooded && bmgn) { - v3POS midp = node_min + (node_max - node_min) / v3POS(2, 2, 2); + v3pos_t midp = node_min + (node_max - node_min) / v3pos_t(2, 2, 2); Biome *biome = (Biome *)bmgn->getBiomeAtPoint(midp); if (biome->c_cave_liquid[0] != CONTENT_IGNORE) { use_biome_liquid = true; @@ -360,7 +360,7 @@ void CavesRandomWalk::makeCave(MMVManip *vm, v3POS nmin, v3POS nmax, main_direction = v3f(0, 0, 0); // Allowed route area size in nodes - ar = node_max - node_min + v3POS(1, 1, 1); + ar = node_max - node_min + v3pos_t(1, 1, 1); // Area starting point in nodes of = node_min; @@ -369,8 +369,8 @@ void CavesRandomWalk::makeCave(MMVManip *vm, v3POS nmin, v3POS nmax, // 'insure' is needed to avoid many 'out of voxelmanip' cave nodes. const s16 insure = 2; s16 more = MYMAX(MAP_BLOCKSIZE - max_tunnel_diameter / 2 - insure, 1); - ar += v3POS(1, 1, 1) * more * 2; - of -= v3POS(1, 1, 1) * more; + ar += v3pos_t(1, 1, 1) * more * 2; + of -= v3pos_t(1, 1, 1) * more; route_y_min = 0; // Allow half a diameter + 7 over stone surface @@ -380,7 +380,7 @@ void CavesRandomWalk::makeCave(MMVManip *vm, v3POS nmin, v3POS nmax, route_y_max = rangelim(route_y_max, 0, ar.Y - 1); if (large_cave) { - POS minpos = 0; + pos_t minpos = 0; if (node_min.Y < water_level && node_max.Y > water_level) { minpos = water_level - max_tunnel_diameter / 3 - of.Y; route_y_max = water_level + max_tunnel_diameter / 3 - of.Y; @@ -389,8 +389,8 @@ void CavesRandomWalk::makeCave(MMVManip *vm, v3POS nmin, v3POS nmax, route_y_min = rangelim(route_y_min, 0, route_y_max); } - POS route_start_y_min = route_y_min; - POS route_start_y_max = route_y_max; + pos_t route_start_y_min = route_y_min; + pos_t route_start_y_max = route_y_max; route_start_y_min = rangelim(route_start_y_min, 0, ar.Y - 1); route_start_y_max = rangelim(route_start_y_max, route_start_y_min, ar.Y - 1); @@ -402,7 +402,7 @@ void CavesRandomWalk::makeCave(MMVManip *vm, v3POS nmin, v3POS nmax, // Add generation notify begin event if (gennotify) { - v3POS abs_pos(of.X + orp.X, of.Y + orp.Y, of.Z + orp.Z); + v3pos_t abs_pos(of.X + orp.X, of.Y + orp.Y, of.Z + orp.Z); GenNotifyType notifytype = large_cave ? GENNOTIFY_LARGECAVE_BEGIN : GENNOTIFY_CAVE_BEGIN; gennotify->addEvent(notifytype, abs_pos); @@ -414,7 +414,7 @@ void CavesRandomWalk::makeCave(MMVManip *vm, v3POS nmin, v3POS nmax, // Add generation notify end event if (gennotify) { - v3POS abs_pos(of.X + orp.X, of.Y + orp.Y, of.Z + orp.Z); + v3pos_t abs_pos(of.X + orp.X, of.Y + orp.Y, of.Z + orp.Z); GenNotifyType notifytype = large_cave ? GENNOTIFY_LARGECAVE_END : GENNOTIFY_CAVE_END; gennotify->addEvent(notifytype, abs_pos); @@ -438,15 +438,15 @@ void CavesRandomWalk::makeTunnel(bool dirswitch) rs = ps->range(min_d, max_d); s16 rs_part_max_length_rs = rs * part_max_length_rs; - v3POS maxlen; + v3pos_t maxlen; if (large_cave) { - maxlen = v3POS( + maxlen = v3pos_t( rs_part_max_length_rs, rs_part_max_length_rs / 2, rs_part_max_length_rs ); } else { - maxlen = v3POS( + maxlen = v3pos_t( rs_part_max_length_rs, ps->range(1, rs_part_max_length_rs), rs_part_max_length_rs @@ -467,8 +467,8 @@ void CavesRandomWalk::makeTunnel(bool dirswitch) // Do not make caves that are above ground. // It is only necessary to check the startpoint and endpoint. - v3POS p1 = v3POS(orp.X, orp.Y, orp.Z) + of + rs / 2; - v3POS p2 = v3POS(vec.X, vec.Y, vec.Z) + p1; + v3pos_t p1 = v3pos_t(orp.X, orp.Y, orp.Z) + of + rs / 2; + v3pos_t p2 = v3pos_t(vec.X, vec.Y, vec.Z) + p1; if (isPosAboveSurface(p1) || isPosAboveSurface(p2)) return; @@ -513,13 +513,13 @@ void CavesRandomWalk::carveRoute(v3f vec, float f, bool randomize_xz) MapNode waternode(c_water_source); MapNode lavanode(c_lava_source); - v3POS startp(orp.X, orp.Y, orp.Z); + v3pos_t startp(orp.X, orp.Y, orp.Z); startp += of; v3f fp = orp + vec * f; fp.X += 0.1f * ps->range(-10, 10); fp.Z += 0.1f * ps->range(-10, 10); - v3POS cp(fp.X, fp.Y, fp.Z); + v3pos_t cp(fp.X, fp.Y, fp.Z); // Choose cave liquid MapNode liquidnode = CONTENT_IGNORE; @@ -565,7 +565,7 @@ void CavesRandomWalk::carveRoute(v3f vec, float f, bool randomize_xz) continue; } - v3POS p(cp.X + x0, cp.Y + y0, cp.Z + z0); + v3pos_t p(cp.X + x0, cp.Y + y0, cp.Z + z0); p += of; if (!vm->m_area.contains(p)) @@ -596,7 +596,7 @@ void CavesRandomWalk::carveRoute(v3f vec, float f, bool randomize_xz) } -inline bool CavesRandomWalk::isPosAboveSurface(v3POS p) +inline bool CavesRandomWalk::isPosAboveSurface(v3pos_t p) { if (heightmap != NULL && p.Z >= node_min.Z && p.Z <= node_max.Z && @@ -639,9 +639,9 @@ CavesV6::CavesV6(const NodeDefManager *ndef, GenerateNotifier *gennotify, } -void CavesV6::makeCave(MMVManip *vm, v3POS nmin, v3POS nmax, +void CavesV6::makeCave(MMVManip *vm, v3pos_t nmin, v3pos_t nmax, PseudoRandom *ps, PseudoRandom *ps2, - bool is_large_cave, int max_stone_height, POS *heightmap) + bool is_large_cave, int max_stone_height, pos_t *heightmap) { assert(vm); assert(ps); @@ -675,7 +675,7 @@ void CavesV6::makeCave(MMVManip *vm, v3POS nmin, v3POS nmax, main_direction = v3f(0, 0, 0); // Allowed route area size in nodes - ar = node_max - node_min + v3POS(1, 1, 1); + ar = node_max - node_min + v3pos_t(1, 1, 1); // Area starting point in nodes of = node_min; @@ -684,8 +684,8 @@ void CavesV6::makeCave(MMVManip *vm, v3POS nmin, v3POS nmax, const s16 max_spread_amount = MAP_BLOCKSIZE; const s16 insure = 10; s16 more = MYMAX(max_spread_amount - max_tunnel_diameter / 2 - insure, 1); - ar += v3POS(1, 0, 1) * more * 2; - of -= v3POS(1, 0, 1) * more; + ar += v3pos_t(1, 0, 1) * more * 2; + of -= v3pos_t(1, 0, 1) * more; route_y_min = 0; // Allow half a diameter + 7 over stone surface @@ -704,8 +704,8 @@ void CavesV6::makeCave(MMVManip *vm, v3POS nmin, v3POS nmax, route_y_min = rangelim(route_y_min, 0, route_y_max); } - POS route_start_y_min = route_y_min; - POS route_start_y_max = route_y_max; + pos_t route_start_y_min = route_y_min; + pos_t route_start_y_max = route_y_max; route_start_y_min = rangelim(route_start_y_min, 0, ar.Y - 1); route_start_y_max = rangelim(route_start_y_max, route_start_y_min, ar.Y - 1); @@ -717,7 +717,7 @@ void CavesV6::makeCave(MMVManip *vm, v3POS nmin, v3POS nmax, // Add generation notify begin event if (gennotify != NULL) { - v3POS abs_pos(of.X + orp.X, of.Y + orp.Y, of.Z + orp.Z); + v3pos_t abs_pos(of.X + orp.X, of.Y + orp.Y, of.Z + orp.Z); GenNotifyType notifytype = large_cave ? GENNOTIFY_LARGECAVE_BEGIN : GENNOTIFY_CAVE_BEGIN; gennotify->addEvent(notifytype, abs_pos); @@ -729,7 +729,7 @@ void CavesV6::makeCave(MMVManip *vm, v3POS nmin, v3POS nmax, // Add generation notify end event if (gennotify != NULL) { - v3POS abs_pos(of.X + orp.X, of.Y + orp.Y, of.Z + orp.Z); + v3pos_t abs_pos(of.X + orp.X, of.Y + orp.Y, of.Z + orp.Z); GenNotifyType notifytype = large_cave ? GENNOTIFY_LARGECAVE_END : GENNOTIFY_CAVE_END; gennotify->addEvent(notifytype, abs_pos); @@ -753,15 +753,15 @@ void CavesV6::makeTunnel(bool dirswitch) rs = ps->range(min_d, max_d); s16 rs_part_max_length_rs = rs * part_max_length_rs; - v3POS maxlen; + v3pos_t maxlen; if (large_cave) { - maxlen = v3POS( + maxlen = v3pos_t( rs_part_max_length_rs, rs_part_max_length_rs / 2, rs_part_max_length_rs ); } else { - maxlen = v3POS( + maxlen = v3pos_t( rs_part_max_length_rs, ps->range(1, rs_part_max_length_rs), rs_part_max_length_rs @@ -783,8 +783,8 @@ void CavesV6::makeTunnel(bool dirswitch) // Do not make caves that are entirely above ground, to fix shadow bugs // caused by overgenerated large caves. // It is only necessary to check the startpoint and endpoint. - v3POS p1 = v3POS(orp.X, orp.Y, orp.Z) + of + rs / 2; - v3POS p2 = v3POS(vec.X, vec.Y, vec.Z) + p1; + v3pos_t p1 = v3pos_t(orp.X, orp.Y, orp.Z) + of + rs / 2; + v3pos_t p2 = v3pos_t(vec.X, vec.Y, vec.Z) + p1; // If startpoint and endpoint are above ground, disable placement of nodes // in carveRoute while still running all PseudoRandom calls to ensure caves @@ -836,13 +836,13 @@ void CavesV6::carveRoute(v3f vec, float f, bool randomize_xz, MapNode waternode(c_water_source); MapNode lavanode(c_lava_source); - v3POS startp(orp.X, orp.Y, orp.Z); + v3pos_t startp(orp.X, orp.Y, orp.Z); startp += of; v3f fp = orp + vec * f; fp.X += 0.1f * ps->range(-10, 10); fp.Z += 0.1f * ps->range(-10, 10); - v3POS cp(fp.X, fp.Y, fp.Z); + v3pos_t cp(fp.X, fp.Y, fp.Z); s16 d0 = -rs / 2; s16 d1 = d0 + rs; @@ -866,7 +866,7 @@ void CavesV6::carveRoute(v3f vec, float f, bool randomize_xz, continue; } - v3POS p(cp.X + x0, cp.Y + y0, cp.Z + z0); + v3pos_t p(cp.X + x0, cp.Y + y0, cp.Z + z0); p += of; if (!vm->m_area.contains(p)) @@ -901,7 +901,7 @@ void CavesV6::carveRoute(v3f vec, float f, bool randomize_xz, } -inline POS CavesV6::getSurfaceFromHeightmap(v3POS p) +inline pos_t CavesV6::getSurfaceFromHeightmap(v3pos_t p) { if (heightmap != NULL && p.Z >= node_min.Z && p.Z <= node_max.Z && diff --git a/src/mapgen/cavegen.h b/src/mapgen/cavegen.h index 45d145e41b..58cd8b1aba 100644 --- a/src/mapgen/cavegen.h +++ b/src/mapgen/cavegen.h @@ -42,18 +42,18 @@ class CavesNoiseIntersection { public: CavesNoiseIntersection(const NodeDefManager *nodedef, - BiomeManager *biomemgr, v3POS chunksize, NoiseParams *np_cave1, + BiomeManager *biomemgr, v3pos_t chunksize, NoiseParams *np_cave1, NoiseParams *np_cave2, s32 seed, float cave_width); ~CavesNoiseIntersection(); - void generateCaves(MMVManip *vm, v3POS nmin, v3POS nmax, biome_t *biomemap); + void generateCaves(MMVManip *vm, v3pos_t nmin, v3pos_t nmax, biome_t *biomemap); private: const NodeDefManager *m_ndef; BiomeManager *m_bmgr; // configurable parameters - v3POS m_csize; + v3pos_t m_csize; float m_cave_width; // intermediate state variables @@ -70,18 +70,18 @@ class CavesNoiseIntersection class CavernsNoise { public: - CavernsNoise(const NodeDefManager *nodedef, v3POS chunksize, + CavernsNoise(const NodeDefManager *nodedef, v3pos_t chunksize, NoiseParams *np_cavern, s32 seed, float cavern_limit, float cavern_taper, float cavern_threshold); ~CavernsNoise(); - bool generateCaverns(MMVManip *vm, v3POS nmin, v3POS nmax); + bool generateCaverns(MMVManip *vm, v3pos_t nmin, v3pos_t nmax); private: const NodeDefManager *m_ndef; // configurable parameters - v3POS m_csize; + v3pos_t m_csize; float m_cavern_limit; float m_cavern_taper; float m_cavern_threshold; @@ -115,7 +115,7 @@ class CavesRandomWalk MMVManip *vm; const NodeDefManager *ndef; GenerateNotifier *gennotify; - POS *heightmap; + pos_t *heightmap; BiomeGen *bmgn; s32 seed; @@ -137,17 +137,17 @@ class CavesRandomWalk bool flooded; bool use_biome_liquid; - v3POS node_min; - v3POS node_max; + v3pos_t node_min; + v3pos_t node_max; v3f orp; // starting point, relative to caved space - v3POS of; // absolute coordinates of caved space - v3POS ar; // allowed route area + v3pos_t of; // absolute coordinates of caved space + v3pos_t ar; // allowed route area s16 rs; // tunnel radius size v3f main_direction; - POS route_y_min; - POS route_y_max; + pos_t route_y_min; + pos_t route_y_max; PseudoRandom *ps; @@ -166,14 +166,14 @@ class CavesRandomWalk // vm and ps are mandatory parameters. // If heightmap is NULL, the surface level at all points is assumed to // be water_level. - void makeCave(MMVManip *vm, v3POS nmin, v3POS nmax, PseudoRandom *ps, - bool is_large_cave, int max_stone_height, POS *heightmap); + void makeCave(MMVManip *vm, v3pos_t nmin, v3pos_t nmax, PseudoRandom *ps, + bool is_large_cave, int max_stone_height, pos_t *heightmap); private: void makeTunnel(bool dirswitch); void carveRoute(v3f vec, float f, bool randomize_xz); - inline bool isPosAboveSurface(v3POS p); + inline bool isPosAboveSurface(v3pos_t p); }; /* @@ -199,7 +199,7 @@ class CavesV6 PseudoRandom *ps2; // configurable parameters - POS *heightmap; + pos_t *heightmap; content_t c_water_source; content_t c_lava_source; int water_level; @@ -215,12 +215,12 @@ class CavesV6 bool large_cave; bool large_cave_is_flat; - v3POS node_min; - v3POS node_max; + v3pos_t node_min; + v3pos_t node_max; v3f orp; // starting point, relative to caved space - v3POS of; // absolute coordinates of caved space - v3POS ar; // allowed route area + v3pos_t of; // absolute coordinates of caved space + v3pos_t ar; // allowed route area s16 rs; // tunnel radius size v3f main_direction; @@ -236,13 +236,13 @@ class CavesV6 // vm, ps, and ps2 are mandatory parameters. // If heightmap is NULL, the surface level at all points is assumed to // be water_level. - void makeCave(MMVManip *vm, v3POS nmin, v3POS nmax, PseudoRandom *ps, + void makeCave(MMVManip *vm, v3pos_t nmin, v3pos_t nmax, PseudoRandom *ps, PseudoRandom *ps2, bool is_large_cave, int max_stone_height, - POS *heightmap = NULL); + pos_t *heightmap = NULL); private: void makeTunnel(bool dirswitch); void carveRoute(v3f vec, float f, bool randomize_xz, bool tunnel_above_ground); - inline POS getSurfaceFromHeightmap(v3POS p); + inline pos_t getSurfaceFromHeightmap(v3pos_t p); }; diff --git a/src/mapgen/dungeongen.cpp b/src/mapgen/dungeongen.cpp index 8a53e73fba..c709240a10 100644 --- a/src/mapgen/dungeongen.cpp +++ b/src/mapgen/dungeongen.cpp @@ -59,13 +59,13 @@ DungeonGen::DungeonGen(const NodeDefManager *ndef, dp.diagonal_dirs = false; dp.only_in_ground = true; - dp.holesize = v3POS(1, 2, 1); + dp.holesize = v3pos_t(1, 2, 1); dp.corridor_len_min = 1; dp.corridor_len_max = 13; - dp.room_size_min = v3POS(4, 4, 4); - dp.room_size_max = v3POS(8, 6, 8); - dp.room_size_large_min = v3POS(8, 8, 8); - dp.room_size_large_max = v3POS(16, 16, 16); + dp.room_size_min = v3pos_t(4, 4, 4); + dp.room_size_max = v3pos_t(8, 6, 8); + dp.room_size_large_min = v3pos_t(8, 8, 8); + dp.room_size_large_max = v3pos_t(16, 16, 16); dp.large_room_chance = 1; dp.num_rooms = 8; dp.num_dungeons = 1; @@ -77,7 +77,7 @@ DungeonGen::DungeonGen(const NodeDefManager *ndef, } -void DungeonGen::generate(MMVManip *vm, u32 bseed, v3POS nmin, v3POS nmax) +void DungeonGen::generate(MMVManip *vm, u32 bseed, v3pos_t nmin, v3pos_t nmax) { if (dp.num_dungeons == 0) return; @@ -101,10 +101,10 @@ void DungeonGen::generate(MMVManip *vm, u32 bseed, v3POS nmin, v3POS nmax) // Like randomwalk caves, preserve nodes that have 'is_ground_content = false', // to avoid dungeons that generate out beyond the edge of a mapchunk destroying // nodes added by mods in 'register_on_generated()'. - for (POS z = nmin.Z; z <= nmax.Z; z++) { - for (POS y = nmin.Y; y <= nmax.Y; y++) { + for (pos_t z = nmin.Z; z <= nmax.Z; z++) { + for (pos_t y = nmin.Y; y <= nmax.Y; y++) { u32 i = vm->m_area.index(nmin.X, y, z); - for (POS x = nmin.X; x <= nmax.X; x++) { + for (pos_t x = nmin.X; x <= nmax.X; x++) { content_t c = vm->m_data[i].getContent(); NodeDrawType dtype = ndef->get(c).drawtype; if (dtype == NDT_AIRLIKE || dtype == NDT_LIQUID || @@ -118,16 +118,16 @@ void DungeonGen::generate(MMVManip *vm, u32 bseed, v3POS nmin, v3POS nmax) // Add them for (u32 i = 0; i < dp.num_dungeons; i++) - makeDungeon(v3POS(1, 1, 1) * MAP_BLOCKSIZE); + makeDungeon(v3pos_t(1, 1, 1) * MAP_BLOCKSIZE); // Optionally convert some structure to alternative structure if (dp.c_alt_wall == CONTENT_IGNORE) return; - for (POS z = nmin.Z; z <= nmax.Z; z++) - for (POS y = nmin.Y; y <= nmax.Y; y++) { + for (pos_t z = nmin.Z; z <= nmax.Z; z++) + for (pos_t y = nmin.Y; y <= nmax.Y; y++) { u32 i = vm->m_area.index(nmin.X, y, z); - for (POS x = nmin.X; x <= nmax.X; x++) { + for (pos_t x = nmin.X; x <= nmax.X; x++) { if (vm->m_data[i].getContent() == dp.c_wall) { if (NoisePerlin3D(&dp.np_alt_wall, x, y, z, blockseed) > 0.0f) vm->m_data[i].setContent(dp.c_alt_wall); @@ -140,11 +140,11 @@ void DungeonGen::generate(MMVManip *vm, u32 bseed, v3POS nmin, v3POS nmax) } -void DungeonGen::makeDungeon(v3POS start_padding) +void DungeonGen::makeDungeon(v3pos_t start_padding) { - const v3POS &areasize = vm->m_area.getExtent(); - v3POS roomsize; - v3POS roomplace; + const v3pos_t &areasize = vm->m_area.getExtent(); + v3pos_t roomsize; + v3pos_t roomplace; /* Find place for first room. @@ -176,7 +176,7 @@ void DungeonGen::makeDungeon(v3POS start_padding) for (s16 z = 0; z < roomsize.Z; z++) for (s16 y = 0; y < roomsize.Y; y++) for (s16 x = 0; x < roomsize.X; x++) { - v3POS p = roomplace + v3POS(x, y, z); + v3pos_t p = roomplace + v3pos_t(x, y, z); u32 vi = vm->m_area.index(p); if ((vm->m_flags[vi] & VMANIP_FLAG_DUNGEON_UNTOUCHABLE) || vm->m_data[vi].getContent() == CONTENT_IGNORE) { @@ -194,13 +194,13 @@ void DungeonGen::makeDungeon(v3POS start_padding) a new corridor can be started from the last room instead of the new room, if chosen so. */ - v3POS last_room_center = roomplace + v3POS(roomsize.X / 2, 1, roomsize.Z / 2); + v3pos_t last_room_center = roomplace + v3pos_t(roomsize.X / 2, 1, roomsize.Z / 2); for (u32 i = 0; i < dp.num_rooms; i++) { // Make a room to the determined place makeRoom(roomsize, roomplace); - v3POS room_center = roomplace + v3POS(roomsize.X / 2, 1, roomsize.Z / 2); + v3pos_t room_center = roomplace + v3pos_t(roomsize.X / 2, 1, roomsize.Z / 2); if (gennotify) gennotify->addEvent(dp.notifytype, room_center); @@ -217,7 +217,7 @@ void DungeonGen::makeDungeon(v3POS start_padding) bool start_in_last_room = (random.range(0, 2) != 0); - v3POS walker_start_place; + v3pos_t walker_start_place; if (start_in_last_room) { walker_start_place = last_room_center; @@ -228,8 +228,8 @@ void DungeonGen::makeDungeon(v3POS start_padding) } // Create walker and find a place for a door - v3POS doorplace; - v3POS doordir; + v3pos_t doorplace; + v3pos_t doordir; m_pos = walker_start_place; if (!findPlaceForDoor(doorplace, doordir)) @@ -243,8 +243,8 @@ void DungeonGen::makeDungeon(v3POS start_padding) doorplace -= doordir; // Make a random corridor starting from the door - v3POS corridor_end; - v3POS corridor_end_dir; + v3pos_t corridor_end; + v3pos_t corridor_end_dir; makeCorridor(doorplace, doordir, corridor_end, corridor_end_dir); // Find a place for a random sized room @@ -274,7 +274,7 @@ void DungeonGen::makeDungeon(v3POS start_padding) } -void DungeonGen::makeRoom(v3POS roomsize, v3POS roomplace) +void DungeonGen::makeRoom(v3pos_t roomsize, v3pos_t roomplace) { MapNode n_wall(dp.c_wall); MapNode n_air(CONTENT_AIR); @@ -283,7 +283,7 @@ void DungeonGen::makeRoom(v3POS roomsize, v3POS roomplace) for (s16 z = 0; z < roomsize.Z; z++) for (s16 y = 0; y < roomsize.Y; y++) { { - v3POS p = roomplace + v3POS(0, y, z); + v3pos_t p = roomplace + v3pos_t(0, y, z); if (!vm->m_area.contains(p)) continue; u32 vi = vm->m_area.index(p); @@ -292,7 +292,7 @@ void DungeonGen::makeRoom(v3POS roomsize, v3POS roomplace) vm->m_data[vi] = n_wall; } { - v3POS p = roomplace + v3POS(roomsize.X - 1, y, z); + v3pos_t p = roomplace + v3pos_t(roomsize.X - 1, y, z); if (!vm->m_area.contains(p)) continue; u32 vi = vm->m_area.index(p); @@ -306,7 +306,7 @@ void DungeonGen::makeRoom(v3POS roomsize, v3POS roomplace) for (s16 x = 0; x < roomsize.X; x++) for (s16 y = 0; y < roomsize.Y; y++) { { - v3POS p = roomplace + v3POS(x, y, 0); + v3pos_t p = roomplace + v3pos_t(x, y, 0); if (!vm->m_area.contains(p)) continue; u32 vi = vm->m_area.index(p); @@ -315,7 +315,7 @@ void DungeonGen::makeRoom(v3POS roomsize, v3POS roomplace) vm->m_data[vi] = n_wall; } { - v3POS p = roomplace + v3POS(x, y, roomsize.Z - 1); + v3pos_t p = roomplace + v3pos_t(x, y, roomsize.Z - 1); if (!vm->m_area.contains(p)) continue; u32 vi = vm->m_area.index(p); @@ -329,7 +329,7 @@ void DungeonGen::makeRoom(v3POS roomsize, v3POS roomplace) for (s16 z = 0; z < roomsize.Z; z++) for (s16 x = 0; x < roomsize.X; x++) { { - v3POS p = roomplace + v3POS(x, 0, z); + v3pos_t p = roomplace + v3pos_t(x, 0, z); if (!vm->m_area.contains(p)) continue; u32 vi = vm->m_area.index(p); @@ -338,7 +338,7 @@ void DungeonGen::makeRoom(v3POS roomsize, v3POS roomplace) vm->m_data[vi] = n_wall; } { - v3POS p = roomplace + v3POS(x,roomsize. Y - 1, z); + v3pos_t p = roomplace + v3pos_t(x,roomsize. Y - 1, z); if (!vm->m_area.contains(p)) continue; u32 vi = vm->m_area.index(p); @@ -352,7 +352,7 @@ void DungeonGen::makeRoom(v3POS roomsize, v3POS roomplace) for (s16 z = 1; z < roomsize.Z - 1; z++) for (s16 y = 1; y < roomsize.Y - 1; y++) for (s16 x = 1; x < roomsize.X - 1; x++) { - v3POS p = roomplace + v3POS(x, y, z); + v3pos_t p = roomplace + v3pos_t(x, y, z); if (!vm->m_area.contains(p)) continue; u32 vi = vm->m_area.index(p); @@ -362,13 +362,13 @@ void DungeonGen::makeRoom(v3POS roomsize, v3POS roomplace) } -void DungeonGen::makeFill(v3POS place, v3POS size, +void DungeonGen::makeFill(v3pos_t place, v3pos_t size, u8 avoid_flags, MapNode n, u8 or_flags) { - for (POS z = 0; z < size.Z; z++) - for (POS y = 0; y < size.Y; y++) - for (POS x = 0; x < size.X; x++) { - v3POS p = place + v3POS(x, y, z); + for (pos_t z = 0; z < size.Z; z++) + for (pos_t y = 0; y < size.Y; y++) + for (pos_t x = 0; x < size.X; x++) { + v3pos_t p = place + v3pos_t(x, y, z); if (!vm->m_area.contains(p)) continue; u32 vi = vm->m_area.index(p); @@ -380,14 +380,14 @@ void DungeonGen::makeFill(v3POS place, v3POS size, } -void DungeonGen::makeHole(v3POS place) +void DungeonGen::makeHole(v3pos_t place) { makeFill(place, dp.holesize, 0, MapNode(CONTENT_AIR), VMANIP_FLAG_DUNGEON_INSIDE); } -void DungeonGen::makeDoor(v3POS doorplace, v3POS doordir) +void DungeonGen::makeDoor(v3pos_t doorplace, v3pos_t doordir) { makeHole(doorplace); @@ -398,12 +398,12 @@ void DungeonGen::makeDoor(v3POS doorplace, v3POS doordir) } -void DungeonGen::makeCorridor(v3POS doorplace, v3POS doordir, - v3POS &result_place, v3POS &result_dir) +void DungeonGen::makeCorridor(v3pos_t doorplace, v3pos_t doordir, + v3pos_t &result_place, v3pos_t &result_dir) { makeHole(doorplace); - v3POS p0 = doorplace; - v3POS dir = doordir; + v3pos_t p0 = doorplace; + v3pos_t dir = doordir; u32 length = random.range(dp.corridor_len_min, dp.corridor_len_max); u32 partlength = random.range(dp.corridor_len_min, dp.corridor_len_max); u32 partcount = 0; @@ -413,15 +413,15 @@ void DungeonGen::makeCorridor(v3POS doorplace, v3POS doordir, make_stairs = random.next() % 2 ? 1 : -1; for (u32 i = 0; i < length; i++) { - v3POS p = p0 + dir; + v3pos_t p = p0 + dir; if (partcount != 0) p.Y += make_stairs; // Check segment of minimum size corridor is in voxelmanip - if (vm->m_area.contains(p) && vm->m_area.contains(p + v3POS(0, 1, 0))) { + if (vm->m_area.contains(p) && vm->m_area.contains(p + v3pos_t(0, 1, 0))) { if (make_stairs) { - makeFill(p + v3POS(-1, -1, -1), - dp.holesize + v3POS(2, 3, 2), + makeFill(p + v3pos_t(-1, -1, -1), + dp.holesize + v3pos_t(2, 3, 2), VMANIP_FLAG_DUNGEON_UNTOUCHABLE, MapNode(dp.c_wall), 0); @@ -441,22 +441,22 @@ void DungeonGen::makeCorridor(v3POS doorplace, v3POS doordir, // rotate face 180 deg if // making stairs backwards int facedir = dir_to_facedir(dir * make_stairs); - v3POS ps = p; + v3pos_t ps = p; u16 stair_width = (dir.Z != 0) ? dp.holesize.X : dp.holesize.Z; // Stair width direction vector - v3POS swv = (dir.Z != 0) ? v3POS(1, 0, 0) : v3POS(0, 0, 1); + v3pos_t swv = (dir.Z != 0) ? v3pos_t(1, 0, 0) : v3pos_t(0, 0, 1); for (u16 st = 0; st < stair_width; st++) { if (make_stairs == -1) { u32 vi = vm->m_area.index(ps.X - dir.X, ps.Y - 1, ps.Z - dir.Z); - if (vm->m_area.contains(ps + v3POS(-dir.X, -1, -dir.Z)) && + if (vm->m_area.contains(ps + v3pos_t(-dir.X, -1, -dir.Z)) && vm->m_data[vi].getContent() == dp.c_wall) { vm->m_flags[vi] |= VMANIP_FLAG_DUNGEON_UNTOUCHABLE; vm->m_data[vi] = MapNode(dp.c_stair, 0, facedir); } } else if (make_stairs == 1) { u32 vi = vm->m_area.index(ps.X, ps.Y - 1, ps.Z); - if (vm->m_area.contains(ps + v3POS(0, -1, 0)) && + if (vm->m_area.contains(ps + v3pos_t(0, -1, 0)) && vm->m_data[vi].getContent() == dp.c_wall) { vm->m_flags[vi] |= VMANIP_FLAG_DUNGEON_UNTOUCHABLE; vm->m_data[vi] = MapNode(dp.c_stair, 0, facedir); @@ -466,8 +466,8 @@ void DungeonGen::makeCorridor(v3POS doorplace, v3POS doordir, } } } else { - makeFill(p + v3POS(-1, -1, -1), - dp.holesize + v3POS(2, 2, 2), + makeFill(p + v3pos_t(-1, -1, -1), + dp.holesize + v3pos_t(2, 2, 2), VMANIP_FLAG_DUNGEON_UNTOUCHABLE, MapNode(dp.c_wall), 0); @@ -502,11 +502,11 @@ void DungeonGen::makeCorridor(v3POS doorplace, v3POS doordir, } -bool DungeonGen::findPlaceForDoor(v3POS &result_place, v3POS &result_dir) +bool DungeonGen::findPlaceForDoor(v3pos_t &result_place, v3pos_t &result_dir) { for (u32 i = 0; i < 100; i++) { - v3POS p = m_pos + m_dir; - v3POS p1 = p + v3POS(0, 1, 0); + v3pos_t p = m_pos + m_dir; + v3pos_t p1 = p + v3pos_t(0, 1, 0); if (!vm->m_area.contains(p) || !vm->m_area.contains(p1) || i % 4 == 0) { randomizeDir(); continue; @@ -525,24 +525,24 @@ bool DungeonGen::findPlaceForDoor(v3POS &result_place, v3POS &result_dir) */ // Jump one up if the actual space is there if (vm->getNodeNoExNoEmerge(p + - v3POS(0, 0, 0)).getContent() == dp.c_wall && + v3pos_t(0, 0, 0)).getContent() == dp.c_wall && vm->getNodeNoExNoEmerge(p + - v3POS(0, 1, 0)).getContent() == CONTENT_AIR && + v3pos_t(0, 1, 0)).getContent() == CONTENT_AIR && vm->getNodeNoExNoEmerge(p + - v3POS(0, 2, 0)).getContent() == CONTENT_AIR) - p += v3POS(0,1,0); + v3pos_t(0, 2, 0)).getContent() == CONTENT_AIR) + p += v3pos_t(0,1,0); // Jump one down if the actual space is there if (vm->getNodeNoExNoEmerge(p + - v3POS(0, 1, 0)).getContent() == dp.c_wall && + v3pos_t(0, 1, 0)).getContent() == dp.c_wall && vm->getNodeNoExNoEmerge(p + - v3POS(0, 0, 0)).getContent() == CONTENT_AIR && + v3pos_t(0, 0, 0)).getContent() == CONTENT_AIR && vm->getNodeNoExNoEmerge(p + - v3POS(0, -1, 0)).getContent() == CONTENT_AIR) - p += v3POS(0, -1, 0); + v3pos_t(0, -1, 0)).getContent() == CONTENT_AIR) + p += v3pos_t(0, -1, 0); // Check if walking is now possible if (vm->getNodeNoExNoEmerge(p).getContent() != CONTENT_AIR || vm->getNodeNoExNoEmerge(p + - v3POS(0, 1, 0)).getContent() != CONTENT_AIR) { + v3pos_t(0, 1, 0)).getContent() != CONTENT_AIR) { // Cannot continue walking here randomizeDir(); continue; @@ -554,36 +554,36 @@ bool DungeonGen::findPlaceForDoor(v3POS &result_place, v3POS &result_dir) } -bool DungeonGen::findPlaceForRoomDoor(v3POS roomsize, v3POS &result_doorplace, - v3POS &result_doordir, v3POS &result_roomplace) +bool DungeonGen::findPlaceForRoomDoor(v3pos_t roomsize, v3pos_t &result_doorplace, + v3pos_t &result_doordir, v3pos_t &result_roomplace) { for (s16 trycount = 0; trycount < 30; trycount++) { - v3POS doorplace; - v3POS doordir; + v3pos_t doorplace; + v3pos_t doordir; bool r = findPlaceForDoor(doorplace, doordir); if (!r) continue; - v3POS roomplace; + v3pos_t roomplace; // X east, Z north, Y up - if (doordir == v3POS(1, 0, 0)) // X+ + if (doordir == v3pos_t(1, 0, 0)) // X+ roomplace = doorplace + - v3POS(0, -1, random.range(-roomsize.Z + 2, -2)); - if (doordir == v3POS(-1, 0, 0)) // X- + v3pos_t(0, -1, random.range(-roomsize.Z + 2, -2)); + if (doordir == v3pos_t(-1, 0, 0)) // X- roomplace = doorplace + - v3POS(-roomsize.X + 1, -1, random.range(-roomsize.Z + 2, -2)); - if (doordir == v3POS(0, 0, 1)) // Z+ + v3pos_t(-roomsize.X + 1, -1, random.range(-roomsize.Z + 2, -2)); + if (doordir == v3pos_t(0, 0, 1)) // Z+ roomplace = doorplace + - v3POS(random.range(-roomsize.X + 2, -2), -1, 0); - if (doordir == v3POS(0, 0, -1)) // Z- + v3pos_t(random.range(-roomsize.X + 2, -2), -1, 0); + if (doordir == v3pos_t(0, 0, -1)) // Z- roomplace = doorplace + - v3POS(random.range(-roomsize.X + 2, -2), -1, -roomsize.Z + 1); + v3pos_t(random.range(-roomsize.X + 2, -2), -1, -roomsize.Z + 1); // Check fit bool fits = true; for (s16 z = 1; z < roomsize.Z - 1; z++) for (s16 y = 1; y < roomsize.Y - 1; y++) for (s16 x = 1; x < roomsize.X - 1; x++) { - v3POS p = roomplace + v3POS(x, y, z); + v3pos_t p = roomplace + v3pos_t(x, y, z); if (!vm->m_area.contains(p)) { fits = false; break; @@ -606,11 +606,11 @@ bool DungeonGen::findPlaceForRoomDoor(v3POS roomsize, v3POS &result_doorplace, } -v3POS rand_ortho_dir(PseudoRandom &random, bool diagonal_dirs) +v3pos_t rand_ortho_dir(PseudoRandom &random, bool diagonal_dirs) { // Make diagonal directions somewhat rare if (diagonal_dirs && (random.next() % 4 == 0)) { - v3POS dir; + v3pos_t dir; int trycount = 0; do { @@ -625,15 +625,15 @@ v3POS rand_ortho_dir(PseudoRandom &random, bool diagonal_dirs) } if (random.next() % 2 == 0) - return random.next() % 2 ? v3POS(-1, 0, 0) : v3POS(1, 0, 0); + return random.next() % 2 ? v3pos_t(-1, 0, 0) : v3pos_t(1, 0, 0); - return random.next() % 2 ? v3POS(0, 0, -1) : v3POS(0, 0, 1); + return random.next() % 2 ? v3pos_t(0, 0, -1) : v3pos_t(0, 0, 1); } -v3POS turn_xz(v3POS olddir, int t) +v3pos_t turn_xz(v3pos_t olddir, int t) { - v3POS dir; + v3pos_t dir; if (t == 0) { // Turn right dir.X = olddir.Z; @@ -649,7 +649,7 @@ v3POS turn_xz(v3POS olddir, int t) } -void random_turn(PseudoRandom &random, v3POS &dir) +void random_turn(PseudoRandom &random, v3pos_t &dir) { int turn = random.range(0, 2); if (turn == 0) { @@ -665,7 +665,7 @@ void random_turn(PseudoRandom &random, v3POS &dir) } -int dir_to_facedir(v3POS d) +int dir_to_facedir(v3pos_t d) { if (abs(d.X) > abs(d.Z)) return d.X < 0 ? 3 : 1; diff --git a/src/mapgen/dungeongen.h b/src/mapgen/dungeongen.h index 631d636fad..3f83927ee2 100644 --- a/src/mapgen/dungeongen.h +++ b/src/mapgen/dungeongen.h @@ -32,10 +32,10 @@ with this program; if not, write to the Free Software Foundation, Inc., class MMVManip; class NodeDefManager; -v3POS rand_ortho_dir(PseudoRandom &random, bool diagonal_dirs); -v3POS turn_xz(v3POS olddir, int t); -void random_turn(PseudoRandom &random, v3POS &dir); -int dir_to_facedir(v3POS d); +v3pos_t rand_ortho_dir(PseudoRandom &random, bool diagonal_dirs); +v3pos_t turn_xz(v3pos_t olddir, int t); +void random_turn(PseudoRandom &random, v3pos_t &dir); +int dir_to_facedir(v3pos_t d); struct DungeonParams { @@ -57,11 +57,11 @@ struct DungeonParams { // Number of rooms u16 num_rooms; // Room size random range. Includes walls / floor / ceilng - v3POS room_size_min; - v3POS room_size_max; + v3pos_t room_size_min; + v3pos_t room_size_max; // Large room size random range. Includes walls / floor / ceilng - v3POS room_size_large_min; - v3POS room_size_large_max; + v3pos_t room_size_large_min; + v3pos_t room_size_large_max; // Value 0 disables large rooms. // Value 1 results in 1 large room, the first generated room. // Value > 1 makes the first generated room large, all other rooms have a @@ -71,7 +71,7 @@ struct DungeonParams { // Dimensions are of the empty space, not including walls / floor / ceilng. // Diagonal corridors must have hole width >=2 to be passable. // Currently, hole width >= 3 causes stair corridor bugs. - v3POS holesize; + v3pos_t holesize; // Corridor length random range u16 corridor_len_min; u16 corridor_len_max; @@ -90,31 +90,31 @@ class DungeonGen { u32 blockseed; PseudoRandom random; - v3POS csize; + v3pos_t csize; content_t c_torch; DungeonParams dp; // RoomWalker - v3POS m_pos; - v3POS m_dir; + v3pos_t m_pos; + v3pos_t m_dir; DungeonGen(const NodeDefManager *ndef, GenerateNotifier *gennotify, DungeonParams *dparams); - void generate(MMVManip *vm, u32 bseed, v3POS full_node_min, v3POS full_node_max); + void generate(MMVManip *vm, u32 bseed, v3pos_t full_node_min, v3pos_t full_node_max); - void makeDungeon(v3POS start_padding); - void makeRoom(v3POS roomsize, v3POS roomplace); - void makeCorridor(v3POS doorplace, v3POS doordir, - v3POS &result_place, v3POS &result_dir); - void makeDoor(v3POS doorplace, v3POS doordir); - void makeFill(v3POS place, v3POS size, u8 avoid_flags, MapNode n, u8 or_flags); - void makeHole(v3POS place); + void makeDungeon(v3pos_t start_padding); + void makeRoom(v3pos_t roomsize, v3pos_t roomplace); + void makeCorridor(v3pos_t doorplace, v3pos_t doordir, + v3pos_t &result_place, v3pos_t &result_dir); + void makeDoor(v3pos_t doorplace, v3pos_t doordir); + void makeFill(v3pos_t place, v3pos_t size, u8 avoid_flags, MapNode n, u8 or_flags); + void makeHole(v3pos_t place); - bool findPlaceForDoor(v3POS &result_place, v3POS &result_dir); - bool findPlaceForRoomDoor(v3POS roomsize, v3POS &result_doorplace, - v3POS &result_doordir, v3POS &result_roomplace); + bool findPlaceForDoor(v3pos_t &result_place, v3pos_t &result_dir); + bool findPlaceForRoomDoor(v3pos_t roomsize, v3pos_t &result_doorplace, + v3pos_t &result_doordir, v3pos_t &result_roomplace); inline void randomizeDir() { diff --git a/src/mapgen/mapgen.cpp b/src/mapgen/mapgen.cpp index 10773a293a..e68cf04429 100644 --- a/src/mapgen/mapgen.cpp +++ b/src/mapgen/mapgen.cpp @@ -114,7 +114,7 @@ Mapgen::Mapgen(int mapgenid, MapgenParams *params, EmergeParams *emerge) : water_level = params->water_level; mapgen_limit = params->mapgen_limit; flags = params->flags; - csize = v3POS(1, 1, 1) * (params->chunksize * MAP_BLOCKSIZE); + csize = v3pos_t(1, 1, 1) * (params->chunksize * MAP_BLOCKSIZE); /* We are losing half our entropy by doing this, but it is necessary to @@ -227,7 +227,7 @@ void Mapgen::setDefaultSettings(Settings *settings) } } -u32 Mapgen::getBlockSeed(v3POS p, s32 seed) +u32 Mapgen::getBlockSeed(v3pos_t p, s32 seed) { return (u32)seed + p.Z * 38134234 + @@ -236,7 +236,7 @@ u32 Mapgen::getBlockSeed(v3POS p, s32 seed) } -u32 Mapgen::getBlockSeed2(v3POS p, s32 seed) +u32 Mapgen::getBlockSeed2(v3pos_t p, s32 seed) { u32 n = 1619 * p.X + 31337 * p.Y + 52591 * p.Z + 1013 * seed; n = (n >> 13) ^ n; @@ -245,11 +245,11 @@ u32 Mapgen::getBlockSeed2(v3POS p, s32 seed) // Returns -MAX_MAP_GENERATION_LIMIT if not found -POS Mapgen::findGroundLevel(v2POS p2d, POS ymin, POS ymax) +pos_t Mapgen::findGroundLevel(v2pos_t p2d, pos_t ymin, pos_t ymax) { - const v3POS &em = vm->m_area.getExtent(); + const v3pos_t &em = vm->m_area.getExtent(); u32 i = vm->m_area.index(p2d.X, ymax, p2d.Y); - POS y; + pos_t y; for (y = ymax; y >= ymin; y--) { MapNode &n = vm->m_data[i]; @@ -263,11 +263,11 @@ POS Mapgen::findGroundLevel(v2POS p2d, POS ymin, POS ymax) // Returns -MAX_MAP_GENERATION_LIMIT if not found or if ground is found first -POS Mapgen::findLiquidSurface(v2POS p2d, POS ymin, POS ymax) +pos_t Mapgen::findLiquidSurface(v2pos_t p2d, pos_t ymin, pos_t ymax) { - const v3POS &em = vm->m_area.getExtent(); + const v3pos_t &em = vm->m_area.getExtent(); u32 i = vm->m_area.index(p2d.X, ymax, p2d.Y); - POS y; + pos_t y; for (y = ymax; y >= ymin; y--) { MapNode &n = vm->m_data[i]; @@ -283,16 +283,16 @@ POS Mapgen::findLiquidSurface(v2POS p2d, POS ymin, POS ymax) } -void Mapgen::updateHeightmap(v3POS nmin, v3POS nmax) +void Mapgen::updateHeightmap(v3pos_t nmin, v3pos_t nmax) { if (!heightmap) return; //TimeTaker t("Mapgen::updateHeightmap", NULL, PRECISION_MICRO); int index = 0; - for (POS z = nmin.Z; z <= nmax.Z; z++) { - for (POS x = nmin.X; x <= nmax.X; x++, index++) { - POS y = findGroundLevel(v2POS(x, z), nmin.Y, nmax.Y); + for (pos_t z = nmin.Z; z <= nmax.Z; z++) { + for (pos_t x = nmin.X; x <= nmax.X; x++, index++) { + pos_t y = findGroundLevel(v2pos_t(x, z), nmin.Y, nmax.Y); heightmap[index] = y; } @@ -300,10 +300,10 @@ void Mapgen::updateHeightmap(v3POS nmin, v3POS nmax) } -void Mapgen::getSurfaces(v2POS p2d, POS ymin, POS ymax, - std::vector &floors, std::vector &ceilings) +void Mapgen::getSurfaces(v2pos_t p2d, pos_t ymin, pos_t ymax, + std::vector &floors, std::vector &ceilings) { - const v3POS &em = vm->m_area.getExtent(); + const v3pos_t &em = vm->m_area.getExtent(); bool is_walkable = false; u32 vi = vm->m_area.index(p2d.X, ymax, p2d.Y); @@ -311,7 +311,7 @@ void Mapgen::getSurfaces(v2POS p2d, POS ymin, POS ymax, bool walkable_above = ndef->get(mn_max).walkable; VoxelArea::add_y(em, vi, -1); - for (POS y = ymax - 1; y >= ymin; y--) { + for (pos_t y = ymax - 1; y >= ymin; y--) { MapNode mn = vm->m_data[vi]; is_walkable = ndef->get(mn).walkable; @@ -327,7 +327,7 @@ void Mapgen::getSurfaces(v2POS p2d, POS ymin, POS ymax, } -inline bool Mapgen::isLiquidHorizontallyFlowable(u32 vi, v3POS em) +inline bool Mapgen::isLiquidHorizontallyFlowable(u32 vi, v3pos_t em) { u32 vi_neg_x = vi; VoxelArea::add_x(em, vi_neg_x, -1); @@ -360,20 +360,20 @@ inline bool Mapgen::isLiquidHorizontallyFlowable(u32 vi, v3POS em) return false; } -void Mapgen::updateLiquid(UniqueQueue *trans_liquid, v3POS nmin, v3POS nmax) +void Mapgen::updateLiquid(UniqueQueue *trans_liquid, v3pos_t nmin, v3pos_t nmax) { bool isignored, isliquid, wasignored, wasliquid, waschecked, waspushed; - const v3POS &em = vm->m_area.getExtent(); + const v3pos_t &em = vm->m_area.getExtent(); - for (POS z = nmin.Z + 1; z <= nmax.Z - 1; z++) - for (POS x = nmin.X + 1; x <= nmax.X - 1; x++) { + for (pos_t z = nmin.Z + 1; z <= nmax.Z - 1; z++) + for (pos_t x = nmin.X + 1; x <= nmax.X - 1; x++) { wasignored = true; wasliquid = false; waschecked = false; waspushed = false; u32 vi = vm->m_area.index(x, nmax.Y, z); - for (POS y = nmax.Y; y >= nmin.Y; y--) { + for (pos_t y = nmax.Y; y >= nmin.Y; y--) { isignored = vm->m_data[vi].getContent() == CONTENT_IGNORE; isliquid = ndef->get(vm->m_data[vi]).isLiquid(); @@ -385,7 +385,7 @@ void Mapgen::updateLiquid(UniqueQueue *trans_liquid, v3POS nmin, v3POS nm // This is the topmost node in the column bool ispushed = false; if (isLiquidHorizontallyFlowable(vi, em)) { - trans_liquid->push_back(v3POS(x, y, z)); + trans_liquid->push_back(v3pos_t(x, y, z)); ispushed = true; } // Remember waschecked and waspushed to avoid repeated @@ -400,7 +400,7 @@ void Mapgen::updateLiquid(UniqueQueue *trans_liquid, v3POS nmin, v3POS nm (!waschecked && isLiquidHorizontallyFlowable(vi_above, em)))) { // Push back the lowest node in the column which is one // node above this one - trans_liquid->push_back(v3POS(x, y + 1, z)); + trans_liquid->push_back(v3pos_t(x, y + 1, z)); } } @@ -412,7 +412,7 @@ void Mapgen::updateLiquid(UniqueQueue *trans_liquid, v3POS nmin, v3POS nm } -void Mapgen::setLighting(u8 light, v3POS nmin, v3POS nmax) +void Mapgen::setLighting(u8 light, v3pos_t nmin, v3pos_t nmax) { ScopeProfiler sp(g_profiler, "EmergeThread: update lighting", SPT_AVG); VoxelArea a(nmin, nmax); @@ -427,8 +427,8 @@ void Mapgen::setLighting(u8 light, v3POS nmin, v3POS nmax) } -void Mapgen::lightSpread(VoxelArea &a, std::queue> &queue, - const v3POS &p, u8 light) +void Mapgen::lightSpread(VoxelArea &a, std::queue> &queue, + const v3pos_t &p, u8 light) { if (light <= 1 || !a.contains(p)) return; @@ -465,7 +465,7 @@ void Mapgen::lightSpread(VoxelArea &a, std::queue> &queue, } -void Mapgen::calcLighting(v3POS nmin, v3POS nmax, v3POS full_nmin, v3POS full_nmax, +void Mapgen::calcLighting(v3pos_t nmin, v3pos_t nmax, v3pos_t full_nmin, v3pos_t full_nmax, bool propagate_shadow) { ScopeProfiler sp(g_profiler, "EmergeThread: update lighting", SPT_AVG); @@ -478,12 +478,12 @@ void Mapgen::calcLighting(v3POS nmin, v3POS nmax, v3POS full_nmin, v3POS full_nm } -void Mapgen::propagateSunlight(v3POS nmin, v3POS nmax, bool propagate_shadow) +void Mapgen::propagateSunlight(v3pos_t nmin, v3pos_t nmax, bool propagate_shadow) { //TimeTaker t("propagateSunlight"); VoxelArea a(nmin, nmax); bool block_is_underground = (water_level >= nmax.Y); - const v3POS &em = vm->m_area.getExtent(); + const v3pos_t &em = vm->m_area.getExtent(); // NOTE: Direct access to the low 4 bits of param1 is okay here because, // by definition, sunlight will never be in the night lightbank. @@ -514,10 +514,10 @@ void Mapgen::propagateSunlight(v3POS nmin, v3POS nmax, bool propagate_shadow) } -void Mapgen::spreadLight(const v3POS &nmin, const v3POS &nmax) +void Mapgen::spreadLight(const v3pos_t &nmin, const v3pos_t &nmax) { //TimeTaker t("spreadLight"); - std::queue> queue; + std::queue> queue; VoxelArea a(nmin, nmax); for (int z = a.MinEdge.Z; z <= a.MaxEdge.Z; z++) { @@ -541,7 +541,7 @@ void Mapgen::spreadLight(const v3POS &nmin, const v3POS &nmax) u8 light = n.param1; if (light) { - const v3POS p(x, y, z); + const v3pos_t p(x, y, z); // spread to all 6 neighbor nodes for (const auto &dir : g_6dirs) lightSpread(a, queue, p + dir, light); @@ -592,7 +592,7 @@ MapgenBasic::MapgenBasic(int mapgenid, MapgenParams *params, EmergeParams *emerg this->zstride_1u1d = csize.X * (csize.Y + 2); //// Allocate heightmap - this->heightmap = new POS[csize.X * csize.Z]; + this->heightmap = new pos_t[csize.X * csize.Z]; //// Initialize biome generator biomegen = emerge->biomegen; @@ -634,20 +634,20 @@ void MapgenBasic::generateBiomes() assert(biomegen); assert(biomemap); - const v3POS &em = vm->m_area.getExtent(); + const v3pos_t &em = vm->m_area.getExtent(); u32 index = 0; noise_filler_depth->perlinMap2D(node_min.X, node_min.Z); - for (POS z = node_min.Z; z <= node_max.Z; z++) - for (POS x = node_min.X; x <= node_max.X; x++, index++) { + for (pos_t z = node_min.Z; z <= node_max.Z; z++) + for (pos_t x = node_min.X; x <= node_max.X; x++, index++) { Biome *biome = NULL; biome_t water_biome_index = 0; - POS depth_top = 0; + pos_t depth_top = 0; u16 base_filler = 0; u16 depth_water_top = 0; u16 depth_riverbed = 0; - POS biome_y_min = -MAX_MAP_GENERATION_LIMIT; + pos_t biome_y_min = -MAX_MAP_GENERATION_LIMIT; u32 vi = vm->m_area.index(x, node_max.Y, z); // Check node at base of mapchunk above, either a node of a previously @@ -663,7 +663,7 @@ void MapgenBasic::generateBiomes() // nplaced to stone level by setting a number exceeding any possible filler depth. u16 nplaced = (air_above || water_above) ? 0 : U16_MAX; - for (POS y = node_max.Y; y >= node_min.Y; y--) { + for (pos_t y = node_max.Y; y >= node_min.Y; y--) { content_t c = vm->m_data[vi].getContent(); // Biome is (re)calculated: // 1. At the surface of stone below air or water. @@ -679,7 +679,7 @@ void MapgenBasic::generateBiomes() if (is_stone_surface || is_water_surface) { // (Re)calculate biome - biome = biomegen->getBiomeAtIndex(index, v3POS(x, y, z)); + biome = biomegen->getBiomeAtIndex(index, v3pos_t(x, y, z)); // Add biome to biomemap at first stone surface detected if (biomemap[index] == BIOME_NONE && is_stone_surface) @@ -770,11 +770,11 @@ void MapgenBasic::dustTopNodes() if (node_max.Y < water_level) return; - const v3POS &em = vm->m_area.getExtent(); + const v3pos_t &em = vm->m_area.getExtent(); u32 index = 0; - for (POS z = node_min.Z; z <= node_max.Z; z++) - for (POS x = node_min.X; x <= node_max.X; x++, index++) { + for (pos_t z = node_min.Z; z <= node_max.Z; z++) + for (pos_t x = node_min.X; x <= node_max.X; x++, index++) { Biome *biome = (Biome *)m_bmgr->getRaw(biomemap[index]); if (biome->c_dust == CONTENT_IGNORE) @@ -786,7 +786,7 @@ void MapgenBasic::dustTopNodes() // will provide this required dust when it does. u32 vi = vm->m_area.index(x, full_node_max.Y, z); content_t c_full_max = vm->m_data[vi].getContent(); - POS y_start; + pos_t y_start; if (c_full_max == CONTENT_AIR) { y_start = full_node_max.Y - 1; @@ -803,7 +803,7 @@ void MapgenBasic::dustTopNodes() } vi = vm->m_area.index(x, y_start, z); - for (POS y = y_start; y >= node_min.Y - 1; y--) { + for (pos_t y = y_start; y >= node_min.Y - 1; y--) { if (vm->m_data[vi].getContent() != CONTENT_AIR) break; @@ -829,7 +829,7 @@ void MapgenBasic::dustTopNodes() } -void MapgenBasic::generateCavesNoiseIntersection(POS max_stone_y) +void MapgenBasic::generateCavesNoiseIntersection(pos_t max_stone_y) { // cave_width >= 10 is used to disable generation and avoid the intensive // 3D noise calculations. Tunnels already have zero width when cave_width > 1. @@ -843,7 +843,7 @@ void MapgenBasic::generateCavesNoiseIntersection(POS max_stone_y) } -void MapgenBasic::generateCavesRandomWalk(POS max_stone_y, POS large_cave_ymax) +void MapgenBasic::generateCavesRandomWalk(pos_t max_stone_y, pos_t large_cave_ymax) { if (node_min.Y > max_stone_y) return; @@ -874,7 +874,7 @@ void MapgenBasic::generateCavesRandomWalk(POS max_stone_y, POS large_cave_ymax) } -bool MapgenBasic::generateCavernsNoise(POS max_stone_y) +bool MapgenBasic::generateCavernsNoise(pos_t max_stone_y) { if (node_min.Y > max_stone_y || node_min.Y > cavern_limit) return false; @@ -886,7 +886,7 @@ bool MapgenBasic::generateCavernsNoise(POS max_stone_y) } -void MapgenBasic::generateDungeons(POS max_stone_y) +void MapgenBasic::generateDungeons(pos_t max_stone_y) { if (node_min.Y > max_stone_y || node_min.Y > dungeon_ymax || node_max.Y < dungeon_ymin) @@ -909,20 +909,20 @@ void MapgenBasic::generateDungeons(POS max_stone_y) dp.num_dungeons = num_dungeons; dp.notifytype = GENNOTIFY_DUNGEON; dp.num_rooms = ps.range(2, 16); - dp.room_size_min = v3POS(5, 5, 5); - dp.room_size_max = v3POS(12, 6, 12); - dp.room_size_large_min = v3POS(12, 6, 12); - dp.room_size_large_max = v3POS(16, 16, 16); + dp.room_size_min = v3pos_t(5, 5, 5); + dp.room_size_max = v3pos_t(12, 6, 12); + dp.room_size_large_min = v3pos_t(12, 6, 12); + dp.room_size_large_max = v3pos_t(16, 16, 16); dp.large_room_chance = (ps.range(1, 4) == 1) ? 8 : 0; dp.diagonal_dirs = ps.range(1, 8) == 1; // Diagonal corridors must have 'hole' width >=2 to be passable u8 holewidth = (dp.diagonal_dirs) ? 2 : ps.range(1, 2); - dp.holesize = v3POS(holewidth, 3, holewidth); + dp.holesize = v3pos_t(holewidth, 3, holewidth); dp.corridor_len_min = 1; dp.corridor_len_max = 13; // Get biome at mapchunk midpoint - v3POS chunk_mid = node_min + (node_max - node_min) / v3POS(2, 2, 2); + v3pos_t chunk_mid = node_min + (node_max - node_min) / v3pos_t(2, 2, 2); Biome *biome = (Biome *)biomegen->getBiomeAtPoint(chunk_mid); // Use biome-defined dungeon nodes if defined @@ -964,7 +964,7 @@ GenerateNotifier::GenerateNotifier(u32 notify_on, } -bool GenerateNotifier::addEvent(GenNotifyType type, v3POS pos, u32 id) +bool GenerateNotifier::addEvent(GenNotifyType type, v3pos_t pos, u32 id) { if (!(m_notify_on & (1 << type))) return false; @@ -984,7 +984,7 @@ bool GenerateNotifier::addEvent(GenNotifyType type, v3POS pos, u32 id) void GenerateNotifier::getEvents( - std::map > &event_map) + std::map > &event_map) { std::list::iterator it; @@ -1078,16 +1078,16 @@ void MapgenParams::calcMapgenEdges() s16 ccfmin = ccmin - MAP_BLOCKSIZE; s16 ccfmax = ccmax + MAP_BLOCKSIZE; // Effective mapgen limit, in blocks - // Uses same calculation as ServerMap::blockpos_over_mapgen_limit(v3POS p) - POS mapgen_limit_b = rangelim(mapgen_limit, + // Uses same calculation as ServerMap::blockpos_over_mapgen_limit(v3pos_t p) + pos_t mapgen_limit_b = rangelim(mapgen_limit, 0, MAX_MAP_GENERATION_LIMIT) / MAP_BLOCKSIZE; // Effective mapgen limits, in nodes - POS mapgen_limit_min = -mapgen_limit_b * MAP_BLOCKSIZE; - POS mapgen_limit_max = (mapgen_limit_b + 1) * MAP_BLOCKSIZE - 1; + pos_t mapgen_limit_min = -mapgen_limit_b * MAP_BLOCKSIZE; + pos_t mapgen_limit_max = (mapgen_limit_b + 1) * MAP_BLOCKSIZE - 1; // Number of complete chunks from central chunk fullminp/fullmaxp // to effective mapgen limits. - POS numcmin = MYMAX((ccfmin - mapgen_limit_min) / csize_n, 0); - POS numcmax = MYMAX((mapgen_limit_max - ccfmax) / csize_n, 0); + pos_t numcmin = MYMAX((ccfmin - mapgen_limit_min) / csize_n, 0); + pos_t numcmax = MYMAX((mapgen_limit_max - ccfmax) / csize_n, 0); // Mapgen edges, in nodes mapgen_edge_min = ccmin - numcmin * csize_n; mapgen_edge_max = ccmax + numcmax * csize_n; diff --git a/src/mapgen/mapgen.h b/src/mapgen/mapgen.h index 6df2119ad0..d045681894 100644 --- a/src/mapgen/mapgen.h +++ b/src/mapgen/mapgen.h @@ -80,7 +80,7 @@ enum GenNotifyType { struct GenNotifyEvent { GenNotifyType type; - v3POS pos; + v3pos_t pos; u32 id; }; @@ -90,8 +90,8 @@ class GenerateNotifier { GenerateNotifier() = default; GenerateNotifier(u32 notify_on, const std::set *notify_on_deco_ids); - bool addEvent(GenNotifyType type, v3POS pos, u32 id=0); - void getEvents(std::map > &event_map); + bool addEvent(GenNotifyType type, v3pos_t pos, u32 id=0); + void getEvents(std::map > &event_map); void clearEvents(); private: @@ -120,16 +120,16 @@ struct MapgenParams { MapgenType mgtype = MAPGEN_DEFAULT; s16 chunksize = 5; u64 seed = 0; - POS water_level = 1; - POS mapgen_limit = MAX_MAP_GENERATION_LIMIT; + pos_t water_level = 1; + pos_t mapgen_limit = MAX_MAP_GENERATION_LIMIT; // Flags set in readParams u32 flags = 0; u32 spflags = 0; BiomeParams *bparams = nullptr; - POS mapgen_edge_min = -MAX_MAP_GENERATION_LIMIT; - POS mapgen_edge_max = MAX_MAP_GENERATION_LIMIT; + pos_t mapgen_edge_min = -MAX_MAP_GENERATION_LIMIT; + pos_t mapgen_edge_max = MAX_MAP_GENERATION_LIMIT; virtual void readParams(const Settings *settings); virtual void writeParams(Settings *settings) const; @@ -166,9 +166,9 @@ class Mapgen { const NodeDefManager *ndef = nullptr; u32 blockseed; - POS *heightmap = nullptr; + pos_t *heightmap = nullptr; biome_t *biomemap = nullptr; - v3POS csize; + v3pos_t csize; BiomeGen *biomegen = nullptr; GenerateNotifier gennotify; @@ -180,33 +180,33 @@ class Mapgen { virtual MapgenType getType() const { return MAPGEN_INVALID; } - static u32 getBlockSeed(v3POS p, s32 seed); - static u32 getBlockSeed2(v3POS p, s32 seed); - POS findGroundLevel(v2POS p2d, POS ymin, POS ymax); - POS findLiquidSurface(v2POS p2d, POS ymin, POS ymax); - void updateHeightmap(v3POS nmin, v3POS nmax); - void getSurfaces(v2POS p2d, POS ymin, POS ymax, - std::vector &floors, std::vector &ceilings); + static u32 getBlockSeed(v3pos_t p, s32 seed); + static u32 getBlockSeed2(v3pos_t p, s32 seed); + pos_t findGroundLevel(v2pos_t p2d, pos_t ymin, pos_t ymax); + pos_t findLiquidSurface(v2pos_t p2d, pos_t ymin, pos_t ymax); + void updateHeightmap(v3pos_t nmin, v3pos_t nmax); + void getSurfaces(v2pos_t p2d, pos_t ymin, pos_t ymax, + std::vector &floors, std::vector &ceilings); - void updateLiquid(UniqueQueue *trans_liquid, v3POS nmin, v3POS nmax); + void updateLiquid(UniqueQueue *trans_liquid, v3pos_t nmin, v3pos_t nmax); - void setLighting(u8 light, v3POS nmin, v3POS nmax); - void lightSpread(VoxelArea &a, std::queue> &queue, - const v3POS &p, u8 light); - void calcLighting(v3POS nmin, v3POS nmax, v3POS full_nmin, v3POS full_nmax, + void setLighting(u8 light, v3pos_t nmin, v3pos_t nmax); + void lightSpread(VoxelArea &a, std::queue> &queue, + const v3pos_t &p, u8 light); + void calcLighting(v3pos_t nmin, v3pos_t nmax, v3pos_t full_nmin, v3pos_t full_nmax, bool propagate_shadow = true); - void propagateSunlight(v3POS nmin, v3POS nmax, bool propagate_shadow); - void spreadLight(const v3POS &nmin, const v3POS &nmax); + void propagateSunlight(v3pos_t nmin, v3pos_t nmax, bool propagate_shadow); + void spreadLight(const v3pos_t &nmin, const v3pos_t &nmax); virtual void makeChunk(BlockMakeData *data) {} - virtual int getGroundLevelAtPoint(v2POS p) { return 0; } + virtual int getGroundLevelAtPoint(v2pos_t p) { return 0; } // getSpawnLevelAtPoint() is a function within each mapgen that returns a // suitable y co-ordinate for player spawn ('suitable' usually meaning // within 16 nodes of water_level). If a suitable spawn level cannot be // found at the specified (X, Z) 'MAX_MAP_GENERATION_LIMIT' is returned to // signify this and to cause Server::findSpawnPos() to try another (X, Z). - virtual int getSpawnLevelAtPoint(v2POS p) { return 0; } + virtual int getSpawnLevelAtPoint(v2pos_t p) { return 0; } // Mapgen management functions static MapgenType getMapgenType(const std::string &mgname); @@ -221,7 +221,7 @@ class Mapgen { // isLiquidHorizontallyFlowable() is a helper function for updateLiquid() // that checks whether there are floodable nodes without liquid beneath // the node at index vi. - inline bool isLiquidHorizontallyFlowable(u32 vi, v3POS em); + inline bool isLiquidHorizontallyFlowable(u32 vi, v3pos_t em); }; /* @@ -245,10 +245,10 @@ class MapgenBasic : public Mapgen { virtual void generateBiomes(); virtual void dustTopNodes(); - virtual void generateCavesNoiseIntersection(POS max_stone_y); - virtual void generateCavesRandomWalk(POS max_stone_y, POS large_cave_ymax); - virtual bool generateCavernsNoise(POS max_stone_y); - virtual void generateDungeons(POS max_stone_y); + virtual void generateCavesNoiseIntersection(pos_t max_stone_y); + virtual void generateCavesRandomWalk(pos_t max_stone_y, pos_t large_cave_ymax); + virtual bool generateCavernsNoise(pos_t max_stone_y); + virtual void generateDungeons(pos_t max_stone_y); protected: EmergeParams *m_emerge; @@ -256,10 +256,10 @@ class MapgenBasic : public Mapgen { Noise *noise_filler_depth; - v3POS node_min; - v3POS node_max; - v3POS full_node_min; - v3POS full_node_max; + v3pos_t node_min; + v3pos_t node_max; + v3pos_t full_node_min; + v3pos_t full_node_max; content_t c_stone; content_t c_water_source; @@ -287,7 +287,7 @@ class MapgenBasic : public Mapgen { int large_cave_num_min; int large_cave_num_max; float large_cave_flooded; - POS large_cave_depth; - POS dungeon_ymin; - POS dungeon_ymax; + pos_t large_cave_depth; + pos_t dungeon_ymin; + pos_t dungeon_ymax; }; diff --git a/src/mapgen/mapgen_carpathian.cpp b/src/mapgen/mapgen_carpathian.cpp index 9f47e1de19..4d1bca500e 100644 --- a/src/mapgen/mapgen_carpathian.cpp +++ b/src/mapgen/mapgen_carpathian.cpp @@ -265,18 +265,18 @@ void MapgenCarpathian::makeChunk(BlockMakeData *data) this->vm = data->vmanip; this->ndef = data->nodedef; - v3POS blockpos_min = data->blockpos_min; - v3POS blockpos_max = data->blockpos_max; + v3pos_t blockpos_min = data->blockpos_min; + v3pos_t blockpos_max = data->blockpos_max; node_min = blockpos_min * MAP_BLOCKSIZE; - node_max = (blockpos_max + v3POS(1, 1, 1)) * MAP_BLOCKSIZE - v3POS(1, 1, 1); + node_max = (blockpos_max + v3pos_t(1, 1, 1)) * MAP_BLOCKSIZE - v3pos_t(1, 1, 1); full_node_min = (blockpos_min - 1) * MAP_BLOCKSIZE; - full_node_max = (blockpos_max + 2) * MAP_BLOCKSIZE - v3POS(1, 1, 1); + full_node_max = (blockpos_max + 2) * MAP_BLOCKSIZE - v3pos_t(1, 1, 1); // Create a block-specific seed blockseed = getBlockSeed2(full_node_min, seed); // Generate terrain - POS stone_surface_max_y = generateTerrain(); + pos_t stone_surface_max_y = generateTerrain(); // Create heightmap updateHeightmap(node_min, node_max); @@ -329,7 +329,7 @@ void MapgenCarpathian::makeChunk(BlockMakeData *data) // Calculate lighting if (flags & MG_LIGHT) { - calcLighting(node_min - v3POS(0, 1, 0), node_max + v3POS(0, 1, 0), + calcLighting(node_min - v3pos_t(0, 1, 0), node_max + v3pos_t(0, 1, 0), full_node_min, full_node_max); } @@ -340,7 +340,7 @@ void MapgenCarpathian::makeChunk(BlockMakeData *data) //////////////////////////////////////////////////////////////////////////////// -int MapgenCarpathian::getSpawnLevelAtPoint(v2POS p) +int MapgenCarpathian::getSpawnLevelAtPoint(v2pos_t p) { // If rivers are enabled, first check if in a river channel if (spflags & MGCARPATHIAN_RIVERS) { @@ -390,7 +390,7 @@ int MapgenCarpathian::getSpawnLevelAtPoint(v2POS p) bool solid_below = false; u8 cons_non_solid = 0; // consecutive non-solid nodes - for (POS y = water_level; y <= water_level + 32; y++) { + for (pos_t y = water_level; y <= water_level + 32; y++) { float mnt_var = NoisePerlin3D(&noise_mnt_var->np, p.X, y, p.Y, seed); float hill1 = getLerp(height1, height2, mnt_var); float hill2 = getLerp(height3, height4, mnt_var); @@ -460,12 +460,12 @@ int MapgenCarpathian::generateTerrain() noise_rivers->perlinMap2D(node_min.X, node_min.Z); //// Place nodes - const v3POS &em = vm->m_area.getExtent(); - POS stone_surface_max_y = -MAX_MAP_GENERATION_LIMIT; + const v3pos_t &em = vm->m_area.getExtent(); + pos_t stone_surface_max_y = -MAX_MAP_GENERATION_LIMIT; u32 index2d = 0; - for (POS z = node_min.Z; z <= node_max.Z; z++) - for (POS x = node_min.X; x <= node_max.X; x++, index2d++) { + for (pos_t z = node_min.Z; z <= node_max.Z; z++) + for (pos_t x = node_min.X; x <= node_max.X; x++, index2d++) { // Hill/Mountain height (hilliness) float height1 = noise_height1->result[index2d]; float height2 = noise_height2->result[index2d]; @@ -513,7 +513,7 @@ int MapgenCarpathian::generateTerrain() u32 index3d = (z - node_min.Z) * zstride_1u1d + (x - node_min.X); u32 vi = vm->m_area.index(x, node_min.Y - 1, z); - for (POS y = node_min.Y - 1; y <= node_max.Y + 1; + for (pos_t y = node_min.Y - 1; y <= node_max.Y + 1; y++, index3d += ystride, VoxelArea::add_y(em, vi, 1)) { diff --git a/src/mapgen/mapgen_carpathian.h b/src/mapgen/mapgen_carpathian.h index f38ce67304..69bb1ebd26 100644 --- a/src/mapgen/mapgen_carpathian.h +++ b/src/mapgen/mapgen_carpathian.h @@ -38,17 +38,17 @@ struct MapgenCarpathianParams : public MapgenParams float valley_width = 0.25f; float cave_width = 0.09f; - POS large_cave_depth = -33; + pos_t large_cave_depth = -33; u16 small_cave_num_min = 0; u16 small_cave_num_max = 0; u16 large_cave_num_min = 0; u16 large_cave_num_max = 2; float large_cave_flooded = 0.5f; - POS cavern_limit = -256; - POS cavern_taper = 256; + pos_t cavern_limit = -256; + pos_t cavern_taper = 256; float cavern_threshold = 0.7f; - POS dungeon_ymin = -MAX_MAP_GENERATION_LIMIT; - POS dungeon_ymax = MAX_MAP_GENERATION_LIMIT; + pos_t dungeon_ymin = -MAX_MAP_GENERATION_LIMIT; + pos_t dungeon_ymax = MAX_MAP_GENERATION_LIMIT; NoiseParams np_filler_depth; NoiseParams np_height1; @@ -85,7 +85,7 @@ class MapgenCarpathian : public MapgenBasic virtual MapgenType getType() const { return MAPGEN_CARPATHIAN; } virtual void makeChunk(BlockMakeData *data); - int getSpawnLevelAtPoint(v2POS p); + int getSpawnLevelAtPoint(v2pos_t p); private: float base_level; diff --git a/src/mapgen/mapgen_flat.cpp b/src/mapgen/mapgen_flat.cpp index 85a23693bf..20749d6d0a 100644 --- a/src/mapgen/mapgen_flat.cpp +++ b/src/mapgen/mapgen_flat.cpp @@ -174,19 +174,19 @@ void MapgenFlatParams::setDefaultSettings(Settings *settings) ///////////////////////////////////////////////////////////////// -int MapgenFlat::getSpawnLevelAtPoint(v2POS p) +int MapgenFlat::getSpawnLevelAtPoint(v2pos_t p) { - POS stone_level = ground_level; + pos_t stone_level = ground_level; float n_terrain = ((spflags & MGFLAT_LAKES) || (spflags & MGFLAT_HILLS)) ? NoisePerlin2D(&noise_terrain->np, p.X, p.Y, seed) : 0.0f; if ((spflags & MGFLAT_LAKES) && n_terrain < lake_threshold) { - POS depress = (lake_threshold - n_terrain) * lake_steepness; + pos_t depress = (lake_threshold - n_terrain) * lake_steepness; stone_level = ground_level - depress; } else if ((spflags & MGFLAT_HILLS) && n_terrain > hill_threshold) { - POS rise = (n_terrain - hill_threshold) * hill_steepness; + pos_t rise = (n_terrain - hill_threshold) * hill_steepness; stone_level = ground_level + rise; } @@ -215,17 +215,17 @@ void MapgenFlat::makeChunk(BlockMakeData *data) this->ndef = data->nodedef; //TimeTaker t("makeChunk"); - v3POS blockpos_min = data->blockpos_min; - v3POS blockpos_max = data->blockpos_max; + v3pos_t blockpos_min = data->blockpos_min; + v3pos_t blockpos_max = data->blockpos_max; node_min = blockpos_min * MAP_BLOCKSIZE; - node_max = (blockpos_max + v3POS(1, 1, 1)) * MAP_BLOCKSIZE - v3POS(1, 1, 1); + node_max = (blockpos_max + v3pos_t(1, 1, 1)) * MAP_BLOCKSIZE - v3pos_t(1, 1, 1); full_node_min = (blockpos_min - 1) * MAP_BLOCKSIZE; - full_node_max = (blockpos_max + 2) * MAP_BLOCKSIZE - v3POS(1, 1, 1); + full_node_max = (blockpos_max + 2) * MAP_BLOCKSIZE - v3pos_t(1, 1, 1); blockseed = getBlockSeed2(full_node_min, seed); // Generate base terrain, mountains, and ridges with initial heightmaps - POS stone_surface_max_y = generateTerrain(); + pos_t stone_surface_max_y = generateTerrain(); // Create heightmap updateHeightmap(node_min, node_max); @@ -277,45 +277,45 @@ void MapgenFlat::makeChunk(BlockMakeData *data) updateLiquid(&data->transforming_liquid, full_node_min, full_node_max); if (flags & MG_LIGHT) - calcLighting(node_min - v3POS(0, 1, 0), node_max + v3POS(0, 1, 0), + calcLighting(node_min - v3pos_t(0, 1, 0), node_max + v3pos_t(0, 1, 0), full_node_min, full_node_max); - //setLighting(node_min - v3POS(1, 0, 1) * MAP_BLOCKSIZE, - // node_max + v3POS(1, 0, 1) * MAP_BLOCKSIZE, 0xFF); + //setLighting(node_min - v3pos_t(1, 0, 1) * MAP_BLOCKSIZE, + // node_max + v3pos_t(1, 0, 1) * MAP_BLOCKSIZE, 0xFF); this->generating = false; } -POS MapgenFlat::generateTerrain() +pos_t MapgenFlat::generateTerrain() { MapNode n_air(CONTENT_AIR); MapNode n_stone(c_stone); MapNode n_water(c_water_source); - const v3POS &em = vm->m_area.getExtent(); - POS stone_surface_max_y = -MAX_MAP_GENERATION_LIMIT; + const v3pos_t &em = vm->m_area.getExtent(); + pos_t stone_surface_max_y = -MAX_MAP_GENERATION_LIMIT; u32 ni2d = 0; bool use_noise = (spflags & MGFLAT_LAKES) || (spflags & MGFLAT_HILLS); if (use_noise) noise_terrain->perlinMap2D(node_min.X, node_min.Z); - for (POS z = node_min.Z; z <= node_max.Z; z++) - for (POS x = node_min.X; x <= node_max.X; x++, ni2d++) { - POS stone_level = ground_level; + for (pos_t z = node_min.Z; z <= node_max.Z; z++) + for (pos_t x = node_min.X; x <= node_max.X; x++, ni2d++) { + pos_t stone_level = ground_level; float n_terrain = use_noise ? noise_terrain->result[ni2d] : 0.0f; if ((spflags & MGFLAT_LAKES) && n_terrain < lake_threshold) { - POS depress = (lake_threshold - n_terrain) * lake_steepness; + pos_t depress = (lake_threshold - n_terrain) * lake_steepness; stone_level = ground_level - depress; } else if ((spflags & MGFLAT_HILLS) && n_terrain > hill_threshold) { - POS rise = (n_terrain - hill_threshold) * hill_steepness; + pos_t rise = (n_terrain - hill_threshold) * hill_steepness; stone_level = ground_level + rise; } u32 vi = vm->m_area.index(x, node_min.Y - 1, z); - for (POS y = node_min.Y - 1; y <= node_max.Y + 1; y++) { + for (pos_t y = node_min.Y - 1; y <= node_max.Y + 1; y++) { if (vm->m_data[vi].getContent() == CONTENT_IGNORE) { if (y <= stone_level) { vm->m_data[vi] = n_stone; diff --git a/src/mapgen/mapgen_flat.h b/src/mapgen/mapgen_flat.h index 82070210c0..73ee00ed30 100644 --- a/src/mapgen/mapgen_flat.h +++ b/src/mapgen/mapgen_flat.h @@ -33,7 +33,7 @@ extern FlagDesc flagdesc_mapgen_flat[]; struct MapgenFlatParams : public MapgenParams { - POS ground_level = 8; + pos_t ground_level = 8; float lake_threshold = -0.45f; float lake_steepness = 48.0f; float hill_threshold = 0.45f; @@ -44,13 +44,13 @@ struct MapgenFlatParams : public MapgenParams u16 small_cave_num_max = 0; u16 large_cave_num_min = 0; u16 large_cave_num_max = 2; - POS large_cave_depth = -33; + pos_t large_cave_depth = -33; float large_cave_flooded = 0.5f; - POS cavern_limit = -256; - POS cavern_taper = 256; + pos_t cavern_limit = -256; + pos_t cavern_taper = 256; float cavern_threshold = 0.7f; - POS dungeon_ymin = -MAX_MAP_GENERATION_LIMIT; - POS dungeon_ymax = MAX_MAP_GENERATION_LIMIT; + pos_t dungeon_ymin = -MAX_MAP_GENERATION_LIMIT; + pos_t dungeon_ymax = MAX_MAP_GENERATION_LIMIT; NoiseParams np_terrain; NoiseParams np_filler_depth; @@ -76,11 +76,11 @@ class MapgenFlat : public MapgenBasic virtual MapgenType getType() const { return MAPGEN_FLAT; } virtual void makeChunk(BlockMakeData *data); - int getSpawnLevelAtPoint(v2POS p); - POS generateTerrain(); + int getSpawnLevelAtPoint(v2pos_t p); + pos_t generateTerrain(); private: - POS ground_level; + pos_t ground_level; float lake_threshold; float lake_steepness; float hill_threshold; diff --git a/src/mapgen/mapgen_fractal.cpp b/src/mapgen/mapgen_fractal.cpp index 6d0c2ce01f..71179bf0f4 100644 --- a/src/mapgen/mapgen_fractal.cpp +++ b/src/mapgen/mapgen_fractal.cpp @@ -174,19 +174,19 @@ void MapgenFractalParams::setDefaultSettings(Settings *settings) ///////////////////////////////////////////////////////////////// -int MapgenFractal::getSpawnLevelAtPoint(v2POS p) +int MapgenFractal::getSpawnLevelAtPoint(v2pos_t p) { bool solid_below = false; // Fractal node is present below to spawn on u8 air_count = 0; // Consecutive air nodes above a fractal node - POS search_start = 0; // No terrain search start + pos_t search_start = 0; // No terrain search start // If terrain present, don't start search below terrain or water level if (noise_seabed) { - POS seabed_level = NoisePerlin2D(&noise_seabed->np, p.X, p.Y, seed); + pos_t seabed_level = NoisePerlin2D(&noise_seabed->np, p.X, p.Y, seed); search_start = MYMAX(search_start, MYMAX(seabed_level, water_level)); } - for (POS y = search_start; y <= search_start + 4096; y++) { + for (pos_t y = search_start; y <= search_start + 4096; y++) { if (getFractalAtPoint(p.X, y, p.Y)) { // Fractal node solid_below = true; @@ -216,17 +216,17 @@ void MapgenFractal::makeChunk(BlockMakeData *data) this->vm = data->vmanip; this->ndef = data->nodedef; - v3POS blockpos_min = data->blockpos_min; - v3POS blockpos_max = data->blockpos_max; + v3pos_t blockpos_min = data->blockpos_min; + v3pos_t blockpos_max = data->blockpos_max; node_min = blockpos_min * MAP_BLOCKSIZE; - node_max = (blockpos_max + v3POS(1, 1, 1)) * MAP_BLOCKSIZE - v3POS(1, 1, 1); + node_max = (blockpos_max + v3pos_t(1, 1, 1)) * MAP_BLOCKSIZE - v3pos_t(1, 1, 1); full_node_min = (blockpos_min - 1) * MAP_BLOCKSIZE; - full_node_max = (blockpos_max + 2) * MAP_BLOCKSIZE - v3POS(1, 1, 1); + full_node_max = (blockpos_max + 2) * MAP_BLOCKSIZE - v3pos_t(1, 1, 1); blockseed = getBlockSeed2(full_node_min, seed); // Generate fractal and optional terrain - POS stone_surface_max_y = generateTerrain(); + pos_t stone_surface_max_y = generateTerrain(); // Create heightmap updateHeightmap(node_min, node_max); @@ -265,7 +265,7 @@ void MapgenFractal::makeChunk(BlockMakeData *data) // Calculate lighting if (flags & MG_LIGHT) - calcLighting(node_min - v3POS(0, 1, 0), node_max + v3POS(0, 1, 0), + calcLighting(node_min - v3pos_t(0, 1, 0), node_max + v3pos_t(0, 1, 0), full_node_min, full_node_max); this->generating = false; @@ -274,7 +274,7 @@ void MapgenFractal::makeChunk(BlockMakeData *data) } -bool MapgenFractal::getFractalAtPoint(POS x, POS y, POS z) +bool MapgenFractal::getFractalAtPoint(pos_t x, pos_t y, pos_t z) { float cx, cy, cz, cw, ox, oy, oz, ow; @@ -404,26 +404,26 @@ bool MapgenFractal::getFractalAtPoint(POS x, POS y, POS z) } -POS MapgenFractal::generateTerrain() +pos_t MapgenFractal::generateTerrain() { MapNode n_air(CONTENT_AIR); MapNode n_stone(c_stone); MapNode n_water(c_water_source); - POS stone_surface_max_y = -MAX_MAP_GENERATION_LIMIT; + pos_t stone_surface_max_y = -MAX_MAP_GENERATION_LIMIT; u32 index2d = 0; if (noise_seabed) noise_seabed->perlinMap2D(node_min.X, node_min.Z); - for (POS z = node_min.Z; z <= node_max.Z; z++) { - for (POS y = node_min.Y - 1; y <= node_max.Y + 1; y++) { + for (pos_t z = node_min.Z; z <= node_max.Z; z++) { + for (pos_t y = node_min.Y - 1; y <= node_max.Y + 1; y++) { u32 vi = vm->m_area.index(node_min.X, y, z); - for (POS x = node_min.X; x <= node_max.X; x++, vi++, index2d++) { + for (pos_t x = node_min.X; x <= node_max.X; x++, vi++, index2d++) { if (vm->m_data[vi].getContent() != CONTENT_IGNORE) continue; - POS seabed_height = -MAX_MAP_GENERATION_LIMIT; + pos_t seabed_height = -MAX_MAP_GENERATION_LIMIT; if (noise_seabed) seabed_height = noise_seabed->result[index2d]; diff --git a/src/mapgen/mapgen_fractal.h b/src/mapgen/mapgen_fractal.h index 0e14e5c04c..e070d2e456 100644 --- a/src/mapgen/mapgen_fractal.h +++ b/src/mapgen/mapgen_fractal.h @@ -36,14 +36,14 @@ extern FlagDesc flagdesc_mapgen_fractal[]; struct MapgenFractalParams : public MapgenParams { float cave_width = 0.09f; - POS large_cave_depth = -33; + pos_t large_cave_depth = -33; u16 small_cave_num_min = 0; u16 small_cave_num_max = 0; u16 large_cave_num_min = 0; u16 large_cave_num_max = 2; float large_cave_flooded = 0.5f; - POS dungeon_ymin = -MAX_MAP_GENERATION_LIMIT; - POS dungeon_ymax = MAX_MAP_GENERATION_LIMIT; + pos_t dungeon_ymin = -MAX_MAP_GENERATION_LIMIT; + pos_t dungeon_ymax = MAX_MAP_GENERATION_LIMIT; u16 fractal = 1; u16 iterations = 11; v3f scale = v3f(4096.0, 1024.0, 4096.0); @@ -78,9 +78,9 @@ class MapgenFractal : public MapgenBasic virtual MapgenType getType() const { return MAPGEN_FRACTAL; } virtual void makeChunk(BlockMakeData *data); - int getSpawnLevelAtPoint(v2POS p); - bool getFractalAtPoint(POS x, POS y, POS z); - POS generateTerrain(); + int getSpawnLevelAtPoint(v2pos_t p); + bool getFractalAtPoint(pos_t x, pos_t y, pos_t z); + pos_t generateTerrain(); private: u16 formula; diff --git a/src/mapgen/mapgen_singlenode.cpp b/src/mapgen/mapgen_singlenode.cpp index 421fde5709..1c1a65b714 100644 --- a/src/mapgen/mapgen_singlenode.cpp +++ b/src/mapgen/mapgen_singlenode.cpp @@ -55,21 +55,21 @@ void MapgenSinglenode::makeChunk(BlockMakeData *data) this->vm = data->vmanip; this->ndef = data->nodedef; - v3BPOS blockpos_min = data->blockpos_min; - v3BPOS blockpos_max = data->blockpos_max; + v3bpos_t blockpos_min = data->blockpos_min; + v3bpos_t blockpos_max = data->blockpos_max; // Area of central chunk - v3POS node_min = blockpos_min * MAP_BLOCKSIZE; - v3POS node_max = (blockpos_max + v3POS(1, 1, 1)) * MAP_BLOCKSIZE - v3POS(1, 1, 1); + v3pos_t node_min = blockpos_min * MAP_BLOCKSIZE; + v3pos_t node_max = (blockpos_max + v3pos_t(1, 1, 1)) * MAP_BLOCKSIZE - v3pos_t(1, 1, 1); blockseed = getBlockSeed2(node_min, data->seed); MapNode n_node(c_node); - for (POS z = node_min.Z; z <= node_max.Z; z++) - for (POS y = node_min.Y; y <= node_max.Y; y++) { + for (pos_t z = node_min.Z; z <= node_max.Z; z++) + for (pos_t y = node_min.Y; y <= node_max.Y; y++) { u32 i = vm->m_area.index(node_min.X, y, z); - for (POS x = node_min.X; x <= node_max.X; x++) { + for (pos_t x = node_min.X; x <= node_max.X; x++) { if (vm->m_data[i].getContent() == CONTENT_IGNORE) vm->m_data[i] = n_node; i++; @@ -87,7 +87,7 @@ void MapgenSinglenode::makeChunk(BlockMakeData *data) } -int MapgenSinglenode::getSpawnLevelAtPoint(v2POS p) +int MapgenSinglenode::getSpawnLevelAtPoint(v2pos_t p) { return 0; } diff --git a/src/mapgen/mapgen_singlenode.h b/src/mapgen/mapgen_singlenode.h index dcb6f39803..9f26962875 100644 --- a/src/mapgen/mapgen_singlenode.h +++ b/src/mapgen/mapgen_singlenode.h @@ -44,5 +44,5 @@ class MapgenSinglenode : public Mapgen virtual MapgenType getType() const { return MAPGEN_SINGLENODE; } void makeChunk(BlockMakeData *data); - int getSpawnLevelAtPoint(v2POS p); + int getSpawnLevelAtPoint(v2pos_t p); }; diff --git a/src/mapgen/mapgen_v5.cpp b/src/mapgen/mapgen_v5.cpp index 2479aae377..e361d6de2b 100644 --- a/src/mapgen/mapgen_v5.cpp +++ b/src/mapgen/mapgen_v5.cpp @@ -162,7 +162,7 @@ void MapgenV5Params::setDefaultSettings(Settings *settings) ///////////////////////////////////////////////////////////////// -int MapgenV5::getSpawnLevelAtPoint(v2POS p) +int MapgenV5::getSpawnLevelAtPoint(v2pos_t p) { float f = 0.55 + NoisePerlin2D(&noise_factor->np, p.X, p.Y, seed); @@ -176,11 +176,11 @@ int MapgenV5::getSpawnLevelAtPoint(v2POS p) // terrain will be below this. // Raising the maximum spawn level above 'water_level + 16' is necessary // for when noise_height 'offset' is set much higher than water_level. - POS max_spawn_y = MYMAX(noise_height->np.offset, water_level + 16); + pos_t max_spawn_y = MYMAX(noise_height->np.offset, water_level + 16); // Starting spawn search at max_spawn_y + 128 ensures 128 nodes of open // space above spawn position. Avoids spawning in possibly sealed voids. - for (POS y = max_spawn_y + 128; y >= water_level; y--) { + for (pos_t y = max_spawn_y + 128; y >= water_level; y--) { float n_ground = NoisePerlin3D(&noise_ground->np, p.X, y, p.Y, seed); if (n_ground * f > y - h) { // If solid @@ -207,18 +207,18 @@ void MapgenV5::makeChunk(BlockMakeData *data) this->ndef = data->nodedef; //TimeTaker t("makeChunk"); - v3POS blockpos_min = data->blockpos_min; - v3POS blockpos_max = data->blockpos_max; + v3pos_t blockpos_min = data->blockpos_min; + v3pos_t blockpos_max = data->blockpos_max; node_min = blockpos_min * MAP_BLOCKSIZE; - node_max = (blockpos_max + v3POS(1, 1, 1)) * MAP_BLOCKSIZE - v3POS(1, 1, 1); + node_max = (blockpos_max + v3pos_t(1, 1, 1)) * MAP_BLOCKSIZE - v3pos_t(1, 1, 1); full_node_min = (blockpos_min - 1) * MAP_BLOCKSIZE; - full_node_max = (blockpos_max + 2) * MAP_BLOCKSIZE - v3POS(1, 1, 1); + full_node_max = (blockpos_max + 2) * MAP_BLOCKSIZE - v3pos_t(1, 1, 1); // Create a block-specific seed blockseed = getBlockSeed2(full_node_min, seed); // Generate base terrain - POS stone_surface_max_y = generateBaseTerrain(); + pos_t stone_surface_max_y = generateBaseTerrain(); // Create heightmap updateHeightmap(node_min, node_max); @@ -273,7 +273,7 @@ void MapgenV5::makeChunk(BlockMakeData *data) // Calculate lighting if (flags & MG_LIGHT) { - calcLighting(node_min - v3POS(0, 1, 0), node_max + v3POS(0, 1, 0), + calcLighting(node_min - v3pos_t(0, 1, 0), node_max + v3pos_t(0, 1, 0), full_node_min, full_node_max); } @@ -291,10 +291,10 @@ int MapgenV5::generateBaseTerrain() noise_height->perlinMap2D(node_min.X, node_min.Z); noise_ground->perlinMap3D(node_min.X, node_min.Y - 1, node_min.Z); - for (POS z=node_min.Z; z<=node_max.Z; z++) { - for (POS y=node_min.Y - 1; y<=node_max.Y + 1; y++) { + for (pos_t z=node_min.Z; z<=node_max.Z; z++) { + for (pos_t y=node_min.Y - 1; y<=node_max.Y + 1; y++) { u32 vi = vm->m_area.index(node_min.X, y, z); - for (POS x=node_min.X; x<=node_max.X; x++, vi++, index++, index2d++) { + for (pos_t x=node_min.X; x<=node_max.X; x++, vi++, index++, index2d++) { if (vm->m_data[vi].getContent() != CONTENT_IGNORE) continue; diff --git a/src/mapgen/mapgen_v5.h b/src/mapgen/mapgen_v5.h index cbefb6e9ed..9df65589f9 100644 --- a/src/mapgen/mapgen_v5.h +++ b/src/mapgen/mapgen_v5.h @@ -32,17 +32,17 @@ extern FlagDesc flagdesc_mapgen_v5[]; struct MapgenV5Params : public MapgenParams { float cave_width = 0.09f; - POS large_cave_depth = -256; + pos_t large_cave_depth = -256; u16 small_cave_num_min = 0; u16 small_cave_num_max = 0; u16 large_cave_num_min = 0; u16 large_cave_num_max = 2; float large_cave_flooded = 0.5f; - POS cavern_limit = -256; - POS cavern_taper = 256; + pos_t cavern_limit = -256; + pos_t cavern_taper = 256; float cavern_threshold = 0.7f; - POS dungeon_ymin = -MAX_MAP_GENERATION_LIMIT; - POS dungeon_ymax = MAX_MAP_GENERATION_LIMIT; + pos_t dungeon_ymin = -MAX_MAP_GENERATION_LIMIT; + pos_t dungeon_ymax = MAX_MAP_GENERATION_LIMIT; NoiseParams np_filler_depth; NoiseParams np_factor; @@ -70,7 +70,7 @@ class MapgenV5 : public MapgenBasic virtual MapgenType getType() const { return MAPGEN_V5; } virtual void makeChunk(BlockMakeData *data); - int getSpawnLevelAtPoint(v2POS p); + int getSpawnLevelAtPoint(v2pos_t p); int generateBaseTerrain(); private: diff --git a/src/mapgen/mapgen_v6.cpp b/src/mapgen/mapgen_v6.cpp index 54cddb18ee..949afee572 100644 --- a/src/mapgen/mapgen_v6.cpp +++ b/src/mapgen/mapgen_v6.cpp @@ -60,7 +60,7 @@ MapgenV6::MapgenV6(MapgenV6Params *params, EmergeParams *emerge) m_emerge = emerge; ystride = csize.X; - heightmap = new POS[csize.X * csize.Z]; + heightmap = new pos_t[csize.X * csize.Z]; spflags = params->spflags; freq_desert = params->freq_desert; @@ -236,13 +236,13 @@ void MapgenV6Params::setDefaultSettings(Settings *settings) // Returns Y one under area minimum if not found -POS MapgenV6::find_stone_level(v2POS p2d) +pos_t MapgenV6::find_stone_level(v2pos_t p2d) { - const v3POS &em = vm->m_area.getExtent(); - POS y_nodes_max = vm->m_area.MaxEdge.Y; - POS y_nodes_min = vm->m_area.MinEdge.Y; + const v3pos_t &em = vm->m_area.getExtent(); + pos_t y_nodes_max = vm->m_area.MaxEdge.Y; + pos_t y_nodes_min = vm->m_area.MinEdge.Y; u32 i = vm->m_area.index(p2d.X, y_nodes_max, p2d.Y); - POS y; + pos_t y; for (y = y_nodes_max; y >= y_nodes_min; y--) { content_t c = vm->m_data[i].getContent(); @@ -256,12 +256,12 @@ POS MapgenV6::find_stone_level(v2POS p2d) // Required by mapgen.h -bool MapgenV6::block_is_underground(u64 seed, v3POS blockpos) +bool MapgenV6::block_is_underground(u64 seed, v3pos_t blockpos) { /*s16 minimum_groundlevel = (s16)get_sector_minimum_ground_level( - seed, v2POS(blockpos.X, blockpos.Z));*/ + seed, v2pos_t(blockpos.X, blockpos.Z));*/ // Nah, this is just a heuristic, just return something - POS minimum_groundlevel = water_level; + pos_t minimum_groundlevel = water_level; if(blockpos.Y * MAP_BLOCKSIZE + MAP_BLOCKSIZE <= minimum_groundlevel) return true; @@ -300,7 +300,7 @@ float MapgenV6::baseTerrainLevel(float terrain_base, float terrain_higher, } -float MapgenV6::baseTerrainLevelFromNoise(v2POS p) +float MapgenV6::baseTerrainLevelFromNoise(v2pos_t p) { if (spflags & MGV6_FLAT) return water_level; @@ -319,7 +319,7 @@ float MapgenV6::baseTerrainLevelFromNoise(v2POS p) } -float MapgenV6::baseTerrainLevelFromMap(v2POS p) +float MapgenV6::baseTerrainLevelFromMap(v2pos_t p) { int index = (p.Y - node_min.Z) * ystride + (p.X - node_min.X); return baseTerrainLevelFromMap(index); @@ -341,15 +341,15 @@ float MapgenV6::baseTerrainLevelFromMap(int index) } -int MapgenV6::getGroundLevelAtPoint(v2POS p) +int MapgenV6::getGroundLevelAtPoint(v2pos_t p) { return baseTerrainLevelFromNoise(p) + MGV6_AVERAGE_MUD_AMOUNT; } -int MapgenV6::getSpawnLevelAtPoint(v2POS p) +int MapgenV6::getSpawnLevelAtPoint(v2pos_t p) { - POS level_at_point = baseTerrainLevelFromNoise(p) + MGV6_AVERAGE_MUD_AMOUNT; + pos_t level_at_point = baseTerrainLevelFromNoise(p) + MGV6_AVERAGE_MUD_AMOUNT; if (level_at_point <= water_level || level_at_point > water_level + 16) return MAX_MAP_GENERATION_LIMIT; // Unsuitable spawn point @@ -361,7 +361,7 @@ int MapgenV6::getSpawnLevelAtPoint(v2POS p) //////////////////////// Noise functions -BiomeV6Type MapgenV6::getBiome(v2POS p) +BiomeV6Type MapgenV6::getBiome(v2pos_t p) { int index = (p.Y - full_node_min.Z) * (ystride + 2 * MAP_BLOCKSIZE) + (p.X - full_node_min.X); @@ -369,7 +369,7 @@ BiomeV6Type MapgenV6::getBiome(v2POS p) } -float MapgenV6::getHumidity(v2POS p) +float MapgenV6::getHumidity(v2pos_t p) { /*double noise = noise2d_perlin( 0.5+(float)p.X/500, 0.5+(float)p.Y/500, @@ -388,7 +388,7 @@ float MapgenV6::getHumidity(v2POS p) } -float MapgenV6::getTreeAmount(v2POS p) +float MapgenV6::getTreeAmount(v2pos_t p) { /*double noise = noise2d_perlin( 0.5+(float)p.X/125, 0.5+(float)p.Y/125, @@ -403,7 +403,7 @@ float MapgenV6::getTreeAmount(v2POS p) } -bool MapgenV6::getHaveAppleTree(v2POS p) +bool MapgenV6::getHaveAppleTree(v2pos_t p) { /*is_apple_tree = noise2d_perlin( 0.5+(float)p.X/100, 0.5+(float)p.Z/100, @@ -440,7 +440,7 @@ bool MapgenV6::getHaveBeach(int index) } -BiomeV6Type MapgenV6::getBiome(int index, v2POS p) +BiomeV6Type MapgenV6::getBiome(int index, v2pos_t p) { // Just do something very simple as for now /*double d = noise2d_perlin( @@ -485,7 +485,7 @@ BiomeV6Type MapgenV6::getBiome(int index, v2POS p) } -u32 MapgenV6::get_blockseed(u64 seed, v3POS p) +u32 MapgenV6::get_blockseed(u64 seed, v3pos_t p) { s32 x = p.X, y = p.Y, z = p.Z; return (u32)(seed % 0x100000000ULL) + z * 38134234 + y * 42123 + x * 23; @@ -505,18 +505,18 @@ void MapgenV6::makeChunk(BlockMakeData *data) this->ndef = data->nodedef; // Hack: use minimum block coords for old code that assumes a single block - v3BPOS blockpos_min = data->blockpos_min; - v3BPOS blockpos_max = data->blockpos_max; + v3bpos_t blockpos_min = data->blockpos_min; + v3bpos_t blockpos_max = data->blockpos_max; // Area of central chunk node_min = blockpos_min * MAP_BLOCKSIZE; - node_max = (blockpos_max + v3POS(1, 1, 1)) * MAP_BLOCKSIZE - v3POS(1, 1, 1); + node_max = (blockpos_max + v3pos_t(1, 1, 1)) * MAP_BLOCKSIZE - v3pos_t(1, 1, 1); // Full allocated area full_node_min = (blockpos_min - 1) * MAP_BLOCKSIZE; - full_node_max = (blockpos_max + 2) * MAP_BLOCKSIZE - v3POS(1, 1, 1); + full_node_max = (blockpos_max + 2) * MAP_BLOCKSIZE - v3pos_t(1, 1, 1); - central_area_size = node_max - node_min + v3POS(1, 1, 1); + central_area_size = node_max - node_min + v3pos_t(1, 1, 1); assert(central_area_size.X == central_area_size.Z); // Create a block-specific seed @@ -527,7 +527,7 @@ void MapgenV6::makeChunk(BlockMakeData *data) // Maximum height of the stone surface and obstacles. // This is used to guide the cave generation - POS stone_surface_max_y; + pos_t stone_surface_max_y; // Generate general ground level to full area stone_surface_max_y = generateGround(); @@ -537,8 +537,8 @@ void MapgenV6::makeChunk(BlockMakeData *data) const s16 max_spread_amount = MAP_BLOCKSIZE; // Limit dirt flow area by 1 because mud is flowed into neighbors - POS mudflow_minpos = -max_spread_amount + 1; - POS mudflow_maxpos = central_area_size.X + max_spread_amount - 2; + pos_t mudflow_minpos = -max_spread_amount + 1; + pos_t mudflow_maxpos = central_area_size.X + max_spread_amount - 2; // Loop this part, it will make stuff look older and newer nicely const u32 age_loops = 2; @@ -581,17 +581,17 @@ void MapgenV6::makeChunk(BlockMakeData *data) dp.np_alt_wall = NoiseParams(-0.4, 1.0, v3f(40.0, 40.0, 40.0), 32474, 6, 1.1, 2.0); - if (getBiome(0, v2POS(node_min.X, node_min.Z)) == BT_DESERT) { + if (getBiome(0, v2pos_t(node_min.X, node_min.Z)) == BT_DESERT) { dp.c_wall = c_desert_stone; dp.c_alt_wall = CONTENT_IGNORE; dp.c_stair = c_stair_desert_stone; dp.diagonal_dirs = true; - dp.holesize = v3POS(2, 3, 2); - dp.room_size_min = v3POS(6, 9, 6); - dp.room_size_max = v3POS(10, 11, 10); - dp.room_size_large_min = v3POS(10, 13, 10); - dp.room_size_large_max = v3POS(18, 21, 18); + dp.holesize = v3pos_t(2, 3, 2); + dp.room_size_min = v3pos_t(6, 9, 6); + dp.room_size_max = v3pos_t(10, 11, 10); + dp.room_size_large_min = v3pos_t(10, 13, 10); + dp.room_size_large_max = v3pos_t(18, 21, 18); dp.notifytype = GENNOTIFY_TEMPLE; } else { dp.c_wall = c_cobble; @@ -599,11 +599,11 @@ void MapgenV6::makeChunk(BlockMakeData *data) dp.c_stair = c_stair_cobble; dp.diagonal_dirs = false; - dp.holesize = v3POS(1, 2, 1); - dp.room_size_min = v3POS(4, 4, 4); - dp.room_size_max = v3POS(8, 6, 8); - dp.room_size_large_min = v3POS(8, 8, 8); - dp.room_size_large_max = v3POS(16, 16, 16); + dp.holesize = v3pos_t(1, 2, 1); + dp.room_size_min = v3pos_t(4, 4, 4); + dp.room_size_max = v3pos_t(8, 6, 8); + dp.room_size_large_min = v3pos_t(8, 8, 8); + dp.room_size_large_max = v3pos_t(16, 16, 16); dp.notifytype = GENNOTIFY_DUNGEON; } @@ -632,8 +632,8 @@ void MapgenV6::makeChunk(BlockMakeData *data) // Calculate lighting if (flags & MG_LIGHT) - calcLighting(node_min - v3POS(1, 1, 1) * MAP_BLOCKSIZE, - node_max + v3POS(1, 0, 1) * MAP_BLOCKSIZE, + calcLighting(node_min - v3pos_t(1, 1, 1) * MAP_BLOCKSIZE, + node_max + v3pos_t(1, 0, 1) * MAP_BLOCKSIZE, full_node_min, full_node_max); this->generating = false; @@ -673,21 +673,21 @@ int MapgenV6::generateGround() int stone_surface_max_y = -MAX_MAP_GENERATION_LIMIT; u32 index = 0; - for (POS z = node_min.Z; z <= node_max.Z; z++) - for (POS x = node_min.X; x <= node_max.X; x++, index++) { + for (pos_t z = node_min.Z; z <= node_max.Z; z++) + for (pos_t x = node_min.X; x <= node_max.X; x++, index++) { // Surface height - POS surface_y = (POS)baseTerrainLevelFromMap(index); + pos_t surface_y = (pos_t)baseTerrainLevelFromMap(index); // Log it if (surface_y > stone_surface_max_y) stone_surface_max_y = surface_y; - BiomeV6Type bt = getBiome(v2POS(x, z)); + BiomeV6Type bt = getBiome(v2pos_t(x, z)); // Fill ground with stone - const v3POS &em = vm->m_area.getExtent(); + const v3pos_t &em = vm->m_area.getExtent(); u32 i = vm->m_area.index(x, node_min.Y, z); - for (POS y = node_min.Y; y <= node_max.Y; y++) { + for (pos_t y = node_min.Y; y <= node_max.Y; y++) { if (vm->m_data[i].getContent() == CONTENT_IGNORE) { if (y <= surface_y) { vm->m_data[i] = (y >= MGV6_DESERT_STONE_BASE @@ -718,19 +718,19 @@ void MapgenV6::addMud() MapNode addnode; u32 index = 0; - for (POS z = node_min.Z; z <= node_max.Z; z++) - for (POS x = node_min.X; x <= node_max.X; x++, index++) { + for (pos_t z = node_min.Z; z <= node_max.Z; z++) + for (pos_t x = node_min.X; x <= node_max.X; x++, index++) { // Randomize mud amount s16 mud_add_amount = getMudAmount(index) / 2.0 + 0.5; // Find ground level - POS surface_y = find_stone_level(v2POS(x, z)); /////////////////optimize this! + pos_t surface_y = find_stone_level(v2pos_t(x, z)); /////////////////optimize this! // Handle area not found if (surface_y == vm->m_area.MinEdge.Y - 1) continue; - BiomeV6Type bt = getBiome(v2POS(x, z)); + BiomeV6Type bt = getBiome(v2pos_t(x, z)); addnode = (bt == BT_DESERT) ? n_desert_sand : n_dirt; if (bt == BT_DESERT && surface_y + mud_add_amount <= water_level + 1) { @@ -754,10 +754,10 @@ void MapgenV6::addMud() // Add mud on ground s16 mudcount = 0; - const v3POS &em = vm->m_area.getExtent(); - POS y_start = surface_y + 1; + const v3pos_t &em = vm->m_area.getExtent(); + pos_t y_start = surface_y + 1; u32 i = vm->m_area.index(x, y_start, z); - for (POS y = y_start; y <= node_max.Y; y++) { + for (pos_t y = y_start; y <= node_max.Y; y++) { if (mudcount >= mud_add_amount) break; @@ -770,30 +770,30 @@ void MapgenV6::addMud() } -void MapgenV6::flowMud(POS &mudflow_minpos, POS &mudflow_maxpos) +void MapgenV6::flowMud(pos_t &mudflow_minpos, pos_t &mudflow_maxpos) { - const v3POS &em = vm->m_area.getExtent(); - static const v3POS dirs4[4] = { - v3POS(0, 0, 1), // Back - v3POS(1, 0, 0), // Right - v3POS(0, 0, -1), // Front - v3POS(-1, 0, 0), // Left + const v3pos_t &em = vm->m_area.getExtent(); + static const v3pos_t dirs4[4] = { + v3pos_t(0, 0, 1), // Back + v3pos_t(1, 0, 0), // Right + v3pos_t(0, 0, -1), // Front + v3pos_t(-1, 0, 0), // Left }; // Iterate twice for (s16 k = 0; k < 2; k++) { - for (POS z = mudflow_minpos; z <= mudflow_maxpos; z++) - for (POS x = mudflow_minpos; x <= mudflow_maxpos; x++) { + for (pos_t z = mudflow_minpos; z <= mudflow_maxpos; z++) + for (pos_t x = mudflow_minpos; x <= mudflow_maxpos; x++) { // Node column position - v2POS p2d; + v2pos_t p2d; // Invert coordinates on second iteration to process columns in // opposite order, to avoid a directional bias. if (k == 1) - p2d = v2POS(node_max.X, node_max.Z) - v2POS(x, z); + p2d = v2pos_t(node_max.X, node_max.Z) - v2pos_t(x, z); else - p2d = v2POS(node_min.X, node_min.Z) + v2POS(x, z); + p2d = v2pos_t(node_min.X, node_min.Z) + v2pos_t(x, z); - POS y = node_max.Y; + pos_t y = node_max.Y; while (y >= node_min.Y) { for (;; y--) { @@ -838,7 +838,7 @@ void MapgenV6::flowMud(POS &mudflow_minpos, POS &mudflow_maxpos) continue; // Drop mud on one side - for (const v3POS &dirp : dirs4) { + for (const v3pos_t &dirp : dirs4) { u32 i2 = i; // Move to side VoxelArea::add_p(em, i2, dirp); @@ -854,7 +854,7 @@ void MapgenV6::flowMud(POS &mudflow_minpos, POS &mudflow_maxpos) continue; // Loop further down until not air - POS y2 = y - 1; // y of i2 + pos_t y2 = y - 1; // y of i2 bool dropped_to_unknown = false; do { y2--; @@ -885,7 +885,7 @@ void MapgenV6::flowMud(POS &mudflow_minpos, POS &mudflow_maxpos) void MapgenV6::moveMud(u32 remove_index, u32 place_index, - u32 above_remove_index, v2POS pos, v3POS em) + u32 above_remove_index, v2pos_t pos, v3pos_t em) { MapNode n_air(CONTENT_AIR); // Copy mud from old place to new place @@ -935,7 +935,7 @@ void MapgenV6::placeTreesAndJungleGrass() if (c_junglegrass == CONTENT_IGNORE) c_junglegrass = CONTENT_AIR; MapNode n_junglegrass(c_junglegrass); - const v3POS &em = vm->m_area.getExtent(); + const v3pos_t &em = vm->m_area.getExtent(); // Divide area into parts s16 div = 8; @@ -947,17 +947,17 @@ void MapgenV6::placeTreesAndJungleGrass() for (s16 z0 = 0; z0 < div; z0++) for (s16 x0 = 0; x0 < div; x0++) { // Center position of part of division - v2POS p2d_center( + v2pos_t p2d_center( node_min.X + sidelen / 2 + sidelen * x0, node_min.Z + sidelen / 2 + sidelen * z0 ); // Minimum edge of part of division - v2POS p2d_min( + v2pos_t p2d_min( node_min.X + sidelen * x0, node_min.Z + sidelen * z0 ); // Maximum edge of part of division - v2POS p2d_max( + v2pos_t p2d_max( node_min.X + sidelen + sidelen * x0 - 1, node_min.Z + sidelen + sidelen * z0 - 1 ); @@ -980,11 +980,11 @@ void MapgenV6::placeTreesAndJungleGrass() float humidity = getHumidity(p2d_center); u32 grass_count = 5 * humidity * tree_count; for (u32 i = 0; i < grass_count; i++) { - POS x = grassrandom.range(p2d_min.X, p2d_max.X); - POS z = grassrandom.range(p2d_min.Y, p2d_max.Y); + pos_t x = grassrandom.range(p2d_min.X, p2d_max.X); + pos_t z = grassrandom.range(p2d_min.Y, p2d_max.Y); int mapindex = central_area_size.X * (z - node_min.Z) + (x - node_min.X); - POS y = heightmap[mapindex]; + pos_t y = heightmap[mapindex]; if (y < water_level) continue; @@ -999,17 +999,17 @@ void MapgenV6::placeTreesAndJungleGrass() // Put trees in random places on part of division for (u32 i = 0; i < tree_count; i++) { - POS x = myrand_range(p2d_min.X, p2d_max.X); - POS z = myrand_range(p2d_min.Y, p2d_max.Y); + pos_t x = myrand_range(p2d_min.X, p2d_max.X); + pos_t z = myrand_range(p2d_min.Y, p2d_max.Y); int mapindex = central_area_size.X * (z - node_min.Z) + (x - node_min.X); - POS y = heightmap[mapindex]; + pos_t y = heightmap[mapindex]; // Don't make a tree under water level // Don't make a tree so high that it doesn't fit if (y < water_level || y > node_max.Y - 6) continue; - v3POS p(x, y, z); + v3pos_t p(x, y, z); // Trees grow only on mud and grass { u32 i = vm->m_area.index(p); @@ -1025,10 +1025,10 @@ void MapgenV6::placeTreesAndJungleGrass() if (bt == BT_JUNGLE) { treegen::make_jungletree(*vm, p, ndef, myrand()); } else if (bt == BT_TAIGA) { - treegen::make_pine_tree(*vm, p - v3POS(0, 1, 0), ndef, myrand()); + treegen::make_pine_tree(*vm, p - v3pos_t(0, 1, 0), ndef, myrand()); } else if (bt == BT_NORMAL) { bool is_apple_tree = (myrand_range(0, 3) == 0) && - getHaveAppleTree(v2POS(x, z)); + getHaveAppleTree(v2pos_t(x, z)); treegen::make_tree(*vm, p, is_apple_tree, ndef, myrand()); } } @@ -1042,17 +1042,17 @@ void MapgenV6::growGrass() // Add surface nodes MapNode n_dirt_with_grass(c_dirt_with_grass); MapNode n_dirt_with_snow(c_dirt_with_snow); MapNode n_snowblock(c_snowblock); - const v3POS &em = vm->m_area.getExtent(); + const v3pos_t &em = vm->m_area.getExtent(); u32 index = 0; - for (POS z = full_node_min.Z; z <= full_node_max.Z; z++) - for (POS x = full_node_min.X; x <= full_node_max.X; x++, index++) { + for (pos_t z = full_node_min.Z; z <= full_node_max.Z; z++) + for (pos_t x = full_node_min.X; x <= full_node_max.X; x++, index++) { // Find the lowest surface to which enough light ends up to make // grass grow. Basically just wait until not air and not leaves. - POS surface_y = 0; + pos_t surface_y = 0; { u32 i = vm->m_area.index(x, node_max.Y, z); - POS y; + pos_t y; // Go to ground level for (y = node_max.Y; y >= full_node_min.Y; y--) { MapNode &n = vm->m_data[i]; @@ -1065,7 +1065,7 @@ void MapgenV6::growGrass() // Add surface nodes surface_y = (y >= full_node_min.Y) ? y : full_node_min.Y; } - BiomeV6Type bt = getBiome(index, v2POS(x, z)); + BiomeV6Type bt = getBiome(index, v2pos_t(x, z)); u32 i = vm->m_area.index(x, surface_y, z); content_t c = vm->m_data[i].getContent(); if (surface_y >= water_level - 20) { @@ -1102,7 +1102,7 @@ void MapgenV6::generateCaves(int max_stone_y) if (ps.range(1, 6) == 1) bruises_count = ps.range(0, ps.range(0, 2)); - if (getBiome(v2POS(node_min.X, node_min.Z)) == BT_DESERT) { + if (getBiome(v2pos_t(node_min.X, node_min.Z)) == BT_DESERT) { caves_count /= 3; bruises_count /= 3; } diff --git a/src/mapgen/mapgen_v6.h b/src/mapgen/mapgen_v6.h index 445505bd6d..e7cfb76d77 100644 --- a/src/mapgen/mapgen_v6.h +++ b/src/mapgen/mapgen_v6.h @@ -57,8 +57,8 @@ enum BiomeV6Type struct MapgenV6Params : public MapgenParams { float freq_desert = 0.45f; float freq_beach = 0.15f; - POS dungeon_ymin = -MAX_MAP_GENERATION_LIMIT; - POS dungeon_ymax = MAX_MAP_GENERATION_LIMIT; + pos_t dungeon_ymin = -MAX_MAP_GENERATION_LIMIT; + pos_t dungeon_ymax = MAX_MAP_GENERATION_LIMIT; NoiseParams np_terrain_base; NoiseParams np_terrain_higher; @@ -88,11 +88,11 @@ class MapgenV6 : public Mapgen { int ystride; u32 spflags; - v3POS node_min; - v3POS node_max; - v3POS full_node_min; - v3POS full_node_max; - v3POS central_area_size; + v3pos_t node_min; + v3pos_t node_max; + v3pos_t full_node_min; + v3pos_t full_node_max; + v3pos_t central_area_size; Noise *noise_terrain_base; Noise *noise_terrain_higher; @@ -111,8 +111,8 @@ class MapgenV6 : public Mapgen { float freq_desert; float freq_beach; - POS dungeon_ymin; - POS dungeon_ymax; + pos_t dungeon_ymin; + pos_t dungeon_ymax; content_t c_stone; content_t c_dirt; @@ -139,34 +139,34 @@ class MapgenV6 : public Mapgen { virtual MapgenType getType() const { return MAPGEN_V6; } void makeChunk(BlockMakeData *data); - int getGroundLevelAtPoint(v2POS p); - int getSpawnLevelAtPoint(v2POS p); + int getGroundLevelAtPoint(v2pos_t p); + int getSpawnLevelAtPoint(v2pos_t p); float baseTerrainLevel(float terrain_base, float terrain_higher, float steepness, float height_select); - virtual float baseTerrainLevelFromNoise(v2POS p); - virtual float baseTerrainLevelFromMap(v2POS p); + virtual float baseTerrainLevelFromNoise(v2pos_t p); + virtual float baseTerrainLevelFromMap(v2pos_t p); virtual float baseTerrainLevelFromMap(int index); - POS find_stone_level(v2POS p2d); - bool block_is_underground(u64 seed, v3POS blockpos); + pos_t find_stone_level(v2pos_t p2d); + bool block_is_underground(u64 seed, v3pos_t blockpos); - float getHumidity(v2POS p); - float getTreeAmount(v2POS p); - bool getHaveAppleTree(v2POS p); + float getHumidity(v2pos_t p); + float getTreeAmount(v2pos_t p); + bool getHaveAppleTree(v2pos_t p); float getMudAmount(int index); bool getHaveBeach(int index); - BiomeV6Type getBiome(v2POS p); - BiomeV6Type getBiome(int index, v2POS p); + BiomeV6Type getBiome(v2pos_t p); + BiomeV6Type getBiome(int index, v2pos_t p); - u32 get_blockseed(u64 seed, v3POS p); + u32 get_blockseed(u64 seed, v3pos_t p); virtual void calculateNoise(); int generateGround(); void addMud(); - void flowMud(POS &mudflow_minpos, POS &mudflow_maxpos); + void flowMud(pos_t &mudflow_minpos, pos_t &mudflow_maxpos); void moveMud(u32 remove_index, u32 place_index, - u32 above_remove_index, v2POS pos, v3POS em); + u32 above_remove_index, v2pos_t pos, v3pos_t em); void growGrass(); void placeTreesAndJungleGrass(); virtual void generateCaves(int max_stone_y); diff --git a/src/mapgen/mapgen_v7.cpp b/src/mapgen/mapgen_v7.cpp index d81f3388a3..a261e27a8a 100644 --- a/src/mapgen/mapgen_v7.cpp +++ b/src/mapgen/mapgen_v7.cpp @@ -261,7 +261,7 @@ void MapgenV7Params::setDefaultSettings(Settings *settings) //////////////////////////////////////////////////////////////////////////////// -int MapgenV7::getSpawnLevelAtPoint(v2POS p) +int MapgenV7::getSpawnLevelAtPoint(v2pos_t p) { // If rivers are enabled, first check if in a river if (spflags & MGV7_RIDGES) { @@ -277,11 +277,11 @@ int MapgenV7::getSpawnLevelAtPoint(v2POS p) // 'offset's. // Raising the maximum spawn level above 'water_level + 16' is necessary // for when terrain 'offset's are set much higher than water_level. - POS max_spawn_y = std::fmax(std::fmax(noise_terrain_alt->np.offset, + pos_t max_spawn_y = std::fmax(std::fmax(noise_terrain_alt->np.offset, noise_terrain_base->np.offset), water_level + 16); // Base terrain calculation - POS y = baseTerrainLevelAtPoint(p.X, p.Y); + pos_t y = baseTerrainLevelAtPoint(p.X, p.Y); // If mountains are disabled, terrain level is base terrain level. // Avoids mid-air spawn where mountain terrain would have been. @@ -324,17 +324,17 @@ void MapgenV7::makeChunk(BlockMakeData *data) this->vm = data->vmanip; this->ndef = data->nodedef; - v3POS blockpos_min = data->blockpos_min; - v3POS blockpos_max = data->blockpos_max; + v3pos_t blockpos_min = data->blockpos_min; + v3pos_t blockpos_max = data->blockpos_max; node_min = blockpos_min * MAP_BLOCKSIZE; - node_max = (blockpos_max + v3POS(1, 1, 1)) * MAP_BLOCKSIZE - v3POS(1, 1, 1); + node_max = (blockpos_max + v3pos_t(1, 1, 1)) * MAP_BLOCKSIZE - v3pos_t(1, 1, 1); full_node_min = (blockpos_min - 1) * MAP_BLOCKSIZE; - full_node_max = (blockpos_max + 2) * MAP_BLOCKSIZE - v3POS(1, 1, 1); + full_node_max = (blockpos_max + 2) * MAP_BLOCKSIZE - v3pos_t(1, 1, 1); blockseed = getBlockSeed2(full_node_min, seed); // Generate base and mountain terrain - POS stone_surface_max_y = generateTerrain(); + pos_t stone_surface_max_y = generateTerrain(); // Create heightmap updateHeightmap(node_min, node_max); @@ -391,7 +391,7 @@ void MapgenV7::makeChunk(BlockMakeData *data) node_max.Y >= floatland_ymin - csize.Y * 2 && node_min.Y <= floatland_ymax); if (flags & MG_LIGHT) - calcLighting(node_min - v3POS(0, 1, 0), node_max + v3POS(0, 1, 0), + calcLighting(node_min - v3pos_t(0, 1, 0), node_max + v3pos_t(0, 1, 0), full_node_min, full_node_max, propagate_shadow); this->generating = false; @@ -403,7 +403,7 @@ void MapgenV7::makeChunk(BlockMakeData *data) //////////////////////////////////////////////////////////////////////////////// -float MapgenV7::baseTerrainLevelAtPoint(POS x, POS z) +float MapgenV7::baseTerrainLevelAtPoint(pos_t x, pos_t z) { float hselect = NoisePerlin2D(&noise_height_select->np, x, z, seed); hselect = rangelim(hselect, 0.0f, 1.0f); @@ -436,7 +436,7 @@ float MapgenV7::baseTerrainLevelFromMap(int index) } -bool MapgenV7::getMountainTerrainAtPoint(POS x, POS y, POS z) +bool MapgenV7::getMountainTerrainAtPoint(pos_t x, pos_t y, pos_t z) { float mnt_h_n = std::fmax(NoisePerlin2D(&noise_mount_height->np, x, z, seed), 1.0f); @@ -447,7 +447,7 @@ bool MapgenV7::getMountainTerrainAtPoint(POS x, POS y, POS z) } -bool MapgenV7::getMountainTerrainFromMap(int idx_xyz, int idx_xz, POS y) +bool MapgenV7::getMountainTerrainFromMap(int idx_xyz, int idx_xz, pos_t y) { float mounthn = std::fmax(noise_mount_height->result[idx_xz], 1.0f); float density_gradient = -((float)(y - mount_zero_level) / mounthn); @@ -457,7 +457,7 @@ bool MapgenV7::getMountainTerrainFromMap(int idx_xyz, int idx_xz, POS y) } -bool MapgenV7::getRiverChannelFromMap(int idx_xyz, int idx_xz, POS y) +bool MapgenV7::getRiverChannelFromMap(int idx_xyz, int idx_xz, pos_t y) { // Maximum width of river channel. Creates the vertical canyon walls float width = 0.2f; @@ -505,8 +505,8 @@ int MapgenV7::generateTerrain() bool gen_floatlands = false; u8 cache_index = 0; // Y values where floatland tapering starts - POS float_taper_ymax = floatland_ymax - floatland_taper; - POS float_taper_ymin = floatland_ymin + floatland_taper; + pos_t float_taper_ymax = floatland_ymax - floatland_taper; + pos_t float_taper_ymin = floatland_ymin + floatland_taper; if ((spflags & MGV7_FLOATLANDS) && node_max.Y >= floatland_ymin && node_min.Y <= floatland_ymax) { @@ -515,7 +515,7 @@ int MapgenV7::generateTerrain() noise_floatland->perlinMap3D(node_min.X, node_min.Y - 1, node_min.Z); // Cache floatland noise offset values, for floatland tapering - for (POS y = node_min.Y - 1; y <= node_max.Y + 1; y++, cache_index++) { + for (pos_t y = node_min.Y - 1; y <= node_max.Y + 1; y++, cache_index++) { float float_offset = 0.0f; if (y > float_taper_ymax) { float_offset = std::pow((y - float_taper_ymax) / (float)floatland_taper, @@ -538,13 +538,13 @@ int MapgenV7::generateTerrain() } //// Place nodes - const v3POS &em = vm->m_area.getExtent(); - POS stone_surface_max_y = -MAX_MAP_GENERATION_LIMIT; + const v3pos_t &em = vm->m_area.getExtent(); + pos_t stone_surface_max_y = -MAX_MAP_GENERATION_LIMIT; u32 index2d = 0; - for (POS z = node_min.Z; z <= node_max.Z; z++) - for (POS x = node_min.X; x <= node_max.X; x++, index2d++) { - POS surface_y = baseTerrainLevelFromMap(index2d); + for (pos_t z = node_min.Z; z <= node_max.Z; z++) + for (pos_t x = node_min.X; x <= node_max.X; x++, index2d++) { + pos_t surface_y = baseTerrainLevelFromMap(index2d); if (surface_y > stone_surface_max_y) stone_surface_max_y = surface_y; @@ -552,7 +552,7 @@ int MapgenV7::generateTerrain() 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 (POS y = node_min.Y - 1; y <= node_max.Y + 1; + for (pos_t y = node_min.Y - 1; y <= node_max.Y + 1; y++, index3d += ystride, VoxelArea::add_y(em, vi, 1), diff --git a/src/mapgen/mapgen_v7.h b/src/mapgen/mapgen_v7.h index c1fc864d03..d6b41bcbd6 100644 --- a/src/mapgen/mapgen_v7.h +++ b/src/mapgen/mapgen_v7.h @@ -35,26 +35,26 @@ extern FlagDesc flagdesc_mapgen_v7[]; struct MapgenV7Params : public MapgenParams { - POS mount_zero_level = 0; - POS floatland_ymin = 1024; - POS floatland_ymax = 4096; - POS floatland_taper = 256; + pos_t mount_zero_level = 0; + pos_t floatland_ymin = 1024; + pos_t floatland_ymax = 4096; + pos_t floatland_taper = 256; float float_taper_exp = 2.0f; float floatland_density = -0.6f; - POS floatland_ywater = -MAX_MAP_GENERATION_LIMIT; + pos_t floatland_ywater = -MAX_MAP_GENERATION_LIMIT; float cave_width = 0.09f; - POS large_cave_depth = -33; + pos_t large_cave_depth = -33; u16 small_cave_num_min = 0; u16 small_cave_num_max = 0; u16 large_cave_num_min = 0; u16 large_cave_num_max = 2; float large_cave_flooded = 0.5f; - POS cavern_limit = -256; - POS cavern_taper = 256; + pos_t cavern_limit = -256; + pos_t cavern_taper = 256; float cavern_threshold = 0.7f; - POS dungeon_ymin = -MAX_MAP_GENERATION_LIMIT; - POS dungeon_ymax = MAX_MAP_GENERATION_LIMIT; + pos_t dungeon_ymin = -MAX_MAP_GENERATION_LIMIT; + pos_t dungeon_ymax = MAX_MAP_GENERATION_LIMIT; NoiseParams np_terrain_base; NoiseParams np_terrain_alt; @@ -88,25 +88,25 @@ class MapgenV7 : public MapgenBasic { virtual MapgenType getType() const { return MAPGEN_V7; } virtual void makeChunk(BlockMakeData *data); - int getSpawnLevelAtPoint(v2POS p); + int getSpawnLevelAtPoint(v2pos_t p); - float baseTerrainLevelAtPoint(POS x, POS z); + float baseTerrainLevelAtPoint(pos_t x, pos_t z); float baseTerrainLevelFromMap(int index); - bool getMountainTerrainAtPoint(POS x, POS y, POS z); - bool getMountainTerrainFromMap(int idx_xyz, int idx_xz, POS y); - bool getRiverChannelFromMap(int idx_xyz, int idx_xz, POS y); + bool getMountainTerrainAtPoint(pos_t x, pos_t y, pos_t z); + bool getMountainTerrainFromMap(int idx_xyz, int idx_xz, pos_t y); + bool getRiverChannelFromMap(int idx_xyz, int idx_xz, pos_t y); bool getFloatlandTerrainFromMap(int idx_xyz, float float_offset); int generateTerrain(); private: - POS mount_zero_level; - POS floatland_ymin; - POS floatland_ymax; - POS floatland_taper; + pos_t mount_zero_level; + pos_t floatland_ymin; + pos_t floatland_ymax; + pos_t floatland_taper; float float_taper_exp; float floatland_density; - POS floatland_ywater; + pos_t floatland_ywater; float *float_offset_cache = nullptr; diff --git a/src/mapgen/mapgen_valleys.cpp b/src/mapgen/mapgen_valleys.cpp index 8c659244e4..28b3e7a460 100644 --- a/src/mapgen/mapgen_valleys.cpp +++ b/src/mapgen/mapgen_valleys.cpp @@ -218,12 +218,12 @@ void MapgenValleys::makeChunk(BlockMakeData *data) this->vm = data->vmanip; this->ndef = data->nodedef; - v3POS blockpos_min = data->blockpos_min; - v3POS blockpos_max = data->blockpos_max; + v3pos_t blockpos_min = data->blockpos_min; + v3pos_t blockpos_max = data->blockpos_max; node_min = blockpos_min * MAP_BLOCKSIZE; - node_max = (blockpos_max + v3POS(1, 1, 1)) * MAP_BLOCKSIZE - v3POS(1, 1, 1); + node_max = (blockpos_max + v3pos_t(1, 1, 1)) * MAP_BLOCKSIZE - v3pos_t(1, 1, 1); full_node_min = (blockpos_min - 1) * MAP_BLOCKSIZE; - full_node_max = (blockpos_max + 2) * MAP_BLOCKSIZE - v3POS(1, 1, 1); + full_node_max = (blockpos_max + 2) * MAP_BLOCKSIZE - v3pos_t(1, 1, 1); blockseed = getBlockSeed2(full_node_min, seed); @@ -233,7 +233,7 @@ void MapgenValleys::makeChunk(BlockMakeData *data) m_bgen->calcBiomeNoise(node_min); // Generate terrain - POS stone_surface_max_y = generateTerrain(); + pos_t stone_surface_max_y = generateTerrain(); // Create heightmap updateHeightmap(node_min, node_max); @@ -281,7 +281,7 @@ void MapgenValleys::makeChunk(BlockMakeData *data) updateLiquid(&data->transforming_liquid, full_node_min, full_node_max); if (flags & MG_LIGHT) - calcLighting(node_min - v3POS(0, 1, 0), node_max + v3POS(0, 1, 0), + calcLighting(node_min - v3pos_t(0, 1, 0), node_max + v3pos_t(0, 1, 0), full_node_min, full_node_max); this->generating = false; @@ -290,7 +290,7 @@ void MapgenValleys::makeChunk(BlockMakeData *data) } -int MapgenValleys::getSpawnLevelAtPoint(v2POS p) +int MapgenValleys::getSpawnLevelAtPoint(v2pos_t p) { // Check if in a river channel float n_rivers = NoisePerlin2D(&noise_rivers->np, p.X, p.Y, seed); @@ -314,14 +314,14 @@ int MapgenValleys::getSpawnLevelAtPoint(v2POS p) // Raising the maximum spawn level above 'water_level + 16' is necessary for custom // parameters that set average terrain level much higher than water_level. - POS max_spawn_y = std::fmax( + pos_t max_spawn_y = std::fmax( noise_terrain_height->np.offset + noise_valley_depth->np.offset * noise_valley_depth->np.offset, water_level + 16); // Starting spawn search at max_spawn_y + 128 ensures 128 nodes of open // space above spawn position. Avoids spawning in possibly sealed voids. - for (POS y = max_spawn_y + 128; y >= water_level; y--) { + for (pos_t y = max_spawn_y + 128; y >= water_level; y--) { float n_fill = NoisePerlin3D(&noise_inter_valley_fill->np, p.X, y, p.Y, seed); float surface_delta = (float)y - surface_y; float density = slope * n_fill - surface_delta; @@ -357,12 +357,12 @@ int MapgenValleys::generateTerrain() noise_inter_valley_fill->perlinMap3D(node_min.X, node_min.Y - 1, node_min.Z); - const v3POS &em = vm->m_area.getExtent(); - POS surface_max_y = -MAX_MAP_GENERATION_LIMIT; + const v3pos_t &em = vm->m_area.getExtent(); + pos_t surface_max_y = -MAX_MAP_GENERATION_LIMIT; u32 index_2d = 0; - for (POS z = node_min.Z; z <= node_max.Z; z++) - for (POS x = node_min.X; x <= node_max.X; x++, index_2d++) { + for (pos_t z = node_min.Z; z <= node_max.Z; z++) + for (pos_t x = node_min.X; x <= node_max.X; x++, index_2d++) { float n_slope = noise_inter_valley_slope->result[index_2d]; float n_rivers = noise_rivers->result[index_2d]; float n_terrain_height = noise_terrain_height->result[index_2d]; @@ -415,11 +415,11 @@ int MapgenValleys::generateTerrain() } // Highest solid node in column - POS column_max_y = surface_y; + pos_t column_max_y = surface_y; u32 index_3d = (z - node_min.Z) * zstride_1u1d + (x - node_min.X); u32 index_data = vm->m_area.index(x, node_min.Y - 1, z); - for (POS y = node_min.Y - 1; y <= node_max.Y + 1; y++) { + for (pos_t y = node_min.Y - 1; y <= node_max.Y + 1; y++) { if (vm->m_data[index_data].getContent() == CONTENT_IGNORE) { float n_fill = noise_inter_valley_fill->result[index_3d]; float surface_delta = (float)y - surface_y; @@ -434,7 +434,7 @@ int MapgenValleys::generateTerrain() column_max_y = y; } else if (y <= water_level) { vm->m_data[index_data] = n_water; // Water - } else if (y <= (POS)river_y) { + } else if (y <= (pos_t)river_y) { vm->m_data[index_data] = n_river_water; // River water } else { vm->m_data[index_data] = n_air; // Air diff --git a/src/mapgen/mapgen_valleys.h b/src/mapgen/mapgen_valleys.h index d74fc6c44c..6eda2322ff 100644 --- a/src/mapgen/mapgen_valleys.h +++ b/src/mapgen/mapgen_valleys.h @@ -46,17 +46,17 @@ struct MapgenValleysParams : public MapgenParams { u16 river_size = 5; float cave_width = 0.09f; - POS large_cave_depth = -33; + pos_t large_cave_depth = -33; u16 small_cave_num_min = 0; u16 small_cave_num_max = 0; u16 large_cave_num_min = 0; u16 large_cave_num_max = 2; float large_cave_flooded = 0.5f; - POS cavern_limit = -256; - POS cavern_taper = 192; + pos_t cavern_limit = -256; + pos_t cavern_taper = 192; float cavern_threshold = 0.6f; - POS dungeon_ymin = -MAX_MAP_GENERATION_LIMIT; - POS dungeon_ymax = 63; + pos_t dungeon_ymin = -MAX_MAP_GENERATION_LIMIT; + pos_t dungeon_ymax = 63; NoiseParams np_filler_depth; NoiseParams np_inter_valley_fill; @@ -90,7 +90,7 @@ class MapgenValleys : public MapgenBasic { virtual MapgenType getType() const { return MAPGEN_VALLEYS; } virtual void makeChunk(BlockMakeData *data); - int getSpawnLevelAtPoint(v2POS p); + int getSpawnLevelAtPoint(v2pos_t p); private: BiomeGenOriginal *m_bgen; diff --git a/src/mapgen/mg_biome.cpp b/src/mapgen/mg_biome.cpp index 8c3eaf9327..82672e490b 100644 --- a/src/mapgen/mg_biome.cpp +++ b/src/mapgen/mg_biome.cpp @@ -46,9 +46,9 @@ BiomeManager::BiomeManager(Server *server) : b->depth_filler = -MAX_MAP_GENERATION_LIMIT; b->depth_water_top = 0; b->depth_riverbed = 0; - b->min_pos = v3POS(-MAX_MAP_GENERATION_LIMIT, + b->min_pos = v3pos_t(-MAX_MAP_GENERATION_LIMIT, -MAX_MAP_GENERATION_LIMIT, -MAX_MAP_GENERATION_LIMIT); - b->max_pos = v3POS(MAX_MAP_GENERATION_LIMIT, + b->max_pos = v3pos_t(MAX_MAP_GENERATION_LIMIT, MAX_MAP_GENERATION_LIMIT, MAX_MAP_GENERATION_LIMIT); b->heat_point = 0.0; b->humidity_point = 0.0; @@ -124,7 +124,7 @@ void BiomeParamsOriginal::writeParams(Settings *settings) const //////////////////////////////////////////////////////////////////////////////// BiomeGenOriginal::BiomeGenOriginal(BiomeManager *biomemgr, - const BiomeParamsOriginal *params, v3POS chunksize) + const BiomeParamsOriginal *params, v3pos_t chunksize) { m_bmgr = biomemgr; m_params = params; @@ -164,25 +164,25 @@ BiomeGen *BiomeGenOriginal::clone(BiomeManager *biomemgr) const return new BiomeGenOriginal(biomemgr, m_params, m_csize); } -float BiomeGenOriginal::calcHeatAtPoint(v3POS pos) const +float BiomeGenOriginal::calcHeatAtPoint(v3pos_t pos) const { return NoisePerlin2D(&m_params->np_heat, pos.X, pos.Z, m_params->seed) + NoisePerlin2D(&m_params->np_heat_blend, pos.X, pos.Z, m_params->seed); } -float BiomeGenOriginal::calcHumidityAtPoint(v3POS pos) const +float BiomeGenOriginal::calcHumidityAtPoint(v3pos_t pos) const { return NoisePerlin2D(&m_params->np_humidity, pos.X, pos.Z, m_params->seed) + NoisePerlin2D(&m_params->np_humidity_blend, pos.X, pos.Z, m_params->seed); } -Biome *BiomeGenOriginal::calcBiomeAtPoint(v3POS pos) const +Biome *BiomeGenOriginal::calcBiomeAtPoint(v3pos_t pos) const { return calcBiomeFromNoise(calcHeatAtPoint(pos), calcHumidityAtPoint(pos), pos); } -void BiomeGenOriginal::calcBiomeNoise(v3POS pmin) +void BiomeGenOriginal::calcBiomeNoise(v3pos_t pmin) { m_pmin = pmin; @@ -198,7 +198,7 @@ void BiomeGenOriginal::calcBiomeNoise(v3POS pmin) } -biome_t *BiomeGenOriginal::getBiomes(POS *heightmap, v3POS pmin) +biome_t *BiomeGenOriginal::getBiomes(pos_t *heightmap, v3pos_t pmin) { for (s16 zr = 0; zr < m_csize.Z; zr++) for (s16 xr = 0; xr < m_csize.X; xr++) { @@ -206,7 +206,7 @@ biome_t *BiomeGenOriginal::getBiomes(POS *heightmap, v3POS pmin) Biome *biome = calcBiomeFromNoise( noise_heat->result[i], noise_humidity->result[i], - v3POS(pmin.X + xr, heightmap[i], pmin.Z + zr)); + v3pos_t(pmin.X + xr, heightmap[i], pmin.Z + zr)); biomemap[i] = biome->index; } @@ -215,7 +215,7 @@ biome_t *BiomeGenOriginal::getBiomes(POS *heightmap, v3POS pmin) } -Biome *BiomeGenOriginal::getBiomeAtPoint(v3POS pos) const +Biome *BiomeGenOriginal::getBiomeAtPoint(v3pos_t pos) const { return getBiomeAtIndex( (pos.Z - m_pmin.Z) * m_csize.X + (pos.X - m_pmin.X), @@ -223,7 +223,7 @@ Biome *BiomeGenOriginal::getBiomeAtPoint(v3POS pos) const } -Biome *BiomeGenOriginal::getBiomeAtIndex(size_t index, v3POS pos) const +Biome *BiomeGenOriginal::getBiomeAtIndex(size_t index, v3pos_t pos) const { return calcBiomeFromNoise( noise_heat->result[index], @@ -232,7 +232,7 @@ Biome *BiomeGenOriginal::getBiomeAtIndex(size_t index, v3POS pos) const } -Biome *BiomeGenOriginal::calcBiomeFromNoise(float heat, float humidity, v3POS pos) const +Biome *BiomeGenOriginal::calcBiomeFromNoise(float heat, float humidity, v3pos_t pos) const { Biome *biome_closest = nullptr; Biome *biome_closest_blend = nullptr; diff --git a/src/mapgen/mg_biome.h b/src/mapgen/mg_biome.h index 3e5024a975..62e1748697 100644 --- a/src/mapgen/mg_biome.h +++ b/src/mapgen/mg_biome.h @@ -59,16 +59,16 @@ class Biome : public ObjDef, public NodeResolver { content_t c_dungeon_alt; content_t c_dungeon_stair; - POS depth_top; - POS depth_filler; - POS depth_water_top; - POS depth_riverbed; + pos_t depth_top; + pos_t depth_filler; + pos_t depth_water_top; + pos_t depth_riverbed; - v3POS min_pos; - v3POS max_pos; + v3pos_t min_pos; + v3pos_t max_pos; float heat_point; float humidity_point; - POS vertical_blend; + pos_t vertical_blend; virtual void resolveNodeNames(); }; @@ -101,7 +101,7 @@ class BiomeGen { virtual BiomeGen *clone(BiomeManager *biomemgr) const = 0; // Check that the internal chunk size is what the mapgen expects, just to be sure. - inline void assertChunkSize(v3POS expect) const + inline void assertChunkSize(v3pos_t expect) const { FATAL_ERROR_IF(m_csize != expect, "Chunk size mismatches"); } @@ -109,32 +109,32 @@ class BiomeGen { // Calculates the biome at the exact position provided. This function can // be called at any time, but may be less efficient than the latter methods, // depending on implementation. - virtual Biome *calcBiomeAtPoint(v3POS pos) const = 0; + virtual Biome *calcBiomeAtPoint(v3pos_t pos) const = 0; // Computes any intermediate results needed for biome generation. Must be // called before using any of: getBiomes, getBiomeAtPoint, or getBiomeAtIndex. // Calling this invalidates the previous results stored in biomemap. - virtual void calcBiomeNoise(v3POS pmin) = 0; + virtual void calcBiomeNoise(v3pos_t pmin) = 0; // Gets all biomes in current chunk using each corresponding element of // heightmap as the y position, then stores the results by biome index in // biomemap (also returned) - virtual biome_t *getBiomes(POS *heightmap, v3POS pmin) = 0; + virtual biome_t *getBiomes(pos_t *heightmap, v3pos_t pmin) = 0; // Gets a single biome at the specified position, which must be contained // in the region formed by m_pmin and (m_pmin + m_csize - 1). - virtual Biome *getBiomeAtPoint(v3POS pos) const = 0; + virtual Biome *getBiomeAtPoint(v3pos_t pos) const = 0; // Same as above, but uses a raw numeric index correlating to the (x,z) position. - virtual Biome *getBiomeAtIndex(size_t index, v3POS pos) const = 0; + virtual Biome *getBiomeAtIndex(size_t index, v3pos_t pos) const = 0; // Result of calcBiomes bulk computation. biome_t *biomemap = nullptr; protected: BiomeManager *m_bmgr = nullptr; - v3POS m_pmin; - v3POS m_csize; + v3pos_t m_pmin; + v3pos_t m_csize; }; @@ -167,7 +167,7 @@ struct BiomeParamsOriginal : public BiomeParams { class BiomeGenOriginal : public BiomeGen { public: BiomeGenOriginal(BiomeManager *biomemgr, - const BiomeParamsOriginal *params, v3POS chunksize); + const BiomeParamsOriginal *params, v3pos_t chunksize); virtual ~BiomeGenOriginal(); BiomeGenType getType() const { return BIOMEGEN_ORIGINAL; } @@ -175,17 +175,17 @@ class BiomeGenOriginal : public BiomeGen { BiomeGen *clone(BiomeManager *biomemgr) const; // Slower, meant for Script API use - float calcHeatAtPoint(v3POS pos) const; - float calcHumidityAtPoint(v3POS pos) const; - Biome *calcBiomeAtPoint(v3POS pos) const; + float calcHeatAtPoint(v3pos_t pos) const; + float calcHumidityAtPoint(v3pos_t pos) const; + Biome *calcBiomeAtPoint(v3pos_t pos) const; - void calcBiomeNoise(v3POS pmin); + void calcBiomeNoise(v3pos_t pmin); - biome_t *getBiomes(POS *heightmap, v3POS pmin); - Biome *getBiomeAtPoint(v3POS pos) const; - Biome *getBiomeAtIndex(size_t index, v3POS pos) const; + biome_t *getBiomes(pos_t *heightmap, v3pos_t pmin); + Biome *getBiomeAtPoint(v3pos_t pos) const; + Biome *getBiomeAtIndex(size_t index, v3pos_t pos) const; - Biome *calcBiomeFromNoise(float heat, float humidity, v3POS pos) const; + Biome *calcBiomeFromNoise(float heat, float humidity, v3pos_t pos) const; float *heatmap; float *humidmap; @@ -221,7 +221,7 @@ class BiomeManager : public ObjDefManager { return new Biome; } - BiomeGen *createBiomeGen(BiomeGenType type, BiomeParams *params, v3POS chunksize) + BiomeGen *createBiomeGen(BiomeGenType type, BiomeParams *params, v3pos_t chunksize) { switch (type) { case BIOMEGEN_ORIGINAL: diff --git a/src/mapgen/mg_decoration.cpp b/src/mapgen/mg_decoration.cpp index 25ed2f55f3..54224aec40 100644 --- a/src/mapgen/mg_decoration.cpp +++ b/src/mapgen/mg_decoration.cpp @@ -51,7 +51,7 @@ DecorationManager::DecorationManager(IGameDef *gamedef) : size_t DecorationManager::placeAllDecos(Mapgen *mg, u32 blockseed, - v3POS nmin, v3POS nmax) + v3pos_t nmin, v3pos_t nmax) { size_t nplaced = 0; @@ -85,7 +85,7 @@ void Decoration::resolveNodeNames() } -bool Decoration::canPlaceDecoration(MMVManip *vm, v3POS p) +bool Decoration::canPlaceDecoration(MMVManip *vm, v3pos_t p) { // Check if the decoration can be placed on this node u32 vi = vm->m_area.index(p); @@ -97,24 +97,24 @@ bool Decoration::canPlaceDecoration(MMVManip *vm, v3POS p) return true; int nneighs = 0; - static const v3POS dirs[16] = { - v3POS( 0, 0, 1), - v3POS( 0, 0, -1), - v3POS( 1, 0, 0), - v3POS(-1, 0, 0), - v3POS( 1, 0, 1), - v3POS(-1, 0, 1), - v3POS(-1, 0, -1), - v3POS( 1, 0, -1), - - v3POS( 0, 1, 1), - v3POS( 0, 1, -1), - v3POS( 1, 1, 0), - v3POS(-1, 1, 0), - v3POS( 1, 1, 1), - v3POS(-1, 1, 1), - v3POS(-1, 1, -1), - v3POS( 1, 1, -1) + static const v3pos_t dirs[16] = { + v3pos_t( 0, 0, 1), + v3pos_t( 0, 0, -1), + v3pos_t( 1, 0, 0), + v3pos_t(-1, 0, 0), + v3pos_t( 1, 0, 1), + v3pos_t(-1, 0, 1), + v3pos_t(-1, 0, -1), + v3pos_t( 1, 0, -1), + + v3pos_t( 0, 1, 1), + v3pos_t( 0, 1, -1), + v3pos_t( 1, 1, 0), + v3pos_t(-1, 1, 0), + v3pos_t( 1, 1, 1), + v3pos_t(-1, 1, 1), + v3pos_t(-1, 1, -1), + v3pos_t( 1, 1, -1) }; // Check these 16 neighbouring nodes for enough spawnby nodes @@ -134,7 +134,7 @@ bool Decoration::canPlaceDecoration(MMVManip *vm, v3POS p) } -size_t Decoration::placeDeco(Mapgen *mg, u32 blockseed, v3POS nmin, v3POS nmax) +size_t Decoration::placeDeco(Mapgen *mg, u32 blockseed, v3pos_t nmin, v3pos_t nmax) { PcgRandom ps(blockseed + 53); int carea_size = nmax.X - nmin.X + 1; @@ -149,15 +149,15 @@ size_t Decoration::placeDeco(Mapgen *mg, u32 blockseed, v3POS nmin, v3POS nmax) for (s16 z0 = 0; z0 < divlen; z0++) for (s16 x0 = 0; x0 < divlen; x0++) { - v2POS p2d_center( // Center position of part of division + v2pos_t p2d_center( // Center position of part of division nmin.X + sidelen / 2 + sidelen * x0, nmin.Z + sidelen / 2 + sidelen * z0 ); - v2POS p2d_min( // Minimum edge of part of division + v2pos_t p2d_min( // Minimum edge of part of division nmin.X + sidelen * x0, nmin.Z + sidelen * z0 ); - v2POS p2d_max( // Maximum edge of part of division + v2pos_t p2d_max( // Maximum edge of part of division nmin.X + sidelen + sidelen * x0 - 1, nmin.Z + sidelen + sidelen * z0 - 1 ); @@ -213,12 +213,12 @@ size_t Decoration::placeDeco(Mapgen *mg, u32 blockseed, v3POS nmin, v3POS nmax) // Get all floors and ceilings in node column u16 size = (nmax.Y - nmin.Y + 1) / 2; - std::vector floors; - std::vector ceilings; + std::vector floors; + std::vector ceilings; floors.reserve(size); ceilings.reserve(size); - mg->getSurfaces(v2POS(x, z), nmin.Y, nmax.Y, floors, ceilings); + mg->getSurfaces(v2pos_t(x, z), nmin.Y, nmax.Y, floors, ceilings); if (flags & DECO_ALL_FLOORS) { // Floor decorations @@ -226,7 +226,7 @@ size_t Decoration::placeDeco(Mapgen *mg, u32 blockseed, v3POS nmin, v3POS nmax) if (y < y_min || y > y_max) continue; - v3POS pos(x, y, z); + v3pos_t pos(x, y, z); if (generate(mg->vm, &ps, pos, false)) mg->gennotify.addEvent( GENNOTIFY_DECORATION, pos, index); @@ -235,24 +235,24 @@ size_t Decoration::placeDeco(Mapgen *mg, u32 blockseed, v3POS nmin, v3POS nmax) if (flags & DECO_ALL_CEILINGS) { // Ceiling decorations - for (const POS y : ceilings) { + for (const pos_t y : ceilings) { if (y < y_min || y > y_max) continue; - v3POS pos(x, y, z); + v3pos_t pos(x, y, z); if (generate(mg->vm, &ps, pos, true)) mg->gennotify.addEvent( GENNOTIFY_DECORATION, pos, index); } } } else { // Heightmap decorations - POS y = -MAX_MAP_GENERATION_LIMIT; + pos_t y = -MAX_MAP_GENERATION_LIMIT; if (flags & DECO_LIQUID_SURFACE) - y = mg->findLiquidSurface(v2POS(x, z), nmin.Y, nmax.Y); + y = mg->findLiquidSurface(v2pos_t(x, z), nmin.Y, nmax.Y); else if (mg->heightmap) y = mg->heightmap[mapindex]; else - y = mg->findGroundLevel(v2POS(x, z), nmin.Y, nmax.Y); + y = mg->findGroundLevel(v2pos_t(x, z), nmin.Y, nmax.Y); if (y < y_min || y > y_max || y < nmin.Y || y > nmax.Y) continue; @@ -263,7 +263,7 @@ size_t Decoration::placeDeco(Mapgen *mg, u32 blockseed, v3POS nmin, v3POS nmax) continue; } - v3POS pos(x, y, z); + v3pos_t pos(x, y, z); if (generate(mg->vm, &ps, pos, false)) mg->gennotify.addEvent(GENNOTIFY_DECORATION, pos, index); } @@ -317,7 +317,7 @@ void DecoSimple::resolveNodeNames() } -size_t DecoSimple::generate(MMVManip *vm, PcgRandom *pr, v3POS p, bool ceiling) +size_t DecoSimple::generate(MMVManip *vm, PcgRandom *pr, v3pos_t p, bool ceiling) { // Don't bother if there aren't any decorations to place if (c_decos.empty()) @@ -353,7 +353,7 @@ size_t DecoSimple::generate(MMVManip *vm, PcgRandom *pr, v3POS p, bool ceiling) pr->range(deco_param2, deco_param2_max) : deco_param2; bool force_placement = (flags & DECO_FORCE_PLACEMENT); - const v3POS &em = vm->m_area.getExtent(); + const v3pos_t &em = vm->m_area.getExtent(); u32 vi = vm->m_area.index(p); if (ceiling) { @@ -414,7 +414,7 @@ ObjDef *DecoSchematic::clone() const } -size_t DecoSchematic::generate(MMVManip *vm, PcgRandom *pr, v3POS p, bool ceiling) +size_t DecoSchematic::generate(MMVManip *vm, PcgRandom *pr, v3pos_t p, bool ceiling) { // Schematic could have been unloaded but not the decoration // In this case generate() does nothing (but doesn't *fail*) diff --git a/src/mapgen/mg_decoration.h b/src/mapgen/mg_decoration.h index 0aea942ea1..e1125c4d36 100644 --- a/src/mapgen/mg_decoration.h +++ b/src/mapgen/mg_decoration.h @@ -57,17 +57,17 @@ class Decoration : public ObjDef, public NodeResolver { virtual void resolveNodeNames(); - bool canPlaceDecoration(MMVManip *vm, v3POS p); - size_t placeDeco(Mapgen *mg, u32 blockseed, v3POS nmin, v3POS nmax); + bool canPlaceDecoration(MMVManip *vm, v3pos_t p); + size_t placeDeco(Mapgen *mg, u32 blockseed, v3pos_t nmin, v3pos_t nmax); - virtual size_t generate(MMVManip *vm, PcgRandom *pr, v3POS p, bool ceiling) = 0; + virtual size_t generate(MMVManip *vm, PcgRandom *pr, v3pos_t p, bool ceiling) = 0; u32 flags = 0; int mapseed = 0; std::vector c_place_on; s16 sidelen = 1; - POS y_min; - POS y_max; + pos_t y_min; + pos_t y_max; float fill_ratio = 0.0f; NoiseParams np; std::vector c_spawnby; @@ -86,7 +86,7 @@ class DecoSimple : public Decoration { ObjDef *clone() const; virtual void resolveNodeNames(); - virtual size_t generate(MMVManip *vm, PcgRandom *pr, v3POS p, bool ceiling); + virtual size_t generate(MMVManip *vm, PcgRandom *pr, v3pos_t p, bool ceiling); std::vector c_decos; s16 deco_height; @@ -103,7 +103,7 @@ class DecoSchematic : public Decoration { DecoSchematic() = default; virtual ~DecoSchematic(); - virtual size_t generate(MMVManip *vm, PcgRandom *pr, v3POS p, bool ceiling); + virtual size_t generate(MMVManip *vm, PcgRandom *pr, v3pos_t p, bool ceiling); Rotation rotation; Schematic *schematic = nullptr; @@ -114,7 +114,7 @@ class DecoSchematic : public Decoration { /* class DecoLSystem : public Decoration { public: - virtual void generate(Mapgen *mg, u32 blockseed, v3POS nmin, v3POS nmax); + virtual void generate(Mapgen *mg, u32 blockseed, v3pos_t nmin, v3pos_t nmax); }; */ @@ -145,7 +145,7 @@ class DecorationManager : public ObjDefManager { } } - size_t placeAllDecos(Mapgen *mg, u32 blockseed, v3POS nmin, v3POS nmax); + size_t placeAllDecos(Mapgen *mg, u32 blockseed, v3pos_t nmin, v3pos_t nmax); private: DecorationManager() {}; diff --git a/src/mapgen/mg_ore.cpp b/src/mapgen/mg_ore.cpp index 944e10429c..cce7c0d874 100644 --- a/src/mapgen/mg_ore.cpp +++ b/src/mapgen/mg_ore.cpp @@ -45,7 +45,7 @@ OreManager::OreManager(IGameDef *gamedef) : } -size_t OreManager::placeAllOres(Mapgen *mg, u32 blockseed, v3POS nmin, v3POS nmax) +size_t OreManager::placeAllOres(Mapgen *mg, u32 blockseed, v3pos_t nmin, v3pos_t nmax) { size_t nplaced = 0; @@ -96,7 +96,7 @@ void Ore::resolveNodeNames() } -size_t Ore::placeOre(Mapgen *mg, u32 blockseed, v3POS nmin, v3POS nmax) +size_t Ore::placeOre(Mapgen *mg, u32 blockseed, v3pos_t nmin, v3pos_t nmax) { if (nmin.Y > y_max || nmax.Y < y_min) return 0; @@ -146,7 +146,7 @@ ObjDef *OreScatter::clone() const void OreScatter::generate(MMVManip *vm, int mapseed, u32 blockseed, - v3POS nmin, v3POS nmax, biome_t *biomemap) + v3pos_t nmin, v3pos_t nmax, biome_t *biomemap) { PcgRandom pr(blockseed); MapNode n_ore(c_ore, 0, ore_param2); @@ -208,7 +208,7 @@ ObjDef *OreSheet::clone() const void OreSheet::generate(MMVManip *vm, int mapseed, u32 blockseed, - v3POS nmin, v3POS nmax, biome_t *biomemap) + v3pos_t nmin, v3pos_t nmax, biome_t *biomemap) { PcgRandom pr(blockseed + 4234); MapNode n_ore(c_ore, 0, ore_param2); @@ -285,7 +285,7 @@ ObjDef *OrePuff::clone() const void OrePuff::generate(MMVManip *vm, int mapseed, u32 blockseed, - v3POS nmin, v3POS nmax, biome_t *biomemap) + v3pos_t nmin, v3pos_t nmax, biome_t *biomemap) { PcgRandom pr(blockseed + 4234); MapNode n_ore(c_ore, 0, ore_param2); @@ -366,7 +366,7 @@ ObjDef *OreBlob::clone() const void OreBlob::generate(MMVManip *vm, int mapseed, u32 blockseed, - v3POS nmin, v3POS nmax, biome_t *biomemap) + v3pos_t nmin, v3pos_t nmax, biome_t *biomemap) { PcgRandom pr(blockseed + 2404); MapNode n_ore(c_ore, 0, ore_param2); @@ -451,7 +451,7 @@ ObjDef *OreVein::clone() const void OreVein::generate(MMVManip *vm, int mapseed, u32 blockseed, - v3POS nmin, v3POS nmax, biome_t *biomemap) + v3pos_t nmin, v3pos_t nmax, biome_t *biomemap) { PcgRandom pr(blockseed + 520); MapNode n_ore(c_ore, 0, ore_param2); @@ -536,7 +536,7 @@ ObjDef *OreStratum::clone() const void OreStratum::generate(MMVManip *vm, int mapseed, u32 blockseed, - v3POS nmin, v3POS nmax, biome_t *biomemap) + v3pos_t nmin, v3pos_t nmax, biome_t *biomemap) { PcgRandom pr(blockseed + 4234); MapNode n_ore(c_ore, 0, ore_param2); diff --git a/src/mapgen/mg_ore.h b/src/mapgen/mg_ore.h index ca017bf037..eb7968d74a 100644 --- a/src/mapgen/mg_ore.h +++ b/src/mapgen/mg_ore.h @@ -59,8 +59,8 @@ class Ore : public ObjDef, public NodeResolver { u32 clust_scarcity; // ore cluster has a 1-in-clust_scarcity chance of appearing at a node s16 clust_num_ores; // how many ore nodes are in a chunk s16 clust_size; // how large (in nodes) a chunk of ore is - POS y_min; - POS y_max; + pos_t y_min; + pos_t y_max; u8 ore_param2; // to set node-specific attributes u32 flags = 0; // attributes for this ore float nthresh; // threshold for noise at which an ore is placed @@ -73,9 +73,9 @@ class Ore : public ObjDef, public NodeResolver { virtual void resolveNodeNames(); - size_t placeOre(Mapgen *mg, u32 blockseed, v3POS nmin, v3POS nmax); + size_t placeOre(Mapgen *mg, u32 blockseed, v3pos_t nmin, v3pos_t nmax); virtual void generate(MMVManip *vm, int mapseed, u32 blockseed, - v3POS nmin, v3POS nmax, biome_t *biomemap) = 0; + v3pos_t nmin, v3pos_t nmax, biome_t *biomemap) = 0; protected: void cloneTo(Ore *def) const; @@ -88,7 +88,7 @@ class OreScatter : public Ore { ObjDef *clone() const override; void generate(MMVManip *vm, int mapseed, u32 blockseed, - v3POS nmin, v3POS nmax, biome_t *biomemap) override; + v3pos_t nmin, v3pos_t nmax, biome_t *biomemap) override; }; class OreSheet : public Ore { @@ -102,7 +102,7 @@ class OreSheet : public Ore { float column_midpoint_factor; void generate(MMVManip *vm, int mapseed, u32 blockseed, - v3POS nmin, v3POS nmax, biome_t *biomemap) override; + v3pos_t nmin, v3pos_t nmax, biome_t *biomemap) override; }; class OrePuff : public Ore { @@ -118,7 +118,7 @@ class OrePuff : public Ore { virtual ~OrePuff(); void generate(MMVManip *vm, int mapseed, u32 blockseed, - v3POS nmin, v3POS nmax, biome_t *biomemap) override; + v3pos_t nmin, v3pos_t nmax, biome_t *biomemap) override; }; class OreBlob : public Ore { @@ -127,7 +127,7 @@ class OreBlob : public Ore { OreBlob() : Ore(true) {} void generate(MMVManip *vm, int mapseed, u32 blockseed, - v3POS nmin, v3POS nmax, biome_t *biomemap) override; + v3pos_t nmin, v3pos_t nmax, biome_t *biomemap) override; }; class OreVein : public Ore { @@ -142,7 +142,7 @@ class OreVein : public Ore { virtual ~OreVein(); void generate(MMVManip *vm, int mapseed, u32 blockseed, - v3POS nmin, v3POS nmax, biome_t *biomemap) override; + v3pos_t nmin, v3pos_t nmax, biome_t *biomemap) override; }; class OreStratum : public Ore { @@ -157,7 +157,7 @@ class OreStratum : public Ore { virtual ~OreStratum(); void generate(MMVManip *vm, int mapseed, u32 blockseed, - v3POS nmin, v3POS nmax, biome_t *biomemap) override; + v3pos_t nmin, v3pos_t nmax, biome_t *biomemap) override; }; class OreManager : public ObjDefManager { @@ -194,7 +194,7 @@ class OreManager : public ObjDefManager { void clear(); - size_t placeAllOres(Mapgen *mg, u32 blockseed, v3POS nmin, v3POS nmax); + size_t placeAllOres(Mapgen *mg, u32 blockseed, v3pos_t nmin, v3pos_t nmax); private: OreManager() {}; diff --git a/src/mapgen/mg_schematic.cpp b/src/mapgen/mg_schematic.cpp index fa92ec6251..cfef839d90 100644 --- a/src/mapgen/mg_schematic.cpp +++ b/src/mapgen/mg_schematic.cpp @@ -121,7 +121,7 @@ void Schematic::resolveNodeNames() } -void Schematic::blitToVManip(MMVManip *vm, v3POS p, Rotation rot, bool force_place) +void Schematic::blitToVManip(MMVManip *vm, v3pos_t p, Rotation rot, bool force_place) { assert(schemdata && slice_probs); sanity_check(m_ndef != NULL); @@ -168,7 +168,7 @@ void Schematic::blitToVManip(MMVManip *vm, v3POS p, Rotation rot, bool force_pla for (s16 z = 0; z != sz; z++) { u32 i = z * i_step_z + y * ystride + i_start; for (s16 x = 0; x != sx; x++, i += i_step_x) { - v3POS pos(p.X + x, y_map, p.Z + z); + v3pos_t pos(p.X + x, y_map, p.Z + z); if (!vm->m_area.contains(pos)) continue; @@ -204,7 +204,7 @@ void Schematic::blitToVManip(MMVManip *vm, v3POS p, Rotation rot, bool force_pla } -bool Schematic::placeOnVManip(MMVManip *vm, v3POS p, u32 flags, +bool Schematic::placeOnVManip(MMVManip *vm, v3pos_t p, u32 flags, Rotation rot, bool force_place) { assert(vm != NULL); @@ -215,8 +215,8 @@ bool Schematic::placeOnVManip(MMVManip *vm, v3POS p, u32 flags, if (rot == ROTATE_RAND) rot = (Rotation)myrand_range(ROTATE_0, ROTATE_270); - v3POS s = (rot == ROTATE_90 || rot == ROTATE_270) ? - v3POS(size.Z, size.Y, size.X) : v3POS(size.X, size.Y, size.Z); + v3pos_t s = (rot == ROTATE_90 || rot == ROTATE_270) ? + v3pos_t(size.Z, size.Y, size.X) : v3pos_t(size.X, size.Y, size.Z); //// Adjust placement position if necessary if (flags & DECO_PLACE_CENTER_X) @@ -228,15 +228,15 @@ bool Schematic::placeOnVManip(MMVManip *vm, v3POS p, u32 flags, blitToVManip(vm, p, rot, force_place); - return vm->m_area.contains(VoxelArea(p, p + s - v3POS(1, 1, 1))); + return vm->m_area.contains(VoxelArea(p, p + s - v3pos_t(1, 1, 1))); } -void Schematic::placeOnMap(ServerMap *map, v3POS p, u32 flags, +void Schematic::placeOnMap(ServerMap *map, v3pos_t p, u32 flags, Rotation rot, bool force_place) { - std::map lighting_modified_blocks; - std::map modified_blocks; - std::map::iterator it; + std::map lighting_modified_blocks; + std::map modified_blocks; + std::map::iterator it; assert(map != NULL); assert(schemdata != NULL); @@ -246,8 +246,8 @@ void Schematic::placeOnMap(ServerMap *map, v3POS p, u32 flags, if (rot == ROTATE_RAND) rot = (Rotation)myrand_range(ROTATE_0, ROTATE_270); - v3POS s = (rot == ROTATE_90 || rot == ROTATE_270) ? - v3POS(size.Z, size.Y, size.X) : v3POS(size.X, size.Y, size.Z); + v3pos_t s = (rot == ROTATE_90 || rot == ROTATE_270) ? + v3pos_t(size.Z, size.Y, size.X) : v3pos_t(size.X, size.Y, size.Z); //// Adjust placement position if necessary if (flags & DECO_PLACE_CENTER_X) @@ -259,8 +259,8 @@ void Schematic::placeOnMap(ServerMap *map, v3POS p, u32 flags, //// Create VManip for effected area, emerge our area, modify area //// inside VManip, then blit back. - v3BPOS bp1 = getNodeBlockPos(p); - v3BPOS bp2 = getNodeBlockPos(p + s - v3POS(1, 1, 1)); + v3bpos_t bp1 = getNodeBlockPos(p); + v3bpos_t bp2 = getNodeBlockPos(p + s - v3pos_t(1, 1, 1)); MMVManip vm(map); vm.initialEmerge(bp1, bp2); @@ -548,15 +548,15 @@ bool Schematic::saveSchematicToFile(const std::string &filename, } -bool Schematic::getSchematicFromMap(Map *map, v3POS p1, v3POS p2) +bool Schematic::getSchematicFromMap(Map *map, v3pos_t p1, v3pos_t p2) { MMVManip *vm = new MMVManip(map); - v3BPOS bp1 = getNodeBlockPos(p1); - v3BPOS bp2 = getNodeBlockPos(p2); + v3bpos_t bp1 = getNodeBlockPos(p1); + v3bpos_t bp2 = getNodeBlockPos(p2); vm->initialEmerge(bp1, bp2); - v3BPOS size_pos = p2 - p1 + 1; + v3bpos_t size_pos = p2 - p1 + 1; size = v3s16(size_pos.X, size_pos.Y, size_pos.Z); slice_probs = new u8[size.Y]; @@ -584,12 +584,12 @@ bool Schematic::getSchematicFromMap(Map *map, v3POS p1, v3POS p2) } -void Schematic::applyProbabilities(v3POS p0, - std::vector > *plist, +void Schematic::applyProbabilities(v3pos_t p0, + std::vector > *plist, std::vector > *splist) { for (size_t i = 0; i != plist->size(); i++) { - v3POS p = (*plist)[i].first - p0; + v3pos_t p = (*plist)[i].first - p0; int index = p.Z * (size.Y * size.X) + p.Y * size.X + p.X; if (index < size.Z * size.Y * size.X) { u8 prob = (*plist)[i].second; diff --git a/src/mapgen/mg_schematic.h b/src/mapgen/mg_schematic.h index e64120a1fb..ace06415df 100644 --- a/src/mapgen/mg_schematic.h +++ b/src/mapgen/mg_schematic.h @@ -104,18 +104,18 @@ class Schematic : public ObjDef, public NodeResolver { const NodeDefManager *ndef, StringMap *replace_names = NULL); bool saveSchematicToFile(const std::string &filename, const NodeDefManager *ndef); - bool getSchematicFromMap(Map *map, v3POS p1, v3POS p2); + bool getSchematicFromMap(Map *map, v3pos_t p1, v3pos_t p2); bool deserializeFromMts(std::istream *is); bool serializeToMts(std::ostream *os) const; bool serializeToLua(std::ostream *os, bool use_comments, u32 indent_spaces) const; - void blitToVManip(MMVManip *vm, v3POS p, Rotation rot, bool force_place); - bool placeOnVManip(MMVManip *vm, v3POS p, u32 flags, Rotation rot, bool force_place); - void placeOnMap(ServerMap *map, v3POS p, u32 flags, Rotation rot, bool force_place); + void blitToVManip(MMVManip *vm, v3pos_t p, Rotation rot, bool force_place); + bool placeOnVManip(MMVManip *vm, v3pos_t p, u32 flags, Rotation rot, bool force_place); + void placeOnMap(ServerMap *map, v3pos_t p, u32 flags, Rotation rot, bool force_place); - void applyProbabilities(v3POS p0, - std::vector > *plist, + void applyProbabilities(v3pos_t p0, + std::vector > *plist, std::vector > *splist); std::vector c_nodes; diff --git a/src/mapgen/treegen.cpp b/src/mapgen/treegen.cpp index f5580ae270..bcaa7cbc18 100644 --- a/src/mapgen/treegen.cpp +++ b/src/mapgen/treegen.cpp @@ -32,7 +32,7 @@ with this program; if not, write to the Free Software Foundation, Inc., namespace treegen { -void make_tree(MMVManip &vmanip, v3POS p0, bool is_apple_tree, +void make_tree(MMVManip &vmanip, v3pos_t p0, bool is_apple_tree, const NodeDefManager *ndef, s32 seed) { /* @@ -52,7 +52,7 @@ void make_tree(MMVManip &vmanip, v3POS p0, bool is_apple_tree, PseudoRandom pr(seed); s16 trunk_h = pr.range(4, 5); - v3POS p1 = p0; + v3pos_t p1 = p0; for (s16 ii = 0; ii < trunk_h; ii++) { if (vmanip.m_area.contains(p1)) { u32 vi = vmanip.m_area.index(p1); @@ -64,7 +64,7 @@ void make_tree(MMVManip &vmanip, v3POS p0, bool is_apple_tree, // p1 is now the last piece of the trunk p1.Y -= 1; - VoxelArea leaves_a(v3POS(-2, -1, -2), v3POS(2, 2, 2)); + VoxelArea leaves_a(v3pos_t(-2, -1, -2), v3pos_t(2, 2, 2)); Buffer leaves_d(leaves_a.getVolume()); for (s32 i = 0; i < leaves_a.getVolume(); i++) leaves_d[i] = 0; @@ -74,12 +74,12 @@ void make_tree(MMVManip &vmanip, v3POS p0, bool is_apple_tree, for (s16 z = -d; z <= d; z++) for (s16 y = -d; y <= d; y++) for (s16 x = -d; x <= d; x++) { - leaves_d[leaves_a.index(v3POS(x, y, z))] = 1; + leaves_d[leaves_a.index(v3pos_t(x, y, z))] = 1; } // Add leaves randomly for (u32 iii = 0; iii < 7; iii++) { - v3POS p( + v3pos_t p( pr.range(leaves_a.MinEdge.X, leaves_a.MaxEdge.X - d), pr.range(leaves_a.MinEdge.Y, leaves_a.MaxEdge.Y - d), pr.range(leaves_a.MinEdge.Z, leaves_a.MaxEdge.Z - d) @@ -88,18 +88,18 @@ void make_tree(MMVManip &vmanip, v3POS p0, bool is_apple_tree, for (s16 z = 0; z <= d; z++) for (s16 y = 0; y <= d; y++) for (s16 x = 0; x <= d; x++) { - leaves_d[leaves_a.index(p + v3POS(x, y, z))] = 1; + leaves_d[leaves_a.index(p + v3pos_t(x, y, z))] = 1; } } // Blit leaves to vmanip for (s16 z = leaves_a.MinEdge.Z; z <= leaves_a.MaxEdge.Z; z++) for (s16 y = leaves_a.MinEdge.Y; y <= leaves_a.MaxEdge.Y; y++) { - v3POS pmin(leaves_a.MinEdge.X, y, z); + v3pos_t pmin(leaves_a.MinEdge.X, y, z); u32 i = leaves_a.index(pmin); u32 vi = vmanip.m_area.index(pmin + p1); for (s16 x = leaves_a.MinEdge.X; x <= leaves_a.MaxEdge.X; x++) { - v3POS p(x, y, z); + v3pos_t p(x, y, z); if (vmanip.m_area.contains(p + p1) && (vmanip.m_data[vi].getContent() == CONTENT_AIR || vmanip.m_data[vi].getContent() == CONTENT_IGNORE)) { @@ -119,15 +119,15 @@ void make_tree(MMVManip &vmanip, v3POS p0, bool is_apple_tree, // L-System tree LUA spawner -treegen::error spawn_ltree(ServerMap *map, v3POS p0, +treegen::error spawn_ltree(ServerMap *map, v3pos_t p0, const NodeDefManager *ndef, const TreeDef &tree_definition) { - std::map modified_blocks; + std::map modified_blocks; MMVManip vmanip(map); - v3BPOS tree_blockp = getNodeBlockPos(p0); + v3bpos_t tree_blockp = getNodeBlockPos(p0); treegen::error e; - vmanip.initialEmerge(tree_blockp - v3POS(1, 1, 1), tree_blockp + v3POS(1, 3, 1)); + vmanip.initialEmerge(tree_blockp - v3pos_t(1, 1, 1), tree_blockp + v3pos_t(1, 3, 1)); e = make_ltree(vmanip, p0, ndef, tree_definition); if (e != SUCCESS) return e; @@ -145,7 +145,7 @@ treegen::error spawn_ltree(ServerMap *map, v3POS p0, //L-System tree generator -treegen::error make_ltree(MMVManip &vmanip, v3POS p0, +treegen::error make_ltree(MMVManip &vmanip, v3pos_t p0, const NodeDefManager *ndef, TreeDef tree_definition) { s32 seed; @@ -530,7 +530,7 @@ treegen::error make_ltree(MMVManip &vmanip, v3POS p0, void tree_trunk_placement(MMVManip &vmanip, v3f p0, TreeDef &tree_definition) { - v3POS p1 = v3POS(myround(p0.X), myround(p0.Y), myround(p0.Z)); + v3pos_t p1 = v3pos_t(myround(p0.X), myround(p0.Y), myround(p0.Z)); if (!vmanip.m_area.contains(p1)) return; u32 vi = vmanip.m_area.index(p1); @@ -550,7 +550,7 @@ void tree_leaves_placement(MMVManip &vmanip, v3f p0, MapNode leavesnode = tree_definition.leavesnode; if (ps.range(1, 100) > 100 - tree_definition.leaves2_chance) leavesnode = tree_definition.leaves2node; - v3POS p1 = v3POS(myround(p0.X), myround(p0.Y), myround(p0.Z)); + v3pos_t p1 = v3pos_t(myround(p0.X), myround(p0.Y), myround(p0.Z)); if (!vmanip.m_area.contains(p1)) return; u32 vi = vmanip.m_area.index(p1); @@ -574,7 +574,7 @@ void tree_single_leaves_placement(MMVManip &vmanip, v3f p0, MapNode leavesnode = tree_definition.leavesnode; if (ps.range(1, 100) > 100 - tree_definition.leaves2_chance) leavesnode = tree_definition.leaves2node; - v3POS p1 = v3POS(myround(p0.X), myround(p0.Y), myround(p0.Z)); + v3pos_t p1 = v3pos_t(myround(p0.X), myround(p0.Y), myround(p0.Z)); if (!vmanip.m_area.contains(p1)) return; u32 vi = vmanip.m_area.index(p1); @@ -587,7 +587,7 @@ void tree_single_leaves_placement(MMVManip &vmanip, v3f p0, void tree_fruit_placement(MMVManip &vmanip, v3f p0, TreeDef &tree_definition) { - v3POS p1 = v3POS(myround(p0.X), myround(p0.Y), myround(p0.Z)); + v3pos_t p1 = v3pos_t(myround(p0.X), myround(p0.Y), myround(p0.Z)); if (!vmanip.m_area.contains(p1)) return; u32 vi = vmanip.m_area.index(p1); @@ -639,7 +639,7 @@ v3f transposeMatrix(irr::core::matrix4 M, v3f v) } -void make_jungletree(MMVManip &vmanip, v3POS p0, const NodeDefManager *ndef, +void make_jungletree(MMVManip &vmanip, v3pos_t p0, const NodeDefManager *ndef, s32 seed) { /* @@ -666,8 +666,8 @@ void make_jungletree(MMVManip &vmanip, v3POS p0, const NodeDefManager *ndef, for (s16 z= -1; z <= 1; z++) { if (pr.range(0, 2) == 0) continue; - v3POS p1 = p0 + v3POS(x, 0, z); - v3POS p2 = p0 + v3POS(x, -1, z); + v3pos_t p1 = p0 + v3pos_t(x, 0, z); + v3pos_t p2 = p0 + v3pos_t(x, -1, z); u32 vi1 = vmanip.m_area.index(p1); u32 vi2 = vmanip.m_area.index(p2); @@ -681,7 +681,7 @@ void make_jungletree(MMVManip &vmanip, v3POS p0, const NodeDefManager *ndef, vmanip.m_data[vmanip.m_area.index(p0)] = treenode; s16 trunk_h = pr.range(8, 12); - v3POS p1 = p0; + v3pos_t p1 = p0; for (s16 ii = 0; ii < trunk_h; ii++) { if (vmanip.m_area.contains(p1)) { u32 vi = vmanip.m_area.index(p1); @@ -693,7 +693,7 @@ void make_jungletree(MMVManip &vmanip, v3POS p0, const NodeDefManager *ndef, // p1 is now the last piece of the trunk p1.Y -= 1; - VoxelArea leaves_a(v3POS(-3, -2, -3), v3POS(3, 2, 3)); + VoxelArea leaves_a(v3pos_t(-3, -2, -3), v3pos_t(3, 2, 3)); //SharedPtr leaves_d(new u8[leaves_a.getVolume()]); Buffer leaves_d(leaves_a.getVolume()); for (s32 i = 0; i < leaves_a.getVolume(); i++) @@ -704,12 +704,12 @@ void make_jungletree(MMVManip &vmanip, v3POS p0, const NodeDefManager *ndef, for (s16 z = -d; z <= d; z++) for (s16 y = -d; y <= d; y++) for (s16 x = -d; x <= d; x++) { - leaves_d[leaves_a.index(v3POS(x,y,z))] = 1; + leaves_d[leaves_a.index(v3pos_t(x,y,z))] = 1; } // Add leaves randomly for (u32 iii = 0; iii < 30; iii++) { - v3POS p( + v3pos_t p( pr.range(leaves_a.MinEdge.X, leaves_a.MaxEdge.X - d), pr.range(leaves_a.MinEdge.Y, leaves_a.MaxEdge.Y - d), pr.range(leaves_a.MinEdge.Z, leaves_a.MaxEdge.Z - d) @@ -718,18 +718,18 @@ void make_jungletree(MMVManip &vmanip, v3POS p0, const NodeDefManager *ndef, for (s16 z = 0; z <= d; z++) for (s16 y = 0; y <= d; y++) for (s16 x = 0; x <= d; x++) { - leaves_d[leaves_a.index(p + v3POS(x, y, z))] = 1; + leaves_d[leaves_a.index(p + v3pos_t(x, y, z))] = 1; } } // Blit leaves to vmanip for (s16 z = leaves_a.MinEdge.Z; z <= leaves_a.MaxEdge.Z; z++) for (s16 y = leaves_a.MinEdge.Y; y <= leaves_a.MaxEdge.Y; y++) { - v3POS pmin(leaves_a.MinEdge.X, y, z); + v3pos_t pmin(leaves_a.MinEdge.X, y, z); u32 i = leaves_a.index(pmin); u32 vi = vmanip.m_area.index(pmin + p1); for (s16 x = leaves_a.MinEdge.X; x <= leaves_a.MaxEdge.X; x++) { - v3POS p(x, y, z); + v3pos_t p(x, y, z); if (vmanip.m_area.contains(p + p1) && (vmanip.m_data[vi].getContent() == CONTENT_AIR || vmanip.m_data[vi].getContent() == CONTENT_IGNORE)) { @@ -743,7 +743,7 @@ void make_jungletree(MMVManip &vmanip, v3POS p0, const NodeDefManager *ndef, } -void make_pine_tree(MMVManip &vmanip, v3POS p0, const NodeDefManager *ndef, +void make_pine_tree(MMVManip &vmanip, v3pos_t p0, const NodeDefManager *ndef, s32 seed) { /* @@ -771,7 +771,7 @@ void make_pine_tree(MMVManip &vmanip, v3POS p0, const NodeDefManager *ndef, PseudoRandom pr(seed); u16 trunk_h = pr.range(9, 13); - v3POS p1 = p0; + v3pos_t p1 = p0; for (u16 ii = 0; ii < trunk_h; ii++) { if (vmanip.m_area.contains(p1)) { u32 vi = vmanip.m_area.index(p1); @@ -783,7 +783,7 @@ void make_pine_tree(MMVManip &vmanip, v3POS p0, const NodeDefManager *ndef, // Make p1 the top node of the trunk p1.Y -= 1; - VoxelArea leaves_a(v3POS(-3, -6, -3), v3POS(3, 3, 3)); + VoxelArea leaves_a(v3pos_t(-3, -6, -3), v3pos_t(3, 3, 3)); Buffer leaves_d(leaves_a.getVolume()); for (s32 i = 0; i < leaves_a.getVolume(); i++) leaves_d[i] = 0; @@ -792,8 +792,8 @@ void make_pine_tree(MMVManip &vmanip, v3POS p0, const NodeDefManager *ndef, u16 dev = 3; for (s16 yy = -1; yy <= 1; yy++) { for (s16 zz = -dev; zz <= dev; zz++) { - u32 i = leaves_a.index(v3POS(-dev, yy, zz)); - u32 ia = leaves_a.index(v3POS(-dev, yy+1, zz)); + u32 i = leaves_a.index(v3pos_t(-dev, yy, zz)); + u32 ia = leaves_a.index(v3pos_t(-dev, yy+1, zz)); for (s16 xx = -dev; xx <= dev; xx++) { if (pr.range(0, 20) <= 19 - dev) { leaves_d[i] = 1; @@ -807,9 +807,9 @@ void make_pine_tree(MMVManip &vmanip, v3POS p0, const NodeDefManager *ndef, } // Centre top nodes - leaves_d[leaves_a.index(v3POS(0, 1, 0))] = 1; - leaves_d[leaves_a.index(v3POS(0, 2, 0))] = 1; - leaves_d[leaves_a.index(v3POS(0, 3, 0))] = 2; + leaves_d[leaves_a.index(v3pos_t(0, 1, 0))] = 1; + leaves_d[leaves_a.index(v3pos_t(0, 2, 0))] = 1; + leaves_d[leaves_a.index(v3pos_t(0, 3, 0))] = 2; // Lower branches s16 my = -6; @@ -820,8 +820,8 @@ void make_pine_tree(MMVManip &vmanip, v3POS p0, const NodeDefManager *ndef, if (yy > my) my = yy; for (s16 zz = zi; zz <= zi + 1; zz++) { - u32 i = leaves_a.index(v3POS(xi, yy, zz)); - u32 ia = leaves_a.index(v3POS(xi, yy + 1, zz)); + u32 i = leaves_a.index(v3pos_t(xi, yy, zz)); + u32 ia = leaves_a.index(v3pos_t(xi, yy + 1, zz)); for (s32 xx = xi; xx <= xi + 1; xx++) { leaves_d[i] = 1; if (leaves_d[ia] == 0) @@ -835,8 +835,8 @@ void make_pine_tree(MMVManip &vmanip, v3POS p0, const NodeDefManager *ndef, dev = 2; for (s16 yy = my + 1; yy <= my + 2; yy++) { for (s16 zz = -dev; zz <= dev; zz++) { - u32 i = leaves_a.index(v3POS(-dev, yy, zz)); - u32 ia = leaves_a.index(v3POS(-dev, yy + 1, zz)); + u32 i = leaves_a.index(v3pos_t(-dev, yy, zz)); + u32 ia = leaves_a.index(v3pos_t(-dev, yy + 1, zz)); for (s16 xx = -dev; xx <= dev; xx++) { if (pr.range(0, 20) <= 19 - dev) { leaves_d[i] = 1; @@ -852,11 +852,11 @@ void make_pine_tree(MMVManip &vmanip, v3POS p0, const NodeDefManager *ndef, // Blit leaves to vmanip for (s16 z = leaves_a.MinEdge.Z; z <= leaves_a.MaxEdge.Z; z++) for (s16 y = leaves_a.MinEdge.Y; y <= leaves_a.MaxEdge.Y; y++) { - v3POS pmin(leaves_a.MinEdge.X, y, z); + v3pos_t pmin(leaves_a.MinEdge.X, y, z); u32 i = leaves_a.index(pmin); u32 vi = vmanip.m_area.index(pmin + p1); for (s16 x = leaves_a.MinEdge.X; x <= leaves_a.MaxEdge.X; x++) { - v3POS p(x, y, z); + v3pos_t p(x, y, z); if (vmanip.m_area.contains(p + p1) && (vmanip.m_data[vi].getContent() == CONTENT_AIR || vmanip.m_data[vi].getContent() == CONTENT_IGNORE || diff --git a/src/mapgen/treegen.h b/src/mapgen/treegen.h index 34e955a9be..4de1d65f75 100644 --- a/src/mapgen/treegen.h +++ b/src/mapgen/treegen.h @@ -59,20 +59,20 @@ namespace treegen { }; // Add default tree - void make_tree(MMVManip &vmanip, v3POS p0, + void make_tree(MMVManip &vmanip, v3pos_t p0, bool is_apple_tree, const NodeDefManager *ndef, s32 seed); // Add jungle tree - void make_jungletree(MMVManip &vmanip, v3POS p0, + void make_jungletree(MMVManip &vmanip, v3pos_t p0, const NodeDefManager *ndef, s32 seed); // Add pine tree - void make_pine_tree(MMVManip &vmanip, v3POS p0, + void make_pine_tree(MMVManip &vmanip, v3pos_t p0, const NodeDefManager *ndef, s32 seed); // Add L-Systems tree (used by engine) - treegen::error make_ltree(MMVManip &vmanip, v3POS p0, + treegen::error make_ltree(MMVManip &vmanip, v3pos_t p0, const NodeDefManager *ndef, TreeDef tree_definition); // Spawn L-systems tree from LUA - treegen::error spawn_ltree (ServerMap *map, v3POS p0, + treegen::error spawn_ltree (ServerMap *map, v3pos_t p0, const NodeDefManager *ndef, const TreeDef &tree_definition); // L-System tree gen helper functions diff --git a/src/mapnode.cpp b/src/mapnode.cpp index 539014af73..ec2e075668 100644 --- a/src/mapnode.cpp +++ b/src/mapnode.cpp @@ -169,16 +169,16 @@ u8 MapNode::getWallMounted(const NodeDefManager *nodemgr) const return 0; } -v3POS MapNode::getWallMountedDir(const NodeDefManager *nodemgr) const +v3pos_t MapNode::getWallMountedDir(const NodeDefManager *nodemgr) const { switch(getWallMounted(nodemgr)) { - case 0: default: return v3POS(0,1,0); - case 1: return v3POS(0,-1,0); - case 2: return v3POS(1,0,0); - case 3: return v3POS(-1,0,0); - case 4: return v3POS(0,0,1); - case 5: return v3POS(0,0,-1); + case 0: default: return v3pos_t(0,1,0); + case 1: return v3pos_t(0,-1,0); + case 2: return v3pos_t(1,0,0); + case 3: return v3pos_t(-1,0,0); + case 4: return v3pos_t(0,0,1); + case 5: return v3pos_t(0,0,-1); } } @@ -396,15 +396,15 @@ void transformNodeBox(const MapNode &n, const NodeBox &nodebox, } else if(nodebox.type == NODEBOX_WALLMOUNTED) { - v3POS dir = n.getWallMountedDir(nodemgr); + v3pos_t dir = n.getWallMountedDir(nodemgr); // top - if(dir == v3POS(0,1,0)) + if(dir == v3pos_t(0,1,0)) { boxes.push_back(nodebox.wall_top); } // bottom - else if(dir == v3POS(0,-1,0)) + else if(dir == v3pos_t(0,-1,0)) { boxes.push_back(nodebox.wall_bottom); } @@ -418,13 +418,13 @@ void transformNodeBox(const MapNode &n, const NodeBox &nodebox, }; for (v3f &vertex : vertices) { - if(dir == v3POS(-1,0,0)) + if(dir == v3pos_t(-1,0,0)) vertex.rotateXZBy(0); - if(dir == v3POS(1,0,0)) + if(dir == v3pos_t(1,0,0)) vertex.rotateXZBy(180); - if(dir == v3POS(0,0,-1)) + if(dir == v3pos_t(0,0,-1)) vertex.rotateXZBy(90); - if(dir == v3POS(0,0,1)) + if(dir == v3pos_t(0,0,1)) vertex.rotateXZBy(-90); } @@ -535,7 +535,7 @@ void transformNodeBox(const MapNode &n, const NodeBox &nodebox, } static inline void getNeighborConnectingFace( - const v3POS &p, const NodeDefManager *nodedef, + const v3pos_t &p, const NodeDefManager *nodedef, Map *map, MapNode n, u8 bitmask, u8 *neighbors) { MapNode n2 = map->getNode(p); @@ -543,14 +543,14 @@ static inline void getNeighborConnectingFace( *neighbors |= bitmask; } -u8 MapNode::getNeighbors(v3POS p, Map *map) const +u8 MapNode::getNeighbors(v3pos_t p, Map *map) const { const NodeDefManager *nodedef = map->getNodeDefManager(); u8 neighbors = 0; const ContentFeatures &f = nodedef->get(*this); // locate possible neighboring nodes to connect to if (f.drawtype == NDT_NODEBOX && f.node_box.type == NODEBOX_CONNECTED) { - v3POS p2 = p; + v3pos_t p2 = p; p2.Y++; getNeighborConnectingFace(p2, nodedef, map, *this, 1, &neighbors); diff --git a/src/mapnode.h b/src/mapnode.h index b53ce7604b..fd9dc38e60 100644 --- a/src/mapnode.h +++ b/src/mapnode.h @@ -239,7 +239,7 @@ struct MapNode u8 getFaceDir(const NodeDefManager *nodemgr, bool allow_wallmounted = false) const; u8 getWallMounted(const NodeDefManager *nodemgr) const; - v3POS getWallMountedDir(const NodeDefManager *nodemgr) const; + v3pos_t getWallMountedDir(const NodeDefManager *nodemgr) const; /// @returns Rotation in range 0–239 (in 1.5° steps) u8 getDegRotate(const NodeDefManager *nodemgr) const; @@ -251,7 +251,7 @@ struct MapNode * * \param p coordinates of the node */ - u8 getNeighbors(v3POS p, Map *map) const; + u8 getNeighbors(v3pos_t p, Map *map) const; /* Gets list of node boxes (used for rendering (NDT_NODEBOX)) diff --git a/src/mapsector.cpp b/src/mapsector.cpp index 7af2e112d0..b786e8ec38 100644 --- a/src/mapsector.cpp +++ b/src/mapsector.cpp @@ -22,7 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "mapblock.h" #include "serialization.h" -MapSector::MapSector(Map *parent, v2POS pos, IGameDef *gamedef): +MapSector::MapSector(Map *parent, v2pos_t pos, IGameDef *gamedef): m_parent(parent), m_pos(pos), m_gamedef(gamedef) @@ -48,7 +48,7 @@ void MapSector::deleteBlocks() m_blocks.clear(); } -MapBlock * MapSector::getBlockBuffered(BPOS y) +MapBlock * MapSector::getBlockBuffered(bpos_t y) { MapBlock *block; @@ -57,7 +57,7 @@ MapBlock * MapSector::getBlockBuffered(BPOS y) } // If block doesn't exist, return NULL - std::unordered_map::const_iterator n = m_blocks.find(y); + std::unordered_map::const_iterator n = m_blocks.find(y); block = (n != m_blocks.end() ? n->second : nullptr); // Cache the last result @@ -67,23 +67,23 @@ MapBlock * MapSector::getBlockBuffered(BPOS y) return block; } -MapBlock * MapSector::getBlockNoCreateNoEx(BPOS y) +MapBlock * MapSector::getBlockNoCreateNoEx(bpos_t y) { return getBlockBuffered(y); } -MapBlock * MapSector::createBlankBlockNoInsert(BPOS y) +MapBlock * MapSector::createBlankBlockNoInsert(bpos_t y) { assert(getBlockBuffered(y) == NULL); // Pre-condition - v3BPOS blockpos_map(m_pos.X, y, m_pos.Y); + v3bpos_t blockpos_map(m_pos.X, y, m_pos.Y); MapBlock *block = new MapBlock(m_parent, blockpos_map, m_gamedef); return block; } -MapBlock * MapSector::createBlankBlock(BPOS y) +MapBlock * MapSector::createBlankBlock(bpos_t y) { MapBlock *block = createBlankBlockNoInsert(y); @@ -94,14 +94,14 @@ MapBlock * MapSector::createBlankBlock(BPOS y) void MapSector::insertBlock(MapBlock *block) { - BPOS block_y = block->getPos().Y; + bpos_t block_y = block->getPos().Y; MapBlock *block2 = getBlockBuffered(block_y); if (block2) { throw AlreadyExistsException("Block already exists"); } - v2BPOS p2d(block->getPos().X, block->getPos().Z); + v2bpos_t p2d(block->getPos().X, block->getPos().Z); assert(p2d == m_pos); // Insert into container @@ -110,7 +110,7 @@ void MapSector::insertBlock(MapBlock *block) void MapSector::deleteBlock(MapBlock *block) { - BPOS block_y = block->getPos().Y; + bpos_t block_y = block->getPos().Y; // Clear from cache m_block_cache = nullptr; diff --git a/src/mapsector.h b/src/mapsector.h index 3220a2539a..31e6e98028 100644 --- a/src/mapsector.h +++ b/src/mapsector.h @@ -40,19 +40,19 @@ class MapSector { public: - MapSector(Map *parent, v2BPOS pos, IGameDef *gamedef); + MapSector(Map *parent, v2bpos_t pos, IGameDef *gamedef); virtual ~MapSector(); void deleteBlocks(); - v2BPOS getPos() + v2bpos_t getPos() { return m_pos; } - MapBlock * getBlockNoCreateNoEx(BPOS y); - MapBlock * createBlankBlockNoInsert(BPOS y); - MapBlock * createBlankBlock(BPOS y); + MapBlock * getBlockNoCreateNoEx(bpos_t y); + MapBlock * createBlankBlockNoInsert(bpos_t y); + MapBlock * createBlankBlock(bpos_t y); void insertBlock(MapBlock *block); @@ -66,22 +66,22 @@ class MapSector protected: // The pile of MapBlocks - std::unordered_map m_blocks; + std::unordered_map m_blocks; Map *m_parent; // Position on parent (in MapBlock widths) - v2BPOS m_pos; + v2bpos_t m_pos; IGameDef *m_gamedef; // Last-used block is cached here for quicker access. // Be sure to set this to nullptr when the cached block is deleted MapBlock *m_block_cache = nullptr; - BPOS m_block_cache_y; + bpos_t m_block_cache_y; /* Private methods */ - MapBlock *getBlockBuffered(BPOS y); + MapBlock *getBlockBuffered(bpos_t y); }; diff --git a/src/network/clientpackethandler.cpp b/src/network/clientpackethandler.cpp index 88ffb19dc5..3e00fe60b9 100644 --- a/src/network/clientpackethandler.cpp +++ b/src/network/clientpackethandler.cpp @@ -227,27 +227,27 @@ void Client::handleCommand_AccessDenied(NetworkPacket* pkt) void Client::handleCommand_RemoveNode(NetworkPacket* pkt) { - if (pkt->getSize() < sizeof(v3POS)) + if (pkt->getSize() < sizeof(v3pos_t)) return; - v3POS p; + v3pos_t p; *pkt >> p; removeNode(p); } void Client::handleCommand_AddNode(NetworkPacket* pkt) { - if (pkt->getSize() < sizeof(v3POS) + MapNode::serializedLength(m_server_ser_ver)) + if (pkt->getSize() < sizeof(v3pos_t) + MapNode::serializedLength(m_server_ser_ver)) return; - v3POS p; + v3pos_t p; *pkt >> p; MapNode n; - n.deSerialize(pkt->getU8Ptr(sizeof(v3POS)), m_server_ser_ver); + n.deSerialize(pkt->getU8Ptr(sizeof(v3pos_t)), m_server_ser_ver); bool remove_metadata = true; - u32 index = sizeof(v3POS) + MapNode::serializedLength(m_server_ser_ver); + u32 index = sizeof(v3pos_t) + MapNode::serializedLength(m_server_ser_ver); if ((pkt->getSize() >= index + 1) && pkt->getU8(index)) { remove_metadata = false; } @@ -270,7 +270,7 @@ void Client::handleCommand_NodemetaChanged(NetworkPacket *pkt) Map &map = m_env.getMap(); for (NodeMetadataMap::const_iterator i = meta_updates_list.begin(); i != meta_updates_list.end(); ++i) { - v3POS pos = i->first; + v3pos_t pos = i->first; if (map.isValidPosition(pos) && map.setNodeMetadata(pos, i->second)) @@ -284,10 +284,10 @@ void Client::handleCommand_NodemetaChanged(NetworkPacket *pkt) void Client::handleCommand_BlockData(NetworkPacket* pkt) { // Ignore too small packet - if (pkt->getSize() < sizeof(v3POS)) + if (pkt->getSize() < sizeof(v3pos_t)) return; - v3POS p; + v3pos_t p; *pkt >> p; std::string datastring(pkt->getString(sizeof(p)), pkt->getSize() - sizeof(p)); @@ -296,7 +296,7 @@ void Client::handleCommand_BlockData(NetworkPacket* pkt) MapSector *sector; MapBlock *block; - v2BPOS p2d(p.X, p.Z); + v2bpos_t p2d(p.X, p.Z); sector = m_env.getMap().emergeSector(p2d); assert(sector->getPos() == p2d); diff --git a/src/network/networkprotocol.h b/src/network/networkprotocol.h index 7b04345bd1..25f5beabeb 100644 --- a/src/network/networkprotocol.h +++ b/src/network/networkprotocol.h @@ -252,7 +252,7 @@ enum ToClientCommand /* Message from server to accept auth. - v3POS player's position + v3f(0,BS/2,0) floatToInt'd + v3pos_t player's position + v3f(0,BS/2,0) floatToInt'd u64 map seed f1000 recommended send interval u32 : supported auth methods for sudo mode @@ -278,13 +278,13 @@ enum ToClientCommand TOCLIENT_BLOCKDATA = 0x20, //TODO: Multiple blocks TOCLIENT_ADDNODE = 0x21, /* - v3POS position + v3pos_t position serialized mapnode u8 keep_metadata // Added in protocol version 22 */ TOCLIENT_REMOVENODE = 0x22, - TOCLIENT_PLAYERPOS = 0x23, // Obsolete + TOCLIENT_PLAYERpos_t = 0x23, // Obsolete TOCLIENT_PLAYERINFO = 0x24, // Obsolete TOCLIENT_OPT_BLOCK_NOT_FOUND = 0x25, // Obsolete TOCLIENT_SECTORMETA = 0x26, // Obsolete @@ -829,8 +829,8 @@ enum ToServerCommand /* [0] u16 command [2] u8 count - [3] v3POS pos_0 - [3+6] v3POS pos_1 + [3] v3pos_t pos_0 + [3+6] v3pos_t pos_1 ... */ @@ -838,8 +838,8 @@ enum ToServerCommand /* [0] u16 command [2] u8 count - [3] v3POS pos_0 - [3+6] v3POS pos_1 + [3] v3pos_t pos_0 + [3+6] v3pos_t pos_1 ... */ @@ -906,7 +906,7 @@ enum ToServerCommand TOSERVER_NODEMETA_FIELDS = 0x3b, /* - v3POS p + v3pos_t p u16 len u8[len] form name (reserved for future use) u16 number of fields diff --git a/src/network/serverpackethandler.cpp b/src/network/serverpackethandler.cpp index f22a0fd299..7dc343c511 100644 --- a/src/network/serverpackethandler.cpp +++ b/src/network/serverpackethandler.cpp @@ -439,15 +439,15 @@ void Server::handleCommand_GotBlocks(NetworkPacket* pkt) /* [0] u16 command [2] u8 count - [3] v3POS pos_0 - [3+6] v3POS pos_1 + [3] v3pos_t pos_0 + [3+6] v3pos_t pos_1 ... */ u8 count; *pkt >> count; - if ((s16)pkt->getSize() < 1 + (int)count * (int)sizeof(v3BPOS)) { + if ((s16)pkt->getSize() < 1 + (int)count * (int)sizeof(v3bpos_t)) { throw con::InvalidIncomingDataException ("GOTBLOCKS length is too short"); } @@ -456,7 +456,7 @@ void Server::handleCommand_GotBlocks(NetworkPacket* pkt) RemoteClient *client = m_clients.lockedGetClientNoEx(pkt->getPeerId()); for (u16 i = 0; i < count; i++) { - v3BPOS p; + v3bpos_t p; *pkt >> p; client->GotBlock(p); } @@ -562,8 +562,8 @@ void Server::handleCommand_DeletedBlocks(NetworkPacket* pkt) /* [0] u16 command [2] u8 count - [3] v3POS pos_0 - [3+6] v3POS pos_1 + [3] v3pos_t pos_0 + [3+6] v3pos_t pos_1 ... */ @@ -572,13 +572,13 @@ void Server::handleCommand_DeletedBlocks(NetworkPacket* pkt) RemoteClient *client = getClient(pkt->getPeerId()); - if ((s16)pkt->getSize() < 1 + (int)count * (int)sizeof(v3BPOS)) { + if ((s16)pkt->getSize() < 1 + (int)count * (int)sizeof(v3bpos_t)) { throw con::InvalidIncomingDataException ("DELETEDBLOCKS length is too short"); } for (u16 i = 0; i < count; i++) { - v3BPOS p; + v3bpos_t p; *pkt >> p; client->SetBlockNotSent(p); } @@ -978,7 +978,7 @@ void Server::handleCommand_Interact(NetworkPacket *pkt) if (pointed.type == POINTEDTHING_NODE) { // Re-send block to revert change on client-side RemoteClient *client = getClient(peer_id); - v3BPOS blockpos = getNodeBlockPos(pointed.node_undersurface); + v3bpos_t blockpos = getNodeBlockPos(pointed.node_undersurface); client->SetBlockNotSent(blockpos); } // Call callbacks @@ -1029,12 +1029,12 @@ void Server::handleCommand_Interact(NetworkPacket *pkt) RemoteClient *client = getClient(peer_id); // Digging completed -> under if (action == INTERACT_DIGGING_COMPLETED) { - v3BPOS blockpos = getNodeBlockPos(pointed.node_undersurface); + v3bpos_t blockpos = getNodeBlockPos(pointed.node_undersurface); client->SetBlockNotSent(blockpos); } // Placement -> above else if (action == INTERACT_PLACE) { - v3BPOS blockpos = getNodeBlockPos(pointed.node_abovesurface); + v3bpos_t blockpos = getNodeBlockPos(pointed.node_abovesurface); client->SetBlockNotSent(blockpos); } return; @@ -1067,7 +1067,7 @@ void Server::handleCommand_Interact(NetworkPacket *pkt) if (pointed.type == POINTEDTHING_NODE) { // Re-send block to revert change on client-side RemoteClient *client = getClient(peer_id); - v3BPOS blockpos = getNodeBlockPos(pointed.node_undersurface); + v3bpos_t blockpos = getNodeBlockPos(pointed.node_undersurface); client->SetBlockNotSent(blockpos); } return; @@ -1087,7 +1087,7 @@ void Server::handleCommand_Interact(NetworkPacket *pkt) MapNode n(CONTENT_IGNORE); bool pos_ok; - v3POS p_under = pointed.node_undersurface; + v3pos_t p_under = pointed.node_undersurface; n = m_env->getMap().getNode(p_under, &pos_ok); if (!pos_ok) { infostream << "Server: Not punching: Node not found. " @@ -1140,7 +1140,7 @@ void Server::handleCommand_Interact(NetworkPacket *pkt) if (pointed.type != POINTEDTHING_NODE) return; bool pos_ok; - v3POS p_under = pointed.node_undersurface; + v3pos_t p_under = pointed.node_undersurface; MapNode n = m_env->getMap().getNode(p_under, &pos_ok); if (!pos_ok) { infostream << "Server: Not finishing digging: Node not found. " @@ -1152,7 +1152,7 @@ void Server::handleCommand_Interact(NetworkPacket *pkt) /* Cheat prevention */ bool is_valid_dig = true; if (enable_anticheat && !isSingleplayer()) { - v3POS nocheat_p = playersao->getNoCheatDigPos(); + v3pos_t nocheat_p = playersao->getNoCheatDigPos(); float nocheat_t = playersao->getNoCheatDigTime(); playersao->noCheatDigEnd(); // If player didn't start digging this, ignore dig @@ -1222,7 +1222,7 @@ void Server::handleCommand_Interact(NetworkPacket *pkt) if (is_valid_dig && n.getContent() != CONTENT_IGNORE) m_script->node_on_dig(p_under, n, playersao); - v3BPOS blockpos = getNodeBlockPos(p_under); + v3bpos_t blockpos = getNodeBlockPos(p_under); RemoteClient *client = getClient(peer_id); // Send unusual result (that is, node not being removed) if (m_env->getMap().getNode(p_under).getContent() != CONTENT_AIR) @@ -1279,8 +1279,8 @@ void Server::handleCommand_Interact(NetworkPacket *pkt) // If item has node placement prediction, always send the // blocks to make sure the client knows what exactly happened RemoteClient *client = getClient(peer_id); - v3BPOS blockpos = getNodeBlockPos(pointed.node_abovesurface); - v3BPOS blockpos2 = getNodeBlockPos(pointed.node_undersurface); + v3bpos_t blockpos = getNodeBlockPos(pointed.node_abovesurface); + v3bpos_t blockpos2 = getNodeBlockPos(pointed.node_undersurface); if (had_prediction) { client->SetBlockNotSent(blockpos); if (blockpos2 != blockpos) @@ -1358,7 +1358,7 @@ void Server::handleCommand_RemovedSounds(NetworkPacket* pkt) void Server::handleCommand_NodeMetaFields(NetworkPacket* pkt) { - v3POS p; + v3pos_t p; std::string formname; u16 num; diff --git a/src/nodedef.h b/src/nodedef.h index d5fff2a5ac..df4fee6497 100644 --- a/src/nodedef.h +++ b/src/nodedef.h @@ -586,7 +586,7 @@ class NodeDefManager { * contains all nodes' selection boxes. The returned box might be larger * than the minimal size if the largest node is removed from the manager. */ - inline core::aabbox3d getSelectionBoxIntUnion() const { + inline core::aabbox3d getSelectionBoxIntUnion() const { return m_selection_box_int_union; } @@ -785,7 +785,7 @@ class NodeDefManager { * contains all nodes' selection boxes. * Might be larger if big nodes are removed from the manager. */ - core::aabbox3d m_selection_box_int_union; + core::aabbox3d m_selection_box_int_union; /*! * NodeResolver instances to notify once node registration has finished. diff --git a/src/nodemetadata.cpp b/src/nodemetadata.cpp index e48cd1c245..5374bf63d7 100644 --- a/src/nodemetadata.cpp +++ b/src/nodemetadata.cpp @@ -132,7 +132,7 @@ void NodeMetadataList::serialize(std::ostream &os, u8 blockver, bool disk, for (NodeMetadataMap::const_iterator i = m_data.begin(); i != m_data.end(); ++i) { - v3POS p = i->first; + v3pos_t p = i->first; NodeMetadata *data = i->second; if (!include_empty && data->empty()) continue; @@ -172,7 +172,7 @@ void NodeMetadataList::deSerialize(std::istream &is, u16 count = readU16(is); for (u16 i = 0; i < count; i++) { - v3POS p; + v3pos_t p; if (absolute_pos) { p.X = readPOS(is); p.Y = readPOS(is); @@ -203,9 +203,9 @@ NodeMetadataList::~NodeMetadataList() clear(); } -std::vector NodeMetadataList::getAllKeys() +std::vector NodeMetadataList::getAllKeys() { - std::vector keys; + std::vector keys; keys.reserve(m_data.size()); for (const auto &it : m_data) keys.push_back(it.first); @@ -213,7 +213,7 @@ std::vector NodeMetadataList::getAllKeys() return keys; } -NodeMetadata *NodeMetadataList::get(v3POS p) +NodeMetadata *NodeMetadataList::get(v3pos_t p) { NodeMetadataMap::const_iterator n = m_data.find(p); if (n == m_data.end()) @@ -221,7 +221,7 @@ NodeMetadata *NodeMetadataList::get(v3POS p) return n->second; } -void NodeMetadataList::remove(v3POS p) +void NodeMetadataList::remove(v3pos_t p) { NodeMetadata *olddata = get(p); if (olddata) { @@ -231,7 +231,7 @@ void NodeMetadataList::remove(v3POS p) } } -void NodeMetadataList::set(v3POS p, NodeMetadata *d) +void NodeMetadataList::set(v3pos_t p, NodeMetadata *d) { remove(p); m_data.emplace(p, d); diff --git a/src/nodemetadata.h b/src/nodemetadata.h index b659b50f45..fe6ec0338a 100644 --- a/src/nodemetadata.h +++ b/src/nodemetadata.h @@ -71,7 +71,7 @@ class NodeMetadata : public Metadata List of metadata of all the nodes of a block */ -typedef std::map NodeMetadataMap; +typedef std::map NodeMetadataMap; class NodeMetadataList { @@ -88,13 +88,13 @@ class NodeMetadataList bool absolute_pos = false); // Add all keys in this list to the vector keys - std::vector getAllKeys(); + std::vector getAllKeys(); // Get pointer to data - NodeMetadata *get(v3POS p); + NodeMetadata *get(v3pos_t p); // Deletes data - void remove(v3POS p); + void remove(v3pos_t p); // Deletes old data and sets a new one - void set(v3POS p, NodeMetadata *d); + void set(v3pos_t p, NodeMetadata *d); // Deletes all void clear(); diff --git a/src/nodetimer.cpp b/src/nodetimer.cpp index d139ffedec..6d56185e18 100644 --- a/src/nodetimer.cpp +++ b/src/nodetimer.cpp @@ -64,7 +64,7 @@ void NodeTimerList::serialize(std::ostream &os, u8 map_format_version) const NodeTimer t = timer.second; NodeTimer nt = NodeTimer(t.timeout, t.timeout - (f32)(timer.first - m_time), t.position); - v3POS p = t.position; + v3pos_t p = t.position; u16 p16 = p.Z * MAP_BLOCKSIZE * MAP_BLOCKSIZE + p.Y * MAP_BLOCKSIZE + p.X; writeU16(os, p16); @@ -95,7 +95,7 @@ void NodeTimerList::deSerialize(std::istream &is, u8 map_format_version) for (u16 i = 0; i < count; i++) { u16 p16 = readU16(is); - v3POS p; + v3pos_t p; p.Z = p16 / MAP_BLOCKSIZE / MAP_BLOCKSIZE; p16 &= MAP_BLOCKSIZE * MAP_BLOCKSIZE - 1; p.Y = p16 / MAP_BLOCKSIZE; diff --git a/src/nodetimer.h b/src/nodetimer.h index 29a6163735..8c1dba23da 100644 --- a/src/nodetimer.h +++ b/src/nodetimer.h @@ -36,9 +36,9 @@ class NodeTimer { public: NodeTimer() = default; - NodeTimer(const v3POS &position_): + NodeTimer(const v3pos_t &position_): position(position_) {} - NodeTimer(f32 timeout_, f32 elapsed_, v3POS position_): + NodeTimer(f32 timeout_, f32 elapsed_, v3pos_t position_): timeout(timeout_), elapsed(elapsed_), position(position_) {} ~NodeTimer() = default; @@ -47,7 +47,7 @@ class NodeTimer f32 timeout = 0.0f; f32 elapsed = 0.0f; - v3POS position; + v3pos_t position; }; /* @@ -64,8 +64,8 @@ class NodeTimerList void deSerialize(std::istream &is, u8 map_format_version); // Get timer - NodeTimer get(const v3POS &p) { - std::map::iterator>::iterator n = + NodeTimer get(const v3pos_t &p) { + std::map::iterator>::iterator n = m_iterators.find(p); if (n == m_iterators.end()) return NodeTimer(); @@ -74,8 +74,8 @@ class NodeTimerList return t; } // Deletes timer - void remove(v3POS p) { - std::map::iterator>::iterator n = + void remove(v3pos_t p) { + std::map::iterator>::iterator n = m_iterators.find(p); if(n != m_iterators.end()) { double removed_time = n->second->first; @@ -94,14 +94,14 @@ class NodeTimerList } // Undefined behaviour if there already is a timer void insert(NodeTimer timer) { - v3POS p = timer.position; + v3pos_t p = timer.position; double trigger_time = m_time + (double)(timer.timeout - timer.elapsed); std::multimap::iterator it = m_timers.insert(std::pair( trigger_time, timer )); m_iterators.insert( - std::pair::iterator>(p, it)); + std::pair::iterator>(p, it)); if (m_next_trigger_time == -1. || trigger_time < m_next_trigger_time) m_next_trigger_time = trigger_time; } @@ -122,7 +122,7 @@ class NodeTimerList private: std::multimap m_timers; - std::map::iterator> m_iterators; + std::map::iterator> m_iterators; double m_next_trigger_time = -1.0; double m_time = 0.0; }; diff --git a/src/pathfinder.cpp b/src/pathfinder.cpp index bb4083a102..f983540315 100644 --- a/src/pathfinder.cpp +++ b/src/pathfinder.cpp @@ -105,22 +105,22 @@ class PathGridnode { * read cost in a specific direction * @param dir direction of cost to fetch */ - PathCost getCost(v3POS dir); + PathCost getCost(v3pos_t dir); /** * set cost value for movement * @param dir direction to set cost for * @cost cost to set */ - void setCost(v3POS dir, const PathCost &cost); + void setCost(v3pos_t dir, const PathCost &cost); bool valid = false; /**< node is on surface */ bool target = false; /**< node is target position */ bool source = false; /**< node is stating position */ int totalcost = -1; /**< cost to move here from starting point */ int estimated_cost = -1; /**< totalcost + heuristic cost to end */ - v3POS sourcedir; /**< origin of movement for current cost */ - v3POS pos; /**< real position of node */ + v3pos_t sourcedir; /**< origin of movement for current cost */ + v3pos_t pos; /**< real position of node */ PathCost directions[4]; /**< cost in different directions */ bool is_closed = false; /**< for A* search: if true, is in closed list */ bool is_open = false; /**< for A* search: if true, is in open list */ @@ -142,21 +142,21 @@ class PathfinderCompareHeuristic; /** Abstract class to manage the map data */ class GridNodeContainer { public: - virtual PathGridnode &access(v3POS p)=0; + virtual PathGridnode &access(v3pos_t p)=0; virtual ~GridNodeContainer() = default; protected: Pathfinder *m_pathf; - void initNode(v3POS ipos, PathGridnode *p_node); + void initNode(v3pos_t ipos, PathGridnode *p_node); }; class ArrayGridNodeContainer : public GridNodeContainer { public: virtual ~ArrayGridNodeContainer() = default; - ArrayGridNodeContainer(Pathfinder *pathf, v3POS dimensions); - virtual PathGridnode &access(v3POS p); + ArrayGridNodeContainer(Pathfinder *pathf, v3pos_t dimensions); + virtual PathGridnode &access(v3pos_t p); private: int m_x_stride; @@ -169,9 +169,9 @@ class MapGridNodeContainer : public GridNodeContainer { virtual ~MapGridNodeContainer() = default; MapGridNodeContainer(Pathfinder *pathf); - virtual PathGridnode &access(v3POS p); + virtual PathGridnode &access(v3pos_t p); private: - std::map m_nodes; + std::map m_nodes; }; /** class doing pathfinding */ @@ -193,8 +193,8 @@ class Pathfinder { * @param max_drop maximum number of blocks a path may drop * @param algo Algorithm to use for finding a path */ - std::vector getPath(v3POS source, - v3POS destination, + std::vector getPath(v3pos_t source, + v3pos_t destination, unsigned int searchdistance, unsigned int max_jump, unsigned int max_drop, @@ -208,41 +208,41 @@ class Pathfinder { * @param ipos a index position * @return map position */ - v3POS getRealPos(v3POS ipos); + v3pos_t getRealPos(v3pos_t ipos); /** * transform mappos to index pos * @param pos a real pos * @return index position */ - v3POS getIndexPos(v3POS pos); + v3pos_t getIndexPos(v3pos_t pos); /** * get gridnode at a specific index position * @param ipos index position * @return gridnode for index */ - PathGridnode &getIndexElement(v3POS ipos); + PathGridnode &getIndexElement(v3pos_t ipos); /** * Get gridnode at a specific index position * @return gridnode for index */ - PathGridnode &getIdxElem(POS x, POS y, POS z); + PathGridnode &getIdxElem(pos_t x, pos_t y, pos_t z); /** * invert a 3D position (change sign of coordinates) * @param pos 3D position * @return pos *-1 */ - v3POS invert(v3POS pos); + v3pos_t invert(v3pos_t pos); /** * check if a index is within current search area * @param index position to validate * @return true/false */ - bool isValidIndex(v3POS index); + bool isValidIndex(v3pos_t index); /* algorithm functions */ @@ -252,7 +252,7 @@ class Pathfinder { * @param pos position to calc distance * @return integer distance */ - int getXZManhattanDist(v3POS pos); + int getXZManhattanDist(v3pos_t pos); /** * calculate cost of movement @@ -260,7 +260,7 @@ class Pathfinder { * @param dir direction to move to * @return cost information */ - PathCost calcCost(v3POS pos, v3POS dir); + PathCost calcCost(v3pos_t pos, v3pos_t dir); /** * recursive update whole search areas total cost information @@ -270,7 +270,7 @@ class Pathfinder { * @param level current recursion depth * @return true/false path to destination has been found */ - bool updateAllCosts(v3POS ipos, v3POS srcdir, int current_cost, int level); + bool updateAllCosts(v3pos_t ipos, v3pos_t srcdir, int current_cost, int level); /** * try to find a path to destination using a heuristic function @@ -279,7 +279,7 @@ class Pathfinder { * @param idestination end position (index pos) * @return true/false path to destination has been found */ - bool updateCostHeuristic(v3POS isource, v3POS idestination); + bool updateCostHeuristic(v3pos_t isource, v3pos_t idestination); /** * build a vector containing all nodes from destination to source; @@ -288,7 +288,7 @@ class Pathfinder { * @param ipos initial pos to check (index pos) * @return true/false path has been fully built */ - bool buildPath(std::vector &path, v3POS ipos); + bool buildPath(std::vector &path, v3pos_t ipos); /** * go downwards from a position until some barrier @@ -298,7 +298,7 @@ class Pathfinder { * @return new position after movement; if too far down, * pos is returned */ - v3POS walkDownwards(v3POS pos, unsigned int max_down); + v3pos_t walkDownwards(v3pos_t pos, unsigned int max_down); /* variables */ int m_max_index_x = 0; /**< max index of search area in x direction */ @@ -311,10 +311,10 @@ class Pathfinder { bool m_prefetch = true; /**< prefetch cost data */ - v3POS m_start; /**< source position */ - v3POS m_destination; /**< destination position */ + v3pos_t m_start; /**< source position */ + v3pos_t m_destination; /**< destination position */ - core::aabbox3d m_limits; /**< position limits in real map coordinates */ + core::aabbox3d m_limits; /**< position limits in real map coordinates */ /** contains all map data already collected and analyzed. Access it via the getIndexElement/getIdxElem methods. */ @@ -354,7 +354,7 @@ class Pathfinder { * print a path * @param path path to show */ - void printPath(std::vector path); + void printPath(std::vector path); /** * print y direction for all movements @@ -388,9 +388,9 @@ class PathfinderCompareHeuristic { myPathfinder = pf; } - bool operator() (v3POS pos1, v3POS pos2) { - v3POS ipos1 = myPathfinder->getIndexPos(pos1); - v3POS ipos2 = myPathfinder->getIndexPos(pos2); + bool operator() (v3pos_t pos1, v3pos_t pos2) { + v3pos_t ipos1 = myPathfinder->getIndexPos(pos1); + v3pos_t ipos2 = myPathfinder->getIndexPos(pos2); PathGridnode &g_pos1 = myPathfinder->getIndexElement(ipos1); PathGridnode &g_pos2 = myPathfinder->getIndexElement(ipos2); if (!g_pos1.valid) @@ -405,9 +405,9 @@ class PathfinderCompareHeuristic /* implementation */ /******************************************************************************/ -std::vector get_path(Map* map, const NodeDefManager *ndef, - v3POS source, - v3POS destination, +std::vector get_path(Map* map, const NodeDefManager *ndef, + v3pos_t source, + v3pos_t destination, unsigned int searchdistance, unsigned int max_jump, unsigned int max_drop, @@ -476,7 +476,7 @@ PathGridnode &PathGridnode::operator= (const PathGridnode &b) } /******************************************************************************/ -PathCost PathGridnode::getCost(v3POS dir) +PathCost PathGridnode::getCost(v3pos_t dir) { if (dir.X > 0) { return directions[DIR_XP]; @@ -495,7 +495,7 @@ PathCost PathGridnode::getCost(v3POS dir) } /******************************************************************************/ -void PathGridnode::setCost(v3POS dir, const PathCost &cost) +void PathGridnode::setCost(v3pos_t dir, const PathCost &cost) { if (dir.X > 0) { directions[DIR_XP] = cost; @@ -511,15 +511,15 @@ void PathGridnode::setCost(v3POS dir, const PathCost &cost) } } -void GridNodeContainer::initNode(v3POS ipos, PathGridnode *p_node) +void GridNodeContainer::initNode(v3pos_t ipos, PathGridnode *p_node) { const NodeDefManager *ndef = m_pathf->m_ndef; PathGridnode &elem = *p_node; - v3POS realpos = m_pathf->getRealPos(ipos); + v3pos_t realpos = m_pathf->getRealPos(ipos); MapNode current = m_pathf->m_map->getNode(realpos); - MapNode below = m_pathf->m_map->getNode(realpos + v3POS(0, -1, 0)); + MapNode below = m_pathf->m_map->getNode(realpos + v3pos_t(0, -1, 0)); if ((current.param0 == CONTENT_IGNORE) || @@ -553,14 +553,14 @@ void GridNodeContainer::initNode(v3POS ipos, PathGridnode *p_node) DEBUG_OUT(PP(ipos) << ": " << 'a' << std::endl); if (m_pathf->m_prefetch) { - elem.directions[DIR_XP] = m_pathf->calcCost(realpos, v3POS( 1, 0, 0)); - elem.directions[DIR_XM] = m_pathf->calcCost(realpos, v3POS(-1, 0, 0)); - elem.directions[DIR_ZP] = m_pathf->calcCost(realpos, v3POS( 0, 0, 1)); - elem.directions[DIR_ZM] = m_pathf->calcCost(realpos, v3POS( 0, 0,-1)); + elem.directions[DIR_XP] = m_pathf->calcCost(realpos, v3pos_t( 1, 0, 0)); + elem.directions[DIR_XM] = m_pathf->calcCost(realpos, v3pos_t(-1, 0, 0)); + elem.directions[DIR_ZP] = m_pathf->calcCost(realpos, v3pos_t( 0, 0, 1)); + elem.directions[DIR_ZM] = m_pathf->calcCost(realpos, v3pos_t( 0, 0,-1)); } } -ArrayGridNodeContainer::ArrayGridNodeContainer(Pathfinder *pathf, v3POS dimensions) : +ArrayGridNodeContainer::ArrayGridNodeContainer(Pathfinder *pathf, v3pos_t dimensions) : m_x_stride(dimensions.Y * dimensions.Z), m_y_stride(dimensions.Z) { @@ -571,14 +571,14 @@ ArrayGridNodeContainer::ArrayGridNodeContainer(Pathfinder *pathf, v3POS dimensio for (int x = 0; x < dimensions.X; x++) { for (int y = 0; y < dimensions.Y; y++) { for (int z= 0; z < dimensions.Z; z++) { - v3POS ipos(x, y, z); + v3pos_t ipos(x, y, z); initNode(ipos, &access(ipos)); } } } } -PathGridnode &ArrayGridNodeContainer::access(v3POS p) +PathGridnode &ArrayGridNodeContainer::access(v3pos_t p) { return m_nodes_array[p.X * m_x_stride + p.Y * m_y_stride + p.Z]; } @@ -588,9 +588,9 @@ MapGridNodeContainer::MapGridNodeContainer(Pathfinder *pathf) m_pathf = pathf; } -PathGridnode &MapGridNodeContainer::access(v3POS p) +PathGridnode &MapGridNodeContainer::access(v3pos_t p) { - std::map::iterator it = m_nodes.find(p); + std::map::iterator it = m_nodes.find(p); if (it != m_nodes.end()) { return it->second; } @@ -602,8 +602,8 @@ PathGridnode &MapGridNodeContainer::access(v3POS p) /******************************************************************************/ -std::vector Pathfinder::getPath(v3POS source, - v3POS destination, +std::vector Pathfinder::getPath(v3pos_t source, + v3pos_t destination, unsigned int searchdistance, unsigned int max_jump, unsigned int max_drop, @@ -613,7 +613,7 @@ std::vector Pathfinder::getPath(v3POS source, timespec ts; clock_gettime(CLOCK_REALTIME, &ts); #endif - std::vector retval; + std::vector retval; //initialization m_maxjump = max_jump; @@ -645,7 +645,7 @@ std::vector Pathfinder::getPath(v3POS source, m_limits.MaxEdge.Y = max_y + searchdistance; m_limits.MaxEdge.Z = max_z + searchdistance; - v3POS diff = m_limits.MaxEdge - m_limits.MinEdge; + v3pos_t diff = m_limits.MaxEdge - m_limits.MinEdge; m_max_index_x = diff.X; m_max_index_y = diff.Y; @@ -681,20 +681,20 @@ std::vector Pathfinder::getPath(v3POS source, //to the first walkable node (up to m_maxdrop). //All algorithms expect the source pos to be *directly* above //a walkable node. - v3POS true_source = v3POS(source); + v3pos_t true_source = v3pos_t(source); source = walkDownwards(source, m_maxdrop); //If destination pos is hovering above air, go downwards //to the first walkable node (up to m_maxjump). //This means a hovering destination pos could be reached //by a final upwards jump. - v3POS true_destination = v3POS(destination); + v3pos_t true_destination = v3pos_t(destination); destination = walkDownwards(destination, m_maxjump); //validate and mark start and end pos - v3POS StartIndex = getIndexPos(source); - v3POS EndIndex = getIndexPos(destination); + v3pos_t StartIndex = getIndexPos(source); + v3pos_t EndIndex = getIndexPos(destination); PathGridnode &startpos = getIndexElement(StartIndex); PathGridnode &endpos = getIndexElement(EndIndex); @@ -721,7 +721,7 @@ std::vector Pathfinder::getPath(v3POS source, //calculate node costs switch (algo) { case PA_DIJKSTRA: - update_cost_retval = updateAllCosts(StartIndex, v3POS(0, 0, 0), 0, 0); + update_cost_retval = updateAllCosts(StartIndex, v3pos_t(0, 0, 0), 0, 0); break; case PA_PLAIN_NP: case PA_PLAIN: @@ -740,7 +740,7 @@ std::vector Pathfinder::getPath(v3POS source, #endif //find path - std::vector index_path; + std::vector index_path; buildPath(index_path, EndIndex); //Now we have a path of index positions, //and it's in reverse. @@ -752,7 +752,7 @@ std::vector Pathfinder::getPath(v3POS source, printPath(index_path); #endif //from here we'll make the final changes to the path - std::vector full_path; + std::vector full_path; //calculate required size int full_path_size = index_path.size(); @@ -770,7 +770,7 @@ std::vector Pathfinder::getPath(v3POS source, } //convert all index positions to "normal" positions and insert //them into full_path in reverse - std::vector::reverse_iterator rit = index_path.rbegin(); + std::vector::reverse_iterator rit = index_path.rbegin(); for (; rit != index_path.rend(); ++rit) { full_path.push_back(getIndexElement(*rit).pos); } @@ -817,19 +817,19 @@ Pathfinder::~Pathfinder() delete m_nodes_container; } /******************************************************************************/ -v3POS Pathfinder::getRealPos(v3POS ipos) +v3pos_t Pathfinder::getRealPos(v3pos_t ipos) { return m_limits.MinEdge + ipos; } /******************************************************************************/ -PathCost Pathfinder::calcCost(v3POS pos, v3POS dir) +PathCost Pathfinder::calcCost(v3pos_t pos, v3pos_t dir) { PathCost retval; retval.updated = true; - v3POS pos2 = pos + dir; + v3pos_t pos2 = pos + dir; //check limits if (!m_limits.isPointInside(pos2)) { @@ -849,12 +849,12 @@ PathCost Pathfinder::calcCost(v3POS pos, v3POS dir) if (!m_ndef->get(node_at_pos2).walkable) { MapNode node_below_pos2 = - m_map->getNode(pos2 + v3POS(0, -1, 0)); + m_map->getNode(pos2 + v3pos_t(0, -1, 0)); //did we get information about node? if (node_below_pos2.param0 == CONTENT_IGNORE ) { VERBOSE_TARGET << "Pathfinder: (2) area at pos: " - << PP((pos2 + v3POS(0, -1, 0))) << " not loaded"; + << PP((pos2 + v3pos_t(0, -1, 0))) << " not loaded"; return retval; } @@ -869,13 +869,13 @@ PathCost Pathfinder::calcCost(v3POS pos, v3POS dir) } else { //test if we can fall a couple of nodes (m_maxdrop) - v3POS testpos = pos2 + v3POS(0, -1, 0); + v3pos_t testpos = pos2 + v3pos_t(0, -1, 0); MapNode node_at_pos = m_map->getNode(testpos); while ((node_at_pos.param0 != CONTENT_IGNORE) && (!m_ndef->get(node_at_pos).walkable) && (testpos.Y > m_limits.MinEdge.Y)) { - testpos += v3POS(0, -1, 0); + testpos += v3pos_t(0, -1, 0); node_at_pos = m_map->getNode(testpos); } @@ -906,8 +906,8 @@ PathCost Pathfinder::calcCost(v3POS pos, v3POS dir) else { //test if we can jump upwards (m_maxjump) - v3POS targetpos = pos2; // position for jump target - v3POS jumppos = pos; // position for checking if jumping space is free + v3pos_t targetpos = pos2; // position for jump target + v3pos_t jumppos = pos; // position for checking if jumping space is free MapNode node_target = m_map->getNode(targetpos); MapNode node_jump = m_map->getNode(jumppos); bool headbanger = false; // true if anything blocks jumppath @@ -921,8 +921,8 @@ PathCost Pathfinder::calcCost(v3POS pos, v3POS dir) headbanger = true; break; } - targetpos += v3POS(0, 1, 0); - jumppos += v3POS(0, 1, 0); + targetpos += v3pos_t(0, 1, 0); + jumppos += v3pos_t(0, 1, 0); node_target = m_map->getNode(targetpos); node_jump = m_map->getNode(jumppos); @@ -958,25 +958,25 @@ PathCost Pathfinder::calcCost(v3POS pos, v3POS dir) } /******************************************************************************/ -v3POS Pathfinder::getIndexPos(v3POS pos) +v3pos_t Pathfinder::getIndexPos(v3pos_t pos) { return pos - m_limits.MinEdge; } /******************************************************************************/ -PathGridnode &Pathfinder::getIndexElement(v3POS ipos) +PathGridnode &Pathfinder::getIndexElement(v3pos_t ipos) { return m_nodes_container->access(ipos); } /******************************************************************************/ -inline PathGridnode &Pathfinder::getIdxElem(POS x, POS y, POS z) +inline PathGridnode &Pathfinder::getIdxElem(pos_t x, pos_t y, pos_t z) { - return m_nodes_container->access(v3POS(x,y,z)); + return m_nodes_container->access(v3pos_t(x,y,z)); } /******************************************************************************/ -bool Pathfinder::isValidIndex(v3POS index) +bool Pathfinder::isValidIndex(v3pos_t index) { if ( (index.X < m_max_index_x) && (index.Y < m_max_index_y) && @@ -990,9 +990,9 @@ bool Pathfinder::isValidIndex(v3POS index) } /******************************************************************************/ -v3POS Pathfinder::invert(v3POS pos) +v3pos_t Pathfinder::invert(v3pos_t pos) { - v3POS retval = pos; + v3pos_t retval = pos; retval.X *=-1; retval.Y *=-1; @@ -1002,8 +1002,8 @@ v3POS Pathfinder::invert(v3POS pos) } /******************************************************************************/ -bool Pathfinder::updateAllCosts(v3POS ipos, - v3POS srcdir, +bool Pathfinder::updateAllCosts(v3pos_t ipos, + v3pos_t srcdir, int current_cost, int level) { @@ -1023,21 +1023,21 @@ bool Pathfinder::updateAllCosts(v3POS ipos, bool retval = false; // the 4 cardinal directions - const static v3POS directions[4] = { - v3POS(1,0, 0), - v3POS(-1,0, 0), - v3POS(0,0, 1), - v3POS(0,0,-1) + const static v3pos_t directions[4] = { + v3pos_t(1,0, 0), + v3pos_t(-1,0, 0), + v3pos_t(0,0, 1), + v3pos_t(0,0,-1) }; - for (v3POS direction : directions) { + for (v3pos_t direction : directions) { if (direction != srcdir) { PathCost cost = g_pos.getCost(direction); if (cost.valid) { direction.Y = cost.y_change; - v3POS ipos2 = ipos + direction; + v3pos_t ipos2 = ipos + direction; if (!isValidIndex(ipos2)) { DEBUG_OUT(LVL " Pathfinder: " << PP(ipos2) << @@ -1090,7 +1090,7 @@ bool Pathfinder::updateAllCosts(v3POS ipos, } /******************************************************************************/ -int Pathfinder::getXZManhattanDist(v3POS pos) +int Pathfinder::getXZManhattanDist(v3pos_t pos) { int min_x = MYMIN(pos.X, m_destination.X); int max_x = MYMAX(pos.X, m_destination.X); @@ -1103,31 +1103,31 @@ int Pathfinder::getXZManhattanDist(v3POS pos) /******************************************************************************/ -bool Pathfinder::updateCostHeuristic(v3POS isource, v3POS idestination) +bool Pathfinder::updateCostHeuristic(v3pos_t isource, v3pos_t idestination) { // A* search algorithm. // The open list contains the pathfinder nodes that still need to be // checked. The priority queue sorts the pathfinder nodes by // estimated cost, with lowest cost on the top. - std::priority_queue, PathfinderCompareHeuristic> + std::priority_queue, PathfinderCompareHeuristic> openList(PathfinderCompareHeuristic(this)); - v3POS source = getRealPos(isource); - v3POS destination = getRealPos(idestination); + v3pos_t source = getRealPos(isource); + v3pos_t destination = getRealPos(idestination); // initial position openList.push(source); // the 4 cardinal directions - const static v3POS directions[4] = { - v3POS(1,0, 0), - v3POS(-1,0, 0), - v3POS(0,0, 1), - v3POS(0,0,-1) + const static v3pos_t directions[4] = { + v3pos_t(1,0, 0), + v3pos_t(-1,0, 0), + v3pos_t(0,0, 1), + v3pos_t(0,0,-1) }; - v3POS current_pos; + v3pos_t current_pos; PathGridnode& s_pos = getIndexElement(isource); s_pos.source = true; s_pos.totalcost = 0; @@ -1141,7 +1141,7 @@ bool Pathfinder::updateCostHeuristic(v3POS isource, v3POS idestination) // The "cheapest" node is always on top. current_pos = openList.top(); openList.pop(); - v3POS ipos = getIndexPos(current_pos); + v3pos_t ipos = getIndexPos(current_pos); // check if node is inside searchdistance and valid if (!isValidIndex(ipos)) { @@ -1164,7 +1164,7 @@ bool Pathfinder::updateCostHeuristic(v3POS isource, v3POS idestination) } // for this node, check the 4 cardinal directions - for (v3POS direction_flat : directions) { + for (v3pos_t direction_flat : directions) { int current_totalcost = g_pos.totalcost; // get cost from current node to currently checked direction @@ -1174,12 +1174,12 @@ bool Pathfinder::updateCostHeuristic(v3POS isource, v3POS idestination) g_pos.setCost(direction_flat, cost); } // update Y component of direction if neighbor requires jump or fall - v3POS direction_3d = v3POS(direction_flat); + v3pos_t direction_3d = v3pos_t(direction_flat); direction_3d.Y = cost.y_change; // get position of true neighbor - v3POS neighbor = current_pos + direction_3d; - v3POS ineighbor = getIndexPos(neighbor); + v3pos_t neighbor = current_pos + direction_3d; + v3pos_t ineighbor = getIndexPos(neighbor); PathGridnode &n_pos = getIndexElement(ineighbor); if (cost.valid && !n_pos.is_closed && !n_pos.is_open) { @@ -1200,7 +1200,7 @@ bool Pathfinder::updateCostHeuristic(v3POS isource, v3POS idestination) } /******************************************************************************/ -bool Pathfinder::buildPath(std::vector &path, v3POS ipos) +bool Pathfinder::buildPath(std::vector &path, v3pos_t ipos) { // The cost calculation should have set a source direction for all relevant nodes. // To build the path, we go backwards from the destination until we reach the start. @@ -1231,17 +1231,17 @@ bool Pathfinder::buildPath(std::vector &path, v3POS ipos) } /******************************************************************************/ -v3POS Pathfinder::walkDownwards(v3POS pos, unsigned int max_down) { +v3pos_t Pathfinder::walkDownwards(v3pos_t pos, unsigned int max_down) { if (max_down == 0) return pos; - v3POS testpos = v3POS(pos); + v3pos_t testpos = v3pos_t(pos); MapNode node_at_pos = m_map->getNode(testpos); unsigned int down = 0; while ((node_at_pos.param0 != CONTENT_IGNORE) && (!m_ndef->get(node_at_pos).walkable) && (testpos.Y > m_limits.MinEdge.Y) && (down <= max_down)) { - testpos += v3POS(0, -1, 0); + testpos += v3pos_t(0, -1, 0); down++; node_at_pos = m_map->getNode(testpos); } @@ -1253,7 +1253,7 @@ v3POS Pathfinder::walkDownwards(v3POS pos, unsigned int max_down) { pos = testpos; } else if ((down - 1) <= max_down) { //difference of y-pos +1 (target node is ABOVE solid node) - testpos += v3POS(0, 1, 0); + testpos += v3pos_t(0, 1, 0); pos = testpos; } else { @@ -1428,10 +1428,10 @@ std::string Pathfinder::dirToName(PathDirections dir) } /******************************************************************************/ -void Pathfinder::printPath(const std::vector &path) +void Pathfinder::printPath(const std::vector &path) { unsigned int current = 0; - for (std::vector::iterator i = path.begin(); + for (std::vector::iterator i = path.begin(); i != path.end(); ++i) { std::cout << std::setw(3) << current << ":" << PP((*i)) << std::endl; current++; diff --git a/src/pathfinder.h b/src/pathfinder.h index cfde4f63d8..241b557217 100644 --- a/src/pathfinder.h +++ b/src/pathfinder.h @@ -55,9 +55,9 @@ typedef enum { /******************************************************************************/ /** c wrapper function to use from scriptapi */ -std::vector get_path(Map *map, const NodeDefManager *ndef, - v3POS source, - v3POS destination, +std::vector get_path(Map *map, const NodeDefManager *ndef, + v3pos_t source, + v3pos_t destination, unsigned int searchdistance, unsigned int max_jump, unsigned int max_drop, diff --git a/src/raycast.cpp b/src/raycast.cpp index 4e2148bd79..4a7b2f8d41 100644 --- a/src/raycast.cpp +++ b/src/raycast.cpp @@ -68,7 +68,7 @@ RaycastState::RaycastState(const core::line3d &shootline, bool boxLineCollision(const aabb3f &box, const v3f &start, - const v3f &dir, v3f *collision_point, v3POS *collision_normal) + const v3f &dir, v3f *collision_point, v3pos_t *collision_normal) { if (box.isPointInside(start)) { *collision_point = start; diff --git a/src/raycast.h b/src/raycast.h index c950a2a16f..eb32fd6d1e 100644 --- a/src/raycast.h +++ b/src/raycast.h @@ -45,7 +45,7 @@ class RaycastState //! Iterator to store the progress of the raycast. voxalgo::VoxelLineIterator m_iterator; //! Previous tested node during the raycast. - v3POS m_previous_node; + v3pos_t m_previous_node; /*! * This priority queue stores the found pointed things @@ -57,7 +57,7 @@ class RaycastState bool m_liquids_pointable; //! The code needs to search these nodes around the center node. - core::aabbox3d m_search_range { 0, 0, 0, 0, 0, 0 }; + core::aabbox3d m_search_range { 0, 0, 0, 0, 0, 0 }; //! If true, the Environment will initialize this state. bool m_initialization_needed = true; @@ -74,4 +74,4 @@ class RaycastState * @returns true if a collision point was found */ bool boxLineCollision(const aabb3f &box, const v3f &start, const v3f &dir, - v3f *collision_point, v3POS *collision_normal); + v3f *collision_point, v3pos_t *collision_normal); diff --git a/src/reflowscan.cpp b/src/reflowscan.cpp index b76a654a90..b098b6ee9d 100644 --- a/src/reflowscan.cpp +++ b/src/reflowscan.cpp @@ -30,7 +30,7 @@ ReflowScan::ReflowScan(Map *map, const NodeDefManager *ndef) : { } -void ReflowScan::scan(MapBlock *block, UniqueQueue *liquid_queue) +void ReflowScan::scan(MapBlock *block, UniqueQueue *liquid_queue) { m_block_pos = block->getPos(); m_rel_block_pos = block->getPosRelative(); @@ -75,7 +75,7 @@ inline MapBlock *ReflowScan::lookupBlock(int x, int y, int z) if (!result && (m_lookup_state_bitset & (1 << idx)) == 0) { // The block wasn't requested yet so fetch it from Map and store it // in the lookup - v3POS pos = m_block_pos + v3POS(bx - 1, by - 1, bz - 1); + v3pos_t pos = m_block_pos + v3pos_t(bx - 1, by - 1, bz - 1); m_lookup[idx] = result = m_map->getBlockNoCreateNoEx(pos); m_lookup_state_bitset |= (1 << idx); } @@ -155,7 +155,7 @@ void ReflowScan::scanColumn(int x, int z) bool is_pushed = false; if (f.liquid_type == LIQUID_FLOWING || isLiquidHorizontallyFlowable(x, y, z)) { - m_liquid_queue->push_back(m_rel_block_pos + v3POS(x, y, z)); + m_liquid_queue->push_back(m_rel_block_pos + v3pos_t(x, y, z)); is_pushed = true; } // Remember waschecked and waspushed to avoid repeated @@ -168,7 +168,7 @@ void ReflowScan::scanColumn(int x, int z) (!was_checked && isLiquidHorizontallyFlowable(x, y + 1, z)))) { // Activate the lowest node in the column which is one // node above this one - m_liquid_queue->push_back(m_rel_block_pos + v3POS(x, y + 1, z)); + m_liquid_queue->push_back(m_rel_block_pos + v3pos_t(x, y + 1, z)); } } @@ -190,7 +190,7 @@ void ReflowScan::scanColumn(int x, int z) // This is the topmost node in the column and might want to flow away if (f.liquid_type == LIQUID_FLOWING || isLiquidHorizontallyFlowable(x, -1, z)) { - m_liquid_queue->push_back(m_rel_block_pos + v3POS(x, -1, z)); + m_liquid_queue->push_back(m_rel_block_pos + v3pos_t(x, -1, z)); } } else { // This is the topmost node below a liquid column @@ -198,7 +198,7 @@ void ReflowScan::scanColumn(int x, int z) (!was_checked && isLiquidHorizontallyFlowable(x, 0, z)))) { // Activate the lowest node in the column which is one // node above this one - m_liquid_queue->push_back(m_rel_block_pos + v3POS(x, 0, z)); + m_liquid_queue->push_back(m_rel_block_pos + v3pos_t(x, 0, z)); } } } diff --git a/src/reflowscan.h b/src/reflowscan.h index 21ab82099d..0ce4102ba4 100644 --- a/src/reflowscan.h +++ b/src/reflowscan.h @@ -29,7 +29,7 @@ class MapBlock; class ReflowScan { public: ReflowScan(Map *map, const NodeDefManager *ndef); - void scan(MapBlock *block, UniqueQueue *liquid_queue); + void scan(MapBlock *block, UniqueQueue *liquid_queue); private: MapBlock *lookupBlock(int x, int y, int z); @@ -40,8 +40,8 @@ class ReflowScan { private: Map *m_map = nullptr; const NodeDefManager *m_ndef = nullptr; - v3POS m_block_pos, m_rel_block_pos; - UniqueQueue *m_liquid_queue = nullptr; + v3pos_t m_block_pos, m_rel_block_pos; + UniqueQueue *m_liquid_queue = nullptr; MapBlock *m_lookup[3 * 3 * 3]; u32 m_lookup_state_bitset; }; diff --git a/src/rollback.cpp b/src/rollback.cpp index c0851b58b8..211413985a 100644 --- a/src/rollback.cpp +++ b/src/rollback.cpp @@ -596,7 +596,7 @@ const std::list RollbackManager::rollbackActionsFromActionRows( break; case RollbackAction::TYPE_SET_NODE: - action.p = v3POS(row.x, row.y, row.z); + action.p = v3pos_t(row.x, row.y, row.z); action.n_old.name = getNodeName(row.oldNode); action.n_old.param1 = row.oldParam1; action.n_old.param2 = row.oldParam2; @@ -636,7 +636,7 @@ const std::list RollbackManager::getRowsSince(time_t firstTime, const const std::list RollbackManager::getRowsSince_range( - time_t start_time, v3POS p, int range, int limit) + time_t start_time, v3pos_t p, int range, int limit) { sqlite3_bind_int64(stmt_select_range, 1, start_time); @@ -656,7 +656,7 @@ const std::list RollbackManager::getRowsSince_range( const std::list RollbackManager::getActionsSince_range( - time_t start_time, v3POS p, int range, int limit) + time_t start_time, v3pos_t p, int range, int limit) { return rollbackActionsFromActionRows(getRowsSince_range(start_time, p, range, limit)); } @@ -794,8 +794,8 @@ void RollbackManager::migrate(const std::string & file_path) // Get nearness factor for subject's action for this action // Return value: 0 = impossible, >0 = factor -float RollbackManager::getSuspectNearness(bool is_guess, v3POS suspect_p, - time_t suspect_t, v3POS action_p, time_t action_t) +float RollbackManager::getSuspectNearness(bool is_guess, v3pos_t suspect_p, + time_t suspect_t, v3pos_t action_p, time_t action_t) { // Suspect cannot cause things in the past if (action_t < suspect_t) { @@ -834,7 +834,7 @@ void RollbackManager::reportAction(const RollbackAction &action_) action.actor_is_guess = current_actor_is_guess; if (action.actor.empty()) { // If actor is not known, find out suspect or cancel - v3POS p; + v3pos_t p; if (!action.getPosition(&p)) { return; } @@ -866,7 +866,7 @@ void RollbackManager::setActor(const std::string & actor, bool is_guess) current_actor_is_guess = is_guess; } -std::string RollbackManager::getSuspect(v3POS p, float nearness_shortcut, +std::string RollbackManager::getSuspect(v3pos_t p, float nearness_shortcut, float min_nearness) { if (!current_actor.empty()) { @@ -886,7 +886,7 @@ std::string RollbackManager::getSuspect(v3POS p, float nearness_shortcut, continue; } // Find position of suspect or continue - v3POS suspect_p; + v3pos_t suspect_p; if (!i->getPosition(&suspect_p)) { continue; } @@ -941,7 +941,7 @@ void RollbackManager::addAction(const RollbackAction & action) } } -std::list RollbackManager::getNodeActors(v3POS pos, int range, +std::list RollbackManager::getNodeActors(v3pos_t pos, int range, time_t seconds, int limit) { flush(); diff --git a/src/rollback.h b/src/rollback.h index 5b7646c665..ad9ed48970 100644 --- a/src/rollback.h +++ b/src/rollback.h @@ -41,12 +41,12 @@ class RollbackManager: public IRollbackManager std::string getActor(); bool isActorGuess(); void setActor(const std::string & actor, bool is_guess); - std::string getSuspect(v3POS p, float nearness_shortcut, + std::string getSuspect(v3pos_t p, float nearness_shortcut, float min_nearness); void flush(); void addAction(const RollbackAction & action); - std::list getNodeActors(v3POS pos, int range, + std::list getNodeActors(v3pos_t pos, int range, time_t seconds, int limit); std::list getRevertActions( const std::string & actor_filter, time_t seconds); @@ -67,15 +67,15 @@ class RollbackManager: public IRollbackManager const std::list & rows); const std::list getRowsSince(time_t firstTime, const std::string & actor); - const std::list getRowsSince_range(time_t firstTime, v3POS p, + const std::list getRowsSince_range(time_t firstTime, v3pos_t p, int range, int limit); - const std::list getActionsSince_range(time_t firstTime, v3POS p, + const std::list getActionsSince_range(time_t firstTime, v3pos_t p, int range, int limit); const std::list getActionsSince(time_t firstTime, const std::string & actor = ""); void migrate(const std::string & filepath); - static float getSuspectNearness(bool is_guess, v3POS suspect_p, - time_t suspect_t, v3POS action_p, time_t action_t); + static float getSuspectNearness(bool is_guess, v3pos_t suspect_p, + time_t suspect_t, v3pos_t action_p, time_t action_t); IGameDef *gamedef = nullptr; diff --git a/src/rollback_interface.cpp b/src/rollback_interface.cpp index 9cdf5b40b5..5f3156fe18 100644 --- a/src/rollback_interface.cpp +++ b/src/rollback_interface.cpp @@ -34,7 +34,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "mapblock.h" -RollbackNode::RollbackNode(Map *map, v3POS p, IGameDef *gamedef) +RollbackNode::RollbackNode(Map *map, v3pos_t p, IGameDef *gamedef) { const NodeDefManager *ndef = gamedef->ndef(); MapNode n = map->getNode(p); @@ -101,7 +101,7 @@ bool RollbackAction::isImportant(IGameDef *gamedef) const } -bool RollbackAction::getPosition(v3POS *dst) const +bool RollbackAction::getPosition(v3pos_t *dst) const { switch (type) { case TYPE_SET_NODE: diff --git a/src/rollback_interface.h b/src/rollback_interface.h index e8c6134778..39f7ee29fe 100644 --- a/src/rollback_interface.h +++ b/src/rollback_interface.h @@ -47,7 +47,7 @@ struct RollbackNode RollbackNode() = default; - RollbackNode(Map *map, v3POS p, IGameDef *gamedef); + RollbackNode(Map *map, v3pos_t p, IGameDef *gamedef); }; @@ -63,7 +63,7 @@ struct RollbackAction std::string actor; bool actor_is_guess = false; - v3POS p; + v3pos_t p; RollbackNode n_old; RollbackNode n_new; @@ -75,7 +75,7 @@ struct RollbackAction RollbackAction() = default; - void setSetNode(v3POS p_, const RollbackNode &n_old_, + void setSetNode(v3pos_t p_, const RollbackNode &n_old_, const RollbackNode &n_new_) { type = TYPE_SET_NODE; @@ -102,7 +102,7 @@ struct RollbackAction // Eg. flowing water level changes are not important bool isImportant(IGameDef *gamedef) const; - bool getPosition(v3POS *dst) const; + bool getPosition(v3pos_t *dst) const; bool applyRevert(Map *map, InventoryManager *imgr, IGameDef *gamedef) const; }; @@ -115,14 +115,14 @@ class IRollbackManager virtual std::string getActor() = 0; virtual bool isActorGuess() = 0; virtual void setActor(const std::string &actor, bool is_guess) = 0; - virtual std::string getSuspect(v3POS p, float nearness_shortcut, + virtual std::string getSuspect(v3pos_t p, float nearness_shortcut, float min_nearness) = 0; virtual ~IRollbackManager() = default;; virtual void flush() = 0; // Get all actors that did something to position p, but not further than // in history - virtual std::list getNodeActors(v3POS pos, int range, + virtual std::list getNodeActors(v3pos_t pos, int range, time_t seconds, int limit) = 0; // Get actions to revert of history made by virtual std::list getRevertActions(const std::string &actor, diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp index 015279efc8..374d7225c6 100644 --- a/src/script/common/c_content.cpp +++ b/src/script/common/c_content.cpp @@ -1861,9 +1861,9 @@ void push_pointed_thing(lua_State *L, const PointedThing &pointed, bool csm, if (pointed.type == POINTEDTHING_NODE) { lua_pushstring(L, "node"); lua_setfield(L, -2, "type"); - push_v3POS(L, pointed.node_undersurface); + push_v3pos_t(L, pointed.node_undersurface); lua_setfield(L, -2, "under"); - push_v3POS(L, pointed.node_abovesurface); + push_v3pos_t(L, pointed.node_abovesurface); lua_setfield(L, -2, "above"); } else if (pointed.type == POINTEDTHING_OBJECT) { lua_pushstring(L, "object"); @@ -1883,7 +1883,7 @@ void push_pointed_thing(lua_State *L, const PointedThing &pointed, bool csm, if (hitpoint && (pointed.type != POINTEDTHING_NOTHING)) { push_v3f(L, pointed.intersection_point / BS); // convert to node coords lua_setfield(L, -2, "intersection_point"); - push_v3POS(L, pointed.intersection_normal); + push_v3pos_t(L, pointed.intersection_normal); lua_setfield(L, -2, "intersection_normal"); lua_pushinteger(L, pointed.box_id + 1); // change to Lua array index lua_setfield(L, -2, "box_id"); @@ -2123,7 +2123,7 @@ void push_collision_move_result(lua_State *L, const collisionMoveResult &res) lua_setfield(L, -2, "axis"); if (c.type == COLLISION_NODE) { - push_v3POS(L, c.node_p); + push_v3pos_t(L, c.node_p); lua_setfield(L, -2, "node_pos"); } else if (c.type == COLLISION_OBJECT) { push_objectRef(L, c.object->getId()); diff --git a/src/script/common/c_converter.cpp b/src/script/common/c_converter.cpp index 3337074b7c..c1c3915255 100644 --- a/src/script/common/c_converter.cpp +++ b/src/script/common/c_converter.cpp @@ -324,7 +324,7 @@ v3s16 read_v3s16(lua_State *L, int index) return doubleToInt(pf, 1.0); } -v3POS read_v3POS(lua_State *L, int index) +v3pos_t read_v3pos_t(lua_State *L, int index) { // Correct rounding at <0 v3d pf = read_v3d(L, index); @@ -338,7 +338,7 @@ v3s16 check_v3s16(lua_State *L, int index) return doubleToInt(pf, 1.0); } -v3POS check_v3POS(lua_State *L, int index) +v3pos_t check_v3pos_t(lua_State *L, int index) { // Correct rounding at <0 v3d pf = check_v3d(L, index); @@ -643,8 +643,8 @@ v3s16 getv3s16field_default(lua_State *L, int table, return default_; } -v3POS getv3POSfield_default(lua_State *L, int table, - const char *fieldname, v3POS default_) +v3pos_t getv3pos_tfield_default(lua_State *L, int table, + const char *fieldname, v3pos_t default_) { getv3intfield(L, table, fieldname, default_); return default_; diff --git a/src/script/common/c_converter.h b/src/script/common/c_converter.h index c4b82bd2d3..1f090547eb 100644 --- a/src/script/common/c_converter.h +++ b/src/script/common/c_converter.h @@ -78,8 +78,8 @@ bool getv3intfield(lua_State *L, int index, v3s16 getv3s16field_default(lua_State *L, int table, const char *fieldname, v3s16 default_); -v3POS getv3POSfield_default(lua_State *L, int table, - const char *fieldname, v3POS default_); +v3pos_t getv3pos_tfield_default(lua_State *L, int table, + const char *fieldname, v3pos_t default_); bool getstringfield(lua_State *L, int table, const char *fieldname, std::string &result); size_t getstringlistfield(lua_State *L, int table, @@ -104,13 +104,13 @@ void setboolfield(lua_State *L, int table, v3f checkFloatPos (lua_State *L, int index); v3f check_v3f (lua_State *L, int index); v3s16 check_v3s16 (lua_State *L, int index); -v3POS check_v3POS (lua_State *L, int index); +v3pos_t check_v3pos_t (lua_State *L, int index); v3f read_v3f (lua_State *L, int index); v2f read_v2f (lua_State *L, int index); v2s16 read_v2s16 (lua_State *L, int index); v2s32 read_v2s32 (lua_State *L, int index); -inline v2POS read_v2POS (lua_State *L, int index) { +inline v2pos_t read_v2pos_t (lua_State *L, int index) { #if USE_POS32 return read_v2s32(L, index); #else @@ -126,7 +126,7 @@ bool is_color_table (lua_State *L, int index); aabb3f read_aabb3f (lua_State *L, int index, f32 scale); v3s16 read_v3s16 (lua_State *L, int index); v3s32 read_v3s32 (lua_State *L, int index); -v3POS read_v3POS (lua_State *L, int index); +v3pos_t read_v3pos_t (lua_State *L, int index); std::vector read_aabb3f_vector (lua_State *L, int index, f32 scale); size_t read_stringlist (lua_State *L, int index, @@ -137,7 +137,7 @@ void push_v3_float_string(lua_State *L, v3f p); void push_v2_float_string(lua_State *L, v2f p); void push_v2s16 (lua_State *L, v2s16 p); void push_v2s32 (lua_State *L, v2s32 p); -inline void push_v2POS (lua_State *L, v2POS p) { +inline void push_v2pos_t (lua_State *L, v2pos_t p) { #if USE_POS32 return push_v2s32(L, p); #else @@ -147,7 +147,7 @@ inline void push_v2POS (lua_State *L, v2POS p) { void push_v3s16 (lua_State *L, v3s16 p); void push_v3s32 (lua_State *L, v3s32 p); -inline void push_v3POS (lua_State *L, v3POS p) { +inline void push_v3pos_t (lua_State *L, v3pos_t p) { #if USE_POS32 return push_v3s32(L, p); #else diff --git a/src/script/cpp_api/s_client.cpp b/src/script/cpp_api/s_client.cpp index 327aafbab4..b50a459d26 100644 --- a/src/script/cpp_api/s_client.cpp +++ b/src/script/cpp_api/s_client.cpp @@ -182,7 +182,7 @@ void ScriptApiClient::on_formspec_input(const std::string &formname, } } -bool ScriptApiClient::on_dignode(v3POS p, MapNode node) +bool ScriptApiClient::on_dignode(v3pos_t p, MapNode node) { SCRIPTAPI_PRECHECKHEADER @@ -193,7 +193,7 @@ bool ScriptApiClient::on_dignode(v3POS p, MapNode node) lua_getfield(L, -1, "registered_on_dignode"); // Push data - push_v3POS(L, p); + push_v3pos_t(L, p); pushnode(L, node, ndef); // Call functions @@ -206,7 +206,7 @@ bool ScriptApiClient::on_dignode(v3POS p, MapNode node) return lua_toboolean(L, -1); } -bool ScriptApiClient::on_punchnode(v3POS p, MapNode node) +bool ScriptApiClient::on_punchnode(v3pos_t p, MapNode node) { SCRIPTAPI_PRECHECKHEADER @@ -217,7 +217,7 @@ bool ScriptApiClient::on_punchnode(v3POS p, MapNode node) lua_getfield(L, -1, "registered_on_punchnode"); // Push data - push_v3POS(L, p); + push_v3pos_t(L, p); pushnode(L, node, ndef); // Call functions diff --git a/src/script/cpp_api/s_client.h b/src/script/cpp_api/s_client.h index edc240271f..4c5e34eeee 100644 --- a/src/script/cpp_api/s_client.h +++ b/src/script/cpp_api/s_client.h @@ -53,8 +53,8 @@ class ScriptApiClient : virtual public ScriptApiBase void environment_step(float dtime); void on_formspec_input(const std::string &formname, const StringMap &fields); - bool on_dignode(v3POS p, MapNode node); - bool on_punchnode(v3POS p, MapNode node); + bool on_dignode(v3pos_t p, MapNode node); + bool on_punchnode(v3pos_t p, MapNode node); bool on_placenode(const PointedThing &pointed, const ItemDefinition &item); bool on_item_use(const ItemStack &item, const PointedThing &pointed); diff --git a/src/script/cpp_api/s_env.cpp b/src/script/cpp_api/s_env.cpp index 5631cdd0a0..d909a187d4 100644 --- a/src/script/cpp_api/s_env.cpp +++ b/src/script/cpp_api/s_env.cpp @@ -28,7 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "script/common/c_content.h" -void ScriptApiEnv::environment_OnGenerated(v3POS minp, v3POS maxp, +void ScriptApiEnv::environment_OnGenerated(v3pos_t minp, v3pos_t maxp, u32 blockseed) { SCRIPTAPI_PRECHECKHEADER @@ -37,8 +37,8 @@ void ScriptApiEnv::environment_OnGenerated(v3POS minp, v3POS maxp, lua_getglobal(L, "core"); lua_getfield(L, -1, "registered_on_generateds"); // Call callbacks - push_v3POS(L, minp); - push_v3POS(L, maxp); + push_v3pos_t(L, minp); + push_v3pos_t(L, maxp); lua_pushnumber(L, blockseed); runCallbacks(3, RUN_CALLBACKS_MODE_FIRST); } @@ -141,10 +141,10 @@ void ScriptApiEnv::initializeEnvironment(ServerEnvironment *env) bool simple_catch_up = true; getboolfield(L, current_abm, "catch_up", simple_catch_up); - POS min_y = INT16_MIN; + pos_t min_y = INT16_MIN; getintfield(L, current_abm, "min_y", min_y); - POS max_y = INT16_MAX; + pos_t max_y = INT16_MAX; getintfield(L, current_abm, "max_y", max_y); lua_getfield(L, current_abm, "action"); @@ -216,7 +216,7 @@ void ScriptApiEnv::initializeEnvironment(ServerEnvironment *env) } void ScriptApiEnv::on_emerge_area_completion( - v3POS blockpos, int action, ScriptCallbackState *state) + v3pos_t blockpos, int action, ScriptCallbackState *state) { Server *server = getServer(); @@ -235,7 +235,7 @@ void ScriptApiEnv::on_emerge_area_completion( lua_rawgeti(L, LUA_REGISTRYINDEX, state->callback_ref); luaL_checktype(L, -1, LUA_TFUNCTION); - push_v3POS(L, blockpos); + push_v3pos_t(L, blockpos); lua_pushinteger(L, action); lua_pushinteger(L, state->refcount); lua_rawgeti(L, LUA_REGISTRYINDEX, state->args_ref); @@ -258,7 +258,7 @@ void ScriptApiEnv::on_emerge_area_completion( } void ScriptApiEnv::on_liquid_transformed( - const std::vector> &list) + const std::vector> &list) { SCRIPTAPI_PRECHECKHEADER @@ -277,9 +277,9 @@ void ScriptApiEnv::on_liquid_transformed( const NodeDefManager *ndef = getEnv()->getGameDef()->ndef(); lua_createtable(L, list.size(), 0); lua_createtable(L, list.size(), 0); - for(std::pair p : list) { + for(std::pair p : list) { lua_pushnumber(L, index); - push_v3POS(L, p.first); + push_v3pos_t(L, p.first); lua_rawset(L, -4); lua_pushnumber(L, index++); pushnode(L, p.second, ndef); diff --git a/src/script/cpp_api/s_env.h b/src/script/cpp_api/s_env.h index 620ea6a698..6b53998f62 100644 --- a/src/script/cpp_api/s_env.h +++ b/src/script/cpp_api/s_env.h @@ -34,17 +34,17 @@ class ScriptApiEnv : virtual public ScriptApiBase void environment_Step(float dtime); // Called after generating a piece of map - void environment_OnGenerated(v3POS minp, v3POS maxp, u32 blockseed); + void environment_OnGenerated(v3pos_t minp, v3pos_t maxp, u32 blockseed); // Called on player event void player_event(ServerActiveObject *player, const std::string &type); // Called after emerge of a block queued from core.emerge_area() - void on_emerge_area_completion(v3POS blockpos, int action, + void on_emerge_area_completion(v3pos_t blockpos, int action, ScriptCallbackState *state); // Called after liquid transform changes - void on_liquid_transformed(const std::vector> &list); + void on_liquid_transformed(const std::vector> &list); void initializeEnvironment(ServerEnvironment *env); }; diff --git a/src/script/cpp_api/s_item.cpp b/src/script/cpp_api/s_item.cpp index 26e34f3986..018c209c31 100644 --- a/src/script/cpp_api/s_item.cpp +++ b/src/script/cpp_api/s_item.cpp @@ -223,7 +223,7 @@ bool ScriptApiItem::item_CraftPredict(ItemStack &item, ServerActiveObject *user, // If core.registered_items[name] doesn't exist, core.nodedef_default // is tried instead so unknown items can still be manipulated to some degree bool ScriptApiItem::getItemCallback(const char *name, const char *callbackname, - const v3POS *p) + const v3pos_t *p) { lua_State* L = getStack(); diff --git a/src/script/cpp_api/s_item.h b/src/script/cpp_api/s_item.h index e929dce5bb..576cc535e7 100644 --- a/src/script/cpp_api/s_item.h +++ b/src/script/cpp_api/s_item.h @@ -60,7 +60,7 @@ class ScriptApiItem friend class LuaItemStack; friend class ModApiItemMod; - bool getItemCallback(const char *name, const char *callbackname, const v3POS *p = nullptr); + bool getItemCallback(const char *name, const char *callbackname, const v3pos_t *p = nullptr); /*! * Pushes a `pointed_thing` tabe to the stack. * \param hitpoint If true, the exact pointing location is also pushed diff --git a/src/script/cpp_api/s_node.cpp b/src/script/cpp_api/s_node.cpp index a16caba999..c0881d2e6a 100644 --- a/src/script/cpp_api/s_node.cpp +++ b/src/script/cpp_api/s_node.cpp @@ -102,7 +102,7 @@ struct EnumString ScriptApiNode::es_TextureAlphaMode[] = {0, NULL}, }; -bool ScriptApiNode::node_on_punch(v3POS p, MapNode node, +bool ScriptApiNode::node_on_punch(v3pos_t p, MapNode node, ServerActiveObject *puncher, const PointedThing &pointed) { SCRIPTAPI_PRECHECKHEADER @@ -116,7 +116,7 @@ bool ScriptApiNode::node_on_punch(v3POS p, MapNode node, return false; // Call function - push_v3POS(L, p); + push_v3pos_t(L, p); pushnode(L, node, ndef); objectrefGetOrCreate(L, puncher); pushPointedThing(pointed); @@ -125,7 +125,7 @@ bool ScriptApiNode::node_on_punch(v3POS p, MapNode node, return true; } -bool ScriptApiNode::node_on_dig(v3POS p, MapNode node, +bool ScriptApiNode::node_on_dig(v3pos_t p, MapNode node, ServerActiveObject *digger) { SCRIPTAPI_PRECHECKHEADER @@ -139,7 +139,7 @@ bool ScriptApiNode::node_on_dig(v3POS p, MapNode node, return false; // Call function - push_v3POS(L, p); + push_v3pos_t(L, p); pushnode(L, node, ndef); objectrefGetOrCreate(L, digger); PCALL_RES(lua_pcall(L, 3, 1, error_handler)); @@ -152,7 +152,7 @@ bool ScriptApiNode::node_on_dig(v3POS p, MapNode node, return result; } -void ScriptApiNode::node_on_construct(v3POS p, MapNode node) +void ScriptApiNode::node_on_construct(v3pos_t p, MapNode node) { SCRIPTAPI_PRECHECKHEADER @@ -165,12 +165,12 @@ void ScriptApiNode::node_on_construct(v3POS p, MapNode node) return; // Call function - push_v3POS(L, p); + push_v3pos_t(L, p); PCALL_RES(lua_pcall(L, 1, 0, error_handler)); lua_pop(L, 1); // Pop error handler } -void ScriptApiNode::node_on_destruct(v3POS p, MapNode node) +void ScriptApiNode::node_on_destruct(v3pos_t p, MapNode node) { SCRIPTAPI_PRECHECKHEADER @@ -183,12 +183,12 @@ void ScriptApiNode::node_on_destruct(v3POS p, MapNode node) return; // Call function - push_v3POS(L, p); + push_v3pos_t(L, p); PCALL_RES(lua_pcall(L, 1, 0, error_handler)); lua_pop(L, 1); // Pop error handler } -bool ScriptApiNode::node_on_flood(v3POS p, MapNode node, MapNode newnode) +bool ScriptApiNode::node_on_flood(v3pos_t p, MapNode node, MapNode newnode) { SCRIPTAPI_PRECHECKHEADER @@ -201,7 +201,7 @@ bool ScriptApiNode::node_on_flood(v3POS p, MapNode node, MapNode newnode) return false; // Call function - push_v3POS(L, p); + push_v3pos_t(L, p); pushnode(L, node, ndef); pushnode(L, newnode, ndef); PCALL_RES(lua_pcall(L, 3, 1, error_handler)); @@ -209,7 +209,7 @@ bool ScriptApiNode::node_on_flood(v3POS p, MapNode node, MapNode newnode) return readParam(L, -1, false); } -void ScriptApiNode::node_after_destruct(v3POS p, MapNode node) +void ScriptApiNode::node_after_destruct(v3pos_t p, MapNode node) { SCRIPTAPI_PRECHECKHEADER @@ -222,13 +222,13 @@ void ScriptApiNode::node_after_destruct(v3POS p, MapNode node) return; // Call function - push_v3POS(L, p); + push_v3pos_t(L, p); pushnode(L, node, ndef); PCALL_RES(lua_pcall(L, 2, 0, error_handler)); lua_pop(L, 1); // Pop error handler } -bool ScriptApiNode::node_on_timer(v3POS p, MapNode node, f32 dtime) +bool ScriptApiNode::node_on_timer(v3pos_t p, MapNode node, f32 dtime) { SCRIPTAPI_PRECHECKHEADER @@ -241,14 +241,14 @@ bool ScriptApiNode::node_on_timer(v3POS p, MapNode node, f32 dtime) return false; // Call function - push_v3POS(L, p); + push_v3pos_t(L, p); lua_pushnumber(L,dtime); PCALL_RES(lua_pcall(L, 2, 1, error_handler)); lua_remove(L, error_handler); return readParam(L, -1, false); } -void ScriptApiNode::node_on_receive_fields(v3POS p, +void ScriptApiNode::node_on_receive_fields(v3pos_t p, const std::string &formname, const StringMap &fields, ServerActiveObject *sender) @@ -269,7 +269,7 @@ void ScriptApiNode::node_on_receive_fields(v3POS p, return; // Call function - push_v3POS(L, p); // pos + push_v3pos_t(L, p); // pos lua_pushstring(L, formname.c_str()); // formname lua_newtable(L); // fields StringMap::const_iterator it; diff --git a/src/script/cpp_api/s_node.h b/src/script/cpp_api/s_node.h index 73ac39263c..0494a9f277 100644 --- a/src/script/cpp_api/s_node.h +++ b/src/script/cpp_api/s_node.h @@ -35,16 +35,16 @@ class ScriptApiNode ScriptApiNode() = default; virtual ~ScriptApiNode() = default; - bool node_on_punch(v3POS p, MapNode node, + bool node_on_punch(v3pos_t p, MapNode node, ServerActiveObject *puncher, const PointedThing &pointed); - bool node_on_dig(v3POS p, MapNode node, + bool node_on_dig(v3pos_t p, MapNode node, ServerActiveObject *digger); - void node_on_construct(v3POS p, MapNode node); - void node_on_destruct(v3POS p, MapNode node); - bool node_on_flood(v3POS p, MapNode node, MapNode newnode); - void node_after_destruct(v3POS p, MapNode node); - bool node_on_timer(v3POS p, MapNode node, f32 dtime); - void node_on_receive_fields(v3POS p, + void node_on_construct(v3pos_t p, MapNode node); + void node_on_destruct(v3pos_t p, MapNode node); + bool node_on_flood(v3pos_t p, MapNode node, MapNode newnode); + void node_after_destruct(v3pos_t p, MapNode node); + bool node_on_timer(v3pos_t p, MapNode node, f32 dtime); + void node_on_receive_fields(v3pos_t p, const std::string &formname, const StringMap &fields, ServerActiveObject *sender); diff --git a/src/script/cpp_api/s_nodemeta.cpp b/src/script/cpp_api/s_nodemeta.cpp index 5d06af9701..e5d7ca2391 100644 --- a/src/script/cpp_api/s_nodemeta.cpp +++ b/src/script/cpp_api/s_nodemeta.cpp @@ -48,7 +48,7 @@ int ScriptApiNodemeta::nodemeta_inventory_AllowMove( return count; // function(pos, from_list, from_index, to_list, to_index, count, player) - push_v3POS(L, ma.to_inv.p); // pos + push_v3pos_t(L, ma.to_inv.p); // pos lua_pushstring(L, ma.from_list.c_str()); // from_list lua_pushinteger(L, ma.from_i + 1); // from_index lua_pushstring(L, ma.to_list.c_str()); // to_list @@ -86,7 +86,7 @@ int ScriptApiNodemeta::nodemeta_inventory_AllowPut( return stack.count; // Call function(pos, listname, index, stack, player) - push_v3POS(L, ma.to_inv.p); // pos + push_v3pos_t(L, ma.to_inv.p); // pos lua_pushstring(L, ma.to_list.c_str()); // listname lua_pushinteger(L, ma.to_i + 1); // index LuaItemStack::create(L, stack); // stack @@ -122,7 +122,7 @@ int ScriptApiNodemeta::nodemeta_inventory_AllowTake( return stack.count; // Call function(pos, listname, index, count, player) - push_v3POS(L, ma.from_inv.p); // pos + push_v3pos_t(L, ma.from_inv.p); // pos lua_pushstring(L, ma.from_list.c_str()); // listname lua_pushinteger(L, ma.from_i + 1); // index LuaItemStack::create(L, stack); // stack @@ -158,7 +158,7 @@ void ScriptApiNodemeta::nodemeta_inventory_OnMove( return; // function(pos, from_list, from_index, to_list, to_index, count, player) - push_v3POS(L, ma.from_inv.p); // pos + push_v3pos_t(L, ma.from_inv.p); // pos lua_pushstring(L, ma.from_list.c_str()); // from_list lua_pushinteger(L, ma.from_i + 1); // from_index lua_pushstring(L, ma.to_list.c_str()); // to_list @@ -191,7 +191,7 @@ void ScriptApiNodemeta::nodemeta_inventory_OnPut( return; // Call function(pos, listname, index, stack, player) - push_v3POS(L, ma.to_inv.p); // pos + push_v3pos_t(L, ma.to_inv.p); // pos lua_pushstring(L, ma.to_list.c_str()); // listname lua_pushinteger(L, ma.to_i + 1); // index LuaItemStack::create(L, stack); // stack @@ -222,7 +222,7 @@ void ScriptApiNodemeta::nodemeta_inventory_OnTake( return; // Call function(pos, listname, index, stack, player) - push_v3POS(L, ma.from_inv.p); // pos + push_v3pos_t(L, ma.from_inv.p); // pos lua_pushstring(L, ma.from_list.c_str()); // listname lua_pushinteger(L, ma.from_i + 1); // index LuaItemStack::create(L, stack); // stack diff --git a/src/script/lua_api/l_areastore.cpp b/src/script/lua_api/l_areastore.cpp index ddb023e775..d5264f61cc 100644 --- a/src/script/lua_api/l_areastore.cpp +++ b/src/script/lua_api/l_areastore.cpp @@ -47,9 +47,9 @@ static void push_area(lua_State *L, const Area *a, } lua_newtable(L); if (include_borders) { - push_v3POS(L, a->minedge); + push_v3pos_t(L, a->minedge); lua_setfield(L, -2, "min"); - push_v3POS(L, a->maxedge); + push_v3pos_t(L, a->maxedge); lua_setfield(L, -2, "max"); } if (include_data) { @@ -127,7 +127,7 @@ int LuaAreaStore::l_get_areas_for_pos(lua_State *L) LuaAreaStore *o = checkobject(L, 1); AreaStore *ast = o->as; - v3POS pos = check_v3POS(L, 2); + v3pos_t pos = check_v3pos_t(L, 2); bool include_borders = true; bool include_data = false; @@ -149,8 +149,8 @@ int LuaAreaStore::l_get_areas_in_area(lua_State *L) LuaAreaStore *o = checkobject(L, 1); AreaStore *ast = o->as; - v3POS minedge = check_v3POS(L, 2); - v3POS maxedge = check_v3POS(L, 3); + v3pos_t minedge = check_v3pos_t(L, 2); + v3pos_t maxedge = check_v3pos_t(L, 3); bool include_borders = true; bool include_data = false; @@ -175,7 +175,7 @@ int LuaAreaStore::l_insert_area(lua_State *L) LuaAreaStore *o = checkobject(L, 1); AreaStore *ast = o->as; - Area a(check_v3POS(L, 2), check_v3POS(L, 3)); + Area a(check_v3pos_t(L, 2), check_v3pos_t(L, 3)); size_t d_len; const char *data = luaL_checklstring(L, 4, &d_len); diff --git a/src/script/lua_api/l_client.cpp b/src/script/lua_api/l_client.cpp index eb828f5136..12f690f581 100644 --- a/src/script/lua_api/l_client.cpp +++ b/src/script/lua_api/l_client.cpp @@ -213,7 +213,7 @@ int ModApiClient::l_gettext(lua_State *L) int ModApiClient::l_get_node_or_nil(lua_State *L) { // pos - v3POS pos = read_v3POS(L, 1); + v3pos_t pos = read_v3pos_t(L, 1); // Do it bool pos_ok; @@ -247,7 +247,7 @@ int ModApiClient::l_get_language(lua_State *L) // get_meta(pos) int ModApiClient::l_get_meta(lua_State *L) { - v3POS p = read_v3POS(L, 1); + v3pos_t p = read_v3pos_t(L, 1); // check restrictions first bool pos_ok; diff --git a/src/script/lua_api/l_env.cpp b/src/script/lua_api/l_env.cpp index fd80219867..c775575515 100644 --- a/src/script/lua_api/l_env.cpp +++ b/src/script/lua_api/l_env.cpp @@ -65,7 +65,7 @@ const EnumString ModApiEnvMod::es_BlockStatusType[] = /////////////////////////////////////////////////////////////////////////////// -void LuaABM::trigger(ServerEnvironment *env, v3POS p, MapNode n, +void LuaABM::trigger(ServerEnvironment *env, v3pos_t p, MapNode n, u32 active_object_count, u32 active_object_count_wider) { ServerScripting *scriptIface = env->getScriptIface(); @@ -97,7 +97,7 @@ void LuaABM::trigger(ServerEnvironment *env, v3POS p, MapNode n, lua_getfield(L, -1, "action"); luaL_checktype(L, -1, LUA_TFUNCTION); lua_remove(L, -2); // Remove registered_abms[m_id] - push_v3POS(L, p); + push_v3pos_t(L, p); pushnode(L, n, env->getGameDef()->ndef()); lua_pushnumber(L, active_object_count); lua_pushnumber(L, active_object_count_wider); @@ -109,7 +109,7 @@ void LuaABM::trigger(ServerEnvironment *env, v3POS p, MapNode n, lua_pop(L, 1); // Pop error handler } -void LuaLBM::trigger(ServerEnvironment *env, v3POS p, MapNode n) +void LuaLBM::trigger(ServerEnvironment *env, v3pos_t p, MapNode n) { ServerScripting *scriptIface = env->getScriptIface(); scriptIface->realityCheck(); @@ -139,7 +139,7 @@ void LuaLBM::trigger(ServerEnvironment *env, v3POS p, MapNode n) lua_getfield(L, -1, "action"); luaL_checktype(L, -1, LUA_TFUNCTION); lua_remove(L, -2); // Remove registered_lbms[m_id] - push_v3POS(L, p); + push_v3pos_t(L, p); pushnode(L, n, env->getGameDef()->ndef()); int result = lua_pcall(L, 2, 0, error_handler); @@ -250,7 +250,7 @@ const luaL_Reg LuaRaycast::methods[] = { 0, 0 } }; -void LuaEmergeAreaCallback(v3POS blockpos, EmergeAction action, void *param) +void LuaEmergeAreaCallback(v3pos_t blockpos, EmergeAction action, void *param) { ScriptCallbackState *state = (ScriptCallbackState *)param; assert(state != NULL); @@ -279,7 +279,7 @@ int ModApiEnvMod::l_set_node(lua_State *L) const NodeDefManager *ndef = env->getGameDef()->ndef(); // parameters - v3POS pos = read_v3POS(L, 1); + v3pos_t pos = read_v3pos_t(L, 1); MapNode n = readnode(L, 2, ndef); // Do it bool succeeded = env->setNode(pos, n); @@ -311,7 +311,7 @@ int ModApiEnvMod::l_bulk_set_node(lua_State *L) bool succeeded = true; for (s32 i = 1; i <= len; i++) { lua_rawgeti(L, 1, i); - if (!env->setNode(read_v3POS(L, -1), n)) + if (!env->setNode(read_v3pos_t(L, -1), n)) succeeded = false; lua_pop(L, 1); } @@ -332,7 +332,7 @@ int ModApiEnvMod::l_remove_node(lua_State *L) GET_ENV_PTR; // parameters - v3POS pos = read_v3POS(L, 1); + v3pos_t pos = read_v3pos_t(L, 1); // Do it bool succeeded = env->removeNode(pos); lua_pushboolean(L, succeeded); @@ -347,7 +347,7 @@ int ModApiEnvMod::l_swap_node(lua_State *L) const NodeDefManager *ndef = env->getGameDef()->ndef(); // parameters - v3POS pos = read_v3POS(L, 1); + v3pos_t pos = read_v3pos_t(L, 1); MapNode n = readnode(L, 2, ndef); // Do it bool succeeded = env->swapNode(pos, n); @@ -362,7 +362,7 @@ int ModApiEnvMod::l_get_node(lua_State *L) GET_ENV_PTR; // pos - v3POS pos = read_v3POS(L, 1); + v3pos_t pos = read_v3pos_t(L, 1); // Do it MapNode n = env->getMap().getNode(pos); // Return node @@ -377,7 +377,7 @@ int ModApiEnvMod::l_get_node_or_nil(lua_State *L) GET_ENV_PTR; // pos - v3POS pos = read_v3POS(L, 1); + v3pos_t pos = read_v3pos_t(L, 1); // Do it bool pos_ok; MapNode n = env->getMap().getNode(pos, &pos_ok); @@ -398,7 +398,7 @@ int ModApiEnvMod::l_get_node_light(lua_State *L) GET_PLAIN_ENV_PTR; // Do it - v3POS pos = read_v3POS(L, 1); + v3pos_t pos = read_v3pos_t(L, 1); u32 time_of_day = env->getTimeOfDay(); if(lua_isnumber(L, 2)) time_of_day = 24000.0 * lua_tonumber(L, 2); @@ -424,7 +424,7 @@ int ModApiEnvMod::l_get_natural_light(lua_State *L) { GET_ENV_PTR; - v3POS pos = read_v3POS(L, 1); + v3pos_t pos = read_v3pos_t(L, 1); bool is_position_ok; MapNode n = env->getMap().getNode(pos, &is_position_ok); @@ -467,7 +467,7 @@ int ModApiEnvMod::l_place_node(lua_State *L) const NodeDefManager *ndef = server->ndef(); IItemDefManager *idef = server->idef(); - v3POS pos = read_v3POS(L, 1); + v3pos_t pos = read_v3pos_t(L, 1); MapNode n = readnode(L, 2, ndef); // Don't attempt to load non-loaded area as of now @@ -482,7 +482,7 @@ int ModApiEnvMod::l_place_node(lua_State *L) PointedThing pointed; pointed.type = POINTEDTHING_NODE; pointed.node_abovesurface = pos; - pointed.node_undersurface = pos + v3POS(0,-1,0); + pointed.node_undersurface = pos + v3pos_t(0,-1,0); // Place it with a NULL placer (appears in Lua as nil) bool success = scriptIfaceItem->item_OnPlace(item, nullptr, pointed); lua_pushboolean(L, success); @@ -497,7 +497,7 @@ int ModApiEnvMod::l_dig_node(lua_State *L) ScriptApiNode *scriptIfaceNode = getScriptApi(L); - v3POS pos = read_v3POS(L, 1); + v3pos_t pos = read_v3pos_t(L, 1); // Don't attempt to load non-loaded area as of now MapNode n = env->getMap().getNode(pos); @@ -520,7 +520,7 @@ int ModApiEnvMod::l_punch_node(lua_State *L) ScriptApiNode *scriptIfaceNode = getScriptApi(L); - v3POS pos = read_v3POS(L, 1); + v3pos_t pos = read_v3pos_t(L, 1); // Don't attempt to load non-loaded area as of now MapNode n = env->getMap().getNode(pos); @@ -541,7 +541,7 @@ int ModApiEnvMod::l_get_node_max_level(lua_State *L) { GET_PLAIN_ENV_PTR; - v3POS pos = read_v3POS(L, 1); + v3pos_t pos = read_v3pos_t(L, 1); MapNode n = env->getMap().getNode(pos); lua_pushnumber(L, n.getMaxLevel(env->getGameDef()->ndef())); return 1; @@ -553,7 +553,7 @@ int ModApiEnvMod::l_get_node_level(lua_State *L) { GET_PLAIN_ENV_PTR; - v3POS pos = read_v3POS(L, 1); + v3pos_t pos = read_v3pos_t(L, 1); MapNode n = env->getMap().getNode(pos); lua_pushnumber(L, n.getLevel(env->getGameDef()->ndef())); return 1; @@ -566,7 +566,7 @@ int ModApiEnvMod::l_set_node_level(lua_State *L) { GET_ENV_PTR; - v3POS pos = read_v3POS(L, 1); + v3pos_t pos = read_v3pos_t(L, 1); u8 level = 1; if(lua_isnumber(L, 2)) level = lua_tonumber(L, 2); @@ -583,7 +583,7 @@ int ModApiEnvMod::l_add_node_level(lua_State *L) { GET_ENV_PTR; - v3POS pos = read_v3POS(L, 1); + v3pos_t pos = read_v3pos_t(L, 1); s16 level = 1; if(lua_isnumber(L, 2)) level = lua_tonumber(L, 2); @@ -598,12 +598,12 @@ int ModApiEnvMod::l_find_nodes_with_meta(lua_State *L) { GET_PLAIN_ENV_PTR; - std::vector positions = env->getMap().findNodesWithMetadata( - check_v3POS(L, 1), check_v3POS(L, 2)); + std::vector positions = env->getMap().findNodesWithMetadata( + check_v3pos_t(L, 1), check_v3pos_t(L, 2)); lua_createtable(L, positions.size(), 0); for (size_t i = 0; i != positions.size(); i++) { - push_v3POS(L, positions[i]); + push_v3pos_t(L, positions[i]); lua_rawseti(L, -2, i + 1); } @@ -616,7 +616,7 @@ int ModApiEnvMod::l_get_meta(lua_State *L) GET_ENV_PTR; // Do it - v3POS p = read_v3POS(L, 1); + v3pos_t p = read_v3pos_t(L, 1); NodeMetaRef::create(L, p, env); return 1; } @@ -627,7 +627,7 @@ int ModApiEnvMod::l_get_node_timer(lua_State *L) GET_ENV_PTR; // Do it - v3POS p = read_v3POS(L, 1); + v3pos_t p = read_v3pos_t(L, 1); NodeTimerRef::create(L, p, &env->getServerMap()); return 1; } @@ -853,7 +853,7 @@ int ModApiEnvMod::l_find_node_near(lua_State *L) const NodeDefManager *ndef = env->getGameDef()->ndef(); Map &map = env->getMap(); - v3POS pos = read_v3POS(L, 1); + v3pos_t pos = read_v3pos_t(L, 1); int radius = luaL_checkinteger(L, 2); std::vector filter; collectNodeIds(L, 3, ndef, filter); @@ -867,12 +867,12 @@ int ModApiEnvMod::l_find_node_near(lua_State *L) #endif for (int d = start_radius; d <= radius; d++) { - const std::vector &list = FacePositionCache::getFacePositions(d); - for (const v3POS &i : list) { - v3POS p = pos + i; + const std::vector &list = FacePositionCache::getFacePositions(d); + for (const v3pos_t &i : list) { + v3pos_t p = pos + i; content_t c = map.getNode(p).getContent(); if (CONTAINS(filter, c)) { - push_v3POS(L, p); + push_v3pos_t(L, p); return 1; } } @@ -880,7 +880,7 @@ int ModApiEnvMod::l_find_node_near(lua_State *L) return 0; } -static void checkArea(v3POS &minp, v3POS &maxp) +static void checkArea(v3pos_t &minp, v3pos_t &maxp) { auto volume = VoxelArea(minp, maxp).getVolume(); // Volume limit equal to 8 default mapchunks, (80 * 2) ^ 3 = 4,096,000 @@ -889,9 +889,9 @@ static void checkArea(v3POS &minp, v3POS &maxp) } // Clamp to map range to avoid problems -#define CLAMP(arg) core::clamp(arg, (POS)-MAX_MAP_GENERATION_LIMIT, (POS)MAX_MAP_GENERATION_LIMIT) - minp = v3POS(CLAMP(minp.X), CLAMP(minp.Y), CLAMP(minp.Z)); - maxp = v3POS(CLAMP(maxp.X), CLAMP(maxp.Y), CLAMP(maxp.Z)); +#define CLAMP(arg) core::clamp(arg, (pos_t)-MAX_MAP_GENERATION_LIMIT, (pos_t)MAX_MAP_GENERATION_LIMIT) + minp = v3pos_t(CLAMP(minp.X), CLAMP(minp.Y), CLAMP(minp.Z)); + maxp = v3pos_t(CLAMP(maxp.X), CLAMP(maxp.Y), CLAMP(maxp.Z)); #undef CLAMP } @@ -900,8 +900,8 @@ int ModApiEnvMod::l_find_nodes_in_area(lua_State *L) { GET_PLAIN_ENV_PTR; - v3POS minp = read_v3POS(L, 1); - v3POS maxp = read_v3POS(L, 2); + v3pos_t minp = read_v3pos_t(L, 1); + v3pos_t maxp = read_v3pos_t(L, 2); sortBoxVerticies(minp, maxp); const NodeDefManager *ndef = env->getGameDef()->ndef(); @@ -932,7 +932,7 @@ int ModApiEnvMod::l_find_nodes_in_area(lua_State *L) for (u32 i = 0; i < filter.size(); i++) lua_newtable(L); - v3POS p; + v3pos_t p; for (p.X = minp.X; p.X <= maxp.X; p.X++) for (p.Y = minp.Y; p.Y <= maxp.Y; p.Y++) for (p.Z = minp.Z; p.Z <= maxp.Z; p.Z++) { @@ -942,7 +942,7 @@ int ModApiEnvMod::l_find_nodes_in_area(lua_State *L) if (it != filter.end()) { // Calculate index of the table and append the position u32 filt_index = it - filter.begin(); - push_v3POS(L, p); + push_v3pos_t(L, p); lua_rawseti(L, base + 1 + filt_index, ++idx[filt_index]); } } @@ -967,7 +967,7 @@ int ModApiEnvMod::l_find_nodes_in_area(lua_State *L) lua_newtable(L); u32 i = 0; - v3POS p; + v3pos_t p; for (p.X = minp.X; p.X <= maxp.X; p.X++) for (p.Y = minp.Y; p.Y <= maxp.Y; p.Y++) for (p.Z = minp.Z; p.Z <= maxp.Z; p.Z++) { @@ -975,7 +975,7 @@ int ModApiEnvMod::l_find_nodes_in_area(lua_State *L) auto it = std::find(filter.begin(), filter.end(), c); if (it != filter.end()) { - push_v3POS(L, p); + push_v3pos_t(L, p); lua_rawseti(L, -2, ++i); u32 filt_index = it - filter.begin(); @@ -1005,8 +1005,8 @@ int ModApiEnvMod::l_find_nodes_in_area_under_air(lua_State *L) GET_PLAIN_ENV_PTR; - v3POS minp = read_v3POS(L, 1); - v3POS maxp = read_v3POS(L, 2); + v3pos_t minp = read_v3pos_t(L, 1); + v3pos_t maxp = read_v3pos_t(L, 2); sortBoxVerticies(minp, maxp); const NodeDefManager *ndef = env->getGameDef()->ndef(); @@ -1026,17 +1026,17 @@ int ModApiEnvMod::l_find_nodes_in_area_under_air(lua_State *L) lua_newtable(L); u32 i = 0; - v3POS p; + v3pos_t p; for (p.X = minp.X; p.X <= maxp.X; p.X++) for (p.Z = minp.Z; p.Z <= maxp.Z; p.Z++) { p.Y = minp.Y; content_t c = map.getNode(p).getContent(); for (; p.Y <= maxp.Y; p.Y++) { - v3POS psurf(p.X, p.Y + 1, p.Z); + v3pos_t psurf(p.X, p.Y + 1, p.Z); content_t csurf = map.getNode(psurf).getContent(); if (c != CONTENT_AIR && csurf == CONTENT_AIR && CONTAINS(filter, c)) { - push_v3POS(L, p); + push_v3pos_t(L, p); lua_rawseti(L, -2, ++i); } c = csurf; @@ -1080,7 +1080,7 @@ int ModApiEnvMod::l_get_perlin_map(lua_State *L) NoiseParams np; if (!read_noiseparams(L, 1, &np)) return 0; - v3POS size = read_v3POS(L, 2); + v3pos_t size = read_v3pos_t(L, 2); s32 seed = (s32)(env->getServerMap().getSeed()); LuaPerlinNoiseMap *n = new LuaPerlinNoiseMap(&np, seed, size); @@ -1098,7 +1098,7 @@ int ModApiEnvMod::l_get_voxel_manip(lua_State *L) Map *map = &(env->getMap()); LuaVoxelManip *o = (lua_istable(L, 1) && lua_istable(L, 2)) ? - new LuaVoxelManip(map, read_v3POS(L, 1), read_v3POS(L, 2)) : + new LuaVoxelManip(map, read_v3pos_t(L, 1), read_v3pos_t(L, 2)) : new LuaVoxelManip(map); *(void **)(lua_newuserdata(L, sizeof(void *))) = o; @@ -1134,12 +1134,12 @@ int ModApiEnvMod::l_line_of_sight(lua_State *L) // read position 2 from lua v3f pos2 = checkFloatPos(L, 2); - v3POS p; + v3pos_t p; bool success = env->line_of_sight(pos1, pos2, &p); lua_pushboolean(L, success); if (!success) { - push_v3POS(L, p); + push_v3pos_t(L, p); return 2; } return 1; @@ -1150,12 +1150,12 @@ int ModApiEnvMod::l_fix_light(lua_State *L) { GET_ENV_PTR; - v3POS blockpos1 = getContainerPos(read_v3POS(L, 1), MAP_BLOCKSIZE); - v3POS blockpos2 = getContainerPos(read_v3POS(L, 2), MAP_BLOCKSIZE); + v3pos_t blockpos1 = getContainerPos(read_v3pos_t(L, 1), MAP_BLOCKSIZE); + v3pos_t blockpos2 = getContainerPos(read_v3pos_t(L, 2), MAP_BLOCKSIZE); ServerMap &map = env->getServerMap(); - std::map modified_blocks; + std::map modified_blocks; bool success = true; - v3POS blockpos; + v3pos_t blockpos; for (blockpos.X = blockpos1.X; blockpos.X <= blockpos2.X; blockpos.X++) for (blockpos.Y = blockpos1.Y; blockpos.Y <= blockpos2.Y; blockpos.Y++) for (blockpos.Z = blockpos1.Z; blockpos.Z <= blockpos2.Z; blockpos.Z++) { @@ -1187,16 +1187,16 @@ int ModApiEnvMod::l_load_area(lua_State *L) MAP_LOCK_REQUIRED; Map *map = &(env->getMap()); - v3BPOS bp1 = getNodeBlockPos(check_v3POS(L, 1)); + v3bpos_t bp1 = getNodeBlockPos(check_v3pos_t(L, 1)); if (!lua_istable(L, 2)) { map->emergeBlock(bp1); } else { - v3BPOS bp2 = getNodeBlockPos(check_v3POS(L, 2)); + v3bpos_t bp2 = getNodeBlockPos(check_v3pos_t(L, 2)); sortBoxVerticies(bp1, bp2); for (s16 z = bp1.Z; z <= bp2.Z; z++) for (s16 y = bp1.Y; y <= bp2.Y; y++) for (s16 x = bp1.X; x <= bp2.X; x++) { - map->emergeBlock(v3POS(x, y, z)); + map->emergeBlock(v3pos_t(x, y, z)); } } @@ -1214,8 +1214,8 @@ int ModApiEnvMod::l_emerge_area(lua_State *L) EmergeManager *emerge = getServer(L)->getEmergeManager(); - v3BPOS bpmin = getNodeBlockPos(read_v3POS(L, 1)); - v3BPOS bpmax = getNodeBlockPos(read_v3POS(L, 2)); + v3bpos_t bpmin = getNodeBlockPos(read_v3pos_t(L, 1)); + v3bpos_t bpmax = getNodeBlockPos(read_v3pos_t(L, 2)); sortBoxVerticies(bpmin, bpmax); size_t num_blocks = VoxelArea(bpmin, bpmax).getVolume(); @@ -1241,7 +1241,7 @@ int ModApiEnvMod::l_emerge_area(lua_State *L) for (s16 z = bpmin.Z; z <= bpmax.Z; z++) for (s16 y = bpmin.Y; y <= bpmax.Y; y++) for (s16 x = bpmin.X; x <= bpmax.X; x++) { - emerge->enqueueBlockEmergeEx(v3POS(x, y, z), PEER_ID_INEXISTENT, + emerge->enqueueBlockEmergeEx(v3pos_t(x, y, z), PEER_ID_INEXISTENT, BLOCK_EMERGE_ALLOW_GEN | BLOCK_EMERGE_FORCE_QUEUE, callback, state); } @@ -1254,8 +1254,8 @@ int ModApiEnvMod::l_delete_area(lua_State *L) { GET_ENV_PTR; - v3BPOS bpmin = getNodeBlockPos(read_v3POS(L, 1)); - v3BPOS bpmax = getNodeBlockPos(read_v3POS(L, 2)); + v3bpos_t bpmin = getNodeBlockPos(read_v3pos_t(L, 1)); + v3bpos_t bpmax = getNodeBlockPos(read_v3pos_t(L, 2)); sortBoxVerticies(bpmin, bpmax); ServerMap &map = env->getServerMap(); @@ -1264,10 +1264,10 @@ int ModApiEnvMod::l_delete_area(lua_State *L) event.type = MEET_OTHER; bool success = true; - for (BPOS z = bpmin.Z; z <= bpmax.Z; z++) - for (BPOS y = bpmin.Y; y <= bpmax.Y; y++) - for (BPOS x = bpmin.X; x <= bpmax.X; x++) { - v3BPOS bp(x, y, z); + for (bpos_t z = bpmin.Z; z <= bpmax.Z; z++) + for (bpos_t y = bpmin.Y; y <= bpmax.Y; y++) + for (bpos_t x = bpmin.X; x <= bpmax.X; x++) { + v3bpos_t bp(x, y, z); if (map.deleteBlock(bp)) { env->setStaticForActiveObjectsInBlock(bp, false); event.modified_blocks.insert(bp); @@ -1287,8 +1287,8 @@ int ModApiEnvMod::l_find_path(lua_State *L) { GET_ENV_PTR; - v3POS pos1 = read_v3POS(L, 1); - v3POS pos2 = read_v3POS(L, 2); + v3pos_t pos1 = read_v3pos_t(L, 1); + v3pos_t pos2 = read_v3pos_t(L, 2); unsigned int searchdistance = luaL_checkint(L, 3); unsigned int max_jump = luaL_checkint(L, 4); unsigned int max_drop = luaL_checkint(L, 5); @@ -1303,16 +1303,16 @@ int ModApiEnvMod::l_find_path(lua_State *L) algo = PA_DIJKSTRA; } - std::vector path = get_path(&env->getServerMap(), env->getGameDef()->ndef(), pos1, pos2, + std::vector path = get_path(&env->getServerMap(), env->getGameDef()->ndef(), pos1, pos2, searchdistance, max_jump, max_drop, algo); if (!path.empty()) { lua_createtable(L, path.size(), 0); int top = lua_gettop(L); unsigned int index = 1; - for (const v3POS &i : path) { + for (const v3pos_t &i : path) { lua_pushnumber(L,index); - push_v3POS(L, i); + push_v3pos_t(L, i); lua_settable(L, top); index++; } @@ -1327,7 +1327,7 @@ int ModApiEnvMod::l_spawn_tree(lua_State *L) { GET_ENV_PTR; - v3POS p0 = read_v3POS(L, 1); + v3pos_t p0 = read_v3pos_t(L, 1); treegen::TreeDef tree_def; std::string trunk,leaves,fruit; @@ -1385,7 +1385,7 @@ int ModApiEnvMod::l_transforming_liquid_add(lua_State *L) { GET_ENV_PTR; - v3POS p0 = read_v3POS(L, 1); + v3pos_t p0 = read_v3pos_t(L, 1); env->getMap().transforming_liquid_add(p0); return 1; } @@ -1396,7 +1396,7 @@ int ModApiEnvMod::l_forceload_block(lua_State *L) { GET_ENV_PTR; - v3POS blockpos = read_v3POS(L, 1); + v3pos_t blockpos = read_v3pos_t(L, 1); env->getForceloadedBlocks()->insert(blockpos); return 0; } @@ -1406,7 +1406,7 @@ int ModApiEnvMod::l_compare_block_status(lua_State *L) { GET_ENV_PTR; - v3POS nodepos = check_v3POS(L, 1); + v3pos_t nodepos = check_v3pos_t(L, 1); std::string condition_s = luaL_checkstring(L, 2); auto status = env->getBlockStatus(getNodeBlockPos(nodepos)); @@ -1425,7 +1425,7 @@ int ModApiEnvMod::l_forceload_free_block(lua_State *L) { GET_ENV_PTR; - v3POS blockpos = read_v3POS(L, 1); + v3pos_t blockpos = read_v3pos_t(L, 1); env->getForceloadedBlocks()->erase(blockpos); return 0; } diff --git a/src/script/lua_api/l_env.h b/src/script/lua_api/l_env.h index 96780604f2..2e6fa3719d 100644 --- a/src/script/lua_api/l_env.h +++ b/src/script/lua_api/l_env.h @@ -223,13 +223,13 @@ class LuaABM : public ActiveBlockModifier { float m_trigger_interval; u32 m_trigger_chance; bool m_simple_catch_up; - POS m_min_y; - POS m_max_y; + pos_t m_min_y; + pos_t m_max_y; public: LuaABM(lua_State *L, int id, const std::vector &trigger_contents, const std::vector &required_neighbors, - float trigger_interval, u32 trigger_chance, bool simple_catch_up, POS min_y, POS max_y): + float trigger_interval, u32 trigger_chance, bool simple_catch_up, pos_t min_y, pos_t max_y): m_id(id), m_trigger_contents(trigger_contents), m_required_neighbors(required_neighbors), @@ -260,15 +260,15 @@ class LuaABM : public ActiveBlockModifier { { return m_simple_catch_up; } - virtual POS getMinY() + virtual pos_t getMinY() { return m_min_y; } - virtual POS getMaxY() + virtual pos_t getMaxY() { return m_max_y; } - virtual void trigger(ServerEnvironment *env, v3POS p, MapNode n, + virtual void trigger(ServerEnvironment *env, v3pos_t p, MapNode n, u32 active_object_count, u32 active_object_count_wider); }; @@ -287,7 +287,7 @@ class LuaLBM : public LoadingBlockModifierDef this->trigger_contents = trigger_contents; this->name = name; } - virtual void trigger(ServerEnvironment *env, v3POS p, MapNode n); + virtual void trigger(ServerEnvironment *env, v3pos_t p, MapNode n); }; //! Lua wrapper for RaycastState objects diff --git a/src/script/lua_api/l_inventory.cpp b/src/script/lua_api/l_inventory.cpp index 82bfb7d5ed..d2e0bf9af7 100644 --- a/src/script/lua_api/l_inventory.cpp +++ b/src/script/lua_api/l_inventory.cpp @@ -385,7 +385,7 @@ int InvRef::l_get_location(lua_State *L) lua_newtable(L); lua_pushstring(L, "node"); lua_setfield(L, -2, "type"); - push_v3POS(L, loc.p); + push_v3pos_t(L, loc.p); lua_setfield(L, -2, "pos"); return 1; case InventoryLocation::DETACHED: @@ -483,7 +483,7 @@ int ModApiInventory::l_get_inventory(lua_State *L) if(type == "node"){ MAP_LOCK_REQUIRED; lua_getfield(L, 1, "pos"); - v3POS pos = check_v3POS(L, -1); + v3pos_t pos = check_v3pos_t(L, -1); loc.setNodeMeta(pos); if (getServerInventoryMgr(L)->getInventory(loc) != NULL) diff --git a/src/script/lua_api/l_mapgen.cpp b/src/script/lua_api/l_mapgen.cpp index 62672ac7be..89f555faa5 100644 --- a/src/script/lua_api/l_mapgen.cpp +++ b/src/script/lua_api/l_mapgen.cpp @@ -389,11 +389,11 @@ Biome *read_biome_def(lua_State *L, int index, const NodeDefManager *ndef) b->vertical_blend = getintfield_default(L, index, "vertical_blend", 0); b->flags = 0; // reserved - b->min_pos = getv3POSfield_default( - L, index, "min_pos", v3POS(-MAX_MAP_GENERATION_LIMIT, -MAX_MAP_GENERATION_LIMIT, -MAX_MAP_GENERATION_LIMIT)); + b->min_pos = getv3pos_tfield_default( + L, index, "min_pos", v3pos_t(-MAX_MAP_GENERATION_LIMIT, -MAX_MAP_GENERATION_LIMIT, -MAX_MAP_GENERATION_LIMIT)); getintfield(L, index, "y_min", b->min_pos.Y); - b->max_pos = getv3POSfield_default( - L, index, "max_pos", v3POS(MAX_MAP_GENERATION_LIMIT, MAX_MAP_GENERATION_LIMIT, MAX_MAP_GENERATION_LIMIT)); + b->max_pos = getv3pos_tfield_default( + L, index, "max_pos", v3pos_t(MAX_MAP_GENERATION_LIMIT, MAX_MAP_GENERATION_LIMIT, MAX_MAP_GENERATION_LIMIT)); getintfield(L, index, "y_max", b->max_pos.Y); std::vector &nn = b->m_nodenames; @@ -523,7 +523,7 @@ int ModApiMapgen::l_get_heat(lua_State *L) { NO_MAP_LOCK_REQUIRED; - v3POS pos = read_v3POS(L, 1); + v3pos_t pos = read_v3pos_t(L, 1); const BiomeGen *biomegen = getServer(L)->getEmergeManager()->getBiomeGen(); @@ -544,7 +544,7 @@ int ModApiMapgen::l_get_humidity(lua_State *L) { NO_MAP_LOCK_REQUIRED; - v3POS pos = read_v3POS(L, 1); + v3pos_t pos = read_v3pos_t(L, 1); const BiomeGen *biomegen = getServer(L)->getEmergeManager()->getBiomeGen(); @@ -565,7 +565,7 @@ int ModApiMapgen::l_get_biome_data(lua_State *L) { NO_MAP_LOCK_REQUIRED; - v3POS pos = read_v3POS(L, 1); + v3pos_t pos = read_v3pos_t(L, 1); const BiomeGen *biomegen = getServer(L)->getEmergeManager()->getBiomeGen(); if (!biomegen) @@ -627,10 +627,10 @@ int ModApiMapgen::l_get_mapgen_object(lua_State *L) lua_setmetatable(L, -2); // emerged min pos - push_v3POS(L, vm->m_area.MinEdge); + push_v3pos_t(L, vm->m_area.MinEdge); // emerged max pos - push_v3POS(L, vm->m_area.MaxEdge); + push_v3pos_t(L, vm->m_area.MaxEdge); return 3; } @@ -688,7 +688,7 @@ int ModApiMapgen::l_get_mapgen_object(lua_State *L) return 1; } case MGOBJ_GENNOTIFY: { - std::map >event_map; + std::map >event_map; mg->gennotify.getEvents(event_map); @@ -697,7 +697,7 @@ int ModApiMapgen::l_get_mapgen_object(lua_State *L) lua_createtable(L, it->second.size(), 0); for (size_t j = 0; j != it->second.size(); j++) { - push_v3POS(L, it->second[j]); + push_v3pos_t(L, it->second[j]); lua_rawseti(L, -2, j + 1); } @@ -721,7 +721,7 @@ int ModApiMapgen::l_get_spawn_level(lua_State *L) s16 z = luaL_checkinteger(L, 2); EmergeManager *emerge = getServer(L)->getEmergeManager(); - int spawn_level = emerge->getSpawnLevelAtPoint(v2POS(x, z)); + int spawn_level = emerge->getSpawnLevelAtPoint(v2pos_t(x, z)); // Unsuitable spawn point if (spawn_level == MAX_MAP_GENERATION_LIMIT) return 0; @@ -1432,10 +1432,10 @@ int ModApiMapgen::l_generate_ores(lua_State *L) mg.vm = LuaVoxelManip::checkobject(L, 1)->vm; mg.ndef = getServer(L)->getNodeDefManager(); - v3POS pmin = lua_istable(L, 2) ? check_v3POS(L, 2) : - mg.vm->m_area.MinEdge + v3POS(1,1,1) * MAP_BLOCKSIZE; - v3POS pmax = lua_istable(L, 3) ? check_v3POS(L, 3) : - mg.vm->m_area.MaxEdge - v3POS(1,1,1) * MAP_BLOCKSIZE; + v3pos_t pmin = lua_istable(L, 2) ? check_v3pos_t(L, 2) : + mg.vm->m_area.MinEdge + v3pos_t(1,1,1) * MAP_BLOCKSIZE; + v3pos_t pmax = lua_istable(L, 3) ? check_v3pos_t(L, 3) : + mg.vm->m_area.MaxEdge - v3pos_t(1,1,1) * MAP_BLOCKSIZE; sortBoxVerticies(pmin, pmax); u32 blockseed = Mapgen::getBlockSeed(pmin, mg.seed); @@ -1461,10 +1461,10 @@ int ModApiMapgen::l_generate_decorations(lua_State *L) mg.vm = LuaVoxelManip::checkobject(L, 1)->vm; mg.ndef = getServer(L)->getNodeDefManager(); - v3POS pmin = lua_istable(L, 2) ? check_v3POS(L, 2) : - mg.vm->m_area.MinEdge + v3POS(1,1,1) * MAP_BLOCKSIZE; - v3POS pmax = lua_istable(L, 3) ? check_v3POS(L, 3) : - mg.vm->m_area.MaxEdge - v3POS(1,1,1) * MAP_BLOCKSIZE; + v3pos_t pmin = lua_istable(L, 2) ? check_v3pos_t(L, 2) : + mg.vm->m_area.MinEdge + v3pos_t(1,1,1) * MAP_BLOCKSIZE; + v3pos_t pmax = lua_istable(L, 3) ? check_v3pos_t(L, 3) : + mg.vm->m_area.MaxEdge - v3pos_t(1,1,1) * MAP_BLOCKSIZE; sortBoxVerticies(pmin, pmax); u32 blockseed = Mapgen::getBlockSeed(pmin, mg.seed); @@ -1488,17 +1488,17 @@ int ModApiMapgen::l_create_schematic(lua_State *L) Map *map = &(getEnv(L)->getMap()); Schematic schem; - v3POS p1 = check_v3POS(L, 1); - v3POS p2 = check_v3POS(L, 2); + v3pos_t p1 = check_v3pos_t(L, 1); + v3pos_t p2 = check_v3pos_t(L, 2); sortBoxVerticies(p1, p2); - std::vector > prob_list; + std::vector > prob_list; if (lua_istable(L, 3)) { lua_pushnil(L); while (lua_next(L, 3)) { if (lua_istable(L, -1)) { lua_getfield(L, -1, "pos"); - v3POS pos = check_v3POS(L, -1); + v3pos_t pos = check_v3pos_t(L, -1); lua_pop(L, 1); u8 prob = getintfield_default(L, -1, "prob", MTSCHEM_PROB_ALWAYS); @@ -1552,7 +1552,7 @@ int ModApiMapgen::l_place_schematic(lua_State *L) SchematicManager *schemmgr = getServer(L)->getEmergeManager()->schemmgr; //// Read position - v3POS p = check_v3POS(L, 1); + v3pos_t p = check_v3pos_t(L, 1); //// Read rotation int rot = ROTATE_0; @@ -1600,7 +1600,7 @@ int ModApiMapgen::l_place_schematic_on_vmanip(lua_State *L) MMVManip *vm = LuaVoxelManip::checkobject(L, 1)->vm; //// Read position - v3POS p = check_v3POS(L, 2); + v3pos_t p = check_v3pos_t(L, 2); //// Read rotation int rot = ROTATE_0; diff --git a/src/script/lua_api/l_minimap.cpp b/src/script/lua_api/l_minimap.cpp index 1fc7c31b1d..9dc1ce42e4 100644 --- a/src/script/lua_api/l_minimap.cpp +++ b/src/script/lua_api/l_minimap.cpp @@ -53,7 +53,7 @@ int LuaMinimap::l_get_pos(lua_State *L) LuaMinimap *ref = checkobject(L, 1); Minimap *m = getobject(ref); - push_v3POS(L, m->getPos()); + push_v3pos_t(L, m->getPos()); return 1; } @@ -62,7 +62,7 @@ int LuaMinimap::l_set_pos(lua_State *L) LuaMinimap *ref = checkobject(L, 1); Minimap *m = getobject(ref); - m->setPos(read_v3POS(L, 2)); + m->setPos(read_v3pos_t(L, 2)); return 1; } diff --git a/src/script/lua_api/l_nodemeta.cpp b/src/script/lua_api/l_nodemeta.cpp index 932f364367..8cb383bd3a 100644 --- a/src/script/lua_api/l_nodemeta.cpp +++ b/src/script/lua_api/l_nodemeta.cpp @@ -171,7 +171,7 @@ bool NodeMetaRef::handleFromTable(lua_State *L, int table, Metadata *_meta) } -NodeMetaRef::NodeMetaRef(v3POS p, ServerEnvironment *env): +NodeMetaRef::NodeMetaRef(v3pos_t p, ServerEnvironment *env): m_p(p), m_env(env) { @@ -185,7 +185,7 @@ NodeMetaRef::NodeMetaRef(Metadata *meta): // Creates an NodeMetaRef and leaves it on top of stack // Not callable from Lua; all references are created on the C side. -void NodeMetaRef::create(lua_State *L, v3POS p, ServerEnvironment *env) +void NodeMetaRef::create(lua_State *L, v3pos_t p, ServerEnvironment *env) { NodeMetaRef *o = new NodeMetaRef(p, env); //infostream<<"NodeMetaRef::create: o="< 1; np = *params; @@ -304,8 +304,8 @@ int LuaPerlinNoiseMap::l_get_map_slice(lua_State *L) NO_MAP_LOCK_REQUIRED; LuaPerlinNoiseMap *o = checkobject(L, 1); - v3POS slice_offset = read_v3POS(L, 2); - v3POS slice_size = read_v3POS(L, 3); + v3pos_t slice_offset = read_v3pos_t(L, 2); + v3pos_t slice_size = read_v3pos_t(L, 3); bool use_buffer = lua_istable(L, 4); Noise *n = o->noise; @@ -329,7 +329,7 @@ int LuaPerlinNoiseMap::create_object(lua_State *L) NoiseParams np; if (!read_noiseparams(L, 1, &np)) return 0; - v3POS size = read_v3POS(L, 2); + v3pos_t size = read_v3pos_t(L, 2); LuaPerlinNoiseMap *o = new LuaPerlinNoiseMap(&np, 0, size); *(void **)(lua_newuserdata(L, sizeof(void *))) = o; diff --git a/src/script/lua_api/l_noise.h b/src/script/lua_api/l_noise.h index 57d1ec7d12..22396385ab 100644 --- a/src/script/lua_api/l_noise.h +++ b/src/script/lua_api/l_noise.h @@ -80,7 +80,7 @@ class LuaPerlinNoiseMap : public ModApiBase static int l_get_map_slice(lua_State *L); public: - LuaPerlinNoiseMap(NoiseParams *np, s32 seed, v3POS size); + LuaPerlinNoiseMap(NoiseParams *np, s32 seed, v3pos_t size); ~LuaPerlinNoiseMap(); diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp index 4ff76d092d..b0d9934551 100644 --- a/src/script/lua_api/l_object.cpp +++ b/src/script/lua_api/l_object.cpp @@ -491,7 +491,7 @@ int ObjectRef::l_send_mapblock(lua_State *L) if (player == nullptr) return 0; - v3POS pos = read_v3POS(L, 2); + v3pos_t pos = read_v3pos_t(L, 2); session_t peer_id = player->getPeerId(); bool r = getServer(L)->SendBlock(peer_id, pos); diff --git a/src/script/lua_api/l_rollback.cpp b/src/script/lua_api/l_rollback.cpp index 044e7f81f2..33410d3272 100644 --- a/src/script/lua_api/l_rollback.cpp +++ b/src/script/lua_api/l_rollback.cpp @@ -40,7 +40,7 @@ int ModApiRollback::l_rollback_get_node_actions(lua_State *L) { NO_MAP_LOCK_REQUIRED; - v3POS pos = read_v3POS(L, 1); + v3pos_t pos = read_v3pos_t(L, 1); int range = luaL_checknumber(L, 2); time_t seconds = (time_t) luaL_checknumber(L, 3); int limit = luaL_checknumber(L, 4); @@ -60,7 +60,7 @@ int ModApiRollback::l_rollback_get_node_actions(lua_State *L) lua_pushstring(L, iter->actor.c_str()); lua_setfield(L, -2, "actor"); - push_v3POS(L, iter->p); + push_v3pos_t(L, iter->p); lua_setfield(L, -2, "pos"); lua_pushnumber(L, iter->unix_time); diff --git a/src/script/lua_api/l_vmanip.cpp b/src/script/lua_api/l_vmanip.cpp index a624b0fd7a..82330644ec 100644 --- a/src/script/lua_api/l_vmanip.cpp +++ b/src/script/lua_api/l_vmanip.cpp @@ -46,14 +46,14 @@ int LuaVoxelManip::l_read_from_map(lua_State *L) LuaVoxelManip *o = checkobject(L, 1); MMVManip *vm = o->vm; - v3BPOS bp1 = getNodeBlockPos(check_v3POS(L, 2)); - v3BPOS bp2 = getNodeBlockPos(check_v3POS(L, 3)); + v3bpos_t bp1 = getNodeBlockPos(check_v3pos_t(L, 2)); + v3bpos_t bp2 = getNodeBlockPos(check_v3pos_t(L, 3)); sortBoxVerticies(bp1, bp2); vm->initialEmerge(bp1, bp2); - push_v3POS(L, vm->m_area.MinEdge); - push_v3POS(L, vm->m_area.MaxEdge); + push_v3pos_t(L, vm->m_area.MinEdge); + push_v3pos_t(L, vm->m_area.MaxEdge); return 2; } @@ -139,7 +139,7 @@ int LuaVoxelManip::l_get_node_at(lua_State *L) const NodeDefManager *ndef = getServer(L)->getNodeDefManager(); LuaVoxelManip *o = checkobject(L, 1); - v3POS pos = check_v3POS(L, 2); + v3pos_t pos = check_v3pos_t(L, 2); pushnode(L, o->vm->getNodeNoExNoEmerge(pos), ndef); return 1; @@ -152,7 +152,7 @@ int LuaVoxelManip::l_set_node_at(lua_State *L) const NodeDefManager *ndef = getServer(L)->getNodeDefManager(); LuaVoxelManip *o = checkobject(L, 1); - v3POS pos = check_v3POS(L, 2); + v3pos_t pos = check_v3pos_t(L, 2); MapNode n = readnode(L, 3, ndef); o->vm->setNodeNoEmerge(pos, n); @@ -195,11 +195,11 @@ int LuaVoxelManip::l_calc_lighting(lua_State *L) EmergeManager *emerge = getServer(L)->getEmergeManager(); MMVManip *vm = o->vm; - v3POS yblock = v3POS(0, 1, 0) * MAP_BLOCKSIZE; - v3POS fpmin = vm->m_area.MinEdge; - v3POS fpmax = vm->m_area.MaxEdge; - v3POS pmin = lua_istable(L, 2) ? check_v3POS(L, 2) : fpmin + yblock; - v3POS pmax = lua_istable(L, 3) ? check_v3POS(L, 3) : fpmax - yblock; + v3pos_t yblock = v3pos_t(0, 1, 0) * MAP_BLOCKSIZE; + v3pos_t fpmin = vm->m_area.MinEdge; + v3pos_t fpmax = vm->m_area.MaxEdge; + v3pos_t pmin = lua_istable(L, 2) ? check_v3pos_t(L, 2) : fpmin + yblock; + v3pos_t pmax = lua_istable(L, 3) ? check_v3pos_t(L, 3) : fpmax - yblock; bool propagate_shadow = !lua_isboolean(L, 4) || readParam(L, 4); sortBoxVerticies(pmin, pmax); @@ -236,9 +236,9 @@ int LuaVoxelManip::l_set_lighting(lua_State *L) MMVManip *vm = o->vm; - v3POS yblock = v3POS(0, 1, 0) * MAP_BLOCKSIZE; - v3POS pmin = lua_istable(L, 3) ? check_v3POS(L, 3) : vm->m_area.MinEdge + yblock; - v3POS pmax = lua_istable(L, 4) ? check_v3POS(L, 4) : vm->m_area.MaxEdge - yblock; + v3pos_t yblock = v3pos_t(0, 1, 0) * MAP_BLOCKSIZE; + v3pos_t pmin = lua_istable(L, 3) ? check_v3pos_t(L, 3) : vm->m_area.MinEdge + yblock; + v3pos_t pmax = lua_istable(L, 4) ? check_v3pos_t(L, 4) : vm->m_area.MaxEdge - yblock; sortBoxVerticies(pmin, pmax); if (!vm->m_area.contains(VoxelArea(pmin, pmax))) @@ -367,8 +367,8 @@ int LuaVoxelManip::l_get_emerged_area(lua_State *L) LuaVoxelManip *o = checkobject(L, 1); - push_v3POS(L, o->vm->m_area.MinEdge); - push_v3POS(L, o->vm->m_area.MaxEdge); + push_v3pos_t(L, o->vm->m_area.MinEdge); + push_v3pos_t(L, o->vm->m_area.MaxEdge); return 2; } @@ -383,12 +383,12 @@ LuaVoxelManip::LuaVoxelManip(Map *map) : vm(new MMVManip(map)) { } -LuaVoxelManip::LuaVoxelManip(Map *map, v3POS p1, v3POS p2) +LuaVoxelManip::LuaVoxelManip(Map *map, v3pos_t p1, v3pos_t p2) { vm = new MMVManip(map); - v3BPOS bp1 = getNodeBlockPos(p1); - v3BPOS bp2 = getNodeBlockPos(p2); + v3bpos_t bp1 = getNodeBlockPos(p1); + v3bpos_t bp2 = getNodeBlockPos(p2); sortBoxVerticies(bp1, bp2); vm->initialEmerge(bp1, bp2); } @@ -407,7 +407,7 @@ int LuaVoxelManip::create_object(lua_State *L) Map *map = &(env->getMap()); LuaVoxelManip *o = (lua_istable(L, 1) && lua_istable(L, 2)) ? - new LuaVoxelManip(map, check_v3POS(L, 1), check_v3POS(L, 2)) : + new LuaVoxelManip(map, check_v3pos_t(L, 1), check_v3pos_t(L, 2)) : new LuaVoxelManip(map); *(void **)(lua_newuserdata(L, sizeof(void *))) = o; diff --git a/src/script/lua_api/l_vmanip.h b/src/script/lua_api/l_vmanip.h index 83dd14d717..4ecd883f8e 100644 --- a/src/script/lua_api/l_vmanip.h +++ b/src/script/lua_api/l_vmanip.h @@ -33,7 +33,7 @@ class MMVManip; class LuaVoxelManip : public ModApiBase { private: - std::map modified_blocks; + std::map modified_blocks; bool is_mapgen_vm = false; static const char className[]; @@ -67,7 +67,7 @@ class LuaVoxelManip : public ModApiBase MMVManip *vm = nullptr; LuaVoxelManip(MMVManip *mmvm, bool is_mapgen_vm); - LuaVoxelManip(Map *map, v3POS p1, v3POS p2); + LuaVoxelManip(Map *map, v3pos_t p1, v3pos_t p2); LuaVoxelManip(Map *map); ~LuaVoxelManip(); diff --git a/src/server.cpp b/src/server.cpp index 7e46a38f18..f7af3aec82 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -650,7 +650,7 @@ void Server::AsyncRunStep(bool initial_step) ScopeProfiler sp(g_profiler, "Server: liquid transform"); - std::map modified_blocks; + std::map modified_blocks; m_env->getMap().transformLiquids(modified_blocks, m_env); /* @@ -865,7 +865,7 @@ void Server::AsyncRunStep(bool initial_step) // We'll log the amount of each Profiler prof; - std::list node_meta_updates; + std::list node_meta_updates; while (!m_unsent_map_edit_queue.empty()) { MapEditEvent* event = m_unsent_map_edit_queue.front(); @@ -906,7 +906,7 @@ void Server::AsyncRunStep(bool initial_step) } case MEET_OTHER: prof.add("MEET_OTHER", 1); - for (const v3POS &modified_block : event->modified_blocks) { + for (const v3pos_t &modified_block : event->modified_blocks) { m_clients.markBlockposAsNotSent(modified_block); } break; @@ -922,8 +922,8 @@ void Server::AsyncRunStep(bool initial_step) */ if (!far_players.empty()) { // Convert list format to that wanted by SetBlocksNotSent - std::map modified_blocks2; - for (const v3POS &modified_block : event->modified_blocks) { + std::map modified_blocks2; + for (const v3pos_t &modified_block : event->modified_blocks) { modified_blocks2[modified_block] = m_env->getMap().getBlockNoCreateNoEx(modified_block); } @@ -1223,7 +1223,7 @@ void Server::onMapEditEvent(const MapEditEvent &event) m_unsent_map_edit_queue.push(new MapEditEvent(event)); } -void Server::SetBlocksNotSent(std::map& block) +void Server::SetBlocksNotSent(std::map& block) { std::vector clients = m_clients.getClientIDs(); m_clients.lock(); @@ -2209,12 +2209,12 @@ void Server::fadeSound(s32 handle, float step, float gain) } } -void Server::sendRemoveNode(v3POS p, std::unordered_set *far_players, +void Server::sendRemoveNode(v3pos_t p, std::unordered_set *far_players, float far_d_nodes) { float maxd = far_d_nodes * BS; v3f p_f = intToFloat(p, BS); - v3BPOS block_pos = getNodeBlockPos(p); + v3bpos_t block_pos = getNodeBlockPos(p); NetworkPacket pkt(TOCLIENT_REMOVENODE, 6); pkt << p; @@ -2247,12 +2247,12 @@ void Server::sendRemoveNode(v3POS p, std::unordered_set *far_players, m_clients.unlock(); } -void Server::sendAddNode(v3POS p, MapNode n, std::unordered_set *far_players, +void Server::sendAddNode(v3pos_t p, MapNode n, std::unordered_set *far_players, float far_d_nodes, bool remove_metadata) { float maxd = far_d_nodes * BS; v3f p_f = intToFloat(p, BS); - v3BPOS block_pos = getNodeBlockPos(p); + v3bpos_t block_pos = getNodeBlockPos(p); NetworkPacket pkt(TOCLIENT_ADDNODE, 6 + 2 + 1 + 1 + 1); pkt << p << n.param0 << n.param1 << n.param2 @@ -2286,7 +2286,7 @@ void Server::sendAddNode(v3POS p, MapNode n, std::unordered_set *far_player m_clients.unlock(); } -void Server::sendMetadataChanged(const std::list &meta_updates, float far_d_nodes) +void Server::sendMetadataChanged(const std::list &meta_updates, float far_d_nodes) { float maxd = far_d_nodes * BS; NodeMetadataList meta_updates_list(false); @@ -2302,13 +2302,13 @@ void Server::sendMetadataChanged(const std::list &meta_updates, float far ServerActiveObject *player = m_env->getActiveObject(i); v3f player_pos = player ? player->getBasePosition() : v3f(); - for (const v3POS &pos : meta_updates) { + for (const v3pos_t &pos : meta_updates) { NodeMetadata *meta = m_env->getMap().getNodeMetadata(pos); if (!meta) continue; - v3BPOS block_pos = getNodeBlockPos(pos); + v3bpos_t block_pos = getNodeBlockPos(pos); if (!client->isBlockSent(block_pos) || (player && player_pos.getDistanceFrom(intToFloat(pos, BS)) > maxd)) { client->SetBlockNotSent(block_pos); @@ -2420,7 +2420,7 @@ void Server::SendBlocks(float dtime) m_clients.unlock(); } -bool Server::SendBlock(session_t peer_id, const v3POS &blockpos) +bool Server::SendBlock(session_t peer_id, const v3pos_t &blockpos) { MapBlock *block = m_env->getMap().getBlockNoCreateNoEx(blockpos); if (!block) @@ -3708,18 +3708,18 @@ v3f Server::findSpawnPos() for (s32 i = 0; i < 4000 && !is_good; i++) { s32 range = MYMIN(1 + i, range_max); // We're going to try to throw the player to this position - v2POS nodepos2d = v2POS( + v2pos_t nodepos2d = v2pos_t( -range + (myrand() % (range * 2)), -range + (myrand() % (range * 2))); // Get spawn level at point - POS spawn_level = m_emerge->getSpawnLevelAtPoint(nodepos2d); + pos_t spawn_level = m_emerge->getSpawnLevelAtPoint(nodepos2d); // Continue if MAX_MAP_GENERATION_LIMIT was returned by the mapgen to // signify an unsuitable spawn position, or if outside limits. if (spawn_level >= MAX_MAP_GENERATION_LIMIT || spawn_level <= -MAX_MAP_GENERATION_LIMIT) continue; - v3POS nodepos(nodepos2d.X, spawn_level, nodepos2d.Y); + v3pos_t nodepos(nodepos2d.X, spawn_level, nodepos2d.Y); // Consecutive empty nodes s32 air_count = 0; @@ -3729,7 +3729,7 @@ v3f Server::findSpawnPos() // no obstructions, but mapgen decorations are generated after spawn so // the player may end up inside one. for (s32 i = 0; i < 8; i++) { - v3BPOS blockpos = getNodeBlockPos(nodepos); + v3bpos_t blockpos = getNodeBlockPos(nodepos); map.emergeBlock(blockpos, true); content_t c = map.getNode(nodepos).getContent(); diff --git a/src/server.h b/src/server.h index 15a97dd323..bc7fc175d2 100644 --- a/src/server.h +++ b/src/server.h @@ -372,7 +372,7 @@ class Server : public con::PeerHandler, public MapEventReceiver, ModChannel *getModChannel(const std::string &channel); // Send block to specific player only - bool SendBlock(session_t peer_id, const v3POS &blockpos); + bool SendBlock(session_t peer_id, const v3pos_t &blockpos); // Get or load translations for a language Translations *getTranslationLanguage(const std::string &lang_code); @@ -425,7 +425,7 @@ class Server : public con::PeerHandler, public MapEventReceiver, u16 protocol_version); /* mark blocks not sent for all clients */ - void SetBlocksNotSent(std::map& block); + void SetBlocksNotSent(std::map& block); virtual void SendChatMessage(session_t peer_id, const ChatMessage &message); @@ -460,13 +460,13 @@ class Server : public con::PeerHandler, public MapEventReceiver, far_d_nodes are ignored and their peer_ids are added to far_players */ // Envlock and conlock should be locked when calling these - void sendRemoveNode(v3POS p, std::unordered_set *far_players = nullptr, + void sendRemoveNode(v3pos_t p, std::unordered_set *far_players = nullptr, float far_d_nodes = 100); - void sendAddNode(v3POS p, MapNode n, + void sendAddNode(v3pos_t p, MapNode n, std::unordered_set *far_players = nullptr, float far_d_nodes = 100, bool remove_metadata = true); - void sendMetadataChanged(const std::list &meta_updates, + void sendMetadataChanged(const std::list &meta_updates, float far_d_nodes = 100); // Environment and Connection must be locked when called diff --git a/src/server/player_sao.cpp b/src/server/player_sao.cpp index 6b330639fd..cace042102 100644 --- a/src/server/player_sao.cpp +++ b/src/server/player_sao.cpp @@ -155,7 +155,7 @@ void PlayerSAO::step(float dtime, bool send_recommended) { if (!isImmortal() && m_drowning_interval.step(dtime, 2.0f)) { // Get nose/mouth position, approximate with eye position - v3POS p = floatToInt(getEyePosition(), BS); + v3pos_t p = floatToInt(getEyePosition(), BS); MapNode n = m_env->getMap().getNode(p); const ContentFeatures &c = m_env->getGameDef()->ndef()->get(n); // If node generates drown @@ -173,7 +173,7 @@ void PlayerSAO::step(float dtime, bool send_recommended) if (m_breathing_interval.step(dtime, 0.5f) && !isImmortal()) { // Get nose/mouth position, approximate with eye position - v3POS p = floatToInt(getEyePosition(), BS); + v3pos_t p = floatToInt(getEyePosition(), BS); MapNode n = m_env->getMap().getNode(p); const ContentFeatures &c = m_env->getGameDef()->ndef()->get(n); // If player is alive & not drowning & not in ignore & not immortal, breathe @@ -191,7 +191,7 @@ void PlayerSAO::step(float dtime, bool send_recommended) // Sequence of damage points, starting 0.1 above feet and progressing // upwards in 1 node intervals, stopping below top damage point. for (float dam_height = 0.1f; dam_height < dam_top; dam_height++) { - v3POS p = floatToInt(m_base_position + + v3pos_t p = floatToInt(m_base_position + v3f(0.0f, dam_height * BS, 0.0f), BS); MapNode n = m_env->getMap().getNode(p); const ContentFeatures &c = m_env->getGameDef()->ndef()->get(n); @@ -202,7 +202,7 @@ void PlayerSAO::step(float dtime, bool send_recommended) } // Top damage point - v3POS ptop = floatToInt(m_base_position + + v3pos_t ptop = floatToInt(m_base_position + v3f(0.0f, dam_top * BS, 0.0f), BS); MapNode ntop = m_env->getMap().getNode(ptop); const ContentFeatures &c = m_env->getGameDef()->ndef()->get(ntop); @@ -339,7 +339,7 @@ void PlayerSAO::setPos(const v3f &pos) return; // Send mapblock of target location - v3POS blockpos = v3POS(pos.X / MAP_BLOCKSIZE, pos.Y / MAP_BLOCKSIZE, pos.Z / MAP_BLOCKSIZE); + v3pos_t blockpos = v3pos_t(pos.X / MAP_BLOCKSIZE, pos.Y / MAP_BLOCKSIZE, pos.Z / MAP_BLOCKSIZE); m_env->getGameDef()->SendBlock(m_peer_id, blockpos); setBasePosition(pos); diff --git a/src/server/player_sao.h b/src/server/player_sao.h index 1a0f8e33de..5f2c397638 100644 --- a/src/server/player_sao.h +++ b/src/server/player_sao.h @@ -150,14 +150,14 @@ class PlayerSAO : public UnitSAO m_time_from_last_punch = 0.0; return r; } - void noCheatDigStart(const v3POS &p) + void noCheatDigStart(const v3pos_t &p) { m_nocheat_dig_pos = p; m_nocheat_dig_time = 0; } - v3POS getNoCheatDigPos() { return m_nocheat_dig_pos; } + v3pos_t getNoCheatDigPos() { return m_nocheat_dig_pos; } float getNoCheatDigTime() { return m_nocheat_dig_time; } - void noCheatDigEnd() { m_nocheat_dig_pos = v3POS(32767, 32767, 32767); } + void noCheatDigEnd() { m_nocheat_dig_pos = v3pos_t(32767, 32767, 32767); } LagPool &getDigPool() { return m_dig_pool; } void setMaxSpeedOverride(const v3f &vel); // Returns true if cheated @@ -197,7 +197,7 @@ class PlayerSAO : public UnitSAO v3f m_last_good_position; float m_time_from_last_teleport = 0.0f; float m_time_from_last_punch = 0.0f; - v3POS m_nocheat_dig_pos = v3POS(32767, 32767, 32767); + v3pos_t m_nocheat_dig_pos = v3pos_t(32767, 32767, 32767); float m_nocheat_dig_time = 0.0f; float m_max_speed_override_time = 0.0f; v3f m_max_speed_override = v3f(0.0f, 0.0f, 0.0f); diff --git a/src/server/serveractiveobject.h b/src/server/serveractiveobject.h index b7957c274e..b529f437ee 100644 --- a/src/server/serveractiveobject.h +++ b/src/server/serveractiveobject.h @@ -233,7 +233,7 @@ class ServerActiveObject : public ActiveObject The block from which the object was loaded from, and in which a copy of the static data resides. */ - v3POS m_static_block = v3POS(1337,1337,1337); + v3pos_t m_static_block = v3pos_t(1337,1337,1337); protected: virtual void onMarkedForDeactivation() {} diff --git a/src/serverenvironment.cpp b/src/serverenvironment.cpp index 0c1ca25e6d..13db96162d 100644 --- a/src/serverenvironment.cpp +++ b/src/serverenvironment.cpp @@ -254,8 +254,8 @@ void LBMManager::applyLBMs(ServerEnvironment *env, MapBlock *block, u32 stamp) // Precondition, we need m_lbm_lookup to be initialized FATAL_ERROR_IF(!m_query_mode, "attempted to query on non fully set up LBMManager"); - v3POS pos_of_block = block->getPosRelative(); - v3POS pos; + v3pos_t pos_of_block = block->getPosRelative(); + v3pos_t pos; MapNode n; content_t c; lbm_lookup_map::const_iterator it = getLBMsIntroducedAfter(stamp); @@ -291,9 +291,9 @@ void LBMManager::applyLBMs(ServerEnvironment *env, MapBlock *block, u32 stamp) ActiveBlockList */ -void fillRadiusBlock(v3POS p0, s16 r, std::set &list) +void fillRadiusBlock(v3pos_t p0, s16 r, std::set &list) { - v3POS p; + v3pos_t p; for(p.X=p0.X-r; p.X<=p0.X+r; p.X++) for(p.Y=p0.Y-r; p.Y<=p0.Y+r; p.Y++) for(p.Z=p0.Z-r; p.Z<=p0.Z+r; p.Z++) @@ -306,14 +306,14 @@ void fillRadiusBlock(v3POS p0, s16 r, std::set &list) } } -void fillViewConeBlock(v3POS p0, +void fillViewConeBlock(v3pos_t p0, const s16 r, const v3f camera_pos, const v3f camera_dir, const float camera_fov, - std::set &list) + std::set &list) { - v3POS p; + v3pos_t p; const s16 r_nodes = r * BS * MAP_BLOCKSIZE; for (p.X = p0.X - r; p.X <= p0.X+r; p.X++) for (p.Y = p0.Y - r; p.Y <= p0.Y+r; p.Y++) @@ -327,16 +327,16 @@ void fillViewConeBlock(v3POS p0, void ActiveBlockList::update(std::vector &active_players, s16 active_block_range, s16 active_object_range, - std::set &blocks_removed, - std::set &blocks_added) + std::set &blocks_removed, + std::set &blocks_added) { /* Create the new list */ - std::set newlist = m_forceloaded_list; + std::set newlist = m_forceloaded_list; m_abm_list = m_forceloaded_list; for (const PlayerSAO *playersao : active_players) { - v3BPOS pos = getNodeBlockPos(floatToInt(playersao->getBasePosition(), BS)); + v3bpos_t pos = getNodeBlockPos(floatToInt(playersao->getBasePosition(), BS)); fillRadiusBlock(pos, active_block_range, m_abm_list); fillRadiusBlock(pos, active_block_range, newlist); @@ -359,7 +359,7 @@ void ActiveBlockList::update(std::vector &active_players, Find out which blocks on the old list are not on the new list */ // Go through old list - for (v3POS p : m_list) { + for (v3pos_t p : m_list) { // If not on new list, it's been removed if (newlist.find(p) == newlist.end()) blocks_removed.insert(p); @@ -369,7 +369,7 @@ void ActiveBlockList::update(std::vector &active_players, Find out which blocks on the new list are not on the old list */ // Go through new list - for (v3POS p : newlist) { + for (v3pos_t p : newlist) { // If not on old list, it's been added if(m_list.find(p) == m_list.end()) blocks_added.insert(p); @@ -379,7 +379,7 @@ void ActiveBlockList::update(std::vector &active_players, Update m_list */ m_list.clear(); - for (v3POS p : newlist) { + for (v3pos_t p : newlist) { m_list.insert(p); } } @@ -729,8 +729,8 @@ struct ActiveABM int chance; std::vector required_neighbors; bool check_required_neighbors; // false if required_neighbors is known to be empty - POS min_y; - POS max_y; + pos_t min_y; + pos_t max_y; }; class ABMHandler @@ -822,7 +822,7 @@ class ABMHandler for(s16 z=-1; z<=1; z++) { MapBlock *block2 = map->getBlockNoCreateNoEx( - block->getPos() + v3POS(x,y,z)); + block->getPos() + v3pos_t(x,y,z)); if(block2==NULL){ wider_unknown_count++; continue; @@ -868,7 +868,7 @@ class ABMHandler u32 active_object_count = this->countObjects(block, map, active_object_count_wider); m_env->m_added_objects = 0; - v3POS p0; + v3pos_t p0; for(p0.X=0; p0.X= m_aabms.size() || !m_aabms[c]) continue; - v3POS p = p0 + block->getPosRelative(); + v3pos_t p = p0 + block->getPosRelative(); for (ActiveABM &aabm : *m_aabms[c]) { if ((p.Y < aabm.min_y) || (p.Y > aabm.max_y)) continue; @@ -898,7 +898,7 @@ class ABMHandler // Check neighbors if (aabm.check_required_neighbors) { - v3POS p1; + v3pos_t p1; for(p1.X = p0.X-1; p1.X <= p0.X+1; p1.X++) for(p1.Y = p0.Y-1; p1.Y <= p0.Y+1; p1.Y++) for(p1.Z = p0.Z-1; p1.Z <= p0.Z+1; p1.Z++) @@ -986,7 +986,7 @@ void ServerEnvironment::activateBlock(MapBlock *block, u32 additional_dtime) MapNode n; for (const NodeTimer &elapsed_timer : elapsed_timers) { n = block->getNodeNoEx(elapsed_timer.position); - v3POS p = elapsed_timer.position + block->getPosRelative(); + v3pos_t p = elapsed_timer.position + block->getPosRelative(); if (m_script->node_on_timer(p, n, elapsed_timer.elapsed)) block->setNodeTimer(NodeTimer(elapsed_timer.timeout, 0, elapsed_timer.position)); @@ -1004,7 +1004,7 @@ void ServerEnvironment::addLoadingBlockModifierDef(LoadingBlockModifierDef *lbm) m_lbm_mgr.addLBMDef(lbm); } -bool ServerEnvironment::setNode(v3POS p, const MapNode &n) +bool ServerEnvironment::setNode(v3pos_t p, const MapNode &n) { const NodeDefManager *ndef = m_server->ndef(); MapNode n_old = m_map->getNode(p); @@ -1037,7 +1037,7 @@ bool ServerEnvironment::setNode(v3POS p, const MapNode &n) return true; } -bool ServerEnvironment::removeNode(v3POS p) +bool ServerEnvironment::removeNode(v3pos_t p) { const NodeDefManager *ndef = m_server->ndef(); MapNode n_old = m_map->getNode(p); @@ -1062,7 +1062,7 @@ bool ServerEnvironment::removeNode(v3POS p) return true; } -bool ServerEnvironment::swapNode(v3POS p, const MapNode &n) +bool ServerEnvironment::swapNode(v3pos_t p, const MapNode &n) { if (!m_map->addNodeWithEvent(p, n, false)) return false; @@ -1073,12 +1073,12 @@ bool ServerEnvironment::swapNode(v3POS p, const MapNode &n) return true; } -u8 ServerEnvironment::findSunlight(v3POS pos) const +u8 ServerEnvironment::findSunlight(v3pos_t pos) const { // Directions for neighbouring nodes with specified order - static const v3POS dirs[] = { - v3POS(-1, 0, 0), v3POS(1, 0, 0), v3POS(0, 0, -1), v3POS(0, 0, 1), - v3POS(0, -1, 0), v3POS(0, 1, 0) + static const v3pos_t dirs[] = { + v3pos_t(-1, 0, 0), v3pos_t(1, 0, 0), v3pos_t(0, 0, -1), v3pos_t(0, 0, 1), + v3pos_t(0, -1, 0), v3pos_t(0, 1, 0) }; const NodeDefManager *ndef = m_server->ndef(); @@ -1087,7 +1087,7 @@ u8 ServerEnvironment::findSunlight(v3POS pos) const u8 found_light = 0; struct stack_entry { - v3POS pos; + v3pos_t pos; s16 dist; }; std::stack stack; @@ -1100,11 +1100,11 @@ u8 ServerEnvironment::findSunlight(v3POS pos) const struct stack_entry e = stack.top(); stack.pop(); - v3POS currentPos = e.pos; + v3pos_t currentPos = e.pos; s8 dist = e.dist + 1; - for (const v3POS& off : dirs) { - v3POS neighborPos = currentPos + off; + for (const v3pos_t& off : dirs) { + v3pos_t neighborPos = currentPos + off; s64 neighborHash = MapDatabase::getBlockAsInteger(neighborPos); // Do not walk neighborPos multiple times unless the distance to the start @@ -1190,7 +1190,7 @@ void ServerEnvironment::clearObjects(ClearObjectsMode mode) m_ao_manager.clear(cb_removal); // Get list of loaded blocks - std::vector loaded_blocks; + std::vector loaded_blocks; infostream << "ServerEnvironment::clearObjects(): " << "Listing all loaded blocks" << std::endl; m_map->listAllLoadedBlocks(loaded_blocks); @@ -1199,7 +1199,7 @@ void ServerEnvironment::clearObjects(ClearObjectsMode mode) << loaded_blocks.size()< loadable_blocks; + std::vector loadable_blocks; if (mode == CLEAR_OBJECTS_MODE_FULL) { infostream << "ServerEnvironment::clearObjects(): " << "Listing all loadable blocks" << std::endl; @@ -1216,7 +1216,7 @@ void ServerEnvironment::clearObjects(ClearObjectsMode mode) << " blocks" << std::endl; // Grab a reference on each loaded block to avoid unloading it - for (v3POS p : loaded_blocks) { + for (v3pos_t p : loaded_blocks) { MapBlock *block = m_map->getBlockNoCreateNoEx(p); assert(block != NULL); block->refGrab(); @@ -1234,7 +1234,7 @@ void ServerEnvironment::clearObjects(ClearObjectsMode mode) u32 num_objs_cleared = 0; for (auto i = loadable_blocks.begin(); i != loadable_blocks.end(); ++i) { - v3POS p = *i; + v3pos_t p = *i; MapBlock *block = m_map->emergeBlock(p, false); if (!block) { errorstream << "ServerEnvironment::clearObjects(): " @@ -1269,7 +1269,7 @@ void ServerEnvironment::clearObjects(ClearObjectsMode mode) m_map->unloadUnreferencedBlocks(); // Drop references that were added above - for (v3POS p : loaded_blocks) { + for (v3pos_t p : loaded_blocks) { MapBlock *block = m_map->getBlockNoCreateNoEx(p); assert(block); block->refDrop(); @@ -1349,8 +1349,8 @@ void ServerEnvironment::step(float dtime) g_settings->getS16("active_object_send_range_blocks"); static thread_local const s16 active_block_range = g_settings->getS16("active_block_range"); - std::set blocks_removed; - std::set blocks_added; + std::set blocks_removed; + std::set blocks_added; m_active_blocks.update(players, active_block_range, active_object_range, blocks_removed, blocks_added); @@ -1361,7 +1361,7 @@ void ServerEnvironment::step(float dtime) // Convert active objects that are no more in active blocks to static deactivateFarObjects(false); - for (const v3POS &p: blocks_removed) { + for (const v3pos_t &p: blocks_removed) { MapBlock *block = m_map->getBlockNoCreateNoEx(p); if (!block) continue; @@ -1374,7 +1374,7 @@ void ServerEnvironment::step(float dtime) Handle added blocks */ - for (const v3POS &p: blocks_added) { + for (const v3pos_t &p: blocks_added) { MapBlock *block = m_map->getBlockOrEmerge(p); if (!block) { m_active_blocks.m_list.erase(p); @@ -1394,7 +1394,7 @@ void ServerEnvironment::step(float dtime) float dtime = m_cache_nodetimer_interval; - for (const v3POS &p: m_active_blocks.m_list) { + for (const v3pos_t &p: m_active_blocks.m_list) { MapBlock *block = m_map->getBlockNoCreateNoEx(p); if (!block) continue; @@ -1414,7 +1414,7 @@ void ServerEnvironment::step(float dtime) std::vector elapsed_timers = block->m_node_timers.step(dtime); if (!elapsed_timers.empty()) { MapNode n; - v3POS p2; + v3pos_t p2; for (const NodeTimer &elapsed_timer: elapsed_timers) { n = block->getNodeNoEx(elapsed_timer.position); p2 = elapsed_timer.position + block->getPosRelative(); @@ -1438,7 +1438,7 @@ void ServerEnvironment::step(float dtime) int abms_run = 0; int blocks_cached = 0; - std::vector output(m_active_blocks.m_abm_list.size()); + std::vector output(m_active_blocks.m_abm_list.size()); // Shuffle the active blocks so that each block gets an equal chance // of having its ABMs run. @@ -1448,7 +1448,7 @@ void ServerEnvironment::step(float dtime) int i = 0; // determine the time budget for ABMs u32 max_time_ms = m_cache_abm_interval * 1000 * m_cache_abm_time_budget; - for (const v3POS &p : output) { + for (const v3pos_t &p : output) { MapBlock *block = m_map->getBlockNoCreateNoEx(p); if (!block) continue; @@ -1550,7 +1550,7 @@ void ServerEnvironment::step(float dtime) m_server->sendDetachedInventories(PEER_ID_INEXISTENT, true); } -ServerEnvironment::BlockStatus ServerEnvironment::getBlockStatus(v3BPOS blockpos) +ServerEnvironment::BlockStatus ServerEnvironment::getBlockStatus(v3bpos_t blockpos) { if (m_active_blocks.contains(blockpos)) return BS_ACTIVE; @@ -1683,7 +1683,7 @@ void ServerEnvironment::getRemovedActiveObjects(PlayerSAO *playersao, s16 radius } void ServerEnvironment::setStaticForActiveObjectsInBlock( - v3POS blockpos, bool static_exists, v3POS static_block) + v3pos_t blockpos, bool static_exists, v3pos_t static_block) { MapBlock *block = m_map->getBlockNoCreateNoEx(blockpos); if (!block) @@ -1737,7 +1737,7 @@ void ServerEnvironment::getSelectedActiveObjects( selection_box.MaxEdge + pos); v3f current_intersection; - v3POS current_normal; + v3pos_t current_normal; if (boxLineCollision(offsetted_box, shootline_on_map.start, line_vector, ¤t_intersection, ¤t_normal)) { objects.emplace_back( @@ -1769,7 +1769,7 @@ u16 ServerEnvironment::addActiveObjectRaw(ServerActiveObject *object, v3f objectpos = object->getBasePosition(); StaticObject s_obj(object, objectpos); // Add to the block where the object is located in - v3BPOS blockpos = getNodeBlockPos(floatToInt(objectpos, BS)); + v3bpos_t blockpos = getNodeBlockPos(floatToInt(objectpos, BS)); MapBlock *block = m_map->emergeBlock(blockpos); if(block){ block->m_static_objects.m_active[object->getId()] = s_obj; @@ -1780,7 +1780,7 @@ u16 ServerEnvironment::addActiveObjectRaw(ServerActiveObject *object, block->raiseModified(MOD_STATE_WRITE_NEEDED, MOD_REASON_ADD_ACTIVE_OBJECT_RAW); } else { - v3POS p = floatToInt(objectpos, BS); + v3pos_t p = floatToInt(objectpos, BS); errorstream<<"ServerEnvironment::addActiveObjectRaw(): " <<"could not emerge block for storing id="<getId() <<" statically (pos="<getBasePosition(); // The block in which the object resides in - v3BPOS blockpos_o = getNodeBlockPos(floatToInt(objectpos, BS)); + v3bpos_t blockpos_o = getNodeBlockPos(floatToInt(objectpos, BS)); // If object's static data is stored in a deactivated block and object // is actually located in an active block, re-save to the block in @@ -2085,7 +2085,7 @@ void ServerEnvironment::deactivateFarObjects(bool _force_delete) deleteStaticFromBlock(obj, id, reason, false); // Add to the block where the object is located in - v3BPOS blockpos = getNodeBlockPos(floatToInt(objectpos, BS)); + v3bpos_t blockpos = getNodeBlockPos(floatToInt(objectpos, BS)); u16 store_id = pending_delete ? id : 0; if (!saveStaticToBlock(blockpos, store_id, obj, s_obj, reason)) force_delete = true; @@ -2152,7 +2152,7 @@ void ServerEnvironment::deleteStaticFromBlock( } bool ServerEnvironment::saveStaticToBlock( - v3POS blockpos, u16 store_id, + v3pos_t blockpos, u16 store_id, ServerActiveObject *obj, const StaticObject &s_obj, u32 mod_reason) { diff --git a/src/serverenvironment.h b/src/serverenvironment.h index bc628038b1..a119cf2406 100644 --- a/src/serverenvironment.h +++ b/src/serverenvironment.h @@ -68,12 +68,12 @@ class ActiveBlockModifier // Whether to modify chance to simulate time lost by an unnattended block virtual bool getSimpleCatchUp() = 0; // get min Y for apply abm - virtual POS getMinY() = 0; + virtual pos_t getMinY() = 0; // get max Y for apply abm - virtual POS getMaxY() = 0; + virtual pos_t getMaxY() = 0; // This is called usually at interval for 1/chance of the nodes - virtual void trigger(ServerEnvironment *env, v3POS p, MapNode n){}; - virtual void trigger(ServerEnvironment *env, v3POS p, MapNode n, + virtual void trigger(ServerEnvironment *env, v3pos_t p, MapNode n){}; + virtual void trigger(ServerEnvironment *env, v3pos_t p, MapNode n, u32 active_object_count, u32 active_object_count_wider){}; }; @@ -94,7 +94,7 @@ struct LoadingBlockModifierDef virtual ~LoadingBlockModifierDef() = default; - virtual void trigger(ServerEnvironment *env, v3POS p, MapNode n){}; + virtual void trigger(ServerEnvironment *env, v3pos_t p, MapNode n){}; }; struct LBMContentMapping @@ -164,10 +164,10 @@ class ActiveBlockList void update(std::vector &active_players, s16 active_block_range, s16 active_object_range, - std::set &blocks_removed, - std::set &blocks_added); + std::set &blocks_removed, + std::set &blocks_added); - bool contains(v3POS p){ + bool contains(v3pos_t p){ return (m_list.find(p) != m_list.end()); } @@ -175,9 +175,9 @@ class ActiveBlockList m_list.clear(); } - std::set m_list; - std::set m_abm_list; - std::set m_forceloaded_list; + std::set m_list; + std::set m_abm_list; + std::set m_forceloaded_list; private: }; @@ -314,12 +314,12 @@ class ServerEnvironment : public Environment */ // Script-aware node setters - bool setNode(v3POS p, const MapNode &n); - bool removeNode(v3POS p); - bool swapNode(v3POS p, const MapNode &n); + bool setNode(v3pos_t p, const MapNode &n); + bool removeNode(v3pos_t p); + bool swapNode(v3pos_t p, const MapNode &n); // Find the daylight value at pos with a Depth First Search - u8 findSunlight(v3POS pos) const; + u8 findSunlight(v3pos_t pos) const; // Find all active objects inside a radius around a point void getObjectsInsideRadius(std::vector &objects, const v3f &pos, float radius, @@ -346,7 +346,7 @@ class ServerEnvironment : public Environment void reportMaxLagEstimate(float f) { m_max_lag_estimate = f; } float getMaxLagEstimate() { return m_max_lag_estimate; } - std::set* getForceloadedBlocks() { return &m_active_blocks.m_forceloaded_list; } + std::set* getForceloadedBlocks() { return &m_active_blocks.m_forceloaded_list; } // Sorted by how ready a mapblock is enum BlockStatus { @@ -355,12 +355,12 @@ class ServerEnvironment : public Environment BS_LOADED, BS_ACTIVE // always highest value }; - BlockStatus getBlockStatus(v3POS blockpos); + BlockStatus getBlockStatus(v3pos_t blockpos); // Sets the static object status all the active objects in the specified block // This is only really needed for deleting blocks from the map - void setStaticForActiveObjectsInBlock(v3POS blockpos, - bool static_exists, v3POS static_block=v3POS(0,0,0)); + void setStaticForActiveObjectsInBlock(v3pos_t blockpos, + bool static_exists, v3pos_t static_block=v3pos_t(0,0,0)); RemotePlayer *getPlayer(const session_t peer_id); RemotePlayer *getPlayer(const char* name); @@ -427,7 +427,7 @@ class ServerEnvironment : public Environment */ void deleteStaticFromBlock( ServerActiveObject *obj, u16 id, u32 mod_reason, bool no_emerge); - bool saveStaticToBlock(v3POS blockpos, u16 store_id, + bool saveStaticToBlock(v3pos_t blockpos, u16 store_id, ServerActiveObject *obj, const StaticObject &s_obj, u32 mod_reason); /* diff --git a/src/settings.cpp b/src/settings.cpp index d17bbf92ee..8524bd67d0 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -527,7 +527,7 @@ s32 Settings::getS32(const std::string &name) const return stoi(get(name)); } -POS Settings::getPOS(const std::string &name) const +pos_t Settings::getPOS(const std::string &name) const { return stoi(get(name)); } @@ -777,7 +777,7 @@ bool Settings::getS32NoEx(const std::string &name, s32 &val) const } -bool Settings::getPOSNoEx(const std::string &name, POS &val) const +bool Settings::getPOSNoEx(const std::string &name, pos_t &val) const { #if USE_POS32 return getS32NoEx(name, val); @@ -921,7 +921,7 @@ bool Settings::setS32(const std::string &name, s32 value) return set(name, itos(value)); } -bool Settings::setPOS(const std::string &name, POS value) +bool Settings::setPOS(const std::string &name, pos_t value) { return set(name, itos(value)); } diff --git a/src/settings.h b/src/settings.h index cd8a2117c9..003cd77a38 100644 --- a/src/settings.h +++ b/src/settings.h @@ -163,7 +163,7 @@ class Settings { u32 getU32(const std::string &name) const; s32 getS32(const std::string &name) const; u64 getU64(const std::string &name) const; - POS getPOS(const std::string &name) const; + pos_t getPOS(const std::string &name) const; float getFloat(const std::string &name) const; v2f getV2F(const std::string &name) const; v3f getV3F(const std::string &name) const; @@ -189,7 +189,7 @@ class Settings { bool getS16NoEx(const std::string &name, s16 &val) const; bool getU32NoEx(const std::string &name, u32 &val) const; bool getS32NoEx(const std::string &name, s32 &val) const; - bool getPOSNoEx(const std::string &name, POS &val) const; + bool getPOSNoEx(const std::string &name, pos_t &val) const; bool getU64NoEx(const std::string &name, u64 &val) const; bool getFloatNoEx(const std::string &name, float &val) const; bool getV2FNoEx(const std::string &name, v2f &val) const; @@ -218,7 +218,7 @@ class Settings { bool setU16(const std::string &name, u16 value); bool setS32(const std::string &name, s32 value); bool setU64(const std::string &name, u64 value); - bool setPOS(const std::string &name, POS value); + bool setPOS(const std::string &name, pos_t value); bool setFloat(const std::string &name, float value); bool setV2F(const std::string &name, v2f value); bool setV3F(const std::string &name, v3f value); diff --git a/src/unittest/test.cpp b/src/unittest/test.cpp index 1eca5422db..8fe72c73ce 100644 --- a/src/unittest/test.cpp +++ b/src/unittest/test.cpp @@ -356,18 +356,18 @@ struct TestMapBlock: public TestBase MapNode node; bool position_valid; - core::list validity_exceptions; + core::list validity_exceptions; TC() { position_valid = true; } - virtual bool isValidPosition(v3POS p) + virtual bool isValidPosition(v3pos_t p) { //return position_valid ^ (p==position_valid_exception); bool exception = false; - for(core::list::Iterator i=validity_exceptions.begin(); + for(core::list::Iterator i=validity_exceptions.begin(); i != validity_exceptions.end(); i++) { if(p == *i) @@ -379,14 +379,14 @@ struct TestMapBlock: public TestBase return exception ? !position_valid : position_valid; } - virtual MapNode getNode(v3POS p) + virtual MapNode getNode(v3pos_t p) { if(isValidPosition(p) == false) throw InvalidPositionException(); return node; } - virtual void setNode(v3POS p, MapNode & n) + virtual void setNode(v3pos_t p, MapNode & n) { if(isValidPosition(p) == false) throw InvalidPositionException(); @@ -402,8 +402,8 @@ struct TestMapBlock: public TestBase { TC parent; - MapBlock b(&parent, v3POS(1,1,1)); - v3POS relpos(MAP_BLOCKSIZE, MAP_BLOCKSIZE, MAP_BLOCKSIZE); + MapBlock b(&parent, v3pos_t(1,1,1)); + v3pos_t relpos(MAP_BLOCKSIZE, MAP_BLOCKSIZE, MAP_BLOCKSIZE); UASSERT(b.getPosRelative() == relpos); @@ -414,18 +414,18 @@ struct TestMapBlock: public TestBase UASSERT(b.getBox().MinEdge.Z == MAP_BLOCKSIZE); UASSERT(b.getBox().MaxEdge.Z == MAP_BLOCKSIZE*2-1); - UASSERT(b.isValidPosition(v3POS(0,0,0)) == true); - UASSERT(b.isValidPosition(v3POS(-1,0,0)) == false); - UASSERT(b.isValidPosition(v3POS(-1,-142,-2341)) == false); - UASSERT(b.isValidPosition(v3POS(-124,142,2341)) == false); - UASSERT(b.isValidPosition(v3POS(MAP_BLOCKSIZE-1,MAP_BLOCKSIZE-1,MAP_BLOCKSIZE-1)) == true); - UASSERT(b.isValidPosition(v3POS(MAP_BLOCKSIZE-1,MAP_BLOCKSIZE,MAP_BLOCKSIZE-1)) == false); + UASSERT(b.isValidPosition(v3pos_t(0,0,0)) == true); + UASSERT(b.isValidPosition(v3pos_t(-1,0,0)) == false); + UASSERT(b.isValidPosition(v3pos_t(-1,-142,-2341)) == false); + UASSERT(b.isValidPosition(v3pos_t(-124,142,2341)) == false); + UASSERT(b.isValidPosition(v3pos_t(MAP_BLOCKSIZE-1,MAP_BLOCKSIZE-1,MAP_BLOCKSIZE-1)) == true); + UASSERT(b.isValidPosition(v3pos_t(MAP_BLOCKSIZE-1,MAP_BLOCKSIZE,MAP_BLOCKSIZE-1)) == false); /* TODO: this method should probably be removed if the block size isn't going to be set variable */ - /*UASSERT(b.getSizeNodes() == v3POS(MAP_BLOCKSIZE, + /*UASSERT(b.getSizeNodes() == v3pos_t(MAP_BLOCKSIZE, MAP_BLOCKSIZE, MAP_BLOCKSIZE));*/ // Changed flag should be initially set @@ -439,10 +439,10 @@ struct TestMapBlock: public TestBase for(u16 y=0; y light_sources; + core::map light_sources; // The bottom block is invalid, because we have a shadowing node UASSERT(b.propagateSunlight(light_sources) == false); - UASSERT(b.getNode(v3POS(1,4,0)).getLight(LIGHTBANK_DAY) == LIGHT_SUN); - UASSERT(b.getNode(v3POS(1,3,0)).getLight(LIGHTBANK_DAY) == LIGHT_SUN); - UASSERT(b.getNode(v3POS(1,2,0)).getLight(LIGHTBANK_DAY) == 0); - UASSERT(b.getNode(v3POS(1,1,0)).getLight(LIGHTBANK_DAY) == 0); - UASSERT(b.getNode(v3POS(1,0,0)).getLight(LIGHTBANK_DAY) == 0); - UASSERT(b.getNode(v3POS(1,2,3)).getLight(LIGHTBANK_DAY) == LIGHT_SUN); - UASSERT(b.getFaceLight2(1000, p, v3POS(0,1,0)) == LIGHT_SUN); - UASSERT(b.getFaceLight2(1000, p, v3POS(0,-1,0)) == 0); - UASSERT(b.getFaceLight2(0, p, v3POS(0,-1,0)) == 0); + UASSERT(b.getNode(v3pos_t(1,4,0)).getLight(LIGHTBANK_DAY) == LIGHT_SUN); + UASSERT(b.getNode(v3pos_t(1,3,0)).getLight(LIGHTBANK_DAY) == LIGHT_SUN); + UASSERT(b.getNode(v3pos_t(1,2,0)).getLight(LIGHTBANK_DAY) == 0); + UASSERT(b.getNode(v3pos_t(1,1,0)).getLight(LIGHTBANK_DAY) == 0); + UASSERT(b.getNode(v3pos_t(1,0,0)).getLight(LIGHTBANK_DAY) == 0); + UASSERT(b.getNode(v3pos_t(1,2,3)).getLight(LIGHTBANK_DAY) == LIGHT_SUN); + UASSERT(b.getFaceLight2(1000, p, v3pos_t(0,1,0)) == LIGHT_SUN); + UASSERT(b.getFaceLight2(1000, p, v3pos_t(0,-1,0)) == 0); + UASSERT(b.getFaceLight2(0, p, v3pos_t(0,-1,0)) == 0); // According to MapBlock::getFaceLight, // The face on the z+ side should have double-diminished light - //UASSERT(b.getFaceLight(p, v3POS(0,0,1)) == diminish_light(diminish_light(LIGHT_MAX))); + //UASSERT(b.getFaceLight(p, v3pos_t(0,0,1)) == diminish_light(diminish_light(LIGHT_MAX))); // The face on the z+ side should have diminished light - UASSERT(b.getFaceLight2(1000, p, v3POS(0,0,1)) == diminish_light(LIGHT_MAX)); + UASSERT(b.getFaceLight2(1000, p, v3pos_t(0,0,1)) == diminish_light(LIGHT_MAX)); } /* Check how the block handles being in between blocks with some non-sunlight @@ -556,14 +556,14 @@ struct TestMapBlock: public TestBase parent.position_valid = true; b.setIsUnderground(true); parent.node.setLight(LIGHTBANK_DAY, LIGHT_MAX/2); - core::map light_sources; + core::map light_sources; // The block below should be valid because there shouldn't be // sunlight in there either UASSERT(b.propagateSunlight(light_sources, true) == true); // Should not touch nodes that are not affected (that is, all of them) - //UASSERT(b.getNode(v3POS(1,2,3)).getLight() == LIGHT_SUN); + //UASSERT(b.getNode(v3pos_t(1,2,3)).getLight() == LIGHT_SUN); // Should set light of non-sunlighted blocks to 0. - UASSERT(b.getNode(v3POS(1,2,3)).getLight(LIGHTBANK_DAY) == 0); + UASSERT(b.getNode(v3pos_t(1,2,3)).getLight(LIGHTBANK_DAY) == 0); } /* Set up a situation where: @@ -583,7 +583,7 @@ struct TestMapBlock: public TestBase MapNode n; n.setContent(CONTENT_AIR); n.setLight(LIGHTBANK_DAY, 0); - b.setNode(v3POS(x,y,z), n); + b.setNode(v3pos_t(x,y,z), n); } } } @@ -593,11 +593,11 @@ struct TestMapBlock: public TestBase for(u16 x=0; x light_sources; + core::map light_sources; // Bottom block is not valid UASSERT(b.propagateSunlight(light_sources) == false); } @@ -618,19 +618,19 @@ struct TestMapSector: public TestBase position_valid = true; } - virtual bool isValidPosition(v3POS p) + virtual bool isValidPosition(v3pos_t p) { return position_valid; } - virtual MapNode getNode(v3POS p) + virtual MapNode getNode(v3pos_t p) { if(position_valid == false) throw InvalidPositionException(); return node; } - virtual void setNode(v3POS p, MapNode & n) + virtual void setNode(v3pos_t p, MapNode & n) { if(position_valid == false) throw InvalidPositionException(); @@ -648,7 +648,7 @@ struct TestMapSector: public TestBase parent.position_valid = false; // Create one with no heightmaps - ServerMapSector sector(&parent, v2POS(1,1)); + ServerMapSector sector(&parent, v2pos_t(1,1)); UASSERT(sector.getBlockNoCreateNoEx(0) == nullptr); UASSERT(sector.getBlockNoCreateNoEx(1) == nullptr); diff --git a/src/unittest/test_areastore.cpp b/src/unittest/test_areastore.cpp index 7d09e56e5c..f4a3408d59 100644 --- a/src/unittest/test_areastore.cpp +++ b/src/unittest/test_areastore.cpp @@ -64,9 +64,9 @@ void TestAreaStore::testSpatialStore() void TestAreaStore::genericStoreTest(AreaStore *store) { - Area a(v3POS(-10, -3, 5), v3POS(0, 29, 7)); - Area b(v3POS(-5, -2, 5), v3POS(0, 28, 6)); - Area c(v3POS(-7, -3, 6), v3POS(-1, 27, 7)); + Area a(v3pos_t(-10, -3, 5), v3pos_t(0, 29, 7)); + Area b(v3pos_t(-5, -2, 5), v3pos_t(0, 28, 6)); + Area c(v3pos_t(-7, -3, 6), v3pos_t(-1, 27, 7)); std::vector res; UASSERTEQ(size_t, store->size(), 0); @@ -76,34 +76,34 @@ void TestAreaStore::genericStoreTest(AreaStore *store) store->insertArea(&c); UASSERTEQ(size_t, store->size(), 3); - store->getAreasForPos(&res, v3POS(-1, 0, 6)); + store->getAreasForPos(&res, v3pos_t(-1, 0, 6)); UASSERTEQ(size_t, res.size(), 3); res.clear(); - store->getAreasForPos(&res, v3POS(0, 0, 7)); + store->getAreasForPos(&res, v3pos_t(0, 0, 7)); UASSERTEQ(size_t, res.size(), 1); res.clear(); store->removeArea(a.id); - store->getAreasForPos(&res, v3POS(0, 0, 7)); + store->getAreasForPos(&res, v3pos_t(0, 0, 7)); UASSERTEQ(size_t, res.size(), 0); res.clear(); store->insertArea(&a); - store->getAreasForPos(&res, v3POS(0, 0, 7)); + store->getAreasForPos(&res, v3pos_t(0, 0, 7)); UASSERTEQ(size_t, res.size(), 1); res.clear(); - store->getAreasInArea(&res, v3POS(-10, -3, 5), v3POS(0, 29, 7), false); + store->getAreasInArea(&res, v3pos_t(-10, -3, 5), v3pos_t(0, 29, 7), false); UASSERTEQ(size_t, res.size(), 3); res.clear(); - store->getAreasInArea(&res, v3POS(-100, 0, 6), v3POS(200, 0, 6), false); + store->getAreasInArea(&res, v3pos_t(-100, 0, 6), v3pos_t(200, 0, 6), false); UASSERTEQ(size_t, res.size(), 0); res.clear(); - store->getAreasInArea(&res, v3POS(-100, 0, 6), v3POS(200, 0, 6), true); + store->getAreasInArea(&res, v3pos_t(-100, 0, 6), v3pos_t(200, 0, 6), true); UASSERTEQ(size_t, res.size(), 3); res.clear(); @@ -111,11 +111,11 @@ void TestAreaStore::genericStoreTest(AreaStore *store) store->removeArea(b.id); store->removeArea(c.id); - Area d(v3POS(-100, -300, -200), v3POS(-50, -200, -100)); + Area d(v3pos_t(-100, -300, -200), v3pos_t(-50, -200, -100)); d.data = "Hi!"; store->insertArea(&d); - store->getAreasForPos(&res, v3POS(-75, -250, -150)); + store->getAreasForPos(&res, v3pos_t(-75, -250, -150)); UASSERTEQ(size_t, res.size(), 1); UASSERTEQ(u16, res[0]->data.size(), 3); UASSERT(strncmp(res[0]->data.c_str(), "Hi!", 3) == 0); @@ -128,11 +128,11 @@ void TestAreaStore::testSerialization() { VectorAreaStore store; - Area a(v3POS(-1, 0, 1), v3POS(0, 1, 2)); + Area a(v3pos_t(-1, 0, 1), v3pos_t(0, 1, 2)); a.data = "Area AA"; store.insertArea(&a); - Area b(v3POS(123, 456, 789), v3POS(32000, 100, 10)); + Area b(v3pos_t(123, 456, 789), v3pos_t(32000, 100, 10)); b.data = "Area BB"; store.insertArea(&b); @@ -183,7 +183,7 @@ void TestAreaStore::testSerialization() // But existing IDs are overridden UASSERTEQ(size_t, store.size(), 2); - Area c(v3POS(33, -2, -6), v3POS(4, 77, -76)); + Area c(v3pos_t(33, -2, -6), v3pos_t(4, 77, -76)); c.data = "Area CC"; store.insertArea(&c); diff --git a/src/unittest/test_voxelalgorithms.cpp b/src/unittest/test_voxelalgorithms.cpp index 28321f5fcb..cbc6b4db7a 100644 --- a/src/unittest/test_voxelalgorithms.cpp +++ b/src/unittest/test_voxelalgorithms.cpp @@ -67,21 +67,21 @@ void TestVoxelAlgorithms::testVoxelLineIterator(const NodeDefManager *ndef) voxalgo::VoxelLineIterator iterator(l.start, l.getVector()); //Test the first voxel - v3POS start_voxel = floatToInt(l.start, 1); + v3pos_t start_voxel = floatToInt(l.start, 1); UASSERT(iterator.m_current_node_pos == start_voxel); // Values for testing - v3POS end_voxel = floatToInt(l.end, 1); - v3POS voxel_vector = end_voxel - start_voxel; + v3pos_t end_voxel = floatToInt(l.end, 1); + v3pos_t voxel_vector = end_voxel - start_voxel; int nodecount = abs(voxel_vector.X) + abs(voxel_vector.Y) + abs(voxel_vector.Z); int actual_nodecount = 0; - v3POS old_voxel = iterator.m_current_node_pos; + v3pos_t old_voxel = iterator.m_current_node_pos; while (iterator.hasNext()) { iterator.next(); actual_nodecount++; - v3POS new_voxel = iterator.m_current_node_pos; + v3pos_t new_voxel = iterator.m_current_node_pos; // This must be a neighbor of the old voxel UASSERTEQ(f32, (new_voxel - old_voxel).getLengthSQ(), 1); // The line must intersect with the voxel diff --git a/src/unittest/test_voxelarea.cpp b/src/unittest/test_voxelarea.cpp index b046dfa13d..568e519d35 100644 --- a/src/unittest/test_voxelarea.cpp +++ b/src/unittest/test_voxelarea.cpp @@ -46,14 +46,14 @@ class TestVoxelArea : public TestBase void test_index_xyz_xz_neg(); void test_index_xyz_yz_neg(); void test_index_xyz_all_neg(); - void test_index_v3POS_all_pos(); - void test_index_v3POS_x_neg(); - void test_index_v3POS_y_neg(); - void test_index_v3POS_z_neg(); - void test_index_v3POS_xy_neg(); - void test_index_v3POS_xz_neg(); - void test_index_v3POS_yz_neg(); - void test_index_v3POS_all_neg(); + void test_index_v3pos_t_all_pos(); + void test_index_v3pos_t_x_neg(); + void test_index_v3pos_t_y_neg(); + void test_index_v3pos_t_z_neg(); + void test_index_v3pos_t_xy_neg(); + void test_index_v3pos_t_xz_neg(); + void test_index_v3pos_t_yz_neg(); + void test_index_v3pos_t_all_neg(); void test_add_x(); void test_add_y(); void test_add_z(); @@ -82,14 +82,14 @@ void TestVoxelArea::runTests(IGameDef *gamedef) TEST(test_index_xyz_xz_neg); TEST(test_index_xyz_yz_neg); TEST(test_index_xyz_all_neg); - TEST(test_index_v3POS_all_pos); - TEST(test_index_v3POS_x_neg); - TEST(test_index_v3POS_y_neg); - TEST(test_index_v3POS_z_neg); - TEST(test_index_v3POS_xy_neg); - TEST(test_index_v3POS_xz_neg); - TEST(test_index_v3POS_yz_neg); - TEST(test_index_v3POS_all_neg); + TEST(test_index_v3pos_t_all_pos); + TEST(test_index_v3pos_t_x_neg); + TEST(test_index_v3pos_t_y_neg); + TEST(test_index_v3pos_t_z_neg); + TEST(test_index_v3pos_t_xy_neg); + TEST(test_index_v3pos_t_xz_neg); + TEST(test_index_v3pos_t_yz_neg); + TEST(test_index_v3pos_t_all_neg); TEST(test_add_x); TEST(test_add_y); TEST(test_add_z); @@ -98,81 +98,81 @@ void TestVoxelArea::runTests(IGameDef *gamedef) void TestVoxelArea::test_addarea() { - VoxelArea v1(v3POS(-1447, 8854, -875), v3POS(-147, -9547, 669)); - VoxelArea v2(v3POS(-887, 4445, -5478), v3POS(447, -8779, 4778)); + VoxelArea v1(v3pos_t(-1447, 8854, -875), v3pos_t(-147, -9547, 669)); + VoxelArea v2(v3pos_t(-887, 4445, -5478), v3pos_t(447, -8779, 4778)); v1.addArea(v2); - UASSERT(v1.MinEdge == v3POS(-1447, 4445, -5478)); - UASSERT(v1.MaxEdge == v3POS(447, -8779, 4778)); + UASSERT(v1.MinEdge == v3pos_t(-1447, 4445, -5478)); + UASSERT(v1.MaxEdge == v3pos_t(447, -8779, 4778)); } void TestVoxelArea::test_pad() { - VoxelArea v1(v3POS(-1447, 8854, -875), v3POS(-147, -9547, 669)); - v1.pad(v3POS(100, 200, 300)); + VoxelArea v1(v3pos_t(-1447, 8854, -875), v3pos_t(-147, -9547, 669)); + v1.pad(v3pos_t(100, 200, 300)); - UASSERT(v1.MinEdge == v3POS(-1547, 8654, -1175)); - UASSERT(v1.MaxEdge == v3POS(-47, -9347, 969)); + UASSERT(v1.MinEdge == v3pos_t(-1547, 8654, -1175)); + UASSERT(v1.MaxEdge == v3pos_t(-47, -9347, 969)); } void TestVoxelArea::test_extent() { - VoxelArea v1(v3POS(-1337, -547, -789), v3POS(-147, 447, 669)); - UASSERT(v1.getExtent() == v3POS(1191, 995, 1459)); + VoxelArea v1(v3pos_t(-1337, -547, -789), v3pos_t(-147, 447, 669)); + UASSERT(v1.getExtent() == v3pos_t(1191, 995, 1459)); - VoxelArea v2(v3POS(32493, -32507, 32753), v3POS(32508, -32492, 32768)); - UASSERT(v2.getExtent() == v3POS(16, 16, 16)); + VoxelArea v2(v3pos_t(32493, -32507, 32753), v3pos_t(32508, -32492, 32768)); + UASSERT(v2.getExtent() == v3pos_t(16, 16, 16)); } void TestVoxelArea::test_volume() { - VoxelArea v1(v3POS(-1337, -547, -789), v3POS(-147, 447, 669)); + VoxelArea v1(v3pos_t(-1337, -547, -789), v3pos_t(-147, 447, 669)); UASSERTEQ(s32, v1.getVolume(), 1728980655); - VoxelArea v2(v3POS(32493, -32507, 32753), v3POS(32508, -32492, 32768)); + VoxelArea v2(v3pos_t(32493, -32507, 32753), v3pos_t(32508, -32492, 32768)); UASSERTEQ(s32, v2.getVolume(), 4096); } void TestVoxelArea::test_contains_voxelarea() { - VoxelArea v1(v3POS(-1337, -9547, -789), v3POS(-147, 750, 669)); - UASSERTEQ(bool, v1.contains(VoxelArea(v3POS(-200, 10, 10), v3POS(-150, 10, 10))), + VoxelArea v1(v3pos_t(-1337, -9547, -789), v3pos_t(-147, 750, 669)); + UASSERTEQ(bool, v1.contains(VoxelArea(v3pos_t(-200, 10, 10), v3pos_t(-150, 10, 10))), true); - UASSERTEQ(bool, v1.contains(VoxelArea(v3POS(-2550, 10, 10), v3POS(10, 10, 10))), + UASSERTEQ(bool, v1.contains(VoxelArea(v3pos_t(-2550, 10, 10), v3pos_t(10, 10, 10))), false); - UASSERTEQ(bool, v1.contains(VoxelArea(v3POS(-10, 10, 10), v3POS(3500, 10, 10))), + UASSERTEQ(bool, v1.contains(VoxelArea(v3pos_t(-10, 10, 10), v3pos_t(3500, 10, 10))), false); UASSERTEQ(bool, v1.contains(VoxelArea( - v3POS(-800, -400, 669), v3POS(-500, 200, 669))), + v3pos_t(-800, -400, 669), v3pos_t(-500, 200, 669))), true); UASSERTEQ(bool, v1.contains(VoxelArea( - v3POS(-800, -400, 670), v3POS(-500, 200, 670))), + v3pos_t(-800, -400, 670), v3pos_t(-500, 200, 670))), false); } void TestVoxelArea::test_contains_point() { - VoxelArea v1(v3POS(-1337, -9547, -789), v3POS(-147, 750, 669)); - UASSERTEQ(bool, v1.contains(v3POS(-200, 10, 10)), true); - UASSERTEQ(bool, v1.contains(v3POS(-10000, 10, 10)), false); - UASSERTEQ(bool, v1.contains(v3POS(-100, 10000, 10)), false); - UASSERTEQ(bool, v1.contains(v3POS(-100, 100, 10000)), false); - UASSERTEQ(bool, v1.contains(v3POS(-100, 100, -10000)), false); - UASSERTEQ(bool, v1.contains(v3POS(10000, 100, 10)), false); + VoxelArea v1(v3pos_t(-1337, -9547, -789), v3pos_t(-147, 750, 669)); + UASSERTEQ(bool, v1.contains(v3pos_t(-200, 10, 10)), true); + UASSERTEQ(bool, v1.contains(v3pos_t(-10000, 10, 10)), false); + UASSERTEQ(bool, v1.contains(v3pos_t(-100, 10000, 10)), false); + UASSERTEQ(bool, v1.contains(v3pos_t(-100, 100, 10000)), false); + UASSERTEQ(bool, v1.contains(v3pos_t(-100, 100, -10000)), false); + UASSERTEQ(bool, v1.contains(v3pos_t(10000, 100, 10)), false); } void TestVoxelArea::test_contains_i() { - VoxelArea v1(v3POS(-1337, -9547, -789), v3POS(-147, 750, 669)); + VoxelArea v1(v3pos_t(-1337, -9547, -789), v3pos_t(-147, 750, 669)); UASSERTEQ(bool, v1.contains(10), true); UASSERTEQ(bool, v1.contains(v1.getVolume()), false); UASSERTEQ(bool, v1.contains(v1.getVolume() - 1), true); UASSERTEQ(bool, v1.contains(v1.getVolume() + 1), false); UASSERTEQ(bool, v1.contains(-1), false) - VoxelArea v2(v3POS(10, 10, 10), v3POS(30, 30, 30)); + VoxelArea v2(v3pos_t(10, 10, 10), v3pos_t(30, 30, 30)); UASSERTEQ(bool, v2.contains(10), true); UASSERTEQ(bool, v2.contains(0), true); UASSERTEQ(bool, v2.contains(-1), false); @@ -180,34 +180,34 @@ void TestVoxelArea::test_contains_i() void TestVoxelArea::test_equal() { - VoxelArea v1(v3POS(-1337, -9547, -789), v3POS(-147, 750, 669)); - UASSERTEQ(bool, v1 == VoxelArea(v3POS(-1337, -9547, -789), v3POS(-147, 750, 669)), + VoxelArea v1(v3pos_t(-1337, -9547, -789), v3pos_t(-147, 750, 669)); + UASSERTEQ(bool, v1 == VoxelArea(v3pos_t(-1337, -9547, -789), v3pos_t(-147, 750, 669)), true); - UASSERTEQ(bool, v1 == VoxelArea(v3POS(0, 0, 0), v3POS(-147, 750, 669)), false); - UASSERTEQ(bool, v1 == VoxelArea(v3POS(0, 0, 0), v3POS(-147, 750, 669)), false); - UASSERTEQ(bool, v1 == VoxelArea(v3POS(0, 0, 0), v3POS(0, 0, 0)), false); + UASSERTEQ(bool, v1 == VoxelArea(v3pos_t(0, 0, 0), v3pos_t(-147, 750, 669)), false); + UASSERTEQ(bool, v1 == VoxelArea(v3pos_t(0, 0, 0), v3pos_t(-147, 750, 669)), false); + UASSERTEQ(bool, v1 == VoxelArea(v3pos_t(0, 0, 0), v3pos_t(0, 0, 0)), false); } void TestVoxelArea::test_plus() { - VoxelArea v1(v3POS(-10, -10, -10), v3POS(100, 100, 100)); - UASSERT(v1 + v3POS(10, 0, 0) == - VoxelArea(v3POS(0, -10, -10), v3POS(110, 100, 100))); - UASSERT(v1 + v3POS(10, -10, 0) == - VoxelArea(v3POS(0, -20, -10), v3POS(110, 90, 100))); - UASSERT(v1 + v3POS(0, 0, 35) == - VoxelArea(v3POS(-10, -10, 25), v3POS(100, 100, 135))); + VoxelArea v1(v3pos_t(-10, -10, -10), v3pos_t(100, 100, 100)); + UASSERT(v1 + v3pos_t(10, 0, 0) == + VoxelArea(v3pos_t(0, -10, -10), v3pos_t(110, 100, 100))); + UASSERT(v1 + v3pos_t(10, -10, 0) == + VoxelArea(v3pos_t(0, -20, -10), v3pos_t(110, 90, 100))); + UASSERT(v1 + v3pos_t(0, 0, 35) == + VoxelArea(v3pos_t(-10, -10, 25), v3pos_t(100, 100, 135))); } void TestVoxelArea::test_minor() { - VoxelArea v1(v3POS(-10, -10, -10), v3POS(100, 100, 100)); - UASSERT(v1 - v3POS(10, 0, 0) == - VoxelArea(v3POS(-20, -10, -10), v3POS(90, 100, 100))); - UASSERT(v1 - v3POS(10, -10, 0) == - VoxelArea(v3POS(-20, 0, -10), v3POS(90, 110, 100))); - UASSERT(v1 - v3POS(0, 0, 35) == - VoxelArea(v3POS(-10, -10, -45), v3POS(100, 100, 65))); + VoxelArea v1(v3pos_t(-10, -10, -10), v3pos_t(100, 100, 100)); + UASSERT(v1 - v3pos_t(10, 0, 0) == + VoxelArea(v3pos_t(-20, -10, -10), v3pos_t(90, 100, 100))); + UASSERT(v1 - v3pos_t(10, -10, 0) == + VoxelArea(v3pos_t(-20, 0, -10), v3pos_t(90, 110, 100))); + UASSERT(v1 - v3pos_t(0, 0, 35) == + VoxelArea(v3pos_t(-10, -10, -45), v3pos_t(100, 100, 65))); } void TestVoxelArea::test_index_xyz_all_pos() @@ -215,7 +215,7 @@ void TestVoxelArea::test_index_xyz_all_pos() VoxelArea v1; UASSERTEQ(s32, v1.index(156, 25, 236), 155); - VoxelArea v2(v3POS(756, 8854, -875), v3POS(-147, -9547, 669)); + VoxelArea v2(v3pos_t(756, 8854, -875), v3pos_t(-147, -9547, 669)); UASSERTEQ(s32, v2.index(156, 25, 236), 1267138774); } @@ -224,7 +224,7 @@ void TestVoxelArea::test_index_xyz_x_neg() VoxelArea v1; UASSERTEQ(s32, v1.index(-147, 25, 366), -148); - VoxelArea v2(v3POS(756, 8854, -875), v3POS(-147, -9547, 669)); + VoxelArea v2(v3pos_t(756, 8854, -875), v3pos_t(-147, -9547, 669)); UASSERTEQ(s32, v2.index(-147, 25, 366), -870244825); } @@ -233,7 +233,7 @@ void TestVoxelArea::test_index_xyz_y_neg() VoxelArea v1; UASSERTEQ(s32, v1.index(247, -269, 100), 246); - VoxelArea v2(v3POS(756, 8854, -875), v3POS(-147, -9547, 669)); + VoxelArea v2(v3pos_t(756, 8854, -875), v3pos_t(-147, -9547, 669)); UASSERTEQ(s32, v2.index(247, -269, 100), -989760747); } @@ -242,7 +242,7 @@ void TestVoxelArea::test_index_xyz_z_neg() VoxelArea v1; UASSERTEQ(s32, v1.index(244, 336, -887), 243); - VoxelArea v2(v3POS(756, 8854, -875), v3POS(-147, -9547, 669)); + VoxelArea v2(v3pos_t(756, 8854, -875), v3pos_t(-147, -9547, 669)); UASSERTEQ(s32, v2.index(244, 336, -887), -191478876); } @@ -251,7 +251,7 @@ void TestVoxelArea::test_index_xyz_xy_neg() VoxelArea v1; UASSERTEQ(s32, v1.index(-365, -47, 6978), -366); - VoxelArea v2(v3POS(756, 8854, -875), v3POS(-147, -9547, 669)); + VoxelArea v2(v3pos_t(756, 8854, -875), v3pos_t(-147, -9547, 669)); UASSERTEQ(s32, v2.index(-365, -47, 6978), 1493679101); } @@ -260,7 +260,7 @@ void TestVoxelArea::test_index_xyz_yz_neg() VoxelArea v1; UASSERTEQ(s32, v1.index(66, -58, -789), 65); - VoxelArea v2(v3POS(756, 8854, -875), v3POS(-147, -9547, 669)); + VoxelArea v2(v3pos_t(756, 8854, -875), v3pos_t(-147, -9547, 669)); UASSERTEQ(s32, v2.index(66, -58, -789), 1435362734); } @@ -269,7 +269,7 @@ void TestVoxelArea::test_index_xyz_xz_neg() VoxelArea v1; UASSERTEQ(s32, v1.index(-36, 589, -992), -37); - VoxelArea v2(v3POS(756, 8854, -875), v3POS(-147, -9547, 669)); + VoxelArea v2(v3pos_t(756, 8854, -875), v3pos_t(-147, -9547, 669)); UASSERTEQ(s32, v2.index(-36, 589, -992), -1934371362); } @@ -278,85 +278,85 @@ void TestVoxelArea::test_index_xyz_all_neg() VoxelArea v1; UASSERTEQ(s32, v1.index(-88, -99, -1474), -89); - VoxelArea v2(v3POS(756, 8854, -875), v3POS(-147, -9547, 669)); + VoxelArea v2(v3pos_t(756, 8854, -875), v3pos_t(-147, -9547, 669)); UASSERTEQ(s32, v2.index(-88, -99, -1474), -1343473846); } -void TestVoxelArea::test_index_v3POS_all_pos() +void TestVoxelArea::test_index_v3pos_t_all_pos() { VoxelArea v1; - UASSERTEQ(s32, v1.index(v3POS(156, 25, 236)), 155); + UASSERTEQ(s32, v1.index(v3pos_t(156, 25, 236)), 155); - VoxelArea v2(v3POS(756, 8854, -875), v3POS(-147, -9547, 669)); - UASSERTEQ(s32, v2.index(v3POS(156, 25, 236)), 1267138774); + VoxelArea v2(v3pos_t(756, 8854, -875), v3pos_t(-147, -9547, 669)); + UASSERTEQ(s32, v2.index(v3pos_t(156, 25, 236)), 1267138774); } -void TestVoxelArea::test_index_v3POS_x_neg() +void TestVoxelArea::test_index_v3pos_t_x_neg() { VoxelArea v1; - UASSERTEQ(s32, v1.index(v3POS(-147, 25, 366)), -148); + UASSERTEQ(s32, v1.index(v3pos_t(-147, 25, 366)), -148); - VoxelArea v2(v3POS(756, 8854, -875), v3POS(-147, -9547, 669)); - UASSERTEQ(s32, v2.index(v3POS(-147, 25, 366)), -870244825); + VoxelArea v2(v3pos_t(756, 8854, -875), v3pos_t(-147, -9547, 669)); + UASSERTEQ(s32, v2.index(v3pos_t(-147, 25, 366)), -870244825); } -void TestVoxelArea::test_index_v3POS_y_neg() +void TestVoxelArea::test_index_v3pos_t_y_neg() { VoxelArea v1; - UASSERTEQ(s32, v1.index(v3POS(247, -269, 100)), 246); + UASSERTEQ(s32, v1.index(v3pos_t(247, -269, 100)), 246); - VoxelArea v2(v3POS(756, 8854, -875), v3POS(-147, -9547, 669)); - UASSERTEQ(s32, v2.index(v3POS(247, -269, 100)), -989760747); + VoxelArea v2(v3pos_t(756, 8854, -875), v3pos_t(-147, -9547, 669)); + UASSERTEQ(s32, v2.index(v3pos_t(247, -269, 100)), -989760747); } -void TestVoxelArea::test_index_v3POS_z_neg() +void TestVoxelArea::test_index_v3pos_t_z_neg() { VoxelArea v1; - UASSERTEQ(s32, v1.index(v3POS(244, 336, -887)), 243); + UASSERTEQ(s32, v1.index(v3pos_t(244, 336, -887)), 243); - VoxelArea v2(v3POS(756, 8854, -875), v3POS(-147, -9547, 669)); - UASSERTEQ(s32, v2.index(v3POS(244, 336, -887)), -191478876); + VoxelArea v2(v3pos_t(756, 8854, -875), v3pos_t(-147, -9547, 669)); + UASSERTEQ(s32, v2.index(v3pos_t(244, 336, -887)), -191478876); } -void TestVoxelArea::test_index_v3POS_xy_neg() +void TestVoxelArea::test_index_v3pos_t_xy_neg() { VoxelArea v1; - UASSERTEQ(s32, v1.index(v3POS(-365, -47, 6978)), -366); + UASSERTEQ(s32, v1.index(v3pos_t(-365, -47, 6978)), -366); - VoxelArea v2(v3POS(756, 8854, -875), v3POS(-147, -9547, 669)); - UASSERTEQ(s32, v2.index(v3POS(-365, -47, 6978)), 1493679101); + VoxelArea v2(v3pos_t(756, 8854, -875), v3pos_t(-147, -9547, 669)); + UASSERTEQ(s32, v2.index(v3pos_t(-365, -47, 6978)), 1493679101); } -void TestVoxelArea::test_index_v3POS_yz_neg() +void TestVoxelArea::test_index_v3pos_t_yz_neg() { VoxelArea v1; - UASSERTEQ(s32, v1.index(v3POS(66, -58, -789)), 65); + UASSERTEQ(s32, v1.index(v3pos_t(66, -58, -789)), 65); - VoxelArea v2(v3POS(756, 8854, -875), v3POS(-147, -9547, 669)); - UASSERTEQ(s32, v2.index(v3POS(66, -58, -789)), 1435362734); + VoxelArea v2(v3pos_t(756, 8854, -875), v3pos_t(-147, -9547, 669)); + UASSERTEQ(s32, v2.index(v3pos_t(66, -58, -789)), 1435362734); } -void TestVoxelArea::test_index_v3POS_xz_neg() +void TestVoxelArea::test_index_v3pos_t_xz_neg() { VoxelArea v1; - UASSERTEQ(s32, v1.index(v3POS(-36, 589, -992)), -37); + UASSERTEQ(s32, v1.index(v3pos_t(-36, 589, -992)), -37); - VoxelArea v2(v3POS(756, 8854, -875), v3POS(-147, -9547, 669)); - UASSERTEQ(s32, v2.index(v3POS(-36, 589, -992)), -1934371362); + VoxelArea v2(v3pos_t(756, 8854, -875), v3pos_t(-147, -9547, 669)); + UASSERTEQ(s32, v2.index(v3pos_t(-36, 589, -992)), -1934371362); } -void TestVoxelArea::test_index_v3POS_all_neg() +void TestVoxelArea::test_index_v3pos_t_all_neg() { VoxelArea v1; - UASSERTEQ(s32, v1.index(v3POS(-88, -99, -1474)), -89); + UASSERTEQ(s32, v1.index(v3pos_t(-88, -99, -1474)), -89); - VoxelArea v2(v3POS(756, 8854, -875), v3POS(-147, -9547, 669)); - UASSERTEQ(s32, v2.index(v3POS(-88, -99, -1474)), -1343473846); + VoxelArea v2(v3pos_t(756, 8854, -875), v3pos_t(-147, -9547, 669)); + UASSERTEQ(s32, v2.index(v3pos_t(-88, -99, -1474)), -1343473846); } void TestVoxelArea::test_add_x() { - v3POS extent; + v3pos_t extent; u32 i = 4; VoxelArea::add_x(extent, i, 8); UASSERTEQ(u32, i, 12) @@ -364,7 +364,7 @@ void TestVoxelArea::test_add_x() void TestVoxelArea::test_add_y() { - v3POS extent(740, 16, 87); + v3pos_t extent(740, 16, 87); u32 i = 8; VoxelArea::add_y(extent, i, 88); UASSERTEQ(u32, i, 65128) @@ -372,7 +372,7 @@ void TestVoxelArea::test_add_y() void TestVoxelArea::test_add_z() { - v3POS extent(114, 80, 256); + v3pos_t extent(114, 80, 256); u32 i = 4; VoxelArea::add_z(extent, i, 8); UASSERTEQ(u32, i, 72964) @@ -380,8 +380,8 @@ void TestVoxelArea::test_add_z() void TestVoxelArea::test_add_p() { - v3POS extent(33, 14, 742); - v3POS a(15, 12, 369); + v3pos_t extent(33, 14, 742); + v3pos_t a(15, 12, 369); u32 i = 4; VoxelArea::add_p(extent, i, a); UASSERTEQ(u32, i, 170893) diff --git a/src/unittest/test_voxelmanipulator.cpp b/src/unittest/test_voxelmanipulator.cpp index 028119a57b..458713fc18 100644 --- a/src/unittest/test_voxelmanipulator.cpp +++ b/src/unittest/test_voxelmanipulator.cpp @@ -48,21 +48,21 @@ void TestVoxelManipulator::runTests(IGameDef *gamedef) void TestVoxelManipulator::testVoxelArea() { - VoxelArea a(v3POS(-1,-1,-1), v3POS(1,1,1)); + VoxelArea a(v3pos_t(-1,-1,-1), v3pos_t(1,1,1)); UASSERT(a.index(0,0,0) == 1*3*3 + 1*3 + 1); UASSERT(a.index(-1,-1,-1) == 0); - VoxelArea c(v3POS(-2,-2,-2), v3POS(2,2,2)); + VoxelArea c(v3pos_t(-2,-2,-2), v3pos_t(2,2,2)); // An area that is 1 bigger in x+ and z- - VoxelArea d(v3POS(-2,-2,-3), v3POS(3,2,2)); + VoxelArea d(v3pos_t(-2,-2,-3), v3pos_t(3,2,2)); std::list aa; d.diff(c, aa); // Correct results std::vector results; - results.emplace_back(v3POS(-2,-2,-3), v3POS(3,2,-3)); - results.emplace_back(v3POS(3,-2,-2), v3POS(3,2,2)); + results.emplace_back(v3pos_t(-2,-2,-3), v3pos_t(3,2,-3)); + results.emplace_back(v3pos_t(3,-2,-2), v3pos_t(3,2,2)); UASSERT(aa.size() == results.size()); @@ -87,22 +87,22 @@ void TestVoxelManipulator::testVoxelManipulator(const NodeDefManager *nodedef) v.print(infostream, nodedef); infostream << "*** Setting (-1,0,-1)=2 ***" << std::endl; - v.setNodeNoRef(v3POS(-1,0,-1), MapNode(t_CONTENT_GRASS)); + v.setNodeNoRef(v3pos_t(-1,0,-1), MapNode(t_CONTENT_GRASS)); v.print(infostream, nodedef); - UASSERT(v.getNode(v3POS(-1,0,-1)).getContent() == t_CONTENT_GRASS); + UASSERT(v.getNode(v3pos_t(-1,0,-1)).getContent() == t_CONTENT_GRASS); infostream << "*** Reading from inexistent (0,0,-1) ***" << std::endl; - EXCEPTION_CHECK(InvalidPositionException, v.getNode(v3POS(0,0,-1))); + EXCEPTION_CHECK(InvalidPositionException, v.getNode(v3pos_t(0,0,-1))); v.print(infostream, nodedef); infostream << "*** Adding area ***" << std::endl; - VoxelArea a(v3POS(-1,-1,-1), v3POS(1,1,1)); + VoxelArea a(v3pos_t(-1,-1,-1), v3pos_t(1,1,1)); v.addArea(a); v.print(infostream, nodedef); - UASSERT(v.getNode(v3POS(-1,0,-1)).getContent() == t_CONTENT_GRASS); - EXCEPTION_CHECK(InvalidPositionException, v.getNode(v3POS(0,1,1))); + UASSERT(v.getNode(v3pos_t(-1,0,-1)).getContent() == t_CONTENT_GRASS); + EXCEPTION_CHECK(InvalidPositionException, v.getNode(v3pos_t(0,1,1))); } diff --git a/src/util/areastore.cpp b/src/util/areastore.cpp index 801f633de8..91eb6439ae 100644 --- a/src/util/areastore.cpp +++ b/src/util/areastore.cpp @@ -144,14 +144,14 @@ void AreaStore::setCacheParams(bool enabled, u8 block_radius, size_t limit) invalidateCache(); } -void AreaStore::cacheMiss(void *data, const v3POS &mpos, std::vector *dest) +void AreaStore::cacheMiss(void *data, const v3pos_t &mpos, std::vector *dest) { AreaStore *as = (AreaStore *)data; u8 r = as->m_cacheblock_radius; // get the points at the edges of the mapblock - v3POS minedge(mpos.X * r, mpos.Y * r, mpos.Z * r); - v3POS maxedge( + v3pos_t minedge(mpos.X * r, mpos.Y * r, mpos.Z * r); + v3pos_t maxedge( minedge.X + r - 1, minedge.Y + r - 1, minedge.Z + r - 1); @@ -165,10 +165,10 @@ void AreaStore::cacheMiss(void *data, const v3POS &mpos, std::vector *de << ")" << std::endl; // */ } -void AreaStore::getAreasForPos(std::vector *result, v3POS pos) +void AreaStore::getAreasForPos(std::vector *result, v3pos_t pos) { if (m_cache_enabled) { - v3POS mblock = getContainerPos(pos, m_cacheblock_radius); + v3pos_t mblock = getContainerPos(pos, m_cacheblock_radius); const std::vector *pre_list = m_res_cache.lookupCache(mblock); size_t s_p_l = pre_list->size(); @@ -221,7 +221,7 @@ bool VectorAreaStore::removeArea(u32 id) return true; } -void VectorAreaStore::getAreasForPosImpl(std::vector *result, v3POS pos) +void VectorAreaStore::getAreasForPosImpl(std::vector *result, v3pos_t pos) { for (Area *area : m_areas) { if (AST_CONTAINS_PT(area, pos)) { @@ -231,7 +231,7 @@ void VectorAreaStore::getAreasForPosImpl(std::vector *result, v3POS pos) } void VectorAreaStore::getAreasInArea(std::vector *result, - v3POS minedge, v3POS maxedge, bool accept_overlap) + v3pos_t minedge, v3pos_t maxedge, bool accept_overlap) { for (Area *area : m_areas) { if (accept_overlap ? AST_AREAS_OVERLAP(minedge, maxedge, area) : @@ -243,8 +243,8 @@ void VectorAreaStore::getAreasInArea(std::vector *result, #if USE_SPATIAL -static inline SpatialIndex::Region get_spatial_region(const v3POS minedge, - const v3POS maxedge) +static inline SpatialIndex::Region get_spatial_region(const v3pos_t minedge, + const v3pos_t maxedge) { const double p_low[] = {(double)minedge.X, (double)minedge.Y, (double)minedge.Z}; @@ -253,7 +253,7 @@ static inline SpatialIndex::Region get_spatial_region(const v3POS minedge, return SpatialIndex::Region(p_low, p_high, 3); } -static inline SpatialIndex::Point get_spatial_point(const v3POS pos) +static inline SpatialIndex::Point get_spatial_point(const v3pos_t pos) { const double p[] = {(double)pos.X, (double)pos.Y, (double)pos.Z}; return SpatialIndex::Point(p, 3); @@ -287,14 +287,14 @@ bool SpatialAreaStore::removeArea(u32 id) } } -void SpatialAreaStore::getAreasForPosImpl(std::vector *result, v3POS pos) +void SpatialAreaStore::getAreasForPosImpl(std::vector *result, v3pos_t pos) { VectorResultVisitor visitor(result, this); m_tree->pointLocationQuery(get_spatial_point(pos), visitor); } void SpatialAreaStore::getAreasInArea(std::vector *result, - v3POS minedge, v3POS maxedge, bool accept_overlap) + v3pos_t minedge, v3pos_t maxedge, bool accept_overlap) { VectorResultVisitor visitor(result, this); if (accept_overlap) { diff --git a/src/util/areastore.h b/src/util/areastore.h index 75c4232c18..b51ca2b5e1 100644 --- a/src/util/areastore.h +++ b/src/util/areastore.h @@ -39,14 +39,14 @@ with this program; if not, write to the Free Software Foundation, Inc., struct Area { Area(u32 area_id) : id(area_id) {} - Area(const v3POS &mine, const v3POS &maxe, u32 area_id = U32_MAX) : + Area(const v3pos_t &mine, const v3pos_t &maxe, u32 area_id = U32_MAX) : id(area_id), minedge(mine), maxedge(maxe) { sortBoxVerticies(minedge, maxedge); } u32 id; - v3POS minedge, maxedge; + v3pos_t minedge, maxedge; std::string data; }; @@ -75,13 +75,13 @@ class AreaStore { /// Finds areas that the passed position is contained in. /// Stores output in passed vector. - void getAreasForPos(std::vector *result, v3POS pos); + void getAreasForPos(std::vector *result, v3pos_t pos); /// Finds areas that are completely contained inside the area defined /// by the passed edges. If @p accept_overlap is true this finds any /// areas that intersect with the passed area at any point. virtual void getAreasInArea(std::vector *result, - v3POS minedge, v3POS maxedge, bool accept_overlap) = 0; + v3pos_t minedge, v3pos_t maxedge, bool accept_overlap) = 0; /// Sets cache parameters. void setCacheParams(bool enabled, u8 block_radius, size_t limit); @@ -106,7 +106,7 @@ class AreaStore { /// Implementation of getAreasForPos. /// getAreasForPos calls this if the cache is disabled. - virtual void getAreasForPosImpl(std::vector *result, v3POS pos) = 0; + virtual void getAreasForPosImpl(std::vector *result, v3pos_t pos) = 0; /// Returns the next area ID and increments it. u32 getNextId() const; @@ -118,13 +118,13 @@ class AreaStore { private: /// Called by the cache when a value isn't found in the cache. - static void cacheMiss(void *data, const v3POS &mpos, std::vector *dest); + static void cacheMiss(void *data, const v3pos_t &mpos, std::vector *dest); bool m_cache_enabled = true; /// Range, in nodes, of the getAreasForPos cache. /// If you modify this, call invalidateCache() u8 m_cacheblock_radius = 64; - LRUCache > m_res_cache; + LRUCache > m_res_cache; }; @@ -134,10 +134,10 @@ class VectorAreaStore : public AreaStore { virtual bool insertArea(Area *a); virtual bool removeArea(u32 id); virtual void getAreasInArea(std::vector *result, - v3POS minedge, v3POS maxedge, bool accept_overlap); + v3pos_t minedge, v3pos_t maxedge, bool accept_overlap); protected: - virtual void getAreasForPosImpl(std::vector *result, v3POS pos); + virtual void getAreasForPosImpl(std::vector *result, v3pos_t pos); private: std::vector m_areas; @@ -154,10 +154,10 @@ class SpatialAreaStore : public AreaStore { virtual bool insertArea(Area *a); virtual bool removeArea(u32 id); virtual void getAreasInArea(std::vector *result, - v3POS minedge, v3POS maxedge, bool accept_overlap); + v3pos_t minedge, v3pos_t maxedge, bool accept_overlap); protected: - virtual void getAreasForPosImpl(std::vector *result, v3POS pos); + virtual void getAreasForPosImpl(std::vector *result, v3pos_t pos); private: SpatialIndex::ISpatialIndex *m_tree = nullptr; diff --git a/src/util/basic_macros.h b/src/util/basic_macros.h index f1b50421d8..57ba6750e0 100644 --- a/src/util/basic_macros.h +++ b/src/util/basic_macros.h @@ -50,7 +50,7 @@ with this program; if not, write to the Free Software Foundation, Inc., // Macros to facilitate writing position vectors to a stream // Usage: -// v3POS pos(1,2,3); +// v3pos_t pos(1,2,3); // mystream << "message " << PP(pos) << std::endl; #define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")" diff --git a/src/util/directiontables.cpp b/src/util/directiontables.cpp index 3aed88e1f2..0d6f7d0abc 100644 --- a/src/util/directiontables.cpp +++ b/src/util/directiontables.cpp @@ -19,95 +19,95 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "directiontables.h" -const v3POS g_6dirs[6] = +const v3pos_t g_6dirs[6] = { // +right, +top, +back - v3POS( 0, 0, 1), // back - v3POS( 0, 1, 0), // top - v3POS( 1, 0, 0), // right - v3POS( 0, 0,-1), // front - v3POS( 0,-1, 0), // bottom - v3POS(-1, 0, 0) // left + v3pos_t( 0, 0, 1), // back + v3pos_t( 0, 1, 0), // top + v3pos_t( 1, 0, 0), // right + v3pos_t( 0, 0,-1), // front + v3pos_t( 0,-1, 0), // bottom + v3pos_t(-1, 0, 0) // left }; -const v3POS g_7dirs[7] = +const v3pos_t g_7dirs[7] = { - v3POS(0,0,1), // back - v3POS(0,1,0), // top - v3POS(1,0,0), // right - v3POS(0,0,-1), // front - v3POS(0,-1,0), // bottom - v3POS(-1,0,0), // left - v3POS(0,0,0), // self + v3pos_t(0,0,1), // back + v3pos_t(0,1,0), // top + v3pos_t(1,0,0), // right + v3pos_t(0,0,-1), // front + v3pos_t(0,-1,0), // bottom + v3pos_t(-1,0,0), // left + v3pos_t(0,0,0), // self }; -const v3POS g_26dirs[26] = +const v3pos_t g_26dirs[26] = { // +right, +top, +back - v3POS( 0, 0, 1), // back - v3POS( 0, 1, 0), // top - v3POS( 1, 0, 0), // right - v3POS( 0, 0,-1), // front - v3POS( 0,-1, 0), // bottom - v3POS(-1, 0, 0), // left + v3pos_t( 0, 0, 1), // back + v3pos_t( 0, 1, 0), // top + v3pos_t( 1, 0, 0), // right + v3pos_t( 0, 0,-1), // front + v3pos_t( 0,-1, 0), // bottom + v3pos_t(-1, 0, 0), // left // 6 - v3POS(-1, 1, 0), // top left - v3POS( 1, 1, 0), // top right - v3POS( 0, 1, 1), // top back - v3POS( 0, 1,-1), // top front - v3POS(-1, 0, 1), // back left - v3POS( 1, 0, 1), // back right - v3POS(-1, 0,-1), // front left - v3POS( 1, 0,-1), // front right - v3POS(-1,-1, 0), // bottom left - v3POS( 1,-1, 0), // bottom right - v3POS( 0,-1, 1), // bottom back - v3POS( 0,-1,-1), // bottom front + v3pos_t(-1, 1, 0), // top left + v3pos_t( 1, 1, 0), // top right + v3pos_t( 0, 1, 1), // top back + v3pos_t( 0, 1,-1), // top front + v3pos_t(-1, 0, 1), // back left + v3pos_t( 1, 0, 1), // back right + v3pos_t(-1, 0,-1), // front left + v3pos_t( 1, 0,-1), // front right + v3pos_t(-1,-1, 0), // bottom left + v3pos_t( 1,-1, 0), // bottom right + v3pos_t( 0,-1, 1), // bottom back + v3pos_t( 0,-1,-1), // bottom front // 18 - v3POS(-1, 1, 1), // top back-left - v3POS( 1, 1, 1), // top back-right - v3POS(-1, 1,-1), // top front-left - v3POS( 1, 1,-1), // top front-right - v3POS(-1,-1, 1), // bottom back-left - v3POS( 1,-1, 1), // bottom back-right - v3POS(-1,-1,-1), // bottom front-left - v3POS( 1,-1,-1), // bottom front-right + v3pos_t(-1, 1, 1), // top back-left + v3pos_t( 1, 1, 1), // top back-right + v3pos_t(-1, 1,-1), // top front-left + v3pos_t( 1, 1,-1), // top front-right + v3pos_t(-1,-1, 1), // bottom back-left + v3pos_t( 1,-1, 1), // bottom back-right + v3pos_t(-1,-1,-1), // bottom front-left + v3pos_t( 1,-1,-1), // bottom front-right // 26 }; -const v3POS g_27dirs[27] = +const v3pos_t g_27dirs[27] = { // +right, +top, +back - v3POS( 0, 0, 1), // back - v3POS( 0, 1, 0), // top - v3POS( 1, 0, 0), // right - v3POS( 0, 0,-1), // front - v3POS( 0,-1, 0), // bottom - v3POS(-1, 0, 0), // left + v3pos_t( 0, 0, 1), // back + v3pos_t( 0, 1, 0), // top + v3pos_t( 1, 0, 0), // right + v3pos_t( 0, 0,-1), // front + v3pos_t( 0,-1, 0), // bottom + v3pos_t(-1, 0, 0), // left // 6 - v3POS(-1, 1, 0), // top left - v3POS( 1, 1, 0), // top right - v3POS( 0, 1, 1), // top back - v3POS( 0, 1,-1), // top front - v3POS(-1, 0, 1), // back left - v3POS( 1, 0, 1), // back right - v3POS(-1, 0,-1), // front left - v3POS( 1, 0,-1), // front right - v3POS(-1,-1, 0), // bottom left - v3POS( 1,-1, 0), // bottom right - v3POS( 0,-1, 1), // bottom back - v3POS( 0,-1,-1), // bottom front + v3pos_t(-1, 1, 0), // top left + v3pos_t( 1, 1, 0), // top right + v3pos_t( 0, 1, 1), // top back + v3pos_t( 0, 1,-1), // top front + v3pos_t(-1, 0, 1), // back left + v3pos_t( 1, 0, 1), // back right + v3pos_t(-1, 0,-1), // front left + v3pos_t( 1, 0,-1), // front right + v3pos_t(-1,-1, 0), // bottom left + v3pos_t( 1,-1, 0), // bottom right + v3pos_t( 0,-1, 1), // bottom back + v3pos_t( 0,-1,-1), // bottom front // 18 - v3POS(-1, 1, 1), // top back-left - v3POS( 1, 1, 1), // top back-right - v3POS(-1, 1,-1), // top front-left - v3POS( 1, 1,-1), // top front-right - v3POS(-1,-1, 1), // bottom back-left - v3POS( 1,-1, 1), // bottom back-right - v3POS(-1,-1,-1), // bottom front-left - v3POS( 1,-1,-1), // bottom front-right + v3pos_t(-1, 1, 1), // top back-left + v3pos_t( 1, 1, 1), // top back-right + v3pos_t(-1, 1,-1), // top front-left + v3pos_t( 1, 1,-1), // top front-right + v3pos_t(-1,-1, 1), // bottom back-left + v3pos_t( 1,-1, 1), // bottom back-right + v3pos_t(-1,-1,-1), // bottom front-left + v3pos_t( 1,-1,-1), // bottom front-right // 26 - v3POS(0,0,0), + v3pos_t(0,0,0), }; const u8 wallmounted_to_facedir[6] = { diff --git a/src/util/directiontables.h b/src/util/directiontables.h index 97574dc175..9f51fb6010 100644 --- a/src/util/directiontables.h +++ b/src/util/directiontables.h @@ -22,14 +22,14 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "irrlichttypes.h" #include "irr_v3d.h" -extern const v3POS g_6dirs[6]; +extern const v3pos_t g_6dirs[6]; -extern const v3POS g_7dirs[7]; +extern const v3pos_t g_7dirs[7]; -extern const v3POS g_26dirs[26]; +extern const v3pos_t g_26dirs[26]; // 26th is (0,0,0) -extern const v3POS g_27dirs[27]; +extern const v3pos_t g_27dirs[27]; extern const u8 wallmounted_to_facedir[6]; diff --git a/src/util/numeric.cpp b/src/util/numeric.cpp index 540f8f70b8..45686fe4b1 100644 --- a/src/util/numeric.cpp +++ b/src/util/numeric.cpp @@ -103,10 +103,10 @@ u64 murmur_hash_64_ua(const void *key, int len, unsigned int seed) range: viewing range distance_ptr: return location for distance from the camera */ -bool isBlockInSight(v3POS blockpos_b, v3f camera_pos, v3f camera_dir, +bool isBlockInSight(v3pos_t blockpos_b, v3f camera_pos, v3f camera_dir, f32 camera_fov, f32 range, f32 *distance_ptr) { - v3POS blockpos_nodes = blockpos_b * MAP_BLOCKSIZE; + v3pos_t blockpos_nodes = blockpos_b * MAP_BLOCKSIZE; // Block center position v3f blockpos( diff --git a/src/util/numeric.h b/src/util/numeric.h index e0687fe288..172495d7bc 100644 --- a/src/util/numeric.h +++ b/src/util/numeric.h @@ -41,58 +41,58 @@ with this program; if not, write to the Free Software Foundation, Inc., // sqrt(3.0) / 2.0 in literal form. static constexpr const f32 BLOCK_MAX_RADIUS = 0.866025403784f * MAP_BLOCKSIZE * BS; -inline BPOS getContainerPos(POS p, POS d) +inline bpos_t getContainerPos(pos_t p, pos_t d) { return (p >= 0 ? p : p - d + 1) / d; } -inline v2BPOS getContainerPos(v2POS p, POS d) +inline v2bpos_t getContainerPos(v2pos_t p, pos_t d) { - return v2BPOS( + return v2bpos_t( getContainerPos(p.X, d), getContainerPos(p.Y, d) ); } -inline v3BPOS getContainerPos(v3POS p, POS d) +inline v3bpos_t getContainerPos(v3pos_t p, pos_t d) { - return v3BPOS( + return v3bpos_t( getContainerPos(p.X, d), getContainerPos(p.Y, d), getContainerPos(p.Z, d) ); } -inline v2BPOS getContainerPos(v2POS p, v2POS d) +inline v2bpos_t getContainerPos(v2pos_t p, v2pos_t d) { - return v2BPOS( + return v2bpos_t( getContainerPos(p.X, d.X), getContainerPos(p.Y, d.Y) ); } -inline v3BPOS getContainerPos(v3POS p, v3POS d) +inline v3bpos_t getContainerPos(v3pos_t p, v3pos_t d) { - return v3BPOS( + return v3bpos_t( getContainerPos(p.X, d.X), getContainerPos(p.Y, d.Y), getContainerPos(p.Z, d.Z) ); } -inline void getContainerPosWithOffset(POS p, POS d, BPOS &container, POS &offset) +inline void getContainerPosWithOffset(pos_t p, pos_t d, bpos_t &container, pos_t &offset) { container = (p >= 0 ? p : p - d + 1) / d; offset = p & (d - 1); } -inline void getContainerPosWithOffset(const v2POS &p, POS d, v2BPOS &container, v2POS &offset) +inline void getContainerPosWithOffset(const v2pos_t &p, pos_t d, v2bpos_t &container, v2pos_t &offset) { getContainerPosWithOffset(p.X, d, container.X, offset.X); getContainerPosWithOffset(p.Y, d, container.Y, offset.Y); } -inline void getContainerPosWithOffset(const v3POS &p, POS d, v3BPOS &container, v3POS &offset) +inline void getContainerPosWithOffset(const v3pos_t &p, pos_t d, v3bpos_t &container, v3pos_t &offset) { getContainerPosWithOffset(p.X, d, container.X, offset.X); getContainerPosWithOffset(p.Y, d, container.Y, offset.Y); @@ -100,7 +100,7 @@ inline void getContainerPosWithOffset(const v3POS &p, POS d, v3BPOS &container, } -inline bool isInArea(v3POS p, POS d) +inline bool isInArea(v3pos_t p, pos_t d) { return ( p.X >= 0 && p.X < d && @@ -109,7 +109,7 @@ inline bool isInArea(v3POS p, POS d) ); } -inline bool isInArea(v2POS p, POS d) +inline bool isInArea(v2pos_t p, pos_t d) { return ( p.X >= 0 && p.X < d && @@ -117,7 +117,7 @@ inline bool isInArea(v2POS p, POS d) ); } -inline bool isInArea(v3POS p, v3POS d) +inline bool isInArea(v3pos_t p, v3pos_t d) { return ( p.X >= 0 && p.X < d.X && @@ -126,23 +126,23 @@ inline bool isInArea(v3POS p, v3POS d) ); } -inline void sortBoxVerticies(v3POS &p1, v3POS &p2) { +inline void sortBoxVerticies(v3pos_t &p1, v3pos_t &p2) { if (p1.X > p2.X) - SWAP(POS, p1.X, p2.X); + SWAP(pos_t, p1.X, p2.X); if (p1.Y > p2.Y) - SWAP(POS, p1.Y, p2.Y); + SWAP(pos_t, p1.Y, p2.Y); if (p1.Z > p2.Z) - SWAP(POS, p1.Z, p2.Z); + SWAP(pos_t, p1.Z, p2.Z); } -inline v3POS componentwise_min(const v3POS &a, const v3POS &b) +inline v3pos_t componentwise_min(const v3pos_t &a, const v3pos_t &b) { - return v3POS(MYMIN(a.X, b.X), MYMIN(a.Y, b.Y), MYMIN(a.Z, b.Z)); + return v3pos_t(MYMIN(a.X, b.X), MYMIN(a.Y, b.Y), MYMIN(a.Z, b.Z)); } -inline v3POS componentwise_max(const v3POS &a, const v3POS &b) +inline v3pos_t componentwise_max(const v3pos_t &a, const v3pos_t &b) { - return v3POS(MYMAX(a.X, b.X), MYMAX(a.Y, b.Y), MYMAX(a.Z, b.Z)); + return v3pos_t(MYMAX(a.X, b.X), MYMAX(a.Y, b.Y), MYMAX(a.Z, b.Z)); } @@ -252,7 +252,7 @@ inline u32 calc_parity(u32 v) u64 murmur_hash_64_ua(const void *key, int len, unsigned int seed); -bool isBlockInSight(v3BPOS blockpos_b, v3f camera_pos, v3f camera_dir, +bool isBlockInSight(v3bpos_t blockpos_b, v3f camera_pos, v3f camera_dir, f32 camera_fov, f32 range, f32 *distance_ptr=NULL); s16 adjustDist(s16 dist, float zoom_fov); @@ -274,9 +274,9 @@ inline constexpr f32 sqr(f32 f) /* Returns integer position of node in given floating point position */ -inline v3POS floatToInt(v3f p, f32 d) +inline v3pos_t floatToInt(v3f p, f32 d) { - return v3POS( + return v3pos_t( (p.X + (p.X > 0 ? d / 2 : -d / 2)) / d, (p.Y + (p.Y > 0 ? d / 2 : -d / 2)) / d, (p.Z + (p.Z > 0 ? d / 2 : -d / 2)) / d); @@ -293,9 +293,9 @@ inline v3s16 doubleToInt(v3d p, double d) (p.Z + (p.Z > 0 ? d / 2 : -d / 2)) / d); } -inline v3POS doubleToPos(v3d p, double d) +inline v3pos_t doubleToPos(v3d p, double d) { - return v3POS( + return v3pos_t( (p.X + (p.X > 0 ? d / 2 : -d / 2)) / d, (p.Y + (p.Y > 0 ? d / 2 : -d / 2)) / d, (p.Z + (p.Z > 0 ? d / 2 : -d / 2)) / d); @@ -304,7 +304,7 @@ inline v3POS doubleToPos(v3d p, double d) /* Returns floating point position of node in given integer position */ -inline v3f intToFloat(v3POS p, f32 d) +inline v3f intToFloat(v3pos_t p, f32 d) { return v3f( (f32)p.X * d, @@ -314,7 +314,7 @@ inline v3f intToFloat(v3POS p, f32 d) } // Random helper. Usually d=BS -inline aabb3f getNodeBox(v3POS p, float d) +inline aabb3f getNodeBox(v3pos_t p, float d) { return aabb3f( (float)p.X * d - 0.5f * d, diff --git a/src/util/pointedthing.cpp b/src/util/pointedthing.cpp index 180c9494b5..ceed42b641 100644 --- a/src/util/pointedthing.cpp +++ b/src/util/pointedthing.cpp @@ -23,8 +23,8 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "exceptions.h" #include -PointedThing::PointedThing(const v3POS &under, const v3POS &above, - const v3POS &real_under, const v3f &point, const v3POS &normal, +PointedThing::PointedThing(const v3pos_t &under, const v3pos_t &above, + const v3pos_t &real_under, const v3f &point, const v3pos_t &normal, u16 box_id, f32 distSq): type(POINTEDTHING_NODE), node_undersurface(under), @@ -36,7 +36,7 @@ PointedThing::PointedThing(const v3POS &under, const v3POS &above, distanceSq(distSq) {} -PointedThing::PointedThing(s16 id, const v3f &point, const v3POS &normal, +PointedThing::PointedThing(s16 id, const v3f &point, const v3pos_t &normal, f32 distSq) : type(POINTEDTHING_OBJECT), object_id(id), @@ -54,8 +54,8 @@ std::string PointedThing::dump() const break; case POINTEDTHING_NODE: { - const v3POS &u = node_undersurface; - const v3POS &a = node_abovesurface; + const v3pos_t &u = node_undersurface; + const v3pos_t &a = node_abovesurface; os << "[node under=" << u.X << "," << u.Y << "," << u.Z << " above=" << a.X << "," << a.Y << "," << a.Z << "]"; } diff --git a/src/util/pointedthing.h b/src/util/pointedthing.h index b02c47a589..42e767d072 100644 --- a/src/util/pointedthing.h +++ b/src/util/pointedthing.h @@ -43,20 +43,20 @@ struct PointedThing * This may differ from node_real_undersurface if * a nodebox exceeds the limits of its node. */ - v3POS node_undersurface; + v3pos_t node_undersurface; /*! * Only valid if type is POINTEDTHING_NODE. * The coordinates of the last node the ray intersects * before node_undersurface. Same as node_undersurface * if the ray starts in a nodebox. */ - v3POS node_abovesurface; + v3pos_t node_abovesurface; /*! * Only valid if type is POINTEDTHING_NODE. * The coordinates of the node which contains the * point of the collision and the nodebox of the node. */ - v3POS node_real_undersurface; + v3pos_t node_real_undersurface; /*! * Only valid if type is POINTEDTHING_OBJECT. * The ID of the object the ray hit. @@ -74,7 +74,7 @@ struct PointedThing * This is perpendicular to the face the ray hits, * points outside of the box and it's length is 1. */ - v3POS intersection_normal; + v3pos_t intersection_normal; /*! * Only valid if type isn't POINTEDTHING_NONE. * Indicates which selection box is selected, if there are more of them. @@ -89,11 +89,11 @@ struct PointedThing //! Constructor for POINTEDTHING_NOTHING PointedThing() = default; //! Constructor for POINTEDTHING_NODE - PointedThing(const v3POS &under, const v3POS &above, - const v3POS &real_under, const v3f &point, const v3POS &normal, + PointedThing(const v3pos_t &under, const v3pos_t &above, + const v3pos_t &real_under, const v3f &point, const v3pos_t &normal, u16 box_id, f32 distSq); //! Constructor for POINTEDTHING_OBJECT - PointedThing(s16 id, const v3f &point, const v3POS &normal, f32 distSq); + PointedThing(s16 id, const v3f &point, const v3pos_t &normal, f32 distSq); std::string dump() const; void serialize(std::ostream &os) const; void deSerialize(std::istream &is); diff --git a/src/util/serialize.h b/src/util/serialize.h index 8ef483eeb8..929fb42ded 100644 --- a/src/util/serialize.h +++ b/src/util/serialize.h @@ -435,7 +435,7 @@ MAKE_STREAM_WRITE_FXN(v2f, V2F32, 8); MAKE_STREAM_WRITE_FXN(v3f, V3F32, 12); MAKE_STREAM_WRITE_FXN(video::SColor, ARGB8, 4); -inline POS readPOS(std::istream &is) { +inline pos_t readPOS(std::istream &is) { #if USE_POS32 return readS32(is); #else @@ -443,7 +443,7 @@ inline POS readPOS(std::istream &is) { #endif } -inline void writePOS(std::ostream &os, POS i) { +inline void writePOS(std::ostream &os, pos_t i) { #if USE_POS32 return writeS32(os, i); #else @@ -451,7 +451,7 @@ inline void writePOS(std::ostream &os, POS i) { #endif } -inline v3POS readV3POS(std::istream &is) { +inline v3pos_t readV3POS(std::istream &is) { #if USE_POS32 return readV3S32(is); #else @@ -459,7 +459,7 @@ inline v3POS readV3POS(std::istream &is) { #endif } -inline void writeV3POS(std::ostream &os, v3POS p) { +inline void writeV3POS(std::ostream &os, v3pos_t p) { #if USE_POS32 return writeV3S32(os, p); #else diff --git a/src/voxel.cpp b/src/voxel.cpp index 8a24056c18..ec0fd99a6d 100644 --- a/src/voxel.cpp +++ b/src/voxel.cpp @@ -51,8 +51,8 @@ void VoxelManipulator::clear() void VoxelManipulator::print(std::ostream &o, const NodeDefManager *ndef, VoxelPrintMode mode) { - const v3POS &em = m_area.getExtent(); - v3POS of = m_area.MinEdge; + const v3pos_t &em = m_area.getExtent(); + v3pos_t of = m_area.MinEdge; o<<"size: "<= MinEdge.Z && a.MaxEdge.Z <= MaxEdge.Z ); } - bool contains(v3POS p) const + bool contains(v3pos_t p) const { return( p.X >= MinEdge.X && p.X <= MaxEdge.X && @@ -173,12 +173,12 @@ class VoxelArea && MaxEdge == other.MaxEdge); } - VoxelArea operator+(const v3POS &off) const + VoxelArea operator+(const v3pos_t &off) const { return {MinEdge+off, MaxEdge+off}; } - VoxelArea operator-(const v3POS &off) const + VoxelArea operator-(const v3pos_t &off) const { return {MinEdge-off, MaxEdge-off}; } @@ -196,7 +196,7 @@ class VoxelArea */ // If a is an empty area, return the current area as a whole - if(a.getExtent() == v3POS(0,0,0)) + if(a.getExtent() == v3pos_t(0,0,0)) { VoxelArea b = *this; if(b.getVolume() != 0) @@ -208,8 +208,8 @@ class VoxelArea // Take back area, XY inclusive { - v3POS min(MinEdge.X, MinEdge.Y, a.MaxEdge.Z+1); - v3POS max(MaxEdge.X, MaxEdge.Y, MaxEdge.Z); + v3pos_t min(MinEdge.X, MinEdge.Y, a.MaxEdge.Z+1); + v3pos_t max(MaxEdge.X, MaxEdge.Y, MaxEdge.Z); VoxelArea b(min, max); if(b.getVolume() != 0) result.push_back(b); @@ -217,8 +217,8 @@ class VoxelArea // Take front area, XY inclusive { - v3POS min(MinEdge.X, MinEdge.Y, MinEdge.Z); - v3POS max(MaxEdge.X, MaxEdge.Y, a.MinEdge.Z-1); + v3pos_t min(MinEdge.X, MinEdge.Y, MinEdge.Z); + v3pos_t max(MaxEdge.X, MaxEdge.Y, a.MinEdge.Z-1); VoxelArea b(min, max); if(b.getVolume() != 0) result.push_back(b); @@ -226,8 +226,8 @@ class VoxelArea // Take top area, X inclusive { - v3POS min(MinEdge.X, a.MaxEdge.Y+1, a.MinEdge.Z); - v3POS max(MaxEdge.X, MaxEdge.Y, a.MaxEdge.Z); + v3pos_t min(MinEdge.X, a.MaxEdge.Y+1, a.MinEdge.Z); + v3pos_t max(MaxEdge.X, MaxEdge.Y, a.MaxEdge.Z); VoxelArea b(min, max); if(b.getVolume() != 0) result.push_back(b); @@ -235,8 +235,8 @@ class VoxelArea // Take bottom area, X inclusive { - v3POS min(MinEdge.X, MinEdge.Y, a.MinEdge.Z); - v3POS max(MaxEdge.X, a.MinEdge.Y-1, a.MaxEdge.Z); + v3pos_t min(MinEdge.X, MinEdge.Y, a.MinEdge.Z); + v3pos_t max(MaxEdge.X, a.MinEdge.Y-1, a.MaxEdge.Z); VoxelArea b(min, max); if(b.getVolume() != 0) result.push_back(b); @@ -244,8 +244,8 @@ class VoxelArea // Take left area, non-inclusive { - v3POS min(MinEdge.X, a.MinEdge.Y, a.MinEdge.Z); - v3POS max(a.MinEdge.X-1, a.MaxEdge.Y, a.MaxEdge.Z); + v3pos_t min(MinEdge.X, a.MinEdge.Y, a.MinEdge.Z); + v3pos_t max(a.MinEdge.X-1, a.MaxEdge.Y, a.MaxEdge.Z); VoxelArea b(min, max); if(b.getVolume() != 0) result.push_back(b); @@ -253,8 +253,8 @@ class VoxelArea // Take right area, non-inclusive { - v3POS min(a.MaxEdge.X+1, a.MinEdge.Y, a.MinEdge.Z); - v3POS max(MaxEdge.X, a.MaxEdge.Y, a.MaxEdge.Z); + v3pos_t min(a.MaxEdge.X+1, a.MinEdge.Y, a.MinEdge.Z); + v3pos_t max(MaxEdge.X, a.MaxEdge.Y, a.MaxEdge.Z); VoxelArea b(min, max); if(b.getVolume() != 0) result.push_back(b); @@ -265,14 +265,14 @@ class VoxelArea /* Translates position from virtual coordinates to array index */ - s32 index(POS x, POS y, POS z) const + s32 index(pos_t x, pos_t y, pos_t z) const { s32 i = (s32)(z - MinEdge.Z) * m_cache_extent.Y * m_cache_extent.X + (y - MinEdge.Y) * m_cache_extent.X + (x - MinEdge.X); return i; } - s32 index(v3POS p) const + s32 index(v3pos_t p) const { return index(p.X, p.Y, p.Z); } @@ -280,7 +280,7 @@ class VoxelArea /** * Translate index in the X coordinate */ - static void add_x(const v3POS &extent, u32 &i, POS a) + static void add_x(const v3pos_t &extent, u32 &i, pos_t a) { i += a; } @@ -288,7 +288,7 @@ class VoxelArea /** * Translate index in the Y coordinate */ - static void add_y(const v3POS &extent, u32 &i, POS a) + static void add_y(const v3pos_t &extent, u32 &i, pos_t a) { i += a * extent.X; } @@ -296,7 +296,7 @@ class VoxelArea /** * Translate index in the Z coordinate */ - static void add_z(const v3POS &extent, u32 &i, POS a) + static void add_z(const v3pos_t &extent, u32 &i, pos_t a) { i += a * extent.X * extent.Y; } @@ -304,7 +304,7 @@ class VoxelArea /** * Translate index in space */ - static void add_p(const v3POS &extent, u32 &i, v3POS a) + static void add_p(const v3pos_t &extent, u32 &i, v3pos_t a) { i += a.Z * extent.X * extent.Y + a.Y * extent.X + a.X; } @@ -320,15 +320,15 @@ class VoxelArea } // Edges are inclusive - v3POS MinEdge = v3POS(1,1,1); - v3POS MaxEdge; + v3pos_t MinEdge = v3pos_t(1,1,1); + v3pos_t MaxEdge; private: void cacheExtent() { - m_cache_extent = MaxEdge - MinEdge + v3POS(1,1,1); + m_cache_extent = MaxEdge - MinEdge + v3pos_t(1,1,1); } - v3POS m_cache_extent = v3POS(0,0,0); + v3pos_t m_cache_extent = v3pos_t(0,0,0); }; // unused @@ -362,7 +362,7 @@ class VoxelManipulator These are a bit slow and shouldn't be used internally. Use m_data[m_area.index(p)] instead. */ - MapNode getNode(const v3POS &p) + MapNode getNode(const v3pos_t &p) { VoxelArea voxel_area(p); addArea(voxel_area); @@ -379,7 +379,7 @@ class VoxelManipulator return m_data[m_area.index(p)]; } - MapNode getNodeNoEx(const v3POS &p) + MapNode getNodeNoEx(const v3pos_t &p) { VoxelArea voxel_area(p); addArea(voxel_area); @@ -390,7 +390,7 @@ class VoxelManipulator return m_data[m_area.index(p)]; } - MapNode getNodeNoExNoEmerge(const v3POS &p) + MapNode getNodeNoExNoEmerge(const v3pos_t &p) { if (!m_area.contains(p)) return {CONTENT_IGNORE}; @@ -400,12 +400,12 @@ class VoxelManipulator } // Stuff explodes if non-emerged area is touched with this. // Emerge first, and check VOXELFLAG_NO_DATA if appropriate. - MapNode & getNodeRefUnsafe(const v3POS &p) + MapNode & getNodeRefUnsafe(const v3pos_t &p) { return m_data[m_area.index(p)]; } - const MapNode & getNodeRefUnsafeCheckFlags(const v3POS &p) + const MapNode & getNodeRefUnsafeCheckFlags(const v3pos_t &p) { s32 index = m_area.index(p); @@ -415,18 +415,18 @@ class VoxelManipulator return m_data[index]; } - u8 & getFlagsRefUnsafe(const v3POS &p) + u8 & getFlagsRefUnsafe(const v3pos_t &p) { return m_flags[m_area.index(p)]; } - bool exists(const v3POS &p) + bool exists(const v3pos_t &p) { return m_area.contains(p) && !(getFlagsRefUnsafe(p) & VOXELFLAG_NO_DATA); } - void setNode(const v3POS &p, const MapNode &n) + void setNode(const v3pos_t &p, const MapNode &n) { VoxelArea voxel_area(p); addArea(voxel_area); @@ -435,7 +435,7 @@ class VoxelManipulator m_flags[m_area.index(p)] &= ~VOXELFLAG_NO_DATA; } // TODO: Should be removed and replaced with setNode - void setNodeNoRef(const v3POS &p, const MapNode &n) + void setNodeNoRef(const v3pos_t &p, const MapNode &n) { setNode(p, n); } @@ -446,7 +446,7 @@ class VoxelManipulator This is convenient but slower than playing around directly with the m_data table with indices. */ - bool setNodeNoEmerge(const v3POS &p, MapNode n) + bool setNodeNoEmerge(const v3pos_t &p, MapNode n) { if(!m_area.contains(p)) return false; @@ -470,11 +470,11 @@ class VoxelManipulator dst_area.getExtent() <= src_area.getExtent() */ void copyFrom(MapNode *src, const VoxelArea& src_area, - v3POS from_pos, v3POS to_pos, const v3POS &size); + v3pos_t from_pos, v3pos_t to_pos, const v3pos_t &size); // Copy data void copyTo(MapNode *dst, const VoxelArea& dst_area, - v3POS dst_pos, v3POS from_pos, const v3POS &size); + v3pos_t dst_pos, v3pos_t from_pos, const v3pos_t &size); /* Algorithms @@ -488,7 +488,7 @@ class VoxelManipulator /* The area that is stored in m_data. - addInternalBox should not be used if getExtent() == v3POS(0,0,0) + addInternalBox should not be used if getExtent() == v3pos_t(0,0,0) MaxEdge is 1 higher than maximum allowed position */ VoxelArea m_area; diff --git a/src/voxelalgorithms.cpp b/src/voxelalgorithms.cpp index 1abe7b6742..cdf176cb7f 100644 --- a/src/voxelalgorithms.cpp +++ b/src/voxelalgorithms.cpp @@ -42,12 +42,12 @@ typedef u8 direction; * This represents a node's position in its map block. * All coordinates must be between 0 and 15. */ -typedef v3POS relative_v3; +typedef v3pos_t relative_v3; /*! * Position of a map block (block coordinates). * One block_pos unit is as long as 16 node position units. */ -typedef v3BPOS mapblock_v3; +typedef v3bpos_t mapblock_v3; //! Contains information about a node whose light is about to change. struct ChangingLight { @@ -158,13 +158,13 @@ typedef LightQueue ReLightQueue; * the direction i. * See the definition of the type "direction" */ -const static v3POS neighbor_dirs[6] = { - v3POS(1, 0, 0), // right - v3POS(0, 1, 0), // top - v3POS(0, 0, 1), // back - v3POS(0, 0, -1), // front - v3POS(0, -1, 0), // bottom - v3POS(-1, 0, 0), // left +const static v3pos_t neighbor_dirs[6] = { + v3pos_t(1, 0, 0), // right + v3pos_t(0, 1, 0), // top + v3pos_t(0, 0, 1), // back + v3pos_t(0, 0, -1), // front + v3pos_t(0, -1, 0), // bottom + v3pos_t(-1, 0, 0), // left }; /*! @@ -248,7 +248,7 @@ bool step_rel_block_pos(direction dir, relative_v3 &rel_pos, */ void unspread_light(Map *map, const NodeDefManager *nodemgr, LightBank bank, UnlightQueue &from_nodes, ReLightQueue &light_sources, - std::map &modified_blocks) + std::map &modified_blocks) { // Stores data popped from from_nodes u8 current_light; @@ -352,7 +352,7 @@ void unspread_light(Map *map, const NodeDefManager *nodemgr, LightBank bank, */ void spread_light(Map *map, const NodeDefManager *nodemgr, LightBank bank, LightQueue &light_sources, - std::map &modified_blocks) + std::map &modified_blocks) { // The light the current node can provide to its neighbors. u8 spreading_light; @@ -407,10 +407,10 @@ void spread_light(Map *map, const NodeDefManager *nodemgr, LightBank bank, } struct SunlightPropagationUnit{ - v2POS relative_pos; + v2pos_t relative_pos; bool is_sunlit; - SunlightPropagationUnit(v2POS relpos, bool sunlit): + SunlightPropagationUnit(v2pos_t relpos, bool sunlit): relative_pos(relpos), is_sunlit(sunlit) {} @@ -418,7 +418,7 @@ struct SunlightPropagationUnit{ struct SunlightPropagationData{ std::vector data; - v3POS target_block; + v3pos_t target_block; }; /*! @@ -427,12 +427,12 @@ struct SunlightPropagationData{ * * \param pos position of the node. */ -bool is_sunlight_above(Map *map, v3POS pos, const NodeDefManager *ndef) +bool is_sunlight_above(Map *map, v3pos_t pos, const NodeDefManager *ndef) { bool sunlight = true; mapblock_v3 source_block_pos; relative_v3 source_rel_pos; - getNodeBlockPosWithOffset(pos + v3POS(0, 1, 0), source_block_pos, + getNodeBlockPosWithOffset(pos + v3pos_t(0, 1, 0), source_block_pos, source_rel_pos); // If the node above has sunlight, this node also can get it. MapBlock *source_block = map->getBlockNoCreateNoEx(source_block_pos); @@ -467,8 +467,8 @@ bool is_sunlight_above(Map *map, v3POS pos, const NodeDefManager *ndef) static const LightBank banks[] = { LIGHTBANK_DAY, LIGHTBANK_NIGHT }; void update_lighting_nodes(Map *map, - const std::vector> &oldnodes, - std::map &modified_blocks) + const std::vector> &oldnodes, + std::map &modified_blocks) { const NodeDefManager *ndef = map->getNodeDefManager(); // For node getter functions @@ -496,7 +496,7 @@ void update_lighting_nodes(Map *map, // For each changed node process sunlight and initialize for (auto it = oldnodes.cbegin(); it < oldnodes.cend(); ++it) { // Get position and block of the changed node - v3POS p = it->first; + v3pos_t p = it->first; relative_v3 rel_pos; mapblock_v3 block_pos; getNodeBlockPosWithOffset(p, block_pos, rel_pos); @@ -524,8 +524,8 @@ void update_lighting_nodes(Map *map, new_light = LIGHT_SUN; } else { new_light = ndef->get(n).light_source; - for (const v3POS &neighbor_dir : neighbor_dirs) { - v3POS p2 = p + neighbor_dir; + for (const v3pos_t &neighbor_dir : neighbor_dirs) { + v3pos_t p2 = p + neighbor_dir; bool is_valid; MapNode n2 = map->getNode(p2, &is_valid); if (is_valid) { @@ -559,8 +559,8 @@ void update_lighting_nodes(Map *map, // Remove sunlight, if there was any if (bank == LIGHTBANK_DAY && old_light == LIGHT_SUN) { - for (POS y = p.Y - 1;; y--) { - v3POS n2pos(p.X, y, p.Z); + for (pos_t y = p.Y - 1;; y--) { + v3pos_t n2pos(p.X, y, p.Z); MapNode n2; @@ -591,8 +591,8 @@ void update_lighting_nodes(Map *map, // one, unlighting is not necessary. // Propagate sunlight if (bank == LIGHTBANK_DAY && new_light == LIGHT_SUN) { - for (POS y = p.Y - 1;; y--) { - v3POS n2pos(p.X, y, p.Z); + for (pos_t y = p.Y - 1;; y--) { + v3pos_t n2pos(p.X, y, p.Z); MapNode n2; @@ -646,12 +646,12 @@ void update_lighting_nodes(Map *map, * Compatible with type 'direction'. */ const VoxelArea block_borders[] = { - VoxelArea(v3POS(15, 0, 0), v3POS(15, 15, 15)), //X+ - VoxelArea(v3POS(0, 15, 0), v3POS(15, 15, 15)), //Y+ - VoxelArea(v3POS(0, 0, 15), v3POS(15, 15, 15)), //Z+ - VoxelArea(v3POS(0, 0, 0), v3POS(15, 15, 0)), //Z- - VoxelArea(v3POS(0, 0, 0), v3POS(15, 0, 15)), //Y- - VoxelArea(v3POS(0, 0, 0), v3POS(0, 15, 15)) //X- + VoxelArea(v3pos_t(15, 0, 0), v3pos_t(15, 15, 15)), //X+ + VoxelArea(v3pos_t(0, 15, 0), v3pos_t(15, 15, 15)), //Y+ + VoxelArea(v3pos_t(0, 0, 15), v3pos_t(15, 15, 15)), //Z+ + VoxelArea(v3pos_t(0, 0, 0), v3pos_t(15, 15, 0)), //Z- + VoxelArea(v3pos_t(0, 0, 0), v3pos_t(15, 0, 15)), //Y- + VoxelArea(v3pos_t(0, 0, 0), v3pos_t(0, 15, 15)) //X- }; /*! @@ -663,7 +663,7 @@ const VoxelArea block_borders[] = { * . */ bool is_light_locally_correct(Map *map, const NodeDefManager *ndef, - LightBank bank, v3POS pos) + LightBank bank, v3pos_t pos) { bool is_valid_position; MapNode n = map->getNode(pos, &is_valid_position); @@ -674,7 +674,7 @@ bool is_light_locally_correct(Map *map, const NodeDefManager *ndef, u8 light = n.getLightNoChecks(bank, &f); assert(f.light_source <= LIGHT_MAX); u8 brightest_neighbor = f.light_source + 1; - for (const v3POS &neighbor_dir : neighbor_dirs) { + for (const v3pos_t &neighbor_dir : neighbor_dirs) { MapNode n2 = map->getNode(pos + neighbor_dir, &is_valid_position); u8 light2 = n2.getLight(bank, ndef); @@ -687,7 +687,7 @@ bool is_light_locally_correct(Map *map, const NodeDefManager *ndef, } void update_block_border_lighting(Map *map, MapBlock *block, - std::map &modified_blocks) + std::map &modified_blocks) { const NodeDefManager *ndef = map->getNodeDefManager(); bool is_valid_position; @@ -700,7 +700,7 @@ void update_block_border_lighting(Map *map, MapBlock *block, for (direction d = 0; d < 6; d++) { // For each direction // Get neighbor block - v3POS otherpos = block->getPos() + neighbor_dirs[d]; + v3pos_t otherpos = block->getPos() + neighbor_dirs[d]; MapBlock *other = map->getBlockNoCreateNoEx(otherpos); if (other == NULL) { continue; @@ -730,7 +730,7 @@ void update_block_border_lighting(Map *map, MapBlock *block, if (light < LIGHT_SUN) { // Unlight if not correct if (!is_light_locally_correct(map, ndef, bank, - v3POS(x, y, z) + b->getPosRelative())) { + v3pos_t(x, y, z) + b->getPosRelative())) { // Initialize for unlighting n.setLight(bank, 0, ndef); b->setNodeNoCheck(x, y, z, n); @@ -775,7 +775,7 @@ void update_block_border_lighting(Map *map, MapBlock *block, * After the procedure returns, this contains outgoing light at * the bottom of the voxel manipulator. */ -void fill_with_sunlight(MMVManip *vm, const NodeDefManager *ndef, v2POS offset, +void fill_with_sunlight(MMVManip *vm, const NodeDefManager *ndef, v2pos_t offset, bool light[MAP_BLOCKSIZE][MAP_BLOCKSIZE]) { // Distance in array between two nodes on top of each other. @@ -786,7 +786,7 @@ void fill_with_sunlight(MMVManip *vm, const NodeDefManager *ndef, v2POS offset, for (s16 z = 0; z < MAP_BLOCKSIZE; z++) for (s16 x = 0; x < MAP_BLOCKSIZE; x++) { // Position of the column on the map. - v2POS realpos = offset + v2POS(x, z); + v2pos_t realpos = offset + v2pos_t(x, z); // Array indices in the voxel manipulator s32 maxindex = vm->m_area.index(realpos.X, vm->m_area.MaxEdge.Y, realpos.Y); @@ -829,7 +829,7 @@ void fill_with_sunlight(MMVManip *vm, const NodeDefManager *ndef, v2POS offset, void is_sunlight_above_block(ServerMap *map, mapblock_v3 pos, const NodeDefManager *ndef, bool light[MAP_BLOCKSIZE][MAP_BLOCKSIZE]) { - mapblock_v3 source_block_pos = pos + v3POS(0, 1, 0); + mapblock_v3 source_block_pos = pos + v3pos_t(0, 1, 0); // Get or load source block. // It might take a while to load, but correcting incorrect // sunlight may be even slower. @@ -946,12 +946,12 @@ bool propagate_block_sunlight(Map *map, const NodeDefManager *ndef, * Compatible with type 'direction'. */ const VoxelArea block_pad[] = { - VoxelArea(v3POS(15, 0, 0), v3POS(15, 15, 15)), //X+ - VoxelArea(v3POS(1, 15, 0), v3POS(14, 15, 15)), //Y+ - VoxelArea(v3POS(1, 1, 15), v3POS(14, 14, 15)), //Z+ - VoxelArea(v3POS(1, 1, 0), v3POS(14, 14, 0)), //Z- - VoxelArea(v3POS(1, 0, 0), v3POS(14, 0, 15)), //Y- - VoxelArea(v3POS(0, 0, 0), v3POS(0, 15, 15)) //X- + VoxelArea(v3pos_t(15, 0, 0), v3pos_t(15, 15, 15)), //X+ + VoxelArea(v3pos_t(1, 15, 0), v3pos_t(14, 15, 15)), //Y+ + VoxelArea(v3pos_t(1, 1, 15), v3pos_t(14, 14, 15)), //Z+ + VoxelArea(v3pos_t(1, 1, 0), v3pos_t(14, 14, 0)), //Z- + VoxelArea(v3pos_t(1, 0, 0), v3pos_t(14, 0, 15)), //Y- + VoxelArea(v3pos_t(0, 0, 0), v3pos_t(0, 15, 15)) //X- }; /*! @@ -976,7 +976,7 @@ const VoxelArea block_pad[] = { */ void finish_bulk_light_update(Map *map, mapblock_v3 minblock, mapblock_v3 maxblock, UnlightQueue unlight[2], ReLightQueue relight[2], - std::map *modified_blocks) + std::map *modified_blocks) { const NodeDefManager *ndef = map->getNodeDefManager(); // dummy boolean @@ -993,8 +993,8 @@ void finish_bulk_light_update(Map *map, mapblock_v3 minblock, // --- STEP 2: Get all newly inserted light sources // For each block: - v3POS blockpos; - v3POS relpos; + v3pos_t blockpos; + v3pos_t relpos; for (blockpos.X = minblock.X; blockpos.X <= maxblock.X; blockpos.X++) for (blockpos.Y = minblock.Y; blockpos.Y <= maxblock.Y; blockpos.Y++) for (blockpos.Z = minblock.Z; blockpos.Z <= maxblock.Z; blockpos.Z++) { @@ -1045,7 +1045,7 @@ void finish_bulk_light_update(Map *map, mapblock_v3 minblock, } void blit_back_with_light(ServerMap *map, MMVManip *vm, - std::map *modified_blocks) + std::map *modified_blocks) { const NodeDefManager *ndef = map->getNodeDefManager(); mapblock_v3 minblock = getNodeBlockPos(vm->m_area.MinEdge); @@ -1062,19 +1062,19 @@ void blit_back_with_light(ServerMap *map, MMVManip *vm, // --- STEP 1: reset everything to sunlight // For each map block: - for (BPOS x = minblock.X; x <= maxblock.X; x++) - for (BPOS z = minblock.Z; z <= maxblock.Z; z++) { + for (bpos_t x = minblock.X; x <= maxblock.X; x++) + for (bpos_t z = minblock.Z; z <= maxblock.Z; z++) { // Extract sunlight above. - is_sunlight_above_block(map, v3BPOS(x, maxblock.Y, z), ndef, lights); - v2POS offset(x, z); + is_sunlight_above_block(map, v3bpos_t(x, maxblock.Y, z), ndef, lights); + v2pos_t offset(x, z); offset *= MAP_BLOCKSIZE; // Reset the voxel manipulator. fill_with_sunlight(vm, ndef, offset, lights); // Copy sunlight data - data.target_block = v3POS(x, minblock.Y - 1, z); + data.target_block = v3pos_t(x, minblock.Y - 1, z); for (s16 z = 0; z < MAP_BLOCKSIZE; z++) for (s16 x = 0; x < MAP_BLOCKSIZE; x++) - data.data.emplace_back(v2POS(x, z), lights[z][x]); + data.data.emplace_back(v2pos_t(x, z), lights[z][x]); // Propagate sunlight and shadow below the voxel manipulator. while (!data.data.empty()) { if (propagate_block_sunlight(map, ndef, &data, &unlight[0], @@ -1087,8 +1087,8 @@ void blit_back_with_light(ServerMap *map, MMVManip *vm, } // --- STEP 2: Get nodes from borders to unlight - v3POS blockpos; - v3POS relpos; + v3pos_t blockpos; + v3pos_t relpos; // In case there are unloaded holes in the voxel manipulator // unlight each block. @@ -1100,7 +1100,7 @@ void blit_back_with_light(ServerMap *map, MMVManip *vm, if (!block || block->isDummy()) // Skip not existing blocks. continue; - v3POS offset = block->getPosRelative(); + v3pos_t offset = block->getPosRelative(); // For each border of the block: for (const VoxelArea &a : block_pad) { // For each node of the border: @@ -1188,7 +1188,7 @@ void fill_with_sunlight(MapBlock *block, const NodeDefManager *ndef, } void repair_block_light(ServerMap *map, MapBlock *block, - std::map *modified_blocks) + std::map *modified_blocks) { if (!block || block->isDummy()) return; @@ -1212,10 +1212,10 @@ void repair_block_light(ServerMap *map, MapBlock *block, // Reset the voxel manipulator. fill_with_sunlight(block, ndef, lights); // Copy sunlight data - data.target_block = v3POS(blockpos.X, blockpos.Y - 1, blockpos.Z); + data.target_block = v3pos_t(blockpos.X, blockpos.Y - 1, blockpos.Z); for (s16 z = 0; z < MAP_BLOCKSIZE; z++) for (s16 x = 0; x < MAP_BLOCKSIZE; x++) { - data.data.emplace_back(v2POS(x, z), lights[z][x]); + data.data.emplace_back(v2pos_t(x, z), lights[z][x]); } // Propagate sunlight and shadow below the voxel manipulator. while (!data.data.empty()) { @@ -1231,7 +1231,7 @@ void repair_block_light(ServerMap *map, MapBlock *block, // For each border of the block: for (const VoxelArea &a : block_pad) { - v3POS relpos; + v3pos_t relpos; // For each node of the border: for (relpos.X = a.MinEdge.X; relpos.X <= a.MaxEdge.X; relpos.X++) for (relpos.Z = a.MinEdge.Z; relpos.Z <= a.MaxEdge.Z; relpos.Z++) @@ -1321,7 +1321,7 @@ void VoxelLineIterator::next() } } -POS VoxelLineIterator::getIndex(v3POS voxel){ +pos_t VoxelLineIterator::getIndex(v3pos_t voxel){ return abs(voxel.X - m_start_node_pos.X) + abs(voxel.Y - m_start_node_pos.Y) + diff --git a/src/voxelalgorithms.h b/src/voxelalgorithms.h index c6b12a4e8c..a1d64b2047 100644 --- a/src/voxelalgorithms.h +++ b/src/voxelalgorithms.h @@ -45,8 +45,8 @@ namespace voxalgo */ void update_lighting_nodes( Map *map, - const std::vector> &oldnodes, - std::map &modified_blocks); + const std::vector> &oldnodes, + std::map &modified_blocks); /*! * Updates borders of the given mapblock. @@ -58,7 +58,7 @@ void update_lighting_nodes( * the function modified */ void update_block_border_lighting(Map *map, MapBlock *block, - std::map &modified_blocks); + std::map &modified_blocks); /*! * Copies back nodes from a voxel manipulator @@ -69,7 +69,7 @@ void update_block_border_lighting(Map *map, MapBlock *block, * the function modified */ void blit_back_with_light(ServerMap *map, MMVManip *vm, - std::map *modified_blocks); + std::map *modified_blocks); /*! * Corrects the light in a map block. @@ -78,7 +78,7 @@ void blit_back_with_light(ServerMap *map, MMVManip *vm, * \param block the block to update */ void repair_block_light(ServerMap *map, MapBlock *block, - std::map *modified_blocks); + std::map *modified_blocks); /*! * This class iterates trough voxels that intersect with @@ -108,13 +108,13 @@ struct VoxelLineIterator * Direction of the line. Each component can be -1 or 1 (if a * component of the line's vector is 0, then there will be 1). */ - v3POS m_step_directions { 1, 1, 1 }; + v3pos_t m_step_directions { 1, 1, 1 }; //! Position of the current node. - v3POS m_current_node_pos; + v3pos_t m_current_node_pos; //! Index of the current node s16 m_current_index = 0; //! Position of the start node. - v3POS m_start_node_pos; + v3pos_t m_start_node_pos; //! Index of the last node s16 m_last_index; @@ -151,7 +151,7 @@ struct VoxelLineIterator * If voxel does not intersect with the line, * the result is undefined. */ - POS getIndex(v3POS voxel); + pos_t getIndex(v3pos_t voxel); }; } // namespace voxalgo From 0d20bbd4e17063c92b1a3ef958c9c1b664655461 Mon Sep 17 00:00:00 2001 From: proller Date: Tue, 7 Dec 2021 18:46:49 +0300 Subject: [PATCH 04/36] Fix replace bug --- src/network/networkprotocol.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/network/networkprotocol.h b/src/network/networkprotocol.h index 25f5beabeb..3f33d2994c 100644 --- a/src/network/networkprotocol.h +++ b/src/network/networkprotocol.h @@ -284,7 +284,7 @@ enum ToClientCommand */ TOCLIENT_REMOVENODE = 0x22, - TOCLIENT_PLAYERpos_t = 0x23, // Obsolete + TOCLIENT_PLAYERPOS = 0x23, // Obsolete TOCLIENT_PLAYERINFO = 0x24, // Obsolete TOCLIENT_OPT_BLOCK_NOT_FOUND = 0x25, // Obsolete TOCLIENT_SECTORMETA = 0x26, // Obsolete From edc2cff0cd96a4c073809339706ec5f839c1ff92 Mon Sep 17 00:00:00 2001 From: proller Date: Tue, 7 Dec 2021 19:48:32 +0300 Subject: [PATCH 05/36] Better names, more bpos --- src/client/client.cpp | 26 +++---- src/client/client.h | 8 +- src/client/clientmap.cpp | 4 +- src/client/clientmap.h | 2 +- src/client/content_mapblock.cpp | 3 +- src/client/mapblock_mesh.cpp | 16 ++-- src/client/mapblock_mesh.h | 4 +- src/client/mesh_generator_thread.cpp | 22 +++--- src/client/mesh_generator_thread.h | 18 ++--- src/client/minimap.cpp | 12 +-- src/client/minimap.h | 2 +- src/clientiface.h | 16 ++-- src/irrlichttypes.h | 3 +- src/map.h | 3 +- src/mapblock.h | 7 +- src/mapgen/mapgen_carpathian.cpp | 12 +-- src/mapgen/mapgen_flat.cpp | 12 +-- src/mapgen/mapgen_fractal.cpp | 12 +-- src/mapgen/mapgen_singlenode.cpp | 4 +- src/mapgen/mapgen_v5.cpp | 12 +-- src/mapgen/mapgen_v6.cpp | 8 +- src/mapgen/mapgen_v7.cpp | 12 +-- src/mapgen/mapgen_valleys.cpp | 12 +-- src/mapgen/mg_schematic.cpp | 8 +- src/mapgen/treegen.cpp | 4 +- src/mapsector.cpp | 2 +- src/network/clientpackethandler.cpp | 4 +- src/script/common/c_content.cpp | 8 +- src/script/common/c_converter.cpp | 4 +- src/script/common/c_converter.h | 10 +-- src/script/cpp_api/s_client.cpp | 4 +- src/script/cpp_api/s_env.cpp | 10 +-- src/script/cpp_api/s_env.h | 2 +- src/script/cpp_api/s_node.cpp | 16 ++-- src/script/cpp_api/s_nodemeta.cpp | 12 +-- src/script/lua_api/l_areastore.cpp | 12 +-- src/script/lua_api/l_client.cpp | 4 +- src/script/lua_api/l_env.cpp | 108 +++++++++++++-------------- src/script/lua_api/l_inventory.cpp | 4 +- src/script/lua_api/l_mapgen.cpp | 30 ++++---- src/script/lua_api/l_minimap.cpp | 4 +- src/script/lua_api/l_noise.cpp | 6 +- src/script/lua_api/l_object.cpp | 2 +- src/script/lua_api/l_rollback.cpp | 4 +- src/script/lua_api/l_vmanip.cpp | 26 +++---- src/server.cpp | 14 ++-- src/server.h | 2 +- src/server/serveractiveobject.h | 2 +- src/serverenvironment.cpp | 50 ++++++------- src/serverenvironment.h | 22 +++--- src/util/areastore.cpp | 2 +- src/util/areastore.h | 2 +- src/voxelalgorithms.h | 2 +- 53 files changed, 308 insertions(+), 302 deletions(-) diff --git a/src/client/client.cpp b/src/client/client.cpp index 478bca8271..60787cf5ea 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -384,7 +384,7 @@ void Client::step(float dtime) */ const float map_timer_and_unload_dtime = 5.25; if(m_map_timer_and_unload_interval.step(dtime, map_timer_and_unload_dtime)) { - std::vector deleted_blocks; + std::vector deleted_blocks; m_env.getMap().timerUpdate(map_timer_and_unload_dtime, g_settings->getFloat("client_unload_unused_data_timeout"), g_settings->getS32("client_mapblock_limit"), @@ -395,8 +395,8 @@ void Client::step(float dtime) NOTE: This loop is intentionally iterated the way it is. */ - std::vector::iterator i = deleted_blocks.begin(); - std::vector sendlist; + std::vector::iterator i = deleted_blocks.begin(); + std::vector sendlist; for(;;) { if(sendlist.size() == 255 || i == deleted_blocks.end()) { if(sendlist.empty()) @@ -489,7 +489,7 @@ void Client::step(float dtime) */ { int num_processed_meshes = 0; - std::vector blocks_to_ack; + std::vector blocks_to_ack; while (!m_mesh_update_thread.m_queue_out.empty()) { num_processed_meshes++; @@ -1097,24 +1097,24 @@ void Client::startAuth(AuthMechanism chosen_auth_mechanism) } } -void Client::sendDeletedBlocks(std::vector &blocks) +void Client::sendDeletedBlocks(std::vector &blocks) { NetworkPacket pkt(TOSERVER_DELETEDBLOCKS, 1 + sizeof(v3pos_t) * blocks.size()); pkt << (u8) blocks.size(); - for (const v3pos_t &block : blocks) { + for (const v3bpos_t &block : blocks) { pkt << block; } Send(&pkt); } -void Client::sendGotBlocks(const std::vector &blocks) +void Client::sendGotBlocks(const std::vector &blocks) { NetworkPacket pkt(TOSERVER_GOTBLOCKS, 1 + 6 * blocks.size()); pkt << (u8) blocks.size(); - for (const v3pos_t &block : blocks) + for (const v3bpos_t &block : blocks) pkt << block; Send(&pkt); @@ -1395,7 +1395,7 @@ void Client::addNode(v3pos_t p, MapNode n, bool remove_metadata) { //TimeTaker timer1("Client::addNode()"); - std::map modified_blocks; + std::map modified_blocks; try { //TimeTaker timer3("Client::addNode(): addNodeAndUpdate"); @@ -1637,7 +1637,7 @@ void Client::addUpdateMeshTaskForNode(v3pos_t nodepos, bool ack_to_server, bool } v3bpos_t blockpos = getNodeBlockPos(nodepos); - v3pos_t blockpos_relative = blockpos * MAP_BLOCKSIZE; + v3pos_t blockpos_relative = getBlockPosRelative(blockpos); try{ addUpdateMeshTask(blockpos, ack_to_server, urgent); @@ -1647,7 +1647,7 @@ void Client::addUpdateMeshTaskForNode(v3pos_t nodepos, bool ack_to_server, bool // Leading edge if(nodepos.X == blockpos_relative.X){ try{ - v3bpos_t p = blockpos + v3pos_t(-1,0,0); + v3bpos_t p = blockpos + v3bpos_t(-1,0,0); addUpdateMeshTask(p, false, urgent); } catch(InvalidPositionException &e){} @@ -1655,7 +1655,7 @@ void Client::addUpdateMeshTaskForNode(v3pos_t nodepos, bool ack_to_server, bool if(nodepos.Y == blockpos_relative.Y){ try{ - v3bpos_t p = blockpos + v3pos_t(0,-1,0); + v3bpos_t p = blockpos + v3bpos_t(0,-1,0); addUpdateMeshTask(p, false, urgent); } catch(InvalidPositionException &e){} @@ -1663,7 +1663,7 @@ void Client::addUpdateMeshTaskForNode(v3pos_t nodepos, bool ack_to_server, bool if(nodepos.Z == blockpos_relative.Z){ try{ - v3bpos_t p = blockpos + v3pos_t(0,0,-1); + v3bpos_t p = blockpos + v3bpos_t(0,0,-1); addUpdateMeshTask(p, false, urgent); } catch(InvalidPositionException &e){} diff --git a/src/client/client.h b/src/client/client.h index fe1cb3a8a1..6c75f5686c 100644 --- a/src/client/client.h +++ b/src/client/client.h @@ -304,9 +304,9 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef u64 getMapSeed(){ return m_map_seed; } - void addUpdateMeshTask(v3pos_t blockpos, bool ack_to_server=false, bool urgent=false); + void addUpdateMeshTask(v3bpos_t blockpos, bool ack_to_server=false, bool urgent=false); // Including blocks at appropriate edges - void addUpdateMeshTaskWithEdge(v3pos_t blockpos, bool ack_to_server=false, bool urgent=false); + void addUpdateMeshTaskWithEdge(v3bpos_t blockpos, bool ack_to_server=false, bool urgent=false); void addUpdateMeshTaskForNode(v3pos_t nodepos, bool ack_to_server=false, bool urgent=false); void updateCameraOffset(v3pos_t camera_offset) @@ -458,8 +458,8 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef void sendInit(const std::string &playerName); void promptConfirmRegistration(AuthMechanism chosen_auth_mechanism); void startAuth(AuthMechanism chosen_auth_mechanism); - void sendDeletedBlocks(std::vector &blocks); - void sendGotBlocks(const std::vector &blocks); + void sendDeletedBlocks(std::vector &blocks); + void sendGotBlocks(const std::vector &blocks); void sendRemovedSounds(std::vector &soundList); // Helper function diff --git a/src/client/clientmap.cpp b/src/client/clientmap.cpp index 5fb7783c28..fe29e78c15 100644 --- a/src/client/clientmap.cpp +++ b/src/client/clientmap.cpp @@ -330,11 +330,11 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass) MeshBufListList grouped_buffers; struct DrawDescriptor { - v3pos_t m_pos; + v3bpos_t m_pos; scene::IMeshBuffer *m_buffer; bool m_reuse_material; - DrawDescriptor(const v3pos_t &pos, scene::IMeshBuffer *buffer, bool reuse_material) : + DrawDescriptor(const v3bpos_t &pos, scene::IMeshBuffer *buffer, bool reuse_material) : m_pos(pos), m_buffer(buffer), m_reuse_material(reuse_material) {} }; diff --git a/src/client/clientmap.h b/src/client/clientmap.h index f53e3d8636..391744cff6 100644 --- a/src/client/clientmap.h +++ b/src/client/clientmap.h @@ -38,7 +38,7 @@ struct MapDrawControl struct MeshBufList { video::SMaterial m; - std::vector> bufs; + std::vector> bufs; }; struct MeshBufListList diff --git a/src/client/content_mapblock.cpp b/src/client/content_mapblock.cpp index 544659651d..45b9b983d7 100644 --- a/src/client/content_mapblock.cpp +++ b/src/client/content_mapblock.cpp @@ -22,6 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "util/numeric.h" #include "util/directiontables.h" #include "mapblock_mesh.h" +#include "mapblock.h" #include "settings.h" #include "nodedef.h" #include "client/tile.h" @@ -66,7 +67,7 @@ MapblockMeshGenerator::MapblockMeshGenerator(MeshMakeData *input, MeshCollector collector(output), nodedef(data->m_client->ndef()), meshmanip(mm), - blockpos_nodes(data->m_blockpos * MAP_BLOCKSIZE) + blockpos_nodes(getBlockPosRelative(data->m_blockpos)) { enable_mesh_cache = g_settings->getBool("enable_mesh_cache") && !data->m_smooth_lighting; // Mesh cache is not supported with smooth lighting diff --git a/src/client/mapblock_mesh.cpp b/src/client/mapblock_mesh.cpp index 8081ad79ef..210da303ff 100644 --- a/src/client/mapblock_mesh.cpp +++ b/src/client/mapblock_mesh.cpp @@ -40,11 +40,11 @@ MeshMakeData::MeshMakeData(Client *client, bool use_shaders): m_use_shaders(use_shaders) {} -void MeshMakeData::fillBlockDataBegin(const v3pos_t &blockpos) +void MeshMakeData::fillBlockDataBegin(const v3bpos_t &blockpos) { m_blockpos = blockpos; - v3pos_t blockpos_nodes = m_blockpos*MAP_BLOCKSIZE; + v3pos_t blockpos_nodes = getBlockPosRelative(m_blockpos); m_vmanip.clear(); VoxelArea voxel_area(blockpos_nodes - v3pos_t(1,1,1) * MAP_BLOCKSIZE, @@ -57,8 +57,8 @@ void MeshMakeData::fillBlockData(const v3pos_t &block_offset, MapNode *data) v3pos_t data_size(MAP_BLOCKSIZE, MAP_BLOCKSIZE, MAP_BLOCKSIZE); VoxelArea data_area(v3pos_t(0,0,0), data_size - v3pos_t(1,1,1)); - v3pos_t bp = m_blockpos + block_offset; - v3pos_t blockpos_nodes = bp * MAP_BLOCKSIZE; + v3bpos_t bp = m_blockpos + v3bpos_t(block_offset.X, block_offset.Y, block_offset.Z); + v3pos_t blockpos_nodes = getBlockPosRelative(bp); m_vmanip.copyFrom(data, data_area, v3pos_t(0,0,0), blockpos_nodes, data_size); } @@ -72,7 +72,7 @@ void MeshMakeData::fill(MapBlock *block) Map *map = block->getParent(); for (const v3pos_t &dir : g_26dirs) { - v3pos_t bp = m_blockpos + dir; + v3bpos_t bp = m_blockpos + v3bpos_t(dir.X, dir.Y, dir.Z); MapBlock *b = map->getBlockNoCreateNoEx(bp); if(b) fillBlockData(dir, b->getData()); @@ -82,7 +82,7 @@ void MeshMakeData::fill(MapBlock *block) void MeshMakeData::setCrack(int crack_level, v3pos_t crack_pos) { if (crack_level >= 0) - m_crack_pos_relative = crack_pos - m_blockpos*MAP_BLOCKSIZE; + m_crack_pos_relative = crack_pos - getBlockPosRelative(m_blockpos); } void MeshMakeData::setSmoothLighting(bool smooth_lighting) @@ -779,7 +779,7 @@ static void getTileInfo( { VoxelManipulator &vmanip = data->m_vmanip; const NodeDefManager *ndef = data->m_client->ndef(); - v3pos_t blockpos_nodes = data->m_blockpos * MAP_BLOCKSIZE; + v3pos_t blockpos_nodes = getBlockPosRelative(data->m_blockpos); const MapNode &n0 = vmanip.getNodeRefUnsafe(blockpos_nodes + p); @@ -1023,7 +1023,7 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3pos_t camera_offset): if (data->m_client->getMinimap()) { m_minimap_mapblock = new MinimapMapblock; m_minimap_mapblock->getMinimapNodes( - &data->m_vmanip, data->m_blockpos * MAP_BLOCKSIZE); + &data->m_vmanip, getBlockPosRelative(data->m_blockpos)); } // 4-21ms for MAP_BLOCKSIZE=16 (NOTE: probably outdated) diff --git a/src/client/mapblock_mesh.h b/src/client/mapblock_mesh.h index 39ea9ae158..6359a563c1 100644 --- a/src/client/mapblock_mesh.h +++ b/src/client/mapblock_mesh.h @@ -39,7 +39,7 @@ struct MinimapMapblock; struct MeshMakeData { VoxelManipulator m_vmanip; - v3pos_t m_blockpos = v3pos_t(-1337,-1337,-1337); + v3bpos_t m_blockpos = v3bpos_t(-1337,-1337,-1337); v3pos_t m_crack_pos_relative = v3pos_t(-1337,-1337,-1337); bool m_smooth_lighting = false; @@ -51,7 +51,7 @@ struct MeshMakeData /* Copy block data manually (to allow optimizations by the caller) */ - void fillBlockDataBegin(const v3pos_t &blockpos); + void fillBlockDataBegin(const v3bpos_t &blockpos); void fillBlockData(const v3pos_t &block_offset, MapNode *data); /* diff --git a/src/client/mesh_generator_thread.cpp b/src/client/mesh_generator_thread.cpp index de658d4793..019e3f0bd4 100644 --- a/src/client/mesh_generator_thread.cpp +++ b/src/client/mesh_generator_thread.cpp @@ -69,7 +69,7 @@ MeshUpdateQueue::~MeshUpdateQueue() } } -void MeshUpdateQueue::addBlock(Map *map, v3pos_t p, bool ack_block_to_server, bool urgent) +void MeshUpdateQueue::addBlock(Map *map, v3bpos_t p, bool ack_block_to_server, bool urgent) { MutexAutoLock lock(m_mutex); @@ -82,13 +82,13 @@ void MeshUpdateQueue::addBlock(Map *map, v3pos_t p, bool ack_block_to_server, bo std::vector cached_blocks; size_t cache_hit_counter = 0; cached_blocks.reserve(3*3*3); - v3pos_t dp; + v3bpos_t dp; for (dp.X = -1; dp.X <= 1; dp.X++) for (dp.Y = -1; dp.Y <= 1; dp.Y++) for (dp.Z = -1; dp.Z <= 1; dp.Z++) { - v3pos_t p1 = p + dp; + v3bpos_t p1 = p + dp; CachedMapBlockData *cached_block; - if (dp == v3pos_t(0, 0, 0)) + if (dp == v3bpos_t(0, 0, 0)) cached_block = cacheBlock(map, p1, FORCE_UPDATE); else cached_block = cacheBlock(map, p1, SKIP_UPDATE_IF_ALREADY_CACHED, @@ -156,11 +156,11 @@ QueuedMeshUpdate *MeshUpdateQueue::pop() return NULL; } -CachedMapBlockData* MeshUpdateQueue::cacheBlock(Map *map, v3pos_t p, UpdateMode mode, +CachedMapBlockData* MeshUpdateQueue::cacheBlock(Map *map, v3bpos_t p, UpdateMode mode, size_t *cache_hit_counter) { CachedMapBlockData *cached_block = nullptr; - std::map::iterator it = + std::map::iterator it = m_cache.find(p); if (it != m_cache.end()) { @@ -193,9 +193,9 @@ CachedMapBlockData* MeshUpdateQueue::cacheBlock(Map *map, v3pos_t p, UpdateMode return cached_block; } -CachedMapBlockData* MeshUpdateQueue::getCachedBlock(const v3pos_t &p) +CachedMapBlockData* MeshUpdateQueue::getCachedBlock(const v3bpos_t &p) { - std::map::iterator it = m_cache.find(p); + std::map::iterator it = m_cache.find(p); if (it != m_cache.end()) { return it->second; } @@ -216,7 +216,7 @@ void MeshUpdateQueue::fillDataFromMapBlockCache(QueuedMeshUpdate *q) for (dp.X = -1; dp.X <= 1; dp.X++) for (dp.Y = -1; dp.Y <= 1; dp.Y++) for (dp.Z = -1; dp.Z <= 1; dp.Z++) { - v3pos_t p = q->p + dp; + v3bpos_t p = q->p + v3bpos_t(dp.X, dp.Y, dp.Z); CachedMapBlockData *cached_block = getCachedBlock(p); if (cached_block) { cached_block->refcount_from_queue--; @@ -246,7 +246,7 @@ void MeshUpdateQueue::cleanupCache() int t_now = time(0); - for (std::map::iterator it = m_cache.begin(); + for (std::map::iterator it = m_cache.begin(); it != m_cache.end(); ) { CachedMapBlockData *cached_block = it->second; if (cached_block->refcount_from_queue == 0 && @@ -271,7 +271,7 @@ MeshUpdateThread::MeshUpdateThread(Client *client): m_generation_interval = rangelim(m_generation_interval, 0, 50); } -void MeshUpdateThread::updateBlock(Map *map, v3pos_t p, bool ack_block_to_server, +void MeshUpdateThread::updateBlock(Map *map, v3bpos_t p, bool ack_block_to_server, bool urgent) { // Allow the MeshUpdateQueue to do whatever it wants diff --git a/src/client/mesh_generator_thread.h b/src/client/mesh_generator_thread.h index 65ad89860c..8667c733ac 100644 --- a/src/client/mesh_generator_thread.h +++ b/src/client/mesh_generator_thread.h @@ -27,7 +27,7 @@ with this program; if not, write to the Free Software Foundation, Inc., struct CachedMapBlockData { - v3pos_t p = v3pos_t(-1337, -1337, -1337); + v3bpos_t p = v3bpos_t(-1337, -1337, -1337); MapNode *data = nullptr; // A copy of the MapBlock's data member int refcount_from_queue = 0; std::time_t last_used_timestamp = std::time(0); @@ -38,7 +38,7 @@ struct CachedMapBlockData struct QueuedMeshUpdate { - v3pos_t p = v3pos_t(-1337, -1337, -1337); + v3bpos_t p = v3bpos_t(-1337, -1337, -1337); bool ack_block_to_server = false; int crack_level = -1; v3pos_t crack_pos; @@ -66,7 +66,7 @@ class MeshUpdateQueue // Caches the block at p and its neighbors (if needed) and queues a mesh // update for the block at p - void addBlock(Map *map, v3pos_t p, bool ack_block_to_server, bool urgent); + void addBlock(Map *map, v3bpos_t p, bool ack_block_to_server, bool urgent); // Returned pointer must be deleted // Returns NULL if queue is empty @@ -81,8 +81,8 @@ class MeshUpdateQueue private: Client *m_client; std::vector m_queue; - std::set m_urgents; - std::map m_cache; + std::set m_urgents; + std::map m_cache; std::mutex m_mutex; // TODO: Add callback to update these when g_settings changes @@ -90,16 +90,16 @@ class MeshUpdateQueue bool m_cache_smooth_lighting; int m_meshgen_block_cache_size; - CachedMapBlockData *cacheBlock(Map *map, v3pos_t p, UpdateMode mode, + CachedMapBlockData *cacheBlock(Map *map, v3bpos_t p, UpdateMode mode, size_t *cache_hit_counter = NULL); - CachedMapBlockData *getCachedBlock(const v3pos_t &p); + CachedMapBlockData *getCachedBlock(const v3bpos_t &p); void fillDataFromMapBlockCache(QueuedMeshUpdate *q); void cleanupCache(); }; struct MeshUpdateResult { - v3pos_t p = v3pos_t(-1338, -1338, -1338); + v3bpos_t p = v3bpos_t(-1338, -1338, -1338); MapBlockMesh *mesh = nullptr; bool ack_block_to_server = false; @@ -113,7 +113,7 @@ class MeshUpdateThread : public UpdateThread // Caches the block at p and its neighbors (if needed) and queues a mesh // update for the block at p - void updateBlock(Map *map, v3pos_t p, bool ack_block_to_server, bool urgent); + void updateBlock(Map *map, v3bpos_t p, bool ack_block_to_server, bool urgent); v3pos_t m_camera_offset; MutexedQueue m_queue_out; diff --git a/src/client/minimap.cpp b/src/client/minimap.cpp index 1e79339d43..bde92e3401 100644 --- a/src/client/minimap.cpp +++ b/src/client/minimap.cpp @@ -42,7 +42,7 @@ MinimapUpdateThread::~MinimapUpdateThread() } } -bool MinimapUpdateThread::pushBlockUpdate(v3pos_t pos, MinimapMapblock *data) +bool MinimapUpdateThread::pushBlockUpdate(v3bpos_t pos, MinimapMapblock *data) { MutexAutoLock lock(m_queue_mutex); @@ -78,7 +78,7 @@ bool MinimapUpdateThread::popBlockUpdate(QueuedMinimapUpdate *update) return true; } -void MinimapUpdateThread::enqueueBlock(v3pos_t pos, MinimapMapblock *data) +void MinimapUpdateThread::enqueueBlock(v3bpos_t pos, MinimapMapblock *data) { pushBlockUpdate(pos, data); deferUpdate(); @@ -92,14 +92,14 @@ void MinimapUpdateThread::doUpdate() while (popBlockUpdate(&update)) { if (update.data) { // Swap two values in the map using single lookup - std::pair::iterator, bool> + std::pair::iterator, bool> result = m_blocks_cache.insert(std::make_pair(update.pos, update.data)); if (!result.second) { delete result.first->second; result.first->second = update.data; } } else { - std::map::iterator it; + std::map::iterator it; it = m_blocks_cache.find(update.pos); if (it != m_blocks_cache.end()) { delete it->second; @@ -144,7 +144,7 @@ void MinimapUpdateThread::getMap(v3pos_t pos, s16 size, pos_t height) continue; const MinimapMapblock &block = *pblock->second; - v3pos_t block_node_min(blockpos * MAP_BLOCKSIZE); + v3pos_t block_node_min = getBlockPosRelative(blockpos); v3pos_t block_node_max(block_node_min + MAP_BLOCKSIZE - 1); // clip v3pos_t range_min = componentwise_max(block_node_min, pos_min); @@ -260,7 +260,7 @@ Minimap::~Minimap() delete m_minimap_update_thread; } -void Minimap::addBlock(v3pos_t pos, MinimapMapblock *data) +void Minimap::addBlock(v3bpos_t pos, MinimapMapblock *data) { m_minimap_update_thread->enqueueBlock(pos, data); } diff --git a/src/client/minimap.h b/src/client/minimap.h index 4c196f5a70..748fd02795 100644 --- a/src/client/minimap.h +++ b/src/client/minimap.h @@ -95,7 +95,7 @@ class MinimapUpdateThread : public UpdateThread { MinimapUpdateThread() : UpdateThread("Minimap") {} virtual ~MinimapUpdateThread(); - void getMap(v3bpos_t pos, s16 size, pos_t height); + void getMap(v3pos_t pos, s16 size, pos_t height); void enqueueBlock(v3bpos_t pos, MinimapMapblock *data); bool pushBlockUpdate(v3bpos_t pos, MinimapMapblock *data); bool popBlockUpdate(QueuedMinimapUpdate *update); diff --git a/src/clientiface.h b/src/clientiface.h index 6d9f990d09..158368a958 100644 --- a/src/clientiface.h +++ b/src/clientiface.h @@ -258,12 +258,12 @@ class RemoteClient void GetNextBlocks(ServerEnvironment *env, EmergeManager* emerge, float dtime, std::vector &dest); - void GotBlock(v3pos_t p); + void GotBlock(v3bpos_t p); - void SentBlock(v3pos_t p); + void SentBlock(v3bpos_t p); - void SetBlockNotSent(v3pos_t p); - void SetBlocksNotSent(std::map &blocks); + void SetBlockNotSent(v3bpos_t p); + void SetBlocksNotSent(std::map &blocks); /** * tell client about this block being modified right now. @@ -271,11 +271,11 @@ class RemoteClient * while modification is processed by server * @param p position of modified block */ - void ResendBlockIfOnWire(v3pos_t p); + void ResendBlockIfOnWire(v3bpos_t p); u32 getSendingCount() const { return m_blocks_sending.size(); } - bool isBlockSent(v3pos_t p) const + bool isBlockSent(v3bpos_t p) const { return m_blocks_sent.find(p) != m_blocks_sent.end(); } @@ -369,7 +369,7 @@ class RemoteClient List of block positions. No MapBlock* is stored here because the blocks can get deleted. */ - std::set m_blocks_sent; + std::set m_blocks_sent; pos_t m_nearest_unsent_d = 0; v3pos_t m_last_center; v3f m_last_camera_dir; @@ -452,7 +452,7 @@ class ClientInterface { std::vector getClientIDs(ClientState min_state=CS_Active); /* mark block as not sent to active client sessions */ - void markBlockposAsNotSent(const v3pos_t &pos); + void markBlockposAsNotSent(const v3bpos_t &pos); /* verify is server user limit was reached */ bool isUserLimitReached(); diff --git a/src/irrlichttypes.h b/src/irrlichttypes.h index 76e6357d6d..ded81a9a7b 100644 --- a/src/irrlichttypes.h +++ b/src/irrlichttypes.h @@ -67,10 +67,9 @@ namespace core { // Node position using pos_t = irr::s32; -// Block position. In future can be renamed to pos_t +// Block position. using bpos_t = irr::s32; - #else using pos_t = irr::s16; using bpos_t = irr::s16; diff --git a/src/map.h b/src/map.h index 4f56ec35d4..69a3c4a878 100644 --- a/src/map.h +++ b/src/map.h @@ -103,7 +103,8 @@ struct MapEditEvent { VoxelArea a; for (v3bpos_t p : modified_blocks) { - v3pos_t np1 = getContainerPos(p, MAP_BLOCKSIZE); + v3bpos_t np1b = getContainerPos(v3pos_t(p.X, p.Y, p.Z), MAP_BLOCKSIZE); + v3pos_t np1(np1b.X, np1b.Y, np1b.Z); v3pos_t np2 = np1 + v3pos_t(1,1,1)*MAP_BLOCKSIZE - v3pos_t(1,1,1); a.addPoint(np1); a.addPoint(np2); diff --git a/src/mapblock.h b/src/mapblock.h index bda6e4ed24..28e1596c4f 100644 --- a/src/mapblock.h +++ b/src/mapblock.h @@ -74,7 +74,7 @@ class VoxelManipulator; class MapBlock { public: - MapBlock(Map *parent, v3pos_t pos, IGameDef *gamedef, bool dummy=false); + MapBlock(Map *parent, v3bpos_t pos, IGameDef *gamedef, bool dummy=false); ~MapBlock(); /*virtual u16 nodeContainerId() const @@ -635,6 +635,11 @@ inline void getNodeBlockPosWithOffset(const v3pos_t &p, v3bpos_t &block, v3pos_t getContainerPosWithOffset(p, MAP_BLOCKSIZE, block, offset); } +inline v3pos_t getBlockPosRelative(const v3bpos_t &p) +{ + return v3pos_t(p.X, p.Y, p.Z) * MAP_BLOCKSIZE; +} + /* Get a quick string to describe what a block actually contains */ diff --git a/src/mapgen/mapgen_carpathian.cpp b/src/mapgen/mapgen_carpathian.cpp index 4d1bca500e..d85ed5b48e 100644 --- a/src/mapgen/mapgen_carpathian.cpp +++ b/src/mapgen/mapgen_carpathian.cpp @@ -265,12 +265,12 @@ void MapgenCarpathian::makeChunk(BlockMakeData *data) this->vm = data->vmanip; this->ndef = data->nodedef; - v3pos_t blockpos_min = data->blockpos_min; - v3pos_t blockpos_max = data->blockpos_max; - node_min = blockpos_min * MAP_BLOCKSIZE; - node_max = (blockpos_max + v3pos_t(1, 1, 1)) * MAP_BLOCKSIZE - v3pos_t(1, 1, 1); - full_node_min = (blockpos_min - 1) * MAP_BLOCKSIZE; - full_node_max = (blockpos_max + 2) * MAP_BLOCKSIZE - v3pos_t(1, 1, 1); + v3bpos_t blockpos_min = data->blockpos_min; + v3bpos_t blockpos_max = data->blockpos_max; + node_min = getBlockPosRelative(blockpos_min); + node_max = getBlockPosRelative(blockpos_max + v3bpos_t(1, 1, 1)) - v3pos_t(1, 1, 1); + full_node_min = getBlockPosRelative(blockpos_min - 1); + full_node_max = getBlockPosRelative(blockpos_max + 2) - v3pos_t(1, 1, 1); // Create a block-specific seed blockseed = getBlockSeed2(full_node_min, seed); diff --git a/src/mapgen/mapgen_flat.cpp b/src/mapgen/mapgen_flat.cpp index 20749d6d0a..982883d4fd 100644 --- a/src/mapgen/mapgen_flat.cpp +++ b/src/mapgen/mapgen_flat.cpp @@ -215,12 +215,12 @@ void MapgenFlat::makeChunk(BlockMakeData *data) this->ndef = data->nodedef; //TimeTaker t("makeChunk"); - v3pos_t blockpos_min = data->blockpos_min; - v3pos_t blockpos_max = data->blockpos_max; - node_min = blockpos_min * MAP_BLOCKSIZE; - node_max = (blockpos_max + v3pos_t(1, 1, 1)) * MAP_BLOCKSIZE - v3pos_t(1, 1, 1); - full_node_min = (blockpos_min - 1) * MAP_BLOCKSIZE; - full_node_max = (blockpos_max + 2) * MAP_BLOCKSIZE - v3pos_t(1, 1, 1); + v3bpos_t blockpos_min = data->blockpos_min; + v3bpos_t blockpos_max = data->blockpos_max; + node_min = getBlockPosRelative(blockpos_min); + node_max = getBlockPosRelative(blockpos_max + v3bpos_t(1, 1, 1)) - v3pos_t(1, 1, 1); + full_node_min = getBlockPosRelative(blockpos_min - 1); + full_node_max = getBlockPosRelative(blockpos_max + 2) - v3pos_t(1, 1, 1); blockseed = getBlockSeed2(full_node_min, seed); diff --git a/src/mapgen/mapgen_fractal.cpp b/src/mapgen/mapgen_fractal.cpp index 71179bf0f4..4c1e9a3a17 100644 --- a/src/mapgen/mapgen_fractal.cpp +++ b/src/mapgen/mapgen_fractal.cpp @@ -216,12 +216,12 @@ void MapgenFractal::makeChunk(BlockMakeData *data) this->vm = data->vmanip; this->ndef = data->nodedef; - v3pos_t blockpos_min = data->blockpos_min; - v3pos_t blockpos_max = data->blockpos_max; - node_min = blockpos_min * MAP_BLOCKSIZE; - node_max = (blockpos_max + v3pos_t(1, 1, 1)) * MAP_BLOCKSIZE - v3pos_t(1, 1, 1); - full_node_min = (blockpos_min - 1) * MAP_BLOCKSIZE; - full_node_max = (blockpos_max + 2) * MAP_BLOCKSIZE - v3pos_t(1, 1, 1); + v3bpos_t blockpos_min = data->blockpos_min; + v3bpos_t blockpos_max = data->blockpos_max; + node_min = getBlockPosRelative(blockpos_min); + node_max = getBlockPosRelative(blockpos_max + v3bpos_t(1, 1, 1)) - v3pos_t(1, 1, 1); + full_node_min = getBlockPosRelative(blockpos_min - 1); + full_node_max = getBlockPosRelative(blockpos_max + 2) - v3pos_t(1, 1, 1); blockseed = getBlockSeed2(full_node_min, seed); diff --git a/src/mapgen/mapgen_singlenode.cpp b/src/mapgen/mapgen_singlenode.cpp index 1c1a65b714..9988faad88 100644 --- a/src/mapgen/mapgen_singlenode.cpp +++ b/src/mapgen/mapgen_singlenode.cpp @@ -59,8 +59,8 @@ void MapgenSinglenode::makeChunk(BlockMakeData *data) v3bpos_t blockpos_max = data->blockpos_max; // Area of central chunk - v3pos_t node_min = blockpos_min * MAP_BLOCKSIZE; - v3pos_t node_max = (blockpos_max + v3pos_t(1, 1, 1)) * MAP_BLOCKSIZE - v3pos_t(1, 1, 1); + v3pos_t node_min = getBlockPosRelative(blockpos_min); + v3pos_t node_max = getBlockPosRelative(blockpos_max + v3bpos_t(1, 1, 1)) - v3pos_t(1, 1, 1); blockseed = getBlockSeed2(node_min, data->seed); diff --git a/src/mapgen/mapgen_v5.cpp b/src/mapgen/mapgen_v5.cpp index e361d6de2b..0c67bdc237 100644 --- a/src/mapgen/mapgen_v5.cpp +++ b/src/mapgen/mapgen_v5.cpp @@ -207,12 +207,12 @@ void MapgenV5::makeChunk(BlockMakeData *data) this->ndef = data->nodedef; //TimeTaker t("makeChunk"); - v3pos_t blockpos_min = data->blockpos_min; - v3pos_t blockpos_max = data->blockpos_max; - node_min = blockpos_min * MAP_BLOCKSIZE; - node_max = (blockpos_max + v3pos_t(1, 1, 1)) * MAP_BLOCKSIZE - v3pos_t(1, 1, 1); - full_node_min = (blockpos_min - 1) * MAP_BLOCKSIZE; - full_node_max = (blockpos_max + 2) * MAP_BLOCKSIZE - v3pos_t(1, 1, 1); + v3bpos_t blockpos_min = data->blockpos_min; + v3bpos_t blockpos_max = data->blockpos_max; + node_min = getBlockPosRelative(blockpos_min); + node_max = getBlockPosRelative(blockpos_max + v3bpos_t(1, 1, 1)) - v3pos_t(1, 1, 1); + full_node_min = getBlockPosRelative(blockpos_min - 1); + full_node_max = getBlockPosRelative(blockpos_max + 2) - v3pos_t(1, 1, 1); // Create a block-specific seed blockseed = getBlockSeed2(full_node_min, seed); diff --git a/src/mapgen/mapgen_v6.cpp b/src/mapgen/mapgen_v6.cpp index 949afee572..aa4146982a 100644 --- a/src/mapgen/mapgen_v6.cpp +++ b/src/mapgen/mapgen_v6.cpp @@ -509,12 +509,12 @@ void MapgenV6::makeChunk(BlockMakeData *data) v3bpos_t blockpos_max = data->blockpos_max; // Area of central chunk - node_min = blockpos_min * MAP_BLOCKSIZE; - node_max = (blockpos_max + v3pos_t(1, 1, 1)) * MAP_BLOCKSIZE - v3pos_t(1, 1, 1); + node_min = getBlockPosRelative(blockpos_min); + node_max = getBlockPosRelative(blockpos_max + v3bpos_t(1, 1, 1)) - v3pos_t(1, 1, 1); // Full allocated area - full_node_min = (blockpos_min - 1) * MAP_BLOCKSIZE; - full_node_max = (blockpos_max + 2) * MAP_BLOCKSIZE - v3pos_t(1, 1, 1); + full_node_min = getBlockPosRelative(blockpos_min - 1); + full_node_max = getBlockPosRelative(blockpos_max + 2) - v3pos_t(1, 1, 1); central_area_size = node_max - node_min + v3pos_t(1, 1, 1); assert(central_area_size.X == central_area_size.Z); diff --git a/src/mapgen/mapgen_v7.cpp b/src/mapgen/mapgen_v7.cpp index a261e27a8a..0293fdfce9 100644 --- a/src/mapgen/mapgen_v7.cpp +++ b/src/mapgen/mapgen_v7.cpp @@ -324,12 +324,12 @@ void MapgenV7::makeChunk(BlockMakeData *data) this->vm = data->vmanip; this->ndef = data->nodedef; - v3pos_t blockpos_min = data->blockpos_min; - v3pos_t blockpos_max = data->blockpos_max; - node_min = blockpos_min * MAP_BLOCKSIZE; - node_max = (blockpos_max + v3pos_t(1, 1, 1)) * MAP_BLOCKSIZE - v3pos_t(1, 1, 1); - full_node_min = (blockpos_min - 1) * MAP_BLOCKSIZE; - full_node_max = (blockpos_max + 2) * MAP_BLOCKSIZE - v3pos_t(1, 1, 1); + v3bpos_t blockpos_min = data->blockpos_min; + v3bpos_t blockpos_max = data->blockpos_max; + node_min = getBlockPosRelative(blockpos_min); + node_max = getBlockPosRelative(blockpos_max + v3bpos_t(1, 1, 1)) - v3pos_t(1, 1, 1); + full_node_min = getBlockPosRelative(blockpos_min - 1); + full_node_max = getBlockPosRelative(blockpos_max + 2) - v3pos_t(1, 1, 1); blockseed = getBlockSeed2(full_node_min, seed); diff --git a/src/mapgen/mapgen_valleys.cpp b/src/mapgen/mapgen_valleys.cpp index 28b3e7a460..9caf945803 100644 --- a/src/mapgen/mapgen_valleys.cpp +++ b/src/mapgen/mapgen_valleys.cpp @@ -218,12 +218,12 @@ void MapgenValleys::makeChunk(BlockMakeData *data) this->vm = data->vmanip; this->ndef = data->nodedef; - v3pos_t blockpos_min = data->blockpos_min; - v3pos_t blockpos_max = data->blockpos_max; - node_min = blockpos_min * MAP_BLOCKSIZE; - node_max = (blockpos_max + v3pos_t(1, 1, 1)) * MAP_BLOCKSIZE - v3pos_t(1, 1, 1); - full_node_min = (blockpos_min - 1) * MAP_BLOCKSIZE; - full_node_max = (blockpos_max + 2) * MAP_BLOCKSIZE - v3pos_t(1, 1, 1); + v3bpos_t blockpos_min = data->blockpos_min; + v3bpos_t blockpos_max = data->blockpos_max; + node_min = getBlockPosRelative(blockpos_min); + node_max = getBlockPosRelative(blockpos_max + v3bpos_t(1, 1, 1)) - v3pos_t(1, 1, 1); + full_node_min = getBlockPosRelative(blockpos_min - 1); + full_node_max = getBlockPosRelative(blockpos_max + 2) - v3pos_t(1, 1, 1); blockseed = getBlockSeed2(full_node_min, seed); diff --git a/src/mapgen/mg_schematic.cpp b/src/mapgen/mg_schematic.cpp index cfef839d90..481f7d7964 100644 --- a/src/mapgen/mg_schematic.cpp +++ b/src/mapgen/mg_schematic.cpp @@ -234,9 +234,9 @@ bool Schematic::placeOnVManip(MMVManip *vm, v3pos_t p, u32 flags, void Schematic::placeOnMap(ServerMap *map, v3pos_t p, u32 flags, Rotation rot, bool force_place) { - std::map lighting_modified_blocks; - std::map modified_blocks; - std::map::iterator it; + std::map lighting_modified_blocks; + std::map modified_blocks; + std::map::iterator it; assert(map != NULL); assert(schemdata != NULL); @@ -556,7 +556,7 @@ bool Schematic::getSchematicFromMap(Map *map, v3pos_t p1, v3pos_t p2) v3bpos_t bp2 = getNodeBlockPos(p2); vm->initialEmerge(bp1, bp2); - v3bpos_t size_pos = p2 - p1 + 1; + v3pos_t size_pos = p2 - p1 + 1; size = v3s16(size_pos.X, size_pos.Y, size_pos.Z); slice_probs = new u8[size.Y]; diff --git a/src/mapgen/treegen.cpp b/src/mapgen/treegen.cpp index bcaa7cbc18..b4a6d3632c 100644 --- a/src/mapgen/treegen.cpp +++ b/src/mapgen/treegen.cpp @@ -122,12 +122,12 @@ void make_tree(MMVManip &vmanip, v3pos_t p0, bool is_apple_tree, treegen::error spawn_ltree(ServerMap *map, v3pos_t p0, const NodeDefManager *ndef, const TreeDef &tree_definition) { - std::map modified_blocks; + std::map modified_blocks; MMVManip vmanip(map); v3bpos_t tree_blockp = getNodeBlockPos(p0); treegen::error e; - vmanip.initialEmerge(tree_blockp - v3pos_t(1, 1, 1), tree_blockp + v3pos_t(1, 3, 1)); + vmanip.initialEmerge(tree_blockp - v3bpos_t(1, 1, 1), tree_blockp + v3bpos_t(1, 3, 1)); e = make_ltree(vmanip, p0, ndef, tree_definition); if (e != SUCCESS) return e; diff --git a/src/mapsector.cpp b/src/mapsector.cpp index b786e8ec38..1b4909c814 100644 --- a/src/mapsector.cpp +++ b/src/mapsector.cpp @@ -22,7 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "mapblock.h" #include "serialization.h" -MapSector::MapSector(Map *parent, v2pos_t pos, IGameDef *gamedef): +MapSector::MapSector(Map *parent, v2bpos_t pos, IGameDef *gamedef): m_parent(parent), m_pos(pos), m_gamedef(gamedef) diff --git a/src/network/clientpackethandler.cpp b/src/network/clientpackethandler.cpp index 3e00fe60b9..7f4781a481 100644 --- a/src/network/clientpackethandler.cpp +++ b/src/network/clientpackethandler.cpp @@ -284,10 +284,10 @@ void Client::handleCommand_NodemetaChanged(NetworkPacket *pkt) void Client::handleCommand_BlockData(NetworkPacket* pkt) { // Ignore too small packet - if (pkt->getSize() < sizeof(v3pos_t)) + if (pkt->getSize() < sizeof(v3bpos_t)) return; - v3pos_t p; + v3bpos_t p; *pkt >> p; std::string datastring(pkt->getString(sizeof(p)), pkt->getSize() - sizeof(p)); diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp index 374d7225c6..31447d6990 100644 --- a/src/script/common/c_content.cpp +++ b/src/script/common/c_content.cpp @@ -1861,9 +1861,9 @@ void push_pointed_thing(lua_State *L, const PointedThing &pointed, bool csm, if (pointed.type == POINTEDTHING_NODE) { lua_pushstring(L, "node"); lua_setfield(L, -2, "type"); - push_v3pos_t(L, pointed.node_undersurface); + push_v3pos(L, pointed.node_undersurface); lua_setfield(L, -2, "under"); - push_v3pos_t(L, pointed.node_abovesurface); + push_v3pos(L, pointed.node_abovesurface); lua_setfield(L, -2, "above"); } else if (pointed.type == POINTEDTHING_OBJECT) { lua_pushstring(L, "object"); @@ -1883,7 +1883,7 @@ void push_pointed_thing(lua_State *L, const PointedThing &pointed, bool csm, if (hitpoint && (pointed.type != POINTEDTHING_NOTHING)) { push_v3f(L, pointed.intersection_point / BS); // convert to node coords lua_setfield(L, -2, "intersection_point"); - push_v3pos_t(L, pointed.intersection_normal); + push_v3pos(L, pointed.intersection_normal); lua_setfield(L, -2, "intersection_normal"); lua_pushinteger(L, pointed.box_id + 1); // change to Lua array index lua_setfield(L, -2, "box_id"); @@ -2123,7 +2123,7 @@ void push_collision_move_result(lua_State *L, const collisionMoveResult &res) lua_setfield(L, -2, "axis"); if (c.type == COLLISION_NODE) { - push_v3pos_t(L, c.node_p); + push_v3pos(L, c.node_p); lua_setfield(L, -2, "node_pos"); } else if (c.type == COLLISION_OBJECT) { push_objectRef(L, c.object->getId()); diff --git a/src/script/common/c_converter.cpp b/src/script/common/c_converter.cpp index c1c3915255..07d23e8885 100644 --- a/src/script/common/c_converter.cpp +++ b/src/script/common/c_converter.cpp @@ -324,7 +324,7 @@ v3s16 read_v3s16(lua_State *L, int index) return doubleToInt(pf, 1.0); } -v3pos_t read_v3pos_t(lua_State *L, int index) +v3pos_t read_v3pos(lua_State *L, int index) { // Correct rounding at <0 v3d pf = read_v3d(L, index); @@ -338,7 +338,7 @@ v3s16 check_v3s16(lua_State *L, int index) return doubleToInt(pf, 1.0); } -v3pos_t check_v3pos_t(lua_State *L, int index) +v3pos_t check_v3pos(lua_State *L, int index) { // Correct rounding at <0 v3d pf = check_v3d(L, index); diff --git a/src/script/common/c_converter.h b/src/script/common/c_converter.h index 1f090547eb..5afe57a14f 100644 --- a/src/script/common/c_converter.h +++ b/src/script/common/c_converter.h @@ -104,13 +104,13 @@ void setboolfield(lua_State *L, int table, v3f checkFloatPos (lua_State *L, int index); v3f check_v3f (lua_State *L, int index); v3s16 check_v3s16 (lua_State *L, int index); -v3pos_t check_v3pos_t (lua_State *L, int index); +v3pos_t check_v3pos (lua_State *L, int index); v3f read_v3f (lua_State *L, int index); v2f read_v2f (lua_State *L, int index); v2s16 read_v2s16 (lua_State *L, int index); v2s32 read_v2s32 (lua_State *L, int index); -inline v2pos_t read_v2pos_t (lua_State *L, int index) { +inline v2pos_t read_v2pos (lua_State *L, int index) { #if USE_POS32 return read_v2s32(L, index); #else @@ -126,7 +126,7 @@ bool is_color_table (lua_State *L, int index); aabb3f read_aabb3f (lua_State *L, int index, f32 scale); v3s16 read_v3s16 (lua_State *L, int index); v3s32 read_v3s32 (lua_State *L, int index); -v3pos_t read_v3pos_t (lua_State *L, int index); +v3pos_t read_v3pos (lua_State *L, int index); std::vector read_aabb3f_vector (lua_State *L, int index, f32 scale); size_t read_stringlist (lua_State *L, int index, @@ -137,7 +137,7 @@ void push_v3_float_string(lua_State *L, v3f p); void push_v2_float_string(lua_State *L, v2f p); void push_v2s16 (lua_State *L, v2s16 p); void push_v2s32 (lua_State *L, v2s32 p); -inline void push_v2pos_t (lua_State *L, v2pos_t p) { +inline void push_v2pos (lua_State *L, v2pos_t p) { #if USE_POS32 return push_v2s32(L, p); #else @@ -147,7 +147,7 @@ inline void push_v2pos_t (lua_State *L, v2pos_t p) { void push_v3s16 (lua_State *L, v3s16 p); void push_v3s32 (lua_State *L, v3s32 p); -inline void push_v3pos_t (lua_State *L, v3pos_t p) { +inline void push_v3pos (lua_State *L, v3pos_t p) { #if USE_POS32 return push_v3s32(L, p); #else diff --git a/src/script/cpp_api/s_client.cpp b/src/script/cpp_api/s_client.cpp index b50a459d26..666f4fe1f3 100644 --- a/src/script/cpp_api/s_client.cpp +++ b/src/script/cpp_api/s_client.cpp @@ -193,7 +193,7 @@ bool ScriptApiClient::on_dignode(v3pos_t p, MapNode node) lua_getfield(L, -1, "registered_on_dignode"); // Push data - push_v3pos_t(L, p); + push_v3pos(L, p); pushnode(L, node, ndef); // Call functions @@ -217,7 +217,7 @@ bool ScriptApiClient::on_punchnode(v3pos_t p, MapNode node) lua_getfield(L, -1, "registered_on_punchnode"); // Push data - push_v3pos_t(L, p); + push_v3pos(L, p); pushnode(L, node, ndef); // Call functions diff --git a/src/script/cpp_api/s_env.cpp b/src/script/cpp_api/s_env.cpp index d909a187d4..d38c273df5 100644 --- a/src/script/cpp_api/s_env.cpp +++ b/src/script/cpp_api/s_env.cpp @@ -37,8 +37,8 @@ void ScriptApiEnv::environment_OnGenerated(v3pos_t minp, v3pos_t maxp, lua_getglobal(L, "core"); lua_getfield(L, -1, "registered_on_generateds"); // Call callbacks - push_v3pos_t(L, minp); - push_v3pos_t(L, maxp); + push_v3pos(L, minp); + push_v3pos(L, maxp); lua_pushnumber(L, blockseed); runCallbacks(3, RUN_CALLBACKS_MODE_FIRST); } @@ -216,7 +216,7 @@ void ScriptApiEnv::initializeEnvironment(ServerEnvironment *env) } void ScriptApiEnv::on_emerge_area_completion( - v3pos_t blockpos, int action, ScriptCallbackState *state) + v3bpos_t blockpos, int action, ScriptCallbackState *state) { Server *server = getServer(); @@ -235,7 +235,7 @@ void ScriptApiEnv::on_emerge_area_completion( lua_rawgeti(L, LUA_REGISTRYINDEX, state->callback_ref); luaL_checktype(L, -1, LUA_TFUNCTION); - push_v3pos_t(L, blockpos); + push_v3pos(L, blockpos); lua_pushinteger(L, action); lua_pushinteger(L, state->refcount); lua_rawgeti(L, LUA_REGISTRYINDEX, state->args_ref); @@ -279,7 +279,7 @@ void ScriptApiEnv::on_liquid_transformed( lua_createtable(L, list.size(), 0); for(std::pair p : list) { lua_pushnumber(L, index); - push_v3pos_t(L, p.first); + push_v3pos(L, p.first); lua_rawset(L, -4); lua_pushnumber(L, index++); pushnode(L, p.second, ndef); diff --git a/src/script/cpp_api/s_env.h b/src/script/cpp_api/s_env.h index 6b53998f62..4a0b30c275 100644 --- a/src/script/cpp_api/s_env.h +++ b/src/script/cpp_api/s_env.h @@ -40,7 +40,7 @@ class ScriptApiEnv : virtual public ScriptApiBase void player_event(ServerActiveObject *player, const std::string &type); // Called after emerge of a block queued from core.emerge_area() - void on_emerge_area_completion(v3pos_t blockpos, int action, + void on_emerge_area_completion(v3bpos_t blockpos, int action, ScriptCallbackState *state); // Called after liquid transform changes diff --git a/src/script/cpp_api/s_node.cpp b/src/script/cpp_api/s_node.cpp index c0881d2e6a..9d38170193 100644 --- a/src/script/cpp_api/s_node.cpp +++ b/src/script/cpp_api/s_node.cpp @@ -116,7 +116,7 @@ bool ScriptApiNode::node_on_punch(v3pos_t p, MapNode node, return false; // Call function - push_v3pos_t(L, p); + push_v3pos(L, p); pushnode(L, node, ndef); objectrefGetOrCreate(L, puncher); pushPointedThing(pointed); @@ -139,7 +139,7 @@ bool ScriptApiNode::node_on_dig(v3pos_t p, MapNode node, return false; // Call function - push_v3pos_t(L, p); + push_v3pos(L, p); pushnode(L, node, ndef); objectrefGetOrCreate(L, digger); PCALL_RES(lua_pcall(L, 3, 1, error_handler)); @@ -165,7 +165,7 @@ void ScriptApiNode::node_on_construct(v3pos_t p, MapNode node) return; // Call function - push_v3pos_t(L, p); + push_v3pos(L, p); PCALL_RES(lua_pcall(L, 1, 0, error_handler)); lua_pop(L, 1); // Pop error handler } @@ -183,7 +183,7 @@ void ScriptApiNode::node_on_destruct(v3pos_t p, MapNode node) return; // Call function - push_v3pos_t(L, p); + push_v3pos(L, p); PCALL_RES(lua_pcall(L, 1, 0, error_handler)); lua_pop(L, 1); // Pop error handler } @@ -201,7 +201,7 @@ bool ScriptApiNode::node_on_flood(v3pos_t p, MapNode node, MapNode newnode) return false; // Call function - push_v3pos_t(L, p); + push_v3pos(L, p); pushnode(L, node, ndef); pushnode(L, newnode, ndef); PCALL_RES(lua_pcall(L, 3, 1, error_handler)); @@ -222,7 +222,7 @@ void ScriptApiNode::node_after_destruct(v3pos_t p, MapNode node) return; // Call function - push_v3pos_t(L, p); + push_v3pos(L, p); pushnode(L, node, ndef); PCALL_RES(lua_pcall(L, 2, 0, error_handler)); lua_pop(L, 1); // Pop error handler @@ -241,7 +241,7 @@ bool ScriptApiNode::node_on_timer(v3pos_t p, MapNode node, f32 dtime) return false; // Call function - push_v3pos_t(L, p); + push_v3pos(L, p); lua_pushnumber(L,dtime); PCALL_RES(lua_pcall(L, 2, 1, error_handler)); lua_remove(L, error_handler); @@ -269,7 +269,7 @@ void ScriptApiNode::node_on_receive_fields(v3pos_t p, return; // Call function - push_v3pos_t(L, p); // pos + push_v3pos(L, p); // pos lua_pushstring(L, formname.c_str()); // formname lua_newtable(L); // fields StringMap::const_iterator it; diff --git a/src/script/cpp_api/s_nodemeta.cpp b/src/script/cpp_api/s_nodemeta.cpp index e5d7ca2391..f16bab5deb 100644 --- a/src/script/cpp_api/s_nodemeta.cpp +++ b/src/script/cpp_api/s_nodemeta.cpp @@ -48,7 +48,7 @@ int ScriptApiNodemeta::nodemeta_inventory_AllowMove( return count; // function(pos, from_list, from_index, to_list, to_index, count, player) - push_v3pos_t(L, ma.to_inv.p); // pos + push_v3pos(L, ma.to_inv.p); // pos lua_pushstring(L, ma.from_list.c_str()); // from_list lua_pushinteger(L, ma.from_i + 1); // from_index lua_pushstring(L, ma.to_list.c_str()); // to_list @@ -86,7 +86,7 @@ int ScriptApiNodemeta::nodemeta_inventory_AllowPut( return stack.count; // Call function(pos, listname, index, stack, player) - push_v3pos_t(L, ma.to_inv.p); // pos + push_v3pos(L, ma.to_inv.p); // pos lua_pushstring(L, ma.to_list.c_str()); // listname lua_pushinteger(L, ma.to_i + 1); // index LuaItemStack::create(L, stack); // stack @@ -122,7 +122,7 @@ int ScriptApiNodemeta::nodemeta_inventory_AllowTake( return stack.count; // Call function(pos, listname, index, count, player) - push_v3pos_t(L, ma.from_inv.p); // pos + push_v3pos(L, ma.from_inv.p); // pos lua_pushstring(L, ma.from_list.c_str()); // listname lua_pushinteger(L, ma.from_i + 1); // index LuaItemStack::create(L, stack); // stack @@ -158,7 +158,7 @@ void ScriptApiNodemeta::nodemeta_inventory_OnMove( return; // function(pos, from_list, from_index, to_list, to_index, count, player) - push_v3pos_t(L, ma.from_inv.p); // pos + push_v3pos(L, ma.from_inv.p); // pos lua_pushstring(L, ma.from_list.c_str()); // from_list lua_pushinteger(L, ma.from_i + 1); // from_index lua_pushstring(L, ma.to_list.c_str()); // to_list @@ -191,7 +191,7 @@ void ScriptApiNodemeta::nodemeta_inventory_OnPut( return; // Call function(pos, listname, index, stack, player) - push_v3pos_t(L, ma.to_inv.p); // pos + push_v3pos(L, ma.to_inv.p); // pos lua_pushstring(L, ma.to_list.c_str()); // listname lua_pushinteger(L, ma.to_i + 1); // index LuaItemStack::create(L, stack); // stack @@ -222,7 +222,7 @@ void ScriptApiNodemeta::nodemeta_inventory_OnTake( return; // Call function(pos, listname, index, stack, player) - push_v3pos_t(L, ma.from_inv.p); // pos + push_v3pos(L, ma.from_inv.p); // pos lua_pushstring(L, ma.from_list.c_str()); // listname lua_pushinteger(L, ma.from_i + 1); // index LuaItemStack::create(L, stack); // stack diff --git a/src/script/lua_api/l_areastore.cpp b/src/script/lua_api/l_areastore.cpp index d5264f61cc..f6fa897194 100644 --- a/src/script/lua_api/l_areastore.cpp +++ b/src/script/lua_api/l_areastore.cpp @@ -47,9 +47,9 @@ static void push_area(lua_State *L, const Area *a, } lua_newtable(L); if (include_borders) { - push_v3pos_t(L, a->minedge); + push_v3pos(L, a->minedge); lua_setfield(L, -2, "min"); - push_v3pos_t(L, a->maxedge); + push_v3pos(L, a->maxedge); lua_setfield(L, -2, "max"); } if (include_data) { @@ -127,7 +127,7 @@ int LuaAreaStore::l_get_areas_for_pos(lua_State *L) LuaAreaStore *o = checkobject(L, 1); AreaStore *ast = o->as; - v3pos_t pos = check_v3pos_t(L, 2); + v3pos_t pos = check_v3pos(L, 2); bool include_borders = true; bool include_data = false; @@ -149,8 +149,8 @@ int LuaAreaStore::l_get_areas_in_area(lua_State *L) LuaAreaStore *o = checkobject(L, 1); AreaStore *ast = o->as; - v3pos_t minedge = check_v3pos_t(L, 2); - v3pos_t maxedge = check_v3pos_t(L, 3); + v3pos_t minedge = check_v3pos(L, 2); + v3pos_t maxedge = check_v3pos(L, 3); bool include_borders = true; bool include_data = false; @@ -175,7 +175,7 @@ int LuaAreaStore::l_insert_area(lua_State *L) LuaAreaStore *o = checkobject(L, 1); AreaStore *ast = o->as; - Area a(check_v3pos_t(L, 2), check_v3pos_t(L, 3)); + Area a(check_v3pos(L, 2), check_v3pos(L, 3)); size_t d_len; const char *data = luaL_checklstring(L, 4, &d_len); diff --git a/src/script/lua_api/l_client.cpp b/src/script/lua_api/l_client.cpp index 12f690f581..ec8b0727bd 100644 --- a/src/script/lua_api/l_client.cpp +++ b/src/script/lua_api/l_client.cpp @@ -213,7 +213,7 @@ int ModApiClient::l_gettext(lua_State *L) int ModApiClient::l_get_node_or_nil(lua_State *L) { // pos - v3pos_t pos = read_v3pos_t(L, 1); + v3pos_t pos = read_v3pos(L, 1); // Do it bool pos_ok; @@ -247,7 +247,7 @@ int ModApiClient::l_get_language(lua_State *L) // get_meta(pos) int ModApiClient::l_get_meta(lua_State *L) { - v3pos_t p = read_v3pos_t(L, 1); + v3pos_t p = read_v3pos(L, 1); // check restrictions first bool pos_ok; diff --git a/src/script/lua_api/l_env.cpp b/src/script/lua_api/l_env.cpp index c775575515..5eaa5f4251 100644 --- a/src/script/lua_api/l_env.cpp +++ b/src/script/lua_api/l_env.cpp @@ -97,7 +97,7 @@ void LuaABM::trigger(ServerEnvironment *env, v3pos_t p, MapNode n, lua_getfield(L, -1, "action"); luaL_checktype(L, -1, LUA_TFUNCTION); lua_remove(L, -2); // Remove registered_abms[m_id] - push_v3pos_t(L, p); + push_v3pos(L, p); pushnode(L, n, env->getGameDef()->ndef()); lua_pushnumber(L, active_object_count); lua_pushnumber(L, active_object_count_wider); @@ -139,7 +139,7 @@ void LuaLBM::trigger(ServerEnvironment *env, v3pos_t p, MapNode n) lua_getfield(L, -1, "action"); luaL_checktype(L, -1, LUA_TFUNCTION); lua_remove(L, -2); // Remove registered_lbms[m_id] - push_v3pos_t(L, p); + push_v3pos(L, p); pushnode(L, n, env->getGameDef()->ndef()); int result = lua_pcall(L, 2, 0, error_handler); @@ -250,7 +250,7 @@ const luaL_Reg LuaRaycast::methods[] = { 0, 0 } }; -void LuaEmergeAreaCallback(v3pos_t blockpos, EmergeAction action, void *param) +void LuaEmergeAreaCallback(v3bpos_t blockpos, EmergeAction action, void *param) { ScriptCallbackState *state = (ScriptCallbackState *)param; assert(state != NULL); @@ -279,7 +279,7 @@ int ModApiEnvMod::l_set_node(lua_State *L) const NodeDefManager *ndef = env->getGameDef()->ndef(); // parameters - v3pos_t pos = read_v3pos_t(L, 1); + v3pos_t pos = read_v3pos(L, 1); MapNode n = readnode(L, 2, ndef); // Do it bool succeeded = env->setNode(pos, n); @@ -311,7 +311,7 @@ int ModApiEnvMod::l_bulk_set_node(lua_State *L) bool succeeded = true; for (s32 i = 1; i <= len; i++) { lua_rawgeti(L, 1, i); - if (!env->setNode(read_v3pos_t(L, -1), n)) + if (!env->setNode(read_v3pos(L, -1), n)) succeeded = false; lua_pop(L, 1); } @@ -332,7 +332,7 @@ int ModApiEnvMod::l_remove_node(lua_State *L) GET_ENV_PTR; // parameters - v3pos_t pos = read_v3pos_t(L, 1); + v3pos_t pos = read_v3pos(L, 1); // Do it bool succeeded = env->removeNode(pos); lua_pushboolean(L, succeeded); @@ -347,7 +347,7 @@ int ModApiEnvMod::l_swap_node(lua_State *L) const NodeDefManager *ndef = env->getGameDef()->ndef(); // parameters - v3pos_t pos = read_v3pos_t(L, 1); + v3pos_t pos = read_v3pos(L, 1); MapNode n = readnode(L, 2, ndef); // Do it bool succeeded = env->swapNode(pos, n); @@ -362,7 +362,7 @@ int ModApiEnvMod::l_get_node(lua_State *L) GET_ENV_PTR; // pos - v3pos_t pos = read_v3pos_t(L, 1); + v3pos_t pos = read_v3pos(L, 1); // Do it MapNode n = env->getMap().getNode(pos); // Return node @@ -377,7 +377,7 @@ int ModApiEnvMod::l_get_node_or_nil(lua_State *L) GET_ENV_PTR; // pos - v3pos_t pos = read_v3pos_t(L, 1); + v3pos_t pos = read_v3pos(L, 1); // Do it bool pos_ok; MapNode n = env->getMap().getNode(pos, &pos_ok); @@ -398,7 +398,7 @@ int ModApiEnvMod::l_get_node_light(lua_State *L) GET_PLAIN_ENV_PTR; // Do it - v3pos_t pos = read_v3pos_t(L, 1); + v3pos_t pos = read_v3pos(L, 1); u32 time_of_day = env->getTimeOfDay(); if(lua_isnumber(L, 2)) time_of_day = 24000.0 * lua_tonumber(L, 2); @@ -424,7 +424,7 @@ int ModApiEnvMod::l_get_natural_light(lua_State *L) { GET_ENV_PTR; - v3pos_t pos = read_v3pos_t(L, 1); + v3pos_t pos = read_v3pos(L, 1); bool is_position_ok; MapNode n = env->getMap().getNode(pos, &is_position_ok); @@ -467,7 +467,7 @@ int ModApiEnvMod::l_place_node(lua_State *L) const NodeDefManager *ndef = server->ndef(); IItemDefManager *idef = server->idef(); - v3pos_t pos = read_v3pos_t(L, 1); + v3pos_t pos = read_v3pos(L, 1); MapNode n = readnode(L, 2, ndef); // Don't attempt to load non-loaded area as of now @@ -497,7 +497,7 @@ int ModApiEnvMod::l_dig_node(lua_State *L) ScriptApiNode *scriptIfaceNode = getScriptApi(L); - v3pos_t pos = read_v3pos_t(L, 1); + v3pos_t pos = read_v3pos(L, 1); // Don't attempt to load non-loaded area as of now MapNode n = env->getMap().getNode(pos); @@ -520,7 +520,7 @@ int ModApiEnvMod::l_punch_node(lua_State *L) ScriptApiNode *scriptIfaceNode = getScriptApi(L); - v3pos_t pos = read_v3pos_t(L, 1); + v3pos_t pos = read_v3pos(L, 1); // Don't attempt to load non-loaded area as of now MapNode n = env->getMap().getNode(pos); @@ -541,7 +541,7 @@ int ModApiEnvMod::l_get_node_max_level(lua_State *L) { GET_PLAIN_ENV_PTR; - v3pos_t pos = read_v3pos_t(L, 1); + v3pos_t pos = read_v3pos(L, 1); MapNode n = env->getMap().getNode(pos); lua_pushnumber(L, n.getMaxLevel(env->getGameDef()->ndef())); return 1; @@ -553,7 +553,7 @@ int ModApiEnvMod::l_get_node_level(lua_State *L) { GET_PLAIN_ENV_PTR; - v3pos_t pos = read_v3pos_t(L, 1); + v3pos_t pos = read_v3pos(L, 1); MapNode n = env->getMap().getNode(pos); lua_pushnumber(L, n.getLevel(env->getGameDef()->ndef())); return 1; @@ -566,7 +566,7 @@ int ModApiEnvMod::l_set_node_level(lua_State *L) { GET_ENV_PTR; - v3pos_t pos = read_v3pos_t(L, 1); + v3pos_t pos = read_v3pos(L, 1); u8 level = 1; if(lua_isnumber(L, 2)) level = lua_tonumber(L, 2); @@ -583,7 +583,7 @@ int ModApiEnvMod::l_add_node_level(lua_State *L) { GET_ENV_PTR; - v3pos_t pos = read_v3pos_t(L, 1); + v3pos_t pos = read_v3pos(L, 1); s16 level = 1; if(lua_isnumber(L, 2)) level = lua_tonumber(L, 2); @@ -599,11 +599,11 @@ int ModApiEnvMod::l_find_nodes_with_meta(lua_State *L) GET_PLAIN_ENV_PTR; std::vector positions = env->getMap().findNodesWithMetadata( - check_v3pos_t(L, 1), check_v3pos_t(L, 2)); + check_v3pos(L, 1), check_v3pos(L, 2)); lua_createtable(L, positions.size(), 0); for (size_t i = 0; i != positions.size(); i++) { - push_v3pos_t(L, positions[i]); + push_v3pos(L, positions[i]); lua_rawseti(L, -2, i + 1); } @@ -616,7 +616,7 @@ int ModApiEnvMod::l_get_meta(lua_State *L) GET_ENV_PTR; // Do it - v3pos_t p = read_v3pos_t(L, 1); + v3pos_t p = read_v3pos(L, 1); NodeMetaRef::create(L, p, env); return 1; } @@ -627,7 +627,7 @@ int ModApiEnvMod::l_get_node_timer(lua_State *L) GET_ENV_PTR; // Do it - v3pos_t p = read_v3pos_t(L, 1); + v3pos_t p = read_v3pos(L, 1); NodeTimerRef::create(L, p, &env->getServerMap()); return 1; } @@ -853,7 +853,7 @@ int ModApiEnvMod::l_find_node_near(lua_State *L) const NodeDefManager *ndef = env->getGameDef()->ndef(); Map &map = env->getMap(); - v3pos_t pos = read_v3pos_t(L, 1); + v3pos_t pos = read_v3pos(L, 1); int radius = luaL_checkinteger(L, 2); std::vector filter; collectNodeIds(L, 3, ndef, filter); @@ -872,7 +872,7 @@ int ModApiEnvMod::l_find_node_near(lua_State *L) v3pos_t p = pos + i; content_t c = map.getNode(p).getContent(); if (CONTAINS(filter, c)) { - push_v3pos_t(L, p); + push_v3pos(L, p); return 1; } } @@ -900,8 +900,8 @@ int ModApiEnvMod::l_find_nodes_in_area(lua_State *L) { GET_PLAIN_ENV_PTR; - v3pos_t minp = read_v3pos_t(L, 1); - v3pos_t maxp = read_v3pos_t(L, 2); + v3pos_t minp = read_v3pos(L, 1); + v3pos_t maxp = read_v3pos(L, 2); sortBoxVerticies(minp, maxp); const NodeDefManager *ndef = env->getGameDef()->ndef(); @@ -942,7 +942,7 @@ int ModApiEnvMod::l_find_nodes_in_area(lua_State *L) if (it != filter.end()) { // Calculate index of the table and append the position u32 filt_index = it - filter.begin(); - push_v3pos_t(L, p); + push_v3pos(L, p); lua_rawseti(L, base + 1 + filt_index, ++idx[filt_index]); } } @@ -975,7 +975,7 @@ int ModApiEnvMod::l_find_nodes_in_area(lua_State *L) auto it = std::find(filter.begin(), filter.end(), c); if (it != filter.end()) { - push_v3pos_t(L, p); + push_v3pos(L, p); lua_rawseti(L, -2, ++i); u32 filt_index = it - filter.begin(); @@ -1005,8 +1005,8 @@ int ModApiEnvMod::l_find_nodes_in_area_under_air(lua_State *L) GET_PLAIN_ENV_PTR; - v3pos_t minp = read_v3pos_t(L, 1); - v3pos_t maxp = read_v3pos_t(L, 2); + v3pos_t minp = read_v3pos(L, 1); + v3pos_t maxp = read_v3pos(L, 2); sortBoxVerticies(minp, maxp); const NodeDefManager *ndef = env->getGameDef()->ndef(); @@ -1036,7 +1036,7 @@ int ModApiEnvMod::l_find_nodes_in_area_under_air(lua_State *L) content_t csurf = map.getNode(psurf).getContent(); if (c != CONTENT_AIR && csurf == CONTENT_AIR && CONTAINS(filter, c)) { - push_v3pos_t(L, p); + push_v3pos(L, p); lua_rawseti(L, -2, ++i); } c = csurf; @@ -1080,7 +1080,7 @@ int ModApiEnvMod::l_get_perlin_map(lua_State *L) NoiseParams np; if (!read_noiseparams(L, 1, &np)) return 0; - v3pos_t size = read_v3pos_t(L, 2); + v3pos_t size = read_v3pos(L, 2); s32 seed = (s32)(env->getServerMap().getSeed()); LuaPerlinNoiseMap *n = new LuaPerlinNoiseMap(&np, seed, size); @@ -1098,7 +1098,7 @@ int ModApiEnvMod::l_get_voxel_manip(lua_State *L) Map *map = &(env->getMap()); LuaVoxelManip *o = (lua_istable(L, 1) && lua_istable(L, 2)) ? - new LuaVoxelManip(map, read_v3pos_t(L, 1), read_v3pos_t(L, 2)) : + new LuaVoxelManip(map, read_v3pos(L, 1), read_v3pos(L, 2)) : new LuaVoxelManip(map); *(void **)(lua_newuserdata(L, sizeof(void *))) = o; @@ -1139,7 +1139,7 @@ int ModApiEnvMod::l_line_of_sight(lua_State *L) bool success = env->line_of_sight(pos1, pos2, &p); lua_pushboolean(L, success); if (!success) { - push_v3pos_t(L, p); + push_v3pos(L, p); return 2; } return 1; @@ -1150,12 +1150,12 @@ int ModApiEnvMod::l_fix_light(lua_State *L) { GET_ENV_PTR; - v3pos_t blockpos1 = getContainerPos(read_v3pos_t(L, 1), MAP_BLOCKSIZE); - v3pos_t blockpos2 = getContainerPos(read_v3pos_t(L, 2), MAP_BLOCKSIZE); + v3bpos_t blockpos1 = getContainerPos(read_v3pos(L, 1), MAP_BLOCKSIZE); + v3bpos_t blockpos2 = getContainerPos(read_v3pos(L, 2), MAP_BLOCKSIZE); ServerMap &map = env->getServerMap(); - std::map modified_blocks; + std::map modified_blocks; bool success = true; - v3pos_t blockpos; + v3bpos_t blockpos; for (blockpos.X = blockpos1.X; blockpos.X <= blockpos2.X; blockpos.X++) for (blockpos.Y = blockpos1.Y; blockpos.Y <= blockpos2.Y; blockpos.Y++) for (blockpos.Z = blockpos1.Z; blockpos.Z <= blockpos2.Z; blockpos.Z++) { @@ -1187,16 +1187,16 @@ int ModApiEnvMod::l_load_area(lua_State *L) MAP_LOCK_REQUIRED; Map *map = &(env->getMap()); - v3bpos_t bp1 = getNodeBlockPos(check_v3pos_t(L, 1)); + v3bpos_t bp1 = getNodeBlockPos(check_v3pos(L, 1)); if (!lua_istable(L, 2)) { map->emergeBlock(bp1); } else { - v3bpos_t bp2 = getNodeBlockPos(check_v3pos_t(L, 2)); + v3bpos_t bp2 = getNodeBlockPos(check_v3pos(L, 2)); sortBoxVerticies(bp1, bp2); for (s16 z = bp1.Z; z <= bp2.Z; z++) for (s16 y = bp1.Y; y <= bp2.Y; y++) for (s16 x = bp1.X; x <= bp2.X; x++) { - map->emergeBlock(v3pos_t(x, y, z)); + map->emergeBlock(v3bpos_t(x, y, z)); } } @@ -1214,8 +1214,8 @@ int ModApiEnvMod::l_emerge_area(lua_State *L) EmergeManager *emerge = getServer(L)->getEmergeManager(); - v3bpos_t bpmin = getNodeBlockPos(read_v3pos_t(L, 1)); - v3bpos_t bpmax = getNodeBlockPos(read_v3pos_t(L, 2)); + v3bpos_t bpmin = getNodeBlockPos(read_v3pos(L, 1)); + v3bpos_t bpmax = getNodeBlockPos(read_v3pos(L, 2)); sortBoxVerticies(bpmin, bpmax); size_t num_blocks = VoxelArea(bpmin, bpmax).getVolume(); @@ -1241,7 +1241,7 @@ int ModApiEnvMod::l_emerge_area(lua_State *L) for (s16 z = bpmin.Z; z <= bpmax.Z; z++) for (s16 y = bpmin.Y; y <= bpmax.Y; y++) for (s16 x = bpmin.X; x <= bpmax.X; x++) { - emerge->enqueueBlockEmergeEx(v3pos_t(x, y, z), PEER_ID_INEXISTENT, + emerge->enqueueBlockEmergeEx(v3bpos_t(x, y, z), PEER_ID_INEXISTENT, BLOCK_EMERGE_ALLOW_GEN | BLOCK_EMERGE_FORCE_QUEUE, callback, state); } @@ -1254,8 +1254,8 @@ int ModApiEnvMod::l_delete_area(lua_State *L) { GET_ENV_PTR; - v3bpos_t bpmin = getNodeBlockPos(read_v3pos_t(L, 1)); - v3bpos_t bpmax = getNodeBlockPos(read_v3pos_t(L, 2)); + v3bpos_t bpmin = getNodeBlockPos(read_v3pos(L, 1)); + v3bpos_t bpmax = getNodeBlockPos(read_v3pos(L, 2)); sortBoxVerticies(bpmin, bpmax); ServerMap &map = env->getServerMap(); @@ -1287,8 +1287,8 @@ int ModApiEnvMod::l_find_path(lua_State *L) { GET_ENV_PTR; - v3pos_t pos1 = read_v3pos_t(L, 1); - v3pos_t pos2 = read_v3pos_t(L, 2); + v3pos_t pos1 = read_v3pos(L, 1); + v3pos_t pos2 = read_v3pos(L, 2); unsigned int searchdistance = luaL_checkint(L, 3); unsigned int max_jump = luaL_checkint(L, 4); unsigned int max_drop = luaL_checkint(L, 5); @@ -1312,7 +1312,7 @@ int ModApiEnvMod::l_find_path(lua_State *L) unsigned int index = 1; for (const v3pos_t &i : path) { lua_pushnumber(L,index); - push_v3pos_t(L, i); + push_v3pos(L, i); lua_settable(L, top); index++; } @@ -1327,7 +1327,7 @@ int ModApiEnvMod::l_spawn_tree(lua_State *L) { GET_ENV_PTR; - v3pos_t p0 = read_v3pos_t(L, 1); + v3pos_t p0 = read_v3pos(L, 1); treegen::TreeDef tree_def; std::string trunk,leaves,fruit; @@ -1385,7 +1385,7 @@ int ModApiEnvMod::l_transforming_liquid_add(lua_State *L) { GET_ENV_PTR; - v3pos_t p0 = read_v3pos_t(L, 1); + v3pos_t p0 = read_v3pos(L, 1); env->getMap().transforming_liquid_add(p0); return 1; } @@ -1396,7 +1396,7 @@ int ModApiEnvMod::l_forceload_block(lua_State *L) { GET_ENV_PTR; - v3pos_t blockpos = read_v3pos_t(L, 1); + v3pos_t blockpos = read_v3pos(L, 1); env->getForceloadedBlocks()->insert(blockpos); return 0; } @@ -1406,7 +1406,7 @@ int ModApiEnvMod::l_compare_block_status(lua_State *L) { GET_ENV_PTR; - v3pos_t nodepos = check_v3pos_t(L, 1); + v3pos_t nodepos = check_v3pos(L, 1); std::string condition_s = luaL_checkstring(L, 2); auto status = env->getBlockStatus(getNodeBlockPos(nodepos)); @@ -1425,7 +1425,7 @@ int ModApiEnvMod::l_forceload_free_block(lua_State *L) { GET_ENV_PTR; - v3pos_t blockpos = read_v3pos_t(L, 1); + v3pos_t blockpos = read_v3pos(L, 1); env->getForceloadedBlocks()->erase(blockpos); return 0; } diff --git a/src/script/lua_api/l_inventory.cpp b/src/script/lua_api/l_inventory.cpp index d2e0bf9af7..8bfb5cfd8d 100644 --- a/src/script/lua_api/l_inventory.cpp +++ b/src/script/lua_api/l_inventory.cpp @@ -385,7 +385,7 @@ int InvRef::l_get_location(lua_State *L) lua_newtable(L); lua_pushstring(L, "node"); lua_setfield(L, -2, "type"); - push_v3pos_t(L, loc.p); + push_v3pos(L, loc.p); lua_setfield(L, -2, "pos"); return 1; case InventoryLocation::DETACHED: @@ -483,7 +483,7 @@ int ModApiInventory::l_get_inventory(lua_State *L) if(type == "node"){ MAP_LOCK_REQUIRED; lua_getfield(L, 1, "pos"); - v3pos_t pos = check_v3pos_t(L, -1); + v3pos_t pos = check_v3pos(L, -1); loc.setNodeMeta(pos); if (getServerInventoryMgr(L)->getInventory(loc) != NULL) diff --git a/src/script/lua_api/l_mapgen.cpp b/src/script/lua_api/l_mapgen.cpp index 89f555faa5..8c79acad39 100644 --- a/src/script/lua_api/l_mapgen.cpp +++ b/src/script/lua_api/l_mapgen.cpp @@ -523,7 +523,7 @@ int ModApiMapgen::l_get_heat(lua_State *L) { NO_MAP_LOCK_REQUIRED; - v3pos_t pos = read_v3pos_t(L, 1); + v3pos_t pos = read_v3pos(L, 1); const BiomeGen *biomegen = getServer(L)->getEmergeManager()->getBiomeGen(); @@ -544,7 +544,7 @@ int ModApiMapgen::l_get_humidity(lua_State *L) { NO_MAP_LOCK_REQUIRED; - v3pos_t pos = read_v3pos_t(L, 1); + v3pos_t pos = read_v3pos(L, 1); const BiomeGen *biomegen = getServer(L)->getEmergeManager()->getBiomeGen(); @@ -565,7 +565,7 @@ int ModApiMapgen::l_get_biome_data(lua_State *L) { NO_MAP_LOCK_REQUIRED; - v3pos_t pos = read_v3pos_t(L, 1); + v3pos_t pos = read_v3pos(L, 1); const BiomeGen *biomegen = getServer(L)->getEmergeManager()->getBiomeGen(); if (!biomegen) @@ -627,10 +627,10 @@ int ModApiMapgen::l_get_mapgen_object(lua_State *L) lua_setmetatable(L, -2); // emerged min pos - push_v3pos_t(L, vm->m_area.MinEdge); + push_v3pos(L, vm->m_area.MinEdge); // emerged max pos - push_v3pos_t(L, vm->m_area.MaxEdge); + push_v3pos(L, vm->m_area.MaxEdge); return 3; } @@ -697,7 +697,7 @@ int ModApiMapgen::l_get_mapgen_object(lua_State *L) lua_createtable(L, it->second.size(), 0); for (size_t j = 0; j != it->second.size(); j++) { - push_v3pos_t(L, it->second[j]); + push_v3pos(L, it->second[j]); lua_rawseti(L, -2, j + 1); } @@ -1432,9 +1432,9 @@ int ModApiMapgen::l_generate_ores(lua_State *L) mg.vm = LuaVoxelManip::checkobject(L, 1)->vm; mg.ndef = getServer(L)->getNodeDefManager(); - v3pos_t pmin = lua_istable(L, 2) ? check_v3pos_t(L, 2) : + v3pos_t pmin = lua_istable(L, 2) ? check_v3pos(L, 2) : mg.vm->m_area.MinEdge + v3pos_t(1,1,1) * MAP_BLOCKSIZE; - v3pos_t pmax = lua_istable(L, 3) ? check_v3pos_t(L, 3) : + v3pos_t pmax = lua_istable(L, 3) ? check_v3pos(L, 3) : mg.vm->m_area.MaxEdge - v3pos_t(1,1,1) * MAP_BLOCKSIZE; sortBoxVerticies(pmin, pmax); @@ -1461,9 +1461,9 @@ int ModApiMapgen::l_generate_decorations(lua_State *L) mg.vm = LuaVoxelManip::checkobject(L, 1)->vm; mg.ndef = getServer(L)->getNodeDefManager(); - v3pos_t pmin = lua_istable(L, 2) ? check_v3pos_t(L, 2) : + v3pos_t pmin = lua_istable(L, 2) ? check_v3pos(L, 2) : mg.vm->m_area.MinEdge + v3pos_t(1,1,1) * MAP_BLOCKSIZE; - v3pos_t pmax = lua_istable(L, 3) ? check_v3pos_t(L, 3) : + v3pos_t pmax = lua_istable(L, 3) ? check_v3pos(L, 3) : mg.vm->m_area.MaxEdge - v3pos_t(1,1,1) * MAP_BLOCKSIZE; sortBoxVerticies(pmin, pmax); @@ -1488,8 +1488,8 @@ int ModApiMapgen::l_create_schematic(lua_State *L) Map *map = &(getEnv(L)->getMap()); Schematic schem; - v3pos_t p1 = check_v3pos_t(L, 1); - v3pos_t p2 = check_v3pos_t(L, 2); + v3pos_t p1 = check_v3pos(L, 1); + v3pos_t p2 = check_v3pos(L, 2); sortBoxVerticies(p1, p2); std::vector > prob_list; @@ -1498,7 +1498,7 @@ int ModApiMapgen::l_create_schematic(lua_State *L) while (lua_next(L, 3)) { if (lua_istable(L, -1)) { lua_getfield(L, -1, "pos"); - v3pos_t pos = check_v3pos_t(L, -1); + v3pos_t pos = check_v3pos(L, -1); lua_pop(L, 1); u8 prob = getintfield_default(L, -1, "prob", MTSCHEM_PROB_ALWAYS); @@ -1552,7 +1552,7 @@ int ModApiMapgen::l_place_schematic(lua_State *L) SchematicManager *schemmgr = getServer(L)->getEmergeManager()->schemmgr; //// Read position - v3pos_t p = check_v3pos_t(L, 1); + v3pos_t p = check_v3pos(L, 1); //// Read rotation int rot = ROTATE_0; @@ -1600,7 +1600,7 @@ int ModApiMapgen::l_place_schematic_on_vmanip(lua_State *L) MMVManip *vm = LuaVoxelManip::checkobject(L, 1)->vm; //// Read position - v3pos_t p = check_v3pos_t(L, 2); + v3pos_t p = check_v3pos(L, 2); //// Read rotation int rot = ROTATE_0; diff --git a/src/script/lua_api/l_minimap.cpp b/src/script/lua_api/l_minimap.cpp index 9dc1ce42e4..ac5a120682 100644 --- a/src/script/lua_api/l_minimap.cpp +++ b/src/script/lua_api/l_minimap.cpp @@ -53,7 +53,7 @@ int LuaMinimap::l_get_pos(lua_State *L) LuaMinimap *ref = checkobject(L, 1); Minimap *m = getobject(ref); - push_v3pos_t(L, m->getPos()); + push_v3pos(L, m->getPos()); return 1; } @@ -62,7 +62,7 @@ int LuaMinimap::l_set_pos(lua_State *L) LuaMinimap *ref = checkobject(L, 1); Minimap *m = getobject(ref); - m->setPos(read_v3pos_t(L, 2)); + m->setPos(read_v3pos(L, 2)); return 1; } diff --git a/src/script/lua_api/l_noise.cpp b/src/script/lua_api/l_noise.cpp index 9b99bcbe5d..6bfa05609a 100644 --- a/src/script/lua_api/l_noise.cpp +++ b/src/script/lua_api/l_noise.cpp @@ -304,8 +304,8 @@ int LuaPerlinNoiseMap::l_get_map_slice(lua_State *L) NO_MAP_LOCK_REQUIRED; LuaPerlinNoiseMap *o = checkobject(L, 1); - v3pos_t slice_offset = read_v3pos_t(L, 2); - v3pos_t slice_size = read_v3pos_t(L, 3); + v3pos_t slice_offset = read_v3pos(L, 2); + v3pos_t slice_size = read_v3pos(L, 3); bool use_buffer = lua_istable(L, 4); Noise *n = o->noise; @@ -329,7 +329,7 @@ int LuaPerlinNoiseMap::create_object(lua_State *L) NoiseParams np; if (!read_noiseparams(L, 1, &np)) return 0; - v3pos_t size = read_v3pos_t(L, 2); + v3pos_t size = read_v3pos(L, 2); LuaPerlinNoiseMap *o = new LuaPerlinNoiseMap(&np, 0, size); *(void **)(lua_newuserdata(L, sizeof(void *))) = o; diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp index b0d9934551..d0f7164efa 100644 --- a/src/script/lua_api/l_object.cpp +++ b/src/script/lua_api/l_object.cpp @@ -491,7 +491,7 @@ int ObjectRef::l_send_mapblock(lua_State *L) if (player == nullptr) return 0; - v3pos_t pos = read_v3pos_t(L, 2); + v3pos_t pos = read_v3pos(L, 2); session_t peer_id = player->getPeerId(); bool r = getServer(L)->SendBlock(peer_id, pos); diff --git a/src/script/lua_api/l_rollback.cpp b/src/script/lua_api/l_rollback.cpp index 33410d3272..1942201d00 100644 --- a/src/script/lua_api/l_rollback.cpp +++ b/src/script/lua_api/l_rollback.cpp @@ -40,7 +40,7 @@ int ModApiRollback::l_rollback_get_node_actions(lua_State *L) { NO_MAP_LOCK_REQUIRED; - v3pos_t pos = read_v3pos_t(L, 1); + v3pos_t pos = read_v3pos(L, 1); int range = luaL_checknumber(L, 2); time_t seconds = (time_t) luaL_checknumber(L, 3); int limit = luaL_checknumber(L, 4); @@ -60,7 +60,7 @@ int ModApiRollback::l_rollback_get_node_actions(lua_State *L) lua_pushstring(L, iter->actor.c_str()); lua_setfield(L, -2, "actor"); - push_v3pos_t(L, iter->p); + push_v3pos(L, iter->p); lua_setfield(L, -2, "pos"); lua_pushnumber(L, iter->unix_time); diff --git a/src/script/lua_api/l_vmanip.cpp b/src/script/lua_api/l_vmanip.cpp index 82330644ec..71a6bffcf4 100644 --- a/src/script/lua_api/l_vmanip.cpp +++ b/src/script/lua_api/l_vmanip.cpp @@ -46,14 +46,14 @@ int LuaVoxelManip::l_read_from_map(lua_State *L) LuaVoxelManip *o = checkobject(L, 1); MMVManip *vm = o->vm; - v3bpos_t bp1 = getNodeBlockPos(check_v3pos_t(L, 2)); - v3bpos_t bp2 = getNodeBlockPos(check_v3pos_t(L, 3)); + v3bpos_t bp1 = getNodeBlockPos(check_v3pos(L, 2)); + v3bpos_t bp2 = getNodeBlockPos(check_v3pos(L, 3)); sortBoxVerticies(bp1, bp2); vm->initialEmerge(bp1, bp2); - push_v3pos_t(L, vm->m_area.MinEdge); - push_v3pos_t(L, vm->m_area.MaxEdge); + push_v3pos(L, vm->m_area.MinEdge); + push_v3pos(L, vm->m_area.MaxEdge); return 2; } @@ -139,7 +139,7 @@ int LuaVoxelManip::l_get_node_at(lua_State *L) const NodeDefManager *ndef = getServer(L)->getNodeDefManager(); LuaVoxelManip *o = checkobject(L, 1); - v3pos_t pos = check_v3pos_t(L, 2); + v3pos_t pos = check_v3pos(L, 2); pushnode(L, o->vm->getNodeNoExNoEmerge(pos), ndef); return 1; @@ -152,7 +152,7 @@ int LuaVoxelManip::l_set_node_at(lua_State *L) const NodeDefManager *ndef = getServer(L)->getNodeDefManager(); LuaVoxelManip *o = checkobject(L, 1); - v3pos_t pos = check_v3pos_t(L, 2); + v3pos_t pos = check_v3pos(L, 2); MapNode n = readnode(L, 3, ndef); o->vm->setNodeNoEmerge(pos, n); @@ -198,8 +198,8 @@ int LuaVoxelManip::l_calc_lighting(lua_State *L) v3pos_t yblock = v3pos_t(0, 1, 0) * MAP_BLOCKSIZE; v3pos_t fpmin = vm->m_area.MinEdge; v3pos_t fpmax = vm->m_area.MaxEdge; - v3pos_t pmin = lua_istable(L, 2) ? check_v3pos_t(L, 2) : fpmin + yblock; - v3pos_t pmax = lua_istable(L, 3) ? check_v3pos_t(L, 3) : fpmax - yblock; + v3pos_t pmin = lua_istable(L, 2) ? check_v3pos(L, 2) : fpmin + yblock; + v3pos_t pmax = lua_istable(L, 3) ? check_v3pos(L, 3) : fpmax - yblock; bool propagate_shadow = !lua_isboolean(L, 4) || readParam(L, 4); sortBoxVerticies(pmin, pmax); @@ -237,8 +237,8 @@ int LuaVoxelManip::l_set_lighting(lua_State *L) MMVManip *vm = o->vm; v3pos_t yblock = v3pos_t(0, 1, 0) * MAP_BLOCKSIZE; - v3pos_t pmin = lua_istable(L, 3) ? check_v3pos_t(L, 3) : vm->m_area.MinEdge + yblock; - v3pos_t pmax = lua_istable(L, 4) ? check_v3pos_t(L, 4) : vm->m_area.MaxEdge - yblock; + v3pos_t pmin = lua_istable(L, 3) ? check_v3pos(L, 3) : vm->m_area.MinEdge + yblock; + v3pos_t pmax = lua_istable(L, 4) ? check_v3pos(L, 4) : vm->m_area.MaxEdge - yblock; sortBoxVerticies(pmin, pmax); if (!vm->m_area.contains(VoxelArea(pmin, pmax))) @@ -367,8 +367,8 @@ int LuaVoxelManip::l_get_emerged_area(lua_State *L) LuaVoxelManip *o = checkobject(L, 1); - push_v3pos_t(L, o->vm->m_area.MinEdge); - push_v3pos_t(L, o->vm->m_area.MaxEdge); + push_v3pos(L, o->vm->m_area.MinEdge); + push_v3pos(L, o->vm->m_area.MaxEdge); return 2; } @@ -407,7 +407,7 @@ int LuaVoxelManip::create_object(lua_State *L) Map *map = &(env->getMap()); LuaVoxelManip *o = (lua_istable(L, 1) && lua_istable(L, 2)) ? - new LuaVoxelManip(map, check_v3pos_t(L, 1), check_v3pos_t(L, 2)) : + new LuaVoxelManip(map, check_v3pos(L, 1), check_v3pos(L, 2)) : new LuaVoxelManip(map); *(void **)(lua_newuserdata(L, sizeof(void *))) = o; diff --git a/src/server.cpp b/src/server.cpp index f7af3aec82..b7e82cdb87 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -650,7 +650,7 @@ void Server::AsyncRunStep(bool initial_step) ScopeProfiler sp(g_profiler, "Server: liquid transform"); - std::map modified_blocks; + std::map modified_blocks; m_env->getMap().transformLiquids(modified_blocks, m_env); /* @@ -906,7 +906,7 @@ void Server::AsyncRunStep(bool initial_step) } case MEET_OTHER: prof.add("MEET_OTHER", 1); - for (const v3pos_t &modified_block : event->modified_blocks) { + for (const v3bpos_t &modified_block : event->modified_blocks) { m_clients.markBlockposAsNotSent(modified_block); } break; @@ -921,9 +921,9 @@ void Server::AsyncRunStep(bool initial_step) Set blocks not sent to far players */ if (!far_players.empty()) { - // Convert list format to that wanted by SetBlocksNotSent - std::map modified_blocks2; - for (const v3pos_t &modified_block : event->modified_blocks) { + // Convert libst format to that wanted by SetBlocksNotSent + std::map modified_blocks2; + for (const v3bpos_t &modified_block : event->modified_blocks) { modified_blocks2[modified_block] = m_env->getMap().getBlockNoCreateNoEx(modified_block); } @@ -1223,7 +1223,7 @@ void Server::onMapEditEvent(const MapEditEvent &event) m_unsent_map_edit_queue.push(new MapEditEvent(event)); } -void Server::SetBlocksNotSent(std::map& block) +void Server::SetBlocksNotSent(std::map& block) { std::vector clients = m_clients.getClientIDs(); m_clients.lock(); @@ -2420,7 +2420,7 @@ void Server::SendBlocks(float dtime) m_clients.unlock(); } -bool Server::SendBlock(session_t peer_id, const v3pos_t &blockpos) +bool Server::SendBlock(session_t peer_id, const v3bpos_t &blockpos) { MapBlock *block = m_env->getMap().getBlockNoCreateNoEx(blockpos); if (!block) diff --git a/src/server.h b/src/server.h index bc7fc175d2..64ce4f9312 100644 --- a/src/server.h +++ b/src/server.h @@ -372,7 +372,7 @@ class Server : public con::PeerHandler, public MapEventReceiver, ModChannel *getModChannel(const std::string &channel); // Send block to specific player only - bool SendBlock(session_t peer_id, const v3pos_t &blockpos); + bool SendBlock(session_t peer_id, const v3bpos_t &blockpos); // Get or load translations for a language Translations *getTranslationLanguage(const std::string &lang_code); diff --git a/src/server/serveractiveobject.h b/src/server/serveractiveobject.h index b529f437ee..7467350905 100644 --- a/src/server/serveractiveobject.h +++ b/src/server/serveractiveobject.h @@ -233,7 +233,7 @@ class ServerActiveObject : public ActiveObject The block from which the object was loaded from, and in which a copy of the static data resides. */ - v3pos_t m_static_block = v3pos_t(1337,1337,1337); + v3bpos_t m_static_block = v3bpos_t(1337,1337,1337); protected: virtual void onMarkedForDeactivation() {} diff --git a/src/serverenvironment.cpp b/src/serverenvironment.cpp index 13db96162d..6efe145ba3 100644 --- a/src/serverenvironment.cpp +++ b/src/serverenvironment.cpp @@ -291,9 +291,9 @@ void LBMManager::applyLBMs(ServerEnvironment *env, MapBlock *block, u32 stamp) ActiveBlockList */ -void fillRadiusBlock(v3pos_t p0, s16 r, std::set &list) +void fillRadiusBlock(v3bpos_t p0, s16 r, std::set &list) { - v3pos_t p; + v3bpos_t p; for(p.X=p0.X-r; p.X<=p0.X+r; p.X++) for(p.Y=p0.Y-r; p.Y<=p0.Y+r; p.Y++) for(p.Z=p0.Z-r; p.Z<=p0.Z+r; p.Z++) @@ -306,14 +306,14 @@ void fillRadiusBlock(v3pos_t p0, s16 r, std::set &list) } } -void fillViewConeBlock(v3pos_t p0, +void fillViewConeBlock(v3bpos_t p0, const s16 r, const v3f camera_pos, const v3f camera_dir, const float camera_fov, - std::set &list) + std::set &list) { - v3pos_t p; + v3bpos_t p; const s16 r_nodes = r * BS * MAP_BLOCKSIZE; for (p.X = p0.X - r; p.X <= p0.X+r; p.X++) for (p.Y = p0.Y - r; p.Y <= p0.Y+r; p.Y++) @@ -333,7 +333,7 @@ void ActiveBlockList::update(std::vector &active_players, /* Create the new list */ - std::set newlist = m_forceloaded_list; + std::set newlist = m_forceloaded_list; m_abm_list = m_forceloaded_list; for (const PlayerSAO *playersao : active_players) { v3bpos_t pos = getNodeBlockPos(floatToInt(playersao->getBasePosition(), BS)); @@ -359,7 +359,7 @@ void ActiveBlockList::update(std::vector &active_players, Find out which blocks on the old list are not on the new list */ // Go through old list - for (v3pos_t p : m_list) { + for (v3bpos_t p : m_list) { // If not on new list, it's been removed if (newlist.find(p) == newlist.end()) blocks_removed.insert(p); @@ -369,7 +369,7 @@ void ActiveBlockList::update(std::vector &active_players, Find out which blocks on the new list are not on the old list */ // Go through new list - for (v3pos_t p : newlist) { + for (v3bpos_t p : newlist) { // If not on old list, it's been added if(m_list.find(p) == m_list.end()) blocks_added.insert(p); @@ -379,7 +379,7 @@ void ActiveBlockList::update(std::vector &active_players, Update m_list */ m_list.clear(); - for (v3pos_t p : newlist) { + for (v3bpos_t p : newlist) { m_list.insert(p); } } @@ -822,7 +822,7 @@ class ABMHandler for(s16 z=-1; z<=1; z++) { MapBlock *block2 = map->getBlockNoCreateNoEx( - block->getPos() + v3pos_t(x,y,z)); + block->getPos() + v3bpos_t(x,y,z)); if(block2==NULL){ wider_unknown_count++; continue; @@ -1118,7 +1118,7 @@ u8 ServerEnvironment::findSunlight(v3pos_t pos) const MapNode node = m_map->getNode(neighborPos, &is_position_ok); if (!is_position_ok) { // This happens very rarely because the map at currentPos is loaded - m_map->emergeBlock(neighborPos, false); + m_map->emergeBlock(getNodeBlockPos(neighborPos), false); node = m_map->getNode(neighborPos, &is_position_ok); if (!is_position_ok) continue; // not generated @@ -1190,7 +1190,7 @@ void ServerEnvironment::clearObjects(ClearObjectsMode mode) m_ao_manager.clear(cb_removal); // Get list of loaded blocks - std::vector loaded_blocks; + std::vector loaded_blocks; infostream << "ServerEnvironment::clearObjects(): " << "Listing all loaded blocks" << std::endl; m_map->listAllLoadedBlocks(loaded_blocks); @@ -1199,7 +1199,7 @@ void ServerEnvironment::clearObjects(ClearObjectsMode mode) << loaded_blocks.size()< loadable_blocks; + std::vector loadable_blocks; if (mode == CLEAR_OBJECTS_MODE_FULL) { infostream << "ServerEnvironment::clearObjects(): " << "Listing all loadable blocks" << std::endl; @@ -1216,7 +1216,7 @@ void ServerEnvironment::clearObjects(ClearObjectsMode mode) << " blocks" << std::endl; // Grab a reference on each loaded block to avoid unloading it - for (v3pos_t p : loaded_blocks) { + for (v3bpos_t p : loaded_blocks) { MapBlock *block = m_map->getBlockNoCreateNoEx(p); assert(block != NULL); block->refGrab(); @@ -1234,7 +1234,7 @@ void ServerEnvironment::clearObjects(ClearObjectsMode mode) u32 num_objs_cleared = 0; for (auto i = loadable_blocks.begin(); i != loadable_blocks.end(); ++i) { - v3pos_t p = *i; + v3bpos_t p = *i; MapBlock *block = m_map->emergeBlock(p, false); if (!block) { errorstream << "ServerEnvironment::clearObjects(): " @@ -1269,7 +1269,7 @@ void ServerEnvironment::clearObjects(ClearObjectsMode mode) m_map->unloadUnreferencedBlocks(); // Drop references that were added above - for (v3pos_t p : loaded_blocks) { + for (v3bpos_t p : loaded_blocks) { MapBlock *block = m_map->getBlockNoCreateNoEx(p); assert(block); block->refDrop(); @@ -1349,8 +1349,8 @@ void ServerEnvironment::step(float dtime) g_settings->getS16("active_object_send_range_blocks"); static thread_local const s16 active_block_range = g_settings->getS16("active_block_range"); - std::set blocks_removed; - std::set blocks_added; + std::set blocks_removed; + std::set blocks_added; m_active_blocks.update(players, active_block_range, active_object_range, blocks_removed, blocks_added); @@ -1361,7 +1361,7 @@ void ServerEnvironment::step(float dtime) // Convert active objects that are no more in active blocks to static deactivateFarObjects(false); - for (const v3pos_t &p: blocks_removed) { + for (const v3bpos_t &p: blocks_removed) { MapBlock *block = m_map->getBlockNoCreateNoEx(p); if (!block) continue; @@ -1374,7 +1374,7 @@ void ServerEnvironment::step(float dtime) Handle added blocks */ - for (const v3pos_t &p: blocks_added) { + for (const v3bpos_t &p: blocks_added) { MapBlock *block = m_map->getBlockOrEmerge(p); if (!block) { m_active_blocks.m_list.erase(p); @@ -1394,7 +1394,7 @@ void ServerEnvironment::step(float dtime) float dtime = m_cache_nodetimer_interval; - for (const v3pos_t &p: m_active_blocks.m_list) { + for (const v3bpos_t &p: m_active_blocks.m_list) { MapBlock *block = m_map->getBlockNoCreateNoEx(p); if (!block) continue; @@ -1438,7 +1438,7 @@ void ServerEnvironment::step(float dtime) int abms_run = 0; int blocks_cached = 0; - std::vector output(m_active_blocks.m_abm_list.size()); + std::vector output(m_active_blocks.m_abm_list.size()); // Shuffle the active blocks so that each block gets an equal chance // of having its ABMs run. @@ -1448,7 +1448,7 @@ void ServerEnvironment::step(float dtime) int i = 0; // determine the time budget for ABMs u32 max_time_ms = m_cache_abm_interval * 1000 * m_cache_abm_time_budget; - for (const v3pos_t &p : output) { + for (const v3bpos_t &p : output) { MapBlock *block = m_map->getBlockNoCreateNoEx(p); if (!block) continue; @@ -1683,7 +1683,7 @@ void ServerEnvironment::getRemovedActiveObjects(PlayerSAO *playersao, s16 radius } void ServerEnvironment::setStaticForActiveObjectsInBlock( - v3pos_t blockpos, bool static_exists, v3pos_t static_block) + v3bpos_t blockpos, bool static_exists, v3bpos_t static_block) { MapBlock *block = m_map->getBlockNoCreateNoEx(blockpos); if (!block) @@ -2152,7 +2152,7 @@ void ServerEnvironment::deleteStaticFromBlock( } bool ServerEnvironment::saveStaticToBlock( - v3pos_t blockpos, u16 store_id, + v3bpos_t blockpos, u16 store_id, ServerActiveObject *obj, const StaticObject &s_obj, u32 mod_reason) { diff --git a/src/serverenvironment.h b/src/serverenvironment.h index a119cf2406..8d6eda880d 100644 --- a/src/serverenvironment.h +++ b/src/serverenvironment.h @@ -164,10 +164,10 @@ class ActiveBlockList void update(std::vector &active_players, s16 active_block_range, s16 active_object_range, - std::set &blocks_removed, - std::set &blocks_added); + std::set &blocks_removed, + std::set &blocks_added); - bool contains(v3pos_t p){ + bool contains(v3bpos_t p){ return (m_list.find(p) != m_list.end()); } @@ -175,9 +175,9 @@ class ActiveBlockList m_list.clear(); } - std::set m_list; - std::set m_abm_list; - std::set m_forceloaded_list; + std::set m_list; + std::set m_abm_list; + std::set m_forceloaded_list; private: }; @@ -346,7 +346,7 @@ class ServerEnvironment : public Environment void reportMaxLagEstimate(float f) { m_max_lag_estimate = f; } float getMaxLagEstimate() { return m_max_lag_estimate; } - std::set* getForceloadedBlocks() { return &m_active_blocks.m_forceloaded_list; } + std::set* getForceloadedBlocks() { return &m_active_blocks.m_forceloaded_list; } // Sorted by how ready a mapblock is enum BlockStatus { @@ -355,12 +355,12 @@ class ServerEnvironment : public Environment BS_LOADED, BS_ACTIVE // always highest value }; - BlockStatus getBlockStatus(v3pos_t blockpos); + BlockStatus getBlockStatus(v3bpos_t blockpos); // Sets the static object status all the active objects in the specified block // This is only really needed for deleting blocks from the map - void setStaticForActiveObjectsInBlock(v3pos_t blockpos, - bool static_exists, v3pos_t static_block=v3pos_t(0,0,0)); + void setStaticForActiveObjectsInBlock(v3bpos_t blockpos, + bool static_exists, v3bpos_t static_block=v3bpos_t(0,0,0)); RemotePlayer *getPlayer(const session_t peer_id); RemotePlayer *getPlayer(const char* name); @@ -427,7 +427,7 @@ class ServerEnvironment : public Environment */ void deleteStaticFromBlock( ServerActiveObject *obj, u16 id, u32 mod_reason, bool no_emerge); - bool saveStaticToBlock(v3pos_t blockpos, u16 store_id, + bool saveStaticToBlock(v3bpos_t blockpos, u16 store_id, ServerActiveObject *obj, const StaticObject &s_obj, u32 mod_reason); /* diff --git a/src/util/areastore.cpp b/src/util/areastore.cpp index 91eb6439ae..f026a3c0e8 100644 --- a/src/util/areastore.cpp +++ b/src/util/areastore.cpp @@ -168,7 +168,7 @@ void AreaStore::cacheMiss(void *data, const v3pos_t &mpos, std::vector * void AreaStore::getAreasForPos(std::vector *result, v3pos_t pos) { if (m_cache_enabled) { - v3pos_t mblock = getContainerPos(pos, m_cacheblock_radius); + v3bpos_t mblock = getContainerPos(pos, m_cacheblock_radius); const std::vector *pre_list = m_res_cache.lookupCache(mblock); size_t s_p_l = pre_list->size(); diff --git a/src/util/areastore.h b/src/util/areastore.h index b51ca2b5e1..5fbb7b95e2 100644 --- a/src/util/areastore.h +++ b/src/util/areastore.h @@ -124,7 +124,7 @@ class AreaStore { /// Range, in nodes, of the getAreasForPos cache. /// If you modify this, call invalidateCache() u8 m_cacheblock_radius = 64; - LRUCache > m_res_cache; + LRUCache > m_res_cache; }; diff --git a/src/voxelalgorithms.h b/src/voxelalgorithms.h index a1d64b2047..c1d4871ad5 100644 --- a/src/voxelalgorithms.h +++ b/src/voxelalgorithms.h @@ -69,7 +69,7 @@ void update_block_border_lighting(Map *map, MapBlock *block, * the function modified */ void blit_back_with_light(ServerMap *map, MMVManip *vm, - std::map *modified_blocks); + std::map *modified_blocks); /*! * Corrects the light in a map block. From 4c4b804ac4ae1eec81a4250a1248c8409e53ae8f Mon Sep 17 00:00:00 2001 From: proller Date: Tue, 7 Dec 2021 23:15:07 +0300 Subject: [PATCH 06/36] Better bpos_t --- src/client/client.cpp | 2 +- src/clientiface.cpp | 10 +++++----- src/clientiface.h | 4 ++-- src/emerge.cpp | 4 ++-- src/main.cpp | 8 ++++---- src/map.cpp | 22 +++++++++++----------- src/mapblock.cpp | 6 +++--- src/reflowscan.cpp | 2 +- src/reflowscan.h | 3 ++- src/script/lua_api/l_env.cpp | 4 ++-- src/script/lua_api/l_object.cpp | 2 +- src/script/lua_api/l_vmanip.h | 2 +- src/server/player_sao.cpp | 2 +- src/util/areastore.h | 2 +- src/voxelalgorithms.cpp | 26 +++++++++++++------------- 15 files changed, 50 insertions(+), 49 deletions(-) diff --git a/src/client/client.cpp b/src/client/client.cpp index 60787cf5ea..351799ed83 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -1620,7 +1620,7 @@ void Client::addUpdateMeshTaskWithEdge(v3bpos_t blockpos, bool ack_to_server, bo for (int i=0;i<6;i++) { try{ - v3bpos_t p = blockpos + g_6dirs[i]; + v3bpos_t p = blockpos + g_6dirs_b[i]; addUpdateMeshTask(p, false, urgent); } catch(InvalidPositionException &e){} diff --git a/src/clientiface.cpp b/src/clientiface.cpp index 635bf400e2..022e70ba9d 100644 --- a/src/clientiface.cpp +++ b/src/clientiface.cpp @@ -64,7 +64,7 @@ RemoteClient::RemoteClient() : { } -void RemoteClient::ResendBlockIfOnWire(v3pos_t p) +void RemoteClient::ResendBlockIfOnWire(v3bpos_t p) { // if this block is on wire, mark it for sending again as soon as possible if (m_blocks_sending.find(p) != m_blocks_sending.end()) { @@ -184,7 +184,7 @@ void RemoteClient::GetNextBlocks ( } if (m_nearest_unsent_d > 0) { // make sure any blocks modified since the last time we sent blocks are resent - for (const v3pos_t &p : m_blocks_modified) { + for (const v3bpos_t &p : m_blocks_modified) { m_nearest_unsent_d = std::min(m_nearest_unsent_d, center.getDistanceFrom(p)); } } @@ -426,12 +426,12 @@ void RemoteClient::SetBlockNotSent(v3bpos_t p) m_blocks_modified.insert(p); } -void RemoteClient::SetBlocksNotSent(std::map &blocks) +void RemoteClient::SetBlocksNotSent(std::map &blocks) { m_nothing_to_send_pause_timer = 0; for (auto &block : blocks) { - v3pos_t p = block.first; + v3bpos_t p = block.first; // remove the block from sending and sent sets, // and mark as modified if found if (m_blocks_sending.erase(p) + m_blocks_sent.erase(p) > 0) @@ -637,7 +637,7 @@ std::vector ClientInterface::getClientIDs(ClientState min_state) return reply; } -void ClientInterface::markBlockposAsNotSent(const v3pos_t &pos) +void ClientInterface::markBlockposAsNotSent(const v3bpos_t &pos) { RecursiveMutexAutoLock clientslock(m_clients_mutex); for (const auto &client : m_clients) { diff --git a/src/clientiface.h b/src/clientiface.h index 158368a958..7a350b39ec 100644 --- a/src/clientiface.h +++ b/src/clientiface.h @@ -370,8 +370,8 @@ class RemoteClient No MapBlock* is stored here because the blocks can get deleted. */ std::set m_blocks_sent; - pos_t m_nearest_unsent_d = 0; - v3pos_t m_last_center; + bpos_t m_nearest_unsent_d = 0; + v3bpos_t m_last_center; v3f m_last_camera_dir; const u16 m_max_simul_sends; diff --git a/src/emerge.cpp b/src/emerge.cpp index c4b5f59503..2499cdb878 100644 --- a/src/emerge.cpp +++ b/src/emerge.cpp @@ -613,8 +613,8 @@ MapBlock *EmergeThread::finishGen(v3bpos_t pos, BlockMakeData *bmdata, return NULL; } - v3pos_t minp = bmdata->blockpos_min * MAP_BLOCKSIZE; - v3pos_t maxp = bmdata->blockpos_max * MAP_BLOCKSIZE + + v3pos_t minp = getBlockPosRelative(bmdata->blockpos_min); + v3pos_t maxp = getBlockPosRelative(bmdata->blockpos_max) + v3pos_t(1,1,1) * (MAP_BLOCKSIZE - 1); // Ignore map edit events, they will not need to be sent diff --git a/src/main.cpp b/src/main.cpp index 9ae4201419..bc44035f5a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1003,10 +1003,10 @@ static bool migrate_map_database(const GameParams &game_params, const Settings & time_t last_update_time = 0; bool &kill = *porting::signal_handler_killstatus(); - std::vector blocks; + std::vector blocks; old_db->listAllLoadableBlocks(blocks); new_db->beginSave(); - for (std::vector::const_iterator it = blocks.begin(); it != blocks.end(); ++it) { + for (std::vector::const_iterator it = blocks.begin(); it != blocks.end(); ++it) { if (kill) return false; std::string data; @@ -1058,7 +1058,7 @@ static bool recompress_map_database(const GameParams &game_params, const Setting const u8 serialize_as_ver = SER_FMT_VER_HIGHEST_WRITE; // This is ok because the server doesn't actually run - std::vector blocks; + std::vector blocks; db->listAllLoadableBlocks(blocks); db->beginSave(); std::istringstream iss(std::ios_base::binary); @@ -1076,7 +1076,7 @@ static bool recompress_map_database(const GameParams &game_params, const Setting iss.str(data); iss.clear(); - MapBlock mb(nullptr, v3pos_t(0,0,0), &server); + MapBlock mb(nullptr, v3bpos_t(0,0,0), &server); u8 ver = readU8(iss); mb.deSerialize(iss, ver, true); diff --git a/src/map.cpp b/src/map.cpp index 87751cb297..1fe9dcc01c 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -159,7 +159,7 @@ MapNode Map::getNode(v3pos_t p, bool *is_valid_position) return {CONTENT_IGNORE}; } - v3pos_t relpos = p - blockpos*MAP_BLOCKSIZE; + v3pos_t relpos = p - getBlockPosRelative(blockpos); bool is_valid_p; MapNode node = block->getNodeNoCheck(relpos, &is_valid_p); if (is_valid_position != NULL) @@ -172,7 +172,7 @@ void Map::setNode(v3pos_t p, MapNode & n) { v3bpos_t blockpos = getNodeBlockPos(p); MapBlock *block = getBlockNoCreate(blockpos); - v3pos_t relpos = p - blockpos*MAP_BLOCKSIZE; + v3pos_t relpos = p - getBlockPosRelative(blockpos); // Never allow placing CONTENT_IGNORE, it causes problems if(n.getContent() == CONTENT_IGNORE){ bool temp_bool; @@ -902,7 +902,7 @@ std::vector Map::findNodesWithMetadata(v3pos_t p1, v3pos_t p2) continue; } - v3pos_t p_base = blockpos * MAP_BLOCKSIZE; + v3pos_t p_base = getBlockPosRelative(blockpos); std::vector keys = block->m_node_metadata.getAllKeys(); for (size_t i = 0; i != keys.size(); i++) { v3pos_t p(keys[i] + p_base); @@ -919,7 +919,7 @@ std::vector Map::findNodesWithMetadata(v3pos_t p1, v3pos_t p2) NodeMetadata *Map::getNodeMetadata(v3pos_t p) { v3bpos_t blockpos = getNodeBlockPos(p); - v3pos_t p_rel = p - blockpos*MAP_BLOCKSIZE; + v3pos_t p_rel = p - getBlockPosRelative(blockpos); MapBlock *block = getBlockNoCreateNoEx(blockpos); if(!block){ infostream<<"Map::getNodeMetadata(): Need to emerge " @@ -938,7 +938,7 @@ NodeMetadata *Map::getNodeMetadata(v3pos_t p) bool Map::setNodeMetadata(v3pos_t p, NodeMetadata *meta) { v3bpos_t blockpos = getNodeBlockPos(p); - v3pos_t p_rel = p - blockpos*MAP_BLOCKSIZE; + v3pos_t p_rel = p - getBlockPosRelative(blockpos); MapBlock *block = getBlockNoCreateNoEx(blockpos); if(!block){ infostream<<"Map::setNodeMetadata(): Need to emerge " @@ -957,7 +957,7 @@ bool Map::setNodeMetadata(v3pos_t p, NodeMetadata *meta) void Map::removeNodeMetadata(v3pos_t p) { v3bpos_t blockpos = getNodeBlockPos(p); - v3pos_t p_rel = p - blockpos*MAP_BLOCKSIZE; + v3pos_t p_rel = p - getBlockPosRelative(blockpos); MapBlock *block = getBlockNoCreateNoEx(blockpos); if(block == NULL) { @@ -971,7 +971,7 @@ void Map::removeNodeMetadata(v3pos_t p) NodeTimer Map::getNodeTimer(v3pos_t p) { v3bpos_t blockpos = getNodeBlockPos(p); - v3pos_t p_rel = p - blockpos*MAP_BLOCKSIZE; + v3pos_t p_rel = p - getBlockPosRelative(blockpos); MapBlock *block = getBlockNoCreateNoEx(blockpos); if(!block){ infostream<<"Map::getNodeTimer(): Need to emerge " @@ -992,7 +992,7 @@ void Map::setNodeTimer(const NodeTimer &t) { v3pos_t p = t.position; v3bpos_t blockpos = getNodeBlockPos(p); - v3pos_t p_rel = p - blockpos*MAP_BLOCKSIZE; + v3pos_t p_rel = p - getBlockPosRelative(blockpos); MapBlock *block = getBlockNoCreateNoEx(blockpos); if(!block){ infostream<<"Map::setNodeTimer(): Need to emerge " @@ -1011,7 +1011,7 @@ void Map::setNodeTimer(const NodeTimer &t) void Map::removeNodeTimer(v3pos_t p) { v3bpos_t blockpos = getNodeBlockPos(p); - v3pos_t p_rel = p - blockpos*MAP_BLOCKSIZE; + v3pos_t p_rel = p - getBlockPosRelative(blockpos); MapBlock *block = getBlockNoCreateNoEx(blockpos); if(block == NULL) { @@ -1885,7 +1885,7 @@ void MMVManip::initialEmerge(v3bpos_t blockpos_min, v3bpos_t blockpos_max, v3bpos_t p_max = blockpos_max; VoxelArea block_area_nodes - (p_min*MAP_BLOCKSIZE, (p_max+1)*MAP_BLOCKSIZE-v3pos_t(1,1,1)); + (getBlockPosRelative(p_min), getBlockPosRelative(p_max+1)-v3pos_t(1,1,1)); u32 size_MB = block_area_nodes.getVolume()*4/1000000; if(size_MB >= 1) @@ -1936,7 +1936,7 @@ void MMVManip::initialEmerge(v3bpos_t blockpos_min, v3bpos_t blockpos_max, /* Mark area inexistent */ - VoxelArea a(p*MAP_BLOCKSIZE, (p+1)*MAP_BLOCKSIZE-v3pos_t(1,1,1)); + VoxelArea a(getBlockPosRelative(p), getBlockPosRelative(p+1)-v3pos_t(1,1,1)); // Fill with VOXELFLAG_NO_DATA for(s32 z=a.MinEdge.Z; z<=a.MaxEdge.Z; z++) for(s32 y=a.MinEdge.Y; y<=a.MaxEdge.Y; y++) diff --git a/src/mapblock.cpp b/src/mapblock.cpp index 74e11a9f4e..5d56bd8462 100644 --- a/src/mapblock.cpp +++ b/src/mapblock.cpp @@ -66,10 +66,10 @@ static const char *modified_reason_strings[] = { MapBlock */ -MapBlock::MapBlock(Map *parent, v3pos_t pos, IGameDef *gamedef, bool dummy): +MapBlock::MapBlock(Map *parent, v3bpos_t pos, IGameDef *gamedef, bool dummy): m_parent(parent), m_pos(pos), - m_pos_relative(pos * MAP_BLOCKSIZE), + m_pos_relative(getBlockPosRelative(pos)), m_gamedef(gamedef) { if (!dummy) @@ -825,7 +825,7 @@ std::string analyze_block(MapBlock *block) std::ostringstream desc; - v3pos_t p = block->getPos(); + v3bpos_t p = block->getPos(); char spos[25]; porting::mt_snprintf(spos, sizeof(spos), "(%2d,%2d,%2d), ", p.X, p.Y, p.Z); desc<getBlockNoCreateNoEx(pos); m_lookup_state_bitset |= (1 << idx); } diff --git a/src/reflowscan.h b/src/reflowscan.h index 0ce4102ba4..6c29bec37a 100644 --- a/src/reflowscan.h +++ b/src/reflowscan.h @@ -40,7 +40,8 @@ class ReflowScan { private: Map *m_map = nullptr; const NodeDefManager *m_ndef = nullptr; - v3pos_t m_block_pos, m_rel_block_pos; + v3bpos_t m_block_pos; + v3pos_t m_rel_block_pos; UniqueQueue *m_liquid_queue = nullptr; MapBlock *m_lookup[3 * 3 * 3]; u32 m_lookup_state_bitset; diff --git a/src/script/lua_api/l_env.cpp b/src/script/lua_api/l_env.cpp index 5eaa5f4251..fe0e2ea713 100644 --- a/src/script/lua_api/l_env.cpp +++ b/src/script/lua_api/l_env.cpp @@ -1396,7 +1396,7 @@ int ModApiEnvMod::l_forceload_block(lua_State *L) { GET_ENV_PTR; - v3pos_t blockpos = read_v3pos(L, 1); + v3bpos_t blockpos = read_v3pos(L, 1); env->getForceloadedBlocks()->insert(blockpos); return 0; } @@ -1425,7 +1425,7 @@ int ModApiEnvMod::l_forceload_free_block(lua_State *L) { GET_ENV_PTR; - v3pos_t blockpos = read_v3pos(L, 1); + v3bpos_t blockpos = read_v3pos(L, 1); env->getForceloadedBlocks()->erase(blockpos); return 0; } diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp index d0f7164efa..dfa4c7711f 100644 --- a/src/script/lua_api/l_object.cpp +++ b/src/script/lua_api/l_object.cpp @@ -491,7 +491,7 @@ int ObjectRef::l_send_mapblock(lua_State *L) if (player == nullptr) return 0; - v3pos_t pos = read_v3pos(L, 2); + v3bpos_t pos = read_v3pos(L, 2); session_t peer_id = player->getPeerId(); bool r = getServer(L)->SendBlock(peer_id, pos); diff --git a/src/script/lua_api/l_vmanip.h b/src/script/lua_api/l_vmanip.h index 4ecd883f8e..c689906deb 100644 --- a/src/script/lua_api/l_vmanip.h +++ b/src/script/lua_api/l_vmanip.h @@ -33,7 +33,7 @@ class MMVManip; class LuaVoxelManip : public ModApiBase { private: - std::map modified_blocks; + std::map modified_blocks; bool is_mapgen_vm = false; static const char className[]; diff --git a/src/server/player_sao.cpp b/src/server/player_sao.cpp index cace042102..b0f3955e82 100644 --- a/src/server/player_sao.cpp +++ b/src/server/player_sao.cpp @@ -339,7 +339,7 @@ void PlayerSAO::setPos(const v3f &pos) return; // Send mapblock of target location - v3pos_t blockpos = v3pos_t(pos.X / MAP_BLOCKSIZE, pos.Y / MAP_BLOCKSIZE, pos.Z / MAP_BLOCKSIZE); + v3bpos_t blockpos = v3bpos_t(pos.X / MAP_BLOCKSIZE, pos.Y / MAP_BLOCKSIZE, pos.Z / MAP_BLOCKSIZE); m_env->getGameDef()->SendBlock(m_peer_id, blockpos); setBasePosition(pos); diff --git a/src/util/areastore.h b/src/util/areastore.h index 5fbb7b95e2..b734e8bb02 100644 --- a/src/util/areastore.h +++ b/src/util/areastore.h @@ -118,7 +118,7 @@ class AreaStore { private: /// Called by the cache when a value isn't found in the cache. - static void cacheMiss(void *data, const v3pos_t &mpos, std::vector *dest); + static void cacheMiss(void *data, const v3bpos_t &mpos, std::vector *dest); bool m_cache_enabled = true; /// Range, in nodes, of the getAreasForPos cache. diff --git a/src/voxelalgorithms.cpp b/src/voxelalgorithms.cpp index cdf176cb7f..454051102a 100644 --- a/src/voxelalgorithms.cpp +++ b/src/voxelalgorithms.cpp @@ -248,7 +248,7 @@ bool step_rel_block_pos(direction dir, relative_v3 &rel_pos, */ void unspread_light(Map *map, const NodeDefManager *nodemgr, LightBank bank, UnlightQueue &from_nodes, ReLightQueue &light_sources, - std::map &modified_blocks) + std::map &modified_blocks) { // Stores data popped from from_nodes u8 current_light; @@ -352,7 +352,7 @@ void unspread_light(Map *map, const NodeDefManager *nodemgr, LightBank bank, */ void spread_light(Map *map, const NodeDefManager *nodemgr, LightBank bank, LightQueue &light_sources, - std::map &modified_blocks) + std::map &modified_blocks) { // The light the current node can provide to its neighbors. u8 spreading_light; @@ -418,7 +418,7 @@ struct SunlightPropagationUnit{ struct SunlightPropagationData{ std::vector data; - v3pos_t target_block; + v3bpos_t target_block; }; /*! @@ -687,7 +687,7 @@ bool is_light_locally_correct(Map *map, const NodeDefManager *ndef, } void update_block_border_lighting(Map *map, MapBlock *block, - std::map &modified_blocks) + std::map &modified_blocks) { const NodeDefManager *ndef = map->getNodeDefManager(); bool is_valid_position; @@ -700,7 +700,7 @@ void update_block_border_lighting(Map *map, MapBlock *block, for (direction d = 0; d < 6; d++) { // For each direction // Get neighbor block - v3pos_t otherpos = block->getPos() + neighbor_dirs[d]; + v3bpos_t otherpos = block->getPos() + neighbor_dirs[d]; MapBlock *other = map->getBlockNoCreateNoEx(otherpos); if (other == NULL) { continue; @@ -829,7 +829,7 @@ void fill_with_sunlight(MMVManip *vm, const NodeDefManager *ndef, v2pos_t offset void is_sunlight_above_block(ServerMap *map, mapblock_v3 pos, const NodeDefManager *ndef, bool light[MAP_BLOCKSIZE][MAP_BLOCKSIZE]) { - mapblock_v3 source_block_pos = pos + v3pos_t(0, 1, 0); + mapblock_v3 source_block_pos = pos + v3bpos_t(0, 1, 0); // Get or load source block. // It might take a while to load, but correcting incorrect // sunlight may be even slower. @@ -976,7 +976,7 @@ const VoxelArea block_pad[] = { */ void finish_bulk_light_update(Map *map, mapblock_v3 minblock, mapblock_v3 maxblock, UnlightQueue unlight[2], ReLightQueue relight[2], - std::map *modified_blocks) + std::map *modified_blocks) { const NodeDefManager *ndef = map->getNodeDefManager(); // dummy boolean @@ -993,7 +993,7 @@ void finish_bulk_light_update(Map *map, mapblock_v3 minblock, // --- STEP 2: Get all newly inserted light sources // For each block: - v3pos_t blockpos; + v3bpos_t blockpos; v3pos_t relpos; for (blockpos.X = minblock.X; blockpos.X <= maxblock.X; blockpos.X++) for (blockpos.Y = minblock.Y; blockpos.Y <= maxblock.Y; blockpos.Y++) @@ -1045,7 +1045,7 @@ void finish_bulk_light_update(Map *map, mapblock_v3 minblock, } void blit_back_with_light(ServerMap *map, MMVManip *vm, - std::map *modified_blocks) + std::map *modified_blocks) { const NodeDefManager *ndef = map->getNodeDefManager(); mapblock_v3 minblock = getNodeBlockPos(vm->m_area.MinEdge); @@ -1071,7 +1071,7 @@ void blit_back_with_light(ServerMap *map, MMVManip *vm, // Reset the voxel manipulator. fill_with_sunlight(vm, ndef, offset, lights); // Copy sunlight data - data.target_block = v3pos_t(x, minblock.Y - 1, z); + data.target_block = v3bpos_t(x, minblock.Y - 1, z); for (s16 z = 0; z < MAP_BLOCKSIZE; z++) for (s16 x = 0; x < MAP_BLOCKSIZE; x++) data.data.emplace_back(v2pos_t(x, z), lights[z][x]); @@ -1087,7 +1087,7 @@ void blit_back_with_light(ServerMap *map, MMVManip *vm, } // --- STEP 2: Get nodes from borders to unlight - v3pos_t blockpos; + v3bpos_t blockpos; v3pos_t relpos; // In case there are unloaded holes in the voxel manipulator @@ -1188,7 +1188,7 @@ void fill_with_sunlight(MapBlock *block, const NodeDefManager *ndef, } void repair_block_light(ServerMap *map, MapBlock *block, - std::map *modified_blocks) + std::map *modified_blocks) { if (!block || block->isDummy()) return; @@ -1212,7 +1212,7 @@ void repair_block_light(ServerMap *map, MapBlock *block, // Reset the voxel manipulator. fill_with_sunlight(block, ndef, lights); // Copy sunlight data - data.target_block = v3pos_t(blockpos.X, blockpos.Y - 1, blockpos.Z); + data.target_block = v3bpos_t(blockpos.X, blockpos.Y - 1, blockpos.Z); for (s16 z = 0; z < MAP_BLOCKSIZE; z++) for (s16 x = 0; x < MAP_BLOCKSIZE; x++) { data.data.emplace_back(v2pos_t(x, z), lights[z][x]); From 42fb97a4a181e3232fecd76163b07094c8cb66c9 Mon Sep 17 00:00:00 2001 From: proller Date: Wed, 8 Dec 2021 00:01:00 +0300 Subject: [PATCH 07/36] Oops --- src/client/client.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/client.cpp b/src/client/client.cpp index 351799ed83..60787cf5ea 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -1620,7 +1620,7 @@ void Client::addUpdateMeshTaskWithEdge(v3bpos_t blockpos, bool ack_to_server, bo for (int i=0;i<6;i++) { try{ - v3bpos_t p = blockpos + g_6dirs_b[i]; + v3bpos_t p = blockpos + g_6dirs[i]; addUpdateMeshTask(p, false, urgent); } catch(InvalidPositionException &e){} From e2ce232e1720c0f51dcf625f915f36d0f236ca39 Mon Sep 17 00:00:00 2001 From: proller Date: Wed, 8 Dec 2021 02:24:19 +0300 Subject: [PATCH 08/36] sqlite error on limit --- src/database/database-sqlite3.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/database/database-sqlite3.cpp b/src/database/database-sqlite3.cpp index 854685c1e8..eb9d49c32e 100644 --- a/src/database/database-sqlite3.cpp +++ b/src/database/database-sqlite3.cpp @@ -37,6 +37,7 @@ SQLite format specification: #include "server/player_sao.h" #include +#include // When to print messages when the database is being held locked by another process // Note: I've seen occasional delays of over 250ms while running minetestmapper. @@ -117,6 +118,12 @@ Database_SQLite3::Database_SQLite3(const std::string &savedir, const std::string m_savedir(savedir), m_dbname(dbname) { +#if USE_POS32 + pos_t mapgen_limit = g_settings->getPOS("mapgen_limit"); + if (mapgen_limit > 31000) { + throw DatabaseException("Database_SQLite3: mapgen_limit is too big (" + std::to_string(mapgen_limit) + "). Please set mapgen_limit = 31000"); + } +#endif } void Database_SQLite3::beginSave() From cd1a40796c90a2dd3239dc14d400f7c7995487ce Mon Sep 17 00:00:00 2001 From: proller Date: Wed, 8 Dec 2021 03:05:25 +0300 Subject: [PATCH 09/36] Some lost s16 --- src/mapgen/mg_decoration.cpp | 4 ++-- src/script/lua_api/l_env.cpp | 6 +++--- src/script/lua_api/l_mapgen.cpp | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/mapgen/mg_decoration.cpp b/src/mapgen/mg_decoration.cpp index 54224aec40..f36c5a595e 100644 --- a/src/mapgen/mg_decoration.cpp +++ b/src/mapgen/mg_decoration.cpp @@ -185,8 +185,8 @@ size_t Decoration::placeDeco(Mapgen *mg, u32 blockseed, v3pos_t nmin, v3pos_t nm } } - s16 x = p2d_min.X - 1; - s16 z = p2d_min.Y; + pos_t x = p2d_min.X - 1; + pos_t z = p2d_min.Y; for (u32 i = 0; i < deco_count; i++) { if (!cover) { diff --git a/src/script/lua_api/l_env.cpp b/src/script/lua_api/l_env.cpp index fe0e2ea713..8d27d35024 100644 --- a/src/script/lua_api/l_env.cpp +++ b/src/script/lua_api/l_env.cpp @@ -1193,9 +1193,9 @@ int ModApiEnvMod::l_load_area(lua_State *L) } else { v3bpos_t bp2 = getNodeBlockPos(check_v3pos(L, 2)); sortBoxVerticies(bp1, bp2); - for (s16 z = bp1.Z; z <= bp2.Z; z++) - for (s16 y = bp1.Y; y <= bp2.Y; y++) - for (s16 x = bp1.X; x <= bp2.X; x++) { + for (bpos_t z = bp1.Z; z <= bp2.Z; z++) + for (bpos_t y = bp1.Y; y <= bp2.Y; y++) + for (bpos_t x = bp1.X; x <= bp2.X; x++) { map->emergeBlock(v3bpos_t(x, y, z)); } } diff --git a/src/script/lua_api/l_mapgen.cpp b/src/script/lua_api/l_mapgen.cpp index 8c79acad39..2823958dc9 100644 --- a/src/script/lua_api/l_mapgen.cpp +++ b/src/script/lua_api/l_mapgen.cpp @@ -717,8 +717,8 @@ int ModApiMapgen::l_get_spawn_level(lua_State *L) { NO_MAP_LOCK_REQUIRED; - s16 x = luaL_checkinteger(L, 1); - s16 z = luaL_checkinteger(L, 2); + pos_t x = luaL_checkinteger(L, 1); + pos_t z = luaL_checkinteger(L, 2); EmergeManager *emerge = getServer(L)->getEmergeManager(); int spawn_level = emerge->getSpawnLevelAtPoint(v2pos_t(x, z)); From b8f6b7aea17ebf0f6ad0a72267c50dcfde75050f Mon Sep 17 00:00:00 2001 From: proller Date: Sat, 11 Dec 2021 03:38:57 +0300 Subject: [PATCH 10/36] Fix sqlite limit message --- src/database/database-sqlite3.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/database/database-sqlite3.cpp b/src/database/database-sqlite3.cpp index eb9d49c32e..41c09c7040 100644 --- a/src/database/database-sqlite3.cpp +++ b/src/database/database-sqlite3.cpp @@ -118,12 +118,6 @@ Database_SQLite3::Database_SQLite3(const std::string &savedir, const std::string m_savedir(savedir), m_dbname(dbname) { -#if USE_POS32 - pos_t mapgen_limit = g_settings->getPOS("mapgen_limit"); - if (mapgen_limit > 31000) { - throw DatabaseException("Database_SQLite3: mapgen_limit is too big (" + std::to_string(mapgen_limit) + "). Please set mapgen_limit = 31000"); - } -#endif } void Database_SQLite3::beginSave() @@ -208,6 +202,12 @@ MapDatabaseSQLite3::MapDatabaseSQLite3(const std::string &savedir): Database_SQLite3(savedir, "map"), MapDatabase() { +#if USE_POS32 + pos_t mapgen_limit = g_settings->getPOS("mapgen_limit"); + if (mapgen_limit > 31000) { + throw DatabaseException("Database_SQLite3: mapgen_limit is too big (" + std::to_string(mapgen_limit) + "). Please set mapgen_limit = 31000"); + } +#endif } MapDatabaseSQLite3::~MapDatabaseSQLite3() From 92461011e53fbe61120a72ef6ce6376c42fa6e2e Mon Sep 17 00:00:00 2001 From: proller Date: Thu, 30 Dec 2021 20:43:22 +0300 Subject: [PATCH 11/36] float -> double part 0 --- src/activeobject.h | 2 +- src/client/activeobjectmgr.cpp | 2 +- src/client/activeobjectmgr.h | 2 +- src/client/camera.cpp | 14 ++- src/client/camera.h | 8 +- src/client/client.cpp | 10 +- src/client/clientenvironment.cpp | 12 +- src/client/clientenvironment.h | 4 +- src/client/clientevent.h | 2 +- src/client/clientmap.cpp | 30 ++--- src/client/clientmap.h | 4 +- src/client/clientobject.h | 4 +- src/client/clouds.cpp | 2 +- src/client/content_cao.cpp | 54 ++++----- src/client/content_cao.h | 10 +- src/client/content_mapblock.cpp | 6 +- src/client/game.cpp | 40 +++---- src/client/gameui.cpp | 2 +- src/client/hud.cpp | 20 ++-- src/client/hud.h | 6 +- src/client/localplayer.cpp | 80 +++++++------- src/client/localplayer.h | 14 +-- src/client/minimap.cpp | 4 +- src/client/particles.cpp | 22 ++-- src/client/particles.h | 2 +- src/client/shadows/dynamicshadows.cpp | 8 +- src/clientiface.cpp | 6 +- src/collision.cpp | 72 +++++++----- src/collision.h | 9 +- src/constants.h | 1 + src/database/database-files.cpp | 4 +- src/database/database-leveldb.cpp | 4 +- src/database/database-sqlite3.cpp | 4 +- src/environment.cpp | 16 +-- src/environment.h | 5 +- src/hud.h | 3 +- src/irr_aabb3d.h | 1 + src/irr_v3d.h | 1 + src/irrlichttypes.h | 6 +- src/map.cpp | 6 +- src/mapblock.h | 13 +++ src/network/clientpackethandler.cpp | 8 +- src/network/networkpacket.cpp | 39 +++++++ src/network/networkpacket.h | 6 + src/network/serverpackethandler.cpp | 16 +-- src/particles.cpp | 4 +- src/particles.h | 3 +- src/raycast.cpp | 9 +- src/raycast.h | 9 +- src/script/common/c_converter.cpp | 47 ++++++++ src/script/common/c_converter.h | 5 + src/script/cpp_api/s_item.cpp | 2 +- src/script/cpp_api/s_item.h | 2 +- src/script/lua_api/l_env.cpp | 18 +-- src/script/lua_api/l_env.h | 2 +- src/script/lua_api/l_noise.cpp | 6 +- src/script/lua_api/l_object.cpp | 6 +- src/script/lua_api/l_particles.cpp | 4 +- src/script/lua_api/l_particles_local.cpp | 2 +- src/server.cpp | 32 +++--- src/server.h | 2 +- src/server/activeobjectmgr.cpp | 12 +- src/server/activeobjectmgr.h | 6 +- src/server/luaentity_sao.cpp | 20 ++-- src/server/luaentity_sao.h | 12 +- src/server/player_sao.cpp | 30 ++--- src/server/player_sao.h | 14 +-- src/server/serveractiveobject.cpp | 2 +- src/server/serveractiveobject.h | 12 +- src/server/unit_sao.cpp | 6 +- src/server/unit_sao.h | 4 +- src/serverenvironment.cpp | 20 ++-- src/serverenvironment.h | 9 +- src/settings.h | 3 + src/staticobject.cpp | 6 +- src/staticobject.h | 4 +- src/unittest/test_activeobject.cpp | 2 +- src/unittest/test_collision.cpp | 64 +++++------ src/unittest/test_serveractiveobjectmgr.cpp | 40 +++---- src/unittest/test_voxelalgorithms.cpp | 20 ++-- src/util/directiontables.cpp | 11 ++ src/util/directiontables.h | 1 + src/util/numeric.cpp | 18 +-- src/util/numeric.h | 115 +++++++++++++++++++- src/util/pointedthing.cpp | 4 +- src/util/pointedthing.h | 6 +- src/util/serialize.h | 50 +++++++++ src/voxelalgorithms.cpp | 4 +- src/voxelalgorithms.h | 4 +- 89 files changed, 778 insertions(+), 458 deletions(-) diff --git a/src/activeobject.h b/src/activeobject.h index 1d8a3712b6..9e5b7950ba 100644 --- a/src/activeobject.h +++ b/src/activeobject.h @@ -103,7 +103,7 @@ class ActiveObject * The box's coordinates are world coordinates. * @returns true if the object has a collision box. */ - virtual bool getCollisionBox(aabb3f *toset) const = 0; + virtual bool getCollisionBox(aabb3o *toset) const = 0; /*! diff --git a/src/client/activeobjectmgr.cpp b/src/client/activeobjectmgr.cpp index 82f3cb9447..fb0a625ba9 100644 --- a/src/client/activeobjectmgr.cpp +++ b/src/client/activeobjectmgr.cpp @@ -90,7 +90,7 @@ void ActiveObjectMgr::removeObject(u16 id) } // clang-format on -void ActiveObjectMgr::getActiveObjects(const v3f &origin, f32 max_d, +void ActiveObjectMgr::getActiveObjects(const v3opos_t &origin, f32 max_d, std::vector &dest) { f32 max_d2 = max_d * max_d; diff --git a/src/client/activeobjectmgr.h b/src/client/activeobjectmgr.h index 510b2d6e3a..468a57eb00 100644 --- a/src/client/activeobjectmgr.h +++ b/src/client/activeobjectmgr.h @@ -35,7 +35,7 @@ class ActiveObjectMgr : public ::ActiveObjectMgr bool registerObject(ClientActiveObject *obj) override; void removeObject(u16 id) override; - void getActiveObjects(const v3f &origin, f32 max_d, + void getActiveObjects(const v3opos_t &origin, f32 max_d, std::vector &dest); }; } // namespace client diff --git a/src/client/camera.cpp b/src/client/camera.cpp index 1fc45927cf..4cfaf37cd6 100644 --- a/src/client/camera.cpp +++ b/src/client/camera.cpp @@ -313,7 +313,7 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 busytime, f32 tool_r // Get player position // Smooth the movement when walking up stairs v3f old_player_position = m_playernode->getPosition(); - v3f player_position = player->getPosition(); + auto player_position = player->getPosition(); // This is worse than `LocalPlayer::getPosition()` but // mods expect the player head to be at the parent's position @@ -338,7 +338,7 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 busytime, f32 tool_r } // Set player node transformation - m_playernode->setPosition(player_position); + m_playernode->setPosition(oposToV3f(player_position)); m_playernode->setRotation(v3f(0, -1 * player->getYaw(), 0)); m_playernode->updateAbsolutePosition(); @@ -405,14 +405,16 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 busytime, f32 tool_r } // Compute absolute camera position and target - m_headnode->getAbsoluteTransformation().transformVect(m_camera_position, rel_cam_pos); + auto tmp = oposToV3f(m_camera_position); // TODO use offset? + m_headnode->getAbsoluteTransformation().transformVect(tmp, rel_cam_pos); + m_camera_position = v3fToOpos(tmp); m_headnode->getAbsoluteTransformation().rotateVect(m_camera_direction, rel_cam_target - rel_cam_pos); v3f abs_cam_up; m_headnode->getAbsoluteTransformation().rotateVect(abs_cam_up, rel_cam_up); // Seperate camera position for calculation - v3f my_cp = m_camera_position; + auto my_cp = m_camera_position; // Reposition the camera for third person view if (m_camera_mode > CAMERA_MODE_FIRST) @@ -459,10 +461,10 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 busytime, f32 tool_r (((pos_t)(my_cp.Z/BS) - m_camera_offset.Z)/CAMERA_OFFSET_STEP); // Set camera node transformation - m_cameranode->setPosition(my_cp-intToFloat(m_camera_offset, BS)); + m_cameranode->setPosition(oposToV3f(my_cp-posToOpos(m_camera_offset, BS))); m_cameranode->setUpVector(abs_cam_up); // *100.0 helps in large map coordinates - m_cameranode->setTarget(my_cp-intToFloat(m_camera_offset, BS) + 100 * m_camera_direction); + m_cameranode->setTarget(oposToV3f(my_cp-posToOpos(m_camera_offset, BS) + v3fToOpos(100 * m_camera_direction))); // update the camera position in third-person mode to render blocks behind player // and correctly apply liquid post FX. diff --git a/src/client/camera.h b/src/client/camera.h index 2195377200..3cd4a884cc 100644 --- a/src/client/camera.h +++ b/src/client/camera.h @@ -91,15 +91,15 @@ class Camera // Get the camera position (in absolute scene coordinates). // This has view bobbing applied. - inline v3f getPosition() const + inline v3opos_t getPosition() const { return m_camera_position; } // Returns the absolute position of the head SceneNode in the world - inline v3f getHeadPosition() const + inline v3opos_t getHeadPosition() const { - return m_headnode->getAbsolutePosition(); + return v3fToOpos(m_headnode->getAbsolutePosition()); } // Get the camera direction (in absolute camera coordinates). @@ -209,7 +209,7 @@ class Camera f32 m_cache_fov; // Absolute camera position - v3f m_camera_position; + v3opos_t m_camera_position; // Absolute camera direction v3f m_camera_direction; // Camera offset diff --git a/src/client/client.cpp b/src/client/client.cpp index 6d40c0f207..32c72ebf57 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -610,7 +610,7 @@ void Client::step(float dtime) ClientActiveObject *cao = m_env.getActiveObject(object_id); if (!cao) continue; - m_sound->updateSoundPosition(client_id, cao->getPosition()); + m_sound->updateSoundPosition(client_id, oposToV3f(cao->getPosition())); } } @@ -924,7 +924,7 @@ void Client::Send(NetworkPacket* pkt) // Will fill up 12 + 12 + 4 + 4 + 4 bytes void writePlayerPos(LocalPlayer *myplayer, ClientMap *clientMap, NetworkPacket *pkt) { - v3f pf = myplayer->getPosition() * 100; + v3opos_t pf = myplayer->getPosition() * 100; v3f sf = myplayer->getSpeed() * 100; s32 pitch = myplayer->getPitch() * 100; s32 yaw = myplayer->getYaw() * 100; @@ -1357,7 +1357,7 @@ void Client::removeNode(v3pos_t p) MapNode Client::CSMGetNode(v3pos_t p, bool *is_valid_position) { if (checkCSMRestrictionFlag(CSMRestrictionFlags::CSM_RF_LOOKUP_NODES)) { - v3pos_t ppos = floatToInt(m_env.getLocalPlayer()->getPosition(), BS); + v3pos_t ppos = oposToPos(m_env.getLocalPlayer()->getPosition(), BS); if ((u32) ppos.getDistanceFrom(p) > m_csm_restriction_noderange) { *is_valid_position = false; return {}; @@ -1371,7 +1371,7 @@ int Client::CSMClampRadius(v3pos_t pos, int radius) if (!checkCSMRestrictionFlag(CSMRestrictionFlags::CSM_RF_LOOKUP_NODES)) return radius; // This is approximate and will cause some allowed nodes to be excluded - v3pos_t ppos = floatToInt(m_env.getLocalPlayer()->getPosition(), BS); + v3pos_t ppos = oposToPos(m_env.getLocalPlayer()->getPosition(), BS); u32 distance = ppos.getDistanceFrom(pos); if (distance >= m_csm_restriction_noderange) return 0; @@ -1382,7 +1382,7 @@ v3pos_t Client::CSMClampPos(v3pos_t pos) { if (!checkCSMRestrictionFlag(CSMRestrictionFlags::CSM_RF_LOOKUP_NODES)) return pos; - v3pos_t ppos = floatToInt(m_env.getLocalPlayer()->getPosition(), BS); + v3pos_t ppos = oposToPos(m_env.getLocalPlayer()->getPosition(), BS); const int range = m_csm_restriction_noderange; return v3pos_t( core::clamp(pos.X, (int)ppos.X - range, (int)ppos.X + range), diff --git a/src/client/clientenvironment.cpp b/src/client/clientenvironment.cpp index e5867d09e1..4965742d32 100644 --- a/src/client/clientenvironment.cpp +++ b/src/client/clientenvironment.cpp @@ -485,13 +485,13 @@ ClientEnvEvent ClientEnvironment::getClientEnvEvent() } void ClientEnvironment::getSelectedActiveObjects( - const core::line3d &shootline_on_map, + const core::line3d &shootline_on_map, std::vector &objects) { std::vector allObjects; getActiveObjects(shootline_on_map.start, shootline_on_map.getLength() + 10.0f, allObjects); - const v3f line_vector = shootline_on_map.getVector(); + const v3opos_t line_vector = shootline_on_map.getVector(); for (const auto &allObject : allObjects) { ClientActiveObject *obj = allObject.obj; @@ -499,11 +499,11 @@ void ClientEnvironment::getSelectedActiveObjects( if (!obj->getSelectionBox(&selection_box)) continue; - const v3f &pos = obj->getPosition(); - aabb3f offsetted_box(selection_box.MinEdge + pos, - selection_box.MaxEdge + pos); + const v3opos_t &pos = obj->getPosition(); + aabb3o offsetted_box(v3fToOpos(selection_box.MinEdge) + pos, + v3fToOpos(selection_box.MaxEdge) + pos); - v3f current_intersection; + v3opos_t current_intersection; v3pos_t current_normal; if (boxLineCollision(offsetted_box, shootline_on_map.start, line_vector, ¤t_intersection, ¤t_normal)) { diff --git a/src/client/clientenvironment.h b/src/client/clientenvironment.h index 1b64e26cbe..0949d233cf 100644 --- a/src/client/clientenvironment.h +++ b/src/client/clientenvironment.h @@ -119,7 +119,7 @@ class ClientEnvironment : public Environment */ // Get all nearby objects - void getActiveObjects(const v3f &origin, f32 max_d, + void getActiveObjects(const v3opos_t &origin, f32 max_d, std::vector &dest) { return m_ao_manager.getActiveObjects(origin, max_d, dest); @@ -131,7 +131,7 @@ class ClientEnvironment : public Environment ClientEnvEvent getClientEnvEvent(); virtual void getSelectedActiveObjects( - const core::line3d &shootline_on_map, + const core::line3d &shootline_on_map, std::vector &objects ); diff --git a/src/client/clientevent.h b/src/client/clientevent.h index 17d3aedd6a..74c6bbff52 100644 --- a/src/client/clientevent.h +++ b/src/client/clientevent.h @@ -61,7 +61,7 @@ struct ClientEventHudAdd std::string text, text2; u32 number, item, dir, style; v2f align, offset; - v3f world_pos; + v3opos_t world_pos; v2s32 size; s16 z_index; }; diff --git a/src/client/clientmap.cpp b/src/client/clientmap.cpp index fe29e78c15..a6d40b9dd5 100644 --- a/src/client/clientmap.cpp +++ b/src/client/clientmap.cpp @@ -173,7 +173,7 @@ void ClientMap::updateDrawList() } m_drawlist.clear(); - const v3f camera_position = m_camera_position; + const auto camera_position = m_camera_position; const v3f camera_direction = m_camera_direction; // Use a higher fov to accomodate faster camera movements. @@ -310,7 +310,7 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass) const int crack = m_client->getCrackLevel(); const u32 daynight_ratio = m_client->getEnv().getDayNightRatio(); - const v3f camera_position = m_camera_position; + const auto camera_position = m_camera_position; /* Get all blocks and draw all visible ones @@ -350,7 +350,7 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass) if (!block->mesh) continue; - v3f block_pos_r = intToFloat(block->getPosRelative() + MAP_BLOCKSIZE / 2, BS); + auto block_pos_r = posToOpos(block->getPosRelative() + MAP_BLOCKSIZE / 2, BS); float d = camera_position.getDistanceFrom(block_pos_r); d = MYMAX(0,d - BLOCK_MAX_RADIUS); @@ -437,7 +437,7 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass) TimeTaker draw("Drawing mesh buffers"); core::matrix4 m; // Model matrix - v3f offset = intToFloat(m_camera_offset, BS); + auto offset = intToFloat(m_camera_offset, BS); u32 material_swaps = 0; // Render all mesh buffers in order @@ -470,8 +470,8 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass) ++material_swaps; } - v3f block_wpos = intToFloat(descriptor.m_pos * MAP_BLOCKSIZE, BS); - m.setTranslation(block_wpos - offset); + auto block_wpos = intToFloat(descriptor.m_pos * MAP_BLOCKSIZE, BS); + m.setTranslation(oposToV3f(block_wpos - offset)); driver->setTransform(video::ETS_WORLD, m); driver->drawMeshBuffer(buf); @@ -494,7 +494,7 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass) g_profiler->avg(prefix + "material swaps [#]", material_swaps); } -static bool getVisibleBrightness(Map *map, const v3f &p0, v3f dir, float step, +static bool getVisibleBrightness(Map *map, const v3opos_t &p0, v3f dir, float step, float step_multiplier, float start_distance, float end_distance, const NodeDefManager *ndef, u32 daylight_factor, float sunlight_min_d, int *result, bool *sunlight_seen) @@ -503,8 +503,8 @@ static bool getVisibleBrightness(Map *map, const v3f &p0, v3f dir, float step, int brightness_count = 0; float distance = start_distance; dir.normalize(); - v3f pf = p0; - pf += dir * distance; + auto pf = p0; + pf += v3fToOpos(dir * distance); int noncount = 0; bool nonlight_seen = false; bool allow_allowing_non_sunlight_propagates = false; @@ -523,13 +523,13 @@ static bool getVisibleBrightness(Map *map, const v3f &p0, v3f dir, float step, MapNode n = map->getNode(p); if(n.getContent() == CONTENT_IGNORE){ float newd = 2*BS; - pf = p0 + dir * 2*newd; + pf = p0 + v3fToOpos(dir * 2*newd); distance = newd; sunlight_min_d = 0; } } for (int i=0; distance < end_distance; i++) { - pf += dir * step; + pf += v3fToOpos(dir * step); distance += step; step *= step_multiplier; @@ -752,7 +752,7 @@ void ClientMap::renderMapShadows(video::IVideoDriver *driver, TimeTaker draw("Drawing shadow mesh buffers"); core::matrix4 m; // Model matrix - v3f offset = intToFloat(m_camera_offset, BS); + auto offset = intToFloat(m_camera_offset, BS); // Render all layers in order for (auto &lists : drawbufs.lists) { @@ -775,8 +775,8 @@ void ClientMap::renderMapShadows(video::IVideoDriver *driver, local_material.Lighting = false; driver->setMaterial(local_material); - v3f block_wpos = intToFloat(pair.first * MAP_BLOCKSIZE, BS); - m.setTranslation(block_wpos - offset); + auto block_wpos = intToFloat(pair.first * MAP_BLOCKSIZE, BS); + m.setTranslation(oposToV3f(block_wpos - offset)); driver->setTransform(video::ETS_WORLD, m); driver->drawMeshBuffer(buf); @@ -805,7 +805,7 @@ void ClientMap::updateDrawListShadow(const v3f &shadow_light_pos, const v3f &sha { ScopeProfiler sp(g_profiler, "CM::updateDrawListShadow()", SPT_AVG); - const v3f camera_position = shadow_light_pos; + const v3opos_t camera_position = v3fToOpos(shadow_light_pos); const v3f camera_direction = shadow_light_dir; // I "fake" fov just to avoid creating a new function to handle orthographic // projection. diff --git a/src/client/clientmap.h b/src/client/clientmap.h index 391744cff6..d7c853e240 100644 --- a/src/client/clientmap.h +++ b/src/client/clientmap.h @@ -85,7 +85,7 @@ class ClientMap : public Map, public scene::ISceneNode ISceneNode::drop(); } - void updateCamera(const v3f &pos, const v3f &dir, f32 fov, const v3pos_t &offset) + void updateCamera(const v3opos_t &pos, const v3f &dir, f32 fov, const v3pos_t &offset) { v3bpos_t previous_block = getContainerPos(floatToInt(m_camera_position, BS) + m_camera_offset, MAP_BLOCKSIZE); @@ -175,7 +175,7 @@ class ClientMap : public Map, public scene::ISceneNode MapDrawControl &m_control; - v3f m_camera_position = v3f(0,0,0); + v3opos_t m_camera_position = v3opos_t(0,0,0); v3f m_camera_direction = v3f(0,0,1); f32 m_camera_fov = M_PI; v3pos_t m_camera_offset; diff --git a/src/client/clientobject.h b/src/client/clientobject.h index b192f0dcd7..d9728d772c 100644 --- a/src/client/clientobject.h +++ b/src/client/clientobject.h @@ -44,10 +44,10 @@ class ClientActiveObject : public ActiveObject virtual void updateLight(u32 day_night_ratio) {} - virtual bool getCollisionBox(aabb3f *toset) const { return false; } + virtual bool getCollisionBox(aabb3o *toset) const { return false; } virtual bool getSelectionBox(aabb3f *toset) const { return false; } virtual bool collideWithObjects() const { return false; } - virtual const v3f getPosition() const { return v3f(0.0f); } + virtual const v3opos_t getPosition() const { return v3opos_t(0.0f); } virtual scene::ISceneNode *getSceneNode() const { return NULL; } virtual scene::IAnimatedMeshSceneNode *getAnimatedMeshSceneNode() const diff --git a/src/client/clouds.cpp b/src/client/clouds.cpp index af0f377d8a..34a07e30bb 100644 --- a/src/client/clouds.cpp +++ b/src/client/clouds.cpp @@ -307,7 +307,7 @@ void Clouds::render() } v3f pos(p0.X, m_params.height * BS, p0.Y); - pos -= intToFloat(m_camera_offset, BS); + pos -= posToFloat(m_camera_offset, BS); for (video::S3DVertex &vertex : v) { vertex.Pos += pos; diff --git a/src/client/content_cao.cpp b/src/client/content_cao.cpp index e1f42d81e5..ac550564c0 100644 --- a/src/client/content_cao.cpp +++ b/src/client/content_cao.cpp @@ -211,7 +211,7 @@ class TestCAO : public ClientActiveObject void processMessage(const std::string &data); - bool getCollisionBox(aabb3f *toset) const { return false; } + bool getCollisionBox(aabb3o *toset) const { return false; } private: scene::IMeshSceneNode *m_node; v3f m_position; @@ -333,13 +333,13 @@ GenericCAO::GenericCAO(Client *client, ClientEnvironment *env): } } -bool GenericCAO::getCollisionBox(aabb3f *toset) const +bool GenericCAO::getCollisionBox(aabb3o *toset) const { if (m_prop.physical) { //update collision box - toset->MinEdge = m_prop.collisionbox.MinEdge * BS; - toset->MaxEdge = m_prop.collisionbox.MaxEdge * BS; + toset->MinEdge = v3fToOpos(m_prop.collisionbox.MinEdge) * BS; + toset->MaxEdge = v3fToOpos(m_prop.collisionbox.MaxEdge) * BS; toset->MinEdge += m_position; toset->MaxEdge += m_position; @@ -378,7 +378,7 @@ void GenericCAO::processInitData(const std::string &data) m_name = deSerializeString16(is); m_is_player = readU8(is); m_id = readU16(is); - m_position = readV3F32(is); + m_position = readV3O(is); m_rotation = readV3F32(is); m_hp = readU16(is); @@ -420,7 +420,7 @@ bool GenericCAO::getSelectionBox(aabb3f *toset) const return true; } -const v3f GenericCAO::getPosition() const +const v3opos_t GenericCAO::getPosition() const { if (!getParent()) return pos_translator.val_current; @@ -428,8 +428,8 @@ const v3f GenericCAO::getPosition() const // Calculate real position in world based on MatrixNode if (m_matrixnode) { v3pos_t camera_offset = m_env->getCameraOffset(); - return m_matrixnode->getAbsolutePosition() + - intToFloat(camera_offset, BS); + return v3fToOpos(m_matrixnode->getAbsolutePosition()) + + posToOpos(camera_offset, BS); } return m_position; @@ -933,13 +933,13 @@ void GenericCAO::setNodeLight(u8 light) u16 GenericCAO::getLightPosition(v3pos_t *pos) { const auto &box = m_prop.collisionbox; - pos[0] = floatToInt(m_position + box.MinEdge * BS, BS); - pos[1] = floatToInt(m_position + box.MaxEdge * BS, BS); + pos[0] = oposToPos(m_position + v3fToOpos(box.MinEdge * BS), BS); + pos[1] = oposToPos(m_position + v3fToOpos(box.MaxEdge * BS), BS); // Skip center pos if it falls into the same node as Min or MaxEdge if ((box.MaxEdge - box.MinEdge).getLengthSQ() < 3.0f) return 2; - pos[2] = floatToInt(m_position + box.getCenter() * BS, BS); + pos[2] = oposToPos(m_position + v3fToOpos(box.getCenter() * BS), BS); return 3; } @@ -1006,9 +1006,9 @@ void GenericCAO::updateNodePos() if (node) { v3pos_t camera_offset = m_env->getCameraOffset(); - v3f pos = pos_translator.val_current - - intToFloat(camera_offset, BS); - getPosRotMatrix().setTranslation(pos); + v3opos_t pos = pos_translator.val_current - + posToOpos(camera_offset, BS); + getPosRotMatrix().setTranslation(oposToV3f(pos)); if (node != m_spritenode) { // rotate if not a sprite v3f rot = m_is_local_player ? -m_rotation : -rot_translator.val_current; setPitchYawRoll(getPosRotMatrix(), rot); @@ -1133,16 +1133,16 @@ void GenericCAO::step(float dtime, ClientEnvironment *env) pos_translator.val_target = m_position; } else { rot_translator.translate(dtime); - v3f lastpos = pos_translator.val_current; + auto lastpos = pos_translator.val_current; if(m_prop.physical) { - aabb3f box = m_prop.collisionbox; + auto box = m_prop.collisionbox; box.MinEdge *= BS; box.MaxEdge *= BS; collisionMoveResult moveresult; f32 pos_max_d = BS*0.125; // Distance per iteration - v3f p_pos = m_position; + auto p_pos = m_position; v3f p_velocity = m_velocity; moveresult = collisionMoveSimple(env,env->getGameDef(), pos_max_d, box, m_prop.stepheight, dtime, @@ -1155,7 +1155,7 @@ void GenericCAO::step(float dtime, ClientEnvironment *env) bool is_end_position = moveresult.collides; pos_translator.update(m_position, is_end_position, dtime); } else { - m_position += dtime * m_velocity + 0.5 * dtime * dtime * m_acceleration; + m_position += v3fToOpos(dtime * m_velocity + 0.5 * dtime * dtime * m_acceleration); m_velocity += dtime * m_acceleration; pos_translator.update(m_position, pos_translator.aim_is_end, pos_translator.anim_time); @@ -1169,14 +1169,14 @@ void GenericCAO::step(float dtime, ClientEnvironment *env) m_step_distance_counter = 0.0f; if (!m_is_local_player && m_prop.makes_footstep_sound) { const NodeDefManager *ndef = m_client->ndef(); - v3pos_t p = floatToInt(getPosition() + - v3f(0.0f, (m_prop.collisionbox.MinEdge.Y - 0.5f) * BS, 0.0f), BS); + v3pos_t p = oposToPos(getPosition() + + v3opos_t(0.0f, (m_prop.collisionbox.MinEdge.Y - 0.5f) * BS, 0.0f), BS); MapNode n = m_env->getMap().getNode(p); SimpleSoundSpec spec = ndef->get(n).sound_footstep; // Reduce footstep gain, as non-local-player footsteps are // somehow louder. spec.gain *= 0.6f; - m_client->sound()->playSoundAt(spec, false, getPosition()); + m_client->sound()->playSoundAt(spec, false, oposToV3f(getPosition())); } } } @@ -1597,10 +1597,10 @@ void GenericCAO::updateAttachments() if (!parent) { // Detach or don't attach if (m_matrixnode) { v3pos_t camera_offset = m_env->getCameraOffset(); - v3f old_pos = getPosition(); + auto old_pos = getPosition(); m_matrixnode->setParent(m_smgr->getRootSceneNode()); - getPosRotMatrix().setTranslation(old_pos - intToFloat(camera_offset, BS)); + getPosRotMatrix().setTranslation(oposToV3f(old_pos - posToOpos(camera_offset, BS))); m_matrixnode->updateAbsolutePosition(); } } @@ -1714,7 +1714,7 @@ void GenericCAO::processMessage(const std::string &data) } else if (cmd == AO_CMD_UPDATE_POSITION) { // Not sent by the server if this object is an attachment. // We might however get here if the server notices the object being detached before the client. - m_position = readV3F32(is); + m_position = v3fToOpos(readV3F32(is)); //TODO f64 m_velocity = readV3F32(is); m_acceleration = readV3F32(is); m_rotation = readV3F32(is); @@ -1727,7 +1727,7 @@ void GenericCAO::processMessage(const std::string &data) // Place us a bit higher if we're physical, to not sink into // the ground due to sucky collision detection... if(m_prop.physical) - m_position += v3f(0,0.002,0); + m_position += v3opos_t(0,0.002,0); if(getParent() != NULL) // Just in case return; @@ -1853,7 +1853,7 @@ void GenericCAO::processMessage(const std::string &data) // TODO: Execute defined fast response // As there is no definition, make a smoke puff ClientSimpleObject *simple = createSmokePuff( - m_smgr, m_env, m_position, + m_smgr, m_env, oposToV3f(m_position), v2f(m_prop.visual_size.X, m_prop.visual_size.Y) * BS); m_env->addSimpleObject(simple); } else if (m_reset_textures_timer < 0 && !m_prop.damage_texture_modifier.empty()) { @@ -1920,7 +1920,7 @@ bool GenericCAO::directReportPunch(v3f dir, const ItemStack *punchitem, // TODO: Execute defined fast response // As there is no definition, make a smoke puff ClientSimpleObject *simple = createSmokePuff( - m_smgr, m_env, m_position, + m_smgr, m_env, oposToV3f(m_position), v2f(m_prop.visual_size.X, m_prop.visual_size.Y) * BS); m_env->addSimpleObject(simple); } diff --git a/src/client/content_cao.h b/src/client/content_cao.h index 7cd855b93a..f86a54055a 100644 --- a/src/client/content_cao.h +++ b/src/client/content_cao.h @@ -86,12 +86,12 @@ class GenericCAO : public ClientActiveObject scene::IDummyTransformationSceneNode *m_matrixnode = nullptr; Nametag *m_nametag = nullptr; MinimapMarker *m_marker = nullptr; - v3f m_position = v3f(0.0f, 10.0f * BS, 0); + v3opos_t m_position = v3opos_t(0.0f, 10.0f * BS, 0); v3f m_velocity; v3f m_acceleration; v3f m_rotation; u16 m_hp = 1; - SmoothTranslator pos_translator; + SmoothTranslator pos_translator; SmoothTranslatorWrappedv3f rot_translator; // Spritesheet/animation stuff v2f m_tx_size = v2f(1,1); @@ -157,15 +157,15 @@ class GenericCAO : public ClientActiveObject void processInitData(const std::string &data); - bool getCollisionBox(aabb3f *toset) const; + bool getCollisionBox(aabb3o *toset) const; bool collideWithObjects() const; virtual bool getSelectionBox(aabb3f *toset) const; - const v3f getPosition() const; + const v3opos_t getPosition() const; - void setPosition(const v3f &pos) + void setPosition(const v3opos_t &pos) { pos_translator.val_current = pos; } diff --git a/src/client/content_mapblock.cpp b/src/client/content_mapblock.cpp index 45b9b983d7..626b6b3711 100644 --- a/src/client/content_mapblock.cpp +++ b/src/client/content_mapblock.cpp @@ -448,7 +448,7 @@ void MapblockMeshGenerator::getLiquidNeighborhood() for (int w = -1; w <= 1; w++) for (int u = -1; u <= 1; u++) { NeighborData &neighbor = liquid_neighbors[w + 1][u + 1]; - v3pos_t p2 = p + v3pos_t(u, 0, w); + auto p2 = p + v3pos_t(u, 0, w); MapNode n2 = data->m_vmanip.getNodeNoEx(blockpos_nodes + p2); neighbor.content = n2.getContent(); neighbor.level = -0.5 * BS; @@ -1196,7 +1196,7 @@ void MapblockMeshGenerator::drawFencelikeNode() tile = tile_nocrack; // Now a section of fence, +X, if there's a post there - v3pos_t p2 = p; + auto p2 = p; p2.X++; MapNode n2 = data->m_vmanip.getNodeNoEx(blockpos_nodes + p2); const ContentFeatures *f2 = &nodedef->get(n2); @@ -1468,7 +1468,7 @@ void MapblockMeshGenerator::drawNode() default: break; } - origin = intToFloat(p, BS); + origin = posToFloat(p, BS); if (data->m_smooth_lighting) getSmoothLightFrame(); else diff --git a/src/client/game.cpp b/src/client/game.cpp index 124600e6d4..bedf816b46 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -507,7 +507,7 @@ class GameGlobalShaderConstantSetter : public IShaderConstantSetter m_animation_timer_pixel.set(&animation_timer_f, services); float eye_position_array[3]; - v3f epos = m_client->getEnv().getLocalPlayer()->getEyePosition(); + v3f epos = oposToV3f(m_client->getEnv().getLocalPlayer()->getEyePosition()); epos.getAs3Values(eye_position_array); m_eye_position_pixel.set(eye_position_array, services); m_eye_position_vertex.set(eye_position_array, services); @@ -520,7 +520,7 @@ class GameGlobalShaderConstantSetter : public IShaderConstantSetter } float camera_offset_array[3]; - v3f offset = intToFloat(m_client->getCamera()->getOffset(), BS); + v3f offset = posToFloat(m_client->getCamera()->getOffset(), BS); offset.getAs3Values(camera_offset_array); m_camera_offset_pixel.set(camera_offset_array, services); m_camera_offset_vertex.set(camera_offset_array, services); @@ -729,13 +729,13 @@ class Game { * NULL if not found */ PointedThing updatePointedThing( - const core::line3d &shootline, bool liquids_pointable, + const core::line3d &shootline, bool liquids_pointable, bool look_for_object, const v3pos_t &camera_offset); void handlePointingAtNothing(const ItemStack &playerItem); void handlePointingAtNode(const PointedThing &pointed, const ItemStack &selected_item, const ItemStack &hand_item, f32 dtime); void handlePointingAtObject(const PointedThing &pointed, const ItemStack &playeritem, - const v3f &player_position, bool show_debug); + const v3opos_t &player_position, bool show_debug); void handleDigging(const PointedThing &pointed, const v3pos_t &nodepos, const ItemStack &selected_item, const ItemStack &hand_item, f32 dtime); void updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime, @@ -2732,7 +2732,7 @@ void Game::handleClientEvent_HudAdd(ClientEvent *event, CameraOrientation *cam) e->dir = event->hudadd->dir; e->align = event->hudadd->align; e->offset = event->hudadd->offset; - e->world_pos = event->hudadd->world_pos; + e->world_pos = oposToV3f(event->hudadd->world_pos); e->size = event->hudadd->size; e->z_index = event->hudadd->z_index; e->text2 = event->hudadd->text2; @@ -2995,7 +2995,7 @@ void Game::updateCamera(u32 busy_time, f32 dtime) camera->update(player, dtime, busy_time / 1000.0f, tool_reload_ratio); camera->step(dtime); - v3f camera_position = camera->getPosition(); + auto camera_position = camera->getPosition(); v3f camera_direction = camera->getDirection(); f32 camera_fov = camera->getFovMax(); v3pos_t camera_offset = camera->getOffset(); @@ -3021,7 +3021,7 @@ void Game::updateSound(f32 dtime) { // Update sound listener v3pos_t camera_offset = camera->getOffset(); - sound->updateListener(camera->getCameraNode()->getPosition() + intToFloat(camera_offset, BS), + sound->updateListener(camera->getCameraNode()->getPosition() + posToFloat(camera_offset, BS), v3f(0, 0, 0), // velocity camera->getDirection(), camera->getCameraNode()->getUpVector()); @@ -3072,7 +3072,7 @@ void Game::processPlayerInteraction(f32 dtime, bool show_hud, bool show_debug) const ItemDefinition &selected_def = selected_item.getDefinition(itemdef_manager); f32 d = getToolRange(selected_def, hand_item.getDefinition(itemdef_manager)); - core::line3d shootline; + core::line3d shootline; switch (camera->getCameraMode()) { case CAMERA_MODE_FIRST: @@ -3089,7 +3089,7 @@ void Game::processPlayerInteraction(f32 dtime, bool show_hud, bool show_debug) d = 0; break; } - shootline.end = shootline.start + camera_direction * BS * d; + shootline.end = shootline.start + v3fToOpos(camera_direction * BS * d); #ifdef HAVE_TOUCHSCREENGUI @@ -3172,7 +3172,7 @@ void Game::processPlayerInteraction(f32 dtime, bool show_hud, bool show_debug) } else if (pointed.type == POINTEDTHING_NODE) { handlePointingAtNode(pointed, selected_item, hand_item, dtime); } else if (pointed.type == POINTEDTHING_OBJECT) { - v3f player_position = player->getPosition(); + auto player_position = player->getPosition(); handlePointingAtObject(pointed, tool_item, player_position, show_debug); } else if (isKeyDown(KeyType::DIG)) { // When button is held down in air, show continuous animation @@ -3204,7 +3204,7 @@ void Game::processPlayerInteraction(f32 dtime, bool show_hud, bool show_debug) PointedThing Game::updatePointedThing( - const core::line3d &shootline, + const core::line3d &shootline, bool liquids_pointable, bool look_for_object, const v3pos_t &camera_offset) @@ -3232,7 +3232,7 @@ PointedThing Game::updatePointedThing( aabb3f selection_box; if (show_entity_selectionbox && runData.selected_object->doShowSelectionBox() && runData.selected_object->getSelectionBox(&selection_box)) { - v3f pos = runData.selected_object->getPosition(); + auto pos = runData.selected_object->getPosition(); selectionboxes->push_back(aabb3f(selection_box)); hud->setSelectionPos(pos, camera_offset); } @@ -3251,7 +3251,7 @@ PointedThing Game::updatePointedThing( box.MaxEdge += v3f(d, d, d); selectionboxes->push_back(box); } - hud->setSelectionPos(intToFloat(result.node_undersurface, BS), + hud->setSelectionPos(posToOpos(result.node_undersurface, BS), camera_offset); hud->setSelectedFaceNormal(v3f( result.intersection_normal.X, @@ -3261,8 +3261,8 @@ PointedThing Game::updatePointedThing( // Update selection mesh light level and vertex colors if (!selectionboxes->empty()) { - v3f pf = hud->getSelectionPos(); - v3pos_t p = floatToInt(pf, BS); + v3opos_t pf = hud->getSelectionPos(); + v3pos_t p = oposToPos(pf, BS); // Get selection mesh light level MapNode n = map.getNode(p); @@ -3468,7 +3468,7 @@ bool Game::nodePlacement(const ItemDefinition &selected_def, } } else if (predicted_f.param_type_2 == CPT2_FACEDIR || predicted_f.param_type_2 == CPT2_COLORED_FACEDIR) { - v3pos_t dir = nodepos - floatToInt(client->getEnv().getLocalPlayer()->getPosition(), BS); + v3pos_t dir = nodepos - oposToPos(client->getEnv().getLocalPlayer()->getPosition(), BS); if (abs(dir.X) > abs(dir.Z)) { param2 = dir.X < 0 ? 3 : 1; @@ -3558,7 +3558,7 @@ bool Game::nodePlacement(const ItemDefinition &selected_def, } void Game::handlePointingAtObject(const PointedThing &pointed, - const ItemStack &tool_item, const v3f &player_position, bool show_debug) + const ItemStack &tool_item, const v3opos_t &player_position, bool show_debug) { std::wstring infotext = unescape_translate( utf8_to_wide(runData.selected_object->infoText())); @@ -3592,8 +3592,8 @@ void Game::handlePointingAtObject(const PointedThing &pointed, if (do_punch_damage) { // Report direct punch - v3f objpos = runData.selected_object->getPosition(); - v3f dir = (objpos - player_position).normalize(); + v3opos_t objpos = runData.selected_object->getPosition(); + v3f dir = (oposToV3f(objpos - player_position)).normalize(); bool disable_send = runData.selected_object->directReportPunch( dir, &tool_item, runData.time_from_last_punch); @@ -3997,7 +3997,7 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime, Update minimap pos and rotation */ if (mapper && m_game_ui->m_flags.show_hud) { - mapper->setPos(floatToInt(player->getPosition(), BS)); + mapper->setPos(oposToPos(player->getPosition(), BS)); mapper->setAngle(player->getYaw()); } diff --git a/src/client/gameui.cpp b/src/client/gameui.cpp index ecb8e0ec4a..a79760d91c 100644 --- a/src/client/gameui.cpp +++ b/src/client/gameui.cpp @@ -134,7 +134,7 @@ void GameUI::update(const RunStats &stats, Client *client, MapDrawControl *draw_ // Basic debug text also shows info that might give a gameplay advantage if (m_flags.show_basic_debug) { LocalPlayer *player = client->getEnv().getLocalPlayer(); - v3f player_position = player->getPosition(); + auto player_position = player->getPosition(); std::ostringstream os(std::ios_base::binary); os << std::setprecision(1) << std::fixed diff --git a/src/client/hud.cpp b/src/client/hud.cpp index 1163f10a70..fe44772455 100644 --- a/src/client/hud.cpp +++ b/src/client/hud.cpp @@ -316,10 +316,10 @@ bool Hud::hasElementOfType(HudElementType type) // Calculates screen position of waypoint. Returns true if waypoint is visible (in front of the player), else false. bool Hud::calculateScreenPos(const v3pos_t &camera_offset, HudElement *e, v2s32 *pos) { - v3f w_pos = e->world_pos * BS; + v3opos_t w_pos_o = v3fToOpos(e->world_pos) * BS; scene::ICameraSceneNode* camera = client->getSceneManager()->getActiveCamera(); - w_pos -= intToFloat(camera_offset, BS); + auto w_pos = oposToV3f(w_pos_o - intToFloat(camera_offset, BS)); core::matrix4 trans = camera->getProjectionMatrix(); trans *= camera->getViewMatrix(); f32 transformed_pos[4] = { w_pos.X, w_pos.Y, w_pos.Z, 1.0f }; @@ -411,7 +411,7 @@ void Hud::drawLuaElements(const v3pos_t &camera_offset) case HUD_ELEM_WAYPOINT: { if (!calculateScreenPos(camera_offset, e, &pos)) break; - v3f p_pos = player->getPosition() / BS; + v3opos_t p_pos = player->getPosition() / BS; pos += v2s32(e->offset.X, e->offset.Y); video::SColor color(255, (e->number >> 16) & 0xFF, (e->number >> 8) & 0xFF, @@ -429,7 +429,7 @@ void Hud::drawLuaElements(const v3pos_t &camera_offset) font->draw(text.c_str(), bounds + v2s32((e->align.X - 1.0) * bounds.getWidth() / 2, 0), color); if (draw_precision) { std::ostringstream os; - float distance = std::floor(precision * p_pos.getDistanceFrom(e->world_pos)) / precision; + float distance = std::floor(precision * p_pos.getDistanceFrom(v3fToOpos(e->world_pos))) / precision; os << distance << unit; text = unescape_translate(utf8_to_wide(os.str())); bounds.LowerRightCorner.X = bounds.UpperLeftCorner.X + font->getDimension(text.c_str()).Width; @@ -817,11 +817,11 @@ void Hud::drawCrosshair() } } -void Hud::setSelectionPos(const v3f &pos, const v3pos_t &camera_offset) +void Hud::setSelectionPos(const v3opos_t &pos, const v3pos_t &camera_offset) { m_camera_offset = camera_offset; m_selection_pos = pos; - m_selection_pos_with_offset = pos - intToFloat(camera_offset, BS); + m_selection_pos_with_offset = oposToV3f(pos - posToOpos(camera_offset, BS)); } void Hud::drawSelectionMesh() @@ -899,7 +899,7 @@ void Hud::drawBlockBounds() floorf((float) pos.Z / MAP_BLOCKSIZE) ); - v3f offset = intToFloat(client->getCamera()->getOffset(), BS); + auto offset = intToFloat(client->getCamera()->getOffset(), BS); s8 radius = m_block_bounds_mode == BLOCK_BOUNDS_NEAR ? 2 : 0; @@ -911,8 +911,8 @@ void Hud::drawBlockBounds() v3pos_t blockOffset(x, y, z); aabb3f box( - intToFloat((blockPos + blockOffset) * MAP_BLOCKSIZE, BS) - offset - halfNode, - intToFloat(((blockPos + blockOffset) * MAP_BLOCKSIZE) + (MAP_BLOCKSIZE - 1), BS) - offset + halfNode + oposToV3f(intToFloat((blockPos + blockOffset) * MAP_BLOCKSIZE, BS) - offset) - halfNode, + oposToV3f(intToFloat(((blockPos + blockOffset) * MAP_BLOCKSIZE) + (MAP_BLOCKSIZE - 1), BS) - offset) + halfNode ); driver->draw3DBox(box, video::SColor(255, 255, 0, 0)); @@ -958,7 +958,7 @@ void Hud::updateSelectionMesh(const v3pos_t &camera_offset) m_halo_boxes.clear(); for (const auto &selection_box : m_selection_boxes) { - halo_box.addInternalBox(selection_box); + halo_box.addInternalBox(aabb3f(selection_box.MinEdge, selection_box.MinEdge)); } m_halo_boxes.push_back(halo_box); diff --git a/src/client/hud.h b/src/client/hud.h index 7f4beb91c3..aeff1ffb15 100644 --- a/src/client/hud.h +++ b/src/client/hud.h @@ -71,9 +71,9 @@ class Hud std::vector *getSelectionBoxes() { return &m_selection_boxes; } - void setSelectionPos(const v3f &pos, const v3pos_t &camera_offset); + void setSelectionPos(const v3opos_t &pos, const v3pos_t &camera_offset); - v3f getSelectionPos() const { return m_selection_pos; } + v3opos_t getSelectionPos() const { return m_selection_pos; } void setSelectionMeshColor(const video::SColor &color) { @@ -124,7 +124,7 @@ class Hud std::vector m_selection_boxes; std::vector m_halo_boxes; - v3f m_selection_pos; + v3opos_t m_selection_pos; v3f m_selection_pos_with_offset; scene::IMesh *m_selection_mesh = nullptr; diff --git a/src/client/localplayer.cpp b/src/client/localplayer.cpp index 4bac49e886..bf0d6365e4 100644 --- a/src/client/localplayer.cpp +++ b/src/client/localplayer.cpp @@ -55,7 +55,7 @@ static aabb3f getNodeBoundingBox(const std::vector &nodeboxes) return b_max; } -bool LocalPlayer::updateSneakNode(Map *map, const v3f &position, +bool LocalPlayer::updateSneakNode(Map *map, const v3opos_t &position, const v3f &sneak_max) { static const v3pos_t dir9_center[9] = { @@ -81,7 +81,7 @@ bool LocalPlayer::updateSneakNode(Map *map, const v3f &position, position_y_mod = m_sneak_node_bb_top.MaxEdge.Y - position_y_mod; // Get position of current standing node - const v3pos_t current_node = floatToInt(position - v3f(0.0f, position_y_mod, 0.0f), BS); + const v3pos_t current_node = floatToInt(position - v3opos_t(0.0f, position_y_mod, 0.0f), BS); if (current_node != m_sneak_node) { new_sneak_node_exists = false; @@ -101,7 +101,7 @@ bool LocalPlayer::updateSneakNode(Map *map, const v3f &position, for (const auto &d : dir9_center) { const v3pos_t p = current_node + d; - const v3f pf = intToFloat(p, BS); + const auto pf = intToFloat(p, BS); const v2f diff(position.X - pf.X, position.Z - pf.Z); f32 distance_f = diff.getLength(); @@ -181,7 +181,7 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d, Map *map = &env->getMap(); const NodeDefManager *nodemgr = m_client->ndef(); - v3f position = getPosition(); + auto position = getPosition(); // Copy parent position if local player is attached if (getParent()) { @@ -198,7 +198,7 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d, bool free_move = player_settings.free_move && fly_allowed; if (noclip && free_move) { - position += m_speed * dtime; + position += v3fToOpos(m_speed * dtime); setPosition(position); touching_ground = false; @@ -224,7 +224,7 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d, // If in liquid, the threshold of coming out is at higher y if (in_liquid) { - pp = floatToInt(position + v3f(0.0f, BS * 0.1f, 0.0f), BS); + pp = floatToInt(position + v3opos_t(0.0f, BS * 0.1f, 0.0f), BS); node = map->getNode(pp, &is_valid_position); if (is_valid_position) { const ContentFeatures &cf = nodemgr->get(node.getContent()); @@ -236,7 +236,7 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d, } else { // If not in liquid, the threshold of going in is at lower y - pp = floatToInt(position + v3f(0.0f, BS * 0.5f, 0.0f), BS); + pp = floatToInt(position + v3opos_t(0.0f, BS * 0.5f, 0.0f), BS); node = map->getNode(pp, &is_valid_position); if (is_valid_position) { const ContentFeatures &cf = nodemgr->get(node.getContent()); @@ -251,7 +251,7 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d, /* Check if player is in liquid (the stable value) */ - pp = floatToInt(position + v3f(0.0f), BS); + pp = floatToInt(position + v3opos_t(0.0f), BS); node = map->getNode(pp, &is_valid_position); if (is_valid_position) { in_liquid_stable = nodemgr->get(node.getContent()).liquid_move_physics; @@ -263,8 +263,8 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d, Check if player is climbing */ - pp = floatToInt(position + v3f(0.0f, 0.5f * BS, 0.0f), BS); - v3pos_t pp2 = floatToInt(position + v3f(0.0f, -0.2f * BS, 0.0f), BS); + pp = floatToInt(position + v3opos_t(0.0f, 0.5f * BS, 0.0f), BS); + v3pos_t pp2 = floatToInt(position + v3opos_t(0.0f, -0.2f * BS, 0.0f), BS); node = map->getNode(pp, &is_valid_position); bool is_valid_position2; MapNode node2 = map->getNode(pp2, &is_valid_position2); @@ -293,7 +293,7 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d, (touching_ground ? m_cao->getStepHeight() : (0.2f * BS)); v3f accel_f; - const v3f initial_position = position; + const v3opos_t initial_position = position; const v3f initial_speed = m_speed; collisionMoveResult result = collisionMoveSimple(env, m_client, @@ -305,7 +305,7 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d, // Add new collisions to the vector if (collision_info && !free_move) { - v3f diff = intToFloat(m_standing_node, BS) - position; + auto diff = posToOpos(m_standing_node, BS) - position; f32 distance = diff.getLength(); // Force update each ClientEnvironment::step() bool is_first = collision_info->empty(); @@ -318,7 +318,7 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d, (could_sneak && m_sneak_node_exists)) continue; - diff = intToFloat(colinfo.node_p, BS) - position; + diff = posToOpos(colinfo.node_p, BS) - position; // Find nearest colliding node f32 len = diff.getLength(); @@ -353,10 +353,10 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d, If sneaking, keep on top of last walked node and don't fall off */ if (could_sneak && m_sneak_node_exists) { - const v3f sn_f = intToFloat(m_sneak_node, BS); - const v3f bmin = sn_f + m_sneak_node_bb_top.MinEdge; - const v3f bmax = sn_f + m_sneak_node_bb_top.MaxEdge; - const v3f old_pos = position; + const v3opos_t sn_f = posToOpos(m_sneak_node, BS); + const v3opos_t bmin = sn_f + v3fToOpos(m_sneak_node_bb_top.MinEdge); + const v3opos_t bmax = sn_f + v3fToOpos(m_sneak_node_bb_top.MaxEdge); + const v3opos_t old_pos = position; const v3f old_speed = m_speed; f32 y_diff = bmax.Y - position.Y; m_standing_node = m_sneak_node; @@ -679,17 +679,17 @@ v3pos_t LocalPlayer::getFootstepNodePos() // BS * 0.05 below the player's feet ensures a 1/16th height // nodebox is detected instead of the node below it. if (touching_ground) - return floatToInt(getPosition() - v3f(0.0f, BS * 0.05f, 0.0f), BS); + return floatToInt(getPosition() - v3opos_t(0.0f, BS * 0.05f, 0.0f), BS); // A larger distance below is necessary for a footstep sound // when landing after a jump or fall. BS * 0.5 ensures water // sounds when swimming in 1 node deep water. - return floatToInt(getPosition() - v3f(0.0f, BS * 0.5f, 0.0f), BS); + return floatToInt(getPosition() - v3opos_t(0.0f, BS * 0.5f, 0.0f), BS); } v3pos_t LocalPlayer::getLightPosition() const { - return floatToInt(m_position + v3f(0.0f, BS * 1.5f, 0.0f), BS); + return floatToInt(m_position + v3opos_t(0.0f, BS * 1.5f, 0.0f), BS); } v3f LocalPlayer::getEyeOffset() const @@ -758,7 +758,7 @@ void LocalPlayer::old_move(f32 dtime, Environment *env, f32 pos_max_d, Map *map = &env->getMap(); const NodeDefManager *nodemgr = m_client->ndef(); - v3f position = getPosition(); + auto position = getPosition(); // Copy parent position if local player is attached if (getParent()) { @@ -775,7 +775,7 @@ void LocalPlayer::old_move(f32 dtime, Environment *env, f32 pos_max_d, bool noclip = m_client->checkLocalPrivilege("noclip") && player_settings.noclip; bool free_move = noclip && fly_allowed && player_settings.free_move; if (free_move) { - position += m_speed * dtime; + position += v3fToOpos(m_speed * dtime); setPosition(position); touching_ground = false; @@ -799,7 +799,7 @@ void LocalPlayer::old_move(f32 dtime, Environment *env, f32 pos_max_d, */ if (in_liquid) { // If in liquid, the threshold of coming out is at higher y - pp = floatToInt(position + v3f(0.0f, BS * 0.1f, 0.0f), BS); + pp = floatToInt(position + v3opos_t(0.0f, BS * 0.1f, 0.0f), BS); node = map->getNode(pp, &is_valid_position); if (is_valid_position) { const ContentFeatures &cf = nodemgr->get(node.getContent()); @@ -810,7 +810,7 @@ void LocalPlayer::old_move(f32 dtime, Environment *env, f32 pos_max_d, } } else { // If not in liquid, the threshold of going in is at lower y - pp = floatToInt(position + v3f(0.0f, BS * 0.5f, 0.0f), BS); + pp = floatToInt(position + v3opos_t(0.0f, BS * 0.5f, 0.0f), BS); node = map->getNode(pp, &is_valid_position); if (is_valid_position) { const ContentFeatures &cf = nodemgr->get(node.getContent()); @@ -824,7 +824,7 @@ void LocalPlayer::old_move(f32 dtime, Environment *env, f32 pos_max_d, /* Check if player is in liquid (the stable value) */ - pp = floatToInt(position + v3f(0.0f), BS); + pp = floatToInt(position + v3opos_t(0.0f), BS); node = map->getNode(pp, &is_valid_position); if (is_valid_position) in_liquid_stable = nodemgr->get(node.getContent()).liquid_move_physics; @@ -834,8 +834,8 @@ void LocalPlayer::old_move(f32 dtime, Environment *env, f32 pos_max_d, /* Check if player is climbing */ - pp = floatToInt(position + v3f(0.0f, 0.5f * BS, 0.0f), BS); - v3pos_t pp2 = floatToInt(position + v3f(0.0f, -0.2f * BS, 0.0f), BS); + pp = floatToInt(position + v3opos_t(0.0f, 0.5f * BS, 0.0f), BS); + v3pos_t pp2 = floatToInt(position + v3opos_t(0.0f, -0.2f * BS, 0.0f), BS); node = map->getNode(pp, &is_valid_position); bool is_valid_position2; MapNode node2 = map->getNode(pp2, &is_valid_position2); @@ -866,7 +866,7 @@ void LocalPlayer::old_move(f32 dtime, Environment *env, f32 pos_max_d, !(fly_allowed && player_settings.free_move) && !in_liquid && physics_override_sneak) { f32 maxd = 0.5f * BS + sneak_max; - v3f lwn_f = intToFloat(m_sneak_node, BS); + auto lwn_f = intToFloat(m_sneak_node, BS); position.X = rangelim(position.X, lwn_f.X - maxd, lwn_f.X + maxd); position.Z = rangelim(position.Z, lwn_f.Z - maxd, lwn_f.Z + maxd); @@ -889,7 +889,7 @@ void LocalPlayer::old_move(f32 dtime, Environment *env, f32 pos_max_d, float player_stepheight = touching_ground ? (BS * 0.6f) : (BS * 0.2f); v3f accel_f; - const v3f initial_position = position; + const v3opos_t initial_position = position; const v3f initial_speed = m_speed; collisionMoveResult result = collisionMoveSimple(env, m_client, @@ -898,7 +898,7 @@ void LocalPlayer::old_move(f32 dtime, Environment *env, f32 pos_max_d, // Positition was slightly changed; update standing node pos if (touching_ground) - m_standing_node = floatToInt(m_position - v3f(0.0f, 0.1f * BS, 0.0f), BS); + m_standing_node = floatToInt(m_position - v3opos_t(0.0f, 0.1f * BS, 0.0f), BS); else m_standing_node = floatToInt(m_position, BS); @@ -921,7 +921,7 @@ void LocalPlayer::old_move(f32 dtime, Environment *env, f32 pos_max_d, f32 position_y_mod = 0.05f * BS; if (m_sneak_node_bb_ymax > 0.0f) position_y_mod = m_sneak_node_bb_ymax - position_y_mod; - v3pos_t current_node = floatToInt(position - v3f(0.0f, position_y_mod, 0.0f), BS); + v3pos_t current_node = floatToInt(position - v3opos_t(0.0f, position_y_mod, 0.0f), BS); if (m_sneak_node_exists && nodemgr->get(map->getNode(m_old_node_below)).name == "air" && m_old_node_below_type != "air") { @@ -937,7 +937,7 @@ void LocalPlayer::old_move(f32 dtime, Environment *env, f32 pos_max_d, if (m_need_to_get_new_sneak_node && physics_override_sneak) { m_sneak_node_bb_ymax = 0.0f; - v3pos_t pos_i_bottom = floatToInt(position - v3f(0.0f, position_y_mod, 0.0f), BS); + v3pos_t pos_i_bottom = floatToInt(position - v3opos_t(0.0f, position_y_mod, 0.0f), BS); v2f player_p2df(position.X, position.Z); f32 min_distance_f = 100000.0f * BS; // If already seeking from some node, compare to it. @@ -945,7 +945,7 @@ void LocalPlayer::old_move(f32 dtime, Environment *env, f32 pos_max_d, for (s16 x= -1; x <= 1; x++) for (s16 z= -1; z <= 1; z++) { v3pos_t p = pos_i_bottom + v3pos_t(x, 0, z); - v3f pf = intToFloat(p, BS); + auto pf = intToFloat(p, BS); v2f node_p2df(pf.X, pf.Z); f32 distance_f = player_p2df.getDistanceFrom(node_p2df); f32 max_axis_distance_f = MYMAX( @@ -1036,7 +1036,7 @@ void LocalPlayer::old_move(f32 dtime, Environment *env, f32 pos_max_d, /* Update the node last under the player */ - m_old_node_below = floatToInt(position - v3f(0.0f, BS / 2.0f, 0.0f), BS); + m_old_node_below = floatToInt(position - v3opos_t(0.0f, BS / 2.0f, 0.0f), BS); m_old_node_below_type = nodemgr->get(map->getNode(m_old_node_below)).name; /* @@ -1086,7 +1086,7 @@ float LocalPlayer::getSlipFactor(Environment *env, const v3f &speedH) } void LocalPlayer::handleAutojump(f32 dtime, Environment *env, - const collisionMoveResult &result, const v3f &initial_position, + const collisionMoveResult &result, const v3opos_t &initial_position, const v3f &initial_speed, f32 pos_max_d) { PlayerSettings &player_settings = getPlayerSettings(); @@ -1117,8 +1117,8 @@ void LocalPlayer::handleAutojump(f32 dtime, Environment *env, return; // check for nodes above - v3f headpos_min = m_position + m_collisionbox.MinEdge * 0.99f; - v3f headpos_max = m_position + m_collisionbox.MaxEdge * 0.99f; + v3opos_t headpos_min = m_position + v3fToOpos(m_collisionbox.MinEdge * 0.99f); + v3opos_t headpos_max = m_position + v3fToOpos(m_collisionbox.MaxEdge * 0.99f); headpos_min.Y = headpos_max.Y; // top face of collision box v3pos_t ceilpos_min = floatToInt(headpos_min, BS) + v3pos_t(0, 1, 0); v3pos_t ceilpos_max = floatToInt(headpos_max, BS) + v3pos_t(0, 1, 0); @@ -1139,7 +1139,7 @@ void LocalPlayer::handleAutojump(f32 dtime, Environment *env, } float jump_height = 1.1f; // TODO: better than a magic number - v3f jump_pos = initial_position + v3f(0.0f, jump_height * BS, 0.0f); + v3opos_t jump_pos = initial_position + v3opos_t(0.0f, jump_height * BS, 0.0f); v3f jump_speed = initial_speed; // try at peak of jump, zero step height @@ -1148,9 +1148,9 @@ void LocalPlayer::handleAutojump(f32 dtime, Environment *env, // see if we can get a little bit farther horizontally if we had // jumped - v3f run_delta = m_position - initial_position; + v3opos_t run_delta = m_position - initial_position; run_delta.Y = 0.0f; - v3f jump_delta = jump_pos - initial_position; + v3opos_t jump_delta = jump_pos - initial_position; jump_delta.Y = 0.0f; if (jump_delta.getLengthSQ() > run_delta.getLengthSQ() * 1.01f) { m_autojump = true; diff --git a/src/client/localplayer.h b/src/client/localplayer.h index c862aceece..654d896ff2 100644 --- a/src/client/localplayer.h +++ b/src/client/localplayer.h @@ -82,7 +82,7 @@ class LocalPlayer : public Player v3pos_t getFootstepNodePos(); // Used to check if anything changed and prevent sending packets if not - v3f last_position; + v3opos_t last_position; v3f last_speed; float last_pitch = 0.0f; float last_yaw = 0.0f; @@ -128,17 +128,17 @@ class LocalPlayer : public Player void setPitch(f32 pitch) { m_pitch = pitch; } f32 getPitch() const { return m_pitch; } - inline void setPosition(const v3f &position) + inline void setPosition(const v3opos_t &position) { m_position = position; m_sneak_node_exists = false; } - v3f getPosition() const { return m_position; } + v3opos_t getPosition() const { return m_position; } // Non-transformed eye offset getters // For accurate positions, use the Camera functions - v3f getEyePosition() const { return m_position + getEyeOffset(); } + v3opos_t getEyePosition() const { return m_position + v3fToOpos(getEyeOffset()); } v3f getEyeOffset() const; void setEyeHeight(float eye_height) { m_eye_height = eye_height; } @@ -161,14 +161,14 @@ class LocalPlayer : public Player private: void accelerate(const v3f &target_speed, const f32 max_increase_H, const f32 max_increase_V, const bool use_pitch); - bool updateSneakNode(Map *map, const v3f &position, const v3f &sneak_max); + bool updateSneakNode(Map *map, const v3opos_t &position, const v3f &sneak_max); float getSlipFactor(Environment *env, const v3f &speedH); void handleAutojump(f32 dtime, Environment *env, const collisionMoveResult &result, - const v3f &position_before_move, const v3f &speed_before_move, + const v3opos_t &position_before_move, const v3f &speed_before_move, f32 pos_max_d); - v3f m_position; + v3opos_t m_position; v3pos_t m_standing_node; v3pos_t m_sneak_node = v3pos_t(32767, 32767, 32767); diff --git a/src/client/minimap.cpp b/src/client/minimap.cpp index bde92e3401..6b663dcba3 100644 --- a/src/client/minimap.cpp +++ b/src/client/minimap.cpp @@ -704,13 +704,13 @@ void Minimap::updateActiveMarkers() data->minimap_mask_round : data->minimap_mask_square; m_active_markers.clear(); - v3f cam_offset = intToFloat(client->getCamera()->getOffset(), BS); + auto cam_offset = intToFloat(client->getCamera()->getOffset(), BS); v3pos_t pos_offset = data->pos - v3pos_t(data->mode.map_size / 2, data->mode.scan_height / 2, data->mode.map_size / 2); for (MinimapMarker *marker : m_markers) { - v3pos_t pos = floatToInt(marker->parent_node->getAbsolutePosition() + + v3pos_t pos = floatToInt(v3fToOpos(marker->parent_node->getAbsolutePosition()) + cam_offset, BS) - pos_offset; if (pos.X < 0 || pos.X > data->mode.map_size || pos.Y < 0 || pos.Y > data->mode.scan_height || diff --git a/src/client/particles.cpp b/src/client/particles.cpp index 31a9cc83c3..4367d52a19 100644 --- a/src/client/particles.cpp +++ b/src/client/particles.cpp @@ -136,7 +136,7 @@ void Particle::step(float dtime) m_time += dtime; if (m_collisiondetection) { aabb3f box = m_collisionbox; - v3f p_pos = m_pos * BS; + v3opos_t p_pos = m_pos * BS; v3f p_velocity = m_velocity * BS; collisionMoveResult r = collisionMoveSimple(m_env, m_gamedef, BS * 0.5f, box, 0.0f, dtime, &p_pos, &p_velocity, m_acceleration * BS, nullptr, @@ -150,7 +150,7 @@ void Particle::step(float dtime) } } else { m_velocity += m_acceleration * dtime; - m_pos += m_velocity * dtime; + m_pos += v3fToOpos(m_velocity * dtime); } if (m_animation.type != TAT_NONE) { m_animation_time += dtime; @@ -230,7 +230,7 @@ void Particle::updateVertices() v3pos_t camera_offset = m_env->getCameraOffset(); for (video::S3DVertex &vertex : m_vertices) { if (m_vertical) { - v3f ppos = m_player->getPosition()/BS; + v3opos_t ppos = m_player->getPosition()/BS; vertex.Pos.rotateXZBy(std::atan2(ppos.Z - m_pos.Z, ppos.X - m_pos.X) / core::DEGTORAD + 90); } else { @@ -238,7 +238,7 @@ void Particle::updateVertices() vertex.Pos.rotateXZBy(m_player->getYaw()); } m_box.addInternalPoint(vertex.Pos); - vertex.Pos += m_pos*BS - intToFloat(camera_offset, BS); + vertex.Pos += oposToV3f(m_pos*BS - posToOpos(camera_offset, BS)); } } @@ -272,7 +272,7 @@ ParticleSpawner::ParticleSpawner( void ParticleSpawner::spawnParticle(ClientEnvironment *env, float radius, const core::matrix4 *attached_absolute_pos_rot_matrix) { - v3f ppos = m_player->getPosition() / BS; + v3opos_t ppos = m_player->getPosition() / BS; v3f pos = random_v3f(p.minpos, p.maxpos); // Need to apply this first or the following check @@ -287,12 +287,12 @@ void ParticleSpawner::spawnParticle(ClientEnvironment *env, float radius, pos.Z += camera_offset.Z; } - if (pos.getDistanceFrom(ppos) > radius) + if (v3fToOpos(pos).getDistanceFrom(ppos) > radius) return; // Parameters for the single particle we're about to spawn ParticleParameters pp; - pp.pos = pos; + pp.pos = v3fToOpos(pos); pp.vel = random_v3f(p.minvel, p.maxvel); pp.acc = random_v3f(p.minacc, p.maxacc); @@ -597,10 +597,10 @@ void ParticleManager::addNodeParticle(IGameDef *gamedef, -player->movement_gravity * player->physics_override_gravity / BS, 0.0f ); - p.pos = v3f( - (f32)pos.X + (rand() % 100) / 200.0f - 0.25f, - (f32)pos.Y + (rand() % 100) / 200.0f - 0.25f, - (f32)pos.Z + (rand() % 100) / 200.0f - 0.25f + p.pos = v3opos_t( + (opos_t)pos.X + (rand() % 100) / 200.0f - 0.25f, + (opos_t)pos.Y + (rand() % 100) / 200.0f - 0.25f, + (opos_t)pos.Z + (rand() % 100) / 200.0f - 0.25f ); Particle *toadd = new Particle( diff --git a/src/client/particles.h b/src/client/particles.h index 2f027e118f..4b0b67096e 100644 --- a/src/client/particles.h +++ b/src/client/particles.h @@ -84,7 +84,7 @@ class Particle : public scene::ISceneNode video::SMaterial m_material; v2f m_texpos; v2f m_texsize; - v3f m_pos; + v3opos_t m_pos; v3f m_velocity; v3f m_acceleration; LocalPlayer *m_player; diff --git a/src/client/shadows/dynamicshadows.cpp b/src/client/shadows/dynamicshadows.cpp index 6b4e6a5463..eed3575a2a 100644 --- a/src/client/shadows/dynamicshadows.cpp +++ b/src/client/shadows/dynamicshadows.cpp @@ -42,17 +42,17 @@ void DirectionalLight::createSplitMatrices(const Camera *cam) float sfFar = adjustDist(future_frustum.zFar, cam->getFovY()); // adjusted camera positions - v3f camPos2 = cam->getPosition(); + auto camPos2 = cam->getPosition(); v3f camPos = v3f(camPos2.X - cam->getOffset().X * BS, camPos2.Y - cam->getOffset().Y * BS, camPos2.Z - cam->getOffset().Z * BS); camPos += look * sfNear; - camPos2 += look * sfNear; + camPos2 += v3fToOpos(look * sfNear); // center point of light frustum float end = sfNear + sfFar; newCenter = camPos + look * (sfNear + 0.05f * end); - v3f world_center = camPos2 + look * (sfNear + 0.05f * end); + v3f world_center = oposToV3f(camPos2) + look * (sfNear + 0.05f * end); // Create a vector to the frustum far corner const v3f &viewUp = cam->getCameraNode()->getUpVector(); @@ -113,7 +113,7 @@ void DirectionalLight::update_frustum(const Camera *cam, Client *client, bool fo v3pos_t cam_offset = cam->getOffset(); if (cam_offset != shadow_frustum.camera_offset) { v3f rotated_offset; - shadow_frustum.ViewMat.rotateVect(rotated_offset, intToFloat(cam_offset - shadow_frustum.camera_offset, BS)); + shadow_frustum.ViewMat.rotateVect(rotated_offset, posToFloat(cam_offset - shadow_frustum.camera_offset, BS)); shadow_frustum.ViewMat.setTranslation(shadow_frustum.ViewMat.getTranslation() + rotated_offset); shadow_frustum.camera_offset = cam_offset; } diff --git a/src/clientiface.cpp b/src/clientiface.cpp index 022e70ba9d..7e20ff4ac5 100644 --- a/src/clientiface.cpp +++ b/src/clientiface.cpp @@ -118,7 +118,7 @@ void RemoteClient::GetNextBlocks ( return; } - v3f playerpos = sao->getBasePosition(); + auto playerpos = sao->getBasePosition(); // if the player is attached, get the velocity from the attached object LuaEntitySAO *lsao = getAttachedObject(sao, env); const v3f &playerspeed = lsao? lsao->getVelocity() : player->getSpeed(); @@ -126,14 +126,14 @@ void RemoteClient::GetNextBlocks ( if (playerspeed.getLength() > 1.0f * BS) playerspeeddir = playerspeed / playerspeed.getLength(); // Predict to next block - v3f playerpos_predicted = playerpos + playerspeeddir * (MAP_BLOCKSIZE * BS); + v3opos_t playerpos_predicted = playerpos + v3fToOpos(playerspeeddir) * (MAP_BLOCKSIZE * BS); v3pos_t center_nodepos = floatToInt(playerpos_predicted, BS); v3bpos_t center = getNodeBlockPos(center_nodepos); // Camera position and direction - v3f camera_pos = sao->getEyePosition(); + auto camera_pos = sao->getEyePosition(); v3f camera_dir = v3f(0,0,1); camera_dir.rotateYZBy(sao->getLookPitch()); camera_dir.rotateXZBy(sao->getRotation().Y); diff --git a/src/collision.cpp b/src/collision.cpp index aed4301a50..efc041be37 100644 --- a/src/collision.cpp +++ b/src/collision.cpp @@ -19,6 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "collision.h" #include +#include "irr_v3d.h" #include "mapblock.h" #include "map.h" #include "nodedef.h" @@ -39,7 +40,7 @@ with this program; if not, write to the Free Software Foundation, Inc., struct NearbyCollisionInfo { // node NearbyCollisionInfo(bool is_ul, int bouncy, const v3pos_t &pos, - const aabb3f &box) : + const aabb3o &box) : is_unloaded(is_ul), obj(nullptr), bouncy(bouncy), @@ -49,7 +50,7 @@ struct NearbyCollisionInfo { // object NearbyCollisionInfo(ActiveObject *obj, int bouncy, - const aabb3f &box) : + const aabb3o &box) : is_unloaded(false), obj(obj), bouncy(bouncy), @@ -63,7 +64,7 @@ struct NearbyCollisionInfo { ActiveObject *obj; int bouncy; v3pos_t position; - aabb3f box; + aabb3o box; }; // Helper functions: @@ -83,12 +84,23 @@ static inline v3f truncate(const v3f& vec, const f32 factor) ); } +#if USE_POS32 +static inline v3opos_t truncate(const v3opos_t& vec, const f32 factor) +{ + return v3opos_t( + truncate(vec.X, factor), + truncate(vec.Y, factor), + truncate(vec.Z, factor) + ); +} +#endif + // Helper function: // Checks for collision of a moving aabbox with a static aabbox // Returns -1 if no collision, 0 if X collision, 1 if Y collision, 2 if Z collision // The time after which the collision occurs is stored in dtime. CollisionAxis axisAlignedCollision( - const aabb3f &staticbox, const aabb3f &movingbox, + const aabb3o &staticbox, const aabb3o &movingbox, const v3f &speed, f32 *dtime) { //TimeTaker tt("axisAlignedCollision"); @@ -114,7 +126,7 @@ CollisionAxis axisAlignedCollision( time = std::max(*dtime, 0.0f); if (*dtime <= dtime_max) { - inner_margin = std::max(-0.5f * (staticbox.MaxEdge.Y - staticbox.MinEdge.Y), -2.0f); + inner_margin = std::max(-0.5f * (staticbox.MaxEdge.Y - staticbox.MinEdge.Y), -2.0f); if ((speed.Y > 0 && staticbox.MinEdge.Y - movingbox.MaxEdge.Y > inner_margin) || (speed.Y < 0 && movingbox.MinEdge.Y - staticbox.MaxEdge.Y > inner_margin)) { @@ -142,7 +154,7 @@ CollisionAxis axisAlignedCollision( time = std::max(*dtime, 0.0f); if (*dtime <= dtime_max) { - inner_margin = std::max(-0.5f * (staticbox.MaxEdge.X - staticbox.MinEdge.X), -2.0f); + inner_margin = std::max(-0.5f * (staticbox.MaxEdge.X - staticbox.MinEdge.X), -2.0f); if ((speed.X > 0 && staticbox.MinEdge.X - movingbox.MaxEdge.X > inner_margin) || (speed.X < 0 && movingbox.MinEdge.X - staticbox.MaxEdge.X > inner_margin)) { @@ -169,7 +181,7 @@ CollisionAxis axisAlignedCollision( time = std::max(*dtime, 0.0f); if (*dtime <= dtime_max) { - inner_margin = std::max(-0.5f * (staticbox.MaxEdge.Z - staticbox.MinEdge.Z), -2.0f); + inner_margin = std::max(-0.5f * (staticbox.MaxEdge.Z - staticbox.MinEdge.Z), -2.0f); if ((speed.Z > 0 && staticbox.MinEdge.Z - movingbox.MaxEdge.Z > inner_margin) || (speed.Z < 0 && movingbox.MinEdge.Z - staticbox.MaxEdge.Z > inner_margin)) { @@ -193,7 +205,7 @@ CollisionAxis axisAlignedCollision( // Checks if moving the movingbox up by the given distance would hit a ceiling. bool wouldCollideWithCeiling( const std::vector &cinfo, - const aabb3f &movingbox, + const aabb3o &movingbox, f32 y_increase, f32 d) { //TimeTaker tt("wouldCollideWithCeiling"); @@ -201,7 +213,7 @@ bool wouldCollideWithCeiling( assert(y_increase >= 0); // pre-condition for (const auto &it : cinfo) { - const aabb3f &staticbox = it.box; + const aabb3o &staticbox = it.box; if ((movingbox.MaxEdge.Y - d <= staticbox.MinEdge.Y) && (movingbox.MaxEdge.Y + y_increase > staticbox.MinEdge.Y) && (movingbox.MinEdge.X < staticbox.MaxEdge.X) && @@ -225,7 +237,7 @@ static inline void getNeighborConnectingFace(const v3pos_t &p, collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef, f32 pos_max_d, const aabb3f &box_0, f32 stepheight, f32 dtime, - v3f *pos_f, v3f *speed_f, + v3opos_t *pos_f, v3f *speed_f, v3f accel_f, ActiveObject *self, bool collideWithObjects) { @@ -270,19 +282,19 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef, //TimeTaker tt2("collisionMoveSimple collect boxes"); ScopeProfiler sp2(g_profiler, "collisionMoveSimple(): collect boxes", SPT_AVG); - v3f newpos_f = *pos_f + *speed_f * dtime; - v3f minpos_f( + v3opos_t newpos_f = *pos_f + v3fToOpos(*speed_f) * dtime; + v3opos_t minpos_f( MYMIN(pos_f->X, newpos_f.X), MYMIN(pos_f->Y, newpos_f.Y) + 0.01f * BS, // bias rounding, player often at +/-n.5 MYMIN(pos_f->Z, newpos_f.Z) ); - v3f maxpos_f( + v3opos_t maxpos_f( MYMAX(pos_f->X, newpos_f.X), MYMAX(pos_f->Y, newpos_f.Y), MYMAX(pos_f->Z, newpos_f.Z) ); - v3pos_t min = floatToInt(minpos_f + box_0.MinEdge, BS) - v3pos_t(1, 1, 1); - v3pos_t max = floatToInt(maxpos_f + box_0.MaxEdge, BS) + v3pos_t(1, 1, 1); + v3pos_t min = floatToInt(minpos_f + v3fToOpos(box_0.MinEdge), BS) - v3pos_t(1, 1, 1); + v3pos_t max = floatToInt(maxpos_f + v3fToOpos(box_0.MaxEdge), BS) + v3pos_t(1, 1, 1); bool any_position_valid = false; @@ -337,8 +349,9 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef, n.getCollisionBoxes(gamedef->ndef(), &nodeboxes, neighbors); // Calculate float position only once - v3f posf = intToFloat(p, BS); - for (auto box : nodeboxes) { + auto posf = posToOpos(p, BS); + for (auto boxf : nodeboxes) { + aabb3o box(v3fToOpos(boxf.MinEdge), v3fToOpos(boxf.MaxEdge)); box.MinEdge += posf; box.MaxEdge += posf; cinfo.emplace_back(false, n_bouncy_value, p, box); @@ -346,7 +359,7 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef, } else { // Collide with unloaded nodes (position invalid) and loaded // CONTENT_IGNORE nodes (position valid) - aabb3f box = getNodeBox(p, BS); + aabb3o box = getNodeBox(p, (opos_t)BS); cinfo.emplace_back(true, 0, p, box); } } @@ -414,7 +427,7 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef, ActiveObject *object = *iter; if (object && object->collideWithObjects()) { - aabb3f object_collisionbox; + aabb3o object_collisionbox; if (object->getCollisionBox(&object_collisionbox)) cinfo.emplace_back(object, 0, object_collisionbox); } @@ -423,8 +436,9 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef, if (self && c_env) { LocalPlayer *lplayer = c_env->getLocalPlayer(); if (lplayer->getParent() == nullptr) { - aabb3f lplayer_collisionbox = lplayer->getCollisionbox(); - v3f lplayer_pos = lplayer->getPosition(); + aabb3f lplayer_collisionbox_f = lplayer->getCollisionbox(); + aabb3o lplayer_collisionbox(v3fToOpos(lplayer_collisionbox_f.MinEdge), v3fToOpos(lplayer_collisionbox_f.MaxEdge)) ; + auto lplayer_pos = lplayer->getPosition(); lplayer_collisionbox.MinEdge += lplayer_pos; lplayer_collisionbox.MaxEdge += lplayer_pos; ActiveObject *obj = (ActiveObject*) lplayer->getCAO(); @@ -450,7 +464,7 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef, break; } - aabb3f movingbox = box_0; + aabb3o movingbox(v3fToOpos(box_0.MinEdge), v3fToOpos(box_0.MaxEdge)); movingbox.MinEdge += *pos_f; movingbox.MaxEdge += *pos_f; @@ -482,15 +496,15 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef, if (nearest_collided == COLLISION_AXIS_NONE) { // No collision with any collision box. - *pos_f += truncate(*speed_f * dtime, 100.0f); + *pos_f += v3fToOpos(truncate(*speed_f * dtime, 100.0f)); dtime = 0; // Set to 0 to avoid "infinite" loop due to small FP numbers } else { // Otherwise, a collision occurred. NearbyCollisionInfo &nearest_info = cinfo[nearest_boxindex]; - const aabb3f& cbox = nearest_info.box; + const aabb3o& cbox = nearest_info.box; //movingbox except moved to the horizontal position it would be after step up - aabb3f stepbox = movingbox; + aabb3o stepbox = movingbox; stepbox.MinEdge.X += speed_f->X * dtime; stepbox.MinEdge.Z += speed_f->Z * dtime; stepbox.MaxEdge.X += speed_f->X * dtime; @@ -518,7 +532,7 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef, pos_f->Z += speed_f->Z * nearest_dtime; } } else { - *pos_f += truncate(*speed_f * nearest_dtime, 100.0f); + *pos_f += v3fToOpos(truncate(*speed_f * nearest_dtime, 100.0f)); dtime -= nearest_dtime; } @@ -576,11 +590,11 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef, /* Final touches: Check if standing on ground, step up stairs. */ - aabb3f box = box_0; + aabb3o box(v3fToOpos(box_0.MinEdge), v3fToOpos(box_0.MaxEdge)); box.MinEdge += *pos_f; box.MaxEdge += *pos_f; for (const auto &box_info : cinfo) { - const aabb3f &cbox = box_info.box; + const aabb3o &cbox = box_info.box; /* See if the object is touching ground. @@ -595,7 +609,7 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef, cbox.MinEdge.Z + d < box.MaxEdge.Z) { if (box_info.is_step_up) { pos_f->Y += cbox.MaxEdge.Y - box.MinEdge.Y; - box = box_0; + box = {(v3fToOpos(box_0.MinEdge), v3fToOpos(box_0.MaxEdge))}; box.MinEdge += *pos_f; box.MaxEdge += *pos_f; } diff --git a/src/collision.h b/src/collision.h index 23106752e4..a09b2e9984 100644 --- a/src/collision.h +++ b/src/collision.h @@ -19,6 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #pragma once +#include "irr_v3d.h" #include "irrlichttypes_bloated.h" #include @@ -68,7 +69,7 @@ struct collisionMoveResult collisionMoveResult collisionMoveSimple(Environment *env,IGameDef *gamedef, f32 pos_max_d, const aabb3f &box_0, f32 stepheight, f32 dtime, - v3f *pos_f, v3f *speed_f, + v3opos_t *pos_f, v3f *speed_f, v3f accel_f, ActiveObject *self=NULL, bool collideWithObjects=true); @@ -77,12 +78,12 @@ collisionMoveResult collisionMoveSimple(Environment *env,IGameDef *gamedef, // Returns -1 if no collision, 0 if X collision, 1 if Y collision, 2 if Z collision // dtime receives time until first collision, invalid if -1 is returned CollisionAxis axisAlignedCollision( - const aabb3f &staticbox, const aabb3f &movingbox, + const aabb3o &staticbox, const aabb3o &movingbox, const v3f &speed, f32 *dtime); // Helper function: // Checks if moving the movingbox up by the given distance would hit a ceiling. bool wouldCollideWithCeiling( - const std::vector &staticboxes, - const aabb3f &movingbox, + const std::vector &staticboxes, + const aabb3o &movingbox, f32 y_increase, f32 d); diff --git a/src/constants.h b/src/constants.h index d2497feb13..6720f284a0 100644 --- a/src/constants.h +++ b/src/constants.h @@ -68,6 +68,7 @@ with this program; if not, write to the Free Software Foundation, Inc., // This is the maximum value the setting map_generation_limit can be #if USE_POS32 #define MAX_MAP_GENERATION_LIMIT (2147483008) +//#define MAX_MAP_GENERATION_LIMIT (31000) #else #define MAX_MAP_GENERATION_LIMIT (31000) #endif diff --git a/src/database/database-files.cpp b/src/database/database-files.cpp index d9d113b4e8..5113545fd3 100644 --- a/src/database/database-files.cpp +++ b/src/database/database-files.cpp @@ -59,7 +59,7 @@ void PlayerDatabaseFiles::deSerialize(RemotePlayer *p, std::istream &is, } try { - sao->setBasePosition(args.getV3F("position")); + sao->setBasePosition(v3fToOpos(args.getV3F("position"))); } catch (SettingNotFoundException &e) {} try { @@ -125,7 +125,7 @@ void PlayerDatabaseFiles::serialize(RemotePlayer *p, std::ostream &os) // This should not happen sanity_check(sao); args.setU16("hp", sao->getHP()); - args.setV3F("position", sao->getBasePosition()); + args.setV3F("position", oposToV3f(sao->getBasePosition())); //TODO setV3D args.setFloat("pitch", sao->getLookPitch()); args.setFloat("yaw", sao->getRotation().Y); args.setU16("breath", sao->getBreath()); diff --git a/src/database/database-leveldb.cpp b/src/database/database-leveldb.cpp index 4a86cd1d7b..e30f11330e 100644 --- a/src/database/database-leveldb.cpp +++ b/src/database/database-leveldb.cpp @@ -137,7 +137,7 @@ void PlayerDatabaseLevelDB::savePlayer(RemotePlayer *player) PlayerSAO *sao = player->getPlayerSAO(); sanity_check(sao); writeU16(os, sao->getHP()); - writeV3F32(os, sao->getBasePosition()); + writeV3F32(os, oposToV3f(sao->getBasePosition())); writeF32(os, sao->getLookPitch()); writeF32(os, sao->getRotation().Y); writeU16(os, sao->getBreath()); @@ -176,7 +176,7 @@ bool PlayerDatabaseLevelDB::loadPlayer(RemotePlayer *player, PlayerSAO *sao) return false; sao->setHPRaw(readU16(is)); - sao->setBasePosition(readV3F32(is)); + sao->setBasePosition(v3fToOpos(readV3F32(is))); sao->setLookPitch(readF32(is)); sao->setPlayerYaw(readF32(is)); sao->setBreath(readU16(is), false); diff --git a/src/database/database-sqlite3.cpp b/src/database/database-sqlite3.cpp index 41c09c7040..f73b96f144 100644 --- a/src/database/database-sqlite3.cpp +++ b/src/database/database-sqlite3.cpp @@ -461,7 +461,7 @@ void PlayerDatabaseSQLite3::savePlayer(RemotePlayer *player) PlayerSAO* sao = player->getPlayerSAO(); sanity_check(sao); - const v3f &pos = sao->getBasePosition(); + const v3opos_t &pos = sao->getBasePosition(); // Begin save in brace is mandatory if (!playerDataExists(player->getName())) { beginSave(); @@ -557,7 +557,7 @@ bool PlayerDatabaseSQLite3::loadPlayer(RemotePlayer *player, PlayerSAO *sao) } sao->setLookPitch(sqlite_to_float(m_stmt_player_load, 0)); sao->setPlayerYaw(sqlite_to_float(m_stmt_player_load, 1)); - sao->setBasePosition(sqlite_to_v3f(m_stmt_player_load, 2)); + sao->setBasePosition(v3fToOpos(sqlite_to_v3f(m_stmt_player_load, 2))); sao->setHPRaw((u16) MYMIN(sqlite_to_int(m_stmt_player_load, 5), U16_MAX)); sao->setBreath((u16) MYMIN(sqlite_to_int(m_stmt_player_load, 6), U16_MAX), false); sqlite3_reset(m_stmt_player_load); diff --git a/src/environment.cpp b/src/environment.cpp index 22e0ab0379..8776375f31 100644 --- a/src/environment.cpp +++ b/src/environment.cpp @@ -25,6 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "server.h" #include "daynightratio.h" #include "emerge.h" +#include "util/numeric.h" Environment::Environment(IGameDef *gamedef): @@ -83,10 +84,10 @@ float Environment::getTimeOfDayF() return m_time_of_day_f; } -bool Environment::line_of_sight(v3f pos1, v3f pos2, v3pos_t *p) +bool Environment::line_of_sight(v3opos_t pos1, v3f pos2, v3pos_t *p) { // Iterate trough nodes on the line - voxalgo::VoxelLineIterator iterator(pos1 / BS, (pos2 - pos1) / BS); + voxalgo::VoxelLineIterator iterator(pos1 / BS, oposToV3f(v3fToOpos(pos2) - pos1) / BS); do { MapNode n = getMap().getNode(iterator.m_current_node_pos); @@ -143,7 +144,7 @@ void Environment::continueRaycast(RaycastState *state, PointedThing *result) Map &map = getMap(); // If a node is found, this is the center of the // first nodebox the shootline meets. - v3f found_boxcenter(0, 0, 0); + v3opos_t found_boxcenter(0, 0, 0); // The untested nodes are in this range. core::aabbox3d new_nodes; while (state->m_iterator.m_current_index <= lastIndex) { @@ -196,13 +197,14 @@ void Environment::continueRaycast(RaycastState *state, PointedThing *result) // ID of the current box (loop counter) u16 id = 0; - v3f npf = intToFloat(np, BS); + auto npf = posToOpos(np, BS); // This loop translates the boxes to their in-world place. - for (aabb3f &box : boxes) { + for (aabb3f &boxf : boxes) { + aabb3o box(v3fToOpos(boxf.MinEdge), v3fToOpos(boxf.MaxEdge)); box.MinEdge += npf; box.MaxEdge += npf; - v3f intersection_point; + v3opos_t intersection_point; v3pos_t intersection_normal; if (!boxLineCollision(box, state->m_shootline.start, state->m_shootline.getVector(), &intersection_point, @@ -233,7 +235,7 @@ void Environment::continueRaycast(RaycastState *state, PointedThing *result) result.distanceSq = min_distance_sq; // Set undersurface and abovesurface nodes f32 d = 0.002 * BS; - v3f fake_intersection = result.intersection_point; + auto fake_intersection = result.intersection_point; // Move intersection towards its source block. if (fake_intersection.X < found_boxcenter.X) { fake_intersection.X += d; diff --git a/src/environment.h b/src/environment.h index d6702e4343..36a17c2b04 100644 --- a/src/environment.h +++ b/src/environment.h @@ -35,6 +35,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include #include "irr_v3d.h" +#include "irrlichttypes.h" #include "network/networkprotocol.h" // for AccessDeniedCode #include "util/basic_macros.h" @@ -84,7 +85,7 @@ class Environment * \param p output, position of the first non-air node * the line intersects */ - bool line_of_sight(v3f pos1, v3f pos2, v3pos_t *p = nullptr); + bool line_of_sight(v3opos_t pos1, v3f pos2, v3pos_t *p = nullptr); /*! * Gets the objects pointed by the shootline as @@ -96,7 +97,7 @@ class Environment * * @param[out] objects found objects */ - virtual void getSelectedActiveObjects(const core::line3d &shootline_on_map, + virtual void getSelectedActiveObjects(const core::line3d &shootline_on_map, std::vector &objects) = 0; /*! diff --git a/src/hud.h b/src/hud.h index 769966688d..bb3dc22737 100644 --- a/src/hud.h +++ b/src/hud.h @@ -20,6 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #pragma once +#include "irr_v3d.h" #include "irrlichttypes_extrabloated.h" #include #include "common/c_types.h" @@ -103,7 +104,7 @@ struct HudElement { u32 dir; v2f align; v2f offset; - v3f world_pos; + v3f world_pos; // todo v3d v2s32 size; s16 z_index = 0; std::string text2; diff --git a/src/irr_aabb3d.h b/src/irr_aabb3d.h index 73bb2db7a3..fd3185e4e8 100644 --- a/src/irr_aabb3d.h +++ b/src/irr_aabb3d.h @@ -24,3 +24,4 @@ with this program; if not, write to the Free Software Foundation, Inc., #include typedef core::aabbox3d aabb3f; +typedef core::aabbox3d aabb3o; diff --git a/src/irr_v3d.h b/src/irr_v3d.h index 7fe5871f9f..c37d197df0 100644 --- a/src/irr_v3d.h +++ b/src/irr_v3d.h @@ -31,3 +31,4 @@ typedef core::vector3d v3s32; using v3pos_t = core::vector3d; using v3bpos_t = core::vector3d; +using v3opos_t = core::vector3d; diff --git a/src/irrlichttypes.h b/src/irrlichttypes.h index ded81a9a7b..5e29a37412 100644 --- a/src/irrlichttypes.h +++ b/src/irrlichttypes.h @@ -67,10 +67,14 @@ namespace core { // Node position using pos_t = irr::s32; -// Block position. +// Block position using bpos_t = irr::s32; +// Object position +using opos_t = double; + #else using pos_t = irr::s16; using bpos_t = irr::s16; +using opos_t = float; #endif diff --git a/src/map.cpp b/src/map.cpp index 1fe9dcc01c..4c5994a884 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -1089,19 +1089,19 @@ bool Map::determineAdditionalOcclusionCheck(const v3pos_t &pos_camera, bool Map::isOccluded(const v3pos_t &pos_camera, const v3pos_t &pos_target, float step, float stepfac, float offset, float end_offset, u32 needed_count) { - v3f direction = intToFloat(pos_target - pos_camera, BS); + auto direction = intToFloat(pos_target - pos_camera, BS); float distance = direction.getLength(); // Normalize direction vector if (distance > 0.0f) direction /= distance; - v3f pos_origin_f = intToFloat(pos_camera, BS); + auto pos_origin_f = intToFloat(pos_camera, BS); u32 count = 0; bool is_valid_position; for (; offset < distance + end_offset; offset += step) { - v3f pos_node_f = pos_origin_f + direction * offset; + auto pos_node_f = pos_origin_f + direction * offset; v3pos_t pos_node = floatToInt(pos_node_f, BS); MapNode node = getNode(pos_node, &is_valid_position); diff --git a/src/mapblock.h b/src/mapblock.h index 28e1596c4f..09eaa981cd 100644 --- a/src/mapblock.h +++ b/src/mapblock.h @@ -611,6 +611,19 @@ inline bool objectpos_over_limit(v3f p) p.Z > max_limit_bs; } +#if USE_POS32 +inline bool objectpos_over_limit(v3opos_t p) +{ + const opos_t max_limit_bs = MAX_MAP_GENERATION_LIMIT * BS; + return p.X < -max_limit_bs || + p.X > max_limit_bs || + p.Y < -max_limit_bs || + p.Y > max_limit_bs || + p.Z < -max_limit_bs || + p.Z > max_limit_bs; +} +#endif + inline bool blockpos_over_max_limit(v3bpos_t p) { const bpos_t max_limit_bp = MAX_MAP_GENERATION_LIMIT / MAP_BLOCKSIZE; diff --git a/src/network/clientpackethandler.cpp b/src/network/clientpackethandler.cpp index b10d82ca43..ff70c39446 100644 --- a/src/network/clientpackethandler.cpp +++ b/src/network/clientpackethandler.cpp @@ -131,7 +131,7 @@ void Client::handleCommand_AuthAccept(NetworkPacket* pkt) // Set player position LocalPlayer *player = m_env.getLocalPlayer(); assert(player != NULL); - player->setPosition(playerpos); + player->setPosition(v3fToOpos(playerpos)); infostream << "Client: received map seed: " << m_map_seed << std::endl; infostream << "Client: received recommended send interval " @@ -594,7 +594,7 @@ void Client::handleCommand_MovePlayer(NetworkPacket* pkt) LocalPlayer *player = m_env.getLocalPlayer(); assert(player != NULL); - v3f pos; + v3opos_t pos; f32 pitch, yaw; *pkt >> pos >> pitch >> yaw; @@ -837,7 +837,7 @@ void Client::handleCommand_PlaySound(NetworkPacket* pkt) { // object ClientActiveObject *cao = m_env.getActiveObject(object_id); if (cao) - pos = cao->getPosition(); + pos = oposToV3f(cao->getPosition()); client_id = m_sound->playSoundAt(name, loop, gain, pos, pitch); break; } @@ -1091,7 +1091,7 @@ void Client::handleCommand_HudAdd(NetworkPacket* pkt) event->hudadd->dir = dir; event->hudadd->align = align; event->hudadd->offset = offset; - event->hudadd->world_pos = world_pos; + event->hudadd->world_pos = v3fToOpos(world_pos); //todo v3d event->hudadd->size = size; event->hudadd->z_index = z_index; event->hudadd->text2 = text2; diff --git a/src/network/networkpacket.cpp b/src/network/networkpacket.cpp index 6b8b0f7037..e3ef89d263 100644 --- a/src/network/networkpacket.cpp +++ b/src/network/networkpacket.cpp @@ -324,6 +324,16 @@ NetworkPacket& NetworkPacket::operator<<(float src) return *this; } +NetworkPacket& NetworkPacket::operator<<(double src) +{ + checkDataSize(sizeof(src)); + + writeF64(&m_data[m_read_offset], src); + + m_read_offset += sizeof(src); + return *this; +} + NetworkPacket& NetworkPacket::operator>>(bool& dst) { checkReadOffset(m_read_offset, 1); @@ -409,6 +419,17 @@ NetworkPacket& NetworkPacket::operator>>(float& dst) return *this; } +NetworkPacket& NetworkPacket::operator>>(double& dst) +{ + checkReadOffset(m_read_offset, sizeof(dst)); + + dst = readF64(&m_data[m_read_offset]); + + m_read_offset += sizeof(dst); + return *this; +} + + NetworkPacket& NetworkPacket::operator>>(v2f& dst) { checkReadOffset(m_read_offset, 8); @@ -429,6 +450,16 @@ NetworkPacket& NetworkPacket::operator>>(v3f& dst) return *this; } +NetworkPacket& NetworkPacket::operator>>(v3d& dst) +{ + checkReadOffset(m_read_offset, sizeof(dst)); + + dst = readV3F64(&m_data[m_read_offset]); + + m_read_offset += sizeof(dst); + return *this; +} + NetworkPacket& NetworkPacket::operator>>(s16& dst) { checkReadOffset(m_read_offset, 2); @@ -506,6 +537,14 @@ NetworkPacket& NetworkPacket::operator<<(v3f src) return *this; } +NetworkPacket& NetworkPacket::operator<<(v3d src) +{ + *this << (double)src.X; + *this << (double)src.Y; + *this << (double)src.Z; + return *this; +} + NetworkPacket& NetworkPacket::operator<<(v3s16 src) { *this << (s16) src.X; diff --git a/src/network/networkpacket.h b/src/network/networkpacket.h index b9c39f332a..0f85cedf8a 100644 --- a/src/network/networkpacket.h +++ b/src/network/networkpacket.h @@ -90,12 +90,18 @@ class NetworkPacket NetworkPacket &operator>>(float &dst); NetworkPacket &operator<<(float src); + NetworkPacket &operator>>(double &dst); + NetworkPacket &operator<<(double src); + NetworkPacket &operator>>(v2f &dst); NetworkPacket &operator<<(v2f src); NetworkPacket &operator>>(v3f &dst); NetworkPacket &operator<<(v3f src); + NetworkPacket &operator>>(v3d &dst); + NetworkPacket &operator<<(v3d src); + NetworkPacket &operator>>(s16 &dst); NetworkPacket &operator<<(s16 src); diff --git a/src/network/serverpackethandler.cpp b/src/network/serverpackethandler.cpp index 85ea8f2c97..a55df8eb9e 100644 --- a/src/network/serverpackethandler.cpp +++ b/src/network/serverpackethandler.cpp @@ -491,7 +491,7 @@ void Server::process_PlayerPos(RemotePlayer *player, PlayerSAO *playersao, fov = (f32)f32fov / 80.0f; *pkt >> wanted_range; - v3f position((f32)ps.X / 100.0f, (f32)ps.Y / 100.0f, (f32)ps.Z / 100.0f); + v3opos_t position((opos_t)ps.X / 100.0f, (opos_t)ps.Y / 100.0f, (opos_t)ps.Z / 100.0f); v3f speed((f32)ss.X / 100.0f, (f32)ss.Y / 100.0f, (f32)ss.Z / 100.0f); pitch = modulo360f(pitch); @@ -651,8 +651,8 @@ void Server::handleCommand_InventoryAction(NetworkPacket* pkt) case InventoryLocation::NODEMETA: { // Check for out-of-range interaction - v3f node_pos = intToFloat(loc.p, BS); - v3f player_pos = player->getPlayerSAO()->getEyePosition(); + v3opos_t node_pos = posToOpos(loc.p, BS); + v3opos_t player_pos = player->getPlayerSAO()->getEyePosition(); f32 d = player_pos.getDistanceFrom(node_pos); return checkInteractDistance(player, d, "inventory"); } @@ -988,7 +988,7 @@ void Server::handleCommand_Interact(NetworkPacket *pkt) process_PlayerPos(player, playersao, pkt); - v3f player_pos = playersao->getLastGoodPosition(); + v3opos_t player_pos = playersao->getLastGoodPosition(); // Update wielded item @@ -1049,9 +1049,9 @@ void Server::handleCommand_Interact(NetworkPacket *pkt) if ((action == INTERACT_START_DIGGING || action == INTERACT_DIGGING_COMPLETED || action == INTERACT_PLACE || action == INTERACT_USE) && enable_anticheat && !isSingleplayer()) { - v3f target_pos = player_pos; + v3opos_t target_pos = player_pos; if (pointed.type == POINTEDTHING_NODE) { - target_pos = intToFloat(pointed.node_undersurface, BS); + target_pos = posToOpos(pointed.node_undersurface, BS); } else if (pointed.type == POINTEDTHING_OBJECT) { if (playersao->getId() == pointed_object->getId()) { actionstream << "Server: " << player->getName() @@ -1113,8 +1113,8 @@ void Server::handleCommand_Interact(NetworkPacket *pkt) ItemStack tool_item = playersao->getWieldedItem(&selected_item, &hand_item); ToolCapabilities toolcap = tool_item.getToolCapabilities(m_itemdef); - v3f dir = (pointed_object->getBasePosition() - - (playersao->getBasePosition() + playersao->getEyeOffset()) + v3f dir = oposToV3f(pointed_object->getBasePosition() - + (playersao->getBasePosition() + v3fToOpos(playersao->getEyeOffset())) ).normalize(); float time_from_last_punch = playersao->resetTimeFromLastPunch(); diff --git a/src/particles.cpp b/src/particles.cpp index 14c987958b..b8dd820bf1 100644 --- a/src/particles.cpp +++ b/src/particles.cpp @@ -22,7 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc., void ParticleParameters::serialize(std::ostream &os, u16 protocol_ver) const { - writeV3F32(os, pos); + writeV3O(os, pos); writeV3F32(os, vel); writeV3F32(os, acc); writeF32(os, expirationtime); @@ -41,7 +41,7 @@ void ParticleParameters::serialize(std::ostream &os, u16 protocol_ver) const void ParticleParameters::deSerialize(std::istream &is, u16 protocol_ver) { - pos = readV3F32(is); + pos = readV3O(is); vel = readV3F32(is); acc = readV3F32(is); expirationtime = readF32(is); diff --git a/src/particles.h b/src/particles.h index 6f518b7710..7eff0b50b5 100644 --- a/src/particles.h +++ b/src/particles.h @@ -20,6 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #pragma once #include +#include "irr_v3d.h" #include "irrlichttypes_bloated.h" #include "tileanimation.h" #include "mapnode.h" @@ -59,7 +60,7 @@ struct CommonParticleParams { }; struct ParticleParameters : CommonParticleParams { - v3f pos; + v3opos_t pos; v3f vel; v3f acc; f32 expirationtime = 1; diff --git a/src/raycast.cpp b/src/raycast.cpp index 4a7b2f8d41..346ccfbfcf 100644 --- a/src/raycast.cpp +++ b/src/raycast.cpp @@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "irr_v3d.h" #include "irr_aabb3d.h" #include "constants.h" +#include "util/numeric.h" bool RaycastSort::operator() (const PointedThing &pt1, const PointedThing &pt2) const @@ -56,10 +57,10 @@ bool RaycastSort::operator() (const PointedThing &pt1, } -RaycastState::RaycastState(const core::line3d &shootline, +RaycastState::RaycastState(const core::line3d &shootline, bool objects_pointable, bool liquids_pointable) : m_shootline(shootline), - m_iterator(shootline.start / BS, shootline.getVector() / BS), + m_iterator(shootline.start / BS, oposToV3f(shootline.getVector() / BS)), m_previous_node(m_iterator.m_current_node_pos), m_objects_pointable(objects_pointable), m_liquids_pointable(liquids_pointable) @@ -67,8 +68,8 @@ RaycastState::RaycastState(const core::line3d &shootline, } -bool boxLineCollision(const aabb3f &box, const v3f &start, - const v3f &dir, v3f *collision_point, v3pos_t *collision_normal) +bool boxLineCollision(const aabb3o &box, const v3opos_t &start, + const v3opos_t &dir, v3opos_t *collision_point, v3pos_t *collision_normal) { if (box.isPointInside(start)) { *collision_point = start; diff --git a/src/raycast.h b/src/raycast.h index eb32fd6d1e..67e6b47ecf 100644 --- a/src/raycast.h +++ b/src/raycast.h @@ -19,6 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #pragma once +#include "irr_v3d.h" #include "voxelalgorithms.h" #include "util/pointedthing.h" @@ -37,11 +38,11 @@ class RaycastState * @param objects_pointable if false, only nodes will be found * @param liquids pointable if false, liquid nodes won't be found */ - RaycastState(const core::line3d &shootline, bool objects_pointable, + RaycastState(const core::line3d &shootline, bool objects_pointable, bool liquids_pointable); //! Shootline of the raycast. - core::line3d m_shootline; + core::line3d m_shootline; //! Iterator to store the progress of the raycast. voxalgo::VoxelLineIterator m_iterator; //! Previous tested node during the raycast. @@ -73,5 +74,5 @@ class RaycastState * outwards of the surface. If start is in the box, zero vector. * @returns true if a collision point was found */ -bool boxLineCollision(const aabb3f &box, const v3f &start, const v3f &dir, - v3f *collision_point, v3pos_t *collision_normal); +bool boxLineCollision(const aabb3o &box, const v3opos_t &start, const v3opos_t &dir, + v3opos_t *collision_point, v3pos_t *collision_normal); diff --git a/src/script/common/c_converter.cpp b/src/script/common/c_converter.cpp index 07d23e8885..d15c49ecbe 100644 --- a/src/script/common/c_converter.cpp +++ b/src/script/common/c_converter.cpp @@ -92,6 +92,18 @@ void push_v3f(lua_State *L, v3f p) set_vector_metatable(L); } +void push_v3f(lua_State *L, v3d p) +{ + lua_createtable(L, 0, 3); + lua_pushnumber(L, p.X); + lua_setfield(L, -2, "x"); + lua_pushnumber(L, p.Y); + lua_setfield(L, -2, "y"); + lua_pushnumber(L, p.Z); + lua_setfield(L, -2, "z"); + set_vector_metatable(L); +} + void push_v2f(lua_State *L, v2f p) { lua_createtable(L, 0, 2); @@ -247,6 +259,15 @@ v3d read_v3d(lua_State *L, int index) return pos; } +v3opos_t read_v3o(lua_State *L, int index) +{ +#if USE_POS32 + return read_v3d(L, index); +#else + return read_v3f(L, index); +#endif +} + v3d check_v3d(lua_State *L, int index) { v3d pos; @@ -254,17 +275,23 @@ v3d check_v3d(lua_State *L, int index) lua_getfield(L, index, "x"); CHECK_POS_COORD("x"); pos.X = lua_tonumber(L, -1); +#if !USE_POS32 CHECK_FLOAT_RANGE(pos.X, "x") +#endif lua_pop(L, 1); lua_getfield(L, index, "y"); CHECK_POS_COORD("y"); pos.Y = lua_tonumber(L, -1); +#if !USE_POS32 CHECK_FLOAT_RANGE(pos.Y, "y") +#endif lua_pop(L, 1); lua_getfield(L, index, "z"); CHECK_POS_COORD("z"); pos.Z = lua_tonumber(L, -1); +#if !USE_POS32 CHECK_FLOAT_RANGE(pos.Z, "z") +#endif lua_pop(L, 1); return pos; } @@ -288,11 +315,31 @@ void pushFloatPos(lua_State *L, v3f p) push_v3f(L, p); } +void pushFloatPos(lua_State *L, v3d p) +{ + p /= BS; + push_v3f(L, p); +} + v3f checkFloatPos(lua_State *L, int index) { return check_v3f(L, index) * BS; } +v3opos_t check_v3o(lua_State *L, int index) +{ +#if USE_POS32 + return check_v3d(L, index); +#else + return check_v3f(L, index); +#endif +} + +v3opos_t checkOposPos(lua_State *L, int index) +{ + return check_v3o(L, index) * BS; +} + void push_v3s16(lua_State *L, v3s16 p) { lua_createtable(L, 0, 3); diff --git a/src/script/common/c_converter.h b/src/script/common/c_converter.h index 5afe57a14f..4497d8acee 100644 --- a/src/script/common/c_converter.h +++ b/src/script/common/c_converter.h @@ -105,8 +105,11 @@ v3f checkFloatPos (lua_State *L, int index); v3f check_v3f (lua_State *L, int index); v3s16 check_v3s16 (lua_State *L, int index); v3pos_t check_v3pos (lua_State *L, int index); +v3opos_t check_v3o (lua_State *L, int index); +v3opos_t checkOposPos (lua_State *L, int index); v3f read_v3f (lua_State *L, int index); +v3opos_t read_v3o (lua_State *L, int index); v2f read_v2f (lua_State *L, int index); v2s16 read_v2s16 (lua_State *L, int index); v2s32 read_v2s32 (lua_State *L, int index); @@ -157,7 +160,9 @@ inline void push_v3pos (lua_State *L, v3pos_t p) { void push_aabb3f (lua_State *L, aabb3f box); void push_ARGB8 (lua_State *L, video::SColor color); void pushFloatPos (lua_State *L, v3f p); +void pushFloatPos (lua_State *L, v3d p); void push_v3f (lua_State *L, v3f p); +void push_v3f (lua_State *L, v3d p); void push_v2f (lua_State *L, v2f p); void warn_if_field_exists(lua_State *L, int table, diff --git a/src/script/cpp_api/s_item.cpp b/src/script/cpp_api/s_item.cpp index 018c209c31..fff325fd61 100644 --- a/src/script/cpp_api/s_item.cpp +++ b/src/script/cpp_api/s_item.cpp @@ -33,7 +33,7 @@ with this program; if not, write to the Free Software Foundation, Inc., LuaError(std::string(__FUNCTION__) + ": " + (e).what() + ". " detail) bool ScriptApiItem::item_OnDrop(ItemStack &item, - ServerActiveObject *dropper, v3f pos) + ServerActiveObject *dropper, v3opos_t pos) { SCRIPTAPI_PRECHECKHEADER diff --git a/src/script/cpp_api/s_item.h b/src/script/cpp_api/s_item.h index 576cc535e7..030d4b733d 100644 --- a/src/script/cpp_api/s_item.h +++ b/src/script/cpp_api/s_item.h @@ -44,7 +44,7 @@ class ScriptApiItem */ bool item_OnDrop(ItemStack &item, - ServerActiveObject *dropper, v3f pos); + ServerActiveObject *dropper, v3opos_t pos); bool item_OnPlace(Optional &item, ServerActiveObject *placer, const PointedThing &pointed); bool item_OnUse(Optional &item, diff --git a/src/script/lua_api/l_env.cpp b/src/script/lua_api/l_env.cpp index 8d27d35024..b81c6b4ef7 100644 --- a/src/script/lua_api/l_env.cpp +++ b/src/script/lua_api/l_env.cpp @@ -176,8 +176,8 @@ int LuaRaycast::create_object(lua_State *L) bool objects = true; bool liquids = false; - v3f pos1 = checkFloatPos(L, 1); - v3f pos2 = checkFloatPos(L, 2); + auto pos1 = check_v3o(L, 1); + auto pos2 = check_v3o(L, 2); if (lua_isboolean(L, 3)) { objects = readParam(L, 3); } @@ -185,7 +185,7 @@ int LuaRaycast::create_object(lua_State *L) liquids = readParam(L, 4); } - LuaRaycast *o = new LuaRaycast(core::line3d(pos1, pos2), + LuaRaycast *o = new LuaRaycast(core::line3d(pos1, pos2), objects, liquids); *(void **) (lua_newuserdata(L, sizeof(void *))) = o; @@ -638,7 +638,7 @@ int ModApiEnvMod::l_add_entity(lua_State *L) { GET_ENV_PTR; - v3f pos = checkFloatPos(L, 1); + auto pos = check_v3o(L, 1); const char *name = luaL_checkstring(L, 2); const char *staticdata = luaL_optstring(L, 3, ""); @@ -735,7 +735,7 @@ int ModApiEnvMod::l_get_objects_inside_radius(lua_State *L) ScriptApiBase *script = getScriptApiBase(L); // Do it - v3f pos = checkFloatPos(L, 1); + v3opos_t pos = checkOposPos(L, 1); float radius = readParam(L, 2) * BS; std::vector objs; @@ -758,9 +758,9 @@ int ModApiEnvMod::l_get_objects_in_area(lua_State *L) GET_ENV_PTR; ScriptApiBase *script = getScriptApiBase(L); - v3f minp = read_v3f(L, 1) * BS; - v3f maxp = read_v3f(L, 2) * BS; - aabb3f box(minp, maxp); + auto minp = read_v3o(L, 1) * BS; + auto maxp = read_v3o(L, 2) * BS; + aabb3o box(minp, maxp); box.repair(); std::vector objs; @@ -1130,7 +1130,7 @@ int ModApiEnvMod::l_line_of_sight(lua_State *L) GET_PLAIN_ENV_PTR; // read position 1 from lua - v3f pos1 = checkFloatPos(L, 1); + v3opos_t pos1 = check_v3o(L, 1); // read position 2 from lua v3f pos2 = checkFloatPos(L, 2); diff --git a/src/script/lua_api/l_env.h b/src/script/lua_api/l_env.h index 2e6fa3719d..8eb28abd79 100644 --- a/src/script/lua_api/l_env.h +++ b/src/script/lua_api/l_env.h @@ -312,7 +312,7 @@ class LuaRaycast : public ModApiBase public: //! Constructor with the same arguments as RaycastState. LuaRaycast( - const core::line3d &shootline, + const core::line3d &shootline, bool objects_pointable, bool liquids_pointable) : state(shootline, objects_pointable, liquids_pointable) diff --git a/src/script/lua_api/l_noise.cpp b/src/script/lua_api/l_noise.cpp index 6bfa05609a..20aaef90e4 100644 --- a/src/script/lua_api/l_noise.cpp +++ b/src/script/lua_api/l_noise.cpp @@ -51,7 +51,7 @@ int LuaPerlinNoise::l_get_3d(lua_State *L) { NO_MAP_LOCK_REQUIRED; LuaPerlinNoise *o = checkobject(L, 1); - v3f p = check_v3f(L, 2); + v3opos_t p = check_v3o(L, 2); lua_Number val = NoisePerlin3D(&o->np, p.X, p.Y, p.Z, 0); lua_pushnumber(L, val); return 1; @@ -215,7 +215,7 @@ int LuaPerlinNoiseMap::l_get_3d_map(lua_State *L) size_t i = 0; LuaPerlinNoiseMap *o = checkobject(L, 1); - v3f p = check_v3f(L, 2); + v3opos_t p = check_v3o(L, 2); if (!o->m_is3d) return 0; @@ -245,7 +245,7 @@ int LuaPerlinNoiseMap::l_get_3d_map_flat(lua_State *L) NO_MAP_LOCK_REQUIRED; LuaPerlinNoiseMap *o = checkobject(L, 1); - v3f p = check_v3f(L, 2); + v3opos_t p = check_v3o(L, 2); bool use_buffer = lua_istable(L, 3); if (!o->m_is3d) diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp index dfa4c7711f..edbf91978c 100644 --- a/src/script/lua_api/l_object.cpp +++ b/src/script/lua_api/l_object.cpp @@ -136,7 +136,7 @@ int ObjectRef::l_set_pos(lua_State *L) if (sao == nullptr) return 0; - v3f pos = checkFloatPos(L, 2); + v3opos_t pos = checkOposPos(L, 2); sao->setPos(pos); return 0; @@ -151,7 +151,7 @@ int ObjectRef::l_move_to(lua_State *L) if (sao == nullptr) return 0; - v3f pos = checkFloatPos(L, 2); + v3opos_t pos = checkOposPos(L, 2); bool continuous = readParam(L, 3); sao->moveTo(pos, continuous); @@ -171,7 +171,7 @@ int ObjectRef::l_punch(lua_State *L) float time_from_last_punch = readParam(L, 3, 1000000.0f); ToolCapabilities toolcap = read_tool_capabilities(L, 4); - v3f dir = readParam(L, 5, sao->getBasePosition() - puncher->getBasePosition()); + v3f dir = readParam(L, 5, oposToV3f(sao->getBasePosition() - puncher->getBasePosition())); dir.normalize(); u32 wear = sao->punch(dir, &toolcap, puncher, time_from_last_punch); diff --git a/src/script/lua_api/l_particles.cpp b/src/script/lua_api/l_particles.cpp index a51c4fe200..ba4eb8beaa 100644 --- a/src/script/lua_api/l_particles.cpp +++ b/src/script/lua_api/l_particles.cpp @@ -50,7 +50,7 @@ int ModApiParticles::l_add_particle(lua_State *L) { log_deprecated(L, "Deprecated add_particle call with " "individual parameters instead of definition"); - p.pos = check_v3f(L, 1); + p.pos = check_v3o(L, 1); p.vel = check_v3f(L, 2); p.acc = check_v3f(L, 3); p.expirationtime = luaL_checknumber(L, 4); @@ -64,7 +64,7 @@ int ModApiParticles::l_add_particle(lua_State *L) { lua_getfield(L, 1, "pos"); if (lua_istable(L, -1)) - p.pos = check_v3f(L, -1); + p.pos = check_v3o(L, -1); lua_pop(L, 1); lua_getfield(L, 1, "vel"); diff --git a/src/script/lua_api/l_particles_local.cpp b/src/script/lua_api/l_particles_local.cpp index cc68b13a58..20dd9e1c5a 100644 --- a/src/script/lua_api/l_particles_local.cpp +++ b/src/script/lua_api/l_particles_local.cpp @@ -36,7 +36,7 @@ int ModApiParticlesLocal::l_add_particle(lua_State *L) lua_getfield(L, 1, "pos"); if (lua_istable(L, -1)) - p.pos = check_v3f(L, -1); + p.pos = check_v3o(L, -1); lua_pop(L, 1); lua_getfield(L, 1, "velocity"); diff --git a/src/server.cpp b/src/server.cpp index e6519ea6e8..5ca07ef28f 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -29,6 +29,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "map.h" #include "threading/mutex_auto_lock.h" #include "constants.h" +#include "util/numeric.h" #include "voxel.h" #include "config.h" #include "version.h" @@ -148,7 +149,7 @@ v3f ServerSoundParams::getPos(ServerEnvironment *env, bool *pos_exists) const if(!sao) return v3f(0,0,0); if(pos_exists) *pos_exists = true; - return sao->getBasePosition(); } + return oposToV3f(sao->getBasePosition()); } } return v3f(0,0,0); } @@ -1543,7 +1544,7 @@ void Server::SendSpawnParticle(session_t peer_id, u16 protocol_version, if (peer_id == PEER_ID_INEXISTENT) { std::vector clients = m_clients.getClientIDs(); - const v3f pos = p.pos * BS; + const auto pos = p.pos * BS; const float radius_sq = radius * radius; for (const session_t client_id : clients) { @@ -1601,7 +1602,7 @@ void Server::SendAddParticleSpawner(session_t peer_id, u16 protocol_version, PlayerSAO *sao = player->getPlayerSAO(); if (!sao) continue; - if (sao->getBasePosition().getDistanceFromSQ(pos) > radius_sq) + if (sao->getBasePosition().getDistanceFromSQ(v3fToOpos(pos)) > radius_sq) continue; } @@ -1839,7 +1840,7 @@ void Server::SendMovePlayer(session_t peer_id) pkt << sao->getBasePosition() << sao->getLookPitch() << sao->getRotation().Y; { - v3f pos = sao->getBasePosition(); + auto pos = sao->getBasePosition(); verbosestream << "Server: Sending TOCLIENT_MOVE_PLAYER" << " pos=(" << pos.X << "," << pos.Y << "," << pos.Z << ")" << " pitch=" << sao->getLookPitch() @@ -2102,7 +2103,7 @@ s32 Server::playSound(const SimpleSoundSpec &spec, continue; if (pos_exists) { - if(sao->getBasePosition().getDistanceFrom(pos) > + if(sao->getBasePosition().getDistanceFrom(v3fToOpos(pos)) > params.max_hear_distance) continue; } @@ -2214,7 +2215,7 @@ void Server::sendRemoveNode(v3pos_t p, std::unordered_set *far_players, float far_d_nodes) { float maxd = far_d_nodes * BS; - v3f p_f = intToFloat(p, BS); + v3opos_t p_f = posToOpos(p, BS); v3bpos_t block_pos = getNodeBlockPos(p); NetworkPacket pkt(TOCLIENT_REMOVENODE, 6); @@ -2252,7 +2253,7 @@ void Server::sendAddNode(v3pos_t p, MapNode n, std::unordered_set *far_play float far_d_nodes, bool remove_metadata) { float maxd = far_d_nodes * BS; - v3f p_f = intToFloat(p, BS); + v3opos_t p_f = intToFloat(p, BS); v3bpos_t block_pos = getNodeBlockPos(p); NetworkPacket pkt(TOCLIENT_ADDNODE, 6 + 2 + 1 + 1 + 1); @@ -2301,7 +2302,7 @@ void Server::sendMetadataChanged(const std::list &meta_updates, float f continue; ServerActiveObject *player = m_env->getActiveObject(i); - v3f player_pos = player ? player->getBasePosition() : v3f(); + auto player_pos = player ? player->getBasePosition() : v3opos_t(); for (const v3pos_t &pos : meta_updates) { NodeMetadata *meta = m_env->getMap().getNodeMetadata(pos); @@ -2311,7 +2312,7 @@ void Server::sendMetadataChanged(const std::list &meta_updates, float f v3bpos_t block_pos = getNodeBlockPos(pos); if (!client->isBlockSent(block_pos) || (player && - player_pos.getDistanceFrom(intToFloat(pos, BS)) > maxd)) { + player_pos.getDistanceFrom(posToOpos(pos, BS)) > maxd)) { client->SetBlockNotSent(block_pos); continue; } @@ -3694,12 +3695,13 @@ std::string Server::getModStoragePath() const return m_path_world + DIR_DELIM + "mod_storage"; } -v3f Server::findSpawnPos() +v3opos_t Server::findSpawnPos() { ServerMap &map = m_env->getServerMap(); - v3f nodeposf; - if (g_settings->getV3FNoEx("static_spawnpoint", nodeposf)) - return nodeposf * BS; + v3opos_t nodeposf; + v3f nodeposff; + if (g_settings->getV3FNoEx("static_spawnpoint", nodeposff)) + return v3fToOpos(nodeposff) * BS; bool is_good = false; // Limit spawn range to mapgen edges (determined by 'mapgen_limit') @@ -3741,7 +3743,7 @@ v3f Server::findSpawnPos() if (air_count >= 2) { // Spawn in lower empty node nodepos.Y--; - nodeposf = intToFloat(nodepos, BS); + nodeposf = posToOpos(nodepos, BS); // Don't spawn the player outside map boundaries if (objectpos_over_limit(nodeposf)) // Exit this loop, positions above are probably over limit @@ -3762,7 +3764,7 @@ v3f Server::findSpawnPos() return nodeposf; // No suitable spawn point found, return fallback 0,0,0 - return v3f(0.0f, 0.0f, 0.0f); + return v3opos_t(0.0f, 0.0f, 0.0f); } void Server::requestShutdown(const std::string &msg, bool reconnect, float delay) diff --git a/src/server.h b/src/server.h index 64ce4f9312..ddd7cabf2b 100644 --- a/src/server.h +++ b/src/server.h @@ -308,7 +308,7 @@ class Server : public con::PeerHandler, public MapEventReceiver, bool showFormspec(const char *name, const std::string &formspec, const std::string &formname); Map & getMap() { return m_env->getMap(); } ServerEnvironment & getEnv() { return *m_env; } - v3f findSpawnPos(); + v3opos_t findSpawnPos(); u32 hudAdd(RemotePlayer *player, HudElement *element); bool hudRemove(RemotePlayer *player, u32 id); diff --git a/src/server/activeobjectmgr.cpp b/src/server/activeobjectmgr.cpp index acd6611f4e..72016b7c13 100644 --- a/src/server/activeobjectmgr.cpp +++ b/src/server/activeobjectmgr.cpp @@ -78,7 +78,7 @@ bool ActiveObjectMgr::registerObject(ServerActiveObject *obj) } if (objectpos_over_limit(obj->getBasePosition())) { - v3f p = obj->getBasePosition(); + auto p = obj->getBasePosition(); warningstream << "Server::ActiveObjectMgr::addActiveObjectRaw(): " << "object position (" << p.X << "," << p.Y << "," << p.Z << ") outside maximum range" << std::endl; @@ -111,14 +111,14 @@ void ActiveObjectMgr::removeObject(u16 id) } // clang-format on -void ActiveObjectMgr::getObjectsInsideRadius(const v3f &pos, float radius, +void ActiveObjectMgr::getObjectsInsideRadius(const v3opos_t &pos, float radius, std::vector &result, std::function include_obj_cb) { float r2 = radius * radius; for (auto &activeObject : m_active_objects) { ServerActiveObject *obj = activeObject.second; - const v3f &objectpos = obj->getBasePosition(); + const auto &objectpos = obj->getBasePosition(); if (objectpos.getDistanceFromSQ(pos) > r2) continue; @@ -127,13 +127,13 @@ void ActiveObjectMgr::getObjectsInsideRadius(const v3f &pos, float radius, } } -void ActiveObjectMgr::getObjectsInArea(const aabb3f &box, +void ActiveObjectMgr::getObjectsInArea(const aabb3o &box, std::vector &result, std::function include_obj_cb) { for (auto &activeObject : m_active_objects) { ServerActiveObject *obj = activeObject.second; - const v3f &objectpos = obj->getBasePosition(); + const auto &objectpos = obj->getBasePosition(); if (!box.isPointInside(objectpos)) continue; @@ -142,7 +142,7 @@ void ActiveObjectMgr::getObjectsInArea(const aabb3f &box, } } -void ActiveObjectMgr::getAddedActiveObjectsAroundPos(const v3f &player_pos, f32 radius, +void ActiveObjectMgr::getAddedActiveObjectsAroundPos(const v3opos_t &player_pos, f32 radius, f32 player_radius, std::set ¤t_objects, std::queue &added_objects) { diff --git a/src/server/activeobjectmgr.h b/src/server/activeobjectmgr.h index d43f5643c2..aa077b4231 100644 --- a/src/server/activeobjectmgr.h +++ b/src/server/activeobjectmgr.h @@ -35,14 +35,14 @@ class ActiveObjectMgr : public ::ActiveObjectMgr bool registerObject(ServerActiveObject *obj) override; void removeObject(u16 id) override; - void getObjectsInsideRadius(const v3f &pos, float radius, + void getObjectsInsideRadius(const v3opos_t &pos, float radius, std::vector &result, std::function include_obj_cb); - void getObjectsInArea(const aabb3f &box, + void getObjectsInArea(const aabb3o &box, std::vector &result, std::function include_obj_cb); - void getAddedActiveObjectsAroundPos(const v3f &player_pos, f32 radius, + void getAddedActiveObjectsAroundPos(const v3opos_t &player_pos, f32 radius, f32 player_radius, std::set ¤t_objects, std::queue &added_objects); }; diff --git a/src/server/luaentity_sao.cpp b/src/server/luaentity_sao.cpp index 82f6da2314..8f781d4f61 100644 --- a/src/server/luaentity_sao.cpp +++ b/src/server/luaentity_sao.cpp @@ -26,7 +26,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "server.h" #include "serverenvironment.h" -LuaEntitySAO::LuaEntitySAO(ServerEnvironment *env, v3f pos, const std::string &data) +LuaEntitySAO::LuaEntitySAO(ServerEnvironment *env, v3opos_t pos, const std::string &data) : UnitSAO(env, pos) { std::string name; @@ -161,7 +161,7 @@ void LuaEntitySAO::step(float dtime, bool send_recommended) box.MinEdge *= BS; box.MaxEdge *= BS; f32 pos_max_d = BS*0.25; // Distance per iteration - v3f p_pos = m_base_position; + auto p_pos = m_base_position; v3f p_velocity = m_velocity; v3f p_acceleration = m_acceleration; moveresult = collisionMoveSimple(m_env, m_env->getGameDef(), @@ -175,8 +175,8 @@ void LuaEntitySAO::step(float dtime, bool send_recommended) m_velocity = p_velocity; m_acceleration = p_acceleration; } else { - m_base_position += dtime * m_velocity + 0.5 * dtime - * dtime * m_acceleration; + m_base_position += v3fToOpos(dtime * m_velocity + 0.5 * dtime + * dtime * m_acceleration); m_velocity += dtime * m_acceleration; } @@ -238,7 +238,7 @@ std::string LuaEntitySAO::getClientInitializationData(u16 protocol_version) os << serializeString16(""); // name writeU8(os, 0); // is_player writeU16(os, getId()); //id - writeV3F32(os, m_base_position); + writeV3O(os, m_base_position); writeV3F32(os, m_rotation); writeU16(os, m_hp); @@ -368,7 +368,7 @@ void LuaEntitySAO::rightClick(ServerActiveObject *clicker) m_env->getScriptIface()->luaentity_Rightclick(m_id, clicker); } -void LuaEntitySAO::setPos(const v3f &pos) +void LuaEntitySAO::setPos(const v3opos_t &pos) { if(isAttached()) return; @@ -376,7 +376,7 @@ void LuaEntitySAO::setPos(const v3f &pos) sendPosition(false, true); } -void LuaEntitySAO::moveTo(v3f pos, bool continuous) +void LuaEntitySAO::moveTo(v3opos_t pos, bool continuous) { if(isAttached()) return; @@ -521,13 +521,13 @@ void LuaEntitySAO::sendPosition(bool do_interpolate, bool is_movement_end) m_messages_out.emplace(getId(), false, str); } -bool LuaEntitySAO::getCollisionBox(aabb3f *toset) const +bool LuaEntitySAO::getCollisionBox(aabb3o *toset) const { if (m_prop.physical) { //update collision box - toset->MinEdge = m_prop.collisionbox.MinEdge * BS; - toset->MaxEdge = m_prop.collisionbox.MaxEdge * BS; + toset->MinEdge = v3fToOpos(m_prop.collisionbox.MinEdge * BS); + toset->MaxEdge = v3fToOpos(m_prop.collisionbox.MaxEdge * BS); toset->MinEdge += m_base_position; toset->MaxEdge += m_base_position; diff --git a/src/server/luaentity_sao.h b/src/server/luaentity_sao.h index 87b664a8b2..126dc75be0 100644 --- a/src/server/luaentity_sao.h +++ b/src/server/luaentity_sao.h @@ -27,9 +27,9 @@ class LuaEntitySAO : public UnitSAO public: LuaEntitySAO() = delete; // Used by the environment to load SAO - LuaEntitySAO(ServerEnvironment *env, v3f pos, const std::string &data); + LuaEntitySAO(ServerEnvironment *env, v3opos_t pos, const std::string &data); // Used by the Lua API - LuaEntitySAO(ServerEnvironment *env, v3f pos, const std::string &name, + LuaEntitySAO(ServerEnvironment *env, v3opos_t pos, const std::string &name, const std::string &state) : UnitSAO(env, pos), m_init_name(name), m_init_state(state) @@ -49,8 +49,8 @@ class LuaEntitySAO : public UnitSAO float time_from_last_punch = 1000000.0f, u16 initial_wear = 0); void rightClick(ServerActiveObject *clicker); - void setPos(const v3f &pos); - void moveTo(v3f pos, bool continuous); + void setPos(const v3opos_t &pos); + void moveTo(v3opos_t pos, bool continuous); float getMinimumSavedMovement(); std::string getDescription(); void setHP(s32 hp, const PlayerHPChangeReason &reason); @@ -68,7 +68,7 @@ class LuaEntitySAO : public UnitSAO void setSprite(v2s16 p, int num_frames, float framelength, bool select_horiz_by_yawpitch); std::string getName(); - bool getCollisionBox(aabb3f *toset) const; + bool getCollisionBox(aabb3o *toset) const; bool getSelectionBox(aabb3f *toset) const; bool collideWithObjects() const; @@ -91,7 +91,7 @@ class LuaEntitySAO : public UnitSAO v3f m_velocity; v3f m_acceleration; - v3f m_last_sent_position; + v3opos_t m_last_sent_position; v3f m_last_sent_velocity; v3f m_last_sent_rotation; float m_last_sent_position_timer = 0.0f; diff --git a/src/server/player_sao.cpp b/src/server/player_sao.cpp index b0f3955e82..04369d53c0 100644 --- a/src/server/player_sao.cpp +++ b/src/server/player_sao.cpp @@ -27,7 +27,7 @@ with this program; if not, write to the Free Software Foundation, Inc., PlayerSAO::PlayerSAO(ServerEnvironment *env_, RemotePlayer *player_, session_t peer_id_, bool is_singleplayer): - UnitSAO(env_, v3f(0,0,0)), + UnitSAO(env_, v3opos_t(0,0,0)), m_player(player_), m_peer_id(peer_id_), m_is_singleplayer(is_singleplayer) @@ -113,7 +113,7 @@ std::string PlayerSAO::getClientInitializationData(u16 protocol_version) os << serializeString16(m_player->getName()); // name writeU8(os, 1); // is_player writeS16(os, getId()); // id - writeV3F32(os, m_base_position); + writeV3F32(os, oposToV3f(m_base_position)); // todo writeV3F64 writeV3F32(os, m_rotation); writeU16(os, getHP()); @@ -191,8 +191,8 @@ void PlayerSAO::step(float dtime, bool send_recommended) // Sequence of damage points, starting 0.1 above feet and progressing // upwards in 1 node intervals, stopping below top damage point. for (float dam_height = 0.1f; dam_height < dam_top; dam_height++) { - v3pos_t p = floatToInt(m_base_position + - v3f(0.0f, dam_height * BS, 0.0f), BS); + v3pos_t p = oposToPos(m_base_position + + v3opos_t(0.0f, dam_height * BS, 0.0f), BS); MapNode n = m_env->getMap().getNode(p); const ContentFeatures &c = m_env->getGameDef()->ndef()->get(n); if (c.damage_per_second > damage_per_second) { @@ -202,8 +202,8 @@ void PlayerSAO::step(float dtime, bool send_recommended) } // Top damage point - v3pos_t ptop = floatToInt(m_base_position + - v3f(0.0f, dam_top * BS, 0.0f), BS); + v3pos_t ptop = oposToPos(m_base_position + + v3opos_t(0.0f, dam_top * BS, 0.0f), BS); MapNode ntop = m_env->getMap().getNode(ptop); const ContentFeatures &c = m_env->getGameDef()->ndef()->get(ntop); if (c.damage_per_second > damage_per_second) { @@ -259,7 +259,7 @@ void PlayerSAO::step(float dtime, bool send_recommended) // If the object gets detached this comes into effect automatically from // the last known origin. if (auto *parent = getParent()) { - v3f pos = parent->getBasePosition(); + auto pos = parent->getBasePosition(); m_last_good_position = pos; setBasePosition(pos); @@ -273,7 +273,7 @@ void PlayerSAO::step(float dtime, bool send_recommended) if (m_position_not_sent) { m_position_not_sent = false; float update_interval = m_env->getSendRecommendedInterval(); - v3f pos; + v3opos_t pos; // When attached, the position is only sent to clients where the // parent isn't known if (isAttached()) @@ -319,7 +319,7 @@ std::string PlayerSAO::generateUpdatePhysicsOverrideCommand() const return os.str(); } -void PlayerSAO::setBasePosition(const v3f &position) +void PlayerSAO::setBasePosition(const v3opos_t &position) { if (m_player && position != m_base_position) m_player->setDirty(true); @@ -333,7 +333,7 @@ void PlayerSAO::setBasePosition(const v3f &position) } } -void PlayerSAO::setPos(const v3f &pos) +void PlayerSAO::setPos(const v3opos_t &pos) { if(isAttached()) return; @@ -350,7 +350,7 @@ void PlayerSAO::setPos(const v3f &pos) m_env->getGameDef()->SendMovePlayer(m_peer_id); } -void PlayerSAO::moveTo(v3f pos, bool continuous) +void PlayerSAO::moveTo(v3opos_t pos, bool continuous) { if(isAttached()) return; @@ -622,7 +622,7 @@ bool PlayerSAO::checkMovementCheat() if (player_max_jump < 0.0001f) player_max_jump = 0.0001f; - v3f diff = (m_base_position - m_last_good_position); + v3opos_t diff = (m_base_position - m_last_good_position); float d_vert = diff.Y; diff.Y = 0; float d_horiz = diff.getLength(); @@ -653,11 +653,11 @@ bool PlayerSAO::checkMovementCheat() return cheated; } -bool PlayerSAO::getCollisionBox(aabb3f *toset) const +bool PlayerSAO::getCollisionBox(aabb3o *toset) const { //update collision box - toset->MinEdge = m_prop.collisionbox.MinEdge * BS; - toset->MaxEdge = m_prop.collisionbox.MaxEdge * BS; + toset->MinEdge = v3fToOpos(m_prop.collisionbox.MinEdge * BS); + toset->MaxEdge = v3fToOpos(m_prop.collisionbox.MaxEdge * BS); toset->MinEdge += m_base_position; toset->MaxEdge += m_base_position; diff --git a/src/server/player_sao.h b/src/server/player_sao.h index 5f2c397638..d3330f9207 100644 --- a/src/server/player_sao.h +++ b/src/server/player_sao.h @@ -87,9 +87,9 @@ class PlayerSAO : public UnitSAO std::string getClientInitializationData(u16 protocol_version); void getStaticData(std::string *result) const; void step(float dtime, bool send_recommended); - void setBasePosition(const v3f &position); - void setPos(const v3f &pos); - void moveTo(v3f pos, bool continuous); + void setBasePosition(const v3opos_t &position); + void setPos(const v3opos_t &pos); + void moveTo(v3opos_t pos, bool continuous); void setPlayerYaw(const float yaw); // Data should not be sent at player initialization void setPlayerYawAndSend(const float yaw); @@ -143,7 +143,7 @@ class PlayerSAO : public UnitSAO // Cheat prevention - v3f getLastGoodPosition() const { return m_last_good_position; } + v3opos_t getLastGoodPosition() const { return m_last_good_position; } float resetTimeFromLastPunch() { float r = m_time_from_last_punch; @@ -171,13 +171,13 @@ class PlayerSAO : public UnitSAO m_is_singleplayer = is_singleplayer; } - bool getCollisionBox(aabb3f *toset) const; + bool getCollisionBox(aabb3o *toset) const; bool getSelectionBox(aabb3f *toset) const; bool collideWithObjects() const { return true; } void finalize(RemotePlayer *player, const std::set &privs); - v3f getEyePosition() const { return m_base_position + getEyeOffset(); } + v3opos_t getEyePosition() const { return m_base_position + v3fToOpos(getEyeOffset()); } v3f getEyeOffset() const; float getZoomFOV() const; @@ -194,7 +194,7 @@ class PlayerSAO : public UnitSAO // Cheat prevention LagPool m_dig_pool; LagPool m_move_pool; - v3f m_last_good_position; + v3opos_t m_last_good_position; float m_time_from_last_teleport = 0.0f; float m_time_from_last_punch = 0.0f; v3pos_t m_nocheat_dig_pos = v3pos_t(32767, 32767, 32767); diff --git a/src/server/serveractiveobject.cpp b/src/server/serveractiveobject.cpp index 96b433d1d1..6c9e2b551a 100644 --- a/src/server/serveractiveobject.cpp +++ b/src/server/serveractiveobject.cpp @@ -23,7 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "constants.h" // BS #include "log.h" -ServerActiveObject::ServerActiveObject(ServerEnvironment *env, v3f pos): +ServerActiveObject::ServerActiveObject(ServerEnvironment *env, v3opos_t pos): ActiveObject(0), m_env(env), m_base_position(pos) diff --git a/src/server/serveractiveobject.h b/src/server/serveractiveobject.h index 7467350905..26f996e7d3 100644 --- a/src/server/serveractiveobject.h +++ b/src/server/serveractiveobject.h @@ -55,7 +55,7 @@ class ServerActiveObject : public ActiveObject NOTE: m_env can be NULL, but step() isn't called if it is. Prototypes are used that way. */ - ServerActiveObject(ServerEnvironment *env, v3f pos); + ServerActiveObject(ServerEnvironment *env, v3opos_t pos); virtual ~ServerActiveObject() = default; virtual ActiveObjectType getSendType() const @@ -82,18 +82,18 @@ class ServerActiveObject : public ActiveObject /* Some simple getters/setters */ - v3f getBasePosition() const { return m_base_position; } - void setBasePosition(v3f pos){ m_base_position = pos; } + v3opos_t getBasePosition() const { return m_base_position; } + void setBasePosition(v3opos_t pos){ m_base_position = pos; } ServerEnvironment* getEnv(){ return m_env; } /* Some more dynamic interface */ - virtual void setPos(const v3f &pos) + virtual void setPos(const v3opos_t &pos) { setBasePosition(pos); } // continuous: if true, object does not stop immediately at pos - virtual void moveTo(v3f pos, bool continuous) + virtual void moveTo(v3opos_t pos, bool continuous) { setBasePosition(pos); } // If object has moved less than this and data has not changed, // saving to disk may be omitted @@ -243,7 +243,7 @@ class ServerActiveObject : public ActiveObject virtual void onDetach(int parent_id) {} ServerEnvironment *m_env; - v3f m_base_position; + v3opos_t m_base_position; std::unordered_set m_attached_particle_spawners; /* diff --git a/src/server/unit_sao.cpp b/src/server/unit_sao.cpp index 9a49b0f437..a73970211e 100644 --- a/src/server/unit_sao.cpp +++ b/src/server/unit_sao.cpp @@ -22,7 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "scripting_server.h" #include "serverenvironment.h" -UnitSAO::UnitSAO(ServerEnvironment *env, v3f pos) : ServerActiveObject(env, pos) +UnitSAO::UnitSAO(ServerEnvironment *env, v3opos_t pos) : ServerActiveObject(env, pos) { // Initialize something to armor groups m_armor_groups["fleshy"] = 100; @@ -321,7 +321,7 @@ std::string UnitSAO::generateUpdateArmorGroupsCommand() const return os.str(); } -std::string UnitSAO::generateUpdatePositionCommand(const v3f &position, +std::string UnitSAO::generateUpdatePositionCommand(const v3opos_t &position, const v3f &velocity, const v3f &acceleration, const v3f &rotation, bool do_interpolate, bool is_movement_end, f32 update_interval) { @@ -329,7 +329,7 @@ std::string UnitSAO::generateUpdatePositionCommand(const v3f &position, // command writeU8(os, AO_CMD_UPDATE_POSITION); // pos - writeV3F32(os, position); + writeV3O(os, position); // velocity writeV3F32(os, velocity); // acceleration diff --git a/src/server/unit_sao.h b/src/server/unit_sao.h index a21e055c56..8d55defc80 100644 --- a/src/server/unit_sao.h +++ b/src/server/unit_sao.h @@ -26,7 +26,7 @@ with this program; if not, write to the Free Software Foundation, Inc., class UnitSAO : public ServerActiveObject { public: - UnitSAO(ServerEnvironment *env, v3f pos); + UnitSAO(ServerEnvironment *env, v3opos_t pos); virtual ~UnitSAO() = default; u16 getHP() const { return m_hp; } @@ -83,7 +83,7 @@ class UnitSAO : public ServerActiveObject std::string generateUpdateAnimationSpeedCommand() const; std::string generateUpdateAnimationCommand() const; std::string generateUpdateArmorGroupsCommand() const; - static std::string generateUpdatePositionCommand(const v3f &position, + static std::string generateUpdatePositionCommand(const v3opos_t &position, const v3f &velocity, const v3f &acceleration, const v3f &rotation, bool do_interpolate, bool is_movement_end, f32 update_interval); std::string generateSetPropertiesCommand(const ObjectProperties &prop) const; diff --git a/src/serverenvironment.cpp b/src/serverenvironment.cpp index 6efe145ba3..553ef4364d 100644 --- a/src/serverenvironment.cpp +++ b/src/serverenvironment.cpp @@ -308,7 +308,7 @@ void fillRadiusBlock(v3bpos_t p0, s16 r, std::set &list) void fillViewConeBlock(v3bpos_t p0, const s16 r, - const v3f camera_pos, + const v3opos_t camera_pos, const v3f camera_dir, const float camera_fov, std::set &list) @@ -1716,13 +1716,13 @@ bool ServerEnvironment::getActiveObjectMessage(ActiveObjectMessage *dest) } void ServerEnvironment::getSelectedActiveObjects( - const core::line3d &shootline_on_map, + const core::line3d &shootline_on_map, std::vector &objects) { std::vector objs; getObjectsInsideRadius(objs, shootline_on_map.start, shootline_on_map.getLength() + 10.0f, nullptr); - const v3f line_vector = shootline_on_map.getVector(); + const auto line_vector = shootline_on_map.getVector(); for (auto obj : objs) { if (obj->isGone()) @@ -1731,12 +1731,12 @@ void ServerEnvironment::getSelectedActiveObjects( if (!obj->getSelectionBox(&selection_box)) continue; - v3f pos = obj->getBasePosition(); + auto pos = obj->getBasePosition(); - aabb3f offsetted_box(selection_box.MinEdge + pos, - selection_box.MaxEdge + pos); + aabb3o offsetted_box(v3fToOpos(selection_box.MinEdge) + pos, + v3fToOpos(selection_box.MaxEdge) + pos); - v3f current_intersection; + v3opos_t current_intersection; v3pos_t current_normal; if (boxLineCollision(offsetted_box, shootline_on_map.start, line_vector, ¤t_intersection, ¤t_normal)) { @@ -1766,7 +1766,7 @@ u16 ServerEnvironment::addActiveObjectRaw(ServerActiveObject *object, // Add static data to block if (object->isStaticAllowed()) { // Add static object to active static list of the block - v3f objectpos = object->getBasePosition(); + auto objectpos = object->getBasePosition(); StaticObject s_obj(object, objectpos); // Add to the block where the object is located in v3bpos_t blockpos = getNodeBlockPos(floatToInt(objectpos, BS)); @@ -1895,7 +1895,7 @@ static void print_hexdump(std::ostream &o, const std::string &data) } } -ServerActiveObject* ServerEnvironment::createSAO(ActiveObjectType type, v3f pos, +ServerActiveObject* ServerEnvironment::createSAO(ActiveObjectType type, v3opos_t pos, const std::string &data) { switch (type) { @@ -2002,7 +2002,7 @@ void ServerEnvironment::deactivateFarObjects(bool _force_delete) if (!force_delete && obj->isGone()) return false; - const v3f &objectpos = obj->getBasePosition(); + const auto &objectpos = obj->getBasePosition(); // The block in which the object resides in v3bpos_t blockpos_o = getNodeBlockPos(floatToInt(objectpos, BS)); diff --git a/src/serverenvironment.h b/src/serverenvironment.h index 8d6eda880d..b095ba917e 100644 --- a/src/serverenvironment.h +++ b/src/serverenvironment.h @@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "activeobject.h" #include "environment.h" +#include "irr_v3d.h" #include "mapnode.h" #include "settings.h" #include "server/activeobjectmgr.h" @@ -290,7 +291,7 @@ class ServerEnvironment : public Environment bool getActiveObjectMessage(ActiveObjectMessage *dest); virtual void getSelectedActiveObjects( - const core::line3d &shootline_on_map, + const core::line3d &shootline_on_map, std::vector &objects ); @@ -322,14 +323,14 @@ class ServerEnvironment : public Environment u8 findSunlight(v3pos_t pos) const; // Find all active objects inside a radius around a point - void getObjectsInsideRadius(std::vector &objects, const v3f &pos, float radius, + void getObjectsInsideRadius(std::vector &objects, const v3opos_t &pos, float radius, std::function include_obj_cb) { return m_ao_manager.getObjectsInsideRadius(pos, radius, objects, include_obj_cb); } // Find all active objects inside a box - void getObjectsInArea(std::vector &objects, const aabb3f &box, + void getObjectsInArea(std::vector &objects, const aabb3o &box, std::function include_obj_cb) { return m_ao_manager.getObjectsInArea(box, objects, include_obj_cb); @@ -487,5 +488,5 @@ class ServerEnvironment : public Environment std::unordered_map m_particle_spawners; std::unordered_map m_particle_spawner_attachments; - ServerActiveObject* createSAO(ActiveObjectType type, v3f pos, const std::string &data); + ServerActiveObject* createSAO(ActiveObjectType type, v3opos_t pos, const std::string &data); }; diff --git a/src/settings.h b/src/settings.h index 003cd77a38..65ab5df96a 100644 --- a/src/settings.h +++ b/src/settings.h @@ -194,6 +194,9 @@ class Settings { bool getFloatNoEx(const std::string &name, float &val) const; bool getV2FNoEx(const std::string &name, v2f &val) const; bool getV3FNoEx(const std::string &name, v3f &val) const; +#if USE_POS32 + bool getV3FNoEx(const std::string &name, v3opos_t &val) const; +#endif // Like other getters, but handling each flag individualy: // 1) Read default flags (or 0) diff --git a/src/staticobject.cpp b/src/staticobject.cpp index 1160ec68f1..22c7c9b097 100644 --- a/src/staticobject.cpp +++ b/src/staticobject.cpp @@ -21,7 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "util/serialize.h" #include "server/serveractiveobject.h" -StaticObject::StaticObject(const ServerActiveObject *s_obj, const v3f &pos_): +StaticObject::StaticObject(const ServerActiveObject *s_obj, const v3opos_t &pos_): type(s_obj->getType()), pos(pos_) { @@ -33,7 +33,7 @@ void StaticObject::serialize(std::ostream &os) // type writeU8(os, type); // pos - writeV3F1000(os, pos); + writeV3F1000(os, oposToV3f(pos)); //TODO // data os< result; - saomgr.getObjectsInsideRadius(v3f(), 50, result, nullptr); + saomgr.getObjectsInsideRadius(v3opos_t(), 50, result, nullptr); UASSERTCMP(int, ==, result.size(), 1); result.clear(); - saomgr.getObjectsInsideRadius(v3f(), 750, result, nullptr); + saomgr.getObjectsInsideRadius(v3opos_t(), 750, result, nullptr); UASSERTCMP(int, ==, result.size(), 2); result.clear(); - saomgr.getObjectsInsideRadius(v3f(), 750000, result, nullptr); + saomgr.getObjectsInsideRadius(v3opos_t(), 750000, result, nullptr); UASSERTCMP(int, ==, result.size(), 5); result.clear(); @@ -165,7 +165,7 @@ void TestServerActiveObjectMgr::testGetObjectsInsideRadius() return (obj->getBasePosition().X != 10); }; - saomgr.getObjectsInsideRadius(v3f(), 750000, result, include_obj_cb); + saomgr.getObjectsInsideRadius(v3opos_t(), 750000, result, include_obj_cb); UASSERTCMP(int, ==, result.size(), 4); clearSAOMgr(&saomgr); @@ -174,12 +174,12 @@ void TestServerActiveObjectMgr::testGetObjectsInsideRadius() void TestServerActiveObjectMgr::testGetAddedActiveObjectsAroundPos() { server::ActiveObjectMgr saomgr; - static const v3f sao_pos[] = { - v3f(10, 40, 10), - v3f(740, 100, -304), - v3f(-200, 100, -304), - v3f(740, -740, -304), - v3f(1500, -740, -304), + static const v3opos_t sao_pos[] = { + v3opos_t(10, 40, 10), + v3opos_t(740, 100, -304), + v3opos_t(-200, 100, -304), + v3opos_t(740, -740, -304), + v3opos_t(1500, -740, -304), }; for (const auto &p : sao_pos) { @@ -188,12 +188,12 @@ void TestServerActiveObjectMgr::testGetAddedActiveObjectsAroundPos() std::queue result; std::set cur_objects; - saomgr.getAddedActiveObjectsAroundPos(v3f(), 100, 50, cur_objects, result); + saomgr.getAddedActiveObjectsAroundPos(v3opos_t(), 100, 50, cur_objects, result); UASSERTCMP(int, ==, result.size(), 1); result = std::queue(); cur_objects.clear(); - saomgr.getAddedActiveObjectsAroundPos(v3f(), 740, 50, cur_objects, result); + saomgr.getAddedActiveObjectsAroundPos(v3opos_t(), 740, 50, cur_objects, result); UASSERTCMP(int, ==, result.size(), 2); clearSAOMgr(&saomgr); diff --git a/src/unittest/test_voxelalgorithms.cpp b/src/unittest/test_voxelalgorithms.cpp index cbc6b4db7a..ff956e9833 100644 --- a/src/unittest/test_voxelalgorithms.cpp +++ b/src/unittest/test_voxelalgorithms.cpp @@ -49,22 +49,22 @@ void TestVoxelAlgorithms::testVoxelLineIterator(const NodeDefManager *ndef) // Test some lines // Do not test lines that start or end on the border of // two voxels as rounding errors can make the test fail! - std::vector > lines; - for (f32 x = -9.1; x < 9; x += 3.124) { - for (f32 y = -9.2; y < 9; y += 3.123) { - for (f32 z = -9.3; z < 9; z += 3.122) { + std::vector > lines; + for (opos_t x = -9.1; x < 9; x += 3.124) { + for (opos_t y = -9.2; y < 9; y += 3.123) { + for (opos_t z = -9.3; z < 9; z += 3.122) { lines.emplace_back(-x, -y, -z, x, y, z); } } } lines.emplace_back(0, 0, 0, 0, 0, 0); // Test every line - std::vector >::iterator it = lines.begin(); + std::vector >::iterator it = lines.begin(); for (; it < lines.end(); it++) { - core::line3d l = *it; + core::line3d l = *it; // Initialize test - voxalgo::VoxelLineIterator iterator(l.start, l.getVector()); + voxalgo::VoxelLineIterator iterator(l.start, oposToV3f(l.getVector())); //Test the first voxel v3pos_t start_voxel = floatToInt(l.start, 1); @@ -85,9 +85,9 @@ void TestVoxelAlgorithms::testVoxelLineIterator(const NodeDefManager *ndef) // This must be a neighbor of the old voxel UASSERTEQ(f32, (new_voxel - old_voxel).getLengthSQ(), 1); // The line must intersect with the voxel - v3f voxel_center = intToFloat(iterator.m_current_node_pos, 1); - aabb3f box(voxel_center - v3f(0.5, 0.5, 0.5), - voxel_center + v3f(0.5, 0.5, 0.5)); + v3opos_t voxel_center = posToOpos(iterator.m_current_node_pos, (f32)1); + aabb3o box(voxel_center - v3opos_t(0.5, 0.5, 0.5), + voxel_center + v3opos_t(0.5, 0.5, 0.5)); UASSERT(box.intersectsWithLine(l)); // Update old voxel old_voxel = new_voxel; diff --git a/src/util/directiontables.cpp b/src/util/directiontables.cpp index 0d6f7d0abc..d9452f75b7 100644 --- a/src/util/directiontables.cpp +++ b/src/util/directiontables.cpp @@ -30,6 +30,17 @@ const v3pos_t g_6dirs[6] = v3pos_t(-1, 0, 0) // left }; +const v3bpos_t g_6dirs_b[6] = +{ + // +right, +top, +back + v3bpos_t( 0, 0, 1), // back + v3bpos_t( 0, 1, 0), // top + v3bpos_t( 1, 0, 0), // right + v3bpos_t( 0, 0,-1), // front + v3bpos_t( 0,-1, 0), // bottom + v3bpos_t(-1, 0, 0) // left +}; + const v3pos_t g_7dirs[7] = { v3pos_t(0,0,1), // back diff --git a/src/util/directiontables.h b/src/util/directiontables.h index 9f51fb6010..9139fcb9a2 100644 --- a/src/util/directiontables.h +++ b/src/util/directiontables.h @@ -23,6 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "irr_v3d.h" extern const v3pos_t g_6dirs[6]; +extern const v3bpos_t g_6dirs_b[6]; extern const v3pos_t g_7dirs[7]; diff --git a/src/util/numeric.cpp b/src/util/numeric.cpp index 45686fe4b1..29d7313843 100644 --- a/src/util/numeric.cpp +++ b/src/util/numeric.cpp @@ -103,23 +103,23 @@ u64 murmur_hash_64_ua(const void *key, int len, unsigned int seed) range: viewing range distance_ptr: return location for distance from the camera */ -bool isBlockInSight(v3pos_t blockpos_b, v3f camera_pos, v3f camera_dir, +bool isBlockInSight(v3pos_t blockpos_b, v3opos_t camera_pos, v3f camera_dir, f32 camera_fov, f32 range, f32 *distance_ptr) { v3pos_t blockpos_nodes = blockpos_b * MAP_BLOCKSIZE; // Block center position - v3f blockpos( - ((float)blockpos_nodes.X + MAP_BLOCKSIZE/2) * BS, - ((float)blockpos_nodes.Y + MAP_BLOCKSIZE/2) * BS, - ((float)blockpos_nodes.Z + MAP_BLOCKSIZE/2) * BS + v3opos_t blockpos( + ((opos_t)blockpos_nodes.X + MAP_BLOCKSIZE/2) * BS, + ((opos_t)blockpos_nodes.Y + MAP_BLOCKSIZE/2) * BS, + ((opos_t)blockpos_nodes.Z + MAP_BLOCKSIZE/2) * BS ); // Block position relative to camera - v3f blockpos_relative = blockpos - camera_pos; + auto blockpos_relative = blockpos - camera_pos; // Total distance - f32 d = MYMAX(0, blockpos_relative.getLength() - BLOCK_MAX_RADIUS); + auto d = MYMAX(0, blockpos_relative.getLength() - BLOCK_MAX_RADIUS); if (distance_ptr) *distance_ptr = d; @@ -140,10 +140,10 @@ bool isBlockInSight(v3pos_t blockpos_b, v3f camera_pos, v3f camera_dir, f32 adjdist = BLOCK_MAX_RADIUS / cos((M_PI - camera_fov) / 2); // Block position relative to adjusted camera - v3f blockpos_adj = blockpos - (camera_pos - camera_dir * adjdist); + auto blockpos_adj = blockpos - (camera_pos - v3fToOpos(camera_dir) * adjdist); // Distance in camera direction (+=front, -=back) - f32 dforward = blockpos_adj.dotProduct(camera_dir); + auto dforward = blockpos_adj.dotProduct(v3fToOpos(camera_dir)); // Cosine of the angle between the camera direction // and the block direction (camera_dir is an unit vector) diff --git a/src/util/numeric.h b/src/util/numeric.h index 172495d7bc..e905a3cd1c 100644 --- a/src/util/numeric.h +++ b/src/util/numeric.h @@ -135,6 +135,17 @@ inline void sortBoxVerticies(v3pos_t &p1, v3pos_t &p2) { SWAP(pos_t, p1.Z, p2.Z); } + /* +inline void sortBoxVerticies(v3bpos_t &p1, v3bpos_t &p2) { + if (p1.X > p2.X) + SWAP(bpos_t, p1.X, p2.X); + if (p1.Y > p2.Y) + SWAP(bpos_t, p1.Y, p2.Y); + if (p1.Z > p2.Z) + SWAP(bpos_t, p1.Z, p2.Z); +} + */ + inline v3pos_t componentwise_min(const v3pos_t &a, const v3pos_t &b) { return v3pos_t(MYMIN(a.X, b.X), MYMIN(a.Y, b.Y), MYMIN(a.Z, b.Z)); @@ -252,7 +263,7 @@ inline u32 calc_parity(u32 v) u64 murmur_hash_64_ua(const void *key, int len, unsigned int seed); -bool isBlockInSight(v3bpos_t blockpos_b, v3f camera_pos, v3f camera_dir, +bool isBlockInSight(v3bpos_t blockpos_b, v3opos_t camera_pos, v3f camera_dir, f32 camera_fov, f32 range, f32 *distance_ptr=NULL); s16 adjustDist(s16 dist, float zoom_fov); @@ -301,10 +312,28 @@ inline v3pos_t doubleToPos(v3d p, double d) (p.Z + (p.Z > 0 ? d / 2 : -d / 2)) / d); } +inline v3pos_t floatToInt(v3d p, f32 d) +{ + return v3pos_t( + (p.X + (p.X > 0 ? d / 2 : -d / 2)) / d, + (p.Y + (p.Y > 0 ? d / 2 : -d / 2)) / d, + (p.Z + (p.Z > 0 ? d / 2 : -d / 2)) / d); +} + + +inline v3pos_t oposToPos(v3opos_t p, double d) +{ + return v3pos_t( + (p.X + (p.X > 0 ? d / 2 : -d / 2)) / d, + (p.Y + (p.Y > 0 ? d / 2 : -d / 2)) / d, + (p.Z + (p.Z > 0 ? d / 2 : -d / 2)) / d); +} + /* Returns floating point position of node in given integer position */ -inline v3f intToFloat(v3pos_t p, f32 d) + +inline v3f intToFloat(v3s16 p, f32 d) { return v3f( (f32)p.X * d, @@ -313,6 +342,75 @@ inline v3f intToFloat(v3pos_t p, f32 d) ); } +#if USE_POS32 +inline v3opos_t intToFloat(const v3pos_t & p, const opos_t d) +{ + return v3opos_t( + (opos_t)p.X * d, + (opos_t)p.Y * d, + (opos_t)p.Z * d + ); +} +#endif + +inline v3f posToFloat(const v3pos_t & p, f32 d) +{ + return v3f( + (f32)p.X * d, + (f32)p.Y * d, + (f32)p.Z * d + ); +} + +inline v3opos_t posToOpos(const v3pos_t & p, const opos_t d) +{ + return v3opos_t( + (opos_t)p.X * d, + (opos_t)p.Y * d, + (opos_t)p.Z * d + ); +} + +inline v3opos_t v3fToOpos(const v3f & p) +{ + return v3opos_t(p.X, p.Y, p.Z); +} + +inline v3f oposToV3f(const v3opos_t & p) +{ + return v3f(p.X, p.Y, p.Z); +} + + /* +inline v3f intToFloat(v3bpos_t p, f32 d) +{ + return v3f( + (f32)p.X * d, + (f32)p.Y * d, + (f32)p.Z * d + ); +} + */ + +inline v3s16 posToS16(const v3pos_t & p) +{ +#if USE_POS32 + return v3s16(p.X, p.Y, p.Z); +#else + return p; +#endif +} + +inline v3pos_t s16ToPos(const v3s16 & p) +{ +#if USE_POS32 + return v3pos_t(p.X, p.Y, p.Z); +#else + return p; +#endif +} + + // Random helper. Usually d=BS inline aabb3f getNodeBox(v3pos_t p, float d) { @@ -326,6 +424,19 @@ inline aabb3f getNodeBox(v3pos_t p, float d) ); } +#if USE_POS32 +inline aabb3o getNodeBox(v3pos_t p, opos_t d) +{ + return aabb3o( + (opos_t)p.X * d - 0.5f * d, + (opos_t)p.Y * d - 0.5f * d, + (opos_t)p.Z * d - 0.5f * d, + (opos_t)p.X * d + 0.5f * d, + (opos_t)p.Y * d + 0.5f * d, + (opos_t)p.Z * d + 0.5f * d + ); +} +#endif class IntervalLimiter { diff --git a/src/util/pointedthing.cpp b/src/util/pointedthing.cpp index ceed42b641..469246cc62 100644 --- a/src/util/pointedthing.cpp +++ b/src/util/pointedthing.cpp @@ -24,7 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include PointedThing::PointedThing(const v3pos_t &under, const v3pos_t &above, - const v3pos_t &real_under, const v3f &point, const v3pos_t &normal, + const v3pos_t &real_under, const v3opos_t &point, const v3pos_t &normal, u16 box_id, f32 distSq): type(POINTEDTHING_NODE), node_undersurface(under), @@ -36,7 +36,7 @@ PointedThing::PointedThing(const v3pos_t &under, const v3pos_t &above, distanceSq(distSq) {} -PointedThing::PointedThing(s16 id, const v3f &point, const v3pos_t &normal, +PointedThing::PointedThing(s16 id, const v3opos_t &point, const v3pos_t &normal, f32 distSq) : type(POINTEDTHING_OBJECT), object_id(id), diff --git a/src/util/pointedthing.h b/src/util/pointedthing.h index 42e767d072..8a7030fd7b 100644 --- a/src/util/pointedthing.h +++ b/src/util/pointedthing.h @@ -67,7 +67,7 @@ struct PointedThing * First intersection point of the ray and the nodebox in irrlicht * coordinates. */ - v3f intersection_point; + v3opos_t intersection_point; /*! * Only valid if type isn't POINTEDTHING_NONE. * Normal vector of the intersection. @@ -90,10 +90,10 @@ struct PointedThing PointedThing() = default; //! Constructor for POINTEDTHING_NODE PointedThing(const v3pos_t &under, const v3pos_t &above, - const v3pos_t &real_under, const v3f &point, const v3pos_t &normal, + const v3pos_t &real_under, const v3opos_t &point, const v3pos_t &normal, u16 box_id, f32 distSq); //! Constructor for POINTEDTHING_OBJECT - PointedThing(s16 id, const v3f &point, const v3pos_t &normal, f32 distSq); + PointedThing(s16 id, const v3opos_t &point, const v3pos_t &normal, f32 distSq); std::string dump() const; void serialize(std::ostream &os) const; void deSerialize(std::istream &is); diff --git a/src/util/serialize.h b/src/util/serialize.h index 929fb42ded..0967570fa4 100644 --- a/src/util/serialize.h +++ b/src/util/serialize.h @@ -23,6 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "exceptions.h" // for SerializationError #include "debug.h" // for assert #include "ieee_float.h" +#include "numeric.h" #include "config.h" #if HAVE_ENDIAN_H @@ -210,6 +211,14 @@ inline f32 readF32(const u8 *data) throw SerializationError("readF32: Unreachable code"); } +inline f64 readF64(const u8 *data) +{ + u64 u = readU64(data); + f64 f; + memcpy(&f, &u, 8); + return f; +} + inline video::SColor readARGB8(const u8 *data) { video::SColor p(readU32(data)); @@ -276,6 +285,15 @@ inline v3f readV3F32(const u8 *data) return p; } +inline v3d readV3F64(const u8 *data) +{ + v3d p; + p.X = readF64(&data[0]); + p.Y = readF64(&data[8]); + p.Z = readF64(&data[16]); + return p; +} + /////////////// write routines //////////////// inline void writeU8(u8 *data, u8 i) @@ -326,6 +344,13 @@ inline void writeF32(u8 *data, f32 i) throw SerializationError("writeF32: Unreachable code"); } +inline void writeF64(u8 *data, double i) +{ + u64 u; + memcpy(&u, &i, 8); + return writeU64(data, u); +} + inline void writeARGB8(u8 *data, video::SColor p) { writeU32(data, p.color); @@ -377,6 +402,13 @@ inline void writeV3F32(u8 *data, v3f p) writeF32(&data[8], p.Z); } +inline void writeV3F64(u8 *data, v3d p) +{ + writeF64(&data[0], p.X); + writeF64(&data[8], p.Y); + writeF64(&data[16], p.Z); +} + //// //// Iostream wrapper for data read/write //// @@ -414,6 +446,7 @@ MAKE_STREAM_READ_FXN(v3s32, V3S32, 12); MAKE_STREAM_READ_FXN(v3f, V3F1000, 12); MAKE_STREAM_READ_FXN(v2f, V2F32, 8); MAKE_STREAM_READ_FXN(v3f, V3F32, 12); +MAKE_STREAM_READ_FXN(v3d, V3F64, 24); MAKE_STREAM_READ_FXN(video::SColor, ARGB8, 4); MAKE_STREAM_WRITE_FXN(u8, U8, 1); @@ -433,6 +466,7 @@ MAKE_STREAM_WRITE_FXN(v3s32, V3S32, 12); MAKE_STREAM_WRITE_FXN(v3f, V3F1000, 12); MAKE_STREAM_WRITE_FXN(v2f, V2F32, 8); MAKE_STREAM_WRITE_FXN(v3f, V3F32, 12); +MAKE_STREAM_WRITE_FXN(v3d, V3F64, 24); MAKE_STREAM_WRITE_FXN(video::SColor, ARGB8, 4); inline pos_t readPOS(std::istream &is) { @@ -467,6 +501,22 @@ inline void writeV3POS(std::ostream &os, v3pos_t p) { #endif } +inline v3opos_t readV3O(std::istream &is) { +#if USE_POS32 + return readV3F64(is); +#else + return readV3F32(is); +#endif +} + +inline void writeV3O(std::ostream &os, v3opos_t p) { +#if USE_POS32 + return writeV3F64(os, p); +#else + return writeV3F32(os, p); +#endif +} + //// //// More serialization stuff //// diff --git a/src/voxelalgorithms.cpp b/src/voxelalgorithms.cpp index 454051102a..a44e74d84d 100644 --- a/src/voxelalgorithms.cpp +++ b/src/voxelalgorithms.cpp @@ -1263,13 +1263,13 @@ void repair_block_light(ServerMap *map, MapBlock *block, modified_blocks); } -VoxelLineIterator::VoxelLineIterator(const v3f &start_position, const v3f &line_vector) : +VoxelLineIterator::VoxelLineIterator(const v3opos_t &start_position, const v3f &line_vector) : m_start_position(start_position), m_line_vector(line_vector) { m_current_node_pos = floatToInt(m_start_position, 1); m_start_node_pos = m_current_node_pos; - m_last_index = getIndex(floatToInt(start_position + line_vector, 1)); + m_last_index = getIndex(floatToInt(start_position + v3fToOpos(line_vector), 1)); if (m_line_vector.X > 0) { m_next_intersection_multi.X = (floorf(m_start_position.X - 0.5) + 1.5 diff --git a/src/voxelalgorithms.h b/src/voxelalgorithms.h index c1d4871ad5..bb85767e48 100644 --- a/src/voxelalgorithms.h +++ b/src/voxelalgorithms.h @@ -90,7 +90,7 @@ struct VoxelLineIterator { public: //! Starting position of the line in world coordinates. - v3f m_start_position; + v3opos_t m_start_position; //! Direction and length of the line in world coordinates. v3f m_line_vector; /*! @@ -126,7 +126,7 @@ struct VoxelLineIterator * line in voxel coordinates. start_position+line_vector * is the end of the line */ - VoxelLineIterator(const v3f &start_position,const v3f &line_vector); + VoxelLineIterator(const v3opos_t &start_position,const v3f &line_vector); /*! * Steps to the next voxel. From 6f473552e5df7e99d06624f6fe2100361e904c83 Mon Sep 17 00:00:00 2001 From: proller Date: Fri, 31 Dec 2021 00:52:26 +0300 Subject: [PATCH 12/36] Fixes --- src/client/content_cao.cpp | 2 +- src/script/lua_api/l_env.cpp | 8 ++++---- src/server/player_sao.cpp | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/client/content_cao.cpp b/src/client/content_cao.cpp index ac550564c0..6b45e9fa1f 100644 --- a/src/client/content_cao.cpp +++ b/src/client/content_cao.cpp @@ -1714,7 +1714,7 @@ void GenericCAO::processMessage(const std::string &data) } else if (cmd == AO_CMD_UPDATE_POSITION) { // Not sent by the server if this object is an attachment. // We might however get here if the server notices the object being detached before the client. - m_position = v3fToOpos(readV3F32(is)); //TODO f64 + m_position = readV3O(is); m_velocity = readV3F32(is); m_acceleration = readV3F32(is); m_rotation = readV3F32(is); diff --git a/src/script/lua_api/l_env.cpp b/src/script/lua_api/l_env.cpp index b81c6b4ef7..c367f822a3 100644 --- a/src/script/lua_api/l_env.cpp +++ b/src/script/lua_api/l_env.cpp @@ -176,8 +176,8 @@ int LuaRaycast::create_object(lua_State *L) bool objects = true; bool liquids = false; - auto pos1 = check_v3o(L, 1); - auto pos2 = check_v3o(L, 2); + auto pos1 = checkOposPos(L, 1); + auto pos2 = checkOposPos(L, 2); if (lua_isboolean(L, 3)) { objects = readParam(L, 3); } @@ -638,7 +638,7 @@ int ModApiEnvMod::l_add_entity(lua_State *L) { GET_ENV_PTR; - auto pos = check_v3o(L, 1); + auto pos = checkOposPos(L, 1); const char *name = luaL_checkstring(L, 2); const char *staticdata = luaL_optstring(L, 3, ""); @@ -1130,7 +1130,7 @@ int ModApiEnvMod::l_line_of_sight(lua_State *L) GET_PLAIN_ENV_PTR; // read position 1 from lua - v3opos_t pos1 = check_v3o(L, 1); + v3opos_t pos1 = checkOposPos(L, 1); // read position 2 from lua v3f pos2 = checkFloatPos(L, 2); diff --git a/src/server/player_sao.cpp b/src/server/player_sao.cpp index 04369d53c0..0b5ef3c052 100644 --- a/src/server/player_sao.cpp +++ b/src/server/player_sao.cpp @@ -113,7 +113,7 @@ std::string PlayerSAO::getClientInitializationData(u16 protocol_version) os << serializeString16(m_player->getName()); // name writeU8(os, 1); // is_player writeS16(os, getId()); // id - writeV3F32(os, oposToV3f(m_base_position)); // todo writeV3F64 + writeV3O(os, m_base_position); writeV3F32(os, m_rotation); writeU16(os, getHP()); From f7eae54668714d0f2a9dd20cfde3229cc035e819 Mon Sep 17 00:00:00 2001 From: proller Date: Fri, 31 Dec 2021 01:07:11 +0300 Subject: [PATCH 13/36] static pos save --- src/staticobject.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/staticobject.cpp b/src/staticobject.cpp index 22c7c9b097..7f3855bbcb 100644 --- a/src/staticobject.cpp +++ b/src/staticobject.cpp @@ -33,7 +33,11 @@ void StaticObject::serialize(std::ostream &os) // type writeU8(os, type); // pos - writeV3F1000(os, oposToV3f(pos)); //TODO +#if USE_POS32 + writeV3O(os, pos); +#else + writeV3F1000(os, oposToV3f(pos)); +#endif // data os< Date: Fri, 31 Dec 2021 12:11:33 +0300 Subject: [PATCH 14/36] Better --- src/map.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/map.cpp b/src/map.cpp index 1fe9dcc01c..26cfcd1f7d 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -1198,6 +1198,9 @@ ServerMap::ServerMap(const std::string &savedir, IGameDef *gamedef, if (!succeeded || !conf.exists("backend")) { // fall back to sqlite3 conf.set("backend", "sqlite3"); +#if USE_POS32 && USE_LEVELDB + conf.set("backend", "leveldb"); +#endif } std::string backend = conf.get("backend"); dbase = createDatabase(backend, savedir, conf); From 7bdf5d0c7cc175f70231774e5769105734a248a6 Mon Sep 17 00:00:00 2001 From: proller Date: Fri, 31 Dec 2021 12:13:03 +0300 Subject: [PATCH 15/36] clean --- src/constants.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/constants.h b/src/constants.h index 6720f284a0..d2497feb13 100644 --- a/src/constants.h +++ b/src/constants.h @@ -68,7 +68,6 @@ with this program; if not, write to the Free Software Foundation, Inc., // This is the maximum value the setting map_generation_limit can be #if USE_POS32 #define MAX_MAP_GENERATION_LIMIT (2147483008) -//#define MAX_MAP_GENERATION_LIMIT (31000) #else #define MAX_MAP_GENERATION_LIMIT (31000) #endif From c40b27dfc9a44f69606fbb4b930bb26c94d2f3f3 Mon Sep 17 00:00:00 2001 From: proller Date: Thu, 10 Feb 2022 02:08:41 +0300 Subject: [PATCH 16/36] upstream merge fix --- src/unittest/test_map.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/unittest/test_map.cpp b/src/unittest/test_map.cpp index 82e55e1aab..31b934471c 100644 --- a/src/unittest/test_map.cpp +++ b/src/unittest/test_map.cpp @@ -60,9 +60,9 @@ void TestMap::testMaxMapgenLimit() UASSERT(objectpos_over_limit(v3f(-limit_times_bs-BS)) == true); // blockpos_over_max_limit - s16 limit_block = MAX_MAP_GENERATION_LIMIT / MAP_BLOCKSIZE; - UASSERT(blockpos_over_max_limit(v3s16(limit_block)) == false); - UASSERT(blockpos_over_max_limit(v3s16(limit_block+1)) == true); - UASSERT(blockpos_over_max_limit(v3s16(-limit_block)) == false); - UASSERT(blockpos_over_max_limit(v3s16(-limit_block-1)) == true); + pos_t limit_block = MAX_MAP_GENERATION_LIMIT / MAP_BLOCKSIZE; + UASSERT(blockpos_over_max_limit(v3pos_t(limit_block)) == false); + UASSERT(blockpos_over_max_limit(v3pos_t(limit_block+1)) == true); + UASSERT(blockpos_over_max_limit(v3pos_t(-limit_block)) == false); + UASSERT(blockpos_over_max_limit(v3pos_t(-limit_block-1)) == true); } From e35ab6bfcc3aec4a7a5d9bfdab834596e9eab5ed Mon Sep 17 00:00:00 2001 From: proller Date: Thu, 10 Feb 2022 15:45:23 +0300 Subject: [PATCH 17/36] split USE_POS32 and USE_OPOS64 --- src/CMakeLists.txt | 3 ++- src/cmake_config.h.in | 1 + src/collision.cpp | 2 +- src/irrlichttypes.h | 9 ++++++--- src/mapblock.h | 2 +- src/script/common/c_converter.cpp | 4 ++-- src/settings.h | 2 +- src/util/numeric.h | 2 +- src/util/serialize.h | 4 ++-- 9 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7e94bae1c8..508ba9976f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -31,7 +31,8 @@ if(NOT (BUILD_CLIENT OR BUILD_SERVER)) set(BUILD_SERVER TRUE) endif() -option(USE_POS32 "32 bit positions (experimental, not compatible with 16 bit)" FALSE) +option(USE_POS32 "32 bit node/block positions (experimental, not compatible with 16 bit)" FALSE) +option(USE_OPOS64 "64 bit object positions (experimental, not compatible with 32 bit)" ${USE_POS32}) option(ENABLE_CURL "Enable cURL support for fetching media" TRUE) set(USE_CURL FALSE) diff --git a/src/cmake_config.h.in b/src/cmake_config.h.in index 7f728e3353..6b724cce62 100644 --- a/src/cmake_config.h.in +++ b/src/cmake_config.h.in @@ -36,3 +36,4 @@ #cmakedefine01 CURSES_HAVE_NCURSESW_CURSES_H #cmakedefine01 BUILD_UNITTESTS #cmakedefine01 USE_POS32 +#cmakedefine01 USE_OPOS64 diff --git a/src/collision.cpp b/src/collision.cpp index efc041be37..e98fb9140a 100644 --- a/src/collision.cpp +++ b/src/collision.cpp @@ -84,7 +84,7 @@ static inline v3f truncate(const v3f& vec, const f32 factor) ); } -#if USE_POS32 +#if USE_OPOS64 static inline v3opos_t truncate(const v3opos_t& vec, const f32 factor) { return v3opos_t( diff --git a/src/irrlichttypes.h b/src/irrlichttypes.h index 5e29a37412..a5716bbb8b 100644 --- a/src/irrlichttypes.h +++ b/src/irrlichttypes.h @@ -70,11 +70,14 @@ using pos_t = irr::s32; // Block position using bpos_t = irr::s32; -// Object position -using opos_t = double; - #else using pos_t = irr::s16; using bpos_t = irr::s16; +#endif + +#if USE_OPOS64 +// Object position +using opos_t = double; +#else using opos_t = float; #endif diff --git a/src/mapblock.h b/src/mapblock.h index 4264e7ce7a..058c32c197 100644 --- a/src/mapblock.h +++ b/src/mapblock.h @@ -611,7 +611,7 @@ inline bool objectpos_over_limit(v3f p) p.Z > max_limit_bs; } -#if USE_POS32 +#if USE_OPOS64 inline bool objectpos_over_limit(v3opos_t p) { const opos_t max_limit_bs = MAX_MAP_GENERATION_LIMIT * BS; diff --git a/src/script/common/c_converter.cpp b/src/script/common/c_converter.cpp index 2a9d7389aa..6c965f44ae 100644 --- a/src/script/common/c_converter.cpp +++ b/src/script/common/c_converter.cpp @@ -234,7 +234,7 @@ v3d read_v3d(lua_State *L, int index) v3opos_t read_v3o(lua_State *L, int index) { -#if USE_POS32 +#if USE_OPOS64 return read_v3d(L, index); #else return read_v3f(L, index); @@ -301,7 +301,7 @@ v3f checkFloatPos(lua_State *L, int index) v3opos_t check_v3o(lua_State *L, int index) { -#if USE_POS32 +#if USE_OPOS64 return check_v3d(L, index); #else return check_v3f(L, index); diff --git a/src/settings.h b/src/settings.h index 131be89c53..b0f9e808c7 100644 --- a/src/settings.h +++ b/src/settings.h @@ -197,7 +197,7 @@ class Settings { bool getFloatNoEx(const std::string &name, float &val) const; bool getV2FNoEx(const std::string &name, v2f &val) const; bool getV3FNoEx(const std::string &name, v3f &val) const; -#if USE_POS32 +#if USE_OPOS64 bool getV3FNoEx(const std::string &name, v3opos_t &val) const; #endif diff --git a/src/util/numeric.h b/src/util/numeric.h index e905a3cd1c..7265843f80 100644 --- a/src/util/numeric.h +++ b/src/util/numeric.h @@ -424,7 +424,7 @@ inline aabb3f getNodeBox(v3pos_t p, float d) ); } -#if USE_POS32 +#if USE_OPOS64 inline aabb3o getNodeBox(v3pos_t p, opos_t d) { return aabb3o( diff --git a/src/util/serialize.h b/src/util/serialize.h index 0967570fa4..c8529e84b4 100644 --- a/src/util/serialize.h +++ b/src/util/serialize.h @@ -502,7 +502,7 @@ inline void writeV3POS(std::ostream &os, v3pos_t p) { } inline v3opos_t readV3O(std::istream &is) { -#if USE_POS32 +#if USE_OPOS64 return readV3F64(is); #else return readV3F32(is); @@ -510,7 +510,7 @@ inline v3opos_t readV3O(std::istream &is) { } inline void writeV3O(std::ostream &os, v3opos_t p) { -#if USE_POS32 +#if USE_OPOS64 return writeV3F64(os, p); #else return writeV3F32(os, p); From dded77eb1892ef79158f7ccf537d6110a71d33fa Mon Sep 17 00:00:00 2001 From: proller Date: Thu, 10 Feb 2022 16:35:39 +0300 Subject: [PATCH 18/36] total split fix --- src/client/clientmap.cpp | 8 ++++---- src/client/hud.cpp | 8 ++++---- src/client/minimap.cpp | 4 ++-- src/rollback.cpp | 2 +- src/server.cpp | 2 +- src/util/numeric.h | 2 +- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/client/clientmap.cpp b/src/client/clientmap.cpp index a6d40b9dd5..68c1dcf016 100644 --- a/src/client/clientmap.cpp +++ b/src/client/clientmap.cpp @@ -437,7 +437,7 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass) TimeTaker draw("Drawing mesh buffers"); core::matrix4 m; // Model matrix - auto offset = intToFloat(m_camera_offset, BS); + auto offset = intToFloat(m_camera_offset, (opos_t)BS); u32 material_swaps = 0; // Render all mesh buffers in order @@ -470,7 +470,7 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass) ++material_swaps; } - auto block_wpos = intToFloat(descriptor.m_pos * MAP_BLOCKSIZE, BS); + auto block_wpos = intToFloat(descriptor.m_pos * MAP_BLOCKSIZE, (opos_t)BS); m.setTranslation(oposToV3f(block_wpos - offset)); driver->setTransform(video::ETS_WORLD, m); @@ -752,7 +752,7 @@ void ClientMap::renderMapShadows(video::IVideoDriver *driver, TimeTaker draw("Drawing shadow mesh buffers"); core::matrix4 m; // Model matrix - auto offset = intToFloat(m_camera_offset, BS); + auto offset = intToFloat(m_camera_offset, (opos_t)BS); // Render all layers in order for (auto &lists : drawbufs.lists) { @@ -775,7 +775,7 @@ void ClientMap::renderMapShadows(video::IVideoDriver *driver, local_material.Lighting = false; driver->setMaterial(local_material); - auto block_wpos = intToFloat(pair.first * MAP_BLOCKSIZE, BS); + auto block_wpos = intToFloat(pair.first * MAP_BLOCKSIZE, (opos_t)BS); m.setTranslation(oposToV3f(block_wpos - offset)); driver->setTransform(video::ETS_WORLD, m); diff --git a/src/client/hud.cpp b/src/client/hud.cpp index 20e1f48dc8..162ea7a9e6 100644 --- a/src/client/hud.cpp +++ b/src/client/hud.cpp @@ -319,7 +319,7 @@ bool Hud::calculateScreenPos(const v3pos_t &camera_offset, HudElement *e, v2s32 v3opos_t w_pos_o = v3fToOpos(e->world_pos) * BS; scene::ICameraSceneNode* camera = client->getSceneManager()->getActiveCamera(); - auto w_pos = oposToV3f(w_pos_o - intToFloat(camera_offset, BS)); + auto w_pos = oposToV3f(w_pos_o - intToFloat(camera_offset, (opos_t)BS)); core::matrix4 trans = camera->getProjectionMatrix(); trans *= camera->getViewMatrix(); f32 transformed_pos[4] = { w_pos.X, w_pos.Y, w_pos.Z, 1.0f }; @@ -898,7 +898,7 @@ void Hud::drawBlockBounds() floorf((float) pos.Z / MAP_BLOCKSIZE) ); - auto offset = intToFloat(client->getCamera()->getOffset(), BS); + auto offset = intToFloat(client->getCamera()->getOffset(), (opos_t)BS); s8 radius = m_block_bounds_mode == BLOCK_BOUNDS_NEAR ? 2 : 0; @@ -910,8 +910,8 @@ void Hud::drawBlockBounds() v3pos_t blockOffset(x, y, z); aabb3f box( - oposToV3f(intToFloat((blockPos + blockOffset) * MAP_BLOCKSIZE, BS) - offset) - halfNode, - oposToV3f(intToFloat(((blockPos + blockOffset) * MAP_BLOCKSIZE) + (MAP_BLOCKSIZE - 1), BS) - offset) + halfNode + oposToV3f(intToFloat((blockPos + blockOffset) * MAP_BLOCKSIZE, (opos_t)BS) - offset) - halfNode, + oposToV3f(intToFloat(((blockPos + blockOffset) * MAP_BLOCKSIZE) + (MAP_BLOCKSIZE - 1), (opos_t)BS) - offset) + halfNode ); driver->draw3DBox(box, video::SColor(255, 255, 0, 0)); diff --git a/src/client/minimap.cpp b/src/client/minimap.cpp index 6b663dcba3..8f6bd9e1c0 100644 --- a/src/client/minimap.cpp +++ b/src/client/minimap.cpp @@ -704,14 +704,14 @@ void Minimap::updateActiveMarkers() data->minimap_mask_round : data->minimap_mask_square; m_active_markers.clear(); - auto cam_offset = intToFloat(client->getCamera()->getOffset(), BS); + auto cam_offset = intToFloat(client->getCamera()->getOffset(), (opos_t)BS); v3pos_t pos_offset = data->pos - v3pos_t(data->mode.map_size / 2, data->mode.scan_height / 2, data->mode.map_size / 2); for (MinimapMarker *marker : m_markers) { v3pos_t pos = floatToInt(v3fToOpos(marker->parent_node->getAbsolutePosition()) + - cam_offset, BS) - pos_offset; + cam_offset, (opos_t)BS) - pos_offset; if (pos.X < 0 || pos.X > data->mode.map_size || pos.Y < 0 || pos.Y > data->mode.scan_height || pos.Z < 0 || pos.Z > data->mode.map_size) { diff --git a/src/rollback.cpp b/src/rollback.cpp index 211413985a..7d3fab45f5 100644 --- a/src/rollback.cpp +++ b/src/rollback.cpp @@ -804,7 +804,7 @@ float RollbackManager::getSuspectNearness(bool is_guess, v3pos_t suspect_p, // Start from 100 int f = 100; // Distance (1 node = -x points) - f -= POINTS_PER_NODE * intToFloat(suspect_p, 1).getDistanceFrom(intToFloat(action_p, 1)); + f -= POINTS_PER_NODE * intToFloat(suspect_p, (float)1).getDistanceFrom(intToFloat(action_p, (float)1)); // Time (1 second = -x points) f -= 1 * (action_t - suspect_t); // If is a guess, halve the points diff --git a/src/server.cpp b/src/server.cpp index 6fed4f33da..b8b84968f4 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -2241,7 +2241,7 @@ void Server::sendAddNode(v3pos_t p, MapNode n, std::unordered_set *far_play float far_d_nodes, bool remove_metadata) { float maxd = far_d_nodes * BS; - v3opos_t p_f = intToFloat(p, BS); + auto p_f = intToFloat(p, (opos_t)BS); v3bpos_t block_pos = getNodeBlockPos(p); NetworkPacket pkt(TOCLIENT_ADDNODE, 6 + 2 + 1 + 1 + 1); diff --git a/src/util/numeric.h b/src/util/numeric.h index 7265843f80..c1e7fedd06 100644 --- a/src/util/numeric.h +++ b/src/util/numeric.h @@ -342,7 +342,7 @@ inline v3f intToFloat(v3s16 p, f32 d) ); } -#if USE_POS32 +#if USE_OPOS64 || USE_POS32 inline v3opos_t intToFloat(const v3pos_t & p, const opos_t d) { return v3opos_t( From e7f82e6afb982078967b38df22abde9a4d64768f Mon Sep 17 00:00:00 2001 From: proller Date: Fri, 25 Feb 2022 13:15:08 +0300 Subject: [PATCH 19/36] fix merge --- src/script/lua_api/l_areastore.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/script/lua_api/l_areastore.cpp b/src/script/lua_api/l_areastore.cpp index f0c5ee5a6a..4447848bcd 100644 --- a/src/script/lua_api/l_areastore.cpp +++ b/src/script/lua_api/l_areastore.cpp @@ -149,8 +149,8 @@ int LuaAreaStore::l_get_areas_in_area(lua_State *L) LuaAreaStore *o = checkobject(L, 1); AreaStore *ast = o->as; - v3s16 minp = check_v3pos(L, 2); - v3s16 maxp = check_v3pos(L, 3); + auto minp = check_v3pos(L, 2); + auto maxp = check_v3pos(L, 3); sortBoxVerticies(minp, maxp); bool include_corners = true; From efdc22ad95aa169464b29f8d2402b5bcab699d31 Mon Sep 17 00:00:00 2001 From: proller Date: Fri, 25 Feb 2022 13:25:03 +0300 Subject: [PATCH 20/36] fix pg --- src/database/database-postgresql.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/database/database-postgresql.cpp b/src/database/database-postgresql.cpp index d2f3cede83..7de7abe744 100644 --- a/src/database/database-postgresql.cpp +++ b/src/database/database-postgresql.cpp @@ -462,7 +462,7 @@ void PlayerDatabasePostgreSQL::savePlayer(RemotePlayer *player) verifyDatabase(); - v3f pos = sao->getBasePosition(); + auto pos = sao->getBasePosition(); std::string pitch = ftos(sao->getLookPitch()); std::string yaw = ftos(sao->getRotation().Y); std::string posx = ftos(pos.X); @@ -559,7 +559,7 @@ bool PlayerDatabasePostgreSQL::loadPlayer(RemotePlayer *player, PlayerSAO *sao) sao->setLookPitch(pg_to_float(results, 0, 0)); sao->setRotation(v3f(0, pg_to_float(results, 0, 1), 0)); - sao->setBasePosition(v3f( + sao->setBasePosition(v3opos_t( pg_to_float(results, 0, 2), pg_to_float(results, 0, 3), pg_to_float(results, 0, 4)) From 2db9271433d3ab1d88277af36284648f00fefb01 Mon Sep 17 00:00:00 2001 From: proller Date: Sat, 19 Mar 2022 23:48:14 +0300 Subject: [PATCH 21/36] Breaking world limit 3: Network compatible with old clients/servers --- src/client/client.cpp | 9 ++-- src/client/content_cao.cpp | 4 +- src/network/clientpackethandler.cpp | 9 ++-- src/network/networkpacket.cpp | 69 +++++++++++++++++++++++------ src/network/networkpacket.h | 31 ++++++++++--- src/network/networkprotocol.h | 7 +++ src/network/serverpackethandler.cpp | 16 +++---- src/particles.cpp | 4 +- src/server.cpp | 34 +++++++------- src/server/luaentity_sao.cpp | 4 +- src/server/player_sao.cpp | 2 +- src/util/pointedthing.cpp | 17 ++++--- src/util/pointedthing.h | 2 +- src/util/serialize.h | 36 ++++++++++----- 14 files changed, 167 insertions(+), 77 deletions(-) diff --git a/src/client/client.cpp b/src/client/client.cpp index 41e01f5e3f..2274ca68e0 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -875,6 +875,7 @@ void Client::ReceiveAll() try { if (!m_con->TryReceive(&pkt)) break; + pkt.setProtoVer(m_proto_ver); ProcessData(&pkt); } catch (const con::InvalidIncomingDataException &e) { infostream << "Client::ReceiveAll(): " @@ -978,7 +979,9 @@ void writePlayerPos(LocalPlayer *myplayer, ClientMap *clientMap, NetworkPacket * [12+12+4+4+4] u8 fov*80 [12+12+4+4+4+1] u8 ceil(wanted_range / MAP_BLOCKSIZE) */ - *pkt << position << speed << pitch << yaw << keyPressed; + pkt->writeV3S32(position); + pkt->writeV3S32(speed); + *pkt << pitch << yaw << keyPressed; *pkt << fov << wanted_range; } @@ -1010,7 +1013,7 @@ void Client::interact(InteractAction action, const PointedThing& pointed) pkt << myplayer->getWieldIndex(); std::ostringstream tmp_os(std::ios::binary); - pointed.serialize(tmp_os); + pointed.serialize(tmp_os, m_proto_ver); pkt.putLongString(tmp_os.str()); @@ -1143,7 +1146,7 @@ void Client::sendDeletedBlocks(std::vector &blocks) void Client::sendGotBlocks(const std::vector &blocks) { - NetworkPacket pkt(TOSERVER_GOTBLOCKS, 1 + 6 * blocks.size()); + NetworkPacket pkt(TOSERVER_GOTBLOCKS, 1 + sizeof_v3pos(m_proto_ver) * blocks.size(), 0, m_proto_ver); pkt << (u8) blocks.size(); for (const v3bpos_t &block : blocks) pkt << block; diff --git a/src/client/content_cao.cpp b/src/client/content_cao.cpp index c0c0164cbd..dbc08395f2 100644 --- a/src/client/content_cao.cpp +++ b/src/client/content_cao.cpp @@ -378,7 +378,7 @@ void GenericCAO::processInitData(const std::string &data) m_name = deSerializeString16(is); m_is_player = readU8(is); m_id = readU16(is); - m_position = readV3O(is); + m_position = readV3O(is, m_client->getProtoVersion()); m_rotation = readV3F32(is); m_hp = readU16(is); @@ -1727,7 +1727,7 @@ void GenericCAO::processMessage(const std::string &data) } else if (cmd == AO_CMD_UPDATE_POSITION) { // Not sent by the server if this object is an attachment. // We might however get here if the server notices the object being detached before the client. - m_position = readV3O(is); + m_position = readV3O(is, /* todo after write version: m_client->getProtoVersion()*/); m_velocity = readV3F32(is); m_acceleration = readV3F32(is); m_rotation = readV3F32(is); diff --git a/src/network/clientpackethandler.cpp b/src/network/clientpackethandler.cpp index e58db90ef5..14b7687cb4 100644 --- a/src/network/clientpackethandler.cpp +++ b/src/network/clientpackethandler.cpp @@ -285,13 +285,12 @@ void Client::handleCommand_NodemetaChanged(NetworkPacket *pkt) void Client::handleCommand_BlockData(NetworkPacket* pkt) { // Ignore too small packet - if (pkt->getSize() < sizeof(v3bpos_t)) + if (pkt->getSize() < sizeof_v3pos(pkt->getProtoVer())) return; v3bpos_t p; *pkt >> p; - - std::string datastring(pkt->getString(sizeof(p)), pkt->getSize() - sizeof(p)); + std::string datastring(pkt->getString(sizeof_v3pos(pkt->getProtoVer())), pkt->getSize() - sizeof_v3pos(pkt->getProtoVer())); std::istringstream istr(datastring, std::ios_base::binary); MapSector *sector; @@ -600,8 +599,8 @@ void Client::handleCommand_MovePlayer(NetworkPacket* pkt) *pkt >> pos >> pitch >> yaw; player->setPosition(pos); - - infostream << "Client got TOCLIENT_MOVE_PLAYER" + + infostream << "Client got TOCLIENT_MOVE_PLAYER" << " pos=(" << pos.X << "," << pos.Y << "," << pos.Z << ")" << " pitch=" << pitch << " yaw=" << yaw diff --git a/src/network/networkpacket.cpp b/src/network/networkpacket.cpp index e3ef89d263..5fb03947d1 100644 --- a/src/network/networkpacket.cpp +++ b/src/network/networkpacket.cpp @@ -23,14 +23,8 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "util/serialize.h" #include "networkprotocol.h" -NetworkPacket::NetworkPacket(u16 command, u32 datasize, session_t peer_id): -m_datasize(datasize), m_command(command), m_peer_id(peer_id) -{ - m_data.resize(m_datasize); -} - -NetworkPacket::NetworkPacket(u16 command, u32 datasize): -m_datasize(datasize), m_command(command) +NetworkPacket::NetworkPacket(u16 command, u32 datasize, session_t peer_id, u16 proto_ver): +m_datasize(datasize), m_command(command), m_peer_id(peer_id), m_proto_ver(proto_ver) { m_data.resize(m_datasize); } @@ -450,8 +444,16 @@ NetworkPacket& NetworkPacket::operator>>(v3f& dst) return *this; } -NetworkPacket& NetworkPacket::operator>>(v3d& dst) +#if USE_POS32 +NetworkPacket& NetworkPacket::operator>>(v3opos_t& dst) { + if (m_proto_ver < 41) { + v3f tmp; + *this >> tmp; + dst = v3fToOpos(tmp); + return *this; + } + checkReadOffset(m_read_offset, sizeof(dst)); dst = readV3F64(&m_data[m_read_offset]); @@ -459,6 +461,7 @@ NetworkPacket& NetworkPacket::operator>>(v3d& dst) m_read_offset += sizeof(dst); return *this; } +#endif NetworkPacket& NetworkPacket::operator>>(s16& dst) { @@ -512,15 +515,34 @@ NetworkPacket& NetworkPacket::operator>>(v2s32& dst) return *this; } -NetworkPacket& NetworkPacket::operator>>(v3s32& dst) +v3s32 NetworkPacket::readV3S32() +{ + checkReadOffset(m_read_offset, 12); + + v3s32 dst = ::readV3S32(&m_data[m_read_offset]); + + m_read_offset += 12; + return dst; +} + +#if USE_POS32 +NetworkPacket& NetworkPacket::operator>>(v3pos_t& dst) { + if (m_proto_ver < 41) { + v3s16 tmp; + *this >> tmp; + dst = s16ToPos(tmp); + return *this; + } + checkReadOffset(m_read_offset, 12); - dst = readV3S32(&m_data[m_read_offset]); + dst = ::readV3S32(&m_data[m_read_offset]); m_read_offset += 12; return *this; } +#endif NetworkPacket& NetworkPacket::operator<<(v2f src) { @@ -537,13 +559,20 @@ NetworkPacket& NetworkPacket::operator<<(v3f src) return *this; } -NetworkPacket& NetworkPacket::operator<<(v3d src) +#if USE_POS32 +NetworkPacket& NetworkPacket::operator<<(v3opos_t src) { + if (m_proto_ver < 41) { + *this << oposToV3f(src); + return *this; + } + *this << (double)src.X; *this << (double)src.Y; *this << (double)src.Z; return *this; } +#endif NetworkPacket& NetworkPacket::operator<<(v3s16 src) { @@ -560,13 +589,27 @@ NetworkPacket& NetworkPacket::operator<<(v2s32 src) return *this; } -NetworkPacket& NetworkPacket::operator<<(v3s32 src) +#if USE_POS32 +NetworkPacket& NetworkPacket::operator<<(v3pos_t src) { + if (m_proto_ver < 41) { + *this << posToS16(src); + return *this; + } + *this << (s32) src.X; *this << (s32) src.Y; *this << (s32) src.Z; return *this; } +#endif + +void NetworkPacket::writeV3S32(const v3s32 &src) +{ + *this << (s32) src.X; + *this << (s32) src.Y; + *this << (s32) src.Z; +} NetworkPacket& NetworkPacket::operator>>(video::SColor& dst) { diff --git a/src/network/networkpacket.h b/src/network/networkpacket.h index 0f85cedf8a..c42928139b 100644 --- a/src/network/networkpacket.h +++ b/src/network/networkpacket.h @@ -19,21 +19,32 @@ with this program; if not, write to the Free Software Foundation, Inc., #pragma once +#include "config.h" #include "util/pointer.h" #include "util/numeric.h" #include "networkprotocol.h" #include + +inline size_t sizeof_v3opos(u16 proto_ver) { + return proto_ver >= 41 ? sizeof(v3opos_t) : sizeof(v3f); +} + +inline size_t sizeof_v3pos(u16 proto_ver) { + return proto_ver >= 41 ? sizeof(v3pos_t) : sizeof(v3s16); +} + class NetworkPacket { public: - NetworkPacket(u16 command, u32 datasize, session_t peer_id); - NetworkPacket(u16 command, u32 datasize); + NetworkPacket(u16 command, u32 datasize, session_t peer_id = 0, u16 proto_ver = 0); NetworkPacket() = default; ~NetworkPacket(); + void setProtoVer(u16 proto_ver) { m_proto_ver = proto_ver; } + u16 getProtoVer() { return m_proto_ver; } void putRawPacket(const u8 *data, u32 datasize, session_t peer_id); void clear(); @@ -99,8 +110,10 @@ class NetworkPacket NetworkPacket &operator>>(v3f &dst); NetworkPacket &operator<<(v3f src); - NetworkPacket &operator>>(v3d &dst); - NetworkPacket &operator<<(v3d src); +#if USE_POS32 + NetworkPacket &operator>>(v3opos_t &dst); + NetworkPacket &operator<<(v3opos_t src); +#endif NetworkPacket &operator>>(s16 &dst); NetworkPacket &operator<<(s16 src); @@ -114,8 +127,13 @@ class NetworkPacket NetworkPacket &operator>>(v3s16 &dst); NetworkPacket &operator<<(v3s16 src); - NetworkPacket &operator>>(v3s32 &dst); - NetworkPacket &operator<<(v3s32 src); + void writeV3S32(const v3s32 &src); + v3s32 readV3S32(); + +#if USE_POS32 + NetworkPacket &operator>>(v3pos_t &dst); + NetworkPacket &operator<<(v3pos_t src); +#endif NetworkPacket &operator>>(video::SColor &dst); NetworkPacket &operator<<(video::SColor src); @@ -140,4 +158,5 @@ class NetworkPacket u32 m_read_offset = 0; u16 m_command = 0; session_t m_peer_id = 0; + u16 m_proto_ver = 0; }; diff --git a/src/network/networkprotocol.h b/src/network/networkprotocol.h index b12c21e020..049027f8fa 100644 --- a/src/network/networkprotocol.h +++ b/src/network/networkprotocol.h @@ -20,6 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #pragma once #include "util/string.h" +#include "config.h" /* changes by PROTOCOL_VERSION: @@ -207,9 +208,15 @@ with this program; if not, write to the Free Software Foundation, Inc., Minimap modes PROTOCOL VERSION 40: TOCLIENT_MEDIA_PUSH changed, TOSERVER_HAVE_MEDIA added + PROTOCOL VERSION 41: + Convert coordinates to s16->s32 and float->double */ +#if USE_POS32 +#define LATEST_PROTOCOL_VERSION 41 +#else #define LATEST_PROTOCOL_VERSION 40 +#endif #define LATEST_PROTOCOL_VERSION_STRING TOSTRING(LATEST_PROTOCOL_VERSION) // Server's supported network protocol range diff --git a/src/network/serverpackethandler.cpp b/src/network/serverpackethandler.cpp index a2bd22f50e..135e364471 100644 --- a/src/network/serverpackethandler.cpp +++ b/src/network/serverpackethandler.cpp @@ -275,7 +275,7 @@ void Server::handleCommand_Init(NetworkPacket* pkt) << auth_mechs << std::endl; NetworkPacket resp_pkt(TOCLIENT_HELLO, - 1 + 4 + legacyPlayerNameCasing.size(), peer_id); + 1 + 4 + legacyPlayerNameCasing.size(), peer_id, 0); u16 depl_compress_mode = NETPROTO_COMPRESSION_NONE; resp_pkt << depl_serial_v << depl_compress_mode << net_proto_version @@ -407,7 +407,7 @@ void Server::handleCommand_ClientReady(NetworkPacket* pkt) // Send player list to this client { const std::vector &players = m_clients.getPlayerNames(); - NetworkPacket list_pkt(TOCLIENT_UPDATE_PLAYER_LIST, 0, peer_id); + NetworkPacket list_pkt(TOCLIENT_UPDATE_PLAYER_LIST, 0, peer_id , 0); list_pkt << (u8) PLAYER_LIST_INIT << (u16) players.size(); for (const auto &player : players) list_pkt << player; @@ -464,8 +464,8 @@ void Server::process_PlayerPos(RemotePlayer *player, PlayerSAO *playersao, s32 f32pitch, f32yaw; u8 f32fov; - *pkt >> ps; - *pkt >> ss; + ps = pkt->readV3S32(); + ss = pkt->readV3S32(); *pkt >> f32pitch; *pkt >> f32yaw; @@ -1625,7 +1625,7 @@ void Server::handleCommand_SrpBytesA(NetworkPacket* pkt) return; } - NetworkPacket resp_pkt(TOCLIENT_SRP_BYTES_S_B, 0, peer_id); + NetworkPacket resp_pkt(TOCLIENT_SRP_BYTES_S_B, 0, peer_id, 0); resp_pkt << salt << std::string(bytes_B, len_B); Send(&resp_pkt); } @@ -1723,7 +1723,7 @@ void Server::handleCommand_ModChannelJoin(NetworkPacket *pkt) session_t peer_id = pkt->getPeerId(); NetworkPacket resp_pkt(TOCLIENT_MODCHANNEL_SIGNAL, - 1 + 2 + channel_name.size(), peer_id); + 1 + 2 + channel_name.size(), peer_id, 0); // Send signal to client to notify join succeed or not if (g_settings->getBool("enable_mod_channels") && @@ -1748,7 +1748,7 @@ void Server::handleCommand_ModChannelLeave(NetworkPacket *pkt) session_t peer_id = pkt->getPeerId(); NetworkPacket resp_pkt(TOCLIENT_MODCHANNEL_SIGNAL, - 1 + 2 + channel_name.size(), peer_id); + 1 + 2 + channel_name.size(), peer_id, 0); // Send signal to client to notify join succeed or not if (g_settings->getBool("enable_mod_channels") && @@ -1783,7 +1783,7 @@ void Server::handleCommand_ModChannelMsg(NetworkPacket *pkt) // If channel not registered, signal it and ignore message if (!m_modchannel_mgr->channelRegistered(channel_name)) { NetworkPacket resp_pkt(TOCLIENT_MODCHANNEL_SIGNAL, - 1 + 2 + channel_name.size(), peer_id); + 1 + 2 + channel_name.size(), peer_id, 0); resp_pkt << (u8)MODCHANNEL_SIGNAL_CHANNEL_NOT_REGISTERED << channel_name; Send(&resp_pkt); return; diff --git a/src/particles.cpp b/src/particles.cpp index b8dd820bf1..0e2fc93c42 100644 --- a/src/particles.cpp +++ b/src/particles.cpp @@ -22,7 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc., void ParticleParameters::serialize(std::ostream &os, u16 protocol_ver) const { - writeV3O(os, pos); + writeV3O(os, pos, protocol_ver); writeV3F32(os, vel); writeV3F32(os, acc); writeF32(os, expirationtime); @@ -41,7 +41,7 @@ void ParticleParameters::serialize(std::ostream &os, u16 protocol_ver) const void ParticleParameters::deSerialize(std::istream &is, u16 protocol_ver) { - pos = readV3O(is); + pos = readV3O(is, protocol_ver); vel = readV3F32(is); acc = readV3F32(is); expirationtime = readF32(is); diff --git a/src/server.cpp b/src/server.cpp index 5da85ec2f7..2cd2487fa6 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -18,13 +18,18 @@ with this program; if not, write to the Free Software Foundation, Inc., */ #include "server.h" +#include #include #include #include +#include "clientiface.h" +#include "exceptions.h" #include "network/connection.h" +#include "network/networkpacket.h" #include "network/networkprotocol.h" #include "network/serveropcodes.h" #include "ban.h" +#include "util/metricsbackend.h" #include "environment.h" #include "map.h" #include "threading/mutex_auto_lock.h" @@ -1180,8 +1185,9 @@ void Server::ProcessData(NetworkPacket *pkt) return; } - u8 peer_ser_ver = getClient(peer_id, CS_InitDone)->serialization_version; - + RemoteClient * client = getClient(peer_id, CS_InitDone); + u8 peer_ser_ver = client->serialization_version; + pkt->setProtoVer(client->net_proto_version); if(peer_ser_ver == SER_FMT_VER_INVALID) { errorstream << "Server::ProcessData(): Cancelling: Peer" " serialization format invalid or not initialized." @@ -1425,7 +1431,7 @@ void Server::SendDeathscreen(session_t peer_id, bool set_camera_point_target, void Server::SendItemDef(session_t peer_id, IItemDefManager *itemdef, u16 protocol_version) { - NetworkPacket pkt(TOCLIENT_ITEMDEF, 0, peer_id); + NetworkPacket pkt(TOCLIENT_ITEMDEF, 0, peer_id, 0); /* u16 command @@ -1448,7 +1454,7 @@ void Server::SendItemDef(session_t peer_id, void Server::SendNodeDef(session_t peer_id, const NodeDefManager *nodedef, u16 protocol_version) { - NetworkPacket pkt(TOCLIENT_NODEDEF, 0, peer_id); + NetworkPacket pkt(TOCLIENT_NODEDEF, 0, peer_id, 0); /* u16 command @@ -1569,7 +1575,7 @@ void Server::SendSpawnParticle(session_t peer_id, u16 protocol_version, } assert(protocol_version != 0); - NetworkPacket pkt(TOCLIENT_SPAWN_PARTICLE, 0, peer_id); + NetworkPacket pkt(TOCLIENT_SPAWN_PARTICLE, 0, peer_id, protocol_version); { // NetworkPacket and iostreams are incompatible... @@ -1616,7 +1622,7 @@ void Server::SendAddParticleSpawner(session_t peer_id, u16 protocol_version, } assert(protocol_version != 0); - NetworkPacket pkt(TOCLIENT_ADD_PARTICLESPAWNER, 100, peer_id); + NetworkPacket pkt(TOCLIENT_ADD_PARTICLESPAWNER, 100, peer_id, protocol_version); pkt << p.amount << p.time << p.minpos << p.maxpos << p.minvel << p.maxvel << p.minacc << p.maxacc << p.minexptime << p.maxexptime @@ -1827,7 +1833,7 @@ void Server::SendMovePlayer(session_t peer_id) // Send attachment updates instantly to the client prior updating position sao->sendOutdatedData(); - NetworkPacket pkt(TOCLIENT_MOVE_PLAYER, sizeof(v3f) + sizeof(f32) * 2, peer_id); + NetworkPacket pkt(TOCLIENT_MOVE_PLAYER, sizeof_v3opos(sao->getPlayer()->protocol_version) + sizeof(f32) * 2, peer_id, sao->getPlayer()->protocol_version); pkt << sao->getBasePosition() << sao->getLookPitch() << sao->getRotation().Y; { @@ -2209,9 +2215,6 @@ void Server::sendRemoveNode(v3pos_t p, std::unordered_set *far_players, v3opos_t p_f = posToOpos(p, BS); v3bpos_t block_pos = getNodeBlockPos(p); - NetworkPacket pkt(TOCLIENT_REMOVENODE, 6); - pkt << p; - std::vector clients = m_clients.getClientIDs(); ClientInterface::AutoLock clientlock(m_clients); @@ -2232,6 +2235,8 @@ void Server::sendRemoveNode(v3pos_t p, std::unordered_set *far_players, client->SetBlockNotSent(block_pos); continue; } + NetworkPacket pkt(TOCLIENT_REMOVENODE, sizeof_v3pos(player->protocol_version), 0, player->protocol_version); + pkt << p; // Send as reliable m_clients.send(client_id, 0, &pkt, true); @@ -2245,10 +2250,6 @@ void Server::sendAddNode(v3pos_t p, MapNode n, std::unordered_set *far_play auto p_f = intToFloat(p, (opos_t)BS); v3bpos_t block_pos = getNodeBlockPos(p); - NetworkPacket pkt(TOCLIENT_ADDNODE, 6 + 2 + 1 + 1 + 1); - pkt << p << n.param0 << n.param1 << n.param2 - << (u8) (remove_metadata ? 0 : 1); - std::vector clients = m_clients.getClientIDs(); ClientInterface::AutoLock clientlock(m_clients); @@ -2270,6 +2271,9 @@ void Server::sendAddNode(v3pos_t p, MapNode n, std::unordered_set *far_play continue; } + NetworkPacket pkt(TOCLIENT_ADDNODE, sizeof_v3pos(player->protocol_version) + 2 + 1 + 1 + 1, 0, player->protocol_version); + pkt << p << n.param0 << n.param1 << n.param2 << (u8) (remove_metadata ? 0 : 1); + // Send as reliable m_clients.send(client_id, 0, &pkt, true); } @@ -2336,7 +2340,7 @@ void Server::SendBlockNoLock(session_t peer_id, MapBlock *block, u8 ver, block->serializeNetworkSpecific(os); std::string s = os.str(); - NetworkPacket pkt(TOCLIENT_BLOCKDATA, 2 + 2 + 2 + s.size(), peer_id); + NetworkPacket pkt(TOCLIENT_BLOCKDATA, sizeof_v3pos(m_env->getPlayer(peer_id)->protocol_version) + s.size(), peer_id, m_env->getPlayer(peer_id)->protocol_version); pkt << block->getPos(); pkt.putRawString(s.c_str(), s.size()); diff --git a/src/server/luaentity_sao.cpp b/src/server/luaentity_sao.cpp index 8f781d4f61..54e055e26b 100644 --- a/src/server/luaentity_sao.cpp +++ b/src/server/luaentity_sao.cpp @@ -238,7 +238,7 @@ std::string LuaEntitySAO::getClientInitializationData(u16 protocol_version) os << serializeString16(""); // name writeU8(os, 0); // is_player writeU16(os, getId()); //id - writeV3O(os, m_base_position); + writeV3O(os, m_base_position, protocol_version); writeV3F32(os, m_rotation); writeU16(os, m_hp); @@ -515,7 +515,7 @@ void LuaEntitySAO::sendPosition(bool do_interpolate, bool is_movement_end) m_rotation, do_interpolate, is_movement_end, - update_interval + update_interval ); // create message and add to list m_messages_out.emplace(getId(), false, str); diff --git a/src/server/player_sao.cpp b/src/server/player_sao.cpp index eb7e0674d7..a85d77499e 100644 --- a/src/server/player_sao.cpp +++ b/src/server/player_sao.cpp @@ -113,7 +113,7 @@ std::string PlayerSAO::getClientInitializationData(u16 protocol_version) os << serializeString16(m_player->getName()); // name writeU8(os, 1); // is_player writeS16(os, getId()); // id - writeV3O(os, m_base_position); + writeV3O(os, m_base_position, protocol_version); writeV3F32(os, m_rotation); writeU16(os, getHP()); diff --git a/src/util/pointedthing.cpp b/src/util/pointedthing.cpp index 469246cc62..9645ea3fcd 100644 --- a/src/util/pointedthing.cpp +++ b/src/util/pointedthing.cpp @@ -19,6 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "pointedthing.h" +#include "gamedef.h" #include "serialize.h" #include "exceptions.h" #include @@ -69,16 +70,18 @@ std::string PointedThing::dump() const return os.str(); } -void PointedThing::serialize(std::ostream &os) const +void PointedThing::serialize(std::ostream &os, const u16 proto_ver) const { - writeU8(os, 0); // version + + const int version = proto_ver >= 41 ? 1 : 0; + writeU8(os, version); // version writeU8(os, (u8)type); switch (type) { case POINTEDTHING_NOTHING: break; case POINTEDTHING_NODE: - writeV3POS(os, node_undersurface); - writeV3POS(os, node_abovesurface); + writeV3POS(os, node_undersurface, proto_ver); + writeV3POS(os, node_abovesurface, proto_ver); break; case POINTEDTHING_OBJECT: writeS16(os, object_id); @@ -89,15 +92,15 @@ void PointedThing::serialize(std::ostream &os) const void PointedThing::deSerialize(std::istream &is) { int version = readU8(is); - if (version != 0) throw SerializationError( + if (version != 0 && version != 1) throw SerializationError( "unsupported PointedThing version"); type = (PointedThingType) readU8(is); switch (type) { case POINTEDTHING_NOTHING: break; case POINTEDTHING_NODE: - node_undersurface = readV3POS(is); - node_abovesurface = readV3POS(is); + node_undersurface = readV3POS(is, version >= 1 ? 41 : 40); + node_abovesurface = readV3POS(is, version >= 1 ? 41 : 40); break; case POINTEDTHING_OBJECT: object_id = readS16(is); diff --git a/src/util/pointedthing.h b/src/util/pointedthing.h index 8a7030fd7b..4c5b96f1e6 100644 --- a/src/util/pointedthing.h +++ b/src/util/pointedthing.h @@ -95,7 +95,7 @@ struct PointedThing //! Constructor for POINTEDTHING_OBJECT PointedThing(s16 id, const v3opos_t &point, const v3pos_t &normal, f32 distSq); std::string dump() const; - void serialize(std::ostream &os) const; + void serialize(std::ostream &os, const u16 proto_ver) const; void deSerialize(std::istream &is); /*! * This function ignores the intersection point and normal. diff --git a/src/util/serialize.h b/src/util/serialize.h index c8529e84b4..d357378230 100644 --- a/src/util/serialize.h +++ b/src/util/serialize.h @@ -469,49 +469,61 @@ MAKE_STREAM_WRITE_FXN(v3f, V3F32, 12); MAKE_STREAM_WRITE_FXN(v3d, V3F64, 24); MAKE_STREAM_WRITE_FXN(video::SColor, ARGB8, 4); -inline pos_t readPOS(std::istream &is) { +inline pos_t readPOS(std::istream &is, const u16 proto_ver = 0) { #if USE_POS32 - return readS32(is); + if (proto_ver >= 41) + return readS32(is); + return readS16(is); #else return readS16(is); #endif } -inline void writePOS(std::ostream &os, pos_t i) { +inline void writePOS(std::ostream &os, pos_t i, const u16 proto_ver = 0) { #if USE_POS32 - return writeS32(os, i); + if (proto_ver >= 41) + return writeS32(os, i); + return writeS16(os, i); #else return writeS16(os, i); #endif } -inline v3pos_t readV3POS(std::istream &is) { +inline v3pos_t readV3POS(std::istream &is, const u16 proto_ver = 0) { #if USE_POS32 - return readV3S32(is); + if (proto_ver >= 41) + return readV3S32(is); + return s16ToPos(readV3S16(is)); #else return readV3S16(is); #endif } -inline void writeV3POS(std::ostream &os, v3pos_t p) { +inline void writeV3POS(std::ostream &os, v3pos_t p, const u16 proto_ver = 0) { #if USE_POS32 - return writeV3S32(os, p); + if (proto_ver >= 41) + return writeV3S32(os, p); + return writeV3S16(os, posToS16(p)); #else return writeV3S16(os, p); #endif } -inline v3opos_t readV3O(std::istream &is) { +inline v3opos_t readV3O(std::istream &is, const u16 proto_ver = 0) { #if USE_OPOS64 - return readV3F64(is); + if (proto_ver >= 41) + return readV3F64(is); + return v3fToOpos(readV3F32(is)); #else return readV3F32(is); #endif } -inline void writeV3O(std::ostream &os, v3opos_t p) { +inline void writeV3O(std::ostream &os, v3opos_t p, const u16 proto_ver = 0) { #if USE_OPOS64 - return writeV3F64(os, p); + if (proto_ver >= 41) + return writeV3F64(os, p); + return writeV3F32(os, oposToV3f(p)); #else return writeV3F32(os, p); #endif From 0fe6ceeb3a1ab702e963306c3338499f95884134 Mon Sep 17 00:00:00 2001 From: proller Date: Sun, 20 Mar 2022 00:49:40 +0300 Subject: [PATCH 22/36] fix --- src/client/content_cao.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/content_cao.cpp b/src/client/content_cao.cpp index dbc08395f2..0ce237f52f 100644 --- a/src/client/content_cao.cpp +++ b/src/client/content_cao.cpp @@ -1727,7 +1727,7 @@ void GenericCAO::processMessage(const std::string &data) } else if (cmd == AO_CMD_UPDATE_POSITION) { // Not sent by the server if this object is an attachment. // We might however get here if the server notices the object being detached before the client. - m_position = readV3O(is, /* todo after write version: m_client->getProtoVersion()*/); + m_position = readV3O(is); /* todo after write version: ,m_client->getProtoVersion() */ m_velocity = readV3F32(is); m_acceleration = readV3F32(is); m_rotation = readV3F32(is); From 74675b03219c6af22bb74d849375ca0e0c5d88c8 Mon Sep 17 00:00:00 2001 From: proller Date: Sun, 20 Mar 2022 04:35:31 +0300 Subject: [PATCH 23/36] fix --- src/network/serverpackethandler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/network/serverpackethandler.cpp b/src/network/serverpackethandler.cpp index 135e364471..b79743c2d8 100644 --- a/src/network/serverpackethandler.cpp +++ b/src/network/serverpackethandler.cpp @@ -439,7 +439,7 @@ void Server::handleCommand_GotBlocks(NetworkPacket* pkt) u8 count; *pkt >> count; - if ((s16)pkt->getSize() < 1 + (int)count * (int)sizeof(v3bpos_t)) { + if ((s16)pkt->getSize() < 1 + (int)count * (int)sizeof_v3pos(pkt->getProtoVer())) { throw con::InvalidIncomingDataException ("GOTBLOCKS length is too short"); } From 7f5ff7054e2e8e7b02a0e1df0f3f765dc34c6cfc Mon Sep 17 00:00:00 2001 From: proller Date: Sun, 20 Mar 2022 04:56:38 +0300 Subject: [PATCH 24/36] fix --- src/client/client.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/client.cpp b/src/client/client.cpp index 2274ca68e0..722593b842 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -1133,7 +1133,7 @@ void Client::startAuth(AuthMechanism chosen_auth_mechanism) void Client::sendDeletedBlocks(std::vector &blocks) { - NetworkPacket pkt(TOSERVER_DELETEDBLOCKS, 1 + sizeof(v3pos_t) * blocks.size()); + NetworkPacket pkt(TOSERVER_DELETEDBLOCKS, 1 + sizeof_v3pos(m_proto_ver) * blocks.size(), m_proto_ver); pkt << (u8) blocks.size(); From 363d16cecf8fb99cdca5e3476090685f5d367d42 Mon Sep 17 00:00:00 2001 From: proller Date: Sun, 20 Mar 2022 05:32:44 +0300 Subject: [PATCH 25/36] fix --- src/client/client.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/client.cpp b/src/client/client.cpp index 722593b842..70ae081c15 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -1133,7 +1133,7 @@ void Client::startAuth(AuthMechanism chosen_auth_mechanism) void Client::sendDeletedBlocks(std::vector &blocks) { - NetworkPacket pkt(TOSERVER_DELETEDBLOCKS, 1 + sizeof_v3pos(m_proto_ver) * blocks.size(), m_proto_ver); + NetworkPacket pkt(TOSERVER_DELETEDBLOCKS, 1 + sizeof_v3pos(m_proto_ver) * blocks.size(), 0, m_proto_ver); pkt << (u8) blocks.size(); From 0c2aa98f0ecb202f0c920ee37b258511e4b80101 Mon Sep 17 00:00:00 2001 From: proller Date: Sun, 20 Mar 2022 16:18:39 +0300 Subject: [PATCH 26/36] enable by default --- src/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b8ccee235b..7122efd0e7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -31,7 +31,7 @@ if(NOT (BUILD_CLIENT OR BUILD_SERVER)) set(BUILD_SERVER TRUE) endif() -option(USE_POS32 "32 bit node/block positions (experimental, not compatible with 16 bit)" FALSE) +option(USE_POS32 "32 bit node/block positions (experimental, not compatible with 16 bit)" TRUE) option(USE_OPOS64 "64 bit object positions (experimental, not compatible with 32 bit)" ${USE_POS32}) option(ENABLE_CURL "Enable cURL support for fetching media" TRUE) From 5466830c1f6fe65ae24eabd79e1b2df7675c852d Mon Sep 17 00:00:00 2001 From: proller Date: Sat, 31 Dec 2022 21:10:09 +0300 Subject: [PATCH 27/36] Use Pos --- src/client/game.cpp | 4 ++-- src/database/database-sqlite3.cpp | 2 +- src/mapgen/mapgen.cpp | 8 +++---- src/mapgen/mapgen_carpathian.cpp | 16 ++++++------- src/mapgen/mapgen_flat.cpp | 24 +++++++++---------- src/mapgen/mapgen_fractal.cpp | 12 +++++----- src/mapgen/mapgen_v5.cpp | 20 ++++++++-------- src/mapgen/mapgen_v6.cpp | 8 +++---- src/mapgen/mapgen_v7.cpp | 40 +++++++++++++++---------------- src/mapgen/mapgen_valleys.cpp | 20 ++++++++-------- src/server.cpp | 2 +- src/settings.cpp | 6 ++--- src/settings.h | 6 ++--- 13 files changed, 84 insertions(+), 84 deletions(-) diff --git a/src/client/game.cpp b/src/client/game.cpp index 0ac068e8e1..ac56b52c9c 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -2354,7 +2354,7 @@ void Game::toggleUpdateCamera() void Game::increaseViewRange() { - pos_t range = g_settings->getPOS("viewing_range"); + pos_t range = g_settings->getPos("viewing_range"); pos_t range_new = range + 10; if (range_new > 4000) { @@ -2371,7 +2371,7 @@ void Game::increaseViewRange() void Game::decreaseViewRange() { - pos_t range = g_settings->getPOS("viewing_range"); + pos_t range = g_settings->getPos("viewing_range"); pos_t range_new = range - 10; if (range_new < 20) { diff --git a/src/database/database-sqlite3.cpp b/src/database/database-sqlite3.cpp index 4966392ae8..934f5cdf64 100644 --- a/src/database/database-sqlite3.cpp +++ b/src/database/database-sqlite3.cpp @@ -203,7 +203,7 @@ MapDatabaseSQLite3::MapDatabaseSQLite3(const std::string &savedir): MapDatabase() { #if USE_POS32 - pos_t mapgen_limit = g_settings->getPOS("mapgen_limit"); + pos_t mapgen_limit = g_settings->getPos("mapgen_limit"); if (mapgen_limit > 31000) { throw DatabaseException("Database_SQLite3: mapgen_limit is too big (" + std::to_string(mapgen_limit) + "). Please set mapgen_limit = 31000"); } diff --git a/src/mapgen/mapgen.cpp b/src/mapgen/mapgen.cpp index 8c7e2eb7f7..3e4327e6f5 100644 --- a/src/mapgen/mapgen.cpp +++ b/src/mapgen/mapgen.cpp @@ -1033,8 +1033,8 @@ void MapgenParams::readParams(const Settings *settings) mgtype = MAPGEN_DEFAULT; } - settings->getPOSNoEx("water_level", water_level); - settings->getPOSNoEx("mapgen_limit", mapgen_limit); + settings->getPosNoEx("water_level", water_level); + settings->getPosNoEx("mapgen_limit", mapgen_limit); settings->getS16NoEx("chunksize", chunksize); settings->getFlagStrNoEx("mg_flags", flags, flagdesc_mapgen); @@ -1053,8 +1053,8 @@ void MapgenParams::writeParams(Settings *settings) const { settings->set("mg_name", Mapgen::getMapgenName(mgtype)); settings->setU64("seed", seed); - settings->setPOS("water_level", water_level); - settings->setPOS("mapgen_limit", mapgen_limit); + settings->setPos("water_level", water_level); + settings->setPos("mapgen_limit", mapgen_limit); settings->setS16("chunksize", chunksize); settings->setFlagStr("mg_flags", flags, flagdesc_mapgen); diff --git a/src/mapgen/mapgen_carpathian.cpp b/src/mapgen/mapgen_carpathian.cpp index d85ed5b48e..99d65baa0b 100644 --- a/src/mapgen/mapgen_carpathian.cpp +++ b/src/mapgen/mapgen_carpathian.cpp @@ -152,17 +152,17 @@ void MapgenCarpathianParams::readParams(const Settings *settings) settings->getFloatNoEx("mgcarpathian_valley_width", valley_width); settings->getFloatNoEx("mgcarpathian_cave_width", cave_width); - settings->getPOSNoEx("mgcarpathian_large_cave_depth", large_cave_depth); + settings->getPosNoEx("mgcarpathian_large_cave_depth", large_cave_depth); settings->getU16NoEx("mgcarpathian_small_cave_num_min", small_cave_num_min); settings->getU16NoEx("mgcarpathian_small_cave_num_max", small_cave_num_max); settings->getU16NoEx("mgcarpathian_large_cave_num_min", large_cave_num_min); settings->getU16NoEx("mgcarpathian_large_cave_num_max", large_cave_num_max); settings->getFloatNoEx("mgcarpathian_large_cave_flooded", large_cave_flooded); - settings->getPOSNoEx("mgcarpathian_cavern_limit", cavern_limit); - settings->getPOSNoEx("mgcarpathian_cavern_taper", cavern_taper); + settings->getPosNoEx("mgcarpathian_cavern_limit", cavern_limit); + settings->getPosNoEx("mgcarpathian_cavern_taper", cavern_taper); settings->getFloatNoEx("mgcarpathian_cavern_threshold", cavern_threshold); - settings->getPOSNoEx("mgcarpathian_dungeon_ymin", dungeon_ymin); - settings->getPOSNoEx("mgcarpathian_dungeon_ymax", dungeon_ymax); + settings->getPosNoEx("mgcarpathian_dungeon_ymin", dungeon_ymin); + settings->getPosNoEx("mgcarpathian_dungeon_ymax", dungeon_ymax); settings->getNoiseParams("mgcarpathian_np_filler_depth", np_filler_depth); settings->getNoiseParams("mgcarpathian_np_height1", np_height1); @@ -194,7 +194,7 @@ void MapgenCarpathianParams::writeParams(Settings *settings) const settings->setFloat("mgcarpathian_valley_width", valley_width); settings->setFloat("mgcarpathian_cave_width", cave_width); - settings->setPOS("mgcarpathian_large_cave_depth", large_cave_depth); + settings->setPos("mgcarpathian_large_cave_depth", large_cave_depth); settings->setU16("mgcarpathian_small_cave_num_min", small_cave_num_min); settings->setU16("mgcarpathian_small_cave_num_max", small_cave_num_max); settings->setU16("mgcarpathian_large_cave_num_min", large_cave_num_min); @@ -203,8 +203,8 @@ void MapgenCarpathianParams::writeParams(Settings *settings) const settings->setS16("mgcarpathian_cavern_limit", cavern_limit); settings->setS16("mgcarpathian_cavern_taper", cavern_taper); settings->setFloat("mgcarpathian_cavern_threshold", cavern_threshold); - settings->setPOS("mgcarpathian_dungeon_ymin", dungeon_ymin); - settings->setPOS("mgcarpathian_dungeon_ymax", dungeon_ymax); + settings->setPos("mgcarpathian_dungeon_ymin", dungeon_ymin); + settings->setPos("mgcarpathian_dungeon_ymax", dungeon_ymax); settings->setNoiseParams("mgcarpathian_np_filler_depth", np_filler_depth); settings->setNoiseParams("mgcarpathian_np_height1", np_height1); diff --git a/src/mapgen/mapgen_flat.cpp b/src/mapgen/mapgen_flat.cpp index 173f5fab8c..773b0977ff 100644 --- a/src/mapgen/mapgen_flat.cpp +++ b/src/mapgen/mapgen_flat.cpp @@ -108,8 +108,8 @@ MapgenFlatParams::MapgenFlatParams(): void MapgenFlatParams::readParams(const Settings *settings) { settings->getFlagStrNoEx("mgflat_spflags", spflags, flagdesc_mapgen_flat); - settings->getPOSNoEx("mgflat_ground_level", ground_level); - settings->getPOSNoEx("mgflat_large_cave_depth", large_cave_depth); + settings->getPosNoEx("mgflat_ground_level", ground_level); + settings->getPosNoEx("mgflat_large_cave_depth", large_cave_depth); settings->getU16NoEx("mgflat_small_cave_num_min", small_cave_num_min); settings->getU16NoEx("mgflat_small_cave_num_max", small_cave_num_max); settings->getU16NoEx("mgflat_large_cave_num_min", large_cave_num_min); @@ -120,11 +120,11 @@ void MapgenFlatParams::readParams(const Settings *settings) settings->getFloatNoEx("mgflat_lake_steepness", lake_steepness); settings->getFloatNoEx("mgflat_hill_threshold", hill_threshold); settings->getFloatNoEx("mgflat_hill_steepness", hill_steepness); - settings->getPOSNoEx("mgflat_cavern_limit", cavern_limit); - settings->getPOSNoEx("mgflat_cavern_taper", cavern_taper); + settings->getPosNoEx("mgflat_cavern_limit", cavern_limit); + settings->getPosNoEx("mgflat_cavern_taper", cavern_taper); settings->getFloatNoEx("mgflat_cavern_threshold", cavern_threshold); - settings->getPOSNoEx("mgflat_dungeon_ymin", dungeon_ymin); - settings->getPOSNoEx("mgflat_dungeon_ymax", dungeon_ymax); + settings->getPosNoEx("mgflat_dungeon_ymin", dungeon_ymin); + settings->getPosNoEx("mgflat_dungeon_ymax", dungeon_ymax); settings->getNoiseParams("mgflat_np_terrain", np_terrain); settings->getNoiseParams("mgflat_np_filler_depth", np_filler_depth); @@ -138,8 +138,8 @@ void MapgenFlatParams::readParams(const Settings *settings) void MapgenFlatParams::writeParams(Settings *settings) const { settings->setFlagStr("mgflat_spflags", spflags, flagdesc_mapgen_flat); - settings->setPOS("mgflat_ground_level", ground_level); - settings->setPOS("mgflat_large_cave_depth", large_cave_depth); + settings->setPos("mgflat_ground_level", ground_level); + settings->setPos("mgflat_large_cave_depth", large_cave_depth); settings->setU16("mgflat_small_cave_num_min", small_cave_num_min); settings->setU16("mgflat_small_cave_num_max", small_cave_num_max); settings->setU16("mgflat_large_cave_num_min", large_cave_num_min); @@ -150,11 +150,11 @@ void MapgenFlatParams::writeParams(Settings *settings) const settings->setFloat("mgflat_lake_steepness", lake_steepness); settings->setFloat("mgflat_hill_threshold", hill_threshold); settings->setFloat("mgflat_hill_steepness", hill_steepness); - settings->setPOS("mgflat_cavern_limit", cavern_limit); - settings->setPOS("mgflat_cavern_taper", cavern_taper); + settings->setPos("mgflat_cavern_limit", cavern_limit); + settings->setPos("mgflat_cavern_taper", cavern_taper); settings->setFloat("mgflat_cavern_threshold", cavern_threshold); - settings->setPOS("mgflat_dungeon_ymin", dungeon_ymin); - settings->setPOS("mgflat_dungeon_ymax", dungeon_ymax); + settings->setPos("mgflat_dungeon_ymin", dungeon_ymin); + settings->setPos("mgflat_dungeon_ymax", dungeon_ymax); settings->setNoiseParams("mgflat_np_terrain", np_terrain); settings->setNoiseParams("mgflat_np_filler_depth", np_filler_depth); diff --git a/src/mapgen/mapgen_fractal.cpp b/src/mapgen/mapgen_fractal.cpp index 4d5774971d..a21fc1ef1c 100644 --- a/src/mapgen/mapgen_fractal.cpp +++ b/src/mapgen/mapgen_fractal.cpp @@ -108,14 +108,14 @@ void MapgenFractalParams::readParams(const Settings *settings) { settings->getFlagStrNoEx("mgfractal_spflags", spflags, flagdesc_mapgen_fractal); settings->getFloatNoEx("mgfractal_cave_width", cave_width); - settings->getPOSNoEx("mgfractal_large_cave_depth", large_cave_depth); + settings->getPosNoEx("mgfractal_large_cave_depth", large_cave_depth); settings->getU16NoEx("mgfractal_small_cave_num_min", small_cave_num_min); settings->getU16NoEx("mgfractal_small_cave_num_max", small_cave_num_max); settings->getU16NoEx("mgfractal_large_cave_num_min", large_cave_num_min); settings->getU16NoEx("mgfractal_large_cave_num_max", large_cave_num_max); settings->getFloatNoEx("mgfractal_large_cave_flooded", large_cave_flooded); - settings->getPOSNoEx("mgfractal_dungeon_ymin", dungeon_ymin); - settings->getPOSNoEx("mgfractal_dungeon_ymax", dungeon_ymax); + settings->getPosNoEx("mgfractal_dungeon_ymin", dungeon_ymin); + settings->getPosNoEx("mgfractal_dungeon_ymax", dungeon_ymax); settings->getU16NoEx("mgfractal_fractal", fractal); settings->getU16NoEx("mgfractal_iterations", iterations); settings->getV3FNoEx("mgfractal_scale", scale); @@ -139,14 +139,14 @@ void MapgenFractalParams::writeParams(Settings *settings) const { settings->setFlagStr("mgfractal_spflags", spflags, flagdesc_mapgen_fractal); settings->setFloat("mgfractal_cave_width", cave_width); - settings->setPOS("mgfractal_large_cave_depth", large_cave_depth); + settings->setPos("mgfractal_large_cave_depth", large_cave_depth); settings->setU16("mgfractal_small_cave_num_min", small_cave_num_min); settings->setU16("mgfractal_small_cave_num_max", small_cave_num_max); settings->setU16("mgfractal_large_cave_num_min", large_cave_num_min); settings->setU16("mgfractal_large_cave_num_max", large_cave_num_max); settings->setFloat("mgfractal_large_cave_flooded", large_cave_flooded); - settings->setPOS("mgfractal_dungeon_ymin", dungeon_ymin); - settings->setPOS("mgfractal_dungeon_ymax", dungeon_ymax); + settings->setPos("mgfractal_dungeon_ymin", dungeon_ymin); + settings->setPos("mgfractal_dungeon_ymax", dungeon_ymax); settings->setU16("mgfractal_fractal", fractal); settings->setU16("mgfractal_iterations", iterations); settings->setV3F("mgfractal_scale", scale); diff --git a/src/mapgen/mapgen_v5.cpp b/src/mapgen/mapgen_v5.cpp index 0c67bdc237..a60e4f5105 100644 --- a/src/mapgen/mapgen_v5.cpp +++ b/src/mapgen/mapgen_v5.cpp @@ -103,17 +103,17 @@ void MapgenV5Params::readParams(const Settings *settings) { settings->getFlagStrNoEx("mgv5_spflags", spflags, flagdesc_mapgen_v5); settings->getFloatNoEx("mgv5_cave_width", cave_width); - settings->getPOSNoEx("mgv5_large_cave_depth", large_cave_depth); + settings->getPosNoEx("mgv5_large_cave_depth", large_cave_depth); settings->getU16NoEx("mgv5_small_cave_num_min", small_cave_num_min); settings->getU16NoEx("mgv5_small_cave_num_max", small_cave_num_max); settings->getU16NoEx("mgv5_large_cave_num_min", large_cave_num_min); settings->getU16NoEx("mgv5_large_cave_num_max", large_cave_num_max); settings->getFloatNoEx("mgv5_large_cave_flooded", large_cave_flooded); - settings->getPOSNoEx("mgv5_cavern_limit", cavern_limit); - settings->getPOSNoEx("mgv5_cavern_taper", cavern_taper); + settings->getPosNoEx("mgv5_cavern_limit", cavern_limit); + settings->getPosNoEx("mgv5_cavern_taper", cavern_taper); settings->getFloatNoEx("mgv5_cavern_threshold", cavern_threshold); - settings->getPOSNoEx("mgv5_dungeon_ymin", dungeon_ymin); - settings->getPOSNoEx("mgv5_dungeon_ymax", dungeon_ymax); + settings->getPosNoEx("mgv5_dungeon_ymin", dungeon_ymin); + settings->getPosNoEx("mgv5_dungeon_ymax", dungeon_ymax); settings->getNoiseParams("mgv5_np_filler_depth", np_filler_depth); settings->getNoiseParams("mgv5_np_factor", np_factor); @@ -130,17 +130,17 @@ void MapgenV5Params::writeParams(Settings *settings) const { settings->setFlagStr("mgv5_spflags", spflags, flagdesc_mapgen_v5); settings->setFloat("mgv5_cave_width", cave_width); - settings->setPOS("mgv5_large_cave_depth", large_cave_depth); + settings->setPos("mgv5_large_cave_depth", large_cave_depth); settings->setU16("mgv5_small_cave_num_min", small_cave_num_min); settings->setU16("mgv5_small_cave_num_max", small_cave_num_max); settings->setU16("mgv5_large_cave_num_min", large_cave_num_min); settings->setU16("mgv5_large_cave_num_max", large_cave_num_max); settings->setFloat("mgv5_large_cave_flooded", large_cave_flooded); - settings->setPOS("mgv5_cavern_limit", cavern_limit); - settings->setPOS("mgv5_cavern_taper", cavern_taper); + settings->setPos("mgv5_cavern_limit", cavern_limit); + settings->setPos("mgv5_cavern_taper", cavern_taper); settings->setFloat("mgv5_cavern_threshold", cavern_threshold); - settings->setPOS("mgv5_dungeon_ymin", dungeon_ymin); - settings->setPOS("mgv5_dungeon_ymax", dungeon_ymax); + settings->setPos("mgv5_dungeon_ymin", dungeon_ymin); + settings->setPos("mgv5_dungeon_ymax", dungeon_ymax); settings->setNoiseParams("mgv5_np_filler_depth", np_filler_depth); settings->setNoiseParams("mgv5_np_factor", np_factor); diff --git a/src/mapgen/mapgen_v6.cpp b/src/mapgen/mapgen_v6.cpp index aa4146982a..a08a244771 100644 --- a/src/mapgen/mapgen_v6.cpp +++ b/src/mapgen/mapgen_v6.cpp @@ -186,8 +186,8 @@ void MapgenV6Params::readParams(const Settings *settings) settings->getFlagStrNoEx("mgv6_spflags", spflags, flagdesc_mapgen_v6); settings->getFloatNoEx("mgv6_freq_desert", freq_desert); settings->getFloatNoEx("mgv6_freq_beach", freq_beach); - settings->getPOSNoEx("mgv6_dungeon_ymin", dungeon_ymin); - settings->getPOSNoEx("mgv6_dungeon_ymax", dungeon_ymax); + settings->getPosNoEx("mgv6_dungeon_ymin", dungeon_ymin); + settings->getPosNoEx("mgv6_dungeon_ymax", dungeon_ymax); settings->getNoiseParams("mgv6_np_terrain_base", np_terrain_base); settings->getNoiseParams("mgv6_np_terrain_higher", np_terrain_higher); @@ -208,8 +208,8 @@ void MapgenV6Params::writeParams(Settings *settings) const settings->setFlagStr("mgv6_spflags", spflags, flagdesc_mapgen_v6); settings->setFloat("mgv6_freq_desert", freq_desert); settings->setFloat("mgv6_freq_beach", freq_beach); - settings->setPOS("mgv6_dungeon_ymin", dungeon_ymin); - settings->setPOS("mgv6_dungeon_ymax", dungeon_ymax); + settings->setPos("mgv6_dungeon_ymin", dungeon_ymin); + settings->setPos("mgv6_dungeon_ymax", dungeon_ymax); settings->setNoiseParams("mgv6_np_terrain_base", np_terrain_base); settings->setNoiseParams("mgv6_np_terrain_higher", np_terrain_higher); diff --git a/src/mapgen/mapgen_v7.cpp b/src/mapgen/mapgen_v7.cpp index 0293fdfce9..571617558d 100644 --- a/src/mapgen/mapgen_v7.cpp +++ b/src/mapgen/mapgen_v7.cpp @@ -172,26 +172,26 @@ MapgenV7Params::MapgenV7Params(): void MapgenV7Params::readParams(const Settings *settings) { settings->getFlagStrNoEx("mgv7_spflags", spflags, flagdesc_mapgen_v7); - settings->getPOSNoEx("mgv7_mount_zero_level", mount_zero_level); - settings->getPOSNoEx("mgv7_floatland_ymin", floatland_ymin); - settings->getPOSNoEx("mgv7_floatland_ymax", floatland_ymax); - settings->getPOSNoEx("mgv7_floatland_taper", floatland_taper); + settings->getPosNoEx("mgv7_mount_zero_level", mount_zero_level); + settings->getPosNoEx("mgv7_floatland_ymin", floatland_ymin); + settings->getPosNoEx("mgv7_floatland_ymax", floatland_ymax); + settings->getPosNoEx("mgv7_floatland_taper", floatland_taper); settings->getFloatNoEx("mgv7_float_taper_exp", float_taper_exp); settings->getFloatNoEx("mgv7_floatland_density", floatland_density); - settings->getPOSNoEx("mgv7_floatland_ywater", floatland_ywater); + settings->getPosNoEx("mgv7_floatland_ywater", floatland_ywater); settings->getFloatNoEx("mgv7_cave_width", cave_width); - settings->getPOSNoEx("mgv7_large_cave_depth", large_cave_depth); + settings->getPosNoEx("mgv7_large_cave_depth", large_cave_depth); settings->getU16NoEx("mgv7_small_cave_num_min", small_cave_num_min); settings->getU16NoEx("mgv7_small_cave_num_max", small_cave_num_max); settings->getU16NoEx("mgv7_large_cave_num_min", large_cave_num_min); settings->getU16NoEx("mgv7_large_cave_num_max", large_cave_num_max); settings->getFloatNoEx("mgv7_large_cave_flooded", large_cave_flooded); - settings->getPOSNoEx("mgv7_cavern_limit", cavern_limit); - settings->getPOSNoEx("mgv7_cavern_taper", cavern_taper); + settings->getPosNoEx("mgv7_cavern_limit", cavern_limit); + settings->getPosNoEx("mgv7_cavern_taper", cavern_taper); settings->getFloatNoEx("mgv7_cavern_threshold", cavern_threshold); - settings->getPOSNoEx("mgv7_dungeon_ymin", dungeon_ymin); - settings->getPOSNoEx("mgv7_dungeon_ymax", dungeon_ymax); + settings->getPosNoEx("mgv7_dungeon_ymin", dungeon_ymin); + settings->getPosNoEx("mgv7_dungeon_ymax", dungeon_ymax); settings->getNoiseParams("mgv7_np_terrain_base", np_terrain_base); settings->getNoiseParams("mgv7_np_terrain_alt", np_terrain_alt); @@ -213,26 +213,26 @@ void MapgenV7Params::readParams(const Settings *settings) void MapgenV7Params::writeParams(Settings *settings) const { settings->setFlagStr("mgv7_spflags", spflags, flagdesc_mapgen_v7); - settings->setPOS("mgv7_mount_zero_level", mount_zero_level); - settings->setPOS("mgv7_floatland_ymin", floatland_ymin); - settings->setPOS("mgv7_floatland_ymax", floatland_ymax); - settings->setPOS("mgv7_floatland_taper", floatland_taper); + settings->setPos("mgv7_mount_zero_level", mount_zero_level); + settings->setPos("mgv7_floatland_ymin", floatland_ymin); + settings->setPos("mgv7_floatland_ymax", floatland_ymax); + settings->setPos("mgv7_floatland_taper", floatland_taper); settings->setFloat("mgv7_float_taper_exp", float_taper_exp); settings->setFloat("mgv7_floatland_density", floatland_density); - settings->setPOS("mgv7_floatland_ywater", floatland_ywater); + settings->setPos("mgv7_floatland_ywater", floatland_ywater); settings->setFloat("mgv7_cave_width", cave_width); - settings->setPOS("mgv7_large_cave_depth", large_cave_depth); + settings->setPos("mgv7_large_cave_depth", large_cave_depth); settings->setU16("mgv7_small_cave_num_min", small_cave_num_min); settings->setU16("mgv7_small_cave_num_max", small_cave_num_max); settings->setU16("mgv7_large_cave_num_min", large_cave_num_min); settings->setU16("mgv7_large_cave_num_max", large_cave_num_max); settings->setFloat("mgv7_large_cave_flooded", large_cave_flooded); - settings->setPOS("mgv7_cavern_limit", cavern_limit); - settings->setPOS("mgv7_cavern_taper", cavern_taper); + settings->setPos("mgv7_cavern_limit", cavern_limit); + settings->setPos("mgv7_cavern_taper", cavern_taper); settings->setFloat("mgv7_cavern_threshold", cavern_threshold); - settings->setPOS("mgv7_dungeon_ymin", dungeon_ymin); - settings->setPOS("mgv7_dungeon_ymax", dungeon_ymax); + settings->setPos("mgv7_dungeon_ymin", dungeon_ymin); + settings->setPos("mgv7_dungeon_ymax", dungeon_ymax); settings->setNoiseParams("mgv7_np_terrain_base", np_terrain_base); settings->setNoiseParams("mgv7_np_terrain_alt", np_terrain_alt); diff --git a/src/mapgen/mapgen_valleys.cpp b/src/mapgen/mapgen_valleys.cpp index 9caf945803..089b60a163 100644 --- a/src/mapgen/mapgen_valleys.cpp +++ b/src/mapgen/mapgen_valleys.cpp @@ -131,7 +131,7 @@ void MapgenValleysParams::readParams(const Settings *settings) { settings->getFlagStrNoEx("mgvalleys_spflags", spflags, flagdesc_mapgen_valleys); settings->getU16NoEx("mgvalleys_altitude_chill", altitude_chill); - settings->getPOSNoEx("mgvalleys_large_cave_depth", large_cave_depth); + settings->getPosNoEx("mgvalleys_large_cave_depth", large_cave_depth); settings->getU16NoEx("mgvalleys_small_cave_num_min", small_cave_num_min); settings->getU16NoEx("mgvalleys_small_cave_num_max", small_cave_num_max); settings->getU16NoEx("mgvalleys_large_cave_num_min", large_cave_num_min); @@ -140,11 +140,11 @@ void MapgenValleysParams::readParams(const Settings *settings) settings->getU16NoEx("mgvalleys_river_depth", river_depth); settings->getU16NoEx("mgvalleys_river_size", river_size); settings->getFloatNoEx("mgvalleys_cave_width", cave_width); - settings->getPOSNoEx("mgvalleys_cavern_limit", cavern_limit); - settings->getPOSNoEx("mgvalleys_cavern_taper", cavern_taper); + settings->getPosNoEx("mgvalleys_cavern_limit", cavern_limit); + settings->getPosNoEx("mgvalleys_cavern_taper", cavern_taper); settings->getFloatNoEx("mgvalleys_cavern_threshold", cavern_threshold); - settings->getPOSNoEx("mgvalleys_dungeon_ymin", dungeon_ymin); - settings->getPOSNoEx("mgvalleys_dungeon_ymax", dungeon_ymax); + settings->getPosNoEx("mgvalleys_dungeon_ymin", dungeon_ymin); + settings->getPosNoEx("mgvalleys_dungeon_ymax", dungeon_ymax); settings->getNoiseParams("mgvalleys_np_filler_depth", np_filler_depth); settings->getNoiseParams("mgvalleys_np_inter_valley_fill", np_inter_valley_fill); @@ -165,7 +165,7 @@ void MapgenValleysParams::writeParams(Settings *settings) const { settings->setFlagStr("mgvalleys_spflags", spflags, flagdesc_mapgen_valleys); settings->setU16("mgvalleys_altitude_chill", altitude_chill); - settings->setPOS("mgvalleys_large_cave_depth", large_cave_depth); + settings->setPos("mgvalleys_large_cave_depth", large_cave_depth); settings->setU16("mgvalleys_small_cave_num_min", small_cave_num_min); settings->setU16("mgvalleys_small_cave_num_max", small_cave_num_max); settings->setU16("mgvalleys_large_cave_num_min", large_cave_num_min); @@ -174,11 +174,11 @@ void MapgenValleysParams::writeParams(Settings *settings) const settings->setU16("mgvalleys_river_depth", river_depth); settings->setU16("mgvalleys_river_size", river_size); settings->setFloat("mgvalleys_cave_width", cave_width); - settings->setPOS("mgvalleys_cavern_limit", cavern_limit); - settings->setPOS("mgvalleys_cavern_taper", cavern_taper); + settings->setPos("mgvalleys_cavern_limit", cavern_limit); + settings->setPos("mgvalleys_cavern_taper", cavern_taper); settings->setFloat("mgvalleys_cavern_threshold", cavern_threshold); - settings->setPOS("mgvalleys_dungeon_ymin", dungeon_ymin); - settings->setPOS("mgvalleys_dungeon_ymax", dungeon_ymax); + settings->setPos("mgvalleys_dungeon_ymin", dungeon_ymin); + settings->setPos("mgvalleys_dungeon_ymax", dungeon_ymax); settings->setNoiseParams("mgvalleys_np_filler_depth", np_filler_depth); settings->setNoiseParams("mgvalleys_np_inter_valley_fill", np_inter_valley_fill); diff --git a/src/server.cpp b/src/server.cpp index ab8a73ecc2..813b4a9110 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -958,7 +958,7 @@ void Server::AsyncRunStep(bool initial_step) Set blocks not sent to far players */ if (!far_players.empty()) { - // Convert libst format to that wanted by SetBlocksNotSent + // Convert libs format to that wanted by SetBlocksNotSent std::map modified_blocks2; for (const v3bpos_t &modified_block : event->modified_blocks) { modified_blocks2[modified_block] = diff --git a/src/settings.cpp b/src/settings.cpp index 129caa8049..5795809f58 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -528,7 +528,7 @@ s32 Settings::getS32(const std::string &name) const return stoi(get(name)); } -pos_t Settings::getPOS(const std::string &name) const +pos_t Settings::getPos(const std::string &name) const { return stoi(get(name)); } @@ -791,7 +791,7 @@ bool Settings::getS32NoEx(const std::string &name, s32 &val) const } -bool Settings::getPOSNoEx(const std::string &name, pos_t &val) const +bool Settings::getPosNoEx(const std::string &name, pos_t &val) const { #if USE_POS32 return getS32NoEx(name, val); @@ -935,7 +935,7 @@ bool Settings::setS32(const std::string &name, s32 value) return set(name, itos(value)); } -bool Settings::setPOS(const std::string &name, pos_t value) +bool Settings::setPos(const std::string &name, pos_t value) { return set(name, itos(value)); } diff --git a/src/settings.h b/src/settings.h index b5b82700bc..b3edbf69cd 100644 --- a/src/settings.h +++ b/src/settings.h @@ -163,7 +163,7 @@ class Settings { u32 getU32(const std::string &name) const; s32 getS32(const std::string &name) const; u64 getU64(const std::string &name) const; - pos_t getPOS(const std::string &name) const; + pos_t getPos(const std::string &name) const; float getFloat(const std::string &name) const; float getFloat(const std::string &name, float min, float max) const; v2f getV2F(const std::string &name) const; @@ -193,7 +193,7 @@ class Settings { bool getS16NoEx(const std::string &name, s16 &val) const; bool getU32NoEx(const std::string &name, u32 &val) const; bool getS32NoEx(const std::string &name, s32 &val) const; - bool getPOSNoEx(const std::string &name, pos_t &val) const; + bool getPosNoEx(const std::string &name, pos_t &val) const; bool getU64NoEx(const std::string &name, u64 &val) const; bool getFloatNoEx(const std::string &name, float &val) const; bool getV2FNoEx(const std::string &name, v2f &val) const; @@ -222,7 +222,7 @@ class Settings { bool setU16(const std::string &name, u16 value); bool setS32(const std::string &name, s32 value); bool setU64(const std::string &name, u64 value); - bool setPOS(const std::string &name, pos_t value); + bool setPos(const std::string &name, pos_t value); bool setFloat(const std::string &name, float value); bool setV2F(const std::string &name, v2f value); bool setV3F(const std::string &name, v3f value); From 0a3f4e5acd8b255b77637cac23530b89a18d8c91 Mon Sep 17 00:00:00 2001 From: proller Date: Thu, 26 Jan 2023 00:33:24 +0300 Subject: [PATCH 28/36] Fix --- src/network/networkpacket.cpp | 13 +++++++------ src/network/networkpacket.h | 6 +++--- src/network/networkprotocol.h | 3 +++ src/util/areastore.cpp | 8 ++++---- src/util/pointedthing.cpp | 12 ++++++------ src/util/serialize.h | 17 +++++++++-------- 6 files changed, 32 insertions(+), 27 deletions(-) diff --git a/src/network/networkpacket.cpp b/src/network/networkpacket.cpp index 5fb03947d1..cd11e04072 100644 --- a/src/network/networkpacket.cpp +++ b/src/network/networkpacket.cpp @@ -19,6 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "networkpacket.h" #include +#include "log.h" #include "networkexceptions.h" #include "util/serialize.h" #include "networkprotocol.h" @@ -444,10 +445,10 @@ NetworkPacket& NetworkPacket::operator>>(v3f& dst) return *this; } -#if USE_POS32 +#if USE_OPOS64 NetworkPacket& NetworkPacket::operator>>(v3opos_t& dst) { - if (m_proto_ver < 41) { + if (m_proto_ver < PROTOCOL_VERSION_32BIT) { v3f tmp; *this >> tmp; dst = v3fToOpos(tmp); @@ -528,7 +529,7 @@ v3s32 NetworkPacket::readV3S32() #if USE_POS32 NetworkPacket& NetworkPacket::operator>>(v3pos_t& dst) { - if (m_proto_ver < 41) { + if (m_proto_ver < PROTOCOL_VERSION_32BIT) { v3s16 tmp; *this >> tmp; dst = s16ToPos(tmp); @@ -559,10 +560,10 @@ NetworkPacket& NetworkPacket::operator<<(v3f src) return *this; } -#if USE_POS32 +#if USE_OPOS64 NetworkPacket& NetworkPacket::operator<<(v3opos_t src) { - if (m_proto_ver < 41) { + if (m_proto_ver < PROTOCOL_VERSION_32BIT) { *this << oposToV3f(src); return *this; } @@ -592,7 +593,7 @@ NetworkPacket& NetworkPacket::operator<<(v2s32 src) #if USE_POS32 NetworkPacket& NetworkPacket::operator<<(v3pos_t src) { - if (m_proto_ver < 41) { + if (m_proto_ver < PROTOCOL_VERSION_32BIT) { *this << posToS16(src); return *this; } diff --git a/src/network/networkpacket.h b/src/network/networkpacket.h index c42928139b..69db32bc8b 100644 --- a/src/network/networkpacket.h +++ b/src/network/networkpacket.h @@ -27,11 +27,11 @@ with this program; if not, write to the Free Software Foundation, Inc., inline size_t sizeof_v3opos(u16 proto_ver) { - return proto_ver >= 41 ? sizeof(v3opos_t) : sizeof(v3f); + return proto_ver >= PROTOCOL_VERSION_32BIT ? sizeof(v3opos_t) : sizeof(v3f); } inline size_t sizeof_v3pos(u16 proto_ver) { - return proto_ver >= 41 ? sizeof(v3pos_t) : sizeof(v3s16); + return proto_ver >= PROTOCOL_VERSION_32BIT ? sizeof(v3pos_t) : sizeof(v3s16); } class NetworkPacket @@ -110,7 +110,7 @@ class NetworkPacket NetworkPacket &operator>>(v3f &dst); NetworkPacket &operator<<(v3f src); -#if USE_POS32 +#if USE_OPOS64 NetworkPacket &operator>>(v3opos_t &dst); NetworkPacket &operator<<(v3opos_t src); #endif diff --git a/src/network/networkprotocol.h b/src/network/networkprotocol.h index a3c6adca42..6a7a706888 100644 --- a/src/network/networkprotocol.h +++ b/src/network/networkprotocol.h @@ -221,6 +221,9 @@ with this program; if not, write to the Free Software Foundation, Inc., #define LATEST_PROTOCOL_VERSION 41 #endif +// First version with 32bit support +#define PROTOCOL_VERSION_32BIT 42 + #define LATEST_PROTOCOL_VERSION_STRING TOSTRING(LATEST_PROTOCOL_VERSION) // Server's supported network protocol range diff --git a/src/util/areastore.cpp b/src/util/areastore.cpp index 1c79530127..84b39563a8 100644 --- a/src/util/areastore.cpp +++ b/src/util/areastore.cpp @@ -75,8 +75,8 @@ void AreaStore::serialize(std::ostream &os) const writeU16(os, areas_map.size()); for (const auto &it : areas_map) { const Area &a = it.second; - writeV3POS(os, a.minedge); - writeV3POS(os, a.maxedge); + writeV3Pos(os, a.minedge); + writeV3Pos(os, a.maxedge); writeU16(os, a.data.size()); os.write(a.data.data(), a.data.size()); } @@ -99,8 +99,8 @@ void AreaStore::deserialize(std::istream &is) areas.reserve(num_areas); for (u32 i = 0; i < num_areas; ++i) { Area a(U32_MAX); - a.minedge = readV3POS(is); - a.maxedge = readV3POS(is); + a.minedge = readV3Pos(is); + a.maxedge = readV3Pos(is); u16 data_len = readU16(is); a.data = std::string(data_len, '\0'); is.read(&a.data[0], data_len); diff --git a/src/util/pointedthing.cpp b/src/util/pointedthing.cpp index 9645ea3fcd..4f543f195b 100644 --- a/src/util/pointedthing.cpp +++ b/src/util/pointedthing.cpp @@ -20,6 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "pointedthing.h" #include "gamedef.h" +#include "network/networkprotocol.h" #include "serialize.h" #include "exceptions.h" #include @@ -72,16 +73,15 @@ std::string PointedThing::dump() const void PointedThing::serialize(std::ostream &os, const u16 proto_ver) const { - - const int version = proto_ver >= 41 ? 1 : 0; + const int version = proto_ver >= PROTOCOL_VERSION_32BIT ? 1 : 0; writeU8(os, version); // version writeU8(os, (u8)type); switch (type) { case POINTEDTHING_NOTHING: break; case POINTEDTHING_NODE: - writeV3POS(os, node_undersurface, proto_ver); - writeV3POS(os, node_abovesurface, proto_ver); + writeV3Pos(os, node_undersurface, proto_ver); + writeV3Pos(os, node_abovesurface, proto_ver); break; case POINTEDTHING_OBJECT: writeS16(os, object_id); @@ -99,8 +99,8 @@ void PointedThing::deSerialize(std::istream &is) case POINTEDTHING_NOTHING: break; case POINTEDTHING_NODE: - node_undersurface = readV3POS(is, version >= 1 ? 41 : 40); - node_abovesurface = readV3POS(is, version >= 1 ? 41 : 40); + node_undersurface = readV3Pos(is, version >= 1 ? PROTOCOL_VERSION_32BIT : PROTOCOL_VERSION_32BIT - 1); + node_abovesurface = readV3Pos(is, version >= 1 ? PROTOCOL_VERSION_32BIT : PROTOCOL_VERSION_32BIT - 1); break; case POINTEDTHING_OBJECT: object_id = readS16(is); diff --git a/src/util/serialize.h b/src/util/serialize.h index 1bb07d3a4b..1f41afa956 100644 --- a/src/util/serialize.h +++ b/src/util/serialize.h @@ -23,6 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "exceptions.h" // for SerializationError #include "debug.h" // for assert #include "ieee_float.h" +#include "network/networkprotocol.h" #include "numeric.h" #include "config.h" @@ -471,7 +472,7 @@ MAKE_STREAM_WRITE_FXN(video::SColor, ARGB8, 4); inline pos_t readPOS(std::istream &is, const u16 proto_ver = 0) { #if USE_POS32 - if (proto_ver >= 41) + if (proto_ver >= PROTOCOL_VERSION_32BIT) return readS32(is); return readS16(is); #else @@ -481,7 +482,7 @@ inline pos_t readPOS(std::istream &is, const u16 proto_ver = 0) { inline void writePOS(std::ostream &os, pos_t i, const u16 proto_ver = 0) { #if USE_POS32 - if (proto_ver >= 41) + if (proto_ver >= PROTOCOL_VERSION_32BIT) return writeS32(os, i); return writeS16(os, i); #else @@ -489,9 +490,9 @@ inline void writePOS(std::ostream &os, pos_t i, const u16 proto_ver = 0) { #endif } -inline v3pos_t readV3POS(std::istream &is, const u16 proto_ver = 0) { +inline v3pos_t readV3Pos(std::istream &is, const u16 proto_ver = 0) { #if USE_POS32 - if (proto_ver >= 41) + if (proto_ver >= PROTOCOL_VERSION_32BIT) return readV3S32(is); return s16ToPos(readV3S16(is)); #else @@ -499,9 +500,9 @@ inline v3pos_t readV3POS(std::istream &is, const u16 proto_ver = 0) { #endif } -inline void writeV3POS(std::ostream &os, v3pos_t p, const u16 proto_ver = 0) { +inline void writeV3Pos(std::ostream &os, v3pos_t p, const u16 proto_ver = 0) { #if USE_POS32 - if (proto_ver >= 41) + if (proto_ver >= PROTOCOL_VERSION_32BIT) return writeV3S32(os, p); return writeV3S16(os, posToS16(p)); #else @@ -511,7 +512,7 @@ inline void writeV3POS(std::ostream &os, v3pos_t p, const u16 proto_ver = 0) { inline v3opos_t readV3O(std::istream &is, const u16 proto_ver = 0) { #if USE_OPOS64 - if (proto_ver >= 41) + if (proto_ver >= PROTOCOL_VERSION_32BIT) return readV3F64(is); return v3fToOpos(readV3F32(is)); #else @@ -521,7 +522,7 @@ inline v3opos_t readV3O(std::istream &is, const u16 proto_ver = 0) { inline void writeV3O(std::ostream &os, v3opos_t p, const u16 proto_ver = 0) { #if USE_OPOS64 - if (proto_ver >= 41) + if (proto_ver >= PROTOCOL_VERSION_32BIT) return writeV3F64(os, p); return writeV3F32(os, oposToV3f(p)); #else From 31f7abbddaa29c5e3667020767d0cf09154e7f70 Mon Sep 17 00:00:00 2001 From: proller Date: Sat, 28 Jan 2023 04:43:56 +0300 Subject: [PATCH 29/36] better opos --- src/client/localplayer.cpp | 8 ++++---- src/irr_v2d.h | 3 ++- src/server/player_sao.cpp | 8 ++++---- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/client/localplayer.cpp b/src/client/localplayer.cpp index e20f2e6c3f..bfbc2aae96 100644 --- a/src/client/localplayer.cpp +++ b/src/client/localplayer.cpp @@ -103,7 +103,7 @@ bool LocalPlayer::updateSneakNode(Map *map, const v3opos_t &position, for (const auto &d : dir9_center) { const v3pos_t p = current_node + d; const auto pf = intToFloat(p, BS); - const v2f diff(position.X - pf.X, position.Z - pf.Z); + const v2opos_t diff(position.X - pf.X, position.Z - pf.Z); f32 distance_f = diff.getLength(); if (distance_f > min_distance_f || @@ -307,7 +307,7 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d, // Add new collisions to the vector if (collision_info && !free_move) { auto diff = posToOpos(m_standing_node, BS) - position; - f32 distance = diff.getLength(); + auto distance = diff.getLength(); // Force update each ClientEnvironment::step() bool is_first = collision_info->empty(); @@ -322,7 +322,7 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d, diff = posToOpos(colinfo.node_p, BS) - position; // Find nearest colliding node - f32 len = diff.getLength(); + auto len = diff.getLength(); if (is_first || len < distance) { m_standing_node = colinfo.node_p; distance = len; @@ -359,7 +359,7 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d, const v3opos_t bmax = sn_f + v3fToOpos(m_sneak_node_bb_top.MaxEdge); const v3opos_t old_pos = position; const v3f old_speed = m_speed; - f32 y_diff = bmax.Y - position.Y; + const auto y_diff = bmax.Y - position.Y; m_standing_node = m_sneak_node; // (BS * 0.6f) is the basic stepheight while standing on ground diff --git a/src/irr_v2d.h b/src/irr_v2d.h index ca2399bea2..ad0ac7d19e 100644 --- a/src/irr_v2d.h +++ b/src/irr_v2d.h @@ -30,4 +30,5 @@ typedef core::vector2d v2u32; typedef core::vector2d v2f32; using v2pos_t = core::vector2d; -using v2bpos_t = core::vector2d; \ No newline at end of file +using v2bpos_t = core::vector2d; +using v2opos_t = core::vector2d; diff --git a/src/server/player_sao.cpp b/src/server/player_sao.cpp index 27d5793186..fc45b52227 100644 --- a/src/server/player_sao.cpp +++ b/src/server/player_sao.cpp @@ -620,16 +620,16 @@ bool PlayerSAO::checkMovementCheat() player_max_jump = 0.0001f; v3opos_t diff = (m_base_position - m_last_good_position); - float d_vert = diff.Y; + auto d_vert = diff.Y; diff.Y = 0; - float d_horiz = diff.getLength(); - float required_time = d_horiz / player_max_walk; + auto d_horiz = diff.getLength(); + auto required_time = d_horiz / player_max_walk; // FIXME: Checking downwards movement is not easily possible currently, // the server could calculate speed differences to examine the gravity if (d_vert > 0) { // In certain cases (water, ladders) walking speed is applied vertically - float s = MYMAX(player_max_jump, player_max_walk); + auto s = MYMAX(player_max_jump, player_max_walk); required_time = MYMAX(required_time, d_vert / s); } From f8b7f47bb549d6a011c1f8139aca197c6a41a64f Mon Sep 17 00:00:00 2001 From: proller Date: Thu, 20 Jul 2023 05:20:12 +0300 Subject: [PATCH 30/36] Fixes --- src/client/clientmap.cpp | 41 +++++++++++----------- src/client/mapblock_mesh.cpp | 16 ++++----- src/client/mesh_generator_thread.cpp | 5 +-- src/client/mesh_generator_thread.h | 7 ++-- src/dummymap.h | 11 +++--- src/map.cpp | 4 +-- src/map.h | 6 ++-- src/mapblock.cpp | 7 ++-- src/mapblock.h | 2 +- src/mapgen/mapgen.cpp | 7 ++-- src/mapgen/mapgen.h | 3 +- src/rollback.h | 2 +- src/script/common/c_converter.h | 3 +- src/script/cpp_api/s_env.cpp | 9 ++--- src/script/cpp_api/s_env.h | 4 +-- src/script/lua_api/l_mapgen.cpp | 11 +++--- src/server.cpp | 2 +- src/server.h | 2 +- src/serverenvironment.cpp | 5 +-- src/serverenvironment.h | 3 +- src/unittest/test_map.cpp | 39 +++++++++++---------- src/unittest/test_voxelalgorithms.cpp | 35 ++++++++++--------- src/util/directiontables.cpp | 50 +++++++++++++-------------- src/util/directiontables.h | 2 +- src/util/pointedthing.cpp | 3 +- 25 files changed, 149 insertions(+), 130 deletions(-) diff --git a/src/client/clientmap.cpp b/src/client/clientmap.cpp index a78aefd8a4..515eb0daaa 100644 --- a/src/client/clientmap.cpp +++ b/src/client/clientmap.cpp @@ -19,6 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "clientmap.h" #include "client.h" +#include "irr_v2d.h" #include "irr_v3d.h" #include "mapblock_mesh.h" #include @@ -169,7 +170,7 @@ void ClientMap::OnRegisterSceneNode() } void ClientMap::getBlocksInViewRange(v3pos_t cam_pos_nodes, - v3pos_t *p_blocks_min, v3pos_t *p_blocks_max, float range) + v3bpos_t *p_blocks_min, v3bpos_t *p_blocks_max, float range) { if (range <= 0.0f) range = m_control.wanted_range; @@ -188,11 +189,11 @@ void ClientMap::getBlocksInViewRange(v3pos_t cam_pos_nodes, cam_pos_nodes.Z + box_nodes_d.Z); // Take a fair amount as we will be dropping more out later // Umm... these additions are a bit strange but they are needed. - *p_blocks_min = v3pos_t( + *p_blocks_min = v3bpos_t( p_nodes_min.X / MAP_BLOCKSIZE - 3, p_nodes_min.Y / MAP_BLOCKSIZE - 3, p_nodes_min.Z / MAP_BLOCKSIZE - 3); - *p_blocks_max = v3pos_t( + *p_blocks_max = v3bpos_t( p_nodes_max.X / MAP_BLOCKSIZE + 1, p_nodes_max.Y / MAP_BLOCKSIZE + 1, p_nodes_max.Z / MAP_BLOCKSIZE + 1); @@ -205,7 +206,7 @@ class MapBlockFlags static constexpr u16 CHUNK_MASK = CHUNK_EDGE - 1; static constexpr std::size_t CHUNK_VOLUME = CHUNK_EDGE * CHUNK_EDGE * CHUNK_EDGE; // volume of a chunk - MapBlockFlags(v3s16 min_pos, v3s16 max_pos) + MapBlockFlags(v3bpos_t min_pos, v3bpos_t max_pos) : min_pos(min_pos), volume((max_pos - min_pos) / CHUNK_EDGE + 1) { chunks.resize(volume.X * volume.Y * volume.Z); @@ -214,14 +215,14 @@ class MapBlockFlags class Chunk { public: - inline u8 &getBits(v3s16 pos) + inline u8 &getBits(v3bpos_t pos) { std::size_t address = getAddress(pos); return bits[address]; } private: - inline std::size_t getAddress(v3s16 pos) { + inline std::size_t getAddress(v3bpos_t pos) { std::size_t address = (pos.X & CHUNK_MASK) + (pos.Y & CHUNK_MASK) * CHUNK_EDGE + (pos.Z & CHUNK_MASK) * (CHUNK_EDGE * CHUNK_EDGE); return address; } @@ -229,9 +230,9 @@ class MapBlockFlags std::array bits; }; - Chunk &getChunk(v3s16 pos) + Chunk &getChunk(v3bpos_t pos) { - v3s16 delta = (pos - min_pos) / CHUNK_EDGE; + v3bpos_t delta = (pos - min_pos) / CHUNK_EDGE; std::size_t address = delta.X + delta.Y * volume.X + delta.Z * volume.X * volume.Y; Chunk *chunk = chunks[address].get(); if (!chunk) { @@ -242,8 +243,8 @@ class MapBlockFlags } private: std::vector> chunks; - v3s16 min_pos; - v3s16 volume; + v3bpos_t min_pos; + v3bpos_t volume; }; void ClientMap::updateDrawList() @@ -289,7 +290,7 @@ void ClientMap::updateDrawList() // if (occlusion_culling_enabled && m_control.show_wireframe) // occlusion_culling_enabled = porting::getTimeS() & 1; - std::queue blocks_to_consider; + std::queue blocks_to_consider; // Bits per block: // [ visited | 0 | 0 | 0 | 0 | Z visible | Y visible | X visible ] @@ -302,7 +303,7 @@ void ClientMap::updateDrawList() // Recursively walk the space and pick mapblocks for drawing while (blocks_to_consider.size() > 0) { - v3s16 block_coord = blocks_to_consider.front(); + v3bpos_t block_coord = blocks_to_consider.front(); blocks_to_consider.pop(); auto &flags = blocks_seen.getChunk(block_coord).getBits(block_coord); @@ -315,7 +316,7 @@ void ClientMap::updateDrawList() blocks_visited++; // Get the sector, block and mesh - MapSector *sector = this->getSectorNoGenerate(v2s16(block_coord.X, block_coord.Z)); + MapSector *sector = this->getSectorNoGenerate(v2bpos_t(block_coord.X, block_coord.Z)); if (!sector) continue; @@ -329,7 +330,7 @@ void ClientMap::updateDrawList() v3f mesh_sphere_center; f32 mesh_sphere_radius; - v3s16 block_pos_nodes = block_coord * MAP_BLOCKSIZE; + v3pos_t block_pos_nodes = block_coord * MAP_BLOCKSIZE; if (mesh) { mesh_sphere_center = intToFloat(block_pos_nodes, BS) @@ -357,7 +358,7 @@ void ClientMap::updateDrawList() // Calculate the vector from the camera block to the current block // We use it to determine through which sides of the current block we can continue the search - v3s16 look = block_coord - camera_block; + v3bpos_t look = block_coord - camera_block; // Occluded near sides will further occlude the far sides u8 visible_outer_sides = flags & 0x07; @@ -422,7 +423,7 @@ void ClientMap::updateDrawList() // Calculate vector from camera to mapblock center. Because we only need relation between // coordinates we scale by 2 to avoid precision loss. - v3s16 precise_look = 2 * (block_pos_nodes - cam_pos_nodes) + MAP_BLOCKSIZE - 1; + v3bpos_t precise_look = 2 * (block_pos_nodes - cam_pos_nodes) + MAP_BLOCKSIZE - 1; // dominant axis flag u8 dominant_axis = (abs(precise_look.X) > abs(precise_look.Y) && abs(precise_look.X) > abs(precise_look.Z)) | @@ -448,7 +449,7 @@ void ClientMap::updateDrawList() bool side_visible = ((near_transparency & adjacent_sides) | (near_transparency & my_side & dominant_axis)) != 0; side_visible = side_visible && ((far_side_mask & transparent_sides) != 0); - v3s16 next_pos = block_coord; + v3bpos_t next_pos = block_coord; next_pos[axis] += next_pos_offset; // If a side is a see-through, mark the next block's side as visible, and queue @@ -483,10 +484,10 @@ void ClientMap::updateDrawList() void ClientMap::touchMapBlocks() { - v3s16 cam_pos_nodes = floatToInt(m_camera_position, BS); + v3pos_t cam_pos_nodes = floatToInt(m_camera_position, BS); - v3s16 p_blocks_min; - v3s16 p_blocks_max; + v3bpos_t p_blocks_min; + v3bpos_t p_blocks_max; getBlocksInViewRange(cam_pos_nodes, &p_blocks_min, &p_blocks_max); // Number of blocks currently loaded by the client diff --git a/src/client/mapblock_mesh.cpp b/src/client/mapblock_mesh.cpp index 43e35c8fd2..88e054f18e 100644 --- a/src/client/mapblock_mesh.cpp +++ b/src/client/mapblock_mesh.cpp @@ -1586,20 +1586,20 @@ video::SColor encode_light(u16 light, u8 emissive_light) u8 get_solid_sides(MeshMakeData *data) { - v3s16 blockpos_nodes = data->m_blockpos * MAP_BLOCKSIZE; + v3pos_t blockpos_nodes = data->m_blockpos * MAP_BLOCKSIZE; const NodeDefManager *ndef = data->m_client->ndef(); u8 result = 0x3F; // all sides solid; for (s16 i = 0; i < MAP_BLOCKSIZE && result != 0; i++) for (s16 j = 0; j < MAP_BLOCKSIZE && result != 0; j++) { - v3s16 positions[6] = { - v3s16(0, i, j), - v3s16(MAP_BLOCKSIZE - 1, i, j), - v3s16(i, 0, j), - v3s16(i, MAP_BLOCKSIZE - 1, j), - v3s16(i, j, 0), - v3s16(i, j, MAP_BLOCKSIZE - 1) + v3pos_t positions[6] = { + v3pos_t(0, i, j), + v3pos_t(MAP_BLOCKSIZE - 1, i, j), + v3pos_t(i, 0, j), + v3pos_t(i, MAP_BLOCKSIZE - 1, j), + v3pos_t(i, j, 0), + v3pos_t(i, j, MAP_BLOCKSIZE - 1) }; for (u8 k = 0; k < 6; k++) { diff --git a/src/client/mesh_generator_thread.cpp b/src/client/mesh_generator_thread.cpp index 5e3f01011c..eb6ae1c221 100644 --- a/src/client/mesh_generator_thread.cpp +++ b/src/client/mesh_generator_thread.cpp @@ -18,6 +18,7 @@ with this program; if not, write to the Free Software Foundation, Inc., */ #include "mesh_generator_thread.h" +#include "irr_v3d.h" #include "settings.h" #include "profiler.h" #include "client.h" @@ -106,7 +107,7 @@ bool MeshUpdateQueue::addBlock(Map *map, v3bpos_t p, bool ack_block_to_server, b cached_blocks.reserve(3*3*3); cached_blocks.push_back(main_block); main_block->refGrab(); - for (v3s16 dp : g_26dirs) { + for (v3pos_t dp : g_26dirs) { MapBlock *block = map->getBlockNoCreateNoEx(p + dp); cached_blocks.push_back(block); if (block) @@ -185,7 +186,7 @@ void MeshUpdateQueue::fillDataFromMapBlocks(QueuedMeshUpdate *q) MeshUpdateWorkerThread */ -MeshUpdateWorkerThread::MeshUpdateWorkerThread(MeshUpdateQueue *queue_in, MeshUpdateManager *manager, v3s16 *camera_offset) : +MeshUpdateWorkerThread::MeshUpdateWorkerThread(MeshUpdateQueue *queue_in, MeshUpdateManager *manager, v3pos_t *camera_offset) : UpdateThread("Mesh"), m_queue_in(queue_in), m_manager(manager), m_camera_offset(camera_offset) { m_generation_interval = g_settings->getU16("mesh_generation_interval"); diff --git a/src/client/mesh_generator_thread.h b/src/client/mesh_generator_thread.h index e2c3301ff0..316994a79e 100644 --- a/src/client/mesh_generator_thread.h +++ b/src/client/mesh_generator_thread.h @@ -23,6 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include #include +#include "irr_v3d.h" #include "mapblock_mesh.h" #include "threading/mutex_auto_lock.h" #include "util/thread.h" @@ -68,7 +69,7 @@ class MeshUpdateQueue QueuedMeshUpdate *pop(); // Marks a position as finished, unblocking the next update - void done(v3s16 pos); + void done(v3pos_t pos); u32 size() { @@ -109,7 +110,7 @@ class MeshUpdateManager; class MeshUpdateWorkerThread : public UpdateThread { public: - MeshUpdateWorkerThread(MeshUpdateQueue *queue_in, MeshUpdateManager *manager, v3s16 *camera_offset); + MeshUpdateWorkerThread(MeshUpdateQueue *queue_in, MeshUpdateManager *manager, v3pos_t *camera_offset); protected: virtual void doUpdate(); @@ -117,7 +118,7 @@ class MeshUpdateWorkerThread : public UpdateThread private: MeshUpdateQueue *m_queue_in; MeshUpdateManager *m_manager; - v3s16 *m_camera_offset; + v3pos_t *m_camera_offset; // TODO: Add callback to update these when g_settings changes int m_generation_interval; diff --git a/src/dummymap.h b/src/dummymap.h index 5f28813718..34d178cc38 100644 --- a/src/dummymap.h +++ b/src/dummymap.h @@ -19,17 +19,20 @@ with this program; if not, write to the Free Software Foundation, Inc., #pragma once +#include "irr_v2d.h" +#include "irr_v3d.h" +#include "irrlichttypes.h" #include "map.h" #include "mapsector.h" class DummyMap : public Map { public: - DummyMap(IGameDef *gamedef, v3s16 bpmin, v3s16 bpmax): Map(gamedef) + DummyMap(IGameDef *gamedef, v3bpos_t bpmin, v3bpos_t bpmax): Map(gamedef) { - for (s16 z = bpmin.Z; z <= bpmax.Z; z++) - for (s16 x = bpmin.X; x <= bpmax.X; x++) { - v2s16 p2d(x, z); + for (bpos_t z = bpmin.Z; z <= bpmax.Z; z++) + for (bpos_t x = bpmin.X; x <= bpmax.X; x++) { + v2bpos_t p2d(x, z); MapSector *sector = new MapSector(this, p2d, gamedef); m_sectors[p2d] = sector; for (s16 y = bpmin.Y; y <= bpmax.Y; y++) diff --git a/src/map.cpp b/src/map.cpp index 6e34dc1225..a421c8157f 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -529,7 +529,7 @@ void ServerMap::transformLiquids(std::map &modified_blocks, std::vector > changed_nodes; - std::vector check_for_falling; + std::vector check_for_falling; u32 liquid_loop_max = g_settings->getS32("liquid_loop_max"); u32 loop_max = liquid_loop_max; @@ -843,7 +843,7 @@ void ServerMap::transformLiquids(std::map &modified_blocks, voxalgo::update_lighting_nodes(this, changed_nodes, modified_blocks); - for (const v3s16 &p : check_for_falling) { + for (const v3pos_t &p : check_for_falling) { env->getScriptIface()->check_for_falling(p); } diff --git a/src/map.h b/src/map.h index fe2b570a5a..0ad71840ac 100644 --- a/src/map.h +++ b/src/map.h @@ -83,14 +83,14 @@ struct MapEditEvent MapEditEvent() = default; // Sets the event's position and marks the block as modified. - void setPositionModified(v3s16 pos) + void setPositionModified(v3pos_t pos) { assert(modified_blocks.empty()); // only meant for initialization (once) p = pos; modified_blocks.push_back(getNodeBlockPos(pos)); } - void setModifiedBlocks(const std::map blocks) + void setModifiedBlocks(const std::map blocks) { assert(modified_blocks.empty()); // only meant for initialization (once) modified_blocks.reserve(blocks.size()); @@ -309,7 +309,7 @@ class Map /*: public NodeContainer*/ } } - bool isBlockOccluded(MapBlock *block, v3s16 cam_pos_nodes); + bool isBlockOccluded(MapBlock *block, v3pos_t cam_pos_nodes); protected: IGameDef *m_gamedef; diff --git a/src/mapblock.cpp b/src/mapblock.cpp index d24908acd6..50606d246b 100644 --- a/src/mapblock.cpp +++ b/src/mapblock.cpp @@ -20,6 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "mapblock.h" #include +#include "irr_v3d.h" #include "map.h" #include "light.h" #include "nodedef.h" @@ -125,13 +126,13 @@ bool MapBlock::saveStaticObject(u16 id, const StaticObject &obj, u32 reason) } // This method is only for Server, don't call it on client -void MapBlock::step(float dtime, const std::function &on_timer_cb) +void MapBlock::step(float dtime, const std::function &on_timer_cb) { // Run script callbacks for elapsed node_timers std::vector elapsed_timers = m_node_timers.step(dtime); if (!elapsed_timers.empty()) { MapNode n; - v3s16 p; + v3pos_t p; for (const NodeTimer &elapsed_timer : elapsed_timers) { n = getNodeNoEx(elapsed_timer.position); p = elapsed_timer.position + getPosRelative(); @@ -910,7 +911,7 @@ std::string analyze_block(MapBlock *block) for(s16 y0=0; y0getNodeNoEx(p); content_t c = n.getContent(); if(c == CONTENT_IGNORE) diff --git a/src/mapblock.h b/src/mapblock.h index ba788bdb46..2937d3cf4a 100644 --- a/src/mapblock.h +++ b/src/mapblock.h @@ -329,7 +329,7 @@ class MapBlock bool onObjectsActivation(); bool saveStaticObject(u16 id, const StaticObject &obj, u32 reason); - void step(float dtime, const std::function &on_timer_cb); + void step(float dtime, const std::function &on_timer_cb); //// //// Timestamp (see m_timestamp) diff --git a/src/mapgen/mapgen.cpp b/src/mapgen/mapgen.cpp index 6cb09d5849..b4240fb0e7 100644 --- a/src/mapgen/mapgen.cpp +++ b/src/mapgen/mapgen.cpp @@ -20,6 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc., */ #include +#include "irrlichttypes.h" #include "mapgen.h" #include "voxel.h" #include "noise.h" @@ -1066,7 +1067,7 @@ void MapgenParams::writeParams(Settings *settings) const s32 MapgenParams::getSpawnRangeMax() { if (!m_mapgen_edges_calculated) { - std::pair edges = get_mapgen_edges(mapgen_limit, chunksize); + std::pair edges = get_mapgen_edges(mapgen_limit, chunksize); mapgen_edge_min = edges.first; mapgen_edge_max = edges.second; m_mapgen_edges_calculated = true; @@ -1076,7 +1077,7 @@ s32 MapgenParams::getSpawnRangeMax() } -std::pair get_mapgen_edges(s16 mapgen_limit, s16 chunksize) +std::pair get_mapgen_edges(pos_t mapgen_limit, s16 chunksize) { // Central chunk offset, in blocks s16 ccoff_b = -chunksize / 2; @@ -1100,5 +1101,5 @@ std::pair get_mapgen_edges(s16 mapgen_limit, s16 chunksize) pos_t numcmin = MYMAX((ccfmin - mapgen_limit_min) / csize_n, 0); pos_t numcmax = MYMAX((mapgen_limit_max - ccfmax) / csize_n, 0); // Mapgen edges, in nodes - return std::pair(ccmin - numcmin * csize_n, ccmax + numcmax * csize_n); + return std::pair(ccmin - numcmin * csize_n, ccmax + numcmax * csize_n); } diff --git a/src/mapgen/mapgen.h b/src/mapgen/mapgen.h index af321907fd..3d40f9ee3a 100644 --- a/src/mapgen/mapgen.h +++ b/src/mapgen/mapgen.h @@ -22,6 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #pragma once #include "irr_v3d.h" +#include "irrlichttypes.h" #include "noise.h" #include "nodedef.h" #include "util/string.h" @@ -333,4 +334,4 @@ class MapgenBasic : public Mapgen { // Calculate exact edges of the outermost mapchunks that are within the set // mapgen_limit. Returns the minimum and maximum edges in nodes in that order. -std::pair get_mapgen_edges(s16 mapgen_limit, s16 chunksize); +std::pair get_mapgen_edges(pos_t mapgen_limit, s16 chunksize); diff --git a/src/rollback.h b/src/rollback.h index c965cb6b51..05c9ebae95 100644 --- a/src/rollback.h +++ b/src/rollback.h @@ -73,7 +73,7 @@ class RollbackManager: public IRollbackManager int range, int limit); const std::list getActionsSince(time_t firstTime, const std::string & actor = ""); - static float getSuspectNearness(bool is_guess, v3s16 suspect_p, + static float getSuspectNearness(bool is_guess, v3pos_t suspect_p, time_t suspect_t, v3pos_t action_p, time_t action_t); diff --git a/src/script/common/c_converter.h b/src/script/common/c_converter.h index 9900954902..d48f9ba03f 100644 --- a/src/script/common/c_converter.h +++ b/src/script/common/c_converter.h @@ -29,6 +29,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include +#include "irr_v3d.h" #include "irrlichttypes_bloated.h" #include "common/c_types.h" @@ -154,7 +155,7 @@ size_t write_array_slice_float(lua_State *L, int table_index, float *data, // This must match the implementation in builtin/game/misc_s.lua // Note that this returns a floating point result as Lua integers are 32-bit -inline lua_Number hash_node_position(v3s16 pos) +inline lua_Number hash_node_position(v3pos_t pos) { return (((s64)pos.Z + 0x8000L) << 32) | (((s64)pos.Y + 0x8000L) << 16) diff --git a/src/script/cpp_api/s_env.cpp b/src/script/cpp_api/s_env.cpp index 099e48c1ab..c5bdd9af60 100644 --- a/src/script/cpp_api/s_env.cpp +++ b/src/script/cpp_api/s_env.cpp @@ -20,6 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "cpp_api/s_env.h" #include "cpp_api/s_internal.h" #include "common/c_converter.h" +#include "irr_v3d.h" #include "log.h" #include "environment.h" #include "mapgen/mapgen.h" @@ -257,7 +258,7 @@ void ScriptApiEnv::on_emerge_area_completion( } } -void ScriptApiEnv::check_for_falling(v3s16 p) +void ScriptApiEnv::check_for_falling(v3pos_t p) { SCRIPTAPI_PRECHECKHEADER @@ -265,7 +266,7 @@ void ScriptApiEnv::check_for_falling(v3s16 p) lua_getglobal(L, "core"); lua_getfield(L, -1, "check_for_falling"); luaL_checktype(L, -1, LUA_TFUNCTION); - push_v3s16(L, p); + push_v3pos(L, p); PCALL_RES(lua_pcall(L, 1, 0, error_handler)); } @@ -300,7 +301,7 @@ void ScriptApiEnv::on_liquid_transformed( runCallbacks(2, RUN_CALLBACKS_MODE_FIRST); } -void ScriptApiEnv::on_mapblocks_changed(const std::unordered_set &set) +void ScriptApiEnv::on_mapblocks_changed(const std::unordered_set &set) { SCRIPTAPI_PRECHECKHEADER @@ -312,7 +313,7 @@ void ScriptApiEnv::on_mapblocks_changed(const std::unordered_set &set) // Convert the set to a set of position hashes lua_createtable(L, 0, set.size()); - for(const v3s16 &p : set) { + for(const v3bpos_t &p : set) { lua_pushnumber(L, hash_node_position(p)); lua_pushboolean(L, true); lua_rawset(L, -3); diff --git a/src/script/cpp_api/s_env.h b/src/script/cpp_api/s_env.h index de05c756ae..416ce0ca65 100644 --- a/src/script/cpp_api/s_env.h +++ b/src/script/cpp_api/s_env.h @@ -44,13 +44,13 @@ class ScriptApiEnv : virtual public ScriptApiBase void on_emerge_area_completion(v3bpos_t blockpos, int action, ScriptCallbackState *state); - void check_for_falling(v3s16 p); + void check_for_falling(v3pos_t p); // Called after liquid transform changes void on_liquid_transformed(const std::vector> &list); // Called after mapblock changes - void on_mapblocks_changed(const std::unordered_set &set); + void on_mapblocks_changed(const std::unordered_set &set); // Determines whether there are any on_mapblocks_changed callbacks bool has_on_mapblocks_changed(); diff --git a/src/script/lua_api/l_mapgen.cpp b/src/script/lua_api/l_mapgen.cpp index 051cb2ab37..1adbe722f5 100644 --- a/src/script/lua_api/l_mapgen.cpp +++ b/src/script/lua_api/l_mapgen.cpp @@ -18,11 +18,14 @@ with this program; if not, write to the Free Software Foundation, Inc., */ #include "lua_api/l_mapgen.h" +#include "irr_v3d.h" +#include "irrlichttypes.h" #include "lua_api/l_internal.h" #include "lua_api/l_vmanip.h" #include "common/c_converter.h" #include "common/c_content.h" #include "cpp_api/s_security.h" +#include "server/player_sao.h" #include "util/serialize.h" #include "server.h" #include "environment.h" @@ -821,7 +824,7 @@ int ModApiMapgen::l_get_mapgen_edges(lua_State *L) // make mapgen settings immutable from then on. Mapgen settings should stay // mutable until after mod loading ends. - s16 mapgen_limit; + pos_t mapgen_limit; if (lua_isnumber(L, 1)) { mapgen_limit = lua_tointeger(L, 1); } else { @@ -839,9 +842,9 @@ int ModApiMapgen::l_get_mapgen_edges(lua_State *L) chunksize = stoi(chunksize_str, -32768, 32767); } - std::pair edges = get_mapgen_edges(mapgen_limit, chunksize); - push_v3s16(L, v3s16(1, 1, 1) * edges.first); - push_v3s16(L, v3s16(1, 1, 1) * edges.second); + std::pair edges = get_mapgen_edges(mapgen_limit, chunksize); + push_v3pos(L, v3pos_t(1, 1, 1) * edges.first); + push_v3pos(L, v3pos_t(1, 1, 1) * edges.second); return 2; } diff --git a/src/server.cpp b/src/server.cpp index 222a326654..ca579af2be 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -2276,7 +2276,7 @@ void Server::sendAddNode(v3pos_t p, MapNode n, std::unordered_set *far_play sendNodeChangePkt(pkt, block_pos, p_f, far_d_nodes, far_players); } -void Server::sendNodeChangePkt(NetworkPacket &pkt, v3s16 block_pos, +void Server::sendNodeChangePkt(NetworkPacket &pkt, v3bpos_t block_pos, v3f p, float far_d_nodes, std::unordered_set *far_players) { float maxd = far_d_nodes * BS; diff --git a/src/server.h b/src/server.h index de2fe43205..4a977f74f2 100644 --- a/src/server.h +++ b/src/server.h @@ -477,7 +477,7 @@ class Server : public con::PeerHandler, public MapEventReceiver, void sendAddNode(v3pos_t p, MapNode n, std::unordered_set *far_players = nullptr, float far_d_nodes = 100, bool remove_metadata = true); - void sendNodeChangePkt(NetworkPacket &pkt, v3s16 block_pos, + void sendNodeChangePkt(NetworkPacket &pkt, v3bpos_t block_pos, v3f p, float far_d_nodes, std::unordered_set *far_players); void sendMetadataChanged(const std::unordered_set &positions, diff --git a/src/serverenvironment.cpp b/src/serverenvironment.cpp index 26825c9caf..cd15207bbc 100644 --- a/src/serverenvironment.cpp +++ b/src/serverenvironment.cpp @@ -18,6 +18,7 @@ with this program; if not, write to the Free Software Foundation, Inc., */ #include +#include "irr_v3d.h" #include "serverenvironment.h" #include "settings.h" #include "log.h" @@ -388,7 +389,7 @@ void ActiveBlockList::update(std::vector &active_players, void OnMapblocksChangedReceiver::onMapEditEvent(const MapEditEvent &event) { assert(receiving); - for (const v3s16 &p : event.modified_blocks) { + for (const v3pos_t &p : event.modified_blocks) { modified_blocks.insert(p); } } @@ -1590,7 +1591,7 @@ void ServerEnvironment::step(float dtime) // Notify mods of modified mapblocks if (m_on_mapblocks_changed_receiver.receiving && !m_on_mapblocks_changed_receiver.modified_blocks.empty()) { - std::unordered_set modified_blocks; + std::unordered_set modified_blocks; std::swap(modified_blocks, m_on_mapblocks_changed_receiver.modified_blocks); m_script->on_mapblocks_changed(modified_blocks); } diff --git a/src/serverenvironment.h b/src/serverenvironment.h index 6d07d1e9b4..f3e9185415 100644 --- a/src/serverenvironment.h +++ b/src/serverenvironment.h @@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "activeobject.h" #include "environment.h" +#include "irr_v3d.h" #include "map.h" #include "settings.h" #include "server/activeobjectmgr.h" @@ -195,7 +196,7 @@ class ActiveBlockList ServerEnvironment::m_on_mapblocks_changed_receiver */ struct OnMapblocksChangedReceiver : public MapEventReceiver { - std::unordered_set modified_blocks; + std::unordered_set modified_blocks; bool receiving = false; void onMapEditEvent(const MapEditEvent &event) override; diff --git a/src/unittest/test_map.cpp b/src/unittest/test_map.cpp index 7a8275141b..3e3633854c 100644 --- a/src/unittest/test_map.cpp +++ b/src/unittest/test_map.cpp @@ -16,6 +16,7 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#include "irr_v3d.h" #include "test.h" #include @@ -78,28 +79,28 @@ void TestMap::testMaxMapgenLimit() void TestMap::testForEachNodeInArea(IGameDef *gamedef) { - v3s16 minp_visit(-10, -10, -10); - v3s16 maxp_visit(20, 20, 10); - v3s16 dims_visit = maxp_visit - minp_visit + v3s16(1, 1, 1); + v3pos_t minp_visit(-10, -10, -10); + v3pos_t maxp_visit(20, 20, 10); + v3pos_t dims_visit = maxp_visit - minp_visit + v3pos_t(1, 1, 1); s32 volume_visit = (s32)dims_visit.X * (s32)dims_visit.Y * (s32)dims_visit.Z; - v3s16 minp = minp_visit - v3s16(1, 1, 1); - v3s16 maxp = maxp_visit + v3s16(1, 1, 1); + v3pos_t minp = minp_visit - v3pos_t(1, 1, 1); + v3pos_t maxp = maxp_visit + v3pos_t(1, 1, 1); DummyMap map(gamedef, getNodeBlockPos(minp), getNodeBlockPos(maxp)); - v3s16 p1(0, 10, 5); + v3pos_t p1(0, 10, 5); MapNode n1(t_CONTENT_STONE); map.setNode(p1, n1); - v3s16 p2(-1, 15, 5); + v3pos_t p2(-1, 15, 5); MapNode n2(t_CONTENT_TORCH); map.setNode(p2, n2); - v3s16 p3 = minp_visit; + v3pos_t p3 = minp_visit; MapNode n3(CONTENT_AIR); map.setNode(p3, n3); - v3s16 p4 = maxp_visit; + v3pos_t p4 = maxp_visit; MapNode n4(t_CONTENT_LAVA); map.setNode(p4, n4); @@ -108,11 +109,11 @@ void TestMap::testForEachNodeInArea(IGameDef *gamedef) map.setNode(maxp, MapNode(t_CONTENT_WATER)); s32 n_visited = 0; - std::unordered_set visited; - v3s16 minp_visited(0, 0, 0); - v3s16 maxp_visited(0, 0, 0); - std::unordered_map found; - map.forEachNodeInArea(minp_visit, maxp_visit, [&](v3s16 p, MapNode n) -> bool { + std::unordered_set visited; + v3pos_t minp_visited(0, 0, 0); + v3pos_t maxp_visited(0, 0, 0); + std::unordered_map found; + map.forEachNodeInArea(minp_visit, maxp_visit, [&](v3pos_t p, MapNode n) -> bool { n_visited++; visited.insert(p); minp_visited.X = std::min(minp_visited.X, p.X); @@ -146,11 +147,11 @@ void TestMap::testForEachNodeInArea(IGameDef *gamedef) void TestMap::testForEachNodeInAreaBlank(IGameDef *gamedef) { - DummyMap map(gamedef, v3s16(0, 0, 0), v3s16(-1, -1, -1)); + DummyMap map(gamedef, v3pos_t(0, 0, 0), v3pos_t(-1, -1, -1)); - v3s16 invalid_p(0, 0, 0); + v3pos_t invalid_p(0, 0, 0); bool visited = false; - map.forEachNodeInArea(invalid_p, invalid_p, [&](v3s16 p, MapNode n) -> bool { + map.forEachNodeInArea(invalid_p, invalid_p, [&](v3pos_t p, MapNode n) -> bool { bool is_valid_position = true; UASSERT(n == map.getNode(p, &is_valid_position)); UASSERT(!is_valid_position); @@ -163,8 +164,8 @@ void TestMap::testForEachNodeInAreaBlank(IGameDef *gamedef) void TestMap::testForEachNodeInAreaEmpty(IGameDef *gamedef) { - DummyMap map(gamedef, v3s16(), v3s16()); - map.forEachNodeInArea(v3s16(0, 0, 0), v3s16(-1, -1, -1), [&](v3s16 p, MapNode n) -> bool { + DummyMap map(gamedef, v3pos_t(), v3pos_t()); + map.forEachNodeInArea(v3pos_t(0, 0, 0), v3pos_t(-1, -1, -1), [&](v3pos_t p, MapNode n) -> bool { UASSERT(false); // Should be unreachable return true; }); diff --git a/src/unittest/test_voxelalgorithms.cpp b/src/unittest/test_voxelalgorithms.cpp index 69260beb6f..fd12689cd7 100644 --- a/src/unittest/test_voxelalgorithms.cpp +++ b/src/unittest/test_voxelalgorithms.cpp @@ -17,6 +17,7 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#include "irr_v3d.h" #include "test.h" #include "gamedef.h" @@ -103,14 +104,14 @@ void TestVoxelAlgorithms::testVoxelLineIterator() void TestVoxelAlgorithms::testLighting(IGameDef *gamedef) { - v3s16 pmin(-32, -32, -32); - v3s16 pmax(31, 31, 31); - v3s16 bpmin = getNodeBlockPos(pmin), bpmax = getNodeBlockPos(pmax); + v3pos_t pmin(-32, -32, -32); + v3pos_t pmax(31, 31, 31); + v3pos_t bpmin = getNodeBlockPos(pmin), bpmax = getNodeBlockPos(pmax); DummyMap map(gamedef, bpmin, bpmax); // Make a 21x21x21 hollow box centered at the origin. { - std::map modified_blocks; + std::map modified_blocks; MMVManip vm(&map); vm.initialEmerge(bpmin, bpmax, false); s32 volume = vm.m_area.getVolume(); @@ -119,52 +120,52 @@ void TestVoxelAlgorithms::testLighting(IGameDef *gamedef) for (s16 z = -10; z <= 10; z++) for (s16 y = -10; y <= 10; y++) for (s16 x = -10; x <= 10; x++) - vm.setNodeNoEmerge(v3s16(x, y, z), MapNode(t_CONTENT_STONE)); + vm.setNodeNoEmerge(v3pos_t(x, y, z), MapNode(t_CONTENT_STONE)); for (s16 z = -9; z <= 9; z++) for (s16 y = -9; y <= 9; y++) for (s16 x = -9; x <= 9; x++) - vm.setNodeNoEmerge(v3s16(x, y, z), MapNode(CONTENT_AIR)); + vm.setNodeNoEmerge(v3pos_t(x, y, z), MapNode(CONTENT_AIR)); voxalgo::blit_back_with_light(&map, &vm, &modified_blocks); } // Place two holes on the edges a torch in the center. { - std::map modified_blocks; - map.addNodeAndUpdate(v3s16(-10, 0, 0), MapNode(CONTENT_AIR), modified_blocks); - map.addNodeAndUpdate(v3s16(9, 10, -9), MapNode(t_CONTENT_WATER), modified_blocks); - map.addNodeAndUpdate(v3s16(0, 0, 0), MapNode(t_CONTENT_TORCH), modified_blocks); - map.addNodeAndUpdate(v3s16(-10, 1, 0), MapNode(t_CONTENT_STONE, 153), modified_blocks); + std::map modified_blocks; + map.addNodeAndUpdate(v3pos_t(-10, 0, 0), MapNode(CONTENT_AIR), modified_blocks); + map.addNodeAndUpdate(v3pos_t(9, 10, -9), MapNode(t_CONTENT_WATER), modified_blocks); + map.addNodeAndUpdate(v3pos_t(0, 0, 0), MapNode(t_CONTENT_TORCH), modified_blocks); + map.addNodeAndUpdate(v3pos_t(-10, 1, 0), MapNode(t_CONTENT_STONE, 153), modified_blocks); } const NodeDefManager *ndef = gamedef->ndef(); { - MapNode n = map.getNode(v3s16(9, 9, -9)); + MapNode n = map.getNode(v3pos_t(9, 9, -9)); UASSERTEQ(int, n.getLight(LIGHTBANK_NIGHT, ndef->getLightingFlags(n)), 0); UASSERTEQ(int, n.getLight(LIGHTBANK_DAY, ndef->getLightingFlags(n)), 13); } { - MapNode n = map.getNode(v3s16(0, 1, 0)); + MapNode n = map.getNode(v3pos_t(0, 1, 0)); UASSERTEQ(int, n.getLight(LIGHTBANK_NIGHT, ndef->getLightingFlags(n)), 12); UASSERTEQ(int, n.getLight(LIGHTBANK_DAY, ndef->getLightingFlags(n)), 12); } { - MapNode n = map.getNode(v3s16(-9, -1, 0)); + MapNode n = map.getNode(v3pos_t(-9, -1, 0)); UASSERTEQ(int, n.getLight(LIGHTBANK_NIGHT, ndef->getLightingFlags(n)), 3); UASSERTEQ(int, n.getLight(LIGHTBANK_DAY, ndef->getLightingFlags(n)), 12); } { - MapNode n = map.getNode(v3s16(-10, 0, 0)); + MapNode n = map.getNode(v3pos_t(-10, 0, 0)); UASSERTEQ(int, n.getLight(LIGHTBANK_NIGHT, ndef->getLightingFlags(n)), 3); UASSERTEQ(int, n.getLight(LIGHTBANK_DAY, ndef->getLightingFlags(n)), 14); } { - MapNode n = map.getNode(v3s16(-11, 0, 0)); + MapNode n = map.getNode(v3pos_t(-11, 0, 0)); UASSERTEQ(int, n.getLight(LIGHTBANK_NIGHT, ndef->getLightingFlags(n)), 2); UASSERTEQ(int, n.getLight(LIGHTBANK_DAY, ndef->getLightingFlags(n)), 15); } { // Test that irrelevant param1 values are not clobbered. - MapNode n = map.getNode(v3s16(-10, 1, 0)); + MapNode n = map.getNode(v3pos_t(-10, 1, 0)); UASSERTEQ(int, n.getParam1(), 153); } } diff --git a/src/util/directiontables.cpp b/src/util/directiontables.cpp index 392ab312fd..ab90c63dcd 100644 --- a/src/util/directiontables.cpp +++ b/src/util/directiontables.cpp @@ -128,37 +128,37 @@ const v3s16 wallmounted_dirs[8] = { v3s16(0, 0, -1), }; -const v3s16 facedir_dirs[32] = { +const v3pos_t facedir_dirs[32] = { //0 - v3s16(0, 0, 1), - v3s16(1, 0, 0), - v3s16(0, 0, -1), - v3s16(-1, 0, 0), + v3pos_t(0, 0, 1), + v3pos_t(1, 0, 0), + v3pos_t(0, 0, -1), + v3pos_t(-1, 0, 0), //4 - v3s16(0, -1, 0), - v3s16(1, 0, 0), - v3s16(0, 1, 0), - v3s16(-1, 0, 0), + v3pos_t(0, -1, 0), + v3pos_t(1, 0, 0), + v3pos_t(0, 1, 0), + v3pos_t(-1, 0, 0), //8 - v3s16(0, 1, 0), - v3s16(1, 0, 0), - v3s16(0, -1, 0), - v3s16(-1, 0, 0), + v3pos_t(0, 1, 0), + v3pos_t(1, 0, 0), + v3pos_t(0, -1, 0), + v3pos_t(-1, 0, 0), //12 - v3s16(0, 0, 1), - v3s16(0, -1, 0), - v3s16(0, 0, -1), - v3s16(0, 1, 0), + v3pos_t(0, 0, 1), + v3pos_t(0, -1, 0), + v3pos_t(0, 0, -1), + v3pos_t(0, 1, 0), //16 - v3s16(0, 0, 1), - v3s16(0, 1, 0), - v3s16(0, 0, -1), - v3s16(0, -1, 0), + v3pos_t(0, 0, 1), + v3pos_t(0, 1, 0), + v3pos_t(0, 0, -1), + v3pos_t(0, -1, 0), //20 - v3s16(0, 0, 1), - v3s16(-1, 0, 0), - v3s16(0, 0, -1), - v3s16(1, 0, 0), + v3pos_t(0, 0, 1), + v3pos_t(-1, 0, 0), + v3pos_t(0, 0, -1), + v3pos_t(1, 0, 0), }; const v3s16 fourdir_dirs[4] = { diff --git a/src/util/directiontables.h b/src/util/directiontables.h index 9ecee454fe..8abd71189f 100644 --- a/src/util/directiontables.h +++ b/src/util/directiontables.h @@ -35,7 +35,7 @@ extern const u8 wallmounted_to_facedir[6]; extern const v3s16 wallmounted_dirs[8]; -extern const v3s16 facedir_dirs[32]; +extern const v3pos_t facedir_dirs[32]; extern const v3s16 fourdir_dirs[4]; diff --git a/src/util/pointedthing.cpp b/src/util/pointedthing.cpp index df7ebd6301..90258b8ade 100644 --- a/src/util/pointedthing.cpp +++ b/src/util/pointedthing.cpp @@ -19,11 +19,12 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "pointedthing.h" +#include "irr_v3d.h" #include "serialize.h" #include "exceptions.h" #include -PointedThing::PointedThing(const v3s16 &under, const v3pos_t &above, +PointedThing::PointedThing(const v3pos_t &under, const v3pos_t &above, const v3pos_t &real_under, const v3f &point, const v3f &normal, u16 box_id, f32 distSq): type(POINTEDTHING_NODE), From bea7d5b63ab0c66826987e9cb032d316aed1f902 Mon Sep 17 00:00:00 2001 From: proller Date: Thu, 3 Aug 2023 23:52:33 +0300 Subject: [PATCH 31/36] More opos --- src/client/activeobjectmgr.cpp | 6 ++--- src/client/activeobjectmgr.h | 2 +- src/client/clientenvironment.h | 3 ++- src/client/content_cao.cpp | 3 ++- src/client/localplayer.cpp | 40 +++++++++++++++++----------------- src/client/localplayer.h | 7 +++--- src/collision.cpp | 11 +++++----- src/collision.h | 3 ++- src/server/luaentity_sao.cpp | 3 ++- 9 files changed, 42 insertions(+), 36 deletions(-) diff --git a/src/client/activeobjectmgr.cpp b/src/client/activeobjectmgr.cpp index 94b737bee9..089d79ac8e 100644 --- a/src/client/activeobjectmgr.cpp +++ b/src/client/activeobjectmgr.cpp @@ -94,14 +94,14 @@ void ActiveObjectMgr::removeObject(u16 id) } // clang-format on -void ActiveObjectMgr::getActiveObjects(const v3opos_t &origin, f32 max_d, +void ActiveObjectMgr::getActiveObjects(const v3opos_t &origin, opos_t max_d, std::vector &dest) { - f32 max_d2 = max_d * max_d; + opos_t max_d2 = max_d * max_d; for (auto &ao_it : m_active_objects) { ClientActiveObject *obj = ao_it.second; - f32 d2 = (obj->getPosition() - origin).getLengthSQ(); + opos_t d2 = (obj->getPosition() - origin).getLengthSQ(); if (d2 > max_d2) continue; diff --git a/src/client/activeobjectmgr.h b/src/client/activeobjectmgr.h index 31d709ed21..c1e0c0e40f 100644 --- a/src/client/activeobjectmgr.h +++ b/src/client/activeobjectmgr.h @@ -36,7 +36,7 @@ class ActiveObjectMgr : public ::ActiveObjectMgr bool registerObject(ClientActiveObject *obj) override; void removeObject(u16 id) override; - void getActiveObjects(const v3opos_t &origin, f32 max_d, + void getActiveObjects(const v3opos_t &origin, opos_t max_d, std::vector &dest); // Similar to above, but takes selection box sizes, and line direction into // account. diff --git a/src/client/clientenvironment.h b/src/client/clientenvironment.h index c3e9149a80..9914d48703 100644 --- a/src/client/clientenvironment.h +++ b/src/client/clientenvironment.h @@ -22,6 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "environment.h" #include #include "clientobject.h" +#include "irrlichttypes.h" #include "util/numeric.h" #include "activeobjectmgr.h" @@ -119,7 +120,7 @@ class ClientEnvironment : public Environment */ // Get all nearby objects - void getActiveObjects(const v3opos_t &origin, f32 max_d, + void getActiveObjects(const v3opos_t &origin, opos_t max_d, std::vector &dest) { return m_ao_manager.getActiveObjects(origin, max_d, dest); diff --git a/src/client/content_cao.cpp b/src/client/content_cao.cpp index 737b2a6d51..a484fe899c 100644 --- a/src/client/content_cao.cpp +++ b/src/client/content_cao.cpp @@ -26,6 +26,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "client/renderingengine.h" #include "client/sound.h" #include "client/tile.h" +#include "irrlichttypes.h" #include "util/basic_macros.h" #include "util/numeric.h" #include "util/serialize.h" @@ -1145,7 +1146,7 @@ void GenericCAO::step(float dtime, ClientEnvironment *env) box.MinEdge *= BS; box.MaxEdge *= BS; collisionMoveResult moveresult; - f32 pos_max_d = BS*0.125; // Distance per iteration + opos_t pos_max_d = BS*0.125; // Distance per iteration auto p_pos = m_position; v3f p_velocity = m_velocity; moveresult = collisionMoveSimple(env,env->getGameDef(), diff --git a/src/client/localplayer.cpp b/src/client/localplayer.cpp index c974ba7feb..2f86e305db 100644 --- a/src/client/localplayer.cpp +++ b/src/client/localplayer.cpp @@ -61,10 +61,10 @@ static aabb3f getNodeBoundingBox(const std::vector &nodeboxes) bool LocalPlayer::updateSneakNode(Map *map, const v3opos_t &position, - const v3f &sneak_max) + const v3opos_t &sneak_max) { // Acceptable distance to node center - constexpr f32 allowed_range = (0.5f + 0.1f) * BS; + constexpr opos_t allowed_range = (0.5f + 0.1f) * BS; static const v3pos_t dir9_center[9] = { v3pos_t( 0, 0, 0), v3pos_t( 1, 0, 0), @@ -83,7 +83,7 @@ bool LocalPlayer::updateSneakNode(Map *map, const v3opos_t &position, bool new_sneak_node_exists = m_sneak_node_exists; // We want the top of the sneak node to be below the players feet - f32 position_y_mod = 0.02f * BS; + opos_t position_y_mod = 0.02f * BS; if (m_sneak_node_exists) position_y_mod = m_sneak_node_bb_top.MaxEdge.Y - position_y_mod; @@ -104,7 +104,7 @@ bool LocalPlayer::updateSneakNode(Map *map, const v3opos_t &position, // Get new sneak node m_sneak_ladder_detected = false; - f32 min_distance_sq = HUGE_VALF; + opos_t min_distance_sq = HUGE_VALF; for (const auto &d : dir9_center) { const v3pos_t p = current_node + d; @@ -122,7 +122,7 @@ bool LocalPlayer::updateSneakNode(Map *map, const v3opos_t &position, } const v2opos_t diff(position.X - pf.X, position.Z - pf.Z); - const f32 distance_sq = diff.getLengthSQ(); + const opos_t distance_sq = diff.getLengthSQ(); if (distance_sq > min_distance_sq || std::fabs(diff.X) > allowed_range + sneak_max.X || @@ -356,11 +356,11 @@ void LocalPlayer::move(f32 dtime, Environment *env, opos_t pos_max_d, // Max. distance (X, Z) over border for sneaking determined by collision box // * 0.49 to keep the center just barely on the node - v3f sneak_max = m_collisionbox.getExtent() * 0.49f; + v3opos_t sneak_max = v3fToOpos(m_collisionbox.getExtent()) * 0.49f; if (m_sneak_ladder_detected) { // restore legacy behavior (this makes the m_speed.Y hack necessary) - sneak_max = v3f(0.4f * BS, 0.0f, 0.4f * BS); + sneak_max = v3opos_t(0.4f * BS, 0.0f, 0.4f * BS); } /* @@ -885,13 +885,13 @@ void LocalPlayer::old_move(f32 dtime, Environment *env, opos_t pos_max_d, Collision uncertainty radius Make it a bit larger than the maximum distance of movement */ - //f32 d = pos_max_d * 1.1; + //opos_t d = pos_max_d * 1.1; // A fairly large value in here makes moving smoother - f32 d = 0.15f * BS; + opos_t d = 0.15f * BS; // This should always apply, otherwise there are glitches sanity_check(d > pos_max_d); // Maximum distance over border for sneaking - f32 sneak_max = BS * 0.4f; + opos_t sneak_max = BS * 0.4f; /* If sneaking, keep in range from the last walked node and don't @@ -900,14 +900,14 @@ void LocalPlayer::old_move(f32 dtime, Environment *env, opos_t pos_max_d, if (control.sneak && m_sneak_node_exists && !(fly_allowed && player_settings.free_move) && !in_liquid && physics_override.sneak) { - f32 maxd = 0.5f * BS + sneak_max; + opos_t maxd = 0.5f * BS + sneak_max; auto lwn_f = intToFloat(m_sneak_node, BS); position.X = rangelim(position.X, lwn_f.X - maxd, lwn_f.X + maxd); position.Z = rangelim(position.Z, lwn_f.Z - maxd, lwn_f.Z + maxd); if (!is_climbing) { // Move up if necessary - f32 new_y = (lwn_f.Y - 0.5f * BS) + m_sneak_node_bb_ymax; + opos_t new_y = (lwn_f.Y - 0.5f * BS) + m_sneak_node_bb_ymax; if (position.Y < new_y) position.Y = new_y; /* @@ -953,7 +953,7 @@ void LocalPlayer::old_move(f32 dtime, Environment *env, opos_t pos_max_d, player is sneaking from, if any. If the node from under the player has been removed, the player falls. */ - f32 position_y_mod = 0.05f * BS; + opos_t position_y_mod = 0.05f * BS; if (m_sneak_node_bb_ymax > 0.0f) position_y_mod = m_sneak_node_bb_ymax - position_y_mod; v3pos_t current_node = floatToInt(position - v3opos_t(0.0f, position_y_mod, 0.0f), BS); @@ -973,17 +973,17 @@ void LocalPlayer::old_move(f32 dtime, Environment *env, opos_t pos_max_d, if (m_need_to_get_new_sneak_node && physics_override.sneak) { m_sneak_node_bb_ymax = 0.0f; v3pos_t pos_i_bottom = floatToInt(position - v3opos_t(0.0f, position_y_mod, 0.0f), BS); - v2f player_p2df(position.X, position.Z); - f32 min_distance_f = 100000.0f * BS; + v2opos_t player_p2df(position.X, position.Z); + opos_t min_distance_f = 100000.0f * BS; // If already seeking from some node, compare to it. v3pos_t new_sneak_node = m_sneak_node; for (s16 x= -1; x <= 1; x++) for (s16 z= -1; z <= 1; z++) { v3pos_t p = pos_i_bottom + v3pos_t(x, 0, z); auto pf = intToFloat(p, BS); - v2f node_p2df(pf.X, pf.Z); - f32 distance_f = player_p2df.getDistanceFrom(node_p2df); - f32 max_axis_distance_f = MYMAX( + v2opos_t node_p2df(pf.X, pf.Z); + opos_t distance_f = player_p2df.getDistanceFrom(node_p2df); + opos_t max_axis_distance_f = MYMAX( std::fabs(player_p2df.X - node_p2df.X), std::fabs(player_p2df.Y - node_p2df.Y)); @@ -1135,7 +1135,7 @@ float LocalPlayer::getSlipFactor(Environment *env, const v3f &speedH) void LocalPlayer::handleAutojump(f32 dtime, Environment *env, const collisionMoveResult &result, const v3opos_t &initial_position, - const v3f &initial_speed, f32 pos_max_d) + const v3f &initial_speed, opos_t pos_max_d) { PlayerSettings &player_settings = getPlayerSettings(); if (!player_settings.autojump) @@ -1186,7 +1186,7 @@ void LocalPlayer::handleAutojump(f32 dtime, Environment *env, float jumpspeed = movement_speed_jump * physics_override.jump; float peak_dtime = jumpspeed / gravity; // at the peak of the jump v = gt <=> t = v / g - float jump_height = (jumpspeed - 0.5f * gravity * peak_dtime) * peak_dtime; // s = vt - 1/2 gt^2 + opos_t jump_height = (jumpspeed - 0.5f * gravity * peak_dtime) * peak_dtime; // s = vt - 1/2 gt^2 v3opos_t jump_pos = initial_position + v3opos_t(0.0f, jump_height, 0.0f); v3f jump_speed = initial_speed; diff --git a/src/client/localplayer.h b/src/client/localplayer.h index 27821fd372..fc85d7fe50 100644 --- a/src/client/localplayer.h +++ b/src/client/localplayer.h @@ -19,6 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #pragma once +#include "irr_v3d.h" #include "irrlichttypes.h" #include "player.h" #include "environment.h" @@ -159,12 +160,12 @@ class LocalPlayer : public Player private: void accelerate(const v3f &target_speed, const f32 max_increase_H, const f32 max_increase_V, const bool use_pitch); - bool updateSneakNode(Map *map, const v3opos_t &position, const v3f &sneak_max); + bool updateSneakNode(Map *map, const v3opos_t &position, const v3opos_t &sneak_max); float getSlipFactor(Environment *env, const v3f &speedH); void handleAutojump(f32 dtime, Environment *env, const collisionMoveResult &result, const v3opos_t &position_before_move, const v3f &speed_before_move, - f32 pos_max_d); + opos_t pos_max_d); v3opos_t m_position; v3pos_t m_standing_node; @@ -180,7 +181,7 @@ class LocalPlayer : public Player // ***** Variables for temporary option of the old move code ***** // Stores the max player uplift by m_sneak_node - f32 m_sneak_node_bb_ymax = 0.0f; + opos_t m_sneak_node_bb_ymax = 0.0f; // Whether recalculation of m_sneak_node and its top bbox is needed bool m_need_to_get_new_sneak_node = true; // Node below player, used to determine whether it has been removed, diff --git a/src/collision.cpp b/src/collision.cpp index 92a7454717..4eda5976e6 100644 --- a/src/collision.cpp +++ b/src/collision.cpp @@ -20,6 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "collision.h" #include #include "irr_v3d.h" +#include "irrlichttypes.h" #include "mapblock.h" #include "map.h" #include "nodedef.h" @@ -236,7 +237,7 @@ static inline void getNeighborConnectingFace(const v3pos_t &p, } collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef, - f32 pos_max_d, const aabb3f &box_0, + opos_t pos_max_d, const aabb3f &box_0, f32 stepheight, f32 dtime, v3opos_t *pos_f, v3f *speed_f, v3f accel_f, ActiveObject *self, @@ -265,12 +266,12 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef, time_notification_done = false; } - v3f dpos_f = (*speed_f + accel_f * 0.5f * dtime) * dtime; - v3opos_t newpos_f = *pos_f + v3fToOpos(dpos_f); + v3opos_t dpos_f = (v3fToOpos(*speed_f + accel_f) * 0.5f * dtime) * dtime; + v3opos_t newpos_f = *pos_f + dpos_f; *speed_f += accel_f * dtime; // If the object is static, there are no collisions - if (dpos_f == v3f()) + if (dpos_f == v3opos_t()) return result; // Limit speed for avoiding hangs @@ -390,7 +391,7 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef, ClientEnvironment *c_env = dynamic_cast(env); if (c_env != 0) { // Calculate distance by speed, add own extent and 1.5m of tolerance - f32 distance = speed_f->getLength() * dtime + + opos_t distance = speed_f->getLength() * dtime + box_0.getExtent().getLength() + 1.5f * BS; std::vector clientobjects; c_env->getActiveObjects(*pos_f, distance, clientobjects); diff --git a/src/collision.h b/src/collision.h index a09b2e9984..2d7d6a3e8c 100644 --- a/src/collision.h +++ b/src/collision.h @@ -20,6 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #pragma once #include "irr_v3d.h" +#include "irrlichttypes.h" #include "irrlichttypes_bloated.h" #include @@ -67,7 +68,7 @@ struct collisionMoveResult // Moves using a single iteration; speed should not exceed pos_max_d/dtime collisionMoveResult collisionMoveSimple(Environment *env,IGameDef *gamedef, - f32 pos_max_d, const aabb3f &box_0, + opos_t pos_max_d, const aabb3f &box_0, f32 stepheight, f32 dtime, v3opos_t *pos_f, v3f *speed_f, v3f accel_f, ActiveObject *self=NULL, diff --git a/src/server/luaentity_sao.cpp b/src/server/luaentity_sao.cpp index ca4e565697..6c7537a961 100644 --- a/src/server/luaentity_sao.cpp +++ b/src/server/luaentity_sao.cpp @@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "luaentity_sao.h" #include "collision.h" #include "constants.h" +#include "irrlichttypes.h" #include "player_sao.h" #include "scripting_server.h" #include "server.h" @@ -160,7 +161,7 @@ void LuaEntitySAO::step(float dtime, bool send_recommended) aabb3f box = m_prop.collisionbox; box.MinEdge *= BS; box.MaxEdge *= BS; - f32 pos_max_d = BS*0.25; // Distance per iteration + opos_t pos_max_d = BS*0.25; // Distance per iteration auto p_pos = m_base_position; v3f p_velocity = m_velocity; v3f p_acceleration = m_acceleration; From e48f64323611573c86bb5a86252297dad927cf44 Mon Sep 17 00:00:00 2001 From: proller Date: Fri, 4 Aug 2023 00:01:26 +0300 Subject: [PATCH 32/36] More opos --- src/client/localplayer.cpp | 8 ++++---- src/server/player_sao.cpp | 7 ++++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/client/localplayer.cpp b/src/client/localplayer.cpp index 2f86e305db..861bbb71fd 100644 --- a/src/client/localplayer.cpp +++ b/src/client/localplayer.cpp @@ -212,7 +212,7 @@ void LocalPlayer::move(f32 dtime, Environment *env, opos_t pos_max_d, bool free_move = player_settings.free_move && fly_allowed; if (noclip && free_move) { - position += v3fToOpos(m_speed * dtime); + position += v3fToOpos(m_speed) * dtime; setPosition(position); touching_ground = false; @@ -296,7 +296,7 @@ void LocalPlayer::move(f32 dtime, Environment *env, opos_t pos_max_d, */ //f32 d = pos_max_d * 1.1; // A fairly large value in here makes moving smoother - f32 d = 0.15f * BS; + opos_t d = 0.15f * BS; // This should always apply, otherwise there are glitches sanity_check(d > pos_max_d); @@ -980,7 +980,7 @@ void LocalPlayer::old_move(f32 dtime, Environment *env, opos_t pos_max_d, for (s16 x= -1; x <= 1; x++) for (s16 z= -1; z <= 1; z++) { v3pos_t p = pos_i_bottom + v3pos_t(x, 0, z); - auto pf = intToFloat(p, BS); + v3opos_t pf = intToFloat(p, BS); v2opos_t node_p2df(pf.X, pf.Z); opos_t distance_f = player_p2df.getDistanceFrom(node_p2df); opos_t max_axis_distance_f = MYMAX( @@ -1016,7 +1016,7 @@ void LocalPlayer::old_move(f32 dtime, Environment *env, opos_t pos_max_d, m_sneak_node_exists = sneak_node_found; if (sneak_node_found) { - f32 cb_max = 0.0f; + opos_t cb_max = 0.0f; MapNode n = map->getNode(m_sneak_node); std::vector nodeboxes; n.getCollisionBoxes(nodemgr, &nodeboxes); diff --git a/src/server/player_sao.cpp b/src/server/player_sao.cpp index 785b3333cf..6bab6ff98c 100644 --- a/src/server/player_sao.cpp +++ b/src/server/player_sao.cpp @@ -19,6 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc., */ #include "player_sao.h" +#include "irrlichttypes.h" #include "nodedef.h" #include "remoteplayer.h" #include "scripting_server.h" @@ -595,7 +596,7 @@ bool PlayerSAO::checkMovementCheat() too, and much more lightweight. */ - float override_max_H, override_max_V; + opos_t override_max_H, override_max_V; if (m_max_speed_override_time > 0.0f) { override_max_H = MYMAX(fabs(m_max_speed_override.X), fabs(m_max_speed_override.Z)); override_max_V = fabs(m_max_speed_override.Y); @@ -603,8 +604,8 @@ bool PlayerSAO::checkMovementCheat() override_max_H = override_max_V = 0.0f; } - float player_max_walk = 0; // horizontal movement - float player_max_jump = 0; // vertical upwards movement + opos_t player_max_walk = 0; // horizontal movement + opos_t player_max_jump = 0; // vertical upwards movement if (m_privs.count("fast") != 0) player_max_walk = m_player->movement_speed_fast; // Fast speed From f3ef637262f5262ac321186955ed46745b53633e Mon Sep 17 00:00:00 2001 From: proller Date: Mon, 7 Aug 2023 04:08:10 +0300 Subject: [PATCH 33/36] Better temporary proto version --- src/network/networkprotocol.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/network/networkprotocol.h b/src/network/networkprotocol.h index 4f0917a9ec..f2b5322ae0 100644 --- a/src/network/networkprotocol.h +++ b/src/network/networkprotocol.h @@ -221,10 +221,10 @@ with this program; if not, write to the Free Software Foundation, Inc., */ // First version with 32bit support -#define PROTOCOL_VERSION_32BIT 43 +#define PROTOCOL_VERSION_32BIT 143 // change to actual in future #if USE_POS32 -#define LATEST_PROTOCOL_VERSION 43 +#define LATEST_PROTOCOL_VERSION 143 // change to actual in future #else #define LATEST_PROTOCOL_VERSION 42 #endif From 9e45b3206139191af1d37c0e466d77c4d16844a2 Mon Sep 17 00:00:00 2001 From: proller Date: Thu, 9 May 2024 21:43:20 +0200 Subject: [PATCH 34/36] 32 --- src/client/sky.h | 5 +++-- src/skyparams.h | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/client/sky.h b/src/client/sky.h index a5b92ace24..df050382af 100644 --- a/src/client/sky.h +++ b/src/client/sky.h @@ -19,6 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #pragma once +#include "irrlichttypes.h" #include "irrlichttypes_extrabloated.h" #include #include @@ -114,8 +115,8 @@ class Sky : public scene::ISceneNode void addTextureToSkybox(const std::string &texture, int material_id, ITextureSource *tsrc); const video::SColorf &getCurrentStarColor() const { return m_star_color; } - void setFogDistance(s16 fog_distance) { m_sky_params.fog_distance = fog_distance; } - s16 getFogDistance() const { return m_sky_params.fog_distance; } + void setFogDistance(pos_t fog_distance) { m_sky_params.fog_distance = fog_distance; } + pos_t getFogDistance() const { return m_sky_params.fog_distance; } void setFogStart(float fog_start) { m_sky_params.fog_start = fog_start; } float getFogStart() const { return m_sky_params.fog_start; } diff --git a/src/skyparams.h b/src/skyparams.h index 554904bc0b..b50028342e 100644 --- a/src/skyparams.h +++ b/src/skyparams.h @@ -44,7 +44,7 @@ struct SkyboxParams video::SColor fog_moon_tint; std::string fog_tint_type; float body_orbit_tilt { INVALID_SKYBOX_TILT }; - s16 fog_distance { -1 }; + pos_t fog_distance { -1 }; float fog_start { -1.0f }; }; From d1c6a091a4f0fe548a59c064c959c95599a64f76 Mon Sep 17 00:00:00 2001 From: proller Date: Thu, 9 May 2024 21:45:53 +0200 Subject: [PATCH 35/36] clean --- src/client/sky.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/client/sky.h b/src/client/sky.h index df050382af..ca8a1ebee5 100644 --- a/src/client/sky.h +++ b/src/client/sky.h @@ -19,7 +19,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #pragma once -#include "irrlichttypes.h" #include "irrlichttypes_extrabloated.h" #include #include From 196ef68be9933b818069bbeec37e5298849523f9 Mon Sep 17 00:00:00 2001 From: proller Date: Tue, 24 Dec 2024 23:27:39 +0100 Subject: [PATCH 36/36] clean --- src/util/directiontables.cpp | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/util/directiontables.cpp b/src/util/directiontables.cpp index 3f6f148a1f..cf17ba44fe 100644 --- a/src/util/directiontables.cpp +++ b/src/util/directiontables.cpp @@ -16,17 +16,6 @@ const v3pos_t g_6dirs[6] = v3pos_t(-1, 0, 0) // left }; -const v3bpos_t g_6dirs_b[6] = -{ - // +right, +top, +back - v3bpos_t( 0, 0, 1), // back - v3bpos_t( 0, 1, 0), // top - v3bpos_t( 1, 0, 0), // right - v3bpos_t( 0, 0,-1), // front - v3bpos_t( 0,-1, 0), // bottom - v3bpos_t(-1, 0, 0) // left -}; - const v3pos_t g_7dirs[7] = { v3pos_t(0,0,1), // back