mirror of
https://github.com/1dot13/source.git
synced 2026-08-26 14:30:26 +02:00
*** 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:
@@ -20,6 +20,8 @@
|
||||
#include "TopicOps.h"
|
||||
#include "TopicIDs.h"
|
||||
|
||||
#include "VFS/vfs_types.h"
|
||||
|
||||
/*
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -55,7 +57,7 @@ inline void _Null() { }
|
||||
//
|
||||
// Uncomment the follow to turn on more aggressive assertions
|
||||
//
|
||||
#define USE_AGGRESSIVE_ASSERTIONS
|
||||
//#define USE_AGGRESSIVE_ASSERTIONS
|
||||
|
||||
#ifdef FORCE_ASSERTS_ON
|
||||
|
||||
@@ -215,6 +217,10 @@ extern void _DebugMessage(const char *pSourceFile, unsigned uiLineNum, const cha
|
||||
#define DebugAttackBusy(x)
|
||||
#endif
|
||||
|
||||
#include "VFS/vfs_debug.h"
|
||||
|
||||
void _ExceptionMessage( CBasicException &ex );
|
||||
|
||||
/*
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -500,3 +500,22 @@ STR8 String(const STR8 String, ...)
|
||||
return gbTmpDebugString[usIndex];
|
||||
|
||||
}
|
||||
|
||||
void _ExceptionMessage( CBasicException &ex )
|
||||
{
|
||||
g_ExceptionList.clear();
|
||||
CBasicException::CALLSTACK::iterator it = ex.m_CallStack.begin();
|
||||
for(; it!=ex.m_CallStack.end(); ++it)
|
||||
{
|
||||
SExceptionData exd;
|
||||
exd.message = (*it).message;
|
||||
exd.function = (*it).function;
|
||||
exd.file = (*it).file;
|
||||
exd.line = (*it).line;
|
||||
g_ExceptionList.push_back(exd);
|
||||
}
|
||||
_FailMessage("",0,"");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#include <malloc.h>
|
||||
#include <stdio.h>
|
||||
#include <direct.h>
|
||||
|
||||
|
||||
#include "windows.h"
|
||||
#include "FileMan.h"
|
||||
@@ -45,6 +46,30 @@
|
||||
#include "LibraryDataBase.h"
|
||||
#include "io.h"
|
||||
|
||||
#endif
|
||||
|
||||
using namespace std;
|
||||
|
||||
#include "VFS/vfs.h"
|
||||
|
||||
#ifdef USE_VFS
|
||||
|
||||
#include "VFS/vfs_file_raii.h"
|
||||
#include <map>
|
||||
|
||||
struct SOperation
|
||||
{
|
||||
enum EOperation
|
||||
{
|
||||
UNKNOWN, READ, WRITE,
|
||||
};
|
||||
EOperation op;
|
||||
SOperation() : op(UNKNOWN) {};
|
||||
};
|
||||
|
||||
typedef std::map<vfs::IBaseFile*, SOperation> tFILEMAP;
|
||||
static tFILEMAP s_mapFiles;
|
||||
|
||||
#endif
|
||||
//**************************************************************************
|
||||
//
|
||||
@@ -230,6 +255,9 @@ void FileDebug( BOOLEAN f )
|
||||
//**************************************************************************
|
||||
BOOLEAN FileExists( STR strFilename )
|
||||
{
|
||||
#ifdef USE_VFS
|
||||
return GetVFS()->FileExists(vfs::Path(strFilename));
|
||||
#else
|
||||
// First check to see if it's in a library (most files should be there)
|
||||
if ( gFileDataBase.fInitialized &&
|
||||
CheckIfFileExistInLibrary( strFilename ) ) return TRUE;
|
||||
@@ -246,6 +274,7 @@ BOOLEAN FileExists( STR strFilename )
|
||||
return TRUE;
|
||||
|
||||
return FALSE;
|
||||
#endif
|
||||
}
|
||||
|
||||
//**************************************************************************
|
||||
@@ -272,6 +301,9 @@ BOOLEAN FileExists( STR strFilename )
|
||||
//**************************************************************************
|
||||
extern BOOLEAN FileExistsNoDB( STR strFilename )
|
||||
{
|
||||
#ifdef USE_VFS
|
||||
return GetVFS()->FileExists(vfs::Path(strFilename));
|
||||
#else
|
||||
// First check if it's in the custom Data directory
|
||||
if ( gCustomDataCat.FindFile(strFilename) ) return TRUE;
|
||||
|
||||
@@ -284,6 +316,7 @@ extern BOOLEAN FileExistsNoDB( STR strFilename )
|
||||
return TRUE;
|
||||
|
||||
return FALSE;
|
||||
#endif
|
||||
}
|
||||
|
||||
//**************************************************************************
|
||||
@@ -308,12 +341,16 @@ extern BOOLEAN FileExistsNoDB( STR strFilename )
|
||||
//**************************************************************************
|
||||
BOOLEAN FileDelete( STR strFilename )
|
||||
{
|
||||
#ifdef USE_VFS
|
||||
return GetVFS()->RemoveFileFromFS(vfs::Path(strFilename));
|
||||
#else
|
||||
// Snap: delete the file from the default Data catalogue (if it is there)
|
||||
// Since the path can be either relative or absolute, try both methods
|
||||
gDefaultDataCat.RemoveFile(strFilename, true);
|
||||
gDefaultDataCat.RemoveFile(strFilename, false);
|
||||
|
||||
return( DeleteFile( (LPCSTR) strFilename ) );
|
||||
#endif
|
||||
}
|
||||
|
||||
//**************************************************************************
|
||||
@@ -343,6 +380,41 @@ BOOLEAN FileDelete( STR strFilename )
|
||||
//**************************************************************************
|
||||
HWFILE FileOpen( STR strFilename, UINT32 uiOptions, BOOLEAN fDeleteOnClose )
|
||||
{
|
||||
#ifdef USE_VFS
|
||||
vfs::Path path(strFilename);
|
||||
vfs::IBaseFile *pFile = NULL;
|
||||
try
|
||||
{
|
||||
if(uiOptions & FILE_ACCESS_WRITE)
|
||||
{
|
||||
// 'vfs::CVirtualFile::SF_TOP' should be enough, but if for some strange reason
|
||||
// file creation fails, we will stop at a writeable profile
|
||||
// and won't unintentionally mess up a file from another profile
|
||||
vfs::COpenWriteFile open_w( path, true, false, vfs::CVirtualFile::SF_STOP_ON_WRITEABLE_PROFILE);
|
||||
pFile = &open_w.file();
|
||||
open_w.release();
|
||||
s_mapFiles[pFile].op = SOperation::WRITE;
|
||||
return (HWFILE)pFile;
|
||||
}
|
||||
else if(uiOptions & FILE_ACCESS_READ)
|
||||
{
|
||||
vfs::COpenReadFile open_r(path, vfs::CVirtualFile::SF_TOP);
|
||||
pFile = &open_r.file();
|
||||
open_r.release();
|
||||
s_mapFiles[pFile].op = SOperation::READ;
|
||||
return (HWFILE)pFile;
|
||||
}
|
||||
}
|
||||
// sometimes a file is supposed to opened that does not exist (not tested with FileExists())
|
||||
// this operation can fail with an exception that the calling code doesn't catch
|
||||
// instead we catch it (any exception, not just CBasicException) here and return 0
|
||||
catch(CBasicException& ex) { LogException(ex); }
|
||||
catch(...)
|
||||
{
|
||||
LogException( CBasicException("Caught undefined exception", _FUNCTION_FORMAT_, __LINE__, __FILE__) );
|
||||
}
|
||||
return 0;
|
||||
#else
|
||||
HWFILE hFile;
|
||||
HANDLE hRealFile;
|
||||
DWORD dwAccess;
|
||||
@@ -483,6 +555,7 @@ HWFILE FileOpen( STR strFilename, UINT32 uiOptions, BOOLEAN fDeleteOnClose )
|
||||
return(0);
|
||||
|
||||
return(hFile);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -507,6 +580,14 @@ HWFILE FileOpen( STR strFilename, UINT32 uiOptions, BOOLEAN fDeleteOnClose )
|
||||
|
||||
void FileClose( HWFILE hFile )
|
||||
{
|
||||
#ifdef USE_VFS
|
||||
vfs::IBaseFile *pFile = (vfs::IBaseFile*)hFile;
|
||||
if(pFile)
|
||||
{
|
||||
pFile->Close();
|
||||
s_mapFiles.erase(pFile);
|
||||
}
|
||||
#else
|
||||
INT16 sLibraryID;
|
||||
UINT32 uiFileNum;
|
||||
|
||||
@@ -535,6 +616,7 @@ void FileClose( HWFILE hFile )
|
||||
if( gFileDataBase.fInitialized )
|
||||
CloseLibraryFile( sLibraryID, uiFileNum );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
//**************************************************************************
|
||||
@@ -573,6 +655,36 @@ void FileClose( HWFILE hFile )
|
||||
|
||||
BOOLEAN FileRead( HWFILE hFile, PTR pDest, UINT32 uiBytesToRead, UINT32 *puiBytesRead )
|
||||
{
|
||||
#ifdef USE_VFS
|
||||
#ifdef JA2TESTVERSION
|
||||
UINT32 uiStartTime = GetJA2Clock();
|
||||
#endif
|
||||
bool bSuccess = false;
|
||||
vfs::IBaseFile *pFile = (vfs::IBaseFile*)hFile;
|
||||
if(pFile && (s_mapFiles[pFile].op == SOperation::READ))
|
||||
{
|
||||
vfs::tReadableFile *pRF = vfs::tReadableFile::Cast(pFile);
|
||||
if(pRF)
|
||||
{
|
||||
UINT32 uiBytesRead;
|
||||
bSuccess = pRF->Read((vfs::Byte*)pDest, uiBytesToRead, uiBytesRead);
|
||||
if(uiBytesToRead != uiBytesRead)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
if(puiBytesRead)
|
||||
{
|
||||
*puiBytesRead = uiBytesRead;
|
||||
}
|
||||
}
|
||||
}
|
||||
#ifdef JA2TESTVERSION
|
||||
//Add the time that we spent in this function to the total.
|
||||
uiTotalFileReadTime += GetJA2Clock() - uiStartTime;
|
||||
uiTotalFileReadCalls++;
|
||||
#endif
|
||||
return bSuccess;
|
||||
#else
|
||||
HANDLE hRealFile;
|
||||
DWORD dwNumBytesToRead, dwNumBytesRead;
|
||||
BOOLEAN fRet = FALSE;
|
||||
@@ -640,6 +752,7 @@ BOOLEAN FileRead( HWFILE hFile, PTR pDest, UINT32 uiBytesToRead, UINT32 *puiByte
|
||||
#endif
|
||||
|
||||
return(fRet);
|
||||
#endif
|
||||
}
|
||||
|
||||
//**************************************************************************
|
||||
@@ -671,6 +784,29 @@ BOOLEAN FileRead( HWFILE hFile, PTR pDest, UINT32 uiBytesToRead, UINT32 *puiByte
|
||||
|
||||
BOOLEAN FileWrite( HWFILE hFile, PTR pDest, UINT32 uiBytesToWrite, UINT32 *puiBytesWritten )
|
||||
{
|
||||
#ifdef USE_VFS
|
||||
vfs::IBaseFile *pFile = (vfs::IBaseFile*)hFile;
|
||||
if(pFile && (s_mapFiles[pFile].op == SOperation::WRITE))
|
||||
{
|
||||
vfs::tWriteableFile *pWF = vfs::tWriteableFile::Cast(pFile);
|
||||
if(pWF)
|
||||
{
|
||||
UINT32 uiBytesWritten;
|
||||
bool bSuccess = pWF->Write((vfs::Byte*)pDest, uiBytesToWrite, uiBytesWritten);
|
||||
|
||||
if (uiBytesToWrite != uiBytesWritten)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
if ( puiBytesWritten )
|
||||
{
|
||||
*puiBytesWritten = uiBytesWritten;
|
||||
}
|
||||
return bSuccess;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
#else
|
||||
HANDLE hRealFile;
|
||||
DWORD dwNumBytesToWrite, dwNumBytesWritten;
|
||||
BOOLEAN fRet;
|
||||
@@ -705,6 +841,7 @@ BOOLEAN FileWrite( HWFILE hFile, PTR pDest, UINT32 uiBytesToWrite, UINT32 *puiBy
|
||||
}
|
||||
|
||||
return(fRet);
|
||||
#endif
|
||||
}
|
||||
|
||||
//**************************************************************************
|
||||
@@ -730,6 +867,27 @@ BOOLEAN FileWrite( HWFILE hFile, PTR pDest, UINT32 uiBytesToWrite, UINT32 *puiBy
|
||||
|
||||
BOOLEAN FileLoad( STR strFilename, PTR pDest, UINT32 uiBytesToRead, UINT32 *puiBytesRead )
|
||||
{
|
||||
#ifdef USE_VFS
|
||||
vfs::tReadableFile *pFile = GetVFS()->GetRFile(vfs::Path(strFilename));
|
||||
if(pFile)
|
||||
{
|
||||
UINT32 uiNumBytesRead;
|
||||
bool bSuccess = pFile->Read((vfs::Byte*)pDest,uiBytesToRead, uiNumBytesRead);
|
||||
pFile->Close();
|
||||
|
||||
if (uiBytesToRead != uiNumBytesRead)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
if ( puiBytesRead )
|
||||
{
|
||||
*puiBytesRead = uiNumBytesRead;
|
||||
}
|
||||
CHECKF( uiNumBytesRead == uiBytesToRead );
|
||||
return bSuccess;
|
||||
}
|
||||
return FALSE;
|
||||
#else
|
||||
HWFILE hFile;
|
||||
UINT32 uiNumBytesRead;
|
||||
BOOLEAN fRet;
|
||||
@@ -752,6 +910,7 @@ BOOLEAN FileLoad( STR strFilename, PTR pDest, UINT32 uiBytesToRead, UINT32 *puiB
|
||||
fRet = FALSE;
|
||||
|
||||
return(fRet);
|
||||
#endif
|
||||
}
|
||||
|
||||
//**************************************************************************
|
||||
@@ -784,6 +943,19 @@ BOOLEAN FileLoad( STR strFilename, PTR pDest, UINT32 uiBytesToRead, UINT32 *puiB
|
||||
|
||||
BOOLEAN _cdecl FilePrintf( HWFILE hFile, STR8 strFormatted, ... )
|
||||
{
|
||||
#ifdef USE_VFS
|
||||
CHAR8 strToSend[160]; /* itemdescription of item 0 will NOT fit if only 80 Chars per Line!, Sergeant_Kolja, 2007-06-10 */
|
||||
va_list argptr;
|
||||
BOOLEAN fRetVal = FALSE;
|
||||
|
||||
va_start(argptr, strFormatted);
|
||||
_vsnprintf( strToSend, DIM(strToSend), strFormatted, argptr ); /* made StringLen Save, Sergeant_Kolja, 2007-06-10 */
|
||||
strToSend[ DIM(strToSend)-1 ] = 0;
|
||||
va_end(argptr);
|
||||
|
||||
fRetVal = FileWrite( hFile, strToSend, strlen(strToSend), NULL );
|
||||
return( fRetVal );
|
||||
#else
|
||||
CHAR8 strToSend[160]; /* itemdescription of item 0 will NOT fit if only 80 Chars per Line!, Sergeant_Kolja, 2007-06-10 */
|
||||
va_list argptr;
|
||||
BOOLEAN fRetVal = FALSE;
|
||||
@@ -810,6 +982,7 @@ BOOLEAN _cdecl FilePrintf( HWFILE hFile, STR8 strFormatted, ... )
|
||||
}
|
||||
|
||||
return( fRetVal );
|
||||
#endif
|
||||
}
|
||||
|
||||
//**************************************************************************
|
||||
@@ -839,6 +1012,53 @@ BOOLEAN _cdecl FilePrintf( HWFILE hFile, STR8 strFormatted, ... )
|
||||
|
||||
BOOLEAN FileSeek( HWFILE hFile, UINT32 uiDistance, UINT8 uiHow )
|
||||
{
|
||||
#ifdef USE_VFS
|
||||
INT32 iDistance = (INT32)uiDistance;
|
||||
|
||||
vfs::IBaseFile *pFile = (vfs::IBaseFile*)hFile;
|
||||
if(pFile)
|
||||
{
|
||||
vfs::IBaseFile::ESeekDir eSD;
|
||||
if ( uiHow == FILE_SEEK_FROM_START )
|
||||
{
|
||||
eSD = vfs::IBaseFile::SD_BEGIN;
|
||||
}
|
||||
else if ( uiHow == FILE_SEEK_FROM_END )
|
||||
{
|
||||
eSD = vfs::IBaseFile::SD_END;
|
||||
if( iDistance > 0 )
|
||||
{
|
||||
iDistance = -(iDistance);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
eSD = vfs::IBaseFile::SD_CURRENT;
|
||||
}
|
||||
|
||||
if(s_mapFiles[pFile].op == SOperation::WRITE)
|
||||
{
|
||||
vfs::tWriteableFile *pWF = vfs::tWriteableFile::Cast(pFile);
|
||||
if(pWF)
|
||||
{
|
||||
return pWF->SetWriteLocation(iDistance, eSD);
|
||||
}
|
||||
}
|
||||
else if(s_mapFiles[pFile].op == SOperation::READ)
|
||||
{
|
||||
vfs::tReadableFile *pRF = vfs::tReadableFile::Cast(pFile);
|
||||
if(pRF)
|
||||
{
|
||||
return pRF->SetReadLocation(iDistance, eSD);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
THROWEXCEPTION(L"unknown operation");
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
#else
|
||||
HANDLE hRealFile;
|
||||
LONG lDistanceToMove;
|
||||
DWORD dwMoveMethod;
|
||||
@@ -881,6 +1101,7 @@ BOOLEAN FileSeek( HWFILE hFile, UINT32 uiDistance, UINT8 uiHow )
|
||||
}
|
||||
|
||||
return(TRUE);
|
||||
#endif
|
||||
}
|
||||
|
||||
//**************************************************************************
|
||||
@@ -908,6 +1129,30 @@ BOOLEAN FileSeek( HWFILE hFile, UINT32 uiDistance, UINT8 uiHow )
|
||||
|
||||
INT32 FileGetPos( HWFILE hFile )
|
||||
{
|
||||
#ifdef USE_VFS
|
||||
vfs::IBaseFile *pFile = (vfs::IBaseFile*)hFile;
|
||||
if(pFile)
|
||||
{
|
||||
if(pFile->IsWriteable())
|
||||
{
|
||||
vfs::tWriteableFile *pWF = vfs::tWriteableFile::Cast(pFile);
|
||||
if(pWF)
|
||||
{
|
||||
return pWF->GetWriteLocation();
|
||||
}
|
||||
}
|
||||
else if(pFile->IsReadable())
|
||||
{
|
||||
vfs::tReadableFile *pRF = vfs::tReadableFile::Cast(pFile);
|
||||
if(pRF)
|
||||
{
|
||||
return pRF->GetReadLocation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return BAD_INDEX;
|
||||
#else
|
||||
HANDLE hRealFile;
|
||||
UINT32 uiPositionInFile=0;
|
||||
|
||||
@@ -944,6 +1189,7 @@ INT32 FileGetPos( HWFILE hFile )
|
||||
}
|
||||
|
||||
return(BAD_INDEX);
|
||||
#endif
|
||||
}
|
||||
|
||||
//**************************************************************************
|
||||
@@ -971,6 +1217,14 @@ INT32 FileGetPos( HWFILE hFile )
|
||||
|
||||
UINT32 FileGetSize( HWFILE hFile )
|
||||
{
|
||||
#ifdef USE_VFS
|
||||
vfs::IBaseFile *pFile = (vfs::IBaseFile*)hFile;
|
||||
if(pFile)
|
||||
{
|
||||
return pFile->GetFileSize();
|
||||
}
|
||||
return 0;
|
||||
#else
|
||||
HANDLE hRealHandle;
|
||||
UINT32 uiFileSize = 0xFFFFFFFF;
|
||||
|
||||
@@ -999,6 +1253,7 @@ UINT32 FileGetSize( HWFILE hFile )
|
||||
return(0);
|
||||
else
|
||||
return( uiFileSize );
|
||||
#endif
|
||||
}
|
||||
|
||||
//**************************************************************************
|
||||
@@ -1250,6 +1505,10 @@ void BuildFileDirectory( void )
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//**************************************************************************
|
||||
//
|
||||
// GetFilesInDirectory
|
||||
@@ -1356,7 +1615,11 @@ BOOLEAN DirectoryExists( STRING512 pcDirectory )
|
||||
|
||||
BOOLEAN MakeFileManDirectory( STRING512 pcDirectory )
|
||||
{
|
||||
#ifndef USE_VFS
|
||||
return CreateDirectory( pcDirectory, NULL );
|
||||
#else
|
||||
return FALSE;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -1366,6 +1629,10 @@ BOOLEAN MakeFileManDirectory( STRING512 pcDirectory )
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
BOOLEAN RemoveFileManDirectory( STRING512 pcDirectory, BOOLEAN fRecursive )
|
||||
{
|
||||
#ifdef USE_VFS
|
||||
// ignore 'recursive' flag, just delete every file in that subtree (but leave the directories)
|
||||
return GetVFS()->RemoveDirectoryFromFS(pcDirectory);
|
||||
#else
|
||||
WIN32_FIND_DATA sFindData;
|
||||
HANDLE SearchHandle;
|
||||
const CHAR8 *pFileSpec = "*.*";
|
||||
@@ -1442,6 +1709,7 @@ BOOLEAN RemoveFileManDirectory( STRING512 pcDirectory, BOOLEAN fRecursive )
|
||||
}
|
||||
|
||||
return fRetval;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -1451,6 +1719,10 @@ BOOLEAN RemoveFileManDirectory( STRING512 pcDirectory, BOOLEAN fRecursive )
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
BOOLEAN EraseDirectory( STRING512 pcDirectory)
|
||||
{
|
||||
#ifdef USE_VFS
|
||||
// ignore 'recursive' flag, just delete every file in that subtree (but leave the directories)
|
||||
return GetVFS()->RemoveDirectoryFromFS(pcDirectory);
|
||||
#else
|
||||
WIN32_FIND_DATA sFindData;
|
||||
HANDLE SearchHandle;
|
||||
const CHAR8 *pFileSpec = "*.*";
|
||||
@@ -1502,6 +1774,7 @@ BOOLEAN EraseDirectory( STRING512 pcDirectory)
|
||||
}
|
||||
|
||||
return( TRUE );
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -1530,8 +1803,31 @@ BOOLEAN GetExecutableDirectory( STRING512 pcDirectory )
|
||||
return( TRUE );
|
||||
}
|
||||
|
||||
#ifdef USE_VFS
|
||||
static vfs::CVirtualFileSystem::Iterator file_iter;
|
||||
#endif
|
||||
BOOLEAN GetFileFirst( CHAR8 * pSpec, GETFILESTRUCT *pGFStruct )
|
||||
{
|
||||
#ifdef USE_VFS
|
||||
CHECKF( pSpec != NULL );
|
||||
CHECKF( pGFStruct != NULL );
|
||||
|
||||
file_iter = GetVFS()->begin(pSpec);
|
||||
if(!file_iter.end())
|
||||
{
|
||||
//vfs::Path const& path = file_iter.value()->GetFullPath();
|
||||
vfs::Path const& path = file_iter.value()->GetFileName();
|
||||
std::string s = path().utf8();
|
||||
utf8string::size_t size = s.length();
|
||||
size = std::min<unsigned int>(size,260-1);
|
||||
sprintf( pGFStruct->zFileName, s.c_str());
|
||||
pGFStruct->zFileName[size] = 0;
|
||||
|
||||
// don't care for the rest of variables in pGFStruct
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
#else
|
||||
INT32 x,iWhich=0;
|
||||
BOOLEAN fFound;
|
||||
|
||||
@@ -1562,10 +1858,31 @@ BOOLEAN GetFileFirst( CHAR8 * pSpec, GETFILESTRUCT *pGFStruct )
|
||||
W32toSGPFileFind( pGFStruct, &Win32FindInfo[iWhich] );
|
||||
|
||||
return(TRUE);
|
||||
#endif
|
||||
}
|
||||
|
||||
BOOLEAN GetFileNext( GETFILESTRUCT *pGFStruct )
|
||||
{
|
||||
#ifdef USE_VFS
|
||||
if(!file_iter.end())
|
||||
{
|
||||
file_iter.next();
|
||||
}
|
||||
if(!file_iter.end())
|
||||
{
|
||||
//vfs::Path const& path = file_iter.value()->GetFullPath();
|
||||
vfs::Path const& path = file_iter.value()->GetFileName();
|
||||
std::string s = path().utf8();
|
||||
utf8string::size_t size = s.length();
|
||||
size = std::min<unsigned int>(size,260-1);
|
||||
sprintf( pGFStruct->zFileName, s.c_str());
|
||||
pGFStruct->zFileName[size] = 0;
|
||||
|
||||
// don't care for the rest of variables in pGFStruct
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
#else
|
||||
CHECKF( pGFStruct != NULL );
|
||||
|
||||
if ( FindNextFile(hFindInfoHandle[pGFStruct->iFindHandle], &Win32FindInfo[pGFStruct->iFindHandle]) )
|
||||
@@ -1574,10 +1891,14 @@ BOOLEAN GetFileNext( GETFILESTRUCT *pGFStruct )
|
||||
return(TRUE);
|
||||
}
|
||||
return(FALSE);
|
||||
#endif
|
||||
}
|
||||
|
||||
void GetFileClose( GETFILESTRUCT *pGFStruct )
|
||||
{
|
||||
#ifdef USE_VFS
|
||||
file_iter = vfs::CVirtualFileSystem::Iterator();
|
||||
#else
|
||||
if ( pGFStruct == NULL )
|
||||
return;
|
||||
|
||||
@@ -1586,6 +1907,7 @@ void GetFileClose( GETFILESTRUCT *pGFStruct )
|
||||
fFindInfoInUse[pGFStruct->iFindHandle] = FALSE;
|
||||
|
||||
return;
|
||||
#endif
|
||||
}
|
||||
|
||||
void W32toSGPFileFind( GETFILESTRUCT *pGFStruct, WIN32_FIND_DATA *pW32Struct )
|
||||
@@ -1802,13 +2124,45 @@ UINT32 FileGetAttributes( STR strFilename )
|
||||
|
||||
BOOLEAN FileClearAttributes( STR strFilename )
|
||||
{
|
||||
#ifndef USE_VFS
|
||||
return SetFileAttributes( (LPCSTR) strFilename, FILE_ATTRIBUTE_NORMAL );
|
||||
#else
|
||||
return TRUE;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
//returns true if at end of file, else false
|
||||
BOOLEAN FileCheckEndOfFile( HWFILE hFile )
|
||||
{
|
||||
#ifdef USE_VFS
|
||||
UINT32 uiCurrentLocation, uiMaxLocation;
|
||||
vfs::IBaseFile *pFile = (vfs::IBaseFile*)hFile;
|
||||
if(pFile)
|
||||
{
|
||||
if(pFile->IsWriteable())
|
||||
{
|
||||
vfs::tWriteableFile *pWF = vfs::tWriteableFile::Cast(pFile);
|
||||
if(pWF)
|
||||
{
|
||||
uiCurrentLocation = pWF->GetWriteLocation();
|
||||
uiMaxLocation = pWF->GetFileSize();
|
||||
return uiCurrentLocation < uiMaxLocation;
|
||||
}
|
||||
}
|
||||
else if(pFile->IsReadable())
|
||||
{
|
||||
vfs::tReadableFile *pRF = vfs::tReadableFile::Cast(pFile);
|
||||
if(pRF)
|
||||
{
|
||||
uiCurrentLocation = pRF->GetReadLocation();
|
||||
uiMaxLocation = pRF->GetFileSize();
|
||||
return uiCurrentLocation < uiMaxLocation;
|
||||
}
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
#else
|
||||
INT16 sLibraryID;
|
||||
UINT32 uiFileNum;
|
||||
HANDLE hRealFile;
|
||||
@@ -1873,6 +2227,7 @@ BOOLEAN FileCheckEndOfFile( HWFILE hFile )
|
||||
|
||||
//we are not and the end of a file
|
||||
return( 0 );
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -1944,6 +2299,14 @@ INT32 CompareSGPFileTimes( SGP_FILETIME *pFirstFileTime, SGP_FILETIME *pSecondFi
|
||||
|
||||
UINT32 FileSize(STR strFilename)
|
||||
{
|
||||
#ifdef USE_VFS
|
||||
vfs::IBaseFile *pFile = GetVFS()->GetFile(vfs::Path(strFilename));
|
||||
if(pFile)
|
||||
{
|
||||
return pFile->GetFileSize();
|
||||
}
|
||||
return 0;
|
||||
#else
|
||||
HWFILE hFile;
|
||||
UINT32 uiSize;
|
||||
|
||||
@@ -1954,6 +2317,7 @@ UINT32 uiSize;
|
||||
FileClose(hFile);
|
||||
|
||||
return(uiSize);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
|
||||
#include "FileCat.h"
|
||||
|
||||
#include "Container.h"
|
||||
|
||||
//**************************************************************************
|
||||
//
|
||||
// Defines
|
||||
@@ -162,7 +164,7 @@ BOOLEAN FileCheckEndOfFile( HWFILE hFile );
|
||||
|
||||
BOOLEAN GetFileManFileTime( HWFILE hFile, SGP_FILETIME *pCreationTime, SGP_FILETIME *pLastAccessedTime, SGP_FILETIME *pLastWriteTime );
|
||||
|
||||
|
||||
INT32 GetFilesInDirectory( HCONTAINER hStack, CHAR *pcDir, HANDLE hFile, WIN32_FIND_DATA *pFind );
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -27,6 +27,8 @@
|
||||
#include "himage.h"
|
||||
#include "vobject.h"
|
||||
#include "vobject_blitters.h"
|
||||
|
||||
#include <sstream>
|
||||
#endif
|
||||
//*******************************************************
|
||||
//
|
||||
@@ -126,7 +128,12 @@ void SetFontForeground(UINT8 ubForeground)
|
||||
UINT32 uiRed, uiGreen, uiBlue;
|
||||
|
||||
if((FontDefault < 0) || (FontDefault > MAX_FONTS))
|
||||
return;
|
||||
{
|
||||
//return;
|
||||
std::wstringstream wss;
|
||||
wss << L"invalid font index ( " << FontDefault << L" )";
|
||||
THROWEXCEPTION(wss.str().c_str());
|
||||
}
|
||||
|
||||
FontForeground8=ubForeground;
|
||||
|
||||
@@ -186,7 +193,12 @@ void SetFontBackground(UINT8 ubBackground)
|
||||
UINT32 uiRed, uiGreen, uiBlue;
|
||||
|
||||
if((FontDefault < 0) || (FontDefault > MAX_FONTS))
|
||||
return;
|
||||
{
|
||||
//return;
|
||||
std::wstringstream wss;
|
||||
wss << L"invalid color background value ( " << ubBackground << L" )";
|
||||
THROWEXCEPTION(wss.str().c_str());
|
||||
}
|
||||
|
||||
FontBackground8=ubBackground;
|
||||
|
||||
@@ -582,6 +594,34 @@ INT16 StringPixLength(const STR16 string, INT32 UseFont)
|
||||
return((INT16)Cur);
|
||||
}
|
||||
|
||||
//*****************************************************************************************
|
||||
//
|
||||
// SubstringPixLength
|
||||
//
|
||||
// Return the length of the of a substring of a string
|
||||
//
|
||||
// Returns INT16
|
||||
//
|
||||
// Created by: Owen Wigg
|
||||
// Created on: 26/04/2009
|
||||
//
|
||||
//*****************************************************************************************
|
||||
INT16 SubstringPixLength(STR16 string, UINT32 iStart, UINT32 iEnd, INT32 UseFont)
|
||||
{
|
||||
Assert (string != NULL);
|
||||
Assert(iStart >= 0 && iStart <= iEnd);
|
||||
Assert(iEnd < wcslen(string));
|
||||
|
||||
INT16 cnt = 0;
|
||||
|
||||
for (unsigned int i=iStart; i <= iEnd; i++)
|
||||
{
|
||||
cnt += GetWidth(FontObjs[UseFont], GetIndex(string[i]));
|
||||
}
|
||||
|
||||
return cnt;
|
||||
}
|
||||
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
@@ -899,9 +939,12 @@ CHAR16 GetUnicodeChar(CHAR16 siChar)
|
||||
//*****************************************************************************
|
||||
BOOLEAN SetFont(INT32 iFontIndex)
|
||||
{
|
||||
Assert(iFontIndex >= 0);
|
||||
Assert(iFontIndex <= MAX_FONTS);
|
||||
Assert(FontObjs[iFontIndex]!=NULL);
|
||||
//Assert(iFontIndex >= 0);
|
||||
//Assert(iFontIndex <= MAX_FONTS);
|
||||
//Assert(FontObjs[iFontIndex]!=NULL);
|
||||
THROWIFFALSE( iFontIndex >= 0 ,"negative font index");
|
||||
THROWIFFALSE( iFontIndex <= MAX_FONTS, "font index > MAX_FONTS" );
|
||||
THROWIFFALSE( FontObjs[iFontIndex]!=NULL, "font is not initialized" );
|
||||
#ifdef WINFONTS
|
||||
SET_WINFONT(WinFontMap[iFontIndex]);
|
||||
#endif
|
||||
@@ -1407,6 +1450,14 @@ UINT8 *pDestBuf;
|
||||
desty+=GetHeight(FontObjs[FontDefault], transletter);
|
||||
}
|
||||
|
||||
// we get a ctd if we try try to write outside of the screen
|
||||
if(desty + GetHeight(FontObjs[FontDefault], transletter) > SCREEN_HEIGHT)
|
||||
{
|
||||
// don't forget to unlock buffer
|
||||
UnLockVideoSurface( FontDestBuffer );
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Blit directly
|
||||
if ( gbPixelDepth == 8 )
|
||||
{
|
||||
|
||||
@@ -157,7 +157,7 @@ extern UINT32 GetWidth(HVOBJECT hSrcVObject, INT16 ssIndex);
|
||||
extern INT16 StringPixLengthArgFastHelp( INT32 usUseFont, INT32 usBoldFont, UINT32 uiCharCount, STR16 pFontString );
|
||||
extern INT16 StringPixLengthArg(INT32 usUseFont, UINT32 uiCharCount, STR16 pFontString, ...);
|
||||
extern INT16 StringPixLength(const STR16 string,INT32 UseFont);
|
||||
|
||||
extern INT16 SubstringPixLength(STR16 string, UINT32 iStart, UINT32 iEnd, INT32 UseFont);
|
||||
extern INT16 StringNPixLength(STR16 string, UINT32 uiMaxCount, INT32 UseFont);
|
||||
extern void SaveFontSettings(void);
|
||||
extern void RestoreFontSettings(void);
|
||||
|
||||
@@ -36,6 +36,9 @@
|
||||
#endif
|
||||
//#endif
|
||||
|
||||
#include "vfs.h"
|
||||
#include "PropertyContainer.h"
|
||||
|
||||
#ifdef _DEBUG
|
||||
//#define DEBUG_MEM_LEAKS // turns on tracking of every MemAlloc and MemFree!
|
||||
#endif
|
||||
@@ -211,6 +214,7 @@ void ShutdownMemoryManager( void )
|
||||
#ifndef EXTREME_MEMORY_DEBUGGING
|
||||
#ifdef JA2BETAVERSION
|
||||
{
|
||||
#ifndef USE_VFS
|
||||
FILE *fp;
|
||||
fp = fopen( "MemLeakInfo.txt", "a" );
|
||||
if( fp )
|
||||
@@ -226,6 +230,18 @@ void ShutdownMemoryManager( void )
|
||||
fprintf( fp, "\n\n" );
|
||||
}
|
||||
fclose( fp );
|
||||
#else
|
||||
CLog memLeak( L"MemLeakInfo.txt", true);
|
||||
memLeak.Endl().Endl();
|
||||
memLeak << ">>>>> MEMORY LEAK DETECTED!!! <<<<<" << CLog::endl;
|
||||
memLeak << " " << guiMemAlloced << " bytes memory total was allocated" << CLog::endl;
|
||||
memLeak << "- " << guiMemFreed << " bytes memory total was freed" << CLog::endl;
|
||||
memLeak << "_______________________________________________" << CLog::endl;
|
||||
memLeak << guiMemTotal << " bytes memory total STILL allocated" << CLog::endl;
|
||||
memLeak << MemDebugCounter << " memory blocks still allocated" << CLog::endl;
|
||||
memLeak << "guiScreenExitedFrom = " << gzJA2ScreenNames[ gMsgBox.uiExitScreen ] << CLog::endl;
|
||||
memLeak.Endl().Endl();
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,13 @@
|
||||
#ifndef _PNGLOADER_H_
|
||||
#define _PNGLOADER_H_
|
||||
|
||||
#include "types.h"
|
||||
#include "himage.h"
|
||||
|
||||
bool LoadPNGFileToImage(HIMAGE hImage, UINT16 fContents);
|
||||
|
||||
bool LoadJPCFileToImage(HIMAGE hImage, UINT16 fContents);
|
||||
|
||||
|
||||
#endif // _PNGLOADER_H_
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="8.00"
|
||||
Version="8,00"
|
||||
Name="SGP_2005Express"
|
||||
ProjectGUID="{6283CE93-2960-4596-8E74-7A6FBA8716FF}"
|
||||
RootNamespace="SGP_2005Express"
|
||||
@@ -41,7 +41,7 @@
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalOptions="/D "_CRT_SECURE_NO_DEPRECATE""
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="..\Multiplayer"
|
||||
AdditionalIncludeDirectories="..\Multiplayer;..\ext\libpng;..\ext\utf8\source;..\VFS"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_LIB;NO_ZLIB_COMPRESSION"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
@@ -105,7 +105,7 @@
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalOptions="/D "_CRT_SECURE_NO_DEPRECATE""
|
||||
AdditionalIncludeDirectories="..\Multiplayer"
|
||||
AdditionalIncludeDirectories="..\Multiplayer;..\ext\libpng;..\ext\utf8\source;..\VFS"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;NO_ZLIB_COMPRESSION"
|
||||
RuntimeLibrary="0"
|
||||
RuntimeTypeInfo="false"
|
||||
@@ -166,7 +166,7 @@
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalOptions="/D "_CRT_SECURE_NO_DEPRECATE""
|
||||
AdditionalIncludeDirectories="..\Multiplayer"
|
||||
AdditionalIncludeDirectories="..\Multiplayer;..\ext\libpng;..\ext\utf8\source;..\VFS"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;NO_ZLIB_COMPRESSION"
|
||||
RuntimeLibrary="0"
|
||||
RuntimeTypeInfo="false"
|
||||
@@ -228,7 +228,7 @@
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalOptions="/D "_CRT_SECURE_NO_DEPRECATE""
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="..\Multiplayer"
|
||||
AdditionalIncludeDirectories="..\Multiplayer;..\ext\libpng;..\ext\utf8\source;..\VFS"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_LIB;NO_ZLIB_COMPRESSION"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
@@ -424,6 +424,10 @@
|
||||
RelativePath=".\pcx.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\PngLoader.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\RAD.H"
|
||||
>
|
||||
@@ -642,6 +646,10 @@
|
||||
RelativePath=".\PCX.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\PngLoader.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Random.cpp"
|
||||
>
|
||||
|
||||
@@ -423,6 +423,10 @@
|
||||
RelativePath="pcx.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\PngLoader.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="RAD.H"
|
||||
>
|
||||
@@ -639,6 +643,10 @@
|
||||
RelativePath="PCX.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\PngLoader.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="Random.cpp"
|
||||
>
|
||||
|
||||
@@ -14,11 +14,18 @@
|
||||
#include "impTGA.h"
|
||||
#include "pcx.h"
|
||||
#include "STCI.h"
|
||||
#include "PngLoader.h"
|
||||
#include "wcheck.h"
|
||||
#include "Compression.h"
|
||||
#include "vobject.h"
|
||||
#endif
|
||||
|
||||
#include "VFS/vfs.h"
|
||||
|
||||
const utf8string::str_t CONST_DOTJPC(L".jpc.7z");
|
||||
|
||||
|
||||
|
||||
// This is the color substituted to keep a 24bpp->16bpp color
|
||||
// from going transparent (0x0000) -- DB
|
||||
|
||||
@@ -79,19 +86,42 @@ HIMAGE CreateImage( SGPFILENAME ImageFile, UINT16 fContents )
|
||||
iFileLoader = PCX_FILE_READER;
|
||||
break;
|
||||
}
|
||||
|
||||
if ( _stricmp( Extension, "TGA" ) == 0 )
|
||||
else if ( _stricmp( Extension, "TGA" ) == 0 )
|
||||
{
|
||||
iFileLoader = TGA_FILE_READER;
|
||||
break;
|
||||
}
|
||||
|
||||
if ( _stricmp( Extension, "STI" ) == 0 )
|
||||
else if ( _stricmp( Extension, "STI" ) == 0 )
|
||||
{
|
||||
#ifdef USE_VFS
|
||||
// see if there is a .jpc file first and when that fails, try .sti
|
||||
utf8string str(ImageFile);
|
||||
utf8string::str_t const& findext = str.c_wcs();
|
||||
utf8string::size_t dot = findext.find_last_of(vfs::Const::DOT());
|
||||
utf8string fname = findext.substr(0,dot).append(CONST_DOTJPC);
|
||||
if(GetVFS()->FileExists(fname))
|
||||
{
|
||||
iFileLoader = JPC_FILE_READER;
|
||||
strncpy(ImageFile, fname.utf8().c_str(), fname.length());
|
||||
ImageFile[fname.length()] = 0;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
iFileLoader = STCI_FILE_READER;
|
||||
break;
|
||||
}
|
||||
|
||||
else if ( _stricmp( Extension, "PNG" ) == 0 )
|
||||
{
|
||||
iFileLoader = PNG_FILE_READER;
|
||||
break;
|
||||
}
|
||||
#ifdef USE_VFS
|
||||
else if ( StrCmp::Equal(Extension, L"jpc.7z") )
|
||||
{
|
||||
iFileLoader = JPC_FILE_READER;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
} while ( FALSE );
|
||||
|
||||
// Determine if resource exists before creating image structure
|
||||
@@ -104,6 +134,7 @@ HIMAGE CreateImage( SGPFILENAME ImageFile, UINT16 fContents )
|
||||
#endif
|
||||
#endif
|
||||
DbgMessage( TOPIC_HIMAGE, DBG_LEVEL_2, String("Resource file %s does not exist.", ImageFile) );
|
||||
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
@@ -221,6 +252,14 @@ BOOLEAN LoadImageData( HIMAGE hImage, UINT16 fContents )
|
||||
fReturnVal = LoadSTCIFileToImage( hImage, fContents );
|
||||
break;
|
||||
|
||||
case PNG_FILE_READER:
|
||||
fReturnVal = LoadPNGFileToImage( hImage, fContents );
|
||||
break;
|
||||
|
||||
case JPC_FILE_READER:
|
||||
fReturnVal = LoadJPCFileToImage( hImage, fContents );
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
DbgMessage( TOPIC_HIMAGE, DBG_LEVEL_2, "Unknown image loader was specified." );
|
||||
@@ -905,6 +944,10 @@ BOOLEAN GetETRLEImageData( HIMAGE hImage, ETRLEData *pBuffer )
|
||||
|
||||
// Create buffer for objects
|
||||
pBuffer->pETRLEObject = (ETRLEObject *) MemAlloc( sizeof( ETRLEObject ) * pBuffer->usNumberOfObjects );
|
||||
if(!pBuffer->pETRLEObject)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
CHECKF( pBuffer->pETRLEObject != NULL );
|
||||
memset( pBuffer->pETRLEObject, 0, sizeof( ETRLEObject ) * pBuffer->usNumberOfObjects );
|
||||
|
||||
@@ -913,6 +956,10 @@ BOOLEAN GetETRLEImageData( HIMAGE hImage, ETRLEData *pBuffer )
|
||||
|
||||
// Allocate memory for pixel data
|
||||
pBuffer->pPixData = MemAlloc( hImage->uiSizePixData );
|
||||
if(!pBuffer->pPixData)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
CHECKF( pBuffer->pPixData != NULL );
|
||||
memset( pBuffer->pPixData, 0, hImage->uiSizePixData );
|
||||
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
#define TGA_FILE_READER 0x2
|
||||
#define STCI_FILE_READER 0x4
|
||||
#define TRLE_FILE_READER 0x8
|
||||
#define PNG_FILE_READER 0x10
|
||||
#define JPC_FILE_READER 0x20
|
||||
#define UNKNOWN_FILE_READER 0x200
|
||||
|
||||
// Defines for buffer bit depth
|
||||
@@ -93,41 +95,29 @@ typedef struct
|
||||
{
|
||||
UINT16 usWidth;
|
||||
UINT16 usHeight;
|
||||
UINT8 ubBitDepth;
|
||||
UINT8 ubBitDepth;
|
||||
UINT16 fFlags;
|
||||
SGPFILENAME ImageFile;
|
||||
SGPFILENAME ImageFile;
|
||||
UINT32 iFileLoader;
|
||||
SGPPaletteEntry *pPalette;
|
||||
UINT16 *pui16BPPPalette;
|
||||
UINT8 * pAppData;
|
||||
SGPPaletteEntry* pPalette;
|
||||
UINT16* pui16BPPPalette;
|
||||
UINT8* pAppData;
|
||||
UINT32 uiAppDataSize;
|
||||
// This union is used to describe each data type and is flexible to include the
|
||||
// data strucutre of the compresssed format, once developed.
|
||||
union
|
||||
{
|
||||
//struct
|
||||
//{
|
||||
PTR pImageData;
|
||||
//};
|
||||
//struct
|
||||
//{
|
||||
PTR pCompressedImageData;
|
||||
//};
|
||||
//struct
|
||||
//{
|
||||
UINT8 *p8BPPData;
|
||||
//};
|
||||
//struct
|
||||
//{
|
||||
|
||||
UINT16 *p16BPPData;
|
||||
//};
|
||||
PTR pImageData;
|
||||
PTR pCompressedImageData;
|
||||
UINT8* p8BPPData;
|
||||
UINT16* p16BPPData;
|
||||
UINT32* p32BPPData;
|
||||
struct
|
||||
{
|
||||
UINT8 * pPixData8;
|
||||
UINT32 uiSizePixData;
|
||||
ETRLEObject * pETRLEObject;
|
||||
UINT16 usNumberOfObjects;
|
||||
UINT8* pPixData8;
|
||||
UINT32 uiSizePixData;
|
||||
ETRLEObject* pETRLEObject;
|
||||
UINT16 usNumberOfObjects;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -1080,7 +1080,7 @@ void MSYS_DisableRegion(MOUSE_REGION *region)
|
||||
//
|
||||
void MSYS_SetCurrentCursor(UINT16 Cursor)
|
||||
{
|
||||
SetCurrentCursorFromDatabase( Cursor );
|
||||
TRYCATCH_RETHROW(SetCurrentCursorFromDatabase( Cursor ), "Could not set Cursor");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -37,6 +37,13 @@
|
||||
#include "input.h"
|
||||
#include "zmouse.h"
|
||||
|
||||
#include "VFS/vfs.h"
|
||||
#include "VFS/vfs_init.h"
|
||||
#include "VFS/File/vfs_file.h"
|
||||
#include "VFS/Location/vfs_slf_library.h"
|
||||
#include "Text.h"
|
||||
|
||||
#define USE_CONSOLE 0
|
||||
|
||||
#include <iostream>
|
||||
|
||||
@@ -46,6 +53,7 @@
|
||||
#include "INIReader.h"
|
||||
#include "Console.h"
|
||||
#include "Lua Interpreter.h"
|
||||
#include "connect.h"
|
||||
|
||||
#ifdef JA2
|
||||
#include "BuildDefines.h"
|
||||
@@ -57,6 +65,24 @@
|
||||
#endif
|
||||
|
||||
|
||||
static void MAGIC(std::string const& aarrrrgggh = "")
|
||||
{}
|
||||
|
||||
static bool s_VfsIsInitialized = false;
|
||||
static std::list<vfs::Path> vfs_config_ini;
|
||||
|
||||
|
||||
void SHOWEXCEPTION(CBasicException& ex)
|
||||
{
|
||||
try {
|
||||
_ExceptionMessage(ex);
|
||||
}
|
||||
catch(CBasicException &ex2) {
|
||||
LogException(ex2);
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
extern UINT32 MemDebugCounter;
|
||||
#ifdef JA2
|
||||
extern BOOLEAN gfPauseDueToPlayerGamePause;
|
||||
@@ -76,7 +102,9 @@ void GetRuntimeSettings( );
|
||||
|
||||
int PASCAL HandledWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR pCommandLine, int sCommandShow);
|
||||
|
||||
#if USE_CONSOLE
|
||||
Console g_Console("", "", "Lua Console", "no");
|
||||
#endif
|
||||
|
||||
#if !defined(JA2) && !defined(UTILS)
|
||||
void ProcessCommandLine(CHAR8 *pCommandLine);
|
||||
@@ -485,12 +513,20 @@ INT32 FAR PASCAL WindowProcedure(HWND hWindow, UINT16 Message, WPARAM wParam, LP
|
||||
break;
|
||||
|
||||
case WM_CHAR:
|
||||
if (wParam == '\\' &&
|
||||
lParam && KF_ALTDOWN)
|
||||
{
|
||||
g_Console.Create(ghWindow);
|
||||
cout << "LUA console ready" << endl;
|
||||
cout << "> ";
|
||||
// WANNE: We disable this for now in multiplayer, because user could enter "\" for the file transfer path
|
||||
if (!is_networked)
|
||||
{
|
||||
if (wParam == '\\' &&
|
||||
lParam && KF_ALTDOWN)
|
||||
{
|
||||
#if USE_CONSOLE
|
||||
g_Console.Create(ghWindow);
|
||||
cout << "LUA console ready" << endl;
|
||||
cout << "> ";
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -515,8 +551,6 @@ INT32 FAR PASCAL WindowProcedure(HWND hWindow, UINT16 Message, WPARAM wParam, LP
|
||||
return 0L;
|
||||
}
|
||||
|
||||
|
||||
|
||||
BOOLEAN InitializeStandardGamingPlatform(HINSTANCE hInstance, int sCommandShow)
|
||||
{
|
||||
FontTranslationTable *pFontTable;
|
||||
@@ -533,7 +567,31 @@ BOOLEAN InitializeStandardGamingPlatform(HINSTANCE hInstance, int sCommandShow)
|
||||
#endif
|
||||
|
||||
// Second, read in settings
|
||||
GetRuntimeSettings( );
|
||||
std::list<CBasicException> exlist;
|
||||
try
|
||||
{
|
||||
GetRuntimeSettings( );
|
||||
}
|
||||
catch(CBasicException& ex)
|
||||
{
|
||||
// nothing is set up, no vfs, no video manager
|
||||
// regular error processing wouldn't work here
|
||||
// set default values and continue as if nothing has happened
|
||||
iResolution = 1;
|
||||
|
||||
gbPixelDepth = PIXEL_DEPTH;
|
||||
|
||||
SCREEN_WIDTH = 800;
|
||||
SCREEN_HEIGHT = 600;
|
||||
|
||||
iScreenWidthOffset = (SCREEN_WIDTH - 640) / 2;
|
||||
iScreenHeightOffset = (SCREEN_HEIGHT - 480) / 2;
|
||||
|
||||
iScreenMode = 1;
|
||||
iPlayIntro = 0;
|
||||
// rethrow exception after full setup
|
||||
exlist.push_back(ex);
|
||||
}
|
||||
|
||||
// Initialize the Debug Manager - success doesn't matter
|
||||
InitializeDebugManager();
|
||||
@@ -603,12 +661,37 @@ BOOLEAN InitializeStandardGamingPlatform(HINSTANCE hInstance, int sCommandShow)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
InitializeJA2Clock();
|
||||
//InitializeJA2TimerID();
|
||||
|
||||
#ifdef USE_VFS
|
||||
STRING512 sExecutableDir;
|
||||
GetExecutableDirectory( sExecutableDir );
|
||||
|
||||
//vfs::Path fullpath = vfs::Path(sExecutableDir) + vfs::Path("vfs_config.ini");
|
||||
|
||||
// set current directory to exe's directory
|
||||
SetCurrentDirectory(sExecutableDir);
|
||||
|
||||
//if(!InitVirtualFileSystem( fullpath ))
|
||||
//{
|
||||
// FastDebugMsg("FAILED : Initializing Virtual File System");
|
||||
// return FALSE;
|
||||
//}
|
||||
//THROWIFFALSE( InitVirtualFileSystem( fullpath ), L"Initializing Virtual File System failed");
|
||||
THROWIFFALSE( InitVirtualFileSystem( vfs_config_ini ), L"Initializing Virtual File System failed");
|
||||
|
||||
s_VfsIsInitialized = true;
|
||||
|
||||
GetVFS()->GetVirtualLocation(vfs::Path("Temp"),true)->SetIsExclusive(true);
|
||||
GetVFS()->GetVirtualLocation(vfs::Path("ShadeTables"),true)->SetIsExclusive(true);
|
||||
GetVFS()->GetVirtualLocation(vfs::Path(pMessageStrings[MSG_SAVEDIRECTORY]+3),true)->SetIsExclusive(true);
|
||||
GetVFS()->GetVirtualLocation(vfs::Path(pMessageStrings[MSG_MPSAVEDIRECTORY]+3),true)->SetIsExclusive(true);
|
||||
#else
|
||||
// Snap: moved the following from InitJA2SplashScreen for clarity
|
||||
STRING512 CurrentDir;
|
||||
STRING512 DataDir;
|
||||
|
||||
InitializeJA2Clock();
|
||||
//InitializeJA2TimerID();
|
||||
// Get Executable Directory
|
||||
GetExecutableDirectory( CurrentDir );
|
||||
|
||||
@@ -633,7 +716,7 @@ BOOLEAN InitializeStandardGamingPlatform(HINSTANCE hInstance, int sCommandShow)
|
||||
if ( GetPrivateProfileString( "Ja2 Settings","CUSTOM_DATA_LOCATION", "", customDataPath, MAX_PATH, "..\\Ja2.ini" ) ) {
|
||||
gCustomDataCat.NewCat(std::string(CurrentDir) + '\\' + customDataPath);
|
||||
}
|
||||
|
||||
#endif
|
||||
//#ifdef JA2
|
||||
InitJA2SplashScreen();
|
||||
//#endif
|
||||
@@ -686,7 +769,11 @@ BOOLEAN InitializeStandardGamingPlatform(HINSTANCE hInstance, int sCommandShow)
|
||||
guiMouseWheelMsg = RegisterWindowMessage( MSH_MOUSEWHEEL );
|
||||
|
||||
gfGameInitialized = TRUE;
|
||||
|
||||
|
||||
if(!exlist.empty())
|
||||
{
|
||||
RETHROWEXCEPTION(L"Error during reading runtime settings", &exlist.front());
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -762,6 +849,10 @@ void ShutdownStandardGamingPlatform(void)
|
||||
UnRegisterDebugTopic(TOPIC_SGP, "Standard Gaming Platform");
|
||||
|
||||
ShutdownDebugManager();
|
||||
|
||||
CLog::FlushFinally();
|
||||
vfs::CVirtualFileSystem::ShutdownVFS();
|
||||
CFileAllocator::Clear();
|
||||
}
|
||||
|
||||
|
||||
@@ -870,10 +961,78 @@ int PASCAL HandledWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR pC
|
||||
|
||||
// ShowCursor(FALSE);
|
||||
|
||||
// Inititialize the SGP
|
||||
if (InitializeStandardGamingPlatform(hInstance, sCommandShow) == FALSE)
|
||||
{ // We failed to initialize the SGP
|
||||
return 0;
|
||||
#ifdef USE_VFS
|
||||
STRING512 sExecutableDir;
|
||||
GetExecutableDirectory( sExecutableDir );
|
||||
SetCurrentDirectory(sExecutableDir);
|
||||
#endif
|
||||
try
|
||||
{
|
||||
// Inititialize the SGP
|
||||
if (InitializeStandardGamingPlatform(hInstance, sCommandShow) == FALSE)
|
||||
{
|
||||
// We failed to initialize the SGP
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
catch(CBasicException &ex)
|
||||
{
|
||||
if(!s_VfsIsInitialized)
|
||||
{
|
||||
vfs::CFile* fonts = new vfs::CFile("Data/Fonts.slf");
|
||||
vfs::CSLFLibrary* slfLib = new vfs::CSLFLibrary(vfs::tReadableFile::Cast(fonts),"");
|
||||
if(slfLib->Init())
|
||||
{
|
||||
GetVFS()->AddLocation(slfLib,"doesn't matter");
|
||||
}
|
||||
// fonts not initialized
|
||||
FontTranslationTable *pFontTable = CreateEnglishTransTable( );
|
||||
if ( pFontTable == NULL )
|
||||
{
|
||||
return( FALSE );
|
||||
}
|
||||
|
||||
// Initialize Font Manager
|
||||
FastDebugMsg("Initializing the Font Manager");
|
||||
// Init the manager and copy the TransTable stuff into it.
|
||||
if ( !InitializeFontManager( 8, pFontTable ) )
|
||||
{
|
||||
FastDebugMsg("FAILED : Initializing Font Manager");
|
||||
return FALSE;
|
||||
}
|
||||
// Don't need this thing anymore, so get rid of it (but don't de-alloc the contents)
|
||||
MemFree( pFontTable );
|
||||
if ( !InitializeFonts( ) )
|
||||
{
|
||||
// Send debug message and quit
|
||||
DebugMsg( TOPIC_JA2, DBG_LEVEL_3, "COULD NOT INUT FONT SYSTEM...");
|
||||
return( ERROR_SCREEN );
|
||||
}
|
||||
}
|
||||
gfProgramIsRunning = 1;
|
||||
LogException(ex);
|
||||
SHOWEXCEPTION(ex);
|
||||
}
|
||||
catch(std::exception &ex)
|
||||
{
|
||||
gfProgramIsRunning = 1;
|
||||
CBasicException nex(ex.what(),_FUNCTION_FORMAT_,__LINE__,__FILE__);
|
||||
LogException(nex);
|
||||
SHOWEXCEPTION(nex);
|
||||
}
|
||||
catch(const char* msg)
|
||||
{
|
||||
gfProgramIsRunning = 1;
|
||||
CBasicException ex(msg,_FUNCTION_FORMAT_,__LINE__,__FILE__);
|
||||
LogException(ex);
|
||||
SHOWEXCEPTION(ex);
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
gfProgramIsRunning = 1;
|
||||
CBasicException ex("Caught undefined exception", _FUNCTION_FORMAT_, __LINE__, __FILE__);
|
||||
LogException( ex );
|
||||
SHOWEXCEPTION(ex);
|
||||
}
|
||||
|
||||
#ifdef LUACONSOLE
|
||||
@@ -901,18 +1060,45 @@ int PASCAL HandledWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR pC
|
||||
// attend to the gaming mechanics themselves
|
||||
Message.wParam = 0;
|
||||
|
||||
while (gfProgramIsRunning)
|
||||
try
|
||||
{
|
||||
// if (PeekMessage(&Message, NULL, 0, 0, PM_NOREMOVE))
|
||||
// { // We have a message on the WIN95 queue, let's get it
|
||||
if (!GetMessage(&Message, NULL, 0, 0))
|
||||
{ // It's quitting time
|
||||
return Message.wParam;
|
||||
MAGIC();
|
||||
while (gfProgramIsRunning)
|
||||
{
|
||||
if (!GetMessage(&Message, NULL, 0, 0))
|
||||
{
|
||||
// It's quitting time
|
||||
return Message.wParam;
|
||||
}
|
||||
// Ok, now that we have the message, let's handle it
|
||||
TranslateMessage(&Message);
|
||||
DispatchMessage(&Message);
|
||||
}
|
||||
// Ok, now that we have the message, let's handle it
|
||||
TranslateMessage(&Message);
|
||||
DispatchMessage(&Message);
|
||||
}
|
||||
catch(CBasicException &ex)
|
||||
{
|
||||
LogException(ex);
|
||||
SHOWEXCEPTION(ex);
|
||||
}
|
||||
catch(std::exception &ex)
|
||||
{
|
||||
CBasicException nex(ex.what(),_FUNCTION_FORMAT_,__LINE__,__FILE__);
|
||||
LogException(nex);
|
||||
SHOWEXCEPTION(nex);
|
||||
}
|
||||
catch(const char* msg)
|
||||
{
|
||||
CBasicException ex(msg,_FUNCTION_FORMAT_,__LINE__,__FILE__);
|
||||
LogException(ex);
|
||||
SHOWEXCEPTION(ex);
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
CBasicException ex("Caught undefined exception", _FUNCTION_FORMAT_, __LINE__, __FILE__);
|
||||
LogException( ex );
|
||||
SHOWEXCEPTION(ex);
|
||||
}
|
||||
|
||||
#if 0
|
||||
else
|
||||
{ // Windows hasn't processed any messages, therefore we handle the rest
|
||||
@@ -992,6 +1178,7 @@ void SGPExit(void)
|
||||
|
||||
void GetRuntimeSettings( )
|
||||
{
|
||||
#ifndef USE_VFS
|
||||
// Runtime settings - for now use INI file - later use registry
|
||||
STRING512 INIFile; // Path to the ini file
|
||||
CHAR8 zScreenResolution[ 50 ];
|
||||
@@ -1000,19 +1187,43 @@ void GetRuntimeSettings( )
|
||||
GetExecutableDirectory( INIFile );
|
||||
|
||||
strcat(INIFile, "\\Ja2.ini");
|
||||
|
||||
#else
|
||||
CPropertyContainer oProps;
|
||||
oProps.InitFromIniFile("Ja2.ini");
|
||||
#endif
|
||||
iResolution = -1;
|
||||
|
||||
#ifndef USE_VFS
|
||||
if (GetPrivateProfileString( "Ja2 Settings","SCREEN_RESOLUTION", "", zScreenResolution, 50, INIFile ))
|
||||
{
|
||||
iResolution = atoi(zScreenResolution);
|
||||
}
|
||||
#else
|
||||
iResolution = oProps.GetIntProperty(L"Ja2 Settings", L"SCREEN_RESOLUTION", -1);
|
||||
|
||||
std::list<utf8string> ini_list;
|
||||
if(oProps.GetStringListProperty(L"Ja2 Settings", L"VFS_CONFIG_INI", ini_list, L""))
|
||||
{
|
||||
vfs_config_ini.clear();
|
||||
for(std::list<utf8string>::iterator it = ini_list.begin(); it != ini_list.end(); ++it)
|
||||
{
|
||||
vfs_config_ini.push_back(*it);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
vfs_config_ini.push_back(L"vfs_config.ini");
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef JA2EDITOR
|
||||
#ifndef USE_VFS
|
||||
if (GetPrivateProfileString( "Ja2 Settings","EDITOR_SCREEN_RESOLUTION", "", zScreenResolution, 50, INIFile ))
|
||||
{
|
||||
iResolution = atoi(zScreenResolution);
|
||||
}
|
||||
#else
|
||||
iResolution = oProps.GetIntProperty("Ja2 Settings","EDITOR_SCREEN_RESOLUTION", -1);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1038,7 +1249,7 @@ void GetRuntimeSettings( )
|
||||
iResY = 600;
|
||||
break;
|
||||
}
|
||||
|
||||
#ifndef USE_VFS
|
||||
gbPixelDepth = GetPrivateProfileInt( "SGP", "PIXEL_DEPTH", PIXEL_DEPTH, INIFile );
|
||||
|
||||
SCREEN_WIDTH = GetPrivateProfileInt( "SGP", "WIDTH", iResX, INIFile );
|
||||
@@ -1054,6 +1265,25 @@ void GetRuntimeSettings( )
|
||||
|
||||
// WANNE: Should we play the intro?
|
||||
iPlayIntro = (int) GetPrivateProfileInt( "Ja2 Settings","PLAY_INTRO", iPlayIntro, INIFile );
|
||||
#else
|
||||
gbPixelDepth = (UINT8)oProps.GetIntProperty(L"SGP", L"PIXEL_DEPTH", PIXEL_DEPTH);
|
||||
|
||||
SCREEN_WIDTH = (UINT16)oProps.GetIntProperty(L"SGP", L"WIDTH", iResX);
|
||||
SCREEN_HEIGHT = (UINT16)oProps.GetIntProperty(L"SGP", L"HEIGHT", iResY);
|
||||
|
||||
iScreenWidthOffset = (SCREEN_WIDTH - 640) / 2;
|
||||
iScreenHeightOffset = (SCREEN_HEIGHT - 480) / 2;
|
||||
|
||||
/* Sergeant_Kolja. 2007-02-20: runtime Windowed mode instead of compile-time */
|
||||
/* 1 for Windowed, 0 for Fullscreen */
|
||||
if( !bScreenModeCmdLine )
|
||||
{
|
||||
iScreenMode = oProps.GetIntProperty("Ja2 Settings","SCREEN_MODE_WINDOWED", iScreenMode);
|
||||
}
|
||||
|
||||
// WANNE: Should we play the intro?
|
||||
iPlayIntro = oProps.GetIntProperty("Ja2 Settings","PLAY_INTRO", iPlayIntro);
|
||||
#endif
|
||||
}
|
||||
|
||||
void ShutdownWithErrorBox(CHAR8 *pcMessage)
|
||||
|
||||
@@ -1801,10 +1801,14 @@ UINT32 uiCount;
|
||||
return(FALSE);
|
||||
}
|
||||
|
||||
#include "vfs.h"
|
||||
#include "PropertyContainer.h"
|
||||
|
||||
// Lesh modifications
|
||||
// Sound debug
|
||||
|
||||
#ifdef USE_VFS
|
||||
static CLog& s_SoundLog = *CLog::Create(SndDebugFileName,true);
|
||||
#endif
|
||||
//*****************************************************************************************
|
||||
// SoundLog
|
||||
// Writes string into log file
|
||||
@@ -1815,11 +1819,15 @@ UINT32 uiCount;
|
||||
//*****************************************************************************************
|
||||
void SoundLog(CHAR8 *strMessage)
|
||||
{
|
||||
#ifndef USE_VFS
|
||||
if ((SndDebug = fopen(SndDebugFileName, "a+t")) != NULL)
|
||||
{
|
||||
fprintf(SndDebug, "%s\n", strMessage);
|
||||
fclose(SndDebug);
|
||||
}
|
||||
#else
|
||||
s_SoundLog << strMessage << CLog::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
//*****************************************************************************************
|
||||
@@ -1832,8 +1840,10 @@ void SoundLog(CHAR8 *strMessage)
|
||||
//*****************************************************************************************
|
||||
void InitLogging()
|
||||
{
|
||||
#ifndef USE_VFS
|
||||
if ((SndDebug = fopen(SndDebugFileName, "wt")) != NULL)
|
||||
{
|
||||
fclose(SndDebug);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -2916,7 +2916,11 @@ BOOLEAN EraseMouseCursor( )
|
||||
//
|
||||
|
||||
pTmpPointer = LockMouseBuffer(&uiPitch);
|
||||
memset(pTmpPointer, 0, MAX_CURSOR_HEIGHT * uiPitch);
|
||||
// when there is no mouse buffer the game can run into an infinite loop (some DirectX stuff)
|
||||
if(pTmpPointer)
|
||||
{
|
||||
memset(pTmpPointer, 0, MAX_CURSOR_HEIGHT * uiPitch);
|
||||
}
|
||||
UnlockMouseBuffer();
|
||||
|
||||
// Don't set dirty
|
||||
|
||||
@@ -455,6 +455,54 @@ HVOBJECT CreateVideoObject( VOBJECT_DESC *VObjectDesc )
|
||||
}
|
||||
}
|
||||
|
||||
if(hImage->ubBitDepth == 32)
|
||||
{
|
||||
hVObject->p16BPPObject = new SixteenBPPObjectInfo;
|
||||
int SIZE = hImage->usHeight*hImage->usWidth;
|
||||
hVObject->pPixData = new UINT32[SIZE];
|
||||
memcpy(hVObject->pPixData, hImage->p32BPPData, SIZE*sizeof(UINT32));
|
||||
hVObject->p16BPPObject->p16BPPData = NULL;
|
||||
hVObject->p16BPPObject->sOffsetX = 0;
|
||||
hVObject->p16BPPObject->sOffsetY = 0;
|
||||
hVObject->p16BPPObject->ubShadeLevel = 0;
|
||||
hVObject->p16BPPObject->usHeight = hImage->usHeight;
|
||||
hVObject->p16BPPObject->usWidth = hImage->usWidth;
|
||||
hVObject->p16BPPObject->usRegionIndex = 0;
|
||||
|
||||
hVObject->usNumberOf16BPPObjects = 1;
|
||||
hVObject->ubBitDepth = hImage->ubBitDepth;
|
||||
|
||||
if ( VObjectDesc->fCreateFlags & VOBJECT_CREATE_FROMFILE )
|
||||
{
|
||||
DestroyImage( hImage );
|
||||
}
|
||||
|
||||
return hVObject;
|
||||
}
|
||||
else if(hImage->ubBitDepth == 16)
|
||||
{
|
||||
hVObject->p16BPPObject = new SixteenBPPObjectInfo;
|
||||
int SIZE = hImage->usHeight*hImage->usWidth;
|
||||
hVObject->p16BPPObject->p16BPPData = new UINT16[SIZE];
|
||||
memcpy(hVObject->p16BPPObject->p16BPPData, hImage->p16BPPData, SIZE*sizeof(UINT16));
|
||||
hVObject->p16BPPObject->sOffsetX = 0;
|
||||
hVObject->p16BPPObject->sOffsetY = 0;
|
||||
hVObject->p16BPPObject->ubShadeLevel = 0;
|
||||
hVObject->p16BPPObject->usHeight = hImage->usHeight;
|
||||
hVObject->p16BPPObject->usWidth = hImage->usWidth;
|
||||
hVObject->p16BPPObject->usRegionIndex = 0;
|
||||
|
||||
hVObject->usNumberOf16BPPObjects = 1;
|
||||
hVObject->ubBitDepth = hImage->ubBitDepth;
|
||||
|
||||
if ( VObjectDesc->fCreateFlags & VOBJECT_CREATE_FROMFILE )
|
||||
{
|
||||
DestroyImage( hImage );
|
||||
}
|
||||
|
||||
return hVObject;
|
||||
}
|
||||
|
||||
// Check if returned himage is TRLE compressed - return error if not
|
||||
if ( ! (hImage->fFlags & IMAGE_TRLECOMPRESSED ) )
|
||||
{
|
||||
@@ -723,23 +771,49 @@ BOOLEAN BltVideoObjectToBuffer( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, HVOBJE
|
||||
__try
|
||||
{
|
||||
// Assertions
|
||||
Assert( pBuffer != NULL );
|
||||
//Assert( pBuffer != NULL );
|
||||
THROWIFFALSE( pBuffer != NULL, L"No Destination Buffer" );
|
||||
|
||||
if ( hSrcVObject == NULL )
|
||||
{
|
||||
//int breakpoint=0;
|
||||
}
|
||||
|
||||
Assert( hSrcVObject != NULL );
|
||||
//Assert( hSrcVObject != NULL );
|
||||
THROWIFFALSE( hSrcVObject != NULL, L"No Source Object" )
|
||||
|
||||
SixteenBPPObjectInfo *image = NULL;
|
||||
// Check For Flags and bit depths
|
||||
switch( hSrcVObject->ubBitDepth )
|
||||
{
|
||||
case 32:
|
||||
image = &hSrcVObject->p16BPPObject[usIndex];
|
||||
#if 0
|
||||
Blt16BPPTo16BPPTrans( pBuffer, uiDestPitchBYTES,
|
||||
image->p16BPPData, image->usWidth * sizeof(UINT16),
|
||||
iDestX, iDestY,
|
||||
0, 0, image->usWidth, image->usHeight,
|
||||
0 );
|
||||
#else
|
||||
Blt32BPPTo16BPPTrans( pBuffer, uiDestPitchBYTES,
|
||||
(UINT32*)hSrcVObject->pPixData, image->usWidth * sizeof(UINT32),
|
||||
iDestX, iDestY,
|
||||
0, 0, image->usWidth, image->usHeight);
|
||||
#endif
|
||||
break;
|
||||
|
||||
case 16:
|
||||
image = &hSrcVObject->p16BPPObject[usIndex];
|
||||
Blt16BPPTo16BPP( pBuffer, uiDestPitchBYTES,
|
||||
image->p16BPPData, image->usWidth * sizeof(UINT16),
|
||||
iDestX, iDestY,
|
||||
0, 0, image->usWidth, image->usHeight );
|
||||
|
||||
break;
|
||||
|
||||
case 8:
|
||||
|
||||
THROWIFFALSE( hSrcVObject->usNumberOfObjects > usIndex, L"Video object index is larger than the number of subimages");
|
||||
// Switch based on flags given
|
||||
do
|
||||
{
|
||||
|
||||
@@ -22,6 +22,85 @@
|
||||
#endif
|
||||
|
||||
|
||||
static UINT8 g_AlphaTimesValueCache[256][256];
|
||||
|
||||
class InitAlphaTimesValueCache
|
||||
{
|
||||
public:
|
||||
InitAlphaTimesValueCache()
|
||||
{
|
||||
for(unsigned int alpha = 0; alpha < 256; alpha++)
|
||||
{
|
||||
for(unsigned int val = 0; val < 256; val++)
|
||||
{
|
||||
// it can't get any simpler than that
|
||||
g_AlphaTimesValueCache[alpha][val] = (UINT8)( ((double)alpha/255.0) * val );
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static InitAlphaTimesValueCache s_InitAlphaCache;
|
||||
|
||||
BOOLEAN Blt32BPPTo16BPPTrans(UINT16 *pDest, UINT32 uiDestPitch, UINT32 *pSrc, UINT32 uiSrcPitch, INT32 iDestXPos, INT32 iDestYPos, INT32 iSrcXPos, INT32 iSrcYPos, UINT32 uiWidth, UINT32 uiHeight)
|
||||
{
|
||||
UINT32 *pSrcPtr;
|
||||
UINT16 *pDestPtr;
|
||||
UINT32 uiLineSkipDest, uiLineSkipSrc;
|
||||
|
||||
Assert(pDest!=NULL);
|
||||
Assert(pSrc!=NULL);
|
||||
|
||||
pSrcPtr = (UINT32 *)((UINT8 *)pSrc+(iSrcYPos*uiSrcPitch)+(iSrcXPos*4));
|
||||
uiLineSkipSrc = uiSrcPitch-(uiWidth*4);
|
||||
|
||||
pDestPtr = (UINT16 *)((UINT8 *)pDest+(iDestYPos*uiDestPitch)+(iDestXPos*2));
|
||||
uiLineSkipDest = uiDestPitch-(uiWidth*2);
|
||||
|
||||
UINT8 alpha, dst_channel, src_channel;
|
||||
UINT8 red, green, blue;
|
||||
do
|
||||
{
|
||||
UINT32 w = uiWidth;
|
||||
do
|
||||
{
|
||||
//alpha = (UINT8)((0xFF000000 & *pSrcPtr) >> 24);
|
||||
alpha = 255;
|
||||
// r
|
||||
dst_channel = (UINT8)((0x1F & *pDestPtr) << 3);
|
||||
src_channel = (UINT8)((0xFF & *pSrcPtr) );
|
||||
//red = (UINT8)( g_AlphaTimesValueCache[255-alpha][dst_channel] + g_AlphaTimesValueCache[alpha][src_channel] );
|
||||
red = (UINT8)( g_AlphaTimesValueCache[alpha][src_channel] );
|
||||
|
||||
// g
|
||||
dst_channel = (UINT8)((0x7E0 & *pDestPtr) >> 3);
|
||||
src_channel = (UINT8)((0xFF00 & *pSrcPtr) >> 8);
|
||||
//green = (UINT8)( g_AlphaTimesValueCache[255-alpha][dst_channel] + g_AlphaTimesValueCache[alpha][src_channel] );
|
||||
green = (UINT8)( g_AlphaTimesValueCache[alpha][src_channel] );
|
||||
|
||||
// b
|
||||
dst_channel = (UINT8)((0xF800 & *pDestPtr) >> 8);
|
||||
src_channel = (UINT8)((0xFF0000 & *pSrcPtr) >> 16);
|
||||
//blue = (UINT8)( g_AlphaTimesValueCache[255-alpha][dst_channel] + g_AlphaTimesValueCache[alpha][src_channel] );
|
||||
blue = (UINT8)( g_AlphaTimesValueCache[alpha][src_channel] );
|
||||
|
||||
|
||||
UINT32 newcolor = FROMRGB(red,green,blue);
|
||||
*pDestPtr = Get16BPPColor(newcolor);
|
||||
pSrcPtr++;
|
||||
pDestPtr++;
|
||||
}
|
||||
while (--w != 0);
|
||||
pSrcPtr = (UINT32*)((UINT8*)pSrcPtr + uiLineSkipSrc);
|
||||
pDestPtr = (UINT16*)((UINT8*)pDestPtr + uiLineSkipDest);
|
||||
}
|
||||
while (--uiHeight != 0);
|
||||
|
||||
return ( TRUE );
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Here are bliting functions. If you dont know what kind of functions they are so :
|
||||
* correct me if im wrong they copy array of bits from src image to dest image
|
||||
* maby we can get ride this includes above? we dont need theme here i thinks so
|
||||
@@ -6907,6 +6986,15 @@ UINT32 uiLineSkipDest, uiLineSkipSrc;
|
||||
Assert(pDest!=NULL);
|
||||
Assert(pSrc!=NULL);
|
||||
|
||||
if(iSrcXPos >= SCREEN_WIDTH)
|
||||
return false;
|
||||
if(iSrcYPos >= SCREEN_HEIGHT)
|
||||
return false;
|
||||
if(iSrcXPos + uiWidth > SCREEN_WIDTH)
|
||||
uiWidth = SCREEN_WIDTH - iSrcXPos;
|
||||
if(iSrcYPos + uiHeight > SCREEN_HEIGHT)
|
||||
uiHeight = SCREEN_HEIGHT - iSrcYPos;
|
||||
|
||||
pSrcPtr=(UINT16 *)((UINT8 *)pSrc+(iSrcYPos*uiSrcPitch)+(iSrcXPos*2));
|
||||
pDestPtr=(UINT16 *)((UINT8 *)pDest+(iDestYPos*uiDestPitch)+(iDestXPos*2));
|
||||
uiLineSkipDest=uiDestPitch-(uiWidth*2);
|
||||
@@ -6978,7 +7066,22 @@ UINT32 uiLineSkipDest, uiLineSkipSrc;
|
||||
pDestPtr=(UINT16 *)((UINT8 *)pDest+(iDestYPos*uiDestPitch)+(iDestXPos*2));
|
||||
uiLineSkipDest=uiDestPitch-(uiWidth*2);
|
||||
uiLineSkipSrc=uiSrcPitch-(uiWidth*2);
|
||||
|
||||
#if 1
|
||||
do
|
||||
{
|
||||
UINT32 w = uiWidth;
|
||||
do
|
||||
{
|
||||
if (*pSrcPtr != usTrans) *pDestPtr = *pSrcPtr;
|
||||
pSrcPtr++;
|
||||
pDestPtr++;
|
||||
}
|
||||
while (--w != 0);
|
||||
pSrcPtr = (UINT16*)((UINT8*)pSrcPtr + uiLineSkipSrc);
|
||||
pDestPtr = (UINT16*)((UINT8*)pDestPtr + uiLineSkipDest);
|
||||
}
|
||||
while (--uiHeight != 0);
|
||||
#else
|
||||
__asm {
|
||||
mov esi, pSrcPtr
|
||||
mov edi, pDestPtr
|
||||
@@ -7007,7 +7110,7 @@ Blit3:
|
||||
jnz BlitNewLine
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
return(TRUE);
|
||||
}
|
||||
|
||||
|
||||
@@ -162,6 +162,8 @@ BOOLEAN BlitZRect(UINT16 *pZBuffer, UINT32 uiPitch, INT16 sLeft, INT16 sTop, INT
|
||||
|
||||
// New 16/16 blitters
|
||||
|
||||
BOOLEAN Blt32BPPTo16BPPTrans(UINT16 *pDest, UINT32 uiDestPitch, UINT32 *pSrc, UINT32 uiSrcPitch, INT32 iDestXPos, INT32 iDestYPos, INT32 iSrcXPos, INT32 iSrcYPos, UINT32 uiWidth, UINT32 uiHeight);
|
||||
|
||||
BOOLEAN Blt16BPPDataTo16BPPBufferTransparentClip( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex, SGPRect *clipregion);
|
||||
BOOLEAN Blt16BPPDataTo16BPPBufferTransZClip( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, UINT16 *pZBuffer, UINT16 usZValue, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex, SGPRect *clipregion);
|
||||
BOOLEAN Blt16BPPDataTo16BPPBufferTransparent( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex );
|
||||
|
||||
Reference in New Issue
Block a user