Skip to content

Commit

Permalink
fixed bad key codes handling
Browse files Browse the repository at this point in the history
  • Loading branch information
les-sosna committed Jan 12, 2010
1 parent e867233 commit 9fbad1a
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 104 deletions.
1 change: 1 addition & 0 deletions game/History.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- ������������� ��������� ����� ������ � �������������� �������������.
- ���������� ������ ������� msgbox.
- ���������� ��������� ���������� �������.
- ���������� ��������� ������������ �������� ����������.

* 1.51.2 beta
- ���������� ����������� ����� ������ ������ ������.
Expand Down
156 changes: 78 additions & 78 deletions game/src/tank/DefaultCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,83 +11,83 @@ DefaultCamera::DefaultCamera()
{
_dwTimeX = _dwTimeY = GetTickCount();
}

void DefaultCamera::HandleMovement(float worldWidth, float worldHeight,
float screenWidth, float screenHeight)
{
static char lastIn = 0, LastOut = 0;
static float levels[] = { 0.0625f, 0.125f, 0.25f, 0.5f, 1.0f, 1.5f, 2.0f };
static int level = 4;

if( !lastIn && g_env.envInputs.keys[DIK_PGUP] )
level = __min(level+1, sizeof(levels) / sizeof(float) - 1);
lastIn = g_env.envInputs.keys[DIK_PGUP];

if( !LastOut && g_env.envInputs.keys[DIK_PGDN] )
level = __max(level-1, 0);
LastOut = g_env.envInputs.keys[DIK_PGDN];

_zoom = levels[level];

bool bMove = false;
DWORD dwCurTime = GetTickCount();
DWORD dt = DWORD(_dt);

if( 0 == g_env.envInputs.mouse_x || g_env.envInputs.keys[DIK_LEFTARROW] )
{
bMove = true;
while( dwCurTime - _dwTimeX > dt )
{
_pos.x -= CELL_SIZE;
_dwTimeX += dt;
}
}
else
if( screenWidth - 1 == g_env.envInputs.mouse_x || g_env.envInputs.keys[DIK_RIGHTARROW] )
{
bMove = true;
while( dwCurTime - _dwTimeX > dt )
{
_pos.x += CELL_SIZE;
_dwTimeX += dt;
}
}
else
_dwTimeX = GetTickCount();
//---------------------------------------
if( 0 == g_env.envInputs.mouse_y || g_env.envInputs.keys[DIK_UPARROW] )
{
bMove = true;
while( dwCurTime - _dwTimeY > dt )
{
_pos.y -= CELL_SIZE;
_dwTimeY += dt;
}
}
else
if( screenHeight - 1 == g_env.envInputs.mouse_y || g_env.envInputs.keys[DIK_DOWNARROW] )
{
bMove = true;
while( dwCurTime - _dwTimeY > dt )
{
_pos.y += CELL_SIZE;
_dwTimeY += dt;
}
}
else
_dwTimeY = GetTickCount();
//---------------------------------------
if( bMove )
_dt = __max(10.0f, 1.0f / (1.0f / _dt + 0.001f));
else
_dt = 50.0f;
//------------------------------------------------------
int dx = __max(0, (int) (screenWidth / _zoom - worldWidth) / 2);
int dy = __max(0, (int) (screenHeight / _zoom - worldHeight) / 2);
_pos.x = (float) __max(int(_pos.x), dx);
_pos.x = (float) __min(int(_pos.x), int(worldWidth - screenWidth / _zoom) + dx);
_pos.y = (float) __max(int(_pos.y), dy);
_pos.y = (float) __min(int(_pos.y), int(worldHeight - screenHeight / _zoom) + dy);
}

