diff options
Diffstat (limited to 'src/crepe/facade')
-rw-r--r-- | src/crepe/facade/DB.cpp | 3 | ||||
-rw-r--r-- | src/crepe/facade/DB.h | 4 | ||||
-rw-r--r-- | src/crepe/facade/SDLContext.cpp | 63 | ||||
-rw-r--r-- | src/crepe/facade/SDLContext.h | 20 | ||||
-rw-r--r-- | src/crepe/facade/Sound.h | 21 |
5 files changed, 45 insertions, 66 deletions
diff --git a/src/crepe/facade/DB.cpp b/src/crepe/facade/DB.cpp index 322ecc0..00acf04 100644 --- a/src/crepe/facade/DB.cpp +++ b/src/crepe/facade/DB.cpp @@ -18,8 +18,7 @@ DB::DB(const string & path) { this->db = {db, [](libdb::DB * db) { db->close(db, 0); }}; // load or create database file - ret = this->db->open(this->db.get(), NULL, path.c_str(), NULL, - libdb::DB_BTREE, DB_CREATE, 0); + ret = this->db->open(this->db.get(), NULL, path.c_str(), NULL, libdb::DB_BTREE, DB_CREATE, 0); if (ret != 0) throw runtime_error(format("db->open: {}", libdb::db_strerror(ret))); // create cursor diff --git a/src/crepe/facade/DB.h b/src/crepe/facade/DB.h index 2112216..629b0eb 100644 --- a/src/crepe/facade/DB.h +++ b/src/crepe/facade/DB.h @@ -15,8 +15,8 @@ namespace crepe { /** * \brief Berkeley DB facade * - * Berkeley DB is a simple key-value database that stores arbitrary data as - * both key and value. This facade uses STL strings as keys/values. + * Berkeley DB is a simple key-value database that stores arbitrary data as both key and value. + * This facade uses STL strings as keys/values. */ class DB { public: diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp index 65ea962..83e91f8 100644 --- a/src/crepe/facade/SDLContext.cpp +++ b/src/crepe/facade/SDLContext.cpp @@ -32,41 +32,37 @@ SDLContext::SDLContext() { if (SDL_Init(SDL_INIT_VIDEO) < 0) { // FIXME: throw exception - std::cerr << "SDL could not initialize! SDL_Error: " << SDL_GetError() - << std::endl; + std::cerr << "SDL could not initialize! SDL_Error: " << SDL_GetError() << std::endl; return; } - SDL_Window * tmp_window = SDL_CreateWindow( - "Crepe Game Engine", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, - this->viewport.w, this->viewport.h, 0); + SDL_Window * tmp_window + = SDL_CreateWindow("Crepe Game Engine", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, + this->viewport.w, this->viewport.h, 0); if (!tmp_window) { // FIXME: throw exception - std::cerr << "Window could not be created! SDL_Error: " - << SDL_GetError() << std::endl; + std::cerr << "Window could not be created! SDL_Error: " << SDL_GetError() << std::endl; return; } - this->game_window - = {tmp_window, [](SDL_Window * window) { SDL_DestroyWindow(window); }}; + this->game_window = {tmp_window, [](SDL_Window * window) { SDL_DestroyWindow(window); }}; - SDL_Renderer * tmp_renderer = SDL_CreateRenderer( - this->game_window.get(), -1, SDL_RENDERER_ACCELERATED); + SDL_Renderer * tmp_renderer + = SDL_CreateRenderer(this->game_window.get(), -1, SDL_RENDERER_ACCELERATED); if (!tmp_renderer) { // FIXME: throw exception - std::cerr << "Renderer could not be created! SDL_Error: " - << SDL_GetError() << std::endl; + std::cerr << "Renderer could not be created! SDL_Error: " << SDL_GetError() + << std::endl; SDL_DestroyWindow(this->game_window.get()); return; } - this->game_renderer = {tmp_renderer, [](SDL_Renderer * renderer) { - SDL_DestroyRenderer(renderer); - }}; + this->game_renderer + = {tmp_renderer, [](SDL_Renderer * renderer) { SDL_DestroyRenderer(renderer); }}; int img_flags = IMG_INIT_PNG; if (!(IMG_Init(img_flags) & img_flags)) { // FIXME: throw exception - std::cout << "SDL_image could not initialize! SDL_image Error: " - << IMG_GetError() << std::endl; + std::cout << "SDL_image could not initialize! SDL_image Error: " << IMG_GetError() + << std::endl; } } @@ -105,12 +101,9 @@ void SDLContext::handle_events(bool & running) { } void SDLContext::clear_screen() { SDL_RenderClear(this->game_renderer.get()); } -void SDLContext::present_screen() { - SDL_RenderPresent(this->game_renderer.get()); -} +void SDLContext::present_screen() { SDL_RenderPresent(this->game_renderer.get()); } -void SDLContext::draw(const Sprite & sprite, const Transform & transform, - const Camera & cam) { +void SDLContext::draw(const Sprite & sprite, const Transform & transform, const Camera & cam) { SDL_RendererFlip render_flip = (SDL_RendererFlip) ((SDL_FLIP_HORIZONTAL * sprite.flip.flip_x) @@ -135,9 +128,7 @@ void SDLContext::draw(const Sprite & sprite, const Transform & transform, .h = static_cast<int>(adjusted_h), }; - SDL_RenderCopyEx(this->game_renderer.get(), - sprite.sprite_image->texture.get(), &srcrect, - + SDL_RenderCopyEx(this->game_renderer.get(), sprite.sprite_image->texture.get(), &srcrect, &dstrect, transform.rotation, NULL, render_flip); } @@ -147,8 +138,8 @@ void SDLContext::camera(const Camera & cam) { this->viewport.x = static_cast<int>(cam.x) - (SCREEN_WIDTH / 2); this->viewport.y = static_cast<int>(cam.y) - (SCREEN_HEIGHT / 2); - SDL_SetRenderDrawColor(this->game_renderer.get(), cam.bg_color.r, - cam.bg_color.g, cam.bg_color.b, cam.bg_color.a); + SDL_SetRenderDrawColor(this->game_renderer.get(), cam.bg_color.r, cam.bg_color.g, + cam.bg_color.b, cam.bg_color.a); } uint64_t SDLContext::get_ticks() const { return SDL_GetTicks64(); } @@ -161,22 +152,18 @@ SDLContext::texture_from_path(const std::string & path) { tmp = IMG_Load("../asset/texture/ERROR.png"); } - std::unique_ptr<SDL_Surface, std::function<void(SDL_Surface *)>> - img_surface; - img_surface - = {tmp, [](SDL_Surface * surface) { SDL_FreeSurface(surface); }}; + std::unique_ptr<SDL_Surface, std::function<void(SDL_Surface *)>> img_surface; + img_surface = {tmp, [](SDL_Surface * surface) { SDL_FreeSurface(surface); }}; - SDL_Texture * tmp_texture = SDL_CreateTextureFromSurface( - this->game_renderer.get(), img_surface.get()); + SDL_Texture * tmp_texture + = SDL_CreateTextureFromSurface(this->game_renderer.get(), img_surface.get()); if (tmp_texture == nullptr) { throw runtime_error(format("Texture cannot be load from {}", path)); } - std::unique_ptr<SDL_Texture, std::function<void(SDL_Texture *)>> - img_texture; - img_texture = {tmp_texture, - [](SDL_Texture * texture) { SDL_DestroyTexture(texture); }}; + std::unique_ptr<SDL_Texture, std::function<void(SDL_Texture *)>> img_texture; + img_texture = {tmp_texture, [](SDL_Texture * texture) { SDL_DestroyTexture(texture); }}; return img_texture; } diff --git a/src/crepe/facade/SDLContext.h b/src/crepe/facade/SDLContext.h index 536dec5..007092b 100644 --- a/src/crepe/facade/SDLContext.h +++ b/src/crepe/facade/SDLContext.h @@ -17,9 +17,8 @@ const int SCREEN_HEIGHT = 480; namespace crepe { -// TODO: SDL_Keycode is defined in a header not distributed with crepe, which -// means this typedef is unusable when crepe is packaged. Wouter will fix this -// later. +// TODO: SDL_Keycode is defined in a header not distributed with crepe, which means this +// typedef is unusable when crepe is packaged. Wouter will fix this later. typedef SDL_Keycode CREPE_KEYCODES; class Texture; @@ -29,8 +28,8 @@ class LoopManager; * \class SDLContext * \brief Facade for the SDL library * - * SDLContext is a singleton that handles the SDL window and renderer, provides methods - * for event handling, and rendering to the screen. It is never used directly by the user + * SDLContext is a singleton that handles the SDL window and renderer, provides methods for + * event handling, and rendering to the screen. It is never used directly by the user */ class SDLContext { @@ -68,9 +67,8 @@ private: /** * \brief Pauses the execution for a specified duration. * - * This function uses SDL's delay function to halt the program execution - * for a given number of milliseconds, allowing for frame rate control - * or other timing-related functionality. + * This function uses SDL's delay function to halt the program execution for a given number + * of milliseconds, allowing for frame rate control or other timing-related functionality. * * \param ms Duration of the delay in milliseconds. */ @@ -127,8 +125,7 @@ private: * \param transform Reference to the Transform for positioning. * \param camera Reference to the Camera for view adjustments. */ - void draw(const Sprite & sprite, const Transform & transform, - const Camera & camera); + void draw(const Sprite & sprite, const Transform & transform, const Camera & camera); //! Clears the screen, preparing for a new frame. void clear_screen(); @@ -147,8 +144,7 @@ private: std::unique_ptr<SDL_Window, std::function<void(SDL_Window *)>> game_window; //! renderer for the crepe engine - std::unique_ptr<SDL_Renderer, std::function<void(SDL_Renderer *)>> - game_renderer; + std::unique_ptr<SDL_Renderer, std::function<void(SDL_Renderer *)>> game_renderer; //! viewport for the camera window SDL_Rect viewport = {0, 0, 640, 480}; diff --git a/src/crepe/facade/Sound.h b/src/crepe/facade/Sound.h index 402482f..32b6478 100644 --- a/src/crepe/facade/Sound.h +++ b/src/crepe/facade/Sound.h @@ -19,29 +19,26 @@ public: /** * \brief Pause this sample * - * Pauses this sound if it is playing, or does nothing if it is already - * paused. The playhead position is saved, such that calling \c play() after - * this function makes the sound resume. + * Pauses this sound if it is playing, or does nothing if it is already paused. The playhead + * position is saved, such that calling \c play() after this function makes the sound resume. */ void pause(); /** * \brief Play this sample * - * Resume playback if this sound is paused, or start from the beginning of - * the sample. + * Resume playback if this sound is paused, or start from the beginning of the sample. * - * \note This class only saves a reference to the most recent 'voice' of this - * sound. Calling \c play() while the sound is already playing causes - * multiple instances of the sample to play simultaniously. The sample - * started last is the one that is controlled afterwards. + * \note This class only saves a reference to the most recent 'voice' of this sound. Calling + * \c play() while the sound is already playing causes multiple instances of the sample to + * play simultaniously. The sample started last is the one that is controlled afterwards. */ void play(); /** * \brief Reset playhead position * - * Resets the playhead position so that calling \c play() after this function - * makes it play from the start of the sample. If the sound is not paused - * before calling this function, this function will stop playback. + * Resets the playhead position so that calling \c play() after this function makes it play + * from the start of the sample. If the sound is not paused before calling this function, + * this function will stop playback. */ void rewind(); /** |