Skip to content

Commit d2b2028

Browse files
committed
add MDL version 49 support
1 parent 2fb712a commit d2b2028

File tree

4 files changed

+121
-21
lines changed

4 files changed

+121
-21
lines changed

datacache/mdlcache.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1680,6 +1680,36 @@ bool CMDLCache::BuildHardwareData( MDLHandle_t handle, studiodata_t *pStudioData
16801680

16811681
Assert( GetVertexData( handle ) );
16821682

1683+
if( pStudioHdr->version == 49 )
1684+
{
1685+
for( int i = 0; i < pVtxHdr->numBodyParts; i++)
1686+
{
1687+
OptimizedModel::BodyPartHeader_t *pBodyPartHdr = pVtxHdr->pBodyPart(i);
1688+
1689+
for( int j = 0; j < pBodyPartHdr->numModels; j++ )
1690+
{
1691+
OptimizedModel::ModelHeader_t *pModelHdr = pBodyPartHdr->pModel(j);
1692+
1693+
for( int k = 0; k < pModelHdr->numLODs; k++)
1694+
{
1695+
OptimizedModel::ModelLODHeader_t *pModelLODHdr = pModelHdr->pLOD(k);
1696+
1697+
for( int l = 0; l < pModelLODHdr->numMeshes; l++ )
1698+
{
1699+
OptimizedModel::MeshHeader_t *pMeshHdr = pModelLODHdr->pMesh(l);
1700+
pMeshHdr->flags |= OptimizedModel::MESH_IS_MDL49;
1701+
1702+
for( int m = 0; m < pMeshHdr->numStripGroups; m++ )
1703+
{
1704+
OptimizedModel::StripGroupHeader_t *pStripGroupHdr = pMeshHdr->pStripGroup(m);
1705+
pStripGroupHdr->flags |= OptimizedModel::STRIPGROUP_IS_MDL49;
1706+
}
1707+
}
1708+
}
1709+
}
1710+
}
1711+
}
1712+
16831713
BeginLock();
16841714
bool bLoaded = g_pStudioRender->LoadModel( pStudioHdr, pVtxHdr, &pStudioData->m_HardwareData );
16851715
EndLock();

public/optimize.h

Lines changed: 72 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ enum StripHeaderFlags_t {
5656
STRIP_IS_TRISTRIP = 0x02
5757
};
5858

59-
// a strip is a piece of a stripgroup that is divided by bones
60-
// (and potentially tristrips if we remove some degenerates.)
6159
struct StripHeader_t
6260
{
6361
DECLARE_BYTESWAP_DATADESC();
@@ -84,12 +82,42 @@ struct StripHeader_t
8482
};
8583
};
8684

85+
struct StripHeader_v49_t
86+
{
87+
DECLARE_BYTESWAP_DATADESC();
88+
// indexOffset offsets into the mesh's index array.
89+
int numIndices;
90+
int indexOffset;
91+
92+
// vertexOffset offsets into the mesh's vert array.
93+
int numVerts;
94+
int vertOffset;
95+
96+
// use this to enable/disable skinning.
97+
// May decide (in optimize.cpp) to put all with 1 bone in a different strip
98+
// than those that need skinning.
99+
short numBones;
100+
101+
unsigned char flags;
102+
103+
int numBoneStateChanges;
104+
int boneStateChangeOffset;
105+
inline BoneStateChangeHeader_t *pBoneStateChange( int i ) const
106+
{
107+
return (BoneStateChangeHeader_t *)(((byte *)this) + boneStateChangeOffset) + i;
108+
};
109+
110+
int numTopologyIndices;
111+
int topologyOffset;
112+
};
113+
87114
enum StripGroupFlags_t
88115
{
89116
STRIPGROUP_IS_FLEXED = 0x01,
90117
STRIPGROUP_IS_HWSKINNED = 0x02,
91118
STRIPGROUP_IS_DELTA_FLEXED = 0x04,
92119
STRIPGROUP_SUPPRESS_HW_MORPH = 0x08, // NOTE: This is a temporary flag used at run time.
120+
STRIPGROUP_IS_MDL49 = 0x80
93121
};
94122