void DefaultCamera::HandleMovement(float worldWidth, float worldHeight,
float screenWidth, float screenHeight)
{
static char lastIn = 0, LastOut = 0;
static float levels[] = { 0.0625f, 0.125f, 0.25f, 0.5f, 1.0f, 1.5f, 2.0f };
static int level = 4;

if( !lastIn && g_env.envInputs.IsKeyPressed(DIK_PGUP) )
level = __min(level+1, sizeof(levels) / sizeof(float) - 1);
lastIn = g_env.envInputs.IsKeyPressed(DIK_PGUP);

if( !LastOut && g_env.envInputs.IsKeyPressed(DIK_PGDN) )
level = __max(level-1, 0);
LastOut = g_env.envInputs.IsKeyPressed(DIK_PGDN);

_zoom = levels[level];

bool bMove = false;
DWORD dwCurTime = GetTickCount();
DWORD dt = DWORD(_dt);

if( 0 == g_env.envInputs.mouse_x || g_env.envInputs.IsKeyPressed(DIK_LEFTARROW) )
{
bMove = true;
while( dwCurTime - _dwTimeX > dt )
{
_pos.x -= CELL_SIZE;
_dwTimeX += dt;
}
}
else
if( screenWidth - 1 == g_env.envInputs.mouse_x || g_env.envInputs.IsKeyPressed(DIK_RIGHTARROW) )
{
bMove = true;
while( dwCurTime - _dwTimeX > dt )
{
_pos.x += CELL_SIZE;
_dwTimeX += dt;
}
}
else
_dwTimeX = GetTickCount();
//---------------------------------------
if( 0 == g_env.envInputs.mouse_y || g_env.envInputs.IsKeyPressed(DIK_UPARROW) )
{
bMove = true;
while( dwCurTime - _dwTimeY > dt )
{
_pos.y -= CELL_SIZE;
_dwTimeY += dt;
}
}
else
if( screenHeight - 1 == g_env.envInputs.mouse_y || g_env.envInputs.IsKeyPressed(DIK_DOWNARROW) )
{
bMove = true;
while( dwCurTime - _dwTimeY > dt )
{
_pos.y += CELL_SIZE;
_dwTimeY += dt;
}
}
else
_dwTimeY = GetTickCount();
//---------------------------------------
if( bMove )
_dt = __max(10.0f, 1.0f / (1.0f / _dt + 0.001f));
else
_dt = 50.0f;
//------------------------------------------------------
int dx = __max(0, (int) (screenWidth / _zoom - worldWidth) / 2);
int dy = __max(0, (int) (screenHeight / _zoom - worldHeight) / 2);
_pos.x = (float) __max(int(_pos.x), dx);
_pos.x = (float) __min(int(_pos.x), int(worldWidth - screenWidth / _zoom) + dx);
_pos.y = (float) __max(int(_pos.y), dy);
_pos.y = (float) __min(int(_pos.y), int(worldHeight - screenHeight / _zoom) + dy);
}

// end of file
6 changes: 3 additions & 3 deletions game/src/tank/InputManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ InputManager::InputManager(HWND hWnd)
{
TRACE("init direct input");

ZeroMemory(g_env.envInputs.keys, sizeof(g_env.envInputs.keys));
ZeroMemory(g_env.envInputs._keys, sizeof(g_env.envInputs._keys));

DWORD dwPriority = DISCL_NONEXCLUSIVE | DISCL_FOREGROUND;

Expand Down Expand Up @@ -62,10 +62,10 @@ HRESULT InputManager::InquireInputDevices()
return S_OK;
}

ZeroMemory(g_env.envInputs.keys, sizeof(g_env.envInputs.keys));
ZeroMemory(g_env.envInputs._keys, sizeof(g_env.envInputs._keys));
for( int i = 0; i < sizeof(data); ++i )
{
g_env.envInputs.keys[i] = (data[i] & 0x80) != 0;
g_env.envInputs._keys[i] = (data[i] & 0x80) != 0;
}


Expand Down
4 changes: 2 additions & 2 deletions game/src/tank/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ static void RenderFrame(bool thumbnail)

// check if print screen key is pressed
static char _oldRQ = 0;
if( g_env.envInputs.keys[DIK_SYSRQ] && !_oldRQ )
if( g_env.envInputs.IsKeyPressed(DIK_SYSRQ) && !_oldRQ )
OnPrintScreen();
_oldRQ = g_env.envInputs.keys[DIK_SYSRQ];
_oldRQ = g_env.envInputs.IsKeyPressed(DIK_SYSRQ);
}

