Add .clang-format, adjust variable names

This commit is contained in:
Tulpen 2023-05-27 20:47:34 +01:00
parent 72d5aa0502
commit e03d66f4d4
11 changed files with 173 additions and 66 deletions

108
.clang-format Normal file
View file

@ -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

View file

@ -1,12 +1,12 @@
# Hibis Game Engine # 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++.<br> 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++.<br>
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 # Install
## Pre-compiled libraries ## Pre-compiled libraries
lmao they don't exist yet chill lmao they don't exist yet chill
## Compiling ## Compiling
### Note: MSVC ### 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 ### Dependencies
To compile Hibis, you will need: To compile Hibis, you will need:
- Meson - Meson

View file

@ -5,14 +5,14 @@
namespace hibis { namespace hibis {
Engine::Engine(Renderer* renderer, LoggerCallback logger) { Engine::Engine(Renderer* renderer, LoggerCallback logger) {
this->renderer = renderer; this->mRenderer = renderer;
loggerCallback = logger; mLoggerCallback = logger;
previousProcessTick = std::chrono::steady_clock::now(); mPreviousProcessTick = std::chrono::steady_clock::now();
previousPhysicsProcessTick = std::chrono::steady_clock::now(); mPreviousPhysicsProcessTick = std::chrono::steady_clock::now();
//watch.start(); //watch.start();
this->loggerCallback(Information, "Started Hibis [using v" + (std::string)getEngineVersion() + "]!"); this->mLoggerCallback(Information, "Started Hibis [using v" + (std::string)getEngineVersion() + "]!");
} }
Engine::~Engine() { Engine::~Engine() {
@ -22,31 +22,31 @@ namespace hibis {
void Engine::runNodeProcesses() { void Engine::runNodeProcesses() {
TODO("check if delta calc is correct") TODO("check if delta calc is correct")
const std::chrono::time_point<std::chrono::steady_clock> current = std::chrono::steady_clock::now(); const std::chrono::time_point<std::chrono::steady_clock> current = std::chrono::steady_clock::now();
auto delta = std::chrono::duration<float>(current - previousProcessTick); auto delta = std::chrono::duration<float>(current - mPreviousProcessTick);
for (Node* node : nodeList) { for (Node* node : mNodeList) {
node->process(delta.count()); node->process(delta.count());
} }
previousProcessTick = std::chrono::steady_clock::now(); mPreviousProcessTick = std::chrono::steady_clock::now();
} }
void Engine::runNodePhysicsProcesses() { void Engine::runNodePhysicsProcesses() {
const std::chrono::time_point<std::chrono::steady_clock> current = std::chrono::steady_clock::now(); const std::chrono::time_point<std::chrono::steady_clock> current = std::chrono::steady_clock::now();
auto delta = std::chrono::duration<float>(current - previousProcessTick); auto delta = std::chrono::duration<float>(current - mPreviousProcessTick);
for (Node* node : nodeList) { for (Node* node : mNodeList) {
node->physicsProcess(delta.count()); node->physicsProcess(delta.count());
} }
previousProcessTick = std::chrono::steady_clock::now(); mPreviousProcessTick = std::chrono::steady_clock::now();
} }
void Engine::drawNodes() { void Engine::drawNodes() {
TODO("check if this works") TODO("check if this works")
for (Node* node : nodeList) { for (Node* node : mNodeList) {
if (Drawable* drawNode = (Drawable*)&node) { if (Drawable* drawNode = (Drawable*)&node) {
drawNode->draw(renderer); drawNode->draw(mRenderer);
} }
} }
} }

View file

@ -21,12 +21,12 @@ namespace hibis {
const char* getEngineVersion(); const char* getEngineVersion();
private: private:
Renderer* renderer; Renderer* mRenderer;
//StopWatch watch; //StopWatch watch;
std::chrono::time_point<std::chrono::steady_clock> previousProcessTick; std::chrono::time_point<std::chrono::steady_clock> mPreviousProcessTick;
std::chrono::time_point<std::chrono::steady_clock> previousPhysicsProcessTick; std::chrono::time_point<std::chrono::steady_clock> mPreviousPhysicsProcessTick;
std::vector<Node*> nodeList; std::vector<Node*> mNodeList;
LoggerCallback loggerCallback; LoggerCallback mLoggerCallback;
}; };
} }

View file

@ -23,6 +23,6 @@ namespace hibis {
// Util // Util
virtual void setWindowTitle(std::string title) = 0; virtual void setWindowTitle(std::string title) = 0;
bool keepOpen = true; bool mKeepOpen = true;
}; };
} }

