Skip to content

Commit

Permalink
Reduce network size for mini player and theme controller (#315)
Browse files Browse the repository at this point in the history
* Reduce network size for theme colors

* Reduce network size in mini player

* Deprecate customThemeColors array

* expand logic in OnGUI

* set a non 0 value for the flag byte

---------

Co-authored-by: Pema Malling <[email protected]>
  • Loading branch information
Happyrobot33 and pema99 authored Sep 8, 2024
1 parent dd38446 commit 87feadb
Show file tree
Hide file tree
Showing 5 changed files with 615 additions and 144 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,26 @@ public class AudioLinkMiniPlayer : UdonSharpBehaviour
int _syncVideoNumber;
int _loadedVideoNumber;

[UdonSynced, NonSerialized]
/// <summary>
/// Synced via <see cref="_flags"/>
/// </summary>
[NonSerialized]
public bool _syncOwnerPlaying;

[UdonSynced]
float _syncVideoStartNetworkTime;

[UdonSynced]
/// <summary>
/// Synced via <see cref="_flags"/>
/// </summary>
bool _syncLocked = true;

/// <summary>
/// Flags byte for various settings that are synced. Order is <see cref="_syncOwnerPlaying"/>, <see cref="_syncLocked"/>
/// </summary>
[UdonSynced]
byte _flags = 0b10;

[NonSerialized]
public int localPlayerState = PLAYER_STATE_STOPPED;
[NonSerialized]
Expand Down Expand Up @@ -102,6 +113,8 @@ void Start()

_currentPlayer = avProVideo;

CopyIntoFlags();

if (Networking.IsOwner(gameObject))
{
_syncLocked = defaultLocked;
Expand All @@ -112,6 +125,27 @@ void Start()
}
}

/// <summary>
/// Copys all the associated bools into the flags byte
/// </summary>
private void CopyIntoFlags()
{
_flags = 0;
if (_syncOwnerPlaying)
_flags |= 1;
if (_syncLocked)
_flags |= 2;
}

/// <summary>
/// Copys all the associated bools out of the flags byte into the associated bools
/// </summary>
private void CopyOutOfFlags()
{
_syncOwnerPlaying = (_flags & 1) != 0;
_syncLocked = (_flags & 2) != 0;
}

public void _TriggerPlay()
{
if (debugLogging)
Expand Down Expand Up @@ -469,10 +503,17 @@ public bool _CanTakeControl()
return player.isMaster || player.isInstanceOwner || !_syncLocked;
}

public override void OnPreSerialization()
{
CopyIntoFlags();
}

public override void OnDeserialization()
{
if (Networking.IsOwner(gameObject))
return;

CopyOutOfFlags();

if (debugLogging)
{
Expand Down
Loading

0 comments on commit 87feadb

Please sign in to comment.