Skip to content

Commit 74ef41e

Browse files
committed
Improve font rendering test suite.
Fixed some minor issues cleaning up memory while destroying the engine (this is to be able to create a new window and load resources without issues, a not very common behavior but needed for tests).
1 parent 984262e commit 74ef41e

File tree

10 files changed

+206
-74
lines changed

10 files changed

+206
-74
lines changed
31.4 KB
Loading
23.4 KB
Loading

include/eepp/system/singleton.hpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
\
1515
static T* instance(); \
1616
\
17-
static void destroySingleton();
17+
static void destroySingleton(); \
18+
\
19+
static void detachSingleton();
1820

1921
#define SINGLETON_DECLARE_IMPLEMENTATION( T ) \
2022
\
@@ -32,7 +34,9 @@
3234
\
3335
T* T::instance() { return createSingleton(); } \
3436
\
35-
void T::destroySingleton() { eeSAFE_DELETE( ms_singleton ); }
37+
void T::destroySingleton() { eeSAFE_DELETE( ms_singleton ); } \
38+
\
39+
void T::detachSingleton() { ms_singleton = nullptr; }
3640

3741
namespace EE { namespace System {
3842

@@ -59,6 +63,9 @@ template <typename T> class Singleton {
5963

6064
/** Destroy the singleton instance */
6165
static void destroySingleton() { eeSAFE_DELETE( ms_singleton ); }
66+
67+
/** Detaches the existing singleton. Instance will keep existing but not associated */
68+
static void detachSingleton() { ms_singleton = nullptr; }
6269
};
6370

6471
}} // namespace EE::System

include/eepp/ui/uiapplication.hpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,13 @@ class EE_API UIApplication {
1616
struct Settings {
1717
Settings() {}
1818

19-
Settings( std::optional<Float> pixelDensity, bool loadBaseResources = true,
20-
Font* baseFont = nullptr, std::optional<std::string> baseStyleSheetPath = {},
21-
Font* emojiFont = nullptr );
19+
Settings( std::optional<std::string> basePath, std::optional<Float> pixelDensity = {},
20+
bool loadBaseResources = true, Font* baseFont = nullptr,
21+
std::optional<std::string> baseStyleSheetPath = {}, Font* emojiFont = nullptr );
2222

23+
//! By default it will use the current process path as the base path. This will set the
24+
//! default working directory.
25+
std::optional<std::string> basePath;
2326
//! Not setting anything will automatically try to detect the main screen pixel density
2427
std::optional<Float> pixelDensity;
2528
//! Must be set to true in order to initialize the basic UI resources (font and UI theme).
@@ -52,12 +55,19 @@ class EE_API UIApplication {
5255
//! Document
5356
UISceneNode* getUI() const;
5457

58+
//! Runs the application until window is closed
59+
//! @return EXIT_SUCCESS if application run successfully
5560
int run();
5661

62+
//! Set if the application must show the memory manager result after closing the main window.
63+
void setShowMemoryManagerResult( bool show );
64+
bool showMemoryManagerResult() const;
65+
5766
protected:
5867
UISceneNode* mUISceneNode{ nullptr };
5968
EE::Window::Window* mWindow{ nullptr };
6069
bool mDidRun{ false };
70+
bool mShowMemoryManagerResult{ false };
6171
};
6272

6373
}} // namespace EE::UI

src/eepp/graphics/primitives.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,17 @@
77

