Skip to content

Commit

Permalink
🤔 Who did this
Browse files Browse the repository at this point in the history
  • Loading branch information
wobbier committed Jun 14, 2024
1 parent 090f379 commit d8a57c6
Show file tree
Hide file tree
Showing 11 changed files with 109 additions and 39 deletions.
11 changes: 11 additions & 0 deletions Source/Components/Audio/AudioSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,17 @@ void AudioSource::Stop( bool immediate )
#endif
}

bool AudioSource::IsLoaded() const
{
#if USING( ME_FMOD )
if( SoundInstance )
{
return SoundInstance->IsReady();
}
#endif
return false;
}

bool AudioSource::IsPlaying() const
{
#if USING( ME_FMOD )
Expand Down
1 change: 1 addition & 0 deletions Source/Components/Audio/AudioSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class AudioSource
void Stop( bool immediate = true );
bool Preload = false;

bool IsLoaded() const;
bool IsPlaying() const;
bool IsPaused() const;

Expand Down
4 changes: 3 additions & 1 deletion Source/Events/AudioEvents.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ class PlayAudioEvent
{
public:
PlayAudioEvent() = default;
PlayAudioEvent( const std::string& InSource )
PlayAudioEvent( const std::string& InSource, bool inImmediate = true )
: SourceName( InSource )
, Immediate( inImmediate )
{
}
std::string SourceName;
float Volume = 1.f;
float StartPercent = 0.f;
bool Immediate = true;

std::function<void( SharedPtr<AudioSource> sound )> Callback;
};
11 changes: 9 additions & 2 deletions Source/Resources/SoundResource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <fmod.hpp>
#endif

Sound::Sound( const Path& path, void* fmodSystem )
Sound::Sound( const Path& path, void* fmodSystem, bool isImmediate )
: Resource( path )
{
#if USING( ME_FMOD )
Expand All @@ -14,10 +14,17 @@ Sound::Sound( const Path& path, void* fmodSystem )
{
YIKES( "FMOD System is not enabled." );
}
if( system->createSound( path.FullPath.c_str(), FMOD_DEFAULT, nullptr, &Handle ) != FMOD_OK )
if( system->createSound( path.FullPath.c_str(), FMOD_DEFAULT | ( isImmediate ? FMOD_DEFAULT : FMOD_NONBLOCKING ), nullptr, &Handle ) != FMOD_OK )
{
// #TODO: Perhaps having the macro for this accepts a string view?
YIKES( "Failed to create sound resource: " + path.FullPath );
}
#endif
}

bool Sound::IsReady() const
{
FMOD_OPENSTATE openstate;
bool result = Handle->getOpenState( &openstate, nullptr, nullptr, nullptr );
return openstate == FMOD_OPENSTATE_READY;
}
4 changes: 3 additions & 1 deletion Source/Resources/SoundResource.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ class Sound
: public Resource
{
public:
Sound( const Path& path, void* fmodSystem = nullptr );
Sound( const Path& path, void* fmodSystem = nullptr, bool isImmediate = true );

bool IsReady() const;

FMOD::Sound* Handle = nullptr;
};
2 changes: 1 addition & 1 deletion Tools/ShaderEditor/BasicInteraction.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"nodes":{"node:1":{"location":{"x":-292,"y":128}},"node:10":{"location":{"x":-238,"y":504}},"node:16":{"location":{"x":31,"y":-12}},"node:20":{"location":{"x":128,"y":224}},"node:27":{"location":{"x":868,"y":233}},"node:30":{"location":{"x":1012,"y":394}},"node:32":{"location":{"x":708,"y":442}},"node:34":{"group_size":{"x":384,"y":154},"location":{"x":112,"y":576}},"node:35":{"group_size":{"x":640,"y":400},"location":{"x":640,"y":128}},"node:36":{"location":{"x":366,"y":652}},"node:40":{"location":{"x":144,"y":652}},"node:44":{"location":{"x":-348,"y":698}},"node:46":{"location":{"x":-69,"y":652}},"node:5":{"location":{"x":-300,"y":351}},"node:50":{"location":{"x":410,"y":-131}},"node:53":{"location":{"x":554,"y":29}}},"selection":null,"view":{"scroll":{"x":-567.69384765625,"y":-272.38262939453125},"visible_rect":{"max":{"x":1552.30615234375,"y":1023.61737060546875},"min":{"x":-567.69384765625,"y":-272.38262939453125}},"zoom":1}}
{"nodes":{"node:1":{"location":{"x":-470,"y":108}},"node:11":{"location":{"x":-696,"y":-356}},"node:16":{"location":{"x":-436,"y":-548}},"node:20":{"location":{"x":-152,"y":-372}},"node:24":{"location":{"x":200,"y":-548}},"node:5":{"location":{"x":-392,"y":-132}},"node:7":{"location":{"x":-440,"y":-20}},"node:9":{"location":{"x":-153,"y":-116}}},"selection":null,"view":{"scroll":{"x":-1079.0804443359375,"y":-927.94964599609375},"visible_rect":{"max":{"x":805.53570556640625,"y":283.24029541015625},"min":{"x":-863.264404296875,"y":-742.35980224609375}},"zoom":1.24999988079071045}}
1 change: 1 addition & 0 deletions Tools/ShaderEditor/BasicShader.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"nodes":{"node:1":{"location":{"x":-470,"y":108}},"node:11":{"location":{"x":-420,"y":-332}},"node:16":{"location":{"x":-436,"y":-548}},"node:20":{"location":{"x":136,"y":-448}},"node:24":{"location":{"x":-8,"y":-556}},"node:5":{"location":{"x":-392,"y":-132}},"node:7":{"location":{"x":-440,"y":-20}},"node:9":{"location":{"x":7,"y":-308}}},"selection":null,"view":{"scroll":{"x":-1.99762141704559326,"y":-640.9991455078125},"visible_rect":{"max":{"x":1431090.375,"y":458120256},"min":{"x":-1427690.5,"y":-458119040}},"zoom":1.39919779940100852e-06}}
16 changes: 16 additions & 0 deletions Tools/ShaderEditor/Source/Core/Node.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ enum class PinType
Vector2,
Vector3Type,
Vector4,
Numeric
};

