CRoomSpawner
Overview
ACRoomSpawner is the main actor to place in a level. It inherits from ACAbstractSpawner and implements ICRoomData. It reads its configuration from a DataTable row, instantiates the roommaker and drives the generation loop on tick.
Properties
| Name | Description |
|---|---|
| pawnToTrack | Pawn whose location drives room generation context |
| roomClusterRH | FDataTableRowHandle pointing to a FCRoomClusterStruct row |
| roommaker | Transient reference to the instantiated UCRoommaker |
| clusterNoise | Transient reference to the cluster UCNoisator singleton |
| roomNoise | Transient reference to the room UCNoisator singleton |
| clusterShiftNoise | Transient reference to the cluster shift UCNoisator singleton |
Lifecycle
| Name | Description |
|---|---|
| init | Reads the DataTable row, creates noise singletons, instantiates the roommaker |
| Tick | Calls roommaker->buildASync until built, then disables tick |
| clean | Destroys the roommaker and its resources |
| debug | Toggles debug drawing on all generated rooms and corridors (CallInEditor) |
// ACRoomSpawner is placed in the level.
// Configure roomClusterRH to point to a DataTable row of type FCRoomClusterStruct.
// Assign pawnToTrack to the player pawn or any pawn to follow.
// init() is called by the spawner system (ACAbstractSpawner).
// It creates UCNoisator singletons for cluster, room and shift noise:
UCNoisator::instanciate(GetRootComponent()->GetOwner(),
CSingletonName::CNAME_Singleton_ClusterNoise,
clusterNoise, seed,
data->clusterNoiseDataAsset->fastNoiseStruct,
data->clusterNoiseDataAsset->noiseStructArray);
// Then instantiates the roommaker:
UCRoommaker::instantiate(GetRootComponent(), roommaker, stream, *data);
// On Tick, the spawner delegates to the roommaker:
// roommaker->buildASync(this) runs until roommaker->built == true.
ICRoomData interface
ACRoomSpawner implements ICRoomData, making room queries available globally via RoomUtility static functions.
| Name | Description |
|---|---|
| roomExists | Returns true if a roommaker is instantiated |
| roomBuilt | Returns true if room generation is complete |
| roomReady | Returns true if room collisions are spawned and ready |
| iterateOnCluster | Iterates over all clusters with a callback |
| iterateOnClusterRoom | Iterates over all rooms in all clusters with a callback |
| getRootCluster | Returns the root bounding rectangle encompassing all clusters |
| retrieveClusterById | Returns a cluster rectangle by ID |
| retrieveRoomById | Returns a room rectangle by cluster ID and room ID |
| retrieveClusterByTag | Returns all clusters matching a tag |
| retrieveRoomByTag | Returns all rooms matching a tag |
| retrieveEdgeById | Returns a corridor edge by cluster ID and edge ID |
| retrieveClusterByRoom | Returns the parent cluster of a room |
| closestCluster | Finds the closest cluster to a 2D location |
| closestRoom | Finds the closest room to a 2D location with optional tolerance |
| closestEdge | Finds the closest corridor edge to a 2D location |
| nearEdge | Finds the nearest edge within its influence width |
| fogOfWarPart | Returns the fog of war rectangle for a cluster |
| boundToOnRoomBuilt | Binds an ICRoomBoundable to receive onRoomBuilt delegate |
| unboundToOnRoomBuilt | Unbinds an ICRoomBoundable from the delegate |
| isRoomEligibleForTagProba | Checks if a room is eligible for content based on tag probabilities |
| retrieveSpecificNoiseData | Returns per-cluster specific noise and shift noise |
// Any system can query rooms via RoomUtility static functions:
FCRectangle* room = RoomUtility::retrieveRoomById(clusterId, roomId);
FCRectangle* cluster = RoomUtility::retrieveClusterById(clusterId);
// Check if rooms are ready:
if (RoomUtility::roomReady()) { /* safe to query rooms */ }
// Find closest room to a world position:
FCRectangle* closestRect;
if (RoomUtility::closestRoom(FVector2D(x, y), closestRect)) {
// closestRect points to the nearest room
}
// Iterate over all rooms:
RoomUtility::iterateOnClusterRoom([](FCRectangle* cluster, FCRectangle* room) {
// process each room
return false; // return true to break
});
// Bind to room built event:
RoomUtility::boundToOnRoomBuilt(myRoomBoundableObject);