95123
// a locking group
@@ -117,16 +145,51 @@ struct StripGroupHeader_t
117145
int stripOffset;
118146
inline StripHeader_t *pStrip( int i ) const
119147
{
120-
return (StripHeader_t *)(((byte *)this) + stripOffset) + i;
148+
if( flags & STRIPGROUP_IS_MDL49 )
149+
return (StripHeader_t *)((StripHeader_v49_t *)(((byte *)this) + stripOffset) + i);
150+
else
151+
return (StripHeader_t *)(((byte *)this) + stripOffset) + i;
121152
};
122153

123154
unsigned char flags;
124155
};
125156

157+
struct StripGroupHeader_v49_t
158+
{
159+
DECLARE_BYTESWAP_DATADESC();
160+
// These are the arrays of all verts and indices for this mesh. strips index into this.
161+
int numVerts;
162+
int vertOffset;
163+
inline Vertex_t *pVertex( int i ) const
164+
{
165+
return (Vertex_t *)(((byte *)this) + vertOffset) + i;
166+
};
167+
168+
int numIndices;
169+
int indexOffset;
170+
inline unsigned short *pIndex( int i ) const
171+
{
172+
return (unsigned short *)(((byte *)this) + indexOffset) + i;
173+
};
174+
175+
int numStrips;
176+
int stripOffset;
177+
inline StripHeader_v49_t *pStrip( int i ) const
178+
{
179+
return (StripHeader_v49_t *)(((byte *)this) + stripOffset) + i;
180+
};
181+
182+
unsigned char flags;
183+
184+
int numTopologyIndices;
185+
int topologyOffset;
186+
};
187+
126188
enum MeshFlags_t {
127189
// these are both material properties, and a mesh has a single material.
128-
MESH_IS_TEETH = 0x01,
129-
MESH_IS_EYES = 0x02
190+
MESH_IS_TEETH = 0x01,
191+
MESH_IS_EYES = 0x02,
192+
MESH_IS_MDL49 = 0x80
130193
};
131194

132195
// a collection of locking groups:
@@ -144,8 +207,10 @@ struct MeshHeader_t
144207
int stripGroupHeaderOffset;
145208
inline StripGroupHeader_t *pStripGroup( int i ) const
146209
{
147-
StripGroupHeader_t *pDebug = (StripGroupHeader_t *)(((byte *)this) + stripGroupHeaderOffset) + i;
148-
return pDebug;
210+
if( flags & STRIPGROUP_IS_MDL49 )
211+
return (StripGroupHeader_t *)((StripGroupHeader_v49_t *)(((byte *)this) + stripGroupHeaderOffset) + i);
212+
else
213+
return (StripGroupHeader_t *)(((byte *)this) + stripGroupHeaderOffset) + i;
149214
};
150215
unsigned char flags;
151216
};

public/studio.h

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,26 +67,26 @@ Studio models are position independent, so the cache manager can move them.
6767
==============================================================================
6868
*/
6969

70-
#define STUDIO_VERSION 48
70+
#define STUDIO_VERSION 49
7171

7272
#ifndef _XBOX
7373
#define MAXSTUDIOTRIANGLES 65536 // TODO: tune this
7474
#define MAXSTUDIOVERTS 65536 // TODO: tune this
7575
#define MAXSTUDIOFLEXVERTS 10000 // max number of verts that can be flexed per mesh. TODO: tune this
7676
#else
77-
#define MAXSTUDIOTRIANGLES 25000
78-
#define MAXSTUDIOVERTS 10000
79-
#define MAXSTUDIOFLEXVERTS 1000
77+
#define MAXSTUDIOTRIANGLES 65536
78+
#define MAXSTUDIOVERTS 32768
79+
#define MAXSTUDIOFLEXVERTS 5000
8080
#endif
8181
#define MAXSTUDIOSKINS 32 // total textures
82-
#define MAXSTUDIOBONES 128 // total bones actually used
82+
#define MAXSTUDIOBONES 256 // total bones actually used
8383
#define MAXSTUDIOFLEXDESC 1024 // maximum number of low level flexes (actual morph targets)
8484
#define MAXSTUDIOFLEXCTRL 96 // maximum number of flexcontrollers (input sliders)
8585
#define MAXSTUDIOPOSEPARAM 24
8686
#define MAXSTUDIOBONECTRLS 5
8787
#define MAXSTUDIOANIMBLOCKS 256
8888

