Skip to content

Commit

Permalink
[fcelib] bump to version 1.8, remove unused branch, refactor, misc
Browse files Browse the repository at this point in the history
  • Loading branch information
bfut committed Aug 8, 2024
1 parent 36e984b commit fb030b7
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 200 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/linux.yaml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
allow-prereleases: true # 3.13
cache: pip

- name: "pip install"
shell: bash
Expand All @@ -42,6 +44,7 @@ jobs:
- name: "Install requirements"
shell: bash
timeout-minutes: 1
run: |
python -m pip install numpy
python -m pip install pytest
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/macos.yaml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
allow-prereleases: true # 3.13
cache: pip

- name: "pip install"
shell: bash
Expand All @@ -42,6 +44,7 @@ jobs:
- name: "Install requirements"
shell: bash
timeout-minutes: 1
run: |
python -m pip install numpy
python -m pip install pytest
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/windows.yaml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
allow-prereleases: true # 3.13
cache: pip

- name: "pip install"
shell: bash
Expand All @@ -42,6 +44,7 @@ jobs:
- name: "Install requirements"
shell: bash
timeout-minutes: 1
run: |
python -m pip install numpy
python -m pip install pytest
Expand Down
4 changes: 2 additions & 2 deletions python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ python -m pip install --upgrade numpy
See<br/>
[https://github.com/bfut/fcecodec/blob/main/scripts](https://github.com/bfut/fcecodec/blob/main/scripts)<br/>
and<br/>
[https://github.com/bfut/fcecodec/blob/main/python/bfut_mywrappers.py](https://github.com/bfut/fcecodec/blob/main/python/bfut_mywrappers.py)
[https://github.com/bfut/fcecodec/blob/main/scripts/bfut_mywrappers.py](https://github.com/bfut/fcecodec/blob/main/scripts/bfut_mywrappers.py)

## Documentation
```
Expand Down Expand Up @@ -258,5 +258,5 @@ FUNCTIONS
Returns 1 for valid FCE data, 0 otherwise.
VERSION
1.7
1.8
```
10 changes: 5 additions & 5 deletions python/fcecodecmodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class Mesh : public FcelibMesh

void Mesh::IoDecode(const std::string &buf)
{
if (!FCELIB_DecodeFce(buf.c_str(), buf.size(), &mesh_))
if (!FCELIB_DecodeFce(&mesh_, buf.c_str(), buf.size()))
throw std::runtime_error("IoDecode: Cannot parse FCE data");
}

Expand All @@ -160,7 +160,7 @@ py::bytes Mesh::IoEncode_Fce3(const bool center_parts) const
unsigned char *buf_ = (unsigned char *)malloc(bufsize_ * sizeof(*buf_));
if (!buf_)
throw std::runtime_error("IoEncode_Fce3: Cannot allocate memory");
if (!FCELIB_EncodeFce3(&buf_, bufsize_, &mesh_, static_cast<int>(center_parts)))
if (!FCELIB_EncodeFce3(&mesh_, &buf_, bufsize_, static_cast<int>(center_parts)))
throw std::runtime_error("IoEncode_Fce3: Cannot encode FCE3");
py::bytes result = py::bytes((char *)buf_, bufsize_);
free(buf_);
Expand All @@ -173,7 +173,7 @@ py::bytes Mesh::IoEncode_Fce4(const bool center_parts) const
unsigned char *buf_ = (unsigned char *)malloc(bufsize_ * sizeof(*buf_));
if (!buf_)
throw std::runtime_error("IoEncode_Fce4: Cannot allocate memory");
if (!FCELIB_EncodeFce4(&buf_, bufsize_, &mesh_, static_cast<int>(center_parts)))
if (!FCELIB_EncodeFce4(&mesh_, &buf_, bufsize_, static_cast<int>(center_parts)))
throw std::runtime_error("IoEncode_Fce4: Cannot encode FCE4");
py::bytes result = py::bytes((char *)buf_, bufsize_);
free(buf_);
Expand All @@ -186,7 +186,7 @@ py::bytes Mesh::IoEncode_Fce4M(const bool center_parts) const
unsigned char *buf_ = (unsigned char *)malloc(bufsize_ * sizeof(*buf_));
if (!buf_)
throw std::runtime_error("IoEncode_Fce4M: Cannot allocate memory");
if (!FCELIB_EncodeFce4M(&buf_, bufsize_, &mesh_, static_cast<int>(center_parts)))
if (!FCELIB_EncodeFce4M(&mesh_, &buf_, bufsize_, static_cast<int>(center_parts)))
throw std::runtime_error("IoEncode_Fce4M: Cannot encode FCE4M");
py::bytes result = py::bytes((char *)buf_, bufsize_);
free(buf_);
Expand Down Expand Up @@ -1150,7 +1150,7 @@ void FCECODECMODULE_PrintFceInfo(const std::string &buf)
{
if (buf.size() < 0x1F04)
throw std::runtime_error("PrintFceInfo: Invalid buffer size (expects >= 0x1F04)");
FCELIB_PrintFceInfo(buf.size(), std::move(buf.c_str()));
FCELIB_PrintFceInfo(buf.c_str(), buf.size());
}

// fcecodec.
Expand Down
8 changes: 6 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,26 @@
if "FCELIB_PYTHON_DEBUG" in os.environ:
print(f'FCELIB_PYTHON_DEBUG={os.environ["FCELIB_PYTHON_DEBUG"]}')
extra_compile_args += [ "-FCELIB_PYTHON_DEBUG" ]
if platform.system() == "Windows":
if platform.system().lower() == "windows":
extra_compile_args += [
("/D_CRT_NONSTDC_NO_WARNINGS"),
("/wd4267"), # prevents warnings on conversion from size_t to int
("/std:c++latest"), ("/Zc:__cplusplus"), # sets __cplusplus
]
else:
extra_compile_args += [
# # debug
# ("-g"), ("-O0"),
("-pedantic-errors"),
# ("-pedantic-errors"),
("-fvisibility=hidden"), # sets the default symbol visibility to hidden
("-Wformat-security"),
("-Wdeprecated-declarations"),
]

if "gcc" in platform.python_compiler().lower():
extra_compile_args += [
# ("-I/usr/include/python3.11"), # DEBUG

("-Wno-unused-parameter"),
("-Wno-missing-field-initializers"),

Expand Down Expand Up @@ -98,6 +101,7 @@
extra_compile_args += [
# ("-Weverything"),
("-Wno-braced-scalar-init"),
("-Wno-deprecated-declarations"),
# ("-Wno-newline-eof"),
]

Expand Down
51 changes: 24 additions & 27 deletions src/fcelib/fcelib.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,19 @@
*/

/**
high level library interface: only functions from this header for external use, never for internal use
public-only interface. include this header in your project to use fcelib.
fcelib_fcetypes.h defines FCE structs and includes extensive FCE format documentation
fcelib_types.h defines library structs
"TODO:" in comments marks nitpicks
fcelib_types.h defines struct FcelibMesh
usage:
#include "fcelib.h"
...
FcelibMesh mesh;
if (!FCELIB_InitMesh(&mesh))
return EXIT_FAILURE;
// workload
FCELIB_FreeMesh(&mesh);
**/

#ifndef FCELIB_H_
Expand All @@ -34,10 +41,9 @@
#include <stdio.h>
#include <string.h>

#define FCECVERS "1.7"
#define FCECVERS "1.8"
#ifndef FCECVERBOSE
#define FCECVERBOSE 0 /* >=1 for verbose console output */
/* #define FCEC_STATE */ /* feature branch */
#endif

#include "./fcelib_io.h"
Expand Down Expand Up @@ -98,25 +104,22 @@ int FCELIB_CenterPart(FcelibMesh *mesh, const int idx)
return FCELIB_OP_CenterPart(mesh, idx);
}

int FCELIB_SetPartCenter(FcelibMesh *mesh, const int pidx,
const float new_center[3])
int FCELIB_SetPartCenter(FcelibMesh *mesh, const int pidx, const float new_center[3])
{
return FCELIB_OP_SetPartCenter(mesh, pidx, new_center);
}

int FCELIB_CopyPartToMesh(FcelibMesh *mesh_rcv, FcelibMesh *mesh_src,
const int idx)
int FCELIB_CopyPartToMesh(FcelibMesh *mesh_dest, FcelibMesh *mesh_src, const int idx)
{
return FCELIB_OP_CopyPartToMesh(mesh_rcv, mesh_src, idx);
return FCELIB_OP_CopyPartToMesh(mesh_dest, mesh_src, idx);
}

int FCELIB_DeletePart(FcelibMesh *mesh, const int idx)
{
return FCELIB_OP_DeletePart(mesh, idx);
}

int FCELIB_DeletePartTriags(FcelibMesh *mesh, const int pidx,
const int *idxs, const int idxs_len)
int FCELIB_DeletePartTriags(FcelibMesh *mesh, const int pidx, const int *idxs, const int idxs_len)
{
return FCELIB_OP_DeletePartTriags(mesh, pidx, idxs, idxs_len);
}
Expand Down Expand Up @@ -144,16 +147,13 @@ int FCELIB_FceComputeSize(const FcelibMesh *mesh, const int target_fce_version)
switch (target_fce_version)
{
case 4:
return FCELIB_FCETYPES_Fce4ComputeSize(0x00101014, mesh->hdr.NumVertices,
mesh->hdr.NumTriangles);
return FCELIB_FCETYPES_Fce4ComputeSize(0x00101014, mesh->hdr.NumVertices, mesh->hdr.NumTriangles);
break;
case 5:
return FCELIB_FCETYPES_Fce4ComputeSize(0x00101015, mesh->hdr.NumVertices,
mesh->hdr.NumTriangles);
return FCELIB_FCETYPES_Fce4ComputeSize(0x00101015, mesh->hdr.NumVertices, mesh->hdr.NumTriangles);
break;
default:
return FCELIB_FCETYPES_Fce3ComputeSize(mesh->hdr.NumVertices,
mesh->hdr.NumTriangles);
return FCELIB_FCETYPES_Fce3ComputeSize(mesh->hdr.NumVertices, mesh->hdr.NumTriangles);
break;
}
}
Expand All @@ -163,7 +163,7 @@ int FCELIB_GetFceVersion(const void *buf, const int length)
return FCELIB_FCETYPES_GetFceVersion(buf, length);
}

void FCELIB_PrintFceInfo(const int fce_size, const void *hdr)
void FCELIB_PrintFceInfo(const void *hdr, const int fce_size)
{
switch (FCELIB_FCETYPES_GetFceVersion(hdr, fce_size))
{
Expand Down Expand Up @@ -199,7 +199,7 @@ int FCELIB_ValidateFce(const void *buf, const int length)
}
}

int FCELIB_DecodeFce(const void *buf, int buf_size, FcelibMesh *mesh)
int FCELIB_DecodeFce(FcelibMesh *mesh, const void *buf, int buf_size)
{
return FCELIB_IO_DecodeFce(mesh, (const unsigned char *)buf, buf_size);
}
Expand All @@ -218,20 +218,17 @@ int FCELIB_ExportObj(const FcelibMesh *mesh,
filter_triagflags_0xfff);
}

