Esempio n. 1
0
        public void Main(string argument, UpdateType updateSource)
        {
            // Echo some information about 'me' and why we were run
            Echo("Source=" + updateSource.ToString());
            Echo("Me=" + Me.EntityId.ToString("X"));
            Echo(Me.CubeGrid.CustomName);

            if (!_areWeInited)
            {
                InitMessageHandlers();
                _areWeInited = true;
            }

            // always check for IGC messages in case some aren't using callbacks
            _wicoIGC.ProcessIGCMessages();
            if ((updateSource & UpdateType.IGC) > 0)
            {
                // we got a callback for an IGC message.
                // but we already processed them.
            }
            else if ((updateSource & _utTriggers) > 0)
            {
                // if we got a 'trigger' source, send out the received argument
                IGC.SendBroadcastMessage(_broadCastTag, argument);
                Echo("Sending Message:\n" + argument);
            }
            else if ((updateSource & _utUpdates) > 0)
            {
                // it was an automatic update

                // this script doesn't have anything to do in this section
            }
        }
Esempio n. 2
0
        public void Main(string argument, UpdateType updateSource)
        {
            // Echo some information aboue 'me' and why we were run
            Echo("Source=" + updateSource.ToString());
            Echo("Me=" + Me.EntityId.ToString("X"));
            Echo(Me.CubeGrid.CustomName);

            if (!bInit)
            {
                InitMessageHandlers();
                bInit = true;
            }

            // use if not setting callbacks for any of the desired channels
            //            if (bInit) wicoIGC.ProcessIGCMessages();

            if ((updateSource & UpdateType.IGC) > 0)
            {
                // we got a callback for an IGC message.
                // There might be multiple incoming IGC messages
                wicoIGC.ProcessIGCMessages();
            }
            else if ((updateSource & utTriggers) > 0)
            {
                // if we got a 'trigger' source, send out the received argument
                IGC.SendBroadcastMessage(sBroadCastTag, argument);
            }
            else if ((updateSource & utUpdates) > 0)
            {
                // it was an automatic update
            }
        }
Esempio n. 3
0
        public void Main(string argument, UpdateType updateSource)
        {
            LastRunMs = Runtime.LastRunTimeMs;
            if (bInitDone)
            { // only count max if done with init.
                if (LastRunMs > MaxRunMs)
                {
                    MaxRunMs = LastRunMs;
                }
            }
            if (moduleList != "")
            {
                Echo(moduleList.Trim());
            }
            ModulePreMain(argument, updateSource);
            if (tmGridCheckElapsedMs >= 0)
            {
                tmGridCheckElapsedMs += Runtime.TimeSinceLastRun.TotalMilliseconds;
            }
            if (!bInitDone)
            {
                if (!WicoLocalInit())
                {
                    // we did not complete an init.
                    Echo("Init Incomplete.  Trying again");

                    // try again
                    Runtime.UpdateFrequency = UpdateFrequency.Once;
                    return;
                }
            }
            else
            {
//                Echo("Inited");
                _wicoControl.AnnounceState();

                /*
                 * // only do this on update, not triggers
                 * if ((updateSource & utUpdates) > 0)
                 * {
                 *  //                    Echo("Init and update. Elapsed:" +tmGridCheckElapsedMs.ToString("0.00"));
                 *  //                    Echo("Local:" + wicoBlockMaster.localBlocksCount.ToString() + " blocks");
                 *  if (tmGridCheckElapsedMs > tmGridCheckWaitMs || tmGridCheckElapsedMs < 0) // it is time to scan..
                 *  {
                 *      //                      Echo("time to check");
                 *      tmGridCheckElapsedMs = 0;
                 *      if (wicoBlockMaster.CalcLocalGridChange())
                 *      {
                 *          //                            mesurface0.WriteText("GRID check!");
                 *          //                            Echo("GRID CHANGED!");
                 *          //                            mesurface0.WriteText("GRID CHANGED!", true);
                 * //                            bInitDone = false;
                 *          tmGridCheckElapsedMs = 0;
                 *          Runtime.UpdateFrequency |= UpdateFrequency.Once; // cause ourselves to run again to continue initialization
                 *          return;
                 *      }
                 *      //                        else Echo("No Grid Change");
                 *  }
                 *  //else Echo("Not Timeto check");
                 * }
                 * //                else Echo("Init and NOTE update");
                 */
            }

            if ((updateSource & UpdateType.IGC) > 0)
            {
//                Echo("IGC");
                wicoIGC.ProcessIGCMessages();
            }
            if ((updateSource & (utTriggers)) > 0)
            {
                //                Echo("Triggers:"+argument);
//               ErrorLog("Trigger:"+updateSource.ToString()+":" + argument);
                MyCommandLine useCommandLine = null;
                if (myCommandLine.TryParse(argument))
                {
                    useCommandLine = myCommandLine;
                }
                bool bProcessed = false;

//                if(myCommandLine.ArgumentCount>1)
                {
                    if (argument == "save")
                    {
                        Save();
                        ErrorLog("After Save storage=");
                        ErrorLog(Storage);
                        bProcessed = true;
                    }
                }
                if (!bProcessed)
                {
                    foreach (var handler in UpdateTriggerHandlers)
                    {
                        handler(argument, useCommandLine, updateSource);
                    }
                }
            }
            if ((updateSource & (utUpdates)) > 0)
            {
                _wicoControl.ResetUpdates();
                Echo("Update:" + updateSource.ToString());
                foreach (var handler in UpdateUpdateHandlers)
                {
                    handler(updateSource);
                }
            }

            if (sMasterReporting != "")
            {
                Echo("Reporting:\n" + sMasterReporting);
            }
            if (sMasterReporting.Length > 1024 * 2)
            {
                sMasterReporting = "";
            }

            ModulePostMain();
            wicoElapsedTime.CheckTimers();
            if (bCustomDataNeedsSave)
            {
                bCustomDataNeedsSave = false;
                Me.CustomData        = _CustomDataIni.ToString();
            }

            Runtime.UpdateFrequency = _wicoControl.GenerateUpdate();
        }
