Skip to content

Commit

Permalink
Round speed to nearest tenth
Browse files Browse the repository at this point in the history
This fixes some problems with floating point rounding errors.
  • Loading branch information
Beyley committed Oct 24, 2023
1 parent 624247f commit e0249e9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion game/screens/gameplay.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1339,7 +1339,7 @@ fn drawScoreUi(render_state: Screen.RenderState, data: *GameplayData) !void {
},
};

//Get the accuracy timer in seconds, note we divide in 2 stagets to help remove floating point inaccuracies
//Get the accuracy timer in seconds, note we divide in 2 stages to help remove floating point inaccuracies
var accuracy_text_timer = @as(f32, @floatFromInt(data.animation_timers.accuracy_text.read() / std.time.ns_per_ms)) / std.time.ms_per_s;

var accuracy_text_offset: f32 = 0;
Expand Down
4 changes: 4 additions & 0 deletions game/screens/song_select.zig
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ pub fn keyDown(self: *Screen, key: c.SDL_Keysym) anyerror!void {
} else if (data.challenge_info.speed < 4) {
data.challenge_info.speed += 0.5;
}
//Round to nearest tenth to prevent floating pointrounding errors
data.challenge_info.speed = @round(data.challenge_info.speed * 10.0) / 10.0;
},
//Speed down
c.SDLK_COMMA => {
Expand All @@ -141,6 +143,8 @@ pub fn keyDown(self: *Screen, key: c.SDL_Keysym) anyerror!void {
} else if (data.challenge_info.speed > 0.5) {
data.challenge_info.speed -= 0.1;
}
//Round to nearest tenth to prevent floating point rounding errors
data.challenge_info.speed = @round(data.challenge_info.speed * 10.0) / 10.0;
},
//Key down
c.SDLK_MINUS => {
Expand Down

0 comments on commit e0249e9

Please sign in to comment.