More hotkey fixes

git-svn-id: http://pcsx2.googlecode.com/svn/trunk@2416 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
Jake.Stine 2010-01-08 23:33:15 +00:00
parent e8cb837db5
commit bee1bde1b3
10 changed files with 109 additions and 79 deletions

View File

@ -16,6 +16,7 @@
#pragma once #pragma once
#include <list> #include <list>
#include "Threading.h"
class wxCommandEvent; class wxCommandEvent;
@ -86,6 +87,8 @@ protected:
ListenerList m_cache_copy; ListenerList m_cache_copy;
bool m_cache_valid; bool m_cache_valid;
Threading::Mutex m_listeners_lock;
public: public:
EventSource() : m_cache_valid( false ) EventSource() : m_cache_valid( false )
{ {
@ -93,34 +96,12 @@ public:
virtual ~EventSource() throw() {} virtual ~EventSource() throw() {}
virtual void Remove( const ListenerType& listener ) virtual void Remove( const ListenerType& listener );
{ virtual void Remove( const Handle& listenerHandle );
m_cache_valid = false;
m_listeners.remove( listener );
}
virtual void Remove( const Handle& listenerHandle ) Handle AddFast( const ListenerType& listener );
{ void Add( void* objhandle, typename ListenerType::FuncType* fnptr );
m_cache_valid = false; void Remove( void* objhandle, typename ListenerType::FuncType* fnptr );
m_listeners.erase( listenerHandle );
}
virtual Handle AddFast( const ListenerType& listener )
{
m_cache_valid = false;
m_listeners.push_front( listener );
return m_listeners.begin();
}
void Add( void* objhandle, typename ListenerType::FuncType* fnptr )
{
Add( ListenerType( objhandle, fnptr ) );
}
void Remove( void* objhandle, typename ListenerType::FuncType* fnptr )
{
Remove( ListenerType( objhandle, fnptr ) );
}
// Checks for duplicates before adding the event. // Checks for duplicates before adding the event.
virtual void Add( const ListenerType& listener ); virtual void Add( const ListenerType& listener );
@ -128,6 +109,7 @@ public:
void Dispatch( EvtType& evt ); void Dispatch( EvtType& evt );
protected: protected:
virtual Handle _AddFast_without_lock( const ListenerType& listener );
inline void _DispatchRaw( ConstIterator iter, const ConstIterator& iend, EvtType& evt ); inline void _DispatchRaw( ConstIterator iter, const ConstIterator& iend, EvtType& evt );
}; };
@ -150,10 +132,10 @@ protected:
bool m_attached; bool m_attached;
public: public:
EventListenerBinding( EventSource<EvtType>& source, const ListenerHandle& listener, bool autoAttach=true ) : EventListenerBinding( EventSource<EvtType>& source, const ListenerHandle& listener, bool autoAttach=true )
m_source( source ) : m_source( source )
, m_listener( listener ) , m_listener( listener )
, m_attached( false ) , m_attached( false )
{ {
// If you want to assert on null pointers, you'll need to do the check yourself. There's // If you want to assert on null pointers, you'll need to do the check yourself. There's
// too many cases where silently ignoring null pointers is the desired behavior. // too many cases where silently ignoring null pointers is the desired behavior.
@ -185,8 +167,4 @@ typedef EventSource<wxCommandEvent> CmdEvt_Source;
typedef EventListener<wxCommandEvent> CmdEvt_Listener; typedef EventListener<wxCommandEvent> CmdEvt_Listener;
typedef EventListenerBinding<wxCommandEvent> CmdEvt_ListenerBinding; typedef EventListenerBinding<wxCommandEvent> CmdEvt_ListenerBinding;
#define EventSource_ImplementType( tname ) \ #define EventSource_ImplementType( tname ) template class EventSource<tname>
template void EventSource<tname>::Add(const EventSource<tname>::ListenerType &listener); \
template void EventSource<tname>::RemoveObject(const void* object); \
template void EventSource<tname>::Dispatch(tname& evt); \
template void EventSource<tname>::_DispatchRaw( EventSource<tname>::ConstIterator iter, const EventSource<tname>::ConstIterator& iend, tname& evt );

View File

@ -15,20 +15,7 @@
#pragma once #pragma once
// Checks for duplicates before adding the event. using Threading::ScopedLock;
template< typename EvtType >
void EventSource<EvtType>::Add( const ListenerType& listener )
{
if( !pxAssertDev( listener.OnEvent != NULL, "NULL listener callback function." ) ) return;
Handle iter = m_listeners.begin();
while( iter != m_listeners.end() )
{
if( *iter == listener ) return;
++iter;
}
AddFast( listener );
}
template< typename EvtType > template< typename EvtType >
class PredicatesAreTheThingsOfNightmares class PredicatesAreTheThingsOfNightmares
@ -47,6 +34,67 @@ public:
} }
}; };
// Checks for duplicates before adding the event.
template< typename EvtType >
void EventSource<EvtType>::Add( const ListenerType& listener )
{
ScopedLock locker( m_listeners_lock );
if( !pxAssertDev( listener.OnEvent != NULL, "NULL listener callback function." ) ) return;
Handle iter = m_listeners.begin();
while( iter != m_listeners.end() )
{
if( *iter == listener ) return;
++iter;
}
_AddFast_without_lock( listener );
}
template< typename EvtType >
void EventSource<EvtType>::Remove( const ListenerType& listener )
{
ScopedLock locker( m_listeners_lock );
m_cache_valid = false;
m_listeners.remove( listener );
}
template< typename EvtType >
void EventSource<EvtType>::Remove( const Handle& listenerHandle )
{
ScopedLock locker( m_listeners_lock );
m_cache_valid = false;
m_listeners.erase( listenerHandle );
}
template< typename EvtType >
typename EventSource<EvtType>::Handle EventSource<EvtType>::AddFast( const ListenerType& listener )
{
ScopedLock locker( m_listeners_lock );
return _AddFast_without_lock( listener );
}
template< typename EvtType >
typename EventSource<EvtType>::Handle EventSource<EvtType>::_AddFast_without_lock( const ListenerType& listener )
{
m_cache_valid = false;
m_listeners.push_front( listener );
return m_listeners.begin();
}
template< typename EvtType >
void EventSource<EvtType>::Add( void* objhandle, typename ListenerType::FuncType* fnptr )
{
Add( ListenerType( objhandle, fnptr ) );
}
template< typename EvtType >
void EventSource<EvtType>::Remove( void* objhandle, typename ListenerType::FuncType* fnptr )
{
Remove( ListenerType( objhandle, fnptr ) );
}
// removes all listeners which reference the given object. Use for assuring object deletion. // removes all listeners which reference the given object. Use for assuring object deletion.
template< typename EvtType > template< typename EvtType >
void EventSource<EvtType>::RemoveObject( const void* object ) void EventSource<EvtType>::RemoveObject( const void* object )

