From 1033b056afffd929f525f3f5e00d9bf2b8ba9aaa Mon Sep 17 00:00:00 2001 From: omigamedev Date: Thu, 8 Mar 2018 22:37:30 +0100 Subject: [PATCH] set data_path to exe location on Windows because the open file dialog change the working directory, change the render loop to update only in case of an event or the animated or redraw is true --- .gitignore | 1 + engine/app.cpp | 16 ++++++++++++++++ engine/main.cpp | 26 ++++++++------------------ engine/pch.cpp | 1 + engine/pch.h | 3 ++- 5 files changed, 28 insertions(+), 19 deletions(-) diff --git a/.gitignore b/.gitignore index 222af98..f6309c6 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,4 @@ data/brushes data/thumbs PanoPainter.aps panopainter-log.txt +*.pano diff --git a/engine/app.cpp b/engine/app.cpp index 583b3af..ac0498b 100644 --- a/engine/app.cpp +++ b/engine/app.cpp @@ -57,6 +57,22 @@ void App::initLog() NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString* docpath = [paths objectAtIndex:0]; data_path = [docpath cStringUsingEncoding:NSASCIIStringEncoding]; +#elif _WIN32 + //CHAR my_documents[MAX_PATH]; + //HRESULT result = SHGetFolderPathA(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, my_documents); + + //HMODULE hModule = GetModuleHandle(NULL); + //CHAR path[MAX_PATH]; + //GetModuleFileNameA(hModule, path, MAX_PATH); + //CHAR out_drive[MAX_PATH]; + //CHAR out_path[MAX_PATH]; + //_splitpath(path, out_drive, out_path, nullptr, nullptr); + //sprintf_s(path, "%s%s", out_drive, out_path); + //data_path = path; + + CHAR path[MAX_PATH]; + GetCurrentDirectoryA(sizeof(path), path); + data_path = path; #endif LogRemote::I.start(); diff --git a/engine/main.cpp b/engine/main.cpp index a1df199..84f78e2 100644 --- a/engine/main.cpp +++ b/engine/main.cpp @@ -91,9 +91,9 @@ std::string win32_open_file() ofn.lpstrFilter = "Image Files (*.jpg, *.png)\0*.jpg;*.png"; ofn.lpstrFile = fileName; ofn.nMaxFile = MAX_PATH; - ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY; + ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_NOCHANGEDIR; ofn.lpstrDefExt = ""; - ofn.lpstrInitialDir = "Missions\\"; + ofn.lpstrInitialDir = ""; if (GetOpenFileNameA(&ofn) != NULL) { return fileName; @@ -387,26 +387,20 @@ int main(int argc, char** argv) while (running) { // If there any message in the queue process it - if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) + auto present = App::I.animate || App::I.redraw ? + PeekMessage(&msg, 0, 0, 0, PM_REMOVE) : GetMessage(&msg, 0, 0, 0); + + if (present) { running = !(msg.message == WM_QUIT/* || gl.keys[VK_ESCAPE]*/); DispatchMessage(&msg); TranslateMessage(&msg); } - else // Otherwise render next frame + //else // Otherwise render next frame { t1 = GetTickCount(); float dt = (float)(t1 - t0) / 1000.0f; - - // force redraw every one second - one_sec += dt; - if (one_sec > 1.f) - { - one_sec = 0; - App::I.redraw = true; - } - - if (dt > 1.0f / 60.0f) + if (dt > 1.0f / 60.0f || App::I.redraw) { t0 = t1; if (App::I.redraw) @@ -421,10 +415,6 @@ int main(int argc, char** argv) //LOG("swap main"); } } -// else -// { -// Sleep((DWORD)(1.0f / 60.0f * 1000.f)); -// } } } diff --git a/engine/pch.cpp b/engine/pch.cpp index 1a1ebab..f9002de 100644 --- a/engine/pch.cpp +++ b/engine/pch.cpp @@ -15,4 +15,5 @@ #ifdef _WIN32 #pragma comment(lib, "BugTrapU-x64.lib") + #pragma comment(lib, "shell32.lib") #endif // _WIN32 diff --git a/engine/pch.h b/engine/pch.h index 8e46cf1..80573a7 100644 --- a/engine/pch.h +++ b/engine/pch.h @@ -65,7 +65,8 @@ #include #include #include - + #include + #define SHADER_VERSION "#version 150\n" #endif