2022-04-06 15:37:28 -04:00
|
|
|
#include <STDInclude.hpp>
|
2022-06-22 11:36:06 -04:00
|
|
|
#include "IComWorld.hpp"
|
2017-01-19 16:23:59 -05:00
|
|
|
|
2017-03-20 05:38:30 -04:00
|
|
|
#define IW4X_COMMAP_VERSION 0
|
|
|
|
|
2017-01-19 16:23:59 -05:00
|
|
|
namespace Assets
|
|
|
|
{
|
2018-12-17 08:29:18 -05:00
|
|
|
void IComWorld::load(Game::XAssetHeader* header, const std::string& _name, Components::ZoneBuilder::Zone* builder)
|
2017-03-20 05:38:30 -04:00
|
|
|
{
|
2018-12-17 08:29:18 -05:00
|
|
|
std::string name = _name;
|
2017-03-20 05:38:30 -04:00
|
|
|
Utils::String::Replace(name, "maps/mp/", "");
|
|
|
|
Utils::String::Replace(name, ".d3dbsp", "");
|
|
|
|
|
|
|
|
Components::FileSystem::File mapFile(Utils::String::VA("comworld/%s.iw4xComWorld", name.data()));
|
|
|
|
|
|
|
|
if (mapFile.exists())
|
|
|
|
{
|
|
|
|
Utils::Stream::Reader reader(builder->getAllocator(), mapFile.getBuffer());
|
|
|
|
|
|
|
|
__int64 magic = reader.read<__int64>();
|
|
|
|
if (std::memcmp(&magic, "IW4xComW", 8))
|
|
|
|
{
|
2022-06-12 17:07:53 -04:00
|
|
|
Components::Logger::Error(Game::ERR_FATAL, "Reading comworld '{}' failed, header is invalid!", name);
|
2017-03-20 05:38:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int version = reader.read<int>();
|
|
|
|
if (version != IW4X_COMMAP_VERSION)
|
|
|
|
{
|
2022-06-12 17:07:53 -04:00
|
|
|
Components::Logger::Error(Game::ERR_FATAL, "Reading comworld '{}' failed, expected version is {}, but it was {}!", name, IW4X_COMMAP_VERSION, version);
|
2017-03-20 05:38:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
Game::ComWorld* asset = reader.readObject<Game::ComWorld>();
|
|
|
|
header->comWorld = asset;
|
|
|
|
|
|
|
|
if (asset->name)
|
|
|
|
{
|
|
|
|
asset->name = reader.readCString();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (asset->primaryLights)
|
|
|
|
{
|
|
|
|
asset->primaryLights = reader.readArray<Game::ComPrimaryLight>(asset->primaryLightCount);
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < asset->primaryLightCount; ++i)
|
|
|
|
{
|
|
|
|
Game::ComPrimaryLight* light = &asset->primaryLights[i];
|
|
|
|
|
|
|
|
if (light->defName)
|
|
|
|
{
|
|
|
|
light->defName = reader.readCString();
|
|
|
|
Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_LIGHT_DEF, light->defName, builder);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-19 16:23:59 -05:00
|
|
|
void IComWorld::mark(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)
|
|
|
|
{
|
|
|
|
Game::ComWorld* asset = header.comWorld;
|
2017-01-20 16:41:03 -05:00
|
|
|
|
2017-03-20 05:38:30 -04:00
|
|
|
if (asset->primaryLights)
|
2017-01-19 16:23:59 -05:00
|
|
|
{
|
2017-03-20 05:38:30 -04:00
|
|
|
for (unsigned int i = 0; i < asset->primaryLightCount; ++i)
|
2017-01-19 16:23:59 -05:00
|
|
|
{
|
2017-03-20 05:38:30 -04:00
|
|
|
if (asset->primaryLights[i].defName)
|
2017-01-19 16:23:59 -05:00
|
|
|
{
|
2017-03-20 05:38:30 -04:00
|
|
|
builder->loadAssetByName(Game::XAssetType::ASSET_TYPE_LIGHT_DEF, asset->primaryLights[i].defName, false);
|
2017-01-19 16:23:59 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void IComWorld::save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)
|
|
|
|
{
|
|
|
|
AssertSize(Game::ComWorld, 16);
|
|
|
|
|
|
|
|
Utils::Stream* buffer = builder->getBuffer();
|
|
|
|
Game::ComWorld* asset = header.comWorld;
|
|
|
|
Game::ComWorld* dest = buffer->dest<Game::ComWorld>();
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2017-03-20 05:38:30 -04:00
|
|
|
if (asset->primaryLights)
|
2017-01-19 16:23:59 -05:00
|
|
|
{
|
|
|
|
AssertSize(Game::ComPrimaryLight, 68);
|
|
|
|
buffer->align(Utils::Stream::ALIGN_4);
|
|
|
|
|
|
|
|
Game::ComPrimaryLight* destLights = buffer->dest<Game::ComPrimaryLight>();
|
2017-03-20 05:38:30 -04:00
|
|
|
buffer->saveArray(asset->primaryLights, asset->primaryLightCount);
|
2017-01-19 16:23:59 -05:00
|
|
|
|
2017-03-20 05:38:30 -04:00
|
|
|
for (unsigned int i = 0; i < asset->primaryLightCount; ++i)
|
2017-01-19 16:23:59 -05:00
|
|
|
{
|
|
|
|
Game::ComPrimaryLight* destLight = &destLights[i];
|
2017-03-20 05:38:30 -04:00
|
|
|
Game::ComPrimaryLight* light = &asset->primaryLights[i];
|
2017-01-19 16:23:59 -05:00
|
|
|
|
2017-03-20 05:38:30 -04:00
|
|
|
if (light->defName)
|
2017-01-19 16:23:59 -05:00
|
|
|
{
|
2017-03-20 05:38:30 -04:00
|
|
|
buffer->saveString(light->defName);
|
|
|
|
Utils::Stream::ClearPointer(&destLight->defName);
|
2017-01-19 16:23:59 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-20 05:38:30 -04:00
|
|
|
Utils::Stream::ClearPointer(&dest->primaryLights);
|
2017-01-19 16:23:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
buffer->popBlock();
|
|
|
|
}
|
|
|
|
}
|