MXVK Vulkan Framework 0.35.0
C++20 Vulkan rendering framework for practical 2D and 3D application development with SDL3.
Loading...
Searching...
No Matches
anonymous_namespace{main.cpp} Namespace Reference

Classes

struct  Block
struct  Cell
struct  CubeInstance
struct  FaceDraw
struct  GridCubePlacement
class  HighScores
struct  Layout
struct  Mesh
struct  MeshInstance
struct  MipLevel
struct  Piece
class  PongGame
struct  PoolBall
class  PuzzleDropWindow
struct  RasterVertex
struct  Score
struct  ScoreEntry
struct  SinkAnim
class  SoftwareRenderer
class  SurfaceDeleter
struct  Texture
struct  TextureLevel
struct  TexVertex
struct  Triangle

Typedefs

using SurfacePtr = std::unique_ptr<SDL_Surface, SurfaceDeleter>

Enumerations

enum class  BlockType {
  Null = 0 , Clear , Red1 , Red2 ,
  Red3 , Green1 , Green2 , Green3 ,
  Blue1 , Blue2 , Blue3 , Match
}
enum class  GamePhase {
  Aiming , Charging , Rolling , Placing ,
  GameOver
}
enum class  GameScreen { Intro , Scores , Game , Start }
enum class  Screen {
  Intro , Menu , Game , Scores ,
  Credits , NameEntry , Intro , Menu ,
  Game , Scores , Credits , NameEntry
}
enum class  Screen {
  Intro , Menu , Game , Scores ,
  Credits , NameEntry , Intro , Menu ,
  Game , Scores , Credits , NameEntry
}
enum class  ShiftDirection { Down , Up }

Functions

void build_mipmaps (Texture &texture)
SurfacePtr create_frame_surface (int width, int height)
SurfacePtr createFrameSurface (int width, int height)
bool crosses_horizontal_texture_seam (const std::array< mxvk::vec2D, 3 > &texcoords)
bool hasPoolAssets (const std::filesystem::path &root)
bool hasResolutionArgument (int argc, char **argv)
mxvk::MXCOLOR interpolate_color (mxvk::MXCOLOR first, mxvk::MXCOLOR second, float fraction)
bool is_play_block (BlockType type)
Texture load_texture (const std::string &filename, const std::string &asset_path, bool generate_mipmaps)
Texture load_texture (const std::string &path)
Texture load_texture (const std::string &path, bool generate_mipmaps=false)
std::filesystem::path model_path (const std::string &filename, const std::string &asset_path)
mxvk::MXCOLOR pack_color (std::uint32_t red, std::uint32_t green, std::uint32_t blue, std::uint32_t alpha)
std::filesystem::path pyramid_path (const std::string &asset_path)
float randFloat (float mn, float mx)
std::string resolve_texture_path (const Arguments &args)
std::filesystem::path resolveAssetRoot (const std::string &path)
std::filesystem::path resolvePuzzleAssetRoot (const std::filesystem::path &asset_root)
bool same_or_match (BlockType actual, BlockType expected)
std::filesystem::path scorePath (const std::filesystem::path &asset_root)
int texture_index (BlockType type)
std::filesystem::path texture_path (const std::string &filename, const std::string &asset_path)
std::array< mxvk::vec2D, 3 > unwrap_horizontal_texcoords (std::array< mxvk::vec2D, 3 > texcoords)

Variables

constexpr float AIM_LENGTH = 2.0f
constexpr float AIM_THICKNESS_Y = 0.008f
constexpr float AIM_THICKNESS_Z = 0.015f
constexpr std::string_view APP_NAME = "3dmath_plg_loader"
constexpr std::string_view BACKEND_NAME = "native"
constexpr mxvk::MXCOLOR BACKGROUND_COLOR = mxvk::MXVK_RGB(3, 4, 8)
const std::array< glm::vec3, NUM_BALLS > BALL_COLORS
constexpr float BALL_RADIUS = 0.14f
constexpr int base_height = 1080
constexpr int base_width = 1440
constexpr float BLOCK_HALF_EXTENT = 0.064f
constexpr float BLOCK_SPACING = 0.145f
constexpr std::array< const char *, 10 > BLOCK_TEXTURE_FILES
constexpr int board_cols = 8
constexpr int BOARD_HEIGHT = 22
constexpr int board_rows = 18
constexpr int BOARD_WIDTH = 20
constexpr float CAM_BASE_TOTAL_SCALE = 1.359411f
constexpr float CAMERA_DISTANCE = 7.0f
constexpr float CAMERA_ZOOM_STEP = 0.45f
constexpr float COURT_HALF_HEIGHT = 1.45f
constexpr float COURT_HALF_WIDTH = 2.65f
constexpr float CUE_LENGTH = 2.5f
constexpr float CUE_THICKNESS = 0.03f
constexpr int DEFAULT_FRAME_HEIGHT = 240
constexpr int DEFAULT_FRAME_WIDTH = 320
constexpr std::string_view DEFAULT_MODEL = "sphere.plg"
constexpr std::array< float, 3 > FALL_SECONDS {0.86f, 0.68f, 0.50f}
constexpr int flash_time_ms = 180
constexpr float FRAME_GAP = 0.016f
constexpr float FRAME_HALF_EXTENT = BLOCK_HALF_EXTENT * 0.72f
constexpr float FRICTION = 0.9988f
constexpr int game_base_height = 480
constexpr int game_base_width = 640
constexpr int game_block_height = 14
constexpr int game_block_spacing = 1
constexpr int game_block_width = 31
constexpr int game_board_start_x = 184
constexpr int game_board_start_y = 78
constexpr int game_next_panel_x = 450
constexpr int game_next_panel_y = 180
constexpr float GRID_DEFAULT_CAMERA_DISTANCE = 2.45f
constexpr float GRID_MAX_CAMERA_DISTANCE = 9.0f
constexpr float GRID_MAX_PITCH = 70.0f
constexpr float GRID_MIN_CAMERA_DISTANCE = 1.65f
constexpr float GRID_MIN_PITCH = -70.0f
constexpr float GRID_PITCH_SPEED = 90.0f
constexpr int GRID_VERTICAL_GAP = 5
constexpr float GRID_YAW_SPEED = 115.0f
constexpr float GRID_ZOOM_SPEED = 3.2f
constexpr Uint32 joy_repeat_delay_ms = 180
constexpr Sint16 joystick_dead_zone = 16000
constexpr int LEVEL_COUNT = 8
constexpr int lines_per_speedup = 10
constexpr float MAX_CAMERA_DISTANCE = 12.0f
constexpr int max_name_length = 16
constexpr float MAX_PITCH_DEGREES = 89.0f
constexpr float MAX_POWER = 1.5f
constexpr int max_scores = 8
constexpr int menu_item_count = 4
constexpr float MIN_CAMERA_DISTANCE = 2.5f
constexpr float MIN_SPEED = 0.001f
constexpr std::string_view MODEL_FORMAT = "PLG"
constexpr float MODEL_SCALE = 2.0f
constexpr float MOUSE_ROTATION_SENSITIVITY = 0.35f
constexpr int NUM_BALLS = 16
constexpr float PADDLE_HALF_HEIGHT = 0.42f
constexpr float PADDLE_HALF_WIDTH = 0.12f
constexpr float PADDLE_X = 2.25f
constexpr float PI = 3.14159265358979323846f
constexpr int piece_height = 3
constexpr float POCKET_INSET = 0.25f
constexpr float POCKET_R = 0.25f
const std::array< glm::vec2, 6 > POCKETS
constexpr int score_points_per_match = 6
constexpr float SINK_DURATION = 0.45f
constexpr float TABLE_H = 6.0f
constexpr float TABLE_HALF_H = TABLE_H / 2.0f
constexpr float TABLE_HALF_W = TABLE_W / 2.0f
constexpr float TABLE_W = 12.0f
constexpr int title_screen_time_ms = 1500
constexpr mxvk::MXCOLOR transparent_black = 0x00000000U
constexpr int WINDOW_HEIGHT = 1080
constexpr std::string_view WINDOW_TITLE = "MXVK 3D Math PLG Loader"
constexpr int WINDOW_WIDTH = 1440