89-
#define MAXSTUDIOBONEBITS 7 // NOTE: MUST MATCH MAXSTUDIOBONES
89+
#define MAXSTUDIOBONEBITS 8 // NOTE: MUST MATCH MAXSTUDIOBONES
9090

9191
// NOTE!!! : Changing this number also changes the vtx file format!!!!!
9292
#define MAX_NUM_BONES_PER_VERT 3
@@ -3101,7 +3101,7 @@ inline const mstudioflexcontroller_t *mstudioflexcontrollerui_t::pController( in
31013101
// If we only support the current version, this function should be empty.
31023102
inline bool Studio_ConvertStudioHdrToNewVersion( studiohdr_t *pStudioHdr )
31033103
{
3104-
COMPILE_TIME_ASSERT( STUDIO_VERSION == 48 ); // put this to make sure this code is updated upon changing version.
3104+
COMPILE_TIME_ASSERT( STUDIO_VERSION == 49 ); // put this to make sure this code is updated upon changing version.
31053105

31063106
int version = pStudioHdr->version;
31073107
if ( version == STUDIO_VERSION )
@@ -3143,7 +3143,7 @@ inline bool Studio_ConvertStudioHdrToNewVersion( studiohdr_t *pStudioHdr )
31433143
pAnim->zeroframeindex = 0;
31443144
pAnim->zeroframespan = 0;
31453145
}
3146-
}
3146+
}
31473147
else if (version == 47)
31483148
{
31493149
for (int i = 0; i < pStudioHdr->numlocalanim; i++)
@@ -3159,7 +3159,9 @@ inline bool Studio_ConvertStudioHdrToNewVersion( studiohdr_t *pStudioHdr )
31593159
}
31603160

31613161
// for now, just slam the version number since they're compatible
3162-
pStudioHdr->version = STUDIO_VERSION;
3162+
3163+
// nillerusr: that's stupid, comment this shit
3164+
//pStudioHdr->version = STUDIO_VERSION;
31633165

31643166
return bResult;
31653167
}

studiorender/studiorendercontext.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -897,25 +897,28 @@ void CStudioRenderContext::R_StudioBuildMeshStrips( studiomeshgroup_t* pMeshGrou
897897
// Compute the amount of memory we need to store the strip data
898898
int i;
899899
int stripDataSize = 0;
900+
901+
size_t stripHdrSize = (pStripGroup->flags & OptimizedModel::STRIPGROUP_IS_MDL49)
902+
? sizeof(OptimizedModel::StripHeader_v49_t) : sizeof(OptimizedModel::StripHeader_t);
903+
900904
for( i = 0; i < pStripGroup->numStrips; ++i )
901905
{
902-
stripDataSize += sizeof(OptimizedModel::StripHeader_t);
906+
stripDataSize += stripHdrSize;
903907
stripDataSize += pStripGroup->pStrip(i)->numBoneStateChanges *
904908
sizeof(OptimizedModel::BoneStateChangeHeader_t);
905909
}
906910

907911
pMeshGroup->m_pStripData = (OptimizedModel::StripHeader_t*)malloc(stripDataSize);
908912

909913
// Copy over the strip info
910-
int boneStateChangeOffset = pStripGroup->numStrips * sizeof(OptimizedModel::StripHeader_t);
914+
int boneStateChangeOffset = pStripGroup->numStrips * stripHdrSize;
911915
for( i = 0; i < pStripGroup->numStrips; ++i )
912916
{
913-
memcpy( &pMeshGroup->m_pStripData[i], pStripGroup->pStrip(i),
914-
sizeof( OptimizedModel::StripHeader_t ) );
917+
memcpy( &pMeshGroup->m_pStripData[i], pStripGroup->pStrip(i), stripHdrSize);
915918

916919
// Fixup the bone state change offset, since we have it right after the strip data
917920
pMeshGroup->m_pStripData[i].boneStateChangeOffset = boneStateChangeOffset -
918-
i * sizeof(OptimizedModel::StripHeader_t);
921+
i * stripHdrSize;
919922

920923
// copy over bone state changes
921924
int boneWeightSize = pMeshGroup->m_pStripData[i].numBoneStateChanges *

0 commit comments

Comments
 (0)