mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2025-01-26 02:49:18 +01:00
Added new helper methods to Array2D.
This commit is contained in:
parent
3ba0a856a3
commit
f9db81c6c4
@ -2,6 +2,8 @@
|
||||
#define FAST_WFC_UTILS_ARRAY2D_HPP_
|
||||
|
||||
#include "core/vector.h"
|
||||
#include "core/pool_vector.h"
|
||||
#include "core/variant.h"
|
||||
|
||||
template <typename T>
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user