Skip to content
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.

Commit

Permalink
refactor(*): bump ZenKit
Browse files Browse the repository at this point in the history
  • Loading branch information
lmichaelis committed Nov 2, 2023
1 parent 3174710 commit c99b354
Show file tree
Hide file tree
Showing 21 changed files with 173 additions and 45 deletions.
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "vendor/phoenix"]
path = vendor/phoenix
url = https://github.com/lmichaelis/phoenix.git
[submodule "vendor/ZenKit"]
path = vendor/ZenKit
url = https://github.com/GothicKit/ZenKit.git
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ if (NOT MSVC)
endif ()

option(PXC_ENABLE_ASAN "phoenix-shared: Enable sanitizers in debug builds." ON)
set(ZK_ENABLE_DEPRECATION OFF)

add_subdirectory(vendor/phoenix)
add_subdirectory(vendor/ZenKit)

list(APPEND PXC_SOURCES
src/Animation.cc
Expand Down Expand Up @@ -53,7 +54,7 @@ target_include_directories(phoenix-shared PUBLIC include)
target_compile_options(phoenix-shared PRIVATE ${PXC_COMPILE_FLAGS})
target_compile_definitions(phoenix-shared PRIVATE PXC_EXPORTS=1)
target_link_options(phoenix-shared PRIVATE ${PXC_LINK_FLAGS})
target_link_libraries(phoenix-shared phoenix)
target_link_libraries(phoenix-shared zenkit)
set_target_properties(phoenix-shared PROPERTIES DEBUG_POSTFIX "d" VERSION ${PROJECT_VERSION})

if (MINGW)
Expand Down
24 changes: 24 additions & 0 deletions include/phoenix/cffi/Mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@ typedef phoenix::mesh PxMesh;
typedef struct PxInternal_Mesh PxMesh;
#endif

typedef struct {
std::uint8_t is_portal;
std::uint8_t is_occluder;
std::uint8_t is_sector;
std::uint8_t should_relight;
std::uint8_t is_outdoor;
std::uint8_t is_ghost_occluder;
std::uint8_t is_dynamically_lit;
std::int16_t sector_index;

uint8_t is_lod;
uint8_t normal_axis;
} PxPolygonFlags;

PXC_API PxMesh* pxMshLoad(PxBuffer* buffer);
PXC_API PxMesh* pxMshLoadFromVfs(PxVfs const* vfs, char const* name);
PXC_API void pxMshDestroy(PxMesh* msh);
Expand Down Expand Up @@ -46,3 +60,13 @@ PXC_API uint8_t pxMshGetPolygonFlagGetIsDynamicallyLit(PxMesh const* msh, uint32
PXC_API int16_t pxMshGetPolygonFlagGetSector_Index(PxMesh const* msh, uint32_t i);
PXC_API uint8_t pxMshGetPolygonFlagGetIsLod(PxMesh const* msh, uint32_t i);
PXC_API uint8_t pxMshGetPolygonFlagGetNormalAxis(PxMesh const* msh, uint32_t i);

PXC_API uint32_t pxMshGetPolygonCount(PxMesh const* msh);
PXC_API void pxMshGetPolygon(PxMesh const* msh,
uint32_t idx,
uint32_t* materialIndex,
int32_t* lightmapIndex,
PxPolygonFlags* flags,
uint32_t const** vertexIndices,
uint32_t const** featureIndices,
uint32_t* vertexCount);
7 changes: 5 additions & 2 deletions src/Animation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,18 @@ PxModelAnimation* pxManLoad(PxBuffer* buffer) {
auto ani = px::animation::parse(buffer->duplicate());
return new px::animation(std::move(ani));
} catch (std::exception const& e) {
px::logging::log(px::logging::level::error, "encountered exception while parsing PxModelAnimation: ", e.what());
px::logging::log(px::logging::level::error,
"CAPI:PxModelAnimation",
"encountered exception while parsing PxModelAnimation: %s",
e.what());
return nullptr;
}
}

PxModelAnimation* pxManLoadFromVfs(PxVfs const* vfs, char const* name) {
PxVfsNode const* node = pxVfsGetNodeByName(vfs, name);
if (node == nullptr) {
px::logging::log(px::logging::level::error, "failed to find vfs entry ", name);
px::logging::log(px::logging::level::error, "CAPI:PxModelAnimation", "failed to find vfs entry: %s", name);
return nullptr;
}

Expand Down
5 changes: 4 additions & 1 deletion src/Buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ PxBuffer* pxBufferMmap(char const* file) {
auto buf = px::buffer::mmap(file);
return new px::buffer(std::move(buf));
} catch (std::exception const& e) {
px::logging::log(px::logging::level::error, "encountered exception while memory-mapping PxBuffer: ", e.what());
px::logging::log(px::logging::level::error,
"CAPI:PxBuffer",
"encountered exception while memory-mapping PxBuffer: %s",
e.what());
return nullptr;
}
}
Expand Down
7 changes: 5 additions & 2 deletions src/Cutscene.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,18 @@ PxCutsceneLib* pxCslLoad(PxBuffer* buffer) {
auto mat = px::messages::parse(buffer->duplicate());
return new phoenix::messages(std::move(mat));
} catch (std::exception const& e) {
px::logging::log(px::logging::level::error, "encountered exception while parsing PxCutsceneLib: ", e.what());
px::logging::log(px::logging::level::error,
"CAPI:PxCutsceneLib",
"encountered exception while parsing PxCutsceneLib: %s",
e.what());
return nullptr;
}
}

