Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
203 changes: 203 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
TabWidth: 4
IndentWidth: 4
ColumnLimit: 150

UseTab: AlignWithSpaces

# Pointer and reference alignment style. Possible values: Left, Right, Middle.
PointerAlignment: Right
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vote for pointer to the left (on the side of the type)


# AccessModifierOffset (int)
# The extra indent or outdent of access modifiers, e.g. public:.
AccessModifierOffset: 0

AlignArrayOfStructures: Right
AlignAfterOpenBracket: true
AlignConsecutiveAssignments: Consecutive
AlignConsecutiveBitFields: Consecutive
AlignConsecutiveDeclarations: None
AlignConsecutiveMacros: Consecutive
AlignConsecutiveShortCaseStatements:
Enabled: true
AcrossEmptyLines: true
AcrossComments: true
AlignCaseColons: false


AlignEscapedNewlines: LeftWithLastLine

AlignOperands: Align

AlignTrailingComments:
Kind: Always
AlignPPAndNotPP: true

AllowAllArgumentsOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowBreakBeforeNoexceptSpecifier: Always

AllowShortBlocksOnASingleLine: Always
AllowShortCaseExpressionOnASingleLine: true
AllowShortCaseLabelsOnASingleLine: true
AllowShortCompoundRequirementOnASingleLine: true
AllowShortEnumsOnASingleLine: false

AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: WithoutElse
AllowShortLambdasOnASingleLine: Inline
AllowShortLoopsOnASingleLine: true
AllowShortNamespacesOnASingleLine: false

AlwaysBreakBeforeMultilineStrings: false

BitFieldColonSpacing: Both

# TODO Highly Opinionated will need to deliberate on this. I prefer K&R Style but some prefer Allman
BreakBeforeBraces: Custom
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: Never
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterStruct: false
AfterExternBlock: false
BeforeCatch: true # catch on separate line, not like we'll use catch
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for consistency. I'd also rather have K&R

BeforeElse: true
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not having a break for if but having for else will look strange for me.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like

if(false) {
// Stuff
}
else if (true) {

}

if you set BeforeElse to false it would like

if(false) {
// Stuff
} else if (true) {

}

In my opinion that does make it a little harder to read especially if the last line before the else has a lot of values.

BeforeLambdaBody: false
BeforeWhile: true
IndentBraces: false

BreakAdjacentStringLiterals: false
BreakAfterAttributes: Leave

BreakAfterOpenBracketBracedList: false
BreakAfterOpenBracketFunction: false
BreakAfterOpenBracketIf: false
BreakAfterOpenBracketLoop: false
BreakAfterOpenBracketSwitch: false
BreakAfterReturnType: Automatic

BreakBeforeBinaryOperators: None
BreakBeforeCloseBracketBracedList: true
BreakBeforeCloseBracketFunction: true
BreakBeforeCloseBracketIf: true
BreakBeforeCloseBracketSwitch: true

BreakBeforeConceptDeclarations: Allowed
BreakBeforeInlineASMColon: OnlyMultiline
BreakBeforeTemplateCloser: true
BreakBeforeTernaryOperators: true

BreakConstructorInitializers: AfterColon
BreakFunctionDefinitionParameters: false

BreakInheritanceList: AfterColon

BreakStringLiterals: false

BreakTemplateDeclarations: Leave

CompactNamespaces: false

Cpp11BracedListStyle: FunctionCall

EmptyLineAfterAccessModifier: Leave
EmptyLineBeforeAccessModifier: LogicalBlock

EnumTrailingComma: Leave

FixNamespaceComments: true

IndentAccessModifiers: false

IndentCaseBlocks: false

IndentExportBlock: false
IndentExternBlock: false
IndentGotoLabels: true

IndentPPDirectives: BeforeHash
IndentRequiresClause: false
IndentWrappedFunctionNames: false

# I personally don't like unbraced things but this should be heavily discussed
# For example it's a Pain in the ass to go back and add braces when someone
# didn't include them after you need to extend it
InsertBraces: true

