Skip to content

Commit

Permalink
v0.1.30
Browse files Browse the repository at this point in the history
  • Loading branch information
AsPJT committed Feb 4, 2019
1 parent 2960c0d commit 834a431
Show file tree
Hide file tree
Showing 13 changed files with 539 additions and 60 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions include/cpp14/DTL.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "DungeonRandom.hpp"
#include "DungeonStandard.hpp"
#include "DungeonFile.hpp"
#include "DungeonMatrix.hpp"

//ダンジョン
#include "FractalIsland.hpp"
Expand All @@ -22,6 +23,7 @@
#include "SimpleRogueLike.hpp"
#include "SimpleVoronoiIsland.hpp"
#include "BoardGame.hpp"
#include "HorizontalScroll.hpp"

//ペイント
#include "DungeonPaint.hpp"
Expand Down
74 changes: 62 additions & 12 deletions include/cpp14/DungeonFile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,18 +230,68 @@ namespace dtl {
ofs << "</svg>";
return true;
}
////bmpファイルの書き込み
//template<typename Matrix_>
//bool fileWrite_bmp(const Matrix_& matrix_, const std::string& str_) noexcept {
// std::ofstream ofs(str_, std::ios::binary);
// if (ofs.fail()) return false;

// std::string a({ 0x42,0x4d });
// a.push_back(0x42);
// a.push_back(0x4d);
// a.push_back(0);

//}
//objファイルの書き込み
template<typename Matrix_>
bool fileWriteTerrain_obj(const Matrix_& matrix_, const std::string& str_) noexcept {
if (matrix_.size() == 0 || matrix_[0].size() == 0) return false;
std::ofstream ofs(str_);
if (ofs.fail()) return false;

const bool is_char{ (typeid(matrix_[0][0]) == typeid(unsigned char) || typeid(matrix_[0][0]) == typeid(signed char)) };
if (is_char)
for (std::size_t row{}; row < matrix_.size(); ++row)
for (std::size_t col{}; col < matrix_[row].size(); ++col)
ofs << "v " << col << " " << static_cast<int>(matrix_[row][col]) << " " << row << std::endl;
else
for (std::size_t row{}; row < matrix_.size(); ++row)
for (std::size_t col{}; col < matrix_[row].size(); ++col)
ofs << "v " << col << " " << matrix_[row][col] << " " << row << std::endl;

std::size_t x_size{ matrix_[0].size() };
for (std::size_t row{ 1 }; row < matrix_.size(); ++row)
for (std::size_t col{ 2 }; col <= matrix_[row].size(); ++col) {
ofs << "f " << (row*x_size + col) << " " << ((row - 1)*x_size + col) << " " << ((row - 1)*x_size + (col - 1)) << std::endl;
ofs << "f " << (row*x_size + col) << " " << (row*x_size + (col - 1)) << " " << ((row - 1)*x_size + (col - 1)) << std::endl;
}
}

void fileWrite_objOutputId(std::ofstream& ofs_, const std::size_t id_ = 0) noexcept {
ofs_ << "f " << (1 + id_ * 8) << " " << (3 + id_ * 8) << " " << (4 + id_ * 8) << " " << (2 + id_ * 8) << std::endl;
ofs_ << "f " << (1 + id_ * 8) << " " << (5 + id_ * 8) << " " << (7 + id_ * 8) << " " << (3 + id_ * 8) << std::endl;
ofs_ << "f " << (2 + id_ * 8) << " " << (4 + id_ * 8) << " " << (8 + id_ * 8) << " " << (6 + id_ * 8) << std::endl;
ofs_ << "f " << (1 + id_ * 8) << " " << (2 + id_ * 8) << " " << (6 + id_ * 8) << " " << (5 + id_ * 8) << std::endl;
ofs_ << "f " << (3 + id_ * 8) << " " << (7 + id_ * 8) << " " << (8 + id_ * 8) << " " << (4 + id_ * 8) << std::endl;
ofs_ << "f " << (5 + id_ * 8) << " " << (6 + id_ * 8) << " " << (8 + id_ * 8) << " " << (7 + id_ * 8) << std::endl;
}
void fileWrite_objOutputCube(std::ofstream& ofs_, std::int_fast32_t start_x, std::int_fast32_t start_y, std::int_fast32_t start_z, std::int_fast32_t size_x, std::int_fast32_t size_y, std::int_fast32_t size_z, std::size_t id_ = 0) noexcept {
ofs_ << "v " << start_x << " " << start_y << " " << start_z << " " << std::endl;
ofs_ << "v " << start_x + size_x << " " << start_y << " " << start_z << " " << std::endl;
ofs_ << "v " << start_x << " " << start_y + size_y << " " << start_z << " " << std::endl;
ofs_ << "v " << start_x + size_x << " " << start_y + size_y << " " << start_z << " " << std::endl;
ofs_ << "v " << start_x << " " << start_y << " " << start_z + size_z << " " << std::endl;
ofs_ << "v " << start_x + size_x << " " << start_y << " " << start_z + size_z << " " << std::endl;
ofs_ << "v " << start_x << " " << start_y + size_y << " " << start_z + size_z << " " << std::endl;
ofs_ << "v " << start_x + size_x << " " << start_y + size_y << " " << start_z + size_z << " " << std::endl;
fileWrite_objOutputId(ofs_, id_);
}

