瀏覽代碼

input: remove some dead code and clarify some function names.

legacy
Sam Hocevar 6 年之前
父節點
當前提交
cfd85fb3a7
共有 4 個檔案被更改,包括 39 行新增65 行删除
  1. +6
    -5
      src/input/input_internal.h
  2. +20
    -47
      src/input/sdl-input.cpp
  3. +5
    -5
      src/platform/android/androidapp.cpp
  4. +8
    -8
      src/platform/d3d9/d3d9input.cpp

+ 6
- 5
src/input/input_internal.h 查看文件

@@ -1,8 +1,8 @@
//
// Lol Engine
//
// Copyright © 2010—2015 Benjamin Litzelmann
// © 2017—2018 Sam Hocevar <sam@hocevar.net>
// Copyright © 2017—2019 Sam Hocevar <sam@hocevar.net>
// © 2010—2015 Benjamin Litzelmann
//
// Lol Engine is free software. It comes without any warranty, to
// the extent permitted by applicable law. You can redistribute it
@@ -47,17 +47,18 @@ public:
AddCursor(-1, name);
}

void SetKey(int id, bool state)
/* Internal functions for the platform-specific drivers. */
void internal_set_key(int id, bool state)
{
m_keys[id] = state;
}

void AddText(std::string const &text)
void internal_add_text(std::string const &text)
{
m_text += text;
}

void SetAxis(int id, float value)
void internal_set_axis(int id, float value)
{
m_axis[id].m1 = value;
}


+ 20
- 47
src/input/sdl-input.cpp 查看文件

@@ -39,21 +39,8 @@
namespace lol
{

//-------------------------------------------------------------------------
#define _SC(id, str, name) static const uint16_t SDLOL_##name = id;
#include "input/keys.h"
//-------------------------------------------------------------------------
static bool ScanCodeIsValid(int sc)
{
switch (sc)
{
#define _SC(id, str, name) \
case id: return true;
#include "input/keys.h"
default: return false;
}
return false;
}

//-------------------------------------------------------------------------
/* DEBUG STUFF
@@ -232,13 +219,13 @@ void SdlInputData::Tick(float seconds)
for (int j = 0; j < m_joysticks.count(); j++)
{
for (int i = 0; i < SDL_JoystickNumButtons(m_joysticks[j].m1); i++)
m_joysticks[j].m2->SetKey(i, SDL_JoystickGetButton(m_joysticks[j].m1, i) != 0);
m_joysticks[j].m2->internal_set_key(i, SDL_JoystickGetButton(m_joysticks[j].m1, i) != 0);
for (int i = 0; i < SDL_JoystickNumAxes(m_joysticks[j].m1); i++)
m_joysticks[j].m2->SetAxis(i, (float)SDL_JoystickGetAxis(m_joysticks[j].m1, i) / 32768.f);
m_joysticks[j].m2->internal_set_axis(i, (float)SDL_JoystickGetAxis(m_joysticks[j].m1, i) / 32768.f);
}
# endif

m_mouse->SetAxis(4, 0);
m_mouse->internal_set_axis(4, 0);

if (m_keyboard->IsTextInputActive())
SDL_StartTextInput();
@@ -259,7 +246,7 @@ void SdlInputData::Tick(float seconds)
case SDL_KEYUP:
switch (int sc = event.key.keysym.scancode)
{
//Lock management
//Lock management
case SDLOL_CapsLock:
case SDLOL_ScrollLock:
case SDLOL_NumLockClear:
@@ -280,7 +267,7 @@ void SdlInputData::Tick(float seconds)
sc2 = SDLOL_NumLockClearStatus;
break;
}
m_keyboard->SetKey(sc2, !m_keyboard->GetKey(sc2));
m_keyboard->internal_set_key(sc2, !m_keyboard->GetKey(sc2));
/* DEBUG STUFF
msg::debug("Repeat: 0x%02x : %s/%s/%s/%i\n",
(int)m_keyboard, ScanCodeToText(sc2).C(), ScanCodeToName(sc2).C(),
@@ -289,38 +276,24 @@ void SdlInputData::Tick(float seconds)
}
# endif
default:
if (ScanCodeIsValid(sc))
{
// Set key updates the corresponding key
m_keyboard->SetKey(sc, event.type == SDL_KEYDOWN);

/* DEBUG STUFF
msg::debug("Repeat: 0x%02x : %s/%s/%s/%i\n",
(int)m_keyboard, ScanCodeToText(sc).C(), ScanCodeToName(sc).C(),
event.type == SDL_KEYDOWN ? "up" : "down", event.key.repeat);
*/
}
/* DEBUG STUFF
else
msg::error("unknown keypress (sym 0x%02x, scancode %0d)\n",
event.key.keysym.sym, event.key.keysym.scancode);
*/
// Set key updates the corresponding key
m_keyboard->internal_set_key(sc, event.type == SDL_KEYDOWN);
break;
}
break;

