KTech 1.1.0
C++ 2D terminal game engine library
Loading...
Searching...
No Matches
KTech::Layer Class Reference

World structure that contains Objects, and exists within Map. More...

#include <layer.hpp>

Public Member Functions

 Layer (Engine &engine, std::string name="")
 Construct a Layer.
 
 Layer (Engine &engine, const ID< Map > &parentMap, std::string name="")
 Construct a Layer and immediately enter a Map.
 
virtual ~Layer ()
 Destruct a Layer.
 
auto operator[] (size_t index) -> ID< Object > &
 Retrieve Object ID at given index.
 
auto AddObject (const ID< Object > &object) -> bool
 Add an Object.
 
auto RemoveObject (const ID< Object > &object) -> bool
 Remove an Object.
 
auto RemoveAllObjects () -> bool
 Remove all contained Objects.
 
auto EnterMap (const ID< Map > &map) -> bool
 Enter a Map.
 
auto LeaveMap () -> bool
 Leave parent Map.
 

Public Attributes

Engineengine
 Parent Engine
 
const ID< Layerm_id {ID<Layer>::Unique()}
 Personal ID.
 
std::string m_name
 String anme; could be useful in debugging.
 
ID< Mapm_parentMap
 Parent Map.
 
std::vector< ID< Object > > m_objects
 Contained Objects.
 
bool m_visible = true
 true: will be rendered by Camera. false: won't be.
 
uint8_t m_alpha = std::numeric_limits<uint8_t>::max()
 Opacity used by Camera when rendering contained Objects.
 
RGBA m_frgba = RGBAColors::transparent
 Foreground color added by Camera after rendering contained Objects.
 
RGBA m_brgba = RGBAColors::transparent
 Background color added by Camera after rendering contained Objects.
 

Protected Member Functions

virtual auto OnTick () -> bool
 Virtual function called once each tick.
 

Friends

class KTech::Memory
 

Detailed Description

World structure that contains Objects, and exists within Map.

Separates Objects in collision (only Objects from the same Layer can collide), and orders Objects in rendering (Objects in the first Layer added to a Map will be covered by Objects from the following Layer, and so on).

Constructor & Destructor Documentation

◆ Layer() [1/2]

KTech::Layer::Layer ( Engine & engine,
std::string name = "" )

Construct a Layer.

Parameters
[in]engineParent Engine.
[in]nameString name.

◆ Layer() [2/2]

KTech::Layer::Layer ( Engine & engine,
const ID< Map > & parentMap,
std::string name = "" )

Construct a Layer and immediately enter a Map.

Parameters
[in]engineParent Engine.
[in]parentMapMap to enter.
[in]nameString name.

◆ ~Layer()

KTech::Layer::~Layer ( )
virtual

Destruct a Layer.

Removes all contained Objects, leaves parent Map (if in one), and removes itself from Memory.

Member Function Documentation

◆ AddObject()

auto KTech::Layer::AddObject ( const ID< Object > & object) -> bool

Add an Object.

Parameters
[in]objectThe Object to add.
Returns
true if added the Object. false if Object doesn't exist in Memory or already contained by Layer.

◆ EnterMap()

auto KTech::Layer::EnterMap ( const ID< Map > & map) -> bool

Enter a Map.

Parameters
[in]mapThe Map to enter.
Returns
true if entered Map. false if given Map doesn't exist in Memory or already the parent Map.

◆ LeaveMap()

auto KTech::Layer::LeaveMap ( ) -> bool

Leave parent Map.

Returns
true if left parent Map (Layer::m_parentMap). false if there's no parent Map, or the parent Map doesn't exist in Memory.

◆ OnTick()

auto KTech::Layer::OnTick ( ) -> bool
protectedvirtual

Virtual function called once each tick.

You can override this in your inherited class to add whatever functionality you want.

Called by Memory::CallOnTicks().

Returns
bool value, which is explained in Output::ShouldRenderThisTick().
See also
Memory::CallOnTicks()
Output::ShouldRenderThisTick()

◆ operator[]()

auto KTech::Layer::operator[] ( size_t index) -> ID<Object>&

Retrieve Object ID at given index.

Returns
Reference to the ID<Object> at the given index.

◆ RemoveAllObjects()

auto KTech::Layer::RemoveAllObjects ( ) -> bool

Remove all contained Objects.

Returns
true if removed all Objects. false if there are no Objects in Layer.

◆ RemoveObject()

auto KTech::Layer::RemoveObject ( const ID< Object > & object) -> bool

Remove an Object.

Parameters
[in]objectReference to the Object's ID.
Returns
true if removed. false if doesn't exist in Memory, or isn't in Layer.

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