Skip to content

Commit

Permalink
#6092: Extend IFxDeclaration interface, add first unit tests and reso…
Browse files Browse the repository at this point in the history
…urces.
  • Loading branch information
codereader committed Sep 4, 2022
1 parent 61179c9 commit ef81b49
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 0 deletions.
14 changes: 14 additions & 0 deletions include/ifx.h
Expand Up @@ -5,11 +5,25 @@
namespace fx
{

class IFxAction
{
public:
using Ptr = std::shared_ptr<IFxAction>;

virtual ~IFxAction() {}


};

class IFxDeclaration :
public decl::IDeclaration
{
public:
// Returns the number of actions in this FX declaration
virtual std::size_t getNumActions() = 0;

// Returns the n-th action (based on the given 0-based index)
virtual IFxAction::Ptr getAction(std::size_t index) = 0;
};

}
17 changes: 17 additions & 0 deletions radiantcore/fx/FxDeclaration.cpp
Expand Up @@ -7,6 +7,23 @@ FxDeclaration::FxDeclaration(const std::string& name) :
DeclarationBase<IFxDeclaration>(decl::Type::Fx, name)
{}

std::size_t FxDeclaration::getNumActions()
{
ensureParsed();
return _actions.size();
}

IFxAction::Ptr FxDeclaration::getAction(std::size_t index)
{
ensureParsed();
return _actions.at(index);
}

void FxDeclaration::onBeginParsing()
{
_actions.clear();
}

void FxDeclaration::parseFromTokens(parser::DefTokeniser& tokeniser)
{

Expand Down
8 changes: 8 additions & 0 deletions radiantcore/fx/FxDeclaration.h
@@ -1,5 +1,6 @@
#pragma once

#include <vector>
#include "ifx.h"
#include "decl/DeclarationBase.h"

Expand All @@ -9,10 +10,17 @@ namespace fx
class FxDeclaration :
public decl::DeclarationBase<IFxDeclaration>
{
private:
std::vector<IFxAction::Ptr> _actions;

public:
FxDeclaration(const std::string& name);

std::size_t getNumActions() override;
IFxAction::Ptr getAction(std::size_t index) override;

protected:
void onBeginParsing() override;
void parseFromTokens(parser::DefTokeniser& tokeniser) override;
};

Expand Down
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Expand Up @@ -15,6 +15,7 @@ add_executable(drtest
EntityClass.cpp
Favourites.cpp
FileTypes.cpp
Fx.cpp
GeometryStore.cpp
Grid.cpp
HeadlessOpenGLContext.cpp
Expand Down
16 changes: 16 additions & 0 deletions test/Fx.cpp
@@ -0,0 +1,16 @@
#include "ifx.h"

#include "RadiantTest.h"

namespace test
{

using FxTest = RadiantTest;

TEST_F(FxTest, GetFxByName)
{
EXPECT_TRUE(GlobalDeclarationManager().findDeclaration(decl::Type::Fx, "fx/tdm_flame"));
EXPECT_TRUE(GlobalDeclarationManager().findDeclaration(decl::Type::Fx, "fx/sparks"));
}

}
37 changes: 37 additions & 0 deletions test/resources/tdm/fx/parsertest.fx
@@ -0,0 +1,37 @@
fx fx/tdm_flame
{
bindto "Head"
{
delay 0
duration 10
restart 0
light "lights/roundfire", 0.2, 0.6, 0.3, 300
offset 0, 0, 5
//fadeIn 2
fadeOut 3
}
}

fx fx/sparks
{
{
delay 0
duration 0.5
restart 0
light "lights/sparks_sound", 0.7, 0.7, 0.7, 64
offset 0, 0, 0
}

{
delay 0
sound "security_camera_spark"
duration 2.5

}
{
delay 0
duration 2.5
restart 0
model "sparks.prt"
}
}
1 change: 1 addition & 0 deletions tools/msvc/Tests/Tests.vcxproj
Expand Up @@ -99,6 +99,7 @@
<ClCompile Include="..\..\..\test\EntityInspector.cpp" />
<ClCompile Include="..\..\..\test\Favourites.cpp" />
<ClCompile Include="..\..\..\test\FileTypes.cpp" />
<ClCompile Include="..\..\..\test\Fx.cpp" />
<ClCompile Include="..\..\..\test\GeometryStore.cpp" />
<ClCompile Include="..\..\..\test\Grid.cpp" />
<ClCompile Include="..\..\..\test\HeadlessOpenGLContext.cpp" />
Expand Down
1 change: 1 addition & 0 deletions tools/msvc/Tests/Tests.vcxproj.filters
Expand Up @@ -66,6 +66,7 @@
<ClCompile Include="..\..\..\test\DefBlockSyntaxParser.cpp" />
<ClCompile Include="..\..\..\test\CommandSystem.cpp" />
<ClCompile Include="..\..\..\test\SceneStatistics.cpp" />
<ClCompile Include="..\..\..\test\Fx.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\test\HeadlessOpenGLContext.h" />
Expand Down

0 comments on commit ef81b49

Please sign in to comment.