diff --git a/Blocks3D VS2003.vcproj b/Blocks3D VS2003.vcproj index 2e30ede..85adb0c 100644 --- a/Blocks3D VS2003.vcproj +++ b/Blocks3D VS2003.vcproj @@ -417,6 +417,12 @@ + + + + @@ -524,12 +530,6 @@ - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + @@ -730,6 +740,36 @@ ObjectFile="$(IntDir)/$(InputName)1.obj"/> + + + + + + + + + + + + + + + + diff --git a/src/include/DataModelV3/DataModelInstance.h b/src/include/DataModelV3/DataModelInstance.h index f1ad5fd..0917569 100644 --- a/src/include/DataModelV3/DataModelInstance.h +++ b/src/include/DataModelV3/DataModelInstance.h @@ -11,7 +11,7 @@ using namespace B3D; //#include "GuiRootInstance.h" //#include "ThumbnailGeneratorInstance.h" #include "XplicitNgine/XplicitNgine.h" -//#include "SoundService.h" +#include "SoundService.h" #include "LightingInstance.h" // Libraries @@ -32,7 +32,7 @@ namespace B3D { LevelInstance* getLevel(); XplicitNgine* getEngine(); // ThumbnailGeneratorInstance* getThumbnailGenerator(); - // SoundService* getSoundService(); + SoundService* getSoundService(); LightingInstance* getLighting(); std::string message; @@ -55,7 +55,7 @@ namespace B3D { SelectionService* selectionService; // ThumbnailGeneratorInstance* thumbnailGenerator; XplicitNgine* xplicitNgine; - // SoundService* soundService; + SoundService* soundService; LightingInstance* lightingInstance; bool running; diff --git a/src/include/DataModelV3/SoundInstance.h b/src/include/DataModelV3/SoundInstance.h new file mode 100644 index 0000000..9b9c7cd --- /dev/null +++ b/src/include/DataModelV3/SoundInstance.h @@ -0,0 +1,30 @@ +#pragma once +#include "Instance.h" +namespace B3D{ + class SoundInstance : public Instance + { + public: + SoundInstance(void); + ~SoundInstance(void); + + // Getters + float getSoundVolume(); + std::string getSoundId(); + bool isPlayedOnRemove(); + bool isLooped(); + + // Setters + void setSoundVolume(float newVolume); + void setSoundId(std::string newSoundId); + void setIsPlayedOnRemove(bool isPlayed); + void setIsLooped(bool isLooped); + + // Functions + void play(); + private: + float soundVolume; + std::string soundId; + bool playOnRemove; + bool looped; + }; +} \ No newline at end of file diff --git a/src/include/DataModelV3/SoundService.h b/src/include/DataModelV3/SoundService.h new file mode 100644 index 0000000..1fa9f40 --- /dev/null +++ b/src/include/DataModelV3/SoundService.h @@ -0,0 +1,17 @@ +#pragma once +#include "Instance.h" +#include "SoundInstance.h" +namespace B3D +{ + class SoundService : public Instance + { + public: + SoundService(void); + ~SoundService(void); + + float getMusicVolume(); + void playSound(Instance* sound); + private: + float musicVolume; + }; +} \ No newline at end of file diff --git a/src/source/DataModelV3/DataModelInstance.cpp b/src/source/DataModelV3/DataModelInstance.cpp index d5a3026..69da22a 100644 --- a/src/source/DataModelV3/DataModelInstance.cpp +++ b/src/source/DataModelV3/DataModelInstance.cpp @@ -12,7 +12,7 @@ DataModelInstance::DataModelInstance(void) //guiRoot = new GuiRootInstance(); level = new LevelInstance(); //thumbnailGenerator = new ThumbnailGeneratorInstance(); - //soundService = new SoundService(); + soundService = new SoundService(); lightingInstance = new LightingInstance(); selectionService = new SelectionService(); @@ -25,7 +25,7 @@ DataModelInstance::DataModelInstance(void) // Parent stuff workspace->setParent(this); level->setParent(this); - //soundService->setParent(this); + soundService->setParent(this); lightingInstance->setParent(this); running = false; @@ -326,11 +326,11 @@ LevelInstance* DataModelInstance::getLevel() return thumbnailGenerator; }*/ -//TODO implement -/*SoundService* DataModelInstance::getSoundService() + +SoundService* DataModelInstance::getSoundService() { return soundService; -}*/ +} //TODO implement LightingInstance* DataModelInstance::getLighting() diff --git a/src/source/DataModelV3/SoundInstance.cpp b/src/source/DataModelV3/SoundInstance.cpp new file mode 100644 index 0000000..4187fd8 --- /dev/null +++ b/src/source/DataModelV3/SoundInstance.cpp @@ -0,0 +1,53 @@ +#include "DataModelV3/SoundInstance.h" +#include "DataModelV3/DataModelInstance.h" + +using namespace B3D; + +SoundInstance::SoundInstance() +{ + name = "Sound"; + + soundVolume = 0.5; + soundId = ""; + playOnRemove = false; + looped = false; +} + +SoundInstance::~SoundInstance(void) +{ + if(isPlayedOnRemove()) + play(); +} + +// Functions +void SoundInstance::play() +{ + parentDataModel->getSoundService()->playSound(this); +} + +// Getters +float SoundInstance::getSoundVolume() +{ + return soundVolume; +} + +bool SoundInstance::isPlayedOnRemove() +{ + return playOnRemove; +} + +std::string SoundInstance::getSoundId() +{ + return soundId; +} + +bool SoundInstance::isLooped() +{ + return looped; +} + +// Setters +void SoundInstance::setSoundId(std::string newSoundId) +{ + soundId = newSoundId; +} \ No newline at end of file diff --git a/src/source/DataModelV3/SoundService.cpp b/src/source/DataModelV3/SoundService.cpp new file mode 100644 index 0000000..ced71ed --- /dev/null +++ b/src/source/DataModelV3/SoundService.cpp @@ -0,0 +1,113 @@ +#include "DataModelV3/SoundService.h" +#include "StringFunctions.h" +#include "AudioPlayer.h" + +using namespace B3D; +SoundService::SoundService() +{ + Instance::Instance("SoundService"); + name = "SoundService"; + musicVolume = 0.3f; + canDelete = false; + + // Create stock sounds + SoundInstance* stockSound = new SoundInstance(); + + // Victory + stockSound = new SoundInstance(); + stockSound->setName("Victory"); + stockSound->setSoundId("/content/sounds/victory.wav"); + stockSound->setParent(this); + + // Boing + stockSound = new SoundInstance(); + stockSound->setName("Boing"); + stockSound->setSoundId("/content/sounds/bass.wav"); + stockSound->setParent(this); + + // Bomb + stockSound = new SoundInstance(); + stockSound->setName("Bomb"); + stockSound->setSoundId("/content/sounds/collide.wav"); + stockSound->setParent(this); + + // Ping + stockSound = new SoundInstance(); + stockSound->setName("Ping"); + stockSound->setSoundId("/content/sounds/electronicpingshort.wav"); + stockSound->setParent(this); + + // Break + stockSound = new SoundInstance(); + stockSound->setName("Break"); + stockSound->setSoundId("/content/sounds/glassbreak.wav"); + stockSound->setParent(this); + + // Splat + stockSound = new SoundInstance(); + stockSound->setName("Splat"); + stockSound->setSoundId("/content/sounds/splat.wav"); + stockSound->setParent(this); + + // Swoosh + stockSound = new SoundInstance(); + stockSound->setName("Swoosh"); + stockSound->setSoundId("/content/sounds/swoosh.wav"); + stockSound->setParent(this); + + // Snap + stockSound = new SoundInstance(); + stockSound->setName("Snap"); + stockSound->setSoundId("/content/sounds/snap.wav"); + stockSound->setParent(this); + + // Page + stockSound = new SoundInstance(); + stockSound->setName("Page"); + stockSound->setSoundId("/content/sounds/pageturn.wav"); + stockSound->setParent(this); + + // Click + stockSound = new SoundInstance(); + stockSound->setName("Click"); + stockSound->setSoundId("/content/sounds/switch.wav"); + stockSound->setParent(this); + + // Clock + stockSound = new SoundInstance(); + stockSound->setName("Clock"); + stockSound->setSoundId("/content/sounds/clickfast.wav"); + stockSound->setParent(this); + + // Step + stockSound = new SoundInstance(); + stockSound->setName("Step"); + stockSound->setSoundId("/content/sounds/SWITCH3.wav"); + stockSound->setParent(this); + + // StepOn + stockSound = new SoundInstance(); + stockSound->setName("StepOn"); + stockSound->setSoundId("/content/sounds/flashbulb.wav"); + stockSound->setParent(this); +} + +SoundService::~SoundService(void) +{ +} + +void SoundService::playSound(Instance* sound) +{ + // Try to dynamic_cast it to SoundInstance + SoundInstance* sndInst = dynamic_cast(sound); + if(sndInst != NULL) + { + std::string soundId = sndInst->getSoundId(); + AudioPlayer::playSound(GetFileInPath(soundId)); + } +} + +float SoundService::getMusicVolume() +{ + return musicVolume; +} \ No newline at end of file