Typedef Documentation

◆ SurfacePtr

typedef std::unique_ptr< SDL_Surface, SurfaceDeleter > anonymous_namespace{main.cpp}::SurfacePtr = std::unique_ptr<SDL_Surface, SurfaceDeleter>

Definition at line 27 of file main.cpp.

Enumeration Type Documentation

◆ BlockType

◆ GamePhase

enum class anonymous_namespace{main.cpp}::GamePhase
strong

◆ GameScreen

enum class anonymous_namespace{main.cpp}::GameScreen
strong

◆ Screen [1/2]

enum class anonymous_namespace{main.cpp}::Screen
strong
Enumerator
Intro 
Menu 
Game 
Scores 
Credits 
NameEntry 
Intro 
Menu 
Game 
Scores 
Credits 
NameEntry 

Definition at line 64 of file main.cpp.

◆ Screen [2/2]

enum class anonymous_namespace{main.cpp}::Screen
strong
Enumerator
Intro 
Menu 
Game 
Scores 
Credits 
NameEntry 
Intro 
Menu 
Game 
Scores 
Credits 
NameEntry 

Definition at line 49 of file main.cpp.

49 {
50 Intro,
51 Menu,
52 Game,
53 Scores,
54 Credits,
56 };

◆ ShiftDirection

enum class anonymous_namespace{main.cpp}::ShiftDirection
strong
Enumerator
Down 
Up 

Definition at line 78 of file main.cpp.

Function Documentation

◆ build_mipmaps()

void anonymous_namespace{main.cpp}::build_mipmaps ( Texture & texture)

Definition at line 232 of file main.cpp.

232 {
233 int source_width = texture.width;
234 int source_height = texture.height;
235 const std::vector<mxvk::MXCOLOR> *source_pixels = &texture.pixels;
236 while (source_width > 1 || source_height > 1) {
237 TextureLevel level;
238 level.width = std::max(1, source_width / 2);
239 level.height = std::max(1, source_height / 2);
240 level.pixels.resize(static_cast<std::size_t>(level.width * level.height));
241 for (int y = 0; y < level.height; ++y) {
242 for (int x = 0; x < level.width; ++x) {
243 std::uint32_t red = 0;
244 std::uint32_t green = 0;
245 std::uint32_t blue = 0;
246 std::uint32_t alpha = 0;
247 for (int offset_y = 0; offset_y < 2; ++offset_y) {
248 for (int offset_x = 0; offset_x < 2; ++offset_x) {
249 const int source_x = std::min(x * 2 + offset_x, source_width - 1);
250 const int source_y = std::min(y * 2 + offset_y, source_height - 1);
251 const mxvk::MXCOLOR color = (*source_pixels)[static_cast<std::size_t>(source_y * source_width + source_x)];
252 red += mxvk::color_r(color);
253 green += mxvk::color_g(color);
254 blue += mxvk::color_b(color);
255 alpha += mxvk::color_a(color);
256 }
257 }
258 level.pixels[static_cast<std::size_t>(y * level.width + x)] = ((alpha / 4U) << 24U) | ((red / 4U) << 16U) | ((green / 4U) << 8U) | (blue / 4U);
259 }
260 }
261 texture.mipmaps.push_back(std::move(level));
262 source_width = texture.mipmaps.back().width;
263 source_height = texture.mipmaps.back().height;
264 source_pixels = &texture.mipmaps.back().pixels;
265 }
266 }
constexpr std::uint8_t color_r(MXCOLOR color)
Extract the red component from a packed ARGB color.
Definition mxvk_math.h:52
std::uint32_t MXCOLOR
Packed 32-bit color in ARGB byte order.
Definition mxvk_math.h:40
constexpr std::uint8_t color_g(MXCOLOR color)
Extract the green component from a packed ARGB color.
Definition mxvk_math.h:55
constexpr std::uint8_t color_a(MXCOLOR color)
Extract the alpha component from a packed ARGB color.
Definition mxvk_math.h:61
constexpr std::uint8_t color_b(MXCOLOR color)
Extract the blue component from a packed ARGB color.
Definition mxvk_math.h:58
std::vector< mxvk::MXCOLOR > pixels
Definition main.cpp:185
std::vector< TextureLevel > mipmaps
Definition main.cpp:192
std::vector< mxvk::MXCOLOR > pixels
Definition main.cpp:191

