Ejemplo n.º 1
0
        private static void TryInitialize()
        {
            // return unless session ready
            if (MyAPIGateway.CubeBuilder == null || MyAPIGateway.Entities == null || MyAPIGateway.Multiplayer == null || MyAPIGateway.Parallel == null ||
                MyAPIGateway.Players == null || MyAPIGateway.Session == null || MyAPIGateway.TerminalActionsHelper == null || MyAPIGateway.Utilities == null ||
                (!MyAPIGateway.Multiplayer.IsServer && MyAPIGateway.Session.Player == null))
            {
                return;
            }

            var runningOn = !MyAPIGateway.Multiplayer.MultiplayerActive ? RunLocation.Both : (MyAPIGateway.Multiplayer.IsServer ? RunLocation.Server : RunLocation.Client);

            Logger.DebugLog($"Initializing. RunningOn: {runningOn}, SessionName: {MyAPIGateway.Session.Name}, SessionPath: {MyAPIGateway.Session.CurrentPath}");

            ComponentStore        = new ComponentCollectionStore(runningOn);
            ExternalRegistrations = new LockedDeque <Action>();

            MyAPIGateway.Entities.OnEntityAdd += EntityAdded;

            var entities = new HashSet <IMyEntity>();

            MyAPIGateway.Entities.GetEntities(entities);
            foreach (IMyEntity entity in entities)
            {
                EntityAdded(entity);
            }

            foreach (var collection in ComponentRegistrar.GetInitComponents())
            {
                ComponentStore.TryAddCollection(collection);
            }

            Status = RunStatus.Initialized;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Releases all resources and marks as terminated.
        /// Called by SEPC.App.MySession only.
        /// </summary>
        public static void Close()
        {
            Logger.DebugLog("Terminating");

            if (ComponentStore != null)
            {
                ComponentStore.RaiseSessionEvent(ComponentEventNames.SessionClose);
            }

            MyAPIGateway.Entities.OnEntityAdd -= EntityAdded;

            // clear fields in case SE doesn't clean up properly
            ComponentStore        = null;
            ExternalRegistrations = null;

            Status = RunStatus.Terminated;
        }