コード例 #1
0
 private TimeLength getStopTimeSpan(int callCount)
 {
     if (callCount == 0)
     {
         if (isKeyPressed(VK_SHIFT))
         {
             return(TimeLength.ZERO);                    // pass this station
         }
         else
         {
             return(TimeLength.fromMinutes(5));                          // make a five minutes stop
         }
     }
     else
     {
         // this train has been stopped at this station
         if (isKeyPressed(VK_UP))
         {
             return(TimeLength.ZERO);                    // move
         }
         if (isKeyPressed(VK_DOWN))
         {
             return(TimeLength.fromMinutes(-1));                 // turn around
         }
         return(TimeLength.fromMinutes(5));                      // make another five minutes stop and wait for the keyboard input
     }
 }
コード例 #2
0
        internal override TimeLength getStopTimeSpan(int callCount)
        {
            if (callCount != 0)
            {
                if (turnAround)
                {
                    return(TimeLength.fromMinutes(-1));
                }
                else
                {
                    return(TimeLength.ZERO);
                }
            }

            Clock c = World.world.clock;

            int m = c.hour * 60 + c.minutes;

            if (minutes > m)
            {
                return(TimeLength.fromMinutes(minutes - m));
            }
            else
            {
                return(TimeLength.fromMinutes(minutes - m) + TimeLength.ONEDAY);
            }
        }
コード例 #3
0
 internal Recorder()
 {
     // align the clock to 0:00am
     clock.registerRepeated(
         new ClockHandler(onClock),
         TimeLength.fromMinutes(
             TimeLength.ONEDAY.totalMinutes - (clock.totalMinutes % TimeLength.ONEDAY.totalMinutes)),
         TimeLength.ONEDAY);
 }
コード例 #4
0
        internal override TimeLength getStopTimeSpan(int callCount)
        {
            Clock clock = World.world.clock;

            if (callCount == 0)
            {
                // decide whether to stop or pass
                foreach (AdvStationRule rule in rules)
                {
                    if (rule.action == StationAction.pass && rule.matches(clock))
                    {
                        return(TimeLength.ZERO);                        // pass
                    }
                    if (rule.action == StationAction.stop && rule.matches(clock))
                    {
                        return(MIN_STOP_TIME);                          // force the train to stop at least this much
                    }
                }
                // by default, we stop.
                return(MIN_STOP_TIME);
            }
            else
            {
                // TODO: do the efficient computation by using the getNextMatch method.

                // decide whether to go or sit still
                foreach (AdvStationRule rule in rules)
                {
                    if (rule.action == StationAction.go && rule.matches(clock))
                    {
                        return(TimeLength.ZERO);                        // go
                    }
                    if (rule.action == StationAction.reverse && rule.matches(clock))
                    {
                        return(TimeLength.fromMinutes(-1));                             // turn around and go
                    }
                    if (rule.action == StationAction.stop && rule.matches(clock))
                    {
                        break;                                  // can't go
                    }
                }

                // the unit of rules is 10 minutes. So wait until the next ten minutes break
                int next = (60 - clock.minutes) % 10;
                if (next == 0)
                {
                    next = 10;
                }
                return(TimeLength.fromMinutes(next));
            }
        }
コード例 #5
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="train"></param>
 /// <param name="harbor"></param>
 /// <param name="callCount"></param>
 /// <returns></returns>
 public override TimeLength getStopTimeSpan(Train train, ITrainHarbor harbor, int callCount)
 {
     // stop 1 hour and go
     if (!(harbor is Station))
     {
         return(TimeLength.ZERO);                        // ignore everything but a station
     }
     if (callCount == 0)
     {
         return(TimeLength.fromMinutes(30));
     }
     else
     {
         return(TimeLength.ZERO);
     }
 }
コード例 #6
0
 internal override TimeLength getStopTimeSpan(int callCount)
 {
     if (callCount == 0)
     {
         return(duration);
     }
     else
     {
         if (turnAround)
         {
             return(TimeLength.fromMinutes(-1));
         }
         else
         {
             return(TimeLength.ZERO);
         }
     }
 }
コード例 #7
0
            // registers a next clock handler.
            private void registerClockHandler()
            {
                if (state == State.abandoned)
                {
                    return;
                }
                if (state == State.walled)
                {
                    // this voxel is finished. don't register another handler
                    if (--((ConstructionSite)owner).uncompletedVoxels == 0)
                    {
                        // the entire construction has finished.
                        ((ConstructionSite)owner).onFinished();
                    }
                    return;
                }

                // TODO: change the time span
                World.world.clock.registerOneShot(new ClockHandler(clockHandler),
                                                  TimeLength.fromMinutes(40 + random.Next(80)));
            }
