From 732c60da46b5c0ce095ae4b861400d3be4dafccb Mon Sep 17 00:00:00 2001 From: Alexis Maiquez Date: Wed, 8 Feb 2023 18:48:19 +0100 Subject: [PATCH] More code cleanups Update .clang-format Signed-off-by: Alexis Maiquez --- .clang-format | 183 ++++-------------- src/Steam/FileSystem/FileSystem.cpp | 6 +- .../Application/CApplicationContext.cpp | 46 +++-- .../Application/CApplicationContext.h | 2 +- .../Application/CWallpaperApplication.cpp | 6 +- .../Assets/CAssetLoadException.h | 2 +- .../Assets/CCombinedContainer.cpp | 6 + .../Assets/CCombinedContainer.h | 4 +- src/WallpaperEngine/Assets/CContainer.cpp | 3 +- src/WallpaperEngine/Assets/CContainer.h | 2 +- src/WallpaperEngine/Assets/CDirectory.cpp | 6 +- src/WallpaperEngine/Assets/CDirectory.h | 4 +- src/WallpaperEngine/Assets/CPackage.cpp | 4 +- src/WallpaperEngine/Assets/CPackage.h | 2 +- .../Assets/CPackageLoadException.h | 2 +- src/WallpaperEngine/Assets/CTexture.cpp | 77 +++++--- src/WallpaperEngine/Assets/CTexture.h | 6 +- .../Assets/CVirtualContainer.h | 4 +- src/WallpaperEngine/Assets/ITexture.h | 3 +- src/WallpaperEngine/Audio/CAudioContext.h | 2 +- src/WallpaperEngine/Audio/CAudioStream.cpp | 73 +++---- src/WallpaperEngine/Audio/CAudioStream.h | 6 +- .../Audio/Drivers/CSDLAudioDriver.cpp | 11 +- src/WallpaperEngine/Core/CObject.cpp | 29 +-- src/WallpaperEngine/Core/CObject.h | 6 +- src/WallpaperEngine/Core/CProject.h | 2 +- src/WallpaperEngine/Core/CScene.h | 2 +- src/WallpaperEngine/Core/CVideo.h | 6 +- src/WallpaperEngine/Core/CWallpaper.cpp | 7 +- src/WallpaperEngine/Core/CWallpaper.h | 4 +- src/WallpaperEngine/Core/Core.cpp | 6 +- src/WallpaperEngine/Core/Core.h | 2 +- src/WallpaperEngine/Core/Objects/CEffect.cpp | 20 +- src/WallpaperEngine/Core/Objects/CEffect.h | 2 +- src/WallpaperEngine/Core/Objects/CImage.cpp | 8 +- src/WallpaperEngine/Core/Objects/CImage.h | 8 +- .../Core/Objects/CParticle.cpp | 6 +- src/WallpaperEngine/Core/Objects/CParticle.h | 2 +- src/WallpaperEngine/Core/Objects/CSound.cpp | 8 +- src/WallpaperEngine/Core/Objects/CSound.h | 4 +- .../Effects/Constants/CShaderConstant.h | 2 +- .../Effects/Constants/CShaderConstantFloat.h | 2 +- .../Constants/CShaderConstantInteger.h | 2 +- .../Constants/CShaderConstantVector2.cpp | 2 +- .../Constants/CShaderConstantVector2.h | 3 +- .../Constants/CShaderConstantVector3.h | 2 +- .../Core/Objects/Images/CMaterial.cpp | 15 +- .../Core/Objects/Images/CMaterial.h | 6 +- .../Core/Objects/Images/Materials/CPass.cpp | 27 +-- .../Core/Objects/Images/Materials/CPass.h | 4 +- .../Core/Objects/Particles/CControlPoint.cpp | 12 +- .../Core/Objects/Particles/CControlPoint.h | 7 +- .../Core/Objects/Particles/CEmitter.cpp | 4 + .../Core/Objects/Particles/CEmitter.h | 3 +- .../Core/Objects/Particles/CInitializer.cpp | 2 +- .../Core/Objects/Particles/CInitializer.h | 4 +- .../Particles/Initializers/CAlphaRandom.cpp | 4 +- .../Particles/Initializers/CAlphaRandom.h | 6 +- .../Initializers/CAngularVelocityRandom.h | 2 +- .../Particles/Initializers/CColorRandom.h | 2 +- .../Initializers/CLifeTimeRandom.cpp | 4 +- .../Particles/Initializers/CLifeTimeRandom.h | 6 +- .../Initializers/CRotationRandom.cpp | 24 +-- .../Particles/Initializers/CRotationRandom.h | 18 +- .../Particles/Initializers/CSizeRandom.cpp | 4 +- .../Particles/Initializers/CSizeRandom.h | 6 +- .../Initializers/CTurbulentVelocityRandom.h | 2 +- .../Particles/Initializers/CVelocityRandom.h | 2 +- .../Core/Projects/CPropertyBoolean.cpp | 10 +- .../Core/Projects/CPropertyBoolean.h | 4 +- .../Core/Projects/CPropertyColor.cpp | 8 +- .../Core/Projects/CPropertyColor.h | 2 +- .../Core/Projects/CPropertyCombo.cpp | 18 +- .../Core/Projects/CPropertyCombo.h | 2 +- .../Core/Projects/CPropertySlider.cpp | 13 +- .../Core/Projects/CPropertySlider.h | 2 +- .../Core/Projects/CPropertyText.h | 2 +- src/WallpaperEngine/Core/Scenes/CCamera.h | 2 +- .../Core/Scenes/CProjection.cpp | 9 +- src/WallpaperEngine/Core/Scenes/CProjection.h | 4 +- .../Core/UserSettings/CUserSettingBoolean.cpp | 14 +- .../Core/UserSettings/CUserSettingBoolean.h | 2 +- .../Core/UserSettings/CUserSettingFloat.cpp | 16 +- .../Core/UserSettings/CUserSettingFloat.h | 2 +- .../Core/UserSettings/CUserSettingValue.h | 4 +- .../Core/UserSettings/CUserSettingVector3.cpp | 10 +- .../Core/UserSettings/CUserSettingVector3.h | 2 +- src/WallpaperEngine/Input/CInputContext.h | 2 +- src/WallpaperEngine/Input/CMouseInput.cpp | 2 +- src/WallpaperEngine/Input/CMouseInput.h | 4 +- src/WallpaperEngine/Render/CCamera.cpp | 15 +- src/WallpaperEngine/Render/CCamera.h | 3 +- src/WallpaperEngine/Render/CFBO.cpp | 12 +- src/WallpaperEngine/Render/CFBO.h | 2 +- src/WallpaperEngine/Render/CObject.cpp | 5 +- src/WallpaperEngine/Render/CObject.h | 2 +- src/WallpaperEngine/Render/CRenderContext.cpp | 36 ++-- src/WallpaperEngine/Render/CScene.cpp | 21 +- src/WallpaperEngine/Render/CTextureCache.cpp | 3 +- src/WallpaperEngine/Render/CVideo.cpp | 23 +-- src/WallpaperEngine/Render/CVideo.h | 2 +- src/WallpaperEngine/Render/CWallpaper.cpp | 17 +- .../Render/Drivers/COpenGLDriver.cpp | 5 +- .../Render/Drivers/COpenGLDriver.h | 2 +- .../Render/Objects/CEffect.cpp | 2 +- src/WallpaperEngine/Render/Objects/CEffect.h | 2 +- src/WallpaperEngine/Render/Objects/CImage.cpp | 73 ++++--- src/WallpaperEngine/Render/Objects/CImage.h | 14 +- .../Render/Objects/Effects/CMaterial.h | 2 +- .../Render/Objects/Effects/CPass.cpp | 52 +++-- .../Render/Shaders/Compiler.cpp | 93 ++++----- src/WallpaperEngine/Render/Shaders/Compiler.h | 4 +- .../Shaders/Variables/CShaderVariable.cpp | 4 +- .../Shaders/Variables/CShaderVariable.h | 2 +- .../Variables/CShaderVariableFloat.cpp | 4 +- .../Shaders/Variables/CShaderVariableFloat.h | 2 +- .../Variables/CShaderVariableVector3.cpp | 2 +- .../Variables/CShaderVariableVector3.h | 2 +- .../Variables/CShaderVariableVector4.cpp | 4 +- .../Variables/CShaderVariableVector4.h | 2 +- 120 files changed, 613 insertions(+), 692 deletions(-) diff --git a/.clang-format b/.clang-format index 5c313af..1f44289 100644 --- a/.clang-format +++ b/.clang-format @@ -1,179 +1,66 @@ ---- -Language: Cpp -# BasedOnStyle: Microsoft +# Generated from CLion C/C++ Code Style settings +BasedOnStyle: LLVM AccessModifierOffset: -4 AlignAfterOpenBracket: Align -AlignArrayOfStructures: None -AlignConsecutiveMacros: None AlignConsecutiveAssignments: None -AlignConsecutiveBitFields: None -AlignConsecutiveDeclarations: None -AlignEscapedNewlines: Right -AlignOperands: Align -AlignTrailingComments: true -AllowAllArgumentsOnNextLine: true -AllowAllConstructorInitializersOnNextLine: true -AllowAllParametersOfDeclarationOnNextLine: true -AllowShortEnumsOnASingleLine: false -AllowShortBlocksOnASingleLine: Empty +AlignOperands: Align +AllowAllArgumentsOnNextLine: false +AllowAllConstructorInitializersOnNextLine: false +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortBlocksOnASingleLine: Always AllowShortCaseLabelsOnASingleLine: true -AllowShortFunctionsOnASingleLine: Inline +AllowShortFunctionsOnASingleLine: All +AllowShortIfStatementsOnASingleLine: Never AllowShortLambdasOnASingleLine: All -AllowShortIfStatementsOnASingleLine: WithoutElse -AllowShortLoopsOnASingleLine: true -AlwaysBreakAfterDefinitionReturnType: None +AllowShortLoopsOnASingleLine: false AlwaysBreakAfterReturnType: None -AlwaysBreakBeforeMultilineStrings: false -AlwaysBreakTemplateDeclarations: MultiLine -AttributeMacros: - - __capability -BinPackArguments: false -BinPackParameters: false +AlwaysBreakTemplateDeclarations: Yes +BreakBeforeBraces: Custom BraceWrapping: - AfterCaseLabel: false - AfterClass: true + AfterCaseLabel: false + AfterClass: true AfterControlStatement: Always - AfterEnum: true - AfterFunction: true - AfterNamespace: true - AfterObjCDeclaration: true - AfterStruct: true - AfterUnion: false - AfterExternBlock: true - BeforeCatch: true - BeforeElse: true - BeforeLambdaBody: false - BeforeWhile: false - IndentBraces: false - SplitEmptyFunction: true + AfterEnum: true + AfterFunction: true + AfterNamespace: true + AfterUnion: true + BeforeCatch: true + BeforeElse: true + IndentBraces: false + SplitEmptyFunction: false SplitEmptyRecord: true - SplitEmptyNamespace: true BreakBeforeBinaryOperators: None -BreakBeforeConceptDeclarations: true -BreakBeforeBraces: Allman -BreakBeforeInheritanceComma: false -BreakInheritanceList: BeforeColon BreakBeforeTernaryOperators: true -BreakConstructorInitializersBeforeComma: false -BreakConstructorInitializers: AfterColon -PackConstructorInitializers: Never -BreakAfterJavaFieldAnnotations: false -BreakStringLiterals: true -ColumnLimit: 120 -CommentPragmas: '^ IWYU pragma:' +BreakConstructorInitializers: BeforeColon +BreakInheritanceList: BeforeColon +ColumnLimit: 0 CompactNamespaces: false -ConstructorInitializerAllOnOneLineOrOnePerLine: false -ConstructorInitializerIndentWidth: 4 -ContinuationIndentWidth: 4 -Cpp11BracedListStyle: true -DeriveLineEnding: true -DerivePointerAlignment: false -DisableFormat: false -EmptyLineAfterAccessModifier: Never -EmptyLineBeforeAccessModifier: LogicalBlock -ExperimentalAutoDetectBinPacking: false -FixNamespaceComments: true -ForEachMacros: - - foreach - - Q_FOREACH - - BOOST_FOREACH -IfMacros: - - KJ_IF_MAYBE -IncludeBlocks: Preserve -IncludeCategories: - - Regex: '^"(llvm|llvm-c|clang|clang-c)/' - Priority: 2 - SortPriority: 0 - CaseSensitive: false - - Regex: '^(<|"(gtest|gmock|isl|json)/)' - Priority: 3 - SortPriority: 0 - CaseSensitive: false - - Regex: '.*' - Priority: 1 - SortPriority: 0 - CaseSensitive: false -IncludeIsMainRegex: '(Test)?$' -IncludeIsMainSourceRegex: '' -IndentAccessModifiers: false +ContinuationIndentWidth: 8 IndentCaseLabels: true -IndentCaseBlocks: true -IndentGotoLabels: true IndentPPDirectives: None -IndentExternBlock: AfterExternBlock -IndentRequires: false -IndentWidth: 4 -IndentWrappedFunctionNames: false -InsertTrailingCommas: None -JavaScriptQuotes: Leave -JavaScriptWrapImports: true +IndentWidth: 4 KeepEmptyLinesAtTheStartOfBlocks: true -LambdaBodyIndentation: Signature -MacroBlockBegin: '' -MacroBlockEnd: '' -MaxEmptyLinesToKeep: 1 +MaxEmptyLinesToKeep: 2 NamespaceIndentation: All -ObjCBinPackProtocolList: Auto -ObjCBlockIndentWidth: 2 -ObjCBreakBeforeNestedBlockParam: true ObjCSpaceAfterProperty: false ObjCSpaceBeforeProtocolList: true -PenaltyBreakAssignment: 2 -PenaltyBreakBeforeFirstCallParameter: 19 -PenaltyBreakComment: 300 -PenaltyBreakFirstLessLess: 120 -PenaltyBreakString: 1000 -PenaltyBreakTemplateDeclaration: 10 -PenaltyExcessCharacter: 1000000 -PenaltyReturnTypeOnItsOwnLine: 1000 -PenaltyIndentedWhitespace: 0 PointerAlignment: Left -PPIndentWidth: -1 -ReferenceAlignment: Pointer -ReflowComments: true -ShortNamespaceLines: 1 -SortIncludes: CaseSensitive -SortJavaStaticImport: Before -SortUsingDeclarations: true +ReflowComments: false SpaceAfterCStyleCast: true SpaceAfterLogicalNot: false SpaceAfterTemplateKeyword: true SpaceBeforeAssignmentOperators: true -SpaceBeforeCaseColon: false -SpaceBeforeCpp11BracedList: false +SpaceBeforeCpp11BracedList: true SpaceBeforeCtorInitializerColon: true SpaceBeforeInheritanceColon: true SpaceBeforeParens: Always -SpaceAroundPointerQualifiers: Default SpaceBeforeRangeBasedForLoopColon: true -SpaceInEmptyBlock: false SpaceInEmptyParentheses: false -SpacesBeforeTrailingComments: 1 -SpacesInAngles: Never -SpacesInConditionalStatement: false -SpacesInContainerLiterals: true +SpacesBeforeTrailingComments: 0 +SpacesInAngles: false SpacesInCStyleCastParentheses: false -SpacesInLineCommentPrefix: - Minimum: 1 - Maximum: -1 +SpacesInContainerLiterals: false SpacesInParentheses: false SpacesInSquareBrackets: false -SpaceBeforeSquareBrackets: true -BitFieldColonSpacing: Both -Standard: Latest -StatementAttributeLikeMacros: - - Q_EMIT -StatementMacros: - - Q_UNUSED - - QT_REQUIRE_VERSION -TabWidth: 4 -UseCRLF: false -UseTab: Never -WhitespaceSensitiveMacros: - - STRINGIZE - - PP_STRINGIZE - - BOOST_PP_STRINGIZE - - NS_SWIFT_NAME - - CF_SWIFT_NAME -... - +TabWidth: 4 +UseTab: ForContinuationAndIndentation diff --git a/src/Steam/FileSystem/FileSystem.cpp b/src/Steam/FileSystem/FileSystem.cpp index 9a1463f..99bf896 100644 --- a/src/Steam/FileSystem/FileSystem.cpp +++ b/src/Steam/FileSystem/FileSystem.cpp @@ -27,7 +27,7 @@ std::filesystem::path detectHomepath () std::filesystem::path path = home; - if (std::filesystem::is_directory (path) == false) + if (!std::filesystem::is_directory (path)) sLog.exception ("Cannot find home directory for current user, ", home, " is not a directory"); return home; @@ -41,7 +41,7 @@ std::filesystem::path Steam::FileSystem::workshopDirectory (int appID, const std { auto currentpath = std::filesystem::path (homepath) / *current / std::to_string (appID) / contentID; - if (std::filesystem::exists (currentpath) == false || std::filesystem::is_directory (currentpath) == false) + if (!std::filesystem::exists (currentpath) || !std::filesystem::is_directory (currentpath)) continue; return currentpath; @@ -58,7 +58,7 @@ std::filesystem::path Steam::FileSystem::appDirectory (const std::string& appDir { auto currentpath = std::filesystem::path (homepath) / *current / appDirectory / path; - if (std::filesystem::exists (currentpath) == false || std::filesystem::is_directory (currentpath) == false) + if (!std::filesystem::exists (currentpath) || !std::filesystem::is_directory (currentpath)) continue; return currentpath; diff --git a/src/WallpaperEngine/Application/CApplicationContext.cpp b/src/WallpaperEngine/Application/CApplicationContext.cpp index 8d9b07e..72b0e62 100644 --- a/src/WallpaperEngine/Application/CApplicationContext.cpp +++ b/src/WallpaperEngine/Application/CApplicationContext.cpp @@ -14,23 +14,23 @@ using namespace WallpaperEngine::Application; struct option long_options [] = { - {"screen-root", required_argument, 0, 'r'}, - {"pkg", required_argument, 0, 'p'}, - {"dir", required_argument, 0, 'd'}, - {"silent", no_argument, 0, 's'}, - {"volume", required_argument, 0, 'v'}, - {"help", no_argument, 0, 'h'}, - {"fps", required_argument, 0, 'f'}, - {"assets-dir", required_argument, 0, 'a'}, - {"screenshot", required_argument, 0, 'c'}, - {"list-properties", no_argument, 0, 'l'}, - {"set-property", required_argument, 0, 'o'}, - {nullptr, 0, 0, 0} + {"screen-root", required_argument, nullptr, 'r'}, + {"pkg", required_argument, nullptr, 'p'}, + {"dir", required_argument, nullptr, 'd'}, + {"silent", no_argument, nullptr, 's'}, + {"volume", required_argument, nullptr, 'v'}, + {"help", no_argument, nullptr, 'h'}, + {"fps", required_argument, nullptr, 'f'}, + {"assets-dir", required_argument, nullptr, 'a'}, + {"screenshot", required_argument, nullptr, 'c'}, + {"list-properties", no_argument, nullptr, 'l'}, + {"set-property", required_argument, nullptr, 'o'}, + {nullptr, 0, nullptr, 0} }; std::string stringPathFixes(const std::string& s) { - if (s.empty () == true) + if (s.empty ()) return s; std::string str (s); @@ -49,7 +49,8 @@ CApplicationContext::CApplicationContext (int argc, char* argv[]) : maximumFPS (30), audioVolume (128), audioEnabled (true), - onlyListProperties (false) + onlyListProperties (false), + screenshotFormat (FIF_UNKNOWN) { int c; @@ -96,7 +97,7 @@ CApplicationContext::CApplicationContext (int argc, char* argv[]) : break; case 'f': - maximumFPS = atoi (optarg); + maximumFPS = strtol (optarg, nullptr, 0); break; case 'a': @@ -104,17 +105,20 @@ CApplicationContext::CApplicationContext (int argc, char* argv[]) : break; case 'v': - this->audioVolume = glm::clamp (atoi (optarg), 0, 128); + this->audioVolume = glm::clamp ((int) strtol (optarg, nullptr, 0), 0, 128); break; case 'c': this->takeScreenshot = true; this->screenshot = stringPathFixes (optarg); break; + + default: + break; } } - if (this->background.empty () == true) + if (this->background.empty ()) { if (optind < argc && strlen (argv [optind]) > 0) { @@ -122,7 +126,7 @@ CApplicationContext::CApplicationContext (int argc, char* argv[]) : } else { - this->printHelp (argv [0]); + CApplicationContext::printHelp (argv [0]); } } @@ -142,7 +146,7 @@ void CApplicationContext::validatePath () void CApplicationContext::validateAssets () { - if (this->assets.empty () == false) + if (!this->assets.empty ()) { sLog.out ("Using wallpaper engine's assets at ", this->assets, " based on --assets-dir parameter"); return; @@ -162,10 +166,10 @@ void CApplicationContext::validateAssets () void CApplicationContext::validateScreenshot () { - if (this->takeScreenshot == false) + if (!this->takeScreenshot) return; - if (this->screenshot.has_extension () == false) + if (!this->screenshot.has_extension ()) sLog.exception ("Cannot determine screenshot format"); std::string extension = this->screenshot.extension (); diff --git a/src/WallpaperEngine/Application/CApplicationContext.h b/src/WallpaperEngine/Application/CApplicationContext.h index 5f2d64f..9c3f47e 100644 --- a/src/WallpaperEngine/Application/CApplicationContext.h +++ b/src/WallpaperEngine/Application/CApplicationContext.h @@ -29,6 +29,6 @@ namespace WallpaperEngine::Application void validatePath (); void validateAssets (); void validateScreenshot (); - void printHelp (const char* route); + static void printHelp (const char* route); }; } \ No newline at end of file diff --git a/src/WallpaperEngine/Application/CWallpaperApplication.cpp b/src/WallpaperEngine/Application/CWallpaperApplication.cpp index 3c932bc..860b02d 100644 --- a/src/WallpaperEngine/Application/CWallpaperApplication.cpp +++ b/src/WallpaperEngine/Application/CWallpaperApplication.cpp @@ -139,7 +139,7 @@ void CWallpaperApplication::loadProject () this->m_project = CProject::fromFile ("project.json", this->m_vfs); // go to the right folder so the videos will play // TODO: stop doing chdir and use full path - if (this->m_project->getWallpaper ()->is () == true) + if (this->m_project->getWallpaper ()->is ()) chdir (this->m_context.background.c_str ()); } @@ -229,7 +229,7 @@ void CWallpaperApplication::show () float startTime, endTime, minimumTime = 1.0f / this->m_context.maximumFPS; - while (videoDriver.closeRequested () == false && g_KeepRunning == true) + while (!videoDriver.closeRequested () && g_KeepRunning) { // update input information inputContext.update (); @@ -248,7 +248,7 @@ void CWallpaperApplication::show () if ((endTime - startTime) < minimumTime) usleep ((minimumTime - (endTime - startTime)) * CLOCKS_PER_SEC); - if (this->m_context.takeScreenshot == true && videoDriver.getFrameCounter () == 5) + if (this->m_context.takeScreenshot && videoDriver.getFrameCounter () == 5) { this->takeScreenshot (context.getWallpaper (), this->m_context.screenshot, this->m_context.screenshotFormat); // disable screenshot just in case the counter overflows diff --git a/src/WallpaperEngine/Assets/CAssetLoadException.h b/src/WallpaperEngine/Assets/CAssetLoadException.h index a6cd511..9aec138 100644 --- a/src/WallpaperEngine/Assets/CAssetLoadException.h +++ b/src/WallpaperEngine/Assets/CAssetLoadException.h @@ -14,4 +14,4 @@ namespace WallpaperEngine::Assets private: std::string m_message; }; -}; \ No newline at end of file +} \ No newline at end of file diff --git a/src/WallpaperEngine/Assets/CCombinedContainer.cpp b/src/WallpaperEngine/Assets/CCombinedContainer.cpp index 1a05b35..32ee7ef 100644 --- a/src/WallpaperEngine/Assets/CCombinedContainer.cpp +++ b/src/WallpaperEngine/Assets/CCombinedContainer.cpp @@ -6,6 +6,12 @@ using namespace WallpaperEngine::Assets; +CCombinedContainer::CCombinedContainer () : + CContainer (), + m_containers () +{ +} + void CCombinedContainer::add (CContainer* container) { this->m_containers.emplace_back (container); diff --git a/src/WallpaperEngine/Assets/CCombinedContainer.h b/src/WallpaperEngine/Assets/CCombinedContainer.h index 43477d3..af5435c 100644 --- a/src/WallpaperEngine/Assets/CCombinedContainer.h +++ b/src/WallpaperEngine/Assets/CCombinedContainer.h @@ -11,6 +11,8 @@ namespace WallpaperEngine::Assets class CCombinedContainer : public CContainer { public: + CCombinedContainer (); + /** * Adds a container to the list * @@ -19,7 +21,7 @@ namespace WallpaperEngine::Assets void add (CContainer* container); void addPkg (const std::filesystem::path& path); - const void* readFile (std::string filename, uint32_t* length) const override; + const void* readFile (std::string filename, uint32_t* length = nullptr) const override; private: std::vector m_containers; diff --git a/src/WallpaperEngine/Assets/CContainer.cpp b/src/WallpaperEngine/Assets/CContainer.cpp index 94d50fa..536117f 100644 --- a/src/WallpaperEngine/Assets/CContainer.cpp +++ b/src/WallpaperEngine/Assets/CContainer.cpp @@ -15,8 +15,9 @@ const ITexture* CContainer::readTexture (std::string filename) const ITexture* result = new CTexture (textureContents); - if (DEBUG) +#if DEBUG glObjectLabel (GL_TEXTURE, result->getTextureID (), -1, filename.c_str ()); +#endif /* DEBUG */ return result; } diff --git a/src/WallpaperEngine/Assets/CContainer.h b/src/WallpaperEngine/Assets/CContainer.h index 3c820be..0585306 100644 --- a/src/WallpaperEngine/Assets/CContainer.h +++ b/src/WallpaperEngine/Assets/CContainer.h @@ -17,7 +17,7 @@ namespace WallpaperEngine::Assets * * @return */ - const virtual void* readFile (std::string filename, uint32_t* length = nullptr) const = 0; + virtual const void* readFile (std::string filename, uint32_t* length = nullptr) const = 0; /** * Wrapper for readFile, appends the texture extension at the end of the filename diff --git a/src/WallpaperEngine/Assets/CDirectory.cpp b/src/WallpaperEngine/Assets/CDirectory.cpp index dcf81dc..a40d088 100644 --- a/src/WallpaperEngine/Assets/CDirectory.cpp +++ b/src/WallpaperEngine/Assets/CDirectory.cpp @@ -12,7 +12,7 @@ CDirectory::CDirectory (std::filesystem::path basepath) : m_basepath (std::move(basepath)) { // ensure the specified path exists - struct stat buffer; + struct stat buffer {}; if (stat (this->m_basepath.c_str (), &buffer) != 0) sLog.exception ("Cannot find ", this->m_basepath, ". This folder is required for wallpaper engine to work"); @@ -22,9 +22,7 @@ CDirectory::CDirectory (std::filesystem::path basepath) : } CDirectory::~CDirectory () -{ - -} += default; const void* CDirectory::readFile (std::string filename, uint32_t* length) const { diff --git a/src/WallpaperEngine/Assets/CDirectory.h b/src/WallpaperEngine/Assets/CDirectory.h index caa8218..589d42c 100644 --- a/src/WallpaperEngine/Assets/CDirectory.h +++ b/src/WallpaperEngine/Assets/CDirectory.h @@ -13,7 +13,7 @@ namespace WallpaperEngine::Assets class CDirectory : public CContainer { public: - CDirectory (std::filesystem::path basepath); + explicit CDirectory (std::filesystem::path basepath); ~CDirectory (); const void* readFile (std::string filename, uint32_t* length) const override; @@ -21,4 +21,4 @@ namespace WallpaperEngine::Assets std::filesystem::path m_basepath; std::map m_cache; }; -}; \ No newline at end of file +} \ No newline at end of file diff --git a/src/WallpaperEngine/Assets/CPackage.cpp b/src/WallpaperEngine/Assets/CPackage.cpp index 3a5f869..8d23957 100644 --- a/src/WallpaperEngine/Assets/CPackage.cpp +++ b/src/WallpaperEngine/Assets/CPackage.cpp @@ -29,9 +29,7 @@ CPackage::CPackage (std::filesystem::path path) : } CPackage::~CPackage() -{ - -} += default; const void* CPackage::readFile (std::string filename, uint32_t* length) const diff --git a/src/WallpaperEngine/Assets/CPackage.h b/src/WallpaperEngine/Assets/CPackage.h index bef2f45..a7696cb 100644 --- a/src/WallpaperEngine/Assets/CPackage.h +++ b/src/WallpaperEngine/Assets/CPackage.h @@ -16,7 +16,7 @@ namespace WallpaperEngine::Assets class CPackage : public CContainer { public: - CPackage (std::filesystem::path path); + explicit CPackage (std::filesystem::path path); ~CPackage (); const void* readFile (std::string filename, uint32_t* length) const override; diff --git a/src/WallpaperEngine/Assets/CPackageLoadException.h b/src/WallpaperEngine/Assets/CPackageLoadException.h index 7632e84..37db8c0 100644 --- a/src/WallpaperEngine/Assets/CPackageLoadException.h +++ b/src/WallpaperEngine/Assets/CPackageLoadException.h @@ -8,7 +8,7 @@ namespace WallpaperEngine::Assets class CPackageLoadException : public std::exception { public: - CPackageLoadException(const std::string& message, const std::string& extrainfo = ""); + explicit CPackageLoadException(const std::string& message, const std::string& extrainfo = ""); const char* what() const noexcept override; private: diff --git a/src/WallpaperEngine/Assets/CTexture.cpp b/src/WallpaperEngine/Assets/CTexture.cpp index ba12e2f..d0ce263 100644 --- a/src/WallpaperEngine/Assets/CTexture.cpp +++ b/src/WallpaperEngine/Assets/CTexture.cpp @@ -7,14 +7,15 @@ using namespace WallpaperEngine::Assets; -CTexture::CTexture (const void* fileData) +CTexture::CTexture (const void* fileData) : + m_resolution () { // ensure the header is parsed - this->m_header = this->parseHeader (static_cast (fileData)); + this->m_header = parseHeader (static_cast (fileData)); GLint internalFormat; - if (this->isAnimated () == true) + if (this->isAnimated ()) { this->m_resolution = { this->m_header->textureWidth, this->m_header->textureHeight, @@ -27,7 +28,7 @@ CTexture::CTexture (const void* fileData) { // wpengine-texture format always has one mipmap // get first image size - std::vector::const_iterator element = this->m_header->images.find (0)->second.begin (); + auto element = this->m_header->images.find (0)->second.begin (); // set the texture resolution this->m_resolution = { @@ -160,14 +161,14 @@ CTexture::CTexture (const void* fileData) } else { - if (this->m_header->format == TextureFormat::RG88) + if (this->m_header->format == TextureFormat::R8) + { + // red textures are 1-byte-per-pixel, so it's alignment has to be set manually + glPixelStorei (GL_UNPACK_ALIGNMENT, 1); + textureFormat = GL_RED; + } + else if (this->m_header->format == TextureFormat::RG88) textureFormat = GL_RG; - else if (this->m_header->format == TextureFormat::R8) - { - // red textures are 1-byte-per-pixel, so it's alignment has to be set manually - glPixelStorei (GL_UNPACK_ALIGNMENT, 1); - textureFormat = GL_RED; - } } switch (internalFormat) @@ -242,12 +243,12 @@ const uint32_t CTexture::getTextureHeight (uint32_t imageIndex) const const uint32_t CTexture::getRealWidth () const { - return this->isAnimated () == true ? this->getHeader ()->gifWidth : this->getHeader ()->width; + return this->isAnimated () ? this->getHeader ()->gifWidth : this->getHeader ()->width; } const uint32_t CTexture::getRealHeight () const { - return this->isAnimated () == true ? this->getHeader ()->gifHeight : this->getHeader ()->height; + return this->isAnimated () ? this->getHeader ()->gifHeight : this->getHeader ()->height; } const ITexture::TextureFormat CTexture::getFormat () const @@ -281,8 +282,7 @@ const bool CTexture::isAnimated () const } CTexture::TextureMipmap::TextureMipmap () -{ -} += default; CTexture::TextureMipmap::~TextureMipmap () { @@ -308,25 +308,40 @@ void CTexture::TextureMipmap::decompressData () } } -CTexture::TextureFrame::TextureFrame () +CTexture::TextureFrame::TextureFrame () : + frameNumber (0), + frametime (0.0f), + x (0), + y (0), + width1 (0), + width2 (0), + height1 (0), + height2 (0) { } CTexture::TextureFrame::~TextureFrame () -{ -} += default; -CTexture::TextureHeader::TextureHeader () +CTexture::TextureHeader::TextureHeader () : + flags (NoFlags), + width (0), + height (0), + textureWidth (0), + textureHeight (0), + gifWidth (0), + gifHeight (0), + format (TextureFormat::UNKNOWN), + imageCount (0), + mipmapCount (0) { } CTexture::TextureHeader::~TextureHeader () { for (const auto& imgCur : this->images) - { for (auto cur : imgCur.second) delete cur; - } } CTexture::TextureHeader* CTexture::parseHeader (const char* fileData) @@ -342,9 +357,9 @@ CTexture::TextureHeader* CTexture::parseHeader (const char* fileData) // jump through the string again fileData += 9; - TextureHeader* header = new TextureHeader; + auto* header = new TextureHeader; - const uint32_t* pointer = reinterpret_cast (fileData); + const auto* pointer = reinterpret_cast (fileData); header->format = static_cast (*pointer ++); header->flags = static_cast (*pointer ++); @@ -433,7 +448,7 @@ CTexture::TextureHeader* CTexture::parseHeader (const char* fileData) while (framecount > 0) { // add the frame to the list - header->frames.push_back (parseAnimation (header, &fileData)); + header->frames.push_back (parseAnimation (&fileData)); framecount --; } @@ -451,19 +466,19 @@ CTexture::TextureHeader* CTexture::parseHeader (const char* fileData) return header; } -CTexture::TextureFrame* CTexture::parseAnimation (TextureHeader* header, const char** originalFileData) +CTexture::TextureFrame* CTexture::parseAnimation (const char** originalFileData) { const char* fileData = *originalFileData; // get back the pointer into integer - const uint32_t* pointer = reinterpret_cast (fileData); + const auto* pointer = reinterpret_cast (fileData); // start reading frame information - TextureFrame* frame = new TextureFrame(); + auto* frame = new TextureFrame(); frame->frameNumber = *pointer++; // reinterpret the pointer into float - const float* fPointer = reinterpret_cast (pointer); + const auto* fPointer = reinterpret_cast (pointer); frame->frametime = *fPointer ++; frame->x = *fPointer ++; @@ -481,13 +496,13 @@ CTexture::TextureFrame* CTexture::parseAnimation (TextureHeader* header, const c CTexture::TextureMipmap* CTexture::parseMipmap (TextureHeader* header, const char** originalFileData) { - TextureMipmap* mipmap = new TextureMipmap (); + auto* mipmap = new TextureMipmap (); // get the current position const char* fileData = *originalFileData; // get an integer pointer - const uint32_t* pointer = reinterpret_cast (fileData); + const auto* pointer = reinterpret_cast (fileData); mipmap->width = *pointer++; mipmap->height = *pointer++; @@ -536,7 +551,7 @@ CTexture::TextureMipmap* CTexture::parseMipmap (TextureHeader* header, const cha return mipmap; } -const bool CTexture::TextureHeader::isAnimated () const +bool CTexture::TextureHeader::isAnimated () const { return this->flags & TextureFlags::IsGif; } \ No newline at end of file diff --git a/src/WallpaperEngine/Assets/CTexture.h b/src/WallpaperEngine/Assets/CTexture.h index f7c0bf8..22dca56 100644 --- a/src/WallpaperEngine/Assets/CTexture.h +++ b/src/WallpaperEngine/Assets/CTexture.h @@ -18,7 +18,7 @@ namespace WallpaperEngine::Assets struct TextureHeader; public: - CTexture (const void* fileData); + explicit CTexture (const void* fileData); ~CTexture (); const GLuint getTextureID (uint32_t imageIndex = 0) const override; @@ -82,7 +82,7 @@ namespace WallpaperEngine::Assets TextureHeader (); ~TextureHeader (); - const bool isAnimated () const; + bool isAnimated () const; /** The version of the texture container */ ContainerVersion containerVersion = ContainerVersion::UNKNOWN; @@ -117,7 +117,7 @@ namespace WallpaperEngine::Assets }; private: static TextureHeader* parseHeader (const char* fileData); - static TextureFrame* parseAnimation (TextureHeader* header, const char** originalFileData); + static TextureFrame* parseAnimation (const char** originalFileData); static TextureMipmap* parseMipmap (TextureHeader* header, const char** fileData); TextureHeader* m_header; diff --git a/src/WallpaperEngine/Assets/CVirtualContainer.h b/src/WallpaperEngine/Assets/CVirtualContainer.h index 8b09d50..bc99392 100644 --- a/src/WallpaperEngine/Assets/CVirtualContainer.h +++ b/src/WallpaperEngine/Assets/CVirtualContainer.h @@ -11,8 +11,8 @@ namespace WallpaperEngine::Assets class CVirtualContainer : public CContainer { public: - CVirtualContainer () {} - ~CVirtualContainer () {} + CVirtualContainer () = default; + ~CVirtualContainer () = default; /** * Adds a new file to the virtual container diff --git a/src/WallpaperEngine/Assets/ITexture.h b/src/WallpaperEngine/Assets/ITexture.h index caa9b20..30d8c67 100644 --- a/src/WallpaperEngine/Assets/ITexture.h +++ b/src/WallpaperEngine/Assets/ITexture.h @@ -36,6 +36,7 @@ namespace WallpaperEngine::Assets */ enum TextureFormat : uint32_t { + UNKNOWN = 0xFFFFFFFF, ARGB8888 = 0, RGB888 = 1, RGB565 = 2, @@ -74,4 +75,4 @@ namespace WallpaperEngine::Assets virtual const glm::vec4* getResolution () const = 0; virtual const bool isAnimated () const = 0; }; -}; \ No newline at end of file +} \ No newline at end of file diff --git a/src/WallpaperEngine/Audio/CAudioContext.h b/src/WallpaperEngine/Audio/CAudioContext.h index c9f95b5..2b6e3f1 100644 --- a/src/WallpaperEngine/Audio/CAudioContext.h +++ b/src/WallpaperEngine/Audio/CAudioContext.h @@ -15,7 +15,7 @@ namespace WallpaperEngine::Audio class CAudioContext { public: - CAudioContext (Drivers::CAudioDriver& driver); + explicit CAudioContext (Drivers::CAudioDriver& driver); void addStream (CAudioStream* stream); diff --git a/src/WallpaperEngine/Audio/CAudioStream.cpp b/src/WallpaperEngine/Audio/CAudioStream.cpp index 05d2852..2915757 100644 --- a/src/WallpaperEngine/Audio/CAudioStream.cpp +++ b/src/WallpaperEngine/Audio/CAudioStream.cpp @@ -23,7 +23,7 @@ int audio_read_thread (void* arg) if (waitMutex == nullptr) sLog.exception ("Cannot create mutex for audio playback waiting"); - while (ret >= 0 && g_KeepRunning == true) + while (ret >= 0 && g_KeepRunning) { // give the cpu some time to play the queued frames if there's enough info there if ( @@ -47,7 +47,7 @@ int audio_read_thread (void* arg) avcodec_flush_buffers (stream->getContext ()); // ensure the thread is not killed if audio has to be looped - if (stream->isRepeat() == true) + if (stream->isRepeat()) ret = 0; continue; @@ -59,7 +59,7 @@ int audio_read_thread (void* arg) else av_packet_unref (packet); - if (stream->isInitialized () == false) + if (!stream->isInitialized ()) break; } @@ -165,8 +165,8 @@ CAudioStream::~CAudioStream() void CAudioStream::loadCustomContent (const char* filename) { - const AVCodec* aCodec = nullptr; - AVCodecContext* avCodecContext = nullptr; + const AVCodec* aCodec; + AVCodecContext* avCodecContext; if (avformat_open_input (&this->m_formatContext, filename, nullptr, nullptr) != 0) sLog.exception ("Cannot open audio file: ", filename); @@ -287,7 +287,7 @@ void CAudioStream::queuePacket(AVPacket *pkt) bool gotQueued = this->doQueue (clone); SDL_UnlockMutex (this->m_queue->mutex); - if (gotQueued == false) + if (!gotQueued) av_packet_free (&pkt); } @@ -324,11 +324,12 @@ void CAudioStream::dequeuePacket (AVPacket* output) while (g_KeepRunning) { - int ret = -1; #if FF_API_FIFO_OLD_API - ret = av_fifo_read (this->m_queue->packetList, &entry, 1); + int ret = av_fifo_read (this->m_queue->packetList, &entry, 1); #else + int ret = -1; + if (av_fifo_size (this->m_queue->packetList) >= sizeof (entry)) ret = av_fifo_generic_read (this->m_queue->packetList, &entry, sizeof (entry), nullptr); #endif @@ -440,29 +441,23 @@ SDL_mutex* CAudioStream::getMutex () void CAudioStream::stop () { - if (this->isInitialized () == false) + if (!this->isInitialized ()) return; // stop the threads running this->m_initialized = false; } -int CAudioStream::resampleAudio ( - AVFrame * decoded_audio_frame, - enum AVSampleFormat out_sample_fmt, - int out_channels, - int out_sample_rate, - uint8_t * out_buf -) +int CAudioStream::resampleAudio (AVFrame * decoded_audio_frame, uint8_t * out_buf) { - int ret = 0; - int out_nb_channels = 0; - int out_linesize = 0; - int in_nb_samples = 0; - int out_nb_samples = 0; - int max_out_nb_samples = 0; - uint8_t ** resampled_data = NULL; - int resampled_data_size = 0; + int out_linesize = 0; + int ret; + int out_nb_channels; + int in_nb_samples; + int out_nb_samples; + int max_out_nb_samples; + uint8_t** resampled_data = nullptr; + int resampled_data_size; // retrieve number of audio samples (per channel) in_nb_samples = decoded_audio_frame->nb_samples; @@ -474,7 +469,7 @@ int CAudioStream::resampleAudio ( max_out_nb_samples = out_nb_samples = av_rescale_rnd( in_nb_samples, - out_sample_rate, + this->m_audioContext.getSampleRate (), this->getContext ()->sample_rate, AV_ROUND_UP ); @@ -507,7 +502,7 @@ int CAudioStream::resampleAudio ( &out_linesize, out_nb_channels, out_nb_samples, - out_sample_fmt, + this->m_audioContext.getFormat (), 0 ); @@ -520,7 +515,7 @@ int CAudioStream::resampleAudio ( // retrieve output samples number taking into account the progressive delay out_nb_samples = av_rescale_rnd( swr_get_delay(this->m_swrctx, this->getContext ()->sample_rate) + in_nb_samples, - out_sample_rate, + this->m_audioContext.getSampleRate (), this->getContext ()->sample_rate, AV_ROUND_UP ); @@ -543,7 +538,7 @@ int CAudioStream::resampleAudio ( &out_linesize, out_nb_channels, out_nb_samples, - out_sample_fmt, + this->m_audioContext.getFormat (), 1 ); @@ -561,7 +556,7 @@ int CAudioStream::resampleAudio ( ret = swr_convert( this->m_swrctx, resampled_data, - out_nb_samples, + max_out_nb_samples, (const uint8_t **) decoded_audio_frame->data, decoded_audio_frame->nb_samples ); @@ -578,7 +573,7 @@ int CAudioStream::resampleAudio ( &out_linesize, out_nb_channels, ret, - out_sample_fmt, + this->m_audioContext.getFormat (), 1 ); @@ -613,7 +608,7 @@ int CAudioStream::decodeFrame (uint8_t* audioBuffer, int bufferSize) static uint8_t *audio_pkt_data = NULL; static int audio_pkt_size = 0; - int len1, data_size = 0; + int len1, data_size; // allocate a new frame, used to decode audio packets static AVFrame * avFrame = NULL; @@ -636,12 +631,10 @@ int CAudioStream::decodeFrame (uint8_t* audioBuffer, int bufferSize) ret = 0; if (ret == 0) ret = avcodec_send_packet(this->getContext (), pkt); - if (ret == AVERROR(EAGAIN)) - ret = 0; - else if (ret < 0) + if (ret < 0 && ret != AVERROR (EAGAIN)) return -1; - else - len1 = pkt->size; + + len1 = pkt->size; if (len1 < 0) { @@ -656,13 +649,7 @@ int CAudioStream::decodeFrame (uint8_t* audioBuffer, int bufferSize) if (got_frame) { // audio resampling - data_size = this->resampleAudio ( - avFrame, - this->m_audioContext.getFormat (), - this->m_audioContext.getChannels (), - this->m_audioContext.getSampleRate (), - audioBuffer - ); + data_size = this->resampleAudio (avFrame, audioBuffer); assert(data_size <= bufferSize); } if (data_size <= 0) { diff --git a/src/WallpaperEngine/Audio/CAudioStream.h b/src/WallpaperEngine/Audio/CAudioStream.h index bcf90d9..1c0537f 100644 --- a/src/WallpaperEngine/Audio/CAudioStream.h +++ b/src/WallpaperEngine/Audio/CAudioStream.h @@ -10,7 +10,7 @@ extern "C" #include #include #include -}; +} #include #include @@ -61,7 +61,7 @@ namespace WallpaperEngine::Audio private: void loadCustomContent (const char* filename = nullptr); - int resampleAudio (AVFrame * decoded_audio_frame, enum AVSampleFormat out_sample_fmt, int out_channels, int out_sample_rate, uint8_t* out_buf); + int resampleAudio (AVFrame * decoded_audio_frame, uint8_t* out_buf); bool doQueue (AVPacket* pkt); void initialize (); @@ -100,4 +100,4 @@ namespace WallpaperEngine::Audio SDL_cond *cond; } *m_queue; }; -}; +} diff --git a/src/WallpaperEngine/Audio/Drivers/CSDLAudioDriver.cpp b/src/WallpaperEngine/Audio/Drivers/CSDLAudioDriver.cpp index e2f93c9..b91e087 100644 --- a/src/WallpaperEngine/Audio/Drivers/CSDLAudioDriver.cpp +++ b/src/WallpaperEngine/Audio/Drivers/CSDLAudioDriver.cpp @@ -24,11 +24,11 @@ void audio_callback (void* userdata, uint8_t* streamData, int length) // sound is not initialized or stopped and is not in loop mode // ignore mixing it in - if (buffer->stream->isInitialized () == false) + if (!buffer->stream->isInitialized ()) continue; - // check if thread is empty and signal the read thread - if (buffer->stream->isQueueEmpty () == true) + // check if queue is empty and signal the read thread + if (buffer->stream->isQueueEmpty ()) { SDL_CondSignal (buffer->stream->getWaitCondition ()); continue; @@ -74,7 +74,8 @@ void audio_callback (void* userdata, uint8_t* streamData, int length) } CSDLAudioDriver::CSDLAudioDriver () : - m_initialized (false) + m_initialized (false), + m_audioSpec () { if (SDL_InitSubSystem (SDL_INIT_AUDIO) < 0) { @@ -110,7 +111,7 @@ CSDLAudioDriver::CSDLAudioDriver () : CSDLAudioDriver::~CSDLAudioDriver () { - if (this->m_initialized == false) + if (!this->m_initialized) return; SDL_CloseAudioDevice (this->m_deviceID); diff --git a/src/WallpaperEngine/Core/CObject.cpp b/src/WallpaperEngine/Core/CObject.cpp index 679db0d..a78ca2a 100644 --- a/src/WallpaperEngine/Core/CObject.cpp +++ b/src/WallpaperEngine/Core/CObject.cpp @@ -54,9 +54,9 @@ CObject* CObject::fromJSON (json data, CScene* scene, const CContainer& containe auto text_it = data.find ("text"); auto light_it = data.find ("light"); - CObject* object = nullptr; + CObject* object; - if (image_it != data.end () && (*image_it).is_null () == false) + if (image_it != data.end () && !(*image_it).is_null ()) { object = Objects::CImage::fromJSON ( scene, @@ -70,7 +70,7 @@ CObject* CObject::fromJSON (json data, CScene* scene, const CContainer& containe WallpaperEngine::Core::aToVector3 (angles_val) ); } - else if (sound_it != data.end () && (*sound_it).is_null () == false) + else if (sound_it != data.end () && !(*sound_it).is_null ()) { object = Objects::CSound::fromJSON ( scene, @@ -83,7 +83,7 @@ CObject* CObject::fromJSON (json data, CScene* scene, const CContainer& containe WallpaperEngine::Core::aToVector3 (angles_val) ); } - else if (particle_it != data.end () && (*particle_it).is_null () == false) + else if (particle_it != data.end () && !(*particle_it).is_null ()) { /// TODO: XXXHACK -- TO REMOVE WHEN PARTICLE SUPPORT IS PROPERLY IMPLEMENTED try @@ -99,17 +99,17 @@ CObject* CObject::fromJSON (json data, CScene* scene, const CContainer& containe scale ); } - catch (std::runtime_error ex) + catch (std::runtime_error& ex) { return nullptr; } } - else if (text_it != data.end () && (*text_it).is_null () == false) + else if (text_it != data.end () && !(*text_it).is_null ()) { /// TODO: XXXHACK -- TO REMOVE WHEN TEXT SUPPORT IS IMPLEMENTED return nullptr; } - else if (light_it != data.end () && (*light_it).is_null () == false) + else if (light_it != data.end () && !(*light_it).is_null ()) { /// TODO: XXXHACK -- TO REMOVE WHEN LIGHT SUPPORT IS IMPLEMENTED return nullptr; @@ -119,23 +119,24 @@ CObject* CObject::fromJSON (json data, CScene* scene, const CContainer& containe sLog.exception ("Unknown object type detected: ", *name_it); } - if (effects_it != data.end () && (*effects_it).is_array () == true) + if (effects_it != data.end () && (*effects_it).is_array ()) { for (const auto& cur : *effects_it) { auto effectVisible = jsonFindUserConfig (data, "visible", true); - + + if (!effectVisible->processValue (scene->getProject ()->getProperties ())) + continue; + object->insertEffect ( Objects::CEffect::fromJSON (cur, effectVisible, object, container) ); } } - if (dependencies_it != data.end () && (*dependencies_it).is_array () == true) - { + if (dependencies_it != data.end () && (*dependencies_it).is_array ()) for (const auto& cur : *dependencies_it) object->insertDependency (cur); - } return object; } @@ -170,7 +171,7 @@ const std::vector& CObject::getDependencies () const return this->m_dependencies; } -const bool CObject::isVisible () const +bool CObject::isVisible () const { // TODO: cache this return this->m_visible->processValue (this->getScene ()->getProject ()->getProperties ()); @@ -181,7 +182,7 @@ CScene* CObject::getScene () const return this->m_scene; } -const int CObject::getId () const +int CObject::getId () const { return this->m_id; } diff --git a/src/WallpaperEngine/Core/CObject.h b/src/WallpaperEngine/Core/CObject.h index c11f972..962b67b 100644 --- a/src/WallpaperEngine/Core/CObject.h +++ b/src/WallpaperEngine/Core/CObject.h @@ -42,14 +42,14 @@ namespace WallpaperEngine::Core const std::vector& getEffects () const; const std::vector& getDependencies () const; - const int getId () const; + int getId () const; glm::vec3 getOrigin () const; glm::vec3 getScale () const; const glm::vec3& getAngles () const; const std::string& getName () const; - const bool isVisible () const; + bool isVisible () const; CScene* getScene () const; protected: CObject ( @@ -80,4 +80,4 @@ namespace WallpaperEngine::Core CScene* m_scene; }; -}; +} diff --git a/src/WallpaperEngine/Core/CProject.h b/src/WallpaperEngine/Core/CProject.h index d17f04d..7aa7af6 100644 --- a/src/WallpaperEngine/Core/CProject.h +++ b/src/WallpaperEngine/Core/CProject.h @@ -38,4 +38,4 @@ namespace WallpaperEngine::Core CWallpaper* m_wallpaper; CContainer& m_container; }; -}; +} diff --git a/src/WallpaperEngine/Core/CScene.h b/src/WallpaperEngine/Core/CScene.h index a9be175..d11f119 100644 --- a/src/WallpaperEngine/Core/CScene.h +++ b/src/WallpaperEngine/Core/CScene.h @@ -97,4 +97,4 @@ namespace WallpaperEngine::Core std::map m_objects; std::vector m_objectsByRenderOrder; }; -}; +} diff --git a/src/WallpaperEngine/Core/CVideo.h b/src/WallpaperEngine/Core/CVideo.h index 3aae90f..239c970 100644 --- a/src/WallpaperEngine/Core/CVideo.h +++ b/src/WallpaperEngine/Core/CVideo.h @@ -16,9 +16,7 @@ namespace WallpaperEngine::Core class CVideo : public CWallpaper { public: - CVideo ( - std::string filename - ); + explicit CVideo (std::string filename); const std::string& getFilename (); @@ -31,4 +29,4 @@ namespace WallpaperEngine::Core private: }; -}; +} diff --git a/src/WallpaperEngine/Core/CWallpaper.cpp b/src/WallpaperEngine/Core/CWallpaper.cpp index 9051b11..c174fbb 100644 --- a/src/WallpaperEngine/Core/CWallpaper.cpp +++ b/src/WallpaperEngine/Core/CWallpaper.cpp @@ -1,9 +1,12 @@ #include "CWallpaper.h" +#include + using namespace WallpaperEngine::Core; -CWallpaper::CWallpaper (std::string type) : - m_type (type) +CWallpaper::CWallpaper (std::string type) : + m_type (std::move(type)), + m_project (nullptr) { } diff --git a/src/WallpaperEngine/Core/CWallpaper.h b/src/WallpaperEngine/Core/CWallpaper.h index 41c6520..9b533fe 100644 --- a/src/WallpaperEngine/Core/CWallpaper.h +++ b/src/WallpaperEngine/Core/CWallpaper.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include "CProject.h" @@ -16,7 +16,7 @@ namespace WallpaperEngine::Core template bool is () { return this->m_type == T::Type; } - CWallpaper (std::string type); + CWallpaper (std::string type); CProject* getProject () const; diff --git a/src/WallpaperEngine/Core/Core.cpp b/src/WallpaperEngine/Core/Core.cpp index 7662d08..b095fac 100644 --- a/src/WallpaperEngine/Core/Core.cpp +++ b/src/WallpaperEngine/Core/Core.cpp @@ -67,9 +67,9 @@ glm::vec3 Core::aToColorf (const std::string& str) glm::ivec3 Core::aToColori (const char* str) { - uint8_t r = static_cast (strtol (str, const_cast(&str), 10)); while (*str == ' ') str ++; - uint8_t g = static_cast (strtol (str, const_cast(&str), 10)); while (*str == ' ') str ++; - uint8_t b = static_cast (strtol (str, const_cast(&str), 10)); + auto r = static_cast (strtol (str, const_cast(&str), 10)); while (*str == ' ') str ++; + auto g = static_cast (strtol (str, const_cast(&str), 10)); while (*str == ' ') str ++; + auto b = static_cast (strtol (str, const_cast(&str), 10)); return {r, g, b}; } diff --git a/src/WallpaperEngine/Core/Core.h b/src/WallpaperEngine/Core/Core.h index e2e8bd5..3f4f6f4 100644 --- a/src/WallpaperEngine/Core/Core.h +++ b/src/WallpaperEngine/Core/Core.h @@ -26,4 +26,4 @@ namespace WallpaperEngine::Core nlohmann::json::iterator jsonFindRequired (nlohmann::json::iterator& data, const char *key, const char *notFoundMsg); template T jsonFindDefault (nlohmann::json& data, const char *key, T defaultValue); template T* jsonFindUserConfig (nlohmann::json& data, const char *key, typename T::data_type defaultValue); -}; +} diff --git a/src/WallpaperEngine/Core/Objects/CEffect.cpp b/src/WallpaperEngine/Core/Objects/CEffect.cpp index f7623d4..a723772 100644 --- a/src/WallpaperEngine/Core/Objects/CEffect.cpp +++ b/src/WallpaperEngine/Core/Objects/CEffect.cpp @@ -51,7 +51,7 @@ CEffect* CEffect::fromJSON (json data, CUserSettingBoolean* visible, Core::CObje auto dependencies_it = jsonFindRequired (content, "dependencies", ""); auto fbos_it = content.find ("fbos"); - CEffect* effect = new CEffect ( + auto* effect = new CEffect ( *name_it, description, *group_it, @@ -64,9 +64,7 @@ CEffect* CEffect::fromJSON (json data, CUserSettingBoolean* visible, Core::CObje CEffect::dependencyFromJSON (dependencies_it, effect); if (fbos_it != content.end ()) - { CEffect::fbosFromJSON (fbos_it, effect); - } if (effectpasses_it != data.end ()) { @@ -94,11 +92,11 @@ CEffect* CEffect::fromJSON (json data, CUserSettingBoolean* visible, Core::CObje { std::string texture; - if (texturesCur.is_null () == true) + if (texturesCur.is_null ()) { if (textureNumber == 0) { - CImage* image = object->as (); + auto* image = object->as (); texture = (*(*image->getMaterial ()->getPasses ().begin ())->getTextures ().begin ()); } @@ -151,13 +149,13 @@ void CEffect::constantsFromJSON (json::const_iterator constants_it, Core::Object { auto val = cur.value (); - Effects::Constants::CShaderConstant* constant = nullptr; + Effects::Constants::CShaderConstant* constant; // if the constant is an object, that means the constant has some extra information // for the UI, take the value, which is what we need // TODO: SUPPORT USER SETTINGS HERE - if (cur.value ().is_object () == true) + if (cur.value ().is_object ()) { auto it = cur.value ().find ("value"); @@ -170,15 +168,15 @@ void CEffect::constantsFromJSON (json::const_iterator constants_it, Core::Object val = it.value (); } - if (val.is_number_float () == true) + if (val.is_number_float ()) { constant = new Effects::Constants::CShaderConstantFloat (val.get ()); } - else if (val.is_number_integer () == true) + else if (val.is_number_integer ()) { constant = new Effects::Constants::CShaderConstantInteger (val.get ()); } - else if (val.is_string () == true) + else if (val.is_string ()) { // try a vector 4 first, then a vector3 and then a vector 2 constant = new Effects::Constants::CShaderConstantVector4 (WallpaperEngine::Core::aToVector4 (val)); @@ -215,7 +213,7 @@ void CEffect::materialsFromJSON (json::const_iterator passes_it, CEffect* effect if (materialfile == cur.end ()) sLog.exception ("Found an effect ", effect->m_name, " without material"); - Images::CMaterial* material = nullptr; + Images::CMaterial* material; if (target == cur.end ()) material = Images::CMaterial::fromFile ((*materialfile).get (), container); diff --git a/src/WallpaperEngine/Core/Objects/CEffect.h b/src/WallpaperEngine/Core/Objects/CEffect.h index c75189e..6a15414 100644 --- a/src/WallpaperEngine/Core/Objects/CEffect.h +++ b/src/WallpaperEngine/Core/Objects/CEffect.h @@ -10,7 +10,7 @@ namespace WallpaperEngine::Core { class CObject; -}; +} namespace WallpaperEngine::Core::UserSettings { diff --git a/src/WallpaperEngine/Core/Objects/CImage.cpp b/src/WallpaperEngine/Core/Objects/CImage.cpp index 4e55429..d69e6f7 100644 --- a/src/WallpaperEngine/Core/Objects/CImage.cpp +++ b/src/WallpaperEngine/Core/Objects/CImage.cpp @@ -70,7 +70,7 @@ WallpaperEngine::Core::CObject* CImage::fromJSON ( Images::CMaterial::fromFile ((*material_it).get (), container), visible, id, - name, + std::move(name), origin, scale, angles, @@ -99,7 +99,7 @@ const std::string& CImage::getAlignment () const return this->m_alignment; } -const float CImage::getAlpha () const +float CImage::getAlpha () const { return this->m_alpha->processValue (this->getScene ()->getProject ()->getProperties ()); } @@ -109,12 +109,12 @@ glm::vec3 CImage::getColor () const return this->m_color->processValue (this->getScene ()->getProject ()->getProperties ()); } -const float CImage::getBrightness () const +float CImage::getBrightness () const { return this->m_brightness; } -const uint32_t CImage::getColorBlendMode () const +uint32_t CImage::getColorBlendMode () const { return this->m_colorBlendMode; } diff --git a/src/WallpaperEngine/Core/Objects/CImage.h b/src/WallpaperEngine/Core/Objects/CImage.h index 812c59d..409368c 100644 --- a/src/WallpaperEngine/Core/Objects/CImage.h +++ b/src/WallpaperEngine/Core/Objects/CImage.h @@ -41,10 +41,10 @@ namespace WallpaperEngine::Core::Objects const Images::CMaterial* getMaterial () const; const glm::vec2& getSize () const; const std::string& getAlignment () const; - const float getAlpha () const; + float getAlpha () const; glm::vec3 getColor () const; - const float getBrightness () const; - const uint32_t getColorBlendMode () const; + float getBrightness () const; + uint32_t getColorBlendMode () const; const glm::vec2& getParallaxDepth () const; protected: @@ -78,4 +78,4 @@ namespace WallpaperEngine::Core::Objects CUserSettingVector3* m_color; uint32_t m_colorBlendMode; }; -}; +} diff --git a/src/WallpaperEngine/Core/Objects/CParticle.cpp b/src/WallpaperEngine/Core/Objects/CParticle.cpp index 6083db1..6c5b014 100644 --- a/src/WallpaperEngine/Core/Objects/CParticle.cpp +++ b/src/WallpaperEngine/Core/Objects/CParticle.cpp @@ -1,4 +1,6 @@ #include "CParticle.h" + +#include #include "WallpaperEngine/FileSystem/FileSystem.h" using namespace WallpaperEngine::Core::Objects; @@ -20,13 +22,13 @@ CParticle* CParticle::fromFile ( auto emitter_it = jsonFindRequired (data, "emitter", "Particles must have emitters"); auto initializer_it = jsonFindRequired (data, "initializer", "Particles must have initializers"); - CParticle* particle = new CParticle ( + auto* particle = new CParticle ( scene, *starttime_it, *maxcount_it, visible, id, - name, + std::move(name), origin, scale ); diff --git a/src/WallpaperEngine/Core/Objects/CParticle.h b/src/WallpaperEngine/Core/Objects/CParticle.h index 252d494..151ced8 100644 --- a/src/WallpaperEngine/Core/Objects/CParticle.h +++ b/src/WallpaperEngine/Core/Objects/CParticle.h @@ -54,4 +54,4 @@ namespace WallpaperEngine::Core::Objects std::vector m_emitters; std::vector m_initializers; }; -}; +} diff --git a/src/WallpaperEngine/Core/Objects/CSound.cpp b/src/WallpaperEngine/Core/Objects/CSound.cpp index 6580fa4..7a3bdaf 100644 --- a/src/WallpaperEngine/Core/Objects/CSound.cpp +++ b/src/WallpaperEngine/Core/Objects/CSound.cpp @@ -24,7 +24,7 @@ WallpaperEngine::Core::CObject* CSound::fromJSON ( json data, CUserSettingBoolean* visible, uint32_t id, - std::string name, + const std::string& name, CUserSettingVector3* origin, CUserSettingVector3* scale, const glm::vec3& angles) @@ -37,10 +37,10 @@ WallpaperEngine::Core::CObject* CSound::fromJSON ( if (playbackmode == "loop") repeat = true; - if ((*sound_it).is_array () == false) + if (!(*sound_it).is_array ()) sLog.exception ("Expected sound list on element ", name); - CSound* sound = new CSound ( + auto* sound = new CSound ( scene, visible, id, @@ -57,7 +57,7 @@ WallpaperEngine::Core::CObject* CSound::fromJSON ( return sound; } -void CSound::insertSound (std::string filename) +void CSound::insertSound (const std::string& filename) { this->m_sounds.push_back (filename); } diff --git a/src/WallpaperEngine/Core/Objects/CSound.h b/src/WallpaperEngine/Core/Objects/CSound.h index 38fc727..cade9e9 100644 --- a/src/WallpaperEngine/Core/Objects/CSound.h +++ b/src/WallpaperEngine/Core/Objects/CSound.h @@ -19,13 +19,13 @@ namespace WallpaperEngine::Core::Objects json data, CUserSettingBoolean* visible, uint32_t id, - std::string name, + const std::string& name, CUserSettingVector3* origin, CUserSettingVector3* scale, const glm::vec3& angles ); - void insertSound (std::string filename); + void insertSound (const std::string& filename); const std::vector& getSounds () const; bool isRepeat () const; diff --git a/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstant.h b/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstant.h index 00e6bc8..781e2a5 100644 --- a/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstant.h +++ b/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstant.h @@ -7,7 +7,7 @@ namespace WallpaperEngine::Core::Objects::Effects::Constants class CShaderConstant { public: - CShaderConstant (std::string type); + explicit CShaderConstant (std::string type); template const T* as () const { assert (is ()); return (const T*) this; } template T* as () { assert (is ()); return (T*) this; } diff --git a/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantFloat.h b/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantFloat.h index 2175b47..2d3aaba 100644 --- a/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantFloat.h +++ b/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantFloat.h @@ -9,7 +9,7 @@ namespace WallpaperEngine::Core::Objects::Effects::Constants class CShaderConstantFloat : public CShaderConstant { public: - CShaderConstantFloat (float value); + explicit CShaderConstantFloat (float value); float* getValue (); diff --git a/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantInteger.h b/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantInteger.h index 74cf610..a0904fd 100644 --- a/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantInteger.h +++ b/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantInteger.h @@ -9,7 +9,7 @@ namespace WallpaperEngine::Core::Objects::Effects::Constants class CShaderConstantInteger : public CShaderConstant { public: - CShaderConstantInteger (int32_t value); + explicit CShaderConstantInteger (int32_t value); int32_t* getValue (); diff --git a/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantVector2.cpp b/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantVector2.cpp index a121b9a..12f85f7 100644 --- a/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantVector2.cpp +++ b/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantVector2.cpp @@ -14,4 +14,4 @@ glm::vec2* CShaderConstantVector2::getValue () return &this->m_value; } -const std::string CShaderConstantVector3::Type = "vec2"; \ No newline at end of file +const std::string CShaderConstantVector2::Type = "vec2"; \ No newline at end of file diff --git a/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantVector2.h b/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantVector2.h index 7740140..7848345 100644 --- a/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantVector2.h +++ b/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantVector2.h @@ -3,6 +3,7 @@ #include "CShaderConstant.h" #include +#include #include namespace WallpaperEngine::Core::Objects::Effects::Constants @@ -10,7 +11,7 @@ namespace WallpaperEngine::Core::Objects::Effects::Constants class CShaderConstantVector2 : public CShaderConstant { public: - CShaderConstantVector2 (glm::vec2 value); + explicit CShaderConstantVector2 (glm::vec2 value); glm::vec2* getValue (); diff --git a/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantVector3.h b/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantVector3.h index 43fe5df..b06ab2b 100644 --- a/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantVector3.h +++ b/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantVector3.h @@ -10,7 +10,7 @@ namespace WallpaperEngine::Core::Objects::Effects::Constants class CShaderConstantVector3 : public CShaderConstant { public: - CShaderConstantVector3 (glm::vec3 value); + explicit CShaderConstantVector3 (glm::vec3 value); glm::vec3* getValue (); diff --git a/src/WallpaperEngine/Core/Objects/Images/CMaterial.cpp b/src/WallpaperEngine/Core/Objects/Images/CMaterial.cpp index ec50736..9902dc5 100644 --- a/src/WallpaperEngine/Core/Objects/Images/CMaterial.cpp +++ b/src/WallpaperEngine/Core/Objects/Images/CMaterial.cpp @@ -1,6 +1,7 @@ #include "CMaterial.h" #include +#include #include "WallpaperEngine/FileSystem/FileSystem.h" @@ -9,9 +10,9 @@ using namespace WallpaperEngine::Assets; using namespace WallpaperEngine::Core::Objects; using namespace WallpaperEngine::Core::Objects::Images; -CMaterial::CMaterial (const std::string& name) : - m_target (""), - m_name (name) +CMaterial::CMaterial (std::string name) : + m_target (), + m_name (std::move(name)) { } @@ -30,7 +31,7 @@ CMaterial* CMaterial::fromFile (const std::string& filename, const std::string& CMaterial* CMaterial::fromJSON (const std::string& name, json data, const std::string& target) { - CMaterial* material = fromJSON (name, data); + CMaterial* material = fromJSON (name, std::move(data)); material->setTarget (target); @@ -41,7 +42,7 @@ CMaterial* CMaterial::fromJSON (const std::string& name, json data) { auto passes_it = jsonFindRequired (data, "passes", "Material must have at least one pass"); - CMaterial* material = new CMaterial (name); + auto* material = new CMaterial (name); for (const auto& cur : (*passes_it)) material->insertPass (Materials::CPass::fromJSON (cur)); @@ -83,7 +84,7 @@ const std::string& CMaterial::getName () const return this->m_name; } -const bool CMaterial::hasTarget () const +bool CMaterial::hasTarget () const { - return this->m_target.empty () == false; + return !this->m_target.empty (); } \ No newline at end of file diff --git a/src/WallpaperEngine/Core/Objects/Images/CMaterial.h b/src/WallpaperEngine/Core/Objects/Images/CMaterial.h index 7068e7b..2b044cb 100644 --- a/src/WallpaperEngine/Core/Objects/Images/CMaterial.h +++ b/src/WallpaperEngine/Core/Objects/Images/CMaterial.h @@ -25,10 +25,10 @@ namespace WallpaperEngine::Core::Objects::Images const std::vector & getPasses () const; const std::map & getTextureBinds () const; const std::string& getTarget () const; - const bool hasTarget () const; + bool hasTarget () const; const std::string& getName () const; protected: - CMaterial (const std::string& name); + explicit CMaterial (std::string name); void setTarget (const std::string& target); private: @@ -37,4 +37,4 @@ namespace WallpaperEngine::Core::Objects::Images std::string m_target; std::string m_name; }; -}; +} diff --git a/src/WallpaperEngine/Core/Objects/Images/Materials/CPass.cpp b/src/WallpaperEngine/Core/Objects/Images/Materials/CPass.cpp index 49df3af..4dfad77 100644 --- a/src/WallpaperEngine/Core/Objects/Images/Materials/CPass.cpp +++ b/src/WallpaperEngine/Core/Objects/Images/Materials/CPass.cpp @@ -1,6 +1,8 @@ #include "common.h" #include "CPass.h" +#include + using namespace WallpaperEngine::Core::Objects::Effects::Constants; using namespace WallpaperEngine::Core::Objects::Images::Materials; @@ -27,11 +29,11 @@ CPass* CPass::fromJSON (json data) if (textures_it != data.end ()) { // TODO: FETCH THIS FROM CImage TO MAKE IT COMPATIBLE WITH OLDER WALLPAPERS - if ((*textures_it).is_array () == false) + if (!(*textures_it).is_array ()) sLog.exception ("Material's textures must be a list"); } - CPass* pass = new CPass ( + auto* pass = new CPass ( blending, cullmode, *depthtest_it, @@ -40,28 +42,15 @@ CPass* CPass::fromJSON (json data) ); if (textures_it != data.end ()) - { for (const auto& cur : (*textures_it)) - { - if (cur.is_null () == true) - { - pass->insertTexture (""); - } - else - { - pass->insertTexture (cur); - } - } - } + pass->insertTexture (cur.is_null () ? "" : cur); if (combos_it != data.end ()) { for (const auto& cur : (*combos_it).items ()) { - std::string name = cur.key (); - - if (cur.value ().is_number_integer () == true) - pass->insertCombo (name, cur.value ()); + if (cur.value ().is_number_integer ()) + pass->insertCombo (cur.key (), cur.value ()); else sLog.exception ("unexpected non-integer combo on pass"); } @@ -128,7 +117,7 @@ const std::string& CPass::getDepthWrite ()const return this->m_depthwrite; } -void CPass::setBlendingMode (std::string mode) +void CPass::setBlendingMode (const std::string& mode) { this->m_blending = mode; } diff --git a/src/WallpaperEngine/Core/Objects/Images/Materials/CPass.h b/src/WallpaperEngine/Core/Objects/Images/Materials/CPass.h index fdbd851..b785bbc 100644 --- a/src/WallpaperEngine/Core/Objects/Images/Materials/CPass.h +++ b/src/WallpaperEngine/Core/Objects/Images/Materials/CPass.h @@ -7,7 +7,7 @@ namespace WallpaperEngine::Core::Objects { class CEffect; -}; +} namespace WallpaperEngine::Core::Objects::Images::Materials { @@ -28,7 +28,7 @@ namespace WallpaperEngine::Core::Objects::Images::Materials const std::string& getCullingMode () const; const std::string& getDepthTest () const; const std::string& getDepthWrite () const; - void setBlendingMode (std::string mode); + void setBlendingMode (const std::string& mode); void insertCombo (const std::string& name, int value); void insertConstant (const std::string& name, Effects::Constants::CShaderConstant* constant); diff --git a/src/WallpaperEngine/Core/Objects/Particles/CControlPoint.cpp b/src/WallpaperEngine/Core/Objects/Particles/CControlPoint.cpp index ed90d44..ef878d3 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/CControlPoint.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/CControlPoint.cpp @@ -8,17 +8,13 @@ CControlPoint* CControlPoint::fromJSON (json data) auto id_it = jsonFindRequired (data, "id", "Particle's control point must have id"); auto offset_it = data.find ("offset"); - CControlPoint* controlpoint = new CControlPoint (*id_it, 0); + auto* controlpoint = new CControlPoint (*id_it, 0); if (offset_it != data.end ()) - { controlpoint->setOffset (WallpaperEngine::Core::aToVector3 (*offset_it)); - } if (flags_it != data.end ()) - { controlpoint->setFlags (*flags_it); - } return controlpoint; } @@ -39,13 +35,17 @@ void CControlPoint::setFlags (uint32_t flags) { this->m_flags = flags; } +uint32_t CControlPoint::getId () const +{ + return this->m_id; +} const glm::vec3& CControlPoint::getOffset () const { return this->m_offset; } -const uint32_t CControlPoint::getFlags () const +uint32_t CControlPoint::getFlags () const { return this->m_flags; } \ No newline at end of file diff --git a/src/WallpaperEngine/Core/Objects/Particles/CControlPoint.h b/src/WallpaperEngine/Core/Objects/Particles/CControlPoint.h index 85d8892..2385ff5 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/CControlPoint.h +++ b/src/WallpaperEngine/Core/Objects/Particles/CControlPoint.h @@ -11,10 +11,11 @@ namespace WallpaperEngine::Core::Objects::Particles public: static CControlPoint* fromJSON (json data); + uint32_t getId () const; const glm::vec3& getOffset () const; - const uint32_t getFlags () const; + uint32_t getFlags () const; protected: - CControlPoint (uint32_t id, uint32_t flags = 0); + explicit CControlPoint (uint32_t id, uint32_t flags = 0); void setOffset (const glm::vec3& offset); void setFlags (uint32_t flags); @@ -23,4 +24,4 @@ namespace WallpaperEngine::Core::Objects::Particles uint32_t m_flags; glm::vec3 m_offset; }; -}; +} diff --git a/src/WallpaperEngine/Core/Objects/Particles/CEmitter.cpp b/src/WallpaperEngine/Core/Objects/Particles/CEmitter.cpp index 381d368..fbcca5c 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/CEmitter.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/CEmitter.cpp @@ -41,6 +41,10 @@ CEmitter::CEmitter ( { } +uint32_t CEmitter::getId () const +{ + return this->m_id; +} const std::string& CEmitter::getName () const { diff --git a/src/WallpaperEngine/Core/Objects/Particles/CEmitter.h b/src/WallpaperEngine/Core/Objects/Particles/CEmitter.h index 908e2a3..5e5cc21 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/CEmitter.h +++ b/src/WallpaperEngine/Core/Objects/Particles/CEmitter.h @@ -11,6 +11,7 @@ namespace WallpaperEngine::Core::Objects::Particles public: static CEmitter* fromJSON (json data); + uint32_t getId () const; const std::string& getName () const; const uint32_t getDistanceMax () const; const uint32_t getDistanceMin () const; @@ -36,4 +37,4 @@ namespace WallpaperEngine::Core::Objects::Particles glm::vec3 m_origin; double m_rate; }; -}; +} diff --git a/src/WallpaperEngine/Core/Objects/Particles/CInitializer.cpp b/src/WallpaperEngine/Core/Objects/Particles/CInitializer.cpp index ccfcd36..84d9db1 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/CInitializer.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/CInitializer.cpp @@ -69,7 +69,7 @@ const std::string& CInitializer::getName () const return this->m_name; } -const uint32_t CInitializer::getId () const +uint32_t CInitializer::getId () const { return this->m_id; } \ No newline at end of file diff --git a/src/WallpaperEngine/Core/Objects/Particles/CInitializer.h b/src/WallpaperEngine/Core/Objects/Particles/CInitializer.h index de01850..f049a39 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/CInitializer.h +++ b/src/WallpaperEngine/Core/Objects/Particles/CInitializer.h @@ -12,11 +12,11 @@ namespace WallpaperEngine::Core::Objects::Particles static CInitializer* fromJSON (json data); const std::string& getName () const; - const uint32_t getId () const; + uint32_t getId () const; protected: CInitializer (uint32_t id, std::string name); private: uint32_t m_id; std::string m_name; }; -}; +} diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAlphaRandom.cpp b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAlphaRandom.cpp index 81ee26b..27200b9 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAlphaRandom.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAlphaRandom.cpp @@ -17,12 +17,12 @@ CAlphaRandom::CAlphaRandom (uint32_t id, double min, double max) : { } -const double CAlphaRandom::getMinimum () const +double CAlphaRandom::getMinimum () const { return this->m_min; } -const double CAlphaRandom::getMaximum () const +double CAlphaRandom::getMaximum () const { return this->m_max; } \ No newline at end of file diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAlphaRandom.h b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAlphaRandom.h index cecc08f..f51cc80 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAlphaRandom.h +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAlphaRandom.h @@ -9,8 +9,8 @@ namespace WallpaperEngine::Core::Objects::Particles::Initializers class CAlphaRandom : CInitializer { public: - const double getMinimum () const; - const double getMaximum () const; + double getMinimum () const; + double getMaximum () const; protected: friend class CInitializer; @@ -21,4 +21,4 @@ namespace WallpaperEngine::Core::Objects::Particles::Initializers double m_max; double m_min; }; -}; +} diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAngularVelocityRandom.h b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAngularVelocityRandom.h index 6fc9820..762298b 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAngularVelocityRandom.h +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAngularVelocityRandom.h @@ -21,4 +21,4 @@ namespace WallpaperEngine::Core::Objects::Particles::Initializers glm::vec3 m_max; glm::vec3 m_min; }; -}; +} diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CColorRandom.h b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CColorRandom.h index d489038..a8a22a8 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CColorRandom.h +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CColorRandom.h @@ -21,4 +21,4 @@ namespace WallpaperEngine::Core::Objects::Particles::Initializers glm::ivec3 m_max; glm::ivec3 m_min; }; -}; +} diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CLifeTimeRandom.cpp b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CLifeTimeRandom.cpp index 8ac86d6..3cd8816 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CLifeTimeRandom.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CLifeTimeRandom.cpp @@ -18,12 +18,12 @@ CLifeTimeRandom::CLifeTimeRandom (uint32_t id, uint32_t min, uint32_t max) : { } -const uint32_t CLifeTimeRandom::getMinimum () const +uint32_t CLifeTimeRandom::getMinimum () const { return this->m_min; } -const uint32_t CLifeTimeRandom::getMaximum () const +uint32_t CLifeTimeRandom::getMaximum () const { return this->m_max; } \ No newline at end of file diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CLifeTimeRandom.h b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CLifeTimeRandom.h index e03fce7..35b1b64 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CLifeTimeRandom.h +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CLifeTimeRandom.h @@ -9,8 +9,8 @@ namespace WallpaperEngine::Core::Objects::Particles::Initializers class CLifeTimeRandom : CInitializer { public: - const uint32_t getMinimum () const; - const uint32_t getMaximum () const; + uint32_t getMinimum () const; + uint32_t getMaximum () const; protected: friend class CInitializer; @@ -21,4 +21,4 @@ namespace WallpaperEngine::Core::Objects::Particles::Initializers uint32_t m_max; uint32_t m_min; }; -}; +} diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CRotationRandom.cpp b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CRotationRandom.cpp index 7ba07e8..3c6af87 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CRotationRandom.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CRotationRandom.cpp @@ -60,42 +60,42 @@ CRotationRandom::CRotationRandom ( { } -const glm::vec3 CRotationRandom::getMinimumVector () const +glm::vec3 CRotationRandom::getMinimumVector () const { return this->m_minVector; } -const glm::vec3 CRotationRandom::getMaximumVector () const +glm::vec3 CRotationRandom::getMaximumVector () const { return this->m_maxVector; } -const double CRotationRandom::getMinimumNumber () const +double CRotationRandom::getMinimumNumber () const { return this->m_minNumber; } -const double CRotationRandom::getMaximumNumber () const +double CRotationRandom::getMaximumNumber () const { return this->m_maxNumber; } -const bool CRotationRandom::isMinimumVector () const +bool CRotationRandom::isMinimumVector () const { - return this->m_isMinimumVector == true; + return this->m_isMinimumVector; } -const bool CRotationRandom::isMinimumNumber () const +bool CRotationRandom::isMinimumNumber () const { - return this->m_isMinimumVector == false; + return !this->m_isMinimumVector; } -const bool CRotationRandom::isMaximumVector () const +bool CRotationRandom::isMaximumVector () const { - return this->m_isMaximumVector == true; + return this->m_isMaximumVector; } -const bool CRotationRandom::isMaximumNumber () const +bool CRotationRandom::isMaximumNumber () const { - return this->m_isMaximumVector == false; + return !this->m_isMaximumVector; } \ No newline at end of file diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CRotationRandom.h b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CRotationRandom.h index 54dc195..11570d8 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CRotationRandom.h +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CRotationRandom.h @@ -9,15 +9,15 @@ namespace WallpaperEngine::Core::Objects::Particles::Initializers class CRotationRandom : CInitializer { public: - const glm::vec3 getMinimumVector () const; - const glm::vec3 getMaximumVector () const; - const double getMinimumNumber () const; - const double getMaximumNumber () const; + glm::vec3 getMinimumVector () const; + glm::vec3 getMaximumVector () const; + double getMinimumNumber () const; + double getMaximumNumber () const; - const bool isMinimumVector () const; - const bool isMinimumNumber () const; - const bool isMaximumVector () const; - const bool isMaximumNumber () const; + bool isMinimumVector () const; + bool isMinimumNumber () const; + bool isMaximumVector () const; + bool isMaximumNumber () const; protected: friend class CInitializer; @@ -42,4 +42,4 @@ namespace WallpaperEngine::Core::Objects::Particles::Initializers bool m_isMinimumVector; bool m_isMaximumVector; }; -}; +} diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CSizeRandom.cpp b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CSizeRandom.cpp index 4aab4b8..ddfa507 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CSizeRandom.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CSizeRandom.cpp @@ -17,12 +17,12 @@ CSizeRandom::CSizeRandom (uint32_t id, uint32_t min, uint32_t max) : { } -const uint32_t CSizeRandom::getMinimum () const +uint32_t CSizeRandom::getMinimum () const { return this->m_min; } -const uint32_t CSizeRandom::getMaximum () const +uint32_t CSizeRandom::getMaximum () const { return this->m_max; } \ No newline at end of file diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CSizeRandom.h b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CSizeRandom.h index 9a62bc5..bd119dd 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CSizeRandom.h +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CSizeRandom.h @@ -9,8 +9,8 @@ namespace WallpaperEngine::Core::Objects::Particles::Initializers class CSizeRandom : CInitializer { public: - const uint32_t getMinimum () const; - const uint32_t getMaximum () const; + uint32_t getMinimum () const; + uint32_t getMaximum () const; protected: friend class CInitializer; @@ -21,4 +21,4 @@ namespace WallpaperEngine::Core::Objects::Particles::Initializers uint32_t m_max; uint32_t m_min; }; -}; +} diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CTurbulentVelocityRandom.h b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CTurbulentVelocityRandom.h index 26470b2..2f1026f 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CTurbulentVelocityRandom.h +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CTurbulentVelocityRandom.h @@ -29,4 +29,4 @@ namespace WallpaperEngine::Core::Objects::Particles::Initializers uint32_t m_speedmin; uint32_t m_speedmax; }; -}; +} diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CVelocityRandom.h b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CVelocityRandom.h index 37afd27..a11a609 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CVelocityRandom.h +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CVelocityRandom.h @@ -21,4 +21,4 @@ namespace WallpaperEngine::Core::Objects::Particles::Initializers glm::vec3 m_max; glm::vec3 m_min; }; -}; +} diff --git a/src/WallpaperEngine/Core/Projects/CPropertyBoolean.cpp b/src/WallpaperEngine/Core/Projects/CPropertyBoolean.cpp index dc4a0ca..1f68aa6 100644 --- a/src/WallpaperEngine/Core/Projects/CPropertyBoolean.cpp +++ b/src/WallpaperEngine/Core/Projects/CPropertyBoolean.cpp @@ -8,16 +8,12 @@ using namespace WallpaperEngine::Core::Projects; CPropertyBoolean* CPropertyBoolean::fromJSON (json data, const std::string& name) { json::const_iterator value = data.find ("value"); - std::string text = jsonFindDefault (data, "text", ""); + auto text = jsonFindDefault (data, "text", ""); - return new CPropertyBoolean ( - *value, - name, - text - ); + return new CPropertyBoolean (*value, name, text); } -bool CPropertyBoolean::getValue () +bool CPropertyBoolean::getValue () const { return this->m_value; } diff --git a/src/WallpaperEngine/Core/Projects/CPropertyBoolean.h b/src/WallpaperEngine/Core/Projects/CPropertyBoolean.h index 188b03d..a6096f5 100644 --- a/src/WallpaperEngine/Core/Projects/CPropertyBoolean.h +++ b/src/WallpaperEngine/Core/Projects/CPropertyBoolean.h @@ -11,7 +11,7 @@ namespace WallpaperEngine::Core::Projects public: static CPropertyBoolean* fromJSON (json data, const std::string& name); - bool getValue (); + bool getValue () const; std::string dump () const override; void update (const std::string& value) override; @@ -22,4 +22,4 @@ namespace WallpaperEngine::Core::Projects bool m_value; }; -}; +} diff --git a/src/WallpaperEngine/Core/Projects/CPropertyColor.cpp b/src/WallpaperEngine/Core/Projects/CPropertyColor.cpp index 9935baa..ab2e092 100644 --- a/src/WallpaperEngine/Core/Projects/CPropertyColor.cpp +++ b/src/WallpaperEngine/Core/Projects/CPropertyColor.cpp @@ -29,13 +29,9 @@ glm::vec3 ParseColor (std::string value) CPropertyColor* CPropertyColor::fromJSON (json data, const std::string& name) { std::string value = *jsonFindRequired (data, "value", "Color property must have a value"); - std::string text = jsonFindDefault (data, "text", ""); + auto text = jsonFindDefault (data, "text", ""); - return new CPropertyColor ( - ParseColor (value), - name, - text - ); + return new CPropertyColor (ParseColor (value), name, text); } const glm::vec3& CPropertyColor::getValue () const diff --git a/src/WallpaperEngine/Core/Projects/CPropertyColor.h b/src/WallpaperEngine/Core/Projects/CPropertyColor.h index 9d1d8ab..ec3dd18 100644 --- a/src/WallpaperEngine/Core/Projects/CPropertyColor.h +++ b/src/WallpaperEngine/Core/Projects/CPropertyColor.h @@ -24,4 +24,4 @@ namespace WallpaperEngine::Core::Projects glm::vec3 m_color; }; -}; +} diff --git a/src/WallpaperEngine/Core/Projects/CPropertyCombo.cpp b/src/WallpaperEngine/Core/Projects/CPropertyCombo.cpp index c32dfa0..8c41826 100644 --- a/src/WallpaperEngine/Core/Projects/CPropertyCombo.cpp +++ b/src/WallpaperEngine/Core/Projects/CPropertyCombo.cpp @@ -11,29 +11,29 @@ using namespace WallpaperEngine::Core::Projects; CPropertyCombo* CPropertyCombo::fromJSON (json data, const std::string& name) { auto value = data.find ("value"); - std::string text = jsonFindDefault (data, "text", ""); + auto text = jsonFindDefault (data, "text", ""); auto options = jsonFindRequired (data, "options", "Options for a property combo is required"); - CPropertyCombo* combo = new CPropertyCombo ( + auto* combo = new CPropertyCombo ( name, text, *value ); - if (options->is_array () == false) + if (!options->is_array ()) sLog.exception ("Property combo options should be an array"); for (auto& cur : (*options)) { // TODO: PROPERLY REPORT THESE ISSUES - if (cur.is_object () == false) + if (!cur.is_object ()) continue; // check for label and value to ensure they're there auto label = jsonFindRequired (cur, "label", "Label is required for a property combo option"); - auto value = jsonFindRequired (cur, "value", "Value is required for a property combo option"); + auto propertyValue = jsonFindRequired (cur, "value", "Value is required for a property combo option"); - combo->addValue (*label, *value); + combo->addValue (*label, *propertyValue); } return combo; @@ -61,9 +61,7 @@ std::string CPropertyCombo::dump () const << "\t\t" << "Posible values:" << std::endl; for (auto cur : this->m_values) - { ss << "\t\t" << cur->label << " -> " << cur->value << std::endl; - } return ss.str(); } @@ -81,7 +79,7 @@ void CPropertyCombo::update (const std::string& value) found = true; } - if (found == false) + if (!found) sLog.exception ("Assigning invalid value to property ", this->m_name); this->m_defaultValue = value; @@ -90,7 +88,7 @@ void CPropertyCombo::update (const std::string& value) void CPropertyCombo::addValue (std::string label, std::string value) { - CPropertyComboValue* prop = new CPropertyComboValue; + auto* prop = new CPropertyComboValue; prop->label = std::move (label); prop->value = std::move (value); diff --git a/src/WallpaperEngine/Core/Projects/CPropertyCombo.h b/src/WallpaperEngine/Core/Projects/CPropertyCombo.h index 1e8ada1..be4c8f4 100644 --- a/src/WallpaperEngine/Core/Projects/CPropertyCombo.h +++ b/src/WallpaperEngine/Core/Projects/CPropertyCombo.h @@ -32,4 +32,4 @@ namespace WallpaperEngine::Core::Projects std::vector m_values; std::string m_defaultValue; }; -}; +} diff --git a/src/WallpaperEngine/Core/Projects/CPropertySlider.cpp b/src/WallpaperEngine/Core/Projects/CPropertySlider.cpp index 650d6b2..7a828f0 100644 --- a/src/WallpaperEngine/Core/Projects/CPropertySlider.cpp +++ b/src/WallpaperEngine/Core/Projects/CPropertySlider.cpp @@ -7,19 +7,12 @@ using namespace WallpaperEngine::Core::Projects; CPropertySlider* CPropertySlider::fromJSON (json data, const std::string& name) { auto value = data.find ("value"); - std::string text = jsonFindDefault (data, "text", ""); + auto text = jsonFindDefault (data, "text", ""); auto min = jsonFindDefault(data, "min", 0.0); auto max = jsonFindDefault (data, "max", 0.0); auto step = jsonFindDefault (data, "step", 0.0); - return new CPropertySlider ( - *value, - name, - text, - min, - max, - step - ); + return new CPropertySlider (*value, name, text, min, max, step); } const double& CPropertySlider::getValue () const @@ -59,7 +52,7 @@ std::string CPropertySlider::dump () const void CPropertySlider::update (const std::string& value) { - double newValue = atof (value.c_str ()); + double newValue = strtod (value.c_str (), nullptr); if (newValue < this->m_min || newValue > this->m_max) sLog.exception ("Slider value (", newValue, ") is out of range (", this->m_min, ",", this->m_max, ")"); diff --git a/src/WallpaperEngine/Core/Projects/CPropertySlider.h b/src/WallpaperEngine/Core/Projects/CPropertySlider.h index b9aac5a..8d210f1 100644 --- a/src/WallpaperEngine/Core/Projects/CPropertySlider.h +++ b/src/WallpaperEngine/Core/Projects/CPropertySlider.h @@ -30,4 +30,4 @@ namespace WallpaperEngine::Core::Projects double m_max; double m_step; }; -}; +} diff --git a/src/WallpaperEngine/Core/Projects/CPropertyText.h b/src/WallpaperEngine/Core/Projects/CPropertyText.h index 855f7cc..5db16ff 100644 --- a/src/WallpaperEngine/Core/Projects/CPropertyText.h +++ b/src/WallpaperEngine/Core/Projects/CPropertyText.h @@ -18,4 +18,4 @@ namespace WallpaperEngine::Core::Projects private: CPropertyText (const std::string& name, const std::string& text); }; -}; +} diff --git a/src/WallpaperEngine/Core/Scenes/CCamera.h b/src/WallpaperEngine/Core/Scenes/CCamera.h index 2bbe8be..df9e20e 100644 --- a/src/WallpaperEngine/Core/Scenes/CCamera.h +++ b/src/WallpaperEngine/Core/Scenes/CCamera.h @@ -21,4 +21,4 @@ namespace WallpaperEngine::Core::Scenes glm::vec3 m_eye; glm::vec3 m_up; }; -}; +} diff --git a/src/WallpaperEngine/Core/Scenes/CProjection.cpp b/src/WallpaperEngine/Core/Scenes/CProjection.cpp index d4b9572..d43bd4f 100644 --- a/src/WallpaperEngine/Core/Scenes/CProjection.cpp +++ b/src/WallpaperEngine/Core/Scenes/CProjection.cpp @@ -3,13 +3,16 @@ using namespace WallpaperEngine::Core::Scenes; CProjection::CProjection (uint32_t width, uint32_t height) : + m_isAuto (false), m_width (width), m_height (height) { } CProjection::CProjection (bool isAuto) : - m_isAuto (isAuto) + m_isAuto (isAuto), + m_width (0), + m_height (0) { } @@ -23,7 +26,7 @@ const uint32_t& CProjection::getHeight () const return this->m_height; } -const bool CProjection::isAuto () const +bool CProjection::isAuto () const { return this->m_isAuto; } @@ -46,7 +49,7 @@ CProjection* CProjection::fromJSON (json data) auto height_it = jsonFindRequired (data, "height", "Projection must have height"); // TODO: PROPERLY SUPPORT AUTO-DETECTING SIZE - if (auto_it == true) + if (auto_it) return new CProjection (true); else return new CProjection ( diff --git a/src/WallpaperEngine/Core/Scenes/CProjection.h b/src/WallpaperEngine/Core/Scenes/CProjection.h index f81e4e4..8f4af06 100644 --- a/src/WallpaperEngine/Core/Scenes/CProjection.h +++ b/src/WallpaperEngine/Core/Scenes/CProjection.h @@ -13,7 +13,7 @@ namespace WallpaperEngine::Core::Scenes const uint32_t& getWidth () const; const uint32_t& getHeight () const; - const bool isAuto () const; + bool isAuto () const; void setWidth (uint32_t width); void setHeight (uint32_t height); @@ -26,4 +26,4 @@ namespace WallpaperEngine::Core::Scenes uint32_t m_height; bool m_isAuto; }; -}; +} diff --git a/src/WallpaperEngine/Core/UserSettings/CUserSettingBoolean.cpp b/src/WallpaperEngine/Core/UserSettings/CUserSettingBoolean.cpp index d41d8aa..b3eb5b0 100644 --- a/src/WallpaperEngine/Core/UserSettings/CUserSettingBoolean.cpp +++ b/src/WallpaperEngine/Core/UserSettings/CUserSettingBoolean.cpp @@ -26,15 +26,15 @@ CUserSettingBoolean* CUserSettingBoolean::fromJSON (nlohmann::json& data) { bool hasCondition = false; bool hasSource = false; - bool defaultValue = false; + bool defaultValue; std::string source; std::string expectedValue; - if (data.is_object () == true) + if (data.is_object ()) { hasSource = true; auto userIt = data.find ("user"); - defaultValue = jsonFindDefault (data, "value", false); // is this default value right? + defaultValue = jsonFindDefault (data, "value", true); // is this default value right? if (userIt != data.end ()) { @@ -56,7 +56,7 @@ CUserSettingBoolean* CUserSettingBoolean::fromJSON (nlohmann::json& data) } else { - if (data.is_boolean () == false) + if (!data.is_boolean ()) sLog.error ("Expected boolean value on user setting"); defaultValue = data.get (); @@ -70,14 +70,14 @@ CUserSettingBoolean* CUserSettingBoolean::fromScalar (bool value) return new CUserSettingBoolean (false, false, value, "", ""); } -bool CUserSettingBoolean::getDefaultValue () +bool CUserSettingBoolean::getDefaultValue () const { return this->m_default; } bool CUserSettingBoolean::processValue (const std::vector& properties) { - if (this->m_hasSource == false && this->m_hasCondition == false) + if (!this->m_hasSource && !this->m_hasCondition) return this->getDefaultValue (); for (auto cur : properties) @@ -85,7 +85,7 @@ bool CUserSettingBoolean::processValue (const std::vector& if (cur->getName () != this->m_source) continue; - if (this->m_hasCondition == false) + if (!this->m_hasCondition) { if (cur->is ()) return cur->as ()->getValue (); diff --git a/src/WallpaperEngine/Core/UserSettings/CUserSettingBoolean.h b/src/WallpaperEngine/Core/UserSettings/CUserSettingBoolean.h index bd44272..1e00027 100644 --- a/src/WallpaperEngine/Core/UserSettings/CUserSettingBoolean.h +++ b/src/WallpaperEngine/Core/UserSettings/CUserSettingBoolean.h @@ -19,7 +19,7 @@ namespace WallpaperEngine::Core::UserSettings static std::string Type; bool processValue (const std::vector& properties); - bool getDefaultValue (); + bool getDefaultValue () const; private: CUserSettingBoolean (bool hasCondition, bool hasSource, bool defaultValue, std::string source, std::string expectedValue); diff --git a/src/WallpaperEngine/Core/UserSettings/CUserSettingFloat.cpp b/src/WallpaperEngine/Core/UserSettings/CUserSettingFloat.cpp index ee10d1a..647ce4f 100644 --- a/src/WallpaperEngine/Core/UserSettings/CUserSettingFloat.cpp +++ b/src/WallpaperEngine/Core/UserSettings/CUserSettingFloat.cpp @@ -21,13 +21,13 @@ CUserSettingFloat::CUserSettingFloat (bool hasCondition, bool hasSource, double CUserSettingFloat* CUserSettingFloat::fromJSON (nlohmann::json& data) { - bool hasCondition = false; - bool hasSource = false; - double defaultValue = false; + double defaultValue; std::string source; std::string expectedValue; + bool hasCondition = false; + bool hasSource = false; - if (data.is_object () == true) + if (data.is_object ()) { hasSource = true; auto userIt = data.find ("user"); @@ -53,7 +53,7 @@ CUserSettingFloat* CUserSettingFloat::fromJSON (nlohmann::json& data) } else { - if (data.is_number () == false) + if (!data.is_number ()) sLog.exception ("Expected numeric value on user settings"); defaultValue = data.get (); @@ -67,14 +67,14 @@ CUserSettingFloat* CUserSettingFloat::fromScalar (double value) return new CUserSettingFloat (false, false, value, "", ""); } -double CUserSettingFloat::getDefaultValue () +double CUserSettingFloat::getDefaultValue () const { return this->m_default; } double CUserSettingFloat::processValue (const std::vector& properties) { - if (this->m_hasSource == false && this->m_hasCondition == false) + if (!this->m_hasSource && !this->m_hasCondition) return this->getDefaultValue (); for (auto cur : properties) @@ -82,7 +82,7 @@ double CUserSettingFloat::processValue (const std::vector& if (cur->getName () != this->m_source) continue; - if (this->m_hasCondition == false) + if (!this->m_hasCondition) { if (cur->is ()) return cur->as ()->getValue (); diff --git a/src/WallpaperEngine/Core/UserSettings/CUserSettingFloat.h b/src/WallpaperEngine/Core/UserSettings/CUserSettingFloat.h index 420492d..5cab219 100644 --- a/src/WallpaperEngine/Core/UserSettings/CUserSettingFloat.h +++ b/src/WallpaperEngine/Core/UserSettings/CUserSettingFloat.h @@ -19,7 +19,7 @@ namespace WallpaperEngine::Core::UserSettings static std::string Type; double processValue (const std::vector& properties); - double getDefaultValue (); + double getDefaultValue () const; private: CUserSettingFloat (bool hasCondition, bool hasSource, double defaultValue, std::string source, std::string expectedValue); diff --git a/src/WallpaperEngine/Core/UserSettings/CUserSettingValue.h b/src/WallpaperEngine/Core/UserSettings/CUserSettingValue.h index f08e3ae..e706df6 100644 --- a/src/WallpaperEngine/Core/UserSettings/CUserSettingValue.h +++ b/src/WallpaperEngine/Core/UserSettings/CUserSettingValue.h @@ -13,9 +13,9 @@ namespace WallpaperEngine::Core::UserSettings template bool is () { return this->m_type == T::Type; } protected: - CUserSettingValue (std::string type); + explicit CUserSettingValue (std::string type); private: std::string m_type; }; -}; +} diff --git a/src/WallpaperEngine/Core/UserSettings/CUserSettingVector3.cpp b/src/WallpaperEngine/Core/UserSettings/CUserSettingVector3.cpp index 70005e4..d0192fe 100644 --- a/src/WallpaperEngine/Core/UserSettings/CUserSettingVector3.cpp +++ b/src/WallpaperEngine/Core/UserSettings/CUserSettingVector3.cpp @@ -28,7 +28,7 @@ CUserSettingVector3* CUserSettingVector3::fromJSON (nlohmann::json& data) std::string source; std::string expectedValue; - if (data.is_object () == true) + if (data.is_object ()) { hasSource = true; auto userIt = data.find ("user"); @@ -54,7 +54,7 @@ CUserSettingVector3* CUserSettingVector3::fromJSON (nlohmann::json& data) } else { - if (data.is_string () == false) + if (!data.is_string ()) sLog.exception ("Expected vector value on user settings"); defaultValue = WallpaperEngine::Core::aToColorf (data.get ().c_str ()); @@ -68,14 +68,14 @@ CUserSettingVector3* CUserSettingVector3::fromScalar (glm::vec3 value) return new CUserSettingVector3 (false, false, value, "", ""); } -glm::vec3 CUserSettingVector3::getDefaultValue () +glm::vec3 CUserSettingVector3::getDefaultValue () const { return this->m_default; } glm::vec3 CUserSettingVector3::processValue (const std::vector& properties) { - if (this->m_hasSource == false && this->m_hasCondition == false) + if (!this->m_hasSource && !this->m_hasCondition) return this->getDefaultValue (); for (auto cur : properties) @@ -83,7 +83,7 @@ glm::vec3 CUserSettingVector3::processValue (const std::vectorgetName () != this->m_source) continue; - if (this->m_hasCondition == false) + if (!this->m_hasCondition) { if (cur->is ()) return cur->as ()->getValue (); diff --git a/src/WallpaperEngine/Core/UserSettings/CUserSettingVector3.h b/src/WallpaperEngine/Core/UserSettings/CUserSettingVector3.h index 84bdcb5..5fa629e 100644 --- a/src/WallpaperEngine/Core/UserSettings/CUserSettingVector3.h +++ b/src/WallpaperEngine/Core/UserSettings/CUserSettingVector3.h @@ -21,7 +21,7 @@ namespace WallpaperEngine::Core::UserSettings static std::string Type; glm::vec3 processValue (const std::vector& properties); - glm::vec3 getDefaultValue (); + glm::vec3 getDefaultValue () const; private: CUserSettingVector3 (bool hasCondition, bool hasSource, glm::vec3 defaultValue, std::string source, std::string expectedValue); diff --git a/src/WallpaperEngine/Input/CInputContext.h b/src/WallpaperEngine/Input/CInputContext.h index 44f0114..5c47718 100644 --- a/src/WallpaperEngine/Input/CInputContext.h +++ b/src/WallpaperEngine/Input/CInputContext.h @@ -13,7 +13,7 @@ namespace WallpaperEngine::Input class CInputContext { public: - CInputContext (Render::Drivers::COpenGLDriver& videoDriver); + explicit CInputContext (Render::Drivers::COpenGLDriver& videoDriver); void update (); const CMouseInput& getMouseInput () const; diff --git a/src/WallpaperEngine/Input/CMouseInput.cpp b/src/WallpaperEngine/Input/CMouseInput.cpp index 4338b50..458bb4d 100644 --- a/src/WallpaperEngine/Input/CMouseInput.cpp +++ b/src/WallpaperEngine/Input/CMouseInput.cpp @@ -3,7 +3,7 @@ using namespace WallpaperEngine::Input; -CMouseInput::CMouseInput (GLFWwindow* window) : position(0, 0), m_window (window) {} +CMouseInput::CMouseInput (GLFWwindow* window) : position (), m_mousePosition (), m_window (window) {} void CMouseInput::update () { diff --git a/src/WallpaperEngine/Input/CMouseInput.h b/src/WallpaperEngine/Input/CMouseInput.h index 746c2d9..08f9f7e 100644 --- a/src/WallpaperEngine/Input/CMouseInput.h +++ b/src/WallpaperEngine/Input/CMouseInput.h @@ -11,7 +11,7 @@ namespace WallpaperEngine::Input class CMouseInput { public: - CMouseInput(GLFWwindow* window); + explicit CMouseInput(GLFWwindow* window); /** * Takes current mouse position and updates it @@ -33,5 +33,5 @@ namespace WallpaperEngine::Input */ glm::dvec2 m_mousePosition; }; -}; +} diff --git a/src/WallpaperEngine/Render/CCamera.cpp b/src/WallpaperEngine/Render/CCamera.cpp index d740823..e8f3b8f 100644 --- a/src/WallpaperEngine/Render/CCamera.cpp +++ b/src/WallpaperEngine/Render/CCamera.cpp @@ -9,7 +9,9 @@ using namespace WallpaperEngine::Render; CCamera::CCamera (CScene* scene, const Core::Scenes::CCamera* camera) : m_camera (camera), m_scene (scene), - m_isOrthogonal (false) + m_isOrthogonal (false), + m_projection (), + m_lookat () { // get the lookat position // TODO: ENSURE THIS IS ONLY USED WHEN NOT DOING AN ORTOGRAPHIC CAMERA AS IT THROWS OFF POINTS @@ -17,9 +19,7 @@ CCamera::CCamera (CScene* scene, const Core::Scenes::CCamera* camera) : } CCamera::~CCamera () -{ - -} += default; const glm::vec3& CCamera::getCenter () const { @@ -46,11 +46,16 @@ const glm::mat4& CCamera::getLookAt () const return this->m_lookat; } -const bool CCamera::isOrthogonal () const +bool CCamera::isOrthogonal () const { return this->m_isOrthogonal; } +CScene* CCamera::getScene () const +{ + return this->m_scene; +} + void CCamera::setOrthogonalProjection (float width, float height) { // TODO: GET THE ZNEAR AND ZFAR FROM THE BACKGROUND (IF AVAILABLE) diff --git a/src/WallpaperEngine/Render/CCamera.h b/src/WallpaperEngine/Render/CCamera.h index 383ba20..9a4ea0f 100644 --- a/src/WallpaperEngine/Render/CCamera.h +++ b/src/WallpaperEngine/Render/CCamera.h @@ -24,7 +24,8 @@ namespace WallpaperEngine::Render const glm::vec3& getUp () const; const glm::mat4& getProjection () const; const glm::mat4& getLookAt () const; - const bool isOrthogonal () const; + CScene* getScene () const; + bool isOrthogonal () const; private: bool m_isOrthogonal; diff --git a/src/WallpaperEngine/Render/CFBO.cpp b/src/WallpaperEngine/Render/CFBO.cpp index 335ed3f..066660d 100644 --- a/src/WallpaperEngine/Render/CFBO.cpp +++ b/src/WallpaperEngine/Render/CFBO.cpp @@ -14,7 +14,11 @@ CFBO::CFBO ( m_name (std::move (name)), m_format (format), m_scale (scale), - m_flags (flags) + m_flags (flags), + m_framebuffer (GL_NONE), + m_depthbuffer (GL_NONE), + m_texture (GL_NONE), + m_resolution () { // create an empty texture that'll be free'd so the FBO is transparent GLenum drawBuffers [1] = {GL_COLOR_ATTACHMENT0}; @@ -28,9 +32,9 @@ CFBO::CFBO ( // give OpenGL an empty image glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA8, textureWidth, textureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); // label stuff for debugging - if (DEBUG) +#if DEBUG glObjectLabel (GL_TEXTURE, this->m_texture, -1, this->m_name.c_str ()); - +#endif /* DEBUG */ // set filtering parameters, otherwise the texture is not rendered if (flags & TextureFlags::ClampUVs) { @@ -74,7 +78,7 @@ CFBO::CFBO ( }; // create the textureframe entries - TextureFrame* frame = new TextureFrame; + auto* frame = new TextureFrame; frame->frameNumber = 0; frame->frametime = 0; diff --git a/src/WallpaperEngine/Render/CFBO.h b/src/WallpaperEngine/Render/CFBO.h index 83ccadf..d7372f1 100644 --- a/src/WallpaperEngine/Render/CFBO.h +++ b/src/WallpaperEngine/Render/CFBO.h @@ -41,4 +41,4 @@ namespace WallpaperEngine::Render /** Placeholder for frames, FBOs only have ONE */ std::vector m_frames; }; -}; +} diff --git a/src/WallpaperEngine/Render/CObject.cpp b/src/WallpaperEngine/Render/CObject.cpp index 7a6262e..f8184d3 100644 --- a/src/WallpaperEngine/Render/CObject.cpp +++ b/src/WallpaperEngine/Render/CObject.cpp @@ -13,8 +13,7 @@ CObject::CObject(CScene* scene, std::string type, Core::CObject *object) : } CObject::~CObject () -{ -} += default; CScene* CObject::getScene () const { @@ -26,7 +25,7 @@ const CContainer& CObject::getContainer () const return this->getScene ()->getContainer (); } -const int CObject::getId () const +int CObject::getId () const { return this->m_object->getId (); } \ No newline at end of file diff --git a/src/WallpaperEngine/Render/CObject.h b/src/WallpaperEngine/Render/CObject.h index 018b2e3..0e787fb 100644 --- a/src/WallpaperEngine/Render/CObject.h +++ b/src/WallpaperEngine/Render/CObject.h @@ -22,7 +22,7 @@ namespace WallpaperEngine::Render CScene* getScene () const; const CContainer& getContainer () const; - const int getId () const; + int getId () const; protected: CObject (CScene* scene, std::string type, Core::CObject *object); diff --git a/src/WallpaperEngine/Render/CRenderContext.cpp b/src/WallpaperEngine/Render/CRenderContext.cpp index a41e603..cc797a1 100644 --- a/src/WallpaperEngine/Render/CRenderContext.cpp +++ b/src/WallpaperEngine/Render/CRenderContext.cpp @@ -59,14 +59,20 @@ CRenderContext::CRenderContext (std::vector screens, CVideoDriver& m_container (container), m_app (app), m_input (input), - m_textureCache (new CTextureCache (*this)) + m_textureCache (new CTextureCache (*this)), + m_display (nullptr), + m_pixmap (0), + m_gc (nullptr), + m_image (nullptr), + m_imageData (nullptr), + m_fbo (nullptr) { this->initialize (); } void CRenderContext::initialize () { - if (this->m_screens.empty () == true) + if (this->m_screens.empty ()) this->setupWindow (); else this->setupScreens (); @@ -162,7 +168,7 @@ void CRenderContext::setupScreens () CRenderContext::~CRenderContext () { - if (this->m_screens.empty () == false) + if (!this->m_screens.empty ()) { // free any used resource XDestroyImage (this->m_image); @@ -182,12 +188,11 @@ void CRenderContext::renderScreens () for (const auto& cur : this->m_viewports) { - if (DEBUG) - { - std::string str = "Rendering to screen " + cur.name; +#if DEBUG + std::string str = "Rendering to screen " + cur.name; - glPushDebugGroup (GL_DEBUG_SOURCE_APPLICATION, 0, -1, str.c_str ()); - } + glPushDebugGroup (GL_DEBUG_SOURCE_APPLICATION, 0, -1, str.c_str ()); +#endif /* DEBUG */ // render the background this->m_wallpaper->render (cur.viewport, false, renderFrame, firstFrame); @@ -196,8 +201,9 @@ void CRenderContext::renderScreens () firstFrame = false; renderFrame = !this->m_wallpaper->is (); - if (DEBUG) - glPopDebugGroup (); +#if DEBUG + glPopDebugGroup (); +#endif /* DEBUG */ } // read the full texture into the image @@ -229,10 +235,10 @@ void CRenderContext::render () if (this->m_wallpaper == nullptr) return; - if (this->m_viewports.empty () == false) - this->renderScreens (); - else - this->renderWindow (); + if (this->m_viewports.empty ()) + this->renderWindow (); + else + this->renderScreens (); this->m_driver.swapBuffers (); } @@ -242,7 +248,7 @@ void CRenderContext::setWallpaper (CWallpaper* wallpaper) this->m_wallpaper = wallpaper; // update the wallpaper's texcoords based on the mode we're running - if (this->m_screens.empty () == false) + if (!this->m_screens.empty ()) { GLfloat texCoords [] = { 0.0f, 1.0f, diff --git a/src/WallpaperEngine/Render/CScene.cpp b/src/WallpaperEngine/Render/CScene.cpp index c11739d..0856fd4 100644 --- a/src/WallpaperEngine/Render/CScene.cpp +++ b/src/WallpaperEngine/Render/CScene.cpp @@ -15,18 +15,21 @@ using namespace WallpaperEngine; using namespace WallpaperEngine::Render; CScene::CScene (Core::CScene* scene, CRenderContext& context, CAudioContext& audioContext) : - CWallpaper (scene, Type, context, audioContext) + CWallpaper (scene, Type, context, audioContext), + m_mousePosition (), + m_mousePositionLast (), + m_parallaxDisplacement () { // setup the scene camera this->m_camera = new CCamera (this, scene->getCamera ()); // detect size if the orthogonal project is auto - if (scene->getOrthogonalProjection ()->isAuto () == true) + if (scene->getOrthogonalProjection ()->isAuto ()) { // calculate the size of the projection based on the size of everything for (const auto& cur : scene->getObjects ()) { - if (cur.second->is () == false) + if (!cur.second->is ()) continue; glm::vec2 size = cur.second->as ()->getSize (); @@ -149,7 +152,7 @@ CScene::CScene (Core::CScene* scene, CRenderContext& context, CAudioContext& aud auto json = nlohmann::json::parse (imagejson); // create image for bloom passes - if (this->getScene ()->isBloom () == true) + if (this->getScene ()->isBloom ()) { this->m_bloomObject = this->createObject ( WallpaperEngine::Core::CObject::fromJSON ( @@ -184,15 +187,15 @@ Render::CObject* CScene::createObject (Core::CObject* object) this->createObject ((*dep).second); } - if (object->is() == true) + if (object->is ()) { - Objects::CImage* image = new Objects::CImage (this, object->as()); + auto* image = new Objects::CImage (this, object->as()); try { image->setup (); } - catch (std::runtime_error ex) + catch (std::runtime_error& ex) { // this error message is already printed, so just show extra info about it sLog.error ("Cannot setup image ", image->getImage ()->getName ()); @@ -200,7 +203,7 @@ Render::CObject* CScene::createObject (Core::CObject* object) renderObject = image; } - else if (object->is() == true) + else if (object->is ()) { renderObject = new Objects::CSound (this, object->as()); } @@ -222,7 +225,7 @@ void CScene::renderFrame (glm::ivec4 viewport) this->updateMouse (viewport); // update the parallax position if required - if (this->getScene ()->isCameraParallax () == true) + if (this->getScene ()->isCameraParallax ()) { float influence = this->getScene ()->getCameraParallaxMouseInfluence (); float amount = this->getScene ()->getCameraParallaxAmount (); diff --git a/src/WallpaperEngine/Render/CTextureCache.cpp b/src/WallpaperEngine/Render/CTextureCache.cpp index 5557bf6..bf5d26d 100644 --- a/src/WallpaperEngine/Render/CTextureCache.cpp +++ b/src/WallpaperEngine/Render/CTextureCache.cpp @@ -8,8 +8,7 @@ CTextureCache::CTextureCache (CRenderContext& context) : } CTextureCache::~CTextureCache () -{ -} + = default; const ITexture* CTextureCache::resolve (const std::string& filename) { diff --git a/src/WallpaperEngine/Render/CVideo.cpp b/src/WallpaperEngine/Render/CVideo.cpp index fbe77a7..58f3021 100644 --- a/src/WallpaperEngine/Render/CVideo.cpp +++ b/src/WallpaperEngine/Render/CVideo.cpp @@ -18,7 +18,8 @@ void* get_proc_address (void* ctx, const char* name) CVideo::CVideo (Core::CVideo* video, CRenderContext& context, CAudioContext& audioContext) : CWallpaper (video, Type, context, audioContext), m_width (16), - m_height (16) + m_height (16), + m_mpvGl (nullptr) { double volume = g_AudioVolume * 100.0 / 128.0; @@ -60,7 +61,7 @@ CVideo::CVideo (Core::CVideo* video, CRenderContext& context, CAudioContext& aud if (mpv_command (this->m_mpv, command) < 0) sLog.exception ("Cannot load video to play"); - if (g_AudioEnabled == false) + if (!g_AudioEnabled) { const char* mutecommand [] = { "set", "mute", "yes", nullptr @@ -98,18 +99,14 @@ void CVideo::renderFrame (glm::ivec4 viewport) break; // we do not care about any of the events - switch (event->event_id) - { - case MPV_EVENT_VIDEO_RECONFIG: - { - int64_t width, height; + if (event->event_id == MPV_EVENT_VIDEO_RECONFIG) + { + int64_t width, height; - if (mpv_get_property (this->m_mpv, "dwidth", MPV_FORMAT_INT64, &width) >= 0 && - mpv_get_property (this->m_mpv, "dheight", MPV_FORMAT_INT64, &height) >= 0) - this->setSize (width, height); - } - break; - } + if (mpv_get_property (this->m_mpv, "dwidth", MPV_FORMAT_INT64, &width) >= 0 && + mpv_get_property (this->m_mpv, "dheight", MPV_FORMAT_INT64, &height) >= 0) + this->setSize (width, height); + } } // render the next diff --git a/src/WallpaperEngine/Render/CVideo.h b/src/WallpaperEngine/Render/CVideo.h index cfa437e..eb90a30 100644 --- a/src/WallpaperEngine/Render/CVideo.h +++ b/src/WallpaperEngine/Render/CVideo.h @@ -35,4 +35,4 @@ namespace WallpaperEngine::Render int64_t m_width; int64_t m_height; }; -}; +} diff --git a/src/WallpaperEngine/Render/CWallpaper.cpp b/src/WallpaperEngine/Render/CWallpaper.cpp index fd6229b..16c4304 100644 --- a/src/WallpaperEngine/Render/CWallpaper.cpp +++ b/src/WallpaperEngine/Render/CWallpaper.cpp @@ -14,6 +14,14 @@ CWallpaper::CWallpaper (Core::CWallpaper* wallpaperData, std::string type, CRend m_type (std::move(type)), m_context (context), m_destFramebuffer (GL_NONE), + m_sceneFBO (nullptr), + m_texCoordBuffer (GL_NONE), + m_positionBuffer (GL_NONE), + m_shader (GL_NONE), + g_Texture0 (GL_NONE), + a_Position (GL_NONE), + a_TexCoord (GL_NONE), + m_vaoBuffer (GL_NONE), m_audioContext (audioContext) { // generate the VAO to stop opengl from complaining @@ -51,8 +59,7 @@ CWallpaper::CWallpaper (Core::CWallpaper* wallpaperData, std::string type, CRend } CWallpaper::~CWallpaper () -{ -} += default; const CContainer& CWallpaper::getContainer () const { @@ -203,7 +210,7 @@ void CWallpaper::setDestinationFramebuffer (GLuint framebuffer) void CWallpaper::render (glm::ivec4 viewport, bool vflip, bool renderFrame, bool newFrame) { - if (renderFrame == true) + if (renderFrame) this->renderFrame (viewport); uint32_t projectionWidth = this->getWidth (); @@ -367,9 +374,9 @@ CFBO* CWallpaper::getFBO () const CWallpaper* CWallpaper::fromWallpaper (Core::CWallpaper* wallpaper, CRenderContext& context, CAudioContext& audioContext) { - if (wallpaper->is () == true) + if (wallpaper->is ()) return new WallpaperEngine::Render::CScene (wallpaper->as (), context, audioContext); - else if (wallpaper->is () == true) + else if (wallpaper->is ()) return new WallpaperEngine::Render::CVideo (wallpaper->as (), context, audioContext); else sLog.exception ("Unsupported wallpaper type"); diff --git a/src/WallpaperEngine/Render/Drivers/COpenGLDriver.cpp b/src/WallpaperEngine/Render/Drivers/COpenGLDriver.cpp index 4aad06d..14190ae 100644 --- a/src/WallpaperEngine/Render/Drivers/COpenGLDriver.cpp +++ b/src/WallpaperEngine/Render/Drivers/COpenGLDriver.cpp @@ -18,8 +18,9 @@ COpenGLDriver::COpenGLDriver (const char* windowTitle) : glfwWindowHint (GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint (GLFW_VISIBLE, GLFW_FALSE); - if (DEBUG) - glfwWindowHint (GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE); +#if DEBUG + glfwWindowHint (GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE); +#endif /* DEBUG */ // create window, size doesn't matter as long as we don't show it this->m_window = glfwCreateWindow (640, 480, windowTitle, nullptr, nullptr); diff --git a/src/WallpaperEngine/Render/Drivers/COpenGLDriver.h b/src/WallpaperEngine/Render/Drivers/COpenGLDriver.h index 1c38902..9ece21c 100644 --- a/src/WallpaperEngine/Render/Drivers/COpenGLDriver.h +++ b/src/WallpaperEngine/Render/Drivers/COpenGLDriver.h @@ -9,7 +9,7 @@ namespace WallpaperEngine::Render::Drivers class COpenGLDriver : public CVideoDriver { public: - COpenGLDriver (const char* windowTitle); + explicit COpenGLDriver (const char* windowTitle); ~COpenGLDriver(); float getRenderTime () override; diff --git a/src/WallpaperEngine/Render/Objects/CEffect.cpp b/src/WallpaperEngine/Render/Objects/CEffect.cpp index c565eaa..39ce4b1 100644 --- a/src/WallpaperEngine/Render/Objects/CEffect.cpp +++ b/src/WallpaperEngine/Render/Objects/CEffect.cpp @@ -1,7 +1,7 @@ #include "CEffect.h" -using namespace WallpaperEngine::Render::Objects; using namespace WallpaperEngine::Render; +using namespace WallpaperEngine::Render::Objects; CEffect::CEffect (CImage* image, Core::Objects::CEffect* effect) : m_image (image), diff --git a/src/WallpaperEngine/Render/Objects/CEffect.h b/src/WallpaperEngine/Render/Objects/CEffect.h index 0f8e5c5..3469b36 100644 --- a/src/WallpaperEngine/Render/Objects/CEffect.h +++ b/src/WallpaperEngine/Render/Objects/CEffect.h @@ -36,4 +36,4 @@ namespace WallpaperEngine::Render::Objects std::vector m_fbos; std::vector m_materials; }; -}; +} diff --git a/src/WallpaperEngine/Render/Objects/CImage.cpp b/src/WallpaperEngine/Render/Objects/CImage.cpp index de8667b..0495200 100644 --- a/src/WallpaperEngine/Render/Objects/CImage.cpp +++ b/src/WallpaperEngine/Render/Objects/CImage.cpp @@ -7,8 +7,20 @@ using namespace WallpaperEngine::Render::Objects; CImage::CImage (CScene* scene, Core::Objects::CImage* image) : Render::CObject (scene, Type, image), m_image (image), + m_animationTime (0.0), + m_material (nullptr), + m_colorBlendMaterial (nullptr), m_texture (nullptr), - m_initialized (false) + m_initialized (false), + m_sceneSpacePosition (GL_NONE), + m_copySpacePosition (GL_NONE), + m_texcoordCopy (GL_NONE), + m_texcoordPass (GL_NONE), + m_passSpacePosition (GL_NONE), + m_modelViewProjectionScreen (), + m_modelViewProjectionCopy (), + m_modelViewProjectionPass (glm::mat4 (1.0)), + m_pos () { auto projection = this->getScene ()->getScene ()->getOrthogonalProjection (); @@ -58,7 +70,7 @@ CImage::CImage (CScene* scene, Core::Objects::CImage* image) : // detect texture (if any) auto textures = (*this->m_image->getMaterial ()->getPasses ().begin ())->getTextures (); - if (textures.empty() == false) + if (!textures.empty()) { std::string textureName = *textures.begin (); @@ -144,7 +156,7 @@ CImage::CImage (CScene* scene, Core::Objects::CImage* image) : float width = 1.0f; float height = 1.0f; - if (this->getTexture ()->isAnimated () == true) + if (this->getTexture ()->isAnimated ()) { // animated images use different coordinates as they're essentially a texture atlas width = static_cast (this->getTexture ()->getRealWidth ()) / static_cast (this->getTexture ()->getTextureWidth ()); @@ -169,7 +181,7 @@ CImage::CImage (CScene* scene, Core::Objects::CImage* image) : float x = 0.0f; float y = 0.0f; - if (this->getTexture ()->isAnimated () == true) + if (this->getTexture ()->isAnimated ()) { // animations should be copied completely x = 0.0f; @@ -222,7 +234,6 @@ CImage::CImage (CScene* scene, Core::Objects::CImage* image) : this->getScene ()->getCamera ()->getProjection () * this->getScene ()->getCamera ()->getLookAt (); - this->m_modelViewProjectionPass = glm::mat4(1.0f); this->m_modelViewProjectionCopy = glm::ortho (0.0, size.x, 0.0, size.y); } @@ -247,7 +258,7 @@ void CImage::setup () } // prepare the passes list - if (this->getImage ()->getEffects ().empty () == false) + if (!this->getImage ()->getEffects ().empty ()) { // generate the effects used by this material for (const auto& cur : this->getImage ()->getEffects ()) @@ -321,7 +332,7 @@ void CImage::setupPasses () first = false; // set viewport and target texture if needed - if (pass->getMaterial ()->getMaterial ()->hasTarget () == true) + if (pass->getMaterial ()->getMaterial ()->hasTarget ()) { // setup target texture std::string target = pass->getMaterial ()->getMaterial ()->getTarget (); @@ -334,7 +345,7 @@ void CImage::setupPasses () drawTo = this->getScene ()->findFBO (target); } // determine if it's the last element in the list as this is a screen-copy-like process - else if (std::next (cur) == end && this->getImage ()->isVisible () == true) + else if (std::next (cur) == end && this->getImage ()->isVisible ()) { // TODO: PROPERLY CHECK EFFECT'S VISIBILITY AND TAKE IT INTO ACCOUNT spacePosition = this->getSceneSpacePosition (); @@ -351,7 +362,7 @@ void CImage::setupPasses () texcoord = this->getTexCoordPass (); drawTo = prevDrawTo; - if (pass->getMaterial ()->getMaterial ()->hasTarget () == false) + if (!pass->getMaterial ()->getMaterial ()->hasTarget ()) this->pinpongFramebuffer (&drawTo, &asInput); } } @@ -375,29 +386,28 @@ void CImage::pinpongFramebuffer (const CFBO** drawTo, const ITexture** asInput) void CImage::render () { // do not try to render something that did not initialize successfully - if (this->m_initialized == false) + if (!this->m_initialized) return; glColorMask (true, true, true, true); // update the position if required - if (this->getScene ()->getScene ()->isCameraParallax () == true) + if (this->getScene ()->getScene ()->isCameraParallax ()) this->updateScreenSpacePosition (); - if (DEBUG) - { - std::string str = "Rendering "; +#if DEBUG + std::string str = "Rendering "; - if (this->getScene ()->getScene ()->isBloom () && this->getId () == 0xFFFFFFFF) - str += "bloom"; - else - { - str += this->getImage ()->getName () + - " (" + std::to_string (this->getId ()) + ", " + this->getImage ()->getMaterial ()->getName () + ")"; - } + if (this->getScene ()->getScene ()->isBloom () && this->getId () == 0xFFFFFFFF) + str += "bloom"; + else + { + str += this->getImage ()->getName () + + " (" + std::to_string (this->getId ()) + ", " + this->getImage ()->getMaterial ()->getName () + ")"; + } - glPushDebugGroup (GL_DEBUG_SOURCE_APPLICATION, 0, -1, str.c_str ()); - } + glPushDebugGroup (GL_DEBUG_SOURCE_APPLICATION, 0, -1, str.c_str ()); +#endif /* DEBUG */ auto cur = this->m_passes.begin (); auto end = this->m_passes.end (); @@ -411,8 +421,9 @@ void CImage::render () (*cur)->render (); } - if (DEBUG) +#if DEBUG glPopDebugGroup (); +#endif /* DEBUG */ } void CImage::updateScreenSpacePosition () @@ -440,7 +451,7 @@ const ITexture* CImage::getTexture () const return this->m_texture; } -const double CImage::getAnimationTime () const +double CImage::getAnimationTime () const { return this->m_animationTime; } @@ -455,7 +466,7 @@ const std::vector& CImage::getEffects () const return this->m_effects; } -const glm::vec2 CImage::getSize() const +glm::vec2 CImage::getSize() const { if (this->m_texture == nullptr) return this->getImage ()->getSize (); @@ -463,27 +474,27 @@ const glm::vec2 CImage::getSize() const return {this->m_texture->getRealWidth (), this->m_texture->getRealHeight ()}; } -const GLuint CImage::getSceneSpacePosition () const +GLuint CImage::getSceneSpacePosition () const { return this->m_sceneSpacePosition; } -const GLuint CImage::getCopySpacePosition () const +GLuint CImage::getCopySpacePosition () const { return this->m_copySpacePosition; } -const GLuint CImage::getPassSpacePosition () const +GLuint CImage::getPassSpacePosition () const { return this->m_passSpacePosition; } -const GLuint CImage::getTexCoordCopy () const +GLuint CImage::getTexCoordCopy () const { return this->m_texcoordCopy; } -const GLuint CImage::getTexCoordPass () const +GLuint CImage::getTexCoordPass () const { return this->m_texcoordPass; } diff --git a/src/WallpaperEngine/Render/Objects/CImage.h b/src/WallpaperEngine/Render/Objects/CImage.h index bfe33ff..9d3f8d1 100644 --- a/src/WallpaperEngine/Render/Objects/CImage.h +++ b/src/WallpaperEngine/Render/Objects/CImage.h @@ -38,15 +38,15 @@ namespace WallpaperEngine::Render::Objects const Core::Objects::CImage* getImage () const; const std::vector& getEffects () const; - const glm::vec2 getSize() const; + glm::vec2 getSize() const; - const GLuint getSceneSpacePosition () const; - const GLuint getCopySpacePosition () const; - const GLuint getPassSpacePosition () const; - const GLuint getTexCoordCopy () const; - const GLuint getTexCoordPass () const; + GLuint getSceneSpacePosition () const; + GLuint getCopySpacePosition () const; + GLuint getPassSpacePosition () const; + GLuint getTexCoordCopy () const; + GLuint getTexCoordPass () const; const ITexture* getTexture () const; - const double getAnimationTime () const; + double getAnimationTime () const; /** * Performs a ping-pong on the available framebuffers to be able to continue rendering things to them diff --git a/src/WallpaperEngine/Render/Objects/Effects/CMaterial.h b/src/WallpaperEngine/Render/Objects/Effects/CMaterial.h index f7ffeb8..8ccb5e1 100644 --- a/src/WallpaperEngine/Render/Objects/Effects/CMaterial.h +++ b/src/WallpaperEngine/Render/Objects/Effects/CMaterial.h @@ -39,4 +39,4 @@ namespace WallpaperEngine::Render::Objects::Effects std::vector m_passes; }; -}; +} diff --git a/src/WallpaperEngine/Render/Objects/Effects/CPass.cpp b/src/WallpaperEngine/Render/Objects/Effects/CPass.cpp index aca8be0..6435a53 100644 --- a/src/WallpaperEngine/Render/Objects/Effects/CPass.cpp +++ b/src/WallpaperEngine/Render/Objects/Effects/CPass.cpp @@ -50,10 +50,8 @@ const ITexture* CPass::resolveTexture (const ITexture* expected, int index, cons // a bind named "previous" is just another way of telling it to use whatever texture there was already if ((*it).second->getName () == "previous") - if (previous == nullptr) - return expected; - else - return previous; + return previous ?: expected; + // the bind actually has a name, search the FBO in the effect and return it auto fbo = this->m_material->m_effect->findFBO ((*it).second->getName ()); @@ -131,7 +129,7 @@ void CPass::render () glm::vec2 translation = {0.0f, 0.0f}; glm::vec4 rotation = {0.0f, 0.0f, 0.0f, 0.0f}; - if (texture->isAnimated () == true) + if (texture->isAnimated ()) { // calculate current texture and frame double currentRenderTime = fmod (static_cast (g_Time), this->m_material->getImage ()->getAnimationTime ()); @@ -162,7 +160,7 @@ void CPass::render () glBindTexture (GL_TEXTURE_2D, texture->getTextureID (currentTexture)); // continue on the map from the second texture - if (this->m_finalTextures.empty () == false) + if (!this->m_finalTextures.empty ()) { for (const auto& cur : this->m_finalTextures) { @@ -248,13 +246,14 @@ void CPass::render () glBindBuffer (GL_ARRAY_BUFFER, *cur->value); glVertexAttribPointer (cur->id, cur->elements, cur->type, GL_FALSE, 0, nullptr); - if (DEBUG) - glObjectLabel (GL_BUFFER, *cur->value, -1, ( - "Image " + std::to_string (this->getMaterial ()->getImage ()->getId ()) + - " Pass " + this->m_pass->getShader() + - " " + cur->name - ).c_str () - ); +#if DEBUG + glObjectLabel (GL_BUFFER, *cur->value, -1, ( + "Image " + std::to_string (this->getMaterial ()->getImage ()->getId ()) + + " Pass " + this->m_pass->getShader() + + " " + cur->name + ).c_str () + ); +#endif /* DEBUG */ } // start actual rendering now @@ -270,7 +269,7 @@ void CPass::render () glBindTexture (GL_TEXTURE_2D, 0); // continue on the map from the second texture - if (this->m_finalTextures.empty () == false) + if (!this->m_finalTextures.empty ()) { for (const auto& cur : this->m_finalTextures) { @@ -430,12 +429,11 @@ void CPass::setupShaders () sLog.exception (message); } - if (DEBUG) - { - glObjectLabel (GL_PROGRAM, this->m_programID, -1, this->m_pass->getShader ().c_str ()); - glObjectLabel (GL_SHADER, vertexShaderID, -1, (this->m_pass->getShader () + ".vert").c_str ()); - glObjectLabel (GL_SHADER, fragmentShaderID, -1, (this->m_pass->getShader () + ".frag").c_str ()); - } +#if DEBUG + glObjectLabel (GL_PROGRAM, this->m_programID, -1, this->m_pass->getShader ().c_str ()); + glObjectLabel (GL_SHADER, vertexShaderID, -1, (this->m_pass->getShader () + ".vert").c_str ()); + glObjectLabel (GL_SHADER, fragmentShaderID, -1, (this->m_pass->getShader () + ".frag").c_str ()); +#endif /* DEBUG */ // after being liked shaders can be dettached and deleted glDetachShader (this->m_programID, vertexShaderID); @@ -686,7 +684,7 @@ void CPass::setupTextures () } else { - if ((*cur) == "") + if ((*cur).empty()) { this->m_textures.emplace_back (nullptr); } @@ -726,26 +724,26 @@ void CPass::setupShaderVariables () // integers and floats are equivalent, this could be detected at load time // but that'd mean to compile the shader in the load, and not on the render stage // so take into account these conversions here - if (cur.second->is () == true && var->is () == true) + if (cur.second->is () && var->is ()) { // create an integer value from a float this->addUniform (var->getName (), static_cast (*cur.second->as ()->getValue ())); } - else if (cur.second->is () == true && var->is () == true) + else if (cur.second->is () && var->is ()) { // create a float value from an integer this->addUniform (var->getName (), static_cast (*cur.second->as ()->getValue ())); } - else if (cur.second->is () == true && var->is () == true) + else if (cur.second->is () && var->is ()) { - CShaderConstantVector4* val = cur.second->as (); + auto* val = cur.second->as (); // create a new vector2 with the first two values this->addUniform (var->getName (), {val->getValue ()->x, val->getValue ()->y}); } - else if (cur.second->is () == true && var->is () == true) + else if (cur.second->is () && var->is ()) { - CShaderConstantVector4* val = cur.second->as (); + auto* val = cur.second->as (); this->addUniform (var->getName (), {val->getValue ()->x, val->getValue ()->y, val->getValue ()->z}); } diff --git a/src/WallpaperEngine/Render/Shaders/Compiler.cpp b/src/WallpaperEngine/Render/Shaders/Compiler.cpp index 3fee2a8..894a509 100644 --- a/src/WallpaperEngine/Render/Shaders/Compiler.cpp +++ b/src/WallpaperEngine/Render/Shaders/Compiler.cpp @@ -41,8 +41,8 @@ namespace WallpaperEngine::Render::Shaders m_recursive (recursive), m_type (type), m_file (std::move(filename)), - m_error (""), - m_errorInfo (""), + m_error (), + m_errorInfo (), m_constants (constants), m_container (container), m_baseCombos () @@ -91,7 +91,7 @@ namespace WallpaperEngine::Render::Shaders if (*it != ';') { this->m_error = true; - this->m_errorInfo = "Expected semicolon but got " + *it; + this->m_errorInfo = std::string ("Expected semicolon but got ") + *it; return false; } @@ -112,7 +112,7 @@ namespace WallpaperEngine::Render::Shaders void Compiler::ignoreUpToBlockCommentEnd (std::string::const_iterator& it) { - while (it != this->m_content.end() && this->peekString ("*/", it) == false) it ++; + while (it != this->m_content.end() && !this->peekString ("*/", it)) it ++; } std::string Compiler::extractType (std::string::const_iterator& it) @@ -128,10 +128,8 @@ namespace WallpaperEngine::Render::Shaders while (cur != end) { - if (this->peekString (*cur + " ", it) == true) - { + if (this->peekString (*cur + " ", it)) return *cur; - } cur ++; } @@ -147,7 +145,7 @@ namespace WallpaperEngine::Render::Shaders std::string::const_iterator begin = cur; // first character has to be a valid alphabetic characer - if (this->isChar (cur) == false && *cur != '_') + if (!this->isChar (cur) && *cur != '_') { this->m_error = true; this->m_errorInfo = "Expected name doesn't start with a valid character"; @@ -156,11 +154,11 @@ namespace WallpaperEngine::Render::Shaders cur ++; - while (cur != this->m_content.end () && (this->isChar (cur) == true || *cur == '_' || this->isNumeric (cur) == true)) cur ++; + while (cur != this->m_content.end () && (this->isChar (cur) || *cur == '_' || this->isNumeric (cur))) cur ++; it = cur; - return std::string (begin, cur); + return {begin, cur}; } std::string Compiler::extractArray(std::string::const_iterator &it, bool mustExists) @@ -170,7 +168,7 @@ namespace WallpaperEngine::Render::Shaders if (*cur != '[') { - if (mustExists == false) + if (!mustExists) return ""; this->m_error = true; @@ -184,7 +182,7 @@ namespace WallpaperEngine::Render::Shaders it = ++cur; - return std::string (begin, cur); + return {begin, cur}; } bool Compiler::isChar (std::string::const_iterator& it) @@ -204,7 +202,7 @@ namespace WallpaperEngine::Render::Shaders if (*cur != '"') { m_error = true; - m_errorInfo = "Expected opening \" but got " + (*cur); + m_errorInfo = std::string ("Expected opening \" but got ") + (*cur); return ""; } @@ -246,7 +244,7 @@ namespace WallpaperEngine::Render::Shaders void Compiler::precompile() { // TODO: SEPARATE THIS IN TWO SO THE COMBOS ARE DETECTED FIRST AND WE DO NOT REQUIRE DOUBLE COMPILATION OF THE SHADER'S SOURCE - #define BREAK_IF_ERROR if (this->m_error == true) { sLog.exception ("ERROR PRE-COMPILING SHADER.", this->m_errorInfo); } + #define BREAK_IF_ERROR if (this->m_error) { sLog.exception ("ERROR PRE-COMPILING SHADER.", this->m_errorInfo); } // parse the shader and find #includes and such things and translate them to the correct name // also remove any #version definition to prevent errors std::string::const_iterator it = this->m_content.begin (); @@ -259,7 +257,7 @@ namespace WallpaperEngine::Render::Shaders this->m_includesProcessed = false; // search preprocessor macros and parse them - while (it != this->m_content.end () && this->m_error == false) + while (it != this->m_content.end () && !this->m_error) { if (*it == ' ' || *it == '\t' || *it == '\n' || *it == '\r' || *it == '\0' || *it == '{' || *it == '}' || *it == '[' || *it == ']' || *it == '.') { @@ -268,14 +266,12 @@ namespace WallpaperEngine::Render::Shaders } else if (*it == '#') { - if (this->peekString ("#include ", it) == true) + if (this->peekString ("#include ", it)) { - std::string filename = ""; - // ignore whitespaces this->ignoreSpaces (it); BREAK_IF_ERROR // extract value between quotes - filename = this->extractQuotedValue (it); BREAK_IF_ERROR + std::string filename = this->extractQuotedValue (it); BREAK_IF_ERROR if (this->m_recursive) { @@ -301,7 +297,7 @@ namespace WallpaperEngine::Render::Shaders else if (*it == 'u') { // uniforms might have extra information for their values - if (this->peekString ("uniform ", it) == true) + if (this->peekString ("uniform ", it)) { this->ignoreSpaces (it); std::string type = this->extractType (it); BREAK_IF_ERROR @@ -314,7 +310,7 @@ namespace WallpaperEngine::Render::Shaders this->ignoreSpaces (it); // check if there is any actual extra information and parse it - if (this->peekString ("//", it) == true) + if (this->peekString ("//", it)) { this->ignoreSpaces (it); std::string::const_iterator begin = it; @@ -324,11 +320,22 @@ namespace WallpaperEngine::Render::Shaders // parse the parameter information this->parseParameterConfiguration (type, name, configuration); BREAK_IF_ERROR - this->m_compiledContent += "uniform " + type + " " + name + array + "; // " + configuration; + this->m_compiledContent += "uniform "; + this->m_compiledContent += type; + this->m_compiledContent += " "; + this->m_compiledContent += name; + this->m_compiledContent += array; + this->m_compiledContent += "; // "; + this->m_compiledContent += configuration; } else { - this->m_compiledContent += "uniform " + type + " " + name + array + ";"; + this->m_compiledContent += "uniform "; + this->m_compiledContent += type; + this->m_compiledContent += " "; + this->m_compiledContent += name; + this->m_compiledContent += array; + this->m_compiledContent += ";"; } } else @@ -342,7 +349,7 @@ namespace WallpaperEngine::Render::Shaders else if (*it == 'a') { // find attribute definitions - if (this->peekString ("attribute ", it) == true) + if (this->peekString ("attribute ", it)) { this->ignoreSpaces (it); std::string type = this->extractType (it); BREAK_IF_ERROR @@ -361,7 +368,7 @@ namespace WallpaperEngine::Render::Shaders std::string type = this->extractType (it); // types not found, try names - if (this->m_error == false) + if (!this->m_error) { this->ignoreSpaces (it); this->m_compiledContent += type; @@ -371,7 +378,7 @@ namespace WallpaperEngine::Render::Shaders this->m_error = false; std::string name = this->extractName (it); - if (this->m_error == false) + if (!this->m_error) { // check if the name is a translated one or not this->m_compiledContent += name; @@ -387,13 +394,13 @@ namespace WallpaperEngine::Render::Shaders } else if (*it == '/') { - if (this->peekString ("//", it) == true) + if (this->peekString ("//", it)) { std::string::const_iterator begin = it - 2; // is there a COMBO mark to take care of? this->ignoreSpaces (it); - if (this->peekString ("[COMBO]", it) == true) + if (this->peekString ("[COMBO]", it)) { // parse combo json data to define the proper variables this->ignoreSpaces (it); @@ -406,7 +413,7 @@ namespace WallpaperEngine::Render::Shaders this->parseComboConfiguration (configuration, 0); BREAK_IF_ERROR; } - else if (this->peekString ("[COMBO_OFF]", it) == true) + else if (this->peekString ("[COMBO_OFF]", it)) { // parse combo json data to define the proper variables this->ignoreSpaces (it); @@ -426,7 +433,7 @@ namespace WallpaperEngine::Render::Shaders this->m_compiledContent.append (begin, it); } } - else if (this->peekString ("/*", it) == true) + else if (this->peekString ("/*", it)) { std::string::const_iterator begin = it - 2; this->ignoreUpToBlockCommentEnd (it); @@ -444,7 +451,7 @@ namespace WallpaperEngine::Render::Shaders std::string type = this->extractType (it); // type found - if (this->m_error == false) + if (!this->m_error) { this->ignoreSpaces (it); // check for main, and take it into account, this also helps adding the includes @@ -452,9 +459,9 @@ namespace WallpaperEngine::Render::Shaders this->ignoreSpaces (it); - if (this->peekString ("(", it) == true) + if (this->peekString ("(", it)) { - if (this->m_includesProcessed == false) + if (!this->m_includesProcessed) { this->m_compiledContent += "\n\n" + this->m_includesContent + "\n\n"; this->m_includesProcessed = true; @@ -472,7 +479,7 @@ namespace WallpaperEngine::Render::Shaders this->m_error = false; std::string name = this->extractName (it); - if (this->m_error == false) + if (!this->m_error) { // check if the name is a translated one or not this->m_compiledContent += name; @@ -488,7 +495,7 @@ namespace WallpaperEngine::Render::Shaders std::string finalCode; - if (this->m_recursive == false) + if (!this->m_recursive) { // add the opengl compatibility at the top finalCode = "#version 150\n" @@ -548,7 +555,7 @@ namespace WallpaperEngine::Render::Shaders finalCode += this->m_compiledContent; - if (this->m_recursive == false) + if (!this->m_recursive) { sLog.debug("======================== COMPILED ", (this->m_type == Type_Vertex ? "VERTEX" : "FRAGMENT"), " SHADER ", this->m_file, " ========================"); sLog.debug(finalCode); @@ -569,7 +576,7 @@ namespace WallpaperEngine::Render::Shaders this->m_compiledContent += "\n"; // check the combos - std::map::const_iterator entry = this->m_combos->find ((*combo).get ()); + auto entry = this->m_combos->find ((*combo).get ()); // add the combo to the found list this->m_foundCombos->insert_or_assign (*combo, true); @@ -654,9 +661,9 @@ namespace WallpaperEngine::Render::Shaders if (constant == this->m_constants.end ()) value = (*defvalue).get (); - else if ((*constant).second->is () == true) + else if ((*constant).second->is ()) value = *(*constant).second->as ()->getValue (); - else if ((*constant).second->is () == true) + else if ((*constant).second->is ()) value = *(*constant).second->as ()->getValue (); parameter = new Variables::CShaderVariableFloat (value); @@ -667,9 +674,9 @@ namespace WallpaperEngine::Render::Shaders if (constant == this->m_constants.end ()) value = (*defvalue).get (); - else if ((*constant).second->is () == true) + else if ((*constant).second->is ()) value = *(*constant).second->as ()->getValue (); - else if ((*constant).second->is () == true) + else if ((*constant).second->is ()) value = *(*constant).second->as ()->getValue (); parameter = new Variables::CShaderVariableInteger (value); @@ -678,7 +685,6 @@ namespace WallpaperEngine::Render::Shaders { // samplers can have special requirements, check what sampler we're working with and create definitions // if needed - auto combo = data.find ("combo"); auto textureName = data.find ("default"); // extract the texture number from the name char value = name.at (std::string("g_Texture").length ()); @@ -688,7 +694,7 @@ namespace WallpaperEngine::Render::Shaders if (combo != data.end ()) { // if the texture exists (and is not null), add to the combo - if (this->m_passTextures.size () > index && (this->m_passTextures.at (index) != "" || textureName != data.end ())) + if (this->m_passTextures.size () > index && (!this->m_passTextures.at (index).empty() || textureName != data.end ())) { // add the new combo to the list this->m_combos->insert_or_assign (*combo, 1); @@ -697,7 +703,6 @@ namespace WallpaperEngine::Render::Shaders if (this->m_foundCombos->find (*combo) == this->m_foundCombos->end ()) this->m_foundCombos->insert_or_assign (*combo, true); } - } if (textureName != data.end ()) diff --git a/src/WallpaperEngine/Render/Shaders/Compiler.h b/src/WallpaperEngine/Render/Shaders/Compiler.h index 8e3e247..f7061b3 100644 --- a/src/WallpaperEngine/Render/Shaders/Compiler.h +++ b/src/WallpaperEngine/Render/Shaders/Compiler.h @@ -180,11 +180,11 @@ namespace WallpaperEngine::Render::Shaders /** * @return Whether the character in the current position is a character or not */ - bool isChar (std::string::const_iterator& it); + static bool isChar (std::string::const_iterator& it); /** * @return Whether the character in the current position is a number or not */ - bool isNumeric (std::string::const_iterator& it); + static bool isNumeric (std::string::const_iterator& it); /** * Parses a COMBO value to add the proper define to the code * diff --git a/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariable.cpp b/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariable.cpp index e79539c..621accc 100644 --- a/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariable.cpp +++ b/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariable.cpp @@ -45,7 +45,7 @@ void CShaderVariable::setIdentifierName (std::string identifierName) this->m_identifierName = std::move(identifierName); } -void CShaderVariable::setName (std::string name) +void CShaderVariable::setName (const std::string& name) { - this->m_name = std::move(name); + this->m_name = name; } \ No newline at end of file diff --git a/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariable.h b/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariable.h index 89ce20f..241f147 100644 --- a/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariable.h +++ b/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariable.h @@ -19,7 +19,7 @@ namespace WallpaperEngine::Render::Shaders::Variables const std::string& getType () const; void setIdentifierName (std::string identifierName); - void setName (std::string name); + void setName (const std::string& name); const void* getValue () const; virtual const int getSize () const = 0; diff --git a/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableFloat.cpp b/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableFloat.cpp index 87ac724..44cc17d 100644 --- a/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableFloat.cpp +++ b/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableFloat.cpp @@ -11,12 +11,12 @@ CShaderVariableFloat::CShaderVariableFloat(float defaultValue) : { } -CShaderVariableFloat::CShaderVariableFloat(float defaultValue, std::string name) : +CShaderVariableFloat::CShaderVariableFloat(float defaultValue, const std::string& name) : m_defaultValue (defaultValue), m_value (0), CShaderVariable (&this->m_defaultValue, nullptr, Type) { - this->setName (std::move(name)); + this->setName (name); } void CShaderVariableFloat::setValue (float value) diff --git a/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableFloat.h b/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableFloat.h index e025526..df1527b 100644 --- a/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableFloat.h +++ b/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableFloat.h @@ -8,7 +8,7 @@ namespace WallpaperEngine::Render::Shaders::Variables { public: explicit CShaderVariableFloat (float defaultValue); - CShaderVariableFloat (float defaultValue, std::string name); + CShaderVariableFloat (float defaultValue, const std::string& name); const int getSize () const override; diff --git a/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector3.cpp b/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector3.cpp index dbb29c6..05a44a1 100644 --- a/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector3.cpp +++ b/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector3.cpp @@ -9,7 +9,7 @@ CShaderVariableVector3::CShaderVariableVector3 (const glm::vec3& defaultValue) : { } -CShaderVariableVector3::CShaderVariableVector3 (const glm::vec3& defaultValue, std::string name) : +CShaderVariableVector3::CShaderVariableVector3 (const glm::vec3& defaultValue, const std::string& name) : m_defaultValue (defaultValue), m_value (glm::vec3 ()), CShaderVariable (&this->m_defaultValue, nullptr, Type) diff --git a/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector3.h b/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector3.h index c37f71d..762f6b0 100644 --- a/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector3.h +++ b/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector3.h @@ -10,7 +10,7 @@ namespace WallpaperEngine::Render::Shaders::Variables { public: explicit CShaderVariableVector3 (const glm::vec3& defaultValue); - CShaderVariableVector3 (const glm::vec3& defaultValue, std::string name); + CShaderVariableVector3 (const glm::vec3& defaultValue, const std::string& name); const int getSize () const override; diff --git a/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector4.cpp b/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector4.cpp index 142777e..e22890b 100644 --- a/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector4.cpp +++ b/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector4.cpp @@ -11,12 +11,12 @@ CShaderVariableVector4::CShaderVariableVector4 (const glm::vec4& defaultValue) : { } -CShaderVariableVector4::CShaderVariableVector4 (const glm::vec4& defaultValue, std::string name) : +CShaderVariableVector4::CShaderVariableVector4 (const glm::vec4& defaultValue, const std::string& name) : m_defaultValue (defaultValue), m_value (glm::vec4 ()), CShaderVariable (&this->m_defaultValue, nullptr, Type) { - this->setName (std::move(name)); + this->setName (name); } void CShaderVariableVector4::setValue (const glm::vec4& value) diff --git a/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector4.h b/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector4.h index 6bc7dae..80ff958 100644 --- a/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector4.h +++ b/src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector4.h @@ -9,7 +9,7 @@ namespace WallpaperEngine::Render::Shaders::Variables { public: explicit CShaderVariableVector4 (const glm::vec4& defaultValue); - CShaderVariableVector4 (const glm::vec4& defaultValue, std::string name); + CShaderVariableVector4 (const glm::vec4& defaultValue, const std::string& name); const int getSize () const override;