Attempt to improve time

This commit is contained in:
2026-01-01 21:49:12 +01:00
parent 69a0a752be
commit 26625f6b6f
12 changed files with 2302 additions and 1913 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -88,7 +88,7 @@ namespace Marro.PacManUdon
StartAttractMode(); StartAttractMode();
} }
public void FixedUpdate() public override void FixedUpdate()
{ {
TimeSequenceUpdate(Time.deltaTime); TimeSequenceUpdate(Time.deltaTime);
} }
@@ -422,7 +422,7 @@ namespace Marro.PacManUdon
ghostManager.SetOwner(Networking.LocalPlayer); ghostManager.SetOwner(Networking.LocalPlayer);
} }
public override void AppendSyncedData(byte[][] data, ref int offset, NetworkEventType eventType, uint eventTime) public override void AppendSyncedData(byte[][] data, ref int offset, NetworkEventType eventType)
{ {
data[offset++] = new byte[] { Int32ToByte((int)gameState) }; data[offset++] = new byte[] { Int32ToByte((int)gameState) };
data[offset++] = BitConverter.GetBytes(currentlyInTimeSequence); data[offset++] = BitConverter.GetBytes(currentlyInTimeSequence);
@@ -430,7 +430,7 @@ namespace Marro.PacManUdon
data[offset++] = BitConverter.GetBytes(timeSequenceProgress); data[offset++] = BitConverter.GetBytes(timeSequenceProgress);
} }
public override bool SetSyncedData(byte[] data, ref int offset, NetworkEventType eventType, uint eventTime) public override bool SetSyncedData(byte[] data, ref int offset, NetworkEventType eventType)
{ {
SetGameState((PacManGameState)data[offset++]); SetGameState((PacManGameState)data[offset++]);
@@ -443,11 +443,6 @@ namespace Marro.PacManUdon
return true; return true;
} }
public override void SyncedToNewTime(uint oldTime, uint newTime)
{
}
public int ExtraLives public int ExtraLives
{ {
set set

File diff suppressed because it is too large Load Diff

View File

@@ -150,7 +150,7 @@ namespace Marro.PacManUdon
// Debug.Log($"{gameObject} reset with state: {state}, target: {target}, offGrid: {offGrid}"); // Debug.Log($"{gameObject} reset with state: {state}, target: {target}, offGrid: {offGrid}");
} }
void FixedUpdate() public override void FixedUpdate()
{ {
if (ghostType == PacManGhostType.Blinky) if (ghostType == PacManGhostType.Blinky)
{ {
@@ -779,11 +779,6 @@ namespace Marro.PacManUdon
UpdateAnimator(); UpdateAnimator();
} }
public override void AppendSyncedData(byte[][] data, ref int offset, NetworkEventType eventType, uint eventTime)
{
base.AppendSyncedData(data, ref offset, eventType, eventTime);
}
void OnTriggerEnter(Collider other) void OnTriggerEnter(Collider other)
{ {
if (Networking.IsOwner(gameObject) && other.gameObject.GetComponent<PacManGhostCollider>()) if (Networking.IsOwner(gameObject) && other.gameObject.GetComponent<PacManGhostCollider>())

View File

@@ -32,7 +32,7 @@ namespace Marro.PacManUdon
protected abstract void UpdateAnimator(); protected abstract void UpdateAnimator();
public override void AppendSyncedData(byte[][] data, ref int offset, NetworkEventType eventType, uint eventTime) public override void AppendSyncedData(byte[][] data, ref int offset, NetworkEventType eventType)
{ {
var position = GetPosition(); var position = GetPosition();
data[offset++] = BitConverter.GetBytes(position.x); data[offset++] = BitConverter.GetBytes(position.x);
@@ -43,7 +43,7 @@ namespace Marro.PacManUdon
data[offset++] = BitConverter.GetBytes(direction.y); data[offset++] = BitConverter.GetBytes(direction.y);
} }
public override bool SetSyncedData(byte[] data, ref int offset, NetworkEventType eventType, uint eventTime) public override bool SetSyncedData(byte[] data, ref int offset, NetworkEventType eventType)
{ {
SetPosition(new Vector2(BitConverter.ToSingle(data, offset), BitConverter.ToSingle(data, offset + 2))); SetPosition(new Vector2(BitConverter.ToSingle(data, offset), BitConverter.ToSingle(data, offset + 2)));
SetDirection(new Vector2(BitConverter.ToSingle(data, offset + 4), BitConverter.ToSingle(data, offset + 6))); SetDirection(new Vector2(BitConverter.ToSingle(data, offset + 4), BitConverter.ToSingle(data, offset + 6)));
@@ -51,10 +51,5 @@ namespace Marro.PacManUdon
return true; return true;
} }
public override void SyncedToNewTime(uint oldTime, uint newTime)
{
}
} }
} }

