Garbage collection for rendered truetype fonts implemented. Added CREDITS file. Removed strange forward declare requirement on util file.

pull/28/head
sigonasr2 1 year ago
parent 5331a3d443
commit d9b1908985
  1. 22
      Crawler/CREDITS
  2. 6
      Crawler/Crawler.vcxproj
  3. 9
      Crawler/LICENSE
  4. 2
      Crawler/Version.h
  5. 4
      Crawler/VisualNovel.cpp
  6. BIN
      Crawler/assets/Habbo.ttf
  7. BIN
      Crawler/assets/LCDBlock.ttf
  8. BIN
      Crawler/assets/LessRoundBox.ttf
  9. BIN
      Crawler/assets/Unknown.ttf
  10. BIN
      Crawler/assets/c64esque.ttf
  11. 8
      Crawler/assets/config/configuration.txt
  12. 5
      Crawler/olcPGEX_TTF.h
  13. 56
      Crawler/olcPixelGameEngine.h
  14. 7
      Crawler/util.h

@ -0,0 +1,22 @@
*** Minifantasy - Tiny Overworld v1.0 ***
Minifantasy is an original idea by Krishna Palacio
ERA OF FANTASY - GRASSLANDS
https://twitter.com/Namatnieks
https://aamatniekss.itch.io/grasslands-era-of-fantasy-pixelart-asset-pack
Portions of this software are copyright © 2023 The FreeType
Project (www.freetype.org). Please see LICENSE_FT.txt for more information.
All rights reserved.
Fonts used are public domain, however authors are credited as such:
c64esque by andraaspar
Habbo by Omni
Unknown by Anonymous
Fonts obtained from:
Nb Pixel Font Bundle: https://nimblebeastscollective.itch.io/nb-pixel-font-bundle
Nb Pixel Font Bundle 2: https://nimblebeastscollective.itch.io/nb-pixel-font-bundle-2

@ -132,6 +132,7 @@
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp20</LanguageStandard>
<AdditionalIncludeDirectories>C:\Users\sigon\Documents\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalOptions>/MP8 %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
@ -152,6 +153,7 @@
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp20</LanguageStandard>
<AdditionalOptions>/MP8 %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
@ -172,6 +174,7 @@
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp20</LanguageStandard>
<AdditionalOptions>/MP8 %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
@ -191,6 +194,7 @@
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp20</LanguageStandard>
<AdditionalIncludeDirectories>C:\Users\sigon\Documents\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalOptions>/MP8 %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
@ -215,6 +219,7 @@
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp20</LanguageStandard>
<AdditionalOptions>/MP8 %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
@ -238,6 +243,7 @@
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp20</LanguageStandard>
<AdditionalOptions>/MP8 %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>

@ -32,4 +32,13 @@ SUCH DAMAGE.
Portions of this software are copyright © 2023 The FreeType
Project (www.freetype.org). Please see LICENSE_FT.txt for more information.
All rights reserved.
Fonts used are public domain, however authors are credited as such:
c64esque by andraaspar
Habbo by Omni
Unknown by Anonymous
Fonts obtained from:
Nb Pixel Font Bundle: https://nimblebeastscollective.itch.io/nb-pixel-font-bundle
Nb Pixel Font Bundle 2: https://nimblebeastscollective.itch.io/nb-pixel-font-bundle-2
*/

@ -39,7 +39,7 @@ All rights reserved.
#define VERSION_MAJOR 0
#define VERSION_MINOR 2
#define VERSION_PATCH 1
#define VERSION_BUILD 3285
#define VERSION_BUILD 3298
#define stringify(a) stringify_(a)
#define stringify_(a) #a

