Ejemplo n.º 1
0
        private void OnRenderFrame(object sender, FrameEventArgs e)
        {
            if (GraphicsContext.CurrentContext == null || GraphicsContext.CurrentContext.IsDisposed)
            {
                return;
            }

            //Should not happen at all..
            if (!GraphicsContext.CurrentContext.IsCurrent)
            {
                OpenTkGameWindow.MakeCurrent();
            }

            if (Game != null)
            {
                _drawGameTime.Update(_now - _lastDrawTime);
                _lastDrawTime = _now;
                Game.DoDraw(_drawGameTime);
            }
            // GG EDIT flush to clear out buffers
#if FALSE
#if NACL
            OpenTK.Graphics.ES20.GL.Finish();
#else
            OpenTK.Graphics.OpenGL.GL.Flush();
#endif
#endif

            OpenTkGameWindow.SwapBuffers();
        }
        private void OnRenderFrame(object sender, FrameEventArgs e)
        {
            if (GraphicsContext.CurrentContext == null || GraphicsContext.CurrentContext.IsDisposed)
            {
                return;
            }

            //Should not happen at all..
            if (!GraphicsContext.CurrentContext.IsCurrent)
            {
                OpenTkGameWindow.MakeCurrent();
            }

            if (Game != null)
            {
                _now = DateTime.Now;
                _updateGameTime.Update(_now - _lastUpdate);
                Game.DoUpdate(_updateGameTime);

                _drawGameTime.Update(_now - _lastUpdate);
                _lastUpdate = _now;
                Game.DoDraw(_drawGameTime);
            }

            OpenTkGameWindow.SwapBuffers();
        }
Ejemplo n.º 3
0
        protected override void OnRenderFrame(FrameEventArgs e)
        {
            base.OnRenderFrame(e);

            if (GraphicsContext == null || GraphicsContext.IsDisposed)
            {
                return;
            }

            //Should not happen at all..
            if (!GraphicsContext.IsCurrent)
            {
                MakeCurrent();
            }

            if (game != null)
            {
                _drawGameTime.Update(_now - _lastUpdate);
                _lastUpdate = _now;
                game.DoDraw(_drawGameTime);
            }
            try
            {
                SwapBuffers();
            }
            catch (Exception ex)
            {
                Android.Util.Log.Error("Error in swap buffers", ex.ToString());
            }
        }
Ejemplo n.º 4
0
        void gameLoop_Update(TimeSpan time)
        {
            if (!playing)
            {
                return;
            }

            updateGameTime.Update(time);
            Update(updateGameTime);
        }
Ejemplo n.º 5
0
        protected override void OnUpdateFrame(FrameEventArgs e)
        {
            base.OnUpdateFrame(e);

            if (game != null)
            {
                _now = DateTime.Now;
                _updateGameTime.Update(_now - _lastUpdate);
                game.DoUpdate(_updateGameTime);
            }
        }
Ejemplo n.º 6
0
        private void OnUpdateFrame(object sender, FrameEventArgs e)
        {
            if (Game != null)
            {
                HandleInput();

                _now = DateTime.Now;
                _updateGameTime.Update(_now - _lastUpdate);
                Game.DoUpdate(_updateGameTime);
            }
        }
Ejemplo n.º 7
0
        private void OnUpdateFrame(object sender, FrameEventArgs e)
        {
            if (Game != null)
            {
                HandleInput();

                _now += TimeSpan.FromSeconds(e.Time);
                _updateGameTime.Update(_now - _lastUpdateTime);
                _lastUpdateTime = _now;
                Game.DoUpdate(_updateGameTime);
            }
        }
Ejemplo n.º 8
0
        protected override void OnUpdateFrame(FrameEventArgs e)
        {
            base.OnUpdateFrame(e);

            if (game != null)
            {
                //ObserveDeviceRotation();

                _now = DateTime.Now;
                _updateGameTime.Update(_now - _lastUpdate);
                game.DoUpdate(_updateGameTime);
            }
        }
Ejemplo n.º 9
0
        internal void DoStep()
        {
            var timeNow = DateTime.Now;

            // Update the game
            _updateGameTime.Update(timeNow - _lastUpdate);
            Update(_updateGameTime);

            // Draw the screen
            _drawGameTime.Update(timeNow - _lastUpdate);
            _lastUpdate = timeNow;
            Draw(_drawGameTime);
        }
