From b882a79322b9cff24c9e61e6018720b06cffc986 Mon Sep 17 00:00:00 2001 From: sigmabeta Date: Sun, 3 Jan 2016 16:32:17 -0500 Subject: [PATCH] Add support for the CPU Clock Override feature to Android UI --- .../dolphinemu/utils/SliderPreference.java | 48 ++++++++++++++++--- .../dolphinemu/utils/UserPreferences.java | 8 ++++ .../app/src/main/res/values/strings.xml | 4 ++ .../app/src/main/res/xml/preferences.xml | 15 ++++++ 4 files changed, 68 insertions(+), 7 deletions(-) diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/SliderPreference.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/SliderPreference.java index eab6f74ff0..da896cf590 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/SliderPreference.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/SliderPreference.java @@ -11,6 +11,7 @@ import android.widget.Button; import android.widget.LinearLayout; import android.widget.SeekBar; import android.widget.TextView; +import android.widget.Toast; import org.dolphinemu.dolphinemu.R; @@ -20,6 +21,7 @@ public class SliderPreference extends DialogPreference implements SeekBar.OnSeek // SeekBar private int m_max, m_value; + private String m_key; private SeekBar m_seekbar; // TextView @@ -32,19 +34,35 @@ public class SliderPreference extends DialogPreference implements SeekBar.OnSeek // Seekbar values m_value = attrs.getAttributeIntValue(androidns, "defaultValue", 0); m_max = attrs.getAttributeIntValue(androidns, "max", 100); + m_key = attrs.getAttributeValue(androidns, "key"); } @Override protected View onCreateDialogView() { LayoutInflater inflater = LayoutInflater.from(getContext()); - LinearLayout layout = (LinearLayout)inflater.inflate(R.layout.slider_layout, null, false); + LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.slider_layout, null, false); - m_seekbar = (SeekBar)layout.findViewById(R.id.sliderSeekBar); - m_textview = (TextView)layout.findViewById(R.id.sliderTextView); + m_seekbar = (SeekBar) layout.findViewById(R.id.sliderSeekBar); + m_textview = (TextView) layout.findViewById(R.id.sliderTextView); if (shouldPersist()) - m_value = Integer.valueOf(getPersistedString(Integer.toString(m_value))); + { + if (m_key != null && m_key.equals("Overclock")) + { + Toast.makeText(getContext(), getContext().getString(R.string.overclock_warning), + Toast.LENGTH_LONG).show(); + + float valueAsFloat = Float.valueOf(getPersistedString(Integer.toString(m_value))); + float valueAsPercent = valueAsFloat * 100; + + m_value = Math.round(valueAsPercent); + } + else + { + m_value = Integer.valueOf(getPersistedString(Integer.toString(m_value))); + } + } m_seekbar.setMax(m_max); m_seekbar.setProgress(m_value); @@ -63,9 +81,14 @@ public class SliderPreference extends DialogPreference implements SeekBar.OnSeek } @Override - public void onStartTrackingTouch(SeekBar seek) {} + public void onStartTrackingTouch(SeekBar seek) + { + } + @Override - public void onStopTrackingTouch(SeekBar seek) {} + public void onStopTrackingTouch(SeekBar seek) + { + } void setProgressText(int value) { @@ -86,7 +109,18 @@ public class SliderPreference extends DialogPreference implements SeekBar.OnSeek { if (shouldPersist()) { - persistString(Integer.toString(m_seekbar.getProgress())); + String valueToSave; + if (m_key != null && m_key.equals("Overclock")) + { + float valueAsFloat = m_value / 100.0f; + valueToSave = Float.toString(valueAsFloat); + } + else + { + valueToSave = Integer.toString(m_seekbar.getProgress()); + } + + persistString(valueToSave); callChangeListener(m_seekbar.getProgress()); } ((AlertDialog) getDialog()).dismiss(); diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/UserPreferences.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/UserPreferences.java index d85705fafe..d1c5e92600 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/UserPreferences.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/UserPreferences.java @@ -46,6 +46,8 @@ public final class UserPreferences editor.putString("cpuCorePref", getConfig("Dolphin.ini", "Core", "CPUCore", "3")); editor.putBoolean("dualCorePref", getConfig("Dolphin.ini", "Core", "CPUThread", "True").equals("True")); + editor.putBoolean("OverclockEnable", getConfig("Dolphin.ini", "Core", "OverclockEnable", "False").equals("True")); + editor.putString("Overclock", getConfig("Dolphin.ini", "Core", "Overclock", "100")); editor.putString("WiimoteExtension_4", getConfig("WiimoteNew.ini", "Wiimote1", "Extension", "None")); editor.putString("WiimoteExtension_5", getConfig("WiimoteNew.ini", "Wiimote2", "Extension", "None")); @@ -142,6 +144,9 @@ public final class UserPreferences // Current CPU core being used. Falls back to interpreter upon error. String currentEmuCore = prefs.getString("cpuCorePref", "0"); + boolean overclockEnabled = prefs.getBoolean("OverclockEnable", false); + String overclockSetting = prefs.getString("Overclock", "100"); + // Current wiimote extension setup. Falls back to no extension upon error. String WiimoteExtension_4 = prefs.getString("WiimoteExtension_4", "None"); String WiimoteExtension_5 = prefs.getString("WiimoteExtension_5", "None"); @@ -225,6 +230,9 @@ public final class UserPreferences NativeLibrary.SetConfig("Dolphin.ini", "Core", "CPUCore", currentEmuCore); NativeLibrary.SetConfig("Dolphin.ini", "Core", "CPUThread", isUsingDualCore ? "True" : "False"); + NativeLibrary.SetConfig("Dolphin.ini", "Core", "OverclockEnable", overclockEnabled ? "True" : "False"); + NativeLibrary.SetConfig("Dolphin.ini", "Core", "Overclock", overclockSetting); + // Wiimote Extension Settings NativeLibrary.SetConfig("WiimoteNew.ini", "Wiimote1", "Extension", WiimoteExtension_4); NativeLibrary.SetConfig("WiimoteNew.ini", "Wiimote2", "Extension", WiimoteExtension_5); diff --git a/Source/Android/app/src/main/res/values/strings.xml b/Source/Android/app/src/main/res/values/strings.xml index cb27f7951e..250bc0462a 100644 --- a/Source/Android/app/src/main/res/values/strings.xml +++ b/Source/Android/app/src/main/res/values/strings.xml @@ -252,6 +252,10 @@ Split workload to two CPU cores instead of one. Increases speed. Fastmem Uses potentially unsafe optimizations for memory access. + Override Emulated CPU Clock Speed + Higher values can make variable-framerate games run at a higher framerate, requiring a powerful device. Lower values make games run at a lower framerate, increasing emulation speed, but reducing the emulated console\'s performance. + Emulated CPU Clock Speed + WARNING: Changing this from the default (100%) WILL break games and cause glitches. Please do not report bugs that occur with a non-default clock. Video diff --git a/Source/Android/app/src/main/res/xml/preferences.xml b/Source/Android/app/src/main/res/xml/preferences.xml index 863cdb298b..8fb40a7c06 100644 --- a/Source/Android/app/src/main/res/xml/preferences.xml +++ b/Source/Android/app/src/main/res/xml/preferences.xml @@ -19,6 +19,21 @@ android:entries="@array/string_emu_cores" android:entryValues="@array/int_emu_cores"/> + + + +