GIGA REFACTOR

This commit is contained in:
2022-03-02 18:51:42 +01:00
parent 553b2f6aad
commit 6df59b1487
92 changed files with 1807 additions and 1785 deletions

View File

@@ -6,8 +6,8 @@
namespace td {
namespace utils {
std::uint64_t inflate(const std::string& source, std::string& dest);
std::uint64_t deflate(const std::string& source, std::string& dest);
std::uint64_t Inflate(const std::string& source, std::string& dest);
std::uint64_t Deflate(const std::string& source, std::string& dest);
DataBuffer Compress(const DataBuffer& buffer);
DataBuffer Decompress(DataBuffer& buffer);

View File

@@ -7,63 +7,63 @@ constexpr float PI = 3.14159274101257324219;
/* Sine functions */
float easeInSine(float x);
float easeOutSine(float x);
float easeInOutSine(float x);
float EaseInSine(float x);
float EaseOutSine(float x);
float EaseInOutSine(float x);
/* Cubic functions */
float easeInCubic(float x);
float easeOutCubic(float x);
float easeInOutCubic(float x);
float EaseInCubic(float x);
float EaseOutCubic(float x);
float EaseInOutCubic(float x);
/* Quint functions */
float easeInQuint(float x);
float easeOutQuint(float x);
float easeInOutQuint(float x);
float EaseInQuint(float x);
float EaseOutQuint(float x);
float EaseInOutQuint(float x);
/* Circ functions */
float easeInCirc(float x);
float easeOutCirc(float x);
float easeInOutCirc(float x);
float EaseInCirc(float x);
float EaseOutCirc(float x);
float EaseInOutCirc(float x);
/* Elastic functions */
float easeInElastic(float x);
float easeOutElastic(float x);
float easeInOutElastic(float x);
float EaseInElastic(float x);
float EaseOutElastic(float x);
float EaseInOutElastic(float x);
/* Quad functions */
float easeInQuad(float x);
float easeOutQuad(float x);
float easeInOutQuad(float x);
float EaseInQuad(float x);
float EaseOutQuad(float x);
float EaseInOutQuad(float x);
/* Quart functions */
float easeInQuart(float x);
float easeOutQuart(float x);
float easeInOutQuart(float x);
float EaseInQuart(float x);
float EaseOutQuart(float x);
float EaseInOutQuart(float x);
/* Expo functions */
float easeInExpo(float x);
float easeOutExpo(float x);
float easeInOutExpo(float x);
float EaseInExpo(float x);
float EaseOutExpo(float x);
float EaseInOutExpo(float x);
/* Back functions */
float easeInBack(float x);
float easeOutBack(float x);
float easeInOutBack(float x);
float EaseInBack(float x);
float EaseOutBack(float x);
float EaseInOutBack(float x);
/* Bounce functions */
float easeInBounce(float x);
float easeOutBounce(float x);
float easeInOutBounce(float x);
float EaseInBounce(float x);
float EaseOutBounce(float x);
float EaseInOutBounce(float x);
} // namespace utils
} // namespace td

View File