PxCutsceneLib* pxCslLoadFromVfs(PxVfs const* vfs, char const* name) {
PxVfsNode const* node = pxVfsGetNodeByName(vfs, name);
if (node == nullptr) {
px::logging::log(px::logging::level::error, "failed to find vfs entry ", name);
px::logging::log(px::logging::level::error, "CAPI:PxCutsceneLib", "failed to find vfs entry: %s", name);
return nullptr;
}

Expand Down
7 changes: 5 additions & 2 deletions src/DaedalusScript.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,18 @@ PxDaedalusScript* pxScriptLoad(PxBuffer* buffer) {
auto scr = px::script::parse(buf);
return new px::script(std::move(scr));
} catch (std::exception const& e) {
px::logging::log(px::logging::level::error, "encountered exception while parsing PxDaedalusScript: ", e.what());
px::logging::log(px::logging::level::error,
"CAPI:PxDaedalusScript",
"encountered exception while parsing PxDaedalusScript: %s",
e.what());
return nullptr;
}
}

PxDaedalusScript* pxScriptLoadFromVfs(PxVfs const* vfs, char const* name) {
PxVfsNode const* node = pxVfsGetNodeByName(vfs, name);
if (node == nullptr) {
px::logging::log(px::logging::level::error, "failed to find vfs entry ", name);
px::logging::log(px::logging::level::error, "CAPI:PxDaedalusScript", "failed to find vfs entry: %s", name);
return nullptr;
}

Expand Down
7 changes: 5 additions & 2 deletions src/Font.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,18 @@ PxFont* pxFntLoad(PxBuffer* buffer) {
auto ani = px::font::parse(buffer->duplicate());
return new phoenix::font(std::move(ani));
} catch (std::exception const& e) {
px::logging::log(px::logging::level::error, "encountered exception while parsing PxFont: ", e.what());
px::logging::log(px::logging::level::error,
"CAPI:PxFont",
"encountered exception while parsing PxFont: %s",
e.what());
return nullptr;
}
}

PxFont* pxFntLoadFromVfs(PxVfs const* vfs, char const* name) {
PxVfsNode const* node = pxVfsGetNodeByName(vfs, name);
if (node == nullptr) {
px::logging::log(px::logging::level::error, "failed to find vfs entry ", name);
px::logging::log(px::logging::level::error, "CAPI:PxFont", "failed to find vfs entry: %s", name);
return nullptr;
}

Expand Down
38 changes: 36 additions & 2 deletions src/Mesh.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,18 @@ PxMesh* pxMshLoad(PxBuffer* buffer) {
auto mat = px::mesh::parse(buffer->duplicate());
return new phoenix::mesh(std::move(mat));
} catch (std::exception const& e) {
px::logging::log(px::logging::level::error, "encountered exception while parsing PxMesh: ", e.what());
px::logging::log(px::logging::level::error,
"CAPI:PxMesh",
"encountered exception while parsing PxMesh: %s",
e.what());
return nullptr;
}
}

