use osyncstream for writing to gamelog.txt

develop
Myk Taylor 2023-09-17 21:22:43 -07:00
parent 48c48baab4
commit 4695b8c86d
No known key found for this signature in database
1 changed files with 11 additions and 5 deletions

@ -28,7 +28,11 @@ distribution.
#include <string> #include <string>
#include <vector> #include <vector>
#include <map> #include <map>
using namespace std; #include <syncstream>
using std::map;
using std::string;
using std::vector;
#include "modules/Gui.h" #include "modules/Gui.h"
#include "MemAccess.h" #include "MemAccess.h"
@ -1397,8 +1401,10 @@ DFHACK_EXPORT void Gui::writeToGamelog(std::string message)
return; return;
std::ofstream fseed("gamelog.txt", std::ios::out | std::ios::app); std::ofstream fseed("gamelog.txt", std::ios::out | std::ios::app);
if(fseed.is_open()) if(fseed.is_open()) {
fseed << message << std::endl; std::osyncstream wrapped_fseed(fseed);
wrapped_fseed << message << std::endl;
}
fseed.close(); fseed.close();
} }
@ -1540,7 +1546,7 @@ DFHACK_EXPORT int Gui::makeAnnouncement(df::announcement_type type, df::announce
if (flags.bits.D_DISPLAY) if (flags.bits.D_DISPLAY)
{ {
world->status.display_timer = ANNOUNCE_DISPLAY_TIME; world->status.display_timer = ANNOUNCE_DISPLAY_TIME;
Gui::writeToGamelog('x' + to_string(repeat_count + 1)); Gui::writeToGamelog('x' + std::to_string(repeat_count + 1));
} }
return -1; return -1;
} }
@ -1802,7 +1808,7 @@ bool Gui::autoDFAnnouncement(df::report_init r, string message)
if (a_flags.bits.D_DISPLAY) if (a_flags.bits.D_DISPLAY)
{ {
world->status.display_timer = r.display_timer; world->status.display_timer = r.display_timer;
Gui::writeToGamelog('x' + to_string(repeat_count + 1)); Gui::writeToGamelog('x' + std::to_string(repeat_count + 1));
} }
DEBUG(gui).print("Announcement succeeded as repeat:\n%s\n", message.c_str()); DEBUG(gui).print("Announcement succeeded as repeat:\n%s\n", message.c_str());
return true; return true;