enum class PinKind
Expand Down Expand Up @@ -64,6 +65,21 @@ struct Pin
ID( id ), Node( nullptr ), Name( name ), Type( type ), Kind( PinKind::Input )
{
}

virtual bool AcceptsType( PinType inType ) const
{
if (Type == PinType::Numeric)
{
return ( inType == PinType::Vector3Type ) || ( inType == PinType::Float );
}
return Type == inType;
}

// this dont make sense
PinType GetPinType()
{
return LinkedInput ? LinkedInput->Type : Type;
}
};

struct Node
Expand Down
75 changes: 44 additions & 31 deletions Tools/ShaderEditor/Source/Nodes/BasicNodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,58 +289,71 @@ AddNode::AddNode( int& inId )
: Node( inId++, "Add", { 168, 201, 156 } )
{
Size = { 300, 0 };
Inputs.emplace_back( inId++, "A(3)", PinType::Vector3Type );
Inputs.emplace_back( inId++, "A(3)", PinType::Numeric );
Inputs.back().Data = 0.f;
Inputs.emplace_back( inId++, "B(3)", PinType::Vector3Type );
Inputs.emplace_back( inId++, "B(3)", PinType::Numeric );
Inputs.back().Data = 0.f;
Outputs.emplace_back( inId++, "Value(3)", PinType::Vector3Type );
Outputs.emplace_back( inId++, "Value(3)", PinType::Numeric );
Outputs.back().Data = Vector3();

BuildNode();
}

