Skip to content
This repository was archived by the owner on Dec 4, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ target_link_libraries(DirectZ PRIVATE
iostreams
archive_static
assimp
zlibstatic
)

target_link_libraries(dzp PRIVATE DirectZ)
Expand Down
7 changes: 4 additions & 3 deletions Tests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ include(CTest)
function(add_dz_test TEST_NAME TEST_SRC)
add_executable(${TEST_NAME} ${TEST_SRC})
target_include_directories(${TEST_NAME} PRIVATE ${DIRECTZ_INCLUDE_DIRS})
target_link_libraries(${TEST_NAME} PRIVATE DirectZ)
target_link_libraries(${TEST_NAME} PRIVATE DirectZ zlibstatic)
if(ANDROID)
target_link_libraries(${TEST_NAME} PRIVATE android log)
elseif(IOS)
Expand Down Expand Up @@ -38,5 +38,6 @@ add_dz_test(DZ_LineGrid tests/LineGrid.cpp)
add_dz_test(DZ_D7Stream tests/D7Stream.cpp)
add_dz_test(DZ_ImGuiTest tests/ImGui.cpp)
add_dz_test(DZ_ECSTest tests/ECS.cpp)
file(COPY images/Suzuho-Ueda.bmp DESTINATION ${CMAKE_BINARY_DIR})
file(COPY images/hi.bmp DESTINATION ${CMAKE_BINARY_DIR})
file(COPY images/Suzuho-Ueda.bmp DESTINATION ${CMAKE_BINARY_DIR}/images)
file(COPY images/hi.bmp DESTINATION ${CMAKE_BINARY_DIR}/images)
file(COPY models/SaiyanOne.glb DESTINATION ${CMAKE_BINARY_DIR}/models)
67 changes: 34 additions & 33 deletions include/dz/ECS.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,14 @@ namespace dz {
}

