Skip to content

Commit 729ac11

Browse files
committed
engine: add bsp v21 support, add StaticPropLump_t v7-v11 support
1 parent 20f5783 commit 729ac11

File tree

4 files changed

+236
-67
lines changed

4 files changed

+236
-67
lines changed

engine/modelloader.cpp

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,9 +1143,55 @@ void Mod_LoadWorldlights( CMapLoadHelper &lh, bool bIsHDR )
11431143
lh.GetMap()->worldlights = NULL;
11441144
return;
11451145
}
1146-
lh.GetMap()->numworldlights = lh.LumpSize() / sizeof( dworldlight_t );
1147-
lh.GetMap()->worldlights = (dworldlight_t *)Hunk_AllocName( lh.LumpSize(), va( "%s [%s]", lh.GetLoadName(), "worldlights" ) );
1148-
memcpy (lh.GetMap()->worldlights, lh.LumpBase(), lh.LumpSize());
1146+
1147+
switch ( lh.LumpVersion() )
1148+
{
1149+
case LUMP_WORLDLIGHTS_VERSION:
1150+
{
1151+
lh.GetMap()->numworldlights = lh.LumpSize() / sizeof( dworldlight_t );
1152+
lh.GetMap()->worldlights = (dworldlight_t *)Hunk_AllocName( lh.LumpSize(), va( "%s [%s]", lh.GetLoadName(), "worldlights" ) );
1153+
memcpy( lh.GetMap()->worldlights, lh.LumpBase(), lh.LumpSize() );
1154+
break;
1155+
}
1156+
1157+
case 0:
1158+
{
1159+
int nNumWorldLights = lh.LumpSize() / sizeof( dworldlight_version0_t );
1160+
lh.GetMap()->numworldlights = nNumWorldLights;
1161+
lh.GetMap()->worldlights = (dworldlight_t *)Hunk_AllocName( nNumWorldLights * sizeof( dworldlight_t ), va( "%s [%s]", lh.GetLoadName(), "worldlights" ) );
1162+
dworldlight_version0_t* RESTRICT pOldWorldLight = reinterpret_cast<dworldlight_version0_t*>( lh.LumpBase() );
1163+
dworldlight_t* RESTRICT pNewWorldLight = lh.GetMap()->worldlights;
1164+
1165+
for ( int i = 0; i < nNumWorldLights; i++ )
1166+
{
1167+
pNewWorldLight->origin = pOldWorldLight->origin;
1168+
pNewWorldLight->intensity = pOldWorldLight->intensity;
1169+
pNewWorldLight->normal = pOldWorldLight->normal;
1170+
pNewWorldLight->shadow_cast_offset.Init( 0.0f, 0.0f, 0.0f );
1171+
pNewWorldLight->cluster = pOldWorldLight->cluster;
1172+
pNewWorldLight->type = pOldWorldLight->type;
1173+
pNewWorldLight->style = pOldWorldLight->style;
1174+
pNewWorldLight->stopdot = pOldWorldLight->stopdot;
1175+
pNewWorldLight->stopdot2 = pOldWorldLight->stopdot2;
1176+
pNewWorldLight->exponent = pOldWorldLight->exponent;
1177+
pNewWorldLight->radius = pOldWorldLight->radius;
1178+
pNewWorldLight->constant_attn = pOldWorldLight->constant_attn;
1179+
pNewWorldLight->linear_attn = pOldWorldLight->linear_attn;
1180+
pNewWorldLight->quadratic_attn = pOldWorldLight->quadratic_attn;
1181+
pNewWorldLight->flags = pOldWorldLight->flags;
1182+
pNewWorldLight->texinfo = pOldWorldLight->texinfo;
1183+
pNewWorldLight->owner = pOldWorldLight->owner;
1184+
pNewWorldLight++;
1185+
pOldWorldLight++;
1186+
}
1187+
break;
1188+
}
1189+
1190+
default:
1191+
Host_Error( "Invalid worldlight lump version!\n" );
1192+
break;
1193+
}
1194+
11491195
#if !defined( SWDS )
11501196
if ( r_lightcache_zbuffercache.GetInt() )
11511197
{

engine/staticpropmgr.cpp

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

537537
int nCurrentDXLevel = g_pMaterialSystemHardwareConfig->GetDXSupportLevel();
538-
bool bNoDraw = ( lump.m_nMinDXLevel && lump.m_nMinDXLevel > nCurrentDXLevel );
538+
/* bool bNoDraw = ( lump.m_nMinDXLevel && lump.m_nMinDXLevel > nCurrentDXLevel );
539539
bNoDraw = bNoDraw || ( lump.m_nMaxDXLevel && lump.m_nMaxDXLevel < nCurrentDXLevel );
540540
if ( bNoDraw )
541541
{
542542
m_Flags |= STATIC_PROP_NO_DRAW;
543-
}
543+
}*/
544544

545545
// Cache the model to world matrix since it never changes.
546546
AngleMatrix( lump.m_Angles, lump.m_Origin, m_ModelToWorld );
@@ -1328,24 +1328,70 @@ void CStaticPropMgr::UnserializeModels( CUtlBuffer& buf )
13281328

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

1348-
m_StaticProps[i].Init( i, lump, m_StaticPropDict[lump.m_PropType].m_pModel );
1393+
int j = m_StaticProps.AddToTail();
1394+
m_StaticProps[j].Init( j, lump, m_StaticPropDict[lump.m_PropType].m_pModel );
13491395

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

public/bspfile.h

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
// MINBSPVERSION is the minimum acceptable version. The engine will load MINBSPVERSION through BSPVERSION
2424
#define MINBSPVERSION 19
25-
#define BSPVERSION 20
25+
#define BSPVERSION 21
2626

2727

2828
// This needs to match the value in gl_lightmap.h
@@ -62,7 +62,7 @@
6262
#define MAX_MAP_ENTITIES 8192
6363
#define MAX_MAP_TEXINFO 12288
6464
#define MAX_MAP_TEXDATA 2048
65-
#define MAX_MAP_DISPINFO 2048
65+
#define MAX_MAP_DISPINFO 10240
6666
#define MAX_MAP_DISP_VERTS ( MAX_MAP_DISPINFO * ((1<<MAX_MAP_DISP_POWER)+1) * ((1<<MAX_MAP_DISP_POWER)+1) )
6767
#define MAX_MAP_DISP_TRIS ( (1 << MAX_MAP_DISP_POWER) * (1 << MAX_MAP_DISP_POWER) * 2 )
6868
#define MAX_DISPVERTS NUM_DISP_POWER_VERTS( MAX_MAP_DISP_POWER )
@@ -364,6 +364,7 @@ enum
364364
LUMP_OCCLUSION_VERSION = 2,
365365
LUMP_LEAFS_VERSION = 1,
366366
LUMP_LEAF_AMBIENT_LIGHTING_VERSION = 1,
367+
LUMP_WORLDLIGHTS_VERSION = 1
367368
};
368369

