16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-18 01:59: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)
{ // wczytanie wyzwalacza zdarzeń
std::string token;
@@ -66,10 +85,10 @@ bool TEventLauncher::Load(cParser *parser)
*parser >> token;
if (token != "none")
{
if (token.size() == 1)
iKey = VkKeyScan(token[0]); // jeden znak jest konwertowany na kod klawisza
if( token.size() == 1 )
iKey = vk_to_glfw_key( token[ 0 ] );
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 >> DeltaTime;
@@ -145,8 +164,20 @@ bool TEventLauncher::Render()
bool bCond = false;
if (iKey != 0)
{
if (Global::bActive) // tylko jeśli okno jest aktywne
bCond = (Console::Pressed(iKey)); // czy klawisz wciśnięty
if( Global::bActive ) {
// 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)
{

View File

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

View File

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

View File

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

View File

@@ -3814,10 +3814,13 @@ double TMoverParameters::TractionForce(double dt)
}
eAngle += enrot * dt;
if( eAngle > M_PI * 2.0 )
eAngle = std::fmod( eAngle, M_PI * 2.0 );
/*
while (eAngle > M_PI * 2.0)
// eAngle = Pirazy2 - eAngle; <- ABu: a nie czasem tak, jak nizej?
eAngle -= M_PI * 2.0;
*/
// hunter-091012: przeniesione z if ActiveDir<>0 (zeby po zejsciu z kierunku dalej spadala
// predkosc wentylatorow)
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;
PH = PH + 1; // wyzsze 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
if ((LIM - PL) < DP)
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);
// McZapkie-130302 - coby nie przekompilowywac:
// 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: ";
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
// powtórzone 256 razy da 1kB na każdy stan przełączników, łącznie będzie 4kB pierwszej tabeli
// 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)
{ // z [Shift] uruchomienie eventu
if (!Global::iPause) // podczas pauzy klawisze nie działają
@@ -584,32 +584,31 @@ void TWorld::OnKeyDown(int cKey)
if( ( Global::iTextMode != GLFW_KEY_F12 ) &&
( Global::iTextMode != GLFW_KEY_F3 ) ) // ograniczamy użycie kamer
{
if ((!Global::pFreeCameraInit[i].x && !Global::pFreeCameraInit[i].y &&
!Global::pFreeCameraInit[i].z))
if ((!Global::FreeCameraInit[i].x)
&& (!Global::FreeCameraInit[i].y)
&& (!Global::FreeCameraInit[i].z))
{ // jeśli kamera jest w punkcie zerowym, zapamiętanie współrzędnych i kątów
Global::pFreeCameraInit[i] = Camera.Pos;
Global::pFreeCameraInitAngle[i].x = Camera.Pitch;
Global::pFreeCameraInitAngle[i].y = Camera.Yaw;
Global::pFreeCameraInitAngle[i].z = Camera.Roll;
Global::FreeCameraInit[i] = Camera.Pos;
Global::FreeCameraInitAngle[i].x = Camera.Pitch;
Global::FreeCameraInitAngle[i].y = Camera.Yaw;
Global::FreeCameraInitAngle[i].z = Camera.Roll;
// logowanie, żeby można było do scenerii przepisać
WriteLog(
"camera " + std::to_string( Global::pFreeCameraInit[i].x ) + " " +
std::to_string(Global::pFreeCameraInit[i].y ) + " " +
std::to_string(Global::pFreeCameraInit[i].z ) + " " +
std::to_string(RadToDeg(Global::pFreeCameraInitAngle[i].x)) +
" " +
std::to_string(RadToDeg(Global::pFreeCameraInitAngle[i].y)) +
" " +
std::to_string(RadToDeg(Global::pFreeCameraInitAngle[i].z)) +
" " + std::to_string(i) + " endcamera");
"camera " + std::to_string( Global::FreeCameraInit[i].x ) + " "
+ std::to_string(Global::FreeCameraInit[i].y ) + " "
+ std::to_string(Global::FreeCameraInit[i].z ) + " "
+ std::to_string(RadToDeg(Global::FreeCameraInitAngle[i].x)) + " "
+ std::to_string(RadToDeg(Global::FreeCameraInitAngle[i].y)) + " "
+ std::to_string(RadToDeg(Global::FreeCameraInitAngle[i].z)) + " "
+ std::to_string(i) + " endcamera");
}
else // również przeskakiwanie
{ // Ra: to z tą kamerą (Camera.Pos i Global::pCameraPosition) jest trochę bez sensu
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
Camera.Init(Global::pFreeCameraInit[i],
Global::pFreeCameraInitAngle[i]); // przestawienie
Camera.Init(Global::FreeCameraInit[i],
Global::FreeCameraInitAngle[i]); // przestawienie
}
}
// 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]
int mask, set = 0; // Ra: [Shift]+[Ctrl]+[T] odpala mi jakąś idiotyczną zmianę
// tapety pulpitu :/
if (Global::shiftState < 0) // z [Shift] zapalanie
if (Global::shiftState) // z [Shift] zapalanie
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
else
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->direction = scenelight.direction;
renderlight->diffuse[ 0 ] = scenelight.color.x;
renderlight->diffuse[ 1 ] = scenelight.color.y;
renderlight->diffuse[ 2 ] = scenelight.color.z;
renderlight->ambient[ 0 ] = scenelight.color.x * scenelight.intensity;
renderlight->ambient[ 1 ] = scenelight.color.y * scenelight.intensity;
renderlight->ambient[ 2 ] = scenelight.color.z * scenelight.intensity;
auto const luminance = Global::fLuminance; // TODO: adjust this based on location, e.g. for tunnels
renderlight->diffuse[ 0 ] = std::max( 0.0, scenelight.color.x - luminance );
renderlight->diffuse[ 1 ] = std::max( 0.0, scenelight.color.y - luminance );
renderlight->diffuse[ 2 ] = std::max( 0.0, scenelight.color.z - luminance );
renderlight->ambient[ 0 ] = std::max( 0.0, scenelight.color.x * scenelight.intensity - luminance);
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 ) );
::glEnable( renderlight->id );