PxMesh* pxMshLoadFromVfs(PxVfs const* vfs, char const* name) {
PxVfsNode const* node = pxVfsGetNodeByName(vfs, name);
if (node == nullptr) {
px::logging::log(px::logging::level::error, "failed to find vfs entry ", name);
px::logging::log(px::logging::level::error, "CAPI:PxMesh", "failed to find vfs entry: %s", name);
return nullptr;
}

Expand Down Expand Up @@ -159,3 +162,34 @@ uint8_t pxMshGetPolygonFlagGetIsLod(PxMesh const* msh, uint32_t i) {
uint8_t pxMshGetPolygonFlagGetNormalAxis(PxMesh const* msh, uint32_t i) {
return msh->polygons.flags[i].normal_axis;
}

uint32_t pxMshGetPolygonCount(PxMesh const* msh) {
return msh->geometry.size();
}

void pxMshGetPolygon(PxMesh const* msh,
uint32_t idx,
uint32_t* materialIndex,
int32_t* lightmapIndex,
PxPolygonFlags* flags,
uint32_t const** vertexIndices,
uint32_t const** featureIndices,
uint32_t* vertexCount) {
auto& poly = msh->geometry[idx];
*materialIndex = poly.material;
*lightmapIndex = poly.lightmap;
*vertexIndices = poly.vertices.data();
*featureIndices = poly.features.data();
*vertexCount = poly.vertices.size();

flags->is_portal = poly.flags.is_portal;
flags->is_occluder = poly.flags.is_occluder;
flags->is_sector = poly.flags.is_sector;
flags->should_relight = poly.flags.should_relight;
flags->is_outdoor = poly.flags.is_outdoor;
flags->is_ghost_occluder = poly.flags.is_ghost_occluder;
flags->is_dynamically_lit = poly.flags.is_dynamically_lit;
flags->sector_index = poly.flags.sector_index;
flags->is_lod = poly.flags.is_lod;
flags->normal_axis = poly.flags.normal_axis;
}
7 changes: 5 additions & 2 deletions src/Model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,18 @@ PxModel* pxMdlLoad(PxBuffer* buffer) {
auto mat = px::model::parse(buffer->duplicate());
return new phoenix::model(std::move(mat));
} catch (std::exception const& e) {
px::logging::log(px::logging::level::error, "encountered exception while parsing PxModel: ", e.what());
px::logging::log(px::logging::level::error,
"CAPI:PxModel",
"encountered exception while parsing PxModel: %s",
e.what());
return nullptr;
}
}

PxModel* pxMdlLoadFromVfs(PxVfs const* vfs, char const* name) {
PxVfsNode const* node = pxVfsGetNodeByName(vfs, name);
if (node == nullptr) {
px::logging::log(px::logging::level::error, "failed to find vfs entry ", name);
px::logging::log(px::logging::level::error, "CAPI:PxModel", "failed to find vfs entry: %s", name);
return nullptr;
}

Expand Down
7 changes: 5 additions & 2 deletions src/ModelHierarchy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,18 @@ PxModelHierarchy* pxMdhLoad(PxBuffer* buffer) {
auto mat = px::model_hierarchy::parse(buffer->duplicate());
return new px::model_hierarchy(std::move(mat));
} catch (std::exception const& e) {
px::logging::log(px::logging::level::error, "encountered exception while parsing PxModelHierarchy: ", e.what());
px::logging::log(px::logging::level::error,
"CAPI:PxModelHierarchy",
"encountered exception while parsing PxModelHierarchy: %s",
e.what());
return nullptr;
}
}

PxModelHierarchy* pxMdhLoadFromVfs(PxVfs const* vfs, char const* name) {
PxVfsNode const* node = pxVfsGetNodeByName(vfs, name);
if (node == nullptr) {
px::logging::log(px::logging::level::error, "failed to find vfs entry ", name);
px::logging::log(px::logging::level::error, "CAPI:PxModelHierarchy", "failed to find vfs entry: %s", name);
return nullptr;
}

Expand Down
7 changes: 5 additions & 2 deletions src/ModelMesh.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,18 @@ PxModelMesh* pxMdmLoad(PxBuffer* buffer) {
auto mat = phoenix::model_mesh::parse(buffer->duplicate());
return new phoenix::model_mesh(std::move(mat));
} catch (std::exception const& e) {
px::logging::log(px::logging::level::error, "encountered exception while parsing PxModelMesh: ", e.what());
px::logging::log(px::logging::level::error,
"CAPI:PxModelMesh",
"encountered exception while parsing PxModelMesh: %s",
e.what());
return nullptr;
}
}

PxModelMesh* pxMdmLoadFromVfs(PxVfs const* vfs, char const* name) {
PxVfsNode const* node = pxVfsGetNodeByName(vfs, name);
if (node == nullptr) {
px::logging::log(px::logging::level::error, "failed to find vfs entry ", name);
px::logging::log(px::logging::level::error, "CAPI:PxModelMesh", "failed to find vfs entry: %s", name);
return nullptr;
}

Expand Down
7 changes: 5 additions & 2 deletions src/ModelScript.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,18 @@ PxModelScript* pxMdsLoad(PxBuffer* buffer) {
auto mat = phoenix::model_script::parse(buffer->duplicate());
return new phoenix::model_script(std::move(mat));
} catch (std::exception const& e) {
px::logging::log(px::logging::level::error, "encountered exception while parsing PxModelScript: ", e.what());
px::logging::log(px::logging::level::error,
"CAPI:PxModelScript",
"encountered exception while parsing PxModelScript: %s",
e.what());
return nullptr;
}
}

PxModelScript* pxMdsLoadFromVfs(PxVfs const* vfs, char const* name) {
PxVfsNode const* node = pxVfsGetNodeByName(vfs, name);
if (node == nullptr) {
px::logging::log(px::logging::level::error, "failed to find vfs entry ", name);
px::logging::log(px::logging::level::error, "CAPI:PxModelScript", "failed to find vfs entry: %s", name);
return nullptr;
}

Expand Down
7 changes: 5 additions & 2 deletions src/MorphMesh.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,18 @@ PxMorphMesh* pxMmbLoad(PxBuffer* buffer) {
auto mat = phoenix::morph_mesh::parse(buffer->duplicate());
return new phoenix::morph_mesh(std::move(mat));
} catch (std::exception const& e) {
px::logging::log(px::logging::level::error, "encountered exception while parsing PxMorphMesh: ", e.what());
px::logging::log(px::logging::level::error,
"CAPI:PxMorphMesh",
"encountered exception while parsing PxMorphMesh: %s",
e.what());
return nullptr;
}
}

PxMorphMesh* pxMmbLoadFromVfs(PxVfs const* vfs, char const* name) {
PxVfsNode const* node = pxVfsGetNodeByName(vfs, name);
if (node == nullptr) {
px::logging::log(px::logging::level::error, "failed to find vfs entry ", name);
px::logging::log(px::logging::level::error, "CAPI:PxMorphMesh", "failed to find vfs entry: %s", name);
return nullptr;
}

Expand Down
5 changes: 3 additions & 2 deletions src/MultiResolutionMesh.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ PxMultiResolutionMesh* pxMrmLoad(PxBuffer* buffer) {
return new phoenix::proto_mesh(std::move(mat));
} catch (std::exception const& e) {
px::logging::log(px::logging::level::error,
"encountered exception while parsing PxMultiResolutionMesh: ",
"CAPI:PxMultiResolutionMesh",
"encountered exception while parsing PxMultiResolutionMesh: %s",
e.what());
return nullptr;
}
Expand All @@ -20,7 +21,7 @@ PxMultiResolutionMesh* pxMrmLoad(PxBuffer* buffer) {
PxMultiResolutionMesh* pxMrmLoadFromVfs(PxVfs const* vfs, char const* name) {
PxVfsNode const* node = pxVfsGetNodeByName(vfs, name);
if (node == nullptr) {
px::logging::log(px::logging::level::error, "failed to find vfs entry ", name);
px::logging::log(px::logging::level::error, "CAPI:PxMultiResolutionMesh", "failed to find vfs entry: %s", name);
return nullptr;
}

Expand Down
7 changes: 5 additions & 2 deletions src/Texture.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,18 @@ PxTexture* pxTexLoad(PxBuffer* buffer) {
auto scr = phoenix::texture::parse(buffer->duplicate());
return new phoenix::texture(std::move(scr));
} catch (std::exception const& e) {
px::logging::log(px::logging::level::error, "encountered exception while parsing PxTexture: ", e.what());
px::logging::log(px::logging::level::error,
"CAPI:PxTexture",
"encountered exception while parsing PxTexture: %s",
e.what());
return nullptr;
}
}

PxTexture* pxTexLoadFromVfs(PxVfs const* vfs, char const* name) {
PxVfsNode const* node = pxVfsGetNodeByName(vfs, name);
if (node == nullptr) {
px::logging::log(px::logging::level::error, "failed to find vfs entry ", name);
px::logging::log(px::logging::level::error, "CAPI:PxTexture", "failed to find vfs entry: %s", name);
return nullptr;
}

Expand Down
13 changes: 11 additions & 2 deletions src/Vfs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ void pxVfsMountDisk(PxVfs* vfs, char const* path, PxVfsOverwriteBehavior overwri
try {
vfs->mount_disk(std::filesystem::path(path), static_cast<px::VfsOverwriteBehavior>(overwriteFlag));
} catch (std::exception const& e) {
px::logging::log(px::logging::level::error, "encountered exception while parsing PxVfs: ", e.what());
px::logging::log(px::logging::level::error,
"CAPI:PxVfs",
"encountered exception while parsing PxVfs: %s",
e.what());
}
}

Expand Down Expand Up @@ -52,7 +55,13 @@ size_t pxVfsNodeGetChildCount(const PxVfsNode* node) {

PxVfsNode const* pxVfsNodeGetChild(const PxVfsNode* node, size_t i) {
if (node->type() == phoenix::VfsNodeType::FILE) return nullptr;
return &node->children()[i];

for (const auto& item : node->children()) {
if (i == 0) return &item;
i--;
}

return nullptr;
}

PxBool pxVfsNodeIsFile(const PxVfsNode* node) {
Expand Down
Loading

0 comments on commit c99b354

Please sign in to comment.