KTech 1.1.0
C++ 2D terminal game engine library
Loading...
Searching...
No Matches
camera.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 "../basic/cell.hpp"
28#include "../basic/point.hpp"
29#include "../basic/upoint.hpp"
30
31#include <limits>
32#include <string>
33#include <vector>
34
41{
42public:
45 std::string m_name;
47
50 Cell m_background = Cell(' ', RGB(0, 0, 0), RGB(0, 0, 0));
51 std::vector<Cell> m_image;
52
53 Camera(Engine& engine, Point position = Point(0, 0), UPoint resolution = UPoint(10, 10), const std::string& name = "");
54 Camera(Engine& engine, const ID<Map>& parentMap, Point position = Point(0, 0), UPoint resolution = UPoint(10, 10), const std::string& name = "");
55 virtual ~Camera();
56
57 auto EnterMap(const ID<Map>& map) -> bool;
58 auto LeaveMap() -> bool;
59
60 void Resize(UPoint resolution);
61
62 void Render();
63 void Render(const std::vector<ID<Layer>>& layers);
64 void Draw(Point position = Point(0, 0), UPoint start = UPoint(0, 0), UPoint end = UPoint(0, 0), uint8_t alpha = std::numeric_limits<uint8_t>::max());
65 void RenderDrawPrint();
66
67protected:
68 virtual auto OnTick() -> bool;
69
70private:
71 inline void RenderBackground();
72 inline void RenderSimple(uint8_t layerAlpha, Object* object, Texture& texture);
73 inline void RenderComplex(uint8_t layerAlpha, Object* object, Texture& texture);
74 inline void RenderForeground(const RGBA& frgba, const RGBA& brgba);
75
76 friend class KTech::Memory;
77};
World structure that renders Objects of Layers, and exists within Map.
Definition camera.hpp:41
Point m_pos
World position.
Definition camera.hpp:48
ID< Map > m_parentMap
The map which contains this Camera.
Definition camera.hpp:46
void Resize(UPoint resolution)
Resize the image resolution (or "size").
Definition camera.cpp:116
std::vector< Cell > m_image
Cell-based rendered image.
Definition camera.hpp:51
Cell m_background
The background to render upon.
Definition camera.hpp:50
Camera(Engine &engine, Point position=Point(0, 0), UPoint resolution=UPoint(10, 10), const std::string &name="")
Prepare Camera for rendering.
Definition camera.cpp:41
virtual auto OnTick() -> bool
Virtual function called once each tick.
Definition camera.cpp:228
UPoint m_res
Camera::m_image's resolution (or "size").
Definition camera.hpp:49
void Render()
Render all Objects of all Layers of the parent Map.
Definition camera.cpp:125
void Draw(Point position=Point(0, 0), UPoint start=UPoint(0, 0), UPoint end=UPoint(0, 0), uint8_t alpha=std::numeric_limits< uint8_t >::max())
Draw the rendered image (Camera::m_image) to Output so it can be printed to the terminal.
Definition camera.cpp:182
const ID< Camera > m_id
Personal ID.
Definition camera.hpp:44
auto EnterMap(const ID< Map > &map) -> bool
Enter a parent Map.
Definition camera.cpp:84
void RenderDrawPrint()
Shortcut for Camera::Render(), Camera::Draw() and Output::Print().
Definition camera.cpp:198
virtual ~Camera()
Leave the parent map (if in one) and removed itself from Memory.
Definition camera.cpp:67
Engine & engine
Parent engine.
Definition camera.hpp:43
auto LeaveMap() -> bool
Leave the parent Map.
Definition camera.cpp:100
std::string m_name
String name, might be useful for debugging.
Definition camera.hpp:45
Complete engine containing all engine components.
Definition engine.hpp:41
Engine component responsible for registering all world structures.
Definition memory.hpp:36
World structure that comprises Textures and Colliders, and exists within Layer.
Definition object.hpp:37
Terminal cell comprising RGB foreground (character) color, RGB background color, and an ASCII charact...
Definition cell.hpp:31
Serializable world structure identifier.
Definition id.hpp:38
2D vector, mostly used to store positions and directions.
Definition point.hpp:30
Like RGB, but also has an alpha channel representing transparency.
Definition rgba.hpp:30
24-bit color, able of representing 16,777,216 (2^24) different colors.
Definition rgb.hpp:29
A CellA-based sprite.
Definition texture.hpp:48
Unsigned 2D vector, mostly used to store sizes and 2D indexes.
Definition upoint.hpp:29