supertux
Classes | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members
GameObjectManager Class Referenceabstract

This class provides basic controlling functions for a sector. More...

#include <game_object_manager.hpp>

Inheritance diagram for GameObjectManager:
Inheritance graph
[legend]
Collaboration diagram for GameObjectManager:
Collaboration graph
[legend]

Public Member Functions

 GameObjectManager (bool undo_tracking=false)
 
virtual std::string get_exposed_class_name () const override
 
GameObjectadd_object (std::unique_ptr< GameObject > object)
 Queue an object up to be added to the object list.
 
void clear_objects ()
 
template<typename T , typename... Args>
T & add (Args &&... args)
 
void update (float dt_sec)
 
void draw (DrawingContext &context)
 
const std::vector< std::unique_ptr< GameObject > > & get_objects () const
 
void flush_game_objects ()
 Commit the queued up additions and deletions to the object list.
 
void set_ambient_light (float red, float green, float blue)
 Sets the sector's ambient light to the specified color. More...
 
void fade_to_ambient_light (float red, float green, float blue, float fadetime)
 Fades to a specified ambient light color in ""fadetime"" seconds. More...
 
float get_ambient_red () const
 Returns the red channel of the ambient light color.
 
float get_ambient_green () const
 Returns the green channel of the ambient light color.
 
float get_ambient_blue () const
 Returns the blue channel of the ambient light color.
 
void set_music (const std::string &music)
 Sets the sector's music. More...
 
void add_object (const std::string &class_name, const std::string &name, float pos_x, float pos_y, const std::string &direction, const std::string &data)
 Adds a ""MovingObject"" to the manager. More...
 
float get_width () const
 
float get_height () const
 
float get_editor_width () const
 
float get_editor_height () const
 
float get_tiles_width () const
 returns the width (in tiles) of a worldmap
 
float get_tiles_height () const
 returns the height (in tiles) of a worldmap
 
virtual bool before_object_add (GameObject &object)=0
 Hook that is called before an object is added to the vector.
 
virtual void before_object_remove (GameObject &object)=0
 Hook that is called before an object is removed from the vector.
 
template<class T >
GameObjectRange< T > get_objects_by_type () const
 
const std::vector< GameObject * > & get_objects_by_type_index (std::type_index type_idx) const
 
template<class T >
T & get_singleton_by_type () const
 
template<class T >
T * get_object_by_uid (const UID &uid) const
 
void move_object (const UID &uid, GameObjectManager &other)
 Move an object to another GameObjectManager. More...
 
void request_name_resolve (const std::string &name, std::function< void(UID)> callback)
 Register a callback to be called once the given name can be resolved to a UID. More...
 
template<class T >
T * get_object_by_name (const std::string &name) const
 
template<class T >
int get_object_count (std::function< bool(const T &)> predicate=nullptr) const
 Get total number of GameObjects of given type.
 
const std::vector< TileMap * > & get_solid_tilemaps () const
 
const std::vector< TileMap * > & get_all_tilemaps () const
 
void update_solid (TileMap *solid)
 
void toggle_undo_tracking (bool enabled)
 Toggle object change tracking for undo/redo. More...
 
bool undo_tracking_enabled () const
 
void set_undo_stack_size (int size)
 Set undo stack size. More...
 
void undo_stack_cleanup ()
 Remove old object changes that exceed the undo stack size limit. More...
 
void undo ()
 Undo/redo changes to GameObjects in the manager. More...
 
void redo ()
 
void save_object_change (GameObject &object, const std::string &data)
 Save object change in the undo stack with given data. More...
 
void clear_undo_stack ()
 Clear undo/redo stacks. More...
 
bool has_object_changes () const
 Indicate if there are any object changes in the undo stack. More...
 
void on_editor_save ()
 Called on editor level save. More...
 

Static Public Member Functions

static void register_class (ssq::VM &vm)
 

Static Public Attributes

static bool s_draw_solids_only = false
 

Protected Member Functions