template<typename Matrix_Int_, typename Matrix_>
bool fileWriteBoard_obj(const Matrix_& matrix_, const std::string& str_, const std::int_fast32_t block_size_ = 1, const Matrix_Int_ output_id_ = 1) noexcept {
if (matrix_.size() == 0 || matrix_[0].size() == 0) return false;
std::ofstream ofs(str_);
if (ofs.fail()) return false;

fileWrite_objOutputCube(ofs, 0, -1, 0, (std::int_fast32_t)matrix_[0].size(), 1, (std::int_fast32_t)matrix_.size());

std::size_t square_count{ 1 };
for (std::size_t row{}; row < matrix_.size(); ++row)
for (std::size_t col{}; col < matrix_[row].size(); ++col)
if (matrix_[row][col] == output_id_) {
fileWrite_objOutputCube(ofs, (std::int_fast32_t)col, 0, (std::int_fast32_t)row, 1, block_size_, 1, square_count);
++square_count;
}
return true;
}
//バイナリファイルの書き込み
template<typename Matrix_>
bool fileWrite(const Matrix_& matrix_, const std::string& str_) noexcept {
Expand Down
209 changes: 209 additions & 0 deletions include/cpp14/DungeonMatrix.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
#ifndef INCLUDED_DUNGEON_TEMPLATE_LIBRARY_DUNGEON_MATRIX
#define INCLUDED_DUNGEON_TEMPLATE_LIBRARY_DUNGEON_MATRIX
//:::::----------::::::::::----------::::://
// Dungeon Template Library //
// Made by Gaccho. //
// This code is licensed under CC0. //
// [email protected] //
//:::::----------::::::::::----------::::://

#include <cstddef>

//Dungeon Template Library Namespace
namespace dtl {

//ダンジョン内の値を操作
namespace matrix {

//配列数を取得
template<typename Matrix_>
constexpr std::size_t getSize(const Matrix_& matrix_) noexcept {
return ((matrix_.size() == 0) ? 0 : (matrix_.size()*matrix_[0].size()));
}
template<typename Matrix_>
constexpr std::size_t getSizeX(const Matrix_& matrix_) noexcept {
return ((matrix_.size() == 0) ? 0 : matrix_[0].size());
}
template<typename Matrix_>
constexpr std::size_t getSizeY(const Matrix_& matrix_) noexcept {
return matrix_.size();
}

constexpr bool isEmpty(const std::size_t x_, const std::size_t y_) noexcept {
return (y_ == 0 || x_ == 0);
}
template<typename Matrix_>
constexpr bool isEmpty(const Matrix_& matrix_) noexcept {
return (matrix_.size() == 0 || matrix_[0].size() == 0);
}
template<typename Matrix_>
constexpr bool isLessThan(const Matrix_& matrix_, const std::size_t num_) noexcept {
return (matrix_.size() < num_ || matrix_[0].size() < num_);
}

//指定位置に値を代入する
template<typename Matrix_Int_, typename Matrix_>
constexpr void setValue(Matrix_& matrix_, const std::size_t x_, const std::size_t y_, const Matrix_Int_ value_) noexcept {
matrix_[y_][x_] = value_;
}
template<typename Matrix_>
constexpr void setValue(Matrix_& matrix_, const std::size_t x_, const std::size_t y_) noexcept {
matrix_[y_][x_] = 0;
}
//指定位置の値を取得する
template<typename Matrix_Int_, typename Matrix_>
constexpr void getValue(const Matrix_& matrix_, const std::size_t x_, const std::size_t y_, Matrix_Int_& value_) noexcept {
value_ = matrix_[y_][x_];
}
template<typename Matrix_>
constexpr auto getValue(const Matrix_& matrix_, const std::size_t x_, const std::size_t y_) noexcept {
return matrix_[y_][x_];
}

//サイズ変更(std::vector, std::deque等)
template<typename Matrix_>
constexpr void resize(Matrix_& matrix_, const std::size_t x_, const std::size_t y_) noexcept {
matrix_.resize(y_);
for (std::size_t row{}; row < y_; ++row)
matrix_[row].resize(x_);
}
template<typename Matrix_Int_, typename Matrix_>
constexpr void resize(Matrix_& matrix_, const std::size_t x_, const std::size_t y_, const Matrix_Int_ value_) noexcept {
matrix_.resize(y_);
for (std::size_t row{}; row < y_; ++row) {
matrix_[row].resize(x_);
for (std::size_t col{}; col < x_; ++col)
matrix_[row][col] = value_;
}
}

namespace layer {

template<typename Matrix_>
constexpr void resize(Matrix_& matrix_, const std::size_t x_, const std::size_t y_, const std::size_t layer_) noexcept {
matrix_.resize(y_);
for (std::size_t row{}; row < y_; ++row) {
matrix_[row].resize(x_);
for (std::size_t col{}; col < x_; ++col)
matrix_[row][col].resize(layer_);
}
}
template<typename Matrix_Int_, typename Matrix_>
constexpr void resize(Matrix_& matrix_, const std::size_t x_, const std::size_t y_, const std::size_t layer_, const Matrix_Int_ value_) noexcept {
matrix_.resize(y_);
for (std::size_t row{}; row < y_; ++row) {
matrix_[row].resize(x_);
for (std::size_t col{}; col < x_; ++col) {
matrix_[row][col].resize(layer_);
for (std::size_t layer{}; layer < layer_; ++layer)
matrix_[row][col][layer_] = value_;
}
}
}
template<typename Matrix_>
constexpr void resize(Matrix_& matrix_, const std::size_t layer_) noexcept {
for (std::size_t row{}; row < matrix_.size(); ++row)
for (std::size_t col{}; col < matrix_[row].size(); ++col)
matrix_[row][col].resize(layer_);
}
template<typename Matrix_Int_, typename Matrix_>
constexpr void resize(Matrix_& matrix_, const std::size_t layer_, const Matrix_Int_ value_) noexcept {
for (std::size_t row{}; row < matrix_.size(); ++row)
for (std::size_t col{}; col < matrix_[row].size(); ++col) {
matrix_[row][col].resize(layer_);
for (std::size_t layer{}; layer < layer_; ++layer)
matrix_[row][col][layer_] = value_;
}
}

}

//ダンジョン内の値を初期化する
template<typename Matrix_>
constexpr void init(Matrix_& matrix_) noexcept {
for (std::size_t row{}; row < matrix_.size(); ++row)
for (std::size_t col{}; col < matrix_[row].size(); ++col)
matrix_[row][col] = 0;
}
template<typename Matrix_Int_, typename Matrix_>
constexpr void init(Matrix_& matrix_, const Matrix_Int_ value_) noexcept {
for (std::size_t row{}; row < matrix_.size(); ++row)
for (std::size_t col{}; col < matrix_[row].size(); ++col)
matrix_[row][col] = value_;
}
template<typename Matrix_>
constexpr void init(Matrix_& matrix_, const std::size_t x_, const std::size_t y_) noexcept {
for (std::size_t row{}; row < y_; ++row)
for (std::size_t col{}; col < x_; ++col)
matrix_[row][col] = 0;
}
template<typename Matrix_Int_, typename Matrix_>
constexpr void init(Matrix_& matrix_, const std::size_t x_, const std::size_t y_, const Matrix_Int_ value_) noexcept {
for (std::size_t row{}; row < y_; ++row)
for (std::size_t col{}; col < x_; ++col)
matrix_[row][col] = value_;
}

//上下反転
template<typename Matrix_>
constexpr void flip(Matrix_& matrix_) noexcept {
for (std::size_t row{}, row2{ matrix_.size() - 1 };; ++row, --row2) {
if (row >= row2) break;
for (std::size_t col{}; col < matrix_[row].size(); ++col) {
const auto&& tmp{ (matrix_[row][col] + 0) };
matrix_[row][col] = matrix_[row2][col];
matrix_[row2][col] = std::move(tmp);
}
}
}
//左右反転
template<typename Matrix_>
constexpr void mirror(Matrix_& matrix_) noexcept {
for (std::size_t row{}; row < matrix_.size(); ++row)
for (std::size_t col{}, col2{ matrix_[row].size() - 1 };; ++col, --col2) {
if (col >= col2) break;
const auto&& tmp{ (matrix_[row][col] + 0) };
matrix_[row][col] = matrix_[row][col2];
matrix_[row][col2] = std::move(tmp);
}
}

template<typename Matrix_>
constexpr void copy(Matrix_& matrix_, const Matrix_& matrix2_) noexcept {
matrix_ = matrix2_;
}
template<typename Matrix_, typename Matrix2_>
constexpr void copy(Matrix_& matrix_, const Matrix2_& matrix2_) noexcept {
for (std::size_t row{}; row < matrix_.size(); ++row)
for (std::size_t col{}; col < matrix_[row].size(); ++col)
matrix_[row][col] = matrix2_[row][col];
}

template<typename Matrix_, typename Matrix2_>
constexpr void convertSTL_intoDefault(Matrix_& matrix_, std::size_t& x_, std::size_t& y_, const Matrix2_& matrix2_) noexcept {
for (std::size_t row{}; row < matrix_.size(); ++row)
for (std::size_t col{}; col < matrix_[row].size(); ++col)
matrix_[row][col] = matrix2_[row][col];
((y_ = matrix2_.size()) == 0) ? (x_ = 0) : (x_ = matrix2_[0].size());
}
template<typename Matrix_, typename Matrix2_>
constexpr void convertSTL_intoArray(Matrix_& matrix_, std::size_t& x_, std::size_t& y_, const Matrix2_& matrix2_) noexcept {
for (std::size_t row{}; row < matrix_.size(); ++row)
for (std::size_t col{}; col < matrix_[row].size(); ++col)
matrix_[row*x_ + col] = matrix2_[row][col];
((y_ = matrix2_.size()) == 0) ? (x_ = 0) : (x_ = matrix2_[0].size());
}
template<typename Matrix_, typename Matrix2_>
constexpr void convertSTL_intoLayer(Matrix_& matrix_, std::size_t& layer_, const Matrix2_& matrix2_) noexcept {
for (std::size_t row{}; row < matrix_.size(); ++row)
for (std::size_t col{}; col < matrix_[row].size(); ++col)
matrix_[row][col][layer_] = matrix2_[row][col];
}



}

}

#endif //Included Dungeon Template Library
12 changes: 6 additions & 6 deletions include/cpp14/DungeonNoise.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace dtl {
constexpr void noiseShoreBool(Matrix_& matrix_, const double rbool_) noexcept {
for (std::size_t row{ 1 }; row < matrix_.size(); ++row)
for (std::size_t col{ 1 }; col < matrix_[row].size(); ++col) {
if (!rnd.randBool(rbool_) || (matrix_[row][col] == matrix_[row][col - 1] && matrix_[row][col] == matrix_[row - 1][col])) continue;
if ((matrix_[row][col] == matrix_[row][col - 1] && matrix_[row][col] == matrix_[row - 1][col]) || !rnd.randBool(rbool_)) continue;
if (matrix_[row][col]) matrix_[row][col] = false;
else matrix_[row][col] = true;
}
Expand All @@ -47,7 +47,7 @@ namespace dtl {
constexpr void rnoiseShoreBool(Matrix_& matrix_, const double rbool_) noexcept {
for (std::size_t row{ matrix_.size() - 1 }; row >= 1; --row)
for (std::size_t col{ matrix_[row].size() - 1 }; col >= 1; --col) {
if (!rnd.randBool(rbool_) || (matrix_[row - 1][col - 1] == matrix_[row][col - 1] && matrix_[row - 1][col - 1] == matrix_[row - 1][col])) continue;
if ((matrix_[row - 1][col - 1] == matrix_[row][col - 1] && matrix_[row - 1][col - 1] == matrix_[row - 1][col]) || !rnd.randBool(rbool_)) continue;
if (matrix_[row - 1][col - 1]) matrix_[row - 1][col - 1] = false;
else matrix_[row - 1][col - 1] = true;
}
Expand Down Expand Up @@ -78,7 +78,7 @@ namespace dtl {
constexpr void noiseShore(Matrix_& matrix_, const double rbool_, const Matrix_Int_ true_tile_ = 1, const Matrix_Int_ false_tile_ = 0) noexcept {
for (std::size_t row{ 1 }; row < matrix_.size(); ++row)
for (std::size_t col{ 1 }; col < matrix_[row].size(); ++col) {
if (!rnd.randBool(rbool_) || (matrix_[row][col] == matrix_[row][col - 1] && matrix_[row][col] == matrix_[row - 1][col])) continue;
if ((matrix_[row][col] == matrix_[row][col - 1] && matrix_[row][col] == matrix_[row - 1][col]) || !rnd.randBool(rbool_)) continue;
if (matrix_[row][col]) matrix_[row][col] = false_tile_;
else matrix_[row][col] = true_tile_;
}
Expand All @@ -87,7 +87,7 @@ namespace dtl {
constexpr void rnoiseShore(Matrix_& matrix_, const double rbool_, const Matrix_Int_ true_tile_ = 1, const Matrix_Int_ false_tile_ = 0) noexcept {
for (std::size_t row{ matrix_.size() - 1 }; row >= 1; --row)
for (std::size_t col{ matrix_[row].size() - 1 }; col >= 1; --col) {
if (!rnd.randBool(rbool_) || (matrix_[row - 1][col - 1] == matrix_[row][col - 1] && matrix_[row - 1][col - 1] == matrix_[row - 1][col])) continue;
if ((matrix_[row - 1][col - 1] == matrix_[row][col - 1] && matrix_[row - 1][col - 1] == matrix_[row - 1][col]) || !rnd.randBool(rbool_)) continue;
if (matrix_[row - 1][col - 1]) matrix_[row - 1][col - 1] = false_tile_;
else matrix_[row - 1][col - 1] = true_tile_;
}
Expand All @@ -97,7 +97,7 @@ namespace dtl {
constexpr void noiseShoreOver(Matrix_& matrix_, const double rbool_, const Matrix_Int_ true_tile_ = 1, const Matrix_Int_ false_tile_ = 0) noexcept {
for (std::size_t row{ 1 }; row < matrix_.size(); ++row)
for (std::size_t col{ 1 }; col < matrix_[row].size(); ++col) {
if (!rnd.randBool(rbool_) || (matrix_[row][col] == matrix_[row][col - 1] && matrix_[row][col] == matrix_[row - 1][col])) continue;
if ((matrix_[row][col] == matrix_[row][col - 1] && matrix_[row][col] == matrix_[row - 1][col]) || !rnd.randBool(rbool_)) continue;
if (matrix_[row][col] >= true_tile_) matrix_[row][col] = false_tile_;
else matrix_[row][col] = true_tile_;
}
Expand All @@ -106,7 +106,7 @@ namespace dtl {
constexpr void rnoiseShoreOver(Matrix_& matrix_, const double rbool_, const Matrix_Int_ true_tile_ = 1, const Matrix_Int_ false_tile_ = 0) noexcept {
for (std::size_t row{ matrix_.size() - 1 }; row >= 1; --row)
for (std::size_t col{ matrix_[row].size() - 1 }; col >= 1; --col) {
if (!rnd.randBool(rbool_) || (matrix_[row - 1][col - 1] == matrix_[row][col - 1] && matrix_[row - 1][col - 1] == matrix_[row - 1][col])) continue;
if ((matrix_[row - 1][col - 1] == matrix_[row][col - 1] && matrix_[row - 1][col - 1] == matrix_[row - 1][col]) || !rnd.randBool(rbool_)) continue;
if (matrix_[row - 1][col - 1] >= true_tile_) matrix_[row - 1][col - 1] = false_tile_;
else matrix_[row - 1][col - 1] = true_tile_;
}
Expand Down
28 changes: 28 additions & 0 deletions include/cpp14/DungeonPaint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,34 @@
//Dungeon Template Library Namespace
namespace dtl {

//beta
template<typename Matrix_Int_>
class PaintTrajectory
{
public:
constexpr PaintTrajectory(const std::size_t size_) :
type(std::make_unique<std::uint_fast8_t[]>(size_)),
value(std::make_unique<Matrix_Int_[]>(size_)),
x(std::make_unique<std::size_t[]>(size_)),
y(std::make_unique<std::size_t[]>(size_)),
size(size_) {}

//void add(const std::uint_fast8_t type_, const Matrix_Int_ value_) noexcept {

//}
private:
std::unique_ptr<std::uint_fast8_t[]> type;
std::unique_ptr<Matrix_Int_[]> value;
std::unique_ptr<std::size_t[]> x;
std::unique_ptr<std::size_t[]> y;

std::size_t start{};
std::size_t end{};
std::size_t now{};
std::size_t size{};
};


struct BucketBuffer {
std::int_fast32_t left_x{};
std::int_fast32_t right_x{};
Expand Down
Loading

0 comments on commit 834a431

Please sign in to comment.