Loading...
Searching...
No Matches
hellfire::Scene Class Reference

Manages a collection of entities and their hierarchical relationships. More...

#include <Scene.h>

Collaboration diagram for hellfire::Scene:

Public Member Functions

 Scene (std::string name="Unnamed")
 Constructs a new Scene with an optional name.
 
virtual ~Scene ()
 Destructor.
 
EntityID create_entity (const std::string &name="GameObject")
 Creates a new entity in the scene.
 
void destroy_entity (EntityID id)
 Destroys an entity and removes it from the scene.
 
Entityget_entity (EntityID id)
 Retrieves an entity by its ID.
 
const Entityget_entity (EntityID id) const
 Retrieves an entity by its ID (const version)
 
bool is_descendant (EntityID potential_descendant, EntityID potential_ancestor)
 Checks if one entity is a descendant of another.
 
void set_parent (EntityID child_id, EntityID parent_id)
 Sets the parent of an entity.
 
void set_as_root (EntityID entity_id)
 Makes an entity a root entity (removes parent)
 
EntityID get_parent (EntityID entity_id) const
 Gets the parent ID of an entity.
 
bool has_parent (EntityID entity_id) const
 Checks if an entity has a parent.
 
std::vector< EntityIDget_children (EntityID parent_id) const
 Gets all children of a parent entity.
 
const std::vector< EntityID > & get_root_entities () const
 Gets all root entities in the scene.
 
virtual void initialize ()
 Initializes the scene Called once when the scene is first loaded or created.
 
virtual void update (float delta_time)
 Updates all entities in the scene.
 
void update_world_matrices ()
 Updates world transformation matrices for all entities Propagates transformations through the entity hierarchy.
 
Entityfind_entity_by_name (const std::string &name)
 Finds an entity by its name.
 
template<typename T >
std::vector< EntityIDfind_entities_with_component ()
 Finds all entities that have a specific component type.
 
void set_default_camera (EntityID camera_id)
 Sets the default camera for the scene.
 
EntityID get_default_camera_entity_id () const
 
CameraComponentget_default_camera () const
 
std::vector< EntityIDget_camera_entities () const
 
size_t get_entity_count () const
 
const std::string & get_name () const
 
void set_name (const std::string &name)
 
bool is_playing () const
 
void set_playing (bool active)
 
void set_source_filename (const std::filesystem::path &filename)
 
const std::filesystem::path & get_source_filename () const
 
bool was_loaded_from_file () const
 
std::string generate_unique_name (const std::string &base_name)
 
void save ()
 
SceneEnvironmentenvironment () const
 
std::unordered_map< EntityID, std::unique_ptr< Entity > > & get_all_entities ()
 

Private Member Functions

void update_hierarchy (EntityID entity_id, float delta_time)
 
void update_world_matrices_recursive (unsigned int entity_id, const glm::mat4 &parent_world)
 
void find_entities_recursive (EntityID entity_id, const std::function< bool(Entity *)> &predicate, std::vector< EntityID > &results)
 

Private Attributes

std::unordered_map< EntityID, std::unique_ptr< Entity > > entities_
 
std::unordered_map< EntityID, EntityIDparent_map_
 
std::unordered_map< EntityID, std::vector< EntityID > > children_map_
 
std::vector< EntityIDroot_entities_
 
EntityID next_id_ = 1
 
EntityID default_camera_entity_id_ = 0
 
std::string name_
 
bool is_playing_
 
std::filesystem::path source_filename_
 
std::unordered_map< std::string, int > name_counters_
 
std::unique_ptr< SceneEnvironmentenvironment_
 

Detailed Description

Manages a collection of entities and their hierarchical relationships.

The Scene class represents a complete game scene containing entities, their parent-child relationships, cameras, and environmental settings. It handles entity lifecycle, hierarchy management, and scene updates.

Definition at line 24 of file Scene.h.

Constructor & Destructor Documentation

◆ Scene()

hellfire::Scene::Scene ( std::string  name = "Unnamed")

Constructs a new Scene with an optional name.

Parameters
nameThe name of the scene (default: "Unnamed")

Definition at line 9 of file Scene.cpp.

◆ ~Scene()

hellfire::Scene::~Scene ( )
virtual

Destructor.

Definition at line 25 of file Scene.cpp.

Member Function Documentation

◆ create_entity()

EntityID hellfire::Scene::create_entity ( const std::string &  name = "GameObject")

Creates a new entity in the scene.

