diff --git a/mk/windoze/Glest.suo b/mk/windoze/Glest.suo index e7c9a3f1..e16002a8 100755 Binary files a/mk/windoze/Glest.suo and b/mk/windoze/Glest.suo differ diff --git a/mk/windoze/shared_lib.vcproj b/mk/windoze/shared_lib.vcproj index bde31e3e..36eb0cbe 100755 --- a/mk/windoze/shared_lib.vcproj +++ b/mk/windoze/shared_lib.vcproj @@ -393,6 +393,14 @@ + + + + @@ -401,6 +409,10 @@ RelativePath="..\..\source\shared_lib\sources\platform\common\platform_common.cpp" > + + @@ -708,11 +720,11 @@ Name="platform" > start(); } NetworkInterface::setAllowGameDataSynchCheck(Config::getInstance().getBool("AllowGameDataSynchCheck","0")); diff --git a/source/glest_game/main/program.h b/source/glest_game/main/program.h index b1e63655..1f077770 100644 --- a/source/glest_game/main/program.h +++ b/source/glest_game/main/program.h @@ -18,6 +18,7 @@ #include "socket.h" #include "components.h" #include "window.h" +#include "simple_threads.h" using Shared::Platform::MouseButton; using Shared::Graphics::Context; @@ -26,6 +27,7 @@ using Shared::Platform::SizeState; using Shared::Platform::MouseState; using Shared::PlatformCommon::PerformanceTimer; using Shared::Platform::Ip; +using namespace Shared::PlatformCommon; namespace Glest{ namespace Game{ @@ -77,6 +79,7 @@ public: class Program{ private: static const int maxTimes; + SimpleTaskThread *soundThreadManager; class ShowMessageProgramState : public ProgramState { GraphicMessageBox msgBox; diff --git a/source/glest_game/sound/sound_renderer.h b/source/glest_game/sound/sound_renderer.h new file mode 100644 index 00000000..3470b076 --- /dev/null +++ b/source/glest_game/sound/sound_renderer.h @@ -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 diff --git a/source/shared_lib/include/platform/common/simple_threads.h b/source/shared_lib/include/platform/common/simple_threads.h index 72366648..60b04259 100644 --- a/source/shared_lib/include/platform/common/simple_threads.h +++ b/source/shared_lib/include/platform/common/simple_threads.h @@ -36,6 +36,34 @@ public: void setTechDataPaths(vector 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 #endif diff --git a/source/shared_lib/sources/platform/common/simple_threads.cpp b/source/shared_lib/sources/platform/common/simple_threads.cpp index 5e8254a3..dd5a909b 100644 --- a/source/shared_lib/sources/platform/common/simple_threads.cpp +++ b/source/shared_lib/sources/platform/common/simple_threads.cpp @@ -63,4 +63,42 @@ void FileCRCPreCacheThread::execute() { 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