Pārlūkot izejas kodu

input: renamed xinput keys to something more human readable (such as A or DPadLeft) and inverted mouse Y axis to match joystick axis (negatives being up)

core: calling InitGame() at the first tick of an entity. InitDraw is still uncalled yet
fixed mrpigeon and orbital accordingly
undefined
Benlitz Sam Hocevar <sam@hocevar.net> pirms 11 gadiem
vecāks
revīzija
c1da4619f7
5 mainītis faili ar 39 papildinājumiem un 14 dzēšanām
  1. +2
    -2
      demos/tutorial/07_input.cpp
  2. +3
    -3
      src/input/input.cpp
  3. +29
    -8
      src/platform/d3d9/d3d9input.cpp
  4. +2
    -1
      src/platform/sdl/sdlinput.cpp
  5. +3
    -0
      src/ticker.cpp

+ 2
- 2
demos/tutorial/07_input.cpp Parādīt failu

@@ -34,7 +34,7 @@ public:
m_mouse = InputDevice::Get("Mouse");
if (m_mouse)
{
m_controller->GetKey(KEY_DRAG_MESH).Bind("Mouse", "ButtonLeft");
m_controller->GetKey(KEY_DRAG_MESH).Bind("Mouse", "Left");
m_controller->GetAxis(AXIS_DRAG_PITCH).Bind("Mouse", "Y");
m_controller->GetAxis(AXIS_DRAG_YAW).Bind("Mouse", "X");
}
@@ -99,7 +99,7 @@ public:
if (m_joystick)
{
if (lol::abs(m_controller->GetAxis(AXIS_PITCH).GetValue()) > 0.2f)
m_pitch_angle -= m_controller->GetAxis(AXIS_PITCH).GetValue() * seconds * 100;
m_pitch_angle += m_controller->GetAxis(AXIS_PITCH).GetValue() * seconds * 100;
if (lol::abs(m_controller->GetAxis(AXIS_YAW).GetValue()) > 0.2f)
m_yaw_angle += m_controller->GetAxis(AXIS_YAW).GetValue() * seconds * 100;
}


+ 3
- 3
src/input/input.cpp Parādīt failu

@@ -64,9 +64,9 @@ InputDeviceInternal* InputDeviceInternal::CreateStandardKeyboard()
InputDeviceInternal* InputDeviceInternal::CreateStandardMouse()
{
InputDeviceInternal* mouse = new InputDeviceInternal("Mouse");
mouse->AddKey("ButtonLeft");
mouse->AddKey("ButtonMiddle");
mouse->AddKey("ButtonRight");
mouse->AddKey("Left");
mouse->AddKey("Middle");
mouse->AddKey("Right");

mouse->AddAxis("X");
mouse->AddAxis("Y");


+ 29
- 8
src/platform/d3d9/d3d9input.cpp Parādīt failu

@@ -56,8 +56,21 @@ D3d9Input::D3d9Input()
InputDeviceInternal* stick = new InputDeviceInternal(String::Printf("Joystick%d", i+1).C());
for (int j = 0; j < 4; ++j)
stick->AddAxis(String::Printf("Axis%d", j+1).C());
for (int j = 0; j < 16; ++j)
stick->AddKey(String::Printf("Button%d", j+1).C());

stick->AddKey("DPadUp");
stick->AddKey("DPadDown");
stick->AddKey("DPadLeft");
stick->AddKey("DPadRight");
stick->AddKey("Start");
stick->AddKey("Back");
stick->AddKey("LeftThumb");
stick->AddKey("RightThumb");
stick->AddKey("LeftShoulder");
stick->AddKey("RightShoulder");
stick->AddKey("A");
stick->AddKey("B");
stick->AddKey("X");
stick->AddKey("Y");

m_data->m_joysticks.Push(i, stick);
}
@@ -82,11 +95,6 @@ D3d9Input::~D3d9Input()
void D3d9Input::TickGame(float seconds)
{
Entity::TickGame(seconds);
}

void D3d9Input::TickDraw(float seconds)
{
Entity::TickDraw(seconds);

#if defined USE_XINPUT
for (int i = 0; i < m_data->m_joysticks.Count(); i++)
@@ -101,10 +109,23 @@ void D3d9Input::TickDraw(float seconds)
m_data->m_joysticks[i].m2->SetAxis(3, -(float)state.Gamepad.sThumbRY / 32768.f);

for (int b = 0; b < 16; b++)
m_data->m_joysticks[i].m2->SetKey(b, ((uint16_t)(state.Gamepad.wButtons) >> b) & 1);
{
// Reserved values
if ((1 << b) > XINPUT_GAMEPAD_RIGHT_SHOULDER && (1 << b) < XINPUT_GAMEPAD_A)
continue;

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);
}
}
#endif
}

void D3d9Input::TickDraw(float seconds)
{
Entity::TickDraw(seconds);
}

} /* namespace lol */


+ 2
- 1
src/platform/sdl/sdlinput.cpp Parādīt failu

@@ -225,7 +225,8 @@ void SdlInputData::Tick(float seconds)
m_mouse->SetCursor(0, vec2((float)(mouse.x) / m_app_w, (float)(mouse.y) / m_app_h), mouse);
// Note: 100.0f is an arbitrary value that makes it feel about the same than an xbox controller joystick
m_mouse->SetAxis(0, (float)(mouse.x - m_prevmouse.x) * 100.0f / m_screen_w);
m_mouse->SetAxis(1, (float)(mouse.y - m_prevmouse.y) * 100.0f / m_screen_h);
// Y Axis is also negated to match the usual joystick Y axis (negatives values are for the upper direction)
m_mouse->SetAxis(1, -(float)(mouse.y - m_prevmouse.y) * 100.0f / m_screen_h);
}

if (m_mousecapture)


+ 3
- 0
src/ticker.cpp Parādīt failu

@@ -337,6 +337,9 @@ void TickerData::GameThreadTick()
data->m_todolist.Remove(-1);
data->m_list[e->m_gamegroup].Push(e);
data->m_list[e->m_drawgroup].Push(e);

// Initialize the entity
e->InitGame();
}

/* Tick objects for the game loop */


Notiek ielāde…
Atcelt
Saglabāt