scummvm/engines/petka/video.cpp

111 lines
2.8 KiB
C++
Raw Normal View History

2019-06-06 10:55:32 +03:00
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "common/system.h"
#include "petka/flc.h"
2019-06-06 10:55:32 +03:00
#include "petka/petka.h"
2019-06-07 11:01:16 +03:00
#include "petka/q_system.h"
#include "petka/interfaces/interface.h"
#include "petka/objects/object.h"
2019-06-07 11:01:16 +03:00
#include "petka/video.h"
2019-06-06 10:55:32 +03:00
namespace Petka {
2019-06-07 11:01:16 +03:00
VideoSystem::VideoSystem() :
2019-06-30 18:11:13 +03:00
_shake(false), _shift(false), _shakeTime(0), _time(0) {
makeAllDirty();
2019-06-07 11:01:16 +03:00
}
static bool objCmp(QVisibleObject *&l, QVisibleObject *&r) {
return l->_z < r->_z;
}
2019-06-07 11:01:16 +03:00
void VideoSystem::update() {
Interface *interface = g_vm->getQSystem()->_currInterface;
2019-06-30 18:11:13 +03:00
int time = g_system->getMillis();
2019-06-07 11:01:16 +03:00
if (interface) {
2019-06-09 18:09:38 +03:00
for (uint i = 0; i < interface->_objs.size(); ++i) {
2019-06-30 18:11:13 +03:00
interface->_objs[i]->update(time - _time);
2019-06-09 18:09:38 +03:00
}
for (uint i = 0; i < interface->_objs.size(); ++i) {
interface->_objs[i]->updateZ();
}
Common::sort(interface->_objs.begin(), interface->_objs.end(), objCmp);
2019-06-07 11:01:16 +03:00
for (uint i = 0; i < interface->_objs.size(); ++i) {
interface->_objs[i]->draw();
}
}
2019-06-30 18:11:13 +03:00
_time = time;
2019-06-07 11:01:16 +03:00
_rects.clear();
2019-06-06 10:55:32 +03:00
if (_shake) {
2019-06-07 11:01:16 +03:00
int width = _screen.w;
2019-06-06 10:55:32 +03:00
int x = 0;
if (_shift) {
Graphics::Surface s;
s.create(3, 480, g_system->getScreenFormat());
g_system->copyRectToScreen(s.getPixels(), s.pitch, 0, 0, s.w, s.h);
2019-06-07 11:01:16 +03:00
width -= 3;
2019-06-06 10:55:32 +03:00
x = 3;
}
2019-06-09 18:09:38 +03:00
g_system->copyRectToScreen(_screen.getPixels(), _screen.pitch, x, 0, width, _screen.h);
g_system->updateScreen();
2019-06-06 10:55:32 +03:00
uint32 time = g_system->getMillis();
if (time - _shakeTime > 30) {
_shift = !_shift;
_shakeTime = time;
}
} else {
2019-06-07 11:01:16 +03:00
_screen.update();
2019-06-06 10:55:32 +03:00
}
}
2019-06-07 11:01:16 +03:00
void VideoSystem::addDirtyRect(const Common::Rect &rect) {
_rects.push_back(rect);
2019-06-06 10:55:32 +03:00
}
2019-06-07 11:01:16 +03:00
const Common::List<Common::Rect> VideoSystem::rects() const {
return _rects;
2019-06-06 10:55:32 +03:00
}
2019-06-07 11:01:16 +03:00
Graphics::Screen &VideoSystem::screen() {
return _screen;
2019-06-06 10:55:32 +03:00
}
void VideoSystem::addDirtyRect(Common::Point pos, FlicDecoder &flc) {
Common::Rect rect = flc.getBounds();
rect.translate(pos.x, pos.y);
addDirtyRect(rect);
}
void VideoSystem::makeAllDirty() {
addDirtyRect(Common::Rect(640, 480));
}
2019-06-06 10:55:32 +03:00
}