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 "neverhood/smackerscene.h"
24 #include "neverhood/smackerplayer.h"
25
26 namespace Neverhood {
27
SmackerScene(NeverhoodEngine * vm,Module * parentModule,bool doubleSurface,bool canSkip,bool canAbort)28 SmackerScene::SmackerScene(NeverhoodEngine *vm, Module *parentModule, bool doubleSurface, bool canSkip, bool canAbort)
29 : Scene(vm, parentModule), _doubleSurface(doubleSurface), _canSkip(canSkip), _canAbort(canAbort), _videoPlayedBefore(false),
30 _fileHashListIndex(-1), _fileHashList(NULL), _playNextVideoFlag(false) {
31
32 debug(0, "SmackerScene::SmackerScene(%d, %d, %d)", doubleSurface, canSkip, canAbort);
33
34 // NOTE: Merged from SmackerScene::init, maybe split again if needed (incl. parameter flags)
35
36 if (getGlobalVar(V_SMACKER_CAN_ABORT)) {
37 _canSkip = true;
38 _canAbort = true;
39 }
40
41 if (!_doubleSurface)
42 _vm->_screen->clear();
43
44 _fileHash[0] = 0;
45 _fileHash[1] = 0;
46
47 SetUpdateHandler(&SmackerScene::update);
48 SetMessageHandler(&SmackerScene::handleMessage);
49
50 }
51
~SmackerScene()52 SmackerScene::~SmackerScene() {
53
54 }
55
setFileHash(uint32 fileHash)56 void SmackerScene::setFileHash(uint32 fileHash) {
57 debug(0, "SmackerScene::setFileHash(%08X)", fileHash);
58 _fileHash[0] = fileHash;
59 _fileHashList = _fileHash;
60 }
61
setFileHashList(const uint32 * fileHashList)62 void SmackerScene::setFileHashList(const uint32 *fileHashList) {
63 debug(0, "SmackerScene::setFileHashList(...)");
64 _fileHashList = fileHashList;
65 }
66
nextVideo()67 void SmackerScene::nextVideo() {
68 debug(0, "SmackerScene::nextVideo()");
69
70 _fileHashListIndex++;
71
72 if (_fileHashList && _fileHashList[_fileHashListIndex] != 0) {
73 uint32 smackerFileHash = _fileHashList[_fileHashListIndex];
74 ResourceHandle resourceHandle;
75 _vm->_res->queryResource(smackerFileHash, resourceHandle);
76 if (resourceHandle.type() != kResTypeVideo) {
77 // Not a Smacker file
78 _vm->_screen->setSmackerDecoder(NULL);
79 sendMessage(_parentModule, 0x1009, 0);
80 return;
81 }
82 _videoPlayedBefore = getSubVar(VA_SMACKER_PLAYED, smackerFileHash);
83 if (!_videoPlayedBefore)
84 setSubVar(VA_SMACKER_PLAYED, smackerFileHash, 1);
85 if (_fileHashListIndex == 0)
86 _smackerPlayer = addSmackerPlayer(new SmackerPlayer(_vm, this, smackerFileHash, _doubleSurface, false));
87 else
88 _smackerPlayer->open(smackerFileHash, false);
89 _vm->_screen->setSmackerDecoder(_smackerPlayer->getSmackerDecoder());
90 } else {
91 _vm->_screen->setSmackerDecoder(NULL);
92 sendMessage(_parentModule, 0x1009, 0);
93 }
94
95 }
96
update()97 void SmackerScene::update() {
98 if (_playNextVideoFlag) {
99 nextVideo();
100 _playNextVideoFlag = false;
101 }
102 Scene::update();
103 }
104
handleMessage(int messageNum,const MessageParam & param,Entity * sender)105 uint32 SmackerScene::handleMessage(int messageNum, const MessageParam ¶m, Entity *sender) {
106 uint32 messageResult = Scene::handleMessage(messageNum, param, sender);
107 switch (messageNum) {
108 case NM_KEYPRESS_SPACE:
109 if ((_videoPlayedBefore && _canSkip) || (_canAbort && _canSkip))
110 _playNextVideoFlag = true;
111 break;
112 case NM_KEYPRESS_ESC:
113 if (_canAbort)
114 sendMessage(_parentModule, 0x1009, 0);
115 break;
116 case NM_ANIMATION_STOP:
117 _playNextVideoFlag = true;
118 break;
119 default:
120 break;
121 }
122 return messageResult;
123 }
124
125 } // End of namespace Neverhood
126