summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/entities.cpp40
-rw-r--r--src/entities.hpp1
-rw-r--r--src/game.cpp22
-rw-r--r--src/game.hpp1
4 files changed, 31 insertions, 33 deletions
diff --git a/src/entities.cpp b/src/entities.cpp
index b4d0f4b..db3d0a3 100644
--- a/src/entities.cpp
+++ b/src/entities.cpp
@@ -16,37 +16,6 @@ struct ImplementedPipelines {
} vkPipelines;
void EntityType_Init() {
- GlobalEntityTypes.Push(
- EntityType {
- .modelsDir = "assets/models",
- .modelFile = "cube.gltf",
- .entityTypeCode = "EntTypeCube",
- .entityHandle = ECS_CreateEntity(),
- .startingInstanceCount = 16,
- .Importer_GLTF = {
- .AccessorIndexVertex = 0,
- .AccessorIndexNormal = 1,
- .AccessorIndexUV = 2,
- .AccessorIndexIndex = 3,
- }
- }
- );
- GlobalEntityTypes.Push(
- EntityType {
- .modelsDir = "assets/models",
- .modelFile = "plane.gltf",
- .entityTypeCode = "EntTypePlane",
- .entityHandle = ECS_CreateEntity(),
- .startingInstanceCount = 16,
- .Importer_GLTF = {
- .AccessorIndexVertex = 0,
- .AccessorIndexNormal = 1,
- .AccessorIndexUV = 2,
- .AccessorIndexIndex = 3,
- }
- }
- );
-
VkDescriptorSetLayoutBinding vkDescriptorSetLayoutBindings[2];
for (long i = 0; i < 2; ++i) {
vkDescriptorSetLayoutBindings[i].pImmutableSamplers = nullptr;
@@ -360,6 +329,15 @@ void EntityType_Init() {
}
}
+int64_t EntityType_FindByTypeCode(const char *typeCode) {
+ for (int64_t i = 0; i < GlobalEntityTypes.Count(); ++i) {
+ if (strcmp(typeCode, GlobalEntityTypes[i].entityTypeCode) == 0) {
+ return i;
+ }
+ }
+ return -1;
+}
+
void EntityType_Load(EntityType &et) {
assert(et.startingInstanceCount > 0);
if (et.modelFile != nullptr && et.modelFile != CAFE_BABE(char)) {
diff --git a/src/entities.hpp b/src/entities.hpp
index 11f26e5..c09e8f5 100644
--- a/src/entities.hpp
+++ b/src/entities.hpp
@@ -32,6 +32,7 @@ struct EntityType {
extern DynArray<EntityType> GlobalEntityTypes;
void EntityType_Init();
+int64_t EntityType_FindByTypeCode(const char *typeCode);
void EntityType_Load(EntityType &et);
void EntityType_Teardown();
diff --git a/src/game.cpp b/src/game.cpp
index cc975c7..0a7becd 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -17,6 +17,8 @@ void SerializeEntityType(void *TODO, const EntityType &et) {
// TODO
}
+void ParseEntityType(void *TODO, EntityType *et) { }
+
void SaveSceneFile(const char *sceneFilePath) {
// TODO init file
@@ -36,11 +38,24 @@ void SaveSceneFile(const char *sceneFilePath) {
f.close();
}
-void ParseSceneFile(const char *sceneFilePath) {
+void LoadSceneFile(const char *sceneFilePath) {
AssetHandle sceneAH = AM_Register(sceneFilePath);
const Asset *sceneAsset = AM_Get(sceneAH);
- // TODO
+ // EntityTypes
+ {
+ long entityTypeCount = 0; // TODO
+ for (int64_t i = 0; i < entityTypeCount; ++i) {
+ EntityType et{};
+ ParseEntityType(nullptr, &et); // TODO
+ int64_t existingEntityTypeIndex = EntityType_FindByTypeCode(et.entityTypeCode);
+ if (existingEntityTypeIndex != -1) {
+ continue;
+ }
+ et.entityHandle = ECS_CreateEntity();
+ EntityType_Load(et);
+ }
+ }
AM_Destroy(sceneAH);
}
@@ -149,6 +164,9 @@ void RecordImGuiSceneEditor() {
if (ImGui::Button("Save")) {
SaveSceneFile("test.yaml");
}
+ if (ImGui::Button("Load")) {
+ LoadSceneFile("test.yaml");
+ }
ImGui::End();
}
}
diff --git a/src/game.hpp b/src/game.hpp
index c5c6f94..ec0ba3e 100644
--- a/src/game.hpp
+++ b/src/game.hpp
@@ -9,6 +9,7 @@
#include "ecs.hpp"
#include "entities.hpp"
#include "event.hpp"
+#include "helpers.hpp"
#include "imgui.h"
#include "window.hpp"