diff options
-rw-r--r-- | src/crepe/facade/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/crepe/facade/SDLApp.cpp | 71 | ||||
-rw-r--r-- | src/crepe/facade/SDLApp.h | 26 | ||||
-rw-r--r-- | src/example/physics.cpp | 1 |
4 files changed, 1 insertions, 99 deletions
diff --git a/src/crepe/facade/CMakeLists.txt b/src/crepe/facade/CMakeLists.txt index dbddcc6..c79e16f 100644 --- a/src/crepe/facade/CMakeLists.txt +++ b/src/crepe/facade/CMakeLists.txt @@ -1,7 +1,6 @@ target_sources(crepe PUBLIC Sound.cpp SoundContext.cpp - SDLApp.cpp SDLContext.cpp ) @@ -9,6 +8,5 @@ target_sources(crepe PUBLIC FILE_SET HEADERS FILES Sound.h SoundContext.h SDLContext.h - SDLContext.h ) diff --git a/src/crepe/facade/SDLApp.cpp b/src/crepe/facade/SDLApp.cpp deleted file mode 100644 index c6ddeaa..0000000 --- a/src/crepe/facade/SDLApp.cpp +++ /dev/null @@ -1,71 +0,0 @@ -#include <iostream> - -#include "SDLApp.h" - -SDLApp::SDLApp(int window_width, int window_height) - : window_width(window_width), window_height(window_height), window(nullptr), - renderer(nullptr) {} - -// FIXME: why is there clean_up and ~SDLApp? -SDLApp::~SDLApp() { clean_up(); } - -bool SDLApp::initialize() { - if (SDL_Init(SDL_INIT_VIDEO) != 0) { - // FIXME: throw exception - std::cerr << "SDL Initialization Error: " << SDL_GetError() - << std::endl; - return false; - } - - window = SDL_CreateWindow("Particle System", SDL_WINDOWPOS_CENTERED, - SDL_WINDOWPOS_CENTERED, window_width, - window_height, SDL_WINDOW_SHOWN); - if (!window) { - // FIXME: throw exception - std::cerr << "Window Creation Error: " << SDL_GetError() << std::endl; - return false; - } - - renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED); - if (!renderer) { - // FIXME: throw exception - std::cerr << "Renderer Creation Error: " << SDL_GetError() << std::endl; - return false; - } - - return true; -} - -void SDLApp::handle_events(bool & running) { - SDL_Event event; - while (SDL_PollEvent(&event)) { - if (event.type == SDL_QUIT) { - running = false; - } - } -} - -void SDLApp::clear_screen() { - SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255); - SDL_RenderClear(renderer); -} - -void SDLApp::present_screen() { SDL_RenderPresent(renderer); } - -void SDLApp::draw_square(int x, int y, int size) { - SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255); - SDL_Rect rect = {x, y, size, size}; - SDL_RenderFillRect(renderer, &rect); -} - -SDL_Texture * square_texture = nullptr; // Load this with an image or create it - -void SDLApp::clean_up() { - if (renderer) { - SDL_DestroyRenderer(renderer); - } - if (window) { - SDL_DestroyWindow(window); - } - SDL_Quit(); -} diff --git a/src/crepe/facade/SDLApp.h b/src/crepe/facade/SDLApp.h deleted file mode 100644 index 6d8f3f4..0000000 --- a/src/crepe/facade/SDLApp.h +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once - -#include <SDL2/SDL.h> - -#include "../api/ParticleEmitter.h" - -class SDLApp { -public: - SDLApp(int window_width, int window_height); - ~SDLApp(); - - bool initialize(); - void handle_events(bool & running); - void clear_screen(); - void present_screen(); - void draw_square(int x, int y, int size); - void clean_up(); - void draw_particles(const std::vector<crepe::ParticleEmitter> & emitters); - void draw_multiple_squares(const std::vector<SDL_Rect> & squares); - -private: - int window_width; - int window_height; - SDL_Window * window; - SDL_Renderer * renderer; -}; diff --git a/src/example/physics.cpp b/src/example/physics.cpp index fd15c79..9a5e5f9 100644 --- a/src/example/physics.cpp +++ b/src/example/physics.cpp @@ -19,5 +19,6 @@ int main(int argc, char * argv[]) { .use_gravity = true, .bounce = false, }); + delete game_object; return 0; } |