forked from nijigenerate/nijigenerate
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.d
More file actions
204 lines (173 loc) · 5.73 KB
/
Copy pathapp.d
File metadata and controls
204 lines (173 loc) · 5.73 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/*
Copyright © 2020-2023, Inochi2D Project
Copyright © 2024, nijigenerate Project
Distributed under the 2-Clause BSD License, see LICENSE file.
Authors: Luna Nielsen
*/
//import std.stdio;
import std.string;
import nijigenerate.core;
import nijigenerate.core.settings;
import nijigenerate.utils.crashdump;
import nijigenerate.panels;
import nijigenerate.panels.resource;
import nijigenerate.windows;
import nijigenerate.widgets;
import nijigenerate.widgets.mainmenu;
import nijigenerate.core.actionstack;
import nijigenerate.core.shortcut; // package re-exports base
import nijigenerate.core.shortcut.base : ngLoadShortcutsFromSettings; // load persisted shortcuts
import nijigenerate.core.shortcut.defaults : ngRegisterDefaultShortcuts;
import nijigenerate.commands : ngInitAllCommands; // explicit commands init to avoid ctor cycles
import nijigenerate.core.i18n;
import nijigenerate.io;
import nijigenerate.io.autosave;
import nijigenerate.atlas.atlas : incInitAtlassing;
import nijigenerate.ext;
import nijigenerate.windows.flipconfig;
import nijilive;
import nijilive.core.nodes.common : nlApplyBlendingCapabilities;
import nijigenerate;
version(HaveMCP) import nijigenerate.api.mcp : ngMcpProcessQueue, ngMcpLoadSettings, ngMcpStop;
import nijigenerate.panels.agent : ngAcpStopAll;
import i18n;
version(D_X32) {
pragma(msg, "nijigenerate does not support compilation on 32 bit platforms");
static assert(0, "nijigenerate does not support 32-bit builds.");
}
version(Windows) {
debug {
} else {
version(InLite) {
// Sorry to the programming gods for this crime
// phobos will crash in lite mode if this isn't here.
} else {
version (LDC) {
pragma(linkerDirective, "/SUBSYSTEM:WINDOWS");
static if (__VERSION__ >= 2091)
pragma(linkerDirective, "/ENTRY:wmainCRTStartup");
else
pragma(linkerDirective, "/ENTRY:mainCRTStartup");
}
}
}
}
int main(string[] args)
{
try {
installNativeCrashDumpHandler();
bool backgroundServicesStopped = false;
void stopBackgroundServices() {
if (backgroundServicesStopped) return;
backgroundServicesStopped = true;
version(HaveMCP) ngMcpStop();
ngAcpStopAll();
}
scope(exit) stopBackgroundServices();
incSettingsLoad();
incLocaleInit();
if (incSettingsCanGet("lang")) {
string lang = incSettingsGet!string("lang");
auto entry = incLocaleGetEntryFor(lang);
if (entry !is null) {
i18nLoadLanguage(entry.file);
}
}
inSetUpdateBounds(true);
// Initialize Window and nijilive
incInitPanels();
incActionInit();
incOpenWindow();
bool tripleBufferFallback = incSettingsGet!bool("TripleBufferFallback", nlIsTripleBufferFallbackEnabled());
nlSetTripleBufferFallback(tripleBufferFallback);
nlApplyBlendingCapabilities();
// Initialize node overrides
incInitExt();
incInitFlipConfig();
ngInitResourcePanel();
// Initialize video exporting
incInitVideoExport();
// Initialize atlassing
incInitAtlassing();
// Initialize default post processing shader
inPostProcessingAddBasicLighting();
// Initialize command registries explicitly (avoid module ctor cycles)
ngInitAllCommands();
// Register default shortcuts, then load user overrides from settings
ngRegisterDefaultShortcuts();
ngLoadShortcutsFromSettings();
// Start/stop MCP HTTP server based on persisted settings (single read)
version(HaveMCP) ngMcpLoadSettings();
// Open or create project
if (incSettingsGet!bool("hasDoneQuickSetup", false) && args.length > 1) incOpenProject(args[1]);
else {
incNewProject();
// TODO: Replace with first-time welcome screen
incPushWindow(new WelcomeWindow());
}
version(InNightly) incModalAdd(
new Nagscreen(
_("Warning!"),
_("You're running a nightly build of nijigenerate!\nnijigenerate may crash unexpectedly and you will likely encounter bugs.\nMake sure to save and back up your work often!"),
5
)
);
// Update loop
while(!incIsCloseRequested()) {
incUpdate();
}
incSettingsSave();
stopBackgroundServices();
incFinalize();
} catch(Throwable ex) {
debug {
version(Windows) {
crashdump(ex);
} else {
throw ex;
}
} else {
crashdump(ex);
}
}
return 0;
}
/**
Update
*/
void incUpdate() {
// Update nijilive
incAnimationUpdate();
inUpdate();
incCheckAutosave();
// Begin IMGUI loop
incBeginLoop();
if (incShouldProcess()) {
incHandleShortcuts();
// Process any queued MCP commands on the main thread
version(HaveMCP) ngMcpProcessQueue();
incMainMenu();
incUpdatePanels();
incUpdateWindows();
incStatusUpdate();
}
incEndLoop();
}
/**
Update without any event polling
*/
void incUpdateNoEv() {
// Update nijilive
incAnimationUpdate();
inUpdate();
// Begin IMGUI loop
incBeginLoopNoEv();
if (incShouldProcess()) {
incHandleShortcuts();
incMainMenu();
incUpdatePanels();
incUpdateWindows();
incStatusUpdate();
}
incEndLoop();
}