summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/entities.cpp60
-rw-r--r--src/entities.hpp1
-rw-r--r--src/game.cpp51
-rw-r--r--src/game.hpp6
4 files changed, 66 insertions, 52 deletions
diff --git a/src/entities.cpp b/src/entities.cpp
index 0c7003c..b4d0f4b 100644
--- a/src/entities.cpp
+++ b/src/entities.cpp
@@ -1,7 +1,7 @@
#include "entities.hpp"
-DynArray<EntityType> globalEntityTypes{16};
+DynArray<EntityType> GlobalEntityTypes{16};
VkDescriptorSetLayout vkDescriptorSetLayout_Texture = VK_NULL_HANDLE;
VkPipelineLayout vkPipelineLayout_Texture = VK_NULL_HANDLE;
VkSampler vkSampler_Texture = VK_NULL_HANDLE;
@@ -15,50 +15,8 @@ struct ImplementedPipelines {
};
} vkPipelines;
-VkPipelineLayoutCreateInfo sharedVkPipelineLayoutCreateInfo {
- .sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
- .pNext = nullptr,
- .flags = 0,
- .setLayoutCount = 0,
- .pSetLayouts = nullptr,
- .pushConstantRangeCount = 0,
- .pPushConstantRanges = nullptr,
-};
-
-VkWriteDescriptorSet uboDescriptor {
- .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
- .pNext = nullptr,
- .dstSet = nullptr,
- .dstBinding = 0,
- .dstArrayElement = 0,
- .descriptorCount = 1,
- .descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
- .pImageInfo = nullptr,
- .pBufferInfo = nullptr,
- .pTexelBufferView = nullptr,
-};
-
-VkDescriptorImageInfo textureDescriptorInfo {
- .sampler = nullptr,
- .imageView = nullptr,
- .imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
-};
-
-VkWriteDescriptorSet samplerDescriptor {
- .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
- .pNext = nullptr,
- .dstSet = nullptr,
- .dstBinding = 1,
- .dstArrayElement = 0,
- .descriptorCount = 1,
- .descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
- .pImageInfo = &textureDescriptorInfo,
- .pBufferInfo = nullptr,
- .pTexelBufferView = nullptr,
-};
-
void EntityType_Init() {
- globalEntityTypes.Push(
+ GlobalEntityTypes.Push(
EntityType {
.modelsDir = "assets/models",
.modelFile = "cube.gltf",
@@ -73,7 +31,7 @@ void EntityType_Init() {
}
}
);
- globalEntityTypes.Push(
+ GlobalEntityTypes.Push(
EntityType {
.modelsDir = "assets/models",
.modelFile = "plane.gltf",
@@ -396,9 +354,9 @@ void EntityType_Init() {
AM_Destroy(vertShaderAssetHandle);
}
- long entityTypeCount = globalEntityTypes.Count();
+ long entityTypeCount = GlobalEntityTypes.Count();
for (long i = 0; i < entityTypeCount; ++i) {
- EntityType_Load(globalEntityTypes[i]);
+ EntityType_Load(GlobalEntityTypes[i]);
}
}
@@ -877,11 +835,11 @@ void EntityType_Load(EntityType &et) {
}
void EntityType_Teardown() {
- long entityTypeCount = globalEntityTypes.Count();
+ long entityTypeCount = GlobalEntityTypes.Count();
for (long i = 0; i < entityTypeCount; ++i) {
- if (globalEntityTypes[i].modelFile == nullptr) continue;
- auto *et = &globalEntityTypes[i];
- auto *grBinds = ECS_GetGrBinds(globalEntityTypes[i].entityHandle);
+ if (GlobalEntityTypes[i].modelFile == nullptr) continue;
+ auto *et = &GlobalEntityTypes[i];
+ auto *grBinds = ECS_GetGrBinds(GlobalEntityTypes[i].entityHandle);
if (grBinds->vertexBuffer != VK_NULL_HANDLE)
vkDestroyBuffer(vkDevice, grBinds->vertexBuffer, vkAllocator);
if (grBinds->normalsBuffer != VK_NULL_HANDLE)
diff --git a/src/entities.hpp b/src/entities.hpp
index 98aba33..11f26e5 100644
--- a/src/entities.hpp
+++ b/src/entities.hpp
@@ -29,6 +29,7 @@ struct EntityType {
int16_t AccessorIndexIndex = -1;
} Importer_GLTF;
};
+extern DynArray<EntityType> GlobalEntityTypes;
void EntityType_Init();
void EntityType_Load(EntityType &et);
diff --git a/src/game.cpp b/src/game.cpp
index 3fe793f..cc975c7 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -6,9 +6,45 @@ 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
@@ -103,11 +139,26 @@ void RecordImGuiEntityList() {
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();
}
}
diff --git a/src/game.hpp b/src/game.hpp
index b780b4a..c5c6f94 100644
--- a/src/game.hpp
+++ b/src/game.hpp
@@ -3,10 +3,13 @@
#include <chrono>
#include <cstdint>
+#include <fstream>
+#include "asset-manager.hpp"
+#include "ecs.hpp"
+#include "entities.hpp"
#include "event.hpp"
#include "imgui.h"
-#include "ecs.hpp"
#include "window.hpp"
using GameTimeDuration = std::chrono::duration<int64_t, std::nano>;
@@ -26,6 +29,7 @@ struct GameSettings {
struct {
bool isShowingConsole = true;
bool isShowingEntityList = true;
+ bool isShowingSceneEditor = true;
} editorSettings;
};