88
namespace EE { namespace Graphics {
99

10-
static GlobalBatchRenderer* sBR = NULL;
11-
1210
Primitives::Primitives() :
1311
mFillMode( DRAW_FILL ),
1412
mBlendMode( BlendMode::Alpha() ),
1513
mLineWidth( 1.f ),
1614
mForceDraw( true ) {
17-
if ( NULL == sBR ) {
18-
sBR = GlobalBatchRenderer::instance();
19-
}
2015
}
2116

2217
Primitives::~Primitives() {}
2318

2419
void Primitives::drawPoint( const Vector2f& p, const Float& pointSize ) {
20+
auto sBR = GlobalBatchRenderer::instance();
2521
sBR->setPointSize( pointSize );
2622

2723
sBR->setTexture( NULL );
@@ -34,6 +30,7 @@ void Primitives::drawPoint( const Vector2f& p, const Float& pointSize ) {
3430
}
3531

3632
void Primitives::drawLine( const Line2f& line ) {
33+
auto sBR = GlobalBatchRenderer::instance();
3734
sBR->setLineWidth( mLineWidth );
3835

3936
sBR->setTexture( NULL );
@@ -47,6 +44,7 @@ void Primitives::drawLine( const Line2f& line ) {
4744

4845
void Primitives::drawTriangle( const Triangle2f& t, const Color& Color1, const Color& Color2,
4946
const Color& Color3 ) {
47+
auto sBR = GlobalBatchRenderer::instance();
5048
sBR->setTexture( NULL );
5149
sBR->setBlendMode( mBlendMode );
5250

@@ -141,6 +139,7 @@ void Primitives::drawArc( const Vector2f& p, const Float& radius, Uint32 segment
141139

142140
Float angleShift = 360 / static_cast<Float>( segmentsCount );
143141
Float arcAngleA = arcAngle > 360 ? arcAngle - 360 * std::floor( arcAngle / 360 ) : arcAngle;
142+
auto sBR = GlobalBatchRenderer::instance();
144143

145144
sBR->setTexture( NULL );
146145

@@ -197,6 +196,7 @@ void Primitives::drawArc( const Vector2f& p, const Float& radius, Uint32 segment
197196
void Primitives::drawRectangle( const Rectf& R, const Color& TopLeft, const Color& BottomLeft,
198197
const Color& BottomRight, const Color& TopRight, const Float& Angle,
199198
const Vector2f& Scale ) {
199+
auto sBR = GlobalBatchRenderer::instance();
200200
sBR->setTexture( NULL );
201201
sBR->setBlendMode( mBlendMode );
202202

@@ -242,6 +242,7 @@ void Primitives::drawRectangle( const Rectf& R, const Float& Angle, const Vector
242242
}
243243

244244
void Primitives::drawRectangle( const Rectf& R ) {
245+
auto sBR = GlobalBatchRenderer::instance();
245246
sBR->setTexture( NULL );
246247
sBR->setBlendMode( mBlendMode );
247248

@@ -269,6 +270,7 @@ void Primitives::drawRoundedRectangle( const Rectf& R, const Color& TopLeft,
269270
const Color& BottomLeft, const Color& BottomRight,
270271
const Color& TopRight, const Float& Angle,
271272
const Vector2f& Scale, const unsigned int& Corners ) {
273+
auto sBR = GlobalBatchRenderer::instance();
272274
sBR->setTexture( NULL );
273275
sBR->setBlendMode( mBlendMode );
274276

@@ -356,6 +358,7 @@ void Primitives::drawRoundedRectangle( const Rectf& R, const Float& Angle, const
356358
void Primitives::drawQuad( const Quad2f& q, const Color& Color1, const Color& Color2,
357359
const Color& Color3, const Color& Color4, const Float& OffsetX,
358360
const Float& OffsetY ) {
361+
auto sBR = GlobalBatchRenderer::instance();
359362
sBR->setTexture( NULL );
360363
sBR->setBlendMode( mBlendMode );
361364

@@ -390,6 +393,7 @@ void Primitives::drawQuad( const Quad2f& q, const Float& OffsetX, const Float& O
390393
}
391394

392395
void Primitives::drawPolygon( const Polygon2f& p ) {
396+
auto sBR = GlobalBatchRenderer::instance();
393397
sBR->setTexture( NULL );
394398
sBR->setBlendMode( mBlendMode );
395399

@@ -416,6 +420,7 @@ void Primitives::drawPolygon( const Polygon2f& p ) {
416420
}
417421

418422
void Primitives::drawBatch() {
423+
auto sBR = GlobalBatchRenderer::instance();
419424
if ( mForceDraw )
420425
sBR->draw();
421426
else

src/eepp/graphics/text.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,12 @@ shapeAndRun( const String& string, FontTrueType* font, Uint32 characterSize, Uin
117117
static const hb_feature_t features[] = {
118118
hb_feature_t{ HB_TAG( 'k', 'e', 'r', 'n' ), 0, HB_FEATURE_GLOBAL_START,
119119
HB_FEATURE_GLOBAL_END },
120+
hb_feature_t{ HB_TAG( 'l', 'i', 'g', 'a' ), 0, HB_FEATURE_GLOBAL_START,
121+
HB_FEATURE_GLOBAL_END },
122+
hb_feature_t{ HB_TAG( 'c', 'l', 'i', 'g' ), 0, HB_FEATURE_GLOBAL_START,
123+
HB_FEATURE_GLOBAL_END },
124+
hb_feature_t{ HB_TAG( 'd', 'l', 'i', 'g' ), 0, HB_FEATURE_GLOBAL_START,
125+
HB_FEATURE_GLOBAL_END },
120126
};
121127

122128
// whitelist cross-platforms shapers only
@@ -128,7 +134,8 @@ shapeAndRun( const String& string, FontTrueType* font, Uint32 characterSize, Uin
128134
break;
129135
}
130136

131-
hb_shape_full( static_cast<hb_font_t*>( font->hb() ), hbBuffer, features, 1, shaper_list );
137+
hb_shape_full( static_cast<hb_font_t*>( font->hb() ), hbBuffer, features,
138+
eeARRAY_SIZE( features ), shaper_list );
132139

133140
// from the shaped text we get the glyphs and positions
134141
unsigned int glyphCount;

src/eepp/graphics/textureatlasmanager.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ TextureAtlasManager::TextureAtlasManager() :
1212
add( GlobalTextureAtlas::instance() );
1313
}
1414

15-
TextureAtlasManager::~TextureAtlasManager() {}
15+
TextureAtlasManager::~TextureAtlasManager() {
16+
GlobalTextureAtlas::detachSingleton();
17+
}
1618

1719
TextureAtlas* TextureAtlasManager::loadFromFile( const std::string& TextureAtlasPath ) {
1820
TextureAtlasLoader loader( TextureAtlasPath );

src/eepp/ui/uiapplication.cpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,13 @@ UIApplication::UIApplication( const WindowSettings& windowSettings, const Settin
3737
displayManager->getDisplayIndex( mWindow->getCurrentDisplayIndex() )
3838
->getPixelDensity() ) );
3939

40-
FileSystem::changeWorkingDirectory( Sys::getProcessPath() );
40+
if ( !appSettings.basePath || appSettings.basePath->empty() ) {
41+
FileSystem::changeWorkingDirectory( Sys::getProcessPath() );
42+
} else {
43+
std::string path( *appSettings.basePath );
44+
FileSystem::dirAddSlashAtEnd( path );
45+
FileSystem::changeWorkingDirectory( path );
46+
}
4147

4248
mUISceneNode = UISceneNode::New();
4349
SceneManager::instance()->add( mUISceneNode );
@@ -78,7 +84,8 @@ UIApplication::UIApplication( const WindowSettings& windowSettings, const Settin
7884

7985
UIApplication::~UIApplication() {
8086
Engine::destroySingleton();
81-
MemoryManager::showResults();
87+
if ( mShowMemoryManagerResult )
88+
MemoryManager::showResults();
8289
}
8390

8491
EE::Window::Window* UIApplication::getWindow() const {
@@ -110,13 +117,23 @@ int UIApplication::run() {
110117
return mDidRun ? EXIT_SUCCESS : EXIT_FAILURE;
111118
}
112119

113-
UIApplication::Settings::Settings( std::optional<Float> pixelDensity, bool loadBaseResources,
120+
UIApplication::Settings::Settings( std::optional<std::string> basePath,
121+
std::optional<Float> pixelDensity, bool loadBaseResources,
114122
Font* baseFont, std::optional<std::string> baseStyleSheetPath,
115123
Font* emojiFont ) :
124+
basePath( basePath ),
116125
pixelDensity( pixelDensity ),
117126
loadBaseResources( loadBaseResources ),
118127
baseFont( baseFont ),
119128
baseStyleSheetPath( baseStyleSheetPath ),
120129
emojiFont( emojiFont ) {}
121130

131+
void UIApplication::setShowMemoryManagerResult( bool show ) {
132+
mShowMemoryManagerResult = show;
133+
}
134+
135+
bool UIApplication::showMemoryManagerResult() const {
136+
return mShowMemoryManagerResult;
137+
}
138+
122139
}} // namespace EE::UI

0 commit comments

Comments
 (0)