From 36bd8584c4311ec612e78e429464aee38abdc85d Mon Sep 17 00:00:00 2001 From: Maschell Date: Thu, 3 Feb 2022 17:08:07 +0100 Subject: [PATCH] Format the code via clang-format --- .clang-format | 67 +++++++++++++++++++++ .github/workflows/ci.yml | 8 +++ .github/workflows/pr.yml | 8 +++ src/Application.cpp | 37 ++++++------ src/Application.h | 3 +- src/common/common.h | 9 ++- src/entry.cpp | 14 ++--- src/fs/CFile.cpp | 24 ++++---- src/fs/CFile.hpp | 6 +- src/fs/DirList.cpp | 16 ++--- src/fs/DirList.h | 7 ++- src/fs/FSUtils.cpp | 15 +++-- src/game/GameList.cpp | 50 ++++++++-------- src/game/GameList.h | 10 ++-- src/gui/GameIcon.cpp | 74 +++++++++++------------ src/gui/GameIcon.h | 4 +- src/gui/GameIconModel.h | 1 + src/gui/GuiIconGrid.cpp | 103 ++++++++++++++++----------------- src/gui/GuiIconGrid.h | 18 +++--- src/gui/GuiTitleBrowser.h | 2 +- src/menu/GameSplashScreen.cpp | 34 +++++------ src/menu/GameSplashScreen.h | 11 ++-- src/menu/KeyboardHelper.cpp | 10 ++-- src/menu/KeyboardHelper.h | 11 ++-- src/menu/MainDrcButtonsFrame.h | 15 ++--- src/menu/MainWindow.cpp | 68 +++++++++++----------- src/menu/MainWindow.h | 10 ++-- src/resources/Resources.cpp | 34 +++++------ src/resources/Resources.h | 5 +- src/system/CThread.h | 58 +++++++++---------- src/utils/AsyncExecutor.cpp | 2 +- src/utils/AsyncExecutor.h | 12 ++-- src/utils/StringTools.cpp | 24 ++++---- src/utils/StringTools.h | 9 ++- src/utils/logger.h | 15 ++--- src/utils/utils.c | 6 +- src/utils/utils.h | 29 +++++----- 37 files changed, 448 insertions(+), 381 deletions(-) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..56cc685 --- /dev/null +++ b/.clang-format @@ -0,0 +1,67 @@ +# Generated from CLion C/C++ Code Style settings +BasedOnStyle: LLVM +AccessModifierOffset: -4 +AlignAfterOpenBracket: Align +AlignConsecutiveAssignments: Consecutive +AlignConsecutiveMacros: AcrossEmptyLinesAndComments +AlignOperands: Align +AllowAllArgumentsOnNextLine: false +AllowAllConstructorInitializersOnNextLine: false +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortBlocksOnASingleLine: Always +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: All +AllowShortIfStatementsOnASingleLine: Always +AllowShortLambdasOnASingleLine: All +AllowShortLoopsOnASingleLine: true +AlwaysBreakAfterReturnType: None +AlwaysBreakTemplateDeclarations: Yes +BreakBeforeBraces: Custom +BraceWrapping: + AfterCaseLabel: false + AfterClass: false + AfterControlStatement: Never + AfterEnum: false + AfterFunction: false + AfterNamespace: false + AfterUnion: false + BeforeCatch: false + BeforeElse: false + IndentBraces: false + SplitEmptyFunction: false + SplitEmptyRecord: true +BreakBeforeBinaryOperators: None +BreakBeforeTernaryOperators: true +BreakConstructorInitializers: BeforeColon +BreakInheritanceList: BeforeColon +ColumnLimit: 0 +CompactNamespaces: false +ContinuationIndentWidth: 8 +IndentCaseLabels: true +IndentPPDirectives: None +IndentWidth: 4 +KeepEmptyLinesAtTheStartOfBlocks: true +MaxEmptyLinesToKeep: 2 +NamespaceIndentation: All +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PointerAlignment: Right +ReflowComments: false +SpaceAfterCStyleCast: true +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: false +SpaceBeforeAssignmentOperators: true +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatements +SpaceBeforeRangeBasedForLoopColon: true +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: false +SpacesInCStyleCastParentheses: false +SpacesInContainerLiterals: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +TabWidth: 4 +UseTab: Never diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 75e8384..f052ab0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,8 +6,16 @@ on: - master jobs: + clang-format: + runs-on: ubuntu-18.04 + steps: + - uses: actions/checkout@v2 + - name: clang-format + run: | + docker run --rm -v ${PWD}:/src wiiuenv/clang-format:13.0.0-2 -r ./src build-binary: runs-on: ubuntu-18.04 + needs: clang-format steps: - uses: actions/checkout@v2 - name: build binary diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index f907f7e..78d88b5 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -3,8 +3,16 @@ name: CI-PR on: [pull_request] jobs: + clang-format: + runs-on: ubuntu-18.04 + steps: + - uses: actions/checkout@v2 + - name: clang-format + run: | + docker run --rm -v ${PWD}:/src wiiuenv/clang-format:13.0.0-2 -r ./src build-binary: runs-on: ubuntu-18.04 + needs: clang-format steps: - uses: actions/checkout@v2 - name: build binary diff --git a/src/Application.cpp b/src/Application.cpp index 3fd94ac..907df52 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -14,29 +14,29 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . ****************************************************************************/ +#include "Application.h" +#include "common/common.h" +#include "resources/Resources.h" +#include "utils/AsyncExecutor.h" +#include "utils/logger.h" #include #include #include -#include -#include -#include "Application.h" -#include "common/common.h" #include #include #include -#include "resources/Resources.h" -#include #include -#include "utils/logger.h" -#include "utils/AsyncExecutor.h" +#include +#include +#include #include Application *Application::applicationInstance = nullptr; -bool Application::exitApplication = false; -bool Application::quitRequest = false; +bool Application::exitApplication = false; +bool Application::quitRequest = false; Application::Application() - : CThread(CThread::eAttributeAffCore1 | CThread::eAttributePinnedAff, 0, 0x800000), bgMusic(nullptr), video(nullptr), mainWindow(nullptr), fontSystem(nullptr), exitCode(0) { + : CThread(CThread::eAttributeAffCore1 | CThread::eAttributePinnedAff, 0, 0x800000), bgMusic(nullptr), video(nullptr), mainWindow(nullptr), fontSystem(nullptr), exitCode(0) { controller[0] = new VPadController(GuiTrigger::CHANNEL_1); controller[1] = new WPadController(GuiTrigger::CHANNEL_2); controller[2] = new WPadController(GuiTrigger::CHANNEL_3); @@ -62,7 +62,7 @@ Application::~Application() { DEBUG_FUNCTION_LINE("Destroy controller"); - for (auto &i: controller) { + for (auto &i : controller) { delete i; } @@ -88,15 +88,13 @@ int32_t Application::exec() { } void Application::quit(int32_t code) { - exitCode = code; + exitCode = code; exitApplication = true; - quitRequest = true; + quitRequest = true; } void Application::fadeOut() { - GuiImage fadeOut(video->getTvWidth(), video->getTvHeight(), (GX2Color) { - 0, 0, 0, 255 - }); + GuiImage fadeOut(video->getTvWidth(), video->getTvHeight(), (GX2Color){0, 0, 0, 255}); for (int32_t i = 0; i < 255; i += 10) { if (i > 255) @@ -138,7 +136,7 @@ bool Application::procUI() { switch (ProcUIProcessMessages(true)) { case PROCUI_STATUS_EXITING: { DEBUG_FUNCTION_LINE("PROCUI_STATUS_EXITING"); - exitCode = EXIT_SUCCESS; + exitCode = EXIT_SUCCESS; exitApplication = true; break; } @@ -185,7 +183,6 @@ bool Application::procUI() { DEBUG_FUNCTION_LINE("Initialize main window"); mainWindow = new MainWindow(video->getTvWidth(), video->getTvHeight()); } - } executeProcess = true; } @@ -212,7 +209,7 @@ void Application::executeThread() { mainWindow->process(); //! Read out inputs - for (auto &i: controller) { + for (auto &i : controller) { if (!i->update(video->getTvWidth(), video->getTvHeight())) continue; diff --git a/src/Application.h b/src/Application.h index 248e819..e2e587f 100644 --- a/src/Application.h +++ b/src/Application.h @@ -18,8 +18,8 @@ #define _APPLICATION_H #include "menu/MainWindow.h" -#include #include "system/CThread.h" +#include // forward declaration class FreeTypeGX; @@ -77,7 +77,6 @@ private: GuiController *controller[5]{}; int exitCode; BOOL sFromHBL = FALSE; - }; #endif //_APPLICATION_H diff --git a/src/common/common.h b/src/common/common.h index 727b29d..f2171a8 100644 --- a/src/common/common.h +++ b/src/common/common.h @@ -1,16 +1,15 @@ #ifndef COMMON_H -#define COMMON_H +#define COMMON_H #ifdef __cplusplus extern "C" { #endif -#define LAUNCHIINE_VERSION "v0.1" -#define META_PATH "/meta" +#define LAUNCHIINE_VERSION "v0.1" +#define META_PATH "/meta" #ifdef __cplusplus } #endif -#endif /* COMMON_H */ - +#endif /* COMMON_H */ diff --git a/src/entry.cpp b/src/entry.cpp index 07d3650..b0cffbe 100644 --- a/src/entry.cpp +++ b/src/entry.cpp @@ -1,18 +1,18 @@ -#include "common/common.h" -#include -#include -#include -#include "utils/logger.h" #include "Application.h" +#include "common/common.h" +#include "utils/logger.h" +#include +#include +#include int32_t main(int32_t argc, char **argv) { bool moduleInit; bool cafeInit = false; - bool udpInit = false; + bool udpInit = false; if (!(moduleInit = WHBLogModuleInit())) { cafeInit = WHBLogCafeInit(); - udpInit = WHBLogUdpInit(); + udpInit = WHBLogUdpInit(); } DEBUG_FUNCTION_LINE("Starting launchiine " LAUNCHIINE_VERSION ""); diff --git a/src/fs/CFile.cpp b/src/fs/CFile.cpp index fa84541..34796cd 100644 --- a/src/fs/CFile.cpp +++ b/src/fs/CFile.cpp @@ -1,15 +1,15 @@ -#include -#include -#include -#include #include +#include +#include +#include +#include CFile::CFile() { - iFd = -1; + iFd = -1; mem_file = nullptr; filesize = 0; - pos = 0; + pos = 0; } CFile::CFile(const std::string &filepath, eOpenTypes mode) { @@ -35,7 +35,7 @@ int32_t CFile::open(const std::string &filepath, eOpenTypes mode) { switch (mode) { default: - case ReadOnly: // file must exist + case ReadOnly: // file must exist openMode = O_RDONLY; break; case WriteOnly: // file will be created / zerod @@ -77,10 +77,10 @@ void CFile::close() { if (iFd >= 0) ::close(iFd); - iFd = -1; + iFd = -1; mem_file = nullptr; filesize = 0; - pos = 0; + pos = 0; } int32_t CFile::read(uint8_t *ptr, size_t size) { @@ -127,7 +127,7 @@ int32_t CFile::write(const uint8_t *ptr, size_t size) { } int32_t CFile::seek(long int offset, int32_t origin) { - int32_t ret = 0; + int32_t ret = 0; int64_t newPos = pos; if (origin == SEEK_SET) { @@ -158,7 +158,7 @@ int32_t CFile::seek(long int offset, int32_t origin) { int32_t CFile::fwrite(const char *format, ...) { char tmp[512]; - tmp[0] = 0; + tmp[0] = 0; int32_t result = -1; va_list va; @@ -171,5 +171,3 @@ int32_t CFile::fwrite(const char *format, ...) { return result; } - - diff --git a/src/fs/CFile.hpp b/src/fs/CFile.hpp index 6c0421b..2bc9dfc 100644 --- a/src/fs/CFile.hpp +++ b/src/fs/CFile.hpp @@ -1,10 +1,10 @@ #ifndef CFILE_HPP_ #define CFILE_HPP_ -#include -#include -#include #include +#include +#include +#include #include #include diff --git a/src/fs/DirList.cpp b/src/fs/DirList.cpp index d48ce2d..048d120 100644 --- a/src/fs/DirList.cpp +++ b/src/fs/DirList.cpp @@ -24,22 +24,22 @@ * DirList Class * for WiiXplorer 2010 ***************************************************************************/ +#include #include #include #include #include #include -#include -#include #include +#include #include #include DirList::DirList() { - Flags = 0; + Flags = 0; Filter = 0; - Depth = 0; + Depth = 0; } DirList::DirList(const std::string &path, const char *filter, uint32_t flags, uint32_t maxDepth) { @@ -55,9 +55,9 @@ BOOL DirList::LoadPath(const std::string &folder, const char *filter, uint32_t f if (folder.empty()) return false; - Flags = flags; + Flags = flags; Filter = filter; - Depth = maxDepth; + Depth = maxDepth; std::string folderpath(folder); uint32_t length = folderpath.size(); @@ -82,14 +82,14 @@ BOOL DirList::InternalLoadPath(std::string &folderpath) { return false; struct dirent *dirent = nullptr; - DIR *dir = nullptr; + DIR *dir = nullptr; dir = opendir(folderpath.c_str()); if (dir == nullptr) return false; while ((dirent = readdir(dir)) != 0) { - BOOL isDir = dirent->d_type & DT_DIR; + BOOL isDir = dirent->d_type & DT_DIR; const char *filename = dirent->d_name; if (isDir) { diff --git a/src/fs/DirList.h b/src/fs/DirList.h index 8c3eba6..3cc62e1 100644 --- a/src/fs/DirList.h +++ b/src/fs/DirList.h @@ -27,8 +27,8 @@ #ifndef ___DIRLIST_H_ #define ___DIRLIST_H_ -#include #include +#include #include typedef struct { @@ -93,10 +93,11 @@ public: //! Enum for search/filter flags enum { - Files = 0x01, - Dirs = 0x02, + Files = 0x01, + Dirs = 0x02, CheckSubfolders = 0x08, }; + protected: // Internal parser BOOL InternalLoadPath(std::string &path); diff --git a/src/fs/FSUtils.cpp b/src/fs/FSUtils.cpp index e3ddc44..fd799c0 100644 --- a/src/fs/FSUtils.cpp +++ b/src/fs/FSUtils.cpp @@ -1,11 +1,11 @@ -#include -#include -#include -#include -#include #include "fs/FSUtils.h" #include "fs/CFile.hpp" #include "utils/logger.h" +#include +#include +#include +#include +#include int32_t FSUtils::LoadFileToMem(const char *filepath, uint8_t **inbuffer, uint32_t *size) { //! always initialze input @@ -27,8 +27,8 @@ int32_t FSUtils::LoadFileToMem(const char *filepath, uint8_t **inbuffer, uint32_ } uint32_t blocksize = 0x4000; - uint32_t done = 0; - int32_t readBytes = 0; + uint32_t done = 0; + int32_t readBytes = 0; while (done < filesize) { if (done + blocksize > filesize) { @@ -139,4 +139,3 @@ int32_t FSUtils::saveBufferToFile(const char *path, void *buffer, uint32_t size) file.close(); return written; } - diff --git a/src/game/GameList.cpp b/src/game/GameList.cpp index 48ac91d..251482d 100644 --- a/src/game/GameList.cpp +++ b/src/game/GameList.cpp @@ -1,14 +1,14 @@ #include -#include -#include +#include #include #include #include -#include +#include +#include -#include "utils/AsyncExecutor.h" #include "GameList.h" #include "common/common.h" +#include "utils/AsyncExecutor.h" #include "fs/FSUtils.h" #include "utils/logger.h" @@ -24,7 +24,7 @@ GameList::~GameList() { void GameList::clear() { lock(); - for (auto const &x: fullGameList) { + for (auto const &x : fullGameList) { if (x != nullptr) { if (x->imageData != nullptr) { AsyncExecutor::pushForDelete(x->imageData); @@ -55,7 +55,7 @@ gameInfo *GameList::getGameInfo(uint64_t titleId) { int32_t GameList::readGameList() { // Clear list - for (auto const &x: fullGameList) { + for (auto const &x : fullGameList) { delete x; } @@ -92,10 +92,10 @@ int32_t GameList::readGameList() { MCP_APP_TYPE_ACCOUNT_APPS, }; - for (auto appType: menuAppTypes) { + for (auto appType : menuAppTypes) { uint32_t titleCountByType = 0; - MCPError err = MCP_TitleListByAppType(mcp, appType, &titleCountByType, titles.data() + realTitleCount, - (titles.size() - realTitleCount) * sizeof(decltype(titles)::value_type)); + MCPError err = MCP_TitleListByAppType(mcp, appType, &titleCountByType, titles.data() + realTitleCount, + (titles.size() - realTitleCount) * sizeof(decltype(titles)::value_type)); if (err < 0) { MCP_Close(mcp); return 0; @@ -106,12 +106,12 @@ int32_t GameList::readGameList() { titles.resize(realTitleCount); } - for (auto title_candidate: titles) { - auto *newGameInfo = new gameInfo; - newGameInfo->titleId = title_candidate.titleId; - newGameInfo->appType = title_candidate.appType; - newGameInfo->gamePath = title_candidate.path; - newGameInfo->name = ""; + for (auto title_candidate : titles) { + auto *newGameInfo = new gameInfo; + newGameInfo->titleId = title_candidate.titleId; + newGameInfo->appType = title_candidate.appType; + newGameInfo->gamePath = title_candidate.path; + newGameInfo->name = ""; newGameInfo->imageData = nullptr; DCFlushRange(newGameInfo, sizeof(gameInfo)); @@ -141,11 +141,11 @@ int32_t GameList::readGameList() { if (header->imageData == nullptr) { std::string filepath = "fs:" + header->gamePath + META_PATH + "/iconTex.tga"; - uint8_t *buffer = nullptr; - uint32_t bufferSize = 0; - int iResult = FSUtils::LoadFileToMem(filepath.c_str(), &buffer, &bufferSize); + uint8_t *buffer = nullptr; + uint32_t bufferSize = 0; + int iResult = FSUtils::LoadFileToMem(filepath.c_str(), &buffer, &bufferSize); if (iResult > 0) { - auto *imageData = new GuiImageData(buffer, bufferSize, GX2_TEX_CLAMP_MODE_MIRROR); + auto *imageData = new GuiImageData(buffer, bufferSize, GX2_TEX_CLAMP_MODE_MIRROR); header->imageData = imageData; //! free original image buffer which is converted to texture now and not needed anymore @@ -173,7 +173,7 @@ void GameList::updateTitleInfo() { auto acp = ACPGetTitleMetaXml(newHeader->titleId, meta); if (acp >= 0) { newHeader->name = meta->shortname_en; - hasChanged = true; + hasChanged = true; } free(meta); } @@ -181,14 +181,14 @@ void GameList::updateTitleInfo() { if (newHeader->imageData == nullptr) { std::string filepath = "fs:" + newHeader->gamePath + META_PATH + "/iconTex.tga"; - uint8_t *buffer = nullptr; - uint32_t bufferSize = 0; - int iResult = FSUtils::LoadFileToMem(filepath.c_str(), &buffer, &bufferSize); + uint8_t *buffer = nullptr; + uint32_t bufferSize = 0; + int iResult = FSUtils::LoadFileToMem(filepath.c_str(), &buffer, &bufferSize); if (iResult > 0) { - auto *imageData = new GuiImageData(buffer, bufferSize, GX2_TEX_CLAMP_MODE_MIRROR); + auto *imageData = new GuiImageData(buffer, bufferSize, GX2_TEX_CLAMP_MODE_MIRROR); newHeader->imageData = imageData; - hasChanged = true; + hasChanged = true; //! free original image buffer which is converted to texture now and not needed anymore free(buffer); diff --git a/src/game/GameList.h b/src/game/GameList.h index 96921ae..3f1a8ba 100644 --- a/src/game/GameList.h +++ b/src/game/GameList.h @@ -1,13 +1,13 @@ #ifndef GAME_LIST_H_ #define GAME_LIST_H_ -#include +#include +#include +#include +#include #include #include -#include -#include -#include -#include +#include typedef struct _gameInfo { uint64_t titleId; diff --git a/src/gui/GameIcon.cpp b/src/gui/GameIcon.cpp index 7d558c4..6b3572b 100644 --- a/src/gui/GameIcon.cpp +++ b/src/gui/GameIcon.cpp @@ -1,42 +1,42 @@ #include "GameIcon.h" -#include "GameIconModel.h" #include "Application.h" +#include "GameIconModel.h" +#include "utils/logger.h" +#include "utils/utils.h" #include #include #include -#include "utils/utils.h" -#include "utils/logger.h" static const float cfIconMirrorScale = 1.15f; static const float cfIconMirrorAlpha = 0.45f; GameIcon::GameIcon(GuiImageData *preloadImage) - : GuiImage(preloadImage) { - bSelected = false; - bRenderStroke = true; - bRenderReflection = false; - bIconLast = false; - strokeFractalEnable = 1; - strokeBlurBorder = 0.0f; - distanceFadeout = 0.0f; - rotationX = 0.0f; - reflectionAlpha = 0.4f; - strokeWidth = 2.35f; - colorIntensity = glm::vec4(1.0f); - colorIntensityMirror = colorIntensity; - alphaFadeOutNorm = glm::vec4(0.0f); - alphaFadeOutRefl = glm::vec4(-1.0f, 0.0f, 0.9f, 1.0f); + : GuiImage(preloadImage) { + bSelected = false; + bRenderStroke = true; + bRenderReflection = false; + bIconLast = false; + strokeFractalEnable = 1; + strokeBlurBorder = 0.0f; + distanceFadeout = 0.0f; + rotationX = 0.0f; + reflectionAlpha = 0.4f; + strokeWidth = 2.35f; + colorIntensity = glm::vec4(1.0f); + colorIntensityMirror = colorIntensity; + alphaFadeOutNorm = glm::vec4(0.0f); + alphaFadeOutRefl = glm::vec4(-1.0f, 0.0f, 0.9f, 1.0f); selectionBlurOuterColorIntensity = glm::vec4(0.09411764f * 1.15f, 0.56862745f * 1.15f, 0.96862745098f * 1.15f, 1.0f); - selectionBlurOuterSize = 1.65f; - selectionBlurOuterBorderSize = 0.5f; + selectionBlurOuterSize = 1.65f; + selectionBlurOuterBorderSize = 0.5f; selectionBlurInnerColorIntensity = glm::vec4(0.46666667f, 0.90588235f, 1.0f, 1.0f); - selectionBlurInnerSize = 1.45f; - selectionBlurInnerBorderSize = 0.95f; + selectionBlurInnerSize = 1.45f; + selectionBlurInnerBorderSize = 0.95f; vtxCount = sizeof(cfGameIconPosVtxs) / (Shader3D::cuVertexAttrSize); //! texture and vertex coordinates - posVtxs = (float *) memalign(GX2_VERTEX_BUFFER_ALIGNMENT, sizeof(cfGameIconPosVtxs)); + posVtxs = (float *) memalign(GX2_VERTEX_BUFFER_ALIGNMENT, sizeof(cfGameIconPosVtxs)); texCoords = (float *) memalign(GX2_VERTEX_BUFFER_ALIGNMENT, sizeof(cfGameIconTexCoords)); if (posVtxs) { @@ -68,7 +68,7 @@ GameIcon::GameIcon(GuiImageData *preloadImage) strokeTexCoords = (float *) memalign(GX2_VERTEX_BUFFER_ALIGNMENT, cuGameIconStrokeVtxCount * Shader::cuTexCoordAttrSize); if (strokeTexCoords) { for (size_t i = 0, n = 0; i < cuGameIconStrokeVtxCount; n += 2, i += 3) { - strokeTexCoords[n] = (1.0f + strokePosVtxs[i]) * 0.5f; + strokeTexCoords[n] = (1.0f + strokePosVtxs[i]) * 0.5f; strokeTexCoords[n + 1] = 1.0f - (1.0f + strokePosVtxs[i + 1]) * 0.5f; } GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, strokeTexCoords, cuGameIconStrokeVtxCount * Shader::cuTexCoordAttrSize); @@ -118,9 +118,9 @@ bool GameIcon::checkRayIntersection(const glm::vec3 &rayOrigin, const glm::vec3 //! since we always face the camera we can just check the AABB intersection //! otherwise an OOB intersection would be required - float currPosX = getCenterX() * Application::instance()->getVideo()->getWidthScaleFactor() * 2.0f; - float currPosY = getCenterY() * Application::instance()->getVideo()->getHeightScaleFactor() * 2.0f; - float currPosZ = getDepth() * Application::instance()->getVideo()->getDepthScaleFactor() * 2.0f; + float currPosX = getCenterX() * Application::instance()->getVideo()->getWidthScaleFactor() * 2.0f; + float currPosY = getCenterY() * Application::instance()->getVideo()->getHeightScaleFactor() * 2.0f; + float currPosZ = getDepth() * Application::instance()->getVideo()->getDepthScaleFactor() * 2.0f; float currScaleX = getScaleX() * (float) getWidth() * Application::instance()->getVideo()->getWidthScaleFactor(); float currScaleY = getScaleY() * (float) getHeight() * Application::instance()->getVideo()->getHeightScaleFactor(); float currScaleZ = getScaleZ() * (float) getWidth() * Application::instance()->getVideo()->getDepthScaleFactor(); @@ -159,12 +159,12 @@ void GameIcon::draw(CVideo *pVideo, const glm::mat4 &projectionMtx, const glm::m return; } //! first setup 2D GUI positions - float currPosX = getCenterX() * pVideo->getWidthScaleFactor() * 2.0f; - float currPosY = getCenterY() * pVideo->getHeightScaleFactor() * 2.0f; - float currPosZ = getDepth() * pVideo->getDepthScaleFactor() * 2.0f; - float currScaleX = getScaleX() * (float) getWidth() * pVideo->getWidthScaleFactor(); - float currScaleY = getScaleY() * (float) getHeight() * pVideo->getHeightScaleFactor(); - float currScaleZ = getScaleZ() * (float) getWidth() * pVideo->getDepthScaleFactor(); + float currPosX = getCenterX() * pVideo->getWidthScaleFactor() * 2.0f; + float currPosY = getCenterY() * pVideo->getHeightScaleFactor() * 2.0f; + float currPosZ = getDepth() * pVideo->getDepthScaleFactor() * 2.0f; + float currScaleX = getScaleX() * (float) getWidth() * pVideo->getWidthScaleFactor(); + float currScaleY = getScaleY() * (float) getHeight() * pVideo->getHeightScaleFactor(); + float currScaleZ = getScaleZ() * (float) getWidth() * pVideo->getDepthScaleFactor(); float strokeScaleX = pVideo->getWidthScaleFactor() * strokeWidth * 0.25f + cfIconMirrorScale; float strokeScaleY = pVideo->getHeightScaleFactor() * strokeWidth * 0.25f + cfIconMirrorScale; @@ -182,10 +182,10 @@ void GameIcon::draw(CVideo *pVideo, const glm::mat4 &projectionMtx, const glm::m m_iconView = glm::rotate(m_iconView, DegToRad(rotationX), glm::vec3(1.0f, 0.0f, 0.0f)); m_iconView = glm::scale(m_iconView, glm::vec3(currScaleX, -currScaleY, currScaleZ)); - colorIntensity[3] = reflectionAlpha * getAlpha(); + colorIntensity[3] = reflectionAlpha * getAlpha(); selectionBlurOuterColorIntensity[3] = colorIntensity[3] * 0.7f; selectionBlurInnerColorIntensity[3] = colorIntensity[3] * 0.7f; - alphaFadeOut = &alphaFadeOutRefl; + alphaFadeOut = &alphaFadeOutRefl; GX2SetCullOnlyControl(GX2_FRONT_FACE_CCW, GX2_ENABLE, GX2_DISABLE); } else { @@ -194,10 +194,10 @@ void GameIcon::draw(CVideo *pVideo, const glm::mat4 &projectionMtx, const glm::m m_iconView = glm::rotate(m_iconView, DegToRad(rotationX), glm::vec3(1.0f, 0.0f, 0.0f)); m_iconView = glm::scale(m_iconView, glm::vec3(currScaleX, currScaleY, currScaleZ)); - colorIntensity[3] = getAlpha(); + colorIntensity[3] = getAlpha(); selectionBlurOuterColorIntensity[3] = colorIntensity[3]; selectionBlurInnerColorIntensity[3] = colorIntensity[3]; - alphaFadeOut = &alphaFadeOutNorm; + alphaFadeOut = &alphaFadeOutNorm; } m_mirrorView = glm::scale(m_iconView, glm::vec3(cfIconMirrorScale, cfIconMirrorScale, cfIconMirrorScale)); diff --git a/src/gui/GameIcon.h b/src/gui/GameIcon.h index 02ba2af..999f758 100644 --- a/src/gui/GameIcon.h +++ b/src/gui/GameIcon.h @@ -15,8 +15,8 @@ public: } void setColorIntensity(const glm::vec4 &color) { - colorIntensity = color; - colorIntensityMirror = colorIntensity; + colorIntensity = color; + colorIntensityMirror = colorIntensity; selectionBlurOuterColorIntensity = color * glm::vec4(0.09411764f * 1.15f, 0.56862745f * 1.15f, 0.96862745098f * 1.15f, 1.0f); selectionBlurInnerColorIntensity = color * glm::vec4(0.46666667f, 0.90588235f, 1.0f, 1.0f); } diff --git a/src/gui/GameIconModel.h b/src/gui/GameIconModel.h index f408409..92a0ac1 100644 --- a/src/gui/GameIconModel.h +++ b/src/gui/GameIconModel.h @@ -1,6 +1,7 @@ #ifndef ICON_MODEL_H_ #define ICON_MODEL_H_ +// clang-format off static const float cfGameIconPosVtxs[] = { -0.844501f, -0.861263f, 0.050154f, -0.802664f, -0.8797f, 0.054004f, -0.809968f, -0.828995f, 0.061777f, -0.864233f, -0.822169f, 0.054004f, -0.802664f, -0.8797f, 0.054004f, -0.726455f, -0.89991f, 0.058224f, -0.730326f, -0.842312f, 0.067487f, -0.809968f, -0.828995f, 0.061777f, diff --git a/src/gui/GuiIconGrid.cpp b/src/gui/GuiIconGrid.cpp index e76c3ac..4f89ac4 100644 --- a/src/gui/GuiIconGrid.cpp +++ b/src/gui/GuiIconGrid.cpp @@ -14,37 +14,37 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . ****************************************************************************/ -#include -#include -#include -#include -#include -#include "common/common.h" #include "Application.h" -#include -#include "utils/logger.h" +#include "common/common.h" #include "gui/GameIcon.h" +#include "utils/logger.h" +#include +#include +#include +#include +#include +#include GuiIconGrid::GuiIconGrid(int32_t w, int32_t h, uint64_t GameIndex, bool sortByName) - : GuiTitleBrowser(w, h, GameIndex), - sortByName(sortByName), - particleBgImage(w, h, 50, 60.0f, 90.0f, 0.6f, 1.0f), buttonClickSound(Resources::GetSound("button_click.mp3")), gameTitle((char *) nullptr, 52, glm::vec4(1.0f)), - touchTrigger(GuiTrigger::CHANNEL_1, GuiTrigger::VPAD_TOUCH), - wpadTouchTrigger(GuiTrigger::CHANNEL_2 | GuiTrigger::CHANNEL_3 | GuiTrigger::CHANNEL_4 | GuiTrigger::CHANNEL_5, GuiTrigger::BUTTON_A), - leftTrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_LEFT | GuiTrigger::STICK_L_LEFT, true), - rightTrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_RIGHT | GuiTrigger::STICK_L_RIGHT, true), - downTrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_DOWN | GuiTrigger::STICK_L_DOWN, true), upTrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_UP | GuiTrigger::STICK_L_UP, true), - buttonATrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_A, true), buttonLTrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_L, true), - buttonRTrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_R, true), leftButton(w, h), rightButton(w, h), downButton(w, h), upButton(w, h), launchButton(w, h), - arrowRightImageData(Resources::GetImageData("rightArrow.png")), arrowLeftImageData(Resources::GetImageData("leftArrow.png")), arrowRightImage(arrowRightImageData), - arrowLeftImage(arrowLeftImageData), arrowRightButton(arrowRightImage.getWidth(), arrowRightImage.getHeight()), arrowLeftButton(arrowLeftImage.getWidth(), arrowLeftImage.getHeight()), - noIcon(Resources::GetFile("noGameIcon.png"), Resources::GetFileSize("noGameIcon.png"), GX2_TEX_CLAMP_MODE_MIRROR), - emptyIcon(Resources::GetFile("iconEmpty.png"), Resources::GetFileSize("iconEmpty.png"), GX2_TEX_CLAMP_MODE_MIRROR), dragListener(w, h) { + : GuiTitleBrowser(w, h, GameIndex), + sortByName(sortByName), + particleBgImage(w, h, 50, 60.0f, 90.0f, 0.6f, 1.0f), buttonClickSound(Resources::GetSound("button_click.mp3")), gameTitle((char *) nullptr, 52, glm::vec4(1.0f)), + touchTrigger(GuiTrigger::CHANNEL_1, GuiTrigger::VPAD_TOUCH), + wpadTouchTrigger(GuiTrigger::CHANNEL_2 | GuiTrigger::CHANNEL_3 | GuiTrigger::CHANNEL_4 | GuiTrigger::CHANNEL_5, GuiTrigger::BUTTON_A), + leftTrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_LEFT | GuiTrigger::STICK_L_LEFT, true), + rightTrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_RIGHT | GuiTrigger::STICK_L_RIGHT, true), + downTrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_DOWN | GuiTrigger::STICK_L_DOWN, true), upTrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_UP | GuiTrigger::STICK_L_UP, true), + buttonATrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_A, true), buttonLTrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_L, true), + buttonRTrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_R, true), leftButton(w, h), rightButton(w, h), downButton(w, h), upButton(w, h), launchButton(w, h), + arrowRightImageData(Resources::GetImageData("rightArrow.png")), arrowLeftImageData(Resources::GetImageData("leftArrow.png")), arrowRightImage(arrowRightImageData), + arrowLeftImage(arrowLeftImageData), arrowRightButton(arrowRightImage.getWidth(), arrowRightImage.getHeight()), arrowLeftButton(arrowLeftImage.getWidth(), arrowLeftImage.getHeight()), + noIcon(Resources::GetFile("noGameIcon.png"), Resources::GetFileSize("noGameIcon.png"), GX2_TEX_CLAMP_MODE_MIRROR), + emptyIcon(Resources::GetFile("iconEmpty.png"), Resources::GetFileSize("iconEmpty.png"), GX2_TEX_CLAMP_MODE_MIRROR), dragListener(w, h) { particleBgImage.setParent(this); setSelectedGame(GameIndex); - listOffset = selectedGame / (MAX_COLS * MAX_ROWS); - targetLeftPosition = -listOffset * getWidth(); + listOffset = selectedGame / (MAX_COLS * MAX_ROWS); + targetLeftPosition = -listOffset * getWidth(); currentLeftPosition = targetLeftPosition; leftButton.setTrigger(&leftTrigger); @@ -126,18 +126,18 @@ GuiIconGrid::GuiIconGrid(int32_t w, int32_t h, uint64_t GameIndex, bool sortByNa GuiIconGrid::~GuiIconGrid() { containerMutex.lock(); - for (auto const &x: gameInfoContainers) { + for (auto const &x : gameInfoContainers) { remove(x.second->button); delete x.second; } gameInfoContainers.clear(); containerMutex.unlock(); - for (auto const &x: emptyButtons) { + for (auto const &x : emptyButtons) { delete x; } - for (auto const &x: emptyIcons) { + for (auto const &x : emptyIcons) { delete x; } @@ -163,7 +163,7 @@ void GuiIconGrid::setSelectedGame(uint64_t idx) { containerMutex.lock(); GameInfoContainer *container = nullptr; - for (auto const &x: gameInfoContainers) { + for (auto const &x : gameInfoContainers) { container = x.second; if (x.first == idx) { container->image->setSelected(true); @@ -178,7 +178,7 @@ void GuiIconGrid::setSelectedGame(uint64_t idx) { if (offset > 0) { uint32_t newPage = offset / (MAX_COLS * MAX_ROWS); if (newPage != (uint32_t) curPage) { - curPage = newPage; + curPage = newPage; bUpdatePositions = true; } } @@ -215,10 +215,10 @@ void GuiIconGrid::OnGameTitleListUpdated(GameList *gameList) { } for (int32_t i = 0; i < gameList->size(); i++) { - gameInfo *info = gameList->at(i); + gameInfo *info = gameList->at(i); GameInfoContainer *container = nullptr; - for (auto const &x: gameInfoContainers) { + for (auto const &x : gameInfoContainers) { if (info->titleId == x.first) { container = x.second; break; @@ -233,9 +233,9 @@ void GuiIconGrid::OnGameTitleListUpdated(GameList *gameList) { gameList->unlock(); setSelectedGame(0); gameSelectionChanged(this, selectedGame); - curPage = 0; + curPage = 0; currentLeftPosition = 0; - bUpdatePositions = true; + bUpdatePositions = true; } void GuiIconGrid::OnLeftArrowClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger) { @@ -268,7 +268,6 @@ void GuiIconGrid::OnLeftClick(GuiButton *button, const GuiController *controller setSelectedGame(newTitleId); gameSelectionChanged(this, selectedGame); } - } void GuiIconGrid::OnRightClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger) { @@ -379,7 +378,7 @@ void GuiIconGrid::OnGameButtonHeld(GuiButton *button, const GuiController *contr if (currentlyHeld == nullptr) { bool found = false; // We don't want to drag empty buttons - for (auto const &x: emptyButtons) { + for (auto const &x : emptyButtons) { if (x == button) { found = true; break; @@ -395,11 +394,9 @@ void GuiIconGrid::OnGameButtonHeld(GuiButton *button, const GuiController *contr } void GuiIconGrid::OnGameButtonPointedOn(GuiButton *button, const GuiController *controller) { - } void GuiIconGrid::OnGameButtonPointedOff(GuiButton *button, const GuiController *controller) { - } void GuiIconGrid::OnDrag(GuiDragListener *element, const GuiController *controller, GuiTrigger *trigger, int32_t dx, int32_t dy) { @@ -412,7 +409,7 @@ void GuiIconGrid::OnDrag(GuiDragListener *element, const GuiController *controll void GuiIconGrid::OnGameButtonClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger) { containerMutex.lock(); - for (auto const &x: gameInfoContainers) { + for (auto const &x : gameInfoContainers) { if (x.second->button == button) { if (selectedGame == (x.second->info->titleId)) { if (gameLaunchTimer < 30) @@ -466,7 +463,7 @@ void GuiIconGrid::OnGameTitleAdded(gameInfo *info) { bool foundFreePlace = false; for (uint32_t i = 0; i < position.size(); i++) { if (position[i] == 0) { - position[i] = info->titleId; + position[i] = info->titleId; foundFreePlace = true; break; } @@ -483,7 +480,7 @@ void GuiIconGrid::OnGameTitleUpdated(gameInfo *info) { DEBUG_FUNCTION_LINE("Updating infos of %016llX", info->titleId); GameInfoContainer *container = nullptr; containerMutex.lock(); - for (auto const &x: gameInfoContainers) { + for (auto const &x : gameInfoContainers) { if (info->titleId == x.first) { container = x.second; break; @@ -514,7 +511,7 @@ void GuiIconGrid::process() { std::copy(gameInfoContainers.begin(), gameInfoContainers.end(), std::back_inserter>>(vec)); containerMutex.unlock(); uint64_t targetTitleId = 0; - for (auto const &x: vec) { + for (auto const &x : vec) { if (x.second->button == dragTarget) { targetTitleId = x.first; break; @@ -543,11 +540,11 @@ void GuiIconGrid::process() { } } positionMutex.unlock(); - currentlyHeld = nullptr; + currentlyHeld = nullptr; currentlyHeldTitleId = 0; currentlyHeldPosition = -1; - bUpdatePositions = true; + bUpdatePositions = true; } else { //DEBUG_FUNCTION_LINE("Holding it"); bUpdatePositions = true; @@ -602,14 +599,14 @@ void GuiIconGrid::updateButtonPositions() { containerMutex.unlock(); - for (auto const &x: vec) { + for (auto const &x : vec) { if (x.second->button == currentlyHeld) { currentlyHeldTitleId = x.first; } remove(x.second->button); } - for (auto const &x: emptyButtons) { + for (auto const &x : emptyButtons) { remove(x); } @@ -629,12 +626,12 @@ void GuiIconGrid::updateButtonPositions() { for (uint32_t i = 0; i < position.size(); i++) { if (position[i] == currentlyHeldTitleId) { currentlyHeldPosition = i; - position[i] = 0; + position[i] = 0; } } uint32_t elementSize = position.size(); - uint32_t pages = (elementSize / (MAX_COLS * MAX_ROWS)) + 1; + uint32_t pages = (elementSize / (MAX_COLS * MAX_ROWS)) + 1; if (elementSize % (MAX_COLS * MAX_ROWS) == 0) { pages--; } @@ -662,10 +659,10 @@ void GuiIconGrid::updateButtonPositions() { } uint32_t startPage = -(currentLeftPosition / getWidth()); - uint32_t endPage = startPage; + uint32_t endPage = startPage; if (targetLeftPosition != currentLeftPosition) { - for (auto const &x: vec) { + for (auto const &x : vec) { x.second->button->setHoldable(false); } endPage++; @@ -673,7 +670,7 @@ void GuiIconGrid::updateButtonPositions() { endPage = pages; } } else { - for (auto const &x: vec) { + for (auto const &x : vec) { x.second->button->setHoldable(true); } } @@ -685,10 +682,10 @@ void GuiIconGrid::updateButtonPositions() { } for (uint32_t i = startPage * (MAX_COLS * MAX_ROWS); i < (endPage + 1) * (MAX_COLS * MAX_ROWS); i++) { - listOff = i / (MAX_COLS * MAX_ROWS); + listOff = i / (MAX_COLS * MAX_ROWS); GuiButton *element = nullptr; - float posX = currentLeftPosition + listOff * width + (col * (noIcon.getWidth() + noIcon.getWidth() * 0.5f) - (MAX_COLS * 0.5f - 0.5f) * (noIcon.getWidth() + noIcon.getWidth() * 0.5f)); - float posY = -row * (noIcon.getHeight() + noIcon.getHeight() * 0.5f) + (MAX_ROWS * 0.5f - 0.5f) * (noIcon.getHeight() + noIcon.getHeight() * 0.5f) + 30.0f; + float posX = currentLeftPosition + listOff * width + (col * (noIcon.getWidth() + noIcon.getWidth() * 0.5f) - (MAX_COLS * 0.5f - 0.5f) * (noIcon.getWidth() + noIcon.getWidth() * 0.5f)); + float posY = -row * (noIcon.getHeight() + noIcon.getHeight() * 0.5f) + (MAX_ROWS * 0.5f - 0.5f) * (noIcon.getHeight() + noIcon.getHeight() * 0.5f) + 30.0f; if (i < position.size()) { uint64_t titleID = position.at(i); diff --git a/src/gui/GuiIconGrid.h b/src/gui/GuiIconGrid.h index dacb807..93b9f62 100644 --- a/src/gui/GuiIconGrid.h +++ b/src/gui/GuiIconGrid.h @@ -16,13 +16,13 @@ ****************************************************************************/ #pragma once -#include -#include "gui/GuiTitleBrowser.h" #include "gui/GameIcon.h" #include "gui/GuiDragListener.h" -#include +#include "gui/GuiTitleBrowser.h" #include "utils/AsyncExecutor.h" #include "utils/logger.h" +#include +#include class GuiIconGrid : public GuiTitleBrowser, public sigslot::has_slots<> { public: @@ -131,17 +131,17 @@ private: int32_t currentLeftPosition; int32_t targetLeftPosition; uint32_t gameLaunchTimer; - bool bUpdatePositions = false; - GuiButton *currentlyHeld = nullptr; + bool bUpdatePositions = false; + GuiButton *currentlyHeld = nullptr; uint64_t currentlyHeldTitleId = 0; int32_t currentlyHeldPosition = -1; - GuiButton *dragTarget = nullptr; + GuiButton *dragTarget = nullptr; class GameInfoContainer { public: GameInfoContainer(GuiButton *button, GameIcon *image, gameInfo *info) { - this->image = image; - this->info = info; + this->image = image; + this->info = info; this->button = button; } @@ -173,6 +173,4 @@ private: std::vector emptyIcons; std::vector emptyButtons; - - }; diff --git a/src/gui/GuiTitleBrowser.h b/src/gui/GuiTitleBrowser.h index d7f5dd7..c6fd6ce 100644 --- a/src/gui/GuiTitleBrowser.h +++ b/src/gui/GuiTitleBrowser.h @@ -1,8 +1,8 @@ #pragma once +#include "game/GameList.h" #include #include -#include "game/GameList.h" class GuiTitleBrowser : public GuiFrame { public: diff --git a/src/menu/GameSplashScreen.cpp b/src/menu/GameSplashScreen.cpp index 2c0cce2..ccb3f84 100644 --- a/src/menu/GameSplashScreen.cpp +++ b/src/menu/GameSplashScreen.cpp @@ -1,25 +1,23 @@ #include "GameSplashScreen.h" -#include "utils/logger.h" #include "common/common.h" #include "fs/FSUtils.h" #include "utils/AsyncExecutor.h" +#include "utils/logger.h" GameSplashScreen::GameSplashScreen(int32_t w, int32_t h, gameInfo *info, bool onTV) : GuiFrame(w, h), - bgImageColor(w, h, (GX2Color) { - 0, 0, 0, 0 - }) { - bgImageColor.setImageColor((GX2Color) { - 79, 153, 239, 255 - }, 0); - bgImageColor.setImageColor((GX2Color) { - 79, 153, 239, 255 - }, 1); - bgImageColor.setImageColor((GX2Color) { - 59, 159, 223, 255 - }, 2); - bgImageColor.setImageColor((GX2Color) { - 59, 159, 223, 255 - }, 3); + bgImageColor(w, h, (GX2Color){0, 0, 0, 0}) { + bgImageColor.setImageColor((GX2Color){ + 79, 153, 239, 255}, + 0); + bgImageColor.setImageColor((GX2Color){ + 79, 153, 239, 255}, + 1); + bgImageColor.setImageColor((GX2Color){ + 59, 159, 223, 255}, + 2); + bgImageColor.setImageColor((GX2Color){ + 59, 159, 223, 255}, + 3); append(&bgImageColor); this->onTV = onTV; this->info = info; @@ -28,9 +26,9 @@ GameSplashScreen::GameSplashScreen(int32_t w, int32_t h, gameInfo *info, bool on if (onTV) { filepath = "fs:" + info->gamePath + META_PATH + "/bootTVTex.tga"; } - uint8_t *buffer = nullptr; + uint8_t *buffer = nullptr; uint32_t bufferSize = 0; - int iResult = FSUtils::LoadFileToMem(filepath.c_str(), &buffer, &bufferSize); + int iResult = FSUtils::LoadFileToMem(filepath.c_str(), &buffer, &bufferSize); if (iResult > 0) { splashScreenData = new GuiImageData(buffer, bufferSize, GX2_TEX_CLAMP_MODE_MIRROR); if (splashScreenData) { diff --git a/src/menu/GameSplashScreen.h b/src/menu/GameSplashScreen.h index 9d002a9..53cc338 100644 --- a/src/menu/GameSplashScreen.h +++ b/src/menu/GameSplashScreen.h @@ -1,8 +1,8 @@ #pragma once #include "game/GameList.h" -#include #include +#include class GameSplashScreen : public GuiFrame, public sigslot::has_slots<> { public: @@ -15,11 +15,12 @@ public: virtual void draw(CVideo *v); sigslot::signal3 gameGameSplashScreenFinished; + private: GuiImage bgImageColor; GuiImageData *splashScreenData = nullptr; - gameInfo *info = nullptr; - bool launchGame = false; - uint32_t frameCounter = 0; - bool onTV = false; + gameInfo *info = nullptr; + bool launchGame = false; + uint32_t frameCounter = 0; + bool onTV = false; }; diff --git a/src/menu/KeyboardHelper.cpp b/src/menu/KeyboardHelper.cpp index 8874f9e..2fe8e53 100644 --- a/src/menu/KeyboardHelper.cpp +++ b/src/menu/KeyboardHelper.cpp @@ -1,7 +1,7 @@ -#include #include "KeyboardHelper.h" #include "utils/logger.h" #include +#include KeyboardHelper::KeyboardHelper() { auto *_fsClient = (FSClient *) MEMAllocFromDefaultHeap(sizeof(FSClient)); @@ -12,9 +12,9 @@ KeyboardHelper::KeyboardHelper() { createArg.regionType = nn::swkbd::RegionType::Europe; createArg.workMemory = MEMAllocFromDefaultHeap(nn::swkbd::GetWorkMemorySize(0)); memset(createArg.workMemory, 0, sizeof(nn::swkbd::GetWorkMemorySize(0))); - this->workMemory = createArg.workMemory; + this->workMemory = createArg.workMemory; createArg.fsClient = _fsClient; - this->fsClient = createArg.fsClient; + this->fsClient = createArg.fsClient; DEBUG_FUNCTION_LINE("Calling create"); if (!nn::swkbd::Create(createArg)) { DEBUG_FUNCTION_LINE("Failed to create keyboard"); @@ -64,7 +64,7 @@ bool KeyboardHelper::checkResult() { } // Update keyboard nn::swkbd::ControllerInfo controllerInfo; - controllerInfo.vpad = &vpadStatus; + controllerInfo.vpad = &vpadStatus; controllerInfo.kpad[0] = nullptr; controllerInfo.kpad[1] = nullptr; controllerInfo.kpad[2] = nullptr; @@ -98,7 +98,7 @@ bool KeyboardHelper::checkResult() { } } this->resultStr = logStr; - keyboardOpen = false; + keyboardOpen = false; nn::swkbd::DisappearInputForm(); return true; } diff --git a/src/menu/KeyboardHelper.h b/src/menu/KeyboardHelper.h index 8777015..0a99eb0 100644 --- a/src/menu/KeyboardHelper.h +++ b/src/menu/KeyboardHelper.h @@ -1,7 +1,7 @@ #pragma once -#include #include +#include class KeyboardHelper { public: @@ -24,10 +24,9 @@ public: std::string getResult(); private: - - void *workMemory = nullptr; - FSClient *fsClient = nullptr; - bool keyboardOpen = false; - bool keyboardCreated = false; + void *workMemory = nullptr; + FSClient *fsClient = nullptr; + bool keyboardOpen = false; + bool keyboardCreated = false; std::string resultStr = ""; }; diff --git a/src/menu/MainDrcButtonsFrame.h b/src/menu/MainDrcButtonsFrame.h index a47c0f4..7ec12c6 100644 --- a/src/menu/MainDrcButtonsFrame.h +++ b/src/menu/MainDrcButtonsFrame.h @@ -23,13 +23,13 @@ class MainDrcButtonsFrame : public GuiFrame, public sigslot::has_slots<> { public: MainDrcButtonsFrame(int32_t w, int32_t h) - : GuiFrame(w, h), buttonClickSound(Resources::GetSound("settings_click_2.mp3")), screenSwitchSound(Resources::GetSound("screenSwitchSound.mp3")), - switchIconData(Resources::GetImageData("layoutSwitchButton.png")), settingsIconData(Resources::GetImageData("settingsButton.png")), switchIcon(switchIconData), - settingsIcon(settingsIconData), switchLayoutButton(switchIcon.getWidth(), switchIcon.getHeight()), settingsButton(settingsIcon.getWidth(), settingsIcon.getHeight()), - gameListFilterButton(w, h), touchTrigger(GuiTrigger::CHANNEL_1, GuiTrigger::VPAD_TOUCH), - wpadTouchTrigger(GuiTrigger::CHANNEL_2 | GuiTrigger::CHANNEL_3 | GuiTrigger::CHANNEL_4 | GuiTrigger::CHANNEL_5, GuiTrigger::BUTTON_A), - settingsTrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_ZL, true), switchLayoutTrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_ZR, true), - plusTrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_PLUS, true) { + : GuiFrame(w, h), buttonClickSound(Resources::GetSound("settings_click_2.mp3")), screenSwitchSound(Resources::GetSound("screenSwitchSound.mp3")), + switchIconData(Resources::GetImageData("layoutSwitchButton.png")), settingsIconData(Resources::GetImageData("settingsButton.png")), switchIcon(switchIconData), + settingsIcon(settingsIconData), switchLayoutButton(switchIcon.getWidth(), switchIcon.getHeight()), settingsButton(settingsIcon.getWidth(), settingsIcon.getHeight()), + gameListFilterButton(w, h), touchTrigger(GuiTrigger::CHANNEL_1, GuiTrigger::VPAD_TOUCH), + wpadTouchTrigger(GuiTrigger::CHANNEL_2 | GuiTrigger::CHANNEL_3 | GuiTrigger::CHANNEL_4 | GuiTrigger::CHANNEL_5, GuiTrigger::BUTTON_A), + settingsTrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_ZL, true), switchLayoutTrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_ZR, true), + plusTrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_PLUS, true) { settingsButton.setClickable(true); settingsButton.setImage(&settingsIcon); settingsButton.setTrigger(&touchTrigger); @@ -69,6 +69,7 @@ public: sigslot::signal1 settingsButtonClicked; sigslot::signal1 layoutSwitchClicked; sigslot::signal1 gameListFilterClicked; + private: void OnSettingsButtonClick(GuiButton *button, const GuiController *controller, GuiTrigger *) { settingsButtonClicked(this); diff --git a/src/menu/MainWindow.cpp b/src/menu/MainWindow.cpp index b6ee9df..33d3a01 100644 --- a/src/menu/MainWindow.cpp +++ b/src/menu/MainWindow.cpp @@ -16,25 +16,25 @@ ****************************************************************************/ #include "MainWindow.h" #include "Application.h" -#include "utils/logger.h" #include "utils/StringTools.h" +#include "utils/logger.h" -#include "resources/Resources.h" -#include "gui/GuiTitleBrowser.h" -#include "gui/GuiIconGrid.h" -#include -#include -#include -#include -#include "utils/AsyncExecutor.h" #include "GameSplashScreen.h" +#include "gui/GuiIconGrid.h" +#include "gui/GuiTitleBrowser.h" +#include "resources/Resources.h" +#include "utils/AsyncExecutor.h" +#include +#include +#include +#include MainWindow::MainWindow(int32_t w, int32_t h) - : width(w), height(h), gameClickSound(Resources::GetSound("game_click.mp3")), mainSwitchButtonFrame(nullptr), currentTvFrame(nullptr), currentDrcFrame(nullptr) { + : width(w), height(h), gameClickSound(Resources::GetSound("game_click.mp3")), mainSwitchButtonFrame(nullptr), currentTvFrame(nullptr), currentDrcFrame(nullptr) { for (int32_t i = 0; i < 4; i++) { std::string filename = StringTools::strfmt("player%i_point.png", i + 1); - pointerImgData[i] = Resources::GetImageData(filename.c_str()); - pointerImg[i] = new GuiImage(pointerImgData[i]); + pointerImgData[i] = Resources::GetImageData(filename.c_str()); + pointerImg[i] = new GuiImage(pointerImgData[i]); pointerImg[i]->setScale(1.5f); pointerValid[i] = false; } @@ -43,7 +43,6 @@ MainWindow::MainWindow(int32_t w, int32_t h) gameList.titleUpdated.connect(this, &MainWindow::OnGameTitleUpdated); gameList.titleAdded.connect(this, &MainWindow::OnGameTitleAdded); AsyncExecutor::execute([&] { gameList.load(); }); - } MainWindow::~MainWindow() { @@ -68,7 +67,7 @@ MainWindow::~MainWindow() { void MainWindow::updateEffects() { //! dont read behind the initial elements in case one was added - uint32_t tvSize = tvElements.size(); + uint32_t tvSize = tvElements.size(); uint32_t drcSize = drcElements.size(); for (uint32_t i = 0; (i < drcSize) && (i < drcElements.size()); ++i) { @@ -90,7 +89,7 @@ void MainWindow::updateEffects() { void MainWindow::process() { //! dont read behind the initial elements in case one was added - uint32_t tvSize = tvElements.size(); + uint32_t tvSize = tvElements.size(); uint32_t drcSize = drcElements.size(); for (uint32_t i = 0; (i < drcSize) && (i < drcElements.size()); ++i) { @@ -160,25 +159,25 @@ void MainWindow::update(GuiController *controller) { } } -// //! only update TV elements that are not updated yet because they are on DRC -// for(uint32_t i = 0; (i < tvSize) && (i < tvElements.size()); ++i) -// { -// uint32_t n; -// for(n = 0; (n < drcSize) && (n < drcElements.size()); n++) -// { -// if(tvElements[i] == drcElements[n]) -// break; -// } -// if(n == drcElements.size()) -// { -// tvElements[i]->update(controller); -// } -// } + // //! only update TV elements that are not updated yet because they are on DRC + // for(uint32_t i = 0; (i < tvSize) && (i < tvElements.size()); ++i) + // { + // uint32_t n; + // for(n = 0; (n < drcSize) && (n < drcElements.size()); n++) + // { + // if(tvElements[i] == drcElements[n]) + // break; + // } + // if(n == drcElements.size()) + // { + // tvElements[i]->update(controller); + // } + // } if (controller->chanIdx >= 1 && controller->chanIdx <= 4 && controller->data.validPointer) { int32_t wpadIdx = controller->chanIdx - 1; - float posX = controller->data.x; - float posY = controller->data.y; + float posX = controller->data.x; + float posY = controller->data.y; pointerImg[wpadIdx]->setPosition(posX, posY); pointerImg[wpadIdx]->setAngle(controller->data.pointerAngle); pointerValid[wpadIdx] = true; @@ -312,8 +311,8 @@ void MainWindow::OnLayoutSwitchEffectFinish(GuiElement *element) { remove(currentTvFrame); GuiTitleBrowser *tmpElement = currentDrcFrame; - currentDrcFrame = currentTvFrame; - currentTvFrame = tmpElement; + currentDrcFrame = currentTvFrame; + currentTvFrame = tmpElement; appendTv(currentTvFrame); appendDrc(currentDrcFrame); @@ -354,7 +353,6 @@ void MainWindow::OnCloseEffectFinish(GuiElement *element) { } void MainWindow::OnSettingsButtonClicked(GuiElement *element) { - } void MainWindow::OnGameSelectionChange(GuiTitleBrowser *element, uint64_t selectedIdx) { @@ -463,7 +461,7 @@ void MainWindow::OnGameLaunch(uint64_t titleId) { MCPTitleListType titleInfo; int32_t handle = MCP_Open(); - auto err = MCP_GetTitleInfo(handle, titleId, &titleInfo); + auto err = MCP_GetTitleInfo(handle, titleId, &titleInfo); MCP_Close(handle); if (err == 0) { ACPAssignTitlePatch(&titleInfo); diff --git a/src/menu/MainWindow.h b/src/menu/MainWindow.h index 369dac9..0a53422 100644 --- a/src/menu/MainWindow.h +++ b/src/menu/MainWindow.h @@ -17,13 +17,13 @@ #ifndef _MAIN_WINDOW_H_ #define _MAIN_WINDOW_H_ -#include -#include -#include -#include "game/GameList.h" #include "KeyboardHelper.h" -#include "gui/GuiTitleBrowser.h" #include "MainDrcButtonsFrame.h" +#include "game/GameList.h" +#include "gui/GuiTitleBrowser.h" +#include +#include +#include class CVideo; diff --git a/src/resources/Resources.cpp b/src/resources/Resources.cpp index 8dcb450..47f354c 100644 --- a/src/resources/Resources.cpp +++ b/src/resources/Resources.cpp @@ -1,18 +1,18 @@ +#include "Resources.h" +#include "filelist.h" +#include "fs/FSUtils.h" +#include "utils/AsyncExecutor.h" +#include +#include #include #include #include -#include "Resources.h" -#include "filelist.h" -#include -#include -#include "fs/FSUtils.h" -#include "utils/AsyncExecutor.h" #include #include #include -#include #include +#include Resources *Resources::instance = nullptr; @@ -46,12 +46,12 @@ bool Resources::LoadFiles(const char *path) { fullpath += "/"; fullpath += RecourceList[i].filename; - uint8_t *buffer = nullptr; + uint8_t *buffer = nullptr; uint32_t filesize = 0; FSUtils::LoadFileToMem(fullpath.c_str(), &buffer, &filesize); - RecourceList[i].CustomFile = buffer; + RecourceList[i].CustomFile = buffer; RecourceList[i].CustomFileSize = (uint32_t) filesize; result |= (buffer != 0); } @@ -82,7 +82,7 @@ GuiImageData *Resources::GetImageData(const char *filename) { if (!instance) instance = new Resources; - std::map >::iterator itr = instance->imageDataMap.find(std::string(filename)); + std::map>::iterator itr = instance->imageDataMap.find(std::string(filename)); if (itr != instance->imageDataMap.end()) { itr->second.first++; return itr->second.second; @@ -96,8 +96,8 @@ GuiImageData *Resources::GetImageData(const char *filename) { if (buff == nullptr) return nullptr; - GuiImageData *image = new GuiImageData(buff, size); - instance->imageDataMap[std::string(filename)].first = 1; + GuiImageData *image = new GuiImageData(buff, size); + instance->imageDataMap[std::string(filename)].first = 1; instance->imageDataMap[std::string(filename)].second = image; return image; @@ -108,7 +108,7 @@ GuiImageData *Resources::GetImageData(const char *filename) { } void Resources::RemoveImageData(GuiImageData *image) { - std::map >::iterator itr; + std::map>::iterator itr; for (itr = instance->imageDataMap.begin(); itr != instance->imageDataMap.end(); itr++) { if (itr->second.second == image) { @@ -128,7 +128,7 @@ GuiSound *Resources::GetSound(const char *filename) { if (!instance) instance = new Resources; - std::map >::iterator itr = instance->soundDataMap.find(std::string(filename)); + std::map>::iterator itr = instance->soundDataMap.find(std::string(filename)); if (itr != instance->soundDataMap.end()) { itr->second.first++; return itr->second.second; @@ -142,8 +142,8 @@ GuiSound *Resources::GetSound(const char *filename) { if (buff == nullptr) return nullptr; - GuiSound *sound = new GuiSound(buff, size); - instance->soundDataMap[std::string(filename)].first = 1; + GuiSound *sound = new GuiSound(buff, size); + instance->soundDataMap[std::string(filename)].first = 1; instance->soundDataMap[std::string(filename)].second = sound; return sound; @@ -154,7 +154,7 @@ GuiSound *Resources::GetSound(const char *filename) { } void Resources::RemoveSound(GuiSound *sound) { - std::map >::iterator itr; + std::map>::iterator itr; for (itr = instance->soundDataMap.begin(); itr != instance->soundDataMap.end(); itr++) { if (itr->second.second == sound) { diff --git a/src/resources/Resources.h b/src/resources/Resources.h index 35b6c25..8c47d61 100644 --- a/src/resources/Resources.h +++ b/src/resources/Resources.h @@ -2,6 +2,7 @@ #include #include +#include //! forward declaration class GuiImageData; @@ -33,6 +34,6 @@ private: ~Resources() {} - std::map > imageDataMap; - std::map > soundDataMap; + std::map> imageDataMap; + std::map> soundDataMap; }; \ No newline at end of file diff --git a/src/system/CThread.h b/src/system/CThread.h index d81f739..eb48cff 100644 --- a/src/system/CThread.h +++ b/src/system/CThread.h @@ -17,29 +17,26 @@ #ifndef CTHREAD_H_ #define CTHREAD_H_ +#include #include #include -#include class CThread { public: - typedef void (* Callback)(CThread *thread, void *arg); + typedef void (*Callback)(CThread *thread, void *arg); //! constructor CThread(int32_t iAttr, int32_t iPriority = 16, int32_t iStackSize = 0x8000, CThread::Callback callback = nullptr, void *callbackArg = nullptr) - : pThread(nullptr) - , pThreadStack(nullptr) - , pCallback(callback) - , pCallbackArg(callbackArg) { + : pThread(nullptr), pThreadStack(nullptr), pCallback(callback), pCallbackArg(callbackArg) { //! save attribute assignment iAttributes = iAttr; //! allocate the thread - pThread = (OSThread*)memalign(8, sizeof(OSThread)); + pThread = (OSThread *) memalign(8, sizeof(OSThread)); //! allocate the stack pThreadStack = (uint8_t *) memalign(0x20, iStackSize); //! create the thread - if(pThread && pThreadStack) - OSCreateThread(pThread, &CThread::threadCallback, 1, (char*)this, pThreadStack+iStackSize, iStackSize, iPriority, iAttributes); + if (pThread && pThreadStack) + OSCreateThread(pThread, &CThread::threadCallback, 1, (char *) this, pThreadStack + iStackSize, iStackSize, iPriority, iAttributes); } //! destructor @@ -48,46 +45,46 @@ public: } static CThread *create(CThread::Callback callback, void *callbackArg, int32_t iAttr = eAttributeNone, int32_t iPriority = 16, int32_t iStackSize = 0x8000) { - return ( new CThread(iAttr, iPriority, iStackSize, callback, callbackArg) ); + return (new CThread(iAttr, iPriority, iStackSize, callback, callbackArg)); } //! Get thread ID - virtual void* getThread() const { + virtual void *getThread() const { return pThread; } //! Thread entry function virtual void executeThread(void) { - if(pCallback) + if (pCallback) pCallback(this, pCallbackArg); } //! Suspend thread virtual void suspendThread(void) { - if(isThreadSuspended()) + if (isThreadSuspended()) return; - if(pThread) + if (pThread) OSSuspendThread(pThread); } //! Resume thread virtual void resumeThread(void) { - if(!isThreadSuspended()) + if (!isThreadSuspended()) return; - if(pThread) + if (pThread) OSResumeThread(pThread); } //! Set thread priority virtual void setThreadPriority(int32_t prio) { - if(pThread) + if (pThread) OSSetThreadPriority(pThread, prio); } //! Check if thread is suspended virtual bool isThreadSuspended(void) const { - if(pThread) + if (pThread) return OSIsThreadSuspended(pThread); return false; } //! Check if thread is terminated virtual bool isThreadTerminated(void) const { - if(pThread) + if (pThread) return OSIsThreadTerminated(pThread); return false; } @@ -98,30 +95,31 @@ public: //! Shutdown thread virtual void shutdownThread(void) { //! wait for thread to finish - if(pThread && !(iAttributes & eAttributeDetach)) { - if(isThreadSuspended()) + if (pThread && !(iAttributes & eAttributeDetach)) { + if (isThreadSuspended()) resumeThread(); OSJoinThread(pThread, nullptr); } //! free the thread stack buffer - if(pThreadStack) + if (pThreadStack) free(pThreadStack); - if(pThread) + if (pThread) free(pThread); - pThread = nullptr; + pThread = nullptr; pThreadStack = nullptr; } //! Thread attributes enum eCThreadAttributes { - eAttributeNone = 0x07, - eAttributeAffCore0 = 0x01, - eAttributeAffCore1 = 0x02, - eAttributeAffCore2 = 0x04, - eAttributeDetach = 0x08, - eAttributePinnedAff = 0x10 + eAttributeNone = 0x07, + eAttributeAffCore0 = 0x01, + eAttributeAffCore1 = 0x02, + eAttributeAffCore2 = 0x04, + eAttributeDetach = 0x08, + eAttributePinnedAff = 0x10 }; + private: static int32_t threadCallback(int32_t argc, const char **argv) { //! After call to start() continue with the internal function diff --git a/src/utils/AsyncExecutor.cpp b/src/utils/AsyncExecutor.cpp index 6a6e6fc..d7a5013 100644 --- a/src/utils/AsyncExecutor.cpp +++ b/src/utils/AsyncExecutor.cpp @@ -14,7 +14,7 @@ AsyncExecutor::AsyncExecutor() { while (!exitThread) { mutex.lock(); bool emptyList = elements.empty(); - auto it = elements.begin(); + auto it = elements.begin(); while (it != elements.end()) { auto future = it; auto status = future->wait_for(std::chrono::seconds(0)); diff --git a/src/utils/AsyncExecutor.h b/src/utils/AsyncExecutor.h index 108d204..09f9e09 100644 --- a/src/utils/AsyncExecutor.h +++ b/src/utils/AsyncExecutor.h @@ -1,12 +1,12 @@ #pragma once -#include -#include -#include -#include -#include -#include #include "utils/logger.h" +#include +#include +#include +#include +#include +#include class AsyncExecutor { public: diff --git a/src/utils/StringTools.cpp b/src/utils/StringTools.cpp index d9baf72..416da5c 100644 --- a/src/utils/StringTools.cpp +++ b/src/utils/StringTools.cpp @@ -23,17 +23,16 @@ * * for WiiXplorer 2010 ***************************************************************************/ -#include -#include -#include #include +#include #include -#include -#include +#include +#include #include -#include -#include #include +#include +#include +#include BOOL StringTools::EndsWith(const std::string &a, const std::string &b) { @@ -85,7 +84,7 @@ const wchar_t *StringTools::wfmt(const char *format, ...) { static char tmp[512]; static wchar_t strWChar[512]; strWChar[0] = 0; - tmp[0] = 0; + tmp[0] = 0; if (!format) return (const wchar_t *) strWChar; @@ -98,7 +97,7 @@ const wchar_t *StringTools::wfmt(const char *format, ...) { if ((vsprintf(tmp, format, va) >= 0)) { int32_t bt; int32_t strlength = strlen(tmp); - bt = mbstowcs(strWChar, tmp, (strlength < 512) ? strlength : 512); + bt = mbstowcs(strWChar, tmp, (strlength < 512) ? strlength : 512); if (bt > 0) { strWChar[bt] = 0; @@ -112,13 +111,13 @@ const wchar_t *StringTools::wfmt(const char *format, ...) { int32_t StringTools::strprintf(std::string &str, const char *format, ...) { static char tmp[512]; - tmp[0] = 0; + tmp[0] = 0; int32_t result = 0; va_list va; va_start(va, format); if ((vsprintf(tmp, format, va) >= 0)) { - str = tmp; + str = tmp; result = str.size(); } va_end(va); @@ -214,7 +213,6 @@ bool StringTools::findStringIC(const std::string &strHaystack, const std::string auto it = std::search( strHaystack.begin(), strHaystack.end(), strNeedle.begin(), strNeedle.end(), - [](char ch1, char ch2) { return std::toupper(ch1) == std::toupper(ch2); } - ); + [](char ch1, char ch2) { return std::toupper(ch1) == std::toupper(ch2); }); return (it != strHaystack.end()); } diff --git a/src/utils/StringTools.h b/src/utils/StringTools.h index 0d28fa4..e118a2a 100644 --- a/src/utils/StringTools.h +++ b/src/utils/StringTools.h @@ -26,11 +26,11 @@ #ifndef __STRING_TOOLS_H #define __STRING_TOOLS_H -#include -#include -#include #include #include +#include +#include +#include class StringTools { public: @@ -58,7 +58,7 @@ public: if (!path) return path; - const char *ptr = path; + const char *ptr = path; const char *Filename = ptr; while (*ptr != '\0') { @@ -91,4 +91,3 @@ public: }; #endif /* __STRING_TOOLS_H */ - diff --git a/src/utils/logger.h b/src/utils/logger.h index efeda1b..a91f9a1 100644 --- a/src/utils/logger.h +++ b/src/utils/logger.h @@ -1,24 +1,25 @@ #pragma once -#include #include +#include #ifdef __cplusplus extern "C" { #endif #define __FILENAME_X__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__) -#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILENAME_X__) +#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILENAME_X__) -#define DEBUG_FUNCTION_LINE(FMT, ARGS...)do { \ - WHBLogPrintf("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \ +#define DEBUG_FUNCTION_LINE(FMT, ARGS...) \ + do { \ + WHBLogPrintf("[%23s]%30s@L%04d: " FMT "", __FILENAME__, __FUNCTION__, __LINE__, ##ARGS); \ } while (0) -#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...)do { \ - WHBLogWritef("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \ +#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...) \ + do { \ + WHBLogWritef("[%23s]%30s@L%04d: " FMT "", __FILENAME__, __FUNCTION__, __LINE__, ##ARGS); \ } while (0) #ifdef __cplusplus } #endif - diff --git a/src/utils/utils.c b/src/utils/utils.c index 01641b1..2a4b4b8 100644 --- a/src/utils/utils.c +++ b/src/utils/utils.c @@ -1,9 +1,9 @@ -#include -#include +#include #include #include #include -#include +#include +#include #include // https://gist.github.com/ccbrown/9722406 diff --git a/src/utils/utils.h b/src/utils/utils.h index 1d00f98..a65f134 100644 --- a/src/utils/utils.h +++ b/src/utils/utils.h @@ -7,23 +7,24 @@ extern "C" { #endif -#define LIMIT(x, min, max) \ - ({ \ - typeof( x ) _x = x; \ - typeof( min ) _min = min; \ - typeof( max ) _max = max; \ - ( ( ( _x ) < ( _min ) ) ? ( _min ) : ( ( _x ) > ( _max ) ) ? ( _max) : ( _x ) ); \ -}) +#define LIMIT(x, min, max) \ + ({ \ + typeof(x) _x = x; \ + typeof(min) _min = min; \ + typeof(max) _max = max; \ + (((_x) < (_min)) ? (_min) : ((_x) > (_max)) ? (_max) \ + : (_x)); \ + }) -#define DegToRad(a) ( (a) * 0.01745329252f ) -#define RadToDeg(a) ( (a) * 57.29577951f ) +#define DegToRad(a) ((a) *0.01745329252f) +#define RadToDeg(a) ((a) *57.29577951f) -#define ALIGN4(x) (((x) + 3) & ~3) -#define ALIGN32(x) (((x) + 31) & ~31) +#define ALIGN4(x) (((x) + 3) & ~3) +#define ALIGN32(x) (((x) + 31) & ~31) -#define le16(i) ((((uint16_t) ((i) & 0xFF)) << 8) | ((uint16_t) (((i) & 0xFF00) >> 8))) -#define le32(i) ((((uint32_t)le16((i) & 0xFFFF)) << 16) | ((uint32_t)le16(((i) & 0xFFFF0000) >> 16))) -#define le64(i) ((((uint64_t)le32((i) & 0xFFFFFFFFLL)) << 32) | ((uint64_t)le32(((i) & 0xFFFFFFFF00000000LL) >> 32))) +#define le16(i) ((((uint16_t) ((i) &0xFF)) << 8) | ((uint16_t) (((i) &0xFF00) >> 8))) +#define le32(i) ((((uint32_t) le16((i) &0xFFFF)) << 16) | ((uint32_t) le16(((i) &0xFFFF0000) >> 16))) +#define le64(i) ((((uint64_t) le32((i) &0xFFFFFFFFLL)) << 32) | ((uint64_t) le32(((i) &0xFFFFFFFF00000000LL) >> 32))) //Needs to have log_init() called beforehand. void dumpHex(const void *data, size_t size);