public void Main(string argument, UpdateType updateSource)
        {
            ECHO       = Echo;
            RUNTIME    = Runtime;
            START_TIME = DateTime.Now;
            try {
                if (_initialization != null)
                {
                    Echo("Initializing");
                    if (!_initialization.MoveNext())
                    {
                        _initialization.Dispose();
                        _initialization = null;
                    }
                }
                else
                {
                    Echo("Acting");
                    Act();
                }
            } catch (Exception e) {
                // Dump the exception content to the
                Echo("An error occurred during script execution.");
                Echo($"Exception: {e}\n---");

                // Rethrow the exception to make the programmable block halt execution properly
                throw;
            }
        }
Beispiel #2
0
            public AdvancedScheduler(int maxRunsPerTick, int instructionMargin, IMyGridProgramRuntimeInfo runtimeInfo) : base(maxRunsPerTick)
            {
                this.instructionMargin = instructionMargin;
                this.runtimeInfo       = runtimeInfo;

                maxInstructionCount = runtimeInfo.MaxInstructionCount - instructionMargin;
            }
        public Profiler(IMyGridProgramRuntimeInfo runtime, int historyMaxCount, double newValueFactor)
        {
            Runtime         = runtime;
            HistoryMaxCount = historyMaxCount;
            NewValueFactor  = newValueFactor;

            invMaxRuntimePercent   = 6;
            invMaxInstCountPercent = 100.0 / Runtime.MaxInstructionCount;
        }
Beispiel #4
0
            public BackgroundWorker(
                IBackgroundWorkerSettingsProvider backgroundWorkerSettingsProvider,
                IDateTimeProvider dateTimeProvider,
                IMyGridProgramRuntimeInfo gridProgramRuntimeInfo)
            {
                _backgroundWorkerSettingsProvider = backgroundWorkerSettingsProvider;
                _dateTimeProvider       = dateTimeProvider;
                _gridProgramRuntimeInfo = gridProgramRuntimeInfo;

                _subOperationScheduler = _scheduledSubOperations.Push;
            }
Beispiel #5
0
 public static void Shutdown()
 {
     if (b != null)
     {
         for (int i = 0, l = b.Count; i < l; i++)
         {
             b[i].Close();
         }
         k = long.
             MaxValue; StaticUpdate(); a = null; b.Clear(); b = null; c = null; g = null; h = null;
     }
 }
Beispiel #6
0
    /// <summary>
    /// Attempts to initialize the protocol
    /// </summary>
    /// <param name="runtime">runtime object</param>
    /// <param name="antennas">antennas array</param>
    /// <param name="transmissionMode">transmission mode</param>
    /// <param name="localName">local id, must be between 1 and 99 characters long</param>
    /// <param name="sendLimit">send limit per packet, if a packet is attempted to be sent more than this value, the associated connection is terminated [default=5]</param>
    /// <param name="sendTimeoutMs">time to wait between attempting packet retransmission [default=400]</param>
    /// <param name="connectionAcceptor">connection acceptor delegate, decides whether to accept an incoming connection request, null causes any such connections to be rejected</param>
    /// <param name="connectionListener">connection listener delegate, invoked when a new connection has been accepted, can be null</param>
    public static void Initialize(IMyGridProgramRuntimeInfo runtime, IMyRadioAntenna[] antennas, MyTransmitTarget transmissionMode, string localName, int sendLimit = 5, int sendTimeoutMs = 400, Func <string, byte, bool> connectionAcceptor = null, Action <IConnection> connectionListener = null)
    {
        if (m_connections == null)
        {
            if (runtime == null)
            {
                throw new Exception("runtime can not be null");
            }
            if (antennas == null || antennas.Length == 0)
            {
                throw new Exception("antennas can not be null or have length of 0");
            }
            if (localName == null || localName.Length <= 0 || localName.Length > 99)
            {
                throw new Exception("localName length must be between 1 and 9 inclusive");
            }

            m_runtime            = runtime;
            m_antennas           = (IMyRadioAntenna[])antennas.Clone();
            m_localID            = localName;
            m_sendLimit          = sendLimit <= 0 ? 1 : sendLimit;
            m_sendTimeoutMs      = sendTimeoutMs < 0 ? 0 : sendTimeoutMs;
            m_connectionAcceptor = connectionAcceptor;
            m_connectionListener = connectionListener;

            m_connections = new List <StaticConnection>();
            m_connections.Add(new StaticConnection());
            m_transmissionMode = transmissionMode;
            m_localIDLength    = m_localID.Length.ToString("00");
            CurrentTime        = sendTimeoutMs * 3;// just an arbitrary value above 0

            for (int i = 0, l = m_antennas.Length; i < l; i++)
            {
                IMyRadioAntenna a = m_antennas[i];
                if (transmissionMode == MyTransmitTarget.Owned)
                {
                    a.IgnoreAlliedBroadcast = true;
                    a.IgnoreOtherBroadcast  = true;
                }
                else if (transmissionMode == MyTransmitTarget.Ally)
                {
                    a.IgnoreAlliedBroadcast = false;
                    a.IgnoreOtherBroadcast  = true;
                }
                else if (transmissionMode == MyTransmitTarget.Enemy || transmissionMode == MyTransmitTarget.Everyone)
                {
                    a.IgnoreAlliedBroadcast = false;
                    a.IgnoreOtherBroadcast  = false;
                }
            }
        }
    }
