Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,4 @@ savgam*.dat
# Eclipse CDT
.project
.cproject
.DS_Store
6 changes: 6 additions & 0 deletions src/GameSrc/setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions src/Libraries/RES/Source/caseless.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <string.h>
#include <stdio.h>
#include <sys/stat.h>
#ifdef __APPLE__
#include <SDL.h>
#endif

#ifndef PATH_MAX
#define PATH_MAX 4096
Expand Down Expand Up @@ -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) {
Expand Down
26 changes: 22 additions & 4 deletions src/MacSrc/OpenGL.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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.");
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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() {
Expand Down
5 changes: 3 additions & 2 deletions src/MacSrc/OpenGL.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ extern "C" {
#endif

#include <3d.h>
#include <SDL.h>

#ifdef USE_OPENGL

Expand All @@ -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);
Expand Down Expand Up @@ -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) {}
Expand Down
24 changes: 13 additions & 11 deletions src/MacSrc/Shock.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
23 changes: 22 additions & 1 deletion src/MusicSrc/MusicDevice.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
# include <sys/types.h>
# include <dirent.h>
#endif
#ifdef __APPLE__
#include <SDL.h>
#endif

//------------------------------------------------------------------------------
// Dummy MIDI player
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)))
{
Expand Down Expand Up @@ -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)))
Expand Down