Skip to content

Commit 1b259b7

Browse files
committed
Fix naming of rollback netcode functions
1 parent 00f5508 commit 1b259b7

38 files changed

+1049
-443
lines changed

addons/FracturalCommons

Submodule FracturalCommons updated 67 files

addons/GodotRollbackNetcodeMono/GDScriptWrapper.cs

Lines changed: 0 additions & 31 deletions
This file was deleted.
Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,56 @@
11
using GDDictionary = Godot.Collections.Dictionary;
2-
using GDArray = Godot.Collections.Array;
32

43
namespace GodotRollbackNetcode
54
{
65
public interface INetworkSync { }
76
public interface IGetLocalInput : INetworkSync
87
{
9-
GDDictionary _GetLocalInput();
8+
GDDictionary _get_local_input();
109
}
1110

1211
public interface INetworkProcess : INetworkSync
1312
{
14-
void _NetworkProcess(GDDictionary input);
13+
void _network_process(GDDictionary input);
1514
}
1615

1716
public interface INetworkPreProcess : INetworkSync
1817
{
19-
void _NetworkPreprocess(GDDictionary input);
18+
void _network_preprocess(GDDictionary input);
2019
}
2120

2221
public interface INetworkPostProcess : INetworkSync
2322
{
24-
void _NetworkPostprocess(GDDictionary input);
23+
void _network_postprocess(GDDictionary input);
2524
}
2625

2726
public interface IInterpolateState : INetworkSync
2827
{
29-
void _InterpolateState(GDDictionary oldState, GDDictionary newState, float weight);
28+
void _interpolate_state(GDDictionary oldState, GDDictionary newState, float weight);
3029
}
3130

3231
public interface IPredictRemoteInput : INetworkSync
3332
{
34-
GDDictionary _PredictRemoteInput(GDDictionary previousInput, int ticksSinceRealInput);
33+
GDDictionary _predict_remote_input(GDDictionary previousInput, int ticksSinceRealInput);
3534
}
3635

3736
public interface INetworkSerializable : INetworkSync
3837
{
39-
GDDictionary _SaveState();
40-
void _LoadState(GDDictionary state);
38+
GDDictionary _save_state();
39+
void _load_state(GDDictionary state);
4140
}
4241

4342
public interface INetworkSpawnPreProcess
4443
{
45-
void _NetworkSpawnPreProcess(GDDictionary data);
44+
void _network_spawn_preprocess(GDDictionary data);
4645
}
4746

4847
public interface INetworkSpawn
4948
{
50-
void _NetworkSpawn(GDDictionary data);
49+
void _network_spawn(GDDictionary data);
5150
}
5251

5352
public interface INetworkDespawn
5453
{
55-
void _NetworkDespawn();
54+
void _network_despawn();
5655
}
5756
}

addons/GodotRollbackNetcodeMono/NetworkAnimationPlayer.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
using Fractural;
2-
using Fractural.Commons;
1+
using Fractural.Commons;
32
using Fractural.Utils;
43
using Godot;
54
using Godot.Collections;
6-
using System;
75

86
namespace GodotRollbackNetcode
97
{
@@ -20,13 +18,13 @@ public override void _Ready()
2018
AddToGroup(SyncManager.NetworkSyncGroup);
2119
}
2220

23-
public void _NetworkProcess(Dictionary input)
21+
public void _network_process(Dictionary input)
2422
{
2523
if (IsPlaying())
2624
Advance(SyncManager.Global.TickTime);
2725
}
2826

29-
public Dictionary _SaveState()
27+
public Dictionary _save_state()
3028
{
3129
if (IsPlaying() && (!AutoReset || CurrentAnimation != "RESET"))
3230
return new Dictionary()
@@ -46,7 +44,7 @@ public Dictionary _SaveState()
4644
};
4745
}
4846

