diff --git a/src/fixed/common.cpp b/src/fixed/common.cpp index bf474ad1..87dee236 100644 --- a/src/fixed/common.cpp +++ b/src/fixed/common.cpp @@ -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" diff --git a/src/fixed/common.h b/src/fixed/common.h index c86e852c..3d571b80 100644 --- a/src/fixed/common.h +++ b/src/fixed/common.h @@ -67,6 +67,7 @@ #define USE_FMT (LVL_FMT_PKD) #define USE_VRAM_MESH // experimental + //#define USE_VRAM_ROOM // experimental #include #elif defined(__NDS__) @@ -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 @@ -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); diff --git a/src/fixed/draw.h b/src/fixed/draw.h index 75a23455..f65c4900 100644 --- a/src/fixed/draw.h +++ b/src/fixed/draw.h @@ -701,7 +701,7 @@ void drawModel(const ItemObj* item) } } -void drawRoom(const Room* room) +void drawRoom(Room* room) { setViewport(room->clip); diff --git a/src/fixed/level.h b/src/fixed/level.h index a2d1a4b2..eb8f982f 100644 --- a/src/fixed/level.h +++ b/src/fixed/level.h @@ -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 } diff --git a/src/platform/gba/asm/transformRoom.s b/src/platform/gba/asm/transformRoom.s index 05ff7ff6..cf660cc1 100644 --- a/src/platform/gba/asm/transformRoom.s +++ b/src/platform/gba/asm/transformRoom.s @@ -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 @@ -69,11 +66,13 @@ 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 @@ -81,15 +80,6 @@ transformRoom_asm: 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 @@ -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 diff --git a/src/platform/gba/render.iwram.cpp b/src/platform/gba/render.iwram.cpp index a262410d..c1accf0a 100644 --- a/src/platform/gba/render.iwram.cpp +++ b/src/platform/gba/render.iwram.cpp @@ -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) @@ -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)) { @@ -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