bool AddNode::OnEvaluate()
{
Vector3 result = ( Inputs[0].LinkedInput ? std::get<Vector3>( Inputs[0].LinkedInput->Data ) : valueA )
+ ( Inputs[1].LinkedInput ? std::get<Vector3>( Inputs[1].LinkedInput->Data ) : valueB );
Outputs[0].Data = result;
PinType outType = PinType::Numeric;

PinType inType1 = Inputs[0].GetPinType();
PinType inType2 = Inputs[1].GetPinType();
if( inType1 != PinType::Numeric )
{
Inputs[1].Type = inType1;
}
if( inType2 != PinType::Numeric )
{
Inputs[0].Type = inType2;
}
Outputs[0].Type = Inputs[0].LinkedInput ? Inputs[0].LinkedInput->Type : PinType::Numeric;
//Vector3 result = ( Inputs[0].LinkedInput ? std::get<Vector3>( Inputs[0].LinkedInput->Data ) : valueA )
// + ( Inputs[1].LinkedInput ? std::get<Vector3>( Inputs[1].LinkedInput->Data ) : valueB );
//Outputs[0].Data = result;
// update the output pin
return false;
}

bool AddNode::OnRender()
{
if( HavanaUtils::EditableVector3( "##Value A", valueA, 0.f ) )
{
}
if( HavanaUtils::EditableVector3( "##Value B", valueA, 0.f ) )
{
}
//if( HavanaUtils::EditableVector3( "##Value A", valueA, 0.f ) )
//{
//}
//if( HavanaUtils::EditableVector3( "##Value B", valueA, 0.f ) )
//{
//}

return true;
}

void AddNode::OnExport( ShaderWriter& inFile )
{
std::string addNameA;
std::string addNameB;

// Make this a helper
if( !ExportLinkedPin( 0, inFile ) )
{
inFile.WriteVector( valueA );
}
addNameA = inFile.LastVariable;
// Make this a helper
if( !ExportLinkedPin( 1, inFile ) )
{
inFile.WriteVector( valueB );
}
addNameB = inFile.LastVariable;

std::string var = "v3_" + std::to_string( inFile.ID++ );
inFile.WriteLine( "vec3 " + var + " = " + addNameA + " + " + addNameB + ";" );
inFile.LastVariable = var;
//std::string addNameA;
//std::string addNameB;
//
//// Make this a helper
//if( !ExportLinkedPin( 0, inFile ) )
//{
// inFile.WriteVector( valueA );
//}
//addNameA = inFile.LastVariable;
//// Make this a helper
//if( !ExportLinkedPin( 1, inFile ) )
//{
// inFile.WriteVector( valueB );
//}
//addNameB = inFile.LastVariable;
//
//std::string var = "v3_" + std::to_string( inFile.ID++ );
//inFile.WriteLine( "vec3 " + var + " = " + addNameA + " + " + addNameB + ";" );
//inFile.LastVariable = var;
}


Expand Down
21 changes: 19 additions & 2 deletions Tools/ShaderEditor/Source/Nodes/BasicNodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,21 @@
namespace ed = ax::NodeEditor;
namespace util = ax::NodeEditor::Utilities;

// this can be baked into the base? just do checks for all types
struct NumericPin
: public Pin
{
NumericPin( int id, const char* name )
: Pin( id, name, PinType::Numeric )
{
}

virtual bool AcceptsType( PinType inType )
{
return true;
}
};

class LessThanNode
: public Node
{
Expand Down Expand Up @@ -79,12 +94,14 @@ class Vector3Node
void OnExport( ShaderWriter& inFile ) override;
};

using ValueVariant = std::variant<float, Vector2, Vector3, Vector4>;

class AddNode
: public Node
{
public:
Vector3 valueA;
Vector3 valueB;
ValueVariant valueA;
ValueVariant valueB;
AddNode( int& inId );

bool OnEvaluate() override;
Expand Down
2 changes: 1 addition & 1 deletion Tools/ShaderEditor/Source/ShaderEditorInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ void ShaderEditorInstance::HandleLinks()
// showLabel("x Cannot connect to self", ImColor(45, 32, 32, 180));
// ed::RejectNewItem(ImColor(255, 0, 0), 1.0f);
//}
else if( endPin->Type != startPin->Type )
else if( !endPin->AcceptsType( startPin->Type ) )
{
showLabel( "x Incompatible Pin Type", ImColor( 45, 32, 32, 180 ) );
ed::RejectNewItem( ImColor( 255, 128, 128 ), 1.0f );
Expand Down

0 comments on commit d8a57c6

Please sign in to comment.