Skip to content

Commit

Permalink
#368 GBA move rooms data to VRAM (experimental), simplify room transf…
Browse files Browse the repository at this point in the history
…orm code
  • Loading branch information
XProger committed Dec 4, 2022
1 parent 17d13c4 commit dd05e19
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 42 deletions.
4 changes: 4 additions & 0 deletions src/fixed/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ EWRAM_DATA const char* const* STR = STR_EN;

EWRAM_DATA ExtraInfoLara playersExtra[MAX_PLAYERS];

#if defined(USE_VRAM_MESH) || defined(USE_VRAM_ROOM)
uint8* vramPtr = (uint8*)0x06014000;
#endif

#if defined(__GBA__)
#include "TRACKS_IMA.h"
#include "TITLE_SCR.h"
Expand Down
7 changes: 6 additions & 1 deletion src/fixed/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@

#define USE_FMT (LVL_FMT_PKD)
#define USE_VRAM_MESH // experimental
//#define USE_VRAM_ROOM // experimental

#include <tonc.h>
#elif defined(__NDS__)
Expand Down Expand Up @@ -357,6 +358,10 @@ X_INLINE int32 abs(int32 x) {

extern int32 fps;

#if defined(USE_VRAM_MESH) || defined(USE_VRAM_ROOM)
extern uint8* vramPtr;
#endif

#ifndef F16_SHIFT
#define F16_SHIFT 0
#endif
Expand Down Expand Up @@ -2796,7 +2801,7 @@ void renderLevelFree();
void setViewport(const RectMinMax &vp);
void setPaletteIndex(int32 index);
void clear();
void renderRoom(const Room* room);
void renderRoom(Room* room);
void renderMesh(const Mesh* mesh);
void renderShadow(int32 x, int32 z, int32 sx, int32 sz);
void renderSprite(int32 vx, int32 vy, int32 vz, int32 vg, int32 index);
Expand Down
2 changes: 1 addition & 1 deletion src/fixed/draw.h
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ void drawModel(const ItemObj* item)
}
}

void drawRoom(const Room* room)
void drawRoom(Room* room)
{
setViewport(room->clip);

Expand Down
23 changes: 11 additions & 12 deletions src/fixed/level.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,18 +189,17 @@ void readLevel(const uint8* data)

#ifdef USE_VRAM_MESH // experimental, should be per level or dynamic
vramMeshesCount = 0;
uint8* ptr = (uint8*)0x06014000; // 16k available
ptr = pushToVRAM(ptr, models + ITEM_LARA);
ptr = pushToVRAM(ptr, models + ITEM_LARA_PISTOLS);
ptr = pushToVRAM(ptr, models + ITEM_LARA_SHOTGUN);
ptr = pushToVRAM(ptr, models + ITEM_LARA_MAGNUMS);
ptr = pushToVRAM(ptr, models + ITEM_LARA_UZIS);
ptr = pushToVRAM(ptr, models + ITEM_WOLF);
ptr = pushToVRAM(ptr, models + ITEM_BAT);
ptr = pushToVRAM(ptr, models + ITEM_BRIDGE_FLAT);
ptr = pushToVRAM(ptr, models + ITEM_BRIDGE_TILT_1);
ptr = pushToVRAM(ptr, models + ITEM_BRIDGE_TILT_2);
//printf("%d\n", ptr - (uint8*)0x06014000);
vramPtr = pushToVRAM(vramPtr, models + ITEM_LARA);
vramPtr = pushToVRAM(vramPtr, models + ITEM_LARA_PISTOLS);
vramPtr = pushToVRAM(vramPtr, models + ITEM_LARA_SHOTGUN);
vramPtr = pushToVRAM(vramPtr, models + ITEM_LARA_MAGNUMS);
vramPtr = pushToVRAM(vramPtr, models + ITEM_LARA_UZIS);
vramPtr = pushToVRAM(vramPtr, models + ITEM_WOLF);
vramPtr = pushToVRAM(vramPtr, models + ITEM_BAT);
vramPtr = pushToVRAM(vramPtr, models + ITEM_BRIDGE_FLAT);
vramPtr = pushToVRAM(vramPtr, models + ITEM_BRIDGE_TILT_1);
vramPtr = pushToVRAM(vramPtr, models + ITEM_BRIDGE_TILT_2);
//printf("%d\n", vramPtr - (uint8*)0x06014000);
#endif
}

