KTech 1.1.0
C++ 2D terminal game engine library
Loading...
Searching...
No Matches
layer.hpp
1/*
2 KTech, Kaup's C++ 2D terminal game engine library.
3 Copyright (C) 2023-2025 Ethan Kaufman (AKA Kaup)
4
5 This file is part of KTech.
6
7 KTech is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 any later version.
11
12 KTech is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with KTech. If not, see <https://www.gnu.org/licenses/>.
19*/
20
21#pragma once
22
23#define KTECH_DEFINITION
24#include "../ktech.hpp"
25#undef KTECH_DEFINITION
26#include "../utility/id.hpp"
27#include "../utility/rgbacolors.hpp"
28#include "../basic/rgba.hpp"
29
30#include <limits>
31#include <string>
32#include <vector>
33
40{
41public:
44 std::string m_name;
46 std::vector<ID<Object>> m_objects;
47 bool m_visible = true;
48
49 uint8_t m_alpha = std::numeric_limits<uint8_t>::max();
50 RGBA m_frgba = RGBAColors::transparent;
51 RGBA m_brgba = RGBAColors::transparent;
52
53 Layer(Engine& engine, std::string name = "");
54 Layer(Engine& engine, const ID<Map>& parentMap, std::string name = "");
55 virtual ~Layer();
56
57 auto operator[](size_t index) -> ID<Object>&;
58
59 auto AddObject(const ID<Object>& object) -> bool;
60 auto RemoveObject(const ID<Object>& object) -> bool;
61 auto RemoveAllObjects() -> bool;
62
63 auto EnterMap(const ID<Map>& map) -> bool;
64 auto LeaveMap() -> bool;
65
66protected:
67 virtual auto OnTick() -> bool;
68
69 friend class KTech::Memory;
70};
Complete engine containing all engine components.
Definition engine.hpp:41
World structure that contains Objects, and exists within Map.
Definition layer.hpp:40
ID< Map > m_parentMap
Parent Map.
Definition layer.hpp:45
virtual ~Layer()
Destruct a Layer.
Definition layer.cpp:59
RGBA m_frgba
Foreground color added by Camera after rendering contained Objects.
Definition layer.hpp:50
RGBA m_brgba
Background color added by Camera after rendering contained Objects.
Definition layer.hpp:51
auto operator[](size_t index) -> ID< Object > &
Retrieve Object ID at given index.
Definition layer.cpp:72
Engine & engine
Parent Engine
Definition layer.hpp:42
auto RemoveAllObjects() -> bool
Remove all contained Objects.
Definition layer.cpp:128
uint8_t m_alpha
Opacity used by Camera when rendering contained Objects.
Definition layer.hpp:49
bool m_visible
true: will be rendered by Camera. false: won't be.
Definition layer.hpp:47
std::string m_name
String anme; could be useful in debugging.
Definition layer.hpp:44
auto LeaveMap() -> bool
Leave parent Map.
Definition layer.cpp:164
std::vector< ID< Object > > m_objects
Contained Objects.
Definition layer.hpp:46
auto EnterMap(const ID< Map > &map) -> bool
Enter a Map.
Definition layer.cpp:151
auto RemoveObject(const ID< Object > &object) -> bool
Remove an Object.
Definition layer.cpp:107
virtual auto OnTick() -> bool
Virtual function called once each tick.
Definition layer.cpp:186
auto AddObject(const ID< Object > &object) -> bool
Add an Object.
Definition layer.cpp:83
const ID< Layer > m_id
Personal ID.
Definition layer.hpp:43
Layer(Engine &engine, std::string name="")
Construct a Layer.
Definition layer.cpp:35
Engine component responsible for registering all world structures.
Definition memory.hpp:36
Serializable world structure identifier.
Definition id.hpp:38
Like RGB, but also has an alpha channel representing transparency.
Definition rgba.hpp:30