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.
22 #include "TileOverlay.h"
23 #include "Interface.h"
26 bool RedrawTile
= false;
28 TileOverlay::TileOverlay(int Width
, int Height
)
33 tiles
= ( Tile
* * ) malloc( w
* h
* sizeof( Tile
* ) );
36 TileOverlay::~TileOverlay(void)
38 for (int i
= 0; i
< count
; i
++) {
44 void TileOverlay::AddTile(Tile
* tile
)
46 tiles
[count
++] = tile
;
49 void TileOverlay::BumpViewport(const Region
&viewport
, Region
&vp
)
54 if (( vp
.x
+ vp
.w
) > w
* 64) {
55 vp
.x
= ( w
* 64 - vp
.w
);
62 if (( vp
.y
+ vp
.h
) > h
* 64) {
63 vp
.y
= ( h
* 64 - vp
.h
);
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
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
) {
97 vid
->BlitTile( anim
->NextFrame(), 0, viewport
.x
+ ( x
* 64 ),
98 viewport
.y
+ ( y
* 64 ), &viewport
, false );
99 if (!tile
->om
|| tile
->tileIndex
) {
103 //draw overlay tiles, they should be half transparent
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
) {
111 vid
->BlitTile( ovtile
->anim
[0]->NextFrame(),
112 tile
->anim
[0]->NextFrame(),
113 viewport
.x
+ ( x
* 64 ),
114 viewport
.y
+ ( y
* 64 ),
119 mask
= tile
->anim
[1]->NextFrame();
120 vid
->BlitTile( ovtile
->anim
[0]->NextFrame(),
122 viewport
.x
+ ( x
* 64 ),
123 viewport
.y
+ ( y
* 64 ),