◆ create_frame_surface()

SurfacePtr anonymous_namespace{main.cpp}::create_frame_surface ( int width,
int height )
nodiscard

Definition at line 29 of file main.cpp.

29 {
30 SurfacePtr surface(SDL_CreateSurface(width, height, SDL_PIXELFORMAT_RGBA32));
31 if (!surface) {
32 throw mxvk::Exception(std::format("Failed to create 3dmath frame surface: {}", SDL_GetError()));
33 }
34 return surface;
35 }
std::unique_ptr< SDL_Surface, SurfaceDeleter > SurfacePtr
Definition main.cpp:27

◆ createFrameSurface()

SurfacePtr anonymous_namespace{main.cpp}::createFrameSurface ( int width,
int height )

Definition at line 118 of file main.cpp.

118 {
119 SurfacePtr surface(SDL_CreateSurface(width, height, SDL_PIXELFORMAT_RGBA32));
120 if (!surface) {
121 throw mxvk::Exception(std::format("Failed to create 3dmath_masterpiece frame surface: {}", SDL_GetError()));
122 }
123 return surface;
124 }

◆ crosses_horizontal_texture_seam()

bool anonymous_namespace{main.cpp}::crosses_horizontal_texture_seam ( const std::array< mxvk::vec2D, 3 > & texcoords)
nodiscard

Definition at line 220 of file main.cpp.

220 {
221 const auto [minimum, maximum] = std::minmax_element(texcoords.begin(), texcoords.end(), [](const mxvk::vec2D &first, const mxvk::vec2D &second) { return first.x < second.x; });
222 const float span = maximum->x - minimum->x;
223 return span > 0.5f && span < 1.0f - mxvk::EPSILON;
224 }
Two-dimensional float vector with common arithmetic helpers.
Definition mxvk_math.h:158
constexpr float EPSILON
Default tolerance used for floating-point singularity and zero-length checks.
Definition mxvk_math.h:37

◆ hasPoolAssets()

bool anonymous_namespace{main.cpp}::hasPoolAssets ( const std::filesystem::path & root)

Definition at line 89 of file main.cpp.

89 {
90 const std::filesystem::path data = root / "data";
91 return std::filesystem::exists(data / "pooltable_felt.mxmod.z") && std::filesystem::exists(data / "pooltable_wood.mxmod.z") && std::filesystem::exists(data / "pooltable_pocket.mxmod.z") && std::filesystem::exists(data / "table.png");
92 }

◆ hasResolutionArgument()

bool anonymous_namespace{main.cpp}::hasResolutionArgument ( int argc,
char ** argv )

Definition at line 126 of file main.cpp.

126 {
127 for (int i = 1; i < argc; ++i) {
128 const std::string arg = argv[i] == nullptr ? std::string{} : std::string(argv[i]);
129 if (arg == "-r" || arg == "-R" || arg == "--resolution") {
130 return true;
131 }
132 }
133 return false;
134 }

◆ interpolate_color()

mxvk::MXCOLOR anonymous_namespace{main.cpp}::interpolate_color ( mxvk::MXCOLOR first,
mxvk::MXCOLOR second,
float fraction )
nodiscard

Definition at line 55 of file main.cpp.

55 {
56 const std::uint32_t second_weight = static_cast<std::uint32_t>(std::clamp(static_cast<int>(fraction * 256.0f + 0.5f), 0, 256));
57 const std::uint32_t first_weight = 256U - second_weight;
58 const auto interpolate_channel = [first_weight, second_weight](std::uint8_t first_channel, std::uint8_t second_channel) { return (static_cast<std::uint32_t>(first_channel) * first_weight + static_cast<std::uint32_t>(second_channel) * second_weight + 128U) >> 8U; };
59 return pack_color(interpolate_channel(mxvk::color_r(first), mxvk::color_r(second)), interpolate_channel(mxvk::color_g(first), mxvk::color_g(second)), interpolate_channel(mxvk::color_b(first), mxvk::color_b(second)), interpolate_channel(mxvk::color_a(first), mxvk::color_a(second)));
60 }
mxvk::MXCOLOR pack_color(std::uint32_t red, std::uint32_t green, std::uint32_t blue, std::uint32_t alpha)
Definition main.cpp:53

◆ is_play_block()

bool anonymous_namespace{main.cpp}::is_play_block ( BlockType type)
nodiscard

Definition at line 176 of file main.cpp.

176{ return type >= BlockType::Red1 && type <= BlockType::Match; }

◆ load_texture() [1/3]

Texture anonymous_namespace{main.cpp}::load_texture ( const std::string & filename,
const std::string & asset_path,
bool generate_mipmaps )
nodiscard

Definition at line 135 of file main.cpp.

135 {
136 if (filename.empty()) {
137 return {};
138 }
139
140 const std::filesystem::path path = texture_path(filename, asset_path);
141 SurfacePtr loaded(mxvk::LoadPNG(path.string().c_str()));
142 if (!loaded) {
143 throw mxvk::Exception(std::format("{}: failed to load texture '{}'", APP_NAME, path.string()));
144 }
145
146 SurfacePtr rgba(SDL_ConvertSurface(loaded.get(), SDL_PIXELFORMAT_RGBA32));
147 if (!rgba) {
148 throw mxvk::Exception(std::format("{}: failed to convert texture '{}': {}", APP_NAME, path.string(), SDL_GetError()));
149 }
150
151 const SDL_PixelFormatDetails *format = SDL_GetPixelFormatDetails(rgba->format);
152 if (format == nullptr) {
153 throw mxvk::Exception(std::format("{}: failed to query texture format '{}': {}", APP_NAME, path.string(), SDL_GetError()));
154 }
155
156 Texture texture;
157 MipLevel base_level;
158 base_level.width = rgba->w;
159 base_level.height = rgba->h;
160 base_level.pixels.resize(static_cast<std::size_t>(base_level.width) * static_cast<std::size_t>(base_level.height));
161 for (int y = 0; y < base_level.height; ++y) {
162 const auto *row = static_cast<const std::uint8_t *>(rgba->pixels) + static_cast<std::size_t>(y) * static_cast<std::size_t>(rgba->pitch);
163 const auto *source = reinterpret_cast<const std::uint32_t *>(row);
164 for (int x = 0; x < base_level.width; ++x) {
165 std::uint8_t red = 0;
166 std::uint8_t green = 0;
167 std::uint8_t blue = 0;
168 std::uint8_t alpha = 0;
169 SDL_GetRGBA(source[x], format, nullptr, &red, &green, &blue, &alpha);
170 base_level.pixels[static_cast<std::size_t>(y) * static_cast<std::size_t>(base_level.width) + static_cast<std::size_t>(x)] = pack_color(red, green, blue, alpha);
171 }
172 }
173 texture.levels.push_back(std::move(base_level));
174
175 while (generate_mipmaps && (texture.levels.back().width > 1 || texture.levels.back().height > 1)) {
176 const MipLevel &source = texture.levels.back();
177 MipLevel destination;
178 destination.width = std::max(1, (source.width + 1) / 2);
179 destination.height = std::max(1, (source.height + 1) / 2);
180 destination.pixels.resize(static_cast<std::size_t>(destination.width) * static_cast<std::size_t>(destination.height));
181 for (int y = 0; y < destination.height; ++y) {
182 for (int x = 0; x < destination.width; ++x) {
183 const int first_x = std::min(x * 2, source.width - 1);
184 const int second_x = std::min(first_x + 1, source.width - 1);
185 const int first_y = std::min(y * 2, source.height - 1);
186 const int second_y = std::min(first_y + 1, source.height - 1);
187 const auto texel = [&source](int source_x, int source_y) { return source.pixels[static_cast<std::size_t>(source_y) * static_cast<std::size_t>(source.width) + static_cast<std::size_t>(source_x)]; };
188 const std::array<mxvk::MXCOLOR, 4> colors = {
189 texel(first_x, first_y),
190 texel(second_x, first_y),
191 texel(first_x, second_y),
192 texel(second_x, second_y),
193 };
194 const auto average_channel = [&colors](auto component) {
195 std::uint32_t sum = 0;
196 for (const mxvk::MXCOLOR color : colors) {
197 sum += component(color);
198 }
199 return (sum + 2U) / 4U;
200 };
201 destination.pixels[static_cast<std::size_t>(y) * static_cast<std::size_t>(destination.width) + static_cast<std::size_t>(x)] = pack_color(average_channel(mxvk::color_r), average_channel(mxvk::color_g), average_channel(mxvk::color_b), average_channel(mxvk::color_a));
202 }
203 }
204 texture.levels.push_back(std::move(destination));
205 }
206
207 std::cout << std::format("{}: loaded texture '{}' ({}x{}, {} mip levels)\n", APP_NAME, path.string(), texture.width(), texture.height(), texture.levels.size());
208 return texture;
209 }
std::filesystem::path texture_path(const std::string &filename, const std::string &asset_path)
Definition main.cpp:122
constexpr std::string_view APP_NAME
Definition main.cpp:38
SDL_Surface * LoadPNG(const char *file)
Load a PNG file into an SDL_Surface.
Definition mxvk_png.cpp:89

◆ load_texture() [2/3]

Texture anonymous_namespace{main.cpp}::load_texture ( const std::string & path)
nodiscard

Definition at line 100 of file main.cpp.

100 {
101 SurfacePtr loaded(mxvk::LoadPNG(path.c_str()));
102 if (!loaded) {
103 throw mxvk::Exception(std::format("3dmath_texture: failed to load PNG '{}'", path));
104 }
105
106 SurfacePtr rgba(SDL_ConvertSurface(loaded.get(), SDL_PIXELFORMAT_RGBA32));
107 if (!rgba) {
108 throw mxvk::Exception(std::format("3dmath_texture: failed to convert PNG '{}': {}", path, SDL_GetError()));
109 }
110
111 const SDL_PixelFormatDetails *format = SDL_GetPixelFormatDetails(rgba->format);
112 if (format == nullptr) {
113 throw mxvk::Exception(std::format("3dmath_texture: failed to query PNG format '{}': {}", path, SDL_GetError()));
114 }
115
116 Texture texture;
117 texture.width = rgba->w;
118 texture.height = rgba->h;
119 texture.pixels.resize(static_cast<std::size_t>(texture.width * texture.height));
120
121 for (int y = 0; y < texture.height; ++y) {
122 const auto *row = static_cast<const std::uint8_t *>(rgba->pixels) + (static_cast<std::size_t>(y) * static_cast<std::size_t>(rgba->pitch));
123 const auto *src = reinterpret_cast<const std::uint32_t *>(row);
124 for (int x = 0; x < texture.width; ++x) {
125 std::uint8_t r = 0;
126 std::uint8_t g = 0;
127 std::uint8_t b = 0;
128 std::uint8_t a = 0;
129 SDL_GetRGBA(src[x], format, nullptr, &r, &g, &b, &a);
130 texture.pixels[static_cast<std::size_t>(y * texture.width + x)] = (static_cast<mxvk::MXCOLOR>(a) << 24U) | (static_cast<mxvk::MXCOLOR>(r) << 16U) | (static_cast<mxvk::MXCOLOR>(g) << 8U) | static_cast<mxvk::MXCOLOR>(b);
131 }
132 }
133
134 return texture;
135 }

◆ load_texture() [3/3]

Texture anonymous_namespace{main.cpp}::load_texture ( const std::string & path,
bool generate_mipmaps = false )
nodiscard

Definition at line 268 of file main.cpp.

