void FpsComponent::Update(const GameTime& gameTime) { if (gameTime.TotalGameTime() - mLastTotalElapsedTime >= 1) { mLastTotalElapsedTime = gameTime.TotalGameTime(); mFrameRate = mFrameCount; mFrameCount = 0; } mFrameCount++; }
//Go through our queue and publish any expired events void EventQueue::Update(const GameTime& curTime) { SList<std::shared_ptr<EventPublisher>>::Iterator i = mQueue.begin(); while(i != mQueue.end()) { if ((**i).IsExpired(curTime.TotalGameTime())) { (**i).Deliver(); mQueue.Remove(*i); i = mQueue.begin(); } else { i++; } } }
void FpsComponent::Draw(const GameTime& gameTime) { mSpriteBatch->Begin(); std::wostringstream fpsLabel; fpsLabel << std::setprecision(4) << L"Frame Rate: " << mFrameRate << " Total Elapsed Time: " << gameTime.TotalGameTime(); mSpriteFont->DrawString(mSpriteBatch, fpsLabel.str().c_str(), mTextPosition); mSpriteBatch->End(); }
//Add a new event publisher to our queue void EventQueue::Enqueue(std::shared_ptr<EventPublisher> publisher, const GameTime& curTime, const double& delay) { (*publisher).SetTime(curTime.TotalGameTime(), delay); mQueue.PushBack(publisher); }