Permalink
Browse files

Merge pull request #483 from fzurita/performance_optimizations

Performance optimizations
  • Loading branch information...
xperia64 committed Oct 11, 2015
2 parents 52ffc03 + bdf15f2 commit 0b588c32bdd82a9ceb4c1c6b135d8a7091aaaf0f
Showing with 644 additions and 308 deletions.
  1. +0 −1 res/values/strings.xml
  2. +0 −1 res/xml/preferences_game.xml
  3. +18 −10 src/paulscode/android/mupen64plusae/GalleryActivity.java
  4. +15 −2 src/paulscode/android/mupen64plusae/SplashActivity.java
  5. +43 −28 src/paulscode/android/mupen64plusae/cheat/CheatEditorActivity.java
  6. +7 −3 src/paulscode/android/mupen64plusae/cheat/CheatFile.java
  7. +23 −7 src/paulscode/android/mupen64plusae/cheat/CheatPreference.java
  8. +142 −83 src/paulscode/android/mupen64plusae/cheat/CheatUtils.java
  9. +4 −2 src/paulscode/android/mupen64plusae/game/GameActivity.java
  10. +5 −2 src/paulscode/android/mupen64plusae/game/GameActivityXperiaPlay.java
  11. +13 −5 src/paulscode/android/mupen64plusae/game/GameLifecycleHandler.java
  12. +4 −2 src/paulscode/android/mupen64plusae/game/GameMenuHandler.java
  13. +2 −1 src/paulscode/android/mupen64plusae/input/DiagnosticActivity.java
  14. +1 −1 src/paulscode/android/mupen64plusae/jni/CoreInterface.java
  15. +67 −27 src/paulscode/android/mupen64plusae/persistent/AppData.java
  16. +11 −17 src/paulscode/android/mupen64plusae/persistent/GamePrefs.java
  17. +71 −78 src/paulscode/android/mupen64plusae/persistent/GamePrefsActivity.java
  18. +62 −9 src/paulscode/android/mupen64plusae/persistent/GlobalPrefs.java
  19. +3 −3 src/paulscode/android/mupen64plusae/persistent/GlobalPrefsActivity.java
  20. +5 −2 src/paulscode/android/mupen64plusae/preference/PlayerMapPreference.java
  21. +3 −3 src/paulscode/android/mupen64plusae/preference/ProfilePreference.java
  22. +2 −1 src/paulscode/android/mupen64plusae/profile/ControllerProfileActivity.java
  23. +5 −2 src/paulscode/android/mupen64plusae/profile/EmulationProfileActivity.java
  24. +3 −2 src/paulscode/android/mupen64plusae/profile/ManageControllerProfilesActivity.java
  25. +3 −2 src/paulscode/android/mupen64plusae/profile/ManageEmulationProfilesActivity.java
  26. +4 −6 src/paulscode/android/mupen64plusae/profile/ManageProfilesActivity.java
  27. +3 −2 src/paulscode/android/mupen64plusae/profile/ManageTouchscreenProfilesActivity.java
  28. +3 −1 src/paulscode/android/mupen64plusae/profile/ProfileActivity.java
  29. +4 −2 src/paulscode/android/mupen64plusae/profile/TouchscreenProfileActivity.java
  30. +6 −1 src/paulscode/android/mupen64plusae/task/CacheRomInfoService.java
  31. +92 −0 src/paulscode/android/mupen64plusae/task/ExtractCheatsTask.java
  32. +3 −1 src/paulscode/android/mupen64plusae/util/CrashHandler.java
  33. +17 −1 src/paulscode/android/mupen64plusae/util/RomDatabase.java
