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 (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
## 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

View file

@ -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<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());
}
previousProcessTick = std::chrono::steady_clock::now();
mPreviousProcessTick = std::chrono::steady_clock::now();
}
void Engine::runNodePhysicsProcesses() {
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());
}
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);
}
}
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -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());
}
}

View file

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

View file

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