* Fixed audio problems

* Added colobot.ini to CApp in Create function
* Fixes to plugin manager
* Fixed CProfile segfault
dev-ui
erihel 2012-09-22 00:11:16 +02:00
parent f5bc8e12d4
commit 15ff1d512b
9 changed files with 106 additions and 70 deletions

View File

@ -178,6 +178,8 @@ ui/slider.cpp
ui/studio.cpp
ui/target.cpp
ui/window.cpp
plugins/pluginmanager.cpp
plugins/pluginloader.cpp
)
set(LIBS
@ -190,6 +192,7 @@ ${OPTIONAL_LIBS}
${PLATFORM_LIBS}
${Boost_LIBRARIES}
CBot
ltdl
)
include_directories(

View File

@ -83,9 +83,11 @@ struct ApplicationPrivate
CApplication::CApplication()
{
m_private = new ApplicationPrivate();
m_iMan = new CInstanceManager();
m_eventQueue = new CEventQueue(m_iMan);
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;
m_device = nullptr;
@ -140,6 +142,12 @@ CApplication::~CApplication()
delete m_eventQueue;
m_eventQueue = nullptr;
delete m_pluginManager;
m_pluginManager = nullptr;
delete m_profile;
m_profile = nullptr;
delete m_iMan;
m_iMan = nullptr;
@ -302,8 +310,28 @@ bool CApplication::Create()
m_deviceConfig.fullScreen = false;
// Create the sound instance.
m_sound = new CSoundInterface();
if (!GetProfile()->InitCurrentDirectory()) {
GetLogger()->Warn("Config not found. Default values will be used!\n");
m_sound = new CSoundInterface();
} else {
std::string path;
if (GetProfile()->GetLocalProfileString("Resources", "Data", path))
m_dataPath = path;
m_pluginManager->LoadFromProfile();
m_sound = static_cast<CSoundInterface*>(CInstanceManager::GetInstancePointer()->SearchInstance(CLASS_SOUND));
if (!m_sound) {
GetLogger()->Error("Sound not loaded!\n");
return false;
}
m_sound->Create(true);
if (GetProfile()->GetLocalProfileString("Resources", "Sound", path))
m_sound->CacheAll(path);
else
m_sound->CacheAll(m_dataPath);
}
std::string standardInfoMessage =
"\nPlease see the console output or log file\n"

View File

@ -30,6 +30,8 @@
#include "graphics/engine/engine.h"
#include "graphics/opengl/gldevice.h"
#include "plugins/pluginmanager.h"
#include <string>
#include <vector>
@ -331,6 +333,8 @@ 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
int m_exitCode;

View File

@ -57,7 +57,7 @@ bool CProfile::SetLocalProfileString(std::string section, std::string key, std::
bool CProfile::GetLocalProfileString(std::string section, std::string key, std::string &buffer)
{
const char* value = m_ini->GetValue(section.c_str(), key.c_str(), nullptr);
if (strlen(value) > 0) {
if (value != nullptr && strlen(value) > 0) {
buffer = std::string(value);
return true;
}

View File

@ -47,19 +47,19 @@ class CPluginInterface {
/** Function to get plugin name or description
* @return returns plugin name
*/
inline std::string PluginName() { return "abc"; };
inline virtual std::string PluginName() { return "abc"; };
/** Function to get plugin version. 1 means version 0.01, 2 means 0.02 etc.
* @return number indicating plugin version
*/
inline int PluginVersion() { return 0; };
inline virtual int PluginVersion() { return 0; };
/** Function to initialize plugin
*/
inline void InstallPlugin() {};
inline virtual void InstallPlugin() {};
/** Function called before removing plugin
*/
inline bool UninstallPlugin(std::string &) { return true; };
inline virtual bool UninstallPlugin(std::string &) { return true; };
};

View File

@ -39,9 +39,11 @@ CPluginManager::~CPluginManager()
void CPluginManager::LoadFromProfile()
{
GetLogger()->Info("Trying to load from profile...\n");
std::vector< std::string > dirs = GetProfile()->GetLocalProfileSection("Plugins", "Path");
std::vector< std::string > plugins = GetProfile()->GetLocalProfileSection("Plugins", "File");
GetLogger()->Info("Path %d, files %d\n", dirs.size(), plugins.size());
for (std::string dir : dirs)
m_folders.insert(dir);

View File

@ -179,20 +179,6 @@ bool ALSound::Cache(Sound sound, std::string filename)
}
void ALSound::CacheAll()
{
char filename[100];
for ( int i = 1; i < 69; i++ )
{
sprintf(filename, "high/sound%.3d.wav", i);
if ( !Cache((Sound) i, std::string(filename)) )
{
fprintf(stderr, "Unable to load audio: %s\n", filename);
}
}
}
int ALSound::RetPriority(Sound sound)
{
if ( sound == SOUND_FLYh ||
@ -276,23 +262,25 @@ bool ALSound::SearchFreeBuffer(Sound sound, int &channel, bool &bAlreadyLoaded)
}
// Seeks a channel completely free.
auto it = mChannels.end();
it--;
int i = (*it).first;
while (++i)
{
if (mChannels.find(i) == mChannels.end()) {
Channel *chn = new Channel();
// check if we channel ready to play music, if not destroy it and seek free one
if (chn->IsReady()) {
chn->SetPriority(priority);
mChannels[1] = chn;
channel = 1;
bAlreadyLoaded = false;
return true;
if (mChannels.size() < 64) {
auto it = mChannels.end();
it--;
int i = (*it).first;
while (++i)
{
if (mChannels.find(i) == mChannels.end()) {
Channel *chn = new Channel();
// check if channel is ready to play music, if not destroy it and seek free one
if (chn->IsReady()) {
chn->SetPriority(priority);
mChannels[++i] = chn;
channel = i;
bAlreadyLoaded = false;
return true;
}
delete chn;
GetLogger()->Warn("Could not open additional channel to play sound!");
}
delete chn;
GetLogger()->Warn("Could not open additional channel to play sound!");
}
}
@ -513,7 +501,6 @@ void ALSound::FrameMove(float delta)
void ALSound::SetListener(Math::Vector eye, Math::Vector lookat)
{
GetLogger()->Info("Setting listener position.\n");
float orientation[] = {lookat.x, lookat.y, lookat.z, 0.f, 1.f, 0.f};
alListener3f(AL_POSITION, eye.x, eye.y, eye.z);
alListenerfv(AL_ORIENTATION, orientation);

View File

@ -40,7 +40,6 @@ class ALSound : public CSoundInterface
~ALSound();
bool Create(bool b3D);
void CacheAll();
bool Cache(Sound, std::string);
bool RetEnable();

View File

@ -26,9 +26,15 @@
#include <math/vector.h>
#include <common/iman.h>
#include <common/logger.h>
#include <plugins/plugininterface.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <sstream>
/*!
@ -152,20 +158,27 @@ class CSoundInterface : public CPluginInterface
{
public:
inline CSoundInterface() {
//CInstanceManager::getInstance().AddInstance(CLASS_SOUND, this);
CInstanceManager::GetInstance().AddInstance(CLASS_SOUND, this);
//m_iMan->AddInstance(CLASS_SOUND, this);
};
inline ~CSoundInterface() {};
inline virtual ~CSoundInterface() {};
/** Function to initialize sound device
* @param bool b3D - enable support for 3D sound
*/
inline bool Create(bool b3D) { return true; };
inline virtual bool Create(bool b3D) { return true; };
/** Function called to cache all sound effect files.
* Function calls \link CSoundInterface::Cache() \endlink for each file
*/
inline void CacheAll() {};
inline void CacheAll(std::string path) {
for ( int i = 1; i < 69; i++ ) {
std::stringstream filename;
filename << path << "/sound" << std::setfill('0') << std::setw(3) << i << ".wav";
if ( !Cache(static_cast<Sound>(i), filename.str()) )
GetLogger()->Warn("Unable to load audio: %s\n", filename.str().c_str());
}
};
/** Function called to cache sound effect file.
* This function is called by plugin interface for each file.
@ -173,58 +186,58 @@ class CSoundInterface : public CPluginInterface
* @param std::string bFile - file to load
* @return return true on success
*/
inline bool Cache(Sound bSound, std::string bFile) { return true; };
inline virtual bool Cache(Sound bSound, std::string bFile) { return true; };
/** Geturn if plugin is enabled
* @return return true if plugin is enabled
*/
inline bool GetEnable() {return true;};
inline virtual bool GetEnable() {return true;};
/** Change sound mode to 2D/3D
* @param bool bMode - true to enable 3D sound
*/
inline void SetSound3D(bool bMode) {};
inline virtual void SetSound3D(bool bMode) {};
/** Geturn if we use 3D sound
* @return true if we have 3D sound enabled
*/
inline bool GetSound3D() {return true;};
inline virtual bool GetSound3D() {return true;};
/** Geturn if we have 3D sound capable card
* @return true for 3D sound support
*/
inline bool GetSound3DCap() {return true;};
inline virtual bool GetSound3DCap() {return true;};
/** Change global sound volume
* @param int volume - range from 0 to MAXVOLUME
*/
inline void SetAudioVolume(int volume) {};
inline virtual void SetAudioVolume(int volume) {};
/** Geturn global sound volume
* @return global volume as int in range from 0 to MAXVOLUME
*/
inline int GetAudioVolume() {return 0;};
inline virtual int GetAudioVolume() {return 0;};
/** Set music volume
* @param int volume - range from 0 to MAXVOLUME
*/
inline void SetMusicVolume(int volume) {};
inline virtual void SetMusicVolume(int volume) {};
/** Geturn music volume
* @return music volume as int in range from 0 to MAXVOLUME
*/
inline int GetMusicVolume() {return 0;};
inline virtual int GetMusicVolume() {return 0;};
/** Set listener position
* @param Math::Vector eye - position of listener
* @param Math::Vector lookat - direction listener is looking at
*/
inline void SetListener(Math::Vector eye, Math::Vector lookat) {};
inline virtual void SetListener(Math::Vector eye, Math::Vector lookat) {};
/** Update data each frame
* @param float rTime - time since last update
*/
inline void FrameMove(float rTime) {};
inline virtual void FrameMove(float rTime) {};
/** Play specific sound
* @param Sound sound - sound to play
@ -233,7 +246,7 @@ class CSoundInterface : public CPluginInterface
* @param bool bLoop - loop sound
* @return identifier of channel that sound will be played on
*/
inline int Play(Sound sound, float amplitude=1.0f, float frequency=1.0f, bool bLoop = false) {return 0;};
inline virtual int Play(Sound sound, float amplitude=1.0f, float frequency=1.0f, bool bLoop = false) {return 0;};
/** Play specific sound
* @param Sound sound - sound to play
@ -243,13 +256,13 @@ class CSoundInterface : public CPluginInterface
* @param bool bLoop - loop sound
* @return identifier of channel that sound will be played on
*/
inline int Play(Sound sound, Math::Vector pos, float amplitude=1.0f, float frequency=1.0f, bool bLoop = false) {return 0;};
inline virtual int Play(Sound sound, Math::Vector pos, float amplitude=1.0f, float frequency=1.0f, bool bLoop = false) {return 0;};
/** Remove all operations that would be made on sound in channel.
* @param int channel - channel to work on
* @return return true on success
*/
inline bool FlushEnvelope(int channel) {return true;};
inline virtual bool FlushEnvelope(int channel) {return true;};
/** Add envelope to sound. Envelope is a operatino that will be performend on sound in future like changing frequency
* @param int channel - channel to work on
@ -259,64 +272,64 @@ class CSoundInterface : public CPluginInterface
* @param SoundNext oper - operation to perform
* @return return true on success
*/
inline bool AddEnvelope(int channel, float amplitude, float frequency, float time, SoundNext oper) {return true;};
inline virtual bool AddEnvelope(int channel, float amplitude, float frequency, float time, SoundNext oper) {return true;};
/** Set sound position in space
* @param int channel - channel to work on
* @param Math::Vector pos - new positino of a sound
* @return return true on success
*/
inline bool Position(int channel, Math::Vector pos) {return true;};
inline virtual bool Position(int channel, Math::Vector pos) {return true;};
/** Set sound frequency
* @param int channel - channel to work on
* @param float frequency - change sound frequency
* @return return true on success
*/
inline bool Frequency(int channel, float frequency) {return true;};
inline virtual bool Frequency(int channel, float frequency) {return true;};
/** Stop playing sound
* @param int channel - channel to work on
* @return return true on success
*/
inline bool Stop(int channel) {return true;};
inline virtual bool Stop(int channel) {return true;};
/** Stop playing all sounds
* @return return true on success
*/
inline bool StopAll() {return true;};
inline virtual bool StopAll() {return true;};
/** Mute/unmute all sounds
* @param bool bMute
* @return return true on success
*/
inline bool MuteAll(bool bMute) {return true;};
inline virtual bool MuteAll(bool bMute) {return true;};
/** Start playing music
* @param int rank - track number
* @param bool bRepeat - repeat playing
* @return return true on success
*/
inline bool PlayMusic(int rank, bool bRepeat) {return true;};
inline virtual bool PlayMusic(int rank, bool bRepeat) {return true;};
/** Restart music
* @return return true on success
*/
inline bool RestartMusic() {return true;};
inline virtual bool RestartMusic() {return true;};
/** Susspend paying music
* @return return true on success
*/
inline void SuspendMusic() {};
inline virtual void SuspendMusic() {};
/** Stop playing music
* @return return true on success
*/
inline void StopMusic() {};
inline virtual void StopMusic() {};
/** Check if music if playing
* @return return true if music is playing
*/
inline bool IsPlayingMusic() {return true;};
inline virtual bool IsPlayingMusic() {return true;};
};