diff --git a/include/ifx.h b/include/ifx.h index 19b3522a7e..b239f96267 100644 --- a/include/ifx.h +++ b/include/ifx.h @@ -120,6 +120,12 @@ class IFxAction // Unused according to docs virtual bool getParticleTrackVelocity() = 0; + + // For Type::Sound actions: start a sound (on any channel) + virtual const std::string& getSoundShaderName() = 0; + + // For Type::Shockwave actions: the name of the shockwave entityDef + virtual const std::string& getShockwaveDefName() = 0; }; class IFxDeclaration : diff --git a/radiantcore/fx/FxAction.cpp b/radiantcore/fx/FxAction.cpp index 71248939e4..194fefa93c 100644 --- a/radiantcore/fx/FxAction.cpp +++ b/radiantcore/fx/FxAction.cpp @@ -199,6 +199,16 @@ bool FxAction::getParticleTrackVelocity() return _particleTrackVelocity; } +const std::string& FxAction::getSoundShaderName() +{ + return _soundShaderName; +} + +const std::string& FxAction::getShockwaveDefName() +{ + return _shockwaveDefName; +} + void FxAction::parseFromTokens(parser::DefTokeniser& tokeniser) { while (tokeniser.hasMoreTokens()) @@ -358,32 +368,16 @@ void FxAction::parseFromTokens(parser::DefTokeniser& tokeniser) { _particleTrackVelocity = true; } -#if 0 - if (!token.Icmp("sound")) { - src.ReadToken(&token); - FXAction.data = token; - FXAction.type = FX_SOUND; - - // precache it - declManager->FindSound(FXAction.data); - continue; - } - - if (!token.Icmp("ignoreMaster")) { - FXAction.shakeIgnoreMaster = true; - continue; + else if (token == "sound") + { + _type = Type::Sound; + _soundShaderName = tokeniser.nextToken(); } - - if (!token.Icmp("shockwave")) { - src.ReadToken(&token); - FXAction.data = token; - FXAction.type = FX_SHOCKWAVE; - - // precache the entity def - declManager->FindType(DECL_ENTITYDEF, FXAction.data); - continue; + else if (token == "shockwave") + { + _type = Type::Shockwave; + _shockwaveDefName = tokeniser.nextToken(); } -#endif else { rWarning() << "Unrecognised token '" << token << "' in FX " << _fx.getDeclName() << std::endl; diff --git a/radiantcore/fx/FxAction.h b/radiantcore/fx/FxAction.h index 523daacded..5b7e0aedc0 100644 --- a/radiantcore/fx/FxAction.h +++ b/radiantcore/fx/FxAction.h @@ -47,6 +47,8 @@ class FxAction : std::string _modelName; std::string _decalMaterialName; bool _particleTrackVelocity; + std::string _soundShaderName; + std::string _shockwaveDefName; public: using Ptr = std::shared_ptr; @@ -86,6 +88,8 @@ class FxAction : const std::string& getModelName() override; const std::string& getDecalMaterialName() override; bool getParticleTrackVelocity() override; + const std::string& getSoundShaderName() override; + const std::string& getShockwaveDefName() override; // Parses the action from the given tokens. // The opening brace { will already have been been consumed by the calling code diff --git a/test/Fx.cpp b/test/Fx.cpp index 42e99a014e..9181e089b2 100644 --- a/test/Fx.cpp +++ b/test/Fx.cpp @@ -240,4 +240,20 @@ TEST_F(FxTest, ParseActionParticleTrackVelocity) EXPECT_EQ(getFxByName("fx/parserTest/useModel")->getAction(2)->getParticleTrackVelocity(), true); } +TEST_F(FxTest, ParseActionSound) +{ + EXPECT_EQ(getFxByName("fx/parserTest/shake")->getAction(0)->getSoundShaderName(), ""); + + EXPECT_EQ(getFxByName("fx/parserTest/sound")->getAction(0)->getType(), fx::IFxAction::Type::Sound); + EXPECT_EQ(getFxByName("fx/parserTest/sound")->getAction(0)->getSoundShaderName(), "footsteps/stone"); +} + +TEST_F(FxTest, ParseActionShockwave) +{ + EXPECT_EQ(getFxByName("fx/parserTest/shake")->getAction(0)->getShockwaveDefName(), ""); + + EXPECT_EQ(getFxByName("fx/parserTest/shockwave")->getAction(0)->getType(), fx::IFxAction::Type::Shockwave); + EXPECT_EQ(getFxByName("fx/parserTest/shockwave")->getAction(0)->getShockwaveDefName(), "atdm:some_shockwave_def"); +} + } diff --git a/test/resources/tdm/fx/parsertest.fx b/test/resources/tdm/fx/parsertest.fx index 60a6292be0..57aa4973e1 100644 --- a/test/resources/tdm/fx/parsertest.fx +++ b/test/resources/tdm/fx/parsertest.fx @@ -181,3 +181,19 @@ fx fx/parserTest/decal decal "textures/decals/blood" } } + +fx fx/parserTest/sound +{ + { + delay 1.5 + sound "footsteps/stone" + } +} + +fx fx/parserTest/shockwave +{ + { + delay 1.5 + shockwave "atdm:some_shockwave_def" + } +} \ No newline at end of file