Parameters
nameThe name for the new entity (default: "GameObject")
Returns
The unique ID of the newly created entity

Definition at line 29 of file Scene.cpp.

◆ destroy_entity()

void hellfire::Scene::destroy_entity ( EntityID  id)

Destroys an entity and removes it from the scene.

Parameters
idThe ID of the entity to destroy

Definition at line 46 of file Scene.cpp.

◆ environment()

SceneEnvironment * hellfire::Scene::environment ( ) const
inline

Definition at line 181 of file Scene.h.

◆ find_entities_recursive()

void hellfire::Scene::find_entities_recursive ( EntityID  entity_id,
const std::function< bool(Entity *)> &  predicate,
std::vector< EntityID > &  results 
)
private

Definition at line 282 of file Scene.cpp.

◆ find_entities_with_component()

template<typename T >
std::vector< EntityID > hellfire::Scene::find_entities_with_component ( )

Finds all entities that have a specific component type.

Template Parameters
TThe component type to search for
Returns
Vector of entity IDs that have specified component

Definition at line 214 of file Scene.h.

◆ find_entity_by_name()

Entity * hellfire::Scene::find_entity_by_name ( const std::string &  name)

Finds an entity by its name.

Parameters
nameThe name of the entity to find
Returns
Pointer to the entity, or nullptr if not found

Definition at line 174 of file Scene.cpp.

◆ generate_unique_name()

std::string hellfire::Scene::generate_unique_name ( const std::string &  base_name)

Definition at line 207 of file Scene.cpp.

◆ get_all_entities()

std::unordered_map< EntityID, std::unique_ptr< Entity > > & hellfire::Scene::get_all_entities ( )
inline

Definition at line 183 of file Scene.h.

◆ get_camera_entities()

std::vector< EntityID > hellfire::Scene::get_camera_entities ( ) const

Definition at line 195 of file Scene.cpp.

◆ get_children()

std::vector< EntityID > hellfire::Scene::get_children ( EntityID  parent_id) const

Gets all children of a parent entity.

Parameters
parent_idThe ID of the parent entity
Returns
Vector of child entity IDs

Definition at line 148 of file Scene.cpp.

◆ get_default_camera()

CameraComponent * hellfire::Scene::get_default_camera ( ) const

Definition at line 189 of file Scene.cpp.

◆ get_default_camera_entity_id()

EntityID hellfire::Scene::get_default_camera_entity_id ( ) const
inline

Definition at line 159 of file Scene.h.

◆ get_entity() [1/2]

Entity * hellfire::Scene::get_entity ( EntityID  id)

Retrieves an entity by its ID.

Parameters
idThe ID of the entity to retrieve
Returns
Pointer to the entity, or nullptr if not found

Definition at line 81 of file Scene.cpp.

◆ get_entity() [2/2]

const Entity * hellfire::Scene::get_entity ( EntityID  id) const

Retrieves an entity by its ID (const version)

Parameters
idThe ID of the entity to retrieve
Returns
Const pointer to the entity, or nullptr if not found

Definition at line 86 of file Scene.cpp.

◆ get_entity_count()

size_t hellfire::Scene::get_entity_count ( ) const
inline

Definition at line 165 of file Scene.h.

◆ get_name()

const std::string & hellfire::Scene::get_name ( ) const
inline

Definition at line 170 of file Scene.h.

◆ get_parent()

EntityID hellfire::Scene::get_parent ( EntityID  entity_id) const

Gets the parent ID of an entity.

Parameters
entity_idThe ID of the entity
Returns
The parent entity ID, or INVALID_ENTITY if no parent

Definition at line 138 of file Scene.cpp.

◆ get_root_entities()

const std::vector< EntityID > & hellfire::Scene::get_root_entities ( ) const
inline

Gets all root entities in the scene.

Returns
Reference to the vector of root entity IDs

Definition at line 112 of file Scene.h.

◆ get_source_filename()

const std::filesystem::path & hellfire::Scene::get_source_filename ( ) const
inline

Definition at line 175 of file Scene.h.

◆ has_parent()

bool hellfire::Scene::has_parent ( EntityID  entity_id) const

Checks if an entity has a parent.

Parameters
entity_idThe ID of the entity to check
Returns
True if the entity has a parent

Definition at line 143 of file Scene.cpp.

◆ initialize()

void hellfire::Scene::initialize ( )
virtual

Initializes the scene Called once when the scene is first loaded or created.

