// Copyright (c) 2008-2023 the Urho3D project // License: MIT #include "AppState_ResultScreen.h" #include "AppStateManager.h" #include #include #include #include #include #include #include #include using namespace Urho3D; static const U3D::String RESULT_WINDOW_STR = "Result Window"; void AppState_ResultScreen::OnEnter() { assert(!scene_); LoadSceneXml("99_Benchmark/Scenes/ResultScreen.xml"); GetSubsystem()->SetMouseVisible(true); SetupViewport(); SubscribeToEvent(scene_, E_SCENEUPDATE, URHO3D_HANDLER(AppState_ResultScreen, HandleSceneUpdate)); fpsCounter_.Clear(); ShowResultWindow(); } void AppState_ResultScreen::OnLeave() { DestroyViewport(); DestroyResultWindow(); scene_ = nullptr; } void AppState_ResultScreen::HandleSceneUpdate(StringHash eventType, VariantMap& eventData) { float timeStep = eventData[SceneUpdate::P_TIMESTEP].GetFloat(); fpsCounter_.Update(timeStep); UpdateCurrentFpsElement(); Input* input = GetSubsystem(); if (input->GetKeyDown(KEY_ESCAPE) || input->GetKeyDown(KEY_RETURN) || input->GetKeyDown(KEY_KP_ENTER)) GetSubsystem()->SetRequiredAppStateId(APPSTATEID_MAINSCREEN); } void AppState_ResultScreen::ShowResultWindow() { UIElement* root = GetSubsystem()->GetRoot(); Window* window = root->CreateChild(RESULT_WINDOW_STR); window->SetStyleAuto(); window->SetLayout(LM_VERTICAL, 6, IntRect(6, 6, 6, 6)); window->SetAlignment(HA_CENTER, VA_CENTER); Text* windowTitle = window->CreateChild(); windowTitle->SetStyleAuto(); windowTitle->SetText("Result"); AppStateManager* appStateManager = GetSubsystem(); AppStateId prevAppStateId = appStateManager->GetPreviousAppStateId(); const String& benchmarkName = appStateManager->GetName(prevAppStateId); const FpsCounter& benchmarkResult = appStateManager->GetResult(prevAppStateId); Text* resultText = window->CreateChild(); resultText->SetStyleAuto(); resultText->SetText(benchmarkName + ": " + String(benchmarkResult.GetResultFps()) + " FPS (min: " + String(benchmarkResult.GetResultMinFps()) + ", max: " + String(benchmarkResult.GetResultMaxFps()) + ")"); Button* okButton = window->CreateChild