X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Fclient%2Fclientmap.cpp;h=68fd41e397845dbd4aaa01cb2093d1f43bb93d48;hb=946f3030fc0728de15620896e08ed7e10696c11b;hp=294687ff8728385c7ee57e3f984caa374528f1fb;hpb=eb6aca8b4a67ef55108231e71ff29a18a29bf5ae;p=dragonfireclient.git diff --git a/src/client/clientmap.cpp b/src/client/clientmap.cpp index 294687ff8..68fd41e39 100644 --- a/src/client/clientmap.cpp +++ b/src/client/clientmap.cpp @@ -31,6 +31,37 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include "client/renderingengine.h" +// struct MeshBufListList +void MeshBufListList::clear() +{ + for (auto &list : lists) + list.clear(); +} + +void MeshBufListList::add(scene::IMeshBuffer *buf, v3s16 position, u8 layer) +{ + // Append to the correct layer + std::vector &list = lists[layer]; + const video::SMaterial &m = buf->getMaterial(); + for (MeshBufList &l : list) { + // comparing a full material is quite expensive so we don't do it if + // not even first texture is equal + if (l.m.TextureLayer[0].Texture != m.TextureLayer[0].Texture) + continue; + + if (l.m == m) { + l.bufs.emplace_back(position, buf); + return; + } + } + MeshBufList l; + l.m = m; + l.bufs.emplace_back(position, buf); + list.emplace_back(l); +} + +// ClientMap + ClientMap::ClientMap( Client *client, MapDrawControl &control, @@ -144,7 +175,7 @@ void ClientMap::updateDrawList() // No occlusion culling when free_move is on and camera is // inside ground bool occlusion_culling_enabled = true; - if (g_settings->getBool("free_move") && g_settings->getBool("noclip")) { + if ((g_settings->getBool("free_move") && g_settings->getBool("noclip")) || g_settings->getBool("freecam")) { MapNode n = getNode(cam_pos_nodes); if (n.getContent() == CONTENT_IGNORE || m_nodedef->get(n).solidness == 2) @@ -182,9 +213,7 @@ void ClientMap::updateDrawList() if not seen on display */ - if (block->mesh) { - block->mesh->updateCameraOffset(m_camera_offset); - } else { + if (!block->mesh) { // Ignore if mesh doesn't exist continue; } @@ -229,50 +258,6 @@ void ClientMap::updateDrawList() g_profiler->avg("MapBlocks loaded [#]", blocks_loaded); } -struct MeshBufList -{ - video::SMaterial m; - std::vector bufs; -}; - -struct MeshBufListList -{ - /*! - * Stores the mesh buffers of the world. - * The array index is the material's layer. - * The vector part groups vertices by material. - */ - std::vector lists[MAX_TILE_LAYERS]; - - void clear() - { - for (auto &list : lists) - list.clear(); - } - - void add(scene::IMeshBuffer *buf, u8 layer) - { - // Append to the correct layer - std::vector &list = lists[layer]; - const video::SMaterial &m = buf->getMaterial(); - for (MeshBufList &l : list) { - // comparing a full material is quite expensive so we don't do it if - // not even first texture is equal - if (l.m.TextureLayer[0].Texture != m.TextureLayer[0].Texture) - continue; - - if (l.m == m) { - l.bufs.push_back(buf); - return; - } - } - MeshBufList l; - l.m = m; - l.bufs.push_back(buf); - list.push_back(l); - } -}; - void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass) { bool is_transparent_pass = pass == scene::ESNRP_TRANSPARENT; @@ -305,6 +290,7 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass) */ u32 vertex_count = 0; + u32 drawcall_count = 0; // For limiting number of mesh animations per frame u32 mesh_animate_count = 0; @@ -317,6 +303,7 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass) MeshBufListList drawbufs; for (auto &i : m_drawlist) { + v3s16 block_pos = i.first; MapBlock *block = i.second; // If the mesh of the block happened to get deleted, ignore it @@ -382,7 +369,7 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass) material.setFlag(video::EMF_WIREFRAME, m_control.show_wireframe); - drawbufs.add(buf, layer); + drawbufs.add(buf, block_pos, layer); } } } @@ -391,6 +378,9 @@ 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); + // Render all layers in order for (auto &lists : drawbufs.lists) { for (MeshBufList &list : lists) { @@ -402,7 +392,14 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass) } driver->setMaterial(list.m); - for (scene::IMeshBuffer *buf : list.bufs) { + drawcall_count += list.bufs.size(); + for (auto &pair : list.bufs) { + scene::IMeshBuffer *buf = pair.second; + + v3f block_wpos = intToFloat(pair.first * MAP_BLOCKSIZE, BS); + m.setTranslation(block_wpos - offset); + + driver->setTransform(video::ETS_WORLD, m); driver->drawMeshBuffer(buf); vertex_count += buf->getVertexCount(); } @@ -416,6 +413,7 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass) } g_profiler->avg(prefix + "vertices drawn [#]", vertex_count); + g_profiler->avg(prefix + "drawcalls [#]", drawcall_count); } static bool getVisibleBrightness(Map *map, const v3f &p0, v3f dir, float step, @@ -588,7 +586,7 @@ void ClientMap::renderPostFx(CameraMode cam_mode) const ContentFeatures& features = m_nodedef->get(n); video::SColor post_effect_color = features.post_effect_color; if(features.solidness == 2 && !((g_settings->getBool("noclip") || g_settings->getBool("freecam")) && - m_client->checkLocalPrivilege("noclip")) && + (m_client->checkLocalPrivilege("noclip") || g_settings->getBool("freecam"))) && cam_mode == CAMERA_MODE_FIRST) { post_effect_color = video::SColor(255, 0, 0, 0); @@ -607,5 +605,3 @@ void ClientMap::PrintInfo(std::ostream &out) { out<<"ClientMap: "; } - -