Browse Source

Samples: Next button (N) now also works when not running all tests (#1569)

Jorrit Rouwe 5 months ago
parent
commit
5c38f1e352
2 changed files with 54 additions and 37 deletions
  1. 53 35
      Samples/SamplesApp.cpp
  2. 1 2
      Samples/SamplesApp.h

+ 53 - 35
Samples/SamplesApp.cpp

@@ -492,8 +492,7 @@ SamplesApp::SamplesApp(const String &inCommandLine) :
 		});
 		});
 		mDebugUI->CreateTextButton(main_menu, "Restart Test (R)", [this]() { StartTest(mTestClass); });
 		mDebugUI->CreateTextButton(main_menu, "Restart Test (R)", [this]() { StartTest(mTestClass); });
 		mDebugUI->CreateTextButton(main_menu, "Run All Tests", [this]() { RunAllTests(); });
 		mDebugUI->CreateTextButton(main_menu, "Run All Tests", [this]() { RunAllTests(); });
-		mNextTestButton = mDebugUI->CreateTextButton(main_menu, "Next Test (N)", [this]() { NextTest(); });
-		mNextTestButton->SetDisabled(true);
+		mDebugUI->CreateTextButton(main_menu, "Next Test (N)", [this]() { NextTest(); });
 		mDebugUI->CreateTextButton(main_menu, "Take Snapshot", [this]() { TakeSnapshot(); });
 		mDebugUI->CreateTextButton(main_menu, "Take Snapshot", [this]() { TakeSnapshot(); });
 		mDebugUI->CreateTextButton(main_menu, "Take And Reload Snapshot", [this]() { TakeAndReloadSnapshot(); });
 		mDebugUI->CreateTextButton(main_menu, "Take And Reload Snapshot", [this]() { TakeAndReloadSnapshot(); });
 		mDebugUI->CreateTextButton(main_menu, "Physics Settings", [this]() {
 		mDebugUI->CreateTextButton(main_menu, "Physics Settings", [this]() {
@@ -682,6 +681,9 @@ SamplesApp::~SamplesApp()
 
 
 void SamplesApp::StartTest(const RTTI *inRTTI)
 void SamplesApp::StartTest(const RTTI *inRTTI)
 {
 {
+	// Clear anything that is being rendered right now to avoid showing the previous test while initializing the new one
+	ClearDebugRenderer();
+
 	// Pop active menus, we might be in the settings menu for the test which will be dangling after restarting the test
 	// Pop active menus, we might be in the settings menu for the test which will be dangling after restarting the test
 	mDebugUI->BackToMain();
 	mDebugUI->BackToMain();
 
 
@@ -743,9 +745,18 @@ void SamplesApp::StartTest(const RTTI *inRTTI)
 	// Reset the camera to the original position
 	// Reset the camera to the original position
 	ResetCamera();
 	ResetCamera();
 
 
-	// Start paused
-	Pause(true);
-	SingleStep();
+	if (mIsRunningAllTests)
+	{
+		// Unpause and start the count down
+		Pause(false);
+		mTestTimeLeft = 10.0f;
+	}
+	else
+	{
+		// Start paused
+		Pause(true);
+		SingleStep();
+	}
 
 
 	// Check if test has settings menu
 	// Check if test has settings menu
 	mTestSettingsButton->SetDisabled(!mTest->HasSettingsMenu());
 	mTestSettingsButton->SetDisabled(!mTest->HasSettingsMenu());
@@ -756,22 +767,42 @@ void SamplesApp::StartTest(const RTTI *inRTTI)
 
 
 void SamplesApp::RunAllTests()
 void SamplesApp::RunAllTests()
 {
 {
-	mTestsToRun.clear();
+	mIsRunningAllTests = true;
+	StartTest(sAllCategories[0].mTests[0].mRTTI);
+}
 
 
+bool SamplesApp::NextTest()
+{
+	// Find the next test to run based on the RTTI of the current test
+	const RTTI *next_test = nullptr;
+	bool cur_test_found = false;
 	for (const TestCategory &c : sAllCategories)
 	for (const TestCategory &c : sAllCategories)
-		for (uint i = 0; i < c.mNumTests; ++i)
+	{
+		for (uint j = 0; j < c.mNumTests; ++j)
 		{
 		{
-			TestNameAndRTTI &t = c.mTests[i];
-			mTestsToRun.push_back(t.mRTTI);
+			const TestNameAndRTTI &test = c.mTests[j];
+			if (cur_test_found)
+			{
+				// We already found the current test so this test is the next test to run
+				next_test = test.mRTTI;
+				break;
+			}
+			else if (test.mRTTI == mTestClass)
+			{
+				// RTTI matches, the next test we encounter is the next test to run
+				cur_test_found = true;
+			}
 		}
 		}
 
 
-	NextTest();
-}
+		if (next_test != nullptr)
+			break;
+	}
 
 
-bool SamplesApp::NextTest()
-{
-	if (mTestsToRun.empty())
+	if (next_test == nullptr)
 	{
 	{
+		mIsRunningAllTests = false;
+		mTestTimeLeft = -1.0f;
+
 		if (mExitAfterRunningTests)
 		if (mExitAfterRunningTests)
 			return false; // Exit the application now
 			return false; // Exit the application now
 		else
 		else
@@ -779,22 +810,10 @@ bool SamplesApp::NextTest()
 	}
 	}
 	else
 	else
 	{
 	{
-		// Start the timer for 10 seconds
-		mTestTimeLeft = 10.0f;
-
-		// Take next test
-		const RTTI *rtti = mTestsToRun.front();
-		mTestsToRun.erase(mTestsToRun.begin());
-
-		// Start it
-		StartTest(rtti);
-
-		// Unpause
-		Pause(false);
+		// Start next test
+		StartTest(next_test);
 	}
 	}
 
 
-	mNextTestButton->SetDisabled(mTestsToRun.empty());
-
 	return true;
 	return true;
 }
 }
 
 
@@ -2028,6 +2047,10 @@ bool SamplesApp::UpdateFrame(float inDeltaTime)
 	if (mMaxConcurrentJobs != mJobSystem->GetMaxConcurrency())
 	if (mMaxConcurrentJobs != mJobSystem->GetMaxConcurrency())
 		static_cast<JobSystemThreadPool *>(mJobSystem)->SetNumThreads(mMaxConcurrentJobs - 1);
 		static_cast<JobSystemThreadPool *>(mJobSystem)->SetNumThreads(mMaxConcurrentJobs - 1);
 
 
+	// Decrement number of frames to show the description
+	if (inDeltaTime > 0.0f && mShowDescription > 0)
+		--mShowDescription;
+
 	// Restart the test if the test requests this
 	// Restart the test if the test requests this
 	if (mTest->NeedsRestart())
 	if (mTest->NeedsRestart())
 	{
 	{
@@ -2059,9 +2082,8 @@ bool SamplesApp::UpdateFrame(float inDeltaTime)
 			return true;
 			return true;
 
 
 		case EKey::N:
 		case EKey::N:
-			if (!mTestsToRun.empty())
-				NextTest();
-			break;
+			NextTest();
+			return true;
 
 
 	#ifdef JPH_DEBUG_RENDERER
 	#ifdef JPH_DEBUG_RENDERER
 		case EKey::H:
 		case EKey::H:
@@ -2520,10 +2542,6 @@ void SamplesApp::StepPhysics(JobSystem *inJobSystem)
 		JPH_PROFILE("PostPhysicsUpdate");
 		JPH_PROFILE("PostPhysicsUpdate");
 		mTest->PostPhysicsUpdate(delta_time);
 		mTest->PostPhysicsUpdate(delta_time);
 	}
 	}
-
-	// Decrement number of frames to show the description
-	if (mShowDescription > 0)
-		--mShowDescription;
 }
 }
 
 
 void SamplesApp::SaveState(StateRecorderImpl &inStream)
 void SamplesApp::SaveState(StateRecorderImpl &inStream)

+ 1 - 2
Samples/SamplesApp.h

@@ -121,10 +121,9 @@ private:
 	int						mShowDescription = 0;										// If > 0, render the description of the test
 	int						mShowDescription = 0;										// If > 0, render the description of the test
 
 
 	// Automatic cycling through tests
 	// Automatic cycling through tests
-	Array<const RTTI *>		mTestsToRun;												// The list of tests that are still waiting to be run
+	bool					mIsRunningAllTests = false;									// If the user selected the 'Run All Tests' option
 	float					mTestTimeLeft = -1.0f;										// How many seconds the test is still supposed to run
 	float					mTestTimeLeft = -1.0f;										// How many seconds the test is still supposed to run
 	bool					mExitAfterRunningTests = false;								// When true, the application will quit when mTestsToRun becomes empty
 	bool					mExitAfterRunningTests = false;								// When true, the application will quit when mTestsToRun becomes empty
-	UITextButton *			mNextTestButton = nullptr;									// Button that activates the next test when we're running all tests
 
 
 	// Test settings
 	// Test settings
 	bool					mInstallContactListener = false;							// When true, the contact listener is installed the next time the test is reset
 	bool					mInstallContactListener = false;							// When true, the contact listener is installed the next time the test is reset