1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2024-11-27 14:37:16 +00:00

nilrider:: consistent replays

This commit is contained in:
Zeno Rogue 2022-05-01 16:44:35 +02:00
parent f82043e87e
commit 3072a998ba
4 changed files with 23 additions and 0 deletions

View File

@ -80,6 +80,7 @@ bool turn(int delta) {
if(!paused && !view_replay && !backing) for(int i=0; i<delta; i++) {
curlev->history.push_back(curlev->current);
curlev->current.be_consistent();
bool b = curlev->current.tick(curlev);
if(b) timer += 1. / tps;
else curlev->history.pop_back();

View File

@ -24,6 +24,7 @@ struct timestamp {
void draw_instruments(ld t);
ld energy_in_squares();
bool collect(level*);
void be_consistent();
};
struct planpoint {

View File

@ -52,6 +52,7 @@ bool level::simulate() {
at.heading_angle = atan2(h[1] - at.where[1], h[0] - at.where[0]);
history.back() = at;
at.be_consistent();
if(!at.tick(this)) return false;
at.t = goal_t;
history.push_back(at);

View File

@ -89,6 +89,26 @@ bool timestamp::collect(level *lev) {
return true;
}
/* convert heading to integral units, to make saved replays consistent */
constexpr ld h_units = 360 * 60 * 60;
constexpr ld h_mul = h_units / 2 / M_PI;
int heading_to_int(ld a) {
a = a * h_mul;
int ai = floor(a + .5);
ai = gmod(ai, h_units);
return ai;
}
ld int_to_heading(ld a) {
return a / h_mul;
}
void timestamp::be_consistent() {
heading_angle = int_to_heading(heading_to_int(heading_angle));
}
bool timestamp::tick(level *lev) {
if(!collect(lev)) return false;