Skip to content

Commit b8ce842

Browse files
committed
Fix CarStateTransceiver
1 parent 965c495 commit b8ce842

File tree

6 files changed

+102
-80
lines changed

6 files changed

+102
-80
lines changed

DistanceServer/BasicAutoServer.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
{
22
"ServerName": "Test Server",
33
"Port": 45671,
4-
"LoadWorkshopLevels": true,
4+
"LoadWorkshopLevels": false,
55
"ReportToMasterServer": false,
66
"WelcomeMessage": "Hello, $player",
7-
"LevelTimeout": 60.0/*,
7+
"LevelTimeout": 60.0,
8+
"IdleTimeout": 10.0,
89
"Workshop":[
910
{
1011
"Search":"",
@@ -38,5 +39,5 @@
3839
"Tags":["Sprint"],
3940
"Count":200
4041
}
41-
]*/
42+
]
4243
}

DistanceServer/DistanceServerBaseExternal/Data/DistanceCar.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ public void MakeNetworker()
203203
}
204204

205205
Rigidbody = networker.GetComponent<Rigidbody>();
206+
CarDirectives = CarStateTransceiver.CarLogicBridge.CarDirectives_;
206207

207208
Log.WriteLine("Created DistanceCarNetworker");
208209

DistanceServer/DistanceServerBaseExternal/Distance/CarLogicBridge.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
using System.Threading.Tasks;
88

99

10-
class CarLogicBridge : Distance::CarLogic
10+
public class CarLogicBridge : Distance::CarLogic
1111
{
1212
public CarLogicBridge()
1313
{

DistanceServer/DistanceServerBaseExternal/Distance/Transceivers/CarStateTransceiver.cs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ public class CarStateTransceiver : NetworkStateTransceiverExternalBase
1111
{
1212
Distance::CarStateTransceiver stateTransceiver;
1313

14+
public CarLogicBridge CarLogicBridge;
15+
1416
public CarStateTransceiver()
1517
{
1618
stateTransceiver = new Distance::CarStateTransceiver();
@@ -19,7 +21,8 @@ public CarStateTransceiver()
1921
public override void Awake()
2022
{
2123
// Do CarStateTransceiver Awake
22-
PrivateUtilities.setPrivateField(stateTransceiver, "carLogic_", new CarLogicBridge());
24+
CarLogicBridge = new CarLogicBridge();
25+
PrivateUtilities.setPrivateField(stateTransceiver, "carLogic_", CarLogicBridge);
2326
PrivateUtilities.setPrivateField(stateTransceiver, "mode_", new GameModeBridge());
2427
// Do NetworkStateTransceiverGeneric Awake
2528
PrivateUtilities.setPrivateField(stateTransceiver, "buffer_", new Distance::SortedCircularBuffer<Distance::CarDirectives>(32));
@@ -28,7 +31,22 @@ public override void Awake()
2831

2932
public override void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
3033
{
31-
stateTransceiver.OnSerializeNetworkView(stream, info);
34+
if (stream.isReading)
35+
{
36+
// Bypass SortedCircularBuffer logic. We assume that this is the newest CarDirectives data and update the main CarDirectives.
37+
// TODO: use SortedCircularBuffer. Find what index is the newest, streamed in data and call Serialize on it.
38+
// (We have to do this because Serialize is not called normally, which means that correct network data never gets turned into a non-zero CarDirectives)
39+
var newStream = ((Distance::BitStreamUnity)PrivateUtilities.getPrivateField(typeof(Distance::NetworkStateTransceiver), stateTransceiver, "stream_"));
40+
newStream.Encapsulate(stream);
41+
double timestamp = double.MinValue;
42+
newStream.Serialize(ref timestamp);
43+
CarLogicBridge.CarDirectives_.StreamIn(newStream);
44+
PrivateUtilities.callPrivateMethod(CarLogicBridge.CarDirectives_, "Serialize", new Distance::BitEncoder(CarLogicBridge.CarDirectives_.Bits_));
45+
}
46+
else
47+
{
48+
stateTransceiver.OnSerializeNetworkView(stream, info);
49+
}
3250
}
3351

3452
public override void Start()
@@ -38,7 +56,9 @@ public override void Start()
3856

3957
public override void Update()
4058
{
41-
PrivateUtilities.callPrivateMethod(stateTransceiver, "Update");
59+
// For CarStateTransceiver, all this does is copy data from the buffer to the main CarDirectives
60+
// Since we are bypassing this at the moment, it would just copy zeros over already non-zero data.
61+
//PrivateUtilities.callPrivateMethod(stateTransceiver, "Update");
4262
}
4363

4464
public override void FixedUpdate() { }

DistanceServer/DistanceServerBaseExternal/DistanceServer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ public bool AttemptToStartLevel()
532532
{
533533
foreach (var player in ValidPlayers)
534534
{
535-
if (player.State != DistancePlayer.PlayerState.LoadingGameModeScene)
535+
if (player.State == DistancePlayer.PlayerState.LoadingGameModeScene)
536536
{
537537
player.Stuck = true;
538538
}

0 commit comments

Comments
 (0)