From a15ebfdd775ba90f9ecebc3da803230f1101462b Mon Sep 17 00:00:00 2001 From: Brett Laptop Date: Tue, 9 Apr 2024 18:03:33 -0400 Subject: [PATCH] more docs --- CMakeLists.txt | 2 +- README.md | 28 ++++- include/blt/fs/filesystem.h | 155 ------------------------- include/blt/fs/loader.h | 28 ----- include/blt/math/fixed_point_vectors.h | 34 ++++++ include/blt/math/vectors.h | 4 +- tests/src/math_tests.cpp | 3 +- 7 files changed, 63 insertions(+), 191 deletions(-) delete mode 100644 include/blt/fs/filesystem.h create mode 100644 include/blt/math/fixed_point_vectors.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 20c84a0..6a98d4f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.5) include(cmake/color.cmake) -set(BLT_VERSION 0.16.5) +set(BLT_VERSION 0.16.6) set(BLT_TEST_VERSION 0.0.1) set(BLT_TARGET BLT) diff --git a/README.md b/README.md index e9025d4..e763cbf 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,32 @@ -# **BLT v0.8.0a** -A C++20 common utilities library to make thing easy! +# **BLT v0.16** +A C++17 common utilities library to make thing easy! ![Icon](icon_large.png) --- +# ***Features*** +- ## blt/fs + - ### loader.h + - std::string blt::fs::getFile(std::string_view path) + - Gets the entire file as a string. + - std::vector\ blt::fs::getLinesFromFile(std::string_view path) + - Gets the entire file as a string, then splits on the new line character. Then returns a vector of those lines + - std::vector\ blt::fs::recursiveInclude(std::string_view path, std::string include_header, std::vector guards); + - Recursively include in order based on the include string (include_header) marked by the include guards + - Defaults to C/C++/GLSL preprocessor style (Was designed for GLSL) + - std::string blt::fs::loadBrainFuckFile(const std::string& path) + - Load a brainfuck file recursively, uses ~ to mark the include path + - ### nbt.h + - probably needs to be remade (TODO) +- ## blt/math + - ### averages.h + - blt::averagizer_o_matic + - Computes a rolling average in a dynamically allocated array. + - Useful for average FPS over a period of time + - ### fixed_point.h + - + # Specialties ## blt::logging.v2 Found in the header file `include/std/logging.h`, blt::logging is a fast and simple @@ -27,7 +49,7 @@ The goal was to create an API which would function exactly as the Python docs de ## blt::profile_t (v2) The newest version of my profiler solution now features a CPU cycle counter, CPU thread execution time, and wall time. It has more options for sorting and general printing while featuring a nicer codebase. It is an improvement over blt::profiling while maintaining (almost) complete backwards -compatability. Due to changes in the ABI the `BLT_PRINT_PROFILE` macro deletes the internal profiles and intervals AND takes arguments which match +compatability. Due to changes in the API the `BLT_PRINT_PROFILE` macro deletes the internal profiles and intervals AND takes arguments which match the new formatting options for profiling v2. However, `BLT_START_INTERVAL`, `BLT_WRITE_PROFILE`, and `BLT_END_INTERVAL` are still the same. Documentation for this is coming soon, along with more profiling features. the `BLT_*` macros can be disabled by the standard `BLT_DISABLE_PROFILING` from the v1 profiler. It is encouraged to use the new blt::* profile functions over the macros however these currently cannot be disabled. (TODO) diff --git a/include/blt/fs/filesystem.h b/include/blt/fs/filesystem.h deleted file mode 100644 index 2aab4bb..0000000 --- a/include/blt/fs/filesystem.h +++ /dev/null @@ -1,155 +0,0 @@ -/* - * Created by Brett on 29/01/23. - * Licensed under GNU General Public License V3.0 - * See LICENSE file for license detail - */ - -#ifndef BLT_FILESYSTEM_H -#define BLT_FILESYSTEM_H - -#include -#include -#include "memory.h" - -namespace blt::fs -{ - - /** - * A simple interface which provides a way of reading the next block of data from a resource. - * The interface provides a single function "read" which will read a specified number of bytes into the buffer. - * The implementation for this could be fstreams, zlib deflate, or any method filesystem access. - * Reading of a large number of bytes ( > block size) is guaranteed to not significantly increase the read time and will likely result in a - * direct passthrough to the underlying system. Small reads will be buffered, hence the name "block" reader. - */ - class block_reader - { - protected: - // 32768 block size seems the fastest on my system - unsigned long m_bufferSize; - public: - explicit block_reader(size_t bufferSize): m_bufferSize(bufferSize) - {} - - /** - * Reads bytes from the internal filesystem implementation - * @param buffer buffer to copy the read bytes into - * @param bytes number of bytes to read - * @return status code. non-zero return codes indicates a failure has occurred. - */ - virtual int read(char* buffer, size_t bytes) = 0; - - virtual size_t gcount() = 0; - - virtual char get() - { - char c[1]; - read(c, 1); - return c[0]; - } - }; - - /** - * A buffered block writer without a definite backend implementation. Exactly the same as a block_reader but for writing to the filesystem. - */ - class block_writer - { - protected: - unsigned long m_bufferSize; - public: - explicit block_writer(unsigned long bufferSize): m_bufferSize(bufferSize) - {} - - /** - * Writes the bytes to the filesystem backend implementation - * @param buffer bytes to write - * @param bytes number of bytes to write - * @return non-zero code if failure - */ - virtual int write(char* buffer, size_t bytes) = 0; - - virtual int put(char c) - { - char a[1]; - a[0] = c; - return write(a, 1); - } - - /** - * Ensures that the internal buffer is written to the filesystem. - */ - virtual void flush() = 0; - }; - - /** - * fstream implementation of the block reader. - */ - class fstream_block_reader : public block_reader - { - private: - std::fstream& m_stream; - char* m_buffer = nullptr; - size_t readIndex = 0; - public: - explicit fstream_block_reader(std::fstream& stream, size_t bufferSize = 131072); - - explicit fstream_block_reader(fstream_block_reader& copy) = delete; - - explicit fstream_block_reader(fstream_block_reader&& move) = delete; - - fstream_block_reader& operator=(const fstream_block_reader& copy) = delete; - - fstream_block_reader& operator=(const fstream_block_reader&& move) = delete; - - int read(char* buffer, size_t bytes) override; - - size_t gcount() final - { - return m_stream.gcount(); - } - - ~fstream_block_reader() - { - delete[] m_buffer; - } - }; - - class fstream_block_writer : public block_writer - { - private: - std::fstream& m_stream; - char* m_buffer; - size_t writeIndex = 0; - - void flush_internal(); - - public: - explicit fstream_block_writer(std::fstream& stream, size_t bufferSize = 131072): - block_writer(bufferSize), m_stream(stream), m_buffer(new char[bufferSize]) - {} - - explicit fstream_block_writer(fstream_block_writer& copy) = delete; - - explicit fstream_block_writer(fstream_block_writer&& move) = delete; - - fstream_block_writer& operator=(const fstream_block_writer& copy) = delete; - - fstream_block_writer& operator=(const fstream_block_writer&& move) = delete; - - int write(char* buffer, size_t bytes) override; - - inline void flush() override - { - flush_internal(); - } - - ~fstream_block_writer() - { - flush_internal(); - delete[] m_buffer; - } - }; - - -} - -#endif //BLT_FILESYSTEM_H diff --git a/include/blt/fs/loader.h b/include/blt/fs/loader.h index f5cc840..991c249 100644 --- a/include/blt/fs/loader.h +++ b/include/blt/fs/loader.h @@ -52,34 +52,6 @@ namespace blt::fs return buffer; } - - static inline std::string loadShaderFile(std::string_view path) - { - std::stringstream stringStream; - - auto lines = recursiveInclude(path); - - for (const auto& line : lines) - { - // now process the defines, if they exist -// if (line.starts_with("#define")) { -// auto defineParts = String::split(line, " "); -// // create a new define statement in the defines place but with the respective value. -// if (defines.contains(defineParts[1])) { -// stringStream << "#define "; -// stringStream << defineParts[1] << " "; -// stringStream << defines[defineParts[1]]; -// stringStream << "\n"; -// continue; -// } -// } - stringStream << line; - stringStream << "\n"; - } - - //tlog << stringStream.str(); - return stringStream.str(); - } } #endif //BLT_TESTS_LOADER_H diff --git a/include/blt/math/fixed_point_vectors.h b/include/blt/math/fixed_point_vectors.h new file mode 100644 index 0000000..1e20773 --- /dev/null +++ b/include/blt/math/fixed_point_vectors.h @@ -0,0 +1,34 @@ +/* + * + * Copyright (C) 2024 Brett Terpstra + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef BLT_FIXED_POINT_VECTORS_H +#define BLT_FIXED_POINT_VECTORS_H + +#include +#include + +namespace blt +{ + + using vec2fp = blt::vec; + using vec3fp = blt::vec; + using vec4fp = blt::vec; + +} + +#endif //BLT_FIXED_POINT_VECTORS_H diff --git a/include/blt/math/vectors.h b/include/blt/math/vectors.h index 72d9225..adfb2ce 100644 --- a/include/blt/math/vectors.h +++ b/include/blt/math/vectors.h @@ -16,6 +16,8 @@ namespace blt { + +#define MSVC_COMPILER (!defined(__GNUC__) && !defined(__clang__)) constexpr float EPSILON = 0.0001f; @@ -23,8 +25,6 @@ namespace blt { return v1 >= v2 - EPSILON && v1 <= v2 + EPSILON; } - -#define MSVC_COMPILER (!defined(__GNUC__) && !defined(__clang__)) template struct vec diff --git a/tests/src/math_tests.cpp b/tests/src/math_tests.cpp index 428fda4..870ac76 100644 --- a/tests/src/math_tests.cpp +++ b/tests/src/math_tests.cpp @@ -16,6 +16,7 @@ * along with this program. If not, see . */ #include +#include #include #include #include @@ -25,8 +26,6 @@ #include #include -using vec3fp = blt::vec; - namespace blt::test { void print(fp64 v, const std::string& name = "")