1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
#include "game.hpp"
GameSettings pkeSettings{};
const uint64_t consoleBufferCount = 30;
const uint64_t consoleLineLength = 128;
char consoleBuffer[consoleBufferCount][consoleLineLength];
long consoleBufferIndex = 0;
void Game_Tick(double delta) {
/*
* ECS_Tick() gets called first because it updates the public
* `EntitiesToBeRemoved` for all other ticks to use.
*/
ECS_Tick(delta);
}
void RecordImGuiEditorWrapper() {
ImGui::DockSpaceOverViewport(nullptr, ImGuiDockNodeFlags_PassthruCentralNode);
ImGui::BeginMainMenuBar();
if (ImGui::BeginMenu("File")) {
if (ImGui::MenuItem("Exit")) {
glfwSetWindowShouldClose(window, true);
}
ImGui::EndMenu();
}
ImGui::EndMainMenuBar();
}
void RecordImGuiConsole() {
static bool scrollToBottom = true;
if (!ImGui::Begin("Console", &pkeSettings.editorSettings.isShowingConsole)) {
ImGui::End();
return;
}
ImVec2 region = ImGui::GetContentRegionAvail();
region.y -= 27;
if (ImGui::BeginListBox("##ConsoleHistory", region)) {
for (long i = consoleBufferIndex + 1; i < consoleBufferCount; ++i) {
ImGui::Text("%s", consoleBuffer[i]);
}
for (long i = 0; i < consoleBufferIndex; ++i) {
ImGui::Text("%s", consoleBuffer[i]);
}
if (scrollToBottom) ImGui::SetScrollHereY(1);
scrollToBottom = false;
ImGui::EndListBox();
}
ImGui::Separator();
if (ImGui::InputText("##ConsoleInput", consoleBuffer[consoleBufferIndex], consoleLineLength, ImGuiInputTextFlags_EnterReturnsTrue)) {
// TODO parse and execute.
scrollToBottom = true;
consoleBufferIndex = (consoleBufferIndex + 1) % consoleBufferCount;
memset(consoleBuffer[consoleBufferIndex], '\0', consoleLineLength);
}
auto focusedFlags = (ImGuiFocusedFlags_ChildWindows);
if (ImGui::IsWindowFocused(focusedFlags) && !ImGui::IsAnyItemFocused() && !ImGui::IsAnyItemHovered() && !ImGui::IsMouseClicked(ImGuiMouseButton_Left) && !ImGui::IsMouseClicked(ImGuiMouseButton_Left, true)) {
ImGui::SetKeyboardFocusHere(-1);
}
ImGui::End();
}
void RecordImGuiEntityList() {
if (!ImGui::Begin("EntityList", &pkeSettings.editorSettings.isShowingEntityList)) {
ImGui::End();
return;
}
static ImGuiTableFlags tableFlags{
ImGuiTableFlags_Borders |
ImGuiTableFlags_RowBg
};
if (ImGui::BeginTable("Entities", 5, tableFlags)) {
ImGui::TableSetupColumn("EntityHandle");
ImGui::TableSetupColumn("ParentEntityHandle");
ImGui::TableSetupColumn("GrBindsHandle");
ImGui::TableSetupColumn("InstanceHandle");
ImGui::TableSetupColumn("IsMarkedForRemoval");
ImGui::TableHeadersRow();
uint64_t bucketCount = ECS_GetEntities_BucketCount();
for (long bucket = 0; bucket <= bucketCount; ++bucket) {
uint64_t itemCount = 0;
auto *entities = ECS_GetEntities(bucket, itemCount);
for (long row = 0; row < itemCount; row++) {
auto *entity = &entities[row];
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
ImGui::Text("%lx", static_cast<EntityHandle_T>(entity->handle));
ImGui::TableSetColumnIndex(1);
ImGui::Text("%lx", static_cast<EntityHandle_T>(entity->parentHandle));
ImGui::TableSetColumnIndex(2);
ImGui::Text("%lx", static_cast<GrBindsHandle_T>(entity->grBindsHandle));
ImGui::TableSetColumnIndex(3);
ImGui::Text("%lx", static_cast<InstanceHandle_T>(entity->instanceHandle));
ImGui::TableSetColumnIndex(4);
ImGui::Text("%u", entity->isMarkedForRemoval);
}
}
ImGui::EndTable();
}
ImGui::End();
}
void RecordImGuiEditor() {
if (pkeSettings.isShowingEditor) {
RecordImGuiEditorWrapper();
RecordImGuiConsole();
RecordImGuiEntityList();
}
}
void Game_Init() {
for (long i = 0; i < consoleBufferCount; ++i) {
memset(consoleBuffer[i], '\0', consoleLineLength);
}
Event_RegisterCallback("RenderImGui", RecordImGuiEditor);
}
|