This commit is contained in:
Josef 2025-07-25 17:35:19 +02:00
parent b5567a0bcd
commit 3961b17226
7 changed files with 91 additions and 10 deletions

View File

@ -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;
@ -21,6 +25,10 @@ namespace Rokojori
[Export]
public Duration durationPerSound;
[Export]
public float cutBufferLengths = 0;
[Export]
public bool generatePools = true;
@ -56,21 +64,31 @@ namespace Rokojori
protected override void _OnTrigger()
{
if ( overdrivePreventionDuration != null )
{
var now = TimeLine.osTime;
var elapsed = now - _lastSoundPlayed;
if ( elapsed < overdrivePreventionDuration.GetDurationInSeconds() )
var audioManager = Unique<AudioManager>.Get();
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 )
{
var random = LCG.WithSeed( networkSeed );
@ -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;

View File

@ -21,6 +21,12 @@ namespace Rokojori
return;
}
CallDeferred( nameof( DisableShape ) );
}
void DisableShape()
{
shape3D.Disabled = disabled;
}
}

View File

@ -20,6 +20,8 @@ namespace Rokojori
return;
}
this.LogInfo( "Remove", HierarchyName.Of( target ) );
target.SelfDestroy( queue );
}

View File

@ -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<SelectorFlag,float> _lastPlayTime = new Dictionary<SelectorFlag, float>();
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;
}
}
}

View File

@ -0,0 +1 @@
uid://dsbph60xvjkaw

View File

@ -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 ) );

View File

@ -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;
}