Skip to content

Commit

Permalink
Preload visible tiles on each window resize
Browse files Browse the repository at this point in the history
  • Loading branch information
AMDmi3 committed Nov 30, 2015
1 parent cf510bb commit 34baca5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/game.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ Game::Game(SDL2pp::Renderer& renderer)
tile_cache_(renderer),
session_start_(std::chrono::steady_clock::now()),
coins_(coin_locations_) {
tile_cache_.PreloadTilesSync(GetCameraRect());
}

Game::~Game() {
Expand Down Expand Up @@ -110,6 +109,10 @@ SDL2pp::Rect Game::GetCoinRect(const SDL2pp::Point& coin) const {
);
}

void Game::LoadVisibleTiles() {
tile_cache_.PreloadTilesSync(GetCameraRect());
}

void Game::Update(float delta_t) {
// All original game constants work at 60 fps fixed frame
// rate and do not take real frame time into account, so
Expand Down
1 change: 1 addition & 0 deletions src/game.hh
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ public:
SDL2pp::Rect GetPlayerCollisionRect() const;
SDL2pp::Rect GetCoinRect(const SDL2pp::Point& coin) const;

void LoadVisibleTiles();
void Update(float delta_t);
void Render();//const SDL2pp::Rect& viewport);

Expand Down
6 changes: 6 additions & 0 deletions src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ int main(int /*argc*/, char** /*argv*/) try {
game.ClearActionFlag(Game::DOWN);
break;
}
} else if (event.type == SDL_WINDOWEVENT) {
switch (event.window.event) {
case SDL_WINDOWEVENT_SIZE_CHANGED:
game.LoadVisibleTiles();
break;
}
}
}

Expand Down

0 comments on commit 34baca5

Please sign in to comment.