coastline 0.0.4
Loading...
Searching...
No Matches
frontend.h
Go to the documentation of this file.
1#pragma once
2
7
8#include <array>
9#include <cstdint>
10#include <filesystem>
11#include <optional>
12#include <string_view>
13#include <vector>
14
15#include <SDL3/SDL.h>
16#include <nlohmann/json.hpp>
17
18#include "common/audio.h"
19#include "scenerenderer.h"
20
21namespace coastline {
22
24constexpr float HALF_PI = 1.570796371f;
26constexpr float PI = 3.141592741f;
28constexpr float TWO_PI = 6.283185482f;
29
31constexpr float SCREEN_WIDTH = 320.0f;
33constexpr float SCREEN_HEIGHT = 240.0f;
34
36constexpr std::size_t SOUND_PADDING = 0x100;
37
39constexpr std::uint64_t SFX_STEP_ONE = 1ull << 32;
40
42constexpr u8 MAX_SFX_VOLUME = 0xFF;
43
51 return (right << 16) + left;
52}
53
55constexpr std::uint32_t COMBINED = 0;
57constexpr std::uint32_t TEXEL0 = 1;
59constexpr std::uint32_t TEXEL1 = 2;
63constexpr std::uint32_t SHADE = 4;
67constexpr std::uint32_t ZERO_AB = 15;
69constexpr std::uint32_t ZERO_D = 7;
72
98 std::uint32_t alphaA0,
99 std::uint32_t alphaB0,
100 std::uint32_t alphaC0,
101 std::uint32_t alphaD0,
102 std::uint32_t a1,
103 std::uint32_t b1,
104 std::uint32_t c1,
105 std::uint32_t d1,
106 std::uint32_t alphaA1,
107 std::uint32_t alphaB1,
108 std::uint32_t alphaC1,
109 std::uint32_t alphaD1) {
110 return {(a0 & 0xf) << 20 | (c0 & 0x1f) << 15 | (alphaA0 & 7) << 12 | (alphaC0 & 7) << 9 |
111 (a1 & 0xf) << 5 | (c1 & 0x1f),
112 (b0 & 0xf) << 28 | (b1 & 0xf) << 24 | (alphaA1 & 7) << 21 | (alphaC1 & 7) << 18 |
113 (d0 & 7) << 15 | (alphaB0 & 7) << 12 | (alphaD0 & 7) << 9 | (d1 & 7) << 6 |
114 (alphaB1 & 7) << 3 | (alphaD1 & 7)};
115}
116
123Matrix4 Translation(float x, float y, float z);
124
129Matrix4 Scale(float s);
130
135Matrix4 RotationX(float angle);
136
141Matrix4 RotationZ(float angle);
142
151
164 float nearPlane,
165 float farPlane,
166 const std::optional<Matrix4> &camera = std::nullopt);
167
173
185Matrix4 ScreenModelAt(float x, float y, float z, float angle, float scale);
186
202Matrix4 StageCamera(float aspect,
203 const std::array<float, 3> &eye,
204 int x,
205 int y,
206 int width,
207 int height,
208 const std::optional<Matrix4> &camera = std::nullopt);
209
219Matrix4 StageFrameAt(float x, float y, float angle);
220
230Matrix4 StageCarAt(float x, float y, float angle);
231
236inline constexpr std::array<std::string_view, 7> STAGE_CAR_PARTS{"lod0-nearDetail",
237 "lod0-textured",
238 "lod0-paint",
239 "lod0-wheel0",
240 "lod0-wheel1",
241 "lod0-wheel2",
242 "lod0-wheel3"};
243
248extern const Lighting STAGE_CAR_LIGHTING;
249
260
266
276 const StageVertex &a,
277 const StageVertex &b,
278 const StageVertex &c);
279
289SDL_Rect FrameRect(Uint32 frameWidth, Uint32 frameHeight, int x, int y, int width, int height);
290
295Lighting ReadLighting(const nlohmann::json &light);
296
303
312
318 float level = 0.0f;
319 float target = 0.0f;
320 float rate = 0.0f;
321 bool autoReverse = false;
322 bool skipFrame = false;
323 int left = 0;
324 int right = 0;
325
332 void SetTarget(float to, float seconds);
333
335 bool FadingIn() const;
336
338 bool FadingOut() const;
339
341 bool Complete() const;
342
348 void Update(float seconds);
349
355 void Draw(SceneRenderer &renderer) const;
356};
357
358} // namespace coastline
The music player of FastTracker 2 modules, the sound channels, and the mixing thread.
A texture of the renderer for flat pictures and text.
Definition scenerenderer.h:333
The renderer of a frame.
Definition scenerenderer.h:467
Definition assetimport.h:11
constexpr std::uint32_t ENVIRONMENT
The environment colour as an RDP colour-combiner input.
Definition frontend.h:65
Matrix4 RotationX(float angle)
constexpr u8 MAX_SFX_VOLUME
The volume of the sound effects at full level.
Definition frontend.h:42
constexpr std::uint32_t ZERO_ALPHA
The zero selector for an RDP alpha-combiner operand.
Definition frontend.h:71
std::array< float, 2 > ScreenExtent(float aspect)
The part of the frame the 4:3 screen of the menus covers, centred: the whole height of a frame wider ...
Matrix4 StageCamera(float aspect, const std::array< float, 3 > &eye, int x, int y, int width, int height, const std::optional< Matrix4 > &camera=std::nullopt)
SetupCameraMatrix() of the console for the trackside camera of a stage of the menus.
constexpr std::uint32_t TEXEL1
The second sampled texel as an RDP colour-combiner input.
Definition frontend.h:59
constexpr std::uint64_t SFX_STEP_ONE
The 32.32 step that plays a sample at its own rate.
Definition frontend.h:39
Matrix4 StageFrameAt(float x, float y, float angle)
The frame of a car on a stage of the menus in the space of the console, facing an angle about z,...
Matrix4 Scale(float s)
Matrix4 StageCarAt(float x, float y, float angle)
The place of a car on a stage of the menus, facing an angle about z, 0.254 above the stage.
std::optional< std::vector< s8 > > ReadSound(const std::filesystem::path &path)
constexpr std::uint32_t ZERO_AB
The zero selector for the A and B RDP colour-combiner operands.
Definition frontend.h:67
Matrix4 RotationZ(float angle)
Matrix4 FlatProjection(float aspect)
constexpr std::size_t SOUND_PADDING
The silence after each sound, for the mixer to read zeros past its end.
Definition frontend.h:36
constexpr float PI
A half turn in radians, in the single precision of the console.
Definition frontend.h:26
constexpr std::uint32_t COMBINED
The previous cycle's result as an RDP colour-combiner input.
Definition frontend.h:55
constexpr std::uint32_t ZERO_D
The zero selector for the D RDP colour-combiner operand.
Definition frontend.h:69
std::array< float, 16 > Matrix4
A 4 by 4 matrix, column by column.
Definition scenerenderer.h:28
constexpr float HALF_PI
A quarter turn in radians, in the single precision of the console.
Definition frontend.h:24
constexpr float SCREEN_WIDTH
The low-resolution screen of the console, in pixels.
Definition frontend.h:31
constexpr float SCREEN_HEIGHT
The height of the low-resolution console screen, in pixels.
Definition frontend.h:33
constexpr float TWO_PI
A whole turn in radians, in the single precision of the console.
Definition frontend.h:28
void AddTriangle(std::vector< FlatVertex > &quads, const StageVertex &a, const StageVertex &b, const StageVertex &c)
Add a shaded triangle to flat quads, as a quad whose last corner repeats its third.
constexpr std::uint32_t PRIMITIVE
The primitive colour as an RDP colour-combiner input.
Definition frontend.h:61
SDL_Rect FrameRect(Uint32 frameWidth, Uint32 frameHeight, int x, int y, int width, int height)
Matrix4 MenuProjection(float aspect, float nearPlane, float farPlane, const std::optional< Matrix4 > &camera=std::nullopt)
The camera of the menus, which looks at the middle of the 320 by 240 screen from 290 in front of it w...
Reflection StageReflection(const RenderTexture *texture, const std::array< float, 3 > &eye)
The reflection of the sky on a car as RenderVehicleModel() sets it up for the trackside camera of the...
s16 PlaySoundEffect(std::vector< s8 > &sample, std::uint32_t volume)
Play a sound on a free sound effect channel.
constexpr std::uint32_t SHADE
The interpolated vertex colour as an RDP colour-combiner input.
Definition frontend.h:63
const Lighting STAGE_CAR_LIGHTING
The lights RenderVehicleModel() lights a car with in the menus: g_DefaultLights, from (84,...
constexpr std::uint32_t TEXEL0
The first sampled texel as an RDP colour-combiner input.
Definition frontend.h:57
Matrix4 ScreenModelAt(float x, float y, float z, float angle, float scale)
DrawModelAt() of the console: a model turned about its own axis, scaled, stood up,...
Matrix4 Translation(float x, float y, float z)
constexpr std::uint32_t SfxVolume(std::uint32_t right, std::uint32_t left)
Definition frontend.h:50
Lighting ReadLighting(const nlohmann::json &light)
constexpr std::array< std::uint32_t, 2 > CombineLerp(std::uint32_t a0, std::uint32_t b0, std::uint32_t c0, std::uint32_t d0, std::uint32_t alphaA0, std::uint32_t alphaB0, std::uint32_t alphaC0, std::uint32_t alphaD0, std::uint32_t a1, std::uint32_t b1, std::uint32_t c1, std::uint32_t d1, std::uint32_t alphaA1, std::uint32_t alphaB1, std::uint32_t alphaC1, std::uint32_t alphaD1)
The two words of gDPSetCombineLERP(), from the colour and alpha inputs of each cycle.
Definition frontend.h:94
constexpr std::array< std::string_view, 7 > STAGE_CAR_PARTS
The parts of a car RenderVehicleModel() draws in the menus: the near detail, the textured parts,...
Definition frontend.h:236
The renderer of the converted models and of flat pictures and text, on the GPU of SDL.
The lights of a model, an ambient colour and a directional colour from a direction in the space the m...
Definition scenerenderer.h:52
The reflection of the sky on a car: the image the parts whose texture coordinates come from their nor...
Definition scenerenderer.h:84
The fade of the screen: a wipe whose level goes to its target at a rate, and the edges of the picture...
Definition frontend.h:317
bool Complete() const
int right
Definition frontend.h:324
float level
Definition frontend.h:318
bool skipFrame
Definition frontend.h:322
void Draw(SceneRenderer &renderer) const
Draw the black of the wipe left and right of the picture, across the whole frame.
float target
Definition frontend.h:319
bool autoReverse
Definition frontend.h:321
int left
Definition frontend.h:323
bool FadingOut() const
void Update(float seconds)
Advance the fade by a frame.
void SetTarget(float to, float seconds)
SetFadeTarget() of the console.
float rate
Definition frontend.h:320
bool FadingIn() const
A vertex of a shaded triangle of a stage: its place and its colour.
Definition frontend.h:262
std::array< float, 3 > position
Definition frontend.h:263
std::array< std::uint8_t, 4 > color
Definition frontend.h:264
short s16
Definition ultratypes.h:24
unsigned char u8
Definition ultratypes.h:18