virtual MovingObjectadd_object_scripting (const std::string &class_name, const std::string &name, const Vector &pos, const std::string &direction, const std::string &data)
 Add a MovingObject from scripting. More...
 
void update_tilemaps ()
 
void process_resolve_requests ()
 
void try_process_resolve_requests ()
 Same as process_resolve_requests(), but those it can't find will be kept in the buffer.
 
template<class T >
T * get_object_by_type () const
 

Protected Attributes

bool m_initialized
 An initial flush_game_objects() call has been initiated. More...
 

Detailed Description

This class provides basic controlling functions for a sector.

Applies for both worldmap and in-level sectors. For in-level sectors, an instance under ""sector.settings"" is available from scripts and the console.${SRG_NEWPARAGRAPH} For worldmap sectors, such instance is available under ""worldmap.settings"".

Member Function Documentation

◆ add_object()

void GameObjectManager::add_object ( const std::string &  class_name,
const std::string &  name,
float  pos_x,
float  pos_y,
const std::string &  direction,
const std::string &  data 
)

Adds a ""MovingObject"" to the manager.

Note: If adding objects to a worldmap sector, ""posX"" and ""posY"" have to be tile positions (sector position / 32).

Parameters
string$class_nameGameObject's class.
string$nameName of the created object.
float$pos_xX position inside the current sector.
float$pos_yY position inside the current sector.
string$directionDirection.
string$dataAdditional data in S-Expression format (check object definitions in level files).

◆ add_object_scripting()

MovingObject & GameObjectManager::add_object_scripting ( const std::string &  class_name,
const std::string &  name,
const Vector &  pos,
const std::string &  direction,
const std::string &  data 
)
protectedvirtual

Add a MovingObject from scripting.

Reimplemented in worldmap::WorldMapSector.

◆ clear_undo_stack()

void GameObjectManager::clear_undo_stack ( )

Clear undo/redo stacks.

◆ fade_to_ambient_light()

void GameObjectManager::fade_to_ambient_light ( float  red,
float  green,
float  blue,
float  fadetime 
)

Fades to a specified ambient light color in ""fadetime"" seconds.

Parameters
float$red
float$green
float$blue
float$fadetime

◆ has_object_changes()

bool GameObjectManager::has_object_changes ( ) const

Indicate if there are any object changes in the undo stack.

◆ move_object()

void GameObjectManager::move_object ( const UID uid,
GameObjectManager other 
)

Move an object to another GameObjectManager.

◆ on_editor_save()

void GameObjectManager::on_editor_save ( )

Called on editor level save.

◆ request_name_resolve()

void GameObjectManager::request_name_resolve ( const std::string &  name,
std::function< void(UID)>  callback 
)

Register a callback to be called once the given name can be resolved to a UID.

Note that this function is only valid in the construction phase, not during draw() or update() calls, use get_object_by_uid() instead.

◆ save_object_change()

void GameObjectManager::save_object_change ( GameObject object,
const std::string &  data 
)

Save object change in the undo stack with given data.

Used to save an object's previous state before a change had occurred.

◆ set_ambient_light()

void GameObjectManager::set_ambient_light ( float  red,
float  green,
float  blue 
)

Sets the sector's ambient light to the specified color.

Parameters
float$red
float$green
float$blue

◆ set_music()

void GameObjectManager::set_music ( const std::string &  music)

Sets the sector's music.

Parameters
string$musicFull filename, relative to the "music" folder.

◆ set_undo_stack_size()

void GameObjectManager::set_undo_stack_size ( int  size)

Set undo stack size.

◆ toggle_undo_tracking()

void GameObjectManager::toggle_undo_tracking ( bool  enabled)

Toggle object change tracking for undo/redo.

◆ undo()

void GameObjectManager::undo ( )

Undo/redo changes to GameObjects in the manager.

Utilized by the Editor.

◆ undo_stack_cleanup()

void GameObjectManager::undo_stack_cleanup ( )

Remove old object changes that exceed the undo stack size limit.

Member Data Documentation

◆ m_initialized

bool GameObjectManager::m_initialized
protected

An initial flush_game_objects() call has been initiated.


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