Skip to content

Commit 1d39be1

Browse files
committed
engine: again fix static prop lump version 10 loading
1 parent 92a1eae commit 1d39be1

File tree

2 files changed

+121
-64
lines changed

2 files changed

+121
-64
lines changed

engine/staticpropmgr.cpp

Lines changed: 19 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -536,12 +536,12 @@ bool CStaticProp::Init( int index, StaticPropLump_t &lump, model_t *pModel )
536536
m_Flags = ( lump.m_Flags & (STATIC_PROP_SCREEN_SPACE_FADE | STATIC_PROP_FLAG_FADES | STATIC_PROP_NO_PER_VERTEX_LIGHTING) );
537537

538538
int nCurrentDXLevel = g_pMaterialSystemHardwareConfig->GetDXSupportLevel();
539-
/* bool bNoDraw = ( lump.m_nMinDXLevel && lump.m_nMinDXLevel > nCurrentDXLevel );
539+
bool bNoDraw = ( lump.m_nMinDXLevel && lump.m_nMinDXLevel > nCurrentDXLevel );
540540
bNoDraw = bNoDraw || ( lump.m_nMaxDXLevel && lump.m_nMaxDXLevel < nCurrentDXLevel );
541541
if ( bNoDraw )
542542
{
543543
m_Flags |= STATIC_PROP_NO_DRAW;
544-
}*/
544+
}
545545

546546
// Cache the model to world matrix since it never changes.
547547
AngleMatrix( lump.m_Angles, lump.m_Origin, m_ModelToWorld );
@@ -1329,73 +1329,30 @@ void CStaticPropMgr::UnserializeModels( CUtlBuffer& buf )
13291329

