mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-22 18:39:18 +02:00
disable interaction in pause mode, audio volume calculations tweak
This commit is contained in:
@@ -127,7 +127,7 @@ global_settings::ConfigParse(cParser &Parser) {
|
|||||||
// selected device for audio renderer
|
// selected device for audio renderer
|
||||||
Parser.getTokens();
|
Parser.getTokens();
|
||||||
Parser >> AudioVolume;
|
Parser >> AudioVolume;
|
||||||
AudioVolume = clamp( AudioVolume, 1.f, 4.f );
|
AudioVolume = clamp( AudioVolume, 0.0f, 2.f );
|
||||||
}
|
}
|
||||||
// else if (str==AnsiString("renderalpha")) //McZapkie-1312302 - dwuprzebiegowe renderowanie
|
// else if (str==AnsiString("renderalpha")) //McZapkie-1312302 - dwuprzebiegowe renderowanie
|
||||||
// bRenderAlpha=(GetNextSymbol().LowerCase()==AnsiString("yes"));
|
// bRenderAlpha=(GetNextSymbol().LowerCase()==AnsiString("yes"));
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ struct global_settings {
|
|||||||
std::string LastGLError;
|
std::string LastGLError;
|
||||||
float ZoomFactor{ 1.f }; // determines current camera zoom level. TODO: move it to the renderer
|
float ZoomFactor{ 1.f }; // determines current camera zoom level. TODO: move it to the renderer
|
||||||
bool CabWindowOpen{ false }; // controls sound attenuation between cab and outside
|
bool CabWindowOpen{ false }; // controls sound attenuation between cab and outside
|
||||||
bool ControlPicking{ false }; // indicates controls pick mode is active
|
bool ControlPicking{ true }; // indicates controls pick mode is active
|
||||||
bool DLFont{ false }; // switch indicating presence of basic font
|
bool DLFont{ false }; // switch indicating presence of basic font
|
||||||
bool bActive{ true }; // czy jest aktywnym oknem
|
bool bActive{ true }; // czy jest aktywnym oknem
|
||||||
int iPause{ 0 }; // globalna pauza ruchu: b0=start,b1=klawisz,b2=tło,b3=lagi,b4=wczytywanie
|
int iPause{ 0 }; // globalna pauza ruchu: b0=start,b1=klawisz,b2=tło,b3=lagi,b4=wczytywanie
|
||||||
|
|||||||
@@ -154,7 +154,7 @@ openal_source::sync_with( sound_properties const &State ) {
|
|||||||
properties.soundproofing = State.soundproofing;
|
properties.soundproofing = State.soundproofing;
|
||||||
properties.soundproofing_stamp = State.soundproofing_stamp;
|
properties.soundproofing_stamp = State.soundproofing_stamp;
|
||||||
|
|
||||||
::alSourcef( id, AL_GAIN, properties.gain * properties.soundproofing * Global.AudioVolume );
|
::alSourcef( id, AL_GAIN, properties.gain * properties.soundproofing );
|
||||||
}
|
}
|
||||||
if( sound_range > 0 ) {
|
if( sound_range > 0 ) {
|
||||||
auto const rangesquared { sound_range * sound_range };
|
auto const rangesquared { sound_range * sound_range };
|
||||||
@@ -170,7 +170,7 @@ openal_source::sync_with( sound_properties const &State ) {
|
|||||||
clamp<float>(
|
clamp<float>(
|
||||||
( distancesquared - rangesquared ) / ( fadedistance * fadedistance ),
|
( distancesquared - rangesquared ) / ( fadedistance * fadedistance ),
|
||||||
0.f, 1.f ) ) };
|
0.f, 1.f ) ) };
|
||||||
::alSourcef( id, AL_GAIN, properties.gain * properties.soundproofing * rangefactor * Global.AudioVolume );
|
::alSourcef( id, AL_GAIN, properties.gain * properties.soundproofing * rangefactor );
|
||||||
}
|
}
|
||||||
is_in_range = ( distancesquared <= rangesquared );
|
is_in_range = ( distancesquared <= rangesquared );
|
||||||
}
|
}
|
||||||
@@ -283,10 +283,7 @@ openal_renderer::init() {
|
|||||||
// basic initialization failed
|
// basic initialization failed
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
//
|
|
||||||
// ::alDistanceModel( AL_LINEAR_DISTANCE );
|
|
||||||
::alDistanceModel( AL_INVERSE_DISTANCE_CLAMPED );
|
::alDistanceModel( AL_INVERSE_DISTANCE_CLAMPED );
|
||||||
::alListenerf( AL_GAIN, clamp( Global.AudioVolume, 1.f, 4.f ) );
|
|
||||||
// all done
|
// all done
|
||||||
m_ready = true;
|
m_ready = true;
|
||||||
return true;
|
return true;
|
||||||
@@ -319,6 +316,8 @@ void
|
|||||||
openal_renderer::update( double const Deltatime ) {
|
openal_renderer::update( double const Deltatime ) {
|
||||||
|
|
||||||
// update listener
|
// update listener
|
||||||
|
// gain
|
||||||
|
::alListenerf( AL_GAIN, clamp( Global.AudioVolume, 0.f, 2.f ) * ( Global.iPause == 0 ? 1.f : 0.15f ) );
|
||||||
// orientation
|
// orientation
|
||||||
glm::dmat4 cameramatrix;
|
glm::dmat4 cameramatrix;
|
||||||
Global.pCamera.SetMatrix( cameramatrix );
|
Global.pCamera.SetMatrix( cameramatrix );
|
||||||
|
|||||||
@@ -299,9 +299,7 @@ driver_mode::enter() {
|
|||||||
|
|
||||||
Timer::ResetTimers();
|
Timer::ResetTimers();
|
||||||
|
|
||||||
Application.set_cursor( GLFW_CURSOR_DISABLED );
|
set_picking( Global.ControlPicking );
|
||||||
Application.set_cursor_pos( 0, 0 );
|
|
||||||
Global.ControlPicking = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// maintenance method, called when the mode is deactivated
|
// maintenance method, called when the mode is deactivated
|
||||||
@@ -351,6 +349,9 @@ driver_mode::on_key( int const Key, int const Scancode, int const Action, int co
|
|||||||
void
|
void
|
||||||
driver_mode::on_cursor_pos( double const Horizontal, double const Vertical ) {
|
driver_mode::on_cursor_pos( double const Horizontal, double const Vertical ) {
|
||||||
|
|
||||||
|
// give the ui first shot at the input processing...
|
||||||
|
if( true == m_userinterface->on_cursor_pos( Horizontal, Vertical ) ) { return; }
|
||||||
|
|
||||||
if( false == Global.ControlPicking ) {
|
if( false == Global.ControlPicking ) {
|
||||||
// in regular view mode keep cursor on screen
|
// in regular view mode keep cursor on screen
|
||||||
Application.set_cursor_pos( 0, 0 );
|
Application.set_cursor_pos( 0, 0 );
|
||||||
@@ -362,6 +363,9 @@ driver_mode::on_cursor_pos( double const Horizontal, double const Vertical ) {
|
|||||||
void
|
void
|
||||||
driver_mode::on_mouse_button( int const Button, int const Action, int const Mods ) {
|
driver_mode::on_mouse_button( int const Button, int const Action, int const Mods ) {
|
||||||
|
|
||||||
|
// give the ui first shot at the input processing...
|
||||||
|
if( true == m_userinterface->on_mouse_button( Button, Action ) ) { return; }
|
||||||
|
|
||||||
// give the potential event recipient a shot at it, in the virtual z order
|
// give the potential event recipient a shot at it, in the virtual z order
|
||||||
m_input.mouse.button( Button, Action );
|
m_input.mouse.button( Button, Action );
|
||||||
}
|
}
|
||||||
@@ -561,8 +565,8 @@ driver_mode::OnKeyDown(int cKey) {
|
|||||||
|
|
||||||
// actual key processing
|
// actual key processing
|
||||||
// TODO: redo the input system
|
// TODO: redo the input system
|
||||||
if( ( cKey >= GLFW_KEY_0 ) && ( cKey <= GLFW_KEY_9 ) ) // klawisze cyfrowe
|
if( ( cKey >= GLFW_KEY_0 ) && ( cKey <= GLFW_KEY_9 ) ) {
|
||||||
{
|
// klawisze cyfrowe
|
||||||
int i = cKey - GLFW_KEY_0; // numer klawisza
|
int i = cKey - GLFW_KEY_0; // numer klawisza
|
||||||
if (Global.shiftState) {
|
if (Global.shiftState) {
|
||||||
// z [Shift] uruchomienie eventu
|
// z [Shift] uruchomienie eventu
|
||||||
@@ -600,9 +604,9 @@ driver_mode::OnKeyDown(int cKey) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else if( ( cKey >= GLFW_KEY_F1 ) && ( cKey <= GLFW_KEY_F12 ) )
|
|
||||||
{
|
|
||||||
switch (cKey) {
|
switch (cKey) {
|
||||||
|
|
||||||
case GLFW_KEY_F1: {
|
case GLFW_KEY_F1: {
|
||||||
@@ -719,52 +723,10 @@ driver_mode::OnKeyDown(int cKey) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
default: {
|
case GLFW_KEY_LEFT_BRACKET:
|
||||||
break;
|
case GLFW_KEY_RIGHT_BRACKET:
|
||||||
}
|
case GLFW_KEY_TAB: {
|
||||||
}
|
// consist movement in debug mode
|
||||||
// if (cKey!=VK_F4)
|
|
||||||
return; // nie są przekazywane do pojazdu wcale
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
if ((Global.iTextMode == GLFW_KEY_F12) ? (cKey >= '0') && (cKey <= '9') : false)
|
|
||||||
{ // tryb konfiguracji debugmode (przestawianie kamery już wyłączone
|
|
||||||
if (!Global.shiftState) // bez [Shift]
|
|
||||||
{
|
|
||||||
if (cKey == GLFW_KEY_1)
|
|
||||||
Global.iWriteLogEnabled ^= 1; // włącz/wyłącz logowanie do pliku
|
|
||||||
else if (cKey == GLFW_KEY_2)
|
|
||||||
{ // włącz/wyłącz okno konsoli
|
|
||||||
Global.iWriteLogEnabled ^= 2;
|
|
||||||
if ((Global.iWriteLogEnabled & 2) == 0) // nie było okienka
|
|
||||||
{ // otwarcie okna
|
|
||||||
AllocConsole(); // jeśli konsola już jest, to zwróci błąd; uwalniać nie ma po
|
|
||||||
// co, bo się odłączy
|
|
||||||
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// else if (cKey=='3') Global.iWriteLogEnabled^=4; //wypisywanie nazw torów
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else */
|
|
||||||
if( cKey == GLFW_KEY_ESCAPE ) {
|
|
||||||
// toggle pause
|
|
||||||
if( Global.iPause & 1 ) {
|
|
||||||
// jeśli pauza startowa
|
|
||||||
// odpauzowanie, gdy po wczytaniu miało nie startować
|
|
||||||
Global.iPause &= ~1;
|
|
||||||
}
|
|
||||||
else if( ( Global.iMultiplayer & 2 ) == 0 ) {
|
|
||||||
// w multiplayerze pauza nie ma sensu
|
|
||||||
Global.iPause ^= 2; // zmiana stanu zapauzowania
|
|
||||||
if( ( Global.iPause & 2 )
|
|
||||||
&& ( false == Global.ControlPicking ) ) {
|
|
||||||
set_picking( true );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
if( ( true == DebugModeFlag )
|
if( ( true == DebugModeFlag )
|
||||||
&& ( false == Global.shiftState )
|
&& ( false == Global.shiftState )
|
||||||
&& ( true == Global.ctrlState )
|
&& ( true == Global.ctrlState )
|
||||||
@@ -810,7 +772,15 @@ driver_mode::OnKeyDown(int cKey) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default: {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return; // nie są przekazywane do pojazdu wcale
|
||||||
}
|
}
|
||||||
|
|
||||||
// places camera outside the controlled vehicle, or nearest if nothing is under control
|
// places camera outside the controlled vehicle, or nearest if nothing is under control
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ http://mozilla.org/MPL/2.0/.
|
|||||||
#include "driveruilayer.h"
|
#include "driveruilayer.h"
|
||||||
|
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
|
#include "application.h"
|
||||||
#include "translation.h"
|
#include "translation.h"
|
||||||
#include "simulation.h"
|
#include "simulation.h"
|
||||||
#include "train.h"
|
#include "train.h"
|
||||||
@@ -42,7 +43,26 @@ bool
|
|||||||
driver_ui::on_key( int const Key, int const Action ) {
|
driver_ui::on_key( int const Key, int const Action ) {
|
||||||
// TODO: pass the input first through an active ui element if there's any
|
// TODO: pass the input first through an active ui element if there's any
|
||||||
// if the ui element shows no interest or we don't have one, try to interpret the input yourself:
|
// if the ui element shows no interest or we don't have one, try to interpret the input yourself:
|
||||||
// shared conditions
|
|
||||||
|
if( Key == GLFW_KEY_ESCAPE ) {
|
||||||
|
// toggle pause
|
||||||
|
if( Action != GLFW_PRESS ) { return true; } // recognized, but ignored
|
||||||
|
|
||||||
|
if( Global.iPause & 1 ) {
|
||||||
|
// jeśli pauza startowa
|
||||||
|
// odpauzowanie, gdy po wczytaniu miało nie startować
|
||||||
|
Global.iPause ^= 1;
|
||||||
|
}
|
||||||
|
else if( ( Global.iMultiplayer & 2 ) == 0 ) {
|
||||||
|
// w multiplayerze pauza nie ma sensu
|
||||||
|
Global.iPause ^= 2; // zmiana stanu zapauzowania
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if the pause is on ignore block other input
|
||||||
|
if( m_paused ) { return true; }
|
||||||
|
|
||||||
switch( Key ) {
|
switch( Key ) {
|
||||||
|
|
||||||
case GLFW_KEY_F1:
|
case GLFW_KEY_F1:
|
||||||
@@ -108,10 +128,32 @@ driver_ui::on_key( int const Key, int const Action ) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// potentially processes provided mouse movement. returns: true if the input was processed, false otherwise
|
||||||
|
bool
|
||||||
|
driver_ui::on_cursor_pos( double const Horizontal, double const Vertical ) {
|
||||||
|
// intercept mouse movement when the pause window is on
|
||||||
|
return m_paused;
|
||||||
|
}
|
||||||
|
|
||||||
|
// potentially processes provided mouse button. returns: true if the input was processed, false otherwise
|
||||||
|
bool
|
||||||
|
driver_ui::on_mouse_button( int const Button, int const Action ) {
|
||||||
|
// intercept mouse movement when the pause window is on
|
||||||
|
return m_paused;
|
||||||
|
}
|
||||||
|
|
||||||
// updates state of UI elements
|
// updates state of UI elements
|
||||||
void
|
void
|
||||||
driver_ui::update() {
|
driver_ui::update() {
|
||||||
|
|
||||||
|
auto const pausemask { 1 | 2 };
|
||||||
|
auto ispaused { ( Global.iPause & pausemask ) != 0 };
|
||||||
|
if( ( ispaused != m_paused )
|
||||||
|
&& ( false == Global.ControlPicking ) ) {
|
||||||
|
set_cursor( ispaused );
|
||||||
|
}
|
||||||
|
m_paused = ispaused;
|
||||||
|
|
||||||
set_tooltip( "" );
|
set_tooltip( "" );
|
||||||
|
|
||||||
auto const *train { simulation::Train };
|
auto const *train { simulation::Train };
|
||||||
@@ -138,12 +180,24 @@ driver_ui::update() {
|
|||||||
ui_layer::update();
|
ui_layer::update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
driver_ui::set_cursor( bool const Visible ) {
|
||||||
|
|
||||||
|
if( Visible ) {
|
||||||
|
Application.set_cursor( GLFW_CURSOR_NORMAL );
|
||||||
|
Application.set_cursor_pos( Global.iWindowWidth / 2, Global.iWindowHeight / 2 );
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Application.set_cursor( GLFW_CURSOR_DISABLED );
|
||||||
|
Application.set_cursor_pos( 0, 0 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// render() subclass details
|
// render() subclass details
|
||||||
void
|
void
|
||||||
driver_ui::render_() {
|
driver_ui::render_() {
|
||||||
|
|
||||||
auto const pausemask { 1 | 2 };
|
if( m_paused ) {
|
||||||
if( ( Global.iPause & pausemask ) != 0 ) {
|
|
||||||
// pause/quit modal
|
// pause/quit modal
|
||||||
auto const popupheader { locale::strings[ locale::string::driver_pause_header ].c_str() };
|
auto const popupheader { locale::strings[ locale::string::driver_pause_header ].c_str() };
|
||||||
ImGui::OpenPopup( popupheader );
|
ImGui::OpenPopup( popupheader );
|
||||||
@@ -151,6 +205,7 @@ driver_ui::render_() {
|
|||||||
auto const popupwidth{ locale::strings[ locale::string::driver_pause_header ].size() * 7 };
|
auto const popupwidth{ locale::strings[ locale::string::driver_pause_header ].size() * 7 };
|
||||||
if( ImGui::Button( locale::strings[ locale::string::driver_pause_resume ].c_str(), ImVec2( popupwidth, 0 ) ) ) {
|
if( ImGui::Button( locale::strings[ locale::string::driver_pause_resume ].c_str(), ImVec2( popupwidth, 0 ) ) ) {
|
||||||
ImGui::CloseCurrentPopup();
|
ImGui::CloseCurrentPopup();
|
||||||
|
auto const pausemask { 1 | 2 };
|
||||||
Global.iPause &= ~pausemask;
|
Global.iPause &= ~pausemask;
|
||||||
}
|
}
|
||||||
if( ImGui::Button( locale::strings[ locale::string::driver_pause_quit ].c_str(), ImVec2( popupwidth, 0 ) ) ) {
|
if( ImGui::Button( locale::strings[ locale::string::driver_pause_quit ].c_str(), ImVec2( popupwidth, 0 ) ) ) {
|
||||||
|
|||||||
@@ -21,12 +21,21 @@ public:
|
|||||||
// potentially processes provided input key. returns: true if the input was processed, false otherwise
|
// potentially processes provided input key. returns: true if the input was processed, false otherwise
|
||||||
bool
|
bool
|
||||||
on_key( int const Key, int const Action ) override;
|
on_key( int const Key, int const Action ) override;
|
||||||
|
// potentially processes provided mouse movement. returns: true if the input was processed, false otherwise
|
||||||
|
bool
|
||||||
|
on_cursor_pos( double const Horizontal, double const Vertical ) override;
|
||||||
|
// potentially processes provided mouse button. returns: true if the input was processed, false otherwise
|
||||||
|
bool
|
||||||
|
on_mouse_button( int const Button, int const Action ) override;
|
||||||
// updates state of UI elements
|
// updates state of UI elements
|
||||||
void
|
void
|
||||||
update() override;
|
update() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// methods
|
// methods
|
||||||
|
// sets visibility of the cursor
|
||||||
|
void
|
||||||
|
set_cursor( bool const Visible );
|
||||||
// render() subclass details
|
// render() subclass details
|
||||||
void
|
void
|
||||||
render_() override;
|
render_() override;
|
||||||
@@ -35,5 +44,6 @@ private:
|
|||||||
timetable_panel m_timetablepanel { "Timetable", false };
|
timetable_panel m_timetablepanel { "Timetable", false };
|
||||||
debug_panel m_debugpanel { "Debug Data", false };
|
debug_panel m_debugpanel { "Debug Data", false };
|
||||||
transcripts_panel m_transcriptspanel { "Transcripts", true }; // voice transcripts
|
transcripts_panel m_transcriptspanel { "Transcripts", true }; // voice transcripts
|
||||||
|
bool m_paused { false };
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
12
uilayer.cpp
12
uilayer.cpp
@@ -129,6 +129,18 @@ ui_layer::on_key( int const Key, int const Action ) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
ui_layer::on_cursor_pos( double const Horizontal, double const Vertical ) {
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
ui_layer::on_mouse_button( int const Button, int const Action ) {
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ui_layer::update() {
|
ui_layer::update() {
|
||||||
|
|
||||||
|
|||||||
@@ -69,6 +69,14 @@ public:
|
|||||||
virtual
|
virtual
|
||||||
bool
|
bool
|
||||||
on_key( int const Key, int const Action );
|
on_key( int const Key, int const Action );
|
||||||
|
// potentially processes provided mouse movement. returns: true if the input was processed, false otherwise
|
||||||
|
virtual
|
||||||
|
bool
|
||||||
|
on_cursor_pos( double const Horizontal, double const Vertical );
|
||||||
|
// potentially processes provided mouse button. returns: true if the input was processed, false otherwise
|
||||||
|
virtual
|
||||||
|
bool
|
||||||
|
on_mouse_button( int const Button, int const Action );
|
||||||
// updates state of UI elements
|
// updates state of UI elements
|
||||||
virtual
|
virtual
|
||||||
void
|
void
|
||||||
|
|||||||
Reference in New Issue
Block a user