Browse Source

Small refactor controller tweak

undefined
Benjamin ‘Touky’ Huet Sam Hocevar <sam@hocevar.net> 10 years ago
parent
commit
3e9e6178ae
6 changed files with 21 additions and 21 deletions
  1. +2
    -2
      doc/samples/btphystest.cpp
  2. +4
    -4
      doc/samples/meshviewer.cpp
  3. +1
    -1
      doc/tutorial/07_input.cpp
  4. +6
    -6
      doc/tutorial/12_voronoi.cpp
  5. +4
    -4
      src/input/controller.cpp
  6. +4
    -4
      src/input/controller.h

+ 2
- 2
doc/samples/btphystest.cpp View File

@@ -317,7 +317,7 @@ void BtPhysTest::TickGame(float seconds)
}


if (m_controller->WasKeyReleased(KEY_QUIT))
if (m_controller->WasKeyReleasedThisFrame(KEY_QUIT))
Ticker::Shutdown();

m_loop_value += seconds;
@@ -508,7 +508,7 @@ void BtPhysTest::TickGame(float seconds)
- (m_controller->IsKeyPressed(KEY_MOVE_DOWN) ? 1.f : 0.f);
vec3 CharMove = movement * seconds * vec3(4.f, 10.f, 4.f);

if (m_controller->WasKeyReleased(KEY_MOVE_JUMP))
if (m_controller->WasKeyReleasedThisFrame(KEY_MOVE_JUMP))
Character->Jump();
Character->SetMovementForFrame(CharMove);



+ 4
- 4
doc/samples/meshviewer.cpp View File

@@ -247,11 +247,11 @@ public:
}

#if NO_NACL_EM_INPUT
bool KeyReleased(MVKeyboardList index) { return (HAS_KBOARD && m_controller->WasKeyReleased(index)); }
bool KeyPressed(MVKeyboardList index) { return (HAS_KBOARD && m_controller->WasKeyPressed(index)); }
bool KeyReleased(MVKeyboardList index) { return (HAS_KBOARD && m_controller->WasKeyReleasedThisFrame(index)); }
bool KeyPressed(MVKeyboardList index) { return (HAS_KBOARD && m_controller->WasKeyPressedThisFrame(index)); }
bool KeyDown(MVKeyboardList index) { return (HAS_KBOARD && m_controller->IsKeyPressed(index)); }
bool KeyReleased(MVMouseKeyList index) { return (HAS_MOUSE && m_controller->WasKeyReleased(index)); }
bool KeyPressed(MVMouseKeyList index) { return (HAS_MOUSE && m_controller->WasKeyPressed(index)); }
bool KeyReleased(MVMouseKeyList index) { return (HAS_MOUSE && m_controller->WasKeyReleasedThisFrame(index)); }
bool KeyPressed(MVMouseKeyList index) { return (HAS_MOUSE && m_controller->WasKeyPressedThisFrame(index)); }
bool KeyDown(MVMouseKeyList index) { return (HAS_MOUSE && m_controller->IsKeyPressed(index)); }
float AxisValue(MVMouseAxisList index) { return (HAS_MOUSE) ? (m_controller->GetAxisValue(index)) : (0.f); }
#endif //NO_NACL_EM_INPUT


+ 1
- 1
doc/tutorial/07_input.cpp View File

@@ -107,7 +107,7 @@ public:
/* Handle keyboard */
if (m_keyboard)
{
if (m_controller->WasKeyPressed(KEY_MANUAL_ROTATION))
if (m_controller->WasKeyPressedThisFrame(KEY_MANUAL_ROTATION))
m_autorot = !m_autorot;
}



+ 6
- 6
doc/tutorial/12_voronoi.cpp View File

@@ -78,7 +78,7 @@ public:

{
//Shutdown logic
if (m_controller->WasKeyReleased(KEY_ESC))
if (m_controller->WasKeyReleasedThisFrame(KEY_ESC))
Ticker::Shutdown();
}

@@ -169,16 +169,16 @@ public:

{
//Shutdown logic
if (m_controller->WasKeyReleased(KEY_POP))
if (m_controller->WasKeyReleasedThisFrame(KEY_POP))
voronoi_points.Pop();
else if (m_controller->WasKeyReleased(KEY_PUSH))
else if (m_controller->WasKeyReleasedThisFrame(KEY_PUSH))
voronoi_points.Push(vec3(rand<float>(512.f), rand<float>(512.f), .0f),
vec2(64.f + rand<float>(64.f), 64.f + rand<float>(64.f)));
else if (m_controller->WasKeyReleased(KEY_F1))
else if (m_controller->WasKeyReleasedThisFrame(KEY_F1))
m_cur_fbo = SrcVoronoiFbo;
else if (m_controller->WasKeyReleased(KEY_F2))
else if (m_controller->WasKeyReleasedThisFrame(KEY_F2))
m_cur_fbo = VoronoiFbo;
else if (m_controller->WasKeyReleased(KEY_F3))
else if (m_controller->WasKeyReleasedThisFrame(KEY_F3))
{
voronoi_points.Empty();
if (mode == 0)


+ 4
- 4
src/input/controller.cpp View File

@@ -320,13 +320,13 @@ bool Controller::IsKeyReleased(int index) const
{
return GetKey(index).IsReleased();
}
bool Controller::WasKeyPressed(int index) const
bool Controller::WasKeyPressedThisFrame(int index) const
{
return GetKey(index).WasKeyPressed();
return GetKey(index).WasPressedThisFrame();
}
bool Controller::WasKeyReleased(int index) const
bool Controller::WasKeyReleasedThisFrame(int index) const
{
return GetKey(index).WasKeyReleased();
return GetKey(index).WasReleasedThisFrame();
}

//Axis methods: should not go directly to binding -----------------------------


+ 4
- 4
src/input/controller.h View File

@@ -30,9 +30,9 @@ protected:
/** Indicates wheither the key is currently up */
bool IsReleased() const { return !m_current; }
/** Indicates wheither the key has just been pressed */
bool WasKeyPressed() const { return m_current && !m_previous; }
bool WasPressedThisFrame() const { return m_current && !m_previous; }
/** Indicates wheither the key has just been released */
bool WasKeyReleased() const { return !m_current && m_previous; }
bool WasReleasedThisFrame() const { return !m_current && m_previous; }

public:
//Binding methods ---------------------------------------------------------
@@ -360,9 +360,9 @@ public:
/** Indicates wheither the key is currently up */
bool IsKeyReleased(int index) const;
/** Indicates wheither the key has just been pressed */
bool WasKeyPressed(int index) const;
bool WasKeyPressedThisFrame(int index) const;
/** Indicates wheither the key has just been released */
bool WasKeyReleased(int index) const;
bool WasKeyReleasedThisFrame(int index) const;

/** Axis methods: should not go directly to binding */
/** Gets the current absolute value of this axis */


Loading…
Cancel
Save