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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ build/
# Windows thumbnail cache
Thumbs.db

# macOS folder metadata
.DS_Store

# The desktop file has to be recreated from the template.
src/SDLPoP.desktop

Expand Down
10 changes: 4 additions & 6 deletions doc/Readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -275,15 +275,14 @@ DEVELOPING
Q: How do I (re)compile it?
A:
Prerequisites for all platforms:
Make sure that you have the development versions of the "SDL2" and "SDL2_image" libraries installed.
Make sure that you have the development versions of the "SDL2" library installed.

Windows:
If you are using Dev-C++:
I originally used Dev-C++ version 4.9.9.2 from here: https://sourceforge.net/projects/dev-cpp/files/Binaries/
More recently, I'm using this version: https://sourceforge.net/projects/orwelldevcpp/
For Dev-C++ you need the MinGW Development Libraries of SDL2:
https://libsdl.org/download-2.0.php
https://libsdl.org/projects/SDL_image/
To install these, just extract the contents of the i686-w64-mingw32 folder from each archive to the Dev-Cpp folder.
To compile, open one of the .dev files and click the compile icon.

Expand All @@ -310,11 +309,10 @@ Windows:

GNU/Linux:
You can install the libraries with apt-get or a package manager.
sudo apt-get install libsdl2-image-dev
sudo apt-get install libsdl2-dev

Alternatively, you can compile SDL2 and the other libraries from source.
https://libsdl.org/download-2.0.php
https://libsdl.org/projects/SDL_image/
I recommend this if your distro does not have the newest SDL version, because older SDL versions have some known bugs.
Namely, sound becomes garbled in SDL versions older than 2.0.4 if the sound output is not 8-bit.

Expand All @@ -330,10 +328,10 @@ GNU/Linux:
macOS:
Get SDL2 and dependencies
a) Install "port" from https://www.macports.org/
b) sudo port install libsdl2 libsdl2_image
b) sudo port install libsdl2
or
a) Install "homebrew"
b) brew install sdl2 sdl2_image
b) brew install sdl2

Get development tools:
a) Install Xcode.
Expand Down
62 changes: 34 additions & 28 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -std=gnu99")
# have CMake output binaries to the directory that contains the source files
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${SDLPoP_SOURCE_DIR}/..")

# SDLPoP requires the SDL2 and SDL2_image development libraries.
# SDLPoP requires the SDL2 development libraries.
# You can pass the SDL2 location to CMake like so: -DSDL2="C:/work/libraries/SDL2-2.0.8"
# Or alternatively, specify the SDL2 location below:

Expand All @@ -16,10 +16,8 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${SDLPoP_SOURCE_DIR}/..")

#set(SDL2 "/usr/local/Cellar/sdl2/2.0.5")

if (NOT(WIN32) AND (DEFINED SDL2))
include_directories(${SDL2}/include)
link_directories(${SDL2}/lib)
endif()
# If you don't specify the location of SDL2, this script will try to guess the location,
# or retrieve it using the sdl2-config utility.

if (WIN32)
if (MSVC)
Expand Down Expand Up @@ -49,6 +47,16 @@ if (WIN32)

include_directories(${SDL2}/${SDL2_ARCH}/include)
link_directories(${SDL2}/${SDL2_ARCH}/lib)
else()
if (DEFINED SDL2)
include_directories(${SDL2}/include)
link_directories(${SDL2}/lib)
else()
execute_process(COMMAND sdl2-config --prefix OUTPUT_VARIABLE SDL2_PREFIX)
string(STRIP ${SDL2_PREFIX} SDL2_PREFIX)
include_directories(${SDL2_PREFIX}/include)
link_directories(${SDL2_PREFIX}/lib)
endif()
endif()