369370

@@ -966,14 +967,39 @@ enum emittype_t
966967

967968
// Flags for dworldlight_t::flags
968969
#define DWL_FLAGS_INAMBIENTCUBE 0x0001 // This says that the light was put into the per-leaf ambient cubes.
970+
#define DWL_FLAGS_CASTENTITYSHADOWS 0x0002 // This says that the light will cast shadows from entities
969971

972+
// Old version of the worldlight struct, used for backward compatibility loading.
973+
struct dworldlight_version0_t
974+
{
975+
DECLARE_BYTESWAP_DATADESC();
976+
Vector origin;
977+
Vector intensity;
978+
Vector normal; // for surfaces and spotlights
979+
int cluster;
980+
emittype_t type;
981+
int style;
982+
float stopdot; // start of penumbra for emit_spotlight
983+
float stopdot2; // end of penumbra for emit_spotlight
984+
float exponent; //
985+
float radius; // cutoff distance
986+
// falloff for emit_spotlight + emit_point:
987+
// 1 / (constant_attn + linear_attn * dist + quadratic_attn * dist^2)
988+
float constant_attn;
989+
float linear_attn;
990+
float quadratic_attn;
991+
int flags; // Uses a combination of the DWL_FLAGS_ defines.
992+
int texinfo; //
993+
int owner; // entity that this light it relative to
994+
};
970995

