Various fixes and optimizations.

This commit is contained in:
momo5502 2016-01-22 13:18:26 +01:00
parent ac4548f4c2
commit f509e67953
12 changed files with 158 additions and 129 deletions

View File

@ -97,6 +97,7 @@ workspace "iw4x"
-- Pre-compiled header -- Pre-compiled header
pchheader "STDInclude.hpp" -- must be exactly same as used in #include directives pchheader "STDInclude.hpp" -- must be exactly same as used in #include directives
pchsource "src/STDInclude.cpp" -- real path pchsource "src/STDInclude.cpp" -- real path
buildoptions { "-Zm200" } -- allocate ~150mb memory for the precompiled header. This should be enough, increase if necessary
-- Dependency on zlib, json11 and asio -- Dependency on zlib, json11 and asio
links { "zlib", "json11", "pdcurses" } links { "zlib", "json11", "pdcurses" }

View File

@ -2,16 +2,6 @@
namespace Assets namespace Assets
{ {
void IGfxImage::Save_GfxImageLoadDef(Components::ZoneBuilder::Zone* builder, const char* name)
{
Game::GfxImageLoadDef loadDef;
ZeroMemory(&loadDef, sizeof(loadDef));
Utils::Stream* buffer = builder->GetBuffer();
}
void IGfxImage::Save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) void IGfxImage::Save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)
{ {
Assert_AssetStruct(Game::GfxImage, 32); Assert_AssetStruct(Game::GfxImage, 32);

View File

@ -5,8 +5,5 @@ namespace Assets
virtual Game::XAssetType GetType() override { return Game::XAssetType::ASSET_TYPE_IMAGE; }; virtual Game::XAssetType GetType() override { return Game::XAssetType::ASSET_TYPE_IMAGE; };
virtual void Save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override; virtual void Save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override;
private:
void Save_GfxImageLoadDef(Components::ZoneBuilder::Zone* builder, const char* name);
}; };
} }

View File

