ScriptManager.cpp 63 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <Automation/ScriptManager.h>
  9. #include <Automation/ScriptableImGui.h>
  10. #include <SampleComponentManagerBus.h>
  11. #include <Atom/RPI.Reflect/Asset/AssetUtils.h>
  12. #include <Atom/RPI.Public/RPISystemInterface.h>
  13. #include <Atom/Component/DebugCamera/CameraComponent.h>
  14. #include <Atom/Component/DebugCamera/NoClipControllerComponent.h>
  15. #include <Atom/Component/DebugCamera/ArcBallControllerComponent.h>
  16. #include <Atom/Feature/ImGui/SystemBus.h>
  17. #include <Atom/RPI.Reflect/Asset/AssetUtils.h>
  18. #include <AzCore/Component/Entity.h>
  19. #include <AzCore/Script/ScriptContext.h>
  20. #include <AzCore/Script/ScriptSystemBus.h>
  21. #include <AzCore/Script/ScriptAsset.h>
  22. #include <AzCore/Math/MathReflection.h>
  23. #include <AzCore/Console/IConsole.h>
  24. #include <AzFramework/API/ApplicationAPI.h>
  25. #include <AzFramework/Components/ConsoleBus.h>
  26. #include <AzFramework/IO/LocalFileIO.h>
  27. #include <AzFramework/Windowing/WindowBus.h>
  28. #include <AtomSampleViewerRequestBus.h>
  29. #include <Utils/Utils.h>
  30. namespace AtomSampleViewer
  31. {
  32. ScriptManager* ScriptManager::s_instance = nullptr;
  33. ScriptManager::ScriptManager()
  34. : m_scriptBrowser("@user@/lua_script_browser.xml")
  35. {
  36. }
  37. void ScriptManager::Activate()
  38. {
  39. AZ_Assert(s_instance == nullptr, "ScriptManager is already activated");
  40. s_instance = this;
  41. ScriptableImGui::Create();
  42. m_scriptContext = AZStd::make_unique<AZ::ScriptContext>();
  43. m_sriptBehaviorContext = AZStd::make_unique<AZ::BehaviorContext>();
  44. ReflectScriptContext(m_sriptBehaviorContext.get());
  45. m_scriptContext->BindTo(m_sriptBehaviorContext.get());
  46. m_scriptBrowser.SetFilter([](const AZ::Data::AssetInfo& assetInfo)
  47. {
  48. return AzFramework::StringFunc::EndsWith(assetInfo.m_relativePath, ".bv.luac");
  49. });
  50. m_scriptBrowser.Activate();
  51. ScriptRepeaterRequestBus::Handler::BusConnect();
  52. ScriptRunnerRequestBus::Handler::BusConnect();
  53. m_imageComparisonOptions.Activate();
  54. }
  55. void ScriptManager::Deactivate()
  56. {
  57. s_instance = nullptr;
  58. m_scriptContext = nullptr;
  59. m_sriptBehaviorContext = nullptr;
  60. m_scriptBrowser.Deactivate();
  61. ScriptableImGui::Destory();
  62. m_imageComparisonOptions.Deactivate();
  63. ScriptRunnerRequestBus::Handler::BusDisconnect();
  64. ScriptRepeaterRequestBus::Handler::BusDisconnect();
  65. AZ::Debug::CameraControllerNotificationBus::Handler::BusDisconnect();
  66. }
  67. void ScriptManager::SetCameraEntity(AZ::Entity* cameraEntity)
  68. {
  69. AZ::Debug::CameraControllerNotificationBus::Handler::BusDisconnect();
  70. m_cameraEntity = cameraEntity;
  71. AZ::Debug::CameraControllerNotificationBus::Handler::BusConnect(m_cameraEntity->GetId());
  72. }
  73. void ScriptManager::PauseScript()
  74. {
  75. PauseScriptWithTimeout(DefaultPauseTimeout);
  76. }
  77. void ScriptManager::PauseScriptWithTimeout(float timeout)
  78. {
  79. m_scriptPaused = true;
  80. m_scriptPauseTimeout = AZ::GetMax(timeout, m_scriptPauseTimeout);
  81. }
  82. void ScriptManager::ResumeScript()
  83. {
  84. AZ_Warning("Automation", m_scriptPaused, "Script is not paused");
  85. m_scriptPaused = false;
  86. }
  87. void ScriptManager::ReportScriptError([[maybe_unused]] const AZStd::string& message)
  88. {
  89. AZ_Error("Automation", false, "Script: %s", message.c_str());
  90. }
  91. void ScriptManager::ReportScriptWarning([[maybe_unused]] const AZStd::string& message)
  92. {
  93. AZ_Warning("Automation", false, "Script: %s", message.c_str());
  94. }
  95. void ScriptManager::ReportScriptableAction([[maybe_unused]] AZStd::string_view scriptCommand)
  96. {
  97. AZ_TracePrintf("Automation", "Scriptable Action: %.*s\n", AZ_STRING_ARG(scriptCommand));
  98. }
  99. void ScriptManager::ImageComparisonOptions::Activate()
  100. {
  101. m_configAsset = AZ::RPI::AssetUtils::LoadAssetByProductPath<AZ::RPI::AnyAsset>("config/ImageComparisonConfig.azasset", AZ::RPI::AssetUtils::TraceLevel::Assert);
  102. if (m_configAsset)
  103. {
  104. AZ::Data::AssetBus::Handler::BusConnect(m_configAsset.GetId());
  105. OnAssetReloaded(m_configAsset);
  106. }
  107. }
  108. void ScriptManager::ImageComparisonOptions::Deactivate()
  109. {
  110. m_configAsset.Release();
  111. ResetImGuiSettings();
  112. AZ::Data::AssetBus::Handler::BusDisconnect();
  113. }
  114. ImageComparisonToleranceLevel* ScriptManager::ImageComparisonOptions::FindToleranceLevel(const AZStd::string& name, bool allowLevelAdjustment)
  115. {
  116. size_t foundIndex = m_config.m_toleranceLevels.size();
  117. for (size_t i = 0; i < m_config.m_toleranceLevels.size(); ++i)
  118. {
  119. if (m_config.m_toleranceLevels[i].m_name == name)
  120. {
  121. foundIndex = i;
  122. break;
  123. }
  124. }
  125. if (foundIndex == m_config.m_toleranceLevels.size())
  126. {
  127. return nullptr;
  128. }
  129. if (allowLevelAdjustment)
  130. {
  131. int adjustedIndex = aznumeric_cast<int>(foundIndex);
  132. adjustedIndex += m_toleranceAdjustment;
  133. adjustedIndex = AZ::GetClamp(adjustedIndex, 0, aznumeric_cast<int>(m_config.m_toleranceLevels.size()) - 1);
  134. foundIndex = aznumeric_cast<size_t>(adjustedIndex);
  135. }
  136. return &m_config.m_toleranceLevels[foundIndex];
  137. }
  138. const AZStd::vector<ImageComparisonToleranceLevel>& ScriptManager::ImageComparisonOptions::GetAvailableToleranceLevels() const
  139. {
  140. return m_config.m_toleranceLevels;
  141. }
  142. void ScriptManager::ImageComparisonOptions::SelectToleranceLevel(const AZStd::string& name, bool allowLevelAdjustment)
  143. {
  144. if (m_selectedOverrideSetting == OverrideSetting_ScriptControlled)
  145. {
  146. ImageComparisonToleranceLevel* level = FindToleranceLevel(name, allowLevelAdjustment);
  147. if (level)
  148. {
  149. m_currentToleranceLevel = level;
  150. }
  151. else
  152. {
  153. ReportScriptError(AZStd::string::format("ImageComparisonToleranceLevel '%s' not found.", name.c_str()));
  154. }
  155. }
  156. }
  157. void ScriptManager::ImageComparisonOptions::SelectToleranceLevel(ImageComparisonToleranceLevel* level)
  158. {
  159. if (nullptr == level)
  160. {
  161. m_currentToleranceLevel = level;
  162. return;
  163. }
  164. else
  165. {
  166. SelectToleranceLevel(level->m_name);
  167. AZ_Assert(GetCurrentToleranceLevel() == level, "Wrong ImageComparisonToleranceLevel pointer used");
  168. }
  169. }
  170. ImageComparisonToleranceLevel* ScriptManager::ImageComparisonOptions::GetCurrentToleranceLevel()
  171. {
  172. return m_currentToleranceLevel;
  173. }
  174. bool ScriptManager::ImageComparisonOptions::IsScriptControlled() const
  175. {
  176. return m_selectedOverrideSetting == OverrideSetting_ScriptControlled;
  177. }
  178. bool ScriptManager::ImageComparisonOptions::IsLevelAdjusted() const
  179. {
  180. return m_toleranceAdjustment != 0;
  181. }
  182. void ScriptManager::ImageComparisonOptions::DrawImGuiSettings()
  183. {
  184. ImGui::Text("Tolerance");
  185. ImGui::Indent();
  186. if (ImGui::Combo("Level",
  187. &m_selectedOverrideSetting,
  188. m_overrideSettings.data(),
  189. aznumeric_cast<int>(m_overrideSettings.size())))
  190. {
  191. if (m_selectedOverrideSetting == OverrideSetting_ScriptControlled)
  192. {
  193. m_currentToleranceLevel = nullptr;
  194. }
  195. else
  196. {
  197. m_currentToleranceLevel = &m_config.m_toleranceLevels[m_selectedOverrideSetting - 1];
  198. }
  199. }
  200. if (IsScriptControlled())
  201. {
  202. ImGui::InputInt("Level Adjustment", &m_toleranceAdjustment);
  203. }
  204. ImGui::Unindent();
  205. }
  206. void ScriptManager::ImageComparisonOptions::ResetImGuiSettings()
  207. {
  208. m_currentToleranceLevel = nullptr;
  209. m_selectedOverrideSetting = OverrideSetting_ScriptControlled;
  210. m_toleranceAdjustment = 0;
  211. }
  212. void ScriptManager::ImageComparisonOptions::OnAssetReloaded(AZ::Data::Asset<AZ::Data::AssetData> asset)
  213. {
  214. m_configAsset = asset;
  215. m_config = *m_configAsset->GetDataAs<ImageComparisonConfig>();
  216. m_overrideSettings.clear();
  217. m_overrideSettings.push_back("[Script-controlled]");
  218. for (size_t i = 0; i < m_config.m_toleranceLevels.size(); ++i)
  219. {
  220. AZ_Assert(i == 0 || m_config.m_toleranceLevels[i].m_threshold > m_config.m_toleranceLevels[i - 1].m_threshold, "Threshold values are not sequential");
  221. m_overrideSettings.push_back(m_config.m_toleranceLevels[i].m_name.c_str());
  222. }
  223. }
  224. void ScriptManager::TickImGui()
  225. {
  226. if (m_showScriptRunnerDialog)
  227. {
  228. ShowScriptRunnerDialog();
  229. }
  230. m_scriptReporter.TickImGui();
  231. if (m_testSuiteRunConfig.m_automatedRunEnabled)
  232. {
  233. if (m_testSuiteRunConfig.m_isStarted == false)
  234. {
  235. m_testSuiteRunConfig.m_isStarted = true;
  236. PrepareAndExecuteScript(m_testSuiteRunConfig.m_testSuitePath);
  237. }
  238. }
  239. }
  240. void ScriptManager::TickScript(float deltaTime)
  241. {
  242. // All actions must be consumed each frame. Otherwise, this indicates that a script is
  243. // scheduling ScriptableImGui actions for fields that don't exist.
  244. ScriptableImGui::CheckAllActionsConsumed();
  245. ScriptableImGui::ClearActions();
  246. // We delayed PopScript() until after the above CheckAllActionsConsumed(), so that any errors
  247. // reported by that function will be associated with the proper script.
  248. if (m_shouldPopScript)
  249. {
  250. m_scriptReporter.PopScript();
  251. m_shouldPopScript = false;
  252. }
  253. while (!m_scriptOperations.empty())
  254. {
  255. if (m_shouldPopScript)
  256. {
  257. // If we just finished executing a script, the remaining m_scriptOperations are for some other script.
  258. // We need to proceed to the next frame and allow that PopScript() to happen, otherwise any errors related
  259. // to subsequent operations would be reported against the prior script.
  260. break;
  261. }
  262. if (m_scriptPaused)
  263. {
  264. m_scriptPauseTimeout -= deltaTime;
  265. if (m_scriptPauseTimeout < 0)
  266. {
  267. AZ_Error("Automation", false, "Script pause timed out. Continuing...");
  268. m_scriptPaused = false;
  269. }
  270. else
  271. {
  272. break;
  273. }
  274. }
  275. if (m_waitForAssetTracker)
  276. {
  277. m_assetTrackingTimeout -= deltaTime;
  278. if (m_assetTrackingTimeout < 0)
  279. {
  280. auto incomplateAssetList = m_assetStatusTracker.GetIncompleteAssetList();
  281. AZStd::string incompleteAssetListString;
  282. AzFramework::StringFunc::Join(incompleteAssetListString, incomplateAssetList.begin(), incomplateAssetList.end(), "\n ");
  283. AZ_Error("Automation", false, "Script asset tracking timed out waiting for:\n %s \n Continuing...", incompleteAssetListString.c_str());
  284. m_waitForAssetTracker = false;
  285. }
  286. else if (m_assetStatusTracker.DidExpectedAssetsFinish())
  287. {
  288. AZ_Printf("Automation", "Asset Tracker finished with %f seconds remaining.", m_assetTrackingTimeout);
  289. m_waitForAssetTracker = false;
  290. }
  291. else
  292. {
  293. break;
  294. }
  295. }
  296. if (m_scriptIdleFrames > 0)
  297. {
  298. m_scriptIdleFrames--;
  299. break;
  300. }
  301. if (m_scriptIdleSeconds > 0)
  302. {
  303. m_scriptIdleSeconds -= deltaTime;
  304. break;
  305. }
  306. // Execute the next operation
  307. m_scriptOperations.front()();
  308. m_scriptOperations.pop();
  309. if (m_scriptOperations.empty())
  310. {
  311. m_doFinalScriptCleanup = true;
  312. }
  313. }
  314. if (m_shouldPopScript)
  315. {
  316. // We need to proceed for one more frame to do the last PopScript() before final cleanup
  317. return;
  318. }
  319. if (m_doFinalScriptCleanup)
  320. {
  321. bool frameCapturePending = false;
  322. SampleComponentManagerRequestBus::BroadcastResult(frameCapturePending, &SampleComponentManagerRequests::IsFrameCapturePending);
  323. if (!frameCapturePending && !m_isCapturePending)
  324. {
  325. AZ_Assert(m_scriptPaused == false, "Script manager is in an unexpected state.");
  326. AZ_Assert(m_scriptIdleFrames == 0, "Script manager is in an unexpected state.");
  327. AZ_Assert(m_scriptIdleSeconds <= 0.0f, "Script manager is in an unexpected state.");
  328. AZ_Assert(m_waitForAssetTracker == false, "Script manager is in an unexpected state.");
  329. AZ_Assert(!m_scriptReporter.HasActiveScript(), "Script manager is in an unexpected state.");
  330. AZ_Assert(m_executingScripts.size() == 0, "Script manager is in an unexpected state");
  331. m_assetStatusTracker.StopTracking();
  332. if (m_frameTimeIsLocked)
  333. {
  334. AZ::Interface<AZ::IConsole>::Get()->PerformCommand("t_frameTimeOverride 0");
  335. m_frameTimeIsLocked = false;
  336. }
  337. if (m_shouldRestoreViewportSize)
  338. {
  339. Utils::ResizeClientArea(m_savedViewportWidth, m_savedViewportHeight);
  340. m_shouldRestoreViewportSize = false;
  341. }
  342. // In case scripts were aborted while ImGui was temporarily hidden, show it again.
  343. SetShowImGui(true);
  344. m_scriptReporter.OpenReportDialog();
  345. m_shouldPopScript = false;
  346. m_doFinalScriptCleanup = false;
  347. if (m_testSuiteRunConfig.m_automatedRunEnabled && m_testSuiteRunConfig.m_closeOnTestScriptFinish)
  348. {
  349. m_testSuiteRunConfig.m_automatedRunEnabled = false;
  350. if (m_scriptReporter.HasErrorsAssertsInReport())
  351. {
  352. AtomSampleViewerRequestsBus::Broadcast(&AtomSampleViewerRequestsBus::Events::SetExitCode, 1);
  353. // Useful console logging for Hydra tests
  354. int failedTests = 0;
  355. for (const ScriptReporter::ScriptReport& testReport : m_scriptReporter.GetScriptReport())
  356. {
  357. if (testReport.m_assertCount > 0 || testReport.m_generalErrorCount > 0 || testReport.m_screenshotErrorCount > 0)
  358. {
  359. ++failedTests;
  360. AZ_Printf("AtomSampleViewer", "Test failure %s: asserts %u, general errors %u, screenshot failures %u\n", testReport.m_scriptAssetPath.c_str(),
  361. testReport.m_assertCount, testReport.m_generalErrorCount, testReport.m_screenshotErrorCount);
  362. }
  363. }
  364. AZ_Printf("AtomSampleViewer", "%d tests failed\n", failedTests);
  365. }
  366. AzFramework::ApplicationRequests::Bus::Broadcast(&AzFramework::ApplicationRequests::ExitMainLoop);
  367. }
  368. }
  369. }
  370. }
  371. void ScriptManager::OpenScriptRunnerDialog()
  372. {
  373. m_showScriptRunnerDialog = true;
  374. }
  375. void ScriptManager::RunMainTestSuite(const AZStd::string& suiteFilePath, bool exitOnTestEnd, int randomSeed)
  376. {
  377. m_testSuiteRunConfig.m_automatedRunEnabled = true;
  378. m_testSuiteRunConfig.m_testSuitePath = suiteFilePath;
  379. m_testSuiteRunConfig.m_closeOnTestScriptFinish = exitOnTestEnd;
  380. m_testSuiteRunConfig.m_randomSeed = randomSeed;
  381. }
  382. void ScriptManager::AbortScripts(const AZStd::string& reason)
  383. {
  384. m_scriptReporter.SetInvalidationMessage(reason);
  385. m_scriptOperations = {};
  386. m_executingScripts.clear();
  387. m_scriptPaused = false;
  388. m_scriptIdleFrames = 0;
  389. m_scriptIdleSeconds = 0.0f;
  390. m_waitForAssetTracker = false;
  391. while (m_scriptReporter.HasActiveScript())
  392. {
  393. m_scriptReporter.PopScript();
  394. }
  395. m_doFinalScriptCleanup = true;
  396. }
  397. void ScriptManager::ShowScriptRunnerDialog()
  398. {
  399. if (ImGui::Begin("Script Runner", &m_showScriptRunnerDialog))
  400. {
  401. auto drawAbortButton = [this](const char* uniqueId)
  402. {
  403. ImGui::PushID(uniqueId);
  404. if (ImGui::Button("Abort"))
  405. {
  406. AbortScripts("Script(s) manually aborted.");
  407. }
  408. ImGui::PopID();
  409. };
  410. // The main buttons are at the bottom, but show the Abort button at the top too, in case the window size is small.
  411. if (!m_scriptOperations.empty())
  412. {
  413. drawAbortButton("Button1");
  414. }
  415. ImGuiAssetBrowser::WidgetSettings assetBrowserSettings;
  416. assetBrowserSettings.m_labels.m_root = "Lua Scripts";
  417. m_scriptBrowser.Tick(assetBrowserSettings);
  418. AZStd::string selectedFileName = "<none>";
  419. AzFramework::StringFunc::Path::GetFullFileName(m_scriptBrowser.GetSelectedAssetPath().c_str(), selectedFileName);
  420. ImGui::LabelText("##SelectedScript", "Selected: %s", selectedFileName.c_str());
  421. ImGui::Separator();
  422. ImGui::Text("Settings");
  423. ImGui::Indent();
  424. ImGui::InputInt("Random Seed for Test Order Execution", &m_testSuiteRunConfig.m_randomSeed);
  425. m_imageComparisonOptions.DrawImGuiSettings();
  426. if (ImGui::Button("Reset"))
  427. {
  428. m_imageComparisonOptions.ResetImGuiSettings();
  429. }
  430. ImGui::Unindent();
  431. ImGui::Separator();
  432. if (ImGui::Button("Run"))
  433. {
  434. auto scriptAsset = m_scriptBrowser.GetSelectedAsset<AZ::ScriptAsset>();
  435. if (scriptAsset.GetId().IsValid())
  436. {
  437. PrepareAndExecuteScript(m_scriptBrowser.GetSelectedAssetPath());
  438. }
  439. }
  440. if (ImGui::Button("View Latest Results"))
  441. {
  442. m_scriptReporter.OpenReportDialog();
  443. }
  444. if (m_scriptOperations.size() > 0)
  445. {
  446. ImGui::LabelText("##RunningScript", "Running %zu operations...", m_scriptOperations.size());
  447. drawAbortButton("Button2");
  448. }
  449. }
  450. m_messageBox.TickPopup();
  451. ImGui::End();
  452. }
  453. void ScriptManager::PrepareAndExecuteScript(const AZStd::string& scriptFilePath)
  454. {
  455. ReportScriptableAction(AZStd::string::format("RunScript('%s')", scriptFilePath.c_str()));
  456. // Save the window size so we can restore it after running the script, in case the script calls ResizeViewport
  457. AzFramework::NativeWindowHandle defaultWindowHandle;
  458. AzFramework::WindowSize windowSize;
  459. AzFramework::WindowSystemRequestBus::BroadcastResult(defaultWindowHandle, &AzFramework::WindowSystemRequestBus::Events::GetDefaultWindowHandle);
  460. AzFramework::WindowRequestBus::EventResult(windowSize, defaultWindowHandle, &AzFramework::WindowRequests::GetClientAreaSize);
  461. m_savedViewportWidth = windowSize.m_width;
  462. m_savedViewportHeight = windowSize.m_height;
  463. if (m_savedViewportWidth == 0 || m_savedViewportHeight == 0)
  464. {
  465. AZ_Assert(false, "Could not get current window size");
  466. }
  467. else
  468. {
  469. m_shouldRestoreViewportSize = true;
  470. }
  471. // Setup the ScriptReporter to track and report the results
  472. m_scriptReporter.Reset();
  473. m_scriptReporter.SetAvailableToleranceLevels(m_imageComparisonOptions.GetAvailableToleranceLevels());
  474. if (m_imageComparisonOptions.IsLevelAdjusted())
  475. {
  476. m_scriptReporter.SetInvalidationMessage("Results are invalid because the tolerance level has been adjusted.");
  477. }
  478. else if (!m_imageComparisonOptions.IsScriptControlled())
  479. {
  480. m_scriptReporter.SetInvalidationMessage("Results are invalid because the tolerance level has been overridden.");
  481. }
  482. else
  483. {
  484. m_scriptReporter.SetInvalidationMessage("");
  485. }
  486. AZ_Assert(m_executingScripts.empty(), "There should be no active scripts at this point");
  487. ExecuteScript(scriptFilePath);
  488. }
  489. void ScriptManager::ExecuteScript(const AZStd::string& scriptFilePath)
  490. {
  491. AZ::Data::Asset<AZ::ScriptAsset> scriptAsset = AZ::RPI::AssetUtils::LoadAssetByProductPath<AZ::ScriptAsset>(scriptFilePath.c_str());
  492. if (!scriptAsset)
  493. {
  494. // Push an error operation on the back of the queue instead of reporting it immediately so it doesn't get lost
  495. // in front of a bunch of queued m_scriptOperations.
  496. Script_Error(AZStd::string::format("Could not find or load script asset '%s'.", scriptFilePath.c_str()));
  497. return;
  498. }
  499. if (s_instance->m_executingScripts.find(scriptAsset.GetId()) != s_instance->m_executingScripts.end())
  500. {
  501. Script_Error(AZStd::string::format("Calling script '%s' would likely cause an infinite loop and crash. Skipping.", scriptFilePath.c_str()));
  502. return;
  503. }
  504. if (s_instance->m_imageComparisonOptions.IsScriptControlled())
  505. {
  506. s_instance->m_imageComparisonOptions.SelectToleranceLevel(nullptr); // Clear the preset before each script to make sure the script is selecting it.
  507. }
  508. // Execute(script) will add commands to the m_scriptOperations. These should be considered part of their own test script, for reporting purposes.
  509. s_instance->m_scriptOperations.push([scriptFilePath]()
  510. {
  511. s_instance->m_scriptReporter.PushScript(scriptFilePath);
  512. }
  513. );
  514. s_instance->m_scriptOperations.push([scriptFilePath]()
  515. {
  516. AZ_Printf("Automation", "Running script '%s'...\n", scriptFilePath.c_str());
  517. }
  518. );
  519. s_instance->m_executingScripts.insert(scriptAsset.GetId());
  520. if (!s_instance->m_scriptContext->Execute(scriptAsset->GetScriptBuffer().data(), scriptFilePath.c_str(), scriptAsset->GetScriptBuffer().size()))
  521. {
  522. // Push an error operation on the back of the queue instead of reporting it immediately so it doesn't get lost
  523. // in front of a bunch of queued m_scriptOperations.
  524. Script_Error(AZStd::string::format("Error running script '%s'.", scriptAsset.ToString<AZStd::string>().c_str()));
  525. }
  526. s_instance->m_executingScripts.erase(scriptAsset.GetId());
  527. // Execute(script) will have added commands to the m_scriptOperations. When they finish, consider this test as completed, for reporting purposes.
  528. s_instance->m_scriptOperations.push([]()
  529. {
  530. // We don't call m_scriptReporter.PopScript() yet because some cleanup needs to happen in TickScript() on the next frame.
  531. AZ_Assert(!s_instance->m_shouldPopScript, "m_shouldPopScript is already true");
  532. s_instance->m_shouldPopScript = true;
  533. }
  534. );
  535. }
  536. void ScriptManager::OnCameraMoveEnded(AZ::TypeId controllerTypeId, uint32_t channels)
  537. {
  538. if (controllerTypeId == azrtti_typeid<AZ::Debug::ArcBallControllerComponent>())
  539. {
  540. if (channels & AZ::Debug::ArcBallControllerChannel_Center)
  541. {
  542. AZ::Vector3 center = AZ::Vector3::CreateZero();
  543. AZ::Debug::ArcBallControllerRequestBus::EventResult(center, m_cameraEntity->GetId(), &AZ::Debug::ArcBallControllerRequests::GetCenter);
  544. ReportScriptableAction(AZStd::string::format("ArcBallCameraController_SetCenter(Vector3(%f, %f, %f))", (float)center.GetX(), (float)center.GetY(), (float)center.GetZ()));
  545. }
  546. if (channels & AZ::Debug::ArcBallControllerChannel_Pan)
  547. {
  548. AZ::Vector3 pan = AZ::Vector3::CreateZero();
  549. AZ::Debug::ArcBallControllerRequestBus::EventResult(pan, m_cameraEntity->GetId(), &AZ::Debug::ArcBallControllerRequests::GetPan);
  550. ReportScriptableAction(AZStd::string::format("ArcBallCameraController_SetPan(Vector3(%f, %f, %f))", (float)pan.GetX(), (float)pan.GetY(), (float)pan.GetZ()));
  551. }
  552. if (channels & AZ::Debug::ArcBallControllerChannel_Heading)
  553. {
  554. float heading = 0.0;
  555. AZ::Debug::ArcBallControllerRequestBus::EventResult(heading, m_cameraEntity->GetId(), &AZ::Debug::ArcBallControllerRequests::GetHeading);
  556. ReportScriptableAction(AZStd::string::format("ArcBallCameraController_SetHeading(DegToRad(%f))", AZ::RadToDeg(heading)));
  557. }
  558. if (channels & AZ::Debug::ArcBallControllerChannel_Pitch)
  559. {
  560. float pitch = 0.0;
  561. AZ::Debug::ArcBallControllerRequestBus::EventResult(pitch, m_cameraEntity->GetId(), &AZ::Debug::ArcBallControllerRequests::GetPitch);
  562. ReportScriptableAction(AZStd::string::format("ArcBallCameraController_SetPitch(DegToRad(%f))", AZ::RadToDeg(pitch)));
  563. }
  564. if (channels & AZ::Debug::ArcBallControllerChannel_Distance)
  565. {
  566. float distance = 0.0;
  567. AZ::Debug::ArcBallControllerRequestBus::EventResult(distance, m_cameraEntity->GetId(), &AZ::Debug::ArcBallControllerRequests::GetDistance);
  568. ReportScriptableAction(AZStd::string::format("ArcBallCameraController_SetDistance(%f)", distance));
  569. }
  570. }
  571. if (controllerTypeId == azrtti_typeid<AZ::Debug::NoClipControllerComponent>())
  572. {
  573. if (channels & AZ::Debug::NoClipControllerChannel_Position)
  574. {
  575. AZ::Vector3 position = AZ::Vector3::CreateZero();
  576. AZ::Debug::NoClipControllerRequestBus::EventResult(position, m_cameraEntity->GetId(), &AZ::Debug::NoClipControllerRequests::GetPosition);
  577. ReportScriptableAction(AZStd::string::format("NoClipCameraController_SetPosition(Vector3(%f, %f, %f))", (float)position.GetX(), (float)position.GetY(), (float)position.GetZ()));
  578. }
  579. if (channels & AZ::Debug::NoClipControllerChannel_Orientation)
  580. {
  581. float heading = 0.0;
  582. AZ::Debug::NoClipControllerRequestBus::EventResult(heading, m_cameraEntity->GetId(), &AZ::Debug::NoClipControllerRequests::GetHeading);
  583. ReportScriptableAction(AZStd::string::format("NoClipCameraController_SetHeading(DegToRad(%f))", AZ::RadToDeg(heading)));
  584. float pitch = 0.0;
  585. AZ::Debug::NoClipControllerRequestBus::EventResult(pitch, m_cameraEntity->GetId(), &AZ::Debug::NoClipControllerRequests::GetPitch);
  586. ReportScriptableAction(AZStd::string::format("NoClipCameraController_SetPitch(DegToRad(%f))", AZ::RadToDeg(pitch)));
  587. }
  588. if (channels & AZ::Debug::NoClipControllerChannel_Fov)
  589. {
  590. float fov = 0.0;
  591. AZ::Debug::NoClipControllerRequestBus::EventResult(fov, m_cameraEntity->GetId(), &AZ::Debug::NoClipControllerRequests::GetFov);
  592. ReportScriptableAction(AZStd::string::format("NoClipCameraController_SetFov(DegToRad(%f))", AZ::RadToDeg(fov)));
  593. }
  594. }
  595. }
  596. void ScriptManager::ReflectScriptContext(AZ::BehaviorContext* behaviorContext)
  597. {
  598. AZ::MathReflect(behaviorContext);
  599. // Utilities...
  600. behaviorContext->Method("RunScript", &Script_RunScript);
  601. behaviorContext->Method("Error", &Script_Error);
  602. behaviorContext->Method("Warning", &Script_Warning);
  603. behaviorContext->Method("Print", &Script_Print);
  604. behaviorContext->Method("IdleFrames", &Script_IdleFrames);
  605. behaviorContext->Method("IdleSeconds", &Script_IdleSeconds);
  606. behaviorContext->Method("LockFrameTime", &Script_LockFrameTime);
  607. behaviorContext->Method("UnlockFrameTime", &Script_UnlockFrameTime);
  608. behaviorContext->Method("ResizeViewport", &Script_ResizeViewport);
  609. behaviorContext->Method("SetShowImGui", &Script_SetShowImGui);
  610. behaviorContext->Method("ExecuteConsoleCommand", &Script_ExecuteConsoleCommand);
  611. // Utilities returning data (these special functions do return data because they don't read dynamic state)...
  612. behaviorContext->Method("ResolvePath", &Script_ResolvePath);
  613. behaviorContext->Method("NormalizePath", &Script_NormalizePath);
  614. behaviorContext->Method("DegToRad", &Script_DegToRad);
  615. behaviorContext->Method("GetRenderApiName", &Script_GetRenderApiName);
  616. behaviorContext->Method("GetRandomTestSeed", &Script_GetRandomTestSeed);
  617. // Samples...
  618. behaviorContext->Method("OpenSample", &Script_OpenSample);
  619. behaviorContext->Method("SetImguiValue", &Script_SetImguiValue);
  620. // Debug profilers...
  621. behaviorContext->Method("ShowTool", &Script_ShowTool);
  622. // Screenshots...
  623. behaviorContext->Method("SelectImageComparisonToleranceLevel", &Script_SelectImageComparisonToleranceLevel);
  624. behaviorContext->Method("CaptureScreenshot", &Script_CaptureScreenshot);
  625. behaviorContext->Method("CaptureScreenshotWithImGui", &Script_CaptureScreenshotWithImGui);
  626. behaviorContext->Method("CaptureScreenshotWithPreview", &Script_CaptureScreenshotWithPreview);
  627. behaviorContext->Method("CapturePassAttachment", &Script_CapturePassAttachment);
  628. // Profiling data...
  629. behaviorContext->Method("CapturePassTimestamp", &Script_CapturePassTimestamp);
  630. behaviorContext->Method("CaptureCpuFrameTime", &Script_CaptureCpuFrameTime);
  631. behaviorContext->Method("CapturePassPipelineStatistics", &Script_CapturePassPipelineStatistics);
  632. behaviorContext->Method("CaptureCpuProfilingStatistics", &Script_CaptureCpuProfilingStatistics);
  633. behaviorContext->Method("CaptureBenchmarkMetadata", &Script_CaptureBenchmarkMetadata);
  634. // Camera...
  635. behaviorContext->Method("ArcBallCameraController_SetCenter", &Script_ArcBallCameraController_SetCenter);
  636. behaviorContext->Method("ArcBallCameraController_SetPan", &Script_ArcBallCameraController_SetPan);
  637. behaviorContext->Method("ArcBallCameraController_SetDistance", &Script_ArcBallCameraController_SetDistance);
  638. behaviorContext->Method("ArcBallCameraController_SetHeading", &Script_ArcBallCameraController_SetHeading);
  639. behaviorContext->Method("ArcBallCameraController_SetPitch", &Script_ArcBallCameraController_SetPitch);
  640. behaviorContext->Method("NoClipCameraController_SetPosition", &Script_NoClipCameraController_SetPosition);
  641. behaviorContext->Method("NoClipCameraController_SetHeading", &Script_NoClipCameraController_SetHeading);
  642. behaviorContext->Method("NoClipCameraController_SetPitch", &Script_NoClipCameraController_SetPitch);
  643. behaviorContext->Method("NoClipCameraController_SetFov", &Script_NoClipCameraController_SetFov);
  644. // Asset System...
  645. AZ::BehaviorParameterOverrides expectedCountDetails = {"expectedCount", "Expected number of asset jobs; default=1", aznew AZ::BehaviorDefaultValue(1u)};
  646. const AZStd::array<AZ::BehaviorParameterOverrides, 2> assetTrackingExpectAssetArgs = {{ AZ::BehaviorParameterOverrides{}, expectedCountDetails }};
  647. behaviorContext->Method("AssetTracking_Start", &Script_AssetTracking_Start);
  648. behaviorContext->Method("AssetTracking_ExpectAsset", &Script_AssetTracking_ExpectAsset, assetTrackingExpectAssetArgs);
  649. behaviorContext->Method("AssetTracking_IdleUntilExpectedAssetsFinish", &Script_AssetTracking_IdleUntilExpectedAssetsFinish);
  650. behaviorContext->Method("AssetTracking_Stop", &Script_AssetTracking_Stop);
  651. }
  652. void ScriptManager::Script_Error(const AZStd::string& message)
  653. {
  654. auto func = [message]()
  655. {
  656. ReportScriptError(message.c_str());
  657. };
  658. s_instance->m_scriptOperations.push(AZStd::move(func));
  659. }
  660. void ScriptManager::Script_Warning(const AZStd::string& message)
  661. {
  662. auto func = [message]()
  663. {
  664. ReportScriptWarning(message.c_str());
  665. };
  666. s_instance->m_scriptOperations.push(AZStd::move(func));
  667. }
  668. void ScriptManager::Script_Print(const AZStd::string& message)
  669. {
  670. auto func = [message]()
  671. {
  672. AZ_TracePrintf("Automation", "Script: %s\n", message.c_str());
  673. };
  674. s_instance->m_scriptOperations.push(AZStd::move(func));
  675. }
  676. AZStd::string ScriptManager::Script_ResolvePath(const AZStd::string& path)
  677. {
  678. return Utils::ResolvePath(path);
  679. }
  680. AZStd::string ScriptManager::Script_NormalizePath(const AZStd::string& path)
  681. {
  682. AZStd::string normalizedPath = path;
  683. AzFramework::StringFunc::Path::Normalize(normalizedPath);
  684. return normalizedPath;
  685. }
  686. void ScriptManager::Script_OpenSample(const AZStd::string& sampleName)
  687. {
  688. auto operation = [sampleName]()
  689. {
  690. AZ_DEBUG_STATIC_MEMEBER(instance, s_instance);
  691. if (sampleName.empty())
  692. {
  693. SampleComponentManagerRequestBus::Broadcast(&SampleComponentManagerRequests::Reset);
  694. }
  695. else
  696. {
  697. bool foundSample = false;
  698. SampleComponentManagerRequestBus::BroadcastResult(foundSample, &SampleComponentManagerRequests::OpenSample, sampleName);
  699. if (foundSample)
  700. {
  701. // Samples need a few frames to initialize before consuming actions from ScriptableImGui,
  702. // so we need to wait before letting the script schedule ScriptableImGui actions.
  703. // They need 1 frame to activate, 1 frame to start ticking, and 1 frame to guarantee
  704. // that a sample OnTick occurs before a ScriptManager::OnTick. We schedule
  705. // a few extra just in case.
  706. AZ_Assert(s_instance->m_scriptIdleFrames == 0, "m_scriptIdleFrames is being stomped");
  707. s_instance->m_scriptIdleFrames = 6;
  708. }
  709. }
  710. };
  711. s_instance->m_scriptOperations.push(AZStd::move(operation));
  712. }
  713. void ScriptManager::Script_ShowTool(const AZStd::string& toolName, bool enable)
  714. {
  715. auto operation = [toolName, enable]()
  716. {
  717. bool foundTool = false;
  718. SampleComponentManagerRequestBus::BroadcastResult(foundTool, &SampleComponentManagerRequests::ShowTool, toolName, enable);
  719. AZ_Warning("ScriptManager", foundTool, "Can't find [%s] tool", toolName.c_str());
  720. };
  721. s_instance->m_scriptOperations.push(AZStd::move(operation));
  722. }
  723. void ScriptManager::Script_RunScript(const AZStd::string& scriptFilePath)
  724. {
  725. // Unlike other Script_ callback functions, we process immediately instead of pushing onto the m_scriptOperations queue.
  726. // This function is special because running the script is what adds more commands onto the m_scriptOperations queue.
  727. s_instance->ExecuteScript(scriptFilePath);
  728. }
  729. void ScriptManager::Script_IdleFrames(int numFrames)
  730. {
  731. auto operation = [numFrames]()
  732. {
  733. AZ_DEBUG_STATIC_MEMEBER(instance, s_instance);
  734. AZ_Assert(s_instance->m_scriptIdleFrames == 0, "m_scriptIdleFrames is being stomped");
  735. s_instance->m_scriptIdleFrames = numFrames;
  736. };
  737. s_instance->m_scriptOperations.push(AZStd::move(operation));
  738. }
  739. void ScriptManager::Script_IdleSeconds(float numSeconds)
  740. {
  741. auto operation = [numSeconds]()
  742. {
  743. AZ_DEBUG_STATIC_MEMEBER(instance, s_instance);
  744. s_instance->m_scriptIdleSeconds = numSeconds;
  745. };
  746. s_instance->m_scriptOperations.push(AZStd::move(operation));
  747. }
  748. void ScriptManager::Script_LockFrameTime(float seconds)
  749. {
  750. auto operation = [seconds]()
  751. {
  752. AZ_DEBUG_STATIC_MEMEBER(instance, s_instance);
  753. AZ::Interface<AZ::IConsole>::Get()->PerformCommand(AZStd::string::format("t_frameTimeOverride %f", seconds).c_str());
  754. s_instance->m_frameTimeIsLocked = true;
  755. };
  756. s_instance->m_scriptOperations.push(AZStd::move(operation));
  757. }
  758. void ScriptManager::Script_UnlockFrameTime()
  759. {
  760. auto operation = []()
  761. {
  762. AZ_DEBUG_STATIC_MEMEBER(instance, s_instance);
  763. AZ::Interface<AZ::IConsole>::Get()->PerformCommand("t_frameTimeOverride 0");
  764. s_instance->m_frameTimeIsLocked = false;
  765. };
  766. s_instance->m_scriptOperations.push(AZStd::move(operation));
  767. }
  768. void ScriptManager::Script_SetImguiValue(AZ::ScriptDataContext& dc)
  769. {
  770. if (dc.GetNumArguments() != 2)
  771. {
  772. ReportScriptError("Wrong number of arguments for SetImguiValue");
  773. return;
  774. }
  775. if (!dc.IsString(0))
  776. {
  777. ReportScriptError("SetImguiValue first argument must be a string");
  778. return;
  779. }
  780. const char* fieldName = nullptr;
  781. dc.ReadArg(0, fieldName);
  782. AZStd::string fieldNameString = fieldName; // Because the lambda will need to capture a copy of something, not a pointer
  783. if (dc.IsBoolean(1))
  784. {
  785. bool value = false;
  786. dc.ReadArg(1, value);
  787. auto func = [fieldNameString, value]()
  788. {
  789. ScriptableImGui::SetBool(fieldNameString, value);
  790. };
  791. s_instance->m_scriptOperations.push(AZStd::move(func));
  792. }
  793. else if (dc.IsNumber(1))
  794. {
  795. float value = 0.0f;
  796. dc.ReadArg(1, value);
  797. auto func = [fieldNameString, value]()
  798. {
  799. ScriptableImGui::SetNumber(fieldNameString, value);
  800. };
  801. s_instance->m_scriptOperations.push(AZStd::move(func));
  802. }
  803. else if (dc.IsString(1))
  804. {
  805. const char* value = nullptr;
  806. dc.ReadArg(1, value);
  807. AZStd::string valueString = value; // Because the lambda will need to capture a copy of something, not a pointer
  808. auto func = [fieldNameString, valueString]()
  809. {
  810. ScriptableImGui::SetString(fieldNameString, valueString);
  811. };
  812. s_instance->m_scriptOperations.push(AZStd::move(func));
  813. }
  814. else if (dc.IsClass<AZ::Vector3>(1))
  815. {
  816. AZ::Vector3 value = AZ::Vector3::CreateZero();
  817. dc.ReadArg(1, value);
  818. auto func = [fieldNameString, value]()
  819. {
  820. ScriptableImGui::SetVector(fieldNameString, value);
  821. };
  822. s_instance->m_scriptOperations.push(AZStd::move(func));
  823. }
  824. else if (dc.IsClass<AZ::Vector2>(1))
  825. {
  826. AZ::Vector2 value = AZ::Vector2::CreateZero();
  827. dc.ReadArg(1, value);
  828. auto func = [fieldNameString, value]()
  829. {
  830. ScriptableImGui::SetVector(fieldNameString, value);
  831. };
  832. s_instance->m_scriptOperations.push(AZStd::move(func));
  833. }
  834. }
  835. void ScriptManager::Script_ResizeViewport(int width, int height)
  836. {
  837. auto operation = [width,height]()
  838. {
  839. if (Utils::SupportsResizeClientArea())
  840. {
  841. Utils::ResizeClientArea(width, height);
  842. }
  843. else
  844. {
  845. s_instance->ReportScriptError("ResizeViewport() is not supported on this platform");
  846. }
  847. };
  848. s_instance->m_scriptOperations.push(AZStd::move(operation));
  849. }
  850. void ScriptManager::Script_ExecuteConsoleCommand(const AZStd::string& command)
  851. {
  852. auto operation = [command]()
  853. {
  854. AzFramework::ConsoleRequestBus::Broadcast(&AzFramework::ConsoleRequests::ExecuteConsoleCommand, command.c_str());
  855. };
  856. s_instance->m_scriptOperations.push(AZStd::move(operation));
  857. }
  858. void ScriptManager::SetShowImGui(bool show)
  859. {
  860. m_prevShowImGui = m_showImGui;
  861. if (show)
  862. {
  863. AZ::Render::ImGuiSystemRequestBus::Broadcast(&AZ::Render::ImGuiSystemRequestBus::Events::ShowAllImGuiPasses);
  864. }
  865. else
  866. {
  867. AZ::Render::ImGuiSystemRequestBus::Broadcast(&AZ::Render::ImGuiSystemRequestBus::Events::HideAllImGuiPasses);
  868. }
  869. m_showImGui = show;
  870. }
  871. void ScriptManager::Script_SetShowImGui(bool show)
  872. {
  873. auto operation = [show]()
  874. {
  875. s_instance->SetShowImGui(show);
  876. };
  877. s_instance->m_scriptOperations.push(AZStd::move(operation));
  878. }
  879. bool ScriptManager::PrepareForScreenCapture(const AZStd::string& path)
  880. {
  881. if (!Utils::IsFileUnderFolder(Utils::ResolvePath(path), ScreenshotPaths::GetScreenshotsFolder(true)))
  882. {
  883. // The main reason we require screenshots to be in a specific folder is to ensure we don't delete or replace some other important file.
  884. ReportScriptError(AZStd::string::format(
  885. "Screenshots must be captured under the '%s' folder. Attempted to save screenshot to '%s'.",
  886. ScreenshotPaths::GetScreenshotsFolder(false).c_str(), path.c_str()));
  887. return false;
  888. }
  889. // Delete the file if it already exists because if the screen capture fails, we don't want to do a screenshot comparison test using an old screenshot.
  890. if (AZ::IO::LocalFileIO::GetInstance()->Exists(path.c_str()) && !AZ::IO::LocalFileIO::GetInstance()->Remove(path.c_str()))
  891. {
  892. ReportScriptError(AZStd::string::format("Failed to delete existing screenshot file '%s'.", path.c_str()));
  893. return false;
  894. }
  895. s_instance->m_scriptReporter.AddScreenshotTest(path);
  896. s_instance->m_isCapturePending = true;
  897. s_instance->AZ::Render::FrameCaptureNotificationBus::Handler::BusConnect();
  898. s_instance->PauseScript();
  899. return true;
  900. }
  901. void ScriptManager::Script_SelectImageComparisonToleranceLevel(const AZStd::string& presetName)
  902. {
  903. auto operation = [presetName]()
  904. {
  905. s_instance->m_imageComparisonOptions.SelectToleranceLevel(presetName);
  906. };
  907. s_instance->m_scriptOperations.push(AZStd::move(operation));
  908. }
  909. void ScriptManager::Script_CaptureScreenshot(const AZStd::string& filePath)
  910. {
  911. Script_SetShowImGui(false);
  912. auto operation = [filePath]()
  913. {
  914. // Note this will pause the script until the capture is complete
  915. if (PrepareForScreenCapture(filePath))
  916. {
  917. AZ::Render::FrameCaptureRequestBus::Broadcast(&AZ::Render::FrameCaptureRequestBus::Events::CaptureScreenshot, filePath);
  918. }
  919. };
  920. s_instance->m_scriptOperations.push(AZStd::move(operation));
  921. s_instance->m_scriptOperations.push([]()
  922. {
  923. s_instance->m_scriptReporter.CheckLatestScreenshot(s_instance->m_imageComparisonOptions.GetCurrentToleranceLevel());
  924. });
  925. // restore imgui show/hide
  926. s_instance->m_scriptOperations.push([]()
  927. {
  928. s_instance->SetShowImGui(s_instance->m_prevShowImGui);
  929. });
  930. }
  931. void ScriptManager::Script_CaptureScreenshotWithImGui(const AZStd::string& filePath)
  932. {
  933. Script_SetShowImGui(true);
  934. auto operation = [filePath]()
  935. {
  936. // Note this will pause the script until the capture is complete
  937. if (PrepareForScreenCapture(filePath))
  938. {
  939. AZ::Render::FrameCaptureRequestBus::Broadcast(&AZ::Render::FrameCaptureRequestBus::Events::CaptureScreenshot, filePath);
  940. }
  941. };
  942. s_instance->m_scriptOperations.push(AZStd::move(operation));
  943. s_instance->m_scriptOperations.push([]()
  944. {
  945. s_instance->m_scriptReporter.CheckLatestScreenshot(s_instance->m_imageComparisonOptions.GetCurrentToleranceLevel());
  946. });
  947. // restore imgui show/hide
  948. s_instance->m_scriptOperations.push([]()
  949. {
  950. s_instance->SetShowImGui(s_instance->m_prevShowImGui);
  951. });
  952. }
  953. void ScriptManager::Script_CaptureScreenshotWithPreview(const AZStd::string& filePath)
  954. {
  955. auto operation = [filePath]()
  956. {
  957. // Note this will pause the script until the capture is complete
  958. if (PrepareForScreenCapture(filePath))
  959. {
  960. AZ::Render::FrameCaptureRequestBus::Broadcast(&AZ::Render::FrameCaptureRequestBus::Events::CaptureScreenshotWithPreview, filePath);
  961. }
  962. };
  963. s_instance->m_scriptOperations.push(AZStd::move(operation));
  964. s_instance->m_scriptOperations.push([]()
  965. {
  966. s_instance->m_scriptReporter.CheckLatestScreenshot(s_instance->m_imageComparisonOptions.GetCurrentToleranceLevel());
  967. });
  968. }
  969. void ScriptManager::Script_CapturePassAttachment(AZ::ScriptDataContext& dc)
  970. {
  971. if (dc.GetNumArguments() != 3 && dc.GetNumArguments() != 4)
  972. {
  973. ReportScriptError("CapturePassAttachment needs three or four arguments");
  974. return;
  975. }
  976. if (!dc.IsTable(0))
  977. {
  978. ReportScriptError("CapturePassAttachment's first argument must be a table of strings");
  979. return;
  980. }
  981. if (!dc.IsString(1) || !dc.IsString(2))
  982. {
  983. ReportScriptError("CapturePassAttachment's second and third argument must be strings");
  984. return;
  985. }
  986. if (dc.GetNumArguments() == 4 && !dc.IsString(3))
  987. {
  988. ReportScriptError("CapturePassAttachment's forth argument must be a string 'Input' or 'Output'");
  989. return;
  990. }
  991. const char* stringValue = nullptr;
  992. AZStd::vector<AZStd::string> passHierarchy;
  993. AZStd::string slot;
  994. AZStd::string outputFilePath;
  995. // read slot name and output file path
  996. dc.ReadArg(1, stringValue);
  997. slot = AZStd::string(stringValue);
  998. dc.ReadArg(2, stringValue);
  999. outputFilePath = AZStd::string(stringValue);
  1000. AZ::RPI::PassAttachmentReadbackOption readbackOption = AZ::RPI::PassAttachmentReadbackOption::Output;
  1001. if (dc.GetNumArguments() == 4)
  1002. {
  1003. AZStd::string option;
  1004. dc.ReadArg(3, option);
  1005. if (option == "Input")
  1006. {
  1007. readbackOption = AZ::RPI::PassAttachmentReadbackOption::Input;
  1008. }
  1009. }
  1010. // read pass hierarchy
  1011. AZ::ScriptDataContext stringtable;
  1012. dc.InspectTable(0, stringtable);
  1013. const char* fieldName;
  1014. int fieldIndex;
  1015. int elementIndex;
  1016. while (stringtable.InspectNextElement(elementIndex, fieldName, fieldIndex))
  1017. {
  1018. if (fieldIndex != -1)
  1019. {
  1020. if (!stringtable.IsString(elementIndex))
  1021. {
  1022. ReportScriptError("CapturePassAttachment's first argument must contain only strings");
  1023. return;
  1024. }
  1025. const char* stringTableValue = nullptr;
  1026. if (stringtable.ReadValue(elementIndex, stringTableValue))
  1027. {
  1028. passHierarchy.push_back(stringTableValue);
  1029. }
  1030. }
  1031. }
  1032. auto operation = [passHierarchy, slot, outputFilePath, readbackOption]()
  1033. {
  1034. // Note this will pause the script until the capture is complete
  1035. if (PrepareForScreenCapture(outputFilePath))
  1036. {
  1037. AZ::Render::FrameCaptureRequestBus::Broadcast(&AZ::Render::FrameCaptureRequestBus::Events::CapturePassAttachment, passHierarchy, slot, outputFilePath, readbackOption);
  1038. }
  1039. };
  1040. s_instance->m_scriptOperations.push(AZStd::move(operation));
  1041. s_instance->m_scriptOperations.push([]()
  1042. {
  1043. s_instance->m_scriptReporter.CheckLatestScreenshot(s_instance->m_imageComparisonOptions.GetCurrentToleranceLevel());
  1044. });
  1045. }
  1046. void ScriptManager::OnCaptureFinished(AZ::Render::FrameCaptureResult result, const AZStd::string &info)
  1047. {
  1048. m_isCapturePending = false;
  1049. AZ::Render::FrameCaptureNotificationBus::Handler::BusDisconnect();
  1050. ResumeScript();
  1051. // This is checking for the exact scenario that results from an HDR setup. The goal is to add a very specific and prominent message that will
  1052. // alert users to a common issue and what action to take. Any other Format issues will be reported by FrameCaptureSystemComponent with a
  1053. // "Can't save image with format %s to a ppm file" message.
  1054. if (result == AZ::Render::FrameCaptureResult::UnsupportedFormat && info.find(AZ::RHI::ToString(AZ::RHI::Format::R10G10B10A2_UNORM)) != AZStd::string::npos)
  1055. {
  1056. m_messageBox.OpenPopupMessage("HDR Not Supported", "Screen capture testing is not supported in HDR. Please change the system configuration to disable the HDR display feature.");
  1057. AbortScripts("Script(s) aborted due to HDR configuration.");
  1058. }
  1059. }
  1060. void ScriptManager::OnCaptureQueryTimestampFinished([[maybe_unused]] bool result, [[maybe_unused]] const AZStd::string& info)
  1061. {
  1062. m_isCapturePending = false;
  1063. AZ::Render::ProfilingCaptureNotificationBus::Handler::BusDisconnect();
  1064. ResumeScript();
  1065. }
  1066. void ScriptManager::OnCaptureCpuFrameTimeFinished([[maybe_unused]] bool result, [[maybe_unused]] const AZStd::string& info)
  1067. {
  1068. m_isCapturePending = false;
  1069. AZ::Render::ProfilingCaptureNotificationBus::Handler::BusDisconnect();
  1070. ResumeScript();
  1071. }
  1072. void ScriptManager::OnCaptureQueryPipelineStatisticsFinished([[maybe_unused]] bool result, [[maybe_unused]] const AZStd::string& info)
  1073. {
  1074. m_isCapturePending = false;
  1075. AZ::Render::ProfilingCaptureNotificationBus::Handler::BusDisconnect();
  1076. ResumeScript();
  1077. }
  1078. void ScriptManager::OnCaptureCpuProfilingStatisticsFinished([[maybe_unused]] bool result, [[maybe_unused]] const AZStd::string& info)
  1079. {
  1080. m_isCapturePending = false;
  1081. Profiler::ProfilerNotificationBus::Handler::BusDisconnect();
  1082. ResumeScript();
  1083. }
  1084. void ScriptManager::OnCaptureBenchmarkMetadataFinished([[maybe_unused]] bool result, [[maybe_unused]] const AZStd::string& info)
  1085. {
  1086. m_isCapturePending = false;
  1087. AZ::Render::ProfilingCaptureNotificationBus::Handler::BusDisconnect();
  1088. ResumeScript();
  1089. }
  1090. void ScriptManager::Script_CapturePassTimestamp(AZ::ScriptDataContext& dc)
  1091. {
  1092. AZStd::string outputFilePath;
  1093. const bool readScriptDataContext = ValidateProfilingCaptureScripContexts(dc, outputFilePath);
  1094. if (!readScriptDataContext)
  1095. {
  1096. return;
  1097. }
  1098. auto operation = [outputFilePath]()
  1099. {
  1100. s_instance->m_isCapturePending = true;
  1101. s_instance->AZ::Render::ProfilingCaptureNotificationBus::Handler::BusConnect();
  1102. s_instance->PauseScript();
  1103. AZ::Render::ProfilingCaptureRequestBus::Broadcast(&AZ::Render::ProfilingCaptureRequestBus::Events::CapturePassTimestamp, outputFilePath);
  1104. };
  1105. s_instance->m_scriptOperations.push(AZStd::move(operation));
  1106. }
  1107. void ScriptManager::Script_CaptureCpuFrameTime(AZ::ScriptDataContext& dc)
  1108. {
  1109. AZStd::string outputFilePath;
  1110. const bool readScriptDataContext = ValidateProfilingCaptureScripContexts(dc, outputFilePath);
  1111. if (!readScriptDataContext)
  1112. {
  1113. return;
  1114. }
  1115. auto operation = [outputFilePath]()
  1116. {
  1117. s_instance->m_isCapturePending = true;
  1118. s_instance->AZ::Render::ProfilingCaptureNotificationBus::Handler::BusConnect();
  1119. s_instance->PauseScript();
  1120. AZ::Render::ProfilingCaptureRequestBus::Broadcast(&AZ::Render::ProfilingCaptureRequestBus::Events::CaptureCpuFrameTime, outputFilePath);
  1121. };
  1122. s_instance->m_scriptOperations.push(AZStd::move(operation));
  1123. }
  1124. void ScriptManager::Script_CapturePassPipelineStatistics(AZ::ScriptDataContext& dc)
  1125. {
  1126. AZStd::string outputFilePath;
  1127. const bool readScriptDataContext = ValidateProfilingCaptureScripContexts(dc, outputFilePath);
  1128. if (!readScriptDataContext)
  1129. {
  1130. return;
  1131. }
  1132. auto operation = [outputFilePath]()
  1133. {
  1134. s_instance->m_isCapturePending = true;
  1135. s_instance->AZ::Render::ProfilingCaptureNotificationBus::Handler::BusConnect();
  1136. s_instance->PauseScript();
  1137. AZ::Render::ProfilingCaptureRequestBus::Broadcast(&AZ::Render::ProfilingCaptureRequestBus::Events::CapturePassPipelineStatistics, outputFilePath);
  1138. };
  1139. s_instance->m_scriptOperations.push(AZStd::move(operation));
  1140. }
  1141. void ScriptManager::Script_CaptureCpuProfilingStatistics(AZ::ScriptDataContext& dc)
  1142. {
  1143. AZStd::string outputFilePath;
  1144. const bool readScriptDataContext = ValidateProfilingCaptureScripContexts(dc, outputFilePath);
  1145. if (!readScriptDataContext)
  1146. {
  1147. return;
  1148. }
  1149. auto operation = [outputFilePath]()
  1150. {
  1151. s_instance->m_isCapturePending = true;
  1152. s_instance->Profiler::ProfilerNotificationBus::Handler::BusConnect();
  1153. s_instance->PauseScript();
  1154. Profiler::ProfilerRequestBus::Broadcast(&Profiler::ProfilerRequestBus::Events::CaptureCpuProfilingStatistics, outputFilePath);
  1155. };
  1156. s_instance->m_scriptOperations.push(AZStd::move(operation));
  1157. }
  1158. void ScriptManager::Script_CaptureBenchmarkMetadata(AZ::ScriptDataContext& dc)
  1159. {
  1160. if (dc.GetNumArguments() != 2)
  1161. {
  1162. ReportScriptError("CaptureBenchmarkMetadata needs two arguments, benchmarkName and outputFilePath.");
  1163. return;
  1164. }
  1165. if (!dc.IsString(0) || !dc.IsString(1))
  1166. {
  1167. ReportScriptError("CaptureBenchmarkMetadata's arguments benchmarkName and outputFilePath must both be of type string.");
  1168. return;
  1169. }
  1170. const char* stringValue = nullptr;
  1171. AZStd::string benchmarkName;
  1172. AZStd::string outputFilePath;
  1173. dc.ReadArg(0, stringValue);
  1174. benchmarkName = AZStd::string(stringValue);
  1175. dc.ReadArg(1, stringValue);
  1176. outputFilePath = AZStd::string(stringValue);
  1177. auto operation = [benchmarkName, outputFilePath]()
  1178. {
  1179. s_instance->m_isCapturePending = true;
  1180. s_instance->AZ::Render::ProfilingCaptureNotificationBus::Handler::BusConnect();
  1181. s_instance->PauseScript();
  1182. AZ::Render::ProfilingCaptureRequestBus::Broadcast(&AZ::Render::ProfilingCaptureRequestBus::Events::CaptureBenchmarkMetadata, benchmarkName, outputFilePath);
  1183. };
  1184. s_instance->m_scriptOperations.push(AZStd::move(operation));
  1185. }
  1186. bool ScriptManager::ValidateProfilingCaptureScripContexts(AZ::ScriptDataContext& dc, AZStd::string& outputFilePath)
  1187. {
  1188. if (dc.GetNumArguments() != 1)
  1189. {
  1190. ReportScriptError("ProfilingCaptureScriptDataContext needs one argument");
  1191. return false;
  1192. }
  1193. if (!dc.IsString(0))
  1194. {
  1195. ReportScriptError("ProfilingCaptureScriptDataContext's first (and only) argument must be of type string");
  1196. return false;
  1197. }
  1198. // Read slot name and output file path
  1199. const char* stringValue = nullptr;
  1200. dc.ReadArg(0, stringValue);
  1201. if (stringValue == nullptr)
  1202. {
  1203. ReportScriptError("ProfilingCaptureScriptDataContext failed to read the string value");
  1204. return false;
  1205. }
  1206. outputFilePath = AZStd::string(stringValue);
  1207. return true;
  1208. }
  1209. float ScriptManager::Script_DegToRad(float degrees)
  1210. {
  1211. return AZ::DegToRad(degrees);
  1212. }
  1213. AZStd::string ScriptManager::Script_GetRenderApiName()
  1214. {
  1215. AZ::RPI::RPISystemInterface* rpiSystem = AZ::RPI::RPISystemInterface::Get();
  1216. return rpiSystem->GetRenderApiName().GetCStr();
  1217. }
  1218. int ScriptManager::Script_GetRandomTestSeed()
  1219. {
  1220. return s_instance->m_testSuiteRunConfig.m_randomSeed;
  1221. }
  1222. void ScriptManager::CheckArcBallControllerHandler()
  1223. {
  1224. if (0 == AZ::Debug::ArcBallControllerRequestBus::GetNumOfEventHandlers(s_instance->m_cameraEntity->GetId()))
  1225. {
  1226. ReportScriptError("There is no handler for ArcBallControllerRequestBus for the camera entity.");
  1227. }
  1228. }
  1229. void ScriptManager::CheckNoClipControllerHandler()
  1230. {
  1231. if (0 == AZ::Debug::NoClipControllerRequestBus::GetNumOfEventHandlers(s_instance->m_cameraEntity->GetId()))
  1232. {
  1233. ReportScriptError("There is no handler for NoClipControllerRequestBus for the camera entity.");
  1234. }
  1235. }
  1236. void ScriptManager::Script_ArcBallCameraController_SetCenter(AZ::Vector3 center)
  1237. {
  1238. auto operation = [center]()
  1239. {
  1240. AZ_DEBUG_STATIC_MEMEBER(instance, s_instance);
  1241. CheckArcBallControllerHandler();
  1242. AZ::Debug::ArcBallControllerRequestBus::Event(s_instance->m_cameraEntity->GetId(), &AZ::Debug::ArcBallControllerRequestBus::Events::SetCenter, center);
  1243. };
  1244. s_instance->m_scriptOperations.push(AZStd::move(operation));
  1245. }
  1246. void ScriptManager::Script_ArcBallCameraController_SetPan(AZ::Vector3 pan)
  1247. {
  1248. auto operation = [pan]()
  1249. {
  1250. AZ_DEBUG_STATIC_MEMEBER(instance, s_instance);
  1251. CheckArcBallControllerHandler();
  1252. AZ::Debug::ArcBallControllerRequestBus::Event(s_instance->m_cameraEntity->GetId(), &AZ::Debug::ArcBallControllerRequestBus::Events::SetPan, pan);
  1253. };
  1254. s_instance->m_scriptOperations.push(AZStd::move(operation));
  1255. }
  1256. void ScriptManager::Script_ArcBallCameraController_SetDistance(float distance)
  1257. {
  1258. auto operation = [distance]()
  1259. {
  1260. AZ_DEBUG_STATIC_MEMEBER(instance, s_instance);
  1261. CheckArcBallControllerHandler();
  1262. AZ::Debug::ArcBallControllerRequestBus::Event(s_instance->m_cameraEntity->GetId(), &AZ::Debug::ArcBallControllerRequestBus::Events::SetDistance, distance);
  1263. };
  1264. s_instance->m_scriptOperations.push(AZStd::move(operation));
  1265. }
  1266. void ScriptManager::Script_ArcBallCameraController_SetHeading(float heading)
  1267. {
  1268. auto operation = [heading]()
  1269. {
  1270. AZ_DEBUG_STATIC_MEMEBER(instance, s_instance);
  1271. CheckArcBallControllerHandler();
  1272. AZ::Debug::ArcBallControllerRequestBus::Event(s_instance->m_cameraEntity->GetId(), &AZ::Debug::ArcBallControllerRequestBus::Events::SetHeading, heading);
  1273. };
  1274. s_instance->m_scriptOperations.push(AZStd::move(operation));
  1275. }
  1276. void ScriptManager::Script_ArcBallCameraController_SetPitch(float pitch)
  1277. {
  1278. auto operation = [pitch]()
  1279. {
  1280. AZ_DEBUG_STATIC_MEMEBER(instance, s_instance);
  1281. CheckArcBallControllerHandler();
  1282. AZ::Debug::ArcBallControllerRequestBus::Event(s_instance->m_cameraEntity->GetId(), &AZ::Debug::ArcBallControllerRequestBus::Events::SetPitch, pitch);
  1283. };
  1284. s_instance->m_scriptOperations.push(AZStd::move(operation));
  1285. }
  1286. void ScriptManager::Script_NoClipCameraController_SetPosition(AZ::Vector3 position)
  1287. {
  1288. auto operation = [position]()
  1289. {
  1290. AZ_DEBUG_STATIC_MEMEBER(instance, s_instance);
  1291. CheckNoClipControllerHandler();
  1292. AZ::Debug::NoClipControllerRequestBus::Event(s_instance->m_cameraEntity->GetId(), &AZ::Debug::NoClipControllerRequestBus::Events::SetPosition, position);
  1293. };
  1294. s_instance->m_scriptOperations.push(AZStd::move(operation));
  1295. }
  1296. void ScriptManager::Script_NoClipCameraController_SetHeading(float heading)
  1297. {
  1298. auto operation = [heading]()
  1299. {
  1300. AZ_DEBUG_STATIC_MEMEBER(instance, s_instance);
  1301. CheckNoClipControllerHandler();
  1302. AZ::Debug::NoClipControllerRequestBus::Event(s_instance->m_cameraEntity->GetId(), &AZ::Debug::NoClipControllerRequestBus::Events::SetHeading, heading);
  1303. };
  1304. s_instance->m_scriptOperations.push(AZStd::move(operation));
  1305. }
  1306. void ScriptManager::Script_NoClipCameraController_SetPitch(float pitch)
  1307. {
  1308. auto operation = [pitch]()
  1309. {
  1310. AZ_DEBUG_STATIC_MEMEBER(instance, s_instance);
  1311. CheckNoClipControllerHandler();
  1312. AZ::Debug::NoClipControllerRequestBus::Event(s_instance->m_cameraEntity->GetId(), &AZ::Debug::NoClipControllerRequestBus::Events::SetPitch, pitch);
  1313. };
  1314. s_instance->m_scriptOperations.push(AZStd::move(operation));
  1315. }
  1316. void ScriptManager::Script_NoClipCameraController_SetFov(float fov)
  1317. {
  1318. auto operation = [fov]()
  1319. {
  1320. AZ_DEBUG_STATIC_MEMEBER(instance, s_instance);
  1321. CheckNoClipControllerHandler();
  1322. AZ::Debug::NoClipControllerRequestBus::Event(s_instance->m_cameraEntity->GetId(), &AZ::Debug::NoClipControllerRequestBus::Events::SetFov, fov);
  1323. };
  1324. s_instance->m_scriptOperations.push(AZStd::move(operation));
  1325. }
  1326. void ScriptManager::Script_AssetTracking_Start()
  1327. {
  1328. auto operation = []()
  1329. {
  1330. AZ_DEBUG_STATIC_MEMEBER(instance, s_instance);
  1331. s_instance->m_assetStatusTracker.StartTracking();
  1332. };
  1333. s_instance->m_scriptOperations.push(AZStd::move(operation));
  1334. }
  1335. void ScriptManager::Script_AssetTracking_ExpectAsset(const AZStd::string& sourceAssetPath, uint32_t expectedCount)
  1336. {
  1337. auto operation = [sourceAssetPath, expectedCount]()
  1338. {
  1339. AZ_DEBUG_STATIC_MEMEBER(instance, s_instance);
  1340. s_instance->m_assetStatusTracker.ExpectAsset(sourceAssetPath, expectedCount);
  1341. };
  1342. s_instance->m_scriptOperations.push(AZStd::move(operation));
  1343. }
  1344. void ScriptManager::Script_AssetTracking_IdleUntilExpectedAssetsFinish(float timeout)
  1345. {
  1346. auto operation = [timeout]()
  1347. {
  1348. AZ_DEBUG_STATIC_MEMEBER(instance, s_instance);
  1349. AZ_Assert(!s_instance->m_waitForAssetTracker, "It shouldn't be possible to run the next command until m_waitForAssetTracker is false");
  1350. s_instance->m_waitForAssetTracker = true;
  1351. s_instance->m_assetTrackingTimeout = timeout;
  1352. };
  1353. s_instance->m_scriptOperations.push(AZStd::move(operation));
  1354. }
  1355. void ScriptManager::Script_AssetTracking_Stop()
  1356. {
  1357. auto operation = []()
  1358. {
  1359. AZ_DEBUG_STATIC_MEMEBER(instance, s_instance);
  1360. s_instance->m_assetStatusTracker.StopTracking();
  1361. };
  1362. s_instance->m_scriptOperations.push(AZStd::move(operation));
  1363. }
  1364. } // namespace AtomSampleViewer