View File

@@ -43,7 +43,7 @@ MonoBehaviour:
Data: Data:
- Name: - Name:
Entry: 12 Entry: 12
Data: 10 Data: 11
- Name: - Name:
Entry: 7 Entry: 7
Data: Data:
@@ -331,25 +331,19 @@ MonoBehaviour:
Data: Data:
- Name: $k - Name: $k
Entry: 1 Entry: 1
Data: nextEventTime Data: nextEventTimeTicks
- Name: $v - Name: $v
Entry: 7 Entry: 7
Data: 19|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor Data: 19|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField - Name: <Name>k__BackingField
Entry: 1 Entry: 1
Data: nextEventTime Data: nextEventTimeTicks
- Name: <UserType>k__BackingField - Name: <UserType>k__BackingField
Entry: 7 Entry: 9
Data: 20|System.RuntimeType, mscorlib Data: 17
- Name:
Entry: 1
Data: System.UInt32, mscorlib
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField - Name: <SystemType>k__BackingField
Entry: 9 Entry: 9
Data: 20 Data: 17
- Name: <SyncMode>k__BackingField - Name: <SyncMode>k__BackingField
Entry: 7 Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -364,7 +358,7 @@ MonoBehaviour:
Data: false Data: false
- Name: _fieldAttributes - Name: _fieldAttributes
Entry: 7 Entry: 7
Data: 21|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib Data: 20|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name: - Name:
Entry: 12 Entry: 12
Data: 0 Data: 0
@@ -388,13 +382,13 @@ MonoBehaviour:
Data: retriesWithoutSuccess Data: retriesWithoutSuccess
- Name: $v - Name: $v
Entry: 7 Entry: 7
Data: 22|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor Data: 21|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField - Name: <Name>k__BackingField
Entry: 1 Entry: 1
Data: retriesWithoutSuccess Data: retriesWithoutSuccess
- Name: <UserType>k__BackingField - Name: <UserType>k__BackingField
Entry: 7 Entry: 7
Data: 23|System.RuntimeType, mscorlib Data: 22|System.RuntimeType, mscorlib
- Name: - Name:
Entry: 1 Entry: 1
Data: System.Int32, mscorlib Data: System.Int32, mscorlib
@@ -403,7 +397,7 @@ MonoBehaviour:
Data: Data:
- Name: <SystemType>k__BackingField - Name: <SystemType>k__BackingField
Entry: 9 Entry: 9
Data: 23 Data: 22
- Name: <SyncMode>k__BackingField - Name: <SyncMode>k__BackingField
Entry: 7 Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -418,7 +412,7 @@ MonoBehaviour:
Data: false Data: false
- Name: _fieldAttributes - Name: _fieldAttributes
Entry: 7 Entry: 7
Data: 24|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib Data: 23|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name: - Name:
Entry: 12 Entry: 12
Data: 0 Data: 0
@@ -442,13 +436,13 @@ MonoBehaviour:
Data: buffer Data: buffer
- Name: $v - Name: $v
Entry: 7 Entry: 7
Data: 25|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor Data: 24|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField - Name: <Name>k__BackingField
Entry: 1 Entry: 1
Data: buffer Data: buffer
- Name: <UserType>k__BackingField - Name: <UserType>k__BackingField
Entry: 7 Entry: 7
Data: 26|System.RuntimeType, mscorlib Data: 25|System.RuntimeType, mscorlib
- Name: - Name:
Entry: 1 Entry: 1
Data: System.Byte[], mscorlib Data: System.Byte[], mscorlib
@@ -457,7 +451,7 @@ MonoBehaviour:
Data: Data:
- Name: <SystemType>k__BackingField - Name: <SystemType>k__BackingField
Entry: 9 Entry: 9
Data: 26 Data: 25
- Name: <SyncMode>k__BackingField - Name: <SyncMode>k__BackingField
Entry: 7 Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -472,7 +466,7 @@ MonoBehaviour:
Data: false Data: false
- Name: _fieldAttributes - Name: _fieldAttributes
Entry: 7 Entry: 7
Data: 27|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib Data: 26|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name: - Name:
Entry: 12 Entry: 12
Data: 0 Data: 0
@@ -496,16 +490,16 @@ MonoBehaviour:
Data: index Data: index
- Name: $v - Name: $v
Entry: 7 Entry: 7
Data: 28|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor Data: 27|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField - Name: <Name>k__BackingField
Entry: 1 Entry: 1
Data: index Data: index
- Name: <UserType>k__BackingField - Name: <UserType>k__BackingField
Entry: 9 Entry: 9
Data: 23 Data: 22
- Name: <SystemType>k__BackingField - Name: <SystemType>k__BackingField
Entry: 9 Entry: 9
Data: 23 Data: 22
- Name: <SyncMode>k__BackingField - Name: <SyncMode>k__BackingField
Entry: 7 Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -520,7 +514,7 @@ MonoBehaviour:
Data: false Data: false
- Name: _fieldAttributes - Name: _fieldAttributes
Entry: 7 Entry: 7
Data: 29|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib Data: 28|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name: - Name:
Entry: 12 Entry: 12
Data: 0 Data: 0
@@ -544,16 +538,16 @@ MonoBehaviour:
Data: networkedData Data: networkedData
- Name: $v - Name: $v
Entry: 7 Entry: 7
Data: 30|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor Data: 29|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField - Name: <Name>k__BackingField
Entry: 1 Entry: 1
Data: networkedData Data: networkedData
- Name: <UserType>k__BackingField - Name: <UserType>k__BackingField
Entry: 9 Entry: 9
Data: 26 Data: 25
- Name: <SystemType>k__BackingField - Name: <SystemType>k__BackingField
Entry: 9 Entry: 9
Data: 26 Data: 25
- Name: <SyncMode>k__BackingField - Name: <SyncMode>k__BackingField
Entry: 7 Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -568,13 +562,13 @@ MonoBehaviour:
Data: false Data: false
- Name: _fieldAttributes - Name: _fieldAttributes
Entry: 7 Entry: 7
Data: 31|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib Data: 30|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name: - Name:
Entry: 12 Entry: 12
Data: 1 Data: 1
- Name: - Name:
Entry: 7 Entry: 7
Data: 32|UdonSharp.UdonSyncedAttribute, UdonSharp.Runtime Data: 31|UdonSharp.UdonSyncedAttribute, UdonSharp.Runtime
- Name: - Name:
Entry: 8 Entry: 8
Data: Data:
@@ -590,6 +584,54 @@ MonoBehaviour:
- Name: - Name:
Entry: 8 Entry: 8
Data: Data:
- Name:
Entry: 7
Data:
- Name: $k
Entry: 1
Data: <CurrentTimeTicks>k__BackingField
- Name: $v
Entry: 7
Data: 32|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: <CurrentTimeTicks>k__BackingField
- Name: <UserType>k__BackingField
Entry: 9
Data: 17
- Name: <SystemType>k__BackingField
Entry: 9
Data: 17
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
- Name:
Entry: 6
Data:
- Name:
Entry: 8
Data:
- Name: <IsSerialized>k__BackingField
Entry: 5
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 33|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
- Name:
Entry: 13
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name: - Name:
Entry: 13 Entry: 13
Data: Data:

