diff --git a/.gitignore b/.gitignore index 516daa9..2d3827f 100644 --- a/.gitignore +++ b/.gitignore @@ -20,8 +20,9 @@ nbproject/* # src src/Config.h +*.orig +*.rej # others debug.html - - +*.patch diff --git a/CMakeLists.txt b/CMakeLists.txt index ba940a2..fe8f523 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,67 +1,77 @@ cmake_minimum_required (VERSION 2.8) -project(savagewheels) +project(savagewheels) ### Defaults set(APP_ARCH "") set(APP_VER_MAJ "1") set(APP_VER_MIN "6") -set(APP_VER_PATCH "0") +set(APP_VER_PATCH "1") ### check for required libs find_package(SDL REQUIRED) -### Install targets (see: http://www.cmake.org/Wiki/CMake_RPATH_handling) -if (NOT INSTALL_DIR) - set(INSTALL_DIR "./") +### Install targets +if (UNIX) + include (GNUInstallDirs) +else() + if (NOT INSTALL_DIR) + set(INSTALL_DIR "./") + endif() + set(CMAKE_INSTALL_BINDIR "${INSTALL_DIR}") + set(CMAKE_INSTALL_SBINDIR "${INSTALL_DIR}") + set(CMAKE_INSTALL_LIBEXECDIR "${INSTALL_DIR}") + set(CMAKE_INSTALL_SYSCONFDIR "${INSTALL_DIR}") + set(CMAKE_INSTALL_SHAREDSTATEDIR "${INSTALL_DIR}") + set(CMAKE_INSTALL_LOCALSTATEDIR "${INSTALL_DIR}") + set(CMAKE_INSTALL_LIBDIR "${INSTALL_DIR}") + set(CMAKE_INSTALL_INCLUDEDIR "${INSTALL_DIR}") + set(CMAKE_INSTALL_OLDINCLUDEDIR "${INSTALL_DIR}") + set(CMAKE_INSTALL_DATAROOTDIR "${INSTALL_DIR}") + set(CMAKE_INSTALL_DATADIR "${INSTALL_DIR}") + set(CMAKE_INSTALL_INFODIR "${INSTALL_DIR}") + set(CMAKE_INSTALL_LOCALEDIR "${INSTALL_DIR}") + set(CMAKE_INSTALL_MANDIR "${INSTALL_DIR}") + set(CMAKE_INSTALL_DOCDIR "${INSTALL_DIR}") endif() -# when building, don't use the install RPATH already -# (but later on when installing) -SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) - -# add the automatically determined parts of the RPATH -SET(CMAKE_INSTALL_RPATH "${INSTALL_DIR}/") -SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) - ### sources include_directories(src/) include_directories(tinyxml/) set( - SOURCES + SOURCES src/CBufferedReader.cpp - src/Bindings.cpp - src/CDeadToy.cpp - src/CKdf.cpp - src/CSdl.cpp - src/CSwv_module.cpp - src/CVehicle.cpp - src/Utils.cpp - src/CAnimation.cpp - src/CGame.cpp - src/CMainMenu.cpp + src/Bindings.cpp + src/CDeadToy.cpp + src/CKdf.cpp + src/CSdl.cpp + src/CSwv_module.cpp + src/CVehicle.cpp + src/Utils.cpp + src/CAnimation.cpp + src/CGame.cpp + src/CMainMenu.cpp src/CSounds.cpp src/CTimer.cpp src/Main.cpp tinyxml/tinystr.cpp tinyxml/tinyxml.cpp tinyxml/tinyxmlerror.cpp - tinyxml/tinyxmlparser.cpp + tinyxml/tinyxmlparser.cpp ) ### specify executable - set(RES_FILES "") if(MINGW) - # include a Windows resource file + # include a Windows resource file set(RES_FILES "src/res.rc") set(CMAKE_RC_COMPILER_INIT windres) ENABLE_LANGUAGE(RC) SET(CMAKE_RC_COMPILE_OBJECT " -O coff -i -o ") - - add_executable(savagewheels ${SOURCES} ${RES_FILES}) + + add_executable(savagewheels ${SOURCES} ${RES_FILES}) else() - add_executable(savagewheels ${SOURCES}) + add_executable(savagewheels ${SOURCES}) endif() ### add required libarires @@ -77,7 +87,7 @@ endif() ## SDL if (UNIX AND NOT WIN32) # Linux - + # set(SDL_LIB_NAME "libSDL.so") # find_library( # SDL_LIBRARY_SO @@ -85,27 +95,27 @@ if (UNIX AND NOT WIN32) # PATHS "/usr/lib" "/usr/local/lib/" # HINTS $ENV{SDLDIR} ${SDL_LIBRARY} "${CMAKE_CURRENT_SOURCE_DIR}/libs") add_definitions(`sdl-config --cflags`) - add_definitions(`sdl-config --libs`) + add_definitions(`sdl-config --libs`) else() # Windows - + set(SDL_LIB_NAME "SDL.dll") - + add_definitions(-lpthread) include_directories(${SDL_INCLUDE_DIR}) link_directories($ENV{SDLDIR}\\lib) set(SDL_LIBRARY_SO $ENV{SDLDIR}\\bin\\SDL.dll) - + message(STATUS "Found libSDL.so/DLL at ${SDL_LIBRARY}") - + # copy the SDL DLL file to the install dir add_custom_command(TARGET savagewheels POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_if_different + COMMAND ${CMAKE_COMMAND} -E copy_if_different ${SDL_LIBRARY_SO} - $) - + $) + INSTALL(FILES "${CMAKE_CURRENT_BINARY_DIR}/SDL.dll" DESTINATION ${INSTALL_DIR}) - + endif() ## SOUND libraries @@ -114,99 +124,100 @@ if (SOUND STREQUAL "NO") elseif(SOUND STREQUAL "FMOD") # FModEx API - # check if path to FMod is defined - if(NOT DEFINED ${FMOD_PATH}) - set(FMOD_PATH "${CMAKE_CURRENT_SOURCE_DIR}/libs/fmod/api") - endif() + # check if path to FMod is defined + if(NOT DEFINED FMOD_PATH) + set(FMOD_PATH "${CMAKE_CURRENT_SOURCE_DIR}/libs/fmod/api") + endif() add_definitions(-I${FMOD_PATH}/inc) link_directories(${FMOD_PATH}/lib) - if (UNIX AND NOT WIN32) - # Linux - - if (CMAKE_SIZEOF_VOID_P MATCHES "8" AND NOT M32) - set(FMOD_LIB_NAME "libfmodex64.so") - set(FMOD_SO_NAME "libfmodex64.so") - else() - set(FMOD_LIB_NAME "libfmodex.so") - set(FMOD_SO_NAME "libfmodex.so") - endif() - - # just in case check also in the system folders - add_definitions(-I/usr/include/fmodex) - else() - # Windows - - set(FMOD_LIB_NAME "libfmodex.a") - if (CMAKE_SIZEOF_VOID_P MATCHES "8" AND NOT M32) - set(FMOD_SO_NAME "fmodex64.dll") - else() - set(FMOD_SO_NAME "fmodex.dll") - endif() - endif() + if (UNIX AND NOT WIN32) + # Linux + + if (CMAKE_SIZEOF_VOID_P MATCHES "8" AND NOT M32) + set(FMOD_LIB_NAME "libfmodex64.so") + set(FMOD_SO_NAME "libfmodex64.so") + else() + set(FMOD_LIB_NAME "libfmodex.so") + set(FMOD_SO_NAME "libfmodex.so") + endif() + + # just in case check also in the system folders + add_definitions(-I/usr/include/fmodex) + else() + # Windows + + set(FMOD_LIB_NAME "libfmodex.a") + if (CMAKE_SIZEOF_VOID_P MATCHES "8" AND NOT M32) + set(FMOD_SO_NAME "fmodex64.dll") + else() + set(FMOD_SO_NAME "fmodex.dll") + endif() + endif() - # add FMod Ex (if present) - find_library( - FMOD_LIBRARY - NAMES ${FMOD_LIB_NAME} - PATHS "/usr/lib" "/usr/local/lib/" - HINTS "${FMOD_PATH}/lib") - - find_library( - FMOD_LIBRARY_SO_PATH - NAMES ${FMOD_SO_NAME} - PATHS "/usr/lib" "/usr/local/lib/" - HINTS "${FMOD_PATH}" "${FMOD_PATH}/lib") - - if (NOT FMOD_LIBRARY) - message(STATUS "FModEx lib - ${FMOD_LIB_NAME} not found! Will compile without sound support.") - else() - message(STATUS "Found FModEx lib at ${FMOD_LIBRARY}. Found FModEx DLL at ${FMOD_LIBRARY_SO_PATH}.") - - add_definitions(-DWITH_FMOD) - - add_custom_command(TARGET savagewheels POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_if_different - ${FMOD_LIBRARY_SO_PATH} - $) - - INSTALL(FILES "${CMAKE_CURRENT_BINARY_DIR}/${FMOD_SO_NAME}" - DESTINATION ${INSTALL_DIR}) - endif() + # add FMod Ex (if present) + find_library( + FMOD_LIBRARY + NAMES ${FMOD_LIB_NAME} + PATHS "/usr/lib" "/usr/local/lib/" + HINTS "${FMOD_PATH}/lib") + + find_library( + FMOD_LIBRARY_SO_PATH + NAMES ${FMOD_SO_NAME} + PATHS "/usr/lib" "/usr/local/lib/" + HINTS "${FMOD_PATH}" "${FMOD_PATH}/lib") + + if (NOT FMOD_LIBRARY) + message(STATUS "FModEx lib - ${FMOD_LIB_NAME} not found! Will compile without sound support.") + else() + message(STATUS "Found FModEx lib at ${FMOD_LIBRARY}. Found FModEx DLL at ${FMOD_LIBRARY_SO_PATH}.") + + add_definitions(-DWITH_FMOD) + + if (WIN32) + add_custom_command(TARGET savagewheels POST_BUILD + COMMAND "${CMAKE_COMMAND}" -E copy_if_different + "${FMOD_LIBRARY_SO_PATH}" + "$") + + INSTALL(FILES "${CMAKE_CURRENT_BINARY_DIR}/${FMOD_SO_NAME}" + DESTINATION "${INSTALL_DIR}") + endif() + endif() else() + # SDL_mixer API find_package(SDL_mixer REQUIRED) add_definitions(-DWITH_SDLMIXER) set(SOUND "SDL_MIXER") - # Copy SDL_mixer.dll and libmikmod-2.dll to installation directory - if (WIN32) - INSTALL(FILES "${SDL_MIXER_LIBRARIES}" DESTINATION ${INSTALL_DIR}) - - # Find mikmod DLL for playing music - find_library(SDL_MIXER_MIKMOD_LIBRARY - NAMES libmikmod-2 - HINTS - ENV SDLMIXERDIR - ENV SDLDIR - PATH_SUFFIXES lib) - - if (NOT SDL_MIXER_MIKMOD_LIBRARY) - message(STATUS "SDL_mixer libmikmod-2 dependency was NOT FOUND! Game will run WITHOUT music.") - endif() - - INSTALL(FILES "${SDL_MIXER_MIKMOD_LIBRARY}" DESTINATION ${INSTALL_DIR}) - endif() + # Copy SDL_mixer.dll and libmikmod-2.dll to installation directory + if (WIN32) + INSTALL(FILES "${SDL_MIXER_LIBRARIES}" DESTINATION ${INSTALL_DIR}) + + # Find mikmod DLL for playing music + find_library(SDL_MIXER_MIKMOD_LIBRARY + NAMES libmikmod-2 + HINTS + ENV SDLMIXERDIR + ENV SDLDIR + PATH_SUFFIXES lib) + + if (NOT SDL_MIXER_MIKMOD_LIBRARY) + message(STATUS "SDL_mixer libmikmod-2 dependency was NOT FOUND! Game will run WITHOUT music.") + endif() + + INSTALL(FILES "${SDL_MIXER_MIKMOD_LIBRARY}" DESTINATION ${INSTALL_DIR}) + endif() endif() ### link required libraries - target_link_libraries(savagewheels ${SDL_LIBRARY} ${FMOD_LIBRARY} ${SDLMIXER_LIBRARY}) ### additional defines - if (UNIX AND NOT WIN32) add_definitions(-DLINUX_BUILD) endif() @@ -219,7 +230,6 @@ endif() message(STATUS "Build type is ${CMAKE_BUILD_TYPE}") ### set architecture - if (CMAKE_SIZEOF_VOID_P MATCHES "8" AND NOT M32) add_definitions(-DARCH_X64) set(APP_ARCH "x64") @@ -231,23 +241,69 @@ else() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32") endif() -### Configure compile time header file +### Configure compile time header file configure_file ( "${PROJECT_SOURCE_DIR}/Config.h.in" "${PROJECT_SOURCE_DIR}/src/Config.h") - -INSTALL(TARGETS savagewheels RUNTIME DESTINATION ${INSTALL_DIR}) -INSTALL(PROGRAMS "${CMAKE_CURRENT_SOURCE_DIR}/run.sh" DESTINATION ${INSTALL_DIR}) + +INSTALL(TARGETS savagewheels RUNTIME DESTINATION "${CMAKE_INSTALL_LIBEXECDIR}") +if (UNIX AND NOT WIN32) + # address Arch Linux packaging by explicitly specifying data dirs + if (NOT INSTALL_DATADIR) + set(INSTALL_DATADIR "${CMAKE_INSTALL_DATADIR}") + endif() + if (NOT INSTALL_LIBEXECDIR) + set(INSTALL_LIBEXECDIR "${CMAKE_INSTALL_LIBEXECDIR}") + endif() + + configure_file( "${CMAKE_CURRENT_SOURCE_DIR}/savagewheels.in" + "${CMAKE_CURRENT_BINARY_DIR}/savagewheels.sh" + @ONLY) + + INSTALL(PROGRAMS "${CMAKE_CURRENT_BINARY_DIR}/savagewheels.sh" + DESTINATION "${CMAKE_INSTALL_BINDIR}" RENAME savagewheels) + + # add run.sh if building a static distro + if (CMAKE_BUILD_STATIC) + INSTALL(PROGRAMS "${CMAKE_CURRENT_SOURCE_DIR}/run.sh" + DESTINATION "./") + endif() +endif() + INSTALL(FILES "${CMAKE_CURRENT_SOURCE_DIR}/README.md" "${CMAKE_CURRENT_SOURCE_DIR}/HISTORY" "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE" - DESTINATION ${INSTALL_DIR}) -INSTALL(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin/" - DESTINATION ${INSTALL_DIR} + "${CMAKE_CURRENT_SOURCE_DIR}/bin/LICENSE.mikmod.txt" + "${CMAKE_CURRENT_SOURCE_DIR}/bin/Readme.html" + "${CMAKE_CURRENT_SOURCE_DIR}/bin/README-SDL_mixer.txt" + "${CMAKE_CURRENT_SOURCE_DIR}/bin/README-SDL.txt" + DESTINATION "${CMAKE_INSTALL_DOCDIR}") +INSTALL(FILES + "${CMAKE_CURRENT_SOURCE_DIR}/bin/bindings.xml" + DESTINATION "${CMAKE_INSTALL_DATADIR}") +INSTALL(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin/help" + DESTINATION "${CMAKE_INSTALL_DOCDIR}" PATTERN "debug.html" EXCLUDE PATTERN "pref" EXCLUDE) - + +# add data folders only if they are already present +if (IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin/autos") + INSTALL(DIRECTORY + "${CMAKE_CURRENT_SOURCE_DIR}/bin/autos" + DESTINATION "${CMAKE_INSTALL_DATADIR}") +endif() +if (IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin/sound") + INSTALL(DIRECTORY + "${CMAKE_CURRENT_SOURCE_DIR}/bin/sound" + DESTINATION "${CMAKE_INSTALL_DATADIR}") +endif() +if (IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin/graphics") + INSTALL(DIRECTORY + "${CMAKE_CURRENT_SOURCE_DIR}/bin/graphics" + DESTINATION "${CMAKE_INSTALL_DATADIR}") +endif() + ### build a CPack driven installer package include (InstallRequiredSystemLibraries) @@ -273,7 +329,7 @@ set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.md") # Debian DEB package stuff if (${CPACK_GENERATOR} STREQUAL "DEB") set(CPACK_PACKAGING_INSTALL_PREFIX "/opt") - set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE ${DEB_ARCH}) + set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE ${DEB_ARCH}) set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6, libstdc++6, libsdl1.2debian (>= 1.2.11)") # require SDL_mixer if support is enabled if(SOUND STREQUAL "SDL_MIXER") @@ -284,7 +340,7 @@ endif() set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE") set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README.md") #set(CPACK_INSTALLED_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/bin;/.") -#set(CPACK_IGNORE_FILES +#set(CPACK_IGNORE_FILES #"~$" #"^.*/.git/" #"^${PROJECT_SOURCE_DIR}/bin/pref" diff --git a/HISTORY b/HISTORY index 4cd1671..cf20753 100644 --- a/HISTORY +++ b/HISTORY @@ -1,6 +1,9 @@ Savage Wheels Release HISTORY ----------------------------- +V1.6.1 Patch + * added Linux configurable game data directories + V1.6 Release * added support for SDL_mixer sound library. It is now the default sound library used. diff --git a/build.sh b/build.sh index 1b25afe..15a12fc 100755 --- a/build.sh +++ b/build.sh @@ -12,14 +12,6 @@ CPACK="$(which cpack)" VERMAJ=`perl -nle 'print $1 if /.*VER_MAJ\s(\d+).*/' src/Main.h` VERMIN=`perl -nle 'print $1 if /.*VER_MIN\s(\d+).*/' src/Main.h` VERSION="$VERMAJ.$VERMIN" -#ARCH="$(uname -m)" -#TMP_PATH="$CUR_DIR/build/savagewheels-$VERSION-linux" - -#if [ $ARCH = "x86_64" ]; then -# TMP_PATH="$TMP_PATH-x64" -#else -# TMP_PATH="$TMP_PATH-$ARCH" -#fi usage() { echo "dist-build.sh - Savage Wheels ${VERMAJ}.${VERMIN} distributable package build script" @@ -32,10 +24,6 @@ usage() { cleanup() { echo "Cleaning up old files ..." - #if [ -e $TMP_PATH ]; then - # rm -rf $TMP_PATH - #fi - cd $BUILD_PATH make clean cd .. @@ -47,12 +35,6 @@ cleanup() { build() { echo "Building package ..." - - mkdir $TMP_PATH - if [ ! -e $TMP_PATH ]; then - echo "Dist path could not be created - $TMP_PATH" - exit - fi if [ ! -e $CMAKE ]; then echo "CMake was not found - $CMAKE" @@ -64,7 +46,9 @@ build() { fi cd $BUILD_PATH - $CMAKE cmake -G "Unix Makefiles" ../ -DCMAKE_BUILD_TYPE:STRING=Release + $CMAKE cmake -G "Unix Makefiles" ../ \ + -DCMAKE_BUILD_TYPE:STRING=Release \ + -DCMAKE_BUILD_STATIC=1 make -j$CPU_CORES $CPACK @@ -77,10 +61,9 @@ build() { if [ "$1" = "clean" ]; then cleanup -#elif [ "$1" = "build" ]; then -else +elif [ "$1EMPTY" = "EMPTY" ]; then cleanup build -#else -# usage +else + usage fi diff --git a/run.sh b/run.sh index 8f16d25..27440d0 100644 --- a/run.sh +++ b/run.sh @@ -4,6 +4,8 @@ CUR_DIR="$(dirname $(readlink -f $0))" export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CUR_DIR:. +export SAVAGEWHEELS_SYS_DATADIR="$CUR_DIR/share" +export SAVAGEWHEELS_LIBEXECDIR="$CUR_DIR/libexec" # Run the game -exec ./savagewheels "$@" +exec bin/savagewheels "$@" diff --git a/savagewheels.desktop b/savagewheels.desktop new file mode 100644 index 0000000..e1a6f36 --- /dev/null +++ b/savagewheels.desktop @@ -0,0 +1,13 @@ +[Desktop Entry] +Encoding=UTF-8 +Name=SavageWheels +GenericName=Action/Arcade Game +Version=1.6 +Type=Application +Categories=Game;ActionGame;Racing; +Keywords=Game;Arcade;2D;Cars;Racing +Comment=2D car crashing game similar to the old classic Destruction Derby +TryExec=savagewheels +Exec=savagewheels +Terminal=false +Icon=sw1 \ No newline at end of file diff --git a/savagewheels.in b/savagewheels.in new file mode 100755 index 0000000..a4ad128 --- /dev/null +++ b/savagewheels.in @@ -0,0 +1,42 @@ +#!/bin/sh + +export SAVAGEWHEELS_SYS_DATADIR="${SAVAGEWHEELS_SYS_DATADIR-@INSTALL_DATADIR@}" +export SAVAGEWHEELS_LIBEXECDIR="${SAVAGEWHEELS_LIBEXECDIR-@INSTALL_LIBEXECDIR@}" +export SAVAGEWHEELS_USR_CONFDIR="${SAVAGEWHEELS_USR_CONFDIR-${HOME}/.config/savagewheels}" +export SAVAGEWHEELS_USR_DATADIR="${SAVAGEWHEELS_USR_DATADIR-${HOME}/.local/share/savagewheels}" + +if [ ! -d ${SAVAGEWHEELS_USR_CONFDIR} ]; then + if [ -e ${SAVAGEWHEELS_USR_CONFDIR} ]; then + printf "${SAVAGEWHEELS_USR_CONFDIR} exists but is not a directory.\n" >&2 + printf " Please remove.\n" >&2 + exit 1 + fi + mkdir -p ${SAVAGEWHEELS_USR_CONFDIR} + if [ $? -ne 0 ]; then + printf "Failed to create ${SAVAGEWHEELS_USR_CONFDIR}\n" >&2 + exit 1 + fi +fi + +if [ ! -d ${SAVAGEWHEELS_USR_DATADIR} ]; then + if [ -e ${SAVAGEWHEELS_USR_DATADIR} ]; then + printf "${SAVAGEWHEELS_USR_DATADIR} exists but is not a directory.\n" >&2 + printf " Please remove.\n" >&2 + exit 1 + fi + mkdir -p ${SAVAGEWHEELS_USR_DATADIR} + if [ $? -ne 0 ]; then + printf "Failed to create ${SAVAGEWHEELS_USR_DATADIR}\n" >&2 + exit 1 + fi +fi + +if [ ! -e ${SAVAGEWHEELS_USR_CONFDIR}/bindings.xml ]; then + cp ${SAVAGEWHEELS_SYS_DATADIR}/bindings.xml ${SAVAGEWHEELS_USR_CONFDIR} + if [ $? -ne 0 ]; then + printf "Failed to create ${SAVAGEWHEELS_USR_CONFDIR}/bindings.xml\n" >&2 + exit 1 + fi +fi + +exec ${SAVAGEWHEELS_LIBEXECDIR}/savagewheels "$@" diff --git a/src/CGame.cpp b/src/CGame.cpp index aecd6b6..60d38b7 100644 --- a/src/CGame.cpp +++ b/src/CGame.cpp @@ -118,6 +118,7 @@ bool CGame::LoadGame() { char buf[255]; int i = 0; + String tmp (sys_datadir); AppendToLog( LOG_DASH ); AppendToLog("Loading Game..."); @@ -163,7 +164,10 @@ bool CGame::LoadGame() UpdateSplash(); // UPDATESPLASH... // search for vehicles - if ( Swv.SearchAndLoad( "autos" ) != SWV_SUCCESS ) return false; + tmp.resize(strlen(sys_datadir)); + tmp.append("/autos"); + if ( Swv.SearchAndLoad( tmp.c_str() ) != SWV_SUCCESS ) + return false; // check for vehicle number if ( Swv.GetVehicles() < 4 ) diff --git a/src/CMainMenu.cpp b/src/CMainMenu.cpp index 5a27153..d454310 100644 --- a/src/CMainMenu.cpp +++ b/src/CMainMenu.cpp @@ -1123,8 +1123,9 @@ void CMainMenu::SaveSettings() FILE *fp = NULL; char header[3] = { 'S', 'W', 'P' }; + String strPref(String(usr_cfgdir) + "/pref"); - if ( ( fp = fopen( "pref", "wb" ) ) == NULL ) + if ( ( fp = fopen( strPref.c_str(), "wb" ) ) == NULL ) { AppendToLog( "Error writing to /pref file !" ); return; @@ -1169,8 +1170,9 @@ void CMainMenu::LoadSettings() FILE *fp = NULL; char header[3]; bool success = true; + String strPref(String(usr_cfgdir) + "/pref"); - if ( ( fp = fopen( "pref", "rb" ) ) == NULL ) + if ( ( fp = fopen( strPref.c_str(), "wb" ) ) == NULL ) { AppendToLog( "Error opening /pref file !" ); success = false; diff --git a/src/CSdl.cpp b/src/CSdl.cpp index 8e7e4ae..641365f 100644 --- a/src/CSdl.cpp +++ b/src/CSdl.cpp @@ -1300,9 +1300,6 @@ SDL_Surface* CSdl::LoadBitmap( const char *filename, Uint32 color_key, Uint8 alp SDL_Surface *sdl_surf = NULL; - char filename_buf[255]; - sprintf( filename_buf, "../%s", filename ); - if ( ( sdl_surf = SDL_LoadBMP( filename_buf )) == NULL ) { LOG("...failed to load graphics from : " << filename_buf ); @@ -1341,8 +1338,21 @@ SDL_Surface* CSdl::LoadBitmap( const char *filename, int32_t file_offset, Uint32 SDL_Surface *sdl_surf = NULL; // temp surface FILE *fp = NULL; // file pointer SDL_RWops *sdl_rw = NULL; // sdl_read_write_operations + String tmp; - if ( ( fp = fopen( filename, "rb")) == NULL ) +#ifdef LINUX_BUILD + if ( filename[0] != '/' ) + { + tmp = String(sys_datadir).append("/autos/").append(filename); + } + else + { + tmp = String(filename); + } +#else + tmp = String(filename); +#endif + if ( ( fp = fopen( tmp.c_str(), "rb")) == NULL ) { LOG("...failed to open file : " << filename ); return NULL; diff --git a/src/CSounds.cpp b/src/CSounds.cpp index fdab2b9..e4a88d7 100644 --- a/src/CSounds.cpp +++ b/src/CSounds.cpp @@ -52,14 +52,31 @@ bool CSounds::Initialize( CSdl *pSdl ) this->_sdl = pSdl; #if defined(WITH_FMOD) || defined(WITH_SDLMIXER) - -#define LOAD_SOUND( container, name, buffered ) if ( (sounds[container] = _sdl->LoadSound( name, buffered )) == -1 ) { \ - LOG( "Failed to load " << name << " ! "); \ - return false; } - -#define LOAD_MUSIC( container, name ) if ( (music[container] = _sdl->LoadSound( name, false, true )) == -1 ) { \ - LOG( "Failed to load music " << name << " ! "); \ - return false; } + String tmp (sys_datadir); + +#define LOAD_SOUND( container, name, buffered) \ + do { \ + tmp.append("/").append(name); \ + sounds[container] = \ + _sdl->LoadSound( tmp.c_str(), buffered ); \ + if ( sounds[container] == -1 ) { \ + LOG( "Failed to load " << name << " ! " ); \ + return false; \ + } \ + tmp.resize(strlen(sys_datadir)); \ + } while(0) + +#define LOAD_MUSIC( container, name) \ + do { \ + tmp.append("/").append(name); \ + music[container] = \ + _sdl->LoadSound( tmp.c_str(), false, true ); \ + if ( music[container] == -1 ) { \ + LOG( "Failed to load music " << name << " ! " ); \ + return false; \ + } \ + tmp.resize(strlen(sys_datadir)); \ + } while(0) LOAD_SOUND( SND_CRASHLIGHT1, "sound/crash3.wav", true ); LOAD_SOUND( SND_CRASHLIGHT2, "sound/crash2.wav", true ); diff --git a/src/CSwv_module.cpp b/src/CSwv_module.cpp index c77f37c..a11c519 100644 --- a/src/CSwv_module.cpp +++ b/src/CSwv_module.cpp @@ -206,8 +206,6 @@ int CSwv_module::Load( char *filename, SWV_HEADER *swv_file ) // << " name: " << swv_file->pfiles[i].filename); // } - // set module filename - sprintf( swv_file->filename, "%s", filename ); if ( fp != NULL ) fclose( fp ); diff --git a/src/Main.cpp b/src/Main.cpp index 04290e5..3af6e4e 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -45,6 +45,13 @@ #include "Main.h" +const char *sys_datadir; +const char *usr_cfgdir; +const char *usr_datadir; + +char *ART_FILE; +char *BINDINGS_FILE; + int main( int argc, char *argv[] ) { bool hardware_support = true; @@ -59,12 +66,88 @@ int main( int argc, char *argv[] ) * ATI Mobility type of video cards. */ bool fullscreen = false; + String tmp; #ifdef LINUX_BUILD + sys_datadir = getenv("SAVAGEWHEELS_SYS_DATADIR"); + if (sys_datadir == NULL) + { + fprintf(stderr, "SAVAGEWHEELS_SYS_DATADIR not set.\n"); + return 1; + } + sys_datadir = strdup(sys_datadir); + + usr_cfgdir = getenv("SAVAGEWHEELS_USR_CONFDIR"); + if (usr_cfgdir == NULL) + { + fprintf(stderr, "SAVAGEWHEELS_USR_CONFDIR not set.\n"); + return 1; + } + usr_cfgdir = strdup(usr_cfgdir); + + usr_datadir = getenv("SAVAGEWHEELS_USR_DATADIR"); + if (usr_datadir == NULL) + { + fprintf(stderr, "SAVAGEWHEELS_USR_DATADIR not set.\n"); + return 1; + } + usr_datadir = strdup(usr_datadir); + + if (sys_datadir == NULL || usr_cfgdir == NULL || usr_datadir == NULL) + { + fprintf(stderr, "Insufficient memory. Execution aborted.\n"); + return 1; + } + setenv("SDL_VIDEO_CENTERED", "1", 1); #else + sys_datadir = usr_cfgdir = usr_datadir = "./"; _putenv("SDL_VIDEO_CENTERED=1"); #endif + int len; + len = snprintf(NULL, 0, "%s/graphics/gfxdata.kdf", sys_datadir); + if (len < 0) + { + fprintf(stderr, + "Unable to store '%s/graphics/gfxdata.kdf': %s\n", + sys_datadir, strerror(errno)); + return 1; + } + if (len == INT_MAX) + { + fprintf(stderr, "Unable to store '%s/graphics/gfxdata.kdf': " + "Path too log\n", sys_datadir); + return 1; + } + ART_FILE = new (std::nothrow) char[len + 1]; + if (ART_FILE == NULL) + { + fprintf(stderr, "Insufficent memory. Execution aborted.\n"); + return 1; + } + sprintf(ART_FILE, "%s/graphics/gfxdata.kdf", sys_datadir); + + len = snprintf(NULL, 0, "%s/bindings.xml", usr_cfgdir); + if (len < 0) + { + fprintf(stderr, + "Unable to store '%s/bindings.xml': %s\n", usr_cfgdir, + strerror(errno)); + return 1; + } + if (len == INT_MAX) + { + fprintf(stderr, "Unable to store '%s/bindings.xml': " + "Path too log\n", usr_cfgdir); + return 1; + } + BINDINGS_FILE = new (std::nothrow) char[len + 1]; + if (BINDINGS_FILE == NULL) + { + fprintf(stderr, "Insufficent memory. Execution aborted.\n"); + return 1; + } + sprintf(BINDINGS_FILE, "%s/bindings.xml", usr_cfgdir); if (argc > 1) { for (int i = 1; i < argc; i++) { @@ -106,7 +189,8 @@ int main( int argc, char *argv[] ) * Load & Start Game */ - OpenLog("debug.html"); + tmp = String(usr_datadir).append("/debug.html"); + OpenLog(tmp.c_str()); CGame game; game.Execute(fullscreen, hardware_support); diff --git a/src/Main.h b/src/Main.h index 38b1555..93b9c6a 100644 --- a/src/Main.h +++ b/src/Main.h @@ -37,6 +37,7 @@ #include #include #include +#include #include #include @@ -86,8 +87,6 @@ #include "Config.h" // --- global game defines -#define ART_FILE "graphics/gfxdata.kdf" -#define BINDINGS_FILE "bindings.xml" #define LOAD_OK (-1) #define LOAD_FAILED (0) #define HRESULT(x) ( (x) == NULL : LOAD_OK ? LOAD_FAILED ) @@ -102,6 +101,12 @@ typedef std::string String; typedef std::ostringstream OutputSStream; +extern const char *sys_datadir; +extern const char *usr_cfgdir; +extern const char *usr_datadir; + +extern char *ART_FILE; +extern char *BINDINGS_FILE; //#include "pstdint.h" // portable types #include "Utils.h" #include "CKdf.h" diff --git a/src/Utils.cpp b/src/Utils.cpp index 215e018..8200edc 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -263,7 +263,7 @@ bool OpenLog ( const char* filename ) String time( GetFormattedTime() ); // open debug file - debug_file.open ( "debug.html", std::ios::out ); //ios::ate ); + debug_file.open ( filename, std::ios::out ); //ios::ate ); if ( ! debug_file.good() ) return false; diff --git a/sw1.png b/sw1.png new file mode 100644 index 0000000..339554e Binary files /dev/null and b/sw1.png differ