MCPcopy Create free account
hub / github.com/OpenApoc/OpenApoc / Framework

Method Framework

framework/framework.cpp:113–259  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

111};
112
113Framework::Framework(const UString programName, bool createWindow)
114 : p(new FrameworkPrivate), programName(programName), createWindow(createWindow)
115{
116 LogInfo("Starting framework");
117
118 if (this->instance)
119 {
120 LogError("Multiple Framework instances created");
121 }
122
123 this->instance = this;
124
125#ifdef __APPLE__
126 {
127 // FIXME: A hack to set the working directory to the Resources directory in the app bundle.
128 char *basePath = SDL_GetBasePath();
129 // FIXME: How to check we're being run from the app bundle and not directly from the
130 // terminal? On my testing (macos 10.15.1 19B88) it seems to have a "/" working directory,
131 // which is unlikely in terminal use, so use that?
132 if (fs::current_path() == "/")
133 {
134 LogWarning("Setting working directory to \"%s\"", basePath);
135 chdir(basePath);
136 }
137 else
138 {
139 LogWarning("Leaving default working directory \"%s\"", fs::current_path());
140 }
141 SDL_free(basePath);
142 }
143#endif
144
145 if (!PHYSFS_isInit())
146 {
147 if (PHYSFS_init(programName.c_str()) == 0)
148 {
149 PHYSFS_ErrorCode error = PHYSFS_getLastErrorCode();
150 LogError("Failed to init code %i PHYSFS: %s", (int)error, PHYSFS_getErrorByCode(error));
151 }
152 }
153#ifdef ANDROID
154 SDL_SetHint(SDL_HINT_ANDROID_SEPARATE_MOUSE_AND_TOUCH, "1");
155#endif
156 // Initialize subsystems separately?
157 if (SDL_Init(SDL_INIT_EVENTS | SDL_INIT_TIMER) < 0)
158 {
159 LogError("Cannot init SDL2");
160 LogError("SDL error: %s", SDL_GetError());
161 p->quitProgram = true;
162 return;
163 }
164 if (createWindow)
165 {
166 if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0)
167 {
168 LogError("Cannot init SDL_VIDEO - \"%s\"", SDL_GetError());
169 p->quitProgram = true;
170 return;

Callers

nothing calls this directly

Calls 7

enableFileLoggerFunction · 0.85
dumpOptionsToLogFunction · 0.85
enableSDLDialogLoggerFunction · 0.85
emptyMethod · 0.80
openMethod · 0.80
getMethod · 0.45
resetMethod · 0.45

Tested by

no test coverage detected