Constificiation.
[gemrb.git] / gemrb / core / TileOverlay.cpp
blobb87ab2a1c74d44965110974f86a434dc3657e4f3
1 /* GemRB - Infinity Engine Emulator
2 * Copyright (C) 2003 The GemRB Project
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #include "win32def.h"
22 #include "TileOverlay.h"
23 #include "Interface.h"
24 #include "Video.h"
26 bool RedrawTile = false;
28 TileOverlay::TileOverlay(int Width, int Height)
30 w = Width;
31 h = Height;
32 count = 0;
33 tiles = ( Tile * * ) malloc( w * h * sizeof( Tile * ) );
36 TileOverlay::~TileOverlay(void)
38 for (int i = 0; i < count; i++) {
39 delete( tiles[i] );
41 free( tiles );
44 void TileOverlay::AddTile(Tile* tile)
46 tiles[count++] = tile;
49 void TileOverlay::BumpViewport(const Region &viewport, Region &vp)
51 bool bump = false;
52 vp.w = viewport.w;
53 vp.h = viewport.h;
54 if (( vp.x + vp.w ) > w * 64) {
55 vp.x = ( w * 64 - vp.w );
56 bump = true;
58 if (vp.x < 0) {
59 vp.x = 0;
60 bump = true;
62 if (( vp.y + vp.h ) > h * 64) {
63 vp.y = ( h * 64 - vp.h );
64 bump = true;
66 if (vp.y < 0) {
67 vp.y = 0;
68 bump = true;
70 if(bump && !(core->timer->ViewportIsMoving())) {
71 core->timer->SetMoveViewPort( vp.x, vp.y, 0, false );
75 void TileOverlay::Draw(Region viewport, std::vector< TileOverlay*> &overlays)
77 Video* vid = core->GetVideoDriver();
78 Region vp = vid->GetViewport();
80 // if the video's viewport is partially outside of the map, bump it back
81 BumpViewport(viewport, vp);
82 // determine which tiles are visible
83 int sx = vp.x / 64;
84 int sy = vp.y / 64;
85 int dx = ( vp.x + vp.w + 63 ) / 64;
86 int dy = ( vp.y + vp.h + 63 ) / 64;
88 for (int y = sy; y < dy && y < h; y++) {
89 for (int x = sx; x < dx && x < w; x++) {
90 Tile* tile = tiles[( y* w ) + x];
92 //draw door tiles if there are any
93 Animation* anim = tile->anim[tile->tileIndex];
94 if (!anim && tile->tileIndex) {
95 anim = tile->anim[0];
97 vid->BlitTile( anim->NextFrame(), 0, viewport.x + ( x * 64 ),
98 viewport.y + ( y * 64 ), &viewport, false );
99 if (!tile->om || tile->tileIndex) {
100 continue;
103 //draw overlay tiles, they should be half transparent
104 int mask = 2;
105 for (size_t z = 1;z<overlays.size();z++) {
106 TileOverlay * ov = overlays[z];
107 if (ov && ov->count > 0) {
108 Tile *ovtile = ov->tiles[0]; //allow only 1x1 tiles now
109 if (tile->om & mask) {
110 if (RedrawTile) {
111 vid->BlitTile( ovtile->anim[0]->NextFrame(),
112 tile->anim[0]->NextFrame(),
113 viewport.x + ( x * 64 ),
114 viewport.y + ( y * 64 ),
115 &viewport, false );
116 } else {
117 Sprite2D* mask = 0;
118 if (tile->anim[1])
119 mask = tile->anim[1]->NextFrame();
120 vid->BlitTile( ovtile->anim[0]->NextFrame(),
121 mask,
122 viewport.x + ( x * 64 ),
123 viewport.y + ( y * 64 ),
124 &viewport, true );
128 mask<<=1;