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

This commit is contained in:
2018-03-08 22:37:30 +01:00
parent da54181754
commit 1033b056af
5 changed files with 28 additions and 19 deletions

1
.gitignore vendored
View File

@@ -18,3 +18,4 @@ data/brushes
data/thumbs
PanoPainter.aps
panopainter-log.txt
*.pano

View File

@@ -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();

View File

@@ -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));
// }
}
}

View File

@@ -15,4 +15,5 @@
#ifdef _WIN32
#pragma comment(lib, "BugTrapU-x64.lib")
#pragma comment(lib, "shell32.lib")
#endif // _WIN32

View File

@@ -65,7 +65,8 @@
#include <gl\wglew.h>
#include <gl\GL.h>
#include <BugTrap.h>
#include <shlobj.h>
#define SHADER_VERSION "#version 150\n"
#endif