2D_Game_Engine
Loading...
Searching...
No Matches
Public Member Functions | Friends | List of all members
Scene Class Reference

#include <scene.hpp>

Public Member Functions

 Scene ()
 
 Scene (const std::string &name)
 
std::string & GetName ()
 
void SetScalingFactor (float scaling_factor)
 
void SetGravity (float x, float y)
 
void SetGravity (Vec2 gravity)
 
uint32_t AddEntity ()
 
void AddEntity (uint32_t uid)
 
EntityGetEntity (uint32_t uid)
 
void RemoveEntity (uint32_t uid)
 
void MoveEntity (uint32_t uid, float x_offset, float y_offset)
 
void SetEntityPosition (uint32_t uid, float x, float y)
 
template<typename T , typename ... Args>
void AddComponent (uint32_t uid, Args...args)
 
template<typename T >
void RemoveComponent (uint32_t uid)
 
template<typename T >
T * GetComponent (uint32_t uid)
 
void OnPhysicsStart ()
 
void OnPhysicsUpdate (double frame_time)
 
void OnPhysicsStop ()
 
void Update (double frame_time)
 
void Render ()
 
std::vector< Entity > & GetEntities ()
 
template<typename T , ComponentType< T > = 0>
std::vector< T > & GetComponents ()
 
CameraGetCamera ()
 
b2WorldGetPhysicsWorld ()
 
void DebugDraw ()
 
template<>
TagComponentGetComponent (uint32_t uid)
 
template<>
TextureComponentGetComponent (uint32_t uid)
 
template<>
AnimatedTextureComponentGetComponent (uint32_t uid)
 
template<>
LightComponentGetComponent (uint32_t uid)
 
template<>
RigidbodyComponentGetComponent (uint32_t uid)
 
template<>
BoxColliderComponentGetComponent (uint32_t uid)
 
template<>
CircleColliderComponentGetComponent (uint32_t uid)
 
template<>
NativeScriptComponentGetComponent (uint32_t uid)
 
template<>
TextComponentGetComponent (uint32_t uid)
 
template<>
void RemoveComponent (uint32_t uid)
 
template<>
void RemoveComponent (uint32_t uid)
 
template<>
void RemoveComponent (uint32_t uid)
 
template<>
void RemoveComponent (uint32_t uid)
 
template<>
void RemoveComponent (uint32_t uid)
 
template<>
void RemoveComponent (uint32_t uid)
 
template<>
void RemoveComponent (uint32_t uid)
 
template<>
void RemoveComponent (uint32_t uid)
 
template<>
void RemoveComponent (uint32_t uid)
 
template<>
std::vector< TextureComponent > & GetComponents ()
 
template<>
std::vector< AnimatedTextureComponent > & GetComponents ()
 
template<>
std::vector< LightComponent > & GetComponents ()
 
template<>
std::vector< RigidbodyComponent > & GetComponents ()
 
template<>
std::vector< BoxColliderComponent > & GetComponents ()
 
template<>
std::vector< CircleColliderComponent > & GetComponents ()
 
template<>
std::vector< NativeScriptComponent > & GetComponents ()
 
template<>
std::vector< TextComponent > & GetComponents ()
 

Friends

class SceneSerializer
 
class Application
 

Detailed Description

Definition at line 6 of file scene.hpp.

Constructor & Destructor Documentation

◆ Scene() [1/2]

Scene::Scene ( )
inline

Calls OnPhysicsStart and sets the scene name to ""

Definition at line 11 of file scene.hpp.

◆ Scene() [2/2]

Scene::Scene ( const std::string & name)

Calls OnPhysicsStart

Parameters
namethe scene name

Definition at line 19 of file scene.cpp.

Member Function Documentation

◆ AddComponent()

template<typename T , typename ... Args>
void Scene::AddComponent ( uint32_t uid,
Args... args )
inline

Add a component to an entity

Parameters
uidthe entity uid
argsthe component constructor arguments

Definition at line 79 of file scene.hpp.

◆ AddEntity() [1/2]

uint32_t Scene::AddEntity ( )

Add an entity to the scene

Returns
the entity uid

Definition at line 42 of file scene.cpp.