971996
struct dworldlight_t
972997
{
973998
DECLARE_BYTESWAP_DATADESC();
974999
Vector origin;
9751000
Vector intensity;
9761001
Vector normal; // for surfaces and spotlights
1002+
Vector shadow_cast_offset; // gets added to the light origin when this light is used as a shadow caster (only if DWL_FLAGS_CASTENTITYSHADOWS flag is set)
9771003
int cluster;
9781004
emittype_t type;
9791005
int style;

public/gamebspfile.h

Lines changed: 100 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ struct StaticPropLumpV6_t
203203
// int m_Lighting; // index into the GAMELUMP_STATIC_PROP_LIGHTING lump
204204
};
205205

206-
struct StaticPropLump_t
206+
struct StaticPropLumpV7_t
207207
{
208208
DECLARE_BYTESWAP_DATADESC();
209209
Vector m_Origin;
@@ -212,6 +212,7 @@ struct StaticPropLump_t
212212
unsigned short m_FirstLeaf;
213213
unsigned short m_LeafCount;
214214
unsigned char m_Solid;
215+
unsigned char m_Flags;
215216
int m_Skin;
216217
float m_FadeMinDist;
217218
float m_FadeMaxDist;
@@ -220,58 +221,108 @@ struct StaticPropLump_t
220221
unsigned short m_nMinDXLevel;
221222
unsigned short m_nMaxDXLevel;
222223
// int m_Lighting; // index into the GAMELUMP_STATIC_PROP_LIGHTING lump
223-
unsigned int m_Flags;
224-
unsigned short m_nLightmapResolutionX;
225-
unsigned short m_nLightmapResolutionY;
226-
227-
228-
StaticPropLump_t& operator=(const StaticPropLumpV4_t& _rhs)
229-
{
230-
m_Origin = _rhs.m_Origin;
231-
m_Angles = _rhs.m_Angles;
232-
m_PropType = _rhs.m_PropType;
233-
m_FirstLeaf = _rhs.m_FirstLeaf;
234-
m_LeafCount = _rhs.m_LeafCount;
235-
m_Solid = _rhs.m_Solid;
236-
m_Flags = _rhs.m_Flags;
237-
m_Skin = _rhs.m_Skin;
238-
m_FadeMinDist = _rhs.m_FadeMinDist;
239-
m_FadeMaxDist = _rhs.m_FadeMaxDist;
240-
m_LightingOrigin = _rhs.m_LightingOrigin;
241-
242-
// These get potentially set twice--once here and once in the caller.
243-
// Value judgement: This makes the code easier to work with, so unless it's a perf issue...
244-
m_flForcedFadeScale = 1.0f;
245-
m_nMinDXLevel = 0;
246-
m_nMaxDXLevel = 0;
247-
m_nLightmapResolutionX = 0;
248-
m_nLightmapResolutionY = 0;
249-
250-
// Older versions don't want this.
251-
m_Flags |= STATIC_PROP_NO_PER_TEXEL_LIGHTING;
252-
return *this;
253-
}
254-
255-
StaticPropLump_t& operator=(const StaticPropLumpV5_t& _rhs)
256-
{
257-
(*this) = reinterpret_cast<const StaticPropLumpV4_t&>(_rhs);
258-
259-
m_flForcedFadeScale = _rhs.m_flForcedFadeScale;
260-
return *this;
261-
}
262-
263-
StaticPropLump_t& operator=(const StaticPropLumpV6_t& _rhs)
264-
{
265-
(*this) = reinterpret_cast<const StaticPropLumpV5_t&>(_rhs);
266-
267-
m_nMinDXLevel = _rhs.m_nMinDXLevel;
268-
m_nMaxDXLevel = _rhs.m_nMaxDXLevel;
269-
return *this;
270-
}
224+
color32 m_DiffuseModulation; // per instance color and alpha modulation
225+
};
226+
227+
struct StaticPropLumpV8_t
228+
{
229+
DECLARE_BYTESWAP_DATADESC();
230+
Vector m_Origin;
231+
QAngle m_Angles;
232+
unsigned short m_PropType;
233+
unsigned short m_FirstLeaf;
234+
unsigned short m_LeafCount;
235+
unsigned char m_Solid;
236+
unsigned char m_Flags;
237+
int m_Skin;
238+
float m_FadeMinDist;
239+
float m_FadeMaxDist;
240+
Vector m_LightingOrigin;
241+
float m_flForcedFadeScale;
242+
unsigned char m_nMinCPULevel;
243+
unsigned char m_nMaxCPULevel;
244+
unsigned char m_nMinGPULevel;
245+
unsigned char m_nMaxGPULevel;
246+
// int m_Lighting; // index into the GAMELUMP_STATIC_PROP_LIGHTING lump
247+
color32 m_DiffuseModulation; // per instance color and alpha modulation
271248
};
272249

