From c9cf496c4947d7af67c16aa73096cffc094ccb40 Mon Sep 17 00:00:00 2001 From: Jorge Botarro Date: Thu, 16 Apr 2026 10:05:01 -0400 Subject: [PATCH] Simple empty window --- .clang-format | 21 ++++ .gitignore | 158 ++++++++++++++++++++++++++++++ .vscode/settings.json | 5 + CMakeLists.txt | 15 +++ cmake/chk.cmake | 105 ++++++++++++++++++++ cmake/deps.cmake | 15 +++ include/chk/Launcher/Launcher.hpp | 40 ++++++++ src/chk/Launcher/Launcher.cpp | 41 ++++++++ src/chk/Launcher/Main.cpp | 54 ++++++++++ 9 files changed, 454 insertions(+) create mode 100644 .clang-format create mode 100644 .vscode/settings.json create mode 100644 CMakeLists.txt create mode 100644 cmake/chk.cmake create mode 100644 cmake/deps.cmake create mode 100644 include/chk/Launcher/Launcher.hpp create mode 100644 src/chk/Launcher/Launcher.cpp create mode 100644 src/chk/Launcher/Main.cpp diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..a827391 --- /dev/null +++ b/.clang-format @@ -0,0 +1,21 @@ +--- +BasedOnStyle: LLVM +AlignConsecutiveAssignments: + Enabled: true +AlignConsecutiveBitFields: + Enabled: true +AlignConsecutiveDeclarations: + Enabled: true +AlignConsecutiveMacros: + Enabled: true +AlignConsecutiveShortCaseStatements: + Enabled: true +AllowShortBlocksOnASingleLine: Always +AllowShortCaseLabelsOnASingleLine: true +AllowShortIfStatementsOnASingleLine: AllIfsAndElse +AllowShortLoopsOnASingleLine: true +ColumnLimit: 120 +IndentCaseLabels: true +IndentPPDirectives: AfterHash +PointerAlignment: Left +LambdaBodyIndentation: OuterScope \ No newline at end of file diff --git a/.gitignore b/.gitignore index 8c2b884..946afa1 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,161 @@ # Built Visual Studio Code Extensions *.vsix +# Ignore build output directories +[Bb]uild*/ +.[Cc]ache/ + +# +# From macOS gitignore template +# + +# General +.DS_Store +__MACOSX/ +.AppleDouble +.LSOverride +Icon[] + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +# +# From Windows gitignore template +# + +# Windows thumbnail cache files +Thumbs.db +Thumbs.db:encryptable +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# +# From Linux gitignore template +# + +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# Metadata left by Dolphin file manager, which comes with KDE Plasma +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +# Log files created by default by the nohup command +nohup.out + +# +# From VSCode gitignore template +# + +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +!.vscode/*.code-snippets +!*.code-workspace + +# Built Visual Studio Code Extensions +*.vsix + +# +# From C gitignore template +# + +# Prerequisites +*.d + +# Object files +*.o +*.ko +*.obj +*.elf + +# Linker output +*.ilk +*.map +*.exp + +# Precompiled Headers +*.gch +*.pch + +# Libraries +*.lib +*.a +*.la +*.lo + +# Shared objects (inc. Windows DLLs) +*.dll +*.so +*.so.* +*.dylib + +# Executables +*.exe +*.out +*.app +*.i*86 +*.x86_64 +*.hex + +# Debug files +*.dSYM/ +*.su +*.idb +*.pdb + +# Kernel Module Compile Results +*.mod* +*.cmd +.tmp_versions/ +modules.order +Module.symvers +Mkfile.old +dkms.conf + +# debug information files +*.dwo \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..cf0ed7b --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "editor.tabSize": 2, + "editor.formatOnSave": true, + "editor.formatOnPaste": true, +} \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..0de8557 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,15 @@ +cmake_minimum_required(VERSION 3.30) +project(chkEngine LANGUAGES CXX VERSION 0.1.0) + +include(cmake/deps.cmake) +include(cmake/chk.cmake) + +chk_add(NAME Launcher KIND exe + HDR + "Launcher.hpp" + SRC + "Launcher.cpp" + "Main.cpp" + PUB + SDL3pp::SDL3pp +) diff --git a/cmake/chk.cmake b/cmake/chk.cmake new file mode 100644 index 0000000..8f114a5 --- /dev/null +++ b/cmake/chk.cmake @@ -0,0 +1,105 @@ +include_guard() + +include(GenerateExportHeader) + +function(chk_add) + cmake_parse_arguments(CHK "" "NAME;KIND;PREFIX;SRCBASE;BINBASE" "SRC;HDR;PUB;PRV" ${ARGN}) + + set(CHK_IS_LIB FALSE) + set(CHK_IS_EXE FALSE) + + if(NOT CHK_NAME) + message(FATAL_ERROR "NAME is required") + endif() + if(CHK_KIND STREQUAL "lib") + set(CHK_IS_LIB TRUE) + elseif(CHK_KIND STREQUAL "exe") + set(CHK_IS_EXE TRUE) + elseif(NOT CHK_KIND) + message(FATAL_ERROR "KIND is required") + else() + message(FATAL_ERROR "KIND must be either \"lib\" or \"exe\". was \"${CHK_KIND}\"") + endif() + if(NOT CHK_PREFIX) + set(CHK_PREFIX "chk") + endif() + if(NOT CHK_SRCBASE) + set(CHK_SRCBASE "${CMAKE_CURRENT_SOURCE_DIR}") + endif() + if(NOT CHK_BINBASE) + set(CHK_BINBASE "${CMAKE_CURRENT_BINARY_DIR}") + endif() + + set(CHK_TARGET "${CHK_PREFIX}_${CHK_NAME}") + string(TOUPPER "${CHK_NAME}" CHK_NAME_CAPS) + string(TOUPPER "${CHK_PREFIX}" CHK_PREFIX_CAPS) + string(TOUPPER "${CHK_TARGET}" CHK_TARGET_CAPS) + + list(TRANSFORM CHK_SRC PREPEND "${CHK_SRCBASE}/src/${CHK_PREFIX}/${CHK_NAME}/") + list(TRANSFORM CHK_HDR PREPEND "${CHK_SRCBASE}/include/${CHK_PREFIX}/${CHK_NAME}/") + + if(CHK_IS_LIB) + add_library(${CHK_TARGET}) + add_library(${CHK_PREFIX}::${CHK_NAME} ALIAS ${CHK_TARGET}) + + set(CHK_EXP_EXT "hpp") + set(CHK_EXP_DIR ${CHK_BINBASE}/include/${CHK_PREFIX}/${CHK_NAME}) + set(CHK_EXP_HDR ${CHK_EXP_DIR}/Api.${CHK_EXP_EXT}) + + generate_export_header(${CHK_TARGET} + EXPORT_FILE_NAME ${CHK_EXP_HDR} + EXPORT_MACRO_NAME ${CHK_NAME_CAPS}_API + NO_EXPORT_MACRO_NAME ${CHK_NAME_CAPS}_LOCAL + PREFIX_NAME ${CHK_PREFIX_CAPS}_ + ) + + list(APPEND CHK_HDR ${CHK_EXP_HDR}) + elseif(CHK_IS_EXE) + add_executable(${CHK_TARGET}) + endif() + + target_sources(${CHK_TARGET} + PUBLIC + FILE_SET "${CHK_PREFIX}_${CHK_NAME}_headers" + TYPE HEADERS + BASE_DIRS + "${CHK_SRCBASE}/include" + "${CHK_BINBASE}/include" + FILES + ${CHK_HDR} + + PRIVATE + ${CHK_SRC} + ) + + target_include_directories(${CHK_TARGET} + PUBLIC + $ + $ + $ + ) + + target_link_libraries(${CHK_TARGET} + PUBLIC + ${CHK_PUB} + + PRIVATE + ${CHK_PRV} + ) + + target_compile_features(${CHK_TARGET} PUBLIC cxx_std_23) + + # Set linker language to C++ + set_target_properties(${CHK_TARGET} PROPERTIES LINKER_LANGUAGE CXX) + + # Copy DLLs alongside the executable on Windows + if (WIN32 AND CHK_IS_EXE) + add_custom_command(TARGET ${CHK_TARGET} POST_BUILD + COMMAND + ${CMAKE_COMMAND} -E copy_if_different + $ + $ + COMMAND_EXPAND_LISTS + ) + endif() +endfunction(chk_add) diff --git a/cmake/deps.cmake b/cmake/deps.cmake new file mode 100644 index 0000000..a0e62c3 --- /dev/null +++ b/cmake/deps.cmake @@ -0,0 +1,15 @@ +include(FetchContent) + +set(SDL3PP_FORCE_BUNDLED ON CACHE BOOL "") +set(SDL3PP_ENABLE_IMAGE OFF CACHE BOOL "") +set(SDL3PP_ENABLE_TTF OFF CACHE BOOL "") +set(SDL3PP_ENABLE_MIXER OFF CACHE BOOL "") +set(SDL3PP_BUILD_EXAMPLES OFF CACHE BOOL "") +set(SDL3PP_BUILD_TESTS OFF CACHE BOOL "") +set(SDL3PP_GEN_DOCS OFF CACHE BOOL "") + +FetchContent_Declare(SDL3ppExternal + URL https://github.com/talesm/SDL3pp/releases/download/0.9.2/SDL3pp-0.9.2.tar.gz + OVERRIDE_FIND_PACKAGE +) +FetchContent_MakeAvailable(SDL3ppExternal) diff --git a/include/chk/Launcher/Launcher.hpp b/include/chk/Launcher/Launcher.hpp new file mode 100644 index 0000000..44ff6c1 --- /dev/null +++ b/include/chk/Launcher/Launcher.hpp @@ -0,0 +1,40 @@ +#pragma once + +#include + +#include + +namespace chk { + +struct LauncherState { + bool running : 1 = false; +}; + +class Launcher { +public: + Launcher(const std::string& title, int w = 1280, int h = 720); + ~Launcher(); + + // Disable copy and move semantics + Launcher(const Launcher&) = delete; + Launcher(Launcher&&) = delete; + Launcher& operator=(const Launcher&) = delete; + Launcher& operator=(Launcher&&) = delete; + + void Step(); + void Event(const SDL::Event& event); + + auto& Is() const { return _is; } + auto& Was() const { return _was; } + + auto& Win() { return _win; } + auto& Ctx() { return _ctx; } + +private: + LauncherState _is, _was; + + SDL::Window _win = nullptr; + SDL::Renderer _ctx = nullptr; +}; + +} // namespace chk diff --git a/src/chk/Launcher/Launcher.cpp b/src/chk/Launcher/Launcher.cpp new file mode 100644 index 0000000..bc43ed2 --- /dev/null +++ b/src/chk/Launcher/Launcher.cpp @@ -0,0 +1,41 @@ +#include + +namespace chk { + +Launcher::Launcher(const std::string& title, int w, int h) { + auto winFlags = SDL::WINDOW_HIDDEN; + winFlags |= SDL::WINDOW_RESIZABLE; + winFlags |= SDL::WINDOW_HIGH_PIXEL_DENSITY; + + _win = SDL::Window(title, SDL::Point{w, h}, winFlags); + _ctx = SDL::Renderer(Win()); + + this->Step(); + _win.Show(); + + _is.running = true; +} + +Launcher::~Launcher() = default; + +void Launcher::Step() { + try { + Ctx().SetTarget(nullptr); + Ctx().SetDrawColorFloat({0.1f, 0.2f, 0.3f, 1.0f}); + Ctx().RenderClear(); + + Ctx().Present(); + + _was = _is; + } catch (const SDL::Error& e) { SDL::Log("[SDL] {}", e.what()); } +} + +void Launcher::Event(const SDL::Event& event) { + switch (event.type) { + case SDL::EVENT_QUIT: { + _is.running = false; + } break; + } +} + +} // namespace chk diff --git a/src/chk/Launcher/Main.cpp b/src/chk/Launcher/Main.cpp new file mode 100644 index 0000000..02a65e9 --- /dev/null +++ b/src/chk/Launcher/Main.cpp @@ -0,0 +1,54 @@ +#include + +#define SDL3PP_MAIN_USE_CALLBACKS +#include + +#include + +namespace chk { + +class EntryPoint { +public: + EntryPoint() { + SDL::SetAppMetadata("chkEngine", "0.1.0", "net.jp.chk.engine"); + SDL::Init(SDL::INIT_VIDEO); + _launcher = std::make_unique("chkEngine"); + } + + ~EntryPoint() = default; + + SDL::AppResult Iterate() { + SDL::AppResult result = SDL::APP_SUCCESS; + + try { + _launcher->Step(); + result = _launcher->Is().running ? SDL::APP_CONTINUE : SDL::APP_SUCCESS; + } catch (const SDL::Error& e) { + SDL::Log("[SDL] {}", e.what()); + result = SDL::APP_FAILURE; + } + + return result; + } + + SDL::AppResult Event(const SDL::Event& event) { + SDL::AppResult result = SDL::APP_SUCCESS; + + try { + _launcher->Event(event); + result = _launcher->Is().running ? SDL::APP_CONTINUE : SDL::APP_SUCCESS; + } catch (const SDL::Error& e) { + SDL::Log("[SDL] {}", e.what()); + result = SDL::APP_FAILURE; + } + + return result; + } + +private: + std::unique_ptr _launcher; +}; + +} // namespace chk + +SDL3PP_DEFINE_CALLBACKS(chk::EntryPoint);