@@ -13,20 +13,20 @@ protected:
std::vector<Listener*> m_Listeners;
public:
void bindListener(Listener* listener) {
void BindListener(Listener* listener) {
m_Listeners.push_back(listener);
}
void unbindListener(Listener* listener) {
void UnbindListener(Listener* listener) {
auto iter = std::find(m_Listeners.begin(), m_Listeners.end(), listener);
if(iter == m_Listeners.end()) return;
if (iter == m_Listeners.end()) return;
m_Listeners.erase(iter);
}
template <typename Func, typename... Args>
void notifyListeners(Func function, Args... args) {
void NotifyListeners(Func function, Args... args) {
for (Listener* listener : m_Listeners)
std::bind(function, listener, args...)();
}

View File

@@ -18,7 +18,7 @@ enum class Architecture {
Unknown,
};
inline Os getSystemOs() {
inline Os GetSystemOs() {
#if defined(_WIN32) || defined(_WIN64)
return Os::Windows;
#elif defined(__ANDROID__)
@@ -31,7 +31,7 @@ inline Os getSystemOs() {
#endif
}
inline Architecture getSystemArchitecture() {
inline Architecture GetSystemArchitecture() {
#if defined(_WIN64)
return Architecture::x86_64;
#elif defined(_WIN32)

View File

@@ -6,7 +6,7 @@ namespace td {
namespace utils {
template<typename NumberType>
NumberType getRandomInt(NumberType min, NumberType max) {
NumberType GetRandomInt(NumberType min, NumberType max) {
std::random_device randomDevice;
std::mt19937 generator(randomDevice());
std::uniform_int_distribution<NumberType> distrib(min, max);
@@ -14,7 +14,7 @@ NumberType getRandomInt(NumberType min, NumberType max) {
}
template<typename NumberType>
NumberType getRandomReal(NumberType min, NumberType max) {
NumberType GetRandomReal(NumberType min, NumberType max) {
std::random_device randomDevice;
std::mt19937 generator(randomDevice());
std::uniform_real_distribution<NumberType> distrib(min, max);

View File

@@ -13,14 +13,14 @@ public:
Point() : m_X(0), m_Y(0) {}
Point(float x, float y) : m_X(x), m_Y(y) {}
float getX() const { return m_X; }
float getY() const { return m_Y; }
float GetX() const { return m_X; }
float GetY() const { return m_Y; }
void setX(float x) { m_X = x; }
void setY(float y) { m_Y = y; }
void SetX(float x) { m_X = x; }
void SetY(float y) { m_Y = y; }
float distance(const Point& point) const;
float distanceSquared(const Point& point) const;
float Distance(const Point& point) const;
float DistanceSquared(const Point& point) const;
};
class Circle;
@@ -32,34 +32,34 @@ private:
public:
Rectangle() {}
const Point& getCenter() const { return m_Center; }
float getCenterX() const { return m_Center.getX(); }
float getCenterY() const { return m_Center.getY(); }
const Point& GetCenter() const { return m_Center; }
float GetCenterX() const { return m_Center.GetX(); }
float GetCenterY() const { return m_Center.GetY(); }
float getWidth() const { return m_Width; }
float getHeight() const { return m_Height; }
float GetWidth() const { return m_Width; }
float GetHeight() const { return m_Height; }
Point getTopLeft() const { return { m_Center.getX() - (m_Width / 2.0f), m_Center.getY() - (m_Height / 2.0f) }; }
Point getBottomRight() const { return { m_Center.getX() + (m_Width / 2.0f), m_Center.getY() + (m_Height / 2.0f) }; }
Point GetTopLeft() const { return { m_Center.GetX() - (m_Width / 2.0f), m_Center.GetY() - (m_Height / 2.0f) }; }
Point GetBottomRight() const { return { m_Center.GetX() + (m_Width / 2.0f), m_Center.GetY() + (m_Height / 2.0f) }; }
void setCenter(const Point& center) { m_Center = center; }
void setCenterX(float x) { m_Center.setX(x); }
void setCenterY(float y) { m_Center.setY(y); }
void SetCenter(const Point& center) { m_Center = center; }
void SetCenterX(float x) { m_Center.SetX(x); }
void SetCenterY(float y) { m_Center.SetY(y); }
void setSize(float width, float height) { setWidth(width); setHeight(height); }
void setSize(Point size) { setSize(size.getX(), size.getY()); }
Point getSize() { return { m_Width, m_Height }; }
void SetSize(float width, float height) { SetWidth(width); SetHeight(height); }
void SetSize(Point size) { SetSize(size.GetX(), size.GetY()); }
Point GetSize() { return { m_Width, m_Height }; }
void setWidth(float width) { m_Width = width; }
void setHeight(float height) { m_Height = height; }
void SetWidth(float width) { m_Width = width; }
void SetHeight(float height) { m_Height = height; }
bool collidesWith(const Point& point) const;
bool collidesWith(const Rectangle& rect) const;
bool collidesWith(const Circle& circle) const;
bool CollidesWith(const Point& point) const;
bool CollidesWith(const Rectangle& rect) const;
bool CollidesWith(const Circle& circle) const;
// distance from the closest side of the rectangle
float distance(const Circle& circle) const;
float distanceSquared(const Circle& circle) const;
float Distance(const Circle& circle) const;
float DistanceSquared(const Circle& circle) const;
};
class Circle {
@@ -70,25 +70,25 @@ public:
Circle(float x, float y, float radius) : m_Center(x, y), m_Radius(radius) {}
Circle() : m_Radius(0) {}
const Point& getCenter() const { return m_Center; }
float getCenterX() const { return m_Center.getX(); }
float getCenterY() const { return m_Center.getY(); }
const Point& GetCenter() const { return m_Center; }
float GetCenterX() const { return m_Center.GetX(); }
float GetCenterY() const { return m_Center.GetY(); }
float getRadius() const { return m_Radius; }
float GetRadius() const { return m_Radius; }
void setCenter(const Point& center) { m_Center = center; }
void setCenterX(float x) { m_Center.setX(x); }
void setCenterY(float y) { m_Center.setY(y); }
void SetCenter(const Point& center) { m_Center = center; }
void SetCenterX(float x) { m_Center.SetX(x); }
void SetCenterY(float y) { m_Center.SetY(y); }
void setRadius(float radius) { m_Radius = radius; }
void SetRadius(float radius) { m_Radius = radius; }
bool collidesWith(const Point& point) const;
bool collidesWith(const Rectangle& rect) const;
bool collidesWith(const Circle& circle) const;
bool CollidesWith(const Point& point) const;
bool CollidesWith(const Rectangle& rect) const;
bool CollidesWith(const Circle& circle) const;
// distance from the closest side of the rectangle
float distance(const Rectangle& rect) const;
float distanceSquared(const Rectangle& rect) const;
float Distance(const Rectangle& rect) const;
float DistanceSquared(const Rectangle& rect) const;
};
} // namespace shape

View File

@@ -6,7 +6,7 @@
namespace td {
namespace utils {
std::uint64_t getTime();
std::uint64_t GetTime();
typedef std::function<void()> TimerExecFunction;
@@ -17,23 +17,23 @@ private:
std::uint64_t m_Interval;
TimerExecFunction m_Function;
std::uint64_t m_LastTime = getTime();
std::uint64_t m_LastTime = GetTime();
std::uint64_t m_InternalTime = 0;
public:
AutoTimer() : m_Interval(0), m_Function(nullptr) {}
AutoTimer(std::uint64_t interval) : m_Interval(interval), m_Function(nullptr) {}
AutoTimer(std::uint64_t interval, TimerExecFunction callback) : m_Interval(interval), m_Function(callback) {}
void update();
void update(std::uint64_t delta);
void Update();
void Update(std::uint64_t delta);
void reset();
void Reset();
void setInterval(std::uint64_t newInterval) { m_Interval = newInterval; }
std::uint64_t getInterval() const { return m_Interval; }
void SetInterval(std::uint64_t newInterval) { m_Interval = newInterval; }
std::uint64_t GetInterval() const { return m_Interval; }
void setCallbackFunction(TimerExecFunction newCallback) { m_Function = newCallback; }
TimerExecFunction getCallbackFunction() const { return m_Function; }
void SetCallbackFunction(TimerExecFunction newCallback) { m_Function = newCallback; }
TimerExecFunction GetCallbackFunction() const { return m_Function; }
};
// utililty class to call function at regular period of time
@@ -45,12 +45,12 @@ public:
Timer() : m_Interval(0) {}
Timer(std::uint64_t interval) : m_Interval(interval) {}
bool update(std::uint64_t delta);
bool Update(std::uint64_t delta);
void reset();
void Reset();
void setInterval(std::uint64_t newInterval) { m_Interval = newInterval; }
std::uint64_t getInterval() const { return m_Interval; }
void SetInterval(std::uint64_t newInterval) { m_Interval = newInterval; }
std::uint64_t GetInterval() const { return m_Interval; }
};
// utililty class to call function at regular period of time with a cooldown (used for towers and mobs )
@@ -62,14 +62,14 @@ public:
CooldownTimer() : m_Cooldown(0), m_CooldownTime(0) {}
CooldownTimer(std::uint64_t cooldown) : m_Cooldown(0), m_CooldownTime(cooldown) {}
bool update(std::uint64_t delta);
bool Update(std::uint64_t delta);
void applyCooldown();
void ApplyCooldown();
void reset();
void Reset();
void setCooldown(std::uint64_t newCooldown) { m_CooldownTime = newCooldown; }
std::uint64_t getCooldown() const { return m_CooldownTime; }
void SetCooldown(std::uint64_t newCooldown) { m_CooldownTime = newCooldown; }
std::uint64_t GetCooldown() const { return m_CooldownTime; }
};
} // namespace utils