コード例 #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;
        }