Skip to content

Commit

Permalink
Pass the actual height and width to PictureFactory.
Browse files Browse the repository at this point in the history
Use these instead of the height and width from settings.video since when
in full screen mode, the width and height are unlikely to be exactly
what was requested.
  • Loading branch information
henricj committed Jun 8, 2022
1 parent fb204bc commit 8edfc7e
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 18 deletions.
2 changes: 1 addition & 1 deletion include/FileClasses/GFXManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

class GFXManager final {
public:
GFXManager();
GFXManager(SDL_Renderer* renderer, int width, int height);
~GFXManager();

GFXManager(const GFXManager&) = delete;
Expand Down
5 changes: 4 additions & 1 deletion include/FileClasses/PictureFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

class PictureFactory {
public:
PictureFactory();
PictureFactory(int width, int height);
~PictureFactory();

PictureFactory(const PictureFactory&) = delete;
Expand Down Expand Up @@ -99,6 +99,9 @@ class PictureFactory {
private:
[[nodiscard]] sdl2::surface_ptr createBackgroundTile(SDL_Surface* fame_pic) const;

int width_{};
int height_{};

sdl2::surface_ptr background;
sdl2::surface_ptr gameStatsBackground;
sdl2::surface_ptr creditsBorder;
Expand Down
2 changes: 1 addition & 1 deletion include/FileClasses/SurfaceLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

class SurfaceLoader final {
public:
SurfaceLoader();
SurfaceLoader(int width, int height);
~SurfaceLoader();

SurfaceLoader(const SurfaceLoader&) = delete;
Expand Down
6 changes: 3 additions & 3 deletions src/FileClasses/GFXManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@

#include <SDL2/SDL.h>

GFXManager::GFXManager()
: random_{RandomFactory{}.create("UI")}, duneTextures{
DuneTextures::create(dune::globals::renderer.get(), &surfaceLoader)} {
GFXManager::GFXManager(SDL_Renderer* renderer, int width, int height)
: random_{RandomFactory{}.create("UI")}, surfaceLoader{width, height}, duneTextures{DuneTextures::create(
renderer, &surfaceLoader)} {
initialize_cursors();
}

Expand Down
12 changes: 5 additions & 7 deletions src/FileClasses/PictureFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#include <cstddef>
#include <memory>

PictureFactory::PictureFactory() {
PictureFactory::PictureFactory(int width, int height) : width_{width}, height_{height} {
const auto* const file_manager = dune::globals::pFileManager.get();

const auto ScreenPic = LoadCPS_RW(file_manager->openFile("SCREEN.CPS").get());
Expand All @@ -58,9 +58,7 @@ PictureFactory::PictureFactory() {

backgroundTile = createBackgroundTile(FamePic.get());

const auto& video = dune::globals::settings.video;

background = createBackground(video.width, video.height);
background = createBackground(width_, height_);

// decoration border
decorationBorder.ball = getSubPicture(ScreenPic.get(), 241, 124, 12, 11);
Expand Down Expand Up @@ -247,7 +245,7 @@ PictureFactory::PictureFactory() {
PictureFactory::~PictureFactory() = default;

sdl2::surface_ptr PictureFactory::createTopBar() const {
auto topBar = getSubPicture(background.get(), 0, 0, dune::globals::settings.video.width - SIDEBARWIDTH, 32 + 12);
auto topBar = getSubPicture(background.get(), 0, 0, width_ - SIDEBARWIDTH, 32 + 12);

const SDL_Rect dest1{0, 31, getWidth(topBar.get()), 12};
SDL_FillRect(topBar.get(), &dest1, COLOR_TRANSPARENT);
Expand All @@ -269,7 +267,7 @@ sdl2::surface_ptr PictureFactory::createTopBar() const {
}

sdl2::surface_ptr PictureFactory::createSideBar(bool bEditor) const {
auto sideBar = getSubPicture(background.get(), 0, 0, SIDEBARWIDTH, dune::globals::settings.video.height);
auto sideBar = getSubPicture(background.get(), 0, 0, SIDEBARWIDTH, height_);

const SDL_Rect dest1{0, 0, 13, getHeight(sideBar.get())};
SDL_FillRect(sideBar.get(), &dest1, COLOR_TRANSPARENT);
Expand Down Expand Up @@ -350,7 +348,7 @@ sdl2::surface_ptr PictureFactory::createSideBar(bool bEditor) const {
}

sdl2::surface_ptr PictureFactory::createBottomBar() const {
auto BottomBar = getSubPicture(background.get(), 0, 0, dune::globals::settings.video.width - SIDEBARWIDTH, 32 + 12);
auto BottomBar = getSubPicture(background.get(), 0, 0, width_ - SIDEBARWIDTH, 32 + 12);
const SDL_Rect dest1{0, 0, getWidth(BottomBar.get()), 13};
SDL_FillRect(BottomBar.get(), &dest1, COLOR_TRANSPARENT);

Expand Down
4 changes: 2 additions & 2 deletions src/FileClasses/SurfaceLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ static_assert(std::tuple_size_v<decltype(objPicTiles)> == NUM_OBJPICS);

} // namespace

SurfaceLoader::SurfaceLoader() {
SurfaceLoader::SurfaceLoader(int width, int height) {

const auto start = std::chrono::steady_clock::now();

Expand Down Expand Up @@ -604,7 +604,7 @@ SurfaceLoader::SurfaceLoader() {
uiGraphic[UI_SendToRepairIcon][harkIdx] = LoadPNG_RW(file_manager->openFile("SendToRepair.png").get());
SDL_SetColorKey(uiGraphic[UI_SendToRepairIcon][harkIdx].get(), SDL_TRUE, 0);

PictureFactory picFactory;
PictureFactory picFactory{width, height};

uiGraphic[UI_CreditsDigits][harkIdx] = shapes->getPictureArray(
10, 1, 2 | TILE_NORMAL, 3 | TILE_NORMAL, 4 | TILE_NORMAL, 5 | TILE_NORMAL, 6 | TILE_NORMAL, 7 | TILE_NORMAL,
Expand Down
9 changes: 6 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -818,9 +818,12 @@ bool run_game(int argc, char* argv[]) {
#endif

GlobalCleanup gfx_cleanup{dune::globals::pGFXManager};
const auto start = std::chrono::steady_clock::now();
dune::globals::pGFXManager = std::make_unique<GFXManager>();
const auto elapsed = std::chrono::steady_clock::now() - start;
const auto start = std::chrono::steady_clock::now();
{ // Scope
const auto size = getRendererSizePoint();
dune::globals::pGFXManager = std::make_unique<GFXManager>(renderer, size.x, size.y);
}
const auto elapsed = std::chrono::steady_clock::now() - start;

sdl2::log_info("GFXManager time: %f", std::chrono::duration<double>(elapsed).count());

Expand Down

0 comments on commit 8edfc7e

Please sign in to comment.