MXVK Vulkan Framework 0.33.1
C++20 Vulkan rendering framework for practical 2D and 3D application development with SDL3.
Loading...
Searching...
No Matches
space Namespace Reference

Namespaces

namespace  anonymous_namespace{asteroids3d_window.cpp}
namespace  anonymous_namespace{multiplayer.cpp}
namespace  anonymous_namespace{port_mapping.cpp}

Classes

struct  Asteroid
 Runtime state for an asteroid. More...
class  Asteroids3DWindow
struct  FlamePushConstants
 Push-constant payload for the engine-flame shaders. More...
struct  FlameVertex
 Vertex consumed by the procedural engine-flame pipeline. More...
class  MultiplayerSession
 Owns a host or client UDP session and exchanges replicated game state. More...
struct  NetworkAsteroid
 Serialized gameplay state for one asteroid. More...
struct  NetworkExchange
 Collection of remote player updates produced by one exchange tick. More...
struct  NetworkPlayerUpdate
 State received for a specific player slot. More...
struct  NetworkProjectile
 Serialized gameplay state for one projectile. More...
struct  NetworkState
 Complete replicated gameplay state published by one player. More...
struct  Particle
 Runtime state for an explosion or engine particle. More...
class  PortMapping
 Owns an automatically created UPnP or NAT-PMP port mapping. More...
struct  Projectile
 Runtime state for a ship projectile. More...
class  Ship
 Mutable gameplay and movement state for a player ship. More...
struct  ShipCollisionSample
 One spherical sample used by the compound ship collision shape. More...
struct  Star
 Runtime state for one animated background star. More...
class  StarField
 Manages and renders a camera-centered field of animated stars. More...

Enumerations

enum class  GameMode {
  Intro , Loading , Lobby , Playing ,
  MatchOver , GameComplete , GameOver , Intro ,
  Loading , Playing , GameComplete , GameOver
}
 High-level state of the Asteroids application. More...
enum class  GameMode {
  Intro , Loading , Lobby , Playing ,
  MatchOver , GameComplete , GameOver , Intro ,
  Loading , Playing , GameComplete , GameOver
}

Functions

glm::mat4 build_model_matrix (const glm::vec3 &position, const glm::vec3 &rotation_degrees, float scale, const glm::vec3 &center_offset)
 Builds a translated, rotated, scaled model matrix.
SDL_Surface * load_color_keyed_png (const std::string &path, std::uint8_t threshold=12, std::uint8_t softness=48)
 Loads a PNG and fades dark color-key pixels to transparency.
glm::vec3 normalize_or_zero (const glm::vec3 &value)
 Normalizes a direction with a stable fallback.
float random_float (float min_value, float max_value)
 Generates a uniformly distributed floating-point value.
int random_int (int min_value, int max_value)
 Generates a uniformly distributed integer.
std::default_random_engine & rng ()
 Returns the thread-local random number engine used by simulation helpers.
void run_asteroids3d (const Arguments &args)
 Runs the Asteroids application.

Variables

constexpr std::size_t NETWORK_ASTEROID_COUNT = 16
 Maximum asteroid snapshots carried in one network state.
constexpr std::size_t NETWORK_PLAYER_COUNT = 4
 Maximum number of players in a session.
constexpr std::size_t NETWORK_PROJECTILE_COUNT = 15
 Maximum projectile snapshots carried in one network state.
Simulation constants
constexpr float PI = 3.14159265358979323846f
 Single-precision value of pi.
constexpr int GAME_STARS = 22000
 Number of stars in the background field.
constexpr int MAX_PROJECTILES = 64
 Maximum locally simulated projectiles.
constexpr int MAX_ASTEROIDS = 64
 Maximum locally simulated asteroids.
constexpr int MAX_PARTICLES = 6000
 Maximum particles in the shared particle pool.
constexpr int MAX_GENERATIONS = 1
 Maximum asteroid split generation.
constexpr int CHILDREN_PER_SPAWN = 2
 Child asteroids created by a split.
constexpr int LARGE_ASTEROID_POINTS = 20
 Score awarded for a large asteroid.
