aboutsummaryrefslogtreecommitdiff
path: root/engines/cryo/ResourceManager.h
diff options
context:
space:
mode:
authorRetro-Junk2016-07-30 23:15:32 +0300
committerEugene Sandulenko2017-01-25 22:41:46 +0100
commitecf0d041045214933b9ef10d490bf62f3c7add99 (patch)
treeeaf091312dc898a15ffedb555588297d2234d871 /engines/cryo/ResourceManager.h
parente25bac9690f2802bce932d9b5490e2d5336be818 (diff)
downloadscummvm-rg350-ecf0d041045214933b9ef10d490bf62f3c7add99.tar.gz
scummvm-rg350-ecf0d041045214933b9ef10d490bf62f3c7add99.tar.bz2
scummvm-rg350-ecf0d041045214933b9ef10d490bf62f3c7add99.zip
CRYO: Lost Eden game engine initial commit
Diffstat (limited to 'engines/cryo/ResourceManager.h')
-rw-r--r--engines/cryo/ResourceManager.h77
1 files changed, 77 insertions, 0 deletions
diff --git a/engines/cryo/ResourceManager.h b/engines/cryo/ResourceManager.h
new file mode 100644
index 0000000000..1ef577678b
--- /dev/null
+++ b/engines/cryo/ResourceManager.h
@@ -0,0 +1,77 @@
+#pragma once
+
+#include "common/array.h"
+#include "common/file.h"
+#include "common/fs.h"
+#include "common/str.h"
+#include "common/substream.h"
+#include "common/debug.h"
+
+namespace Cryo {
+
+ template<typename T>
+ class CryoArray {
+ private:
+ unsigned char *_data;
+ bool _ownData;
+ unsigned short ElementOffset(int num)
+ {
+ assert(_data && num < Count())
+ return (static_cast<unsigned short*>_data)[num];
+ }
+ public:
+ CryoArray(void* data, bool ownData) : _data(data), _ownData(ownData)
+ {
+ }
+ ~CryoArray()
+ {
+ if (_ownData)
+ delete data;
+ }
+ unsigned short Count()
+ {
+ return ElementOffset(0) / 2;
+ }
+ const T* operator[](int index)
+ {
+ return static_cast<T*>(_data + ElementOffset(num));
+ }
+ };
+
+ class ResourceManager
+ {
+ private:
+ struct DatFileEntry {
+ char _name[16];
+ unsigned int _size;
+ unsigned int _offset;
+ unsigned char _flag;
+ };
+
+ Common::Array<DatFileEntry> _files;
+ Common::File _datFile;
+
+ static void *StreamToBuffer(Common::SeekableReadStream *stream, unsigned int *size);
+
+ public:
+ ResourceManager(const Common::String &datFileName);
+ ResourceManager();
+ ~ResourceManager();
+
+ bool LoadDatFile(const Common::String &datFileName);
+
+ // Load resource as a seekable stream
+ Common::SeekableReadStream *GetFile(const Common::String &resName, unsigned int hintIndex = 0);
+ Common::SeekableReadStream *GetFile(unsigned int resIndex);
+
+ // Load resource as a buffer
+ void* GetData(const Common::String &resName, unsigned int *size = nullptr);
+ void* GetData(int resIndex, unsigned int *size = nullptr);
+ void* operator[](int resIndex)
+ {
+ return GetData(resIndex);
+ }
+
+ };
+
+} \ No newline at end of file