49-
public void _LoadState(Dictionary state)
47+
public void _load_state(Dictionary state)
5048
{
5149
if (state.Get<bool>(nameof(IsPlaying)))
5250
{
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using Fractural;
2+
using Fractural.Utils;
3+
using Godot;
4+
5+
namespace GodotRollbackNetcode
6+
{
7+
public class NetworkAnimationPlayerWrapper : GDScriptWrapper
8+
{
9+
public bool AutoReset { get => Source.Get<bool>("auto_reset"); set => Source.Set("auto_reset", value); }
10+
public new AnimationPlayer Source => base.Source as AnimationPlayer;
11+
}
12+
}

addons/GodotRollbackNetcodeMono/NetworkRandomNumberGenerator.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using Fractural;
2-
using Fractural.Commons;
1+
using Fractural.Commons;
32
using Fractural.Utils;
43
using Godot;
54
using Godot.Collections;
@@ -12,34 +11,37 @@ public class NetworkRandomNumberGenerator : Node, INetworkSerializable
1211
private RandomNumberGenerator generator;
1312

1413
private ulong seed;
14+
[Export]
1515
public ulong Seed
1616
{
1717
get => seed;
1818
set
1919
{
2020
seed = value;
21-
generator.Seed = value;
21+
if (generator != null)
22+
generator.Seed = value;
2223
}
2324
}
2425

2526
public override void _Ready()
2627
{
2728
generator = new RandomNumberGenerator();
29+
Seed = seed;
2830
}
2931

3032
public void Randomize() => generator.Randomize();
3133
public uint Randi() => generator.Randi();
3234
public int RandiRange(int from, int to) => generator.RandiRange(from, to);
3335

34-
public Dictionary _SaveState()
36+
public Dictionary _save_state()
3537
{
3638
return new Dictionary()
3739
{
3840
["state"] = generator.State.Serialize()
3941
};
4042
}
4143

42-
public void _LoadState(Dictionary state)
44+
public void _load_state(Dictionary state)
4345
{
4446
generator.State = state.Get<byte[]>("state").DeserializePrimitive<ulong>();
4547
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using Fractural;
2+
using Fractural.Utils;
3+
using Godot;
4+
5+
namespace GodotRollbackNetcode
6+
{
7+
public class NetworkRandomNumberGeneratorWrapper : GDScriptWrapper
8+
{
9+
public RandomNumberGenerator Generator => Source.Get<RandomNumberGenerator>("generator");
10+
public ulong Seed { get => Generator.Seed; set => Generator.Seed = value; }
11+
12+
public void Randomize() => Generator.Randomize();
13+
public uint Randi() => Generator.Randi();
14+
public int RandiRange(int from, int to) => Generator.RandiRange(from, to);
15+
}
16+
}

addons/GodotRollbackNetcodeMono/NetworkTimer.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using Fractural;
2-
using Fractural.Commons;
1+
using Fractural.Commons;
32
using Godot;
43
using Godot.Collections;
54
using System;
@@ -9,15 +8,21 @@ namespace GodotRollbackNetcode
98
[RegisteredType(nameof(NetworkTimer), "res://addons/GodotRollbackNetcodeMono/Assets/NetworkTimer.svg")]
109
public class NetworkTimer : Node, INetworkSerializable, INetworkProcess
1110
{
11+
[Export]
1212
public bool Autostart { get; set; }
13+
[Export]
1314
public bool OneShot { get; set; }
15+
[Export]
1416
public int WaitTicks { get; set; }
17+
[Export]
1518
public bool HashState { get; set; }
1619
public bool IsRunning { get; private set; }
1720
public bool IsStopped => !IsRunning;
1821
public int TicksLeft { get; private set; }
1922

2023
public event Action Timeout;
24+
[Signal]
25+
public delegate void TimeoutSignal();
2126

2227
public override void _Ready()
2328
{
@@ -44,7 +49,7 @@ public void Stop()
4449
TicksLeft = 0;
4550
}
4651

47-
public void _NetworkProcess(Dictionary input)
52+
public void _network_process(Dictionary input)
4853
{
4954
if (!IsRunning) return;
5055
if (TicksLeft <= 0)
@@ -60,10 +65,11 @@ public void _NetworkProcess(Dictionary input)
6065
if (!OneShot)
6166
TicksLeft = WaitTicks;
6267
Timeout?.Invoke();
68+
EmitSignal(nameof(TimeoutSignal));
6369
}
6470
}
6571

66-
public Dictionary _SaveState()
72+
public Dictionary _save_state()
6773
{
6874
var state = new Dictionary()
6975
{
@@ -76,7 +82,7 @@ public Dictionary _SaveState()
7682
return state.IgnoreState();
7783
}
7884

79-
public void _LoadState(Dictionary state)
85+
public void _load_state(Dictionary state)
8086
{
8187
IsRunning = state.GetStateValue<bool>(nameof(IsRunning));
8288
WaitTicks = state.GetStateValue<int>(nameof(WaitTicks));
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using Fractural;
2+
using Fractural.Utils;
3+
using System;
4+
5+
namespace GodotRollbackNetcode
6+
{
7+
public class NetworkTimerWrapper : GDScriptWrapper
8+
{
9+
public bool Autostart { get => Source.Get<bool>("auto_start"); set => Source.Set("auto_start", value); }
10+
public bool OneShot { get => Source.Get<bool>("one_shot"); set => Source.Set("one_shot", value); }
11+
public int WaitTicks { get => Source.Get<int>("wait_ticks"); set => Source.Set("wait_ticks", value); }
12+
public bool HashState { get => Source.Get<bool>("hash_state"); set => Source.Set("hash_state", value); }
13+
public bool IsRunning => Source.Get<bool>("_running");
14+
public bool IsStopped => !IsRunning;
15+
public int TicksLeft => Source.Get<int>("ticks_left");
16+
17+
public event Action Timeout;
18+
19+
public void Start(int ticks = -1) => Source.Call("start", ticks);
20+
21+
public void Stop() => Source.Call("stop");
22+
23+
private void OnTimeout() => Timeout?.Invoke();
24+
25+
protected override void ForwardSignalsToEvents()
26+
{
27+
Source.Connect("timeout", this, nameof(OnTimeout));
28+
}
29+
}
30+
}

addons/godot-rollback-netcode/HashSerializer.gd

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
extends Reference
22

3+
static func is_type(obj: Object):
4+
return obj.has_method("serialize") \
5+
and obj.has_method("unserialize")
6+
37
func serialize(value):
48
if value is Dictionary:
59
return serialize_dictionary(value)
@@ -9,7 +13,7 @@ func serialize(value):
913
return serialize_resource(value)
1014
elif value is Object:
1115
return serialize_object(value)
12-
16+
1317
return serialize_other(value)
1418

1519
func serialize_dictionary(value: Dictionary) -> Dictionary:
@@ -65,19 +69,19 @@ func serialize_other(value):
6569
z = {x = value.basis.z.x, y = value.basis.z.y, z = value.basis.z.z},
6670
origin = {x = value.origin.x, y = value.origin.y, z = value.origin.z},
6771
}
68-
72+
6973
return value
7074

7175
func unserialize(value):
7276
if value is Dictionary:
7377
if not value.has('_'):
7478
return unserialize_dictionary(value)
75-
79+
7680
if value['_'] == 'resource':
7781
return unserialize_resource(value)
7882
elif value['_'] in ['Vector2', 'Vector3', 'Transform2D', 'Transform']:
7983
return unserialize_other(value)
80-
84+
8185
return unserialize_object(value)
8286
elif value is Array:
8387
return unserialize_array(value)
@@ -122,5 +126,5 @@ func unserialize_other(value: Dictionary):
122126
Vector3(value.z.x, value.z.y, value.z.z),
123127
Vector3(value.origin.x, value.origin.y, value.origin.z)
124128
)
125-
129+
126130
return null

0 commit comments

Comments
 (0)