From 018d8f8769ea2a2281578fce6f61b3190333e592 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Mon, 3 Jun 2024 07:45:26 +1000 Subject: [PATCH] Revert camera changes to fix crashing plugins --- src/Camera.c | 20 +++++++++++++------- src/Camera.h | 6 +++--- src/EnvRenderer.c | 2 +- src/Game.c | 4 ++-- src/Queue.c | 3 ++- src/SystemFonts.c | 2 -- third_party/gldc/src/sh4.c | 2 +- 7 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/Camera.c b/src/Camera.c index 776fc2f95..10f7dc43d 100644 --- a/src/Camera.c +++ b/src/Camera.c @@ -42,15 +42,17 @@ static void PerspectiveCamera_GetProjection(struct Matrix* proj) { Gfx_CalcPerspectiveMatrix(proj, fovy, aspectRatio, (float)Game_ViewDistance); } -static void PerspectiveCamera_GetView(struct LocalPlayer* p, struct Matrix* mat) { +static void PerspectiveCamera_GetView(struct Matrix* mat) { Vec3 pos = Camera.CurrentPos; - Vec2 rot = Camera.Active->GetOrientation(p); + Vec2 rot = Camera.Active->GetOrientation(); Matrix_LookRot(mat, pos, rot); Matrix_MulBy(mat, &Camera.TiltM); } -static void PerspectiveCamera_GetPickedBlock(struct LocalPlayer* p, struct RayTracer* t) { - struct Entity* e = &p->Base; +static void PerspectiveCamera_GetPickedBlock(struct RayTracer* t) { + struct LocalPlayer* p = Entities.CurPlayer; + struct Entity* e = &p->Base; + Vec3 dir = Vec3_GetDirVector(e->Yaw * MATH_DEG2RAD, e->Pitch * MATH_DEG2RAD + Camera.TiltPitch); Vec3 eyePos = Entity_GetEyePosition(e); Picking_CalcPickedBlock(&eyePos, &dir, p->ReachDistance, t); @@ -146,8 +148,10 @@ static void PerspectiveCamera_CalcViewBobbing(struct LocalPlayer* p, float t, fl /*########################################################################################################################* *---------------------------------------------------First person camera---------------------------------------------------* *#########################################################################################################################*/ -static Vec2 FirstPersonCamera_GetOrientation(struct LocalPlayer* p) { +static Vec2 FirstPersonCamera_GetOrientation(void) { + struct LocalPlayer* p = Entities.CurPlayer; struct Entity* e = &p->Base; + Vec2 v; v.x = e->Yaw * MATH_DEG2RAD; v.y = e->Pitch * MATH_DEG2RAD; @@ -185,8 +189,10 @@ static struct Camera cam_FirstPerson = { #define DEF_ZOOM 3.0f static float dist_third = DEF_ZOOM, dist_forward = DEF_ZOOM; -static Vec2 ThirdPersonCamera_GetOrientation(struct LocalPlayer* p) { +static Vec2 ThirdPersonCamera_GetOrientation(void) { + struct LocalPlayer* p = Entities.CurPlayer; struct Entity* e = &p->Base; + Vec2 v; v.x = e->Yaw * MATH_DEG2RAD; v.y = e->Pitch * MATH_DEG2RAD; @@ -216,7 +222,7 @@ static Vec3 ThirdPersonCamera_GetPosition(float t) { target = Entity_GetEyePosition(e); target.y += Camera.BobbingVer; - rot = Camera.Active->GetOrientation(p); + rot = Camera.Active->GetOrientation(); dir = Vec3_GetDirVector(rot.x, rot.y); Vec3_Negate(&dir, &dir); diff --git a/src/Camera.h b/src/Camera.h index 04afda320..e4c17a2d9 100644 --- a/src/Camera.h +++ b/src/Camera.h @@ -46,10 +46,10 @@ struct Camera { /* Calculates the current projection matrix of this camera. */ void (*GetProjection)(struct Matrix* proj); /* Calculates the current modelview matrix of this camera. */ - void (*GetView)(struct LocalPlayer* p, struct Matrix* view); + void (*GetView)(struct Matrix* view); /* Returns the current orientation of the camera. */ - Vec2 (*GetOrientation)(struct LocalPlayer* p); + Vec2 (*GetOrientation)(void); /* Returns the current interpolated position of the camera. */ Vec3 (*GetPosition)(float t); @@ -64,7 +64,7 @@ struct Camera { void (*LoseFocus)(void); /* Calculates selected block in the world, based on camera's current state */ - void (*GetPickedBlock)(struct LocalPlayer* p, struct RayTracer* t); + void (*GetPickedBlock)(struct RayTracer* t); /* Zooms the camera in or out when scrolling mouse wheel. */ cc_bool (*Zoom)(float amount); diff --git a/src/EnvRenderer.c b/src/EnvRenderer.c index 6f5fcc35e..3f77a8647 100644 --- a/src/EnvRenderer.c +++ b/src/EnvRenderer.c @@ -326,7 +326,7 @@ void EnvRenderer_RenderSkybox(void) { /* Rotate around camera */ pos = Camera.CurrentPos; Vec3_Set(Camera.CurrentPos, 0,0,0); - Camera.Active->GetView(Entities.CurPlayer, &view); + Camera.Active->GetView(&view); Matrix_MulBy(&m, &view); Camera.CurrentPos = pos; diff --git a/src/Game.c b/src/Game.c index 194a18337..c88374481 100644 --- a/src/Game.c +++ b/src/Game.c @@ -483,7 +483,7 @@ void Game_SetFpsLimit(int method) { } static void UpdateViewMatrix(void) { - Camera.Active->GetView(Entities.CurPlayer, &Gfx.View); + Camera.Active->GetView(&Gfx.View); FrustumCulling_CalcFrustumEquations(&Gfx.Projection, &Gfx.View); } @@ -607,7 +607,7 @@ static CC_INLINE void Game_DrawFrame(float delta, float t) { UpdateViewMatrix(); if (!Gui_GetBlocksWorld()) { - Camera.Active->GetPickedBlock(Entities.CurPlayer, &Game_SelectedPos); /* TODO: only pick when necessary */ + Camera.Active->GetPickedBlock(&Game_SelectedPos); /* TODO: only pick when necessary */ Camera_KeyLookUpdate(delta); InputHandler_Tick(); diff --git a/src/Queue.c b/src/Queue.c index d12efba95..3c3b9cb5b 100644 --- a/src/Queue.c +++ b/src/Queue.c @@ -20,7 +20,8 @@ void Queue_Clear(struct Queue* queue) { } static void Queue_Resize(struct Queue* queue) { cc_uint8* entries; - int i, idx, capacity, headToEndSize, byteOffsetToHead; + int idx, capacity, headToEndSize, byteOffsetToHead; + if (queue->capacity >= (Int32_MaxValue / 4)) { Chat_AddRaw("&cToo many generic queue entries, clearing"); Queue_Clear(queue); diff --git a/src/SystemFonts.c b/src/SystemFonts.c index d2c9d9534..2add90332 100644 --- a/src/SystemFonts.c +++ b/src/SystemFonts.c @@ -289,8 +289,6 @@ size_t cc_strlen(const char* a) { } char* cc_strstr(const char* str, const char* substr) { - const char* a; - const char* b; if (!substr[0]) return (char*)str; for (; *str; str++) diff --git a/third_party/gldc/src/sh4.c b/third_party/gldc/src/sh4.c index 9f64ca47c..075ab71ba 100644 --- a/third_party/gldc/src/sh4.c +++ b/third_party/gldc/src/sh4.c @@ -449,7 +449,7 @@ void SceneListSubmit(Vertex* v3, int n) { *PVR_LMMODE1 = 0; //Set QACR registers - QACR[1] = QACR[0] = 0x10; + QACR[1] = QACR[0] = 0x11; #if CLIP_DEBUG Vertex* vertex = (Vertex*) src;