@ -59,73 +59,100 @@ namespace Assets
{ {
Assert_AssetStruct(Game::MaterialTextureDef, 12); Assert_AssetStruct(Game::MaterialTextureDef, 12);
buffer->Align(Utils::Stream::ALIGN_4); // Pointer/Offset insertion is untested, but it worked in T6, so I think it's fine
if (builder->HasPointer(asset->textureTable))
Game::MaterialTextureDef* destTextureTable = (Game::MaterialTextureDef*)buffer->At();
buffer->SaveArray(asset->textureTable, asset->textureCount);
for (char i = 0; i < asset->textureCount; i++)
{ {
Game::MaterialTextureDef* destTextureDef = &destTextureTable[i]; dest->textureTable = builder->GetPointer(asset->textureTable);
Game::MaterialTextureDef* textureDef = &asset->textureTable[i]; }
else
{
buffer->Align(Utils::Stream::ALIGN_4);
builder->StorePointer(asset->textureTable);
if (textureDef->semantic == SEMANTIC_WATER_MAP) Game::MaterialTextureDef* destTextureTable = (Game::MaterialTextureDef*)buffer->At();
buffer->SaveArray(asset->textureTable, asset->textureCount);
for (char i = 0; i < asset->textureCount; i++)
{ {
Assert_AssetStruct(Game::water_t, 68); Game::MaterialTextureDef* destTextureDef = &destTextureTable[i];
Game::MaterialTextureDef* textureDef = &asset->textureTable[i];
Game::water_t* destWater = (Game::water_t*)buffer->At(); if (textureDef->semantic == SEMANTIC_WATER_MAP)
Game::water_t* water = textureDef->info.water;
if (water)
{ {
buffer->Align(Utils::Stream::ALIGN_4); Assert_AssetStruct(Game::water_t, 68);
buffer->Save(water, sizeof(Game::water_t));
destTextureDef->info.water = (Game::water_t *)-1;
// Save_water_t Game::water_t* destWater = (Game::water_t*)buffer->At();
if (water->H0X) Game::water_t* water = textureDef->info.water;
if (water)
{ {
buffer->Align(Utils::Stream::ALIGN_4); buffer->Align(Utils::Stream::ALIGN_4);
buffer->Save(water->H0X, 8, water->M * water->N); buffer->Save(water, sizeof(Game::water_t));
destWater->H0X = (float *)-1; destTextureDef->info.water = (Game::water_t *) - 1;
}
if (water->H0Y) // Save_water_t
{ if (water->H0X)
buffer->Align(Utils::Stream::ALIGN_4); {
buffer->Save(water->H0Y, 4, water->M * water->N); buffer->Align(Utils::Stream::ALIGN_4);
destWater->H0Y = (float *)-1; buffer->Save(water->H0X, 8, water->M * water->N);
} destWater->H0X = (float *)-1;
}
if (water->image) if (water->H0Y)
{ {
destWater->image = builder->RequireAsset(Game::XAssetType::ASSET_TYPE_IMAGE, water->image->name).image; buffer->Align(Utils::Stream::ALIGN_4);
buffer->Save(water->H0Y, 4, water->M * water->N);
destWater->H0Y = (float *)-1;
}
if (water->image)
{
destWater->image = builder->RequireAsset(Game::XAssetType::ASSET_TYPE_IMAGE, water->image->name).image;
}
} }
} }
else if (textureDef->info.image)
{
destTextureDef->info.image = builder->RequireAsset(Game::XAssetType::ASSET_TYPE_IMAGE, textureDef->info.image->name).image;
}
} }
else if(textureDef->info.image)
{
destTextureDef->info.image = builder->RequireAsset(Game::XAssetType::ASSET_TYPE_IMAGE, textureDef->info.image->name).image;
}
}
dest->textureTable = (Game::MaterialTextureDef*)-1; dest->textureTable = (Game::MaterialTextureDef*) - 1;
}
} }
if (asset->constantTable) if (asset->constantTable)
{ {
Assert_AssetStruct(Game::MaterialConstantDef, 32); Assert_AssetStruct(Game::MaterialConstantDef, 32);
buffer->Align(Utils::Stream::ALIGN_16); if (builder->HasPointer(asset->constantTable))
buffer->SaveArray(asset->constantTable, asset->constantCount); {
dest->constantTable = (Game::MaterialConstantDef *)-1; dest->constantTable = builder->GetPointer(asset->constantTable);
}
else
{
buffer->Align(Utils::Stream::ALIGN_16);
builder->StorePointer(asset->constantTable);
buffer->SaveArray(asset->constantTable, asset->constantCount);
dest->constantTable = (Game::MaterialConstantDef *) - 1;
}
} }
if (asset->stateBitTable) if (asset->stateBitTable)
{ {
buffer->Align(Utils::Stream::ALIGN_4); if (builder->HasPointer(asset->stateBitTable))
buffer->Save(asset->stateBitTable, 8, asset->stateBitsCount); {
dest->stateBitTable = (void *)-1; dest->stateBitTable = builder->GetPointer(asset->stateBitTable);
}
else
{
buffer->Align(Utils::Stream::ALIGN_4);
builder->StorePointer(asset->stateBitTable);
buffer->Save(asset->stateBitTable, 8, asset->stateBitsCount);
dest->stateBitTable = (void *)-1;
}
} }
buffer->PopBlock(); buffer->PopBlock();

View File

