Skip to content

Commit

Permalink
Don't check if the TIKI model exists when initializing a static model
Browse files Browse the repository at this point in the history
In later version like 2.0 and above, the TIKI model can be registered before static models which would prevent static xyz to be initialized
  • Loading branch information
smallmodel authored Dec 18, 2024
1 parent bd021b1 commit 58bef33
Showing 1 changed file with 83 additions and 85 deletions.
168 changes: 83 additions & 85 deletions code/renderergl1/tr_staticmodels.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
===========================================================================
Copyright (C) 2015-2024 the OpenMoHAA team
Copyright (C) 2024 the OpenMoHAA team
This file is part of OpenMoHAA source code.
Expand Down Expand Up @@ -41,7 +41,6 @@ void R_InitStaticModels(void)
{
cStaticModelUnpacked_t *pSM;
char szTemp[1024];
bool exists;
skelBoneCache_t bones[128];
float radius;
int i, j, k, l;
Expand Down Expand Up @@ -87,7 +86,7 @@ void R_InitStaticModels(void)
}

ri.FS_CanonicalFilename(szTemp);
exists = ri.TIKI_FindTiki(szTemp) != NULL;
//const bool exists = ri.TIKI_FindTiki(szTemp) != NULL;
pSM->tiki = ri.TIKI_RegisterTikiFlags(szTemp, qfalse);

