Fix for stat forge, setup a test character
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#include "Data/StatForgeRegistry.h"
|
||||
|
||||
TArray<FStatDef>& FStatForgeRegistry::Get()
|
||||
{
|
||||
// Function-local static on purpose: it is created on first use, so stats declared during static
|
||||
// initialization (STATFORGE_MAKE_STAT) can never touch an uninitialized registry.
|
||||
static TArray<FStatDef> Registry;
|
||||
return Registry;
|
||||
}
|
||||
|
||||
void FStatForgeRegistry::RegisterStat(const FName& StatName)
|
||||
{
|
||||
UE_LOG(LogTemp, Verbose, TEXT("StatForge: Registering %s"), *StatName.ToString());
|
||||
|
||||
const bool bAlreadyRegistered = Get().ContainsByPredicate([&](const FStatDef& Def)
|
||||
{
|
||||
return Def.StatName == StatName;
|
||||
});
|
||||
|
||||
if (!bAlreadyRegistered)
|
||||
{
|
||||
FStatDef StatDef;
|
||||
StatDef.StatName = StatName;
|
||||
Get().Add(StatDef);
|
||||
}
|
||||
}
|
||||
@@ -4,38 +4,35 @@
|
||||
#include "CoreMinimal.h"
|
||||
#include "StatForgeDefs.h"
|
||||
|
||||
/**
|
||||
* Single, module-external registry of every stat declared with STATFORGE_MAKE_STAT / STATFORGE_MAKE_STAT_NS.
|
||||
*
|
||||
* The storage lives in StatForgeRegistry.cpp rather than in an inline body here on purpose: the registry has
|
||||
* to be ONE instance shared by all module binaries. A function-local static inside an inline header function
|
||||
* gets hidden (private-extern) visibility on macOS (-fvisibility-inlines-hidden) and is therefore duplicated
|
||||
* into every module that calls it, which made the game module register its stats into a copy that
|
||||
* UStatForgeDeveloperSettings::MergeRegistryIntoStatMap() - living in the plugin binary - never read.
|
||||
*/
|
||||
class STATFORGE_API FStatForgeRegistry
|
||||
{
|
||||
public:
|
||||
|
||||
static TArray<FStatDef>& Get()
|
||||
{
|
||||
static TArray<FStatDef> Registry;
|
||||
return Registry;
|
||||
}
|
||||
|
||||
static void RegisterStat(const FName& StatName)
|
||||
{
|
||||
UE_LOG(LogTemp, Warning, TEXT("StatForge: Registering %s"), *StatName.ToString());
|
||||
|
||||
const bool bAlreadyRegistered = Get().ContainsByPredicate([&](const FStatDef& Def)
|
||||
{
|
||||
return Def.StatName == StatName;
|
||||
});
|
||||
|
||||
if (!bAlreadyRegistered)
|
||||
{
|
||||
FStatDef StatDef;
|
||||
StatDef.StatName = StatName;
|
||||
Get().Add(StatDef);
|
||||
}
|
||||
}
|
||||
static TArray<FStatDef>& Get();
|
||||
static void RegisterStat(const FName& StatName);
|
||||
};
|
||||
|
||||
/**
|
||||
* Linkage specifier for the FName symbols generated by the macros below. Define it before including this
|
||||
* header (e.g. to PROJECTELERI_API) when the stats are declared in a module other than the one consuming
|
||||
* them - otherwise those symbols are hidden on macOS and cross-module references fail to link there.
|
||||
*/
|
||||
#ifndef STATFORGE_STAT_API
|
||||
#define STATFORGE_STAT_API
|
||||
#endif
|
||||
|
||||
#define STATFORGE_DECLARE_STAT(StatName)\
|
||||
namespace FStat\
|
||||
{\
|
||||
extern const FName StatName;\
|
||||
extern STATFORGE_STAT_API const FName StatName;\
|
||||
}\
|
||||
|
||||
#define STATFORGE_DECLARE_STAT_NS(Group, StatName)\
|
||||
@@ -43,7 +40,7 @@ public:
|
||||
{\
|
||||
namespace Group\
|
||||
{\
|
||||
extern const FName StatName;\
|
||||
extern STATFORGE_STAT_API const FName StatName;\
|
||||
}\
|
||||
}\
|
||||
|
||||
|
||||
Reference in New Issue
Block a user