268 {
269 SurfacePtr loaded(mxvk::LoadPNG(path.c_str()));
270 if (!loaded) {
271 throw mxvk::Exception(std::format("3dmath_puzzle_drop: failed to load PNG '{}'", path));
272 }
273 SurfacePtr rgba(SDL_ConvertSurface(loaded.get(), SDL_PIXELFORMAT_RGBA32));
274 if (!rgba) {
275 throw mxvk::Exception(std::format("3dmath_puzzle_drop: failed to convert PNG '{}': {}", path, SDL_GetError()));
276 }
277 const SDL_PixelFormatDetails *format = SDL_GetPixelFormatDetails(rgba->format);
278 if (format == nullptr) {
279 throw mxvk::Exception(std::format("3dmath_puzzle_drop: failed to query PNG format '{}'", path));
280 }
281
282 Texture texture;
283 texture.width = rgba->w;
284 texture.height = rgba->h;
285 texture.pixels.resize(static_cast<std::size_t>(texture.width * texture.height));
286 for (int y = 0; y < texture.height; ++y) {
287 const auto *row = static_cast<const std::uint8_t *>(rgba->pixels) + static_cast<std::size_t>(y * rgba->pitch);
288 const auto *source = reinterpret_cast<const std::uint32_t *>(row);
289 for (int x = 0; x < texture.width; ++x) {
290 std::uint8_t red = 0;
291 std::uint8_t green = 0;
292 std::uint8_t blue = 0;
293 std::uint8_t alpha = 0;
294 SDL_GetRGBA(source[x], format, nullptr, &red, &green, &blue, &alpha);
295 texture.pixels[static_cast<std::size_t>(y * texture.width + x)] = (static_cast<mxvk::MXCOLOR>(alpha) << 24U) | (static_cast<mxvk::MXCOLOR>(red) << 16U) | (static_cast<mxvk::MXCOLOR>(green) << 8U) | static_cast<mxvk::MXCOLOR>(blue);
296 }
297 }
298 if (generate_mipmaps) {
299 build_mipmaps(texture);
300 }
301 return texture;
302 }
void build_mipmaps(Texture &texture)
Definition main.cpp:232

◆ model_path()

std::filesystem::path anonymous_namespace{main.cpp}::model_path ( const std::string & filename,
const std::string & asset_path )
nodiscard

Definition at line 115 of file main.cpp.

115 {
116 if (!filename.empty()) {
117 return filename;
118 }
119 return std::filesystem::path(asset_path) / "data" / DEFAULT_MODEL;
120 }
constexpr std::string_view DEFAULT_MODEL
Definition main.cpp:40

◆ pack_color()

mxvk::MXCOLOR anonymous_namespace{main.cpp}::pack_color ( std::uint32_t red,
std::uint32_t green,
std::uint32_t blue,
std::uint32_t alpha )
nodiscard

Definition at line 53 of file main.cpp.

53{ return ((alpha & 0xFFU) << 24U) | ((red & 0xFFU) << 16U) | ((green & 0xFFU) << 8U) | (blue & 0xFFU); }

◆ pyramid_path()

std::filesystem::path anonymous_namespace{main.cpp}::pyramid_path ( const std::string & asset_path)
nodiscard

Definition at line 41 of file main.cpp.

41{ return std::filesystem::path(asset_path) / "data" / "pyramid.plg"; }

◆ randFloat()

float anonymous_namespace{main.cpp}::randFloat ( float mn,
float mx )

Definition at line 82 of file main.cpp.

82 {
83 static std::random_device rd;
84 static std::default_random_engine eng(rd());
85 std::uniform_real_distribution<float> dist(mn, mx);
86 return dist(eng);
87 }

◆ resolve_texture_path()

std::string anonymous_namespace{main.cpp}::resolve_texture_path ( const Arguments & args)
nodiscard

Definition at line 78 of file main.cpp.

78 {
79 std::string texture_path = !args.filename.empty() ? args.filename : args.texture;
80 if (texture_path.empty()) {
81 throw mxvk::Exception("3dmath_texture: pass a PNG with --filename <file.png> or --texture <file.png>");
82 }
83
84 namespace fs = std::filesystem;
85 fs::path requested(texture_path);
86 if (requested.is_absolute() || fs::exists(requested)) {
87 return requested.string();
88 }
89
90 if (!args.path.empty()) {
91 const fs::path from_asset_path = fs::path(args.path) / requested;
92 if (fs::exists(from_asset_path)) {
93 return from_asset_path.string();
94 }
95 }
96
97 return requested.string();
98 }
std::string texture
Optional texture file path (--texture).
Definition argz.hpp:752
std::string filename
Optional input filename (--filename).
Definition argz.hpp:726
std::string path
Asset root; proc_args() defaults it to the executable directory.
Definition argz.hpp:723

◆ resolveAssetRoot()

std::string anonymous_namespace{main.cpp}::resolveAssetRoot ( const std::string & path)

Definition at line 136 of file main.cpp.

136 {
137 if (!path.empty() && path != "." && path != "./") {
138 return std::filesystem::path(path);
139 }
140 return std::filesystem::path(MASTERPIECE_ASSET_DIR);
141 }

◆ resolvePuzzleAssetRoot()

std::filesystem::path anonymous_namespace{main.cpp}::resolvePuzzleAssetRoot ( const std::filesystem::path & asset_root)

Definition at line 143 of file main.cpp.

143 {
144 const std::filesystem::path shared_root = asset_root.parent_path() / "puzzle";
145 if (std::filesystem::exists(shared_root / "data" / "gamebg.png")) {
146 return shared_root;
147 }
148 return asset_root;
149 }

◆ same_or_match()

bool anonymous_namespace{main.cpp}::same_or_match ( BlockType actual,
BlockType expected )
nodiscard

Definition at line 180 of file main.cpp.

180{ return actual == expected || actual == BlockType::Match; }

◆ scorePath()

std::filesystem::path anonymous_namespace{main.cpp}::scorePath ( const std::filesystem::path & asset_root)

Definition at line 151 of file main.cpp.

151{ return asset_root / "data" / "scores.dat"; }

◆ texture_index()

int anonymous_namespace{main.cpp}::texture_index ( BlockType type)
nodiscard

Definition at line 178 of file main.cpp.

178{ return is_play_block(type) ? static_cast<int>(type) - static_cast<int>(BlockType::Red1) : 0; }
bool is_play_block(BlockType type)
Definition main.cpp:176

◆ texture_path()

std::filesystem::path anonymous_namespace{main.cpp}::texture_path ( const std::string & filename,
const std::string & asset_path )
nodiscard

