载入中...
搜索中...
未找到
TileBuffer.cpp
浏览该文件的文档.
2
3#include "common/Exception.h"
4
5#include <algorithm>
6
7namespace eve::level_editing {
8
10 if (width <= 0 || height <= 0) throw Exception("TileBuffer: width/height must be > 0");
11 width_ = width;
12 height_ = height;
13 gids_.assign(static_cast<size_t>(width_) * static_cast<size_t>(height_), 0);
14}
15
17 if (width <= 0 || height <= 0) throw Exception("TileBuffer::resize: width/height must be > 0");
18 std::vector<int> next(static_cast<size_t>(width) * static_cast<size_t>(height), 0);
19 int copyW = std::min(width, width_);
20 int copyH = std::min(height, height_);
21 for (int y = 0; y < copyH; ++y) {
22 for (int x = 0; x < copyW; ++x) {
23 next[static_cast<size_t>(y * width + x)] = gids_[static_cast<size_t>(y * width_ + x)];
24 }
25 }
26 width_ = width;
27 height_ = height;
28 gids_.swap(next);
29}
30
31void TileBuffer::clear() { std::fill(gids_.begin(), gids_.end(), 0); }
32
33void TileBuffer::fill(int gid) { std::fill(gids_.begin(), gids_.end(), gid); }
34
35bool TileBuffer::containsCell(int x, int y) const { return x >= 0 && y >= 0 && x < width_ && y < height_; }
36
37void TileBuffer::setGid(int x, int y, int gid) {
38 if (!containsCell(x, y)) throw Exception("TileBuffer::setGid: out of bounds");
39 gids_[static_cast<size_t>(index(x, y))] = gid;
40}
41
42int TileBuffer::getGid(int x, int y) const {
43 if (!containsCell(x, y)) throw Exception("TileBuffer::getGid: out of bounds");
44 return gids_[static_cast<size_t>(index(x, y))];
45}
46
47} // namespace eve::level_editing
float y
Definition AnimClip.cpp:738
float x
Definition AnimClip.cpp:738
std::uint32_t height
std::uint32_t width
uint32_t index
EVENGINE_API_FOUNDATION public API.
Definition Exception.h:13
void setGid(int x, int y, int gid)
Sets the gid.
void resize(int width, int height)
Resize.
bool containsCell(int x, int y) const
Return whether a cell belongs to this buffer.
int getGid(int x, int y) const
Returns the gid.
TileBuffer(int width, int height)
Tile buffer.
Definition TileBuffer.cpp:9