MXVK Vulkan Framework 0.24.0
C++20 Vulkan rendering framework for practical 2D and 3D application development with SDL3.
Loading...
Searching...
No Matches
defender_types.hpp
Go to the documentation of this file.
1#ifndef DEFENDER_TYPES_HPP
2#define DEFENDER_TYPES_HPP
3
4#include <SDL3/SDL.h>
5
6#include <cmath>
7
8#include <glm/glm.hpp>
9
10namespace defender {
11
12 constexpr int STAR_COUNT = 90000;
13 constexpr int MAX_PROJECTILES = 64;
14 constexpr int MAX_UFOS = 6;
15 constexpr int MAX_ASTEROIDS = 5;
16 constexpr int UFO_ANIMATION_FRAMES = 8;
17 constexpr int UFO_SPRITE_SET_COUNT = 3;
18 constexpr float SHIP_MODEL_SCALE = 1.65f;
19 constexpr float PROJECTILE_SPEED = 118.0f;
20 constexpr float PROJECTILE_LIFETIME = 0.72f;
21 constexpr int FIRE_COOLDOWN = 4;
22 constexpr glm::vec4 PROJECTILE_COLOR{1.0f, 0.96f, 0.60f, 1.0f};
23 constexpr float WORLD_TOP = 8.5f;
24 constexpr float WORLD_BOTTOM = -8.5f;
25 constexpr float WORLD_WIDTH = 160.0f;
26 constexpr float WORLD_HALF_WIDTH = WORLD_WIDTH * 0.5f;
27 constexpr int RADAR_TOP = 42;
28 constexpr int RADAR_HEIGHT = 104;
30 constexpr float CAMERA_DISTANCE = 26.0f;
31 constexpr float CAMERA_HEIGHT = 1.6f;
32 constexpr float CAMERA_SCROLL_EDGE_FRACTION = 0.68f;
33 constexpr Sint16 CONTROLLER_DEAD_ZONE = 8000;
34 constexpr float CONTROLLER_AXIS_MAX = 32767.0f;
35
36 [[nodiscard]] inline float wrap_world_x(float x) {
37 x = std::fmod(x + WORLD_HALF_WIDTH, WORLD_WIDTH);
38 if (x < 0.0f) {
39 x += WORLD_WIDTH;
40 }
41 return x - WORLD_HALF_WIDTH;
42 }
43
44 [[nodiscard]] inline float wrapped_delta_x(float target, float origin) {
45 return wrap_world_x(target - origin);
46 }
47
48 [[nodiscard]] inline float nearest_world_x(float target, float origin) {
49 return origin + wrapped_delta_x(target, origin);
50 }
51
52 [[nodiscard]] inline glm::vec3 nearest_world_position(glm::vec3 position, float origin_x) {
53 position.x = nearest_world_x(position.x, origin_x);
54 return position;
55 }
56
57 [[nodiscard]] inline float terrain_height(float world_x) {
58 constexpr float TERRAIN_SEGMENT_WIDTH = 8.0f;
59 const float wrapped_x = wrap_world_x(world_x) + WORLD_HALF_WIDTH;
60 const int segment = static_cast<int>(std::floor(wrapped_x / TERRAIN_SEGMENT_WIDTH));
61 const float segment_progress = std::fmod(wrapped_x, TERRAIN_SEGMENT_WIDTH) / TERRAIN_SEGMENT_WIDTH;
62 const auto height_for = [](int index) {
63 const uint32_t hash = static_cast<uint32_t>(index) * 1103515245U + 12345U;
64 return WORLD_BOTTOM + 1.0f + static_cast<float>((hash >> 16U) % 7U) * 0.26f;
65 };
66 return std::lerp(height_for(segment), height_for(segment + 1), segment_progress);
67 }
68
69} // namespace defender
70
71#endif
constexpr int RADAR_TOP
glm::vec3 nearest_world_position(glm::vec3 position, float origin_x)
constexpr glm::vec4 PROJECTILE_COLOR
constexpr float PROJECTILE_LIFETIME
float nearest_world_x(float target, float origin)
float wrapped_delta_x(float target, float origin)
constexpr float CONTROLLER_AXIS_MAX
constexpr float WORLD_BOTTOM
constexpr float WORLD_TOP
float wrap_world_x(float x)
constexpr int MAX_UFOS
constexpr Sint16 CONTROLLER_DEAD_ZONE
constexpr int MAX_ASTEROIDS
float terrain_height(float world_x)
constexpr int STAR_COUNT
constexpr float SHIP_MODEL_SCALE
constexpr float WORLD_HALF_WIDTH
constexpr int FIRE_COOLDOWN
constexpr int UFO_SPRITE_SET_COUNT
constexpr int MAX_PROJECTILES
constexpr float CAMERA_SCROLL_EDGE_FRACTION
constexpr float CAMERA_DISTANCE
constexpr int RADAR_HEIGHT
constexpr int GAME_VIEWPORT_TOP
constexpr float PROJECTILE_SPEED
constexpr float WORLD_WIDTH
constexpr int UFO_ANIMATION_FRAMES
constexpr float CAMERA_HEIGHT