From 2d828d27dbe1455d802e326820d7d28aab6d5333 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Thu, 9 Feb 2017 21:14:28 +0100 Subject: [PATCH] [IFxEffectDef] Continue with the efx parser --- .../Modules/AssetInterfaces/IFxEffectDef.cpp | 48 ++++++++++++++++--- src/Game/Functions.cpp | 1 + src/Game/Functions.hpp | 3 ++ 3 files changed, 46 insertions(+), 6 deletions(-) diff --git a/src/Components/Modules/AssetInterfaces/IFxEffectDef.cpp b/src/Components/Modules/AssetInterfaces/IFxEffectDef.cpp index 6a6475ea..c5c7f0f5 100644 --- a/src/Components/Modules/AssetInterfaces/IFxEffectDef.cpp +++ b/src/Components/Modules/AssetInterfaces/IFxEffectDef.cpp @@ -4,8 +4,8 @@ namespace Assets { void IFxEffectDef::load(Game::XAssetHeader* /*header*/, std::string name, Components::ZoneBuilder::Zone* /*builder*/) { -#if 0 - Components::FileSystem::File rawFx(fmt::sprintf("fx/%s.efx", name.data())); +#ifdef DEBUG + Components::FileSystem::File rawFx(Utils::String::VA("fx/%s.efx", name.data())); if (rawFx.exists()) { const char* session = rawFx.getBuffer().data(); @@ -30,12 +30,48 @@ namespace Assets Game::FxEditorEffectDef efx; ZeroMemory(&efx, sizeof(efx)); -// for (int i = 0; i < FX_ELEM_FIELD_COUNT; ++i) -// { -// Game::s_elemFields[i].handler(&session, efx.elems); -// } + for (efx.elemCount = 0; ; ++efx.elemCount) + { + const char* value = Game::Com_Parse(&session); + if (!value) break; + if (*value != '{') + { + Components::Logger::Error("Expected '{' to start a new segment, found '%s' instead.\n", value); + } + + if (efx.elemCount >= ARRAYSIZE(efx.elems)) + { + Components::Logger::Error("Cannot have more than %i segments.\n", ARRAYSIZE(efx.elems)); + } + + Game::FxEditorElemDef* element = &efx.elems[efx.elemCount]; + // TODO: Initialize some stuff here + + while (true) + { + std::string newValue = Game::Com_Parse(&session); + if (newValue[0] != '}') break; + + for (int i = 0; i < FX_ELEM_FIELD_COUNT; ++i) + { + if(Game::s_elemFields[i].keyName == std::string(newValue)) + { + // TODO: Allow loading assets from raw! + if(Game::s_elemFields[i].handler(&session, element)) break; + Components::Logger::Error("Failed to parse element %s!\n", newValue); + } + } + + if (!Game::Com_MatchToken(&session, ";", 1)) + { + Components::Logger::Error("Expected token ';'\n"); + } + } + } Game::Com_EndParseSession(); + + // TODO: Convert editor fx to real fx } #endif } diff --git a/src/Game/Functions.cpp b/src/Game/Functions.cpp index 0fbfa024..2a6a364d 100644 --- a/src/Game/Functions.cpp +++ b/src/Game/Functions.cpp @@ -35,6 +35,7 @@ namespace Game Com_BeginParseSession_t Com_BeginParseSession = Com_BeginParseSession_t(0x4AAB80); Com_SetSpaceDelimited_t Com_SetSpaceDelimited = Com_SetSpaceDelimited_t(0x4FC710); Com_Parse_t Com_Parse = Com_Parse_t(0x474D60); + Com_MatchToken_t Com_MatchToken = Com_MatchToken_t(0x447130); Com_SetSlowMotion_t Com_SetSlowMotion = Com_SetSlowMotion_t(0x446E20); Con_DrawMiniConsole_t Con_DrawMiniConsole = Con_DrawMiniConsole_t(0x464F30); diff --git a/src/Game/Functions.hpp b/src/Game/Functions.hpp index e2553ce3..cdf1b52d 100644 --- a/src/Game/Functions.hpp +++ b/src/Game/Functions.hpp @@ -86,6 +86,9 @@ namespace Game typedef char* (__cdecl * Com_Parse_t)(const char **data_p); extern Com_Parse_t Com_Parse; + typedef bool (__cdecl * Com_MatchToken_t)(const char **data_p, const char* token, int size); + extern Com_MatchToken_t Com_MatchToken; + typedef void(__cdecl * Com_SetSlowMotion_t)(float start, float end, int duration); extern Com_SetSlowMotion_t Com_SetSlowMotion;