ScummVM API documentation
oncall.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_ONCALL_H
27 #define SAGA2_ONCALL_H
28 
29 namespace Saga2 {
30 
31 class HandleArray {
32 private:
33  Common::Array<byte*> _handles;
34  uint32 _tileID;
35  byte *(*_loader)(hResID, bool);
36 public:
37  HandleArray(uint16 size, byte*(*loadfunction)(hResID, bool), uint32 newID) {
38  for (int i = 0; i < size; ++i)
39  _handles.push_back(nullptr);
40  _loader = loadfunction;
41  _tileID = newID;
42  }
43 
44  void flush() {
45  for (unsigned int i = 0; i < _handles.size(); ++i) {
46  if (_handles[i]) {
47  free(_handles[i]);
48  _handles[i] = nullptr;
49  }
50  }
51  }
52 
53  byte *operator[](uint32 ind) {
54  if (_handles[ind])
55  return _handles[ind];
56 
57  return _handles[ind] = _loader(_tileID + MKTAG(0, 0, 0, ind), false);
58  }
59 };
60 
61 } // end of namespace Saga2
62 
63 #endif
Definition: actor.h:32
void push_back(const T &element)
Definition: array.h:180
size_type size() const
Definition: array.h:315
#define MKTAG(a0, a1, a2, a3)
Definition: endian.h:188
Definition: oncall.h:31