Plasma Engine  2.0
Loading...
Searching...
No Matches
plWorldReader Class Reference

Reads a world description from a stream. Allows to instantiate that world multiple times in different locations and different plWorld'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 = plDelegate<const plRTTI*(plStringView sTypeName)>
 

Public Member Functions

plResult ReadWorldDescription (plStreamReader &inout_stream, bool bWarningOnUnkownSkip=true)
 Reads all information about the world from the given stream.
 
plUniquePtr< InstantiationContextBaseInstantiateWorld (plWorld &ref_world, const plUInt16 *pOverrideTeamID=nullptr, plTime maxStepTime=plTime::MakeZero(), plProgress *pProgress=nullptr)
 Creates one instance of the world that was previously read by ReadWorldDescription().
 
plUniquePtr< InstantiationContextBaseInstantiatePrefab (plWorld &ref_world, const plTransform &rootTransform, const plPrefabInstantiationOptions &options)
 Creates one instance of the world that was previously read by ReadWorldDescription().
 
plStreamReaderGetStream () const
 Gives access to the stream of data. Use this inside component deserialization functions to read data.
 
plGameObjectHandle ReadGameObjectHandle ()
 Used during component deserialization to read a handle to a game object.
 
void ReadComponentHandle (plComponentHandle &out_hComponent)
 Used during component deserialization to read a handle to a component.
 
plUInt32 GetComponentTypeVersion (const plRTTI *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 PL_BEGIN_COMPONENT_TYPE macro. Whenever the serialization of a component changes, that number should be increased.
 
void ClearAndCompact ()
 Clears all data.
 
plUInt64 GetHeapMemoryUsage () const
 Returns the amount of bytes that are currently allocated on the heap.
 
plUInt32 GetRootObjectCount () const
 
plUInt32 GetChildObjectCount () const
 

Static Public Member Functions

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

Static Public Attributes

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

Detailed Description

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

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

Member Function Documentation

◆ InstantiatePrefab()

plUniquePtr< plWorldReader::InstantiationContextBase > plWorldReader::InstantiatePrefab ( plWorld & ref_world,
const plTransform & rootTransform,
const plPrefabInstantiationOptions & 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 plProgress object has to be valid as long as the instantiation is in progress.

◆ InstantiateWorld()

plUniquePtr< plWorldReader::InstantiationContextBase > plWorldReader::InstantiateWorld ( plWorld & ref_world,
const plUInt16 * pOverrideTeamID = nullptr,
plTime maxStepTime = plTime::MakeZero(),
plProgress * 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 plProgress object has to be valid as long as the instantiation is in progress.

◆ ReadWorldDescription()

plResult plWorldReader::ReadWorldDescription ( plStreamReader & inout_stream,
bool bWarningOnUnkownSkip = true )

Reads all information about the world from the given stream.

Call this once to populate plWorldReader 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 plWorld. 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

plWorldReader::FindComponentTypeCallback plWorldReader::s_FindComponentTypeCallback
static

An optional callback to redirect the lookup of a component type name to an plRTTI 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: