diff options
author | Matthew Hoops | 2015-07-15 23:59:21 -0400 |
---|---|---|
committer | Matthew Hoops | 2015-07-17 20:05:00 -0400 |
commit | 7e6c8be7db2449c1f793b6fb01af5613282e7f27 (patch) | |
tree | 02fd969920a4c0a4aad285462eee2050885e620e /engines/mohawk/video.h | |
parent | 95b1288329b12dce9d96a1a97a28f1bc457d605f (diff) | |
download | scummvm-rg350-7e6c8be7db2449c1f793b6fb01af5613282e7f27.tar.gz scummvm-rg350-7e6c8be7db2449c1f793b6fb01af5613282e7f27.tar.bz2 scummvm-rg350-7e6c8be7db2449c1f793b6fb01af5613282e7f27.zip |
MOHAWK: Make video handles actual objects
Diffstat (limited to 'engines/mohawk/video.h')
-rw-r--r-- | engines/mohawk/video.h | 274 |
1 files changed, 232 insertions, 42 deletions
diff --git a/engines/mohawk/video.h b/engines/mohawk/video.h index deb09afe6b..70eecb8175 100644 --- a/engines/mohawk/video.h +++ b/engines/mohawk/video.h @@ -23,9 +23,17 @@ #ifndef MOHAWK_VIDEO_H #define MOHAWK_VIDEO_H +#include "audio/timestamp.h" #include "common/array.h" +#include "common/list.h" +#include "common/noncopyable.h" +#include "common/ptr.h" +#include "common/rational.h" #include "graphics/pixelformat.h" -#include "video/video_decoder.h" + +namespace Video { +class VideoDecoder; +} namespace Mohawk { @@ -43,29 +51,219 @@ struct MLSTRecord { uint16 u1; }; -struct VideoEntry { +/** + * A video monitored by the VideoManager + */ +class VideoEntry : private Common::NonCopyable { + // The private members should be able to be manipulated by VideoManager + friend class VideoManager; + +private: + // Hide the destructor/constructor + // Only VideoManager should be allowed + VideoEntry(); + VideoEntry(Video::VideoDecoder *video, const Common::String &fileName); + VideoEntry(Video::VideoDecoder *video, int id); + +public: + ~VideoEntry(); + + /** + * Convenience implicit cast to bool + */ + operator bool() const { return isOpen(); } + + /** + * Is the video open? + */ + bool isOpen() const { return _video != 0; } + + /** + * Close the video + */ + void close(); + + /** + * Has the video reached its end? + */ + bool endOfVideo() const; + + /** + * Get the X position of where the video is displayed + */ + uint16 getX() const { return _x; } + + /** + * Get the Y position of where the video is displayed + */ + uint16 getY() const { return _y; } + + /** + * Is the video looping? + */ + bool isLooping() const { return _loop; } + + /** + * Is the video enabled? (Drawing to the screen) + */ + bool isEnabled() const { return _enabled; } + + /** + * Get the start time of the video bounds + */ + const Audio::Timestamp &getStart() const { return _start; } + + /** + * Get the file name of the video, or empty if by ID + */ + const Common::String &getFileName() const { return _fileName; } + + /** + * Get the ID of the video, or -1 if by file name + */ + int getID() const { return _id; } + + /** + * Get the current frame of the video + */ + int getCurFrame() const; + + /** + * Get the frame count of the video + */ + uint32 getFrameCount() const; + + /** + * Get the current time position of the video + */ + uint32 getTime() const; + + /** + * Get the duration of the video + */ + Audio::Timestamp getDuration() const; + + /** + * Get the current playback rate of the videos + */ + Common::Rational getRate() const; + + /** + * Move the x position of the video + */ + void setX(uint16 x) { _x = x; } + + /** + * Move the y position of the video + */ + void setY(uint16 y) { _y = y; } + + /** + * Set the start time when using video bounds + */ + void setStart(const Audio::Timestamp &start) { _start = start; } + + /** + * Set the video to loop (true) or not (false) + */ + void setLooping(bool loop) { _loop = loop; } + + /** + * Set the video's enabled status + */ + void setEnabled(bool enabled) { _enabled = enabled; } + + /** + * Set the bounds of the video + * + * This automatically seeks to the start time + */ + void setBounds(const Audio::Timestamp &start, const Audio::Timestamp &end); + + /** + * Seek to the given time + */ + void seek(const Audio::Timestamp &time); + + /** + * Set the playback rate + */ + void setRate(const Common::Rational &rate); + + /** + * Pause the video + */ + void pause(bool isPaused); + +private: + // Non-changing variables + Video::VideoDecoder *_video; + Common::String _fileName; // External video files + int _id; // Internal Mohawk files + // Playback variables - Video::VideoDecoder *video; - uint16 x; - uint16 y; - bool loop; - bool enabled; - Audio::Timestamp start; - - // Identification - Common::String filename; // External video files - int id; // Internal Mohawk files - - // Helper functions - Video::VideoDecoder *operator->() const { assert(video); return video; } // TODO: Remove this eventually - void clear(); - bool endOfVideo(); + uint16 _x; + uint16 _y; + bool _loop; + bool _enabled; + Audio::Timestamp _start; }; -typedef int32 VideoHandle; +typedef Common::SharedPtr<VideoEntry> VideoEntryPtr; + +/** + * A handle for manipulating a video + */ +class VideoHandle { + // The private members should be able to be manipulated by VideoManager + friend class VideoManager; + +public: + /** + * Default constructor + */ + VideoHandle() {} + + /** + * Copy constructor + */ + VideoHandle(const VideoHandle &handle); + + /** + * Is this handle pointing to a valid video entry? + */ + bool isValid() const { return _ptr && _ptr->isOpen(); } + + /** + * Convenience implicit cast to bool + */ + operator bool() const { return isValid(); } + + /** + * Simple equality operator + */ + bool operator==(const VideoHandle &other) const { return _ptr.get() == other._ptr.get(); } -enum { - NULL_VID_HANDLE = -1 + /** + * Simple inequality operator + */ + bool operator!=(const VideoHandle &other) const { return !(*this == other); } + + /** + * Convenience operator-> override to give direct access to the VideoEntry + */ + VideoEntryPtr operator->() const { return _ptr; } + +private: + /** + * Constructor for internal VideoManager use + */ + VideoHandle(VideoEntryPtr ptr); + + /** + * The video entry this is associated with + */ + VideoEntryPtr _ptr; }; class VideoManager { @@ -87,31 +285,18 @@ public: // Riven-related functions void activateMLST(uint16 mlstId, uint16 card); void clearMLST(); - void enableMovieRiven(uint16 id); - void disableMovieRiven(uint16 id); void disableAllMovies(); VideoHandle playMovieRiven(uint16 id); - void stopMovieRiven(uint16 id); void playMovieBlockingRiven(uint16 id); VideoHandle findVideoHandleRiven(uint16 id); + void stopMovieRiven(uint16 id); // Handle functions VideoHandle findVideoHandle(uint16 id); - VideoHandle findVideoHandle(const Common::String &filename); - int getCurFrame(VideoHandle handle); - uint32 getFrameCount(VideoHandle handle); - uint32 getTime(VideoHandle handle); - Audio::Timestamp getDuration(VideoHandle videoHandle); - bool endOfVideo(VideoHandle handle); - void setVideoBounds(VideoHandle handle, Audio::Timestamp start, Audio::Timestamp end); - void drawVideoFrame(VideoHandle handle, Audio::Timestamp time); - void seekToTime(VideoHandle handle, Audio::Timestamp time); - void setVideoLooping(VideoHandle handle, bool loop); - Common::Rational getVideoRate(VideoHandle handle) const; - void setVideoRate(VideoHandle handle, const Common::Rational &rate); - void waitUntilMovieEnds(VideoHandle videoHandle); - void delayUntilMovieEnds(VideoHandle videoHandle); - void pauseMovie(VideoHandle videoHandle, bool pause); + VideoHandle findVideoHandle(const Common::String &fileName); + void waitUntilMovieEnds(VideoHandle handle); + void delayUntilMovieEnds(VideoHandle handle); + void drawVideoFrame(VideoHandle handle, const Audio::Timestamp &time); private: MohawkEngine *_vm; @@ -120,14 +305,19 @@ private: Common::Array<MLSTRecord> _mlstRecords; // Keep tabs on any videos playing - Common::Array<VideoEntry> _videoStreams; + typedef Common::List<VideoEntryPtr> VideoList; + VideoList _videos; - VideoHandle createVideoHandle(uint16 id, uint16 x, uint16 y, bool loop, uint16 volume = 0xff); - VideoHandle createVideoHandle(const Common::String &filename, uint16 x, uint16 y, bool loop, byte volume = 0xff); + // Utility functions for managing entries + VideoEntryPtr open(uint16 id, int volume = 0xFF); + VideoEntryPtr open(const Common::String &fileName, int volume = 0xFF); + + VideoList::iterator findEntry(VideoEntryPtr ptr); + void removeEntry(VideoEntryPtr ptr); // Dithering control bool _enableDither; - void checkEnableDither(VideoEntry &entry); + void checkEnableDither(VideoEntryPtr &entry); }; } // End of namespace Mohawk |