Add lock for Gameplay Globals access
This commit is contained in:
@@ -59,6 +59,7 @@ GameplayGlobals::GameplayGlobals(const SpawnParams& params, const AssetInfo* inf
|
||||
|
||||
Dictionary<String, Variant> GameplayGlobals::GetValues() const
|
||||
{
|
||||
ScopeLock lock(Locker);
|
||||
Dictionary<String, Variant> result;
|
||||
for (auto& e : Variables)
|
||||
result.Add(e.Key, e.Value.Value);
|
||||
@@ -67,7 +68,8 @@ Dictionary<String, Variant> GameplayGlobals::GetValues() const
|
||||
|
||||
void GameplayGlobals::SetValues(const Dictionary<String, Variant>& values)
|
||||
{
|
||||
for (auto& e : Variables)
|
||||
ScopeLock lock(Locker);
|
||||
for (auto& e : values)
|
||||
{
|
||||
bool hasKey = false;
|
||||
for (auto& q : values)
|
||||
@@ -97,6 +99,7 @@ void GameplayGlobals::SetValues(const Dictionary<String, Variant>& values)
|
||||
|
||||
Dictionary<String, Variant> GameplayGlobals::GetDefaultValues() const
|
||||
{
|
||||
ScopeLock lock(Locker);
|
||||
Dictionary<String, Variant> result;
|
||||
for (auto& e : Variables)
|
||||
result.Add(e.Key, e.Value.DefaultValue);
|
||||
@@ -105,7 +108,8 @@ Dictionary<String, Variant> GameplayGlobals::GetDefaultValues() const
|
||||
|
||||
void GameplayGlobals::SetDefaultValues(const Dictionary<String, Variant>& values)
|
||||
{
|
||||
for (auto& e : Variables)
|
||||
ScopeLock lock(Locker);
|
||||
for (auto& e : values)
|
||||
{
|
||||
bool hasKey = false;
|
||||
for (auto& q : values)
|
||||
@@ -135,12 +139,14 @@ void GameplayGlobals::SetDefaultValues(const Dictionary<String, Variant>& values
|
||||
|
||||
Variant GameplayGlobals::GetValue(const StringView& name) const
|
||||
{
|
||||
ScopeLock lock(Locker);
|
||||
auto e = Variables.TryGet(name);
|
||||
return e ? e->Value : Variant::Zero;
|
||||
}
|
||||
|
||||
void GameplayGlobals::SetValue(const StringView& name, const Variant& value)
|
||||
{
|
||||
ScopeLock lock(Locker);
|
||||
auto e = Variables.TryGet(name);
|
||||
if (e)
|
||||
{
|
||||
@@ -150,6 +156,7 @@ void GameplayGlobals::SetValue(const StringView& name, const Variant& value)
|
||||
|
||||
void GameplayGlobals::ResetValues()
|
||||
{
|
||||
ScopeLock lock(Locker);
|
||||
for (auto& e : Variables)
|
||||
{
|
||||
e.Value.Value = e.Value.DefaultValue;
|
||||
|
||||
Reference in New Issue
Block a user