@ -60,56 +60,64 @@ namespace Assets
if (technique) if (technique)
{ {
// Size-check is obsolete, as the structure is dynamic if (builder->HasPointer(technique))
buffer->Align(Utils::Stream::ALIGN_4);
Game::MaterialTechnique* destTechnique = (Game::MaterialTechnique*)buffer->At();
buffer->Save(technique, 8);
dest->techniques[i] = (Game::MaterialTechnique*) - 1;
// Save_MaterialPassArray
for (short i = 0; i < technique->numPasses; i++)
{ {
Assert_AssetStruct(Game::MaterialPass, 20); dest->techniques[i] = builder->GetPointer(technique);
Game::MaterialPass* destPass = (Game::MaterialPass*)buffer->At();
Game::MaterialPass* pass = &technique->passes[i];
buffer->Save(pass, sizeof(Game::MaterialPass));
if (pass->vertexDecl)
{
destPass->vertexDecl = builder->RequireAsset(Game::XAssetType::ASSET_TYPE_VERTEXDECL, pass->vertexDecl->name).vertexDecl;
}
if (pass->vertexShader)
{
destPass->vertexShader = builder->RequireAsset(Game::XAssetType::ASSET_TYPE_VERTEXSHADER, pass->vertexShader->name).vertexShader;
}
if (pass->pixelShader)
{
destPass->pixelShader = builder->RequireAsset(Game::XAssetType::ASSET_TYPE_PIXELSHADER, pass->pixelShader->name).pixelShader;
}
if (pass->argumentDef)
{
buffer->Align(Utils::Stream::ALIGN_4);
buffer->SaveArray(pass->argumentDef, pass->argCount1 + pass->argCount2 + pass->argCount3);
destPass->argumentDef = (Game::ShaderArgumentDef*)-1;
}
}
// We absolutely have to write something here!
if (technique->name)
{
buffer->SaveString(technique->name);
} }
else else
{ {
buffer->SaveString(""); // Size-check is obsolete, as the structure is dynamic
} buffer->Align(Utils::Stream::ALIGN_4);
builder->StorePointer(technique);
destTechnique->name = (char*)-1; Game::MaterialTechnique* destTechnique = (Game::MaterialTechnique*)buffer->At();
buffer->Save(technique, 8);
// Save_MaterialPassArray
for (short i = 0; i < technique->numPasses; i++)
{
Assert_AssetStruct(Game::MaterialPass, 20);
Game::MaterialPass* destPass = (Game::MaterialPass*)buffer->At();
Game::MaterialPass* pass = &technique->passes[i];
buffer->Save(pass, sizeof(Game::MaterialPass));
if (pass->vertexDecl)
{
destPass->vertexDecl = builder->RequireAsset(Game::XAssetType::ASSET_TYPE_VERTEXDECL, pass->vertexDecl->name).vertexDecl;
}
if (pass->vertexShader)
{
destPass->vertexShader = builder->RequireAsset(Game::XAssetType::ASSET_TYPE_VERTEXSHADER, pass->vertexShader->name).vertexShader;
}
if (pass->pixelShader)
{
destPass->pixelShader = builder->RequireAsset(Game::XAssetType::ASSET_TYPE_PIXELSHADER, pass->pixelShader->name).pixelShader;
}
if (pass->argumentDef)
{
buffer->Align(Utils::Stream::ALIGN_4);
buffer->SaveArray(pass->argumentDef, pass->argCount1 + pass->argCount2 + pass->argCount3);
destPass->argumentDef = (Game::ShaderArgumentDef*) - 1;
}
}
// We absolutely have to write something here!
if (technique->name)
{
buffer->SaveString(technique->name);
}
else
{
buffer->SaveString("");
}
destTechnique->name = (char*)-1;
dest->techniques[i] = (Game::MaterialTechnique*) - 1;
}
} }
} }

View File