View
@@ -197,7 +197,6 @@
<!-- Checkbox Preferences -->
<string name="playShowCheats_title">Enable cheats</string>
<string name="playShowCheats_summary">Menu loading is slower when enabled</string>
<string name="touchscreenFeedback_title">Haptic feedback</string>
<string name="touchscreenFeedback_summary">Vibrate on button press</string>
<string name="touchpadEnabled_title">Enable touchpad</string>
@@ -59,7 +59,6 @@
<CheckBoxPreference
android:defaultValue="false"
android:key="playShowCheats"
android:summary="@string/playShowCheats_summary"
android:title="@string/playShowCheats_title" />
<Preference
@@ -109,6 +109,7 @@
private List<GalleryItem> mGalleryItems = null;
private GalleryItem mSelectedItem = null;
private boolean mDragging = false;
private boolean mOnCreateCalled = false;
private CacheRomInfoFragment mCacheRomInfoFragment = null;
@@ -134,9 +135,11 @@ protected void onCreate( Bundle savedInstanceState )
{
super.onCreate( savedInstanceState );
mOnCreateCalled = true;
// Get app data and user preferences
mAppData = new AppData( this );
mGlobalPrefs = new GlobalPrefs( this );
mGlobalPrefs = new GlobalPrefs( this, mAppData );
mGlobalPrefs.enforceLocale( this );
int lastVer = mAppData.getLastAppVersionCode();
@@ -168,7 +171,13 @@ public void onComputeMd5Finished( File file, String md5 )
{
RomHeader header = new RomHeader(file);
final RomDatabase database = new RomDatabase( mAppData.mupen64plus_ini );
final RomDatabase database = RomDatabase.getInstance();
if(!database.hasDatabaseFile())
{
database.setDatabaseFile(mAppData.mupen64plus_ini);
}
RomDetail detail = database.lookupByMd5WithFallback( md5, file, header.crc );
launchGameActivity( file.getAbsolutePath(), null, true, md5, header.crc, header.name,
header.countryCode, null, detail.goodName, false );
@@ -276,12 +285,6 @@ public void onClick( MenuItem menuItem )
// Configure the game information drawer
mGameSidebar = (GameSidebar) findViewById( R.id.gameSidebar );
// Popup a warning if the installation appears to be corrupt
if( !mAppData.isValidInstallation )
{
Popups.showInvalidInstall( this );
}
if( savedInstanceState != null )
{
mSelectedItem = null;
@@ -768,7 +771,7 @@ protected void onResume()
private void refreshViews()
{
// Refresh the preferences object in case another activity changed the data
mGlobalPrefs = new GlobalPrefs( this );
mGlobalPrefs = new GlobalPrefs( this, mAppData );
// Set the sidebar opacity on the two sidebars
mDrawerList.setBackgroundDrawable( new DrawerDrawable(
@@ -777,7 +780,12 @@ private void refreshViews()
mGlobalPrefs.displayActionBarTransparency ) );
// Refresh the gallery
refreshGrid();
if(!mOnCreateCalled)
{
refreshGrid();
}
mOnCreateCalled = false;
}
public void launchGameActivity( String romPath, String zipPath, boolean extracted, String romMd5, String romCrc,
@@ -26,6 +26,7 @@
import org.mupen64plusae.v3.alpha.R;
import paulscode.android.mupen64plusae.cheat.CheatUtils;
import paulscode.android.mupen64plusae.dialog.Popups;
import paulscode.android.mupen64plusae.persistent.AppData;
import paulscode.android.mupen64plusae.persistent.GlobalPrefs;
import paulscode.android.mupen64plusae.preference.PrefUtil;
@@ -34,6 +35,7 @@
import paulscode.android.mupen64plusae.task.ExtractAssetsTask.Failure;
import paulscode.android.mupen64plusae.util.FileUtil;
import paulscode.android.mupen64plusae.util.Notifier;
import paulscode.android.mupen64plusae.util.RomDatabase;
import tv.ouya.console.api.OuyaFacade;
import android.content.SharedPreferences;
import android.content.res.Resources;
@@ -111,7 +113,7 @@ public void onCreate( Bundle savedInstanceState )
// Get app data and user preferences
mAppData = new AppData( this );
mGlobalPrefs = new GlobalPrefs( this );
mGlobalPrefs = new GlobalPrefs( this, mAppData );
mGlobalPrefs.enforceLocale( this );
mPrefs = PreferenceManager.getDefaultSharedPreferences( this );
@@ -138,7 +140,7 @@ public void onCreate( Bundle savedInstanceState )
// @formatter:on
// Refresh the preference data wrapper
mGlobalPrefs = new GlobalPrefs( this );
mGlobalPrefs = new GlobalPrefs( this, mAppData );
// Initialize the OUYA interface if running on OUYA
if( AppData.IS_OUYA_HARDWARE )
@@ -164,6 +166,12 @@ public void onCreate( Bundle savedInstanceState )
// Handler.postDelayed ensures this runs only after activity has resumed
final Handler handler = new Handler();
handler.postDelayed( extractAssetsTaskLauncher, SPLASH_DELAY );
// Popup a warning if the installation appears to be corrupt
if( !mAppData.isValidInstallation() )
{
Popups.showInvalidInstall( this );
}
}
/** Runnable that launches the non-UI thread from the UI thread after the activity has resumed. */
@@ -209,6 +217,11 @@ public void onExtractAssetsFinished( List<Failure> failures )
mAppData.putAssetVersion( ASSET_VERSION );
CheatUtils.mergeCheatFiles( mAppData.mupencheat_default, mGlobalPrefs.customCheats_txt, mAppData.mupencheat_txt );
if(!RomDatabase.getInstance().hasDatabaseFile())
{
RomDatabase.getInstance().setDatabaseFile(mAppData.mupen64plus_ini);
}
// Launch gallery activity, passing ROM path if it was provided externally
ActivityHelper.startGalleryActivity( this, getIntent().getData() );
@@ -21,6 +21,7 @@
package paulscode.android.mupen64plusae.cheat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
@@ -33,6 +34,8 @@
import paulscode.android.mupen64plusae.dialog.Prompt.PromptTextListener;
import paulscode.android.mupen64plusae.persistent.AppData;
import paulscode.android.mupen64plusae.persistent.GlobalPrefs;
import paulscode.android.mupen64plusae.task.ExtractCheatsTask;
import paulscode.android.mupen64plusae.task.ExtractCheatsTask.ExtractCheatListener;
import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
@@ -55,7 +58,7 @@
import android.widget.TextView;
import android.widget.Toast;
public class CheatEditorActivity extends AppCompatListActivity implements View.OnClickListener, OnItemLongClickListener
public class CheatEditorActivity extends AppCompatListActivity implements View.OnClickListener, OnItemLongClickListener, ExtractCheatListener
{
private static class CheatListAdapter extends ArrayAdapter<Cheat>
{
@@ -91,7 +94,8 @@ public View getView( int position, View convertView, ViewGroup parent )
}
}
private final ArrayList<Cheat> cheats = new ArrayList<Cheat>();
private final ArrayList<Cheat> userCheats = new ArrayList<Cheat>();
private final ArrayList<Cheat> systemCheats = new ArrayList<Cheat>();
private CheatListAdapter cheatListAdapter = null;
private AppData mAppData = null;
private GlobalPrefs mGlobalPrefs = null;
@@ -104,7 +108,7 @@ protected void onCreate( Bundle savedInstanceState )
{
super.onCreate( savedInstanceState );
mAppData = new AppData( this );
mGlobalPrefs = new GlobalPrefs( this );
mGlobalPrefs = new GlobalPrefs( this, mAppData );
mGlobalPrefs.enforceLocale( this );
// Get the ROM header info
@@ -132,21 +136,38 @@ private void reload( String crc )
if( crc == null )
return;
// Get the appropriate section of the config file, using CRC as the key
CheatFile mupencheat_default = new CheatFile( mAppData.mupencheat_default );
CheatFile usrcheat_txt = new CheatFile( mGlobalPrefs.customCheats_txt );
cheats.addAll( CheatUtils.populate( crc, mupencheat_default, true, this ) );
cheats.addAll( CheatUtils.populate( crc, usrcheat_txt, false, this ) );
cheatListAdapter = new CheatListAdapter( this, cheats );
//Do this in a separate task since it takes longer
ExtractCheatsTask cheatsTask = new ExtractCheatsTask(this, this, mAppData.mupencheat_default, crc);
cheatsTask.execute((String) null);
//We don't extract user cheats in a separate task since there aren't as many
CheatFile usrcheat_txt = new CheatFile( mGlobalPrefs.customCheats_txt, true );
userCheats.clear();
userCheats.addAll( CheatUtils.populate( mRomCrc, usrcheat_txt, false, this ) );
cheatListAdapter = new CheatListAdapter( this, userCheats );
setListAdapter( cheatListAdapter );
}
@Override
public void onExtractFinished(ArrayList<Cheat> moreCheats)
{
systemCheats.clear();
systemCheats.addAll( moreCheats );
}
private void save( String crc )
{
CheatFile usrcheat_txt = new CheatFile( mGlobalPrefs.customCheats_txt );
CheatFile mupencheat_txt = new CheatFile( mAppData.mupencheat_txt );
CheatUtils.save( crc, usrcheat_txt, cheats, mRomHeaderName, mRomCountryCode, this, false );
CheatUtils.save( crc, mupencheat_txt, cheats, mRomHeaderName, mRomCountryCode, this, true );
ArrayList<Cheat> combinedCheats;
combinedCheats = new ArrayList<Cheat>();
combinedCheats.addAll(systemCheats);
combinedCheats.addAll(userCheats);
Collections.sort(combinedCheats);
CheatFile usrcheat_txt = new CheatFile( mGlobalPrefs.customCheats_txt, true );
CheatFile mupencheat_txt = new CheatFile( mAppData.mupencheat_txt, true );
CheatUtils.save( crc, usrcheat_txt, userCheats, mRomHeaderName, mRomCountryCode, this, false );
CheatUtils.save( crc, mupencheat_txt, combinedCheats, mRomHeaderName, mRomCountryCode, this, true );
}
private boolean isHexNumber( String num )
@@ -165,7 +186,7 @@ private boolean isHexNumber( String num )
@Override
protected void onListItemClick( ListView l, View v, final int position, long id )
{
Cheat cheat = cheats.get( position );
Cheat cheat = userCheats.get( position );
StringBuilder message = new StringBuilder();
message.append( getString( R.string.cheatEditor_title2 ) + "\n" );
message.append( cheat.name + "\n" );
@@ -198,8 +219,8 @@ public void onClick( View v )
cheat.desc = getString( R.string.cheatNotes_none );
cheat.code = "";
cheat.option = "";
cheats.add( cheat );
cheatListAdapter = new CheatListAdapter( CheatEditorActivity.this, cheats );
userCheats.add( cheat );
cheatListAdapter = new CheatListAdapter( CheatEditorActivity.this, userCheats );
setListAdapter( cheatListAdapter );
Toast t = Toast.makeText( CheatEditorActivity.this, getString( R.string.cheatEditor_added ), Toast.LENGTH_SHORT );
t.show();
@@ -214,7 +235,6 @@ public void onClick( View v )
case R.id.imgBtnChtSave:
save( mRomCrc );
CheatUtils.reset();
CheatEditorActivity.this.finish();
break;
@@ -239,7 +259,7 @@ public void onClick( View v )
@Override
public boolean onItemLongClick( AdapterView<?> av, View v, final int pos, long id )
{
final Cheat cheat = cheats.get( pos );
final Cheat cheat = userCheats.get( pos );
// Inflate the long-click dialog
LayoutInflater inflater = (LayoutInflater) getSystemService( Context.LAYOUT_INFLATER_SERVICE );
@@ -286,13 +306,9 @@ public void onClick( View v )
ll.findViewById( R.id.btnEditCode ).setOnClickListener( listener );
ll.findViewById( R.id.btnEditOption ).setOnClickListener( listener );
ll.findViewById( R.id.btnDelete ).setOnClickListener( listener );
if( pos < CheatUtils.numberOfSystemCheats )
{
ll.findViewById( R.id.btnDelete ).setEnabled( false );
}
// Hide the edit option button if not applicable
if( !cheats.get( pos ).code.contains( "?" ) )
if( !userCheats.get( pos ).code.contains( "?" ) )
ll.findViewById( R.id.btnEditOption ).setVisibility( View.GONE );
// Show the long-click dialog
@@ -315,7 +331,6 @@ public void onClick( DialogInterface dialog, int which )
{
save( mRomCrc );
}
CheatUtils.reset();
CheatEditorActivity.this.finish();
}
};
@@ -343,7 +358,7 @@ public void onDialogClosed( CharSequence text, int which )
{
String str = text.toString().replace( '\n', ' ' );
cheat.name = str;
cheatListAdapter = new CheatListAdapter( CheatEditorActivity.this, cheats );
cheatListAdapter = new CheatListAdapter( CheatEditorActivity.this, userCheats );
setListAdapter( cheatListAdapter );
}
}
@@ -501,8 +516,8 @@ public void onClick( DialogInterface dialog, int which )
{
if( which == DialogInterface.BUTTON_POSITIVE )
{
cheats.remove( pos );
cheatListAdapter = new CheatListAdapter( CheatEditorActivity.this, cheats );
userCheats.remove( pos );
cheatListAdapter = new CheatListAdapter( CheatEditorActivity.this, userCheats );
setListAdapter( cheatListAdapter );
}
}
@@ -513,5 +528,5 @@ public void onClick( DialogInterface dialog, int which )
builder.setPositiveButton( android.R.string.yes, listener );
builder.setNegativeButton( android.R.string.no, listener );
builder.create().show();
}
}
}
@@ -98,11 +98,15 @@
*
* @param filename the path of the file to load
*/
public CheatFile( String filename )
public CheatFile( String filename, boolean loadAll )
{
mFilename = filename;
mSections = new LinkedHashMap<String, CheatFile.CheatSection>();
reload();
if(loadAll)
{
reload();
}
}
/**
@@ -333,7 +337,7 @@ public CheatSection( String crc, String name, String country )
* @param reader the object providing disk read access
* @throws IOException if a read error occurs
*/
private CheatSection( String key, BufferedReader reader ) throws IOException
public CheatSection( String key, BufferedReader reader ) throws IOException
{
this.key = key;
this.blocks = new LinkedList<CheatBlock>();
Oops, something went wrong.

0 comments on commit 0b588c3

Please sign in to comment.