constexpr int MEDIUM_ASTEROID_POINTS = 50
 Score awarded for a medium asteroid.
constexpr int SMALL_ASTEROID_POINTS = 100
 Score awarded for a small asteroid.
constexpr float PROJECTILE_SPEED = 52.0f
 Projectile travel speed in world units per second.
constexpr float PROJECTILE_LIFETIME = 3.0f
 Projectile lifetime in seconds.
constexpr int FIRE_COOLDOWN = 5
 Frames between firing bursts.
constexpr int SHOTS_PER_BURST = 5
 Projectiles fired in one burst.
constexpr int FIRE_DELAY = 3
 Frames between shots within a burst.
constexpr int EXPLOSION_DURATION_FRAMES = 90
 Ship explosion duration in frames.
constexpr float ROUND_TIME_LIMIT_SECONDS = 270.0f
 Multiplayer round limit in seconds.
constexpr float SHIP_MODEL_SCALE = 1.55f
 Uniform ship model scale.
constexpr float ASTEROID_SHIP_COLLISION_SCALE = 1.08f
 Ship collision-radius adjustment.
constexpr float ASTEROID_PROJECTILE_COLLISION_SCALE = 1.18f
 Projectile collision-radius adjustment.
constexpr glm::vec4 PROJECTILE_COLOR {1.0f, 0.58f, 0.12f, 1.0f}
 Default projectile color.
constexpr Sint16 CONTROLLER_DEAD_ZONE = 8000
 Controller axis dead-zone magnitude.
constexpr float CONTROLLER_AXIS_MAX = 32767.0f
 Maximum signed controller axis magnitude.
constexpr float BOUNDARY_X_MIN = -150.0f
 Minimum simulation x-coordinate.
constexpr float BOUNDARY_X_MAX = 150.0f
 Maximum simulation x-coordinate.
constexpr float BOUNDARY_Y_MIN = -100.0f
 Minimum simulation y-coordinate.
constexpr float BOUNDARY_Y_MAX = 100.0f
 Maximum simulation y-coordinate.
constexpr float BOUNDARY_Z_MIN = -150.0f
 Minimum simulation z-coordinate.
constexpr float BOUNDARY_Z_MAX = 150.0f
 Maximum simulation z-coordinate.
constexpr float BOUNDARY_BOUNCE_FACTOR = 1.2f
 Boundary collision response multiplier.

Enumeration Type Documentation

◆ GameMode [1/2]

enum class space::GameMode
strong

High-level state of the Asteroids application.

Enumerator
Intro 

Introductory screen.

Loading 

Asset-loading screen.

Lobby 

Multiplayer lobby.

Playing 

Active gameplay.

MatchOver 

Completed multiplayer round.

GameComplete 

Completed game.

GameOver 

Player has no remaining lives.

Intro 
Loading 
Playing 
GameComplete 
GameOver 

Definition at line 66 of file asteroids3d_types.hpp.

66 {
67 Intro, ///< Introductory screen.
68 Loading, ///< Asset-loading screen.
69 Lobby, ///< Multiplayer lobby.
70 Playing, ///< Active gameplay.
71 MatchOver, ///< Completed multiplayer round.
72 GameComplete, ///< Completed game.
73 GameOver ///< Player has no remaining lives.
74 };
@ Lobby
Multiplayer lobby.
@ Loading
Asset-loading screen.
@ GameComplete
Completed game.
@ GameOver
Player has no remaining lives.
@ MatchOver
Completed multiplayer round.
@ Playing
Active gameplay.

◆ GameMode [2/2]

enum class space::GameMode
strong
Enumerator
Intro 

Introductory screen.

Loading 

Asset-loading screen.

Lobby 

Multiplayer lobby.

Playing 

Active gameplay.

MatchOver 

Completed multiplayer round.

GameComplete 

Completed game.

GameOver 

Player has no remaining lives.

Intro 
Loading 
Playing 
GameComplete 
GameOver 

Definition at line 56 of file asteroids3d_types.hpp.

56 {
57 Intro,
58 Loading,
59 Playing,
62 };

