Add a replay speed option so that we can watch the replay in action.
This commit is contained in:
@@ -234,9 +234,11 @@ static void process_args(int argc, char* argv[]) {
|
||||
clara::Parser cli;
|
||||
bool record_unique = false;
|
||||
boost::optional<std::string> record_to, replay, saved_game;
|
||||
boost::optional<double> replay_speed;
|
||||
cli |= clara::Opt(record_to, "record")["--record"]("Records a replay of your session to the specified XML file.");
|
||||
cli |= clara::Opt(record_unique)["--unique"]("When recording, automatically insert a timestamp into the filename to guarantee uniqueness.");
|
||||
cli |= clara::Opt(replay, "replay-file")["--replay"]("Replays a previously-recorded session from the specified XML file.");
|
||||
cli |= clara::Opt(replay_speed, "fps")["--replay-speed"]("Specifies how quickly actions are processed while replaying");
|
||||
cli |= clara::Arg(saved_game, "save-file")("Launch and load a saved game file.");
|
||||
bool show_help = false;
|
||||
cli |= clara::Help(show_help);
|
||||
@@ -249,7 +251,13 @@ static void process_args(int argc, char* argv[]) {
|
||||
exit(0);
|
||||
}
|
||||
if(record_to && init_action_log(record_unique || record_to->empty() ? "record-unique" : "record", *record_to)) return;
|
||||
if(replay && init_action_log("replay", *replay)) return;
|
||||
if(replay && init_action_log("replay", *replay)) {
|
||||
if(replay_speed) {
|
||||
extern boost::optional<cFramerateLimiter> replay_fps_limit;
|
||||
replay_fps_limit.emplace(*replay_speed);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if(saved_game) {
|
||||
if(!load_party(*saved_game, univ)) {
|
||||
std::cout << "Failed to load save file: " << *saved_game << std::endl;
|
||||
|
@@ -6,6 +6,11 @@ cFramerateLimiter::cFramerateLimiter(int desired_fps)
|
||||
|
||||
}
|
||||
|
||||
cFramerateLimiter::cFramerateLimiter(double desired_fps)
|
||||
: desired_microseconds_per_frame { static_cast<int>(1000000 / desired_fps) } {
|
||||
|
||||
}
|
||||
|
||||
void cFramerateLimiter::frame_finished() {
|
||||
const sf::Int64 remaining_time_budget = this->desired_microseconds_per_frame - this->clock.getElapsedTime().asMicroseconds();
|
||||
if(remaining_time_budget > 0) sf::sleep(sf::microseconds(remaining_time_budget));
|
||||
|
@@ -6,8 +6,9 @@
|
||||
|
||||
class cFramerateLimiter {
|
||||
public:
|
||||
|
||||
cFramerateLimiter(int desired_fps = 60);
|
||||
static const int DEFAULT_FPS = 60;
|
||||
cFramerateLimiter(int desired_fps = DEFAULT_FPS);
|
||||
cFramerateLimiter(double desired_fps);
|
||||
|
||||
void frame_finished();
|
||||
|
||||
|
@@ -8,7 +8,9 @@
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <boost/algorithm/string/predicate.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
#include <cppcodec/base64_rfc4648.hpp>
|
||||
#include "tools/framerate_limiter.hpp"
|
||||
using base64 = cppcodec::base64_rfc4648;
|
||||
|
||||
bool recording = false;
|
||||
@@ -18,6 +20,7 @@ using namespace ticpp;
|
||||
Document log_document;
|
||||
std::string log_file;
|
||||
Element* next_action;
|
||||
boost::optional<cFramerateLimiter> replay_fps_limit;
|
||||
|
||||
bool init_action_log(std::string command, std::string file) {
|
||||
if(command == "record-unique") {
|
||||
@@ -108,9 +111,12 @@ Element& pop_next_action(std::string expected_action_type) {
|
||||
}
|
||||
|
||||
Element* to_return = next_action;
|
||||
|
||||
next_action = next_action->NextSiblingElement(false);
|
||||
|
||||
if(replay_fps_limit.has_value()) {
|
||||
replay_fps_limit->frame_finished();
|
||||
}
|
||||
|
||||
return *to_return;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user