From d06c7ebeb630f737584d1a1c711f99b5d4086a27 Mon Sep 17 00:00:00 2001 From: Brett Laptop Date: Mon, 10 Jul 2023 18:45:43 -0400 Subject: [PATCH 1/6] String buffer --- CMakeLists.txt | 4 ++-- CMakeSettings.json | 0 LICENSE | 0 README.md | 0 design.txt | 0 icon.png | Bin icon_large.png | Bin icon_small.png | Bin include/blt/config.h.in | 0 include/blt/math/averages.h | 0 include/blt/math/log_util.h | 0 include/blt/math/math.h | 0 include/blt/math/matrix.h | 0 include/blt/math/vectors.h | 0 include/blt/nbt/nbt.h | 0 include/blt/nbt/nbt_block.h | 0 include/blt/profiling/profiler.h | 0 include/blt/std/binary_tree.h | 0 include/blt/std/filesystem.h | 0 include/blt/std/format.h | 0 include/blt/std/hash_map.h | 0 include/blt/std/loader.h | 0 include/blt/std/logging.h | 0 include/blt/std/map.h | 0 include/blt/std/memory.h | 0 include/blt/std/queue.h | 0 include/blt/std/random.h | 0 include/blt/std/string.h | 25 +++++++++++++++++++++++++ include/blt/std/system.h | 0 include/blt/std/time.h | 0 include/blt/window/window.h | 0 src/blt/nbt/nbt.cpp | 0 src/blt/nbt/nbt_block.cpp | 0 src/blt/profiling/profiler.cpp | 0 src/blt/std/filesystem.cpp | 0 src/blt/std/format.cpp | 0 src/blt/std/loader.cpp | 0 src/blt/std/logging.cpp | 0 src/blt/std/string.cpp | 29 +++++++++++++++++++++++++++++ src/blt/std/system.cpp | 0 src/blt/window/window.cpp | 0 src/tests/binary_trees.h | 0 src/tests/hashmap_tests.h | 0 src/tests/logging.h | 0 src/tests/main.cpp | 0 src/tests/nbt_tests.h | 0 src/tests/profiling_tests.h | 0 src/tests/queue_tests.h | 0 48 files changed, 56 insertions(+), 2 deletions(-) mode change 100644 => 100755 CMakeLists.txt mode change 100644 => 100755 CMakeSettings.json mode change 100644 => 100755 LICENSE mode change 100644 => 100755 README.md mode change 100644 => 100755 design.txt mode change 100644 => 100755 icon.png mode change 100644 => 100755 icon_large.png mode change 100644 => 100755 icon_small.png mode change 100644 => 100755 include/blt/config.h.in mode change 100644 => 100755 include/blt/math/averages.h mode change 100644 => 100755 include/blt/math/log_util.h mode change 100644 => 100755 include/blt/math/math.h mode change 100644 => 100755 include/blt/math/matrix.h mode change 100644 => 100755 include/blt/math/vectors.h mode change 100644 => 100755 include/blt/nbt/nbt.h mode change 100644 => 100755 include/blt/nbt/nbt_block.h mode change 100644 => 100755 include/blt/profiling/profiler.h mode change 100644 => 100755 include/blt/std/binary_tree.h mode change 100644 => 100755 include/blt/std/filesystem.h mode change 100644 => 100755 include/blt/std/format.h mode change 100644 => 100755 include/blt/std/hash_map.h mode change 100644 => 100755 include/blt/std/loader.h mode change 100644 => 100755 include/blt/std/logging.h mode change 100644 => 100755 include/blt/std/map.h mode change 100644 => 100755 include/blt/std/memory.h mode change 100644 => 100755 include/blt/std/queue.h mode change 100644 => 100755 include/blt/std/random.h mode change 100644 => 100755 include/blt/std/string.h mode change 100644 => 100755 include/blt/std/system.h mode change 100644 => 100755 include/blt/std/time.h mode change 100644 => 100755 include/blt/window/window.h mode change 100644 => 100755 src/blt/nbt/nbt.cpp mode change 100644 => 100755 src/blt/nbt/nbt_block.cpp mode change 100644 => 100755 src/blt/profiling/profiler.cpp mode change 100644 => 100755 src/blt/std/filesystem.cpp mode change 100644 => 100755 src/blt/std/format.cpp mode change 100644 => 100755 src/blt/std/loader.cpp mode change 100644 => 100755 src/blt/std/logging.cpp create mode 100755 src/blt/std/string.cpp mode change 100644 => 100755 src/blt/std/system.cpp mode change 100644 => 100755 src/blt/window/window.cpp mode change 100644 => 100755 src/tests/binary_trees.h mode change 100644 => 100755 src/tests/hashmap_tests.h mode change 100644 => 100755 src/tests/logging.h mode change 100644 => 100755 src/tests/main.cpp mode change 100644 => 100755 src/tests/nbt_tests.h mode change 100644 => 100755 src/tests/profiling_tests.h mode change 100644 => 100755 src/tests/queue_tests.h diff --git a/CMakeLists.txt b/CMakeLists.txt old mode 100644 new mode 100755 index e126a88..04af8bd --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,8 @@ option(BUILD_NBT "Build the BLT NBT + eNBT extension" ON) option(BUILD_TESTS "Build the BLT test set" OFF) option(BLT_ENABLE_LOGGING "Enable blt::logging" ON) +configure_file(include/blt/config.h.in config/blt/config.h @ONLY) + if(${BUILD_STD} OR ${BUILD_PROFILING}) file(GLOB_RECURSE STD_FILES "${CMAKE_CURRENT_SOURCE_DIR}/src/blt/std/*.cpp") else() @@ -44,8 +46,6 @@ message("Profiler Files ${PROFILING_FILES}") message("Source: ${CMAKE_SOURCE_DIR}") message("Current Source: ${CMAKE_CURRENT_SOURCE_DIR}") -configure_file(include/blt/config.h.in config/blt/config.h @ONLY) - add_library(BLT ${STD_FILES} ${PROFILING_FILES} ${NBT_FILES}) target_include_directories(BLT PUBLIC include/) diff --git a/CMakeSettings.json b/CMakeSettings.json old mode 100644 new mode 100755 diff --git a/LICENSE b/LICENSE old mode 100644 new mode 100755 diff --git a/README.md b/README.md old mode 100644 new mode 100755 diff --git a/design.txt b/design.txt old mode 100644 new mode 100755 diff --git a/icon.png b/icon.png old mode 100644 new mode 100755 diff --git a/icon_large.png b/icon_large.png old mode 100644 new mode 100755 diff --git a/icon_small.png b/icon_small.png old mode 100644 new mode 100755 diff --git a/include/blt/config.h.in b/include/blt/config.h.in old mode 100644 new mode 100755 diff --git a/include/blt/math/averages.h b/include/blt/math/averages.h old mode 100644 new mode 100755 diff --git a/include/blt/math/log_util.h b/include/blt/math/log_util.h old mode 100644 new mode 100755 diff --git a/include/blt/math/math.h b/include/blt/math/math.h old mode 100644 new mode 100755 diff --git a/include/blt/math/matrix.h b/include/blt/math/matrix.h old mode 100644 new mode 100755 diff --git a/include/blt/math/vectors.h b/include/blt/math/vectors.h old mode 100644 new mode 100755 diff --git a/include/blt/nbt/nbt.h b/include/blt/nbt/nbt.h old mode 100644 new mode 100755 diff --git a/include/blt/nbt/nbt_block.h b/include/blt/nbt/nbt_block.h old mode 100644 new mode 100755 diff --git a/include/blt/profiling/profiler.h b/include/blt/profiling/profiler.h old mode 100644 new mode 100755 diff --git a/include/blt/std/binary_tree.h b/include/blt/std/binary_tree.h old mode 100644 new mode 100755 diff --git a/include/blt/std/filesystem.h b/include/blt/std/filesystem.h old mode 100644 new mode 100755 diff --git a/include/blt/std/format.h b/include/blt/std/format.h old mode 100644 new mode 100755 diff --git a/include/blt/std/hash_map.h b/include/blt/std/hash_map.h old mode 100644 new mode 100755 diff --git a/include/blt/std/loader.h b/include/blt/std/loader.h old mode 100644 new mode 100755 diff --git a/include/blt/std/logging.h b/include/blt/std/logging.h old mode 100644 new mode 100755 diff --git a/include/blt/std/map.h b/include/blt/std/map.h old mode 100644 new mode 100755 diff --git a/include/blt/std/memory.h b/include/blt/std/memory.h old mode 100644 new mode 100755 diff --git a/include/blt/std/queue.h b/include/blt/std/queue.h old mode 100644 new mode 100755 diff --git a/include/blt/std/random.h b/include/blt/std/random.h old mode 100644 new mode 100755 diff --git a/include/blt/std/string.h b/include/blt/std/string.h old mode 100644 new mode 100755 index 69412dc..cea9f6a --- a/include/blt/std/string.h +++ b/include/blt/std/string.h @@ -16,6 +16,30 @@ namespace blt::string { + class StringBuffer { + private: + const size_t BLOCK_SIZE = 4096; + size_t front = 0; + size_t size = 0; + char* characterBuffer = nullptr; + + void expand(); + public: + void trim(); + std::string toString(); + + StringBuffer(){ + characterBuffer = static_cast(malloc(BLOCK_SIZE)); + size = BLOCK_SIZE; + } + + StringBuffer& operator<<(char c); + + ~StringBuffer() { + free(characterBuffer); + } + }; + static inline bool starts_with(const std::string& string, const std::string& search){ if (search.length() > string.length()) return false; @@ -153,6 +177,7 @@ namespace blt::string { trim(s); return s; } + } #endif //BLT_STRING_H diff --git a/include/blt/std/system.h b/include/blt/std/system.h old mode 100644 new mode 100755 diff --git a/include/blt/std/time.h b/include/blt/std/time.h old mode 100644 new mode 100755 diff --git a/include/blt/window/window.h b/include/blt/window/window.h old mode 100644 new mode 100755 diff --git a/src/blt/nbt/nbt.cpp b/src/blt/nbt/nbt.cpp old mode 100644 new mode 100755 diff --git a/src/blt/nbt/nbt_block.cpp b/src/blt/nbt/nbt_block.cpp old mode 100644 new mode 100755 diff --git a/src/blt/profiling/profiler.cpp b/src/blt/profiling/profiler.cpp old mode 100644 new mode 100755 diff --git a/src/blt/std/filesystem.cpp b/src/blt/std/filesystem.cpp old mode 100644 new mode 100755 diff --git a/src/blt/std/format.cpp b/src/blt/std/format.cpp old mode 100644 new mode 100755 diff --git a/src/blt/std/loader.cpp b/src/blt/std/loader.cpp old mode 100644 new mode 100755 diff --git a/src/blt/std/logging.cpp b/src/blt/std/logging.cpp old mode 100644 new mode 100755 diff --git a/src/blt/std/string.cpp b/src/blt/std/string.cpp new file mode 100755 index 0000000..0dba300 --- /dev/null +++ b/src/blt/std/string.cpp @@ -0,0 +1,29 @@ +// +// Created by brett on 7/9/23. +// +#include + +void blt::string::StringBuffer::expand() { + size_t multiplier = size / BLOCK_SIZE; + auto newSize = BLOCK_SIZE * (multiplier * 2); + characterBuffer = static_cast(realloc(characterBuffer, newSize)); + size = newSize; +} + +void blt::string::StringBuffer::trim() { + characterBuffer = static_cast(realloc(characterBuffer, front+1)); + size = front+1; + characterBuffer[front] = '\0'; +} + +blt::string::StringBuffer& blt::string::StringBuffer::operator<<(char c) { + characterBuffer[front++] = c; + if (front > size) + expand(); + return *this; +} + +std::string blt::string::StringBuffer::toString() { + trim(); + return std::string{characterBuffer}; +} diff --git a/src/blt/std/system.cpp b/src/blt/std/system.cpp old mode 100644 new mode 100755 diff --git a/src/blt/window/window.cpp b/src/blt/window/window.cpp old mode 100644 new mode 100755 diff --git a/src/tests/binary_trees.h b/src/tests/binary_trees.h old mode 100644 new mode 100755 diff --git a/src/tests/hashmap_tests.h b/src/tests/hashmap_tests.h old mode 100644 new mode 100755 diff --git a/src/tests/logging.h b/src/tests/logging.h old mode 100644 new mode 100755 diff --git a/src/tests/main.cpp b/src/tests/main.cpp old mode 100644 new mode 100755 diff --git a/src/tests/nbt_tests.h b/src/tests/nbt_tests.h old mode 100644 new mode 100755 diff --git a/src/tests/profiling_tests.h b/src/tests/profiling_tests.h old mode 100644 new mode 100755 diff --git a/src/tests/queue_tests.h b/src/tests/queue_tests.h old mode 100644 new mode 100755 From 5426aa835956afc4ce8b374cbf44d9247350c905 Mon Sep 17 00:00:00 2001 From: Brett Laptop Date: Mon, 10 Jul 2023 18:54:04 -0400 Subject: [PATCH 2/6] add template for string buffer --- include/blt/std/string.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/blt/std/string.h b/include/blt/std/string.h index cea9f6a..2611f5b 100755 --- a/include/blt/std/string.h +++ b/include/blt/std/string.h @@ -35,6 +35,14 @@ namespace blt::string { StringBuffer& operator<<(char c); + template + inline StringBuffer& operator<<(T t) { + auto str = std::to_string(t); + for (char c : str) + *this << c; + return *this; + } + ~StringBuffer() { free(characterBuffer); } From d883adaf5cf6fa9906658206df5b0b7487575d87 Mon Sep 17 00:00:00 2001 From: Brett Laptop Date: Mon, 10 Jul 2023 18:55:20 -0400 Subject: [PATCH 3/6] Change toString() to str() to better replicate the std --- include/blt/std/string.h | 2 +- src/blt/std/string.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/blt/std/string.h b/include/blt/std/string.h index 2611f5b..4051c56 100755 --- a/include/blt/std/string.h +++ b/include/blt/std/string.h @@ -26,7 +26,7 @@ namespace blt::string { void expand(); public: void trim(); - std::string toString(); + std::string str(); StringBuffer(){ characterBuffer = static_cast(malloc(BLOCK_SIZE)); diff --git a/src/blt/std/string.cpp b/src/blt/std/string.cpp index 0dba300..2ce5dd7 100755 --- a/src/blt/std/string.cpp +++ b/src/blt/std/string.cpp @@ -23,7 +23,7 @@ blt::string::StringBuffer& blt::string::StringBuffer::operator<<(char c) { return *this; } -std::string blt::string::StringBuffer::toString() { +std::string blt::string::StringBuffer::str() { trim(); return std::string{characterBuffer}; } From f15a89328fa5defa4cc38cca77dd4fc033ead602 Mon Sep 17 00:00:00 2001 From: Brett Laptop Date: Mon, 10 Jul 2023 19:08:23 -0400 Subject: [PATCH 4/6] add string writing support to string buffer --- include/blt/std/string.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/include/blt/std/string.h b/include/blt/std/string.h index 4051c56..0382b7d 100755 --- a/include/blt/std/string.h +++ b/include/blt/std/string.h @@ -34,12 +34,15 @@ namespace blt::string { } StringBuffer& operator<<(char c); + StringBuffer& operator<<(const std::string& str) { + for (char c : str) + *this << str; + return *this; + } template inline StringBuffer& operator<<(T t) { - auto str = std::to_string(t); - for (char c : str) - *this << c; + *this << std::to_string(t); return *this; } From fc8aa8204a0970ba26f02a4660589b3993ee6b14 Mon Sep 17 00:00:00 2001 From: Brett Laptop Date: Tue, 11 Jul 2023 17:50:40 -0400 Subject: [PATCH 5/6] fix bug in useless string buffer (use += on std::string, faster) --- include/blt/std/string.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/blt/std/string.h b/include/blt/std/string.h index 0382b7d..e2e1542 100755 --- a/include/blt/std/string.h +++ b/include/blt/std/string.h @@ -36,7 +36,7 @@ namespace blt::string { StringBuffer& operator<<(char c); StringBuffer& operator<<(const std::string& str) { for (char c : str) - *this << str; + *this << c; return *this; } From 15cca07286d319d87693136d303699c03415e1a4 Mon Sep 17 00:00:00 2001 From: Brett Laptop Date: Tue, 11 Jul 2023 18:35:29 -0400 Subject: [PATCH 6/6] fix mat4x4 scale op --- include/blt/math/matrix.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/blt/math/matrix.h b/include/blt/math/matrix.h index cd607bd..28fd7db 100755 --- a/include/blt/math/matrix.h +++ b/include/blt/math/matrix.h @@ -96,7 +96,7 @@ namespace blt { m00(m00() * x); m11(m11() * y); - m22(m11() * z); + m22(m22() * z); *this = *this * scale_mat;