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"
>
</File>
<File
RelativePath=".\src\source\DataModelV2\SoundInstance.cpp"
>
</File>
<File
RelativePath=".\src\source\DataModelV2\SoundService.cpp"
>
</File>
<File
RelativePath=".\ThumbnailGeneratorInstance.cpp"
>
@@ -878,6 +886,14 @@
RelativePath=".\src\include\DataModelV2\SelectionService.h"
>
</File>
<File
RelativePath=".\src\include\DataModelV2\SoundInstance.h"
>
</File>
<File
RelativePath=".\src\include\DataModelV2\SoundService.h"
>
</File>
<File
RelativePath=".\src\include\DataModelV2\ThumbnailGeneratorInstance.h"
>

View File

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

View File

@@ -2,7 +2,6 @@
#include <G3DAll.h>
#include "propertyGrid.h"
#include "map"
//#include "Properties/BoolProperty.h"
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 rapidxml;
DataModelInstance::DataModelInstance(void)
{
// Instances
Instance::Instance();
workspace = new WorkspaceInstance();
guiRoot = new GuiRootInstance();
level = new LevelInstance();
thumbnailGenerator = new ThumbnailGeneratorInstance();
soundService = new SoundService();
selectionService = new SelectionService();
selectionService->setPropertyWindow(g_usableApp->_propWindow);
@@ -31,6 +32,7 @@ DataModelInstance::DataModelInstance(void)
_modY=0;
workspace->setParent(this);
level->setParent(this);
_loadedFileName="..//skooter.rbxm";
listicon = 5;
running = false;
@@ -655,3 +657,8 @@ ThumbnailGeneratorInstance* DataModelInstance::getThumbnailGenerator()
{
return thumbnailGenerator;
}
SoundService* DataModelInstance::getSoundService()
{
return soundService;
}

View File

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