From e03d66f4d4a51a94cc167e1945864e3a36d8790c Mon Sep 17 00:00:00 2001 From: tulpenkiste Date: Sat, 27 May 2023 20:47:34 +0100 Subject: [PATCH] Add `.clang-format`, adjust variable names --- .clang-format | 108 +++++++++++++++++++++++++++++++ README.md | 4 +- core/engine/engine.cpp | 26 ++++---- core/engine/engine.hpp | 10 +-- core/renderer/renderer.hpp | 2 +- core/resources/texture.hpp | 2 +- renderer/rsdl/resources/font.cpp | 20 +++--- renderer/rsdl/resources/font.hpp | 13 ++-- renderer/rsdl/rsdl.cpp | 46 ++++++------- renderer/rsdl/rsdl.hpp | 6 +- test/app.cpp | 2 +- 11 files changed, 173 insertions(+), 66 deletions(-) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..676d9ff --- /dev/null +++ b/.clang-format @@ -0,0 +1,108 @@ +--- +UseTab: Always +UseCRLF: false +TabWidth: 4 +SpacesInSquareBrackets: false +SpacesInParentheses: false +SpacesInLineCommentPrefix: + Minimum: 1 + Maximum: 1 +SpaceInEmptyBlock: false +SpaceInEmptyParentheses: false +SpaceBeforeParensOptions: + AfterControlStatements: true + AfterForeachMacros: false + AfterFunctionDeclarationName: false + AfterFunctionDefinitionName: false + AfterIfMacros: false + AfterOverloadedOperator: false + AfterRequiresInClause: false + BeforeNonEmptyParentheses: false + AfterRequiresInExpression: false +LineEnding: LF +NamespaceIndentation: All +Language: Cpp +IncludeBlocks: Regroup +CompactNamespaces: false +Standard: c++17 +BreakBeforeBraces: Attach +InsertNewlineAtEOF: true +InsertTrailingCommas: None +IndentWidth: 4 +IndentRequiresClause: false +SortIncludes: CaseSensitive +SpaceAfterCStyleCast: false +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: false +SpaceAroundPointerQualifiers: Before +SpaceBeforeAssignmentOperators: true +SpaceBeforeCaseColon: false +SortUsingDeclarations: Lexicographic +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatementsExceptControlMacros +SpaceBeforeRangeBasedForLoopColon: true +SpaceBeforeSquareBrackets: false +SpacesInAngles: Never +SpacesInCStyleCastParentheses: false +SpacesInConditionalStatement: false +SpacesInContainerLiterals: false +SeparateDefinitionBlocks: Always +RequiresExpressionIndentation: OuterScope +RequiresClausePosition: SingleLine +ReferenceAlignment: Pointer +QualifierAlignment: Left +PointerAlignment: Left +PenaltyIndentedWhitespace: 20 +PackConstructorInitializers: CurrentLine +PPIndentWidth: 4 +LambdaBodyIndentation: Signature +KeepEmptyLinesAtTheStartOfBlocks: false +IndentPPDirectives: BeforeHash +IndentGotoLabels: true +IndentExternBlock: Indent +IndentCaseLabels: true +IndentCaseBlocks: false +IndentAccessModifiers: false +EmptyLineBeforeAccessModifier: Always +EmptyLineAfterAccessModifier: Never +DisableFormat: false +DerivePointerAlignment: false +Cpp11BracedListStyle: true +BraceWrapping: + SplitEmptyNamespace: false + SplitEmptyRecord: false + SplitEmptyFunction: false + IndentBraces: false + BeforeWhile: false + BeforeLambdaBody: false + BeforeElse: false + BeforeCatch: false + AfterClass: false + AfterCaseLabel: false + AfterControlStatement: Never + AfterEnum: false + AfterFunction: false + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + AfterExternBlock: false +BitFieldColonSpacing: After +AlwaysBreakAfterReturnType: None +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakTemplateDeclarations: No +AllowShortBlocksOnASingleLine: Always +AllowShortCaseLabelsOnASingleLine: false +AllowShortEnumsOnASingleLine: false +AllowShortFunctionsOnASingleLine: Inline +AllowShortIfStatementsOnASingleLine: AllIfsAndElse +AllowShortLoopsOnASingleLine: true +AllowShortLambdasOnASingleLine: All +AllowAllParametersOfDeclarationOnNextLine: false +AllowAllArgumentsOnNextLine: false +AlignTrailingComments: + Kind: Always +AlignOperands: Align +AlignEscapedNewlines: Left diff --git a/README.md b/README.md index 0453aa4..6c13c08 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ # Hibis Game Engine Hibis (short for Hibiscus ([named after the genus of flowering plants](https://en.wikipedia.org/wiki/Hibiscus))) is a work in progress game engine written in C++.
-The goal of this game engine is to provide each part of the engine (renderer, audio, physics etc.) in seperate libraries so you can easily make your own system if need be. +The goal of this game engine is to provide each module of the engine (renderer, audio, physics etc.) in seperate libraries so you can easily make your own system if need be. # Install ## Pre-compiled libraries lmao they don't exist yet chill ## Compiling ### Note: MSVC -`MSVC` (Microsoft Visual C++ Compiler) is unsupported and I cannot guarentee that Hibis will compile using it. Please use another compiler like G++ or Ninja instead. +`MSVC` (Microsoft Visual C++ Compiler) is unsupported and I cannot guarentee that Hibis will compile/run properly using it. Please use another compiler like G++ or Ninja instead. ### Dependencies To compile Hibis, you will need: - Meson diff --git a/core/engine/engine.cpp b/core/engine/engine.cpp index d3eecf1..c20e68e 100644 --- a/core/engine/engine.cpp +++ b/core/engine/engine.cpp @@ -5,14 +5,14 @@ namespace hibis { Engine::Engine(Renderer* renderer, LoggerCallback logger) { - this->renderer = renderer; - loggerCallback = logger; - previousProcessTick = std::chrono::steady_clock::now(); - previousPhysicsProcessTick = std::chrono::steady_clock::now(); + this->mRenderer = renderer; + mLoggerCallback = logger; + mPreviousProcessTick = std::chrono::steady_clock::now(); + mPreviousPhysicsProcessTick = std::chrono::steady_clock::now(); //watch.start(); - this->loggerCallback(Information, "Started Hibis [using v" + (std::string)getEngineVersion() + "]!"); + this->mLoggerCallback(Information, "Started Hibis [using v" + (std::string)getEngineVersion() + "]!"); } Engine::~Engine() { @@ -22,31 +22,31 @@ namespace hibis { void Engine::runNodeProcesses() { TODO("check if delta calc is correct") const std::chrono::time_point current = std::chrono::steady_clock::now(); - auto delta = std::chrono::duration(current - previousProcessTick); + auto delta = std::chrono::duration(current - mPreviousProcessTick); - for (Node* node : nodeList) { + for (Node* node : mNodeList) { node->process(delta.count()); } - previousProcessTick = std::chrono::steady_clock::now(); + mPreviousProcessTick = std::chrono::steady_clock::now(); } void Engine::runNodePhysicsProcesses() { const std::chrono::time_point current = std::chrono::steady_clock::now(); - auto delta = std::chrono::duration(current - previousProcessTick); + auto delta = std::chrono::duration(current - mPreviousProcessTick); - for (Node* node : nodeList) { + for (Node* node : mNodeList) { node->physicsProcess(delta.count()); } - previousProcessTick = std::chrono::steady_clock::now(); + mPreviousProcessTick = std::chrono::steady_clock::now(); } void Engine::drawNodes() { TODO("check if this works") - for (Node* node : nodeList) { + for (Node* node : mNodeList) { if (Drawable* drawNode = (Drawable*)&node) { - drawNode->draw(renderer); + drawNode->draw(mRenderer); } } } diff --git a/core/engine/engine.hpp b/core/engine/engine.hpp index e1513e4..7926712 100644 --- a/core/engine/engine.hpp +++ b/core/engine/engine.hpp @@ -21,12 +21,12 @@ namespace hibis { const char* getEngineVersion(); private: - Renderer* renderer; + Renderer* mRenderer; //StopWatch watch; - std::chrono::time_point previousProcessTick; - std::chrono::time_point previousPhysicsProcessTick; + std::chrono::time_point mPreviousProcessTick; + std::chrono::time_point mPreviousPhysicsProcessTick; - std::vector nodeList; - LoggerCallback loggerCallback; + std::vector mNodeList; + LoggerCallback mLoggerCallback; }; } diff --git a/core/renderer/renderer.hpp b/core/renderer/renderer.hpp index 9190510..73347e9 100644 --- a/core/renderer/renderer.hpp +++ b/core/renderer/renderer.hpp @@ -23,6 +23,6 @@ namespace hibis { // Util virtual void setWindowTitle(std::string title) = 0; - bool keepOpen = true; + bool mKeepOpen = true; }; } diff --git a/core/resources/texture.hpp b/core/resources/texture.hpp index c551de2..b312401 100644 --- a/core/resources/texture.hpp +++ b/core/resources/texture.hpp @@ -6,6 +6,6 @@ namespace hibis { TODO("Make this function") class Texture : Resource { - void* data; + void* mData; }; } diff --git a/renderer/rsdl/resources/font.cpp b/renderer/rsdl/resources/font.cpp index 8fa1a17..5d0e86e 100644 --- a/renderer/rsdl/resources/font.cpp +++ b/renderer/rsdl/resources/font.cpp @@ -5,28 +5,28 @@ namespace hibis::rsdl { Font::Font(std::string path, uint size) { - this->size = size; - this->path = path; + this->mSize = size; + this->mPath = path; loadFont(); } Font::~Font() { - TTF_CloseFont(loadedFont); + TTF_CloseFont(mLoadedFont); } void Font::loadFont(bool reload) { // If already loaded, close font - if (loadedFont != NULL) { - TTF_CloseFont(loadedFont); - loadedFont = NULL; + if (mLoadedFont != NULL) { + TTF_CloseFont(mLoadedFont); + mLoadedFont = NULL; } - loadedFont = TTF_OpenFont(path.c_str(), size); + mLoadedFont = TTF_OpenFont(mPath.c_str(), mSize); // Do the message - if (!didReload) { - std::cout << fmt::format((reload ? "Reloaded font from" : "Loaded font at") + (std::string)" {}", path) << std::endl; - didReload = reload; + if (!mDidReload) { + std::cout << fmt::format((reload ? "Reloaded font from" : "Loaded font at") + (std::string)" {}", mPath) << std::endl; + mDidReload = reload; } } } diff --git a/renderer/rsdl/resources/font.hpp b/renderer/rsdl/resources/font.hpp index 5ae37e2..2c64f1c 100644 --- a/renderer/rsdl/resources/font.hpp +++ b/renderer/rsdl/resources/font.hpp @@ -12,17 +12,16 @@ namespace hibis::rsdl { ~Font(); - uint getFontSize() { return size; } + uint getFontSize() { return mSize; } - void setFontSize(uint newSize) { size = newSize; loadFont(true); } + void setFontSize(uint newSize) { mSize = newSize; loadFont(true); } - - TTF_Font* loadedFont = NULL; + TTF_Font* mLoadedFont = NULL; private: void loadFont(bool reload = false); - uint size; - std::string path; + uint mSize; + std::string mPath; - bool didReload = false; + bool mDidReload = false; }; } diff --git a/renderer/rsdl/rsdl.cpp b/renderer/rsdl/rsdl.cpp index 0050c71..dd5316e 100644 --- a/renderer/rsdl/rsdl.cpp +++ b/renderer/rsdl/rsdl.cpp @@ -8,33 +8,33 @@ namespace hibis::rsdl { RSDL::RSDL(std::string title, IntVec2 size, LoggerCallback callback) { - logger = callback; + mLoggerCallback = callback; SDL_Init(SDL_INIT_VIDEO); // Create window. `title` is cast to a char* here as tostd::stringz returns an immutable char* (causing an error) - window = SDL_CreateWindow(title.c_str(), SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, + mWindow = SDL_CreateWindow(title.c_str(), SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, size.x, size.y, SDL_WINDOW_RESIZABLE); - if (window == NULL) { - logger(Fatal, fmt::format("Couldn't create window! what: {}", SDL_GetError())); + if (mWindow == NULL) { + mLoggerCallback(Fatal, fmt::format("Couldn't create window! what: {}", SDL_GetError())); SDL_Quit(); exit(1); } - renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED); + mRendererContext = SDL_CreateRenderer(mWindow, -1, SDL_RENDERER_ACCELERATED); - if (renderer == NULL) { - logger(Fatal, fmt::format("Couldn't create renderer! what: {}", SDL_GetError())); - SDL_DestroyWindow(window); + if (mRendererContext == NULL) { + mLoggerCallback(Fatal, fmt::format("Couldn't create renderer! what: {}", SDL_GetError())); + SDL_DestroyWindow(mWindow); SDL_Quit(); exit(1); } if (TTF_Init() != 0) { - logger(Fatal, fmt::format("Couldn't load SDL_TTF! what: %d", TTF_GetError())); - SDL_DestroyRenderer(renderer); - SDL_DestroyWindow(window); + mLoggerCallback(Fatal, fmt::format("Couldn't load SDL_TTF! what: %d", TTF_GetError())); + SDL_DestroyRenderer(mRendererContext); + SDL_DestroyWindow(mWindow); SDL_Quit(); TTF_Quit(); exit(1); @@ -43,31 +43,31 @@ namespace hibis::rsdl { RSDL::~RSDL() { TTF_Quit(); - SDL_DestroyRenderer(renderer); - SDL_DestroyWindow(window); + SDL_DestroyRenderer(mRendererContext); + SDL_DestroyWindow(mWindow); SDL_Quit(); } void RSDL::clearScreen(Color col) { - SDL_SetRenderDrawColor(renderer, col.r, col.g, col.b, col.a); - SDL_RenderClear(renderer); + SDL_SetRenderDrawColor(mRendererContext, col.r, col.g, col.b, col.a); + SDL_RenderClear(mRendererContext); } void RSDL::renderCurrent() { - SDL_UpdateWindowSurface(window); - SDL_RenderPresent(renderer); + SDL_UpdateWindowSurface(mWindow); + SDL_RenderPresent(mRendererContext); } void RSDL::drawText(Resource* resource, std::string text, IntVec2 pos, Color color) { WARNING("tulip what the hell is this, this sucks.\nAvoid remaking textures every time text has to be drawn") if (Font* font = (Font*)resource) { - SDL_Surface* textSurface = TTF_RenderText_Solid(font->loadedFont, text.c_str(), SDL_Color {color.r, color.g, color.b, color.a }); - SDL_Texture* textTexture = SDL_CreateTextureFromSurface(renderer, textSurface); + SDL_Surface* textSurface = TTF_RenderText_Solid(font->mLoadedFont, text.c_str(), SDL_Color {color.r, color.g, color.b, color.a }); + SDL_Texture* textTexture = SDL_CreateTextureFromSurface(mRendererContext, textSurface); int width = 0; int height = 0; - TTF_SizeText(font->loadedFont, text.c_str(), &width, &height); + TTF_SizeText(font->mLoadedFont, text.c_str(), &width, &height); SDL_Rect textRect; textRect.x = pos.x; @@ -75,7 +75,7 @@ namespace hibis::rsdl { textRect.w = width; textRect.h = height; - SDL_RenderCopy(renderer, textTexture, NULL, &textRect); + SDL_RenderCopy(mRendererContext, textTexture, NULL, &textRect); SDL_DestroyTexture(textTexture); SDL_FreeSurface(textSurface); @@ -89,11 +89,11 @@ namespace hibis::rsdl { SDL_Event event; while(SDL_PollEvent(&event)) { - if (event.type == SDL_QUIT) keepOpen = false; + if (event.type == SDL_QUIT) mKeepOpen = false; } } void RSDL::setWindowTitle(std::string title) { - SDL_SetWindowTitle(window, title.c_str()); + SDL_SetWindowTitle(mWindow, title.c_str()); } } diff --git a/renderer/rsdl/rsdl.hpp b/renderer/rsdl/rsdl.hpp index f868a53..b26b277 100644 --- a/renderer/rsdl/rsdl.hpp +++ b/renderer/rsdl/rsdl.hpp @@ -33,9 +33,9 @@ namespace hibis::rsdl { void setWindowTitle(std::string title); private: - SDL_Window* window; - SDL_Renderer* renderer; + SDL_Window* mWindow; + SDL_Renderer* mRendererContext; - LoggerCallback logger; + LoggerCallback mLoggerCallback; }; } diff --git a/test/app.cpp b/test/app.cpp index e2514d0..23a3217 100644 --- a/test/app.cpp +++ b/test/app.cpp @@ -60,7 +60,7 @@ int main() { uint f = 0; logger(Information, "Started Hibis test app! BEHOLD: Colours."); - while (renderer.keepOpen) { + while (renderer.mKeepOpen) { engine.runNodeProcesses(); // Colour changing background!