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

Refactor typing; fix crash in /set #36

Merged
merged 7 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions include/libtrx/bson.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,28 @@

#include "json.h"

enum bson_parse_error_e {
bson_parse_error_none = 0,
bson_parse_error_invalid_value,
bson_parse_error_premature_end_of_buffer,
bson_parse_error_unexpected_trailing_bytes,
bson_parse_error_unknown,
};
typedef enum {
BSON_PARSE_ERROR_NONE = 0,
BSON_PARSE_ERROR_INVALID_VALUE,
BSON_PARSE_ERROR_PREMATURE_END_OF_BUFFER,
BSON_PARSE_ERROR_UNEXPECTED_TRAILING_BYTES,
BSON_PARSE_ERROR_UNKNOWN,
} BSON_PARSE_ERROR;

struct bson_parse_result_s {
enum bson_parse_error_e error;
typedef struct {
BSON_PARSE_ERROR error;
size_t error_offset;
};
} BSON_PARSE_RESULT;

// Parse a BSON file, returning a pointer to the root of the JSON structure.
// Returns NULL if an error occurred (malformed BSON input, or malloc failed).
struct json_value_s *bson_parse(const char *src, size_t src_size);
JSON_VALUE *BSON_Parse(const char *src, size_t src_size);

struct json_value_s *bson_parse_ex(
const char *src, size_t src_size, struct bson_parse_result_s *result);
JSON_VALUE *BSON_ParseEx(
const char *src, size_t src_size, BSON_PARSE_RESULT *result);

const char *bson_get_error_description(enum bson_parse_error_e error);
const char *BSON_GetErrorDescription(BSON_PARSE_ERROR error);

/* Write out a BSON binary string. Return 0 if an error occurred (malformed
* JSON input, or malloc failed). The out_size parameter is optional. */
void *bson_write(const struct json_value_s *value, size_t *out_size);
void *BSON_Write(const JSON_VALUE *value, size_t *out_size);
14 changes: 6 additions & 8 deletions include/libtrx/config/config_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,17 @@
#include <stdbool.h>
#include <stdint.h>

bool ConfigFile_Read(
const char *path, void (*load)(struct json_object_s *root_obj));
bool ConfigFile_Write(
const char *path, void (*dump)(struct json_object_s *root_obj));
bool ConfigFile_Read(const char *path, void (*load)(JSON_OBJECT *root_obj));
bool ConfigFile_Write(const char *path, void (*dump)(JSON_OBJECT *root_obj));

void ConfigFile_LoadOptions(
struct json_object_s *root_obj, const CONFIG_OPTION *options);
JSON_OBJECT *root_obj, const CONFIG_OPTION *options);
void ConfigFile_DumpOptions(
struct json_object_s *root_obj, const CONFIG_OPTION *options);
JSON_OBJECT *root_obj, const CONFIG_OPTION *options);

int ConfigFile_ReadEnum(
struct json_object_s *obj, const char *name, int default_value,
JSON_OBJECT *obj, const char *name, int default_value,
const ENUM_STRING_MAP *enum_map);
void ConfigFile_WriteEnum(
struct json_object_s *obj, const char *name, int value,
JSON_OBJECT *obj, const char *name, int value,
const ENUM_STRING_MAP *enum_map);
2 changes: 1 addition & 1 deletion include/libtrx/config/config_option.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

typedef enum CONFIG_OPTION_TYPE {
typedef enum {
COT_BOOL = 0,
COT_INT32 = 1,
COT_FLOAT = 2,
Expand Down
2 changes: 1 addition & 1 deletion include/libtrx/game/console/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ typedef enum {
CR_BAD_INVOCATION,
} COMMAND_RESULT;

typedef struct {
typedef struct __PACKING {
const struct __PACKING CONSOLE_COMMAND *cmd;
const char *prefix;
const char *args;
Expand Down
6 changes: 3 additions & 3 deletions include/libtrx/game/creature.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ typedef struct __PACKING {
LOT_INFO lot;
XYZ_32 target;
#if TR_VERSION == 2
ITEM_INFO *enemy;
ITEM *enemy;
#endif
} CREATURE_INFO;
} CREATURE;

bool Creature_IsEnemy(const ITEM_INFO *item);
bool Creature_IsEnemy(const ITEM *item);
2 changes: 1 addition & 1 deletion include/libtrx/game/effects/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ typedef struct __PACKING {
} result, prev;
} interp;
#endif
} FX_INFO;
} FX;
6 changes: 3 additions & 3 deletions include/libtrx/game/items/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include <stdbool.h>