set(SOURCE_FILES
Expand Down Expand Up @@ -88,33 +96,31 @@ else()
# By default, a normal binary executable will be created.
# If you want an Application Bundle instead, pass CREATE_BUNDLE to CMake like so: -DCREATE_BUNDLE=1

# NOTE: Currently, the SDL2 and SDL2_image frameworks are not being correctly included/linked in the bundle!
# As long as this isn't fixed, these bundles will only work if SDL2 and SDL2_image are installed.

set (SDLPoP_VERSION "1.19")
set (MACOSX_BUNDLE_INFO_STRING ${PROJECT_NAME})
set (MACOSX_BUNDLE_ICON_FILE "icon.icns")
set(MACOSX_BUNDLE_ICON_FILE "icon.icns")
set_source_files_properties(${MACOSX_BUNDLE_ICON_FILE} PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
set (MACOSX_BUNDLE_GUI_IDENTIFIER "org.princed.SDLPoP")
set (MACOSX_BUNDLE_LONG_VERSION_STRING ${SDLPoP_VERSION})
set (MACOSX_BUNDLE_BUNDLE_NAME "SDLPoP")
set (MACOSX_BUNDLE_SHORT_VERSION_STRING ${SDLPoP_VERSION})
set (MACOSX_BUNDLE_BUNDLE_VERSION ${SDLPoP_VERSION})
set (MACOSX_BUNDLE_COPYRIGHT "GNU General Public Licence, v3")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mmacosx-version-min=10.4")
set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -headerpad_max_install_names")
add_executable(prince MACOSX_BUNDLE ${SOURCE_FILES} ${MACOSX_BUNDLE_ICON_FILE})
add_custom_command(TARGET prince POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_SOURCE_DIR}/../data ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/prince.app/Contents/MacOS/data)
add_custom_command(TARGET prince POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_SOURCE_DIR}/../doc ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/prince.app/Contents/MacOS/doc)
add_custom_command(TARGET prince POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_SOURCE_DIR}/../SDLPoP.ini ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/prince.app/Contents/MacOS/SDLPoP.ini)
set_target_properties(prince PROPERTIES MACOSX_BUNDLE_INFO_PLIST ${CMAKE_SOURCE_DIR}/Info.plist)

# If you want to copy the data files from another folder, pass this to CMake: -DDATA_DIRECTORY=<path>.
if (NOT (DEFINED DATA_DIRECTORY))
set(DATA_DIRECTORY ${CMAKE_SOURCE_DIR}/../data)
endif()
# Copy the data files, documentation and SDLPoP.ini into the bundle
set(BUNDLE_BINARY_DIR "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/prince.app/Contents/MacOS")
add_custom_command(TARGET prince POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory ${DATA_DIRECTORY} ${BUNDLE_BINARY_DIR}/data)
add_custom_command(TARGET prince POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/../doc ${BUNDLE_BINARY_DIR}/doc)
add_custom_command(TARGET prince POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/../SDLPoP.ini ${BUNDLE_BINARY_DIR}/SDLPoP.ini)
# Copy the .dylib file for SDL2 into the prince.app/Contents/MacOS folder.
add_custom_command(TARGET prince POST_BUILD COMMAND cp -f `otool -L ${BUNDLE_BINARY_DIR}/prince | grep SDL2- | cut -d' ' -f1` "${BUNDLE_BINARY_DIR}/libSDL2-2.0.0.dylib")
# Modify the executable, so that the program loads the packaged .dylib files, instead of looking in e.g. /usr/local/opt
add_custom_command(TARGET prince POST_BUILD COMMAND install_name_tool -change `otool -L "${BUNDLE_BINARY_DIR}/prince" | grep SDL2- | cut -d' ' -f1` @executable_path/libSDL2-2.0.0.dylib "${BUNDLE_BINARY_DIR}/prince")

endif()

if(WIN32)
target_link_libraries(prince mingw32 SDL2main SDL2 SDL2.dll SDL2_image)
target_link_libraries(prince mingw32 SDL2main SDL2 SDL2.dll)
else()
target_link_libraries(prince SDL2main SDL2 SDL2_image m)
target_link_libraries(prince SDL2main SDL2 m)
endif()
38 changes: 38 additions & 0 deletions src/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>prince</string>
<key>CFBundleGetInfoString</key>
<string>SDLPoP</string>
<key>CFBundleIconFile</key>
<string>icon.icns</string>
<key>CFBundleIdentifier</key>
<string>org.princed.SDLPoP</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleLongVersionString</key>
<string>1.19</string>
<key>CFBundleName</key>
<string>SDLPoP</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.19</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.19</string>
<key>CSResourcesFileMapped</key>
<true/>
<key>NSSupportsSuddenTermination</key>
<false/>
<key>NSHumanReadableCopyright</key>
<string>GNU General Public Licence, v3</string>
<key>NSHighResolutionCapable</key>
<true/>
</dict>
</plist>
6 changes: 3 additions & 3 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ BIN = ../prince
OS := $(shell uname)

