Skip to content

Commit

Permalink
#6092: Action parsing code and unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Sep 6, 2022
1 parent bf99b84 commit 6ff88a4
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 24 deletions.
6 changes: 6 additions & 0 deletions include/ifx.h
Expand Up @@ -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 :
Expand Down
42 changes: 18 additions & 24 deletions radiantcore/fx/FxAction.cpp
Expand Up @@ -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())
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions radiantcore/fx/FxAction.h
Expand Up @@ -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<FxAction>;
Expand Down Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions test/Fx.cpp
Expand Up @@ -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");
}

}
16 changes: 16 additions & 0 deletions test/resources/tdm/fx/parsertest.fx
Expand Up @@ -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"
}
}

0 comments on commit 6ff88a4

Please sign in to comment.