gothickit / phoenix-shared-interface Goto Github PK
View Code? Open in Web Editor NEWC-bindings for phoenix, the ZenGin asset parser.
License: MIT License
C-bindings for phoenix, the ZenGin asset parser.
License: MIT License
When I register TA_MIN, it should return the following values:
FUNC VOID TA_Min (var c_npc self, var int start_h, var int start_m, var int stop_h, var int stop_m, VAR func state, VAR string waypoint) { };
I implemented the pop() logic inside PxCs.Test and get all of the data except the instance which will always be 0x0.
(Code: https://github.com/GothicKit/phoenix-csharp-interface/blob/main/PxCs.Tests/PxVmTest.cs#L74)
As the other data is poped() right, I assume the order is correct?
public static void TA_MIN(IntPtr vmPtr)
{
var waypoint = PxVm.pxVmStackPopString(vmPtr); // OCR_HUT_33 --> correct
var action = PxVm.pxVmStackPopInt(vmPtr); // 5903 --> correct
var stop_m = PxVm.pxVmStackPopInt(vmPtr);
var stop_h = PxVm.pxVmStackPopInt(vmPtr);
var start_m = PxVm.pxVmStackPopInt(vmPtr); // 30 --> correct
var start_h = PxVm.pxVmStackPopInt(vmPtr); // 22 --> correct
var npc = PxVm.pxVmStackPopInstance(vmPtr); // --> error. Shouldn't be 0
Assert.True(npc != IntPtr.Zero, "Npc is IntPtr.Zero.");
}
What could drive this error?
When I pick the built phoenix-shared.dll from GitHub actions, I can't run it neither on PxCs.Tests nor Unity.
What I checked:
When I build phoenix-shared with MinGW-64 on Windows, I include the "libstdc++" as static dependency. This solved this issue earlier.
I checked file size (first indicator of different static dependencies)
--> libphoenix-shared.dll -> working one built with mingw
--> phoenix-shared.dll -> taken from GitHub action
I checked with DependencyWalker what's the difference between the two dlls.
--> Yes. Both show warnings/errors - seems natural ¯_(ツ)_/¯
--> the GitHub Action one (second one) shows additional errors about API-MS-WIN-CRT in the main window. Could be related to these missing ones? Are there any required DLLs for Windows? Or can we bake it into the dll itself (like libstdc++ with mingw)
Feel free to ping me for further tests.
When calling the below VM method, I get a memory exception:
C#
public static bool CallFunction(IntPtr vmPtr, uint index, IntPtr self, params object[] parameters)
{
var prevSelf = pxVmSetGlobalSelf(vmPtr, self); // returns 0x0
StackPushParameters(vmPtr, parameters);
var success = pxVmCallFunctionByIndex(vmPtr, index, IntPtr.Zero);
pxVmSetGlobalSelf(vmPtr, prevSelf); // Memory Exception
return success;
}
C++
PxVmInstance* pxVmSetGlobalSelf(PxVm* vm, PxVmInstance* instance) {
auto* old = pxVmGetGlobalSelf(vm);
auto* instSym = vm->vm.find_symbol_by_index(instance->symbol_index());
vm->vm.global_self()->set_instance(instSym->get_instance());
return old; // returns 0x0 during first call of pxVmSetGlobalSelf()
}
OpenGothic is doing the reset of globalSelf() in a similar fashion, but there's a difference:
The original phoenix implementation uses std::shared_ptr which are never empty. But the C-API leverages the underlying .data() (c_npc*) which can be empty.
Could it be possible to have a null-check within C-API and reset to a default (empty shared_ptr<>()) value? (maybe create a new shared_ptr every time? But is the old one being deleted?)
When loading an object's model, I get no nullptr, but the model itself has no data.
Example:
auto mdm = pxMdmLoadFromVdf(vdfPtr, name);
auto checksum = pxMdmGetChecksum(mdm); // 0
auto meshCount = pxMdmGetMeshCount(mdm); // 0
...
It cab be tested with CHESTBIG_OCCHESTLARGE.MDM
from anims.vdf
When putting the .dylib into the same folder where the .so and .dlls of our Unity project are, we get the following error:
Hint: I got this message when I used Unity on Windows. (I have no clue if this is related or if the dylib won't work at all. Just want to mention it as this could be an issue if any other project wants to use this on their end).
We tested with @Romeyyy's new PC and there were additional libraries inside the libphoenix-shared.dll missing.
They are:
You can see it in Dependency Walker tool:
Solution: We tested with a different static linking compiler flag for mingw builds. Works like a charm. And the DLL only got 100kb bigger in size.
Currently clang-format is only checking .cc
and .hh
files. But the API headers are of format .h
.
run: 'find include src -iname "*.hh" -or -iname "*.cc" | xargs clang-format --dry-run --style=file --Werror'
I would recommend changing this behavior. But beware: I tested it locally once and it showed some errors on the Header files.
The API currently supports returning compressed Textures only.
PXC_API uint8_t const* pxTexGetMipmap(PxTexture const* tex, uint32_t* length, uint32_t level, uint32_t* width, uint32_t* height);
(https://github.com/GothicKit/phoenix-shared-interface/blob/main/include/phoenix/cffi/Texture.h#L46)
As not every game engine supports all the compression algorithms, we need to have a way getting the data uncompressed if needed.
(Specifically Unity3D can't handle dxt_3)
OpenGothic uses it like this:
if (tex.format() == phoenix::tex_dxt1 ||
tex.format() == phoenix::tex_dxt5) {
...
} else {
auto rgba = tex.as_rgba8(0); // This is the required method to call.
}
It would be sufficient to either have another parameter like bool uncompressed
or call a similar method like pxTexGetMipmapUncompressed()
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.