diff options
| author | fschildt <florian.schildt@protonmail.com> | 2025-10-01 14:08:24 +0200 |
|---|---|---|
| committer | fschildt <florian.schildt@protonmail.com> | 2025-10-01 14:09:13 +0200 |
| commit | c775ca6133d93ed97359a6a50bd94a5563c740de (patch) | |
| tree | 9d3efb1c7e7538ff9d5cae408d2c29f9dd3daeab /src/common | |
| parent | 41c2e2ecfcccf62b3c646980dd283848e33a8134 (diff) | |
general refactoring, prepare breakout game
Diffstat (limited to 'src/common')
| -rw-r--r-- | src/common/Font.cpp | 4 | ||||
| -rw-r--r-- | src/common/Font.hpp | 4 | ||||
| -rw-r--r-- | src/common/defs.hpp | 14 | ||||
| -rw-r--r-- | src/common/math.cpp | 95 | ||||
| -rw-r--r-- | src/common/math.hpp | 61 | ||||
| -rw-r--r-- | src/common/shapes.hpp | 16 |
6 files changed, 190 insertions, 4 deletions
diff --git a/src/common/Font.cpp b/src/common/Font.cpp index 31a6720..b5b177c 100644 --- a/src/common/Font.cpp +++ b/src/common/Font.cpp @@ -86,8 +86,8 @@ Font::LoadGlyph(Glyph& glyph, uint32_t codepoint) } delete[] bitmap_flipped; - glyph.bitmap.width = width; - glyph.bitmap.height = height; + glyph.bitmap.w = width; + glyph.bitmap.h = height; glyph.bitmap.pixels = std::unique_ptr<uint8_t>(bitmap_correct); diff --git a/src/common/Font.hpp b/src/common/Font.hpp index a594add..91afe06 100644 --- a/src/common/Font.hpp +++ b/src/common/Font.hpp @@ -5,8 +5,8 @@ struct MonoBitmap { - int32_t width; - int32_t height; + int32_t w; + int32_t h; std::unique_ptr<uint8_t> pixels; }; diff --git a/src/common/defs.hpp b/src/common/defs.hpp new file mode 100644 index 0000000..007d560 --- /dev/null +++ b/src/common/defs.hpp @@ -0,0 +1,14 @@ +#pragma once + +#include <cassert> +#include <cstdint> + + +#define ARRAY_COUNT(x) (sizeof(x) / sizeof(x[0])) + +#define InvalidDefaultCase assert(0) + +#define KIBIBYTES(x) ((x)*1024) +#define MEBIBYTES(x) ((x)*KIBIBYTES(1024)) +#define GIBIBYTES(x) ((x)*MEBIBYTES(1024)) + diff --git a/src/common/math.cpp b/src/common/math.cpp new file mode 100644 index 0000000..ba54f3a --- /dev/null +++ b/src/common/math.cpp @@ -0,0 +1,95 @@ +#include <common/math.hpp> + + +/* V2ST */ + +bool +V2ST::operator==(V2ST& b) +{ + bool result = this->x == b.x && this->y == b.y; + return result; +} + + + +/* V2F32 */ + +V2F32 +V2F32::operator/(float scalar) +{ + V2F32 result {}; + result.x = this->x / scalar; + result.y = this->y / scalar; + return result; +} + +V2F32 +V2F32::operator*(float scalar) +{ + V2F32 result {}; + result.x = this->x * scalar; + result.y = this->y * scalar; + return result; +} + +V2F32 V2F32::operator+(V2F32 other) { + V2F32 result {}; + result.x = this->x + other.x; + result.y = this->y + other.y; + return result; +} + + +/* V3F32 */ + +V3F32 V3F32::operator/(float scalar) { + V3F32 result = {}; + result.x = this->x / scalar; + result.y = this->y / scalar; + result.z = this->z / scalar; + return result; +} + +V3F32 V3F32::operator*(float scalar) { + V3F32 result = {}; + result.x = this->x * scalar; + result.y = this->y * scalar; + result.z = this->z * scalar; + return result; +} + + +/* V4F32 */ + +V4F32 +V4F32::operator/(float scalar) +{ + V4F32 result {}; + result.x = this->x / scalar; + result.y = this->y / scalar; + result.z = this->z / scalar; + result.w = this->w / scalar; + return result; +} + +V4F32 +V4F32::operator*(float scalar) +{ + V4F32 result {}; + result.x = this->x * scalar; + result.y = this->y * scalar; + result.z = this->z * scalar; + result.w = this->z * scalar; + return result; +} + + +/* V2I32 */ + +bool +V2I32::operator==(V2I32 other) +{ + bool result = x == other.x && y == other.y; + return result; +} + diff --git a/src/common/math.hpp b/src/common/math.hpp new file mode 100644 index 0000000..de856e8 --- /dev/null +++ b/src/common/math.hpp @@ -0,0 +1,61 @@ +#pragma once + + +#include <common/defs.hpp> + +#include <cstddef> +#include <cstdint> + + +struct V2ST { + size_t x; + size_t y; + + bool operator==(V2ST &b); + bool operator==(const V2ST& other) const { + return x == other.x && y == other.y; + } +}; + +struct V2F32 { + float x; + float y; + + V2F32 operator/(float scalar); + V2F32 operator*(float scalar); + V2F32 operator+(V2F32 other); +}; + +struct V3F32 { + float x; + float y; + float z; + + V3F32 operator/(float scalar); + V3F32 operator*(float scalar); +}; + +struct V4F32 { + float x; + float y; + float z; + float w; + + V4F32 operator/(float scalar); + V4F32 operator*(float scalar); +}; + +struct V2I32 { + int32_t x; + int32_t y; + + bool operator==(V2I32 other); +}; + +struct Color { + float r; + float g; + float b; + float a; +}; + diff --git a/src/common/shapes.hpp b/src/common/shapes.hpp new file mode 100644 index 0000000..b556b2b --- /dev/null +++ b/src/common/shapes.hpp @@ -0,0 +1,16 @@ +#pragma once + + +struct Rectangle { + float x0; + float y0; + float x1; + float y1; +}; + +struct Circle { + float x; + float y; + float r; +}; + |