@ -13,6 +13,9 @@ namespace Components
Discovery::Discovery() Discovery::Discovery()
{ {
Dvar::Register<int>("net_discoveryPortRangeMin", 25000, 0, 65535, Game::dvar_flag::DVAR_FLAG_SAVED, "Minimum scan range port for local server discovery");
Dvar::Register<int>("net_discoveryPortRangeMax", 35000, 1, 65536, Game::dvar_flag::DVAR_FLAG_SAVED, "Maximum scan range port for local server discovery");
Discovery::DiscoveryContainer.Perform = false; Discovery::DiscoveryContainer.Perform = false;
Discovery::DiscoveryContainer.Terminate = false; Discovery::DiscoveryContainer.Terminate = false;
Discovery::DiscoveryContainer.Thread = new std::thread([] () Discovery::DiscoveryContainer.Thread = new std::thread([] ()
@ -28,7 +31,9 @@ namespace Components
Discovery::DiscoveryContainer.Challenge = Utils::VA("%d", Game::Com_Milliseconds()); Discovery::DiscoveryContainer.Challenge = Utils::VA("%d", Game::Com_Milliseconds());
//Network::BroadcastAll("discovery\n"); //Network::BroadcastAll("discovery\n");
Network::BroadcastRange(25000, 35000, Utils::VA("discovery\n%s", Discovery::DiscoveryContainer.Challenge.data())); unsigned int minPort = Dvar::Var("net_discoveryPortRangeMin").Get<unsigned int>();
unsigned int maxPort = Dvar::Var("net_discoveryPortRangeMax").Get<unsigned int>();
Network::BroadcastRange(minPort, maxPort, Utils::VA("discovery\n%s", Discovery::DiscoveryContainer.Challenge.data()));
Logger::Print("Discovery sent within %dms, awaiting responses...\n", Game::Com_Milliseconds() - start); Logger::Print("Discovery sent within %dms, awaiting responses...\n", Game::Com_Milliseconds() - start);

View File

@ -42,6 +42,10 @@ namespace Components
return 0; return 0;
} }
template <> unsigned int Dvar::Var::Get()
{
return (unsigned int)this->Get<int>();
}
template <> float Dvar::Var::Get() template <> float Dvar::Var::Get()
{ {
if (this->dvar && this->dvar->type == Game::dvar_type::DVAR_TYPE_FLOAT) if (this->dvar && this->dvar->type == Game::dvar_type::DVAR_TYPE_FLOAT)

View File

@ -105,6 +105,18 @@ namespace Components
float color[4] = { 1.0f, 1.0f, 1.0f, (Game::CL_IsCgameInitialized() ? 0.3f : 1.0f) }; float color[4] = { 1.0f, 1.0f, 1.0f, (Game::CL_IsCgameInitialized() ? 0.3f : 1.0f) };
Game::R_AddCmdDrawText(Utils::VA("Loading FastFile: %s", FastFiles::Current().data()), 0x7FFFFFFF, font, 5.0f, (float)(Renderer::Height() - 5), 1.0f, 1.0f, 0.0f, color, 0); Game::R_AddCmdDrawText(Utils::VA("Loading FastFile: %s", FastFiles::Current().data()), 0x7FFFFFFF, font, 5.0f, (float)(Renderer::Height() - 5), 1.0f, 1.0f, 0.0f, color, 0);
}); });
Command::Add("loadzone", [] (Command::Params params)
{
if (params.Length() < 2) return;
Game::XZoneInfo info;
info.name = params[1];
info.allocFlags = 0x01000000;
info.freeFlags = 0;
Game::DB_LoadXAssets(&info, 1, true);
});
} }
FastFiles::~FastFiles() FastFiles::~FastFiles()

View File

