From 8cf87bddf942f9e608a7843533a9b1a149a7ee7e Mon Sep 17 00:00:00 2001 From: nhatdongdang <144138246+nhatdongdang@users.noreply.github.com> Date: Mon, 12 Aug 2024 14:25:01 +1000 Subject: [PATCH] First iterator version --- .vscode/settings.json | 50 +++++++++++++++++++++++++++++++++++++++++++ Doxyfile | 2 +- include/mcpp/util.h | 37 ++++++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..1dd4a7f6 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,50 @@ +{ + "files.associations": { + "__bit_reference": "cpp", + "__config": "cpp", + "__debug": "cpp", + "__errc": "cpp", + "__locale": "cpp", + "__mutex_base": "cpp", + "__threading_support": "cpp", + "__verbose_abort": "cpp", + "array": "cpp", + "atomic": "cpp", + "bitset": "cpp", + "cctype": "cpp", + "charconv": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "exception": "cpp", + "initializer_list": "cpp", + "ios": "cpp", + "iosfwd": "cpp", + "limits": "cpp", + "locale": "cpp", + "mutex": "cpp", + "new": "cpp", + "optional": "cpp", + "ostream": "cpp", + "queue": "cpp", + "stack": "cpp", + "stdexcept": "cpp", + "streambuf": "cpp", + "string": "cpp", + "string_view": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "typeinfo": "cpp", + "variant": "cpp", + "vector": "cpp", + "print": "cpp", + "algorithm": "cpp" + } +} \ No newline at end of file diff --git a/Doxyfile b/Doxyfile index efd988f2..aa53d8ca 100644 --- a/Doxyfile +++ b/Doxyfile @@ -2,7 +2,7 @@ DOXYFILE_ENCODING = UTF-8 PROJECT_NAME = "mcpp" PROJECT_NUMBER = PROJECT_BRIEF = "C++ Minecraft Library" -PROJECT_LOGO = +PROJECT_LOGO = "https://github.com/rozukke/mcpp/blob/main/resources/mcpplogosmall.png" OUTPUT_DIRECTORY = ./doc/ CREATE_SUBDIRS = NO CREATE_SUBDIRS_LEVEL = 8 diff --git a/include/mcpp/util.h b/include/mcpp/util.h index 72c1fcf8..58148245 100644 --- a/include/mcpp/util.h +++ b/include/mcpp/util.h @@ -132,6 +132,43 @@ struct Chunk { * non-air blocks at each (x,z) */ struct HeightMap { + struct Iterator { + using value_type = int; + using pointer = int*; + using reference = int&; + + Iterator(pointer ptr) : m_ptr(ptr) {} + + reference operator*() const { return *m_ptr; } + pointer operator->() { return m_ptr; } + + // Prefix increment + Iterator& operator++() { + m_ptr++; + return *this; + } + + // Postfix increment + Iterator operator++(int) { + Iterator tmp = *this; + ++(*this); + return tmp; + } + + friend bool operator==(const Iterator& a, const Iterator& b) { + return a.m_ptr == b.m_ptr; + }; + + friend bool operator!=(const Iterator& a, const Iterator& b) { + return a.m_ptr != b.m_ptr; + }; + + private: + pointer m_ptr; + }; + Iterator begin() { return Iterator(&raw_heights[0]); } + Iterator end() { return Iterator(&raw_heights[_x_len * _z_len]); } + HeightMap(const Coordinate& loc1, const Coordinate& loc2, const std::vector& heights);