13301330
// Gotta preallocate the static props here so no rellocations take place
13311331
// the leaf list stores pointers to these tricky little guys.
1332-
bool bSkip = false;
1333-
m_StaticProps.EnsureCapacity(count);
1332+
m_StaticProps.AddMultipleToTail(count);
13341333
for ( int i = 0; i < count; ++i )
13351334
{
1336-
// Reset every loop.
1337-
bSkip = false;
1338-
13391335
StaticPropLump_t lump;
13401336
switch ( nLumpVersion )
13411337
{
1342-
case 4:
1343-
buf.Get( &lump, sizeof(StaticPropLumpV4_t) );
1344-
lump.m_flForcedFadeScale = 1.0f;
1345-
lump.m_nMinCPULevel = lump.m_nMaxCPULevel = lump.m_nMinGPULevel = lump.m_nMaxGPULevel = 0;
1346-
lump.m_DiffuseModulation.r = lump.m_DiffuseModulation.g = lump.m_DiffuseModulation.b = lump.m_DiffuseModulation.a = 255; // default color/alpha modulation to identity
1347-
lump.m_bDisableX360 = false;
1348-
lump.m_FlagsEx = 0;
1349-
break;
1350-
1351-
case 5:
1352-
buf.Get( &lump, sizeof(StaticPropLumpV5_t) );
1353-
lump.m_nMinCPULevel = lump.m_nMaxCPULevel = lump.m_nMinGPULevel = lump.m_nMaxGPULevel = 0;
1354-
lump.m_DiffuseModulation.r = lump.m_DiffuseModulation.g = lump.m_DiffuseModulation.b = lump.m_DiffuseModulation.a = 255; // default color/alpha modulation to identity
1355-
lump.m_bDisableX360 = false;
1356-
lump.m_FlagsEx = 0;
1357-
break;
1358-
1359-
case 6:
1360-
buf.Get( &lump, sizeof( StaticPropLumpV6_t ) );
1361-
lump.m_nMinCPULevel = lump.m_nMaxCPULevel = lump.m_nMinGPULevel = lump.m_nMaxGPULevel = 0;
1362-
lump.m_DiffuseModulation.r = lump.m_DiffuseModulation.g = lump.m_DiffuseModulation.b = lump.m_DiffuseModulation.a = 255; // default color/alpha modulation to identity
1363-
lump.m_bDisableX360 = false;
1364-
lump.m_FlagsEx = 0;
1365-
break;
1366-
1367-
case 7:
1368-
buf.Get( &lump, sizeof( StaticPropLumpV7_t ) );
1369-
lump.m_nMinCPULevel = lump.m_nMaxCPULevel = lump.m_nMinGPULevel = lump.m_nMaxGPULevel = 0;
1370-
lump.m_bDisableX360 = false;
1371-
lump.m_FlagsEx = 0;
1372-
break;
1373-
1374-
case 8:
1375-
buf.Get( &lump, sizeof( StaticPropLumpV8_t ) );
1376-
lump.m_bDisableX360 = false;
1377-
lump.m_FlagsEx = 0;
1378-
break;
1379-
1380-
case 9:
1381-
buf.Get( &lump, sizeof( StaticPropLumpV9_t ) );
1382-
lump.m_FlagsEx = 0;
1383-
break;
1384-
1385-
case 10:
1386-
if( s_MapHeader.version >= 21 )
1387-
buf.Get( &lump, sizeof( StaticPropLumpV10_21_t ) );
1388-
else
1389-
buf.Get( &lump, sizeof( StaticPropLumpV10_t ) );
1390-
break;
1391-
1392-
case 11:
1393-
buf.Get( &lump, sizeof( StaticPropLump_t ) );
1394-
break;
1338+
case 4: UnserializeLump<StaticPropLumpV4_t>(&lump, buf); break;
1339+
case 5: UnserializeLump<StaticPropLumpV5_t>(&lump, buf); break;
1340+
case 6: UnserializeLump<StaticPropLumpV6_t>(&lump, buf); break;
1341+
case 7: // Falls down to version 10. We promoted TF to version 10 to deal with SFM.
1342+
case 9: UnserializeLump<StaticPropLumpV9_t>(&lump, buf); break;
1343+
case 10:
1344+
{
1345+
if( s_MapHeader.version == 21 )
1346+
UnserializeLump<StaticPropLumpV10_21_t>(&lump, buf);
1347+
else
1348+
UnserializeLump<StaticPropLumpV10_t>(&lump, buf);
1349+
break;
1350+
}
1351+
default:
1352+
Assert("Unexpected version while deserializing lumps.");
13951353
}
13961354

1397-
int j = m_StaticProps.AddToTail();
1398-
m_StaticProps[j].Init( j, lump, m_StaticPropDict[lump.m_PropType].m_pModel );
1355+
m_StaticProps[i].Init( i, lump, m_StaticPropDict[lump.m_PropType].m_pModel );
13991356

14001357
// For distance-based fading, keep a list of the things that need
14011358
// to be faded out. Not sure if this is the optimal way of doing it

public/gamebspfile.h

Lines changed: 102 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ struct StaticPropLumpV10_t
292292
unsigned short m_nLightmapResolutionY;
293293
};
294294

295-
// version 10
295+
// version 10 bsp21
296296
struct StaticPropLumpV10_21_t
297297
{
298298
DECLARE_BYTESWAP_DATADESC();
@@ -319,7 +319,7 @@ struct StaticPropLumpV10_21_t
319319
};
320320

321321
// version 11
322-
struct StaticPropLump_t
322+
struct StaticPropLumpV11_t
323323
{
324324
DECLARE_BYTESWAP_DATADESC();
325325
Vector m_Origin;
@@ -345,6 +345,106 @@ struct StaticPropLump_t
345345
float m_flPropScale;
346346
};
347347

