Skip to content

Commit

Permalink
Trying to fix gamepads on Android
Browse files Browse the repository at this point in the history
  • Loading branch information
deathkiller committed Nov 5, 2023
1 parent 80b1dbd commit c964c7d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
8 changes: 3 additions & 5 deletions Sources/Jazz2/Actors/Enemies/EnemyBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ namespace Jazz2::Actors::Enemies
return false;
}

bool tilesetReduced = GetState(ActorState::CollideWithTilesetReduced);
bool skipPerPixelCollisions = GetState(ActorState::SkipPerPixelCollisions);
ActorState prevState = GetState();
SetState(ActorState::CollideWithTilesetReduced, false);
SetState(ActorState::SkipPerPixelCollisions, true);

Expand All @@ -111,9 +110,8 @@ namespace Jazz2::Actors::Enemies
} else {
success = false;
}

SetState(ActorState::CollideWithTilesetReduced, tilesetReduced);
SetState(ActorState::SkipPerPixelCollisions, skipPerPixelCollisions);

SetState(prevState);

return success;
}
Expand Down
15 changes: 15 additions & 0 deletions Sources/nCine/Backends/Android/AndroidInputManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,21 @@ namespace nCine
}
LOGI("Device (%d, %d) - Axes%s", deviceId, joyId, deviceInfoString);
#endif
if (numAxes >= 4) {
// Android sometimes returns strange range for the first axis, all other axes are fine
if (std::abs(joyState.axesMinValues_[0]) < 0.01f && joyState.axesRangeValues_[0] > 128.0f &&
std::abs(joyState.axesMinValues_[1]) < 0.01f && joyState.axesRangeValues_[1] > 128.0f &&
joyState.axesMinValues_[2] == -1.0f && joyState.axesRangeValues_[2] == 2.0f &&
joyState.axesMinValues_[3] == -1.0f && joyState.axesRangeValues_[3] == 2.0f) {
LOGW("Device (%d, %d) - Axis %d:%d reported strange range %.2f, using %.2f to %.2f instead", deviceId, joyId, 0, joyState.axesMapping_[0], joyState.axesRangeValues_[0], -1.0f, 1.0f);
LOGW("Device (%d, %d) - Axis %d:%d reported strange range %.2f, using %.2f to %.2f instead", deviceId, joyId, 1, joyState.axesMapping_[1], joyState.axesRangeValues_[1], -1.0f, 1.0f);
joyState.axesMinValues_[0] = -1.0f;
joyState.axesRangeValues_[0] = 2.0f;
joyState.axesMinValues_[1] = -1.0f;
joyState.axesRangeValues_[1] = 2.0f;
}
}

joyState.numAxes_ = numAxes;
joyState.numAxesMapped_ = numAxesMapped;

Expand Down

0 comments on commit c964c7d

Please sign in to comment.