Kajetan Johannes Hammerle 1 өдөр өмнө
commit
fd8f57801e

+ 6 - 0
.clangd

@@ -0,0 +1,6 @@
+CompileFlags:
+  Add: [-ferror-limit=0]
+  CompilationDatabase: ./build_debug/
+Diagnostics:
+  Suppress:
+    - module_decl_not_at_start

+ 11 - 0
.gitignore

@@ -0,0 +1,11 @@
+build_debug
+build_profile
+build_release
+install
+profile
+compiler
+tasks_settings
+.cache
+*.swp
+*.swo
+*.spv

+ 9 - 0
.gitmodules

@@ -0,0 +1,9 @@
+[submodule "stb"]
+	path = stb
+	url = https://github.com/nothings/stb.git
+[submodule "enet"]
+	path = enet
+	url = https://github.com/zpl-c/enet.git
+[submodule "glfw"]
+	path = glfw
+	url = https://github.com/glfw/glfw.git

+ 50 - 0
CMakeLists.txt

@@ -0,0 +1,50 @@
+cmake_minimum_required(VERSION 3.28)
+project(gamingcore CXX)
+
+set(CMAKE_CXX_STANDARD 23)
+
+set(SRC
+    "src/Main.cpp"
+)
+
+if("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
+    set(LINK_OPTIONS "")
+    set(LOG_LEVEL 2)
+    set(DEFINITIONS CHECK_MEMORY)
+else()
+    set(DEFINITIONS ERROR_SIMULATOR CHECK_MEMORY DEBUG_VULKAN)
+    set(LOG_LEVEL 4)
+endif()
+
+if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
+    include("cmake/gcc_warnings.cmake")
+elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
+    include("cmake/clang_warnings.cmake")
+endif()
+include("${CMAKE_INSTALL_PREFIX}/cmake/add_modules.cmake")
+
+add_executable(table ${SRC})
+target_compile_options(table PUBLIC
+    ${WARNINGS}
+    -fdiagnostics-color=always
+)
+target_compile_definitions(table
+    PRIVATE LOG_LEVEL=${LOG_LEVEL}
+    PUBLIC ${DEFINITIONS}
+)
+target_link_libraries(table PRIVATE core)
+add_modules(
+    TARGET table
+    NAME core_modules
+    PREFIX ${CMAKE_INSTALL_PREFIX}/
+    FILES ${core_modules}
+)
+add_modules(
+    TARGET table
+    NAME table_private_modules
+    FILES
+    src/Module.cppm
+)
+target_link_directories(table
+    PUBLIC ${CMAKE_INSTALL_PREFIX}/lib
+)

+ 61 - 0
cmake/clang_warnings.cmake

@@ -0,0 +1,61 @@
+set(WARNINGS
+    -Wall
+    -Walloca
+    -Warray-parameter
+    -Wbad-function-cast
+    -Wcast-qual
+    -Wconditional-uninitialized
+    -Wconversion
+    -Wdate-time
+    -Wdisabled-optimization
+    -Wdouble-promotion
+    -Wenum-compare
+    -Wenum-conversion
+    -Werror
+    -Wextra
+    -Wextra-semi-stmt
+    -Wfloat-equal
+    -Wformat=2
+    -Wframe-larger-than=8388608
+    -Winfinite-recursion
+    -Winit-self
+    -Winvalid-pch
+    -Wlarger-than=1073741824
+    -Wmissing-braces
+    -Wmissing-declarations
+    -Wmissing-include-dirs
+    -Wmissing-noreturn
+    -Wmissing-prototypes
+    -Wmissing-variable-declarations
+    -Wmultichar
+    -Wnarrowing
+    -Wnested-externs
+    -Wnull-dereference
+    -Wold-style-definition
+    -Woverlength-strings
+    -Wredundant-decls
+    -Wshadow
+    -Wsign-conversion
+    -Wstack-protector
+    -Wstrict-overflow=2
+    -Wstrict-prototypes
+    -Wundef
+    -Wunreachable-code
+    -Wvla
+    -Wwrite-strings
+    -pedantic
+    -pedantic-errors
+
+    -Wno-missing-designated-field-initializers
+)
+
+if(0)
+    set(WARNINGS ${WARNINGS}
+        -Weverything
+        -Wno-unsafe-buffer-usage
+        -Wno-c++98-compat
+        -Wno-declaration-after-statement
+        -Wno-pre-c2x-compat
+        -Wno-padded
+    )
+endif()

+ 94 - 0
cmake/gcc_warnings.cmake

@@ -0,0 +1,94 @@
+set(WARNINGS
+    -Waligned-new=all
+    -Wall
+    -Walloc-zero
+    -Walloca
+    -Wanalyzer-too-complex
+    -Warith-conversion
+    -Warray-bounds=2
+    -Warray-parameter
+    -Wattribute-alias=2
+    -Wbidi-chars=any
+    -Wcast-align=strict
+    -Wcast-qual
+    -Wcatch-value=3
+    -Wcomma-subscript
+    -Wconditionally-supported
+    -Wconversion
+    -Wctad-maybe-unsupported
+    -Wctor-dtor-privacy
+    -Wdate-time
+    -Wdeprecated-copy-dtor
+    -Wdeprecated-enum-enum-conversion
+    -Wdeprecated-enum-float-conversion
+    -Wdisabled-optimization
+    -Wdouble-promotion
+    -Wduplicated-branches
+    -Wduplicated-cond
+    -Weffc++
+    -Wenum-compare
+    -Wenum-conversion
+    -Werror
+    -Wextra
+    -Wextra-semi
+    -Wfloat-equal
+    -Wformat-overflow=2
+    -Wformat-signedness
+    -Wformat-truncation=2
+    -Wformat=2
+    -Wframe-larger-than=8388608
+    -Wimplicit-fallthrough=5
+    -Winfinite-recursion
+    -Winit-self
+    -Winvalid-constexpr
+    -Winvalid-imported-macros
+    -Winvalid-pch
+    -Winvalid-utf8
+    -Wlarger-than=1073741824
+    -Wlogical-op
+    -Wmismatched-tags
+    -Wmissing-braces
+    -Wmissing-declarations
+    -Wmissing-include-dirs
+    -Wmultichar
+    -Wmultiple-inheritance
+    -Wnoexcept
+    -Wnon-virtual-dtor
+    -Wnormalized=nfkc
+    -Wnull-dereference
+    -Wold-style-cast
+    -Woverlength-strings
+    -Woverloaded-virtual
+    -Wplacement-new=2
+    -Wredundant-decls
+    -Wredundant-tags
+    -Wregister
+    -Wshadow
+    -Wshift-overflow=2
+    -Wsign-conversion
+    -Wsign-promo
+    -Wstack-protector
+    -Wstack-usage=8388608
+    -Wstrict-null-sentinel
+    -Wstrict-overflow=2
+    -Wstringop-overflow=4
+    -Wsuggest-final-methods
+    -Wsuggest-final-types
+    -Wsuggest-override
+    -Wsynth
+    -Wtrampolines
+    -Wtrivial-auto-var-init
+    -Wundef
+    -Wunreachable-code
+    -Wunused-const-variable=2
+    -Wuse-after-free=3
+    -Wvirtual-inheritance
+    -Wvla
+    -Wvolatile
+    -Wwrite-strings
+    -Wzero-as-null-pointer-constant
+    -pedantic
+    -pedantic-errors
+
+    -Wno-missing-field-initializers
+)

+ 129 - 0
src/Main.cpp

@@ -0,0 +1,129 @@
+#include <stdio.h>
+#include <string.h>
+
+import Core.Terminal;
+import Core.TerminalConstants;
+import Core.List;
+import Core.Math;
+import Core.ToString;
+import Core.Logger;
+
+using SizeVector = Core::Vector<2, size_t>;
+
+struct Cell {
+    Core::String<16> content{};
+};
+
+static bool running = true;
+static SizeVector size = {20, 10};
+static Core::List<Cell> cells;
+static SizeVector cursorPosition{0, 0};
+
+static void init() {
+    cells.resize(size[0] * size[1]);
+    for(Cell& c : cells) {
+        c.content.format(" ");
+    }
+}
+
+static Cell& getCell(size_t x, size_t y) {
+    return cells[y * size[0] + x];
+}
+
+static Cell& getCell(const SizeVector& v) {
+    return getCell(v[0], v[1]);
+}
+
+static void print(const char* s) {
+    fputs(s, stdout);
+}
+
+static size_t getColumnWidth(size_t x) {
+    size_t w = 0;
+    for(size_t y = 0; y < size[1]; y++) {
+        Cell& c = getCell(x, y);
+        w = Core::max(w, strlen(c.content));
+    }
+    return w;
+}
+
+static void render() {
+    static constexpr const char* lc[2] = {
+        Core::Terminal::BG_WHITE, Core::Terminal::BG_BRIGHT_WHITE};
+    Core::clearTerminal();
+    Core::resetCursor();
+    Core::List<size_t> columnWidths;
+    for(size_t x = 0; x < size[0]; x++) {
+        columnWidths.add(getColumnWidth(x));
+    }
+    for(size_t y = 0; y < size[1]; y++) {
+        print(lc[y & 1]);
+        print("|");
+        for(size_t x = 0; x < size[0]; x++) {
+            Cell& c = getCell(x, y);
+            if(cursorPosition[0] == x && cursorPosition[1] == y) {
+                fputs(Core::Terminal::BG_BRIGHT_BLUE, stdout);
+            }
+            c.content.print();
+            size_t filler = columnWidths[x] - strlen(c.content);
+            while(filler > 0) {
+                filler--;
+                putchar(' ');
+            }
+            if(cursorPosition[0] == x && cursorPosition[1] == y) {
+                fputs(lc[y & 1], stdout);
+            }
+            print("|");
+        }
+        putchar('\n');
+    }
+    fputs(Core::Terminal::RESET, stdout);
+}
+
+static void loop(u64 input) {
+    // Core::IntVector2 size = Core::getTerminalSize();
+    if(input == 'q') {
+        running = false;
+        return;
+    } else if(input == Core::Terminal::KEY_ARROW_LEFT) {
+        if(cursorPosition[0] > 0) {
+            cursorPosition += SizeVector{-1, 0};
+        }
+    } else if(input == Core::Terminal::KEY_ARROW_RIGHT) {
+        if(cursorPosition[0] < size[0] - 1) {
+            cursorPosition += SizeVector{1, 0};
+        }
+    } else if(input == Core::Terminal::KEY_ARROW_UP) {
+        if(cursorPosition[1] > 0) {
+            cursorPosition += SizeVector{0, -1};
+        }
+    } else if(input == Core::Terminal::KEY_ARROW_DOWN) {
+        if(cursorPosition[1] < size[1] - 1) {
+            cursorPosition += SizeVector{0, 1};
+        }
+    } else {
+        Cell& c = getCell(cursorPosition);
+        c.content.add(static_cast<char>(input));
+    }
+    render();
+}
+
+int main() {
+    Core::enterAlternativeTerminal();
+    if(Core::enterRawTerminal()) {
+        return 0;
+    }
+    init();
+    render();
+    while(running) {
+        u64 u = Core::getRawChar();
+        if(u != 0) {
+            loop(u);
+        }
+    }
+    if(Core::leaveRawTerminal()) {
+        puts("Could not reset terminal.");
+    }
+    Core::leaveAlternativeTerminal();
+    return 0;
+}

+ 3 - 0
src/Module.cppm

@@ -0,0 +1,3 @@
+module;
+
+export module Dummy;