Skip to content

Commit

Permalink
UPBGE: Fix for mouse actuator return value (#907)
Browse files Browse the repository at this point in the history
Now it works perfectly when activating from an always sensor.

Additionally, it introduces a boolean check for initial skipping instead the modifying the oldposition.
  • Loading branch information
lordloki authored and youle31 committed May 26, 2019
1 parent a88fa48 commit 60d29a4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
14 changes: 7 additions & 7 deletions source/gameengine/Ketsji/KX_MouseActuator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ KX_MouseActuator::KX_MouseActuator(SCA_IObject* gameobj, KX_KetsjiEngine* ketsji
m_visible(visible),
m_threshold(threshold),
m_sensitivity(sensitivity),
m_oldPosition(-1.0f, -1.0f),
m_initialSkipping(true),
m_oldPosition(mt::zero2),
m_angle(mt::zero2)
{
for (unsigned short i = 0; i < 2; ++i) {
Expand All @@ -71,14 +72,12 @@ KX_MouseActuator::~KX_MouseActuator()

bool KX_MouseActuator::Update()
{
bool result = false;

bool bNegativeEvent = IsNegativeEvent();
RemoveAllEvents();

if (bNegativeEvent) {
// Reset previous position on negative events.
m_oldPosition = mt::vec2(-1.0f, -1.0f);
// Reset initial skipping check on negative events.
m_initialSkipping = true;
return false;
}

Expand Down Expand Up @@ -121,7 +120,7 @@ bool KX_MouseActuator::Update()
}

//preventing initial skipping.
if ((m_oldPosition.x <= -0.9f) && (m_oldPosition.y <= -0.9f)) {
if (m_initialSkipping) {
for (unsigned short i = 0; i < 2; ++i) {
if (m_reset[i]) {
m_oldPosition[i] = center[i];
Expand All @@ -132,6 +131,7 @@ bool KX_MouseActuator::Update()
}

SetMousePosition(m_oldPosition);
m_initialSkipping = false;
break;
}

Expand Down Expand Up @@ -205,7 +205,7 @@ bool KX_MouseActuator::Update()
break;
}
}
return result;
return true;
}

EXP_Value *KX_MouseActuator::GetReplica()
Expand Down
1 change: 1 addition & 0 deletions source/gameengine/Ketsji/KX_MouseActuator.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class KX_MouseActuator : public SCA_IActuator
SCA_IInputDevice* m_mouse;
RAS_ICanvas* m_canvas;
int m_type;
bool m_initialSkipping;

bool m_visible;

Expand Down

0 comments on commit 60d29a4

Please sign in to comment.