diff --git a/.gitignore b/.gitignore index 583a1809f..75db28936 100644 --- a/.gitignore +++ b/.gitignore @@ -58,3 +58,4 @@ savgam*.dat # Eclipse CDT .project .cproject +.DS_Store diff --git a/src/GameSrc/setup.c b/src/GameSrc/setup.c index 9fdcc6d4a..f27033a07 100644 --- a/src/GameSrc/setup.c +++ b/src/GameSrc/setup.c @@ -1207,7 +1207,13 @@ errtype load_savegame_names(void) { for (i = 0; i < NUM_SAVE_SLOTS; i++) { Poke_SaveName(i); +#ifdef __APPLE__ + char full_save_game_name[1024]; + sprintf(full_save_game_name, "%s%s", SDL_GetPrefPath("Interrupt", "SystemShock"), save_game_name); + if (access(full_save_game_name, F_OK) != -1) { +#else if (access(save_game_name, F_OK) != -1) { +#endif file = ResOpenFile(save_game_name); if (ResInUse(OLD_SAVE_GAME_ID_BASE)) { #ifdef OLD_SG_FORMAT diff --git a/src/Libraries/RES/Source/caseless.c b/src/Libraries/RES/Source/caseless.c index be1c15368..ca5227f6c 100644 --- a/src/Libraries/RES/Source/caseless.c +++ b/src/Libraries/RES/Source/caseless.c @@ -23,6 +23,9 @@ along with this program. If not, see . #include #include #include +#ifdef __APPLE__ +#include +#endif #ifndef PATH_MAX #define PATH_MAX 4096 @@ -245,7 +248,16 @@ FILE *fopen_caseless(const char *path, const char *mode) { if (path == NULL || mode == NULL) return NULL; +#ifdef __APPLE__ + char *macpath; + const char * prefix = SDL_GetPrefPath("Interrupt", "SystemShock"); + macpath = (char *)malloc(strlen(prefix) + strlen(path) + 1); + strcpy(macpath, prefix); + strcpy(&macpath[strlen(prefix)], path); + ret = fopen(macpath, mode); +#else ret = fopen(path, mode); +#endif #ifndef _WIN32 // not windows if (ret == NULL) { diff --git a/src/MacSrc/OpenGL.cc b/src/MacSrc/OpenGL.cc index cd2777c10..47c185057 100644 --- a/src/MacSrc/OpenGL.cc +++ b/src/MacSrc/OpenGL.cc @@ -184,8 +184,13 @@ static GLuint loadShader(GLenum type, const char *filename) { DEBUG("Loading shader %s", filename); +#ifdef __APPLE__ + char fb[1024]; + sprintf(fb, "%s/shaders/%s", SDL_GetBasePath(), filename); +#else char fb[256]; sprintf(fb, "shaders/%s", filename); +#endif FILE *file = fopen(fb, "r"); if (file == nullptr) { @@ -294,6 +299,7 @@ int init_opengl() { } // Can we create the world rendering context? + SDL_GL_SetAttribute(SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1); context = SDL_GL_CreateContext(window); if (context == nullptr) { ERROR("Could not create an OpenGL context! Falling back to Software mode."); @@ -444,21 +450,21 @@ void get_hdpi_scaling(int *x_scale, int *y_scale) { *y_scale = output_height / screen_height; } -void opengl_swap_and_restore() { +void opengl_swap_and_restore(SDL_Surface *ui) { // restore the view backup (without HUD overlay) for incremental // updates in the subsequent frame SDL_GL_MakeCurrent(window, context); - SDL_GL_SwapWindow(window); - glClear(GL_COLOR_BUFFER_BIT); int x_hdpi_scale, y_hdpi_scale; get_hdpi_scaling(&x_hdpi_scale, &y_hdpi_scale); + // Set the drawable area for the 3d view glViewport(phys_offset_x * x_hdpi_scale, phys_offset_y * y_hdpi_scale, phys_width * x_hdpi_scale, phys_height * y_hdpi_scale); set_blend_mode(false); + // Bind and setup our general shader program glUseProgram(textureShaderProgram.shaderProgram); GLint tcAttrib = textureShaderProgram.tcAttrib; GLint lightAttrib = textureShaderProgram.lightAttrib; @@ -468,6 +474,7 @@ void opengl_swap_and_restore() { glUniformMatrix4fv(textureShaderProgram.uniView, 1, false, IdentityMatrix); glUniformMatrix4fv(textureShaderProgram.uniProj, 1, false, IdentityMatrix); + // Draw the frame buffer to the screen as a quad bind_texture(backupBuffer.texture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); @@ -487,14 +494,25 @@ void opengl_swap_and_restore() { glVertex3f(-1.0f, 1.0f, 0.0f); glEnd(); + // Finish drawing the 3d view glFlush(); glUniform1i(textureShaderProgram.uniNightSight, false); - // check OpenGL error + // Check for OpenGL errors that might have happened GLenum err = glGetError(); if (err != GL_NO_ERROR) ERROR("OpenGL error: %i", err); + + // Blit the UI canvas over the 3d view + SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer, ui); + SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND); + + SDL_RenderCopy(renderer, texture, NULL, NULL); + SDL_DestroyTexture(texture); + + // Finally, swap to the screen + SDL_RenderPresent(renderer); } void toggle_opengl() { diff --git a/src/MacSrc/OpenGL.h b/src/MacSrc/OpenGL.h index bcab1b8e5..b11c89364 100644 --- a/src/MacSrc/OpenGL.h +++ b/src/MacSrc/OpenGL.h @@ -6,6 +6,7 @@ extern "C" { #endif #include <3d.h> +#include #ifdef USE_OPENGL @@ -18,7 +19,7 @@ bool use_opengl(); void toggle_opengl(); void opengl_resize(int width, int height); bool should_opengl_swap(); -void opengl_swap_and_restore(); +void opengl_swap_and_restore(SDL_Surface *ui); void opengl_change_palette(); void opengl_set_viewport(int x, int y, int width, int height); @@ -46,7 +47,7 @@ static bool use_opengl() { return false; } static void toggle_opengl() {} static void opengl_resize(int width, int height) {} static bool should_opengl_swap() { return false; } -static void opengl_swap_and_restore() {} +static void opengl_swap_and_restore(SDL_Surface *ui) {} static void opengl_change_palette() {} static void opengl_set_viewport(int x, int y, int width, int height) {} diff --git a/src/MacSrc/Shock.c b/src/MacSrc/Shock.c index 973f9d726..7b3f9099b 100644 --- a/src/MacSrc/Shock.c +++ b/src/MacSrc/Shock.c @@ -232,7 +232,7 @@ void SetSDLPalette(int index, int count, uchar *pal) { static bool gammalut_init = 0; static uchar gammalut[100 - 10 + 1][256]; if (!gammalut_init) { - double factor = (can_use_opengl() ? 1.0 : 2.2); // OpenGL uses 2.2 + double factor = (use_opengl() ? 1.0 : 2.2); // OpenGL uses 2.2 int i, j; for (i = 10; i <= 100; i++) { double gamma = (double)i * 1.0 / 100; @@ -279,26 +279,28 @@ void SetSDLPalette(int index, int count, uchar *pal) { void SDLDraw() { if (should_opengl_swap()) { + // We want the UI background to be transparent! sdlPalette->colors[255].a = 0x00; - } - SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer, drawSurface); + // Draw the OpenGL view + opengl_swap_and_restore(drawSurface); - if (should_opengl_swap()) { + // Set the palette back, and we are done sdlPalette->colors[255].a = 0xff; - SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND); + return; } + // Clear the screen! + SDL_RenderClear(renderer); + SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer, drawSurface); + + // Blit to the screen by drawing the surface SDL_Rect srcRect = {0, 0, gScreenWide, gScreenHigh}; SDL_RenderCopy(renderer, texture, &srcRect, NULL); SDL_DestroyTexture(texture); - if (should_opengl_swap()) { - opengl_swap_and_restore(); - } else { - SDL_RenderPresent(renderer); - SDL_RenderClear(renderer); - } + // Show everything we've drawn + SDL_RenderPresent(renderer); } bool MouseCaptured = FALSE; diff --git a/src/MusicSrc/MusicDevice.c b/src/MusicSrc/MusicDevice.c index 84a70f619..8519229ae 100644 --- a/src/MusicSrc/MusicDevice.c +++ b/src/MusicSrc/MusicDevice.c @@ -18,6 +18,9 @@ # include # include #endif +#ifdef __APPLE__ +#include +#endif //------------------------------------------------------------------------------ // Dummy MIDI player @@ -1023,9 +1026,15 @@ static int FluidMidiInit(MusicDevice *dev, const unsigned int outputIndex, unsig fluid_settings_t *settings; fluid_synth_t *synth; int sfid; - char fileName[1024] = "res/"; +#ifdef __APPLE__ + char fileName[1024] = ""; + sprintf(fileName, "%sres/", SDL_GetBasePath()); + FluidMidiGetOutputName(dev, outputIndex, &fileName[strlen(fileName)], 1024 - strlen(fileName)); +#else + char fileName[1024] = "res/"; FluidMidiGetOutputName(dev, outputIndex, &fileName[4], 1020); +#endif if (strlen(fileName) == 4) { WARN("Failed to locate SoundFont for outputIndex=%d", outputIndex); @@ -1183,8 +1192,14 @@ static unsigned int FluidMidiGetOutputCount(MusicDevice *dev) do { ++outputCount; } while (FindNextFile(hFind, &data)); FindClose(hFind); } +#else +#ifdef __APPLE__ + char *respath[1024]; + sprintf(respath, "%sres/", SDL_GetBasePath()); + DIR *dirp = opendir(respath); #else DIR *dirp = opendir("res"); +#endif struct dirent *dp = 0; while ((dp = readdir(dirp))) { @@ -1237,7 +1252,13 @@ static void FluidMidiGetOutputName(MusicDevice *dev, const unsigned int outputIn unsigned int outputCount = 0; // subtract 1 to get index // count .sf2 files in res/ subdirectory until we find the one that the user // probably wants +#ifdef __APPLE__ + char *respath[1024]; + sprintf(respath, "%sres/", SDL_GetBasePath()); + DIR *dirp = opendir(respath); +#else DIR *dirp = opendir("res"); +#endif struct dirent *dp = 0; while ((outputCount <= outputIndex) && (dp = readdir(dirp)))