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) // CJ_WATER
26
27#include "common/scummsys.h"
28#include "twine/parser/blocklibrary.h"
29#include "twine/parser/sprite.h"
30#include "twine/shared.h"
31
32namespace Graphics {
33class ManagedSurface;
34}
35
36namespace TwinE {
37
38class ActorStruct;
39
41struct BlockEntry {
43 uint8 blockIdx = 0;
45 uint8 brickBlockIdx = 0;
46};
48struct BrickEntry { // T_COLONB
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
73#define SIZE_CUBE_Y 25
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 MAX_BRICKS 150
92
93class TwinEEngine;
94
95class Grid {
96private:
97 TwinEEngine *_engine;
98
107 void drawBrickBlock(int32 blockIdx, int32 brickBlockIdx, int32 x, int32 y, int32 z);
114 void map2Screen(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 *_bufferBrick[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 *_listBrickColon = nullptr;
171 int16 *_nbBrickColon = 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;
185public:
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
202 int32 _addBetaCam = 0;
203
205 int16 _zoneGrm = 0;
207 int16 _indexGrm = 0;
208
215 void drawOverBrick(int32 x, int32 y, int32 z);
216
223 void drawOverBrick3(int32 x, int32 y, int32 z);
224
232 void getSpriteSize(int32 offset, int32 *width, int32 *height, const uint8 *spritePtr);
233
236 void centerOnActor(const ActorStruct* actor);
237
244 bool drawGraph(int32 index, int32 posX, int32 posY);
245
253 bool drawGraph(int32 index, int32 posX, int32 posY, const uint8 *spritePtr);
254 bool drawSprite(int32 posX, int32 posY, const SpriteData &ptr, int spriteIndex = 0);
255
263 bool drawGraph(int32 posX, int32 posY, const uint8 *pGraph, bool isSprite);
264
270 const BlockData *getBlockLibrary(int32 blockIdx) const;
271 const BlockDataEntry* getAdrBlock(int32 blockIdx, int32 tmpBrickIdx) const;
272
275
280 bool initGrid(int32 index);
281
286 bool initCellingGrid(int32 index);
287
290
291 ShapeType worldColBrick(int32 x, int32 y, int32 z);
292
293 ShapeType worldColBrickFull(int32 x, int32 y, int32 z, int32 y2, int32 actorIdx);
294
295 uint8 worldCodeBrick(int32 x, int32 y, int32 z);
296
297 inline ShapeType worldColBrick(const IVec3 &pos) {
298 return worldColBrick(pos.x, pos.y, pos.z);
299 }
300
301 inline ShapeType worldColBrickFull(const IVec3 &pos, int32 y2, int32 actorIdx) {
302 return worldColBrickFull(pos.x, pos.y, pos.z, y2, actorIdx);
303 }
304};
305
306} // namespace TwinE
307
308#endif
Definition: managed_surface.h:51
Definition: actor.h:137
Definition: blocklibrary.h:46
Definition: grid.h:95
bool drawGraph(int32 index, int32 posX, int32 posY, const uint8 *spritePtr)
bool drawGraph(int32 index, int32 posX, int32 posY)
bool drawGraph(int32 posX, int32 posY, const uint8 *pGraph, bool isSprite)
void drawOverBrick3(int32 x, int32 y, int32 z)
const BlockData * getBlockLibrary(int32 blockIdx) const
bool initCellingGrid(int32 index)
int16 _indexGrm
Definition: grid.h:207
IVec3 _startCube
Definition: grid.h:197
const uint8 * getBlockBufferGround(const IVec3 &pos, int32 &ground)
void drawOverBrick(int32 x, int32 y, int32 z)
void getSpriteSize(int32 offset, int32 *width, int32 *height, const uint8 *spritePtr)
int16 _zoneGrm
Definition: grid.h:205
bool initGrid(int32 index)
void copyMapToCube()
IVec3 _worldCube
Definition: grid.h:200
void redrawGrid()
void centerScreenOnActor()
Definition: sprite.h:68
Definition: twine.h:207
Definition: formatinfo.h:28
Definition: blocklibrary.h:32
Definition: blocklibrary.h:42
Definition: grid.h:41
uint8 blockIdx
Definition: grid.h:43
uint8 brickBlockIdx
Definition: grid.h:45
Definition: grid.h:48
uint8 shape
Definition: grid.h:62
int16 index
Definition: grid.h:60
int16 posX
Definition: grid.h:56
int16 y
Definition: grid.h:52
int16 x
Definition: grid.h:50
int16 posY
Definition: grid.h:58
int16 z
Definition: grid.h:54
uint8 sound
Definition: grid.h:64
Definition: shared.h:127