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
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (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, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 *
21 */
22
23 #include "common/system.h"
24
25 #include "petka/flc.h"
26 #include "petka/petka.h"
27 #include "petka/q_system.h"
28 #include "petka/interfaces/interface.h"
29 #include "petka/video.h"
30
31 namespace Petka {
32
33 const uint kShakeTime = 30;
34 const int kShakeOffset = 3;
35
VideoSystem(PetkaEngine & vm)36 VideoSystem::VideoSystem(PetkaEngine &vm)
37 : _vm(vm) {
38 _shakeTime = 0;
39 _time = g_system->getMillis();
40 _shake = false;
41 _shift = false;
42 _allowAddingRects = true;
43 }
44
update()45 void VideoSystem::update() {
46 QSystem *sys = _vm.getQSystem();
47 Interface *interface = sys->_currInterface;
48 uint32 time = g_system->getMillis();
49
50 assert(sys);
51 assert(interface);
52
53 interface->update(time - _time);
54
55 mergeDirtyRects();
56
57 _allowAddingRects = false;
58 interface->draw();
59 _allowAddingRects = true;
60
61 for (Common::Rect &r : _dirtyRects) {
62 const byte *srcP = (const byte *)getBasePtr(r.left, r.top);
63 g_system->copyRectToScreen(srcP, pitch, r.left, r.top, r.width(), r.height());
64 }
65
66 _dirtyRects.clear();
67
68 _time = time;
69
70 if (_shake) {
71 g_system->setShakePos(_shift ? kShakeOffset : 0, 0);
72 if (time - _shakeTime > kShakeTime) {
73 _shift = !_shift;
74 _shakeTime = time;
75 }
76 }
77
78 g_system->updateScreen();
79 }
80
addDirtyRect(const Common::Rect & rect)81 void VideoSystem::addDirtyRect(const Common::Rect &rect) {
82 if (_allowAddingRects) {
83 Graphics::Screen::addDirtyRect(rect);
84 }
85 }
86
addDirtyRect(Common::Point pos,Common::Rect rect)87 void VideoSystem::addDirtyRect(Common::Point pos, Common::Rect rect) {
88 rect.translate(pos.x, pos.y);
89 addDirtyRect(rect);
90 }
91
addDirtyRect(Common::Point pos,FlicDecoder & flc)92 void VideoSystem::addDirtyRect(Common::Point pos, FlicDecoder &flc) {
93 pos.x = pos.x - _vm.getQSystem()->_xOffset;
94 addDirtyRect(pos, flc.getBounds());
95 }
96
addDirtyMskRects(Common::Point pos,FlicDecoder & flc)97 void VideoSystem::addDirtyMskRects(Common::Point pos, FlicDecoder &flc) {
98 for (auto rect : flc.getMskRects()) {
99 addDirtyRect(pos, rect);
100 }
101 }
102
addDirtyMskRects(FlicDecoder & flc)103 void VideoSystem::addDirtyMskRects(FlicDecoder &flc) {
104 addDirtyMskRects(Common::Point(0, 0), flc);
105 }
106
rects() const107 const Common::List<Common::Rect> &VideoSystem::rects() const {
108 return _dirtyRects;
109 }
110
updateTime()111 void VideoSystem::updateTime() {
112 _time = g_system->getMillis();
113 }
114
setShake(bool shake)115 void VideoSystem::setShake(bool shake) {
116 _shake = shake;
117 g_system->setShakePos(0, 0);
118 }
119
120 } // End of namespace Petka
121