*** Merged Code from Multiplayer Branch Revision 2960 ***

- Virtual File System (VFS) by birdflu. This is needed for Multiplayer and is also used for Single Player. Very neat system :-)
- Multiplayer Version 1.1 + some additional features and bugfixes
* INFO: If you compile a new EXE and want to test, be sure to also use the latest SVN GameDir files in your JA2 install directory *




git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@2961 3b4a5df2-a311-0410-b5c6-a8a6f20db521
This commit is contained in:
Wanne
2009-06-04 21:01:45 +00:00
parent 17f44f63e8
commit 47db604b50
301 changed files with 76701 additions and 1843 deletions
+21
View File
@@ -0,0 +1,21 @@
#ifndef _VFS_DIRECTORY_INTERFACE_H_
#define _VFS_DIRECTORY_INTERFACE_H_
//#include "vfs_file_interface.h"
#include "vfs_location_interface.h"
namespace vfs
{
/**
* NOTE: declaration of 'IDirectory' is in file 'vfs_location_interface' because
* of msvc and gcc incompatibilities
*
template<class WriteType>
class IDirectory : public IVFSLocation<vfs::IReadable, WriteType>
*
*/
}
#endif // _VFS_DIRECTORY_INTERFACE_H_
+222
View File
@@ -0,0 +1,222 @@
#ifndef _VFS_FILE_INTERFACE_H_
#define _VFS_FILE_INTERFACE_H_
#include "../vfs_types.h"
namespace vfs
{
/**
* IBaseFile
*/
class IBaseFile
{
public:
enum ESeekDir
{
SD_BEGIN,
SD_CURRENT,
SD_END,
};
public:
IBaseFile(vfs::Path const& sFileName)
: m_sFileName(sFileName)
{};
virtual ~IBaseFile()
{};
vfs::Path const& GetFileName()
{
return m_sFileName;
};
virtual vfs::Path GetFullPath()
{
return GetFileName();
};
virtual bool IsWriteable() = 0;
virtual bool IsReadable() = 0;
virtual bool Close() = 0;
virtual bool GetFileSize(UInt32& uiFileSize) = 0;
UInt32 GetFileSize()
{
UInt32 size;
if(GetFileSize(size))
{
return size;
}
return 0;
};
protected:
vfs::Path m_sFileName;
};
/**
* IReadType , IReadable
*/
class IReadType{};
class IReadable : public vfs::IReadType
{
public:
virtual bool IsOpenRead() = 0;
virtual bool OpenRead() = 0;
virtual bool Read(Byte* pData, UInt32 uiBytesToRead, UInt32& uiBytesRead) = 0;
virtual UInt32 GetReadLocation() = 0;
virtual bool SetReadLocation(UInt32 uiPositionInBytes) = 0;
virtual bool SetReadLocation(Int32 uiOffsetInBytes, IBaseFile::ESeekDir eSeekDir) = 0;
};
//class NonReadable : public IReadType{};
/**
* IWriteType , IWriteable
*/
class IWriteType{};
class IWriteable : public vfs::IWriteType
{
public:
virtual bool IsOpenWrite() = 0;
virtual bool OpenWrite(bool bCreateWhenNotExist = false, bool bTruncate = false) = 0;
virtual bool Write(const Byte* pData, UInt32 uiBytesToWrite, UInt32& uiBytesWritten) = 0;
virtual UInt32 GetWriteLocation() = 0;
virtual bool SetWriteLocation(Int32 uiPositionInBytes) = 0;
virtual bool SetWriteLocation(Int32 uiOffsetInBytes, IBaseFile::ESeekDir eSeekDir) = 0;
virtual bool Delete() = 0;
};
//class NonWriteable: public IWriteType{};
/******************************************************************/
/******************************************************************/
/**
* IFileTemplate
*/
template<typename ReadType=vfs::IReadType, typename WriteType=vfs::IWriteType>
class IFileTemplate : public vfs::IBaseFile, public ReadType, public WriteType
{
public:
typedef ReadType read_type;
typedef WriteType write_type;
public:
IFileTemplate(vfs::Path const& sFileName)
: vfs::IBaseFile(sFileName), ReadType(), WriteType()
{};
virtual ~IFileTemplate()
{};
virtual bool IsWriteable()
{
return typeid(write_type) == typeid(vfs::IWriteable);
}
virtual bool IsReadable()
{
return typeid(read_type) == typeid(vfs::IReadable);
}
virtual vfs::IFileTemplate<read_type,vfs::IWriteable>* GetWriteable()
{
//if(IsWriteable()) TODO: test how this affects compatibility
{
return reinterpret_cast<vfs::IFileTemplate<read_type,vfs::IWriteable>*>(this);
}
return NULL;
}
virtual vfs::IFileTemplate<vfs::IReadable,write_type>* GetReadable()
{
if(IsReadable())
{
return reinterpret_cast<vfs::IFileTemplate<vfs::IReadable,write_type>*>(this);
}
return NULL;
}
};
/**
* IReadableFile
*/
template<class WriteType=vfs::IWriteType>
class IReadableFile : public vfs::IFileTemplate<IReadable,WriteType>
{
public:
template<typename T>
static IReadableFile* Cast(T* t)
{
vfs::IBaseFile* bf = t;
return Cast<IBaseFile>(bf);
}
template<>
static IReadableFile* Cast<IBaseFile>(IBaseFile* bf)
{
if(bf && bf->IsReadable())
{
return static_cast<IReadableFile*>(bf);
}
return NULL;
}
template<class T>
IReadableFile* operator=(T const& t)
{
return IReadableFile::Cast(t);
}
public:
IReadableFile(vfs::Path const& sFileName)
: vfs::IFileTemplate<vfs::IReadable,WriteType>(sFileName)
{};
virtual ~IReadableFile(){};
protected:
IReadableFile();
};
/**
* IWriteableFile
*/
template<class ReadType=IReadType>
class IWriteableFile : public vfs::IFileTemplate<ReadType,vfs::IWriteable>
{
public:
template<class T>
static IWriteableFile* Cast(T* t)
{
vfs::IBaseFile* bf = t;
return Cast<IBaseFile>(bf);
}
template<>
static IWriteableFile* Cast<IBaseFile>(IBaseFile* bf)
{
if(bf && bf->IsWriteable())
{
return static_cast<IWriteableFile*>(bf);
}
return NULL;
}
template<class T>
IWriteableFile& operator=(T const& t)
{
return *IWriteableFile::Cast(t);
}
public:
IWriteableFile(vfs::Path const& sFileName)
: vfs::IFileTemplate<ReadType,vfs::IWriteable>(sFileName)
{};
virtual ~IWriteableFile(){};
protected:
IWriteableFile();
};
/******************************************************************/
/******************************************************************/
/**
* typedef's
*/
typedef vfs::IReadableFile<vfs::IWriteType> tReadableFile;
typedef vfs::IWriteableFile<vfs::IReadable> tWriteableFile;
//typedef vfs::IWriteableFile<vfs::IReadType> tWriteableFile;
} // end namespace
#endif // _VFS_FILE_INTERFACE_H_
+50
View File
@@ -0,0 +1,50 @@
#ifndef _VFS_LIBRARY_INTERFACE_H_
#define _VFS_LIBRARY_INTERFACE_H_
#include "vfs_location_interface.h"
namespace vfs
{
class ILibrary : public vfs::IVFSLocation<vfs::IReadable,vfs::IWriteType>
{
public:
ILibrary(tReadableFile *pLibraryFile, vfs::Path const& sMountPoint, bool bOwnFile = false)
: vfs::IVFSLocation<vfs::IReadable,vfs::IWriteType>(sMountPoint), m_pLibraryFile(pLibraryFile), m_bOwnLibFile(bOwnFile)
{};
virtual ~ILibrary()
{
if(m_pLibraryFile && m_bOwnLibFile)
{
m_pLibraryFile->Close();
delete m_pLibraryFile;
m_pLibraryFile = NULL;
}
};
virtual bool Init() = 0;
virtual bool CloseLibrary() = 0;
virtual bool Close(tFileType *pFileHandle) = 0;
virtual bool OpenRead(tFileType *pFileHandle) = 0;
virtual bool Read(tFileType *pFileHandle, Byte* pData, UInt32 uiBytesToRead, UInt32& uiBytesRead) = 0;
virtual UInt32 GetReadLocation(tFileType *pFileHandle) = 0;
virtual bool SetReadLocation(tFileType *pFileHandle, UInt32 uiPositionInBytes) = 0;
virtual bool SetReadLocation(tFileType *pFileHandle, Int32 uiOffsetInBytes, IBaseFile::ESeekDir eSeekDir) = 0;
virtual bool GetFileSize(tFileType *pFileHandle, UInt32& uiFileSize) = 0;
vfs::Path const& GetLibName()
{
return m_pLibraryFile->GetFileName();
}
protected:
vfs::tReadableFile* m_pLibraryFile;
bool m_bOwnLibFile;
};
}
#endif // _VFS_LIBRARY_INTERFACE_H_
@@ -0,0 +1,43 @@
#ifndef _VFS_LOCATION_AWARE_FILE_INTERFACE_H_
#define _VFS_LOCATION_AWARE_FILE_INTERFACE_H_
#include "vfs_file_interface.h"
namespace vfs
{
template<typename ReadType, typename WriteType>
class IVFSLocation;
template<class WriteType> class IDirectory;
class ILibrary;
/**
* ILocationAware
*/
template<typename ReadType, typename WriteType>
class ILocationAware
{
public:
typedef vfs::IVFSLocation<ReadType,WriteType> tLocationType;
public:
ILocationAware(vfs::IVFSLocation<ReadType,WriteType> *pLocation)
: _pLoc_(pLocation)
{};
virtual ~ILocationAware()
{};
protected:
tLocationType* _pLoc_;
};
/******************************************************************/
/******************************************************************/
}
#endif // _VFS_LOCATION_AWARE_FILE_INTERFACE_H_
+236
View File
@@ -0,0 +1,236 @@
#ifndef _VFS_LOCATION_INTERFACE_H_
#define _VFS_LOCATION_INTERFACE_H_
#include "../vfs_types.h"
#include "../vfs_debug.h"
#include "vfs_file_interface.h"
#include <map>
#include <list>
namespace vfs
{
class IBaseLocation
{
public:
class Iterator
{
public:
class IImplemetation
{
public:
virtual ~IImplemetation() {};
virtual vfs::IBaseFile* value() = 0;
virtual void next() = 0;
};
public:
Iterator() : _iter_impl(NULL), _file(NULL) {};
Iterator(IImplemetation* impl) : _iter_impl(impl), _file(NULL)
{
THROWIFFALSE(_iter_impl, L"EXCEPTION");
_file = _iter_impl->value();
}
~Iterator()
{
}
//////////////////////////////
vfs::IBaseFile* value()
{
return _file;
};
void next()
{
if(_iter_impl)
{
_iter_impl->next();
_file = _iter_impl->value();
if(!_file)
{
delete _iter_impl;
_iter_impl = NULL;
}
}
}
bool end()
{
return _file == NULL;
}
//////////////////////////////
private:
IImplemetation* _iter_impl;
vfs::IBaseFile* _file;
};
public:
virtual ~IBaseLocation()
{};
template<typename T>
T* Cast()
{
return dynamic_cast<T*>(this);
}
virtual bool IsWriteable() = 0;
virtual bool IsReadable() = 0;
virtual vfs::Path const& GetFullPath() = 0;
virtual bool FileExists(vfs::Path const& sFileName) = 0;
virtual vfs::IBaseFile* GetFile(vfs::Path const& sFileName) = 0;
virtual Iterator begin() = 0;
virtual void GetSubDirList(std::list<vfs::Path>& rlSubDirs) = 0;
};
/**
* IVFSLocation
*/
//template<typename ReadType=vfs::IReadType, typename WriteType=vfs::IWriteType>
template<typename ReadType, typename WriteType>
class IVFSLocation : public IBaseLocation
{
public:
typedef vfs::IVFSLocation<ReadType,WriteType> tClassType;
typedef vfs::IFileTemplate<ReadType,WriteType> tFileType;
typedef ReadType tReadType;
typedef WriteType tWriteType;
typedef std::list<std::pair<tFileType*,vfs::Path> > tListFilesWithPath;
public:
IVFSLocation(vfs::Path const& sMountPoint)
: m_sMountPoint(sMountPoint)
{};
virtual ~IVFSLocation()
{};
// has to be virtual , or the types of the caller (not the real object) will be tested
virtual bool IsWriteable()
{
return typeid(tWriteType) == typeid(vfs::IWriteable);
}
virtual bool IsReadable()
{
return typeid(tReadType) == typeid(vfs::IReadable);
}
virtual IVFSLocation<IReadType,IWriteable>* GetWriteable()
{
//if(IsWriteable()) TODO: test how this affects compatibility
{
return reinterpret_cast<IVFSLocation<vfs::IReadType,vfs::IWriteable>*>(this);
}
return NULL;
}
vfs::Path const& GetMountPoint()
{
return m_sMountPoint;
};
/**
* IVFSLocation interface
*/
virtual vfs::Path const& GetFullPath()
{
return m_sMountPoint;
}
virtual bool FileExists(vfs::Path const& sFileName) = 0;
virtual vfs::IBaseFile* GetFile(vfs::Path const& sFileName) = 0;
virtual tFileType* GetFileTyped(vfs::Path const& rFileName) = 0;
protected:
vfs::Path m_sMountPoint;
};
/**************************************************************************************/
/**************************************************************************************/
template<typename WriteType=vfs::IWriteType>
class IReadLocation : public IVFSLocation<IReadable,WriteType>
{
public:
template<typename T>
static IReadLocation* Cast(T* t)
{
// which file type does the to tested location contain
typename T::tFileType* _F=NULL;
// is it readable?
vfs::IReadable *rf = _F;
// is the write type compatible (probably redundant)
WriteType *wf = _F;
// it is readable and the write type fits
return reinterpret_cast<IReadLocation*>(t);
}
template<>
static IReadLocation* Cast<IBaseLocation>(IBaseLocation* bl)
{
return dynamic_cast<IReadLocation*>(bl);
}
public:
IReadLocation(vfs::Path const& sLocalPath)
: vfs::IVFSLocation<IReadable,WriteType>(sLocalPath)
{};
virtual ~IReadLocation(){};
};
typedef IReadLocation<vfs::IWriteType> tReadLocation;
template<typename ReadType=vfs::IReadType>
class IWriteLocation : public vfs::IVFSLocation<ReadType,vfs::IWriteable>
{
public:
template<class T>
static IWriteLocation* Cast(T* t)
{
// which file type does the to tested location contain
typename T::tFileType* _F=NULL;
// is it writeable?
vfs::IWriteable *wf = _F;
// is the read type compatible (probably redundant)
ReadType *rf = _F;
// is writeable and the read type fits
return reinterpret_cast<IWriteLocation*>(t);
}
template<>
static IWriteLocation* Cast<IBaseLocation>(IBaseLocation* bl)
{
return dynamic_cast<IWriteLocation*>(bl);
}
public:
IWriteLocation(vfs::Path const& sLocalPath)
: vfs::IVFSLocation<ReadType,vfs::IWriteable>(sLocalPath)
{};
virtual ~IWriteLocation(){};
};
typedef IWriteLocation<vfs::IReadType> tWriteLocation;
/**************************************************************************************/
/**************************************************************************************/
template<class WriteType>
class IDirectory : public vfs::IVFSLocation<vfs::IReadable, WriteType>
{
typedef typename vfs::IVFSLocation<vfs::IReadable, WriteType> tBaseType;
public:
IDirectory(vfs::Path const& sMountPoint, vfs::Path const& sRealPath)
: vfs::IVFSLocation<vfs::IReadable, WriteType>(sMountPoint), m_sRealPath(sRealPath)
{};
virtual ~IDirectory()
{};
vfs::Path const& GetRealPath()
{
return m_sRealPath;
}
virtual tBaseType::tFileType* AddFile(vfs::Path const& sFilename, bool bDeleteOldFile=false) = 0;
virtual bool AddFile( typename vfs::IVFSLocation<vfs::IReadable, WriteType>::tFileType* pFile, bool bDeleteOldFile=false) = 0;
virtual bool CreateSubDirectory(vfs::Path const& sSubDirPath) = 0;
virtual bool DeleteDirectory(vfs::Path const& sDirPath) = 0;
virtual bool DeleteFileFromDirectory(vfs::Path const& sFileName) = 0;
protected:
const vfs::Path m_sRealPath;
};
/**************************************************************************************/
/**************************************************************************************/
} // end namespace
#endif // _VFS_LOCATION_INTERFACE_H_