示例#1
0
        void IModule.Update(float elapsedSeconds)
        {
            netSession.update();

            var   rawTickInterval = sim.settings.GetLocalProperty("tick-interval");
            float tickInterval    = 1.0f;

            if (rawTickInterval != null)
            {
                try { tickInterval = Convert.ToSingle(rawTickInterval); }
                catch (Exception) { }
            }
            ;
            if (tickInterval <= 0)
            {
                tickInterval = 1.0f;
            }

            tickSeconds += elapsedSeconds;
            if (tickSeconds > tickInterval)
            {
                tickSeconds -= tickInterval;
                var datagram = new Network.WriteOnlyDatagram();

                foreach (var message in pendingMessages)
                {
                    datagram.WriteUInt(2u, 8);
                    datagram.WriteUInt((uint)message.Length, 32);
                    datagram.WriteBytes(message);
                }
                pendingMessages.Clear();

                foreach (var syncable in syncables)
                {
                    var syncData = new WriteOnlyDatagram();
                    syncable.WriteFullSync(syncData);
                    if (syncData.LengthInBytes > 0)
                    {
                        datagram.WriteUInt(1u, 8);
                        //datagram.WriteUInt(syncable.EntityID, 32);
                        //datagram.WriteUInt(syncable.SyncID, 8);
                        datagram.WriteUInt((uint)syncData.LengthInBytes, 32);
                        datagram.WriteBytes(syncData.BufferAsArray);
                    }
                }

                netSession.broadcastCriticalDatagram(datagram.BufferAsArray);
            }
        }
示例#2
0
 void Network.ISyncable.WriteFullSync(Network.WriteOnlyDatagram datagram)
 {
     datagram.WriteBytes(BitConverter.GetBytes(Position.X));
     datagram.WriteBytes(BitConverter.GetBytes(Position.Y));
     datagram.WriteBytes(BitConverter.GetBytes(Position.Z));
     datagram.WriteBytes(BitConverter.GetBytes(Scale.X));
     datagram.WriteBytes(BitConverter.GetBytes(Scale.Y));
     datagram.WriteBytes(BitConverter.GetBytes(Scale.Z));
     datagram.WriteBytes(BitConverter.GetBytes(Orientation.X));
     datagram.WriteBytes(BitConverter.GetBytes(Orientation.Y));
     datagram.WriteBytes(BitConverter.GetBytes(Orientation.Z));
 }