From 0dd8ca5ae9a50c4f6393f6efaee35e94bda6d466 Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Wed, 5 Jun 2024 18:24:20 -0500 Subject: [PATCH] Split up implementation of Pixel from the header file so that the entire pixel game engine header isn't required for Pixels. [WIP] Stage Mask polygon and overlay structures setup. AreaHighlightTest branch. --- .../Adventures in Lestoria.vcxproj | 13 ++ .../Adventures in Lestoria.vcxproj.filters | 18 ++ .../AdventuresInLestoria.cpp | 17 -- Adventures in Lestoria/Pixel.cpp | 171 ++++++++++++++++++ Adventures in Lestoria/Pixel.h | 109 +++++++++++ Adventures in Lestoria/StageMaskPolygon.cpp | 74 ++++++++ Adventures in Lestoria/StageMaskPolygon.h | 66 +++++++ Adventures in Lestoria/State_GameRun.cpp | 1 - Adventures in Lestoria/olcPixelGameEngine.h | 170 +---------------- 9 files changed, 452 insertions(+), 187 deletions(-) create mode 100644 Adventures in Lestoria/Pixel.cpp create mode 100644 Adventures in Lestoria/Pixel.h create mode 100644 Adventures in Lestoria/StageMaskPolygon.cpp create mode 100644 Adventures in Lestoria/StageMaskPolygon.h diff --git a/Adventures in Lestoria/Adventures in Lestoria.vcxproj b/Adventures in Lestoria/Adventures in Lestoria.vcxproj index eb2edbdf..8175345b 100644 --- a/Adventures in Lestoria/Adventures in Lestoria.vcxproj +++ b/Adventures in Lestoria/Adventures in Lestoria.vcxproj @@ -429,6 +429,10 @@ + + + + @@ -511,6 +515,10 @@ + + + + @@ -849,6 +857,7 @@ + @@ -886,6 +895,10 @@ + + + + diff --git a/Adventures in Lestoria/Adventures in Lestoria.vcxproj.filters b/Adventures in Lestoria/Adventures in Lestoria.vcxproj.filters index 33c5ce18..6970af1d 100644 --- a/Adventures in Lestoria/Adventures in Lestoria.vcxproj.filters +++ b/Adventures in Lestoria/Adventures in Lestoria.vcxproj.filters @@ -91,6 +91,12 @@ {ac44510a-638e-4ae5-8529-2c68dddad459} + + {1b310925-7ec7-4584-8c9c-2154a6e0df80} + + + {aaa148fb-5e34-4c35-a5bf-65ee8f2c0fb1} + @@ -645,6 +651,12 @@ Header Files + + Header Files + + + Header Files\Engine + @@ -1085,6 +1097,12 @@ Source Files\Monster Strategies + + Source Files + + + Source Files\Engine + diff --git a/Adventures in Lestoria/AdventuresInLestoria.cpp b/Adventures in Lestoria/AdventuresInLestoria.cpp index dfc3a614..2f8bd0dc 100644 --- a/Adventures in Lestoria/AdventuresInLestoria.cpp +++ b/Adventures in Lestoria/AdventuresInLestoria.cpp @@ -970,23 +970,6 @@ void AiL::RenderWorld(float fElapsedTime){ PopulateRenderLists(); auto RenderPlayer=[&](vf2d pos,vf2d scale){ - if(GetCurrentMapData().provideOptimization){ - - std::vectorpoints{ - GetMousePos()-vf2d{50,50}, - GetMousePos()+vf2d{100,-20}, - GetMousePos()+vf2d{200,200}, - GetMousePos()+vf2d{-50,150}, - GetMousePos()+vf2d{-120,90},}; - std::vectoruvs; - - std::transform(points.begin(),points.end(),std::back_inserter(uvs),[&](const vf2d&point){return view.ScreenToWorld(point)/GetCurrentMap().GetOptimizedMap()->Sprite()->Size();}); - - DrawPolygonDecal(GetCurrentMap().GetOptimizedMap()->Decal(),points,uvs); - SetDecalMode(DecalMode::WIREFRAME); - DrawPolygonDecal(nullptr,points,uvs,RED); - SetDecalMode(DecalMode::NORMAL); - } if(player->IsInvisible())return; vf2d playerScale=vf2d(player->GetSizeMult(),player->GetSizeMult()); int count=0; diff --git a/Adventures in Lestoria/Pixel.cpp b/Adventures in Lestoria/Pixel.cpp new file mode 100644 index 00000000..e921487f --- /dev/null +++ b/Adventures in Lestoria/Pixel.cpp @@ -0,0 +1,171 @@ +#pragma region License +/* +License (OLC-3) +~~~~~~~~~~~~~~~ + +Copyright 2018 - 2024 OneLoneCoder.com + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +1. Redistributions or derivations of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + +2. Redistributions or derivative works in binary form must reproduce the above +copyright notice. This list of conditions and the following disclaimer must be +reproduced in the documentation and/or other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its contributors may +be used to endorse or promote products derived from this software without specific +prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT +SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED +TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR +BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +SUCH DAMAGE. + +Portions of this software are copyright © 2024 The FreeType +Project (www.freetype.org). Please see LICENSE_FT.txt for more information. +All rights reserved. + +Links +~~~~~ +YouTube: https://www.youtube.com/javidx9 +https://www.youtube.com/javidx9extra +Discord: https://discord.gg/WhwHUMV +Twitter: https://www.twitter.com/javidx9 +Twitch: https://www.twitch.tv/javidx9 +GitHub: https://www.github.com/onelonecoder +Homepage: https://www.onelonecoder.com +Patreon: https://www.patreon.com/javidx9 +Community: https://community.onelonecoder.com +*/ +#pragma endregion + +#include "Pixel.h" +#include + +namespace olc{ + // O------------------------------------------------------------------------------O + // | olc::Pixel IMPLEMENTATION | + // O------------------------------------------------------------------------------O + #if !defined(OLC_IGNORE_PIXEL) + Pixel::Pixel() + { r = 0; g = 0; b = 0; a = nDefaultAlpha; } + + Pixel::Pixel(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha) + { n = red | (green << 8) | (blue << 16) | (alpha << 24); } // Thanks jarekpelczar + + Pixel::Pixel(uint32_t p) + { n = p; } + + bool Pixel::operator==(const Pixel& p) const + { return n == p.n; } + + bool Pixel::operator!=(const Pixel& p) const + { return n != p.n; } + + Pixel Pixel::operator * (const float i) const + { + float fR = std::min(255.0f, std::max(0.0f, float(r) * i)); + float fG = std::min(255.0f, std::max(0.0f, float(g) * i)); + float fB = std::min(255.0f, std::max(0.0f, float(b) * i)); + return Pixel(uint8_t(fR), uint8_t(fG), uint8_t(fB), a); + } + + Pixel Pixel::operator / (const float i) const + { + float fR = std::min(255.0f, std::max(0.0f, float(r) / i)); + float fG = std::min(255.0f, std::max(0.0f, float(g) / i)); + float fB = std::min(255.0f, std::max(0.0f, float(b) / i)); + return Pixel(uint8_t(fR), uint8_t(fG), uint8_t(fB), a); + } + + Pixel& Pixel::operator *=(const float i) + { + this->r = uint8_t(std::min(255.0f, std::max(0.0f, float(r) * i))); + this->g = uint8_t(std::min(255.0f, std::max(0.0f, float(g) * i))); + this->b = uint8_t(std::min(255.0f, std::max(0.0f, float(b) * i))); + return *this; + } + + Pixel& Pixel::operator /=(const float i) + { + this->r = uint8_t(std::min(255.0f, std::max(0.0f, float(r) / i))); + this->g = uint8_t(std::min(255.0f, std::max(0.0f, float(g) / i))); + this->b = uint8_t(std::min(255.0f, std::max(0.0f, float(b) / i))); + return *this; + } + + Pixel Pixel::operator + (const Pixel& p) const + { + uint8_t nR = uint8_t(std::min(255, std::max(0, int(r) + int(p.r)))); + uint8_t nG = uint8_t(std::min(255, std::max(0, int(g) + int(p.g)))); + uint8_t nB = uint8_t(std::min(255, std::max(0, int(b) + int(p.b)))); + return Pixel(nR, nG, nB, a); + } + + Pixel Pixel::operator - (const Pixel& p) const + { + uint8_t nR = uint8_t(std::min(255, std::max(0, int(r) - int(p.r)))); + uint8_t nG = uint8_t(std::min(255, std::max(0, int(g) - int(p.g)))); + uint8_t nB = uint8_t(std::min(255, std::max(0, int(b) - int(p.b)))); + return Pixel(nR, nG, nB, a); + } + + Pixel& Pixel::operator += (const Pixel& p) + { + this->r = uint8_t(std::min(255, std::max(0, int(r) + int(p.r)))); + this->g = uint8_t(std::min(255, std::max(0, int(g) + int(p.g)))); + this->b = uint8_t(std::min(255, std::max(0, int(b) + int(p.b)))); + return *this; + } + + Pixel& Pixel::operator -= (const Pixel& p) // Thanks Au Lit + { + this->r = uint8_t(std::min(255, std::max(0, int(r) - int(p.r)))); + this->g = uint8_t(std::min(255, std::max(0, int(g) - int(p.g)))); + this->b = uint8_t(std::min(255, std::max(0, int(b) - int(p.b)))); + return *this; + } + + Pixel Pixel::operator * (const Pixel& p) const + { + uint8_t nR = uint8_t(std::min(255.0f, std::max(0.0f, float(r) * float(p.r) / 255.0f))); + uint8_t nG = uint8_t(std::min(255.0f, std::max(0.0f, float(g) * float(p.g) / 255.0f))); + uint8_t nB = uint8_t(std::min(255.0f, std::max(0.0f, float(b) * float(p.b) / 255.0f))); + uint8_t nA = uint8_t(std::min(255.0f, std::max(0.0f, float(a) * float(p.a) / 255.0f))); + return Pixel(nR, nG, nB, nA); + } + + Pixel& Pixel::operator *=(const Pixel& p) + { + this->r = uint8_t(std::min(255.0f, std::max(0.0f, float(r) * float(p.r) / 255.0f))); + this->g = uint8_t(std::min(255.0f, std::max(0.0f, float(g) * float(p.g) / 255.0f))); + this->b = uint8_t(std::min(255.0f, std::max(0.0f, float(b) * float(p.b) / 255.0f))); + this->a = uint8_t(std::min(255.0f, std::max(0.0f, float(a) * float(p.a) / 255.0f))); + return *this; + } + + Pixel Pixel::inv() const + { + uint8_t nR = uint8_t(std::min(255, std::max(0, 255 - int(r)))); + uint8_t nG = uint8_t(std::min(255, std::max(0, 255 - int(g)))); + uint8_t nB = uint8_t(std::min(255, std::max(0, 255 - int(b)))); + return Pixel(nR, nG, nB, a); + } + + Pixel PixelF(float red, float green, float blue, float alpha) + { return Pixel(uint8_t(red * 255.0f), uint8_t(green * 255.0f), uint8_t(blue * 255.0f), uint8_t(alpha * 255.0f)); } + + Pixel PixelLerp(const olc::Pixel& p1, const olc::Pixel& p2, float t) + { return (p2 * t) + p1 * (1.0f - t); } + + #endif +} \ No newline at end of file diff --git a/Adventures in Lestoria/Pixel.h b/Adventures in Lestoria/Pixel.h new file mode 100644 index 00000000..7063816b --- /dev/null +++ b/Adventures in Lestoria/Pixel.h @@ -0,0 +1,109 @@ +#pragma region License +/* +License (OLC-3) +~~~~~~~~~~~~~~~ + +Copyright 2018 - 2024 OneLoneCoder.com + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +1. Redistributions or derivations of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + +2. Redistributions or derivative works in binary form must reproduce the above +copyright notice. This list of conditions and the following disclaimer must be +reproduced in the documentation and/or other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its contributors may +be used to endorse or promote products derived from this software without specific +prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT +SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED +TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR +BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +SUCH DAMAGE. + +Portions of this software are copyright © 2024 The FreeType +Project (www.freetype.org). Please see LICENSE_FT.txt for more information. +All rights reserved. + +Links +~~~~~ +YouTube: https://www.youtube.com/javidx9 +https://www.youtube.com/javidx9extra +Discord: https://discord.gg/WhwHUMV +Twitter: https://www.twitter.com/javidx9 +Twitch: https://www.twitch.tv/javidx9 +GitHub: https://www.github.com/onelonecoder +Homepage: https://www.onelonecoder.com +Patreon: https://www.patreon.com/javidx9 +Community: https://community.onelonecoder.com +*/ +#pragma endregion +#pragma once +#include + +// O------------------------------------------------------------------------------O +// | olc::Pixel IMPLEMENTATION | +// O------------------------------------------------------------------------------O +// O------------------------------------------------------------------------------O +// | olc::Pixel - Represents a 32-Bit RGBA colour | +// O------------------------------------------------------------------------------O +namespace olc{ + constexpr inline uint8_t nDefaultAlpha = 0xFF; + constexpr inline uint32_t nDefaultPixel = (nDefaultAlpha << 24); + #if !defined(OLC_IGNORE_PIXEL) + struct Pixel + { + union + { + uint32_t n = nDefaultPixel; + struct { uint8_t r; uint8_t g; uint8_t b; uint8_t a; }; + }; + + enum Mode { NORMAL, MASK, ALPHA, CUSTOM }; + + Pixel(); + Pixel(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha = nDefaultAlpha); + Pixel(uint32_t p); + Pixel& operator = (const Pixel& v) = default; + bool operator ==(const Pixel& p) const; + bool operator !=(const Pixel& p) const; + Pixel operator * (const float i) const; + Pixel operator / (const float i) const; + Pixel& operator *=(const float i); + Pixel& operator /=(const float i); + Pixel operator + (const Pixel& p) const; + Pixel operator - (const Pixel& p) const; + Pixel& operator +=(const Pixel& p); + Pixel& operator -=(const Pixel& p); + Pixel operator * (const Pixel& p) const; + Pixel& operator *=(const Pixel& p); + Pixel inv() const; + }; + + Pixel PixelF(float red, float green, float blue, float alpha = 1.0f); + Pixel PixelLerp(const olc::Pixel& p1, const olc::Pixel& p2, float t); + + + // O------------------------------------------------------------------------------O + // | USEFUL CONSTANTS | + // O------------------------------------------------------------------------------O + static const Pixel + GREY(192, 192, 192), DARK_GREY(128, 128, 128), VERY_DARK_GREY(64, 64, 64), + RED(255, 0, 0), DARK_RED(128, 0, 0), VERY_DARK_RED(64, 0, 0), + YELLOW(255, 255, 0), DARK_YELLOW(128, 128, 0), VERY_DARK_YELLOW(64, 64, 0), + GREEN(0, 255, 0), DARK_GREEN(0, 128, 0), VERY_DARK_GREEN(0, 64, 0), + CYAN(0, 255, 255), DARK_CYAN(0, 128, 128), VERY_DARK_CYAN(0, 64, 64), + BLUE(0, 0, 255), DARK_BLUE(0, 0, 128), VERY_DARK_BLUE(0, 0, 64), + MAGENTA(255, 0, 255), DARK_MAGENTA(128, 0, 128), VERY_DARK_MAGENTA(64, 0, 64), + WHITE(255, 255, 255), BLACK(0, 0, 0), BLANK(0, 0, 0, 0); + #endif +} \ No newline at end of file diff --git a/Adventures in Lestoria/StageMaskPolygon.cpp b/Adventures in Lestoria/StageMaskPolygon.cpp new file mode 100644 index 00000000..c133687d --- /dev/null +++ b/Adventures in Lestoria/StageMaskPolygon.cpp @@ -0,0 +1,74 @@ +#pragma region License +/* +License (OLC-3) +~~~~~~~~~~~~~~~ + +Copyright 2024 Joshua Sigona + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +1. Redistributions or derivations of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + +2. Redistributions or derivative works in binary form must reproduce the above +copyright notice. This list of conditions and the following disclaimer must be +reproduced in the documentation and/or other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its contributors may +be used to endorse or promote products derived from this software without specific +prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT +SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED +TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR +BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +SUCH DAMAGE. + +Portions of this software are copyright © 2024 The FreeType +Project (www.freetype.org). Please see LICENSE_FT.txt for more information. +All rights reserved. +*/ +#pragma endregion + +#include "StageMaskPolygon.h" +#include "AdventuresInLestoria.h" +#include "DEFINES.h" +#include "LoadingScreen.h" + +INCLUDE_game + +StageMaskPolygon::StageMaskPolygon(const std::vector&points,const std::optionalstageMaskOverlay) +:polygon(geom2d::polygon{points}),overlay{stageMaskOverlay}{ + if(LoadingScreen::loading)ERR("WARNING! A stage mask overlay attempted to initialize itself before the stage finished! THIS IS NOT ALLOWED!"); + if(!game->MAP_DATA.at(game->GetCurrentMapName()).GetOptimizedMap())ERR(std::format("WARNING! No optimized map found for stage {} while trying to create a Stage Polygon! THIS IS NOT ALLOWED!",game->GetCurrentMapName())); + + std::transform(points.begin(),points.end(),std::back_inserter(uvs),[&](const vf2d&point){return game->view.ScreenToWorld(point)/game->GetCurrentMap().GetOptimizedMap()->Sprite()->Size();}); +} + +StageMaskOverlay::StageMaskOverlay(const std::vector&points,const Pixel overlayCol,const float blendScale) +:overlayPolygon(geom2d::polygon{points}),overlayCol(overlayCol),blendScale(blendScale){ + std::transform(points.begin(),points.end(),std::back_inserter(overlayUVs),[&](const vf2d&point){return game->view.ScreenToWorld(point)/game->GetCurrentMap().GetOptimizedMap()->Sprite()->Size();}); +} + +const Pixel StageMaskOverlay::GetColor()const{ + return overlayCol; +} +const float StageMaskOverlay::GetScale()const{ + return blendScale; +} +const geom2d::polygon&StageMaskOverlay::GetPolygon()const{ + return overlayPolygon; +} + +void StageMaskPolygon::Draw()const{ + game->DrawPolygonDecal(game->GetCurrentMap().GetOptimizedMap()->Decal(),points,uvs); + game->SetDecalMode(DecalMode::WIREFRAME); + game->DrawPolygonDecal(nullptr,points,uvs,RED); + game->SetDecalMode(DecalMode::NORMAL); +} \ No newline at end of file diff --git a/Adventures in Lestoria/StageMaskPolygon.h b/Adventures in Lestoria/StageMaskPolygon.h new file mode 100644 index 00000000..d67446a5 --- /dev/null +++ b/Adventures in Lestoria/StageMaskPolygon.h @@ -0,0 +1,66 @@ +#pragma region License +/* +License (OLC-3) +~~~~~~~~~~~~~~~ + +Copyright 2024 Joshua Sigona + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +1. Redistributions or derivations of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + +2. Redistributions or derivative works in binary form must reproduce the above +copyright notice. This list of conditions and the following disclaimer must be +reproduced in the documentation and/or other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its contributors may +be used to endorse or promote products derived from this software without specific +prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT +SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED +TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR +BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +SUCH DAMAGE. + +Portions of this software are copyright © 2024 The FreeType +Project (www.freetype.org). Please see LICENSE_FT.txt for more information. +All rights reserved. +*/ +#pragma endregion +#pragma once + +#include "Pixel.h" +#include "olcUTIL_Geometry2D.h" + +class StageMaskOverlay{ + friend class StageMaskPolygon; +private: + StageMaskOverlay(const std::vector&points,const Pixel overlayCol=BLANK,const float blendScale=0.f); + const Pixel GetColor()const; + const float GetScale()const; + const geom2d::polygon&GetPolygon()const; + geom2d::polygonoverlayPolygon; + geom2d::polygonoverlayUVs; + Pixel overlayCol; + //The entire overlay is replicated to also be at a smaller (or larger) blend scale size that interpolates from 1.0 on the outer edge towards 0.0 of the overlayCol to the blendScale. + //As an example, if blendScale is 0.6, then from 1.0 to 0.6x size of the shape from the outer edge the overlayCol will be lerped from 1.0 to 0.0 to the 0.6x size version of the shape. + float blendScale; +}; + +class StageMaskPolygon{ +public: + StageMaskPolygon(const std::vector&points,const std::optionalstageMaskOverlay={}); + void Draw()const; +private: + geom2d::polygonpolygon; + geom2d::polygonuvs; + std::optionaloverlay; +}; \ No newline at end of file diff --git a/Adventures in Lestoria/State_GameRun.cpp b/Adventures in Lestoria/State_GameRun.cpp index dbb278e6..48a9c268 100644 --- a/Adventures in Lestoria/State_GameRun.cpp +++ b/Adventures in Lestoria/State_GameRun.cpp @@ -86,7 +86,6 @@ void State_GameRun::OnUserUpdate(AiL*game){ game->UpdateCamera(game->GetElapsedTime()); } void State_GameRun::Draw(AiL*game){ - game->SetWorldColor(DARK_BLUE); game->RenderWorld(game->GetElapsedTime()); game->RenderHud(); Tutorial::Draw(); diff --git a/Adventures in Lestoria/olcPixelGameEngine.h b/Adventures in Lestoria/olcPixelGameEngine.h index c0db5e0d..833bd45b 100644 --- a/Adventures in Lestoria/olcPixelGameEngine.h +++ b/Adventures in Lestoria/olcPixelGameEngine.h @@ -406,6 +406,7 @@ return 0; #include #include "Error.h" #include "olcUTIL_Geometry2D.h" +#include "Pixel.h" #pragma endregion #define PGE_VER 225 @@ -583,62 +584,9 @@ namespace olc // Pixel Game Engine Advanced Configuration constexpr inline uint8_t nMouseButtons = 5; - constexpr inline uint8_t nDefaultAlpha = 0xFF; - constexpr inline uint32_t nDefaultPixel = (nDefaultAlpha << 24); constexpr inline uint8_t nTabSizeInSpaces = 4; constexpr inline size_t OLC_MAX_VERTS = 128; enum rcode { FAIL = 0, OK = 1, NO_FILE = -1 }; - - // O------------------------------------------------------------------------------O - // | olc::Pixel - Represents a 32-Bit RGBA colour | - // O------------------------------------------------------------------------------O - #if !defined(OLC_IGNORE_PIXEL) - struct Pixel - { - union - { - uint32_t n = nDefaultPixel; - struct { uint8_t r; uint8_t g; uint8_t b; uint8_t a; }; - }; - - enum Mode { NORMAL, MASK, ALPHA, CUSTOM }; - - Pixel(); - Pixel(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha = nDefaultAlpha); - Pixel(uint32_t p); - Pixel& operator = (const Pixel& v) = default; - bool operator ==(const Pixel& p) const; - bool operator !=(const Pixel& p) const; - Pixel operator * (const float i) const; - Pixel operator / (const float i) const; - Pixel& operator *=(const float i); - Pixel& operator /=(const float i); - Pixel operator + (const Pixel& p) const; - Pixel operator - (const Pixel& p) const; - Pixel& operator +=(const Pixel& p); - Pixel& operator -=(const Pixel& p); - Pixel operator * (const Pixel& p) const; - Pixel& operator *=(const Pixel& p); - Pixel inv() const; - }; - - Pixel PixelF(float red, float green, float blue, float alpha = 1.0f); - Pixel PixelLerp(const olc::Pixel& p1, const olc::Pixel& p2, float t); - - - // O------------------------------------------------------------------------------O - // | USEFUL CONSTANTS | - // O------------------------------------------------------------------------------O - static const Pixel - GREY(192, 192, 192), DARK_GREY(128, 128, 128), VERY_DARK_GREY(64, 64, 64), - RED(255, 0, 0), DARK_RED(128, 0, 0), VERY_DARK_RED(64, 0, 0), - YELLOW(255, 255, 0), DARK_YELLOW(128, 128, 0), VERY_DARK_YELLOW(64, 64, 0), - GREEN(0, 255, 0), DARK_GREEN(0, 128, 0), VERY_DARK_GREEN(0, 64, 0), - CYAN(0, 255, 255), DARK_CYAN(0, 128, 128), VERY_DARK_CYAN(0, 64, 64), - BLUE(0, 0, 255), DARK_BLUE(0, 0, 128), VERY_DARK_BLUE(0, 0, 64), - MAGENTA(255, 0, 255), DARK_MAGENTA(128, 0, 128), VERY_DARK_MAGENTA(64, 0, 64), - WHITE(255, 255, 255), BLACK(0, 0, 0), BLANK(0, 0, 0, 0); - #endif // Thanks to scripticuk and others for updating the key maps // NOTE: The GLUT platform will need updating, open to contributions ;) enum Key @@ -1609,122 +1557,6 @@ namespace olc std::string PixelGameEngine::White; std::string PixelGameEngine::Black; std::string PixelGameEngine::Reset; //Will render the original color provided when used. - - // O------------------------------------------------------------------------------O - // | olc::Pixel IMPLEMENTATION | - // O------------------------------------------------------------------------------O - #if !defined(OLC_IGNORE_PIXEL) - Pixel::Pixel() - { r = 0; g = 0; b = 0; a = nDefaultAlpha; } - - Pixel::Pixel(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha) - { n = red | (green << 8) | (blue << 16) | (alpha << 24); } // Thanks jarekpelczar - - Pixel::Pixel(uint32_t p) - { n = p; } - - bool Pixel::operator==(const Pixel& p) const - { return n == p.n; } - - bool Pixel::operator!=(const Pixel& p) const - { return n != p.n; } - - Pixel Pixel::operator * (const float i) const - { - float fR = std::min(255.0f, std::max(0.0f, float(r) * i)); - float fG = std::min(255.0f, std::max(0.0f, float(g) * i)); - float fB = std::min(255.0f, std::max(0.0f, float(b) * i)); - return Pixel(uint8_t(fR), uint8_t(fG), uint8_t(fB), a); - } - - Pixel Pixel::operator / (const float i) const - { - float fR = std::min(255.0f, std::max(0.0f, float(r) / i)); - float fG = std::min(255.0f, std::max(0.0f, float(g) / i)); - float fB = std::min(255.0f, std::max(0.0f, float(b) / i)); - return Pixel(uint8_t(fR), uint8_t(fG), uint8_t(fB), a); - } - - Pixel& Pixel::operator *=(const float i) - { - this->r = uint8_t(std::min(255.0f, std::max(0.0f, float(r) * i))); - this->g = uint8_t(std::min(255.0f, std::max(0.0f, float(g) * i))); - this->b = uint8_t(std::min(255.0f, std::max(0.0f, float(b) * i))); - return *this; - } - - Pixel& Pixel::operator /=(const float i) - { - this->r = uint8_t(std::min(255.0f, std::max(0.0f, float(r) / i))); - this->g = uint8_t(std::min(255.0f, std::max(0.0f, float(g) / i))); - this->b = uint8_t(std::min(255.0f, std::max(0.0f, float(b) / i))); - return *this; - } - - Pixel Pixel::operator + (const Pixel& p) const - { - uint8_t nR = uint8_t(std::min(255, std::max(0, int(r) + int(p.r)))); - uint8_t nG = uint8_t(std::min(255, std::max(0, int(g) + int(p.g)))); - uint8_t nB = uint8_t(std::min(255, std::max(0, int(b) + int(p.b)))); - return Pixel(nR, nG, nB, a); - } - - Pixel Pixel::operator - (const Pixel& p) const - { - uint8_t nR = uint8_t(std::min(255, std::max(0, int(r) - int(p.r)))); - uint8_t nG = uint8_t(std::min(255, std::max(0, int(g) - int(p.g)))); - uint8_t nB = uint8_t(std::min(255, std::max(0, int(b) - int(p.b)))); - return Pixel(nR, nG, nB, a); - } - - Pixel& Pixel::operator += (const Pixel& p) - { - this->r = uint8_t(std::min(255, std::max(0, int(r) + int(p.r)))); - this->g = uint8_t(std::min(255, std::max(0, int(g) + int(p.g)))); - this->b = uint8_t(std::min(255, std::max(0, int(b) + int(p.b)))); - return *this; - } - - Pixel& Pixel::operator -= (const Pixel& p) // Thanks Au Lit - { - this->r = uint8_t(std::min(255, std::max(0, int(r) - int(p.r)))); - this->g = uint8_t(std::min(255, std::max(0, int(g) - int(p.g)))); - this->b = uint8_t(std::min(255, std::max(0, int(b) - int(p.b)))); - return *this; - } - - Pixel Pixel::operator * (const Pixel& p) const - { - uint8_t nR = uint8_t(std::min(255.0f, std::max(0.0f, float(r) * float(p.r) / 255.0f))); - uint8_t nG = uint8_t(std::min(255.0f, std::max(0.0f, float(g) * float(p.g) / 255.0f))); - uint8_t nB = uint8_t(std::min(255.0f, std::max(0.0f, float(b) * float(p.b) / 255.0f))); - uint8_t nA = uint8_t(std::min(255.0f, std::max(0.0f, float(a) * float(p.a) / 255.0f))); - return Pixel(nR, nG, nB, nA); - } - - Pixel& Pixel::operator *=(const Pixel& p) - { - this->r = uint8_t(std::min(255.0f, std::max(0.0f, float(r) * float(p.r) / 255.0f))); - this->g = uint8_t(std::min(255.0f, std::max(0.0f, float(g) * float(p.g) / 255.0f))); - this->b = uint8_t(std::min(255.0f, std::max(0.0f, float(b) * float(p.b) / 255.0f))); - this->a = uint8_t(std::min(255.0f, std::max(0.0f, float(a) * float(p.a) / 255.0f))); - return *this; - } - - Pixel Pixel::inv() const - { - uint8_t nR = uint8_t(std::min(255, std::max(0, 255 - int(r)))); - uint8_t nG = uint8_t(std::min(255, std::max(0, 255 - int(g)))); - uint8_t nB = uint8_t(std::min(255, std::max(0, 255 - int(b)))); - return Pixel(nR, nG, nB, a); - } - - Pixel PixelF(float red, float green, float blue, float alpha) - { return Pixel(uint8_t(red * 255.0f), uint8_t(green * 255.0f), uint8_t(blue * 255.0f), uint8_t(alpha * 255.0f)); } - - Pixel PixelLerp(const olc::Pixel& p1, const olc::Pixel& p2, float t) - { return (p2 * t) + p1 * (1.0f - t); } - #endif // O------------------------------------------------------------------------------O // | olc::Sprite IMPLEMENTATION | // O------------------------------------------------------------------------------O