16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-22 10:29:19 +02:00

key logging

This commit is contained in:
tmj-fstate
2017-03-31 00:56:33 +02:00
parent f2cd420bbb
commit 96b01c6205
5 changed files with 57 additions and 15 deletions

View File

@@ -59,8 +59,8 @@ simulation_time::init() {
::memcpy( m_monthdaycounts, monthdaycounts, sizeof( monthdaycounts ) ); ::memcpy( m_monthdaycounts, monthdaycounts, sizeof( monthdaycounts ) );
// cache requested elements, if any // cache requested elements, if any
auto const requestedhour = m_time.wHour; WORD const requestedhour = m_time.wHour;
auto const requestedminute = m_time.wMinute; WORD const requestedminute = m_time.wMinute;
::GetLocalTime( &m_time ); ::GetLocalTime( &m_time );
@@ -69,10 +69,10 @@ simulation_time::init() {
daymonth( m_time.wDay, m_time.wMonth, m_time.wYear, static_cast<WORD>( Global::fMoveLight ) ); daymonth( m_time.wDay, m_time.wMonth, m_time.wYear, static_cast<WORD>( Global::fMoveLight ) );
} }
if( requestedhour != -1 ) { m_time.wHour = clamp( requestedhour, static_cast<WORD>( 0 ), static_cast<WORD>( 23 ) ); } if( requestedhour != (WORD)-1 ) { m_time.wHour = clamp( requestedhour, static_cast<WORD>( 0 ), static_cast<WORD>( 23 ) ); }
if( requestedminute != -1 ) { m_time.wMinute = clamp( requestedminute, static_cast<WORD>( 0 ), static_cast<WORD>( 59 ) ); } if( requestedminute != (WORD)-1 ) { m_time.wMinute = clamp( requestedminute, static_cast<WORD>( 0 ), static_cast<WORD>( 59 ) ); }
// if the time is taken from the local clock leave the seconds intact, otherwise set them to zero // if the time is taken from the local clock leave the seconds intact, otherwise set them to zero
if( ( requestedhour != -1 ) || ( requestedminute != -1 ) ) { if( ( requestedhour != (WORD)-1 ) || ( requestedminute != (WORD)-1 ) ) {
m_time.wSecond = 0; m_time.wSecond = 0;
} }
@@ -402,12 +402,54 @@ bool TWorld::Init( GLFWwindow *Window ) {
}; };
void TWorld::OnKeyDown(int cKey) void TWorld::OnKeyDown(int cKey)
{ //(cKey) to kod klawisza, cyfrowe i literowe się zgadzają {
// Ra 2014-09: tu by można dodać tabelę konwersji: 256 wirtualnych kodów w kontekście dwóch // dump keypress info in the log
// przełączników [Shift] i [Ctrl] if( !Global::iPause ) {
// na każdy kod wirtualny niech przypadają 4 bajty: 2 dla naciśnięcia i 2 dla zwolnienia // podczas pauzy klawisze nie działają
// powtórzone 256 razy da 1kB na każdy stan przełączników, łącznie będzie 4kB pierwszej tabeli std::string keyinfo;
// przekodowania auto keyname = glfwGetKeyName( cKey, 0 );
if( keyname != nullptr ) {
keyinfo += std::string( keyname );
}
else {
switch( cKey ) {
case GLFW_KEY_SPACE: { keyinfo += "Space"; break; }
case GLFW_KEY_ENTER: { keyinfo += "Enter"; break; }
case GLFW_KEY_ESCAPE: { keyinfo += "Esc"; break; }
case GLFW_KEY_TAB: { keyinfo += "Tab"; break; }
case GLFW_KEY_INSERT: { keyinfo += "Insert"; break; }
case GLFW_KEY_DELETE: { keyinfo += "Delete"; break; }
case GLFW_KEY_HOME: { keyinfo += "Home"; break; }
case GLFW_KEY_END: { keyinfo += "End"; break; }
case GLFW_KEY_F1: { keyinfo += "F1"; break; }
case GLFW_KEY_F2: { keyinfo += "F2"; break; }
case GLFW_KEY_F3: { keyinfo += "F3"; break; }
case GLFW_KEY_F4: { keyinfo += "F4"; break; }
case GLFW_KEY_F5: { keyinfo += "F5"; break; }
case GLFW_KEY_F6: { keyinfo += "F6"; break; }
case GLFW_KEY_F7: { keyinfo += "F7"; break; }
case GLFW_KEY_F8: { keyinfo += "F8"; break; }
case GLFW_KEY_F9: { keyinfo += "F9"; break; }
case GLFW_KEY_F10: { keyinfo += "F10"; break; }
case GLFW_KEY_F11: { keyinfo += "F11"; break; }
case GLFW_KEY_F12: { keyinfo += "F12"; break; }
}
}
if( keyinfo.empty() == false ) {
std::string keymodifiers;
if( Global::shiftState )
keymodifiers += "[Shift]+";
if( Global::ctrlState )
keymodifiers += "[Ctrl]+";
WriteLog( "Key pressed: " + keymodifiers + "[" + keyinfo + "]" );
}
}
// actual key processing
// 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

