Esempio n. 1
0
        // Function from file: master.dm
        public override int?process(dynamic seconds = null)
        {
            int       timer          = 0;
            Subsystem SS             = null;
            int?      start_time     = null;
            int       startingtick   = 0;
            bool      ran_subsystems = false;
            Subsystem SS2            = null;
            double    oldwait        = 0;
            double    global_delta   = 0;
            double    newwait        = 0;
            double    oldcost        = 0;
            double    newcost        = 0;
            Subsystem SS3            = null;
            double    extrasleep     = 0;


            if (!(GlobalVars.Failsafe != null))
            {
                new Controller_Failsafe();
            }
            Task13.Schedule(0, (Task13.Closure)(() => {
                timer = Game13.time;

                foreach (dynamic _a in Lang13.Enumerate(this.subsystems, typeof(Subsystem)))
                {
                    SS = _a;

                    timer       += this.processing_interval ?1:0;
                    SS.next_fire = timer;
                }
                start_time = null;

                while (true)
                {
                    if ((this.processing_interval ?1:0) > 0)
                    {
                        this.iteration++;
                        startingtick   = Game13.time;
                        start_time     = Game13.timeofday;
                        ran_subsystems = false;

                        foreach (dynamic _b in Lang13.Enumerate(this.subsystems, typeof(Subsystem)))
                        {
                            SS2 = _b;


                            if (Game13.cpu >= 100)
                            {
                                break;
                            }

                            if ((SS2.can_fire ?1:0) > 0)
                            {
                                if (SS2.next_fire <= Game13.time && SS2.last_fire + SS2.wait * 0.75 <= Game13.time)
                                {
                                    ran_subsystems           = true;
                                    timer                    = Game13.timeofday;
                                    this.last_type_processed = SS2.type;
                                    SS2.last_fire            = Game13.time;
                                    SS2.fire();
                                    SS2.cost = Num13.MaxInt(((int)(SS2.cost * 0.8 + (Game13.timeofday - timer) * 0.2)), 0);

                                    if (SS2.dynamic_wait)
                                    {
                                        oldwait      = SS2.wait;
                                        global_delta = this.subsystem_cost - SS2.cost / (SS2.wait / 10) - 1;
                                        newwait      = (SS2.cost - SS2.dwait_buffer + global_delta) * SS2.dwait_delta;
                                        newwait      = newwait * (Game13.cpu / 100 + 1);

                                        if (newwait < oldwait)
                                        {
                                            newwait = oldwait * 0.8 + newwait * 0.2;
                                        }
                                        SS2.wait      = Num13.MaxInt(SS2.dwait_lower, Num13.MinInt(((int)(newwait)), SS2.dwait_upper));
                                        SS2.next_fire = Game13.time + SS2.wait;
                                    }
                                    else
                                    {
                                        SS2.next_fire += SS2.wait;
                                    }
                                    SS2.times_fired++;

                                    if (startingtick < Game13.time || (start_time ?? 0) + 1 < Game13.timeofday)
                                    {
                                        break;
                                    }
                                    Task13.Sleep(0);
                                }
                            }
                        }
                        this.cost = Num13.MaxInt(((int)(this.cost * 0.8 + (Game13.timeofday - (start_time ?? 0)) * 0.2)), 0);

                        if (ran_subsystems)
                        {
                            oldcost = this.subsystem_cost;
                            newcost = 0;

                            foreach (dynamic _c in Lang13.Enumerate(this.subsystems, typeof(Subsystem)))
                            {
                                SS3 = _c;


                                if (!SS3.can_fire)
                                {
                                    continue;
                                }
                                newcost            += SS3.cost / (SS3.wait / 10);
                                this.subsystem_cost = oldcost * 0.8 + newcost * 0.2;
                            }
                        }
                        extrasleep = 0;

                        if (Game13.cpu >= 75)
                        {
                            extrasleep += (extrasleep + (this.processing_interval ?1:0)) * ((Game13.cpu - 50) / 10);
                        }

                        if (Game13.cpu >= 100)
                        {
                            if (!Lang13.Bool(this.old_fps))
                            {
                                this.old_fps = Game13.fps;
                                Game13.fps   = 10;
                            }
                        }
                        else if (Lang13.Bool(this.old_fps) && Game13.cpu < 50)
                        {
                            Game13.fps   = this.old_fps ?? 0;
                            this.old_fps = null;
                        }
                        Task13.Sleep(((int)((this.processing_interval ?1:0) + extrasleep)));
                    }
                    else
                    {
                        Task13.Sleep(50);
                    }
                }
                return;
            }));
            return(null);
        }