diff --git a/src/CloonelJumpConfig.h.in b/src/CloonelJumpConfig.h.in index 70c715f..ad02d3a 100644 --- a/src/CloonelJumpConfig.h.in +++ b/src/CloonelJumpConfig.h.in @@ -21,11 +21,13 @@ #define id5FC1D6EEF9DF41E790068FBC6753035F #define GameName "@PROJECT_NAME@" -#define GameVersionMinor 1 +#define GameVersionMinor 11 #define GameVersionMajor 0 -#define DEF_WIN_WIDTH 800 -#define DEF_WIN_HEIGHT 600 +#define REFERENCE_WIDTH 480 +#define REFERENCE_HEIGHT 600 +#define DEF_WIN_WIDTH REFERENCE_WIDTH +#define DEF_WIN_HEIGHT REFERENCE_HEIGHT #define GAME_BASE_PATH "@CMAKE_SOURCE_DIR@" diff --git a/src/character.cpp b/src/character.cpp index 8301e8b..310b80e 100644 --- a/src/character.cpp +++ b/src/character.cpp @@ -49,7 +49,7 @@ namespace cloonel { ///------------------------------------------------------------------------- void Character::Prepare() { const SDLMain* const sdlmain = m_texture->SDLObject(); - const int2 screensize(sdlmain->DefWidthHeight()); + const int2 screensize(sdlmain->WidthHeight()); m_texture->Reload(); } diff --git a/src/gameplaysceneclassic.cpp b/src/gameplaysceneclassic.cpp index eacd11f..d26447e 100644 --- a/src/gameplaysceneclassic.cpp +++ b/src/gameplaysceneclassic.cpp @@ -77,7 +77,7 @@ namespace cloonel { AddDrawable(m_wallpaper.get()); AddDrawable(m_player.get()); - m_moverSine->SetPower(static_cast(SDLObject()->DefWidthHeight().y() / 2)); + m_moverSine->SetPower(static_cast(SDLObject()->WidthHeight().y() / 2)); } ///-------------------------------------------------------------------------- diff --git a/src/main.cpp b/src/main.cpp index 2633cb6..176ac65 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -21,6 +21,7 @@ #include "sdlmain.hpp" #include "physicsfswrapper.hpp" #include "gameplaysceneclassic.hpp" +#include "vector.hpp" #include #include #include @@ -44,7 +45,7 @@ int main (int, char* parArgv[]) { std::cout << GameName << " v" << GameVersionMajor << "." << GameVersionMinor << std::endl; int retVal = 0; - cloonel::SDLMain sdlmain(GameName, DEF_WIN_WIDTH, DEF_WIN_HEIGHT); + cloonel::SDLMain sdlmain(GameName, cloonel::ushort2(DEF_WIN_WIDTH, DEF_WIN_HEIGHT), cloonel::ushort2(REFERENCE_WIDTH, REFERENCE_HEIGHT)); try { cloonel::PhysicsFSWrapper physfs(parArgv[0]); physfs.Append(GAME_BASE_PATH "/resources/", "resources"); diff --git a/src/sdlmain.cpp b/src/sdlmain.cpp index 8670c12..a83cad3 100644 --- a/src/sdlmain.cpp +++ b/src/sdlmain.cpp @@ -27,12 +27,27 @@ namespace cloonel { bool initialized; }; + namespace { + float2 GetScaling (ushort2 parRes, ushort2 parRef) __attribute__((pure)); + + ///---------------------------------------------------------------------- + ///---------------------------------------------------------------------- + float2 GetScaling (ushort2 parRes, ushort2 parRef) { + return float2( + static_cast(parRes.x()) / static_cast(parRef.x()), + static_cast(parRes.y()) / static_cast(parRef.y()) + ); + } + } //unnamed namespace + ///------------------------------------------------------------------------ ///------------------------------------------------------------------------ - SDLMain::SDLMain (const char* parGameName, int parWidth, int parHeight) : + SDLMain::SDLMain (const char* parGameName, ushort2 parRes, ushort2 parReferenceRes) : m_gameName(parGameName), m_localData(new LocalData), - m_defWH(parWidth, parHeight) + m_WHScaling(GetScaling(parRes, parReferenceRes)), + m_WH(parRes), + m_WHRef(parReferenceRes) { } @@ -60,7 +75,7 @@ namespace cloonel { throw std::runtime_error(SDL_GetError()); parInitSDL.initialized = true; - SDL_Window* const win = SDL_CreateWindow(m_gameName.c_str(), 100, 100, m_defWH.x(), m_defWH.y(), SDL_WINDOW_SHOWN); + SDL_Window* const win = SDL_CreateWindow(m_gameName.c_str(), 100, 100, m_WH.x(), m_WH.y(), SDL_WINDOW_SHOWN); if (!win) throw std::runtime_error(SDL_GetError()); parInitSDL.window = win; diff --git a/src/sdlmain.hpp b/src/sdlmain.hpp index 78f8748..f11b4b9 100644 --- a/src/sdlmain.hpp +++ b/src/sdlmain.hpp @@ -28,12 +28,13 @@ struct SDL_Renderer; namespace cloonel { class SDLMain { public: - SDLMain ( const char* parGameName, int parWidth, int parHeight ); + SDLMain ( const char* parGameName, ushort2 parRes, ushort2 parReferenceRes ); ~SDLMain ( void ) noexcept; void Init ( void ); SDL_Renderer* GetRenderer ( void ); - const int2& DefWidthHeight ( void ) const { return m_defWH; } + const ushort2& WidthHeight ( void ) const { return m_WH; } + const float2& WHScaling ( void ) const { return m_WHScaling; } private: struct LocalData; @@ -43,7 +44,9 @@ namespace cloonel { const std::string m_gameName; std::unique_ptr m_localData; - const int2 m_defWH; + float2 m_WHScaling; + ushort2 m_WH; + const ushort2 m_WHRef; }; } //namespace cloonel diff --git a/src/texture.cpp b/src/texture.cpp index e8b2683..007836a 100644 --- a/src/texture.cpp +++ b/src/texture.cpp @@ -271,7 +271,7 @@ namespace cloonel { ///-------------------------------------------------------------------------- void Texture::Render (int2 parPos, ushort2 parSize) const { assert(IsLoaded()); - const int screenHeight = m_sdlmain->DefWidthHeight().y(); + const int screenHeight = m_sdlmain->WidthHeight().y(); const SDL_Rect dest = { parPos.x(), screenHeight - parPos.y() - parSize.y(), parSize.x(), parSize.y() }; SDL_RenderCopy(m_sdlmain->GetRenderer(), m_texture, nullptr, &dest); }