ezEngine  Release 25.03
ezWorldReader Class Reference

Reads a world description from a stream. Allows to instantiate that world multiple times in different locations and different ezWorld's. More...

#include <WorldReader.h>

Classes

class  InstantiationContextBase
 A context object is returned from InstantiateWorld or InstantiatePrefab if a maxStepTime greater than zero is specified. More...
 

Public Types

using FindComponentTypeCallback = ezDelegate< const ezRTTI *(ezStringView sTypeName)>
 

Public Member Functions

ezResult ReadWorldDescription (ezStreamReader &inout_stream, bool bWarningOnUnkownSkip=true)
 Reads all information about the world from the given stream. More...
 
ezUniquePtr< InstantiationContextBaseInstantiateWorld (ezWorld &ref_world, const ezUInt16 *pOverrideTeamID=nullptr, ezTime maxStepTime=ezTime::MakeZero(), ezProgress *pProgress=nullptr)
 Creates one instance of the world that was previously read by ReadWorldDescription(). More...
 
ezUniquePtr< InstantiationContextBaseInstantiatePrefab (ezWorld &ref_world, const ezTransform &rootTransform, const ezPrefabInstantiationOptions &options)
 Creates one instance of the world that was previously read by ReadWorldDescription(). More...
 
ezStreamReaderGetStream () const
 Gives access to the stream of data. Use this inside component deserialization functions to read data.
 
ezGameObjectHandle ReadGameObjectHandle ()
 Used during component deserialization to read a handle to a game object.
 
void ReadComponentHandle (ezComponentHandle &out_hComponent)
 Used during component deserialization to read a handle to a component.
 
ezUInt32 GetComponentTypeVersion (const ezRTTI *pRtti) const
 Used during component deserialization to query the actual version number with which the given component type was written. The version number is given through the EZ_BEGIN_COMPONENT_TYPE macro. Whenever the serialization of a component changes, that number should be increased.
 
bool HasComponentOfType (const ezRTTI *pRtti) const
 Returns whether world contains a component of given type.
 
void ClearAndCompact ()
 Clears all data.
 
ezUInt64 GetHeapMemoryUsage () const
 Returns the amount of bytes that are currently allocated on the heap.
 
ezUInt32 GetRootObjectCount () const
 
ezUInt32 GetChildObjectCount () const
 

Static Public Member Functions

static void SetMaxStepTime (InstantiationContextBase *pContext, ezTime maxStepTime)
 
static ezTime GetMaxStepTime (InstantiationContextBase *pContext)
 

Static Public Attributes

static FindComponentTypeCallback s_FindComponentTypeCallback
 An optional callback to redirect the lookup of a component type name to an ezRTTI type. More...
 

Detailed Description

Reads a world description from a stream. Allows to instantiate that world multiple times in different locations and different ezWorld's.

The reader will ignore unknown component types and skip them during instantiation.

Member Function Documentation

◆ InstantiatePrefab()

ezUniquePtr< ezWorldReader::InstantiationContextBase > ezWorldReader::InstantiatePrefab ( ezWorld ref_world,
const ezTransform rootTransform,
const ezPrefabInstantiationOptions options 
)

Creates one instance of the world that was previously read by ReadWorldDescription().

Parameters
rootTransformis an additional transform that is applied to all root objects.
hParentallows to attach the newly created objects immediately to a parent
out_CreatedRootObjectsIf this is valid, all pointers the to created root objects are stored in this array

If pOverrideTeamID is not null, every instantiated game object will get it passed in as its new value. This can be used to identify that the object belongs to a specific player or team.

If maxStepTime is not zero the function will return a valid ptr to an InstantiationContextBase. This context will only spend the given amount of time in its Step() function. The function has to be periodically called until it returns true to complete the instantiation.

If pProgress is a valid pointer it is used to track the progress of the instantiation. The ezProgress object has to be valid as long as the instantiation is in progress.

◆ InstantiateWorld()

ezUniquePtr< ezWorldReader::InstantiationContextBase > ezWorldReader::InstantiateWorld ( ezWorld ref_world,
const ezUInt16 *  pOverrideTeamID = nullptr,
ezTime  maxStepTime = ezTime::MakeZero(),
ezProgress pProgress = nullptr 
)

Creates one instance of the world that was previously read by ReadWorldDescription().

This is identical to calling InstantiatePrefab() with identity values, however, it is a bit more efficient, as unnecessary computations are skipped.

If pOverrideTeamID is not null, every instantiated game object will get it passed in as its new value. This can be used to identify that the object belongs to a specific player or team.

If maxStepTime is not zero the function will return a valid ptr to an InstantiationContextBase. This context will only spend the given amount of time in its Step() function. The function has to be periodically called until it returns true to complete the instantiation.

If pProgress is a valid pointer it is used to track the progress of the instantiation. The ezProgress object has to be valid as long as the instantiation is in progress.

◆ ReadWorldDescription()

ezResult ezWorldReader::ReadWorldDescription ( ezStreamReader inout_stream,
bool  bWarningOnUnkownSkip = true 
)

Reads all information about the world from the given stream.

Call this once to populate ezWorldReader with information how to instantiate the world. Afterwards stream can be deleted. Call InstantiateWorld() or InstantiatePrefab() afterwards as often as you like to actually get an objects into an ezWorld. By default, the method will warn if it skips bytes in the stream that are of unknown types. The warnings can be suppressed by setting warningOnUnkownSkip to false.

Member Data Documentation

◆ s_FindComponentTypeCallback

ezWorldReader::FindComponentTypeCallback ezWorldReader::s_FindComponentTypeCallback
static

An optional callback to redirect the lookup of a component type name to an ezRTTI type.

If specified, this is used by ALL world readers. The intention is to use this either for logging purposes, or to implement a whitelist or blacklist for specific component types. E.g. if the callback returns nullptr, the component type is 'unknown' and skipped by the world reader. Thus one can remove unwanted component types. Theoretically one could also redirect an old (or renamed) component type to a new one, given that their deserialization code is compatible.


The documentation for this class was generated from the following files: