- got rid of the state variables in the model class entirely.

This is *not* the right way to reduce function parameter count. The data in question is far easier evaluated at the calling site and passed as a parameter.
This commit is contained in:
Christoph Oelckers 2022-07-23 10:35:01 +02:00
parent 76c8214d67
commit 9875850c19
13 changed files with 43 additions and 53 deletions

View file

@ -61,19 +61,15 @@ public:
virtual bool Load(const char * fn, int lumpnum, const char * buffer, int length) = 0;
virtual int FindFrame(const char * name) = 0;
virtual void RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int frame, int frame2, double inter, int translation, const TArray<FTextureID>& surfaceskinids) = 0;
virtual void RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int frame, int frame2, double inter, int translation, const FTextureID* surfaceskinids) = 0;
virtual void BuildVertexBuffer(FModelRenderer *renderer) = 0;
virtual void AddSkins(uint8_t *hitlist) = 0;
virtual void AddSkins(uint8_t *hitlist, const FTextureID* surfaceskinids) = 0;
virtual float getAspectFactor(float vscale) { return 1.f; }
void SetVertexBuffer(int type, IModelVertexBuffer *buffer) { mVBuf[type] = buffer; }
IModelVertexBuffer *GetVertexBuffer(int type) const { return mVBuf[type]; }
void DestroyVertexBuffer();
const FSpriteModelFrame* curSpriteMDLFrame;
int curMDLIndex;
void PushSpriteMDLFrame(const FSpriteModelFrame *smf, int index) { curSpriteMDLFrame = smf; curMDLIndex = index; };
FString mFileName;
private:

View file

@ -59,8 +59,8 @@ public:
bool Load(const char * fn, int lumpnum, const char * buffer, int length) override;
void Initialize();
virtual int FindFrame(const char * name) override;
virtual void RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int frame, int frame2, double inter, int translation, const TArray<FTextureID>& surfaceskinids) override;
virtual void AddSkins(uint8_t *hitlist) override;
virtual void RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int frame, int frame2, double inter, int translation, const FTextureID* surfaceskinids) override;
virtual void AddSkins(uint8_t *hitlist, const FTextureID* surfaceskinids) override;
FTextureID GetPaletteTexture() const { return mPalette; }
void BuildVertexBuffer(FModelRenderer *renderer) override;
float getAspectFactor(float vscale) override;

View file

@ -111,11 +111,11 @@ public:
}
virtual ~FDMDModel();
virtual bool Load(const char * fn, int lumpnum, const char * buffer, int length);
virtual int FindFrame(const char * name);
virtual void RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int frame, int frame2, double inter, int translation, const TArray<FTextureID>& surfaceskinids);
virtual bool Load(const char * fn, int lumpnum, const char * buffer, int length) override;
virtual int FindFrame(const char * name) override;
virtual void RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int frame, int frame2, double inter, int translation, const FTextureID* surfaceskinids) override;
virtual void LoadGeometry();
virtual void AddSkins(uint8_t *hitlist);
virtual void AddSkins(uint8_t *hitlist, const FTextureID* surfaceskinids) override;
void UnloadGeometry();
void BuildVertexBuffer(FModelRenderer *renderer);

View file

@ -65,11 +65,11 @@ class FMD3Model : public FModel
public:
FMD3Model() = default;
virtual bool Load(const char * fn, int lumpnum, const char * buffer, int length);
virtual int FindFrame(const char * name);
virtual void RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int frame, int frame2, double inter, int translation, const TArray<FTextureID>& surfaceskinids);
virtual bool Load(const char * fn, int lumpnum, const char * buffer, int length) override;
virtual int FindFrame(const char * name) override;
virtual void RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int frame, int frame2, double inter, int translation, const FTextureID* surfaceskinids) override;
void LoadGeometry();
void BuildVertexBuffer(FModelRenderer *renderer);
virtual void AddSkins(uint8_t *hitlist);
virtual void AddSkins(uint8_t *hitlist, const FTextureID* surfaceskinids) override;
};

