diff options
| -rw-r--r-- | engines/titanic/core/resource_key.cpp | 13 | ||||
| -rw-r--r-- | engines/titanic/core/resource_key.h | 15 | ||||
| -rw-r--r-- | engines/titanic/files_manager.cpp | 44 | ||||
| -rw-r--r-- | engines/titanic/files_manager.h | 7 | ||||
| -rw-r--r-- | engines/titanic/string.cpp | 38 | ||||
| -rw-r--r-- | engines/titanic/string.h | 19 | ||||
| -rw-r--r-- | engines/titanic/video_surface.cpp | 64 | ||||
| -rw-r--r-- | engines/titanic/video_surface.h | 112 | 
8 files changed, 278 insertions, 34 deletions
diff --git a/engines/titanic/core/resource_key.cpp b/engines/titanic/core/resource_key.cpp index 4788f7a493..4b52082b77 100644 --- a/engines/titanic/core/resource_key.cpp +++ b/engines/titanic/core/resource_key.cpp @@ -21,6 +21,7 @@   */  #include "common/file.h" +#include "titanic/titanic.h"  #include "titanic/simple_file.h"  #include "titanic/core/resource_key.h" @@ -73,4 +74,16 @@ CString CResourceKey::exists() {  	return f.exists(name) ? name : CString();  } +bool CResourceKey::scanForFile() const { +	return g_vm->_filesManager.scanForFile(_value); +} + +FileType CResourceKey::fileTypeSuffix() const { +	return _value.fileTypeSuffix(); +} + +ImageType CResourceKey::imageTypeSuffix() const { +	return _value.imageTypeSuffix(); +} +  } // End of namespace Titanic diff --git a/engines/titanic/core/resource_key.h b/engines/titanic/core/resource_key.h index a165a11e1a..111cec5c7c 100644 --- a/engines/titanic/core/resource_key.h +++ b/engines/titanic/core/resource_key.h @@ -57,6 +57,21 @@ public:  	 * and returns it's filename if it does  	 */  	CString exists(); + +	/** +	 * Scans for a file with a matching name +	 */ +	bool scanForFile() const; + +	/** +	 * Returns the type of the resource based on it's extension +	 */ +	FileType fileTypeSuffix() const; + +	/** +	 * Returns the type of the resource based on it's extension +	 */ +	ImageType imageTypeSuffix() const;  };  } // End of namespace Titanic diff --git a/engines/titanic/files_manager.cpp b/engines/titanic/files_manager.cpp index b7562b638a..662a882e3e 100644 --- a/engines/titanic/files_manager.cpp +++ b/engines/titanic/files_manager.cpp @@ -31,35 +31,35 @@ CFilesManager::CFilesManager() : _gameManager(nullptr),  		_field18(0), _field1C(0), _field3C(0) {  } -bool CFilesManager::fn1(const CString &name) { +bool CFilesManager::fileExists(const CString &name) { +	Common::File f; +	return f.exists(name); +} + +bool CFilesManager::scanForFile(const CString &name) {  	if (name.empty()) -		return 0; +		return false; -	CString str = name; -	str.toLowercase(); +	CString filename = name; +	filename.toLowercase(); -	if (str[0] == 'z' || str[0] == 'y') { -		return 1; -	} else if (str[0] < 'a' || str[0] > 'c') { -		return 0; -	} +	if (filename[0] == 'y' || filename[0] == 'z') +		return true; +	else if (filename[0] < 'a' || filename[0] > 'c') +		return false; -	CString tempStr = str; -	int idx = tempStr.indexOf('#'); +	CString fname = filename; +	int idx = fname.indexOf('#');  	if (idx >= 0) { -		tempStr = tempStr.left(idx); -		str = str.c_str() + idx + 1; -		str += ".st"; +		fname = fname.left(idx); +		fname += ".st";  	} - - -	return true; -} - -bool CFilesManager::fileExists(const CString &name) { -	Common::File f; -	return f.exists(name); +	// The original had a bunch of code here handling determining +	// which asset path, if any, the filename was present for, +	// and storing the "active asset path" it was found on. +	// This is redundant for ScummVM, which takes care of the paths +	return fileExists(fname);  }  } // End of namespace Titanic diff --git a/engines/titanic/files_manager.h b/engines/titanic/files_manager.h index 63eda5ec1e..93505230f8 100644 --- a/engines/titanic/files_manager.h +++ b/engines/titanic/files_manager.h @@ -54,12 +54,15 @@ public:  		_gameManager = gameManager;  	} -	bool fn1(const CString &name); -  	/**  	 * Returns true if a file of the given name exists  	 */  	static bool fileExists(const CString &name); + +	/** +	 * Scans for a file with a matching name +	 */ +	bool scanForFile(const CString &name);  };  } // End of namespace Titanic diff --git a/engines/titanic/string.cpp b/engines/titanic/string.cpp index c1afb4ff52..dbe0617f06 100644 --- a/engines/titanic/string.cpp +++ b/engines/titanic/string.cpp @@ -56,4 +56,42 @@ int CString::lastIndexOf(char c) {  	return charP ? charP - c_str() : -1;  } +FileType CString::fileTypeSuffix() const { +	CString ext = right(1); +	if (ext == "0" || ext == "4") +		return FILETYPE_IMAGE; +	else if (ext == "1") +		return FILETYPE_WAV; +	else if (ext == "2" || ext == "3") +		return FILETYPE_MOVIE; +	 +	ext = right(3); +	if (ext == "tga" || ext == "jpg") +		return FILETYPE_IMAGE; +	else if (ext == "wav") +		return FILETYPE_WAV; +	else if (ext == "avi" || ext == "mov") +		return FILETYPE_MOVIE; +	else if (ext == "dlg") +		return FILETYPE_DLG; +	else +		return FILETYPE_UNKNOWN; +} + +ImageType CString::imageTypeSuffix() const { +	CString ext = right(1); +	if (ext == "0") +		return IMAGETYPE_TARGA; +	else if (ext == "4") +		return IMAGETYPE_JPEG; + +	ext = right(3); +	if (ext == "tga") +		return IMAGETYPE_TARGA; +	else if (ext == "jpg") +		return IMAGETYPE_JPEG; +	else +		return IMAGETYPE_UNKNOWN; +} +  } // End of namespace Titanic diff --git a/engines/titanic/string.h b/engines/titanic/string.h index d70e23d023..6b8e4b784e 100644 --- a/engines/titanic/string.h +++ b/engines/titanic/string.h @@ -28,6 +28,15 @@  namespace Titanic { +enum FileType { +	FILETYPE_UNKNOWN = 0, FILETYPE_IMAGE = 1, FILETYPE_MOVIE = 2, +	FILETYPE_WAV = 3, FILETYPE_DLG = 4 +}; + +enum ImageType { +	IMAGETYPE_UNKNOWN = 0, IMAGETYPE_TARGA = 1, IMAGETYPE_JPEG = 2 +}; +  class CString : public Common::String {  public:  	CString() : Common::String() {} @@ -66,6 +75,16 @@ public:  	 * Returns the index of the last occurance of a given character  	 */  	int lastIndexOf(char c); + +	/** +	 * Returns the type of a filename based on it's extension +	 */ +	FileType fileTypeSuffix() const; + +	/** +	 * Returns the type of an image filename based on it's extension +	 */ +	ImageType imageTypeSuffix() const;  };  } // End of namespace Titanic diff --git a/engines/titanic/video_surface.cpp b/engines/titanic/video_surface.cpp index 1db23830b4..e649532b81 100644 --- a/engines/titanic/video_surface.cpp +++ b/engines/titanic/video_surface.cpp @@ -21,6 +21,7 @@   */  #include "titanic/video_surface.h" +#include "titanic/screen_manager.h"  namespace Titanic { @@ -51,27 +52,78 @@ OSVideoSurface::OSVideoSurface(CScreenManager *screenManager, const CResourceKey  	_field38 = flag;  	if (_field38) { -		proc8(key); +		loadResource(key);  	} else {  		_resourceKey = key; -		proc43(); +		load();  	}  } -void OSVideoSurface::proc8(const CResourceKey &key) { +void OSVideoSurface::loadResource(const CResourceKey &key) {  	_resourceKey = key;  	_field38 = 1;  	if (hasSurface()) -		proc43(); +		load(); +} + +void OSVideoSurface::loadTarga() { +	warning("TODO"); +} + +void OSVideoSurface::loadJPEG() { +	warning("TODO"); +} + +void OSVideoSurface::loadMovie() { +	warning("TODO");  }  bool OSVideoSurface::hasSurface() {  	return _ddSurface != nullptr;  } -void OSVideoSurface::proc43() { -	warning("TODO"); +int OSVideoSurface::getWidth() const { +	assert(_ddSurface); +	return _ddSurface->w; +} + +int OSVideoSurface::getHeight() const { +	assert(_ddSurface); +	return _ddSurface->h; +} + +int OSVideoSurface::getPitch() const { +	assert(_ddSurface); +	return _ddSurface->pitch; +} + +void OSVideoSurface::load() { +	if (!_resourceKey.scanForFile()) +		return; + +	bool result = true; +	switch (_resourceKey.fileTypeSuffix()) { +	case FILETYPE_IMAGE: +		switch (_resourceKey.imageTypeSuffix()) { +		case IMAGETYPE_TARGA: +			loadTarga(); +			break; +		case IMAGETYPE_JPEG: +			loadJPEG(); +			break; +		default: +			break; +		} +		return true; + +	case FILETYPE_MOVIE: +		loadMovie(); +		return true; + +	default: +		return false; +	}  }  } // End of namespace Titanic diff --git a/engines/titanic/video_surface.h b/engines/titanic/video_surface.h index d0fa54bf85..1c4bf322ab 100644 --- a/engines/titanic/video_surface.h +++ b/engines/titanic/video_surface.h @@ -54,11 +54,64 @@ protected:  public:  	CVideoSurface(CScreenManager *screenManager); +	/** +	 * Set the underlying surface for this video surface +	 */  	void setSurface(CScreenManager *screenManager, DirectDrawSurface *surface); -	virtual void proc8(const CResourceKey &key) = 0; +	/** +	 * Load the surface with the passed resource +	 */ +	virtual void loadResource(const CResourceKey &key) = 0; + +	/** +	 * Loads a Targa image file specified by the resource key +	 */ +	virtual void loadTarga() = 0; + +	/** +	 * Loads a JPEG image file specified by the resource key +	 */ +	virtual void loadJPEG() = 0; + +	/** +	 * Loads a movie file specified by the resource key +	 */ +	virtual void loadMovie() = 0; + +	/** +	 * Lock the surface for direct access to the pixels +	 */ +	virtual void lock() = 0; + +	/** +	 * Unlocks the surface after prior calls to lock() +	 */ +	virtual void unlock() = 0; + +	/** +	 * Returns true if an underlying raw surface has been set +	 */  	virtual bool hasSurface() = 0; -	virtual void proc43() = 0; + +	/** +	 * Returns the width of the surface +	 */ +	virtual int getWidth() = 0; + +	/** +	 * Returns the height of the surface +	 */ +	virtual int getHeight() const = 0; + +	/** +	 * Returns the pitch of the surface in bytes +	 */ +	virtual int getPitch() const = 0; +	/** +	 * Loads the surface data based on the currently set resource key +	 */ +	virtual void load() const = 0;  };  class OSVideoSurface : public CVideoSurface { @@ -66,9 +119,60 @@ public:  	OSVideoSurface(CScreenManager *screenManager, DirectDrawSurface *surface);  	OSVideoSurface(CScreenManager *screenManager, const CResourceKey &key, bool flag = false); -	virtual void proc8(const CResourceKey &key); +	/** +	 * Load the surface with the passed resource +	 */ +	virtual void loadResource(const CResourceKey &key); + +	/** +	 * Loads a Targa image file specified by the resource key +	 */ +	virtual void loadTarga(); + +	/** +	 * Loads a JPEG image file specified by the resource key +	 */ +	virtual void loadJPEG(); + +	/** +	 * Loads a movie file specified by the resource key +	 */ +	virtual void loadMovie(); + +	/** +	 * Lock the surface for direct access to the pixels +	 */ +	virtual void lock(); + +	/** +	 * Unlocks the surface after prior calls to lock() +	 */ +	virtual void unlock(); + +	/** +	 * Returns true if an underlying raw surface has been set +	 */  	virtual bool hasSurface(); -	virtual void proc43(); + +	/** +	 * Returns the width of the surface +	 */ +	virtual int getWidth() const; + +	/** +	 * Returns the height of the surface +	 */ +	virtual int getHeight() const; + +	/** +	 * Returns the pitch of the surface in bytes +	 */ +	virtual int getPitch() const; + +	/** +	 * Loads the surface data based on the currently set resource key +	 */ +	virtual void load();  };  } // End of namespace Titanic  | 
