Skip to content

Commit

Permalink
added the basest of the base window creation, pulled in GLFW as a dep…
Browse files Browse the repository at this point in the history
…endency
  • Loading branch information
Israfil committed Feb 8, 2025
1 parent d7be82e commit 0bb385f
Show file tree
Hide file tree
Showing 10 changed files with 215 additions and 12 deletions.
112 changes: 112 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
---
BasedOnStyle: LLVM
IndentAccessModifiers: true
AccessModifierOffset: 0
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Right
InsertNewlineAtEOF: true
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: Always
AlignConsecutiveShortCaseStatements:
Enabled: true
AcrossEmptyLines: true
AcrossComments: true
AlignCaseColons: false
AllowShortCaseLabelsOnASingleLine: true
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: AllIfsAndElse
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: true
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterClass: true
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterObjCDeclaration: true
AfterStruct: true
AfterUnion: true
AfterExternBlock: true
BeforeCatch: true
BeforeElse: true
IndentBraces: false
SplitEmptyFunction: false
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Custom
BreakBeforeInheritanceComma: false
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 75
CommentPragmas: '^ pragma::'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: false
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
- Regex: ".*"
Priority: 1
IncludeIsMainRegex: "(Test)?$"
IndentCaseLabels: true
IndentPPDirectives: BeforeHash
IndentWidth: 4
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ""
MacroBlockEnd: ""
MaxEmptyLinesToKeep: 1
NamespaceIndentation: All
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Right
ReflowComments: true
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
13 changes: 9 additions & 4 deletions Abyssguard/Abyssguard.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
int main(int argc, char** argv) {
(void)argc;
(void)argv;
#include <Window.hpp>

return 0;
int main(int argc, char **argv)
{
(void)argc;
(void)argv;

Lightbleeder::Window::Get();

return 0;
}
4 changes: 3 additions & 1 deletion Abyssguard/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
set(ABYSSGUARD_FILE "Abyssguard.cpp")

add_executable(Stormsinger ${ABYSSGUARD_FILE})
add_dependencies(Stormsinger Lightbleeder)
target_link_libraries(Stormsinger Lightbleeder)
target_include_directories(Stormsinger PRIVATE "${CMAKE_SOURCE_DIR}/Lightbleeder/Include")
target_link_libraries(Stormsinger Lightbleeder)
11 changes: 11 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ project("Stormsinger" LANGUAGES CXX VERSION 0.1.0 DESCRIPTION

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/Stormsinger)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/Lightbleeder)
link_directories("${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}")

set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 20)
Expand All @@ -25,6 +26,16 @@ else()
endif()
endif()

include(FetchContent)

FetchContent_Declare(glfw GIT_REPOSITORY https://github.com/glfw/glfw.git GIT_TAG 3.3.4)
FetchContent_GetProperties(glfw)
if(NOT glfw_POPULATED)
FetchContent_Populate(glfw)
add_subdirectory("${glfw_SOURCE_DIR}" "${glfw_BINARY_DIR}" EXCLUDE_FROM_ALL)
endif()
include_directories("${glfw_SOURCE_DIR}/include")

add_subdirectory("Lightbleeder") # Pull in the Lightbleeder engine.
add_subdirectory("Sunbringer") # Pull in the Sunbringer asset library.
add_subdirectory("Abyssguard") # Pull in the game's code.
9 changes: 6 additions & 3 deletions Lightbleeder/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
set(LIGHTBLEEDER_SOURCES "Lightbleeder.cpp")
set(LIGHTBLEEDER_HEADERS "Lightbleeder.hpp")
set(LIGHTBLEEDER_SOURCES "Source/Lightbleeder.cpp" "Source/Window.cpp")
set(LIGHTBLEEDER_HEADERS "Include/Lightbleeder.hpp" "Source/Window.cpp")

add_library(Lightbleeder STATIC ${LIGHTBLEEDER_SOURCES} ${LIGHTBLEEDER_HEADERS})
add_library(Lightbleeder STATIC ${LIGHTBLEEDER_SOURCES} ${LIGHTBLEEDER_HEADERS})
add_dependencies(Lightbleeder glfw)
target_include_directories(Lightbleeder PRIVATE "Include")
target_link_libraries(Lightbleeder PUBLIC glfw3)
File renamed without changes.
35 changes: 35 additions & 0 deletions Lightbleeder/Include/Window.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#ifndef LIGHTBLEEDER_WINDOW_HPP
#define LIGHTBLEEDER_WINDOW_HPP

#include <GLFW/glfw3.h>

#include <string_view>

namespace Lightbleeder
{
class Window
{
private:
GLFWwindow *window;
Window();

public:
static Window &Get()
{
static Window instance;
return instance;
}

inline void SetTitle(const std::string_view title) noexcept
{
glfwSetWindowTitle(window, title.data());
}

// We don't want to allow copying or moving the window's data
// in any way.
Window(Window const &) = delete;
void operator=(const Window &) = delete;
};
}

#endif // LIGHTBLEEDER_WINDOW_HPP
File renamed without changes.
34 changes: 34 additions & 0 deletions Lightbleeder/Source/Window.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <Window.hpp>

#include <iostream>
#include <stdexcept>

namespace Lightbleeder
{
Window::Window()
{
glfwSetErrorCallback([](int error, const char *description) {
std::cout << "Error " << error << ": " << description
<< std::endl;
});

bool initialized = glfwInit();
if (!initialized)
// TODO: Log system.
throw std::runtime_error("Failed to initialize GLFW.");

glfwDefaultWindowHints();
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);

GLFWmonitor *monitor = glfwGetPrimaryMonitor();
const GLFWvidmode *mode = glfwGetVideoMode(monitor);

window = glfwCreateWindow(mode->width, mode->height,
"Lightbleeder", monitor, nullptr);
if (window == nullptr)
throw std::runtime_error("Failed to create window.");

while (!glfwWindowShouldClose(window)) { glfwPollEvents(); }
}
}
9 changes: 5 additions & 4 deletions Sunbringer/Sunbringer.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Executable that creates and formats the Sunbringer asset archive.

int main(int argc, char** argv) {
(void)argc;
(void)argv;
int main(int argc, char **argv)
{
(void)argc;
(void)argv;

return 0;
return 0;
}

0 comments on commit 0bb385f

Please sign in to comment.