ITEM_INFO *Item_Get(int16_t num);
ITEM *Item_Get(int16_t num);
int32_t Item_GetTotalCount(void);
int32_t Item_GetDistance(const ITEM_INFO *item, const XYZ_32 *target);
void Item_TakeDamage(ITEM_INFO *item, int16_t damage, bool hit_status);
int32_t Item_GetDistance(const ITEM *item, const XYZ_32 *target);
void Item_TakeDamage(ITEM *item, int16_t damage, bool hit_status);
6 changes: 3 additions & 3 deletions include/libtrx/game/items/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ typedef struct __PACKING {
void *priv;
CARRIED_ITEM *carried_item;
#elif TR_VERSION == 2
int16_t shade1;
int16_t shade2;
int16_t shade_1;
int16_t shade_2;
int16_t carried_item;
void *data;
#endif
Expand Down Expand Up @@ -78,4 +78,4 @@ typedef struct __PACKING {
} result, prev;
} interp;
#endif
} ITEM_INFO;
} ITEM;
2 changes: 1 addition & 1 deletion include/libtrx/game/lara/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
#include "types.h"

LARA_INFO *Lara_GetLaraInfo(void);
ITEM_INFO *Lara_GetItem(void);
ITEM *Lara_GetItem(void);
2 changes: 1 addition & 1 deletion include/libtrx/game/lara/enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ typedef enum {
} LARA_GUN_STATE;
// clang-format on