View file

@ -6,6 +6,6 @@
namespace hibis { namespace hibis {
TODO("Make this function") TODO("Make this function")
class Texture : Resource { class Texture : Resource {
void* data; void* mData;
}; };
} }

View file

@ -5,28 +5,28 @@
namespace hibis::rsdl { namespace hibis::rsdl {
Font::Font(std::string path, uint size) { Font::Font(std::string path, uint size) {
this->size = size; this->mSize = size;
this->path = path; this->mPath = path;
loadFont(); loadFont();
} }
Font::~Font() { Font::~Font() {
TTF_CloseFont(loadedFont); TTF_CloseFont(mLoadedFont);
} }
void Font::loadFont(bool reload) { void Font::loadFont(bool reload) {
// If already loaded, close font // If already loaded, close font
if (loadedFont != NULL) { if (mLoadedFont != NULL) {
TTF_CloseFont(loadedFont); TTF_CloseFont(mLoadedFont);
loadedFont = NULL; mLoadedFont = NULL;
} }
loadedFont = TTF_OpenFont(path.c_str(), size); mLoadedFont = TTF_OpenFont(mPath.c_str(), mSize);
// Do the message // Do the message
if (!didReload) { if (!mDidReload) {
std::cout << fmt::format((reload ? "Reloaded font from" : "Loaded font at") + (std::string)" {}", path) << std::endl; std::cout << fmt::format((reload ? "Reloaded font from" : "Loaded font at") + (std::string)" {}", mPath) << std::endl;
didReload = reload; mDidReload = reload;
} }
} }
} }

View file

@ -12,17 +12,16 @@ namespace hibis::rsdl {
~Font(); ~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* mLoadedFont = NULL;
TTF_Font* loadedFont = NULL;
private: private:
void loadFont(bool reload = false); void loadFont(bool reload = false);
uint size; uint mSize;
std::string path; std::string mPath;
bool didReload = false; bool mDidReload = false;
}; };
} }

View file