Definition at line 153 of file Scene.cpp.

◆ is_descendant()

bool hellfire::Scene::is_descendant ( EntityID  potential_descendant,
EntityID  potential_ancestor 
)

Checks if one entity is a descendant of another.

Parameters
potential_descendantThe ID of the potential descendant entity
potential_ancestorThe ID of the potential ancestor entity
Returns
True of potential_descendant is a descendant of potential_ancestor

Definition at line 91 of file Scene.cpp.

◆ is_playing()

bool hellfire::Scene::is_playing ( ) const
inline

Definition at line 172 of file Scene.h.

◆ save()

void hellfire::Scene::save ( )

Definition at line 244 of file Scene.cpp.

◆ set_as_root()

void hellfire::Scene::set_as_root ( EntityID  entity_id)

Makes an entity a root entity (removes parent)

Parameters
entity_idThe ID of the entity to make root

Definition at line 134 of file Scene.cpp.

◆ set_default_camera()

void hellfire::Scene::set_default_camera ( EntityID  camera_id)

Sets the default camera for the scene.

Parameters
camera_id

Definition at line 182 of file Scene.cpp.

◆ set_name()

void hellfire::Scene::set_name ( const std::string &  name)
inline

Definition at line 171 of file Scene.h.

◆ set_parent()

void hellfire::Scene::set_parent ( EntityID  child_id,
EntityID  parent_id 
)

Sets the parent of an entity.

Parameters
child_idThe ID of the child entity
parent_idThe ID of the parent entity

Definition at line 105 of file Scene.cpp.

◆ set_playing()

void hellfire::Scene::set_playing ( bool  active)
inline

Definition at line 173 of file Scene.h.

◆ set_source_filename()

void hellfire::Scene::set_source_filename ( const std::filesystem::path &  filename)
inline

Definition at line 174 of file Scene.h.

◆ update()

void hellfire::Scene::update ( float  delta_time)
virtual

Updates all entities in the scene.

Parameters
delta_timeTime elapsed since last update in seconds

Definition at line 161 of file Scene.cpp.

◆ update_hierarchy()

void hellfire::Scene::update_hierarchy ( EntityID  entity_id,
float  delta_time 
)
private

Definition at line 247 of file Scene.cpp.

◆ update_world_matrices()

void hellfire::Scene::update_world_matrices ( )

Updates world transformation matrices for all entities Propagates transformations through the entity hierarchy.

Definition at line 168 of file Scene.cpp.

◆ update_world_matrices_recursive()

void hellfire::Scene::update_world_matrices_recursive ( unsigned int  entity_id,
const glm::mat4 &  parent_world 
)
private

Definition at line 260 of file Scene.cpp.

◆ was_loaded_from_file()

bool hellfire::Scene::was_loaded_from_file ( ) const
inline

Definition at line 176 of file Scene.h.

Member Data Documentation

◆ children_map_

std::unordered_map<EntityID, std::vector<EntityID> > hellfire::Scene::children_map_
private

Definition at line 191 of file Scene.h.

◆ default_camera_entity_id_

EntityID hellfire::Scene::default_camera_entity_id_ = 0
private

Definition at line 196 of file Scene.h.

◆ entities_

std::unordered_map<EntityID, std::unique_ptr<Entity> > hellfire::Scene::entities_
private

Definition at line 187 of file Scene.h.

◆ environment_

std::unique_ptr<SceneEnvironment> hellfire::Scene::environment_
private

Definition at line 202 of file Scene.h.

◆ is_playing_

bool hellfire::Scene::is_playing_
private

Definition at line 198 of file Scene.h.

◆ name_

std::string hellfire::Scene::name_
private

Definition at line 197 of file Scene.h.

◆ name_counters_

std::unordered_map<std::string, int> hellfire::Scene::name_counters_
private

Definition at line 200 of file Scene.h.

◆ next_id_

EntityID hellfire::Scene::next_id_ = 1
private

Definition at line 195 of file Scene.h.

◆ parent_map_

std::unordered_map<EntityID, EntityID> hellfire::Scene::parent_map_
private

Definition at line 190 of file Scene.h.

◆ root_entities_

std::vector<EntityID> hellfire::Scene::root_entities_
private

Definition at line 192 of file Scene.h.

◆ source_filename_

std::filesystem::path hellfire::Scene::source_filename_
private

Definition at line 199 of file Scene.h.


The documentation for this class was generated from the following files: