mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-21 09:39:56 +00:00
Merge branch 'log_viewer' into 'master'
Initialize in-game log viewer earlier in order not to miss the beginning of the log See merge request OpenMW/openmw!1904
This commit is contained in:
commit
5fe6f6333c
@ -544,15 +544,15 @@ void OMW::Engine::setSkipMenu (bool skipMenu, bool newGame)
|
||||
mNewGame = newGame;
|
||||
}
|
||||
|
||||
void OMW::Engine::createWindow(Settings::Manager& settings)
|
||||
void OMW::Engine::createWindow()
|
||||
{
|
||||
int screen = settings.getInt("screen", "Video");
|
||||
int width = settings.getInt("resolution x", "Video");
|
||||
int height = settings.getInt("resolution y", "Video");
|
||||
int screen = Settings::Manager::getInt("screen", "Video");
|
||||
int width = Settings::Manager::getInt("resolution x", "Video");
|
||||
int height = Settings::Manager::getInt("resolution y", "Video");
|
||||
Settings::WindowMode windowMode = static_cast<Settings::WindowMode>(Settings::Manager::getInt("window mode", "Video"));
|
||||
bool windowBorder = settings.getBool("window border", "Video");
|
||||
bool vsync = settings.getBool("vsync", "Video");
|
||||
unsigned int antialiasing = std::max(0, settings.getInt("antialiasing", "Video"));
|
||||
bool windowBorder = Settings::Manager::getBool("window border", "Video");
|
||||
bool vsync = Settings::Manager::getBool("vsync", "Video");
|
||||
unsigned int antialiasing = std::max(0, Settings::Manager::getInt("antialiasing", "Video"));
|
||||
|
||||
int pos_x = SDL_WINDOWPOS_CENTERED_DISPLAY(screen),
|
||||
pos_y = SDL_WINDOWPOS_CENTERED_DISPLAY(screen);
|
||||
@ -577,7 +577,7 @@ void OMW::Engine::createWindow(Settings::Manager& settings)
|
||||
flags |= SDL_WINDOW_BORDERLESS;
|
||||
|
||||
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_GREEN_SIZE, 8));
|
||||
@ -706,7 +706,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);
|
||||
mEnvironment.setStateManager(*mStateManager);
|
||||
@ -716,7 +716,7 @@ void OMW::Engine::prepareEngine (Settings::Manager & settings)
|
||||
osg::ref_ptr<osg::Group> rootNode(new osg::Group);
|
||||
mViewer->setSceneData(rootNode);
|
||||
|
||||
createWindow(settings);
|
||||
createWindow();
|
||||
|
||||
mVFS = std::make_unique<VFS::Manager>(mFSStrict);
|
||||
|
||||
@ -980,10 +980,6 @@ void OMW::Engine::go()
|
||||
|
||||
Misc::Rng::init(mRandomSeed);
|
||||
|
||||
// Load settings
|
||||
Settings::Manager settings;
|
||||
std::string settingspath = settings.load(mCfgMgr);
|
||||
|
||||
Settings::ShaderManager::get().load((mCfgMgr.getUserConfigPath() / "shaders.yaml").string());
|
||||
|
||||
MWClass::registerClasses();
|
||||
@ -1002,7 +998,7 @@ void OMW::Engine::go()
|
||||
|
||||
mEnvironment.setFrameRateLimit(Settings::Manager::getFloat("framerate limit", "Video"));
|
||||
|
||||
prepareEngine (settings);
|
||||
prepareEngine();
|
||||
|
||||
std::ofstream stats;
|
||||
if (const auto path = std::getenv("OPENMW_OSG_STATS_FILE"))
|
||||
@ -1108,7 +1104,7 @@ void OMW::Engine::go()
|
||||
luaWorker.join();
|
||||
|
||||
// Save user settings
|
||||
settings.saveUser(settingspath);
|
||||
Settings::Manager::saveUser((mCfgMgr.getUserConfigPath() / "settings.cfg").string());
|
||||
Settings::ShaderManager::get().save();
|
||||
mLuaManager->savePermanentStorage(mCfgMgr.getUserConfigPath().string());
|
||||
|
||||
|
@ -181,13 +181,10 @@ namespace OMW
|
||||
|
||||
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
|
||||
void prepareEngine (Settings::Manager & settings);
|
||||
void prepareEngine();
|
||||
|
||||
void createWindow(Settings::Manager& settings);
|
||||
void createWindow();
|
||||
void setWindowIcon();
|
||||
|
||||
public:
|
||||
|
@ -5,6 +5,8 @@
|
||||
#include <components/debug/debugging.hpp>
|
||||
#include <components/misc/rng.hpp>
|
||||
|
||||
#include "mwgui/debugwindow.hpp"
|
||||
|
||||
#include "engine.hpp"
|
||||
#include "options.hpp"
|
||||
|
||||
@ -58,8 +60,10 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat
|
||||
}
|
||||
|
||||
cfgMgr.readConfiguration(variables, desc);
|
||||
Settings::Manager::load(cfgMgr);
|
||||
|
||||
setupLogging(cfgMgr.getLogPath().string(), "OpenMW");
|
||||
MWGui::DebugWindow::startLogRecording();
|
||||
|
||||
Version::Version v = Version::getOpenmwVersion(variables["resources"].as<Files::MaybeQuotedPath>().string());
|
||||
Log(Debug::Info) << v.describe();
|
||||
|
@ -89,7 +89,10 @@ namespace MWGui
|
||||
// - Material 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
|
||||
MyGUI::TabItem* item = mTabControl->addItem("Physics Profiler");
|
||||
@ -100,17 +103,16 @@ namespace MWGui
|
||||
#endif
|
||||
}
|
||||
|
||||
void DebugWindow::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);
|
||||
std::vector<char> DebugWindow::sLogCircularBuffer;
|
||||
int64_t DebugWindow::sLogStartIndex = 0;
|
||||
int64_t DebugWindow::sLogEndIndex = 0;
|
||||
|
||||
mLogCircularBuffer.resize(std::max<int64_t>(0, Settings::Manager::getInt64("log buffer size", "General")));
|
||||
Debug::setLogListener([this](Debug::Level level, std::string_view prefix, std::string_view msg)
|
||||
void DebugWindow::startLogRecording()
|
||||
{
|
||||
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 (mLogCircularBuffer.empty())
|
||||
if (sLogCircularBuffer.empty())
|
||||
return; // Log viewer is disabled.
|
||||
std::string_view color;
|
||||
switch (level)
|
||||
@ -123,13 +125,13 @@ namespace MWGui
|
||||
default: color = "#FFFFFF";
|
||||
}
|
||||
bool bufferOverflow = false;
|
||||
const int64_t bufSize = mLogCircularBuffer.size();
|
||||
const int64_t bufSize = sLogCircularBuffer.size();
|
||||
auto addChar = [&](char c)
|
||||
{
|
||||
mLogCircularBuffer[mLogEndIndex++] = c;
|
||||
if (mLogEndIndex == bufSize)
|
||||
mLogEndIndex = 0;
|
||||
bufferOverflow = bufferOverflow || mLogEndIndex == mLogStartIndex;
|
||||
sLogCircularBuffer[sLogEndIndex++] = c;
|
||||
if (sLogEndIndex == bufSize)
|
||||
sLogEndIndex = 0;
|
||||
bufferOverflow = bufferOverflow || sLogEndIndex == sLogStartIndex;
|
||||
};
|
||||
auto addShieldedStr = [&](std::string_view s)
|
||||
{
|
||||
@ -145,29 +147,29 @@ namespace MWGui
|
||||
addShieldedStr(prefix);
|
||||
addShieldedStr(msg);
|
||||
if (bufferOverflow)
|
||||
mLogStartIndex = (mLogEndIndex + 1) % bufSize;
|
||||
sLogStartIndex = (sLogEndIndex + 1) % bufSize;
|
||||
});
|
||||
}
|
||||
|
||||
void DebugWindow::updateLogView()
|
||||
{
|
||||
if (!mLogView || mLogCircularBuffer.empty() || mLogStartIndex == mLogEndIndex)
|
||||
if (!mLogView || sLogCircularBuffer.empty() || sLogStartIndex == sLogEndIndex)
|
||||
return;
|
||||
if (mLogView->isTextSelection())
|
||||
return; // Don't change text while player is trying to copy something
|
||||
|
||||
std::string addition;
|
||||
const int64_t bufSize = mLogCircularBuffer.size();
|
||||
const int64_t bufSize = sLogCircularBuffer.size();
|
||||
{
|
||||
std::unique_lock<std::mutex> lock = Log::lock();
|
||||
if (mLogStartIndex < mLogEndIndex)
|
||||
addition = std::string(mLogCircularBuffer.data() + mLogStartIndex, mLogEndIndex - mLogStartIndex);
|
||||
if (sLogStartIndex < sLogEndIndex)
|
||||
addition = std::string(sLogCircularBuffer.data() + sLogStartIndex, sLogEndIndex - sLogStartIndex);
|
||||
else
|
||||
{
|
||||
addition = std::string(mLogCircularBuffer.data() + mLogStartIndex, bufSize - mLogStartIndex);
|
||||
addition.append(mLogCircularBuffer.data(), mLogEndIndex);
|
||||
addition = std::string(sLogCircularBuffer.data() + sLogStartIndex, bufSize - sLogStartIndex);
|
||||
addition.append(sLogCircularBuffer.data(), sLogEndIndex);
|
||||
}
|
||||
mLogStartIndex = mLogEndIndex;
|
||||
sLogStartIndex = sLogEndIndex;
|
||||
}
|
||||
|
||||
size_t scrollPos = mLogView->getVScrollPosition();
|
||||
|
@ -13,17 +13,19 @@ namespace MWGui
|
||||
|
||||
void onFrame(float dt) override;
|
||||
|
||||
static void startLogRecording();
|
||||
|
||||
private:
|
||||
void initLogView();
|
||||
void updateLogView();
|
||||
void updateBulletProfile();
|
||||
|
||||
MyGUI::TabControl* mTabControl;
|
||||
|
||||
MyGUI::EditBox* mLogView;
|
||||
std::vector<char> mLogCircularBuffer;
|
||||
int64_t mLogStartIndex = 0;
|
||||
int64_t mLogEndIndex = 0;
|
||||
|
||||
static std::vector<char> sLogCircularBuffer;
|
||||
static int64_t sLogStartIndex;
|
||||
static int64_t sLogEndIndex;
|
||||
|
||||
MyGUI::EditBox* mBulletProfilerEdit;
|
||||
};
|
||||
|
@ -35,13 +35,13 @@ namespace Settings
|
||||
static CategorySettingVector mChangedSettings;
|
||||
///< tracks all the settings that were changed since the last apply() call
|
||||
|
||||
void clear();
|
||||
static void clear();
|
||||
///< 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.
|
||||
|
||||
void saveUser (const std::string& file);
|
||||
static void saveUser (const std::string& file);
|
||||
///< save user settings to file
|
||||
|
||||
static void resetPendingChange(const std::string &setting, const std::string &category);
|
||||
|
Loading…
x
Reference in New Issue
Block a user