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

Commit

Permalink
port LOS_ClipTarget
Browse files Browse the repository at this point in the history
  • Loading branch information
rr- committed Nov 3, 2023
1 parent b794016 commit 1fb9b4c
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 10 deletions.
16 changes: 8 additions & 8 deletions docs/progress.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/progress.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1342,7 +1342,7 @@ typedef enum LARA_MESH {
00415BE0 000000A0 + int32_t __cdecl LOS_Check(const struct GAME_VECTOR *start, struct GAME_VECTOR *target);
00415C80 000002EB + int32_t __cdecl LOS_CheckZ(const struct GAME_VECTOR *start, struct GAME_VECTOR *target);
00415F70 000002EC + int32_t __cdecl LOS_CheckX(const struct GAME_VECTOR *start, struct GAME_VECTOR *target);
00416260 000000DA - int32_t __cdecl LOS_ClipTarget(const struct GAME_VECTOR *start, struct GAME_VECTOR *target, const FLOOR_INFO *floor);
00416260 000000DA + int32_t __cdecl LOS_ClipTarget(const struct GAME_VECTOR *start, struct GAME_VECTOR *target, const FLOOR_INFO *floor);
00416340 000002FE - int32_t __cdecl LOS_ObjectOnLOS(const struct GAME_VECTOR *start, struct GAME_VECTOR *target);
00416640 000000B3 - void __cdecl Room_FlipMap(void);
00416700 00000096 - void __cdecl Room_RemoveFlipItems(struct ROOM_INFO *r);
Expand Down
29 changes: 29 additions & 0 deletions src/game/los.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,35 @@ int32_t __cdecl LOS_CheckZ(
return 1;
}

int32_t __cdecl LOS_ClipTarget(
const struct GAME_VECTOR *const start, struct GAME_VECTOR *const target,
const FLOOR_INFO *const floor)
{
const int32_t dx = target->x - start->x;
const int32_t dy = target->y - start->y;
const int32_t dz = target->z - start->z;

const int32_t height =
Room_GetHeight(floor, target->x, target->y, target->z);
if (target->y > height && start->y < height) {
target->y = height;
target->x = start->x + dx * (height - start->y) / dy;
target->z = start->z + dz * (height - start->y) / dy;
return 0;
}

const int32_t ceiling =
Room_GetCeiling(floor, target->x, target->y, target->z);
if (target->y < ceiling && start->y > ceiling) {
target->y = ceiling;
target->x = start->x + dx * (ceiling - start->y) / dy;
target->z = start->z + dz * (ceiling - start->y) / dy;
return 0;
}

return 1;
}

int32_t __cdecl LOS_Check(
const struct GAME_VECTOR *const start, struct GAME_VECTOR *const target)
{
Expand Down
3 changes: 3 additions & 0 deletions src/game/los.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@ int32_t __cdecl LOS_CheckX(
const struct GAME_VECTOR *start, struct GAME_VECTOR *target);
int32_t __cdecl LOS_CheckZ(
const struct GAME_VECTOR *start, struct GAME_VECTOR *target);
int32_t __cdecl LOS_ClipTarget(
const struct GAME_VECTOR *start, struct GAME_VECTOR *target,
const FLOOR_INFO *floor);
int32_t __cdecl LOS_Check(
const struct GAME_VECTOR *start, struct GAME_VECTOR *target);
1 change: 0 additions & 1 deletion src/global/funcs.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@
#define Item_IsTriggerActive ((int32_t __cdecl (*)(struct ITEM_INFO *item))0x004158D0)
#define Room_GetCeiling ((int32_t __cdecl (*)(const struct FLOOR_INFO *floor, int32_t x, int32_t y, int32_t z))0x00415930)
#define Room_GetDoor ((int16_t __cdecl (*)(struct FLOOR_INFO *floor))0x00415B90)
#define LOS_ClipTarget ((int32_t __cdecl (*)(const struct GAME_VECTOR *start, struct GAME_VECTOR *target, const FLOOR_INFO *floor))0x00416260)
#define LOS_ObjectOnLOS ((int32_t __cdecl (*)(const struct GAME_VECTOR *start, struct GAME_VECTOR *target))0x00416340)
#define Room_FlipMap ((void __cdecl (*)(void))0x00416640)
#define Room_RemoveFlipItems ((void __cdecl (*)(struct ROOM_INFO *r))0x00416700)
Expand Down
1 change: 1 addition & 0 deletions src/inject_exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ static void Inject_LOS(void)
INJECT(1, 0x00415BE0, LOS_Check);
INJECT(1, 0x00415C80, LOS_CheckZ);
INJECT(1, 0x00415F70, LOS_CheckX);
INJECT(1, 0x00416260, LOS_ClipTarget);
}

static void Inject_Lara_Misc(void)
Expand Down

0 comments on commit 1fb9b4c

Please sign in to comment.