The two TArrays of type FTextureID skinIDs and surfaceskinIDs no longer have any null elements. These elements will have a textureid (FTextureID.texnum) of 0.

Re-worded error messages which were unprecise or unfitting before (model index below 0 was not acknowledged at all, or grouped together with a "too many models" message).

modelIDs are given a default value of -1.

Important: A MODELDEF's FrameIndex lines can no longer refer to model indices that are beyond the number of models of that MODELDEF entry. There is in fact a check to avoid going beyond the number of an actor's models which would abort program operation at startup, but it never caught any such occurances.

surfaceSkinIDs was two-dimensional and is now a one-dimensional TArray as well, elements are accessed via [Row + Column * NumRows], in this case surfaceIndex + modelIndex * MD3_MAX_SURFACES]
Used TArray.Alloc to make TArrays have the correct size depending on the number of models.

Also removed MAX_MODELS_PER_FRAME.
Edited skinSurfaceIDs access for one-dimensional TArray

Added MD3_MODELS_MIN
To ensure compatibility with mods, all model-related TArrays (four in total) have a minimum size of 4, defined by MD3_MODELS_MIN.
This commit is contained in:
Chernoskill 2021-02-09 14:48:43 +01:00 committed by Cherno
parent e0e0fb0d8f
commit fa2058004b
6 changed files with 87 additions and 29 deletions

View file

@ -638,9 +638,10 @@ void FOBJModel::RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int f
FGameTexture *userSkin = skin;
if (!userSkin)
{
if (i < MD3_MAX_SURFACES && curSpriteMDLFrame->surfaceskinIDs[curMDLIndex][i].isValid())
int ssIndex = i + curMDLIndex * MD3_MAX_SURFACES;
if (i < MD3_MAX_SURFACES && curSpriteMDLFrame->surfaceskinIDs[ssIndex].isValid())
{
userSkin = TexMan.GetGameTexture(curSpriteMDLFrame->surfaceskinIDs[curMDLIndex][i], true);
userSkin = TexMan.GetGameTexture(curSpriteMDLFrame->surfaceskinIDs[ssIndex], true);
}
else if (surf->skin.isValid())
{
@ -669,13 +670,14 @@ void FOBJModel::AddSkins(uint8_t* hitlist)
{
for (size_t i = 0; i < surfaces.Size(); i++)
{
if (i < MD3_MAX_SURFACES && curSpriteMDLFrame->surfaceskinIDs[curMDLIndex][i].isValid())
size_t ssIndex = i + curMDLIndex * MD3_MAX_SURFACES;
if (i < MD3_MAX_SURFACES && curSpriteMDLFrame->surfaceskinIDs[ssIndex].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[curMDLIndex][i].GetIndex()] |= FTextureManager::HIT_Flat;
hitlist[curSpriteMDLFrame->surfaceskinIDs[ssIndex].GetIndex()] |= FTextureManager::HIT_Flat;
return; // No need to precache skin that was replaced
}