ScummVM API documentation
TileInfo.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 /*
23  * This code is based on the CRAB engine
24  *
25  * Copyright (c) Arvind Raja Yadav
26  *
27  * Licensed under MIT
28  *
29  */
30 
31 #ifndef CRAB_TILEINFO_H
32 #define CRAB_TILEINFO_H
33 
34 #include "crab/loaders.h"
35 
36 namespace Crab {
37 
38 namespace TMX {
39 typedef uint GidFormat;
40 
41 // Bits on the far end of the 32-bit global tile ID are used for tile flags
42 const static GidFormat FlippedHorizontallyFlag = 0x80000000;
43 const static GidFormat FlippedVerticallyFlag = 0x40000000;
44 const static GidFormat FlippedAntiDiagonallyFlag = 0x20000000;
45 
46 struct TileInfo {
47  // The gid of the tile
48  GidFormat _gid;
49 
50  // Do we need to flip this tile?
51  TextureFlipType _flip;
52 
53  TileInfo() {
54  _gid = 0;
55  _flip = FLIP_NONE;
56  }
57 
58  TileInfo(rapidxml::xml_node<char> *node) {
59  // Load the gid of the tile
60  if (!loadNum(_gid, "gid", node))
61  _gid = 0;
62 
63  bool horizontal = (_gid & FlippedHorizontallyFlag) != 0;
64  bool vertical = (_gid & FlippedVerticallyFlag) != 0;
65  bool antidiagonal = (_gid & FlippedAntiDiagonallyFlag) != 0;
66 
67  // Find how the tile is flipped
68  if (horizontal) {
69  if (vertical) {
70  if (antidiagonal)
71  _flip = FLIP_XYD;
72  else
73  _flip = FLIP_XY;
74  } else if (antidiagonal)
75  _flip = FLIP_DX;
76  else
77  _flip = FLIP_X;
78  } else if (vertical) {
79  if (antidiagonal)
80  _flip = FLIP_DY;
81  else
82  _flip = FLIP_Y;
83  } else if (antidiagonal)
84  _flip = FLIP_D;
85  else
86  _flip = FLIP_NONE;
87 
88  // Clear the flags
89  _gid &= ~(FlippedHorizontallyFlag | FlippedVerticallyFlag | FlippedAntiDiagonallyFlag);
90  }
91 
92  bool operator==(const TileInfo& other) const {
93  return (_gid == other._gid) && (_flip == other._flip);
94  }
95 };
96 } // End of namespace TMX
97 
98 } // End of namespace Crab
99 
100 #endif // CRAB_TILEINFO_H
Definition: moveeffect.h:37
Definition: TileInfo.h:46