NWengine 0.9
Loading...
Searching...
No Matches
Scene Class Reference

Represents a scene in the game. More...

#include <Scene.h>

Public Member Functions

GameObjectAddObject ()
 Adds a new empty GameObject to the scene objects container.
 
void DeleteObject (uint32 index)
 Deletes a GameObject from the scene objects container by index.
 
void DeleteObject (std::string name)
 Deletes a GameObject from the scene objects container by name.
 
std::list< GameObject >::iterator DeleteObject (std::list< GameObject >::iterator it)
 Deletes a GameObject from the scene objects container by iterator.
 
void DeleteCurrentObj ()
 This function is intended to be called within object (to-delete) component (like scripts), as DeleteObject() will produce invalidation internally.
 
GameObjectGetGameObject (std::string name)
 Gets a GameObject in the scene by name.
 
GameObjectGetGameObject (const uint32 &position)
 Gets a GameObject in the scene by position.
 
GameObjectGetGameObject ()
 Gets the last object added to the scene.
 
void SortScene ()
 Deprecated. Sorts the scene objects container. This method is no longer used as objects are kept sorted at each insertion.
 
void Render (Sprite *sprite)
 Adds a sprite to the draw list.
 
void ForceRenderStop ()
 Iterates over the draw list and deletes sprites that are not rendered. If a sprite is not rendered, it will be deleted. Otherwise, the action is taken only at the next scene draw.
 
void Rearrange (Sprite *sprite)
 Refinds a position to insert a sprite in the draw list. This method is called internally when the layer of a sprite changes.
 
const std::string & Rename (const std::string &newName, GameObject *obj)
 Renames a GameObject. This method is mostly used internally and can be used by the user to change the name of an object.
 
 Scene (const std::string &path)
 Constructs a Scene object with the given path.
 
 ~Scene ()
 Destroys the Scene object.
 
void LoadScene ()
 Loads the scene from the file with the same name as the path.
 
void MakeCurrent ()
 Sets the scene as the current scene. The current scene will be updated and drawn during the engine update.
 
bool IsCurrent ()
 Checks if the scene is the current scene.
 
void Start ()
 Initializes the scene. This method should be called once before the update.
 
void Update ()
 Updates the scene. This method should be called every frame. It is called within the default NWengine update.
 
void SetUp ()
 Sets up the needed static variables and other things.
 
void Draw ()
 Draws all the scene objects. This method is called within the default NWengine update.
 
void Save ()
 Serializes the scene and saves it in a file with the same name.
 
void SetPath (const std::string &path)
 Sets the path of the scene. This method changes the "name" member to the given path.
 

Static Public Member Functions

static SceneCreateNew (const std::string &path)
 Creates a new scene and pushes it to a container.
 
static SceneGetScene (const std::string &path)
 Gets a scene by its path. If multiple scenes have the same path, it returns one of them; order or determinism is not guaranteed.
 
static bool DeleteScene (const std::string &path)
 Deletes a scene by its path.
 
static void Destroy ()
 Destroys the current scene.
 
static void UpdateActiveScene ()
 Updates the active scene.
 
static SceneGetCurrent ()
 Gets the current scene.
 

Public Attributes

bool _shouldDelObj = 0
 
std::string name
 
std::list< GameObjectsceneObjs
 
std::list< Sprite * > drawList
 

Static Public Attributes

static std::list< Scene_scenes
 
static ScenecurrentScene = nullptr
 

Detailed Description

Represents a scene in the game.

Constructor & Destructor Documentation

◆ Scene()

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

Constructs a Scene object with the given path.

Parameters
pathThe path of the scene file.

Member Function Documentation

◆ AddObject()

GameObject &const Scene::AddObject ( )

Adds a new empty GameObject to the scene objects container.

Returns
The reference to the newly added GameObject.

◆ CreateNew()

Scene & Scene::CreateNew ( const std::string & path)
static

Creates a new scene and pushes it to a container.

Parameters
pathThe path of the new scene.
Returns
The reference to the newly created scene.

◆ DeleteObject() [1/3]

std::list< GameObject >::iterator Scene::DeleteObject ( std::list< GameObject >::iterator it)

Deletes a GameObject from the scene objects container by iterator.

Parameters
itThe iterator of the object to delete.
Returns
Return value of std::list::erase()

◆ DeleteObject() [2/3]

void Scene::DeleteObject ( std::string name)

Deletes a GameObject from the scene objects container by name.

Parameters
nameThe name of the GameObject to delete.

◆ DeleteObject() [3/3]

void Scene::DeleteObject ( uint32 index)

Deletes a GameObject from the scene objects container by index.

Parameters
indexThe index of the GameObject to delete.

◆ DeleteScene()

bool Scene::DeleteScene ( const std::string & path)
static

Deletes a scene by its path.

Parameters
pathThe path of the scene to delete.
Returns
True if the scene is found and deleted, false otherwise.

◆ GetCurrent()

Scene * Scene::GetCurrent ( )
static

Gets the current scene.

Returns
A pointer to the current scene if available, nullptr otherwise.

◆ GetGameObject() [1/3]

GameObject * Scene::GetGameObject ( )

Gets the last object added to the scene.

Returns
A pointer to the last GameObject added to the scene if available, nullptr otherwise.

◆ GetGameObject() [2/3]

GameObject * Scene::GetGameObject ( const uint32 & position)

Gets a GameObject in the scene by position.

Parameters
positionThe position of the GameObject to get.
Returns
A pointer to the GameObject if found, nullptr otherwise.

◆ GetGameObject() [3/3]

GameObject * Scene::GetGameObject ( std::string name)

Gets a GameObject in the scene by name.

Parameters
nameThe name of the GameObject to get.
Returns
A pointer to the GameObject if found, nullptr otherwise.

◆ GetScene()

Scene * Scene::GetScene ( const std::string & path)
static

Gets a scene by its path. If multiple scenes have the same path, it returns one of them; order or determinism is not guaranteed.

Parameters
pathThe path of the scene.
Returns
A pointer to the scene if found, nullptr otherwise.

◆ IsCurrent()

bool Scene::IsCurrent ( )

Checks if the scene is the current scene.

Returns
True if the scene is the current scene, false otherwise.

◆ Rearrange()

void Scene::Rearrange ( Sprite * sprite)

Refinds a position to insert a sprite in the draw list. This method is called internally when the layer of a sprite changes.

Parameters
spriteThe sprite to rearrange.

◆ Rename()

const std::string & Scene::Rename ( const std::string & newName,
GameObject * obj )

Renames a GameObject. This method is mostly used internally and can be used by the user to change the name of an object.

Parameters
newNameThe new name for the GameObject.
objThe GameObject to rename.
Returns
The new name of the GameObject.

◆ Render()

void Scene::Render ( Sprite * sprite)

Adds a sprite to the draw list.

Parameters
spriteThe sprite to add.

◆ SetPath()

void Scene::SetPath ( const std::string & path)

Sets the path of the scene. This method changes the "name" member to the given path.

Parameters
pathThe new path for the scene.

Member Data Documentation

◆ _scenes

std::list< Scene > Scene::_scenes
static

The list of all scenes.

◆ _shouldDelObj

bool Scene::_shouldDelObj = 0

Internal flag that holds if currently iterated on gameobject during update should be deleted. see DestroyCurrentObj() for details

◆ currentScene

Scene * Scene::currentScene = nullptr
static

The pointer to the current scene.

◆ drawList

std::list<Sprite*> Scene::drawList

The list of sprites to be drawn in the scene.

◆ name

std::string Scene::name

The name of the scene.

◆ sceneObjs

std::list<GameObject> Scene::sceneObjs

The list of game objects in the scene.


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