1 #ifndef CORE_MAPS_LAYER_HPP
2 #define CORE_MAPS_LAYER_HPP
4 #include <BLIB/Logging.hpp>
5 #include <BLIB/Serialization.hpp>
57 const T&
get(
unsigned int x,
unsigned int y)
const;
66 T&
getRef(
unsigned int x,
unsigned int y);
75 void set(
unsigned int x,
unsigned int y,
const T& value);
82 friend struct bl::serial::SerializableObject<
Layer<T>>;
97 data.resize(width * height, val);
112 const unsigned int i = y * w + x;
113 if (i < data.size()) {
return data[i]; }
115 static const T
null{};
116 BL_LOG_WARN <<
"Out of bounds layer access: pos=(" << x <<
"," << y <<
") size=(" << w
124 const unsigned int i = y * w + x;
125 if (i < data.size()) {
return data[i]; }
128 BL_LOG_WARN <<
"Out of bounds layer access: pos=(" << x <<
"," << y <<
") size=(" << w
136 const unsigned int i = y * w + x;
137 if (i < data.size()) { data[i] = value; }
148 struct SerializableObject<
core::map::Layer<T>> :
public SerializableObjectBase {
151 SerializableField<1, Layer, std::uint32_t>
w;
152 SerializableField<2, Layer, std::uint32_t>
h;
153 SerializableField<3, Layer, std::vector<T>>
data;
156 : SerializableObjectBase(
"MapLayer")
157 , w(
"w", *this, &
Layer::w, SerializableFieldBase::Required{})
158 , h(
"h", *this, &
Layer::h, SerializableFieldBase::Required{})
159 , data(
"data", *this, &
Layer::data, SerializableFieldBase::Required{}) {}
Core classes and functionality for both the editor and game.
Generic map layer class. Can be used for any type of layer.
void create(unsigned int width, unsigned int height, const T &val=T())
Clears all stored data (if any) and creates the layer with the given size.
void set(unsigned int x, unsigned int y, const T &value)
Sets the object in the layer at the position to the given value.
unsigned int width() const
Returns the width of the layer in tiles.
unsigned int height() const
Returns the height of the layer in tiles.
T & getRef(unsigned int x, unsigned int y)
Returns the object in the layer at the given position.
Layer()
Construct an empty layer.
const T & get(unsigned int x, unsigned int y) const
Returns the object in the layer at the given position.
SerializableField< 1, Layer, std::uint32_t > w
SerializableField< 3, Layer, std::vector< T > > data
SerializableField< 2, Layer, std::uint32_t > h