SoundService & SoundInstance

Basic implementation. More work needs to be done.
This commit is contained in:
Modnark
2022-10-11 21:16:14 -04:00
parent d2f3e718a7
commit d269b360ce
9 changed files with 225 additions and 8 deletions

View File

@@ -505,6 +505,14 @@
RelativePath=".\src\source\DataModel\SelectionService.cpp" RelativePath=".\src\source\DataModel\SelectionService.cpp"
> >
</File> </File>
<File
RelativePath=".\src\source\DataModelV2\SoundInstance.cpp"
>
</File>
<File
RelativePath=".\src\source\DataModelV2\SoundService.cpp"
>
</File>
<File <File
RelativePath=".\ThumbnailGeneratorInstance.cpp" RelativePath=".\ThumbnailGeneratorInstance.cpp"
> >
@@ -878,6 +886,14 @@
RelativePath=".\src\include\DataModelV2\SelectionService.h" RelativePath=".\src\include\DataModelV2\SelectionService.h"
> >
</File> </File>
<File
RelativePath=".\src\include\DataModelV2\SoundInstance.h"
>
</File>
<File
RelativePath=".\src\include\DataModelV2\SoundService.h"
>
</File>
<File <File
RelativePath=".\src\include\DataModelV2\ThumbnailGeneratorInstance.h" RelativePath=".\src\include\DataModelV2\ThumbnailGeneratorInstance.h"
> >

View File

@@ -1,12 +1,17 @@
#pragma once #pragma once
// Instances
#include "WorkspaceInstance.h" #include "WorkspaceInstance.h"
#include "LevelInstance.h" #include "LevelInstance.h"
#include "PartInstance.h" #include "PartInstance.h"
#include "ThumbnailGeneratorInstance.h"
#include "SelectionService.h" #include "SelectionService.h"
#include "rapidxml/rapidxml.hpp"
#include "GuiRootInstance.h" #include "GuiRootInstance.h"
#include "ThumbnailGeneratorInstance.h"
#include "XplicitNgine/XplicitNgine.h" #include "XplicitNgine/XplicitNgine.h"
#include "SoundService.h"
// Libraries
#include "rapidxml/rapidxml.hpp"
class GuiRootInstance; class GuiRootInstance;
@@ -25,10 +30,12 @@ public:
bool readXMLFileStream(std::ifstream* file); bool readXMLFileStream(std::ifstream* file);
void drawMessage(RenderDevice*); void drawMessage(RenderDevice*);
// Instance getters
WorkspaceInstance* getWorkspace(); WorkspaceInstance* getWorkspace();
LevelInstance* getLevel(); LevelInstance* getLevel();
XplicitNgine* getEngine(); XplicitNgine* getEngine();
ThumbnailGeneratorInstance* getThumbnailGenerator(); ThumbnailGeneratorInstance* getThumbnailGenerator();
SoundService* getSoundService();
std::string message; std::string message;
std::string _loadedFileName; std::string _loadedFileName;
@@ -53,11 +60,16 @@ private:
std::string _errMsg; std::string _errMsg;
bool _legacyLoad; bool _legacyLoad;
float _modY; float _modY;
// Instances
WorkspaceInstance* workspace; WorkspaceInstance* workspace;
LevelInstance* level; LevelInstance* level;
GuiRootInstance* guiRoot; GuiRootInstance* guiRoot;
SelectionService* selectionService; SelectionService* selectionService;
ThumbnailGeneratorInstance * thumbnailGenerator; ThumbnailGeneratorInstance* thumbnailGenerator;
XplicitNgine* xplicitNgine;
SoundService* soundService;
bool running; bool running;
XplicitNgine * xplicitNgine;
}; };

View File

