From d11555e46eac1e4e238de6501bfae482dc3a4801 Mon Sep 17 00:00:00 2001 From: miloszunio Date: Tue, 24 Nov 2026 00:11:50 +0100 Subject: [PATCH] feat(driver): a flashlight of the player, switched with Ctrl+Shift+L The new command flashlighttoggle (Ctrl+Shift+L, free in the default keyboard bindings) switches a cone of warm white light from a little under the camera where it looks, in the cab, outside and in the free camera, by day as well. It is one more local light of the clustered lighting (gfx::local_lights), so it works with both the OpenGL 4.6 and the Vulkan renderers, and only with gfx.lights.clustered on. It casts no shadows. It is off at the start and isn't kept between the runs. The command is added at the end of user_command, so the numbers of the commands before it stay as they were. Its key comes from the default bindings in the code: an eu07_input-keyboard.ini without it keeps working, and one can bind it to another key with a "flashlighttoggle" line. Co-Authored-By: Claude Opus 5.5 --- input/command.cpp | 2 ++ input/command.h | 2 ++ input/driverkeyboardinput.cpp | 1 + rendering/common/locallights.cpp | 27 +++++++++++++++++++++++++++ rendering/common/locallights.h | 2 ++ simulation/simulation.cpp | 3 +++ utilities/Globals.h | 3 +++ 7 files changed, 40 insertions(+) diff --git a/input/command.cpp b/input/command.cpp index 30cd9e5b3..0c81b82ec 100644 --- a/input/command.cpp +++ b/input/command.cpp @@ -423,6 +423,7 @@ commanddescription_sequence Commands_descriptions = { {"linebreakeropenc", command_target::vehicle, command_mode::oneoff}, {"linebreakerclosec", command_target::vehicle, command_mode::oneoff}, {"repaircoupler", command_target::simulation, command_mode::oneoff}, + {"flashlighttoggle", command_target::simulation, command_mode::oneoff}, }; // Maps of command and coresponding strings @@ -825,6 +826,7 @@ std::unordered_map const commandMap = { {"linebreakeropenc", user_command::linebreakeropenc}, {"linebreakerclosec", user_command::linebreakerclosec}, {"repaircoupler", user_command::repaircoupler}, + {"flashlighttoggle", user_command::flashlighttoggle}, {"none", user_command::none}}; } // namespace simulation diff --git a/input/command.h b/input/command.h index 01da3c183..3b2955d15 100644 --- a/input/command.h +++ b/input/command.h @@ -421,6 +421,8 @@ enum class user_command linebreakeropenc, linebreakerclosec, repaircoupler, // the broken coupler of the vehicle (payload) at the end (param1) + // the flashlight of the player (Global.flashlight), at the end so the numbers of the commands before it stay as they were + flashlighttoggle, none = -1 }; diff --git a/input/driverkeyboardinput.cpp b/input/driverkeyboardinput.cpp index 047f3678c..fd70b2f70 100644 --- a/input/driverkeyboardinput.cpp +++ b/input/driverkeyboardinput.cpp @@ -263,6 +263,7 @@ driverkeyboard_input::default_bindings() { // interiorlightenable, // interiorlightdisable, { interiorlightdimtoggle, {GLFW_KEY_APOSTROPHE | keymodifier::control, ""} }, + { flashlighttoggle, {GLFW_KEY_L | keymodifier::control | keymodifier::shift, ""} }, // interiorlightdimenable, // interiorlightdimdisable, // compartmentlightstoggle, diff --git a/rendering/common/locallights.cpp b/rendering/common/locallights.cpp index 9f042afe0..2b2ea5b52 100644 --- a/rendering/common/locallights.cpp +++ b/rendering/common/locallights.cpp @@ -254,6 +254,11 @@ void gfx::local_lights::gather(glm::dvec3 const &Camera, scene::basic_region &Re } } + if (Global.flashlight) + { + add_flashlight(); + } + // the most important lights first: when the light buffer or the list of a cluster fills up, the others are left out std::sort(std::begin(m_lights), std::end(m_lights), [&Camera](light const &Left, light const &Right) { return glm::length2(Left.position - Camera) / std::max(max_component(Left.color), 1e-6f) < glm::length2(Right.position - Camera) / std::max(max_component(Right.color), 1e-6f); @@ -264,6 +269,28 @@ void gfx::local_lights::gather(glm::dvec3 const &Camera, scene::basic_region &Re m_gathertime = (m_gathertime == 0.0 ? elapsed : m_gathertime * 0.95 + elapsed * 0.05); } +// the flashlight of the player (Global.flashlight): a cone of warm white light where the camera looks, from a little under it as +// from a hand, by day as well. it casts no shadows (it has no shadow map of its own) +void gfx::local_lights::add_flashlight() +{ + auto const &camera{Global.pCamera}; + glm::dmat4 view{1.0}; + camera.SetMatrix(view); + // the line of sight: the -z axis of the view, in the world + auto const forward{glm::normalize(-glm::dvec3{view[0][2], view[1][2], view[2][2]})}; + auto const up{glm::normalize(glm::dvec3{view[0][1], view[1][1], view[2][1]})}; + light flashlight; + flashlight.position = camera.Pos - up * 0.15; + flashlight.direction = glm::vec3{forward}; + flashlight.color = to_linear(glm::vec3{1.f, 0.93f, 0.82f}) * 4.f; + flashlight.cos_outer = std::cos(glm::radians(24.f)); + flashlight.cos_inner = std::cos(glm::radians(12.f)); + flashlight.range = light_range(flashlight.color); + flashlight.radius = 0.02f; + flashlight.cast_shadows = false; + m_lights.emplace_back(flashlight); +} + void gfx::local_lights::reset() { m_lights.clear(); diff --git a/rendering/common/locallights.h b/rendering/common/locallights.h index 5cfd6247f..140122836 100644 --- a/rendering/common/locallights.h +++ b/rendering/common/locallights.h @@ -78,6 +78,8 @@ class local_lights void gather(glm::dvec3 const &Camera, scene::basic_region &Region, gfx::geometrybank_manager const &Geometry, unsigned int const Framestamp); // forgets the lights and everything kept about the scene, which is about to be replaced (a scenery being loaded) void reset(); + // the flashlight of the player, when it's on (Global.flashlight), added by gather() + void add_flashlight(); // the lights of models and vehicles, the most important (closest and brightest) first std::vector const &lights() const { diff --git a/simulation/simulation.cpp b/simulation/simulation.cpp index c6b150cf4..25c5cf29a 100644 --- a/simulation/simulation.cpp +++ b/simulation/simulation.cpp @@ -256,6 +256,9 @@ void state_manager::process_commands() { if (commanddata.command == user_command::debugtoggle) DebugModeFlag = !DebugModeFlag; + if (commanddata.command == user_command::flashlighttoggle) + Global.flashlight = !Global.flashlight; + if (commanddata.command == user_command::pausetoggle) { if( Global.iPause & 1 ) { // jeśli pauza startowa diff --git a/utilities/Globals.h b/utilities/Globals.h index 2998ca813..762a821bd 100644 --- a/utilities/Globals.h +++ b/utilities/Globals.h @@ -182,6 +182,9 @@ struct global_settings { std::string GfxRenderer{ "default" }; bool RenderShadows{ true }; bool applicationQuitOrder{false}; + // the flashlight of the player is on: a cone of light from the camera where it looks (gfx::local_lights), switched with + // flashlighttoggle (Ctrl+Shift+L). off at the start, not kept between the runs + bool flashlight{false}; int RenderCabShadowsRange{ 0 }; struct shadowtune_t { unsigned int map_size{ 2048 };