racing:: measuring times

This commit is contained in:
Zeno Rogue 2018-11-24 03:26:07 +01:00
parent bf23d42e4c
commit 27011f1cf0
4 changed files with 65 additions and 5 deletions

41
hud.cpp
View File

@ -343,6 +343,22 @@ void drawMobileArrow(int i) {
bool nofps = false;
string racetimeformat(int t) {
string times = "";
int digits = 0;
bool minus = (t < 0);
if(t < 0) t = -t;
while(t || digits < 6) {
int mby = (digits == 5 ? 6 : 10);
times = char('0'+(t%mby)) + times;
t /= mby; digits++;
if(digits == 3) times = "." + times;
if(digits == 5) times = ":" + times;
}
if(minus) times = "-" + times;
return times;
}
void drawStats() {
if(nohud || vid.stereo_mode == sLR) return;
if(callhandlers(false, hooks_prestats)) return;
@ -373,7 +389,8 @@ void drawStats() {
quickqueue();
}
if(vid.xres > vid.yres * 85/100 && vid.yres > vid.xres * 85/100) {
if(racing::on) ;
else if(vid.xres > vid.yres * 85/100 && vid.yres > vid.xres * 85/100) {
int bycorner[4];
for(int u=0; u<4; u++) bycorner[u] = 0;
for(int i=0; i<glyphs; i++) if(ikappear(i) && (glyphflags(i) & GLYPH_INSQUARE))
@ -482,7 +499,27 @@ void drawStats() {
calcparam(); current_display->set_projection(0, false);
string s0;
if(!peace::on) {
if(racing::on) {
#if CAP_RACING
color_t col;
if(ticks >= racing::race_start_tick)
col = 0x00FF00;
else if(ticks >= racing::race_start_tick - 2000)
col = 0xFFFF00;
else
col = 0xFF0000;
for(int i=0; i<multi::players; i++) if(racing::race_finish_tick[i])
col = 0xFFFFFF;
dynamicval<int> x(vid.fsize, vid.fsize*2);
if(displayButtonS(vid.xres - 8, vid.fsize, racetimeformat(ticks - racing::race_start_tick), col, 16, vid.fsize));
for(int i=0; i<multi::players; i++) if(racing::race_finish_tick[i]) {
multi::cpid = i;
if(displayButtonS(vid.xres - 8, vid.fsize * (3+i), racetimeformat(racing::race_finish_tick[i] - racing::race_start_tick), (getcs().uicolor >> 8), 16, vid.fsize));
}
#endif
}
else if(!peace::on) {
if(displayButtonS(vid.xres - 8, vid.fsize, XLAT("score: %1", its(gold())), forecolor, 16, vid.fsize)) {
mouseovers = XLAT("Your total wealth"),
instat = true,

View File

@ -4685,6 +4685,8 @@ namespace racing {
extern map<cell*, pair<int, int> > trackstage;
extern int current_player;
extern vector<eLand> race_lands;
extern string track_code;
extern int race_start_tick, race_finish_tick[MAXPLAYER];
}
bool subscreen_split(reaction_t for_each_subscreen);

View File

@ -19,6 +19,21 @@ static const int TWIDTH = 6;
vector<cell*> track;
map<cell*, pair<int, int> > trackstage;
string track_code = "OFFICIAL";
int race_start_tick, race_finish_tick[MAXPLAYER];
struct ghostmoment {
int step;
cell *where;
transmatrix T;
ld footphase;
};
map<string, map<int, vector<ghostmoment> > > race_ghosts;
vector<ghostmoment> current_history[MAXPLAYER];
void fix_cave(cell *c) {
int v = 0;
// if(c->wall == waCavewall) v++;
@ -290,10 +305,11 @@ void generate_track() {
*/
track_ready = true;
race_start_tick = 0;
for(int i=0; i<MAXPLAYER; i++) race_finish_tick[i] = 0;
}
vector<tuple<int, cell*, transmatrix, ld> > history;
bool inrec = false;
ld race_angle = 90;
@ -302,12 +318,14 @@ int current_player;
void set_view() {
if(race_start_tick == 0) race_start_tick = ticks + 5000;
if(subscreen_split(set_view)) return;
shmup::monster *who = shmup::pc[current_player];
safety = true;
if(!inrec) history.emplace_back(ticks, who->base, who->at, who->footphase);
if(!inrec) current_history[current_player].emplace_back(ghostmoment{ticks - race_start_tick, who->base, who->at, who->footphase});
transmatrix at = ggmatrix(who->base) * who->at;

View File

@ -1580,6 +1580,7 @@ void movePlayer(monster *m, int delta) {
if(abs(mdx) > abs(mturn)) mturn = -mdx;
mdx = mdy = 0;
facemouse = shotkey = dropgreen = false;
if(ticks < racing::race_start_tick) mgo = 0;
}
#endif
@ -1791,6 +1792,8 @@ void movePlayer(monster *m, int delta) {
mirror::createHere(cw, cpid);
mirror::breakMirror(cw, cpid);
awakenMimics(m, c2);
if(racing::on && !racing::race_finish_tick[racing::current_player])
racing::race_finish_tick[racing::current_player] = ticks;
}
if(c2->wall == waGlass && items[itOrbAether]) {
items[itOrbAether] = 0;