@@ -11,6 +11,8 @@ public class CarStateTransceiver : NetworkStateTransceiverExternalBase
11
11
{
12
12
Distance ::CarStateTransceiver stateTransceiver ;
13
13
14
+ public CarLogicBridge CarLogicBridge ;
15
+
14
16
public CarStateTransceiver ( )
15
17
{
16
18
stateTransceiver = new Distance ::CarStateTransceiver ( ) ;
@@ -19,7 +21,8 @@ public CarStateTransceiver()
19
21
public override void Awake ( )
20
22
{
21
23
// Do CarStateTransceiver Awake
22
- PrivateUtilities . setPrivateField ( stateTransceiver , "carLogic_" , new CarLogicBridge ( ) ) ;
24
+ CarLogicBridge = new CarLogicBridge ( ) ;
25
+ PrivateUtilities . setPrivateField ( stateTransceiver , "carLogic_" , CarLogicBridge ) ;
23
26
PrivateUtilities . setPrivateField ( stateTransceiver , "mode_" , new GameModeBridge ( ) ) ;
24
27
// Do NetworkStateTransceiverGeneric Awake
25
28
PrivateUtilities . setPrivateField ( stateTransceiver , "buffer_" , new Distance ::SortedCircularBuffer < Distance ::CarDirectives > ( 32 ) ) ;
@@ -28,7 +31,22 @@ public override void Awake()
28
31
29
32
public override void OnSerializeNetworkView ( BitStream stream , NetworkMessageInfo info )
30
33
{
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
+ }
32
50
}
33
51
34
52
public override void Start ( )
@@ -38,7 +56,9 @@ public override void Start()
38
56
39
57
public override void Update ( )
40
58
{
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");
42
62
}
43
63
44
64
public override void FixedUpdate ( ) { }
0 commit comments