///////////////////////////////////////////////////////////////////////////////
Expand Down
34 changes: 17 additions & 17 deletions game/src/tank/gc/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ void GC_PlayerLocal::ReadControllerStateAndStepPredicted(VehicleState &vs, float
//
// lights
//
bool tmp = g_env.envInputs.keys[_keyLight];
bool tmp = g_env.envInputs.IsKeyPressed(_keyLight);
if( tmp && !_lastLightKeyState && g_conf.sv_nightmode.Get() )
{
PLAY(SND_LightSwitch, GetVehicle()->GetPos());
Expand All @@ -618,14 +618,14 @@ void GC_PlayerLocal::ReadControllerStateAndStepPredicted(VehicleState &vs, float
//
// pickup
//
vs._bState_AllowDrop = g_env.envInputs.keys[_keyPickup]
|| ( g_env.envInputs.keys[_keyForward] && g_env.envInputs.keys[_keyBack] )
|| ( g_env.envInputs.keys[_keyLeft] && g_env.envInputs.keys[_keyRight] );
vs._bState_AllowDrop = g_env.envInputs.IsKeyPressed(_keyPickup)
|| ( g_env.envInputs.IsKeyPressed(_keyForward) && g_env.envInputs.IsKeyPressed(_keyBack) )
|| ( g_env.envInputs.IsKeyPressed(_keyLeft) && g_env.envInputs.IsKeyPressed(_keyRight) );

//
// fire
//
vs._bState_Fire = g_env.envInputs.keys[_keyFire];
vs._bState_Fire = g_env.envInputs.IsKeyPressed(_keyFire);


//
Expand All @@ -634,10 +634,10 @@ void GC_PlayerLocal::ReadControllerStateAndStepPredicted(VehicleState &vs, float
if( _arcadeStyle )
{
vec2d tmp(0, 0);
if( g_env.envInputs.keys[_keyForward] ) tmp.y -= 1;
if( g_env.envInputs.keys[_keyBack] ) tmp.y += 1;
if( g_env.envInputs.keys[_keyLeft] ) tmp.x -= 1;
if( g_env.envInputs.keys[_keyRight] ) tmp.x += 1;
if( g_env.envInputs.IsKeyPressed(_keyForward) ) tmp.y -= 1;
if( g_env.envInputs.IsKeyPressed(_keyBack) ) tmp.y += 1;
if( g_env.envInputs.IsKeyPressed(_keyLeft) ) tmp.x -= 1;
if( g_env.envInputs.IsKeyPressed(_keyRight) ) tmp.x += 1;
tmp.Normalize();

bool move = tmp.x || tmp.y;
Expand All @@ -654,10 +654,10 @@ void GC_PlayerLocal::ReadControllerStateAndStepPredicted(VehicleState &vs, float
}
else
{
vs._bState_MoveForward = g_env.envInputs.keys[_keyForward];
vs._bState_MoveBack = g_env.envInputs.keys[_keyBack ];
vs._bState_RotateLeft = g_env.envInputs.keys[_keyLeft ];
vs._bState_RotateRight = g_env.envInputs.keys[_keyRight ];
vs._bState_MoveForward = g_env.envInputs.IsKeyPressed(_keyForward);
vs._bState_MoveBack = g_env.envInputs.IsKeyPressed(_keyBack );
vs._bState_RotateLeft = g_env.envInputs.IsKeyPressed(_keyLeft );
vs._bState_RotateRight = g_env.envInputs.IsKeyPressed(_keyRight );
}

if( _moveToMouse )
Expand Down Expand Up @@ -709,10 +709,10 @@ void GC_PlayerLocal::ReadControllerStateAndStepPredicted(VehicleState &vs, float
}
else
{
vs._bState_TowerLeft = g_env.envInputs.keys[_keyTowerLeft];
vs._bState_TowerRight = g_env.envInputs.keys[_keyTowerRight];
vs._bState_TowerCenter = g_env.envInputs.keys[_keyTowerCenter]
|| g_env.envInputs.keys[_keyTowerLeft] && g_env.envInputs.keys[_keyTowerRight];
vs._bState_TowerLeft = g_env.envInputs.IsKeyPressed(_keyTowerLeft);
vs._bState_TowerRight = g_env.envInputs.IsKeyPressed(_keyTowerRight);
vs._bState_TowerCenter = g_env.envInputs.IsKeyPressed(_keyTowerCenter)
|| g_env.envInputs.IsKeyPressed(_keyTowerLeft) && g_env.envInputs.IsKeyPressed(_keyTowerRight);
if( vs._bState_TowerCenter )
{
vs._bState_TowerLeft = false;
Expand Down
10 changes: 9 additions & 1 deletion game/src/tank/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,21 @@ extern SafePtr<FS::FileSystem> g_fs;

struct InputState
{
bool keys[300];
bool _keys[300];
int mouse_x;
int mouse_y;
int mouse_wheel;
bool bLButtonState;
bool bRButtonState;
bool bMButtonState;
bool IsKeyPressed(int code)
{
if( code > 0 && code < sizeof(_keys) / sizeof(_keys[0]) )
{
return _keys[code];
}
return false;
}
};


Expand Down
2 changes: 1 addition & 1 deletion game/src/tank/ui/gui_scoretable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void ScoreTable::DrawChildren(const DrawingContext *dc, float sx, float sy) cons

void ScoreTable::OnTimeStep(float dt)
{
bool tab = g_env.envInputs.keys[DIK_TAB];
bool tab = g_env.envInputs.IsKeyPressed(DIK_TAB);
SetVisible(!g_level->IsEmpty() && !g_level->GetEditorMode() && (tab || g_level->_limitHit));
}

Expand Down
4 changes: 2 additions & 2 deletions game/src/tank/ui/gui_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,9 @@ void ControlProfileDlg::OnTimeStep(float dt)
_time += dt;
_actions->GetData()->SetItemText(_activeIndex, 1, fmodf(_time, 0.6f) > 0.3f ? "" : "...");

for( int k = 0; k < sizeof(g_env.envInputs.keys) / sizeof(g_env.envInputs.keys[0]); ++k )
for( int k = 0; k < sizeof(g_env.envInputs._keys) / sizeof(g_env.envInputs._keys[0]); ++k )
{
if( g_env.envInputs.keys[k] )
if( g_env.envInputs.IsKeyPressed(k) )
{
if( _skipNextKey )
{
Expand Down

0 comments on commit 9fbad1a

Please sign in to comment.