Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Thiago Zimmermann committed May 9, 2020
1 parent 57a31ad commit fd8a90a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 35 deletions.
33 changes: 9 additions & 24 deletions src/Hypnonema.Client/ClientScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,7 @@ private void OnClientResourceStart(string resourceName)

if (!double.TryParse(
API.GetResourceMetadata(API.GetCurrentResourceName(), "hypnonema_sync_interval", 0),
out var syncInterval))
{
this.syncInterval = 10000;
}
out var syncInterval)) this.syncInterval = 10000;

this.playerPool = new VideoPlayerPool(url);
this.Tick += this.OnFirstTick;
Expand Down Expand Up @@ -307,7 +304,7 @@ private CallbackDelegate OnCreateScreen(IDictionary<string, object> args, Callba
SoundMaxDistance = soundMaxDistance,
SoundMinDistance = soundMinDistance,
SoundAttenuation = soundAttenuation,
Is3DAudioEnabled = is3DAudioEnabled,
Is3DAudioEnabled = is3DAudioEnabled
},
PositionalSettings = is3DRendered
? new PositionalSettings
Expand Down Expand Up @@ -466,10 +463,9 @@ private CallbackDelegate OnEditScreen(IDictionary<string, object> args, Callback
return callback;
}

if (!bool.TryParse(args.FirstOrDefault(arg => arg.Key == "is3DAudioEnabled").Value?.ToString(), out var is3DAudioEnabled))
{
is3DAudioEnabled = false;
}
if (!bool.TryParse(
args.FirstOrDefault(arg => arg.Key == "is3DAudioEnabled").Value?.ToString(),
out var is3DAudioEnabled)) is3DAudioEnabled = false;

var screen = new Screen
{
Expand All @@ -484,7 +480,7 @@ private CallbackDelegate OnEditScreen(IDictionary<string, object> args, Callback
SoundMaxDistance = soundMaxDistance,
SoundAttenuation = soundAttenuation,
SoundMinDistance = soundMinDistance,
Is3DAudioEnabled = is3DAudioEnabled,
Is3DAudioEnabled = is3DAudioEnabled
},
TargetSettings =
is3DRendered
Expand Down Expand Up @@ -539,19 +535,14 @@ private async Task OnInitialize(string jsonScreens, int rendererLimit, bool isAc
this.playerPool.VideoPlayers?.Add(player);
}

if (isAceAllowed)
{
this.TriggerStateTick();
}
if (isAceAllowed) this.TriggerStateTick();

var state = JsonConvert.DeserializeObject<List<ScreenDuiState>>(lastKnownState);
if (state != null)
{
await Delay(5000);
foreach (var screenDuiState in state)
{
await this.playerPool.SynchronizeState(screenDuiState.State, screenDuiState.Screen);
}
}

Debug.WriteLine("Initialized..");
Expand Down Expand Up @@ -670,10 +661,7 @@ private void OnShowNUI(bool isAceAllowed, string jsonScreens)

private async Task OnStateTick()
{
if (!this.isInitialized || this.playerPool?.VideoPlayers?.Count == 0)
{
return;
}
if (!this.isInitialized || this.playerPool?.VideoPlayers?.Count == 0) return;

var stateList = new List<DuiState>();
var videoPlayers = this.playerPool?.VideoPlayers;
Expand All @@ -684,10 +672,7 @@ private async Task OnStateTick()
{
player.Browser.GetState();
var duiState = await BrowserStateHelperScript.GetLastState();
if (duiState == null)
{
continue;
}
if (duiState == null) continue;

stateList.Add(duiState);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Hypnonema.Client/Graphics/DuiBrowser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void Init(string screenName, string posterUrl)
{
this.SendMessage(new { type = "init", screenName, posterUrl });
}

public void Pause()
{
this.SendMessage(new { type = "pause" });
Expand Down
21 changes: 11 additions & 10 deletions src/Hypnonema.Client/Players/VideoPlayer3D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,6 @@ public void CalculateVolume()
}
}

public void Toggle3DAudio(bool value)
{
this.Browser.Toggle3DAudio(value);
}

private float GetSoundFactor(float distance)
{
return this.SoundMinDistance / (this.SoundMinDistance + this.SoundAttenuation
* (Math.Max(distance, this.SoundMinDistance) - this.SoundMinDistance));
}
public void Dispose()
{
if (this.Browser.IsValid) this.Browser.Dispose();
Expand Down Expand Up @@ -127,9 +117,20 @@ public void SynchronizeState(bool paused, float currentTime, string currentSourc
this.Browser.Update(paused, currentTime, currentSource);
}

public void Toggle3DAudio(bool value)
{
this.Browser.Toggle3DAudio(value);
}

public void ToggleReplay(bool replay)
{
this.Browser.ToggleReplay(replay);
}

private float GetSoundFactor(float distance)
{
return this.SoundMinDistance / (this.SoundMinDistance + this.SoundAttenuation
* (Math.Max(distance, this.SoundMinDistance) - this.SoundMinDistance));
}
}
}

0 comments on commit fd8a90a

Please sign in to comment.