Fazen2d renders via a double-buffered frame loop. Every frame follows three steps in strict order: clear the back-buffer to a uniform color, write shape data into it, then flush the completed buffer to the visible console in a single atomic call. This separation ensures the screen is never updated mid-draw, eliminating flicker even at high frame rates.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/adi3120/Fazen2d/llms.txt
Use this file to discover all available pages before exploring further.
The Three Steps
Clear — background()
Call Passing
game.graphics.background(whiteB) at the start of every frame. Internally this iterates over every cell in the CHAR_INFO* array and writes a space character plus the given color attribute:whiteB produces a bright-white background. Any ConsoleColor constant or raw Windows attribute short works here.Draw — draw()
Call Each shape’s
game.graphics.draw(shape) once per visible object. GraphicsRenderer::draw simply delegates to the shape’s own virtual method:draw() implementation computes which buffer cells it occupies and writes a Unicode character and a color attribute directly into the CHAR_INFO array. For a Point at (x, y), the target index is int(x) + ConsoleHandler::GetConsoleWidth() * int(y). Draw all shapes you want visible before moving to step three.Why Double-Buffering
Without double-buffering, each
draw() call would update the visible console immediately, meaning a fast-moving eye could catch a frame halfway through — some shapes drawn, others not yet. WriteConsoleOutputW copies the entire CHAR_INFO back-buffer to the visible console in a single API call, so the transition from one frame to the next is instantaneous and tear-free. The user always sees a complete, consistent frame.The display() Implementation
The exact source ofGraphicsRenderer::display() from include/GraphicsRenderer.cpp:
| Argument | Source | Description |
|---|---|---|
GetOutHandle() | ConsoleHandler | HANDLE to STD_OUTPUT_HANDLE |
GetBuffScreen() | ConsoleHandler | Pointer to the CHAR_INFO[] back-buffer |
GetBufferSize() | ConsoleHandler | COORD{console_width, console_height} |
GetCharacterPos() | ConsoleHandler | COORD{0, 0} — write starts at the buffer origin |
GetRectWin() | ConsoleHandler | SMALL_RECT{0, 0, width-1, height-1} — destination on screen |
Buffer Indexing
The back-buffer is a flat, one-dimensionalCHAR_INFO array of size console_width × console_height. The cell at console coordinates (x, y) maps to:
Point::draw() uses this formula to write a single character into the buffer:
Char.UnicodeChar carries the Unicode code point (the default solid block is 0x2588 — █). Attributes is the packed Windows console color short combining foreground and background masks. All coordinate values are float internally and are truncated to int at the moment of indexing.
Delta-Time Animation
Shapes can be moved by a fixed pixel offset per frame, but the speed will then depend on how fast the loop runs. UseTimeManager to measure the real elapsed time each frame and multiply velocities by that value, giving frame-rate independent motion:
GetElapsedTime() uses std::chrono::system_clock under the hood. It captures the current time, computes the duration since tp1, advances tp1 to the captured time, and returns the elapsed seconds — so the baseline is automatically updated on every call. No explicit Reset() is needed inside the loop.
The
TimeManager constructor calls Reset() automatically, so the timer is primed from the moment Fazen is constructed. Call Reset() manually only if you want to discard elapsed time and start a fresh measurement — for example, after a pause or a scene transition.Complete Frame Loop Reference
| Method | Description |
|---|---|
game.graphics.background(short col) | Fill every buffer cell with a space and the given color attribute |
game.graphics.draw(Shape& s) | Rasterize a shape into the back-buffer by calling its draw() |
game.graphics.display() | Flush the back-buffer to the console via WriteConsoleOutputW |
game.timer.Reset() | Restart the internal std::chrono clock to the current time |
game.timer.GetElapsedTime() | Return seconds elapsed since the last call (or construction); advances the baseline automatically |
game.keyboardHandler.CheckForUserExit() | Return true when the Escape key is held, signalling loop exit |