if (!pSM->tiki) {
Expand All @@ -106,12 +105,7 @@ void R_InitStaticModels(void)
for (k = 0; k < surf->numskins; k++) {
if (surf->shader[k][0]) {
shader_t *sh = R_FindShader(
surf->shader[k],
-1,
!(surf->flags & TIKI_SURF_NOMIPMAPS),
r_picmip->integer,
qtrue,
qtrue
surf->shader[k], -1, !(surf->flags & TIKI_SURF_NOMIPMAPS), r_picmip->integer, qtrue, qtrue
);
surf->hShader[k] = sh->index;
} else {
Expand All @@ -127,91 +121,96 @@ void R_InitStaticModels(void)
// Suggestion:
// It would be cool to have animated static model in the future

if (!exists) {
for (j = 0; j < pSM->tiki->numMeshes; j++) {
skelHeaderGame_t *skelmodel = ri.TIKI_GetSkel(pSM->tiki->mesh[j]);
skelSurfaceGame_t *surf;
// Removed in 2.0
// This only leads to issues where pStaticXyz is not initialized
// and it can occurs if the TIKI model is registered before the static model
//if (exists) {
// continue;
//}

if (!skelmodel) {
ri.Printf(PRINT_WARNING, "^~^~^: Warning: Missing mesh in Static Model %s\n", skelmodel->name);
continue;
}
for (j = 0; j < pSM->tiki->numMeshes; j++) {
skelHeaderGame_t *skelmodel = ri.TIKI_GetSkel(pSM->tiki->mesh[j]);
skelSurfaceGame_t *surf;

surf = skelmodel->pSurfaces;
if (!skelmodel) {
ri.Printf(PRINT_WARNING, "^~^~^: Warning: Missing mesh in Static Model %s\n", skelmodel->name);
continue;
}

for (k = 0; k < skelmodel->numSurfaces; k++, surf = surf->pNext) {
byte *buf;
byte *p;
skelWeight_t *weight;
skeletorVertex_t *vert;
surf = skelmodel->pSurfaces;

if (surf->pStaticXyz) {
continue;
}
for (k = 0; k < skelmodel->numSurfaces; k++, surf = surf->pNext) {
byte *buf;
byte *p;
skelWeight_t *weight;
skeletorVertex_t *vert;

// allocate static vectors
p = buf =
(byte *)ri.TIKI_Alloc((sizeof(vec4_t) + sizeof(vec4_t) + sizeof(vec2_t) * 2) * surf->numVerts);
surf->pStaticXyz = (vec4_t *)p;
p += sizeof(vec4_t) * surf->numVerts;
surf->pStaticNormal = (vec4_t *)p;
p += sizeof(vec4_t) * surf->numVerts;
surf->pStaticTexCoords = (vec2_t(*)[2])p;
if (surf->pStaticXyz) {
continue;
}

vert = surf->pVerts;
// allocate static vectors
p = buf =
(byte *)ri.TIKI_Alloc((sizeof(vec4_t) + sizeof(vec4_t) + sizeof(vec2_t) * 2) * surf->numVerts);
surf->pStaticXyz = (vec4_t *)p;
p += sizeof(vec4_t) * surf->numVerts;
surf->pStaticNormal = (vec4_t *)p;
p += sizeof(vec4_t) * surf->numVerts;
surf->pStaticTexCoords = (vec2_t(*)[2])p;

for (l = 0; l < surf->numVerts; l++) {
int channel;
skelBoneCache_t *bone;
vert = surf->pVerts;

weight = (skelWeight_t *)((byte *)vert + sizeof(skeletorVertex_t)
+ vert->numMorphs * sizeof(skeletorMorph_t));
for (l = 0; l < surf->numVerts; l++) {
int channel;
skelBoneCache_t *bone;

if (j > 0) {
channel = ri.TIKI_GetLocalChannel(pSM->tiki, skelmodel->pBones[weight->boneIndex].channel);
} else {
channel = weight->boneIndex;
}
weight = (skelWeight_t *)((byte *)vert + sizeof(skeletorVertex_t)
+ vert->numMorphs * sizeof(skeletorMorph_t));

bone = &bones[channel];

surf->pStaticXyz[l][0] =
((weight->offset[0] * bone->matrix[0][0] + weight->offset[1] * bone->matrix[1][0]
+ weight->offset[2] * bone->matrix[2][0])
+ bone->offset[0])
* weight->boneWeight;
surf->pStaticXyz[l][1] =
((weight->offset[0] * bone->matrix[0][1] + weight->offset[1] * bone->matrix[1][1]
+ weight->offset[2] * bone->matrix[2][1])
+ bone->offset[1])
* weight->boneWeight;
surf->pStaticXyz[l][2] =
((weight->offset[0] * bone->matrix[0][2] + weight->offset[1] * bone->matrix[1][2]
+ weight->offset[2] * bone->matrix[2][2])
+ bone->offset[2])
* weight->boneWeight;
surf->pStaticXyz[l][3] = 0.f;

surf->pStaticNormal[l][0] = vert->normal[0] * bone->matrix[0][0]
+ vert->normal[1] * bone->matrix[1][0]
+ vert->normal[2] * bone->matrix[2][0];
surf->pStaticNormal[l][1] = vert->normal[0] * bone->matrix[0][1]
+ vert->normal[1] * bone->matrix[1][1]
+ vert->normal[2] * bone->matrix[2][1];
surf->pStaticNormal[l][2] = vert->normal[0] * bone->matrix[0][2]
+ vert->normal[1] * bone->matrix[1][2]
+ vert->normal[2] * bone->matrix[2][2];
surf->pStaticNormal[l][3] = 0.f;

surf->pStaticTexCoords[l][0][0] = vert->texCoords[0];
surf->pStaticTexCoords[l][0][1] = vert->texCoords[1];
surf->pStaticTexCoords[l][1][0] = vert->texCoords[0];
surf->pStaticTexCoords[l][1][1] = vert->texCoords[1];

vert = (skeletorVertex_t *)((byte *)vert + sizeof(skeletorVertex_t)
+ sizeof(skeletorMorph_t) * vert->numMorphs
+ sizeof(skelWeight_t) * vert->numWeights);
if (j > 0) {
channel = ri.TIKI_GetLocalChannel(pSM->tiki, skelmodel->pBones[weight->boneIndex].channel);
} else {
channel = weight->boneIndex;
}

bone = &bones[channel];

surf->pStaticXyz[l][0] =
((weight->offset[0] * bone->matrix[0][0] + weight->offset[1] * bone->matrix[1][0]
+ weight->offset[2] * bone->matrix[2][0])
+ bone->offset[0])
* weight->boneWeight;
surf->pStaticXyz[l][1] =
((weight->offset[0] * bone->matrix[0][1] + weight->offset[1] * bone->matrix[1][1]
+ weight->offset[2] * bone->matrix[2][1])
+ bone->offset[1])
* weight->boneWeight;
surf->pStaticXyz[l][2] =
((weight->offset[0] * bone->matrix[0][2] + weight->offset[1] * bone->matrix[1][2]
+ weight->offset[2] * bone->matrix[2][2])
+ bone->offset[2])
* weight->boneWeight;
surf->pStaticXyz[l][3] = 0.f;

surf->pStaticNormal[l][0] = vert->normal[0] * bone->matrix[0][0]
+ vert->normal[1] * bone->matrix[1][0]
+ vert->normal[2] * bone->matrix[2][0];
surf->pStaticNormal[l][1] = vert->normal[0] * bone->matrix[0][1]
+ vert->normal[1] * bone->matrix[1][1]
+ vert->normal[2] * bone->matrix[2][1];
surf->pStaticNormal[l][2] = vert->normal[0] * bone->matrix[0][2]
+ vert->normal[1] * bone->matrix[1][2]
+ vert->normal[2] * bone->matrix[2][2];
surf->pStaticNormal[l][3] = 0.f;

surf->pStaticTexCoords[l][0][0] = vert->texCoords[0];
surf->pStaticTexCoords[l][0][1] = vert->texCoords[1];
surf->pStaticTexCoords[l][1][0] = vert->texCoords[0];
surf->pStaticTexCoords[l][1][1] = vert->texCoords[1];

vert = (skeletorVertex_t *)((byte *)vert + sizeof(skeletorVertex_t)
+ sizeof(skeletorMorph_t) * vert->numMorphs
+ sizeof(skelWeight_t) * vert->numWeights);
}
}
}
Expand Down Expand Up @@ -338,8 +337,7 @@ void R_AddStaticModelSurfaces(void)
iRadiusCull = R_CullPointAndRadius(tiki_worldorigin, SM->cull_radius);

if (r_showcull->integer & 8) {
switch (iRadiusCull)
{
switch (iRadiusCull) {
case CULL_IN:
R_DebugCircle(tiki_worldorigin, SM->cull_radius * 1.2, 0.0, 1.0, 0.0, 0.5, 0);
break;
Expand Down

0 comments on commit 58bef33

Please sign in to comment.