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

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

Engineengine
 Parent engine.
 
const ID< Cameram_id {ID<Camera>::Unique()}
 Personal ID.
 
std::string m_name
 String name, might be useful for debugging.
 
ID< Mapm_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< Cellm_image
 Cell-based rendered image.
 

Protected Member Functions

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

Friends

class KTech::Memory
 

Detailed Description

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()).

Constructor & Destructor Documentation

◆ Camera() [1/2]

KTech::Camera::Camera ( Engine & engine,
Point position = Point(0, 0),
UPoint resolution = UPoint(10, 10),
const std::string & name = "" )

Prepare Camera for rendering.

Parameters
[in]engineParent engine.
[in]positionWorld position.
[in]resolutionImage resolution.
[in]nameString name.

◆ Camera() [2/2]

KTech::Camera::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.

Parameters
[in]engineParent engine.
[in]parentMapParent map to immediately enter.
[in]positionWorld position.
[in]resolutionImage resolution.
[in]nameString name.
See also
Map::m_activeCameraI

Member Function Documentation

◆ Draw()

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.

See also
Output::Draw() for parameters explanation.

◆ EnterMap()

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

Enter a parent Map.

Parameters
mapParent map to enter.
Returns
True if joined given Map. False if already in given Map, given Map doesn't exist in Memory, or failed to join.
See also
Map::m_activeCameraI

◆ LeaveMap()

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

Leave the parent Map.

Returns
True if left Camera::m_parentMap. False if doesn't have a parent Map, given Map doesn't exist in Memory, or failed to leave.
See also
Map::m_activeCameraI

◆ OnTick()

auto KTech::Camera::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()

◆ Render()

void KTech::Camera::Render ( const std::vector< ID< Layer > > & layers)

Render all Objects of the given Layers.

Parameters
layersThe Layers containing the Objects to render.

◆ RenderDrawPrint()

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.

See also
Camera::Render()
Camera::Draw()
Output::Print()
Engine::noGameLoopMode
Tutorial chapter 5: no-game-loop mode example that uses this function

◆ Resize()

void KTech::Camera::Resize ( UPoint resolution)

Resize the image resolution (or "size").

Parameters
resolutionThe new resolution.

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