diff --git a/src/client/game.cpp b/src/client/game.cpp index 1a34f9de7..f36eb2477 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -715,8 +715,6 @@ struct GameRunData { v3f update_draw_list_last_cam_pos; unsigned int autoexit = 0; bool profiler_state = false; -// - //freeminer: bool headless_optimize = false; bool no_output = false; float dedicated_server_step = 0.1; @@ -931,9 +929,12 @@ class Game { GUITable *playerlist = nullptr; video::SColor console_bg {}; async_step_runner updateDrawList_async; + async_step_runner update_shadows_async; bool m_cinematic = false; std::unique_ptr farmesh; async_step_runner farmesh_async; + std::unique_ptr pointedRaycastState; + PointedThing pointed; // minetest: @@ -3728,7 +3729,7 @@ void Game::processPlayerInteraction(f32 dtime, bool show_hud) } #endif - PointedThing pointed = updatePointedThing(shootline, + updatePointedThing(shootline, selected_def.liquids_pointable, !runData.btn_down_for_dig, camera_offset); @@ -3854,7 +3855,21 @@ PointedThing Game::updatePointedThing( RaycastState s(shootline, look_for_object, liquids_pointable); PointedThing result; - env.continueRaycast(&s, &result); + + if (!pointedRaycastState || pointedRaycastState->finished) { + pointedRaycastState = std::make_unique( + shootline, look_for_object, liquids_pointable); + } + pointedRaycastState->end_ms = porting::getTimeMs() + 3; + + env.continueRaycast(pointedRaycastState.get(), &result); + + if (!pointedRaycastState->finished) { + result = pointed; + } else { + pointed = result; + } + if (result.type == POINTEDTHING_OBJECT) { hud->pointing_at_object = true; @@ -4639,20 +4654,21 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime, runData.update_draw_list_last_cam_pos.getDistanceFrom(camera_position) > MAP_BLOCKSIZE * BS * 1 || m_camera_offset_changed) { - updateDrawList_async.step( - [&](const float dtime) { - client->m_new_meshes = 0; - runData.update_draw_list_timer = 0; + updateDrawList_async.step( + [&](const float dtime) { + client->m_new_meshes = 0; + runData.update_draw_list_timer = 0; runData.update_draw_list_last_cam_pos = camera_position; client->getEnv().getClientMap().updateDrawListFm(dtime, 10000); - }, - runData.update_draw_list_timer); - + }, + runData.update_draw_list_timer); } - if (!runData.headless_optimize) + if (!runData.headless_optimize) if (RenderingEngine::get_shadow_renderer()) { + update_shadows_async.step([&]() { updateShadows(); + }); } diff --git a/src/environment.cpp b/src/environment.cpp index 39a0a753a..847fe16a6 100644 --- a/src/environment.cpp +++ b/src/environment.cpp @@ -292,7 +292,12 @@ void Environment::continueRaycast(RaycastState *state, PointedThing *result) // Next node state->m_previous_node = state->m_iterator.m_current_node_pos; state->m_iterator.next(); + + if (state->end_ms && porting::getTimeMs() > state->end_ms) { + return; + } } + state->finished = true; // Return empty PointedThing if nothing left on the ray if (state->m_found.empty()) { result->type = POINTEDTHING_NOTHING; diff --git a/src/mapblock.h b/src/mapblock.h index b9925a4a6..416089b06 100644 --- a/src/mapblock.h +++ b/src/mapblock.h @@ -99,7 +99,7 @@ struct abm_trigger_one { //// class MapBlock -: public locker<> +: public shared_locker { public: MapBlock(Map *parent, v3s16 pos, IGameDef *gamedef); diff --git a/src/noise.h b/src/noise.h index 3a36747ee..de542178f 100644 --- a/src/noise.h +++ b/src/noise.h @@ -40,7 +40,7 @@ along with Freeminer. If not, see . extern FlagDesc flagdesc_noiseparams[]; -#if FARSCALE_LIMIT > 32768 +#if MAX_MAP_GENERATION_LIMIT > FARSCALE_LIMIT template inline type_scale farscale(type_scale scale, type_coord z) { diff --git a/src/raycast.h b/src/raycast.h index 8da075738..27501b5f5 100644 --- a/src/raycast.h +++ b/src/raycast.h @@ -32,6 +32,12 @@ struct RaycastSort class RaycastState { public: + + // fm: + bool finished = false; + uint64_t end_ms = 0; + // == + /*! * Creates a raycast. * @param objects_pointable if false, only nodes will be found diff --git a/src/threading/async.h b/src/threading/async.h index 6272f2ce9..4fcc1626c 100644 --- a/src/threading/async.h +++ b/src/threading/async.h @@ -57,10 +57,10 @@ class async_step_runner inline bool valid() { return future.valid(); } - constexpr static uint8_t UNKNOWN = 2; - // 0 : started - // 1 : skipped - // 2 : unknown ? + constexpr static uint8_t IN_PROGRESS = 2; + // 0 : started and finished + // 1 : started + // 2 : in progress, skip template uint8_t step(Func func, Args &&...args) { @@ -70,7 +70,7 @@ class async_step_runner #if defined(DUMP_STREAM) ++skips; #endif - return UNKNOWN; + return IN_PROGRESS; } }