Skip to content
Open
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
8 changes: 7 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ feature_summary(WHAT DISABLED_FEATURES DESCRIPTION "Disabled features:")
add_subdirectory(src/Libraries/)

set(MAC_SRC
src/MacSrc/SDLFunctions.c
src/MacSrc/ShockBitmap.c
src/MacSrc/InitMac.c
src/MacSrc/Shock.c
src/MacSrc/Prefs.c
src/MacSrc/MacTune.c
src/MacSrc/SDLSound.c
Expand Down Expand Up @@ -275,6 +275,10 @@ set(GAME_SRC
src/GameSrc/mouselook.c
)

set(SHOCK_SRC
src/ShockSrc/Shock.cpp
)

include_directories(
src/Libraries/2D/Source
src/Libraries/3D/Source
Expand All @@ -297,6 +301,7 @@ include_directories(
src/GameSrc/Headers
src/MacSrc
src/MusicSrc
src/ShockSrc
${CMAKE_BINARY_DIR}/src/GameSrc/Headers
)

Expand Down Expand Up @@ -381,6 +386,7 @@ add_definitions(

add_executable(systemshock
${MAC_SRC}
${SHOCK_SRC}
)

add_library(GAME_LIB ${GAME_SRC})
Expand Down
2 changes: 1 addition & 1 deletion src/GameSrc/Headers/init.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ extern grs_bitmap material_maps[MAX_MATERIALS];
extern void init_all(void);
extern void free_all(void);
extern uchar ppall[]; // pointer to main shadow palette

errtype load_da_palette(void);
void object_data_flush(void);
errtype object_data_load(void);
extern uchar objdata_loaded;
Expand Down
1 change: 0 additions & 1 deletion src/GameSrc/damage.c
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,6 @@ int shield_absorb_damage(int damage, ubyte ub, byte shield_absorb, ubyte shield_

uchar alternate_death = FALSE;
extern bool gPlayingGame;
extern bool gDeadPlayerQuit;

// kill_player()
// kills the player, checks for traps and stuff, so on
Expand Down
1 change: 0 additions & 1 deletion src/GameSrc/trigger.c
Original file line number Diff line number Diff line change
Expand Up @@ -1192,7 +1192,6 @@ extern uchar alternate_death;

extern bool gPlayingGame;
extern bool gDeadPlayerQuit;
extern bool gGameCompletedQuit;

errtype trap_cutscene_func(int p1, int p2, int p3, int p4) {
short cs = qdata_get(p1);
Expand Down
24 changes: 12 additions & 12 deletions src/MacSrc/InitMac.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// Prototypes
//--------------------
void InitMac(void);
void FailNIL(void *);
//void FailNIL(void *);
// Handle GetResourceFail(long id, short num);
void CheckConfig(void);
void ErrorDie(short stringnum);
//void CheckConfig(void);
//void ErrorDie(short stringnum);
void CleanupAndExit(void);
void SetupWindows(WindowPtr *mainWind);
void SetUpMenus(MenuHandle *theMenus, short numMenus);
void StringAlert(short stringnum);
void GetFolders(void);
//void SetupWindows(WindowPtr *mainWind);
//void SetUpMenus(MenuHandle *theMenus, short numMenus);
//void StringAlert(short stringnum);
//void GetFolders(void);
void InstallShockTimers(void);
void RemoveShockTimers(void);
void StartShockTimer(void);
void StopShockTimer(void);
void HideMenuBar(void);
void ShowMenuBar(void);
//void RemoveShockTimers(void);
//void StartShockTimer(void);
//void StopShockTimer(void);
//void HideMenuBar(void);
//void ShowMenuBar(void);
4 changes: 4 additions & 0 deletions src/MacSrc/Prefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ void SetDefaultPrefs(void);
int16_t LoadPrefs(void);
int16_t SavePrefs(void);

void CreateDefaultKeybindsFile(void);
void LoadHotkeyKeybinds(void);
void LoadMoveKeybinds(void);

//-------------------
// Enums
//-------------------
Expand Down
201 changes: 201 additions & 0 deletions src/MacSrc/SDLFunctions.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
/*

Copyright (C) 2015-2018 Night Dive Studios, LLC.
Copyright (C) 2018-2020 Shockolate project

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.

*/

#include <SDL.h>
#include "shockolate_version.h"
#include "InitMac.h"
#include "OpenGL.h"
#include "Prefs.h"
#include "ShockBitmap.h"
#include "Shock.h"
#include "ShockHelp.h"

#include "amaploop.h"
#include "map.h"
#include "gr2ss.h"
#include "frflags.h"
#include "version.h"


SDL_AudioDeviceID device;
SDL_Color gamePalette[256];
SDL_Palette *sdlPalette;
SDL_Renderer *renderer;
SDL_Window *window;

bool UseCutscenePalette = FALSE; // see cutsloop.c
bool MouseCaptured = FALSE;
char window_title[128];

extern grs_screen *svga_screen;
extern int mlook_enabled;

void InitSDL() {
SDL_SetHint(SDL_HINT_NO_SIGNAL_HANDLERS, "1");
SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengl");
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_AUDIO) < 0) {
DEBUG("%s: Init failed", __FUNCTION__);
}

// TODO: figure out some universal set of settings that work...
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32);

gr_init();

extern short svga_mode_data[];
gr_set_mode(svga_mode_data[gShockPrefs.doVideoMode], TRUE);

INFO("Setting up screen and render contexts");

// Create a canvas to draw to

SetupOffscreenBitmaps(grd_cap->w, grd_cap->h);

// Open our window!

sprintf(window_title, "System Shock - %s", SHOCKOLATE_VERSION);

window = SDL_CreateWindow(window_title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, grd_cap->w, grd_cap->h,
SDL_WINDOW_HIDDEN | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_OPENGL);

// Create the palette

sdlPalette = SDL_AllocPalette(256);

// Setup the screen

svga_screen = cit_screen = gr_alloc_screen(grd_cap->w, grd_cap->h);
gr_set_screen(svga_screen);

gr_alloc_ipal();

SDL_ShowCursor(SDL_DISABLE);

atexit(SDL_Quit);

SDL_RaiseWindow(window);

renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_PRESENTVSYNC);
SDL_RenderSetLogicalSize(renderer, grd_cap->w, grd_cap->h);

// Startup OpenGL

init_opengl();

SDLDraw();

SDL_ShowWindow(window);
}

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
int i, j;
for (i = 10; i <= 100; i++) {
double gamma = (double)i * 1.0 / 100;
gamma = 1 - gamma;
gamma *= gamma;
gamma = 1 - gamma;
gamma = 1 / (gamma * factor);
for (j = 0; j < 256; j++)
gammalut[i - 10][j] = (uchar)(pow((double)j / 255, gamma) * 255);
}
gammalut_init = 1;
INFO("Gamma LUT init\'ed");
}

