![]() |
Olympe Engine 2.0
2D Game Engine with ECS Architecture
|
Factory class for creating entities from prefab blueprints. More...
#include <prefabfactory.h>
Collaboration diagram for PrefabFactory:Public Member Functions | |
| void | RegisterComponentFactory (const std::string &componentName, std::function< bool(EntityID, const ComponentDefinition &)> factory) |
| Register a component factory (called by auto-registration system) | |
| bool | IsComponentRegistered (const std::string &componentName) const |
| Check if a component is registered. | |
| std::vector< std::string > | GetRegisteredComponents () const |
| Get list of all registered components (for debugging) | |
| void | PreloadAllPrefabs (const std::string &prefabDirectory="Blueprints/EntityPrefab") |
| Preload all prefabs from directory. | |
| EntityID | CreateEntityFromPrefabName (const std::string &prefabName) |
| Create entity from prefab name. | |
| int | GetPrefabCount () const |
| Create entity from prefab name with explicit layer override. | |
| bool | HasPrefab (const std::string &prefabName) const |
| Check if prefab exists. | |
| void | RegisterPrefab (const std::string &name, PrefabBuilder builder) |
| Register a legacy prefab builder function. | |
| EntityID | CreateEntity (const std::string &prefabName) |
| Create an entity using legacy prefab system. | |
| void | SetPrefabRegistry (const PrefabRegistry ®istry) |
| Set the prefab registry cache. | |
| const PrefabRegistry & | GetPrefabRegistry () const |
| Get the cached prefab registry. | |
| std::string | NormalizeType (const std::string &type) const |
| Normalize a type string to canonical form. | |
| bool | AreTypesEquivalent (const std::string &type1, const std::string &type2) const |
| Check if two types are equivalent. | |
| bool | IsTypeRegistered (const std::string &type) const |
| Check if a type is registered. | |
| bool | GetCanonicalInfo (const std::string &type, std::string &outCanonical, std::string &outPrefabFile) const |
| Get canonical type info for debugging. | |
| EntityID | CreateEntityFromBlueprint (const PrefabBlueprint &blueprint, bool autoAssignLayer=true) |
| Create entity from a parsed blueprint. | |
| EntityID | CreateEntityWithOverrides (const PrefabBlueprint &blueprint, const LevelInstanceParameters &instanceParams, bool autoAssignLayer=true) |
| Create entity from blueprint with level instance parameter overrides. | |
| bool | InstantiateComponent (EntityID entity, const ComponentDefinition &componentDef) |
| Instantiate a single component on an entity. | |
Static Public Member Functions | |
| static PrefabFactory & | Get () |
| Get singleton instance. | |
Private Attributes | |
| std::map< std::string, PrefabBuilder > | m_prefabs |
| PrefabRegistry | m_prefabRegistry |
| bool | m_prefabsPreloaded = false |
| std::unique_ptr< PrefabScanner > | m_scanner |
| std::map< std::string, std::function< bool(EntityID, const ComponentDefinition &)> > | m_componentFactories |
Factory class for creating entities from prefab blueprints.
PrefabFactory manages entity creation from JSON blueprint files. It supports both modern component-agnostic instantiation and legacy function-based prefabs.
Definition at line 32 of file prefabfactory.h.
|
privatedefault |
| bool PrefabFactory::AreTypesEquivalent | ( | const std::string & | type1, |
| const std::string & | type2 | ||
| ) | const |
Check if two types are equivalent.
| type1 | First type string |
| type2 | Second type string |
Definition at line 165 of file PrefabFactory.cpp.
References GetComponentTypeID_Static(), and m_scanner.
Here is the call graph for this function:Create an entity using legacy prefab system.
| prefabName | Name of the prefab |
Definition at line 129 of file PrefabFactory.cpp.
References World::CreateEntity(), CreateEntityFromPrefabName(), World::Get(), GetComponentTypeID_Static(), m_prefabs, and SYSTEM_LOG.
Referenced by VideoGame::InitializeAITestScene().
Here is the call graph for this function:
Here is the caller graph for this function:| EntityID PrefabFactory::CreateEntityFromBlueprint | ( | const PrefabBlueprint & | blueprint, |
| bool | autoAssignLayer = true |
||
| ) |
Create entity from a parsed blueprint.
| blueprint | Parsed prefab blueprint |
| autoAssignLayer | If true, automatically assign layer based on EntityType |
Definition at line 193 of file PrefabFactory.cpp.
References World::CreateEntity(), World::Get(), World::GetComponent(), GetComponentTypeID_Static(), World::GetDefaultLayerForType(), World::HasComponent(), InstantiateComponent(), INVALID_ENTITY_ID, World::SetEntityLayer(), and SYSTEM_LOG.
Referenced by CreateEntityFromPrefabName().
Here is the call graph for this function:
Here is the caller graph for this function:Create entity from prefab name.
Instantiates a new entity by loading and applying all components defined in the prefab blueprint file.
| prefabName | Name of the prefab (without .json extension) |
Definition at line 110 of file PrefabFactory.cpp.
References CreateEntityFromBlueprint(), PrefabRegistry::Find(), GetComponentTypeID_Static(), INVALID_ENTITY_ID, m_prefabRegistry, m_prefabsPreloaded, and SYSTEM_LOG.
Referenced by VideoGame::AddPlayerEntity(), and CreateEntity().
Here is the call graph for this function:
Here is the caller graph for this function:| EntityID PrefabFactory::CreateEntityWithOverrides | ( | const PrefabBlueprint & | blueprint, |
| const LevelInstanceParameters & | instanceParams, | ||
| bool | autoAssignLayer = true |
||
| ) |
Create entity from blueprint with level instance parameter overrides.
This is the unified method for both static and dynamic object creation.
| blueprint | Parsed prefab blueprint |
| instanceParams | Level instance parameters to override blueprint defaults |
| autoAssignLayer | If true, automatically assign layer based on EntityType |
Definition at line 245 of file PrefabFactory.cpp.
References ComponentDefinition::componentType, World::CreateEntity(), World::Get(), World::GetComponent(), GetComponentTypeID_Static(), World::GetDefaultLayerForType(), World::HasComponent(), InstantiateComponent(), INVALID_ENTITY_ID, Position_data::position, ParameterResolver::Resolve(), World::SetEntityLayer(), and SYSTEM_LOG.
Here is the call graph for this function:
|
inlinestatic |
Get singleton instance.
Definition at line 39 of file prefabfactory.h.
References GetComponentTypeID_Static().
Referenced by VideoGame::AddPlayerEntity(), Olympe::Tiled::TiledToOlympe::Convert(), World::Initialize_ECS_Systems(), VideoGame::InitializeAITestScene(), World::LoadLevelFromTiled(), RegisterComponentFactory_Internal(), BehaviorTreeDependencyScanner::ScanPrefabs(), and World::ValidateLevelPrefabs().
Here is the call graph for this function:
Here is the caller graph for this function:| bool PrefabFactory::GetCanonicalInfo | ( | const std::string & | type, |
| std::string & | outCanonical, | ||
| std::string & | outPrefabFile | ||
| ) | const |
Get canonical type info for debugging.
| type | Type to query |
| outCanonical | Output parameter for canonical type name |
| outPrefabFile | Output parameter for prefab file path |
Definition at line 183 of file PrefabFactory.cpp.
References GetComponentTypeID_Static(), and m_scanner.
Here is the call graph for this function:
|
inline |
Create entity from prefab name with explicit layer override.
Get prefab count
Definition at line 94 of file prefabfactory.h.
References PrefabRegistry::GetCount(), and m_prefabRegistry.
Here is the call graph for this function:
|
inline |
Get the cached prefab registry.
Definition at line 142 of file prefabfactory.h.
References m_prefabRegistry.
Referenced by BehaviorTreeDependencyScanner::ScanPrefabs().
Here is the caller graph for this function:| std::vector< std::string > PrefabFactory::GetRegisteredComponents | ( | ) | const |
Get list of all registered components (for debugging)
Definition at line 51 of file PrefabFactory.cpp.
References GetComponentTypeID_Static(), and m_componentFactories.
Here is the call graph for this function:Check if prefab exists.
| prefabName | Name of the prefab to check |
Definition at line 101 of file prefabfactory.h.
References PrefabRegistry::Find(), and m_prefabRegistry.
Here is the call graph for this function:
|
private |
Definition at line 776 of file PrefabFactory.cpp.
References World::AddComponent(), AIBehavior_data::behaviorType, World::Get(), and GetComponentTypeID_Static().
Referenced by InstantiateComponent().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Definition at line 788 of file PrefabFactory.cpp.
References World::Get(), World::GetComponent(), GetComponentTypeID_Static(), and AIBlackboard_data::targetEntity.
Referenced by InstantiateComponent().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Definition at line 825 of file PrefabFactory.cpp.
References World::Get(), World::GetComponent(), GetComponentTypeID_Static(), and AISenses_data::visionRadius.
Referenced by InstantiateComponent().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Definition at line 1248 of file PrefabFactory.cpp.
References World::AddComponent(), Combat, AIState_data::currentMode, Dead, Flee, World::Get(), GetComponentTypeID_Static(), Idle, Investigate, Patrol, and SYSTEM_LOG.
Referenced by InstantiateComponent().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Definition at line 973 of file PrefabFactory.cpp.
References World::AddComponent(), Animation_data::animationID, Animation_data::currentFrame, Animation_data::frameDuration, World::Get(), and GetComponentTypeID_Static().
Referenced by InstantiateComponent().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Definition at line 1421 of file PrefabFactory.cpp.
References World::AddComponent(), AttackIntent_data::Area, World::Get(), GetComponentTypeID_Static(), AttackIntent_data::Melee, AttackIntent_data::Ranged, SYSTEM_LOG, and AttackIntent_data::targetEntity.
Referenced by InstantiateComponent().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Definition at line 1006 of file PrefabFactory.cpp.
References World::AddComponent(), World::Get(), GetComponentTypeID_Static(), AudioSource_data::soundEffectID, and AudioSource_data::volume.
Referenced by InstantiateComponent().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Definition at line 1297 of file PrefabFactory.cpp.
References BehaviorTreeRuntime_data::AITreeAssetId, BehaviorTreeManager::Get(), World::Get(), World::GetComponent(), GetComponentTypeID_Static(), BehaviorTreeManager::GetTree(), BehaviorTreeManager::GetTreeIdFromPath(), and World::HasComponent().
Referenced by InstantiateComponent().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Definition at line 862 of file PrefabFactory.cpp.
References World::AddComponent(), BoundingBox_data::boundingBox, World::Get(), and GetComponentTypeID_Static().
Referenced by InstantiateComponent().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Definition at line 1110 of file PrefabFactory.cpp.
References World::AddComponent(), World::Get(), GetComponentTypeID_Static(), and Camera_data::playerId.
Referenced by InstantiateComponent().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Definition at line 1167 of file PrefabFactory.cpp.
References World::AddComponent(), CameraBounds_data::boundingBox, World::Get(), GetComponentTypeID_Static(), and CameraBounds_data::useBounds.
Referenced by InstantiateComponent().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Definition at line 1149 of file PrefabFactory.cpp.
References World::AddComponent(), World::Get(), GetComponentTypeID_Static(), and CameraEffects_data::isShaking.
Referenced by InstantiateComponent().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Definition at line 1188 of file PrefabFactory.cpp.
References World::AddComponent(), World::Get(), GetComponentTypeID_Static(), and CameraInputBinding_data::playerId.
Referenced by InstantiateComponent().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Definition at line 1131 of file PrefabFactory.cpp.
References World::AddComponent(), World::Get(), GetComponentTypeID_Static(), and CameraTarget_data::targetEntityID.
Referenced by InstantiateComponent().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Definition at line 952 of file PrefabFactory.cpp.
References World::AddComponent(), CollisionZone_data::bounds, World::Get(), GetComponentTypeID_Static(), and CollisionZone_data::isStatic.
Referenced by InstantiateComponent().
Here is the call graph for this function:
Here is the caller graph for this function:| bool PrefabFactory::InstantiateComponent | ( | EntityID | entity, |
| const ComponentDefinition & | componentDef | ||
| ) |
Instantiate a single component on an entity.
Component-agnostic instantiation method that works with any registered component type.
| entity | EntityID to add component to |
| componentDef | Component definition with type and parameters |
Definition at line 330 of file PrefabFactory.cpp.
References GetComponentTypeID_Static(), InstantiateAIBehavior(), InstantiateAIBlackboard(), InstantiateAISenses(), InstantiateAIState(), InstantiateAnimation(), InstantiateAttackIntent(), InstantiateAudioSource(), InstantiateBehaviorTreeRuntime(), InstantiateBoundingBox(), InstantiateCamera(), InstantiateCameraBounds(), InstantiateCameraEffects(), InstantiateCameraInputBinding(), InstantiateCameraTarget(), InstantiateCollisionZone(), InstantiateController(), InstantiateFX(), InstantiateHealth(), InstantiateIdentity(), InstantiateInputMapping(), InstantiateInventory(), InstantiateMoveIntent(), InstantiateMovement(), InstantiateNavigationAgent(), InstantiateNPC(), InstantiatePhysicsBody(), InstantiatePlayerBinding(), InstantiatePlayerController(), InstantiatePosition(), InstantiateTriggerZone(), InstantiateVisualAnimation(), InstantiateVisualEditor(), InstantiateVisualSprite(), m_componentFactories, and SYSTEM_LOG.
Referenced by CreateEntityFromBlueprint(), and CreateEntityWithOverrides().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Definition at line 1021 of file PrefabFactory.cpp.
References World::AddComponent(), Controller_data::controllerID, World::Get(), and GetComponentTypeID_Static().
Referenced by InstantiateComponent().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Definition at line 991 of file PrefabFactory.cpp.
References World::AddComponent(), FX_data::effectType, World::Get(), and GetComponentTypeID_Static().
Referenced by InstantiateComponent().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Definition at line 921 of file PrefabFactory.cpp.
References World::AddComponent(), Health_data::currentHealth, World::Get(), and GetComponentTypeID_Static().
Referenced by InstantiateComponent().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Definition at line 481 of file PrefabFactory.cpp.
References World::Get(), World::GetComponent(), GetComponentTypeID_Static(), Identity_data::name, and StringToEntityType().
Referenced by InstantiateComponent().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Definition at line 1206 of file PrefabFactory.cpp.
References World::AddComponent(), World::Get(), GetComponentTypeID_Static(), and InputMapping_data::InitializeDefaults().
Referenced by InstantiateComponent().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Definition at line 1099 of file PrefabFactory.cpp.
References World::AddComponent(), World::Get(), and GetComponentTypeID_Static().
Referenced by InstantiateComponent().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Definition at line 1375 of file PrefabFactory.cpp.
References World::Get(), World::GetComponent(), GetComponentTypeID_Static(), and MoveIntent_data::targetPosition.
Referenced by InstantiateComponent().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Definition at line 889 of file PrefabFactory.cpp.
References World::AddComponent(), Movement_data::direction, World::Get(), and GetComponentTypeID_Static().
Referenced by InstantiateComponent().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Definition at line 1224 of file PrefabFactory.cpp.
References NavigationAgent_data::agentRadius, World::Get(), World::GetComponent(), GetComponentTypeID_Static(), and SYSTEM_LOG.
Referenced by InstantiateComponent().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Definition at line 1087 of file PrefabFactory.cpp.
References World::AddComponent(), World::Get(), GetComponentTypeID_Static(), and NPC_data::npcType.
Referenced by InstantiateComponent().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Definition at line 544 of file PrefabFactory.cpp.
References World::Get(), World::GetComponent(), GetComponentTypeID_Static(), and PhysicsBody_data::mass.
Referenced by InstantiateComponent().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Definition at line 1071 of file PrefabFactory.cpp.
References World::AddComponent(), World::Get(), GetComponentTypeID_Static(), and PlayerBinding_data::playerIndex.
Referenced by InstantiateComponent().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Definition at line 1041 of file PrefabFactory.cpp.
References World::AddComponent(), World::Get(), GetComponentTypeID_Static(), and PlayerController_data::isJumping.
Referenced by InstantiateComponent().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Definition at line 514 of file PrefabFactory.cpp.
References World::Get(), World::GetComponent(), GetComponentTypeID_Static(), and Position_data::position.
Referenced by InstantiateComponent().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Definition at line 937 of file PrefabFactory.cpp.
References World::AddComponent(), World::Get(), GetComponentTypeID_Static(), and TriggerZone_data::radius.
Referenced by InstantiateComponent().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Definition at line 727 of file PrefabFactory.cpp.
References VisualAnimation_data::bankId, World::Get(), World::GetComponent(), and GetComponentTypeID_Static().
Referenced by InstantiateComponent().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Definition at line 665 of file PrefabFactory.cpp.
References World::AddComponent(), GameEntity, DataManager::Get(), World::Get(), GetComponentTypeID_Static(), DataManager::GetSprite(), VisualEditor_data::sprite, and SYSTEM_LOG.
Referenced by InstantiateComponent().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Definition at line 578 of file PrefabFactory.cpp.
References GameEntity, DataManager::Get(), World::Get(), World::GetComponent(), GetComponentTypeID_Static(), DataManager::GetSprite(), VisualSprite_data::sprite, and SYSTEM_LOG.
Referenced by InstantiateComponent().
Here is the call graph for this function:
Here is the caller graph for this function:Check if a component is registered.
Definition at line 46 of file PrefabFactory.cpp.
References GetComponentTypeID_Static(), and m_componentFactories.
Here is the call graph for this function:Check if a type is registered.
| type | Type string to check (will be normalized) |
Definition at line 174 of file PrefabFactory.cpp.
References m_scanner.
| std::string PrefabFactory::NormalizeType | ( | const std::string & | type | ) | const |
Normalize a type string to canonical form.
| type | Type string to normalize |
Definition at line 156 of file PrefabFactory.cpp.
References m_scanner.
| void PrefabFactory::PreloadAllPrefabs | ( | const std::string & | prefabDirectory = "Blueprints/EntityPrefab" | ) |
Preload all prefabs from directory.
Scans and caches all prefab blueprints for fast entity creation. Should be called once at engine startup (World::Initialize).
| prefabDirectory | Path to prefab directory (default: "Blueprints/EntityPrefab") |
Definition at line 73 of file PrefabFactory.cpp.
References PrefabBlueprint::components, PrefabRegistry::Find(), PrefabRegistry::GetAllPrefabNames(), GetComponentTypeID_Static(), PrefabRegistry::GetCount(), m_prefabRegistry, m_prefabsPreloaded, m_scanner, and SYSTEM_LOG.
Referenced by World::Initialize_ECS_Systems().
Here is the call graph for this function:
Here is the caller graph for this function:| void PrefabFactory::RegisterComponentFactory | ( | const std::string & | componentName, |
| std::function< bool(EntityID, const ComponentDefinition &)> | factory | ||
| ) |
Register a component factory (called by auto-registration system)
Definition at line 31 of file PrefabFactory.cpp.
References GetComponentTypeID_Static(), and m_componentFactories.
Referenced by RegisterComponentFactory_Internal().
Here is the call graph for this function:
Here is the caller graph for this function:
|
inline |
Register a legacy prefab builder function.
| name | Prefab name |
| builder | Function that builds the entity |
Definition at line 115 of file prefabfactory.h.
References GetComponentTypeID_Static(), m_prefabs, and SYSTEM_LOG.
Here is the call graph for this function:| void PrefabFactory::SetPrefabRegistry | ( | const PrefabRegistry & | registry | ) |
Set the prefab registry cache.
| registry | PrefabRegistry to use for lookups |
Definition at line 144 of file PrefabFactory.cpp.
References GetComponentTypeID_Static(), PrefabRegistry::GetCount(), m_prefabRegistry, m_prefabsPreloaded, and SYSTEM_LOG.
Here is the call graph for this function:
|
private |
Definition at line 218 of file prefabfactory.h.
Referenced by GetRegisteredComponents(), InstantiateComponent(), IsComponentRegistered(), and RegisterComponentFactory().
|
private |
Definition at line 213 of file prefabfactory.h.
Referenced by CreateEntityFromPrefabName(), GetPrefabCount(), GetPrefabRegistry(), HasPrefab(), PreloadAllPrefabs(), and SetPrefabRegistry().
|
private |
Definition at line 212 of file prefabfactory.h.
Referenced by CreateEntity(), and RegisterPrefab().
Definition at line 214 of file prefabfactory.h.
Referenced by CreateEntityFromPrefabName(), PreloadAllPrefabs(), and SetPrefabRegistry().
|
private |
Definition at line 215 of file prefabfactory.h.
Referenced by AreTypesEquivalent(), GetCanonicalInfo(), IsTypeRegistered(), NormalizeType(), and PreloadAllPrefabs().