typedef enum LARA_MESH {
typedef enum {
LM_HIPS = 0,
LM_THIGH_L = 1,
LM_CALF_L = 2,
Expand Down
10 changes: 5 additions & 5 deletions include/libtrx/game/lara/enum_tr1.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

// clang-format off
typedef enum LARA_SHOTGUN_ANIMATION_FRAME {
typedef enum {
LF_SG_AIM_START = 0,
LF_SG_AIM_BEND = 1,
LF_SG_AIM_END = 12,
Expand All @@ -24,7 +24,7 @@ typedef enum LARA_SHOTGUN_ANIMATION_FRAME {
// clang-format on

// clang-format off
typedef enum LARA_GUN_ANIMATION_FRAME {
typedef enum {
LF_G_AIM_START = 0,
LF_G_AIM_BEND = 1,
LF_G_AIM_EXTEND = 3,
Expand All @@ -40,7 +40,7 @@ typedef enum LARA_GUN_ANIMATION_FRAME {
// clang-format on

// clang-format off
typedef enum LARA_ANIMATION {
typedef enum {
LA_RUN = 0,
LA_WALK_FORWARD = 1,
LA_RUN_START = 6,
Expand Down Expand Up @@ -93,7 +93,7 @@ typedef enum LARA_ANIMATION {
} LARA_ANIMATION;

// clang-format off
typedef enum LARA_STATE {
typedef enum {
LS_WALK = 0,
LS_RUN = 1,
LS_STOP = 2,
Expand Down Expand Up @@ -157,7 +157,7 @@ typedef enum LARA_STATE {
// clang-format on

// clang-format off
typedef enum LARA_GUN_TYPE {
typedef enum {
LGT_UNKNOWN = -1, // for legacy saves
LGT_UNARMED = 0,
LGT_PISTOLS = 1,
Expand Down
12 changes: 6 additions & 6 deletions include/libtrx/game/lara/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ typedef struct __PACKING {
LARA_GUN_TYPE holsters_gun_type;
LARA_GUN_TYPE back_gun_type;
int16_t calc_fall_speed;
int16_t water_status;
LARA_WATER_STATE water_status;
int16_t pose_count;
int16_t hit_frame;
int16_t hit_direction;
Expand All @@ -45,10 +45,10 @@ typedef struct __PACKING {
int16_t death_timer;
int16_t current_active;
int16_t spaz_effect_count;
FX_INFO *spaz_effect;
FX *spaz_effect;
int32_t mesh_effects;
int16_t *mesh_ptrs[LM_NUMBER_OF];
ITEM_INFO *target;
ITEM *target;
int16_t target_angles[2];
int16_t turn_rate;
int16_t move_angle;
Expand Down Expand Up @@ -125,10 +125,10 @@ typedef struct __PACKING {
// clang-format on
int32_t water_surface_dist;
XYZ_32 last_pos;
FX_INFO *spaz_effect;
FX *spaz_effect;
uint32_t mesh_effects;
int16_t *mesh_ptrs[15];
ITEM_INFO *target;
ITEM *target;
int16_t target_angles[2];
int16_t turn_rate;
int16_t move_angle;
Expand All @@ -147,7 +147,7 @@ typedef struct __PACKING {
AMMO_INFO harpoon_ammo;
AMMO_INFO grenade_ammo;
AMMO_INFO m16_ammo;
CREATURE_INFO *creature;
CREATURE *creature;
} LARA_INFO;

#endif
2 changes: 1 addition & 1 deletion include/libtrx/game/objects/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "ids.h"
#include "types.h"

OBJECT_INFO *Object_GetObject(GAME_OBJECT_ID object_id);
OBJECT *Object_GetObject(GAME_OBJECT_ID object_id);

bool Object_IsObjectType(
GAME_OBJECT_ID object_id, const GAME_OBJECT_ID *test_arr);
22 changes: 10 additions & 12 deletions include/libtrx/game/objects/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ typedef struct __PACKING {
void (*initialise)(int16_t item_num);
void (*control)(int16_t item_num);
int16_t (*floor_height_func)(
const ITEM_INFO *item, int32_t x, int32_t y, int32_t z, int16_t height);
const ITEM *item, int32_t x, int32_t y, int32_t z, int16_t height);
int16_t (*ceiling_height_func)(
const ITEM_INFO *item, int32_t x, int32_t y, int32_t z, int16_t height);
void (*draw_routine)(ITEM_INFO *item);
void (*collision)(int16_t item_num, ITEM_INFO *lara_item, COLL_INFO *coll);
const ITEM *item, int32_t x, int32_t y, int32_t z, int16_t height);
void (*draw_routine)(ITEM *item);
void (*collision)(int16_t item_num, ITEM *lara_item, COLL_INFO *coll);
const OBJECT_BOUNDS *(*bounds)(void);
int16_t anim_idx;
int16_t hit_points;
Expand All @@ -38,7 +38,7 @@ typedef struct __PACKING {
uint16_t save_hitpoints : 1;
uint16_t save_flags : 1;
uint16_t save_anim : 1;
} OBJECT_INFO;
} OBJECT;

#elif TR_VERSION == 2
typedef struct __PACKING {
Expand All @@ -50,13 +50,11 @@ typedef struct __PACKING {
void (*initialise)(int16_t item_num);
void (*control)(int16_t item_num);
void (*floor)(
const ITEM_INFO *item, int32_t x, int32_t y, int32_t z,
int32_t *height);
const ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height);
void (*ceiling)(
const ITEM_INFO *item, int32_t x, int32_t y, int32_t z,
int32_t *height);
void (*draw_routine)(const ITEM_INFO *item);
void (*collision)(int16_t item_num, ITEM_INFO *lara_item, COLL_INFO *coll);
const ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height);
void (*draw_routine)(const ITEM *item);
void (*collision)(int16_t item_num, ITEM *lara_item, COLL_INFO *coll);

int16_t anim_idx;
int16_t hit_points;
Expand All @@ -80,5 +78,5 @@ typedef struct __PACKING {
};
// clang-format on
};
} OBJECT_INFO;
} OBJECT;
#endif
2 changes: 1 addition & 1 deletion include/libtrx/game/rooms/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
#include "types.h"

extern int32_t Room_GetTotalCount(void);
ROOM_INFO *Room_Get(int32_t room_num);
ROOM *Room_Get(int32_t room_num);
Loading