View file

@ -98,9 +98,9 @@ public:
~FOBJModel();
bool Load(const char* fn, int lumpnum, const char* buffer, int length) override;
int FindFrame(const char* name) override;
void RenderFrame(FModelRenderer* renderer, FGameTexture* skin, int frame, int frame2, double inter, int translation, const TArray<FTextureID>& surfaceskinids) override;
void RenderFrame(FModelRenderer* renderer, FGameTexture* skin, int frame, int frame2, double inter, int translation, const FTextureID* surfaceskinids) override;
void BuildVertexBuffer(FModelRenderer* renderer) override;
void AddSkins(uint8_t* hitlist) override;
void AddSkins(uint8_t* hitlist, const FTextureID* surfaceskinids) override;
};
#endif

View file

@ -26,9 +26,9 @@ public:
bool Load(const char * fn, int lumpnum, const char * buffer, int length) override;
int FindFrame(const char * name) override;
void RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int frame, int frame2, double inter, int translation, const TArray<FTextureID>& surfaceskinids) override;
void RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int frame, int frame2, double inter, int translation, const FTextureID* surfaceskinids) override;
void BuildVertexBuffer(FModelRenderer *renderer) override;
void AddSkins(uint8_t *hitlist) override;
void AddSkins(uint8_t *hitlist, const FTextureID* surfaceskinids) override;
void LoadGeometry();
void UnloadGeometry();
FUE1Model()

View file

