feat: update BMapSharp.
- update the function calling in BMapSharp.BMFileReader. (hope JIT can optimize my bad code served for beauty) - remove outdated content in COMPILE.md
This commit is contained in:
parent
f781bcd63d
commit
623334f863
|
@ -150,7 +150,7 @@ namespace BMapSharp.BMapWrapper {
|
||||||
}
|
}
|
||||||
|
|
||||||
public class BMObject : AbstractCKObject {
|
public class BMObject : AbstractCKObject {
|
||||||
internal BMObject(nint raw_pointer, uint ckid) : base(raw_pointer, ckid) {}
|
internal BMObject(nint raw_pointer, uint ckid) : base(raw_pointer, ckid) { }
|
||||||
|
|
||||||
public string GetName() {
|
public string GetName() {
|
||||||
BMapException.ThrowIfFailed(BMap.BMObject_GetName(
|
BMapException.ThrowIfFailed(BMap.BMObject_GetName(
|
||||||
|
@ -166,30 +166,30 @@ namespace BMapSharp.BMapWrapper {
|
||||||
}
|
}
|
||||||
|
|
||||||
public class BMTexture : BMObject {
|
public class BMTexture : BMObject {
|
||||||
internal BMTexture(nint raw_pointer, uint ckid) : base(raw_pointer, ckid) {}
|
internal BMTexture(nint raw_pointer, uint ckid) : base(raw_pointer, ckid) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class BMMaterial : BMObject {
|
public class BMMaterial : BMObject {
|
||||||
internal BMMaterial(nint raw_pointer, uint ckid) : base(raw_pointer, ckid) {}
|
internal BMMaterial(nint raw_pointer, uint ckid) : base(raw_pointer, ckid) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class BMMesh : BMObject {
|
public class BMMesh : BMObject {
|
||||||
internal BMMesh(nint raw_pointer, uint ckid) : base(raw_pointer, ckid) {}
|
internal BMMesh(nint raw_pointer, uint ckid) : base(raw_pointer, ckid) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class BM3dObject : BMObject {
|
public class BM3dObject : BMObject {
|
||||||
internal BM3dObject(nint raw_pointer, uint ckid) : base(raw_pointer, ckid) {}
|
internal BM3dObject(nint raw_pointer, uint ckid) : base(raw_pointer, ckid) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class BMGroup : BMObject {
|
public class BMGroup : BMObject {
|
||||||
internal BMGroup(nint raw_pointer, uint ckid) : base(raw_pointer, ckid) {}
|
internal BMGroup(nint raw_pointer, uint ckid) : base(raw_pointer, ckid) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
public sealed class BMFileReader : AbstractPointer {
|
public sealed class BMFileReader : AbstractPointer {
|
||||||
private static IntPtr AllocateHandle(string file_name, string temp_folder, string texture_folder, string[] encodings) {
|
private static IntPtr AllocateHandle(string file_name, string temp_folder, string texture_folder, string[] encodings) {
|
||||||
BMapException.ThrowIfFailed(BMap.BMFile_Load(
|
BMapException.ThrowIfFailed(BMap.BMFile_Load(
|
||||||
file_name, temp_folder, texture_folder,
|
file_name, temp_folder, texture_folder,
|
||||||
Utils.BMapSharpCallback,
|
Utils.BMapSharpCallback,
|
||||||
(uint)encodings.Length, encodings,
|
(uint)encodings.Length, encodings,
|
||||||
out IntPtr out_file
|
out IntPtr out_file
|
||||||
));
|
));
|
||||||
|
@ -199,67 +199,44 @@ namespace BMapSharp.BMapWrapper {
|
||||||
return BMap.BMFile_Free(this.handle);
|
return BMap.BMFile_Free(this.handle);
|
||||||
}
|
}
|
||||||
public BMFileReader(string file_name, string temp_folder, string texture_folder, string[] encodings)
|
public BMFileReader(string file_name, string temp_folder, string texture_folder, string[] encodings)
|
||||||
: base(AllocateHandle(file_name, temp_folder, texture_folder, encodings)) {}
|
: base(AllocateHandle(file_name, temp_folder, texture_folder, encodings)) { }
|
||||||
|
|
||||||
public uint GetTextureCount() {
|
|
||||||
BMapException.ThrowIfFailed(BMap.BMFile_GetTextureCount(this.getPointer(), out uint out_count));
|
private delegate bool FctProtoGetCount(nint bmf, out uint cnt);
|
||||||
|
private delegate bool FctProtoGetObject(nint bmf, uint idx, out uint id);
|
||||||
|
private delegate T FctProtoCreateInstance<T>(nint bmf, uint id);
|
||||||
|
private uint GetCKObjectCount(FctProtoGetCount fct_cnt) {
|
||||||
|
BMapException.ThrowIfFailed(fct_cnt(this.getPointer(), out uint out_count));
|
||||||
return out_count;
|
return out_count;
|
||||||
}
|
}
|
||||||
public IEnumerable<BMTexture> GetTextures() {
|
private IEnumerable<T> GetCKObjects<T>(FctProtoGetCount fct_cnt, FctProtoGetObject fct_obj, FctProtoCreateInstance<T> fct_crt) {
|
||||||
uint count = GetTextureCount();
|
uint count = GetCKObjectCount(fct_cnt);
|
||||||
for (uint i = 0; i < count; ++i) {
|
for (uint i = 0; i < count; ++i) {
|
||||||
BMapException.ThrowIfFailed(BMap.BMFile_GetTexture(this.getPointer(), i, out uint out_id));
|
BMapException.ThrowIfFailed(fct_obj(this.getPointer(), i, out uint out_id));
|
||||||
yield return new BMTexture(this.getPointer(), out_id);
|
yield return fct_crt(this.getPointer(), out_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public uint GetMaterialCount() {
|
public uint GetTextureCount() =>
|
||||||
BMapException.ThrowIfFailed(BMap.BMFile_GetMaterialCount(this.getPointer(), out uint out_count));
|
GetCKObjectCount(BMap.BMFile_GetTextureCount);
|
||||||
return out_count;
|
public IEnumerable<BMTexture> GetTextures() =>
|
||||||
}
|
GetCKObjects<BMTexture>(BMap.BMFile_GetTextureCount, BMap.BMFile_GetTexture, (bmf, id) => new BMTexture(bmf, id));
|
||||||
public IEnumerable<BMMaterial> GetMaterials() {
|
public uint GetMaterialCount() =>
|
||||||
uint count = GetMaterialCount();
|
GetCKObjectCount(BMap.BMFile_GetMaterialCount);
|
||||||
for (uint i = 0; i < count; ++i) {
|
public IEnumerable<BMMaterial> GetMaterials() =>
|
||||||
BMapException.ThrowIfFailed(BMap.BMFile_GetMaterial(this.getPointer(), i, out uint out_id));
|
GetCKObjects<BMMaterial>(BMap.BMFile_GetMaterialCount, BMap.BMFile_GetMaterial, (bmf, id) => new BMMaterial(bmf, id));
|
||||||
yield return new BMMaterial(this.getPointer(), out_id);
|
public uint GetMeshCount() =>
|
||||||
}
|
GetCKObjectCount(BMap.BMFile_GetMeshCount);
|
||||||
}
|
public IEnumerable<BMMesh> GetMeshes() =>
|
||||||
|
GetCKObjects<BMMesh>(BMap.BMFile_GetMeshCount, BMap.BMFile_GetMesh, (bmf, id) => new BMMesh(bmf, id));
|
||||||
public uint GetMeshCount() {
|
public uint Get3dObjectCount() =>
|
||||||
BMapException.ThrowIfFailed(BMap.BMFile_GetMeshCount(this.getPointer(), out uint out_count));
|
GetCKObjectCount(BMap.BMFile_Get3dObjectCount);
|
||||||
return out_count;
|
public IEnumerable<BM3dObject> Get3dObjects() =>
|
||||||
}
|
GetCKObjects<BM3dObject>(BMap.BMFile_Get3dObjectCount, BMap.BMFile_Get3dObject, (bmf, id) => new BM3dObject(bmf, id));
|
||||||
public IEnumerable<BMMesh> GetMeshes() {
|
public uint GetGroupCount() =>
|
||||||
uint count = GetMeshCount();
|
GetCKObjectCount(BMap.BMFile_GetGroupCount);
|
||||||
for (uint i = 0; i < count; ++i) {
|
public IEnumerable<BMGroup> GetGroups() =>
|
||||||
BMapException.ThrowIfFailed(BMap.BMFile_GetMesh(this.getPointer(), i, out uint out_id));
|
GetCKObjects<BMGroup>(BMap.BMFile_GetGroupCount, BMap.BMFile_GetGroup, (bmf, id) => new BMGroup(bmf, id));
|
||||||
yield return new BMMesh(this.getPointer(), out_id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public uint Get3dObjectCount() {
|
|
||||||
BMapException.ThrowIfFailed(BMap.BMFile_Get3dObjectCount(this.getPointer(), out uint out_count));
|
|
||||||
return out_count;
|
|
||||||
}
|
|
||||||
public IEnumerable<BM3dObject> Get3dObjects() {
|
|
||||||
uint count = Get3dObjectCount();
|
|
||||||
for (uint i = 0; i < count; ++i) {
|
|
||||||
BMapException.ThrowIfFailed(BMap.BMFile_Get3dObject(this.getPointer(), i, out uint out_id));
|
|
||||||
yield return new BM3dObject(this.getPointer(), out_id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public uint GetGroupCount() {
|
|
||||||
BMapException.ThrowIfFailed(BMap.BMFile_GetGroupCount(this.getPointer(), out uint out_count));
|
|
||||||
return out_count;
|
|
||||||
}
|
|
||||||
public IEnumerable<BMGroup> GetGroups() {
|
|
||||||
uint count = GetGroupCount();
|
|
||||||
for (uint i = 0; i < count; ++i) {
|
|
||||||
BMapException.ThrowIfFailed(BMap.BMFile_GetGroup(this.getPointer(), i, out uint out_id));
|
|
||||||
yield return new BMGroup(this.getPointer(), out_id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
14
COMPILE.md
14
COMPILE.md
|
@ -42,7 +42,7 @@ First, create subdirectory `Bin/build` and `Bin/install`.
|
||||||
|
|
||||||
Then enter subdirectory `Bin/build` and use following command to configure CMake:
|
Then enter subdirectory `Bin/build` and use following command to configure CMake:
|
||||||
|
|
||||||
- Windows: `cmake -DNEMO_BUILD_UNVIRT=ON -DNEMO_BUILD_BMAP=ON -DNEMO_BUILD_DOC=OFF -DSTB_IMAGE_PATH=<path-to-stb> -DYYCC_PATH=<path-to-yycc-install> -DZLIB_HEADER_PATH=<path-to-zlib-hdr> -DZLIB_BINARY_PATH=<path-to-zlib-bin> ../..`
|
- Windows (MSVC): `cmake -DNEMO_BUILD_UNVIRT=ON -DNEMO_BUILD_BMAP=ON -DNEMO_BUILD_DOC=OFF -DSTB_IMAGE_PATH=<path-to-stb> -DYYCC_PATH=<path-to-yycc-install> -DZLIB_HEADER_PATH=<path-to-zlib-hdr> -DZLIB_BINARY_PATH=<path-to-zlib-bin> ../..`
|
||||||
- non-Windows: `cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DNEMO_BUILD_UNVIRT=ON -DNEMO_BUILD_BMAP=ON -DNEMO_BUILD_DOC=OFF -DSTB_IMAGE_PATH=<path-to-stb> -DYYCC_PATH=<path-to-yycc-install> ../..`
|
- non-Windows: `cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DNEMO_BUILD_UNVIRT=ON -DNEMO_BUILD_BMAP=ON -DNEMO_BUILD_DOC=OFF -DSTB_IMAGE_PATH=<path-to-stb> -DYYCC_PATH=<path-to-yycc-install> ../..`
|
||||||
|
|
||||||
The arguments in command should be replaced by:
|
The arguments in command should be replaced by:
|
||||||
|
@ -62,8 +62,8 @@ The switches in command can be switched as you wish:
|
||||||
|
|
||||||
Execute following command to build libcmo21.
|
Execute following command to build libcmo21.
|
||||||
|
|
||||||
* Windows:`cmake --build . --config RelWithDebInfo`
|
* Windows: `cmake --build . --config RelWithDebInfo`
|
||||||
* non-Windows:`cmake --build .`
|
* non-Windows: `cmake --build .`
|
||||||
|
|
||||||
### Build Type
|
### Build Type
|
||||||
|
|
||||||
|
@ -76,11 +76,3 @@ Currently the CMake install script still has some bugs and can not work as expec
|
||||||
## Note
|
## Note
|
||||||
|
|
||||||
You may face issue when compiling this program on Linux or macOS because I develop this project on Windows frequently. The compatibility with Linux will only be checked just before releasing. And I don't have any Apple device to check the compatibility with macOS. So, for Linux issue, please report it directly and I will try to fix. For macOS bug, PR is welcomed.
|
You may face issue when compiling this program on Linux or macOS because I develop this project on Windows frequently. The compatibility with Linux will only be checked just before releasing. And I don't have any Apple device to check the compatibility with macOS. So, for Linux issue, please report it directly and I will try to fix. For macOS bug, PR is welcomed.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
It can be compiled on Windows via sln file. You should set up `LibRef.props` when using sln file to build this project on Windows.
|
|
||||||
You also can use CMake file to compile this project on Linux or anything else platform. However CMake may not be updated in time because I develop this project on Windows frequently.
|
|
||||||
You may need use this command to configure CMake: `cmake .. -DSTB_IMAGE_PATH="/path/to/stb-image" -DCMAKE_BUILD_TYPE=Release`
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user