From 3850e27bc504927a96eb55327e678558d13e6e82 Mon Sep 17 00:00:00 2001 From: Wanne Date: Sat, 6 Jun 2009 16:13:00 +0000 Subject: [PATCH] - Merged Source Code from MP branch Revision 2972 enable intro videos in VFS mode workaround for original intro hack allow to get real path of a file (only CVFSFile) streamline Allocator usage in VFile small non-VFS mode fixes in MPHostScreen.cpp Synced "Cutting Fences" in a multiplayer game git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@2973 3b4a5df2-a311-0410-b5c6-a8a6f20db521 --- Intro.cpp | 5 ++- Multiplayer/client.cpp | 23 ++++++++------ Tactical/Soldier Control.cpp | 12 +++++-- Utils/Cinematics.cpp | 51 +++++++++++++++++++++++++++++- Utils/Event Pump.h | 1 + VFS/File/vfs_dir_file.cpp | 11 +++++++ VFS/File/vfs_dir_file.h | 2 ++ VFS/Interface/vfs_file_interface.h | 4 +++ VFS/vfs_vfile.cpp | 19 ++++++----- VFS/vfs_vfile.h | 8 +++-- VFS/vfs_vloc.cpp | 8 ++--- 11 files changed, 115 insertions(+), 29 deletions(-) diff --git a/Intro.cpp b/Intro.cpp index f837c2af..46da910c 100644 --- a/Intro.cpp +++ b/Intro.cpp @@ -32,6 +32,8 @@ #include "MessageBoxScreen.h" #endif +#include "VFS/vfs.h" + extern STR16 gzIntroScreen[]; extern HVSURFACE ghFrameBuffer; @@ -198,13 +200,14 @@ BOOLEAN EnterIntroScreen() // return( TRUE ); // } //#endif - +#ifndef USE_VFS //if the library doesnt exist, exit if( !IsLibraryOpened( LIBRARY_INTRO ) ) { PrepareToExitIntroScreen(); return( TRUE ); } +#endif //initialize smacker SmkInitialize( ghWindow, SCREEN_WIDTH, SCREEN_HEIGHT); diff --git a/Multiplayer/client.cpp b/Multiplayer/client.cpp index 0e638013..39cfd55b 100644 --- a/Multiplayer/client.cpp +++ b/Multiplayer/client.cpp @@ -3023,30 +3023,33 @@ void send_changestate (EV_S_CHANGESTATE * SChangeState) void recieveSTATE(RPCParameters *rpcParameters) { - EV_S_CHANGESTATE* new_state = (EV_S_CHANGESTATE*)rpcParameters->input; - - //ScreenMsg( FONT_YELLOW, MSG_MPSYSTEM, L"recieved state"); - - SOLDIERTYPE * pSoldier=MercPtrs[ new_state->usSoldierID ]; if(pSoldier->bActive) { - if(new_state->usNewState==93) + // Start first AID + if(new_state->usNewState==START_AID) { pSoldier->EVENT_InternalSetSoldierPosition( new_state->sXPos, new_state->sYPos ,FALSE, FALSE, FALSE ); pSoldier->ChangeSoldierStance( ANIM_CROUCH ); pSoldier->EVENT_SetSoldierDirection( new_state->usNewDirection ); } - //if(new_state->usNewState==95)ScreenMsg( FONT_YELLOW, MSG_MPSYSTEM, L"All Bandaged."); + // Start cutting fence + else if (new_state->usNewState==CUTTING_FENCE) + { + // The usTargetGridNo holds the GridNo of the fence tile + pSoldier->sTargetGridNo = new_state->usTargetGridNo; + + pSoldier->EVENT_InternalSetSoldierPosition( new_state->sXPos, new_state->sYPos ,FALSE, FALSE, FALSE ); + pSoldier->ChangeSoldierStance( ANIM_CROUCH ); + pSoldier->EVENT_SetSoldierDirection( new_state->usNewDirection ); + } pSoldier->EVENT_InitNewSoldierAnim( new_state->usNewState, new_state->usStartingAniCode, new_state->fForce ); - } -//AddGameEvent( S_CHANGESTATE, 0, &SChangeState ); - //someday ;) + } } void send_death( SOLDIERTYPE *pSoldier ) diff --git a/Tactical/Soldier Control.cpp b/Tactical/Soldier Control.cpp index b86d09fc..22197c40 100644 --- a/Tactical/Soldier Control.cpp +++ b/Tactical/Soldier Control.cpp @@ -2522,6 +2522,7 @@ BOOLEAN SOLDIERTYPE::ChangeSoldierState( UINT16 usNewState, UINT16 usStartingAni SChangeState.sYPos = this->sY; SChangeState.fForce = fForce; SChangeState.usNewDirection = this->ubDirection; + SChangeState.usTargetGridNo = this->sTargetGridNo; //AddGameEvent( S_CHANGESTATE, 0, &SChangeState ); @@ -10694,8 +10695,10 @@ void SOLDIERTYPE::EVENT_SoldierBeginFirstAid( INT16 sGridNo, UINT8 ubDirection ) //else { // CHANGE TO ANIMATION - if(!is_networked)this->EVENT_InitNewSoldierAnim( START_AID, 0 , FALSE ); - else this->ChangeSoldierState( START_AID, 0, 0 ); + if(!is_networked) + this->EVENT_InitNewSoldierAnim( START_AID, 0 , FALSE ); + else + this->ChangeSoldierState( START_AID, 0, 0 ); } @@ -12350,7 +12353,10 @@ void SOLDIERTYPE::EVENT_SoldierBeginCutFence( INT16 sGridNo, UINT8 ubDirection ) this->sTargetGridNo = sGridNo; // CHANGE TO ANIMATION - this->EVENT_InitNewSoldierAnim( CUTTING_FENCE, 0 , FALSE ); + if (!is_networked) + this->EVENT_InitNewSoldierAnim( CUTTING_FENCE, 0 , FALSE ); + else + this->ChangeSoldierState( CUTTING_FENCE, 0, 0 ); } } diff --git a/Utils/Cinematics.cpp b/Utils/Cinematics.cpp index 6fcac4ce..b34bd54c 100644 --- a/Utils/Cinematics.cpp +++ b/Utils/Cinematics.cpp @@ -30,6 +30,8 @@ #include "DirectDraw Calls.h" #include "Cinematics.h" #include "soundman.h" +#include "VFS/vfs.h" +#include "VFS/vfs_file_raii.h" #ifdef JA2 #include "video.h" @@ -200,6 +202,7 @@ SMKFLIC *SmkOpenFlic(CHAR8 *cFilename) return(NULL); } +#ifndef USE_VFS // Attempt opening the filename if(!(pSmack->hFileHandle=FileOpen(cFilename, FILE_OPEN_EXISTING | FILE_ACCESS_READ, FALSE))) { @@ -209,6 +212,36 @@ SMKFLIC *SmkOpenFlic(CHAR8 *cFilename) //Get the real file handle for the file man handle for the smacker file hFile = GetRealFileHandleFromFileManFileHandle( pSmack->hFileHandle ); +#else + vfs::Path introname(cFilename); + vfs::Path dir,filename; + introname.SplitLast(dir,filename); + vfs::Path tempfile = vfs::Path(L"Temp") + filename; + if(!GetVFS()->FileExists(tempfile)) + { + try + { + if(!GetVFS()->FileExists(introname)) + { + return NULL; + } + vfs::COpenReadFile rfile(introname); + vfs::UInt32 size = rfile.file().GetFileSize(); + std::vector data(size); + vfs::UInt32 io; + rfile.file().Read(&data[0],size,io); + + vfs::COpenWriteFile wfile(tempfile,true); + wfile.file().Write(&data[0],size,io); + } + catch(CBasicException& ex) + { + std::wstringstream wss; + wss << L"Intro file \"" << filename() << L"\" could not be extracted"; + RETHROWEXCEPTION(wss.str().c_str(),&ex); + } + } +#endif // Allocate a Smacker buffer for video decompression if(!(pSmack->SmackBuffer=SmackBufferOpen(hDisplayWindow,SMACKAUTOBLIT,SCREEN_WIDTH,SCREEN_HEIGHT,0,0))) @@ -216,9 +249,25 @@ SMKFLIC *SmkOpenFlic(CHAR8 *cFilename) ErrorMsg("SMK ERROR: Can't allocate a Smacker decompression buffer"); return(NULL); } - +#ifndef USE_VFS if(!(pSmack->SmackHandle=SmackOpen((CHAR8 *)hFile, SMACKFILEHANDLE | SMACKTRACKS, SMACKAUTOEXTRA))) +#else // if(!(pSmack->SmackHandle=SmackOpen(cFilename, SMACKTRACKS, SMACKAUTOEXTRA))) + vfs::Path tempfilename; + try + { + vfs::COpenWriteFile wfile(tempfile); + if(!wfile.file()._getRealPath(tempfilename)) + { + return NULL; + } + } + catch(CBasicException& ex) + { + RETHROWEXCEPTION(L"Temporary intro file could not be read", &ex); + } + if(!(pSmack->SmackHandle=SmackOpen(tempfilename().utf8().c_str(), SMACKTRACKS, SMACKAUTOEXTRA))) +#endif { ErrorMsg("SMK ERROR: Smacker won't open the SMK file"); return(NULL); diff --git a/Utils/Event Pump.h b/Utils/Event Pump.h index 6ed356ce..24db3774 100644 --- a/Utils/Event Pump.h +++ b/Utils/Event Pump.h @@ -68,6 +68,7 @@ typedef struct UINT16 usStartingAniCode; BOOLEAN fForce; UINT8 usNewDirection;//hayden + UINT16 usTargetGridNo; // WANNE - MP: Used for manipulating the target grid no } EV_S_CHANGESTATE; diff --git a/VFS/File/vfs_dir_file.cpp b/VFS/File/vfs_dir_file.cpp index d7c813db..9caf43c6 100644 --- a/VFS/File/vfs_dir_file.cpp +++ b/VFS/File/vfs_dir_file.cpp @@ -14,6 +14,17 @@ vfs::Path vfs::CVFSFile::GetFullPath() } } +bool vfs::CVFSFile::_getRealPath(vfs::Path& rPath) +{ + if(_pLoc_) + { + rPath = static_cast*>(_pLoc_)->GetRealPath() + m_sFileName; + return true; + } + return false; +} + + bool vfs::CVFSFile::Delete() { Close(); diff --git a/VFS/File/vfs_dir_file.h b/VFS/File/vfs_dir_file.h index 8197f53a..bab88663 100644 --- a/VFS/File/vfs_dir_file.h +++ b/VFS/File/vfs_dir_file.h @@ -24,6 +24,8 @@ namespace vfs virtual bool OpenRead(); virtual bool OpenWrite(bool bCreateWhenNotExist = false, bool bTruncate = false); + + virtual bool _getRealPath(vfs::Path& rPath); }; class CVFSTextFile : public vfs::CTextFile, public vfs::ILocationAware diff --git a/VFS/Interface/vfs_file_interface.h b/VFS/Interface/vfs_file_interface.h index 3913aa6c..33a98f87 100644 --- a/VFS/Interface/vfs_file_interface.h +++ b/VFS/Interface/vfs_file_interface.h @@ -48,6 +48,10 @@ namespace vfs return 0; }; + virtual bool _getRealPath(vfs::Path& rPath) + { + return false; + } protected: vfs::Path m_sFileName; }; diff --git a/VFS/vfs_vfile.cpp b/VFS/vfs_vfile.cpp index 6db41e13..f29eeb6c 100644 --- a/VFS/vfs_vfile.cpp +++ b/VFS/vfs_vfile.cpp @@ -8,15 +8,15 @@ ObjBlockAllocator* vfs::CVirtualFile::_vfile_pool = NULL; vfs::CVirtualFile* vfs::CVirtualFile::Create(vfs::Path const& sFilePath, vfs::CProfileStack& rPStack) { unsigned int ID=0; -#if 0 - CVirtualFile* file = new CVirtualFile(); -#else +#ifdef VFILE_BLOCK_CREATE if(!_vfile_pool) { _vfile_pool = new ObjBlockAllocator(); CFileAllocator::RegisterAllocator(_vfile_pool); } CVirtualFile* file = _vfile_pool->New(&ID); +#else + CVirtualFile* file = new CVirtualFile(); #endif file->_path = sFilePath; file->_pstack = &rPStack; @@ -24,10 +24,14 @@ vfs::CVirtualFile* vfs::CVirtualFile::Create(vfs::Path const& sFilePath, vfs::CP return file; } -//vfs::CVirtualFile::CVirtualFile(vfs::Path const& sFilePath, CProfileStack& rPStack) -//: _path(sFilePath), _top_pname("_INVALID_"), _top_file(NULL), _rstack(rPStack) -//{ -//}; +void vfs::CVirtualFile::Destroy() +{ +#ifndef VFILE_BLOCK_CREATE + delete this; +#endif +} + + vfs::CVirtualFile::CVirtualFile() : _path(""), _top_pname("_INVALID_"), _top_file(NULL), _pstack(NULL) , _myID(-1) @@ -36,7 +40,6 @@ vfs::CVirtualFile::CVirtualFile() vfs::CVirtualFile::~CVirtualFile() { - int i = 0; } vfs::Path const& vfs::CVirtualFile::Path() diff --git a/VFS/vfs_vfile.h b/VFS/vfs_vfile.h index 70ff138b..e0a143b0 100644 --- a/VFS/vfs_vfile.h +++ b/VFS/vfs_vfile.h @@ -4,6 +4,8 @@ #include "vfs_profile.h" #include +#define VFILE_BLOCK_CREATE + namespace vfs { class CVirtualFile @@ -17,9 +19,9 @@ namespace vfs }; public: ~CVirtualFile(); - //CVirtualFile(vfs::Path const& sFilePath, CProfileStack& rPStack); + void Destroy(); static CVirtualFile* Create(vfs::Path const& sFilePath, CProfileStack& rPStack); - + vfs::Path const& Path(); void Add(vfs::IBaseFile *pFile, utf8string sProfileName, bool bReplace = false); bool Remove(vfs::IBaseFile *pFile); @@ -37,7 +39,9 @@ namespace vfs CProfileStack* _pstack; private: unsigned int _myID; +#ifdef VFILE_BLOCK_CREATE static ObjBlockAllocator* _vfile_pool; +#endif }; } // end namspace diff --git a/VFS/vfs_vloc.cpp b/VFS/vfs_vloc.cpp index 4468936c..40eef388 100644 --- a/VFS/vfs_vloc.cpp +++ b/VFS/vfs_vloc.cpp @@ -55,10 +55,10 @@ vfs::CVirtualLocation::CVirtualLocation(vfs::Path const& sPath) vfs::CVirtualLocation::~CVirtualLocation() { tVFiles::iterator it = m_mapVFiles.begin(); - //for(; it != m_mapVFiles.end(); ++it) - //{ - // delete it->second; - //} + for(; it != m_mapVFiles.end(); ++it) + { + it->second->Destroy(); + } m_mapVFiles.clear(); }