@@ -2,7 +2,6 @@
#include <G3DAll.h> #include <G3DAll.h>
#include "propertyGrid.h" #include "propertyGrid.h"
#include "map" #include "map"
//#include "Properties/BoolProperty.h"
class Instance class Instance
{ {

View File

@@ -0,0 +1,30 @@
#pragma once
#include "Instance.h"
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;
};

View File

@@ -0,0 +1,16 @@
#pragma once
#include "Instance.h"
#include "SoundInstance.h"
class SoundService :
public Instance
{
public:
SoundService(void);
~SoundService(void);
float getMusicVolume();
void playSound(SoundInstance* sound);
private:
float musicVolume;
};

View File

@@ -14,14 +14,15 @@
using namespace std; using namespace std;
using namespace rapidxml; using namespace rapidxml;
DataModelInstance::DataModelInstance(void) DataModelInstance::DataModelInstance(void)
{ {
// Instances
Instance::Instance(); Instance::Instance();
workspace = new WorkspaceInstance(); workspace = new WorkspaceInstance();
guiRoot = new GuiRootInstance(); guiRoot = new GuiRootInstance();
level = new LevelInstance(); level = new LevelInstance();
thumbnailGenerator = new ThumbnailGeneratorInstance(); thumbnailGenerator = new ThumbnailGeneratorInstance();
soundService = new SoundService();
selectionService = new SelectionService(); selectionService = new SelectionService();
selectionService->setPropertyWindow(g_usableApp->_propWindow); selectionService->setPropertyWindow(g_usableApp->_propWindow);
@@ -31,6 +32,7 @@ DataModelInstance::DataModelInstance(void)
_modY=0; _modY=0;
workspace->setParent(this); workspace->setParent(this);
level->setParent(this); level->setParent(this);
_loadedFileName="..//skooter.rbxm"; _loadedFileName="..//skooter.rbxm";
listicon = 5; listicon = 5;
running = false; running = false;
@@ -655,3 +657,8 @@ ThumbnailGeneratorInstance* DataModelInstance::getThumbnailGenerator()
{ {
return thumbnailGenerator; return thumbnailGenerator;
} }
SoundService* DataModelInstance::getSoundService()
{
return soundService;
}

View File

@@ -518,15 +518,17 @@ void PartInstance::onTouch()
break; break;
} }
SoundService* sndService = g_dataModel->getSoundService();
switch(OnTouchSound) switch(OnTouchSound)
{ {
case Enum::Sound::NoSound: case Enum::Sound::NoSound:
break; break;
case Enum::Sound::Victory: case Enum::Sound::Victory:
AudioPlayer::playSound(GetFileInPath("/content/sounds/victory.wav")); sndService->playSound(dynamic_cast<SoundInstance*>(sndService->findFirstChild("Victory")));
break; break;
case Enum::Sound::Boing: case Enum::Sound::Boing:
AudioPlayer::playSound(GetFileInPath("/content/sounds/boing.wav")); sndService->playSound(dynamic_cast<SoundInstance*>(sndService->findFirstChild("Boing")));
break; break;
} }
} }

View File

@@ -0,0 +1,52 @@
#include "DataModelV2/SoundInstance.h"
#include "Globals.h"
SoundInstance::SoundInstance()
{
name = "Sound";
className = "Sound";
soundVolume = 0.5;
soundId = "";
playOnRemove = false;
looped = false;
}
SoundInstance::~SoundInstance(void)
{
if(isPlayedOnRemove())
play();
}
// Functions
void SoundInstance::play()
{
g_dataModel->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;
}

View File

@@ -0,0 +1,83 @@
#include "DataModelV2/SoundService.h"
#include "StringFunctions.h"
#include "AudioPlayer.h"
#include "Globals.h"
SoundService::SoundService()
{
name = "SoundService";
className = "SoundService";
musicVolume = 0.3f;
// 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);
}
SoundService::~SoundService(void)
{
}
void SoundService::playSound(SoundInstance* sound)
{
std::string soundId = sound->getSoundId();
AudioPlayer::playSound(GetFileInPath(soundId));
}
float SoundService::getMusicVolume()
{
return musicVolume;
}