Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
proller committed Nov 20, 2023
1 parent 546f220 commit 51869c8
Showing 1 changed file with 25 additions and 34 deletions.
59 changes: 25 additions & 34 deletions src/client/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ along with Freeminer. If not, see <http://www.gnu.org/licenses/>.
#include "hud.h"
#include "clientdynamicinfo.h"

#include "threading/async.h"
#include <future>
#include <memory>

Expand Down Expand Up @@ -956,11 +957,14 @@ class Game {
//freeminer:
GUITable *playerlist = nullptr;
video::SColor console_bg {};
#if ENABLE_THREADS && HAVE_FUTURE
/*#if ENABLE_THREADS && HAVE_FUTURE
std::future<void> updateDrawList_future;
#endif
#endif*/
async_step_runner updateDrawList_async;
bool m_cinematic = false;
std::unique_ptr<FarMesh> farmesh;
//std::future<void> farmesh_future;
async_step_runner farmesh_async;
// minetest:


Expand Down Expand Up @@ -1409,10 +1413,10 @@ void Game::shutdown()

showOverlayMessage(N_("Shutting down..."), 0, 0, false);

#if ENABLE_THREADS && HAVE_FUTURE
/*#if ENABLE_THREADS && HAVE_FUTURE
if (updateDrawList_future.valid())
updateDrawList_future.wait_for(std::chrono::seconds(10));
#endif
#endif*/

if (clouds)
clouds->drop();
Expand Down Expand Up @@ -4450,20 +4454,19 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,
}
}

if(!runData.headless_optimize && farmesh)
{
auto farmesh_range = draw_control->wanted_range; // * 10;
if(draw_control->range_all && farmesh_range < 512)
farmesh_range = 512;
if(farmesh_range > 1024)
farmesh_range = 1024;

farmesh->update(camera->getPosition(), camera->getDirection(), camera->getFovMax(),
camera->getCameraMode(), player->getYaw(), player->getPitch(),
camera->getOffset(),
sky->getBrightness(), farmesh_range);
}

if (!runData.headless_optimize && farmesh) {
auto farmesh_range = draw_control->wanted_range; // * 10;
if (draw_control->range_all && farmesh_range < 512)
farmesh_range = 512;
if (farmesh_range > 1024)
farmesh_range = 1024;
farmesh_async.step(std::function<void()>{[&, farmesh_range]() {
farmesh->update(camera->getPosition(), camera->getDirection(),
camera->getFovMax(), camera->getCameraMode(), player->getYaw(),
player->getPitch(), camera->getOffset(), sky->getBrightness(),
farmesh_range);
}});
}

/*
Update particles
Expand Down Expand Up @@ -4582,22 +4585,10 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,
bool allow = true;
#if ENABLE_THREADS && HAVE_FUTURE
if (g_settings->getBool("more_threads")) {
bool allow = true;
if (updateDrawList_future.valid()) {
auto res =
updateDrawList_future.wait_for(std::chrono::milliseconds(0));
if (res == std::future_status::timeout)
allow = false;
}
if (allow) {
updateDrawList_future = std::async(
std::launch::async,
[=](float dtime) {
client->getEnv().getClientMap().updateDrawListFm(
dtime, 10000);
},
runData.update_draw_list_timer);
}
updateDrawList_async.step(std::function{[&](const float dtime) {
client->getEnv().getClientMap().updateDrawListFm(dtime, 10000);
}},
runData.update_draw_list_timer);
} else
#endif

Expand Down

0 comments on commit 51869c8

Please sign in to comment.