From c819bdff24b963cae5a6dae59cd1a603f7782de4 Mon Sep 17 00:00:00 2001 From: Mitch Andrews Date: Sun, 28 Jul 2024 05:21:05 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=94=20Audio=20stopping=20/=20Type=20co?= =?UTF-8?q?nversion=20for=20shader=20nodes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/Cores/AudioCore.cpp | 16 ++- Source/Events/AudioEvents.h | 12 ++ Source/Resources/SoundResource.cpp | 9 ++ Source/Resources/SoundResource.h | 1 + .../ShaderEditor/Source/Nodes/BasicNodes.cpp | 135 ++++++++++++++---- 5 files changed, 143 insertions(+), 30 deletions(-) diff --git a/Source/Cores/AudioCore.cpp b/Source/Cores/AudioCore.cpp index 18e7629b..f8283c5a 100644 --- a/Source/Cores/AudioCore.cpp +++ b/Source/Cores/AudioCore.cpp @@ -31,7 +31,8 @@ AudioCore::AudioCore() #endif std::vector events = { - PlayAudioEvent::GetEventId() + PlayAudioEvent::GetEventId(), + StopAudioEvent::GetEventId() }; EventManager::GetInstance().RegisterReceiver( this, events ); } @@ -113,6 +114,19 @@ bool AudioCore::OnEvent( const BaseEvent& InEvent ) return true; } + if( InEvent.GetEventId() == StopAudioEvent::GetEventId() ) + { + const StopAudioEvent& evt = static_cast( InEvent ); + Path soundPath = Path( evt.SourceName ); + auto sound = soundPath.GetLocalPath(); + if( m_cachedSounds.find( sound.data() ) != m_cachedSounds.end() ) + { + std::remove( sound.data() ); + //auto& source = m_cachedSounds[sound.data()] = MakeShared( sound.data() ); + //InitComponent( *source ); + } + } + return false; } diff --git a/Source/Events/AudioEvents.h b/Source/Events/AudioEvents.h index e1e8f51e..1b6d6d13 100644 --- a/Source/Events/AudioEvents.h +++ b/Source/Events/AudioEvents.h @@ -20,4 +20,16 @@ class PlayAudioEvent bool Immediate = true; std::function sound )> Callback; +}; + +class StopAudioEvent + : public Event +{ +public: + StopAudioEvent() = default; + StopAudioEvent( const std::string& InSource ) + : SourceName( InSource ) + { + } + std::string SourceName; }; \ No newline at end of file diff --git a/Source/Resources/SoundResource.cpp b/Source/Resources/SoundResource.cpp index 9ab5e90a..2c777435 100644 --- a/Source/Resources/SoundResource.cpp +++ b/Source/Resources/SoundResource.cpp @@ -22,6 +22,15 @@ Sound::Sound( const Path& path, void* fmodSystem, bool isImmediate ) #endif } +Sound::~Sound() +{ + if( Handle ) + { + Handle->release(); + Handle = nullptr; + } +} + bool Sound::IsReady() const { #if USING( ME_FMOD ) diff --git a/Source/Resources/SoundResource.h b/Source/Resources/SoundResource.h index 93a9e1bc..22a7371e 100644 --- a/Source/Resources/SoundResource.h +++ b/Source/Resources/SoundResource.h @@ -12,6 +12,7 @@ class Sound { public: Sound( const Path& path, void* fmodSystem = nullptr, bool isImmediate = true ); + ~Sound(); bool IsReady() const; diff --git a/Tools/ShaderEditor/Source/Nodes/BasicNodes.cpp b/Tools/ShaderEditor/Source/Nodes/BasicNodes.cpp index 0afdb72c..72a2b0e4 100644 --- a/Tools/ShaderEditor/Source/Nodes/BasicNodes.cpp +++ b/Tools/ShaderEditor/Source/Nodes/BasicNodes.cpp @@ -333,37 +333,122 @@ bool AddNode::OnRender() return true; } +std::string ToMyType( PinType myType, PinType theirType ) +{ + if( myType == theirType ) + { + return ""; + } + + switch( myType ) + { + case PinType::Flow: + break; + case PinType::Bool: + break; + case PinType::Int: + break; + case PinType::Float: + break; + case PinType::String: + break; + case PinType::Object: + break; + case PinType::Function: + break; + case PinType::Delegate: + break; + case PinType::Texture: + break; + case PinType::Vector2: + break; + case PinType::Vector3Type: + { + switch( theirType ) + { + case PinType::Vector4: + return ".xyz"; + default: + break; + } + } + break; + case PinType::Vector4: + break; + case PinType::Numeric: + break; + default: + break; + } + return ""; +} + +std::string PinToString( PinType inType ) +{ + switch( inType ) + { + case PinType::Flow: + break; + case PinType::Bool: + break; + case PinType::Int: + break; + case PinType::Float: + break; + case PinType::String: + break; + case PinType::Object: + break; + case PinType::Function: + break; + case PinType::Delegate: + break; + case PinType::Texture: + break; + case PinType::Vector2: + return "vec2"; + case PinType::Vector3Type: + return "vec3"; + case PinType::Vector4: + return "vec4"; + case PinType::Numeric: + break; + default: + break; + } + return ""; +} + + void AddNode::OnExport( ShaderWriter& inFile ) { std::string addNameA; std::string addNameB; std::string outputType; - + std::string conversionType1; + std::string conversionType2; + // Make this a helper if( ExportLinkedPin( 0, inFile ) ) { - if( inFile.LastType == PinType::Vector3Type ) - { - //inFile.WriteVector( std::get( valueA ) ); - outputType = "vec3"; - } - - if( inFile.LastType == PinType::Float ) - { - //inFile.WriteFloat( std::get( valueA ) ); - outputType = "float"; - } + conversionType1 = ToMyType( Outputs[0].Type, inFile.LastType ); } addNameA = inFile.LastVariable; // Make this a helper - if( !ExportLinkedPin( 1, inFile ) ) + if( ExportLinkedPin( 1, inFile ) ) { + conversionType2 = ToMyType( Outputs[0].Type, inFile.LastType ); + } + else + { + // this is an issue for sure... inFile.WriteVector( Vector3() ); } + outputType = PinToString( Outputs[0].Type ); addNameB = inFile.LastVariable; - + std::string var = "add_" + std::to_string( inFile.ID++ ); - inFile.WriteLine( outputType + " " + var + " = " + addNameA + " + " + addNameB + ";" ); + inFile.WriteLine( outputType + " " + var + " = " + addNameA + conversionType1 + " + " + addNameB + conversionType2 + ";" ); inFile.LastVariable = var; } @@ -375,9 +460,10 @@ SampleTextureNode::SampleTextureNode( int& inId ) Inputs.back().Data = 0.f; Inputs.emplace_back( inId++, "UV(2)", PinType::Vector2 ); Inputs.back().Data = Vector2(); + // this isn't actually a vec3... Outputs.emplace_back( inId++, "Value(3)", PinType::Vector3Type ); Outputs.back().Data = Vector3(); - Outputs.emplace_back( inId++, "Value(3)", PinType::Float ); + Outputs.emplace_back( inId++, "Alpha(1)", PinType::Float ); Outputs.back().Data = 0.f; BuildNode(); @@ -428,20 +514,11 @@ void SampleTextureNode::OnExport( ShaderWriter& inFile ) } uvName = inFile.LastVariable; - // useless? - if( ExportLinkedPin( 1, inFile ) ) - { - std::string var = "sample_" + std::to_string( inFile.ID++ ); - //" + var + " - inFile.WriteLine( "vec4 color = " + inFile.LastVariable + ";" ); - inFile.LastVariable = "color"; - } - else if( filePath.Exists ) + if( filePath.Exists ) { - std::string var = "sample_" + std::to_string( inFile.ID++ ); + inFile.LastVariable = "sample_" + std::to_string( inFile.ID++ ); //" + var + " - inFile.WriteLine( "vec4 color = texture2D( s_texDiffuse0, " + uvName + " );" ); - inFile.LastVariable = "color"; + inFile.WriteLine( "vec4 " + inFile.LastVariable + " = texture2D( s_texDiffuse0, " + uvName + " );" ); } else { @@ -525,7 +602,7 @@ void BasicShaderMasterNode::ExportShitty( Path& inPath, const std::string& inSha std::string localPrefix = inPath.FullPath.substr( 0, inPath.FullPath.rfind( ".shader" ) ); if( !outFile.FilePath.Exists ) { - outFile.Write("{}"); + outFile.Write( "{}" ); } json outJson = json::parse( outFile.Read() ); json& textures = outJson["Textures"];