ifeq ($(OS),Darwin)
LIBS := $(shell sdl2-config --libs) -lSDL2_image
LIBS := $(shell sdl2-config --libs)
INCS := -I/opt/local/include
CFLAGS += $(INCS) -Wall -std=gnu99 -D_GNU_SOURCE=1 -D_THREAD_SAFE -DOSX -O2
else
LIBS := $(shell pkg-config --libs sdl2 SDL2_image)
INCS := $(shell pkg-config --cflags sdl2 SDL2_image)
LIBS := $(shell pkg-config --libs sdl2)
INCS := $(shell pkg-config --cflags sdl2)
CFLAGS += $(INCS) -Wall -std=gnu99 -O2
endif

Expand Down
2 changes: 1 addition & 1 deletion src/NMakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
OBJ = main.obj data.obj seg000.obj seg001.obj seg002.obj seg003.obj seg004.obj seg005.obj seg006.obj seg007.obj seg008.obj seg009.obj seqtbl.obj replay.obj options.obj lighting.obj screenshot.obj menu.obj midi.obj opl3.obj stb_vorbis.c

sdl = "..\SDL2-2.0.4"
LIBS = $(sdl)\lib\x86\SDL2main.lib $(sdl)\lib\x86\SDL2.lib $(sdl)\lib\x86\SDL2_image.lib
LIBS = $(sdl)\lib\x86\SDL2main.lib $(sdl)\lib\x86\SDL2.lib
cc = cl /c
link = link /subsystem:windows

Expand Down
2 changes: 1 addition & 1 deletion src/build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ set PreprocessorDefinitions=
:compile
set SourceFiles= main.c data.c seg000.c seg001.c seg002.c seg003.c seg004.c seg005.c seg006.c seg007.c seg008.c seg009.c seqtbl.c replay.c options.c lighting.c screenshot.c menu.c midi.c opl3.c stb_vorbis.c
set CommonCompilerFlags= /nologo /MP /fp:fast /GR- /wd4048 %PreprocessorDefinitions% /I"%SDL2%\include"
set CommonLinkerFlags= /subsystem:windows,5.01 /libpath:"%SDL2%\lib\%VSCMD_ARG_TGT_ARCH%" SDL2main.lib SDL2.lib SDL2_image.lib icon.res /out:..\prince.exe
set CommonLinkerFlags= /subsystem:windows,5.01 /libpath:"%SDL2%\lib\%VSCMD_ARG_TGT_ARCH%" SDL2main.lib SDL2.lib icon.res /out:..\prince.exe

rc /nologo /fo icon.res icon.rc
cl %BuildTypeCompilerFlags% %CommonCompilerFlags% %SourceFiles% /link %CommonLinkerFlags%
Expand Down
9 changes: 9 additions & 0 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ extern "C" {
#define ABS(x) ((x)<0?-(x):(x))
#endif

#if defined(__APPLE__) && !defined(strnlen)
// Use this if strnlen is missing.
static inline size_t strnlen(const char *str, size_t max)
{
const char *end = memchr (str, 0, max);
return end ? (size_t)(end - str) : max;
}
#endif

#ifdef __cplusplus
}
#endif
Expand Down
1 change: 1 addition & 0 deletions src/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,7 @@ extern SDL_Texture* texture_fuzzy;
extern SDL_Texture* texture_blurry;
extern SDL_Texture* target_texture;

extern bool is_joyst_supported;
extern SDL_GameController* sdl_controller_ INIT( = 0 );
extern SDL_Joystick* sdl_joystick_; // in case our joystick is not compatible with SDL_GameController
extern byte using_sdl_joystick_interface;
Expand Down
7 changes: 6 additions & 1 deletion src/lighting.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ The authors of this program may be contacted at http://forum.princed.org
*/

#include "common.h"
#include "stb_image.h"

