Пример #1
0
        static Engine()
        {
            Configuration = EngineConfiguration.Open();
            MediaFile.MCIErrorsThrowExceptions = Configuration.Settings.MCIErrorsThrowExceptions;
            _startTick           = HighResTimer.GetCurrentTickCount();
            _lastCPSSamplingTick = _startTick;
            Keyboard.DefaultTicksBetweenKeyEvents = (long)(Configuration.Settings.TimeBetweenKeyboardEvents * (double)HighResTimer.TicksPerSecond);

            Directory.SetCurrentDirectory(Path.GetDirectoryName(Application.ExecutablePath));

            // deserialize all EngineState files listed in configuration
            if (Configuration.StateFiles != null && Configuration.StateFiles.LoadAtStartup == true)
            {
                foreach (var stateFile in Configuration.StateFiles)
                {
                    if (stateFile.LoadAtStartup == true)
                    {
                        LoadEngineStateFile(stateFile.Path, stateFile.IsBinary);
                    }
                }
            }

            VisibleSurfaces.ForcedRefreshRate = Configuration.Settings.VisibleSurfaceRefreshTimer;
            Application.Idle += Application_Idle;
        }
Пример #2
0
        public void Start()
        {
            // don't do anything if there is not a current movePoint
            if (_movePoint == null)
            {
                return;
            }

            // ignore if Sprite already moving
            if (Tile.TilesMoving.IndexOf(_parent) != -1)
            {
                return;
            }

            // reset velocities since using MovePoints
            _velocityX = 0;
            _velocityY = 0;

            // add Sprite to moving list
            Tile.TilesMoving.Add(_parent);

            _lastTick = HighResTimer.GetCurrentTickCount();

            // initialize MovePoint values based on Sprite's current state
            _movePoint.InitializeMovePoint();

            // raise the event
            if (Started != null)
            {
                Started(new SpriteMovementEventArgs(_parent, this));
            }
        }
Пример #3
0
        public string SaveToFile()
        {
            string file = Environment.CurrentDirectory + @"\" + this.Name + "_"
                          + HighResTimer.GetCurrentTickCount().ToString() + ".bmp";

            return(SaveToFile(file));
        }
Пример #4
0
        public static Timer Add(string timerID, TimerType timerType, TimerCycles timerCycles, double timerLength)
        {
            Timer timer = new Timer(timerType, timerCycles, HighResTimer.GetCurrentTickCount(), timerLength);

            _timers.Add(timerID, timer);
            timer.TimerID = timerID;
            return(timer);
        }
Пример #5
0
 internal Movement(DirectDrawing drawing, double totalTime, Rectangle dest)
 {
     parent      = drawing;
     startTick   = HighResTimer.GetCurrentTickCount();
     lastTick    = startTick;
     totalTicks  = (long)(totalTime * (double)HighResTimer.TicksPerSecond);
     startBounds = parent.Bounds;
     destBounds  = dest;
 }
Пример #6
0
 protected internal Movement(Sprite sprite)
 {
     _parent        = sprite;
     _lastTick      = HighResTimer.GetCurrentTickCount();
     _velocityX     = 0;
     _velocityY     = 0;
     _accelerationX = 0;
     _accelerationY = 0;
 }
Пример #7
0
            internal void Start(double totalTime, PointF dest)
            {
                Stop();

                startTick = HighResTimer.GetCurrentTickCount();
                //lastTick = startTick;
                totalTicks = (long)(totalTime * HighResTimer.TicksPerSecond);
                startCoord = parent.SourceGridPoint;
                destCoord  = dest;

                IsScrolling = true;
            }
Пример #8
0
        private ResizedFrame(Frame orig, Size render)
        {
            OriginalFrame = orig;
            RenderSize    = render;
            CreationTick  = HighResTimer.GetCurrentTickCount();

            // resize original Bitmap
            CreateResizedGDIBitmap(orig.Tilesheet, ref NewBmp, ref ResizedGraphics, ref hDC, ref hBmp);

            // resize Mask of original Bitmap
            if (OriginalFrame.Tilesheet.Mask != null)
            {
                CreateResizedGDIBitmap(orig.Tilesheet.Mask, ref NewBmpMask, ref ResizedGraphicsMask, ref hDCMask, ref hBmpMask);
            }

            // hook into Tilesheet Disposed event
            orig.Tilesheet.Disposed += Tilesheet_Disposed;

            ResizedFrameCache.Add(this.Id, this);
        }
Пример #9
0
        private static void Cycle()
        {
            long tick = HighResTimer.GetCurrentTickCount();

            // throttle time hasn't passed; do background tasks
            if ((Configuration.Settings.TargetFPS > 0) && ((double)(tick - _lastTick) < (((double)1 / (double)Configuration.Settings.TargetFPS)) * (double)HighResTimer.TicksPerSecond))
            {
                DoBackgroundTasks(tick);

                // flag that the background tasks have been run this "tick"
                _backgroundRun = true;
            }
            else        // Settings.Throttle time has passed since last tick...
            {
                // make sure background rendering done at least once
                if (!_backgroundRun)
                {
                    DoBackgroundTasks(tick);
                }

                DoForegroundTasks(tick);

                // this "tick" complete, reset flag for next tick
                _backgroundRun = false;
            }

            // increment CPS counter
            _grossCyclesThisMeasure++;
            _grossCycles++;

            // if 0 or negative, sampling is turned off
            if (Configuration.Settings.SamplingTimeForCPS > 0)
            {
                CalculateCPS(tick);
            }
        }
Пример #10
0
 public static void ResetTotalTimeRunning()
 {
     _startTick = HighResTimer.GetCurrentTickCount();
 }