-
Notifications
You must be signed in to change notification settings - Fork 0
/
chunk.cpp
54 lines (45 loc) · 1.04 KB
/
chunk.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "chunk.hpp"
#include <cstring>
#include <cmath>
IChunk::IChunk(const stf::Vec2d &size)
: Size{size} { }
IChunk::~IChunk()
{
for(size_t i = 0; i < mArray.size(); ++i)
delete mArray.at(i);
}
const stf::Vec2d &IChunk::size() const
{
return Size;
}
ICell *IChunk::put(const stf::Vec2d &pos, ICell *cell)
{
return mArray[Size.x * std::abs(pos.y % Size.y) + std::abs(pos.x % Size.x)] = cell;
}
ICell *IChunk::operator [](const stf::Vec2d &pos)
{
return mArray[Size.x * std::abs(pos.y % Size.y) + std::abs(pos.x % Size.x)];
}
ICell *IChunk::at(const stf::Vec2d &pos)
{
return mArray[Size.x * std::abs(pos.y % Size.y) + std::abs(pos.x % Size.x)];
}
size_t IChunk::sizeOfSelf() const
{
size_t size = 0;
for(auto &c : mArray)
size += c->sizeOfSelf();
return mArray.size() * size + sizeof(uint8_t);
}
IChunk &IChunk::save(FILE *file)
{
for(auto &c : mArray)
c->save(file);
return *this;
}
IChunk &IChunk::load(FILE *file)
{
for(auto &c : mArray)
c->load(file);
return *this;
}