-
Notifications
You must be signed in to change notification settings - Fork 0
/
V2TileInfo.cpp
79 lines (75 loc) · 2.52 KB
/
V2TileInfo.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
* Tileset Tool, an editor for Commander Keen: Invasion of the Vorticons
* Tilesets.
* Copyright (C) 2010-2012 Kyle Delaney
*
* This file is a part of Tileset Tool.
*
* Tileset Tool is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Tileset Tool is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* You may contact the author at <dr.kylstein@gmail.com>
*/
#include "V2TileInfo.hpp"
bool V2TileInfo::load(QDataStream& stream) {
for(int i = 0; i < TILES; ++i) {
if(stream.atEnd()) return false;
stream >> tileProperties[i].behavior;
}
quint8 b;
for(int side = 0; side < 4; ++side) {
for(int tile = 0; tile < TILES; ++tile) {
if(stream.atEnd()) return false;
stream >> b;
tileProperties[tile].style[side] = (b & 0x03);
tileProperties[tile].slopeEnabled[side] = b & 0x80;
tileProperties[tile].b[side] = (b & 0x0C) >> 2;
tileProperties[tile].m[side] = (b & 0x30) >> 4;
tileProperties[tile].negativeSlope[side] = b & 0x40;
}
}
return true;
}
void V2TileInfo::dump(QDataStream& stream) {
for(int tile = 0; tile < TILES; ++tile) {
stream << tileProperties[tile].behavior;
}
quint8 b = 0;
for(int side = 0; side < 4; ++side) {
for(int tile = 0; tile < TILES; ++tile) {
b = 0;
b = tileProperties[tile].style[side] & 0x03;
if(tileProperties[tile].slopeEnabled[side]) {
b |= 0x80;
}
b |= (tileProperties[tile].b[side] & 0x03) << 2;
b |= (tileProperties[tile].m[side] & 0x03) << 4;
if(tileProperties[tile].negativeSlope[side]) {
b |= 0x40;
}
stream << b;
}
}
}
V2TileInfo::V2TileInfo() {
for(int tile = 0; tile < TILES; ++tile) {
tileProperties[tile].behavior = 0;
for(int side = 0; side < 4; ++side) {
tileProperties[tile].style[side] = 0;
tileProperties[tile].slopeEnabled[side] = false;
tileProperties[tile].b[side] = 0;
tileProperties[tile].m[side] = 0;
tileProperties[tile].negativeSlope[side] = false;
}
}
}