Expand Down
31 changes: 9 additions & 22 deletions src/platform/gba/asm/transformRoom.s
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,11 @@ transformRoom_asm:

ldr res, =gVerticesBase
ldr res, [res]
add res, #VERTEX_G

ldr tmp, =viewportRel
ldmia tmp, {minXY, maxXY}
stmfd sp!, {minXY, maxXY}

mov mask, #0xFF

ldr m, =gMatrixPtr
ldr m, [m]
fiq_on
Expand All @@ -69,27 +66,20 @@ transformRoom_asm:

.loop:
// unpack vertex
ldmia vertices!, {v}
ldr v, [vertices], #4

and vz, mask, v, lsr #16
and vy, mask, v, lsr #8
mov mask, #0xFF
and vx, mask, v
and vy, mask, v, lsr #8
and vz, mask, v, lsr #16
mov vg, v, lsr #(24 + 3)

// transform z
mul z, mx2, vx
mla z, my2, vy, z
mla z, mz2, vz, z
add z, mw2, z, asr #(FIXED_SHIFT - 8 + OT_SHIFT)

// skip if vertex is out of z-range
add z, #(VIEW_OFF >> OT_SHIFT)
cmp z, #((VIEW_OFF + VIEW_OFF + VIEW_MAX) >> OT_SHIFT)
movhi vg, #(CLIP_NEAR + CLIP_FAR)
bhi .skip

mov vg, v, lsr #(24 + 3)
sub z, #(VIEW_OFF >> OT_SHIFT)

fiq_on
// transform y
mul y, mx1, vx
Expand Down Expand Up @@ -151,13 +141,10 @@ transformRoom_asm:
orrhi vg, #CLIP_FRAME

// store the result
strh x, [res, #-6]
strh y, [res, #-4]
strh z, [res, #-2]

mov mask, #0xFF
.skip:
strh vg, [res], #8
strh x, [res], #2
strh y, [res], #2
strh z, [res], #2
strh vg, [res], #2

subs count, #1
bne .loop
Expand Down
28 changes: 22 additions & 6 deletions src/platform/gba/render.iwram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@ void clear()
dmaFill((void*)fb, 0, FRAME_WIDTH * FRAME_HEIGHT);
}

void renderRoom(const Room* room)
void renderRoom(Room* room)
{
int32 vCount = room->info->verticesCount;
if (vCount <= 0)
Expand All @@ -820,6 +820,27 @@ void renderRoom(const Room* room)
return;
}

#ifdef USE_VRAM_ROOM
if (playersExtra[0].camera.view.room == room && !((uint32)room->data.vertices & 0x06000000))
{
memcpy(vramPtr, room->data.quads, room->info->quadsCount * sizeof(RoomQuad));
room->data.quads = (RoomQuad*)vramPtr;
vramPtr += room->info->quadsCount * sizeof(RoomQuad);

if ((uint32)vramPtr & 3) vramPtr += 2;

memcpy(vramPtr, room->data.triangles, room->info->trianglesCount * sizeof(RoomTriangle));
room->data.triangles = (RoomTriangle*)vramPtr;
vramPtr += room->info->trianglesCount * sizeof(RoomTriangle);

if ((uint32)vramPtr & 3) vramPtr += 2;

memcpy(vramPtr, room->data.vertices, room->info->verticesCount * sizeof(RoomVertex));
room->data.vertices = (RoomVertex*)vramPtr;
vramPtr += room->info->verticesCount * sizeof(RoomVertex);
}
#endif

{
PROFILE(CNT_TRANSFORM);
if (ROOM_FLAG_WATER(room->info->flags)) {
Expand Down Expand Up @@ -1098,20 +1119,15 @@ void renderGlyph(int32 vx, int32 vy, int32 index)
Vertex* v1 = gVerticesBase++;
v1->x = l;
v1->y = t;
//v1->z = z;
v1->g = 16;

Vertex* v2 = gVerticesBase++;
v2->x = r;
v2->y = b;
//v2->z = z;
//v2->g = vg;

Face* f = faceAdd(0);
f->flags = (FACE_TYPE_SPRITE << FACE_TYPE_SHIFT) | index;
f->indices[0] = v1 - gVertices;

gVerticesBase += 2;
}

#define BAR_HEIGHT 5
Expand Down

0 comments on commit dd05e19

Please sign in to comment.