Beispiel #7
0
 public ProgramManager(
     IBackgroundWorker backgroundWorker,
     IConfigManager configManager,
     IDoorManager doorManager,
     IEchoProvider echoProvider,
     IMyGridProgramRuntimeInfo gridProgramRuntimeInfo,
     ILogger logger)
 {
     _backgroundWorker       = backgroundWorker;
     _configManager          = configManager;
     _doorManager            = doorManager;
     _echoProvider           = echoProvider;
     _gridProgramRuntimeInfo = gridProgramRuntimeInfo;
     _logger = logger;
 }
Beispiel #8
0
 /// <summary>
 /// Shuts down this protocol if it was initialized
 /// </summary>
 public static void Shutdown()
 {
     if (m_connections != null)  // guard initialization state
     {
         for (int i = 0, l = m_connections.Count; i < l; i++)
         {
             m_connections[i].Close();
         }                            // close all connections
         CurrentTime = long.MaxValue; // set max time to enable any remaining connection_delete packets to be sent
         StaticUpdate();              // causes packets to be transmitted, best efforts scenario
         m_runtime = null;            // null out the rest members, enabling faster gc
         m_connections.Clear();
         m_connections        = null;
         m_antennas           = null;
         m_connectionAcceptor = null;
         m_connectionListener = null;
     }
 }
Beispiel #9
0
 Initialize(IMyGridProgramRuntimeInfo m, IMyRadioAntenna[] n, MyTransmitTarget o, string p, int q = 5, int r = 400, Func <string, byte, bool
                                                                                                                          > s = null, Action <IConnection> t = null)
 {
     if (b == null)
     {
         if (m == null)
         {
             throw new Exception("runtime can not be null");
         }
         if (n == null || n.
             Length == 0)
         {
             throw new Exception("antennas can not be null or have length of 0");
         }
         if (p == null || p.Length <= 0 || p.Length > 99)
         {
             throw
                 new Exception("localName length must be between 1 and 9 inclusive");
         }
         a = m; c = (IMyRadioAntenna[])n.Clone(); i = p; e = q <= 0?1:q; f = r < 0?
                                                                             0:r; g = s; h = t; b = new List <X>(); b.Add(new X()); d = o; j = i.Length.ToString("00"); k = r * 3; for (int i = 0, l = c.Length; i < l; i++)
         {
             IMyRadioAntenna a = c[i]; if (o == MyTransmitTarget.Owned)
             {
                 a.IgnoreAlliedBroadcast = true; a.IgnoreOtherBroadcast = true;
             }
             else if (o ==
                      MyTransmitTarget.Ally)
             {
                 a.IgnoreAlliedBroadcast = false; a.IgnoreOtherBroadcast = true;
             }
             else if (o == MyTransmitTarget.Enemy || o ==
                      MyTransmitTarget.Everyone)
             {
                 a.IgnoreAlliedBroadcast = false; a.IgnoreOtherBroadcast = false;
             }
         }
     }
 }
Beispiel #10
0
 public void Tick(IMyGridProgramRuntimeInfo runtime)
 {
     Tick(runtime.TimeSinceLastRun);
 }
Beispiel #11
0
 public TimingManager(IMyGridProgramRuntimeInfo runtimeInfo)
 {
     _timers      = new List <Timer>();
     _runtimeInfo = runtimeInfo;
     _time        = 0;
 }