Function Documentation

◆ build_model_matrix()

glm::mat4 space::build_model_matrix ( const glm::vec3 & position,
const glm::vec3 & rotation_degrees,
float scale,
const glm::vec3 & center_offset )
inline

Builds a translated, rotated, scaled model matrix.

Parameters
positionWorld-space translation.
rotation_degreesEuler rotation in degrees.
scaleUniform scale.
center_offsetModel-space center correction.
Returns
Composed model matrix.

Definition at line 240 of file asteroids3d_types.hpp.

243 {
244 glm::mat4 model(1.0f);
245 model = glm::translate(model, position);
246 model = glm::rotate(model, glm::radians(rotation_degrees.y), glm::vec3(0.0f, 1.0f, 0.0f));
247 model = glm::rotate(model, glm::radians(rotation_degrees.x), glm::vec3(1.0f, 0.0f, 0.0f));
248 model = glm::rotate(model, glm::radians(rotation_degrees.z), glm::vec3(0.0f, 0.0f, 1.0f));
249 model = glm::scale(model, glm::vec3(scale));
250 model = glm::translate(model, center_offset);
251 return model;
252 }

◆ load_color_keyed_png()

SDL_Surface * space::load_color_keyed_png ( const std::string & path,
std::uint8_t threshold = 12,
std::uint8_t softness = 48 )
inline

Loads a PNG and fades dark color-key pixels to transparency.

Parameters
pathPNG file path.
thresholdBrightness at or below which pixels become transparent.
softnessBrightness range over which alpha fades in.
Returns
Newly allocated RGBA surface owned by the caller.
Exceptions
mxvk::ExceptionIf the image cannot be loaded, converted, queried, or locked.

Definition at line 112 of file asteroids3d_types.hpp.

112 {
113 SDL_Surface *loaded_surface = mxvk::LoadPNG(path.c_str());
114 if (loaded_surface == nullptr) {
115 throw mxvk::Exception("Failed to load PNG: " + path);
116 }
117
118 SDL_Surface *surface = SDL_ConvertSurface(loaded_surface, SDL_PIXELFORMAT_RGBA32);
119 SDL_DestroySurface(loaded_surface);
120 if (surface == nullptr) {
121 throw mxvk::Exception("Failed to convert PNG to RGBA: " + path);
122 }
123
124 const SDL_PixelFormatDetails *format_details = SDL_GetPixelFormatDetails(surface->format);
125 if (format_details == nullptr) {
126 SDL_DestroySurface(surface);
127 throw mxvk::Exception("Failed to query pixel format details for: " + path);
128 }
129
130 if (!SDL_LockSurface(surface)) {
131 SDL_DestroySurface(surface);
132 throw mxvk::Exception("Failed to lock PNG surface: " + path);
133 }
134
135 auto *pixels = static_cast<std::uint32_t *>(surface->pixels);
136 const int pixel_count = surface->w * surface->h;
137
138 struct KeyedPixel {
139 std::uint8_t r = 0;
140 std::uint8_t g = 0;
141 std::uint8_t b = 0;
142 std::uint8_t a = 0;
143 };
144
145 std::vector<KeyedPixel> keyed(static_cast<std::size_t>(pixel_count));
146 for (int i = 0; i < pixel_count; ++i) {
147 std::uint8_t r = 0;
148 std::uint8_t g = 0;
149 std::uint8_t b = 0;
150 std::uint8_t a = 0;
151 SDL_GetRGBA(pixels[i], format_details, nullptr, &r, &g, &b, &a);
152 const int brightness = std::max({static_cast<int>(r), static_cast<int>(g), static_cast<int>(b)});
153 if (brightness <= threshold) {
154 keyed[static_cast<std::size_t>(i)] = {r, g, b, 0};
155 continue;
156 }
157 const int soft_end = static_cast<int>(threshold) + static_cast<int>(softness);
158 if (brightness < soft_end) {
159 const float t = static_cast<float>(brightness - threshold) / static_cast<float>(std::max<int>(1, softness));
160 a = static_cast<std::uint8_t>(std::clamp(static_cast<int>(std::lround(static_cast<float>(a) * t)), 0, 255));
161 }
162 keyed[static_cast<std::size_t>(i)] = {r, g, b, a};
163 }
164
165 constexpr int COLOR_BLEED_PASSES = 5;
166 for (int pass = 0; pass < COLOR_BLEED_PASSES; ++pass) {
167 std::vector<KeyedPixel> next = keyed;
168 for (int y = 0; y < surface->h; ++y) {
169 for (int x = 0; x < surface->w; ++x) {
170 const int index = y * surface->w + x;
171 if (keyed[static_cast<std::size_t>(index)].a != 0) {
172 continue;
173 }
174
175 int red = 0;
176 int green = 0;
177 int blue = 0;
178 int count = 0;
179 for (int oy = -1; oy <= 1; ++oy) {
180 for (int ox = -1; ox <= 1; ++ox) {
181 if (ox == 0 && oy == 0) {
182 continue;
183 }
184 const int nx = x + ox;
185 const int ny = y + oy;
186 if (nx < 0 || ny < 0 || nx >= surface->w || ny >= surface->h) {
187 continue;
188 }
189 const KeyedPixel &neighbor = keyed[static_cast<std::size_t>(ny * surface->w + nx)];
190 if (neighbor.a == 0) {
191 continue;
192 }
193 red += neighbor.r;
194 green += neighbor.g;
195 blue += neighbor.b;
196 ++count;
197 }
198 }
199 if (count > 0) {
200 KeyedPixel &out = next[static_cast<std::size_t>(index)];
201 out.r = static_cast<std::uint8_t>(red / count);
202 out.g = static_cast<std::uint8_t>(green / count);
203 out.b = static_cast<std::uint8_t>(blue / count);
204 }
205 }
206 }
207 keyed = std::move(next);
208 }
209
210 for (int i = 0; i < pixel_count; ++i) {
211 const KeyedPixel &px = keyed[static_cast<std::size_t>(i)];
212 pixels[i] = SDL_MapRGBA(format_details, nullptr, px.r, px.g, px.b, px.a);
213 }
214
215 SDL_UnlockSurface(surface);
216 return surface;
217 }
SDL_Surface * LoadPNG(const char *file)
Load a PNG file into an SDL_Surface.
Definition mxvk_png.cpp:103

