Exemplo n.º 1
0
        protected override void OnUpdate(UpdateEventArgs e)
        {
            if(this.Focused)
                InputManager.Update();

            this.game.Update(e);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="UpdateEventArgs"/> class.
        /// </summary>
        /// <param name="lastFrame">The <see cref="UpdateEventArgs"/> instance of the last frame.</param>
        /// <param name="currentTimeInSeconds">The current time.</param>
        public UpdateEventArgs(UpdateEventArgs lastFrame, double currentTimeInSeconds)
        {
            this.Frame = lastFrame.Frame + 1;
            this.ElapsedTimeInS = currentTimeInSeconds - lastFrame.TimeInS;
            this.ElapsedTimeInSf = (float)this.ElapsedTimeInS;

            this.TimeInS = currentTimeInSeconds;
        }
Exemplo n.º 3
0
        protected override void OnRender(UpdateEventArgs e)
        {
            this.renderer.PrepareFrame(this.Width, this.Height);

            this.renderer.Draw(this.game);
            this.renderer.FinaliseFrame();

            this.SwapBuffers();
        }
Exemplo n.º 4
0
        public void Update(UpdateEventArgs args)
        {
            var elapsedTime = new TimeSpan(args.ElapsedTimeInS);

            this.time += elapsedTime;

            foreach (var gameObject in this.gameObjects)
            {
                gameObject.Update(elapsedTime);
            }
        }
Exemplo n.º 5
0
        protected override void OnRender(UpdateEventArgs e)
        {
            this.renderer.PrepareFrame(this.Width, this.Height);

            this.renderer.Draw(this.game);
            this.renderer.FinaliseFrame();

            if (InputManager.IsKeyHit(Key.P))
            {
                this.SaveScreenshot(Settings.Screenshot.Path, Settings.Screenshot.NameBase, false);
            }

            this.SwapBuffers();
        }
 public void Update(UpdateEventArgs e)
 {
     switch (this.status)
     {
         case Status.Hosting:
             this.Stopped(new Server.LobbyGameHandler(this.gameWindow, this.form.PlayerName));
             this.gameWindow.UIActionQueue.RunAndForget(this.form.Close);
             break;
         case Status.Connecting:
             this.Stopped(new Client.ConnectingGameHandler(this.gameWindow, this.form.PlayerName, this.form.IpAddress));
             this.gameWindow.UIActionQueue.RunAndForget(this.form.Close);
             break;
     }
 }
        public void Update(UpdateEventArgs e)
        {
            if (this.form == null)
                return;
            if (this.server == null)
            {
                this.startServer();
            }

            if (this.status != LobbyStatus.Waiting)
            {
                switch (status)
                {
                    case LobbyStatus.Starting:
                        this.startGame();
                        break;
                    default:
                        throw new ArgumentOutOfRangeException();
                }
                return;
            }

            NetIncomingMessage message;
            while ((message = this.server.ReadMessage()) != null)
            {
                switch (message.MessageType)
                {
                    case NetIncomingMessageType.ConnectionApproval:
                    {
                        this.tryApproveClient(message);
                        break;
                    }
                    case NetIncomingMessageType.StatusChanged:
                    {
                        this.onClientStatusChanged(message);
                        break;
                    }
                    default:
                    {
                        Log.Line("unhandled message with type: " + message.MessageType);
                        if (message.MessageType == NetIncomingMessageType.DebugMessage)
                            Log.Debug(message.ReadString());
                        break;
                    }
                }
            }
        }
Exemplo n.º 8
0
        protected override void OnRender(UpdateEventArgs e)
        {
            this.glQueue.ExecuteFor(TimeSpan.FromMilliseconds(5));
            if (this.resized)
            {
                GL.Viewport(0, 0, this.Width, this.Height);
                this.renderer.Resize(this.Width, this.Height);
                this.resized = false;
            }

            this.renderer.PrepareFrame();

            this.game.Render(this.renderer);

            this.renderer.FinaliseFrame();

            this.SwapBuffers();
        }
 public void Update(UpdateEventArgs e)
 {
     NetIncomingMessage message;
     while ((message = this.client.ReadMessage()) != null)
     {
         switch (message.MessageType)
         {
             case NetIncomingMessageType.StatusChanged:
             {
                 this.onStatusChanged();
                 return; // if status changed we are either connected or disconnected
             }
             default:
             {
                 Log.Line("unhandled message with type: " + message.MessageType);
                 if(message.MessageType == NetIncomingMessageType.DebugMessage)
                     Log.Debug(message.ReadString());
                 break;
             }
         }
         Log.Line("");
     }
 }
        protected override void OnUpdate(UpdateEventArgs e)
        {
            if (this.Focused)
            {
                InputManager.Update();

            }

            float t = e.ElapsedTimeInSf;

            if (InputManager.IsKeyPressed(Key.Number2))
                t *= 0.1f;

            foreach (var layer in this.layers)
            {
                //layer.Update(t);
            }
        }
Exemplo n.º 11
0
        public void Update(UpdateEventArgs args)
        {
            var elapsedTime = args.ElapsedTimeInS;

            if (InputManager.IsKeyPressed(Key.Space))
                elapsedTime *= 3;

            this.time += elapsedTime;
            this.timeF = (float)this.time;

            var elapsedTimeF = (float)elapsedTime;

            foreach (var gameObject in this.gameObjects)
            {
                gameObject.Update(elapsedTimeF);
            }
        }
Exemplo n.º 12
0
 protected virtual void OnRender(UpdateEventArgs e) { }
Exemplo n.º 13
0
 protected virtual void OnRender(UpdateEventArgs e)
 {
 }
Exemplo n.º 14
0
 protected virtual void OnUpdate(UpdateEventArgs e)
 {
 }
Exemplo n.º 15
0
        private void run(double targetUpdatesPerSecond, double targetDrawsPerSecond, double maximumFrameTimeFactor = 3, bool dontOverrideFps = false)
        {
            this.Context.MakeCurrent(this.WindowInfo);

            double prevUpdateInterval = this.targetUpdateInterval;

            this.targetUpdateInterval = targetUpdatesPerSecond <= 0 ? 0 : 1 / targetUpdatesPerSecond;
            double targetRenderInterval = targetDrawsPerSecond <= 0 ? 0 : 1 / targetDrawsPerSecond;

            double maximumUpdateInterval = this.targetUpdateInterval == 0
                ? double.PositiveInfinity
                : this.targetUpdateInterval * maximumFrameTimeFactor;

            if (dontOverrideFps)
            {
                this.targetUpdateInterval = prevUpdateInterval;
            }

            UpdateEventArgs updateEventArgs = new UpdateEventArgs(0);

            double lastTimerTime = 0;

            double gameSeconds = 0;

            double nextTargetRenderTime = 0;

            var gameTimer = Stopwatch.StartNew();


            // main loop
            while (true)
            {
                double thisTimerTime  = gameTimer.Elapsed.TotalSeconds;
                double elapsedSeconds = thisTimerTime - lastTimerTime;
                lastTimerTime = thisTimerTime;

                double updateSeconds = Math.Min(elapsedSeconds, maximumUpdateInterval);

                gameSeconds += updateSeconds;


                //this.ProcessEvents();
                if (this.Exists && !this.IsExiting)
                {
                    // update
                    updateEventArgs = new UpdateEventArgs(updateEventArgs, gameSeconds);

                    this.OnUpdate(updateEventArgs);

                    if (thisTimerTime >= nextTargetRenderTime)
                    {
                        // render
                        this.OnRender(updateEventArgs);
                        nextTargetRenderTime = thisTimerTime + targetRenderInterval;
                    }
                }
                else
                {
                    return;
                }

                if (!this.vsync)
                {
                    double timeAfterFrame = gameTimer.Elapsed.TotalSeconds;

                    double frameTime = timeAfterFrame - thisTimerTime;
                    double waitTime  = this.targetUpdateInterval - frameTime;
                    if (waitTime > 0)
                    {
                        Thread.Sleep((int)(waitTime * 1000));
                    }
                }
            }
        }
Exemplo n.º 16
0
        private void run(double targetUpdatesPerSecond, double targetDrawsPerSecond, double maximumFrameTimeFactor = 3, bool dontOverrideFps = false)
        {
            this.Context.MakeCurrent(this.WindowInfo);

            double prevUpdateInterval = this.targetUpdateInterval;

            this.targetUpdateInterval = targetUpdatesPerSecond <= 0 ? 0 : 1 / targetUpdatesPerSecond;
            double targetRenderInterval = targetDrawsPerSecond <= 0 ? 0 : 1 / targetDrawsPerSecond;

            double maximumUpdateInterval = this.targetUpdateInterval == 0
                ? double.PositiveInfinity
                : this.targetUpdateInterval * maximumFrameTimeFactor;

            if (dontOverrideFps)
                this.targetUpdateInterval = prevUpdateInterval;

            UpdateEventArgs updateEventArgs = new UpdateEventArgs(0);

            double lastTimerTime = 0;

            double gameSeconds = 0;

            double nextTargetRenderTime = 0;

            var gameTimer = Stopwatch.StartNew();


            // main loop
            while (true)
            {
                double thisTimerTime = gameTimer.Elapsed.TotalSeconds;
                double elapsedSeconds = thisTimerTime - lastTimerTime;
                lastTimerTime = thisTimerTime;

                double updateSeconds = Math.Min(elapsedSeconds, maximumUpdateInterval);

                gameSeconds += updateSeconds;


                //this.ProcessEvents();
                if (this.Exists && !this.IsExiting)
                {
                    // update
                    updateEventArgs = new UpdateEventArgs(updateEventArgs, gameSeconds);

                    this.OnUpdate(updateEventArgs);

                    if (thisTimerTime >= nextTargetRenderTime)
                    {
                        // render
                        this.OnRender(updateEventArgs);
                        nextTargetRenderTime = thisTimerTime + targetRenderInterval;
                    }
                }
                else
                    return;

                if (!this.vsync)
                {
                    double timeAfterFrame = gameTimer.Elapsed.TotalSeconds;

                    double frameTime = timeAfterFrame - thisTimerTime;
                    double waitTime = this.targetUpdateInterval - frameTime;
                    if (waitTime > 0)
                        Thread.Sleep((int)(waitTime * 1000));
                }
            }
        }
Exemplo n.º 17
0
 protected virtual void OnUpdate(UpdateEventArgs e) { }
Exemplo n.º 18
0
 protected override void OnUpdate(UpdateEventArgs e)
 {
     this.game.Update(e);
 }
Exemplo n.º 19
0
 public void Update(UpdateEventArgs e)
 {
     this.gameHandler.Update(e);
 }
        protected override void OnRender(UpdateEventArgs e)
        {
            // resize viewport if needed
            if (this.Height != this.glHeight || this.Width != this.glWidth)
            {
                this.glHeight = this.Height;
                this.glWidth = this.Width;
                GL.Viewport(0, 0, this.glWidth, this.glHeight);

                this.renderTexture.Resize(this.glWidth, this.glHeight);
            }

            GL.BindFramebuffer(FramebufferTarget.DrawFramebuffer, this.renderTarget);

            GL.CullFace(CullFaceMode.FrontAndBack);
            GL.ClearColor(Color.GrayScale(200));
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            SurfaceBlendSetting.PremultipliedAlpha.Set(null);

            foreach (var layer in layers)
            {
                layer.Draw();
            }

            GL.BindFramebuffer(FramebufferTarget.DrawFramebuffer, 0);

            this.copyToScreen.Render();

            if (InputManager.IsKeyPressed(Key.Number1))
            {
                this.raySurface.Clear();
            }
            else
            {
                this.raySurface.Render();
            }

            this.SwapBuffers();
        }