From 62331b43f15c5eb1fd3eaa661cad742c04a984f1 Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Sun, 1 May 2022 16:45:18 +0200 Subject: [PATCH] nilrider:: basic save functionality (no load though) --- rogueviz/nilrider/nilrider.cpp | 9 ++++++++- rogueviz/nilrider/nilrider.h | 17 +++++++++++++++- rogueviz/nilrider/save.cpp | 37 ++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 rogueviz/nilrider/save.cpp diff --git a/rogueviz/nilrider/nilrider.cpp b/rogueviz/nilrider/nilrider.cpp index da4fba61..329ef7ab 100644 --- a/rogueviz/nilrider/nilrider.cpp +++ b/rogueviz/nilrider/nilrider.cpp @@ -5,6 +5,7 @@ #include "level.cpp" #include "planning.cpp" #include "solver.cpp" +#include "save.cpp" namespace nilrider { @@ -254,13 +255,19 @@ void main_menu() { dialog::addItem("view the replay", 'v'); dialog::add_action(toggle_replay); - dialog::addItem("save the replay", 'e'); + dialog::addItem("save the replay", 's'); dialog::add_action([] { + vector ang; + for(auto& h: curlev->history) ang.push_back(heading_to_int(h.heading_angle)); + curlev->manual_replays.emplace_back(manual_replay{new_replay_name(), std::move(ang)}); + save(); }); } else { dialog::addItem("save this plan", 's'); dialog::add_action([] { + curlev->plan_replays.emplace_back(plan_replay{new_replay_name(), curlev->plan}); + save(); }); } diff --git a/rogueviz/nilrider/nilrider.h b/rogueviz/nilrider/nilrider.h index db7d2bec..7e65425d 100644 --- a/rogueviz/nilrider/nilrider.h +++ b/rogueviz/nilrider/nilrider.h @@ -33,6 +33,8 @@ struct planpoint { planpoint(hyperpoint a, hyperpoint v): at(a), vel(v) {}; }; +using plan_t = vector; + constexpr flagtype nrlPolar = Flag(1); struct statue { @@ -47,6 +49,16 @@ struct triangledata { array colors; }; +struct manual_replay { + string name; + vector headings; + }; + +struct plan_replay { + string name; + plan_t plan; + }; + struct level { string name; char hotkey; @@ -94,8 +106,11 @@ struct level { vector history; + vector manual_replays; + vector plan_replays; + /** plan for the planning mode */ - vector plan; + plan_t plan; void init_plan(); bool simulate(); void draw_planning_screen(); diff --git a/rogueviz/nilrider/save.cpp b/rogueviz/nilrider/save.cpp new file mode 100644 index 00000000..496079e6 --- /dev/null +++ b/rogueviz/nilrider/save.cpp @@ -0,0 +1,37 @@ +namespace nilrider { + +const string ver = "0.1"; + +string new_replay_name() { + time_t timer; + timer = time(NULL); + char timebuf[128]; + strftime(timebuf, 128, "%y%m%d-%H%M%S", localtime(&timer)); + return timebuf; + } + +void save() { + println(hlog, "save called"); + fhstream f("nilrider.save", "wt"); + println(f, "version ", ver); + for(auto l: all_levels) { + for(auto& p: l->manual_replays) { + println(f, "*MANUAL"); + println(f, l->name); + println(f, p.name); + println(f, isize(p.headings)); + for(auto t: p.headings) println(f, t); + println(f); + } + for(auto& p: l->plan_replays) { + println(f, "*PLANNING"); + println(f, l->name); + println(f, p.name); + println(f, isize(p.plan)); + for(auto t: p.plan) println(f, format("%.6f %.6f %.6f %.6f", t.at[0], t.at[1], t.vel[0], t.vel[1])); + println(f); + } + } + } + +}