Update
This commit is contained in:
parent
b5567a0bcd
commit
3961b17226
|
@ -10,10 +10,14 @@ namespace Rokojori
|
||||||
[Export]
|
[Export]
|
||||||
public AudioStreamPlayer3D player;
|
public AudioStreamPlayer3D player;
|
||||||
|
|
||||||
|
[Export]
|
||||||
|
public SelectorFlag overdrivePreventionFlag;
|
||||||
|
|
||||||
|
|
||||||
[Export]
|
[Export]
|
||||||
public Duration overdrivePreventionDuration;
|
public Duration overdrivePreventionDuration;
|
||||||
|
|
||||||
float _lastSoundPlayed;
|
|
||||||
[ExportGroup("Randomize Playback Position")]
|
[ExportGroup("Randomize Playback Position")]
|
||||||
[Export]
|
[Export]
|
||||||
public bool randomizePlaybackPosition = false;
|
public bool randomizePlaybackPosition = false;
|
||||||
|
@ -21,6 +25,10 @@ namespace Rokojori
|
||||||
[Export]
|
[Export]
|
||||||
public Duration durationPerSound;
|
public Duration durationPerSound;
|
||||||
|
|
||||||
|
[Export]
|
||||||
|
public float cutBufferLengths = 0;
|
||||||
|
|
||||||
|
|
||||||
[Export]
|
[Export]
|
||||||
public bool generatePools = true;
|
public bool generatePools = true;
|
||||||
|
|
||||||
|
@ -56,21 +64,31 @@ namespace Rokojori
|
||||||
|
|
||||||
protected override void _OnTrigger()
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var offset = 0f;
|
var offset = 0f;
|
||||||
|
|
||||||
var player = generatePools ? GetFreePlayer() : this.player;
|
var player = generatePools ? GetFreePlayer() : this.player;
|
||||||
|
|
||||||
|
if ( ! IsInstanceValid( player ) )
|
||||||
|
{
|
||||||
|
this.LogInfo( "Can't play sound, invalid" );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if ( randomizePlaybackPosition )
|
if ( randomizePlaybackPosition )
|
||||||
{
|
{
|
||||||
var random = LCG.WithSeed( networkSeed );
|
var random = LCG.WithSeed( networkSeed );
|
||||||
|
@ -85,13 +103,21 @@ namespace Rokojori
|
||||||
|
|
||||||
player.Play( offset );
|
player.Play( offset );
|
||||||
|
|
||||||
|
this.LogInfo( "Play sound", offset, HierarchyName.Of( player ) );
|
||||||
|
|
||||||
|
if ( overdrivePreventionFlag != null )
|
||||||
|
{
|
||||||
|
audioManager.RecordSoundPlaying( overdrivePreventionFlag );
|
||||||
|
}
|
||||||
|
|
||||||
if ( randomizePlaybackPosition )
|
if ( randomizePlaybackPosition )
|
||||||
{
|
{
|
||||||
var tl = TimeLineManager.Ensure( durationPerSound.timeLine );
|
var tl = TimeLineManager.Ensure( durationPerSound.timeLine );
|
||||||
|
|
||||||
var start = tl.position;
|
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 )=>
|
( span, type )=>
|
||||||
{
|
{
|
||||||
var timeNow = tl.position;
|
var timeNow = tl.position;
|
||||||
|
|
|
@ -21,6 +21,12 @@ namespace Rokojori
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
CallDeferred( nameof( DisableShape ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
void DisableShape()
|
||||||
|
{
|
||||||
shape3D.Disabled = disabled;
|
shape3D.Disabled = disabled;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,8 @@ namespace Rokojori
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.LogInfo( "Remove", HierarchyName.Of( target ) );
|
||||||
|
|
||||||
target.SelfDestroy( queue );
|
target.SelfDestroy( queue );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
uid://dsbph60xvjkaw
|
|
@ -52,6 +52,11 @@ namespace Rokojori
|
||||||
Trillean signalsEnabled,Trillean visible, bool setProcessMode, Node.ProcessModeEnum processMode
|
Trillean signalsEnabled,Trillean visible, bool setProcessMode, Node.ProcessModeEnum processMode
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
if ( ! Node.IsInstanceValid( target ) )
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if ( Trillean.Any != processEnabled )
|
if ( Trillean.Any != processEnabled )
|
||||||
{
|
{
|
||||||
target.SetProcess( TrilleanLogic.ToBool( processEnabled ) );
|
target.SetProcess( TrilleanLogic.ToBool( processEnabled ) );
|
||||||
|
|
|
@ -36,13 +36,13 @@ namespace Rokojori
|
||||||
{
|
{
|
||||||
if ( cameraEffectRunner.isFinished )
|
if ( cameraEffectRunner.isFinished )
|
||||||
{
|
{
|
||||||
this.LogInfo( "finished" );
|
// this.LogInfo( "finished" );
|
||||||
cameraEffectRunner = null;
|
cameraEffectRunner = null;
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this.LogInfo( "time:", cameraEffectRunner.timePosition, cameraEffectRunner.effect.maxDuration );
|
// this.LogInfo( "time:", cameraEffectRunner.timePosition, cameraEffectRunner.effect.maxDuration );
|
||||||
cameraEffectRunner.Update();
|
cameraEffectRunner.Update();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -73,7 +73,7 @@ namespace Rokojori
|
||||||
|
|
||||||
var offset = camera.GetGlobalOffset( cameraEffectRunner.position );
|
var offset = camera.GetGlobalOffset( cameraEffectRunner.position );
|
||||||
|
|
||||||
this.LogInfo( "Cam Off", offset );
|
// this.LogInfo( "Cam Off", offset );
|
||||||
|
|
||||||
return camera.GetCameraPosition() + offset;
|
return camera.GetCameraPosition() + offset;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue