From d923e94541095184830a23ea2de5111564aa8879 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Sat, 22 Dec 2012 01:24:44 +0100 Subject: [PATCH] Game: Merged tick() into loop(), removed getFps(). --- source/Game.cpp | 43 +++++++------------------------------------ source/Game.h | 7 ------- 2 files changed, 7 insertions(+), 43 deletions(-) diff --git a/source/Game.cpp b/source/Game.cpp index 7752c9f..f3a85a1 100644 --- a/source/Game.cpp +++ b/source/Game.cpp @@ -19,18 +19,13 @@ /// Goal amount of frames per second. const int Game::FPS_GOAL = 60; -/// Milliseconds per tick at FPS_GOAL. -const float Game::TICKS_GOAL = 1000 / Game::FPS_GOAL; - /** * Initializes game, including window and objects (sprites). */ Game::Game(sf::RenderWindow& window) : mWindow(window), mView(Vector2f(0, 0), mWindow.getView().getSize()), - //mFps("test"), - mTileManager(mWorld), - mElapsed(0), + mTileManager(mWorld), mQuit(false), mPaused(false) { mWindow.setFramerateLimit(FPS_GOAL); @@ -73,38 +68,24 @@ Game::~Game() { */ void Game::loop() { - sf::Uint32 left = 0; while (!mQuit) { input(); - for (; !mPaused && (left >= TICKS_GOAL); left -= TICKS_GOAL) { - Character::think(TICKS_GOAL); - mWorld.step(); - - mCollection.checkDelete(); + int elapsed = mClock.restart().asMilliseconds(); + if (mPaused) { + elapsed = 0; } - //mFps.setString(getFps()); + Character::think(elapsed); + mCollection.checkDelete(); - tick(); - left += mElapsed; + mWorld.step(); render(); } } -/** - * Saves ticks since last call. - */ -void -Game::tick() { - mElapsed = mClock.restart().asMilliseconds(); - if (mPaused) { - mElapsed = 0; - } -} - /** * Handles general game input. */ @@ -230,15 +211,5 @@ Game::render() { // Render GUI and static stuff. mWindow.setView(mWindow.getDefaultView()); - //mWindow.draw(mFps); - mWindow.display(); } - -/** - * Returns current FPS as string. - */ -String -Game::getFps() { - return str((mElapsed != 0) ? 1000.0f / mElapsed : 0.0f, 2); -} diff --git a/source/Game.h b/source/Game.h index 0f6cab3..5f3d50a 100644 --- a/source/Game.h +++ b/source/Game.h @@ -39,36 +39,29 @@ public: private: void input(); void render(); - void tick(); void keyDown(const sf::Event& event); void keyUp(const sf::Event& event); void mouseUp(const sf::Event& event); void generate(); - String getFps(); sf::Vector2 convertCoordinates(int x, int y); // Private variables. private: static const int FPS_GOAL; - static const float TICKS_GOAL; World mWorld; sf::RenderWindow& mWindow; sf::Clock mClock; sf::View mView; - //sf::Text mFps; Collection mCollection; TileManager mTileManager; Pathfinder mPathfinder; std::unique_ptr mPlayer; - /// Milliseconds since the last tick. - sf::Uint32 mElapsed; - bool mQuit; bool mPaused; };