Add a replay speed option so that we can watch the replay in action.
This commit is contained in:
@@ -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