Beispiel #1
0
        /// <summary>
        /// Initializes once MySession is ready, runs external actions, and propagates updates to the store.
        /// Called by SEPC.App.MySession only.
        /// </summary>
        public static void Update()
        {
            try
            {
                if (Status == RunStatus.Terminated)
                {
                    return;
                }

                if (Status == RunStatus.NotInitialized)
                {
                    TryInitialize();
                    return;
                }

                if (ExternalRegistrations.Count != 0)
                {
                    ExternalRegistrations.PopHeadInvokeAll();
                }

                ComponentStore.Update();
            }
            catch (Exception error)
            {
                Logger.Log("Error: " + error, Severity.Level.FATAL);
                Status = RunStatus.Terminated;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Initializes if needed, issues updates.
        /// </summary>
        public override void UpdateAfterSimulation()
        {
            MainLock.MainThread_ReleaseExclusive();
            try
            {
                switch (ManagerStatus)
                {
                case Status.Not_Initialized:
                    Init();
                    return;

                case Status.Initialized:
                    if (ServerSettings.ServerSettingsLoaded)
                    {
                        Log.DebugLog("Server settings loaded");
                        Start();
                    }
                    return;

                case Status.Terminated:
                    return;
                }
                Dictionary <Action, uint> Unregister = null;

                if (AddRemoveActions.Count != 0)
                {
                    try
                    { AddRemoveActions.PopHeadInvokeAll(); }
                    catch (Exception ex)
                    { Log.AlwaysLog("Exception in AddRemoveActions: " + ex, Logger.severity.ERROR); }
                }

                if (ExternalRegistrations.Count != 0)
                {
                    try
                    { ExternalRegistrations.PopHeadInvokeAll(); }
                    catch (Exception ex)
                    { Log.AlwaysLog("Exception in ExternalRegistrations: " + ex, Logger.severity.ERROR); }
                }

                foreach (KeyValuePair <uint, List <Action> > pair in UpdateRegistrar)
                {
                    if (Globals.UpdateCount % pair.Key == 0)
                    {
                        foreach (Action item in pair.Value)
                        {
                            try
                            {
                                Profiler.StartProfileBlock(item);
                                item.Invoke();
                                Profiler.EndProfileBlock();
                            }
                            catch (Exception ex2)
                            {
                                if (Unregister == null)
                                {
                                    Unregister = new Dictionary <Action, uint>();
                                }
                                if (!Unregister.ContainsKey(item))
                                {
                                    Log.AlwaysLog("Script threw exception, unregistering: " + ex2, Logger.severity.ERROR);
                                    Logger.DebugNotify("A script has been terminated", 10000, Logger.severity.ERROR);
                                    Unregister.Add(item, pair.Key);
                                }
                            }
                        }
                    }
                }

                if (Unregister != null)
                {
                    foreach (KeyValuePair <Action, uint> pair in Unregister)
                    {
                        UnRegisterForUpdates(pair.Value, pair.Key);
                    }
                }
            }
            catch (Exception ex)
            {
                Log.AlwaysLog("Exception: " + ex, Logger.severity.FATAL);
                ManagerStatus = Status.Terminated;
            }
            finally
            {
                Globals.UpdateCount++;

                float instantSimSpeed = Globals.UpdateDuration / (float)(DateTime.UtcNow - m_lastUpdate).TotalSeconds;
                if (instantSimSpeed > 0.01f && instantSimSpeed < 1.1f)
                {
                    Globals.SimSpeed = Globals.SimSpeed * 0.9f + instantSimSpeed * 0.1f;
                }
                //Log.DebugLog("instantSimSpeed: " + instantSimSpeed + ", SimSpeed: " + Globals.SimSpeed);
                m_lastUpdate = DateTime.UtcNow;

                MainLock.MainThread_AcquireExclusive();
            }
        }