Skip to content

Commit

Permalink
Improve scrolling in high FPS situations
Browse files Browse the repository at this point in the history
  • Loading branch information
past-due committed Oct 13, 2023
1 parent 971781d commit c936be8
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions src/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1092,24 +1092,27 @@ static void handleCameraScrolling()

// Apparently there's stutter if using deltaRealTime, so we have our very own delta time here, just for us.
timeDiff = wzGetTicks() - scrollRefTime;
scrollRefTime += timeDiff;
timeDiff = std::min<unsigned>(timeDiff, 500); // Since we're using our own time variable, which isn't updated when dragging a box, clamp the time here so releasing the box doesn't scroll to the edge of the map suddenly.
if (timeDiff >= 8) // throttle max update rate to avoid really jerky scrolling
{
scrollRefTime += timeDiff;
timeDiff = std::min<unsigned>(timeDiff, 500); // Since we're using our own time variable, which isn't updated when dragging a box, clamp the time here so releasing the box doesn't scroll to the edge of the map suddenly.

scrollStepLeftRight = 0;
scrollStepUpDown = 0;
calcScroll(&scrollStepLeftRight, &scrollSpeedLeftRight, scaled_accel, 2 * scaled_accel, scrollDirLeftRight * scaled_max_scroll_speed, (float)timeDiff / GAME_TICKS_PER_SEC);
calcScroll(&scrollStepUpDown, &scrollSpeedUpDown, scaled_accel, 2 * scaled_accel, scrollDirUpDown * scaled_max_scroll_speed, (float)timeDiff / GAME_TICKS_PER_SEC);
scrollStepLeftRight = 0;
scrollStepUpDown = 0;
calcScroll(&scrollStepLeftRight, &scrollSpeedLeftRight, scaled_accel, 2 * scaled_accel, scrollDirLeftRight * scaled_max_scroll_speed, (float)timeDiff / GAME_TICKS_PER_SEC);
calcScroll(&scrollStepUpDown, &scrollSpeedUpDown, scaled_accel, 2 * scaled_accel, scrollDirUpDown * scaled_max_scroll_speed, (float)timeDiff / GAME_TICKS_PER_SEC);

/* Get x component of movement */
xDif = (int) (cos(-playerPos.r.y * (M_PI / 32768)) * scrollStepLeftRight + sin(-playerPos.r.y * (M_PI / 32768)) * scrollStepUpDown);
/* Get y component of movement */
yDif = (int) (sin(-playerPos.r.y * (M_PI / 32768)) * scrollStepLeftRight - cos(-playerPos.r.y * (M_PI / 32768)) * scrollStepUpDown);
/* Get x component of movement */
xDif = (int) (cos(-playerPos.r.y * (M_PI / 32768)) * scrollStepLeftRight + sin(-playerPos.r.y * (M_PI / 32768)) * scrollStepUpDown);
/* Get y component of movement */
yDif = (int) (sin(-playerPos.r.y * (M_PI / 32768)) * scrollStepLeftRight - cos(-playerPos.r.y * (M_PI / 32768)) * scrollStepUpDown);

/* Adjust player's position by these components */
playerPos.p.x += xDif;
playerPos.p.z += yDif;
/* Adjust player's position by these components */
playerPos.p.x += xDif;
playerPos.p.z += yDif;

CheckScrollLimits();
CheckScrollLimits();
}

// Reset scroll directions
scrollDirLeftRight = 0;
Expand Down

0 comments on commit c936be8

Please sign in to comment.