@ -330,6 +330,11 @@ namespace Components
ZoneBuilder::Zone::PointerMap[pointer] = ZoneBuilder::Zone::Buffer.GetPackedOffset(); ZoneBuilder::Zone::PointerMap[pointer] = ZoneBuilder::Zone::Buffer.GetPackedOffset();
} }
int ZoneBuilder::Zone::AddScriptString(std::string str)
{
return ZoneBuilder::Zone::AddScriptString(Game::SL_GetString(str.data(), 0));
}
// Mark a scriptString for writing and map it. // Mark a scriptString for writing and map it.
int ZoneBuilder::Zone::AddScriptString(unsigned short gameIndex) int ZoneBuilder::Zone::AddScriptString(unsigned short gameIndex)
{ {
@ -405,17 +410,6 @@ namespace Components
return (Flags::HasFlag("zonebuilder") && !Dedicated::IsDedicated()); return (Flags::HasFlag("zonebuilder") && !Dedicated::IsDedicated());
} }
// TODO: Remove and replace with loadzone command
void TestZoneLoading(Game::XZoneInfo *zoneInfo, unsigned int zoneCount, int sync)
{
std::vector<Game::XZoneInfo> data;
Utils::Merge(data, zoneInfo, zoneCount);
data.push_back({ "penis", zoneInfo->allocFlags, zoneInfo->freeFlags });
Game::DB_LoadXAssets(data.data(), data.size(), sync);
}
ZoneBuilder::ZoneBuilder() ZoneBuilder::ZoneBuilder()
{ {
static_assert(sizeof(Game::XFileHeader) == 21, "Invalid XFileHeader structure!"); static_assert(sizeof(Game::XFileHeader) == 21, "Invalid XFileHeader structure!");
@ -449,7 +443,7 @@ namespace Components
// Prevent destroying textures // Prevent destroying textures
Utils::Hook::Set<BYTE>(0x51F03D, 0xEB); Utils::Hook::Set<BYTE>(0x51F03D, 0xEB);
Command::Add("build", [] (Command::Params params) Command::Add("buildzone", [] (Command::Params params)
{ {
if (params.Length() < 2) return; if (params.Length() < 2) return;
@ -473,19 +467,5 @@ namespace Components
} }
}); });
} }
//else
//Utils::Hook(0x4546DF, TestZoneLoading, HOOK_CALL).Install()->Quick();
Command::Add("loadzone", [] (Command::Params params)
{
if (params.Length() < 2) return;
Game::XZoneInfo info;
info.name = params[1];
info.allocFlags = 0x01000000;
info.freeFlags = 0;
Game::DB_LoadXAssets(&info, 1, true);
});
} }
} }

View File

@ -29,6 +29,7 @@ namespace Components
bool LoadAsset(Game::XAssetType type, std::string name); bool LoadAsset(Game::XAssetType type, std::string name);
int AddScriptString(unsigned short gameIndex); int AddScriptString(unsigned short gameIndex);
int AddScriptString(std::string str);
int FindScriptString(std::string str); int FindScriptString(std::string str);
void MapScriptString(unsigned short* gameIndex); void MapScriptString(unsigned short* gameIndex);

View File

@ -121,6 +121,7 @@ namespace Game
SetConsole_t SetConsole = (SetConsole_t)0x44F060; SetConsole_t SetConsole = (SetConsole_t)0x44F060;
SL_ConvertToString_t SL_ConvertToString = (SL_ConvertToString_t)0x4EC1D0; SL_ConvertToString_t SL_ConvertToString = (SL_ConvertToString_t)0x4EC1D0;
SL_GetString_t SL_GetString = (SL_GetString_t)0x4CDC10;
Steam_JoinLobby_t Steam_JoinLobby = (Steam_JoinLobby_t)0x49CF70; Steam_JoinLobby_t Steam_JoinLobby = (Steam_JoinLobby_t)0x49CF70;

View File

@ -280,9 +280,12 @@ namespace Game
typedef void(__cdecl * SetConsole_t)(const char* cvar, const char* value); typedef void(__cdecl * SetConsole_t)(const char* cvar, const char* value);
extern SetConsole_t SetConsole; extern SetConsole_t SetConsole;
typedef char* (__cdecl * SL_ConvertToString_t)(unsigned short); typedef char* (__cdecl * SL_ConvertToString_t)(unsigned short stringValue);
extern SL_ConvertToString_t SL_ConvertToString; extern SL_ConvertToString_t SL_ConvertToString;
typedef short(__cdecl * SL_GetString_t)(const char *str, unsigned int user);
extern SL_GetString_t SL_GetString;
typedef void(__cdecl * Steam_JoinLobby_t)(SteamID, char); typedef void(__cdecl * Steam_JoinLobby_t)(SteamID, char);
extern Steam_JoinLobby_t Steam_JoinLobby; extern Steam_JoinLobby_t Steam_JoinLobby;