◆ AddEntity() [2/2]

void Scene::AddEntity ( uint32_t uid)

Add an entity to the scene. Used when deserializing a scene.

Parameters
uidthe entity uid

Definition at line 47 of file scene.cpp.

◆ DebugDraw()

void Scene::DebugDraw ( )

Definition at line 381 of file scene.cpp.

◆ GetCamera()

Camera & Scene::GetCamera ( )
inline

Definition at line 190 of file scene.hpp.

◆ GetComponent() [1/10]

template<typename T >
T * Scene::GetComponent ( uint32_t uid)

Get a component from an entity

Parameters
uidthe entity uid
Returns
a pointer to the component or nullptr if the component does not exist

◆ GetComponent() [2/10]

template<>
TagComponent * Scene::GetComponent ( uint32_t uid)

Definition at line 80 of file scene.cpp.

◆ GetComponent() [3/10]

template<>
TextureComponent * Scene::GetComponent ( uint32_t uid)

Definition at line 87 of file scene.cpp.

◆ GetComponent() [4/10]

template<>
AnimatedTextureComponent * Scene::GetComponent ( uint32_t uid)

Definition at line 94 of file scene.cpp.

◆ GetComponent() [5/10]

template<>
LightComponent * Scene::GetComponent ( uint32_t uid)

Definition at line 101 of file scene.cpp.

◆ GetComponent() [6/10]

template<>
RigidbodyComponent * Scene::GetComponent ( uint32_t uid)

Definition at line 108 of file scene.cpp.

◆ GetComponent() [7/10]

template<>
BoxColliderComponent * Scene::GetComponent ( uint32_t uid)

Definition at line 115 of file scene.cpp.

◆ GetComponent() [8/10]

template<>
CircleColliderComponent * Scene::GetComponent ( uint32_t uid)

Definition at line 122 of file scene.cpp.

◆ GetComponent() [9/10]

template<>
NativeScriptComponent * Scene::GetComponent ( uint32_t uid)

Definition at line 129 of file scene.cpp.

◆ GetComponent() [10/10]

template<>
TextComponent * Scene::GetComponent ( uint32_t uid)

Definition at line 136 of file scene.cpp.

◆ GetComponents() [1/9]

template<typename T , ComponentType< T > = 0>
std::vector< T > & Scene::GetComponents ( )

Get the components vector

Returns
a reference to the components vector

◆ GetComponents() [2/9]

template<>
std::vector< TextComponent > & Scene::GetComponents ( )

Definition at line 337 of file scene.cpp.

◆ GetComponents() [3/9]

template<>
std::vector< LightComponent > & Scene::GetComponents ( )

Definition at line 337 of file scene.cpp.

◆ GetComponents() [4/9]

template<>
std::vector< NativeScriptComponent > & Scene::GetComponents ( )

Definition at line 337 of file scene.cpp.

◆ GetComponents() [5/9]

template<>
std::vector< CircleColliderComponent > & Scene::GetComponents ( )

Definition at line 337 of file scene.cpp.

◆ GetComponents() [6/9]

template<>
std::vector< BoxColliderComponent > & Scene::GetComponents ( )

Definition at line 337 of file scene.cpp.

◆ GetComponents() [7/9]

template<>
std::vector< RigidbodyComponent > & Scene::GetComponents ( )

Definition at line 337 of file scene.cpp.

◆ GetComponents() [8/9]

template<>
std::vector< TextureComponent > & Scene::GetComponents ( )

Definition at line 337 of file scene.cpp.

◆ GetComponents() [9/9]

template<>
std::vector< AnimatedTextureComponent > & Scene::GetComponents ( )

Definition at line 337 of file scene.cpp.

◆ GetEntities()

std::vector< Entity > & Scene::GetEntities ( )

Get the entities vector

Returns
a reference to the entities vector

Definition at line 337 of file scene.cpp.

◆ GetEntity()

Entity * Scene::GetEntity ( uint32_t uid)

Get an entity from the scene

Parameters
uidthe entity uid
Returns
a pointer to the entity or nullptr if the entity does not exist

Definition at line 51 of file scene.cpp.

◆ GetName()

