change --advance-time to --verbose, w/ better replay behavior

This commit is contained in:
2024-09-25 10:46:36 -05:00
committed by Celtic Minstrel
parent c335f34537
commit 1a6f005a36
3 changed files with 44 additions and 12 deletions

View File

@@ -2,7 +2,6 @@
// Input recording system
#include "ticpp.h"
#include <ctime>
#include <iomanip>
#include <fstream>
@@ -10,12 +9,15 @@
#include <boost/algorithm/string/predicate.hpp>
#include <boost/optional.hpp>
#include <cppcodec/base64_rfc4648.hpp>
#include "tools/framerate_limiter.hpp"
#include <locale>
#include <codecvt>
#include <string>
#include <algorithm>
#include <boost/lexical_cast.hpp>
#include "ticpp.h"
#include "gfx/render_shapes.hpp"
#include "tools/framerate_limiter.hpp"
#ifndef MSBUILD_GITREV
#include "tools/gitrev.hpp"
#endif
@@ -25,6 +27,9 @@ using base64 = cppcodec::base64_rfc4648;
bool recording = false;
bool replaying = false;
bool record_verbose = false;
bool replay_verbose = false;
std::string last_action_type;
using namespace ticpp;
@@ -72,8 +77,31 @@ bool init_action_log(std::string command, std::string file) {
else if (command == "replay") {
try {
log_document.LoadFile(file);
Element* root = log_document.FirstChildElement();
next_action = root->FirstChildElement();
// Set replay_verbose automatically if the log has verbose elements.
// This must be done before starting the replay, not when the first
// verbose element appears, because the *absence* of a verbose elements
// is meaningful in a verbose replay.
// This is an O(N) traversal, but it won't matter, because advance_time
// elements are the most common elements in verbose logs.
// Specifying replay_verbose manually and incorrectly would cause confusing
// errors.
std::vector<std::string> verbose_actions = { "advance_time" };
Element* checking_action = next_action;
do{
if(std::find(verbose_actions.begin(), verbose_actions.end(), checking_action->Value()) != verbose_actions.end()){
replay_verbose = true;
break;
}
checking_action = checking_action->NextSiblingElement(false);
}while(checking_action != nullptr);
replaying = true;
} catch(...) {
std::cout << "Failed to load file " << file << std::endl;
@@ -159,6 +187,12 @@ Element& pop_next_action(std::string expected_action_type) {
// control_click actions are not meaningful for debugging
if (to_return->Value() != "control_click"){
last_action_type = to_return->Value();
if(replay_verbose){
// Verbose replays are for internal testing, so this console output won't bother
// anyone and is very helpful:
std::cout << last_action_type << std::endl;
}
}
return *to_return;