Fix editor scene persistence and XC scene workflow
This commit is contained in:
@@ -8,15 +8,69 @@
|
||||
#include <imgui_impl_win32.h>
|
||||
#include <imgui_impl_dx12.h>
|
||||
#include <imgui_internal.h>
|
||||
#include <filesystem>
|
||||
#include <stdio.h>
|
||||
#include <windows.h>
|
||||
#include <string>
|
||||
|
||||
extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
|
||||
|
||||
namespace {
|
||||
|
||||
std::string WideToUtf8(const std::wstring& value) {
|
||||
if (value.empty()) {
|
||||
return {};
|
||||
}
|
||||
|
||||
int len = WideCharToMultiByte(CP_UTF8, 0, value.c_str(), -1, nullptr, 0, nullptr, nullptr);
|
||||
if (len <= 0) {
|
||||
return {};
|
||||
}
|
||||
|
||||
std::string result(len - 1, '\0');
|
||||
WideCharToMultiByte(CP_UTF8, 0, value.c_str(), -1, &result[0], len, nullptr, nullptr);
|
||||
return result;
|
||||
}
|
||||
|
||||
std::wstring Utf8ToWide(const std::string& value) {
|
||||
if (value.empty()) {
|
||||
return {};
|
||||
}
|
||||
|
||||
int len = MultiByteToWideChar(CP_UTF8, 0, value.c_str(), -1, nullptr, 0);
|
||||
if (len <= 0) {
|
||||
return {};
|
||||
}
|
||||
|
||||
std::wstring result(len - 1, L'\0');
|
||||
MultiByteToWideChar(CP_UTF8, 0, value.c_str(), -1, &result[0], len);
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string GetExecutableDirectoryUtf8() {
|
||||
wchar_t exePath[MAX_PATH];
|
||||
GetModuleFileNameW(nullptr, exePath, MAX_PATH);
|
||||
|
||||
std::wstring exeDirW(exePath);
|
||||
const size_t pos = exeDirW.find_last_of(L"\\/");
|
||||
if (pos != std::wstring::npos) {
|
||||
exeDirW = exeDirW.substr(0, pos);
|
||||
}
|
||||
|
||||
return WideToUtf8(exeDirW);
|
||||
}
|
||||
|
||||
std::string GetExecutableLogPath(const char* fileName) {
|
||||
return GetExecutableDirectoryUtf8() + "\\" + fileName;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
static LONG WINAPI GlobalExceptionFilter(EXCEPTION_POINTERS* exceptionPointers) {
|
||||
const char* logPath = "D:\\Xuanchi\\Main\\XCEngine\\editor\\bin\\Release\\crash.log";
|
||||
|
||||
FILE* f = fopen(logPath, "a");
|
||||
const std::string logPath = GetExecutableLogPath("crash.log");
|
||||
|
||||
FILE* f = nullptr;
|
||||
fopen_s(&f, logPath.c_str(), "a");
|
||||
if (f) {
|
||||
fprintf(f, "[CRASH] ExceptionCode=0x%08X, Address=0x%p\n",
|
||||
exceptionPointers->ExceptionRecord->ExceptionCode,
|
||||
@@ -45,20 +99,7 @@ bool Application::Initialize(HWND hwnd) {
|
||||
|
||||
// Redirect stderr to log file to capture ImGui errors
|
||||
{
|
||||
wchar_t exePath[MAX_PATH];
|
||||
GetModuleFileNameW(nullptr, exePath, MAX_PATH);
|
||||
std::wstring exeDirW(exePath);
|
||||
size_t pos = exeDirW.find_last_of(L"\\/");
|
||||
if (pos != std::wstring::npos) {
|
||||
exeDirW = exeDirW.substr(0, pos);
|
||||
}
|
||||
std::string exeDir;
|
||||
int len = WideCharToMultiByte(CP_UTF8, 0, exeDirW.c_str(), -1, nullptr, 0, nullptr, nullptr);
|
||||
if (len > 0) {
|
||||
exeDir.resize(len - 1);
|
||||
WideCharToMultiByte(CP_UTF8, 0, exeDirW.c_str(), -1, &exeDir[0], len, nullptr, nullptr);
|
||||
}
|
||||
std::string stderrPath = exeDir + "\\stderr.log";
|
||||
const std::string stderrPath = GetExecutableLogPath("stderr.log");
|
||||
freopen(stderrPath.c_str(), "w", stderr);
|
||||
|
||||
fprintf(stderr, "[TEST] stderr redirection test - this should appear in stderr.log\n");
|
||||
@@ -70,19 +111,7 @@ bool Application::Initialize(HWND hwnd) {
|
||||
Debug::Logger::Get().AddSink(std::make_unique<Debug::EditorConsoleSink>());
|
||||
|
||||
// Get exe directory for log file path
|
||||
wchar_t exePath[MAX_PATH];
|
||||
GetModuleFileNameW(nullptr, exePath, MAX_PATH);
|
||||
std::wstring exeDirW(exePath);
|
||||
size_t pos = exeDirW.find_last_of(L"\\/");
|
||||
if (pos != std::wstring::npos) {
|
||||
exeDirW = exeDirW.substr(0, pos);
|
||||
}
|
||||
std::string exeDir;
|
||||
int len = WideCharToMultiByte(CP_UTF8, 0, exeDirW.c_str(), -1, nullptr, 0, nullptr, nullptr);
|
||||
if (len > 0) {
|
||||
exeDir.resize(len - 1);
|
||||
WideCharToMultiByte(CP_UTF8, 0, exeDirW.c_str(), -1, &exeDir[0], len, nullptr, nullptr);
|
||||
}
|
||||
const std::string exeDir = GetExecutableDirectoryUtf8();
|
||||
std::string logPath = exeDir + "\\editor.log";
|
||||
Debug::Logger::Get().AddSink(std::make_unique<Debug::FileLogSink>(logPath.c_str()));
|
||||
Debug::Logger::Get().Info(Debug::LogCategory::General, "Editor Application starting...");
|
||||
@@ -154,6 +183,7 @@ void Application::Render() {
|
||||
ImGui::NewFrame();
|
||||
|
||||
m_layerStack.onImGuiRender();
|
||||
UpdateWindowTitle();
|
||||
|
||||
ImGui::Render();
|
||||
|
||||
@@ -198,6 +228,34 @@ void Application::Render() {
|
||||
}
|
||||
}
|
||||
|
||||
void Application::UpdateWindowTitle() {
|
||||
if (!m_hwnd || !m_editorContext) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto& sceneManager = m_editorContext->GetSceneManager();
|
||||
std::string sceneName = sceneManager.HasActiveScene() ? sceneManager.GetCurrentSceneName() : "No Scene";
|
||||
if (sceneName.empty()) {
|
||||
sceneName = "Untitled Scene";
|
||||
}
|
||||
|
||||
if (sceneManager.IsSceneDirty()) {
|
||||
sceneName += " *";
|
||||
}
|
||||
if (sceneManager.GetCurrentScenePath().empty()) {
|
||||
sceneName += " (Unsaved)";
|
||||
} else {
|
||||
sceneName += " - ";
|
||||
sceneName += std::filesystem::path(sceneManager.GetCurrentScenePath()).filename().string();
|
||||
}
|
||||
|
||||
const std::wstring title = Utf8ToWide(sceneName + " - XCVolumeRenderer - Unity Style Editor");
|
||||
if (title != m_lastWindowTitle) {
|
||||
SetWindowTextW(m_hwnd, title.c_str());
|
||||
m_lastWindowTitle = title;
|
||||
}
|
||||
}
|
||||
|
||||
void Application::OnResize(int width, int height) {
|
||||
if (width <= 0 || height <= 0) return;
|
||||
|
||||
@@ -303,4 +361,4 @@ void Application::CleanupRenderTarget() {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user