Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#5907: EntityClass::getVisibility() returns value from spawnargs
Instead of a constant value, getVisibility() now returns the correct value based on the presence of an "editor_visibility" spawnarg. The value is initialised lazily by way of a new Lazy class template which provides a generic means of lazily initialising a value using a callback function.
- Loading branch information
Matthew Mott
committed
Mar 30, 2022
1 parent
6bb4c83
commit 0722857
Showing
5 changed files
with
44 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#pragma once | ||
|
||
#include <optional> | ||
#include <functional> | ||
|
||
/// Wrapper for an arbitrary object which is initialised lazily via a functor | ||
template<typename T> class Lazy | ||
{ | ||
// Contained value (may or may not be initialised) | ||
mutable std::optional<T> _value; | ||
|
||
// Functor to initialise _value when required | ||
using InitialiseFunc = std::function<T()>; | ||
InitialiseFunc _initFunc; | ||
|
||
public: | ||
|
||
/// Construct the Lazy wrapper with a functor to be called when initialisation is required | ||
Lazy(InitialiseFunc func): _initFunc(func) | ||
{} | ||
|
||
/// Return the contained value, initialising via the functor if necessary | ||
T get() const | ||
{ | ||
if (!_value) | ||
_value = _initFunc(); | ||
|
||
return *_value; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters