/
RadiantModule.cpp
335 lines (258 loc) · 8.96 KB
/
RadiantModule.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
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
#include "RadiantModule.h"
#include "RadiantThreadManager.h"
#include <iostream>
#include <ctime>
#include "ifiletypes.h"
#include "iregistry.h"
#include "icommandsystem.h"
#include "itextstream.h"
#include "ifilesystem.h"
#include "iuimanager.h"
#include "ieclass.h"
#include "ipreferencesystem.h"
#include "ieventmanager.h"
#include "iclipper.h"
#include "i18n.h"
#include "imainframe.h"
#include "scene/Node.h"
#include "map/PointFile.h"
#include "ui/texturebrowser/TextureBrowser.h"
#include "ui/mediabrowser/MediaBrowser.h"
#include "ui/mainframe/ScreenUpdateBlocker.h"
#include "textool/TexTool.h"
#include "ui/overlay/OverlayDialog.h"
#include "ui/prefdialog/PrefDialog.h"
#include "ui/splash/Splash.h"
#include "wxutil/FileChooser.h"
#include "ui/mru/MRU.h"
#include "map/Map.h"
#include "wxutil/MultiMonitor.h"
#include "brush/csg/CSG.h"
#include "modulesystem/StaticModule.h"
#include "selection/algorithm/General.h"
#include "log/Console.h"
#include "ui/lightinspector/LightInspector.h"
#include "ui/patch/PatchInspector.h"
#include "ui/surfaceinspector/SurfaceInspector.h"
#include "ui/transform/TransformDialog.h"
#include "ui/mapinfo/MapInfoDialog.h"
#include "ui/layers/LayerControlDialog.h"
#include "ui/commandlist/CommandList.h"
#include "ui/findshader/FindShader.h"
#include "ui/filterdialog/FilterDialog.h"
#include "ui/mousetool/ToolMappingDialog.h"
#include "ui/about/AboutDialog.h"
#include "map/FindMapElements.h"
#include "ui/modelselector/ModelSelector.h"
#include "EventRateLimiter.h"
#include "selection/shaderclipboard/ShaderClipboard.h"
#include <wx/app.h>
namespace radiant
{
sigc::signal<void> RadiantModule::signal_radiantStarted() const
{
return _radiantStarted;
}
sigc::signal<void> RadiantModule::signal_radiantShutdown() const
{
return _radiantShutdown;
}
ThreadManager& RadiantModule::getThreadManager()
{
if (!_threadManager)
{
_threadManager.reset(new RadiantThreadManager);
}
return *_threadManager;
}
namespace
{
class LongRunningOperation :
public ILongRunningOperation,
private ui::ScreenUpdateBlocker
{
private:
bool _messageChanged;
std::string _message;
public:
LongRunningOperation(const std::string& title, const std::string& message) :
ScreenUpdateBlocker(title, message),
_messageChanged(true),
_message(message)
{}
void pulse()
{
ScreenUpdateBlocker::pulse();
}
void setProgress(float progress)
{
ScreenUpdateBlocker::setProgress(progress);
}
// Set the message that is displayed to the user
void setMessage(const std::string& message)
{
_message = message;
_messageChanged = true;
}
bool messageChanged()
{
return _messageChanged;
}
void dispatch()
{
_messageChanged = false;
ScreenUpdateBlocker::setMessage(_message);
}
};
}
void RadiantModule::performLongRunningOperation(
const std::function<void(ILongRunningOperation&)>& operationFunc,
const std::string& message)
{
LongRunningOperation operation(_("Processing..."), message);
std::size_t threadId = getThreadManager().execute([&]()
{
operationFunc(operation);
});
while (getThreadManager().threadIsRunning(threadId))
{
operation.pulse();
if (operation.messageChanged())
{
operation.dispatch();
}
wxTheApp->Yield();
wxThread::Sleep(15); // sleep for a few ms, then ask again
}
GlobalMainFrame().updateAllWindows();
}
void RadiantModule::broadcastShutdownEvent()
{
_threadManager.reset();
_radiantShutdown.emit();
_radiantShutdown.clear();
}
// Broadcasts a "startup" event to all the listeners
void RadiantModule::broadcastStartupEvent()
{
_radiantStarted.emit();
}
// RegisterableModule implementation
const std::string& RadiantModule::getName() const
{
static std::string _name(MODULE_RADIANT);
return _name;
}
const StringSet& RadiantModule::getDependencies() const
{
static StringSet _dependencies;
if (_dependencies.empty())
{
_dependencies.insert(MODULE_COMMANDSYSTEM);
_dependencies.insert(MODULE_XMLREGISTRY);
_dependencies.insert(MODULE_PREFERENCESYSTEM);
_dependencies.insert(MODULE_EVENTMANAGER);
_dependencies.insert(MODULE_SELECTIONSYSTEM);
_dependencies.insert(MODULE_RENDERSYSTEM);
_dependencies.insert(MODULE_CLIPPER);
}
return _dependencies;
}
void RadiantModule::initialiseModule(const ApplicationContext& ctx)
{
rMessage() << "RadiantModule::initialiseModule called." << std::endl;
// Reset the node id count
scene::Node::resetIds();
map::PointFile::Instance().registerCommands();
registerUICommands();
ui::TexTool::registerCommands();
selection::algorithm::registerCommands();
brush::algorithm::registerCommands();
GlobalCommandSystem().addCommand("Exit", exitCmd);
GlobalEventManager().addCommand("Exit", "Exit");
// Subscribe for the post-module init event
module::GlobalModuleRegistry().signal_allModulesInitialised().connect(
sigc::mem_fun(this, &RadiantModule::postModuleInitialisation));
}
void RadiantModule::shutdownModule()
{
rMessage() << "RadiantModule::shutdownModule called." << std::endl;
GlobalFileSystem().shutdown();
map::PointFile::Instance().destroy();
_radiantShutdown.clear();
}
void RadiantModule::postModuleInitialisation()
{
// Create the empty Settings node and set the title to empty.
GlobalPreferenceSystem().getPage(_("Game"));
IPreferencePage& settingsPage = GlobalPreferenceSystem().getPage(_("Settings"));
settingsPage.setTitle("");
// Construct the MRU commands and menu structure, load the recently used files
GlobalMRU().initialise();
wxutil::MultiMonitor::printMonitorInfo();
// Initialise the mediabrowser
ui::MediaBrowser::init();
// Initialise the mainframe
GlobalMainFrame().construct();
// Initialise the shaderclipboard
GlobalShaderClipboard().clear();
// Broadcast the startup event
broadcastStartupEvent();
// Load the shortcuts from the registry
GlobalEventManager().loadAccelerators();
// Pre-load models
ui::ModelSelector::Populate();
// Show the top level window as late as possible
GlobalMainFrame().getWxTopLevelWindow()->Show();
time_t localtime;
time(&localtime);
rMessage() << "Startup complete at " << ctime(&localtime) << std::endl;
}
void RadiantModule::registerUICommands()
{
GlobalCommandSystem().addCommand("ProjectSettings", ui::PrefDialog::ShowProjectSettings);
GlobalCommandSystem().addCommand("Preferences", ui::PrefDialog::ShowPrefDialog);
GlobalCommandSystem().addCommand("ToggleConsole", ui::Console::toggle);
GlobalCommandSystem().addCommand("ToggleLightInspector", ui::LightInspector::toggleInspector);
GlobalCommandSystem().addCommand("SurfaceInspector", ui::SurfaceInspector::toggle);
GlobalCommandSystem().addCommand("PatchInspector", ui::PatchInspector::toggle);
GlobalCommandSystem().addCommand("OverlayDialog", ui::OverlayDialog::toggle);
GlobalCommandSystem().addCommand("TransformDialog", ui::TransformDialog::toggle);
GlobalCommandSystem().addCommand("FindBrush", DoFind);
GlobalCommandSystem().addCommand("MapInfo", ui::MapInfoDialog::ShowDialog);
GlobalCommandSystem().addCommand("EditFiltersDialog", ui::FilterDialog::ShowDialog);
GlobalCommandSystem().addCommand("MouseToolMappingDialog", ui::ToolMappingDialog::ShowDialog);
GlobalCommandSystem().addCommand("FindReplaceTextures", ui::FindAndReplaceShader::ShowDialog);
GlobalCommandSystem().addCommand("ShowCommandList", ui::CommandList::ShowDialog);
GlobalCommandSystem().addCommand("About", ui::AboutDialog::showDialog);
// ----------------------- Bind Events ---------------------------------------
GlobalEventManager().addCommand("ProjectSettings", "ProjectSettings");
GlobalEventManager().addCommand("Preferences", "Preferences");
GlobalEventManager().addCommand("ToggleConsole", "ToggleConsole");
GlobalEventManager().addCommand("ToggleLightInspector", "ToggleLightInspector");
GlobalEventManager().addCommand("SurfaceInspector", "SurfaceInspector");
GlobalEventManager().addCommand("PatchInspector", "PatchInspector");
GlobalEventManager().addCommand("OverlayDialog", "OverlayDialog");
GlobalEventManager().addCommand("TransformDialog", "TransformDialog");
GlobalEventManager().addCommand("FindBrush", "FindBrush");
GlobalEventManager().addCommand("MapInfo", "MapInfo");
GlobalEventManager().addCommand("EditFiltersDialog", "EditFiltersDialog");
GlobalEventManager().addCommand("MouseToolMappingDialog", "MouseToolMappingDialog");
GlobalEventManager().addCommand("FindReplaceTextures", "FindReplaceTextures");
GlobalEventManager().addCommand("ShowCommandList", "ShowCommandList");
GlobalEventManager().addCommand("About", "About");
}
void RadiantModule::exitCmd(const cmd::ArgumentList& args)
{
// Just tell the main application window to close, which will invoke
// appropriate event handlers.
GlobalMainFrame().getWxTopLevelWindow()->Close(false /* don't force */);
}
// Define the static Radiant module
module::StaticModule<RadiantModule> radiantCoreModule;
// Return the static Radiant module to other code within the main binary
RadiantModulePtr getGlobalRadiant()
{
return radiantCoreModule.getModule();
}
} // namespace radiant