public void OnFrame(FrameMessage msg)
        {
            // Get target fps in frametime
            float frametime = 1.0f / TargetFPS;

            // Find delta time
            float tosleep = frametime - msg.DeltaTime;
            if (tosleep > 0.0f) Thread.Sleep((int)(tosleep * 1000.0f));
        }
        public void OnFrame(FrameMessage msg)
        {
            // Determine the rotation
            Quaternion rotation = Quaternion.RotationAxis(Axis, msg.DeltaTime * Speed);

            // Apply
            Transform transform = Owner.GetComponent<Transform>();
            transform.LocalRotation = transform.LocalRotation * rotation;
        }
        /// <summary>
        /// Entry point for the application
        /// </summary>
        /// <param name="args"></param>
        public static void Main(string[] args)
        {
            // Create the message pool
            MessagePool pool = new MessagePool();

            // Create the root actor
            Actor root = new Actor(pool);

            // Attach core systems
            root.AddComponent<UserInputHandler>();
            root.AddComponent<Renderer>();
            root.AddComponent<MaterialSystem>();
            root.AddComponent<SceneManager>();
            root.AddComponent<SceneLoader>();
            root.AddComponent<Sleeper>().TargetFPS = 60.0f;

            // Attach exit listener
            bool exit = false;
            Listener<ExitMessage> exitlistener = root.AddComponent<Listener<ExitMessage>>() as Listener<ExitMessage>;
            exitlistener.OnMessageReceived += (msg) => exit = true;

            // Initialise
            root.Init();

            // Send the initialise message
            InitialiseMessage initmsg = new InitialiseMessage();
            pool.SendMessage(initmsg);

            // Load the scene
            if (!root.GetComponent<SceneLoader>().LoadSceneFromFile("scene.json"))
            {
                Console.WriteLine("Failed to load scene!");
                Console.ReadKey();
                return;
            }

            // Setup the frame message
            FrameMessage framemsg = new FrameMessage();
            framemsg.FrameNumber = 0;
            framemsg.DeltaTime = 0.0f;

            // Setup the timer
            Stopwatch frametimer = new Stopwatch();

            // Loop until done
            while (!exit)
            {
                // Send frame message
                frametimer.Start();
                pool.SendMessage(framemsg);
                frametimer.Stop();
                framemsg.DeltaTime = (float)frametimer.Elapsed.TotalSeconds;
                frametimer.Reset();

                // Increase frame number
                framemsg.FrameNumber++;

                // Process windows events
                Application.DoEvents();
            }

            // Send the shutdown message
            ShutdownMessage shutdownmsg = new ShutdownMessage();
            pool.SendMessage(shutdownmsg);

            // Delete root actor and clean up
            root.Destroy(true);
        }
        public void OnFrame(FrameMessage msg)
        {
            // Clear the backbuffer
            BindBackbuffer();
            context.ClearRenderTargetView(rtBackbuffer, ClearColour);
            context.ClearDepthStencilView(vwDepthBuffer, DepthStencilClearFlags.Depth, 1.0f, 0);

            // Reset counters
            frame_drawcalls = 0;
            frame_materialswitches = 0;
            frame_shaderswitches = 0;

            // Send update message
            updatemsg.DeltaTime = msg.DeltaTime;
            updatemsg.FrameNumber = msg.FrameNumber;
            Owner.MessagePool.SendMessage(updatemsg);

            // Send render message
            Owner.MessagePool.SendMessage(rendermsg);

            // Update console title
            Console.Title = string.Format("drawcalls: {0}, matswitches: {1}, shaderswitches: {2}", frame_drawcalls, frame_materialswitches, frame_shaderswitches);

            // Present
            swapchain.Present(0, PresentFlags.None);
        }