1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
|
/* 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 "bladerunner/overlays.h"
#include "bladerunner/bladerunner.h"
#include "bladerunner/archive.h"
#include "bladerunner/vqa_player.h"
#include "graphics/surface.h"
namespace BladeRunner {
Overlays::Overlays(BladeRunnerEngine *vm)
: _vm(vm)
{
}
bool Overlays::init() {
reset();
_videos.resize(kOverlayVideos);
for (int i = 0; i < kOverlayVideos; ++i) {
_videos[i].vqaPlayer = nullptr;
resetSingle(i);
}
return true;
}
Overlays::~Overlays() {
for (int i = 0; i < kOverlayVideos; ++i) {
resetSingle(i);
}
_videos.clear();
reset();
}
int Overlays::play(const Common::String &name, int loopId, int loopForever, int startNow, int a6) {
int id = mix_id(name);
int index = findById(id);
if (index < 0) {
index = findEmpty();
if (index < 0) {
return index;
}
_videos[index].id = id;
_videos[index].vqaPlayer = new VQAPlayer(_vm, &_vm->_surfaceGame);
// repeat forever
_videos[index].vqaPlayer->setBeginAndEndFrame(0, 0, -1, kLoopSetModeJustStart, nullptr, nullptr);
_videos[index].loaded = true;
}
Common::String resourceName = Common::String::format("%s.VQA", name.c_str());
_videos[index].vqaPlayer->open(resourceName);
_videos[index].vqaPlayer->setLoop(
loopId,
loopForever ? -1 : 0,
startNow ? kLoopSetModeImmediate : kLoopSetModeEnqueue,
nullptr, nullptr);
return index;
}
void Overlays::remove(const Common::String &name) {
int id = mix_id(name);
int index = findById(id);
if (index >= 0) {
resetSingle(index);
}
}
void Overlays::removeAll() {
for (int i = 0; i < kOverlayVideos; ++i) {
if (_videos[i].loaded) {
resetSingle(i);
}
}
}
void Overlays::tick() {
for (int i = 0; i < kOverlayVideos; ++i) {
if (_videos[i].loaded) {
int frame = _videos[i].vqaPlayer->update(true);
if (frame < 0) {
resetSingle(i);
}
}
}
}
int Overlays::findById(int32 id) const {
for (int i = 0; i < kOverlayVideos; ++i) {
if (_videos[i].loaded && _videos[i].id == id) {
return i;
}
}
return -1;
}
int Overlays::findEmpty() const {
for (int i = 0; i < kOverlayVideos; ++i) {
if (!_videos[i].loaded) {
return i;
}
}
return -1;
}
void Overlays::resetSingle(int i) {
assert(i >= 0 && i < (int)_videos.size());
if (_videos[i].vqaPlayer) {
delete _videos[i].vqaPlayer;
_videos[i].vqaPlayer = nullptr;
}
_videos[i].loaded = false;
_videos[i].id = 0;
_videos[i].field2 = -1;
}
void Overlays::reset() {
_videos.clear();
}
} // End of namespace BladeRunner
|