ScummVM API documentation
tileload.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  * aint32 with this program; if not, write to the Free Software
19  *
20  *
21  * Based on the original sources
22  * Faery Tale II -- The Halls of the Dead
23  * (c) 1993-1996 The Wyrmkeep Entertainment Co.
24  */
25 
26 #ifndef SAGA2_TILELOAD_H
27 #define SAGA2_TILELOAD_H
28 
29 namespace Saga2 {
30 
31 const int kMaxBanks = 64; // 64 banks maximum
32 
33 /* ============================================================================ *
34  TileBank request bits
35  * ============================================================================ */
36 
37 // To facilitate loading of tile banks on demand, a bit-array
38 // is used to indicate which banks are needed for each metatile
39 // to render.
40 
41 class BankBits {
42 public:
43  uint32 _b[kMaxBanks / 32];
44 
45  // constructors
46  BankBits() {}
47  BankBits(uint32 c, uint32 d) {
48  _b[0] = c;
49  _b[1] = d;
50  }
51 
52  // BankBits operators
53  friend BankBits operator+ (BankBits c, BankBits d) {
54  return BankBits(c._b[0] + d._b[0], c._b[1] + d._b[1]);
55  }
56 
57  friend BankBits operator- (BankBits c, BankBits d) {
58  return BankBits(c._b[0] - d._b[0], c._b[1] - d._b[1]);
59  }
60 
61  void operator>>=(int a) {
62  bool c = (bool)(_b[0] & 1);
63  _b[0] >>= (uint32)a;
64  _b[1] >>= (uint32)a;
65  _b[1] |= ((1 << 31) & (uint32)c);
66  }
67  void operator<<=(int a) {
68  bool c = (bool)(_b[1] & (1 << 31));
69  _b[0] >>= (uint32)a;
70  _b[0] |= (1 & (uint32)c);
71  _b[1] >>= (uint32)a;
72  }
73 
74  friend BankBits operator& (BankBits c, BankBits d) {
75  return BankBits(c._b[0] & d._b[0], c._b[1] & d._b[1]);
76  }
77 
78  friend BankBits operator| (BankBits c, BankBits d) {
79  return BankBits(c._b[0] | d._b[0], c._b[1] | d._b[1]);
80  }
81 
82  friend BankBits operator|= (BankBits c, BankBits d) {
83  return BankBits(c._b[0] |= d._b[0], c._b[1] |= d._b[1]);
84  }
85 
86  friend bool operator!= (BankBits c, BankBits d) {
87  return (c._b[0] != d._b[0] && c._b[1] != d._b[1]);
88  }
89 
90  friend BankBits operator^ (BankBits c, BankBits d) {
91  return BankBits(c._b[0] ^ d._b[0], c._b[1] ^ d._b[1]);
92  }
93 
94  bool isSet(uint16 i) {
95  return (bool)(_b[i >> 5] & ((uint32) 1 << (i & 31)));
96  }
97 
98  void SetBit(int16 i) {
99  _b[i / 32] |= ((uint32) 1 << (i % 32)) ;
100  }
101  void NotBit(int16 i) {
102  _b[i / 32] &= ~((uint32) 1 << (i % 32));
103  }
104  void Reset(uint32 c, uint32 d) {
105  _b[0] = c;
106  _b[1] = d;
107  }
108  bool Test() {
109  return (_b[0] || _b[1]);
110  }
111 
112  // Point16 functions
113 
114 };
115 
116 class bitArray {
117 private:
118  uint32 *_b;
119  uint16 _size;
120 public:
121  bitArray(uint16 newSize);
122  ~bitArray();
123 
124  bool operator[](uint16 i) {
125  if (i < _size) return (bool)(_b[i / 32] & (1 << (i % 32)));
126  else return false;
127  }
128  void resize(uint16 newSize);
129 
130 };
131 
132 template<int size> class FixedBitArray {
133 private:
134  enum {
135  klWords = ((size + 31) / 32)
136  };
137 
138  int16 WORDNUM(int n) {
139  return (n >> 5);
140  }
141  int16 BITNUM(int n) {
142  return (n & 31);
143  }
144  int16 BITMASK(int n) {
145  return (1 << (n & 31));
146  }
147 
148  uint32 _b[klWords];
149 
150  void clear() {
151  memset(&_b, 0, sizeof _b);
152  }
153 
154 public:
155 
156  FixedBitArray() {
157  clear();
158  }
159 
160  uint32 getChunk(uint16 i) {
161  return _b[i];
162  }
163 
164  bool operator[](uint32 ind) {
165  return (ind < size && (_b[WORDNUM(ind)] & BITMASK(ind)));
166  }
167 
168  void Bit(uint32 ind, bool val) {
169  if (ind < size) {
170  if (val) _b[WORDNUM(ind)] |= BITMASK(ind);
171  else _b[WORDNUM(ind)] &= ~BITMASK(ind);
172  }
173  }
174 
175  void clearAll() {
176  clear();
177  }
178 
179 // Untested below here
180 
181  friend FixedBitArray operator& (FixedBitArray c, FixedBitArray d) {
182  FixedBitArray t;
183 
184  for (uint16 i = 0; i < klWords; i++)
185  t._b[i] = c._b[i] & d._b[i];
186  return t;
187  }
188 
189  friend FixedBitArray operator| (FixedBitArray c, FixedBitArray d) {
190  FixedBitArray t;
191 
192  for (uint16 i = 0; i < klWords; i++)
193  t._b[i] = c._b[i] | d._b[i];
194  return t;
195  }
196 
197  friend FixedBitArray &operator|= (FixedBitArray c, FixedBitArray d) {
198  for (uint16 i = 0; i < klWords; i++)
199  c._b[i] |= d._b[i];
200  return c;
201  }
202 
203  friend bool operator!= (FixedBitArray c, FixedBitArray d) {
204  for (uint16 i = 0; i < klWords; i++)
205  if (c._b[i] != d._b[i]) return true;
206  return false;
207  }
208 
209  friend FixedBitArray operator^ (FixedBitArray c, FixedBitArray d) {
210  FixedBitArray t;
211 
212  for (uint16 i = 0; i < klWords; i++)
213  t._b[i] = c._b[i] ^ d._b[i];
214  return t;
215  }
216 };
217 
218 } // end of namespace Saga2
219 
220 #endif
Definition: actor.h:32
Definition: tileload.h:132
Definition: tileload.h:116
Definition: tileload.h:41