Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a4c1ab01e6 | |||
| ded4a437cc | |||
| 447a4e385e | |||
| 776ff4f4aa | |||
| 318331a21e |
@@ -1,6 +1,6 @@
|
||||
# NESLite
|
||||
|
||||
NESLite 是一个面向 Android 的轻量 NES/FC 模拟器前端。当前版本为 1.0.0,内置固定提交的
|
||||
NESLite 是一个面向 Android 的轻量 NES/FC 模拟器前端。当前版本为 1.0.5,内置固定提交的
|
||||
FCEUmm 和 Nestopia,可设置默认内核,也可长按游戏单独选择,下次打开游戏时生效。两个内核的存档
|
||||
独立保留。0.9.17 对已确认哈希的“龙珠英雄”自动使用 Dendy 制式,两个内核的桌面启动与菜单检查
|
||||
通过,详见 [兼容修复记录](docs/reports/long-zhu-ying-xiong-0.9.17.md)。
|
||||
@@ -8,7 +8,7 @@ FCEUmm 和 Nestopia,可设置默认内核,也可长按游戏单独选择,
|
||||
见 [显示修复记录](docs/reports/integer-scaling-0.9.18.md)。
|
||||
|
||||
源码仓库:[shen/NESLite](http://git.m3frame.com/shen/NESLite)。安装包、源码与校验值见
|
||||
[发行版](http://git.m3frame.com/shen/NESLite/releases),首次发布说明见 [1.0.0](docs/releases/1.0.0.md)。
|
||||
[发行版](http://git.m3frame.com/shen/NESLite/releases),本次更新说明见 [1.0.5](docs/releases/1.0.5.md),首次发布说明见 [1.0.0](docs/releases/1.0.0.md)。
|
||||
用户已确认产品可发布;历史测试报告中未归档的专项证据仍保留原状态,不据此宣称所有计划测试均已执行。
|
||||
|
||||
主界面固定为横屏游戏布局:中央是 4:3 游戏容器,可切换原始像素整数缩放,左右为虚拟按键,左上角提供游戏列表、导入和
|
||||
|
||||
@@ -21,8 +21,8 @@ android {
|
||||
applicationId = "org.neslite.app"
|
||||
minSdk = 28
|
||||
targetSdk = 36
|
||||
versionCode = 1000000
|
||||
versionName = "1.0.0"
|
||||
versionCode = 1000005
|
||||
versionName = "1.0.5"
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
|
||||
ndk {
|
||||
|
||||
@@ -0,0 +1,156 @@
|
||||
package org.neslite.app
|
||||
|
||||
import android.os.SystemClock
|
||||
import androidx.test.core.app.ActivityScenario
|
||||
import androidx.test.espresso.Espresso.onView
|
||||
import androidx.test.espresso.action.ViewActions.click
|
||||
import androidx.test.espresso.action.ViewActions.scrollTo
|
||||
import androidx.test.espresso.matcher.ViewMatchers.*
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.hamcrest.Matchers.allOf
|
||||
import org.json.JSONObject
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.neslite.app.input.RoutedInputState
|
||||
import org.neslite.app.library.GameEntity
|
||||
import org.neslite.app.settings.AppSettingsStore
|
||||
import java.io.File
|
||||
import java.security.MessageDigest
|
||||
|
||||
/** Uses a tiny, self-authored NROM loop; no commercial ROM or device controller is required. */
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class ButtonStateFlowTest {
|
||||
@Test fun pauseShortcutInSettingsCannotResumeBehindTheMenu() = withGame { scenario ->
|
||||
onView(withContentDescription("设置")).perform(click())
|
||||
await(scenario) { field(it, "lastSessionState") == "Paused" && field(it, "pendingSessionCommand") == null }
|
||||
pauseShortcut(scenario)
|
||||
scenario.onActivity {
|
||||
assertEquals("Paused", field(it, "lastSessionState"))
|
||||
assertNull(field(it, "pendingSessionCommand"))
|
||||
}
|
||||
pauseShortcut(scenario) // Paused gameplay opens the pause menu.
|
||||
await(scenario) { field(it, "currentOverlayPage").toString() == "PAUSE_MENU" }
|
||||
onView(allOf(withText("继续"), isDisplayed())).perform(click())
|
||||
await(scenario) { field(it, "lastSessionState") == "Running" && field(it, "pendingSessionCommand") == null }
|
||||
}
|
||||
|
||||
@Test fun saveResetLoadAndExitCancelRemainInTheCorrectState() = withGame { scenario ->
|
||||
pauseShortcut(scenario)
|
||||
await(scenario) { field(it, "currentOverlayPage").toString() == "PAUSE_MENU" && field(it, "pendingSessionCommand") == null }
|
||||
onView(allOf(withText("保存 1"), withEffectiveVisibility(Visibility.VISIBLE))).perform(scrollTo(), click())
|
||||
await(scenario) { field(it, "pendingSessionCommand") == null }
|
||||
assertTrue(JSONObject(NativeBridge.sessionStatus()).getString("operationCompletion").endsWith(":state_saved"))
|
||||
onView(allOf(withText("重置游戏"), withEffectiveVisibility(Visibility.VISIBLE))).perform(scrollTo(), click())
|
||||
await(scenario) { field(it, "pendingSessionCommand") == null }
|
||||
onView(allOf(withText("读取 1"), withEffectiveVisibility(Visibility.VISIBLE))).perform(scrollTo(), click())
|
||||
await(scenario) { field(it, "pendingSessionCommand") == null }
|
||||
assertTrue(JSONObject(NativeBridge.sessionStatus()).getString("operationCompletion").endsWith(":state_loaded"))
|
||||
scenario.onActivity { activity ->
|
||||
val menu = field(activity, "pauseMenu") as android.view.ViewGroup
|
||||
(0 until menu.childCount).map { menu.getChildAt(it) }.filterIsInstance<android.widget.Button>()
|
||||
.single { it.text == "退出游戏" }.performClick()
|
||||
}
|
||||
onView(withText("取消")).perform(click())
|
||||
scenario.onActivity {
|
||||
assertEquals("Paused", field(it, "lastSessionState"))
|
||||
assertNull(field(it, "exitDestination"))
|
||||
}
|
||||
onView(allOf(withText("继续"), withEffectiveVisibility(Visibility.VISIBLE))).perform(scrollTo(), click())
|
||||
await(scenario) { field(it, "lastSessionState") == "Running" && field(it, "pendingSessionCommand") == null }
|
||||
}
|
||||
|
||||
@Test fun repeatedSaveAndResumeAreRejectedUntilAcknowledged() = withGame { scenario ->
|
||||
pauseShortcut(scenario)
|
||||
await(scenario) { field(it, "lastSessionState") == "Paused" && field(it, "pendingSessionCommand") == null }
|
||||
scenario.onActivity {
|
||||
val send = MainActivity::class.java.getDeclaredMethod("sendControlCommand", String::class.java).apply { isAccessible = true }
|
||||
assertEquals(true, send.invoke(it, "state_save:0"))
|
||||
assertEquals(false, send.invoke(it, "state_save:0"))
|
||||
assertEquals(false, send.invoke(it, "run"))
|
||||
assertEquals(false, send.invoke(it, "stop"))
|
||||
}
|
||||
await(scenario) { field(it, "pendingSessionCommand") == null }
|
||||
scenario.onActivity { assertEquals("Paused", field(it, "lastSessionState")) }
|
||||
}
|
||||
|
||||
@Test fun resettingWhileHoldingButtonsClearsHeldInputAndFastForward() = withGame { scenario ->
|
||||
scenario.onActivity {
|
||||
val input = MainActivity::class.java.getDeclaredMethod("handleVirtualInput", Int::class.javaPrimitiveType,
|
||||
org.neslite.app.input.GameAction::class.java, Boolean::class.javaPrimitiveType).apply { isAccessible = true }
|
||||
input.invoke(it, 1, org.neslite.app.input.GameAction.NES_A, true)
|
||||
input.invoke(it, 2, org.neslite.app.input.GameAction.FAST_FORWARD, true)
|
||||
val send = MainActivity::class.java.getDeclaredMethod("sendControlCommand", String::class.java).apply { isAccessible = true }
|
||||
assertEquals(true, send.invoke(it, "reset"))
|
||||
input.invoke(it, 1, org.neslite.app.input.GameAction.NES_A, false)
|
||||
input.invoke(it, 2, org.neslite.app.input.GameAction.FAST_FORWARD, false)
|
||||
val router = field(it, "inputRouter") as org.neslite.app.input.InputRouter
|
||||
assertEquals(0, router.current().joypadMask)
|
||||
}
|
||||
await(scenario) { field(it, "pendingSessionCommand") == null }
|
||||
val status = JSONObject(NativeBridge.sessionStatus())
|
||||
assertFalse(status.getBoolean("fastForward"))
|
||||
assertEquals(0, status.getJSONObject("input").getInt("baseMask"))
|
||||
}
|
||||
|
||||
private fun pauseShortcut(scenario: ActivityScenario<MainActivity>) = scenario.onActivity {
|
||||
MainActivity::class.java.getDeclaredMethod("applyRoutedInput", RoutedInputState::class.java)
|
||||
.apply { isAccessible = true }.invoke(it, RoutedInputState(0, 0, pauseMenuEdge = true))
|
||||
}
|
||||
|
||||
private fun field(activity: MainActivity, name: String): Any? =
|
||||
MainActivity::class.java.getDeclaredField(name).apply { isAccessible = true }.get(activity)
|
||||
|
||||
private fun await(scenario: ActivityScenario<MainActivity>, condition: (MainActivity) -> Boolean) {
|
||||
val deadline = SystemClock.uptimeMillis() + 10000
|
||||
while (SystemClock.uptimeMillis() < deadline) {
|
||||
var ready = false
|
||||
scenario.onActivity { ready = condition(it) }
|
||||
if (ready) return
|
||||
SystemClock.sleep(30)
|
||||
}
|
||||
fail("Timed out waiting for button/session state")
|
||||
}
|
||||
|
||||
private fun withGame(test: (ActivityScenario<MainActivity>) -> Unit) {
|
||||
val context = InstrumentationRegistry.getInstrumentation().targetContext
|
||||
val settings = AppSettingsStore(context)
|
||||
val previous = runBlocking { settings.load() }
|
||||
runBlocking { settings.save(previous.copy(guideCompleted = true)) }
|
||||
// SEI; JMP $8001. NMI/reset/IRQ vectors all point to $8000.
|
||||
val rom = ByteArray(16 + 16384 + 8192)
|
||||
byteArrayOf(0x4e, 0x45, 0x53, 0x1a, 1, 1).copyInto(rom)
|
||||
byteArrayOf(0x78, 0x4c, 0x01, 0x80.toByte()).copyInto(rom, 16)
|
||||
for (offset in listOf(0x3ffa, 0x3ffc, 0x3ffe)) rom[16 + offset + 1] = 0x80.toByte()
|
||||
val hash = MessageDigest.getInstance("SHA-256").digest(rom).joinToString("") { "%02x".format(it) }
|
||||
val directory = File(context.filesDir, "roms").apply { mkdirs() }
|
||||
val file = File(directory, "button-flow-fixture.nes").apply { writeBytes(rom) }
|
||||
val game = GameEntity(hash, "Button state fixture", rom.size.toLong(), "iNES", file.name,
|
||||
GameEntity.STATUS_READY, 0, false, false, 0)
|
||||
try {
|
||||
ActivityScenario.launch(MainActivity::class.java).use { scenario ->
|
||||
await(scenario) { field(it, "corePreferencesReady") == true && it.hasWindowFocus() }
|
||||
scenario.onActivity {
|
||||
MainActivity::class.java.getDeclaredMethod("loadGame", GameEntity::class.java)
|
||||
.apply { isAccessible = true }.invoke(it, game)
|
||||
}
|
||||
await(scenario) { field(it, "lastSessionState") == "Running" && field(it, "pendingSessionCommand") == null }
|
||||
try { test(scenario) } finally {
|
||||
val status = JSONObject(NativeBridge.sessionStatus())
|
||||
val id = status.optLong("sessionId")
|
||||
if (id != 0L && status.optString("state") != "Idle") {
|
||||
NativeBridge.command(id, "stop")
|
||||
val deadline = SystemClock.uptimeMillis() + 10000
|
||||
while (JSONObject(NativeBridge.sessionStatus()).optString("state") != "Idle" &&
|
||||
SystemClock.uptimeMillis() < deadline) SystemClock.sleep(50)
|
||||
}
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
file.delete()
|
||||
runBlocking { settings.save(previous) }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
package org.neslite.app
|
||||
|
||||
import android.os.SystemClock
|
||||
import androidx.test.core.app.ActivityScenario
|
||||
import androidx.test.espresso.Espresso.onView
|
||||
import androidx.test.espresso.NoMatchingViewException
|
||||
import androidx.test.espresso.action.ViewActions.click
|
||||
import androidx.test.espresso.action.ViewActions.scrollTo
|
||||
import androidx.test.espresso.assertion.ViewAssertions.matches
|
||||
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
|
||||
import androidx.test.espresso.matcher.ViewMatchers.isEnabled
|
||||
import androidx.test.espresso.matcher.ViewMatchers.withContentDescription
|
||||
import androidx.test.espresso.matcher.ViewMatchers.withText
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.withTimeout
|
||||
import org.junit.Assume.assumeTrue
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.neslite.app.diagnostics.DeviceDiagnostics
|
||||
import org.neslite.app.settings.AppSettingsStore
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class ButtonSwapSettingsTest {
|
||||
@Test
|
||||
fun noControllerCanSwapPersistReopenAndResetScreenButtons() {
|
||||
assumeTrue("Disconnect external controllers for this test", DeviceDiagnostics.controllerDeviceIds().isEmpty())
|
||||
val store = AppSettingsStore(InstrumentationRegistry.getInstrumentation().targetContext)
|
||||
val previous = runBlocking { store.load() }
|
||||
runBlocking { store.save(previous.copy(guideCompleted = true, virtualSwapAB = false, virtualSwapXY = false)) }
|
||||
try {
|
||||
ActivityScenario.launch(MainActivity::class.java).use { scenario ->
|
||||
openSwaps()
|
||||
awaitButton("交换 X/Y 按键:关")
|
||||
awaitButton("交换 A/B 按键:关")
|
||||
onView(withText("交换 X/Y 按键:关")).perform(click())
|
||||
onView(withText("交换 A/B 按键:关")).perform(click())
|
||||
awaitSaved(store, swapAB = true, swapXY = true)
|
||||
onView(withText("交换 A/B 按键:开")).perform(click())
|
||||
awaitSaved(store, swapAB = false, swapXY = true)
|
||||
|
||||
scenario.recreate()
|
||||
openSwaps()
|
||||
awaitButton("交换 X/Y 按键:开")
|
||||
awaitButton("交换 A/B 按键:关")
|
||||
onView(withText("恢复屏幕按键默认顺序")).perform(scrollTo(), click())
|
||||
awaitSaved(store, swapAB = false, swapXY = false)
|
||||
awaitButton("交换 X/Y 按键:关")
|
||||
awaitButton("交换 A/B 按键:关")
|
||||
}
|
||||
} finally {
|
||||
runBlocking { store.save(previous) }
|
||||
}
|
||||
}
|
||||
|
||||
private fun openSwaps() {
|
||||
onView(withContentDescription("设置")).perform(click())
|
||||
onView(withText("交换 X/Y、A/B 按键与手动映射")).perform(scrollTo(), click())
|
||||
}
|
||||
|
||||
private fun awaitButton(label: String) {
|
||||
val deadline = SystemClock.uptimeMillis() + 5000L
|
||||
while (true) {
|
||||
try {
|
||||
onView(withText(label)).check(matches(isDisplayed())).check(matches(isEnabled()))
|
||||
return
|
||||
} catch (failure: NoMatchingViewException) {
|
||||
if (SystemClock.uptimeMillis() >= deadline) throw failure
|
||||
} catch (failure: AssertionError) {
|
||||
if (SystemClock.uptimeMillis() >= deadline) throw failure
|
||||
}
|
||||
SystemClock.sleep(50L)
|
||||
}
|
||||
}
|
||||
|
||||
private fun awaitSaved(store: AppSettingsStore, swapAB: Boolean, swapXY: Boolean) = runBlocking {
|
||||
withTimeout(5000L) {
|
||||
while (true) {
|
||||
val settings = store.load()
|
||||
if (settings.virtualSwapAB == swapAB && settings.virtualSwapXY == swapXY) break
|
||||
delay(50L)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
package org.neslite.app
|
||||
|
||||
import android.os.SystemClock
|
||||
import android.view.MotionEvent
|
||||
import org.junit.Assert.assertEquals
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.test.core.app.ActivityScenario
|
||||
import androidx.test.espresso.Espresso.onView
|
||||
import androidx.test.espresso.action.ViewActions.click
|
||||
import androidx.test.espresso.action.ViewActions.scrollTo
|
||||
import androidx.test.espresso.assertion.ViewAssertions.matches
|
||||
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
|
||||
import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility
|
||||
import androidx.test.espresso.matcher.ViewMatchers.Visibility
|
||||
import androidx.test.espresso.matcher.ViewMatchers.withContentDescription
|
||||
import androidx.test.espresso.matcher.ViewMatchers.withText
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.withTimeout
|
||||
import org.hamcrest.Matchers.allOf
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.neslite.app.settings.AppSettingsStore
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class ExitControlsTest {
|
||||
@Test
|
||||
fun gameExitWithNoSessionOpensLibraryAndApplicationExitClosesTask() = withPreparedSettings {
|
||||
ActivityScenario.launch(MainActivity::class.java).use { scenario ->
|
||||
scenario.onActivity { activity ->
|
||||
val view = MainActivity::class.java.getDeclaredField("virtualGamepad").apply { isAccessible = true }
|
||||
.get(activity) as VirtualGamepadView
|
||||
val geometry = VirtualGamepadView::class.java.getDeclaredMethod("geometry").apply { isAccessible = true }
|
||||
.invoke(view) as VirtualGamepadGeometry
|
||||
touch(view, MotionEvent.ACTION_DOWN, geometry.exit.x, geometry.exit.y)
|
||||
touch(view, MotionEvent.ACTION_UP, geometry.exit.x, geometry.exit.y)
|
||||
}
|
||||
onView(allOf(withText("游戏列表"), isDisplayed())).check(matches(isDisplayed()))
|
||||
onView(allOf(withText("退出应用"), isDisplayed())).perform(click())
|
||||
awaitDestroyed(scenario)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun settingsOffersApplicationExitWithoutAnActiveGame() = withPreparedSettings {
|
||||
ActivityScenario.launch(MainActivity::class.java).use { scenario ->
|
||||
onView(withContentDescription("设置")).perform(click())
|
||||
onView(allOf(withText("退出应用"), withEffectiveVisibility(Visibility.VISIBLE))).perform(scrollTo(), click())
|
||||
awaitDestroyed(scenario)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun exitRequiresATapAndDoesNotFireFromSlidingOrCancelledTouches() {
|
||||
val instrumentation = InstrumentationRegistry.getInstrumentation()
|
||||
instrumentation.runOnMainSync {
|
||||
var exits = 0
|
||||
val view = VirtualGamepadView(instrumentation.targetContext, { _, _, _ -> }, {}, { exits++ })
|
||||
view.layout(0, 0, 2760, 1256)
|
||||
val geometry = VirtualGamepadView::class.java.getDeclaredMethod("geometry").apply { isAccessible = true }
|
||||
.invoke(view) as VirtualGamepadGeometry
|
||||
val x = geometry.exit.x
|
||||
val y = geometry.exit.y
|
||||
touch(view, MotionEvent.ACTION_DOWN, x, y)
|
||||
assertEquals(0, exits)
|
||||
touch(view, MotionEvent.ACTION_UP, x, y)
|
||||
assertEquals(1, exits)
|
||||
touch(view, MotionEvent.ACTION_DOWN, x, y)
|
||||
touch(view, MotionEvent.ACTION_MOVE, x, y + geometry.exit.radius * 4)
|
||||
touch(view, MotionEvent.ACTION_UP, x, y)
|
||||
touch(view, MotionEvent.ACTION_DOWN, x, y)
|
||||
touch(view, MotionEvent.ACTION_CANCEL, x, y)
|
||||
touch(view, MotionEvent.ACTION_UP, x, y)
|
||||
touch(view, MotionEvent.ACTION_DOWN, geometry.faceA.x, geometry.faceA.y)
|
||||
touch(view, MotionEvent.ACTION_MOVE, x, y)
|
||||
touch(view, MotionEvent.ACTION_UP, x, y)
|
||||
assertEquals(1, exits)
|
||||
}
|
||||
}
|
||||
|
||||
private fun touch(view: VirtualGamepadView, action: Int, x: Float, y: Float) {
|
||||
val now = SystemClock.uptimeMillis()
|
||||
MotionEvent.obtain(now, now, action, x, y, 0).let { event ->
|
||||
try { view.onTouchEvent(event) } finally { event.recycle() }
|
||||
}
|
||||
}
|
||||
|
||||
private fun awaitDestroyed(scenario: ActivityScenario<MainActivity>) = runBlocking {
|
||||
withTimeout(5000L) {
|
||||
while (scenario.state != Lifecycle.State.DESTROYED) delay(50L)
|
||||
}
|
||||
}
|
||||
|
||||
private fun withPreparedSettings(test: () -> Unit) {
|
||||
val store = AppSettingsStore(InstrumentationRegistry.getInstrumentation().targetContext)
|
||||
val previous = runBlocking { store.load() }
|
||||
runBlocking { store.save(previous.copy(guideCompleted = true)) }
|
||||
try { test() } finally { runBlocking { store.save(previous) } }
|
||||
}
|
||||
}
|
||||
@@ -55,6 +55,14 @@ if(ANDROID)
|
||||
add_dependencies(neslite_jni neslite_nestopia)
|
||||
else()
|
||||
enable_testing()
|
||||
add_executable(neslite_operation_completion_test tests/operation_completion_test.cpp session_rules.cpp)
|
||||
target_include_directories(neslite_operation_completion_test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
neslite_enable_strict_warnings(neslite_operation_completion_test)
|
||||
add_test(NAME neslite_operation_completion_test COMMAND neslite_operation_completion_test)
|
||||
add_executable(neslite_exit_save_test tests/exit_save_test.cpp save_policy.cpp)
|
||||
target_include_directories(neslite_exit_save_test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
neslite_enable_strict_warnings(neslite_exit_save_test)
|
||||
add_test(NAME neslite_exit_save_test COMMAND neslite_exit_save_test)
|
||||
add_executable(neslite_native_smoke_test
|
||||
tests/native_smoke_test.cpp
|
||||
${NESLITE_COMMON_SOURCES}
|
||||
|
||||
@@ -115,6 +115,8 @@ struct Host {
|
||||
std::atomic<std::uint64_t> session_id{0};
|
||||
std::uint64_t completion_id = 0;
|
||||
std::string completion;
|
||||
std::string executing_command;
|
||||
OperationCompletion operation;
|
||||
std::string error;
|
||||
std::string system_dir;
|
||||
std::string save_dir;
|
||||
@@ -173,6 +175,7 @@ struct Host {
|
||||
std::lock_guard lock(mutex);
|
||||
++completion_id;
|
||||
completion = std::to_string(id) + ":" + std::move(result);
|
||||
operation.record(completion_id, executing_command, completion);
|
||||
}
|
||||
|
||||
void fail(std::uint64_t id, std::string message) {
|
||||
@@ -234,13 +237,13 @@ struct Host {
|
||||
committed_battery_hash = sha256_hex(battery_snapshot());
|
||||
}
|
||||
|
||||
bool save_battery() {
|
||||
bool save_battery(bool ensure_committed = false) {
|
||||
auto snapshot = battery_snapshot();
|
||||
if (snapshot.empty()) return false;
|
||||
if (snapshot.empty()) return ensure_committed && core.retro_get_memory_size(RETRO_MEMORY_SAVE_RAM) == 0;
|
||||
const std::string checksum = sha256_hex(snapshot);
|
||||
const auto final_path = std::filesystem::path(save_dir) / rom_hash / "battery" / "battery.sav";
|
||||
std::error_code exists_error;
|
||||
if (checksum == committed_battery_hash && std::filesystem::is_regular_file(final_path, exists_error)) return false;
|
||||
if (!ensure_committed && checksum == committed_battery_hash && std::filesystem::is_regular_file(final_path, exists_error)) return false;
|
||||
const bool success = commit_bytes(final_path, std::move(snapshot)) == CommitResult::Committed;
|
||||
if (success) committed_battery_hash = checksum;
|
||||
return success;
|
||||
@@ -507,7 +510,7 @@ struct Host {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool unload() {
|
||||
bool unload(bool persist = true) {
|
||||
timing.transition(TimingMode::Paused, monotonic_now_ns());
|
||||
fast_forward = false;
|
||||
audio.set_fast_muted(false);
|
||||
@@ -516,9 +519,11 @@ struct Host {
|
||||
resampler.reset();
|
||||
bool battery_saved = false;
|
||||
if (loaded) {
|
||||
battery_saved = save_battery();
|
||||
(void)save_auto_point();
|
||||
(void)write_session_marker(false);
|
||||
if (persist) {
|
||||
battery_saved = save_battery();
|
||||
(void)save_auto_point();
|
||||
(void)write_session_marker(false);
|
||||
}
|
||||
core.retro_unload_game();
|
||||
loaded = false;
|
||||
}
|
||||
@@ -641,6 +646,7 @@ struct Host {
|
||||
}
|
||||
|
||||
bool handle(Command command) {
|
||||
executing_command = command.name;
|
||||
if (command.name == "shutdown") {
|
||||
unload();
|
||||
return false;
|
||||
@@ -750,9 +756,33 @@ struct Host {
|
||||
} else if (command.name == "stop" && (loaded || state == SessionState::Error) &&
|
||||
command_allowed(state.load(), command.name)) {
|
||||
set_state(SessionState::Stopping);
|
||||
const bool battery_saved = unload();
|
||||
timing.transition(TimingMode::Paused, monotonic_now_ns());
|
||||
fast_forward = false;
|
||||
audio.set_fast_muted(false);
|
||||
audio.stop();
|
||||
joypad.store(0, std::memory_order_relaxed);
|
||||
turbo.store(0, std::memory_order_relaxed);
|
||||
effective_joypad.store(0, std::memory_order_relaxed);
|
||||
error.clear();
|
||||
const bool had_game = loaded;
|
||||
if (loaded) {
|
||||
const auto saved = commit_exit_saves(
|
||||
[this] { return save_battery(true); },
|
||||
[this] { return save_auto_point(); },
|
||||
[this] { return write_session_marker(false); });
|
||||
if (saved != ExitSaveResult::Committed) {
|
||||
error = saved == ExitSaveResult::BatteryFailed ? "Exit battery save failed" :
|
||||
saved == ExitSaveResult::AutoStateFailed ? "Exit auto state save failed" :
|
||||
"Exit session marker commit failed";
|
||||
// Keep the core and ROM alive so saving can be retried.
|
||||
set_state(SessionState::Paused);
|
||||
complete(active_id, "stop_save_failed");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
(void)unload(false);
|
||||
set_state(SessionState::Idle);
|
||||
complete(active_id, battery_saved ? "stopped_saved" : "stopped");
|
||||
complete(active_id, had_game ? "stopped_saved" : "stopped");
|
||||
} else {
|
||||
complete(command.session_id, "ignored");
|
||||
}
|
||||
@@ -1033,6 +1063,9 @@ std::string session_status_json() {
|
||||
<< ",\"compatibilityProfile\":\"" << compatibility_profile_name(host.compatibility.load()) << "\""
|
||||
<< ",\"state\":\"" << session_state_name(host.state.load(std::memory_order_acquire))
|
||||
<< "\",\"queueDepth\":" << host.commands.size()
|
||||
<< ",\"operationCompletionId\":" << host.operation.id
|
||||
<< ",\"operationCommand\":\"" << json_escape(host.operation.command) << "\""
|
||||
<< ",\"operationCompletion\":\"" << json_escape(host.operation.result) << "\""
|
||||
<< ",\"completionId\":" << host.completion_id
|
||||
<< ",\"completion\":\"" << json_escape(host.completion)
|
||||
<< "\",\"error\":\"" << json_escape(host.error)
|
||||
|
||||
@@ -4,6 +4,15 @@
|
||||
|
||||
namespace neslite {
|
||||
|
||||
ExitSaveResult commit_exit_saves(const std::function<bool()>& battery,
|
||||
const std::function<bool()>& auto_state,
|
||||
const std::function<bool()>& closed_marker) {
|
||||
if (!battery()) return ExitSaveResult::BatteryFailed;
|
||||
if (!auto_state()) return ExitSaveResult::AutoStateFailed;
|
||||
if (!closed_marker()) return ExitSaveResult::MarkerFailed;
|
||||
return ExitSaveResult::Committed;
|
||||
}
|
||||
|
||||
SaveSchedule::SaveSchedule(double battery_interval_seconds, double auto_interval_seconds)
|
||||
: battery_interval_(std::max(0.001, battery_interval_seconds)),
|
||||
auto_interval_(std::max(0.001, auto_interval_seconds)) {}
|
||||
|
||||
@@ -1,9 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <functional>
|
||||
|
||||
namespace neslite {
|
||||
|
||||
enum class ExitSaveResult { Committed, BatteryFailed, AutoStateFailed, MarkerFailed };
|
||||
|
||||
// Close the session marker only after both forms of progress are durable.
|
||||
ExitSaveResult commit_exit_saves(const std::function<bool()>& battery,
|
||||
const std::function<bool()>& auto_state,
|
||||
const std::function<bool()>& closed_marker);
|
||||
|
||||
class SaveSchedule {
|
||||
public:
|
||||
SaveSchedule(double battery_interval_seconds, double auto_interval_seconds);
|
||||
|
||||
@@ -18,6 +18,20 @@ const char* session_state_name(SessionState state) {
|
||||
return "Error";
|
||||
}
|
||||
|
||||
bool is_session_operation(std::string_view command) {
|
||||
return command == "load" || command == "run" || command == "pause" || command == "stop" ||
|
||||
command == "reset" || command == "audio_rebuild" || command == "package_export" ||
|
||||
command == "package_import" || command.starts_with("state_save:") ||
|
||||
command.starts_with("state_load:") || command.starts_with("auto_load:");
|
||||
}
|
||||
|
||||
void OperationCompletion::record(std::uint64_t completion_id, std::string_view name, const std::string& value) {
|
||||
if (!is_session_operation(name)) return;
|
||||
id = completion_id;
|
||||
command = name;
|
||||
result = value;
|
||||
}
|
||||
|
||||
bool command_allowed(SessionState state, std::string_view command) {
|
||||
if (command == "load") return state != SessionState::Loading && state != SessionState::Stopping;
|
||||
if (command == "run") return state == SessionState::Paused;
|
||||
|
||||
@@ -3,12 +3,23 @@
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <string_view>
|
||||
#include <string>
|
||||
|
||||
namespace neslite {
|
||||
|
||||
enum class SessionState { Idle, Loading, Paused, Running, Pausing, Stopping, Error };
|
||||
|
||||
const char* session_state_name(SessionState state);
|
||||
bool is_session_operation(std::string_view command);
|
||||
// Settings and input acknowledgements must not erase a save/transition result
|
||||
// before the UI's next status poll. The caller serializes access.
|
||||
struct OperationCompletion {
|
||||
std::uint64_t id = 0;
|
||||
std::string command;
|
||||
std::string result;
|
||||
void record(std::uint64_t completion_id, std::string_view name, const std::string& value);
|
||||
};
|
||||
|
||||
bool command_allowed(SessionState state, std::string_view command);
|
||||
bool command_targets_active_session(std::uint64_t active_session, std::uint64_t command_session);
|
||||
bool required_host_capabilities_available(unsigned core_api_version, unsigned expected_api_version,
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
#include "save_policy.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
int main() {
|
||||
using neslite::ExitSaveResult;
|
||||
for (int failure = 0; failure <= 3; ++failure) {
|
||||
std::vector<int> writes;
|
||||
bool closed = false;
|
||||
const auto result = neslite::commit_exit_saves(
|
||||
[&] { writes.push_back(1); return failure != 1; },
|
||||
[&] { writes.push_back(2); return failure != 2; },
|
||||
[&] { writes.push_back(3); closed = failure != 3; return closed; });
|
||||
const auto expected = failure == 0 ? ExitSaveResult::Committed :
|
||||
failure == 1 ? ExitSaveResult::BatteryFailed :
|
||||
failure == 2 ? ExitSaveResult::AutoStateFailed : ExitSaveResult::MarkerFailed;
|
||||
if (result != expected || closed != (failure == 0)) return 1;
|
||||
const std::vector<int> expected_writes = failure == 1 ? std::vector<int>{1} :
|
||||
failure == 2 ? std::vector<int>{1, 2} : std::vector<int>{1, 2, 3};
|
||||
if (writes != expected_writes) return 2;
|
||||
// Retrying after any failure must complete all writes before declaring the session closed.
|
||||
writes.clear();
|
||||
const auto retry = neslite::commit_exit_saves(
|
||||
[&] { writes.push_back(1); return true; },
|
||||
[&] { writes.push_back(2); return true; },
|
||||
[&] { writes.push_back(3); closed = true; return true; });
|
||||
if (retry != ExitSaveResult::Committed || !closed || writes != std::vector<int>{1, 2, 3}) return 3;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
#include "session_rules.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
int main() {
|
||||
neslite::OperationCompletion completion;
|
||||
const std::vector<std::string> operations{"load", "run", "pause", "stop", "reset", "audio_rebuild",
|
||||
"state_save:0", "state_load:9", "auto_load:2", "package_export", "package_import"};
|
||||
std::uint64_t sequence = 0;
|
||||
for (const auto& command : operations) {
|
||||
const auto expected_id = ++sequence;
|
||||
completion.record(expected_id, command, "7:finished");
|
||||
for (const auto& noise : {"volume:0.5", "mute:on", "mute:off", "fast:on", "fast:off"}) {
|
||||
completion.record(++sequence, noise, "7:ignored");
|
||||
if (completion.id != expected_id || completion.command != command || completion.result != "7:finished") return 1;
|
||||
}
|
||||
}
|
||||
completion.record(++sequence, "stop", "7:stop_save_failed");
|
||||
completion.record(++sequence, "volume:1", "7:volume");
|
||||
if (completion.result != "7:stop_save_failed") return 2;
|
||||
completion.record(++sequence, "stop", "7:stopped_saved");
|
||||
if (completion.id != sequence || completion.result != "7:stopped_saved") return 3;
|
||||
return 0;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -20,6 +20,7 @@ internal data class VirtualGamepadGeometry(
|
||||
val start: VirtualControl,
|
||||
val pause: VirtualControl,
|
||||
val reset: VirtualControl,
|
||||
val exit: VirtualControl,
|
||||
)
|
||||
|
||||
internal fun computeVirtualGamepadGeometry(
|
||||
@@ -32,6 +33,8 @@ internal fun computeVirtualGamepadGeometry(
|
||||
dpadScale: Float = 1f,
|
||||
dpadHorizontalOffset: Float = 0f,
|
||||
dpadVerticalOffset: Float = 0f,
|
||||
swapAB: Boolean = false,
|
||||
swapXY: Boolean = false,
|
||||
): VirtualGamepadGeometry {
|
||||
val w = width.coerceAtLeast(1f)
|
||||
val h = height.coerceAtLeast(1f)
|
||||
@@ -57,8 +60,11 @@ internal fun computeVirtualGamepadGeometry(
|
||||
val expandedRightWidth = (w - rightInset - baseGameRight).coerceAtLeast(1f)
|
||||
val faceX = baseGameRight + expandedRightWidth * 0.50f
|
||||
val faceGapX = min(faceRadius * 1.70f, expandedRightWidth * 0.50f - faceRadius)
|
||||
val baseResetX = w - rightInset - sideWidth * 0.28f - horizontalShift
|
||||
val rightmostControl = maxOf(faceX + faceGapX + faceRadius, baseResetX + utilityRadius)
|
||||
val utilityGapX = expandedRightWidth / 3f
|
||||
val rightmostControl = maxOf(
|
||||
faceX + faceGapX + faceRadius,
|
||||
faceX + utilityGapX + utilityRadius * 1.14f,
|
||||
)
|
||||
val shift = screenShift.coerceIn(0f, (w - rightmostControl - edgeGap).coerceAtLeast(0f))
|
||||
val gameLeft = baseGameLeft + shift
|
||||
val gameRight = baseGameRight + shift
|
||||
@@ -94,7 +100,17 @@ internal fun computeVirtualGamepadGeometry(
|
||||
h * 0.89f,
|
||||
menuRadius,
|
||||
),
|
||||
pause = VirtualControl(w - rightInset - sideWidth * 0.72f - horizontalShift + shift, h * 0.13f, utilityRadius),
|
||||
reset = VirtualControl(baseResetX + shift, h * 0.13f, utilityRadius),
|
||||
)
|
||||
// Keep all three utility buttons inside the same right-side area as ABXY.
|
||||
pause = VirtualControl(faceX - utilityGapX + shift, h * 0.13f, utilityRadius),
|
||||
reset = VirtualControl(faceX + shift, h * 0.13f, utilityRadius),
|
||||
exit = VirtualControl(faceX + utilityGapX + shift, h * 0.13f, utilityRadius),
|
||||
).let { geometry ->
|
||||
// Drawing, pressed feedback and touch hit testing all use these same controls.
|
||||
geometry.copy(
|
||||
faceA = if (swapAB) geometry.faceB else geometry.faceA,
|
||||
faceB = if (swapAB) geometry.faceA else geometry.faceB,
|
||||
faceX = if (swapXY) geometry.faceY else geometry.faceX,
|
||||
faceY = if (swapXY) geometry.faceX else geometry.faceY,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,11 +20,13 @@ class VirtualGamepadView(
|
||||
context: Context,
|
||||
private val onTransition: (pointerId: Int, action: GameAction, pressed: Boolean) -> Unit,
|
||||
private val onReset: () -> Unit,
|
||||
private val onExit: () -> Unit = {},
|
||||
private val onHorizontalShiftChanged: (Float) -> Unit = {},
|
||||
) : View(context) {
|
||||
private val tracker = VirtualInputTracker()
|
||||
private val dpadResolver = VirtualDpadResolver()
|
||||
private val resetPointers = mutableSetOf<Int>()
|
||||
private val exitPointers = mutableMapOf<Int, Boolean>()
|
||||
private val resetRunnables = mutableMapOf<Int, Runnable>()
|
||||
private val fill = Paint(Paint.ANTI_ALIAS_FLAG).apply { color = Color.argb(145, 45, 52, 64) }
|
||||
private val turboFill = Paint(Paint.ANTI_ALIAS_FLAG).apply { color = Color.argb(150, 65, 79, 99) }
|
||||
@@ -47,6 +49,8 @@ class VirtualGamepadView(
|
||||
private var safeLeft = 0f
|
||||
private var safeRight = 0f
|
||||
private var screenShift = 0f
|
||||
private var swapAB = false
|
||||
private var swapXY = false
|
||||
private var directionMode = DirectionMode.EIGHT_WAY
|
||||
private var dpadScale = 1.18f
|
||||
private var dpadHorizontalOffset = 0f
|
||||
@@ -54,7 +58,7 @@ class VirtualGamepadView(
|
||||
|
||||
init {
|
||||
isFocusable = true
|
||||
contentDescription = "屏幕虚拟手柄:方向、A、B、X、Y、Start、Select、暂停和重置"
|
||||
contentDescription = "屏幕虚拟手柄:方向、A、B、X、Y、Start、Select、暂停、重置和退出"
|
||||
}
|
||||
|
||||
override fun onDraw(canvas: Canvas) {
|
||||
@@ -70,6 +74,7 @@ class VirtualGamepadView(
|
||||
drawControl(canvas, geometry.start, "Start", compact = true, isPressed = GameAction.START in pressed)
|
||||
drawControl(canvas, geometry.pause, "暂停", compact = true, isPressed = GameAction.PAUSE_MENU in pressed)
|
||||
drawControl(canvas, geometry.reset, "重置", compact = true, secondary = "长按", isPressed = resetPointers.isNotEmpty())
|
||||
drawControl(canvas, geometry.exit, "退出", compact = true, isPressed = exitPointers.values.any { it })
|
||||
}
|
||||
|
||||
override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
|
||||
@@ -88,6 +93,15 @@ class VirtualGamepadView(
|
||||
invalidate()
|
||||
}
|
||||
|
||||
internal fun configureButtonSwaps(swapAB: Boolean, swapXY: Boolean) {
|
||||
if (this.swapAB == swapAB && this.swapXY == swapXY) return
|
||||
// Release touches against the old layout before changing their targets.
|
||||
clearInputs()
|
||||
this.swapAB = swapAB
|
||||
this.swapXY = swapXY
|
||||
invalidate()
|
||||
}
|
||||
|
||||
internal fun configureDpad(
|
||||
mode: DirectionMode,
|
||||
scale: Float,
|
||||
@@ -113,7 +127,9 @@ class VirtualGamepadView(
|
||||
when (event.actionMasked) {
|
||||
MotionEvent.ACTION_DOWN, MotionEvent.ACTION_POINTER_DOWN -> updatePointer(event, event.actionIndex)
|
||||
MotionEvent.ACTION_MOVE -> repeat(event.pointerCount) { updatePointer(event, it) }
|
||||
MotionEvent.ACTION_UP, MotionEvent.ACTION_POINTER_UP -> releasePointer(event.getPointerId(event.actionIndex))
|
||||
MotionEvent.ACTION_UP, MotionEvent.ACTION_POINTER_UP -> releasePointer(
|
||||
event.getPointerId(event.actionIndex), event.getX(event.actionIndex), event.getY(event.actionIndex),
|
||||
)
|
||||
MotionEvent.ACTION_CANCEL -> clearInputs()
|
||||
}
|
||||
if (event.actionMasked == MotionEvent.ACTION_UP) performClick()
|
||||
@@ -129,6 +145,7 @@ class VirtualGamepadView(
|
||||
resetRunnables.values.forEach(::removeCallbacks)
|
||||
resetRunnables.clear()
|
||||
resetPointers.clear()
|
||||
exitPointers.clear()
|
||||
emit(tracker.clear())
|
||||
invalidate()
|
||||
}
|
||||
@@ -137,6 +154,19 @@ class VirtualGamepadView(
|
||||
val pointerId = event.getPointerId(index)
|
||||
val x = event.getX(index)
|
||||
val y = event.getY(index)
|
||||
if (pointerId in exitPointers) {
|
||||
exitPointers[pointerId] = exitPointers[pointerId] == true && inside(geometry().exit, x, y)
|
||||
invalidate()
|
||||
return
|
||||
}
|
||||
val startingTouch = event.actionMasked == MotionEvent.ACTION_DOWN ||
|
||||
event.actionMasked == MotionEvent.ACTION_POINTER_DOWN
|
||||
if (startingTouch && inside(geometry().exit, x, y)) {
|
||||
exitPointers[pointerId] = true
|
||||
emit(tracker.update(pointerId, emptySet()))
|
||||
invalidate()
|
||||
return
|
||||
}
|
||||
if (inside(geometry().reset, x, y)) {
|
||||
emit(tracker.update(pointerId, emptySet()))
|
||||
beginResetHold(pointerId)
|
||||
@@ -149,9 +179,11 @@ class VirtualGamepadView(
|
||||
emit(tracker.update(pointerId, hitTestActions(pointerId, x, y)))
|
||||
}
|
||||
|
||||
private fun releasePointer(pointerId: Int) {
|
||||
private fun releasePointer(pointerId: Int, x: Float, y: Float) {
|
||||
val exitClicked = exitPointers.remove(pointerId) == true && inside(geometry().exit, x, y)
|
||||
cancelPendingReset(pointerId, keepConsumed = false)
|
||||
emit(tracker.update(pointerId, null))
|
||||
if (exitClicked) onExit()
|
||||
}
|
||||
|
||||
private fun beginResetHold(pointerId: Int) {
|
||||
@@ -285,6 +317,8 @@ class VirtualGamepadView(
|
||||
dpadScale = dpadScale,
|
||||
dpadHorizontalOffset = dpadHorizontalOffset,
|
||||
dpadVerticalOffset = dpadVerticalOffset,
|
||||
swapAB = swapAB,
|
||||
swapXY = swapXY,
|
||||
)
|
||||
|
||||
private companion object {
|
||||
|
||||
@@ -52,6 +52,7 @@ data class ControllerProfile(
|
||||
val pressThreshold: Float = 0.55f,
|
||||
val releaseThreshold: Float = 0.35f,
|
||||
val swapAB: Boolean = false,
|
||||
val swapXY: Boolean = false,
|
||||
) {
|
||||
init {
|
||||
require(pressThreshold in 0.2f..0.95f)
|
||||
@@ -78,6 +79,16 @@ data class ControllerProfile(
|
||||
},
|
||||
)
|
||||
|
||||
fun toggleXY(): ControllerProfile {
|
||||
val x = bindings[GameAction.TURBO_A].orEmpty()
|
||||
val y = bindings[GameAction.TURBO_B].orEmpty()
|
||||
return copy(
|
||||
origin = ProfileOrigin.CUSTOM,
|
||||
bindings = bindings + mapOf(GameAction.TURBO_A to y, GameAction.TURBO_B to x),
|
||||
swapXY = !swapXY,
|
||||
)
|
||||
}
|
||||
|
||||
fun toggleAB(): ControllerProfile {
|
||||
val a = bindings[GameAction.NES_A].orEmpty()
|
||||
val b = bindings[GameAction.NES_B].orEmpty()
|
||||
|
||||
@@ -13,6 +13,7 @@ object ControllerProfileJson {
|
||||
.put("pressThreshold", profile.pressThreshold.toDouble())
|
||||
.put("releaseThreshold", profile.releaseThreshold.toDouble())
|
||||
.put("swapAB", profile.swapAB)
|
||||
.put("swapXY", profile.swapXY)
|
||||
.put(
|
||||
"bindings",
|
||||
JSONObject().apply {
|
||||
@@ -50,6 +51,7 @@ object ControllerProfileJson {
|
||||
pressThreshold = root.getDouble("pressThreshold").toFloat(),
|
||||
releaseThreshold = root.getDouble("releaseThreshold").toFloat(),
|
||||
swapAB = root.getBoolean("swapAB"),
|
||||
swapXY = root.optBoolean("swapXY", false),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,6 +38,8 @@ data class AppSettings(
|
||||
val virtualDpadSize: VirtualDpadSize = VirtualDpadSize.LARGE,
|
||||
val virtualDpadHorizontalOffset: Float = 0f,
|
||||
val virtualDpadVerticalOffset: Float = 0f,
|
||||
val virtualSwapAB: Boolean = false,
|
||||
val virtualSwapXY: Boolean = false,
|
||||
val guideCompleted: Boolean = false,
|
||||
)
|
||||
|
||||
@@ -63,6 +65,8 @@ class AppSettingsStore(private val context: Context) {
|
||||
virtualDpadSize = VirtualDpadSize.fromStored(values[VIRTUAL_DPAD_SIZE] ?: VirtualDpadSize.LARGE.ordinal),
|
||||
virtualDpadHorizontalOffset = (values[VIRTUAL_DPAD_HORIZONTAL_OFFSET] ?: 0f).coerceIn(-1f, 1f),
|
||||
virtualDpadVerticalOffset = (values[VIRTUAL_DPAD_VERTICAL_OFFSET] ?: 0f).coerceIn(-1f, 1f),
|
||||
virtualSwapAB = values[VIRTUAL_SWAP_AB] ?: false,
|
||||
virtualSwapXY = values[VIRTUAL_SWAP_XY] ?: false,
|
||||
guideCompleted = values[GUIDE_COMPLETED] ?: false,
|
||||
)
|
||||
}
|
||||
@@ -80,6 +84,8 @@ class AppSettingsStore(private val context: Context) {
|
||||
values[VIRTUAL_DPAD_SIZE] = settings.virtualDpadSize.ordinal
|
||||
values[VIRTUAL_DPAD_HORIZONTAL_OFFSET] = settings.virtualDpadHorizontalOffset.coerceIn(-1f, 1f)
|
||||
values[VIRTUAL_DPAD_VERTICAL_OFFSET] = settings.virtualDpadVerticalOffset.coerceIn(-1f, 1f)
|
||||
values[VIRTUAL_SWAP_AB] = settings.virtualSwapAB
|
||||
values[VIRTUAL_SWAP_XY] = settings.virtualSwapXY
|
||||
values[GUIDE_COMPLETED] = settings.guideCompleted
|
||||
}
|
||||
}
|
||||
@@ -97,6 +103,8 @@ class AppSettingsStore(private val context: Context) {
|
||||
private val VIRTUAL_DPAD_SIZE = intPreferencesKey("virtual_dpad_size")
|
||||
private val VIRTUAL_DPAD_HORIZONTAL_OFFSET = floatPreferencesKey("virtual_dpad_horizontal_offset")
|
||||
private val VIRTUAL_DPAD_VERTICAL_OFFSET = floatPreferencesKey("virtual_dpad_vertical_offset")
|
||||
private val VIRTUAL_SWAP_AB = booleanPreferencesKey("virtual_swap_ab")
|
||||
private val VIRTUAL_SWAP_XY = booleanPreferencesKey("virtual_swap_xy")
|
||||
private val GUIDE_COMPLETED = booleanPreferencesKey("guide_completed")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,22 @@
|
||||
package org.neslite.app.system
|
||||
|
||||
enum class ExitDestination { LIBRARY, APPLICATION }
|
||||
enum class ExitRequestAction { FINISH_APPLICATION, OPEN_LIBRARY, PAUSE_THEN_CONFIRM, CONFIRM, WAIT }
|
||||
|
||||
fun exitRequestAction(
|
||||
destination: ExitDestination,
|
||||
hasSession: Boolean,
|
||||
state: String,
|
||||
pendingCommand: String?,
|
||||
exitInProgress: Boolean,
|
||||
): ExitRequestAction = when {
|
||||
exitInProgress || pendingCommand != null || state in setOf("Loading", "Pausing", "Stopping") -> ExitRequestAction.WAIT
|
||||
!hasSession -> if (destination == ExitDestination.APPLICATION) ExitRequestAction.FINISH_APPLICATION else ExitRequestAction.OPEN_LIBRARY
|
||||
state == "Running" -> ExitRequestAction.PAUSE_THEN_CONFIRM
|
||||
state in setOf("Paused", "Error") -> ExitRequestAction.CONFIRM
|
||||
else -> ExitRequestAction.WAIT
|
||||
}
|
||||
|
||||
enum class UiLayer {
|
||||
CONTROLLER_SETTINGS,
|
||||
SETTINGS,
|
||||
@@ -81,28 +98,51 @@ fun resolveLayoutSafeInsets(
|
||||
}
|
||||
|
||||
fun sessionCommandAllowed(pending: String?, command: String, state: String): Boolean {
|
||||
val transition = command in setOf("load", "run", "pause", "stop")
|
||||
if (pending == "audio_rebuild" && command == "stop") return state in setOf("Paused", "Pausing")
|
||||
if (pending != null && (transition || command in setOf("reset", "audio_rebuild"))) return false
|
||||
return when (command) {
|
||||
"load" -> state !in setOf("Loading", "Stopping")
|
||||
"run" -> state == "Paused"
|
||||
"pause" -> state == "Running"
|
||||
"stop" -> state in setOf("Paused", "Running", "Error")
|
||||
else -> true
|
||||
if (pending != null) return false
|
||||
return when {
|
||||
command == "load" -> state in setOf("Idle", "Paused", "Error")
|
||||
command == "run" -> state == "Paused"
|
||||
command == "pause" -> state == "Running"
|
||||
command == "stop" -> state in setOf("Paused", "Running", "Error")
|
||||
command == "reset" -> state in setOf("Paused", "Running")
|
||||
command == "audio_rebuild" || command.startsWith("state_save:") ||
|
||||
command.startsWith("state_load:") || command.startsWith("auto_load:") ||
|
||||
command in setOf("package_export", "package_import") -> state == "Paused"
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
||||
fun sessionTransitionSettled(pending: String?, nextState: String, completion: String): Boolean =
|
||||
// A status poll may still contain a previous command's acknowledgement. Only the
|
||||
// requested operation in the current session, completed after dispatch, can unlock UI.
|
||||
fun matchesPendingCompletion(pending: String?, baseline: Long, completionId: Long,
|
||||
command: String, completion: String, sessionId: Long): Boolean =
|
||||
pending != null && completionId > baseline && sessionId != 0L &&
|
||||
command == (if (pending == "pause_external") "pause" else pending) &&
|
||||
completion.substringBefore(':').toLongOrNull() == sessionId
|
||||
|
||||
fun shouldRunLoadedGame(requested: Boolean, foreground: Boolean, focused: Boolean,
|
||||
hasOverlay: Boolean, abnormalSession: Boolean): Boolean =
|
||||
requested && foreground && focused && !hasOverlay && !abnormalSession
|
||||
|
||||
fun sessionTransitionSettled(pending: String?, nextState: String, completion: String, error: String = ""): Boolean =
|
||||
when (pending) {
|
||||
"load" -> nextState == "Paused" || nextState == "Error"
|
||||
"pause", "pause_external" -> nextState == "Paused"
|
||||
"run" -> nextState == "Running"
|
||||
"stop" -> nextState == "Idle"
|
||||
"stop" -> nextState == "Idle" || completion.endsWith(":stop_save_failed") ||
|
||||
(nextState == "Paused" && error.startsWith("Exit ") && error.endsWith("failed"))
|
||||
"audio_rebuild" -> nextState == "Paused" &&
|
||||
(completion.endsWith(":audio_rebuilt_paused") || completion.endsWith(":audio_unavailable_paused"))
|
||||
else -> false
|
||||
} || completion.endsWith(":ignored") || completion.endsWith(":stale") || completion.endsWith(":error")
|
||||
"reset" -> completion.endsWith(":reset")
|
||||
"package_export" -> completion.endsWith(":package_exported") || completion.endsWith(":package_export_failed")
|
||||
"package_import" -> completion.endsWith(":package_imported") || completion.endsWith(":package_import_failed")
|
||||
else -> when {
|
||||
pending?.startsWith("state_save:") == true -> completion.endsWith(":state_saved") || completion.endsWith(":state_save_failed")
|
||||
pending?.startsWith("state_load:") == true -> completion.endsWith(":state_loaded") || completion.endsWith(":state_load_failed")
|
||||
pending?.startsWith("auto_load:") == true -> completion.endsWith(":auto_loaded") || completion.endsWith(":auto_load_failed")
|
||||
else -> false
|
||||
}
|
||||
} || (pending != null && (completion.endsWith(":ignored") || completion.endsWith(":stale") || completion.endsWith(":error")))
|
||||
|
||||
data class RefreshRateSample(
|
||||
val epochMs: Long,
|
||||
|
||||
@@ -7,7 +7,7 @@ class BuildIdentityTest {
|
||||
@Test
|
||||
fun debugBuildUsesTheDocumentedIdentity() {
|
||||
assertEquals("org.neslite.app.debug", BuildConfig.APPLICATION_ID)
|
||||
assertEquals("1.0.0-debug", BuildConfig.VERSION_NAME)
|
||||
assertEquals(1000000, BuildConfig.VERSION_CODE)
|
||||
assertEquals("1.0.5-debug", BuildConfig.VERSION_NAME)
|
||||
assertEquals(1000005, BuildConfig.VERSION_CODE)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,6 +58,7 @@ class VirtualGamepadLayoutTest {
|
||||
geometry.start,
|
||||
geometry.pause,
|
||||
geometry.reset,
|
||||
geometry.exit,
|
||||
)
|
||||
|
||||
assertTrue(leftControls.all { it.x + it.radius <= geometry.gameLeft })
|
||||
@@ -97,6 +98,7 @@ class VirtualGamepadLayoutTest {
|
||||
geometry.start,
|
||||
geometry.pause,
|
||||
geometry.reset,
|
||||
geometry.exit,
|
||||
)
|
||||
|
||||
assertTrue(controls.all { it.x - it.radius >= 0f && it.x + it.radius <= width })
|
||||
@@ -163,9 +165,9 @@ class VirtualGamepadLayoutTest {
|
||||
assertEquals(right.pause.radius, left.pause.radius, 0.01f)
|
||||
assertEquals(movement, left.gameLeft - right.gameLeft, 0.01f)
|
||||
val leftControls = listOf(left.up, left.down, left.left, left.right, left.select,
|
||||
left.faceX, left.faceY, left.faceA, left.faceB, left.start, left.pause, left.reset)
|
||||
left.faceX, left.faceY, left.faceA, left.faceB, left.start, left.pause, left.reset, left.exit)
|
||||
val rightControls = listOf(right.up, right.down, right.left, right.right, right.select,
|
||||
right.faceX, right.faceY, right.faceA, right.faceB, right.start, right.pause, right.reset)
|
||||
right.faceX, right.faceY, right.faceA, right.faceB, right.start, right.pause, right.reset, right.exit)
|
||||
leftControls.zip(rightControls).forEach { (shifted, original) ->
|
||||
assertEquals(movement, shifted.x - original.x, 0.01f)
|
||||
assertEquals(original.radius, shifted.radius, 0.01f)
|
||||
@@ -218,6 +220,67 @@ class VirtualGamepadLayoutTest {
|
||||
assertTrue(flipped.faceB.x + flipped.faceB.radius < 2760f)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun allSwapCombinationsMoveOnlyTheirMatchingLabeledTouchControls() {
|
||||
val original = computeVirtualGamepadGeometry(2760f, 1256f, 126f)
|
||||
for (swapAB in listOf(false, true)) {
|
||||
for (swapXY in listOf(false, true)) {
|
||||
val swapped = computeVirtualGamepadGeometry(
|
||||
2760f, 1256f, 126f, swapAB = swapAB, swapXY = swapXY,
|
||||
)
|
||||
assertEquals(if (swapAB) original.faceB else original.faceA, swapped.faceA)
|
||||
assertEquals(if (swapAB) original.faceA else original.faceB, swapped.faceB)
|
||||
assertEquals(if (swapXY) original.faceY else original.faceX, swapped.faceX)
|
||||
assertEquals(if (swapXY) original.faceX else original.faceY, swapped.faceY)
|
||||
// Every other control and the game viewport remain unchanged.
|
||||
assertEquals(original, swapped.copy(
|
||||
faceA = original.faceA, faceB = original.faceB,
|
||||
faceX = original.faceX, faceY = original.faceY,
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun swappedControlsKeepTheirPositionsAcrossDifferentInsetsAndDpadSettings() {
|
||||
for (inset in listOf(0f, 48f, 172f, 288f)) {
|
||||
val original = computeVirtualGamepadGeometry(
|
||||
2760f, 1256f, 126f, safeLeft = inset, screenShift = 47f,
|
||||
dpadScale = 1.35f, dpadHorizontalOffset = -1f, dpadVerticalOffset = 1f,
|
||||
)
|
||||
val swapped = computeVirtualGamepadGeometry(
|
||||
2760f, 1256f, 126f, safeLeft = inset, screenShift = 47f,
|
||||
dpadScale = 1.35f, dpadHorizontalOffset = -1f, dpadVerticalOffset = 1f,
|
||||
swapAB = true, swapXY = true,
|
||||
)
|
||||
assertEquals(original.faceB, swapped.faceA)
|
||||
assertEquals(original.faceA, swapped.faceB)
|
||||
assertEquals(original.faceY, swapped.faceX)
|
||||
assertEquals(original.faceX, swapped.faceY)
|
||||
assertEquals(original.horizontalShift, swapped.horizontalShift)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun utilityRowStaysOutsideViewportWithSeparateTouchTargets() {
|
||||
for ((width, height) in listOf(2760f to 1256f, 2400f to 1080f, 1920f to 1080f)) {
|
||||
for (inset in listOf(0f, 48f, 160f)) {
|
||||
val geometry = computeVirtualGamepadGeometry(width, height, 126f,
|
||||
safeLeft = inset, safeRight = inset, screenShift = 128f, dpadScale = 1.18f)
|
||||
val row = listOf(geometry.pause, geometry.reset, geometry.exit)
|
||||
row.forEach {
|
||||
assertEquals(geometry.pause.radius, it.radius, 0.01f)
|
||||
assertEquals(geometry.pause.y, it.y, 0.01f)
|
||||
assertTrue(it.x - it.radius * 1.14f >= geometry.gameRight)
|
||||
assertTrue(it.x + it.radius * 1.14f <= width)
|
||||
}
|
||||
row.zipWithNext().forEach { (left, right) ->
|
||||
assertTrue(right.x - left.x > (left.radius + right.radius) * 1.14f)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun distance(first: VirtualControl, second: VirtualControl): Float =
|
||||
hypot(first.x - second.x, first.y - second.y)
|
||||
}
|
||||
|
||||
@@ -55,6 +55,54 @@ class ControllerProfileTest {
|
||||
assertFalse(JSONObject(ControllerProfileJson.encode(swapped)).has("deviceId"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun xySwapOnlyExchangesTurboActionsAndIsReversible() {
|
||||
val original = ControllerProfileResolver().resolve(identity)
|
||||
val swapped = original.toggleXY()
|
||||
assertTrue(swapped.swapXY)
|
||||
assertFalse(swapped.swapAB)
|
||||
assertEquals(ProfileOrigin.CUSTOM, swapped.origin)
|
||||
assertEquals(setOf(GameAction.TURBO_B), swapped.actionsFor(InputBinding(BindingKind.KEY, 99)))
|
||||
assertEquals(setOf(GameAction.TURBO_A), swapped.actionsFor(InputBinding(BindingKind.KEY, 100)))
|
||||
GameAction.entries.filter { it != GameAction.TURBO_A && it != GameAction.TURBO_B }.forEach {
|
||||
assertEquals(original.bindings[it], swapped.bindings[it])
|
||||
}
|
||||
assertEquals(original.bindings, swapped.toggleXY().bindings)
|
||||
assertFalse(swapped.toggleXY().swapXY)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun bothSwapsAreIndependentAndPersistTogether() {
|
||||
val original = ControllerProfileResolver().resolve(identity)
|
||||
val swapped = original.toggleAB().toggleXY()
|
||||
assertEquals(swapped, original.toggleXY().toggleAB())
|
||||
assertEquals(setOf(GameAction.NES_B), swapped.actionsFor(InputBinding(BindingKind.KEY, 96)))
|
||||
assertEquals(setOf(GameAction.NES_A), swapped.actionsFor(InputBinding(BindingKind.KEY, 97)))
|
||||
assertEquals(swapped, ControllerProfileJson.decode(ControllerProfileJson.encode(swapped)))
|
||||
val xyOnly = swapped.toggleAB()
|
||||
assertFalse(xyOnly.swapAB)
|
||||
assertTrue(xyOnly.swapXY)
|
||||
assertEquals(original.bindings, xyOnly.toggleXY().bindings)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun legacyProfileWithoutXyFlagKeepsSavedBindings() {
|
||||
val original = ControllerProfileResolver().resolve(identity).toggleAB()
|
||||
val legacy = JSONObject(ControllerProfileJson.encode(original)).apply { remove("swapXY") }
|
||||
assertEquals(original, ControllerProfileJson.decode(legacy.toString()))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun xySwapPreservesCustomAndEmptyBindings() {
|
||||
val original = ControllerProfileResolver().resolve(identity)
|
||||
.replaceBinding(GameAction.TURBO_A, InputBinding(BindingKind.KEY, 188))
|
||||
.clearBinding(GameAction.TURBO_B)
|
||||
val swapped = original.toggleXY()
|
||||
assertTrue(swapped.bindings.getValue(GameAction.TURBO_A).isEmpty())
|
||||
assertEquals(setOf(GameAction.TURBO_B), swapped.actionsFor(InputBinding(BindingKind.KEY, 188)))
|
||||
assertEquals(original, swapped.toggleXY())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun manualMappingCanReplaceAndClearEachAction() {
|
||||
val original = ControllerProfileResolver().resolve(identity)
|
||||
|
||||
@@ -20,6 +20,8 @@ class AppSettingsTest {
|
||||
assertEquals(VirtualDpadSize.LARGE, settings.virtualDpadSize)
|
||||
assertEquals(0f, settings.virtualDpadHorizontalOffset)
|
||||
assertEquals(0f, settings.virtualDpadVerticalOffset)
|
||||
assertFalse(settings.virtualSwapAB)
|
||||
assertFalse(settings.virtualSwapXY)
|
||||
assertFalse(settings.guideCompleted)
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
package org.neslite.app.system
|
||||
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Test
|
||||
|
||||
class ButtonStateMatrixTest {
|
||||
private val states = listOf("Idle", "Loading", "Running", "Pausing", "Paused", "Stopping", "Error")
|
||||
private val actions = mapOf(
|
||||
"load" to setOf("Idle", "Paused", "Error"),
|
||||
"run" to setOf("Paused"), "pause" to setOf("Running"),
|
||||
"stop" to setOf("Paused", "Running", "Error"), "reset" to setOf("Paused", "Running"),
|
||||
"audio_rebuild" to setOf("Paused"), "state_save:0" to setOf("Paused"),
|
||||
"state_load:9" to setOf("Paused"), "auto_load:2" to setOf("Paused"),
|
||||
"package_export" to setOf("Paused"), "package_import" to setOf("Paused"),
|
||||
)
|
||||
|
||||
@Test fun eachButtonAcceptsOnlyItsSupportedSessionStates() {
|
||||
actions.forEach { (command, allowed) -> states.forEach { state ->
|
||||
assertEquals("$state / $command", state in allowed, sessionCommandAllowed(null, command, state))
|
||||
} }
|
||||
states.forEach { assertFalse(sessionCommandAllowed(null, "unknown", it)) }
|
||||
}
|
||||
|
||||
@Test fun rapidClicksCannotCrossAnyPendingOperationIncludingFileCopies() {
|
||||
(actions.keys + setOf("pause_external", "package_import_read", "package_export_copy")).forEach { pending ->
|
||||
states.forEach { state -> actions.keys.forEach { command ->
|
||||
assertFalse("$pending -> $command in $state", sessionCommandAllowed(pending, command, state))
|
||||
} }
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun oldOrUnrelatedAcknowledgementsDoNotUnlockTheNextCommand() {
|
||||
assertFalse(matchesPendingCompletion("stop", 10, 10, "stop", "7:stopped_saved", 7))
|
||||
assertFalse(matchesPendingCompletion("stop", 10, 11, "fast:off", "7:ignored", 7))
|
||||
assertFalse(matchesPendingCompletion("stop", 10, 11, "stop", "6:stale", 7))
|
||||
assertFalse(matchesPendingCompletion("state_save:1", 10, 11, "state_save:0", "7:state_saved", 7))
|
||||
assertTrue(matchesPendingCompletion("stop", 10, 11, "stop", "7:stop_save_failed", 7))
|
||||
assertTrue(matchesPendingCompletion("pause_external", 10, 11, "pause", "7:paused_saved", 7))
|
||||
assertFalse(matchesPendingCompletion(null, 10, 11, "pause", "7:paused_saved", 7))
|
||||
}
|
||||
|
||||
@Test fun loadingNeverStartsInTheBackgroundOrBehindMenusOrRecoveryDialogs() {
|
||||
assertTrue(shouldRunLoadedGame(true, true, true, false, false))
|
||||
assertFalse(shouldRunLoadedGame(false, true, true, false, false))
|
||||
assertFalse(shouldRunLoadedGame(true, false, true, false, false))
|
||||
assertFalse(shouldRunLoadedGame(true, true, false, false, false))
|
||||
assertFalse(shouldRunLoadedGame(true, true, true, true, false))
|
||||
assertFalse(shouldRunLoadedGame(true, true, true, false, true))
|
||||
}
|
||||
|
||||
@Test fun everySaveResultIncludingFailureReleasesTheOperationLock() {
|
||||
mapOf("state_save:0" to listOf("state_saved", "state_save_failed"),
|
||||
"state_load:0" to listOf("state_loaded", "state_load_failed"),
|
||||
"auto_load:0" to listOf("auto_loaded", "auto_load_failed"),
|
||||
"package_export" to listOf("package_exported", "package_export_failed"),
|
||||
"package_import" to listOf("package_imported", "package_import_failed"),
|
||||
"reset" to listOf("reset")
|
||||
).forEach { (command, results) ->
|
||||
(results + listOf("ignored", "stale", "error")).forEach { result ->
|
||||
assertTrue("$command / $result", sessionTransitionSettled(command, "Paused", "7:$result"))
|
||||
}
|
||||
assertFalse(sessionTransitionSettled(command, "Paused", "7:muted"))
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun pauseShortcutNavigatesSubmenusBeforeResuming() {
|
||||
listOf(UiLayer.SETTINGS, UiLayer.CONTROLLER_SETTINGS, UiLayer.SAVE_MANAGER,
|
||||
UiLayer.DIAGNOSTICS, UiLayer.AUXILIARY_PAGE).forEach {
|
||||
assertNotEquals(BackDecision.RESUME_GAME, SystemUiPolicy.backDecision(it))
|
||||
}
|
||||
assertEquals(BackDecision.RESUME_GAME, SystemUiPolicy.backDecision(UiLayer.PAUSE_MENU))
|
||||
assertEquals(BackDecision.IGNORE_TRANSITION, SystemUiPolicy.backDecision(UiLayer.TRANSITION))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package org.neslite.app.system
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
class ExitPolicyTest {
|
||||
@Test
|
||||
fun noGameClosesApplicationOrReturnsToLibraryWithoutConfirmation() {
|
||||
assertEquals(ExitRequestAction.FINISH_APPLICATION,
|
||||
exitRequestAction(ExitDestination.APPLICATION, false, "Idle", null, false))
|
||||
assertEquals(ExitRequestAction.OPEN_LIBRARY,
|
||||
exitRequestAction(ExitDestination.LIBRARY, false, "Idle", null, false))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun runningGameMustPauseBeforeEitherExitConfirmation() {
|
||||
ExitDestination.entries.forEach { destination ->
|
||||
assertEquals(ExitRequestAction.PAUSE_THEN_CONFIRM,
|
||||
exitRequestAction(destination, true, "Running", null, false))
|
||||
listOf("Paused", "Error").forEach { state ->
|
||||
assertEquals(ExitRequestAction.CONFIRM,
|
||||
exitRequestAction(destination, true, state, null, false))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun duplicateRequestsAndInFlightOperationsCannotCloseTheApp() {
|
||||
ExitDestination.entries.forEach { destination ->
|
||||
listOf("Loading", "Pausing", "Stopping").forEach { state ->
|
||||
assertEquals(ExitRequestAction.WAIT,
|
||||
exitRequestAction(destination, true, state, null, false))
|
||||
}
|
||||
listOf("load", "pause", "stop", "run", "audio_rebuild").forEach { command ->
|
||||
assertEquals(ExitRequestAction.WAIT,
|
||||
exitRequestAction(destination, true, "Paused", command, false))
|
||||
}
|
||||
assertEquals(ExitRequestAction.WAIT,
|
||||
exitRequestAction(destination, true, "Paused", null, true))
|
||||
assertEquals(ExitRequestAction.WAIT,
|
||||
exitRequestAction(destination, false, "Idle", null, true))
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun failedSaveSettlesStopWithoutRequiringTheCoreToBeUnloaded() {
|
||||
assertTrue(sessionTransitionSettled("stop", "Paused", "1:stop_save_failed"))
|
||||
assertTrue(sessionCommandAllowed(null, "stop", "Paused"))
|
||||
assertTrue(sessionCommandAllowed(null, "run", "Paused"))
|
||||
assertFalse(sessionTransitionSettled("stop", "Paused", "1:paused_saved"))
|
||||
assertFalse(sessionTransitionSettled("stop", "Stopping", "1:paused_saved"))
|
||||
assertTrue(sessionTransitionSettled("stop", "Idle", "1:stopped_saved"))
|
||||
// A later settings acknowledgement must not hide a failed stop and leave the progress dialog stuck.
|
||||
assertTrue(sessionTransitionSettled("stop", "Paused", "1:volume", "Exit auto state save failed"))
|
||||
assertFalse(sessionTransitionSettled("stop", "Paused", "1:volume", ""))
|
||||
assertFalse(sessionCommandAllowed("stop", "state_save:0", "Paused"))
|
||||
}
|
||||
}
|
||||
@@ -95,7 +95,7 @@ class SystemUiPolicyTest {
|
||||
assertEquals(false, sessionCommandAllowed("pause", "run", "Running"))
|
||||
assertEquals(false, sessionCommandAllowed("load", "stop", "Loading"))
|
||||
assertEquals(false, sessionCommandAllowed("audio_rebuild", "run", "Paused"))
|
||||
assertEquals(true, sessionCommandAllowed("audio_rebuild", "stop", "Paused"))
|
||||
assertEquals(false, sessionCommandAllowed("audio_rebuild", "stop", "Paused"))
|
||||
assertEquals(true, sessionTransitionSettled("pause", "Paused", "1:paused_saved"))
|
||||
assertEquals(true, sessionTransitionSettled("audio_rebuild", "Paused", "1:audio_rebuilt_paused"))
|
||||
assertEquals(false, sessionTransitionSettled("stop", "Stopping", ""))
|
||||
|
||||
+3
-3
@@ -1,7 +1,7 @@
|
||||
# NESLite 构建与打包
|
||||
|
||||
项目的 APK 打包入口统一为根目录 `打包.cmd`,项目内的编译产物、缓存、日志和交付文件统一放入
|
||||
`build/`。当前应用版本为 1.0.0,入口从 APK 构建元数据读取版本,不另写一套版本号。
|
||||
`build/`。当前应用版本为 1.0.5,入口从 APK 构建元数据读取版本,不另写一套版本号。
|
||||
|
||||
## 一键打包
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
.\打包.cmd -NoPause
|
||||
```
|
||||
|
||||
当前交付文件是 `build/releases/NESLite-1.0.0-debug-arm64-v8a.apk`,旁边的 `.sha256` 保存校验值。
|
||||
当前交付文件是 `build/releases/NESLite-1.0.5-debug-arm64-v8a.apk`,旁边的 `.sha256` 保存校验值。
|
||||
入口检查工具链与固定依赖、编译选定 APK、检查原生库和 APK 的 16 KB 对齐,成功后复制产物。
|
||||
它不会自动启动单元测试、ROM 遍历、设备测试或发布回归;失败会返回非零退出码,旧交付 APK 不冒充本次成功产物。
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
.\打包.cmd release -NoPause
|
||||
```
|
||||
|
||||
该模式使用项目外的正式密钥,生成 `build/releases/NESLite-1.0.0-arm64-v8a.apk`、原生符号、应用和依赖源码 ZIP、发布清单及校验值。
|
||||
该模式使用项目外的正式密钥,生成 `build/releases/NESLite-1.0.5-arm64-v8a.apk`、原生符号、应用和依赖源码 ZIP、发布清单及校验值。
|
||||
正式打包前必须提交源码并配置签名目录;入口读取 Windows 用户加密的密码,完成签名和签名验证。密钥位置与发布步骤见 [publishing.md](publishing.md)。
|
||||
一键打包不会运行原 `package-rc.ps1` 的全量 Stage/lint/设备测试包构建,也不表示发布门槛通过。
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
ABXY、视图/菜单键及左右肩键。随后在荣耀 Magic8 页面取得了 Android 设备身份和静态轴范围;
|
||||
实际 KeyEvent、动态轴采样、手柄模式及拔出重连仍待诊断 JSON 回填。
|
||||
|
||||
在 0.9.15-debug 中可从“设置 → 手动设置手柄按键、摇杆与功能键”进入编辑页。可选择“开始逐项手动
|
||||
在 0.9.15-debug 中可从“设置 → 交换 X/Y、A/B 按键与手动映射”进入编辑页。可选择“开始逐项手动
|
||||
设置全部按键”,按页面顺序操作 X5 Lite;也可点击任一动作单独修改或清除。轴方向捕获后先松回中位,
|
||||
冲突时确认是否替换,最后点击“保存”。配置按下表设备指纹保存,不依赖临时 deviceId。
|
||||
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
# NESLite 1.0.1
|
||||
|
||||
本次更新增加手柄与屏幕虚拟按键的同步交换,面向 Android 9 及以上的 arm64 设备。
|
||||
|
||||
## 本次更新
|
||||
|
||||
- 设置中提供“交换 X/Y、A/B 按键与手动映射”入口,两组可独立交换。
|
||||
- 保存后屏幕虚拟按键同步换位,文字、颜色、按下反馈和触控区域保持一致。
|
||||
- 屏幕按键在断开手柄或重启后保留最近的交换状态;恢复默认时一起还原。
|
||||
- 兼容旧手柄配置,换位前释放触控输入,保存失败时继续使用原有映射。
|
||||
|
||||
## 安装
|
||||
|
||||
安装包为 `NESLite-1.0.1-arm64-v8a.apk`,正式包名为 `org.neslite.app`,版本号为 1000001。
|
||||
沿用 1.0.0 正式签名,可直接覆盖安装旧正式版。调试版包名不同,仍需通过存档导入导出迁移进度。
|
||||
应用不附带游戏 ROM。
|
||||
|
||||
## 验证与构建材料
|
||||
|
||||
功能修改已通过 71 项单元测试和调试构建;手柄实机、触屏操作及覆盖升级仍待设备验证。
|
||||
正式打包流程校验签名、arm64 库与 16 KB 静态对齐,并输出源码、原生符号、依赖源码和 SHA-256 清单。
|
||||
具体版本、源码提交及安装包校验值见同目录的 `NESLite-1.0.1-release.json`。
|
||||
@@ -0,0 +1,20 @@
|
||||
# NESLite 1.0.2
|
||||
|
||||
修复未连接外接手柄时,无法调整屏幕虚拟按键顺序的问题。
|
||||
|
||||
## 本次更新
|
||||
|
||||
- “设置 → 交换 X/Y、A/B 按键与手动映射”始终显示两组交换选项。
|
||||
- 未连接手柄时,点击立即调整屏幕按键并自动保存,重新打开应用后保留。
|
||||
- 新增“恢复屏幕按键默认顺序”,无需连接手柄即可还原。
|
||||
- 已连接手柄时,保留逐设备保存与手柄、屏幕同步交换的行为。
|
||||
- 调整设置保存顺序,防止快速切换两组按键时旧设置覆盖新设置。
|
||||
|
||||
## 安装与验证
|
||||
|
||||
正式安装包为 `NESLite-1.0.2-arm64-v8a.apk`,版本号为 1000002,沿用原有正式签名。
|
||||
可覆盖升级 1.0.0、1.0.1 正式版;调试版与正式版包名不同。
|
||||
|
||||
新增无手柄场景的界面回归测试,覆盖选项可用、独立交换、保存、重建页面和恢复默认。
|
||||
71 项单元测试全部通过,界面测试安装包编译成功。当前环境没有连接测试设备,界面测试尚未在设备运行。
|
||||
源码、符号、签名安装包和校验清单由正式打包入口统一生成到 `build/releases/`。
|
||||
@@ -0,0 +1,12 @@
|
||||
# NESLite 1.0.3
|
||||
|
||||
新增清晰的“退出游戏”和“退出应用”入口,并加强退出前的进度保存。
|
||||
|
||||
- 游戏画面左上角和暂停菜单顶部提供“退出游戏”,保存后返回游戏列表。
|
||||
- 游戏列表右上角、设置页底部和暂停菜单提供“退出应用”,保存后关闭应用并返回桌面。
|
||||
- 有游戏运行时先暂停,再显示确认框,默认选中取消;没有运行游戏时退出应用无需确认。
|
||||
- 退出前提交电池进度与自动恢复点,不覆盖手动存档;保存失败保留游戏,支持重试或留在暂停菜单。
|
||||
- 退出过程中忽略重复操作,并在页面重建后恢复退出流程。
|
||||
|
||||
正式安装包为 `NESLite-1.0.3-arm64-v8a.apk`,版本号为 1000003,沿用原有正式签名,可覆盖安装旧正式版。
|
||||
75 项单元测试和 5 项原生测试通过,覆盖退出决策、重复请求和保存失败重试;设备界面测试编译通过。当前没有连接测试设备,完整游戏退出与手机桌面返回仍需实机验证。
|
||||
@@ -0,0 +1,15 @@
|
||||
# NESLite 1.0.4
|
||||
|
||||
修复游戏、暂停、设置、存档与退出之间的按钮状态交叉问题。
|
||||
|
||||
- 设置等子页面中的暂停快捷键先返回上一级,避免直接恢复游戏。
|
||||
- 加载时切到后台或进入异常恢复流程,完成后保持暂停。
|
||||
- 存读档、重置、恢复、退出及存档包传输期间拦截重复或交叉操作;完成通知核对游戏会话与具体命令,不受音量、静音和快进通知覆盖。
|
||||
- 切换游戏前先安全保存并结束当前游戏,保存失败保留当前会话。
|
||||
- 拦截退出后的异步界面更新;退出时等待手柄及屏幕按键配置写入完成。
|
||||
- 设置读取完成前暂缓编辑,并按点击顺序保存手柄配置。
|
||||
- 重置时清除按键和快进状态,避免松开事件在状态交接期间丢失。
|
||||
|
||||
正式安装包为 `NESLite-1.0.4-arm64-v8a.apk`,版本号为 1000004,沿用原有正式签名。
|
||||
81 项单元测试、6 项原生测试通过,应用及设备测试包编译成功,Android 静态检查无错误。
|
||||
新增自制测试 ROM 的按钮流程测试;当前未连接手机,设备测试尚未执行。
|
||||
@@ -0,0 +1,12 @@
|
||||
# NESLite 1.0.5
|
||||
|
||||
调整游戏画面的退出按钮,避免遮挡中央游戏窗口。
|
||||
|
||||
- 移除左上角工具栏中的矩形“退出游戏”按钮。
|
||||
- 右侧上方按“暂停、重置、退出”排列,三个按钮沿用相同的圆形尺寸、描边和配色。
|
||||
- “退出”仍执行暂停、确认、保存并返回游戏列表的安全退出流程;滑入或滑出取消的触摸不会误触退出。
|
||||
- 暂停菜单中的退出游戏及退出应用入口保留。
|
||||
|
||||
正式安装包为 `NESLite-1.0.5-arm64-v8a.apk`,版本号为 1000005,沿用原有正式签名。
|
||||
新增不同横屏尺寸与安全边距下的按钮布局检查,并更新设备点击测试;设备测试仍需连接手机执行。
|
||||
82 项单元测试通过,应用和设备测试包编译成功;实机点击测试尚未执行。
|
||||
+9
-2
@@ -13,7 +13,14 @@
|
||||
长按游戏名可查看详情、收藏、从列表移除或选择内核。连接外接手柄后仍可按设置选择是否显示
|
||||
屏幕按键。多点触控支持方向与动作同时按住,滑出、取消、失焦或暂停都会释放输入。
|
||||
4. 点左上角“设置”图标,在画面与声音、方向与触控、手柄与辅助三个卡片中调整选项,可切换 4:3/整数缩放、最近邻/线性过滤、音量、静音、软件连发和 RB 快进。进入
|
||||
“手动设置手柄按键、摇杆与功能键”后,可启动逐项向导,也可单独点击动作修改或清除;按下物理键
|
||||
“交换 X/Y、A/B 按键与手动映射”后,无论是否连接手柄,都能看到“交换 X/Y 按键”和“交换 A/B 按键”。
|
||||
未连接手柄时,点击即可交换屏幕按键并自动保存,也可点击“恢复屏幕按键默认顺序”;无需连接手柄。
|
||||
连接手柄时,两项编辑当前手柄配置,点击“保存”后手柄与屏幕按键同步生效。
|
||||
默认 A/B 对应 NES A/B,X/Y 对应 A/B 连发;两组独立交换,保存后所选手柄与屏幕虚拟按键同步。
|
||||
屏幕上的按钮文字、颜色、按下反馈与触控区域一起换位;断开手柄或重启应用后保留最近的交换状态。
|
||||
切换所选手柄时,屏幕跟随该手柄已保存的交换设置;尚未保存的修改不会影响屏幕按键。
|
||||
已有自定义映射时,交换对应的普通或连发动作绑定;再次切换可还原,恢复默认映射会关闭两项交换。
|
||||
同一页面可启动逐项向导,也可单独点击动作修改或清除;按下物理键
|
||||
或推动轴完成捕获,检查无误后点“保存”。冲突会要求确认,设置按设备特征在重启和重连后恢复。
|
||||
“屏幕方向键与手柄摇杆”可切换四方向/八方向,并循环选择标准、大、特大方向键;两个位置滑块可
|
||||
调整方向键的水平和垂直位置。默认八方向与大号,A、B 支持两根手指同时按住。
|
||||
@@ -24,7 +31,7 @@
|
||||
提交时间和缩略图。只有原生层确认安全落盘后才显示保存成功。
|
||||
6. 存档包通过 Android 系统文件选择器导入导出,默认不含 ROM。导入前先加载对应游戏并暂停;哈希、
|
||||
内核名称/提交、配置、路径、大小或校验不匹配会被拒绝并保留现有有效存档。
|
||||
7. 用“退出游戏”正常结束。上次进程异常终止时,再次加载相同游戏只列出校验有效的自动恢复点,
|
||||
7. 游戏画面左上角和暂停菜单顶部提供“退出游戏”,确认后保存并返回游戏列表。游戏列表右上角、设置页底部和暂停菜单提供“退出应用”;有游戏时确认保存后关闭,无游戏时直接关闭。取消退出会保留暂停状态,保存失败可重试或留在游戏,自动恢复点不会覆盖手动存档。上次进程异常终止时,再次加载相同游戏只列出校验有效的自动恢复点,
|
||||
不会自动运行或覆盖当前进度;同一游戏和恢复点连续异常两次后会返回列表并阻止重复启动,只有
|
||||
明确点“手动重试”才再次加载。
|
||||
8. 系统返回手势与手柄 B 使用相同规则:运行中先安全暂停;各独立页面返回主画面;设置、按键设置、
|
||||
|
||||
Reference in New Issue
Block a user