float jump_timer;
float damage_flash;
float update_draw_list_timer;
+ float update_shadows_timer;
f32 fog_range;
bool handleCallbacks();
void processQueues();
void updateProfilers(const RunStats &stats, const FpsControl &draw_times, f32 dtime);
+ void updateDebugState();
void updateStats(RunStats *stats, const FpsControl &draw_times, f32 dtime);
void updateProfilerGraphs(ProfilerGraph *graph);
void toggleFast();
void toggleNoClip();
void toggleCinematic();
+ void toggleBlockBounds();
void toggleAutoforward();
void toggleMinimap(bool shift_pressed);
const ItemStack &selected_item, const ItemStack &hand_item, f32 dtime);
void updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,
const CameraOrientation &cam);
+ void updateShadows();
// Misc
void limitFps(FpsControl *fps_timings, f32 *dtime);
m_game_ui->clearInfoText();
hud->resizeHotbar();
+
updateProfilers(stats, draw_times, dtime);
processUserInput(dtime);
// Update camera before player movement to avoid camera lag of one frame
updatePlayerControl(cam_view);
step(&dtime);
processClientEvents(&cam_view_target);
+ updateDebugState();
updateCamera(draw_times.busy_time, dtime);
updateSound(dtime);
processPlayerInteraction(dtime, m_game_ui->m_flags.show_hud,
- m_game_ui->m_flags.show_debug);
+ m_game_ui->m_flags.show_basic_debug);
updateFrame(&graph, &stats, dtime, cam_view);
updateProfilerGraphs(&graph);
shader_src->processQueue();
}
+void Game::updateDebugState()
+{
+ bool has_basic_debug = client->checkPrivilege("basic_debug");
+ bool has_debug = client->checkPrivilege("debug");
+
+ if (m_game_ui->m_flags.show_basic_debug) {
+ if (!has_basic_debug) {
+ m_game_ui->m_flags.show_basic_debug = false;
+ }
+ } else if (m_game_ui->m_flags.show_minimal_debug) {
+ if (has_basic_debug) {
+ m_game_ui->m_flags.show_basic_debug = true;
+ }
+ }
+ if (!has_basic_debug)
+ hud->disableBlockBounds();
+ if (!has_debug)
+ draw_control->show_wireframe = false;
+}
void Game::updateProfilers(const RunStats &stats, const FpsControl &draw_times,
f32 dtime)
} else if (wasKeyDown(KeyType::SCREENSHOT)) {
client->makeScreenshot();
} else if (wasKeyDown(KeyType::TOGGLE_BLOCK_BOUNDS)) {
- hud->toggleBlockBounds();
+ toggleBlockBounds();
} else if (wasKeyDown(KeyType::TOGGLE_HUD)) {
m_game_ui->toggleHud();
} else if (wasKeyDown(KeyType::MINIMAP)) {
m_game_ui->showTranslatedStatusText("Cinematic mode disabled");
}
+void Game::toggleBlockBounds()
+{
+ if (client->checkPrivilege("basic_debug")) {
+ hud->toggleBlockBounds();
+ } else {
+ m_game_ui->showTranslatedStatusText("Can't show block bounds (need 'basic_debug' privilege)");
+ }
+}
+
// Autoforward by toggling continuous forward.
void Game::toggleAutoforward()
{
void Game::toggleDebug()
{
- // Initial / 4x toggle: Chat only
- // 1x toggle: Debug text with chat
+ // Initial: No debug info
+ // 1x toggle: Debug text
// 2x toggle: Debug text with profiler graph
- // 3x toggle: Debug text and wireframe
- if (!m_game_ui->m_flags.show_debug) {
- m_game_ui->m_flags.show_debug = true;
+ // 3x toggle: Debug text and wireframe (needs "debug" priv)
+ // Next toggle: Back to initial
+ //
+ // The debug text can be in 2 modes: minimal and basic.
+ // * Minimal: Only technical client info that not gameplay-relevant
+ // * Basic: Info that might give gameplay advantage, e.g. pos, angle
+ // Basic mode is used when player has "basic_debug" priv,
+ // otherwise the Minimal mode is used.
+ if (!m_game_ui->m_flags.show_minimal_debug) {
+ m_game_ui->m_flags.show_minimal_debug = true;
+ if (client->checkPrivilege("basic_debug")) {
+ m_game_ui->m_flags.show_basic_debug = true;
+ }
m_game_ui->m_flags.show_profiler_graph = false;
draw_control->show_wireframe = false;
m_game_ui->showTranslatedStatusText("Debug info shown");
} else if (!m_game_ui->m_flags.show_profiler_graph && !draw_control->show_wireframe) {
+ if (client->checkPrivilege("basic_debug")) {
+ m_game_ui->m_flags.show_basic_debug = true;
+ }
m_game_ui->m_flags.show_profiler_graph = true;
m_game_ui->showTranslatedStatusText("Profiler graph shown");
} else if (!draw_control->show_wireframe && client->checkPrivilege("debug")) {
+ if (client->checkPrivilege("basic_debug")) {
+ m_game_ui->m_flags.show_basic_debug = true;
+ }
m_game_ui->m_flags.show_profiler_graph = false;
draw_control->show_wireframe = true;
m_game_ui->showTranslatedStatusText("Wireframe shown");
} else {
- m_game_ui->m_flags.show_debug = false;
+ m_game_ui->m_flags.show_minimal_debug = false;
+ m_game_ui->m_flags.show_basic_debug = false;
m_game_ui->m_flags.show_profiler_graph = false;
draw_control->show_wireframe = false;
if (client->checkPrivilege("debug")) {
changed much
*/
runData.update_draw_list_timer += dtime;
+ runData.update_shadows_timer += dtime;
+
+ float update_draw_list_delta = 0.2f;
+ bool draw_list_updated = false;
v3f camera_direction = camera->getDirection();
- if (runData.update_draw_list_timer >= 0.2
+ if (runData.update_draw_list_timer >= update_draw_list_delta
|| runData.update_draw_list_last_cam_dir.getDistanceFrom(camera_direction) > 0.2
|| m_camera_offset_changed) {
+
runData.update_draw_list_timer = 0;
client->getEnv().getClientMap().updateDrawList();
runData.update_draw_list_last_cam_dir = camera_direction;
+ draw_list_updated = true;
+ }
+
+ if (ShadowRenderer *shadow = RenderingEngine::get_shadow_renderer()) {
+ update_draw_list_delta = shadow->getUpdateDelta();
+
+ if (m_camera_offset_changed ||
+ (runData.update_shadows_timer > update_draw_list_delta &&
+ (!draw_list_updated || shadow->getDirectionalLightCount() == 0))) {
+ runData.update_shadows_timer = 0;
+ updateShadows();
+ }
}
m_game_ui->update(*stats, client, draw_control, cam, runData.pointed_old, gui_chat_console, dtime);
graph->put(values);
}
+/****************************************************************************
+ * Shadows
+ *****************************************************************************/
+void Game::updateShadows()
+{
+ ShadowRenderer *shadow = RenderingEngine::get_shadow_renderer();
+ if (!shadow)
+ return;
+
+ float in_timeofday = fmod(runData.time_of_day_smooth, 1.0f);
+
+ float timeoftheday = fmod(getWickedTimeOfDay(in_timeofday) + 0.75f, 0.5f) + 0.25f;
+ const float offset_constant = 10000.0f;
+ v3f light(0.0f, 0.0f, -1.0f);
+ light.rotateXZBy(90);
+ light.rotateXYBy(timeoftheday * 360 - 90);
+ light.rotateYZBy(sky->getSkyBodyOrbitTilt());
+
+ v3f sun_pos = light * offset_constant;
+
+ if (shadow->getDirectionalLightCount() == 0)
+ shadow->addDirectionalLight();
+ shadow->getDirectionalLight().setDirection(sun_pos);
+ shadow->setTimeOfDay(in_timeofday);
+
+ shadow->getDirectionalLight().update_frustum(camera, client);
+}
/****************************************************************************
Misc