mirror of
https://github.com/XProger/OpenLara.git
synced 2025-01-17 12:58:50 +01:00
#368 minor optimizations (next & prev links, mod in drawPoly, anglesFromVector)
This commit is contained in:
parent
48e57ece0e
commit
3d0f82ba6b
@ -1057,12 +1057,7 @@ uint32 phd_sqrt(uint32 x)
|
||||
void anglesFromVector(int32 x, int32 y, int32 z, int16 &angleX, int16 &angleY)
|
||||
{
|
||||
angleY = phd_atan(z, x);
|
||||
angleX = phd_atan(phd_sqrt(x * x + z * z), y);
|
||||
|
||||
if ((y > 0 && angleX > 0) || (y < 0 && angleX < 0))
|
||||
{
|
||||
angleX = -angleX;
|
||||
}
|
||||
angleX = phd_atan(phd_sqrt(x * x + z * z), -y);
|
||||
}
|
||||
|
||||
bool boxIntersect(const AABBi &a, const AABBi &b)
|
||||
|
@ -13,8 +13,10 @@
|
||||
.equ VERTEX_CLIP, 7
|
||||
.equ VERTEX_T, 8
|
||||
.equ VERTEX_PREV, 12
|
||||
.equ VERTEX_NEXT, 16
|
||||
.equ VERTEX_SIZEOF, 20
|
||||
.equ VERTEX_NEXT, 13
|
||||
|
||||
.equ VERTEX_SIZEOF_SHIFT, 4
|
||||
.equ VERTEX_SIZEOF, (1 << VERTEX_SIZEOF_SHIFT)
|
||||
|
||||
.equ LEVEL_TILES, 40
|
||||
.equ LEVEL_TEXTURES, 92
|
||||
|
@ -45,7 +45,8 @@ rasterizeF_asm:
|
||||
.calc_left_start:
|
||||
cmp Lh, #0
|
||||
bne .calc_left_end // if (Lh != 0) end with left
|
||||
ldr N, [L, #VERTEX_PREV] // N = L->prev
|
||||
ldrsb N, [L, #VERTEX_PREV] // N = L + L->prev
|
||||
add N, L, N, lsl #VERTEX_SIZEOF_SHIFT
|
||||
ldr Lxy, [L, #VERTEX_X] // Lxy = (L->v.y << 16) | (L->v.x)
|
||||
ldrsh Ly2, [N, #VERTEX_Y] // Ly2 = N->v.y
|
||||
subs Lh, Ly2, Lxy, asr #16 // Lh = N->v.y - L->v.y
|
||||
@ -65,7 +66,8 @@ rasterizeF_asm:
|
||||
.calc_right_start:
|
||||
cmp Rh, #0
|
||||
bne .calc_right_end // if (Rh != 0) end with right
|
||||
ldr N, [R, #VERTEX_NEXT] // N = R->next
|
||||
ldrsb N, [R, #VERTEX_NEXT] // N = R + R->next
|
||||
add N, R, N, lsl #VERTEX_SIZEOF_SHIFT
|
||||
ldr Rxy, [R, #VERTEX_X] // Rxy = (R->v.y << 16) | (R->v.x)
|
||||
ldrsh Ry2, [N, #VERTEX_Y] // Ry2 = N->v.y
|
||||
subs Rh, Ry2, Rxy, asr #16 // Rh = N->v.y - R->v.y
|
||||
|
@ -100,7 +100,8 @@ rasterizeFT_asm:
|
||||
.calc_left_start:
|
||||
cmp Lh, #0
|
||||
bne .calc_left_end // if (Lh != 0) end with left
|
||||
ldr N, [L, #VERTEX_PREV] // N = L->prev
|
||||
ldrsb N, [L, #VERTEX_PREV] // N = L + L->prev
|
||||
add N, L, N, lsl #VERTEX_SIZEOF_SHIFT
|
||||
ldr Lxy, [L, #VERTEX_X] // Lxy = (L->v.y << 16) | (L->v.x)
|
||||
ldrsh Ly2, [N, #VERTEX_Y] // Ly2 = N->v.y
|
||||
subs Lh, Ly2, Lxy, asr #16 // Lh = N->v.y - L->v.y
|
||||
@ -136,7 +137,8 @@ rasterizeFT_asm:
|
||||
.calc_right_start:
|
||||
cmp Rh, #0
|
||||
bne .calc_right_end // if (Rh != 0) end with right
|
||||
ldr N, [R, #VERTEX_NEXT] // N = R->next
|
||||
ldrsb N, [R, #VERTEX_NEXT] // N = R + R->next
|
||||
add N, R, N, lsl #VERTEX_SIZEOF_SHIFT
|
||||
ldr Rxy, [R, #VERTEX_X] // Rxy = (R->v.y << 16) | (R->v.x)
|
||||
ldrsh Ry2, [N, #VERTEX_Y] // Ry2 = N->v.y
|
||||
subs Rh, Ry2, Rxy, asr #16 // Rh = Ry2 - Rxy
|
||||
|
@ -106,7 +106,8 @@ rasterizeFTA_asm:
|
||||
.calc_left_start:
|
||||
cmp Lh, #0
|
||||
bne .calc_left_end // if (Lh != 0) end with left
|
||||
ldr N, [L, #VERTEX_PREV] // N = L->prev
|
||||
ldrsb N, [L, #VERTEX_PREV] // N = L + L->prev
|
||||
add N, L, N, lsl #VERTEX_SIZEOF_SHIFT
|
||||
ldr Lxy, [L, #VERTEX_X] // Lxy = (L->v.y << 16) | (L->v.x)
|
||||
ldrsh Ly2, [N, #VERTEX_Y] // Ly2 = N->v.y
|
||||
subs Lh, Ly2, Lxy, asr #16 // Lh = N->v.y - L->v.y
|
||||
@ -142,7 +143,8 @@ rasterizeFTA_asm:
|
||||
.calc_right_start:
|
||||
cmp Rh, #0
|
||||
bne .calc_right_end // if (Rh != 0) end with right
|
||||
ldr N, [R, #VERTEX_NEXT] // N = R->next
|
||||
ldrsb N, [R, #VERTEX_NEXT] // N = R + R->next
|
||||
add N, R, N, lsl #VERTEX_SIZEOF_SHIFT
|
||||
ldr Rxy, [R, #VERTEX_X] // Rxy = (R->v.y << 16) | (R->v.x)
|
||||
ldrsh Ry2, [N, #VERTEX_Y] // Ry2 = N->v.y
|
||||
subs Rh, Ry2, Rxy, asr #16 // Rh = N->v.y - R->v.y
|
||||
|
@ -122,7 +122,8 @@ rasterizeGT_asm:
|
||||
.calc_left_start:
|
||||
cmp Lh, #0
|
||||
bne .calc_left_end // if (Lh != 0) end with left
|
||||
ldr N, [L, #VERTEX_PREV] // N = L->prev
|
||||
ldrsb N, [L, #VERTEX_PREV] // N = L + L->prev
|
||||
add N, L, N, lsl #VERTEX_SIZEOF_SHIFT
|
||||
ldr Lxy, [L, #VERTEX_X] // Lxy = (L->v.y << 16) | (L->v.x)
|
||||
ldrsh Ly2, [N, #VERTEX_Y] // Ly2 = N->v.y
|
||||
subs Lh, Ly2, Lxy, asr #16 // Lh = N->v.y - L->v.y
|
||||
@ -166,7 +167,8 @@ rasterizeGT_asm:
|
||||
.calc_right_start:
|
||||
cmp Rh, #0
|
||||
bne .calc_right_end // if (Rh != 0) end with right
|
||||
ldr N, [R, #VERTEX_NEXT] // N = R->next
|
||||
ldrsb N, [R, #VERTEX_NEXT] // N = R + R->next
|
||||
add N, R, N, lsl #VERTEX_SIZEOF_SHIFT
|
||||
ldr Rxy, [R, #VERTEX_X] // Rxy = (R->v.y << 16) | (R->v.x)
|
||||
ldrsh Ry2, [N, #VERTEX_Y] // Ry2 = N->v.y
|
||||
subs Rh, Ry2, Rxy, asr #16 // Rh = N->v.y - R->v.y
|
||||
|
@ -127,7 +127,8 @@ rasterizeGTA_asm:
|
||||
.calc_left_start:
|
||||
cmp Lh, #0
|
||||
bne .calc_left_end // if (Lh != 0) end with left
|
||||
ldr N, [L, #VERTEX_PREV] // N = L->prev
|
||||
ldrsb N, [L, #VERTEX_PREV] // N = L + L->prev
|
||||
add N, L, N, lsl #VERTEX_SIZEOF_SHIFT
|
||||
ldr Lxy, [L, #VERTEX_X] // Lxy = (L->v.y << 16) | (L->v.x)
|
||||
ldrsh Ly2, [N, #VERTEX_Y] // Ly2 = N->v.y
|
||||
subs Lh, Ly2, Lxy, asr #16 // Lh = N->v.y - L->v.y
|
||||
@ -171,7 +172,8 @@ rasterizeGTA_asm:
|
||||
.calc_right_start:
|
||||
cmp Rh, #0
|
||||
bne .calc_right_end // if (Rh != 0) end with right
|
||||
ldr N, [R, #VERTEX_NEXT] // N = R->next
|
||||
ldrsb N, [R, #VERTEX_NEXT] // N = R + R->next
|
||||
add N, R, N, lsl #VERTEX_SIZEOF_SHIFT
|
||||
ldr Rxy, [R, #VERTEX_X] // Rxy = (R->v.y << 16) | (R->v.x)
|
||||
ldrsh Ry2, [N, #VERTEX_Y] // Ry2 = N->v.y
|
||||
subs Rh, Ry2, Rxy, asr #16 // Rh = N->v.y - R->v.y
|
||||
|
@ -39,7 +39,8 @@ rasterizeS_asm:
|
||||
.calc_left_start:
|
||||
cmp Lh, #0
|
||||
bne .calc_left_end // if (Lh != 0) end with left
|
||||
ldr N, [L, #VERTEX_PREV] // N = L->prev
|
||||
ldrsb N, [L, #VERTEX_PREV] // N = L + L->prev
|
||||
add N, L, N, lsl #VERTEX_SIZEOF_SHIFT
|
||||
ldr Lxy, [L, #VERTEX_X] // Lxy = (L->v.y << 16) | (L->v.x)
|
||||
ldrsh Ly2, [N, #VERTEX_Y] // Ly2 = N->v.y
|
||||
subs Lh, Ly2, Lxy, asr #16 // Lh = N->v.y - L->v.y
|
||||
@ -59,7 +60,8 @@ rasterizeS_asm:
|
||||
.calc_right_start:
|
||||
cmp Rh, #0
|
||||
bne .calc_right_end // if (Rh != 0) end with right
|
||||
ldr N, [R, #VERTEX_NEXT] // N = R->next
|
||||
ldrsb N, [R, #VERTEX_NEXT] // N = R + R->next
|
||||
add N, R, N, lsl #VERTEX_SIZEOF_SHIFT
|
||||
ldr Rxy, [R, #VERTEX_X] // Rxy = (R->v.y << 16) | (R->v.x)
|
||||
ldrsh Ry2, [N, #VERTEX_Y] // Ry2 = N->v.y
|
||||
subs Rh, Ry2, Rxy, asr #16 // Rh = N->v.y - R->v.y
|
||||
|
@ -60,7 +60,7 @@ void rasterizeS_c(uint16* pixel, const VertexLink* L, const VertexLink* R)
|
||||
{
|
||||
while (!Lh)
|
||||
{
|
||||
const VertexLink* N = L->prev;
|
||||
const VertexLink* N = L + L->prev;
|
||||
|
||||
if (N->v.y < L->v.y) return;
|
||||
|
||||
@ -79,7 +79,7 @@ void rasterizeS_c(uint16* pixel, const VertexLink* L, const VertexLink* R)
|
||||
|
||||
while (!Rh)
|
||||
{
|
||||
const VertexLink* N = R->next;
|
||||
const VertexLink* N = R + R->next;
|
||||
|
||||
if (N->v.y < R->v.y) return;
|
||||
|
||||
@ -167,7 +167,7 @@ void rasterizeF_c(uint16* pixel, const VertexLink* L, const VertexLink* R)
|
||||
{
|
||||
while (!Lh)
|
||||
{
|
||||
const VertexLink* N = L->prev;
|
||||
const VertexLink* N = L + L->prev;
|
||||
|
||||
ASSERT(L->v.y >= 0);
|
||||
|
||||
@ -188,7 +188,7 @@ void rasterizeF_c(uint16* pixel, const VertexLink* L, const VertexLink* R)
|
||||
|
||||
while (!Rh)
|
||||
{
|
||||
const VertexLink* N = R->next;
|
||||
const VertexLink* N = R + R->next;
|
||||
|
||||
ASSERT(R->v.y >= 0);
|
||||
|
||||
@ -270,7 +270,7 @@ void rasterizeG_c(uint16* pixel, const VertexLink* L, const VertexLink* R, int32
|
||||
{
|
||||
while (!Lh)
|
||||
{
|
||||
const VertexLink* N = L->prev;
|
||||
const VertexLink* N = L + L->prev;
|
||||
|
||||
if (N->v.y < L->v.y) return;
|
||||
|
||||
@ -292,7 +292,7 @@ void rasterizeG_c(uint16* pixel, const VertexLink* L, const VertexLink* R, int32
|
||||
|
||||
while (!Rh)
|
||||
{
|
||||
const VertexLink* N = R->next;
|
||||
const VertexLink* N = R + R->next;
|
||||
|
||||
if (N->v.y < R->v.y) return;
|
||||
|
||||
@ -396,7 +396,7 @@ void rasterizeFT_c(uint16* pixel, const VertexLink* L, const VertexLink* R)
|
||||
{
|
||||
while (!Lh)
|
||||
{
|
||||
const VertexLink* N = L->prev;
|
||||
const VertexLink* N = L + L->prev;
|
||||
|
||||
if (N->v.y < L->v.y) return;
|
||||
|
||||
@ -421,7 +421,7 @@ void rasterizeFT_c(uint16* pixel, const VertexLink* L, const VertexLink* R)
|
||||
|
||||
while (!Rh)
|
||||
{
|
||||
const VertexLink* N = R->next;
|
||||
const VertexLink* N = R + R->next;
|
||||
|
||||
if (N->v.y < R->v.y) return;
|
||||
|
||||
@ -528,7 +528,7 @@ void rasterizeGT_c(uint16* pixel, const VertexLink* L, const VertexLink* R)
|
||||
{
|
||||
while (!Lh)
|
||||
{
|
||||
const VertexLink* N = L->prev;
|
||||
const VertexLink* N = L + L->prev;
|
||||
|
||||
if (N->v.y < L->v.y) return;
|
||||
|
||||
@ -556,7 +556,7 @@ void rasterizeGT_c(uint16* pixel, const VertexLink* L, const VertexLink* R)
|
||||
|
||||
while (!Rh)
|
||||
{
|
||||
const VertexLink* N = R->next;
|
||||
const VertexLink* N = R + R->next;
|
||||
|
||||
if (N->v.y < R->v.y) return;
|
||||
|
||||
@ -680,7 +680,7 @@ void rasterizeFTA_c(uint16* pixel, const VertexLink* L, const VertexLink* R)
|
||||
{
|
||||
while (!Lh)
|
||||
{
|
||||
const VertexLink* N = L->prev;
|
||||
const VertexLink* N = L + L->prev;
|
||||
|
||||
if (N->v.y < L->v.y) return;
|
||||
|
||||
@ -705,7 +705,7 @@ void rasterizeFTA_c(uint16* pixel, const VertexLink* L, const VertexLink* R)
|
||||
|
||||
while (!Rh)
|
||||
{
|
||||
const VertexLink* N = R->next;
|
||||
const VertexLink* N = R + R->next;
|
||||
|
||||
if (N->v.y < R->v.y) return;
|
||||
|
||||
@ -823,7 +823,7 @@ void rasterizeGTA_c(uint16* pixel, const VertexLink* L, const VertexLink* R)
|
||||
{
|
||||
while (!Lh)
|
||||
{
|
||||
const VertexLink* N = L->prev;
|
||||
const VertexLink* N = L + L->prev;
|
||||
|
||||
if (N->v.y < L->v.y) return;
|
||||
|
||||
@ -851,7 +851,7 @@ void rasterizeGTA_c(uint16* pixel, const VertexLink* L, const VertexLink* R)
|
||||
|
||||
while (!Rh)
|
||||
{
|
||||
const VertexLink* N = R->next;
|
||||
const VertexLink* N = R + R->next;
|
||||
|
||||
if (N->v.y < R->v.y) return;
|
||||
|
||||
|
@ -13,8 +13,9 @@ struct VertexLink
|
||||
{
|
||||
Vertex v;
|
||||
TexCoord t;
|
||||
VertexLink* prev;
|
||||
VertexLink* next;
|
||||
int8 prev;
|
||||
int8 next;
|
||||
uint16 padding;
|
||||
};
|
||||
|
||||
struct ViewportRel {
|
||||
@ -637,16 +638,6 @@ X_NOINLINE void rasterize_c(uint32 flags, VertexLink* top)
|
||||
top->v.clip = flags; // use tex coord as color index for untextured polys
|
||||
}
|
||||
|
||||
#if defined(_WIN32)
|
||||
if (type <= FACE_TYPE_GTA) {
|
||||
VertexLink* t = top;
|
||||
do {
|
||||
ASSERT(t->v.x >= 0 && t->v.x <= FRAME_WIDTH && t->v.y >= 0 && t->v.y <= FRAME_HEIGHT);
|
||||
t = t->next;
|
||||
} while (t != top);
|
||||
}
|
||||
#endif
|
||||
|
||||
gRasterProc[type]((uint16*)pixel, top, top);
|
||||
}
|
||||
|
||||
@ -805,30 +796,30 @@ void renderInit()
|
||||
|
||||
extern "C" X_NOINLINE void drawTriangle(uint32 flags, VertexLink* v)
|
||||
{
|
||||
VertexLink* v1 = v + 0;
|
||||
VertexLink* v2 = v + 1;
|
||||
VertexLink* v3 = v + 2;
|
||||
VertexLink* v0 = v + 0;
|
||||
VertexLink* v1 = v + 1;
|
||||
VertexLink* v2 = v + 2;
|
||||
|
||||
v1->next = v2;
|
||||
v2->next = v3;
|
||||
v3->next = v1;
|
||||
v1->prev = v3;
|
||||
v2->prev = v1;
|
||||
v3->prev = v2;
|
||||
v0->next = v1 - v0;
|
||||
v1->next = v2 - v1;
|
||||
v2->next = v0 - v2;
|
||||
v0->prev = v2 - v0;
|
||||
v1->prev = v0 - v1;
|
||||
v2->prev = v1 - v2;
|
||||
|
||||
VertexLink* top = v1;
|
||||
VertexLink* top;
|
||||
|
||||
if (v1->v.y < v2->v.y) {
|
||||
if (v1->v.y < v3->v.y) {
|
||||
top = v1;
|
||||
if (v0->v.y < v1->v.y) {
|
||||
if (v0->v.y < v2->v.y) {
|
||||
top = v0;
|
||||
} else {
|
||||
top = v3;
|
||||
top = v2;
|
||||
}
|
||||
} else {
|
||||
if (v2->v.y < v3->v.y) {
|
||||
top = v2;
|
||||
if (v1->v.y < v2->v.y) {
|
||||
top = v1;
|
||||
} else {
|
||||
top = v3;
|
||||
top = v2;
|
||||
}
|
||||
}
|
||||
|
||||
@ -837,33 +828,33 @@ extern "C" X_NOINLINE void drawTriangle(uint32 flags, VertexLink* v)
|
||||
|
||||
extern "C" X_NOINLINE void drawQuad(uint32 flags, VertexLink* v)
|
||||
{
|
||||
VertexLink* v1 = v + 0;
|
||||
VertexLink* v2 = v + 1;
|
||||
VertexLink* v3 = v + 2;
|
||||
VertexLink* v4 = v + 3;
|
||||
VertexLink* v0 = v + 0;
|
||||
VertexLink* v1 = v + 1;
|
||||
VertexLink* v2 = v + 2;
|
||||
VertexLink* v3 = v + 3;
|
||||
|
||||
v1->next = v2;
|
||||
v2->next = v3;
|
||||
v3->next = v4;
|
||||
v4->next = v1;
|
||||
v1->prev = v4;
|
||||
v2->prev = v1;
|
||||
v3->prev = v2;
|
||||
v4->prev = v3;
|
||||
v0->next = v1 - v0;
|
||||
v1->next = v2 - v1;
|
||||
v2->next = v3 - v2;
|
||||
v3->next = v0 - v3;
|
||||
v0->prev = v3 - v0;
|
||||
v1->prev = v0 - v1;
|
||||
v2->prev = v1 - v2;
|
||||
v3->prev = v2 - v3;
|
||||
|
||||
VertexLink* top;
|
||||
|
||||
if (v1->v.y < v2->v.y) {
|
||||
if (v1->v.y < v3->v.y) {
|
||||
top = (v1->v.y < v4->v.y) ? v1 : v4;
|
||||
if (v0->v.y < v1->v.y) {
|
||||
if (v0->v.y < v2->v.y) {
|
||||
top = (v0->v.y < v3->v.y) ? v0 : v3;
|
||||
} else {
|
||||
top = (v3->v.y < v4->v.y) ? v3 : v4;
|
||||
top = (v2->v.y < v3->v.y) ? v2 : v3;
|
||||
}
|
||||
} else {
|
||||
if (v2->v.y < v3->v.y) {
|
||||
top = (v2->v.y < v4->v.y) ? v2 : v4;
|
||||
if (v1->v.y < v2->v.y) {
|
||||
top = (v1->v.y < v3->v.y) ? v1 : v3;
|
||||
} else {
|
||||
top = (v3->v.y < v4->v.y) ? v3 : v4;
|
||||
top = (v2->v.y < v3->v.y) ? v2 : v3;
|
||||
}
|
||||
}
|
||||
|
||||
@ -902,17 +893,30 @@ extern "C" X_NOINLINE void drawPoly(uint32 flags, VertexLink* v)
|
||||
}
|
||||
|
||||
VertexLink* top = v;
|
||||
top->next = v + 1;
|
||||
top->prev = v + count - 1;
|
||||
top->next = (v + 1) - top;
|
||||
top->prev = (v + count - 1) - top;
|
||||
|
||||
bool skip = true;
|
||||
|
||||
for (int32 i = 1; i < count; i++)
|
||||
{
|
||||
VertexLink *p = v + i;
|
||||
int8 next = i + 1;
|
||||
int8 prev = i - 1;
|
||||
|
||||
p->next = v + (i + 1) % count;
|
||||
p->prev = v + (i - 1 + count) % count;
|
||||
if (next >= count) {
|
||||
next -= count;
|
||||
}
|
||||
|
||||
if (prev < 0) {
|
||||
prev += count;
|
||||
}
|
||||
|
||||
next -= i;
|
||||
prev -= i;
|
||||
|
||||
VertexLink *p = v + i;
|
||||
p->next = next;
|
||||
p->prev = prev;
|
||||
|
||||
if (p->v.y != top->v.y)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user