KarmaEngine
Game Engine for practical learning and research purposes
|
This file contains some commonly used game code macros. More...
#include "krpch.h"
Go to the source code of this file.
Classes | |
struct | Karma::FUObjectItem |
Single item in UObjectStore. More... | |
class | Karma::FUObjectArray |
A class for managing the collection of UObjects (all or some?) More... | |
class | Karma::FUObjectArray::TIterator |
Low level iterator. More... | |
class | Karma::KarmaClassObjectMap |
Class for caching list of UObject pointers categorized by UClass. More... | |
struct | Karma::FStaticConstructObjectParameters |
This struct is used for passing parameter values to the StaticConstructObject_Internal() method. Only the constructor parameters are required to be valid - all other members are optional. Basically various UObject variables to be initialized when calling the NewObject routine. More... | |
class | Karma::FObjectInitializer |
Internal class to finalize UObject creation (initialize properties) after the real C++ constructor is called. More... | |
Namespaces | |
namespace | Karma::ECastCheckedType |
Macros | |
#define | INVALID_OBJECT (UObject*)-1 |
maximum value, 0xffffffff | |
Typedefs | |
typedef signed int | Karma::int32 |
32-bit signed integer | |
Functions | |
template<typename Enum> | |
constexpr bool | Karma::EnumHasAnyFlags (Enum Flags, Enum Contains) |
Sees if a specified flag(s) exists in the linear combination of flags. | |
template<class T, class U> | |
FORCEINLINE T * | Karma::CastChecked (const U &Src, ECastCheckedType::Type CheckType=ECastCheckedType::NullChecked) |
UObject * | Karma::StaticConstructObject_Internal (const FStaticConstructObjectParameters &Params) |
UObject * | Karma::StaticAllocateObject (const UClass *inClass, UObject *inOuter, const std::string &inName, EObjectFlags inFlags, EInternalObjectFlags internalSetFlags) |
template<class T> | |
FUNCTION_NON_NULL_RETURN_START T * | Karma::NewObject (UObject *Outer, const UClass *Class, std::string name="No_Name", EObjectFlags Flags=RF_NoFlags, UObject *Template=nullptr, bool bCopyTransientsFromClassDefaults=false) FUNCTION_NON_NULL_RETURN_END |
UObject * | Karma::StaticFindObjectFastInternal (const UClass *ObjectClass, const UObject *ObjectPackage, const std::string &ObjectName, bool bExactClass, EObjectFlags ExcludeFlags, EInternalObjectFlags ExclusiveInternalFlags) |
KARMA_API UObject * | Karma::StaticFindObject (UClass *Class, UObject *InOuter, const std::string &Name, bool ExactClass=false) |
template<class T> | |
KARMA_API T * | Karma::FindObject (UObject *Outer, const std::string &Name, bool ExactClass=false) |
Find an optional object. | |
UPackage * | Karma::CreatePackage (const std::string &PackageName) |
void | Karma::GetObjectsOfClass (const UClass *ClassToLookFor, KarmaVector< UObject * > &Results, bool bIncludeDerivedClasses, EObjectFlags ExclusionFlags, EInternalObjectFlags ExclusionInternalFlags) |
void | Karma::ForEachObjectOfClass (const UClass *ClassToLookFor, std::function< void(UObject *)> Operation, bool bIncludeDerivedClasses, EObjectFlags ExclusionFlags, EInternalObjectFlags ExclusionInternalFlags) |
void | Karma::RegisterUObjectsStatisticsCallback (FUObjectAllocatorCallback dumpCallback) |
void | Karma::CacheObject (UObject *Object) |
void | Karma::StaticUObjectInit () |
UPackage * | Karma::GetTransientPackage () |
This file contains some commonly used game code macros.
typedef signed int Karma::int32 |
32-bit signed integer
enum Karma::EClassFlags |
Flags describing a class.
Enumerator | |
---|---|
CLASS_None | No Flags |
CLASS_Abstract | Class is abstract and can't be instantiated directly. |
CLASS_DefaultConfig | Save object configuration only to Default INIs, never to local INIs. Must be combined with CLASS_Config |
CLASS_Config | Load object configuration at construction time. |
CLASS_Transient | This object type can't be saved; null it out at save time. |
CLASS_Optional | This object type may not be available in certain context. (i.e. game runtime or in certain configuration). Optional class data is saved separately to other object types. (i.e. might use sidecar files) |
CLASS_ProjectUserConfig | Indicates that the config settings for this class will be saved to Project/User*.ini (similar to CLASS_GlobalUserConfig) |
CLASS_Native | Class is a native class - native interfaces will have CLASS_Native set, but not RF_MarkAsNative |
CLASS_NotPlaceable | Don't export to C++ header. Do not allow users to create in the editor. |
CLASS_PerObjectConfig | Handle object configuration on a per-object basis, rather than per-class. |
CLASS_ReplicationDataIsSetUp | Whether SetUpRuntimeReplicationData still needs to be called for this class |
CLASS_EditInlineNew | Class can be constructed from editinline New button. |
CLASS_CollapseCategories | Display properties in the editor without using categories. |
CLASS_Interface | Class is an interface |
CLASS_Const | Do not export a constructor for this class, assuming it is in the cpptext all properties and functions in this class are const and should be exported as const |
CLASS_NeedsDeferredDependencyLoading | Class flag indicating objects of this class need deferred dependency loading |
CLASS_CompiledFromBlueprint | Indicates that the class was created from blueprint source material |
CLASS_MinimalAPI | Indicates that only the bare minimum bits of this class should be DLL exported/imported |
CLASS_RequiredAPI | Indicates this class must be DLL exported/imported (along with all of it's members) |
CLASS_DefaultToInstanced | Indicates that references to this class default to instanced. Used to be subclasses of UComponent, but now can be any UObject |
CLASS_TokenStreamAssembled | Indicates that the parent token stream has been merged with ours. |
CLASS_HasInstancedReference | Class has component properties. |
CLASS_Hidden | Don't show this class in the editor class browser or edit inline new menus. |
CLASS_Deprecated | Don't save objects of this class when serializing |
CLASS_HideDropDown | Class not shown in editor drop down for class selection |
CLASS_GlobalUserConfig | Class settings are saved to <AppData>/..../Blah.ini (as opposed to CLASS_DefaultConfig) |
CLASS_Intrinsic | Class was declared directly in C++ and has no boilerplate generated by UnrealHeaderTool |
CLASS_Constructed | Class has already been constructed (maybe in a previous DLL version before hot-reload). |
CLASS_ConfigDoNotCheckDefaults | Indicates that object configuration will not check against ini base/defaults when serialized |
CLASS_NewerVersionExists | Class has been consigned to oblivion as part of a blueprint recompile, and a newer version currently exists. |
|
strong |
Objects flags for internal use (GC, low level UObject code)
Enumerator | |
---|---|
LoaderImport | Object is ready to be imported by another package during loading. |
Garbage | Garbage from logical point of view and should not be referenced. This flag is mirrored in EObjectFlags as RF_Garbage for performance. |
PersistentGarbage | Same as above but referenced through a persistent reference so it can't be GC'd. |
ReachableInCluster | External reference to object in cluster exists. |
ClusterRoot | Root of a cluster. |
Native | Native (UClass only). |
Async | Object exists only on a different thread than the game thread. |
AsyncLoading | Object is being asynchronously loaded. |
Unreachable | Object is not reachable on the object graph. |
PendingKill | Objects that are pending destruction (invalid for gameplay but valid objects). This flag is mirrored in EObjectFlags as RF_PendingKill for performance. |
RootSet | Object will not be garbage collected, even if unreferenced. |
PendingConstruction | Object didn't have its class constructor called yet (only the UObjectBase one to initialize its most basic members) |
AllFlags | Flags mirrored in EObjectFlags. |
enum Karma::EObjectFlags |
Flags describing an object instance.
Enumerator | |
---|---|
RF_NoFlags | No flags, used to avoid a cast. |
RF_Public | Object is visible outside its package. |
RF_Standalone | Keep object around for editing even if unreferenced. |
RF_MarkAsNative | Object (UField) will be marked as native on construction (DO NOT USE THIS FLAG in HasAnyFlags() etc) |
RF_Transactional | Object is transactional. |
RF_ClassDefaultObject | This object is its class's default object. |
RF_ArchetypeObject | This object is a template for another object - treat like a class default object. |
RF_Transient | Don't save object. |
RF_MarkAsRootSet | Object will be marked as root set on construction and not be garbage collected, even if unreferenced (DO NOT USE THIS FLAG in HasAnyFlags() etc) |
RF_TagGarbageTemp | This is a temp user flag for various utilities that need to use the garbage collector. The garbage collector itself does not interpret it. |
RF_NeedInitialization | This object has not completed its initialization process. Cleared when ~FObjectInitializer completes. |
RF_NeedLoad | During load, indicates object needs loading. |
RF_KeepForCooker | Keep this object during garbage collection because it's still being used by the cooker. |
RF_NeedPostLoad | Object needs to be postloaded. |
RF_NeedPostLoadSubobjects | During load, indicates that the object still needs to instance subobjects and fixup serialized component references. |
RF_NewerVersionExists | Object has been consigned to oblivion due to its owner package being reloaded, and a newer version currently exists. |
RF_BeginDestroyed | BeginDestroy has been called on the object. |
RF_FinishDestroyed | FinishDestroy has been called on the object. |
RF_BeingRegenerated | Flagged on UObjects that are used to create UClasses (e.g. Blueprints) while they are regenerating their UClass on load (See FLinkerLoad::CreateExport()), as well as UClass objects in the midst of being created. |
RF_DefaultSubObject | Flagged on subobjects that are defaults. |
RF_WasLoaded | Flagged on UObjects that were loaded. |
RF_TextExportTransient | Do not export object to text form (e.g. copy/paste). Generally used for sub-objects that can be regenerated from data in their parent object. |
RF_LoadCompleted | Object has been completely serialized by linkerload at least once. DO NOT USE THIS FLAG, It should be replaced with RF_WasLoaded. |
RF_InheritableComponentTemplate | Archetype of the object can be in its super class. |
RF_DuplicateTransient | Object should not be included in any type of duplication (copy/paste, binary duplication, etc.) |
RF_StrongRefOnFrame | References to this object from persistent function frame are handled as strong ones. |
RF_NonPIEDuplicateTransient | Object should not be included for duplication unless it's being duplicated for a PIE session. |
RF_Dynamic | Field Only. Dynamic field - doesn't get constructed during static initialization, can be constructed multiple times //.
|
RF_WillBeLoaded | This object was constructed during load and will be loaded shortly. |
RF_HasExternalPackage | This object has an external package assigned and should look it up when getting the outermost package. |
RF_PendingKill | Objects that are pending destruction (invalid for gameplay but valid objects). This flag is mirrored in EInternalObjectFlags as PendingKill for performance. |
RF_Garbage | Garbage from logical point of view and should not be referenced. This flag is mirrored in EInternalObjectFlags as Garbage for performance. |
RF_AllocatedInSharedPage | Allocated from a ref-counted page shared with other UObjects. |
enum Karma::EPackageFlags |
Package flags, passed into UPackage::SetPackageFlags and related functions.
Enumerator | |
---|---|
PKG_None | No flags. |
PKG_NewlyCreated | Newly created package, not saved yet. In editor only. |
PKG_ClientOptional | Purely optional for clients. |
PKG_ServerSideOnly | Only needed on the server side. |
PKG_CompiledIn | This package is from "compiled in" classes. |
PKG_ForDiffing | This package was loaded just for the purposes of diffing. |
PKG_EditorOnly | This is editor-only package (for example: editor module script package) |
PKG_Developer | Developer module. |
PKG_UncookedOnly | Loaded only in uncooked builds (i.e. runtime in editor) |
PKG_Cooked | Package is cooked. |
PKG_ContainsNoAsset | Package doesn't contain any asset object (although asset tags can be present) |
PKG_NotExternallyReferenceable | Objects in this package cannot be referenced in a different plugin or mount point (i.e /Game -> /Engine) |
PKG_UnversionedProperties | Uses unversioned property serialization instead of versioned tagged property serialization. |
PKG_ContainsMapData | Contains map data (UObjects only referenced by a single ULevel) but is stored in a different package. |
PKG_IsSaving | Temporarily set on a package while it is being saved. |
PKG_Compiling | package is currently being compiled |
PKG_ContainsMap | Set if the package contains a ULevel/ UWorld object. |
PKG_RequiresLocalizationGather | Set if the package contains any data to be gathered by localization. |
PKG_PlayInEditor | Set if the package was created for the purpose of PIE. |
PKG_ContainsScript | Package is allowed to contain UClass objects. |
PKG_DisallowExport | Editor should not export asset in this package. |
PKG_CookGenerated | This package was generated by the cooker and does not exist in the WorkspaceDomain. |
PKG_DynamicImports | This package should resolve dynamic imports from its export at runtime. |
PKG_RuntimeGenerated | This package contains elements that are runtime generated, and may not follow standard loading order rules. |
PKG_ReloadingForCooker | This package is reloading in the cooker, try to avoid getting data we will never need. We won't save this package. |
PKG_FilterEditorOnly | Package has editor-only data filtered out. |
Add an object to the cache, categorized by class
Object | Object to add to the cache |
FORCEINLINE T * Karma::CastChecked | ( | const U & | Src, |
ECastCheckedType::Type | CheckType = ECastCheckedType::NullChecked ) |
Sees if class of type U can be cast into T class type, returns the casted class Needs to move to own Cast class
Src | The object pointer which needs to be checked |
CheckType | How to perform cast checks |
KARMA_API UPackage * Karma::CreatePackage | ( | const std::string & | PackageName | ) |
Find an existing package by name or create it if it doesn't exist
The | name of the package to be searched or create |
|
constexpr |
Sees if a specified flag(s) exists in the linear combination of flags.
Flags | The linear combination (&'d) of flags |
Contains | The flags to be seen |
|
inline |
Find an optional object.
Tries to find an object in memory
KARMA_API void Karma::ForEachObjectOfClass | ( | const UClass * | ClassToLookFor, |
std::function< void(UObject *)> | Operation, | ||
bool | bIncludeDerivedClasses = true, | ||
EObjectFlags | ExcludeFlags = RF_ClassDefaultObject, | ||
EInternalObjectFlags | ExclusionInternalFlags = EInternalObjectFlags::None ) |
Performs an operation on all objects of the provided class Note that the operation must not modify UObject hash maps so it can not create, rename, or destroy UObjects.
Outer | UObject class to loop over instances of |
Operation | Function to be called for each object |
bIncludeDerivedClasses | If true, the results will include objects of child classes as well. |
AdditionalExcludeFlags | Objects with any of these flags will be excluded from the results. |
KARMA_API void Karma::GetObjectsOfClass | ( | const UClass * | ClassToLookFor, |
KarmaVector< UObject * > & | Results, | ||
bool | bIncludeDerivedClasses = true, | ||
EObjectFlags | ExcludeFlags = RF_ClassDefaultObject, | ||
EInternalObjectFlags | ExclusionInternalFlags = EInternalObjectFlags::None ) |
Returns a vector of objects of a specific class. Optionally, results can include objects of derived classes as well.
ClassToLookFor | Class of the objects to return. |
Results | An output list of objects of the specified class. |
bIncludeDerivedClasses | If true, the results will include objects of child classes as well. |
AdditionalExcludeFlags | Objects with any of these flags will be excluded from the results. |
ExclusiveInternalFlags | Specifies internal flags to use as a filter for which objects to return |
FUNCTION_NON_NULL_RETURN_START T * Karma::NewObject | ( | UObject * | Outer, |
const UClass * | Class, | ||
std::string | name = "No_Name", | ||
EObjectFlags | Flags = RF_NoFlags, | ||
UObject * | Template = nullptr, | ||
bool | bCopyTransientsFromClassDefaults = false ) |
Convenience template for constructing a gameplay object
Outer | the outer for the new object. If not specified, object will be created in the transient package. For AActors, Outer is the ULevel |
Class | the class of object to construct |
Name | the name for the new object. If not specified, the object will be given a transient name via MakeUniqueObjectName |
Flags | the object flags to apply to the new object |
Template | the object to use for initializing the new object. If not specified, the class's default object will be used. Not functional atm |
bCopyTransientsFromClassDefaults | if true, copy transient from the class defaults instead of the pass in archetype ptr (often these are the same) |
InInstanceGraph | contains the mappings of instanced objects and components to their templates |
ExternalPackage | Assign an external Package to the created object if non-null |
KARMA_API void Karma::RegisterUObjectsStatisticsCallback | ( | FUObjectAllocatorCallback | dumpCallback | ) |
Client's callback registering routine for receiving UObjects relevant data dump
dumpCallback | The callback function defined in client |
KARMA_API UObject * Karma::StaticAllocateObject | ( | const UClass * | Class, |
UObject * | InOuter, | ||
const std::string & | name, | ||
EObjectFlags | SetFlags = EObjectFlags::RF_NoFlags, | ||
EInternalObjectFlags | InternalSetFlags = EInternalObjectFlags::None ) |
Create a new instance of an object or replace an existing object. If both an Outer and Name are specified, and there is an object already in memory with the same Class, Outer, and Name, the existing object will be destructed, and the new object will be created in its place.
Class | the class of the object to create |
InOuter | the object to create this object within (the Outer property for the new object will be set to the value specified here). |
Name | the name to give the new object. If no value (NAME_None) is specified, the object will be given a unique name in the form of ClassName_#. |
SetFlags | the ObjectFlags to assign to the new object. some flags can affect the behavior of constructing the object. |
InternalSetFlags | the InternalObjectFlags to assign to the new object. some flags can affect the behavior of constructing the object. |
Rest shall be made available when reflection code is enabled
bCanReuseSubobjects | if set to true, SAO will not attempt to destroy a subobject if it already exists in memory. |
bOutReusedSubobject | flag indicating if the object is a subobject that has already been created (in which case further initialization is not necessary). |
ExternalPackage | External Package assigned to the allocated object, if any |
KARMA_API UObject * Karma::StaticConstructObject_Internal | ( | const FStaticConstructObjectParameters & | Params | ) |
Create a new instance of an object. The returned object will be fully initialized. If InFlags contains RF_NeedsLoad (indicating that the object still needs to load its object data from disk), components are not instanced (this will instead occur in PostLoad()). The different between StaticConstructObject and StaticAllocateObject is that StaticConstructObject will also call the class constructor on the object and instance any components.
Params | The parameters to use when construction the object. |
KARMA_API UObject * Karma::StaticFindObject | ( | UClass * | Class, |
UObject * | InOuter, | ||
const std::string & | Name, | ||
bool | ExactClass = false ) |
Tries to find an object in memory. This will handle fully qualified paths of the form /path/packagename.object:subobject and resolve references for you.
Class | The to be found object's class |
InOuter | Outer object to look inside. If this is null then InName should start with a package name |
InName | The object path to search for an object, relative to InOuter |
ExactClass | Whether to require an exact match with the passed in class |
KARMA_API UObject * Karma::StaticFindObjectFastInternal | ( | const UClass * | ObjectClass, |
const UObject * | ObjectPackage, | ||
const std::string & | ObjectName, | ||
bool | bExactClass = false, | ||
EObjectFlags | ExcludeFlags = RF_NoFlags, | ||
EInternalObjectFlags | ExclusiveInternalFlags = EInternalObjectFlags::None ) |
A routine to find if the object is instantiated already. May need to modify in accordance with thread safety in future UE name StaticFindObjectFastInternal
ObjectClass | the class of object to construct |
ObjectPackage | the outer where the object is supposed to be found |
ObjectName | the name for the object to be found |
bExactClass | class match check |
bAnyPackage | If there is no package (no InObjectPackage specified, and InName's package is "") and the caller specified any_package, then accept it, regardless of its package.Or, if the object is a top-level package then accept it immediately |
ExcludeFlags | Don't return objects that have any of these exclusive flags set |
ExclusiveInternalFlags | Include (or not) pending kill objects |
ExternalPackage | Assign an external Package to the created object if non-null |
If a class was specified, check that the object is of the correct class (hierarchy)
Include (or not) pending kill objects