Beispiel #1
0
        /// <summary>
        /// Creates a delta between a state and a record. If forceUpdate is set
        /// to false, this function will return null if there is no change between
        /// the current and basis.
        /// </summary>
        internal static RailStateDelta CreateDelta(
            EntityId entityId,
            RailState current,
            RailStateRecord basisRecord,
            bool includeControllerData,
            bool includeImmutableData,
            Tick commandAck,
            Tick removedTick)
        {
            bool shouldReturn =
                includeControllerData ||
                includeImmutableData ||
                removedTick.IsValid;

            uint flags = RailState.FLAGS_ALL;

            if ((basisRecord != null) && (basisRecord.State != null))
            {
                flags = current.CompareMutableData(basisRecord.State);
            }
            if ((flags == 0) && (shouldReturn == false))
            {
                return(null);
            }

            RailState deltaState = RailState.Create(current.factoryType);

            deltaState.Flags = flags;
            deltaState.ApplyMutableFrom(current, deltaState.Flags);

            deltaState.HasControllerData = includeControllerData;
            if (includeControllerData)
            {
                deltaState.ApplyControllerFrom(current);
            }

            deltaState.HasImmutableData = includeImmutableData;
            if (includeImmutableData)
            {
                deltaState.ApplyImmutableFrom(current);
            }

            deltaState.RemovedTick = removedTick;
            deltaState.CommandAck  = commandAck;

            // We don't need to include a tick when sending -- it's in the packet
            RailStateDelta delta = RailResource.Instance.CreateDelta();

            delta.Initialize(Tick.INVALID, entityId, deltaState, false);
            return(delta);
        }
Beispiel #2
0
        /// <summary>
        /// Creates a record of the current state, taking the latest record (if
        /// any) into account. If a latest state is given, this function will
        /// return null if there is no change between the current and latest.
        /// </summary>
        internal static RailStateRecord CreateRecord(
            Tick tick,
            RailState current,
            RailStateRecord latestRecord = null)
        {
            if (latestRecord != null)
            {
                RailState latest       = latestRecord.State;
                bool      shouldReturn =
                    (current.CompareMutableData(latest) > 0) ||
                    (current.IsControllerDataEqual(latest) == false);
                if (shouldReturn == false)
                {
                    return(null);
                }
            }

            RailStateRecord record = RailResource.Instance.CreateRecord();

            record.Overwrite(tick, current);
            return(record);
        }