2022-02-27 07:53:44 -05:00
# include <STDInclude.hpp>
2017-01-19 16:23:59 -05:00
2017-03-20 05:38:30 -04:00
# define IW4X_LIGHT_VERSION "0"
2017-01-19 16:23:59 -05:00
namespace Assets
{
2018-12-17 08:29:18 -05:00
void IGfxLightDef : : load ( Game : : XAssetHeader * header , const std : : string & name , Components : : ZoneBuilder : : Zone * builder )
2017-03-20 05:38:30 -04:00
{
Components : : FileSystem : : File mapFile ( Utils : : String : : VA ( " lights/%s.iw4xLight " , name . data ( ) ) ) ;
if ( mapFile . exists ( ) )
{
Utils : : Stream : : Reader reader ( builder - > getAllocator ( ) , mapFile . getBuffer ( ) ) ;
char * magic = reader . readArray < char > ( 7 ) ;
if ( std : : memcmp ( magic , " IW4xLit " , 7 ) )
{
Components : : Logger : : Error ( 0 , " Reading light '%s' failed, header is invalid! " , name . data ( ) ) ;
}
std : : string version ;
version . push_back ( reader . read < char > ( ) ) ;
if ( version ! = IW4X_LIGHT_VERSION )
{
Components : : Logger : : Error ( " Reading light '%s' failed, expected version is %d, but it was %d! " , name . data ( ) , atoi ( IW4X_LIGHT_VERSION ) , atoi ( version . data ( ) ) ) ;
}
Game : : GfxLightDef * asset = reader . readObject < Game : : GfxLightDef > ( ) ;
header - > lightDef = asset ;
if ( asset - > name )
{
asset - > name = reader . readCString ( ) ;
}
if ( asset - > attenuation . image )
{
asset - > attenuation . image = Components : : AssetHandler : : FindAssetForZone ( Game : : XAssetType : : ASSET_TYPE_IMAGE , reader . readString ( ) . data ( ) , builder ) . image ;
}
}
}
2017-01-19 16:23:59 -05:00
void IGfxLightDef : : mark ( Game : : XAssetHeader header , Components : : ZoneBuilder : : Zone * builder )
{
Game : : GfxLightDef * asset = header . lightDef ;
if ( asset - > attenuation . image )
{
builder - > loadAsset ( Game : : XAssetType : : ASSET_TYPE_IMAGE , asset - > attenuation . image ) ;
}
}
void IGfxLightDef : : save ( Game : : XAssetHeader header , Components : : ZoneBuilder : : Zone * builder )
{
AssertSize ( Game : : GfxLightDef , 16 ) ;
AssertSize ( Game : : GfxLightImage , 8 ) ;
Utils : : Stream * buffer = builder - > getBuffer ( ) ;
Game : : GfxLightDef * asset = header . lightDef ;
Game : : GfxLightDef * dest = buffer - > dest < Game : : GfxLightDef > ( ) ;
buffer - > save ( asset ) ;
buffer - > pushBlock ( Game : : XFILE_BLOCK_VIRTUAL ) ;
if ( asset - > name )
{
buffer - > saveString ( builder - > getAssetName ( this - > getType ( ) , asset - > name ) ) ;
Utils : : Stream : : ClearPointer ( & dest - > name ) ;
}
if ( asset - > attenuation . image )
{
dest - > attenuation . image = builder - > saveSubAsset ( Game : : XAssetType : : ASSET_TYPE_IMAGE , asset - > attenuation . image ) . image ;
}
buffer - > popBlock ( ) ;
}
}