gdc 2010 - a dynamic component architecture for high performance gameplay - may, 2010

Download GDC 2010 - A Dynamic Component Architecture for High Performance Gameplay - May, 2010

If you can't read please download the document

Upload: terrance-cohen

Post on 30-Jul-2015

99 views

Category:

Technology


2 download

TRANSCRIPT

1. A Dynamic Component Architecturefor High Performance GameplayTerrance CohenLead Systems EngineerInsomniac Games 2. A Dynamic Component Architecture for High Performance Gameplay Purpose The Dynamic Component System Implementation by Example Questions (note slide #) 3. A Dynamic Component Architecture for High Performance Gameplay Purposeo Statement of Problemo Proposed Solution The Dynamic Component System Implementation by Example 4. Purpose : Statement of Problem Monolithic / deep Game Object hierarchyo Memory: binds data @ compile time Allocated throughout lifetime 5. Purpose : Statement of Problem Monolithic / deep Game Object hierarchy:o Memory: binds data @ compile timeo Performance: poor cache coherence Arrays of non-homogeneous objects Virtual dispatch Fragmented instance data 6. Purpose : Statement of Problem Monolithic / deep Game Object hierarchy:o Memory: binds data @ compile timeo Performance: poor cache coherenceo Architecture: capability inheritance Fixed at compile time Fully determined by class Change capabilities -> change hierarchy 7. Purpose : Statement of Problem Monolithic / deep Game Object hierarchy:o Memory: binds data @ compile timeo Performance: poor cache coherenceo Architecture: capability inheritance "What were used to" But select the best tool for the job. 8. Purpose : Statement of Problem Monolithic / deep Game Object hierarchy:o Memory: binds data @ compile timeo Performance: poor cache coherenceo Architecture: capability inheritance "What were used to" But select the best tool for the job. Theres a better way! 9. A Dynamic Component Architecture for High Performance Gameplay Purposeo Statement of Problemo Proposed Solution The Dynamic Component System Implementation by Example 10. Purpose : Proposed Solution Construction of Game Object through composition ofcomponents at runtime 11. Purpose : Proposed Solution Construction of Game Object through composition ofcomponents at runtime Simple! Thank you for coming! 12. Purpose : Proposed Solution Construction of Game Object through composition ofcomponents at runtime Simple! Thank you for coming!o Oh, you want details !?! 13. Purpose : Proposed Solution Construction of Game Object through composition ofcomponents at runtime Small chunks Represent a data transformation 14. A Dynamic Component Architecture for High Performance Gameplay Purpose The Dynamic Component Systemo Features Implementation by Example 15. The Dynamic Component System Evolution o Resistance 1 - Proof of Concept (1 type) o Resistance 2 - "Early Adopters" (32 types) o Ongoing (295 types as of May 1st 2010) Majority of new gameplay code Large portions of old gameplay refactored 16. The Dynamic Component System Evolution o Resistance 1 - Proof of Concept (1 type) o Resistance 2 - "Early Adopters" (32 types) o Ongoing (295 types as of May 1st 2010) Majority of new gameplay code Large portions of old gameplay refactored So its mature. 17. The Dynamic Component System Evolution o Resistance 1 - Proof of Concept (1 type) o Resistance 2 - "Early Adopters" (32 types) o Ongoing (295 types as of May 1st 2010) Majority of new gameplay code Large portions of old gameplay refactored So its mature. (No, not that way.) 18. The Dynamic Component System Side-by-side implementation o Not necessary to refactor existing code o Coexist with components General solution 19. The Dynamic Component System Does notaddress matters ofo Reflectiono Serializationo Data buildingo Instance versioningo ... those things are handled separately outside the scope of this discussion 20. A Dynamic Component Architecture for High Performance Gameplay Purpose The Dynamic Component Systemo Features Implementation by Example 21. Dynamic Component System : Features Components High-performance Dynamic System 22. Dynamic Component System : Features Components o Originally Aspects o Base Component class 8 bytes of administrative data o Allocated from pools One pool per concrete type "Roster" indexes instances "Partition" separates allocated/free instances 23. Dynamic Component System : Features Components High-performance o Small, constant-time operations Allocate/free Resolve handle Get type Type implements (derived from) o No instance copying 24. Dynamic Component System : Features Components High-performance o Updates per-type (per-pool) Cache friendly o Encourage async update e.g. on SPU Roster: contiguous list of allocd instances Roster up to partitionisDMA list 25. Dynamic Component System : Features Components High-performance o Resolving handle Small, constant-time operation: Index into Pool Compare generation Return Component* 26. Dynamic Component System : Features Components High-performance Dynamic o Runtime composition of game objects Dynamically alter behavior without baggage o Component allocated == in use o Pool sizes == max concurrent allocations 27. Dynamic Component System : Features Components High-performance Dynamic o High-frequency alloc() & free() alloc(): test for availability make handle from index & generation increment Roster Partition Component::Init() 28. Dynamic Component System : Features Components High-performance Dynamic o High-frequency alloc() & free() alloc(): free(): Component::Deinit() swap Roster index with Partition-adjacentindex decrement Partition increment generation 29. Demo : DynamicComponent::Free()//freethecomponentfromhostscomponentchainvoidDynamicComponent::Free(Typetype,HostHandlehost_handle,Chain&chain,ComponentHandle&component_handle); 30. Demo : DynamicComponent::Free()//freethecomponentfromhostscomponentchainvoidDynamicComponent::Free(Typetype,HostHandlehost_handle,Chain&chain,ComponentHandle&component_handle); 31. Demo : DynamicComponent::Free()//freethecomponentfromhostscomponentchainvoidDynamicComponent::Free(Typetype,HostHandlehost_handle,Chain&chain,ComponentHandle&component_handle); 32. Demo : DynamicComponent::Free()//freethecomponentfromhostscomponentchainvoidDynamicComponent::Free(Typetype,HostHandlehost_handle,Chain&chain,ComponentHandle&component_handle); 33. Demo : DynamicComponent::Free()//freethecomponentfromhostscomponentchainvoidDynamicComponent::Free(Typetype,HostHandlehost_handle,Chain&chain,ComponentHandle&component_handle); 34. Dynamic Component System : Features Components High-performance Dynamic System o Not all-or-nothing! o Examples: Conversation Script Events Shots: no game object 35. A Dynamic Component Architecture for High Performance Gameplay Purpose The Dynamic Component System Implementation by Example o API o Script Events: Type Registration o Navigation: Allocation & Init o Shots: Asynchronous Update 36. namespaceDynamicComponent{////HostsAPI////CallthesefromGameObjects(orotherobjects)thathostDynamicComponents//___________________________________________________________________________________________________//allocateacomponentoftype,addittohostscomponentchain,//andoptionallyparkapriusinthecomponent//returnsnullifnospaceisavailableforallocationComponent*Allocate(Typetype,HostHandlehost_handle,Chain*chain,void*prius=NULL); 37. namespace DynamicComponent{//// Hosts API//// Call these from GameObjects (or other objects) that host Dynamic Components// Component*Allocate ( Type type, HostHandle host_handle,Chain* chain, void* prius = NULL );___________________________________________________________________________________________________ //resolve a ComponentHandle to a Component // returns NULL if component_handle is null or is a stale handle // (i.e. component instance has been reused) Component*ResolveHandle( Type type, ComponentHandle component_handle ); 38. namespace DynamicComponent{//// Hosts API//// Call these from GameObjects (or other objects) that host Dynamic Components// Component*Allocate ( Type type, HostHandle host_handle,Chain* chain, void* prius = NULL );Component*ResolveHandle ( Type type, ComponentHandle component_handle );___________________________________________________________________________________________________ //get one component of type that belongs to host Component*Get ( Type type, HostHandle host_handle, Chain chain ); 39. namespace DynamicComponent{//// Hosts API//// Call these from GameObjects (or other objects) that host Dynamic Components// Component*Allocate ( Type type, HostHandle host_handle,Chain* chain, void* prius = NULL );Component*ResolveHandle ( Type type, ComponentHandle component_handle );Component*Get ( Type type, HostHandle host_handle, Chain chain );___________________________________________________________________________________________________ //get the first Component in hosts chain that implements the type interface Component*GetComponentThatImplements( Type type, HostHandle host_handle, Chain chain ); 40. namespace DynamicComponent{//// Hosts API//// Call these from GameObjects (or other objects) that host Dynamic Components// Component*Allocate ( Type type, HostHandle host_handle,Chain* chain, void* prius = NULL );Component*ResolveHandle ( Type type, ComponentHandle component_handle );Component*Get ( Type type, HostHandle host_handle, Chain chain );Component*GetComponentThatImplements( Type type, HostHandle host_handle, Chain chain );___________________________________________________________________________________________________ //get all Components of type in hosts chain, up to a max of count instances. // count should be passed with the size of the component array. // on return, count will contain the number of matching components, up to the specified limit. Component** GetComponents ( Type type, HostHandle host_handle, Chain chain, u32& count ); 41. namespace DynamicComponent{//// Hosts API//// Call these from GameObjects (or other objects) that host Dynamic Components// Component*Allocate ( Type type, HostHandle host_handle,Chain* chain, void* prius = NULL );Component*ResolveHandle ( Type type, ComponentHandle component_handle );Component*Get ( Type type, HostHandle host_handle, Chain chain );Component*GetComponentThatImplements( Type type, HostHandle host_handle, Chain chain );Component** GetComponents ( Type type, HostHandle host_handle,Chain chain, u32& count );___________________________________________________________________________________________________ //get all Components in hosts chain that implement types interface. // count should be passed with the size of the component array. // on return, count will contain the number of matching components, up to the specified limit. Component** GetComponentsThatImplement( Type type, HostHandle host_handle, Chain chain, u32& count ); 42. namespace DynamicComponent{//// Hosts API//// Call these from GameObjects (or other objects) that host Dynamic Components// Component*Allocate ( Type type, HostHandle host_handle,Chain* chain, void* prius = NULL );Component*ResolveHandle ( Type type, ComponentHandle component_handle );Component*Get ( Type type, HostHandle host_handle, Chain chain );Component*GetComponentThatImplements( Type type, HostHandle host_handle, Chain chain );Component** GetComponents ( Type type, HostHandle host_handle,Chain chain, u32& count );Component** GetComponentsThatImplement( Type type, HostHandle host_handle,Chain chain, u32& count );___________________________________________________________________________________________________ //free the component from hosts component chain voidFree( Type type, HostHandle host_handle, Chain& chain, ComponentHandle& component_handle ); 43. namespace DynamicComponent{//// Hosts API//// Call these from GameObjects (or other objects) that host Dynamic Components// Component*Allocate ( Type type, HostHandle host_handle,Chain* chain, void* prius = NULL );Component*ResolveHandle ( Type type, ComponentHandle component_handle );Component*Get ( Type type, HostHandle host_handle, Chain chain );Component*GetComponentThatImplements( Type type, HostHandle host_handle, Chain chain );Component** GetComponents ( Type type, HostHandle host_handle,Chain chain, u32& count );Component** GetComponentsThatImplement( Type type, HostHandle host_handle,Chain chain, u32& count );voidFree( Type type, HostHandle host_handle, Chain& chain,ComponentHandle& component_handle );___________________________________________________________________________________________________ //free all of the components in hosts component chain // (GameObjects automatically free their component chain when they are destroyed) voidFreeChain ( HostHandle host_handle, Chain& chain ); 44. namespace DynamicComponent{//// Hosts API//// Call these from GameObjects (or other objects) that host Dynamic Components// Component*Allocate ( Type type, HostHandle host_handle,Chain* chain, void* prius = NULL );Component*ResolveHandle ( Type type, ComponentHandle component_handle );Component*Get ( Type type, HostHandle host_handle, Chain chain );Component*GetComponentThatImplements( Type type, HostHandle host_handle, Chain chain );Component** GetComponents ( Type type, HostHandle host_handle,Chain chain, u32& count );Component** GetComponentsThatImplement( Type type, HostHandle host_handle,Chain chain, u32& count );voidFree( Type type, HostHandle host_handle, Chain& chain,ComponentHandle& component_handle );voidFreeChain ( HostHandle host_handle, Chain& chain );___________________________________________________________________________________________________//downcast a Component* to one of its subclasses.// please use this instead of the c-style (Type*)object so that casts are checked in debug//Example:// HeadComponent* my_head = COMPONENT_CAST(component_ptr, Head);//#define COMPONENT_CAST(component, type) ((type##Component*)ValidCast(component, DynamicComponent::type))inline Component* ValidCast ( Component* component, Type type ); 45. namespace DynamicComponent{// Hosts API Component*Allocate( Type type, HostHandle host_handle, Chain* chain, void* prius = NULL ); Component*ResolveHandle ( Type type, ComponentHandle component_handle ); Component*Get ( Type type, HostHandle host_handle, Chain chain ); Component*GetComponentThatImplements( Type type, HostHandle host_handle, Chain chain ); Component** GetComponents ( Type type, HostHandle host_handle, Chain chain, u32& count ); Component** GetComponentsThatImplement( Type type, HostHandle host_handle, Chain chain, u32& count ); voidFree( Type type, HostHandle host_handle, Chain& chain, ComponentHandle& component_handle ); voidFreeChain ( HostHandle host_handle, Chain& chain );#define COMPONENT_CAST(component, type) ((type##Component*)ValidCast(component, DynamicComponent::type))inline Component* ValidCast ( Component* component, Type type );___________________________________________________________________________________________________ // // Systems API // // Call these from systems that use the DCS // //get a list of component types that implement the interface of the given component type // count should be passed with the size of the types array. // on return, count will contain the number of matching component types, // up to the specified limit. Type* GetTypesThatImplement ( Type type, u32& count ); 46. namespace DynamicComponent{// Hosts API Component*Allocate( Type type, HostHandle host_handle, Chain* chain, void* prius = NULL ); Component*ResolveHandle ( Type type, ComponentHandle component_handle ); Component*Get ( Type type, HostHandle host_handle, Chain chain ); Component*GetComponentThatImplements( Type type, HostHandle host_handle, Chain chain ); Component** GetComponents ( Type type, HostHandle host_handle, Chain chain, u32& count ); Component** GetComponentsThatImplement( Type type, HostHandle host_handle, Chain chain, u32& count ); voidFree( Type type, HostHandle host_handle, Chain& chain, ComponentHandle& component_handle ); voidFreeChain ( HostHandle host_handle, Chain& chain );#define COMPONENT_CAST(component, type) ((type##Component*)ValidCast(component, DynamicComponent::type))inline Component* ValidCast ( Component* component, Type type ); // // Systems API // // Call these from systems that use the DCS //Type* GetTypesThatImplement ( Type type, u32& count );___________________________________________________________________________________________________ //returns whether component type implements interface boolTypeImplements( Type type, Type interface ); 47. namespace DynamicComponent{// Hosts API Component*Allocate( Type type, HostHandle host_handle, Chain* chain, void* prius = NULL ); Component*ResolveHandle ( Type type, ComponentHandle component_handle ); Component*Get ( Type type, HostHandle host_handle, Chain chain ); Component*GetComponentThatImplements( Type type, HostHandle host_handle, Chain chain ); Component** GetComponents ( Type type, HostHandle host_handle, Chain chain, u32& count ); Component** GetComponentsThatImplement( Type type, HostHandle host_handle, Chain chain, u32& count ); voidFree( Type type, HostHandle host_handle, Chain& chain, ComponentHandle& component_handle ); voidFreeChain ( HostHandle host_handle, Chain& chain );#define COMPONENT_CAST(component, type) ((type##Component*)ValidCast(component, DynamicComponent::type))inline Component* ValidCast ( Component* component, Type type ); // // Systems API // // Call these from systems that use the DCS //Type* GetTypesThatImplement ( Type type, u32& count );boolTypeImplements( Type type, Type interface );___________________________________________________________________________________________________ //returns the number of components of type that are currently allocated u32 GetNumAllocated ( Type type ); 48. namespace DynamicComponent{// Hosts API Component*Allocate( Type type, HostHandle host_handle, Chain* chain, void* prius = NULL ); Component*ResolveHandle ( Type type, ComponentHandle component_handle ); Component*Get ( Type type, HostHandle host_handle, Chain chain ); Component*GetComponentThatImplements( Type type, HostHandle host_handle, Chain chain ); Component** GetComponents ( Type type, HostHandle host_handle, Chain chain, u32& count ); Component** GetComponentsThatImplement( Type type, HostHandle host_handle, Chain chain, u32& count ); voidFree( Type type, HostHandle host_handle, Chain& chain, ComponentHandle& component_handle ); voidFreeChain ( HostHandle host_handle, Chain& chain );#define COMPONENT_CAST(component, type) ((type##Component*)ValidCast(component, DynamicComponent::type))inline Component* ValidCast ( Component* component, Type type ); // // Systems API // // Call these from systems that use the DCS //Type* GetTypesThatImplement ( Type type, u32& count );boolTypeImplements( Type type, Type interface );u32 GetNumAllocated ( Type type );___________________________________________________________________________________________________ //returns an array of pointers to all allocated components of type, their count, // and their size Component** GetComponents ( Type type, u32& count ); //returns an array of all components of type (including unallocated instances!), // an array of the indices of allocated components within that array, // and the count of indices Component*GetComponentsIndexed( Type type, u16*& indices, u32& count ); 49. namespace DynamicComponent{// Hosts API Component*Allocate( Type type, HostHandle host_handle, Chain* chain, void* prius = NULL ); Component*ResolveHandle ( Type type, ComponentHandle component_handle ); Component*Get ( Type type, HostHandle host_handle, Chain chain ); Component*GetComponentThatImplements( Type type, HostHandle host_handle, Chain chain ); Component** GetComponents ( Type type, HostHandle host_handle, Chain chain, u32& count ); Component** GetComponentsThatImplement( Type type, HostHandle host_handle, Chain chain, u32& count ); voidFree( Type type, HostHandle host_handle, Chain& chain, ComponentHandle& component_handle ); voidFreeChain ( HostHandle host_handle, Chain& chain );#define COMPONENT_CAST(component, type) ((type##Component*)ValidCast(component, DynamicComponent::type))inline Component* ValidCast ( Component* component, Type type ); // // Systems API // // Call these from systems that use the DCS //Type* GetTypesThatImplement ( Type type, u32& count );boolTypeImplements( Type type, Type interface );u32 GetNumAllocated ( Type type );Component** GetComponents ( Type type, u32& count );Component*GetComponentsIndexed( Type type, u16*& indices, u32& count );___________________________________________________________________________________________________ //updates all components of those types that want to be updated in the given UpdateStage voidUpdateComponents( UpdateStage::Enum stage ); 50. namespace DynamicComponent{// Hosts API Component*Allocate( Type type, HostHandle host_handle, Chain* chain, void* prius = NULL ); Component*ResolveHandle ( Type type, ComponentHandle component_handle ); Component*Get ( Type type, HostHandle host_handle, Chain chain ); Component*GetComponentThatImplements( Type type, HostHandle host_handle, Chain chain ); Component** GetComponents ( Type type, HostHandle host_handle, Chain chain, u32& count ); Component** GetComponentsThatImplement( Type type, HostHandle host_handle, Chain chain, u32& count ); voidFree( Type type, HostHandle host_handle, Chain& chain, ComponentHandle& component_handle ); voidFreeChain ( HostHandle host_handle, Chain& chain );#define COMPONENT_CAST(component, type) ((type##Component*)ValidCast(component, DynamicComponent::type))inline Component* ValidCast ( Component* component, Type type ); // // Systems API // // Call these from systems that use the DCS //Type* GetTypesThatImplement ( Type type, u32& count );boolTypeImplements( Type type, Type interface );u32 GetNumAllocated ( Type type );Component** GetComponents ( Type type, u32& count );Component*GetComponentsIndexed( Type type, u16*& indices, u32& count );voidUpdateComponents( UpdateStage::Enum stage );___________________________________________________________________________________________________ //frees a component that was allocated without a host, and is not in any chain voidFree( Type type, ComponentHandle& component_handle ); 51. namespace DynamicComponent{// Hosts API Component*Allocate( Type type, HostHandle host_handle, Chain* chain, void* prius = NULL ); Component*ResolveHandle ( Type type, ComponentHandle component_handle ); Component*Get ( Type type, HostHandle host_handle, Chain chain ); Component*GetComponentThatImplements( Type type, HostHandle host_handle, Chain chain ); Component** GetComponents ( Type type, HostHandle host_handle, Chain chain, u32& count ); Component** GetComponentsThatImplement( Type type, HostHandle host_handle, Chain chain, u32& count ); voidFree( Type type, HostHandle host_handle, Chain& chain, ComponentHandle& component_handle ); voidFreeChain ( HostHandle host_handle, Chain& chain );#define COMPONENT_CAST(component, type) ((type##Component*)ValidCast(component, DynamicComponent::type))inline Component* ValidCast ( Component* component, Type type ); // // Systems API // // Call these from systems that use the DCS //Type* GetTypesThatImplement ( Type type, u32& count );boolTypeImplements( Type type, Type interface );u32 GetNumAllocated ( Type type );Component** GetComponents ( Type type, u32& count );Component*GetComponentsIndexed( Type type, u16*& indices, u32& count );voidUpdateComponents( UpdateStage::Enum stage );voidFree( Type type, ComponentHandle& component_handle );___________________________________________________________________________________________________ //returns the current PPU UpdateStage::Enum. // will be UpdateStage::None unless UpdateComponents() is on the stack. UpdateStage::Enum GetCurrentUpdateStage( ); 52. namespace DynamicComponent{// Hosts APIComponent* Allocate( Type type, HostHandle host_handle, Chain* chain, void* prius = NULL );Component* ResolveHandle ( Type type, ComponentHandle component_handle );Component* Get ( Type type, HostHandle host_handle, Chain chain );Component* GetComponentThatImplements( Type type, HostHandle host_handle, Chain chain );Component**GetComponents ( Type type, HostHandle host_handle, Chain chain, u32& count );Component**GetComponentsThatImplement( Type type, HostHandle host_handle, Chain chain, u32& count );void Free( Type type, HostHandle host_handle, Chain& chain, ComponentHandle& component_handle );void FreeChain ( HostHandle host_handle, Chain& chain );#define COMPONENT_CAST(component, type) ((type##Component*)ValidCast(component, DynamicComponent::type))inline Component* ValidCast ( Component* component, Type type );//// Systems API//// Call these from systems that use the DCS//Type* GetTypesThatImplement ( Type type, u32& count );boolTypeImplements( Type type, Type interface );u32 GetNumAllocated ( Type type );Component** GetComponents ( Type type, u32& count );Component*GetComponentsIndexed( Type type, u16*& indices, u32& count );voidUpdateComponents( UpdateStage::Enum stage );voidFree( Type type, ComponentHandle& component_handle );UpdateStage::Enum GetCurrentUpdateStage ( );___________________________________________________________________________________________________//returns true iff type updates in stageu8GetTypeUpdateStages ( Type type );} 53. namespace DynamicComponent{// Hosts APIComponent*Allocate( Type type, HostHandle host_handle,Chain* chain, void* prius = NULL );Component*ResolveHandle ( Type type, ComponentHandle component_handle );Component*Get ( Type type, HostHandle host_handle, Chain chain );Component*GetComponentThatImplements( Type type, HostHandle host_handle, Chain chain );Component** GetComponents ( Type type, HostHandle host_handle,Chain chain, u32& count );Component** GetComponentsThatImplement( Type type, HostHandle host_handle,Chain chain, u32& count );voidFree( Type type, HostHandle host_handle, Chain& chain,ComponentHandle& component_handle );voidFreeChain ( HostHandle host_handle, Chain& chain );#define COMPONENT_CAST(component, type) ((type##Component*)ValidCast(component, DynamicComponent::type))inline Component* ValidCast ( Component* component, Type type );// Systems APIType* GetTypesThatImplement ( Type type, u32& count );boolTypeImplements( Type type, Type interface );u32 GetNumAllocated ( Type type );Component** GetComponents ( Type type, u32& count );Component*GetComponentsIndexed( Type type, u16*& indices, u32& count );voidUpdateComponents( UpdateStage::Enum stage );voidFree( Type type, ComponentHandle& component_handle );UpdateStage::Enum GetCurrentUpdateStage ( );u8GetTypeUpdateStages ( Type type );} 54. A Dynamic Component Architecture for High Performance Gameplay Purpose The Dynamic Component System Implementation by Example o API o Script Events: Type Registration o Navigation: Allocation & Init o Shots: Asynchronous Update 55. Script Events : Type Registration Script Events are Components o Hosted by the System o Possibly related to a Game Object Registered (allocated) from Lua o When conditions are met, call back Satisfaction: 1.Updated: poll their conditions 2.Notified by gameplay 56. Script Events : Type RegistrationNotified Updated Checkpoint Location Damage Timer Death Visible NumAlive Active Customo Reloado Zoomo Grappleo SeatEnter 57. Script Events: Type RegistrationnamespaceDynamicComponent{typedefu16Type;Typeunregistered_type=0xFFFF;TypeTypeRegistrar::RegisterType(constchar*name,Typebase_type=unregistered_type,UpdateStage::Enumupdate_stages=UpdateStage::None,AsyncUpdateStage::Enumasync_update_stages=AsyncUpdateStage::None);} 58. Script Events: Type RegistrationnamespaceDynamicComponent{typedefu16Type;Typeunregistered_type=0xFFFF;TypeTypeRegistrar::RegisterType(constchar*name,Typebase_type=unregistered_type,UpdateStage::Enumupdate_stages=UpdateStage::None,AsyncUpdateStage::Enumasync_update_stages=AsyncUpdateStage::None);}usingnamespaceDynamicComponent;voidScriptEventSystem::Init(){m_event_type=TypeRegistrar::RegisterType("ScriptEvent");m_checkpoint_type=TypeRegistrar::RegisterType("CheckpointEvent",m_event_type);m_location_type=TypeRegistrar::RegisterType("LocationEvent",m_event_type,//baseclassisScriptEventUpdateStage::PostUpdate,//automaticallyupdatedonPPUduringPostUpdateAsyncUpdateStage::PreUpdate);//andontheSPUduringthePreUpdatestage} 59. A Dynamic Component Architecture for High Performance Gameplay Purpose The Dynamic Component System Implementation by Example o API o Script Events: Type Registration o Navigation: Allocation & Init o Shots: Asynchronous Update 60. Navigation : Allocation & Initialization NavComponents are hosted by Game Objects Updated by the Navigation system 61. Navigation : Allocation & Initialization Remember the API call to allocate a component://allocateacomponentoftype,addittohostscomponentchain,//andoptionallyparkapriusinthecomponent//returnsnullifnospaceisavailableforallocationComponent*DynamicComponent::Allocate(Typetype,HostHandlehost_handle,Chain*chain,void* prius = NULL); WTF is a prius? 62. Navigation : Allocation & Initialization Remember the API call to allocate a component: //allocateacomponentoftype,addittohostscomponentchain, //andoptionallyparkapriusinthecomponent //returnsnullifnospaceisavailableforallocation Component*DynamicComponent::Allocate(Typetype,HostHandlehost_handle, Chain*chain,void* prius = NULL); WTF is a prius?o initialization datao Runtimeor design-time data void* But is thatsafe!? 63. Navigation : Allocation & Initialization Initialization o NavQuery isthe Prius for a NavComponent o NavQuery::Submit() allocates a NavComponent, and passesitselfas the prius.NavComponent*NavQuery::Submit(GameObject*host){DynamicComponent::Typetype=GetComponentType();//virtualmemberofNavQueryDynamicComponent::Component*component=host->AllocateComponent(type,this);NavComponent*nav=COMPONENT_CAST(component,Nav);returnnav;} host->AllocateComponent()? Helper in GameObject:DynamicComponentComponent*GameObject::AllocateComponent(DynamicComponent::Typetype,void*prius){returnDynamicComponent::Allocate(type,m_handle,&m_component_chain,prius);} 64. Navigation : Allocation & Initialization Gameplay code examplevoidFollowerBot::Initialize(GameObject*target){Nav::GameObjectQuerysource_query(this);//queryclosestpointtogameobjectNav::GameObjectQuerytarget_query(target);Nav::PathQuerypath_query(source_query,target_query);Nav::PathComponent*m_path=path_query.Submit();} When navigation components are updated, endpointsand path are dynamically recomputed on SPU 65. A Dynamic Component Architecture for High Performance Gameplay Purpose The Dynamic Component System Implementation by Example o API o Script Events: Type Registration o Navigation: Allocation & Init o Shots: Asynchronous Update 66. Shots : Asynchronous Update Hosted by Game Object Replaces Projectile GameObjects Two DynamicComponent Type hierarchies: o Shot represents a state machine Notified o ShotAction represents thestateof a Shot Updated Shared 67. Shots : Asynchronous Update#ifndefSPU//PPUonlyclassShotMoveForward:publicShotAction{DERIVED_COMPONENT(ShotMoveForward,ShotAction)public:virtualvoidParkPrius(void*prius);virtualvoidUpdate(UpdateStage::Enumstage);#else//SPUonlystructShotMoveForward{puspu_vec4m_locationALIGNED(16);//shadowsShotAction::m_next_locationonPPU#endif//PPU&SPUsharedpuspu_vec4m_direction;f32m_speed;}__attribute__((aligned(16))); ShotAction::m_next_locationon PPU andShotMoveForward::m_locationon SPU share the same address 68. Shots : Asynchronous Update How? "Sentinel"//asynccomponentsmustindicatewheretheirasyncdatabegins#defineBEGIN_ASYNC_COMPONENT_DATAu32m_async_data[0]__attribute__((aligned(16)));classShotAction:publicDynamicComponent::Component{COMPONENT(ShotAction);//...DynamicComponent::Handlem_shot;DynamicComponent::Typem_shot_type;BEGIN_ASYNC_COMPONENT_DATAvec4fm_next_location;}; 69. A Dynamic Component Architecture for High Performance Gameplay Purpose The Dynamic Component System Implementation by Example 70. A Dynamic Component Architecture for High Performance Gameplay Purpose The Dynamic Component System Implementation by Example Thank You! Questions 71. A Dynamic Component Architecturefor High Performance Gameplay Visit me on the Web:http://www.TerranceCohen.com Follow me on Twitter:http://twitter.com/terrance_cohen Connect with me on LinkedIn:http://www.linkedin.com/in/terrancecohen Ask me anything:http://www.formspring.me/terrancecohen 72. A Dynamic Component Architecturefor High Performance GameplayTerrance CohenLead Systems EngineerInsomniac Gameswww.TerranceCohen.comTwitter: @terrance_cohen