View File

@ -19,5 +19,5 @@
#include <wx/event.h> #include <wx/event.h>
EventSource_ImplementType( wxCommandEvent ); template class EventSource< wxCommandEvent >;
EventSource_ImplementType( int ); template class EventSource< int >;

View File

@ -86,8 +86,8 @@ public:
} }
protected: protected:
_BaseStateThread( const char* name, FnType_OnThreadComplete* onFinished ) : _BaseStateThread( const char* name, FnType_OnThreadComplete* onFinished )
m_bind_OnExit( wxGetApp().Source_AppStatus(), EventListener<AppEventType>( this, StateThread_OnAppStatus ) ) : m_bind_OnExit( wxGetApp().Source_AppStatus(), EventListener<AppEventType>( this, StateThread_OnAppStatus ) )
{ {
Callback_FreezeFinished = onFinished; Callback_FreezeFinished = onFinished;
m_name = L"StateThread::" + fromUTF8(name); m_name = L"StateThread::" + fromUTF8(name);
@ -366,7 +366,7 @@ void StateCopy_LoadFromSlot( uint slot )
bool StateCopy_IsValid() bool StateCopy_IsValid()
{ {
return !state_buffer.IsDisposed(); return !state_buffer.IsDisposed();
} }
const SafeArray<u8>* StateCopy_GetBuffer() const SafeArray<u8>* StateCopy_GetBuffer()

View File

@ -22,7 +22,7 @@
#include "System/PageFaultSource.h" #include "System/PageFaultSource.h"
#include "Utilities/EventSource.inl" #include "Utilities/EventSource.inl"
EventSource_ImplementType( PageFaultInfo ); template class EventSource< PageFaultInfo >;
SrcType_PageFault Source_PageFault; SrcType_PageFault Source_PageFault;

View File

@ -250,7 +250,7 @@ void SysCoreThread::_reset_stuff_as_needed()
} }
if( m_resetVsyncTimers ) if( m_resetVsyncTimers )
{ {
UpdateVSyncRate(); UpdateVSyncRate();
frameLimitReset(); frameLimitReset();
m_resetVsyncTimers = false; m_resetVsyncTimers = false;

View File

@ -322,11 +322,11 @@ protected:
EventSource<AppEventType> m_evtsrc_AppStatus; EventSource<AppEventType> m_evtsrc_AppStatus;
public: public:
CmdEvt_Source& Source_CoreThreadStatus() { AffinityAssert_AllowFromMain(); return m_evtsrc_CoreThreadStatus; } CmdEvt_Source& Source_CoreThreadStatus() { return m_evtsrc_CoreThreadStatus; }
EventSource<int>& Source_SettingsApplied() { AffinityAssert_AllowFromMain(); return m_evtsrc_SettingsApplied; } EventSource<int>& Source_SettingsApplied() { return m_evtsrc_SettingsApplied; }
EventSource<AppEventType>& Source_AppStatus() { AffinityAssert_AllowFromMain(); return m_evtsrc_AppStatus; } EventSource<AppEventType>& Source_AppStatus() { return m_evtsrc_AppStatus; }
EventSource<PluginEventType>& Source_CorePluginStatus() { AffinityAssert_AllowFromMain(); return m_evtsrc_CorePluginStatus; } EventSource<PluginEventType>& Source_CorePluginStatus() { return m_evtsrc_CorePluginStatus; }
EventSource<IniInterface>& Source_SettingsLoadSave() { AffinityAssert_AllowFromMain(); return m_evtsrc_SettingsLoadSave; } EventSource<IniInterface>& Source_SettingsLoadSave() { return m_evtsrc_SettingsLoadSave; }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
public: public:

View File

@ -45,9 +45,9 @@ DEFINE_EVENT_TYPE( pxEvt_InvokeMethod );
DEFINE_EVENT_TYPE( pxEvt_LogicalVsync ); DEFINE_EVENT_TYPE( pxEvt_LogicalVsync );
#include "Utilities/EventSource.inl" #include "Utilities/EventSource.inl"
EventSource_ImplementType( IniInterface ); template class EventSource< IniInterface >;
EventSource_ImplementType( AppEventType ); template class EventSource< AppEventType >;
EventSource_ImplementType( PluginEventType ); template class EventSource< PluginEventType >;
bool UseAdminMode = false; bool UseAdminMode = false;
wxDirName SettingsFolder; wxDirName SettingsFolder;
@ -202,7 +202,7 @@ void Pcsx2App::PadKeyDispatch( const keyEvent& ev )
// times a second if not (ok, not quite, but you get the idea... I hope.) // times a second if not (ok, not quite, but you get the idea... I hope.)
void Pcsx2App::LogicalVsync() void Pcsx2App::LogicalVsync()
{ {
if( !SelfMethodPost( &Pcsx2App::LogicalVsync ) ) return; if( SelfMethodPost( &Pcsx2App::LogicalVsync ) ) return;
if( !SysHasValidState() || g_plugins == NULL ) return; if( !SysHasValidState() || g_plugins == NULL ) return;

View File

@ -30,7 +30,7 @@ struct Component_FileMcd;
# include "svnrev.h" # include "svnrev.h"
#endif #endif
#include <wx/file.h> #include <wx/ffile.h>
static const int MCD_SIZE = 1024 * 8 * 16; static const int MCD_SIZE = 1024 * 8 * 16;
static const int MC2_SIZE = 1024 * 528 * 16; static const int MC2_SIZE = 1024 * 528 * 16;
@ -43,13 +43,13 @@ static const int MC2_SIZE = 1024 * 528 * 16;
class FileMemoryCard class FileMemoryCard
{ {
protected: protected:
wxFile m_file[2][4]; wxFFile m_file[2][4];
u8 m_effeffs[528*16]; u8 m_effeffs[528*16];
SafeArray<u8> m_currentdata; SafeArray<u8> m_currentdata;
public: public:
FileMemoryCard(); FileMemoryCard();
virtual ~FileMemoryCard() {} virtual ~FileMemoryCard() throw() {}
void Lock(); void Lock();
void Unlock(); void Unlock();
@ -61,7 +61,7 @@ public:
u64 GetCRC( uint port, uint slot ); u64 GetCRC( uint port, uint slot );
protected: protected:
bool Seek( wxFile& f, u32 adr ); bool Seek( wxFFile& f, u32 adr );
bool Create( const wxString& mcdFile ); bool Create( const wxString& mcdFile );
wxString GetDisabledMessage( uint port, uint slot ) const wxString GetDisabledMessage( uint port, uint slot ) const
@ -104,7 +104,7 @@ FileMemoryCard::FileMemoryCard()
NTFS_CompressFile( str, g_Conf->McdEnableNTFS ); NTFS_CompressFile( str, g_Conf->McdEnableNTFS );
if( !m_file[port][slot].Open( str.c_str(), wxFile::read_write ) ) if( !m_file[port][slot].Open( str.c_str(), L"r+b" ) )
{ {
// Translation note: detailed description should mention that the memory card will be disabled // Translation note: detailed description should mention that the memory card will be disabled
// for the duration of this session. // for the duration of this session.
@ -118,7 +118,7 @@ FileMemoryCard::FileMemoryCard()
} }
// Returns FALSE if the seek failed (is outside the bounds of the file). // Returns FALSE if the seek failed (is outside the bounds of the file).
bool FileMemoryCard::Seek( wxFile& f, u32 adr ) bool FileMemoryCard::Seek( wxFFile& f, u32 adr )
{ {
const u32 size = f.Length(); const u32 size = f.Length();
@ -137,7 +137,7 @@ bool FileMemoryCard::Seek( wxFile& f, u32 adr )
// perform sanity checks here? // perform sanity checks here?
} }
return wxInvalidOffset != f.Seek( adr + offset ); return f.Seek( adr + offset );
} }
// returns FALSE if an error occurred (either permission denied or disk full) // returns FALSE if an error occurred (either permission denied or disk full)
@ -145,7 +145,7 @@ bool FileMemoryCard::Create( const wxString& mcdFile )
{ {
//int enc[16] = {0x77,0x7f,0x7f,0x77,0x7f,0x7f,0x77,0x7f,0x7f,0x77,0x7f,0x7f,0,0,0,0}; //int enc[16] = {0x77,0x7f,0x7f,0x77,0x7f,0x7f,0x77,0x7f,0x7f,0x77,0x7f,0x7f,0,0,0,0};
wxFile fp( mcdFile, wxFile::write ); wxFFile fp( mcdFile, L"wb" );
if( !fp.IsOpened() ) return false; if( !fp.IsOpened() ) return false;
for( uint i=0; i<MC2_SIZE/sizeof(m_effeffs); i++ ) for( uint i=0; i<MC2_SIZE/sizeof(m_effeffs); i++ )
@ -163,7 +163,7 @@ s32 FileMemoryCard::IsPresent( uint port, uint slot )
s32 FileMemoryCard::Read( uint port, uint slot, u8 *dest, u32 adr, int size ) s32 FileMemoryCard::Read( uint port, uint slot, u8 *dest, u32 adr, int size )
{ {
wxFile& mcfp( m_file[port][slot] ); wxFFile& mcfp( m_file[port][slot] );
if( !mcfp.IsOpened() ) if( !mcfp.IsOpened() )
{ {
DevCon.Error( "MemoryCard: Ignoring attempted read from disabled card." ); DevCon.Error( "MemoryCard: Ignoring attempted read from disabled card." );
@ -176,7 +176,7 @@ s32 FileMemoryCard::Read( uint port, uint slot, u8 *dest, u32 adr, int size )
s32 FileMemoryCard::Save( uint port, uint slot, const u8 *src, u32 adr, int size ) s32 FileMemoryCard::Save( uint port, uint slot, const u8 *src, u32 adr, int size )
{ {
wxFile& mcfp( m_file[port][slot] ); wxFFile& mcfp( m_file[port][slot] );
if( !mcfp.IsOpened() ) if( !mcfp.IsOpened() )
{ {
@ -201,7 +201,7 @@ s32 FileMemoryCard::Save( uint port, uint slot, const u8 *src, u32 adr, int size
s32 FileMemoryCard::EraseBlock( uint port, uint slot, u32 adr ) s32 FileMemoryCard::EraseBlock( uint port, uint slot, u32 adr )
{ {
wxFile& mcfp( m_file[port][slot] ); wxFFile& mcfp( m_file[port][slot] );
if( !mcfp.IsOpened() ) if( !mcfp.IsOpened() )
{ {
@ -215,7 +215,7 @@ s32 FileMemoryCard::EraseBlock( uint port, uint slot, u32 adr )
u64 FileMemoryCard::GetCRC( uint port, uint slot ) u64 FileMemoryCard::GetCRC( uint port, uint slot )
{ {
wxFile& mcfp( m_file[port][slot] ); wxFFile& mcfp( m_file[port][slot] );
if( !mcfp.IsOpened() ) return 0; if( !mcfp.IsOpened() ) return 0;
if( !Seek( mcfp, 0 ) ) return 0; if( !Seek( mcfp, 0 ) ) return 0;
@ -272,6 +272,8 @@ static u64 PS2E_CALLBACK FileMcd_GetCRC( PS2E_THISPTR thisptr, uint port, uint s
Component_FileMcd::Component_FileMcd() Component_FileMcd::Component_FileMcd()
{ {
memzero( api );
api.McdIsPresent = FileMcd_IsPresent; api.McdIsPresent = FileMcd_IsPresent;
api.McdRead = FileMcd_Read; api.McdRead = FileMcd_Read;
api.McdSave = FileMcd_Save; api.McdSave = FileMcd_Save;

View File

@ -237,6 +237,9 @@ protected:
wxString m_Stacktrace; wxString m_Stacktrace;
public: public:
virtual ~pxAssertionEvent() throw() { }
virtual pxAssertionEvent *Clone() const { return new pxAssertionEvent(*this); }
pxAssertionEvent(); pxAssertionEvent();
pxAssertionEvent( MsgboxEventResult& instdata, const wxString& content, const wxString& trace ); pxAssertionEvent( MsgboxEventResult& instdata, const wxString& content, const wxString& trace );
pxAssertionEvent( const wxString& content, const wxString& trace ); pxAssertionEvent( const wxString& content, const wxString& trace );
@ -244,7 +247,6 @@ public:
pxAssertionEvent& SetInstData( MsgboxEventResult& instdata ); pxAssertionEvent& SetInstData( MsgboxEventResult& instdata );
pxAssertionEvent& SetStacktrace( const wxString& trace ); pxAssertionEvent& SetStacktrace( const wxString& trace );
~pxAssertionEvent() throw() { }
protected: protected:
virtual int _DoDialog() const; virtual int _DoDialog() const;