Skip to content

Commit

Permalink
Add portable engine mode
Browse files Browse the repository at this point in the history
Default on every homebrew platform and Windows
Needed to ignore installation paths and not writing configuration in
$HOME on e.g. Linux or *BSD platforms
  • Loading branch information
carstene1ns committed Oct 26, 2023
1 parent 36293b8 commit 51264cc
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 14 deletions.
2 changes: 2 additions & 0 deletions BUILDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ http://www.alister.eu/jazz/oj/build.php

- `DATAPATH` - add a fixed path for game data files
- `SCALE` - enable scaling of the video output (i.e. Scale2X...)
- `PORTABLE` - Do not use external directories for configuration saving, etc.
(This only affects Unix platforms, Windows version is always portable)

Some ports have their own options, see (Platforms)[PLATFORMS.md] for details.

Expand Down
24 changes: 22 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.13...3.24)
cmake_minimum_required(VERSION 3.16...3.27)

project(OpenJazz
VERSION 20220827
Expand All @@ -17,6 +17,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED OFF)

# platform

include(CMakeDependentOption)
include(Platform-Helpers)

# Endianess check
Expand Down Expand Up @@ -124,16 +125,30 @@ target_include_directories(OpenJazz PUBLIC src)

# Default Options

set(SCALE_STATUS "Disabled")
option(SCALE "Allow scaling" ${OJ_SCALE})
if(SCALE)
set(SCALE_STATUS "Enabled, scale2x")
target_compile_definitions(OpenJazz PRIVATE SCALE)
set(OJ_LIBS_SCALE scale2x)
endif()

cmake_dependent_option(PORTABLE "Do not write to external directories, etc." OFF
"NOT OJ_DEFAULT_PORTABLE" ON)
if(PORTABLE)
set(PORTABLE_STATUS "Enabled")
target_compile_definitions(OpenJazz PRIVATE PORTABLE)
else()
set(PORTABLE_STATUS "Disabled")
endif()
if((PORTABLE AND OJ_DEFAULT_PORTABLE) OR (NOT PORTABLE AND NOT OJ_DEFAULT_PORTABLE))
set(PORTABLE_STATUS "${PORTABLE_STATUS} (Default)")
endif()

# path to game data

set(DATAPATH "" CACHE PATH "Fixed path where game data is available")
if(${DATAPATH})
if(DATAPATH)
target_compile_definitions(OpenJazz PRIVATE DATAPATH="${DATAPATH}")
endif()

Expand Down Expand Up @@ -349,7 +364,12 @@ if(ROMFS)
message(STATUS "RomFS: Embedding directory \"${ROMFS_PATH}\"")
endif()
message(STATUS "Network: ${NETWORK_STATUS}")
message(STATUS "Scaling: ${SCALE_STATUS}")
if(DATAPATH)
message(STATUS "Additional/System Game Data Path: \"${DATAPATH}\"")
endif()
message(STATUS "Manual page: ${MANUAL_STATUS}")
message(STATUS "Portable Engine: ${PORTABLE_STATUS}")
message(STATUS "")
message(STATUS "In case something goes wrong, report bugs to https://github.com/AlisterT/openjazz/issues")
message(STATUS "")
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ include openjazz.mk
# Sane defaults
CXX ?= g++
CXXFLAGS ?= -g -Wall -O2
CPPFLAGS = -Isrc -DSCALE -Iext/scale2x -Iext/psmplug -Iext/miniz -Iext/argparse
DEFINES = -DSCALE -DPORTABLE
CPPFLAGS = $(DEFINES) -Isrc -Iext/scale2x -Iext/psmplug -Iext/miniz -Iext/argparse

# Network support
CXXFLAGS += -DUSE_SOCKETS
Expand Down
7 changes: 6 additions & 1 deletion builds/cmake/Platform-Helpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ set(PLATFORM_LIST "")
set(OJ_SCALE ON)
set(OJ_LIBS_NET)
set(OJ_LIBS_HOST)
set(OJ_DEFAULT_PORTABLE ON)

option(PANDORA "Build for Pandora" OFF) # arm-none-linux-gnueabi
option(CAANOO "Build for GP2X Canoo" OFF) # arm-gph-linux-gnueabi
Expand Down Expand Up @@ -113,8 +114,12 @@ endif()
if(${OJ_HOST} STREQUAL "Unknown")
set(OJ_HOST ${CMAKE_SYSTEM_NAME})
set(OJ_ALLOW_NEW_SDL TRUE)

if(UNIX)
# usually we do a system-wide installation
set(OJ_DEFAULT_PORTABLE OFF)
endif()
endif()

# choose SDL library for Linux/Windows/Mac/etc., but not homebrew platforms
include(CMakeDependentOption)
cmake_dependent_option(LEGACY_SDL "Build for SDL 1.2" OFF "OJ_ALLOW_NEW_SDL" ON)
16 changes: 6 additions & 10 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,20 +158,12 @@ void startUp (const char *argv0, int pathCount, char *paths[]) {

// Determine paths

// Use hard-coded data paths, if available
#ifdef DATAPATH
gamePaths.add(createString(DATAPATH), PATH_TYPE_SYSTEM|PATH_TYPE_GAME);
#endif

PLATFORM_AddGamePaths();

// Use any provided paths
for (int i = 0; i < pathCount; i++) {

for (int i = 0; i < pathCount; i++)
gamePaths.add(createString(paths[i]), PATH_TYPE_GAME);

}


// Use the path of the program, but check before, since it is not always available
// At least crashes in Dolphin emulator (Wii) and 3DS (.cia build)
Expand All @@ -193,9 +185,13 @@ void startUp (const char *argv0, int pathCount, char *paths[]) {

}

// Last Resort: Use the current working directory
// Use the current working directory
gamePaths.add(createString(""), PATH_TYPE_GAME|PATH_TYPE_CONFIG|PATH_TYPE_TEMP);

// Use hard-coded data paths, if available
#ifdef DATAPATH
gamePaths.add(createString(DATAPATH), PATH_TYPE_SYSTEM|PATH_TYPE_GAME);
#endif

// Default settings

Expand Down
3 changes: 3 additions & 0 deletions src/platforms/platforms.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ inline void PLATFORM_AddGamePaths() {

// using __unix__ might add too much
#if (__linux__ && !__ANDROID__) || __FreeBSD__ || __OpenBSD__
#ifndef PORTABLE
// Only use XDG dirs for installed package
XDG_AddGamePaths();
#endif
#endif
}

Expand Down

0 comments on commit 51264cc

Please sign in to comment.