mirror of https://github.com/mgba-emu/mgba.git
SDL: Fix pointer aliasing warning
This commit is contained in:
parent
657bcec879
commit
0fbba68b02
|
@ -498,13 +498,16 @@ static void _GBASDLRotationSample(struct GBARotationSource* source) {
|
||||||
|
|
||||||
int x = SDL_JoystickGetAxis(rotation->p->joystick, rotation->gyroX);
|
int x = SDL_JoystickGetAxis(rotation->p->joystick, rotation->gyroX);
|
||||||
int y = SDL_JoystickGetAxis(rotation->p->joystick, rotation->gyroY);
|
int y = SDL_JoystickGetAxis(rotation->p->joystick, rotation->gyroY);
|
||||||
float theta = atan2f(y, x) - atan2f(rotation->oldY, rotation->oldX);
|
union {
|
||||||
if (isnan(theta)) {
|
float f;
|
||||||
theta = 0.0f;
|
int32_t i;
|
||||||
} else if (theta > M_PI) {
|
} theta = { .f = atan2f(y, x) - atan2f(rotation->oldY, rotation->oldX) };
|
||||||
theta -= 2.0f * M_PI;
|
if (isnan(theta.f)) {
|
||||||
} else if (theta < -M_PI) {
|
theta.f = 0.0f;
|
||||||
theta += 2.0f * M_PI;
|
} else if (theta.f > M_PI) {
|
||||||
|
theta.f -= 2.0f * M_PI;
|
||||||
|
} else if (theta.f < -M_PI) {
|
||||||
|
theta.f += 2.0f * M_PI;
|
||||||
}
|
}
|
||||||
rotation->oldX = x;
|
rotation->oldX = x;
|
||||||
rotation->oldY = y;
|
rotation->oldY = y;
|
||||||
|
@ -513,6 +516,6 @@ static void _GBASDLRotationSample(struct GBARotationSource* source) {
|
||||||
if (CircleBufferSize(&rotation->zHistory) == GYRO_STEPS * sizeof(float)) {
|
if (CircleBufferSize(&rotation->zHistory) == GYRO_STEPS * sizeof(float)) {
|
||||||
CircleBufferRead32(&rotation->zHistory, (int32_t*) &oldZ);
|
CircleBufferRead32(&rotation->zHistory, (int32_t*) &oldZ);
|
||||||
}
|
}
|
||||||
CircleBufferWrite32(&rotation->zHistory, *(int32_t*) &theta);
|
CircleBufferWrite32(&rotation->zHistory, theta.i);
|
||||||
rotation->zDelta += theta - oldZ;
|
rotation->zDelta += theta.f - oldZ;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue