| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
- //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
- #include "Utility/BsTime.h"
- #include "Utility/BsTimer.h"
- namespace bs
- {
- const double Time::MICROSEC_TO_SEC = 1.0/1000000.0;
- Time::Time()
- :mFrameDelta(0.0f), mTimeSinceStart(0.0f), mTimeSinceStartMs(0), mAppStartTime(0), mLastFrameTime(0),
- mCurrentFrame(0UL)
- {
- mTimer = bs_new<Timer>();
- mAppStartTime = mTimer->getStartMs();
- mLastFrameTime = mTimer->getMicroseconds();
- }
- Time::~Time()
- {
- bs_delete(mTimer);
- }
- void Time::_update()
- {
- UINT64 currentFrameTime = mTimer->getMicroseconds();
- mFrameDelta = (float)((currentFrameTime - mLastFrameTime) * MICROSEC_TO_SEC);
- mTimeSinceStartMs = (UINT64)(currentFrameTime / 1000);
- mTimeSinceStart = mTimeSinceStartMs / 1000.0f;
-
- mLastFrameTime = currentFrameTime;
- mCurrentFrame.fetch_add(1, std::memory_order_relaxed);
- }
- UINT64 Time::getTimePrecise() const
- {
- return mTimer->getMicroseconds();
- }
- Time& gTime()
- {
- return Time::instance();
- }
- }
|