Browse Source

engine: add bsp v21 support, add StaticPropLump_t v7-v11 support

pull/153/head
nillerusr 2 years ago
parent
commit
729ac111af
  1. 52
      engine/modelloader.cpp
  2. 72
      engine/staticpropmgr.cpp
  3. 30
      public/bspfile.h
  4. 149
      public/gamebspfile.h

52
engine/modelloader.cpp

@ -1143,9 +1143,55 @@ void Mod_LoadWorldlights( CMapLoadHelper &lh, bool bIsHDR ) @@ -1143,9 +1143,55 @@ void Mod_LoadWorldlights( CMapLoadHelper &lh, bool bIsHDR )
lh.GetMap()->worldlights = NULL;
return;
}
lh.GetMap()->numworldlights = lh.LumpSize() / sizeof( dworldlight_t );
lh.GetMap()->worldlights = (dworldlight_t *)Hunk_AllocName( lh.LumpSize(), va( "%s [%s]", lh.GetLoadName(), "worldlights" ) );
memcpy (lh.GetMap()->worldlights, lh.LumpBase(), lh.LumpSize());
switch ( lh.LumpVersion() )
{
case LUMP_WORLDLIGHTS_VERSION:
{
lh.GetMap()->numworldlights = lh.LumpSize() / sizeof( dworldlight_t );
lh.GetMap()->worldlights = (dworldlight_t *)Hunk_AllocName( lh.LumpSize(), va( "%s [%s]", lh.GetLoadName(), "worldlights" ) );
memcpy( lh.GetMap()->worldlights, lh.LumpBase(), lh.LumpSize() );
break;
}
case 0:
{
int nNumWorldLights = lh.LumpSize() / sizeof( dworldlight_version0_t );
lh.GetMap()->numworldlights = nNumWorldLights;
lh.GetMap()->worldlights = (dworldlight_t *)Hunk_AllocName( nNumWorldLights * sizeof( dworldlight_t ), va( "%s [%s]", lh.GetLoadName(), "worldlights" ) );
dworldlight_version0_t* RESTRICT pOldWorldLight = reinterpret_cast<dworldlight_version0_t*>( lh.LumpBase() );
dworldlight_t* RESTRICT pNewWorldLight = lh.GetMap()->worldlights;
for ( int i = 0; i < nNumWorldLights; i++ )
{
pNewWorldLight->origin = pOldWorldLight->origin;
pNewWorldLight->intensity = pOldWorldLight->intensity;
pNewWorldLight->normal = pOldWorldLight->normal;
pNewWorldLight->shadow_cast_offset.Init( 0.0f, 0.0f, 0.0f );
pNewWorldLight->cluster = pOldWorldLight->cluster;
pNewWorldLight->type = pOldWorldLight->type;
pNewWorldLight->style = pOldWorldLight->style;
pNewWorldLight->stopdot = pOldWorldLight->stopdot;
pNewWorldLight->stopdot2 = pOldWorldLight->stopdot2;
pNewWorldLight->exponent = pOldWorldLight->exponent;
pNewWorldLight->radius = pOldWorldLight->radius;
pNewWorldLight->constant_attn = pOldWorldLight->constant_attn;
pNewWorldLight->linear_attn = pOldWorldLight->linear_attn;
pNewWorldLight->quadratic_attn = pOldWorldLight->quadratic_attn;
pNewWorldLight->flags = pOldWorldLight->flags;
pNewWorldLight->texinfo = pOldWorldLight->texinfo;
pNewWorldLight->owner = pOldWorldLight->owner;
pNewWorldLight++;
pOldWorldLight++;
}
break;
}
default:
Host_Error( "Invalid worldlight lump version!\n" );
break;
}
#if !defined( SWDS )
if ( r_lightcache_zbuffercache.GetInt() )
{

72
engine/staticpropmgr.cpp

@ -535,12 +535,12 @@ bool CStaticProp::Init( int index, StaticPropLump_t &lump, model_t *pModel ) @@ -535,12 +535,12 @@ bool CStaticProp::Init( int index, StaticPropLump_t &lump, model_t *pModel )
m_Flags = ( lump.m_Flags & (STATIC_PROP_SCREEN_SPACE_FADE | STATIC_PROP_FLAG_FADES | STATIC_PROP_NO_PER_VERTEX_LIGHTING) );
int nCurrentDXLevel = g_pMaterialSystemHardwareConfig->GetDXSupportLevel();
bool bNoDraw = ( lump.m_nMinDXLevel && lump.m_nMinDXLevel > nCurrentDXLevel );
/* bool bNoDraw = ( lump.m_nMinDXLevel && lump.m_nMinDXLevel > nCurrentDXLevel );
bNoDraw = bNoDraw || ( lump.m_nMaxDXLevel && lump.m_nMaxDXLevel < nCurrentDXLevel );
if ( bNoDraw )
{
m_Flags |= STATIC_PROP_NO_DRAW;
}
}*/
// Cache the model to world matrix since it never changes.
AngleMatrix( lump.m_Angles, lump.m_Origin, m_ModelToWorld );
@ -1328,24 +1328,70 @@ void CStaticPropMgr::UnserializeModels( CUtlBuffer& buf ) @@ -1328,24 +1328,70 @@ void CStaticPropMgr::UnserializeModels( CUtlBuffer& buf )
// Gotta preallocate the static props here so no rellocations take place
// the leaf list stores pointers to these tricky little guys.
m_StaticProps.AddMultipleToTail(count);
bool bSkip = false;
m_StaticProps.EnsureCapacity(count);
for ( int i = 0; i < count; ++i )
{
// Reset every loop.
bSkip = false;
StaticPropLump_t lump;
switch ( nLumpVersion )
{
case 4: UnserializeLump<StaticPropLumpV4_t>(&lump, buf); break;
case 5: UnserializeLump<StaticPropLumpV5_t>(&lump, buf); break;
case 6: UnserializeLump<StaticPropLumpV6_t>(&lump, buf); break;
case 7: // Falls down to version 10. We promoted TF to version 10 to deal with SFM.
case 10: UnserializeLump<StaticPropLump_t>(&lump, buf); break;
break;
default:
Assert("Unexpected version while deserializing lumps.");
case 4:
buf.Get( &lump, sizeof(StaticPropLumpV4_t) );
lump.m_flForcedFadeScale = 1.0f;
lump.m_nMinCPULevel = lump.m_nMaxCPULevel = lump.m_nMinGPULevel = lump.m_nMaxGPULevel = 0;
lump.m_DiffuseModulation.r = lump.m_DiffuseModulation.g = lump.m_DiffuseModulation.b = lump.m_DiffuseModulation.a = 255; // default color/alpha modulation to identity
lump.m_bDisableX360 = false;
lump.m_FlagsEx = 0;
break;
case 5:
buf.Get( &lump, sizeof(StaticPropLumpV5_t) );
lump.m_nMinCPULevel = lump.m_nMaxCPULevel = lump.m_nMinGPULevel = lump.m_nMaxGPULevel = 0;
lump.m_DiffuseModulation.r = lump.m_DiffuseModulation.g = lump.m_DiffuseModulation.b = lump.m_DiffuseModulation.a = 255; // default color/alpha modulation to identity
lump.m_bDisableX360 = false;
lump.m_FlagsEx = 0;
break;
case 6:
buf.Get( &lump, sizeof( StaticPropLumpV6_t ) );
lump.m_nMinCPULevel = lump.m_nMaxCPULevel = lump.m_nMinGPULevel = lump.m_nMaxGPULevel = 0;
lump.m_DiffuseModulation.r = lump.m_DiffuseModulation.g = lump.m_DiffuseModulation.b = lump.m_DiffuseModulation.a = 255; // default color/alpha modulation to identity
lump.m_bDisableX360 = false;
lump.m_FlagsEx = 0;
break;
case 7:
buf.Get( &lump, sizeof( StaticPropLumpV7_t ) );
lump.m_nMinCPULevel = lump.m_nMaxCPULevel = lump.m_nMinGPULevel = lump.m_nMaxGPULevel = 0;
lump.m_bDisableX360 = false;
lump.m_FlagsEx = 0;
break;
case 8:
buf.Get( &lump, sizeof( StaticPropLumpV8_t ) );
lump.m_bDisableX360 = false;
lump.m_FlagsEx = 0;
break;
case 9:
buf.Get( &lump, sizeof( StaticPropLumpV9_t ) );
lump.m_FlagsEx = 0;
break;
case 10:
buf.Get( &lump, sizeof( StaticPropLumpV10_t ) );
break;
case 11:
buf.Get( &lump, sizeof( StaticPropLump_t ) );
break;
}
m_StaticProps[i].Init( i, lump, m_StaticPropDict[lump.m_PropType].m_pModel );
int j = m_StaticProps.AddToTail();
m_StaticProps[j].Init( j, lump, m_StaticPropDict[lump.m_PropType].m_pModel );
// For distance-based fading, keep a list of the things that need
// to be faded out. Not sure if this is the optimal way of doing it

30
public/bspfile.h

@ -22,7 +22,7 @@ @@ -22,7 +22,7 @@
// MINBSPVERSION is the minimum acceptable version. The engine will load MINBSPVERSION through BSPVERSION
#define MINBSPVERSION 19
#define BSPVERSION 20
#define BSPVERSION 21
// This needs to match the value in gl_lightmap.h
@ -62,7 +62,7 @@ @@ -62,7 +62,7 @@
#define MAX_MAP_ENTITIES 8192
#define MAX_MAP_TEXINFO 12288
#define MAX_MAP_TEXDATA 2048
#define MAX_MAP_DISPINFO 2048
#define MAX_MAP_DISPINFO 10240
#define MAX_MAP_DISP_VERTS ( MAX_MAP_DISPINFO * ((1<<MAX_MAP_DISP_POWER)+1) * ((1<<MAX_MAP_DISP_POWER)+1) )
#define MAX_MAP_DISP_TRIS ( (1 << MAX_MAP_DISP_POWER) * (1 << MAX_MAP_DISP_POWER) * 2 )
#define MAX_DISPVERTS NUM_DISP_POWER_VERTS( MAX_MAP_DISP_POWER )
@ -364,6 +364,7 @@ enum @@ -364,6 +364,7 @@ enum
LUMP_OCCLUSION_VERSION = 2,
LUMP_LEAFS_VERSION = 1,
LUMP_LEAF_AMBIENT_LIGHTING_VERSION = 1,
LUMP_WORLDLIGHTS_VERSION = 1
};
@ -966,7 +967,31 @@ enum emittype_t @@ -966,7 +967,31 @@ enum emittype_t
// Flags for dworldlight_t::flags
#define DWL_FLAGS_INAMBIENTCUBE 0x0001 // This says that the light was put into the per-leaf ambient cubes.
#define DWL_FLAGS_CASTENTITYSHADOWS 0x0002 // This says that the light will cast shadows from entities
// Old version of the worldlight struct, used for backward compatibility loading.
struct dworldlight_version0_t
{
DECLARE_BYTESWAP_DATADESC();
Vector origin;
Vector intensity;
Vector normal; // for surfaces and spotlights
int cluster;
emittype_t type;
int style;
float stopdot; // start of penumbra for emit_spotlight
float stopdot2; // end of penumbra for emit_spotlight
float exponent; //
float radius; // cutoff distance
// falloff for emit_spotlight + emit_point:
// 1 / (constant_attn + linear_attn * dist + quadratic_attn * dist^2)
float constant_attn;
float linear_attn;
float quadratic_attn;
int flags; // Uses a combination of the DWL_FLAGS_ defines.
int texinfo; //
int owner; // entity that this light it relative to
};
struct dworldlight_t
{
@ -974,6 +999,7 @@ struct dworldlight_t @@ -974,6 +999,7 @@ struct dworldlight_t
Vector origin;
Vector intensity;
Vector normal; // for surfaces and spotlights
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)
int cluster;
emittype_t type;
int style;

149
public/gamebspfile.h

@ -203,7 +203,7 @@ struct StaticPropLumpV6_t @@ -203,7 +203,7 @@ struct StaticPropLumpV6_t
// int m_Lighting; // index into the GAMELUMP_STATIC_PROP_LIGHTING lump
};
struct StaticPropLump_t
struct StaticPropLumpV7_t
{
DECLARE_BYTESWAP_DATADESC();
Vector m_Origin;
@ -212,6 +212,7 @@ struct StaticPropLump_t @@ -212,6 +212,7 @@ struct StaticPropLump_t
unsigned short m_FirstLeaf;
unsigned short m_LeafCount;
unsigned char m_Solid;
unsigned char m_Flags;
int m_Skin;
float m_FadeMinDist;
float m_FadeMaxDist;
@ -220,58 +221,108 @@ struct StaticPropLump_t @@ -220,58 +221,108 @@ struct StaticPropLump_t
unsigned short m_nMinDXLevel;
unsigned short m_nMaxDXLevel;
// int m_Lighting; // index into the GAMELUMP_STATIC_PROP_LIGHTING lump
unsigned int m_Flags;
unsigned short m_nLightmapResolutionX;
unsigned short m_nLightmapResolutionY;
StaticPropLump_t& operator=(const StaticPropLumpV4_t& _rhs)
{
m_Origin = _rhs.m_Origin;
m_Angles = _rhs.m_Angles;
m_PropType = _rhs.m_PropType;
m_FirstLeaf = _rhs.m_FirstLeaf;
m_LeafCount = _rhs.m_LeafCount;
m_Solid = _rhs.m_Solid;
m_Flags = _rhs.m_Flags;
m_Skin = _rhs.m_Skin;
m_FadeMinDist = _rhs.m_FadeMinDist;
m_FadeMaxDist = _rhs.m_FadeMaxDist;
m_LightingOrigin = _rhs.m_LightingOrigin;
// These get potentially set twice--once here and once in the caller.
// Value judgement: This makes the code easier to work with, so unless it's a perf issue...
m_flForcedFadeScale = 1.0f;
m_nMinDXLevel = 0;
m_nMaxDXLevel = 0;
m_nLightmapResolutionX = 0;
m_nLightmapResolutionY = 0;
// Older versions don't want this.
m_Flags |= STATIC_PROP_NO_PER_TEXEL_LIGHTING;
return *this;
}
StaticPropLump_t& operator=(const StaticPropLumpV5_t& _rhs)
{
(*this) = reinterpret_cast<const StaticPropLumpV4_t&>(_rhs);
m_flForcedFadeScale = _rhs.m_flForcedFadeScale;
return *this;
}
StaticPropLump_t& operator=(const StaticPropLumpV6_t& _rhs)
{
(*this) = reinterpret_cast<const StaticPropLumpV5_t&>(_rhs);
m_nMinDXLevel = _rhs.m_nMinDXLevel;
m_nMaxDXLevel = _rhs.m_nMaxDXLevel;
return *this;
}
color32 m_DiffuseModulation; // per instance color and alpha modulation
};
struct StaticPropLumpV8_t
{
DECLARE_BYTESWAP_DATADESC();
Vector m_Origin;
QAngle m_Angles;
unsigned short m_PropType;
unsigned short m_FirstLeaf;
unsigned short m_LeafCount;
unsigned char m_Solid;
unsigned char m_Flags;
int m_Skin;
float m_FadeMinDist;
float m_FadeMaxDist;
Vector m_LightingOrigin;
float m_flForcedFadeScale;
unsigned char m_nMinCPULevel;
unsigned char m_nMaxCPULevel;
unsigned char m_nMinGPULevel;
unsigned char m_nMaxGPULevel;
// int m_Lighting; // index into the GAMELUMP_STATIC_PROP_LIGHTING lump
color32 m_DiffuseModulation; // per instance color and alpha modulation
};
struct StaticPropLumpV9_t
{
DECLARE_BYTESWAP_DATADESC();
Vector m_Origin;
QAngle m_Angles;
unsigned short m_PropType;
unsigned short m_FirstLeaf;
unsigned short m_LeafCount;
unsigned char m_Solid;
unsigned char m_Flags;
int m_Skin;
float m_FadeMinDist;
float m_FadeMaxDist;
Vector m_LightingOrigin;
float m_flForcedFadeScale;
unsigned char m_nMinCPULevel;
unsigned char m_nMaxCPULevel;
unsigned char m_nMinGPULevel;
unsigned char m_nMaxGPULevel;
// int m_Lighting; // index into the GAMELUMP_STATIC_PROP_LIGHTING lump
color32 m_DiffuseModulation; // per instance color and alpha modulation
bool m_bDisableX360;
};
// version 10
struct StaticPropLumpV10_t
{
DECLARE_BYTESWAP_DATADESC();
Vector m_Origin;
QAngle m_Angles;
unsigned short m_PropType;
unsigned short m_FirstLeaf;
unsigned short m_LeafCount;
unsigned char m_Solid;
unsigned char m_Flags;
int m_Skin;
float m_FadeMinDist;
float m_FadeMaxDist;
Vector m_LightingOrigin;
float m_flForcedFadeScale;
unsigned char m_nMinCPULevel;
unsigned char m_nMaxCPULevel;
unsigned char m_nMinGPULevel;
unsigned char m_nMaxGPULevel;
// int m_Lighting; // index into the GAMELUMP_STATIC_PROP_LIGHTING lump
color32 m_DiffuseModulation; // per instance color and alpha modulation
bool m_bDisableX360;
int m_FlagsEx; // more flags (introduced in v10)
};
// version 11
struct StaticPropLump_t
{
DECLARE_BYTESWAP_DATADESC();
Vector m_Origin;
QAngle m_Angles;
unsigned short m_PropType;
unsigned short m_FirstLeaf;
unsigned short m_LeafCount;
unsigned char m_Solid;
unsigned char m_Flags;
int m_Skin;
float m_FadeMinDist;
float m_FadeMaxDist;
Vector m_LightingOrigin;
float m_flForcedFadeScale;
unsigned char m_nMinCPULevel;
unsigned char m_nMaxCPULevel;
unsigned char m_nMinGPULevel;
unsigned char m_nMaxGPULevel;
// int m_Lighting; // index into the GAMELUMP_STATIC_PROP_LIGHTING lump
color32 m_DiffuseModulation; // per instance color and alpha modulation
bool m_bDisableX360;
int m_FlagsEx; // more flags (introduced in v10)
float m_flPropScale;
};
struct StaticPropLeafLump_t
{

Loading…
Cancel
Save