Exemple #1
0
        public GameStatePacket BuildGameStatePacket()
        {
            FlatBufferBuilder builder = new FlatBufferBuilder(100);

            int ballStateOffset = -1;

            if (BallState != null)
            {
                ballStateOffset = BallState.ToFlatBuffer(builder).Value;
            }

            VectorOffset carStateVector = CreateCarStateVector(builder, carStates);

            DesiredGameState.StartDesiredGameState(builder);

            if (BallState != null)
            {
                DesiredGameState.AddBallState(builder, new Offset <DesiredBallState>(ballStateOffset));
            }

            DesiredGameState.AddCarStates(builder, carStateVector);

            builder.Finish(DesiredGameState.EndDesiredGameState(builder).Value);

            return(new GameStatePacket(builder.SizedByteArray()));
        }
        public static Offset <DesiredGameState> ToFlatBuffer(this WorldState worldState, FlatBufferBuilder builder)
        {
            DesiredGameState.StartDesiredGameState(builder);

            DesiredGameState.AddBallState(builder, worldState.Ball.ToFlatBuffer(builder));

            DesiredGameInfoState.StartDesiredGameInfoState(builder);
            DesiredGameInfoState.AddGameSpeed(builder, Float.CreateFloat(builder, worldState.GameSpeed));
            DesiredGameInfoState.AddWorldGravityZ(builder, Float.CreateFloat(builder, worldState.WorldGravityZ));
            DesiredGameInfoState.EndDesiredGameInfoState(builder);

            var carStates = new List <Offset <DesiredCarState> >();

            foreach (var player in worldState.Players)
            {
                carStates.Add(player.ToFlatBuffer(builder));
            }
            var carStateVector = DesiredGameState.CreateCarStatesVector(builder, carStates.ToArray());

            DesiredGameState.AddCarStates(builder, carStateVector);

            return(DesiredGameState.EndDesiredGameState(builder));
        }