Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- -----------------------------------------------------------------------------
- Filename: Main.h
- -----------------------------------------------------------------------------
- -----------------------------------------------------------------------------
- */
- // Declare Once
- #pragma once
- // Engine
- #include <R3D\R3D.hpp>
- // I am going to regret this (I'm stabbing myself as I type)
- using namespace R3D;
- // Class definition -------------------------------------------------------------------
- class Game
- {
- public:
- // Constructors
- Game() = default;
- Game(const Game& other) = delete;
- ~Game() = default;
- // Primary application functions
- bool Initialize();
- void Shutdown();
- void Run();
- private:
- // Private methods
- bool Frame();
- bool Render();
- // Modules
- Window mWindow;
- // Variables
- Double mFrameTime;
- };
- // Application initialization ---------------------------------------------------------
- bool Game::Initialize()
- {
- Window::Description windowDesc;
- bool result;
- // Initialize R3D
- R3D::Initialize();
- // Set the frame time
- mFrameTime = floor(1000 / 60); // 60 FPS target
- // Setup the window
- windowDesc.Width = 960;
- windowDesc.Height = 640;
- windowDesc.Flags.Format = Texture::Format::RGBA8UNorm;
- // Create a window and begin initialization
- result = mWindow.Create(windowDesc);
- if(!result) { return false; }
- // Load some resources
- // Setup the scene
- return true;
- }
- // Application runtime ----------------------------------------------------------------
- void Game::Run()
- {
- LARGE_INTEGER li;
- Double frequency;
- Double time;
- bool done;
- // Get the high-resolution timer frequency
- if(FAILED(QueryPerformanceFrequency(&li))) { return; }
- // Set the timer frequency to milliseconds
- frequency = (double)li.QuadPart / 1000.0;
- // Loop until the engine wants to quit
- done = false;
- while(!done)
- {
- // Reset the timer
- QueryPerformanceCounter(&li);
- time = li.QuadPart;
- // Do frame processing
- bool result = Frame();
- if(!result) { done = true; }
- // Get the elasped time
- QueryPerformanceCounter(&li);
- time = li.QuadPart - time;
- time /= frequency;
- // Sleep
- Sleep(max(mFrameTime - time, 0));
- }
- return;
- }
- // Application frame processing -------------------------------------------------------
- bool Game::Frame()
- {
- bool result;
- // Update the engine state
- result = R3D::Update();
- if(!result) { return false; }
- // Render the current frame
- // <insert a comment here>
- mWindow.Clear(0.1f, 0.1f, 0.1f, 1.0f);
- // Prepare the scene
- // Present our back buffer to our front buffer
- mWindow.Finish();
- return true;
- }
- // Application shutdown ---------------------------------------------------------------
- void Game::Shutdown()
- {
- // Shut down the engine
- R3D::Shutdown();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement