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 "HudTween.hpp"
9#include "HudTypes.hpp"
10#include "HudWidget.hpp"
11
12#include <SDL3/SDL.h>
13
14#include <memory>
15#include <vector>
16
17class SdfAtlas;
18
23class Hud
24{
25public:
27 bool init(SDL_GPUDevice* device,
28 SDL_GPUShaderFormat shaderFormat,
29 const SdfAtlas& sdfAtlas,
30 uint32_t screenW,
31 uint32_t screenH);
32
34 void quit();
35
37 void resize(uint32_t newW, uint32_t newH);
38
40 void processEvent(const SDL_Event* event);
41
43 void update(float dt, const HudGameState& state);
44
46 void render();
47
49 [[nodiscard]] SDL_GPUTexture* getOutputTexture() const { return renderer_.getOutputTexture(); }
50
52 [[nodiscard]] std::vector<std::unique_ptr<HudWidget>>& widgets() { return widgets_; }
53
55 [[nodiscard]] HudTweenPool& tweens() { return tweens_; }
56
57private:
61 std::vector<std::unique_ptr<HudWidget>> widgets_;
62
63 float screenW_ = 0.f, screenH_ = 0.f;
64
66 void resolveAnchor(const HudWidget& w, float& outX, float& outY) const;
67
69 void createWidgets();
70};
Immediate-mode draw API for HUD widgets.
GPU backend for the HUD system — owns offscreen target, pipeline, and vertex buffer upload.
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:18
Renders batched HUD geometry to an offscreen RGBA8 texture.
Definition HudRenderer.hpp:22
Fixed-size tween pool. No heap allocations.
Definition HudTween.hpp:35
Top-level HUD system.
Definition Hud.hpp:24
void resize(uint32_t newW, uint32_t newH)
Notify of window resize.
Definition Hud.cpp:48
SDL_GPUTexture * getOutputTexture() const
The offscreen texture to blit.
Definition Hud.hpp:49
void quit()
Release all resources.
Definition Hud.cpp:42
void update(float dt, const HudGameState &state)
Tick widget animations and consume game events.
Definition Hud.cpp:80
void resolveAnchor(const HudWidget &w, float &outX, float &outY) const
Resolve anchor + offset to pixel coordinates.
Definition Hud.cpp:119
HudRenderer renderer_
Definition Hud.hpp:58
std::vector< std::unique_ptr< HudWidget > > widgets_
Definition Hud.hpp:61
void render()
Draw all widgets and flush to the GPU offscreen target.
Definition Hud.cpp:92
void createWidgets()
Create all default widgets with initial layout.
Definition Hud.cpp:166
float screenH_
Definition Hud.hpp:63
float screenW_
Definition Hud.hpp:63
HudTweenPool & tweens()
Access the tween pool (for debug panel).
Definition Hud.hpp:55
void processEvent(const SDL_Event *event)
Forward an SDL event to interactive widgets (buy menu, scoreboard).
Definition Hud.cpp:55
HudContext context_
Definition Hud.hpp:59
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:23
HudTweenPool tweens_
Definition Hud.hpp:60
std::vector< std::unique_ptr< HudWidget > > & widgets()
Access all widgets (for debug panel iteration).
Definition Hud.hpp:52
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:148
Base class for a retained HUD element.
Definition HudWidget.hpp:16