Definition at line 122 of file main.cpp.

122 {
123 const std::filesystem::path requested(filename);
124 if (requested.is_absolute() || std::filesystem::exists(requested)) {
125 return requested;
126 }
127
128 const std::filesystem::path from_asset_path = std::filesystem::path(asset_path) / requested;
129 if (std::filesystem::exists(from_asset_path)) {
130 return from_asset_path;
131 }
132 return requested;
133 }

◆ unwrap_horizontal_texcoords()

std::array< mxvk::vec2D, 3 > anonymous_namespace{main.cpp}::unwrap_horizontal_texcoords ( std::array< mxvk::vec2D, 3 > texcoords)
nodiscard

Definition at line 226 of file main.cpp.

226 {
227 if (!crosses_horizontal_texture_seam(texcoords)) {
228 return texcoords;
229 }
230
231 for (mxvk::vec2D &texcoord : texcoords) {
232 if (texcoord.x < 0.5f) {
233 texcoord.x += 1.0f;
234 }
235 }
236
237 for (std::size_t index = 0; index < texcoords.size(); ++index) {
238 if (texcoords[index].y > mxvk::EPSILON && texcoords[index].y < 1.0f - mxvk::EPSILON) {
239 continue;
240 }
241
242 const std::size_t next = (index + 1) % texcoords.size();
243 const std::size_t previous = (index + texcoords.size() - 1) % texcoords.size();
244 texcoords[index].x = (texcoords[next].x + texcoords[previous].x) * 0.5f;
245 }
246 return texcoords;
247 }
bool crosses_horizontal_texture_seam(const std::array< mxvk::vec2D, 3 > &texcoords)
Definition main.cpp:220

Variable Documentation

◆ AIM_LENGTH

float anonymous_namespace{main.cpp}::AIM_LENGTH = 2.0f
constexpr

Definition at line 42 of file main.cpp.

◆ AIM_THICKNESS_Y

float anonymous_namespace{main.cpp}::AIM_THICKNESS_Y = 0.008f
constexpr

Definition at line 43 of file main.cpp.

◆ AIM_THICKNESS_Z

float anonymous_namespace{main.cpp}::AIM_THICKNESS_Z = 0.015f
constexpr

Definition at line 44 of file main.cpp.

◆ APP_NAME

std::string_view anonymous_namespace{main.cpp}::APP_NAME = "3dmath_plg_loader"
constexpr

Definition at line 38 of file main.cpp.

◆ BACKEND_NAME

std::string_view anonymous_namespace{main.cpp}::BACKEND_NAME = "native"
constexpr

Definition at line 257 of file main.cpp.

◆ BACKGROUND_COLOR

mxvk::MXCOLOR anonymous_namespace{main.cpp}::BACKGROUND_COLOR = mxvk::MXVK_RGB(3, 4, 8)
constexpr

Definition at line 43 of file main.cpp.

◆ BALL_COLORS

const std::array<glm::vec3, NUM_BALLS> anonymous_namespace{main.cpp}::BALL_COLORS
Initial value:
= {
glm::vec3{1.0f, 1.0f, 1.0f},
glm::vec3{1.0f, 0.84f, 0.0f},
glm::vec3{0.0f, 0.0f, 0.8f},
glm::vec3{0.9f, 0.0f, 0.0f},
glm::vec3{0.5f, 0.0f, 0.5f},
glm::vec3{1.0f, 0.5f, 0.0f},
glm::vec3{0.0f, 0.5f, 0.0f},
glm::vec3{0.55f, 0.0f, 0.0f},
glm::vec3{0.1f, 0.1f, 0.1f},
glm::vec3{1.0f, 0.84f, 0.0f},
glm::vec3{0.0f, 0.0f, 0.8f},
glm::vec3{0.9f, 0.0f, 0.0f},
glm::vec3{0.5f, 0.0f, 0.5f},
glm::vec3{1.0f, 0.5f, 0.0f},
glm::vec3{0.0f, 0.5f, 0.0f},
glm::vec3{0.55f, 0.0f, 0.0f},
}

Definition at line 63 of file main.cpp.

◆ BALL_RADIUS

float anonymous_namespace{main.cpp}::BALL_RADIUS = 0.14f
constexpr

Definition at line 35 of file main.cpp.

◆ base_height

int anonymous_namespace{main.cpp}::base_height = 1080
constexpr

Definition at line 35 of file main.cpp.

◆ base_width

int anonymous_namespace{main.cpp}::base_width = 1440
constexpr

Definition at line 34 of file main.cpp.

◆ BLOCK_HALF_EXTENT

float anonymous_namespace{main.cpp}::BLOCK_HALF_EXTENT = 0.064f
constexpr

Definition at line 38 of file main.cpp.

◆ BLOCK_SPACING

float anonymous_namespace{main.cpp}::BLOCK_SPACING = 0.145f
constexpr

Definition at line 37 of file main.cpp.

◆ BLOCK_TEXTURE_FILES

std::array<const char *, 10> anonymous_namespace{main.cpp}::BLOCK_TEXTURE_FILES
constexpr
Initial value:
{
"red1.png",
"red2.png",
"red3.png",
"green1.png",
"green2.png",
"green3.png",
"blue1.png",
"blue2.png",
"blue3.png",
"red3.png",
}

Definition at line 43 of file main.cpp.

◆ board_cols

int anonymous_namespace{main.cpp}::board_cols = 8
constexpr

Definition at line 31 of file main.cpp.

◆ BOARD_HEIGHT

int anonymous_namespace{main.cpp}::BOARD_HEIGHT = 22
constexpr

Definition at line 33 of file main.cpp.

◆ board_rows

int anonymous_namespace{main.cpp}::board_rows = 18
constexpr

Definition at line 30 of file main.cpp.

◆ BOARD_WIDTH

int anonymous_namespace{main.cpp}::BOARD_WIDTH = 20
constexpr

Definition at line 32 of file main.cpp.

◆ CAM_BASE_TOTAL_SCALE

float anonymous_namespace{main.cpp}::CAM_BASE_TOTAL_SCALE = 1.359411f
constexpr

