sound fix

dev-ui
erihel 2012-12-20 21:57:57 +01:00
parent a6ff654ae3
commit f0e76ad446
11 changed files with 40 additions and 154 deletions

View File

@ -38,6 +38,8 @@ option(CBOT_STATIC "Build CBot as static libary" OFF)
# Doxygen docs are optional for installation
option(INSTALL_DOCS "Install Doxygen-generated documentation" OFF)
# Build openal sound support
option(OPENAL_SOUND "Build openal sound support" OFF)
##
# Required packages

View File

@ -1,30 +0,0 @@
# Find the native LTDL includes and library
# Copied verbatim from
# http://code.metager.de/source/xref/hshannover/trust/tnc-fhh/shared/cmake_modules/FindLTDL.cmake
# The above version was under GPL-2, this one is under GPL-3, for consistency
# with the rest of the colobot project.
#
# This module defines
# LTDL_INCLUDE_DIR, where to find ltdl.h, etc.
# LTDL_LIBRARY, where to find the LTDL library.
# LTDL_FOUND, If false, do not try to use LTDL.
FIND_PATH(LTDL_INCLUDE_DIR ltdl.h)
FIND_LIBRARY(LTDL_LIBRARY ltdl)
IF (LTDL_INCLUDE_DIR AND LTDL_LIBRARY)
SET(LTDL_FOUND TRUE)
ELSE(LTDL_INCLUDE_DIR AND LTDL_LIBRARY)
SET(LTDL_FOUND FALSE)
ENDIF (LTDL_INCLUDE_DIR AND LTDL_LIBRARY)
IF (LTDL_FOUND)
IF (NOT LTDL_FIND_QUIETLY)
MESSAGE(STATUS "Found LTDL: ${LTDL_LIBRARY}")
ENDIF (NOT LTDL_FIND_QUIETLY)
ELSE (LTDL_FOUND)
IF (LTDL_FIND_REQUIRED)
MESSAGE(FATAL_ERROR "Could not find LTDL")
ENDIF (LTDL_FIND_REQUIRED)
ENDIF (LTDL_FOUND)

View File

@ -23,6 +23,7 @@ if((${CMAKE_CROSSCOMPILING}) AND (DEFINED MSYS))
${CMAKE_FIND_ROOT_PATH}/lib/libjpeg.a
${CMAKE_FIND_ROOT_PATH}/lib/libwinmm.a
${CMAKE_FIND_ROOT_PATH}/lib/libdxguid.a
${CMAKE_FIND_ROOT_PATH}/lib/libbz2.a
)
else()
set(MXE 0)

View File

@ -16,6 +16,5 @@ if(${CBOT_STATIC})
add_library(CBot STATIC ${SOURCES})
else()
add_library(CBot SHARED ${SOURCES})
install(TARGETS CBot LIBRARY DESTINATION ${COLOBOT_INSTALL_LIB_DIR})
endif()
install(TARGETS CBot LIBRARY DESTINATION ${COLOBOT_INSTALL_LIB_DIR})

View File