250+
struct StaticPropLumpV9_t
251+
{
252+
DECLARE_BYTESWAP_DATADESC();
253+
Vector m_Origin;
254+
QAngle m_Angles;
255+
unsigned short m_PropType;
256+
unsigned short m_FirstLeaf;
257+
unsigned short m_LeafCount;
258+
unsigned char m_Solid;
259+
unsigned char m_Flags;
260+
int m_Skin;
261+
float m_FadeMinDist;
262+
float m_FadeMaxDist;
263+
Vector m_LightingOrigin;
264+
float m_flForcedFadeScale;
265+
unsigned char m_nMinCPULevel;
266+
unsigned char m_nMaxCPULevel;
267+
unsigned char m_nMinGPULevel;
268+
unsigned char m_nMaxGPULevel;
269+
// int m_Lighting; // index into the GAMELUMP_STATIC_PROP_LIGHTING lump
270+
color32 m_DiffuseModulation; // per instance color and alpha modulation
271+
bool m_bDisableX360;
272+
};
273273

274+
// version 10
275+
struct StaticPropLumpV10_t
276+
{
277+
DECLARE_BYTESWAP_DATADESC();
278+
Vector m_Origin;
279+
QAngle m_Angles;
280+
unsigned short m_PropType;
281+
unsigned short m_FirstLeaf;
282+
unsigned short m_LeafCount;
283+
unsigned char m_Solid;
284+
unsigned char m_Flags;
285+
int m_Skin;
286+
float m_FadeMinDist;
287+
float m_FadeMaxDist;
288+
Vector m_LightingOrigin;
289+
float m_flForcedFadeScale;
290+
unsigned char m_nMinCPULevel;
291+
unsigned char m_nMaxCPULevel;
292+
unsigned char m_nMinGPULevel;
293+
unsigned char m_nMaxGPULevel;
294+
// int m_Lighting; // index into the GAMELUMP_STATIC_PROP_LIGHTING lump
295+
color32 m_DiffuseModulation; // per instance color and alpha modulation
296+
bool m_bDisableX360;
297+
int m_FlagsEx; // more flags (introduced in v10)
298+
};
274299

300+
// version 11
301+
struct StaticPropLump_t
302+
{
303+
DECLARE_BYTESWAP_DATADESC();
304+
Vector m_Origin;
305+
QAngle m_Angles;
306+
unsigned short m_PropType;
307+
unsigned short m_FirstLeaf;
308+
unsigned short m_LeafCount;
309+
unsigned char m_Solid;
310+
unsigned char m_Flags;
311+
int m_Skin;
312+
float m_FadeMinDist;
313+
float m_FadeMaxDist;
314+
Vector m_LightingOrigin;
315+
float m_flForcedFadeScale;
316+
unsigned char m_nMinCPULevel;
317+
unsigned char m_nMaxCPULevel;
318+
unsigned char m_nMinGPULevel;
319+
unsigned char m_nMaxGPULevel;
320+
// int m_Lighting; // index into the GAMELUMP_STATIC_PROP_LIGHTING lump
321+
color32 m_DiffuseModulation; // per instance color and alpha modulation
322+
bool m_bDisableX360;
323+
int m_FlagsEx; // more flags (introduced in v10)
324+
float m_flPropScale;
325+
};
275326

276327
struct StaticPropLeafLump_t
277328
{

0 commit comments

Comments
 (0)