group2 0.1.0
CSE 125 Group 2
Loading...
Searching...
No Matches
Hud.hpp
Go to the documentation of this file.
1
3
4#pragma once
5
6#include "HudContext.hpp"
7#include "HudRenderer.hpp"
8#include "HudSvgAtlas.hpp"
9#include "HudTween.hpp"
10#include "HudTypes.hpp"
11#include "HudWidget.hpp"
12
13#include <SDL3/SDL.h>
14
15#include <memory>
16#include <vector>
17
18class SdfAtlas;
19
24class Hud
25{
26public:
28 bool init(SDL_GPUDevice* device,
29 SDL_GPUShaderFormat shaderFormat,
30 const SdfAtlas& sdfAtlas,
31 uint32_t screenW,
32 uint32_t screenH);
33
35 void quit();
36
38 void resize(uint32_t newW, uint32_t newH);
39
41 void processEvent(const SDL_Event* event, const InputBindings* bindings);
42
44 void update(float dt, const HudGameState& state);
45
47 void render();
48
50 [[nodiscard]] SDL_GPUTexture* getOutputTexture() const { return renderer_.getOutputTexture(); }
51
53 [[nodiscard]] std::vector<std::unique_ptr<HudWidget>>& widgets() { return widgets_; }
54
56 [[nodiscard]] HudTweenPool& tweens() { return tweens_; }
57
60
62 [[nodiscard]] bool& debugShowAlignmentBorder() { return debugShowAlignmentBorder_; }
63
66
69
70private:
75 std::vector<std::unique_ptr<HudWidget>> widgets_;
80
81 float screenW_ = 0.f, screenH_ = 0.f;
82
84 void resolveAnchor(const HudWidget& w, float& outX, float& outY) const;
85
87 void createWidgets();
88};
Immediate-mode draw API for HUD widgets.
GPU backend for the HUD system — owns offscreen target, pipeline, and vertex buffer upload.
Runtime GPU atlas for LunaSVG-rasterized HUD SVG assets.
Lightweight fixed-pool tween engine for HUD animations.
Shared types for the HUD system.
Base struct for all HUD widgets.
Accumulates HUD geometry during a frame for batch rendering.
Definition HudContext.hpp:19
Renders batched HUD geometry to an offscreen RGBA8 texture.
Definition HudRenderer.hpp:23
Definition HudSvgAtlas.hpp:26
Fixed-size tween pool. No heap allocations.
Definition HudTween.hpp:35
Top-level HUD system.
Definition Hud.hpp:25
void resize(uint32_t newW, uint32_t newH)
Notify of window resize.
Definition Hud.cpp:68
float debugAlignmentBorderOffsetY_
Definition Hud.hpp:79
float debugAlignmentBorderOffsetX_
Definition Hud.hpp:78
SDL_GPUTexture * getOutputTexture() const
The offscreen texture to blit.
Definition Hud.hpp:50
void quit()
Release all resources.
Definition Hud.cpp:61
void update(float dt, const HudGameState &state)
Tick widget animations and consume game events.
Definition Hud.cpp:89
void resolveAnchor(const HudWidget &w, float &outX, float &outY) const
Resolve anchor + offset to pixel coordinates.
Definition Hud.cpp:152
HudRenderer renderer_
Definition Hud.hpp:71
std::vector< std::unique_ptr< HudWidget > > widgets_
Definition Hud.hpp:75
void render()
Draw all widgets and flush to the GPU offscreen target.
Definition Hud.cpp:101
void createWidgets()
Create all default widgets with initial layout.
Definition Hud.cpp:199
bool & debugShowAlignmentBorder()
Debug overlay: draw a screen-space alignment border.
Definition Hud.hpp:62
void processEvent(const SDL_Event *event, const InputBindings *bindings)
Forward an SDL event to interactive widgets (buy menu, scoreboard).
Definition Hud.cpp:75
bool debugRenderInactiveWidgets_
Definition Hud.hpp:76
bool debugShowAlignmentBorder_
Definition Hud.hpp:77
float screenH_
Definition Hud.hpp:81
float screenW_
Definition Hud.hpp:81
HudTweenPool & tweens()
Access the tween pool (for debug panel).
Definition Hud.hpp:56
HudSvgAtlas svgAtlas_
Definition Hud.hpp:72
HudContext context_
Definition Hud.hpp:73
float & debugAlignmentBorderOffsetY()
Vertical inset for the alignment border from top and bottom edges.
Definition Hud.hpp:68
bool init(SDL_GPUDevice *device, SDL_GPUShaderFormat shaderFormat, const SdfAtlas &sdfAtlas, uint32_t screenW, uint32_t screenH)
Initialise all HUD subsystems and create default widgets.
Definition Hud.cpp:39
HudTweenPool tweens_
Definition Hud.hpp:74
float & debugAlignmentBorderOffsetX()
Horizontal inset for the alignment border from left and right edges.
Definition Hud.hpp:65
std::vector< std::unique_ptr< HudWidget > > & widgets()
Access all widgets (for debug panel iteration).
Definition Hud.hpp:53
bool & debugRenderInactiveWidgets()
Debug override: render inactive widgets, excluding the railgun scope.
Definition Hud.hpp:59
Stores action-to-input bindings and helper conversions for UI and persistence.
Definition InputBindings.hpp:128
Loads a TTF font, bakes an SDF glyph atlas, and uploads it to the GPU.
Definition SdfAtlas.hpp:18
Snapshot of game state consumed by the HUD each frame.
Definition HudTypes.hpp:367
Base class for a retained HUD element.
Definition HudWidget.hpp:16