From a3472f3e04342db770e057714138aa0abfb9614c Mon Sep 17 00:00:00 2001 From: pouillot Date: Sun, 11 Nov 2012 15:38:27 +0000 Subject: [PATCH] Re #755 Applied Joe's menu-music-5040.patch : menu music first step git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@5042 30fe4595-0a0c-4342-8851-515496e4dcbd Former-commit-id: 87495f3c30b0f30c1a875d081960cecd6dabb40d Former-commit-id: 7cae952707f8401162d76aefd9981452fc7911ea --- INSTALL.txt | 6 ++ cmake/CMakeLists.txt | 3 +- cmake/FindOGG.cmake | 95 ++++++++++++++++++ cmake/FindVORBIS.cmake | 95 ++++++++++++++++++ cmake/FindVORBISFILE.cmake | 95 ++++++++++++++++++ cmake/checks.cmake | 31 ++++++ cmake/customthirdparty.cmake | 34 ++++++- cmake/options.cmake | 8 +- cmake/thirdpartydeps.cmake | 96 +++++++++++++++++++ src/libs/tgfclient/CMakeLists.txt | 27 ++++++ src/libs/tgfclient/gui.cpp | 6 +- src/libs/tgfclient/guiscreen.cpp | 6 +- src/libs/tgfclient/musicplayer.cpp | 82 +++++++++++++--- src/libs/tgfclient/musicplayer.h | 17 +++- src/libs/tgfclient/oggsoundstream.cpp | 6 +- src/libs/tgfclient/oggsoundstream.h | 10 +- src/libs/tgfclient/openalmusicplayer.cpp | 32 +++++-- src/libs/tgfclient/openalmusicplayer.h | 5 +- src/libs/tgfclient/soundstream.cpp | 4 +- src/libs/tgfclient/soundstream.h | 6 +- .../userinterface/legacymenu/legacymenu.cpp | 3 + .../legacymenu/racescreens/racepitmenu.cpp | 2 + .../racescreens/racerunningmenus.cpp | 9 ++ .../legacymenu/racescreens/racestopmenu.cpp | 3 + 24 files changed, 636 insertions(+), 45 deletions(-) create mode 100644 cmake/FindOGG.cmake create mode 100644 cmake/FindVORBIS.cmake create mode 100644 cmake/FindVORBISFILE.cmake diff --git a/INSTALL.txt b/INSTALL.txt index d85978d40..dc9283098 100644 --- a/INSTALL.txt +++ b/INSTALL.txt @@ -34,6 +34,7 @@ I - Pre-requisites Linux: Be carefull to compile plib with -fPIC on AMD64 if you run a 64 bit version. - OpenAL soft 1.5 / 1.6 / 1.11 / 1.14 (http://connect.creativelabs.com/openal) (Torcs modified 0.0.8 from www.torcs.org also used to work in the past). +- libOGG 1.3 or newer and libVorbis 1.3 or newer (optional for the moment, will soon get mandatory) - ENet 1.3.2/4 (http://enet.bespin.org) Linux: Be careful to compile ENet with -fPIC on AMD64 if you run a 64 bit build. - Expat 2 (can be skipped for the moment, but won't anymore soon) @@ -171,6 +172,7 @@ The Speed Dreams Team. - CMAKE_PREFIX_PATH:STRING : Path prefixes for additional 3rdParty libraries (def:empty) (use /usr/local if you compiled some 3rdParty libs yourself). + - CMAKE_INSTALL_PREFIX:PATH : Install path for Speed Dreams (def: /usr/local) @@ -184,6 +186,10 @@ The Speed Dreams Team. on most Linux distros (only Fedora is working on this right now, AFAIK, 2012, July) Ask the dev team for any hint about building it ... + - OPTION_MENU_MUSIC:BOOL : + Enable building with the new Menu Music enabled (def: OFF) + Note: This requires libogg, libvorbis, and libvorbisfile (these dependencies are new for 2.1) + - OPTION_TRACE:BOOL : Full run-time traces if ON (def: ON) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index dbb34f715..fe689eb80 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -1,3 +1,4 @@ INCLUDE(../cmake/macros.cmake) -SD_INSTALL_FILES(DATA cmake FILES splitargn.cmake robot.def.in.cmake FindENET.cmake FindPLIB.cmake FindSOLID.cmake) +SD_INSTALL_FILES(DATA cmake FILES splitargn.cmake robot.def.in.cmake FindENET.cmake FindPLIB.cmake FindSOLID.cmake + FindOGG.cmake FindVORBISFILE.cmake FindVORBIS.cmake) diff --git a/cmake/FindOGG.cmake b/cmake/FindOGG.cmake new file mode 100644 index 000000000..dc3a51182 --- /dev/null +++ b/cmake/FindOGG.cmake @@ -0,0 +1,95 @@ +# Locate OGG libraries () +# This module defines +# OGG_LIBRARY : list of lib names +# OGG_FOUND : if false, do not try to link to OGG +# OGG_INCLUDE_DIR : where to find the headers +# +# $OGG_DIR is an environment variable that would +# correspond to the ./configure --prefix=$OGG_DIR +# used in building OGG. +# +# Created by Joe Thompson (based on Jean-Philippe Meuret's FindSOLID.cmake). + +# No use to do all of this twice. +IF(OGG_FOUND) + RETURN() +ENDIF(OGG_FOUND) + +# First, try with PkgConfig if available. +FIND_PACKAGE(PkgConfig) +IF(PKGCONFIG_FOUND) + + PKG_CHECK_MODULES(OGG ogg) + IF(NOT OGG_FOUND) + PKG_CHECK_MODULES(OGG OGG) + ENDIF (NOT OGG_FOUND) + + IF(OGG_FOUND) + SET(OGG_FOUND TRUE) + SET(OGG_INCLUDE_DIR ${OGG_INCLUDE_DIRS} CACHE STRING "OGG include paths") + SET(OGG_LIBRARY ${OGG_LIBRARIES} CACHE STRING "OGG library") + MESSAGE(STATUS "Looking for OGG --- found using pkg-config (${OGG_LIBRARY})") + RETURN() + ENDIF(OGG_FOUND) + +ENDIF(PKGCONFIG_FOUND) + +# Then try the good old way for include dirs. +IF(NOT APPLE) + + FIND_PATH(OGG_INCLUDE_DIR ogg/ogg.h + HINTS ENV OGG_DIR + PATH_SUFFIXES + include/ogg include/OGG + PATHS + /usr /usr/local + DOC "Non-Apple include dir for OGG") + +ELSE(NOT APPLE) + + FIND_PATH(OGG_INCLUDE_DIR ogg.h + HINTS ENV OGG_DIR + PATH_SUFFIXES + Headers include/ogg + PATHS + #Additional MacOS Paths + ~/Library/Frameworks/OGG.framework + /Library/Frameworks/OGG.framework + /System/Library/Frameworks/OGG.framework # Tiger + + /usr /usr/local + DOC "Apple include dir for OGG") + +ENDIF(NOT APPLE) + +# Then try the good old way for libs. +FIND_LIBRARY(OGG_LIBRARY + NAMES ogg + HINTS ENV OGG_DIR + PATH_SUFFIXES lib64 lib libs64 libs libs/Win32 libs/Win64 + PATHS /usr /usr/local) + +IF(WIN32) + + FIND_LIBRARY(OGG_LIBRARY + NAMES ogg + HINTS ENV OGG_DIR + PATH_SUFFIXES lib64 lib libs64 libs libs/Win32 libs/Win64 + PATHS /usr /usr/local) + +ENDIF(WIN32) + +IF(OGG_INCLUDE_DIR AND OGG_LIBRARY AND (NOT WIN32 OR OGG_LIBRARY)) + SET(OGG_FOUND TRUE) +ENDIF(OGG_INCLUDE_DIR AND OGG_LIBRARY AND (NOT WIN32 OR OGG_LIBRARY)) + +IF(OGG_FOUND) + MESSAGE(STATUS "Looking for OGG - found (${OGG_LIBRARY})") + SET(OGG_LIBRARY ${OGG_LIBRARY}) + IF(WIN32) + SET(OGG_LIBRARY ${OGG_LIBRARY}) + ENDIF(WIN32) +ELSE(OGG_FOUND) + MESSAGE(FATAL_ERROR "Could not find OGG") +ENDIF(OGG_FOUND) + diff --git a/cmake/FindVORBIS.cmake b/cmake/FindVORBIS.cmake new file mode 100644 index 000000000..bd5b3c934 --- /dev/null +++ b/cmake/FindVORBIS.cmake @@ -0,0 +1,95 @@ +# Locate VORBIS libraries () +# This module defines +# VORBIS_LIBRARY : list of lib names +# VORBIS_FOUND : if false, do not try to link to VORBIS +# VORBIS_INCLUDE_DIR : where to find the headers +# +# $VORBIS_DIR is an environment variable that would +# correspond to the ./configure --prefix=$VORBIS_DIR +# used in building VORBIS. +# +# Created by Joe Thompson (based on Jean-Philippe Meuret's FindSOLID.cmake). + +# No use to do all of this twice. +IF(VORBIS_FOUND) + RETURN() +ENDIF(VORBIS_FOUND) + +# First, try with PkgConfig if available. +FIND_PACKAGE(PkgConfig) +IF(PKGCONFIG_FOUND) + + PKG_CHECK_MODULES(VORBIS vorbis) + IF(NOT VORBIS_FOUND) + PKG_CHECK_MODULES(VORBIS VORBIS) + ENDIF (NOT VORBIS_FOUND) + + IF(VORBIS_FOUND) + SET(VORBIS_FOUND TRUE) + SET(VORBIS_INCLUDE_DIR ${VORBIS_INCLUDE_DIRS} CACHE STRING "VORBIS include paths") + SET(VORBIS_LIBRARY ${VORBIS_LIBRARIES} CACHE STRING "VORBIS library") + MESSAGE(STATUS "Looking for VORBIS --- found using pkg-config (${VORBIS_LIBRARY})") + RETURN() + ENDIF(VORBIS_FOUND) + +ENDIF(PKGCONFIG_FOUND) + +# Then try the good old way for include dirs. +IF(NOT APPLE) + + FIND_PATH(VORBIS_INCLUDE_DIR vorbis/vorbisfile.h + HINTS ENV VORBIS_DIR + PATH_SUFFIXES + include/vorbis include/VORBIS + PATHS + /usr /usr/local + DOC "Non-Apple include dir for VORBIS") + +ELSE(NOT APPLE) + + FIND_PATH(VORBIS_INCLUDE_DIR vorbisfile.h + HINTS ENV VORBIS_DIR + PATH_SUFFIXES + Headers include/vorbis + PATHS + #Additional MacOS Paths + ~/Library/Frameworks/VORBIS.framework + /Library/Frameworks/VORBIS.framework + /System/Library/Frameworks/VORBIS.framework # Tiger + + /usr /usr/local + DOC "Apple include dir for VORBIS") + +ENDIF(NOT APPLE) + +# Then try the good old way for libs. +FIND_LIBRARY(VORBIS_LIBRARY + NAMES vorbis + HINTS ENV VORBIS_DIR + PATH_SUFFIXES lib64 lib libs64 libs libs/Win32 libs/Win64 + PATHS /usr /usr/local) + +IF(WIN32) + + FIND_LIBRARY(VORBIS_LIBRARY + NAMES vorbis + HINTS ENV VORBIS_DIR + PATH_SUFFIXES lib64 lib libs64 libs libs/Win32 libs/Win64 + PATHS /usr /usr/local) + +ENDIF(WIN32) + +IF(VORBIS_INCLUDE_DIR AND VORBIS_LIBRARY AND (NOT WIN32 OR VORBIS_LIBRARY)) + SET(VORBIS_FOUND TRUE) +ENDIF(VORBIS_INCLUDE_DIR AND VORBIS_LIBRARY AND (NOT WIN32 OR VORBIS_LIBRARY)) + +IF(VORBIS_FOUND) + MESSAGE(STATUS "Looking for VORBIS - found (${VORBIS_LIBRARY})") + SET(VORBIS_LIBRARY ${VORBIS_LIBRARY}) + IF(WIN32) + SET(VORBIS_LIBRARY ${VORBIS_LIBRARY}) + ENDIF(WIN32) +ELSE(VORBIS_FOUND) + MESSAGE(FATAL_ERROR "Could not find VORBIS") +ENDIF(VORBIS_FOUND) + diff --git a/cmake/FindVORBISFILE.cmake b/cmake/FindVORBISFILE.cmake new file mode 100644 index 000000000..83bfc3944 --- /dev/null +++ b/cmake/FindVORBISFILE.cmake @@ -0,0 +1,95 @@ +# Locate VORBISFILE libraries () +# This module defines +# VORBISFILE_LIBRARY : list of lib names +# VORBISFILE_FOUND : if false, do not try to link to VORBISFILE +# VORBISFILE_INCLUDE_DIR : where to find the headers +# +# $VORBISFILE_DIR is an environment variable that would +# correspond to the ./configure --prefix=$VORBISFILE_DIR +# used in building VORBISFILE. +# +# Created by Joe Thompson (based on Jean-Philippe Meuret's FindSOLID.cmake). + +# No use to do all of this twice. +IF(VORBISFILE_FOUND) + RETURN() +ENDIF(VORBISFILE_FOUND) + +# First, try with PkgConfig if available. +FIND_PACKAGE(PkgConfig) +IF(PKGCONFIG_FOUND) + + PKG_CHECK_MODULES(VORBISFILE vorbisfile) + IF(NOT VORBISFILE_FOUND) + PKG_CHECK_MODULES(VORBISFILE VORBISFILE) + ENDIF (NOT VORBISFILE_FOUND) + + IF(VORBISFILE_FOUND) + SET(VORBISFILE_FOUND TRUE) + SET(VORBISFILE_INCLUDE_DIR ${VORBISFILE_INCLUDE_DIRS} CACHE STRING "VORBISFILE include paths") + SET(VORBISFILE_LIBRARY ${VORBISFILE_LIBRARIES} CACHE STRING "VORBISFILE library") + MESSAGE(STATUS "Looking for VORBISFILE --- found using pkg-config (${VORBISFILE_LIBRARY})") + RETURN() + ENDIF(VORBISFILE_FOUND) + +ENDIF(PKGCONFIG_FOUND) + +# Then try the good old way for include dirs. +IF(NOT APPLE) + + FIND_PATH(VORBISFILE_INCLUDE_DIR vorbis/vorbisfile.h + HINTS ENV VORBISFILE_DIR + PATH_SUFFIXES + include/vorbis include/VORBIS + PATHS + /usr /usr/local + DOC "Non-Apple include dir for VORBISFILE") + +ELSE(NOT APPLE) + + FIND_PATH(VORBISFILE_INCLUDE_DIR vorbisfile.h + HINTS ENV VORBISFILE_DIR + PATH_SUFFIXES + Headers include/vorbis + PATHS + #Additional MacOS Paths + ~/Library/Frameworks/VORBIS.framework + /Library/Frameworks/VORBIS.framework + /System/Library/Frameworks/VORBIS.framework # Tiger + + /usr /usr/local + DOC "Apple include dir for VORBISFILE") + +ENDIF(NOT APPLE) + +# Then try the good old way for libs. +FIND_LIBRARY(VORBISFILE_LIBRARY + NAMES vorbisfile + HINTS ENV VORBISFILE_DIR + PATH_SUFFIXES lib64 lib libs64 libs libs/Win32 libs/Win64 + PATHS /usr /usr/local) + +IF(WIN32) + + FIND_LIBRARY(VORBISFILE_LIBRARY + NAMES vorbisfile + HINTS ENV VORBISFILE_DIR + PATH_SUFFIXES lib64 lib libs64 libs libs/Win32 libs/Win64 + PATHS /usr /usr/local) + +ENDIF(WIN32) + +IF(VORBISFILE_INCLUDE_DIR AND VORBISFILE_LIBRARY AND (NOT WIN32 OR VORBISFILE_LIBRARY)) + SET(VORBISFILE_FOUND TRUE) +ENDIF(VORBISFILE_INCLUDE_DIR AND VORBISFILE_LIBRARY AND (NOT WIN32 OR VORBISFILE_LIBRARY)) + +IF(VORBISFILE_FOUND) + MESSAGE(STATUS "Looking for VORBISFILE - found (${VORBISFILE_LIBRARY})") + SET(VORBISFILE_LIBRARY ${VORBISFILE_LIBRARY}) + IF(WIN32) + SET(VORBISFILE_LIBRARY ${VORBISFILE_LIBRARY}) + ENDIF(WIN32) +ELSE(VORBISFILE_FOUND) + MESSAGE(FATAL_ERROR "Could not find VORBISFILE") +ENDIF(VORBISFILE_FOUND) + diff --git a/cmake/checks.cmake b/cmake/checks.cmake index 4502e8853..22455a643 100644 --- a/cmake/checks.cmake +++ b/cmake/checks.cmake @@ -151,6 +151,37 @@ MACRO(CHECK_LIBRARIES) MESSAGE(STATUS "Looking for library OpenAL - NOT found") ENDIF(OPENAL_FOUND) + IF(OPTION_MENU_MUSIC) + + # Ogg + Find_Package(OGG) + IF(OGG_FOUND) + SET(HAVE_LIBOGG 1) + MESSAGE(STATUS "Looking for library Ogg - found") + ELSE(OGG_FOUND) + MESSAGE(STATUS "Looking for library Ogg - NOT found") + ENDIF(OGG_FOUND) + + # Vorbis + Find_Package(VORBIS) + IF(VORBIS_FOUND) + SET(HAVE_LIBVORBIS 1) + MESSAGE(STATUS "Looking for library Vorbis - found") + ELSE(VORBIS_FOUND) + MESSAGE(STATUS "Looking for library Vorbis - NOT found") + ENDIF(VORBIS_FOUND) + + # VorbisFile + Find_Package(VORBISFILE) + IF(VORBISFILE_FOUND) + SET(HAVE_LIBVORBISFILE 1) + MESSAGE(STATUS "Looking for library VorbisFile - found") + ELSE(VORBISFILE_FOUND) + MESSAGE(STATUS "Looking for library VorbisFile - NOT found") + ENDIF(VORBISFILE_FOUND) + + ENDIF(OPTION_MENU_MUSIC) + # ENet Find_Package(ENET) diff --git a/cmake/customthirdparty.cmake b/cmake/customthirdparty.cmake index fc981bcd8..c178cb58b 100644 --- a/cmake/customthirdparty.cmake +++ b/cmake/customthirdparty.cmake @@ -111,6 +111,22 @@ MACRO(_FIND_3RDPARTY_DEPENDENCIES ROOT_DIR) # Open AL. _FIND_3RDPARTY_DEPENDENCY(OPENAL AL/al.h "" openal32 ${ROOT_DIR} "") + + # Menu Music requires ogg, vorbis, and vorbisfile + # this option may be removed after Menu Music becomes on by default + # and these libs become part of Official 3rdParty package + IF(OPTION_MENU_MUSIC) + + # OGG. + _FIND_3RDPARTY_DEPENDENCY(OGG ogg/ogg.h "" libogg ${ROOT_DIR} "") + + # Vorbis. + _FIND_3RDPARTY_DEPENDENCY(VORBIS vorbis/vorbisfile.h "" libvorbis ${ROOT_DIR} "") + + # VorbisFile. + _FIND_3RDPARTY_DEPENDENCY(VORBISFILE vorbis/vorbisfile.h "" libvorbisfile ${ROOT_DIR} "") + + ENDIF(OPTION_MENU_MUSIC) # ENet. _FIND_3RDPARTY_DEPENDENCY(ENET enet/enet.h "" enet ${ROOT_DIR} "") @@ -220,7 +236,7 @@ MACRO(_FIND_3RDPARTY_DLL PACKAGE_NAME LINK_LIBRARY NAME_HINTS DLL_PATHNAME_VAR) ENDFOREACH(_LIB_NAME ${NAME_HINTS}) IF(NOT ${_DLL_PATHNAME_VAR}) - #MESSAGE(STATUS "Could not find 3rdParty DLL in ${NAME_HINTS} for ${PACKAGE_NAME}") + MESSAGE(STATUS "Could not find 3rdParty DLL in ${NAME_HINTS} for ${PACKAGE_NAME}") ENDIF(NOT ${_DLL_PATHNAME_VAR}) ENDMACRO(_FIND_3RDPARTY_DLL DLL_PATHNAME) @@ -232,6 +248,22 @@ MACRO(SD_INSTALL_CUSTOM_3RDPARTY) _FIND_3RDPARTY_DLL("OpenAL" "${OPENAL_LIBRARY}" "OpenAL32" _DLL_PATHNAME) LIST(APPEND _THIRDPARTY_DLL_PATHNAMES "${_DLL_PATHNAME}") + # Menu Music requires ogg, vorbis, and vorbisfile + # this option may be removed after Menu Music becomes on by default + # and these libs become part of Official 3rdParty package + IF(OPTION_MENU_MUSIC) + + _FIND_3RDPARTY_DLL("OGG" "${OGG_LIBRARY}" "libogg;libogg-0" _DLL_PATHNAME) + LIST(APPEND _THIRDPARTY_DLL_PATHNAMES "${_DLL_PATHNAME}") + + _FIND_3RDPARTY_DLL("VORBIS" "${VORBIS_LIBRARY}" "libvorbis;libvorbis-0" _DLL_PATHNAME) + LIST(APPEND _THIRDPARTY_DLL_PATHNAMES "${_DLL_PATHNAME}") + + _FIND_3RDPARTY_DLL("VORBISFILE" "${VORBISFILE_LIBRARY}" "libvorbisfile;libvorbisfile-3" _DLL_PATHNAME) + LIST(APPEND _THIRDPARTY_DLL_PATHNAMES "${_DLL_PATHNAME}") + + ENDIF(OPTION_MENU_MUSIC) + _FIND_3RDPARTY_DLL("SDL" "${SDL_LIBRARY}" "SDL" _DLL_PATHNAME) LIST(APPEND _THIRDPARTY_DLL_PATHNAMES "${_DLL_PATHNAME}") diff --git a/cmake/options.cmake b/cmake/options.cmake index 6a5eeeb18..238158532 100644 --- a/cmake/options.cmake +++ b/cmake/options.cmake @@ -64,6 +64,8 @@ MACRO(ADD_SD_COMPILE_OPTIONS) SET(OPTION_3RDPARTY_EXPAT true CACHE BOOL "Use 3rd party Expat library rather than bundled TXML") + SET(OPTION_MENU_MUSIC false CACHE BOOL "Enable Menu Music") + # Enable building with 3rd party SOLID library under Windows, as we ship the binary package, # but not under Linux, where FreeSolid seems not to be available by default on most distros. IF(WIN32) @@ -135,6 +137,10 @@ MACRO(ADD_SD_COMPILE_OPTIONS) IF(OPTION_3RDPARTY_EXPAT) ADD_DEFINITIONS(-DTHIRD_PARTY_EXPAT) ENDIF(OPTION_3RDPARTY_EXPAT) + + IF(OPTION_MENU_MUSIC) + ADD_DEFINITIONS(-DMENU_MUSIC) + ENDIF(OPTION_MENU_MUSIC) IF(OPTION_3RDPARTY_SOLID) ADD_DEFINITIONS(-DTHIRD_PARTY_SOLID) @@ -165,4 +171,4 @@ MACRO(ADD_SD_COMPILE_OPTIONS) ENDIF(NOT _ALREADY_DONE) -ENDMACRO(ADD_SD_COMPILE_OPTIONS) +ENDMACRO(ADD_SD_COMPILE_OPTIONS) \ No newline at end of file diff --git a/cmake/thirdpartydeps.cmake b/cmake/thirdpartydeps.cmake index 6b2ae3655..0a09f545d 100644 --- a/cmake/thirdpartydeps.cmake +++ b/cmake/thirdpartydeps.cmake @@ -148,6 +148,102 @@ MACRO(ADD_OPENAL_LIBRARY TARGET) ENDMACRO(ADD_OPENAL_LIBRARY TARGET) +MACRO(ADD_OGG_INCLUDEDIR) + + IF(OPTION_MENU_MUSIC) + + FIND_PACKAGE(OGG) + + IF(OGG_FOUND) + INCLUDE_DIRECTORIES(${OGG_INCLUDE_DIR}) + ELSE(OGG_FOUND) + MESSAGE(FATAL_ERROR "Cannot find OGG header files") + ENDIF(OGG_FOUND) + + ENDIF(OPTION_MENU_MUSIC) + +ENDMACRO(ADD_OGG_INCLUDEDIR) + +MACRO(ADD_OGG_LIBRARY TARGET) + + IF(OPTION_MENU_MUSIC) + + FIND_PACKAGE(OGG) + + IF(OGG_FOUND) + TARGET_LINK_LIBRARIES(${TARGET} ${OGG_LIBRARY}) + ELSE(OGG_FOUND) + MESSAGE(FATAL_ERROR "Cannot find OGG libraries") + ENDIF(OGG_FOUND) + + ENDIF(OPTION_MENU_MUSIC) + +ENDMACRO(ADD_OGG_LIBRARY TARGET) + +MACRO(ADD_VORBIS_INCLUDEDIR) + + IF(OPTION_MENU_MUSIC) + + FIND_PACKAGE(VORBIS) + + IF(VORBIS_FOUND) + INCLUDE_DIRECTORIES(${VORBIS_INCLUDE_DIR}) + ELSE(VORBIS_FOUND) + MESSAGE(FATAL_ERROR "Cannot find VORBIS header files") + ENDIF(VORBIS_FOUND) + + ENDIF(OPTION_MENU_MUSIC) + +ENDMACRO(ADD_VORBIS_INCLUDEDIR) + +MACRO(ADD_VORBIS_LIBRARY TARGET) + + IF(OPTION_MENU_MUSIC) + + FIND_PACKAGE(VORBIS) + + IF(VORBIS_FOUND) + TARGET_LINK_LIBRARIES(${TARGET} ${VORBIS_LIBRARY}) + ELSE(VORBIS_FOUND) + MESSAGE(FATAL_ERROR "Cannot find VORBIS libraries") + ENDIF(VORBIS_FOUND) + + ENDIF(OPTION_MENU_MUSIC) + +ENDMACRO(ADD_VORBIS_LIBRARY TARGET) + +MACRO(ADD_VORBISFILE_INCLUDEDIR) + + IF(OPTION_MENU_MUSIC) + + FIND_PACKAGE(VORBISFILE) + + IF(VORBISFILE_FOUND) + INCLUDE_DIRECTORIES(${VORBISFILE_INCLUDE_DIR}) + ELSE(VORBISFILE_FOUND) + MESSAGE(FATAL_ERROR "Cannot find VORBISFILE header files") + ENDIF(VORBISFILE_FOUND) + + ENDIF(OPTION_MENU_MUSIC) + +ENDMACRO(ADD_VORBISFILE_INCLUDEDIR) + +MACRO(ADD_VORBISFILE_LIBRARY TARGET) + + IF(OPTION_MENU_MUSIC) + + FIND_PACKAGE(VORBISFILE) + + IF(VORBISFILE_FOUND) + TARGET_LINK_LIBRARIES(${TARGET} ${VORBISFILE_LIBRARY}) + ELSE(VORBISFILE_FOUND) + MESSAGE(FATAL_ERROR "Cannot find VORBISFILE libraries") + ENDIF(VORBISFILE_FOUND) + + ENDIF(OPTION_MENU_MUSIC) + +ENDMACRO(ADD_VORBISFILE_LIBRARY TARGET) + MACRO(ADD_ENET_INCLUDEDIR) FIND_PACKAGE(ENET) diff --git a/src/libs/tgfclient/CMakeLists.txt b/src/libs/tgfclient/CMakeLists.txt index 0480ebe9e..e7f1b8ad9 100644 --- a/src/libs/tgfclient/CMakeLists.txt +++ b/src/libs/tgfclient/CMakeLists.txt @@ -7,6 +7,8 @@ ADD_SDLIB_INCLUDEDIR(tgf math portability) ADD_SDL_INCLUDEDIR() ADD_JPEG_INCLUDEDIR() ADD_PLIB_INCLUDEDIR() +ADD_OPENAL_INCLUDEDIR() +ADD_VORBIS_INCLUDEDIR() SET(TGFCLIENT_SOURCES control.cpp glfeatures.cpp guibutton.cpp guifont.cpp @@ -15,9 +17,18 @@ SET(TGFCLIENT_SOURCES control.cpp glfeatures.cpp guibutton.cpp guifont.cpp guilabel.cpp guiobject.cpp guiscrollist.cpp guicombobox.cpp guicheckbox.cpp guiprogresbar.cpp guiscreen.cpp guieventloop.cpp guiapplication.cpp + musicplayer.cpp musicplayer.h glfeatures.h gui.h guiscreen.h guimenu.h tgfclient.h guifont.h ) SET(TGFCLIENT_OTHER_SOURCES guimenutest.xml screen.xml) +# Note: Menu music sources needed ONLY if menu music enabled. +IF(OPTION_MENU_MUSIC) + SET(TGFCLIENT_SOURCES ${TGFCLIENT_SOURCES} + soundstream.cpp soundstream.h + oggsoundstream.cpp oggsoundstream.h + openalmusicplayer.cpp openalmusicplayer.h ) +ENDIF(OPTION_MENU_MUSIC) + #disable developer warning IF (COMMAND CMAKE_POLICY) CMAKE_POLICY(SET CMP0003 NEW) @@ -52,6 +63,22 @@ IF(OPENGL_FOUND) TARGET_LINK_LIBRARIES(tgfclient ${OPENGL_LIBRARY}) ENDIF(OPENGL_FOUND) +IF(OPENAL_FOUND) + TARGET_LINK_LIBRARIES(tgfclient ${OPENAL_LIBRARY}) +ENDIF(OPENAL_FOUND) + +IF(OPTION_MENU_MUSIC) + IF(VORBIS_FOUND) + TARGET_LINK_LIBRARIES(tgfclient ${VORBIS_LIBRARY}) + ENDIF(VORBIS_FOUND) + IF(VORBISFILE_FOUND) + TARGET_LINK_LIBRARIES(tgfclient ${VORBISFILE_LIBRARY}) + ENDIF(VORBISFILE_FOUND) + IF(OGG_FOUND) + TARGET_LINK_LIBRARIES(tgfclient ${OGG_LIBRARY}) + ENDIF(OGG_FOUND) +ENDIF(OPTION_MENU_MUSIC) + ADD_PLIB_LIBRARY(tgfclient ul sg js) ADD_SDL_LIBRARY(tgfclient) diff --git a/src/libs/tgfclient/gui.cpp b/src/libs/tgfclient/gui.cpp index 0fd5287ba..70dad94a2 100644 --- a/src/libs/tgfclient/gui.cpp +++ b/src/libs/tgfclient/gui.cpp @@ -40,6 +40,7 @@ #include "tgfclient.h" #include "gui.h" #include "guimenu.h" +#include "musicplayer.h" tGfuiScreen *GfuiScreen; /* current screen */ @@ -115,6 +116,7 @@ gfuiInit(void) gfuiInitLabel(); gfuiInitHelp(); gfuiInitMenu(); + startMenuMusic(); //gfctrlJoyInit(); // Not here ; done later on the fly, when really needed. } @@ -123,6 +125,7 @@ void gfuiShutdown(void) { gfctrlJoyShutdown(); + stopMenuMusic(); } GfuiColor @@ -1098,5 +1101,4 @@ void GfuiSwapBuffers(void) { SDL_GL_SwapBuffers(); -} - +} \ No newline at end of file diff --git a/src/libs/tgfclient/guiscreen.cpp b/src/libs/tgfclient/guiscreen.cpp index 162efe411..b4ebd97c7 100644 --- a/src/libs/tgfclient/guiscreen.cpp +++ b/src/libs/tgfclient/guiscreen.cpp @@ -319,9 +319,9 @@ static void gfScrReshapeViewport(int width, int height) bool GfScrInit(int nWinWidth, int nWinHeight, int nFullScreen) { // Initialize SDL video subsystem (and exit if not supported). - if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) + if (SDL_InitSubSystem(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) { - GfLogError("Couldn't initialize SDL video sub-system (%s)\n", SDL_GetError()); + GfLogError("Couldn't initialize SDL audio/video sub-system (%s)\n", SDL_GetError()); return false; } @@ -815,4 +815,4 @@ int GfScrCaptureAsPNG(const char *filename) GfLogError("Failed to capture screen to %s\n", filename); return nStatus; -} +} \ No newline at end of file diff --git a/src/libs/tgfclient/musicplayer.cpp b/src/libs/tgfclient/musicplayer.cpp index 410c4df31..3dd716f4e 100644 --- a/src/libs/tgfclient/musicplayer.cpp +++ b/src/libs/tgfclient/musicplayer.cpp @@ -17,19 +17,28 @@ * * ***************************************************************************/ -#include "musicplayer.h" - -#include +#include "musicplayer.h" + +//#include #include #include +#include "tgfclient.h" #include -#include "OggSoundStream.h" -#include "OpenALMusicPlayer.h" +#if MENU_MUSIC +#include "oggsoundstream.h" +#include "openalmusicplayer.h" + + +static void playMenuMusic(int /* value */); -static bool isEnabled() -{ + static bool isEnabled() + { + // TODO - fix this (needs UI) + return true; + +#if 0 const int BUFSIZE = 1024; char buf[BUFSIZE]; snprintf(buf, BUFSIZE, "%s%s", GetLocalDir(), MM_SOUND_PARM_CFG); @@ -43,11 +52,13 @@ static bool isEnabled() } GfParmReleaseHandle(handle); + return enabled; +#endif } -// Path relative to CWD, e.g "data/music/torcs1.ogg" +// Path relative to CWD, e.g "data/music/main.ogg" static SoundStream* getMenuSoundStream(char* oggFilePath) { static OggSoundStream stream(oggFilePath); @@ -59,37 +70,80 @@ static OpenALMusicPlayer* getMusicPlayer() { const int BUFSIZE = 1024; char oggFilePath[BUFSIZE]; - strncpy(oggFilePath, "data/music/torcs1.ogg", BUFSIZE); + + // TODO - get from config?? + strncpy(oggFilePath, "data/music/main.ogg", BUFSIZE); static OpenALMusicPlayer player(getMenuSoundStream(oggFilePath)); return &player; } +// TODO rethink... +static Uint32 sdlTimerFunc(Uint32 interval, void* /* pEvLoopPriv */) +{ + playMenuMusic(0); + return 1; + //return 0; +} +// TODO clean this up +SDL_TimerID timerId = 0; static void playMenuMusic(int /* value */) { - const int nextcallinms = 100; + const int nextcallinms = 200; OpenALMusicPlayer* player = getMusicPlayer(); if (player->playAndManageBuffer()) { - glutTimerFunc(nextcallinms, playMenuMusic, 0); + if(timerId == 0){ + timerId = SDL_AddTimer(nextcallinms, sdlTimerFunc, (void*)NULL); + } + //glutTimerFunc(nextcallinms, playMenuMusic, 0); } } - - +#endif void startMenuMusic() { +#if MENU_MUSIC if (isEnabled()) { OpenALMusicPlayer* player = getMusicPlayer(); player->start(); playMenuMusic(0); } +#endif } void stopMenuMusic() { +#if MENU_MUSIC + if(timerId != 0){ + SDL_RemoveTimer(timerId); + timerId = 0; + } OpenALMusicPlayer* player = getMusicPlayer(); player->stop(); player->rewind(); -} \ No newline at end of file +#endif +} + +void pauseMenuMusic() +{ +#if MENU_MUSIC + if(timerId != 0){ + SDL_RemoveTimer(timerId); + timerId = 0; + } + OpenALMusicPlayer* player = getMusicPlayer(); + player->pause(); +#endif +} + +void resumeMenuMusic(int sourceId) +{ +#if MENU_MUSIC + if (isEnabled()) { + getMusicPlayer()->resume(sourceId); + playMenuMusic(0); + } +#endif +} diff --git a/src/libs/tgfclient/musicplayer.h b/src/libs/tgfclient/musicplayer.h index 31b4472a6..c8218c06a 100644 --- a/src/libs/tgfclient/musicplayer.h +++ b/src/libs/tgfclient/musicplayer.h @@ -26,7 +26,20 @@ #define MM_VAL_SOUND_ENABLED "enabled" #define MM_VAL_SOUND_DISABLED "disabled" -extern void startMenuMusic(); -extern void stopMenuMusic(); +// DLL exported symbols declarator for Windows. +#ifdef WIN32 +# ifdef TGFCLIENT_DLL +# define TGFCLIENT_API __declspec(dllexport) +# else +# define TGFCLIENT_API __declspec(dllimport) +# endif +#else +# define TGFCLIENT_API +#endif + +TGFCLIENT_API void startMenuMusic(); +TGFCLIENT_API void stopMenuMusic(); +TGFCLIENT_API void pauseMenuMusic(); +TGFCLIENT_API void resumeMenuMusic(int sourceId); #endif //__musicplayer_h__ \ No newline at end of file diff --git a/src/libs/tgfclient/oggsoundstream.cpp b/src/libs/tgfclient/oggsoundstream.cpp index fa76885b9..a74d65c3f 100644 --- a/src/libs/tgfclient/oggsoundstream.cpp +++ b/src/libs/tgfclient/oggsoundstream.cpp @@ -19,7 +19,7 @@ /* Concrete implementation for ogg sound streams */ -#include "OggSoundStream.h" +#include "oggsoundstream.h" #include OggSoundStream::OggSoundStream(char* path): @@ -62,7 +62,7 @@ OggSoundStream::~OggSoundStream() -bool OggSoundStream::read(char* buffer, const int bufferSize, int* resultSize, const char* error) +bool OggSoundStream::read(char* buffer, const int bufferSize, int* resultSize, const char*& error) { if (!isValid()) { error = "OggSoundStream: Invalid, no data available."; @@ -157,4 +157,4 @@ const char* OggSoundStream::errorString(int code) default: return "OggSoundStream: Unknown Ogg error."; } -} +} \ No newline at end of file diff --git a/src/libs/tgfclient/oggsoundstream.h b/src/libs/tgfclient/oggsoundstream.h index f6e32ac36..f941e6a13 100644 --- a/src/libs/tgfclient/oggsoundstream.h +++ b/src/libs/tgfclient/oggsoundstream.h @@ -21,11 +21,11 @@ ***************************************************************************/ /* Concrete implementation for ogg sound streams */ - -#define OV_EXCLUDE_STATIC_CALLBACKS + +#define OV_EXCLUDE_STATIC_CALLBACKS #include -#include "SoundStream.h" +#include "soundstream.h" class OggSoundStream : public SoundStream { @@ -36,7 +36,7 @@ class OggSoundStream : public SoundStream virtual int getRateInHz() { return rateInHz; } virtual SoundFormat getSoundFormat() { return format; } - virtual bool read(char* buffer, const int bufferSize, int* resultSize, const char* error); + virtual bool read(char* buffer, const int bufferSize, int* resultSize, const char*& error); virtual void rewind(); virtual void display(); virtual bool isValid() { return valid; } @@ -52,4 +52,4 @@ class OggSoundStream : public SoundStream SoundFormat format; }; -#endif // __OggSoundStream_h__ \ No newline at end of file +#endif // __OggSoundStream_h__ diff --git a/src/libs/tgfclient/openalmusicplayer.cpp b/src/libs/tgfclient/openalmusicplayer.cpp index e74669a43..d390f1a02 100644 --- a/src/libs/tgfclient/openalmusicplayer.cpp +++ b/src/libs/tgfclient/openalmusicplayer.cpp @@ -19,13 +19,14 @@ #include #include -#include "OpenALMusicPlayer.h" +#include "openalmusicplayer.h" const int OpenALMusicPlayer::BUFFERSIZE = 4096*64; OpenALMusicPlayer::OpenALMusicPlayer(SoundStream* soundStream): device(NULL), context(NULL), + previouscontext(NULL), source(0), stream(soundStream), ready(false) @@ -55,7 +56,7 @@ void OpenALMusicPlayer::stop() alSourceStop(source); - int queued; + int queued = 0; alGetSourcei(source, AL_BUFFERS_QUEUED, &queued); while (queued--) { @@ -69,7 +70,8 @@ void OpenALMusicPlayer::stop() alDeleteBuffers(2, buffers); check(); - alcMakeContextCurrent(NULL); + //alcMakeContextCurrent(previouscontext); + // previouscontext = NULL; alcDestroyContext(context); alcCloseDevice(device); @@ -93,7 +95,7 @@ bool OpenALMusicPlayer::initContext() GfError("OpenALMusicPlayer: OpenAL could not create contect for device\n"); return false; } - + previouscontext = alcGetCurrentContext(); alcMakeContextCurrent(context); alcGetError(device); @@ -205,9 +207,25 @@ void OpenALMusicPlayer::start() } } +void OpenALMusicPlayer::pause() +{ + alSourceStop(source); + if(previouscontext == NULL){ + previouscontext = alcGetCurrentContext(); + } + alcMakeContextCurrent(previouscontext); + //previouscontext = NULL; +} - - +void OpenALMusicPlayer::resume(int flag) +{ + alcMakeContextCurrent(context); + alSourcePlay(source); + if(flag == 1){ + previouscontext = NULL; + } + +} void OpenALMusicPlayer::rewind() { stream->rewind(); @@ -222,7 +240,7 @@ bool OpenALMusicPlayer::playAndManageBuffer() return false; } - int processed; + int processed = 0; bool active = true; alGetSourcei(source, AL_BUFFERS_PROCESSED, &processed); diff --git a/src/libs/tgfclient/openalmusicplayer.h b/src/libs/tgfclient/openalmusicplayer.h index 3bdcecfb5..8465310f5 100644 --- a/src/libs/tgfclient/openalmusicplayer.h +++ b/src/libs/tgfclient/openalmusicplayer.h @@ -22,7 +22,7 @@ #include #include -#include "SoundStream.h" +#include "soundstream.h" class OpenALMusicPlayer { @@ -32,6 +32,8 @@ class OpenALMusicPlayer virtual void start(); virtual void stop(); + virtual void pause(); + virtual void resume(int flag); virtual void rewind(); virtual bool playAndManageBuffer(); @@ -46,6 +48,7 @@ class OpenALMusicPlayer ALCdevice* device; ALCcontext* context; + ALCcontext* previouscontext; ALuint source; // audio source ALuint buffers[2]; // front and back buffers diff --git a/src/libs/tgfclient/soundstream.cpp b/src/libs/tgfclient/soundstream.cpp index e1a4767f4..52e045da8 100644 --- a/src/libs/tgfclient/soundstream.cpp +++ b/src/libs/tgfclient/soundstream.cpp @@ -17,6 +17,6 @@ * * ***************************************************************************/ -/* Intherface for sound streams */ +/* Interface for sound streams */ -#include "SoundStream.h" \ No newline at end of file +#include "soundstream.h" \ No newline at end of file diff --git a/src/libs/tgfclient/soundstream.h b/src/libs/tgfclient/soundstream.h index 0a88f9432..c6031124a 100644 --- a/src/libs/tgfclient/soundstream.h +++ b/src/libs/tgfclient/soundstream.h @@ -37,12 +37,12 @@ class SoundStream virtual int getRateInHz() = 0; virtual SoundFormat getSoundFormat() = 0; - virtual bool read(char* buffer, const int bufferSize, int* resultSize, const char* error) = 0; + virtual bool read(char* buffer, const int bufferSize, int* resultSize, const char*& error) = 0; virtual void rewind() = 0; virtual void display() = 0; - // isValid is not nice, but I do not want to introduce exceptions into TORCS at this time + // isValid is not nice, but I do not want to introduce exceptions at this time virtual bool isValid() = 0; }; -#endif // __SoundStream_h__ \ No newline at end of file +#endif // __SoundStream_h__ diff --git a/src/modules/userinterface/legacymenu/legacymenu.cpp b/src/modules/userinterface/legacymenu/legacymenu.cpp index be76d7f9c..d7247ea82 100644 --- a/src/modules/userinterface/legacymenu/legacymenu.cpp +++ b/src/modules/userinterface/legacymenu/legacymenu.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -302,6 +303,7 @@ void LegacyMenu::onRaceSimulationReady() { loadCarsGraphics(_piRaceEngine->outData()->s); _piSoundEngine->init(_piRaceEngine->outData()->s); + pauseMenuMusic(); } } @@ -332,6 +334,7 @@ void LegacyMenu::onRaceInterrupted() { void LegacyMenu::onRaceFinishing() { if (_piRaceEngine->inData()->_displayMode == RM_DISP_MODE_NORMAL) { shutdownSound(); + resumeMenuMusic(1); unloadCarsGraphics(); shutdownGraphicsView(); unloadTrackGraphics(); diff --git a/src/modules/userinterface/legacymenu/racescreens/racepitmenu.cpp b/src/modules/userinterface/legacymenu/racescreens/racepitmenu.cpp index b259783f3..42ab51d62 100644 --- a/src/modules/userinterface/legacymenu/racescreens/racepitmenu.cpp +++ b/src/modules/userinterface/legacymenu/racescreens/racepitmenu.cpp @@ -180,6 +180,8 @@ RmCheckPitRequest() // Mute sound. if (LegacyMenu::self().soundEngine()) LegacyMenu::self().soundEngine()->mute(true); + + // TODO pit music?? // First, stop the race engine. LmRaceEngine().stop(); diff --git a/src/modules/userinterface/legacymenu/racescreens/racerunningmenus.cpp b/src/modules/userinterface/legacymenu/racescreens/racerunningmenus.cpp index 94c9914b0..136d169ae 100644 --- a/src/modules/userinterface/legacymenu/racescreens/racerunningmenus.cpp +++ b/src/modules/userinterface/legacymenu/racescreens/racerunningmenus.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include @@ -390,6 +391,8 @@ rmScreenActivate(void * /* dummy */) // If not paused ... if (!rmRacePaused) { + pauseMenuMusic(); + // Reset normal sound volume. if (LegacyMenu::self().soundEngine()) LegacyMenu::self().soundEngine()->mute(false); @@ -410,6 +413,8 @@ rmRacePause(void * /* vboard */) { if (rmRacePaused) { + pauseMenuMusic(); + if (LegacyMenu::self().soundEngine()) LegacyMenu::self().soundEngine()->mute(false); @@ -430,6 +435,8 @@ rmRacePause(void * /* vboard */) if (LegacyMenu::self().soundEngine()) LegacyMenu::self().soundEngine()->mute(true); + resumeMenuMusic(0); + LmRaceEngine().stop(); // Show the "Pause" label. @@ -537,6 +544,8 @@ rmOpenHelpScreen(void * /* dummy */) if (LegacyMenu::self().soundEngine()) LegacyMenu::self().soundEngine()->mute(true); + resumeMenuMusic(0); + GfuiHelpScreen(rmScreenHandle, RmBackToRaceHookInit()); } diff --git a/src/modules/userinterface/legacymenu/racescreens/racestopmenu.cpp b/src/modules/userinterface/legacymenu/racescreens/racestopmenu.cpp index 3a6966272..59758b590 100644 --- a/src/modules/userinterface/legacymenu/racescreens/racestopmenu.cpp +++ b/src/modules/userinterface/legacymenu/racescreens/racestopmenu.cpp @@ -16,6 +16,7 @@ ***************************************************************************/ #include +#include #include @@ -238,6 +239,8 @@ RmStopRaceMenu() // Mute sound. if (LegacyMenu::self().soundEngine()) LegacyMenu::self().soundEngine()->mute(); + + resumeMenuMusic(0); if (!strcmp(GfParmGetStr(params, pszRaceName, RM_ATTR_ALLOW_RESTART, RM_VAL_NO), RM_VAL_NO)) {