From 3961b1722646443eebe26fcbffac80ecdaec88cc Mon Sep 17 00:00:00 2001 From: Josef Date: Fri, 25 Jul 2025 17:35:19 +0200 Subject: [PATCH] Update --- Runtime/Actions/Node3D/PlaySound.cs | 40 ++++++++++++++---- Runtime/Actions/Physics/SetCollisionShape.cs | 6 +++ Runtime/Actions/RemoveNode.cs | 2 + Runtime/Audio/AudioManager/AudioManager.cs | 41 +++++++++++++++++++ .../Audio/AudioManager/AudioManager.cs.uid | 1 + Runtime/Godot/NodeState.cs | 5 +++ Runtime/VirtualCameras/VirtualCamera3DSlot.cs | 6 +-- 7 files changed, 91 insertions(+), 10 deletions(-) create mode 100644 Runtime/Audio/AudioManager/AudioManager.cs create mode 100644 Runtime/Audio/AudioManager/AudioManager.cs.uid diff --git a/Runtime/Actions/Node3D/PlaySound.cs b/Runtime/Actions/Node3D/PlaySound.cs index f554219..4e225a5 100644 --- a/Runtime/Actions/Node3D/PlaySound.cs +++ b/Runtime/Actions/Node3D/PlaySound.cs @@ -10,10 +10,14 @@ namespace Rokojori [Export] public AudioStreamPlayer3D player; + [Export] + public SelectorFlag overdrivePreventionFlag; + + [Export] public Duration overdrivePreventionDuration; - float _lastSoundPlayed; + [ExportGroup("Randomize Playback Position")] [Export] public bool randomizePlaybackPosition = false; @@ -22,6 +26,10 @@ namespace Rokojori public Duration durationPerSound; [Export] + public float cutBufferLengths = 0; + + + [Export] public bool generatePools = true; @@ -56,20 +64,30 @@ namespace Rokojori protected override void _OnTrigger() { - if ( overdrivePreventionDuration != null ) - { - var now = TimeLine.osTime; - var elapsed = now - _lastSoundPlayed; + + var audioManager = Unique.Get(); - if ( elapsed < overdrivePreventionDuration.GetDurationInSeconds() ) + if ( overdrivePreventionDuration != null && overdrivePreventionFlag != null ) + { + if ( ! audioManager.CanPlay( overdrivePreventionFlag, overdrivePreventionDuration.GetDurationInSeconds() ) ) { + this.LogInfo( "Can't play sound, prevention" ); return; } + } + + var offset = 0f; var player = generatePools ? GetFreePlayer() : this.player; + + if ( ! IsInstanceValid( player ) ) + { + this.LogInfo( "Can't play sound, invalid" ); + return; + } if ( randomizePlaybackPosition ) { @@ -85,13 +103,21 @@ namespace Rokojori player.Play( offset ); + this.LogInfo( "Play sound", offset, HierarchyName.Of( player ) ); + + if ( overdrivePreventionFlag != null ) + { + audioManager.RecordSoundPlaying( overdrivePreventionFlag ); + } + if ( randomizePlaybackPosition ) { var tl = TimeLineManager.Ensure( durationPerSound.timeLine ); var start = tl.position; - TimeLineManager.ScheduleSpanIn( durationPerSound.timeLine, 0, durationPerSound.GetDurationInSeconds() / player.PitchScale, + var stopDuration = ( durationPerSound.GetDurationInSeconds() - audioManager.bufferCutLength * cutBufferLengths ) / player.PitchScale; + TimeLineManager.ScheduleSpanIn( durationPerSound.timeLine, 0, stopDuration, ( span, type )=> { var timeNow = tl.position; diff --git a/Runtime/Actions/Physics/SetCollisionShape.cs b/Runtime/Actions/Physics/SetCollisionShape.cs index 1997760..f2e6478 100644 --- a/Runtime/Actions/Physics/SetCollisionShape.cs +++ b/Runtime/Actions/Physics/SetCollisionShape.cs @@ -21,6 +21,12 @@ namespace Rokojori return; } + + CallDeferred( nameof( DisableShape ) ); + } + + void DisableShape() + { shape3D.Disabled = disabled; } } diff --git a/Runtime/Actions/RemoveNode.cs b/Runtime/Actions/RemoveNode.cs index 82624c8..8e383a5 100644 --- a/Runtime/Actions/RemoveNode.cs +++ b/Runtime/Actions/RemoveNode.cs @@ -19,6 +19,8 @@ namespace Rokojori { return; } + + this.LogInfo( "Remove", HierarchyName.Of( target ) ); target.SelfDestroy( queue ); diff --git a/Runtime/Audio/AudioManager/AudioManager.cs b/Runtime/Audio/AudioManager/AudioManager.cs new file mode 100644 index 0000000..a204582 --- /dev/null +++ b/Runtime/Audio/AudioManager/AudioManager.cs @@ -0,0 +1,41 @@ +using Godot; +using System.Collections.Generic; +using System.Text; + +namespace Rokojori +{ + [GlobalClass,Tool] + public partial class AudioManager:Node + { + [Export] + public float bufferCutLength = 0.021f; + + Dictionary _lastPlayTime = new Dictionary(); + + public float GetLastPlayed( SelectorFlag selectorFlag ) + { + if ( ! _lastPlayTime.ContainsKey( selectorFlag ) ) + { + return -1; + } + + return _lastPlayTime[ selectorFlag ]; + } + + public void RecordSoundPlaying( SelectorFlag selectorFlag ) + { + _lastPlayTime[ selectorFlag ] = TimeLine.osTime; + } + + public bool CanPlay( SelectorFlag selectorFlag, float blockDuration ) + { + if ( ! _lastPlayTime.ContainsKey( selectorFlag ) ) + { + return true; + } + + return ( TimeLine.osTime - _lastPlayTime[ selectorFlag ] ) > blockDuration; + + } + } +} \ No newline at end of file diff --git a/Runtime/Audio/AudioManager/AudioManager.cs.uid b/Runtime/Audio/AudioManager/AudioManager.cs.uid new file mode 100644 index 0000000..f38f14b --- /dev/null +++ b/Runtime/Audio/AudioManager/AudioManager.cs.uid @@ -0,0 +1 @@ +uid://dsbph60xvjkaw diff --git a/Runtime/Godot/NodeState.cs b/Runtime/Godot/NodeState.cs index ceacf42..ac0f112 100644 --- a/Runtime/Godot/NodeState.cs +++ b/Runtime/Godot/NodeState.cs @@ -52,6 +52,11 @@ namespace Rokojori Trillean signalsEnabled,Trillean visible, bool setProcessMode, Node.ProcessModeEnum processMode ) { + if ( ! Node.IsInstanceValid( target ) ) + { + return; + } + if ( Trillean.Any != processEnabled ) { target.SetProcess( TrilleanLogic.ToBool( processEnabled ) ); diff --git a/Runtime/VirtualCameras/VirtualCamera3DSlot.cs b/Runtime/VirtualCameras/VirtualCamera3DSlot.cs index e9f9794..746b3cb 100644 --- a/Runtime/VirtualCameras/VirtualCamera3DSlot.cs +++ b/Runtime/VirtualCameras/VirtualCamera3DSlot.cs @@ -36,13 +36,13 @@ namespace Rokojori { if ( cameraEffectRunner.isFinished ) { - this.LogInfo( "finished" ); + // this.LogInfo( "finished" ); cameraEffectRunner = null; } else { - this.LogInfo( "time:", cameraEffectRunner.timePosition, cameraEffectRunner.effect.maxDuration ); + // this.LogInfo( "time:", cameraEffectRunner.timePosition, cameraEffectRunner.effect.maxDuration ); cameraEffectRunner.Update(); } @@ -73,7 +73,7 @@ namespace Rokojori var offset = camera.GetGlobalOffset( cameraEffectRunner.position ); - this.LogInfo( "Cam Off", offset ); + // this.LogInfo( "Cam Off", offset ); return camera.GetCameraPosition() + offset; }