template <typename TData, typename TProvider>
void AddProviderSingle(int parent_id, size_t& id, const TData& data, std::vector<std::shared_ptr<ReflectableGroup>>& reflectable_group_vector, int& out_index) {
void AddProviderSingle(
int parent_id,
size_t& id,
const TData& data,
std::vector<std::shared_ptr<ReflectableGroup>>& reflectable_group_vector,
int& out_index,
const std::string& name = ""
) {
if (id)
return;

Expand Down Expand Up @@ -607,20 +614,26 @@ namespace dz {
}

template <typename TData>
size_t AddProvider(int parent_id, const TData& data, std::vector<std::shared_ptr<ReflectableGroup>>& reflectable_group_vector, int& out_index) {
int AddProvider(
int parent_id,
const TData& data,
std::vector<std::shared_ptr<ReflectableGroup>>& reflectable_group_vector,
int& out_index,
const std::string& name = ""
) {
size_t id = 0;
(AddProviderSingle<TData, TProviders>(parent_id, id, data, reflectable_group_vector, out_index), ...);
(AddProviderSingle<TData, TProviders>(parent_id, id, data, reflectable_group_vector, out_index, name), ...);
if (!id)
throw std::runtime_error("Unable to find Provider supporting TData");
return id;
}

template <typename TEntity>
size_t AddEntity(int parent_id, const TEntity& entity_data, const std::vector<int>& mesh_indexes) {
int AddEntity(int parent_id, const TEntity& entity_data, const std::vector<int>& mesh_indexes, const std::string& name = "") {
auto parent_group_ptr = FindParentGroupPtr(parent_id);
int out_index = -1;
auto entity_id = AddProvider<TEntity>(parent_id, entity_data,
parent_group_ptr ? parent_group_ptr->GetChildren() : reflectable_group_root_vector, out_index);
parent_group_ptr ? parent_group_ptr->GetChildren() : reflectable_group_root_vector, out_index, name);
auto& entity_group = GetGroupByID<EntityProviderT, typename EntityProviderT::ReflectableGroup>(entity_id);
for (auto& mesh_index : mesh_indexes) {
auto& mesh_group = GetGroupByIndex<MeshProviderT, typename MeshProviderT::ReflectableGroup>(mesh_index);
Expand All @@ -630,35 +643,35 @@ namespace dz {
.mesh_index = mesh_index,
.material_index = mesh_group.material_index
};
auto submesh_id = AddProvider<SubMeshProviderT>(entity_id, submesh_data, entity_group.reflectable_children, submesh_index);
auto submesh_id = AddProvider<SubMeshProviderT>(entity_id, submesh_data, entity_group.reflectable_children, submesh_index, mesh_group.name);
}
return entity_id;
}

template <typename TEntity>
size_t AddEntity(const TEntity& entity_data, const std::vector<int>& mesh_indexes) {
return AddEntity<TEntity>(-1, entity_data, mesh_indexes);
int AddEntity(const TEntity& entity_data, const std::vector<int>& mesh_indexes, const std::string& name = "") {
return AddEntity<TEntity>(-1, entity_data, mesh_indexes, name);
}

template <typename TScene>
size_t AddScene(int parent_id, const TScene& scene_data) {
int AddScene(int parent_id, const TScene& scene_data, const std::string& name = "") {
auto parent_group_ptr = FindParentGroupPtr(parent_id);
int out_index = -1;
return AddProvider<TScene>(parent_id, scene_data,
parent_group_ptr ? parent_group_ptr->GetChildren() : reflectable_group_root_vector, out_index);
parent_group_ptr ? parent_group_ptr->GetChildren() : reflectable_group_root_vector, out_index, name);
}

template <typename TScene>
size_t AddScene(const TScene& scene_data) {
return AddScene<TScene>(-1, scene_data);
int AddScene(const TScene& scene_data, const std::string& name = "") {
return AddScene<TScene>(-1, scene_data, name);
}

SceneProviderT& GetScene(size_t scene_id) {
return GetProviderData<SceneProviderT>(scene_id);
}

template <typename TMaterial>
size_t AddMaterial(const TMaterial& material_data, int& out_index) {
int AddMaterial(const TMaterial& material_data, int& out_index) {
return AddProvider<TMaterial>(-1, material_data, material_group_vector, out_index);
}

Expand All @@ -678,13 +691,13 @@ namespace dz {
UpdateAtlas();
}

size_t AddMesh(
size_t parent_id,
int AddMesh(
const std::vector<vec<float, 4>>& positions,
const std::vector<vec<float, 2>>& uv2s,
const std::vector<vec<float, 4>>& normals,
int material_index,
int& out_index
int& out_index,
const std::string& name = ""
) {
MeshProviderT mesh_data;
auto position_index = buffer_group_get_buffer_element_count(buffer_group, VertexPositions_Str);
Expand All @@ -700,9 +713,7 @@ namespace dz {
if (!normals.empty())
mesh_data.normal_offset = normal_index;

auto parent_group_ptr = FindParentGroupPtr(parent_id);
auto mesh_id = AddProvider<MeshProviderT>(parent_id, mesh_data,
parent_group_ptr ? parent_group_ptr->GetChildren() : mesh_group_vector, out_index);
auto mesh_id = AddProvider<MeshProviderT>(-1, mesh_data, mesh_group_vector, out_index, name);

if (mesh_data.position_offset != -1) {
buffer_group_set_buffer_element_count(buffer_group, VertexPositions_Str, mesh_data.position_offset + positions.size());
Expand Down Expand Up @@ -737,16 +748,6 @@ namespace dz {
return mesh_id;
}

size_t AddMesh(
const std::vector<vec<float, 4>>& positions,
const std::vector<vec<float, 2>>& uv2s,
const std::vector<vec<float, 4>>& normals,
int material_index,
int& out_index
) {
return AddMesh(-1, positions, uv2s, normals, material_index, out_index);
}

ReflectableGroup& GetGenericGroupByID(size_t id) {
auto ptr = FindParentGroupPtr(id);
if (ptr)
Expand Down Expand Up @@ -836,11 +837,11 @@ namespace dz {
}

template <typename TCamera>
size_t AddCamera(size_t parent_id, const TCamera& camera_data, TCamera::ProjectionType projectionType) {
int AddCamera(size_t parent_id, const TCamera& camera_data, TCamera::ProjectionType projectionType, const std::string& name = "") {
auto parent_group_ptr = FindParentGroupPtr(parent_id);
int out_index = -1;
auto camera_id = AddProvider<TCamera>(parent_id, camera_data,
parent_group_ptr ? parent_group_ptr->GetChildren() : reflectable_group_root_vector, out_index);
parent_group_ptr ? parent_group_ptr->GetChildren() : reflectable_group_root_vector, out_index, name);

auto& camera = GetCamera(camera_id);
auto& camera_group = GetGroupByID<TCamera, typename TCamera::ReflectableGroup>(camera_id);
Expand Down Expand Up @@ -869,8 +870,8 @@ namespace dz {
}

template <typename TCamera>
size_t AddCamera(const TCamera& camera_data, TCamera::ProjectionType projectionType) {
return AddCamera<TCamera>(-1, camera_data, projectionType);
int AddCamera(const TCamera& camera_data, TCamera::ProjectionType projectionType, const std::string& name = "") {
return AddCamera<TCamera>(-1, camera_data, projectionType, name);
}

CameraProviderT& GetCamera(size_t camera_id) {
Expand Down
66 changes: 33 additions & 33 deletions include/dz/ECS/Camera.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,16 @@ void GetCameraModel(int camera_index, out mat4 out_model, out int parent_index,
int uid;
std::string name;
inline static std::unordered_map<std::string, std::pair<int, int>> prop_name_indexes = {
{"type", {0, 0}},
{"is_active", {1, 0}}
{"Type", {0, 0}},
{"Is Active", {1, 0}}
};
inline static std::unordered_map<int, std::string> prop_index_names = {
{0, "type"},
{1, "is_active"}
{0, "Type"},
{1, "Is Active"}
};
inline static std::vector<std::string> prop_names = {
"type",
"is_active"
"Type",
"Is Active"
};
inline static const std::vector<const std::type_info*> typeinfos = {
&typeid(Camera::ProjectionType),
Expand Down Expand Up @@ -172,25 +172,25 @@ void GetCameraModel(int camera_index, out mat4 out_model, out int parent_index,
int uid;
std::string name;
inline static std::unordered_map<std::string, std::pair<int, int>> prop_name_indexes = {
{"position", {0, 0}},
{"center", {1, 0}},
{"up", {2, 0}},
{"nearPlane", {3, 0}},
{"farPlane", {4, 0}}
{"Position", {0, 0}},
{"Center", {1, 0}},
{"Up", {2, 0}},
{"Near Plane", {3, 0}},
{"Far Plane", {4, 0}}
};
inline static std::unordered_map<int, std::string> prop_index_names = {
{0, "posiiton"},
{1, "center"},
{2, "up"},
{3, "nearPlane"},
{4, "farPlane"},
{0, "Position"},
{1, "Center"},
{2, "Up"},
{3, "Near Plane"},
{4, "Far Plane"},
};
inline static std::vector<std::string> prop_names = {
"position",
"center",
"up",
"nearPlane",
"farPlane"
"Position",
"Center",
"Up",
"Near Plane",
"Far Plane"
};
inline static const std::vector<const std::type_info*> typeinfos = {
&typeid(vec<float, 3>),
Expand Down Expand Up @@ -219,16 +219,16 @@ void GetCameraModel(int camera_index, out mat4 out_model, out int parent_index,
int uid;
std::string name;
inline static std::unordered_map<std::string, std::pair<int, int>> prop_name_indexes = {
{"aspect", {0, 0}},
{"fov", {1, 0}}
{"Aspect", {0, 0}},
{"FOV", {1, 0}}
};
inline static std::unordered_map<int, std::string> prop_index_names = {
{0, "aspect"},
{1, "fov"}
{0, "Aspect"},
{1, "FOV"}
};
inline static std::vector<std::string> prop_names = {
"aspect",
"fov"
"Aspect",
"FOV"
};
inline static const std::vector<const std::type_info*> typeinfos = {
&typeid(float),
Expand All @@ -254,16 +254,16 @@ void GetCameraModel(int camera_index, out mat4 out_model, out int parent_index,
int uid;
std::string name;
inline static std::unordered_map<std::string, std::pair<int, int>> prop_name_indexes = {
{"orthoWidth", {0, 0}},
{"orthoHeight", {1, 0}}
{"Ortho Width", {0, 0}},
{"Ortho Height", {1, 0}}
};
inline static std::unordered_map<int, std::string> prop_index_names = {
{0, "orthoWidth"},
{1, "orthoHeight"}
{0, "Ortho Width"},
{1, "Ortho Height"}
};
inline static std::vector<std::string> prop_names = {
"orthoWidth",
"orthoHeight"
"Ortho Width",
"Ortho Height"
};
inline static const std::vector<const std::type_info*> typeinfos = {
&typeid(float),
Expand Down
18 changes: 9 additions & 9 deletions include/dz/ECS/Entity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,19 +97,19 @@ void GetEntityModel(int entity_index, out mat4 out_model, out int parent_index,
int uid;
std::string name;
inline static std::unordered_map<std::string, std::pair<int, int>> prop_name_indexes = {
{"position", {0, 0}},
{"rotation", {1, 0}},
{"scale", {2, 0}}
{"Position", {0, 0}},
{"Rotation", {1, 0}},
{"Scale", {2, 0}}
};
inline static std::unordered_map<int, std::string> prop_index_names = {
{0, "position"},
{1, "rotation"},
{2, "scale"}
{0, "Position"},
{1, "Rotation"},
{2, "Scale"}
};
inline static std::vector<std::string> prop_names = {
"position",
"rotation",
"scale"
"Position",
"Rotation",
"Scale"
};
inline static const std::vector<const std::type_info*> typeinfos = {
&typeid(vec<float, 3>),
Expand Down
14 changes: 3 additions & 11 deletions include/dz/ECS/Material.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,23 +84,15 @@ void EnsureMaterialFragColor(in SubMesh submesh, inout vec4 current_color) {
int uid;
std::string name;
inline static std::unordered_map<std::string, std::pair<int, int>> prop_name_indexes = {
{"atlasImageSize", {0, 0}},
{"atlasPackedRect", {1, 0}},
{"albedo", {2, 0}}
{"Albedo Color", {0, 0}}
};
inline static std::unordered_map<int, std::string> prop_index_names = {
{0, "atlasImageSize"},
{1, "atlasPackedRect"},
{2, "albedo"}
{0, "Albedo Color"}
};
inline static std::vector<std::string> prop_names = {
"atlasImageSize",
"atlasPackedRect",
"albedo"
"Albedo Color"
};
inline static const std::vector<const std::type_info*> typeinfos = {
&typeid(vec<float, 2>),
&typeid(vec<float, 2>),
&typeid(color_vec<float, 4>)
};

Expand Down
18 changes: 9 additions & 9 deletions include/dz/ECS/Scene.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,19 @@ void GetSceneModel(int scene_index, out mat4 out_model, out int parent_index, ou
int uid;
std::string name;
inline static std::unordered_map<std::string, std::pair<int, int>> prop_name_indexes = {
{"position", {0, 0}},
{"rotation", {1, 0}},
{"scale", {2, 0}}
{"Position", {0, 0}},
{"Rotation", {1, 0}},
{"Scale", {2, 0}}
};
inline static std::unordered_map<int, std::string> prop_index_names = {
{0, "position"},
{1, "rotation"},
{2, "scale"}
{0, "Position"},
{1, "Rotation"},
{2, "Scale"}
};
inline static std::vector<std::string> prop_names = {
"position",
"rotation",
"scale"
"Position",
"Rotation",
"Scale"
};
inline static const std::vector<const std::type_info*> typeinfos = {
&typeid(vec<float, 3>),
Expand Down
Loading
Loading