Nebula
|
#include <world.h>
Classes | |
struct | AddStagedComponentCommand |
struct | AllocateInstanceCommand |
struct | DeallocInstanceCommand |
struct | RemoveComponentCommand |
Public Member Functions | |
World (WorldHash hash, WorldId id) | |
~World () | |
WorldHash | GetWorldHash () const |
WorldId | GetWorldId () const |
Entity | CreateEntity (bool immediate=true) |
Create a new empty entity. | |
Entity | CreateEntity (EntityCreateInfo const &info) |
Create a new entity from create info. | |
void | DeleteEntity (Entity entity) |
Delete entity. | |
bool | IsValid (Entity entity) |
Check if an entity ID is still valid. | |
bool | HasInstance (Entity entity) |
Check if an entity has an instance. It might be valid, but not have received an instance just after it has been created. | |
EntityMapping | GetEntityMapping (Entity entity) |
Returns the entity mapping of an entity. | |
bool | HasComponent (Entity entity, ComponentId component) |
Check if entity has a specific component. (SLOW!) | |
template<typename TYPE > | |
bool | HasComponent (Entity entity) |
Check if entity has a specific component. | |
MemDb::RowId | GetInstance (Entity entity) |
Get instance of entity. | |
template<typename TYPE > | |
void | RemoveComponent (Entity entity) |
Remove a component from an entity. | |
void | RemoveComponent (Entity entity, ComponentId component) |
Remove a component from an entity. | |
template<typename TYPE > | |
void | SetComponent (Entity entity, TYPE const &value) |
Set the value of an entitys component. | |
template<typename TYPE > | |
TYPE | GetComponent (Entity entity) |
Get an entitys component. | |
template<typename TYPE > | |
TYPE * | AddComponent (Entity entity) |
Create a component. This queues the component in a command buffer to be added later. | |
void * | AddComponent (Entity entity, ComponentId component) |
Add a component to an entity. This queues the component in a command buffer to be added later. | |
ComponentDecayBuffer const | GetDecayBuffer (ComponentId component) |
Get a decay buffer for the given component. | |
void | SetComponentValue (Entity entity, ComponentId component, void *value, uint64_t size) |
Set the value of a component by providing a pointer and type size. | |
void | ReinitializeComponent (Entity entity, ComponentId component, void *value, uint64_t size) |
Set the value of a component by providing a pointer and type size, then reinitialize the component. | |
Dataset | Query (Filter filter) |
Query the entity database using specified filter set. This does NOT wait for resources to be available. | |
Dataset | Query (Filter filter, Util::Array< MemDb::TableId > &tids) |
Query a subset of tables using a specified filter set. | |
Ptr< MemDb::Database > | GetDatabase () |
Get the entity database. Be careful when directly modifying the database, as some information is only kept track of via the World. | |
MemDb::TableId | CreateEntityTable (EntityTableCreateInfo const &info) |
Create a table in the entity database that has a specific set of components. | |
FramePipeline & | GetFramePipeline () |
Get the frame pipeline. | |
void | MarkAsModified (Game::Entity entity) |
Mark an entity as modified in its table. | |
PackedLevel * | PreloadLevel (Util::String const &path) |
preload a level that can be instantiated | |
void | UnloadLevel (PackedLevel *level) |
unload a preloaded level | |
void | ExportLevel (Util::String const &path) |
Export the world as a level. | |
Entity | AllocateEntityId () |
Allocate an entity id. Use this with caution! | |
void | DeallocateEntityId (Entity entity) |
Deallocate an entity id. Use this with caution! | |
MemDb::RowId | AllocateInstance (Entity entity, MemDb::TableId table, Util::Blob const *const data=nullptr) |
Allocate an entity instance in a table. Use this with caution! | |
MemDb::RowId | AllocateInstance (Entity entity, BlueprintId blueprint) |
Allocate an entity instance from a blueprint. Use this with caution! | |
MemDb::RowId | AllocateInstance (Entity entity, TemplateId templateId, bool performInitialize) |
Allocate an entity instance from a template. Use this with caution! | |
void | FinalizeAllocate (Entity entity) |
void | DeallocateInstance (MemDb::TableId table, MemDb::RowId instance) |
Deallocate an entity instance. Use this with caution! | |
void | DeallocateInstance (Entity entity) |
Deallocate an entity instance. Use this with caution! | |
void | Defragment (MemDb::TableId tableId) |
Defragment an entity table. | |
void * | GetInstanceBuffer (MemDb::TableId const tableId, uint16_t partitionId, ComponentId const component) |
Get a pointer to the first instance of a component in a partition of an entity table. Use with caution! | |
void * | GetColumnData (MemDb::TableId const tableId, uint16_t partitionId, MemDb::ColumnIndex const column) |
Get a pointer to the first instance of a column in a partition of an entity table. Use with caution! | |
void | ExecuteAddComponentCommands () |
dispatches all staged components to be added to entities | |
void | RenderDebug () |
template<> | |
Game::Position | GetComponent (Entity entity) |
template<> | |
Game::Orientation | GetComponent (Entity entity) |
template<> | |
Game::Scale | GetComponent (Entity entity) |
template<> | |
void | SetComponent (Entity entity, Game::Position const &value) |
template<> | |
void | SetComponent (Entity entity, Game::Orientation const &value) |
template<> | |
void | SetComponent (Entity entity, Game::Scale const &value) |
template<> | |
Game::Position | GetComponent (Entity entity) |
template<> | |
Game::Orientation | GetComponent (Entity entity) |
template<> | |
Game::Scale | GetComponent (Entity entity) |
template<> | |
void | SetComponent (Entity entity, Game::Position const &) |
template<> | |
void | SetComponent (Entity entity, Game::Orientation const &) |
template<> | |
void | SetComponent (Entity entity, Game::Scale const &) |
Static Public Member Functions | |
static void | Override (World *src, World *dst) |
copies and overrides dst with src. This is extremely destructive - make sure you understand the implications! | |
Public Attributes | |
bool | componentInitializationEnabled = true |
Disable if initialization of components is not required (ex. when running as editor db) | |
Private Member Functions | |
void | Start () |
void | BeginFrame () |
void | SimFrame () |
void | EndFrame () |
void | OnLoad () |
void | OnSave () |
void | ManageEntities () |
void | Reset () |
void | PrefilterProcessors () |
bool | Prefiltered () const |
Check if the database is fully prefiltered. | |
void | ClearDecayBuffers () |
Clears all decay buffers. This is called by the game server automatically. | |
void | ExecuteRemoveComponentCommands () |
void | AddStagedComponentsToEntity (Entity entity, AddStagedComponentCommand *cmds, SizeT numCmds) |
void | RemoveComponentsFromEntity (Entity entity, RemoveComponentCommand *cmds, SizeT numCmds) |
SizeT | GetNumInstances (MemDb::TableId tid) |
Get total number of instances in an entity table. | |
MemDb::RowId | Migrate (Entity entity, MemDb::TableId newTable) |
void | Migrate (Util::Array< Entity > const &entities, MemDb::TableId fromTable, MemDb::TableId newTable, Util::FixedArray< MemDb::RowId > &newInstances) |
void | DecayComponent (ComponentId component, MemDb::TableId tableId, MemDb::ColumnIndex column, MemDb::RowId instance) |
void | MoveInstance (MemDb::Table::Partition *partition, MemDb::RowId from, MemDb::RowId to) |
void | InitializeAllComponents (Entity entity, MemDb::TableId tableId, MemDb::RowId row) |
Run OnInit on all components. Use with caution, since they can only be initialized once and the function doesn't check for this. | |
Private Attributes | |
EntityPool | pool |
used to allocate entity ids for this world | |
SizeT | numEntities |
Number of entities alive. | |
Util::Array< EntityMapping > | entityMap |
maps entity index to table+row pair | |
Ptr< MemDb::Database > | db |
contains all entity instances | |
WorldHash | hash |
world hash | |
WorldId | worldId |
world id | |
Util::HashTable< BlueprintId, MemDb::TableId > | blueprintToTableMap |
maps from blueprint to a table that has the same signature | |
Util::Queue< AllocateInstanceCommand > | allocQueue |
Util::Queue< DeallocInstanceCommand > | deallocQueue |
Util::Array< AddStagedComponentCommand > | addStagedQueue |
Util::Array< RemoveComponentCommand > | removeComponentQueue |
Memory::ArenaAllocator< 4096_KB > | componentStageAllocator |
allocator for staged components | |
bool | cacheValid = false |
set to true if the caches for the frame pipeline is valid | |
FramePipeline | pipeline |
the frame pipeline for this world | |
MemDb::TableId | defaultTableId |
Friends | |
class | GameServer |
class | BlueprintManager |
class | PackedLevel |
Game::World::~World | ( | ) |
|
inline |
Create a component. This queues the component in a command buffer to be added later.
void * Game::World::AddComponent | ( | Entity | entity, |
Game::ComponentId | id ) |
Add a component to an entity. This queues the component in a command buffer to be added later.
|
private |
Entity Game::World::AllocateEntityId | ( | ) |
Allocate an entity id. Use this with caution!
MemDb::RowId Game::World::AllocateInstance | ( | Entity | entity, |
BlueprintId | blueprint ) |
Allocate an entity instance from a blueprint. Use this with caution!
MemDb::RowId Game::World::AllocateInstance | ( | Entity | entity, |
MemDb::TableId | table, | ||
Util::Blob const *const | data = nullptr ) |
Allocate an entity instance in a table. Use this with caution!
MemDb::RowId Game::World::AllocateInstance | ( | Entity | entity, |
TemplateId | templateId, | ||
bool | performInitialize ) |
Allocate an entity instance from a template. Use this with caution!
|
private |
|
private |
Clears all decay buffers. This is called by the game server automatically.
Game::Entity Game::World::CreateEntity | ( | bool | immediate = true | ) |
Create a new empty entity.
Game::Entity Game::World::CreateEntity | ( | EntityCreateInfo const & | info | ) |
Create a new entity from create info.
MemDb::TableId Game::World::CreateEntityTable | ( | EntityTableCreateInfo const & | info | ) |
Create a table in the entity database that has a specific set of components.
void Game::World::DeallocateEntityId | ( | Entity | entity | ) |
Deallocate an entity id. Use this with caution!
void Game::World::DeallocateInstance | ( | Entity | entity | ) |
Deallocate an entity instance. Use this with caution!
void Game::World::DeallocateInstance | ( | MemDb::TableId | table, |
MemDb::RowId | instance ) |
Deallocate an entity instance. Use this with caution!
|
private |
void Game::World::Defragment | ( | MemDb::TableId | tableId | ) |
Defragment an entity table.
void Game::World::DeleteEntity | ( | Game::Entity | entity | ) |
Delete entity.
|
private |
void Game::World::ExecuteAddComponentCommands | ( | ) |
dispatches all staged components to be added to entities
|
private |
void Game::World::ExportLevel | ( | Util::String const & | path | ) |
Export the world as a level.
void Game::World::FinalizeAllocate | ( | Entity | entity | ) |
void * Game::World::GetColumnData | ( | MemDb::TableId const | tableId, |
uint16_t | partitionId, | ||
MemDb::ColumnIndex const | column ) |
Get a pointer to the first instance of a column in a partition of an entity table. Use with caution!
Game::Position Game::World::GetComponent | ( | Entity | entity | ) |
Game::Orientation Game::World::GetComponent | ( | Entity | entity | ) |
Game::Scale Game::World::GetComponent | ( | Entity | entity | ) |
|
inline |
Get an entitys component.
Game::Position Game::World::GetComponent | ( | Entity | entity | ) |
Game::Orientation Game::World::GetComponent | ( | Entity | entity | ) |
Game::Scale Game::World::GetComponent | ( | Entity | entity | ) |
Ptr< MemDb::Database > Game::World::GetDatabase | ( | ) |
Get the entity database. Be careful when directly modifying the database, as some information is only kept track of via the World.
ComponentDecayBuffer const Game::World::GetDecayBuffer | ( | Game::ComponentId | component | ) |
Get a decay buffer for the given component.
EntityMapping Game::World::GetEntityMapping | ( | Game::Entity | entity | ) |
Returns the entity mapping of an entity.
FramePipeline & Game::World::GetFramePipeline | ( | ) |
Get the frame pipeline.
MemDb::RowId Game::World::GetInstance | ( | Entity | entity | ) |
Get instance of entity.
void * Game::World::GetInstanceBuffer | ( | MemDb::TableId const | tableId, |
uint16_t | partitionId, | ||
ComponentId const | component ) |
Get a pointer to the first instance of a component in a partition of an entity table. Use with caution!
|
private |
Get total number of instances in an entity table.
|
inline |
|
inline |
|
inline |
Check if entity has a specific component.
bool Game::World::HasComponent | ( | Entity | entity, |
ComponentId | component ) |
Check if entity has a specific component. (SLOW!)
TODO: This is not thread safe!
bool Game::World::HasInstance | ( | Entity | entity | ) |
Check if an entity has an instance. It might be valid, but not have received an instance just after it has been created.
|
private |
Run OnInit on all components. Use with caution, since they can only be initialized once and the function doesn't check for this.
bool Game::World::IsValid | ( | Entity | entity | ) |
Check if an entity ID is still valid.
|
private |
void Game::World::MarkAsModified | ( | Game::Entity | entity | ) |
Mark an entity as modified in its table.
|
private |
|
private |
newInstances | Will be filled with the new instance ids in the destination table. |
|
private |
|
private |
|
private |
copies and overrides dst with src. This is extremely destructive - make sure you understand the implications!
|
private |
Check if the database is fully prefiltered.
|
private |
PackedLevel * Game::World::PreloadLevel | ( | Util::String const & | path | ) |
preload a level that can be instantiated
Query the entity database using specified filter set. This does NOT wait for resources to be available.
Dataset Game::World::Query | ( | Filter | filter, |
Util::Array< MemDb::TableId > & | tids ) |
Query a subset of tables using a specified filter set.
Modifies the tables array so that it only contains valid tables. This does NOT wait for resources to be available.
void Game::World::ReinitializeComponent | ( | Game::Entity | entity, |
Game::ComponentId | component, | ||
void * | value, | ||
uint64_t | size ) |
Set the value of a component by providing a pointer and type size, then reinitialize the component.
|
inline |
Remove a component from an entity.
void Game::World::RemoveComponent | ( | Entity | entity, |
ComponentId | component ) |
Remove a component from an entity.
|
private |
void Game::World::RenderDebug | ( | ) |
|
private |
void Game::World::SetComponent | ( | Entity | entity, |
Game::Orientation const & | ) |
void Game::World::SetComponent | ( | Entity | entity, |
Game::Orientation const & | value ) |
void Game::World::SetComponent | ( | Entity | entity, |
Game::Position const & | ) |
void Game::World::SetComponent | ( | Entity | entity, |
Game::Position const & | value ) |
void Game::World::SetComponent | ( | Entity | entity, |
Game::Scale const & | ) |
void Game::World::SetComponent | ( | Entity | entity, |
Game::Scale const & | value ) |
|
inline |
Set the value of an entitys component.
void Game::World::SetComponentValue | ( | Game::Entity | entity, |
Game::ComponentId | component, | ||
void * | value, | ||
uint64_t | size ) |
Set the value of a component by providing a pointer and type size.
|
private |
|
private |
void Game::World::UnloadLevel | ( | PackedLevel * | level | ) |
unload a preloaded level
|
friend |
|
friend |
|
friend |
|
private |
|
private |
|
private |
maps from blueprint to a table that has the same signature
|
private |
set to true if the caches for the frame pipeline is valid
bool Game::World::componentInitializationEnabled = true |
Disable if initialization of components is not required (ex. when running as editor db)
|
private |
allocator for staged components
|
private |
contains all entity instances
|
private |
|
private |
|
private |
maps entity index to table+row pair
|
private |
world hash
|
private |
Number of entities alive.
|
private |
the frame pipeline for this world
|
private |
used to allocate entity ids for this world
|
private |
|
private |
world id