Initial commit
This commit is contained in:
130
engines/kyra/sequence/sequences_v2.cpp
Normal file
130
engines/kyra/sequence/sequences_v2.cpp
Normal file
@@ -0,0 +1,130 @@
|
||||
/* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "kyra/engine/kyra_v2.h"
|
||||
#include "kyra/resource/resource.h"
|
||||
|
||||
#include "common/system.h"
|
||||
|
||||
namespace Kyra {
|
||||
|
||||
void KyraEngine_v2::runAnimationScript(const char *filename, int allowSkip, int resetChar, int newShapes, int shapeUnload) {
|
||||
memset(&_animationScriptData, 0, sizeof(_animationScriptData));
|
||||
memset(&_animationScriptState, 0, sizeof(_animationScriptState));
|
||||
|
||||
if (!_emc->load(filename, &_animationScriptData, &_opcodesAnimation))
|
||||
error("Couldn't load temporary script '%s'", filename);
|
||||
|
||||
_emc->init(&_animationScriptState, &_animationScriptData);
|
||||
_emc->start(&_animationScriptState, 0);
|
||||
|
||||
_animResetFrame = -1;
|
||||
|
||||
if (_animShapeFiledata && newShapes) {
|
||||
uninitAnimationShapes(_animShapeCount, _animShapeFiledata);
|
||||
_animShapeFiledata = nullptr;
|
||||
_animShapeCount = 0;
|
||||
}
|
||||
|
||||
while (_emc->isValid(&_animationScriptState))
|
||||
_emc->run(&_animationScriptState);
|
||||
|
||||
uint8 *fileData = nullptr;
|
||||
|
||||
if (newShapes)
|
||||
_animShapeFiledata = _res->fileData(_animShapeFilename, nullptr);
|
||||
|
||||
fileData = _animShapeFiledata;
|
||||
|
||||
if (!fileData) {
|
||||
_emc->unload(&_animationScriptData);
|
||||
return;
|
||||
}
|
||||
|
||||
if (newShapes)
|
||||
_animShapeCount = initAnimationShapes(fileData);
|
||||
|
||||
processAnimationScript(allowSkip, resetChar);
|
||||
|
||||
if (shapeUnload) {
|
||||
uninitAnimationShapes(_animShapeCount, fileData);
|
||||
_animShapeCount = 0;
|
||||
_animShapeFiledata = nullptr;
|
||||
}
|
||||
|
||||
_emc->unload(&_animationScriptData);
|
||||
}
|
||||
|
||||
void KyraEngine_v2::processAnimationScript(int allowSkip, int resetChar) {
|
||||
setCharacterAnimDim(_animShapeWidth, _animShapeHeight);
|
||||
|
||||
_emc->init(&_animationScriptState, &_animationScriptData);
|
||||
_emc->start(&_animationScriptState, 1);
|
||||
|
||||
resetSkipFlag();
|
||||
|
||||
while (_emc->isValid(&_animationScriptState)) {
|
||||
_animNeedUpdate = false;
|
||||
while (_emc->isValid(&_animationScriptState) && !_animNeedUpdate)
|
||||
_emc->run(&_animationScriptState);
|
||||
|
||||
if (_animNewFrame < 0)
|
||||
continue;
|
||||
|
||||
_mainCharacter.animFrame = _animNewFrame + _desc.animScriptFrameAdd;
|
||||
updateCharacterAnim(0);
|
||||
if (!_chatText.empty())
|
||||
updateWithText();
|
||||
else
|
||||
update();
|
||||
|
||||
uint32 delayEnd = _system->getMillis() + _animDelayTime * _tickLength;
|
||||
|
||||
while ((!skipFlag() || !allowSkip) && _system->getMillis() < delayEnd)
|
||||
delay(10, true);
|
||||
|
||||
if (skipFlag()) {
|
||||
if (!_kbEventSkip || _eventList.front().event.type != Common::EVENT_KEYDOWN)
|
||||
resetSkipFlag();
|
||||
if (allowSkip)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (resetChar) {
|
||||
if (_animResetFrame >= 0) {
|
||||
_mainCharacter.animFrame = _animResetFrame + _desc.animScriptFrameAdd;
|
||||
updateCharacterAnim(0);
|
||||
if (!_chatText.empty())
|
||||
updateWithText();
|
||||
else
|
||||
update();
|
||||
}
|
||||
|
||||
_mainCharacter.animFrame = _desc.characterFrameTable[_mainCharacter.facing];
|
||||
updateCharacterAnim(0);
|
||||
}
|
||||
|
||||
_animResetFrame = -1;
|
||||
resetCharacterAnimDim();
|
||||
}
|
||||
|
||||
} // End of namespace Kyra
|
||||
Reference in New Issue
Block a user