int FCELIB_EncodeFce3(unsigned char **buf, const int buf_size,
FcelibMesh *mesh, const int center_parts)
int FCELIB_EncodeFce3(FcelibMesh *mesh, unsigned char **buf, const int buf_size, const int center_parts)
{
return FCELIB_IO_EncodeFce3(mesh, buf, buf_size, center_parts);
}

int FCELIB_EncodeFce4(unsigned char **buf, const int buf_size,
FcelibMesh *mesh, const int center_parts)
int FCELIB_EncodeFce4(FcelibMesh *mesh, unsigned char **buf, const int buf_size, const int center_parts)
{
return FCELIB_IO_EncodeFce4(mesh, buf, buf_size, center_parts, 0x00101014);
}

int FCELIB_EncodeFce4M(unsigned char **buf, const int buf_size,
FcelibMesh *mesh, const int center_parts)
int FCELIB_EncodeFce4M(FcelibMesh *mesh, unsigned char **buf, const int buf_size, const int center_parts)
{
return FCELIB_IO_EncodeFce4(mesh, buf, buf_size, center_parts, 0x00101015);
}
Expand Down
21 changes: 5 additions & 16 deletions src/fcelib/fcelib_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -1893,23 +1893,12 @@ int FCELIB_IO_GeomDataToNewPart(FcelibMesh *mesh,
}

