mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-03 10:05:23 +01:00
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 <noreply@anthropic.com>
This commit is contained in:
@@ -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<std::string, user_command> const commandMap = {
|
||||
{"linebreakeropenc", user_command::linebreakeropenc},
|
||||
{"linebreakerclosec", user_command::linebreakerclosec},
|
||||
{"repaircoupler", user_command::repaircoupler},
|
||||
{"flashlighttoggle", user_command::flashlighttoggle},
|
||||
{"none", user_command::none}};
|
||||
|
||||
} // namespace simulation
|
||||
|
||||
@@ -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
|
||||
};
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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<light> const &lights() const
|
||||
{
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 };
|
||||
|
||||
Reference in New Issue
Block a user