Trying an experiment with a thread for playing streamed sounds
This commit is contained in:
parent
ff592be457
commit
a911088d39
Binary file not shown.
|
@ -393,6 +393,14 @@
|
||||||
<Filter
|
<Filter
|
||||||
Name="platform"
|
Name="platform"
|
||||||
>
|
>
|
||||||
|
<File
|
||||||
|
RelativePath="..\..\source\shared_lib\sources\platform\common\base_thread.cpp"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\..\source\shared_lib\sources\platform\common\cache_manager.cpp"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\..\source\shared_lib\sources\platform\sdl\gl_wrap.cpp"
|
RelativePath="..\..\source\shared_lib\sources\platform\sdl\gl_wrap.cpp"
|
||||||
>
|
>
|
||||||
|
@ -401,6 +409,10 @@
|
||||||
RelativePath="..\..\source\shared_lib\sources\platform\common\platform_common.cpp"
|
RelativePath="..\..\source\shared_lib\sources\platform\common\platform_common.cpp"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\..\source\shared_lib\sources\platform\common\simple_threads.cpp"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\..\source\shared_lib\sources\platform\posix\socket.cpp"
|
RelativePath="..\..\source\shared_lib\sources\platform\posix\socket.cpp"
|
||||||
>
|
>
|
||||||
|
@ -708,11 +720,11 @@
|
||||||
Name="platform"
|
Name="platform"
|
||||||
>
|
>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\..\source\shared_lib\sources\platform\common\base_thread.cpp"
|
RelativePath="..\..\source\shared_lib\include\platform\common\base_thread.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\..\source\shared_lib\sources\platform\common\cache_manager.cpp"
|
RelativePath="..\..\source\shared_lib\include\platform\common\cache_manager.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
<File
|
||||||
|
@ -736,7 +748,7 @@
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\..\source\shared_lib\sources\platform\common\simple_threads.cpp"
|
RelativePath="..\..\source\shared_lib\include\platform\common\simple_threads.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
<File
|
||||||
|
|
|
@ -120,6 +120,8 @@ void Program::ShowMessageProgramState::update() {
|
||||||
Program::Program() {
|
Program::Program() {
|
||||||
programState= NULL;
|
programState= NULL;
|
||||||
singleton = this;
|
singleton = this;
|
||||||
|
|
||||||
|
soundThreadManager = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Program::initNormal(WindowGl *window){
|
void Program::initNormal(WindowGl *window){
|
||||||
|
@ -161,6 +163,10 @@ Program::~Program(){
|
||||||
//restore video mode
|
//restore video mode
|
||||||
restoreDisplaySettings();
|
restoreDisplaySettings();
|
||||||
singleton = NULL;
|
singleton = NULL;
|
||||||
|
|
||||||
|
BaseThread::shutdownAndWait(soundThreadManager);
|
||||||
|
delete soundThreadManager;
|
||||||
|
soundThreadManager = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Program::keyDown(char key){
|
void Program::keyDown(char key){
|
||||||
|
@ -199,7 +205,7 @@ void Program::loop(){
|
||||||
|
|
||||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
SoundRenderer::getInstance().update();
|
//!!!SoundRenderer::getInstance().update();
|
||||||
|
|
||||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
|
@ -356,6 +362,11 @@ void Program::init(WindowGl *window, bool initSound, bool toggleFullScreen){
|
||||||
if(initSound == true && toggleFullScreen == false) {
|
if(initSound == true && toggleFullScreen == false) {
|
||||||
SoundRenderer &soundRenderer= SoundRenderer::getInstance();
|
SoundRenderer &soundRenderer= SoundRenderer::getInstance();
|
||||||
soundRenderer.init(window);
|
soundRenderer.init(window);
|
||||||
|
|
||||||
|
BaseThread::shutdownAndWait(soundThreadManager);
|
||||||
|
delete soundThreadManager;
|
||||||
|
soundThreadManager = new SimpleTaskThread(&SoundRenderer::getInstance(),0,50);
|
||||||
|
soundThreadManager->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkInterface::setAllowGameDataSynchCheck(Config::getInstance().getBool("AllowGameDataSynchCheck","0"));
|
NetworkInterface::setAllowGameDataSynchCheck(Config::getInstance().getBool("AllowGameDataSynchCheck","0"));
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
#include "socket.h"
|
#include "socket.h"
|
||||||
#include "components.h"
|
#include "components.h"
|
||||||
#include "window.h"
|
#include "window.h"
|
||||||
|
#include "simple_threads.h"
|
||||||
|
|
||||||
using Shared::Platform::MouseButton;
|
using Shared::Platform::MouseButton;
|
||||||
using Shared::Graphics::Context;
|
using Shared::Graphics::Context;
|
||||||
|
@ -26,6 +27,7 @@ using Shared::Platform::SizeState;
|
||||||
using Shared::Platform::MouseState;
|
using Shared::Platform::MouseState;
|
||||||
using Shared::PlatformCommon::PerformanceTimer;
|
using Shared::PlatformCommon::PerformanceTimer;
|
||||||
using Shared::Platform::Ip;
|
using Shared::Platform::Ip;
|
||||||
|
using namespace Shared::PlatformCommon;
|
||||||
|
|
||||||
namespace Glest{ namespace Game{
|
namespace Glest{ namespace Game{
|
||||||
|
|
||||||
|
@ -77,6 +79,7 @@ public:
|
||||||
class Program{
|
class Program{
|
||||||
private:
|
private:
|
||||||
static const int maxTimes;
|
static const int maxTimes;
|
||||||
|
SimpleTaskThread *soundThreadManager;
|
||||||
|
|
||||||
class ShowMessageProgramState : public ProgramState {
|
class ShowMessageProgramState : public ProgramState {
|
||||||
GraphicMessageBox msgBox;
|
GraphicMessageBox msgBox;
|
||||||
|
|
|
@ -0,0 +1,80 @@
|
||||||
|
// ==============================================================
|
||||||
|
// This file is part of Glest (www.glest.org)
|
||||||
|
//
|
||||||
|
// Copyright (C) 2001-2008 Martiño Figueroa
|
||||||
|
//
|
||||||
|
// You can redistribute this code and/or modify it under
|
||||||
|
// the terms of the GNU General Public License as published
|
||||||
|
// by the Free Software Foundation; either version 2 of the
|
||||||
|
// License, or (at your option) any later version
|
||||||
|
// ==============================================================
|
||||||
|
|
||||||
|
#ifndef _GLEST_GAME_SOUNDRENDERER_H_
|
||||||
|
#define _GLEST_GAME_SOUNDRENDERER_H_
|
||||||
|
|
||||||
|
#include "sound.h"
|
||||||
|
#include "sound_player.h"
|
||||||
|
#include "window.h"
|
||||||
|
#include "vec.h"
|
||||||
|
#include "simple_threads.h"
|
||||||
|
#include "platform_common.h"
|
||||||
|
|
||||||
|
namespace Glest{ namespace Game{
|
||||||
|
|
||||||
|
using Shared::Sound::StrSound;
|
||||||
|
using Shared::Sound::StaticSound;
|
||||||
|
using Shared::Sound::SoundPlayer;
|
||||||
|
using Shared::Graphics::Vec3f;
|
||||||
|
using namespace Shared::PlatformCommon;
|
||||||
|
|
||||||
|
// =====================================================
|
||||||
|
// class SoundRenderer
|
||||||
|
//
|
||||||
|
/// Wrapper to acces the shared library sound engine
|
||||||
|
// =====================================================
|
||||||
|
|
||||||
|
class SoundRenderer : public SimpleTaskCallbackInterface {
|
||||||
|
public:
|
||||||
|
static const int ambientFade;
|
||||||
|
static const float audibleDist;
|
||||||
|
private:
|
||||||
|
SoundPlayer *soundPlayer;
|
||||||
|
|
||||||
|
//volume
|
||||||
|
float fxVolume;
|
||||||
|
float musicVolume;
|
||||||
|
float ambientVolume;
|
||||||
|
|
||||||
|
private:
|
||||||
|
SoundRenderer();
|
||||||
|
|
||||||
|
public:
|
||||||
|
//misc
|
||||||
|
~SoundRenderer();
|
||||||
|
static SoundRenderer &getInstance();
|
||||||
|
void init(Window *window);
|
||||||
|
void update();
|
||||||
|
virtual void simpleTask() { update(); }
|
||||||
|
SoundPlayer *getSoundPlayer() const {return soundPlayer;}
|
||||||
|
|
||||||
|
//music
|
||||||
|
void playMusic(StrSound *strSound);
|
||||||
|
void stopMusic(StrSound *strSound);
|
||||||
|
|
||||||
|
//fx
|
||||||
|
void playFx(StaticSound *staticSound, Vec3f soundPos, Vec3f camPos);
|
||||||
|
void playFx(StaticSound *staticSound);
|
||||||
|
|
||||||
|
//ambient
|
||||||
|
//void playAmbient(StaticSound *staticSound);
|
||||||
|
void playAmbient(StrSound *strSound);
|
||||||
|
void stopAmbient(StrSound *strSound);
|
||||||
|
|
||||||
|
//misc
|
||||||
|
void stopAllSounds();
|
||||||
|
void loadConfig();
|
||||||
|
};
|
||||||
|
|
||||||
|
}}//end namespace
|
||||||
|
|
||||||
|
#endif
|
|
@ -36,6 +36,34 @@ public:
|
||||||
void setTechDataPaths(vector<string> techDataPaths) { this->techDataPaths = techDataPaths; }
|
void setTechDataPaths(vector<string> techDataPaths) { this->techDataPaths = techDataPaths; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// =====================================================
|
||||||
|
// class SimpleTaskThread
|
||||||
|
// =====================================================
|
||||||
|
|
||||||
|
//
|
||||||
|
// This interface describes the methods a callback object must implement
|
||||||
|
//
|
||||||
|
class SimpleTaskCallbackInterface {
|
||||||
|
public:
|
||||||
|
virtual void simpleTask() = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
class SimpleTaskThread : public BaseThread
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
|
||||||
|
SimpleTaskCallbackInterface *simpleTaskInterface;
|
||||||
|
unsigned int executionCount;
|
||||||
|
unsigned int millisecsBetweenExecutions;
|
||||||
|
|
||||||
|
public:
|
||||||
|
SimpleTaskThread();
|
||||||
|
SimpleTaskThread(SimpleTaskCallbackInterface *simpleTaskInterface,
|
||||||
|
unsigned int executionCount=0,
|
||||||
|
unsigned int millisecsBetweenExecutions=0);
|
||||||
|
virtual void execute();
|
||||||
|
};
|
||||||
|
|
||||||
}}//end namespace
|
}}//end namespace
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -63,4 +63,42 @@ void FileCRCPreCacheThread::execute() {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SimpleTaskThread::SimpleTaskThread( SimpleTaskCallbackInterface *simpleTaskInterface,
|
||||||
|
unsigned int executionCount,
|
||||||
|
unsigned int millisecsBetweenExecutions) {
|
||||||
|
this->simpleTaskInterface = simpleTaskInterface;
|
||||||
|
this->executionCount = executionCount;
|
||||||
|
this->millisecsBetweenExecutions = millisecsBetweenExecutions;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SimpleTaskThread::execute() {
|
||||||
|
try {
|
||||||
|
setRunningStatus(true);
|
||||||
|
|
||||||
|
unsigned int idx = 0;
|
||||||
|
for(;this->simpleTaskInterface != NULL;) {
|
||||||
|
this->simpleTaskInterface->simpleTask();
|
||||||
|
if(this->executionCount > 0) {
|
||||||
|
idx++;
|
||||||
|
if(idx >= this->executionCount) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(getQuitStatus() == true) {
|
||||||
|
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
sleep(this->millisecsBetweenExecutions);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(const exception &ex) {
|
||||||
|
setRunningStatus(false);
|
||||||
|
|
||||||
|
throw runtime_error(ex.what());
|
||||||
|
}
|
||||||
|
setRunningStatus(false);
|
||||||
|
}
|
||||||
|
|
||||||
}}//end namespace
|
}}//end namespace
|
||||||
|
|
Loading…
Reference in New Issue