ScriptCanvasDeveloperComponent.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 <ScriptCanvas/Core/Connection.h>
  9. #include <ScriptCanvas/Core/Graph.h>
  10. #include <ScriptCanvas/Core/Node.h>
  11. #include <ScriptCanvasDeveloper/ScriptCanvasDeveloperComponent.h>
  12. #if defined(IMGUI_ENABLED)
  13. #include <imgui/imgui.h>
  14. #endif
  15. namespace ScriptCanvasDeveloperComponentCpp
  16. {
  17. bool GetListEntryFromAZStdStringVector(void* data, int idx, const char** out_text)
  18. {
  19. AZStd::vector<AZStd::string>* vector = reinterpret_cast<AZStd::vector<AZStd::string>*>(data);
  20. if (idx < vector->size())
  21. {
  22. *out_text = (*vector)[idx].c_str();
  23. return true;
  24. }
  25. else
  26. {
  27. return false;
  28. }
  29. }
  30. }
  31. namespace ScriptCanvas::Developer
  32. {
  33. void SystemComponent::Reflect(AZ::ReflectContext* context)
  34. {
  35. if (auto serialize = azrtti_cast<AZ::SerializeContext*>(context))
  36. {
  37. serialize->Class<SystemComponent, AZ::Component>()
  38. ->Version(0)
  39. ;
  40. }
  41. ScriptCanvas::Execution::PerformanceStatistician::Reflect(context);
  42. }
  43. void SystemComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
  44. {
  45. provided.push_back(AZ_CRC_CE("ScriptCanvasDeveloperService"));
  46. }
  47. void SystemComponent::Init()
  48. {
  49. }
  50. void SystemComponent::Activate()
  51. {
  52. #ifdef IMGUI_ENABLED
  53. ImGui::ImGuiUpdateListenerBus::Handler::BusConnect();
  54. #endif // IMGUI_ENABLED
  55. }
  56. void SystemComponent::Deactivate()
  57. {
  58. #ifdef IMGUI_ENABLED
  59. ImGui::ImGuiUpdateListenerBus::Handler::BusDisconnect();
  60. #endif
  61. }
  62. #ifdef IMGUI_ENABLED
  63. void SystemComponent::FullPerformanceWindow()
  64. {
  65. GraphHistoryListBox();
  66. }
  67. void SystemComponent::GraphHistoryListBox()
  68. {
  69. AZStd::vector<AZStd::string> scriptHistory = m_perfStatistician.GetExecutedScriptsSinceLastSnapshot();
  70. int index = 0;
  71. const int k_HeightInItemCount = 30;
  72. ImGui::ListBox(":Graph", &index, &ScriptCanvasDeveloperComponentCpp::GetListEntryFromAZStdStringVector, &scriptHistory, aznumeric_cast<int>(scriptHistory.size()), k_HeightInItemCount);
  73. }
  74. #endif // IMGUI_ENABLED
  75. void SystemComponent::OnImGuiMainMenuUpdate()
  76. {
  77. #ifdef IMGUI_ENABLED
  78. if (ImGui::BeginMenu("Script Canvas"))
  79. {
  80. FullPerformanceWindow();
  81. ImGui::EndMenu();
  82. }
  83. #endif
  84. }
  85. }