//case SDL_TEXTEDITING: //TODO: handle that ?
//case SDL_TEXTEDITING: //TODO: handle that?
case SDL_TEXTINPUT:
m_keyboard->AddText(event.text.text);
m_keyboard->internal_add_text(event.text.text);
break;


case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEBUTTONUP:
//event.button.which
m_mouse->SetKey(event.button.button - 1, event.type == SDL_MOUSEBUTTONDOWN);
m_mouse->internal_set_key(event.button.button - 1, event.type == SDL_MOUSEBUTTONDOWN);
break;
case SDL_MOUSEWHEEL:
m_mouse->SetAxis(4, (float)event.button.y);
m_mouse->internal_set_axis(4, (float)event.button.y);
break;
case SDL_WINDOWEVENT:
{
@@ -328,11 +301,11 @@ void SdlInputData::Tick(float seconds)
{
case SDL_WINDOWEVENT_ENTER:
case SDL_WINDOWEVENT_FOCUS_GAINED:
m_mouse->SetKey(3, true);
m_mouse->internal_set_key(3, true);
break;
case SDL_WINDOWEVENT_LEAVE:
case SDL_WINDOWEVENT_FOCUS_LOST:
m_mouse->SetKey(3, false);
m_mouse->internal_set_key(3, false);
break;
case SDL_WINDOWEVENT_RESIZED:
Video::Resize(ivec2(event.window.data1, event.window.data2));
@@ -343,12 +316,12 @@ void SdlInputData::Tick(float seconds)

# if !SDL_FORCE_POLL_JOYSTICK
case SDL_JOYAXISMOTION:
m_joysticks[event.jaxis.which].m2->SetAxis(event.jaxis.axis, (float)event.jaxis.value / 32768.f);
m_joysticks[event.jaxis.which].m2->internal_set_axis(event.jaxis.axis, (float)event.jaxis.value / 32768.f);
break;

case SDL_JOYBUTTONUP:
case SDL_JOYBUTTONDOWN:
m_joysticks[event.jbutton.which].m2->SetKey(event.jbutton.button, event.jbutton.state);
m_joysticks[event.jbutton.which].m2->internal_set_key(event.jbutton.button, event.jbutton.state);
break;
# endif
}
@@ -375,12 +348,12 @@ void SdlInputData::Tick(float seconds)
vec2 vprevmouse = vec2(m_prevmouse);
m_mouse->SetCursor(0, vmouse / m_app, mouse);
// Note: 100.0f is an arbitrary value that makes it feel about the same than an xbox controller joystick
m_mouse->SetAxis(0, (mouse.x - vprevmouse.x) * MOUSE_SPEED_MOD / max_screen_size);
m_mouse->internal_set_axis(0, (mouse.x - vprevmouse.x) * MOUSE_SPEED_MOD / max_screen_size);
// Y Axis is also negated to match the usual joystick Y axis (negatives values are for the upper direction)
m_mouse->SetAxis(1,-(mouse.y - vprevmouse.y) * MOUSE_SPEED_MOD / max_screen_size);
m_mouse->internal_set_axis(1,-(mouse.y - vprevmouse.y) * MOUSE_SPEED_MOD / max_screen_size);
//Pixel movement
m_mouse->SetAxis(2, (mouse.x - vprevmouse.x));
m_mouse->SetAxis(3,-(mouse.y - vprevmouse.y));
m_mouse->internal_set_axis(2, (mouse.x - vprevmouse.x));
m_mouse->internal_set_axis(3,-(mouse.y - vprevmouse.y));
}

if (m_mousecapture)


+ 5
- 5
src/platform/android/androidapp.cpp 查看文件

