mirror of
https://github.com/AquariaOSE/Aquaria.git
synced 2024-11-25 09:44:02 +00:00
d7ff053efd
This also fixes a long-standing off-by-one with the generated ObsRows: Before this commit, the game would (upon F11) eat every black pixel from the map template that was directly left of a white pixel, eg. #### ## # ## ... would become ### # # ... GENERATED MAPS ARE NOW DIFFERENT! With this bug gone, dumping obs (F8) and loading that back in as a map template (F11) should now be fully round-trip compatible and not lose pixels anymore. Extra feature: (R>=200, G in [128..199], B>=200) in the map template now designate zones that should not be obstructed but also not generate border rocks when skinned (F12). Makes editing energy temple styled maps much easier since we don't have to manually erase tiles on layer "5" anymore, all the time.
77 lines
1.7 KiB
C++
77 lines
1.7 KiB
C++
#ifndef BBGE_DATASTRUCTURES_H
|
|
#define BBGE_DATASTRUCTURES_H
|
|
|
|
#include <stddef.h>
|
|
#include <vector>
|
|
#include <algorithm>
|
|
#include <assert.h>
|
|
|
|
template<typename T>
|
|
class Array2d
|
|
{
|
|
protected:
|
|
size_t _w, _h;
|
|
std::vector<T> _v;
|
|
|
|
public:
|
|
Array2d() : _w(0), _h(0) {}
|
|
Array2d(size_t w, size_t h) : _w(w), _h(h), _v(w*h) {}
|
|
|
|
size_t width() const {return _w;}
|
|
size_t height() const {return _h;}
|
|
void init(size_t w, size_t h)
|
|
{
|
|
_w = w;
|
|
_h = h;
|
|
_v.resize(w*h);
|
|
}
|
|
|
|
void clear()
|
|
{
|
|
_w = _h = 0;
|
|
_v.clear();
|
|
}
|
|
|
|
void fill(const T& v)
|
|
{
|
|
std::fill(_v.begin(), _v.end(), v);
|
|
}
|
|
|
|
void copy2d(size_t dstx, size_t dsty, const Array2d<T>& src, size_t srcx, size_t srcy, size_t w, size_t h)
|
|
{
|
|
assert(dstx + w <= width());
|
|
assert(dsty + h <= height());
|
|
assert(srcx + w <= src.width());
|
|
assert(srcy + h <= src.height());
|
|
|
|
for(size_t y = 0; y < h; ++y)
|
|
{
|
|
T *dstrow = row(dsty + y);
|
|
const T *srcrow = src.row(srcy + y);
|
|
std::copy(srcrow + srcx, srcrow + srcx + w, dstrow + dstx);
|
|
}
|
|
}
|
|
|
|
const T& at(size_t x, size_t y, const T& def) const
|
|
{
|
|
return x < _w && y < _h ? _v[y * _w + x] : def;
|
|
}
|
|
|
|
inline T& operator()(size_t x, size_t y)
|
|
{
|
|
return _v[y * _w + x];
|
|
}
|
|
inline const T& operator()(size_t x, size_t y) const
|
|
{
|
|
return _v[y * _w + x];
|
|
}
|
|
|
|
const T *data() const { return _v.empty() ? NULL : &_v[0]; }
|
|
T *data() { return _v.empty() ? NULL : &_v[0]; }
|
|
|
|
const T *row(size_t y) const { return &_v[y * _w]; }
|
|
T *row(size_t y) { return &_v[y * _w]; }
|
|
};
|
|
|
|
|
|
#endif
|