1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2025-02-08 23:20:12 +00:00

nilrider:: replays available in manual mode

This commit is contained in:
Zeno Rogue 2022-05-01 16:42:38 +02:00
parent 1e176bb3b0
commit c4d4bfa517

View File

@ -12,7 +12,7 @@ namespace nilrider {
bool paused = false; bool paused = false;
bool planning_mode = false; bool planning_mode = false;
bool view_simulation = false; bool view_replay = false;
int simulation_start_tick; int simulation_start_tick;
ld aimspeed_key_x = 1, aimspeed_key_y = 1, aimspeed_mouse_x = 1, aimspeed_mouse_y = 1; ld aimspeed_key_x = 1, aimspeed_key_y = 1, aimspeed_mouse_x = 1, aimspeed_mouse_y = 1;
@ -22,7 +22,7 @@ vector<string> move_names = { "camera down", "move left", "camera up", "move rig
int reversals = 0; int reversals = 0;
void frame() { void frame() {
if(planning_mode && !view_simulation) return; if(planning_mode && !view_replay) return;
shiftmatrix V = ggmatrix(cwt.at); shiftmatrix V = ggmatrix(cwt.at);
@ -32,7 +32,7 @@ void frame() {
} }
bool turn(int delta) { bool turn(int delta) {
if(planning_mode && !view_simulation) return false; if(planning_mode && !view_replay) return false;
multi::handleInput(0); multi::handleInput(0);
auto& a = multi::actionspressed; auto& a = multi::actionspressed;
@ -78,7 +78,7 @@ bool turn(int delta) {
} }
} }
if(!paused && !view_simulation && !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);
bool b = curlev->current.tick(curlev); bool b = curlev->current.tick(curlev);
if(b) timer += 1. / tps; if(b) timer += 1. / tps;
@ -94,22 +94,33 @@ void main_menu();
#define PSEUDOKEY_PAUSE 2511 #define PSEUDOKEY_PAUSE 2511
#define PSEUDOKEY_SIM 2512 #define PSEUDOKEY_SIM 2512
void toggle_replay() {
view_replay = !view_replay;
paused = false;
simulation_start_tick = ticks;
if(!view_replay && !planning_mode) {
paused = true;
curlev->current = curlev->history.back();
timer = isize(curlev->history) * 1. / tps;
}
}
void run() { void run() {
cmode = sm::MAP; cmode = sm::MAP;
clearMessages(); clearMessages();
dialog::init(); dialog::init();
if(view_simulation && !paused) { if(view_replay && !paused) {
int ttick = gmod(ticks - simulation_start_tick, isize(curlev->history)); int ttick = gmod(ticks - simulation_start_tick, isize(curlev->history));
timer = ttick * 1. / tps; timer = ttick * 1. / tps;
curlev->current = curlev->history[ttick]; curlev->current = curlev->history[ttick];
curlev->current.centerview(curlev); curlev->current.centerview(curlev);
} }
if(planning_mode && !view_simulation) if(planning_mode && !view_replay)
cmode |= sm::SHOWCURSOR; cmode |= sm::SHOWCURSOR;
if(aimspeed_mouse_x == 0 && aimspeed_mouse_y == 0) if(aimspeed_mouse_x == 0 && aimspeed_mouse_y == 0)
cmode |= sm::SHOWCURSOR; cmode |= sm::SHOWCURSOR;
gamescreen(0); gamescreen(0);
if(planning_mode && !view_simulation) { if(planning_mode && !view_replay) {
curlev->draw_planning_screen(); curlev->draw_planning_screen();
if(!holdmouse) { if(!holdmouse) {
auto t0 = SDL_GetTicks(); auto t0 = SDL_GetTicks();
@ -131,20 +142,14 @@ void run() {
x += textwidth(vid.fsize, s) + vid.fsize; x += textwidth(vid.fsize, s) + vid.fsize;
}; };
if(planning_mode && !view_simulation) { if(planning_mode && !view_replay) {
for(auto& b: buttons) show_button(b.first, b.second, planmode == b.first ? 0xFFD500 : dialog::dialogcolor); for(auto& b: buttons) show_button(b.first, b.second, planmode == b.first ? 0xFFD500 : dialog::dialogcolor);
show_button(PSEUDOKEY_SIM, "simulation"); show_button(PSEUDOKEY_SIM, "simulation");
} }
bool pause_av = false; bool pause_av = view_replay || !planning_mode;
if(planning_mode && view_simulation) { if(pause_av) {
show_button(PSEUDOKEY_SIM, "return"); show_button(PSEUDOKEY_SIM, planning_mode ? "return" : "replay", (view_replay && !planning_mode) ? 0xFF0000 : dialog::dialogcolor);
pause_av = true;
show_button(PSEUDOKEY_PAUSE, "pause", paused ? 0xFF0000 : dialog::dialogcolor);
}
if(!planning_mode) {
pause_av = true;
show_button(PSEUDOKEY_PAUSE, "pause", paused ? 0xFF0000 : dialog::dialogcolor); show_button(PSEUDOKEY_PAUSE, "pause", paused ? 0xFF0000 : dialog::dialogcolor);
} }
@ -156,17 +161,13 @@ void run() {
}); });
if(pause_av) dialog::add_key_action(PSEUDOKEY_PAUSE, [] { if(pause_av) dialog::add_key_action(PSEUDOKEY_PAUSE, [] {
paused = !paused; paused = !paused;
if(view_simulation && !paused) if(view_replay && !paused)
simulation_start_tick = ticks - timer * tps; simulation_start_tick = ticks - timer * tps;
}); });
dialog::add_key_action('-', [] { dialog::add_key_action('-', [] {
paused = false; paused = false;
}); });
if(planning_mode) dialog::add_key_action(PSEUDOKEY_SIM, [] { dialog::add_key_action(PSEUDOKEY_SIM, toggle_replay);
view_simulation = !view_simulation;
paused = false;
simulation_start_tick = ticks;
});
dialog::display(); dialog::display();
char* t = multi::scfg.keyaction; char* t = multi::scfg.keyaction;
@ -179,7 +180,7 @@ void run() {
keyhandler = [] (int sym, int uni) { keyhandler = [] (int sym, int uni) {
if(paused) handlePanning(sym, uni); if(paused) handlePanning(sym, uni);
if(planning_mode && !view_simulation && curlev->handle_planning(sym, uni)) return; if(planning_mode && !view_replay && curlev->handle_planning(sym, uni)) return;
dialog::handleNavigation(sym, uni); dialog::handleNavigation(sym, uni);
}; };
} }
@ -250,8 +251,7 @@ void main_menu() {
}); });
dialog::addItem("view the replay", 'v'); dialog::addItem("view the replay", 'v');
dialog::add_action([] { dialog::add_action(toggle_replay);
});
dialog::addItem("save the replay", 'e'); dialog::addItem("save the replay", 'e');
dialog::add_action([] { dialog::add_action([] {
@ -321,7 +321,7 @@ void initialize() {
pushScreen(run); pushScreen(run);
} }
auto celldemo = arg::add3("-unilcycle", initialize) + arg::add3("-unilplan", [] { planning_mode = true; }) + arg::add3("-viewsim", [] { view_simulation = true; }) auto celldemo = arg::add3("-unilcycle", initialize) + arg::add3("-unilplan", [] { planning_mode = true; }) + arg::add3("-viewsim", [] { view_replay = true; })
+ arg::add3("-oqc", [] { on_quit = popScreenAll; }) + arg::add3("-oqc", [] { on_quit = popScreenAll; })
+ arg::add3("-nilsolve", [] { curlev->solve(); }) + arg::add3("-nilsolve", [] { curlev->solve(); })
+ addHook(hooks_configfile, 100, [] { + addHook(hooks_configfile, 100, [] {