diff --git a/src/core/application.cpp b/src/core/canvas_engine.cpp similarity index 71% rename from src/core/application.cpp rename to src/core/canvas_engine.cpp index 1e883d4..4867931 100644 --- a/src/core/application.cpp +++ b/src/core/canvas_engine.cpp @@ -1,13 +1,17 @@ -#include "application.hpp" -#include +#include "canvas_engine.hpp" #include +#include +#include +#include #include + #ifndef PROJECTNAME #define PROJECTNAME "Pass define for PROJECTNAME to change title" #endif -Application::Application() { +namespace ce { +CanvasEngine::CanvasEngine() { if(SDL_Init(SDL_INIT_EVERYTHING) != 0) { SDL_LogError(SDL_LOG_CATEGORY_ERROR, "Failed to initialize SDL, SDL error: %s", SDL_GetError()); return; @@ -28,13 +32,13 @@ Application::Application() { this->stay_open = true; } -Application::~Application() { +CanvasEngine::~CanvasEngine() { SDL_DestroyRenderer(this->render); SDL_DestroyWindow(this->window); SDL_Quit(); } -void Application::run() { +void CanvasEngine::run() { // start tracking time std::timespec_get(&this->startup_ts, TIME_UTC); this->frame_start_ts = this->last_frame_start_ts = this->startup_ts; @@ -55,23 +59,38 @@ void Application::run() { } } -void Application::request_close() { +void CanvasEngine::request_close() { this->stay_open = false; } -void Application::set_target_delta_time(double target) { +void CanvasEngine::set_target_delta_time(double target) { this->target_delta_time = target; } -void Application::process_events() { +void CanvasEngine::process_events() { SDL_Event evt{}; - while(SDL_PollEvent(&evt)) { - switch(evt.type) { - case SDL_QUIT: - this->request_close(); - break; - default:break; - } + while(SDL_PollEvent(&evt)) this->process_event(evt); +} +void CanvasEngine::process_event(SDL_Event const &evt) { + switch(evt.type) { + case SDL_QUIT: + this->request_close(); + break; + case SDL_KEYDOWN: + break; + case SDL_KEYUP: + break; + default: + break; } } + +void CanvasEngine::tick(double delta_time) { +} + +void CanvasEngine::draw(SDL_Renderer *render) { + SDL_SetRenderDrawColor(this->render, 0, 0, 0, 255); + SDL_RenderClear(render); +} +} diff --git a/src/core/application.hpp b/src/core/canvas_engine.hpp similarity index 70% rename from src/core/application.hpp rename to src/core/canvas_engine.hpp index 09497f8..be57de6 100644 --- a/src/core/application.hpp +++ b/src/core/canvas_engine.hpp @@ -1,33 +1,35 @@ -#ifndef CORE_APPLICATION_HPP -#define CORE_APPLICATION_HPP +#ifndef CANVAS_ENGINE_HPP +#define CANVAS_ENGINE_HPP -#include #include #include #include +#include -class Application { -public: Application(); - virtual ~Application(); - void run(); - virtual void process_event(SDL_Event const &event) = 0; - virtual void tick(double delta_time) = 0; - virtual void draw(SDL_Renderer *render) = 0; - - void request_close(); - void set_target_delta_time(double target); +namespace ce { +class CanvasEngine { private: - void process_events(); -protected: SDL_Window *window{nullptr}; //!< primary application window SDL_Renderer *render{nullptr}; //!< primary application window's renderer -private: std::timespec startup_ts{}; //!< time in UTC at start of application (when run() was called) std::timespec last_frame_start_ts{}; //!< time at start of last frame std::timespec frame_start_ts{}; //!< time at start of this frame double delta_time{0.f}; double target_delta_time{}; bool stay_open{false}; //!< application loop will continue so long as this is true -}; +public: + CanvasEngine(); + ~CanvasEngine(); -#endif // !CORE_APPLICATION_HPP + void run(); + void request_close(); + void set_target_delta_time(double target); +private: + void process_events(); + void process_event(SDL_Event const &evt); + void tick(double delta_time); + void draw(SDL_Renderer *render); +}; +} + +#endif // !CANVAS_ENGINE_HPP diff --git a/src/game.cpp b/src/game.cpp deleted file mode 100644 index e400448..0000000 --- a/src/game.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "game.hpp" - -void Game::process_event(SDL_Event const &evt) { -} - -void Game::tick(double delta_time) { -} - -void Game::draw(SDL_Renderer *render) { - SDL_SetRenderDrawColor(this->render, 0, 0, 0, 255); - SDL_RenderClear(render); -} diff --git a/src/game.hpp b/src/game.hpp deleted file mode 100644 index 928ad96..0000000 --- a/src/game.hpp +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef GAME_HPP -#define GAME_HPP - -#include "core/application.hpp" - -class Game : public Application { -public: - virtual void process_event(SDL_Event const &evt) override; - virtual void tick(double delta_time) override; - virtual void draw(SDL_Renderer *render) override; -}; - -#endif // !GAME_HPP diff --git a/src/main.cpp b/src/main.cpp index fefb240..e99a819 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,6 @@ -#include "game.hpp" +#include "core/canvas_engine.hpp" int main(int argc, char* argv[]) { - Game game{}; - game.run(); + ce::CanvasEngine engine{}; + engine.run(); }