From 0e111ae151e7b147ceaf57d2072d2e785856e02d Mon Sep 17 00:00:00 2001
From: Christoph Oelckers <coelckers@users.noreply.github.com>
Date: Sun, 6 Nov 2022 10:25:37 +0100
Subject: [PATCH] - changed CalculateBones to receive the bone component data
 directly instead of the owning actor.

Since the backend also gets used by Raze it may not access Doom game data.
---
 src/common/models/model.h        |  3 +--
 src/common/models/model_iqm.h    |  2 +-
 src/common/models/models_iqm.cpp | 20 ++++++++++----------
 3 files changed, 12 insertions(+), 13 deletions(-)

diff --git a/src/common/models/model.h b/src/common/models/model.h
index 3f613d6f4..a849b8ba7 100644
--- a/src/common/models/model.h
+++ b/src/common/models/model.h
@@ -5,7 +5,6 @@
 #include "i_modelvertexbuffer.h"
 #include "matrix.h"
 #include "TRS.h"
-#include "d_player.h"
 
 class FModelRenderer;
 class FGameTexture;
@@ -77,7 +76,7 @@ public:
 	virtual void AddSkins(uint8_t *hitlist, const FTextureID* surfaceskinids) = 0;
 	virtual float getAspectFactor(float vscale) { return 1.f; }
 	virtual const TArray<TRS>* AttachAnimationData() { return nullptr; };
-	virtual const TArray<VSMatrix> CalculateBones(int frame1, int frame2, double inter, const TArray<TRS>& animationData, AActor* actor, int index) { return {}; };
+	virtual const TArray<VSMatrix> CalculateBones(int frame1, int frame2, double inter, const TArray<TRS>& animationData, DBoneComponents* bones, int index) { return {}; };
 
 	void SetVertexBuffer(int type, IModelVertexBuffer *buffer) { mVBuf[type] = buffer; }
 	IModelVertexBuffer *GetVertexBuffer(int type) const { return mVBuf[type]; }
diff --git a/src/common/models/model_iqm.h b/src/common/models/model_iqm.h
index 21f8338e9..5b6aad4ce 100644
--- a/src/common/models/model_iqm.h
+++ b/src/common/models/model_iqm.h
@@ -113,7 +113,7 @@ public:
 	void BuildVertexBuffer(FModelRenderer* renderer) override;
 	void AddSkins(uint8_t* hitlist, const FTextureID* surfaceskinids) override;
 	const TArray<TRS>* AttachAnimationData() override;
-	const TArray<VSMatrix> CalculateBones(int frame1, int frame2, double inter, const TArray<TRS>& animationData, AActor* actor, int index) override;
+	const TArray<VSMatrix> CalculateBones(int frame1, int frame2, double inter, const TArray<TRS>& animationData, DBoneComponents* bones, int index) override;
 
 private:
 	void LoadGeometry();
diff --git a/src/common/models/models_iqm.cpp b/src/common/models/models_iqm.cpp
index 9ded3df01..a743db6c2 100644
--- a/src/common/models/models_iqm.cpp
+++ b/src/common/models/models_iqm.cpp
@@ -510,17 +510,17 @@ const TArray<TRS>* IQMModel::AttachAnimationData()
 	return &TRSData;
 }
 
-const TArray<VSMatrix> IQMModel::CalculateBones(int frame1, int frame2, double inter, const TArray<TRS>& animationData, AActor* actor, int index)
+const TArray<VSMatrix> IQMModel::CalculateBones(int frame1, int frame2, double inter, const TArray<TRS>& animationData, DBoneComponents* boneComponentData, int index)
 {
 	const TArray<TRS>& animationFrames = &animationData ? animationData : TRSData;
 	if (Joints.Size() > 0)
 	{
 		int numbones = Joints.Size();
 
-		if (actor->boneComponentData->trscomponents[index].Size() != numbones)
-			actor->boneComponentData->trscomponents[index].Resize(numbones);
-		if (actor->boneComponentData->trsmatrix[index].Size() != numbones)
-			actor->boneComponentData->trsmatrix[index].Resize(numbones);
+		if (boneComponentData->trscomponents[index].Size() != numbones)
+			boneComponentData->trscomponents[index].Resize(numbones);
+		if (boneComponentData->trsmatrix[index].Size() != numbones)
+			boneComponentData->trsmatrix[index].Resize(numbones);
 
 		frame1 = clamp(frame1, 0, ((int)animationFrames.Size() - 1) / numbones);
 		frame2 = clamp(frame2, 0, ((int)animationFrames.Size() - 1) / numbones);
@@ -556,18 +556,18 @@ const TArray<VSMatrix> IQMModel::CalculateBones(int frame1, int frame2, double i
 
 			if (Joints[i].Parent >= 0 && modifiedBone[Joints[i].Parent])
 			{
-				actor->boneComponentData->trscomponents[index][i] = bone;
+				boneComponentData->trscomponents[index][i] = bone;
 				modifiedBone[i] = true;
 			}
-			else if (actor->boneComponentData->trscomponents[index][i].Equals(bone))
+			else if (boneComponentData->trscomponents[index][i].Equals(bone))
 			{
-				bones[i] = actor->boneComponentData->trsmatrix[index][i];
+				bones[i] = boneComponentData->trsmatrix[index][i];
 				modifiedBone[i] = false;
 				continue;
 			}
 			else
 			{
-				actor->boneComponentData->trscomponents[index][i] = bone;
+				boneComponentData->trscomponents[index][i] = bone;
 				modifiedBone[i] = true;
 			}
 
@@ -595,7 +595,7 @@ const TArray<VSMatrix> IQMModel::CalculateBones(int frame1, int frame2, double i
 			result.multMatrix(swapYZ);
 		}
 
-		actor->boneComponentData->trsmatrix[index] = bones;
+		boneComponentData->trsmatrix[index] = bones;
 
 		return bones;
 	}