ScummVM API documentation
grid.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 #ifndef TWINE_SCENE_GRID_H
23 #define TWINE_SCENE_GRID_H
24 
25 #define WATER_BRICK (0xF1)
26 
27 #include "common/scummsys.h"
28 #include "twine/parser/blocklibrary.h"
29 #include "twine/parser/sprite.h"
30 #include "twine/shared.h"
31 
32 namespace Graphics {
33 class ManagedSurface;
34 }
35 
36 namespace TwinE {
37 
38 class ActorStruct;
39 
41 struct BlockEntry {
43  uint8 blockIdx = 0;
45  uint8 brickBlockIdx = 0;
46 };
48 struct BrickEntry {
50  int16 x = 0; //z
52  int16 y = 0;
54  int16 z = 0; // x
56  int16 posX = 0;
58  int16 posY = 0;
60  int16 index = 0;
62  uint8 shape = 0;
64  uint8 sound = 0;
65 };
66 
68 #define NUM_BRICKS 9000
69 
71 #define SIZE_CUBE_X 64
72 
73 #define SIZE_CUBE_Y 25
74 
75 #define SIZE_CUBE_Z SIZE_CUBE_X
76 
77 #define ISO_SCALE 512
78 #define SIZE_BRICK_XZ 512
79 #define SIZE_BRICK_Y 256
80 #define DEMI_BRICK_XZ 256
81 #define DEMI_BRICK_Y 128
82 // short max 32767 0x7FFF
83 // 32256 0x7E00
84 // 32000 0x7D00
85 #define SCENE_SIZE_MAX (SIZE_BRICK_XZ * (SIZE_CUBE_X - 1))
86 // short min -32768
87 #define SCENE_SIZE_MIN (-SIZE_BRICK_XZ * SIZE_CUBE_X)
88 #define SCENE_SIZE_HALF (SIZE_BRICK_XZ * SIZE_CUBE_X / 2)
89 #define SCENE_SIZE_HALFF (SIZE_BRICK_XZ * SIZE_CUBE_X / 2.0f)
90 
91 #define MAXBRICKS 150
92 
93 class TwinEEngine;
94 
95 class Grid {
96 private:
97  TwinEEngine *_engine;
98 
107  void drawColumnGrid(int32 blockIdx, int32 brickBlockIdx, int32 x, int32 y, int32 z);
114  void getBrickPos(int32 x, int32 y, int32 z, int32 &_brickPixelPosX, int32 &_brickPixelPosY) const;
119  void createCellingGridMap(const uint8 *gridPtr, int32 gridPtrSize);
125  void calcGraphMsk(const uint8 *gridEntry, uint32 gridEntrySize, uint8 *dest, uint32 destSize);
131  void decompColumn(const uint8 *gridEntry, uint32 gridEntrySize, uint8 *dest, uint32 destSize);
135  void loadGridBricks();
137  void createGridMask();
143  void processGridMask(const uint8 *buffer, uint8 *ptr);
151  void copyMask(int32 index, int32 x, int32 y, const Graphics::ManagedSurface &buffer);
152 
154  uint8 *_brickTable[NUM_BRICKS]{nullptr};
156  uint8 *_brickMaskTable[NUM_BRICKS]{nullptr};
158  uint32 _brickSizeTable[NUM_BRICKS]{0};
160  uint8 _brickUsageTable[NUM_BRICKS]{0};
161 
163  int32 _currentGridSize = 0;
164  uint8 *_currentGrid = nullptr;
166  BlockLibraryData _currentBlockLibrary;
167 
169  BrickEntry *_bricksDataBuffer = nullptr;
171  int16 *_brickInfoBuffer = nullptr;
172  int32 _brickInfoBufferSize = 0;
173 
175  int32 _blockBufferSize = 0;
176  uint8 *_bufCube = nullptr;
177 
178  const BrickEntry* getBrickEntry(int32 j, int32 i) const;
179 
180  const IVec3 &updateCollisionCoordinates(int32 x, int32 y, int32 z);
181 
182  BlockEntry getBlockEntry(int32 xmap, int32 ymap, int32 zmap) const;
183 
184  bool shouldCheckWaterCol(int32 actorIdx) const;
185 public:
186  Grid(TwinEEngine *engine);
187  ~Grid();
188 
189  void init(int32 w, int32 h);
190 
194  const uint8 *getBlockBufferGround(const IVec3 &pos, int32 &ground);
195 
197  IVec3 _startCube; // StartXCube, StartYCube, StartZCube
198 
200  IVec3 _worldCube; // WorldXCube WorldYCube
201 
203  int16 _zoneGrm = 0;
205  int16 _indexGrm = 0;
206 
213  void drawOverBrick(int32 x, int32 y, int32 z);
214 
221  void drawOverBrick3(int32 x, int32 y, int32 z);
222 
230  void getSpriteSize(int32 offset, int32 *width, int32 *height, const uint8 *spritePtr);
231 
233  void centerScreenOnActor();
234  void centerOnActor(const ActorStruct* actor);
235 
242  bool drawBrick(int32 index, int32 posX, int32 posY);
243 
251  bool drawSprite(int32 index, int32 posX, int32 posY, const uint8 *spritePtr);
252  bool drawSprite(int32 posX, int32 posY, const SpriteData &ptr, int spriteIndex = 0);
253 
261  bool drawBrickSprite(int32 posX, int32 posY, const uint8 *spritePtr, bool isSprite);
262 
268  const BlockData *getBlockLibrary(int32 blockIdx) const;
269  const BlockDataEntry* getAdrBlock(int32 blockIdx, int32 tmpBrickIdx) const;
270 
272  void copyMapToCube();
273 
278  bool initGrid(int32 index);
279 
284  bool initCellingGrid(int32 index);
285 
287  void redrawGrid();
288 
289  ShapeType worldColBrick(int32 x, int32 y, int32 z);
290 
291  ShapeType worldColBrickFull(int32 x, int32 y, int32 z, int32 y2, int32 actorIdx);
292 
293  uint8 worldCodeBrick(int32 x, int32 y, int32 z);
294 
295  inline ShapeType worldColBrick(const IVec3 &pos) {
296  return worldColBrick(pos.x, pos.y, pos.z);
297  }
298 
299  inline ShapeType worldColBrickFull(const IVec3 &pos, int32 y2, int32 actorIdx) {
300  return worldColBrickFull(pos.x, pos.y, pos.z, y2, actorIdx);
301  }
302 };
303 
304 } // namespace TwinE
305 
306 #endif
Definition: managed_surface.h:51
Definition: blocklibrary.h:42
Definition: blocklibrary.h:32
Definition: actor.h:143
Definition: grid.h:95
Definition: grid.h:48
Definition: shared.h:122
Definition: sprite.h:68
Definition: grid.h:41
Definition: blocklibrary.h:46
Definition: formatinfo.h:28
Definition: twine.h:207
Definition: achievements_tables.h:27
IVec3 _startCube
Definition: grid.h:197
IVec3 _worldCube
Definition: grid.h:200