diff --git a/include/rwsdk/rwplcore.h b/include/rwsdk/rwplcore.h index 80c5eba6d..9ae185e01 100644 --- a/include/rwsdk/rwplcore.h +++ b/include/rwsdk/rwplcore.h @@ -789,6 +789,23 @@ struct rwGameCube2DVertex RwRGBA emissiveColor; RwReal u; RwReal v; + + rwGameCube2DVertex& operator=(const rwGameCube2DVertex& rhs) + { + this->x = rhs.x; + this->y = rhs.y; + this->z = rhs.z; + + this->emissiveColor.red = rhs.emissiveColor.red; + this->emissiveColor.green = rhs.emissiveColor.green; + this->emissiveColor.blue = rhs.emissiveColor.blue; + this->emissiveColor.alpha = rhs.emissiveColor.alpha; + + this->u = rhs.u; + this->v = rhs.v; + + return *this; + } }; typedef rwGameCube2DVertex RwIm2DVertex; diff --git a/src/SB/Core/x/xBound.cpp b/src/SB/Core/x/xBound.cpp index 91e1e79da..bbb98c891 100644 --- a/src/SB/Core/x/xBound.cpp +++ b/src/SB/Core/x/xBound.cpp @@ -168,17 +168,17 @@ static void xBoundOBBIsectRay(const xBox* b, const xMat4x3* m, const xRay3* r, x { F32 len2 = SQR(m->right.x) + SQR(m->right.y) + SQR(m->right.z); - if ((F32)iabs(len2 - 1.0f) <= 0.0000099999997f) + if ((F32)iabs(len2 - 1.0f) <= 0.00001f) { // non-matching: incorrect instruction + order scale.x = 1.0f; - mnormal.right.x = m->right.x; - mnormal.right.y = m->right.y; - mnormal.right.z = m->right.z; + mnormal.right.x = SQR(m->right.x); + mnormal.right.y = SQR(m->right.y); + mnormal.right.z = SQR(m->right.z); } - else if ((F32)iabs(len2) <= 0.0000099999997f) + else if ((F32)iabs(len2) <= 0.00001f) { // non-matching: incorrect order @@ -203,17 +203,17 @@ static void xBoundOBBIsectRay(const xBox* b, const xMat4x3* m, const xRay3* r, x { F32 len2 = SQR(m->up.x) + SQR(m->up.y) + SQR(m->up.z); - if ((F32)iabs(len2 - 1.0f) <= 0.0000099999997f) + if ((F32)iabs(len2 - 1.0f) <= 0.00001f) { // non-matching: incorrect instruction + order scale.y = 1.0f; - mnormal.up.x = m->up.x; - mnormal.up.y = m->up.y; - mnormal.up.z = m->up.z; + mnormal.up.x = SQR(m->up.x); + mnormal.up.y = SQR(m->up.y); + mnormal.up.z = SQR(m->up.z); } - else if ((F32)iabs(len2) <= 0.0000099999997f) + else if ((F32)iabs(len2) <= 0.00001f) { // non-matching: incorrect order @@ -238,17 +238,17 @@ static void xBoundOBBIsectRay(const xBox* b, const xMat4x3* m, const xRay3* r, x { F32 len2 = SQR(m->at.x) + SQR(m->at.y) + SQR(m->at.z); - if ((F32)iabs(len2 - 1.0f) <= 0.0000099999997f) + if ((F32)iabs(len2 - 1.0f) <= 0.00001f) { // non-matching: incorrect instruction + order scale.z = 1.0f; - mnormal.at.x = m->at.x; - mnormal.at.y = m->at.y; - mnormal.at.z = m->at.z; + mnormal.at.x = SQR(m->at.x); + mnormal.at.y = SQR(m->at.y); + mnormal.at.z = SQR(m->at.z); } - else if ((F32)iabs(len2) <= 0.0000099999997f) + else if ((F32)iabs(len2) <= 0.00001f) { // non-matching: incorrect order diff --git a/src/SB/Core/x/xCamera.cpp b/src/SB/Core/x/xCamera.cpp index 791c0ba10..d04d64e09 100644 --- a/src/SB/Core/x/xCamera.cpp +++ b/src/SB/Core/x/xCamera.cpp @@ -1240,11 +1240,11 @@ F32 xrmod(F32 ang) xVec3& xVec3::operator/=(F32 f) { - F32 f2 = 1.0f; + F32 f2 = 1.0f / f; - this->x *= f2 / f; - this->y *= f2 / f; - this->z *= f2 / f; + this->x *= f2; + this->y *= f2; + this->z *= f2; return *this; } diff --git a/src/SB/Core/x/xFont.h b/src/SB/Core/x/xFont.h index 055fa11fa..88059f9a1 100644 --- a/src/SB/Core/x/xFont.h +++ b/src/SB/Core/x/xFont.h @@ -157,6 +157,45 @@ struct xtextbox static callback text_cb; + xtextbox& operator=(const xtextbox& rhs) + { + this->font.id = rhs.font.id; + + *(S32*)(&this->font.width) = *(S32*)(&rhs.font.width); + *(S32*)(&this->font.height) = *(S32*)(&rhs.font.height); + *(S32*)(&this->font.space) = *(S32*)(&rhs.font.space); + + *(S32*)(&this->font.color) = *(S32*)(&rhs.font.color); + + *(S32*)(&this->font.clip.x) = *(S32*)(&rhs.font.clip.x); + *(S32*)(&this->font.clip.y) = *(S32*)(&rhs.font.clip.y); + *(S32*)(&this->font.clip.w) = *(S32*)(&rhs.font.clip.w); + *(S32*)(&this->font.clip.h) = *(S32*)(&rhs.font.clip.h); + + *(S32*)(&this->bounds.x) = *(S32*)(&rhs.bounds.x); + *(S32*)(&this->bounds.y) = *(S32*)(&rhs.bounds.y); + *(S32*)(&this->bounds.w) = *(S32*)(&rhs.bounds.w); + *(S32*)(&this->bounds.h) = *(S32*)(&rhs.bounds.h); + + this->flags = rhs.flags; + + this->line_space = rhs.line_space; + this->tab_stop = rhs.tab_stop; + this->left_indent = rhs.left_indent; + this->right_indent = rhs.right_indent; + + this->cb = rhs.cb; + this->context = rhs.context; + this->texts = rhs.texts; + this->text_sizes = rhs.text_sizes; + this->texts_size = rhs.texts_size; + this->text.text = rhs.text.text; + this->text.size = rhs.text.size; + this->text_hash = rhs.text_hash; + + return *this; + } + static void text_render(const jot& j, const xtextbox& tb, F32 x, F32 y); static tag_entry_list read_tag(const substr& s); static tag_entry* find_entry(const tag_entry_list& el, const substr& name); diff --git a/src/SB/Core/x/xMath.cpp b/src/SB/Core/x/xMath.cpp index a1c64c580..a1bd2208b 100644 --- a/src/SB/Core/x/xMath.cpp +++ b/src/SB/Core/x/xMath.cpp @@ -237,6 +237,8 @@ F32 xDangleClamp(F32 a) void xAccelMove(F32& x, F32& v, F32 a, F32 dt, F32 endx, F32 maxv) { + // Todo: These variable names aren't all right. + F32 var_f31; F32 offset; F32 t1; F32 t2; @@ -248,28 +250,27 @@ void xAccelMove(F32& x, F32& v, F32 a, F32 dt, F32 endx, F32 maxv) F32 dx; F32 temp_f1_2; - F32 temp_f28; - F32 temp_f29; - F32 var_f0; - F32 var_f2; - F32 var_f31; - S32 var_r0; - S32 var_r0_2; - S32 var_r0_3; S32 var_r0_4; S32 var_r3_2; S32 var_r3_3; + S32 var_r0; + S32 var_r0_2; + S32 var_r0_3; + S32 var_r3; S32 var_r3_4; S32 var_r4; - S8 var_r3; + F32 var_f0; + F32 var_f2; + F32 temp_f29; + F32 temp_f28; temp_f29 = endx - x; - var_r3 = 1; + var_r3 = 1; // Possible missing debug subroutine if (!((F32)__fabs(v) < 0.001f)) { if (v < 0.0f) { - var_r4 = 1; + var_r4 = var_r3; } else { @@ -288,7 +289,7 @@ void xAccelMove(F32& x, F32& v, F32 a, F32 dt, F32 endx, F32 maxv) var_r3 = 0; } } - if (var_r3 != 0) + if (var_r3 & 0xff) { var_f31 = 1e38f; } @@ -309,14 +310,14 @@ void xAccelMove(F32& x, F32& v, F32 a, F32 dt, F32 endx, F32 maxv) oldv = v; newv = oldv + dv; - if ((F32)__fabs(newv) == maxv) + if ((F32)__fabs(newv) <= maxv) { v = newv; var_f0 = 0.5f * dv * dt; } else { - if ((F32)__fabs(oldv) == maxv) + if ((F32)__fabs(oldv) <= maxv) { v = range_limit(newv, -maxv, maxv); if (oldv != v) @@ -527,11 +528,14 @@ void xAccelStop(F32& x, F32& v, F32 a, F32 dt) void xFuncPiece_EndPoints(xFuncPiece* func, F32 pi, F32 pf, F32 fi, F32 ff) { - F32 xfinv; // from DWARF data + F32 xfinv; // from DWARF data + F32 df; // not from DWARF data func->end = pf - pi; + xfinv = (1.0f / func->end); + df = ff - fi; func->order = 1; func->coef[0] = fi; - func->coef[1] = (ff - fi) * (1.0f / func->end); + func->coef[1] = df * xfinv; xFuncPiece_ShiftPiece(func, func, -pi); } diff --git a/src/SB/Core/x/xMath3.cpp b/src/SB/Core/x/xMath3.cpp index 0daf9e6ea..d931e4fa4 100644 --- a/src/SB/Core/x/xMath3.cpp +++ b/src/SB/Core/x/xMath3.cpp @@ -94,43 +94,33 @@ void xMat3x3Euler(xMat3x3* m, F32 yaw, F32 pitch, F32 roll) /* xMat3x3RotC (xMat3x3 *, float, float, float, float) */ void xMat3x3RotC(xMat3x3* m, F32 _x, F32 _y, F32 _z, F32 t) { - F32 temp_f0; - F32 temp_f0_2; - F32 temp_f1; - F32 temp_f28; - F32 temp_f2; - F32 temp_f3; - F32 temp_f4; - F32 temp_f5; - F32 temp_f6; - F32 temp_f7; - F32 temp_f8; + F32 sin; + F32 cos; + F32 c; if (t == 0.0f) { xMat3x3Identity(m); return; } - temp_f28 = icos(t); - temp_f1 = isin(t); - temp_f5 = -temp_f1; - temp_f2 = 1.0f - temp_f28; - temp_f0 = temp_f2 * _x; - temp_f8 = temp_f2 * _z; - temp_f4 = temp_f2 * _y; - temp_f3 = _y * temp_f0; - temp_f6 = _x * temp_f8; - temp_f0_2 = (temp_f1 * _z) + temp_f3; - m->right.x = (_x * temp_f0) + temp_f28; - temp_f7 = _z * temp_f4; - m->right.y = temp_f0_2; - m->right.z = (temp_f5 * _y) + temp_f6; - m->up.x = (temp_f5 * _z) + temp_f3; - m->up.y = (_y * temp_f4) + temp_f28; - m->up.z = (temp_f1 * _x) + temp_f7; - m->at.x = (temp_f1 * _y) + temp_f6; - m->at.y = (temp_f5 * _x) + temp_f7; - m->at.z = (_z * temp_f8) + temp_f28; + + cos = icos(t); + sin = isin(t); + + c = 1.0f - cos; + + m->right.x = (c * _x * _x) + cos; + m->right.y = (sin * _z) + (c * _x * _y); + m->right.z = (-sin * _y) + (c * _z * _x); + + m->up.x = (-sin * _z) + (c * _x * _y); + m->up.y = (c * _y * _y) + cos; + m->up.z = (sin * _x) + (c * _y * _z); + + m->at.x = (sin * _y) + (c * _z * _x); + m->at.y = (-sin * _x) + (c * _y * _z); + m->at.z = (c * _z * _z) + cos; + m->flags = 0; } @@ -180,35 +170,13 @@ void xMat3x3Normalize(xMat3x3* o, const xMat3x3* m) /* xMat3x3Tolocal (xVec3 *, xMat3x3 const *, xVec3 const *) */ void xMat3x3Tolocal(xVec3* o, const xMat3x3* m, const xVec3* v) { - F32 temp_f0; - F32 temp_f0_2; - F32 temp_f1; - F32 temp_f1_2; - F32 temp_f29; - F32 temp_f2; - F32 temp_f30; - F32 temp_f31; - F32 temp_f6; - F32 temp_f7; - F32 temp_f8; - F32 temp_f8_2; - - temp_f1 = m->right.x; - temp_f0 = m->right.y; - temp_f2 = m->up.x; - temp_f1_2 = m->up.y; - temp_f8 = m->at.x; - temp_f0_2 = m->at.y; - temp_f6 = m->right.z; - temp_f7 = m->up.z; - temp_f8_2 = m->at.z; - temp_f31 = (temp_f6 * temp_f6) + ((temp_f1 * temp_f1) + (temp_f0 * temp_f0)); - temp_f30 = (temp_f7 * temp_f7) + ((temp_f2 * temp_f2) + (temp_f1_2 * temp_f1_2)); - temp_f29 = (temp_f8_2 * temp_f8_2) + ((temp_f8 * temp_f8) + (temp_f0_2 * temp_f0_2)); + F32 sumRt = (m->right.x * m->right.x) + (m->right.y * m->right.y) + (m->right.z * m->right.z); + F32 sumUp = (m->up.x * m->up.x) + (m->up.y * m->up.y) + (m->up.z * m->up.z); + F32 sumAt = (m->at.x * m->at.x) + (m->at.y * m->at.y) + (m->at.z * m->at.z); xMat3x3LMulVec(o, m, v); - o->x /= temp_f31; - o->y /= temp_f30; - o->z /= temp_f29; + o->x /= sumRt; + o->y /= sumUp; + o->z /= sumAt; } /* xMat4x3MoveLocalRight (xMat4x3 *, float) */ @@ -720,4 +688,10 @@ void xBoxUnion(xBox& a, const xBox& b, const xBox& c) void xMat3x3LMulVec(xVec3* o, const xMat3x3* m, const xVec3* v) { + F32 y = (m->up.x * v->x) + (m->up.y * v->y) + (m->up.z * v->z); + F32 z = (m->at.x * v->x) + (m->at.y * v->y) + (m->at.z * v->z); + + o->x = (m->right.x * v->x) + (m->right.y * v->y) + (m->right.z * v->z); + o->y = y; + o->z = z; } diff --git a/src/SB/Core/x/xMath3.h b/src/SB/Core/x/xMath3.h index c7cc0d56c..8918ca533 100644 --- a/src/SB/Core/x/xMath3.h +++ b/src/SB/Core/x/xMath3.h @@ -28,6 +28,16 @@ struct xSphere { xVec3 center; F32 r; + + xSphere& operator=(const xSphere& rhs) + { + *(S32*)(&this->center.x) = *(S32*)(&rhs.center.x); + *(S32*)(&this->center.y) = *(S32*)(&rhs.center.y); + *(S32*)(&this->center.z) = *(S32*)(&rhs.center.z); + this->r = rhs.r; + + return *this; + } }; // Size: 0x18 @@ -35,6 +45,19 @@ struct xBox { xVec3 upper; xVec3 lower; + + xBox& operator=(const xBox& rhs) + { + *(S32*)(&this->upper.x) = *(S32*)(&rhs.upper.x); + *(S32*)(&this->upper.y) = *(S32*)(&rhs.upper.y); + *(S32*)(&this->upper.z) = *(S32*)(&rhs.upper.z); + + *(S32*)(&this->lower.x) = *(S32*)(&rhs.lower.x); + *(S32*)(&this->lower.y) = *(S32*)(&rhs.lower.y); + *(S32*)(&this->lower.z) = *(S32*)(&rhs.lower.z); + + return *this; + } }; struct xBBox @@ -54,6 +77,16 @@ struct xQuat { xVec3 v; F32 s; + + xQuat& operator=(const xQuat& rhs) + { + *(S32*)(&this->v.x) = *(S32*)(&rhs.v.x); + *(S32*)(&this->v.y) = *(S32*)(&rhs.v.y); + *(S32*)(&this->v.z) = *(S32*)(&rhs.v.z); + this->s = rhs.s; + + return *this; + } }; struct xVec4 diff --git a/src/SB/Game/zNPCTypeTiki.cpp b/src/SB/Game/zNPCTypeTiki.cpp index e94226abd..ea9fa81bd 100644 --- a/src/SB/Game/zNPCTypeTiki.cpp +++ b/src/SB/Game/zNPCTypeTiki.cpp @@ -67,7 +67,7 @@ void zNPCTiki_InitStacking(zScene* zsc) { tiki->FindParents(zsc); - if (tiki->numParents == 0) + if (*(U8*)(&tiki->numParents) == 0) { F32 dh = tiki->landHt - tiki->bound.box.box.lower.y; @@ -266,18 +266,20 @@ void zNPCTiki::Reset() timeToLive = 0.0f; tikiFlag = 0; - for (int i = 0; i < sizeof(parents[0]); i++) - { - parents[i] = NULL; - } - numParents = 0; + + parents[0] = NULL; + parents[1] = NULL; + parents[2] = NULL; + parents[3] = NULL; + *(U8*)(&numParents) = 0; // needs to store as byte contactParent = 0xffffffff; - for (int i = 0; i < sizeof(children[0]); i++) - { - children[i] = NULL; - } - numChildren = 0; + children[0] = NULL; + children[1] = NULL; + children[2] = NULL; + children[3] = NULL; + *(U8*)(&numChildren) = 0; // needs to store as byte + vel = 0.0f; nonTikiParent = NULL; @@ -1190,12 +1192,12 @@ static void genericTikiRender(xEnt* ent) } F32 dot = 2.0f; + xVec3 tmp; if ((globals.player.ControlOff & 0x23f3) == 0) { - xVec3* tmp = NULL; - xVec3Sub(tmp, &ent->bound.box.center, &globals.camera.mat.pos); - dot = xVec3Dot(tmp, &globals.camera.mat.at); + xVec3Sub(&tmp, &ent->bound.box.center, &globals.camera.mat.pos); + dot = xVec3Dot(&tmp, &globals.camera.mat.at); } if (dot < 1.5f) @@ -1217,7 +1219,7 @@ static void genericTikiRender(xEnt* ent) return; } - xModelRender(ent->model->Next); + xModelRender(ent->model); } // WIP