InsertNewlineAtEOF: true

# This one will be controversial...
IntegerLiteralSeparator:
Binary: 4
Decimal: 3
Hex: 4
Comment thread
JoltedJon marked this conversation as resolved.
BinaryMinDigitsInsert: 8
DecimalMinDigitsInsert: 6
HexMinDigitsInsert: 8

KeepEmptyLines:
AtEndOfFile: false
AtStartOfBlock: false
AtStartOfFile: false

KeepFormFeed: false

# No Microslop BS \r\n
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win

Revise unprofessional comment.

The comment contains informal language and a derogatory reference that is inappropriate for a project configuration file. Consider rewording to maintain professionalism.

📝 Suggested revision
-# No Microslop BS \r\n 
+# Use Unix-style line endings (LF) instead of Windows-style (CRLF)
 LineEnding: LF
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# No Microslop BS \r\n
# Use Unix-style line endings (LF) instead of Windows-style (CRLF)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.clang-format at line 151, Replace the unprofessional comment string "# No
Microslop BS" in the .clang-format file with a neutral, professional phrase (or
remove it entirely); locate the comment by searching for the exact text "# No
Microslop BS" and update it to something like a concise, descriptive note about
the intent (e.g., indicating that project-specific or proprietary vendor
settings are excluded) to keep the config file professional.

LineEnding: LF

NamespaceIndentation: None

NumericLiteralCase:
ExponentLetter: Leave
HexDigit: Lower
Prefix: Lower
Suffix: Upper

QualifierAlignment: Right

ReflowComments: Never

RemoveBracesLLVM: false
RemoveEmptyLinesInUnwrappedLines: false
RemoveParentheses: Leave

RemoveSemicolon: false

RequiresExpressionIndentation: OuterScope

SeparateDefinitionBlocks: Leave

SkipMacroDefinitionBody: true

SortIncludes:
Enabled: false

SortUsingDeclarations: Never

SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterOperatorKeyword: false
SpaceAfterTemplateKeyword: false
SpaceAroundPointerQualifiers: Default

SpaceBeforeAssignmentOperators: true
SpaceBeforeCaseColon: false
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements

SpaceBeforeRangeBasedForLoopColon: true
SpaceBeforeSquareBrackets: false
SpaceInEmptyBraces: Always

SpacesInAngles: Leave

SpacesInContainerLiterals: false
SpacesInParens: Never
SpacesInSquareBrackets: false