Ejemplo n.º 10
0
        protected override void OnRenderFrame(FrameEventArgs e)
        {
            base.OnRenderFrame(e);

            // This code was commented to make the code base more iPhone like.
            // More speed testing is required, to see if this is worse or better
            // game.DoStep();

            if (game != null)
            {
                _drawGameTime.Update(_now - _lastUpdate);
                _lastUpdate = _now;
                game.DoDraw(_drawGameTime);
            }
        }
Ejemplo n.º 11
0
        private void OnRenderFrame(object sender, FrameEventArgs e)
        {
            if (GraphicsContext.CurrentContext == null || GraphicsContext.CurrentContext.IsDisposed)
            {
                return;
            }

            //Should not happen at all..
            if (!GraphicsContext.CurrentContext.IsCurrent)
            {
                window.MakeCurrent();
            }

            // we should wait until window's not fullscreen to resize
            if (updateClientBounds && window.WindowState == WindowState.Normal)
            {
                // it seems, at least on linux, we can't resize if we disallow user resizing
                // make next state the current state
                _transitiveAllowUserResizing = AllowUserResizing;
                // allow resize to resize window
                window.WindowBorder = WindowBorder.Resizable;

                window.ClientRectangle = new System.Drawing.Rectangle(clientBounds.X,
                                                                      clientBounds.Y, clientBounds.Width, clientBounds.Height);

                updateClientBounds = false;
            }
            else if (_transitiveAllowUserResizing != _allowUserResizing)
            {
                // reset previous value
                AllowUserResizing = _transitiveAllowUserResizing;
            }

            if (window.WindowState != windowState)
            {
                window.WindowState = windowState;
            }

            if (Game != null)
            {
                _drawGameTime.Update(_now - _lastUpdate);
                _lastUpdate = _now;
                Game.DoDraw(_drawGameTime);
            }

            window.SwapBuffers();
        }
        protected override void OnRenderFrame(FrameEventArgs e)
        {
            base.OnRenderFrame(e);

            if (GraphicsContext == null || GraphicsContext.IsDisposed)
            {
                return;
            }

            //Should not happen at all..
            if (!GraphicsContext.IsCurrent)
            {
                MakeCurrent();
            }

            if (game != null)
            {
                _drawGameTime.Update(_now - _lastUpdate);
                _lastUpdate = _now;
                game.DoDraw(_drawGameTime);
            }

            SwapBuffers();
        }
Ejemplo n.º 13
0
        protected override void OnUpdateFrame(FrameEventArgs e)
        {
/*            if(game.IsFixedTimeStep)
 *          {
 *              var elapsed = DateTime.Now - _lastUpdate;
 *              var remainder = (game.TargetElapsedTime - elapsed);
 *              if(remainder.TotalMilliseconds > 0)
 *              {
 *                  //PerformanceCounter.Event("Delay", (int)remainder.TotalMilliseconds);
 *                  Thread.Sleep(remainder);
 *                  //PerformanceCounter.Event("DelayDone", (int)remainder.TotalMilliseconds);
 *              }
 *          }
 */
            base.OnUpdateFrame(e);

            if (game != null)
            {
                _nowUpdate = DateTime.Now;
                _updateGameTime.Update(_nowUpdate - _lastUpdate);
                _lastUpdate = _nowUpdate;
                game.DoUpdate(_updateGameTime);
            }
        }
