Exemplo n.º 1
0
 /// <summary>Creates the watcher</summary>
 /// <param name="b">Block whose <see cref="IMyTerminalBlock.CustomData"/> we're intersted in</param>
 /// <param name="spawner">To spawn the watch process</param>
 public IniWatcher(IMyTerminalBlock b, IProcessSpawner spawner)
 {
     this.block = b;
     this.Parse(b.CustomData);
     this.previous = this.block.CustomData;
     spawner.Spawn(this.update, "ini-update", period: 100);
 }
Exemplo n.º 2
0
 /// <summary>Creates a new network</summary>
 /// <param name="remote">The remote doing the autopilot, and whose position is used as a referential</param>
 /// <param name="logger">Optional logger</param>
 /// <param name="spawner">Used to spawn the update processes</param>
 public WPNetwork(IMyRemoteControl remote, Action <string> logger, IProcessSpawner spawner)
 {
     this.logger = logger;
     this.remote = remote;
     this.updateData();
     spawner.Spawn(p => this.updateData(), "wpn-update", period: 100);
 }
Exemplo n.º 3
0
 public DoorManager(MyGridProgram program, IProcessSpawner spawner, Action <string> logger)
 {
     this.logger      = logger;
     this.mainProcess = spawner.Spawn(this._handleDoors, "autodoors-main");
     this.Scan(program);
     this.mainProcess.Spawn(p => this.Scan(program), "scan", period: 431);
 }
Exemplo n.º 4
0
 public GridManager(MyGridProgram program, MyIni ini, IProcessSpawner spawner, Action <string> logger)
 {
     this.logger = logger;
     this._block = program.Me;
     this.Scan(program.GridTerminalSystem);
     spawner.Spawn(p => this.Scan(program.GridTerminalSystem), "grid-scanner", period: 100);
     this._managedGrids = new HashSet <string>(ini.Get(INI_SECTION, "managed-grids").ToString().Split(SPLIT_VALUES_CHAR, StringSplitOptions.RemoveEmptyEntries));
     this.log($"We manage {this._managedGrids.Count} grids");
 }
Exemplo n.º 5
0
            public CameraTurret(IMyGridTerminalSystem gts, IProcessSpawner spawner)
            {
                this.camera = gts.GetBlockWithName("SMB Turret Camera") as IMyCameraBlock;
                this.pitch  = gts.GetBlockWithName("SMB Camera Turret Rotor") as IMyMotorStator;
                this.yaw    = gts.GetBlockWithName("SMB Camera Turret Base Rotor") as IMyMotorStator;
                gts.GetBlocksOfType(this.controllers);

                spawner.Spawn(this.main, "camera-turret");
            }