◆ normalize_or_zero()

glm::vec3 space::normalize_or_zero ( const glm::vec3 & value)
inline

Normalizes a direction with a stable fallback.

Parameters
valueDirection to normalize.
Returns
Normalized value, or forward when its length is near zero.

Definition at line 224 of file asteroids3d_types.hpp.

224 {
225 const float len = glm::length(value);
226 if (len <= 1e-6f) {
227 return glm::vec3(0.0f, 0.0f, -1.0f);
228 }
229 return value / len;
230 }

◆ random_float()

float space::random_float ( float min_value,
float max_value )
inline

Generates a uniformly distributed floating-point value.

Parameters
min_valueInclusive lower bound.
max_valueInclusive upper bound.
Returns
Generated value.

Definition at line 88 of file asteroids3d_types.hpp.

88 {
89 std::uniform_real_distribution<float> dist(min_value, max_value);
90 return dist(rng());
91 }
std::default_random_engine & rng()
Returns the thread-local random number engine used by simulation helpers.

◆ random_int()

int space::random_int ( int min_value,
int max_value )
inline

Generates a uniformly distributed integer.

Parameters
min_valueInclusive lower bound.
max_valueInclusive upper bound.
Returns
Generated value.

Definition at line 99 of file asteroids3d_types.hpp.

99 {
100 std::uniform_int_distribution<int> dist(min_value, max_value);
101 return dist(rng());
102 }

◆ rng()

std::default_random_engine & space::rng ( )
inline

Returns the thread-local random number engine used by simulation helpers.

Definition at line 77 of file asteroids3d_types.hpp.

77 {
78 static thread_local std::default_random_engine engine{std::random_device{}()};
79 return engine;
80 }

◆ run_asteroids3d()

void space::run_asteroids3d ( const Arguments & args)

Runs the Asteroids application.

Parameters
argsParsed command-line arguments controlling the application.

Definition at line 3703 of file asteroids3d_window.cpp.

3703 {
3704 Asteroids3DWindow window(args.path, args.width, args.height, args.fullscreen, args.enable_vsync, args.enable_crt, args.disable_sound);
3705 window.loop();
3706}
bool fullscreen
Whether fullscreen mode was requested.
Definition argz.hpp:736
bool enable_vsync
Enable FIFO present mode / v-sync (--enable-vsync).
Definition argz.hpp:750
int height
Viewport height in pixels (default: 720).
Definition argz.hpp:733
std::string path
Asset root; proc_args() defaults it to the executable directory.
Definition argz.hpp:735
int width
Viewport width in pixels (default: 1280).
Definition argz.hpp:732
bool enable_crt
Enable CRT post-processing at startup (--enable-crt).
Definition argz.hpp:749
bool disable_sound
Disable application background music (--disable-sound).
Definition argz.hpp:752

Variable Documentation

◆ ASTEROID_PROJECTILE_COLLISION_SCALE

float space::ASTEROID_PROJECTILE_COLLISION_SCALE = 1.18f
constexpr

Projectile collision-radius adjustment.

Definition at line 52 of file asteroids3d_types.hpp.

◆ ASTEROID_SHIP_COLLISION_SCALE

float space::ASTEROID_SHIP_COLLISION_SCALE = 1.08f
constexpr

Ship collision-radius adjustment.

Definition at line 51 of file asteroids3d_types.hpp.

◆ BOUNDARY_BOUNCE_FACTOR

float space::BOUNDARY_BOUNCE_FACTOR = 1.2f
constexpr

Boundary collision response multiplier.

Definition at line 62 of file asteroids3d_types.hpp.

◆ BOUNDARY_X_MAX

float space::BOUNDARY_X_MAX = 150.0f
constexpr

Maximum simulation x-coordinate.

Definition at line 57 of file asteroids3d_types.hpp.

◆ BOUNDARY_X_MIN

float space::BOUNDARY_X_MIN = -150.0f
constexpr

Minimum simulation x-coordinate.

Definition at line 56 of file asteroids3d_types.hpp.

◆ BOUNDARY_Y_MAX

float space::BOUNDARY_Y_MAX = 100.0f
constexpr

Maximum simulation y-coordinate.

Definition at line 59 of file asteroids3d_types.hpp.

◆ BOUNDARY_Y_MIN

float space::BOUNDARY_Y_MIN = -100.0f
constexpr

Minimum simulation y-coordinate.

Definition at line 58 of file asteroids3d_types.hpp.

◆ BOUNDARY_Z_MAX

float space::BOUNDARY_Z_MAX = 150.0f
constexpr

Maximum simulation z-coordinate.

Definition at line 61 of file asteroids3d_types.hpp.

◆ BOUNDARY_Z_MIN

float space::BOUNDARY_Z_MIN = -150.0f
constexpr

Minimum simulation z-coordinate.

Definition at line 60 of file asteroids3d_types.hpp.

◆ CHILDREN_PER_SPAWN

int space::CHILDREN_PER_SPAWN = 2
constexpr

Child asteroids created by a split.

Definition at line 39 of file asteroids3d_types.hpp.

◆ CONTROLLER_AXIS_MAX

float space::CONTROLLER_AXIS_MAX = 32767.0f
constexpr

Maximum signed controller axis magnitude.

Definition at line 55 of file asteroids3d_types.hpp.

◆ CONTROLLER_DEAD_ZONE

Sint16 space::CONTROLLER_DEAD_ZONE = 8000
constexpr

Controller axis dead-zone magnitude.

Definition at line 54 of file asteroids3d_types.hpp.

◆ EXPLOSION_DURATION_FRAMES

int space::EXPLOSION_DURATION_FRAMES = 90
constexpr

Ship explosion duration in frames.

Definition at line 48 of file asteroids3d_types.hpp.

◆ FIRE_COOLDOWN

