Added caching for shadow text for all PGE default drawing functions and viewport drawing functions.
This commit is contained in:
parent
52d36eab3b
commit
126753053f
@ -88,10 +88,10 @@ public:
|
||||
inline float&get(const ItemAttribute&a){
|
||||
return attributes[a];
|
||||
}
|
||||
inline const float get_readOnly(std::string_view a)const{
|
||||
inline const float&get_readOnly(std::string_view a)const{
|
||||
return get_readOnly(ItemAttribute::Get(a));
|
||||
}
|
||||
inline const float get_readOnly(const ItemAttribute&a)const{
|
||||
inline const float&get_readOnly(const ItemAttribute&a)const{
|
||||
if(attributes.count(a)){
|
||||
return attributes.at(a);
|
||||
}
|
||||
|
@ -1226,7 +1226,7 @@ void Crawler::RenderHud(){
|
||||
std::stringstream castTimeDisplay;
|
||||
castTimeDisplay<<std::fixed<<std::setprecision(1)<<timer;
|
||||
DrawShadowStringPropDecal(vf2d{ScreenWidth()/2+90.f,ScreenHeight()-80.f}-vf2d{float(GetTextSizeProp(castTimeDisplay.str()).x),0},castTimeDisplay.str(),WHITE,BLACK);
|
||||
DrawShadowStringPropDecal(vf2d{ScreenWidth()/2.f-GetTextSizeProp(castText).x*2/2,ScreenHeight()-64.f},castText,WHITE,BLACK,{2,3},std::numeric_limits<float>::max(),2.f);
|
||||
DrawShadowStringPropDecal(vf2d{ScreenWidth()/2.f-GetTextSizeProp(castText).x*2/2,ScreenHeight()-64.f},castText,WHITE,BLACK,{2,3},std::numeric_limits<float>::max(),0.75f);
|
||||
};
|
||||
|
||||
if(GetPlayer()->GetCastInfo().castTimer>0){
|
||||
@ -1240,8 +1240,8 @@ void Crawler::RenderHud(){
|
||||
DrawDecal({2,20},GFX["mana.png"].Decal());
|
||||
std::string text=player->GetHealth()>0?std::to_string(player->GetHealth()):"X";
|
||||
std::string text_mana=std::to_string(player->GetMana());
|
||||
DrawShadowStringPropDecal({20,3},text,WHITE,BLACK,{2,2});
|
||||
DrawShadowStringPropDecal({24,23},text_mana,{192,192,255},BLACK,{1.5,1.5});
|
||||
DrawShadowStringPropDecal({20,3},text,WHITE,BLACK,{2,2},INFINITE,0.5f);
|
||||
DrawShadowStringPropDecal({24,23},text_mana,{192,192,255},BLACK,{1.5f,1.5f},INFINITE,0.6f);
|
||||
if(player->notEnoughManaDisplay.second>0){
|
||||
std::string displayText="Not enough mana for "+player->notEnoughManaDisplay.first+"!";
|
||||
DrawShadowStringPropDecal(vf2d{float(ScreenWidth()/2),float(ScreenHeight()/4)}-GetTextSizeProp(displayText)/2,displayText,DARK_RED,VERY_DARK_RED);
|
||||
@ -1519,12 +1519,10 @@ void Crawler::LoadLevel(MapName map){
|
||||
totalBossEncounterMobs=0;
|
||||
Inventory::Clear("Monster Loot");
|
||||
Inventory::Clear("Stage Loot");
|
||||
std::cout<<GetPlayer()->hp<<std::endl;
|
||||
GetPlayer()->hp=GetPlayer()->GetStat("Health");
|
||||
GetPlayer()->mana=GetPlayer()->GetMaxMana();
|
||||
GetPlayer()->SetState(State::NORMAL);
|
||||
GetPlayer()->GetCastInfo()={};
|
||||
std::cout<<GetPlayer()->hp<<std::endl;
|
||||
|
||||
#pragma region Monster Spawn Data Setup
|
||||
for(auto&[key,value]:MAP_DATA[map].SpawnerData){
|
||||
|
@ -832,7 +832,7 @@ void Player::SetIframes(float duration){
|
||||
}
|
||||
|
||||
bool Player::Heal(int damage){
|
||||
hp=std::clamp(hp+damage,0,GetStat("Health"));
|
||||
hp=std::clamp(hp+damage,0,int(GetStat("Health")));
|
||||
if(damage>0){
|
||||
DAMAGENUMBER_LIST.push_back(std::make_shared<DamageNumber>(GetPos(),damage,true,HEALTH_GAIN));
|
||||
}
|
||||
@ -896,19 +896,19 @@ void Player::SetItem3UseFunc(Ability a){
|
||||
useItem3=a;
|
||||
};
|
||||
|
||||
const int&Player::GetStat(std::string_view a)const{
|
||||
const float&Player::GetStat(std::string_view a)const{
|
||||
return GetStat(ItemAttribute::Get(a));
|
||||
}
|
||||
|
||||
const int&Player::GetStat(ItemAttribute a)const{
|
||||
const float&Player::GetStat(ItemAttribute a)const{
|
||||
return stats.GetStat(a);
|
||||
}
|
||||
|
||||
const int&Player::GetBaseStat(std::string_view a)const{
|
||||
const float&Player::GetBaseStat(std::string_view a)const{
|
||||
return GetBaseStat(ItemAttribute::Get(a));
|
||||
}
|
||||
|
||||
const int&Player::GetBaseStat(ItemAttribute a)const{
|
||||
const float&Player::GetBaseStat(ItemAttribute a)const{
|
||||
return stats.GetBaseStat(a);
|
||||
}
|
||||
|
||||
|
@ -98,10 +98,10 @@ public:
|
||||
float GetX();
|
||||
float GetY();
|
||||
float GetZ();
|
||||
const int&GetStat(ItemAttribute a)const;
|
||||
const int&GetStat(std::string_view a)const;
|
||||
const int&GetBaseStat(ItemAttribute a)const;
|
||||
const int&GetBaseStat(std::string_view a)const;
|
||||
const float&GetStat(ItemAttribute a)const;
|
||||
const float&GetStat(std::string_view a)const;
|
||||
const float&GetBaseStat(ItemAttribute a)const;
|
||||
const float&GetBaseStat(std::string_view a)const;
|
||||
void SetBaseStat(std::string_view a,float val);
|
||||
void SetBaseStat(ItemAttribute a,float val);
|
||||
const int GetMaxHealth()const;
|
||||
|
@ -39,7 +39,7 @@ All rights reserved.
|
||||
#define VERSION_MAJOR 0
|
||||
#define VERSION_MINOR 2
|
||||
#define VERSION_PATCH 1
|
||||
#define VERSION_BUILD 4672
|
||||
#define VERSION_BUILD 4739
|
||||
|
||||
#define stringify(a) stringify_(a)
|
||||
#define stringify_(a) #a
|
||||
|
@ -119,8 +119,8 @@ namespace olc {
|
||||
void DrawStringDecal(const olc::vf2d& pos, std::string_view sText, const Pixel col = olc::WHITE, const olc::vf2d& scale = { 1.0f, 1.0f },const float width=std::numeric_limits<float>::max(),const bool disableDynamicScaling=false);
|
||||
void DrawStringDecal(Font&font, const olc::vf2d& pos, const std::u32string& sText, const Pixel col = olc::WHITE, const olc::vf2d& scale = { 1.0f, 1.0f });
|
||||
void DrawStringPropDecal(const olc::vf2d& pos, std::string_view sText, const Pixel col = olc::WHITE, const olc::vf2d& scale = { 1.0f, 1.0f }, const float width=std::numeric_limits<float>::max(),const bool disableDynamicScaling=false);
|
||||
void DrawShadowStringDecal(const olc::vf2d& pos, std::string_view sText, const Pixel col = olc::WHITE, const Pixel shadowCol = olc::BLACK, const olc::vf2d& scale = { 1.0f, 1.0f },const float width=std::numeric_limits<float>::max(),const float shadowSizeFactor=1);
|
||||
void DrawShadowStringPropDecal(const olc::vf2d& pos, std::string_view sText, const Pixel col = olc::WHITE, const Pixel shadowCol = olc::BLACK, const olc::vf2d& scale = { 1.0f, 1.0f },const float width=std::numeric_limits<float>::max(),const float shadowSizeFactor=1);
|
||||
void DrawShadowStringDecal(const olc::vf2d& pos, std::string_view sText, const Pixel col = olc::WHITE, const Pixel shadowCol = olc::BLACK, const olc::vf2d& scale = { 1.0f, 1.0f },const float width=std::numeric_limits<float>::max(),const float shadowSizeFactor=1,const bool disableDynamicScaling=false);
|
||||
void DrawShadowStringPropDecal(const olc::vf2d& pos, std::string_view sText, const Pixel col = olc::WHITE, const Pixel shadowCol = olc::BLACK, const olc::vf2d& scale = { 1.0f, 1.0f },const float width=std::numeric_limits<float>::max(),const float shadowSizeFactor=1,const bool disableDynamicScaling=false);
|
||||
void DrawShadowStringDecal(Font&font, const olc::vf2d& pos, const std::u32string& sText, const Pixel col = olc::WHITE, const Pixel shadowCol = olc::BLACK, const olc::vf2d& scale = { 1.0f, 1.0f },const float shadowSizeFactor=1);
|
||||
void DrawDropShadowStringDecal(Font&font, const olc::vf2d& pos, const std::u32string& sText, const Pixel col = olc::WHITE, const Pixel shadowCol = olc::BLACK, const olc::vf2d& scale = { 1.0f, 1.0f });
|
||||
|
||||
@ -716,26 +716,100 @@ void olc::ViewPort::DrawStringPropDecal(const olc::vf2d& pos, std::string_view s
|
||||
DrawDecal(pos,garbageCollector[key].decal,scale,col);
|
||||
}
|
||||
|
||||
void olc::ViewPort::DrawShadowStringDecal(const olc::vf2d& pos, std::string_view sText, const Pixel col, const Pixel shadowCol, const olc::vf2d& scale,const float width,const float shadowSizeFactor){
|
||||
for(float y=-shadowSizeFactor;y<=shadowSizeFactor+0.1;y+=shadowSizeFactor/2){
|
||||
for(float x=-shadowSizeFactor;x<=shadowSizeFactor+0.1;x+=shadowSizeFactor/2){
|
||||
if(x!=0||y!=0){
|
||||
DrawStringDecal(pos+vf2d{x,y}, sText, shadowCol,scale,width);
|
||||
}
|
||||
void olc::ViewPort::DrawShadowStringDecal(const olc::vf2d& pos, std::string_view sText, const Pixel col, const Pixel shadowCol, const olc::vf2d& scale,const float width,const float shadowSizeFactor,const bool disableDynamicScaling){
|
||||
struct DecalData{
|
||||
Decal*decal;
|
||||
float expireTime=0.0f;
|
||||
};
|
||||
if(sText.length()==0)return;
|
||||
static std::map<std::string,DecalData>garbageCollector;
|
||||
std::string key{sText};
|
||||
key+=std::to_string(width);
|
||||
if(!disableDynamicScaling){
|
||||
key+=scale.str();
|
||||
}
|
||||
}
|
||||
DrawStringDecal(pos, sText, col,scale,width);
|
||||
if(!garbageCollector.count(key)){ //If the text key already exists, don't have to recreate the decal, just update the expire time.
|
||||
vi2d imageSize=pge->GetWrappedTextSize(sText,width,scale);
|
||||
Decal*newDecal=new Decal(new Sprite(imageSize.x/scale.x,imageSize.y/scale.x));
|
||||
garbageCollector[key].decal=newDecal;
|
||||
pge->SetDrawTarget(newDecal->sprite);
|
||||
pge->Clear(BLANK);
|
||||
pge->DrawString({0,0},sText,WHITE,1U,width/scale.x);
|
||||
newDecal->Update();
|
||||
float adjustedShadowSizeFactor=shadowSizeFactor*4;
|
||||
Decal*newShadowDecal=new Decal(new Sprite((imageSize.x/scale.x*4)+adjustedShadowSizeFactor*2,(imageSize.y/scale.x*4)+adjustedShadowSizeFactor*2));
|
||||
garbageCollector[key+"_SHADOW"].decal=newShadowDecal;
|
||||
pge->SetDrawTarget(newShadowDecal->sprite);
|
||||
pge->Clear(BLANK);
|
||||
for(float y=-adjustedShadowSizeFactor;y<=adjustedShadowSizeFactor+0.1;y+=adjustedShadowSizeFactor/2){
|
||||
for(float x=-adjustedShadowSizeFactor;x<=adjustedShadowSizeFactor+0.1;x+=adjustedShadowSizeFactor/2){
|
||||
if(x!=0||y!=0){
|
||||
pge->DrawString(vf2d{x,y}+vf2d{adjustedShadowSizeFactor,adjustedShadowSizeFactor}, sText, WHITE,4U,width/scale.x*4);
|
||||
}
|
||||
}
|
||||
}
|
||||
pge->SetDrawTarget(nullptr);
|
||||
newShadowDecal->Update();
|
||||
}
|
||||
garbageCollector[key].expireTime=pge->GetRuntime()+120.0f;
|
||||
garbageCollector[key+"_SHADOW"].expireTime=pge->GetRuntime()+120.0f;
|
||||
std::erase_if(garbageCollector,[&](auto&key){
|
||||
if(key.second.expireTime<pge->GetRuntime()){
|
||||
delete key.second.decal;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
DrawDecal(pos-vf2d{shadowSizeFactor,shadowSizeFactor}*scale,garbageCollector[key+"_SHADOW"].decal,scale/4,shadowCol);
|
||||
DrawDecal(pos,garbageCollector[key].decal,scale,col);
|
||||
}
|
||||
|
||||
void olc::ViewPort::DrawShadowStringPropDecal(const olc::vf2d& pos, std::string_view sText, const Pixel col, const Pixel shadowCol, const olc::vf2d& scale,const float width,const float shadowSizeFactor){
|
||||
for(float y=-shadowSizeFactor;y<=shadowSizeFactor+0.1;y+=shadowSizeFactor/2){
|
||||
for(float x=-shadowSizeFactor;x<=shadowSizeFactor+0.1;x+=shadowSizeFactor/2){
|
||||
if(x!=0||y!=0){
|
||||
DrawStringPropDecal(pos+vf2d{x,y}, sText, shadowCol,scale,width);
|
||||
}
|
||||
void olc::ViewPort::DrawShadowStringPropDecal(const olc::vf2d& pos, std::string_view sText, const Pixel col, const Pixel shadowCol, const olc::vf2d& scale,const float width,const float shadowSizeFactor,const bool disableDynamicScaling){
|
||||
struct DecalData{
|
||||
Decal*decal;
|
||||
float expireTime=0.0f;
|
||||
};
|
||||
if(sText.length()==0)return;
|
||||
static std::map<std::string,DecalData>garbageCollector;
|
||||
std::string key{sText};
|
||||
key+=std::to_string(width);
|
||||
if(!disableDynamicScaling){
|
||||
key+=scale.str();
|
||||
}
|
||||
}
|
||||
DrawStringPropDecal(pos, sText, col,scale,width);
|
||||
if(!garbageCollector.count(key)){ //If the text key already exists, don't have to recreate the decal, just update the expire time.
|
||||
vi2d imageSize=pge->GetWrappedTextSizeProp(sText,width,scale);
|
||||
Decal*newDecal=new Decal(new Sprite(imageSize.x/scale.x,imageSize.y/scale.x));
|
||||
garbageCollector[key].decal=newDecal;
|
||||
pge->SetDrawTarget(newDecal->sprite);
|
||||
pge->Clear(BLANK);
|
||||
pge->DrawStringProp({0,0},sText,WHITE,1U,width/scale.x);
|
||||
newDecal->Update();
|
||||
float adjustedShadowSizeFactor=shadowSizeFactor*4;
|
||||
Decal*newShadowDecal=new Decal(new Sprite((imageSize.x/scale.x*4)+adjustedShadowSizeFactor*2,(imageSize.y/scale.x*4)+adjustedShadowSizeFactor*2));
|
||||
garbageCollector[key+"_SHADOW"].decal=newShadowDecal;
|
||||
pge->SetDrawTarget(newShadowDecal->sprite);
|
||||
pge->Clear(BLANK);
|
||||
for(float y=-adjustedShadowSizeFactor;y<=adjustedShadowSizeFactor+0.1;y+=adjustedShadowSizeFactor/2){
|
||||
for(float x=-adjustedShadowSizeFactor;x<=adjustedShadowSizeFactor+0.1;x+=adjustedShadowSizeFactor/2){
|
||||
if(x!=0||y!=0){
|
||||
pge->DrawStringProp(vf2d{x,y}+vf2d{adjustedShadowSizeFactor,adjustedShadowSizeFactor}, sText, WHITE,4U,width/scale.x*4);
|
||||
}
|
||||
}
|
||||
}
|
||||
pge->SetDrawTarget(nullptr);
|
||||
newShadowDecal->Update();
|
||||
}
|
||||
garbageCollector[key].expireTime=pge->GetRuntime()+120.0f;
|
||||
garbageCollector[key+"_SHADOW"].expireTime=pge->GetRuntime()+120.0f;
|
||||
std::erase_if(garbageCollector,[&](auto&key){
|
||||
if(key.second.expireTime<pge->GetRuntime()){
|
||||
delete key.second.decal;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
DrawDecal(pos-vf2d{shadowSizeFactor,shadowSizeFactor}*scale,garbageCollector[key+"_SHADOW"].decal,scale/4,shadowCol);
|
||||
DrawDecal(pos,garbageCollector[key].decal,scale,col);
|
||||
}
|
||||
|
||||
void olc::ViewPort::DrawShadowStringDecal(Font&font, const olc::vf2d& pos, const std::u32string& sText, const Pixel col, const Pixel shadowCol, const olc::vf2d& scale,const float shadowSizeFactor){
|
||||
|
@ -1152,8 +1152,8 @@ namespace olc
|
||||
void DrawStringDecal(const olc::vf2d& pos, std::string_view sText, const Pixel col = olc::WHITE, const olc::vf2d& scale = { 1.0f, 1.0f },const float width=std::numeric_limits<float>::max(),const bool disableDynamicScaling=false);
|
||||
void DrawStringDecal(Font&font, const olc::vf2d& pos, const std::u32string& sText, const Pixel col = olc::WHITE, const olc::vf2d& scale = { 1.0f, 1.0f });
|
||||
void DrawStringPropDecal(const olc::vf2d& pos, std::string_view sText, const Pixel col = olc::WHITE, const olc::vf2d& scale = { 1.0f, 1.0f }, const float width=std::numeric_limits<float>::max(),const bool disableDynamicScaling=false);
|
||||
void DrawShadowStringDecal(const olc::vf2d& pos, std::string_view sText, const Pixel col = olc::WHITE, const Pixel shadowCol = olc::BLACK, const olc::vf2d& scale = { 1.0f, 1.0f },const float width=std::numeric_limits<float>::max(),const float shadowSizeFactor=1);
|
||||
void DrawShadowStringPropDecal(const olc::vf2d& pos, std::string_view sText, const Pixel col = olc::WHITE, const Pixel shadowCol = olc::BLACK, const olc::vf2d& scale = { 1.0f, 1.0f },const float width=std::numeric_limits<float>::max(),const float shadowSizeFactor=1);
|
||||
void DrawShadowStringDecal(const olc::vf2d& pos, std::string_view sText, const Pixel col = olc::WHITE, const Pixel shadowCol = olc::BLACK, const olc::vf2d& scale = { 1.0f, 1.0f },const float width=std::numeric_limits<float>::max(),const float shadowSizeFactor=1,const bool disableDynamicScaling=false);
|
||||
void DrawShadowStringPropDecal(const olc::vf2d& pos, std::string_view sText, const Pixel col = olc::WHITE, const Pixel shadowCol = olc::BLACK, const olc::vf2d& scale = { 1.0f, 1.0f },const float width=std::numeric_limits<float>::max(),const float shadowSizeFactor=1,const bool disableDynamicScaling=false);
|
||||
void DrawShadowStringDecal(Font&font, const olc::vf2d& pos, const std::u32string& sText, const Pixel col = olc::WHITE, const Pixel shadowCol = olc::BLACK, const olc::vf2d& scale = { 1.0f, 1.0f },const float shadowSizeFactor=1);
|
||||
void DrawDropShadowStringDecal(Font&font, const olc::vf2d& pos, const std::u32string& sText, const Pixel col = olc::WHITE, const Pixel shadowCol = olc::BLACK, const olc::vf2d& scale = { 1.0f, 1.0f });
|
||||
// Draws a single shaded filled rectangle as a decal
|
||||
@ -3420,15 +3420,52 @@ namespace olc
|
||||
DrawDecal(pos,garbageCollector[key].decal,scale,col);
|
||||
}
|
||||
|
||||
void PixelGameEngine::DrawShadowStringDecal(const olc::vf2d& pos, std::string_view sText, const Pixel col, const Pixel shadowCol, const olc::vf2d& scale,const float width,const float shadowSizeFactor){
|
||||
for(float y=-shadowSizeFactor;y<=shadowSizeFactor+0.1;y+=shadowSizeFactor/2){
|
||||
for(float x=-shadowSizeFactor;x<=shadowSizeFactor+0.1;x+=shadowSizeFactor/2){
|
||||
if(x!=0||y!=0){
|
||||
DrawStringDecal(pos+vf2d{x,y}, sText, shadowCol,scale,width);
|
||||
void PixelGameEngine::DrawShadowStringDecal(const olc::vf2d& pos, std::string_view sText, const Pixel col, const Pixel shadowCol, const olc::vf2d& scale,const float width,const float shadowSizeFactor,const bool disableDynamicScaling){
|
||||
struct DecalData{
|
||||
Decal*decal;
|
||||
float expireTime=0.0f;
|
||||
};
|
||||
if(sText.length()==0)return;
|
||||
static std::map<std::string,DecalData>garbageCollector;
|
||||
std::string key{sText};
|
||||
key+=std::to_string(width);
|
||||
if(!disableDynamicScaling){
|
||||
key+=scale.str();
|
||||
}
|
||||
if(!garbageCollector.count(key)){ //If the text key already exists, don't have to recreate the decal, just update the expire time.
|
||||
vi2d imageSize=GetWrappedTextSize(sText,width,scale);
|
||||
Decal*newDecal=new Decal(new Sprite(imageSize.x/scale.x,imageSize.y/scale.x));
|
||||
garbageCollector[key].decal=newDecal;
|
||||
SetDrawTarget(newDecal->sprite);
|
||||
Clear(BLANK);
|
||||
DrawString({0,0},sText,WHITE,1U,width/scale.x);
|
||||
newDecal->Update();
|
||||
float adjustedShadowSizeFactor=shadowSizeFactor*4;
|
||||
Decal*newShadowDecal=new Decal(new Sprite((imageSize.x/scale.x*4)+adjustedShadowSizeFactor*2,(imageSize.y/scale.x*4)+adjustedShadowSizeFactor*2));
|
||||
garbageCollector[key+"_SHADOW"].decal=newShadowDecal;
|
||||
SetDrawTarget(newShadowDecal->sprite);
|
||||
Clear(BLANK);
|
||||
for(float y=-adjustedShadowSizeFactor;y<=adjustedShadowSizeFactor+0.1;y+=adjustedShadowSizeFactor/2){
|
||||
for(float x=-adjustedShadowSizeFactor;x<=adjustedShadowSizeFactor+0.1;x+=adjustedShadowSizeFactor/2){
|
||||
if(x!=0||y!=0){
|
||||
DrawString(vf2d{x,y}+vf2d{adjustedShadowSizeFactor,adjustedShadowSizeFactor}, sText, WHITE,4U,width/scale.x*4);
|
||||
}
|
||||
}
|
||||
}
|
||||
SetDrawTarget(nullptr);
|
||||
newShadowDecal->Update();
|
||||
}
|
||||
DrawStringDecal(pos, sText, col,scale,width);
|
||||
garbageCollector[key].expireTime=GetRuntime()+120.0f;
|
||||
garbageCollector[key+"_SHADOW"].expireTime=GetRuntime()+120.0f;
|
||||
std::erase_if(garbageCollector,[&](auto&key){
|
||||
if(key.second.expireTime<GetRuntime()){
|
||||
delete key.second.decal;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
DrawDecal(pos-vf2d{shadowSizeFactor,shadowSizeFactor}*scale,garbageCollector[key+"_SHADOW"].decal,scale/4,shadowCol);
|
||||
DrawDecal(pos,garbageCollector[key].decal,scale,col);
|
||||
}
|
||||
|
||||
void PixelGameEngine::DrawStringDecal(Font&font, const olc::vf2d& pos, const std::u32string& sText, const Pixel col, const olc::vf2d& scale){
|
||||
@ -3507,15 +3544,52 @@ namespace olc
|
||||
DrawDecal(pos,garbageCollector[key].decal,scale/4,col);
|
||||
}
|
||||
|
||||
void PixelGameEngine::DrawShadowStringPropDecal(const olc::vf2d& pos, std::string_view sText, const Pixel col, const Pixel shadowCol, const olc::vf2d& scale,const float width,const float shadowSizeFactor){
|
||||
for(float y=-shadowSizeFactor;y<=shadowSizeFactor+0.1;y+=shadowSizeFactor/2){
|
||||
for(float x=-shadowSizeFactor;x<=shadowSizeFactor+0.1;x+=shadowSizeFactor/2){
|
||||
if(x!=0||y!=0){
|
||||
DrawStringPropDecal(pos+vf2d{x,y}, sText, shadowCol,scale,width);
|
||||
void PixelGameEngine::DrawShadowStringPropDecal(const olc::vf2d& pos, std::string_view sText, const Pixel col, const Pixel shadowCol, const olc::vf2d& scale,const float width,const float shadowSizeFactor,const bool disableDynamicScaling){
|
||||
struct DecalData{
|
||||
Decal*decal;
|
||||
float expireTime=0.0f;
|
||||
};
|
||||
if(sText.length()==0)return;
|
||||
static std::map<std::string,DecalData>garbageCollector;
|
||||
std::string key{sText};
|
||||
key+=std::to_string(width);
|
||||
if(!disableDynamicScaling){
|
||||
key+=scale.str();
|
||||
}
|
||||
if(!garbageCollector.count(key)){ //If the text key already exists, don't have to recreate the decal, just update the expire time.
|
||||
vi2d imageSize=GetWrappedTextSizeProp(sText,width,scale);
|
||||
Decal*newDecal=new Decal(new Sprite(imageSize.x/scale.x,imageSize.y/scale.x));
|
||||
garbageCollector[key].decal=newDecal;
|
||||
SetDrawTarget(newDecal->sprite);
|
||||
Clear(BLANK);
|
||||
DrawStringProp({0,0},sText,WHITE,1U,width/scale.x);
|
||||
newDecal->Update();
|
||||
float adjustedShadowSizeFactor=shadowSizeFactor*4;
|
||||
Decal*newShadowDecal=new Decal(new Sprite((imageSize.x/scale.x*4)+adjustedShadowSizeFactor*2,(imageSize.y/scale.x*4)+adjustedShadowSizeFactor*2));
|
||||
garbageCollector[key+"_SHADOW"].decal=newShadowDecal;
|
||||
SetDrawTarget(newShadowDecal->sprite);
|
||||
Clear(BLANK);
|
||||
for(float y=-adjustedShadowSizeFactor;y<=adjustedShadowSizeFactor+0.1;y+=adjustedShadowSizeFactor/2){
|
||||
for(float x=-adjustedShadowSizeFactor;x<=adjustedShadowSizeFactor+0.1;x+=adjustedShadowSizeFactor/2){
|
||||
if(x!=0||y!=0){
|
||||
DrawStringProp(vf2d{x,y}+vf2d{adjustedShadowSizeFactor,adjustedShadowSizeFactor}, sText, WHITE,4U,width/scale.x*4);
|
||||
}
|
||||
}
|
||||
}
|
||||
SetDrawTarget(nullptr);
|
||||
newShadowDecal->Update();
|
||||
}
|
||||
DrawStringPropDecal(pos, sText, col,scale,width);
|
||||
garbageCollector[key].expireTime=GetRuntime()+120.0f;
|
||||
garbageCollector[key+"_SHADOW"].expireTime=GetRuntime()+120.0f;
|
||||
std::erase_if(garbageCollector,[&](auto&key){
|
||||
if(key.second.expireTime<GetRuntime()){
|
||||
delete key.second.decal;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
DrawDecal(pos-vf2d{shadowSizeFactor,shadowSizeFactor}*scale,garbageCollector[key+"_SHADOW"].decal,scale/4,shadowCol);
|
||||
DrawDecal(pos,garbageCollector[key].decal,scale,col);
|
||||
}
|
||||
|
||||
void PixelGameEngine::DrawShadowString(const olc::vi2d& pos, std::string_view sText, Pixel col, const Pixel shadowCol, const olc::vf2d& scale,const float width,const float shadowSizeFactor){
|
||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user