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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
#include "game.hpp"
GameSettings pkeSettings{};
const uint64_t consoleBufferCount = 30;
const uint64_t consoleLineLength = 128;
const char *levelName = "demo-level";
char consoleBuffer[consoleBufferCount][consoleLineLength];
long consoleBufferIndex = 0;
void SerializeEntityType(void *TODO, const EntityType &et) {
char handleStr[19] = { '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0' };
snprintf(handleStr, 19, "0x%016lX",static_cast<EntityHandle_T>(et.entityHandle));
// TODO
}
void SaveSceneFile(const char *sceneFilePath) {
// TODO init file
for (long i = 0; i < GlobalEntityTypes.Count(); ++i) {
const auto &et = GlobalEntityTypes[i];
const CompGrBinds *grBinds = ECS_GetGrBinds(et.entityHandle);
// TODO ignore if no instances
if (grBinds == nullptr) {
continue;
}
SerializeEntityType(nullptr, et); // TODO
}
std::ofstream f(sceneFilePath, std::ios::out);
// TODO write to file
f.flush();
f.close();
}
void ParseSceneFile(const char *sceneFilePath) {
AssetHandle sceneAH = AM_Register(sceneFilePath);
const Asset *sceneAsset = AM_Get(sceneAH);
// TODO
AM_Destroy(sceneAH);
}
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 RecordImGuiSceneEditor() {
{
if (!ImGui::Begin("SceneEditorEntityTypes", &pkeSettings.editorSettings.isShowingSceneEditor)) {
ImGui::End();
return;
}
if (ImGui::Button("Save")) {
SaveSceneFile("test.yaml");
}
ImGui::End();
}
}
void RecordImGuiEditor() {
if (pkeSettings.isShowingEditor) {
RecordImGuiEditorWrapper();
RecordImGuiConsole();
RecordImGuiEntityList();
RecordImGuiSceneEditor();
}
}
void Game_Init() {
for (long i = 0; i < consoleBufferCount; ++i) {
memset(consoleBuffer[i], '\0', consoleLineLength);
}
Event_RegisterCallback("RenderImGui", RecordImGuiEditor);
}
|