Exemplo n.º 6
0
            /// <summary>Create a <see cref="CommandLine"/> able to parse and dispatch commands to its registered <see cref="Command"/>.</summary>
            /// <param name="name">Name of the command line.</param>
            /// <param name="logger">Optional logger to log some events.</param>
            /// <param name="spawner">Default spawner used for the processes.</param>
            public CommandLine(string name, Action <string> logger, IProcessSpawner spawner)
            {
                this.name    = name;
                this.logger  = logger;
                this.spawner = spawner;

                this.RegisterCommand(new Command("help", Command.Wrap(this.help), "Displays this help or help on a command", detailedHelp: @"If no argument, gives the list of available command
Else, gives the detailed help on the command", maxArgs: 1));
                this.log($"'{this.name}' initialized. Run '-help' for more info");
                if ((spawner as IProcessManager) != null)
                {
                    this.RegisterCommand(new Command("kill", Command.Wrap(this.kill), "Kills processes by pid or by name", nArgs: 1, detailedHelp: @"If a number is provided, it will kill the process with the given process id.
Otherwise, it kills all the process with the given name."));
                    this.RegisterCommand(new Command("ps", Command.Wrap(this.ps), "Lists alive processes", nArgs: 0));
                }
            }
Exemplo n.º 7
0
            public Logger(IProcessSpawner spawner, IMyTextSurface s, Color?bgdCol = null, Color?col = null, Action <string> echo = null, float size = 0.5f)
            {
                int nMsgs = 1;

                if (s != null)
                {
                    s.TextPadding     = 0;
                    s.ContentType     = (ContentType)1;
                    s.Alignment       = 0;
                    s.Font            = "Monospace";
                    s.FontSize        = size;
                    s.FontColor       = col ?? Color.White;
                    s.BackgroundColor = bgdCol ?? Color.Black;
                    var sb = new StringBuilder("G");
                    nMsgs        = (int)((GetMultiplier(s) * s.SurfaceSize.Y / s.MeasureStringInPixels(sb, s.Font, s.FontSize).Y) + 0.1f);
                    this.surface = s;
                }
                this.messages = new CircularBuffer <string>(nMsgs);
                spawner.Spawn(p => this.flush(), "logger");
                this.echo = echo;
            }
 /// <summary>Creates a new transformer</summary>
 /// <param name="block">Reference block, coordinates will then be </param>
 /// <param name="spawner">If present, a <see cref="Process"/> will be spawned to update the transformer each tick</param>
 public CoordinatesTransformer(IMyTerminalBlock block, IProcessSpawner spawner = null)
 {
     this.reference = block;
     this.update(null);
     spawner?.Spawn(this.update, $"coords-transformer {this.reference.DisplayNameText}");
 }
Exemplo n.º 9
0
 public MiscInventoryManager(IMyGridTerminalSystem gts, GridManager gridManager, IProcessSpawner spawner, Action <string> logger)
 {
     this.Scan(gts, gridManager);
     spawner.Spawn(p => this.Scan(gts, gridManager), "misc-inventory-groomer", period: 300);
     this.logger = logger;
 }
Exemplo n.º 10
0
 public InventoriesGroomer(GridManager gridManager, ContainerManager contManager, AssemblerManager assemblerManager,
                           MiscInventoryManager miscInventoryManager, RefineryManager refineryManager, IProcessSpawner spawner, Action <string> logger)
 {
     this.logger             = logger;
     this._outputInventories = new List <IOutputInventoryCollection> {
         assemblerManager, miscInventoryManager, refineryManager
     };
     spawner.Spawn(p => this._groomContainers(contManager), "container-groomer", period: 100);
     spawner.Spawn(p => this.groomOutputInventories(gridManager, contManager), "producer-groomer", period: 47);
 }
Exemplo n.º 11
0
 public AutoConnectionServer(MyIni ini, IMyIntergridCommunicationSystem igc, AutoConnector connector, IProcessSpawner spawner, Action <string> logger)
     : this(igc, connector, spawner)
 {
     this.logger = logger;
     this.deserialize(ini);
 }
Exemplo n.º 12
0
 public AutoConnectionServer(IMyIntergridCommunicationSystem igc, AutoConnector connector, IProcessSpawner spawner)
 {
     this.connector   = connector;
     this.igc         = igc;
     this.mainProcess = spawner.Spawn(p => this.Update(), $"ac-server '{this.Name}'", onDone => this.connector.Stop());
     this.logger?.Invoke($"Connector {this.Name} ready");
 }
Exemplo n.º 13
0
 public ScreensController(GeneralStatus status, InventoriesController inventoryController, IMyTextSurface drillStatusSurface,
                          IMyTextSurface wheelStatusSurface, ColorScheme scheme, string sprites, IProcessSpawner spawner)
 {
     this._scheme = scheme;
     if (drillStatusSurface != null)
     {
         var offset = new Vector2(2, 25);
         var sprts  = new ShapeCollections(this._scheme);
         sprts.Parse(sprites);
         this._drillSurface = new Display(drillStatusSurface, offset, scheme: this._scheme, sprites: sprts);
     }
     if (wheelStatusSurface != null)
     {
         this._wheelSurface = new Display(wheelStatusSurface, scheme: this._scheme);
     }
     this._status = status;
     spawner.Spawn(p => this._updateScreens(status, inventoryController), "screens-update", period: 20);
 }
Exemplo n.º 14
0
 public InventoryManager(IProcessSpawner spawner, Action <List <IMyCargoContainer> > containersGetter)
 {
     containersGetter(this.containers);
     spawner.Spawn(p => this.updateStatus(containersGetter), "inventory-process", period: 100);
 }
Exemplo n.º 15
0
 public BatteryManager(Program p, IProcessSpawner spawner)
 {
     this.update(p);
     spawner.Spawn(process => this.update(p), "battery-manager", period: 100);
 }
Exemplo n.º 16
0
            public Projector(IMyDoor door, IMyPistonBase piston, IMyProjector projector, IProcessSpawner spawner, Action <string, string> logger)
            {
                this.door        = door;
                this.piston      = piston;
                this.projector   = projector;
                this.mainProcess = spawner.Spawn(null, "projector-process");
                this.logger      = logger;

                if (this.door.Status == DoorStatus.Closing || this.piston.Velocity < 0)
                {
                    this.Retract();
                }
                else if (this.door.Status == DoorStatus.Opening || this.piston.Velocity > 0)
                {
                    this.Deploy();
                }
            }
Exemplo n.º 17
0
 public RefineryManager(IMyGridTerminalSystem gts, GridManager gridManager, IProcessSpawner spawner)
 {
     this.Scan(gts, gridManager);
     spawner.Spawn(p => this.Scan(gts, gridManager), "refinery-scanner", period: 100);
 }
Exemplo n.º 18
0
            /// <summary> Parses the command and spawns the corresponding process.</summary>
            /// <param name="cmd">Command with the command name and its arguments</param>
            /// <param name="trigger">What triggered the command, for some limited access control</param>
            /// <param name="onDone">Callback the process will call on termination</param>
            /// <param name="spawner">The spawner (typically a <see cref="Process"/>) used to spawn the process. If null, <see cref="CommandLine.spawner"/> will be used.</param>
            /// <returns>The spawned <see cref="Process"/>. Can be null if it failed or was executed immediately.</returns>
            public Process StartCmd(string cmd, CommandTrigger trigger, Action <Process> onDone = null, IProcessSpawner spawner = null)
            {
                MyTuple <string, List <string> > parsed = this.ParseCommand(cmd);

                if (parsed.Item1 != "")
                {
                    Command command;
                    if (this.commands.TryGetValue(parsed.Item1, out command))
                    {
                        return(command.Spawn(parsed.Item2, this.log, onDone, spawner ?? this.spawner, trigger));
                    }
                    else
                    {
                        this.log($"Unknown command {parsed.Item1}");
                    }
                }
                return(null);
            }
Exemplo n.º 19
0
 /// <summary>Spawns a new <see cref="Process"/>, taking into account the arguments. Can fail and return null if the arguments are incorrect.</summary>
 /// <param name="args">The arguments given to the command line.</param>
 /// <param name="logger">The logger the process can use to log.</param>
 /// <param name="onDone">The callback to call on process termination.</param>
 /// <param name="spawner">Used to spawn the process</param>
 /// <param name="trigger">What triggered the command</param>
 /// <returns>The spawned process, if successful.</returns>
 public Process Spawn(List <string> args, Action <string> logger, Action <Process> onDone, IProcessSpawner spawner, CommandTrigger trigger)
 {
     if (trigger < this.RequiredTrigger)
     {
         logger?.Invoke($"Permission denied for '{this.Name}'");
     }
     else if (args.Count <= this.MaxArgs && args.Count >= this.MinArgs)
     {
         MyTuple <int, bool, Action <Process> > parameters = this.provider(args, logger);
         return(spawner.Spawn(parameters.Item3, this.Name, onDone, parameters.Item1, parameters.Item2));
     }
     else
     {
         logger?.Invoke($"Wrong number of arguments for '{this.Name}'");
         logger?.Invoke($"Run -help '{this.Name}' for more info");
     }
     return(null);
 }
Exemplo n.º 20
0
 public AssemblerManager(IMyGridTerminalSystem gts, GridManager gridManager, IProcessSpawner spawner)
 {
     this.Scan(gts, gridManager);
     spawner.Spawn(p => this.Scan(gts, gridManager), "assembler-scanner", period: 100);
 }
Exemplo n.º 21
0
            public InventoriesController(CoordinatesTransformer tformer, IMyGridTerminalSystem gts, IMyCockpit cockpit, double idealCenterOfMass, IProcessSpawner spawner)
            {
                this._cpit     = cockpit;
                this._idealCoM = idealCenterOfMass;
                var containers = new List <IMyCargoContainer>();

                gts.GetBlocksOfType(containers, c => c.CubeGrid == cockpit.CubeGrid);
                this._invs = containers
                             .Select(c => new Inventory(c, tformer.Pos(c.GetPosition()).Z))
                             .OrderBy(inv => inv.Z)
                             .ToList();
                gts.GetBlocksOfType(this._lights, light => light.DisplayNameText.StartsWith("BM Spotlight") &&
                                    !light.DisplayNameText.Contains("Rear"));
                spawner.Spawn(p => this.updateDrills(), "drill-updater");

                this._invAction = spawner.Spawn(p => this.updateInventories(tformer.Pos(cockpit.CenterOfMass).Z), "inv-handle", period: 100);
            }
Exemplo n.º 22
0
 public Welder(IEnumerable <IMyPistonBase> pistons, IMySensorBlock sensor, IEnumerable <IMyShipWelder> welders, IEnumerable <IMyLightingBlock> lights, int positionMultiplier, IProcessSpawner spawner)
 {
     this.lights             = lights;
     this.pistons            = pistons;
     this.positionMultiplier = positionMultiplier;
     this.sensor             = sensor;
     this.welders            = welders;
     this.mainProcess        = spawner.Spawn(null, "welder-process");
     this.sensor.Enabled     = false;
     if (this.pistons.First().Velocity > 0)
     {
         this.Deploy();
     }
     else if (this.welders.First().Enabled)
     {
         this.move(0);
     }
     else if (this.pistons.First().Velocity < 0)
     {
         this.Retract();
     }
 }
Exemplo n.º 23
0
 public FabricatorDisplay(IMyTextSurface statusDisplay, IMyTextSurface mandatoryDisplay, IMyTextSurface otherDisplay, string name, Projector projector, Welder welder, InventoryManager invManager, IProcessSpawner spawner)
 {
     this.statusDisplay    = new Display(statusDisplay);
     this.mandatoryDisplay = new Display(mandatoryDisplay);
     this.otherDisplay     = new Display(otherDisplay);
     this.invManager       = invManager;
     this.name             = name;
     this.welder           = welder;
     this.projector        = projector;
     this.mainProcess      = spawner.Spawn(p => this.updateDisplays(), "display-process", period: 30);
 }
Exemplo n.º 24
0
            //readonly List<Display> wheelDisplays;

            public ScreensController(GeneralStatus status, InventoryWatcher invWatcher, IEnumerable <IMyTextSurface> drillStatusSurfaces,
                                     IEnumerable <IMyTextSurface> wheelStatusSurfaces, ColorScheme scheme, string sprites, IProcessSpawner spawner)
            {
                this.scheme = scheme;
                var sprts = new ShapeCollections(this.scheme);

                sprts.Parse(sprites);
                this.drillDisplays = drillStatusSurfaces.Select(s => new Display(s, new Vector2(2, 25), scheme: this.scheme, sprites: sprts)).ToList();
                //this.wheelDisplays = wheelStatusSurfaces.Select(s => new Display(s, new Vector2(2, 25), scheme: this.scheme)).ToList();
                this.status = status;
                spawner.Spawn(p => this.updateScreens(status, invWatcher), "screens-update", period: 20);
            }
Exemplo n.º 25
0
 public ContainerManager(IMyGridTerminalSystem gts, GridManager gridManager, IProcessSpawner spawner, Action <string> logger)
 {
     this.logger = logger;
     spawner.Spawn(p => this.Scan(gts, gridManager), "container-scanner", period: 100);
     this.Scan(gts, gridManager);
 }