@ -245,8 +245,8 @@ void VisualNovel::Draw(){
vf2d dialogDisplaySize={game->GetScreenSize().x-48.f,20.f};
Menu::DrawThemedWindow(dialogDisplayPos,dialogDisplaySize);
FontRect speakerTextSize=font.GetStringBounds(speakerDisplayName);
game->DrawShadowStringDecal(font,nameDisplayPos-vf2d{10,8}+(nameDisplayWindowSize+vf2d{24,0})/2-speakerTextSize.size/2,speakerDisplayName);
game->DrawShadowStringDecal(font,dialogDisplayPos-vf2d{10,10},activeText);
game->DrawStringDecal(font,nameDisplayPos-vf2d{10,8}+(nameDisplayWindowSize+vf2d{24,0})/2-speakerTextSize.size/2,speakerDisplayName);
game->DrawStringDecal(font,dialogDisplayPos-vf2d{10,10},activeText);
float yOffset=util::lerp(dialogDisplaySize.y+12,-8,textScrollTime/maxTextScrollTime);
game->DrawPolygonDecal(
Menu::GetPatchPart(1,1).Decal(),

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -61,7 +61,13 @@ story_background_image_location = backgrounds/
story_player_name = You
# Dialog font and size.
dialog_font_size = LessRoundBox,12
dialog_font_size = Habbo,12
# Location font and size.
location_font_size = Habbo,24
# Encrypted font and size.
encrypted_font_size = Unknown,16
# Whether or not to show individual data accesses from config data structure.
debug_access_options = 0

@ -365,6 +365,11 @@ namespace olc {
fallbacks.emplace_back(path, fontSize);
}
std::u32string GetFontName(){
std::string name=fontFace->family_name;
return std::u32string(name.begin(),name.end());
}
static bool init() {
FT_Error error = FT_Init_FreeType(&library);

@ -1026,6 +1026,7 @@ namespace olc
// Specify which Sprite should be the target of drawing functions, use nullptr
// to specify the primary screen
void SetDrawTarget(Sprite* target);
float GetRuntime() const;
// Gets the current Frames Per Second
uint32_t GetFPS() const;
// Gets last update of elapsed time
@ -1258,6 +1259,7 @@ namespace olc
uint32_t nLastFPS = 0;
bool bPixelCohesion = false;
DecalMode nDecalMode = DecalMode::NORMAL;
float fRunTime = 0.0f;
DecalStructure nDecalStructure = DecalStructure::FAN;
std::function<olc::Pixel(const int x, const int y, const olc::Pixel&, const olc::Pixel&)> funcPixelMode;
std::chrono::time_point<std::chrono::system_clock> m_tp1, m_tp2;
@ -2119,6 +2121,9 @@ namespace olc
return 0;
}
float PixelGameEngine::GetRuntime() const
{ return fRunTime; }
uint32_t PixelGameEngine::GetFPS() const
{ return nLastFPS; }
@ -3339,30 +3344,54 @@ namespace olc
}
void PixelGameEngine::DrawStringDecal(Font&font, const olc::vf2d& pos, const std::u32string& sText, const Pixel col, const olc::vf2d& scale){
struct DecalData{
Decal*decal;
float expireTime=0.0f;
};
if(sText.length()==0)return;
static Decal*temp=nullptr;
if(temp!=nullptr){
delete temp;
}
temp=font.RenderStringToDecal(sText,col);
DrawDecal(pos,temp,scale/4,col);
static std::map<std::u32string,DecalData>garbageCollector;
std::u32string key=font.GetFontName()+U"_"+sText;
if(!garbageCollector.count(key)){ //If the text key already exists, don't have to recreate the decal, just update the expire time.
garbageCollector[key].decal=font.RenderStringToDecal(sText,WHITE);
}
garbageCollector[key].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,garbageCollector[key].decal,scale/4,col);
}
void PixelGameEngine::DrawShadowStringDecal(Font&font, const olc::vf2d& pos, const std::u32string& sText, const Pixel col, const Pixel shadowCol, const olc::vf2d& scale,const float shadowSizeFactor){
struct DecalData{
Decal*decal;
float expireTime=0.0f;
};
if(sText.length()==0)return;
static Decal*temp=nullptr;
if(temp!=nullptr){
delete temp;
}
temp=font.RenderStringToDecal(sText,col);
static std::map<std::u32string,DecalData>garbageCollector;
std::u32string key=font.GetFontName()+U"_"+sText;
if(!garbageCollector.count(key)){ //If the text key already exists, don't have to recreate the decal, just update the expire time.
garbageCollector[key].decal=font.RenderStringToDecal(sText,WHITE);
}
garbageCollector[key].expireTime=GetRuntime()+120.0f;
std::erase_if(garbageCollector,[&](auto&key){
if(key.second.expireTime<GetRuntime()){
delete key.second.decal;
return true;
}
return false;
});
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){
DrawDecal(pos+vf2d{x,y},temp,scale/4,shadowCol);
DrawDecal(pos+vf2d{x,y},garbageCollector[key].decal,scale/4,shadowCol);
}
}
}
DrawDecal(pos,temp,scale/4,col);
DrawDecal(pos,garbageCollector[key].decal,scale/4,col);
}
void PixelGameEngine::DrawShadowStringPropDecal(const olc::vf2d& pos, const std::string& sText, const Pixel col, const Pixel shadowCol, const olc::vf2d& scale,const float shadowSizeFactor){
@ -3990,6 +4019,7 @@ namespace olc
// Our time per frame coefficient
float fElapsedTime = elapsedTime.count();
fLastElapsed = fElapsedTime;
fRunTime += fElapsedTime;
if (bConsoleSuspendTime)
fElapsedTime = 0.0f;

@ -38,13 +38,8 @@ All rights reserved.
#pragma once
#include <stdlib.h>
#include "olcUTIL_Geometry2D.h"
#if defined(__EMSCRIPTEN__)
#include "olcPGEX_TTF.h"
#else
class olc::Font;
#endif
namespace util{
namespace olc::util{
//Returns 0-range (as a float).
float random(float range);
//Returns a normalized vector pointing from posFrom towards posTo.

Loading…
Cancel
Save