コード例 #8
0
ファイル: Recorder.cs プロジェクト: hayate891/freetrain
        /// <summary>
        /// Create a new recorder with the given setting.
        /// </summary>
        public Recorder(Rectangle rect, VCROptions config)
        {
            drawer = new QuarterViewDrawer(World.world, MainWindow.mainWindow.directDraw, rect);

            // register timer
            World.world.clock.registerRepeated(new ClockHandler(capture), TimeLength.fromMinutes(config.period));

            // create BitmapWriter component and configure it
            writer = (IBitmapWriter) new CVideoRecorder();
            writer.Init(rect.Width, rect.Height, config.fps);

            // create DirectShow graph builder
            ICaptureGraphBuilder2 builder = (ICaptureGraphBuilder2) new CaptureGraphBuilder2Cls();

            // create AVIMux and file writer component
            IBaseFilter     pMux;
            IFileSinkFilter unused;

            builder.SetOutputFileName(ref MEDIASUBTYPE_Avi, "test.avi", out pMux, out unused);

            builder.GetFiltergraph(out graph);

            // add BitmapWriter as the source component
            graph.AddFilter((IBaseFilter)writer, "source");
            // if the compressor is specified, add it
            IBaseFilter compressor = config.compressor.bind();

            graph.AddFilter(compressor, "compressor");

            // connect components
            builder.RenderStream(IntPtr.Zero, IntPtr.Zero, writer, compressor, pMux);

            mediaControl = (IMediaControl)graph;

            // explicitly release local objects
//			Marshal.ReleaseComObject(builder);
//			Marshal.ReleaseComObject(pMux);
//			Marshal.ReleaseComObject(unused);
//			Marshal.ReleaseComObject(compressor);
        }
コード例 #9
0
 private void onOK(object sender, System.EventArgs e)
 {
     if (radioFixedDuration.Checked)
     {
         currentHandler = new FixedDurationStationHandler(TimeLength.fromMinutes((long)durationBox.Value), checkTurn1.Checked);
     }
     if (radioPass.Checked)
     {
         currentHandler = new PassStationHandler();
     }
     if (radioSimple.Checked)
     {
         currentHandler = new OnceADayStationHandler(getMinutes(), checkTurn2.Checked);
     }
     if (radioAdvanced.Checked)
     {
         if (!(currentHandler is AdvancedStationHandler))
         {
             currentHandler = new AdvancedStationHandler();
         }
     }
 }
コード例 #10
0
 public override void onDue()
 {
     base.onDue();
     if (auto_continue)
     {
         this._corpus       = amountDue;
         this._interest     = bank.GetDepositInterest(_totalPeriod);
         minInterestRate    = bank.GetDepositInterest(TimeLength.fromMinutes(Time.YEAR));
         this._begining     = clock + TimeLength.ZERO;
         this._due         += _totalPeriod;
         this._lastUnitTime = clock + TimeLength.ZERO;
         if (onStatusChanging != null)
         {
             onStatusChanging(this, AssetStatus.STATUS_UPDATING, 0);
         }
         clock.registerOneShot(new ClockHandler(onDue), _totalPeriod);
     }
     else
     {
         Cancel();
     }
 }
コード例 #11
0
        private void setClockHandlers()
        {
            //long today_h = TimeLength.pastMinutesToday().totalMinutes;
            long today_h = clock.hour;
            long today_m = today_h * Time.HOUR + clock.minutes;

            // MajorEvent occures both day and night. Generate trend making events.
            if (MajorUpdateEvent != null)
            {
                clock.unregister(MajorUpdateEvent);
            }
            MajorUpdateEvent = new ClockHandler(onMajorUpdate);
            long major = MajorUpdateStartingHour;

            while (major < today_h)
            {
                major += MajorUpdateIntervalHours;
            }
            clock.registerRepeated(MajorUpdateEvent,
                                   TimeLength.fromMinutes(major * Time.HOUR - today_m),
                                   TimeLength.fromHours(MajorUpdateIntervalHours));

            // MinorEvent dispached only in the business hours. Progresses trend only.
            if (MinorUpdateEvent != null)
            {
                clock.unregister(MinorUpdateEvent);
            }
            MinorUpdateEvent = new ClockHandler(onMinorUpdate);
            long minor = MinorUpdateStartingHour;

            while (minor < today_h)
            {
                minor += MinorUpdateIntervalHours;
            }
            clock.registerRepeated(MinorUpdateEvent,
                                   TimeLength.fromMinutes(minor * Time.HOUR - today_m),
                                   TimeLength.fromHours(MinorUpdateIntervalHours));
        }
コード例 #12
0
ファイル: StadiumStructure.cs プロジェクト: wty0512/FreeTrain
        /// <summary>
        /// Creates a new commercial structurewith its left-top corner at
        /// the specified location.
        /// </summary>
        /// <param name="_type">
        /// Type of the structure to be built.
        /// </param>
        public StadiumStructure(StructureContributionImpl _type, WorldLocator wloc) : base(_type, wloc)
        {
//			this.type = _type;

            // register once a month timer for the strength/popularity decay
            World.world.clock.registerRepeated(new ClockHandler(onClock), TimeLength.fromDays(30));

            // schedule initial games
            // minutes to the next day midnight
            TimeLength b = TimeLength.fromMinutes(
                TimeLength.ONEDAY.totalMinutes
                - (World.world.clock.totalMinutes % TimeLength.ONEDAY.totalMinutes));

            // the first game is set to 14:00 that day.
            b += TimeLength.fromHours(14);

            for (int i = 0; i < Const.SCHEDULE_DAYS; i += 7)
            {
                scheduleNewGame(b);
                scheduleNewGame(b + TimeLength.fromHours(24 * 3 + 5));                  // schdule a nighter

                b += TimeLength.fromDays(7);
            }
        }
コード例 #13
0
ファイル: Train.cs プロジェクト: wcp16/FreeTrainSDL
 private void registerTimer()
 {
     registerTimer(TimeLength.fromMinutes(type.MinutesPerVoxel));
 }
コード例 #14
0
 protected void initialize()
 {
     minInterestRate = bank.GetDepositInterest(TimeLength.fromMinutes(Time.YEAR));
     manager.spend(_corpus, genre);
 }