16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-21 14:49:19 +02:00

restored keyboard controls for events; tweaks to intensity of vehicle spotlights, minor bug fixes

This commit is contained in:
tmj-fstate
2017-03-06 03:27:52 +01:00
parent d920644af8
commit 89fe4e7f7c
8 changed files with 88 additions and 47 deletions

View File

@@ -55,6 +55,25 @@ void TEventLauncher::Init()
{ {
} }
// encodes expected key in a short, where low byte represents the actual key,
// and the high byte holds modifiers: 0x1 = shift, 0x2 = ctrl, 0x4 = alt
int vk_to_glfw_key( int const Keycode ) {
#ifdef _WINDOWS
auto const code = VkKeyScan( Keycode );
char key = code & 0xff;
char shiftstate = ( code & 0xff00 ) >> 8;
if( (key >= 'A') && (key <= 'Z') ) {
key = GLFW_KEY_A + key - 'A';
}
else if( key >= '0' ) {
key = GLFW_KEY_0 + key - '0';
}
return key + ( shiftstate << 8 );
#endif
}
bool TEventLauncher::Load(cParser *parser) bool TEventLauncher::Load(cParser *parser)
{ // wczytanie wyzwalacza zdarzeń { // wczytanie wyzwalacza zdarzeń
std::string token; std::string token;
@@ -66,10 +85,10 @@ bool TEventLauncher::Load(cParser *parser)
*parser >> token; *parser >> token;
if (token != "none") if (token != "none")
{ {
if (token.size() == 1) if( token.size() == 1 )
iKey = VkKeyScan(token[0]); // jeden znak jest konwertowany na kod klawisza iKey = vk_to_glfw_key( token[ 0 ] );
else else
iKey = stol_def(token,0); // a jak więcej, to jakby numer klawisza jest iKey = vk_to_glfw_key(stol_def( token, 0 )); // a jak więcej, to jakby numer klawisza jest
} }
parser->getTokens(); parser->getTokens();
*parser >> DeltaTime; *parser >> DeltaTime;
@@ -145,8 +164,20 @@ bool TEventLauncher::Render()
bool bCond = false; bool bCond = false;
if (iKey != 0) if (iKey != 0)
{ {
if (Global::bActive) // tylko jeśli okno jest aktywne if( Global::bActive ) {
bCond = (Console::Pressed(iKey)); // czy klawisz wciśnięty // tylko jeśli okno jest aktywne
if( iKey > 255 ) {
// key and modifier
auto const modifier = ( iKey & 0xff00 ) >> 8;
bCond = ( Console::Pressed( iKey & 0xff ) )
&& ( modifier & 1 ? Global::shiftState : true )
&& ( modifier & 2 ? Global::ctrlState : true );
}
else {
// just key
bCond = ( Console::Pressed( iKey & 0xff ) ); // czy klawisz wciśnięty
}
}
} }
if (DeltaTime > 0) if (DeltaTime > 0)
{ {

View File

@@ -90,8 +90,8 @@ TTranscripts Global::tranTexts; // obiekt obsługujący stenogramy dźwięków n
vector3 Global::pCameraPosition; vector3 Global::pCameraPosition;
double Global::pCameraRotation; double Global::pCameraRotation;
double Global::pCameraRotationDeg; double Global::pCameraRotationDeg;
vector3 Global::pFreeCameraInit[10]; std::vector<vector3> Global::FreeCameraInit;
vector3 Global::pFreeCameraInitAngle[10]; std::vector<vector3> Global::FreeCameraInitAngle;
double Global::fFogStart = 1700; double Global::fFogStart = 1700;
double Global::fFogEnd = 2000; double Global::fFogEnd = 2000;
float Global::Background[3] = {0.2, 0.4, 0.33}; float Global::Background[3] = {0.2, 0.4, 0.33};
@@ -240,11 +240,15 @@ std::string Global::GetNextSymbol()
void Global::LoadIniFile(std::string asFileName) void Global::LoadIniFile(std::string asFileName)
{ {
/*
for (int i = 0; i < 10; ++i) for (int i = 0; i < 10; ++i)
{ // zerowanie pozycji kamer { // zerowanie pozycji kamer
pFreeCameraInit[i] = vector3(0, 0, 0); // współrzędne w scenerii pFreeCameraInit[i] = vector3(0, 0, 0); // współrzędne w scenerii
pFreeCameraInitAngle[i] = vector3(0, 0, 0); // kąty obrotu w radianach pFreeCameraInitAngle[i] = vector3(0, 0, 0); // kąty obrotu w radianach
} }
*/
FreeCameraInit.resize( 10 );
FreeCameraInitAngle.resize( 10 );
cParser parser(asFileName, cParser::buffer_FILE); cParser parser(asFileName, cParser::buffer_FILE);
ConfigParse(parser); ConfigParse(parser);
}; };
@@ -322,8 +326,10 @@ void Global::ConfigParse(cParser &Parser)
Parser.getTokens(); Parser.getTokens();
Parser >> Global::bFreeFly; Parser >> Global::bFreeFly;
Parser.getTokens(3, false); Parser.getTokens(3, false);
Parser >> Global::pFreeCameraInit[0].x, Global::pFreeCameraInit[0].y, Parser >>
Global::pFreeCameraInit[0].z; Global::FreeCameraInit[0].x,
Global::FreeCameraInit[0].y,
Global::FreeCameraInit[0].z;
} }
else if (token == "wireframe") else if (token == "wireframe")
{ {

View File

@@ -170,8 +170,8 @@ class Global
static double static double
pCameraRotation; // kierunek bezwzględny kamery w świecie: 0=północ, 90°=zachód (-azymut) pCameraRotation; // kierunek bezwzględny kamery w świecie: 0=północ, 90°=zachód (-azymut)
static double pCameraRotationDeg; // w stopniach, dla animacji billboard static double pCameraRotationDeg; // w stopniach, dla animacji billboard
static Math3D::vector3 pFreeCameraInit[10]; // pozycje kamery static std::vector<Math3D::vector3> FreeCameraInit; // pozycje kamery
static Math3D::vector3 pFreeCameraInitAngle[10]; static std::vector<Math3D::vector3> FreeCameraInitAngle;
static int iWindowWidth; static int iWindowWidth;
static int iWindowHeight; static int iWindowHeight;
static float fDistanceFactor; static float fDistanceFactor;

View File

@@ -2959,11 +2959,12 @@ bool TGround::Init(std::string File)
into = ++Global::iCameraLast; into = ++Global::iCameraLast;
if ((into >= 0) && (into < 10)) if ((into >= 0) && (into < 10))
{ // przepisanie do odpowiedniego miejsca w tabelce { // przepisanie do odpowiedniego miejsca w tabelce
Global::pFreeCameraInit[into] = xyz; Global::FreeCameraInit[ into ] = xyz;
abc.x = DegToRad(abc.x); Global::FreeCameraInitAngle[ into ] =
abc.y = DegToRad(abc.y); Math3D::vector3(
abc.z = DegToRad(abc.z); DegToRad( abc.x ),
Global::pFreeCameraInitAngle[into] = abc; DegToRad( abc.y ),
DegToRad( abc.z ) );
Global::iCameraLast = into; // numer ostatniej Global::iCameraLast = into; // numer ostatniej
} }
} }

