diff --git a/src/Starfighter.cpp b/src/Starfighter.cpp index e579fcb..a80ca1e 100644 --- a/src/Starfighter.cpp +++ b/src/Starfighter.cpp @@ -28,6 +28,23 @@ int main(int argc, char **argv) if (chdir(DATADIR) == -1) printf("Warning: failed to change directory to \"%s\"\n", DATADIR); + + // This makes relative paths work in C++ in Xcode by changing directory to the Resources folder inside the .app bundle +#ifdef __APPLE__ + CFBundleRef mainBundle = CFBundleGetMainBundle(); + CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(mainBundle); + char path[PATH_MAX]; + if (!CFURLGetFileSystemRepresentation(resourcesURL, TRUE, (UInt8 *)path, PATH_MAX)) + { + // error! + } + CFRelease(resourcesURL); + + chdir(path); + printf("Current directory \"%s\"\n", path); +#endif + // ---------------------------------------------------------------------------- + engine_init(); // Must do this first! diff --git a/src/Starfighter.h b/src/Starfighter.h index 9bdbc83..9a2269f 100644 --- a/src/Starfighter.h +++ b/src/Starfighter.h @@ -28,9 +28,16 @@ along with this program. If not, see . #include #include +#ifdef __APPLE__ +#include +#include +#include +#include "CoreFoundation/CoreFoundation.h" +#else #include "SDL.h" #include "SDL_image.h" #include "SDL_mixer.h" +#endif #include "defs.h" #include "structs.h" diff --git a/src/colors.cpp b/src/colors.cpp index 137e1fe..44cb609 100644 --- a/src/colors.cpp +++ b/src/colors.cpp @@ -17,8 +17,6 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#include - #include "Starfighter.h" Uint32 red; diff --git a/src/engine.h b/src/engine.h index 52cc990..e657a04 100644 --- a/src/engine.h +++ b/src/engine.h @@ -20,7 +20,12 @@ along with this program. If not, see . #ifndef GLOBALS_H #define GLOBALS_H +#ifdef __APPLE__ +#include +#else #include "SDL.h" +#endif + #include "defs.h" #include "structs.h" diff --git a/src/renderer.cpp b/src/renderer.cpp index cd46d81..f43db47 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -17,7 +17,12 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +#ifdef __APPLE__ +#include +#else #include "SDL.h" +#endif + #include "screen.h" diff --git a/src/screen.cpp b/src/screen.cpp index c0e44f2..12f3717 100644 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -19,8 +19,6 @@ along with this program. If not, see . #include -#include "SDL.h" - #include "engine.h" #include "gfx.h" #include "structs.h" diff --git a/src/title.cpp b/src/title.cpp index d9d5cb2..a236eed 100644 --- a/src/title.cpp +++ b/src/title.cpp @@ -285,7 +285,7 @@ int doTitle() aliens[i].face = 0; } - sprintf(buildVersion, "Version "VERSION); + sprintf(buildVersion, "Version %s", VERSION ); SDL_Rect optionRec; diff --git a/src/window.cpp b/src/window.cpp index 3a17242..4faefc5 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -17,6 +17,11 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +#ifdef __APPLE__ +#include +#else #include "SDL.h" +#endif + SDL_Window *window;