Skip to content

Commit

Permalink
add island string
Browse files Browse the repository at this point in the history
  • Loading branch information
AsPJT committed Apr 17, 2019
1 parent 166e26e commit 698f288
Show file tree
Hide file tree
Showing 21 changed files with 260 additions and 123 deletions.
223 changes: 123 additions & 100 deletions DungeonTemplateLibrary/ThirdParty/STB/stb_image_write.hpp

Large diffs are not rendered by default.

48 changes: 28 additions & 20 deletions DungeonTemplateLibrary/ThirdParty/STB/wrapper_stb_image_write.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,36 +41,44 @@ namespace dtl::thirdParty::stb {
template<typename Matrix_Int_, std::size_t Width_, std::size_t Height_, std::size_t Color_Num_ = dtl::thirdParty::stb::primary_colors_rgb>
class FileSTB {
private:
std::unique_ptr<unsigned char[][Width_][Color_Num_]> data;
//std::unique_ptr<unsigned char[][Width_][Color_Num_]> data;
std::unique_ptr<unsigned char[]> data;

public:
FileSTB() noexcept :data(new(std::nothrow) unsigned char[Height_][Width_][Color_Num_]) {}
template<typename Matrix_,typename Function_>
FileSTB(Matrix_&& matrix_, Function_&& function_) noexcept :data(new(std::nothrow) unsigned char[Height_][Width_][Color_Num_]) {
for (std::size_t row{}; row < Height_; ++row)
for (std::size_t col{}; col < Width_; ++col)
function_(matrix_[row][col], &data[row][col][0]);
}
template<typename Matrix_, typename Function_>
FileSTB(Matrix_&& matrix_, const Matrix_Int_& layer_, Function_&& function_) noexcept :data(new(std::nothrow) unsigned char[Height_][Width_][Color_Num_]) {
FileSTB(Matrix_&& matrix_, Function_&& function_) noexcept :data(new(std::nothrow) unsigned char[Height_*Width_*Color_Num_]) {
for (std::size_t row{}; row < Height_; ++row)
for (std::size_t col{}; col < Width_; ++col)
function_(matrix_[row][col][layer_], &data[row][col][0]);
function_(matrix_[row][col], &data[(row * Width_ + col) * Color_Num_]);
}
//FileSTB() noexcept :data(new(std::nothrow) unsigned char[Height_][Width_][Color_Num_]) {}
//template<typename Matrix_,typename Function_>
//FileSTB(Matrix_&& matrix_, Function_&& function_) noexcept :data(new(std::nothrow) unsigned char[Height_][Width_][Color_Num_]) {
// for (std::size_t row{}; row < Height_; ++row)
// for (std::size_t col{}; col < Width_; ++col)
// function_(matrix_[row][col], &data[row][col][0]);
//}
//template<typename Matrix_, typename Function_>
//FileSTB(Matrix_&& matrix_, const Matrix_Int_& layer_, Function_&& function_) noexcept :data(new(std::nothrow) unsigned char[Height_][Width_][Color_Num_]) {
// for (std::size_t row{}; row < Height_; ++row)
// for (std::size_t col{}; col < Width_; ++col)
// function_(matrix_[row][col][layer_], &data[row][col][0]);
//}

void writePNG(const std::string& string_, const int stride_in_bytes_ = 0) const noexcept {
stbi_write_png(string_.c_str(), static_cast<int>(Width_), static_cast<int>(Height_), static_cast<int>(Color_Num_), data.get(), stride_in_bytes_);
auto writePNG(const std::string& string_, const int stride_in_bytes_ = 0) const noexcept {
return stbi_write_png(string_, static_cast<int>(Width_), static_cast<int>(Height_), static_cast<int>(Color_Num_), data.get(), stride_in_bytes_);
}
void writeBMP(const std::string& string_) const noexcept {
stbi_write_bmp(string_.c_str(), static_cast<int>(Width_), static_cast<int>(Height_), static_cast<int>(Color_Num_), data.get());
auto writeBMP(const std::string& string_) const noexcept {
return stbi_write_bmp(string_, static_cast<int>(Width_), static_cast<int>(Height_), static_cast<int>(Color_Num_), data.get());
}
void writeTGA(const std::string& string_) const noexcept {
stbi_write_tga(string_.c_str(), static_cast<int>(Width_), static_cast<int>(Height_), static_cast<int>(Color_Num_), data.get());
auto writeTGA(const std::string& string_) const noexcept {
return stbi_write_tga(string_, static_cast<int>(Width_), static_cast<int>(Height_), static_cast<int>(Color_Num_), data.get());
}
void writeHDR(const std::string& string_) const noexcept {
stbi_write_hdr(string_.c_str(), static_cast<int>(Width_), static_cast<int>(Height_), static_cast<int>(Color_Num_), data.get());
auto writeHDR(const std::string& string_) const noexcept {
return stbi_write_hdr(string_, static_cast<int>(Width_), static_cast<int>(Height_), static_cast<int>(Color_Num_), data.get());
}
void writeJPG(const std::string& string_, const int quality_ = 100) const noexcept {
stbi_write_jpg(string_.c_str(), static_cast<int>(Width_), static_cast<int>(Height_), static_cast<int>(Color_Num_), data.get(), quality_);
auto writeJPG(const std::string& string_, const int quality_ = 100) const noexcept {
return stbi_write_jpg(string_, static_cast<int>(Width_), static_cast<int>(Height_), static_cast<int>(Color_Num_), data.get(), quality_);
}
};

Expand Down
Binary file added DungeonTemplateLibrary/island128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added DungeonTemplateLibrary/island128_128_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added DungeonTemplateLibrary/island256_256_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added DungeonTemplateLibrary/island256_256_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added DungeonTemplateLibrary/island256_256_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added DungeonTemplateLibrary/island256_256_4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added DungeonTemplateLibrary/island256_256_5.bmp
Binary file not shown.
Binary file added DungeonTemplateLibrary/island256_256_5.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added DungeonTemplateLibrary/island256_256_5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added DungeonTemplateLibrary/island256_256_5.tga
Binary file not shown.
Binary file added DungeonTemplateLibrary/island256_256_6.bmp
Binary file not shown.
Binary file added DungeonTemplateLibrary/island256_256_6.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added DungeonTemplateLibrary/island256_256_6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added DungeonTemplateLibrary/island256_256_6.tga
Binary file not shown.
Binary file added DungeonTemplateLibrary/island63_31.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added DungeonTemplateLibrary/island64.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added DungeonTemplateLibrary/island64_32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added DungeonTemplateLibrary/island64_64_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
112 changes: 109 additions & 3 deletions DungeonTemplateLibrary/pdf_sample.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,118 @@
#include <DTL.hpp>
#include <array>
#include <bitset>
#include <algorithm>
#include <limits>

#include <cstdint>
#include <cstddef>
#include <memory>
#include <new>

class FileImageFunc {
public:
template<typename Matrix_Int_>
void operator()(const Matrix_Int_& value_, dtl::storage::Image_Palette* color) noexcept {
constexpr dtl::storage::Image_Palette color_sub{ 1 };
constexpr Matrix_Int_ deep_max_value{ 80 };
constexpr Matrix_Int_ sea_max_value{ 120 };
constexpr Matrix_Int_ sand_max_value{ 142 };
constexpr Matrix_Int_ land_max_value{ 160 };

if (value_ <= deep_max_value) {
color[dtl::storage::image_red] = static_cast<dtl::storage::Image_Palette>(30);
color[dtl::storage::image_green] = static_cast<dtl::storage::Image_Palette>(88);
color[dtl::storage::image_blue] = static_cast<dtl::storage::Image_Palette>(126);
}
else if (value_ <= sea_max_value) {
color[dtl::storage::image_red] = static_cast<dtl::storage::Image_Palette>(30 + 135 * (value_ - deep_max_value) / (sea_max_value - deep_max_value)) / color_sub * color_sub;
color[dtl::storage::image_green] = static_cast<dtl::storage::Image_Palette>(88 + 133 * (value_ - deep_max_value) / (sea_max_value - deep_max_value)) / color_sub * color_sub;
color[dtl::storage::image_blue] = static_cast<dtl::storage::Image_Palette>(126 + 84 * (value_ - deep_max_value) / (sea_max_value - deep_max_value)) / color_sub * color_sub;
}
else if (value_ <= sand_max_value) {
color[dtl::storage::image_red] = static_cast<dtl::storage::Image_Palette>(244 - 20 * (value_ - sea_max_value) / (sand_max_value - sea_max_value)) / color_sub * color_sub;
color[dtl::storage::image_green] = static_cast<dtl::storage::Image_Palette>(236 - 27 * (value_ - sea_max_value) / (sand_max_value - sea_max_value)) / color_sub * color_sub;
color[dtl::storage::image_blue] = static_cast<dtl::storage::Image_Palette>(215 - 25 * (value_ - sea_max_value) / (sand_max_value - sea_max_value)) / color_sub * color_sub;
}
else if (value_ <= sand_max_value + 2) {
color[dtl::storage::image_red] = static_cast<dtl::storage::Image_Palette>(224 / 2 + 166 / 2);
color[dtl::storage::image_green] = static_cast<dtl::storage::Image_Palette>(209 / 2 + 193 / 2);
color[dtl::storage::image_blue] = static_cast<dtl::storage::Image_Palette>(190 / 2 + 98 / 2);
}
else {
color[dtl::storage::image_red] = static_cast<dtl::storage::Image_Palette>(166 - 30 * (value_ - sand_max_value) / (land_max_value - sand_max_value)) / color_sub * color_sub;
color[dtl::storage::image_green] = static_cast<dtl::storage::Image_Palette>(193 + 12 * (value_ - sand_max_value) / (land_max_value - sand_max_value)) / color_sub * color_sub;
color[dtl::storage::image_blue] = static_cast<dtl::storage::Image_Palette>(98 + 1 * (value_ - sand_max_value) / (land_max_value - sand_max_value)) / color_sub * color_sub;
}

color[dtl::storage::image_red] += dtl::random::mt32bit.get<dtl::storage::Image_Palette>(20) - 10;
color[dtl::storage::image_green] += dtl::random::mt32bit.get<dtl::storage::Image_Palette>(20) - 10;
color[dtl::storage::image_blue] += dtl::random::mt32bit.get<dtl::storage::Image_Palette>(20) - 10;

}
};

template<typename Matrix_Int_,typename Matrix_>
void randomTerrain(Matrix_&& matrix_, const std::size_t width, const std::size_t height, const std::int_fast32_t min_value_, const std::int_fast32_t max_value_, const std::int_fast32_t min_size, const std::int_fast32_t max_size, const Matrix_Int_& sub_) noexcept {

matrix_[0][0] = dtl::random::mt32bit.get<Matrix_Int_>(min_value_, max_value_);

for (std::size_t row{ 1 }; row < height; ++row) {
if (matrix_[row - 1][0] < min_size + sub_) {
matrix_[row][0] = matrix_[row - 1][0]+dtl::random::mt32bit.get<Matrix_Int_>(sub_);
continue;
}
const Matrix_Int_& rand_value{ dtl::random::mt32bit.get<Matrix_Int_>(sub_ * 2 + 1) };
if (matrix_[row - 1][0] >= max_size - rand_value) {
matrix_[row][0] = matrix_[row - 1][0]-dtl::random::mt32bit.get<Matrix_Int_>(sub_);
continue;
}

matrix_[row][0] = matrix_[row - 1][0] + rand_value - sub_;
}
for (std::size_t col{ 1 }; col < width; ++col) {
if (matrix_[0][col - 1] < min_size + sub_) {
matrix_[0][col] = matrix_[0][col - 1]+dtl::random::mt32bit.get<Matrix_Int_>(sub_);
continue;
}
const Matrix_Int_& rand_value{ dtl::random::mt32bit.get<Matrix_Int_>(sub_ * 2 + 1) };
if (matrix_[0][col - 1] >= max_size - rand_value) {
matrix_[0][col] = matrix_[0][col - 1]-dtl::random::mt32bit.get<Matrix_Int_>(sub_);
continue;
}

matrix_[0][col] = matrix_[0][col - 1] + rand_value - sub_;
}
for (std::size_t row{ 1 }; row < height; ++row)
for (std::size_t col{ 1 }; col < width; ++col) {
if ((std::min)(matrix_[row][col - 1], matrix_[row - 1][col]) < min_size + sub_) {
matrix_[row][col] = (std::min)(matrix_[row][col - 1], matrix_[row - 1][col])+dtl::random::mt32bit.get<Matrix_Int_>(sub_);
continue;
}
const Matrix_Int_& rand_value{ dtl::random::mt32bit.get<Matrix_Int_>((std::max)(matrix_[row][col - 1], matrix_[row - 1][col]) - (std::min)(matrix_[row][col - 1], matrix_[row - 1][col]) + sub_ * 2 + 1) };
if ((std::min)(matrix_[row][col], matrix_[row - 1][col]) >= max_size - rand_value) {
matrix_[row][col] = (std::min)(matrix_[row][col], matrix_[row - 1][col])-dtl::random::mt32bit.get<Matrix_Int_>(sub_);
continue;
}

matrix_[row][col] = (std::min)(matrix_[row][col - 1], matrix_[row - 1][col]) + rand_value - sub_;
}

}

int main() {

std::array<std::bitset<63>, 31> matrix{ {} };
dtl::shape::PointGridWithBorder<bool>(1).draw(matrix);
using shape_t = std::uint_fast8_t;
constexpr std::size_t width{ 256 };
constexpr std::size_t height{ 256 };
std::array<std::array<shape_t, width>, height> matrix{ {} };
//dtl::shape::PointGridWithBorder<bool>(1).draw(matrix);

randomTerrain<shape_t>(matrix, width, height, 110, 120, 0, 255, 3);

//dtl::console::OutputNumber<bool>(",").draw(matrix);
//dtl::console::OutputStringBool<bool>("##", " ").drawOperator(matrix, [](const shape_t a) {return a > 150; });

dtl::console::OutputStringBool<bool>("##", " ").draw(matrix);
dtl::storage::FileImage<shape_t, width, height, dtl::storage::primary_colors_rgb>(matrix, FileImageFunc()).writeJPG("island256_256_6.jpg");

}

0 comments on commit 698f288

Please sign in to comment.