Definition at line 49 of file main.cpp.

◆ CAMERA_DISTANCE

float anonymous_namespace{main.cpp}::CAMERA_DISTANCE = 7.0f
constexpr

Definition at line 36 of file main.cpp.

◆ CAMERA_ZOOM_STEP

float anonymous_namespace{main.cpp}::CAMERA_ZOOM_STEP = 0.45f
constexpr

Definition at line 251 of file main.cpp.

◆ COURT_HALF_HEIGHT

float anonymous_namespace{main.cpp}::COURT_HALF_HEIGHT = 1.45f
constexpr

Definition at line 31 of file main.cpp.

◆ COURT_HALF_WIDTH

float anonymous_namespace{main.cpp}::COURT_HALF_WIDTH = 2.65f
constexpr

Definition at line 30 of file main.cpp.

◆ CUE_LENGTH

float anonymous_namespace{main.cpp}::CUE_LENGTH = 2.5f
constexpr

Definition at line 40 of file main.cpp.

◆ CUE_THICKNESS

float anonymous_namespace{main.cpp}::CUE_THICKNESS = 0.03f
constexpr

Definition at line 41 of file main.cpp.

◆ DEFAULT_FRAME_HEIGHT

int anonymous_namespace{main.cpp}::DEFAULT_FRAME_HEIGHT = 240
constexpr

Definition at line 27 of file main.cpp.

◆ DEFAULT_FRAME_WIDTH

int anonymous_namespace{main.cpp}::DEFAULT_FRAME_WIDTH = 320
constexpr

Definition at line 26 of file main.cpp.

◆ DEFAULT_MODEL

std::string_view anonymous_namespace{main.cpp}::DEFAULT_MODEL = "sphere.plg"
constexpr

Definition at line 40 of file main.cpp.

◆ FALL_SECONDS

std::array<float, 3> anonymous_namespace{main.cpp}::FALL_SECONDS {0.86f, 0.68f, 0.50f}
constexpr

Definition at line 42 of file main.cpp.

◆ flash_time_ms

int anonymous_namespace{main.cpp}::flash_time_ms = 180
constexpr

Definition at line 48 of file main.cpp.

◆ FRAME_GAP

float anonymous_namespace{main.cpp}::FRAME_GAP = 0.016f
constexpr

Definition at line 40 of file main.cpp.

◆ FRAME_HALF_EXTENT

float anonymous_namespace{main.cpp}::FRAME_HALF_EXTENT = BLOCK_HALF_EXTENT * 0.72f
constexpr

Definition at line 39 of file main.cpp.

◆ FRICTION

float anonymous_namespace{main.cpp}::FRICTION = 0.9988f
constexpr

Definition at line 46 of file main.cpp.

◆ game_base_height

int anonymous_namespace{main.cpp}::game_base_height = 480
constexpr

Definition at line 37 of file main.cpp.

◆ game_base_width

int anonymous_namespace{main.cpp}::game_base_width = 640
constexpr

Definition at line 36 of file main.cpp.

◆ game_block_height

int anonymous_namespace{main.cpp}::game_block_height = 14
constexpr

Definition at line 41 of file main.cpp.

◆ game_block_spacing

int anonymous_namespace{main.cpp}::game_block_spacing = 1
constexpr

Definition at line 42 of file main.cpp.

◆ game_block_width

int anonymous_namespace{main.cpp}::game_block_width = 31
constexpr

Definition at line 40 of file main.cpp.

◆ game_board_start_x

int anonymous_namespace{main.cpp}::game_board_start_x = 184
constexpr

Definition at line 38 of file main.cpp.

◆ game_board_start_y

int anonymous_namespace{main.cpp}::game_board_start_y = 78
constexpr

Definition at line 39 of file main.cpp.

◆ game_next_panel_x

int anonymous_namespace{main.cpp}::game_next_panel_x = 450
constexpr

Definition at line 44 of file main.cpp.

◆ game_next_panel_y

int anonymous_namespace{main.cpp}::game_next_panel_y = 180
constexpr

Definition at line 45 of file main.cpp.

◆ GRID_DEFAULT_CAMERA_DISTANCE

float anonymous_namespace{main.cpp}::GRID_DEFAULT_CAMERA_DISTANCE = 2.45f
constexpr

Definition at line 62 of file main.cpp.

◆ GRID_MAX_CAMERA_DISTANCE

float anonymous_namespace{main.cpp}::GRID_MAX_CAMERA_DISTANCE = 9.0f
constexpr

Definition at line 61 of file main.cpp.

◆ GRID_MAX_PITCH

float anonymous_namespace{main.cpp}::GRID_MAX_PITCH = 70.0f
constexpr

Definition at line 59 of file main.cpp.

◆ GRID_MIN_CAMERA_DISTANCE

float anonymous_namespace{main.cpp}::GRID_MIN_CAMERA_DISTANCE = 1.65f
constexpr

Definition at line 60 of file main.cpp.

◆ GRID_MIN_PITCH

float anonymous_namespace{main.cpp}::GRID_MIN_PITCH = -70.0f
constexpr

Definition at line 58 of file main.cpp.

◆ GRID_PITCH_SPEED

float anonymous_namespace{main.cpp}::GRID_PITCH_SPEED = 90.0f
constexpr

Definition at line 56 of file main.cpp.

◆ GRID_VERTICAL_GAP

int anonymous_namespace{main.cpp}::GRID_VERTICAL_GAP = 5
constexpr

Definition at line 43 of file main.cpp.

◆ GRID_YAW_SPEED

float anonymous_namespace{main.cpp}::GRID_YAW_SPEED = 115.0f
constexpr

Definition at line 55 of file main.cpp.

◆ GRID_ZOOM_SPEED

float anonymous_namespace{main.cpp}::GRID_ZOOM_SPEED = 3.2f
constexpr

Definition at line 57 of file main.cpp.

◆ joy_repeat_delay_ms

Uint32 anonymous_namespace{main.cpp}::joy_repeat_delay_ms = 180
constexpr

Definition at line 52 of file main.cpp.

◆ joystick_dead_zone

Sint16 anonymous_namespace{main.cpp}::joystick_dead_zone = 16000
constexpr

