| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680 |
- #include "containersWindow.h"
- #include <pikaImgui/pikaImgui.h>
- #include "imguiComboSearch.h"
- #include <imgui_spinner.h>
- #include <validatePath.h>
- void pika::ContainersWindow::init(pika::pikaImgui::ImGuiIdsManager &imguiIdsManager)
- {
- imguiIds = imguiIdsManager.getImguiIds(10);
- }
- void pika::ContainersWindow::update(pika::LogManager &logManager, bool &open, pika::LoadedDll &loadedDll,
- pika::ContainerManager &containerManager, pika::pikaImgui::ImGuiIdsManager &imguiIdsManager)
- {
- ImGui::PushID(imguiIds);
- if (!ImGui::Begin(ICON_NAME, &open))
- {
- ImGui::End();
- ImGui::PopID();
- return;
- }
- static int selected = 0;
-
- std::string selectedContainerToLaunch = "";
- {
- ImGui::BeginGroup();
- ImGui::BeginChild("item view", ImVec2(0, -ImGui::GetFrameHeightWithSpacing())); // Leave room for 1 line below us
- if (ImGui::BeginTabBar("##Tabs", ImGuiTabBarFlags_Reorderable))
- {
- if (ImGui::BeginTabItem(ICON_FK_PLUS_SQUARE_O " Create container"))
- {
- ImGui::Text("Available containers");
- ImGui::Separator();
- //left
- ImGui::PushID(imguiIds +1);
- ImGui::BeginGroup();
- {
- static char filter[256] = {};
-
- std::vector<std::string> containerNames;
- containerNames.reserve(loadedDll.containerInfo.size());
- for (auto &i : loadedDll.containerInfo)
- {
- containerNames.push_back(i.containerName);
- }
- auto contentSize = ImGui::GetItemRectSize();
- contentSize.y -= ImGui::GetFrameHeightWithSpacing();
- contentSize.x /= 2;
- ImGui::ListWithFilter("##list box container info", &itemCurrentAvailableCOntainers, filter, sizeof(filter),
- containerNames, contentSize);
- }
- ImGui::EndGroup();
- ImGui::PopID();
- ImGui::SameLine();
- //right
- ImGui::PushID(imguiIds + 2);
- ImGui::BeginGroup();
- {
- if (itemCurrentAvailableCOntainers < loadedDll.containerInfo.size())
- {
- auto &c = loadedDll.containerInfo[itemCurrentAvailableCOntainers];
- ImGui::Text("Container info: %s", c.containerName.c_str());
- ImGui::Separator();
- selectedContainerToLaunch = c.containerName;
- if (ImGui::BeginTabBar("##Tabs for container info", ImGuiTabBarFlags_Reorderable))
- {
- if (ImGui::BeginTabItem(ICON_FK_PIE_CHART " Memory"))
- {
- ImGui::NewLine();
- #pragma region total memory requirement
- size_t totalHeapMemory = c.containerStaticInfo.defaultHeapMemorySize;
- for (auto i : c.containerStaticInfo.bonusAllocators)
- {
- totalHeapMemory += i;
- }
- size_t totalMemory = totalHeapMemory + c.containerStructBaseSize;
- ImGui::Text("Total Memory requirement: ");
- ImGui::SameLine();
- pika::pikaImgui::displayMemorySizeValue(totalMemory);
- ImGui::Text("Total Heap requirement: ");
- ImGui::SameLine();
- pika::pikaImgui::displayMemorySizeValue(totalHeapMemory);
- #pragma endregion
- ImGui::NewLine();
- ImGui::Text("Static Memory requirement: ");
- ImGui::SameLine();
- pika::pikaImgui::displayMemorySizeValue(c.containerStructBaseSize);
- ImGui::Text("Default Heap Memory requirement: ");
- ImGui::SameLine();
- pika::pikaImgui::displayMemorySizeValue(c.containerStaticInfo.defaultHeapMemorySize);
- ImGui::Text("Other Heap Memory Allocators count: ");
- ImGui::SameLine();
- pika::pikaImgui::displayMemorySizeValue(c.containerStaticInfo.bonusAllocators.size());
- if (!c.containerStaticInfo.bonusAllocators.empty())
- {
- if (ImGui::BeginChild("##heap allocators",
- {0, 100}, true, ImGuiWindowFlags_AlwaysVerticalScrollbar))
- {
- for (auto i : c.containerStaticInfo.bonusAllocators)
- {
- pika::pikaImgui::displayMemorySizeValue(i);
- }
- }
- ImGui::EndChild();
- }
- ImGui::EndTabItem();
- }
- if (ImGui::BeginTabItem(ICON_FK_PLUS_SQUARE_O" Launch"))
- {
- ImGui::NewLine();
- if (!selectedContainerToLaunch.empty()
- && ImGui::Button(ICON_FK_PLAY " Launch a default configuration"))
- {
- if (createAtSpecificMemoryRegion)
- {
- containerManager.createContainer(selectedContainerToLaunch, loadedDll,
- logManager, imguiIdsManager, pika::TB(1));
- }
- else
- {
- containerManager.createContainer(selectedContainerToLaunch, loadedDll, logManager,
- imguiIdsManager);
- }
- }
- ImGui::Checkbox("allocate at specific memory region", &createAtSpecificMemoryRegion);
- //ImGui::NewLine();
- {
- static int currentSelectedSnapshot = 0;
- auto snapshots = pika::getAvailableSnapshotsAnyMemoryPosition(c);
- if (!selectedContainerToLaunch.empty()
- && ImGui::Button(ICON_FK_PICTURE_O " Launch a snapshot"))
- {
- auto s = snapshots[currentSelectedSnapshot];
- auto memPos = getSnapshotMemoryPosition(s.c_str());
- if (memPos == nullptr)
- {
- logManager.log("Failes to get snapshot info", pika::logError);
- }
- else
- {
- auto c = containerManager.createContainer(
- selectedContainerToLaunch, loadedDll, logManager,
- imguiIdsManager, (size_t)memPos);
- //no need to log error since create container does that
- if (c != 0)
- {
- if (!containerManager.setSnapshotToContainer(c,
- s.c_str(), logManager, imguiIdsManager))
- {
- containerManager.destroyContainer(c, loadedDll, logManager);
- }
- }
- }
-
-
-
- }
- auto contentSize = ImGui::GetItemRectSize();
- contentSize.y -= ImGui::GetFrameHeightWithSpacing();
- //contentSize.x /= 2;
- ImGui::ListWithFilter("##list box snapshots", ¤tSelectedSnapshot,
- filterSnapshots, sizeof(filterSnapshots),
- snapshots, contentSize);
- }
-
- ImGui::EndTabItem();
- }
- ImGui::EndTabBar();
- }
- }
- else
- {
- ImGui::Text("Container info:");
- ImGui::Separator();
- }
- }
- ImGui::EndGroup();
- ImGui::PopID();
-
-
- ImGui::EndTabItem();
- }
- if (ImGui::BeginTabItem(ICON_FK_MICROCHIP " Running containers"))
- {
-
- ImGui::Text("Running containers");
- ImGui::SameLine();
- pika::pikaImgui::helpMarker(
- ICON_FK_BOLT ": Container is running;\n"
- ICON_FK_PAUSE_CIRCLE_O ": Container is on pause;\n"
- ICON_FK_VIDEO_CAMERA ": Container is being recorded;\n"
- ICON_FK_REPEAT ": Container is on input playback."
- );
- ImGui::Separator();
-
- //left
- std::vector<pika::containerId_t> containerIds;
- std::vector<std::string> containerNames;
- ImGui::PushID(imguiIds + 3);
- ImGui::BeginGroup();
- {
-
- containerIds.reserve(containerManager.runningContainers.size());
- containerNames.reserve(containerManager.runningContainers.size());
- for (auto &i : containerManager.runningContainers)
- {
- containerIds.push_back(i.first);
- containerNames.push_back(
- std::string(i.second.flags.getStatusIcon()) + " " + i.second.baseContainerName + ": " + std::to_string(i.first));
- }
- auto contentSize = ImGui::GetItemRectSize();
- contentSize.y -= ImGui::GetFrameHeightWithSpacing();
- contentSize.x /= 2;
- ImGui::ListWithFilter("##list box container info", &itemCurrentCreatedContainers,
- filterContainerInfo, sizeof(filterContainerInfo),
- containerNames, contentSize);
- }
- ImGui::EndGroup();
- ImGui::PopID();
- ImGui::SameLine();
- //right
- ImGui::PushID(imguiIds + 4);
- ImGui::BeginGroup();
- {
- if (itemCurrentCreatedContainers < containerIds.size())
- {
- auto &c = containerManager.runningContainers[containerIds[itemCurrentCreatedContainers]];
-
- ImGui::Text("Running container: %s #%u", c.baseContainerName, containerIds[itemCurrentCreatedContainers]);
- ImGui::Separator();
- #pragma region buttons
-
- //calculate cursor pos for 3 buttons
- {
- ImGuiStyle &style = ImGui::GetStyle();
- float width = 0.0f;
- width += ImGui::CalcTextSize(ICON_FK_PAUSE).x;
- width += style.ItemSpacing.x;
- width += ImGui::CalcTextSize(ICON_FK_PAUSE).x;
- width += style.ItemSpacing.x;
- width += ImGui::CalcTextSize(ICON_FK_PAUSE).x;
- pika::pikaImgui::alignForWidth(width);
- }
- if (c.flags.status == pika::RuntimeContainer::FLAGS::STATUS_RUNNING)
- {
- if (ImGui::Button(ICON_FK_PAUSE))
- {
- c.flags.status = pika::RuntimeContainer::FLAGS::STATUS_PAUSE;
- }
- if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled))
- {
- ImGui::SetTooltip("Pause container.");
- }
- }
- else if (c.flags.status == pika::RuntimeContainer::FLAGS::STATUS_PAUSE)
- {
- if (ImGui::Button(ICON_FK_PLAY))
- {
- c.flags.status = pika::RuntimeContainer::FLAGS::STATUS_RUNNING;
- }
- if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled))
- {
- ImGui::SetTooltip("Resume container.");
- }
- }
- else if (c.flags.status == pika::RuntimeContainer::FLAGS::STATUS_BEING_RECORDED)
- {
- ImGui::BeginDisabled();
- if (ImGui::Button(ICON_FK_PAUSE))
- {
- }
- ImGui::EndDisabled();
- if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled))
- {
- ImGui::SetTooltip("Can't pause container while it is recorded."); //todo implement
- }
- }
- else if (c.flags.status == pika::RuntimeContainer::FLAGS::STATUS_BEING_PLAYBACK)
- {
- if (ImGui::Button(ICON_FK_REPEAT))
- {
- c.flags.status = pika::RuntimeContainer::FLAGS::STATUS_RUNNING;
- }
- if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled))
- {
- ImGui::SetTooltip("Stop playback");
- }
- }
- ImGui::SameLine();
- bool stopped = false;
- if (ImGui::Button(ICON_FK_STOP))
- {
- //todo mabe defer here when api is made
- containerManager.destroyContainer(containerIds[itemCurrentCreatedContainers], loadedDll, logManager);
- stopped = true;
- }
- if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled))
- {
- ImGui::SetTooltip("Stop container.");
- }
- ImGui::SameLine();
- if (ImGui::Button(ICON_FK_EJECT))
- {
- containerManager.forceTerminateContainer(containerIds[itemCurrentCreatedContainers], loadedDll, logManager);
- stopped = true;
- }
- if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled))
- {
- ImGui::SetTooltip("Force stop container (not recomended).\nThis won't call any destructors.");
- }
- #pragma endregion
- if(!stopped)
- {
- ImGui::Text("Status: %s", c.flags.getStatusName());
- ImGui::Separator();
- if (ImGui::BeginTabBar("##Tabs for play and record", ImGuiTabBarFlags_Reorderable))
- {
- if (ImGui::BeginTabItem(ICON_FK_CAMERA " Snapshot"))
- {
- //snapshot button
- {
- if (ImGui::Button(ICON_FK_CAMERA))
- {
- if (pika::isFileNameValid(snapshotName, sizeof(snapshotName)))
- {
- if (!containerManager.makeSnapshot(containerIds[itemCurrentCreatedContainers], logManager, snapshotName))
- {
- logManager.log("Coultn't make snapshot", pika::logError);
- }
- else
- {
- logManager.log("Successfully created snapshot.");
- }
- }
- else
- {
- logManager.log("File name invalid", pika::logError);
- }
- }
- if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled))
- {
- ImGui::SetTooltip("Make snapshot");
- }
- ImGui::SameLine();
- ImGui::InputText("snapshot name", snapshotName, sizeof(snapshotName));
- }
- ImGui::NewLine();
- ImGui::Separator();
- #pragma region snapshots
- {
- auto snapshots = pika::getAvailableSnapshots(
- containerManager.runningContainers[containerIds[itemCurrentCreatedContainers]]);
- auto contentSize = ImGui::GetItemRectSize();
- contentSize.y -= ImGui::GetFrameHeightWithSpacing();
- contentSize.x /= 2;
- ImGui::ListWithFilter("##list box snapshots", ¤tSelectedSnapshot,
- filterSnapshots, sizeof(filterSnapshots),
- snapshots, contentSize);
- ImGui::SameLine();
- if (snapshots.size() == 0 || currentSelectedSnapshot >= snapshots.size())
- {
- ImGui::BeginDisabled(true);
- }
- else
- {
- ImGui::BeginDisabled(false);
- }
- if (ImGui::Button(ICON_FK_PLAY "##play snapshot"))
- {
- if (!containerManager.setSnapshotToContainer(
- containerIds[itemCurrentCreatedContainers],
- snapshots[currentSelectedSnapshot].c_str(), logManager, imguiIdsManager
- ))
- {
- logManager.log("Failed to assign snapshot", pika::logError);
- }
- }
- ImGui::EndDisabled();
- if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled))
- {
- ImGui::SetTooltip("Play this snapshot to this container");
- }
- }
- #pragma endregion
- ImGui::EndTabItem();
- }
- if (ImGui::BeginTabItem(ICON_FK_VIDEO_CAMERA " Record"))
- {
- //recording
- {
- if (c.flags.status == pika::RuntimeContainer::FLAGS::STATUS_RUNNING)
- {
- if (ImGui::Button(ICON_FK_VIDEO_CAMERA))
- {
- if (pika::isFileNameValid(recordingName, sizeof(recordingName)))
- {
- containerManager.startRecordingContainer
- (containerIds[itemCurrentCreatedContainers], logManager, recordingName);
- }
- else
- {
- logManager.log("File name invalid", pika::logError);
- }
- }
- if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled))
- {
- ImGui::SetTooltip("start recording");
- }
- }
- else if (c.flags.status == pika::RuntimeContainer::FLAGS::STATUS_BEING_RECORDED)
- {
- if (ImGui::Button(ICON_FK_STOP_CIRCLE))
- {
- containerManager.stopRecordingContainer
- (containerIds[itemCurrentCreatedContainers], logManager);
- }
- if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled))
- {
- ImGui::SetTooltip("stop recording");
- }
- }
- else if (c.flags.status == pika::RuntimeContainer::FLAGS::STATUS_PAUSE)
- {
- ImGui::BeginDisabled(1);
- if (ImGui::Button(ICON_FK_VIDEO_CAMERA))
- {
- }
- ImGui::EndDisabled();
- if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled))
- {
- ImGui::SetTooltip("Can't record while container is paused");
- }
- }
- else if (c.flags.status == pika::RuntimeContainer::FLAGS::STATUS_BEING_PLAYBACK)
- {
- ImGui::BeginDisabled(1);
- if (ImGui::Button(ICON_FK_VIDEO_CAMERA))
- {
- }
- ImGui::EndDisabled();
- if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled))
- {
- ImGui::SetTooltip("Can't record while container is on playback");
- }
- }
- ImGui::BeginDisabled(c.flags.status == pika::RuntimeContainer::FLAGS::STATUS_BEING_RECORDED);
- ImGui::SameLine();
- ImGui::InputText("recording name", recordingName, sizeof(recordingName));
- ImGui::EndDisabled();
- }
- ImGui::NewLine();
- ImGui::Separator();
- #pragma region recordings
- auto recordings = pika::getAvailableRecordings(
- containerManager.runningContainers[containerIds[itemCurrentCreatedContainers]]);
- auto contentSize = ImGui::GetItemRectSize();
- contentSize.y -= ImGui::GetFrameHeightWithSpacing();
- contentSize.x /= 2;
- ImGui::ListWithFilter("##list box recordings", ¤tSelectedRecording,
- filterSnapshots, sizeof(filterSnapshots),
- recordings, contentSize);
- ImGui::SameLine();
- if (recordings.size() == 0 || currentSelectedRecording >= recordings.size()
- || c.flags.status == pika::RuntimeContainer::FLAGS::STATUS_BEING_RECORDED)
- {
- ImGui::BeginDisabled(true);
- }
- else
- {
- ImGui::BeginDisabled(false);
- }
- if (ImGui::Button(ICON_FK_PLAY "##play recording"))
- {
- if (!containerManager.setRecordingToContainer(
- containerIds[itemCurrentCreatedContainers],
- recordings[currentSelectedSnapshot].c_str(), logManager, imguiIdsManager
- ))
- {
- logManager.log("Failed to assign recording", pika::logError);
- }
- }
- ImGui::EndDisabled();
-
- if (c.flags.status == pika::RuntimeContainer::FLAGS::STATUS_BEING_RECORDED)
- {
- if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled))
- {
- ImGui::SetTooltip("Can't play a recording because the container is being recorded at the moment");
- }
- }
- else
- {
- if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled))
- {
- ImGui::SetTooltip("Play this recording to this container");
- }
- }
-
- #pragma endregion
- ImGui::EndTabItem();
- }
- ImGui::EndTabBar();
- }
-
-
-
-
- }
- }
- else
- {
- ImGui::Text("Running container:");
- ImGui::Separator();
- }
- }
- ImGui::EndGroup();
- ImGui::PopID();
-
-
- ImGui::EndTabItem();
- }
- ImGui::EndTabBar();
- }
- ImGui::EndChild();
-
- //you can add buttons here
-
- ImGui::EndGroup();
- }
- //todo container profiler will have an instance per container with imgui id and stuff.
- ImGui::End();
- ImGui::PopID();
- }
- //todo options hide show push notidications also engine push notifications that are forced
|