-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcreator_main.cpp
163 lines (137 loc) · 4.15 KB
/
creator_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
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
#include <vector>
#include "crash.h"
#include "creator_main_window.h"
#include "cursesdef.h"
#include "debug.h"
#include "game.h"
#include "game_ui.h"
#include "input.h"
#include "loading_ui.h"
#include "mapsharing.h"
#include "options.h"
#include "output.h"
#include "path_info.h"
#include "platform_win.h"
#include "rng.h"
#include "string_id.h"
#include "ui.h"
#include "worldfactory.h"
#include <QtWidgets/qapplication.h>
#include <QtCore/QSettings>
#ifdef QT_STATICPLUGIN
#include <QtCore/QtPlugin>
#ifdef _WIN32
Q_IMPORT_PLUGIN( QWindowsIntegrationPlugin );
#endif
#endif
struct MOD_INFORMATION;
using mod_id = string_id<MOD_INFORMATION>;
namespace
{
void exit_handler( int s )
{
const int old_timeout = inp_mngr.get_timeout();
inp_mngr.reset_timeout();
if( s != 2 || query_yn( _( "Really Quit? All unsaved changes will be lost." ) ) ) {
deinitDebug();
int exit_status = 0;
g.reset();
catacurses::endwin();
exit( exit_status );
}
inp_mngr.set_timeout( old_timeout );
}
}
struct cli_opts {
int seed = time( nullptr );
bool verifyexit = false;
bool check_mods = false;
std::string dump;
dump_mode dmode = dump_mode::TSV;
std::vector<std::string> opts;
std::string world; /** if set try to load first save in this world on startup */
};
#if defined(USE_WINMAIN)
int APIENTRY WinMain( HINSTANCE /* hInstance */, HINSTANCE /* hPrevInstance */,
LPSTR /* lpCmdLine */, int /* nCmdShow */ )
{
int argc = __argc;
char **argv = __argv;
#elif defined(__ANDROID__)
extern "C" int SDL_main( int argc, char **argv ) {
#else
int main( int argc, char *argv[] )
{
#endif
init_crash_handlers();
#if defined(__ANDROID__)
// Start the standard output logging redirector
start_logger( "cdda" );
// On Android first launch, we copy all data files from the APK into the app's writeable folder so std::io stuff works.
// Use the external storage so it's publicly modifiable data (so users can mess with installed data, save games etc.)
std::string external_storage_path( SDL_AndroidGetExternalStoragePath() );
if( external_storage_path.back() != '/' ) {
external_storage_path += '/';
}
PATH_INFO::init_base_path( external_storage_path );
#else
// Set default file paths
#if defined(PREFIX)
#define Q(STR) #STR
#define QUOTE(STR) Q(STR)
PATH_INFO::init_base_path( std::string( QUOTE( PREFIX ) ) );
#else
PATH_INFO::init_base_path( "" );
#endif
#endif
#if defined(__ANDROID__)
PATH_INFO::init_user_dir( external_storage_path );
#else
# if defined(USE_HOME_DIR) || defined(USE_XDG_DIR)
PATH_INFO::init_user_dir( "" );
# else
PATH_INFO::init_user_dir( "./" );
# endif
#endif
PATH_INFO::set_standard_filenames();
MAP_SHARING::setDefaults();
QSettings settings( QSettings::IniFormat, QSettings::UserScope,
"CleverRaven", "Cataclysm - DDA" );
cli_opts cli;
rng_set_engine_seed( cli.seed );
g = std::make_unique<game>();
// First load and initialize everything that does not
// depend on the mods.
try {
g->load_static_data();
if( cli.verifyexit ) {
exit_handler( 0 );
}
if( !cli.dump.empty() ) {
init_colors();
exit( g->dump_stats( cli.dump, cli.dmode, cli.opts ) ? 0 : 1 );
}
} catch( const std::exception &err ) {
debugmsg( "%s", err.what() );
exit_handler( -999 );
}
loading_ui ui( false );
get_options().init();
get_options().load();
init_colors();
world_generator = std::make_unique<worldfactory>();
world_generator->init();
std::vector<mod_id> mods;
mods.push_back( mod_id( "dda" ) );
if( settings.contains( "mods/include" ) ) {
QStringList modlist = settings.value( "mods/include" ).value<QStringList>();
for( const QString &i : modlist ) {
mods.push_back( mod_id( i.toStdString() ) );
}
}
world_generator->active_world = world_generator->make_new_world( { mods } );
g->load_core_data( ui );
g->load_world_modfiles( ui );
QApplication app( argc, argv );
creator::main_window().execute( app );
}