From da71ee05bdefffaf00d2df67624c7cf687539ebc Mon Sep 17 00:00:00 2001 From: Artemis Rosman <73006620+rozukke@users.noreply.github.com> Date: Sat, 22 Jun 2024 15:40:04 +1000 Subject: [PATCH 1/4] Add ability to specify release types for CMake --- CMakeLists.txt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 587339a1..d0fcf200 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,6 +4,14 @@ project(mcpp) set(CMAKE_CXX_STANDARD 17) +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE Release) +endif() + +set(CMAKE_CXX_FLAGS "-Wall -Wextra") +set(CMAKE_CXX_FLAGS_DEBUG "-g") +set(CMAKE_CXX_FLAGS_RELEASE "-O3") + set(MCPP_SRC_DIR src) set(MCPP_INC_DIR include/mcpp) From 5e27d3b05939bb67825fbb4ded4986885682773b Mon Sep 17 00:00:00 2001 From: Artemis Rosman <73006620+rozukke@users.noreply.github.com> Date: Wed, 14 Aug 2024 17:43:26 +1000 Subject: [PATCH 2/4] Add pyramid example --- example/pyramid.cpp | 52 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 example/pyramid.cpp diff --git a/example/pyramid.cpp b/example/pyramid.cpp new file mode 100644 index 00000000..80404ca5 --- /dev/null +++ b/example/pyramid.cpp @@ -0,0 +1,52 @@ +#include +#include +#include +#include + +// Change location here +mcpp::Coordinate ORIGIN {0, 0, 0}; +int PYRAMID_HEIGHT = 50; + +// Can declare globally +mcpp::MinecraftConnection mc; + +void make_ring(mcpp::Coordinate base_pt, int side_len) { + // Flat plane + mc.setBlocks( + base_pt, + base_pt + mcpp::Coordinate(side_len, 0, side_len), + mcpp::Blocks::SANDSTONE + ); + + // Air inside to make border + base_pt = base_pt + mcpp::Coordinate(1, 0, 1); + mc.setBlocks( + base_pt, + base_pt + mcpp::Coordinate(side_len - 2, 0, side_len - 2), + mcpp::Blocks::AIR + ); +} + +int main() { + int pyramid_base_len = PYRAMID_HEIGHT * 2; + + // Get heights of build area + mcpp::HeightMap heights = mc.getHeights( + ORIGIN, + ORIGIN + mcpp::Coordinate(pyramid_base_len, 0, pyramid_base_len) + ); + + // Use minimum height of the area as the lowest point on the pyramid + int min_height = *std::min_element( + heights.begin(), + heights.end() + ); + + // Build rings, diminishing up to pyramid height + mcpp::Coordinate base_pt = heights.base_pt(); + base_pt.y = min_height; + int side_len = pyramid_base_len; + for(int i = 0; i < PYRAMID_HEIGHT; i++) { + make_ring(base_pt + mcpp::Coordinate(i, i, i), side_len - (i * 2)); + } +} From 4d44f70bb5e11f02fca8201547a745cad93badb4 Mon Sep 17 00:00:00 2001 From: Artemis Rosman <73006620+rozukke@users.noreply.github.com> Date: Wed, 14 Aug 2024 17:43:43 +1000 Subject: [PATCH 3/4] Add example README.md --- example/README.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 example/README.md diff --git a/example/README.md b/example/README.md new file mode 100644 index 00000000..7c3fe08f --- /dev/null +++ b/example/README.md @@ -0,0 +1,7 @@ +## Examples +A few small examples to show the capabilities of `mcpp`. + +They should be compilable with something along the lines of `g++ -std=c++17 -o example example.cpp -lmcpp` +after you have installed the library. + +Feel free to open a PR if you have an interesting usecase to include as part of the examples. From 6f7add046d297ae5f46fd33d2855bdbd9894dc94 Mon Sep 17 00:00:00 2001 From: Artemis Rosman <73006620+rozukke@users.noreply.github.com> Date: Wed, 14 Aug 2024 17:47:34 +1000 Subject: [PATCH 4/4] Fix formatting --- example/pyramid.cpp | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/example/pyramid.cpp b/example/pyramid.cpp index 80404ca5..ec6dff47 100644 --- a/example/pyramid.cpp +++ b/example/pyramid.cpp @@ -1,10 +1,10 @@ +#include #include #include #include -#include // Change location here -mcpp::Coordinate ORIGIN {0, 0, 0}; +mcpp::Coordinate ORIGIN{0, 0, 0}; int PYRAMID_HEIGHT = 50; // Can declare globally @@ -12,41 +12,32 @@ mcpp::MinecraftConnection mc; void make_ring(mcpp::Coordinate base_pt, int side_len) { // Flat plane - mc.setBlocks( - base_pt, - base_pt + mcpp::Coordinate(side_len, 0, side_len), - mcpp::Blocks::SANDSTONE - ); + mc.setBlocks(base_pt, base_pt + mcpp::Coordinate(side_len, 0, side_len), + mcpp::Blocks::SANDSTONE); // Air inside to make border base_pt = base_pt + mcpp::Coordinate(1, 0, 1); - mc.setBlocks( - base_pt, - base_pt + mcpp::Coordinate(side_len - 2, 0, side_len - 2), - mcpp::Blocks::AIR - ); + mc.setBlocks(base_pt, + base_pt + mcpp::Coordinate(side_len - 2, 0, side_len - 2), + mcpp::Blocks::AIR); } int main() { int pyramid_base_len = PYRAMID_HEIGHT * 2; // Get heights of build area - mcpp::HeightMap heights = mc.getHeights( - ORIGIN, - ORIGIN + mcpp::Coordinate(pyramid_base_len, 0, pyramid_base_len) - ); + mcpp::HeightMap heights = + mc.getHeights(ORIGIN, ORIGIN + mcpp::Coordinate(pyramid_base_len, 0, + pyramid_base_len)); // Use minimum height of the area as the lowest point on the pyramid - int min_height = *std::min_element( - heights.begin(), - heights.end() - ); + int min_height = *std::min_element(heights.begin(), heights.end()); // Build rings, diminishing up to pyramid height mcpp::Coordinate base_pt = heights.base_pt(); base_pt.y = min_height; int side_len = pyramid_base_len; - for(int i = 0; i < PYRAMID_HEIGHT; i++) { + for (int i = 0; i < PYRAMID_HEIGHT; i++) { make_ring(base_pt + mcpp::Coordinate(i, i, i), side_len - (i * 2)); - } + } }