Skip to content

Commit

Permalink
#6092: Add IFxManager interface and global module declaration
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Sep 6, 2022
1 parent 6ff88a4 commit d959c2b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
23 changes: 23 additions & 0 deletions include/ifx.h
@@ -1,5 +1,6 @@
#pragma once

#include "imodule.h"
#include "ideclmanager.h"
#include "math/Vector3.h"

Expand Down Expand Up @@ -145,4 +146,26 @@ class IFxDeclaration :
virtual std::string getBindTo() = 0;
};

/**
* Convenience interface to deal with FX declarations
*/
class IFxManager :
public RegisterableModule
{
public:
/**
* Lookup an FX declaration by name.
* If the decl is not found, an empty reference is returned.
*/
virtual IFxDeclaration::Ptr findFx(const std::string& name) = 0;
};

}

constexpr const char* const MODULE_FXMANAGER("FxManager");

inline fx::IFxManager& GlobalFxManager()
{
static module::InstanceReference<fx::IFxManager> _reference(MODULE_FXMANAGER);
return _reference;
}
6 changes: 6 additions & 0 deletions radiantcore/fx/FxManager.cpp
Expand Up @@ -7,6 +7,12 @@
namespace fx
{

IFxDeclaration::Ptr FxManager::findFx(const std::string& name)
{
return std::static_pointer_cast<IFxDeclaration>(
GlobalDeclarationManager().findDeclaration(decl::Type::Fx, name));
}

const std::string& FxManager::getName() const
{
static std::string _name("FxManager");
Expand Down
6 changes: 4 additions & 2 deletions radiantcore/fx/FxManager.h
@@ -1,14 +1,16 @@
#pragma once

#include "imodule.h"
#include "ifx.h"

namespace fx
{

class FxManager final :
public RegisterableModule
public IFxManager
{
public:
IFxDeclaration::Ptr findFx(const std::string& name) override;

// RegisterableModule implementation
const std::string& getName() const override;
const StringSet& getDependencies() const override;
Expand Down
7 changes: 3 additions & 4 deletions test/Fx.cpp
Expand Up @@ -9,14 +9,13 @@ using FxTest = RadiantTest;

inline fx::IFxDeclaration::Ptr getFxByName(const std::string& name)
{
return std::static_pointer_cast<fx::IFxDeclaration>(
GlobalDeclarationManager().findDeclaration(decl::Type::Fx, name));
return GlobalFxManager().findFx(name);
}

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

TEST_F(FxTest, GetNumActions)
Expand Down

0 comments on commit d959c2b

Please sign in to comment.