-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
93 lines (71 loc) · 1.81 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <filesystem>
#include "App.h"
#include "AppGui.h"
#include "ConsoleApp.h"
#include "DroppedAssets.h"
#include "Sdl.h"
#ifdef _WIN32
#include <windows.h>
#else
#include <unistd.h>
#endif
ConsoleApp console;
App *g_app;
std::string GetExeDirectory() {
#ifdef _WIN32
wchar_t szPath[MAX_PATH];
GetModuleFileNameW(NULL, szPath, MAX_PATH);
#else
char szPath[4096];
ssize_t count = readlink("/proc/self/exe", szPath, 4096);
if (count < 0 || count >= 4096)
return {};
szPath[count] = '\0';
#endif
return std::filesystem::path{szPath}.parent_path().string();
}
int main(int argv, char **args) {
App app(GetExeDirectory());
app.engine_settings.LoadFromDisk(&app);
app.state = ProjectState(app.engine_settings);
g_app = &app;
Sdl::Init(&app);
app.LoadAssets();
AppGui::ChangeTheme(app, app.engine_settings.GetTheme());
while (app.is_running) {
SDL_Event event;
while (SDL_PollEvent(&event)) {
Sdl::ProcessEvent(&event);
switch (event.type) {
case SDL_QUIT:
app.is_running = false;
break;
case SDL_DROPFILE: {
console.AddLog("Dropped file: %s", event.drop.file);
if (app.project.project_settings.IsOpen()) {
AppGui::ProcessImportFile(app, event.drop.file);
} else {
std::filesystem::path dropped_path(event.drop.file);
if (std::filesystem::is_directory(dropped_path)) {
app.OpenProject(dropped_path.string());
} else if (std::filesystem::is_regular_file(dropped_path)) {
app.OpenProject(dropped_path.parent_path().string());
}
}
} break;
default:
break;
}
}
if (!app.is_running)
break;
Sdl::NewFrame();
AppGui::Update(app);
Sdl::RenderStart(app.renderer);
// render SDL stuff here
Sdl::RenderEnd(app.renderer);
}
app.project.Close(&app);
Sdl::Quit(&app, app.window, app.renderer);
return 0;
}