/* Add part */
#ifdef FCEC_STATE
if (mesh->state & kFceLibFlagPartsDirty)
#else
if (1)
#endif
{
mesh->hdr.Parts[new_pid] = 1 + FCELIB_UTIL_ArrMax(mesh->hdr.Parts, mesh->parts_len);
if (mesh->hdr.Parts[new_pid] < 0)
{
fprintf(stderr, "GeomDataToNewPart: Cannot set new part index\n");
new_pid = -1;
break;
}
}
else
mesh->hdr.Parts[new_pid] = 1 + FCELIB_UTIL_ArrMax(mesh->hdr.Parts, mesh->parts_len);
if (mesh->hdr.Parts[new_pid] < 0)
{
mesh->hdr.Parts[new_pid] = mesh->hdr.NumParts;
fprintf(stderr, "GeomDataToNewPart: Cannot set new part index\n");
new_pid = -1;
break;
}

part = (FcelibPart *)malloc(sizeof(*part));
Expand Down
24 changes: 0 additions & 24 deletions src/fcelib/fcelib_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,6 @@ int FCELIB_OP_CopyPartToMesh(FcelibMesh *mesh_dest, FcelibMesh *mesh_src, const

for (;;)
{
#ifdef FCEC_STATE
/* TODO: this is a defensive assumption. this function may not be dirty'ing at all */
mesh_dest->state |= (kFceLibFlagPartsDirty | kFceLibFlagVerticesDirty | kFceLibFlagTrianglesDirty);
#endif

/* Lengthen part index map only if necessary */
if (!mesh_dest->hdr.Parts)
{
Expand Down Expand Up @@ -366,10 +361,6 @@ int FCELIB_OP_DeletePart(FcelibMesh *mesh, const int idx)
mesh->parts[ mesh->hdr.Parts[internal_idx] ] = NULL;
mesh->hdr.Parts[internal_idx] = -1;

#ifdef FCEC_STATE
mesh->state |= (kFceLibFlagPartsDirty | kFceLibFlagVerticesDirty | kFceLibFlagTrianglesDirty);
#endif

retv = 1;
break;
} /* for (;;) */
Expand Down Expand Up @@ -446,10 +437,6 @@ int FCELIB_OP_DeletePartTriags(FcelibMesh *mesh, const int pidx, const int *idxs
mesh->hdr.NumTriangles -= idxs_len;
free(map);

#ifdef FCEC_STATE
mesh->state |= kFceLibFlagTrianglesDirty;
#endif

retv = 1;
break;
} /* for (;;) */
Expand Down Expand Up @@ -500,9 +487,6 @@ int FCELIB_OP_DeleteUnrefdVerts(FcelibMesh *mesh)
part->PVertices[j] = -1;
--part->PNumVertices;
--mesh->hdr.NumVertices;
#ifdef FCEC_STATE
mesh->state |= kFceLibFlagVerticesDirty;
#endif
}
}

Expand Down Expand Up @@ -549,11 +533,6 @@ int FCELIB_OP_MergePartsToNew(FcelibMesh *mesh, const int pid1, const int pid2)

for (;;)
{
#ifdef FCEC_STATE
/* TODO: this is a defensive assumption. this function may not be dirty'ing at all */
mesh->state |= (kFceLibFlagPartsDirty | kFceLibFlagVerticesDirty | kFceLibFlagTrianglesDirty);
#endif

if (mesh->hdr.Parts[mesh->parts_len - 1] >= 0)
{
if (!FCELIB_TYPES_AddParts(mesh, 1))
Expand Down Expand Up @@ -775,9 +754,6 @@ int FCELIB_OP_MoveUpPart(FcelibMesh *mesh, const int idx)
const int tmp = mesh->hdr.Parts[internal_index_idx];
mesh->hdr.Parts[internal_index_idx] = mesh->hdr.Parts[internal_index_j];
mesh->hdr.Parts[internal_index_j] = tmp;
#ifdef FCEC_STATE
mesh->state |= kFceLibFlagPartsDirty;
#endif
}

return idx - 1;
Expand Down
Loading

0 comments on commit fb030b7

Please sign in to comment.