Esempio n. 4
0
        public void Main(string argument, UpdateType updateSource)
        {
            wicoControl.ResetUpdates();
            ModulePreMain(argument, updateSource);
            if (tmGridCheckElapsedMs >= 0)
            {
                tmGridCheckElapsedMs += Runtime.TimeSinceLastRun.TotalMilliseconds;
            }
            if (!WicoLocalInit())
            {
                Echo("Init");
            }
            else
            {
                if (wicoControl.IamMain())
                {
                    Echo("MAIN MODULE");
                }
                else
                {
                    Echo("SUB MODULE");
                }
                // only do this on update, not triggers
                if ((updateSource & utUpdates) > 0)
                {
                    //                    Echo("Init and update. Elapsed:" +tmGridCheckElapsedMs.ToString("0.00"));
                    //                    Echo("Local:" + wicoBlockMaster.localBlocksCount.ToString() + " blocks");
                    if (tmGridCheckElapsedMs > tmGridCheckWaitMs || tmGridCheckElapsedMs < 0) // it is time to scan..
                    {
                        //                      Echo("time to check");
                        tmGridCheckElapsedMs = 0;
                        if (wicoBlockMaster.CalcLocalGridChange())
                        {
                            //                            mesurface0.WriteText("GRID check!");
                            //                            Echo("GRID CHANGED!");
                            //                            mesurface0.WriteText("GRID CHANGED!", true);
                            bInitDone                = false;
                            tmGridCheckElapsedMs     = -1;
                            Runtime.UpdateFrequency |= UpdateFrequency.Once; // cause ourselves to run again to continue initialization
                            return;
                        }
                        //                        else Echo("No Grid Change");
                    }
                    //else Echo("Not Timeto check");
                }
                //                else Echo("Init and NOTE update");
            }
//            Echo(updateSource.ToString());
            if ((updateSource & UpdateType.IGC) > 0)
            {
                //                Echo("IGC");
                wicoIGC.ProcessIGCMessages();
                if (wicoControl.IamMain())
                {
                    mesurface1.WriteText("Master Module");
                }
                else
                {
                    mesurface1.WriteText("Sub Module");
                }
            }
            if ((updateSource & (utTriggers)) > 0)
            {
                Echo("Triggers:" + argument);
                MyCommandLine useCommandLine = null;
                if (myCommandLine.TryParse(argument))
                {
                    useCommandLine = myCommandLine;
                }
                bool bProcessed = false;
                if (myCommandLine.ArgumentCount > 1)
                {
                    if (myCommandLine.Argument(0) == "setmode")
                    {
                        int  toMode = 0;
                        bool bOK    = int.TryParse(myCommandLine.Argument(1), out toMode);
                        if (bOK)
                        {
                            wicoControl.SetMode(toMode);
                            bProcessed = true;
                        }
                    }
                }
                if (!bProcessed)
                {
                    foreach (var handler in UpdateTriggerHandlers)
                    {
                        handler(argument, useCommandLine, updateSource);
                    }
                }
            }
            if ((updateSource & (utUpdates)) > 0)
            {
                //                Echo("Update");
                foreach (var handler in UpdateUpdateHandlers)
                {
                    handler(updateSource);
                }
            }

            /*
             * Echo("I Am Main=" + wicoControl.IamMain().ToString());
             * Echo(wicoThrusters.ThrusterCount() + " Thrusters Found");
             *
             * if (wicoGyros.gyroControl == null)
             *  wicoGyros.SetController();
             * Echo(wicoGyros.NumberAllGyros() + " Total Gyros Found");
             * Echo(wicoGyros.NumberUsedGyros() + " Used Gyros");
             *
             * var shipController= wicoBlockMaster.GetMainController();
             * if (shipController != null)
             *  Echo("Controller = " + shipController.CustomName);
             */
            Echo("Mode=" + wicoControl.IMode.ToString() + " State=" + wicoControl.IState.ToString());

            Echo("Reporting:\n" + sMasterReporting);

            ModulePostMain();
            Runtime.UpdateFrequency = wicoControl.GenerateUpdate()
                                      | UpdateFrequency.Update100
            ;
        }