int gam = gShockPrefs.doGamma;
if (gam < 10)
gam = 10;
if (gam > 100)
gam = 100;
gam -= 10;

for (int i = index; i < index + count; i++) {
gamePalette[i].r = gammalut[gam][*pal++];
gamePalette[i].g = gammalut[gam][*pal++];
gamePalette[i].b = gammalut[gam][*pal++];
gamePalette[i].a = 0xff;
}

if (!UseCutscenePalette) {
// Hack black!
gamePalette[255].r = 0x0;
gamePalette[255].g = 0x0;
gamePalette[255].b = 0x0;
gamePalette[255].a = 0xff;
}

SDL_SetPaletteColors(sdlPalette, gamePalette, 0, 256);
SDL_SetSurfacePalette(drawSurface, sdlPalette);
SDL_SetSurfacePalette(offscreenDrawSurface, sdlPalette);

if (should_opengl_swap())
opengl_change_palette();
}

void SDLDraw() {
if (should_opengl_swap()) {
sdlPalette->colors[255].a = 0x00;
}

SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer, drawSurface);

if (should_opengl_swap()) {
sdlPalette->colors[255].a = 0xff;
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
}

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);
}
}

void CaptureMouse(bool capture) {
MouseCaptured = (capture && gShockPrefs.goCaptureMouse);

if (!MouseCaptured && mlook_enabled && SDL_GetRelativeMouseMode() == SDL_TRUE) {
SDL_SetRelativeMouseMode(SDL_FALSE);

int w, h;
SDL_GetWindowSize(window, &w, &h);
SDL_WarpMouseInWindow(window, w / 2, h / 2);
} else
SDL_SetRelativeMouseMode(MouseCaptured ? SDL_TRUE : SDL_FALSE);
}
Loading