From 6cbe1e24007f306c8a8500e9df888ae0f660be00 Mon Sep 17 00:00:00 2001 From: Erik Sohns Date: Wed, 3 Jan 2024 16:50:35 +0100 Subject: [PATCH 1/3] - add #include ; required to compile on my Win32 system - add dist() method to vx2d vector class - remove renderer->ClearBuffer() call during display; saves some cycles and required for some effects --> please consider for merging into the mainline ! --- olcPixelGameEngine.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/olcPixelGameEngine.h b/olcPixelGameEngine.h index 62a4d8a1..9c5117d5 100644 --- a/olcPixelGameEngine.h +++ b/olcPixelGameEngine.h @@ -526,6 +526,7 @@ int main() #include #undef _WINSOCKAPI_ + #include #endif #if defined(OLC_PLATFORM_X11) @@ -690,6 +691,7 @@ namespace olc v2d_generic lerp(const v2d_generic& v1, const double t) { return this->operator*(T(1.0 - t)) + (v1 * T(t)); } T dot(const v2d_generic& rhs) const { return this->x * rhs.x + this->y * rhs.y; } T cross(const v2d_generic& rhs) const { return this->x * rhs.y - this->y * rhs.x; } + T dist(const v2d_generic& rhs) const { return std::sqrt(this->x - rhs.x * this->x - rhs.x + this->y - rhs.y * this->y - rhs.y); } v2d_generic operator + (const v2d_generic& rhs) const { return v2d_generic(this->x + rhs.x, this->y + rhs.y); } v2d_generic operator - (const v2d_generic& rhs) const { return v2d_generic(this->x - rhs.x, this->y - rhs.y); } v2d_generic operator * (const T& rhs) const { return v2d_generic(this->x * rhs, this->y * rhs); } @@ -3896,7 +3898,7 @@ namespace olc // Display Frame renderer->UpdateViewport(vViewPos, vViewSize); - renderer->ClearBuffer(olc::BLACK, true); + //renderer->ClearBuffer(olc::BLACK, true); // Layer 0 must always exist vLayers[0].bUpdate = true; From 5ab26d09b9b7f89e0034d583de16f4944b0855ec Mon Sep 17 00:00:00 2001 From: Erik Sohns Date: Wed, 3 Jan 2024 17:13:03 +0100 Subject: [PATCH 2/3] added some brackets for precedence disambiguation (not sure if this is required) --- olcPixelGameEngine.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/olcPixelGameEngine.h b/olcPixelGameEngine.h index 9c5117d5..0c81da84 100644 --- a/olcPixelGameEngine.h +++ b/olcPixelGameEngine.h @@ -691,7 +691,7 @@ namespace olc v2d_generic lerp(const v2d_generic& v1, const double t) { return this->operator*(T(1.0 - t)) + (v1 * T(t)); } T dot(const v2d_generic& rhs) const { return this->x * rhs.x + this->y * rhs.y; } T cross(const v2d_generic& rhs) const { return this->x * rhs.y - this->y * rhs.x; } - T dist(const v2d_generic& rhs) const { return std::sqrt(this->x - rhs.x * this->x - rhs.x + this->y - rhs.y * this->y - rhs.y); } + T dist(const v2d_generic& rhs) const { return std::sqrt((this->x - rhs.x) * (this->x - rhs.x) + (this->y - rhs.y) * (this->y - rhs.y)); } v2d_generic operator + (const v2d_generic& rhs) const { return v2d_generic(this->x + rhs.x, this->y + rhs.y); } v2d_generic operator - (const v2d_generic& rhs) const { return v2d_generic(this->x - rhs.x, this->y - rhs.y); } v2d_generic operator * (const T& rhs) const { return v2d_generic(this->x * rhs, this->y * rhs); } From 282438dee9e0a16061dfa980e3d1ab05578ea1c1 Mon Sep 17 00:00:00 2001 From: Erik Sohns Date: Wed, 3 Jan 2024 17:19:21 +0100 Subject: [PATCH 3/3] cast result back to T (see v2d_generic::mag()). --- olcPixelGameEngine.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/olcPixelGameEngine.h b/olcPixelGameEngine.h index 0c81da84..9222218a 100644 --- a/olcPixelGameEngine.h +++ b/olcPixelGameEngine.h @@ -691,7 +691,7 @@ namespace olc v2d_generic lerp(const v2d_generic& v1, const double t) { return this->operator*(T(1.0 - t)) + (v1 * T(t)); } T dot(const v2d_generic& rhs) const { return this->x * rhs.x + this->y * rhs.y; } T cross(const v2d_generic& rhs) const { return this->x * rhs.y - this->y * rhs.x; } - T dist(const v2d_generic& rhs) const { return std::sqrt((this->x - rhs.x) * (this->x - rhs.x) + (this->y - rhs.y) * (this->y - rhs.y)); } + T dist(const v2d_generic& rhs) const { return T(std::sqrt((this->x - rhs.x) * (this->x - rhs.x) + (this->y - rhs.y) * (this->y - rhs.y))); } v2d_generic operator + (const v2d_generic& rhs) const { return v2d_generic(this->x + rhs.x, this->y + rhs.y); } v2d_generic operator - (const v2d_generic& rhs) const { return v2d_generic(this->x - rhs.x, this->y - rhs.y); } v2d_generic operator * (const T& rhs) const { return v2d_generic(this->x * rhs, this->y * rhs); }