#ifdef USE_LIGHTING

Expand All @@ -32,12 +33,16 @@ const Uint8 ambient_level = 128;
void init_lighting() {
if (!enable_lighting) return;

lighting_mask = IMG_Load(locate_file(mask_filename));
int mask_width, mask_height;
void* mask_pixel_data = stbi_load(locate_file(mask_filename), &mask_width, &mask_height, NULL, 4);
lighting_mask = SDL_CreateRGBSurfaceFrom(mask_pixel_data, mask_width, mask_height, 32, 4*mask_width,
0xFF, 0xFF<<8, 0xFF<<16, 0xFF<<24);
if (lighting_mask == NULL) {
sdlperror("IMG_Load (lighting_mask)");
enable_lighting = 0;
return;
}
lighting_mask->userdata = mask_pixel_data;

screen_overlay = SDL_CreateRGBSurface(0, 320, 192, 32, 0xFF << 0, 0xFF << 8, 0xFF << 16, 0xFF << 24);
if (screen_overlay == NULL) {
Expand Down
20 changes: 16 additions & 4 deletions src/screenshot.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ The authors of this program may be contacted at http://forum.princed.org

#include "common.h"

#define STB_IMAGE_WRITE_IMPLEMENTATION
#include "stb_image_write.h"

#ifdef USE_SCREENSHOT

const char screenshots_folder[] = "screenshots";
Expand Down Expand Up @@ -54,18 +57,27 @@ void show_result(int result, const char* what) {
printf("Saved %s to \"%s\".\n", what, screenshot_filename);
snprintf(sprintf_temp, sizeof(sprintf_temp), "Saved %s", what);
} else {
printf("Could not save %s to \"%s\". Error: %s\n", what, screenshot_filename, IMG_GetError());
printf("Could not save %s to \"%s\".", what, screenshot_filename);
snprintf(sprintf_temp, sizeof(sprintf_temp), "Could not save %s", what);
}
display_text_bottom(sprintf_temp);
text_time_total = 24;
text_time_remaining = 24;
}

// Output SDL surface as PNG.
int save_surface_as_png(SDL_Surface* surface, const char* filename) {
SDL_LockSurface(surface);
int result = stbi_write_png(filename, surface->w, surface->h,
surface->format->BytesPerPixel, surface->pixels, surface->pitch);
SDL_UnlockSurface(surface);
return result;
}

// Save a screenshot.
void save_screenshot() {
make_screenshot_filename();
int result = IMG_SavePNG(get_final_surface(), screenshot_filename);
int result = save_surface_as_png(onscreen_surface_, screenshot_filename);
show_result(result, "screenshot");
}

Expand Down Expand Up @@ -579,10 +591,10 @@ void save_level_screenshot(bool want_extras) {
switch_to_room(old_room);

make_screenshot_filename();
int result = IMG_SavePNG(map_surface, screenshot_filename);
int result = save_surface_as_png(map_surface, screenshot_filename);
show_result(result, "level map");

SDL_FreeSurface(map_surface);
free_surface(map_surface);

//printf("random_seed = 0x%08X\n", random_seed);
}
Expand Down
2 changes: 1 addition & 1 deletion src/seg001.c
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ void __pascal far load_intro(int which_imgs,cutscene_ptr_type func,int free_soun

// Free the images that are not needed anymore.
free_all_chtabs_from(id_chtab_9_princessbed);
SDL_FreeSurface(get_image(id_chtab_8_princessroom, 0));
free_surface(get_image(id_chtab_8_princessroom, 0));
if (NULL != chtab_addrs[id_chtab_8_princessroom]) chtab_addrs[id_chtab_8_princessroom]->images[0] = NULL;

load_chtab_from_file(id_chtab_3_princessinstory, 800, "PV.DAT", 1<<9);
Expand Down
2 changes: 1 addition & 1 deletion src/seg008.c
Original file line number Diff line number Diff line change
Expand Up @@ -1013,7 +1013,7 @@ void __pascal far draw_mid(int index) {
}
if (need_free_image) {
//free_far(image);
SDL_FreeSurface(image);
free_surface(image);
}
if (need_free_mask) {
free_far(mask);
Expand Down
Loading