Source code changes necessary to compile on OS X.

This commit is contained in:
Richard Smith 2016-08-04 16:51:46 +01:00
parent dda76c8fe4
commit 6a165e8f0b
8 changed files with 40 additions and 5 deletions

View File

@ -29,6 +29,23 @@ int main(int argc, char **argv)
if (chdir(DATADIR) == -1) if (chdir(DATADIR) == -1)
printf("Warning: failed to change directory to \"%s\"\n", DATADIR); 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! engine_init(); // Must do this first!
cheatAttempt = false; cheatAttempt = false;

View File

@ -28,9 +28,16 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
#ifdef __APPLE__
#include <SDL2/SDL.h>
#include <SDL2_image/SDL_image.h>
#include <SDL2_mixer/SDL_mixer.h>
#include "CoreFoundation/CoreFoundation.h"
#else
#include "SDL.h" #include "SDL.h"
#include "SDL_image.h" #include "SDL_image.h"
#include "SDL_mixer.h" #include "SDL_mixer.h"
#endif
#include "defs.h" #include "defs.h"
#include "structs.h" #include "structs.h"

View File

@ -17,8 +17,6 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <SDL.h>
#include "Starfighter.h" #include "Starfighter.h"
Uint32 red; Uint32 red;

View File

@ -20,7 +20,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef GLOBALS_H #ifndef GLOBALS_H
#define GLOBALS_H #define GLOBALS_H
#ifdef __APPLE__
#include <SDL2/SDL.h>
#else
#include "SDL.h" #include "SDL.h"
#endif
#include "defs.h" #include "defs.h"
#include "structs.h" #include "structs.h"

View File

@ -17,7 +17,12 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifdef __APPLE__
#include <SDL2/SDL.h>
#else
#include "SDL.h" #include "SDL.h"
#endif
#include "screen.h" #include "screen.h"

View File

@ -19,8 +19,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <stdlib.h> #include <stdlib.h>
#include "SDL.h"
#include "engine.h" #include "engine.h"
#include "gfx.h" #include "gfx.h"
#include "structs.h" #include "structs.h"

View File

@ -285,7 +285,7 @@ int doTitle()
aliens[i].face = 0; aliens[i].face = 0;
} }
sprintf(buildVersion, "Version "VERSION); sprintf(buildVersion, "Version %s", VERSION );
SDL_Rect optionRec; SDL_Rect optionRec;

View File

@ -17,6 +17,11 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifdef __APPLE__
#include <SDL2/SDL.h>
#else
#include "SDL.h" #include "SDL.h"
#endif
SDL_Window *window; SDL_Window *window;