@@ -1,7 +1,7 @@
//
// Lol Engine
//
// Copyright © 2010—2017 Sam Hocevar <sam@hocevar.net>
// Copyright © 2010—2019 Sam Hocevar <sam@hocevar.net>
//
// Lol Engine is free software. It comes without any warranty, to
// the extent permitted by applicable law. You can redistribute it
@@ -209,17 +209,17 @@ int32_t lol::AndroidAppData::HandleInput(AInputEvent* event)
pos.y = m_wanted_resolution.y - 1 - pos.y;
m_mouse->SetCursor(0, vec2(pos) / vec2(m_wanted_resolution), pos);
// Note: 100.0f is an arbitrary value that makes it feel about the same than an xbox controller joystick
m_mouse->SetAxis(0, (pos.x - m_prev_pos.x) / max_screen_size * 100.f);
m_mouse->internal_set_axis(0, (pos.x - m_prev_pos.x) / max_screen_size * 100.f);
// Unlike SDL, no need to negate Y axis
m_mouse->SetAxis(1, (pos.y - m_prev_pos.y) / max_screen_size * -100.f);
m_mouse->internal_set_axis(1, (pos.y - m_prev_pos.y) / max_screen_size * -100.f);
m_prev_pos = pos;
switch (AKeyEvent_getAction(event) & AMOTION_EVENT_ACTION_MASK)
{
case AMOTION_EVENT_ACTION_DOWN:
m_mouse->SetKey(0, true);
m_mouse->internal_set_key(0, true);
break;
case AMOTION_EVENT_ACTION_UP:
m_mouse->SetKey(0, false);
m_mouse->internal_set_key(0, false);
break;
}
return 1;


+ 8
- 8
src/platform/d3d9/d3d9input.cpp 查看文件

@@ -1,7 +1,7 @@
//
// Lol Engine
//
// Copyright © 2010—2016 Sam Hocevar <sam@hocevar.net>
// Copyright © 2010—2019 Sam Hocevar <sam@hocevar.net>
//
// Lol Engine is free software. It comes without any warranty, to
// the extent permitted by applicable law. You can redistribute it
@@ -110,12 +110,12 @@ void D3d9Input::tick_game(float seconds)
if (XInputGetState(m_data->m_joysticks[i].m1, &state) != ERROR_SUCCESS)
continue;

m_data->m_joysticks[i].m2->SetAxis(0, (float)state.Gamepad.sThumbLX / 32768.f);
m_data->m_joysticks[i].m2->SetAxis(1, -(float)state.Gamepad.sThumbLY / 32768.f);
m_data->m_joysticks[i].m2->SetAxis(2, (float)state.Gamepad.sThumbRX / 32768.f);
m_data->m_joysticks[i].m2->SetAxis(3, -(float)state.Gamepad.sThumbRY / 32768.f);
m_data->m_joysticks[i].m2->SetAxis(4, (float)state.Gamepad.bLeftTrigger / 32768.f);
m_data->m_joysticks[i].m2->SetAxis(5, (float)state.Gamepad.bRightTrigger / 32768.f);
m_data->m_joysticks[i].m2->internal_set_axis(0, (float)state.Gamepad.sThumbLX / 32768.f);
m_data->m_joysticks[i].m2->internal_set_axis(1, -(float)state.Gamepad.sThumbLY / 32768.f);
m_data->m_joysticks[i].m2->internal_set_axis(2, (float)state.Gamepad.sThumbRX / 32768.f);
m_data->m_joysticks[i].m2->internal_set_axis(3, -(float)state.Gamepad.sThumbRY / 32768.f);
m_data->m_joysticks[i].m2->internal_set_axis(4, (float)state.Gamepad.bLeftTrigger / 32768.f);
m_data->m_joysticks[i].m2->internal_set_axis(5, (float)state.Gamepad.bRightTrigger / 32768.f);

for (int b = 0; b < 16; b++)
{
@@ -125,7 +125,7 @@ void D3d9Input::tick_game(float seconds)

int key_index = (1 << b) > XINPUT_GAMEPAD_RIGHT_SHOULDER ? b - 2 : b;

m_data->m_joysticks[i].m2->SetKey(key_index, ((uint16_t)(state.Gamepad.wButtons) >> b) & 1);
m_data->m_joysticks[i].m2->internal_set_key(key_index, ((uint16_t)(state.Gamepad.wButtons) >> b) & 1);
}
}
#endif


Loading…
取消
儲存