Ejemplo n.º 14
0
        protected override void OnRenderFrame(FrameEventArgs e)
        {
            PerformanceCounter.EndMensure("!OnRenderFrame");
            PerformanceCounter.BeginMensure("OnRenderFrame");

            if (inBackground)
            {
                return;
            }
            base.OnRenderFrame(e);

            MakeCurrent();

            // This code was commented to make the code base more iPhone like.
            // More speed testing is required, to see if this is worse or better
            // game.DoStep();
            if (game != null)
            {
                _nowDraw = DateTime.Now;
                //PerformanceCounter.Event ("Now", (int)_nowDraw.Millisecond);
                _drawGameTime.Update(_nowDraw - _lastDraw);
                _lastDraw = _nowDraw;
                game.DoDraw(_drawGameTime);
            }


            //PerformanceCounter.Event("SwapBuffers", true);
            PerformanceCounter.BeginMensure("SwapBuffers");

            if (game.IsFixedTimeStep)
            {
                var now       = DateTime.Now;
                var elapsed   = now - _lastSwap;
                var remainder = (game.TargetElapsedTime - elapsed);
                if (remainder.TotalMilliseconds > 0)
                {
                    _lastSwap = now + remainder; // don't measure when swap actually happened, count when it was supposed to
                                                 // allow for drift if frame is a bit too slow.
                    Thread.Sleep(remainder);
                }
                else
                {
                    _lastSwap = now;
                }
            }

            SwapBuffers();
            //PerformanceCounter.Event("EndSwap", true);


            PerformanceCounter.EndMensure("SwapBuffers");

            /*   var cc = GC.CollectionCount(0);
             * if(cc != lastCollectCount0)
             * {
             *     Console.WriteLine("Collect0!");
             *     lastCollectCount0 = cc;
             * }
             * cc = GC.CollectionCount(1);
             * if(cc != lastCollectCount1)
             * {
             *     Console.WriteLine("Collect1!");
             *     lastCollectCount1 = cc;
             * }
             * cc = GC.CollectionCount(2);
             * if(cc != lastCollectCount2)
             * {
             *     Console.WriteLine("Collect2!");
             *     lastCollectCount2 = cc;
             * }
             * cc = GC.CollectionCount(3);
             * if(cc != lastCollectCount3)
             * {
             *     Console.WriteLine("Collect3!");
             *     lastCollectCount3 = cc;
             * }*/

            PerformanceCounter.EndMensure("OnRenderFrame");
            PerformanceCounter.BeginMensure("!OnRenderFrame");
        }
Ejemplo n.º 15
0
 void DoUpdate(TimeSpan time)
 {
     updateGameTime.Update(time);
     game.Update(updateGameTime);
 }
Ejemplo n.º 16
0
 void gameLoop_Draw(TimeSpan time)
 {
     drawGameTime.Update(time);
     DoDraw(drawGameTime);
 }
Ejemplo n.º 17
0
        protected override void OnRenderFrame(FrameEventArgs e)
        {
            base.OnRenderFrame(e);

            // FIXME: Since Game.Exit may be called during an Update loop (and
            //        in fact that is quite likely to happen), this code is now
            //        littered with checks to _platform.IsRunning.  It would be
            //        nice if there weren't quite so many.  The move to a
            //        Game.Tick-centric architecture may eliminate this problem
            //        automatically.
            if (_game != null)
            {
                _now = DateTime.Now;
                if (_isFirstTime)
                {
                    // Initialize GameTime
                    _updateGameTime = new GameTime();
                    _drawGameTime   = new GameTime();
                    _lastUpdate     = DateTime.Now;
                    _isFirstTime    = false;
                }

                if (_needsToResetElapsedTime)
                {
                    _drawGameTime.ResetElapsedTime();
                    _needsToResetElapsedTime = false;
                }

                // Try to catch up with frames
                _drawGameTime.Update(_now - _lastUpdate);
                TimeSpan catchup = _drawGameTime.ElapsedGameTime;
                if (catchup > _game.TargetElapsedTime)
                {
                    while (catchup > _game.TargetElapsedTime)
                    {
                        //Console.WriteLine("Catching up " + (catchup - _game.TargetElapsedTime));
                        catchup -= _game.TargetElapsedTime;
                        _drawGameTime.ElapsedGameTime = _game.TargetElapsedTime;
                        if (_platform.IsRunning)
                        {
                            _game.DoUpdate(_drawGameTime);
                        }
                        _extraElapsedTime += catchup;
                    }
                    if (_extraElapsedTime > _game.TargetElapsedTime)
                    {
                        //Console.WriteLine("FastForward " + _extraElapsedTime);
                        if (_platform.IsRunning)
                        {
                            _game.DoUpdate(_drawGameTime);
                        }
                        _extraElapsedTime = TimeSpan.Zero;
                    }
                }
                else
                {
                    if (_platform.IsRunning)
                    {
                        _game.DoUpdate(_drawGameTime);
                    }
                }

                //Console.WriteLine("Render " + _drawGameTime.ElapsedGameTime);
//				_game.DoUpdate(_drawGameTime);
                if (_platform.IsRunning)
                {
                    _game.DoDraw(_drawGameTime);
                }
                _lastUpdate = _now;
            }
        }