collision stuff (#785)

* flag fixes

* enum vals

* npc flags

* ai flags

* collision stuff

* ok

Co-authored-by: HailSanta <Hail2Santa@gmail.com>
This commit is contained in:
HailSanta 2022-09-24 16:01:49 -04:00 committed by GitHub
parent b6ab97c066
commit 3a8ba482e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 47 additions and 56 deletions

View File

@ -4141,36 +4141,25 @@ enum SurfaceType {
enum ColliderFlags {
COLLIDER_FLAGS_UPPER_MASK = 0x7FFFFE00, // map data dumper needs this to be first
COLLIDER_FLAGS_SURFACE_TYPE_MASK = 0x000000FF,
COLLIDER_FLAGS_100 = 0x00000100,
COLLIDER_FLAGS_200 = 0x00000200,
COLLIDER_FLAGS_400 = 0x00000400,
COLLIDER_FLAGS_800 = 0x00000800,
COLLIDER_FLAGS_1000 = 0x00001000,
COLLIDER_FLAGS_2000 = 0x00002000,
COLLIDER_FLAGS_4000 = 0x00004000,
COLLIDER_FLAGS_SAFE_FLOOR = 0x00000100,
COLLIDER_FLAGS_IGNORE_SHELL = 0x00008000,
COLLIDER_FLAGS_IGNORE_PLAYER = 0x00010000,
COLLIDER_FLAGS_20000 = 0x00020000,
COLLIDER_FLAGS_40000 = 0x00040000,
COLLIDER_FLAGS_80000 = 0x00080000,
COLLIDER_FLAGS_100000 = 0x00100000,
COLLIDER_FLAGS_200000 = 0x00200000,
COLLIDER_FLAGS_400000 = 0x00400000,
COLLIDER_FLAGS_800000 = 0x00800000,
COLLIDER_FLAGS_1000000 = 0x01000000,
COLLIDER_FLAGS_2000000 = 0x02000000,
COLLIDER_FLAGS_4000000 = 0x04000000,
COLLIDER_FLAGS_8000000 = 0x08000000,
COLLIDER_FLAGS_10000000 = 0x10000000,
COLLIDER_FLAGS_20000000 = 0x20000000,
COLLIDER_FLAGS_40000000 = 0x40000000,
COLLIDER_FLAGS_80000000 = 0x80000000
COLLIDER_FLAGS_HAS_MODEL_PARENT = 0x80000000
};
enum ColliderFlagsModifyMode {
MODIFY_COLLIDER_FLAGS_SET_BITS = 0,
MODIFY_COLLIDER_FLAGS_CLEAR_BITS = 1,
MODIFY_COLLIDER_FLAGS_SET_VALUE = 2,
MODIFY_COLLIDER_FLAGS_SET_SURFACE = 3,
};
enum CollisionChannels {
COLLISION_CHANNEL_10000 = 0x00010000,
COLLISION_CHANNEL_20000 = 0x00020000,
COLLISION_CHANNEL_40000 = 0x00040000,
COLLISION_IGNORE_ENTITIES = 0x00040000,
COLLISION_CHANNEL_80000 = 0x00080000,
COLLISION_ONLY_ENTITIES = 0x00100000,
};
enum CameraInitDataFlags {

View File

@ -95,8 +95,6 @@
#define COLLISION_WITH_NPC_BIT 0x2000
#define COLLISION_WITH_ENTITY_BIT 0x4000
#define COLLISION_IGNORE_ENTITIES 0x40000
#define COLLISION_ONLY_ENTITIES 0x100000
#define PACK_FILL_COLOR(r, g, b, a) (GPACK_RGBA5551(r, g, b, a) << 0x10) | GPACK_RGBA5551(r, g, b, a)
#define PACK_FILL_DEPTH(z,dz) (GPACK_ZDZ(z, dz) << 0x10) | GPACK_ZDZ(z, dz)

View File

@ -427,19 +427,22 @@ s32 player_raycast_general(s32 mode, f32 startX, f32 startY, f32 startZ, f32 dir
ret = entityID | COLLISION_WITH_ENTITY_BIT;
}
} else if (mode == 3) {
ret = test_ray_colliders(COLLIDER_FLAGS_IGNORE_SHELL, startX, startY, startZ, dirX, dirY, dirZ, hitX, hitY, hitZ, hitDepth,
hitNx, hitNy, hitNz);
ret = test_ray_colliders(COLLIDER_FLAGS_IGNORE_SHELL, startX, startY, startZ, dirX, dirY, dirZ,
hitX, hitY, hitZ, hitDepth, hitNx, hitNy, hitNz);
}
if (mode == 1 || mode == 3)
if (mode == 1 || mode == 3) {
return ret;
ignoreFlags = COLLIDER_FLAGS_IGNORE_PLAYER;
if (mode == 4) {
ignoreFlags = 0x80000;
}
colliderID = test_ray_colliders(ignoreFlags, startX, startY, startZ, dirX, dirY, dirZ, hitX, hitY, hitZ, hitDepth,
hitNx, hitNy, hitNz);
if (mode == 4) {
ignoreFlags = COLLISION_CHANNEL_80000;
} else {
ignoreFlags = COLLIDER_FLAGS_IGNORE_PLAYER;
}
colliderID = test_ray_colliders(ignoreFlags, startX, startY, startZ, dirX, dirY, dirZ,
hitX, hitY, hitZ, hitDepth, hitNx, hitNy, hitNz);
if (ret < 0) {
ret = colliderID;

View File

@ -133,7 +133,7 @@ void restore_map_collision_data(void) {
collider->flags = backupEntry->flags;
collider->parentModelIndex = backupEntry->parentModelIndex;
if (collider->flags != -1 && collider->flags & 0x80000000) {
if (collider->flags != -1 && collider->flags & COLLIDER_FLAGS_HAS_MODEL_PARENT) {
parent_collider_to_model(i, collider->parentModelIndex);
update_collider_transform(i);
}
@ -316,9 +316,9 @@ void parent_collider_to_model(s16 colliderID, s16 modelIndex) {
collider = &gCollisionData.colliderList[colliderID];
collider->parentModelIndex = modelIndex;
collider->flags |= 0x80000000;
collider->flags |= COLLIDER_FLAGS_HAS_MODEL_PARENT;
vertexBuffer = collision_heap_malloc(collider->numTriangles * 0xC);
vertexBuffer = collision_heap_malloc(collider->numTriangles * sizeof(Vec3f));
vertexBufferSize = 0;
vertexPtr = vertexBuffer;
@ -329,7 +329,7 @@ void parent_collider_to_model(s16 colliderID, s16 modelIndex) {
}
collider->numVertices = vertexBufferSize;
collider->vertexTable = collision_heap_malloc(vertexBufferSize * 0x18);
collider->vertexTable = collision_heap_malloc(vertexBufferSize * 2 * sizeof(Vec3f));
for (i = 0, vertexTable = collider->vertexTable; i < vertexBufferSize; vertexPtr++, vertexTable += 2, i++) {
vertex = *vertexPtr;
vertexTable[0].x = vertexTable[1].x = vertex->x;
@ -871,7 +871,7 @@ s32 test_ray_zones(f32 startX, f32 startY, f32 startZ, f32 dirX, f32 dirY, f32 d
for (i = 0; i < collisionData->numColliders; i++) {
collider = &collisionData->colliderList[i];
if (collider->flags & 0x10000)
if (collider->flags & COLLIDER_FLAGS_IGNORE_PLAYER)
continue;
if (collider->numTriangles == 0 || collider->aabb == NULL)

View File

@ -8,7 +8,7 @@ typedef struct LavaReset {
} LavaReset; // size = 0x10;
extern LavaReset* gLavaResetList;
extern s32 D_802DADA4;
extern s32 LastSafeFloor;
ApiStatus TranslateModel(Evt* script, s32 isInitialCall) {
Bytecode* args = script->ptrReadPos;
@ -546,16 +546,16 @@ ApiStatus ModifyColliderFlags(Evt* script, s32 isInitialCall) {
}
switch (mode) {
case 0:
case MODIFY_COLLIDER_FLAGS_SET_BITS:
collider->flags |= flags;
break;
case 1:
case MODIFY_COLLIDER_FLAGS_CLEAR_BITS:
collider->flags &= ~flags;
break;
case 2:
case MODIFY_COLLIDER_FLAGS_SET_VALUE:
collider->flags = flags;
break;
case 3:
case MODIFY_COLLIDER_FLAGS_SET_SURFACE:
collider->flags &= ~0xFF;
collider->flags |= flags & 0xFF;
break;
@ -564,6 +564,7 @@ ApiStatus ModifyColliderFlags(Evt* script, s32 isInitialCall) {
return ApiStatus_DONE2;
}
//TODO rename to MonitorLastSafeFloor
ApiStatus ResetFromLava(Evt* script, s32 isInitialCall) {
Bytecode* args = script->ptrReadPos;
CollisionStatus* collisionStatus = &gCollisionStatus;
@ -579,19 +580,19 @@ ApiStatus ResetFromLava(Evt* script, s32 isInitialCall) {
}
collider = &gCollisionData.colliderList[lavaReset->colliderID];
if (collider->firstChild >= 0) {
modify_collider_family_flags(collider->firstChild, 0x100, 0);
modify_collider_family_flags(collider->firstChild, COLLIDER_FLAGS_SAFE_FLOOR, 0);
}
collider->flags |= 0x100;
collider->flags |= COLLIDER_FLAGS_SAFE_FLOOR;
lavaReset++;
}
D_802DADA4 = -1;
LastSafeFloor = -1;
}
if (!(collisionStatus->currentFloor & COLLISION_WITH_ENTITY_BIT)) {
collider = &gCollisionData.colliderList[collisionStatus->currentFloor];
if (collider->flags & 0x100) {
D_802DADA4 = collisionStatus->currentFloor;
if (collider->flags & COLLIDER_FLAGS_SAFE_FLOOR) {
LastSafeFloor = collisionStatus->currentFloor;
return ApiStatus_BLOCK;
}
}
@ -604,7 +605,7 @@ s32 get_lava_reset_pos(f32* outX, f32* outY, f32* outZ) {
s32 temp_a0;
LavaReset* lavaReset = gLavaResetList;
if (D_802DADA4 == -1) {
if (LastSafeFloor == -1) {
temp_v0 = &(*get_current_map_settings()->entryList)[gGameStatusPtr->entryID];
*outX = temp_v0->x;
*outY = temp_v0->y;
@ -617,7 +618,7 @@ s32 get_lava_reset_pos(f32* outX, f32* outY, f32* outZ) {
break;
}
if (lavaReset->colliderID == D_802DADA4) {
if (lavaReset->colliderID == LastSafeFloor) {
*outX = lavaReset->pos.x;
*outY = lavaReset->pos.y;
*outZ = lavaReset->pos.z;

View File

@ -24,7 +24,7 @@ BSS char evtDebugPrintBuffer[0x100];
// map_api
BSS struct LavaReset* gLavaResetList;
BSS s32 D_802DADA4;
BSS s32 LastSafeFloor;
BSS s32 D_802DADA8[2]; // unused?
// model_api

View File

@ -380,7 +380,7 @@ void npc_do_other_npc_collision(Npc* npc) {
for (i = 0; i < 0x40; i++) {
otherNpc = get_npc_by_index(i);
if (otherNpc != NULL && npc != otherNpc) {
if (otherNpc->flags != 0 && !(otherNpc->flags & (0x80000000 | NPC_FLAG_100))) {
if (otherNpc->flags != 0 && !(otherNpc->flags & (NPC_FLAG_80000000 | NPC_FLAG_100))) {
if (!(otherNpc->pos.y + otherNpc->collisionHeight < thisY) &&
!(thisY + npc->collisionHeight < otherNpc->pos.y))
{
@ -523,9 +523,9 @@ void update_npcs(void) {
npc->onUpdate(npc);
if (npc->flags & NPC_FLAG_8000) {
npc->collisionChannel |= COLLISION_CHANNEL_40000;
npc->collisionChannel |= COLLISION_IGNORE_ENTITIES;
} else {
npc->collisionChannel &= ~COLLISION_CHANNEL_40000;
npc->collisionChannel &= ~COLLISION_IGNORE_ENTITIES;
}
npc->currentFloor = -1;

View File

@ -27136,7 +27136,7 @@ gScriptIdList = 0x802DAA98; //
gScriptListCount = 0x802DAC98; //
evtDebugPrintBuffer = 0x802DACA0; // type:data
gLavaResetList = 0x802DADA0; // type:data
D_802DADA4 = 0x802DADA4; // type:data
LastSafeFloor = 0x802DADA4; // type:data
gBattleMeshAnimationList = 0x802DADB0; // size:0x40
gWorldMeshAnimationList = 0x802DADF0; // size:0x40
gCurrentMeshAnimationListPtr = 0x802DAE30; //