View File

@@ -24,7 +24,7 @@ http://mozilla.org/MPL/2.0/.
class simulation_time { class simulation_time {
public: public:
simulation_time() { m_time.wHour = -1; m_time.wMinute = -1; } simulation_time() { m_time.wHour = 10; m_time.wMinute = 30; }
void void
init(); init();
void void

View File

@@ -36,7 +36,7 @@ void
cMoon::update() { cMoon::update() {
move(); move();
Math3D::vector3 position( 0.0f, 0.0f, -2000.0f ); Math3D::vector3 position( 0.0f, 0.0f, -2000.0f * Global::fDistanceFactor );
position.RotateX( (float)( m_body.elevref * ( M_PI / 180.0 ) ) ); position.RotateX( (float)( m_body.elevref * ( M_PI / 180.0 ) ) );
position.RotateY( (float)( -m_body.hrang * ( M_PI / 180.0 ) ) ); position.RotateY( (float)( -m_body.hrang * ( M_PI / 180.0 ) ) );

View File

@@ -234,7 +234,7 @@ opengl_renderer::Render( world_environment *Environment ) {
::glLoadIdentity(); // macierz jedynkowa ::glLoadIdentity(); // macierz jedynkowa
::glTranslatef( moonposition.x, moonposition.y, moonposition.z ); ::glTranslatef( moonposition.x, moonposition.y, moonposition.z );
float const size = 0.025f; // TODO: expose distance/scale factor from the moon object float const size = 0.02f; // TODO: expose distance/scale factor from the moon object
// choose the moon appearance variant, based on current moon phase // choose the moon appearance variant, based on current moon phase
// NOTE: implementation specific, 8 variants are laid out in 3x3 arrangement // NOTE: implementation specific, 8 variants are laid out in 3x3 arrangement
// from new moon onwards, top left to right bottom (last spot is left for future use, if any) // from new moon onwards, top left to right bottom (last spot is left for future use, if any)

View File

@@ -33,7 +33,7 @@ void
cSun::update() { cSun::update() {
move(); move();
Math3D::vector3 position( 0.0f, 0.0f, -2000.0f ); Math3D::vector3 position( 0.0f, 0.0f, -2000.0f * Global::fDistanceFactor );
position.RotateX( (float)( m_body.elevref * ( M_PI / 180.0 ) ) ); position.RotateX( (float)( m_body.elevref * ( M_PI / 180.0 ) ) );
position.RotateY( (float)( -m_body.hrang * ( M_PI / 180.0 ) ) ); position.RotateY( (float)( -m_body.hrang * ( M_PI / 180.0 ) ) );