@ -27,9 +27,24 @@ endif()
# Additional libraries per platform
set(PLATFORM_LIBS "")
set(OPENAL_LIBS "")
if (${OPENAL_SOUND})
if (${MXE})
set(OPENAL_LIBS
${CMAKE_FIND_ROOT_PATH}/lib/libOpenAL32.a
${CMAKE_FIND_ROOT_PATH}/lib/libalut.a
)
else()
set(OPENAL_LIBS
openal
alut
)
endif()
endif()
if (${MXE}) # MXE requires special treatment
set(PLATFORM_LIBS ${MXE_LIBS})
set(PLATFORM_LIBS ${MXE_LIBS})
elseif (${PLATFORM_WINDOWS})
# because it isn't included in standard linking libraries
set(PLATFORM_LIBS "-lintl")
@ -42,6 +57,15 @@ endif()
# Configure file
configure_file(common/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/common/config.h)
set(OPENAL_SRC "")
if (${OPENAL_SOUND})
set(OPENAL_SRC
sound/oalsound/alsound.cpp
sound/oalsound/buffer.cpp
sound/oalsound/channel.cpp
)
endif()
# Source files
set(SOURCES
@ -160,8 +184,10 @@ ui/slider.cpp
ui/studio.cpp
ui/target.cpp
ui/window.cpp
${OPENAL_SRC}
)
set(LIBS
${SDL_LIBRARY}
${SDLIMAGE_LIBRARY}
@ -172,6 +198,7 @@ ${OPTIONAL_LIBS}
${PLATFORM_LIBS}
${Boost_LIBRARIES}
CBot
${OPENAL_LIBS}
)
include_directories(

View File

@ -89,7 +89,6 @@ CApplication::CApplication()
m_private = new ApplicationPrivate();
m_iMan = new CInstanceManager();
m_eventQueue = new CEventQueue(m_iMan);
m_pluginManager = new CPluginManager();
m_profile = new CProfile();
m_engine = nullptr;
@ -158,9 +157,6 @@ CApplication::~CApplication()
delete m_eventQueue;
m_eventQueue = nullptr;
delete m_pluginManager;
m_pluginManager = nullptr;
delete m_profile;
m_profile = nullptr;
@ -336,8 +332,7 @@ bool CApplication::Create()
if (GetProfile().GetLocalProfileString("Resources", "Data", path))
m_dataPath = path;
m_pluginManager->LoadFromProfile();
m_sound = static_cast<CSoundInterface*>(CInstanceManager::GetInstancePointer()->SearchInstance(CLASS_SOUND));
m_sound = static_cast<CSoundInterface*>(CInstanceManager::GetInstancePointer()->SearchInstance(CLASS_SOUND));
if (!m_sound) {
GetLogger()->Error("Sound not loaded, falling back to fake sound!\n");

View File

@ -25,13 +25,12 @@
#include "common/global.h"
#include "common/singleton.h"
#include "common/profile.h"
#include "graphics/core/device.h"
#include "graphics/engine/engine.h"
#include "graphics/opengl/gldevice.h"
#include "plugins/pluginmanager.h"
#include <string>
#include <vector>
@ -337,7 +336,6 @@ protected:
CSoundInterface* m_sound;
//! Main class of the proper game engine
CRobotMain* m_robotMain;
CPluginManager* m_pluginManager;
CProfile* m_profile;
//! Code to return at exit

View File

@ -1,24 +0,0 @@
cmake_minimum_required(VERSION 2.8)
set(SOURCES
alsound.cpp
buffer.cpp
channel.cpp
)
SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++0x -fPIC")
SET (CMAKE_CXX_FLAGS_DEBUG "-g")
include(FindPkgConfig)
include(FindOpenAL)
pkg_check_modules(OPENAL_LIB REQUIRED openal)
set(OPENAL_LIBRARIES
openal
alut
)
include_directories(../../..)
include_directories(.)
add_library(openalsound SHARED ${SOURCES})
target_link_libraries(openalsound ${OPENAL_LIBRARIES})

View File

@ -23,51 +23,23 @@
#define MIN(a, b) (a > b ? b : a)
PLUGIN_INTERFACE(ALSound)
std::string ALSound::PluginName()
{
return "Sound plugin using OpenAL library to play sounds.";
}
int ALSound::PluginVersion()
{
return 2;
}
void ALSound::InstallPlugin()
{
auto pointer = CInstanceManager::GetInstancePointer();
if (pointer != nullptr)
CInstanceManager::GetInstancePointer()->AddInstance(CLASS_SOUND, this);
}
bool ALSound::UninstallPlugin(std::string &reason)
{
auto pointer = CInstanceManager::GetInstancePointer();
if (pointer != nullptr)
CInstanceManager::GetInstancePointer()->DeleteInstance(CLASS_SOUND, this);
CleanUp();
return true;
}
ALSound::ALSound()
{
mEnabled = false;
m3D = false;
mAudioVolume = MAXVOLUME;
mMute = false;
auto pointer = CInstanceManager::GetInstancePointer();
if (pointer != nullptr)
CInstanceManager::GetInstancePointer()->AddInstance(CLASS_SOUND, this);
}
ALSound::~ALSound()
{
auto pointer = CInstanceManager::GetInstancePointer();
if (pointer != nullptr)
CInstanceManager::GetInstancePointer()->DeleteInstance(CLASS_SOUND, this);
CleanUp();
}

View File

@ -1,14 +0,0 @@
cmake_minimum_required(VERSION 2.8)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE debug)
endif(NOT CMAKE_BUILD_TYPE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++11 -rdynamic")
set(CMAKE_CXX_FLAGS_DEBUG "-g -O0")
add_executable(plugin_test plugin_test.cpp ../../../../common/iman.cpp ../../../../common/logger.cpp ../../../../plugins/pluginloader.cpp)
include_directories(".")
include_directories("../../../../")
target_link_libraries(plugin_test ${LTDL_LIBRARY})

View File

@ -1,40 +0,0 @@
#include <string>
#include <cstdio>
#include <unistd.h>
#include <common/logger.h>
#include <common/iman.h>
#include <sound/sound.h>
#include <plugins/pluginloader.h>
int main() {
new CLogger();
new CInstanceManager();
lt_dlinit();
CPluginLoader *plugin = new CPluginLoader("libopenalsound");
if (plugin->LoadPlugin()) {
CSoundInterface *sound = static_cast<CSoundInterface*>(CInstanceManager::GetInstancePointer()->SearchInstance(CLASS_SOUND));
sound->Create(true);
sound->CacheAll();
sound->Play((Sound)8);
sound->Play((Sound)18);
sleep(10);
/*
while (1)
{
// just a test, very slow
plugin->FrameMove(0);
//if ('n' == getchar())
// break;
}*/
plugin->UnloadPlugin();
}
lt_dlexit();
return 0;
}