1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-03-28 08:37:12 +00:00

Initialize log recorder right after initializing the logging

This commit is contained in:
Petr Mikheev 2022-05-22 02:47:58 +02:00
parent 8047a2138e
commit 7f8d433775
6 changed files with 52 additions and 51 deletions

View File

@ -548,15 +548,15 @@ void OMW::Engine::setSkipMenu (bool skipMenu, bool newGame)
mNewGame = newGame; mNewGame = newGame;
} }
void OMW::Engine::createWindow(Settings::Manager& settings) void OMW::Engine::createWindow()
{ {
int screen = settings.getInt("screen", "Video"); int screen = Settings::Manager::getInt("screen", "Video");
int width = settings.getInt("resolution x", "Video"); int width = Settings::Manager::getInt("resolution x", "Video");
int height = settings.getInt("resolution y", "Video"); int height = Settings::Manager::getInt("resolution y", "Video");
Settings::WindowMode windowMode = static_cast<Settings::WindowMode>(Settings::Manager::getInt("window mode", "Video")); Settings::WindowMode windowMode = static_cast<Settings::WindowMode>(Settings::Manager::getInt("window mode", "Video"));
bool windowBorder = settings.getBool("window border", "Video"); bool windowBorder = Settings::Manager::getBool("window border", "Video");
bool vsync = settings.getBool("vsync", "Video"); bool vsync = Settings::Manager::getBool("vsync", "Video");
unsigned int antialiasing = std::max(0, settings.getInt("antialiasing", "Video")); unsigned int antialiasing = std::max(0, Settings::Manager::getInt("antialiasing", "Video"));
int pos_x = SDL_WINDOWPOS_CENTERED_DISPLAY(screen), int pos_x = SDL_WINDOWPOS_CENTERED_DISPLAY(screen),
pos_y = SDL_WINDOWPOS_CENTERED_DISPLAY(screen); pos_y = SDL_WINDOWPOS_CENTERED_DISPLAY(screen);
@ -581,7 +581,7 @@ void OMW::Engine::createWindow(Settings::Manager& settings)
flags |= SDL_WINDOW_BORDERLESS; flags |= SDL_WINDOW_BORDERLESS;
SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS,
settings.getBool("minimize on focus loss", "Video") ? "1" : "0"); Settings::Manager::getBool("minimize on focus loss", "Video") ? "1" : "0");
checkSDLError(SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8)); checkSDLError(SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8));
checkSDLError(SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8)); checkSDLError(SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8));
@ -710,7 +710,7 @@ void OMW::Engine::setWindowIcon()
} }
} }
void OMW::Engine::prepareEngine (Settings::Manager & settings) void OMW::Engine::prepareEngine()
{ {
mStateManager = std::make_unique<MWState::StateManager>(mCfgMgr.getUserDataPath() / "saves", mContentFiles); mStateManager = std::make_unique<MWState::StateManager>(mCfgMgr.getUserDataPath() / "saves", mContentFiles);
mEnvironment.setStateManager(*mStateManager); mEnvironment.setStateManager(*mStateManager);
@ -720,7 +720,7 @@ void OMW::Engine::prepareEngine (Settings::Manager & settings)
osg::ref_ptr<osg::Group> rootNode(new osg::Group); osg::ref_ptr<osg::Group> rootNode(new osg::Group);
mViewer->setSceneData(rootNode); mViewer->setSceneData(rootNode);
createWindow(settings); createWindow();
mVFS = std::make_unique<VFS::Manager>(mFSStrict); mVFS = std::make_unique<VFS::Manager>(mFSStrict);
@ -984,10 +984,6 @@ void OMW::Engine::go()
Misc::Rng::init(mRandomSeed); Misc::Rng::init(mRandomSeed);
// Load settings
Settings::Manager settings;
std::string settingspath = settings.load(mCfgMgr);
Settings::ShaderManager::get().load((mCfgMgr.getUserConfigPath() / "shaders.yaml").string()); Settings::ShaderManager::get().load((mCfgMgr.getUserConfigPath() / "shaders.yaml").string());
MWClass::registerClasses(); MWClass::registerClasses();
@ -1006,7 +1002,7 @@ void OMW::Engine::go()
mEnvironment.setFrameRateLimit(Settings::Manager::getFloat("framerate limit", "Video")); mEnvironment.setFrameRateLimit(Settings::Manager::getFloat("framerate limit", "Video"));
prepareEngine (settings); prepareEngine();
std::ofstream stats; std::ofstream stats;
if (const auto path = std::getenv("OPENMW_OSG_STATS_FILE")) if (const auto path = std::getenv("OPENMW_OSG_STATS_FILE"))
@ -1112,7 +1108,7 @@ void OMW::Engine::go()
luaWorker.join(); luaWorker.join();
// Save user settings // Save user settings
settings.saveUser(settingspath); Settings::Manager::saveUser((mCfgMgr.getUserConfigPath() / "settings.cfg").string());
Settings::ShaderManager::get().save(); Settings::ShaderManager::get().save();
mLuaManager->savePermanentStorage(mCfgMgr.getUserConfigPath().string()); mLuaManager->savePermanentStorage(mCfgMgr.getUserConfigPath().string());

View File

@ -181,13 +181,10 @@ namespace OMW
bool frame (float dt); bool frame (float dt);
/// Load settings from various files, returns the path to the user settings file
std::string loadSettings (Settings::Manager & settings);
/// Prepare engine for game play /// Prepare engine for game play
void prepareEngine (Settings::Manager & settings); void prepareEngine();
void createWindow(Settings::Manager& settings); void createWindow();
void setWindowIcon(); void setWindowIcon();
public: public:

View File

@ -5,6 +5,8 @@
#include <components/debug/debugging.hpp> #include <components/debug/debugging.hpp>
#include <components/misc/rng.hpp> #include <components/misc/rng.hpp>
#include "mwgui/debugwindow.hpp"
#include "engine.hpp" #include "engine.hpp"
#include "options.hpp" #include "options.hpp"
@ -58,8 +60,10 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat
} }
cfgMgr.readConfiguration(variables, desc); cfgMgr.readConfiguration(variables, desc);
Settings::Manager::load(cfgMgr);
setupLogging(cfgMgr.getLogPath().string(), "OpenMW"); setupLogging(cfgMgr.getLogPath().string(), "OpenMW");
MWGui::DebugWindow::startLogRecording();
Version::Version v = Version::getOpenmwVersion(variables["resources"].as<Files::MaybeQuotedPath>().string()); Version::Version v = Version::getOpenmwVersion(variables["resources"].as<Files::MaybeQuotedPath>().string());
Log(Debug::Info) << v.describe(); Log(Debug::Info) << v.describe();

