mirror of
https://github.com/zenorogue/hyperrogue.git
synced 2025-08-03 20:34:04 +00:00
nilrider:: consistent replays
This commit is contained in:
parent
f82043e87e
commit
3072a998ba
@ -80,6 +80,7 @@ bool turn(int delta) {
|
|||||||
|
|
||||||
if(!paused && !view_replay && !backing) for(int i=0; i<delta; i++) {
|
if(!paused && !view_replay && !backing) for(int i=0; i<delta; i++) {
|
||||||
curlev->history.push_back(curlev->current);
|
curlev->history.push_back(curlev->current);
|
||||||
|
curlev->current.be_consistent();
|
||||||
bool b = curlev->current.tick(curlev);
|
bool b = curlev->current.tick(curlev);
|
||||||
if(b) timer += 1. / tps;
|
if(b) timer += 1. / tps;
|
||||||
else curlev->history.pop_back();
|
else curlev->history.pop_back();
|
||||||
|
@ -24,6 +24,7 @@ struct timestamp {
|
|||||||
void draw_instruments(ld t);
|
void draw_instruments(ld t);
|
||||||
ld energy_in_squares();
|
ld energy_in_squares();
|
||||||
bool collect(level*);
|
bool collect(level*);
|
||||||
|
void be_consistent();
|
||||||
};
|
};
|
||||||
|
|
||||||
struct planpoint {
|
struct planpoint {
|
||||||
|
@ -52,6 +52,7 @@ bool level::simulate() {
|
|||||||
at.heading_angle = atan2(h[1] - at.where[1], h[0] - at.where[0]);
|
at.heading_angle = atan2(h[1] - at.where[1], h[0] - at.where[0]);
|
||||||
history.back() = at;
|
history.back() = at;
|
||||||
|
|
||||||
|
at.be_consistent();
|
||||||
if(!at.tick(this)) return false;
|
if(!at.tick(this)) return false;
|
||||||
at.t = goal_t;
|
at.t = goal_t;
|
||||||
history.push_back(at);
|
history.push_back(at);
|
||||||
|
@ -89,6 +89,26 @@ bool timestamp::collect(level *lev) {
|
|||||||
return true;
|
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) {
|
bool timestamp::tick(level *lev) {
|
||||||
|
|
||||||
if(!collect(lev)) return false;
|
if(!collect(lev)) return false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user