Refactoring in SDLMain.
This commit is contained in:
parent
4e3ad27ae8
commit
ccc831e34d
7 changed files with 34 additions and 13 deletions
|
@ -21,11 +21,13 @@
|
||||||
#define id5FC1D6EEF9DF41E790068FBC6753035F
|
#define id5FC1D6EEF9DF41E790068FBC6753035F
|
||||||
|
|
||||||
#define GameName "@PROJECT_NAME@"
|
#define GameName "@PROJECT_NAME@"
|
||||||
#define GameVersionMinor 1
|
#define GameVersionMinor 11
|
||||||
#define GameVersionMajor 0
|
#define GameVersionMajor 0
|
||||||
|
|
||||||
#define DEF_WIN_WIDTH 800
|
#define REFERENCE_WIDTH 480
|
||||||
#define DEF_WIN_HEIGHT 600
|
#define REFERENCE_HEIGHT 600
|
||||||
|
#define DEF_WIN_WIDTH REFERENCE_WIDTH
|
||||||
|
#define DEF_WIN_HEIGHT REFERENCE_HEIGHT
|
||||||
|
|
||||||
#define GAME_BASE_PATH "@CMAKE_SOURCE_DIR@"
|
#define GAME_BASE_PATH "@CMAKE_SOURCE_DIR@"
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ namespace cloonel {
|
||||||
///-------------------------------------------------------------------------
|
///-------------------------------------------------------------------------
|
||||||
void Character::Prepare() {
|
void Character::Prepare() {
|
||||||
const SDLMain* const sdlmain = m_texture->SDLObject();
|
const SDLMain* const sdlmain = m_texture->SDLObject();
|
||||||
const int2 screensize(sdlmain->DefWidthHeight());
|
const int2 screensize(sdlmain->WidthHeight());
|
||||||
|
|
||||||
m_texture->Reload();
|
m_texture->Reload();
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,7 +77,7 @@ namespace cloonel {
|
||||||
AddDrawable(m_wallpaper.get());
|
AddDrawable(m_wallpaper.get());
|
||||||
AddDrawable(m_player.get());
|
AddDrawable(m_player.get());
|
||||||
|
|
||||||
m_moverSine->SetPower(static_cast<float>(SDLObject()->DefWidthHeight().y() / 2));
|
m_moverSine->SetPower(static_cast<float>(SDLObject()->WidthHeight().y() / 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
///--------------------------------------------------------------------------
|
///--------------------------------------------------------------------------
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include "sdlmain.hpp"
|
#include "sdlmain.hpp"
|
||||||
#include "physicsfswrapper.hpp"
|
#include "physicsfswrapper.hpp"
|
||||||
#include "gameplaysceneclassic.hpp"
|
#include "gameplaysceneclassic.hpp"
|
||||||
|
#include "vector.hpp"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <ciso646>
|
#include <ciso646>
|
||||||
|
@ -44,7 +45,7 @@ int main (int, char* parArgv[]) {
|
||||||
std::cout << GameName << " v" << GameVersionMajor << "." << GameVersionMinor << std::endl;
|
std::cout << GameName << " v" << GameVersionMajor << "." << GameVersionMinor << std::endl;
|
||||||
|
|
||||||
int retVal = 0;
|
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 {
|
try {
|
||||||
cloonel::PhysicsFSWrapper physfs(parArgv[0]);
|
cloonel::PhysicsFSWrapper physfs(parArgv[0]);
|
||||||
physfs.Append(GAME_BASE_PATH "/resources/", "resources");
|
physfs.Append(GAME_BASE_PATH "/resources/", "resources");
|
||||||
|
|
|
@ -27,12 +27,27 @@ namespace cloonel {
|
||||||
bool initialized;
|
bool initialized;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
float2 GetScaling (ushort2 parRes, ushort2 parRef) __attribute__((pure));
|
||||||
|
|
||||||
|
///----------------------------------------------------------------------
|
||||||
|
///----------------------------------------------------------------------
|
||||||
|
float2 GetScaling (ushort2 parRes, ushort2 parRef) {
|
||||||
|
return float2(
|
||||||
|
static_cast<float>(parRes.x()) / static_cast<float>(parRef.x()),
|
||||||
|
static_cast<float>(parRes.y()) / static_cast<float>(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_gameName(parGameName),
|
||||||
m_localData(new LocalData),
|
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());
|
throw std::runtime_error(SDL_GetError());
|
||||||
parInitSDL.initialized = true;
|
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)
|
if (!win)
|
||||||
throw std::runtime_error(SDL_GetError());
|
throw std::runtime_error(SDL_GetError());
|
||||||
parInitSDL.window = win;
|
parInitSDL.window = win;
|
||||||
|
|
|
@ -28,12 +28,13 @@ struct SDL_Renderer;
|
||||||
namespace cloonel {
|
namespace cloonel {
|
||||||
class SDLMain {
|
class SDLMain {
|
||||||
public:
|
public:
|
||||||
SDLMain ( const char* parGameName, int parWidth, int parHeight );
|
SDLMain ( const char* parGameName, ushort2 parRes, ushort2 parReferenceRes );
|
||||||
~SDLMain ( void ) noexcept;
|
~SDLMain ( void ) noexcept;
|
||||||
|
|
||||||
void Init ( void );
|
void Init ( void );
|
||||||
SDL_Renderer* GetRenderer ( 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:
|
private:
|
||||||
struct LocalData;
|
struct LocalData;
|
||||||
|
@ -43,7 +44,9 @@ namespace cloonel {
|
||||||
|
|
||||||
const std::string m_gameName;
|
const std::string m_gameName;
|
||||||
std::unique_ptr<LocalData> m_localData;
|
std::unique_ptr<LocalData> m_localData;
|
||||||
const int2 m_defWH;
|
float2 m_WHScaling;
|
||||||
|
ushort2 m_WH;
|
||||||
|
const ushort2 m_WHRef;
|
||||||
};
|
};
|
||||||
} //namespace cloonel
|
} //namespace cloonel
|
||||||
|
|
||||||
|
|
|
@ -271,7 +271,7 @@ namespace cloonel {
|
||||||
///--------------------------------------------------------------------------
|
///--------------------------------------------------------------------------
|
||||||
void Texture::Render (int2 parPos, ushort2 parSize) const {
|
void Texture::Render (int2 parPos, ushort2 parSize) const {
|
||||||
assert(IsLoaded());
|
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() };
|
const SDL_Rect dest = { parPos.x(), screenHeight - parPos.y() - parSize.y(), parSize.x(), parSize.y() };
|
||||||
SDL_RenderCopy(m_sdlmain->GetRenderer(), m_texture, nullptr, &dest);
|
SDL_RenderCopy(m_sdlmain->GetRenderer(), m_texture, nullptr, &dest);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue