From a8f8d501298e79aca6823e0ffad434159d8f567d Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Sun, 9 Feb 2014 00:32:11 +0100 Subject: [PATCH] New code and data to get something on screen. WiP. --- CMakeLists.txt | 2 ++ resources/graphics/duck.bmp | Bin 0 -> 56498 bytes src/game.cpp | 38 ++++++++++++++++++++++++++++++++++++ src/game.hpp | 25 ++++++++++++++++++++++++ src/gamebase.cpp | 38 ++++++++++++++++++++++++++++++++++++ src/gamebase.hpp | 30 ++++++++++++++++++++++++++++ src/main.cpp | 5 +++++ src/sdlmain.cpp | 1 + src/texture.cpp | 17 ++++++++++++++++ src/texture.hpp | 1 + 10 files changed, 157 insertions(+) create mode 100644 resources/graphics/duck.bmp create mode 100644 src/game.cpp create mode 100644 src/game.hpp create mode 100644 src/gamebase.cpp create mode 100644 src/gamebase.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 8da09bc..2dea7fb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,6 +27,8 @@ add_executable(${PROJECT_NAME} src/texture.cpp src/sdlerror.cpp src/sdlmain.cpp + src/game.cpp + src/gamebase.cpp ) target_link_libraries(${PROJECT_NAME} diff --git a/resources/graphics/duck.bmp b/resources/graphics/duck.bmp new file mode 100644 index 0000000000000000000000000000000000000000..a0542f49734a5fac5cc154979aee2da1983ba575 GIT binary patch literal 56498 zcmeI52Y3@l_Q3DHKcqkiAqfeA5FijtFQFP2+J#)&0j_i~5HQ$a0s$w%1VZnXtleN-f!Q`oA=(#Ecz~-_>Ydi z+3^23_;>2%zkmK?NXKz6c>lfr%6}aP;J>lU>r7C_*%7NVo;DTu(y9}sqV^Z2{Zl9u zF&SK|jSVLFr8s_siP$XOTuRRO1vU&~np`F^Et(e$w#@Z-i-nyjp2D8TX6KSTvu82zK zT5sxMJ&jT?O~J-`T?H{4H3V8KV#qw2SAEp{!ZY)8ep`^~xj40G?n_riMvZ2?e=5d==S3Fd*nV-4OHr3rW*=2shiZA1x);)K5 z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b-C+OH;B#5l~pmJQO(66uzYvt zQXEVv4s9t7gUt)+HOZ{TJXqFKBE+)8B!B_)p$65M9u^$a1%QTg3}Q3Mq2}1NVm70N z$EfEs|Embv$RZw7D&i>+?9m-mUF3?kc3Db3Z|QDxPhZv`Wo&O5#HPc`*^pku7l`B_ zMEFy0hzzX5-C$HyLlWN#WG&j-i0$X~=&KB5QwR3(>ix~Wv79oZn8TB!V;4Le0Wf@l z!BA8>7fdoUpCw~F{D!iDZwBM=c`glWy(kB7(O~$JRl?^Bu?GuaSPJ9Qq&z&!5% z@C;?M+?^2YA61qe*Fq-pcw(6h8Z*@J?NlH`4ALsVfd=|Prb=p?#GoZd@6f;4-l+8} z_SzE+WP`TU^ETAEpJ+P&h(nullptr)); + } + + ///------------------------------------------------------------------------ + ///------------------------------------------------------------------------ + void Game::OnRender() { + m_character->Render(); + } +} //namespace cloonel diff --git a/src/game.hpp b/src/game.hpp new file mode 100644 index 0000000..2402f28 --- /dev/null +++ b/src/game.hpp @@ -0,0 +1,25 @@ +#ifndef id0E85DAFBFF5D497E8B3699AED806840A +#define id0E85DAFBFF5D497E8B3699AED806840A + +#include "gamebase.hpp" +#include + +namespace cloonel { + class Texture; + + class Game : public GameBase { + public: + Game ( SDLMain* parSdlMain ); + virtual ~Game ( void ) noexcept; + + virtual void Prepare ( void ); + virtual void Destroy ( void ) noexcept; + + private: + virtual void OnRender ( void ); + + std::unique_ptr m_character; + }; +} //namespace cloonel + +#endif diff --git a/src/gamebase.cpp b/src/gamebase.cpp new file mode 100644 index 0000000..af8ab2e --- /dev/null +++ b/src/gamebase.cpp @@ -0,0 +1,38 @@ +#include "gamebase.hpp" +#include "texture.hpp" +#include "sdlmain.hpp" +#include +#include + +namespace cloonel { + ///------------------------------------------------------------------------ + ///------------------------------------------------------------------------ + GameBase::GameBase (SDLMain* parSdlMain) : + m_sdlmain(parSdlMain) + { + } + + ///------------------------------------------------------------------------ + ///------------------------------------------------------------------------ + GameBase::~GameBase() { + } + + ///------------------------------------------------------------------------ + ///------------------------------------------------------------------------ + std::unique_ptr GameBase::LoadTexture (const char* parPath) { + std::ostringstream oss; + oss << "/home/duckz/dev/code/cpp/clooneljump/" << parPath; + return std::move(std::unique_ptr(new Texture(oss.str(), m_sdlmain, true))); + } + + ///------------------------------------------------------------------------ + ///------------------------------------------------------------------------ + void GameBase::Exec (float parDelta) { + SDL_Renderer* const ren = m_sdlmain->GetRenderer(); + + SDL_RenderClear(ren); + OnRender(); + SDL_RenderPresent(ren); + SDL_Delay(2000); + } +} //namespace cloonel diff --git a/src/gamebase.hpp b/src/gamebase.hpp new file mode 100644 index 0000000..118d690 --- /dev/null +++ b/src/gamebase.hpp @@ -0,0 +1,30 @@ +#ifndef id8C7FE975525B4329BFBEAF364D934EAD +#define id8C7FE975525B4329BFBEAF364D934EAD + +#include + +namespace cloonel { + class SDLMain; + class Texture; + + class GameBase { + public: + void Exec ( float parDelta ); + + protected: + explicit GameBase ( SDLMain* parSdlMain ); + virtual ~GameBase ( void ) noexcept; + + virtual void Prepare ( void ) = 0; + virtual void Destroy ( void ) noexcept = 0; + + std::unique_ptr LoadTexture ( const char* parPath ); + + private: + virtual void OnRender ( void ) = 0; + + SDLMain* const m_sdlmain; + }; +} //namespace cloonel + +#endif diff --git a/src/main.cpp b/src/main.cpp index 81eadf5..4a0f0f4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,5 +1,6 @@ #include "CloonelJumpConfig.h" #include "sdlmain.hpp" +#include "game.hpp" #include #include @@ -18,6 +19,10 @@ int main() { std::cerr << e.what() << std::endl; } + cloonel::Game game(&sdlmain); + game.Prepare(); + game.Exec(0.0f); + std::cout << "Quitting now" << std::endl; return 0; } diff --git a/src/sdlmain.cpp b/src/sdlmain.cpp index cb67f59..ed2c6b1 100644 --- a/src/sdlmain.cpp +++ b/src/sdlmain.cpp @@ -12,6 +12,7 @@ namespace cloonel { ///------------------------------------------------------------------------ SDLMain::SDLMain (const char* parGameName, int parWidth, int parHeight) : m_gameName(parGameName), + m_localData(new LocalData), m_defWidth(parWidth), m_defHeight(parHeight) { diff --git a/src/texture.cpp b/src/texture.cpp index 11ff4b5..c9f60e9 100644 --- a/src/texture.cpp +++ b/src/texture.cpp @@ -3,8 +3,11 @@ #include "sdlmain.hpp" #include #include +#include namespace cloonel { + ///------------------------------------------------------------------------ + ///------------------------------------------------------------------------ Texture::Texture (const std::string& parPath, SDLMain* parMain, bool parLoadNow) : m_path(parPath), m_texture(nullptr), @@ -14,10 +17,14 @@ namespace cloonel { Reload(); } + ///------------------------------------------------------------------------ + ///------------------------------------------------------------------------ Texture::~Texture() noexcept { Destroy(); } + ///------------------------------------------------------------------------ + ///------------------------------------------------------------------------ void Texture::Destroy() noexcept { if (m_texture) { SDL_DestroyTexture(m_texture); @@ -25,6 +32,8 @@ namespace cloonel { } } + ///------------------------------------------------------------------------ + ///------------------------------------------------------------------------ void Texture::Reload() { Destroy(); SDL_Surface* surf = SDL_LoadBMP(m_path.c_str()); @@ -32,5 +41,13 @@ namespace cloonel { throw std::runtime_error(GetFullErrorMessage(__PRETTY_FUNCTION__, m_path)); m_texture = SDL_CreateTextureFromSurface(m_sdlmain->GetRenderer(), surf); + SDL_FreeSurface(surf); + } + + ///------------------------------------------------------------------------ + ///------------------------------------------------------------------------ + void Texture::Render() { + assert(IsLoaded()); + SDL_RenderCopy(m_sdlmain->GetRenderer(), m_texture, nullptr, nullptr); } } //namespace cloonel diff --git a/src/texture.hpp b/src/texture.hpp index ac76c27..3f5e212 100644 --- a/src/texture.hpp +++ b/src/texture.hpp @@ -16,6 +16,7 @@ namespace cloonel { void Reload ( void ); void Destroy ( void ) noexcept; bool IsLoaded ( void ) const { return nullptr != m_texture; } + void Render ( void ); private: const std::string m_path;