Definition at line 53 of file main.cpp.

◆ LEVEL_COUNT

int anonymous_namespace{main.cpp}::LEVEL_COUNT = 8
constexpr

Definition at line 36 of file main.cpp.

◆ lines_per_speedup

int anonymous_namespace{main.cpp}::lines_per_speedup = 10
constexpr

Definition at line 49 of file main.cpp.

◆ MAX_CAMERA_DISTANCE

float anonymous_namespace{main.cpp}::MAX_CAMERA_DISTANCE = 12.0f
constexpr

Definition at line 250 of file main.cpp.

◆ max_name_length

int anonymous_namespace{main.cpp}::max_name_length = 16
constexpr

Definition at line 51 of file main.cpp.

◆ MAX_PITCH_DEGREES

float anonymous_namespace{main.cpp}::MAX_PITCH_DEGREES = 89.0f
constexpr

Definition at line 253 of file main.cpp.

◆ MAX_POWER

float anonymous_namespace{main.cpp}::MAX_POWER = 1.5f
constexpr

Definition at line 48 of file main.cpp.

◆ max_scores

int anonymous_namespace{main.cpp}::max_scores = 8
constexpr

Definition at line 33 of file main.cpp.

◆ menu_item_count

int anonymous_namespace{main.cpp}::menu_item_count = 4
constexpr

Definition at line 46 of file main.cpp.

◆ MIN_CAMERA_DISTANCE

float anonymous_namespace{main.cpp}::MIN_CAMERA_DISTANCE = 2.5f
constexpr

Definition at line 249 of file main.cpp.

◆ MIN_SPEED

float anonymous_namespace{main.cpp}::MIN_SPEED = 0.001f
constexpr

Definition at line 47 of file main.cpp.

◆ MODEL_FORMAT

std::string_view anonymous_namespace{main.cpp}::MODEL_FORMAT = "PLG"
constexpr

Definition at line 39 of file main.cpp.

◆ MODEL_SCALE

float anonymous_namespace{main.cpp}::MODEL_SCALE = 2.0f
constexpr

Definition at line 42 of file main.cpp.

◆ MOUSE_ROTATION_SENSITIVITY

float anonymous_namespace{main.cpp}::MOUSE_ROTATION_SENSITIVITY = 0.35f
constexpr

Definition at line 252 of file main.cpp.

◆ NUM_BALLS

int anonymous_namespace{main.cpp}::NUM_BALLS = 16
constexpr

Definition at line 45 of file main.cpp.

◆ PADDLE_HALF_HEIGHT

float anonymous_namespace{main.cpp}::PADDLE_HALF_HEIGHT = 0.42f
constexpr

Definition at line 34 of file main.cpp.

◆ PADDLE_HALF_WIDTH

float anonymous_namespace{main.cpp}::PADDLE_HALF_WIDTH = 0.12f
constexpr

Definition at line 33 of file main.cpp.

◆ PADDLE_X

float anonymous_namespace{main.cpp}::PADDLE_X = 2.25f
constexpr

Definition at line 32 of file main.cpp.

◆ PI

float anonymous_namespace{main.cpp}::PI = 3.14159265358979323846f
constexpr

Definition at line 51 of file main.cpp.

◆ piece_height

int anonymous_namespace{main.cpp}::piece_height = 3
constexpr

Definition at line 32 of file main.cpp.

◆ POCKET_INSET

float anonymous_namespace{main.cpp}::POCKET_INSET = 0.25f
constexpr

Definition at line 53 of file main.cpp.

◆ POCKET_R

float anonymous_namespace{main.cpp}::POCKET_R = 0.25f
constexpr

Definition at line 38 of file main.cpp.

◆ POCKETS

const std::array<glm::vec2, 6> anonymous_namespace{main.cpp}::POCKETS
Initial value:
= {
glm::vec2{0.0f, TABLE_HALF_H - 0.15f},
glm::vec2{0.0f, -TABLE_HALF_H + 0.15f},
}
constexpr float POCKET_INSET
Definition main.cpp:53
constexpr float TABLE_HALF_H
Definition main.cpp:37
constexpr float TABLE_HALF_W
Definition main.cpp:36

Definition at line 54 of file main.cpp.

◆ score_points_per_match

int anonymous_namespace{main.cpp}::score_points_per_match = 6
constexpr

Definition at line 50 of file main.cpp.

◆ SINK_DURATION

float anonymous_namespace{main.cpp}::SINK_DURATION = 0.45f
constexpr

Definition at line 50 of file main.cpp.

◆ TABLE_H

float anonymous_namespace{main.cpp}::TABLE_H = 6.0f
constexpr

Definition at line 35 of file main.cpp.

◆ TABLE_HALF_H

float anonymous_namespace{main.cpp}::TABLE_HALF_H = TABLE_H / 2.0f
constexpr

Definition at line 37 of file main.cpp.

◆ TABLE_HALF_W

float anonymous_namespace{main.cpp}::TABLE_HALF_W = TABLE_W / 2.0f
constexpr

Definition at line 36 of file main.cpp.

◆ TABLE_W

float anonymous_namespace{main.cpp}::TABLE_W = 12.0f
constexpr

Definition at line 34 of file main.cpp.

◆ title_screen_time_ms

int anonymous_namespace{main.cpp}::title_screen_time_ms = 1500
constexpr

Definition at line 47 of file main.cpp.

◆ transparent_black

mxvk::MXCOLOR anonymous_namespace{main.cpp}::transparent_black = 0x00000000U
constexpr

Definition at line 54 of file main.cpp.

◆ WINDOW_HEIGHT

int anonymous_namespace{main.cpp}::WINDOW_HEIGHT = 1080
constexpr

Definition at line 29 of file main.cpp.

◆ WINDOW_TITLE

std::string_view anonymous_namespace{main.cpp}::WINDOW_TITLE = "MXVK 3D Math PLG Loader"
constexpr

Definition at line 41 of file main.cpp.

◆ WINDOW_WIDTH

int anonymous_namespace{main.cpp}::WINDOW_WIDTH = 1440
constexpr

Definition at line 28 of file main.cpp.