diff --git a/src/game/boe.main.cpp b/src/game/boe.main.cpp index f397ad9a..1f9c8b87 100644 --- a/src/game/boe.main.cpp +++ b/src/game/boe.main.cpp @@ -304,6 +304,7 @@ extern bool record_verbose; extern bool replay_verbose; extern bool replay_strict; +bool record_in_memory = true; static void process_args(int argc, char* argv[]) { preprocess_args(argc, argv); @@ -374,6 +375,11 @@ static void process_args(int argc, char* argv[]) { exit(1); } // Don't return, because we want to support recording a run that starts with a party from the CLI. + }else if(record_in_memory){ + if(!init_action_log("record", "")){ + std::cerr << "Failed to start recording in memory." << std::endl; + exit(1); + } } if(saved_game){ diff --git a/src/tools/replay.cpp b/src/tools/replay.cpp index 528c90f5..d912ed79 100644 --- a/src/tools/replay.cpp +++ b/src/tools/replay.cpp @@ -44,6 +44,16 @@ std::string log_file; Element* next_action; boost::optional replay_fps_limit; +static void save_log() { + if(!log_file.empty()) log_document.SaveFile(log_file); +} + +void start_log_file(std::string file) { + log_file = file; + std::cout << "Recording this session: " << log_file << std::endl; + save_log(); +} + bool init_action_log(std::string command, std::string file) { if(command == "record-unique") { // If a filename is given, use it as a base, but insert a timestamp for uniqueness. @@ -72,9 +82,12 @@ bool init_action_log(std::string command, std::string file) { root_element.SetAttribute("Repo", GIT_REPO); #endif log_document.InsertEndChild(root_element); - log_document.SaveFile(log_file); recording = true; - std::cout << "Recording this session: " << log_file << std::endl; + if(log_file.empty()){ + std::cout << "Recording this session in memory." << std::endl; + }else{ + start_log_file(log_file); + } } catch(...) { std::cout << "Failed to write to file " << log_file << std::endl; } @@ -125,7 +138,7 @@ void record_action(std::string action_type, std::string inner_text, bool cdata) action_text.SetCDATA(cdata); next_action.InsertEndChild(action_text); root->InsertEndChild(next_action); - log_document.SaveFile(log_file); + save_log(); } void record_action(std::string action_type, std::map info) { @@ -138,13 +151,13 @@ void record_action(std::string action_type, std::map in next_action.InsertEndChild(next_child); } root->InsertEndChild(next_action); - log_document.SaveFile(log_file); + save_log(); } void record_action(Element& action) { Element* root = log_document.FirstChildElement(); root->InsertEndChild(action); - log_document.SaveFile(log_file); + save_log(); } void record_field_input(cKey key) { diff --git a/src/tools/replay.hpp b/src/tools/replay.hpp index e75ec363..5ac6073b 100644 --- a/src/tools/replay.hpp +++ b/src/tools/replay.hpp @@ -47,6 +47,7 @@ extern short short_from_action(Element& action); extern cKey key_from_action(Element& action); extern word_rect_t word_rect_from_action(Element& action); extern void record_click_talk_rect(word_rect_t word_rect, bool preset); +extern void start_log_file(std::string file); extern const std::string replay_warning; extern const std::string replay_error;