Esempio n. 1
0
void TestbedApp::draw()
{
	// clear out the window with black
	gl::clear( Color( 0, 0, 0 ) );

	settings.hz = settingsHz;

	test->Step(&settings);

	// Update the state of the particle parameter.
	bool restartTest;
	const bool changed = particleParameter.Changed(&restartTest);
	B2_NOT_USED(changed);

	test->DrawTitle(entry->name);

#if ! defined( CINDER_GL_ES )
	mParams.draw();
#else
	gl::color( 0.6f, 0.6f, 0.7f );
	gl::drawSolidRect( mLeftButton );
	gl::drawSolidRect( mRightButton );
#endif

	if (testSelection != testIndex || restartTest)
	{
		fullscreenUI.Reset();
		if (!restartTest) particleParameter.Reset();

		testIndex = testSelection;
		delete test;
		entry = g_testEntries + testIndex;
		test = entry->createFcn();
		viewZoom = test->GetDefaultViewZoom();
		settings.viewCenter.Set(0.0f, 20.0f * viewZoom);
		resizeView( width, height );
	}

	// print world step time stats every 600 frames
	static int s_printCount = 0;
	static b2Stat st;
	st.Record(settings.stepTimeOut);

	const int STAT_PRINT_INTERVAL = 600;
	if( settings.printStepTimeStats && st.GetCount() == STAT_PRINT_INTERVAL ) {

		console() << "World Step Time samples "
		          << s_printCount*STAT_PRINT_INTERVAL << "-" << (s_printCount+1)*STAT_PRINT_INTERVAL-1 << ": "
		          << st.GetMin() << "min " <<  st.GetMax() << "max " <<  st.GetMean() << "avg (ms)" << std::endl;
		s_printCount++;
	}
}
Esempio n. 2
0
static void SimulationLoop()
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	settings.hz = settingsHz;

	// call this each frame, to function correctly with devices that may recreate
	// the GL Context without us asking for it
	Resize(width, height);

	test->Step(&settings);

	// Update the state of the particle parameter.
	bool restartTest;
	const bool changed = particleParameter.Changed(&restartTest);
	B2_NOT_USED(changed);


	if (fullscreenUI.GetEnabled())
	{
		// Set framework settings options based on parameters
		const uint32 options = particleParameter.GetOptions();

		settings.strictContacts 	= options &
			ParticleParameter::OptionStrictContacts;
		settings.drawContactPoints	= options &
			ParticleParameter::OptionDrawContactPoints;
		settings.drawContactNormals	= options &
			ParticleParameter::OptionDrawContactNormals;
		settings.drawContactImpulse	= options &
			ParticleParameter::OptionDrawContactImpulse;
		settings.drawFrictionImpulse = options &
			ParticleParameter::OptionDrawFrictionImpulse;
		settings.drawStats 			 = options &
			ParticleParameter::OptionDrawStats;
		settings.drawProfile		 = options &
			ParticleParameter::OptionDrawProfile;

		// The b2Draw based flags must be exactly 0 or 1 currently.
		settings.drawShapes 	= options &
			ParticleParameter::OptionDrawShapes ? 1 : 0;
		settings.drawParticles 	= options &
			ParticleParameter::OptionDrawParticles ? 1 : 0;
		settings.drawJoints		= options &
			ParticleParameter::OptionDrawJoints ? 1 : 0;
		settings.drawAABBs		= options &
			ParticleParameter::OptionDrawAABBs ? 1 : 0;
		settings.drawCOMs 		= options &
			ParticleParameter::OptionDrawCOMs ? 1 : 0;

		// Draw the full screen UI with
		// "test_name [: particle_parameter] / fps" at the bottom of the
		// screen.
		std::string msg = entry->name;
		if (fullscreenUI.GetParticleParameterSelectionEnabled())
		{
			msg += " : ";
			msg += particleParameter.GetName();
		}

		std::stringstream ss;
		ss << int(1000.0f / ComputeFPS());
		msg += " / " + ss.str() + " fps";
		fullscreenUI.Draw(msg);
	}

	test->DrawTitle(entry->name);

	glutSwapBuffers();

	if (testSelection != testIndex || restartTest)
	{
		fullscreenUI.Reset();
		if (!restartTest) particleParameter.Reset();

		testIndex = testSelection;
		delete test;
		entry = g_testEntries + testIndex;
		test = entry->createFcn();
		viewZoom = test->GetDefaultViewZoom();
		settings.viewCenter.Set(0.0f, 20.0f * viewZoom);
		Resize(width, height);
	}

	// print world step time stats every 600 frames
	static int s_printCount = 0;
	static b2Stat st;
	st.Record(settings.stepTimeOut);

	const int STAT_PRINT_INTERVAL = 600;
	if ( settings.printStepTimeStats && st.GetCount() == STAT_PRINT_INTERVAL )
	{
		printf("World Step Time samples %i-%i: %fmin %fmax %favg (ms)\n",
			s_printCount*STAT_PRINT_INTERVAL,
			(s_printCount+1)*STAT_PRINT_INTERVAL-1,
			st.GetMin(), st.GetMax(), st.GetMean());
		st.Clear();
		s_printCount++;
	}
}