int space::FIRE_COOLDOWN = 5
constexpr

Frames between firing bursts.

Definition at line 45 of file asteroids3d_types.hpp.

◆ FIRE_DELAY

int space::FIRE_DELAY = 3
constexpr

Frames between shots within a burst.

Definition at line 47 of file asteroids3d_types.hpp.

◆ GAME_STARS

int space::GAME_STARS = 22000
constexpr

Number of stars in the background field.

Definition at line 34 of file asteroids3d_types.hpp.

◆ LARGE_ASTEROID_POINTS

int space::LARGE_ASTEROID_POINTS = 20
constexpr

Score awarded for a large asteroid.

Definition at line 40 of file asteroids3d_types.hpp.

◆ MAX_ASTEROIDS

int space::MAX_ASTEROIDS = 64
constexpr

Maximum locally simulated asteroids.

Definition at line 36 of file asteroids3d_types.hpp.

◆ MAX_GENERATIONS

int space::MAX_GENERATIONS = 1
constexpr

Maximum asteroid split generation.

Definition at line 38 of file asteroids3d_types.hpp.

◆ MAX_PARTICLES

int space::MAX_PARTICLES = 6000
constexpr

Maximum particles in the shared particle pool.

Definition at line 37 of file asteroids3d_types.hpp.

◆ MAX_PROJECTILES

int space::MAX_PROJECTILES = 64
constexpr

Maximum locally simulated projectiles.

Definition at line 35 of file asteroids3d_types.hpp.

◆ MEDIUM_ASTEROID_POINTS

int space::MEDIUM_ASTEROID_POINTS = 50
constexpr

Score awarded for a medium asteroid.

Definition at line 41 of file asteroids3d_types.hpp.

◆ NETWORK_ASTEROID_COUNT

std::size_t space::NETWORK_ASTEROID_COUNT = 16
constexpr

Maximum asteroid snapshots carried in one network state.

Definition at line 25 of file multiplayer.hpp.

◆ NETWORK_PLAYER_COUNT

std::size_t space::NETWORK_PLAYER_COUNT = 4
constexpr

Maximum number of players in a session.

Definition at line 27 of file multiplayer.hpp.

◆ NETWORK_PROJECTILE_COUNT

std::size_t space::NETWORK_PROJECTILE_COUNT = 15
constexpr

Maximum projectile snapshots carried in one network state.

Definition at line 23 of file multiplayer.hpp.

◆ PI

float space::PI = 3.14159265358979323846f
constexpr

Single-precision value of pi.

Definition at line 33 of file asteroids3d_types.hpp.

◆ PROJECTILE_COLOR

glm::vec4 space::PROJECTILE_COLOR {1.0f, 0.58f, 0.12f, 1.0f}
constexpr

Default projectile color.

Definition at line 53 of file asteroids3d_types.hpp.

◆ PROJECTILE_LIFETIME

float space::PROJECTILE_LIFETIME = 3.0f
constexpr

Projectile lifetime in seconds.

Definition at line 44 of file asteroids3d_types.hpp.

◆ PROJECTILE_SPEED

float space::PROJECTILE_SPEED = 52.0f
constexpr

Projectile travel speed in world units per second.

Definition at line 43 of file asteroids3d_types.hpp.

◆ ROUND_TIME_LIMIT_SECONDS

float space::ROUND_TIME_LIMIT_SECONDS = 270.0f
constexpr

Multiplayer round limit in seconds.

Definition at line 49 of file asteroids3d_types.hpp.

◆ SHIP_MODEL_SCALE

float space::SHIP_MODEL_SCALE = 1.55f
constexpr

Uniform ship model scale.

Definition at line 50 of file asteroids3d_types.hpp.

◆ SHOTS_PER_BURST

int space::SHOTS_PER_BURST = 5
constexpr

Projectiles fired in one burst.

Definition at line 46 of file asteroids3d_types.hpp.

◆ SMALL_ASTEROID_POINTS

int space::SMALL_ASTEROID_POINTS = 100
constexpr

Score awarded for a small asteroid.

Definition at line 42 of file asteroids3d_types.hpp.