![]() |
KTech 1.1.0
C++ 2D terminal game engine library
|
World structure that renders Objects of Layers, and exists within Map.
More...
#include <camera.hpp>
Public Member Functions | |
| Camera (Engine &engine, Point position=Point(0, 0), UPoint resolution=UPoint(10, 10), const std::string &name="") | |
Prepare Camera for rendering. | |
| Camera (Engine &engine, const ID< Map > &parentMap, Point position=Point(0, 0), UPoint resolution=UPoint(10, 10), const std::string &name="") | |
Prepare Camera for rendering and immediately enter a Map. | |
| virtual | ~Camera () |
Leave the parent map (if in one) and removed itself from Memory. | |
| auto | EnterMap (const ID< Map > &map) -> bool |
Enter a parent Map. | |
| auto | LeaveMap () -> bool |
Leave the parent Map. | |
| void | Resize (UPoint resolution) |
| Resize the image resolution (or "size"). | |
| void | Render () |
Render all Objects of all Layers of the parent Map. | |
| void | Render (const std::vector< ID< Layer > > &layers) |
Render all Objects of the given Layers. | |
| 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. | |
| void | RenderDrawPrint () |
Shortcut for Camera::Render(), Camera::Draw() and Output::Print(). | |
Public Attributes | |
| Engine & | engine |
| Parent engine. | |
| const ID< Camera > | m_id {ID<Camera>::Unique()} |
Personal ID. | |
| std::string | m_name |
| String name, might be useful for debugging. | |
| ID< Map > | m_parentMap |
The map which contains this Camera. | |
| Point | m_pos |
| World position. | |
| UPoint | m_res |
Camera::m_image's resolution (or "size"). | |
| Cell | m_background = Cell(' ', RGB(0, 0, 0), RGB(0, 0, 0)) |
| The background to render upon. | |
| std::vector< Cell > | m_image |
Cell-based rendered image. | |
Protected Member Functions | |
| virtual auto | OnTick () -> bool |
| Virtual function called once each tick. | |
Friends | |
| class | KTech::Memory |
World structure that renders Objects of Layers, and exists within Map.
Camera is able to render a Cell-based image (Camera::Render()), which can be drawn to Output's image buffer (Camera::Draw() or Output::Draw()), and printed to the terminal (Output::Print()).
| KTech::Camera::Camera | ( | Engine & | engine, |
| Point | position = Point(0, 0), | ||
| UPoint | resolution = UPoint(10, 10), | ||
| const std::string & | name = "" ) |
Prepare Camera for rendering.
| [in] | engine | Parent engine. |
| [in] | position | World position. |
| [in] | resolution | Image resolution. |
| [in] | name | String name. |
| void KTech::Camera::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.
This function redirects to Output::Draw() and passes the given parameters verbatim.
Output::Draw() for parameters explanation. | auto KTech::Camera::LeaveMap | ( | ) | -> bool |
Leave the parent Map.
Camera::m_parentMap. False if doesn't have a parent Map, given Map doesn't exist in Memory, or failed to leave.Map::m_activeCameraI
|
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().
bool value, which is explained in Output::ShouldRenderThisTick().| void KTech::Camera::RenderDrawPrint | ( | ) |
Shortcut for Camera::Render(), Camera::Draw() and Output::Print().
This function calls the above functions with respect to "render on demand" (by checking Output::ShouldRenderThisTick() and Output::ShouldPrintThisTick()). So, you can use this function in your game loop to avoid boilerplate code while still maintaining good performance, unless you want more functionality in your graphics portion of your game loop. This function is especially convenient for testing in no-game-loop mode.
Camera::Render() Camera::Draw() Output::Print() Engine::noGameLoopMode | void KTech::Camera::Resize | ( | UPoint | resolution | ) |
Resize the image resolution (or "size").
| resolution | The new resolution. |