View File

@@ -1,4 +1,6 @@
using System; using Cysharp.Threading.Tasks.Triggers;
using JetBrains.Annotations;
using System;
using System.Drawing; using System.Drawing;
using System.Text; using System.Text;
using UdonSharp; using UdonSharp;
@@ -46,8 +48,7 @@ namespace Marro.PacManUdon
private bool isSynced; private bool isSynced;
private long startTimeTicks = DateTime.UtcNow.Ticks; // Initialize to prevent errors private long startTimeTicks = DateTime.UtcNow.Ticks; // Initialize to prevent errors
private long nextEventTimeTicks;
private uint nextEventTime;
private int retriesWithoutSuccess; private int retriesWithoutSuccess;
@@ -64,6 +65,8 @@ namespace Marro.PacManUdon
[UdonSynced] private byte[] networkedData = new byte[0]; [UdonSynced] private byte[] networkedData = new byte[0];
public long CurrentTimeTicks { get; private set; }
public void Initialize() public void Initialize()
{ {
if (!BitConverter.IsLittleEndian) if (!BitConverter.IsLittleEndian)
@@ -90,6 +93,8 @@ namespace Marro.PacManUdon
{ {
ProgressReplayTime(); ProgressReplayTime();
} }
UpdateTime(DateTime.UtcNow.Ticks);
} }
public void SendEvent(NetworkEventType eventType) public void SendEvent(NetworkEventType eventType)
@@ -100,13 +105,13 @@ namespace Marro.PacManUdon
return; return;
} }
var eventTime = CurrentTime; var eventTime = GetTimestamp(CurrentTimeTicks);
InitializeEvent(eventType, eventTime, BufferMaxSizeBytes, out byte[][] data, out var index); InitializeEvent(eventType, eventTime, BufferMaxSizeBytes, out byte[][] data, out var index);
foreach (var obj in syncedObjects) foreach (var obj in syncedObjects)
{ {
obj.AppendSyncedData(data, ref index, eventType, eventTime); obj.AppendSyncedData(data, ref index, eventType);
} }
// Get event size, skipping over the event size which is not yet included // Get event size, skipping over the event size which is not yet included
@@ -210,11 +215,11 @@ namespace Marro.PacManUdon
this.index = size; this.index = size;
// Sync up to the time in the full sync // Sync up to the time in the full sync
var time = BitConverter.ToUInt32(networkedData, index + HeaderTimestampIndex); var timestamp = BitConverter.ToUInt32(networkedData, index + HeaderTimestampIndex);
SyncToTime(time); SyncToTimestamp(timestamp);
// Immediately apply the full sync // Immediately apply the full sync
nextEventTime = time; nextEventTimeTicks = GetTimeTicks(timestamp);
isSynced = true; isSynced = true;
} }
@@ -233,8 +238,7 @@ namespace Marro.PacManUdon
private void ProgressReplayTime() private void ProgressReplayTime()
{ {
var currentTime = CurrentTime; while (index != 0 && nextEventTimeTicks <= CurrentTimeTicks)
while (index != 0 && nextEventTime <= currentTime)
{ {
ProcessIncomingEvent(); ProcessIncomingEvent();
UpdateNextEventTime(); UpdateNextEventTime();
@@ -248,10 +252,10 @@ namespace Marro.PacManUdon
return; return;
} }
var nextEventTime = BitConverter.ToUInt32(buffer, HeaderTimestampIndex); var nextEventTimeTicks = GetTimeTicks(BitConverter.ToUInt32(buffer, HeaderTimestampIndex));
if (nextEventTime >= this.nextEventTime) if (nextEventTimeTicks >= this.nextEventTimeTicks)
{ {
this.nextEventTime = nextEventTime; this.nextEventTimeTicks = nextEventTimeTicks;
} }
else else
{ {
@@ -263,31 +267,31 @@ namespace Marro.PacManUdon
private void ProcessIncomingEvent() private void ProcessIncomingEvent()
{ {
var eventTime = BitConverter.ToUInt32(buffer, HeaderTimestampIndex); var eventTimeTicks = GetTimeTicks(BitConverter.ToUInt32(buffer, HeaderTimestampIndex));
var eventType = (NetworkEventType)buffer[HeaderEventTypeIndex]; var eventType = (NetworkEventType)buffer[HeaderEventTypeIndex];
var index = (int)HeaderLength; // Skip header var index = (int)HeaderLength; // Skip header
if (false) // TODO: check event type UpdateTime(eventTimeTicks);
foreach (var obj in syncedObjects)
{ {
Debug.LogWarning($"({nameof(PacManUdon)} {nameof(NetworkManager)}) Invalid event type for incoming data! Buffer will be cleared."); obj.FixedUpdate();
HandleError();
return;
} }
foreach (var obj in syncedObjects) foreach (var obj in syncedObjects)
{ {
var success = obj.SetSyncedData(buffer, ref index, eventType, eventTime); var success = obj.SetSyncedData(buffer, ref index, eventType);
if (!success) if (!success)
{ {
Debug.LogWarning($"({nameof(PacManUdon)} {nameof(NetworkManager)}) Malformed data reported by {obj.name} during event type {eventType}! Resetting state."); Debug.LogWarning($"({nameof(PacManUdon)} {nameof(NetworkManager)}) Malformed data reported by {obj.name} during event type {eventType}!");
HandleError(); HandleError();
return; return;
} }
if (index > this.index) if (index > this.index)
{ {
Debug.LogWarning($"({nameof(PacManUdon)} {nameof(NetworkManager)}) Buffer overflow during SetSyncedData for {obj.name} in event type {eventType}! Resetting state."); Debug.LogWarning($"({nameof(PacManUdon)} {nameof(NetworkManager)}) Buffer overflow during {nameof(SyncedObject.SetSyncedData)} for {obj.name} in event type {eventType}!");
HandleError(); HandleError();
return; return;
} }
@@ -308,10 +312,11 @@ namespace Marro.PacManUdon
retriesWithoutSuccess = 0; // We had success! retriesWithoutSuccess = 0; // We had success!
} }
private void SyncToTime(uint newTime) private void SyncToTimestamp(uint newTime)
{ {
var timeToSyncTo = newTime - Delay; var timeToSyncTo = newTime - Delay;
startTimeTicks = DateTime.UtcNow.Ticks - timeToSyncTo * TimeSpan.TicksPerMillisecond; startTimeTicks = DateTime.UtcNow.Ticks - timeToSyncTo * TimeSpan.TicksPerMillisecond;
Debug.Log($"({nameof(PacManUdon)} {nameof(NetworkManager)}) Synced to time {newTime}, startTimeTicks is now {startTimeTicks}"); Debug.Log($"({nameof(PacManUdon)} {nameof(NetworkManager)}) Synced to time {newTime}, startTimeTicks is now {startTimeTicks}");
} }
@@ -483,12 +488,26 @@ namespace Marro.PacManUdon
} }
} }
public float GetDtInSeconds(uint currentTime, uint lastUpdate) private void UpdateTime(long timeTicks)
{ {
return (CurrentTime - lastUpdate) / 1000f; CurrentTimeTicks = timeTicks;
foreach (var obj in syncedObjects)
{
obj.Dt = (timeTicks - obj.LastUpdateTicks) / (float)TimeSpan.TicksPerSecond;
obj.LastUpdateTicks = timeTicks;
}
} }
public uint CurrentTime => (uint)((DateTime.UtcNow.Ticks - startTimeTicks) / TimeSpan.TicksPerMillisecond); public uint GetTimestamp(long timeTicks)
{
return (uint)((timeTicks - startTimeTicks) / TimeSpan.TicksPerMillisecond);
}
public long GetTimeTicks(uint timeStamp)
{
return timeStamp * TimeSpan.TicksPerMillisecond + startTimeTicks;
}
public bool IsOwner => isOwner; public bool IsOwner => isOwner;

File diff suppressed because it is too large Load Diff

View File

@@ -75,7 +75,7 @@
animator.SetTrigger("Reset"); animator.SetTrigger("Reset");
} }
void FixedUpdate() public override void FixedUpdate()
{ {
// gameStateManager.statusDisplay.SetDebugText(1, this.targetDirection.ToString()); // gameStateManager.statusDisplay.SetDebugText(1, this.targetDirection.ToString());

View File

@@ -6,8 +6,10 @@ namespace Marro.PacManUdon
{ {
public abstract class SyncedObject : UdonSharpBehaviour public abstract class SyncedObject : UdonSharpBehaviour
{ {
public abstract void AppendSyncedData(byte[][] data, ref int index, NetworkEventType eventType, uint eventTime); public long LastUpdateTicks { get; set; }
public abstract bool SetSyncedData(byte[] data, ref int index, NetworkEventType eventType, uint eventTime); public float Dt { get; set; }
public abstract void SyncedToNewTime(uint oldTime, uint newTime); public abstract void FixedUpdate();
public abstract void AppendSyncedData(byte[][] data, ref int index, NetworkEventType eventType);
public abstract bool SetSyncedData(byte[] data, ref int index, NetworkEventType eventType);
} }
} }

View File

@@ -43,7 +43,115 @@ MonoBehaviour:
Data: Data:
- Name: - Name:
Entry: 12 Entry: 12
Data: 7
- Name:
Entry: 7
Data:
- Name: $k
Entry: 1
Data: <LastUpdateTicks>k__BackingField
- Name: $v
Entry: 7
Data: 2|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: <LastUpdateTicks>k__BackingField
- Name: <UserType>k__BackingField
Entry: 7
Data: 3|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: System.Int64, mscorlib
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField
Entry: 9
Data: 3
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
- Name:
Entry: 6
Data:
- Name:
Entry: 8
Data:
- Name: <IsSerialized>k__BackingField
Entry: 5
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 4|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
- Name:
Entry: 13
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data:
- Name: $k
Entry: 1
Data: <Dt>k__BackingField
- Name: $v
Entry: 7
Data: 5|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: <Dt>k__BackingField
- Name: <UserType>k__BackingField
Entry: 7
Data: 6|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: System.Single, mscorlib
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField
Entry: 9
Data: 6 Data: 6
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
- Name:
Entry: 6
Data:
- Name:
Entry: 8
Data:
- Name: <IsSerialized>k__BackingField
Entry: 5
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 7|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
- Name:
Entry: 13
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name: - Name:
Entry: 7 Entry: 7
Data: Data:
@@ -52,13 +160,13 @@ MonoBehaviour:
Data: networkManager Data: networkManager
- Name: $v - Name: $v
Entry: 7 Entry: 7
Data: 2|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor Data: 8|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField - Name: <Name>k__BackingField
Entry: 1 Entry: 1
Data: networkManager Data: networkManager
- Name: <UserType>k__BackingField - Name: <UserType>k__BackingField
Entry: 7 Entry: 7
Data: 3|System.RuntimeType, mscorlib Data: 9|System.RuntimeType, mscorlib
- Name: - Name:
Entry: 1 Entry: 1
Data: Marro.PacManUdon.NetworkManager, Assembly-CSharp Data: Marro.PacManUdon.NetworkManager, Assembly-CSharp
@@ -67,7 +175,7 @@ MonoBehaviour:
Data: Data:
- Name: <SystemType>k__BackingField - Name: <SystemType>k__BackingField
Entry: 7 Entry: 7
Data: 4|System.RuntimeType, mscorlib Data: 10|System.RuntimeType, mscorlib
- Name: - Name:
Entry: 1 Entry: 1
Data: VRC.Udon.UdonBehaviour, VRC.Udon Data: VRC.Udon.UdonBehaviour, VRC.Udon
@@ -88,13 +196,13 @@ MonoBehaviour:
Data: true Data: true
- Name: _fieldAttributes - Name: _fieldAttributes
Entry: 7 Entry: 7
Data: 5|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib Data: 11|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name: - Name:
Entry: 12 Entry: 12
Data: 1 Data: 1
- Name: - Name:
Entry: 7 Entry: 7
Data: 6|UnityEngine.SerializeField, UnityEngine.CoreModule Data: 12|UnityEngine.SerializeField, UnityEngine.CoreModule
- Name: - Name:
Entry: 8 Entry: 8
Data: Data:
@@ -118,13 +226,13 @@ MonoBehaviour:
Data: start Data: start
- Name: $v - Name: $v
Entry: 7 Entry: 7
Data: 7|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor Data: 13|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField - Name: <Name>k__BackingField
Entry: 1 Entry: 1
Data: start Data: start
- Name: <UserType>k__BackingField - Name: <UserType>k__BackingField
Entry: 7 Entry: 7
Data: 8|System.RuntimeType, mscorlib Data: 14|System.RuntimeType, mscorlib
- Name: - Name:
Entry: 1 Entry: 1
Data: UnityEngine.Transform, UnityEngine.CoreModule Data: UnityEngine.Transform, UnityEngine.CoreModule
@@ -133,7 +241,7 @@ MonoBehaviour:
Data: Data:
- Name: <SystemType>k__BackingField - Name: <SystemType>k__BackingField
Entry: 9 Entry: 9
Data: 8 Data: 14
- Name: <SyncMode>k__BackingField - Name: <SyncMode>k__BackingField
Entry: 7 Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -148,13 +256,13 @@ MonoBehaviour:
Data: true Data: true
- Name: _fieldAttributes - Name: _fieldAttributes
Entry: 7 Entry: 7
Data: 9|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib Data: 15|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name: - Name:
Entry: 12 Entry: 12
Data: 1 Data: 1
- Name: - Name:
Entry: 7 Entry: 7
Data: 10|UnityEngine.SerializeField, UnityEngine.CoreModule Data: 16|UnityEngine.SerializeField, UnityEngine.CoreModule
- Name: - Name:
Entry: 8 Entry: 8
Data: Data:
@@ -178,16 +286,16 @@ MonoBehaviour:
Data: end Data: end
- Name: $v - Name: $v
Entry: 7 Entry: 7
Data: 11|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor Data: 17|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField - Name: <Name>k__BackingField
Entry: 1 Entry: 1
Data: end Data: end
- Name: <UserType>k__BackingField - Name: <UserType>k__BackingField
Entry: 9 Entry: 9
Data: 8 Data: 14
- Name: <SystemType>k__BackingField - Name: <SystemType>k__BackingField
Entry: 9 Entry: 9
Data: 8 Data: 14
- Name: <SyncMode>k__BackingField - Name: <SyncMode>k__BackingField
Entry: 7 Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -202,13 +310,13 @@ MonoBehaviour:
Data: true Data: true
- Name: _fieldAttributes - Name: _fieldAttributes
Entry: 7 Entry: 7
Data: 12|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib Data: 18|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name: - Name:
Entry: 12 Entry: 12
Data: 1 Data: 1
- Name: - Name:
Entry: 7 Entry: 7
Data: 13|UnityEngine.SerializeField, UnityEngine.CoreModule Data: 19|UnityEngine.SerializeField, UnityEngine.CoreModule
- Name: - Name:
Entry: 8 Entry: 8
Data: Data:
@@ -232,22 +340,16 @@ MonoBehaviour:
Data: amountUp Data: amountUp
- Name: $v - Name: $v
Entry: 7 Entry: 7
Data: 14|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor Data: 20|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField - Name: <Name>k__BackingField
Entry: 1 Entry: 1
Data: amountUp Data: amountUp
- Name: <UserType>k__BackingField - Name: <UserType>k__BackingField
Entry: 7 Entry: 9
Data: 15|System.RuntimeType, mscorlib Data: 6
- Name:
Entry: 1
Data: System.Single, mscorlib
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField - Name: <SystemType>k__BackingField
Entry: 9 Entry: 9
Data: 15 Data: 6
- Name: <SyncMode>k__BackingField - Name: <SyncMode>k__BackingField
Entry: 7 Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -262,7 +364,7 @@ MonoBehaviour:
Data: false Data: false
- Name: _fieldAttributes - Name: _fieldAttributes
Entry: 7 Entry: 7
Data: 16|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib Data: 21|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name: - Name:
Entry: 12 Entry: 12
Data: 0 Data: 0
@@ -286,13 +388,13 @@ MonoBehaviour:
Data: loopOffset Data: loopOffset
- Name: $v - Name: $v
Entry: 7 Entry: 7
Data: 17|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor Data: 22|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField - Name: <Name>k__BackingField
Entry: 1 Entry: 1
Data: loopOffset Data: loopOffset
- Name: <UserType>k__BackingField - Name: <UserType>k__BackingField
Entry: 7 Entry: 7
Data: 18|System.RuntimeType, mscorlib Data: 23|System.RuntimeType, mscorlib
- Name: - Name:
Entry: 1 Entry: 1
Data: System.Int32, mscorlib Data: System.Int32, mscorlib
@@ -301,7 +403,7 @@ MonoBehaviour:
Data: Data:
- Name: <SystemType>k__BackingField - Name: <SystemType>k__BackingField
Entry: 9 Entry: 9
Data: 18 Data: 23
- Name: <SyncMode>k__BackingField - Name: <SyncMode>k__BackingField
Entry: 7 Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -316,61 +418,7 @@ MonoBehaviour:
Data: false Data: false
- Name: _fieldAttributes - Name: _fieldAttributes
Entry: 7 Entry: 7
Data: 19|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib Data: 24|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
- Name:
Entry: 13
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data:
- Name: $k
Entry: 1
Data: lastUpdate
- Name: $v
Entry: 7
Data: 20|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: lastUpdate
- Name: <UserType>k__BackingField
Entry: 7
Data: 21|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: System.UInt32, mscorlib
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField
Entry: 9
Data: 21
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
- Name:
Entry: 6
Data:
- Name:
Entry: 8
Data:
- Name: <IsSerialized>k__BackingField
Entry: 5
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 22|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name: - Name:
Entry: 12 Entry: 12
Data: 0 Data: 0

View File

@@ -17,91 +17,74 @@ public class TestBall : SyncedObject
private float amountUp = 0; private float amountUp = 0;
private int loopOffset = 0; private int loopOffset = 0;
private uint lastUpdate;
private void Start() private void Start()
{ {
networkManager.Initialize(); networkManager.Initialize();
lastUpdate = networkManager.CurrentTime;
} }
public void FixedUpdate() public override void FixedUpdate()
{ {
var currentTime = networkManager.CurrentTime; DeltaUp(-DownPerSecond * Dt);
float dt = networkManager.GetDtInSeconds(currentTime, lastUpdate);
DeltaUp(-DownPerSecond * dt);
float progress = GetProgress(currentTime); float progress = GetProgress();
transform.position = Vector3.Lerp(start.position, end.position, progress) + amountUp * MaxUp * Vector3.up; transform.position = Vector3.Lerp(start.position, end.position, progress) + amountUp * MaxUp * Vector3.up;;
lastUpdate = currentTime;
} }
private void DeltaUp(float delta) private void DeltaUp(float delta)
{ {
amountUp = Mathf.Clamp(amountUp + delta, 0, 1); amountUp = Mathf.Clamp(amountUp + delta, 0, 1);
//Debug.Log($"delta: {delta}, amountUp: {amountUp}");
} }
private void SetProgress(float progress, uint currentTime) private void SetProgress(float progress)
{ {
//loopOffset = (int)(progress * LoopTimeMs % (LoopTimeMs + currentTime)); var currentTimestamp = networkManager.GetTimestamp(networkManager.CurrentTimeTicks);
loopOffset = (int)(currentTime - progress * LoopTimeMs); loopOffset = (int)(currentTimestamp - progress * LoopTimeMs);
//loopOffset = (int)currentTime % LoopTimeMs + (int)(progress * LoopTimeMs);
} }
private float GetProgress(uint currentTime) private float GetProgress()
{ {
return ((int)currentTime - loopOffset) % LoopTimeMs / (float)LoopTimeMs; // "uint % int" is not exposed, I love working in Udon var currentTimestamp = networkManager.GetTimestamp(networkManager.CurrentTimeTicks);
//return loopOffset - ((int)currentTime % LoopTimeMs) / (float)LoopTimeMs; // "uint % int" is not exposed, I love working in Udon return ((int)currentTimestamp - loopOffset) % LoopTimeMs / (float)LoopTimeMs; // "uint % int" is not exposed, I love working in Udon
} }
public void UpButtonPressed() public void UpButtonPressed()
{ {
DeltaUp(UpPerPress); DeltaUp(UpPerPress);
Debug.Log($"({nameof(TestBall)}) Up button pressed, jumped up at {GetProgress(networkManager.CurrentTime)} to {amountUp}."); Debug.Log($"({nameof(TestBall)}) Up button pressed, jumped up at {GetProgress()} to {amountUp}.");
networkManager.SendEvent((NetworkEventType)1); networkManager.SendEvent((NetworkEventType)1);
} }
public void SyncButtonPressed() public void SyncButtonPressed()
{ {
networkManager.SendEvent((NetworkEventType)0); networkManager.SendEvent((NetworkEventType)0);
Debug.Log($"({nameof(TestBall)}) Sync button pressed, synced at progress {GetProgress(networkManager.CurrentTime)} and amountUp {amountUp}."); Debug.Log($"({nameof(TestBall)}) Sync button pressed, synced at progress {GetProgress()} and amountUp {amountUp}.");
} }
public override void AppendSyncedData(byte[][] data, ref int index, NetworkEventType eventType, uint eventTime) public override void AppendSyncedData(byte[][] data, ref int index, NetworkEventType eventType)
{ {
var currentTime = networkManager.CurrentTime;
if (eventType == 0) if (eventType == 0)
{ {
data[index++] = BitConverter.GetBytes(amountUp); data[index++] = BitConverter.GetBytes(amountUp);
data[index++] = BitConverter.GetBytes(GetProgress(currentTime)); data[index++] = BitConverter.GetBytes(GetProgress());
} }
} }
public override bool SetSyncedData(byte[] data, ref int index, NetworkEventType eventType, uint eventTime) public override bool SetSyncedData(byte[] data, ref int index, NetworkEventType eventType)
{ {
var currentTime = networkManager.CurrentTime;
if (eventType == 0) if (eventType == 0)
{ {
amountUp = BitConverter.ToSingle(data, index); amountUp = BitConverter.ToSingle(data, index);
SetProgress(BitConverter.ToSingle(data, index + 4), currentTime); SetProgress(BitConverter.ToSingle(data, index + 4));
Debug.Log($"({nameof(TestBall)}) Received sync event, synced to progress {GetProgress(currentTime)} and amountUp {amountUp}."); Debug.Log($"({nameof(TestBall)}) Received sync event, synced to progress {GetProgress()} and amountUp {amountUp}.");
index += 8; index += 8;
} }
else else
{ {
DeltaUp(UpPerPress); DeltaUp(UpPerPress);
Debug.Log($"({nameof(TestBall)}) Received up event, jumped up at {GetProgress(networkManager.CurrentTime)} to {amountUp}."); Debug.Log($"({nameof(TestBall)}) Received up event, jumped up at {GetProgress()} to {amountUp}.");
} }
return true; return true;
} }
public override void SyncedToNewTime(uint oldTime, uint newTime)
{
lastUpdate += newTime - oldTime;
}
} }