View File

@ -89,7 +89,10 @@ namespace MWGui
// - Material editor // - Material editor
// - Shader editor // - Shader editor
initLogView(); MyGUI::TabItem* itemLV = mTabControl->addItem("Log Viewer");
mLogView = itemLV->createWidgetReal<MyGUI::EditBox>
("LogEdit", MyGUI::FloatCoord(0,0,1,1), MyGUI::Align::Stretch);
mLogView->setEditReadOnly(true);
#ifndef BT_NO_PROFILE #ifndef BT_NO_PROFILE
MyGUI::TabItem* item = mTabControl->addItem("Physics Profiler"); MyGUI::TabItem* item = mTabControl->addItem("Physics Profiler");
@ -100,17 +103,16 @@ namespace MWGui
#endif #endif
} }
void DebugWindow::initLogView() std::vector<char> DebugWindow::sLogCircularBuffer;
{ int64_t DebugWindow::sLogStartIndex = 0;
MyGUI::TabItem* itemLV = mTabControl->addItem("Log Viewer"); int64_t DebugWindow::sLogEndIndex = 0;
mLogView = itemLV->createWidgetReal<MyGUI::EditBox>
("LogEdit", MyGUI::FloatCoord(0,0,1,1), MyGUI::Align::Stretch);
mLogView->setEditReadOnly(true);
mLogCircularBuffer.resize(std::max<int64_t>(0, Settings::Manager::getInt64("log buffer size", "General"))); void DebugWindow::startLogRecording()
Debug::setLogListener([this](Debug::Level level, std::string_view prefix, std::string_view msg)
{ {
if (mLogCircularBuffer.empty()) sLogCircularBuffer.resize(std::max<int64_t>(0, Settings::Manager::getInt64("log buffer size", "General")));
Debug::setLogListener([](Debug::Level level, std::string_view prefix, std::string_view msg)
{
if (sLogCircularBuffer.empty())
return; // Log viewer is disabled. return; // Log viewer is disabled.
std::string_view color; std::string_view color;
switch (level) switch (level)
@ -123,13 +125,13 @@ namespace MWGui
default: color = "#FFFFFF"; default: color = "#FFFFFF";
} }
bool bufferOverflow = false; bool bufferOverflow = false;
const int64_t bufSize = mLogCircularBuffer.size(); const int64_t bufSize = sLogCircularBuffer.size();
auto addChar = [&](char c) auto addChar = [&](char c)
{ {
mLogCircularBuffer[mLogEndIndex++] = c; sLogCircularBuffer[sLogEndIndex++] = c;
if (mLogEndIndex == bufSize) if (sLogEndIndex == bufSize)
mLogEndIndex = 0; sLogEndIndex = 0;
bufferOverflow = bufferOverflow || mLogEndIndex == mLogStartIndex; bufferOverflow = bufferOverflow || sLogEndIndex == sLogStartIndex;
}; };
auto addShieldedStr = [&](std::string_view s) auto addShieldedStr = [&](std::string_view s)
{ {
@ -145,29 +147,29 @@ namespace MWGui
addShieldedStr(prefix); addShieldedStr(prefix);
addShieldedStr(msg); addShieldedStr(msg);
if (bufferOverflow) if (bufferOverflow)
mLogStartIndex = (mLogEndIndex + 1) % bufSize; sLogStartIndex = (sLogEndIndex + 1) % bufSize;
}); });
} }
void DebugWindow::updateLogView() void DebugWindow::updateLogView()
{ {
if (!mLogView || mLogCircularBuffer.empty() || mLogStartIndex == mLogEndIndex) if (!mLogView || sLogCircularBuffer.empty() || sLogStartIndex == sLogEndIndex)
return; return;
if (mLogView->isTextSelection()) if (mLogView->isTextSelection())
return; // Don't change text while player is trying to copy something return; // Don't change text while player is trying to copy something
std::string addition; std::string addition;
const int64_t bufSize = mLogCircularBuffer.size(); const int64_t bufSize = sLogCircularBuffer.size();
{ {
std::unique_lock<std::mutex> lock = Log::lock(); std::unique_lock<std::mutex> lock = Log::lock();
if (mLogStartIndex < mLogEndIndex) if (sLogStartIndex < sLogEndIndex)
addition = std::string(mLogCircularBuffer.data() + mLogStartIndex, mLogEndIndex - mLogStartIndex); addition = std::string(sLogCircularBuffer.data() + sLogStartIndex, sLogEndIndex - sLogStartIndex);
else else
{ {
addition = std::string(mLogCircularBuffer.data() + mLogStartIndex, bufSize - mLogStartIndex); addition = std::string(sLogCircularBuffer.data() + sLogStartIndex, bufSize - sLogStartIndex);
addition.append(mLogCircularBuffer.data(), mLogEndIndex); addition.append(sLogCircularBuffer.data(), sLogEndIndex);
} }
mLogStartIndex = mLogEndIndex; sLogStartIndex = sLogEndIndex;
} }
size_t scrollPos = mLogView->getVScrollPosition(); size_t scrollPos = mLogView->getVScrollPosition();

View File

@ -13,17 +13,19 @@ namespace MWGui
void onFrame(float dt) override; void onFrame(float dt) override;
static void startLogRecording();
private: private:
void initLogView();
void updateLogView(); void updateLogView();
void updateBulletProfile(); void updateBulletProfile();
MyGUI::TabControl* mTabControl; MyGUI::TabControl* mTabControl;
MyGUI::EditBox* mLogView; MyGUI::EditBox* mLogView;
std::vector<char> mLogCircularBuffer;
int64_t mLogStartIndex = 0; static std::vector<char> sLogCircularBuffer;
int64_t mLogEndIndex = 0; static int64_t sLogStartIndex;
static int64_t sLogEndIndex;
MyGUI::EditBox* mBulletProfilerEdit; MyGUI::EditBox* mBulletProfilerEdit;
}; };

View File

@ -35,13 +35,13 @@ namespace Settings
static CategorySettingVector mChangedSettings; static CategorySettingVector mChangedSettings;
///< tracks all the settings that were changed since the last apply() call ///< tracks all the settings that were changed since the last apply() call
void clear(); static void clear();
///< clears all settings and default settings ///< clears all settings and default settings
std::string load(const Files::ConfigurationManager& cfgMgr, bool loadEditorSettings = false); static std::string load(const Files::ConfigurationManager& cfgMgr, bool loadEditorSettings = false);
///< load settings from all active config dirs. Returns the path of the last loaded file. ///< load settings from all active config dirs. Returns the path of the last loaded file.
void saveUser (const std::string& file); static void saveUser (const std::string& file);
///< save user settings to file ///< save user settings to file
static void resetPendingChange(const std::string &setting, const std::string &category); static void resetPendingChange(const std::string &setting, const std::string &category);