2 changes: 2 additions & 0 deletions .clang-format-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build/*
engine/native/thirdparty/*
27 changes: 12 additions & 15 deletions engine/native/core/definitions/definitions.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,21 @@ export module core.defs;
export import core.version;
export import core.stdtypes;

static_assert(__cplusplus >= 202207L, "Minimum of C++23 required. Consider upgrading your compiler.");
static_assert(__cplusplus >= 202'207L, "Minimum of C++23 required. Consider upgrading your compiler.");

export namespace draco {
template<typename T>
concept arithmetic = std::is_arithmetic_v<T>;
template<typename T> concept arithmetic = std::is_arithmetic_v<T>;

template<typename T>
concept trivial = std::is_trivial_v<T>;
template<typename T> concept trivial = std::is_trivial_v<T>;

// Whether the default value of a type is just all-0 bytes.
// This can most commonly be exploited by using memset for these types instead of loop-construct.
// Must be explicitly specialized to mark a type as such.
template <typename T>
struct is_zero_constructible : std::false_type {};
// Whether the default value of a type is just all-0 bytes.
// This can most commonly be exploited by using memset for these types instead of loop-construct.
// Must be explicitly specialized to mark a type as such.
template<typename T>
struct is_zero_constructible : std::false_type { };

template <typename T>
constexpr bool is_zero_constructible_v = is_zero_constructible<T>::value;
template<typename T>
constexpr bool is_zero_constructible_v = is_zero_constructible<T>::value;

template <typename T>
concept zero_constructible = is_zero_constructible_v<T>;
}
template<typename T> concept zero_constructible = is_zero_constructible_v<T>;
} // namespace draco
12 changes: 6 additions & 6 deletions engine/native/core/definitions/stdtypes.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@ module;
export module core.stdtypes;

export namespace draco {
using i8 = int8_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

using uint = unsigned int;
using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

using isize = int64_t;
using usize = std::size_t;

using rawptr = void *;
using rawptr = void *;
using uintptr = uintptr_t;
using ptrdiff = ptrdiff_t;

Expand Down
23 changes: 12 additions & 11 deletions engine/native/core/definitions/version.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,23 @@ import core.stdtypes;
export namespace draco {

struct Version {
u16 major;
u16 minor;
u16 patch;
u16 major;
u16 minor;
u16 patch;
};

constexpr Version VERSION{.major = 2026, .minor = 0, .patch = 0};
} // namespace draco

export namespace std {
template <> struct formatter<draco::Version> {
constexpr auto parse(std::format_parse_context &ctx) {
return ctx.begin(); // Accept any format spec (or parse custom ones)
}

auto format(const draco::Version &v, std::format_context &ctx) const {
return std::format_to(ctx.out(), "{}.{}.{}", v.major, v.minor, v.patch);
}
template<> struct formatter<draco::Version> {
constexpr auto parse(std::format_parse_context &ctx) {
return ctx.begin(); // Accept any format spec (or parse custom ones)
}

auto format(draco::Version const &v, std::format_context &ctx) const {
return std::format_to(ctx.out(), "{}.{}.{}", v.major, v.minor, v.patch);
}
};

} // namespace std
62 changes: 28 additions & 34 deletions engine/native/core/io/filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,31 @@ module core.io.filesystem;

import core.stdtypes;

namespace draco::core::io::filesystem
{
std::vector<u8> load_binary(const std::string& path)
{
// Open at the end (ate) to get size and in binary mode
std::ifstream file(path, std::ios::binary | std::ios::ate);

if (!file.is_open()) {
std::println("Error: Could not open file at: {}", path);
// Return an empty vector
return {};
}

std::streamsize size = file.tellg();
if (size < 0) {
std::println("Error: File is empty or unreadable: {}", path);
return {};
}

if (size == 0) {
return {};
}

file.seekg(0, std::ios::beg);

std::vector<u8> buffer(static_cast<std::size_t>(size));
if (file.read(reinterpret_cast<char*>(buffer.data()), size)) {
return buffer;
}

std::println("Error: Failed to read file contents: {}", path);
return {};
}
}
namespace draco::core::io::filesystem {
std::vector<u8> load_binary(std::string const &path) {
// Open at the end (ate) to get size and in binary mode
std::ifstream file(path, std::ios::binary | std::ios::ate);

if (!file.is_open()) {
std::println("Error: Could not open file at: {}", path);
// Return an empty vector
return {};
}

std::streamsize size = file.tellg();
if (size < 0) {
std::println("Error: File is empty or unreadable: {}", path);
return {};
}

if (size == 0) { return {}; }

file.seekg(0, std::ios::beg);

std::vector<u8> buffer(static_cast<std::size_t>(size));
if (file.read(reinterpret_cast<char *>(buffer.data()), size)) { return buffer; }

std::println("Error: Failed to read file contents: {}", path);
return {};
}
} // namespace draco::core::io::filesystem
9 changes: 4 additions & 5 deletions engine/native/core/io/filesystem.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ export module core.io.filesystem;

import core.stdtypes;

export namespace draco::core::io::filesystem
{
// Returns a buffer of the file data
std::vector<u8> load_binary(const std::string& path);
}
export namespace draco::core::io::filesystem {
// Returns a buffer of the file data
std::vector<u8> load_binary(std::string const &path);
} // namespace draco::core::io::filesystem
Loading
Loading