std::string & Scene::GetName ( )

Definition at line 24 of file scene.cpp.

◆ GetPhysicsWorld()

b2World * Scene::GetPhysicsWorld ( )
inline

Definition at line 192 of file scene.hpp.

◆ MoveEntity()

void Scene::MoveEntity ( uint32_t uid,
float x_offset,
float y_offset )

Move the entity. The coordinates are expected in engine units (screen width = 10 units)

Definition at line 291 of file scene.cpp.

◆ OnPhysicsStart()

void Scene::OnPhysicsStart ( )

Starts the physics simulation

Definition at line 307 of file scene.cpp.

◆ OnPhysicsStop()

void Scene::OnPhysicsStop ( )

Stops the physics simulation

Definition at line 332 of file scene.cpp.

◆ OnPhysicsUpdate()

void Scene::OnPhysicsUpdate ( double frame_time)

Update the physics simulation

Parameters
frame_timethe frame time

Definition at line 311 of file scene.cpp.

◆ RemoveComponent() [1/10]

template<typename T >
void Scene::RemoveComponent ( uint32_t uid)

Remove a component from an entity

Parameters
uidthe entity uid

◆ RemoveComponent() [2/10]

template<>
void Scene::RemoveComponent ( uint32_t uid)

Definition at line 213 of file scene.cpp.

◆ RemoveComponent() [3/10]

template<>
void Scene::RemoveComponent ( uint32_t uid)

Definition at line 220 of file scene.cpp.

◆ RemoveComponent() [4/10]

template<>
void Scene::RemoveComponent ( uint32_t uid)

Definition at line 227 of file scene.cpp.

◆ RemoveComponent() [5/10]

template<>
void Scene::RemoveComponent ( uint32_t uid)

Definition at line 234 of file scene.cpp.

◆ RemoveComponent() [6/10]

template<>
void Scene::RemoveComponent ( uint32_t uid)

Definition at line 241 of file scene.cpp.

◆ RemoveComponent() [7/10]

template<>
void Scene::RemoveComponent ( uint32_t uid)

Definition at line 248 of file scene.cpp.

◆ RemoveComponent() [8/10]

template<>
void Scene::RemoveComponent ( uint32_t uid)

Definition at line 255 of file scene.cpp.

◆ RemoveComponent() [9/10]

template<>
void Scene::RemoveComponent ( uint32_t uid)

Definition at line 262 of file scene.cpp.

◆ RemoveComponent() [10/10]

template<>
void Scene::RemoveComponent ( uint32_t uid)

Definition at line 269 of file scene.cpp.

◆ RemoveEntity()

void Scene::RemoveEntity ( uint32_t uid)

Remove an entity from the scene

Parameters
uidthe entity uid

Definition at line 60 of file scene.cpp.

◆ Render()

void Scene::Render ( )

Render the scene

Definition at line 282 of file scene.cpp.

◆ SetEntityPosition()

void Scene::SetEntityPosition ( uint32_t uid,
float x,
float y )

Definition at line 142 of file scene.cpp.

◆ SetGravity() [1/2]

void Scene::SetGravity ( float x,
float y )

Set the gravity for the scene (m/s^2). Should be called after OnPhysicsStart(). Default value is (0,-0.3). Adjust the gravity according to the scaling factor.

Definition at line 32 of file scene.cpp.

◆ SetGravity() [2/2]

void Scene::SetGravity ( Vec2 gravity)

Set the gravity for the scene (m/s^2). Should be called after OnPhysicsStart(). Default value is (0,-0.3). Adjust the gravity according to the scaling factor.

Definition at line 37 of file scene.cpp.

◆ SetScalingFactor()

void Scene::SetScalingFactor ( float scaling_factor)

Set the scaling factor for the scene. Default value is 0.5 (1 meter = 0.5 units)

Definition at line 28 of file scene.cpp.

◆ Update()

void Scene::Update ( double frame_time)

Update the scene

Parameters
frame_timethe frame time

Definition at line 275 of file scene.cpp.

Friends And Related Symbol Documentation

◆ Application

Definition at line 197 of file scene.hpp.

◆ SceneSerializer

Definition at line 196 of file scene.hpp.


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