From f9db81c6c4e160160cc4fd190e838a971784fbe0 Mon Sep 17 00:00:00 2001 From: Relintai Date: Sun, 24 Apr 2022 01:39:47 +0200 Subject: [PATCH] Added new helper methods to Array2D. --- modules/wfc/array_2d.h | 44 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/modules/wfc/array_2d.h b/modules/wfc/array_2d.h index 308007a50..d31f99487 100644 --- a/modules/wfc/array_2d.h +++ b/modules/wfc/array_2d.h @@ -2,6 +2,8 @@ #define FAST_WFC_UTILS_ARRAY2D_HPP_ #include "core/vector.h" +#include "core/pool_vector.h" +#include "core/variant.h" template class Array2D { @@ -29,6 +31,28 @@ public: data.fill(p_value); } + Array2D(const PoolIntArray &p_data, int p_height, int p_width) { + int wh = p_width * p_height; + if (wh != p_data.size()) { + width = 0; + height = 0; + ERR_FAIL_MSG("wh != p_data.size()"); + } + + height = p_height; + width = p_width; + data.resize(wh); + + int *w = data.ptrw(); + int s = data.size(); + + PoolIntArray::Read r = p_data.read(); + + for (int i = 0; i < s; ++i) { + w[i] = r[i]; + } + } + void resize(int p_height, int p_width) { height = p_height; width = p_width; @@ -42,6 +66,26 @@ public: data.fill(p_value); } + void set_data(const PoolIntArray &p_data, int p_height, int p_width) { + int wh = p_width * p_height; + ERR_FAIL_COND(wh != p_data.size()); + + resize(p_height, p_width); + + height = p_height; + width = p_width; + data.resize(wh); + + int *w = data.ptrw(); + int s = data.size(); + + PoolIntArray::Read r = p_data.read(); + + for (int i = 0; i < s; ++i) { + w[i] = r[i]; + } + } + const T &get(int i, int j) const { CRASH_BAD_INDEX(i, height); CRASH_BAD_INDEX(j, width);