From e5375e1d64dbb964c3f195c47eb6fd72783d09cb Mon Sep 17 00:00:00 2001 From: Arthur Date: Sat, 15 Dec 2018 08:46:08 -0500 Subject: [PATCH 01/66] New fixed math functions - ClosestPointOnVector, and Strength. Normal also returns length now, since it is free. --- src/m_fixed.c | 239 +++++++++++++++++++++++++++++--------------------- src/m_fixed.h | 4 +- 2 files changed, 140 insertions(+), 103 deletions(-) diff --git a/src/m_fixed.c b/src/m_fixed.c index d45bb70bf..5e7896739 100644 --- a/src/m_fixed.c +++ b/src/m_fixed.c @@ -56,7 +56,7 @@ fixed_t FixedDiv2(fixed_t a, fixed_t b) if (b == 0) I_Error("FixedDiv: divide by zero"); - ret = (((INT64)a * FRACUNIT) ) / b; + ret = (((INT64)a * FRACUNIT)) / b; if ((ret > INT32_MAX) || (ret < INT32_MIN)) I_Error("FixedDiv: divide by zero"); @@ -117,7 +117,7 @@ fixed_t FixedHypot(fixed_t x, fixed_t y) yx = FixedDiv(y, x); // (x/y) } yx2 = FixedMul(yx, yx); // (x/y)^2 - yx1 = FixedSqrt(1*FRACUNIT + yx2); // (1 + (x/y)^2)^1/2 + yx1 = FixedSqrt(1 * FRACUNIT + yx2); // (1 + (x/y)^2)^1/2 return FixedMul(ax, yx1); // |x|*((1 + (x/y)^2)^1/2) } @@ -191,8 +191,8 @@ vector2_t *FV2_Divide(vector2_t *a_i, fixed_t a_c) // Vector Complex Math vector2_t *FV2_Midpoint(const vector2_t *a_1, const vector2_t *a_2, vector2_t *a_o) { - a_o->x = FixedDiv(a_2->x - a_1->x, 2*FRACUNIT); - a_o->y = FixedDiv(a_2->y - a_1->y, 2*FRACUNIT); + a_o->x = FixedDiv(a_2->x - a_1->x, 2 * FRACUNIT); + a_o->y = FixedDiv(a_2->y - a_1->y, 2 * FRACUNIT); a_o->x = a_1->x + a_o->x; a_o->y = a_1->y + a_o->y; return a_o; @@ -200,16 +200,16 @@ vector2_t *FV2_Midpoint(const vector2_t *a_1, const vector2_t *a_2, vector2_t *a fixed_t FV2_Distance(const vector2_t *p1, const vector2_t *p2) { - fixed_t xs = FixedMul(p2->x-p1->x,p2->x-p1->x); - fixed_t ys = FixedMul(p2->y-p1->y,p2->y-p1->y); - return FixedSqrt(xs+ys); + fixed_t xs = FixedMul(p2->x - p1->x, p2->x - p1->x); + fixed_t ys = FixedMul(p2->y - p1->y, p2->y - p1->y); + return FixedSqrt(xs + ys); } fixed_t FV2_Magnitude(const vector2_t *a_normal) { - fixed_t xs = FixedMul(a_normal->x,a_normal->x); - fixed_t ys = FixedMul(a_normal->y,a_normal->y); - return FixedSqrt(xs+ys); + fixed_t xs = FixedMul(a_normal->x, a_normal->x); + fixed_t ys = FixedMul(a_normal->y, a_normal->y); + return FixedSqrt(xs + ys); } // Also returns the magnitude @@ -240,7 +240,7 @@ vector2_t *FV2_Negate(vector2_t *a_1) boolean FV2_Equal(const vector2_t *a_1, const vector2_t *a_2) { - fixed_t Epsilon = FRACUNIT/FRACUNIT; + fixed_t Epsilon = FRACUNIT / FRACUNIT; if ((abs(a_2->x - a_1->x) > Epsilon) || (abs(a_2->y - a_1->y) > Epsilon)) @@ -261,7 +261,7 @@ fixed_t FV2_Dot(const vector2_t *a_1, const vector2_t *a_2) // // Given two points, create a vector between them. // -vector2_t *FV2_Point2Vec (const vector2_t *point1, const vector2_t *point2, vector2_t *a_o) +vector2_t *FV2_Point2Vec(const vector2_t *point1, const vector2_t *point2, vector2_t *a_o) { a_o->x = point1->x - point2->x; a_o->y = point1->y - point2->y; @@ -344,9 +344,9 @@ vector3_t *FV3_Divide(vector3_t *a_i, fixed_t a_c) // Vector Complex Math vector3_t *FV3_Midpoint(const vector3_t *a_1, const vector3_t *a_2, vector3_t *a_o) { - a_o->x = FixedDiv(a_2->x - a_1->x, 2*FRACUNIT); - a_o->y = FixedDiv(a_2->y - a_1->y, 2*FRACUNIT); - a_o->z = FixedDiv(a_2->z - a_1->z, 2*FRACUNIT); + a_o->x = FixedDiv(a_2->x - a_1->x, 2 * FRACUNIT); + a_o->y = FixedDiv(a_2->y - a_1->y, 2 * FRACUNIT); + a_o->z = FixedDiv(a_2->z - a_1->z, 2 * FRACUNIT); a_o->x = a_1->x + a_o->x; a_o->y = a_1->y + a_o->y; a_o->z = a_1->z + a_o->z; @@ -355,18 +355,18 @@ vector3_t *FV3_Midpoint(const vector3_t *a_1, const vector3_t *a_2, vector3_t *a fixed_t FV3_Distance(const vector3_t *p1, const vector3_t *p2) { - fixed_t xs = FixedMul(p2->x-p1->x,p2->x-p1->x); - fixed_t ys = FixedMul(p2->y-p1->y,p2->y-p1->y); - fixed_t zs = FixedMul(p2->z-p1->z,p2->z-p1->z); - return FixedSqrt(xs+ys+zs); + fixed_t xs = FixedMul(p2->x - p1->x, p2->x - p1->x); + fixed_t ys = FixedMul(p2->y - p1->y, p2->y - p1->y); + fixed_t zs = FixedMul(p2->z - p1->z, p2->z - p1->z); + return FixedSqrt(xs + ys + zs); } fixed_t FV3_Magnitude(const vector3_t *a_normal) { - fixed_t xs = FixedMul(a_normal->x,a_normal->x); - fixed_t ys = FixedMul(a_normal->y,a_normal->y); - fixed_t zs = FixedMul(a_normal->z,a_normal->z); - return FixedSqrt(xs+ys+zs); + fixed_t xs = FixedMul(a_normal->x, a_normal->x); + fixed_t ys = FixedMul(a_normal->y, a_normal->y); + fixed_t zs = FixedMul(a_normal->z, a_normal->z); + return FixedSqrt(xs + ys + zs); } // Also returns the magnitude @@ -399,7 +399,7 @@ vector3_t *FV3_Negate(vector3_t *a_1) boolean FV3_Equal(const vector3_t *a_1, const vector3_t *a_2) { - fixed_t Epsilon = FRACUNIT/FRACUNIT; + fixed_t Epsilon = FRACUNIT / FRACUNIT; if ((abs(a_2->x - a_1->x) > Epsilon) || (abs(a_2->y - a_1->y) > Epsilon) || @@ -458,6 +458,20 @@ vector3_t *FV3_ClosestPointOnLine(const vector3_t *Line, const vector3_t *p, vec return FV3_AddEx(&Line[0], &V, out); } +// +// ClosestPointOnVector +// +// Similar to ClosestPointOnLine, but uses a vector instead of two points. +// +void FV3_ClosestPointOnVector(const vector3_t *dir, const vector3_t *p, vector3_t *out) +{ + fixed_t t = FV3_Dot(dir, p); + + // Return the point on the line closest + FV3_MulEx(dir, t, out); + return; +} + // // ClosestPointOnTriangle // @@ -465,7 +479,7 @@ vector3_t *FV3_ClosestPointOnLine(const vector3_t *Line, const vector3_t *p, vec // the closest point on the edge of // the triangle is returned. // -void FV3_ClosestPointOnTriangle (const vector3_t *tri, const vector3_t *point, vector3_t *result) +void FV3_ClosestPointOnTriangle(const vector3_t *tri, const vector3_t *point, vector3_t *result) { UINT8 i; fixed_t dist, closestdist; @@ -506,7 +520,7 @@ void FV3_ClosestPointOnTriangle (const vector3_t *tri, const vector3_t *point, v // // Given two points, create a vector between them. // -vector3_t *FV3_Point2Vec (const vector3_t *point1, const vector3_t *point2, vector3_t *a_o) +vector3_t *FV3_Point2Vec(const vector3_t *point1, const vector3_t *point2, vector3_t *a_o) { a_o->x = point1->x - point2->x; a_o->y = point1->y - point2->y; @@ -519,7 +533,7 @@ vector3_t *FV3_Point2Vec (const vector3_t *point1, const vector3_t *point2, vect // // Calculates the normal of a polygon. // -void FV3_Normal (const vector3_t *a_triangle, vector3_t *a_normal) +fixed_t FV3_Normal(const vector3_t *a_triangle, vector3_t *a_normal) { vector3_t a_1; vector3_t a_2; @@ -529,7 +543,28 @@ void FV3_Normal (const vector3_t *a_triangle, vector3_t *a_normal) FV3_Cross(&a_1, &a_2, a_normal); - FV3_NormalizeEx(a_normal, a_normal); + return FV3_NormalizeEx(a_normal, a_normal); +} + +// +// Strength +// +// Measures the 'strength' of a vector in a particular direction. +// +fixed_t FV3_Strength(const vector3_t *a_1, const vector3_t *dir) +{ + vector3_t normal; + fixed_t dist = FV3_NormalizeEx(a_1, &normal); + fixed_t dot = FV3_Dot(&normal, dir); + + FV3_ClosestPointOnVector(dir, a_1, &normal); + + dist = FV3_Magnitude(&normal); + + if (dot < 0) // Not facing same direction, so negate result. + dist = -dist; + + return dist; } // @@ -550,11 +585,11 @@ boolean FV3_IntersectedPlane(const vector3_t *a_triangle, const vector3_t *a_lin *originDistance = FV3_PlaneDistance(a_normal, &a_triangle[0]); - distance1 = (FixedMul(a_normal->x, a_line[0].x) + FixedMul(a_normal->y, a_line[0].y) - + FixedMul(a_normal->z, a_line[0].z)) + *originDistance; + distance1 = (FixedMul(a_normal->x, a_line[0].x) + FixedMul(a_normal->y, a_line[0].y) + + FixedMul(a_normal->z, a_line[0].z)) + *originDistance; - distance2 = (FixedMul(a_normal->x, a_line[1].x) + FixedMul(a_normal->y, a_line[1].y) - + FixedMul(a_normal->z, a_line[1].z)) + *originDistance; + distance2 = (FixedMul(a_normal->x, a_line[1].x) + FixedMul(a_normal->y, a_line[1].y) + + FixedMul(a_normal->z, a_line[1].z)) + *originDistance; // Positive or zero number means no intersection if (FixedMul(distance1, distance2) >= 0) @@ -575,8 +610,8 @@ boolean FV3_IntersectedPlane(const vector3_t *a_triangle, const vector3_t *a_lin fixed_t FV3_PlaneIntersection(const vector3_t *pOrigin, const vector3_t *pNormal, const vector3_t *rOrigin, const vector3_t *rVector) { fixed_t d = -(FV3_Dot(pNormal, pOrigin)); - fixed_t number = FV3_Dot(pNormal,rOrigin) + d; - fixed_t denom = FV3_Dot(pNormal,rVector); + fixed_t number = FV3_Dot(pNormal, rOrigin) + d; + fixed_t denom = FV3_Dot(pNormal, rVector); return -FixedDiv(number, denom); } @@ -597,11 +632,11 @@ fixed_t FV3_IntersectRaySphere(const vector3_t *rO, const vector3_t *rV, const v c = FV3_Magnitude(&Q); v = FV3_Dot(&Q, rV); - d = FixedMul(sR, sR) - (FixedMul(c,c) - FixedMul(v,v)); + d = FixedMul(sR, sR) - (FixedMul(c, c) - FixedMul(v, v)); // If there was no intersection, return -1 - if (d < 0*FRACUNIT) - return (-1*FRACUNIT); + if (d < 0 * FRACUNIT) + return (-1 * FRACUNIT); // Return the distance to the [first] intersecting point return (v - FixedSqrt(d)); @@ -629,9 +664,9 @@ vector3_t *FV3_IntersectionPoint(const vector3_t *vNormal, const vector3_t *vLin // Here I just chose a arbitrary point as the point to find that distance. You notice we negate that // distance. We negate the distance because we want to eventually go BACKWARDS from our point to the plane. // By doing this is will basically bring us back to the plane to find our intersection point. - Numerator = - (FixedMul(vNormal->x, vLine[0].x) + // Use the plane equation with the normal and the line - FixedMul(vNormal->y, vLine[0].y) + - FixedMul(vNormal->z, vLine[0].z) + distance); + Numerator = -(FixedMul(vNormal->x, vLine[0].x) + // Use the plane equation with the normal and the line + FixedMul(vNormal->y, vLine[0].y) + + FixedMul(vNormal->z, vLine[0].z) + distance); // 3) If we take the dot product between our line vector and the normal of the polygon, // this will give us the cosine of the angle between the 2 (since they are both normalized - length 1). @@ -643,7 +678,7 @@ vector3_t *FV3_IntersectionPoint(const vector3_t *vNormal, const vector3_t *vLin // on the plane (the normal is perpendicular to the line - (Normal.Vector = 0)). // In this case, we should just return any point on the line. - if( Denominator == 0*FRACUNIT) // Check so we don't divide by zero + if (Denominator == 0 * FRACUNIT) // Check so we don't divide by zero { ReturnVec->x = vLine[0].x; ReturnVec->y = vLine[0].y; @@ -686,8 +721,8 @@ vector3_t *FV3_IntersectionPoint(const vector3_t *vNormal, const vector3_t *vLin // UINT8 FV3_PointOnLineSide(const vector3_t *point, const vector3_t *line) { - fixed_t s1 = FixedMul((point->y - line[0].y),(line[1].x - line[0].x)); - fixed_t s2 = FixedMul((point->x - line[0].x),(line[1].y - line[0].y)); + fixed_t s1 = FixedMul((point->y - line[0].y), (line[1].x - line[0].x)); + fixed_t s2 = FixedMul((point->x - line[0].x), (line[1].y - line[0].y)); return (UINT8)(s1 - s2 < 0); } @@ -752,7 +787,7 @@ void FM_CreateObjectMatrix(matrix_t *matrix, fixed_t x, fixed_t y, fixed_t z, fi matrix->m[0] = upcross.x; matrix->m[1] = upcross.y; matrix->m[2] = upcross.z; - matrix->m[3] = 0*FRACUNIT; + matrix->m[3] = 0 * FRACUNIT; matrix->m[4] = upx; matrix->m[5] = upy; @@ -764,9 +799,9 @@ void FM_CreateObjectMatrix(matrix_t *matrix, fixed_t x, fixed_t y, fixed_t z, fi matrix->m[10] = anglez; matrix->m[11] = 0; - matrix->m[12] = x - FixedMul(upx,radius); - matrix->m[13] = y - FixedMul(upy,radius); - matrix->m[14] = z - FixedMul(upz,radius); + matrix->m[12] = x - FixedMul(upx, radius); + matrix->m[13] = y - FixedMul(upy, radius); + matrix->m[14] = z - FixedMul(upz, radius); matrix->m[15] = FRACUNIT; } @@ -778,20 +813,20 @@ void FM_CreateObjectMatrix(matrix_t *matrix, fixed_t x, fixed_t y, fixed_t z, fi void FM_MultMatrixVec3(const matrix_t *matrix, const vector3_t *vec, vector3_t *out) { #define M(row,col) matrix->m[col * 4 + row] - out->x = FixedMul(vec->x,M(0, 0)) - + FixedMul(vec->y,M(0, 1)) - + FixedMul(vec->z,M(0, 2)) - + M(0, 3); + out->x = FixedMul(vec->x, M(0, 0)) + + FixedMul(vec->y, M(0, 1)) + + FixedMul(vec->z, M(0, 2)) + + M(0, 3); - out->y = FixedMul(vec->x,M(1, 0)) - + FixedMul(vec->y,M(1, 1)) - + FixedMul(vec->z,M(1, 2)) - + M(1, 3); + out->y = FixedMul(vec->x, M(1, 0)) + + FixedMul(vec->y, M(1, 1)) + + FixedMul(vec->z, M(1, 2)) + + M(1, 3); - out->z = FixedMul(vec->x,M(2, 0)) - + FixedMul(vec->y,M(2, 1)) - + FixedMul(vec->z,M(2, 2)) - + M(2, 3); + out->z = FixedMul(vec->x, M(2, 0)) + + FixedMul(vec->y, M(2, 1)) + + FixedMul(vec->z, M(2, 2)) + + M(2, 3); #undef M } @@ -811,7 +846,7 @@ void FM_MultMatrix(matrix_t *dest, const matrix_t *multme) for (i = 0; i < 4; i++) { for (j = 0; j < 4; j++) - R(i, j) = FixedMul(D(i, 0),M(0, j)) + FixedMul(D(i, 1),M(1, j)) + FixedMul(D(i, 2),M(2, j)) + FixedMul(D(i, 3),M(3, j)); + R(i, j) = FixedMul(D(i, 0), M(0, j)) + FixedMul(D(i, 1), M(1, j)) + FixedMul(D(i, 2), M(2, j)) + FixedMul(D(i, 3), M(3, j)); } M_Memcpy(dest, &result, sizeof(matrix_t)); @@ -869,8 +904,8 @@ void FM_Scale(matrix_t *dest, fixed_t x, fixed_t y, fixed_t z) static inline void M_print(INT64 a) { - const fixed_t w = (a>>FRACBITS); - fixed_t f = a%FRACUNIT; + const fixed_t w = (a >> FRACBITS); + fixed_t f = a % FRACUNIT; fixed_t d = FRACUNIT; if (f == 0) @@ -878,7 +913,7 @@ static inline void M_print(INT64 a) printf("%d", (fixed_t)w); return; } - else while (f != 1 && f/2 == f>>1) + else while (f != 1 && f / 2 == f >> 1) { d /= 2; f /= 2; @@ -892,7 +927,7 @@ static inline void M_print(INT64 a) FUNCMATH FUNCINLINE static inline fixed_t FixedMulC(fixed_t a, fixed_t b) { - return (fixed_t)((((INT64)a * b) ) / FRACUNIT); + return (fixed_t)((((INT64)a * b)) / FRACUNIT); } FUNCMATH FUNCINLINE static inline fixed_t FixedDivC2(fixed_t a, fixed_t b) @@ -902,7 +937,7 @@ FUNCMATH FUNCINLINE static inline fixed_t FixedDivC2(fixed_t a, fixed_t b) if (b == 0) I_Error("FixedDiv: divide by zero"); - ret = (((INT64)a * FRACUNIT) ) / b; + ret = (((INT64)a * FRACUNIT)) / b; if ((ret > INT32_MAX) || (ret < INT32_MIN)) I_Error("FixedDiv: divide by zero"); @@ -911,7 +946,7 @@ FUNCMATH FUNCINLINE static inline fixed_t FixedDivC2(fixed_t a, fixed_t b) FUNCMATH FUNCINLINE static inline fixed_t FixedDivC(fixed_t a, fixed_t b) { - if ((abs(a) >> (FRACBITS-2)) >= abs(b)) + if ((abs(a) >> (FRACBITS - 2)) >= abs(b)) return (a^b) < 0 ? INT32_MIN : INT32_MAX; return FixedDivC2(a, b); @@ -938,43 +973,43 @@ int main(int argc, char** argv) #ifdef MULDIV_TEST for (a = 1; a <= INT32_MAX; a += FRACUNIT) - for (b = 0; b <= INT32_MAX; b += FRACUNIT) - { - c = FixedMul(a, b); - d = FixedMulC(a, b); - if (c != d) + for (b = 0; b <= INT32_MAX; b += FRACUNIT) { - printf("("); - M_print(a); - printf(") * ("); - M_print(b); - printf(") = ("); - M_print(c); - printf(") != ("); - M_print(d); - printf(") \n"); - n--; - printf("%d != %d\n", c, d); + c = FixedMul(a, b); + d = FixedMulC(a, b); + if (c != d) + { + printf("("); + M_print(a); + printf(") * ("); + M_print(b); + printf(") = ("); + M_print(c); + printf(") != ("); + M_print(d); + printf(") \n"); + n--; + printf("%d != %d\n", c, d); + } + c = FixedDiv(a, b); + d = FixedDivC(a, b); + if (c != d) + { + printf("("); + M_print(a); + printf(") / ("); + M_print(b); + printf(") = ("); + M_print(c); + printf(") != ("); + M_print(d); + printf(")\n"); + n--; + printf("%d != %d\n", c, d); + } + if (n <= 0) + exit(-1); } - c = FixedDiv(a, b); - d = FixedDivC(a, b); - if (c != d) - { - printf("("); - M_print(a); - printf(") / ("); - M_print(b); - printf(") = ("); - M_print(c); - printf(") != ("); - M_print(d); - printf(")\n"); - n--; - printf("%d != %d\n", c, d); - } - if (n <= 0) - exit(-1); - } #endif #ifdef SQRT_TEST @@ -982,7 +1017,7 @@ int main(int argc, char** argv) { c = FixedSqrt(a); d = FixedSqrtC(a); - b = abs(c-d); + b = abs(c - d); if (b > 1) { printf("sqrt("); diff --git a/src/m_fixed.h b/src/m_fixed.h index 4609913b7..8145a6917 100644 --- a/src/m_fixed.h +++ b/src/m_fixed.h @@ -394,9 +394,11 @@ boolean FV3_Equal(const vector3_t *a_1, const vector3_t *a_2); fixed_t FV3_Dot(const vector3_t *a_1, const vector3_t *a_2); vector3_t *FV3_Cross(const vector3_t *a_1, const vector3_t *a_2, vector3_t *a_o); vector3_t *FV3_ClosestPointOnLine(const vector3_t *Line, const vector3_t *p, vector3_t *out); +void FV3_ClosestPointOnVector(const vector3_t *dir, const vector3_t *p, vector3_t *out); void FV3_ClosestPointOnTriangle(const vector3_t *tri, const vector3_t *point, vector3_t *result); vector3_t *FV3_Point2Vec(const vector3_t *point1, const vector3_t *point2, vector3_t *a_o); -void FV3_Normal(const vector3_t *a_triangle, vector3_t *a_normal); +fixed_t FV3_Normal(const vector3_t *a_triangle, vector3_t *a_normal); +fixed_t FV3_Strength(const vector3_t *a_1, const vector3_t *dir); fixed_t FV3_PlaneDistance(const vector3_t *a_normal, const vector3_t *a_point); boolean FV3_IntersectedPlane(const vector3_t *a_triangle, const vector3_t *a_line, vector3_t *a_normal, fixed_t *originDistance); fixed_t FV3_PlaneIntersection(const vector3_t *pOrigin, const vector3_t *pNormal, const vector3_t *rOrigin, const vector3_t *rVector); From e67c1bee5d1549e4838138e7ae6b8435639b143e Mon Sep 17 00:00:00 2001 From: Arthur Date: Sat, 15 Dec 2018 20:57:11 -0500 Subject: [PATCH 02/66] Common model format, with MD2/MD3 loading --- src/hardware/hw_drv.h | 6 +- src/hardware/hw_md2.c | 361 +------------ src/hardware/hw_md2.h | 94 +--- src/hardware/hw_md2load.c | 520 ++++++++++++++++++ src/hardware/hw_md2load.h | 19 + src/hardware/hw_md3load.c | 489 +++++++++++++++++ src/hardware/hw_md3load.h | 19 + src/hardware/hw_model.c | 706 +++++++++++++++++++++++++ src/hardware/hw_model.h | 104 ++++ src/hardware/r_opengl/r_opengl.c | 178 ++++--- src/hardware/u_list.c | 230 ++++++++ src/hardware/u_list.h | 29 + src/sdl/Srb2SDL-vc10.vcxproj | 10 +- src/sdl/Srb2SDL-vc10.vcxproj.filters | 24 + src/sdl/hwsym_sdl.c | 3 +- src/sdl/i_video.c | 3 +- src/win32/Srb2win-vc10.vcxproj | 10 +- src/win32/Srb2win-vc10.vcxproj.filters | 24 + src/win32/win_dll.c | 6 +- 19 files changed, 2319 insertions(+), 516 deletions(-) create mode 100644 src/hardware/hw_md2load.c create mode 100644 src/hardware/hw_md2load.h create mode 100644 src/hardware/hw_md3load.c create mode 100644 src/hardware/hw_md3load.h create mode 100644 src/hardware/hw_model.c create mode 100644 src/hardware/hw_model.h create mode 100644 src/hardware/u_list.c create mode 100644 src/hardware/u_list.h diff --git a/src/hardware/hw_drv.h b/src/hardware/hw_drv.h index e2fa90eb0..0afd6d272 100644 --- a/src/hardware/hw_drv.h +++ b/src/hardware/hw_drv.h @@ -58,8 +58,7 @@ EXPORT void HWRAPI(ClearMipMapCache) (void); EXPORT void HWRAPI(SetSpecialState) (hwdspecialstate_t IdState, INT32 Value); //Hurdler: added for new development -EXPORT void HWRAPI(DrawMD2) (INT32 *gl_cmd_buffer, md2_frame_t *frame, FTransform *pos, float scale); -EXPORT void HWRAPI(DrawMD2i) (INT32 *gl_cmd_buffer, md2_frame_t *frame, INT32 duration, INT32 tics, md2_frame_t *nextframe, FTransform *pos, float scale, UINT8 flipped, UINT8 *color); +EXPORT void HWRAPI(DrawModel) (model_t *model, mdlframe_t *frame, INT32 duration, INT32 tics, mdlframe_t *nextframe, FTransform *pos, float scale, UINT8 flipped, UINT8 *color); EXPORT void HWRAPI(SetTransform) (FTransform *ptransform); EXPORT INT32 HWRAPI(GetTextureUsed) (void); EXPORT INT32 HWRAPI(GetRenderVersion) (void); @@ -96,8 +95,7 @@ struct hwdriver_s GClipRect pfnGClipRect; ClearMipMapCache pfnClearMipMapCache; SetSpecialState pfnSetSpecialState;//Hurdler: added for backward compatibility - DrawMD2 pfnDrawMD2; - DrawMD2i pfnDrawMD2i; + DrawModel pfnDrawModel; SetTransform pfnSetTransform; GetTextureUsed pfnGetTextureUsed; GetRenderVersion pfnGetRenderVersion; diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.c index 2856cada3..5d865c5ae 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -43,6 +43,7 @@ #include "../r_draw.h" #include "../p_tick.h" #include "../k_kart.h" // colortranslations +#include "hw_model.h" #include "hw_main.h" #include "../v_video.h" @@ -75,172 +76,6 @@ #include "errno.h" #endif -#define NUMVERTEXNORMALS 162 -float avertexnormals[NUMVERTEXNORMALS][3] = { -{-0.525731f, 0.000000f, 0.850651f}, -{-0.442863f, 0.238856f, 0.864188f}, -{-0.295242f, 0.000000f, 0.955423f}, -{-0.309017f, 0.500000f, 0.809017f}, -{-0.162460f, 0.262866f, 0.951056f}, -{0.000000f, 0.000000f, 1.000000f}, -{0.000000f, 0.850651f, 0.525731f}, -{-0.147621f, 0.716567f, 0.681718f}, -{0.147621f, 0.716567f, 0.681718f}, -{0.000000f, 0.525731f, 0.850651f}, -{0.309017f, 0.500000f, 0.809017f}, -{0.525731f, 0.000000f, 0.850651f}, -{0.295242f, 0.000000f, 0.955423f}, -{0.442863f, 0.238856f, 0.864188f}, -{0.162460f, 0.262866f, 0.951056f}, -{-0.681718f, 0.147621f, 0.716567f}, -{-0.809017f, 0.309017f, 0.500000f}, -{-0.587785f, 0.425325f, 0.688191f}, -{-0.850651f, 0.525731f, 0.000000f}, -{-0.864188f, 0.442863f, 0.238856f}, -{-0.716567f, 0.681718f, 0.147621f}, -{-0.688191f, 0.587785f, 0.425325f}, -{-0.500000f, 0.809017f, 0.309017f}, -{-0.238856f, 0.864188f, 0.442863f}, -{-0.425325f, 0.688191f, 0.587785f}, -{-0.716567f, 0.681718f, -0.147621f}, -{-0.500000f, 0.809017f, -0.309017f}, -{-0.525731f, 0.850651f, 0.000000f}, -{0.000000f, 0.850651f, -0.525731f}, -{-0.238856f, 0.864188f, -0.442863f}, -{0.000000f, 0.955423f, -0.295242f}, -{-0.262866f, 0.951056f, -0.162460f}, -{0.000000f, 1.000000f, 0.000000f}, -{0.000000f, 0.955423f, 0.295242f}, -{-0.262866f, 0.951056f, 0.162460f}, -{0.238856f, 0.864188f, 0.442863f}, -{0.262866f, 0.951056f, 0.162460f}, -{0.500000f, 0.809017f, 0.309017f}, -{0.238856f, 0.864188f, -0.442863f}, -{0.262866f, 0.951056f, -0.162460f}, -{0.500000f, 0.809017f, -0.309017f}, -{0.850651f, 0.525731f, 0.000000f}, -{0.716567f, 0.681718f, 0.147621f}, -{0.716567f, 0.681718f, -0.147621f}, -{0.525731f, 0.850651f, 0.000000f}, -{0.425325f, 0.688191f, 0.587785f}, -{0.864188f, 0.442863f, 0.238856f}, -{0.688191f, 0.587785f, 0.425325f}, -{0.809017f, 0.309017f, 0.500000f}, -{0.681718f, 0.147621f, 0.716567f}, -{0.587785f, 0.425325f, 0.688191f}, -{0.955423f, 0.295242f, 0.000000f}, -{1.000000f, 0.000000f, 0.000000f}, -{0.951056f, 0.162460f, 0.262866f}, -{0.850651f, -0.525731f, 0.000000f}, -{0.955423f, -0.295242f, 0.000000f}, -{0.864188f, -0.442863f, 0.238856f}, -{0.951056f, -0.162460f, 0.262866f}, -{0.809017f, -0.309017f, 0.500000f}, -{0.681718f, -0.147621f, 0.716567f}, -{0.850651f, 0.000000f, 0.525731f}, -{0.864188f, 0.442863f, -0.238856f}, -{0.809017f, 0.309017f, -0.500000f}, -{0.951056f, 0.162460f, -0.262866f}, -{0.525731f, 0.000000f, -0.850651f}, -{0.681718f, 0.147621f, -0.716567f}, -{0.681718f, -0.147621f, -0.716567f}, -{0.850651f, 0.000000f, -0.525731f}, -{0.809017f, -0.309017f, -0.500000f}, -{0.864188f, -0.442863f, -0.238856f}, -{0.951056f, -0.162460f, -0.262866f}, -{0.147621f, 0.716567f, -0.681718f}, -{0.309017f, 0.500000f, -0.809017f}, -{0.425325f, 0.688191f, -0.587785f}, -{0.442863f, 0.238856f, -0.864188f}, -{0.587785f, 0.425325f, -0.688191f}, -{0.688191f, 0.587785f, -0.425325f}, -{-0.147621f, 0.716567f, -0.681718f}, -{-0.309017f, 0.500000f, -0.809017f}, -{0.000000f, 0.525731f, -0.850651f}, -{-0.525731f, 0.000000f, -0.850651f}, -{-0.442863f, 0.238856f, -0.864188f}, -{-0.295242f, 0.000000f, -0.955423f}, -{-0.162460f, 0.262866f, -0.951056f}, -{0.000000f, 0.000000f, -1.000000f}, -{0.295242f, 0.000000f, -0.955423f}, -{0.162460f, 0.262866f, -0.951056f}, -{-0.442863f, -0.238856f, -0.864188f}, -{-0.309017f, -0.500000f, -0.809017f}, -{-0.162460f, -0.262866f, -0.951056f}, -{0.000000f, -0.850651f, -0.525731f}, -{-0.147621f, -0.716567f, -0.681718f}, -{0.147621f, -0.716567f, -0.681718f}, -{0.000000f, -0.525731f, -0.850651f}, -{0.309017f, -0.500000f, -0.809017f}, -{0.442863f, -0.238856f, -0.864188f}, -{0.162460f, -0.262866f, -0.951056f}, -{0.238856f, -0.864188f, -0.442863f}, -{0.500000f, -0.809017f, -0.309017f}, -{0.425325f, -0.688191f, -0.587785f}, -{0.716567f, -0.681718f, -0.147621f}, -{0.688191f, -0.587785f, -0.425325f}, -{0.587785f, -0.425325f, -0.688191f}, -{0.000000f, -0.955423f, -0.295242f}, -{0.000000f, -1.000000f, 0.000000f}, -{0.262866f, -0.951056f, -0.162460f}, -{0.000000f, -0.850651f, 0.525731f}, -{0.000000f, -0.955423f, 0.295242f}, -{0.238856f, -0.864188f, 0.442863f}, -{0.262866f, -0.951056f, 0.162460f}, -{0.500000f, -0.809017f, 0.309017f}, -{0.716567f, -0.681718f, 0.147621f}, -{0.525731f, -0.850651f, 0.000000f}, -{-0.238856f, -0.864188f, -0.442863f}, -{-0.500000f, -0.809017f, -0.309017f}, -{-0.262866f, -0.951056f, -0.162460f}, -{-0.850651f, -0.525731f, 0.000000f}, -{-0.716567f, -0.681718f, -0.147621f}, -{-0.716567f, -0.681718f, 0.147621f}, -{-0.525731f, -0.850651f, 0.000000f}, -{-0.500000f, -0.809017f, 0.309017f}, -{-0.238856f, -0.864188f, 0.442863f}, -{-0.262866f, -0.951056f, 0.162460f}, -{-0.864188f, -0.442863f, 0.238856f}, -{-0.809017f, -0.309017f, 0.500000f}, -{-0.688191f, -0.587785f, 0.425325f}, -{-0.681718f, -0.147621f, 0.716567f}, -{-0.442863f, -0.238856f, 0.864188f}, -{-0.587785f, -0.425325f, 0.688191f}, -{-0.309017f, -0.500000f, 0.809017f}, -{-0.147621f, -0.716567f, 0.681718f}, -{-0.425325f, -0.688191f, 0.587785f}, -{-0.162460f, -0.262866f, 0.951056f}, -{0.442863f, -0.238856f, 0.864188f}, -{0.162460f, -0.262866f, 0.951056f}, -{0.309017f, -0.500000f, 0.809017f}, -{0.147621f, -0.716567f, 0.681718f}, -{0.000000f, -0.525731f, 0.850651f}, -{0.425325f, -0.688191f, 0.587785f}, -{0.587785f, -0.425325f, 0.688191f}, -{0.688191f, -0.587785f, 0.425325f}, -{-0.955423f, 0.295242f, 0.000000f}, -{-0.951056f, 0.162460f, 0.262866f}, -{-1.000000f, 0.000000f, 0.000000f}, -{-0.850651f, 0.000000f, 0.525731f}, -{-0.955423f, -0.295242f, 0.000000f}, -{-0.951056f, -0.162460f, 0.262866f}, -{-0.864188f, 0.442863f, -0.238856f}, -{-0.951056f, 0.162460f, -0.262866f}, -{-0.809017f, 0.309017f, -0.500000f}, -{-0.864188f, -0.442863f, -0.238856f}, -{-0.951056f, -0.162460f, -0.262866f}, -{-0.809017f, -0.309017f, -0.500000f}, -{-0.681718f, 0.147621f, -0.716567f}, -{-0.681718f, -0.147621f, -0.716567f}, -{-0.850651f, 0.000000f, -0.525731f}, -{-0.688191f, 0.587785f, -0.425325f}, -{-0.587785f, 0.425325f, -0.688191f}, -{-0.425325f, 0.688191f, -0.587785f}, -{-0.425325f, -0.688191f, -0.587785f}, -{-0.587785f, -0.425325f, -0.688191f}, -{-0.688191f, -0.587785f, -0.425325f}, -}; - md2_t md2_models[NUMSPRITES]; md2_t md2_playermodels[MAXSKINS]; @@ -248,36 +83,9 @@ md2_t md2_playermodels[MAXSKINS]; /* * free model */ -static void md2_freeModel (md2_model_t *model) +static void md2_freeModel (model_t *model) { - if (model) - { - if (model->skins) - free(model->skins); - - if (model->texCoords) - free(model->texCoords); - - if (model->triangles) - free(model->triangles); - - if (model->frames) - { - size_t i; - - for (i = 0; i < model->header.numFrames; i++) - { - if (model->frames[i].vertices) - free(model->frames[i].vertices); - } - free(model->frames); - } - - if (model->glCommandBuffer) - free(model->glCommandBuffer); - - free(model); - } + UnloadModel(model); } @@ -285,157 +93,13 @@ static void md2_freeModel (md2_model_t *model) // load model // // Hurdler: the current path is the Legacy.exe path -static md2_model_t *md2_readModel(const char *filename) +static model_t *md2_readModel(const char *filename) { - FILE *file; - md2_model_t *model; - UINT8 buffer[MD2_MAX_FRAMESIZE]; - size_t i; - - model = calloc(1, sizeof (*model)); - if (model == NULL) - return 0; - //Filename checking fixed ~Monster Iestyn and Golden - file = fopen(va("%s"PATHSEP"%s", srb2home, filename), "rb"); - if (!file) - { - free(model); - return 0; - } - - // initialize model and read header - - if (fread(&model->header, sizeof (model->header), 1, file) != 1 - || model->header.magic != MD2_IDENT - || model->header.version != MD2_VERSION) - { - fclose(file); - free(model); - return 0; - } - - model->header.numSkins = 1; - -#define MD2LIMITCHECK(field, max, msgname) \ - if (field > max) \ - { \ - CONS_Alert(CONS_ERROR, "md2_readModel: %s has too many " msgname " (# found: %d, maximum: %d)\n", filename, field, max); \ - md2_freeModel (model); \ - fclose(file); \ - return 0; \ - } - - // Uncomment if these are actually needed -// MD2LIMITCHECK(model->header.numSkins, MD2_MAX_SKINS, "skins") -// MD2LIMITCHECK(model->header.numTexCoords, MD2_MAX_TEXCOORDS, "texture coordinates") - MD2LIMITCHECK(model->header.numTriangles, MD2_MAX_TRIANGLES, "triangles") - MD2LIMITCHECK(model->header.numFrames, MD2_MAX_FRAMES, "frames") - MD2LIMITCHECK(model->header.numVertices, MD2_MAX_VERTICES, "vertices") - -#undef MD2LIMITCHECK - - // read skins - fseek(file, model->header.offsetSkins, SEEK_SET); - if (model->header.numSkins > 0) - { - model->skins = calloc(sizeof (md2_skin_t), model->header.numSkins); - if (!model->skins || model->header.numSkins != - fread(model->skins, sizeof (md2_skin_t), model->header.numSkins, file)) - { - md2_freeModel (model); - fclose(file); - return 0; - } - } - - // read texture coordinates - fseek(file, model->header.offsetTexCoords, SEEK_SET); - if (model->header.numTexCoords > 0) - { - model->texCoords = calloc(sizeof (md2_textureCoordinate_t), model->header.numTexCoords); - if (!model->texCoords || model->header.numTexCoords != - fread(model->texCoords, sizeof (md2_textureCoordinate_t), model->header.numTexCoords, file)) - { - md2_freeModel (model); - fclose(file); - return 0; - } - } - - // read triangles - fseek(file, model->header.offsetTriangles, SEEK_SET); - if (model->header.numTriangles > 0) - { - model->triangles = calloc(sizeof (md2_triangle_t), model->header.numTriangles); - if (!model->triangles || model->header.numTriangles != - fread(model->triangles, sizeof (md2_triangle_t), model->header.numTriangles, file)) - { - md2_freeModel (model); - fclose(file); - return 0; - } - } - - // read alias frames - fseek(file, model->header.offsetFrames, SEEK_SET); - if (model->header.numFrames > 0) - { - model->frames = calloc(sizeof (md2_frame_t), model->header.numFrames); - if (!model->frames) - { - md2_freeModel (model); - fclose(file); - return 0; - } - - for (i = 0; i < model->header.numFrames; i++) - { - md2_alias_frame_t *frame = (md2_alias_frame_t *)(void *)buffer; - size_t j; - - model->frames[i].vertices = calloc(sizeof (md2_triangleVertex_t), model->header.numVertices); - if (!model->frames[i].vertices || model->header.frameSize != - fread(frame, 1, model->header.frameSize, file)) - { - md2_freeModel (model); - fclose(file); - return 0; - } - - strcpy(model->frames[i].name, frame->name); - for (j = 0; j < model->header.numVertices; j++) - { - model->frames[i].vertices[j].vertex[0] = (float) ((INT32) frame->alias_vertices[j].vertex[0]) * frame->scale[0] + frame->translate[0]; - model->frames[i].vertices[j].vertex[2] = -1* ((float) ((INT32) frame->alias_vertices[j].vertex[1]) * frame->scale[1] + frame->translate[1]); - model->frames[i].vertices[j].vertex[1] = (float) ((INT32) frame->alias_vertices[j].vertex[2]) * frame->scale[2] + frame->translate[2]; - model->frames[i].vertices[j].normal[0] = avertexnormals[frame->alias_vertices[j].lightNormalIndex][0]; - model->frames[i].vertices[j].normal[1] = avertexnormals[frame->alias_vertices[j].lightNormalIndex][1]; - model->frames[i].vertices[j].normal[2] = avertexnormals[frame->alias_vertices[j].lightNormalIndex][2]; - } - } - } - - // read gl commands - fseek(file, model->header.offsetGlCommands, SEEK_SET); - if (model->header.numGlCommands) - { - model->glCommandBuffer = calloc(sizeof (INT32), model->header.numGlCommands); - if (!model->glCommandBuffer || model->header.numGlCommands != - fread(model->glCommandBuffer, sizeof (INT32), model->header.numGlCommands, file)) - { - md2_freeModel (model); - fclose(file); - return 0; - } - } - - fclose(file); - - return model; + return LoadModel(va("%s"PATHSEP"%s", srb2home, filename), PU_STATIC); } -static inline void md2_printModelInfo (md2_model_t *model) +static inline void md2_printModelInfo (model_t *model) { #if 0 INT32 i; @@ -936,7 +600,7 @@ void HWR_AddSpriteMD2(size_t spritenum) // For MD2s that were added after startu return; } - // Check for any MD2s that match the names of player skins! + // Check for any MD2s that match the names of sprite names! while (fscanf(f, "%19s %31s %f %f", name, filename, &scale, &offset) == 4) { if (stricmp(name, sprnames[spritenum]) == 0) @@ -1216,10 +880,9 @@ void HWR_DrawMD2(gr_vissprite_t *spr) // Look at HWR_ProjectSprite for more { GLPatch_t *gpatch; - INT32 *buff; INT32 durs = spr->mobj->state->tics; INT32 tics = spr->mobj->tics; - md2_frame_t *curr, *next = NULL; + mdlframe_t *curr, *next = NULL; const UINT8 flip = (UINT8)((spr->mobj->eflags & MFE_VERTICALFLIP) == MFE_VERTICALFLIP); spritedef_t *sprdef; spriteframe_t *sprframe; @@ -1332,9 +995,8 @@ void HWR_DrawMD2(gr_vissprite_t *spr) } //FIXME: this is not yet correct - frame = (spr->mobj->frame & FF_FRAMEMASK) % md2->model->header.numFrames; - buff = md2->model->glCommandBuffer; - curr = &md2->model->frames[frame]; + frame = (spr->mobj->frame & FF_FRAMEMASK) % md2->model->meshes[0].numFrames; + curr = &md2->model->meshes[0].frames[frame]; #if 0 if (cv_grmd2.value == 1 && tics <= durs) { @@ -1401,7 +1063,6 @@ void HWR_DrawMD2(gr_vissprite_t *spr) p.anglex = FIXED_TO_FLOAT(tempangle); } - color[0] = Surf.FlatColor.s.red; color[1] = Surf.FlatColor.s.green; color[2] = Surf.FlatColor.s.blue; @@ -1413,7 +1074,7 @@ void HWR_DrawMD2(gr_vissprite_t *spr) p.flip = atransform.flip; p.mirror = atransform.mirror; - HWD.pfnDrawMD2i(buff, curr, durs, tics, next, &p, finalscale, flip, color); + HWD.pfnDrawModel(md2->model, curr, durs, tics, next, &p, finalscale, flip, color); } } diff --git a/src/hardware/hw_md2.h b/src/hardware/hw_md2.h index ca43c7b4f..57d8026b9 100644 --- a/src/hardware/hw_md2.h +++ b/src/hardware/hw_md2.h @@ -22,97 +22,7 @@ #define _HW_MD2_H_ #include "hw_glob.h" - -// magic number "IDP2" or 844121161 -#define MD2_IDENT (INT32)(('2' << 24) + ('P' << 16) + ('D' << 8) + 'I') -// model version -#define MD2_VERSION 8 - -#define MD2_MAX_TRIANGLES 16384 -#define MD2_MAX_VERTICES 4096 -#define MD2_MAX_TEXCOORDS 4096 -#define MD2_MAX_FRAMES 512 -#define MD2_MAX_SKINS 32 -#define MD2_MAX_FRAMESIZE (MD2_MAX_VERTICES * 4 + 128) - -#if defined(_MSC_VER) -#pragma pack(1) -#endif -typedef struct -{ - UINT32 magic; - UINT32 version; - UINT32 skinWidth; - UINT32 skinHeight; - UINT32 frameSize; - UINT32 numSkins; - UINT32 numVertices; - UINT32 numTexCoords; - UINT32 numTriangles; - UINT32 numGlCommands; - UINT32 numFrames; - UINT32 offsetSkins; - UINT32 offsetTexCoords; - UINT32 offsetTriangles; - UINT32 offsetFrames; - UINT32 offsetGlCommands; - UINT32 offsetEnd; -} ATTRPACK md2_header_t; //NOTE: each of md2_header's members are 4 unsigned bytes - -typedef struct -{ - UINT8 vertex[3]; - UINT8 lightNormalIndex; -} ATTRPACK md2_alias_triangleVertex_t; - -typedef struct -{ - float vertex[3]; - float normal[3]; -} ATTRPACK md2_triangleVertex_t; - -typedef struct -{ - INT16 vertexIndices[3]; - INT16 textureIndices[3]; -} ATTRPACK md2_triangle_t; - -typedef struct -{ - INT16 s, t; -} ATTRPACK md2_textureCoordinate_t; - -typedef struct -{ - float scale[3]; - float translate[3]; - char name[16]; - md2_alias_triangleVertex_t alias_vertices[1]; -} ATTRPACK md2_alias_frame_t; - -typedef struct -{ - char name[16]; - md2_triangleVertex_t *vertices; -} ATTRPACK md2_frame_t; - -typedef char md2_skin_t[64]; - -typedef struct -{ - float s, t; - INT32 vertexIndex; -} ATTRPACK md2_glCommandVertex_t; - -typedef struct -{ - md2_header_t header; - md2_skin_t *skins; - md2_textureCoordinate_t *texCoords; - md2_triangle_t *triangles; - md2_frame_t *frames; - INT32 *glCommandBuffer; -} ATTRPACK md2_model_t; +#include "hw_model.h" #if defined(_MSC_VER) #pragma pack() @@ -123,7 +33,7 @@ typedef struct char filename[32]; float scale; float offset; - md2_model_t *model; + model_t *model; void *grpatch; void *blendgrpatch; boolean notfound; diff --git a/src/hardware/hw_md2load.c b/src/hardware/hw_md2load.c new file mode 100644 index 000000000..3b083fee4 --- /dev/null +++ b/src/hardware/hw_md2load.c @@ -0,0 +1,520 @@ +/* + From the 'Wizard2' engine by Spaddlewit Inc. ( http://www.spaddlewit.com ) + An experimental work-in-progress. + + Donated to Sonic Team Junior and adapted to work with + Sonic Robo Blast 2. The license of this code matches whatever + the licensing is for Sonic Robo Blast 2. +*/ + +#include +#include +#include +#include "../doomdef.h" +#include "hw_md2load.h" +#include "hw_model.h" +#include "../z_zone.h" + +#define NUMVERTEXNORMALS 162 + +// Quake 2 normals are indexed. Use avertexnormals[normalindex][x/y/z] and +// you'll have your normals. +float avertexnormals[NUMVERTEXNORMALS][3] = { +{-0.525731f, 0.000000f, 0.850651f}, +{-0.442863f, 0.238856f, 0.864188f}, +{-0.295242f, 0.000000f, 0.955423f}, +{-0.309017f, 0.500000f, 0.809017f}, +{-0.162460f, 0.262866f, 0.951056f}, +{0.000000f, 0.000000f, 1.000000f}, +{0.000000f, 0.850651f, 0.525731f}, +{-0.147621f, 0.716567f, 0.681718f}, +{0.147621f, 0.716567f, 0.681718f}, +{0.000000f, 0.525731f, 0.850651f}, +{0.309017f, 0.500000f, 0.809017f}, +{0.525731f, 0.000000f, 0.850651f}, +{0.295242f, 0.000000f, 0.955423f}, +{0.442863f, 0.238856f, 0.864188f}, +{0.162460f, 0.262866f, 0.951056f}, +{-0.681718f, 0.147621f, 0.716567f}, +{-0.809017f, 0.309017f, 0.500000f}, +{-0.587785f, 0.425325f, 0.688191f}, +{-0.850651f, 0.525731f, 0.000000f}, +{-0.864188f, 0.442863f, 0.238856f}, +{-0.716567f, 0.681718f, 0.147621f}, +{-0.688191f, 0.587785f, 0.425325f}, +{-0.500000f, 0.809017f, 0.309017f}, +{-0.238856f, 0.864188f, 0.442863f}, +{-0.425325f, 0.688191f, 0.587785f}, +{-0.716567f, 0.681718f, -0.147621f}, +{-0.500000f, 0.809017f, -0.309017f}, +{-0.525731f, 0.850651f, 0.000000f}, +{0.000000f, 0.850651f, -0.525731f}, +{-0.238856f, 0.864188f, -0.442863f}, +{0.000000f, 0.955423f, -0.295242f}, +{-0.262866f, 0.951056f, -0.162460f}, +{0.000000f, 1.000000f, 0.000000f}, +{0.000000f, 0.955423f, 0.295242f}, +{-0.262866f, 0.951056f, 0.162460f}, +{0.238856f, 0.864188f, 0.442863f}, +{0.262866f, 0.951056f, 0.162460f}, +{0.500000f, 0.809017f, 0.309017f}, +{0.238856f, 0.864188f, -0.442863f}, +{0.262866f, 0.951056f, -0.162460f}, +{0.500000f, 0.809017f, -0.309017f}, +{0.850651f, 0.525731f, 0.000000f}, +{0.716567f, 0.681718f, 0.147621f}, +{0.716567f, 0.681718f, -0.147621f}, +{0.525731f, 0.850651f, 0.000000f}, +{0.425325f, 0.688191f, 0.587785f}, +{0.864188f, 0.442863f, 0.238856f}, +{0.688191f, 0.587785f, 0.425325f}, +{0.809017f, 0.309017f, 0.500000f}, +{0.681718f, 0.147621f, 0.716567f}, +{0.587785f, 0.425325f, 0.688191f}, +{0.955423f, 0.295242f, 0.000000f}, +{1.000000f, 0.000000f, 0.000000f}, +{0.951056f, 0.162460f, 0.262866f}, +{0.850651f, -0.525731f, 0.000000f}, +{0.955423f, -0.295242f, 0.000000f}, +{0.864188f, -0.442863f, 0.238856f}, +{0.951056f, -0.162460f, 0.262866f}, +{0.809017f, -0.309017f, 0.500000f}, +{0.681718f, -0.147621f, 0.716567f}, +{0.850651f, 0.000000f, 0.525731f}, +{0.864188f, 0.442863f, -0.238856f}, +{0.809017f, 0.309017f, -0.500000f}, +{0.951056f, 0.162460f, -0.262866f}, +{0.525731f, 0.000000f, -0.850651f}, +{0.681718f, 0.147621f, -0.716567f}, +{0.681718f, -0.147621f, -0.716567f}, +{0.850651f, 0.000000f, -0.525731f}, +{0.809017f, -0.309017f, -0.500000f}, +{0.864188f, -0.442863f, -0.238856f}, +{0.951056f, -0.162460f, -0.262866f}, +{0.147621f, 0.716567f, -0.681718f}, +{0.309017f, 0.500000f, -0.809017f}, +{0.425325f, 0.688191f, -0.587785f}, +{0.442863f, 0.238856f, -0.864188f}, +{0.587785f, 0.425325f, -0.688191f}, +{0.688191f, 0.587785f, -0.425325f}, +{-0.147621f, 0.716567f, -0.681718f}, +{-0.309017f, 0.500000f, -0.809017f}, +{0.000000f, 0.525731f, -0.850651f}, +{-0.525731f, 0.000000f, -0.850651f}, +{-0.442863f, 0.238856f, -0.864188f}, +{-0.295242f, 0.000000f, -0.955423f}, +{-0.162460f, 0.262866f, -0.951056f}, +{0.000000f, 0.000000f, -1.000000f}, +{0.295242f, 0.000000f, -0.955423f}, +{0.162460f, 0.262866f, -0.951056f}, +{-0.442863f, -0.238856f, -0.864188f}, +{-0.309017f, -0.500000f, -0.809017f}, +{-0.162460f, -0.262866f, -0.951056f}, +{0.000000f, -0.850651f, -0.525731f}, +{-0.147621f, -0.716567f, -0.681718f}, +{0.147621f, -0.716567f, -0.681718f}, +{0.000000f, -0.525731f, -0.850651f}, +{0.309017f, -0.500000f, -0.809017f}, +{0.442863f, -0.238856f, -0.864188f}, +{0.162460f, -0.262866f, -0.951056f}, +{0.238856f, -0.864188f, -0.442863f}, +{0.500000f, -0.809017f, -0.309017f}, +{0.425325f, -0.688191f, -0.587785f}, +{0.716567f, -0.681718f, -0.147621f}, +{0.688191f, -0.587785f, -0.425325f}, +{0.587785f, -0.425325f, -0.688191f}, +{0.000000f, -0.955423f, -0.295242f}, +{0.000000f, -1.000000f, 0.000000f}, +{0.262866f, -0.951056f, -0.162460f}, +{0.000000f, -0.850651f, 0.525731f}, +{0.000000f, -0.955423f, 0.295242f}, +{0.238856f, -0.864188f, 0.442863f}, +{0.262866f, -0.951056f, 0.162460f}, +{0.500000f, -0.809017f, 0.309017f}, +{0.716567f, -0.681718f, 0.147621f}, +{0.525731f, -0.850651f, 0.000000f}, +{-0.238856f, -0.864188f, -0.442863f}, +{-0.500000f, -0.809017f, -0.309017f}, +{-0.262866f, -0.951056f, -0.162460f}, +{-0.850651f, -0.525731f, 0.000000f}, +{-0.716567f, -0.681718f, -0.147621f}, +{-0.716567f, -0.681718f, 0.147621f}, +{-0.525731f, -0.850651f, 0.000000f}, +{-0.500000f, -0.809017f, 0.309017f}, +{-0.238856f, -0.864188f, 0.442863f}, +{-0.262866f, -0.951056f, 0.162460f}, +{-0.864188f, -0.442863f, 0.238856f}, +{-0.809017f, -0.309017f, 0.500000f}, +{-0.688191f, -0.587785f, 0.425325f}, +{-0.681718f, -0.147621f, 0.716567f}, +{-0.442863f, -0.238856f, 0.864188f}, +{-0.587785f, -0.425325f, 0.688191f}, +{-0.309017f, -0.500000f, 0.809017f}, +{-0.147621f, -0.716567f, 0.681718f}, +{-0.425325f, -0.688191f, 0.587785f}, +{-0.162460f, -0.262866f, 0.951056f}, +{0.442863f, -0.238856f, 0.864188f}, +{0.162460f, -0.262866f, 0.951056f}, +{0.309017f, -0.500000f, 0.809017f}, +{0.147621f, -0.716567f, 0.681718f}, +{0.000000f, -0.525731f, 0.850651f}, +{0.425325f, -0.688191f, 0.587785f}, +{0.587785f, -0.425325f, 0.688191f}, +{0.688191f, -0.587785f, 0.425325f}, +{-0.955423f, 0.295242f, 0.000000f}, +{-0.951056f, 0.162460f, 0.262866f}, +{-1.000000f, 0.000000f, 0.000000f}, +{-0.850651f, 0.000000f, 0.525731f}, +{-0.955423f, -0.295242f, 0.000000f}, +{-0.951056f, -0.162460f, 0.262866f}, +{-0.864188f, 0.442863f, -0.238856f}, +{-0.951056f, 0.162460f, -0.262866f}, +{-0.809017f, 0.309017f, -0.500000f}, +{-0.864188f, -0.442863f, -0.238856f}, +{-0.951056f, -0.162460f, -0.262866f}, +{-0.809017f, -0.309017f, -0.500000f}, +{-0.681718f, 0.147621f, -0.716567f}, +{-0.681718f, -0.147621f, -0.716567f}, +{-0.850651f, 0.000000f, -0.525731f}, +{-0.688191f, 0.587785f, -0.425325f}, +{-0.587785f, 0.425325f, -0.688191f}, +{-0.425325f, 0.688191f, -0.587785f}, +{-0.425325f, -0.688191f, -0.587785f}, +{-0.587785f, -0.425325f, -0.688191f}, +{-0.688191f, -0.587785f, -0.425325f}, +}; + +typedef struct +{ + int ident; // A "magic number" that's used to identify the .md2 file + int version; // The version of the file, always 8 + int skinwidth; // Width of the skin(s) in pixels + int skinheight; // Height of the skin(s) in pixels + int framesize; // Size of each frame in bytes + int numSkins; // Number of skins with the model + int numXYZ; // Number of vertices in each frame + int numST; // Number of texture coordinates in each frame. + int numTris; // Number of triangles in each frame + int numGLcmds; // Number of dwords (4 bytes) in the gl command list. + int numFrames; // Number of frames + int offsetSkins; // Offset, in bytes from the start of the file, to the list of skin names. + int offsetST; // Offset, in bytes from the start of the file, to the list of texture coordinates + int offsetTris; // Offset, in bytes from the start of the file, to the list of triangles + int offsetFrames; // Offset, in bytes from the start of the file, to the list of frames + int offsetGLcmds; // Offset, in bytes from the start of the file, to the list of gl commands + int offsetEnd; // Offset, in bytes from the start of the file, to the end of the file (filesize) +} md2header_t; + +typedef struct +{ + unsigned short meshIndex[3]; // indices into the array of vertices in each frames + unsigned short stIndex[3]; // indices into the array of texture coordinates +} md2triangle_t; + +typedef struct +{ + short s; + short t; +} md2texcoord_t; + +typedef struct +{ + unsigned char v[3]; // Scaled vertices. You'll need to multiply them with scale[x] to make them normal. + unsigned char lightNormalIndex; // Index to the array of normals +} md2vertex_t; + +typedef struct +{ + float scale[3]; // Used by the v member in the md2framePoint structure + float translate[3]; // Used by the v member in the md2framePoint structure + char name[16]; // Name of the frame +} md2frame_t; + +// Load the model +model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) +{ + useFloat = true; // Right now we always useFloat = true, because the GL subsystem needs some work for the other option to work. + + model_t *retModel = NULL; + md2header_t *header; + + FILE *f = fopen(fileName, "rb"); + + if (!f) + return NULL; + + retModel = (model_t*)Z_Calloc(sizeof(model_t), ztag, 0); + + size_t fileLen; + int i, j; + + size_t namelen; + char *texturefilename; + const char *texPos = strchr(fileName, '/'); + + if (texPos) + { + texPos++; + namelen = strlen(texPos) + 1; + texturefilename = (char*)Z_Malloc(namelen, PU_CACHE, 0); + strcpy(texturefilename, texPos); + } + else + { + namelen = strlen(fileName) + 1; + texturefilename = (char*)Z_Malloc(namelen, PU_CACHE, 0); + strcpy(texturefilename, fileName); + } + + texturefilename[namelen-2] = 'z'; + texturefilename[namelen-3] = 'u'; + texturefilename[namelen-4] = 'b'; + + // find length of file + fseek(f, 0, SEEK_END); + fileLen = ftell(f); + fseek(f, 0, SEEK_SET); + + // read in file + char *buffer = malloc(fileLen); + fread(buffer, fileLen, 1, f); + fclose(f); + + // get pointer to file header + header = (md2header_t*)buffer; + + retModel->numMeshes = 1; // MD2 only has one mesh + retModel->meshes = (mesh_t*)Z_Calloc(sizeof(mesh_t) * retModel->numMeshes, ztag, 0); + retModel->meshes[0].numFrames = header->numFrames; + const float WUNITS = 1.0f; + float dataScale = WUNITS; + + // Tris and ST are simple structures that can be straight-copied + md2triangle_t *tris = (md2triangle_t*)&buffer[header->offsetTris]; + md2texcoord_t *texcoords = (md2texcoord_t*)&buffer[header->offsetST]; + md2frame_t *frames = (md2frame_t*)&buffer[header->offsetFrames]; + + // Read in textures + retModel->numMaterials = header->numSkins; + + if (retModel->numMaterials <= 0) // Always at least one skin, duh + retModel->numMaterials = 1; + + retModel->materials = (material_t*)Z_Calloc(sizeof(material_t)*retModel->numMaterials, ztag, 0); + + int t; + for (t = 0; t < retModel->numMaterials; t++) + { + retModel->materials[t].ambient[0] = 0.8f; + retModel->materials[t].ambient[1] = 0.8f; + retModel->materials[t].ambient[2] = 0.8f; + retModel->materials[t].ambient[3] = 1.0f; + retModel->materials[t].diffuse[0] = 0.8f; + retModel->materials[t].diffuse[1] = 0.8f; + retModel->materials[t].diffuse[2] = 0.8f; + retModel->materials[t].diffuse[3] = 1.0f; + retModel->materials[t].emissive[0] = 0.0f; + retModel->materials[t].emissive[1] = 0.0f; + retModel->materials[t].emissive[2] = 0.0f; + retModel->materials[t].emissive[3] = 1.0f; + retModel->materials[t].specular[0] = 0.0f; + retModel->materials[t].specular[1] = 0.0f; + retModel->materials[t].specular[2] = 0.0f; + retModel->materials[t].specular[3] = 1.0f; + retModel->materials[t].shininess = 0.0f; + retModel->materials[t].spheremap = false; + +/* retModel->materials[t].texture = Texture::ReadTexture((char*)texturefilename, ZT_TEXTURE); + + if (!systemSucks) + { + // Check for a normal map...?? + char openfilename[1024]; + char normalMapName[1024]; + strcpy(normalMapName, texturefilename); + size_t len = strlen(normalMapName); + char *ptr = &normalMapName[len]; + ptr--; // z + ptr--; // u + ptr--; // b + ptr--; // . + *ptr++ = '_'; + *ptr++ = 'n'; + *ptr++ = '.'; + *ptr++ = 'b'; + *ptr++ = 'u'; + *ptr++ = 'z'; + *ptr++ = '\0'; + + sprintf(openfilename, "%s/%s", "textures", normalMapName); + // Convert backslashes to forward slashes + for (int k = 0; k < 1024; k++) + { + if (openfilename[k] == '\0') + break; + + if (openfilename[k] == '\\') + openfilename[k] = '/'; + } + + Resource::resource_t *res = Resource::Open(openfilename); + if (res) + { + Resource::Close(res); + retModel->materials[t].lightmap = Texture::ReadTexture(normalMapName, ZT_TEXTURE); + } + }*/ + } + + retModel->meshes[0].numTriangles = header->numTris; + + if (!useFloat) // Decompress to MD3 'tinyframe' space + { + dataScale = 0.015624f; // 1 / 64.0f + retModel->meshes[0].tinyframes = (tinyframe_t*)Z_Calloc(sizeof(tinyframe_t)*header->numFrames, ztag, 0); + retModel->meshes[0].numVertices = header->numXYZ; + retModel->meshes[0].uvs = (float*)Z_Malloc (sizeof(float)*2*retModel->meshes[0].numVertices, ztag, 0); + + byte *ptr = (byte*)frames; + for (i = 0; i < header->numFrames; i++, ptr += header->framesize) + { + md2frame_t *framePtr = (md2frame_t*)ptr; + retModel->meshes[0].tinyframes[i].vertices = (short*)Z_Malloc(sizeof(short)*3*header->numXYZ, ztag, 0); + retModel->meshes[0].tinyframes[i].normals = (char*)Z_Malloc(sizeof(char)*3*header->numXYZ, ztag, 0); + +// if (retModel->materials[0].lightmap) +// retModel->meshes[0].tinyframes[i].tangents = (char*)malloc(sizeof(char));//(char*)Z_Malloc(sizeof(char)*3*header->numVerts, ztag); + retModel->meshes[0].indices = (unsigned short*)Z_Malloc(sizeof(unsigned short) * 3 * header->numTris, ztag, 0); + + short *vertptr = retModel->meshes[0].tinyframes[i].vertices; + char *normptr = retModel->meshes[0].tinyframes[i].normals; + +// char *tanptr = retModel->meshes[0].tinyframes[i].tangents; + retModel->meshes[0].tinyframes[i].material = &retModel->materials[0]; + + framePtr++; // Advance to vertex list + md2vertex_t *vertex = (md2vertex_t*)framePtr; + framePtr--; + for (j = 0; j < header->numXYZ; j++, vertex++) + { + *vertptr = (short)(((vertex->v[1] * framePtr->scale[1]) + framePtr->translate[1]) / dataScale); + vertptr++; + *vertptr = (short)(((vertex->v[2] * framePtr->scale[2]) + framePtr->translate[2]) / dataScale); + vertptr++; + *vertptr = (short)(((vertex->v[0] * framePtr->scale[0]) + framePtr->translate[0]) / dataScale); + vertptr++; + + // Normal + *normptr++ = (byte)(avertexnormals[vertex->lightNormalIndex][1] * 127); + *normptr++ = (byte)(avertexnormals[vertex->lightNormalIndex][2] * 127); + *normptr++ = (byte)(avertexnormals[vertex->lightNormalIndex][0] * 127); + } + } + + // This doesn't need to be done every frame! + md2triangle_t *trisPtr = tris; + unsigned short *indexptr = retModel->meshes[0].indices; + float *uvptr = (float*)retModel->meshes[0].uvs; + for (j = 0; j < header->numTris; j++, trisPtr++) + { + *indexptr = trisPtr->meshIndex[0]; + indexptr++; + *indexptr = trisPtr->meshIndex[2]; + indexptr++; + *indexptr = trisPtr->meshIndex[1]; + indexptr++; + + uvptr[trisPtr->meshIndex[1] * 2] = texcoords[trisPtr->stIndex[1]].s / (float)header->skinwidth; + uvptr[trisPtr->meshIndex[1] * 2 + 1] = (texcoords[trisPtr->stIndex[1]].t / (float)header->skinheight); + uvptr[trisPtr->meshIndex[2] * 2] = texcoords[trisPtr->stIndex[2]].s / (float)header->skinwidth; + uvptr[trisPtr->meshIndex[2] * 2 + 1] = (texcoords[trisPtr->stIndex[2]].t / (float)header->skinheight); + uvptr[trisPtr->meshIndex[0] * 2] = texcoords[trisPtr->stIndex[0]].s / (float)header->skinwidth; + uvptr[trisPtr->meshIndex[0] * 2 + 1] = (texcoords[trisPtr->stIndex[0]].t / (float)header->skinheight); + } + } + else // Full float loading method + { + retModel->meshes[0].numVertices = header->numTris*3; + retModel->meshes[0].frames = (mdlframe_t*)Z_Calloc(sizeof(mdlframe_t)*header->numFrames, ztag, 0); + retModel->meshes[0].uvs = (float*)Z_Malloc(sizeof(float)*2*retModel->meshes[0].numVertices, ztag, 0); + + md2triangle_t *trisPtr = tris; + float *uvptr = retModel->meshes[0].uvs; + for (i = 0; i < retModel->meshes[0].numTriangles; i++, trisPtr++) + { + *uvptr++ = texcoords[trisPtr->stIndex[0]].s / (float)header->skinwidth; + *uvptr++ = (texcoords[trisPtr->stIndex[0]].t / (float)header->skinheight); + *uvptr++ = texcoords[trisPtr->stIndex[1]].s / (float)header->skinwidth; + *uvptr++ = (texcoords[trisPtr->stIndex[1]].t / (float)header->skinheight); + *uvptr++ = texcoords[trisPtr->stIndex[2]].s / (float)header->skinwidth; + *uvptr++ = (texcoords[trisPtr->stIndex[2]].t / (float)header->skinheight); + } + + byte *ptr = (byte*)frames; + for (i = 0; i < header->numFrames; i++, ptr += header->framesize) + { + md2frame_t *framePtr = (md2frame_t*)ptr; + retModel->meshes[0].frames[i].normals = (float*)Z_Malloc(sizeof(float)*3*header->numTris*3, ztag, 0); + retModel->meshes[0].frames[i].vertices = (float*)Z_Malloc(sizeof(float)*3*header->numTris*3, ztag, 0); +// if (retModel->materials[0].lightmap) +// retModel->meshes[0].frames[i].tangents = (float*)malloc(sizeof(float));//(float*)Z_Malloc(sizeof(float)*3*header->numTris*3, ztag); + float *vertptr, *normptr; + normptr = (float*)retModel->meshes[0].frames[i].normals; + vertptr = (float*)retModel->meshes[0].frames[i].vertices; + trisPtr = tris; + + retModel->meshes[0].frames[i].material = &retModel->materials[0]; + + framePtr++; // Advance to vertex list + md2vertex_t *vertex = (md2vertex_t*)framePtr; + framePtr--; + for (j = 0; j < header->numTris; j++, trisPtr++) + { + *vertptr = ((vertex[trisPtr->meshIndex[0]].v[0] * framePtr->scale[0]) + framePtr->translate[0]) * WUNITS; + vertptr++; + *vertptr = ((vertex[trisPtr->meshIndex[0]].v[2] * framePtr->scale[2]) + framePtr->translate[2]) * WUNITS; + vertptr++; + *vertptr = -1.0f * ((vertex[trisPtr->meshIndex[0]].v[1] * framePtr->scale[1]) + framePtr->translate[1]) * WUNITS; + vertptr++; + + *vertptr = ((vertex[trisPtr->meshIndex[1]].v[0] * framePtr->scale[0]) + framePtr->translate[0]) * WUNITS; + vertptr++; + *vertptr = ((vertex[trisPtr->meshIndex[1]].v[2] * framePtr->scale[2]) + framePtr->translate[2]) * WUNITS; + vertptr++; + *vertptr = -1.0f * ((vertex[trisPtr->meshIndex[1]].v[1] * framePtr->scale[1]) + framePtr->translate[1]) * WUNITS; + vertptr++; + + *vertptr = ((vertex[trisPtr->meshIndex[2]].v[0] * framePtr->scale[0]) + framePtr->translate[0]) * WUNITS; + vertptr++; + *vertptr = ((vertex[trisPtr->meshIndex[2]].v[2] * framePtr->scale[2]) + framePtr->translate[2]) * WUNITS; + vertptr++; + *vertptr = -1.0f * ((vertex[trisPtr->meshIndex[2]].v[1] * framePtr->scale[1]) + framePtr->translate[1]) * WUNITS; + vertptr++; + + *normptr++ = avertexnormals[vertex[trisPtr->meshIndex[0]].lightNormalIndex][0]; + *normptr++ = avertexnormals[vertex[trisPtr->meshIndex[0]].lightNormalIndex][1]; + *normptr++ = avertexnormals[vertex[trisPtr->meshIndex[0]].lightNormalIndex][2]; + + *normptr++ = avertexnormals[vertex[trisPtr->meshIndex[1]].lightNormalIndex][0]; + *normptr++ = avertexnormals[vertex[trisPtr->meshIndex[1]].lightNormalIndex][1]; + *normptr++ = avertexnormals[vertex[trisPtr->meshIndex[1]].lightNormalIndex][2]; + + *normptr++ = avertexnormals[vertex[trisPtr->meshIndex[2]].lightNormalIndex][0]; + *normptr++ = avertexnormals[vertex[trisPtr->meshIndex[2]].lightNormalIndex][1]; + *normptr++ = avertexnormals[vertex[trisPtr->meshIndex[2]].lightNormalIndex][2]; + } + /* + // Rotate MD2 by 90 degrees in code BLAAHH + vector_t *normVecptr = (vector_t*)retModel->meshes[0].frames[i].normals; + vector_t *vertVecptr = (vector_t*)retModel->meshes[0].frames[i].vertices; + for (j = 0; j < header->numTris * 3; j++, normVecptr++, vertVecptr++) + { + VectorRotate(normVecptr, &vectorYaxis, -90.0f); + VectorRotate(vertVecptr, &vectorYaxis, -90.0f); + }*/ + } + } + + free(buffer); + return retModel; +} diff --git a/src/hardware/hw_md2load.h b/src/hardware/hw_md2load.h new file mode 100644 index 000000000..1662d6471 --- /dev/null +++ b/src/hardware/hw_md2load.h @@ -0,0 +1,19 @@ +/* + From the 'Wizard2' engine by Spaddlewit Inc. ( http://www.spaddlewit.com ) + An experimental work-in-progress. + + Donated to Sonic Team Junior and adapted to work with + Sonic Robo Blast 2. The license of this code matches whatever + the licensing is for Sonic Robo Blast 2. +*/ + +#ifndef _HW_MD2LOAD_H_ +#define _HW_MD2LOAD_H_ + +#include "hw_model.h" +#include "../doomtype.h" + +// Load the Model +model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat); + +#endif diff --git a/src/hardware/hw_md3load.c b/src/hardware/hw_md3load.c new file mode 100644 index 000000000..bac799cdb --- /dev/null +++ b/src/hardware/hw_md3load.c @@ -0,0 +1,489 @@ +/* + From the 'Wizard2' engine by Spaddlewit Inc. ( http://www.spaddlewit.com ) + An experimental work-in-progress. + + Donated to Sonic Team Junior and adapted to work with + Sonic Robo Blast 2. The license of this code matches whatever + the licensing is for Sonic Robo Blast 2. +*/ + +#include +#include +#include +#include "../doomdef.h" +#include "hw_md3load.h" +#include "hw_model.h" +#include "../z_zone.h" + +typedef struct +{ + int ident; // A "magic number" that's used to identify the .md3 file + int version; // The version of the file, always 15 + char name[64]; + int flags; + int numFrames; // Number of frames + int numTags; + int numSurfaces; + int numSkins; // Number of skins with the model + int offsetFrames; + int offsetTags; + int offsetSurfaces; + int offsetEnd; // Offset, in bytes from the start of the file, to the end of the file (filesize) +} md3modelHeader; + +typedef struct +{ + float minBounds[3]; // First corner of the bounding box + float maxBounds[3]; // Second corner of the bounding box + float localOrigin[3]; // Local origin, usually (0, 0, 0) + float radius; // Radius of bounding sphere + char name[16]; // Name of frame +} md3Frame; + +typedef struct +{ + char name[64]; // Name of tag + float origin[3]; // Coordinates of tag + float axis[9]; // Orientation of tag object +} md3Tag; + +typedef struct +{ + int ident; + char name[64]; // Name of this surface + int flags; + int numFrames; // # of keyframes + int numShaders; // # of shaders + int numVerts; // # of vertices + int numTriangles; // # of triangles + int offsetTriangles; // Relative offset from start of this struct to where the list of Triangles start + int offsetShaders; // Relative offset from start of this struct to where the list of Shaders start + int offsetST; // Relative offset from start of this struct to where the list of tex coords start + int offsetXYZNormal; // Relative offset from start of this struct to where the list of vertices start + int offsetEnd; // Relative offset from start of this struct to where this surface ends +} md3Surface; + +typedef struct +{ + char name[64]; // Name of this shader + int shaderIndex; // Shader index number +} md3Shader; + +typedef struct +{ + int index[3]; // List of offset values into the list of Vertex objects that constitute the corners of the Triangle object. +} md3Triangle; + +typedef struct +{ + float st[2]; +} md3TexCoord; + +typedef struct +{ + short x, y, z, n; +} md3Vertex; + +static float latlnglookup[256][256][3]; + +static void GetNormalFromLatLong(short latlng, float *out) +{ + float *lookup = latlnglookup[(unsigned char)(latlng >> 8)][(unsigned char)(latlng & 255)]; + + out[0] = *lookup++; + out[1] = *lookup++; + out[2] = *lookup++; +} + +static void NormalToLatLng(float *n, short *out) +{ + // Special cases + if (0.0f == n[0] && 0.0f == n[1]) + { + if (n[2] > 0.0f) + *out = 0; + else + *out = 128; + } + else + { + char x, y; + + x = (char)(57.2957795f * (atan2(n[1], n[0])) * (255.0f / 360.0f)); + y = (char)(57.2957795f * (acos(n[2])) * (255.0f / 360.0f)); + + *out = (x << 8) + y; + } +} + +static inline void LatLngToNormal(short n, float *out) +{ + const float PI = (3.1415926535897932384626433832795f); + float lat = (float)(n >> 8); + float lng = (float)(n & 255); + + lat *= PI / 128.0f; + lng *= PI / 128.0f; + + out[0] = cosf(lat) * sinf(lng); + out[1] = sinf(lat) * sinf(lng); + out[2] = cosf(lng); +} + +static void LatLngInit(void) +{ + int i, j; + for (i = 0; i < 256; i++) + { + for (j = 0; j < 256; j++) + LatLngToNormal((short)((i << 8) + j), latlnglookup[i][j]); + } +} + +static bool latlnginit = false; + +model_t *MD3_LoadModel(const char *fileName, int ztag, boolean useFloat) +{ + useFloat = true; // Right now we always useFloat = true, because the GL subsystem needs some work for the other option to work. + + if (!latlnginit) + { + LatLngInit(); + latlnginit = true; + } + + const float WUNITS = 1.0f; + model_t *retModel = NULL; + + FILE *f = fopen(fileName, "rb"); + + if (!f) + return NULL; + + retModel = (model_t*)Z_Calloc(sizeof(model_t), ztag, 0); + + md3modelHeader *mdh; + + // find length of file + fseek(f, 0, SEEK_END); + long fileLen = ftell(f); + fseek(f, 0, SEEK_SET); + + // read in file + char *buffer = malloc(fileLen); + fread(buffer, fileLen, 1, f); + fclose(f); + + // get pointer to file header + mdh = (md3modelHeader*)buffer; + + retModel->numMeshes = mdh->numSurfaces; + + retModel->numMaterials = 0; + int surfEnd = 0; + int i; + for (i = 0; i < mdh->numSurfaces; i++) + { + md3Surface *mdS = (md3Surface*)&buffer[mdh->offsetSurfaces]; + surfEnd += mdS->offsetEnd; + + retModel->numMaterials += mdS->numShaders; + } + + // Initialize materials + if (retModel->numMaterials <= 0) // Always at least one skin, duh + retModel->numMaterials = 1; + + retModel->materials = (material_t*)Z_Calloc(sizeof(material_t)*retModel->numMaterials, ztag, 0); + + int t; + for (t = 0; t < retModel->numMaterials; t++) + { + retModel->materials[t].ambient[0] = 0.3686f; + retModel->materials[t].ambient[1] = 0.3684f; + retModel->materials[t].ambient[2] = 0.3684f; + retModel->materials[t].ambient[3] = 1.0f; + retModel->materials[t].diffuse[0] = 0.8863f; + retModel->materials[t].diffuse[1] = 0.8850f; + retModel->materials[t].diffuse[2] = 0.8850f; + retModel->materials[t].diffuse[3] = 1.0f; + retModel->materials[t].emissive[0] = 0.0f; + retModel->materials[t].emissive[1] = 0.0f; + retModel->materials[t].emissive[2] = 0.0f; + retModel->materials[t].emissive[3] = 1.0f; + retModel->materials[t].specular[0] = 0.4902f; + retModel->materials[t].specular[1] = 0.4887f; + retModel->materials[t].specular[2] = 0.4887f; + retModel->materials[t].specular[3] = 1.0f; + retModel->materials[t].shininess = 25.0f; + retModel->materials[t].spheremap = false; + } + + retModel->meshes = (mesh_t*)Z_Calloc(sizeof(mesh_t)*retModel->numMeshes, ztag, 0); + + int matCount = 0; + for (i = 0, surfEnd = 0; i < mdh->numSurfaces; i++) + { + md3Surface *mdS = (md3Surface*)&buffer[mdh->offsetSurfaces + surfEnd]; + surfEnd += mdS->offsetEnd; + + md3Shader *mdShader = (md3Shader*)((char*)mdS + mdS->offsetShaders); + int j; + for (j = 0; j < mdS->numShaders; j++, matCount++) + { + size_t len = strlen(mdShader[j].name); + mdShader[j].name[len-1] = 'z'; + mdShader[j].name[len-2] = 'u'; + mdShader[j].name[len-3] = 'b'; + + // Load material +/* retModel->materials[matCount].texture = Texture::ReadTexture(mdShader[j].name, ZT_TEXTURE); + + if (!systemSucks) + { + // Check for a normal map...?? + char openfilename[1024]; + char normalMapName[1024]; + strcpy(normalMapName, mdShader[j].name); + len = strlen(normalMapName); + char *ptr = &normalMapName[len]; + ptr--; // z + ptr--; // u + ptr--; // b + ptr--; // . + *ptr++ = '_'; + *ptr++ = 'n'; + *ptr++ = '.'; + *ptr++ = 'b'; + *ptr++ = 'u'; + *ptr++ = 'z'; + *ptr++ = '\0'; + + sprintf(openfilename, "%s/%s", "textures", normalMapName); + // Convert backslashes to forward slashes + for (int k = 0; k < 1024; k++) + { + if (openfilename[k] == '\0') + break; + + if (openfilename[k] == '\\') + openfilename[k] = '/'; + } + + Resource::resource_t *res = Resource::Open(openfilename); + if (res) + { + Resource::Close(res); + retModel->materials[matCount].lightmap = Texture::ReadTexture(normalMapName, ZT_TEXTURE); + } + }*/ + } + + retModel->meshes[i].numFrames = mdS->numFrames; + retModel->meshes[i].numTriangles = mdS->numTriangles; + + if (!useFloat) // 'tinyframe' mode with indices + { + float tempNormal[3]; + retModel->meshes[i].tinyframes = (tinyframe_t*)Z_Calloc(sizeof(tinyframe_t)*mdS->numFrames, ztag, 0); + retModel->meshes[i].numVertices = mdS->numVerts; + retModel->meshes[i].uvs = (float*)Z_Malloc(sizeof(float)*2*mdS->numVerts, ztag, 0); + for (j = 0; j < mdS->numFrames; j++) + { + md3Vertex *mdV = (md3Vertex*)((char*)mdS + mdS->offsetXYZNormal + (mdS->numVerts*j*sizeof(md3Vertex))); + retModel->meshes[i].tinyframes[j].vertices = (short*)Z_Malloc(sizeof(short)*3*mdS->numVerts, ztag, 0); + retModel->meshes[i].tinyframes[j].normals = (char*)Z_Malloc(sizeof(char)*3*mdS->numVerts, ztag, 0); + +// if (retModel->materials[0].lightmap) +// retModel->meshes[i].tinyframes[j].tangents = (char*)malloc(sizeof(char));//(char*)Z_Malloc(sizeof(char)*3*mdS->numVerts, ztag); + retModel->meshes[i].indices = (unsigned short*)Z_Malloc(sizeof(unsigned short) * 3 * mdS->numTriangles, ztag, 0); + short *vertptr = retModel->meshes[i].tinyframes[j].vertices; + char *normptr = retModel->meshes[i].tinyframes[j].normals; + +// char *tanptr = retModel->meshes[i].tinyframes[j].tangents; + retModel->meshes[i].tinyframes[j].material = &retModel->materials[i]; + + int k; + for (k = 0; k < mdS->numVerts; k++) + { + // Vertex + *vertptr = mdV[k].y; + vertptr++; + *vertptr = mdV[k].z; + vertptr++; + *vertptr = mdV[k].x; + vertptr++; + + // Normal + GetNormalFromLatLong(mdV[k].n, tempNormal); + *normptr = (byte)(tempNormal[1] * 127); + normptr++; + *normptr = (byte)(tempNormal[2] * 127); + normptr++; + *normptr = (byte)(tempNormal[0] * 127); + normptr++; + } + } + + float *uvptr = (float*)retModel->meshes[i].uvs; + md3TexCoord *mdST = (md3TexCoord*)((char*)mdS + mdS->offsetST); + for (j = 0; j < mdS->numVerts; j++) + { + *uvptr = mdST[j].st[0]; + uvptr++; + *uvptr = 1.0f - mdST[j].st[1]; + uvptr++; + } + + unsigned short *indexptr = retModel->meshes[i].indices; + md3Triangle *mdT = (md3Triangle*)((char*)mdS + mdS->offsetTriangles); + for (j = 0; j < mdS->numTriangles; j++, mdT++) + { + // Indices + *indexptr = (unsigned short)mdT->index[0]; + indexptr++; + *indexptr = (unsigned short)mdT->index[2]; + indexptr++; + *indexptr = (unsigned short)mdT->index[1]; + indexptr++; + } + } + else // Traditional full-float loading method + { + retModel->meshes[i].numVertices = mdS->numTriangles * 3;//mdS->numVerts; + float dataScale = 0.015624f * WUNITS; + float tempNormal[3]; + retModel->meshes[i].frames = (mdlframe_t*)Z_Calloc(sizeof(mdlframe_t)*mdS->numFrames, ztag, 0); + retModel->meshes[i].uvs = (float*)Z_Malloc(sizeof(float)*2*mdS->numTriangles*3, ztag, 0); + + for (j = 0; j < mdS->numFrames; j++) + { + md3Vertex *mdV = (md3Vertex*)((char*)mdS + mdS->offsetXYZNormal + (mdS->numVerts*j*sizeof(md3Vertex))); + retModel->meshes[i].frames[j].vertices = (float*)Z_Malloc(sizeof(float)*3*mdS->numTriangles*3, ztag, 0); + retModel->meshes[i].frames[j].normals = (float*)Z_Malloc(sizeof(float)*3*mdS->numTriangles*3, ztag, 0); +// if (retModel->materials[i].lightmap) +// retModel->meshes[i].frames[j].tangents = (float*)malloc(sizeof(float));//(float*)Z_Malloc(sizeof(float)*3*mdS->numTriangles*3, ztag); + float *vertptr = retModel->meshes[i].frames[j].vertices; + float *normptr = retModel->meshes[i].frames[j].normals; + retModel->meshes[i].frames[j].material = &retModel->materials[i]; + + int k; + md3Triangle *mdT = (md3Triangle*)((char*)mdS + mdS->offsetTriangles); + + for (k = 0; k < mdS->numTriangles; k++) + { + // Vertex 1 + *vertptr = mdV[mdT->index[0]].x * dataScale; + vertptr++; + *vertptr = mdV[mdT->index[0]].z * dataScale; + vertptr++; + *vertptr = mdV[mdT->index[0]].y * dataScale; + vertptr++; + + GetNormalFromLatLong(mdV[mdT->index[0]].n, tempNormal); + *normptr = tempNormal[1]; + normptr++; + *normptr = tempNormal[2]; + normptr++; + *normptr = tempNormal[0]; + normptr++; + + // Vertex 2 + *vertptr = mdV[mdT->index[2]].x * dataScale; + vertptr++; + *vertptr = mdV[mdT->index[2]].z * dataScale; + vertptr++; + *vertptr = mdV[mdT->index[2]].y * dataScale; + vertptr++; + + GetNormalFromLatLong(mdV[mdT->index[2]].n, tempNormal); + *normptr = tempNormal[1]; + normptr++; + *normptr = tempNormal[2]; + normptr++; + *normptr = tempNormal[0]; + normptr++; + + // Vertex 3 + *vertptr = mdV[mdT->index[1]].x * dataScale; + vertptr++; + *vertptr = mdV[mdT->index[1]].z * dataScale; + vertptr++; + *vertptr = mdV[mdT->index[1]].y * dataScale; + vertptr++; + + GetNormalFromLatLong(mdV[mdT->index[1]].n, tempNormal); + *normptr = tempNormal[1]; + normptr++; + *normptr = tempNormal[2]; + normptr++; + *normptr = tempNormal[0]; + normptr++; + + mdT++; // Advance to next triangle + } + } + + md3TexCoord *mdST = (md3TexCoord*)((char*)mdS + mdS->offsetST); + float *uvptr = (float*)retModel->meshes[i].uvs; + int k; + md3Triangle *mdT = (md3Triangle*)((char*)mdS + mdS->offsetTriangles); + + for (k = 0; k < mdS->numTriangles; k++) + { + *uvptr = mdST[mdT->index[0]].st[0]; + uvptr++; + *uvptr = mdST[mdT->index[0]].st[1]; + uvptr++; + + *uvptr = mdST[mdT->index[2]].st[0]; + uvptr++; + *uvptr = mdST[mdT->index[2]].st[1]; + uvptr++; + + *uvptr = mdST[mdT->index[1]].st[0]; + uvptr++; + *uvptr = mdST[mdT->index[1]].st[1]; + uvptr++; + + mdT++; // Advance to next triangle + } + } + } + /* + // Tags? + retModel->numTags = mdh->numTags; + retModel->maxNumFrames = mdh->numFrames; + retModel->tags = (tag_t*)Z_Calloc(sizeof(tag_t) * retModel->numTags * mdh->numFrames, ztag); + md3Tag *mdTag = (md3Tag*)&buffer[mdh->offsetTags]; + tag_t *curTag = retModel->tags; + for (i = 0; i < mdh->numFrames; i++) + { + int j; + for (j = 0; j < retModel->numTags; j++, mdTag++) + { + strcpys(curTag->name, mdTag->name, sizeof(curTag->name) / sizeof(char)); + curTag->transform.m[0][0] = mdTag->axis[0]; + curTag->transform.m[0][1] = mdTag->axis[1]; + curTag->transform.m[0][2] = mdTag->axis[2]; + curTag->transform.m[1][0] = mdTag->axis[3]; + curTag->transform.m[1][1] = mdTag->axis[4]; + curTag->transform.m[1][2] = mdTag->axis[5]; + curTag->transform.m[2][0] = mdTag->axis[6]; + curTag->transform.m[2][1] = mdTag->axis[7]; + curTag->transform.m[2][2] = mdTag->axis[8]; + curTag->transform.m[3][0] = mdTag->origin[0] * WUNITS; + curTag->transform.m[3][1] = mdTag->origin[1] * WUNITS; + curTag->transform.m[3][2] = mdTag->origin[2] * WUNITS; + curTag->transform.m[3][3] = 1.0f; + + Matrix::Rotate(&curTag->transform, 90.0f, &Vector::Xaxis); + curTag++; + } + }*/ + + + free(buffer); + + return retModel; +} diff --git a/src/hardware/hw_md3load.h b/src/hardware/hw_md3load.h new file mode 100644 index 000000000..c0e0522ff --- /dev/null +++ b/src/hardware/hw_md3load.h @@ -0,0 +1,19 @@ +/* + From the 'Wizard2' engine by Spaddlewit Inc. ( http://www.spaddlewit.com ) + An experimental work-in-progress. + + Donated to Sonic Team Junior and adapted to work with + Sonic Robo Blast 2. The license of this code matches whatever + the licensing is for Sonic Robo Blast 2. +*/ + +#ifndef _HW_MD3LOAD_H_ +#define _HW_MD3LOAD_H_ + +#include "hw_model.h" +#include "../doomtype.h" + +// Load the Model +model_t *MD3_LoadModel(const char *fileName, int ztag, boolean useFloat); + +#endif diff --git a/src/hardware/hw_model.c b/src/hardware/hw_model.c new file mode 100644 index 000000000..73b2b484b --- /dev/null +++ b/src/hardware/hw_model.c @@ -0,0 +1,706 @@ +/* + From the 'Wizard2' engine by Spaddlewit Inc. ( http://www.spaddlewit.com ) + An experimental work-in-progress. + + Donated to Sonic Team Junior and adapted to work with + Sonic Robo Blast 2. The license of this code matches whatever + the licensing is for Sonic Robo Blast 2. +*/ + +#include "../z_zone.h" +#include "../doomdef.h" +#include "hw_model.h" +#include "hw_md2load.h" +#include "hw_md3load.h" +#include "u_list.h" +#include + +static float PI = (3.1415926535897932384626433832795f); +float U_Deg2Rad(float deg) +{ + return deg * ((float)PI / 180.0f); +} + +vector_t vectorXaxis = { 1.0f, 0.0f, 0.0f }; +vector_t vectorYaxis = { 0.0f, 1.0f, 0.0f }; +vector_t vectorZaxis = { 0.0f, 0.0f, 1.0f }; + +void VectorRotate(vector_t *rotVec, const vector_t *axisVec, float angle) +{ + angle = U_Deg2Rad(angle); + + // Rotate the point (x,y,z) around the vector (u,v,w) + float ux = axisVec->x * rotVec->x; + float uy = axisVec->x * rotVec->y; + float uz = axisVec->x * rotVec->z; + float vx = axisVec->y * rotVec->x; + float vy = axisVec->y * rotVec->y; + float vz = axisVec->y * rotVec->z; + float wx = axisVec->z * rotVec->x; + float wy = axisVec->z * rotVec->y; + float wz = axisVec->z * rotVec->z; + float sa = sinf(angle); + float ca = cosf(angle); + + rotVec->x = axisVec->x*(ux + vy + wz) + (rotVec->x*(axisVec->y*axisVec->y + axisVec->z*axisVec->z) - axisVec->x*(vy + wz))*ca + (-wy + vz)*sa; + rotVec->y = axisVec->y*(ux + vy + wz) + (rotVec->y*(axisVec->x*axisVec->x + axisVec->z*axisVec->z) - axisVec->y*(ux + wz))*ca + (wx - uz)*sa; + rotVec->z = axisVec->z*(ux + vy + wz) + (rotVec->z*(axisVec->x*axisVec->x + axisVec->y*axisVec->y) - axisVec->z*(ux + vy))*ca + (-vx + uy)*sa; +} + +void CreateVBOTiny(mesh_t *mesh, tinyframe_t *frame) +{ + return; +/* int bufferSize = sizeof(VBO::vbotiny_t)*mesh->numTriangles*3; + VBO::vbotiny_t *buffer = (VBO::vbotiny_t*)Z_Malloc(bufferSize, PU_STATIC, 0); + VBO::vbotiny_t *bufPtr = buffer; + + short *vertPtr = frame->vertices; + char *normPtr = frame->normals; + float *uvPtr = mesh->uvs; + char *tanPtr = frame->tangents; + + int i; + for (i = 0; i < mesh->numTriangles*3; i++) + { + bufPtr->x = *vertPtr++; + bufPtr->y = *vertPtr++; + bufPtr->z = *vertPtr++; + + bufPtr->nx = (*normPtr++) * 127; + bufPtr->ny = (*normPtr++) * 127; + bufPtr->nz = (*normPtr++) * 127; + + bufPtr->s0 = *uvPtr++; + bufPtr->t0 = *uvPtr++; + + if (tanPtr) + { + bufPtr->tanx = *tanPtr++; + bufPtr->tany = *tanPtr++; + bufPtr->tanz = *tanPtr++; + } + + bufPtr++; + } + + bglGenBuffers(1, &frame->vboID); + bglBindBuffer(BGL_ARRAY_BUFFER, frame->vboID); + bglBufferData(BGL_ARRAY_BUFFER, bufferSize, buffer, BGL_STATIC_DRAW); + Z_Free(buffer);*/ +} + +void CreateVBO(mesh_t *mesh, mdlframe_t *frame) +{ + return; +/* int bufferSize = sizeof(VBO::vbo64_t)*mesh->numTriangles*3; + VBO::vbo64_t *buffer = (VBO::vbo64_t*)Z_Malloc(bufferSize, PU_STATIC, 0); + VBO::vbo64_t *bufPtr = buffer; + + float *vertPtr = frame->vertices; + float *normPtr = frame->normals; + float *tanPtr = frame->tangents; + float *uvPtr = mesh->uvs; + float *lightPtr = mesh->lightuvs; + byte *colorPtr = frame->colors; + + int i; + for (i = 0; i < mesh->numTriangles*3; i++) + { + bufPtr->x = *vertPtr++; + bufPtr->y = *vertPtr++; + bufPtr->z = *vertPtr++; + + bufPtr->nx = *normPtr++; + bufPtr->ny = *normPtr++; + bufPtr->nz = *normPtr++; + + bufPtr->s0 = *uvPtr++; + bufPtr->t0 = *uvPtr++; + + if (tanPtr != NULL) + { + bufPtr->tan0 = *tanPtr++; + bufPtr->tan1 = *tanPtr++; + bufPtr->tan2 = *tanPtr++; + } + + if (lightPtr != NULL) + { + bufPtr->s1 = *lightPtr++; + bufPtr->t1 = *lightPtr++; + } + + if (colorPtr) + { + bufPtr->r = *colorPtr++; + bufPtr->g = *colorPtr++; + bufPtr->b = *colorPtr++; + bufPtr->a = *colorPtr++; + } + else + { + bufPtr->r = 255; + bufPtr->g = 255; + bufPtr->b = 255; + bufPtr->a = 255; + } + + bufPtr++; + } + + bglGenBuffers(1, &frame->vboID); + bglBindBuffer(BGL_ARRAY_BUFFER, frame->vboID); + bglBufferData(BGL_ARRAY_BUFFER, bufferSize, buffer, BGL_STATIC_DRAW); + Z_Free(buffer);*/ +} + +void UnloadModel(model_t *model) +{ + // Wouldn't it be great if C just had destructors? + int i; + for (i = 0; i < model->numMeshes; i++) + { + mesh_t *mesh = &model->meshes[i]; + + if (mesh->frames) + { + int j; + for (j = 0; j < mesh->numFrames; j++) + { + if (mesh->frames[j].normals) + Z_Free(mesh->frames[j].normals); + + if (mesh->frames[j].tangents) + Z_Free(mesh->frames[j].tangents); + + if (mesh->frames[j].vertices) + Z_Free(mesh->frames[j].vertices); + + if (mesh->frames[j].colors) + Z_Free(mesh->frames[j].colors); + } + + Z_Free(mesh->frames); + } + else if (mesh->tinyframes) + { + int j; + for (j = 0; j < mesh->numFrames; j++) + { + if (mesh->tinyframes[j].normals) + Z_Free(mesh->tinyframes[j].normals); + + if (mesh->tinyframes[j].tangents) + Z_Free(mesh->tinyframes[j].tangents); + + if (mesh->tinyframes[j].vertices) + Z_Free(mesh->tinyframes[j].vertices); + } + + if (mesh->indices) + Z_Free(mesh->indices); + + Z_Free(mesh->tinyframes); + } + + if (mesh->uvs) + Z_Free(mesh->uvs); + + if (mesh->lightuvs) + Z_Free(mesh->lightuvs); + } + + if (model->meshes) + Z_Free(model->meshes); + + if (model->tags) + Z_Free(model->tags); + + if (model->materials) + Z_Free(model->materials); + + DeleteVBOs(model); + Z_Free(model); +} + +tag_t *GetTagByName(model_t *model, char *name, int frame) +{ + if (frame < model->maxNumFrames) + { + tag_t *iterator = &model->tags[frame * model->numTags]; + + int i; + for (i = 0; i < model->numTags; i++) + { + if (!stricmp(iterator[i].name, name)) + return &iterator[i]; + } + } + + return NULL; +} + +// +// LoadModel +// +// Load a model and +// convert it to the +// internal format. +// +model_t *LoadModel(const char *filename, int ztag) +{ + model_t *model; + + // What type of file? + const char *extension = NULL; + int i; + for (i = (int)strlen(filename)-1; i >= 0; i--) + { + if (filename[i] != '.') + continue; + + extension = &filename[i]; + break; + } + + if (!extension) + { + CONS_Printf("Model %s is lacking a file extension, unable to determine type!\n", filename); + return NULL; + } + + if (!strcmp(extension, ".md3")) + { + if (!(model = MD3_LoadModel(filename, ztag, false))) + return NULL; + } + else if (!strcmp(extension, ".md3s")) // MD3 that will be converted in memory to use full floats + { + if (!(model = MD3_LoadModel(filename, ztag, true))) + return NULL; + } + else if (!strcmp(extension, ".md2")) + { + if (!(model = MD2_LoadModel(filename, ztag, false))) + return NULL; + } + else if (!strcmp(extension, ".md2s")) + { + if (!(model = MD2_LoadModel(filename, ztag, true))) + return NULL; + } + else + { + CONS_Printf("Unknown model format: %s\n", extension); + return NULL; + } + + model->mdlFilename = (char*)Z_Malloc(strlen(filename)+1, ztag, 0); + strcpy(model->mdlFilename, filename); + + Optimize(model); + GeneratePolygonNormals(model, ztag); + + // Default material properties + for (i = 0 ; i < model->numMaterials; i++) + { + material_t *material = &model->materials[i]; + material->ambient[0] = 0.7686f; + material->ambient[1] = 0.7686f; + material->ambient[2] = 0.7686f; + material->ambient[3] = 1.0f; + material->diffuse[0] = 0.5863f; + material->diffuse[1] = 0.5863f; + material->diffuse[2] = 0.5863f; + material->diffuse[3] = 1.0f; + material->specular[0] = 0.4902f; + material->specular[1] = 0.4902f; + material->specular[2] = 0.4902f; + material->specular[3] = 1.0f; + material->shininess = 25.0f; + } + + CONS_Printf("Generating VBOs for %s\n", filename); + for (i = 0; i < model->numMeshes; i++) + { + mesh_t *mesh = &model->meshes[i]; + + if (mesh->frames) + { + int j; + for (j = 0; j < model->meshes[i].numFrames; j++) + { + mdlframe_t *frame = &mesh->frames[j]; + frame->vboID = 0; + CreateVBO(mesh, frame); + } + } + else if (mesh->tinyframes) + { + int j; + for (j = 0; j < model->meshes[i].numFrames; j++) + { + tinyframe_t *frame = &mesh->tinyframes[j]; + frame->vboID = 0; + CreateVBOTiny(mesh, frame); + } + } + } + + return model; +} + +// +// GenerateVertexNormals +// +// Creates a new normal for a vertex using the average of all of the polygons it belongs to. +// +void GenerateVertexNormals(model_t *model) +{ + int i; + for (i = 0; i < model->numMeshes; i++) + { + mesh_t *mesh = &model->meshes[i]; + + if (!mesh->frames) + continue; + + int j; + for (j = 0; j < mesh->numFrames; j++) + { + mdlframe_t *frame = &mesh->frames[j]; + int memTag = PU_STATIC; + float *newNormals = (float*)Z_Malloc(sizeof(float)*3*mesh->numTriangles*3, memTag, 0); + M_Memcpy(newNormals, frame->normals, sizeof(float)*3*mesh->numTriangles*3); + +/* if (!systemSucks) + { + memTag = Z_GetTag(frame->tangents); + float *newTangents = (float*)Z_Malloc(sizeof(float)*3*mesh->numTriangles*3, memTag); + M_Memcpy(newTangents, frame->tangents, sizeof(float)*3*mesh->numTriangles*3); + }*/ + + int k; + float *vertPtr = frame->vertices; + for (k = 0; k < mesh->numVertices; k++) + { + float x, y, z; + x = *vertPtr++; + y = *vertPtr++; + z = *vertPtr++; + + int vCount = 0; + vector_t normal; + normal.x = normal.y = normal.z = 0; + int l; + float *testPtr = frame->vertices; + for (l = 0; l < mesh->numVertices; l++) + { + float testX, testY, testZ; + testX = *testPtr++; + testY = *testPtr++; + testZ = *testPtr++; + + if (x != testX || y != testY || z != testZ) + continue; + + // Found a vertex match! Add it... + normal.x += frame->normals[3 * l + 0]; + normal.y += frame->normals[3 * l + 1]; + normal.z += frame->normals[3 * l + 2]; + vCount++; + } + + if (vCount > 1) + { +// Vector::Normalize(&normal); + newNormals[3 * k + 0] = (float)normal.x; + newNormals[3 * k + 1] = (float)normal.y; + newNormals[3 * k + 2] = (float)normal.z; + +/* if (!systemSucks) + { + Vector::vector_t tangent; + Vector::Tangent(&normal, &tangent); + newTangents[3 * k + 0] = tangent.x; + newTangents[3 * k + 1] = tangent.y; + newTangents[3 * k + 2] = tangent.z; + }*/ + } + } + + float *oldNormals = frame->normals; + frame->normals = newNormals; + Z_Free(oldNormals); + +/* if (!systemSucks) + { + float *oldTangents = frame->tangents; + frame->tangents = newTangents; + Z_Free(oldTangents); + }*/ + } + } +} + +typedef struct materiallist_s +{ + struct materiallist_s *next; + struct materiallist_s *prev; + material_t *material; +} materiallist_t; + +static bool AddMaterialToList(materiallist_t **head, material_t *material) +{ + materiallist_t *node; + for (node = *head; node; node = node->next) + { + if (node->material == material) + return false; + } + + // Didn't find it, so add to the list + materiallist_t *newMatNode = (materiallist_t*)Z_Malloc(sizeof(materiallist_t), PU_CACHE, 0); + newMatNode->material = material; + ListAdd(newMatNode, (listitem_t**)head); + return true; +} + +// +// Optimize +// +// Groups triangles from meshes in the model +// Only works for models with 1 frame +// +void Optimize(model_t *model) +{ + if (model->numMeshes <= 1) + return; // No need + + int numMeshes = 0; + int i; + materiallist_t *matListHead = NULL; + for (i = 0; i < model->numMeshes; i++) + { + mesh_t *curMesh = &model->meshes[i]; + + if (curMesh->numFrames > 1) + return; // Can't optimize models with > 1 frame + + if (!curMesh->frames) + return; // Don't optimize tinyframe models (no need) + + // We are condensing to 1 mesh per material, so + // the # of materials we use will be the new + // # of meshes + if (AddMaterialToList(&matListHead, curMesh->frames[0].material)) + numMeshes++; + } + + int memTag = PU_STATIC; + mesh_t *newMeshes = (mesh_t*)Z_Calloc(sizeof(mesh_t) * numMeshes, memTag, 0); + + i = 0; + materiallist_t *node; + for (node = matListHead; node; node = node->next) + { + material_t *curMat = node->material; + mesh_t *newMesh = &newMeshes[i]; + + // Find all triangles with this material and count them + int numTriangles = 0; + int j; + for (j = 0; j < model->numMeshes; j++) + { + mesh_t *curMesh = &model->meshes[j]; + + if (curMesh->frames[0].material == curMat) + numTriangles += curMesh->numTriangles; + } + + newMesh->numFrames = 1; + newMesh->numTriangles = numTriangles; + newMesh->numVertices = numTriangles * 3; + newMesh->uvs = (float*)Z_Malloc(sizeof(float)*2*numTriangles*3, memTag, 0); +// if (node->material->lightmap) +// newMesh->lightuvs = (float*)Z_Malloc(sizeof(float)*2*numTriangles*3, memTag, 0); + newMesh->frames = (mdlframe_t*)Z_Calloc(sizeof(mdlframe_t), memTag, 0); + mdlframe_t *curFrame = &newMesh->frames[0]; + + curFrame->material = curMat; + curFrame->normals = (float*)Z_Malloc(sizeof(float)*3*numTriangles*3, memTag, 0); +// if (!systemSucks) +// curFrame->tangents = (float*)Z_Malloc(sizeof(float)*3*numTriangles*3, memTag, 0); + curFrame->vertices = (float*)Z_Malloc(sizeof(float)*3*numTriangles*3, memTag, 0); + curFrame->colors = (byte*)Z_Malloc(sizeof(byte)*4*numTriangles*3, memTag, 0); + + // Now traverse the meshes of the model, adding in + // vertices/normals/uvs that match the current material + int uvCount = 0; + int vertCount = 0; + int colorCount = 0; + for (j = 0; j < model->numMeshes; j++) + { + mesh_t *curMesh = &model->meshes[j]; + + if (curMesh->frames[0].material == curMat) + { + float *dest; + float *src; + + M_Memcpy(&newMesh->uvs[uvCount], + curMesh->uvs, + sizeof(float)*2*curMesh->numTriangles*3); + +/* if (node->material->lightmap) + { + M_Memcpy(&newMesh->lightuvs[uvCount], + curMesh->lightuvs, + sizeof(float)*2*curMesh->numTriangles*3); + }*/ + uvCount += 2*curMesh->numTriangles*3; + + dest = (float*)newMesh->frames[0].vertices; + src = (float*)curMesh->frames[0].vertices; + M_Memcpy(&dest[vertCount], + src, + sizeof(float)*3*curMesh->numTriangles*3); + + dest = (float*)newMesh->frames[0].normals; + src = (float*)curMesh->frames[0].normals; + M_Memcpy(&dest[vertCount], + src, + sizeof(float)*3*curMesh->numTriangles*3); + +/* if (!systemSucks) + { + dest = (float*)newMesh->frames[0].tangents; + src = (float*)curMesh->frames[0].tangents; + M_Memcpy(&dest[vertCount], + src, + sizeof(float)*3*curMesh->numTriangles*3); + }*/ + + vertCount += 3 * curMesh->numTriangles * 3; + + byte *destByte; + byte *srcByte; + destByte = (byte*)newMesh->frames[0].colors; + srcByte = (byte*)curMesh->frames[0].colors; + + if (srcByte) + { + M_Memcpy(&destByte[colorCount], + srcByte, + sizeof(byte)*4*curMesh->numTriangles*3); + } + else + { + memset(&destByte[colorCount], + 255, + sizeof(byte)*4*curMesh->numTriangles*3); + } + + colorCount += 4 * curMesh->numTriangles * 3; + } + } + + i++; + } + + CONS_Printf("Model::Optimize(): Model reduced from %d to %d meshes.\n", model->numMeshes, numMeshes); + model->meshes = newMeshes; + model->numMeshes = numMeshes; +} + +void GeneratePolygonNormals(model_t *model, int ztag) +{ + int i; + for (i = 0; i < model->numMeshes; i++) + { + mesh_t *mesh = &model->meshes[i]; + + if (!mesh->frames) + continue; + + int j; + for (j = 0; j < mesh->numFrames; j++) + { + mdlframe_t *frame = &mesh->frames[j]; + + frame->polyNormals = (vector_t*)Z_Malloc(sizeof(vector_t) * mesh->numTriangles, ztag, 0); + + const float *vertices = frame->vertices; + vector_t *polyNormals = frame->polyNormals; + int k; + for (k = 0; k < mesh->numTriangles; k++) + { +// Vector::Normal(vertices, polyNormals); + vertices += 3 * 3; + polyNormals++; + } + } + } +} + +// +// Reload +// +// Reload VBOs +// +void Reload(void) +{ +/* model_t *node; + for (node = modelHead; node; node = node->next) + { + int i; + for (i = 0; i < node->numMeshes; i++) + { + mesh_t *mesh = &node->meshes[i]; + + if (mesh->frames) + { + int j; + for (j = 0; j < mesh->numFrames; j++) + CreateVBO(mesh, &mesh->frames[j]); + } + else if (mesh->tinyframes) + { + int j; + for (j = 0; j < mesh->numFrames; j++) + CreateVBO(mesh, &mesh->tinyframes[j]); + } + } + }*/ +} + +void DeleteVBOs(model_t *model) +{ +/* for (int i = 0; i < model->numMeshes; i++) + { + mesh_t *mesh = &model->meshes[i]; + + if (mesh->frames) + { + for (int j = 0; j < mesh->numFrames; j++) + { + mdlframe_t *frame = &mesh->frames[j]; + if (!frame->vboID) + continue; + bglDeleteBuffers(1, &frame->vboID); + frame->vboID = 0; + } + } + else if (mesh->tinyframes) + { + for (int j = 0; j < mesh->numFrames; j++) + { + tinyframe_t *frame = &mesh->tinyframes[j]; + if (!frame->vboID) + continue; + bglDeleteBuffers(1, &frame->vboID); + frame->vboID = 0; + } + } + }*/ +} diff --git a/src/hardware/hw_model.h b/src/hardware/hw_model.h new file mode 100644 index 000000000..ed7e41a55 --- /dev/null +++ b/src/hardware/hw_model.h @@ -0,0 +1,104 @@ +/* + From the 'Wizard2' engine by Spaddlewit Inc. ( http://www.spaddlewit.com ) + An experimental work-in-progress. + + Donated to Sonic Team Junior and adapted to work with + Sonic Robo Blast 2. The license of this code matches whatever + the licensing is for Sonic Robo Blast 2. +*/ + +#ifndef _HW_MODEL_H_ +#define _HW_MODEL_H_ + +#include "../doomtype.h" + +typedef struct +{ + float x, y, z; +} vector_t; + +extern vector_t vectorXaxis; +extern vector_t vectorYaxis; +extern vector_t vectorZaxis; + +void VectorRotate(vector_t *rotVec, const vector_t *axisVec, float angle); + +typedef struct +{ + float ambient[4], diffuse[4], specular[4], emissive[4]; + float shininess; + bool spheremap; +// Texture::texture_t *texture; +// Texture::texture_t *lightmap; +} material_t; + +typedef struct +{ + material_t *material; // Pointer to the allocated 'materials' list in model_t + float *vertices; + float *normals; + float *tangents; + byte *colors; + unsigned int vboID; + vector_t *polyNormals; +} mdlframe_t; + +typedef struct +{ + material_t *material; + short *vertices; + char *normals; + char *tangents; + unsigned int vboID; +} tinyframe_t; + +// Equivalent to MD3's many 'surfaces' +typedef struct mesh_s +{ + int numVertices; + int numTriangles; + + float *uvs; + float *lightuvs; + + int numFrames; + mdlframe_t *frames; + tinyframe_t *tinyframes; + unsigned short *indices; +} mesh_t; + +typedef struct tag_s +{ + char name[64]; +// matrix_t transform; +} tag_t; + +typedef struct model_s +{ + int maxNumFrames; + + int numMaterials; + material_t *materials; + int numMeshes; + mesh_t *meshes; + int numTags; + tag_t *tags; + + char *mdlFilename; + boolean unloaded; +} model_t; + +extern int numModels; +extern model_t *modelHead; + +tag_t *GetTagByName(model_t *model, char *name, int frame); +model_t *LoadModel(const char *filename, int ztag); +void UnloadModel(model_t *model); +void Optimize(model_t *model); +void GenerateVertexNormals(model_t *model); +void GeneratePolygonNormals(model_t *model, int ztag); +void CreateVBOTiny(mesh_t *mesh, tinyframe_t *frame); +void CreateVBO(mesh_t *mesh, mdlframe_t *frame); +void DeleteVBOs(model_t *model); + +#endif diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 91578e7f4..f8b324ed0 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -245,6 +245,12 @@ FUNCPRINTF void DBG_Printf(const char *lpFmt, ...) #define pglColor4f glColor4f #define pglColor4fv glColor4fv #define pglTexCoord2f glTexCoord2f +#define pglVertexPointer glVertexPointer +#define pglNormalPointer glNormalPointer +#define pglTexCoordPointer glTexCoordPointer +#define pglDrawArrays glDrawArrays +#define pglEnableClientState glEnableClientState +#define pglDisableClientState pglDisableClientState /* Lighting */ #define pglShadeModel glShadeModel @@ -357,6 +363,18 @@ typedef void (APIENTRY * PFNglColor4fv) (const GLfloat *v); static PFNglColor4fv pglColor4fv; typedef void (APIENTRY * PFNglTexCoord2f) (GLfloat s, GLfloat t); static PFNglTexCoord2f pglTexCoord2f; +typedef void (APIENTRY * PFNglVertexPointer) (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +static PFNglVertexPointer pglVertexPointer; +typedef void (APIENTRY * PFNglNormalPointer) (GLenum type, GLsizei stride, const GLvoid *pointer); +static PFNglNormalPointer pglNormalPointer; +typedef void (APIENTRY * PFNglTexCoordPointer) (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +static PFNglTexCoordPointer pglTexCoordPointer; +typedef void (APIENTRY * PFNglDrawArrays) (GLenum mode, GLint first, GLsizei count); +static PFNglDrawArrays pglDrawArrays; +typedef void (APIENTRY * PFNglEnableClientState) (GLenum cap); +static PFNglEnableClientState pglEnableClientState; +typedef void (APIENTRY * PFNglDisableClientState) (GLenum cap); +static PFNglDisableClientState pglDisableClientState; /* Lighting */ typedef void (APIENTRY * PFNglShadeModel) (GLenum mode); @@ -495,6 +513,12 @@ boolean SetupGLfunc(void) GETOPENGLFUNC(pglColor4f , glColor4f) GETOPENGLFUNC(pglColor4fv , glColor4fv) GETOPENGLFUNC(pglTexCoord2f , glTexCoord2f) + GETOPENGLFUNC(pglVertexPointer, glVertexPointer) + GETOPENGLFUNC(pglNormalPointer, glNormalPointer) + GETOPENGLFUNC(pglTexCoordPointer, glTexCoordPointer) + GETOPENGLFUNC(pglDrawArrays, glDrawArrays) + GETOPENGLFUNC(pglEnableClientState, glEnableClientState) + GETOPENGLFUNC(pglDisableClientState, glDisableClientState) GETOPENGLFUNC(pglShadeModel , glShadeModel) GETOPENGLFUNC(pglLightfv, glLightfv) @@ -1878,14 +1902,15 @@ EXPORT void HWRAPI(SetSpecialState) (hwdspecialstate_t IdState, INT32 Value) } } -static void DrawMD2Ex(INT32 *gl_cmd_buffer, md2_frame_t *frame, INT32 duration, INT32 tics, md2_frame_t *nextframe, FTransform *pos, float scale, UINT8 flipped, UINT8 *color) -{ +static void DrawModelEx(model_t *model, mdlframe_t *frame, INT32 duration, INT32 tics, mdlframe_t *nextframe, FTransform *pos, float scale, UINT8 flipped, UINT8 *color) +{ INT32 val, count, pindex; GLfloat s, t; GLfloat ambient[4]; GLfloat diffuse[4]; float pol = 0.0f; + scale *= 0.5f; float scalex = scale, scaley = scale, scalez = scale; // Because Otherwise, scaling the screen negatively vertically breaks the lighting @@ -1966,68 +1991,107 @@ static void DrawMD2Ex(INT32 *gl_cmd_buffer, md2_frame_t *frame, INT32 duration, pglRotatef(pos->anglex, -1.0f, 0.0f, 0.0f); pglRotatef(pos->angley, 0.0f, -1.0f, 0.0f); - val = *gl_cmd_buffer++; + pglScalef(scalex, scaley, scalez); - while (val != 0) + mesh_t *mesh = &model->meshes[0]; + + if (!nextframe || pol == 0.0f) { - if (val < 0) + // Zoom! Take advantage of just shoving the entire arrays to the GPU. + pglEnableClientState(GL_VERTEX_ARRAY); + pglEnableClientState(GL_TEXTURE_COORD_ARRAY); + pglEnableClientState(GL_NORMAL_ARRAY); + pglVertexPointer(3, GL_FLOAT, 0, frame->vertices); + pglNormalPointer(GL_FLOAT, 0, frame->normals); + pglTexCoordPointer(2, GL_FLOAT, 0, mesh->uvs); + pglDrawArrays(GL_TRIANGLES, 0, mesh->numTriangles * 3); + pglDisableClientState(GL_NORMAL_ARRAY); + pglDisableClientState(GL_TEXTURE_COORD_ARRAY); + pglDisableClientState(GL_TEXTURE_COORD_ARRAY); + /* + pglBegin(GL_TRIANGLES); + + int i = 0; + float *uvPtr = mesh->uvs; + float *frameVert = frame->vertices; + float *frameNormal = frame->normals; + for (i = 0; i < mesh->numTriangles; i++) { - pglBegin(GL_TRIANGLE_FAN); - count = -val; - } - else - { - pglBegin(GL_TRIANGLE_STRIP); - count = val; + float uvx = *uvPtr++; + float uvy = *uvPtr++; + + // Interpolate + float px1 = *frameVert++; + float py1 = *frameVert++; + float pz1 = *frameVert++; + float nx1 = *frameNormal++; + float ny1 = *frameNormal++; + float nz1 = *frameNormal++; + + pglTexCoord2f(uvx, uvy); + pglNormal3f(nx1, ny1, nz1); + pglVertex3f(px1, py1, pz1); } - while (count--) + pglEnd();*/ + } + else + { + // Dangit, I soooo want to do this in a GLSL shader... + pglBegin(GL_TRIANGLES); + + int i = 0; + float *uvPtr = mesh->uvs; + float *frameVert = frame->vertices; + float *frameNormal = frame->normals; + float *nextFrameVert = nextframe->vertices; + float *nextFrameNormal = frame->normals; + for (i = 0; i < mesh->numTriangles; i++) { - s = *(float *) gl_cmd_buffer++; - t = *(float *) gl_cmd_buffer++; - pindex = *gl_cmd_buffer++; + float uvx = *uvPtr++; + float uvy = *uvPtr++; - pglTexCoord2f(s, t); + // Interpolate + float px1 = *frameVert++; + float px2 = *nextFrameVert++; + float py1 = *frameVert++; + float py2 = *nextFrameVert++; + float pz1 = *frameVert++; + float pz2 = *nextFrameVert++; + float nx1 = *frameNormal++; + float nx2 = *nextFrameNormal++; + float ny1 = *frameNormal++; + float ny2 = *nextFrameNormal++; + float nz1 = *frameNormal++; + float nz2 = *nextFrameNormal++; - if (!nextframe || pol == 0.0f) - { - pglNormal3f(frame->vertices[pindex].normal[0], - frame->vertices[pindex].normal[1], - frame->vertices[pindex].normal[2]); - - pglVertex3f(frame->vertices[pindex].vertex[0]*scalex/2.0f, - frame->vertices[pindex].vertex[1]*scaley/2.0f, - frame->vertices[pindex].vertex[2]*scalez/2.0f); - } - else - { - // Interpolate - float px1 = frame->vertices[pindex].vertex[0]*scalex/2.0f; - float px2 = nextframe->vertices[pindex].vertex[0]*scalex/2.0f; - float py1 = frame->vertices[pindex].vertex[1]*scaley/2.0f; - float py2 = nextframe->vertices[pindex].vertex[1]*scaley/2.0f; - float pz1 = frame->vertices[pindex].vertex[2]*scalez/2.0f; - float pz2 = nextframe->vertices[pindex].vertex[2]*scalez/2.0f; - float nx1 = frame->vertices[pindex].normal[0]; - float nx2 = nextframe->vertices[pindex].normal[0]; - float ny1 = frame->vertices[pindex].normal[1]; - float ny2 = nextframe->vertices[pindex].normal[1]; - float nz1 = frame->vertices[pindex].normal[2]; - float nz2 = nextframe->vertices[pindex].normal[2]; - - pglNormal3f((nx1 + pol * (nx2 - nx1)), - (ny1 + pol * (ny2 - ny1)), - (nz1 + pol * (nz2 - nz1))); - pglVertex3f((px1 + pol * (px2 - px1)), - (py1 + pol * (py2 - py1)), - (pz1 + pol * (pz2 - pz1))); - } + pglTexCoord2f(uvx, uvy); + pglNormal3f((nx1 + pol * (nx2 - nx1)), + (ny1 + pol * (ny2 - ny1)), + (nz1 + pol * (nz2 - nz1))); + pglVertex3f((px1 + pol * (px2 - px1)), + (py1 + pol * (py2 - py1)), + (pz1 + pol * (pz2 - pz1))); } pglEnd(); - - val = *gl_cmd_buffer++; } + +/* if (lightType != LIGHT_NONE) + { + glVertexAttribPointer(program->slots[Shaders::A_NORMAL_SLOT], 3, BGL_FLOAT, BGL_FALSE, 0, frame->normals); + // if (normalmapped) + // bglVertexAttribPointer(program->slots[Shaders::A_TANGENT_SLOT], 3, BGL_FLOAT, BGL_FALSE, 0, frame->tangents); + } + + if (frame->colors) + glVertexAttribPointer(program->slots[Shaders::A_COLOR_SLOT], 4, GL_UNSIGNED_BYTE, BGL_TRUE, 0, frame->colors); + else + { + SetGlobalWhiteColorArray(mesh->numTriangles * 3); + glVertexAttribPointer(program->slots[Shaders::A_COLOR_SLOT], 3, BGL_UNSIGNED_BYTE, BGL_TRUE, 0, globalWhiteColorArray); + } + */ pglPopMatrix(); // should be the same as glLoadIdentity if (color) pglDisable(GL_LIGHTING); @@ -2038,17 +2102,11 @@ static void DrawMD2Ex(INT32 *gl_cmd_buffer, md2_frame_t *frame, INT32 duration, // -----------------+ // HWRAPI DrawMD2 : Draw an MD2 model with glcommands // -----------------+ -EXPORT void HWRAPI(DrawMD2i) (INT32 *gl_cmd_buffer, md2_frame_t *frame, INT32 duration, INT32 tics, md2_frame_t *nextframe, FTransform *pos, float scale, UINT8 flipped, UINT8 *color) +EXPORT void HWRAPI(DrawModel) (model_t *model, mdlframe_t *frame, INT32 duration, INT32 tics, mdlframe_t *nextframe, FTransform *pos, float scale, UINT8 flipped, UINT8 *color) { - DrawMD2Ex(gl_cmd_buffer, frame, duration, tics, nextframe, pos, scale, flipped, color); + DrawModelEx(model, frame, duration, tics, nextframe, pos, scale, flipped, color); } -EXPORT void HWRAPI(DrawMD2) (INT32 *gl_cmd_buffer, md2_frame_t *frame, FTransform *pos, float scale) -{ - DrawMD2Ex(gl_cmd_buffer, frame, 0, 0, NULL, pos, scale, false, NULL); -} - - // -----------------+ // SetTransform : // -----------------+ diff --git a/src/hardware/u_list.c b/src/hardware/u_list.c new file mode 100644 index 000000000..dc49a74e7 --- /dev/null +++ b/src/hardware/u_list.c @@ -0,0 +1,230 @@ +/* + From the 'Wizard2' engine by Spaddlewit Inc. ( http://www.spaddlewit.com ) + An experimental work-in-progress. + + Donated to Sonic Team Junior and adapted to work with + Sonic Robo Blast 2. The license of this code matches whatever + the licensing is for Sonic Robo Blast 2. +*/ + +#include "u_list.h" +#include "../z_zone.h" + +// Utility for managing +// structures in a linked +// list. +// +// Struct must have "next" and "prev" pointers +// as its first two variables. +// + +// +// ListAdd +// +// Adds an item to the list +// +void ListAdd(void *pItem, listitem_t **itemHead) +{ + listitem_t *item = (listitem_t*)pItem; + + if (*itemHead == NULL) + { + *itemHead = item; + (*itemHead)->prev = (*itemHead)->next = NULL; + } + else + { + listitem_t *tail; + tail = *itemHead; + + while (tail->next != NULL) + tail = tail->next; + + tail->next = item; + + tail->next->prev = tail; + + item->next = NULL; + } +} + +// +// ListAddFront +// +// Adds an item to the front of the list +// (This is much faster) +// +void ListAddFront(void *pItem, listitem_t **itemHead) +{ + listitem_t *item = (listitem_t*)pItem; + + if (*itemHead == NULL) + { + *itemHead = item; + (*itemHead)->prev = (*itemHead)->next = NULL; + } + else + { + (*itemHead)->prev = item; + item->next = (*itemHead); + item->prev = NULL; + *itemHead = item; + } +} + +// +// ListAddBefore +// +// Adds an item before the item specified in the list +// +void ListAddBefore(void *pItem, void *pSpot, listitem_t **itemHead) +{ + listitem_t *item = (listitem_t*)pItem; + listitem_t *spot = (listitem_t*)pSpot; + + listitem_t *prev = spot->prev; + + if (!prev) + ListAddFront(pItem, itemHead); + else + { + item->next = spot; + spot->prev = item; + item->prev = prev; + prev->next = item; + } +} + +// +// ListAddAfter +// +// Adds an item after the item specified in the list +// +void ListAddAfter(void *pItem, void *pSpot, listitem_t **itemHead) +{ + listitem_t *item = (listitem_t*)pItem; + listitem_t *spot = (listitem_t*)pSpot; + + listitem_t *next = spot->next; + + if (!next) + ListAdd(pItem, itemHead); + else + { + item->prev = spot; + spot->next = item; + item->next = next; + next->prev = item; + } +} + +// +// ListRemove +// +// Take an item out of the list and free its memory. +// +void ListRemove(void *pItem, listitem_t **itemHead) +{ + listitem_t *item = (listitem_t*)pItem; + + if (item == *itemHead) // Start of list + { + *itemHead = item->next; + + if (*itemHead) + (*itemHead)->prev = NULL; + } + else if (item->next == NULL) // end of list + { + item->prev->next = NULL; + } + else // Somewhere in between + { + item->prev->next = item->next; + item->next->prev = item->prev; + } + + Z_Free (item); +} + +// +// ListRemoveAll +// +// Removes all items from the list, freeing their memory. +// +void ListRemoveAll(listitem_t **itemHead) +{ + listitem_t *item; + listitem_t *next; + for (item = *itemHead; item; item = next) + { + next = item->next; + ListRemove(item, itemHead); + } +} + +// +// ListRemoveNoFree +// +// Take an item out of the list, but don't free its memory. +// +void ListRemoveNoFree(void *pItem, listitem_t **itemHead) +{ + listitem_t *item = (listitem_t*)pItem; + + if (item == *itemHead) // Start of list + { + *itemHead = item->next; + + if (*itemHead) + (*itemHead)->prev = NULL; + } + else if (item->next == NULL) // end of list + { + item->prev->next = NULL; + } + else // Somewhere in between + { + item->prev->next = item->next; + item->next->prev = item->prev; + } +} + +// +// ListGetCount +// +// Counts the # of items in a list +// Should not be used in performance-minded code +// +unsigned int ListGetCount(void *itemHead) +{ + listitem_t *item = (listitem_t*)itemHead; + + unsigned int count = 0; + for (; item; item = item->next) + count++; + + return count; +} + +// +// ListGetByIndex +// +// Gets an item in the list by its index +// Should not be used in performance-minded code +// +listitem_t *ListGetByIndex(void *itemHead, unsigned int index) +{ + listitem_t *head = (listitem_t*)itemHead; + unsigned int count = 0; + listitem_t *node; + for (node = head; node; node = node->next) + { + if (count == index) + return node; + + count++; + } + + return NULL; +} diff --git a/src/hardware/u_list.h b/src/hardware/u_list.h new file mode 100644 index 000000000..7e9a3cabd --- /dev/null +++ b/src/hardware/u_list.h @@ -0,0 +1,29 @@ +/* + From the 'Wizard2' engine by Spaddlewit Inc. ( http://www.spaddlewit.com ) + An experimental work-in-progress. + + Donated to Sonic Team Junior and adapted to work with + Sonic Robo Blast 2. The license of this code matches whatever + the licensing is for Sonic Robo Blast 2. +*/ + +#ifndef _U_LIST_H_ +#define _U_LIST_H_ + +typedef struct listitem_s +{ + struct listitem_s *next; + struct listitem_s *prev; +} listitem_t; + +void ListAdd(void *pItem, listitem_t **itemHead); +void ListAddFront(void *pItem, listitem_t **itemHead); +void ListAddBefore(void *pItem, void *pSpot, listitem_t **itemHead); +void ListAddAfter(void *pItem, void *pSpot, listitem_t **itemHead); +void ListRemove(void *pItem, listitem_t **itemHead); +void ListRemoveAll(listitem_t **itemHead); +void ListRemoveNoFree(void *pItem, listitem_t **itemHead); +unsigned int ListGetCount(void *itemHead); +listitem_t *ListGetByIndex(void *itemHead, unsigned int index); + +#endif diff --git a/src/sdl/Srb2SDL-vc10.vcxproj b/src/sdl/Srb2SDL-vc10.vcxproj index df582865c..a51661380 100644 --- a/src/sdl/Srb2SDL-vc10.vcxproj +++ b/src/sdl/Srb2SDL-vc10.vcxproj @@ -156,6 +156,10 @@ + + + + @@ -294,8 +298,12 @@ + + + + @@ -304,7 +312,7 @@ - + diff --git a/src/sdl/Srb2SDL-vc10.vcxproj.filters b/src/sdl/Srb2SDL-vc10.vcxproj.filters index 09287436d..d789a61fe 100644 --- a/src/sdl/Srb2SDL-vc10.vcxproj.filters +++ b/src/sdl/Srb2SDL-vc10.vcxproj.filters @@ -246,6 +246,18 @@ Hw_Hardware + + Hw_Hardware + + + Hw_Hardware + + + Hw_Hardware + + + Hw_Hardware + I_Interface @@ -624,9 +636,21 @@ Hw_Hardware + + Hw_Hardware + + + Hw_Hardware + + + Hw_Hardware + Hw_Hardware + + Hw_Hardware + I_Interface diff --git a/src/sdl/hwsym_sdl.c b/src/sdl/hwsym_sdl.c index 05ac6450e..7962e01b1 100644 --- a/src/sdl/hwsym_sdl.c +++ b/src/sdl/hwsym_sdl.c @@ -87,8 +87,7 @@ void *hwSym(const char *funcName,void *handle) GETFUNC(ClearMipMapCache); GETFUNC(SetSpecialState); GETFUNC(GetTextureUsed); - GETFUNC(DrawMD2); - GETFUNC(DrawMD2i); + GETFUNC(DrawModel); GETFUNC(SetTransform); GETFUNC(GetRenderVersion); #ifdef SHUFFLE diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 78dfc820c..336a709df 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -1546,8 +1546,7 @@ void I_StartupGraphics(void) HWD.pfnSetSpecialState = hwSym("SetSpecialState",NULL); HWD.pfnSetPalette = hwSym("SetPalette",NULL); HWD.pfnGetTextureUsed = hwSym("GetTextureUsed",NULL); - HWD.pfnDrawMD2 = hwSym("DrawMD2",NULL); - HWD.pfnDrawMD2i = hwSym("DrawMD2i",NULL); + HWD.pfnDrawModel = hwSym("DrawModel",NULL); HWD.pfnSetTransform = hwSym("SetTransform",NULL); HWD.pfnGetRenderVersion = hwSym("GetRenderVersion",NULL); #ifdef SHUFFLE diff --git a/src/win32/Srb2win-vc10.vcxproj b/src/win32/Srb2win-vc10.vcxproj index 5bfa29b8c..3056b975a 100644 --- a/src/win32/Srb2win-vc10.vcxproj +++ b/src/win32/Srb2win-vc10.vcxproj @@ -124,7 +124,11 @@ + + + + @@ -132,7 +136,7 @@ - + @@ -287,6 +291,10 @@ + + + + diff --git a/src/win32/Srb2win-vc10.vcxproj.filters b/src/win32/Srb2win-vc10.vcxproj.filters index d20dd672b..1a2a7f80d 100644 --- a/src/win32/Srb2win-vc10.vcxproj.filters +++ b/src/win32/Srb2win-vc10.vcxproj.filters @@ -108,9 +108,21 @@ Hw_Hardware + + Hw_Hardware + + + Hw_Hardware + + + Hw_Hardware + Hw_Hardware + + Hw_Hardware + Hw_Hardware @@ -506,6 +518,15 @@ Hw_Hardware + + Hw_Hardware + + + Hw_Hardware + + + Hw_Hardware + Hw_Hardware @@ -515,6 +536,9 @@ Hw_Hardware + + Hw_Hardware + BLUA diff --git a/src/win32/win_dll.c b/src/win32/win_dll.c index 71eda0437..bc67f04a5 100644 --- a/src/win32/win_dll.c +++ b/src/win32/win_dll.c @@ -109,8 +109,7 @@ static loadfunc_t hwdFuncTable[] = { {"GClipRect@20", &hwdriver.pfnGClipRect}, {"ClearMipMapCache@0", &hwdriver.pfnClearMipMapCache}, {"SetSpecialState@8", &hwdriver.pfnSetSpecialState}, - {"DrawMD2@16", &hwdriver.pfnDrawMD2}, - {"DrawMD2i@36", &hwdriver.pfnDrawMD2i}, + {"DrawModel@16", &hwdriver.pfnDrawModel}, {"SetTransform@4", &hwdriver.pfnSetTransform}, {"GetTextureUsed@0", &hwdriver.pfnGetTextureUsed}, {"GetRenderVersion@0", &hwdriver.pfnGetRenderVersion}, @@ -140,8 +139,7 @@ static loadfunc_t hwdFuncTable[] = { {"GClipRect", &hwdriver.pfnGClipRect}, {"ClearMipMapCache", &hwdriver.pfnClearMipMapCache}, {"SetSpecialState", &hwdriver.pfnSetSpecialState}, - {"DrawMD2", &hwdriver.pfnDrawMD2}, - {"DrawMD2i", &hwdriver.pfnDrawMD2i}, + {"DrawModel", &hwdriver.pfnDrawModel}, {"SetTransform", &hwdriver.pfnSetTransform}, {"GetTextureUsed", &hwdriver.pfnGetTextureUsed}, {"GetRenderVersion", &hwdriver.pfnGetRenderVersion}, From 797023102bfc4a467e8139a33dffeb7783717f05 Mon Sep 17 00:00:00 2001 From: Arthur Date: Sun, 16 Dec 2018 12:04:10 -0500 Subject: [PATCH 03/66] Support for 'tinyframes', and lots more optimization --- src/hardware/hw_drv.h | 2 +- src/hardware/hw_md2.c | 5 +- src/hardware/hw_md2load.c | 16 +-- src/hardware/hw_md3load.c | 68 +++++---- src/hardware/r_opengl/r_opengl.c | 228 +++++++++++++++++++------------ 5 files changed, 183 insertions(+), 136 deletions(-) diff --git a/src/hardware/hw_drv.h b/src/hardware/hw_drv.h index 0afd6d272..7b45b0974 100644 --- a/src/hardware/hw_drv.h +++ b/src/hardware/hw_drv.h @@ -58,7 +58,7 @@ EXPORT void HWRAPI(ClearMipMapCache) (void); EXPORT void HWRAPI(SetSpecialState) (hwdspecialstate_t IdState, INT32 Value); //Hurdler: added for new development -EXPORT void HWRAPI(DrawModel) (model_t *model, mdlframe_t *frame, INT32 duration, INT32 tics, mdlframe_t *nextframe, FTransform *pos, float scale, UINT8 flipped, UINT8 *color); +EXPORT void HWRAPI(DrawModel) (model_t *model, INT32 frameIndex, INT32 duration, INT32 tics, INT32 nextFrameIndex, FTransform *pos, float scale, UINT8 flipped, UINT8 *color); EXPORT void HWRAPI(SetTransform) (FTransform *ptransform); EXPORT INT32 HWRAPI(GetTextureUsed) (void); EXPORT INT32 HWRAPI(GetRenderVersion) (void); diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.c index 5d865c5ae..10517b7e0 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -832,7 +832,8 @@ void HWR_DrawMD2(gr_vissprite_t *spr) FSurfaceInfo Surf; char filename[64]; - INT32 frame; + INT32 frame = 0; + INT32 nextFrame = -1; FTransform p; md2_t *md2; UINT8 color[4]; @@ -1074,7 +1075,7 @@ void HWR_DrawMD2(gr_vissprite_t *spr) p.flip = atransform.flip; p.mirror = atransform.mirror; - HWD.pfnDrawModel(md2->model, curr, durs, tics, next, &p, finalscale, flip, color); + HWD.pfnDrawModel(md2->model, frame, durs, tics, nextFrame, &p, finalscale, flip, color); } } diff --git a/src/hardware/hw_md2load.c b/src/hardware/hw_md2load.c index 3b083fee4..998dc70b6 100644 --- a/src/hardware/hw_md2load.c +++ b/src/hardware/hw_md2load.c @@ -233,8 +233,6 @@ typedef struct // Load the model model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) { - useFloat = true; // Right now we always useFloat = true, because the GL subsystem needs some work for the other option to work. - model_t *retModel = NULL; md2header_t *header; @@ -397,17 +395,17 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) framePtr--; for (j = 0; j < header->numXYZ; j++, vertex++) { - *vertptr = (short)(((vertex->v[1] * framePtr->scale[1]) + framePtr->translate[1]) / dataScale); + *vertptr = (short)(((vertex->v[0] * framePtr->scale[0]) + framePtr->translate[0]) / dataScale); vertptr++; *vertptr = (short)(((vertex->v[2] * framePtr->scale[2]) + framePtr->translate[2]) / dataScale); vertptr++; - *vertptr = (short)(((vertex->v[0] * framePtr->scale[0]) + framePtr->translate[0]) / dataScale); + *vertptr = -1.0f * (short)(((vertex->v[1] * framePtr->scale[1]) + framePtr->translate[1]) / dataScale); vertptr++; // Normal + *normptr++ = (byte)(avertexnormals[vertex->lightNormalIndex][0] * 127); *normptr++ = (byte)(avertexnormals[vertex->lightNormalIndex][1] * 127); *normptr++ = (byte)(avertexnormals[vertex->lightNormalIndex][2] * 127); - *normptr++ = (byte)(avertexnormals[vertex->lightNormalIndex][0] * 127); } } @@ -419,17 +417,17 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) { *indexptr = trisPtr->meshIndex[0]; indexptr++; - *indexptr = trisPtr->meshIndex[2]; - indexptr++; *indexptr = trisPtr->meshIndex[1]; indexptr++; + *indexptr = trisPtr->meshIndex[2]; + indexptr++; + uvptr[trisPtr->meshIndex[0] * 2] = texcoords[trisPtr->stIndex[0]].s / (float)header->skinwidth; + uvptr[trisPtr->meshIndex[0] * 2 + 1] = (texcoords[trisPtr->stIndex[0]].t / (float)header->skinheight); uvptr[trisPtr->meshIndex[1] * 2] = texcoords[trisPtr->stIndex[1]].s / (float)header->skinwidth; uvptr[trisPtr->meshIndex[1] * 2 + 1] = (texcoords[trisPtr->stIndex[1]].t / (float)header->skinheight); uvptr[trisPtr->meshIndex[2] * 2] = texcoords[trisPtr->stIndex[2]].s / (float)header->skinwidth; uvptr[trisPtr->meshIndex[2] * 2 + 1] = (texcoords[trisPtr->stIndex[2]].t / (float)header->skinheight); - uvptr[trisPtr->meshIndex[0] * 2] = texcoords[trisPtr->stIndex[0]].s / (float)header->skinwidth; - uvptr[trisPtr->meshIndex[0] * 2 + 1] = (texcoords[trisPtr->stIndex[0]].t / (float)header->skinheight); } } else // Full float loading method diff --git a/src/hardware/hw_md3load.c b/src/hardware/hw_md3load.c index bac799cdb..87a2f6ed1 100644 --- a/src/hardware/hw_md3load.c +++ b/src/hardware/hw_md3load.c @@ -144,8 +144,6 @@ static bool latlnginit = false; model_t *MD3_LoadModel(const char *fileName, int ztag, boolean useFloat) { - useFloat = true; // Right now we always useFloat = true, because the GL subsystem needs some work for the other option to work. - if (!latlnginit) { LatLngInit(); @@ -307,20 +305,20 @@ model_t *MD3_LoadModel(const char *fileName, int ztag, boolean useFloat) for (k = 0; k < mdS->numVerts; k++) { // Vertex - *vertptr = mdV[k].y; + *vertptr = mdV[k].x; vertptr++; *vertptr = mdV[k].z; vertptr++; - *vertptr = mdV[k].x; + *vertptr = 1.0f - mdV[k].y; vertptr++; // Normal GetNormalFromLatLong(mdV[k].n, tempNormal); - *normptr = (byte)(tempNormal[1] * 127); + *normptr = (byte)(tempNormal[0] * 127); normptr++; *normptr = (byte)(tempNormal[2] * 127); normptr++; - *normptr = (byte)(tempNormal[0] * 127); + *normptr = (byte)(tempNormal[1] * 127); normptr++; } } @@ -331,7 +329,7 @@ model_t *MD3_LoadModel(const char *fileName, int ztag, boolean useFloat) { *uvptr = mdST[j].st[0]; uvptr++; - *uvptr = 1.0f - mdST[j].st[1]; + *uvptr = mdST[j].st[1]; uvptr++; } @@ -342,10 +340,10 @@ model_t *MD3_LoadModel(const char *fileName, int ztag, boolean useFloat) // Indices *indexptr = (unsigned short)mdT->index[0]; indexptr++; - *indexptr = (unsigned short)mdT->index[2]; - indexptr++; *indexptr = (unsigned short)mdT->index[1]; indexptr++; + *indexptr = (unsigned short)mdT->index[2]; + indexptr++; } } else // Traditional full-float loading method @@ -377,48 +375,48 @@ model_t *MD3_LoadModel(const char *fileName, int ztag, boolean useFloat) vertptr++; *vertptr = mdV[mdT->index[0]].z * dataScale; vertptr++; - *vertptr = mdV[mdT->index[0]].y * dataScale; + *vertptr = 1.0f - mdV[mdT->index[0]].y * dataScale; vertptr++; GetNormalFromLatLong(mdV[mdT->index[0]].n, tempNormal); - *normptr = tempNormal[1]; + *normptr = tempNormal[0]; normptr++; *normptr = tempNormal[2]; normptr++; - *normptr = tempNormal[0]; + *normptr = tempNormal[1]; normptr++; // Vertex 2 - *vertptr = mdV[mdT->index[2]].x * dataScale; - vertptr++; - *vertptr = mdV[mdT->index[2]].z * dataScale; - vertptr++; - *vertptr = mdV[mdT->index[2]].y * dataScale; - vertptr++; - - GetNormalFromLatLong(mdV[mdT->index[2]].n, tempNormal); - *normptr = tempNormal[1]; - normptr++; - *normptr = tempNormal[2]; - normptr++; - *normptr = tempNormal[0]; - normptr++; - - // Vertex 3 *vertptr = mdV[mdT->index[1]].x * dataScale; vertptr++; *vertptr = mdV[mdT->index[1]].z * dataScale; vertptr++; - *vertptr = mdV[mdT->index[1]].y * dataScale; + *vertptr = 1.0f - mdV[mdT->index[1]].y * dataScale; vertptr++; GetNormalFromLatLong(mdV[mdT->index[1]].n, tempNormal); - *normptr = tempNormal[1]; + *normptr = tempNormal[0]; normptr++; *normptr = tempNormal[2]; normptr++; + *normptr = tempNormal[1]; + normptr++; + + // Vertex 3 + *vertptr = mdV[mdT->index[2]].x * dataScale; + vertptr++; + *vertptr = mdV[mdT->index[2]].z * dataScale; + vertptr++; + *vertptr = 1.0f - mdV[mdT->index[2]].y * dataScale; + vertptr++; + + GetNormalFromLatLong(mdV[mdT->index[2]].n, tempNormal); *normptr = tempNormal[0]; normptr++; + *normptr = tempNormal[2]; + normptr++; + *normptr = tempNormal[1]; + normptr++; mdT++; // Advance to next triangle } @@ -436,16 +434,16 @@ model_t *MD3_LoadModel(const char *fileName, int ztag, boolean useFloat) *uvptr = mdST[mdT->index[0]].st[1]; uvptr++; - *uvptr = mdST[mdT->index[2]].st[0]; - uvptr++; - *uvptr = mdST[mdT->index[2]].st[1]; - uvptr++; - *uvptr = mdST[mdT->index[1]].st[0]; uvptr++; *uvptr = mdST[mdT->index[1]].st[1]; uvptr++; + *uvptr = mdST[mdT->index[2]].st[0]; + uvptr++; + *uvptr = mdST[mdT->index[2]].st[1]; + uvptr++; + mdT++; // Advance to next triangle } } diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index f8b324ed0..dbf9649d4 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -241,14 +241,18 @@ FUNCPRINTF void DBG_Printf(const char *lpFmt, ...) #define pglBegin glBegin #define pglEnd glEnd #define pglVertex3f glVertex3f +#define pglVertex3sv glVertex3sv #define pglNormal3f glNormal3f +#define pglNormal3bv glNormal3bv #define pglColor4f glColor4f #define pglColor4fv glColor4fv #define pglTexCoord2f glTexCoord2f +#define pglTexCoord2fv glTexCoord2fv #define pglVertexPointer glVertexPointer #define pglNormalPointer glNormalPointer #define pglTexCoordPointer glTexCoordPointer #define pglDrawArrays glDrawArrays +#define pglDrawElements glDrawElements #define pglEnableClientState glEnableClientState #define pglDisableClientState pglDisableClientState @@ -355,14 +359,20 @@ typedef void (APIENTRY * PFNglEnd) (void); static PFNglEnd pglEnd; typedef void (APIENTRY * PFNglVertex3f) (GLfloat x, GLfloat y, GLfloat z); static PFNglVertex3f pglVertex3f; +typedef void (APIENTRY * PFNglVertex3sv) (const GLshort *v); +static PFNglVertex3sv pglVertex3sv; typedef void (APIENTRY * PFNglNormal3f) (GLfloat x, GLfloat y, GLfloat z); static PFNglNormal3f pglNormal3f; +typedef void (APIENTRY * PFNglNormal3bv)(const GLbyte *v); +static PFNglNormal3bv pglNormal3bv; typedef void (APIENTRY * PFNglColor4f) (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); static PFNglColor4f pglColor4f; typedef void (APIENTRY * PFNglColor4fv) (const GLfloat *v); static PFNglColor4fv pglColor4fv; typedef void (APIENTRY * PFNglTexCoord2f) (GLfloat s, GLfloat t); static PFNglTexCoord2f pglTexCoord2f; +typedef void (APIENTRY * PFNglTexCoord2fv) (const GLfloat *v); +static PFNglTexCoord2fv pglTexCoord2fv; typedef void (APIENTRY * PFNglVertexPointer) (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); static PFNglVertexPointer pglVertexPointer; typedef void (APIENTRY * PFNglNormalPointer) (GLenum type, GLsizei stride, const GLvoid *pointer); @@ -371,6 +381,8 @@ typedef void (APIENTRY * PFNglTexCoordPointer) (GLint size, GLenum type, GLsizei static PFNglTexCoordPointer pglTexCoordPointer; typedef void (APIENTRY * PFNglDrawArrays) (GLenum mode, GLint first, GLsizei count); static PFNglDrawArrays pglDrawArrays; +typedef void (APIENTRY * PFNglDrawElements) (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices); +static PFNglDrawElements pglDrawElements; typedef void (APIENTRY * PFNglEnableClientState) (GLenum cap); static PFNglEnableClientState pglEnableClientState; typedef void (APIENTRY * PFNglDisableClientState) (GLenum cap); @@ -509,14 +521,18 @@ boolean SetupGLfunc(void) GETOPENGLFUNC(pglBegin , glBegin) GETOPENGLFUNC(pglEnd , glEnd) GETOPENGLFUNC(pglVertex3f , glVertex3f) + GETOPENGLFUNC(pglVertex3sv, glVertex3sv) GETOPENGLFUNC(pglNormal3f , glNormal3f) + GETOPENGLFUNC(pglNormal3bv, glNomral3bv) GETOPENGLFUNC(pglColor4f , glColor4f) GETOPENGLFUNC(pglColor4fv , glColor4fv) GETOPENGLFUNC(pglTexCoord2f , glTexCoord2f) + GETOPENGLFUNC(pglTexCoord2fv, glTexCoord2fv) GETOPENGLFUNC(pglVertexPointer, glVertexPointer) GETOPENGLFUNC(pglNormalPointer, glNormalPointer) GETOPENGLFUNC(pglTexCoordPointer, glTexCoordPointer) GETOPENGLFUNC(pglDrawArrays, glDrawArrays) + GETOPENGLFUNC(pglDrawElements, glDrawElements) GETOPENGLFUNC(pglEnableClientState, glEnableClientState) GETOPENGLFUNC(pglDisableClientState, glDisableClientState) @@ -1902,7 +1918,7 @@ EXPORT void HWRAPI(SetSpecialState) (hwdspecialstate_t IdState, INT32 Value) } } -static void DrawModelEx(model_t *model, mdlframe_t *frame, INT32 duration, INT32 tics, mdlframe_t *nextframe, FTransform *pos, float scale, UINT8 flipped, UINT8 *color) +static void DrawModelEx(model_t *model, INT32 frameIndex, INT32 duration, INT32 tics, INT32 nextFrameIndex, FTransform *pos, float scale, UINT8 flipped, UINT8 *color) { INT32 val, count, pindex; GLfloat s, t; @@ -1993,105 +2009,139 @@ static void DrawModelEx(model_t *model, mdlframe_t *frame, INT32 duration, INT32 pglScalef(scalex, scaley, scalez); - mesh_t *mesh = &model->meshes[0]; + boolean useTinyFrames = model->meshes[0].tinyframes != NULL; - if (!nextframe || pol == 0.0f) + if (useTinyFrames) + pglScalef(1 / 64.0f, 1 / 64.0f, 1 / 64.0f); + + for (int i = 0; i < model->numMeshes; i++) { - // Zoom! Take advantage of just shoving the entire arrays to the GPU. - pglEnableClientState(GL_VERTEX_ARRAY); - pglEnableClientState(GL_TEXTURE_COORD_ARRAY); - pglEnableClientState(GL_NORMAL_ARRAY); - pglVertexPointer(3, GL_FLOAT, 0, frame->vertices); - pglNormalPointer(GL_FLOAT, 0, frame->normals); - pglTexCoordPointer(2, GL_FLOAT, 0, mesh->uvs); - pglDrawArrays(GL_TRIANGLES, 0, mesh->numTriangles * 3); - pglDisableClientState(GL_NORMAL_ARRAY); - pglDisableClientState(GL_TEXTURE_COORD_ARRAY); - pglDisableClientState(GL_TEXTURE_COORD_ARRAY); - /* - pglBegin(GL_TRIANGLES); + mesh_t *mesh = &model->meshes[i]; - int i = 0; - float *uvPtr = mesh->uvs; - float *frameVert = frame->vertices; - float *frameNormal = frame->normals; - for (i = 0; i < mesh->numTriangles; i++) + if (useTinyFrames) { - float uvx = *uvPtr++; - float uvy = *uvPtr++; + tinyframe_t *frame = &mesh->tinyframes[frameIndex % mesh->numFrames]; + tinyframe_t *nextframe = NULL; - // Interpolate - float px1 = *frameVert++; - float py1 = *frameVert++; - float pz1 = *frameVert++; - float nx1 = *frameNormal++; - float ny1 = *frameNormal++; - float nz1 = *frameNormal++; + if (nextFrameIndex != -1) + nextframe = &mesh->tinyframes[nextFrameIndex % mesh->numFrames]; - pglTexCoord2f(uvx, uvy); - pglNormal3f(nx1, ny1, nz1); - pglVertex3f(px1, py1, pz1); + if (!nextframe || pol == 0.0f) + { + pglEnableClientState(GL_VERTEX_ARRAY); + pglEnableClientState(GL_TEXTURE_COORD_ARRAY); + pglEnableClientState(GL_NORMAL_ARRAY); + pglVertexPointer(3, GL_SHORT, 0, frame->vertices); + pglNormalPointer(GL_BYTE, 0, frame->normals); + pglTexCoordPointer(2, GL_FLOAT, 0, mesh->uvs); + pglDrawElements(GL_TRIANGLES, mesh->numTriangles * 3, GL_UNSIGNED_SHORT, mesh->indices); + pglDisableClientState(GL_NORMAL_ARRAY); + pglDisableClientState(GL_TEXTURE_COORD_ARRAY); + pglDisableClientState(GL_TEXTURE_COORD_ARRAY); + } + else + { + // Dangit, I soooo want to do this in a GLSL shader... + pglBegin(GL_TRIANGLES); + + short *buffer = malloc(mesh->numVertices * sizeof(short)); + short *vertPtr = buffer; + char *normBuffer = malloc(mesh->numVertices * sizeof(char)); + char *normPtr = normBuffer; + + int j = 0; + for (j = 0; j < mesh->numVertices; j++) + { + // Interpolate + *vertPtr++ = (short)(frame->vertices[j] + (pol * (nextframe->vertices[j] - frame->vertices[j]))); + *normPtr++ = (short)(frame->normals[j] + (pol * (nextframe->normals[j] - frame->normals[j]))); + } + + float *uvPtr = mesh->uvs; + vertPtr = buffer; + normPtr = normBuffer; + for (j = 0; j < mesh->numTriangles; j++) + { + pglTexCoord2fv(uvPtr); + pglNormal3bv(normPtr); + pglVertex3sv(vertPtr); + + uvPtr += 2; + normPtr += 3; + vertPtr += 3; + } + + free(buffer); + free(normBuffer); + + pglEnd(); + } } - - pglEnd();*/ - } - else - { - // Dangit, I soooo want to do this in a GLSL shader... - pglBegin(GL_TRIANGLES); - - int i = 0; - float *uvPtr = mesh->uvs; - float *frameVert = frame->vertices; - float *frameNormal = frame->normals; - float *nextFrameVert = nextframe->vertices; - float *nextFrameNormal = frame->normals; - for (i = 0; i < mesh->numTriangles; i++) + else { - float uvx = *uvPtr++; - float uvy = *uvPtr++; + mdlframe_t *frame = &mesh->frames[frameIndex % mesh->numFrames]; + mdlframe_t *nextframe = NULL; - // Interpolate - float px1 = *frameVert++; - float px2 = *nextFrameVert++; - float py1 = *frameVert++; - float py2 = *nextFrameVert++; - float pz1 = *frameVert++; - float pz2 = *nextFrameVert++; - float nx1 = *frameNormal++; - float nx2 = *nextFrameNormal++; - float ny1 = *frameNormal++; - float ny2 = *nextFrameNormal++; - float nz1 = *frameNormal++; - float nz2 = *nextFrameNormal++; + if (nextFrameIndex != -1) + nextframe = &mesh->frames[nextFrameIndex % mesh->numFrames]; - pglTexCoord2f(uvx, uvy); - pglNormal3f((nx1 + pol * (nx2 - nx1)), - (ny1 + pol * (ny2 - ny1)), - (nz1 + pol * (nz2 - nz1))); - pglVertex3f((px1 + pol * (px2 - px1)), - (py1 + pol * (py2 - py1)), - (pz1 + pol * (pz2 - pz1))); + if (!nextframe || pol == 0.0f) + { + // Zoom! Take advantage of just shoving the entire arrays to the GPU. + pglEnableClientState(GL_VERTEX_ARRAY); + pglEnableClientState(GL_TEXTURE_COORD_ARRAY); + pglEnableClientState(GL_NORMAL_ARRAY); + pglVertexPointer(3, GL_FLOAT, 0, frame->vertices); + pglNormalPointer(GL_FLOAT, 0, frame->normals); + pglTexCoordPointer(2, GL_FLOAT, 0, mesh->uvs); + pglDrawArrays(GL_TRIANGLES, 0, mesh->numTriangles * 3); + pglDisableClientState(GL_NORMAL_ARRAY); + pglDisableClientState(GL_TEXTURE_COORD_ARRAY); + pglDisableClientState(GL_TEXTURE_COORD_ARRAY); + } + else + { + // Dangit, I soooo want to do this in a GLSL shader... + pglBegin(GL_TRIANGLES); + + int j = 0; + float *uvPtr = mesh->uvs; + float *frameVert = frame->vertices; + float *frameNormal = frame->normals; + float *nextFrameVert = nextframe->vertices; + float *nextFrameNormal = frame->normals; + for (j = 0; j < mesh->numTriangles; j++) + { + // Interpolate + float px1 = *frameVert++; + float px2 = *nextFrameVert++; + float py1 = *frameVert++; + float py2 = *nextFrameVert++; + float pz1 = *frameVert++; + float pz2 = *nextFrameVert++; + float nx1 = *frameNormal++; + float nx2 = *nextFrameNormal++; + float ny1 = *frameNormal++; + float ny2 = *nextFrameNormal++; + float nz1 = *frameNormal++; + float nz2 = *nextFrameNormal++; + + pglTexCoord2fv(uvPtr); + pglNormal3f((nx1 + pol * (nx2 - nx1)), + (ny1 + pol * (ny2 - ny1)), + (nz1 + pol * (nz2 - nz1))); + pglVertex3f((px1 + pol * (px2 - px1)), + (py1 + pol * (py2 - py1)), + (pz1 + pol * (pz2 - pz1))); + + uvPtr++; + } + + pglEnd(); + } } - - pglEnd(); } -/* if (lightType != LIGHT_NONE) - { - glVertexAttribPointer(program->slots[Shaders::A_NORMAL_SLOT], 3, BGL_FLOAT, BGL_FALSE, 0, frame->normals); - // if (normalmapped) - // bglVertexAttribPointer(program->slots[Shaders::A_TANGENT_SLOT], 3, BGL_FLOAT, BGL_FALSE, 0, frame->tangents); - } - - if (frame->colors) - glVertexAttribPointer(program->slots[Shaders::A_COLOR_SLOT], 4, GL_UNSIGNED_BYTE, BGL_TRUE, 0, frame->colors); - else - { - SetGlobalWhiteColorArray(mesh->numTriangles * 3); - glVertexAttribPointer(program->slots[Shaders::A_COLOR_SLOT], 3, BGL_UNSIGNED_BYTE, BGL_TRUE, 0, globalWhiteColorArray); - } - */ pglPopMatrix(); // should be the same as glLoadIdentity if (color) pglDisable(GL_LIGHTING); @@ -2102,9 +2152,9 @@ static void DrawModelEx(model_t *model, mdlframe_t *frame, INT32 duration, INT32 // -----------------+ // HWRAPI DrawMD2 : Draw an MD2 model with glcommands // -----------------+ -EXPORT void HWRAPI(DrawModel) (model_t *model, mdlframe_t *frame, INT32 duration, INT32 tics, mdlframe_t *nextframe, FTransform *pos, float scale, UINT8 flipped, UINT8 *color) +EXPORT void HWRAPI(DrawModel) (model_t *model, INT32 frameIndex, INT32 duration, INT32 tics, INT32 nextFrameIndex, FTransform *pos, float scale, UINT8 flipped, UINT8 *color) { - DrawModelEx(model, frame, duration, tics, nextframe, pos, scale, flipped, color); + DrawModelEx(model, frameIndex, duration, tics, nextFrameIndex, pos, scale, flipped, color); } // -----------------+ From ee2d105308e7e33213cd840934c9a8cebf528dcc Mon Sep 17 00:00:00 2001 From: Arthur Date: Sun, 16 Dec 2018 15:24:17 -0500 Subject: [PATCH 04/66] Remove CONS_Printf message that isn't even doing what it says it is! --- src/hardware/hw_model.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hardware/hw_model.c b/src/hardware/hw_model.c index 73b2b484b..495c8c109 100644 --- a/src/hardware/hw_model.c +++ b/src/hardware/hw_model.c @@ -320,7 +320,7 @@ model_t *LoadModel(const char *filename, int ztag) material->shininess = 25.0f; } - CONS_Printf("Generating VBOs for %s\n", filename); +// CONS_Printf("Generating VBOs for %s\n", filename); for (i = 0; i < model->numMeshes; i++) { mesh_t *mesh = &model->meshes[i]; From 3f2208bda2095f7a6d9f5a7482ff533b3ae2b458 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Tue, 18 Dec 2018 17:57:39 -0500 Subject: [PATCH 05/66] Add MD2/MD3 files to makefile --- src/Makefile | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/Makefile b/src/Makefile index a2279a94d..753bfab46 100644 --- a/src/Makefile +++ b/src/Makefile @@ -277,7 +277,8 @@ ifndef DC endif OPTS+=-DHWRENDER OBJS+=$(OBJDIR)/hw_bsp.o $(OBJDIR)/hw_draw.o $(OBJDIR)/hw_light.o \ - $(OBJDIR)/hw_main.o $(OBJDIR)/hw_clip.o $(OBJDIR)/hw_md2.o $(OBJDIR)/hw_cache.o $(OBJDIR)/hw_trick.o + $(OBJDIR)/hw_main.o $(OBJDIR)/hw_clip.o $(OBJDIR)/hw_md2.o $(OBJDIR)/hw_cache.o $(OBJDIR)/hw_trick.o \ + $(OBJDIR)/hw_md2load.o $(OBJDIR)/hw_md3load.o $(OBJDIR)/hw_model.o $(OBJDIR)/u_list.o endif ifdef NOHS @@ -728,16 +729,18 @@ ifdef MINGW $(OBJDIR)/r_opengl.o: hardware/r_opengl/r_opengl.c hardware/r_opengl/r_opengl.h \ doomdef.h doomtype.h g_state.h m_swap.h hardware/hw_drv.h screen.h \ command.h hardware/hw_data.h hardware/hw_glide.h hardware/hw_defs.h \ - hardware/hw_md2.h hardware/hw_glob.h hardware/hw_main.h hardware/hw_clip.h am_map.h \ - d_event.h d_player.h p_pspr.h m_fixed.h tables.h info.h d_think.h \ + hardware/hw_md2.h hardware/hw_glob.h hardware/hw_main.h hardware/hw_clip.h \ + hardware/hw_md2load.h hardware/hw_md3load.h hardware/hw_model.h hardware/u_list.h \ + am_map.h d_event.h d_player.h p_pspr.h m_fixed.h tables.h info.h d_think.h \ p_mobj.h doomdata.h d_ticcmd.h r_defs.h hardware/hw_dll.h $(CC) $(CFLAGS) $(WFLAGS) -c $< -o $@ else $(OBJDIR)/r_opengl.o: hardware/r_opengl/r_opengl.c hardware/r_opengl/r_opengl.h \ doomdef.h doomtype.h g_state.h m_swap.h hardware/hw_drv.h screen.h \ command.h hardware/hw_data.h hardware/hw_glide.h hardware/hw_defs.h \ - hardware/hw_md2.h hardware/hw_glob.h hardware/hw_main.h hardware/hw_clip.h am_map.h \ - d_event.h d_player.h p_pspr.h m_fixed.h tables.h info.h d_think.h \ + hardware/hw_md2.h hardware/hw_glob.h hardware/hw_main.h hardware/hw_clip.h \ + hardware/hw_md2load.h hardware/hw_md3load.h hardware/hw_model.h hardware/u_list.h \ + am_map.h d_event.h d_player.h p_pspr.h m_fixed.h tables.h info.h d_think.h \ p_mobj.h doomdata.h d_ticcmd.h r_defs.h hardware/hw_dll.h $(CC) $(CFLAGS) $(WFLAGS) -I/usr/X11R6/include -c $< -o $@ endif @@ -889,24 +892,27 @@ ifndef NOHW $(OBJDIR)/r_opengl.o: hardware/r_opengl/r_opengl.c hardware/r_opengl/r_opengl.h \ doomdef.h doomtype.h g_state.h m_swap.h hardware/hw_drv.h screen.h \ command.h hardware/hw_data.h hardware/hw_glide.h hardware/hw_defs.h \ - hardware/hw_md2.h hardware/hw_glob.h hardware/hw_main.h hardware/hw_clip.h am_map.h \ - d_event.h d_player.h p_pspr.h m_fixed.h tables.h info.h d_think.h \ + hardware/hw_md2.h hardware/hw_glob.h hardware/hw_main.h hardware/hw_clip.h \ + hardware/hw_md2load.h hardware/hw_md3load.h hardware/hw_model.h hardware/u_list.h \ + am_map.h d_event.h d_player.h p_pspr.h m_fixed.h tables.h info.h d_think.h \ p_mobj.h doomdata.h d_ticcmd.h r_defs.h hardware/hw_dll.h $(CC) $(CFLAGS) $(WFLAGS) -D_WINDOWS -mwindows -c $< -o $@ $(OBJDIR)/ogl_win.o: hardware/r_opengl/ogl_win.c hardware/r_opengl/r_opengl.h \ doomdef.h doomtype.h g_state.h m_swap.h hardware/hw_drv.h screen.h \ command.h hardware/hw_data.h hardware/hw_glide.h hardware/hw_defs.h \ - hardware/hw_md2.h hardware/hw_glob.h hardware/hw_main.h hardware/hw_clip.h am_map.h \ - d_event.h d_player.h p_pspr.h m_fixed.h tables.h info.h d_think.h \ + hardware/hw_md2.h hardware/hw_glob.h hardware/hw_main.h hardware/hw_clip.h \ + hardware/hw_md2load.h hardware/hw_md3load.h hardware/hw_model.h hardware/u_list.h \ + am_map.h d_event.h d_player.h p_pspr.h m_fixed.h tables.h info.h d_think.h \ p_mobj.h doomdata.h d_ticcmd.h r_defs.h hardware/hw_dll.h $(CC) $(CFLAGS) $(WFLAGS) -D_WINDOWS -mwindows -c $< -o $@ $(OBJDIR)/r_minigl.o: hardware/r_minigl/r_minigl.c hardware/r_opengl/r_opengl.h \ doomdef.h doomtype.h g_state.h m_swap.h hardware/hw_drv.h screen.h \ command.h hardware/hw_data.h hardware/hw_glide.h hardware/hw_defs.h \ - hardware/hw_md2.h hardware/hw_glob.h hardware/hw_main.h hardware/hw_clip.h am_map.h \ - d_event.h d_player.h p_pspr.h m_fixed.h tables.h info.h d_think.h \ + hardware/hw_md2.h hardware/hw_glob.h hardware/hw_main.h hardware/hw_clip.h \ + hardware/hw_md2load.h hardware/hw_md3load.h hardware/hw_model.h hardware/u_list.h \ + am_map.h d_event.h d_player.h p_pspr.h m_fixed.h tables.h info.h d_think.h \ p_mobj.h doomdata.h d_ticcmd.h r_defs.h hardware/hw_dll.h $(CC) $(CFLAGS) $(WFLAGS) -D_WINDOWS -mwindows -c $< -o $@ endif From 43089535d558447150b2eba0b58f28e535478b51 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Tue, 18 Dec 2018 19:17:33 -0500 Subject: [PATCH 06/66] GCC compile fixes --- src/hardware/hw_md2.c | 107 +------------------------------ src/hardware/hw_md3load.c | 8 ++- src/hardware/hw_model.c | 19 ++++-- src/hardware/hw_model.h | 2 +- src/hardware/r_opengl/r_opengl.c | 10 ++- 5 files changed, 25 insertions(+), 121 deletions(-) diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.c index 10517b7e0..b9ff29578 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -83,10 +83,12 @@ md2_t md2_playermodels[MAXSKINS]; /* * free model */ +#if 0 static void md2_freeModel (model_t *model) { UnloadModel(model); } +#endif // @@ -832,11 +834,7 @@ void HWR_DrawMD2(gr_vissprite_t *spr) FSurfaceInfo Surf; char filename[64]; - INT32 frame = 0; - INT32 nextFrame = -1; - FTransform p; md2_t *md2; - UINT8 color[4]; if (!cv_grmd2.value) return; @@ -881,17 +879,6 @@ void HWR_DrawMD2(gr_vissprite_t *spr) // Look at HWR_ProjectSprite for more { GLPatch_t *gpatch; - INT32 durs = spr->mobj->state->tics; - INT32 tics = spr->mobj->tics; - mdlframe_t *curr, *next = NULL; - const UINT8 flip = (UINT8)((spr->mobj->eflags & MFE_VERTICALFLIP) == MFE_VERTICALFLIP); - spritedef_t *sprdef; - spriteframe_t *sprframe; - float finalscale; - - // Apparently people don't like jump frames like that, so back it goes - //if (tics > durs) - //durs = tics; if (spr->mobj->flags2 & MF2_SHADOW) Surf.FlatColor.s.alpha = 0x40; @@ -933,7 +920,6 @@ void HWR_DrawMD2(gr_vissprite_t *spr) } } //HWD.pfnSetBlend(blend); // This seems to actually break translucency? - finalscale = md2->scale; //Hurdler: arf, I don't like that implementation at all... too much crappy gpatch = md2->grpatch; if (!gpatch || !gpatch->mipmap.grInfo.format || !gpatch->mipmap.downloaded) @@ -987,95 +973,6 @@ void HWR_DrawMD2(gr_vissprite_t *spr) gpatch = W_CachePatchNum(spr->patchlumpnum, PU_CACHE); HWR_GetMappedPatch(gpatch, spr->colormap); } - - if (spr->mobj->frame & FF_ANIMATE) - { - // set duration and tics to be the correct values for FF_ANIMATE states - durs = spr->mobj->state->var2; - tics = spr->mobj->anim_duration; - } - - //FIXME: this is not yet correct - frame = (spr->mobj->frame & FF_FRAMEMASK) % md2->model->meshes[0].numFrames; - curr = &md2->model->meshes[0].frames[frame]; -#if 0 - if (cv_grmd2.value == 1 && tics <= durs) - { - // frames are handled differently for states with FF_ANIMATE, so get the next frame differently for the interpolation - if (spr->mobj->frame & FF_ANIMATE) - { - UINT32 nextframe = (spr->mobj->frame & FF_FRAMEMASK) + 1; - if (nextframe >= (UINT32)spr->mobj->state->var1) - nextframe = (spr->mobj->state->frame & FF_FRAMEMASK); - nextframe %= md2->model->header.numFrames; - next = &md2->model->frames[nextframe]; - } - else - { - if (spr->mobj->state->nextstate != S_NULL && states[spr->mobj->state->nextstate].sprite != SPR_NULL) - { - const UINT32 nextframe = (states[spr->mobj->state->nextstate].frame & FF_FRAMEMASK) % md2->model->header.numFrames; - next = &md2->model->frames[nextframe]; - } - } - } -#endif - - //Hurdler: it seems there is still a small problem with mobj angle - p.x = FIXED_TO_FLOAT(spr->mobj->x); - p.y = FIXED_TO_FLOAT(spr->mobj->y)+md2->offset; - - if (spr->mobj->eflags & MFE_VERTICALFLIP) - p.z = FIXED_TO_FLOAT(spr->mobj->z + spr->mobj->height); - else - p.z = FIXED_TO_FLOAT(spr->mobj->z); - - if (spr->mobj->skin && spr->mobj->sprite == SPR_PLAY) - sprdef = &((skin_t *)spr->mobj->skin)->spritedef; - else - sprdef = &sprites[spr->mobj->sprite]; - - sprframe = &sprdef->spriteframes[spr->mobj->frame & FF_FRAMEMASK]; - - if (sprframe->rotate) - { - fixed_t anglef; - if (spr->mobj->player) - anglef = AngleFixed(spr->mobj->player->frameangle); - else - anglef = AngleFixed(spr->mobj->angle); - p.angley = FIXED_TO_FLOAT(anglef); - } - else - { - const fixed_t anglef = AngleFixed((R_PointToAngle(spr->mobj->x, spr->mobj->y))-ANGLE_180); - p.angley = FIXED_TO_FLOAT(anglef); - } - p.anglex = 0.0f; - p.anglez = 0.0f; - if (spr->mobj->standingslope) - { - fixed_t tempz = spr->mobj->standingslope->normal.z; - fixed_t tempy = spr->mobj->standingslope->normal.y; - fixed_t tempx = spr->mobj->standingslope->normal.x; - fixed_t tempangle = AngleFixed(R_PointToAngle2(0, 0, FixedSqrt(FixedMul(tempy, tempy) + FixedMul(tempz, tempz)), tempx)); - p.anglez = FIXED_TO_FLOAT(tempangle); - tempangle = -AngleFixed(R_PointToAngle2(0, 0, tempz, tempy)); - p.anglex = FIXED_TO_FLOAT(tempangle); - } - - color[0] = Surf.FlatColor.s.red; - color[1] = Surf.FlatColor.s.green; - color[2] = Surf.FlatColor.s.blue; - color[3] = Surf.FlatColor.s.alpha; - - // SRB2CBTODO: MD2 scaling support - finalscale *= FIXED_TO_FLOAT(spr->mobj->scale); - - p.flip = atransform.flip; - p.mirror = atransform.mirror; - - HWD.pfnDrawModel(md2->model, frame, durs, tics, nextFrame, &p, finalscale, flip, color); } } diff --git a/src/hardware/hw_md3load.c b/src/hardware/hw_md3load.c index 87a2f6ed1..1f1763ebd 100644 --- a/src/hardware/hw_md3load.c +++ b/src/hardware/hw_md3load.c @@ -95,6 +95,7 @@ static void GetNormalFromLatLong(short latlng, float *out) out[2] = *lookup++; } +#if 0 static void NormalToLatLng(float *n, short *out) { // Special cases @@ -115,6 +116,7 @@ static void NormalToLatLng(float *n, short *out) *out = (x << 8) + y; } } +#endif static inline void LatLngToNormal(short n, float *out) { @@ -140,7 +142,7 @@ static void LatLngInit(void) } } -static bool latlnginit = false; +static boolean latlnginit = false; model_t *MD3_LoadModel(const char *fileName, int ztag, boolean useFloat) { @@ -218,7 +220,7 @@ model_t *MD3_LoadModel(const char *fileName, int ztag, boolean useFloat) } retModel->meshes = (mesh_t*)Z_Calloc(sizeof(mesh_t)*retModel->numMeshes, ztag, 0); - + int matCount = 0; for (i = 0, surfEnd = 0; i < mdh->numSurfaces; i++) { @@ -236,7 +238,7 @@ model_t *MD3_LoadModel(const char *fileName, int ztag, boolean useFloat) // Load material /* retModel->materials[matCount].texture = Texture::ReadTexture(mdShader[j].name, ZT_TEXTURE); - + if (!systemSucks) { // Check for a normal map...?? diff --git a/src/hardware/hw_model.c b/src/hardware/hw_model.c index 495c8c109..f0c6f283b 100644 --- a/src/hardware/hw_model.c +++ b/src/hardware/hw_model.c @@ -16,7 +16,7 @@ #include static float PI = (3.1415926535897932384626433832795f); -float U_Deg2Rad(float deg) +static float U_Deg2Rad(float deg) { return deg * ((float)PI / 180.0f); } @@ -49,11 +49,13 @@ void VectorRotate(vector_t *rotVec, const vector_t *axisVec, float angle) void CreateVBOTiny(mesh_t *mesh, tinyframe_t *frame) { + (void)mesh; + (void)frame; return; /* int bufferSize = sizeof(VBO::vbotiny_t)*mesh->numTriangles*3; VBO::vbotiny_t *buffer = (VBO::vbotiny_t*)Z_Malloc(bufferSize, PU_STATIC, 0); VBO::vbotiny_t *bufPtr = buffer; - + short *vertPtr = frame->vertices; char *normPtr = frame->normals; float *uvPtr = mesh->uvs; @@ -91,6 +93,8 @@ void CreateVBOTiny(mesh_t *mesh, tinyframe_t *frame) void CreateVBO(mesh_t *mesh, mdlframe_t *frame) { + (void)mesh; + (void)frame; return; /* int bufferSize = sizeof(VBO::vbo64_t)*mesh->numTriangles*3; VBO::vbo64_t *buffer = (VBO::vbo64_t*)Z_Malloc(bufferSize, PU_STATIC, 0); @@ -161,7 +165,7 @@ void UnloadModel(model_t *model) for (i = 0; i < model->numMeshes; i++) { mesh_t *mesh = &model->meshes[i]; - + if (mesh->frames) { int j; @@ -450,7 +454,7 @@ typedef struct materiallist_s material_t *material; } materiallist_t; -static bool AddMaterialToList(materiallist_t **head, material_t *material) +static boolean AddMaterialToList(materiallist_t **head, material_t *material) { materiallist_t *node; for (node = *head; node; node = node->next) @@ -619,7 +623,7 @@ void GeneratePolygonNormals(model_t *model, int ztag) for (i = 0; i < model->numMeshes; i++) { mesh_t *mesh = &model->meshes[i]; - + if (!mesh->frames) continue; @@ -648,7 +652,8 @@ void GeneratePolygonNormals(model_t *model, int ztag) // // Reload VBOs // -void Reload(void) +#if 0 +static void Reload(void) { /* model_t *node; for (node = modelHead; node; node = node->next) @@ -673,9 +678,11 @@ void Reload(void) } }*/ } +#endif void DeleteVBOs(model_t *model) { + (void)model; /* for (int i = 0; i < model->numMeshes; i++) { mesh_t *mesh = &model->meshes[i]; diff --git a/src/hardware/hw_model.h b/src/hardware/hw_model.h index ed7e41a55..34e83731f 100644 --- a/src/hardware/hw_model.h +++ b/src/hardware/hw_model.h @@ -27,7 +27,7 @@ typedef struct { float ambient[4], diffuse[4], specular[4], emissive[4]; float shininess; - bool spheremap; + boolean spheremap; // Texture::texture_t *texture; // Texture::texture_t *lightmap; } material_t; diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index dbf9649d4..a36563ef7 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -1919,9 +1919,7 @@ EXPORT void HWRAPI(SetSpecialState) (hwdspecialstate_t IdState, INT32 Value) } static void DrawModelEx(model_t *model, INT32 frameIndex, INT32 duration, INT32 tics, INT32 nextFrameIndex, FTransform *pos, float scale, UINT8 flipped, UINT8 *color) -{ - INT32 val, count, pindex; - GLfloat s, t; +{ GLfloat ambient[4]; GLfloat diffuse[4]; @@ -2062,9 +2060,9 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, INT32 duration, INT32 normPtr = normBuffer; for (j = 0; j < mesh->numTriangles; j++) { - pglTexCoord2fv(uvPtr); - pglNormal3bv(normPtr); - pglVertex3sv(vertPtr); + pglTexCoord2fv((const GLfloat*) uvPtr); + pglNormal3bv((const GLbyte*) normPtr); + pglVertex3sv((const GLshort*) vertPtr); uvPtr += 2; normPtr += 3; From 6b9ddf47fb8b48a5ac4db839db26f73ef775700a Mon Sep 17 00:00:00 2001 From: mazmazz Date: Tue, 18 Dec 2018 19:31:30 -0500 Subject: [PATCH 07/66] Buildbot fixes (changed byte types to char; mixed d&c) --- src/hardware/hw_md2load.c | 89 ++++++++++++++++----------- src/hardware/hw_md3load.c | 86 +++++++++++++++----------- src/hardware/hw_model.c | 102 ++++++++++++++++++------------- src/hardware/hw_model.h | 2 +- src/hardware/r_opengl/r_opengl.c | 45 +++++++++----- 5 files changed, 197 insertions(+), 127 deletions(-) diff --git a/src/hardware/hw_md2load.c b/src/hardware/hw_md2load.c index 998dc70b6..1fdfefb97 100644 --- a/src/hardware/hw_md2load.c +++ b/src/hardware/hw_md2load.c @@ -17,7 +17,7 @@ #define NUMVERTEXNORMALS 162 -// Quake 2 normals are indexed. Use avertexnormals[normalindex][x/y/z] and +// Quake 2 normals are indexed. Use avertexnormals[normalindex][x/y/z] and // you'll have your normals. float avertexnormals[NUMVERTEXNORMALS][3] = { {-0.525731f, 0.000000f, 0.850651f}, @@ -195,9 +195,9 @@ typedef struct int numXYZ; // Number of vertices in each frame int numST; // Number of texture coordinates in each frame. int numTris; // Number of triangles in each frame - int numGLcmds; // Number of dwords (4 bytes) in the gl command list. + int numGLcmds; // Number of dwords (4 bytes) in the gl command list. int numFrames; // Number of frames - int offsetSkins; // Offset, in bytes from the start of the file, to the list of skin names. + int offsetSkins; // Offset, in bytes from the start of the file, to the list of skin names. int offsetST; // Offset, in bytes from the start of the file, to the list of texture coordinates int offsetTris; // Offset, in bytes from the start of the file, to the list of triangles int offsetFrames; // Offset, in bytes from the start of the file, to the list of frames @@ -236,6 +236,20 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) model_t *retModel = NULL; md2header_t *header; + size_t fileLen; + int i, j, t; + + size_t namelen; + char *texturefilename, *buffer; + const char *texPos; + + const float WUNITS = 1.0f; + float dataScale; + + md2triangle_t *tris; + md2texcoord_t *texcoords; + md2frame_t *frames; + FILE *f = fopen(fileName, "rb"); if (!f) @@ -243,12 +257,7 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) retModel = (model_t*)Z_Calloc(sizeof(model_t), ztag, 0); - size_t fileLen; - int i, j; - - size_t namelen; - char *texturefilename; - const char *texPos = strchr(fileName, '/'); + texPos = strchr(fileName, '/'); if (texPos) { @@ -274,7 +283,7 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) fseek(f, 0, SEEK_SET); // read in file - char *buffer = malloc(fileLen); + buffer = malloc(fileLen); fread(buffer, fileLen, 1, f); fclose(f); @@ -284,13 +293,13 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) retModel->numMeshes = 1; // MD2 only has one mesh retModel->meshes = (mesh_t*)Z_Calloc(sizeof(mesh_t) * retModel->numMeshes, ztag, 0); retModel->meshes[0].numFrames = header->numFrames; - const float WUNITS = 1.0f; - float dataScale = WUNITS; + + dataScale = WUNITS; // Tris and ST are simple structures that can be straight-copied - md2triangle_t *tris = (md2triangle_t*)&buffer[header->offsetTris]; - md2texcoord_t *texcoords = (md2texcoord_t*)&buffer[header->offsetST]; - md2frame_t *frames = (md2frame_t*)&buffer[header->offsetFrames]; + tris = (md2triangle_t*)&buffer[header->offsetTris]; + texcoords = (md2texcoord_t*)&buffer[header->offsetST]; + frames = (md2frame_t*)&buffer[header->offsetFrames]; // Read in textures retModel->numMaterials = header->numSkins; @@ -300,7 +309,6 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) retModel->materials = (material_t*)Z_Calloc(sizeof(material_t)*retModel->numMaterials, ztag, 0); - int t; for (t = 0; t < retModel->numMaterials; t++) { retModel->materials[t].ambient[0] = 0.8f; @@ -327,6 +335,7 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) if (!systemSucks) { // Check for a normal map...?? + Resource::resource_t *res char openfilename[1024]; char normalMapName[1024]; strcpy(normalMapName, texturefilename); @@ -355,7 +364,7 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) openfilename[k] = '/'; } - Resource::resource_t *res = Resource::Open(openfilename); + res = Resource::Open(openfilename); if (res) { Resource::Close(res); @@ -368,15 +377,24 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) if (!useFloat) // Decompress to MD3 'tinyframe' space { + char *ptr = (char*)frames; + md2triangle_t *trisPtr; + unsigned short *indexptr; + float *uvptr; + dataScale = 0.015624f; // 1 / 64.0f retModel->meshes[0].tinyframes = (tinyframe_t*)Z_Calloc(sizeof(tinyframe_t)*header->numFrames, ztag, 0); retModel->meshes[0].numVertices = header->numXYZ; retModel->meshes[0].uvs = (float*)Z_Malloc (sizeof(float)*2*retModel->meshes[0].numVertices, ztag, 0); - byte *ptr = (byte*)frames; for (i = 0; i < header->numFrames; i++, ptr += header->framesize) { + short *vertptr; + char *normptr; + //char *tanptr; md2frame_t *framePtr = (md2frame_t*)ptr; + md2vertex_t *vertex; + retModel->meshes[0].tinyframes[i].vertices = (short*)Z_Malloc(sizeof(short)*3*header->numXYZ, ztag, 0); retModel->meshes[0].tinyframes[i].normals = (char*)Z_Malloc(sizeof(char)*3*header->numXYZ, ztag, 0); @@ -384,14 +402,14 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) // retModel->meshes[0].tinyframes[i].tangents = (char*)malloc(sizeof(char));//(char*)Z_Malloc(sizeof(char)*3*header->numVerts, ztag); retModel->meshes[0].indices = (unsigned short*)Z_Malloc(sizeof(unsigned short) * 3 * header->numTris, ztag, 0); - short *vertptr = retModel->meshes[0].tinyframes[i].vertices; - char *normptr = retModel->meshes[0].tinyframes[i].normals; + vertptr = retModel->meshes[0].tinyframes[i].vertices; + normptr = retModel->meshes[0].tinyframes[i].normals; -// char *tanptr = retModel->meshes[0].tinyframes[i].tangents; +// tanptr = retModel->meshes[0].tinyframes[i].tangents; retModel->meshes[0].tinyframes[i].material = &retModel->materials[0]; framePtr++; // Advance to vertex list - md2vertex_t *vertex = (md2vertex_t*)framePtr; + vertex = (md2vertex_t*)framePtr; framePtr--; for (j = 0; j < header->numXYZ; j++, vertex++) { @@ -403,16 +421,16 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) vertptr++; // Normal - *normptr++ = (byte)(avertexnormals[vertex->lightNormalIndex][0] * 127); - *normptr++ = (byte)(avertexnormals[vertex->lightNormalIndex][1] * 127); - *normptr++ = (byte)(avertexnormals[vertex->lightNormalIndex][2] * 127); + *normptr++ = (char)(avertexnormals[vertex->lightNormalIndex][0] * 127); + *normptr++ = (char)(avertexnormals[vertex->lightNormalIndex][1] * 127); + *normptr++ = (char)(avertexnormals[vertex->lightNormalIndex][2] * 127); } } // This doesn't need to be done every frame! - md2triangle_t *trisPtr = tris; - unsigned short *indexptr = retModel->meshes[0].indices; - float *uvptr = (float*)retModel->meshes[0].uvs; + trisPtr = tris; + indexptr = retModel->meshes[0].indices; + uvptr = (float*)retModel->meshes[0].uvs; for (j = 0; j < header->numTris; j++, trisPtr++) { *indexptr = trisPtr->meshIndex[0]; @@ -432,12 +450,14 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) } else // Full float loading method { + md2triangle_t *trisPtr = tris; + float *uvptr = retModel->meshes[0].uvs; + char *ptr = (char*)frames; + retModel->meshes[0].numVertices = header->numTris*3; retModel->meshes[0].frames = (mdlframe_t*)Z_Calloc(sizeof(mdlframe_t)*header->numFrames, ztag, 0); retModel->meshes[0].uvs = (float*)Z_Malloc(sizeof(float)*2*retModel->meshes[0].numVertices, ztag, 0); - md2triangle_t *trisPtr = tris; - float *uvptr = retModel->meshes[0].uvs; for (i = 0; i < retModel->meshes[0].numTriangles; i++, trisPtr++) { *uvptr++ = texcoords[trisPtr->stIndex[0]].s / (float)header->skinwidth; @@ -448,23 +468,24 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) *uvptr++ = (texcoords[trisPtr->stIndex[2]].t / (float)header->skinheight); } - byte *ptr = (byte*)frames; for (i = 0; i < header->numFrames; i++, ptr += header->framesize) { + md2vertex_t *vertex; md2frame_t *framePtr = (md2frame_t*)ptr; + float *vertptr, *normptr; retModel->meshes[0].frames[i].normals = (float*)Z_Malloc(sizeof(float)*3*header->numTris*3, ztag, 0); retModel->meshes[0].frames[i].vertices = (float*)Z_Malloc(sizeof(float)*3*header->numTris*3, ztag, 0); // if (retModel->materials[0].lightmap) // retModel->meshes[0].frames[i].tangents = (float*)malloc(sizeof(float));//(float*)Z_Malloc(sizeof(float)*3*header->numTris*3, ztag); - float *vertptr, *normptr; + normptr = (float*)retModel->meshes[0].frames[i].normals; vertptr = (float*)retModel->meshes[0].frames[i].vertices; trisPtr = tris; - + retModel->meshes[0].frames[i].material = &retModel->materials[0]; framePtr++; // Advance to vertex list - md2vertex_t *vertex = (md2vertex_t*)framePtr; + vertex = (md2vertex_t*)framePtr; framePtr--; for (j = 0; j < header->numTris; j++, trisPtr++) { diff --git a/src/hardware/hw_md3load.c b/src/hardware/hw_md3load.c index 1f1763ebd..35c6abf29 100644 --- a/src/hardware/hw_md3load.c +++ b/src/hardware/hw_md3load.c @@ -146,31 +146,36 @@ static boolean latlnginit = false; model_t *MD3_LoadModel(const char *fileName, int ztag, boolean useFloat) { + const float WUNITS = 1.0f; + model_t *retModel = NULL; + md3modelHeader *mdh; + long fileLen; + char *buffer; + int surfEnd; + int i, t; + int matCount; + FILE *f; + if (!latlnginit) { LatLngInit(); latlnginit = true; } - const float WUNITS = 1.0f; - model_t *retModel = NULL; - - FILE *f = fopen(fileName, "rb"); + f = fopen(fileName, "rb"); if (!f) return NULL; retModel = (model_t*)Z_Calloc(sizeof(model_t), ztag, 0); - md3modelHeader *mdh; - // find length of file fseek(f, 0, SEEK_END); - long fileLen = ftell(f); + fileLen = ftell(f); fseek(f, 0, SEEK_SET); // read in file - char *buffer = malloc(fileLen); + buffer = malloc(fileLen); fread(buffer, fileLen, 1, f); fclose(f); @@ -180,8 +185,7 @@ model_t *MD3_LoadModel(const char *fileName, int ztag, boolean useFloat) retModel->numMeshes = mdh->numSurfaces; retModel->numMaterials = 0; - int surfEnd = 0; - int i; + surfEnd = 0; for (i = 0; i < mdh->numSurfaces; i++) { md3Surface *mdS = (md3Surface*)&buffer[mdh->offsetSurfaces]; @@ -196,7 +200,6 @@ model_t *MD3_LoadModel(const char *fileName, int ztag, boolean useFloat) retModel->materials = (material_t*)Z_Calloc(sizeof(material_t)*retModel->numMaterials, ztag, 0); - int t; for (t = 0; t < retModel->numMaterials; t++) { retModel->materials[t].ambient[0] = 0.3686f; @@ -221,14 +224,16 @@ model_t *MD3_LoadModel(const char *fileName, int ztag, boolean useFloat) retModel->meshes = (mesh_t*)Z_Calloc(sizeof(mesh_t)*retModel->numMeshes, ztag, 0); - int matCount = 0; + matCount = 0; for (i = 0, surfEnd = 0; i < mdh->numSurfaces; i++) { + int j; + md3Shader *mdShader; md3Surface *mdS = (md3Surface*)&buffer[mdh->offsetSurfaces + surfEnd]; surfEnd += mdS->offsetEnd; - md3Shader *mdShader = (md3Shader*)((char*)mdS + mdS->offsetShaders); - int j; + mdShader = (md3Shader*)((char*)mdS + mdS->offsetShaders); + for (j = 0; j < mdS->numShaders; j++, matCount++) { size_t len = strlen(mdShader[j].name); @@ -285,11 +290,20 @@ model_t *MD3_LoadModel(const char *fileName, int ztag, boolean useFloat) if (!useFloat) // 'tinyframe' mode with indices { float tempNormal[3]; + float *uvptr; + md3TexCoord *mdST; + unsigned short *indexptr; + md3Triangle *mdT; + retModel->meshes[i].tinyframes = (tinyframe_t*)Z_Calloc(sizeof(tinyframe_t)*mdS->numFrames, ztag, 0); retModel->meshes[i].numVertices = mdS->numVerts; retModel->meshes[i].uvs = (float*)Z_Malloc(sizeof(float)*2*mdS->numVerts, ztag, 0); for (j = 0; j < mdS->numFrames; j++) { + short *vertptr; + char *normptr; + // char *tanptr; + int k; md3Vertex *mdV = (md3Vertex*)((char*)mdS + mdS->offsetXYZNormal + (mdS->numVerts*j*sizeof(md3Vertex))); retModel->meshes[i].tinyframes[j].vertices = (short*)Z_Malloc(sizeof(short)*3*mdS->numVerts, ztag, 0); retModel->meshes[i].tinyframes[j].normals = (char*)Z_Malloc(sizeof(char)*3*mdS->numVerts, ztag, 0); @@ -297,13 +311,12 @@ model_t *MD3_LoadModel(const char *fileName, int ztag, boolean useFloat) // if (retModel->materials[0].lightmap) // retModel->meshes[i].tinyframes[j].tangents = (char*)malloc(sizeof(char));//(char*)Z_Malloc(sizeof(char)*3*mdS->numVerts, ztag); retModel->meshes[i].indices = (unsigned short*)Z_Malloc(sizeof(unsigned short) * 3 * mdS->numTriangles, ztag, 0); - short *vertptr = retModel->meshes[i].tinyframes[j].vertices; - char *normptr = retModel->meshes[i].tinyframes[j].normals; + vertptr = retModel->meshes[i].tinyframes[j].vertices; + normptr = retModel->meshes[i].tinyframes[j].normals; -// char *tanptr = retModel->meshes[i].tinyframes[j].tangents; +// tanptr = retModel->meshes[i].tinyframes[j].tangents; retModel->meshes[i].tinyframes[j].material = &retModel->materials[i]; - int k; for (k = 0; k < mdS->numVerts; k++) { // Vertex @@ -316,17 +329,17 @@ model_t *MD3_LoadModel(const char *fileName, int ztag, boolean useFloat) // Normal GetNormalFromLatLong(mdV[k].n, tempNormal); - *normptr = (byte)(tempNormal[0] * 127); + *normptr = (char)(tempNormal[0] * 127); normptr++; - *normptr = (byte)(tempNormal[2] * 127); + *normptr = (char)(tempNormal[2] * 127); normptr++; - *normptr = (byte)(tempNormal[1] * 127); + *normptr = (char)(tempNormal[1] * 127); normptr++; } } - float *uvptr = (float*)retModel->meshes[i].uvs; - md3TexCoord *mdST = (md3TexCoord*)((char*)mdS + mdS->offsetST); + uvptr = (float*)retModel->meshes[i].uvs; + mdST = (md3TexCoord*)((char*)mdS + mdS->offsetST); for (j = 0; j < mdS->numVerts; j++) { *uvptr = mdST[j].st[0]; @@ -335,8 +348,8 @@ model_t *MD3_LoadModel(const char *fileName, int ztag, boolean useFloat) uvptr++; } - unsigned short *indexptr = retModel->meshes[i].indices; - md3Triangle *mdT = (md3Triangle*)((char*)mdS + mdS->offsetTriangles); + indexptr = retModel->meshes[i].indices; + mdT = (md3Triangle*)((char*)mdS + mdS->offsetTriangles); for (j = 0; j < mdS->numTriangles; j++, mdT++) { // Indices @@ -350,25 +363,31 @@ model_t *MD3_LoadModel(const char *fileName, int ztag, boolean useFloat) } else // Traditional full-float loading method { - retModel->meshes[i].numVertices = mdS->numTriangles * 3;//mdS->numVerts; float dataScale = 0.015624f * WUNITS; float tempNormal[3]; + md3TexCoord *mdST; + md3Triangle *mdT; + float *uvptr; + int k; + + retModel->meshes[i].numVertices = mdS->numTriangles * 3;//mdS->numVerts; retModel->meshes[i].frames = (mdlframe_t*)Z_Calloc(sizeof(mdlframe_t)*mdS->numFrames, ztag, 0); retModel->meshes[i].uvs = (float*)Z_Malloc(sizeof(float)*2*mdS->numTriangles*3, ztag, 0); for (j = 0; j < mdS->numFrames; j++) { + float *vertptr; + float *normptr; md3Vertex *mdV = (md3Vertex*)((char*)mdS + mdS->offsetXYZNormal + (mdS->numVerts*j*sizeof(md3Vertex))); retModel->meshes[i].frames[j].vertices = (float*)Z_Malloc(sizeof(float)*3*mdS->numTriangles*3, ztag, 0); retModel->meshes[i].frames[j].normals = (float*)Z_Malloc(sizeof(float)*3*mdS->numTriangles*3, ztag, 0); // if (retModel->materials[i].lightmap) // retModel->meshes[i].frames[j].tangents = (float*)malloc(sizeof(float));//(float*)Z_Malloc(sizeof(float)*3*mdS->numTriangles*3, ztag); - float *vertptr = retModel->meshes[i].frames[j].vertices; - float *normptr = retModel->meshes[i].frames[j].normals; + vertptr = retModel->meshes[i].frames[j].vertices; + normptr = retModel->meshes[i].frames[j].normals; retModel->meshes[i].frames[j].material = &retModel->materials[i]; - int k; - md3Triangle *mdT = (md3Triangle*)((char*)mdS + mdS->offsetTriangles); + mdT = (md3Triangle*)((char*)mdS + mdS->offsetTriangles); for (k = 0; k < mdS->numTriangles; k++) { @@ -424,10 +443,9 @@ model_t *MD3_LoadModel(const char *fileName, int ztag, boolean useFloat) } } - md3TexCoord *mdST = (md3TexCoord*)((char*)mdS + mdS->offsetST); - float *uvptr = (float*)retModel->meshes[i].uvs; - int k; - md3Triangle *mdT = (md3Triangle*)((char*)mdS + mdS->offsetTriangles); + mdST = (md3TexCoord*)((char*)mdS + mdS->offsetST); + uvptr = (float*)retModel->meshes[i].uvs; + mdT = (md3Triangle*)((char*)mdS + mdS->offsetTriangles); for (k = 0; k < mdS->numTriangles; k++) { diff --git a/src/hardware/hw_model.c b/src/hardware/hw_model.c index f0c6f283b..828339563 100644 --- a/src/hardware/hw_model.c +++ b/src/hardware/hw_model.c @@ -27,20 +27,22 @@ vector_t vectorZaxis = { 0.0f, 0.0f, 1.0f }; void VectorRotate(vector_t *rotVec, const vector_t *axisVec, float angle) { + float ux, uy, uz, vx, vy, vz, wx, wy, wz, sa, ca; + angle = U_Deg2Rad(angle); // Rotate the point (x,y,z) around the vector (u,v,w) - float ux = axisVec->x * rotVec->x; - float uy = axisVec->x * rotVec->y; - float uz = axisVec->x * rotVec->z; - float vx = axisVec->y * rotVec->x; - float vy = axisVec->y * rotVec->y; - float vz = axisVec->y * rotVec->z; - float wx = axisVec->z * rotVec->x; - float wy = axisVec->z * rotVec->y; - float wz = axisVec->z * rotVec->z; - float sa = sinf(angle); - float ca = cosf(angle); + ux = axisVec->x * rotVec->x; + uy = axisVec->x * rotVec->y; + uz = axisVec->x * rotVec->z; + vx = axisVec->y * rotVec->x; + vy = axisVec->y * rotVec->y; + vz = axisVec->y * rotVec->z; + wx = axisVec->z * rotVec->x; + wy = axisVec->z * rotVec->y; + wz = axisVec->z * rotVec->z; + sa = sinf(angle); + ca = cosf(angle); rotVec->x = axisVec->x*(ux + vy + wz) + (rotVec->x*(axisVec->y*axisVec->y + axisVec->z*axisVec->z) - axisVec->x*(vy + wz))*ca + (-wy + vz)*sa; rotVec->y = axisVec->y*(ux + vy + wz) + (rotVec->y*(axisVec->x*axisVec->x + axisVec->z*axisVec->z) - axisVec->y*(ux + wz))*ca + (wx - uz)*sa; @@ -105,7 +107,7 @@ void CreateVBO(mesh_t *mesh, mdlframe_t *frame) float *tanPtr = frame->tangents; float *uvPtr = mesh->uvs; float *lightPtr = mesh->lightuvs; - byte *colorPtr = frame->colors; + char *colorPtr = frame->colors; int i; for (i = 0; i < mesh->numTriangles*3; i++) @@ -364,17 +366,22 @@ void GenerateVertexNormals(model_t *model) int i; for (i = 0; i < model->numMeshes; i++) { + int j; + mesh_t *mesh = &model->meshes[i]; if (!mesh->frames) continue; - int j; for (j = 0; j < mesh->numFrames; j++) { mdlframe_t *frame = &mesh->frames[j]; int memTag = PU_STATIC; float *newNormals = (float*)Z_Malloc(sizeof(float)*3*mesh->numTriangles*3, memTag, 0); + int k; + float *vertPtr = frame->vertices; + float *oldNormals; + M_Memcpy(newNormals, frame->normals, sizeof(float)*3*mesh->numTriangles*3); /* if (!systemSucks) @@ -384,20 +391,20 @@ void GenerateVertexNormals(model_t *model) M_Memcpy(newTangents, frame->tangents, sizeof(float)*3*mesh->numTriangles*3); }*/ - int k; - float *vertPtr = frame->vertices; for (k = 0; k < mesh->numVertices; k++) { float x, y, z; + int vCount = 0; + vector_t normal; + int l; + float *testPtr = frame->vertices; + x = *vertPtr++; y = *vertPtr++; z = *vertPtr++; - int vCount = 0; - vector_t normal; normal.x = normal.y = normal.z = 0; - int l; - float *testPtr = frame->vertices; + for (l = 0; l < mesh->numVertices; l++) { float testX, testY, testZ; @@ -433,7 +440,7 @@ void GenerateVertexNormals(model_t *model) } } - float *oldNormals = frame->normals; + oldNormals = frame->normals; frame->normals = newNormals; Z_Free(oldNormals); @@ -456,7 +463,7 @@ typedef struct materiallist_s static boolean AddMaterialToList(materiallist_t **head, material_t *material) { - materiallist_t *node; + materiallist_t *node, *newMatNode; for (node = *head; node; node = node->next) { if (node->material == material) @@ -464,7 +471,7 @@ static boolean AddMaterialToList(materiallist_t **head, material_t *material) } // Didn't find it, so add to the list - materiallist_t *newMatNode = (materiallist_t*)Z_Malloc(sizeof(materiallist_t), PU_CACHE, 0); + newMatNode = (materiallist_t*)Z_Malloc(sizeof(materiallist_t), PU_CACHE, 0); newMatNode->material = material; ListAdd(newMatNode, (listitem_t**)head); return true; @@ -478,12 +485,16 @@ static boolean AddMaterialToList(materiallist_t **head, material_t *material) // void Optimize(model_t *model) { - if (model->numMeshes <= 1) - return; // No need - int numMeshes = 0; int i; materiallist_t *matListHead = NULL; + int memTag; + mesh_t *newMeshes; + materiallist_t *node; + + if (model->numMeshes <= 1) + return; // No need + for (i = 0; i < model->numMeshes; i++) { mesh_t *curMesh = &model->meshes[i]; @@ -501,15 +512,18 @@ void Optimize(model_t *model) numMeshes++; } - int memTag = PU_STATIC; - mesh_t *newMeshes = (mesh_t*)Z_Calloc(sizeof(mesh_t) * numMeshes, memTag, 0); + memTag = PU_STATIC; + newMeshes = (mesh_t*)Z_Calloc(sizeof(mesh_t) * numMeshes, memTag, 0); i = 0; - materiallist_t *node; for (node = matListHead; node; node = node->next) { material_t *curMat = node->material; mesh_t *newMesh = &newMeshes[i]; + mdlframe_t *curFrame; + int uvCount; + int vertCount; + int colorCount; // Find all triangles with this material and count them int numTriangles = 0; @@ -529,20 +543,20 @@ void Optimize(model_t *model) // if (node->material->lightmap) // newMesh->lightuvs = (float*)Z_Malloc(sizeof(float)*2*numTriangles*3, memTag, 0); newMesh->frames = (mdlframe_t*)Z_Calloc(sizeof(mdlframe_t), memTag, 0); - mdlframe_t *curFrame = &newMesh->frames[0]; + curFrame = &newMesh->frames[0]; curFrame->material = curMat; curFrame->normals = (float*)Z_Malloc(sizeof(float)*3*numTriangles*3, memTag, 0); // if (!systemSucks) // curFrame->tangents = (float*)Z_Malloc(sizeof(float)*3*numTriangles*3, memTag, 0); curFrame->vertices = (float*)Z_Malloc(sizeof(float)*3*numTriangles*3, memTag, 0); - curFrame->colors = (byte*)Z_Malloc(sizeof(byte)*4*numTriangles*3, memTag, 0); + curFrame->colors = (char*)Z_Malloc(sizeof(char)*4*numTriangles*3, memTag, 0); // Now traverse the meshes of the model, adding in // vertices/normals/uvs that match the current material - int uvCount = 0; - int vertCount = 0; - int colorCount = 0; + uvCount = 0; + vertCount = 0; + colorCount = 0; for (j = 0; j < model->numMeshes; j++) { mesh_t *curMesh = &model->meshes[j]; @@ -551,6 +565,8 @@ void Optimize(model_t *model) { float *dest; float *src; + char *destByte; + char *srcByte; M_Memcpy(&newMesh->uvs[uvCount], curMesh->uvs, @@ -587,22 +603,20 @@ void Optimize(model_t *model) vertCount += 3 * curMesh->numTriangles * 3; - byte *destByte; - byte *srcByte; - destByte = (byte*)newMesh->frames[0].colors; - srcByte = (byte*)curMesh->frames[0].colors; + destByte = (char*)newMesh->frames[0].colors; + srcByte = (char*)curMesh->frames[0].colors; if (srcByte) { M_Memcpy(&destByte[colorCount], srcByte, - sizeof(byte)*4*curMesh->numTriangles*3); + sizeof(char)*4*curMesh->numTriangles*3); } else { memset(&destByte[colorCount], 255, - sizeof(byte)*4*curMesh->numTriangles*3); + sizeof(char)*4*curMesh->numTriangles*3); } colorCount += 4 * curMesh->numTriangles * 3; @@ -622,21 +636,23 @@ void GeneratePolygonNormals(model_t *model, int ztag) int i; for (i = 0; i < model->numMeshes; i++) { + int j; mesh_t *mesh = &model->meshes[i]; if (!mesh->frames) continue; - int j; for (j = 0; j < mesh->numFrames; j++) { + int k; mdlframe_t *frame = &mesh->frames[j]; + const float *vertices = frame->vertices; + vector_t *polyNormals; frame->polyNormals = (vector_t*)Z_Malloc(sizeof(vector_t) * mesh->numTriangles, ztag, 0); - const float *vertices = frame->vertices; - vector_t *polyNormals = frame->polyNormals; - int k; + polyNormals = frame->polyNormals; + for (k = 0; k < mesh->numTriangles; k++) { // Vector::Normal(vertices, polyNormals); diff --git a/src/hardware/hw_model.h b/src/hardware/hw_model.h index 34e83731f..1803f4c5c 100644 --- a/src/hardware/hw_model.h +++ b/src/hardware/hw_model.h @@ -38,7 +38,7 @@ typedef struct float *vertices; float *normals; float *tangents; - byte *colors; + char *colors; unsigned int vboID; vector_t *polyNormals; } mdlframe_t; diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index a36563ef7..e29c6a383 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -1924,14 +1924,19 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, INT32 duration, INT32 GLfloat diffuse[4]; float pol = 0.0f; - scale *= 0.5f; float scalex = scale, scaley = scale, scalez = scale; + boolean useTinyFrames; + + int i; + // Because Otherwise, scaling the screen negatively vertically breaks the lighting #ifndef KOS_GL_COMPATIBILITY GLfloat LightPos[] = {0.0f, 1.0f, 0.0f, 0.0f}; #endif + scale *= 0.5f; + if (duration != 0 && duration != -1 && tics != -1) // don't interpolate if instantaneous or infinite in length { UINT32 newtime = (duration - tics); // + 1; @@ -2007,12 +2012,12 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, INT32 duration, INT32 pglScalef(scalex, scaley, scalez); - boolean useTinyFrames = model->meshes[0].tinyframes != NULL; + useTinyFrames = model->meshes[0].tinyframes != NULL; if (useTinyFrames) pglScalef(1 / 64.0f, 1 / 64.0f, 1 / 64.0f); - for (int i = 0; i < model->numMeshes; i++) + for (i = 0; i < model->numMeshes; i++) { mesh_t *mesh = &model->meshes[i]; @@ -2039,15 +2044,19 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, INT32 duration, INT32 } else { + short *buffer, *vertPtr; + char *normBuffer, *normPtr; + float *uvPtr; + int j = 0; + // Dangit, I soooo want to do this in a GLSL shader... pglBegin(GL_TRIANGLES); - short *buffer = malloc(mesh->numVertices * sizeof(short)); - short *vertPtr = buffer; - char *normBuffer = malloc(mesh->numVertices * sizeof(char)); - char *normPtr = normBuffer; + buffer = malloc(mesh->numVertices * sizeof(short)); + vertPtr = buffer; + normBuffer = malloc(mesh->numVertices * sizeof(char)); + normPtr = normBuffer; - int j = 0; for (j = 0; j < mesh->numVertices; j++) { // Interpolate @@ -2055,7 +2064,7 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, INT32 duration, INT32 *normPtr++ = (short)(frame->normals[j] + (pol * (nextframe->normals[j] - frame->normals[j]))); } - float *uvPtr = mesh->uvs; + uvPtr = mesh->uvs; vertPtr = buffer; normPtr = normBuffer; for (j = 0; j < mesh->numTriangles; j++) @@ -2099,15 +2108,21 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, INT32 duration, INT32 } else { + int j = 0; + float *uvPtr; + float *frameVert; + float *frameNormal; + float *nextFrameVert; + float *nextFrameNormal; + // Dangit, I soooo want to do this in a GLSL shader... pglBegin(GL_TRIANGLES); - int j = 0; - float *uvPtr = mesh->uvs; - float *frameVert = frame->vertices; - float *frameNormal = frame->normals; - float *nextFrameVert = nextframe->vertices; - float *nextFrameNormal = frame->normals; + uvPtr = mesh->uvs; + frameVert = frame->vertices; + frameNormal = frame->normals; + nextFrameVert = nextframe->vertices; + nextFrameNormal = frame->normals; for (j = 0; j < mesh->numTriangles; j++) { // Interpolate From 3c496db7f540fc7931bc47ee6e27764f8c4c82e7 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Tue, 18 Dec 2018 20:36:39 -0500 Subject: [PATCH 08/66] Add new model files to CMake --- src/CMakeLists.txt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index faa860d44..97360b4f4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -395,7 +395,11 @@ if(${SRB2_CONFIG_HWRENDER}) ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_light.c ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_main.c ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_md2.c + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_md2load.c + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_md3load.c + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_model.c ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_trick.c + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/u_list.c ) set (SRB2_HWRENDER_HEADERS @@ -409,6 +413,10 @@ if(${SRB2_CONFIG_HWRENDER}) ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_light.h ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_main.h ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_md2.h + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_md2load.h + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_md3load.h + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_model.h + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/u_list.h ) set(SRB2_R_OPENGL_SOURCES From b9b99cc6be5ee05a43028b8342add46157cf46fe Mon Sep 17 00:00:00 2001 From: mazmazz Date: Tue, 18 Dec 2018 20:41:08 -0500 Subject: [PATCH 09/66] Ignore fread return value (buildbot error) --- src/hardware/hw_md2load.c | 5 ++++- src/hardware/hw_md3load.c | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/hardware/hw_md2load.c b/src/hardware/hw_md2load.c index 1fdfefb97..ff195dda5 100644 --- a/src/hardware/hw_md2load.c +++ b/src/hardware/hw_md2load.c @@ -237,6 +237,7 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) md2header_t *header; size_t fileLen; + size_t fileReadLen; int i, j, t; size_t namelen; @@ -284,9 +285,11 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) // read in file buffer = malloc(fileLen); - fread(buffer, fileLen, 1, f); + fileReadLen = fread(buffer, fileLen, 1, f); fclose(f); + (void)fileReadLen; // intentionally ignore return value, per buildbot + // get pointer to file header header = (md2header_t*)buffer; diff --git a/src/hardware/hw_md3load.c b/src/hardware/hw_md3load.c index 35c6abf29..53f6034c0 100644 --- a/src/hardware/hw_md3load.c +++ b/src/hardware/hw_md3load.c @@ -150,6 +150,7 @@ model_t *MD3_LoadModel(const char *fileName, int ztag, boolean useFloat) model_t *retModel = NULL; md3modelHeader *mdh; long fileLen; + long fileReadLen; char *buffer; int surfEnd; int i, t; @@ -176,9 +177,11 @@ model_t *MD3_LoadModel(const char *fileName, int ztag, boolean useFloat) // read in file buffer = malloc(fileLen); - fread(buffer, fileLen, 1, f); + fileReadLen = fread(buffer, fileLen, 1, f); fclose(f); + (void)fileReadLen; // intentionally ignore return value, per buildbot + // get pointer to file header mdh = (md3modelHeader*)buffer; From 1b2124b99b6394c82c37179842184daccf008549 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Tue, 18 Dec 2018 21:53:30 -0500 Subject: [PATCH 10/66] Add model sources to sdl1.2 VC project --- src/sdl12/Srb2SDL-vc10.vcxproj | 44 ++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/sdl12/Srb2SDL-vc10.vcxproj b/src/sdl12/Srb2SDL-vc10.vcxproj index 958cd7d02..9c550a092 100644 --- a/src/sdl12/Srb2SDL-vc10.vcxproj +++ b/src/sdl12/Srb2SDL-vc10.vcxproj @@ -755,6 +755,36 @@ %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) @@ -765,6 +795,16 @@ %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) @@ -1329,7 +1369,11 @@ + + + + From a140fe92316422fbafa907749bfae69978f28f4b Mon Sep 17 00:00:00 2001 From: mazmazz Date: Tue, 18 Dec 2018 22:50:00 -0500 Subject: [PATCH 11/66] hw_md2 merge errors --- src/hardware/hw_md2.c | 101 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.c index b9ff29578..c29bfe172 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -765,6 +765,8 @@ static void HWR_GetBlendedTexture(GLPatch_t *gpatch, GLPatch_t *blendgpatch, INT // mostly copied from HWR_GetMappedPatch, hence the similarities and comment GLMipmap_t *grmip, *newmip; + (void)skinnum; + if (colormap == colormaps || colormap == NULL) { // Don't do any blending @@ -834,7 +836,11 @@ void HWR_DrawMD2(gr_vissprite_t *spr) FSurfaceInfo Surf; char filename[64]; + INT32 frame = 0; + INT32 nextFrame = -1; + FTransform p; md2_t *md2; + UINT8 color[4]; if (!cv_grmd2.value) return; @@ -879,6 +885,16 @@ void HWR_DrawMD2(gr_vissprite_t *spr) // Look at HWR_ProjectSprite for more { GLPatch_t *gpatch; + INT32 durs = spr->mobj->state->tics; + INT32 tics = spr->mobj->tics; + const UINT8 flip = (UINT8)((spr->mobj->eflags & MFE_VERTICALFLIP) == MFE_VERTICALFLIP); + spritedef_t *sprdef; + spriteframe_t *sprframe; + float finalscale; + + // Apparently people don't like jump frames like that, so back it goes + //if (tics > durs) + //durs = tics; if (spr->mobj->flags2 & MF2_SHADOW) Surf.FlatColor.s.alpha = 0x40; @@ -920,6 +936,7 @@ void HWR_DrawMD2(gr_vissprite_t *spr) } } //HWD.pfnSetBlend(blend); // This seems to actually break translucency? + finalscale = md2->scale; //Hurdler: arf, I don't like that implementation at all... too much crappy gpatch = md2->grpatch; if (!gpatch || !gpatch->mipmap.grInfo.format || !gpatch->mipmap.downloaded) @@ -973,6 +990,90 @@ void HWR_DrawMD2(gr_vissprite_t *spr) gpatch = W_CachePatchNum(spr->patchlumpnum, PU_CACHE); HWR_GetMappedPatch(gpatch, spr->colormap); } + + if (spr->mobj->frame & FF_ANIMATE) + { + // set duration and tics to be the correct values for FF_ANIMATE states + durs = spr->mobj->state->var2; + tics = spr->mobj->anim_duration; + } + + //FIXME: this is not yet correct + frame = (spr->mobj->frame & FF_FRAMEMASK) % md2->model->meshes[0].numFrames; +#if 0 + if (cv_grmd2.value == 1 && tics <= durs) + { + // frames are handled differently for states with FF_ANIMATE, so get the next frame differently for the interpolation + if (spr->mobj->frame & FF_ANIMATE) + { + UINT32 nextframe = (spr->mobj->frame & FF_FRAMEMASK) + 1; + if (nextframe >= (UINT32)spr->mobj->state->var1) + nextframe = (spr->mobj->state->frame & FF_FRAMEMASK); + nextframe %= md2->model->header.numFrames; + next = &md2->model->frames[nextframe]; + } + else + { + if (spr->mobj->state->nextstate != S_NULL && states[spr->mobj->state->nextstate].sprite != SPR_NULL) + { + const UINT32 nextframe = (states[spr->mobj->state->nextstate].frame & FF_FRAMEMASK) % md2->model->header.numFrames; + next = &md2->model->frames[nextframe]; + } + } + } +#endif + + //Hurdler: it seems there is still a small problem with mobj angle + p.x = FIXED_TO_FLOAT(spr->mobj->x); + p.y = FIXED_TO_FLOAT(spr->mobj->y)+md2->offset; + + if (spr->mobj->eflags & MFE_VERTICALFLIP) + p.z = FIXED_TO_FLOAT(spr->mobj->z + spr->mobj->height); + else + p.z = FIXED_TO_FLOAT(spr->mobj->z); + + if (spr->mobj->skin && spr->mobj->sprite == SPR_PLAY) + sprdef = &((skin_t *)spr->mobj->skin)->spritedef; + else + sprdef = &sprites[spr->mobj->sprite]; + + sprframe = &sprdef->spriteframes[spr->mobj->frame & FF_FRAMEMASK]; + + if (sprframe->rotate) + { + const fixed_t anglef = AngleFixed(spr->mobj->angle); + p.angley = FIXED_TO_FLOAT(anglef); + } + else + { + const fixed_t anglef = AngleFixed((R_PointToAngle(spr->mobj->x, spr->mobj->y))-ANGLE_180); + p.angley = FIXED_TO_FLOAT(anglef); + } + p.anglex = 0.0f; + p.anglez = 0.0f; + if (spr->mobj->standingslope) + { + fixed_t tempz = spr->mobj->standingslope->normal.z; + fixed_t tempy = spr->mobj->standingslope->normal.y; + fixed_t tempx = spr->mobj->standingslope->normal.x; + fixed_t tempangle = AngleFixed(R_PointToAngle2(0, 0, FixedSqrt(FixedMul(tempy, tempy) + FixedMul(tempz, tempz)), tempx)); + p.anglez = FIXED_TO_FLOAT(tempangle); + tempangle = -AngleFixed(R_PointToAngle2(0, 0, tempz, tempy)); + p.anglex = FIXED_TO_FLOAT(tempangle); + } + + color[0] = Surf.FlatColor.s.red; + color[1] = Surf.FlatColor.s.green; + color[2] = Surf.FlatColor.s.blue; + color[3] = Surf.FlatColor.s.alpha; + + // SRB2CBTODO: MD2 scaling support + finalscale *= FIXED_TO_FLOAT(spr->mobj->scale); + + p.flip = atransform.flip; + p.mirror = atransform.mirror; + + HWD.pfnDrawModel(md2->model, frame, durs, tics, nextFrame, &p, finalscale, flip, color); } } From 4116ffb5e996fa8cfa4d0ecb18b64d08ea1008e4 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Tue, 18 Dec 2018 23:44:38 -0500 Subject: [PATCH 12/66] More hw_md2 merge errors; re-enable interpolation code block --- src/hardware/hw_md2.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.c index c29bfe172..6cba468e9 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -765,8 +765,6 @@ static void HWR_GetBlendedTexture(GLPatch_t *gpatch, GLPatch_t *blendgpatch, INT // mostly copied from HWR_GetMappedPatch, hence the similarities and comment GLMipmap_t *grmip, *newmip; - (void)skinnum; - if (colormap == colormaps || colormap == NULL) { // Don't do any blending @@ -1000,7 +998,7 @@ void HWR_DrawMD2(gr_vissprite_t *spr) //FIXME: this is not yet correct frame = (spr->mobj->frame & FF_FRAMEMASK) % md2->model->meshes[0].numFrames; -#if 0 + if (cv_grmd2.value == 1 && tics <= durs) { // frames are handled differently for states with FF_ANIMATE, so get the next frame differently for the interpolation @@ -1014,14 +1012,14 @@ void HWR_DrawMD2(gr_vissprite_t *spr) } else { - if (spr->mobj->state->nextstate != S_NULL && states[spr->mobj->state->nextstate].sprite != SPR_NULL) + if (spr->mobj->state->nextstate != S_NULL && states[spr->mobj->state->nextstate].sprite != SPR_NULL + && !(spr->mobj->player && (spr->mobj->state->nextstate == S_PLAY_TAP1 || spr->mobj->state->nextstate == S_PLAY_TAP2) && spr->mobj->state == &states[S_PLAY_STND])) { const UINT32 nextframe = (states[spr->mobj->state->nextstate].frame & FF_FRAMEMASK) % md2->model->header.numFrames; next = &md2->model->frames[nextframe]; } } } -#endif //Hurdler: it seems there is still a small problem with mobj angle p.x = FIXED_TO_FLOAT(spr->mobj->x); From 2685af7331f9092f421bc65f60b8fa8afb32dca9 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Wed, 19 Dec 2018 00:17:51 -0500 Subject: [PATCH 13/66] Hide/add Kart FTransform mirror and anglez behind ifdef --- src/hardware/hw_defs.h | 11 +++++++++++ src/hardware/hw_md2.c | 7 ++++++- src/hardware/r_opengl/r_opengl.c | 22 ++++++++++++++++++++-- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/hardware/hw_defs.h b/src/hardware/hw_defs.h index ece627d3c..fc6ae348e 100644 --- a/src/hardware/hw_defs.h +++ b/src/hardware/hw_defs.h @@ -101,15 +101,26 @@ typedef struct //Hurdler: Transform (coords + angles) //BP: transform order : scale(rotation_x(rotation_y(translation(v)))) + +// Kart features +#define USE_FTRANSFORM_ANGLEZ +#define USE_FTRANSFORM_MIRROR + typedef struct { FLOAT x,y,z; // position +#ifdef USE_FTRANSFORM_ANGLEZ FLOAT anglex,angley,anglez; // aimingangle / viewangle +#else + FLOAT anglex,angley; // aimingangle / viewangle +#endif FLOAT scalex,scaley,scalez; FLOAT fovxangle, fovyangle; UINT8 splitscreen; boolean flip; // screenflip +#ifdef USE_FTRANSFORM_MIRROR boolean mirror; // SRB2Kart: Encore Mode +#endif } FTransform; // Transformed vector, as passed to HWR API diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.c index 6cba468e9..10e2847f9 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -1048,6 +1048,8 @@ void HWR_DrawMD2(gr_vissprite_t *spr) p.angley = FIXED_TO_FLOAT(anglef); } p.anglex = 0.0f; +#ifdef USE_FTRANSFORM_ANGLEZ + // Slope rotation from Kart p.anglez = 0.0f; if (spr->mobj->standingslope) { @@ -1059,6 +1061,7 @@ void HWR_DrawMD2(gr_vissprite_t *spr) tempangle = -AngleFixed(R_PointToAngle2(0, 0, tempz, tempy)); p.anglex = FIXED_TO_FLOAT(tempangle); } +#endif color[0] = Surf.FlatColor.s.red; color[1] = Surf.FlatColor.s.green; @@ -1069,7 +1072,9 @@ void HWR_DrawMD2(gr_vissprite_t *spr) finalscale *= FIXED_TO_FLOAT(spr->mobj->scale); p.flip = atransform.flip; - p.mirror = atransform.mirror; +#ifdef USE_FTRANSFORM_MIRROR + p.mirror = atransform.mirror; // from Kart +#endif HWD.pfnDrawModel(md2->model, frame, durs, tics, nextFrame, &p, finalscale, flip, color); } diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index e29c6a383..5f21ec7ed 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -1971,6 +1971,7 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, INT32 duration, INT32 pglEnable(GL_CULL_FACE); +#ifdef USE_FTRANSFORM_MIRROR // flipped is if the object is flipped // pos->flip is if the screen is flipped vertically // pos->mirror is if the screen is flipped horizontally @@ -1982,6 +1983,17 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, INT32 duration, INT32 else pglCullFace(GL_BACK); } +#else + // pos->flip is if the screen is flipped too + if (flipped != pos->flip) // If either are active, but not both, invert the model's culling + { + pglCullFace(GL_FRONT); + } + else + { + pglCullFace(GL_BACK); + } +#endif #ifndef KOS_GL_COMPATIBILITY pglLightfv(GL_LIGHT0, GL_POSITION, LightPos); @@ -2006,7 +2018,9 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, INT32 duration, INT32 pglTranslatef(pos->x, pos->z, pos->y); if (flipped) scaley = -scaley; - pglRotatef(pos->anglez, 0.0f, 0.0f, -1.0f); +#ifdef USE_FTRANSFORM_ANGLEZ + pglRotatef(pos->anglez, 0.0f, 0.0f, -1.0f); // rotate by slope from Kart +#endif pglRotatef(pos->anglex, -1.0f, 0.0f, 0.0f); pglRotatef(pos->angley, 0.0f, -1.0f, 0.0f); @@ -2182,9 +2196,13 @@ EXPORT void HWRAPI(SetTransform) (FTransform *stransform) // keep a trace of the transformation for md2 memcpy(&md2_transform, stransform, sizeof (md2_transform)); +#ifdef USE_FTRANSFORM_MIRROR + // mirroring from Kart if (stransform->mirror) pglScalef(-stransform->scalex, stransform->scaley, -stransform->scalez); - else if (stransform->flip) + else +#endif + if (stransform->flip) pglScalef(stransform->scalex, -stransform->scaley, -stransform->scalez); else pglScalef(stransform->scalex, stransform->scaley, -stransform->scalez); From 71aa549a15044224db8b3c8e777f791256bc9025 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Wed, 19 Dec 2018 00:38:00 -0500 Subject: [PATCH 14/66] Adapt re-enabled DrawMD2 code block for meshes --- src/hardware/hw_md2.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.c index 10e2847f9..f58de224b 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -885,6 +885,7 @@ void HWR_DrawMD2(gr_vissprite_t *spr) GLPatch_t *gpatch; INT32 durs = spr->mobj->state->tics; INT32 tics = spr->mobj->tics; + //mdlframe_t *next = NULL; const UINT8 flip = (UINT8)((spr->mobj->eflags & MFE_VERTICALFLIP) == MFE_VERTICALFLIP); spritedef_t *sprdef; spriteframe_t *sprframe; @@ -1004,19 +1005,19 @@ void HWR_DrawMD2(gr_vissprite_t *spr) // frames are handled differently for states with FF_ANIMATE, so get the next frame differently for the interpolation if (spr->mobj->frame & FF_ANIMATE) { - UINT32 nextframe = (spr->mobj->frame & FF_FRAMEMASK) + 1; - if (nextframe >= (UINT32)spr->mobj->state->var1) - nextframe = (spr->mobj->state->frame & FF_FRAMEMASK); - nextframe %= md2->model->header.numFrames; - next = &md2->model->frames[nextframe]; + nextFrame = (spr->mobj->frame & FF_FRAMEMASK) + 1; + if (nextFrame >= spr->mobj->state->var1) + nextFrame = (spr->mobj->state->frame & FF_FRAMEMASK); + nextFrame %= md2->model->meshes[0].numFrames; + //next = &md2->model->meshes[0].frames[nextFrame]; } else { if (spr->mobj->state->nextstate != S_NULL && states[spr->mobj->state->nextstate].sprite != SPR_NULL && !(spr->mobj->player && (spr->mobj->state->nextstate == S_PLAY_TAP1 || spr->mobj->state->nextstate == S_PLAY_TAP2) && spr->mobj->state == &states[S_PLAY_STND])) { - const UINT32 nextframe = (states[spr->mobj->state->nextstate].frame & FF_FRAMEMASK) % md2->model->header.numFrames; - next = &md2->model->frames[nextframe]; + nextFrame = (states[spr->mobj->state->nextstate].frame & FF_FRAMEMASK) % md2->model->meshes[0].numFrames; + //next = &md2->model->meshes[0].frames[nextFrame]; } } } From cb1dba7798a05dd38a1c2e851793c32a8bd48e79 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Wed, 19 Dec 2018 01:57:54 -0500 Subject: [PATCH 15/66] Interpolation fix attempt? * Fix pglNormal3bv pointer because typo --- src/hardware/r_opengl/r_opengl.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 5f21ec7ed..7bb8442e4 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -523,7 +523,7 @@ boolean SetupGLfunc(void) GETOPENGLFUNC(pglVertex3f , glVertex3f) GETOPENGLFUNC(pglVertex3sv, glVertex3sv) GETOPENGLFUNC(pglNormal3f , glNormal3f) - GETOPENGLFUNC(pglNormal3bv, glNomral3bv) + GETOPENGLFUNC(pglNormal3bv, glNormal3bv) GETOPENGLFUNC(pglColor4f , glColor4f) GETOPENGLFUNC(pglColor4fv , glColor4fv) GETOPENGLFUNC(pglTexCoord2f , glTexCoord2f) @@ -2075,7 +2075,7 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, INT32 duration, INT32 { // Interpolate *vertPtr++ = (short)(frame->vertices[j] + (pol * (nextframe->vertices[j] - frame->vertices[j]))); - *normPtr++ = (short)(frame->normals[j] + (pol * (nextframe->normals[j] - frame->normals[j]))); + *normPtr++ = (char)(frame->normals[j] + (pol * (nextframe->normals[j] - frame->normals[j]))); } uvPtr = mesh->uvs; @@ -2083,9 +2083,9 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, INT32 duration, INT32 normPtr = normBuffer; for (j = 0; j < mesh->numTriangles; j++) { - pglTexCoord2fv((const GLfloat*) uvPtr); - pglNormal3bv((const GLbyte*) normPtr); - pglVertex3sv((const GLshort*) vertPtr); + pglTexCoord2fv(uvPtr); + pglNormal3bv((signed char*) normPtr); + pglVertex3sv(vertPtr); uvPtr += 2; normPtr += 3; From c8fd6f01b9069cb081dd06360297c6d3529b26cd Mon Sep 17 00:00:00 2001 From: mazmazz Date: Wed, 19 Dec 2018 10:33:13 -0500 Subject: [PATCH 16/66] Ifdef nextFrame handling under USE_MODEL_NEXTFRAME --- src/hardware/hw_defs.h | 3 +++ src/hardware/hw_md2.c | 2 ++ 2 files changed, 5 insertions(+) diff --git a/src/hardware/hw_defs.h b/src/hardware/hw_defs.h index fc6ae348e..04f63af71 100644 --- a/src/hardware/hw_defs.h +++ b/src/hardware/hw_defs.h @@ -106,6 +106,9 @@ typedef struct #define USE_FTRANSFORM_ANGLEZ #define USE_FTRANSFORM_MIRROR +// Vanilla features +#define USE_MODEL_NEXTFRAME + typedef struct { FLOAT x,y,z; // position diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.c index f58de224b..33cd8b8a3 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -1000,6 +1000,7 @@ void HWR_DrawMD2(gr_vissprite_t *spr) //FIXME: this is not yet correct frame = (spr->mobj->frame & FF_FRAMEMASK) % md2->model->meshes[0].numFrames; +#ifdef USE_MODEL_NEXTFRAME if (cv_grmd2.value == 1 && tics <= durs) { // frames are handled differently for states with FF_ANIMATE, so get the next frame differently for the interpolation @@ -1021,6 +1022,7 @@ void HWR_DrawMD2(gr_vissprite_t *spr) } } } +#endif //Hurdler: it seems there is still a small problem with mobj angle p.x = FIXED_TO_FLOAT(spr->mobj->x); From 0adf6fea1975c84e29532cf082903aa56b2430d7 Mon Sep 17 00:00:00 2001 From: AJ Freda Date: Wed, 19 Dec 2018 20:52:47 -0500 Subject: [PATCH 17/66] Fixed a few unnoticable mistakes [vanilla] --- src/hardware/hw_md2load.c | 3 +- src/hardware/r_opengl/r_opengl.c | 75 ++++++++++++-------------------- 2 files changed, 31 insertions(+), 47 deletions(-) diff --git a/src/hardware/hw_md2load.c b/src/hardware/hw_md2load.c index ff195dda5..49fdbf8ab 100644 --- a/src/hardware/hw_md2load.c +++ b/src/hardware/hw_md2load.c @@ -454,12 +454,13 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) else // Full float loading method { md2triangle_t *trisPtr = tris; - float *uvptr = retModel->meshes[0].uvs; + float *uvptr; char *ptr = (char*)frames; retModel->meshes[0].numVertices = header->numTris*3; retModel->meshes[0].frames = (mdlframe_t*)Z_Calloc(sizeof(mdlframe_t)*header->numFrames, ztag, 0); retModel->meshes[0].uvs = (float*)Z_Malloc(sizeof(float)*2*retModel->meshes[0].numVertices, ztag, 0); + uvptr = retModel->meshes[0].uvs; for (i = 0; i < retModel->meshes[0].numTriangles; i++, trisPtr++) { diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 7bb8442e4..c0b6d2a7c 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -1924,6 +1924,7 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, INT32 duration, INT32 GLfloat diffuse[4]; float pol = 0.0f; + scale *= 0.5f; float scalex = scale, scaley = scale, scalez = scale; boolean useTinyFrames; @@ -1935,8 +1936,6 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, INT32 duration, INT32 GLfloat LightPos[] = {0.0f, 1.0f, 0.0f, 0.0f}; #endif - scale *= 0.5f; - if (duration != 0 && duration != -1 && tics != -1) // don't interpolate if instantaneous or infinite in length { UINT32 newtime = (duration - tics); // + 1; @@ -2054,22 +2053,16 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, INT32 duration, INT32 pglDrawElements(GL_TRIANGLES, mesh->numTriangles * 3, GL_UNSIGNED_SHORT, mesh->indices); pglDisableClientState(GL_NORMAL_ARRAY); pglDisableClientState(GL_TEXTURE_COORD_ARRAY); - pglDisableClientState(GL_TEXTURE_COORD_ARRAY); + pglDisableClientState(GL_VERTEX_ARRAY); } else { - short *buffer, *vertPtr; - char *normBuffer, *normPtr; - float *uvPtr; - int j = 0; - // Dangit, I soooo want to do this in a GLSL shader... - pglBegin(GL_TRIANGLES); - - buffer = malloc(mesh->numVertices * sizeof(short)); - vertPtr = buffer; - normBuffer = malloc(mesh->numVertices * sizeof(char)); - normPtr = normBuffer; + short *buffer = malloc(mesh->numVertices * sizeof(short) * 3); + short *vertPtr = buffer; + char *normBuffer = malloc(mesh->numVertices * sizeof(char) * 3); + char *normPtr = normBuffer; + int j = 0; for (j = 0; j < mesh->numVertices; j++) { @@ -2078,24 +2071,19 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, INT32 duration, INT32 *normPtr++ = (char)(frame->normals[j] + (pol * (nextframe->normals[j] - frame->normals[j]))); } - uvPtr = mesh->uvs; - vertPtr = buffer; - normPtr = normBuffer; - for (j = 0; j < mesh->numTriangles; j++) - { - pglTexCoord2fv(uvPtr); - pglNormal3bv((signed char*) normPtr); - pglVertex3sv(vertPtr); - - uvPtr += 2; - normPtr += 3; - vertPtr += 3; - } + pglEnableClientState(GL_VERTEX_ARRAY); + pglEnableClientState(GL_TEXTURE_COORD_ARRAY); + pglEnableClientState(GL_NORMAL_ARRAY); + pglVertexPointer(3, GL_SHORT, 0, buffer); + pglNormalPointer(GL_BYTE, 0, normBuffer); + pglTexCoordPointer(2, GL_FLOAT, 0, mesh->uvs); + pglDrawElements(GL_TRIANGLES, mesh->numTriangles * 3, GL_UNSIGNED_SHORT, mesh->indices); + pglDisableClientState(GL_NORMAL_ARRAY); + pglDisableClientState(GL_TEXTURE_COORD_ARRAY); + pglDisableClientState(GL_VERTEX_ARRAY); free(buffer); free(normBuffer); - - pglEnd(); } } else @@ -2118,39 +2106,34 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, INT32 duration, INT32 pglDrawArrays(GL_TRIANGLES, 0, mesh->numTriangles * 3); pglDisableClientState(GL_NORMAL_ARRAY); pglDisableClientState(GL_TEXTURE_COORD_ARRAY); - pglDisableClientState(GL_TEXTURE_COORD_ARRAY); + pglDisableClientState(GL_VERTEX_ARRAY); } else { int j = 0; - float *uvPtr; - float *frameVert; - float *frameNormal; - float *nextFrameVert; - float *nextFrameNormal; + float *uvPtr = mesh->uvs; + float *frameVert = frame->vertices; + float *frameNormal = frame->normals; + float *nextFrameVert = nextframe->vertices; + float *nextFrameNormal = nextframe->normals; // Dangit, I soooo want to do this in a GLSL shader... pglBegin(GL_TRIANGLES); - uvPtr = mesh->uvs; - frameVert = frame->vertices; - frameNormal = frame->normals; - nextFrameVert = nextframe->vertices; - nextFrameNormal = frame->normals; - for (j = 0; j < mesh->numTriangles; j++) + for (j = 0; j < mesh->numTriangles * 3; j++) { // Interpolate float px1 = *frameVert++; - float px2 = *nextFrameVert++; float py1 = *frameVert++; - float py2 = *nextFrameVert++; float pz1 = *frameVert++; + float px2 = *nextFrameVert++; + float py2 = *nextFrameVert++; float pz2 = *nextFrameVert++; float nx1 = *frameNormal++; - float nx2 = *nextFrameNormal++; float ny1 = *frameNormal++; - float ny2 = *nextFrameNormal++; float nz1 = *frameNormal++; + float nx2 = *nextFrameNormal++; + float ny2 = *nextFrameNormal++; float nz2 = *nextFrameNormal++; pglTexCoord2fv(uvPtr); @@ -2161,7 +2144,7 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, INT32 duration, INT32 (py1 + pol * (py2 - py1)), (pz1 + pol * (pz2 - pz1))); - uvPtr++; + uvPtr += 2; } pglEnd(); From 8a4066486ec690a52e816955218ffdf1d4d47591 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Wed, 19 Dec 2018 20:56:58 -0500 Subject: [PATCH 18/66] Small Mixed D&C fix --- src/hardware/r_opengl/r_opengl.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index c0b6d2a7c..fec8c33a3 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -1924,8 +1924,8 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, INT32 duration, INT32 GLfloat diffuse[4]; float pol = 0.0f; - scale *= 0.5f; - float scalex = scale, scaley = scale, scalez = scale; + + float scalex, scaley, scalez; boolean useTinyFrames; @@ -1936,6 +1936,9 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, INT32 duration, INT32 GLfloat LightPos[] = {0.0f, 1.0f, 0.0f, 0.0f}; #endif + scale *= 0.5f; + scalex = scaley = scalez = scale; + if (duration != 0 && duration != -1 && tics != -1) // don't interpolate if instantaneous or infinite in length { UINT32 newtime = (duration - tics); // + 1; From 9617e604bbc159158953c718a8618d3c82d672c6 Mon Sep 17 00:00:00 2001 From: Arthur Date: Sun, 23 Dec 2018 17:00:11 -0500 Subject: [PATCH 19/66] Removed all glBegin/glEnd references MD2/MD3 now works, with the exception of WAD textures for some odd reason --- src/hardware/hw_drv.h | 4 - src/hardware/hw_main.c | 2 - src/hardware/hw_md2load.c | 250 +++---- src/hardware/r_opengl/r_opengl.c | 885 ++++++++----------------- src/hardware/r_opengl/r_opengl.h | 2 - src/sdl/hwsym_sdl.c | 2 - src/sdl/i_video.c | 2 - src/win32/Srb2win-vc10.vcxproj.filters | 16 +- 8 files changed, 386 insertions(+), 777 deletions(-) diff --git a/src/hardware/hw_drv.h b/src/hardware/hw_drv.h index 7b45b0974..c1ece091a 100644 --- a/src/hardware/hw_drv.h +++ b/src/hardware/hw_drv.h @@ -63,10 +63,8 @@ EXPORT void HWRAPI(SetTransform) (FTransform *ptransform); EXPORT INT32 HWRAPI(GetTextureUsed) (void); EXPORT INT32 HWRAPI(GetRenderVersion) (void); -#ifdef SHUFFLE #define SCREENVERTS 10 EXPORT void HWRAPI(PostImgRedraw) (float points[SCREENVERTS][SCREENVERTS][2]); -#endif EXPORT void HWRAPI(FlushScreenTextures) (void); EXPORT void HWRAPI(StartScreenWipe) (void); EXPORT void HWRAPI(EndScreenWipe) (void); @@ -105,9 +103,7 @@ struct hwdriver_s #ifndef HAVE_SDL Shutdown pfnShutdown; #endif -#ifdef SHUFFLE PostImgRedraw pfnPostImgRedraw; -#endif FlushScreenTextures pfnFlushScreenTextures; StartScreenWipe pfnStartScreenWipe; EndScreenWipe pfnEndScreenWipe; diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index e4c9e8330..fc70492ca 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -6838,7 +6838,6 @@ void HWR_DoPostProcessor(player_t *player) if (splitscreen) // Not supported in splitscreen - someone want to add support? return; -#ifdef SHUFFLE // Drunken vision! WooOOooo~ if (*type == postimg_water || *type == postimg_heat) { @@ -6881,7 +6880,6 @@ void HWR_DoPostProcessor(player_t *player) HWD.pfnMakeScreenTexture(); } // Flipping of the screen isn't done here anymore -#endif // SHUFFLE } void HWR_StartScreenWipe(void) diff --git a/src/hardware/hw_md2load.c b/src/hardware/hw_md2load.c index 49fdbf8ab..d29414b0f 100644 --- a/src/hardware/hw_md2load.c +++ b/src/hardware/hw_md2load.c @@ -17,7 +17,7 @@ #define NUMVERTEXNORMALS 162 -// Quake 2 normals are indexed. Use avertexnormals[normalindex][x/y/z] and +// Quake 2 normals are indexed. Use avertexnormals[normalindex][x/y/z] and // you'll have your normals. float avertexnormals[NUMVERTEXNORMALS][3] = { {-0.525731f, 0.000000f, 0.850651f}, @@ -186,71 +186,57 @@ float avertexnormals[NUMVERTEXNORMALS][3] = { typedef struct { - int ident; // A "magic number" that's used to identify the .md2 file - int version; // The version of the file, always 8 - int skinwidth; // Width of the skin(s) in pixels - int skinheight; // Height of the skin(s) in pixels - int framesize; // Size of each frame in bytes - int numSkins; // Number of skins with the model - int numXYZ; // Number of vertices in each frame - int numST; // Number of texture coordinates in each frame. - int numTris; // Number of triangles in each frame - int numGLcmds; // Number of dwords (4 bytes) in the gl command list. - int numFrames; // Number of frames - int offsetSkins; // Offset, in bytes from the start of the file, to the list of skin names. - int offsetST; // Offset, in bytes from the start of the file, to the list of texture coordinates - int offsetTris; // Offset, in bytes from the start of the file, to the list of triangles - int offsetFrames; // Offset, in bytes from the start of the file, to the list of frames - int offsetGLcmds; // Offset, in bytes from the start of the file, to the list of gl commands - int offsetEnd; // Offset, in bytes from the start of the file, to the end of the file (filesize) + int ident; // A "magic number" that's used to identify the .md2 file + int version; // The version of the file, always 8 + int skinwidth; // Width of the skin(s) in pixels + int skinheight; // Height of the skin(s) in pixels + int framesize; // Size of each frame in bytes + int numSkins; // Number of skins with the model + int numXYZ; // Number of vertices in each frame + int numST; // Number of texture coordinates in each frame. + int numTris; // Number of triangles in each frame + int numGLcmds; // Number of dwords (4 bytes) in the gl command list. + int numFrames; // Number of frames + int offsetSkins; // Offset, in bytes from the start of the file, to the list of skin names. + int offsetST; // Offset, in bytes from the start of the file, to the list of texture coordinates + int offsetTris; // Offset, in bytes from the start of the file, to the list of triangles + int offsetFrames; // Offset, in bytes from the start of the file, to the list of frames + int offsetGLcmds; // Offset, in bytes from the start of the file, to the list of gl commands + int offsetEnd; // Offset, in bytes from the start of the file, to the end of the file (filesize) } md2header_t; typedef struct { - unsigned short meshIndex[3]; // indices into the array of vertices in each frames - unsigned short stIndex[3]; // indices into the array of texture coordinates + unsigned short meshIndex[3]; // indices into the array of vertices in each frames + unsigned short stIndex[3]; // indices into the array of texture coordinates } md2triangle_t; typedef struct { - short s; - short t; + short s; + short t; } md2texcoord_t; typedef struct { - unsigned char v[3]; // Scaled vertices. You'll need to multiply them with scale[x] to make them normal. - unsigned char lightNormalIndex; // Index to the array of normals + unsigned char v[3]; // Scaled vertices. You'll need to multiply them with scale[x] to make them normal. + unsigned char lightNormalIndex; // Index to the array of normals } md2vertex_t; typedef struct { - float scale[3]; // Used by the v member in the md2framePoint structure - float translate[3]; // Used by the v member in the md2framePoint structure - char name[16]; // Name of the frame + float scale[3]; // Used by the v member in the md2framePoint structure + float translate[3]; // Used by the v member in the md2framePoint structure + char name[16]; // Name of the frame } md2frame_t; // Load the model model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) { + useFloat = true; model_t *retModel = NULL; md2header_t *header; - size_t fileLen; - size_t fileReadLen; - int i, j, t; - - size_t namelen; - char *texturefilename, *buffer; - const char *texPos; - - const float WUNITS = 1.0f; - float dataScale; - - md2triangle_t *tris; - md2texcoord_t *texcoords; - md2frame_t *frames; - FILE *f = fopen(fileName, "rb"); if (!f) @@ -258,7 +244,13 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) retModel = (model_t*)Z_Calloc(sizeof(model_t), ztag, 0); - texPos = strchr(fileName, '/'); + size_t fileLen; + + int i, j; + + size_t namelen; + char *texturefilename; + const char *texPos = strchr(fileName, '/'); if (texPos) { @@ -274,9 +266,9 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) strcpy(texturefilename, fileName); } - texturefilename[namelen-2] = 'z'; - texturefilename[namelen-3] = 'u'; - texturefilename[namelen-4] = 'b'; + texturefilename[namelen - 2] = 'z'; + texturefilename[namelen - 3] = 'u'; + texturefilename[namelen - 4] = 'b'; // find length of file fseek(f, 0, SEEK_END); @@ -284,25 +276,23 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) fseek(f, 0, SEEK_SET); // read in file - buffer = malloc(fileLen); - fileReadLen = fread(buffer, fileLen, 1, f); + char *buffer = malloc(fileLen); + fread(buffer, fileLen, 1, f); fclose(f); - (void)fileReadLen; // intentionally ignore return value, per buildbot - // get pointer to file header header = (md2header_t*)buffer; retModel->numMeshes = 1; // MD2 only has one mesh retModel->meshes = (mesh_t*)Z_Calloc(sizeof(mesh_t) * retModel->numMeshes, ztag, 0); retModel->meshes[0].numFrames = header->numFrames; - - dataScale = WUNITS; + const float WUNITS = 1.0f; + float dataScale = WUNITS; // Tris and ST are simple structures that can be straight-copied - tris = (md2triangle_t*)&buffer[header->offsetTris]; - texcoords = (md2texcoord_t*)&buffer[header->offsetST]; - frames = (md2frame_t*)&buffer[header->offsetFrames]; + md2triangle_t *tris = (md2triangle_t*)&buffer[header->offsetTris]; + md2texcoord_t *texcoords = (md2texcoord_t*)&buffer[header->offsetST]; + md2frame_t *frames = (md2frame_t*)&buffer[header->offsetFrames]; // Read in textures retModel->numMaterials = header->numSkins; @@ -312,6 +302,7 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) retModel->materials = (material_t*)Z_Calloc(sizeof(material_t)*retModel->numMaterials, ztag, 0); + int t; for (t = 0; t < retModel->numMaterials; t++) { retModel->materials[t].ambient[0] = 0.8f; @@ -333,86 +324,76 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) retModel->materials[t].shininess = 0.0f; retModel->materials[t].spheremap = false; -/* retModel->materials[t].texture = Texture::ReadTexture((char*)texturefilename, ZT_TEXTURE); + /* retModel->materials[t].texture = Texture::ReadTexture((char*)texturefilename, ZT_TEXTURE); - if (!systemSucks) - { - // Check for a normal map...?? - Resource::resource_t *res - char openfilename[1024]; - char normalMapName[1024]; - strcpy(normalMapName, texturefilename); - size_t len = strlen(normalMapName); - char *ptr = &normalMapName[len]; - ptr--; // z - ptr--; // u - ptr--; // b - ptr--; // . - *ptr++ = '_'; - *ptr++ = 'n'; - *ptr++ = '.'; - *ptr++ = 'b'; - *ptr++ = 'u'; - *ptr++ = 'z'; - *ptr++ = '\0'; + if (!systemSucks) + { + // Check for a normal map...?? + char openfilename[1024]; + char normalMapName[1024]; + strcpy(normalMapName, texturefilename); + size_t len = strlen(normalMapName); + char *ptr = &normalMapName[len]; + ptr--; // z + ptr--; // u + ptr--; // b + ptr--; // . + *ptr++ = '_'; + *ptr++ = 'n'; + *ptr++ = '.'; + *ptr++ = 'b'; + *ptr++ = 'u'; + *ptr++ = 'z'; + *ptr++ = '\0'; - sprintf(openfilename, "%s/%s", "textures", normalMapName); - // Convert backslashes to forward slashes - for (int k = 0; k < 1024; k++) - { - if (openfilename[k] == '\0') - break; + sprintf(openfilename, "%s/%s", "textures", normalMapName); + // Convert backslashes to forward slashes + for (int k = 0; k < 1024; k++) + { + if (openfilename[k] == '\0') + break; - if (openfilename[k] == '\\') - openfilename[k] = '/'; - } + if (openfilename[k] == '\\') + openfilename[k] = '/'; + } - res = Resource::Open(openfilename); - if (res) - { - Resource::Close(res); - retModel->materials[t].lightmap = Texture::ReadTexture(normalMapName, ZT_TEXTURE); - } - }*/ + Resource::resource_t *res = Resource::Open(openfilename); + if (res) + { + Resource::Close(res); + retModel->materials[t].lightmap = Texture::ReadTexture(normalMapName, ZT_TEXTURE); + } + }*/ } retModel->meshes[0].numTriangles = header->numTris; if (!useFloat) // Decompress to MD3 'tinyframe' space { - char *ptr = (char*)frames; - md2triangle_t *trisPtr; - unsigned short *indexptr; - float *uvptr; - dataScale = 0.015624f; // 1 / 64.0f retModel->meshes[0].tinyframes = (tinyframe_t*)Z_Calloc(sizeof(tinyframe_t)*header->numFrames, ztag, 0); retModel->meshes[0].numVertices = header->numXYZ; - retModel->meshes[0].uvs = (float*)Z_Malloc (sizeof(float)*2*retModel->meshes[0].numVertices, ztag, 0); + retModel->meshes[0].uvs = (float*)Z_Malloc(sizeof(float) * 2 * retModel->meshes[0].numVertices, ztag, 0); + byte *ptr = (byte*)frames; for (i = 0; i < header->numFrames; i++, ptr += header->framesize) { - short *vertptr; - char *normptr; - //char *tanptr; md2frame_t *framePtr = (md2frame_t*)ptr; - md2vertex_t *vertex; + retModel->meshes[0].tinyframes[i].vertices = (short*)Z_Malloc(sizeof(short) * 3 * header->numXYZ, ztag, 0); + retModel->meshes[0].tinyframes[i].normals = (char*)Z_Malloc(sizeof(char) * 3 * header->numXYZ, ztag, 0); - retModel->meshes[0].tinyframes[i].vertices = (short*)Z_Malloc(sizeof(short)*3*header->numXYZ, ztag, 0); - retModel->meshes[0].tinyframes[i].normals = (char*)Z_Malloc(sizeof(char)*3*header->numXYZ, ztag, 0); - -// if (retModel->materials[0].lightmap) -// retModel->meshes[0].tinyframes[i].tangents = (char*)malloc(sizeof(char));//(char*)Z_Malloc(sizeof(char)*3*header->numVerts, ztag); + // if (retModel->materials[0].lightmap) + // retModel->meshes[0].tinyframes[i].tangents = (char*)malloc(sizeof(char));//(char*)Z_Malloc(sizeof(char)*3*header->numVerts, ztag); retModel->meshes[0].indices = (unsigned short*)Z_Malloc(sizeof(unsigned short) * 3 * header->numTris, ztag, 0); - vertptr = retModel->meshes[0].tinyframes[i].vertices; - normptr = retModel->meshes[0].tinyframes[i].normals; + short *vertptr = retModel->meshes[0].tinyframes[i].vertices; + char *normptr = retModel->meshes[0].tinyframes[i].normals; -// tanptr = retModel->meshes[0].tinyframes[i].tangents; + // char *tanptr = retModel->meshes[0].tinyframes[i].tangents; retModel->meshes[0].tinyframes[i].material = &retModel->materials[0]; framePtr++; // Advance to vertex list - vertex = (md2vertex_t*)framePtr; + md2vertex_t *vertex = (md2vertex_t*)framePtr; framePtr--; for (j = 0; j < header->numXYZ; j++, vertex++) { @@ -425,15 +406,15 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) // Normal *normptr++ = (char)(avertexnormals[vertex->lightNormalIndex][0] * 127); - *normptr++ = (char)(avertexnormals[vertex->lightNormalIndex][1] * 127); *normptr++ = (char)(avertexnormals[vertex->lightNormalIndex][2] * 127); + *normptr++ = (char)(avertexnormals[vertex->lightNormalIndex][1] * 127); } } // This doesn't need to be done every frame! - trisPtr = tris; - indexptr = retModel->meshes[0].indices; - uvptr = (float*)retModel->meshes[0].uvs; + md2triangle_t *trisPtr = tris; + unsigned short *indexptr = retModel->meshes[0].indices; + float *uvptr = (float*)retModel->meshes[0].uvs; for (j = 0; j < header->numTris; j++, trisPtr++) { *indexptr = trisPtr->meshIndex[0]; @@ -453,15 +434,12 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) } else // Full float loading method { - md2triangle_t *trisPtr = tris; - float *uvptr; - char *ptr = (char*)frames; - - retModel->meshes[0].numVertices = header->numTris*3; + retModel->meshes[0].numVertices = header->numTris * 3; retModel->meshes[0].frames = (mdlframe_t*)Z_Calloc(sizeof(mdlframe_t)*header->numFrames, ztag, 0); - retModel->meshes[0].uvs = (float*)Z_Malloc(sizeof(float)*2*retModel->meshes[0].numVertices, ztag, 0); - uvptr = retModel->meshes[0].uvs; + retModel->meshes[0].uvs = (float*)Z_Malloc(sizeof(float) * 2 * retModel->meshes[0].numVertices, ztag, 0); + md2triangle_t *trisPtr = tris; + float *uvptr = retModel->meshes[0].uvs; for (i = 0; i < retModel->meshes[0].numTriangles; i++, trisPtr++) { *uvptr++ = texcoords[trisPtr->stIndex[0]].s / (float)header->skinwidth; @@ -472,16 +450,15 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) *uvptr++ = (texcoords[trisPtr->stIndex[2]].t / (float)header->skinheight); } + byte *ptr = (byte*)frames; for (i = 0; i < header->numFrames; i++, ptr += header->framesize) { - md2vertex_t *vertex; md2frame_t *framePtr = (md2frame_t*)ptr; + retModel->meshes[0].frames[i].normals = (float*)Z_Malloc(sizeof(float) * 3 * header->numTris * 3, ztag, 0); + retModel->meshes[0].frames[i].vertices = (float*)Z_Malloc(sizeof(float) * 3 * header->numTris * 3, ztag, 0); + // if (retModel->materials[0].lightmap) + // retModel->meshes[0].frames[i].tangents = (float*)malloc(sizeof(float));//(float*)Z_Malloc(sizeof(float)*3*header->numTris*3, ztag); float *vertptr, *normptr; - retModel->meshes[0].frames[i].normals = (float*)Z_Malloc(sizeof(float)*3*header->numTris*3, ztag, 0); - retModel->meshes[0].frames[i].vertices = (float*)Z_Malloc(sizeof(float)*3*header->numTris*3, ztag, 0); -// if (retModel->materials[0].lightmap) -// retModel->meshes[0].frames[i].tangents = (float*)malloc(sizeof(float));//(float*)Z_Malloc(sizeof(float)*3*header->numTris*3, ztag); - normptr = (float*)retModel->meshes[0].frames[i].normals; vertptr = (float*)retModel->meshes[0].frames[i].vertices; trisPtr = tris; @@ -489,7 +466,7 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) retModel->meshes[0].frames[i].material = &retModel->materials[0]; framePtr++; // Advance to vertex list - vertex = (md2vertex_t*)framePtr; + md2vertex_t *vertex = (md2vertex_t*)framePtr; framePtr--; for (j = 0; j < header->numTris; j++, trisPtr++) { @@ -515,26 +492,17 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) vertptr++; *normptr++ = avertexnormals[vertex[trisPtr->meshIndex[0]].lightNormalIndex][0]; - *normptr++ = avertexnormals[vertex[trisPtr->meshIndex[0]].lightNormalIndex][1]; *normptr++ = avertexnormals[vertex[trisPtr->meshIndex[0]].lightNormalIndex][2]; + *normptr++ = avertexnormals[vertex[trisPtr->meshIndex[0]].lightNormalIndex][1]; *normptr++ = avertexnormals[vertex[trisPtr->meshIndex[1]].lightNormalIndex][0]; - *normptr++ = avertexnormals[vertex[trisPtr->meshIndex[1]].lightNormalIndex][1]; *normptr++ = avertexnormals[vertex[trisPtr->meshIndex[1]].lightNormalIndex][2]; + *normptr++ = avertexnormals[vertex[trisPtr->meshIndex[1]].lightNormalIndex][1]; *normptr++ = avertexnormals[vertex[trisPtr->meshIndex[2]].lightNormalIndex][0]; - *normptr++ = avertexnormals[vertex[trisPtr->meshIndex[2]].lightNormalIndex][1]; *normptr++ = avertexnormals[vertex[trisPtr->meshIndex[2]].lightNormalIndex][2]; + *normptr++ = avertexnormals[vertex[trisPtr->meshIndex[2]].lightNormalIndex][1]; } - /* - // Rotate MD2 by 90 degrees in code BLAAHH - vector_t *normVecptr = (vector_t*)retModel->meshes[0].frames[i].normals; - vector_t *vertVecptr = (vector_t*)retModel->meshes[0].frames[i].vertices; - for (j = 0; j < header->numTris * 3; j++, normVecptr++, vertVecptr++) - { - VectorRotate(normVecptr, &vectorYaxis, -90.0f); - VectorRotate(vertVecptr, &vectorYaxis, -90.0f); - }*/ } } diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index fec8c33a3..4f77680d9 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -29,11 +29,6 @@ #include #include -#ifndef SHUFFLE -#ifndef KOS_GL_COMPATIBILITY -#define SHUFFLE -#endif -#endif #include "r_opengl.h" #if defined (HWRENDER) && !defined (NOROPENGL) @@ -83,9 +78,7 @@ GLint screen_height = 0; GLbyte screen_depth = 0; GLint textureformatGL = 0; GLint maximumAnisotropy = 0; -#ifndef KOS_GL_COMPATIBILITY static GLboolean MipMap = GL_FALSE; -#endif static GLint min_filter = GL_LINEAR; static GLint mag_filter = GL_LINEAR; static GLint anisotropic_filter = 0; @@ -94,11 +87,9 @@ static FTransform md2_transform; const GLubyte *gl_extensions = NULL; //Hurdler: 04/10/2000: added for the kick ass coronas as Boris wanted;-) -#ifndef MINI_GL_COMPATIBILITY static GLdouble modelMatrix[16]; static GLdouble projMatrix[16]; static GLint viewport[4]; -#endif #ifdef USE_PALETTED_TEXTURE @@ -167,11 +158,6 @@ float byteasfloat(UINT8 fbyte) static I_Error_t I_Error_GL = NULL; -#ifndef MINI_GL_COMPATIBILITY -static boolean gl13 = false; // whether we can use opengl 1.3 functions -#endif - - // -----------------+ // DBG_Printf : Output error messages to debug log if DEBUG_TO_FILE is defined, // : else do nothing @@ -207,14 +193,10 @@ FUNCPRINTF void DBG_Printf(const char *lpFmt, ...) #define pglScissor glScissor #define pglEnable glEnable #define pglDisable glDisable -#ifndef MINI_GL_COMPATIBILITY #define pglGetDoublev glGetDoublev -#endif //glGetIntegerv //glGetString -#ifdef KOS_GL_COMPATIBILITY #define pglHint glHint -#endif /* Depth Buffer */ #define pglClearDepth glClearDepth @@ -228,11 +210,8 @@ FUNCPRINTF void DBG_Printf(const char *lpFmt, ...) #define pglPushMatrix glPushMatrix #define pglPopMatrix glPopMatrix #define pglLoadIdentity glLoadIdentity -#ifdef MINI_GL_COMPATIBILITY #define pglMultMatrixf glMultMatrixf -#else #define pglMultMatrixd glMultMatrixd -#endif #define pglRotatef glRotatef #define pglScalef glScalef #define pglTranslatef glTranslatef @@ -241,6 +220,7 @@ FUNCPRINTF void DBG_Printf(const char *lpFmt, ...) #define pglBegin glBegin #define pglEnd glEnd #define pglVertex3f glVertex3f +#define pglVertex3fv glVertex3fv #define pglVertex3sv glVertex3sv #define pglNormal3f glNormal3f #define pglNormal3bv glNormal3bv @@ -254,7 +234,8 @@ FUNCPRINTF void DBG_Printf(const char *lpFmt, ...) #define pglDrawArrays glDrawArrays #define pglDrawElements glDrawElements #define pglEnableClientState glEnableClientState -#define pglDisableClientState pglDisableClientState +#define pglDisableClientState glDisableClientState +#define pglClientActiveTexture glClientActiveTexture /* Lighting */ #define pglShadeModel glShadeModel @@ -280,10 +261,8 @@ FUNCPRINTF void DBG_Printf(const char *lpFmt, ...) #define pglDeleteTextures glDeleteTextures #define pglBindTexture glBindTexture /* texture mapping */ //GL_EXT_copy_texture -#ifndef KOS_GL_COMPATIBILITY #define pglCopyTexImage2D glCopyTexImage2D #define pglCopyTexSubImage2D glCopyTexSubImage2D -#endif #else //!STATIC_OPENGL @@ -310,10 +289,8 @@ typedef void (APIENTRY * PFNglEnable) (GLenum cap); static PFNglEnable pglEnable; typedef void (APIENTRY * PFNglDisable) (GLenum cap); static PFNglDisable pglDisable; -#ifndef MINI_GL_COMPATIBILITY typedef void (APIENTRY * PFNglGetDoublev) (GLenum pname, GLdouble *params); static PFNglGetDoublev pglGetDoublev; -#endif //glGetIntegerv //glGetString @@ -338,13 +315,10 @@ typedef void (APIENTRY * PFNglPopMatrix) (void); static PFNglPopMatrix pglPopMatrix; typedef void (APIENTRY * PFNglLoadIdentity) (void); static PFNglLoadIdentity pglLoadIdentity; -#ifdef MINI_GL_COMPATIBILITY typedef void (APIENTRY * PFNglMultMatrixf) (const GLfloat *m); static PFNglMultMatrixf pglMultMatrixf; -#else typedef void (APIENTRY * PFNglMultMatrixd) (const GLdouble *m); static PFNglMultMatrixd pglMultMatrixd; -#endif typedef void (APIENTRY * PFNglRotatef) (GLfloat angle, GLfloat x, GLfloat y, GLfloat z); static PFNglRotatef pglRotatef; typedef void (APIENTRY * PFNglScalef) (GLfloat x, GLfloat y, GLfloat z); @@ -359,6 +333,8 @@ typedef void (APIENTRY * PFNglEnd) (void); static PFNglEnd pglEnd; typedef void (APIENTRY * PFNglVertex3f) (GLfloat x, GLfloat y, GLfloat z); static PFNglVertex3f pglVertex3f; +typedef void (APIENTRY * PFNglVertex3fv)(const GLfloat *v); +static PFNglVertex3fv pglVertex3fv; typedef void (APIENTRY * PFNglVertex3sv) (const GLshort *v); static PFNglVertex3sv pglVertex3sv; typedef void (APIENTRY * PFNglNormal3f) (GLfloat x, GLfloat y, GLfloat z); @@ -434,15 +410,16 @@ static PFNglCopyTexSubImage2D pglCopyTexSubImage2D; typedef GLint (APIENTRY * PFNgluBuild2DMipmaps) (GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *data); static PFNgluBuild2DMipmaps pgluBuild2DMipmaps; -#ifndef MINI_GL_COMPATIBILITY /* 1.3 functions for multitexturing */ typedef void (APIENTRY *PFNglActiveTexture) (GLenum); static PFNglActiveTexture pglActiveTexture; typedef void (APIENTRY *PFNglMultiTexCoord2f) (GLenum, GLfloat, GLfloat); static PFNglMultiTexCoord2f pglMultiTexCoord2f; -#endif +typedef void (APIENTRY *PFNglMultiTexCoord2fv) (GLenum target, const GLfloat *v); +static PFNglMultiTexCoord2fv pglMultiTexCoord2fv; +typedef void (APIENTRY *PFNglClientActiveTexture) (GLenum); +static PFNglClientActiveTexture pglClientActiveTexture; -#ifndef MINI_GL_COMPATIBILITY /* 1.2 Parms */ /* GL_CLAMP_TO_EDGE_EXT */ #ifndef GL_CLAMP_TO_EDGE @@ -463,14 +440,6 @@ static PFNglMultiTexCoord2f pglMultiTexCoord2f; #define GL_TEXTURE1 0x84C1 #endif -#endif - -#ifdef MINI_GL_COMPATIBILITY -#undef GL_CLAMP_TO_EDGE -#undef GL_TEXTURE_MIN_LOD -#undef GL_TEXTURE_MAX_LOD -#endif - boolean SetupGLfunc(void) { #ifndef STATIC_OPENGL @@ -493,9 +462,7 @@ boolean SetupGLfunc(void) GETOPENGLFUNC(pglScissor , glScissor) GETOPENGLFUNC(pglEnable , glEnable) GETOPENGLFUNC(pglDisable , glDisable) -#ifndef MINI_GL_COMPATIBILITY GETOPENGLFUNC(pglGetDoublev , glGetDoublev) -#endif GETOPENGLFUNC(pglGetIntegerv , glGetIntegerv) GETOPENGLFUNC(pglGetString , glGetString) @@ -509,11 +476,8 @@ boolean SetupGLfunc(void) GETOPENGLFUNC(pglPushMatrix , glPushMatrix) GETOPENGLFUNC(pglPopMatrix , glPopMatrix) GETOPENGLFUNC(pglLoadIdentity , glLoadIdentity) -#ifdef MINI_GL_COMPATIBILITY GETOPENGLFUNC(pglMultMatrixf , glMultMatrixf) -#else GETOPENGLFUNC(pglMultMatrixd , glMultMatrixd) -#endif GETOPENGLFUNC(pglRotatef , glRotatef) GETOPENGLFUNC(pglScalef , glScalef) GETOPENGLFUNC(pglTranslatef , glTranslatef) @@ -521,6 +485,7 @@ boolean SetupGLfunc(void) GETOPENGLFUNC(pglBegin , glBegin) GETOPENGLFUNC(pglEnd , glEnd) GETOPENGLFUNC(pglVertex3f , glVertex3f) + GETOPENGLFUNC(pglVertex3fv, glVertex3fv) GETOPENGLFUNC(pglVertex3sv, glVertex3sv) GETOPENGLFUNC(pglNormal3f , glNormal3f) GETOPENGLFUNC(pglNormal3bv, glNormal3bv) @@ -535,6 +500,9 @@ boolean SetupGLfunc(void) GETOPENGLFUNC(pglDrawElements, glDrawElements) GETOPENGLFUNC(pglEnableClientState, glEnableClientState) GETOPENGLFUNC(pglDisableClientState, glDisableClientState) + GETOPENGLFUNC(pglClientActiveTexture, glClientActiveTexture) + if (!pglClientActiveTexture) + GETOPENGLFUNC(pglClientActiveTexture, glClientActiveTextureARB) GETOPENGLFUNC(pglShadeModel , glShadeModel) GETOPENGLFUNC(pglLightfv, glLightfv) @@ -566,47 +534,15 @@ boolean SetupGLfunc(void) } // This has to be done after the context is created so the version number can be obtained +// This is stupid -- even some of the oldest usable OpenGL hardware today supports 1.3-level featureset. boolean SetupGLFunc13(void) { -#ifdef MINI_GL_COMPATIBILITY - return false; -#else - const GLubyte *version = pglGetString(GL_VERSION); - int glmajor, glminor; - - gl13 = false; - // Parse the GL version - if (version != NULL) - { - if (sscanf((const char*)version, "%d.%d", &glmajor, &glminor) == 2) - { - // Look, we gotta prepare for the inevitable arrival of GL 2.0 code... - if (glmajor == 1 && glminor >= 3) - gl13 = true; - else if (glmajor > 1) - gl13 = true; - } - } - - if (gl13) - { - pglActiveTexture = GetGLFunc("glActiveTexture"); - pglMultiTexCoord2f = GetGLFunc("glMultiTexCoord2f"); - } - else if (isExtAvailable("GL_ARB_multitexture", gl_extensions)) - { - // Get the functions - pglActiveTexture = GetGLFunc("glActiveTextureARB"); - pglMultiTexCoord2f = GetGLFunc("glMultiTexCoord2fARB"); - - gl13 = true; // This is now true, so the new fade mask stuff can be done, if OpenGL version is less than 1.3, it still uses the old fade stuff. - DBG_Printf("GL_ARB_multitexture support: enabled\n"); - - } - else - DBG_Printf("GL_ARB_multitexture support: disabled\n"); + pglActiveTexture = GetGLFunc("glActiveTexture"); + pglMultiTexCoord2f = GetGLFunc("glMultiTexCoord2f"); + pglClientActiveTexture = GetGLFunc("glClientActiveTexture"); + pglMultiTexCoord2fv = GetGLFunc("glMultiTexCoord2fv"); + return true; -#endif } // -----------------+ @@ -624,11 +560,7 @@ static void SetNoTexture(void) static void GLPerspective(GLdouble fovy, GLdouble aspect) { -#ifdef MINI_GL_COMPATIBILITY - GLfloat m[4][4] = -#else GLdouble m[4][4] = -#endif { { 1.0f, 0.0f, 0.0f, 0.0f}, { 0.0f, 1.0f, 0.0f, 0.0f}, @@ -651,14 +583,10 @@ static void GLPerspective(GLdouble fovy, GLdouble aspect) m[1][1] = cotangent; m[2][2] = -(zFar + zNear) / deltaZ; m[3][2] = -2.0f * zNear * zFar / deltaZ; -#ifdef MINI_GL_COMPATIBILITY - pglMultMatrixf(&m[0][0]); -#else + pglMultMatrixd(&m[0][0]); -#endif } -#ifndef MINI_GL_COMPATIBILITY static void GLProject(GLdouble objX, GLdouble objY, GLdouble objZ, GLdouble* winX, GLdouble* winY, GLdouble* winZ) { @@ -698,7 +626,6 @@ static void GLProject(GLdouble objX, GLdouble objY, GLdouble objZ, *winY=in[1]; *winZ=in[2]; } -#endif // -----------------+ // SetModelView : @@ -729,10 +656,8 @@ void SetModelView(GLint w, GLint h) //pglScalef(1.0f, 320.0f/200.0f, 1.0f); // gr_scalefrustum (ORIGINAL_ASPECT) // added for new coronas' code (without depth buffer) -#ifndef MINI_GL_COMPATIBILITY pglGetIntegerv(GL_VIEWPORT, viewport); pglGetDoublev(GL_PROJECTION_MATRIX, projMatrix); -#endif } @@ -757,17 +682,15 @@ void SetStates(void) //pglShadeModel(GL_FLAT); pglEnable(GL_TEXTURE_2D); // two-dimensional texturing -#ifndef KOS_GL_COMPATIBILITY + pglTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); pglAlphaFunc(GL_NOTEQUAL, 0.0f); -#endif + //pglBlendFunc(GL_ONE, GL_ZERO); // copy pixel to frame buffer (opaque) pglEnable(GL_BLEND); // enable color blending -#ifndef KOS_GL_COMPATIBILITY pglColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); -#endif //pglDisable(GL_DITHER); // faB: ??? (undocumented in OpenGL 1.1) // Hurdler: yes, it is! @@ -792,9 +715,7 @@ void SetStates(void) //tex_downloaded = NOTEXTURE_NUM; //pglTexImage2D(GL_TEXTURE_2D, 0, 4, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, Data); -#ifndef KOS_GL_COMPATIBILITY pglPolygonOffset(-1.0f, -1.0f); -#endif //pglEnable(GL_CULL_FACE); //pglCullFace(GL_FRONT); @@ -815,9 +736,7 @@ void SetStates(void) // bp : when no t&l :) pglLoadIdentity(); pglScalef(1.0f, 1.0f, -1.0f); -#ifndef MINI_GL_COMPATIBILITY pglGetDoublev(GL_MODELVIEW_MATRIX, modelMatrix); // added for new coronas' code (without depth buffer) -#endif } @@ -921,14 +840,6 @@ EXPORT void HWRAPI(ClearMipMapCache) (void) EXPORT void HWRAPI(ReadRect) (INT32 x, INT32 y, INT32 width, INT32 height, INT32 dst_stride, UINT16 * dst_data) { -#ifdef KOS_GL_COMPATIBILITY - (void)x; - (void)y; - (void)width; - (void)height; - (void)dst_stride; - (void)dst_data; -#else INT32 i; // DBG_Printf ("ReadRect()\n"); if (dst_stride == width*3) @@ -970,7 +881,6 @@ EXPORT void HWRAPI(ReadRect) (INT32 x, INT32 y, INT32 width, INT32 height, } free(image); } -#endif } @@ -991,10 +901,8 @@ EXPORT void HWRAPI(GClipRect) (INT32 minx, INT32 miny, INT32 maxx, INT32 maxy, f pglMatrixMode(GL_MODELVIEW); // added for new coronas' code (without depth buffer) -#ifndef MINI_GL_COMPATIBILITY pglGetIntegerv(GL_VIEWPORT, viewport); pglGetDoublev(GL_PROJECTION_MATRIX, projMatrix); -#endif } @@ -1041,12 +949,9 @@ EXPORT void HWRAPI(Draw2DLine) (F2DCoord * v1, GLRGBAFloat c; // DBG_Printf ("DrawLine() (%f %f %f) %d\n", v1->x, -v1->y, -v1->z, v1->argb); -#ifdef MINI_GL_COMPATIBILITY - GLfloat px1, px2, px3, px4; - GLfloat py1, py2, py3, py4; + GLfloat p[12]; GLfloat dx, dy; GLfloat angle; -#endif // BP: we should reflect the new state in our variable //SetBlend(PF_Modulated|PF_NoTexture); @@ -1058,33 +963,24 @@ EXPORT void HWRAPI(Draw2DLine) (F2DCoord * v1, c.blue = byte2float[Color.s.blue]; c.alpha = byte2float[Color.s.alpha]; -#ifndef MINI_GL_COMPATIBILITY - pglColor4fv(&c.red); // is in RGBA float format - pglBegin(GL_LINES); - pglVertex3f(v1->x, -v1->y, 1.0f); - pglVertex3f(v2->x, -v2->y, 1.0f); - pglEnd(); -#else + // This is the preferred, 'modern' way of rendering lines -- creating a polygon. if (v2->x != v1->x) angle = (float)atan((v2->y-v1->y)/(v2->x-v1->x)); else - angle = N_PI_DEMI; + angle = (float)N_PI_DEMI; dx = (float)sin(angle) / (float)screen_width; dy = (float)cos(angle) / (float)screen_height; - px1 = v1->x - dx; py1 = v1->y + dy; - px2 = v2->x - dx; py2 = v2->y + dy; - px3 = v2->x + dx; py3 = v2->y - dy; - px4 = v1->x + dx; py4 = v1->y - dy; + p[0] = v1->x - dx; p[1] = -(v1->y + dy); p[2] = 1; + p[3] = v2->x - dx; p[4] = -(v2->y + dy); p[5] = 1; + p[6] = v2->x + dx; p[7] = -(v2->y - dy); p[8] = 1; + p[9] = v1->x + dx; p[10] = -(v1->y - dy); p[11] = 1; - pglColor4f(c.red, c.green, c.blue, c.alpha); - pglBegin(GL_TRIANGLE_FAN); - pglVertex3f(px1, -py1, 1); - pglVertex3f(px2, -py2, 1); - pglVertex3f(px3, -py3, 1); - pglVertex3f(px4, -py4, 1); - pglEnd(); -#endif + pglColor4fv(&c.red); // is in RGBA float format + pglEnableClientState(GL_VERTEX_ARRAY); + pglVertexPointer(3, GL_FLOAT, 0, p); + pglDrawArrays(GL_TRIANGLE_FAN, 0, 4); + pglDisableClientState(GL_VERTEX_ARRAY); pglEnable(GL_TEXTURE_2D); } @@ -1114,60 +1010,42 @@ EXPORT void HWRAPI(SetBlend) (FBITFIELD PolyFlags) switch (PolyFlags & PF_Blending) { case PF_Translucent & PF_Blending: pglBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // alpha = level of transparency -#ifndef KOS_GL_COMPATIBILITY pglAlphaFunc(GL_NOTEQUAL, 0.0f); -#endif break; case PF_Masked & PF_Blending: // Hurdler: does that mean lighting is only made by alpha src? // it sounds ok, but not for polygonsmooth pglBlendFunc(GL_SRC_ALPHA, GL_ZERO); // 0 alpha = holes in texture -#ifndef KOS_GL_COMPATIBILITY pglAlphaFunc(GL_GREATER, 0.5f); -#endif break; case PF_Additive & PF_Blending: -#ifdef ATI_RAGE_PRO_COMPATIBILITY - pglBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // alpha = level of transparency -#else pglBlendFunc(GL_SRC_ALPHA, GL_ONE); // src * alpha + dest -#endif -#ifndef KOS_GL_COMPATIBILITY pglAlphaFunc(GL_NOTEQUAL, 0.0f); -#endif break; case PF_Environment & PF_Blending: pglBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); -#ifndef KOS_GL_COMPATIBILITY pglAlphaFunc(GL_NOTEQUAL, 0.0f); -#endif break; case PF_Substractive & PF_Blending: // good for shadow - // not realy but what else ? + // not really but what else ? pglBlendFunc(GL_ZERO, GL_ONE_MINUS_SRC_COLOR); -#ifndef KOS_GL_COMPATIBILITY pglAlphaFunc(GL_NOTEQUAL, 0.0f); -#endif break; case PF_Fog & PF_Fog: // Sryder: Fog // multiplies input colour by input alpha, and destination colour by input colour, then adds them pglBlendFunc(GL_SRC_ALPHA, GL_SRC_COLOR); -#ifndef KOS_GL_COMPATIBILITY pglAlphaFunc(GL_NOTEQUAL, 0.0f); -#endif break; default : // must be 0, otherwise it's an error // No blending pglBlendFunc(GL_ONE, GL_ZERO); // the same as no blending -#ifndef KOS_GL_COMPATIBILITY pglAlphaFunc(GL_GREATER, 0.5f); -#endif break; } } -#ifndef KOS_GL_COMPATIBILITY + if (Xor & PF_NoAlphaTest) { if (PolyFlags & PF_NoAlphaTest) @@ -1183,7 +1061,7 @@ EXPORT void HWRAPI(SetBlend) (FBITFIELD PolyFlags) else pglDisable(GL_POLYGON_OFFSET_FILL); } -#endif + if (Xor&PF_NoDepthTest) { if (PolyFlags & PF_NoDepthTest) @@ -1210,10 +1088,6 @@ EXPORT void HWRAPI(SetBlend) (FBITFIELD PolyFlags) pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); } -#ifdef KOS_GL_COMPATIBILITY - if (Xor&PF_Modulated && !(PolyFlags & PF_Modulated)) - pglColor4f(1.0f, 1.0f, 1.0f, 1.0f); -#else if (Xor&PF_Modulated) { #if defined (__unix__) || defined (UNIXCOMMON) @@ -1233,7 +1107,6 @@ EXPORT void HWRAPI(SetBlend) (FBITFIELD PolyFlags) pglTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); } } -#endif if (Xor & PF_Occlude) // depth test but (no) depth write { @@ -1287,11 +1160,7 @@ EXPORT void HWRAPI(SetTexture) (FTextureInfo *pTexInfo) else { // Download a mipmap -#ifdef KOS_GL_COMPATIBILITY - static GLushort tex[2048*2048]; -#else static RGBA_t tex[2048*2048]; -#endif const GLvoid *ptex = tex; INT32 w, h; @@ -1310,102 +1179,7 @@ EXPORT void HWRAPI(SetTexture) (FTextureInfo *pTexInfo) } else #endif -#ifdef KOS_GL_COMPATIBILITY - if ((pTexInfo->grInfo.format == GR_TEXFMT_P_8) || - (pTexInfo->grInfo.format == GR_TEXFMT_AP_88)) - { - const GLubyte *pImgData = (const GLubyte *)pTexInfo->grInfo.data; - INT32 i, j; - for (j = 0; j < h; j++) - { - for (i = 0; i < w; i++) - { - if ((*pImgData == HWR_PATCHES_CHROMAKEY_COLORINDEX) && - (pTexInfo->flags & TF_CHROMAKEYED)) - { - tex[w*j+i] = 0; - } - else - { - if (pTexInfo->grInfo.format == GR_TEXFMT_AP_88 && !(pTexInfo->flags & TF_CHROMAKEYED)) - tex[w*j+i] = 0; - else - tex[w*j+i] = (myPaletteData[*pImgData].s.alpha>>4)<<12; - - tex[w*j+i] |= (myPaletteData[*pImgData].s.red >>4)<<8; - tex[w*j+i] |= (myPaletteData[*pImgData].s.green>>4)<<4; - tex[w*j+i] |= (myPaletteData[*pImgData].s.blue >>4); - } - - pImgData++; - - if (pTexInfo->grInfo.format == GR_TEXFMT_AP_88) - { - if (!(pTexInfo->flags & TF_CHROMAKEYED)) - tex[w*j+i] |= ((*pImgData)>>4)<<12; - pImgData++; - } - - } - } - } - else if (pTexInfo->grInfo.format == GR_RGBA) - { - // corona test : passed as ARGB 8888, which is not in glide formats - // Hurdler: not used for coronas anymore, just for dynamic lighting - const RGBA_t *pImgData = (const RGBA_t *)pTexInfo->grInfo.data; - INT32 i, j; - - for (j = 0; j < h; j++) - { - for (i = 0; i < w; i++) - { - tex[w*j+i] = (pImgData->s.alpha>>4)<<12; - tex[w*j+i] |= (pImgData->s.red >>4)<<8; - tex[w*j+i] |= (pImgData->s.green>>4)<<4; - tex[w*j+i] |= (pImgData->s.blue >>4); - pImgData++; - } - } - } - else if (pTexInfo->grInfo.format == GR_TEXFMT_ALPHA_INTENSITY_88) - { - const GLubyte *pImgData = (const GLubyte *)pTexInfo->grInfo.data; - INT32 i, j; - - for (j = 0; j < h; j++) - { - for (i = 0; i < w; i++) - { - const GLubyte sID = (*pImgData)>>4; - tex[w*j+i] = sID<<8 | sID<<4 | sID; - pImgData++; - tex[w*j+i] |= ((*pImgData)>>4)<<12; - pImgData++; - } - } - } - else if (pTexInfo->grInfo.format == GR_TEXFMT_ALPHA_8) // Used for fade masks - { - const GLubyte *pImgData = (const GLubyte *)pTexInfo->grInfo.data; - INT32 i, j; - - for (j = 0; j < h; j++) - { - for (i = 0; i < w; i++) - { - tex[w*j+i] = (pImgData>>4)<<12; - tex[w*j+i] |= (255>>4)<<8; - tex[w*j+i] |= (255>>4)<<4; - tex[w*j+i] |= (255>>4); - pImgData++; - } - } - } - else - DBG_Printf ("SetTexture(bad format) %ld\n", pTexInfo->grInfo.format); -#else if ((pTexInfo->grInfo.format == GR_TEXFMT_P_8) || (pTexInfo->grInfo.format == GR_TEXFMT_AP_88)) { @@ -1488,7 +1262,6 @@ EXPORT void HWRAPI(SetTexture) (FTextureInfo *pTexInfo) } else DBG_Printf ("SetTexture(bad format) %ld\n", pTexInfo->grInfo.format); -#endif pTexInfo->downloaded = NextTexAvail++; tex_downloaded = pTexInfo->downloaded; @@ -1497,13 +1270,8 @@ EXPORT void HWRAPI(SetTexture) (FTextureInfo *pTexInfo) // disable texture filtering on any texture that has holes so there's no dumb borders or blending issues if (pTexInfo->flags & TF_TRANSPARENT) { -#ifdef KOS_GL_COMPATIBILITY - pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NONE); - pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NONE); -#else pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); -#endif } else { @@ -1511,29 +1279,6 @@ EXPORT void HWRAPI(SetTexture) (FTextureInfo *pTexInfo) pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter); } -#ifdef KOS_GL_COMPATIBILITY - pglTexImage2D(GL_TEXTURE_2D, 0, GL_ARGB4444, w, h, 0, GL_ARGB4444, GL_UNSIGNED_BYTE, ptex); -#else -#ifdef MINI_GL_COMPATIBILITY - //if (pTexInfo->grInfo.format == GR_TEXFMT_ALPHA_INTENSITY_88) - //pglTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex); - //else - if (MipMap) - pgluBuild2DMipmaps(GL_TEXTURE_2D, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, ptex); - else - pglTexImage2D(GL_TEXTURE_2D, 0, 4, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex); -#else -#ifdef USE_PALETTED_TEXTURE - //Hurdler: not really supported and not tested recently - if (glColorTableEXT && - (pTexInfo->grInfo.format == GR_TEXFMT_P_8) && - !(pTexInfo->flags & TF_CHROMAKEYED)) - { - glColorTableEXT(GL_TEXTURE_2D, GL_RGB8, 256, GL_RGB, GL_UNSIGNED_BYTE, palette_tex); - pglTexImage2D(GL_TEXTURE_2D, 0, GL_COLOR_INDEX8_EXT, w, h, 0, GL_COLOR_INDEX, GL_UNSIGNED_BYTE, pTexInfo->grInfo.data); - } - else -#endif if (pTexInfo->grInfo.format == GR_TEXFMT_ALPHA_INTENSITY_88) { //pglTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex); @@ -1593,8 +1338,6 @@ EXPORT void HWRAPI(SetTexture) (FTextureInfo *pTexInfo) else pglTexImage2D(GL_TEXTURE_2D, 0, textureformatGL, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex); } -#endif -#endif if (pTexInfo->flags & TF_WRAPX) pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); @@ -1618,19 +1361,6 @@ EXPORT void HWRAPI(SetTexture) (FTextureInfo *pTexInfo) else // initialisation de la liste gr_cachetail = gr_cachehead = pTexInfo; } -#ifdef MINI_GL_COMPATIBILITY - switch (pTexInfo->flags) - { - case 0 : - pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); - pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); - break; - default: - pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); - pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); - break; - } -#endif } @@ -1644,18 +1374,11 @@ EXPORT void HWRAPI(DrawPolygon) (FSurfaceInfo *pSurf, FBITFIELD PolyFlags) { FUINT i; -#ifndef MINI_GL_COMPATIBILITY FUINT j; -#endif GLRGBAFloat c = {0,0,0,0}; -#ifdef MINI_GL_COMPATIBILITY - if (PolyFlags & PF_Corona) - PolyFlags &= ~PF_NoDepthTest; -#else if ((PolyFlags & PF_Corona) && (oglflags & GLF_NOZBUFREAD)) PolyFlags &= ~(PF_NoDepthTest|PF_Corona); -#endif SetBlend(PolyFlags); //TODO: inline (#pragma..) @@ -1677,16 +1400,11 @@ EXPORT void HWRAPI(DrawPolygon) (FSurfaceInfo *pSurf, c.alpha = byte2float[pSurf->FlatColor.s.alpha]; } -#ifdef MINI_GL_COMPATIBILITY - pglColor4f(c.red, c.green, c.blue, c.alpha); -#else pglColor4fv(&c.red); // is in RGBA float format -#endif } // this test is added for new coronas' code (without depth buffer) // I think I should do a separate function for drawing coronas, so it will be a little faster -#ifndef MINI_GL_COMPATIBILITY if (PolyFlags & PF_Corona) // check to see if we need to draw the corona { //rem: all 8 (or 8.0f) values are hard coded: it can be changed to a higher value @@ -1733,19 +1451,17 @@ EXPORT void HWRAPI(DrawPolygon) (FSurfaceInfo *pSurf, c.alpha *= scalef; // change the alpha value (it seems better than changing the size of the corona) pglColor4fv(&c.red); } -#endif + if (PolyFlags & PF_MD2) return; - pglBegin(GL_TRIANGLE_FAN); - for (i = 0; i < iNumPts; i++) - { - pglTexCoord2f(pOutVerts[i].sow, pOutVerts[i].tow); - //Hurdler: test code: -pOutVerts[i].z => pOutVerts[i].z - pglVertex3f(pOutVerts[i].x, pOutVerts[i].y, pOutVerts[i].z); - //pglVertex3f(pOutVerts[i].x, pOutVerts[i].y, -pOutVerts[i].z); - } - pglEnd(); + pglEnableClientState(GL_VERTEX_ARRAY); + pglEnableClientState(GL_TEXTURE_COORD_ARRAY); + pglVertexPointer(3, GL_FLOAT, sizeof(FOutVector), &pOutVerts[0].x); + pglTexCoordPointer(2, GL_FLOAT, sizeof(FOutVector), &pOutVerts[0].sow); + pglDrawArrays(GL_TRIANGLE_FAN, 0, iNumPts); + pglDisableClientState(GL_TEXTURE_COORD_ARRAY); + pglDisableClientState(GL_VERTEX_ARRAY); if (PolyFlags & PF_RemoveYWrap) pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); @@ -1827,41 +1543,15 @@ EXPORT void HWRAPI(SetSpecialState) (hwdspecialstate_t IdState, INT32 Value) break; case HWD_SET_POLYGON_SMOOTH: -#ifdef KOS_GL_COMPATIBILITY // GL_POLYGON_SMOOTH_HINT - if (Value) - pglHint(GL_POLYGON_SMOOTH_HINT,GL_NICEST); - else - pglHint(GL_POLYGON_SMOOTH_HINT,GL_FASTEST); -#else if (Value) pglEnable(GL_POLYGON_SMOOTH); else pglDisable(GL_POLYGON_SMOOTH); -#endif break; case HWD_SET_TEXTUREFILTERMODE: switch (Value) { -#ifdef KOS_GL_COMPATIBILITY - case HWD_SET_TEXTUREFILTER_TRILINEAR: - case HWD_SET_TEXTUREFILTER_BILINEAR: - min_filter = mag_filter = GL_FILTER_BILINEAR; - break; - case HWD_SET_TEXTUREFILTER_POINTSAMPLED: - min_filter = mag_filter = GL_FILTER_NONE; - case HWD_SET_TEXTUREFILTER_MIXED1: - min_filter = GL_FILTER_NONE; - mag_filter = GL_LINEAR; - case HWD_SET_TEXTUREFILTER_MIXED2: - min_filter = GL_LINEAR; - mag_filter = GL_FILTER_NONE; - break; - case HWD_SET_TEXTUREFILTER_MIXED3: - min_filter = GL_FILTER_BILINEAR; - mag_filter = GL_FILTER_NONE; - break; -#elif !defined (MINI_GL_COMPATIBILITY) case HWD_SET_TEXTUREFILTER_TRILINEAR: min_filter = GL_LINEAR_MIPMAP_LINEAR; mag_filter = GL_LINEAR; @@ -1890,14 +1580,9 @@ EXPORT void HWRAPI(SetSpecialState) (hwdspecialstate_t IdState, INT32 Value) mag_filter = GL_NEAREST; MipMap = GL_TRUE; break; -#endif default: -#ifdef KOS_GL_COMPATIBILITY - min_filter = mag_filter = GL_FILTER_NONE; -#else mag_filter = GL_LINEAR; min_filter = GL_NEAREST; -#endif } if (!pgluBuild2DMipmaps) { @@ -1918,26 +1603,64 @@ EXPORT void HWRAPI(SetSpecialState) (hwdspecialstate_t IdState, INT32 Value) } } +static float *vertBuffer = NULL; +static float *normBuffer = NULL; +static size_t lerpBufferSize = 0; +static short *vertTinyBuffer = NULL; +static char *normTinyBuffer = NULL; +static size_t lerpTinyBufferSize = 0; + +// Static temporary buffer for doing frame interpolation +// 'size' is the vertex size +static void AllocLerpBuffer(size_t size) +{ + if (lerpBufferSize >= size) + return; + + if (vertBuffer != NULL) + free(vertBuffer); + + if (normBuffer != NULL) + free(normBuffer); + + lerpBufferSize = size; + vertBuffer = malloc(lerpBufferSize); + normBuffer = malloc(lerpBufferSize); +} + +// Static temporary buffer for doing frame interpolation +// 'size' is the vertex size +static void AllocLerpTinyBuffer(size_t size) +{ + if (lerpTinyBufferSize >= size) + return; + + if (vertTinyBuffer != NULL) + free(vertTinyBuffer); + + if (normTinyBuffer != NULL) + free(normTinyBuffer); + + lerpTinyBufferSize = size; + vertTinyBuffer = malloc(lerpTinyBufferSize); + normTinyBuffer = malloc(lerpTinyBufferSize / 2); +} + static void DrawModelEx(model_t *model, INT32 frameIndex, INT32 duration, INT32 tics, INT32 nextFrameIndex, FTransform *pos, float scale, UINT8 flipped, UINT8 *color) { GLfloat ambient[4]; GLfloat diffuse[4]; float pol = 0.0f; - - float scalex, scaley, scalez; + scale *= 0.5f; + float scalex = scale, scaley = scale, scalez = scale; boolean useTinyFrames; int i; // Because Otherwise, scaling the screen negatively vertically breaks the lighting -#ifndef KOS_GL_COMPATIBILITY GLfloat LightPos[] = {0.0f, 1.0f, 0.0f, 0.0f}; -#endif - - scale *= 0.5f; - scalex = scaley = scalez = scale; if (duration != 0 && duration != -1 && tics != -1) // don't interpolate if instantaneous or infinite in length { @@ -1997,9 +1720,7 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, INT32 duration, INT32 } #endif -#ifndef KOS_GL_COMPATIBILITY pglLightfv(GL_LIGHT0, GL_POSITION, LightPos); -#endif pglShadeModel(GL_SMOOTH); if (color) @@ -2033,6 +1754,10 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, INT32 duration, INT32 if (useTinyFrames) pglScalef(1 / 64.0f, 1 / 64.0f, 1 / 64.0f); + pglEnableClientState(GL_VERTEX_ARRAY); + pglEnableClientState(GL_TEXTURE_COORD_ARRAY); + pglEnableClientState(GL_NORMAL_ARRAY); + for (i = 0; i < model->numMeshes; i++) { mesh_t *mesh = &model->meshes[i]; @@ -2047,46 +1772,30 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, INT32 duration, INT32 if (!nextframe || pol == 0.0f) { - pglEnableClientState(GL_VERTEX_ARRAY); - pglEnableClientState(GL_TEXTURE_COORD_ARRAY); - pglEnableClientState(GL_NORMAL_ARRAY); pglVertexPointer(3, GL_SHORT, 0, frame->vertices); pglNormalPointer(GL_BYTE, 0, frame->normals); pglTexCoordPointer(2, GL_FLOAT, 0, mesh->uvs); pglDrawElements(GL_TRIANGLES, mesh->numTriangles * 3, GL_UNSIGNED_SHORT, mesh->indices); - pglDisableClientState(GL_NORMAL_ARRAY); - pglDisableClientState(GL_TEXTURE_COORD_ARRAY); - pglDisableClientState(GL_VERTEX_ARRAY); } else { // Dangit, I soooo want to do this in a GLSL shader... - short *buffer = malloc(mesh->numVertices * sizeof(short) * 3); - short *vertPtr = buffer; - char *normBuffer = malloc(mesh->numVertices * sizeof(char) * 3); - char *normPtr = normBuffer; + AllocLerpTinyBuffer(mesh->numVertices * sizeof(short) * 3); + short *vertPtr = vertTinyBuffer; + char *normPtr = normTinyBuffer; int j = 0; - for (j = 0; j < mesh->numVertices; j++) + for (j = 0; j < mesh->numVertices * 3; j++) { // Interpolate *vertPtr++ = (short)(frame->vertices[j] + (pol * (nextframe->vertices[j] - frame->vertices[j]))); *normPtr++ = (char)(frame->normals[j] + (pol * (nextframe->normals[j] - frame->normals[j]))); } - pglEnableClientState(GL_VERTEX_ARRAY); - pglEnableClientState(GL_TEXTURE_COORD_ARRAY); - pglEnableClientState(GL_NORMAL_ARRAY); - pglVertexPointer(3, GL_SHORT, 0, buffer); - pglNormalPointer(GL_BYTE, 0, normBuffer); + pglVertexPointer(3, GL_SHORT, 0, vertTinyBuffer); + pglNormalPointer(GL_BYTE, 0, normTinyBuffer); pglTexCoordPointer(2, GL_FLOAT, 0, mesh->uvs); pglDrawElements(GL_TRIANGLES, mesh->numTriangles * 3, GL_UNSIGNED_SHORT, mesh->indices); - pglDisableClientState(GL_NORMAL_ARRAY); - pglDisableClientState(GL_TEXTURE_COORD_ARRAY); - pglDisableClientState(GL_VERTEX_ARRAY); - - free(buffer); - free(normBuffer); } } else @@ -2100,61 +1809,38 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, INT32 duration, INT32 if (!nextframe || pol == 0.0f) { // Zoom! Take advantage of just shoving the entire arrays to the GPU. - pglEnableClientState(GL_VERTEX_ARRAY); - pglEnableClientState(GL_TEXTURE_COORD_ARRAY); - pglEnableClientState(GL_NORMAL_ARRAY); pglVertexPointer(3, GL_FLOAT, 0, frame->vertices); pglNormalPointer(GL_FLOAT, 0, frame->normals); pglTexCoordPointer(2, GL_FLOAT, 0, mesh->uvs); pglDrawArrays(GL_TRIANGLES, 0, mesh->numTriangles * 3); - pglDisableClientState(GL_NORMAL_ARRAY); - pglDisableClientState(GL_TEXTURE_COORD_ARRAY); - pglDisableClientState(GL_VERTEX_ARRAY); } else { - int j = 0; - float *uvPtr = mesh->uvs; - float *frameVert = frame->vertices; - float *frameNormal = frame->normals; - float *nextFrameVert = nextframe->vertices; - float *nextFrameNormal = nextframe->normals; - // Dangit, I soooo want to do this in a GLSL shader... - pglBegin(GL_TRIANGLES); + AllocLerpBuffer(mesh->numVertices * sizeof(float) * 3); + float *vertPtr = vertBuffer; + float *normPtr = normBuffer; + int j = 0; - for (j = 0; j < mesh->numTriangles * 3; j++) + for (j = 0; j < mesh->numVertices * 3; j++) { // Interpolate - float px1 = *frameVert++; - float py1 = *frameVert++; - float pz1 = *frameVert++; - float px2 = *nextFrameVert++; - float py2 = *nextFrameVert++; - float pz2 = *nextFrameVert++; - float nx1 = *frameNormal++; - float ny1 = *frameNormal++; - float nz1 = *frameNormal++; - float nx2 = *nextFrameNormal++; - float ny2 = *nextFrameNormal++; - float nz2 = *nextFrameNormal++; - - pglTexCoord2fv(uvPtr); - pglNormal3f((nx1 + pol * (nx2 - nx1)), - (ny1 + pol * (ny2 - ny1)), - (nz1 + pol * (nz2 - nz1))); - pglVertex3f((px1 + pol * (px2 - px1)), - (py1 + pol * (py2 - py1)), - (pz1 + pol * (pz2 - pz1))); - - uvPtr += 2; + *vertPtr++ = frame->vertices[j] + (pol * (nextframe->vertices[j] - frame->vertices[j])); + *normPtr++ = frame->normals[j] + (pol * (nextframe->normals[j] - frame->normals[j])); } - pglEnd(); + pglVertexPointer(3, GL_FLOAT, 0, vertBuffer); + pglNormalPointer(GL_FLOAT, 0, normBuffer); + pglTexCoordPointer(2, GL_FLOAT, 0, mesh->uvs); + pglDrawArrays(GL_TRIANGLES, 0, mesh->numVertices); } } } + pglDisableClientState(GL_NORMAL_ARRAY); + pglDisableClientState(GL_TEXTURE_COORD_ARRAY); + pglDisableClientState(GL_VERTEX_ARRAY); + pglPopMatrix(); // should be the same as glLoadIdentity if (color) pglDisable(GL_LIGHTING); @@ -2204,9 +1890,7 @@ EXPORT void HWRAPI(SetTransform) (FTransform *stransform) GLPerspective(53.13l, 2*ASPECT_RATIO); // 53.13 = 2*atan(0.5) else GLPerspective(stransform->fovxangle, ASPECT_RATIO); -#ifndef MINI_GL_COMPATIBILITY pglGetDoublev(GL_PROJECTION_MATRIX, projMatrix); // added for new coronas' code (without depth buffer) -#endif pglMatrixMode(GL_MODELVIEW); } else @@ -2220,15 +1904,11 @@ EXPORT void HWRAPI(SetTransform) (FTransform *stransform) else //Hurdler: is "fov" correct? GLPerspective(fov, ASPECT_RATIO); -#ifndef MINI_GL_COMPATIBILITY pglGetDoublev(GL_PROJECTION_MATRIX, projMatrix); // added for new coronas' code (without depth buffer) -#endif pglMatrixMode(GL_MODELVIEW); } -#ifndef MINI_GL_COMPATIBILITY pglGetDoublev(GL_MODELVIEW_MATRIX, modelMatrix); // added for new coronas' code (without depth buffer) -#endif } EXPORT INT32 HWRAPI(GetTextureUsed) (void) @@ -2249,7 +1929,6 @@ EXPORT INT32 HWRAPI(GetRenderVersion) (void) return VERSION; } -#ifdef SHUFFLE EXPORT void HWRAPI(PostImgRedraw) (float points[SCREENVERTS][SCREENVERTS][2]) { INT32 x, y; @@ -2269,16 +1948,25 @@ EXPORT void HWRAPI(PostImgRedraw) (float points[SCREENVERTS][SCREENVERTS][2]) pglDisable(GL_DEPTH_TEST); pglDisable(GL_BLEND); - pglBegin(GL_QUADS); + + const float blackBack[16] = + { + -16.0f, -16.0f, 6.0f, + -16.0f, 16.0f, 6.0f, + 16.0f, 16.0f, 6.0f, + 16.0f, -16.0f, 6.0f + }; + + pglEnableClientState(GL_VERTEX_ARRAY); // Draw a black square behind the screen texture, // so nothing shows through the edges pglColor4f(1.0f, 1.0f, 1.0f, 1.0f); - pglVertex3f(-16.0f, -16.0f, 6.0f); - pglVertex3f(-16.0f, 16.0f, 6.0f); - pglVertex3f(16.0f, 16.0f, 6.0f); - pglVertex3f(16.0f, -16.0f, 6.0f); + + pglVertexPointer(3, GL_FLOAT, 0, blackBack); + pglDrawArrays(GL_TRIANGLE_FAN, 0, 4); + pglEnableClientState(GL_TEXTURE_COORD_ARRAY); for(x=0;x #include -#ifndef MINI_GL_COMPATIBILITY #ifdef STATIC_OPENGL // Because of the 1.3 functions, you'll need GLext to compile it if static #define GL_GLEXT_PROTOTYPES #include #endif #endif -#endif #define _CREATE_DLL_ // necessary for Unix AND Windows #include "../../doomdef.h" diff --git a/src/sdl/hwsym_sdl.c b/src/sdl/hwsym_sdl.c index 7962e01b1..9f844c623 100644 --- a/src/sdl/hwsym_sdl.c +++ b/src/sdl/hwsym_sdl.c @@ -90,9 +90,7 @@ void *hwSym(const char *funcName,void *handle) GETFUNC(DrawModel); GETFUNC(SetTransform); GETFUNC(GetRenderVersion); -#ifdef SHUFFLE GETFUNC(PostImgRedraw); -#endif //SHUFFLE GETFUNC(FlushScreenTextures); GETFUNC(StartScreenWipe); GETFUNC(EndScreenWipe); diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 336a709df..11ad2be9a 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -1549,9 +1549,7 @@ void I_StartupGraphics(void) HWD.pfnDrawModel = hwSym("DrawModel",NULL); HWD.pfnSetTransform = hwSym("SetTransform",NULL); HWD.pfnGetRenderVersion = hwSym("GetRenderVersion",NULL); -#ifdef SHUFFLE HWD.pfnPostImgRedraw = hwSym("PostImgRedraw",NULL); -#endif HWD.pfnFlushScreenTextures=hwSym("FlushScreenTextures",NULL); HWD.pfnStartScreenWipe = hwSym("StartScreenWipe",NULL); HWD.pfnEndScreenWipe = hwSym("EndScreenWipe",NULL); diff --git a/src/win32/Srb2win-vc10.vcxproj.filters b/src/win32/Srb2win-vc10.vcxproj.filters index 1a2a7f80d..8f6077969 100644 --- a/src/win32/Srb2win-vc10.vcxproj.filters +++ b/src/win32/Srb2win-vc10.vcxproj.filters @@ -108,21 +108,9 @@ Hw_Hardware - - Hw_Hardware - - - Hw_Hardware - - - Hw_Hardware - Hw_Hardware - - Hw_Hardware - Hw_Hardware @@ -465,6 +453,10 @@ M_Misc + + + + From 6f70a07cb68657fef5d1ad28740719935b28b9c2 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Wed, 26 Dec 2018 23:15:28 -0500 Subject: [PATCH 20/66] Fix floating point comparisons --- src/hardware/hw_model.c | 4 +++- src/hardware/r_opengl/r_opengl.c | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/hardware/hw_model.c b/src/hardware/hw_model.c index 828339563..394b0f899 100644 --- a/src/hardware/hw_model.c +++ b/src/hardware/hw_model.c @@ -412,7 +412,9 @@ void GenerateVertexNormals(model_t *model) testY = *testPtr++; testZ = *testPtr++; - if (x != testX || y != testY || z != testZ) + if (fabsf(x - testX) > FLT_EPSILON + || fabsf(y - testY) > FLT_EPSILON + || fabsf(z - testZ) > FLT_EPSILON) continue; // Found a vertex match! Add it... diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 4f77680d9..22a4d7df8 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -964,7 +964,7 @@ EXPORT void HWRAPI(Draw2DLine) (F2DCoord * v1, c.alpha = byte2float[Color.s.alpha]; // This is the preferred, 'modern' way of rendering lines -- creating a polygon. - if (v2->x != v1->x) + if (fabsf(v2->x - v1->x) > FLT_EPSILON) angle = (float)atan((v2->y-v1->y)/(v2->x-v1->x)); else angle = (float)N_PI_DEMI; @@ -1770,7 +1770,7 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, INT32 duration, INT32 if (nextFrameIndex != -1) nextframe = &mesh->tinyframes[nextFrameIndex % mesh->numFrames]; - if (!nextframe || pol == 0.0f) + if (!nextframe || fpclassify(pol) == FP_ZERO) { pglVertexPointer(3, GL_SHORT, 0, frame->vertices); pglNormalPointer(GL_BYTE, 0, frame->normals); @@ -2151,6 +2151,8 @@ EXPORT void HWRAPI(DoScreenWipe)(float alpha) INT32 fademaskdownloaded = tex_downloaded; // the fade mask that has been set + (void)alpha; + // Use a power of two texture, dammit if(screen_width <= 1024) texsize = 1024; From d60b77b0625af01fb32e74511c407b7e06afe348 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Wed, 26 Dec 2018 23:31:55 -0500 Subject: [PATCH 21/66] Mixed D&C fixes --- src/hardware/hw_md2load.c | 99 ++++++++++++++++++++------- src/hardware/r_opengl/r_opengl.c | 112 ++++++++++++++++++++----------- 2 files changed, 144 insertions(+), 67 deletions(-) diff --git a/src/hardware/hw_md2load.c b/src/hardware/hw_md2load.c index d29414b0f..1d0e4f361 100644 --- a/src/hardware/hw_md2load.c +++ b/src/hardware/hw_md2load.c @@ -17,7 +17,7 @@ #define NUMVERTEXNORMALS 162 -// Quake 2 normals are indexed. Use avertexnormals[normalindex][x/y/z] and +// Quake 2 normals are indexed. Use avertexnormals[normalindex][x/y/z] and // you'll have your normals. float avertexnormals[NUMVERTEXNORMALS][3] = { {-0.525731f, 0.000000f, 0.850651f}, @@ -195,9 +195,9 @@ typedef struct int numXYZ; // Number of vertices in each frame int numST; // Number of texture coordinates in each frame. int numTris; // Number of triangles in each frame - int numGLcmds; // Number of dwords (4 bytes) in the gl command list. + int numGLcmds; // Number of dwords (4 bytes) in the gl command list. int numFrames; // Number of frames - int offsetSkins; // Offset, in bytes from the start of the file, to the list of skin names. + int offsetSkins; // Offset, in bytes from the start of the file, to the list of skin names. int offsetST; // Offset, in bytes from the start of the file, to the list of texture coordinates int offsetTris; // Offset, in bytes from the start of the file, to the list of triangles int offsetFrames; // Offset, in bytes from the start of the file, to the list of frames @@ -233,10 +233,36 @@ typedef struct // Load the model model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) { - useFloat = true; model_t *retModel = NULL; md2header_t *header; + size_t fileLen; + int i, j; + size_t namelen; + char *texturefilename; + const char *texPos; + + char *buffer; + + const float WUNITS = 1.0f; + float dataScale = WUNITS; + + int t; + + // MD2 currently does not work with tinyframes, so force useFloat = true + // + // + // the UV coordinates in MD2 are not compatible with glDrawElements like MD3 is. So they need to be loaded as full float. + // + // MD2 is intended to be draw in triangle strips and fans + // not very compatible with a modern GL implementation, either + // so the idea would be to full float expand it, and put it in a vertex buffer object + // I'm sure there's a way to convert the UVs to 'tinyframes', but maybe that's a job for someone else. + // You'd have to decompress the model, then recompress, reindexing the triangles and weeding out duplicate coordinates + // I already have the decompression work done + + useFloat = true; + FILE *f = fopen(fileName, "rb"); if (!f) @@ -244,13 +270,13 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) retModel = (model_t*)Z_Calloc(sizeof(model_t), ztag, 0); - size_t fileLen; + //size_t fileLen; - int i, j; + //int i, j; - size_t namelen; - char *texturefilename; - const char *texPos = strchr(fileName, '/'); + //size_t namelen; + //char *texturefilename; + texPos = strchr(fileName, '/'); if (texPos) { @@ -276,7 +302,7 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) fseek(f, 0, SEEK_SET); // read in file - char *buffer = malloc(fileLen); + buffer = malloc(fileLen); fread(buffer, fileLen, 1, f); fclose(f); @@ -286,8 +312,8 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) retModel->numMeshes = 1; // MD2 only has one mesh retModel->meshes = (mesh_t*)Z_Calloc(sizeof(mesh_t) * retModel->numMeshes, ztag, 0); retModel->meshes[0].numFrames = header->numFrames; - const float WUNITS = 1.0f; - float dataScale = WUNITS; + // const float WUNITS = 1.0f; + // float dataScale = WUNITS; // Tris and ST are simple structures that can be straight-copied md2triangle_t *tris = (md2triangle_t*)&buffer[header->offsetTris]; @@ -302,7 +328,7 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) retModel->materials = (material_t*)Z_Calloc(sizeof(material_t)*retModel->numMaterials, ztag, 0); - int t; + // int t; for (t = 0; t < retModel->numMaterials; t++) { retModel->materials[t].ambient[0] = 0.8f; @@ -370,14 +396,26 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) if (!useFloat) // Decompress to MD3 'tinyframe' space { + byte *ptr; + + md2triangle_t *trisPtr; + unsigned short *indexptr; + float *uvptr; + dataScale = 0.015624f; // 1 / 64.0f retModel->meshes[0].tinyframes = (tinyframe_t*)Z_Calloc(sizeof(tinyframe_t)*header->numFrames, ztag, 0); retModel->meshes[0].numVertices = header->numXYZ; retModel->meshes[0].uvs = (float*)Z_Malloc(sizeof(float) * 2 * retModel->meshes[0].numVertices, ztag, 0); - byte *ptr = (byte*)frames; + ptr = (byte*)frames; for (i = 0; i < header->numFrames; i++, ptr += header->framesize) { + short *vertptr; + char *normptr; + // char *tanptr; + + md2vertex_t *vertex; + md2frame_t *framePtr = (md2frame_t*)ptr; retModel->meshes[0].tinyframes[i].vertices = (short*)Z_Malloc(sizeof(short) * 3 * header->numXYZ, ztag, 0); retModel->meshes[0].tinyframes[i].normals = (char*)Z_Malloc(sizeof(char) * 3 * header->numXYZ, ztag, 0); @@ -386,14 +424,14 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) // retModel->meshes[0].tinyframes[i].tangents = (char*)malloc(sizeof(char));//(char*)Z_Malloc(sizeof(char)*3*header->numVerts, ztag); retModel->meshes[0].indices = (unsigned short*)Z_Malloc(sizeof(unsigned short) * 3 * header->numTris, ztag, 0); - short *vertptr = retModel->meshes[0].tinyframes[i].vertices; - char *normptr = retModel->meshes[0].tinyframes[i].normals; + vertptr = retModel->meshes[0].tinyframes[i].vertices; + normptr = retModel->meshes[0].tinyframes[i].normals; - // char *tanptr = retModel->meshes[0].tinyframes[i].tangents; + // tanptr = retModel->meshes[0].tinyframes[i].tangents; retModel->meshes[0].tinyframes[i].material = &retModel->materials[0]; framePtr++; // Advance to vertex list - md2vertex_t *vertex = (md2vertex_t*)framePtr; + vertex = (md2vertex_t*)framePtr; framePtr--; for (j = 0; j < header->numXYZ; j++, vertex++) { @@ -412,9 +450,9 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) } // This doesn't need to be done every frame! - md2triangle_t *trisPtr = tris; - unsigned short *indexptr = retModel->meshes[0].indices; - float *uvptr = (float*)retModel->meshes[0].uvs; + trisPtr = tris; + indexptr = retModel->meshes[0].indices; + uvptr = (float*)retModel->meshes[0].uvs; for (j = 0; j < header->numTris; j++, trisPtr++) { *indexptr = trisPtr->meshIndex[0]; @@ -434,12 +472,17 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) } else // Full float loading method { + md2triangle_t *trisPtr; + float *uvptr; + + byte *ptr; + retModel->meshes[0].numVertices = header->numTris * 3; retModel->meshes[0].frames = (mdlframe_t*)Z_Calloc(sizeof(mdlframe_t)*header->numFrames, ztag, 0); retModel->meshes[0].uvs = (float*)Z_Malloc(sizeof(float) * 2 * retModel->meshes[0].numVertices, ztag, 0); - md2triangle_t *trisPtr = tris; - float *uvptr = retModel->meshes[0].uvs; + trisPtr = tris; + uvptr = retModel->meshes[0].uvs; for (i = 0; i < retModel->meshes[0].numTriangles; i++, trisPtr++) { *uvptr++ = texcoords[trisPtr->stIndex[0]].s / (float)header->skinwidth; @@ -450,15 +493,19 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) *uvptr++ = (texcoords[trisPtr->stIndex[2]].t / (float)header->skinheight); } - byte *ptr = (byte*)frames; + ptr = (byte*)frames; for (i = 0; i < header->numFrames; i++, ptr += header->framesize) { + float *vertptr, *normptr; + + md2vertex_t *vertex; + md2frame_t *framePtr = (md2frame_t*)ptr; retModel->meshes[0].frames[i].normals = (float*)Z_Malloc(sizeof(float) * 3 * header->numTris * 3, ztag, 0); retModel->meshes[0].frames[i].vertices = (float*)Z_Malloc(sizeof(float) * 3 * header->numTris * 3, ztag, 0); // if (retModel->materials[0].lightmap) // retModel->meshes[0].frames[i].tangents = (float*)malloc(sizeof(float));//(float*)Z_Malloc(sizeof(float)*3*header->numTris*3, ztag); - float *vertptr, *normptr; + //float *vertptr, *normptr; normptr = (float*)retModel->meshes[0].frames[i].normals; vertptr = (float*)retModel->meshes[0].frames[i].vertices; trisPtr = tris; @@ -466,7 +513,7 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) retModel->meshes[0].frames[i].material = &retModel->materials[0]; framePtr++; // Advance to vertex list - md2vertex_t *vertex = (md2vertex_t*)framePtr; + vertex = (md2vertex_t*)framePtr; framePtr--; for (j = 0; j < header->numTris; j++, trisPtr++) { diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 22a4d7df8..3410ed3ec 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -1652,8 +1652,7 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, INT32 duration, INT32 GLfloat diffuse[4]; float pol = 0.0f; - scale *= 0.5f; - float scalex = scale, scaley = scale, scalez = scale; + float scalex, scaley, scalez; boolean useTinyFrames; @@ -1662,6 +1661,12 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, INT32 duration, INT32 // Because Otherwise, scaling the screen negatively vertically breaks the lighting GLfloat LightPos[] = {0.0f, 1.0f, 0.0f, 0.0f}; + // Affect input model scaling + scale *= 0.5f; + scalex = scale; + scaley = scale; + scalez = scale; + if (duration != 0 && duration != -1 && tics != -1) // don't interpolate if instantaneous or infinite in length { UINT32 newtime = (duration - tics); // + 1; @@ -1779,11 +1784,15 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, INT32 duration, INT32 } else { + short *vertPtr; + char *normPtr; + int j; + // Dangit, I soooo want to do this in a GLSL shader... AllocLerpTinyBuffer(mesh->numVertices * sizeof(short) * 3); - short *vertPtr = vertTinyBuffer; - char *normPtr = normTinyBuffer; - int j = 0; + vertPtr = vertTinyBuffer; + normPtr = normTinyBuffer; + j = 0; for (j = 0; j < mesh->numVertices * 3; j++) { @@ -1816,10 +1825,13 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, INT32 duration, INT32 } else { + float *vertPtr; + float *normPtr; + // Dangit, I soooo want to do this in a GLSL shader... AllocLerpBuffer(mesh->numVertices * sizeof(float) * 3); - float *vertPtr = vertBuffer; - float *normPtr = normBuffer; + vertPtr = vertBuffer; + normPtr = normBuffer; int j = 0; for (j = 0; j < mesh->numVertices * 3; j++) @@ -1936,6 +1948,14 @@ EXPORT void HWRAPI(PostImgRedraw) (float points[SCREENVERTS][SCREENVERTS][2]) float xfix, yfix; INT32 texsize = 2048; + const float blackBack[16] = + { + -16.0f, -16.0f, 6.0f, + -16.0f, 16.0f, 6.0f, + 16.0f, 16.0f, 6.0f, + 16.0f, -16.0f, 6.0f + }; + // Use a power of two texture, dammit if(screen_width <= 1024) texsize = 1024; @@ -1949,13 +1969,7 @@ EXPORT void HWRAPI(PostImgRedraw) (float points[SCREENVERTS][SCREENVERTS][2]) pglDisable(GL_DEPTH_TEST); pglDisable(GL_BLEND); - const float blackBack[16] = - { - -16.0f, -16.0f, 6.0f, - -16.0f, 16.0f, 6.0f, - 16.0f, 16.0f, 6.0f, - 16.0f, -16.0f, 6.0f - }; + // const float blackBack[16] pglEnableClientState(GL_VERTEX_ARRAY); @@ -1971,6 +1985,9 @@ EXPORT void HWRAPI(PostImgRedraw) (float points[SCREENVERTS][SCREENVERTS][2]) { for(y=0;y Date: Wed, 26 Dec 2018 23:40:29 -0500 Subject: [PATCH 22/66] byte -> char --- src/hardware/hw_md2load.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/hardware/hw_md2load.c b/src/hardware/hw_md2load.c index 1d0e4f361..84b1bc531 100644 --- a/src/hardware/hw_md2load.c +++ b/src/hardware/hw_md2load.c @@ -396,7 +396,7 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) if (!useFloat) // Decompress to MD3 'tinyframe' space { - byte *ptr; + char *ptr; md2triangle_t *trisPtr; unsigned short *indexptr; @@ -407,7 +407,7 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) retModel->meshes[0].numVertices = header->numXYZ; retModel->meshes[0].uvs = (float*)Z_Malloc(sizeof(float) * 2 * retModel->meshes[0].numVertices, ztag, 0); - ptr = (byte*)frames; + ptr = (char*)frames; for (i = 0; i < header->numFrames; i++, ptr += header->framesize) { short *vertptr; @@ -475,7 +475,7 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) md2triangle_t *trisPtr; float *uvptr; - byte *ptr; + char *ptr; retModel->meshes[0].numVertices = header->numTris * 3; retModel->meshes[0].frames = (mdlframe_t*)Z_Calloc(sizeof(mdlframe_t)*header->numFrames, ztag, 0); @@ -493,7 +493,7 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) *uvptr++ = (texcoords[trisPtr->stIndex[2]].t / (float)header->skinheight); } - ptr = (byte*)frames; + ptr = (char*)frames; for (i = 0; i < header->numFrames; i++, ptr += header->framesize) { float *vertptr, *normptr; From c0547d56aa93e1d74663ad7f500c494f226f22ed Mon Sep 17 00:00:00 2001 From: mazmazz Date: Wed, 26 Dec 2018 23:50:35 -0500 Subject: [PATCH 23/66] More mixed d&c fixes --- src/hardware/hw_md2load.c | 14 ++++++++++---- src/hardware/r_opengl/r_opengl.c | 3 ++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/hardware/hw_md2load.c b/src/hardware/hw_md2load.c index 84b1bc531..ddf89f8db 100644 --- a/src/hardware/hw_md2load.c +++ b/src/hardware/hw_md2load.c @@ -233,6 +233,8 @@ typedef struct // Load the model model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) { + FILE *f; + model_t *retModel = NULL; md2header_t *header; @@ -247,6 +249,10 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) const float WUNITS = 1.0f; float dataScale = WUNITS; + md2triangle_t *tris; + md2texcoord_t *texcoords; + md2frame_t *frames; + int t; // MD2 currently does not work with tinyframes, so force useFloat = true @@ -263,7 +269,7 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) useFloat = true; - FILE *f = fopen(fileName, "rb"); + f = fopen(fileName, "rb"); if (!f) return NULL; @@ -316,9 +322,9 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) // float dataScale = WUNITS; // Tris and ST are simple structures that can be straight-copied - md2triangle_t *tris = (md2triangle_t*)&buffer[header->offsetTris]; - md2texcoord_t *texcoords = (md2texcoord_t*)&buffer[header->offsetST]; - md2frame_t *frames = (md2frame_t*)&buffer[header->offsetFrames]; + tris = (md2triangle_t*)&buffer[header->offsetTris]; + texcoords = (md2texcoord_t*)&buffer[header->offsetST]; + frames = (md2frame_t*)&buffer[header->offsetFrames]; // Read in textures retModel->numMaterials = header->numSkins; diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 3410ed3ec..f7f9dd5bd 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -1827,12 +1827,13 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, INT32 duration, INT32 { float *vertPtr; float *normPtr; + int j = 0; // Dangit, I soooo want to do this in a GLSL shader... AllocLerpBuffer(mesh->numVertices * sizeof(float) * 3); vertPtr = vertBuffer; normPtr = normBuffer; - int j = 0; + //int j = 0; for (j = 0; j < mesh->numVertices * 3; j++) { From dbcdacc8bb97de1a9c472f1c5149332ca145cb39 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 27 Dec 2018 00:01:51 -0500 Subject: [PATCH 24/66] Ignored fread fix --- src/hardware/hw_md2load.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hardware/hw_md2load.c b/src/hardware/hw_md2load.c index ddf89f8db..3805deffb 100644 --- a/src/hardware/hw_md2load.c +++ b/src/hardware/hw_md2load.c @@ -309,7 +309,7 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) // read in file buffer = malloc(fileLen); - fread(buffer, fileLen, 1, f); + if (fread(buffer, fileLen, 1, f)) { } // squash ignored fread error fclose(f); // get pointer to file header From 191f9454c32f5de4eb739dda6e3bf068fb09f858 Mon Sep 17 00:00:00 2001 From: Arthur Date: Mon, 24 Dec 2018 12:08:00 -0500 Subject: [PATCH 25/66] boolean fix for VS add GL_NORMALIZE --- src/hardware/r_opengl/r_opengl.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index f7f9dd5bd..6813b9564 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -1700,6 +1700,7 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, INT32 duration, INT32 } pglEnable(GL_CULL_FACE); + pglEnable(GL_NORMALIZE); #ifdef USE_FTRANSFORM_MIRROR // flipped is if the object is flipped @@ -1859,6 +1860,7 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, INT32 duration, INT32 pglDisable(GL_LIGHTING); pglShadeModel(GL_FLAT); pglDisable(GL_CULL_FACE); + pglDisable(GL_NORMALIZE); } // -----------------+ From f5562c47ec6a254edf2f92885326e02dd78107a0 Mon Sep 17 00:00:00 2001 From: Arthur Date: Tue, 25 Dec 2018 21:28:51 -0500 Subject: [PATCH 26/66] Removed unused PF_Md2 flag More OpenGL performance increase by making assumptions about client state --- src/hardware/hw_defs.h | 2 +- src/hardware/r_opengl/r_opengl.c | 142 ++++++++++++------------------- src/hardware/r_opengl/r_opengl.h | 2 + 3 files changed, 58 insertions(+), 88 deletions(-) diff --git a/src/hardware/hw_defs.h b/src/hardware/hw_defs.h index 04f63af71..767eac0b6 100644 --- a/src/hardware/hw_defs.h +++ b/src/hardware/hw_defs.h @@ -166,7 +166,7 @@ enum EPolyFlags // When set, pass the color constant into the FSurfaceInfo -> FlatColor PF_NoTexture = 0x00002000, // Use the small white texture PF_Corona = 0x00004000, // Tell the rendrer we are drawing a corona - PF_MD2 = 0x00008000, // Tell the rendrer we are drawing an MD2 + PF_Unused = 0x00008000, // Unused PF_RemoveYWrap = 0x00010000, // Force clamp texture on Y PF_ForceWrapX = 0x00020000, // Force repeat texture on X PF_ForceWrapY = 0x00040000, // Force repeat texture on Y diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 6813b9564..fc6c21f13 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -42,6 +42,7 @@ struct GLRGBAFloat GLfloat alpha; }; typedef struct GLRGBAFloat GLRGBAFloat; +static const float white[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; // ========================================================================== // CONSTANTS @@ -541,7 +542,7 @@ boolean SetupGLFunc13(void) pglMultiTexCoord2f = GetGLFunc("glMultiTexCoord2f"); pglClientActiveTexture = GetGLFunc("glClientActiveTexture"); pglMultiTexCoord2fv = GetGLFunc("glMultiTexCoord2fv"); - + return true; } @@ -936,6 +937,8 @@ EXPORT void HWRAPI(ClearBuffer) (FBOOLEAN ColorMask, SetBlend(DepthMask ? PF_Occlude | CurrentPolyFlags : CurrentPolyFlags&~PF_Occlude); pglClear(ClearMask); + pglEnableClientState(GL_VERTEX_ARRAY); // We always use this one + pglEnableClientState(GL_TEXTURE_COORD_ARRAY); // And mostly this one, too } @@ -976,12 +979,12 @@ EXPORT void HWRAPI(Draw2DLine) (F2DCoord * v1, p[6] = v2->x + dx; p[7] = -(v2->y - dy); p[8] = 1; p[9] = v1->x + dx; p[10] = -(v1->y - dy); p[11] = 1; + pglDisableClientState(GL_TEXTURE_COORD_ARRAY); pglColor4fv(&c.red); // is in RGBA float format - pglEnableClientState(GL_VERTEX_ARRAY); pglVertexPointer(3, GL_FLOAT, 0, p); pglDrawArrays(GL_TRIANGLE_FAN, 0, 4); - pglDisableClientState(GL_VERTEX_ARRAY); + pglEnableClientState(GL_TEXTURE_COORD_ARRAY); pglEnable(GL_TEXTURE_2D); } @@ -1094,7 +1097,7 @@ EXPORT void HWRAPI(SetBlend) (FBITFIELD PolyFlags) if (oglflags & GLF_NOTEXENV) { if (!(PolyFlags & PF_Modulated)) - pglColor4f(1.0f, 1.0f, 1.0f, 1.0f); + pglColor4fv(white); } else #endif @@ -1452,16 +1455,9 @@ EXPORT void HWRAPI(DrawPolygon) (FSurfaceInfo *pSurf, pglColor4fv(&c.red); } - if (PolyFlags & PF_MD2) - return; - - pglEnableClientState(GL_VERTEX_ARRAY); - pglEnableClientState(GL_TEXTURE_COORD_ARRAY); pglVertexPointer(3, GL_FLOAT, sizeof(FOutVector), &pOutVerts[0].x); pglTexCoordPointer(2, GL_FLOAT, sizeof(FOutVector), &pOutVerts[0].sow); pglDrawArrays(GL_TRIANGLE_FAN, 0, iNumPts); - pglDisableClientState(GL_TEXTURE_COORD_ARRAY); - pglDisableClientState(GL_VERTEX_ARRAY); if (PolyFlags & PF_RemoveYWrap) pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); @@ -1760,8 +1756,6 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, INT32 duration, INT32 if (useTinyFrames) pglScalef(1 / 64.0f, 1 / 64.0f, 1 / 64.0f); - pglEnableClientState(GL_VERTEX_ARRAY); - pglEnableClientState(GL_TEXTURE_COORD_ARRAY); pglEnableClientState(GL_NORMAL_ARRAY); for (i = 0; i < model->numMeshes; i++) @@ -1852,8 +1846,6 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, INT32 duration, INT32 } pglDisableClientState(GL_NORMAL_ARRAY); - pglDisableClientState(GL_TEXTURE_COORD_ARRAY); - pglDisableClientState(GL_VERTEX_ARRAY); pglPopMatrix(); // should be the same as glLoadIdentity if (color) @@ -1974,65 +1966,59 @@ EXPORT void HWRAPI(PostImgRedraw) (float points[SCREENVERTS][SCREENVERTS][2]) // const float blackBack[16] - pglEnableClientState(GL_VERTEX_ARRAY); + // Draw a black square behind the screen texture, + // so nothing shows through the edges + pglColor4fv(white); - // Draw a black square behind the screen texture, - // so nothing shows through the edges - pglColor4f(1.0f, 1.0f, 1.0f, 1.0f); - - pglVertexPointer(3, GL_FLOAT, 0, blackBack); - pglDrawArrays(GL_TRIANGLE_FAN, 0, 4); + pglVertexPointer(3, GL_FLOAT, 0, blackBack); + pglDrawArrays(GL_TRIANGLE_FAN, 0, 4); - pglEnableClientState(GL_TEXTURE_COORD_ARRAY); - for(x=0;x Date: Wed, 26 Dec 2018 10:58:37 -0500 Subject: [PATCH 27/66] Removed gr_voodoocompatibility as even low-power mobile devices do not have this limitation No longer using byte2float in DrawPolygon -- use the surface color data directly Vertex Buffer Objects for non-interpolated model frames Removed some old unused paletted texture stuff --- src/d_main.c | 3 - src/doomtype.h | 16 +- src/hardware/hw_cache.c | 61 ------- src/hardware/hw_defs.h | 2 - src/hardware/hw_drv.h | 2 + src/hardware/hw_main.c | 5 - src/hardware/hw_main.h | 2 - src/hardware/hw_md2.c | 1 + src/hardware/hw_model.c | 138 ---------------- src/hardware/r_opengl/r_opengl.c | 267 ++++++++++++++++++++++++------- src/hardware/r_opengl/r_vbo.h | 52 ++++++ src/r_main.c | 1 - src/sdl/hwsym_sdl.c | 1 + src/sdl/i_video.c | 1 + src/v_video.c | 1 - src/w_wad.c | 4 +- 16 files changed, 276 insertions(+), 281 deletions(-) create mode 100644 src/hardware/r_opengl/r_vbo.h diff --git a/src/d_main.c b/src/d_main.c index 31781cba2..5352ce6e4 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -634,9 +634,6 @@ void D_SRB2Loop(void) if (dedicated) server = true; - if (M_CheckParm("-voodoo")) // 256x256 Texture Limiter - COM_BufAddText("gr_voodoocompatibility on\n"); - // Pushing of + parameters is now done back in D_SRB2Main, not here. CONS_Printf("I_StartupKeyboard()...\n"); diff --git a/src/doomtype.h b/src/doomtype.h index 5d6434845..67491abb3 100644 --- a/src/doomtype.h +++ b/src/doomtype.h @@ -366,16 +366,18 @@ size_t strlcpy(char *dst, const char *src, size_t siz); /* Miscellaneous types that don't fit anywhere else (Can this be changed?) */ +typedef struct +{ + UINT8 red; + UINT8 green; + UINT8 blue; + UINT8 alpha; +} byteColor_t; + union FColorRGBA { UINT32 rgba; - struct - { - UINT8 red; - UINT8 green; - UINT8 blue; - UINT8 alpha; - } s; + byteColor_t s; } ATTRPACK; typedef union FColorRGBA RGBA_t; diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c index 78fc31afc..d49531bdf 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.c @@ -241,43 +241,6 @@ static void HWR_ResizeBlock(INT32 originalwidth, INT32 originalheight, if (blockheight < 1) I_Error("3D GenerateTexture : too small"); } - else if (cv_voodoocompatibility.value) - { - if (originalwidth > 256 || originalheight > 256) - { - blockwidth = 256; - while (originalwidth < blockwidth) - blockwidth >>= 1; - if (blockwidth < 1) - I_Error("3D GenerateTexture : too small"); - - blockheight = 256; - while (originalheight < blockheight) - blockheight >>= 1; - if (blockheight < 1) - I_Error("3D GenerateTexture : too small"); - } - else - { - //size up to nearest power of 2 - blockwidth = 1; - while (blockwidth < originalwidth) - blockwidth <<= 1; - // scale down the original graphics to fit in 256 - if (blockwidth > 256) - blockwidth = 256; - //I_Error("3D GenerateTexture : too big"); - - //size up to nearest power of 2 - blockheight = 1; - while (blockheight < originalheight) - blockheight <<= 1; - // scale down the original graphics to fit in 256 - if (blockheight > 256) - blockheight = 255; - //I_Error("3D GenerateTexture : too big"); - } - } else { //size up to nearest power of 2 @@ -508,18 +471,6 @@ void HWR_MakePatch (const patch_t *patch, GLPatch_t *grPatch, GLMipmap_t *grMipm newwidth = blockwidth; newheight = blockheight; } - else if (cv_voodoocompatibility.value) // Only scales down textures that exceed 256x256. - { - // no rounddown, do not size up patches, so they don't look 'scaled' - newwidth = min(grPatch->width, blockwidth); - newheight = min(grPatch->height, blockheight); - - if (newwidth > 256 || newheight > 256) - { - newwidth = blockwidth; - newheight = blockheight; - } - } else { // no rounddown, do not size up patches, so they don't look 'scaled' @@ -935,18 +886,6 @@ GLPatch_t *HWR_GetPic(lumpnum_t lumpnum) newwidth = blockwidth; newheight = blockheight; } - else if (cv_voodoocompatibility.value) // Only scales down textures that exceed 256x256. - { - // no rounddown, do not size up patches, so they don't look 'scaled' - newwidth = min(SHORT(pic->width),blockwidth); - newheight = min(SHORT(pic->height),blockheight); - - if (newwidth > 256 || newheight > 256) - { - newwidth = blockwidth; - newheight = blockheight; - } - } else { // no rounddown, do not size up patches, so they don't look 'scaled' diff --git a/src/hardware/hw_defs.h b/src/hardware/hw_defs.h index 767eac0b6..a1e4ad19a 100644 --- a/src/hardware/hw_defs.h +++ b/src/hardware/hw_defs.h @@ -224,8 +224,6 @@ enum hwdsetspecialstate HWD_SET_FOG_COLOR, HWD_SET_FOG_DENSITY, HWD_SET_FOV, - HWD_SET_POLYGON_SMOOTH, - HWD_SET_PALETTECOLOR, HWD_SET_TEXTUREFILTERMODE, HWD_SET_TEXTUREANISOTROPICMODE, HWD_NUMSTATE diff --git a/src/hardware/hw_drv.h b/src/hardware/hw_drv.h index c1ece091a..e1d050cf8 100644 --- a/src/hardware/hw_drv.h +++ b/src/hardware/hw_drv.h @@ -59,6 +59,7 @@ EXPORT void HWRAPI(SetSpecialState) (hwdspecialstate_t IdState, INT32 Value); //Hurdler: added for new development EXPORT void HWRAPI(DrawModel) (model_t *model, INT32 frameIndex, INT32 duration, INT32 tics, INT32 nextFrameIndex, FTransform *pos, float scale, UINT8 flipped, UINT8 *color); +EXPORT void HWRAPI(CreateModelVBOs) (model_t *model); EXPORT void HWRAPI(SetTransform) (FTransform *ptransform); EXPORT INT32 HWRAPI(GetTextureUsed) (void); EXPORT INT32 HWRAPI(GetRenderVersion) (void); @@ -94,6 +95,7 @@ struct hwdriver_s ClearMipMapCache pfnClearMipMapCache; SetSpecialState pfnSetSpecialState;//Hurdler: added for backward compatibility DrawModel pfnDrawModel; + CreateModelVBOs pfnCreateModelVBOs; SetTransform pfnSetTransform; GetTextureUsed pfnGetTextureUsed; GetRenderVersion pfnGetRenderVersion; diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index fc70492ca..2f5f6c488 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -6783,11 +6783,6 @@ static void HWR_RenderWall(wallVert3D *wallVerts, FSurfaceInfo *pSurf, FBITFIE #endif } -void HWR_SetPaletteColor(INT32 palcolor) -{ - HWD.pfnSetSpecialState(HWD_SET_PALETTECOLOR, palcolor); -} - INT32 HWR_GetTextureUsed(void) { return HWD.pfnGetTextureUsed(); diff --git a/src/hardware/hw_main.h b/src/hardware/hw_main.h index f74814f00..b8b3e3edc 100644 --- a/src/hardware/hw_main.h +++ b/src/hardware/hw_main.h @@ -59,7 +59,6 @@ void HWR_AddCommands(void); void HWR_CorrectSWTricks(void); void transform(float *cx, float *cy, float *cz); FBITFIELD HWR_TranstableToAlpha(INT32 transtablenum, FSurfaceInfo *pSurf); -void HWR_SetPaletteColor(INT32 palcolor); INT32 HWR_GetTextureUsed(void); void HWR_DoPostProcessor(player_t *player); void HWR_StartScreenWipe(void); @@ -93,7 +92,6 @@ extern consvar_t cv_grgammablue; extern consvar_t cv_grfiltermode; extern consvar_t cv_granisotropicmode; extern consvar_t cv_grcorrecttricks; -extern consvar_t cv_voodoocompatibility; extern consvar_t cv_grfovchange; extern consvar_t cv_grsolvetjoin; diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.c index 33cd8b8a3..b70d0d6a3 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -926,6 +926,7 @@ void HWR_DrawMD2(gr_vissprite_t *spr) if (md2->model) { md2_printModelInfo(md2->model); + HWD.pfnCreateModelVBOs(md2->model); } else { diff --git a/src/hardware/hw_model.c b/src/hardware/hw_model.c index 394b0f899..2c36f9744 100644 --- a/src/hardware/hw_model.c +++ b/src/hardware/hw_model.c @@ -49,117 +49,6 @@ void VectorRotate(vector_t *rotVec, const vector_t *axisVec, float angle) rotVec->z = axisVec->z*(ux + vy + wz) + (rotVec->z*(axisVec->x*axisVec->x + axisVec->y*axisVec->y) - axisVec->z*(ux + vy))*ca + (-vx + uy)*sa; } -void CreateVBOTiny(mesh_t *mesh, tinyframe_t *frame) -{ - (void)mesh; - (void)frame; - return; -/* int bufferSize = sizeof(VBO::vbotiny_t)*mesh->numTriangles*3; - VBO::vbotiny_t *buffer = (VBO::vbotiny_t*)Z_Malloc(bufferSize, PU_STATIC, 0); - VBO::vbotiny_t *bufPtr = buffer; - - short *vertPtr = frame->vertices; - char *normPtr = frame->normals; - float *uvPtr = mesh->uvs; - char *tanPtr = frame->tangents; - - int i; - for (i = 0; i < mesh->numTriangles*3; i++) - { - bufPtr->x = *vertPtr++; - bufPtr->y = *vertPtr++; - bufPtr->z = *vertPtr++; - - bufPtr->nx = (*normPtr++) * 127; - bufPtr->ny = (*normPtr++) * 127; - bufPtr->nz = (*normPtr++) * 127; - - bufPtr->s0 = *uvPtr++; - bufPtr->t0 = *uvPtr++; - - if (tanPtr) - { - bufPtr->tanx = *tanPtr++; - bufPtr->tany = *tanPtr++; - bufPtr->tanz = *tanPtr++; - } - - bufPtr++; - } - - bglGenBuffers(1, &frame->vboID); - bglBindBuffer(BGL_ARRAY_BUFFER, frame->vboID); - bglBufferData(BGL_ARRAY_BUFFER, bufferSize, buffer, BGL_STATIC_DRAW); - Z_Free(buffer);*/ -} - -void CreateVBO(mesh_t *mesh, mdlframe_t *frame) -{ - (void)mesh; - (void)frame; - return; -/* int bufferSize = sizeof(VBO::vbo64_t)*mesh->numTriangles*3; - VBO::vbo64_t *buffer = (VBO::vbo64_t*)Z_Malloc(bufferSize, PU_STATIC, 0); - VBO::vbo64_t *bufPtr = buffer; - - float *vertPtr = frame->vertices; - float *normPtr = frame->normals; - float *tanPtr = frame->tangents; - float *uvPtr = mesh->uvs; - float *lightPtr = mesh->lightuvs; - char *colorPtr = frame->colors; - - int i; - for (i = 0; i < mesh->numTriangles*3; i++) - { - bufPtr->x = *vertPtr++; - bufPtr->y = *vertPtr++; - bufPtr->z = *vertPtr++; - - bufPtr->nx = *normPtr++; - bufPtr->ny = *normPtr++; - bufPtr->nz = *normPtr++; - - bufPtr->s0 = *uvPtr++; - bufPtr->t0 = *uvPtr++; - - if (tanPtr != NULL) - { - bufPtr->tan0 = *tanPtr++; - bufPtr->tan1 = *tanPtr++; - bufPtr->tan2 = *tanPtr++; - } - - if (lightPtr != NULL) - { - bufPtr->s1 = *lightPtr++; - bufPtr->t1 = *lightPtr++; - } - - if (colorPtr) - { - bufPtr->r = *colorPtr++; - bufPtr->g = *colorPtr++; - bufPtr->b = *colorPtr++; - bufPtr->a = *colorPtr++; - } - else - { - bufPtr->r = 255; - bufPtr->g = 255; - bufPtr->b = 255; - bufPtr->a = 255; - } - - bufPtr++; - } - - bglGenBuffers(1, &frame->vboID); - bglBindBuffer(BGL_ARRAY_BUFFER, frame->vboID); - bglBufferData(BGL_ARRAY_BUFFER, bufferSize, buffer, BGL_STATIC_DRAW); - Z_Free(buffer);*/ -} - void UnloadModel(model_t *model) { // Wouldn't it be great if C just had destructors? @@ -326,33 +215,6 @@ model_t *LoadModel(const char *filename, int ztag) material->shininess = 25.0f; } -// CONS_Printf("Generating VBOs for %s\n", filename); - for (i = 0; i < model->numMeshes; i++) - { - mesh_t *mesh = &model->meshes[i]; - - if (mesh->frames) - { - int j; - for (j = 0; j < model->meshes[i].numFrames; j++) - { - mdlframe_t *frame = &mesh->frames[j]; - frame->vboID = 0; - CreateVBO(mesh, frame); - } - } - else if (mesh->tinyframes) - { - int j; - for (j = 0; j < model->meshes[i].numFrames; j++) - { - tinyframe_t *frame = &mesh->tinyframes[j]; - frame->vboID = 0; - CreateVBOTiny(mesh, frame); - } - } - } - return model; } diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index fc6c21f13..ce1491979 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -30,6 +30,7 @@ #include #include #include "r_opengl.h" +#include "r_vbo.h" #if defined (HWRENDER) && !defined (NOROPENGL) // for KOS: GL_TEXTURE_ENV, glAlphaFunc, glColorMask, glPolygonOffset, glReadPixels, GL_ALPHA_TEST, GL_POLYGON_OFFSET_FILL @@ -42,7 +43,7 @@ struct GLRGBAFloat GLfloat alpha; }; typedef struct GLRGBAFloat GLRGBAFloat; -static const float white[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; +static const GLubyte white[4] = { 255, 255, 255, 255 }; // ========================================================================== // CONSTANTS @@ -227,6 +228,8 @@ FUNCPRINTF void DBG_Printf(const char *lpFmt, ...) #define pglNormal3bv glNormal3bv #define pglColor4f glColor4f #define pglColor4fv glColor4fv +#define pglColor4ub glColor4ub +#define pglColor4ubv glColor4ubv #define pglTexCoord2f glTexCoord2f #define pglTexCoord2fv glTexCoord2fv #define pglVertexPointer glVertexPointer @@ -237,6 +240,10 @@ FUNCPRINTF void DBG_Printf(const char *lpFmt, ...) #define pglEnableClientState glEnableClientState #define pglDisableClientState glDisableClientState #define pglClientActiveTexture glClientActiveTexture +#define pglGenBuffers glGenBuffers +#define pglBindBuffer glBindBuffer +#define pglBufferData glBufferData +#define pglDeleteBuffers glDeleteBuffers /* Lighting */ #define pglShadeModel glShadeModel @@ -346,6 +353,10 @@ typedef void (APIENTRY * PFNglColor4f) (GLfloat red, GLfloat green, GLfloat blue static PFNglColor4f pglColor4f; typedef void (APIENTRY * PFNglColor4fv) (const GLfloat *v); static PFNglColor4fv pglColor4fv; +typedef void (APIENTRY * PFNglColor4ub) (GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha); +static PFNglColor4ub pglColor4ub; +typedef void (APIENTRY * PFNglColor4ubv) (const GLubyte *v); +static PFNglColor4ubv pglColor4ubv; typedef void (APIENTRY * PFNglTexCoord2f) (GLfloat s, GLfloat t); static PFNglTexCoord2f pglTexCoord2f; typedef void (APIENTRY * PFNglTexCoord2fv) (const GLfloat *v); @@ -364,6 +375,15 @@ typedef void (APIENTRY * PFNglEnableClientState) (GLenum cap); static PFNglEnableClientState pglEnableClientState; typedef void (APIENTRY * PFNglDisableClientState) (GLenum cap); static PFNglDisableClientState pglDisableClientState; +typedef void (APIENTRY * PFNglGenBuffers) (GLsizei n, GLuint *buffers); +static PFNglGenBuffers pglGenBuffers; +typedef void (APIENTRY * PFNglBindBuffer) (GLenum target, GLuint buffer); +static PFNglBindBuffer pglBindBuffer; +typedef void (APIENTRY * PFNglBufferData) (GLenum target, GLsizei size, const GLvoid *data, GLenum usage); +static PFNglBufferData pglBufferData; +typedef void (APIENTRY * PFNglDeleteBuffers) (GLsizei n, const GLuint *buffers); +static PFNglDeleteBuffers pglDeleteBuffers; + /* Lighting */ typedef void (APIENTRY * PFNglShadeModel) (GLenum mode); @@ -492,6 +512,8 @@ boolean SetupGLfunc(void) GETOPENGLFUNC(pglNormal3bv, glNormal3bv) GETOPENGLFUNC(pglColor4f , glColor4f) GETOPENGLFUNC(pglColor4fv , glColor4fv) + GETOPENGLFUNC(pglColor4ub, glColor4ub) + GETOPENGLFUNC(pglColor4ubv, glColor4ubv) GETOPENGLFUNC(pglTexCoord2f , glTexCoord2f) GETOPENGLFUNC(pglTexCoord2fv, glTexCoord2fv) GETOPENGLFUNC(pglVertexPointer, glVertexPointer) @@ -501,9 +523,6 @@ boolean SetupGLfunc(void) GETOPENGLFUNC(pglDrawElements, glDrawElements) GETOPENGLFUNC(pglEnableClientState, glEnableClientState) GETOPENGLFUNC(pglDisableClientState, glDisableClientState) - GETOPENGLFUNC(pglClientActiveTexture, glClientActiveTexture) - if (!pglClientActiveTexture) - GETOPENGLFUNC(pglClientActiveTexture, glClientActiveTextureARB) GETOPENGLFUNC(pglShadeModel , glShadeModel) GETOPENGLFUNC(pglLightfv, glLightfv) @@ -542,6 +561,10 @@ boolean SetupGLFunc13(void) pglMultiTexCoord2f = GetGLFunc("glMultiTexCoord2f"); pglClientActiveTexture = GetGLFunc("glClientActiveTexture"); pglMultiTexCoord2fv = GetGLFunc("glMultiTexCoord2fv"); + pglGenBuffers = GetGLFunc("glGenBuffers"); + pglBindBuffer = GetGLFunc("glBindBuffer"); + pglBufferData = GetGLFunc("glBufferData"); + pglDeleteBuffers = GetGLFunc("glDeleteBuffers"); return true; } @@ -949,8 +972,6 @@ EXPORT void HWRAPI(Draw2DLine) (F2DCoord * v1, F2DCoord * v2, RGBA_t Color) { - GLRGBAFloat c; - // DBG_Printf ("DrawLine() (%f %f %f) %d\n", v1->x, -v1->y, -v1->z, v1->argb); GLfloat p[12]; GLfloat dx, dy; @@ -961,11 +982,6 @@ EXPORT void HWRAPI(Draw2DLine) (F2DCoord * v1, pglDisable(GL_TEXTURE_2D); - c.red = byte2float[Color.s.red]; - c.green = byte2float[Color.s.green]; - c.blue = byte2float[Color.s.blue]; - c.alpha = byte2float[Color.s.alpha]; - // This is the preferred, 'modern' way of rendering lines -- creating a polygon. if (fabsf(v2->x - v1->x) > FLT_EPSILON) angle = (float)atan((v2->y-v1->y)/(v2->x-v1->x)); @@ -980,7 +996,7 @@ EXPORT void HWRAPI(Draw2DLine) (F2DCoord * v1, p[9] = v1->x + dx; p[10] = -(v1->y - dy); p[11] = 1; pglDisableClientState(GL_TEXTURE_COORD_ARRAY); - pglColor4fv(&c.red); // is in RGBA float format + pglColor4ubv((GLbyte*)&Color); pglVertexPointer(3, GL_FLOAT, 0, p); pglDrawArrays(GL_TRIANGLE_FAN, 0, 4); @@ -1097,7 +1113,7 @@ EXPORT void HWRAPI(SetBlend) (FBITFIELD PolyFlags) if (oglflags & GLF_NOTEXENV) { if (!(PolyFlags & PF_Modulated)) - pglColor4fv(white); + pglColor4ubv(white); } else #endif @@ -1378,7 +1394,6 @@ EXPORT void HWRAPI(DrawPolygon) (FSurfaceInfo *pSurf, { FUINT i; FUINT j; - GLRGBAFloat c = {0,0,0,0}; if ((PolyFlags & PF_Corona) && (oglflags & GLF_NOZBUFREAD)) PolyFlags &= ~(PF_NoDepthTest|PF_Corona); @@ -1387,24 +1402,7 @@ EXPORT void HWRAPI(DrawPolygon) (FSurfaceInfo *pSurf, // If Modulated, mix the surface colour to the texture if ((CurrentPolyFlags & PF_Modulated) && pSurf) - { - if (pal_col) - { // hack for non-palettized mode - c.red = (const_pal_col.red +byte2float[pSurf->FlatColor.s.red]) /2.0f; - c.green = (const_pal_col.green+byte2float[pSurf->FlatColor.s.green])/2.0f; - c.blue = (const_pal_col.blue +byte2float[pSurf->FlatColor.s.blue]) /2.0f; - c.alpha = byte2float[pSurf->FlatColor.s.alpha]; - } - else - { - c.red = byte2float[pSurf->FlatColor.s.red]; - c.green = byte2float[pSurf->FlatColor.s.green]; - c.blue = byte2float[pSurf->FlatColor.s.blue]; - c.alpha = byte2float[pSurf->FlatColor.s.alpha]; - } - - pglColor4fv(&c.red); // is in RGBA float format - } + pglColor4ubv(&pSurf->FlatColor.s); // this test is added for new coronas' code (without depth buffer) // I think I should do a separate function for drawing coronas, so it will be a little faster @@ -1451,8 +1449,15 @@ EXPORT void HWRAPI(DrawPolygon) (FSurfaceInfo *pSurf, if (scalef < 0.05f) return; - c.alpha *= scalef; // change the alpha value (it seems better than changing the size of the corona) - pglColor4fv(&c.red); + GLubyte c[4]; + c[0] = pSurf->FlatColor.s.red; + c[1] = pSurf->FlatColor.s.green; + c[2] = pSurf->FlatColor.s.blue; + + float alpha = byte2float[pSurf->FlatColor.s.alpha]; + alpha *= scalef; // change the alpha value (it seems better than changing the size of the corona) + c[3] = (unsigned char)(alpha * 255); + pglColor4ubv(c); } pglVertexPointer(3, GL_FLOAT, sizeof(FOutVector), &pOutVerts[0].x); @@ -1488,15 +1493,6 @@ EXPORT void HWRAPI(SetSpecialState) (hwdspecialstate_t IdState, INT32 Value) } #endif - case HWD_SET_PALETTECOLOR: - { - pal_col = Value; - const_pal_col.blue = byte2float[((Value>>16)&0xff)]; - const_pal_col.green = byte2float[((Value>>8)&0xff)]; - const_pal_col.red = byte2float[((Value)&0xff)]; - break; - } - case HWD_SET_FOG_COLOR: { GLfloat fogcolor[4]; @@ -1538,13 +1534,6 @@ EXPORT void HWRAPI(SetSpecialState) (hwdspecialstate_t IdState, INT32 Value) pglDisable(GL_FOG); break; - case HWD_SET_POLYGON_SMOOTH: - if (Value) - pglEnable(GL_POLYGON_SMOOTH); - else - pglDisable(GL_POLYGON_SMOOTH); - break; - case HWD_SET_TEXTUREFILTERMODE: switch (Value) { @@ -1642,6 +1631,155 @@ static void AllocLerpTinyBuffer(size_t size) normTinyBuffer = malloc(lerpTinyBufferSize / 2); } +#ifndef GL_STATIC_DRAW +#define GL_STATIC_DRAW 0x88E4 +#endif + +#ifndef GL_ARRAY_BUFFER +#define GL_ARRAY_BUFFER 0x8892 +#endif + +static void CreateModelVBO(mesh_t *mesh, mdlframe_t *frame) +{ + int bufferSize = sizeof(vbo64_t)*mesh->numTriangles * 3; + vbo64_t *buffer = (vbo64_t*)malloc(bufferSize); + vbo64_t *bufPtr = buffer; + + float *vertPtr = frame->vertices; + float *normPtr = frame->normals; + float *tanPtr = frame->tangents; + float *uvPtr = mesh->uvs; + float *lightPtr = mesh->lightuvs; + char *colorPtr = frame->colors; + + int i; + for (i = 0; i < mesh->numTriangles * 3; i++) + { + bufPtr->x = *vertPtr++; + bufPtr->y = *vertPtr++; + bufPtr->z = *vertPtr++; + + bufPtr->nx = *normPtr++; + bufPtr->ny = *normPtr++; + bufPtr->nz = *normPtr++; + + bufPtr->s0 = *uvPtr++; + bufPtr->t0 = *uvPtr++; + + if (tanPtr != NULL) + { + bufPtr->tan0 = *tanPtr++; + bufPtr->tan1 = *tanPtr++; + bufPtr->tan2 = *tanPtr++; + } + + if (lightPtr != NULL) + { + bufPtr->s1 = *lightPtr++; + bufPtr->t1 = *lightPtr++; + } + + if (colorPtr) + { + bufPtr->r = *colorPtr++; + bufPtr->g = *colorPtr++; + bufPtr->b = *colorPtr++; + bufPtr->a = *colorPtr++; + } + else + { + bufPtr->r = 255; + bufPtr->g = 255; + bufPtr->b = 255; + bufPtr->a = 255; + } + + bufPtr++; + } + + pglGenBuffers(1, &frame->vboID); + pglBindBuffer(GL_ARRAY_BUFFER, frame->vboID); + pglBufferData(GL_ARRAY_BUFFER, bufferSize, buffer, GL_STATIC_DRAW); + free(buffer); +} + +static void CreateModelVBOTiny(mesh_t *mesh, tinyframe_t *frame) +{ + int bufferSize = sizeof(vbotiny_t)*mesh->numTriangles * 3; + vbotiny_t *buffer = (vbotiny_t*)malloc(bufferSize); + vbotiny_t *bufPtr = buffer; + + short *vertPtr = frame->vertices; + char *normPtr = frame->normals; + float *uvPtr = mesh->uvs; + char *tanPtr = frame->tangents; + + int i; + for (i = 0; i < mesh->numVertices; i++) + { + bufPtr->x = *vertPtr++; + bufPtr->y = *vertPtr++; + bufPtr->z = *vertPtr++; + + bufPtr->nx = *normPtr++; + bufPtr->ny = *normPtr++; + bufPtr->nz = *normPtr++; + + bufPtr->s0 = *uvPtr++; + bufPtr->t0 = *uvPtr++; + + if (tanPtr) + { + bufPtr->tanx = *tanPtr++; + bufPtr->tany = *tanPtr++; + bufPtr->tanz = *tanPtr++; + } + + bufPtr++; + } + + pglGenBuffers(1, &frame->vboID); + pglBindBuffer(GL_ARRAY_BUFFER, frame->vboID); + pglBufferData(GL_ARRAY_BUFFER, bufferSize, buffer, GL_STATIC_DRAW); + free(buffer); +} + +EXPORT void HWRAPI(CreateModelVBOs) (model_t *model) +{ + int i; + for (i = 0; i < model->numMeshes; i++) + { + mesh_t *mesh = &model->meshes[i]; + + if (mesh->frames) + { + int j; + for (j = 0; j < model->meshes[i].numFrames; j++) + { + mdlframe_t *frame = &mesh->frames[j]; + if (frame->vboID) + pglDeleteBuffers(1, &frame->vboID); + frame->vboID = 0; + CreateModelVBO(mesh, frame); + } + } + else if (mesh->tinyframes) + { + int j; + for (j = 0; j < model->meshes[i].numFrames; j++) + { + tinyframe_t *frame = &mesh->tinyframes[j]; + if (frame->vboID) + pglDeleteBuffers(1, &frame->vboID); + frame->vboID = 0; + CreateModelVBOTiny(mesh, frame); + } + } + } +} + +#define BUFFER_OFFSET(i) ((char*)NULL + (i)) + static void DrawModelEx(model_t *model, INT32 frameIndex, INT32 duration, INT32 tics, INT32 nextFrameIndex, FTransform *pos, float scale, UINT8 flipped, UINT8 *color) { GLfloat ambient[4]; @@ -1772,10 +1910,13 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, INT32 duration, INT32 if (!nextframe || fpclassify(pol) == FP_ZERO) { - pglVertexPointer(3, GL_SHORT, 0, frame->vertices); - pglNormalPointer(GL_BYTE, 0, frame->normals); - pglTexCoordPointer(2, GL_FLOAT, 0, mesh->uvs); + pglBindBuffer(GL_ARRAY_BUFFER, frame->vboID); + pglVertexPointer(3, GL_SHORT, sizeof(vbotiny_t), BUFFER_OFFSET(0)); + pglNormalPointer(GL_BYTE, sizeof(vbotiny_t), BUFFER_OFFSET(sizeof(short)*3)); + pglTexCoordPointer(2, GL_FLOAT, sizeof(vbotiny_t), BUFFER_OFFSET(sizeof(short) * 3 + sizeof(byte) * 6)); + pglDrawElements(GL_TRIANGLES, mesh->numTriangles * 3, GL_UNSIGNED_SHORT, mesh->indices); + pglBindBuffer(GL_ARRAY_BUFFER, 0); } else { @@ -1813,10 +1954,18 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, INT32 duration, INT32 if (!nextframe || pol == 0.0f) { // Zoom! Take advantage of just shoving the entire arrays to the GPU. - pglVertexPointer(3, GL_FLOAT, 0, frame->vertices); +/* pglVertexPointer(3, GL_FLOAT, 0, frame->vertices); pglNormalPointer(GL_FLOAT, 0, frame->normals); pglTexCoordPointer(2, GL_FLOAT, 0, mesh->uvs); - pglDrawArrays(GL_TRIANGLES, 0, mesh->numTriangles * 3); + pglDrawArrays(GL_TRIANGLES, 0, mesh->numTriangles * 3);*/ + + pglBindBuffer(GL_ARRAY_BUFFER, frame->vboID); + pglVertexPointer(3, GL_FLOAT, sizeof(vbo64_t), BUFFER_OFFSET(0)); + pglNormalPointer(GL_FLOAT, sizeof(vbo64_t), BUFFER_OFFSET(sizeof(float) * 3)); + pglTexCoordPointer(2, GL_FLOAT, sizeof(vbo64_t), BUFFER_OFFSET(sizeof(float) * 6)); + + pglDrawElements(GL_TRIANGLES, mesh->numTriangles * 3, GL_UNSIGNED_SHORT, mesh->indices); + pglBindBuffer(GL_ARRAY_BUFFER, 0); } else { @@ -1968,7 +2117,7 @@ EXPORT void HWRAPI(PostImgRedraw) (float points[SCREENVERTS][SCREENVERTS][2]) // Draw a black square behind the screen texture, // so nothing shows through the edges - pglColor4fv(white); + pglColor4ubv(white); pglVertexPointer(3, GL_FLOAT, 0, blackBack); pglDrawArrays(GL_TRIANGLE_FAN, 0, 4); @@ -2140,7 +2289,7 @@ EXPORT void HWRAPI(DrawIntermissionBG)(void) pglClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); pglBindTexture(GL_TEXTURE_2D, screentexture); - pglColor4fv(white); + pglColor4ubv(white); pglTexCoordPointer(2, GL_FLOAT, 0, fix); pglVertexPointer(3, GL_FLOAT, 0, screenVerts); @@ -2205,7 +2354,7 @@ EXPORT void HWRAPI(DoScreenWipe)(float alpha) // Draw the original screen pglBindTexture(GL_TEXTURE_2D, startScreenWipe); - pglColor4fv(white); + pglColor4ubv(white); pglTexCoordPointer(2, GL_FLOAT, 0, fix); pglVertexPointer(3, GL_FLOAT, 0, screenVerts); pglDrawArrays(GL_TRIANGLE_FAN, 0, 4); @@ -2363,7 +2512,7 @@ EXPORT void HWRAPI(DrawScreenFinalTexture)(int width, int height) ClearBuffer(true, false, &clearColour); pglBindTexture(GL_TEXTURE_2D, finalScreenTexture); - pglColor4fv(white); + pglColor4ubv(white); pglTexCoordPointer(2, GL_FLOAT, 0, fix); pglVertexPointer(3, GL_FLOAT, 0, off); diff --git a/src/hardware/r_opengl/r_vbo.h b/src/hardware/r_opengl/r_vbo.h new file mode 100644 index 000000000..ca1a974da --- /dev/null +++ b/src/hardware/r_opengl/r_vbo.h @@ -0,0 +1,52 @@ +/* + From the 'Wizard2' engine by Spaddlewit Inc. ( http://www.spaddlewit.com ) + An experimental work-in-progress. + + Donated to Sonic Team Junior and adapted to work with + Sonic Robo Blast 2. The license of this code matches whatever + the licensing is for Sonic Robo Blast 2. +*/ +#ifndef _R_VBO_H_ +#define _R_VBO_H_ + +typedef struct +{ + float x, y, z; // Vertex + float nx, ny, nz; // Normal + float s0, t0; // Texcoord0 +} vbo32_t; + +typedef struct +{ + float x, y, z; // Vertex + float s0, t0; // Texcoord0 + unsigned char r, g, b, a; // Color + float pad[2]; // Pad +} vbo2d32_t; + +typedef struct +{ + float x, y; // Vertex + float s0, t0; // Texcoord0 +} vbofont_t; + +typedef struct +{ + short x, y, z; // Vertex + char nx, ny, nz; // Normal + char tanx, tany, tanz; // Tangent + float s0, t0; // Texcoord0 +} vbotiny_t; + +typedef struct +{ + float x, y, z; // Vertex + float nx, ny, nz; // Normal + float s0, t0; // Texcoord0 + float s1, t1; // Texcoord1 + float s2, t2; // Texcoord2 + float tan0, tan1, tan2; // Tangent + unsigned char r, g, b, a; // Color +} vbo64_t; + +#endif diff --git a/src/r_main.c b/src/r_main.c index 12e3e03b7..a61324dce 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -1543,7 +1543,6 @@ void R_RegisterEngineStuff(void) CV_RegisterVar(&cv_grgammared); CV_RegisterVar(&cv_grfovchange); CV_RegisterVar(&cv_grfog); - CV_RegisterVar(&cv_voodoocompatibility); CV_RegisterVar(&cv_grfogcolor); CV_RegisterVar(&cv_grsoftwarefog); #ifdef ALAM_LIGHTING diff --git a/src/sdl/hwsym_sdl.c b/src/sdl/hwsym_sdl.c index 9f844c623..4e083b4c2 100644 --- a/src/sdl/hwsym_sdl.c +++ b/src/sdl/hwsym_sdl.c @@ -88,6 +88,7 @@ void *hwSym(const char *funcName,void *handle) GETFUNC(SetSpecialState); GETFUNC(GetTextureUsed); GETFUNC(DrawModel); + GETFUNC(CreateModelVBOs); GETFUNC(SetTransform); GETFUNC(GetRenderVersion); GETFUNC(PostImgRedraw); diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 11ad2be9a..1db1e27bd 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -1547,6 +1547,7 @@ void I_StartupGraphics(void) HWD.pfnSetPalette = hwSym("SetPalette",NULL); HWD.pfnGetTextureUsed = hwSym("GetTextureUsed",NULL); HWD.pfnDrawModel = hwSym("DrawModel",NULL); + HWD.pfnCreateModelVBOs = hwSym("CreateModelVBOs",NULL); HWD.pfnSetTransform = hwSym("SetTransform",NULL); HWD.pfnGetRenderVersion = hwSym("GetRenderVersion",NULL); HWD.pfnPostImgRedraw = hwSym("PostImgRedraw",NULL); diff --git a/src/v_video.c b/src/v_video.c index 90411d4ea..dd06d04c1 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -60,7 +60,6 @@ static void CV_Gammaxxx_ONChange(void); static CV_PossibleValue_t grgamma_cons_t[] = {{1, "MIN"}, {255, "MAX"}, {0, NULL}}; static CV_PossibleValue_t grsoftwarefog_cons_t[] = {{0, "Off"}, {1, "On"}, {2, "LightPlanes"}, {0, NULL}}; -consvar_t cv_voodoocompatibility = {"gr_voodoocompatibility", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_grfovchange = {"gr_fovchange", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_grfog = {"gr_fog", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_grfogcolor = {"gr_fogcolor", "AAAAAA", CV_SAVE, NULL, NULL, 0, NULL, NULL, 0, 0, NULL}; diff --git a/src/w_wad.c b/src/w_wad.c index 512320c2a..fb2b84b66 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -1609,12 +1609,12 @@ void W_VerifyFileMD5(UINT16 wadfilenum, const char *matchmd5) { char actualmd5text[2*MD5_LEN+1]; PrintMD5String(wadfiles[wadfilenum]->md5sum, actualmd5text); -#ifdef _DEBUG +/*#ifdef _DEBUG CONS_Printf #else I_Error #endif - (M_GetText("File is corrupt or has been modified: %s (found md5: %s, wanted: %s)\n"), wadfiles[wadfilenum]->filename, actualmd5text, matchmd5); + (M_GetText("File is corrupt or has been modified: %s (found md5: %s, wanted: %s)\n"), wadfiles[wadfilenum]->filename, actualmd5text, matchmd5);*/ } #endif } From 766fb9d8364700dd086b6d1f5ed5bf9cac321aec Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 27 Dec 2018 00:47:43 -0500 Subject: [PATCH 28/66] Compile fixes -- specify GLubyte for pglColor4ubv --- src/hardware/r_opengl/r_opengl.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index ce1491979..b75621713 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -67,8 +67,10 @@ static float NEAR_CLIPPING_PLANE = NZCLIP_PLANE; static GLuint NextTexAvail = FIRST_TEX_AVAIL; static GLuint tex_downloaded = 0; static GLfloat fov = 90.0f; +#if 0 static GLuint pal_col = 0; static FRGBAFloat const_pal_col; +#endif static FBITFIELD CurrentPolyFlags; static FTextureInfo* gr_cachetail = NULL; @@ -996,7 +998,7 @@ EXPORT void HWRAPI(Draw2DLine) (F2DCoord * v1, p[9] = v1->x + dx; p[10] = -(v1->y - dy); p[11] = 1; pglDisableClientState(GL_TEXTURE_COORD_ARRAY); - pglColor4ubv((GLbyte*)&Color); + pglColor4ubv((GLubyte*)&Color); pglVertexPointer(3, GL_FLOAT, 0, p); pglDrawArrays(GL_TRIANGLE_FAN, 0, 4); @@ -1402,7 +1404,7 @@ EXPORT void HWRAPI(DrawPolygon) (FSurfaceInfo *pSurf, // If Modulated, mix the surface colour to the texture if ((CurrentPolyFlags & PF_Modulated) && pSurf) - pglColor4ubv(&pSurf->FlatColor.s); + pglColor4ubv((GLubyte*)&pSurf->FlatColor.s); // this test is added for new coronas' code (without depth buffer) // I think I should do a separate function for drawing coronas, so it will be a little faster From 89cdc1cbc2bf9778bffb05aba992b9a9aa599d14 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 27 Dec 2018 00:54:27 -0500 Subject: [PATCH 29/66] Buildbot fixes --- src/hardware/r_opengl/r_opengl.c | 10 +++++++--- src/hardware/r_opengl/r_opengl.h | 4 +++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index b75621713..d24e4bc66 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -1416,6 +1416,10 @@ EXPORT void HWRAPI(DrawPolygon) (FSurfaceInfo *pSurf, GLdouble px = 0.0f, py = 0.0f, pz = -1.0f; GLfloat scalef = 0.0f; + GLubyte c[4]; + + float alpha; + cx = (pOutVerts[0].x + pOutVerts[2].x) / 2.0f; // we should change the coronas' ... cy = (pOutVerts[0].y + pOutVerts[2].y) / 2.0f; // ... code so its only done once. cz = pOutVerts[0].z; @@ -1451,12 +1455,12 @@ EXPORT void HWRAPI(DrawPolygon) (FSurfaceInfo *pSurf, if (scalef < 0.05f) return; - GLubyte c[4]; + // GLubyte c[4]; c[0] = pSurf->FlatColor.s.red; c[1] = pSurf->FlatColor.s.green; c[2] = pSurf->FlatColor.s.blue; - float alpha = byte2float[pSurf->FlatColor.s.alpha]; + alpha = byte2float[pSurf->FlatColor.s.alpha]; alpha *= scalef; // change the alpha value (it seems better than changing the size of the corona) c[3] = (unsigned char)(alpha * 255); pglColor4ubv(c); @@ -1915,7 +1919,7 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, INT32 duration, INT32 pglBindBuffer(GL_ARRAY_BUFFER, frame->vboID); pglVertexPointer(3, GL_SHORT, sizeof(vbotiny_t), BUFFER_OFFSET(0)); pglNormalPointer(GL_BYTE, sizeof(vbotiny_t), BUFFER_OFFSET(sizeof(short)*3)); - pglTexCoordPointer(2, GL_FLOAT, sizeof(vbotiny_t), BUFFER_OFFSET(sizeof(short) * 3 + sizeof(byte) * 6)); + pglTexCoordPointer(2, GL_FLOAT, sizeof(vbotiny_t), BUFFER_OFFSET(sizeof(short) * 3 + sizeof(char) * 6)); pglDrawElements(GL_TRIANGLES, mesh->numTriangles * 3, GL_UNSIGNED_SHORT, mesh->indices); pglBindBuffer(GL_ARRAY_BUFFER, 0); diff --git a/src/hardware/r_opengl/r_opengl.h b/src/hardware/r_opengl/r_opengl.h index 8741a174f..ce834c12c 100644 --- a/src/hardware/r_opengl/r_opengl.h +++ b/src/hardware/r_opengl/r_opengl.h @@ -118,9 +118,11 @@ typedef void (APIENTRY * PFNglGetIntegerv) (GLenum pname, GLint *params); extern PFNglGetIntegerv pglGetIntegerv; typedef const GLubyte* (APIENTRY * PFNglGetString) (GLenum name); extern PFNglGetString pglGetString; -typedef void (APIENTRY * PFNglEnableClientState) (GLenum cap); +#if 0 +typedef void (APIENTRY * PFNglEnableClientState) (GLenum cap); // redefined in r_opengl.c static PFNglEnableClientState pglEnableClientState; #endif +#endif // ========================================================================== // GLOBAL From d1b448f8d1013917ca9b9af581e0860b535b27fb Mon Sep 17 00:00:00 2001 From: Arthur Date: Thu, 27 Dec 2018 14:58:07 -0500 Subject: [PATCH 30/66] Fix screen transitions --- src/hardware/r_opengl/r_opengl.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index d24e4bc66..0e7d7a8ce 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -998,7 +998,7 @@ EXPORT void HWRAPI(Draw2DLine) (F2DCoord * v1, p[9] = v1->x + dx; p[10] = -(v1->y - dy); p[11] = 1; pglDisableClientState(GL_TEXTURE_COORD_ARRAY); - pglColor4ubv((GLubyte*)&Color); + pglColor4ubv((GLubyte*)&Color.s); pglVertexPointer(3, GL_FLOAT, 0, p); pglDrawArrays(GL_TRIANGLE_FAN, 0, 4); @@ -2369,27 +2369,31 @@ EXPORT void HWRAPI(DoScreenWipe)(float alpha) // Draw the end screen that fades in pglActiveTexture(GL_TEXTURE0); + pglEnable(GL_TEXTURE_2D); pglBindTexture(GL_TEXTURE_2D, endScreenWipe); pglTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); pglActiveTexture(GL_TEXTURE1); + pglEnable(GL_TEXTURE_2D); pglBindTexture(GL_TEXTURE_2D, fademaskdownloaded); pglTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); // const float defaultST[8] - pglVertexPointer(3, GL_FLOAT, 0, screenVerts); pglClientActiveTexture(GL_TEXTURE0); pglTexCoordPointer(2, GL_FLOAT, 0, fix); + pglVertexPointer(3, GL_FLOAT, 0, screenVerts); pglClientActiveTexture(GL_TEXTURE1); + pglEnableClientState(GL_TEXTURE_COORD_ARRAY); pglTexCoordPointer(2, GL_FLOAT, 0, defaultST); pglDrawArrays(GL_TRIANGLE_FAN, 0, 4); - pglClientActiveTexture(GL_TEXTURE0); - pglDisable(GL_TEXTURE_2D); // disable the texture in the 2nd texture unit + pglDisableClientState(GL_TEXTURE_COORD_ARRAY); + pglActiveTexture(GL_TEXTURE0); + pglClientActiveTexture(GL_TEXTURE0); tex_downloaded = endScreenWipe; } From f41951bfb130063c09802f21b6d1a677d247dff5 Mon Sep 17 00:00:00 2001 From: Arthur Date: Thu, 27 Dec 2018 15:23:33 -0500 Subject: [PATCH 31/66] Eliminate some old GL functions so we don't slide back into bad habits! --- src/hardware/hw_clip.c | 8 +- src/hardware/hw_drv.h | 2 +- src/hardware/hw_main.c | 2 +- src/hardware/r_opengl/ogl_win.c | 22 +---- src/hardware/r_opengl/r_opengl.c | 158 ++++++++----------------------- src/hardware/r_opengl/r_opengl.h | 5 - 6 files changed, 49 insertions(+), 148 deletions(-) diff --git a/src/hardware/hw_clip.c b/src/hardware/hw_clip.c index 6d120efe7..4bdc753ec 100644 --- a/src/hardware/hw_clip.c +++ b/src/hardware/hw_clip.c @@ -77,8 +77,8 @@ #include "r_opengl/r_opengl.h" #ifdef HAVE_SPHEREFRUSTRUM -static GLdouble viewMatrix[16]; -static GLdouble projMatrix[16]; +static GLfloat viewMatrix[16]; +static GLfloat projMatrix[16]; float frustum[6][4]; #endif @@ -380,8 +380,8 @@ void gld_FrustrumSetup(void) float t; float clip[16]; - pglGetDoublev(GL_PROJECTION_MATRIX, projMatrix); - pglGetDoublev(GL_MODELVIEW_MATRIX, viewMatrix); + pglGeFloatv(GL_PROJECTION_MATRIX, projMatrix); + pglGetFloatv(GL_MODELVIEW_MATRIX, viewMatrix); clip[0] = CALCMATRIX(0, 0, 1, 4, 2, 8, 3, 12); clip[1] = CALCMATRIX(0, 1, 1, 5, 2, 9, 3, 13); diff --git a/src/hardware/hw_drv.h b/src/hardware/hw_drv.h index e1d050cf8..54bd9e786 100644 --- a/src/hardware/hw_drv.h +++ b/src/hardware/hw_drv.h @@ -69,7 +69,7 @@ EXPORT void HWRAPI(PostImgRedraw) (float points[SCREENVERTS][SCREENVERTS][2]); EXPORT void HWRAPI(FlushScreenTextures) (void); EXPORT void HWRAPI(StartScreenWipe) (void); EXPORT void HWRAPI(EndScreenWipe) (void); -EXPORT void HWRAPI(DoScreenWipe) (float alpha); +EXPORT void HWRAPI(DoScreenWipe) (void); EXPORT void HWRAPI(DrawIntermissionBG) (void); EXPORT void HWRAPI(MakeScreenTexture) (void); EXPORT void HWRAPI(MakeScreenFinalTexture) (void); diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 2f5f6c488..133e43c39 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -6921,7 +6921,7 @@ void HWR_DoWipe(UINT8 wipenum, UINT8 scrnnum) HWR_GetFadeMask(lumpnum); - HWD.pfnDoScreenWipe(HWRWipeCounter); // Still send in wipecounter since old stuff might not support multitexturing + HWD.pfnDoScreenWipe(); HWRWipeCounter += 0.05f; // increase opacity of end screen diff --git a/src/hardware/r_opengl/ogl_win.c b/src/hardware/r_opengl/ogl_win.c index eb9a31a7d..562afe998 100644 --- a/src/hardware/r_opengl/ogl_win.c +++ b/src/hardware/r_opengl/ogl_win.c @@ -347,13 +347,6 @@ static INT32 WINAPI SetRes(viddef_t *lvid, vmode_t *pcurrentmode) if (strstr(renderer, "810")) oglflags |= GLF_NOZBUFREAD; DBG_Printf("oglflags : 0x%X\n", oglflags); -#ifdef USE_PALETTED_TEXTURE - if (isExtAvailable("GL_EXT_paletted_texture",gl_extensions)) - glColorTableEXT = GetGLFunc("glColorTableEXT"); - else - glColorTableEXT = NULL; -#endif - #ifdef USE_WGL_SWAP if (isExtAvailable("WGL_EXT_swap_control",gl_extensions)) wglSwapIntervalEXT = GetGLFunc("wglSwapIntervalEXT"); @@ -582,19 +575,8 @@ EXPORT void HWRAPI(SetPalette) (RGBA_t *pal, RGBA_t *gamma) myPaletteData[i].s.blue = (UINT8)MIN((pal[i].s.blue*gamma->s.blue)/127, 255); myPaletteData[i].s.alpha = pal[i].s.alpha; } -#ifdef USE_PALETTED_TEXTURE - if (glColorTableEXT) - { - for (i = 0; i < 256; i++) - { - palette_tex[3*i+0] = pal[i].s.red; - palette_tex[3*i+1] = pal[i].s.green; - palette_tex[3*i+2] = pal[i].s.blue; - } - glColorTableEXT(GL_TEXTURE_2D, GL_RGB8, 256, GL_RGB, GL_UNSIGNED_BYTE, palette_tex); - } -#endif - // on a chang� de palette, il faut recharger toutes les textures + + // on a palette change, you have to reload all of the textures Flush(); } diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 0e7d7a8ce..e17ee32f7 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -33,7 +33,6 @@ #include "r_vbo.h" #if defined (HWRENDER) && !defined (NOROPENGL) -// for KOS: GL_TEXTURE_ENV, glAlphaFunc, glColorMask, glPolygonOffset, glReadPixels, GL_ALPHA_TEST, GL_POLYGON_OFFSET_FILL struct GLRGBAFloat { @@ -91,16 +90,10 @@ static FTransform md2_transform; const GLubyte *gl_extensions = NULL; //Hurdler: 04/10/2000: added for the kick ass coronas as Boris wanted;-) -static GLdouble modelMatrix[16]; -static GLdouble projMatrix[16]; +static GLfloat modelMatrix[16]; +static GLfloat projMatrix[16]; static GLint viewport[4]; - -#ifdef USE_PALETTED_TEXTURE - PFNGLCOLORTABLEEXTPROC glColorTableEXT = NULL; - GLubyte palette_tex[256*3]; -#endif - // Yay for arbitrary numbers! NextTexAvail is buggy for some reason. // Sryder: NextTexAvail is broken for these because palette changes or changes to the texture filter or antialiasing // flush all of the stored textures, leaving them unavailable at times such as between levels @@ -192,12 +185,11 @@ FUNCPRINTF void DBG_Printf(const char *lpFmt, ...) #define pglAlphaFunc glAlphaFunc #define pglBlendFunc glBlendFunc #define pglCullFace glCullFace -#define pglPolygonMode glPolygonMode #define pglPolygonOffset glPolygonOffset #define pglScissor glScissor #define pglEnable glEnable #define pglDisable glDisable -#define pglGetDoublev glGetDoublev +#define pglGetFloatv glGetFloatv //glGetIntegerv //glGetString #define pglHint glHint @@ -215,25 +207,12 @@ FUNCPRINTF void DBG_Printf(const char *lpFmt, ...) #define pglPopMatrix glPopMatrix #define pglLoadIdentity glLoadIdentity #define pglMultMatrixf glMultMatrixf -#define pglMultMatrixd glMultMatrixd #define pglRotatef glRotatef #define pglScalef glScalef #define pglTranslatef glTranslatef /* Drawing Functions */ -#define pglBegin glBegin -#define pglEnd glEnd -#define pglVertex3f glVertex3f -#define pglVertex3fv glVertex3fv -#define pglVertex3sv glVertex3sv -#define pglNormal3f glNormal3f -#define pglNormal3bv glNormal3bv -#define pglColor4f glColor4f -#define pglColor4fv glColor4fv -#define pglColor4ub glColor4ub #define pglColor4ubv glColor4ubv -#define pglTexCoord2f glTexCoord2f -#define pglTexCoord2fv glTexCoord2fv #define pglVertexPointer glVertexPointer #define pglNormalPointer glNormalPointer #define pglTexCoordPointer glTexCoordPointer @@ -289,8 +268,6 @@ typedef void (APIENTRY * PFNglBlendFunc) (GLenum sfactor, GLenum dfactor); static PFNglBlendFunc pglBlendFunc; typedef void (APIENTRY * PFNglCullFace) (GLenum mode); static PFNglCullFace pglCullFace; -typedef void (APIENTRY * PFNglPolygonMode) (GLenum face, GLenum mode); -static PFNglPolygonMode pglPolygonMode; typedef void (APIENTRY * PFNglPolygonOffset) (GLfloat factor, GLfloat units); static PFNglPolygonOffset pglPolygonOffset; typedef void (APIENTRY * PFNglScissor) (GLint x, GLint y, GLsizei width, GLsizei height); @@ -299,8 +276,8 @@ typedef void (APIENTRY * PFNglEnable) (GLenum cap); static PFNglEnable pglEnable; typedef void (APIENTRY * PFNglDisable) (GLenum cap); static PFNglDisable pglDisable; -typedef void (APIENTRY * PFNglGetDoublev) (GLenum pname, GLdouble *params); -static PFNglGetDoublev pglGetDoublev; +typedef void (APIENTRY * PFNglGetFloatv) (GLenum pname, GLfloat *params); +static PFNglGetFloatv pglGetFloatv; //glGetIntegerv //glGetString @@ -327,8 +304,6 @@ typedef void (APIENTRY * PFNglLoadIdentity) (void); static PFNglLoadIdentity pglLoadIdentity; typedef void (APIENTRY * PFNglMultMatrixf) (const GLfloat *m); static PFNglMultMatrixf pglMultMatrixf; -typedef void (APIENTRY * PFNglMultMatrixd) (const GLdouble *m); -static PFNglMultMatrixd pglMultMatrixd; typedef void (APIENTRY * PFNglRotatef) (GLfloat angle, GLfloat x, GLfloat y, GLfloat z); static PFNglRotatef pglRotatef; typedef void (APIENTRY * PFNglScalef) (GLfloat x, GLfloat y, GLfloat z); @@ -337,32 +312,8 @@ typedef void (APIENTRY * PFNglTranslatef) (GLfloat x, GLfloat y, GLfloat z); static PFNglTranslatef pglTranslatef; /* Drawing Functions */ -typedef void (APIENTRY * PFNglBegin) (GLenum mode); -static PFNglBegin pglBegin; -typedef void (APIENTRY * PFNglEnd) (void); -static PFNglEnd pglEnd; -typedef void (APIENTRY * PFNglVertex3f) (GLfloat x, GLfloat y, GLfloat z); -static PFNglVertex3f pglVertex3f; -typedef void (APIENTRY * PFNglVertex3fv)(const GLfloat *v); -static PFNglVertex3fv pglVertex3fv; -typedef void (APIENTRY * PFNglVertex3sv) (const GLshort *v); -static PFNglVertex3sv pglVertex3sv; -typedef void (APIENTRY * PFNglNormal3f) (GLfloat x, GLfloat y, GLfloat z); -static PFNglNormal3f pglNormal3f; -typedef void (APIENTRY * PFNglNormal3bv)(const GLbyte *v); -static PFNglNormal3bv pglNormal3bv; -typedef void (APIENTRY * PFNglColor4f) (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); -static PFNglColor4f pglColor4f; -typedef void (APIENTRY * PFNglColor4fv) (const GLfloat *v); -static PFNglColor4fv pglColor4fv; -typedef void (APIENTRY * PFNglColor4ub) (GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha); -static PFNglColor4ub pglColor4ub; typedef void (APIENTRY * PFNglColor4ubv) (const GLubyte *v); static PFNglColor4ubv pglColor4ubv; -typedef void (APIENTRY * PFNglTexCoord2f) (GLfloat s, GLfloat t); -static PFNglTexCoord2f pglTexCoord2f; -typedef void (APIENTRY * PFNglTexCoord2fv) (const GLfloat *v); -static PFNglTexCoord2fv pglTexCoord2fv; typedef void (APIENTRY * PFNglVertexPointer) (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); static PFNglVertexPointer pglVertexPointer; typedef void (APIENTRY * PFNglNormalPointer) (GLenum type, GLsizei stride, const GLvoid *pointer); @@ -475,19 +426,18 @@ boolean SetupGLfunc(void) GETOPENGLFUNC(pglClearColor, glClearColor) - GETOPENGLFUNC(pglClear , glClear) - GETOPENGLFUNC(pglColorMask , glColorMask) - GETOPENGLFUNC(pglAlphaFunc , glAlphaFunc) - GETOPENGLFUNC(pglBlendFunc , glBlendFunc) - GETOPENGLFUNC(pglCullFace , glCullFace) - GETOPENGLFUNC(pglPolygonMode , glPolygonMode) - GETOPENGLFUNC(pglPolygonOffset , glPolygonOffset) - GETOPENGLFUNC(pglScissor , glScissor) - GETOPENGLFUNC(pglEnable , glEnable) - GETOPENGLFUNC(pglDisable , glDisable) - GETOPENGLFUNC(pglGetDoublev , glGetDoublev) - GETOPENGLFUNC(pglGetIntegerv , glGetIntegerv) - GETOPENGLFUNC(pglGetString , glGetString) + GETOPENGLFUNC(pglClear, glClear) + GETOPENGLFUNC(pglColorMask, glColorMask) + GETOPENGLFUNC(pglAlphaFunc, glAlphaFunc) + GETOPENGLFUNC(pglBlendFunc, glBlendFunc) + GETOPENGLFUNC(pglCullFace, glCullFace) + GETOPENGLFUNC(pglPolygonOffset, glPolygonOffset) + GETOPENGLFUNC(pglScissor, glScissor) + GETOPENGLFUNC(pglEnable, glEnable) + GETOPENGLFUNC(pglDisable, glDisable) + GETOPENGLFUNC(pglGetFloatv, glGetFloatv) + GETOPENGLFUNC(pglGetIntegerv, glGetIntegerv) + GETOPENGLFUNC(pglGetString, glGetString) GETOPENGLFUNC(pglClearDepth , glClearDepth) GETOPENGLFUNC(pglDepthFunc , glDepthFunc) @@ -500,24 +450,11 @@ boolean SetupGLfunc(void) GETOPENGLFUNC(pglPopMatrix , glPopMatrix) GETOPENGLFUNC(pglLoadIdentity , glLoadIdentity) GETOPENGLFUNC(pglMultMatrixf , glMultMatrixf) - GETOPENGLFUNC(pglMultMatrixd , glMultMatrixd) GETOPENGLFUNC(pglRotatef , glRotatef) GETOPENGLFUNC(pglScalef , glScalef) GETOPENGLFUNC(pglTranslatef , glTranslatef) - GETOPENGLFUNC(pglBegin , glBegin) - GETOPENGLFUNC(pglEnd , glEnd) - GETOPENGLFUNC(pglVertex3f , glVertex3f) - GETOPENGLFUNC(pglVertex3fv, glVertex3fv) - GETOPENGLFUNC(pglVertex3sv, glVertex3sv) - GETOPENGLFUNC(pglNormal3f , glNormal3f) - GETOPENGLFUNC(pglNormal3bv, glNormal3bv) - GETOPENGLFUNC(pglColor4f , glColor4f) - GETOPENGLFUNC(pglColor4fv , glColor4fv) - GETOPENGLFUNC(pglColor4ub, glColor4ub) GETOPENGLFUNC(pglColor4ubv, glColor4ubv) - GETOPENGLFUNC(pglTexCoord2f , glTexCoord2f) - GETOPENGLFUNC(pglTexCoord2fv, glTexCoord2fv) GETOPENGLFUNC(pglVertexPointer, glVertexPointer) GETOPENGLFUNC(pglNormalPointer, glNormalPointer) GETOPENGLFUNC(pglTexCoordPointer, glTexCoordPointer) @@ -584,39 +521,39 @@ static void SetNoTexture(void) } } -static void GLPerspective(GLdouble fovy, GLdouble aspect) +static void GLPerspective(GLfloat fovy, GLfloat aspect) { - GLdouble m[4][4] = + GLfloat m[4][4] = { { 1.0f, 0.0f, 0.0f, 0.0f}, { 0.0f, 1.0f, 0.0f, 0.0f}, { 0.0f, 0.0f, 1.0f,-1.0f}, { 0.0f, 0.0f, 0.0f, 0.0f}, }; - const GLdouble zNear = NEAR_CLIPPING_PLANE; - const GLdouble zFar = FAR_CLIPPING_PLANE; - const GLdouble radians = (GLdouble)(fovy / 2.0f * M_PIl / 180.0f); - const GLdouble sine = sin(radians); - const GLdouble deltaZ = zFar - zNear; - GLdouble cotangent; + const GLfloat zNear = NEAR_CLIPPING_PLANE; + const GLfloat zFar = FAR_CLIPPING_PLANE; + const GLfloat radians = (GLfloat)(fovy / 2.0f * M_PIl / 180.0f); + const GLfloat sine = sinf(radians); + const GLfloat deltaZ = zFar - zNear; + GLfloat cotangent; if ((deltaZ == 0.0f) || (sine == 0.0f) || (aspect == 0.0f)) { return; } - cotangent = cos(radians) / sine; + cotangent = cosf(radians) / sine; m[0][0] = cotangent / aspect; m[1][1] = cotangent; m[2][2] = -(zFar + zNear) / deltaZ; m[3][2] = -2.0f * zNear * zFar / deltaZ; - pglMultMatrixd(&m[0][0]); + pglMultMatrixf(&m[0][0]); } -static void GLProject(GLdouble objX, GLdouble objY, GLdouble objZ, - GLdouble* winX, GLdouble* winY, GLdouble* winZ) +static void GLProject(GLfloat objX, GLfloat objY, GLfloat objZ, + GLfloat* winX, GLfloat* winY, GLfloat* winZ) { - GLdouble in[4], out[4]; + GLfloat in[4], out[4]; int i; for (i=0; i<4; i++) @@ -683,7 +620,7 @@ void SetModelView(GLint w, GLint h) // added for new coronas' code (without depth buffer) pglGetIntegerv(GL_VIEWPORT, viewport); - pglGetDoublev(GL_PROJECTION_MATRIX, projMatrix); + pglGetFloatv(GL_PROJECTION_MATRIX, projMatrix); } @@ -745,8 +682,6 @@ void SetStates(void) //pglEnable(GL_CULL_FACE); //pglCullFace(GL_FRONT); - //pglPolygonMode(GL_FRONT_AND_BACK, GL_LINE); - //pglPolygonMode(GL_FRONT, GL_LINE); //glFogi(GL_FOG_MODE, GL_EXP); //pglHint(GL_FOG_HINT, GL_FASTEST); @@ -762,7 +697,7 @@ void SetStates(void) // bp : when no t&l :) pglLoadIdentity(); pglScalef(1.0f, 1.0f, -1.0f); - pglGetDoublev(GL_MODELVIEW_MATRIX, modelMatrix); // added for new coronas' code (without depth buffer) + pglGetFloatv(GL_MODELVIEW_MATRIX, modelMatrix); // added for new coronas' code (without depth buffer) } @@ -928,7 +863,7 @@ EXPORT void HWRAPI(GClipRect) (INT32 minx, INT32 miny, INT32 maxx, INT32 maxy, f // added for new coronas' code (without depth buffer) pglGetIntegerv(GL_VIEWPORT, viewport); - pglGetDoublev(GL_PROJECTION_MATRIX, projMatrix); + pglGetFloatv(GL_PROJECTION_MATRIX, projMatrix); } @@ -1190,17 +1125,6 @@ EXPORT void HWRAPI(SetTexture) (FTextureInfo *pTexInfo) w = pTexInfo->width; h = pTexInfo->height; -#ifdef USE_PALETTED_TEXTURE - if (glColorTableEXT && - (pTexInfo->grInfo.format == GR_TEXFMT_P_8) && - !(pTexInfo->flags & TF_CHROMAKEYED)) - { - // do nothing here. - // Not a problem with MiniGL since we don't use paletted texture - } - else -#endif - if ((pTexInfo->grInfo.format == GR_TEXFMT_P_8) || (pTexInfo->grInfo.format == GR_TEXFMT_AP_88)) { @@ -1412,8 +1336,8 @@ EXPORT void HWRAPI(DrawPolygon) (FSurfaceInfo *pSurf, { //rem: all 8 (or 8.0f) values are hard coded: it can be changed to a higher value GLfloat buf[8][8]; - GLdouble cx, cy, cz; - GLdouble px = 0.0f, py = 0.0f, pz = -1.0f; + GLfloat cx, cy, cz; + GLfloat px = 0.0f, py = 0.0f, pz = -1.0f; GLfloat scalef = 0.0f; GLubyte c[4]; @@ -2049,10 +1973,10 @@ EXPORT void HWRAPI(SetTransform) (FTransform *stransform) pglLoadIdentity(); special_splitscreen = (stransform->splitscreen == 1 && stransform->fovxangle == 90.0f); if (special_splitscreen) - GLPerspective(53.13l, 2*ASPECT_RATIO); // 53.13 = 2*atan(0.5) + GLPerspective(53.13f, 2*ASPECT_RATIO); // 53.13 = 2*atan(0.5) else GLPerspective(stransform->fovxangle, ASPECT_RATIO); - pglGetDoublev(GL_PROJECTION_MATRIX, projMatrix); // added for new coronas' code (without depth buffer) + pglGetFloatv(GL_PROJECTION_MATRIX, projMatrix); // added for new coronas' code (without depth buffer) pglMatrixMode(GL_MODELVIEW); } else @@ -2062,15 +1986,15 @@ EXPORT void HWRAPI(SetTransform) (FTransform *stransform) pglMatrixMode(GL_PROJECTION); pglLoadIdentity(); if (special_splitscreen) - GLPerspective(53.13l, 2*ASPECT_RATIO); // 53.13 = 2*atan(0.5) + GLPerspective(53.13f, 2*ASPECT_RATIO); // 53.13 = 2*atan(0.5) else //Hurdler: is "fov" correct? GLPerspective(fov, ASPECT_RATIO); - pglGetDoublev(GL_PROJECTION_MATRIX, projMatrix); // added for new coronas' code (without depth buffer) + pglGetFloatv(GL_PROJECTION_MATRIX, projMatrix); // added for new coronas' code (without depth buffer) pglMatrixMode(GL_MODELVIEW); } - pglGetDoublev(GL_MODELVIEW_MATRIX, modelMatrix); // added for new coronas' code (without depth buffer) + pglGetFloatv(GL_MODELVIEW_MATRIX, modelMatrix); // added for new coronas' code (without depth buffer) } EXPORT INT32 HWRAPI(GetTextureUsed) (void) @@ -2305,7 +2229,7 @@ EXPORT void HWRAPI(DrawIntermissionBG)(void) } // Do screen fades! -EXPORT void HWRAPI(DoScreenWipe)(float alpha) +EXPORT void HWRAPI(DoScreenWipe)() { INT32 texsize = 2048; float xfix, yfix; diff --git a/src/hardware/r_opengl/r_opengl.h b/src/hardware/r_opengl/r_opengl.h index ce834c12c..baf5c7b2a 100644 --- a/src/hardware/r_opengl/r_opengl.h +++ b/src/hardware/r_opengl/r_opengl.h @@ -71,7 +71,6 @@ extern FILE *gllogstream; #endif #ifndef DRIVER_STRING -// #define USE_PALETTED_TEXTURE #define DRIVER_STRING "HWRAPI Init(): SRB2Kart OpenGL renderer" // Tails #endif @@ -89,10 +88,6 @@ int SetupPixelFormat(INT32 WantColorBits, INT32 WantStencilBits, INT32 WantDepth void SetModelView(GLint w, GLint h); void SetStates(void); FUNCMATH float byteasfloat(UINT8 fbyte); -#ifdef USE_PALETTED_TEXTURE -extern PFNGLCOLORTABLEEXTPROC glColorTableEXT; -extern GLubyte palette_tex[256*3]; -#endif #ifndef GL_EXT_texture_filter_anisotropic #define GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE From 7f88e134920a9fd1f9da1d25dbe186d3ea88fe4e Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 27 Dec 2018 22:25:13 -0500 Subject: [PATCH 32/66] Compile fix -- remove (void)alpha from DoScreenWipe --- src/hardware/r_opengl/r_opengl.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index e17ee32f7..4a26aa0eb 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -2229,7 +2229,7 @@ EXPORT void HWRAPI(DrawIntermissionBG)(void) } // Do screen fades! -EXPORT void HWRAPI(DoScreenWipe)() +EXPORT void HWRAPI(DoScreenWipe)(void) { INT32 texsize = 2048; float xfix, yfix; @@ -2254,8 +2254,6 @@ EXPORT void HWRAPI(DoScreenWipe)() 1.0f, 1.0f }; - (void)alpha; - // Use a power of two texture, dammit if(screen_width <= 1024) texsize = 1024; From afb6bde0612e1321f9828aaa6380ce555d017c8d Mon Sep 17 00:00:00 2001 From: mazmazz Date: Wed, 2 Jan 2019 23:31:29 -0500 Subject: [PATCH 33/66] Un-dummy md5 checks --- src/w_wad.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/w_wad.c b/src/w_wad.c index fb2b84b66..512320c2a 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -1609,12 +1609,12 @@ void W_VerifyFileMD5(UINT16 wadfilenum, const char *matchmd5) { char actualmd5text[2*MD5_LEN+1]; PrintMD5String(wadfiles[wadfilenum]->md5sum, actualmd5text); -/*#ifdef _DEBUG +#ifdef _DEBUG CONS_Printf #else I_Error #endif - (M_GetText("File is corrupt or has been modified: %s (found md5: %s, wanted: %s)\n"), wadfiles[wadfilenum]->filename, actualmd5text, matchmd5);*/ + (M_GetText("File is corrupt or has been modified: %s (found md5: %s, wanted: %s)\n"), wadfiles[wadfilenum]->filename, actualmd5text, matchmd5); } #endif } From 157cbe4b233f2892c7a56c34c3cda7ab085e2f9f Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 3 Jan 2019 00:57:14 -0500 Subject: [PATCH 34/66] Fix blinking MD2 models MD2 models are forced to load float frames, so mesh->indices is never loaded, so glDrawElements can't be used. Use glDrawArrays instead. --- src/hardware/r_opengl/r_opengl.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 4a26aa0eb..91c48ccdb 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -1894,7 +1894,9 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, INT32 duration, INT32 pglNormalPointer(GL_FLOAT, sizeof(vbo64_t), BUFFER_OFFSET(sizeof(float) * 3)); pglTexCoordPointer(2, GL_FLOAT, sizeof(vbo64_t), BUFFER_OFFSET(sizeof(float) * 6)); - pglDrawElements(GL_TRIANGLES, mesh->numTriangles * 3, GL_UNSIGNED_SHORT, mesh->indices); + pglDrawArrays(GL_TRIANGLES, 0, mesh->numTriangles * 3); + // No tinyframes, no mesh indices + //pglDrawElements(GL_TRIANGLES, mesh->numTriangles * 3, GL_UNSIGNED_SHORT, mesh->indices); pglBindBuffer(GL_ARRAY_BUFFER, 0); } else From b056842deb04c251e7cec96397d72f0e6511327d Mon Sep 17 00:00:00 2001 From: mazmazz Date: Mon, 7 Jan 2019 04:38:17 -0500 Subject: [PATCH 35/66] Dummy out nextframe lerping (unused in Kart) --- src/hardware/hw_defs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hardware/hw_defs.h b/src/hardware/hw_defs.h index a1e4ad19a..b37850bb7 100644 --- a/src/hardware/hw_defs.h +++ b/src/hardware/hw_defs.h @@ -107,7 +107,7 @@ typedef struct #define USE_FTRANSFORM_MIRROR // Vanilla features -#define USE_MODEL_NEXTFRAME +//#define USE_MODEL_NEXTFRAME typedef struct { From 0c9be9fd4b6a83e23e67258c8ad74ae2a9d12973 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Mon, 7 Jan 2019 04:40:19 -0500 Subject: [PATCH 36/66] Add floating point epsilons --- src/doomdef.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/doomdef.h b/src/doomdef.h index a35f3291d..8b3bdee6d 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -453,6 +453,15 @@ INT32 I_GetKey(void); #define max(x, y) (((x) > (y)) ? (x) : (y)) #endif +// Floating point comparison epsilons from float.h +#ifndef FLT_EPSILON +#define FLT_EPSILON 1.1920928955078125e-7f +#endif + +#ifndef DBL_EPSILON +#define DBL_EPSILON 2.2204460492503131e-16 +#endif + // An assert-type mechanism. #ifdef PARANOIA #define I_Assert(e) ((e) ? (void)0 : I_Error("assert failed: %s, file %s, line %d", #e, __FILE__, __LINE__)) From 22cf53b8ae72ef3d288386dc33d9c0e69c827ff1 Mon Sep 17 00:00:00 2001 From: Digiku Date: Tue, 8 Jan 2019 11:22:33 -0500 Subject: [PATCH 37/66] Update hw_md2.c -- player->frameangle fix --- src/hardware/hw_md2.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.c index b70d0d6a3..fb5b201fa 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -1043,7 +1043,11 @@ void HWR_DrawMD2(gr_vissprite_t *spr) if (sprframe->rotate) { - const fixed_t anglef = AngleFixed(spr->mobj->angle); + fixed_t anglef = AngleFixed(spr->mobj->angle); + if (spr->mobj->player) + anglef = AngleFixed(spr->mobj->player->frameangle); + else + anglef = AngleFixed(spr->mobj->angle); p.angley = FIXED_TO_FLOAT(anglef); } else From bfd6d83a3b004fdf86aeb8a45e59d72c8d752e9b Mon Sep 17 00:00:00 2001 From: Digiku Date: Tue, 8 Jan 2019 11:30:04 -0500 Subject: [PATCH 38/66] Update hw_md2.c -- Redundant AngleFixed operation when modifying anglef --- src/hardware/hw_md2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.c index fb5b201fa..74301a85a 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -1043,7 +1043,7 @@ void HWR_DrawMD2(gr_vissprite_t *spr) if (sprframe->rotate) { - fixed_t anglef = AngleFixed(spr->mobj->angle); + fixed_t anglef; if (spr->mobj->player) anglef = AngleFixed(spr->mobj->player->frameangle); else From 9518939a9d246d49c914af97bd6143c87083fee7 Mon Sep 17 00:00:00 2001 From: wolfy852 Date: Thu, 21 Mar 2019 00:32:27 -0500 Subject: [PATCH 39/66] Fix Visual Studio compiling --- src/hardware/r_opengl/r_opengl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index cb2b6ae43..9fcc8d157 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -1988,10 +1988,10 @@ EXPORT void HWRAPI(SetTransform) (FTransform *stransform) if (special_splitscreen) { used_fov = atan(tan(used_fov*M_PIl/360.0l)*0.8l)*360/M_PIl; - GLPerspective(used_fov, 2*ASPECT_RATIO); + GLPerspective((GLfloat)used_fov, 2*ASPECT_RATIO); } else - GLPerspective(used_fov, ASPECT_RATIO); + GLPerspective((GLfloat)used_fov, ASPECT_RATIO); pglGetFloatv(GL_PROJECTION_MATRIX, projMatrix); // added for new coronas' code (without depth buffer) pglMatrixMode(GL_MODELVIEW); From 714b4068ca8255cefbb7c6f5211c3199626a0fa0 Mon Sep 17 00:00:00 2001 From: James R Date: Fri, 29 Mar 2019 22:00:47 -0700 Subject: [PATCH 40/66] Grab mouse on window focus Window focus does not necessarily imply mouse movement. --- src/sdl/i_video.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 9fbe57b39..74f789804 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -359,6 +359,14 @@ static INT32 Impl_SDL_Scancode_To_Keycode(SDL_Scancode code) return 0; } +static void SDLdoGrabMouse(void) +{ + SDL_ShowCursor(SDL_DISABLE); + SDL_SetWindowGrab(window, SDL_TRUE); + if (SDL_SetRelativeMouseMode(SDL_TRUE) == 0) // already warps mouse if successful + wrapmouseok = SDL_TRUE; // TODO: is wrapmouseok or HalfWarpMouse needed anymore? +} + static void SDLdoUngrabMouse(void) { SDL_ShowCursor(SDL_ENABLE); @@ -629,6 +637,9 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) //else firsttimeonmouse = SDL_FALSE; capslock = !!( SDL_GetModState() & KMOD_CAPS );// in case CL changes + + if (USE_MOUSEINPUT) + SDLdoGrabMouse(); } else if (!mousefocus && !kbfocus) { @@ -708,9 +719,7 @@ static void Impl_HandleMouseMotionEvent(SDL_MouseMotionEvent evt) // -- Monster Iestyn if (SDL_GetMouseFocus() == window && SDL_GetKeyboardFocus() == window) { - SDL_SetWindowGrab(window, SDL_TRUE); - if (SDL_SetRelativeMouseMode(SDL_TRUE) == 0) // already warps mouse if successful - wrapmouseok = SDL_TRUE; // TODO: is wrapmouseok or HalfWarpMouse needed anymore? + SDLdoGrabMouse(); } } } @@ -1277,7 +1286,7 @@ void I_StartupMouse(void) else firsttimeonmouse = SDL_FALSE; if (cv_usemouse.value) - return; + SDLdoGrabMouse(); else SDLdoUngrabMouse(); } From 4f86a447cae69f8fed5d978ea4f1ff99028e72fb Mon Sep 17 00:00:00 2001 From: Steel Titanium Date: Sat, 6 Apr 2019 23:42:02 -0400 Subject: [PATCH 41/66] Expose cv_numlaps as global variable --- src/dehacked.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/dehacked.c b/src/dehacked.c index 1c88fe832..3fcfd50bf 100644 --- a/src/dehacked.c +++ b/src/dehacked.c @@ -9925,6 +9925,9 @@ static inline int lib_getenum(lua_State *L) } else if (fastcmp(word,"mapobjectscale")) { lua_pushinteger(L, mapobjectscale); return 1; + } else if (fastcmp(word,"numlaps")) { + lua_pushinteger(L, cv_numlaps.value); + return 1; } return 0; } From 03c27101df37246c7718b243d60c3b8080e11d31 Mon Sep 17 00:00:00 2001 From: James R Date: Mon, 8 Apr 2019 15:48:20 -0700 Subject: [PATCH 42/66] "NEWPING" might as well be the only ping --- src/d_clisrv.c | 16 ------------ src/d_clisrv.h | 8 ------ src/d_net.c | 66 ++++---------------------------------------------- src/d_netcmd.c | 4 --- src/d_netcmd.h | 2 -- src/doomdef.h | 3 --- src/doomstat.h | 2 -- src/m_menu.c | 2 -- 8 files changed, 5 insertions(+), 98 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index e227ce2ed..4f5e762d3 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -91,12 +91,10 @@ tic_t jointimeout = (3*TICRATE); static boolean sendingsavegame[MAXNETNODES]; // Are we sending the savegame? static tic_t freezetimeout[MAXNETNODES]; // Until when can this node freeze the server before getting a timeout? -#ifdef NEWPING UINT16 pingmeasurecount = 1; UINT32 realpingtable[MAXPLAYERS]; //the base table of ping where an average will be sent to everyone. UINT32 playerpingtable[MAXPLAYERS]; //table of player latency values. tic_t servermaxping = 800; // server's max ping. Defaults to 800 -#endif SINT8 nodetoplayer[MAXNETNODES]; SINT8 nodetoplayer2[MAXNETNODES]; // say the numplayer for this node if any (splitscreen) SINT8 nodetoplayer3[MAXNETNODES]; // say the numplayer for this node if any (splitscreen == 2) @@ -3094,12 +3092,10 @@ static void Got_KickCmd(UINT8 **p, INT32 playernum) HU_AddChatText(va("\x82*%s has been kicked (Go away)", player_names[pnum]), false); kickreason = KR_KICK; break; -#ifdef NEWPING case KICK_MSG_PING_HIGH: HU_AddChatText(va("\x82*%s left the game (Broke ping limit)", player_names[pnum]), false); kickreason = KR_PINGLIMIT; break; -#endif case KICK_MSG_CON_FAIL: HU_AddChatText(va("\x82*%s left the game (Synch Failure)", player_names[pnum]), false); kickreason = KR_SYNCH; @@ -3172,10 +3168,8 @@ static void Got_KickCmd(UINT8 **p, INT32 playernum) D_StartTitle(); if (msg == KICK_MSG_CON_FAIL) M_StartMessage(M_GetText("Server closed connection\n(Synch failure)\nPress ESC\n"), NULL, MM_NOTHING); -#ifdef NEWPING else if (msg == KICK_MSG_PING_HIGH) M_StartMessage(M_GetText("Server closed connection\n(Broke ping limit)\nPress ESC\n"), NULL, MM_NOTHING); -#endif else if (msg == KICK_MSG_BANNED) M_StartMessage(M_GetText("You have been banned by the server\n\nPress ESC\n"), NULL, MM_NOTHING); else if (msg == KICK_MSG_CUSTOM_KICK) @@ -4630,7 +4624,6 @@ FILESTAMP resynch_local_inprogress = true; CL_AcknowledgeResynch(&netbuffer->u.resynchpak); break; -#ifdef NEWPING case PT_PING: // Only accept PT_PING from the server. if (node != servernode) @@ -4660,7 +4653,6 @@ FILESTAMP } break; -#endif case PT_SERVERCFG: break; case PT_FILEFRAGMENT: @@ -5298,7 +5290,6 @@ void TryRunTics(tic_t realtics) } } -#ifdef NEWPING /* Ping Update except better: We call this once per second and check for people's pings. If their ping happens to be too high, we increment some timer and kick them out. @@ -5382,11 +5373,9 @@ static inline void PingUpdate(void) pingmeasurecount = 1; //Reset count } -#endif static tic_t gametime = 0; -#ifdef NEWPING static void UpdatePingTable(void) { INT32 i; @@ -5401,7 +5390,6 @@ static void UpdatePingTable(void) pingmeasurecount++; } } -#endif // Handle timeouts to prevent definitive freezes from happenning static void HandleNodeTimeouts(void) @@ -5426,9 +5414,7 @@ void NetKeepAlive(void) if (realtics <= 0) // nothing new to update return; -#ifdef NEWPING UpdatePingTable(); -#endif if (server) CL_SendClientKeepAlive(); @@ -5475,9 +5461,7 @@ void NetUpdate(void) gametime = nowtime; -#ifdef NEWPING UpdatePingTable(); -#endif if (client) maketic = neededtic; diff --git a/src/d_clisrv.h b/src/d_clisrv.h index f3a9011eb..f4db85129 100644 --- a/src/d_clisrv.h +++ b/src/d_clisrv.h @@ -93,9 +93,7 @@ typedef enum PT_NODETIMEOUT, // Packet sent to self if the connection times out. PT_RESYNCHING, // Packet sent to resync players. // Blocks game advance until synched. -#ifdef NEWPING PT_PING, // Packet sent to tell clients the other client's latency to server. -#endif NUMPACKETTYPE } packettype_t; @@ -473,9 +471,7 @@ typedef struct msaskinfo_pak msaskinfo; // 22 bytes plrinfo playerinfo[MAXPLAYERS]; // 576 bytes(?) plrconfig playerconfig[MAXPLAYERS]; // (up to) 528 bytes(?) -#ifdef NEWPING UINT32 pingtable[MAXPLAYERS+1]; // 68 bytes -#endif } u; // This is needed to pack diff packet types data together } ATTRPACK doomdata_t; @@ -509,9 +505,7 @@ extern consvar_t cv_playbackspeed; #define KICK_MSG_PLAYER_QUIT 3 #define KICK_MSG_TIMEOUT 4 #define KICK_MSG_BANNED 5 -#ifdef NEWPING #define KICK_MSG_PING_HIGH 6 -#endif #define KICK_MSG_CUSTOM_KICK 7 #define KICK_MSG_CUSTOM_BAN 8 @@ -536,12 +530,10 @@ extern SINT8 servernode; void Command_Ping_f(void); extern tic_t connectiontimeout; extern tic_t jointimeout; -#ifdef NEWPING extern UINT16 pingmeasurecount; extern UINT32 realpingtable[MAXPLAYERS]; extern UINT32 playerpingtable[MAXPLAYERS]; extern tic_t servermaxping; -#endif extern consvar_t #ifdef VANILLAJOINNEXTROUND diff --git a/src/d_net.c b/src/d_net.c index 9f7199673..9cff9278a 100644 --- a/src/d_net.c +++ b/src/d_net.c @@ -185,22 +185,10 @@ typedef struct UINT8 nextacknum; UINT8 flags; -#ifndef NEWPING - // jacobson tcp timeout evaluation algorithm (Karn variation) - fixed_t ping; - fixed_t varping; - INT32 timeout; // computed with ping and varping -#endif } node_t; static node_t nodes[MAXNETNODES]; -#ifndef NEWPING -#define PINGDEFAULT ((200*TICRATE*FRACUNIT)/1000) -#define VARPINGDEFAULT ((50*TICRATE*FRACUNIT)/1000) -#define TIMEOUT(p,v) (p+4*v+FRACUNIT/2)>>FRACBITS; -#else -#define NODETIMEOUT 14 //What the above boiled down to... -#endif +#define NODETIMEOUT 14 #ifndef NONET // return <0 if a < b (mod 256) @@ -320,19 +308,7 @@ static UINT8 GetAcktosend(INT32 node) static void RemoveAck(INT32 i) { INT32 node = ackpak[i].destinationnode; -#ifndef NEWPING - fixed_t trueping = (I_GetTime() - ackpak[i].senttime)<>FRACBITS,(double)FIXED_TO_FLOAT(nodes[node].ping),(double)FIXED_TO_FLOAT(nodes[node].varping),nodes[node].timeout)); -#else DEBFILE(va("Remove ack %d\n",ackpak[i].acknum)); -#endif ackpak[i].acknum = 0; if (nodes[node].flags & NF_CLOSE) Net_CloseConnection(node); @@ -519,11 +495,7 @@ void Net_AckTicker(void) { const INT32 nodei = ackpak[i].destinationnode; node_t *node = &nodes[nodei]; -#ifdef NEWPING if (ackpak[i].acknum && ackpak[i].senttime + NODETIMEOUT < I_GetTime()) -#else - if (ackpak[i].acknum && ackpak[i].senttime + node->timeout < I_GetTime()) -#endif { if (ackpak[i].resentnum > 10 && (node->flags & NF_CLOSE)) { @@ -534,13 +506,8 @@ void Net_AckTicker(void) ackpak[i].acknum = 0; continue; } -#ifdef NEWPING DEBFILE(va("Resend ack %d, %u<%d at %u\n", ackpak[i].acknum, ackpak[i].senttime, NODETIMEOUT, I_GetTime())); -#else - DEBFILE(va("Resend ack %d, %u<%d at %u\n", ackpak[i].acknum, ackpak[i].senttime, - node->timeout, I_GetTime())); -#endif M_Memcpy(netbuffer, ackpak[i].pak.raw, ackpak[i].length); ackpak[i].senttime = I_GetTime(); ackpak[i].resentnum++; @@ -658,11 +625,6 @@ void Net_WaitAllAckReceived(UINT32 timeout) static void InitNode(node_t *node) { node->acktosend_head = node->acktosend_tail = 0; -#ifndef NEWPING - node->ping = PINGDEFAULT; - node->varping = VARPINGDEFAULT; - node->timeout = TIMEOUT(node->ping, node->varping); -#endif node->firstacktosend = 0; node->nextacknum = 1; node->remotefirstack = 0; @@ -854,9 +816,7 @@ static const char *packettypename[NUMPACKETTYPE] = "CLIENTJOIN", "NODETIMEOUT", "RESYNCHING", -#ifdef NEWPING "PING" -#endif }; static void DebugPrintpacket(const char *header) @@ -1412,28 +1372,12 @@ boolean D_CheckNetGame(void) void Command_Ping_f(void) { -#ifndef NEWPING - if(server) + INT32 i; + for (i = 0; i < MAXPLAYERS;i++) { -#endif - INT32 i; - for (i = 0; i < MAXPLAYERS;i++) - { -#ifndef NEWPING - const INT32 node = playernode[i]; - if (playeringame[i] && node != 0) - CONS_Printf(M_GetText("%.2d : %s\n %d tics, %d ms.\n"), i, player_names[i], - GetLag(node), G_TicsToMilliseconds(GetLag(node))); -#else - if (playeringame[i] && i != 0) - CONS_Printf(M_GetText("%.2d : %s\n %d ms\n"), i, player_names[i], playerpingtable[i]); -#endif - } -#ifndef NEWPING + if (playeringame[i] && i != 0) + CONS_Printf(M_GetText("%.2d : %s\n %d ms\n"), i, player_names[i], playerpingtable[i]); } - else - CONS_Printf(M_GetText("Only the server can use this.\n")); -#endif } void D_CloseConnection(void) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 08bf33185..0173b5db4 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -434,7 +434,6 @@ static CV_PossibleValue_t nettimeout_cons_t[] = {{TICRATE/7, "MIN"}, {60*TICRATE consvar_t cv_nettimeout = {"nettimeout", "105", CV_CALL|CV_SAVE, nettimeout_cons_t, NetTimeout_OnChange, 0, NULL, NULL, 0, 0, NULL}; //static CV_PossibleValue_t jointimeout_cons_t[] = {{5*TICRATE, "MIN"}, {60*TICRATE, "MAX"}, {0, NULL}}; consvar_t cv_jointimeout = {"jointimeout", "105", CV_CALL|CV_SAVE, nettimeout_cons_t, JoinTimeout_OnChange, 0, NULL, NULL, 0, 0, NULL}; -#ifdef NEWPING static CV_PossibleValue_t maxping_cons_t[] = {{0, "MIN"}, {1000, "MAX"}, {0, NULL}}; consvar_t cv_maxping = {"maxping", "800", CV_SAVE, maxping_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -445,7 +444,6 @@ consvar_t cv_pingtimeout = {"pingtimeout", "10", CV_SAVE, pingtimeout_cons_t, NU static CV_PossibleValue_t showping_cons_t[] = {{0, "Off"}, {1, "Always"}, {2, "Warning"}, {0, NULL}}; consvar_t cv_showping = {"showping", "Always", CV_SAVE, showping_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; -#endif // Intermission time Tails 04-19-2002 static CV_PossibleValue_t inttime_cons_t[] = {{0, "MIN"}, {3600, "MAX"}, {0, NULL}}; consvar_t cv_inttime = {"inttime", "20", CV_NETVAR, inttime_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -674,11 +672,9 @@ void D_RegisterServerCommands(void) CV_RegisterVar(&cv_skipmapcheck); CV_RegisterVar(&cv_sleep); -#ifdef NEWPING CV_RegisterVar(&cv_maxping); CV_RegisterVar(&cv_pingtimeout); CV_RegisterVar(&cv_showping); -#endif #ifdef SEENAMES CV_RegisterVar(&cv_allowseenames); diff --git a/src/d_netcmd.h b/src/d_netcmd.h index 166c5e008..e6c327abf 100644 --- a/src/d_netcmd.h +++ b/src/d_netcmd.h @@ -143,11 +143,9 @@ extern consvar_t cv_ringslinger, cv_soundtest; extern consvar_t cv_specialrings, cv_powerstones, cv_matchboxes, cv_competitionboxes; -#ifdef NEWPING extern consvar_t cv_maxping; extern consvar_t cv_pingtimeout; extern consvar_t cv_showping; -#endif extern consvar_t cv_skipmapcheck; diff --git a/src/doomdef.h b/src/doomdef.h index 6664ff51a..51052a0b9 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -601,9 +601,6 @@ extern const char *compdate, *comptime, *comprevision, *compbranch; /// Polyobject fake flat code #define POLYOBJECTS_PLANES -/// Improved way of dealing with ping values and a ping limit. -#define NEWPING - /// See name of player in your crosshair #define SEENAMES diff --git a/src/doomstat.h b/src/doomstat.h index 834b3a7cf..4b0c2e3e8 100644 --- a/src/doomstat.h +++ b/src/doomstat.h @@ -543,9 +543,7 @@ extern consvar_t cv_forceskin; // force clients to use the server's skin extern consvar_t cv_downloading; // allow clients to downloading WADs. extern consvar_t cv_nettimeout; // SRB2Kart: Advanced server options menu extern consvar_t cv_jointimeout; -#ifdef NEWPING extern consvar_t cv_maxping; -#endif extern ticcmd_t netcmds[BACKUPTICS][MAXPLAYERS]; extern INT32 serverplayer; extern INT32 adminplayers[MAXPLAYERS]; diff --git a/src/m_menu.c b/src/m_menu.c index 3ad076ff7..afb085c4e 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -2331,10 +2331,8 @@ static void M_ChangeCvar(INT32 choice) choice *= (TICRATE/7); else if (cv == &cv_maxsend) choice *= 512; -#ifdef NEWPING else if (cv == &cv_maxping) choice *= 50; -#endif #endif CV_AddValue(cv,choice); } From 2fa20751e99d1046213daa7c7e282bf32f0a4f44 Mon Sep 17 00:00:00 2001 From: James R Date: Mon, 8 Apr 2019 15:57:23 -0700 Subject: [PATCH 43/66] Replace ping command with a condensed and sorted version --- src/d_net.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 62 insertions(+), 3 deletions(-) diff --git a/src/d_net.c b/src/d_net.c index 9cff9278a..94b11d518 100644 --- a/src/d_net.c +++ b/src/d_net.c @@ -1370,13 +1370,72 @@ boolean D_CheckNetGame(void) return ret; } +struct pingcell +{ + INT32 num; + INT32 ms; +}; + +static int pingcellcmp(const void *va, const void *vb) +{ + const struct pingcell *a, *b; + a = va; + b = vb; + return ( a->ms - b->ms ); +} + +/* +New ping command formatted nicely to present ping in +ascending order. And with equally spaced columns. +The caller's ping is presented at the bottom too, for +convenience. +*/ + void Command_Ping_f(void) { + struct pingcell pingv[MAXPLAYERS]; + INT32 pingc; + + int name_width = 0; + int ms_width = 0; + + int n; INT32 i; - for (i = 0; i < MAXPLAYERS;i++) + + pingc = 0; + for (i = 1; i < MAXPLAYERS; ++i) + if (playeringame[i]) { - if (playeringame[i] && i != 0) - CONS_Printf(M_GetText("%.2d : %s\n %d ms\n"), i, player_names[i], playerpingtable[i]); + n = strlen(player_names[i]); + if (n > name_width) + name_width = n; + + n = playerpingtable[i]; + if (n > ms_width) + ms_width = n; + + pingv[pingc].num = i; + pingv[pingc].ms = playerpingtable[i]; + pingc++; + } + + if (ms_width < 10) ms_width = 1; + else if (ms_width < 100) ms_width = 2; + else ms_width = 3; + + qsort(pingv, pingc, sizeof (struct pingcell), &pingcellcmp); + + for (i = 0; i < pingc; ++i) + { + CONS_Printf("%02d : %-*s %*d ms\n", + pingv[i].num, + name_width, player_names[pingv[i].num], + ms_width, pingv[i].ms); + } + + if (!server && playeringame[consoleplayer]) + { + CONS_Printf("\nYour ping is %d ms\n", playerpingtable[consoleplayer]); } } From aec9e721dc3438a755d32dbc5f50cdddf6ca504d Mon Sep 17 00:00:00 2001 From: wolfy852 Date: Fri, 12 Apr 2019 00:35:35 -0500 Subject: [PATCH 44/66] Generic model terminology --- src/hardware/hw_main.c | 6 +++--- src/hardware/hw_main.h | 2 +- src/hardware/hw_md2.c | 44 +++++++++++++++++++++--------------------- src/m_menu.c | 2 +- src/r_main.c | 2 +- src/v_video.c | 2 +- 6 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 5c09a0bca..af0546dc1 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -5261,14 +5261,14 @@ static void HWR_DrawSprites(void) if (spr->mobj && spr->mobj->skin && spr->mobj->sprite == SPR_PLAY) { // 8/1/19: Only don't display player models if no default SPR_PLAY is found. - if (!cv_grmd2.value || ((md2_playermodels[(skin_t*)spr->mobj->skin-skins].notfound || md2_playermodels[(skin_t*)spr->mobj->skin-skins].scale < 0.0f) && (md2_models[SPR_PLAY].notfound || md2_models[SPR_PLAY].scale < 0.0f))) + if (!cv_grmdls.value || ((md2_playermodels[(skin_t*)spr->mobj->skin-skins].notfound || md2_playermodels[(skin_t*)spr->mobj->skin-skins].scale < 0.0f) && (md2_models[SPR_PLAY].notfound || md2_models[SPR_PLAY].scale < 0.0f))) HWR_DrawSprite(spr); else HWR_DrawMD2(spr); } else { - if (!cv_grmd2.value || md2_models[spr->mobj->sprite].notfound || md2_models[spr->mobj->sprite].scale < 0.0f) + if (!cv_grmdls.value || md2_models[spr->mobj->sprite].notfound || md2_models[spr->mobj->sprite].scale < 0.0f) HWR_DrawSprite(spr); else HWR_DrawMD2(spr); @@ -5435,7 +5435,7 @@ static void HWR_ProjectSprite(mobj_t *thing) tz = (tr_x * gr_viewcos) + (tr_y * gr_viewsin); // thing is behind view plane? - if (tz < ZCLIP_PLANE && !papersprite && (!cv_grmd2.value || md2_models[thing->sprite].notfound == true)) //Yellow: Only MD2's dont disappear + if (tz < ZCLIP_PLANE && !papersprite && (!cv_grmdls.value || md2_models[thing->sprite].notfound == true)) //Yellow: Only MD2's dont disappear return; // The above can stay as it works for cutting sprites that are too close diff --git a/src/hardware/hw_main.h b/src/hardware/hw_main.h index 8c9590e9c..335240c5c 100644 --- a/src/hardware/hw_main.h +++ b/src/hardware/hw_main.h @@ -79,7 +79,7 @@ extern consvar_t cv_grstaticlighting; extern consvar_t cv_grcoronas; extern consvar_t cv_grcoronasize; #endif -extern consvar_t cv_grmd2; +extern consvar_t cv_grmdls; extern consvar_t cv_grfog; extern consvar_t cv_grfogcolor; extern consvar_t cv_grfogdensity; diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.c index 07ccd3d8a..d217f4094 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -164,13 +164,13 @@ static GrTextureFormat_t PNG_Load(const char *filename, int *w, int *h, GLPatch_ #endif volatile png_FILE_p png_FILE; //Filename checking fixed ~Monster Iestyn and Golden - char *pngfilename = va("%s"PATHSEP"md2"PATHSEP"%s", srb2home, filename); + char *pngfilename = va("%s"PATHSEP"mdls"PATHSEP"%s", srb2home, filename); FIL_ForceExtension(pngfilename, ".png"); png_FILE = fopen(pngfilename, "rb"); if (!png_FILE) { - pngfilename = va("%s"PATHSEP"md2"PATHSEP"%s", srb2path, filename); + pngfilename = va("%s"PATHSEP"mdls"PATHSEP"%s", srb2path, filename); FIL_ForceExtension(pngfilename, ".png"); png_FILE = fopen(pngfilename, "rb"); //CONS_Debug(DBG_RENDER, "M_SavePNG: Error on opening %s for loading\n", filename); @@ -297,13 +297,13 @@ static GrTextureFormat_t PCX_Load(const char *filename, int *w, int *h, INT32 ch, rep; FILE *file; //Filename checking fixed ~Monster Iestyn and Golden - char *pcxfilename = va("%s"PATHSEP"md2"PATHSEP"%s", srb2home, filename); + char *pcxfilename = va("%s"PATHSEP"mdls"PATHSEP"%s", srb2home, filename); FIL_ForceExtension(pcxfilename, ".pcx"); file = fopen(pcxfilename, "rb"); if (!file) { - pcxfilename = va("%s"PATHSEP"md2"PATHSEP"%s", srb2path, filename); + pcxfilename = va("%s"PATHSEP"mdls"PATHSEP"%s", srb2path, filename); FIL_ForceExtension(pcxfilename, ".pcx"); file = fopen(pcxfilename, "rb"); if (!file) @@ -492,16 +492,16 @@ void HWR_InitMD2(void) md2_models[i].error = false; } - // read the md2.dat file + // read the mdls.dat file //Filename checking fixed ~Monster Iestyn and Golden - f = fopen(va("%s"PATHSEP"%s", srb2home, "kmd2.dat"), "rt"); + f = fopen(va("%s"PATHSEP"%s", srb2home, "mdls.dat"), "rt"); if (!f) { - f = fopen(va("%s"PATHSEP"%s", srb2path, "kmd2.dat"), "rt"); + f = fopen(va("%s"PATHSEP"%s", srb2path, "mdls.dat"), "rt"); if (!f) { - CONS_Printf("%s %s\n", M_GetText("Error while loading kmd2.dat:"), strerror(errno)); + CONS_Printf("%s %s\n", M_GetText("Error while loading mdls.dat:"), strerror(errno)); nomd2s = true; return; } @@ -510,7 +510,7 @@ void HWR_InitMD2(void) { /*if (stricmp(name, "PLAY") == 0) { - CONS_Printf("MD2 for sprite PLAY detected in kmd2.dat, use a player skin instead!\n"); + CONS_Printf("MD2 for sprite PLAY detected in mdls.dat, use a player skin instead!\n"); continue; }*/ // 8/1/19: Allow PLAY to load for default MD2. @@ -545,7 +545,7 @@ void HWR_InitMD2(void) } } // no sprite/player skin name found?!? - CONS_Printf("Unknown sprite/player skin %s detected in kmd2.dat\n", name); + CONS_Printf("Unknown sprite/player skin %s detected in mdls.dat\n", name); md2found: // move on to next line... continue; @@ -564,16 +564,16 @@ void HWR_AddPlayerMD2(int skin) // For MD2's that were added after startup CONS_Printf("AddPlayerMD2()...\n"); - // read the md2.dat file + // read the mdls.dat file //Filename checking fixed ~Monster Iestyn and Golden - f = fopen(va("%s"PATHSEP"%s", srb2home, "kmd2.dat"), "rt"); + f = fopen(va("%s"PATHSEP"%s", srb2home, "mdls.dat"), "rt"); if (!f) { - f = fopen(va("%s"PATHSEP"%s", srb2path, "kmd2.dat"), "rt"); + f = fopen(va("%s"PATHSEP"%s", srb2path, "mdls.dat"), "rt"); if (!f) { - CONS_Printf("%s %s\n", M_GetText("Error while loading kmd2.dat:"), strerror(errno)); + CONS_Printf("%s %s\n", M_GetText("Error while loading mdls.dat:"), strerror(errno)); nomd2s = true; return; } @@ -603,7 +603,7 @@ playermd2found: void HWR_AddSpriteMD2(size_t spritenum) // For MD2s that were added after startup { FILE *f; - // name[18] is used to check for names in the kmd2.dat file that match with sprites or player skins + // name[18] is used to check for names in the mdls.dat file that match with sprites or player skins // sprite names are always 4 characters long, and names is for player skins can be up to 19 characters long char name[18], filename[32]; float scale, offset; @@ -616,14 +616,14 @@ void HWR_AddSpriteMD2(size_t spritenum) // For MD2s that were added after startu // Read the md2.dat file //Filename checking fixed ~Monster Iestyn and Golden - f = fopen(va("%s"PATHSEP"%s", srb2home, "kmd2.dat"), "rt"); + f = fopen(va("%s"PATHSEP"%s", srb2home, "mdls.dat"), "rt"); if (!f) { - f = fopen(va("%s"PATHSEP"%s", srb2path, "kmd2.dat"), "rt"); + f = fopen(va("%s"PATHSEP"%s", srb2path, "mdls.dat"), "rt"); if (!f) { - CONS_Printf("%s %s\n", M_GetText("Error while loading kmd2.dat:"), strerror(errno)); + CONS_Printf("%s %s\n", M_GetText("Error while loading mdls.dat:"), strerror(errno)); nomd2s = true; return; } @@ -867,7 +867,7 @@ void HWR_DrawMD2(gr_vissprite_t *spr) md2_t *md2; UINT8 color[4]; - if (!cv_grmd2.value) + if (!cv_grmdls.value) return; if (spr->precip) @@ -951,8 +951,8 @@ void HWR_DrawMD2(gr_vissprite_t *spr) return; // we already failed loading this before :( if (!md2->model) { - CONS_Debug(DBG_RENDER, "Loading MD2... (%s, %s)", sprnames[spr->mobj->sprite], md2->filename); - sprintf(filename, "md2/%s", md2->filename); + CONS_Debug(DBG_RENDER, "Loading model... (%s, %s)", sprnames[spr->mobj->sprite], md2->filename); + sprintf(filename, "mdls/%s", md2->filename); md2->model = md2_readModel(filename); if (md2->model) @@ -1034,7 +1034,7 @@ void HWR_DrawMD2(gr_vissprite_t *spr) frame = (spr->mobj->frame & FF_FRAMEMASK) % md2->model->meshes[0].numFrames; #ifdef USE_MODEL_NEXTFRAME - if (cv_grmd2.value == 1 && tics <= durs) + if (cv_grmdls.value == 1 && tics <= durs) { // frames are handled differently for states with FF_ANIMATE, so get the next frame differently for the interpolation if (spr->mobj->frame & FF_ANIMATE) diff --git a/src/m_menu.c b/src/m_menu.c index 3ad076ff7..9a98bb73a 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -1217,7 +1217,7 @@ static menuitem_t OP_VideoOptionsMenu[] = {IT_STRING | IT_CVAR, NULL, "Vertical Sync", &cv_vidwait, 90}, #ifdef HWRENDER - {IT_STRING | IT_CVAR, NULL, "3D models", &cv_grmd2, 105}, + {IT_STRING | IT_CVAR, NULL, "3D models", &cv_grmdls, 105}, {IT_SUBMENU|IT_STRING, NULL, "OpenGL Options...", &OP_OpenGLOptionsDef, 115}, #endif }; diff --git a/src/r_main.c b/src/r_main.c index 1a72d6165..9e355a09c 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -1569,7 +1569,7 @@ void R_RegisterEngineStuff(void) CV_RegisterVar(&cv_grcoronas); CV_RegisterVar(&cv_grcoronasize); #endif - CV_RegisterVar(&cv_grmd2); + CV_RegisterVar(&cv_grmdls); #endif #ifdef HWRENDER diff --git a/src/v_video.c b/src/v_video.c index 16d39e1d0..bac0faea5 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -79,7 +79,7 @@ consvar_t cv_grcoronasize = {"gr_coronasize", "1", CV_SAVE| CV_FLOAT, 0, NULL, 0 //static CV_PossibleValue_t CV_MD2[] = {{0, "Off"}, {1, "On"}, {2, "Old"}, {0, NULL}}; // console variables in development -consvar_t cv_grmd2 = {"gr_md2", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_grmdls = {"gr_mdls", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; #endif const UINT8 gammatable[5][256] = From c7be2769a2570a849bd596f70ab4e2fd6682742c Mon Sep 17 00:00:00 2001 From: fickleheart Date: Fri, 12 Apr 2019 00:46:52 -0500 Subject: [PATCH 45/66] Allow argument substitution in aliases --- src/command.c | 44 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/src/command.c b/src/command.c index a5d45bc1e..543df6ce9 100644 --- a/src/command.c +++ b/src/command.c @@ -537,10 +537,48 @@ static void COM_ExecuteString(char *ptext) { CONS_Alert(CONS_WARNING, M_GetText("Alias recursion cycle detected!\n")); recursion = 0; - return; } - recursion++; - COM_BufInsertText(a->value); + else + { + char buf[1024]; + char *write = buf, *read = a->value, *seek = read; + + while (*seek != '\0') + { + if (*seek == '$') + { + memcpy(write, read, seek-read); + write += seek-read; + + seek++; + + if (*seek >= '1' && *seek <= '9') + { + if (com_argc > (size_t)(*seek - '0')) + { + memcpy(write, com_argv[*seek - '0'], strlen(com_argv[*seek - '0'])); + write += strlen(com_argv[*seek - '0']); + } + seek++; + } + else + { + *write = '$'; + write++; + } + + read = seek; + } + else + seek++; + } + memcpy(write, read, seek-read); + write += seek-read; + *write = '\0'; + + recursion++; + COM_BufInsertText(buf); + } return; } } From 9d408b474b50b68244f78c72a8ecc9114e9b00fb Mon Sep 17 00:00:00 2001 From: fickleheart Date: Sat, 13 Apr 2019 10:16:54 -0500 Subject: [PATCH 46/66] Use strchr? --- src/command.c | 45 +++++++++++++++++++-------------------------- 1 file changed, 19 insertions(+), 26 deletions(-) diff --git a/src/command.c b/src/command.c index 543df6ce9..8e2d0037e 100644 --- a/src/command.c +++ b/src/command.c @@ -543,38 +543,31 @@ static void COM_ExecuteString(char *ptext) char buf[1024]; char *write = buf, *read = a->value, *seek = read; - while (*seek != '\0') + while ((seek = strchr(seek, '$')) != NULL) { - if (*seek == '$') + memcpy(write, read, seek-read); + write += seek-read; + + seek++; + + if (*seek >= '1' && *seek <= '9') { - memcpy(write, read, seek-read); - write += seek-read; - + if (com_argc > (size_t)(*seek - '0')) + { + memcpy(write, com_argv[*seek - '0'], strlen(com_argv[*seek - '0'])); + write += strlen(com_argv[*seek - '0']); + } seek++; - - if (*seek >= '1' && *seek <= '9') - { - if (com_argc > (size_t)(*seek - '0')) - { - memcpy(write, com_argv[*seek - '0'], strlen(com_argv[*seek - '0'])); - write += strlen(com_argv[*seek - '0']); - } - seek++; - } - else - { - *write = '$'; - write++; - } - - read = seek; } else - seek++; + { + *write = '$'; + write++; + } + + read = seek; } - memcpy(write, read, seek-read); - write += seek-read; - *write = '\0'; + WRITESTRING(write, read); recursion++; COM_BufInsertText(buf); From 0318bf7116e50cc41c2f9967e6739d4de25607c2 Mon Sep 17 00:00:00 2001 From: fickleheart Date: Sat, 13 Apr 2019 10:25:56 -0500 Subject: [PATCH 47/66] Preserve quote and etc in aliases --- src/command.c | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/src/command.c b/src/command.c index 8e2d0037e..7d7a357a8 100644 --- a/src/command.c +++ b/src/command.c @@ -594,8 +594,6 @@ static void COM_ExecuteString(char *ptext) static void COM_Alias_f(void) { cmdalias_t *a; - char cmd[1024]; - size_t i, c; if (COM_Argc() < 3) { @@ -608,19 +606,9 @@ static void COM_Alias_f(void) com_alias = a; a->name = Z_StrDup(COM_Argv(1)); - - // copy the rest of the command line - cmd[0] = 0; // start out with a null string - c = COM_Argc(); - for (i = 2; i < c; i++) - { - strcat(cmd, COM_Argv(i)); - if (i != c) - strcat(cmd, " "); - } - strcat(cmd, "\n"); - - a->value = Z_StrDup(cmd); + // Just use arg 2 if it's the only other argument, in case the alias is wrapped in quotes (backward compat, or multiple commands in one string). + // Otherwise pull the whole string and seek to the end of the alias name. The strctr is in case the alias is quoted. + a->value = Z_StrDup(COM_Argc() == 3 ? COM_Argv(2) : (strchr(COM_Args() + strlen(a->name), ' ') + 1)); } /** Prints a line of text to the console. From 870f29f8616f0c99e262e5f2ab172d2228a93d48 Mon Sep 17 00:00:00 2001 From: wolfy852 Date: Sun, 21 Apr 2019 07:52:01 -0500 Subject: [PATCH 48/66] Flashing tics on respawn --- src/k_kart.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/k_kart.c b/src/k_kart.c index 9d928a2a2..17790bf00 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -1568,7 +1568,7 @@ void K_RespawnChecker(player_t *player) if (!P_IsObjectOnGround(player->mo) && !mapreset) { - player->powers[pw_flashing] = 2; + player->powers[pw_flashing] = K_GetKartFlashing(player); // Sal: The old behavior was stupid and prone to accidental usage. // Let's rip off Mania instead, and turn this into a Drop Dash! From 50ae248b84defb4d399fa9794783fd51ab32f696 Mon Sep 17 00:00:00 2001 From: James R Date: Fri, 26 Apr 2019 12:59:21 -0700 Subject: [PATCH 49/66] Unfuck MS connecting and error reporting Reconnect if the socket is closed. Report the proper error from SO_ERROR and report an error from getsockopt. --- src/mserv.c | 48 +++++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/src/mserv.c b/src/mserv.c index f5c4fa889..eb1e6302e 100644 --- a/src/mserv.c +++ b/src/mserv.c @@ -661,11 +661,19 @@ FUNCMATH static const char *int2str(INT32 n) #ifndef NONET static INT32 ConnectionFailed(void) { + time(&MSLastPing); con_state = MSCS_FAILED; CONS_Alert(CONS_ERROR, M_GetText("Connection to Master Server failed\n")); CloseConnection(); return MS_CONNECT_ERROR; } + +static INT32 ConnectionFailedwerrno(int no) +{ + CONS_Alert(CONS_ERROR, M_GetText("Master Server socket error: %s\n"), + strerror(no)); + return ConnectionFailed(); +} #endif /** Tries to register the local game server on the master server. @@ -682,44 +690,41 @@ static INT32 AddToMasterServer(boolean firstadd) msg_server_t *info = (msg_server_t *)msg.buffer; INT32 room = -1; fd_set tset; - time_t timestamp = time(NULL); UINT32 signature, tmp; const char *insname; + if (socket_fd == ERRSOCKET)/* Woah, our socket was closed! */ + { + if (MS_Connect(GetMasterServerIP(), GetMasterServerPort(), 0)) + return ConnectionFailedwerrno(errno); + } + M_Memcpy(&tset, &wset, sizeof (tset)); res = select(255, NULL, &tset, NULL, &select_timeout); - if (res != ERRSOCKET && !res) + if (res == 0)/* nothing selected */ { - if (retry++ > 30) // an about 30 second timeout + /* + Timeout next call because SendPingToMasterServer + (our calling function) already calls this once + every two minutes. + */ + if (retry++ == 1) { retry = 0; CONS_Alert(CONS_ERROR, M_GetText("Master Server timed out\n")); - MSLastPing = timestamp; return ConnectionFailed(); } return MS_CONNECT_ERROR; } retry = 0; - if (res == ERRSOCKET) - { - if (MS_Connect(GetMasterServerIP(), GetMasterServerPort(), 0)) - { - CONS_Alert(CONS_ERROR, M_GetText("Master Server socket error #%u: %s\n"), errno, strerror(errno)); - MSLastPing = timestamp; - return ConnectionFailed(); - } - } // so, the socket is writable, but what does that mean, that the connection is // ok, or bad... let see that! j = (socklen_t)sizeof (i); - getsockopt(socket_fd, SOL_SOCKET, SO_ERROR, (char *)&i, &j); + if (getsockopt(socket_fd, SOL_SOCKET, SO_ERROR, (char *)&i, &j) == ERRSOCKET) + return ConnectionFailedwerrno(errno); if (i) // it was bad - { - CONS_Alert(CONS_ERROR, M_GetText("Master Server socket error #%u: %s\n"), errno, strerror(errno)); - MSLastPing = timestamp; - return ConnectionFailed(); - } + return ConnectionFailedwerrno(i); #ifdef PARANOIA if (ms_RoomId <= 0) @@ -752,15 +757,12 @@ static INT32 AddToMasterServer(boolean firstadd) msg.length = (UINT32)sizeof (msg_server_t); msg.room = 0; if (MS_Write(&msg) < 0) - { - MSLastPing = timestamp; return ConnectionFailed(); - } if(con_state != MSCS_REGISTERED) CONS_Printf(M_GetText("Master Server update successful.\n")); - MSLastPing = timestamp; + time(&MSLastPing); con_state = MSCS_REGISTERED; CloseConnection(); #endif From 1d77716d7ebeea2bf279d690a6c0542ff155cb22 Mon Sep 17 00:00:00 2001 From: James R Date: Fri, 26 Apr 2019 13:06:26 -0700 Subject: [PATCH 50/66] Check error on select --- src/mserv.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/mserv.c b/src/mserv.c index eb1e6302e..1b0b41be3 100644 --- a/src/mserv.c +++ b/src/mserv.c @@ -701,6 +701,8 @@ static INT32 AddToMasterServer(boolean firstadd) M_Memcpy(&tset, &wset, sizeof (tset)); res = select(255, NULL, &tset, NULL, &select_timeout); + if (res == -1) + return ConnectionFailedwerrno(errno); if (res == 0)/* nothing selected */ { /* From 9f0887fafca1388561c535714c60d84016f2f447 Mon Sep 17 00:00:00 2001 From: James R Date: Fri, 26 Apr 2019 13:08:35 -0700 Subject: [PATCH 51/66] Force of habit --- src/mserv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mserv.c b/src/mserv.c index 1b0b41be3..5d10aa3ca 100644 --- a/src/mserv.c +++ b/src/mserv.c @@ -701,7 +701,7 @@ static INT32 AddToMasterServer(boolean firstadd) M_Memcpy(&tset, &wset, sizeof (tset)); res = select(255, NULL, &tset, NULL, &select_timeout); - if (res == -1) + if (res == ERRSOCKET) return ConnectionFailedwerrno(errno); if (res == 0)/* nothing selected */ { From 2e221946777c2d0b287059aceb59a4aa3478da86 Mon Sep 17 00:00:00 2001 From: TehRealSalt Date: Fri, 26 Apr 2019 18:18:53 -0400 Subject: [PATCH 52/66] Final v1 colors - 11 new colors: Skunk, Artichoke, Pigeon, Walnut, Cinnamon, Lemonade, Quarry, Crocodile, Azure, Thunder, & Wristwatch - Updated Dawn, Sunset, Cream, Gold, Olive, Vomit, Lime, Plague, & Caribbean - Updated opposite colors for Bubblegum & Camouflage in response to the new colors --- src/dehacked.c | 17 +++++++++----- src/doomdef.h | 11 +++++++++ src/hu_stuff.c | 11 +++++++++ src/k_kart.c | 60 +++++++++++++++++++++++++++++++++++++++----------- 4 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/dehacked.c b/src/dehacked.c index 1c88fe832..0431eb0c7 100644 --- a/src/dehacked.c +++ b/src/dehacked.c @@ -8135,29 +8135,35 @@ static const char *const ML_LIST[16] = { // This DOES differ from r_draw's Color_Names, unfortunately. // Also includes Super colors -static const char *COLOR_ENUMS[] = { // Rejigged for Kart. +static const char *COLOR_ENUMS[] = { // Rejigged for Kart. "NONE", // SKINCOLOR_NONE "WHITE", // SKINCOLOR_WHITE "SILVER", // SKINCOLOR_SILVER "GREY", // SKINCOLOR_GREY "NICKEL", // SKINCOLOR_NICKEL "BLACK", // SKINCOLOR_BLACK + "SKUNK", // SKINCOLOR_SKUNK "FAIRY", // SKINCOLOR_FAIRY "POPCORN", // SKINCOLOR_POPCORN + "ARTICHOKE", // SKINCOLOR_ARTICHOKE + "PIGEON", // SKINCOLOR_PIGEON "SEPIA", // SKINCOLOR_SEPIA "BEIGE", // SKINCOLOR_BEIGE + "WALNUT", // SKINCOLOR_WALNUT "BROWN", // SKINCOLOR_BROWN "LEATHER", // SKINCOLOR_LEATHER "SALMON", // SKINCOLOR_SALMON "PINK", // SKINCOLOR_PINK "ROSE", // SKINCOLOR_ROSE "BRICK", // SKINCOLOR_BRICK + "CINNAMON", // SKINCOLOR_CINNAMON "RUBY", // SKINCOLOR_RUBY "RASPBERRY", // SKINCOLOR_RASPBERRY "CHERRY", // SKINCOLOR_CHERRY "RED", // SKINCOLOR_RED "CRIMSON", // SKINCOLOR_CRIMSON "MAROON", // SKINCOLOR_MAROON + "LEMONADE", // SKINCOLOR_LEMONADE "FLAME", // SKINCOLOR_FLAME "SCARLET", // SKINCOLOR_SCARLET "KETCHUP", // SKINCOLOR_KETCHUP @@ -8176,8 +8182,10 @@ static const char *COLOR_ENUMS[] = { // Rejigged for Kart. "ROYAL", // SKINCOLOR_ROYAL "BRONZE", // SKINCOLOR_BRONZE "COPPER", // SKINCOLOR_COPPER + "QUARRY", // SKINCOLOR_QUARRY "YELLOW", // SKINCOLOR_YELLOW "MUSTARD", // SKINCOLOR_MUSTARD + "CROCODILE", // SKINCOLOR_CROCODILE "OLIVE", // SKINCOLOR_OLIVE "VOMIT", // SKINCOLOR_VOMIT "GARDEN", // SKINCOLOR_GARDEN @@ -8197,6 +8205,7 @@ static const char *COLOR_ENUMS[] = { // Rejigged for Kart. "PLAGUE", // SKINCOLOR_PLAGUE "ALGAE", // SKINCOLOR_ALGAE "CARIBBEAN", // SKINCOLOR_CARIBBEAN + "AZURE", // SKINCOLOR_AZURE "AQUA", // SKINCOLOR_AQUA "TEAL", // SKINCOLOR_TEAL "CYAN", // SKINCOLOR_CYAN @@ -8206,7 +8215,9 @@ static const char *COLOR_ENUMS[] = { // Rejigged for Kart. "PLATINUM", // SKINCOLOR_PLATINUM "SLATE", // SKINCOLOR_SLATE "STEEL", // SKINCOLOR_STEEL + "THUNDER", // SKINCOLOR_THUNDER "RUST", // SKINCOLOR_RUST + "WRISTWATCH", // SKINCOLOR_WRISTWATCH "JET", // SKINCOLOR_JET "SAPPHIRE", // SKINCOLOR_SAPPHIRE "PERIWINKLE", // SKINCOLOR_PERIWINKLE @@ -8227,10 +8238,6 @@ static const char *COLOR_ENUMS[] = { // Rejigged for Kart. "POMEGRANATE", // SKINCOLOR_POMEGRANATE "LILAC", // SKINCOLOR_LILAC - - - - // Special super colors // Super Sonic Yellow "SUPER1", // SKINCOLOR_SUPER1 diff --git a/src/doomdef.h b/src/doomdef.h index 6664ff51a..07761c60f 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -256,22 +256,28 @@ typedef enum SKINCOLOR_GREY, SKINCOLOR_NICKEL, SKINCOLOR_BLACK, + SKINCOLOR_SKUNK, SKINCOLOR_FAIRY, SKINCOLOR_POPCORN, + SKINCOLOR_ARTICHOKE, + SKINCOLOR_PIGEON, SKINCOLOR_SEPIA, SKINCOLOR_BEIGE, + SKINCOLOR_WALNUT, SKINCOLOR_BROWN, SKINCOLOR_LEATHER, SKINCOLOR_SALMON, SKINCOLOR_PINK, SKINCOLOR_ROSE, SKINCOLOR_BRICK, + SKINCOLOR_CINNAMON, SKINCOLOR_RUBY, SKINCOLOR_RASPBERRY, SKINCOLOR_CHERRY, SKINCOLOR_RED, SKINCOLOR_CRIMSON, SKINCOLOR_MAROON, + SKINCOLOR_LEMONADE, SKINCOLOR_FLAME, SKINCOLOR_SCARLET, SKINCOLOR_KETCHUP, @@ -290,8 +296,10 @@ typedef enum SKINCOLOR_ROYAL, SKINCOLOR_BRONZE, SKINCOLOR_COPPER, + SKINCOLOR_QUARRY, SKINCOLOR_YELLOW, SKINCOLOR_MUSTARD, + SKINCOLOR_CROCODILE, SKINCOLOR_OLIVE, SKINCOLOR_VOMIT, SKINCOLOR_GARDEN, @@ -311,6 +319,7 @@ typedef enum SKINCOLOR_PLAGUE, SKINCOLOR_ALGAE, SKINCOLOR_CARIBBEAN, + SKINCOLOR_AZURE, SKINCOLOR_AQUA, SKINCOLOR_TEAL, SKINCOLOR_CYAN, @@ -320,7 +329,9 @@ typedef enum SKINCOLOR_PLATINUM, SKINCOLOR_SLATE, SKINCOLOR_STEEL, + SKINCOLOR_THUNDER, SKINCOLOR_RUST, + SKINCOLOR_WRISTWATCH, SKINCOLOR_JET, SKINCOLOR_SAPPHIRE, // sweet mother, i cannot weave - slender aphrodite has overcome me with longing for a girl SKINCOLOR_PERIWINKLE, diff --git a/src/hu_stuff.c b/src/hu_stuff.c index b43570735..cb9499c6d 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -793,14 +793,17 @@ static void Got_Saycmd(UINT8 **p, INT32 playernum) case SKINCOLOR_GREY: case SKINCOLOR_NICKEL: case SKINCOLOR_BLACK: + case SKINCOLOR_SKUNK: case SKINCOLOR_JET: cstart = "\x86"; // V_GRAYMAP break; case SKINCOLOR_SEPIA: case SKINCOLOR_BEIGE: + case SKINCOLOR_WALNUT: case SKINCOLOR_BROWN: case SKINCOLOR_LEATHER: case SKINCOLOR_RUST: + case SKINCOLOR_WRISTWATCH: cstart = "\x8e"; // V_BROWNMAP break; case SKINCOLOR_FAIRY: @@ -808,10 +811,12 @@ static void Got_Saycmd(UINT8 **p, INT32 playernum) case SKINCOLOR_PINK: case SKINCOLOR_ROSE: case SKINCOLOR_BRICK: + case SKINCOLOR_LEMONADE: case SKINCOLOR_BUBBLEGUM: case SKINCOLOR_LILAC: cstart = "\x8d"; // V_PINKMAP break; + case SKINCOLOR_CINNAMON: case SKINCOLOR_RUBY: case SKINCOLOR_RASPBERRY: case SKINCOLOR_CHERRY: @@ -842,14 +847,18 @@ static void Got_Saycmd(UINT8 **p, INT32 playernum) case SKINCOLOR_ROYAL: case SKINCOLOR_BRONZE: case SKINCOLOR_COPPER: + case SKINCOLOR_THUNDER: cstart = "\x8A"; // V_GOLDMAP break; case SKINCOLOR_POPCORN: + case SKINCOLOR_QUARRY: case SKINCOLOR_YELLOW: case SKINCOLOR_MUSTARD: + case SKINCOLOR_CROCODILE: case SKINCOLOR_OLIVE: cstart = "\x82"; // V_YELLOWMAP break; + case SKINCOLOR_ARTICHOKE: case SKINCOLOR_VOMIT: case SKINCOLOR_GARDEN: case SKINCOLOR_TEA: @@ -872,6 +881,7 @@ static void Got_Saycmd(UINT8 **p, INT32 playernum) cstart = "\x83"; // V_GREENMAP break; case SKINCOLOR_CARIBBEAN: + case SKINCOLOR_AZURE: case SKINCOLOR_AQUA: case SKINCOLOR_TEAL: case SKINCOLOR_CYAN: @@ -881,6 +891,7 @@ static void Got_Saycmd(UINT8 **p, INT32 playernum) case SKINCOLOR_SAPPHIRE: cstart = "\x88"; // V_SKYMAP break; + case SKINCOLOR_PIGEON: case SKINCOLOR_PLATINUM: case SKINCOLOR_STEEL: cstart = "\x8c"; // V_STEELMAP diff --git a/src/k_kart.c b/src/k_kart.c index 79cfe8763..df65a7c9e 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -49,22 +49,28 @@ const char *KartColor_Names[MAXSKINCOLORS] = "Grey", // SKINCOLOR_GREY "Nickel", // SKINCOLOR_NICKEL "Black", // SKINCOLOR_BLACK + "Skunk", // SKINCOLOR_SKUNK "Fairy", // SKINCOLOR_FAIRY "Popcorn", // SKINCOLOR_POPCORN + "Artichoke", // SKINCOLOR_ARTICHOKE + "Pigeon", // SKINCOLOR_PIGEON "Sepia", // SKINCOLOR_SEPIA "Beige", // SKINCOLOR_BEIGE + "Walnut", // SKINCOLOR_WALNUT "Brown", // SKINCOLOR_BROWN "Leather", // SKINCOLOR_LEATHER "Salmon", // SKINCOLOR_SALMON "Pink", // SKINCOLOR_PINK "Rose", // SKINCOLOR_ROSE "Brick", // SKINCOLOR_BRICK + "Cinnamon", // SKINCOLOR_CINNAMON "Ruby", // SKINCOLOR_RUBY "Raspberry", // SKINCOLOR_RASPBERRY "Cherry", // SKINCOLOR_CHERRY "Red", // SKINCOLOR_RED "Crimson", // SKINCOLOR_CRIMSON "Maroon", // SKINCOLOR_MAROON + "Lemonade", // SKINCOLOR_LEMONADE "Flame", // SKINCOLOR_FLAME "Scarlet", // SKINCOLOR_SCARLET "Ketchup", // SKINCOLOR_KETCHUP @@ -83,8 +89,10 @@ const char *KartColor_Names[MAXSKINCOLORS] = "Royal", // SKINCOLOR_ROYAL "Bronze", // SKINCOLOR_BRONZE "Copper", // SKINCOLOR_COPPER + "Quarry", // SKINCOLOR_QUARRY "Yellow", // SKINCOLOR_YELLOW "Mustard", // SKINCOLOR_MUSTARD + "Crocodile", // SKINCOLOR_CROCODILE "Olive", // SKINCOLOR_OLIVE "Vomit", // SKINCOLOR_VOMIT "Garden", // SKINCOLOR_GARDEN @@ -104,6 +112,7 @@ const char *KartColor_Names[MAXSKINCOLORS] = "Plague", // SKINCOLOR_PLAGUE "Algae", // SKINCOLOR_ALGAE "Caribbean", // SKINCOLOR_CARIBBEAN + "Azure", // SKINCOLOR_AZURE "Aqua", // SKINCOLOR_AQUA "Teal", // SKINCOLOR_TEAL "Cyan", // SKINCOLOR_CYAN @@ -113,7 +122,9 @@ const char *KartColor_Names[MAXSKINCOLORS] = "Platinum", // SKINCOLOR_PLATINUM "Slate", // SKINCOLOR_SLATE "Steel", // SKINCOLOR_STEEL + "Thunder", // SKINCOLOR_THUNDER "Rust", // SKINCOLOR_RUST + "Wristwatch", // SKINCOLOR_WRISTWATCH "Jet", // SKINCOLOR_JET "Sapphire", // SKINCOLOR_SAPPHIRE "Periwinkle", // SKINCOLOR_PERIWINKLE @@ -144,22 +155,28 @@ const UINT8 KartColor_Opposite[MAXSKINCOLORS*2] = SKINCOLOR_GREY,8, // SKINCOLOR_GREY SKINCOLOR_SILVER,8, // SKINCOLOR_NICKEL SKINCOLOR_WHITE,8, // SKINCOLOR_BLACK - SKINCOLOR_CAMOUFLAGE,8, // SKINCOLOR_FAIRY - SKINCOLOR_BUBBLEGUM,8, // SKINCOLOR_POPCORN + SKINCOLOR_SKUNK,8, // SKINCOLOR_SKUNK + SKINCOLOR_ARTICHOKE,12, // SKINCOLOR_FAIRY + SKINCOLOR_PIGEON,12, // SKINCOLOR_POPCORN + SKINCOLOR_FAIRY,12, // SKINCOLOR_ARTICHOKE + SKINCOLOR_POPCORN,12, // SKINCOLOR_PIGEON SKINCOLOR_LEATHER,6, // SKINCOLOR_SEPIA SKINCOLOR_BROWN,2, // SKINCOLOR_BEIGE + SKINCOLOR_CAMOUFLAGE,8, // SKINCOLOR_WALNUT SKINCOLOR_BEIGE,8, // SKINCOLOR_BROWN SKINCOLOR_SEPIA,8, // SKINCOLOR_LEATHER SKINCOLOR_TEA,8, // SKINCOLOR_SALMON SKINCOLOR_PISTACHIO,8, // SKINCOLOR_PINK SKINCOLOR_MOSS,8, // SKINCOLOR_ROSE SKINCOLOR_RUST,8, // SKINCOLOR_BRICK + SKINCOLOR_WRISTWATCH,6, // SKINCOLOR_CINNAMON SKINCOLOR_SAPPHIRE,8, // SKINCOLOR_RUBY SKINCOLOR_MINT,8, // SKINCOLOR_RASPBERRY SKINCOLOR_HANDHELD,10, // SKINCOLOR_CHERRY SKINCOLOR_GREEN,6, // SKINCOLOR_RED SKINCOLOR_PINETREE,6, // SKINCOLOR_CRIMSON SKINCOLOR_TOXIC,8, // SKINCOLOR_MAROON + SKINCOLOR_THUNDER,8, // SKINCOLOR_LEMONADE SKINCOLOR_CARIBBEAN,10, // SKINCOLOR_FLAME SKINCOLOR_ALGAE,10, // SKINCOLOR_SCARLET SKINCOLOR_MUSTARD,10, // SKINCOLOR_KETCHUP @@ -178,8 +195,10 @@ const UINT8 KartColor_Opposite[MAXSKINCOLORS*2] = SKINCOLOR_PLATINUM,6, // SKINCOLOR_ROYAL SKINCOLOR_STEEL,8, // SKINCOLOR_BRONZE SKINCOLOR_CREAM,6, // SKINCOLOR_COPPER + SKINCOLOR_AZURE,8, // SKINCOLOR_QUARRY SKINCOLOR_AQUA,8, // SKINCOLOR_YELLOW SKINCOLOR_KETCHUP,8, // SKINCOLOR_MUSTARD + SKINCOLOR_BUBBLEGUM,8, // SKINCOLOR_CROCODILE SKINCOLOR_TEAL,8, // SKINCOLOR_OLIVE SKINCOLOR_ROBOHOOD,8, // SKINCOLOR_VOMIT SKINCOLOR_LAVENDER,6, // SKINCOLOR_GARDEN @@ -188,7 +207,7 @@ const UINT8 KartColor_Opposite[MAXSKINCOLORS*2] = SKINCOLOR_SALMON,8, // SKINCOLOR_TEA SKINCOLOR_PINK,6, // SKINCOLOR_PISTACHIO SKINCOLOR_ROSE,8, // SKINCOLOR_MOSS - SKINCOLOR_FAIRY,10, // SKINCOLOR_CAMOUFLAGE + SKINCOLOR_WALNUT,8, // SKINCOLOR_CAMOUFLAGE SKINCOLOR_VOMIT,8, // SKINCOLOR_ROBOHOOD SKINCOLOR_RASPBERRY,8, // SKINCOLOR_MINT SKINCOLOR_RED,8, // SKINCOLOR_GREEN @@ -199,6 +218,7 @@ const UINT8 KartColor_Opposite[MAXSKINCOLORS*2] = SKINCOLOR_NOVA,8, // SKINCOLOR_PLAGUE SKINCOLOR_SCARLET,10, // SKINCOLOR_ALGAE SKINCOLOR_FLAME,8, // SKINCOLOR_CARIBBEAN + SKINCOLOR_QUARRY,8, // SKINCOLOR_AZURE SKINCOLOR_YELLOW,8, // SKINCOLOR_AQUA SKINCOLOR_OLIVE,8, // SKINCOLOR_TEAL SKINCOLOR_PEACH,8, // SKINCOLOR_CYAN @@ -208,7 +228,9 @@ const UINT8 KartColor_Opposite[MAXSKINCOLORS*2] = SKINCOLOR_ROYAL,8, // SKINCOLOR_PLATINUM SKINCOLOR_GOLD,10, // SKINCOLOR_SLATE SKINCOLOR_BRONZE,10, // SKINCOLOR_STEEL + SKINCOLOR_LEMONADE,8, // SKINCOLOR_THUNDER SKINCOLOR_BRICK,10, // SKINCOLOR_RUST + SKINCOLOR_CINNAMON,8, // SKINCOLOR_WRISTWATCH SKINCOLOR_BURGUNDY,8, // SKINCOLOR_JET SKINCOLOR_RUBY,6, // SKINCOLOR_SAPPHIRE SKINCOLOR_CREAMSICLE,8, // SKINCOLOR_PERIWINKLE @@ -219,7 +241,7 @@ const UINT8 KartColor_Opposite[MAXSKINCOLORS*2] = SKINCOLOR_SUNSET,10, // SKINCOLOR_MOONSLAM SKINCOLOR_MAUVE,10, // SKINCOLOR_ULTRAVIOLET SKINCOLOR_DAWN,6, // SKINCOLOR_DUSK - SKINCOLOR_POPCORN,12, // SKINCOLOR_BUBBLEGUM + SKINCOLOR_CROCODILE,8, // SKINCOLOR_BUBBLEGUM SKINCOLOR_EMERALD,8, // SKINCOLOR_PURPLE SKINCOLOR_PASTEL,11, // SKINCOLOR_FUCHSIA SKINCOLOR_MAROON,8, // SKINCOLOR_TOXIC @@ -237,27 +259,33 @@ UINT8 colortranslations[MAXTRANSLATIONS][16] = { { 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31}, // SKINCOLOR_GREY { 3, 5, 8, 11, 15, 17, 19, 21, 23, 24, 25, 26, 27, 29, 30, 31}, // SKINCOLOR_NICKEL { 4, 7, 11, 15, 20, 22, 24, 27, 28, 28, 28, 29, 29, 30, 30, 31}, // SKINCOLOR_BLACK + {120, 120, 0, 2, 4, 10, 16, 22, 23, 24, 25, 26, 27, 28, 29, 31}, // SKINCOLOR_SKUNK {120, 120, 121, 121, 122, 123, 10, 14, 16, 18, 20, 22, 24, 26, 28, 31}, // SKINCOLOR_FAIRY {120, 96, 97, 98, 99, 71, 32, 11, 13, 16, 18, 21, 23, 26, 28, 31}, // SKINCOLOR_POPCORN + { 97, 176, 177, 162, 163, 179, 12, 14, 16, 18, 20, 22, 24, 26, 28, 31}, // SKINCOLOR_ARTICHOKE + { 0, 208, 209, 211, 226, 202, 14, 15, 17, 19, 21, 23, 25, 27, 29, 31}, // SKINCOLOR_PIGEON { 0, 1, 3, 5, 7, 9, 34, 36, 38, 40, 42, 44, 60, 61, 62, 63}, // SKINCOLOR_SEPIA {120, 65, 67, 69, 32, 34, 36, 38, 40, 42, 44, 45, 46, 47, 62, 63}, // SKINCOLOR_BEIGE + { 3, 6, 32, 33, 35, 37, 51, 52, 54, 55, 57, 58, 60, 61, 63, 30}, // SKINCOLOR_WALNUT { 67, 70, 73, 76, 48, 49, 51, 53, 54, 56, 58, 59, 61, 63, 29, 30}, // SKINCOLOR_BROWN { 72, 76, 48, 51, 53, 55, 57, 59, 61, 63, 28, 28, 29, 29, 30, 31}, // SKINCOLOR_LEATHER {120, 120, 120, 121, 121, 122, 123, 124, 126, 127, 129, 131, 133, 135, 137, 139}, // SKINCOLOR_SALMON {120, 121, 121, 122, 144, 145, 146, 147, 148, 149, 150, 151, 134, 136, 138, 140}, // SKINCOLOR_PINK {144, 145, 146, 147, 148, 149, 150, 151, 134, 135, 136, 137, 138, 139, 140, 141}, // SKINCOLOR_ROSE { 64, 67, 70, 73, 146, 147, 148, 150, 118, 118, 119, 119, 156, 159, 141, 143}, // SKINCOLOR_BRICK + { 68, 75, 48, 50, 52, 94, 152, 136, 137, 138, 139, 140, 141, 142, 143, 31}, // SKINCOLOR_CINNAMON {120, 121, 144, 145, 147, 149, 132, 133, 134, 136, 198, 198, 199, 255, 30, 31}, // SKINCOLOR_RUBY {120, 121, 122, 123, 124, 125, 126, 127, 128, 130, 131, 134, 136, 137, 139, 140}, // SKINCOLOR_RASPBERRY {120, 65, 67, 69, 71, 124, 125, 127, 132, 133, 135, 136, 138, 139, 140, 141}, // SKINCOLOR_CHERRY {122, 123, 124, 126, 129, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142}, // SKINCOLOR_RED {123, 125, 128, 131, 133, 135, 136, 138, 140, 140, 141, 141, 142, 142, 143, 31}, // SKINCOLOR_CRIMSON {123, 124, 126, 128, 132, 135, 137, 27, 28, 28, 28, 29, 29, 30, 30, 31}, // SKINCOLOR_MAROON + {120, 96, 97, 98, 99, 65, 122, 144, 123, 124, 147, 149, 151, 153, 156, 159}, // SKINCOLOR_LEMONADE {120, 97, 112, 113, 113, 85, 87, 126, 149, 150, 151, 252, 253, 254, 255, 29}, // SKINCOLOR_FLAME { 99, 113, 113, 84, 85, 87, 126, 128, 130, 196, 197, 198, 199, 240, 243, 246}, // SKINCOLOR_SCARLET {103, 113, 113, 84, 85, 88, 127, 130, 131, 133, 134, 136, 138, 139, 141, 143}, // SKINCOLOR_KETCHUP - {120, 121, 122, 123, 124, 147, 147, 148, 90, 91, 92, 93, 94, 95, 152, 154}, // SKINCOLOR_DAWN - { 98, 112, 113, 84, 85, 87, 89, 149, 150, 251, 252, 206, 238, 240, 243, 246}, // SKINCOLOR_SUNSET + {120, 121, 122, 123, 124, 147, 148, 91, 93, 95, 152, 154, 156, 159, 141, 143}, // SKINCOLOR_DAWN + { 98, 112, 113, 84, 85, 87, 89, 149, 150, 251, 251, 205, 206, 207, 29, 31}, // SKINCOLOR_SUNSET {120, 120, 80, 80, 81, 82, 83, 83, 84, 85, 86, 88, 89, 91, 93, 95}, // SKINCOLOR_CREAMSICLE { 80, 81, 82, 83, 84, 85, 86, 88, 89, 91, 94, 95, 154, 156, 158, 159}, // SKINCOLOR_ORANGE { 82, 83, 84, 85, 87, 89, 90, 92, 94, 152, 153, 155, 157, 159, 141, 142}, // SKINCOLOR_PUMPKIN @@ -266,17 +294,19 @@ UINT8 colortranslations[MAXTRANSLATIONS][16] = { { 98, 98, 112, 112, 113, 113, 84, 85, 87, 89, 91, 93, 95, 153, 156, 159}, // SKINCOLOR_TANGERINE {120, 80, 66, 70, 72, 76, 148, 149, 150, 151, 153, 154, 156, 61, 62, 63}, // SKINCOLOR_PEACH { 64, 66, 68, 70, 72, 74, 76, 78, 48, 50, 52, 54, 56, 58, 60, 62}, // SKINCOLOR_CARAMEL - {120, 120, 96, 96, 97, 82, 84, 77, 50, 54, 57, 59, 61, 63, 29, 31}, // SKINCOLOR_CREAM - {112, 112, 112, 113, 113, 114, 114, 115, 115, 116, 116, 117, 117, 118, 118, 119}, // SKINCOLOR_GOLD + {120, 96, 96, 97, 98, 82, 84, 77, 50, 54, 57, 59, 61, 63, 29, 31}, // SKINCOLOR_CREAM + { 96, 97, 98, 112, 113, 114, 115, 116, 117, 151, 118, 119, 157, 159, 140, 143}, // SKINCOLOR_GOLD { 97, 112, 113, 113, 114, 78, 53, 252, 252, 253, 253, 254, 255, 29, 30, 31}, // SKINCOLOR_ROYAL {112, 113, 114, 115, 116, 117, 118, 119, 156, 157, 158, 159, 141, 141, 142, 143}, // SKINCOLOR_BRONZE {120, 99, 113, 114, 116, 117, 119, 61, 63, 28, 28, 29, 29, 30, 30, 31}, // SKINCOLOR_COPPER + { 96, 97, 98, 99, 104, 105, 106, 107, 117, 152, 154, 156, 159, 141, 142, 143}, // SKINCOLOR_QUARRY { 96, 97, 98, 100, 101, 102, 104, 113, 114, 115, 116, 117, 118, 119, 156, 159}, // SKINCOLOR_YELLOW { 96, 98, 99, 112, 113, 114, 114, 106, 106, 107, 107, 108, 108, 109, 110, 111}, // SKINCOLOR_MUSTARD - {105, 105, 105, 106, 106, 107, 107, 108, 108, 109, 109, 110, 110, 111, 111, 31}, // SKINCOLOR_OLIVE - {121, 144, 145, 72, 73, 84, 114, 115, 107, 108, 109, 183, 223, 207, 30, 246}, // SKINCOLOR_VOMIT + {120, 96, 97, 98, 176, 113, 114, 106, 115, 107, 108, 109, 110, 174, 175, 31}, // SKINCOLOR_CROCODILE + { 98, 101, 104, 105, 106, 115, 107, 108, 182, 109, 183, 110, 174, 111, 30, 31}, // SKINCOLOR_OLIVE + { 0, 121, 122, 144, 71, 84, 114, 115, 107, 108, 109, 183, 223, 207, 30, 246}, // SKINCOLOR_VOMIT { 98, 99, 112, 101, 113, 114, 106, 179, 180, 180, 181, 182, 183, 173, 174, 175}, // SKINCOLOR_GARDEN - { 96, 97, 99, 100, 102, 104, 160, 162, 164, 166, 168, 171, 223, 223, 207, 31}, // SKINCOLOR_LIME + {120, 96, 97, 98, 99, 176, 177, 163, 164, 166, 168, 170, 223, 207, 243, 31}, // SKINCOLOR_LIME { 98, 104, 105, 105, 106, 167, 168, 169, 170, 171, 172, 173, 174, 175, 30, 31}, // SKINCOLOR_HANDHELD {120, 120, 176, 176, 176, 177, 177, 178, 178, 179, 179, 180, 180, 181, 182, 183}, // SKINCOLOR_TEA {120, 120, 176, 176, 177, 177, 178, 179, 165, 166, 167, 168, 169, 170, 171, 172}, // SKINCOLOR_PISTACHIO @@ -289,9 +319,10 @@ UINT8 colortranslations[MAXTRANSLATIONS][16] = { {160, 184, 184, 185, 185, 186, 186, 187, 187, 188, 188, 189, 189, 190, 191, 175}, // SKINCOLOR_EMERALD {160, 184, 185, 186, 187, 188, 189, 190, 191, 191, 29, 29, 30, 30, 31, 31}, // SKINCOLOR_SWAMP {120, 120, 80, 80, 81, 177, 162, 164, 228, 228, 204, 204, 205, 205, 206, 207}, // SKINCOLOR_DREAM - {176, 160, 184, 185, 186, 187, 188, 230, 230, 206, 206, 207, 28, 29, 30, 31}, // SKINCOLOR_PLAGUE + { 97, 176, 160, 184, 185, 186, 187, 229, 229, 205, 206, 207, 28, 29, 30, 31}, // SKINCOLOR_PLAGUE {208, 209, 210, 211, 213, 220, 216, 167, 168, 188, 188, 189, 190, 191, 30, 31}, // SKINCOLOR_ALGAE - {120, 176, 177, 160, 185, 220, 216, 217, 221, 230, 206, 206, 254, 255, 29, 31}, // SKINCOLOR_CARIBBEAN + {120, 176, 177, 160, 185, 220, 216, 217, 229, 229, 204, 205, 206, 254, 255, 31}, // SKINCOLOR_CARIBBEAN + {120, 96, 97, 98, 177, 220, 216, 217, 218, 204, 252, 253, 254, 255, 30, 31}, // SKINCOLOR_AZURE {120, 208, 208, 210, 212, 214, 220, 220, 220, 221, 221, 222, 222, 223, 223, 191}, // SKINCOLOR_AQUA {210, 213, 220, 220, 220, 216, 216, 221, 221, 221, 222, 222, 223, 223, 191, 31}, // SKINCOLOR_TEAL {120, 120, 208, 208, 209, 210, 211, 212, 213, 215, 216, 217, 218, 219, 222, 223}, // SKINCOLOR_CYAN @@ -301,7 +332,9 @@ UINT8 colortranslations[MAXTRANSLATIONS][16] = { {120, 0, 0, 200, 200, 201, 11, 14, 17, 218, 222, 223, 238, 240, 243, 246}, // SKINCOLOR_PLATINUM {120, 120, 200, 200, 200, 201, 201, 201, 202, 202, 202, 203, 204, 205, 206, 207}, // SKINCOLOR_SLATE {120, 200, 200, 201, 201, 202, 202, 203, 203, 204, 204, 205, 205, 206, 207, 31}, // SKINCOLOR_STEEL + { 96, 97, 98, 112, 113, 114, 11, 203, 204, 205, 205, 237, 239, 241, 243, 246}, // SKINCOLOR_THUNDER { 64, 66, 68, 70, 32, 34, 36, 203, 204, 205, 24, 25, 26, 28, 29, 31}, // SKINCOLOR_RUST + { 81, 72, 76, 48, 51, 55, 252, 205, 205, 206, 240, 241, 242, 243, 244, 246}, // SKINCOLOR_WRISTWATCH {225, 226, 227, 228, 229, 205, 205, 206, 207, 207, 28, 28, 29, 29, 30, 31}, // SKINCOLOR_JET {208, 209, 211, 213, 215, 217, 229, 230, 232, 234, 236, 238, 240, 242, 244, 246}, // SKINCOLOR_SAPPHIRE {120, 120, 224, 225, 226, 202, 227, 228, 229, 230, 231, 233, 235, 237, 239, 241}, // SKINCOLOR_PERIWINKLE @@ -321,6 +354,7 @@ UINT8 colortranslations[MAXTRANSLATIONS][16] = { {144, 248, 249, 250, 251, 252, 253, 254, 255, 255, 29, 29, 30, 30, 31, 31}, // SKINCOLOR_BYZANTIUM {144, 145, 146, 147, 148, 149, 150, 251, 251, 252, 252, 253, 254, 255, 29, 30}, // SKINCOLOR_POMEGRANATE {120, 120, 120, 121, 121, 122, 122, 123, 192, 248, 249, 250, 251, 252, 253, 254}, // SKINCOLOR_LILAC + {120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 96, 100, 104, 113, 116, 119}, // SKINCOLOR_SUPER1 {120, 120, 120, 120, 120, 120, 120, 120, 96, 98, 101, 104, 113, 115, 117, 119}, // SKINCOLOR_SUPER2 {120, 120, 120, 120, 120, 120, 96, 98, 100, 102, 104, 113, 114, 116, 117, 119}, // SKINCOLOR_SUPER3 From 359d06f1b4d4f969f367718c16457a5d6fd0c8cd Mon Sep 17 00:00:00 2001 From: TehRealSalt Date: Fri, 26 Apr 2019 22:32:31 -0400 Subject: [PATCH 53/66] Modify the first shade of Byzantium --- src/k_kart.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/k_kart.c b/src/k_kart.c index df65a7c9e..5eeb9a1be 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -351,7 +351,7 @@ UINT8 colortranslations[MAXTRANSLATIONS][16] = { {120, 120, 176, 176, 177, 6, 8, 10, 249, 250, 196, 197, 198, 199, 143, 31}, // SKINCOLOR_TOXIC { 96, 97, 98, 112, 113, 73, 146, 248, 249, 251, 205, 205, 206, 207, 29, 31}, // SKINCOLOR_MAUVE {121, 145, 192, 248, 249, 250, 251, 252, 252, 253, 253, 254, 254, 255, 30, 31}, // SKINCOLOR_LAVENDER - {144, 248, 249, 250, 251, 252, 253, 254, 255, 255, 29, 29, 30, 30, 31, 31}, // SKINCOLOR_BYZANTIUM + {201, 248, 249, 250, 251, 252, 253, 254, 255, 255, 29, 29, 30, 30, 31, 31}, // SKINCOLOR_BYZANTIUM {144, 145, 146, 147, 148, 149, 150, 251, 251, 252, 252, 253, 254, 255, 29, 30}, // SKINCOLOR_POMEGRANATE {120, 120, 120, 121, 121, 122, 122, 123, 192, 248, 249, 250, 251, 252, 253, 254}, // SKINCOLOR_LILAC From fd251ed29f19470313dda1d5d1e9d0d9ba885cf5 Mon Sep 17 00:00:00 2001 From: James R Date: Sat, 27 Apr 2019 17:28:29 -0700 Subject: [PATCH 54/66] Move some cvars out of D_ClientServerInit and save them --- src/d_clisrv.c | 12 +++--------- src/d_netcmd.c | 8 ++++++++ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index f3b07d343..901879ec4 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -3199,15 +3199,15 @@ static void Got_KickCmd(UINT8 **p, INT32 playernum) static CV_PossibleValue_t netticbuffer_cons_t[] = {{0, "MIN"}, {3, "MAX"}, {0, NULL}}; consvar_t cv_netticbuffer = {"netticbuffer", "1", CV_SAVE, netticbuffer_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_allownewplayer = {"allowjoin", "On", CV_NETVAR, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL }; +consvar_t cv_allownewplayer = {"allowjoin", "On", CV_SAVE|CV_NETVAR, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL }; #ifdef VANILLAJOINNEXTROUND -consvar_t cv_joinnextround = {"joinnextround", "Off", CV_NETVAR, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; /// \todo not done +consvar_t cv_joinnextround = {"joinnextround", "Off", CV_SAVE|CV_NETVAR, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; /// \todo not done #endif static CV_PossibleValue_t maxplayers_cons_t[] = {{2, "MIN"}, {MAXPLAYERS, "MAX"}, {0, NULL}}; consvar_t cv_maxplayers = {"maxplayers", "8", CV_SAVE, maxplayers_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; static CV_PossibleValue_t resynchattempts_cons_t[] = {{0, "MIN"}, {20, "MAX"}, {0, NULL}}; consvar_t cv_resynchattempts = {"resynchattempts", "5", CV_SAVE, resynchattempts_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL }; -consvar_t cv_blamecfail = {"blamecfail", "Off", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL }; +consvar_t cv_blamecfail = {"blamecfail", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL }; // max file size to send to a player (in kilobytes) static CV_PossibleValue_t maxsend_cons_t[] = {{0, "MIN"}, {51200, "MAX"}, {0, NULL}}; @@ -3250,12 +3250,6 @@ void D_ClientServerInit(void) RegisterNetXCmd(XD_ADDPLAYER, Got_AddPlayer); RegisterNetXCmd(XD_REMOVEPLAYER, Got_RemovePlayer); #ifndef NONET - CV_RegisterVar(&cv_allownewplayer); -#ifdef VANILLAJOINNEXTROUND - CV_RegisterVar(&cv_joinnextround); -#endif - CV_RegisterVar(&cv_showjoinaddress); - CV_RegisterVar(&cv_blamecfail); #ifdef DUMPCONSISTENCY CV_RegisterVar(&cv_dumpconsistency); #endif diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 08bf33185..574c39d06 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -667,6 +667,14 @@ void D_RegisterServerCommands(void) CV_RegisterVar(&cv_maxsend); CV_RegisterVar(&cv_noticedownload); CV_RegisterVar(&cv_downloadspeed); +#ifndef NONET + CV_RegisterVar(&cv_allownewplayer); +#ifdef VANILLAJOINNEXTROUND + CV_RegisterVar(&cv_joinnextround); +#endif + CV_RegisterVar(&cv_showjoinaddress); + CV_RegisterVar(&cv_blamecfail); +#endif COM_AddCommand("ping", Command_Ping_f); CV_RegisterVar(&cv_nettimeout); From 9e24d4aba7c6a17479baf57813674b6251d6722c Mon Sep 17 00:00:00 2001 From: toaster Date: Sun, 28 Apr 2019 19:26:11 +0100 Subject: [PATCH 55/66] Completely untested -encore parameter for the map command; inverts cvar value. --- src/d_netcmd.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 08bf33185..bd0d6fb23 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -2204,12 +2204,14 @@ static void Command_Map_f(void) const char *mapname; size_t i; INT32 j, newmapnum; - boolean newresetplayers; + boolean newresetplayers, newencoremode; INT32 newgametype = gametype; - // max length of command: map map03 -gametype coop -noresetplayers -force - // 1 2 3 4 5 6 + // max length of command: map map03 -gametype race -noresetplayers -force -encore + // 1 2 3 4 5 6 7 // = 8 arg max + // i don't know whether this is intrinsic to the system or just someone being weird but + // "noresetplayers" is pretty useless for kart if it turns out this is too close to the limit if (COM_Argc() < 2 || COM_Argc() > 8) { CONS_Printf(M_GetText("map [-gametype [-force]: warp to map\n")); @@ -2292,6 +2294,21 @@ static void Command_Map_f(void) } } + // new encoremode value + // use cvar by default + + newencoremode = (boolean)cv_kartencore.value; + + if (COM_CheckParm("-encore")) + { + if (!M_SecretUnlocked(SECRET_ENCORE) && !newencoremode) + { + CONS_Alert(CONS_NOTICE, M_GetText("You haven't unlocked Encore Mode yet!\n")); + return; + } + newencoremode = !newencoremode; + } + if (!(i = COM_CheckParm("-force")) && newgametype == gametype) // SRB2Kart newresetplayers = false; // if not forcing and gametypes is the same @@ -2322,7 +2339,7 @@ static void Command_Map_f(void) } fromlevelselect = false; - D_MapChange(newmapnum, newgametype, (boolean)cv_kartencore.value, newresetplayers, 0, false, false); + D_MapChange(newmapnum, newgametype, newencoremode, newresetplayers, 0, false, false); } /** Receives a map command and changes the map. From 353a5b1b6199d4ace1db4bec3d69ec544090f092 Mon Sep 17 00:00:00 2001 From: Steel Titanium Date: Sun, 21 Apr 2019 17:34:59 -0400 Subject: [PATCH 56/66] New -port param --- src/i_tcp.c | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/src/i_tcp.c b/src/i_tcp.c index 11a84ceba..0e5da8ae1 100644 --- a/src/i_tcp.c +++ b/src/i_tcp.c @@ -813,6 +813,8 @@ static SOCKET_TYPE UDP_Bind(int family, struct sockaddr *addr, socklen_t addrlen #endif #endif mysockaddr_t straddr; + struct sockaddr_in sin; + socklen_t len = sizeof(sin); if (s == (SOCKET_TYPE)ERRSOCKET) return (SOCKET_TYPE)ERRSOCKET; @@ -906,12 +908,16 @@ static SOCKET_TYPE UDP_Bind(int family, struct sockaddr *addr, socklen_t addrlen CONS_Printf(M_GetText("Network system buffer set to: %dKb\n"), opt>>10); } + if (getsockname(s, (struct sockaddr *)&sin, &len) == -1) + CONS_Alert(CONS_WARNING, M_GetText("Failed to get port number\n")); + else + current_port = (UINT16)ntohs(sin.sin_port); + return s; } static boolean UDP_Socket(void) { - const char *sock_port = NULL; size_t s; struct my_addrinfo *ai, *runp, hints; int gaie; @@ -933,20 +939,11 @@ static boolean UDP_Socket(void) hints.ai_socktype = SOCK_DGRAM; hints.ai_protocol = IPPROTO_UDP; - if (M_CheckParm("-clientport")) - { - if (!M_IsNextParm()) - I_Error("syntax: -clientport "); - sock_port = M_GetNextParm(); - } - else - sock_port = port_name; - if (M_CheckParm("-bindaddr")) { while (M_IsNextParm()) { - gaie = I_getaddrinfo(M_GetNextParm(), sock_port, &hints, &ai); + gaie = I_getaddrinfo(M_GetNextParm(), port_name, &hints, &ai); if (gaie == 0) { runp = ai; @@ -967,7 +964,7 @@ static boolean UDP_Socket(void) } else { - gaie = I_getaddrinfo("0.0.0.0", sock_port, &hints, &ai); + gaie = I_getaddrinfo("0.0.0.0", port_name, &hints, &ai); if (gaie == 0) { runp = ai; @@ -982,8 +979,8 @@ static boolean UDP_Socket(void) #ifdef HAVE_MINIUPNPC if (UPNP_support) { - I_UPnP_rem(sock_port, "UDP"); - I_UPnP_add(NULL, sock_port, "UDP"); + I_UPnP_rem(port_name, "UDP"); + I_UPnP_add(NULL, port_name, "UDP"); } #endif } @@ -1000,7 +997,7 @@ static boolean UDP_Socket(void) { while (M_IsNextParm()) { - gaie = I_getaddrinfo(M_GetNextParm(), sock_port, &hints, &ai); + gaie = I_getaddrinfo(M_GetNextParm(), port_name, &hints, &ai); if (gaie == 0) { runp = ai; @@ -1021,7 +1018,7 @@ static boolean UDP_Socket(void) } else { - gaie = I_getaddrinfo("::", sock_port, &hints, &ai); + gaie = I_getaddrinfo("::", port_name, &hints, &ai); if (gaie == 0) { runp = ai; @@ -1478,14 +1475,15 @@ boolean I_InitTcpNetwork(void) if (!I_InitTcpDriver()) return false; - if (M_CheckParm("-udpport")) + if (M_CheckParm("-port")) + // Combined -udpport and -clientport into -port + // As it was really redundant having two seperate parms that does the same thing { if (M_IsNextParm()) strcpy(port_name, M_GetNextParm()); else strcpy(port_name, "0"); } - current_port = (UINT16)atoi(port_name); // parse network game options, if (M_CheckParm("-server") || dedicated) From db34bcbdbfaa09069180ee4b8d5965efcd7645cc Mon Sep 17 00:00:00 2001 From: Steel Titanium Date: Sun, 28 Apr 2019 22:02:25 -0400 Subject: [PATCH 57/66] Prettyify code. --- src/i_tcp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/i_tcp.c b/src/i_tcp.c index 0e5da8ae1..fb0e5852d 100644 --- a/src/i_tcp.c +++ b/src/i_tcp.c @@ -909,9 +909,9 @@ static SOCKET_TYPE UDP_Bind(int family, struct sockaddr *addr, socklen_t addrlen } if (getsockname(s, (struct sockaddr *)&sin, &len) == -1) - CONS_Alert(CONS_WARNING, M_GetText("Failed to get port number\n")); + CONS_Alert(CONS_WARNING, M_GetText("Failed to get port number\n")); else - current_port = (UINT16)ntohs(sin.sin_port); + current_port = (UINT16)ntohs(sin.sin_port); return s; } From 70566c808886eb5d0d9406c452ca2b2be3862f32 Mon Sep 17 00:00:00 2001 From: James R Date: Tue, 30 Apr 2019 13:03:13 -0700 Subject: [PATCH 58/66] Fix differing signedness compare --- src/mserv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mserv.c b/src/mserv.c index 5d10aa3ca..29aa99fae 100644 --- a/src/mserv.c +++ b/src/mserv.c @@ -693,7 +693,7 @@ static INT32 AddToMasterServer(boolean firstadd) UINT32 signature, tmp; const char *insname; - if (socket_fd == ERRSOCKET)/* Woah, our socket was closed! */ + if (socket_fd == (SOCKET_TYPE)ERRSOCKET)/* Woah, our socket was closed! */ { if (MS_Connect(GetMasterServerIP(), GetMasterServerPort(), 0)) return ConnectionFailedwerrno(errno); From 3a707c093b9b587a9153fd4bf0ef496203fe626d Mon Sep 17 00:00:00 2001 From: TehRealSalt Date: Wed, 1 May 2019 23:30:53 -0400 Subject: [PATCH 59/66] Add options for adjusting deadzone, increase default deadzone from 0.25 to 0.5 --- src/d_netcmd.c | 4 ++++ src/g_game.c | 16 +++++++++++----- src/g_game.h | 8 ++++---- src/m_menu.c | 2 +- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index b605c9541..21e83d59b 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -864,6 +864,10 @@ void D_RegisterClientCommands(void) CV_RegisterVar(&cv_driftaxis2); CV_RegisterVar(&cv_driftaxis3); CV_RegisterVar(&cv_driftaxis4); + CV_RegisterVar(&cv_deadzone); + CV_RegisterVar(&cv_deadzone2); + CV_RegisterVar(&cv_deadzone3); + CV_RegisterVar(&cv_deadzone4); // filesrch.c CV_RegisterVar(&cv_addons_option); diff --git a/src/g_game.c b/src/g_game.c index ad25c8ce9..229cf3d47 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -406,6 +406,8 @@ static CV_PossibleValue_t joyaxis_cons_t[] = {{0, "None"}, #endif #endif +static CV_PossibleValue_t deadzone_cons_t[] = {{0, "MIN"}, {FRACUNIT, "MAX"}, {0, NULL}}; + // don't mind me putting these here, I was lazy to figure out where else I could put those without blowing up the compiler. // it automatically becomes compact with 20+ players, but if you like it, I guess you can turn that on! @@ -476,6 +478,7 @@ consvar_t cv_aimaxis = {"joyaxis_aim", "Y-Axis", CV_SAVE, joyaxis_cons_t, NULL, consvar_t cv_lookaxis = {"joyaxis_look", "None", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_fireaxis = {"joyaxis_fire", "Z-Axis", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_driftaxis = {"joyaxis_drift", "Z-Rudder", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_deadzone = {"joy_deadzone", "0.5", CV_FLOAT|CV_SAVE, deadzone_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_turnaxis2 = {"joyaxis2_turn", "X-Axis", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_moveaxis2 = {"joyaxis2_move", "None", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -484,6 +487,7 @@ consvar_t cv_aimaxis2 = {"joyaxis2_aim", "Y-Axis", CV_SAVE, joyaxis_cons_t, NULL consvar_t cv_lookaxis2 = {"joyaxis2_look", "None", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_fireaxis2 = {"joyaxis2_fire", "Z-Axis", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_driftaxis2 = {"joyaxis2_drift", "Z-Rudder", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_deadzone2 = {"joy2_deadzone", "0.5", CV_FLOAT|CV_SAVE, deadzone_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_turnaxis3 = {"joyaxis3_turn", "X-Axis", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_moveaxis3 = {"joyaxis3_move", "None", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -492,6 +496,7 @@ consvar_t cv_aimaxis3 = {"joyaxis3_aim", "Y-Axis", CV_SAVE, joyaxis_cons_t, NULL consvar_t cv_lookaxis3 = {"joyaxis3_look", "None", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_fireaxis3 = {"joyaxis3_fire", "Z-Axis", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_driftaxis3 = {"joyaxis3_drift", "Z-Rudder", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_deadzone3 = {"joy3_deadzone", "0.5", CV_FLOAT|CV_SAVE, deadzone_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_turnaxis4 = {"joyaxis4_turn", "X-Axis", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_moveaxis4 = {"joyaxis4_move", "None", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -500,6 +505,7 @@ consvar_t cv_aimaxis4 = {"joyaxis4_aim", "Y-Axis", CV_SAVE, joyaxis_cons_t, NULL consvar_t cv_lookaxis4 = {"joyaxis4_look", "None", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_fireaxis4 = {"joyaxis4_fire", "Z-Axis", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_driftaxis4 = {"joyaxis4_drift", "Z-Rudder", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_deadzone4 = {"joy4_deadzone", "0.5", CV_FLOAT|CV_SAVE, deadzone_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; #if MAXPLAYERS > 16 @@ -925,8 +931,8 @@ static INT32 Joy1Axis(axis_input_e axissel) retaxis = +JOYAXISRANGE; if (!Joystick.bGamepadStyle && axissel < AXISDEAD) { - const INT32 jdeadzone = JOYAXISRANGE/4; - if (-jdeadzone < retaxis && retaxis < jdeadzone) + const INT32 jdeadzone = ((JOYAXISRANGE-1) * cv_deadzone.value) >> FRACBITS; + if (abs(retaxis) <= jdeadzone) return 0; } if (flp) retaxis = -retaxis; //flip it around @@ -1006,7 +1012,7 @@ static INT32 Joy2Axis(axis_input_e axissel) retaxis = +JOYAXISRANGE; if (!Joystick2.bGamepadStyle && axissel < AXISDEAD) { - const INT32 jdeadzone = JOYAXISRANGE/4; + const INT32 jdeadzone = ((JOYAXISRANGE-1) * cv_deadzone2.value) >> FRACBITS; if (-jdeadzone < retaxis && retaxis < jdeadzone) return 0; } @@ -1087,7 +1093,7 @@ static INT32 Joy3Axis(axis_input_e axissel) retaxis = +JOYAXISRANGE; if (!Joystick3.bGamepadStyle && axissel < AXISDEAD) { - const INT32 jdeadzone = JOYAXISRANGE/4; + const INT32 jdeadzone = jdeadzone = ((JOYAXISRANGE-1) * cv_deadzone3.value) >> FRACBITS; if (-jdeadzone < retaxis && retaxis < jdeadzone) return 0; } @@ -1167,7 +1173,7 @@ static INT32 Joy4Axis(axis_input_e axissel) retaxis = +JOYAXISRANGE; if (!Joystick4.bGamepadStyle && axissel < AXISDEAD) { - const INT32 jdeadzone = JOYAXISRANGE/4; + const INT32 jdeadzone = jdeadzone = ((JOYAXISRANGE-1) * cv_deadzone4.value) >> FRACBITS; if (-jdeadzone < retaxis && retaxis < jdeadzone) return 0; } diff --git a/src/g_game.h b/src/g_game.h index eea149c98..9681491b7 100644 --- a/src/g_game.h +++ b/src/g_game.h @@ -62,10 +62,10 @@ extern consvar_t cv_invertmouse/*, cv_alwaysfreelook, cv_chasefreelook, cv_mouse extern consvar_t cv_invertmouse2/*, cv_alwaysfreelook2, cv_chasefreelook2, cv_mousemove2*/; extern consvar_t cv_useranalog, cv_useranalog2, cv_useranalog3, cv_useranalog4; extern consvar_t cv_analog, cv_analog2, cv_analog3, cv_analog4; -extern consvar_t cv_turnaxis,cv_moveaxis,cv_brakeaxis,cv_aimaxis,cv_lookaxis,cv_fireaxis,cv_driftaxis; -extern consvar_t cv_turnaxis2,cv_moveaxis2,cv_brakeaxis2,cv_aimaxis2,cv_lookaxis2,cv_fireaxis2,cv_driftaxis2; -extern consvar_t cv_turnaxis3,cv_moveaxis3,cv_brakeaxis3,cv_aimaxis3,cv_lookaxis3,cv_fireaxis3,cv_driftaxis3; -extern consvar_t cv_turnaxis4,cv_moveaxis4,cv_brakeaxis4,cv_aimaxis4,cv_lookaxis4,cv_fireaxis4,cv_driftaxis4; +extern consvar_t cv_turnaxis,cv_moveaxis,cv_brakeaxis,cv_aimaxis,cv_lookaxis,cv_fireaxis,cv_driftaxis,cv_deadzone; +extern consvar_t cv_turnaxis2,cv_moveaxis2,cv_brakeaxis2,cv_aimaxis2,cv_lookaxis2,cv_fireaxis2,cv_driftaxis2,cv_deadzone2; +extern consvar_t cv_turnaxis3,cv_moveaxis3,cv_brakeaxis3,cv_aimaxis3,cv_lookaxis3,cv_fireaxis3,cv_driftaxis3,cv_deadzone3; +extern consvar_t cv_turnaxis4,cv_moveaxis4,cv_brakeaxis4,cv_aimaxis4,cv_lookaxis4,cv_fireaxis4,cv_driftaxis4,cv_deadzone4; extern consvar_t cv_ghost_besttime, cv_ghost_bestlap, cv_ghost_last, cv_ghost_guest, cv_ghost_staff; typedef enum diff --git a/src/m_menu.c b/src/m_menu.c index fefafff31..a5b21b768 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -2493,7 +2493,7 @@ boolean M_Responder(event_t *ev) { if (ev->type == ev_joystick && ev->data1 == 0 && joywait < I_GetTime()) { - const INT32 jdeadzone = JOYAXISRANGE/4; + const INT32 jdeadzone = ((JOYAXISRANGE-1) * cv_deadzone.value) >> FRACBITS; if (ev->data3 != INT32_MAX) { if (Joystick.bGamepadStyle || abs(ev->data3) > jdeadzone) From e59a7175be91c0cde11df8dd98a2dae08945e1a7 Mon Sep 17 00:00:00 2001 From: TehRealSalt Date: Thu, 2 May 2019 00:39:49 -0400 Subject: [PATCH 60/66] Fix skin shit --- src/b_bot.c | 8 +--- src/d_clisrv.c | 28 -------------- src/d_clisrv.h | 14 ------- src/d_player.h | 48 ----------------------- src/g_game.c | 94 ++++++--------------------------------------- src/lua_playerlib.c | 56 --------------------------- src/p_saveg.c | 28 -------------- src/p_user.c | 36 ++++++++--------- 8 files changed, 31 insertions(+), 281 deletions(-) diff --git a/src/b_bot.c b/src/b_bot.c index b84db288c..c16976b07 100644 --- a/src/b_bot.c +++ b/src/b_bot.c @@ -271,13 +271,7 @@ void B_RespawnBot(INT32 playernum) player->powers[pw_nocontrol] = sonic->player->powers[pw_nocontrol]; P_TeleportMove(tails, x, y, z); - if (player->charability == CA_FLY) - { - P_SetPlayerMobjState(tails, S_KART_STND1); // SRB2kart - was S_PLAY_ABL1 - tails->player->powers[pw_tailsfly] = (UINT16)-1; - } - else - P_SetPlayerMobjState(tails, S_KART_STND1); // SRB2kart - was S_PLAY_FALL1 + P_SetPlayerMobjState(tails, S_KART_STND1); // SRB2kart - was S_PLAY_FALL1 P_SetScale(tails, sonic->scale); tails->destscale = sonic->destscale; } diff --git a/src/d_clisrv.c b/src/d_clisrv.c index f3b07d343..d7a8e6528 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -585,21 +585,7 @@ static inline void resynch_write_player(resynch_pak *rsp, const size_t i) rsp->kartspeed = (UINT8)players[i].kartspeed; rsp->kartweight = (UINT8)players[i].kartweight; // - rsp->normalspeed = (fixed_t)LONG(players[i].normalspeed); - rsp->runspeed = (fixed_t)LONG(players[i].runspeed); - rsp->thrustfactor = players[i].thrustfactor; - rsp->accelstart = players[i].accelstart; - rsp->acceleration = players[i].acceleration; - rsp->charability = players[i].charability; - rsp->charability2 = players[i].charability2; rsp->charflags = (UINT32)LONG(players[i].charflags); - rsp->thokitem = (UINT32)LONG(players[i].thokitem); //mobjtype_t - rsp->spinitem = (UINT32)LONG(players[i].spinitem); //mobjtype_t - rsp->revitem = (UINT32)LONG(players[i].revitem); //mobjtype_t - rsp->actionspd = (fixed_t)LONG(players[i].actionspd); - rsp->mindash = (fixed_t)LONG(players[i].mindash); - rsp->maxdash = (fixed_t)LONG(players[i].maxdash); - rsp->jumpfactor = (fixed_t)LONG(players[i].jumpfactor); rsp->speed = (fixed_t)LONG(players[i].speed); rsp->jumping = players[i].jumping; @@ -722,21 +708,7 @@ static void resynch_read_player(resynch_pak *rsp) players[i].kartspeed = (UINT8)rsp->kartspeed; players[i].kartweight = (UINT8)rsp->kartweight; - players[i].normalspeed = (fixed_t)LONG(rsp->normalspeed); - players[i].runspeed = (fixed_t)LONG(rsp->runspeed); - players[i].thrustfactor = rsp->thrustfactor; - players[i].accelstart = rsp->accelstart; - players[i].acceleration = rsp->acceleration; - players[i].charability = rsp->charability; - players[i].charability2 = rsp->charability2; players[i].charflags = (UINT32)LONG(rsp->charflags); - players[i].thokitem = (UINT32)LONG(rsp->thokitem); //mobjtype_t - players[i].spinitem = (UINT32)LONG(rsp->spinitem); //mobjtype_t - players[i].revitem = (UINT32)LONG(rsp->revitem); //mobjtype_t - players[i].actionspd = (fixed_t)LONG(rsp->actionspd); - players[i].mindash = (fixed_t)LONG(rsp->mindash); - players[i].maxdash = (fixed_t)LONG(rsp->maxdash); - players[i].jumpfactor = (fixed_t)LONG(rsp->jumpfactor); players[i].speed = (fixed_t)LONG(rsp->speed); players[i].jumping = rsp->jumping; diff --git a/src/d_clisrv.h b/src/d_clisrv.h index f3a9011eb..8e431dbbf 100644 --- a/src/d_clisrv.h +++ b/src/d_clisrv.h @@ -224,21 +224,7 @@ typedef struct UINT8 kartspeed; UINT8 kartweight; // - fixed_t normalspeed; - fixed_t runspeed; - UINT8 thrustfactor; - UINT8 accelstart; - UINT8 acceleration; - UINT8 charability; - UINT8 charability2; UINT32 charflags; - UINT32 thokitem; // mobjtype_t - UINT32 spinitem; // mobjtype_t - UINT32 revitem; // mobjtype_t - fixed_t actionspd; - fixed_t mindash; - fixed_t maxdash; - fixed_t jumpfactor; fixed_t speed; UINT8 jumping; diff --git a/src/d_player.h b/src/d_player.h index decd96552..c6a7f0f34 100644 --- a/src/d_player.h +++ b/src/d_player.h @@ -35,33 +35,6 @@ typedef enum SF_HIRES = 1, // Draw the sprite 2x as small? } skinflags_t; -//Primary and secondary skin abilities -typedef enum -{ - CA_NONE=0, - CA_THOK, - CA_FLY, - CA_GLIDEANDCLIMB, - CA_HOMINGTHOK, - CA_SWIM, - CA_DOUBLEJUMP, - CA_FLOAT, - CA_SLOWFALL, - CA_TELEKINESIS, - CA_FALLSWITCH, - CA_JUMPBOOST, - CA_AIRDRILL, - CA_JUMPTHOK -} charability_t; - -//Secondary skin abilities -typedef enum -{ - CA2_NONE=0, - CA2_SPINDASH, - CA2_MULTIABILITY -} charability2_t; - // // Player states. // @@ -442,29 +415,8 @@ typedef struct player_s UINT8 kartweight; // Kart weight stat between 1 and 9 // - fixed_t normalspeed; // Normal ground - fixed_t runspeed; // Speed you break into the run animation - UINT8 thrustfactor; // Thrust = thrustfactor * acceleration - UINT8 accelstart; // Starting acceleration if speed = 0. - UINT8 acceleration; // Acceleration - - // See charability_t and charability2_t for more information. - UINT8 charability; // Ability definition - UINT8 charability2; // Secondary ability definition - UINT32 charflags; // Extra abilities/settings for skins (combinable stuff) // See SF_ flags - - mobjtype_t thokitem; // Object # to spawn for the thok - mobjtype_t spinitem; // Object # to spawn for spindash/spinning - mobjtype_t revitem; // Object # to spawn for spindash/spinning - - fixed_t actionspd; // Speed of thok/glide/fly - fixed_t mindash; // Minimum spindash speed - fixed_t maxdash; // Maximum spindash speed - - fixed_t jumpfactor; // How high can the player jump? - SINT8 lives; SINT8 continues; // continues that player has acquired diff --git a/src/g_game.c b/src/g_game.c index ad25c8ce9..260c88790 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -2325,25 +2325,12 @@ void G_PlayerReborn(INT32 player) INT32 score, marescore; INT32 lives; INT32 continues; - UINT8 charability; - UINT8 charability2; // SRB2kart UINT8 kartspeed; UINT8 kartweight; // - fixed_t normalspeed; - fixed_t runspeed; - UINT8 thrustfactor; - UINT8 accelstart; - UINT8 acceleration; INT32 charflags; INT32 pflags; - UINT32 thokitem; - UINT32 spinitem; - UINT32 revitem; - fixed_t actionspd; - fixed_t mindash; - fixed_t maxdash; INT32 ctfteam; INT32 starposttime; INT16 starpostx; @@ -2399,18 +2386,10 @@ void G_PlayerReborn(INT32 player) skincolor = players[player].skincolor; skin = players[player].skin; - charability = players[player].charability; - charability2 = players[player].charability2; // SRB2kart kartspeed = players[player].kartspeed; kartweight = players[player].kartweight; // - normalspeed = players[player].normalspeed; - runspeed = players[player].runspeed; - thrustfactor = players[player].thrustfactor; - accelstart = players[player].accelstart; - acceleration = players[player].acceleration; - charflags = players[player].charflags; starposttime = players[player].starposttime; starpostx = players[player].starpostx; @@ -2419,13 +2398,6 @@ void G_PlayerReborn(INT32 player) starpostnum = players[player].starpostnum; respawnflip = players[player].kartstuff[k_starpostflip]; //SRB2KART starpostangle = players[player].starpostangle; - jumpfactor = players[player].jumpfactor; - thokitem = players[player].thokitem; - spinitem = players[player].spinitem; - revitem = players[player].revitem; - actionspd = players[player].actionspd; - mindash = players[player].mindash; - maxdash = players[player].maxdash; mare = players[player].mare; bot = players[player].bot; @@ -2489,24 +2461,11 @@ void G_PlayerReborn(INT32 player) // save player config truth reborn p->skincolor = skincolor; p->skin = skin; - p->charability = charability; - p->charability2 = charability2; // SRB2kart p->kartspeed = kartspeed; p->kartweight = kartweight; // - p->normalspeed = normalspeed; - p->runspeed = runspeed; - p->thrustfactor = thrustfactor; - p->accelstart = accelstart; - p->acceleration = acceleration; p->charflags = charflags; - p->thokitem = thokitem; - p->spinitem = spinitem; - p->revitem = revitem; - p->actionspd = actionspd; - p->mindash = mindash; - p->maxdash = maxdash; p->starposttime = starposttime; p->starpostx = starpostx; @@ -2514,7 +2473,6 @@ void G_PlayerReborn(INT32 player) p->starpostz = starpostz; p->starpostnum = starpostnum; p->starpostangle = starpostangle; - p->jumpfactor = jumpfactor; p->exiting = exiting; p->numboxes = numboxes; @@ -5531,24 +5489,8 @@ void G_BeginRecording(void) demo_p += 16; // Stats - WRITEUINT8(demo_p,player->charability); - WRITEUINT8(demo_p,player->charability2); - WRITEUINT8(demo_p,player->actionspd>>FRACBITS); - WRITEUINT8(demo_p,player->mindash>>FRACBITS); - WRITEUINT8(demo_p,player->maxdash>>FRACBITS); - // SRB2kart WRITEUINT8(demo_p,player->kartspeed); WRITEUINT8(demo_p,player->kartweight); - // - WRITEUINT8(demo_p,player->normalspeed>>FRACBITS); - WRITEUINT8(demo_p,player->runspeed>>FRACBITS); - WRITEUINT8(demo_p,player->thrustfactor); - WRITEUINT8(demo_p,player->accelstart); - WRITEUINT8(demo_p,player->acceleration); - - // Trying to convert it back to % causes demo desync due to precision loss. - // Don't do it. - WRITEFIXED(demo_p, player->jumpfactor); // Save netvar data (SONICCD, etc) CV_SaveNetVars(&demo_p); @@ -5761,9 +5703,8 @@ void G_DoPlayDemo(char *defdemoname) UINT8 i; lumpnum_t l; char skin[17],color[17],*n,*pdemoname; - UINT8 version,subversion,charability,charability2,kartspeed,kartweight,thrustfactor,accelstart,acceleration; + UINT8 version,subversion,kartspeed,kartweight; UINT32 randseed; - fixed_t actionspd,mindash,maxdash,normalspeed,runspeed,jumpfactor; char msg[1024]; #if defined(SKIPERRORS) && !defined(DEVELOP) boolean skiperrors = false; @@ -5900,21 +5841,21 @@ void G_DoPlayDemo(char *defdemoname) M_Memcpy(color,demo_p,16); demo_p += 16; - charability = READUINT8(demo_p); - charability2 = READUINT8(demo_p); - actionspd = (fixed_t)READUINT8(demo_p)<kartweight); // - else if (fastcmp(field,"normalspeed")) - lua_pushfixed(L, plr->normalspeed); - else if (fastcmp(field,"runspeed")) - lua_pushfixed(L, plr->runspeed); - else if (fastcmp(field,"thrustfactor")) - lua_pushinteger(L, plr->thrustfactor); - else if (fastcmp(field,"accelstart")) - lua_pushinteger(L, plr->accelstart); - else if (fastcmp(field,"acceleration")) - lua_pushinteger(L, plr->acceleration); - else if (fastcmp(field,"charability")) - lua_pushinteger(L, plr->charability); - else if (fastcmp(field,"charability2")) - lua_pushinteger(L, plr->charability2); else if (fastcmp(field,"charflags")) lua_pushinteger(L, plr->charflags); - else if (fastcmp(field,"thokitem")) - lua_pushinteger(L, plr->thokitem); - else if (fastcmp(field,"spinitem")) - lua_pushinteger(L, plr->spinitem); - else if (fastcmp(field,"revitem")) - lua_pushinteger(L, plr->revitem); - else if (fastcmp(field,"actionspd")) - lua_pushfixed(L, plr->actionspd); - else if (fastcmp(field,"mindash")) - lua_pushfixed(L, plr->mindash); - else if (fastcmp(field,"maxdash")) - lua_pushfixed(L, plr->maxdash); - else if (fastcmp(field,"jumpfactor")) - lua_pushfixed(L, plr->jumpfactor); else if (fastcmp(field,"lives")) lua_pushinteger(L, plr->lives); else if (fastcmp(field,"continues")) @@ -431,36 +403,8 @@ static int player_set(lua_State *L) else if (fastcmp(field,"kartweight")) plr->kartweight = (UINT8)luaL_checkinteger(L, 3); // - else if (fastcmp(field,"normalspeed")) - plr->normalspeed = luaL_checkfixed(L, 3); - else if (fastcmp(field,"runspeed")) - plr->runspeed = luaL_checkfixed(L, 3); - else if (fastcmp(field,"thrustfactor")) - plr->thrustfactor = (UINT8)luaL_checkinteger(L, 3); - else if (fastcmp(field,"accelstart")) - plr->accelstart = (UINT8)luaL_checkinteger(L, 3); - else if (fastcmp(field,"acceleration")) - plr->acceleration = (UINT8)luaL_checkinteger(L, 3); - else if (fastcmp(field,"charability")) - plr->charability = (UINT8)luaL_checkinteger(L, 3); - else if (fastcmp(field,"charability2")) - plr->charability2 = (UINT8)luaL_checkinteger(L, 3); else if (fastcmp(field,"charflags")) plr->charflags = (UINT32)luaL_checkinteger(L, 3); - else if (fastcmp(field,"thokitem")) - plr->thokitem = luaL_checkinteger(L, 3); - else if (fastcmp(field,"spinitem")) - plr->spinitem = luaL_checkinteger(L, 3); - else if (fastcmp(field,"revitem")) - plr->revitem = luaL_checkinteger(L, 3); - else if (fastcmp(field,"actionspd")) - plr->actionspd = (INT32)luaL_checkinteger(L, 3); - else if (fastcmp(field,"mindash")) - plr->mindash = (INT32)luaL_checkinteger(L, 3); - else if (fastcmp(field,"maxdash")) - plr->maxdash = (INT32)luaL_checkinteger(L, 3); - else if (fastcmp(field,"jumpfactor")) - plr->jumpfactor = (INT32)luaL_checkinteger(L, 3); else if (fastcmp(field,"lives")) plr->lives = (SINT8)luaL_checkinteger(L, 3); else if (fastcmp(field,"continues")) diff --git a/src/p_saveg.c b/src/p_saveg.c index 0061ee029..fb82ceb23 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -265,25 +265,11 @@ static void P_NetArchivePlayers(void) if (flags & AWAYVIEW) WRITEUINT32(save_p, players[i].awayviewmobj->mobjnum); - WRITEUINT8(save_p, players[i].charability); - WRITEUINT8(save_p, players[i].charability2); WRITEUINT32(save_p, players[i].charflags); - WRITEUINT32(save_p, (UINT32)players[i].thokitem); - WRITEUINT32(save_p, (UINT32)players[i].spinitem); - WRITEUINT32(save_p, (UINT32)players[i].revitem); - WRITEFIXED(save_p, players[i].actionspd); - WRITEFIXED(save_p, players[i].mindash); - WRITEFIXED(save_p, players[i].maxdash); // SRB2kart WRITEUINT8(save_p, players[i].kartspeed); WRITEUINT8(save_p, players[i].kartweight); // - WRITEFIXED(save_p, players[i].normalspeed); - WRITEFIXED(save_p, players[i].runspeed); - WRITEUINT8(save_p, players[i].thrustfactor); - WRITEUINT8(save_p, players[i].accelstart); - WRITEUINT8(save_p, players[i].acceleration); - WRITEFIXED(save_p, players[i].jumpfactor); for (j = 0; j < MAXPREDICTTICS; j++) { @@ -447,25 +433,11 @@ static void P_NetUnArchivePlayers(void) players[i].viewheight = 32<flags & FF_SHATTER) && !(rover->flags & FF_SPINBUST) && !((player->pflags & PF_SPINNING) && !(player->pflags & PF_JUMPED)) - && (player->charability != CA_GLIDEANDCLIMB && !player->powers[pw_super]) + && (/*player->charability != CA_GLIDEANDCLIMB &&*/ !player->powers[pw_super]) && !(player->pflags & PF_DRILLING) && !metalrecording) continue; // Only Knuckles can break this rock... - if (!(rover->flags & FF_SHATTER) && (rover->flags & FF_ONLYKNUX) && !(player->charability == CA_GLIDEANDCLIMB)) - continue; + /*if (!(rover->flags & FF_SHATTER) && (rover->flags & FF_ONLYKNUX) && !(player->charability == CA_GLIDEANDCLIMB)) + continue;*/ topheight = P_GetFOFTopZ(player->mo, node->m_sector, rover, player->mo->x, player->mo->y, NULL); bottomheight = P_GetFOFBottomZ(player->mo, node->m_sector, rover, player->mo->x, player->mo->y, NULL); @@ -2468,7 +2468,7 @@ static void P_DoBubbleBreath(player_t *player) return; // Tails stirs up the water while flying in it - if (player->powers[pw_tailsfly] && (leveltime & 1) && player->charability != CA_SWIM) + /*if (player->powers[pw_tailsfly] && (leveltime & 1) && player->charability != CA_SWIM) { fixed_t radius = (3*player->mo->radius)>>1; angle_t fa = ((leveltime%45)*FINEANGLES/8) & FINEMASK; @@ -2494,7 +2494,7 @@ static void P_DoBubbleBreath(player_t *player) stirwaterz, MT_SMALLBUBBLE); bubble->destscale = player->mo->scale; P_SetScale(bubble,bubble->destscale); - } + }*/ } // @@ -3718,13 +3718,13 @@ void P_DoJump(player_t *player, boolean soundandstate) else if (player->mo->eflags & MFE_GOOWATER) { player->mo->momz = 7*FRACUNIT; - if (player->charability == CA_JUMPBOOST && onground) + /*if (player->charability == CA_JUMPBOOST && onground) { if (player->charability2 == CA2_MULTIABILITY) player->mo->momz += FixedMul(FRACUNIT/4, dist6); else player->mo->momz += FixedMul(FRACUNIT/8, dist6); - } + }*/ } else if (maptol & TOL_NIGHTS) player->mo->momz = 24*FRACUNIT; @@ -4029,7 +4029,7 @@ static void P_DoJumpStuff(player_t *player, ticcmd_t *cmd) #ifdef HAVE_BLUA if (!LUAh_JumpSpinSpecial(player)) #endif - switch (player->charability) + /*switch (player->charability) { case CA_TELEKINESIS: if (player->pflags & PF_JUMPED) @@ -4054,11 +4054,11 @@ static void P_DoJumpStuff(player_t *player, ticcmd_t *cmd) break; default: break; - } + }*/ } } - if (player->charability == CA_AIRDRILL) + /*if (player->charability == CA_AIRDRILL) { if (player->pflags & PF_JUMPED) { @@ -4076,7 +4076,7 @@ static void P_DoJumpStuff(player_t *player, ticcmd_t *cmd) P_InstaThrust(player->mo, player->mo->angle, ((FixedMul(player->normalspeed - player->actionspd/4, player->mo->scale))*2)/3); } } - } + }*/ if (cmd->buttons & BT_DRIFT && !player->exiting && !P_PlayerInPain(player)) { @@ -4299,7 +4299,7 @@ static void P_DoJumpStuff(player_t *player, ticcmd_t *cmd) { if (player->secondjump == 1) { - if (player->charability == CA_FLOAT) + /*if (player->charability == CA_FLOAT) player->mo->momz = 0; else if (player->charability == CA_SLOWFALL) { @@ -4310,7 +4310,7 @@ static void P_DoJumpStuff(player_t *player, ticcmd_t *cmd) } else if (P_MobjFlip(player->mo)*player->mo->momz < -gravity*4) player->mo->momz = P_MobjFlip(player->mo)*-gravity*4; - } + }*/ player->pflags &= ~PF_SPINNING; } } @@ -4320,11 +4320,11 @@ static void P_DoJumpStuff(player_t *player, ticcmd_t *cmd) player->pflags &= ~PF_JUMPDOWN; // Repeat abilities, but not double jump! - if ((player->charability2 == CA2_MULTIABILITY && player->charability != CA_DOUBLEJUMP) + /*if ((player->charability2 == CA2_MULTIABILITY && player->charability != CA_DOUBLEJUMP) || (player->powers[pw_super] && ALL7EMERALDS(player->powers[pw_emeralds]))) player->secondjump = 0; else if (player->charability == CA_FLOAT && player->secondjump == 1) - player->secondjump = 2; + player->secondjump = 2;*/ // If letting go of the jump button while still on ascent, cut the jump height. @@ -6545,7 +6545,7 @@ static void P_MovePlayer(player_t *player) else if (player->dashspeed > 0 && player->dashspeed < FixedMul(player->mindash, player->mo->scale)) player->dashspeed = FixedMul(player->mindash, player->mo->scale); - if (!(player->charability == CA_GLIDEANDCLIMB) || player->gotflag) // If you can't glide, then why the heck would you be gliding? + if (/*!(player->charability == CA_GLIDEANDCLIMB) ||*/ player->gotflag) // If you can't glide, then why the heck would you be gliding? { /* // SRB2kart - ??? if (player->pflags & PF_GLIDING || player->climbing) @@ -6854,7 +6854,7 @@ static void P_MovePlayer(player_t *player) } // Otherwise, face the direction you're travelling. else if (player->panim == PA_WALK || player->panim == PA_RUN || player->panim == PA_ROLL - || (/*(player->mo->state >= &states[S_PLAY_ABL1] && player->mo->state <= &states[S_PLAY_SPC4]) && */player->charability == CA_FLY)) // SRB2kart - idk + /*|| ((player->mo->state >= &states[S_PLAY_ABL1] && player->mo->state <= &states[S_PLAY_SPC4]) && player->charability == CA_FLY)*/) // SRB2kart - idk player->mo->angle = R_PointToAngle2(0, 0, player->rmomx, player->rmomy); // Update the local angle control. @@ -9090,7 +9090,7 @@ void P_PlayerThink(player_t *player) || (player->spectator || player->powers[pw_flashing] < K_GetKartFlashing(player)))) player->powers[pw_flashing]--; - if (player->powers[pw_tailsfly] && player->powers[pw_tailsfly] < UINT16_MAX && player->charability != CA_SWIM && !(player->powers[pw_super] && ALL7EMERALDS(player->powers[pw_emeralds]))) // tails fly counter + if (player->powers[pw_tailsfly] && player->powers[pw_tailsfly] < UINT16_MAX /*&& player->charability != CA_SWIM*/ && !(player->powers[pw_super] && ALL7EMERALDS(player->powers[pw_emeralds]))) // tails fly counter player->powers[pw_tailsfly]--; /* // SRB2kart - Can't drown. From 889ead7840408b378ac512901c4f52b01ddf3ad1 Mon Sep 17 00:00:00 2001 From: TehRealSalt Date: Thu, 2 May 2019 00:44:04 -0400 Subject: [PATCH 61/66] Fix wheel animations --- src/g_game.c | 2 +- src/k_kart.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/g_game.c b/src/g_game.c index ad25c8ce9..713eecac1 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -5283,7 +5283,7 @@ void G_ReadMetalTic(mobj_t *metal) speed = FixedDiv(P_AproxDistance(oldmetal.momx, oldmetal.momy), metal->scale)>>FRACBITS; // Use speed to decide an appropriate state - if (speed > 28) // default skin runspeed + if (speed > 20) // default skin runspeed statetype = 2; else if (speed > 1) // stopspeed statetype = 1; diff --git a/src/k_kart.c b/src/k_kart.c index c6f028872..8d1e9373a 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -1634,7 +1634,7 @@ void K_KartMoveAnimation(player_t *player) P_SetPlayerMobjState(player->mo, S_KART_DRIFT1_R); } // Run frames - S_KART_RUN1 S_KART_RUN1_L S_KART_RUN1_R - else if (player->speed > FixedMul(player->runspeed, player->mo->scale)) + else if (player->speed > (20*player->mo->scale)) { if (cmd->driftturn < 0 && !(player->mo->state >= &states[S_KART_RUN1_R] && player->mo->state <= &states[S_KART_RUN2_R])) P_SetPlayerMobjState(player->mo, S_KART_RUN1_R); @@ -1644,7 +1644,7 @@ void K_KartMoveAnimation(player_t *player) P_SetPlayerMobjState(player->mo, S_KART_RUN1); } // Walk frames - S_KART_WALK1 S_KART_WALK1_L S_KART_WALK1_R - else if (player->speed <= FixedMul(player->runspeed, player->mo->scale)) + else if (player->speed <= (20*player->mo->scale)) { if (cmd->driftturn < 0 && !(player->mo->state >= &states[S_KART_WALK1_R] && player->mo->state <= &states[S_KART_WALK2_R])) P_SetPlayerMobjState(player->mo, S_KART_WALK1_R); From 2d9ae1abfd3aadff827e5e1e3e92f4ca627cf922 Mon Sep 17 00:00:00 2001 From: TehRealSalt Date: Thu, 2 May 2019 02:13:44 -0400 Subject: [PATCH 62/66] Dumbass typo --- src/g_game.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/g_game.c b/src/g_game.c index 229cf3d47..bfe49fc1a 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -1093,7 +1093,7 @@ static INT32 Joy3Axis(axis_input_e axissel) retaxis = +JOYAXISRANGE; if (!Joystick3.bGamepadStyle && axissel < AXISDEAD) { - const INT32 jdeadzone = jdeadzone = ((JOYAXISRANGE-1) * cv_deadzone3.value) >> FRACBITS; + const INT32 jdeadzone = ((JOYAXISRANGE-1) * cv_deadzone3.value) >> FRACBITS; if (-jdeadzone < retaxis && retaxis < jdeadzone) return 0; } @@ -1173,7 +1173,7 @@ static INT32 Joy4Axis(axis_input_e axissel) retaxis = +JOYAXISRANGE; if (!Joystick4.bGamepadStyle && axissel < AXISDEAD) { - const INT32 jdeadzone = jdeadzone = ((JOYAXISRANGE-1) * cv_deadzone4.value) >> FRACBITS; + const INT32 jdeadzone = ((JOYAXISRANGE-1) * cv_deadzone4.value) >> FRACBITS; if (-jdeadzone < retaxis && retaxis < jdeadzone) return 0; } From ab7e7476483e75c5f2993d1bc0cc30c583ee5121 Mon Sep 17 00:00:00 2001 From: TehRealSalt Date: Thu, 2 May 2019 02:51:13 -0400 Subject: [PATCH 63/66] Fix warnings Remove entries from dehacked, remove P_DoJump, remove debug stuff --- src/dehacked.c | 21 ----- src/g_game.c | 2 +- src/lua_baselib.c | 12 --- src/p_local.h | 1 - src/p_user.c | 204 +--------------------------------------------- src/st_stuff.c | 16 ++-- 6 files changed, 13 insertions(+), 243 deletions(-) diff --git a/src/dehacked.c b/src/dehacked.c index 1c88fe832..03944640d 100644 --- a/src/dehacked.c +++ b/src/dehacked.c @@ -8642,27 +8642,6 @@ struct { // Character flags (skinflags_t) {"SF_HIRES",SF_HIRES}, - // Character abilities! - // Primary - {"CA_NONE",CA_NONE}, // now slot 0! - {"CA_THOK",CA_THOK}, - {"CA_FLY",CA_FLY}, - {"CA_GLIDEANDCLIMB",CA_GLIDEANDCLIMB}, - {"CA_HOMINGTHOK",CA_HOMINGTHOK}, - {"CA_DOUBLEJUMP",CA_DOUBLEJUMP}, - {"CA_FLOAT",CA_FLOAT}, - {"CA_SLOWFALL",CA_SLOWFALL}, - {"CA_SWIM",CA_SWIM}, - {"CA_TELEKINESIS",CA_TELEKINESIS}, - {"CA_FALLSWITCH",CA_FALLSWITCH}, - {"CA_JUMPBOOST",CA_JUMPBOOST}, - {"CA_AIRDRILL",CA_AIRDRILL}, - {"CA_JUMPTHOK",CA_JUMPTHOK}, - // Secondary - {"CA2_NONE",CA2_NONE}, // now slot 0! - {"CA2_SPINDASH",CA2_SPINDASH}, - {"CA2_MULTIABILITY",CA2_MULTIABILITY}, - // Sound flags {"SF_TOTALLYSINGLE",SF_TOTALLYSINGLE}, {"SF_NOMULTIPLESOUND",SF_NOMULTIPLESOUND}, diff --git a/src/g_game.c b/src/g_game.c index 260c88790..a1e90822e 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -2338,7 +2338,6 @@ void G_PlayerReborn(INT32 player) INT16 starpostz; INT32 starpostnum; INT32 starpostangle; - fixed_t jumpfactor; INT32 exiting; INT16 numboxes; INT16 totalring; @@ -2390,6 +2389,7 @@ void G_PlayerReborn(INT32 player) kartspeed = players[player].kartspeed; kartweight = players[player].kartweight; // + charflags = players[player].charflags; starposttime = players[player].starposttime; starpostx = players[player].starpostx; diff --git a/src/lua_baselib.c b/src/lua_baselib.c index d9a5fb1d7..481ab89a0 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -946,17 +946,6 @@ static int lib_pHomingAttack(lua_State *L) return 1; }*/ -static int lib_pDoJump(lua_State *L) -{ - player_t *player = *((player_t **)luaL_checkudata(L, 1, META_PLAYER)); - boolean soundandstate = (boolean)lua_opttrueboolean(L, 2); - NOHUD - if (!player) - return LUA_ErrInvalid(L, "player_t"); - P_DoJump(player, soundandstate); - return 0; -} - static int lib_pSpawnThokMobj(lua_State *L) { player_t *player = *((player_t **)luaL_checkudata(L, 1, META_PLAYER)); @@ -2645,7 +2634,6 @@ static luaL_Reg lib[] = { {"P_NukeEnemies",lib_pNukeEnemies}, {"P_HomingAttack",lib_pHomingAttack}, //{"P_SuperReady",lib_pSuperReady}, - {"P_DoJump",lib_pDoJump}, {"P_SpawnThokMobj",lib_pSpawnThokMobj}, {"P_SpawnSpinMobj",lib_pSpawnSpinMobj}, {"P_Telekinesis",lib_pTelekinesis}, diff --git a/src/p_local.h b/src/p_local.h index 1ac613bdb..a6f6b8aef 100644 --- a/src/p_local.h +++ b/src/p_local.h @@ -178,7 +178,6 @@ boolean P_LookForEnemies(player_t *player); void P_NukeEnemies(mobj_t *inflictor, mobj_t *source, fixed_t radius); void P_HomingAttack(mobj_t *source, mobj_t *enemy); /// \todo doesn't belong in p_user //boolean P_SuperReady(player_t *player); -void P_DoJump(player_t *player, boolean soundandstate); boolean P_AnalogMove(player_t *player); /*boolean P_TransferToNextMare(player_t *player); UINT8 P_FindLowestMare(void);*/ diff --git a/src/p_user.c b/src/p_user.c index ab0a16edd..d5a4c6944 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -3634,195 +3634,6 @@ static void P_DoFiring(player_t *player, ticcmd_t *cmd) // SRB2kart - unused. } */ -// -// P_DoJump -// -// Jump routine for the player -// -void P_DoJump(player_t *player, boolean soundandstate) -{ - fixed_t factor; - const fixed_t dist6 = FixedMul(FixedDiv(player->speed, player->mo->scale), player->actionspd)/20; - - return; - - if (player->pflags & PF_JUMPSTASIS) - return; - - if (!player->jumpfactor) - return; - - if (player->kartstuff[k_spinouttimer]) // SRB2kart - return; - - /* // SRB2kart - climbing in a kart? - if (player->climbing) - { - // Jump this high. - if (player->powers[pw_super]) - player->mo->momz = 5*FRACUNIT; - else if (player->mo->eflags & MFE_UNDERWATER) - player->mo->momz = 2*FRACUNIT; - else - player->mo->momz = 15*(FRACUNIT/4); - - player->mo->angle = player->mo->angle - ANGLE_180; // Turn around from the wall you were climbing. - - if (player == &players[consoleplayer]) - localangle = player->mo->angle; // Adjust the local control angle. - else if (player == &players[secondarydisplayplayer]) - localangle2 = player->mo->angle; - else if (player == &players[thirddisplayplayer]) - localangle3 = player->mo->angle; - else if (player == &players[fourthdisplayplayer]) - localangle4 = player->mo->angle; - - player->climbing = 0; // Stop climbing, duh! - P_InstaThrust(player->mo, player->mo->angle, FixedMul(6*FRACUNIT, player->mo->scale)); // Jump off the wall. - } - // Quicksand jumping. - else if (P_InQuicksand(player->mo)) - { - if (player->mo->ceilingz-player->mo->floorz <= player->mo->height-1) - return; - player->mo->momz += (39*(FRACUNIT/4))>>1; - if (player->mo->momz >= 6*FRACUNIT) - player->mo->momz = 6*FRACUNIT; //max momz in quicksand - else if (player->mo->momz < 0) // still descending? - player->mo->momz = (39*(FRACUNIT/4))>>1; // just default to the jump height. - } - else*/ if (!(player->pflags & PF_JUMPED)) // Spin Attack - { - if (player->mo->ceilingz-player->mo->floorz <= player->mo->height-1) - return; - - // Jump this high. - if (player->pflags & PF_CARRIED) - { - player->mo->momz = 9*FRACUNIT; - player->pflags &= ~PF_CARRIED; - /*if (player-players == consoleplayer && botingame) - CV_SetValue(&cv_analog2, true);*/ - } - else if (player->pflags & PF_ITEMHANG) - { - player->mo->momz = 9*FRACUNIT; - player->pflags &= ~PF_ITEMHANG; - } - else if (player->pflags & PF_ROPEHANG) - { - player->mo->momz = 12*FRACUNIT; - player->pflags &= ~PF_ROPEHANG; - P_SetTarget(&player->mo->tracer, NULL); - } - else if (player->mo->eflags & MFE_GOOWATER) - { - player->mo->momz = 7*FRACUNIT; - /*if (player->charability == CA_JUMPBOOST && onground) - { - if (player->charability2 == CA2_MULTIABILITY) - player->mo->momz += FixedMul(FRACUNIT/4, dist6); - else - player->mo->momz += FixedMul(FRACUNIT/8, dist6); - }*/ - } - else if (maptol & TOL_NIGHTS) - player->mo->momz = 24*FRACUNIT; - else - player->mo->momz = 3*FRACUNIT; // Kart jump momentum. - /* // SRB2kart - Okay enough of that. - else if (player->powers[pw_super]) - { - if (player->charability == CA_FLOAT) - player->mo->momz = 28*FRACUNIT; //Obscene jump height anyone? - else if (player->charability == CA_SLOWFALL) - player->mo->momz = 37*(FRACUNIT/2); //Less obscene because during super, floating propells oneself upward. - else // Default super jump momentum. - player->mo->momz = 13*FRACUNIT; - - // Add a boost for super characters with float/slowfall and multiability. - if (player->charability2 == CA2_MULTIABILITY && - (player->charability == CA_FLOAT || player->charability == CA_SLOWFALL)) - player->mo->momz += 2*FRACUNIT; - else if (player->charability == CA_JUMPBOOST) - { - if (player->charability2 == CA2_MULTIABILITY) - player->mo->momz += FixedMul(FRACUNIT/4, dist6); - else - player->mo->momz += FixedMul(FRACUNIT/8, dist6); - } - } - else if (player->charability2 == CA2_MULTIABILITY && - (player->charability == CA_DOUBLEJUMP || player->charability == CA_FLOAT || player->charability == CA_SLOWFALL)) - { - // Multiability exceptions, since some abilities cannot effectively use it and need a boost. - if (player->charability == CA_DOUBLEJUMP) - player->mo->momz = 23*(FRACUNIT/2); // Increased jump height instead of infinite jumps. - else if (player->charability == CA_FLOAT || player->charability == CA_SLOWFALL) - player->mo->momz = 12*FRACUNIT; // Increased jump height due to ineffective repeat. - } - else - { - player->mo->momz = 39*(FRACUNIT/4); // Default jump momentum. - if (player->charability == CA_JUMPBOOST && onground) - { - if (player->charability2 == CA2_MULTIABILITY) - player->mo->momz += FixedMul(FRACUNIT/4, dist6); - else - player->mo->momz += FixedMul(FRACUNIT/8, dist6); - } - } - */ - - // Reduce player momz by 58.5% when underwater. - if (player->mo->eflags & MFE_UNDERWATER) - player->mo->momz = FixedMul(player->mo->momz, FixedDiv(117*FRACUNIT, 200*FRACUNIT)); - - player->jumping = 1; - } - - factor = player->jumpfactor; - - if (twodlevel || (player->mo->flags2 & MF2_TWOD)) - factor += player->jumpfactor / 10; - - P_SetObjectMomZ(player->mo, FixedMul(factor, player->mo->momz), false); // Custom height - - // set just an eensy above the ground - if (player->mo->eflags & MFE_VERTICALFLIP) - { - player->mo->z--; - if (player->mo->pmomz < 0) - player->mo->momz += player->mo->pmomz; // Add the platform's momentum to your jump. - else - player->mo->pmomz = 0; - } - else - { - player->mo->z++; - if (player->mo->pmomz > 0) - player->mo->momz += player->mo->pmomz; // Add the platform's momentum to your jump. - else - player->mo->pmomz = 0; - } - player->mo->eflags &= ~MFE_APPLYPMOMZ; - - player->pflags |= PF_JUMPED; - - if (soundandstate) - { - if (!player->spectator) - S_StartSound(player->mo, sfx_jump); // Play jump sound! - - /* // SRB2kart - don't need jump frames - if (!(player->charability2 == CA2_SPINDASH)) - P_SetPlayerMobjState(player->mo, S_PLAY_SPRING); - else - P_SetPlayerMobjState(player->mo, S_PLAY_ATK1); - */ - } -} - // // P_DoSpinDash // @@ -3946,7 +3757,7 @@ void P_DoJumpShield(player_t *player) return; player->pflags &= ~PF_JUMPED; - P_DoJump(player, false); + //P_DoJump(player, false); player->pflags &= ~PF_JUMPED; player->secondjump = 0; player->jumping = 0; @@ -4091,7 +3902,7 @@ static void P_DoJumpStuff(player_t *player, ticcmd_t *cmd) // Jump S3&K style while in quicksand. if (P_InQuicksand(player->mo)) { - P_DoJump(player, true); + //P_DoJump(player, true); player->secondjump = 0; player->pflags &= ~PF_THOKKED; } @@ -4099,7 +3910,7 @@ static void P_DoJumpStuff(player_t *player, ticcmd_t *cmd) // can't jump while in air, can't jump while jumping if (onground || player->climbing || player->pflags & (PF_CARRIED|PF_ITEMHANG|PF_ROPEHANG)) { - P_DoJump(player, true); + //P_DoJump(player, true); player->secondjump = 0; player->pflags &= ~PF_THOKKED; } @@ -6538,13 +6349,6 @@ static void P_MovePlayer(player_t *player) P_SetPlayerMobjState(player->mo, S_KART_STND1); // SRB2kart - was S_PLAY_STND } - // Cap the speed limit on a spindash - // Up the 60*FRACUNIT number to boost faster, you speed demon you! - if (player->dashspeed > FixedMul(player->maxdash, player->mo->scale)) - player->dashspeed = FixedMul(player->maxdash, player->mo->scale); - else if (player->dashspeed > 0 && player->dashspeed < FixedMul(player->mindash, player->mo->scale)) - player->dashspeed = FixedMul(player->mindash, player->mo->scale); - if (/*!(player->charability == CA_GLIDEANDCLIMB) ||*/ player->gotflag) // If you can't glide, then why the heck would you be gliding? { /* // SRB2kart - ??? @@ -6798,7 +6602,7 @@ static void P_MovePlayer(player_t *player) P_DoSpinDash(player, cmd); */ // jumping - P_DoJumpStuff(player, cmd); + //P_DoJumpStuff(player, cmd); /* // If you're not spinning, you'd better not be spindashing! diff --git a/src/st_stuff.c b/src/st_stuff.c index 36a658aec..cd4ed7e25 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -573,17 +573,17 @@ static void ST_drawDebugInfo(void) if (cv_debug & DBG_DETAILED) { - V_DrawRightAlignedString(320, height - 104, V_MONOSPACE, va("SHIELD: %5x", stplyr->powers[pw_shield])); + //V_DrawRightAlignedString(320, height - 104, V_MONOSPACE, va("SHIELD: %5x", stplyr->powers[pw_shield])); V_DrawRightAlignedString(320, height - 96, V_MONOSPACE, va("SCALE: %5d%%", (stplyr->mo->scale*100)/FRACUNIT)); - V_DrawRightAlignedString(320, height - 88, V_MONOSPACE, va("DASH: %3d/%3d", stplyr->dashspeed>>FRACBITS, FixedMul(stplyr->maxdash,stplyr->mo->scale)>>FRACBITS)); - V_DrawRightAlignedString(320, height - 80, V_MONOSPACE, va("AIR: %4d, %3d", stplyr->powers[pw_underwater], stplyr->powers[pw_spacetime])); + //V_DrawRightAlignedString(320, height - 88, V_MONOSPACE, va("DASH: %3d/%3d", stplyr->dashspeed>>FRACBITS, FixedMul(stplyr->maxdash,stplyr->mo->scale)>>FRACBITS)); + //V_DrawRightAlignedString(320, height - 80, V_MONOSPACE, va("AIR: %4d, %3d", stplyr->powers[pw_underwater], stplyr->powers[pw_spacetime])); // Flags - V_DrawRightAlignedString(304-64, height - 72, V_MONOSPACE, "Flags:"); - V_DrawString(304-60, height - 72, (stplyr->jumping) ? V_GREENMAP : V_REDMAP, "JM"); - V_DrawString(304-40, height - 72, (stplyr->pflags & PF_JUMPED) ? V_GREENMAP : V_REDMAP, "JD"); - V_DrawString(304-20, height - 72, (stplyr->pflags & PF_SPINNING) ? V_GREENMAP : V_REDMAP, "SP"); - V_DrawString(304, height - 72, (stplyr->pflags & PF_STARTDASH) ? V_GREENMAP : V_REDMAP, "ST"); + //V_DrawRightAlignedString(304-64, height - 72, V_MONOSPACE, "Flags:"); + //V_DrawString(304-60, height - 72, (stplyr->jumping) ? V_GREENMAP : V_REDMAP, "JM"); + //V_DrawString(304-40, height - 72, (stplyr->pflags & PF_JUMPED) ? V_GREENMAP : V_REDMAP, "JD"); + //V_DrawString(304-20, height - 72, (stplyr->pflags & PF_SPINNING) ? V_GREENMAP : V_REDMAP, "SP"); + //V_DrawString(304, height - 72, (stplyr->pflags & PF_STARTDASH) ? V_GREENMAP : V_REDMAP, "ST"); V_DrawRightAlignedString(320, height - 64, V_MONOSPACE, va("CEILZ: %6d", stplyr->mo->ceilingz>>FRACBITS)); V_DrawRightAlignedString(320, height - 56, V_MONOSPACE, va("FLOORZ: %6d", stplyr->mo->floorz>>FRACBITS)); From e954f0b410a09451dc03a1c772061c4537e658e5 Mon Sep 17 00:00:00 2001 From: TehRealSalt Date: Thu, 2 May 2019 02:52:22 -0400 Subject: [PATCH 64/66] Missed a spot --- src/k_kart.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/k_kart.c b/src/k_kart.c index 8d1e9373a..d8028f08a 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -8291,7 +8291,7 @@ static void K_drawKartFirstPerson(void) } { - if (stplyr->speed < FixedMul(stplyr->runspeed, stplyr->mo->scale) && (leveltime & 1) && !splitscreen) + if (stplyr->speed < (20*stplyr->mo->scale) && (leveltime & 1) && !splitscreen) y++; // the following isn't EXPLICITLY right, it just gets the result we want, but i'm too lazy to look up the right way to do it if (stplyr->mo->flags2 & MF2_SHADOW) From 9314a0d9a9a7a9533f7cd55cdce50a94628c0224 Mon Sep 17 00:00:00 2001 From: TehRealSalt Date: Thu, 2 May 2019 02:58:34 -0400 Subject: [PATCH 65/66] Fix normalspeed Alright fuck this branch it's misery --- src/p_enemy.c | 4 ++-- src/p_mobj.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/p_enemy.c b/src/p_enemy.c index 31a5a61bf..599d1f2a5 100644 --- a/src/p_enemy.c +++ b/src/p_enemy.c @@ -4781,8 +4781,8 @@ void A_DetonChase(mobj_t *actor) actor->reactiontime = -42; exact = actor->movedir>>ANGLETOFINESHIFT; - xyspeed = FixedMul(FixedMul(actor->tracer->player->normalspeed,3*FRACUNIT/4), FINECOSINE(exact)); - actor->momz = FixedMul(FixedMul(actor->tracer->player->normalspeed,3*FRACUNIT/4), FINESINE(exact)); + xyspeed = FixedMul(FixedMul(K_GetKartSpeed(actor->tracer->player, false),3*FRACUNIT/4), FINECOSINE(exact)); + actor->momz = FixedMul(FixedMul(K_GetKartSpeed(actor->tracer->player, false),3*FRACUNIT/4), FINESINE(exact)); exact = actor->angle>>ANGLETOFINESHIFT; actor->momx = FixedMul(xyspeed, FINECOSINE(exact)); diff --git a/src/p_mobj.c b/src/p_mobj.c index e1ac3f2db..508acc0b1 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -1932,7 +1932,7 @@ void P_XYMovement(mobj_t *mo) if (mo->type == MT_ORBINAUT || mo->type == MT_JAWZ_DUD || mo->type == MT_JAWZ || mo->type == MT_BALLHOG) //(mo->type == MT_JAWZ && !mo->tracer)) return; - if (mo->player && (mo->player->kartstuff[k_spinouttimer] && !mo->player->kartstuff[k_wipeoutslow]) && mo->player->speed <= mo->player->normalspeed/2) + if (mo->player && (mo->player->kartstuff[k_spinouttimer] && !mo->player->kartstuff[k_wipeoutslow]) && mo->player->speed <= K_GetKartSpeed(mo->player, false)/2) return; //} From 833cf980b487086c441677d6fdd9a37744f3d57b Mon Sep 17 00:00:00 2001 From: TehRealSalt Date: Thu, 2 May 2019 09:20:49 -0400 Subject: [PATCH 66/66] Finish this Now that I was told that the spinout slowdown bug was caused by this I was 100% convinced that we need to remove all of this bullshit ASAP --- src/g_game.c | 13 ++ src/lua_baselib.c | 25 --- src/p_local.h | 2 - src/p_user.c | 445 +--------------------------------------------- 4 files changed, 18 insertions(+), 467 deletions(-) diff --git a/src/g_game.c b/src/g_game.c index e986434a7..9bbe4197c 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -5489,8 +5489,21 @@ void G_BeginRecording(void) demo_p += 16; // Stats + demo_p++; // charability + demo_p++; // charability2 + demo_p++; // actionspd + demo_p++; // mindash + demo_p++; // maxdash + // SRB2Kart WRITEUINT8(demo_p,player->kartspeed); WRITEUINT8(demo_p,player->kartweight); + // + demo_p++; // normalspeed + demo_p++; // runspeed + demo_p++; // thrustfactor + demo_p++; // accelstart + demo_p++; // acceleration + demo_p += 4; // jumpfactor // Save netvar data (SONICCD, etc) CV_SaveNetVars(&demo_p); diff --git a/src/lua_baselib.c b/src/lua_baselib.c index 481ab89a0..541514530 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -946,29 +946,6 @@ static int lib_pHomingAttack(lua_State *L) return 1; }*/ -static int lib_pSpawnThokMobj(lua_State *L) -{ - player_t *player = *((player_t **)luaL_checkudata(L, 1, META_PLAYER)); - NOHUD - if (!player) - return LUA_ErrInvalid(L, "player_t"); - P_SpawnThokMobj(player); - return 0; -} - -static int lib_pSpawnSpinMobj(lua_State *L) -{ - player_t *player = *((player_t **)luaL_checkudata(L, 1, META_PLAYER)); - mobjtype_t type = luaL_checkinteger(L, 2); - NOHUD - if (!player) - return LUA_ErrInvalid(L, "player_t"); - if (type >= NUMMOBJTYPES) - return luaL_error(L, "mobj type %d out of range (0 - %d)", type, NUMMOBJTYPES-1); - P_SpawnSpinMobj(player, type); - return 0; -} - static int lib_pTelekinesis(lua_State *L) { player_t *player = *((player_t **)luaL_checkudata(L, 1, META_PLAYER)); @@ -2634,8 +2611,6 @@ static luaL_Reg lib[] = { {"P_NukeEnemies",lib_pNukeEnemies}, {"P_HomingAttack",lib_pHomingAttack}, //{"P_SuperReady",lib_pSuperReady}, - {"P_SpawnThokMobj",lib_pSpawnThokMobj}, - {"P_SpawnSpinMobj",lib_pSpawnSpinMobj}, {"P_Telekinesis",lib_pTelekinesis}, // p_map diff --git a/src/p_local.h b/src/p_local.h index a6f6b8aef..2362476dd 100644 --- a/src/p_local.h +++ b/src/p_local.h @@ -186,8 +186,6 @@ UINT8 P_FindHighestLap(void); void P_FindEmerald(void); //void P_TransferToAxis(player_t *player, INT32 axisnum); boolean P_PlayerMoving(INT32 pnum); -void P_SpawnThokMobj(player_t *player); -void P_SpawnSpinMobj(player_t *player, mobjtype_t type); void P_Telekinesis(player_t *player, fixed_t thrust, fixed_t range); void P_PlayLivesJingle(player_t *player); diff --git a/src/p_user.c b/src/p_user.c index d5a4c6944..9999b5a9d 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -1653,113 +1653,6 @@ mobj_t *P_SpawnGhostMobj(mobj_t *mobj) return ghost; } -// -// P_SpawnThokMobj -// -// Spawns the appropriate thok object on the player -// -void P_SpawnThokMobj(player_t *player) -{ - mobj_t *mobj; - mobjtype_t type = player->thokitem; - fixed_t zheight; - - if (player->skincolor == 0) - return; - - if (player->spectator) - return; - - if (type == MT_GHOST) - mobj = P_SpawnGhostMobj(player->mo); // virtually does everything here for us - else - { - if (player->mo->eflags & MFE_VERTICALFLIP) - zheight = player->mo->z + player->mo->height + FixedDiv(P_GetPlayerHeight(player) - player->mo->height, 3*FRACUNIT) - FixedMul(mobjinfo[type].height, player->mo->scale); - else - zheight = player->mo->z - FixedDiv(P_GetPlayerHeight(player) - player->mo->height, 3*FRACUNIT); - - if (!(player->mo->eflags & MFE_VERTICALFLIP) && zheight < player->mo->floorz && !(mobjinfo[type].flags & MF_NOCLIPHEIGHT)) - zheight = player->mo->floorz; - else if (player->mo->eflags & MFE_VERTICALFLIP && zheight + FixedMul(mobjinfo[type].height, player->mo->scale) > player->mo->ceilingz && !(mobjinfo[type].flags & MF_NOCLIPHEIGHT)) - zheight = player->mo->ceilingz - FixedMul(mobjinfo[type].height, player->mo->scale); - - mobj = P_SpawnMobj(player->mo->x, player->mo->y, zheight, type); - - // set to player's angle, just in case - mobj->angle = player->mo->angle; - - // color and skin - mobj->color = player->mo->color; - mobj->skin = player->mo->skin; - - // vertical flip - if (player->mo->eflags & MFE_VERTICALFLIP) - mobj->flags2 |= MF2_OBJECTFLIP; - mobj->eflags |= (player->mo->eflags & MFE_VERTICALFLIP); - - // scale - P_SetScale(mobj, player->mo->scale); - mobj->destscale = player->mo->scale; - } - - P_SetTarget(&mobj->target, player->mo); // the one thing P_SpawnGhostMobj doesn't do - if (demorecording) - G_GhostAddThok(); -} - -// -// P_SpawnSpinMobj -// -// Spawns the appropriate spin object on the player -// -void P_SpawnSpinMobj(player_t *player, mobjtype_t type) -{ - mobj_t *mobj; - fixed_t zheight; - - if (player->skincolor == 0) - return; - - if (player->spectator) - return; - - if (type == MT_GHOST) - mobj = P_SpawnGhostMobj(player->mo); // virtually does everything here for us - else - { - if (player->mo->eflags & MFE_VERTICALFLIP) - zheight = player->mo->z + player->mo->height + FixedDiv(P_GetPlayerHeight(player) - player->mo->height, 3*FRACUNIT) - FixedMul(mobjinfo[type].height, player->mo->scale); - else - zheight = player->mo->z - FixedDiv(P_GetPlayerHeight(player) - player->mo->height, 3*FRACUNIT); - - if (!(player->mo->eflags & MFE_VERTICALFLIP) && zheight < player->mo->floorz && !(mobjinfo[type].flags & MF_NOCLIPHEIGHT)) - zheight = player->mo->floorz; - else if (player->mo->eflags & MFE_VERTICALFLIP && zheight + FixedMul(mobjinfo[type].height, player->mo->scale) > player->mo->ceilingz && !(mobjinfo[type].flags & MF_NOCLIPHEIGHT)) - zheight = player->mo->ceilingz - FixedMul(mobjinfo[type].height, player->mo->scale); - - mobj = P_SpawnMobj(player->mo->x, player->mo->y, zheight, type); - - // set to player's angle, just in case - mobj->angle = player->mo->angle; - - // color and skin - mobj->color = player->mo->color; - mobj->skin = player->mo->skin; - - // vertical flip - if (player->mo->eflags & MFE_VERTICALFLIP) - mobj->flags2 |= MF2_OBJECTFLIP; - mobj->eflags |= (player->mo->eflags & MFE_VERTICALFLIP); - - // scale - P_SetScale(mobj, player->mo->scale); - mobj->destscale = player->mo->scale; - } - - P_SetTarget(&mobj->target, player->mo); // the one thing P_SpawnGhostMobj doesn't do -} - // // P_DoPlayerExit // @@ -3815,338 +3708,10 @@ void P_Telekinesis(player_t *player, fixed_t thrust, fixed_t range) } } - P_SpawnThokMobj(player); + //P_SpawnThokMobj(player); player->pflags |= PF_THOKKED; } -// -// P_DoJumpStuff -// -// Handles player jumping -// -static void P_DoJumpStuff(player_t *player, ticcmd_t *cmd) -{ - if (player->pflags & PF_JUMPSTASIS) - return; - - if (cmd->buttons & BT_BRAKE && !(player->pflags & PF_JUMPDOWN) && !player->exiting && !P_PlayerInPain(player)) - { - if (onground || player->climbing || player->pflags & (PF_CARRIED|PF_ITEMHANG|PF_ROPEHANG)) - {} - else if (player->pflags & PF_MACESPIN && player->mo->tracer) - {} - else if (!(player->pflags & PF_SLIDING) && ((gametype != GT_CTF) || (!player->gotflag))) - { -#ifdef HAVE_BLUA - if (!LUAh_JumpSpinSpecial(player)) -#endif - /*switch (player->charability) - { - case CA_TELEKINESIS: - if (player->pflags & PF_JUMPED) - { - if (!(player->pflags & PF_THOKKED) || (player->charability2 == CA2_MULTIABILITY)) - { - P_Telekinesis(player, - -FixedMul(player->actionspd, player->mo->scale), // -ve thrust (pulling towards player) - FixedMul(384*FRACUNIT, player->mo->scale)); - } - } - break; - case CA_AIRDRILL: - if (player->pflags & PF_JUMPED) - { - if (player->pflags & PF_THOKKED) // speed up falling down - { - if (player->secondjump < 42) - player->secondjump ++; - } - } - break; - default: - break; - }*/ - } - } - - /*if (player->charability == CA_AIRDRILL) - { - if (player->pflags & PF_JUMPED) - { - if (player->flyangle > 0 && player->pflags & PF_THOKKED) - { - player->flyangle--; - - P_SetObjectMomZ(player->mo, ((player->flyangle-24 - player->secondjump*3)*((player->actionspd>>FRACBITS)/12 + 1)<mo->eflags & MFE_UNDERWATER)) - P_InstaThrust(player->mo, player->mo->angle, FixedMul(player->normalspeed, player->mo->scale)*(80-player->flyangle - (player->actionspd>>FRACBITS)/2)/80); - else - P_InstaThrust(player->mo, player->mo->angle, ((FixedMul(player->normalspeed - player->actionspd/4, player->mo->scale))*2)/3); - } - } - }*/ - - if (cmd->buttons & BT_DRIFT && !player->exiting && !P_PlayerInPain(player)) - { -#ifdef HAVE_BLUA - if (LUAh_JumpSpecial(player)) - ; - else -#endif - if (player->pflags & PF_JUMPDOWN) // all situations below this require jump button not to be pressed already - ; - else - // Jump S3&K style while in quicksand. - if (P_InQuicksand(player->mo)) - { - //P_DoJump(player, true); - player->secondjump = 0; - player->pflags &= ~PF_THOKKED; - } - else - // can't jump while in air, can't jump while jumping - if (onground || player->climbing || player->pflags & (PF_CARRIED|PF_ITEMHANG|PF_ROPEHANG)) - { - //P_DoJump(player, true); - player->secondjump = 0; - player->pflags &= ~PF_THOKKED; - } - /* // SRB2kart - no jumpy power things - else if (player->pflags & PF_MACESPIN && player->mo->tracer) - { - player->pflags &= ~PF_MACESPIN; - player->powers[pw_flashing] = TICRATE/4; - } - else if (player->pflags & PF_SLIDING || (gametype == GT_CTF && player->gotflag)) - ; - else if (P_SuperReady(player)) - { - // If you can turn super and aren't already, - // and you don't have a shield, do it! - P_DoSuperTransformation(player, false); - } - else if (player->pflags & PF_JUMPED) - { -#ifdef HAVE_BLUA - if (!LUAh_AbilitySpecial(player)) -#endif - switch (player->charability) - { - case CA_THOK: - case CA_HOMINGTHOK: - case CA_JUMPTHOK: // Credit goes to CZ64 and Sryder13 for the original - // Now it's Sonic's abilities turn! - // THOK! - if (!(player->pflags & PF_THOKKED) || (player->charability2 == CA2_MULTIABILITY)) - { - // Catapult the player - fixed_t actionspd = player->actionspd; - if (player->mo->eflags & MFE_UNDERWATER) - actionspd >>= 1; - if ((player->charability == CA_JUMPTHOK) && !(player->pflags & PF_THOKKED)) - { - player->pflags &= ~PF_JUMPED; - P_DoJump(player, false); - } - P_InstaThrust(player->mo, player->mo->angle, FixedMul(actionspd, player->mo->scale)); - - if (maptol & TOL_2D) - { - player->mo->momx /= 2; - player->mo->momy /= 2; - } - else if (player->charability == CA_HOMINGTHOK) - { - player->mo->momx /= 3; - player->mo->momy /= 3; - } - - if (player->mo->info->attacksound && !player->spectator) - S_StartSound(player->mo, player->mo->info->attacksound); // Play the THOK sound - - P_SpawnThokMobj(player); - - if (player->charability == CA_HOMINGTHOK && !player->homing) - { - if (P_LookForEnemies(player)) - { - if (player->mo->tracer) - player->homing = 3*TICRATE; - } - } - - player->pflags &= ~(PF_SPINNING|PF_STARTDASH); - player->pflags |= PF_THOKKED; - } - break; - - case CA_FLY: - case CA_SWIM: // Swim - // If currently in the air from a jump, and you pressed the - // button again and have the ability to fly, do so! - if (player->charability == CA_SWIM && !(player->mo->eflags & MFE_UNDERWATER)) - ; // Can't do anything if you're a fish out of water! - else if (!(player->pflags & PF_THOKKED) && !(player->powers[pw_tailsfly])) - { - //P_SetPlayerMobjState(player->mo, S_PLAY_ABL1); // Change to the flying animation - - player->powers[pw_tailsfly] = tailsflytics + 1; // Set the fly timer - - player->pflags &= ~(PF_JUMPED|PF_SPINNING|PF_STARTDASH); - player->pflags |= PF_THOKKED; - } - break; - case CA_GLIDEANDCLIMB: - // Now Knuckles-type abilities are checked. - // If you can turn super and aren't already, - // and you don't have a shield, do it! - if (!(player->pflags & PF_THOKKED) || player->charability2 == CA2_MULTIABILITY) - { - INT32 glidespeed = player->actionspd; - - player->pflags |= PF_GLIDING|PF_THOKKED; - player->glidetime = 0; - - if (player->powers[pw_super] && ALL7EMERALDS(player->powers[pw_emeralds])) - { - // Glide at double speed while super. - glidespeed *= 2; - player->pflags &= ~PF_THOKKED; - } - - //P_SetPlayerMobjState(player->mo, S_PLAY_ABL1); - P_InstaThrust(player->mo, player->mo->angle, FixedMul(glidespeed, player->mo->scale)); - player->pflags &= ~(PF_SPINNING|PF_STARTDASH); - } - break; - case CA_DOUBLEJUMP: // Double-Jump - if (!(player->pflags & PF_THOKKED)) - { - player->pflags &= ~PF_JUMPED; - P_DoJump(player, true); - - // Allow infinite double jumping if super. - if (!player->powers[pw_super]) - player->pflags |= PF_THOKKED; - } - break; - case CA_FLOAT: // Float - case CA_SLOWFALL: // Slow descent hover - if (!player->secondjump) - player->secondjump = 1; - break; - case CA_TELEKINESIS: - if (!(player->pflags & PF_THOKKED) || player->charability2 == CA2_MULTIABILITY) - { - P_Telekinesis(player, - FixedMul(player->actionspd, player->mo->scale), // +ve thrust (pushing away from player) - FixedMul(384*FRACUNIT, player->mo->scale)); - } - break; - case CA_FALLSWITCH: - if (!(player->pflags & PF_THOKKED) || player->charability2 == CA2_MULTIABILITY) - { - player->mo->momz = -player->mo->momz; - P_SpawnThokMobj(player); - player->pflags |= PF_THOKKED; - } - break; - - case CA_AIRDRILL: - if (!(player->pflags & PF_THOKKED) || player->charability2 == CA2_MULTIABILITY) - { - player->flyangle = 56 + (60-(player->actionspd>>FRACBITS))/3; - player->pflags |= PF_THOKKED; - S_StartSound(player->mo, sfx_spndsh); - } - break; - default: - break; - } - } - else if (player->pflags & PF_THOKKED) - { -#ifdef HAVE_BLUA - if (!LUAh_AbilitySpecial(player)) -#endif - switch (player->charability) - { - case CA_FLY: - case CA_SWIM: // Swim - if (player->charability == CA_SWIM && !(player->mo->eflags & MFE_UNDERWATER)) - ; // Can't do anything if you're a fish out of water! - else if (player->powers[pw_tailsfly]) // If currently flying, give an ascend boost. - { - if (!player->fly1) - player->fly1 = 20; - else - player->fly1 = 2; - - if (player->charability == CA_SWIM) - player->fly1 /= 2; - - // Slow down! - if (player->speed > FixedMul(8*FRACUNIT, player->mo->scale) && player->speed > FixedMul(player->normalspeed>>1, player->mo->scale)) - P_Thrust(player->mo, R_PointToAngle2(0,0,player->mo->momx,player->mo->momy), FixedMul(-4*FRACUNIT, player->mo->scale)); - } - break; - default: - break; - } - } - else if ((player->powers[pw_shield] & SH_NOSTACK) == SH_JUMP && !player->powers[pw_super]) - P_DoJumpShield(player); - */ - } - - if (cmd->buttons & BT_DRIFT) - { - player->pflags |= PF_JUMPDOWN; - - if ((gametype != GT_CTF || !player->gotflag) && !player->exiting) - { - if (player->secondjump == 1) - { - /*if (player->charability == CA_FLOAT) - player->mo->momz = 0; - else if (player->charability == CA_SLOWFALL) - { - if (player->powers[pw_super]) - { - if (P_MobjFlip(player->mo)*player->mo->momz < gravity*16) - player->mo->momz = P_MobjFlip(player->mo)*gravity*16; //Float upward 4x as fast while super. - } - else if (P_MobjFlip(player->mo)*player->mo->momz < -gravity*4) - player->mo->momz = P_MobjFlip(player->mo)*-gravity*4; - }*/ - player->pflags &= ~PF_SPINNING; - } - } - } - else // If not pressing the jump button - { - player->pflags &= ~PF_JUMPDOWN; - - // Repeat abilities, but not double jump! - /*if ((player->charability2 == CA2_MULTIABILITY && player->charability != CA_DOUBLEJUMP) - || (player->powers[pw_super] && ALL7EMERALDS(player->powers[pw_emeralds]))) - player->secondjump = 0; - else if (player->charability == CA_FLOAT && player->secondjump == 1) - player->secondjump = 2;*/ - - - // If letting go of the jump button while still on ascent, cut the jump height. - if (player->pflags & PF_JUMPED && P_MobjFlip(player->mo)*player->mo->momz > 0 && player->jumping == 1) - { - player->mo->momz >>= 1; - player->jumping = 0; - } - } -} - boolean P_AnalogMove(player_t *player) { return player->pflags & PF_ANALOGMODE; @@ -6848,8 +6413,8 @@ static void P_MovePlayer(player_t *player) speed = R_PointToDist2(player->rmomx, player->rmomy, 0, 0); - if (speed > player->normalspeed-5*FRACUNIT) - speed = player->normalspeed-5*FRACUNIT; + if (speed > K_GetKartSpeed(player, false)-(5<= runnyspeed) player->fovadd = speed-runnyspeed; @@ -7404,7 +6969,7 @@ void P_HomingAttack(mobj_t *source, mobj_t *enemy) // Home in on your target dist = 1; if (source->type == MT_DETON && enemy->player) // For Deton Chase (Unused) - ns = FixedDiv(FixedMul(enemy->player->normalspeed, enemy->scale), FixedDiv(20*FRACUNIT,17*FRACUNIT)); + ns = FixedDiv(FixedMul(K_GetKartSpeed(enemy->player, false), enemy->scale), FixedDiv(20*FRACUNIT,17*FRACUNIT)); else if (source->type != MT_PLAYER) { if (source->threshold == 32000) @@ -7413,7 +6978,7 @@ void P_HomingAttack(mobj_t *source, mobj_t *enemy) // Home in on your target ns = FixedMul(source->info->speed, source->scale); } else if (source->player) - ns = FixedDiv(FixedMul(source->player->actionspd, source->scale), 3*FRACUNIT/2); + ns = FixedDiv(FixedMul(K_GetKartSpeed(source->player, false), source->scale), 3*FRACUNIT/2); source->momx = FixedMul(FixedDiv(enemy->x - source->x, dist), ns); source->momy = FixedMul(FixedDiv(enemy->y - source->y, dist), ns);