예제 #1
0
        public static SerializedRuntimeState FromRuntimeState(VM.RuntimeState state)
        {
            SerializedRuntimeState serState = new SerializedRuntimeState();

            serState.IP       = state.IP;
            serState.LSLState = state.LSLState;
            serState.Globals  = SerializedLSLPrimitive.FromPrimitiveList(state.Globals);
            serState.Operands = SerializedLSLPrimitive.FromPrimitiveStack(state.Operands);



            serState.Calls = new SerializedStackFrame[state.Calls.Count];
            int i = 0;

            foreach (VM.StackFrame frame in state.Calls)
            {
                serState.Calls[i] = SerializedStackFrame.FromStackFrame(frame);
                i++;
            }

            serState.TopFrame = SerializedStackFrame.FromStackFrame(state.TopFrame);
            serState.MemInfo  = state.MemInfo;

            serState.EventQueue = new SerializedPostedEvent[state.EventQueue.Count];
            i = 0;
            foreach (VM.PostedEvent evt in state.EventQueue)
            {
                serState.EventQueue[i] = SerializedPostedEvent.FromPostedEvent(evt);
                i++;
            }

            serState.RunState = state.RunState;
            serState.Enabled  = state.GeneralEnable;

            UInt64 tickCountNow = Util.Clock.GetLongTickCount();

            serState.StateCapturedOn = DateTime.Now;

            //if the next wakeup is in the past, just filter it to be now equal to the state capture time
            //this prevents strange values from getting into the tickcounttodatetime calculation
            serState.NextWakeup           = state.NextWakeup < tickCountNow ? serState.StateCapturedOn : Util.Clock.TickCountToDateTime(state.NextWakeup, tickCountNow);
            serState.TimerLastScheduledOn = Util.Clock.TickCountToDateTime(state.TimerLastScheduledOn, tickCountNow);

            serState.TimerInterval  = state.TimerInterval;
            serState.RunningEvent   = SerializedPostedEvent.FromPostedEvent(state.RunningEvent);
            serState.ActiveListens  = new Dictionary <int, VM.ActiveListen>(state.ActiveListens);
            serState.StartParameter = state.StartParameter;

            serState.MiscAttributes = new Dictionary <int, SerializedLSLPrimitive[]>();
            foreach (KeyValuePair <int, object[]> kvp in state.MiscAttributes)
            {
                serState.MiscAttributes[kvp.Key] = SerializedLSLPrimitive.FromPrimitiveList(kvp.Value);
            }

            //calculate total runtime
            serState.TotalRuntime = state.TotalRuntime;

            return(serState);
        }
예제 #2
0
        /// <summary>
        /// Creates a new serialized event from a posted event
        /// </summary>
        /// <param name="evt"></param>
        /// <returns></returns>
        public static SerializedPostedEvent FromPostedEvent(VM.PostedEvent evt)
        {
            if (evt == null)
            {
                return(null);
            }

            SerializedPostedEvent serEvent = new SerializedPostedEvent();

            serEvent.EventType = evt.EventType;

            serEvent.Args = SerializedLSLPrimitive.FromPrimitiveList(evt.Args);

            serEvent.DetectVars = evt.DetectVars;

            serEvent.TransitionToState = evt.TransitionToState;

            return(serEvent);
        }