From ba7594b83ce96ef29706bdcf1796ea7bad551305 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Thu, 21 Nov 2019 23:29:23 -0300 Subject: [PATCH] Added FrameRateLimit to Context variables. Updated SOIL2 and efsw. Minor changes in UILoader. --HG-- branch : dev --- bin/assets/ee.ini | 1 + include/eepp/window/window.hpp | 5 ++- premake4.lua | 2 +- premake5.lua | 2 +- src/eepp/ui/uiloader.cpp | 66 +++++++++++++++++++++++----------- src/eepp/window/engine.cpp | 7 ++-- src/eepp/window/window.cpp | 1 + src/test/eetest.cpp | 3 +- 8 files changed, 59 insertions(+), 28 deletions(-) diff --git a/bin/assets/ee.ini b/bin/assets/ee.ini index 32feb5cf3..1b7f1dcf0 100755 --- a/bin/assets/ee.ini +++ b/bin/assets/ee.ini @@ -16,3 +16,4 @@ UseShaders = 1 Music = 0 PixelDensity = auto DebugUI = 0 +FrameRateLimit = 0 diff --git a/include/eepp/window/window.hpp b/include/eepp/window/window.hpp index 6d9261151..3625d2933 100644 --- a/include/eepp/window/window.hpp +++ b/include/eepp/window/window.hpp @@ -79,11 +79,12 @@ class WindowSettings { class ContextSettings { public: - inline ContextSettings( bool vsync, EEGL_version version = GLv_default, bool doubleBuffering = true, Uint32 depthBufferSize = 24, Uint32 stencilBufferSize = 1, Uint32 multisamples = 0, bool sharedGLContext = true ) : + inline ContextSettings( bool vsync, EEGL_version version = GLv_default, bool doubleBuffering = true, Uint32 depthBufferSize = 24, Uint32 stencilBufferSize = 1, Uint32 multisamples = 0, bool sharedGLContext = true, Int32 frameRateLimit = 0 ) : Version( version ), DepthBufferSize( depthBufferSize ), StencilBufferSize( stencilBufferSize ), Multisamples( multisamples ), + FrameRateLimit( frameRateLimit ), VSync( vsync ), DoubleBuffering( doubleBuffering ), SharedGLContext( sharedGLContext ) @@ -94,6 +95,7 @@ class ContextSettings { DepthBufferSize( 24 ), StencilBufferSize( 1 ), Multisamples( 0 ), + FrameRateLimit( 0 ), VSync( false ), DoubleBuffering( true ), SharedGLContext( true ) @@ -103,6 +105,7 @@ class ContextSettings { Uint32 DepthBufferSize; Uint32 StencilBufferSize; Uint32 Multisamples; + Int32 FrameRateLimit; bool VSync; bool DoubleBuffering; bool SharedGLContext; diff --git a/premake4.lua b/premake4.lua index 09ea1df40..ea172dfe5 100644 --- a/premake4.lua +++ b/premake4.lua @@ -143,7 +143,7 @@ newoption { trigger = "with-static-eepp", description = "Force to build the demo newoption { trigger = "with-static-backend", description = "It will try to compile the library with a static backend (only for gcc and mingw).\n\t\t\t\tThe backend should be placed in libs/your_platform/libYourBackend.a" } newoption { trigger = "with-gles2", description = "Compile with GLES2 support" } newoption { trigger = "with-gles1", description = "Compile with GLES1 support" } -newoption { trigger = "use-frameworks", description = "In Mac OS X it will try to link the external libraries from its frameworks. For example, instead of linking against SDL2 it will link agains SDL2.framework." } +newoption { trigger = "use-frameworks", description = "In macOS it will try to link the external libraries from its frameworks. For example, instead of linking against SDL2 it will link agains SDL2.framework." } newoption { trigger = "with-backend", description = "Select the backend to use for window and input handling.\n\t\t\tIf no backend is selected or if the selected is not installed the script will search for a backend present in the system, and will use it.", diff --git a/premake5.lua b/premake5.lua index 0bd2904cb..bf1a10238 100644 --- a/premake5.lua +++ b/premake5.lua @@ -6,7 +6,7 @@ newoption { trigger = "with-static-eepp", description = "Force to build the demo newoption { trigger = "with-static-backend", description = "It will try to compile the library with a static backend (only for gcc and mingw).\n\t\t\t\tThe backend should be placed in libs/your_platform/libYourBackend.a" } newoption { trigger = "with-gles2", description = "Compile with GLES2 support" } newoption { trigger = "with-gles1", description = "Compile with GLES1 support" } -newoption { trigger = "use-frameworks", description = "In Mac OS X it will try to link the external libraries from its frameworks. For example, instead of linking against SDL2 it will link agains SDL2.framework." } +newoption { trigger = "use-frameworks", description = "In macOS it will try to link the external libraries from its frameworks. For example, instead of linking against SDL2 it will link against SDL2.framework." } newoption { trigger = "with-backend", description = "Select the backend to use for window and input handling.\n\t\t\tIf no backend is selected or if the selected is not installed the script will search for a backend present in the system, and will use it.", diff --git a/src/eepp/ui/uiloader.cpp b/src/eepp/ui/uiloader.cpp index 596e05276..6fbf9695a 100644 --- a/src/eepp/ui/uiloader.cpp +++ b/src/eepp/ui/uiloader.cpp @@ -12,7 +12,7 @@ UILoader::UILoader() : UIWidget( "loader" ), mRadius(0), mOutlineThickness( PixelDensity::dpToPx(8) ), - mColor( Color::Green ), + mColor( Color::Transparent ), mArcAngle(0), mArcStartAngle(0), mProgress(0), @@ -25,7 +25,7 @@ UILoader::UILoader() : mArc.setFillMode( DRAW_FILL ); mCircle.setFillMode( DRAW_FILL ); - setFillColor( mColor ); + setFillColor( Color::White ); } UILoader::~UILoader() { @@ -63,7 +63,7 @@ void UILoader::draw() { } void UILoader::scheduledUpdate( const Time& time ) { - if ( mVisible && isMeOrParentTreeVisible() ) + if ( mVisible && isMeOrParentTreeVisible() && mAnimationSpeed != 0.f ) invalidateDraw(); if ( mIndeterminate ) { @@ -87,8 +87,11 @@ void UILoader::scheduledUpdate( const Time& time ) { } UILoader * UILoader::setOutlineThickness( const Float& thickness ) { - mOutlineThickness = thickness; - mCircle.setRadius( PixelDensity::dpToPx( mRadius ) - PixelDensity::dpToPx( mOutlineThickness ) ); + if ( thickness != mOutlineThickness ) { + mOutlineThickness = thickness; + mCircle.setRadius( PixelDensity::dpToPx( mRadius ) - PixelDensity::dpToPx( mOutlineThickness ) ); + invalidateDraw(); + } return this; } @@ -97,10 +100,13 @@ const Float& UILoader::getOutlineThickness() const { } UILoader * UILoader::setRadius( const Float& radius ) { - mRadius = radius; - Float rRadius = PixelDensity::dpToPx( radius ); - mCircle.setRadius( rRadius - PixelDensity::dpToPx( mOutlineThickness ) ); - mArc.setRadius( rRadius ); + if ( radius != mRadius ) { + mRadius = radius; + Float rRadius = PixelDensity::dpToPx( radius ); + mCircle.setRadius( rRadius - PixelDensity::dpToPx( mOutlineThickness ) ); + mArc.setRadius( rRadius ); + invalidateDraw(); + } return this; } @@ -109,9 +115,12 @@ const Float& UILoader::getRadius() const { } UILoader * UILoader::setFillColor( const Color& color ) { - mColor = color; - mArc.setColor( mColor ); - mCircle.setColor( mColor ); + if ( color != mColor ) { + mColor = color; + mArc.setColor( mColor ); + mCircle.setColor( mColor ); + invalidateDraw(); + } return this; } @@ -162,18 +171,24 @@ const bool& UILoader::isIndeterminate() const { } UILoader * UILoader::setIndeterminate( const bool& indeterminate ) { - mIndeterminate = indeterminate; + if ( indeterminate != mIndeterminate ) { + mIndeterminate = indeterminate; + invalidateDraw(); + } return this; } UILoader * UILoader::setProgress( const Float& progress ) { - mProgress = eemax( 0.f, eemin( progress, mMaxProgress ) ); + if ( progress != mProgress ) { + mProgress = eemax( 0.f, eemin( progress, mMaxProgress ) ); - if ( !mIndeterminate ) { - mArcAngle = progress / mMaxProgress * 360.f; - mArc.setArcAngle( mArcAngle ); + if ( !mIndeterminate ) { + mArcAngle = progress / mMaxProgress * 360.f; + mArc.setArcAngle( mArcAngle ); + } + + invalidateDraw(); } - return this; } @@ -186,7 +201,10 @@ const Float& UILoader::getMaxProgress() const { } UILoader * UILoader::setMaxProgress( const Float& maxProgress ) { - mMaxProgress = maxProgress; + if ( maxProgress != mMaxProgress ) { + mMaxProgress = maxProgress; + invalidateDraw(); + } return this; } @@ -195,7 +213,10 @@ const Float& UILoader::getAnimationSpeed() const { } UILoader * UILoader::setAnimationSpeed( const Float& animationSpeed ) { - mAnimationSpeed = animationSpeed; + if ( animationSpeed != mAnimationSpeed ) { + mAnimationSpeed = animationSpeed; + invalidateDraw(); + } return this; } @@ -230,7 +251,10 @@ Float UILoader::getArcStartAngle() const { } UILoader * UILoader::setArcStartAngle( const Float& arcStartAngle ) { - mArcStartAngle = arcStartAngle; + if ( arcStartAngle != mArcStartAngle ) { + mArcStartAngle = arcStartAngle; + invalidateDraw(); + } return this; } diff --git a/src/eepp/window/engine.cpp b/src/eepp/window/engine.cpp index 347174304..af1eabf7a 100755 --- a/src/eepp/window/engine.cpp +++ b/src/eepp/window/engine.cpp @@ -309,13 +309,14 @@ ContextSettings Engine::createContextSettings( IniFile * ini, std::string iniKey else if ( "2" == GLVersion || "opengl 2" == GLVersion || "gl2" == GLVersion || "gl 2" == GLVersion ) GLVer = GLv_2; else GLVer = GLv_default; - bool doubleBuffering = ini->getValueB( iniKeyName, "DoubleBuffering", true ); int depthBufferSize = ini->getValueI( iniKeyName, "DepthBufferSize", 24 ); int stencilBufferSize = ini->getValueI( iniKeyName, "StencilBufferSize", 1 ); int multisamples = ini->getValueI( iniKeyName, "Multisamples", 0 ); - bool sharedGLContext = ini->getValueB( iniKeyName, "SharedGLContext", false ); + int frameRateLimit = ini->getValueI( iniKeyName, "FrameRateLimit", 0 ); + bool doubleBuffering = ini->getValueB( iniKeyName, "DoubleBuffering", true ); + bool sharedGLContext = ini->getValueB( iniKeyName, "SharedGLContext", false ); - return ContextSettings( VSync, GLVer, doubleBuffering, depthBufferSize, stencilBufferSize, multisamples, sharedGLContext ); + return ContextSettings( VSync, GLVer, doubleBuffering, depthBufferSize, stencilBufferSize, multisamples, sharedGLContext, frameRateLimit ); } ContextSettings Engine::createContextSettings( std::string iniPath, std::string iniKeyName ) { diff --git a/src/eepp/window/window.cpp b/src/eepp/window/window.cpp index 2582829d4..d05247d1a 100644 --- a/src/eepp/window/window.cpp +++ b/src/eepp/window/window.cpp @@ -50,6 +50,7 @@ Window::Window( WindowSettings Settings, ContextSettings Context, Clipboard * Cl { mWindow.WindowConfig = Settings; mWindow.ContextConfig = Context; + setFrameRateLimit( Context.FrameRateLimit ); } Window::~Window() { diff --git a/src/test/eetest.cpp b/src/test/eetest.cpp index a7454ae22..6e865f5ed 100644 --- a/src/test/eetest.cpp +++ b/src/test/eetest.cpp @@ -135,6 +135,7 @@ void EETest::init() { #endif mMusEnabled = Ini.getValueB( "EEPP", "Music", false ); + mLastFPSLimit = Ini.getValueI( "EEPP", "FrameRateLimit", 0 ); Int32 StartScreen = Ini.getValueI( "EEPP", "StartScreen", 5 ); WindowSettings WinSettings = EE->createWindowSettings( &Ini ); @@ -1996,7 +1997,7 @@ void EETest::process() { if ( NULL != mWindow && mWindow->isOpen() ) { TestInstance = this; - mWindow->runMainLoop( &mainLoop ); + mWindow->runMainLoop( &mainLoop, mLastFPSLimit ); } end();