From 27011f1cf03acab51ef83ea6f411ef219e6b36d2 Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Sat, 24 Nov 2018 03:26:07 +0100 Subject: [PATCH] racing:: measuring times --- hud.cpp | 41 +++++++++++++++++++++++++++++++++++++++-- hyper.h | 2 ++ racing.cpp | 24 +++++++++++++++++++++--- shmup.cpp | 3 +++ 4 files changed, 65 insertions(+), 5 deletions(-) diff --git a/hud.cpp b/hud.cpp index cd7f1e07..9cabc9b0 100644 --- a/hud.cpp +++ b/hud.cpp @@ -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; iset_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 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> 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, diff --git a/hyper.h b/hyper.h index a00706d3..4ca061c8 100644 --- a/hyper.h +++ b/hyper.h @@ -4685,6 +4685,8 @@ namespace racing { extern map > trackstage; extern int current_player; extern vector race_lands; + extern string track_code; + extern int race_start_tick, race_finish_tick[MAXPLAYER]; } bool subscreen_split(reaction_t for_each_subscreen); diff --git a/racing.cpp b/racing.cpp index ae8774e6..fdeb2853 100644 --- a/racing.cpp +++ b/racing.cpp @@ -19,6 +19,21 @@ static const int TWIDTH = 6; vector track; map > trackstage; +string track_code = "OFFICIAL"; + +int race_start_tick, race_finish_tick[MAXPLAYER]; + +struct ghostmoment { + int step; + cell *where; + transmatrix T; + ld footphase; + }; + +map > > race_ghosts; + +vector 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 > 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; diff --git a/shmup.cpp b/shmup.cpp index 5b7af485..2f992aac 100644 --- a/shmup.cpp +++ b/shmup.cpp @@ -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;