@ -8,33 +8,33 @@
namespace hibis::rsdl { namespace hibis::rsdl {
RSDL::RSDL(std::string title, IntVec2 size, LoggerCallback callback) { RSDL::RSDL(std::string title, IntVec2 size, LoggerCallback callback) {
logger = callback; mLoggerCallback = callback;
SDL_Init(SDL_INIT_VIDEO); SDL_Init(SDL_INIT_VIDEO);
// Create window. `title` is cast to a char* here as tostd::stringz returns an immutable char* (causing an error) // 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); size.x, size.y, SDL_WINDOW_RESIZABLE);
if (window == NULL) { if (mWindow == NULL) {
logger(Fatal, fmt::format("Couldn't create window! what: {}", SDL_GetError())); mLoggerCallback(Fatal, fmt::format("Couldn't create window! what: {}", SDL_GetError()));
SDL_Quit(); SDL_Quit();
exit(1); exit(1);
} }
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED); mRendererContext = SDL_CreateRenderer(mWindow, -1, SDL_RENDERER_ACCELERATED);
if (renderer == NULL) { if (mRendererContext == NULL) {
logger(Fatal, fmt::format("Couldn't create renderer! what: {}", SDL_GetError())); mLoggerCallback(Fatal, fmt::format("Couldn't create renderer! what: {}", SDL_GetError()));
SDL_DestroyWindow(window); SDL_DestroyWindow(mWindow);
SDL_Quit(); SDL_Quit();
exit(1); exit(1);
} }
if (TTF_Init() != 0) { if (TTF_Init() != 0) {
logger(Fatal, fmt::format("Couldn't load SDL_TTF! what: %d", TTF_GetError())); mLoggerCallback(Fatal, fmt::format("Couldn't load SDL_TTF! what: %d", TTF_GetError()));
SDL_DestroyRenderer(renderer); SDL_DestroyRenderer(mRendererContext);
SDL_DestroyWindow(window); SDL_DestroyWindow(mWindow);
SDL_Quit(); SDL_Quit();
TTF_Quit(); TTF_Quit();
exit(1); exit(1);
@ -43,31 +43,31 @@ namespace hibis::rsdl {
RSDL::~RSDL() { RSDL::~RSDL() {
TTF_Quit(); TTF_Quit();
SDL_DestroyRenderer(renderer); SDL_DestroyRenderer(mRendererContext);
SDL_DestroyWindow(window); SDL_DestroyWindow(mWindow);
SDL_Quit(); SDL_Quit();
} }
void RSDL::clearScreen(Color col) { void RSDL::clearScreen(Color col) {
SDL_SetRenderDrawColor(renderer, col.r, col.g, col.b, col.a); SDL_SetRenderDrawColor(mRendererContext, col.r, col.g, col.b, col.a);
SDL_RenderClear(renderer); SDL_RenderClear(mRendererContext);
} }
void RSDL::renderCurrent() { void RSDL::renderCurrent() {
SDL_UpdateWindowSurface(window); SDL_UpdateWindowSurface(mWindow);
SDL_RenderPresent(renderer); SDL_RenderPresent(mRendererContext);
} }
void RSDL::drawText(Resource* resource, std::string text, IntVec2 pos, Color color) { 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") WARNING("tulip what the hell is this, this sucks.\nAvoid remaking textures every time text has to be drawn")
if (Font* font = (Font*)resource) { 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_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(renderer, textSurface); SDL_Texture* textTexture = SDL_CreateTextureFromSurface(mRendererContext, textSurface);
int width = 0; int width = 0;
int height = 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; SDL_Rect textRect;
textRect.x = pos.x; textRect.x = pos.x;
@ -75,7 +75,7 @@ namespace hibis::rsdl {
textRect.w = width; textRect.w = width;
textRect.h = height; textRect.h = height;
SDL_RenderCopy(renderer, textTexture, NULL, &textRect); SDL_RenderCopy(mRendererContext, textTexture, NULL, &textRect);
SDL_DestroyTexture(textTexture); SDL_DestroyTexture(textTexture);
SDL_FreeSurface(textSurface); SDL_FreeSurface(textSurface);
@ -89,11 +89,11 @@ namespace hibis::rsdl {
SDL_Event event; SDL_Event event;
while(SDL_PollEvent(&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) { void RSDL::setWindowTitle(std::string title) {
SDL_SetWindowTitle(window, title.c_str()); SDL_SetWindowTitle(mWindow, title.c_str());
} }
} }

View file

@ -33,9 +33,9 @@ namespace hibis::rsdl {
void setWindowTitle(std::string title); void setWindowTitle(std::string title);
private: private:
SDL_Window* window; SDL_Window* mWindow;
SDL_Renderer* renderer; SDL_Renderer* mRendererContext;
LoggerCallback logger; LoggerCallback mLoggerCallback;
}; };
} }

View file

@ -60,7 +60,7 @@ int main() {
uint f = 0; uint f = 0;
logger(Information, "Started Hibis test app! BEHOLD: Colours."); logger(Information, "Started Hibis test app! BEHOLD: Colours.");
while (renderer.keepOpen) { while (renderer.mKeepOpen) {
engine.runNodeProcesses(); engine.runNodeProcesses();
// Colour changing background! // Colour changing background!