Merge pull request #212 from SHADE-DP/SP3-6-c-scripting
Added Audio class for playing audio from C#
This commit is contained in:
commit
b887a303ef
|
@ -7,7 +7,7 @@
|
||||||
#include "ECS_Base/System/SHSystem.h"
|
#include "ECS_Base/System/SHSystem.h"
|
||||||
#include "ECS_Base/System/SHSystemRoutine.h"
|
#include "ECS_Base/System/SHSystemRoutine.h"
|
||||||
#include "ECS_Base/SHECSMacros.h"
|
#include "ECS_Base/SHECSMacros.h"
|
||||||
#include "Math/SHMath.h"
|
#include "Math/Vector/SHVec3.h"
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <FMOD/fmod_studio.hpp>
|
#include <FMOD/fmod_studio.hpp>
|
||||||
#include "SH_API.h"
|
#include "SH_API.h"
|
||||||
|
|
|
@ -39,13 +39,15 @@ project "SHADE_Managed"
|
||||||
"%{IncludeDir.dotnet}\\include",
|
"%{IncludeDir.dotnet}\\include",
|
||||||
"%{IncludeDir.reactphysics3d}\\include",
|
"%{IncludeDir.reactphysics3d}\\include",
|
||||||
"%{IncludeDir.VULKAN}\\include",
|
"%{IncludeDir.VULKAN}\\include",
|
||||||
|
"%{IncludeDir.fmod}\\include",
|
||||||
"%{wks.location}/SHADE_Engine/src"
|
"%{wks.location}/SHADE_Engine/src"
|
||||||
}
|
}
|
||||||
|
|
||||||
libdirs
|
libdirs
|
||||||
{
|
{
|
||||||
"%{IncludeDir.RTTR}/lib",
|
"%{IncludeDir.RTTR}/lib",
|
||||||
"%{IncludeDir.SDL}/lib"
|
"%{IncludeDir.SDL}/lib",
|
||||||
|
"%{IncludeDir.fmod}/lib"
|
||||||
}
|
}
|
||||||
|
|
||||||
links
|
links
|
||||||
|
@ -93,16 +95,19 @@ project "SHADE_Managed"
|
||||||
symbols "On"
|
symbols "On"
|
||||||
defines {"_DEBUG"}
|
defines {"_DEBUG"}
|
||||||
links{"librttr_core_d.lib"}
|
links{"librttr_core_d.lib"}
|
||||||
|
links{"fmodstudioL_vc.lib", "fmodL_vc.lib"}
|
||||||
|
|
||||||
filter "configurations:Release"
|
filter "configurations:Release"
|
||||||
optimize "On"
|
optimize "On"
|
||||||
defines{"_RELEASE"}
|
defines{"_RELEASE"}
|
||||||
links{"librttr_core.lib"}
|
links{"librttr_core.lib"}
|
||||||
|
links{"fmodstudio_vc.lib", "fmod_vc.lib"}
|
||||||
|
|
||||||
filter "configurations:Publish"
|
filter "configurations:Publish"
|
||||||
optimize "On"
|
optimize "On"
|
||||||
defines{"_RELEASE"}
|
defines{"_RELEASE"}
|
||||||
links{"librttr_core.lib"}
|
links{"librttr_core.lib"}
|
||||||
|
links{"fmodstudio_vc.lib", "fmod_vc.lib"}
|
||||||
|
|
||||||
require "vstudio"
|
require "vstudio"
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,101 @@
|
||||||
|
/************************************************************************************//*!
|
||||||
|
\file Audio.cxx
|
||||||
|
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||||
|
\par email: kahwei.tng\@digipen.edu
|
||||||
|
\date Nov 16, 2022
|
||||||
|
\brief Contains the function definitions of the managed Audio static class.
|
||||||
|
|
||||||
|
Note: This file is written in C++17/CLI.
|
||||||
|
|
||||||
|
Copyright (C) 2022 DigiPen Institute of Technology.
|
||||||
|
Reproduction or disclosure of this file or its contents without the prior written consent
|
||||||
|
of DigiPen Institute of Technology is prohibited.
|
||||||
|
*//*************************************************************************************/
|
||||||
|
// Precompiled Header
|
||||||
|
#include "SHpch.h"
|
||||||
|
// Primary Header
|
||||||
|
#include "Audio.hxx"
|
||||||
|
// External Dependencies
|
||||||
|
#include "AudioSystem/SHAudioSystem.h"
|
||||||
|
#include "ECS_Base/Managers/SHSystemManager.h"
|
||||||
|
#include "Utility/Convert.hxx"
|
||||||
|
|
||||||
|
namespace SHADE
|
||||||
|
{
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/* Properties */
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
float Audio::BGMVolume::get()
|
||||||
|
{
|
||||||
|
auto audioSys = SHSystemManager::GetSystem<SHAudioSystem>();
|
||||||
|
return audioSys->GetBgmVolume();
|
||||||
|
}
|
||||||
|
void Audio::BGMVolume::set(float value)
|
||||||
|
{
|
||||||
|
auto audioSys = SHSystemManager::GetSystem<SHAudioSystem>();
|
||||||
|
audioSys->SetBgmVolume(System::Math::Clamp(value, 0.0f, 1.0f));
|
||||||
|
}
|
||||||
|
float Audio::SFXVolume::get()
|
||||||
|
{
|
||||||
|
auto audioSys = SHSystemManager::GetSystem<SHAudioSystem>();
|
||||||
|
return audioSys->GetSfxVolume();
|
||||||
|
}
|
||||||
|
void Audio::SFXVolume::set(float value)
|
||||||
|
{
|
||||||
|
auto audioSys = SHSystemManager::GetSystem<SHAudioSystem>();
|
||||||
|
audioSys->SetSfxVolume(System::Math::Clamp(value, 0.0f, 1.0f));
|
||||||
|
}
|
||||||
|
float Audio::MasterVolume::get()
|
||||||
|
{
|
||||||
|
auto audioSys = SHSystemManager::GetSystem<SHAudioSystem>();
|
||||||
|
return audioSys->GetMasterVolume();
|
||||||
|
}
|
||||||
|
void Audio::MasterVolume::set(float value)
|
||||||
|
{
|
||||||
|
auto audioSys = SHSystemManager::GetSystem<SHAudioSystem>();
|
||||||
|
audioSys->SetMasterVolume(System::Math::Clamp(value, 0.0f, 1.0f));
|
||||||
|
}
|
||||||
|
bool Audio::IsPaused::get()
|
||||||
|
{
|
||||||
|
auto audioSys = SHSystemManager::GetSystem<SHAudioSystem>();
|
||||||
|
return audioSys->GetPaused();
|
||||||
|
}
|
||||||
|
void Audio::IsPaused::set(bool value)
|
||||||
|
{
|
||||||
|
auto audioSys = SHSystemManager::GetSystem<SHAudioSystem>();
|
||||||
|
audioSys->SetPaused(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/* Playback Control Functions */
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
void Audio::PlaySFXOnce2D(System::String^ path)
|
||||||
|
{
|
||||||
|
auto audioSys = SHSystemManager::GetSystem<SHAudioSystem>();
|
||||||
|
audioSys->PlayEventOnce(Convert::ToNative(path).data());
|
||||||
|
}
|
||||||
|
|
||||||
|
void Audio::PlaySFXOnce3D(System::String^ path, GameObject gameObject)
|
||||||
|
{
|
||||||
|
auto audioSys = SHSystemManager::GetSystem<SHAudioSystem>();
|
||||||
|
audioSys->PlayEventOnce(Convert::ToNative(path).data(), true, gameObject.GetEntity(), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Audio::PlayBGMOnce2D(System::String^ path)
|
||||||
|
{
|
||||||
|
auto audioSys = SHSystemManager::GetSystem<SHAudioSystem>();
|
||||||
|
audioSys->PlayEventOnce(Convert::ToNative(path).data(), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Audio::PlayBGMOnce3D(System::String^ path, GameObject gameObject)
|
||||||
|
{
|
||||||
|
auto audioSys = SHSystemManager::GetSystem<SHAudioSystem>();
|
||||||
|
audioSys->PlayEventOnce(Convert::ToNative(path).data(), false, gameObject.GetEntity(), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Audio::StopAllSounds()
|
||||||
|
{
|
||||||
|
auto audioSys = SHSystemManager::GetSystem<SHAudioSystem>();
|
||||||
|
audioSys->StopAllSounds();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,103 @@
|
||||||
|
/************************************************************************************//*!
|
||||||
|
\file Audio.hxx
|
||||||
|
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||||
|
\par email: kahwei.tng\@digipen.edu
|
||||||
|
\date Nov 16, 2022
|
||||||
|
\brief Contains the definitions of the managed Audio static class.
|
||||||
|
|
||||||
|
Note: This file is written in C++17/CLI.
|
||||||
|
|
||||||
|
Copyright (C) 2022 DigiPen Institute of Technology.
|
||||||
|
Reproduction or disclosure of this file or its contents without the prior written consent
|
||||||
|
of DigiPen Institute of Technology is prohibited.
|
||||||
|
*//*************************************************************************************/
|
||||||
|
#pragma once
|
||||||
|
#include "Engine/GameObject.hxx"
|
||||||
|
|
||||||
|
namespace SHADE
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Static class that contains the functions for interfacing with the Audio system.
|
||||||
|
/// </summary>
|
||||||
|
public ref class Audio abstract sealed
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/* Properties */
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/// <summary>
|
||||||
|
/// Volume of background music playback. Clamped between 0.0 and 1.0.
|
||||||
|
/// </summary>
|
||||||
|
static property float BGMVolume
|
||||||
|
{
|
||||||
|
float get();
|
||||||
|
void set(float value);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Volume of sound effects playback. Clamped between 0.0 and 1.0.
|
||||||
|
/// </summary>
|
||||||
|
static property float SFXVolume
|
||||||
|
{
|
||||||
|
float get();
|
||||||
|
void set(float value);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Overall volume for all audio playback. Clamped between 0.0 and 1.0.
|
||||||
|
/// </summary>
|
||||||
|
static property float MasterVolume
|
||||||
|
{
|
||||||
|
float get();
|
||||||
|
void set(float value);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Whether or not all audio playback is paused.
|
||||||
|
/// </summary>
|
||||||
|
static property bool IsPaused
|
||||||
|
{
|
||||||
|
bool get();
|
||||||
|
void set(bool value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/* Playback Control Functions */
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/// <summary>
|
||||||
|
/// Plays a sound effect without looping without spatial attenuation.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="path">
|
||||||
|
/// Path to the audio file relative to the working directory.
|
||||||
|
/// </param>
|
||||||
|
static void PlaySFXOnce2D(System::String^ path);
|
||||||
|
/// <summary>
|
||||||
|
/// Plays a sound effect without looping with spatial attenuation.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="path">
|
||||||
|
/// Path to the audio file relative to the working directory.
|
||||||
|
/// </param>
|
||||||
|
/// <param name="gameObject">
|
||||||
|
/// Object whose position is used to play the sound effect.
|
||||||
|
/// </param>
|
||||||
|
static void PlaySFXOnce3D(System::String^ path, GameObject gameObject);
|
||||||
|
/// <summary>
|
||||||
|
/// Plays background music without looping without spatial attenuation.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="path">
|
||||||
|
/// Path to the audio file relative to the working directory.
|
||||||
|
/// </param>
|
||||||
|
static void PlayBGMOnce2D(System::String^ path);
|
||||||
|
/// <summary>
|
||||||
|
/// Plays background music without looping with spatial attenuation.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="path">
|
||||||
|
/// Path to the audio file relative to the working directory.
|
||||||
|
/// </param>
|
||||||
|
/// <param name="gameObject">
|
||||||
|
/// Object whose position is used to play the background music.
|
||||||
|
/// </param>
|
||||||
|
static void PlayBGMOnce3D(System::String^ path, GameObject gameObject);
|
||||||
|
/// <summary>
|
||||||
|
/// Stops playback of all sound effects and music.
|
||||||
|
/// </summary>
|
||||||
|
static void StopAllSounds();
|
||||||
|
};
|
||||||
|
}
|
Loading…
Reference in New Issue