348+
struct StaticPropLump_t
349+
{
350+
DECLARE_BYTESWAP_DATADESC();
351+
Vector m_Origin;
352+
QAngle m_Angles;
353+
unsigned short m_PropType;
354+
unsigned short m_FirstLeaf;
355+
unsigned short m_LeafCount;
356+
unsigned char m_Solid;
357+
int m_Skin;
358+
float m_FadeMinDist;
359+
float m_FadeMaxDist;
360+
Vector m_LightingOrigin;
361+
float m_flForcedFadeScale;
362+
unsigned short m_nMinDXLevel;
363+
unsigned short m_nMaxDXLevel;
364+
// int m_Lighting; // index into the GAMELUMP_STATIC_PROP_LIGHTING lump
365+
unsigned int m_Flags;
366+
unsigned short m_nLightmapResolutionX;
367+
unsigned short m_nLightmapResolutionY;
368+
369+
color32 m_DiffuseModulation; // per instance color and alpha modulation
370+
bool m_bDisableX360;
371+
int m_FlagsEx; // more flags (introduced in v10)
372+
373+
inline StaticPropLump_t& operator=(const StaticPropLumpV4_t& _rhs)
374+
{
375+
m_Origin = _rhs.m_Origin;
376+
m_Angles = _rhs.m_Angles;
377+
m_PropType = _rhs.m_PropType;
378+
m_FirstLeaf = _rhs.m_FirstLeaf;
379+
m_LeafCount = _rhs.m_LeafCount;
380+
m_Solid = _rhs.m_Solid;
381+
m_Flags = _rhs.m_Flags;
382+
m_Skin = _rhs.m_Skin;
383+
m_FadeMinDist = _rhs.m_FadeMinDist;
384+
m_FadeMaxDist = _rhs.m_FadeMaxDist;
385+
m_LightingOrigin = _rhs.m_LightingOrigin;
386+
387+
// These get potentially set twice--once here and once in the caller.
388+
// Value judgement: This makes the code easier to work with, so unless it's a perf issue...
389+
m_flForcedFadeScale = 1.0f;
390+
m_nMinDXLevel = 0;
391+
m_nMaxDXLevel = 0;
392+
m_nLightmapResolutionX = 0;
393+
m_nLightmapResolutionY = 0;
394+
m_DiffuseModulation.r = 0;
395+
m_DiffuseModulation.g = 0;
396+
m_DiffuseModulation.b = 0;
397+
m_DiffuseModulation.a = 0;
398+
399+
// Older versions don't want this.
400+
m_Flags |= STATIC_PROP_NO_PER_TEXEL_LIGHTING;
401+
return *this;
402+
}
403+
404+
inline StaticPropLump_t& operator=(const StaticPropLumpV5_t& _rhs)
405+
{
406+
(*this) = reinterpret_cast<const StaticPropLumpV4_t&>(_rhs);
407+
408+
m_flForcedFadeScale = _rhs.m_flForcedFadeScale;
409+
return *this;
410+
}
411+
412+
inline StaticPropLump_t& operator=(const StaticPropLumpV6_t& _rhs)
413+
{
414+
(*this) = reinterpret_cast<const StaticPropLumpV5_t&>(_rhs);
415+
416+
m_nMinDXLevel = _rhs.m_nMinDXLevel;
417+
m_nMaxDXLevel = _rhs.m_nMaxDXLevel;
418+
return *this;
419+
}
420+
421+
inline StaticPropLump_t& operator=(const StaticPropLumpV9_t& _rhs)
422+
{
423+
(*this) = reinterpret_cast<const StaticPropLumpV5_t&>(_rhs);
424+
425+
m_DiffuseModulation = _rhs.m_DiffuseModulation;
426+
return *this;
427+
}
428+
429+
inline StaticPropLump_t& operator=(const StaticPropLumpV10_t& _rhs)
430+
{
431+
(*this) = reinterpret_cast<const StaticPropLumpV6_t&>(_rhs);
432+
433+
m_Flags = _rhs.m_Flags;
434+
m_nLightmapResolutionX = _rhs.m_nLightmapResolutionX;
435+
m_nLightmapResolutionY = _rhs.m_nLightmapResolutionY;
436+
return *this;
437+
}
438+
439+
inline StaticPropLump_t& operator=(const StaticPropLumpV10_21_t& _rhs)
440+
{
441+
(*this) = reinterpret_cast<const StaticPropLumpV9_t&>(_rhs);
442+
443+
m_FlagsEx = _rhs.m_FlagsEx;
444+
return *this;
445+
}
446+
};
447+
348448
struct StaticPropLeafLump_t
349449
{
350450
DECLARE_BYTESWAP_DATADESC();

0 commit comments

Comments
 (0)