@ -332,7 +332,7 @@ void FDMDModel::BuildVertexBuffer(FModelRenderer *renderer)
//
//===========================================================================
void FDMDModel::AddSkins(uint8_t *hitlist)
void FDMDModel::AddSkins(uint8_t *hitlist, const FTextureID*)
{
for (int i = 0; i < info.numSkins; i++)
{
@ -363,7 +363,7 @@ int FDMDModel::FindFrame(const char * name)
//
//===========================================================================
void FDMDModel::RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int frameno, int frameno2, double inter, int translation, const TArray<FTextureID>&)
void FDMDModel::RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int frameno, int frameno2, double inter, int translation, const FTextureID*)
{
if (frameno >= info.numFrames || frameno2 >= info.numFrames) return;

View file

@ -302,14 +302,13 @@ void FMD3Model::BuildVertexBuffer(FModelRenderer *renderer)
//
//===========================================================================
void FMD3Model::AddSkins(uint8_t *hitlist)
void FMD3Model::AddSkins(uint8_t *hitlist, const FTextureID* surfaceskinids)
{
for (unsigned i = 0; i < Surfaces.Size(); i++)
{
int ssIndex = i + curMDLIndex * MD3_MAX_SURFACES;
if (curSpriteMDLFrame && curSpriteMDLFrame->surfaceskinIDs[ssIndex].isValid())
if (surfaceskinids && surfaceskinids[i].isValid())
{
hitlist[curSpriteMDLFrame->surfaceskinIDs[ssIndex].GetIndex()] |= FTextureManager::HIT_Flat;
hitlist[surfaceskinids[i].GetIndex()] |= FTextureManager::HIT_Flat;
}
MD3Surface * surf = &Surfaces[i];
@ -344,7 +343,7 @@ int FMD3Model::FindFrame(const char * name)
//
//===========================================================================
void FMD3Model::RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int frameno, int frameno2, double inter, int translation, const TArray<FTextureID>& surfaceskinids)
void FMD3Model::RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int frameno, int frameno2, double inter, int translation, const FTextureID* surfaceskinids)
{
if ((unsigned)frameno >= Frames.Size() || (unsigned)frameno2 >= Frames.Size()) return;
@ -358,10 +357,9 @@ void FMD3Model::RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int f
FGameTexture *surfaceSkin = skin;
if (!surfaceSkin)
{
int ssIndex = i + curMDLIndex * MD3_MAX_SURFACES;
if (surfaceskinids[ssIndex].isValid())
if (surfaceskinids && surfaceskinids[i].isValid())
{
surfaceSkin = TexMan.GetGameTexture(surfaceskinids[ssIndex], true);
surfaceSkin = TexMan.GetGameTexture(surfaceskinids[i], true);
}
else if (surf->numSkins > 0 && surf->Skins[0].isValid())
{

View file

@ -628,7 +628,7 @@ int FOBJModel::FindFrame(const char* name)
* @param inter The amount to interpolate the two frames.
* @param translation The translation for the skin
*/
void FOBJModel::RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int frameno, int frameno2, double inter, int translation, const TArray<FTextureID>& surfaceskinids)
void FOBJModel::RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int frameno, int frameno2, double inter, int translation, const FTextureID* surfaceskinids)
{
// Prevent the model from rendering if the frame number is < 0
if (frameno < 0 || frameno2 < 0) return;
@ -640,10 +640,9 @@ void FOBJModel::RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int f
FGameTexture *userSkin = skin;
if (!userSkin)
{
int ssIndex = i + curMDLIndex * MD3_MAX_SURFACES;
if (i < MD3_MAX_SURFACES && surfaceskinids[ssIndex].isValid())
if (surfaceskinids && surfaceskinids[i].isValid())
{
userSkin = TexMan.GetGameTexture(surfaceskinids[ssIndex], true);
userSkin = TexMan.GetGameTexture(surfaceskinids[i], true);
}
else if (surf->skin.isValid())
{
@ -668,18 +667,17 @@ void FOBJModel::RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int f
*
* @param hitlist The list of textures
*/
void FOBJModel::AddSkins(uint8_t* hitlist)
void FOBJModel::AddSkins(uint8_t* hitlist, const FTextureID* surfaceskinids)
{
for (size_t i = 0; i < surfaces.Size(); i++)
{
size_t ssIndex = i + curMDLIndex * MD3_MAX_SURFACES;
if (curSpriteMDLFrame && i < MD3_MAX_SURFACES && curSpriteMDLFrame->surfaceskinIDs[ssIndex].isValid())
if (surfaceskinids && i < MD3_MAX_SURFACES && surfaceskinids[i].isValid())
{
// Precache skins manually reassigned by the user.
// On OBJs with lots of skins, such as Doom map OBJs exported from GZDB,
// there may be too many skins for the user to manually change, unless
// the limit is bumped or surfaceskinIDs is changed to a TArray<FTextureID>.
hitlist[curSpriteMDLFrame->surfaceskinIDs[ssIndex].GetIndex()] |= FTextureManager::HIT_Flat;
hitlist[surfaceskinids[i].GetIndex()] |= FTextureManager::HIT_Flat;
return; // No need to precache skin that was replaced
}

View file

@ -227,7 +227,7 @@ int FUE1Model::FindFrame( const char *name )
return -1;
}
void FUE1Model::RenderFrame( FModelRenderer *renderer, FGameTexture *skin, int frame, int frame2, double inter, int translation, const TArray<FTextureID>& surfaceskinids)
void FUE1Model::RenderFrame( FModelRenderer *renderer, FGameTexture *skin, int frame, int frame2, double inter, int translation, const FTextureID* surfaceskinids)
{
// the moment of magic
if ( (frame >= numFrames) || (frame2 >= numFrames) ) return;
@ -246,9 +246,8 @@ void FUE1Model::RenderFrame( FModelRenderer *renderer, FGameTexture *skin, int f
FGameTexture *sskin = skin;
if ( !sskin )
{
int ssIndex = groups[i].texNum + curMDLIndex * MD3_MAX_SURFACES;
if (surfaceskinids[ssIndex].isValid())
sskin = TexMan.GetGameTexture(surfaceskinids[ssIndex], true);
if (surfaceskinids && surfaceskinids[i].isValid())
sskin = TexMan.GetGameTexture(surfaceskinids[i], true);
if ( !sskin )
{
vofs += vsize;
@ -305,13 +304,12 @@ void FUE1Model::BuildVertexBuffer( FModelRenderer *renderer )
vbuf->UnlockVertexBuffer();
}
void FUE1Model::AddSkins( uint8_t *hitlist )
void FUE1Model::AddSkins( uint8_t *hitlist, const FTextureID* surfaceskinids)
{
for (int i = 0; i < numGroups; i++)
{
int ssIndex = groups[i].texNum + curMDLIndex * MD3_MAX_SURFACES;
if (curSpriteMDLFrame && curSpriteMDLFrame->surfaceskinIDs[ssIndex].isValid())
hitlist[curSpriteMDLFrame->surfaceskinIDs[ssIndex].GetIndex()] |= FTextureManager::HIT_Flat;
if (surfaceskinids && surfaceskinids[i].isValid())
hitlist[surfaceskinids[i].GetIndex()] |= FTextureManager::HIT_Flat;
}
}

View file

@ -356,7 +356,7 @@ void FVoxelModel::BuildVertexBuffer(FModelRenderer *renderer)
//
//===========================================================================
void FVoxelModel::AddSkins(uint8_t *hitlist)
void FVoxelModel::AddSkins(uint8_t *hitlist, const FTextureID*)
{
hitlist[mPalette.GetIndex()] |= FTextureManager::HIT_Flat;
}
@ -400,7 +400,7 @@ float FVoxelModel::getAspectFactor(float stretch)
//
//===========================================================================
void FVoxelModel::RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int frame, int frame2, double inter, int translation, const TArray<FTextureID>&)
void FVoxelModel::RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int frame, int frame2, double inter, int translation, const FTextureID*)
{
renderer->SetMaterial(skin, true, translation);
renderer->SetupFrame(this, 0, 0, 0);

View file

@ -339,12 +339,13 @@ void RenderFrameModels(FModelRenderer *renderer, FLevelLocals *Level, const FSpr
auto tex = skinid.isValid() ? TexMan.GetGameTexture(skinid, true) : nullptr;
mdl->BuildVertexBuffer(renderer);
mdl->PushSpriteMDLFrame(smf, i);
auto& ssids = surfaceskinids.Size() > 0 ? surfaceskinids : smf->surfaceskinIDs;
auto ssidp = (unsigned)(i * MD3_MAX_SURFACES) < ssids.Size() ? &ssids[i * MD3_MAX_SURFACES] : nullptr;
if (smfNext && modelframe != modelframenext)
mdl->RenderFrame(renderer, tex, modelframe, modelframenext, inter, translation, surfaceskinids.Size() > 0? surfaceskinids : smf->surfaceskinIDs);
mdl->RenderFrame(renderer, tex, modelframe, modelframenext, inter, translation, ssidp);
else
mdl->RenderFrame(renderer, tex, modelframe, modelframe, 0.f, translation, surfaceskinids.Size() > 0 ? surfaceskinids : smf->surfaceskinIDs);
mdl->RenderFrame(renderer, tex, modelframe, modelframe, 0.f, translation, ssidp);
}
}
}

View file

@ -170,8 +170,7 @@ void hw_PrecacheTexture(uint8_t *texhitlist, TMap<PClassActor*, bool> &actorhitl
}
else if (smf->modelIDs[i] != -1)
{
Models[smf->modelIDs[i]]->PushSpriteMDLFrame(smf, i);
Models[smf->modelIDs[i]]->AddSkins(texhitlist);
Models[smf->modelIDs[i]]->AddSkins(texhitlist, (unsigned)(i * MD3_MAX_SURFACES) < smf->surfaceskinIDs.Size()? &smf->surfaceskinIDs[i * MD3_MAX_SURFACES] : nullptr);
}
if (smf->modelIDs[i] != -1)
{