Skip to content

Commit

Permalink
#368 GBA mesh visible mask, enemies head/neck rotation, death animati…
Browse files Browse the repository at this point in the history
…on for Wolf, Bear and Bat
  • Loading branch information
XProger committed Aug 2, 2021
1 parent e9ba3a2 commit 6139aa4
Show file tree
Hide file tree
Showing 7 changed files with 545 additions and 61 deletions.
1 change: 1 addition & 0 deletions src/platform/gba/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ int32 matrixStackIndex = 0;

const FloorData* gLastFloorData;
FloorData gLastFloorSlant;
TargetInfo tinfo;

EWRAM_DATA SaveGame gSaveGame;
EWRAM_DATA Settings gSettings;
Expand Down
32 changes: 28 additions & 4 deletions src/platform/gba/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,14 @@ struct Room {
Room** getVisibleRooms();
};

enum NodeFlag {
NODE_FLAG_POP = (1 << 0),
NODE_FLAG_PUSH = (1 << 1),
NODE_FLAG_ROTX = (1 << 2),
NODE_FLAG_ROTY = (1 << 3),
NODE_FLAG_ROTZ = (1 << 4),
};

struct Node {
uint16 flags;
vec3s pos;
Expand Down Expand Up @@ -1159,24 +1167,29 @@ struct Item {
uint16 frameIndex;

uint8 state;
uint8 nextState;
uint8 nextState; // enemies only
uint8 goalState;
uint8 waterState;

int16 headOffset; // enemies only
int16 aggression;

int16 health;
union {
int16 timer;
int16 oxygen;
int16 oxygen; // Lara only
int16 radius; // enemies only
};

uint16 input;
uint16 input; // Lara only
int16 turnSpeed;

uint8 type;
uint8 intensity;
int16 roomFloor;

int32 hitMask;
uint32 hitMask;
uint32 visibleMask;

union {
uint8* extra;
Expand Down Expand Up @@ -1606,6 +1619,17 @@ struct Level {
const int32* soundOffsets;
};

// used by enemies
struct TargetInfo
{
Item* target;
int16 angle;
int16 rotHead;
bool aim;
};

extern TargetInfo tinfo;

extern Level level;

struct IMA_STATE {
Expand Down
69 changes: 54 additions & 15 deletions src/platform/gba/draw.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ void drawNumber(int32 number, int32 x, int32 y)
}
}

void drawMesh(int16 meshIndex)
void drawMesh(int32 meshIndex)
{
const uint8* ptr = (uint8*)meshes[meshIndex] + sizeof(Mesh);

Expand Down Expand Up @@ -224,22 +224,41 @@ void drawNodes(const Item* item, const AnimFrame* frameA)
{
const Model* model = models + item->type;
const Node* node = level.nodes + model->nodeIndex;
int32 meshIndex = model->start;
int32 meshCount = model->count;
uint32 visibleMask = item->visibleMask;

const uint32* angles = (uint32*)(frameA->angles + 1);
const int16* extraAngles = (int16*)item->extra;

matrixFrame(frameA->pos, angles);
if (visibleMask & 1) {
drawMesh(meshIndex);
}

drawMesh(model->start);

for (int32 i = 1; i < model->count; i++)
while (meshCount > 1)
{
if (node->flags & 1) matrixPop();
if (node->flags & 2) matrixPush();
meshIndex++;
visibleMask >>= 1;
angles++;

matrixFrame(node->pos, ++angles);
if (node->flags & NODE_FLAG_POP) matrixPop();
if (node->flags & NODE_FLAG_PUSH) matrixPush();

drawMesh(model->start + i);
matrixFrame(node->pos, angles);

if (extraAngles)
{
if (node->flags & NODE_FLAG_ROTY) matrixRotateY(*extraAngles++);
if (node->flags & NODE_FLAG_ROTX) matrixRotateX(*extraAngles++);
if (node->flags & NODE_FLAG_ROTZ) matrixRotateZ(*extraAngles++);
}

if (visibleMask & 1) {
drawMesh(meshIndex);
}

meshCount--;
node++;
}
}
Expand All @@ -254,9 +273,13 @@ void drawNodesLerp(const Item* item, const AnimFrame* frameA, const AnimFrame* f

const Model* model = models + item->type;
const Node* node = level.nodes + model->nodeIndex;
int32 meshIndex = model->start;
int32 meshCount = model->count;
uint32 visibleMask = item->visibleMask;

const uint32* anglesA = (uint32*)(frameA->angles + 1);
const uint32* anglesB = (uint32*)(frameB->angles + 1);
const int16* extraAngles = (int16*)item->extra;

int32 t = FixedInvU(frameRate) * frameDelta;

Expand All @@ -266,18 +289,34 @@ void drawNodesLerp(const Item* item, const AnimFrame* frameA, const AnimFrame* f
posLerp.z = frameA->pos.z + ((frameB->pos.z - frameA->pos.z) * t >> 16);

matrixFrameLerp(posLerp, anglesA, anglesB, frameDelta, frameRate);
if (visibleMask & 1) {
drawMesh(meshIndex);
}

drawMesh(model->start);

for (int32 i = 1; i < model->count; i++)
while (meshCount > 1)
{
if (node->flags & 1) matrixPop();
if (node->flags & 2) matrixPush();
meshIndex++;
visibleMask >>= 1;
anglesA++;
anglesB++;

matrixFrameLerp(node->pos, ++anglesA, ++anglesB, frameDelta, frameRate);
if (node->flags & NODE_FLAG_POP) matrixPop();
if (node->flags & NODE_FLAG_PUSH) matrixPush();

drawMesh(model->start + i);
matrixFrameLerp(node->pos, anglesA, anglesB, frameDelta, frameRate);

if (extraAngles)
{
if (node->flags & NODE_FLAG_ROTY) matrixRotateY(*extraAngles++);
if (node->flags & NODE_FLAG_ROTX) matrixRotateX(*extraAngles++);
if (node->flags & NODE_FLAG_ROTZ) matrixRotateZ(*extraAngles++);
}

if (visibleMask & 1) {
drawMesh(meshIndex);
}

meshCount--;
node++;
}
}
Expand Down
Loading

0 comments on commit 6139aa4

Please sign in to comment.