[Scummvm-git-logs] scummvm master -> ff394892af023bb25c4755e53597d5dc19ee9cc4
elasota
noreply at scummvm.org
Thu Aug 29 03:51:58 UTC 2024
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
ff394892af MTROPOLIS: Convert MovieElement tasks to coroutines
Commit: ff394892af023bb25c4755e53597d5dc19ee9cc4
https://github.com/scummvm/scummvm/commit/ff394892af023bb25c4755e53597d5dc19ee9cc4
Author: elasota (1137273+elasota at users.noreply.github.com)
Date: 2024-08-28T23:46:14-04:00
Commit Message:
MTROPOLIS: Convert MovieElement tasks to coroutines
Changed paths:
engines/mtropolis/elements.cpp
engines/mtropolis/elements.h
diff --git a/engines/mtropolis/elements.cpp b/engines/mtropolis/elements.cpp
index d8b64437382..4d92d5fb0d3 100644
--- a/engines/mtropolis/elements.cpp
+++ b/engines/mtropolis/elements.cpp
@@ -632,62 +632,8 @@ CORO_BEGIN_DEFINITION(MovieElement::MovieElementConsumeCommandCoroutine)
CORO_END_DEFINITION
VThreadState MovieElement::asyncConsumeCommand(Runtime *runtime, const Common::SharedPtr<MessageProperties> &msg) {
- // The reaction to the Play command should be Shown -> Unpaused -> Played
- // At First Cel is NOT fired by Play commands for some reason.
- // The reaction to the Stop command should be Paused -> Hidden -> Stopped
-
- if (true) {
- runtime->getVThread().pushCoroutine<MovieElement::MovieElementConsumeCommandCoroutine>(this, runtime, msg);
- return kVThreadReturn;
- }
-
- if (Event(EventIDs::kPlay, 0).respondsTo(msg->getEvent())) {
- {
- Common::SharedPtr<MessageProperties> msgProps(new MessageProperties(Event(EventIDs::kPlay, 0), DynamicValue(), getSelfReference()));
- Common::SharedPtr<MessageDispatch> dispatch(new MessageDispatch(msgProps, this, false, true, false));
- runtime->sendMessageOnVThread(dispatch);
- }
-
- if (_paused) {
- _paused = false;
- Common::SharedPtr<MessageProperties> msgProps(new MessageProperties(Event(EventIDs::kUnpause, 0), DynamicValue(), getSelfReference()));
- Common::SharedPtr<MessageDispatch> dispatch(new MessageDispatch(msgProps, this, false, true, false));
- runtime->sendMessageOnVThread(dispatch);
- }
-
- StartPlayingTaskData *startPlayingTaskData = runtime->getVThread().pushTask("MovieElement::startPlayingTask", this, &MovieElement::startPlayingTask);
- startPlayingTaskData->runtime = runtime;
-
- ChangeFlagTaskData *becomeVisibleTaskData = runtime->getVThread().pushTask("MovieElement::changeVisibilityTask", static_cast<VisualElement *>(this), &MovieElement::changeVisibilityTask);
- becomeVisibleTaskData->desiredFlag = true;
- becomeVisibleTaskData->runtime = runtime;
-
- return kVThreadReturn;
- }
- if (Event(EventIDs::kStop, 0).respondsTo(msg->getEvent())) {
- {
- Common::SharedPtr<MessageProperties> msgProps(new MessageProperties(Event(EventIDs::kStop, 0), DynamicValue(), getSelfReference()));
- Common::SharedPtr<MessageDispatch> dispatch(new MessageDispatch(msgProps, this, false, true, false));
- runtime->sendMessageOnVThread(dispatch);
- }
-
- ChangeFlagTaskData *becomeVisibleTaskData = runtime->getVThread().pushTask("MovieElement::changeVisibilityTask", static_cast<VisualElement *>(this), &MovieElement::changeVisibilityTask);
- becomeVisibleTaskData->desiredFlag = false;
- becomeVisibleTaskData->runtime = runtime;
-
- if (!_paused) {
- stopSubtitles();
-
- _paused = true;
- Common::SharedPtr<MessageProperties> msgProps(new MessageProperties(Event(EventIDs::kPause, 0), DynamicValue(), getSelfReference()));
- Common::SharedPtr<MessageDispatch> dispatch(new MessageDispatch(msgProps, this, false, true, false));
- runtime->sendMessageOnVThread(dispatch);
- }
-
- return kVThreadReturn;
- }
-
- return VisualElement::asyncConsumeCommand(runtime, msg);
+ runtime->getVThread().pushCoroutine<MovieElement::MovieElementConsumeCommandCoroutine>(this, runtime, msg);
+ return kVThreadReturn;
}
void MovieElement::activate() {
@@ -1110,10 +1056,7 @@ MiniscriptInstructionOutcome MovieElement::scriptSetTimestamp(MiniscriptThread *
asInteger = _playRange.max;
if (asInteger != (int32)_currentTimestamp) {
- SeekToTimeTaskData *taskData = thread->getRuntime()->getVThread().pushTask("MovieElement::seekToTimeTask", this, &MovieElement::seekToTimeTask);
- taskData->runtime = getRuntime();
- taskData->timestamp = asInteger;
-
+ thread->getRuntime()->getVThread().pushCoroutine<MovieElement::SeekToTimeCoroutine>(this, getRuntime(), asInteger);
return kMiniscriptInstructionOutcomeYieldToVThreadNoRetry;
}
@@ -1184,10 +1127,7 @@ MiniscriptInstructionOutcome MovieElement::scriptSetRangeTyped(MiniscriptThread
targetTS = _reversed ? maxTS : minTS;
if (targetTS != _currentTimestamp) {
- SeekToTimeTaskData *taskData = thread->getRuntime()->getVThread().pushTask("MovieElement::seekToTimeTask", this, &MovieElement::seekToTimeTask);
- taskData->runtime = getRuntime();
- taskData->timestamp = targetTS;
-
+ thread->getRuntime()->getVThread().pushCoroutine<MovieElement::SeekToTimeCoroutine>(this, getRuntime(), targetTS);
return kMiniscriptInstructionOutcomeYieldToVThreadNoRetry;
}
@@ -1216,49 +1156,37 @@ CORO_BEGIN_DEFINITION(MovieElement::StartPlayingCoroutine)
CORO_END_FUNCTION
CORO_END_DEFINITION
-VThreadState MovieElement::startPlayingTask(const StartPlayingTaskData &taskData) {
- if (_videoDecoder) {
- _videoDecoder->stop();
- _currentPlayState = kMediaStateStopped;
- _needsReset = true;
- _contentsDirty = true;
- _currentTimestamp = _reversed ? _playRange.max : _playRange.min;
-
- _shouldPlayIfNotPaused = true;
- _paused = false;
-
- stopSubtitles();
- }
- return kVThreadReturn;
-}
-
-VThreadState MovieElement::seekToTimeTask(const SeekToTimeTaskData &taskData) {
- uint32 minTS = _playRange.min;
- uint32 maxTS = _playRange.max;
+CORO_BEGIN_DEFINITION(MovieElement::SeekToTimeCoroutine)
+ struct Locals {
+ };
- uint32 targetTS = taskData.timestamp;
+ CORO_BEGIN_FUNCTION
+ MovieElement *self = params->self;
- if (targetTS < minTS)
- targetTS = minTS;
- if (targetTS > maxTS)
- targetTS = maxTS;
+ uint32 minTS = self->_playRange.min;
+ uint32 maxTS = self->_playRange.max;
- if (targetTS == _currentTimestamp)
- return kVThreadReturn;
+ uint32 targetTS = params->timestamp;
- _currentTimestamp = targetTS;
- if (_videoDecoder) {
- _videoDecoder->stop();
- _currentPlayState = kMediaStateStopped;
- }
- _needsReset = true;
- _contentsDirty = true;
+ if (targetTS < minTS)
+ targetTS = minTS;
+ if (targetTS > maxTS)
+ targetTS = maxTS;
- stopSubtitles();
+ if (targetTS != self->_currentTimestamp) {
+ self->_currentTimestamp = targetTS;
+ if (self->_videoDecoder) {
+ self->_videoDecoder->stop();
+ self->_currentPlayState = kMediaStateStopped;
+ }
+ self->_needsReset = true;
+ self->_contentsDirty = true;
- return kVThreadReturn;
-}
+ self->stopSubtitles();
+ }
+ CORO_END_FUNCTION
+CORO_END_DEFINITION
ImageElement::ImageElement() : _cacheBitmap(false), _assetID(0) {
}
diff --git a/engines/mtropolis/elements.h b/engines/mtropolis/elements.h
index bd87cac1c7b..0a253afa178 100644
--- a/engines/mtropolis/elements.h
+++ b/engines/mtropolis/elements.h
@@ -147,19 +147,6 @@ private:
MiniscriptInstructionOutcome scriptSetRangeTyped(MiniscriptThread *thread, const IntRange &range);
- struct StartPlayingTaskData {
- StartPlayingTaskData() : runtime(nullptr) {}
-
- Runtime *runtime;
- };
-
- struct SeekToTimeTaskData {
- SeekToTimeTaskData() : runtime(nullptr), timestamp(0) {}
-
- Runtime *runtime;
- uint32 timestamp;
- };
-
struct StartPlayingCoroutine {
CORO_DEFINE_RETURN_TYPE(void);
CORO_DEFINE_PARAMS_2(MovieElement *, self, Runtime *, runtime);
@@ -167,12 +154,9 @@ private:
struct SeekToTimeCoroutine {
CORO_DEFINE_RETURN_TYPE(void);
- CORO_DEFINE_PARAMS_2(Runtime *, runtime, uint32, timestamp);
+ CORO_DEFINE_PARAMS_3(MovieElement *, self, Runtime *, runtime, uint32, timestamp);
};
- VThreadState startPlayingTask(const StartPlayingTaskData &taskData);
- VThreadState seekToTimeTask(const SeekToTimeTaskData &taskData);
-
bool _cacheBitmap;
bool _alternate;
bool _playEveryFrame;
More information about the Scummvm-git-logs
mailing list