Add middle() function for polygons in geometry util. Restructure stage mask overlays to be part of the stage mask polygon class. Reproduce sample using new class. Release Build 9572.

mac-build
sigonasr2 6 months ago
parent 9c17b3b649
commit 346f264c9d
  1. 14
      Adventures in Lestoria/AdventuresInLestoria.cpp
  2. 59
      Adventures in Lestoria/StageMaskPolygon.cpp
  3. 25
      Adventures in Lestoria/StageMaskPolygon.h
  4. 2
      Adventures in Lestoria/Version.h
  5. 1
      Adventures in Lestoria/assets/config/gfx/gfx.txt
  6. BIN
      Adventures in Lestoria/assets/gamepack.pak
  7. BIN
      Adventures in Lestoria/assets/safeIndicatorGradient.png
  8. 6
      Adventures in Lestoria/olcUTIL_Geometry2D.h
  9. BIN
      x64/Release/Adventures in Lestoria.exe

@ -81,6 +81,7 @@ All rights reserved.
#include "Tutorial.h"
#include "SteamKeyboardCallbackHandler.h"
#include "SteamStatsReceivedHandler.h"
#include "StageMaskPolygon.h"
INCLUDE_EMITTER_LIST
INCLUDE_ITEM_CATEGORIES
@ -970,6 +971,19 @@ void AiL::RenderWorld(float fElapsedTime){
PopulateRenderLists();
auto RenderPlayer=[&](vf2d pos,vf2d scale){
SetWorldColor(PixelLerp(DARK_BLUE,BLACK,sin(geom2d::pi*GetRunTime()*2)));
if(GetCurrentMapData().provideOptimization&&!LoadingScreen::loading){
StageMaskPolygon poly{
{
view.ScreenToWorld(GetMousePos()-vf2d{50,50}),
view.ScreenToWorld(GetMousePos()+vf2d{100,-20}),
view.ScreenToWorld(GetMousePos()+vf2d{200,200}),
view.ScreenToWorld(GetMousePos()+vf2d{-50,150}),
view.ScreenToWorld(GetMousePos()+vf2d{-120,90}),
},"safeIndicatorGradient.png",PixelLerp(VERY_DARK_BLUE,BLACK,sin(geom2d::pi*GetRunTime()*2))
};
poly.Draw();
}
if(player->IsInvisible())return;
vf2d playerScale=vf2d(player->GetSizeMult(),player->GetSizeMult());
int count=0;

@ -40,35 +40,64 @@ All rights reserved.
#include "AdventuresInLestoria.h"
#include "DEFINES.h"
#include "LoadingScreen.h"
#include "util.h"
INCLUDE_game
INCLUDE_GFX
StageMaskPolygon::StageMaskPolygon(const std::vector<vf2d>&points,const std::optional<StageMaskOverlay>stageMaskOverlay)
:polygon(geom2d::polygon<float>{points}),overlay{stageMaskOverlay}{
StageMaskPolygon::StageMaskPolygon(const std::vector<vf2d>&points,const std::string&texture,const Pixel overlayCol)
:polygon(geom2d::polygon<float>{points}){
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();});
if(texture.length()>0)overlay=StageMaskPolygon::StageMaskOverlay{points,texture,overlayCol};
std::transform(points.begin(),points.end(),std::back_inserter(uvs.pos),[&](const vf2d&point){return point/game->GetCurrentMap().GetOptimizedMap()->Sprite()->Size();});
}
StageMaskOverlay::StageMaskOverlay(const std::vector<vf2d>&points,const Pixel overlayCol,const float blendScale)
:overlayPolygon(geom2d::polygon<float>{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();});
StageMaskPolygon::StageMaskOverlay::StageMaskOverlay(const std::vector<vf2d>&points,const std::string&texture,const Pixel overlayCol)
:overlayPolygon(geom2d::polygon<float>{points}),texture(texture),overlayCol(overlayCol){
if(!GFX.count(texture))ERR(std::format("WARNING! Texture {} does not exist while trying to initialize Stage Mask Overlay!",texture));
overlayPolygon.pos.insert(overlayPolygon.pos.begin(),overlayPolygon.middle()); //Insert the middle point to the front of the overlay polygon's point list.
//Copy the first point provided from the original polygon to the end of the new overlay polygon since we have to fully connect the polygon for the texture to show up correctly.
overlayPolygon.pos.push_back(points[0]);
bool first=false;
std::transform(overlayPolygon.pos.begin(),overlayPolygon.pos.end(),std::back_inserter(overlayUVs.pos),[&](const vf2d&point){
if(!first){
first=true;
return vf2d{0.f,0.f};
}else{
return vf2d{1.f,1.f};
}
});
}
const Pixel StageMaskOverlay::GetColor()const{
const Pixel StageMaskPolygon::StageMaskOverlay::GetColor()const{
return overlayCol;
}
const float StageMaskOverlay::GetScale()const{
return blendScale;
}
const geom2d::polygon<float>&StageMaskOverlay::GetPolygon()const{
const geom2d::polygon<float>&StageMaskPolygon::StageMaskOverlay::GetPolygon()const{
return overlayPolygon;
}
void StageMaskPolygon::StageMaskOverlay::Draw()const{
game->view.DrawPolygonDecal(GFX.at(texture).Decal(),overlayPolygon.pos,overlayUVs.pos,GetColor());
}
const bool StageMaskPolygon::HasOverlay()const{
return overlay.has_value();
}
void StageMaskPolygon::SetBlendColor(const Pixel overlayCol){
if(!HasOverlay())ERR("WARNING! Trying to set the blend color when there is no overlay on this stage mask polygon! THIS IS NOT ALLOWED!");
overlay.value().overlayCol=overlayCol;
}
const StageMaskPolygon::StageMaskOverlay&StageMaskPolygon::GetOverlay()const{
return overlay.value();
}
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);
game->view.DrawPolygonDecal(game->GetCurrentMap().GetOptimizedMap()->Decal(),polygon.pos,uvs.pos);
if(HasOverlay())GetOverlay().Draw();
}

@ -40,24 +40,25 @@ All rights reserved.
#include "Pixel.h"
#include "olcUTIL_Geometry2D.h"
class StageMaskOverlay{
class StageMaskPolygon{
class StageMaskOverlay{
friend class StageMaskPolygon;
private:
StageMaskOverlay(const std::vector<vf2d>&points,const Pixel overlayCol=BLANK,const float blendScale=0.f);
private:
//The stage mask overlay auto-forms a UV mapping where the center is {0,0} and the edges are {1,1}. Use this to shape a texture with the desired outline you want.
StageMaskOverlay(const std::vector<vf2d>&points,const std::string&texture,const Pixel overlayCol=BLANK);
const Pixel GetColor()const;
const float GetScale()const;
const geom2d::polygon<float>&GetPolygon()const;
geom2d::polygon<float>overlayPolygon;
void Draw()const;
std::string texture;
geom2d::polygon<float>overlayPolygon; //The overlay polygon uses a middle point so that a texture can fade in towards the center.
geom2d::polygon<float>overlayUVs;
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<vf2d>&points,const std::optional<StageMaskOverlay>stageMaskOverlay={});
StageMaskPolygon(const std::vector<vf2d>&points,const std::string&texture="",const Pixel overlayCol=BLANK);
void SetBlendColor(const Pixel overlayCol);
const bool HasOverlay()const;
const StageMaskOverlay&GetOverlay()const;
void Draw()const;
private:
geom2d::polygon<float>polygon;

@ -39,7 +39,7 @@ All rights reserved.
#define VERSION_MAJOR 1
#define VERSION_MINOR 2
#define VERSION_PATCH 3
#define VERSION_BUILD 9561
#define VERSION_BUILD 9572
#define stringify(a) stringify_(a)
#define stringify_(a) #a

@ -104,6 +104,7 @@ Images
GFX_Wind2 = wind2.png
GFX_WindObjects = commercial_assets/wind_solid_objects.png
GFX_LargeTornado = large_tornado.png
GFX_SafeAreaIndicator = safeIndicatorGradient.png
# Ability Icons
GFX_Warrior_BattleCry_Icon = Ability Icons/battlecry.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 681 B

@ -190,6 +190,7 @@
#include <cstdint>
#include <optional>
#include <cassert>
#include <numeric>
#ifndef OLC_V2D_TYPE
#define OLC_V2D_TYPE
@ -784,6 +785,11 @@ namespace olc::utils::geom2d
struct polygon
{
std::vector<olc::v_2d<T>> pos;
inline constexpr olc::v_2d<T>middle()const{
vf2d total=std::accumulate(pos.begin(),pos.end(),olc::v_2d<T>{},[](const olc::v_2d<T>&middle,const olc::v_2d<T>&point){return std::move(middle)+point;});
return total/pos.size();
}
};

Loading…
Cancel
Save