diff --git a/crumpet-engine/Game.cpp b/crumpet-engine/Game.cpp index 9c23fad..7a3d9bf 100644 --- a/crumpet-engine/Game.cpp +++ b/crumpet-engine/Game.cpp @@ -1,8 +1,11 @@ #include "game.h" -Game::Game(std::string title, int width, int height) +Game::Game(std::string title, int width, int height, int targetFramerate, int targetUpdaterate) : m_display(title, width, height) { + this->targetFramerate = targetFramerate; + this->targetUpdaterate = targetUpdaterate; + std::cout << "Engine initialized" << std::endl; } @@ -18,8 +21,16 @@ bool Game::IsDisplayClosed() { return m_display.IsClosed(); } -Display Game::GetDisplay() { +Renderer Game::GetDisplay() { return m_display; } -Game::~Game() {} +void Game::PollEvents() { + while (SDL_PollEvent(&m_event) != 0) + if (m_event.type == SDL_QUIT) + this->CloseDisplay(); +} + +Game::~Game() { + +} diff --git a/crumpet-engine/crumpet-engine.vcxproj b/crumpet-engine/crumpet-engine.vcxproj index f1a1530..4cee162 100644 --- a/crumpet-engine/crumpet-engine.vcxproj +++ b/crumpet-engine/crumpet-engine.vcxproj @@ -125,14 +125,14 @@ - + - + diff --git a/crumpet-engine/crumpet-engine.vcxproj.filters b/crumpet-engine/crumpet-engine.vcxproj.filters index c88409b..f980d56 100644 --- a/crumpet-engine/crumpet-engine.vcxproj.filters +++ b/crumpet-engine/crumpet-engine.vcxproj.filters @@ -2,8 +2,8 @@ - + @@ -12,10 +12,10 @@ - + headers - + headers diff --git a/crumpet-engine/display.cpp b/crumpet-engine/display.cpp deleted file mode 100644 index 7567d6d..0000000 --- a/crumpet-engine/display.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include "display.h" - -Display::Display(std::string title, int width, int height) { - if (SDL_Init(SDL_INIT_EVERYTHING) < 0) { - std::cout << "SDL could not initialize, SDL ERROR: " << SDL_GetError() << std::endl; - } - - m_window = SDL_CreateWindow(title.c_str(), SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_SHOWN); - m_renderer = SDL_CreateRenderer(m_window, -1, SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED); - SDL_SetRenderDrawColor(m_renderer, 123, 122, 0, 255); - - isClosed = false; -} - -void Display::Update() { - -} - -bool Display::IsClosed() { - return isClosed; -} - -void Display::Close() { - isClosed = true; -} - -Display::~Display() { - isClosed = true; - SDL_DestroyWindow(m_window); - SDL_Quit(); -} diff --git a/crumpet-engine/display.h b/crumpet-engine/display.h deleted file mode 100644 index 8e81991..0000000 --- a/crumpet-engine/display.h +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once - -#include -#include -#include - -class Display { -public: - Display(std::string title, int width, int height); - - void Update(); - - bool IsClosed(); - void Close(); - virtual ~Display(); -private: - SDL_Window *m_window; - SDL_Renderer *m_renderer; - - bool isClosed; -}; - diff --git a/crumpet-engine/game.h b/crumpet-engine/game.h index 9f11676..05dd1f2 100644 --- a/crumpet-engine/game.h +++ b/crumpet-engine/game.h @@ -1,19 +1,29 @@ #pragma once #include -#include "display.h" +#include "renderer.h" +#include "entity.h" class Game { public: - Game(std::string title, int width, int height); + Game(std::string title, int width, int height, int targetFramerate, int targetUpdaterate); void UpdateDisplay(); void CloseDisplay(); bool IsDisplayClosed(); - Display GetDisplay(); + Renderer GetDisplay(); + + void PollEvents(); virtual ~Game(); private: - Display m_display; + int targetFramerate; // If 0, the engine will try as many as possibe, if 1, it will use vsync + int targetUpdaterate; // If 0, the engine will try as many as possible + + int framerate; // Current framerate + int updaterate; // Current updaterate + + Renderer m_display; + SDL_Event m_event; }; diff --git a/crumpet-engine/main.cpp b/crumpet-engine/main.cpp index 60be6f3..c67caca 100644 --- a/crumpet-engine/main.cpp +++ b/crumpet-engine/main.cpp @@ -2,18 +2,17 @@ #undef main -#define SCREEN_WIDTH 640 -#define SCREEN_HEIGHT 480 +#define SCREEN_WIDTH 800 +#define SCREEN_HEIGHT 600 int main(int argc, char** argv) { - Game game("Crumpet engine", SCREEN_WIDTH, SCREEN_HEIGHT); + Game game("Crumpet engine", SCREEN_WIDTH, SCREEN_HEIGHT, 0, 60); + + - SDL_Event e; while (!game.IsDisplayClosed()) { - - while (SDL_PollEvent(&e) != 0) - if (e.type == SDL_QUIT) - game.CloseDisplay(); + game.PollEvents(); + game.UpdateDisplay(); }