View File

@@ -3814,10 +3814,13 @@ double TMoverParameters::TractionForce(double dt)
} }
eAngle += enrot * dt; eAngle += enrot * dt;
if( eAngle > M_PI * 2.0 )
eAngle = std::fmod( eAngle, M_PI * 2.0 );
/*
while (eAngle > M_PI * 2.0) while (eAngle > M_PI * 2.0)
// eAngle = Pirazy2 - eAngle; <- ABu: a nie czasem tak, jak nizej? // eAngle = Pirazy2 - eAngle; <- ABu: a nie czasem tak, jak nizej?
eAngle -= M_PI * 2.0; eAngle -= M_PI * 2.0;
*/
// hunter-091012: przeniesione z if ActiveDir<>0 (zeby po zejsciu z kierunku dalej spadala // hunter-091012: przeniesione z if ActiveDir<>0 (zeby po zejsciu z kierunku dalej spadala
// predkosc wentylatorow) // predkosc wentylatorow)
if (EngineType == ElectricSeriesMotor) if (EngineType == ElectricSeriesMotor)

View File

@@ -90,7 +90,7 @@ double PFVa( double PH, double PL, double const S, double LIM, double const DP )
LIM = LIM + 1; LIM = LIM + 1;
PH = PH + 1; // wyzsze cisnienie absolutne PH = PH + 1; // wyzsze cisnienie absolutne
PL = PL + 1; // nizsze cisnienie absolutne PL = PL + 1; // nizsze cisnienie absolutne
double sg = PL / PH; // bezwymiarowy stosunek cisnien double sg = std::min( 1.0, PL / PH ); // bezwymiarowy stosunek cisnien. NOTE: sg is capped at 1 to prevent calculations from going awry. TODO, TBD: log these as errors?
double FM = PH * 197 * S; // najwyzszy mozliwy przeplyw, wraz z kierunkiem double FM = PH * 197 * S; // najwyzszy mozliwy przeplyw, wraz z kierunkiem
if ((LIM - PL) < DP) if ((LIM - PL) < DP)
FM = FM * (LIM - PL) / DP; // jesli jestesmy przy nastawieniu, to zawor sie przymyka FM = FM * (LIM - PL) / DP; // jesli jestesmy przy nastawieniu, to zawor sie przymyka

