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;
- //Scene mScene;
- //Scene::Node mNode;
- // Structures
- struct WindowBuffer { Float4x4 ViewProjectionMatrix; };
- struct NodeBuffer { Float4x3 WorldMatrix; };
- struct InstanceBuffer { Float4x3 InstanceMatrix; };
- //Buffer WindowBuffer;
- // Objects
- Camera mCamera;
- // Variables
- Double mFrameTime;
- };
- // DEBUG / TEMPORARY
- #define isAligned(POINTER, BYTE_COUNT) (((uintptr_t)(const void *)(POINTER)) % (BYTE_COUNT) == 0)
- #define Aligned __declspec(align(16))
- // 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
- //mScene.Initialize();
- //mNode = mScene.CreateNode();
- //mCamera.Translate(0.0f, -64.0, 0.0f);
- //mCamera.LookAt(0.0f, 0.0f, 0.0f);
- // DEBUG
- //Log::Singleton->Write("Sizeof(Float2) = " + string(sizeof(Float2)) + ".");
- //Log::Singleton->Write("Sizeof(Float2A) = " + string(sizeof(Float2A)) + ".");
- //Log::Singleton->Write("Sizeof(Float3) = " + string(sizeof(Float3)) + ".");
- //Log::Singleton->Write("Sizeof(Float3A) = " + string(sizeof(Float3A)) + ".");
- Movable unaligned;
- Log::Singleton->Write("Sizeof(Movable) = " + string(sizeof(unaligned)) + ".");
- Log::Singleton->Write("isAligned(Movable) = " + string(isAligned(&unaligned, 16)) + ".");
- Log::Singleton->Write("Sizeof(Forward) = " + string(sizeof(unaligned.Forward)) + ".");
- Log::Singleton->Write("isAligned(Forward) = " + string(isAligned(&unaligned.Forward, 16)) + ".");
- Log::Singleton->Write("Sizeof(Right) = " + string(sizeof(unaligned.Right)) + ".");
- Log::Singleton->Write("isAligned(Right) = " + string(isAligned(&unaligned.Right, 16)) + ".");
- Log::Singleton->Write("Sizeof(Up) = " + string(sizeof(unaligned.Up)) + ".");
- Log::Singleton->Write("isAligned(Up) = " + string(isAligned(&unaligned.Up, 16)) + ".");
- Log::Singleton->Write("Sizeof(Position) = " + string(sizeof(unaligned.Position)) + ".");
- Log::Singleton->Write("isAligned(Position) = " + string(isAligned(&unaligned.Position, 16)) + ".");
- 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 our time
- static float t = 0.0f;
- static ULONGLONG timeStart = 0;
- ULONGLONG timeCur = GetTickCount64();
- if(timeStart == 0) { timeStart = timeCur; }
- t = (timeCur - timeStart) / 1000.0f;
- // 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
- Matrix worldMatrix, viewMatrix, projectionMatrix;
- //worldMatrix = Math::RotationZ(-t);
- //viewMatrix = mCamera.Transform();
- projectionMatrix = mWindow.ProjectionMatrix;
- // 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