Skip to content

Commit

Permalink
First iterator version
Browse files Browse the repository at this point in the history
  • Loading branch information
nhatdongdang committed Aug 12, 2024
1 parent 2d34459 commit 8cf87bd
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 1 deletion.
50 changes: 50 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
2 changes: 1 addition & 1 deletion Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 37 additions & 0 deletions include/mcpp/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>& heights);

Expand Down

0 comments on commit 8cf87bd

Please sign in to comment.