View File

@@ -472,7 +472,7 @@ bool TWorld::Init( GLFWwindow *w ) {
// Camera.Init(vector3(1500,5,-4000),0,M_PI,0); // Camera.Init(vector3(1500,5,-4000),0,M_PI,0);
// McZapkie-130302 - coby nie przekompilowywac: // McZapkie-130302 - coby nie przekompilowywac:
// Camera.Init(Global::pFreeCameraInit,0,M_PI,0); // Camera.Init(Global::pFreeCameraInit,0,M_PI,0);
Camera.Init(Global::pFreeCameraInit[0], Global::pFreeCameraInitAngle[0]); Camera.Init(Global::FreeCameraInit[0], Global::FreeCameraInitAngle[0]);
char buff[255] = "Player train init: "; char buff[255] = "Player train init: ";
glRasterPos2f( -0.85f * widthratio, -0.50f ); glRasterPos2f( -0.85f * widthratio, -0.50f );
@@ -570,9 +570,9 @@ void TWorld::OnKeyDown(int cKey)
// na każdy kod wirtualny niech przypadają 4 bajty: 2 dla naciśnięcia i 2 dla zwolnienia // na każdy kod wirtualny niech przypadają 4 bajty: 2 dla naciśnięcia i 2 dla zwolnienia
// powtórzone 256 razy da 1kB na każdy stan przełączników, łącznie będzie 4kB pierwszej tabeli // powtórzone 256 razy da 1kB na każdy stan przełączników, łącznie będzie 4kB pierwszej tabeli
// przekodowania // przekodowania
if ((cKey <= '9') ? (cKey >= '0') : false) // klawisze cyfrowe if( ( cKey >= GLFW_KEY_0 ) && ( cKey <= GLFW_KEY_9 ) ) // klawisze cyfrowe
{ {
int i = cKey - '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
if (!Global::iPause) // podczas pauzy klawisze nie działają if (!Global::iPause) // podczas pauzy klawisze nie działają
@@ -584,32 +584,31 @@ void TWorld::OnKeyDown(int cKey)
if( ( Global::iTextMode != GLFW_KEY_F12 ) && if( ( Global::iTextMode != GLFW_KEY_F12 ) &&
( Global::iTextMode != GLFW_KEY_F3 ) ) // ograniczamy użycie kamer ( Global::iTextMode != GLFW_KEY_F3 ) ) // ograniczamy użycie kamer
{ {
if ((!Global::pFreeCameraInit[i].x && !Global::pFreeCameraInit[i].y && if ((!Global::FreeCameraInit[i].x)
!Global::pFreeCameraInit[i].z)) && (!Global::FreeCameraInit[i].y)
&& (!Global::FreeCameraInit[i].z))
{ // jeśli kamera jest w punkcie zerowym, zapamiętanie współrzędnych i kątów { // jeśli kamera jest w punkcie zerowym, zapamiętanie współrzędnych i kątów
Global::pFreeCameraInit[i] = Camera.Pos; Global::FreeCameraInit[i] = Camera.Pos;
Global::pFreeCameraInitAngle[i].x = Camera.Pitch; Global::FreeCameraInitAngle[i].x = Camera.Pitch;
Global::pFreeCameraInitAngle[i].y = Camera.Yaw; Global::FreeCameraInitAngle[i].y = Camera.Yaw;
Global::pFreeCameraInitAngle[i].z = Camera.Roll; Global::FreeCameraInitAngle[i].z = Camera.Roll;
// logowanie, żeby można było do scenerii przepisać // logowanie, żeby można było do scenerii przepisać
WriteLog( WriteLog(
"camera " + std::to_string( Global::pFreeCameraInit[i].x ) + " " + "camera " + std::to_string( Global::FreeCameraInit[i].x ) + " "
std::to_string(Global::pFreeCameraInit[i].y ) + " " + + std::to_string(Global::FreeCameraInit[i].y ) + " "
std::to_string(Global::pFreeCameraInit[i].z ) + " " + + std::to_string(Global::FreeCameraInit[i].z ) + " "
std::to_string(RadToDeg(Global::pFreeCameraInitAngle[i].x)) + + std::to_string(RadToDeg(Global::FreeCameraInitAngle[i].x)) + " "
" " + + std::to_string(RadToDeg(Global::FreeCameraInitAngle[i].y)) + " "
std::to_string(RadToDeg(Global::pFreeCameraInitAngle[i].y)) + + std::to_string(RadToDeg(Global::FreeCameraInitAngle[i].z)) + " "
" " + + std::to_string(i) + " endcamera");
std::to_string(RadToDeg(Global::pFreeCameraInitAngle[i].z)) +
" " + std::to_string(i) + " endcamera");
} }
else // również przeskakiwanie else // również przeskakiwanie
{ // Ra: to z tą kamerą (Camera.Pos i Global::pCameraPosition) jest trochę bez sensu { // Ra: to z tą kamerą (Camera.Pos i Global::pCameraPosition) jest trochę bez sensu
Global::SetCameraPosition( Global::SetCameraPosition(
Global::pFreeCameraInit[i]); // nowa pozycja dla generowania obiektów Global::FreeCameraInit[i]); // nowa pozycja dla generowania obiektów
Ground.Silence(Camera.Pos); // wyciszenie wszystkiego z poprzedniej pozycji Ground.Silence(Camera.Pos); // wyciszenie wszystkiego z poprzedniej pozycji
Camera.Init(Global::pFreeCameraInit[i], Camera.Init(Global::FreeCameraInit[i],
Global::pFreeCameraInitAngle[i]); // przestawienie Global::FreeCameraInitAngle[i]); // przestawienie
} }
} }
// będzie jeszcze załączanie sprzęgów z [Ctrl] // będzie jeszcze załączanie sprzęgów z [Ctrl]
@@ -802,9 +801,9 @@ void TWorld::OnKeyDown(int cKey)
CouplNr = 0; // z [-1,1] zrobić [0,1] CouplNr = 0; // z [-1,1] zrobić [0,1]
int mask, set = 0; // Ra: [Shift]+[Ctrl]+[T] odpala mi jakąś idiotyczną zmianę int mask, set = 0; // Ra: [Shift]+[Ctrl]+[T] odpala mi jakąś idiotyczną zmianę
// tapety pulpitu :/ // tapety pulpitu :/
if (Global::shiftState < 0) // z [Shift] zapalanie if (Global::shiftState) // z [Shift] zapalanie
set = mask = 64; // bez [Ctrl] założyć tabliczki set = mask = 64; // bez [Ctrl] założyć tabliczki
else if (Global::ctrlState < 0) else if (Global::ctrlState)
set = mask = 2 + 32; // z [Ctrl] zapalić światła czerwone set = mask = 2 + 32; // z [Ctrl] zapalić światła czerwone
else else
mask = 2 + 32 + 64; // wyłączanie ściąga wszystko mask = 2 + 32 + 64; // wyłączanie ściąga wszystko

View File

@@ -59,12 +59,13 @@ opengl_renderer::Update_Lights( light_array const &Lights ) {
renderlight->set_position( scenelight.position ); renderlight->set_position( scenelight.position );
renderlight->direction = scenelight.direction; renderlight->direction = scenelight.direction;
renderlight->diffuse[ 0 ] = scenelight.color.x; auto const luminance = Global::fLuminance; // TODO: adjust this based on location, e.g. for tunnels
renderlight->diffuse[ 1 ] = scenelight.color.y; renderlight->diffuse[ 0 ] = std::max( 0.0, scenelight.color.x - luminance );
renderlight->diffuse[ 2 ] = scenelight.color.z; renderlight->diffuse[ 1 ] = std::max( 0.0, scenelight.color.y - luminance );
renderlight->ambient[ 0 ] = scenelight.color.x * scenelight.intensity; renderlight->diffuse[ 2 ] = std::max( 0.0, scenelight.color.z - luminance );
renderlight->ambient[ 1 ] = scenelight.color.y * scenelight.intensity; renderlight->ambient[ 0 ] = std::max( 0.0, scenelight.color.x * scenelight.intensity - luminance);
renderlight->ambient[ 2 ] = scenelight.color.z * scenelight.intensity; renderlight->ambient[ 1 ] = std::max( 0.0, scenelight.color.y * scenelight.intensity - luminance );
renderlight->ambient[ 2 ] = std::max( 0.0, scenelight.color.z * scenelight.intensity - luminance );
::glLightf( renderlight->id, GL_LINEAR_ATTENUATION, (0.25f * scenelight.count) / std::pow( scenelight.count, 2 ) ); ::glLightf( renderlight->id, GL_LINEAR_ATTENUATION, (0.25f * scenelight.count) / std::pow( scenelight.count, 2 ) );
::glEnable( renderlight->id ); ::glEnable( renderlight->id );