Răsfoiți Sursa

Fixing update time.

bkaradzic 12 ani în urmă
părinte
comite
3686725fef

+ 3 - 2
examples/02-metaballs/metaballs.cpp

@@ -572,6 +572,8 @@ int _main_(int /*_argc*/, char** /*_argv*/)
 	const uint32_t zpitch = DIMS*DIMS;
 	const float invdim = 1.0f/float(DIMS-1);
 
+	int64_t timeOffset = bx::getHPCounter();
+
 	while (!processEvents(width, height, debug, reset) )
 	{
 		// Set view 0 default viewport.
@@ -587,6 +589,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
 		last = now;
 		const double freq = double(bx::getHPFrequency() );
 		const double toMs = 1000.0/freq;
+		float time = (float)( (now - timeOffset)/double(bx::getHPFrequency() ) );
 
 		// Use debug font to print information about this example.
 		bgfx::dbgTextClear();
@@ -604,8 +607,6 @@ int _main_(int /*_argc*/, char** /*_argv*/)
 		// Set view and projection matrix for view 0.
 		bgfx::setViewTransform(0, view, proj);
 
-		float time = (float)(bx::getHPCounter()/double(bx::getHPFrequency() ) );
-
 		// Stats.
 		uint32_t numVertices = 0;
 		int64_t profUpdate = 0;

+ 3 - 2
examples/05-instancing/instancing.cpp

@@ -172,6 +172,8 @@ int _main_(int /*_argc*/, char** /*_argv*/)
 	bgfx::destroyVertexShader(vsh);
 	bgfx::destroyFragmentShader(fsh);
 
+	int64_t timeOffset = bx::getHPCounter();
+
 	while (!processEvents(width, height, debug, reset) )
 	{
 		// Set view 0 default viewport.
@@ -187,6 +189,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
 		last = now;
 		const double freq = double(bx::getHPFrequency() );
 		const double toMs = 1000.0/freq;
+		float time = (float)( (now - timeOffset)/double(bx::getHPFrequency() ) );
 
 		// Use debug font to print information about this example.
 		bgfx::dbgTextClear();
@@ -205,8 +208,6 @@ int _main_(int /*_argc*/, char** /*_argv*/)
 		// Set view and projection matrix for view 0.
 		bgfx::setViewTransform(0, view, proj);
 
-		float time = (float)(bx::getHPCounter()/double(bx::getHPFrequency() ) );
-
 		const uint16_t instanceStride = 80;
 		const bgfx::InstanceDataBuffer* idb = bgfx::allocInstanceDataBuffer(121, instanceStride);
 		if (NULL != idb)

+ 3 - 2
examples/08-update/update.cpp

@@ -228,6 +228,8 @@ int _main_(int /*_argc*/, char** /*_argv*/)
 	uint32_t miss = 0;
 	std::list<PackCube> quads;
 
+	int64_t timeOffset = bx::getHPCounter();
+
 	while (!processEvents(width, height, debug, reset) )
 	{
 		// Set view 0 default viewport.
@@ -243,6 +245,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
 		last = now;
 		const int64_t freq = bx::getHPFrequency();
 		const double toMs = 1000.0/double(freq);
+		float time = (float)( (now - timeOffset)/double(bx::getHPFrequency() ) );
 
 		// Use debug font to print information about this example.
 		bgfx::dbgTextClear();
@@ -310,8 +313,6 @@ int _main_(int /*_argc*/, char** /*_argv*/)
 		// Set view and projection matrix for view 0.
 		bgfx::setViewTransform(0, view, proj);
 
-		float time = (float)(bx::getHPCounter()/double(bx::getHPFrequency() ) );
-
 		float mtx[16];
 		mtxRotateXY(mtx, time, time*0.37f);