Skip to content

Commit

Permalink
[fcelib] bump to version 1.9, reduce fluff
Browse files Browse the repository at this point in the history
  • Loading branch information
bfut committed Aug 9, 2024
1 parent fb030b7 commit e2c2baa
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 72 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,4 @@ __Website:__ <https://github.com/bfut/fcecodec>
Third party licenses

__sclpython.h:__ zlib License<br/>
__fcecodec scripts:__ zlib License<br/>
__bfut_mywrappers.py:__ zlib License
__fcecodec scripts:__ zlib License
2 changes: 1 addition & 1 deletion python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -258,5 +258,5 @@ FUNCTIONS
Returns 1 for valid FCE data, 0 otherwise.
VERSION
1.8
1.9
```
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
# # debug
# ("-g"), ("-O0"),
# ("-pedantic-errors"),
("-pedantic"),
("-fvisibility=hidden"), # sets the default symbol visibility to hidden
("-Wformat-security"),
("-Wdeprecated-declarations"),
Expand Down
2 changes: 1 addition & 1 deletion src/fcelib/fcelib.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
#include <stdio.h>
#include <string.h>

#define FCECVERS "1.8"
#define FCECVERS "1.9"
#ifndef FCECVERBOSE
#define FCECVERBOSE 0 /* >=1 for verbose console output */
#endif
Expand Down
29 changes: 4 additions & 25 deletions src/fcelib/fcelib_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,6 @@ int __FCELIB_IO_DECODE_GETPARTS(FcelibMesh *mesh, const char *header_PartNames,
Params: FCE buffer, FcelibMesh. Returns bool.
Assumes (mesh != NULL). Silently releases and re-initializes existing mesh.
Assumes valid FCE data.
C API: mesh must have been initialized
*/
int FCELIB_IO_DecodeFce(FcelibMesh *mesh, const unsigned char *buf, int buf_size)
{
Expand All @@ -161,24 +159,17 @@ int FCELIB_IO_DecodeFce(FcelibMesh *mesh, const unsigned char *buf, int buf_size
break;
}

#ifdef __cplusplus
if (mesh->_consumed && mesh->release == &FCELIB_TYPES_FreeMesh)
if (mesh->release == &FCELIB_TYPES_FreeMesh)
{
mesh->release(mesh);
FCELIB_TYPES_InitMesh(mesh);
}
#ifndef FCELIB_PYTHON_BINDINGS
else if (!mesh->release)
FCELIB_TYPES_InitMesh(mesh);
else if (mesh->_consumed || mesh->release != &FCELIB_TYPES_FreeMesh)
else if (!mesh->release || mesh->release != &FCELIB_TYPES_FreeMesh)
{
fprintf(stderr, "DecodeFce: mesh is not free and cannot be initialized.\n");
break;
FCELIB_TYPES_InitMesh(mesh);
}
#endif
#endif

mesh->_consumed = 1;

if (buf_size < 0x1F04)
{
Expand Down Expand Up @@ -1792,7 +1783,7 @@ int FCELIB_IO_EncodeFce4(FcelibMesh *mesh, unsigned char **outbuf, const int buf
}

/*
Assumes (mesh != NULL). If necessary, will initialize mesh.
Assumes (mesh != NULL).
Otherwise, expects non-NULL parameters.
vert_idxs: 012...
Expand Down Expand Up @@ -1827,20 +1818,8 @@ int FCELIB_IO_GeomDataToNewPart(FcelibMesh *mesh,
fprintf(stderr, "DecodeFce: an input is NULL\n");
break;
}

#ifdef __cplusplus
if (!mesh->release)
FCELIB_TYPES_InitMesh(mesh);
else if (mesh->release != &FCELIB_TYPES_FreeMesh)
{
fprintf(stderr, "DecodeFce: mesh is not free and cannot be initialized.\n");
break;
}
#endif
#endif

mesh->_consumed = 1;

if (vert_idxs_len % 3 != 0)
{
fprintf(stderr, "GeomDataToNewPart: Expects N*3 == vert_idxs_len, for N triangles.\n");
Expand Down
42 changes: 8 additions & 34 deletions src/fcelib/fcelib_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,6 @@ struct FcelibHeader {
};

struct FcelibMesh {
#ifdef __cplusplus
int _consumed = 0; /* previously decoded? yes/no 1/0, internal fcelib use only */
#else
int _consumed; /* previously decoded? yes/no 1/0, internal fcelib use only */
#endif

int parts_len; /* capacity: array length */
int triangles_len; /* capacity: array length */
int vertices_len; /* capacity: array length */
Expand All @@ -125,11 +119,7 @@ struct FcelibMesh {
FcelibTriangle **triangles; /* may contain NULL elements */
FcelibVertex **vertices; /* may contain NULL elements */

#ifdef __cplusplus
void (*release)(struct FcelibMesh*) = NULL;
#else
void (*release)(struct FcelibMesh*);
#endif
};

#ifdef __cplusplus
Expand All @@ -138,7 +128,11 @@ struct FcelibMesh {

/* release, init, validate -------------------------------------------------- */

/* Call via mesh->release(), never directly. */
/*
Call via mesh->release(), never directly.
Afterwards (!mesh->release).
*/
void FCELIB_TYPES_FreeMesh(FcelibMesh *mesh)
{
int i;
Expand Down Expand Up @@ -184,39 +178,22 @@ void FCELIB_TYPES_FreeMesh(FcelibMesh *mesh)
if (mesh->triangles) free(mesh->triangles);
if (mesh->vertices) free(mesh->vertices);

#ifdef __cplusplus
*mesh = {};
#else
memset(mesh, 0, sizeof(*mesh));
#endif
mesh->release = NULL;
}

/*
Assumes (mesh != NULL). Silently re-initializes.
C API: mesh must have been initialized
Assumes (mesh). memset's mesh to 0. Silently re-initializes.
*/
FcelibMesh *FCELIB_TYPES_InitMesh(FcelibMesh *mesh)
{
#ifndef FCELIB_PYTHON_BINDINGS
#ifdef __cplusplus
if (mesh->release == &FCELIB_TYPES_FreeMesh)
mesh->release(mesh);
if (mesh->release && mesh->release != &FCELIB_TYPES_FreeMesh)
{
fprintf(stderr, "InitMesh: mesh is not free and cannot be initialized.\n");
return NULL;
}
#endif
#endif

#ifdef __cplusplus
*mesh = {};
#else
memset(mesh, 0, sizeof(*mesh));
/* array_dirty = 0; */
#endif

mesh->hdr.NumArts = 1;
mesh->release = &FCELIB_TYPES_FreeMesh;
return mesh;
Expand All @@ -232,10 +209,7 @@ int FCELIB_TYPES_ValidateMesh(const FcelibMesh *mesh)
int sum_verts = 0;
FcelibPart *part = NULL;

if (!mesh->release)
return 0;
if (mesh->release != &FCELIB_TYPES_FreeMesh)
return 0;
if (!mesh->release || mesh->release != &FCELIB_TYPES_FreeMesh) return 0;

if (mesh->parts_len == 0 && !mesh->parts && !mesh->hdr.Parts &&
mesh->triangles_len == 0 && !mesh->triangles &&
Expand Down
11 changes: 2 additions & 9 deletions src/fcelib/fcelib_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,8 @@
#include <stdlib.h>
#include <string.h>

#ifndef __cplusplus
enum { kFceLibImplementedFce3Parts = 13 };
enum { kFceLibNumFce4HiBodyParts = 18 };
#else
static const int kFceLibImplementedFce3Parts = 13;
static const int kFceLibNumFce4HiBodyParts = 18;
#endif
#define kFceLibImplementedFce3Parts 13
#define kFceLibNumFce4HiBodyParts 18

/* Represent FCE dummies (light/fx objects)
Mainly used for OBJ output, hence kTrianglesDiamond has 1-based indexes. */
Expand All @@ -58,10 +53,8 @@ const int kTrianglesDiamond[8 * 3] = {
4, 5, 1
};

#ifndef FCELIB_UTIL_Min
#define FCELIB_UTIL_Min(x,y) ((x)<(y)?(x):(y))
#define FCELIB_UTIL_Abs(x) ((x)<0 ? -(x) : (x))
#endif

const char *FCELIB_UTIL_GetLastSlash(const char *path)
{
Expand Down

0 comments on commit e2c2baa

Please sign in to comment.