Simple empty window

This commit is contained in:
2026-04-16 10:05:01 -04:00
parent 09623ef864
commit c9cf496c49
9 changed files with 454 additions and 0 deletions

21
.clang-format Normal file
View File

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

158
.gitignore vendored
View File

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

5
.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,5 @@
{
"editor.tabSize": 2,
"editor.formatOnSave": true,
"editor.formatOnPaste": true,
}

15
CMakeLists.txt Normal file
View File

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

105
cmake/chk.cmake Normal file
View File

@@ -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
$<BUILD_INTERFACE:${CHK_SRCBASE}/include>
$<BUILD_INTERFACE:${CHK_BINBASE}/include>
$<INSTALL_INTERFACE:include>
)
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
$<TARGET_RUNTIME_DLLS:${CHK_TARGET}>
$<TARGET_FILE_DIR:${CHK_TARGET}>
COMMAND_EXPAND_LISTS
)
endif()
endfunction(chk_add)

15
cmake/deps.cmake Normal file
View File

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

View File

@@ -0,0 +1,40 @@
#pragma once
#include <SDL3pp/SDL3pp.h>
#include <string>
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

View File

@@ -0,0 +1,41 @@
#include <chk/Launcher/Launcher.hpp>
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

54
src/chk/Launcher/Main.cpp Normal file
View File

@@ -0,0 +1,54 @@
#include <chk/Launcher/Launcher.hpp>
#define SDL3PP_MAIN_USE_CALLBACKS
#include <SDL3pp/SDL3pp_main.h>
#include <memory>
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<chk::Launcher>("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<chk::Launcher> _launcher;
};
} // namespace chk
SDL3PP_DEFINE_CALLBACKS(chk::EntryPoint);