Skip to content

Commit

Permalink
Part of CCoronas (#583)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pirulax authored Jul 16, 2023
1 parent f652cb7 commit 8af1be2
Show file tree
Hide file tree
Showing 19 changed files with 605 additions and 63 deletions.
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@
[submodule "libs/tracy"]
path = libs/tracy
url = git@github.com:wolfpld/tracy.git
[submodule "libs/spdlog"]
path = libs/spdlog
url = git@github.com:gabime/spdlog.git

8 changes: 7 additions & 1 deletion source/Base.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,15 @@ template<typename... Ts>
* @tparam T The type of the variable
* @param Addr The address of it
*/
template<typename T>
T& StaticRef(uintptr addr) {
return *reinterpret_cast<T*>(addr);
}

// TODO: Replace this with the one above
template<typename T, uintptr Addr>
T& StaticRef() {
return *reinterpret_cast<T*>(Addr);
return StaticRef<T>(Addr);
}

#define _IGNORED_
Expand Down
12 changes: 5 additions & 7 deletions source/extensions/FixedFloat.hpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
#pragma once

//! Fixed point number (With implicit conversion to float)
template<typename T, float CompressValue>
requires std::is_integral_v<T>
template<std::integral T, float CompressValue>
class FixedFloat {
T value{};

public:
constexpr FixedFloat() = default;
constexpr FixedFloat(float X) : value(static_cast<T>(X * CompressValue)) {}
explicit constexpr FixedFloat(T X) : value(X) {}
constexpr FixedFloat(float v) : value(static_cast<T>(v * CompressValue)) {}
template<std::integral Y>
constexpr FixedFloat(Y x) : value(x) {}

constexpr operator float() const {
return static_cast<float>(value) / CompressValue;
}
constexpr operator float() const { return static_cast<float>(value) / CompressValue; }
};
5 changes: 2 additions & 3 deletions source/extensions/FixedVector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
template<typename T, float CompressValue>
struct FixedVector {
constexpr FixedVector() = default;
constexpr FixedVector(float X, float Y, float Z) : x(X), y(Y), z(Z) {}
constexpr FixedVector(CVector v3d) : x(v3d.x), y(v3d.y), z(v3d.z) {}
explicit constexpr FixedVector(T X, T Y, T Z) : x(X), y(Y), z(Z) {}
constexpr FixedVector(T X, T Y, T Z) : x(X), y(Y), z(Z) {}

constexpr operator CVector() const { return CVector{ x, y, z }; }

Expand All @@ -20,7 +19,7 @@ struct FixedVector2D {
constexpr FixedVector2D() = default;
constexpr FixedVector2D(float X, float Y) : x(X), y(Y) {}
constexpr FixedVector2D(CVector2D v2d) : FixedVector2D{v2d.x, v2d.y} {}
explicit constexpr FixedVector2D(T X, T Y) : FixedVector2D{ x, y } {}
constexpr FixedVector2D(T X, T Y) : FixedVector2D{ x, y } {}

constexpr operator CVector2D() const { return { x, y }; }

Expand Down
6 changes: 6 additions & 0 deletions source/game_sa/Camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ enum class eSwitchType : uint16 {
JUMPCUT
};

/* todo:
LOOKING_BEHIND = 0x0,
LOOKING_LEFT = 0x1,
LOOKING_RIGHT = 0x2,
LOOKING_FORWARD = 0x3,
*/
enum eLookingDirection {
LOOKING_DIRECTION_UNKNOWN_1 = 0,
LOOKING_DIRECTION_BEHIND = 1,
Expand Down
8 changes: 0 additions & 8 deletions source/game_sa/Core/Vector2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,3 @@ CVector2D CVector2D::RotatedBy(float rad) const {
x * s - y * c,
};
}

CVector2D CVector2D::GetPerpRight() const {
return { y, -x }; // `RotatedBy(-PI / 2)` done manually, rotate by +PI/2 would be `{-y, x}`
}

CVector2D CVector2D::GetPerpLeft() const {
return { -y, x };
}
4 changes: 2 additions & 2 deletions source/game_sa/Core/Vector2D.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,11 @@ class CVector2D : public RwV2d {
//! Get vector perpendicular to `*this` on the right side (Same direction `*this` rotated by -90)
//! Also see `GetPerpLeft` and `RotatedBy`
//! (This sometimes is also called a 2D cross product https://stackoverflow.com/questions/243945 )
CVector2D GetPerpRight() const;
CVector2D GetPerpRight() const { return { y, -x }; }

//! Get vector perpendicular to `*this` on the left side (Same direction `*this` rotated by 90)
//! Also see `GetPerpRight` and `RotatedBy`
CVector2D GetPerpLeft() const;
CVector2D GetPerpLeft() const { return { -y, x }; }

/*!
* @notsa
Expand Down
Loading

0 comments on commit 8af1be2

Please sign in to comment.