Fixed: Savestate bug when saving caused erratic freezeups.

Fixed: More savestate slowness, and less savestate memory hogging.
SPU2-X: Fixed crash bug on using savestates while suspended.

git-svn-id: http://pcsx2.googlecode.com/svn/trunk@1994 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
Jake.Stine 2009-10-09 17:28:17 +00:00
parent e8e61a5cf8
commit 28473c1436
8 changed files with 46 additions and 23 deletions

View File

@ -151,16 +151,15 @@ public:
m_ptr = _virtual_realloc( newsize );
if( m_ptr == NULL )
{
throw Exception::OutOfMemory(
wxsFormat( // english (for diagnostic)
L"Out-of-memory on SafeArray block re-allocation.\n"
L"Old size: %d bytes, New size: %d bytes.",
m_size, newsize
),
// internationalized!
wxsFormat( _("Out of memory, trying to allocate %d bytes."), newsize )
);
throw Exception::OutOfMemory(
wxsFormat( // english (for diagnostic)
L"Out-of-memory on SafeArray block re-allocation.\n"
L"Old size: %d bytes, New size: %d bytes.",
m_size, newsize
),
// internationalized!
wxsFormat( _("Out of memory, trying to allocate %d bytes."), newsize )
);
}
m_size = newsize;
}

View File

@ -104,6 +104,7 @@ protected:
void OnStart()
{
_parent::OnStart();
sys_resume_lock = true;
CoreThread.Pause();
}
@ -203,7 +204,7 @@ protected:
int thisBlockSize = std::min( BlockSize, state_buffer.GetSizeInBytes() - curidx );
if( gzwrite( m_gzfp, state_buffer.GetPtr(curidx), thisBlockSize ) < thisBlockSize )
throw Exception::BadStream( m_filename );
curidx += BlockSize;
curidx += thisBlockSize;
Yield( 1 );
} while( curidx < state_buffer.GetSizeInBytes() );
}
@ -259,11 +260,13 @@ protected:
{
// fixme: should start initially with the file size, and then grow from there.
static const int BlockSize = 327680;
static const int BlockSize = 0x100000;
state_buffer.MakeRoomFor( 0x800000 ); // start with an 8 meg buffer to avoid frequent reallocation.
int curidx = 0;
do
{
state_buffer.ExactAlloc( curidx+BlockSize );
state_buffer.MakeRoomFor( curidx+BlockSize );
gzread( m_gzfp, state_buffer.GetPtr(curidx), BlockSize );
curidx += BlockSize;
TestCancel();
@ -313,6 +316,11 @@ void OnFinished_Resume( const wxCommandEvent& evt )
CoreThread.Resume();
}
void OnFinished_Dispose( const wxCommandEvent& evt )
{
state_buffer.Dispose();
}
static wxString zip_dest_filename;
void OnFinished_ZipToDisk( const wxCommandEvent& evt )
@ -326,7 +334,7 @@ void OnFinished_ZipToDisk( const wxCommandEvent& evt )
}
// Phase 2: Record to disk!!
(new StateThread_ZipToDisk( NULL, zip_dest_filename ))->Start();
(new StateThread_ZipToDisk( OnFinished_Dispose, zip_dest_filename ))->Start();
CoreThread.Resume();
}

View File

@ -352,8 +352,6 @@ void SaveStateBase::FreezeAll()
memSavingState::memSavingState( SafeArray<u8>& save_to ) :
SaveStateBase( save_to )
{
save_to.ChunkSize = ReallocThreshold;
save_to.MakeRoomFor( MemoryBaseAllocSize );
}
// Saving of state data
@ -365,6 +363,15 @@ void memSavingState::FreezeMem( void* data, int size )
memcpy_fast( dest, data, size );
}
void memSavingState::FreezeAll()
{
// 90% of all savestates fit in under 45 megs (and require more than 43 megs, so migght as well...)
m_memory.ChunkSize = ReallocThreshold;
m_memory.MakeRoomFor( MemoryBaseAllocSize );
_parent::FreezeAll();
}
memLoadingState::memLoadingState( const SafeArray<u8>& load_from ) :
SaveStateBase( const_cast<SafeArray<u8>&>(load_from) )
{

View File

@ -85,7 +85,7 @@ public:
// Loads or saves the entire emulation state.
// Note: The Cpu state must be reset, and plugins *open*, prior to Defrosting
// (loading) a state!
void FreezeAll();
virtual void FreezeAll();
// Loads or saves an arbitrary data type. Usable on atomic types, structs, and arrays.
// For dynamically allocated pointers use FreezeMem instead.
@ -168,9 +168,11 @@ protected:
class memSavingState : public SaveStateBase
{
typedef SaveStateBase _parent;
protected:
static const int ReallocThreshold = 0x200000; // 256k reallocation block size.
static const int MemoryBaseAllocSize = 0x02a00000; // 42 meg base alloc
static const int MemoryBaseAllocSize = 0x02b00000; // 45 meg base alloc
public:
virtual ~memSavingState() { }
@ -178,6 +180,8 @@ public:
// Saving of state data to a memory buffer
void FreezeMem( void* data, int size );
void FreezeAll();
bool IsSaving() const { return true; }
};

View File

@ -431,8 +431,8 @@ void SysCoreThread::OnResumeInThread( bool isSuspended )
{
if( isSuspended && g_plugins != NULL )
{
CpuInitializeMess();
g_plugins->Open();
CpuInitializeMess();
}
}

View File

@ -220,11 +220,14 @@ u64 FileMemoryCard::GetCRC( uint port, uint slot )
if( !Seek( mcfp, 0 ) ) return 0;
// Process the file in 4k chunks. Speeds things up significantly.
u64 retval = 0;
for( uint i=MC2_SIZE/sizeof(u64); i; --i )
u64 buffer[0x1000];
for( uint i=MC2_SIZE/sizeof(buffer); i; --i )
{
u64 temp; mcfp.Read( &temp, sizeof(temp) );
retval ^= temp;
mcfp.Read( &buffer, sizeof(buffer) );
for( uint t=0; t<ArraySize(buffer); ++t )
retval ^= buffer[t];
}
return retval;

View File

@ -612,6 +612,6 @@ Global
{677B7D11-D5E1-40B3-88B1-9A4DF83D2213} = {2D6F0A62-A247-4CCF-947F-FCD54BE16103}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
AMDCaProjectFile = E:\devpcsx2\nommx\CodeAnalyst\pcsx2_suite_2008.caw
AMDCaProjectFile = E:\devpcsx2\trunk2\CodeAnalyst\pcsx2_suite_2008.caw
EndGlobalSection
EndGlobal

View File

@ -324,6 +324,8 @@ void SndBuffer::soundtouchInit()
// reset timestretch management vars, and delay updates a bit:
void SndBuffer::soundtouchClearContents()
{
if( pSoundTouch == NULL ) return;
pSoundTouch->clear();
pSoundTouch->setTempo(1);