Initial public release
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
t_touch_controls
|
||||
*.dSYM/
|
||||
|
||||
/t_native_binding
|
||||
/t_game_bridge
|
||||
|
||||
/t_binding_freshness
|
||||
|
||||
/t_portal_sequence
|
||||
/t_binding_group
|
||||
|
||||
/t_native_hud_identity
|
||||
/t_native_hud_bridge
|
||||
|
||||
/t_native_art
|
||||
|
||||
/t_skill_aim
|
||||
/t_metal_cache_guard
|
||||
/t_joy_travel
|
||||
@@ -0,0 +1,64 @@
|
||||
DM_ROOT ?= $(HOME)/dm-work
|
||||
CC ?= cc
|
||||
CFLAGS ?= -std=c11 -Wall -Wextra -Werror -pedantic -O2
|
||||
TARGET = t_touch_controls
|
||||
METAL_CACHE_TARGET = t_metal_cache_guard
|
||||
BINDING_TARGETS = t_native_binding t_game_bridge t_binding_freshness t_portal_sequence t_binding_group t_native_hud_identity t_native_hud_bridge
|
||||
BINDING_FIXTURES = fixtures/native_binding/mapping.bin fixtures/native_binding/bindings.bin
|
||||
# 这两份夹具是从运行中的游戏内存抓下来的两张表,公开仓库不带(见 fixtures/native_binding/README)。不在就跳过要读它们的三个测试并说明,别的照跑
|
||||
# These two fixtures are tables captured from the memory of the running game, and the public repository does not ship them (see fixtures/native_binding/README). When they are absent, the three tests that read them are skipped with an explanation, and everything else still runs
|
||||
HAVE_BINDING_FIXTURES := $(and $(wildcard fixtures/native_binding/mapping.bin),$(wildcard fixtures/native_binding/bindings.bin))
|
||||
fixture_test = $(if $(HAVE_BINDING_FIXTURES),./$(1) $(BINDING_FIXTURES),@echo "跳过 $(1):没有夹具 $(BINDING_FIXTURES)(公开仓库不带,要自己从运行中的游戏抓,见 fixtures/native_binding/README)")
|
||||
|
||||
.PHONY: all run test clean
|
||||
all: $(TARGET) $(BINDING_TARGETS) t_native_art t_skill_aim t_joy_travel $(METAL_CACHE_TARGET)
|
||||
run: test
|
||||
$(TARGET): t_touch_controls.c $(wildcard ../Sources/dm_touch_controls.[ch]) ../../host/dm_input.h
|
||||
$(CC) $(CFLAGS) -I../Sources t_touch_controls.c ../Sources/dm_touch_controls.c -lm -o $@
|
||||
t_native_binding: t_native_binding.c ../Sources/dm_touch_game_state.c ../Sources/dm_touch_game_state.h ../Sources/dm_touch_controls.c ../Sources/dm_touch_controls.h
|
||||
$(CC) $(CFLAGS) -I../Sources t_native_binding.c ../Sources/dm_touch_game_state.c ../Sources/dm_touch_controls.c -lm -o $@
|
||||
t_game_bridge: t_game_bridge.c ../Sources/dm_touch_game_bridge.c ../Sources/dm_touch_game_identity.c ../Sources/dm_touch_game_identity.h ../Sources/dm_touch_game_state.c ../Sources/dm_touch_game_state.h ../../host/dm.h
|
||||
$(CC) $(CFLAGS) -DDM_TG_TEST_SYNTHETIC_IDENTITY -I../Sources t_game_bridge.c ../Sources/dm_touch_game_bridge.c ../Sources/dm_touch_game_identity.c ../Sources/dm_touch_game_state.c -lpthread -o $@
|
||||
t_binding_freshness: t_binding_freshness.c ../Sources/dm_touch_game_state.c ../Sources/dm_touch_game_state.h ../Sources/dm_touch_controls.c ../Sources/dm_touch_controls.h
|
||||
$(CC) $(CFLAGS) -I../Sources t_binding_freshness.c ../Sources/dm_touch_game_state.c ../Sources/dm_touch_controls.c -lm -o $@
|
||||
t_portal_sequence: t_portal_sequence.c ../Sources/dm_touch_controls.c ../Sources/dm_touch_controls.h
|
||||
$(CC) $(CFLAGS) -I../Sources t_portal_sequence.c ../Sources/dm_touch_controls.c -lm -o $@
|
||||
t_binding_group: t_binding_group.c ../Sources/dm_touch_game_state.c ../Sources/dm_touch_game_state.h
|
||||
$(CC) $(CFLAGS) -I../Sources t_binding_group.c ../Sources/dm_touch_game_state.c -o $@
|
||||
t_native_hud_identity: t_native_hud_identity.c ../Sources/dm_touch_game_identity.c ../Sources/dm_touch_game_identity.h ../Sources/dm_touch_game_state.h
|
||||
$(CC) $(CFLAGS) -I../Sources t_native_hud_identity.c ../Sources/dm_touch_game_identity.c -o $@
|
||||
t_native_hud_bridge: t_native_hud_bridge.c ../Sources/dm_touch_game_bridge.c ../Sources/dm_touch_game_identity.c ../Sources/dm_touch_game_identity.h ../Sources/dm_touch_game_state.c ../Sources/dm_touch_game_state.h ../../host/dm.h
|
||||
$(CC) $(CFLAGS) -I../Sources t_native_hud_bridge.c ../Sources/dm_touch_game_bridge.c ../Sources/dm_touch_game_identity.c ../Sources/dm_touch_game_state.c -lpthread -o $@
|
||||
# 技能图集 / 技能索引由原版表生成、不进仓库(tools/native_art/generate.py;dm/README.md「从你的游戏文件生成资源」)
|
||||
# The skill atlas / skill index are generated from the original game's tables and are not kept in the repository (tools/native_art/generate.py; dm/README.md 「从你的游戏文件生成资源」(Generating assets from your game files))
|
||||
ROMFS?=$(or $(DM_ROMFS_SRC),$(DM_ROOT)/data/switch/3.3.94012/Update/RomFS)
|
||||
../Sources/dm_touch_native_art.c: ../tools/native_art/generate.py ../tools/native_art/implementation.c.inc ../Sources/TouchArt/native_art_manifest.json
|
||||
python3 ../tools/native_art/generate.py "$(ROMFS)"
|
||||
t_native_art: t_native_art.c ../Sources/dm_touch_native_art.c ../Sources/dm_touch_native_art.h
|
||||
$(CC) $(CFLAGS) -I../Sources t_native_art.c ../Sources/dm_touch_native_art.c -o $@
|
||||
t_skill_aim: t_skill_aim.c ../Sources/dm_touch_controls.c ../Sources/dm_touch_controls.h ../../host/dm_input.h
|
||||
$(CC) $(CFLAGS) -I../Sources t_skill_aim.c ../Sources/dm_touch_controls.c -lm -o $@
|
||||
t_joy_travel: t_joy_travel.c ../Sources/dm_touch_controls.c ../Sources/dm_touch_controls.h ../../host/dm_input.h
|
||||
$(CC) $(CFLAGS) -I../Sources t_joy_travel.c ../Sources/dm_touch_controls.c -lm -o $@
|
||||
t_metal_cache_guard: t_metal_cache_guard.c ../Sources/dm_metal_cache_guard.c ../Sources/dm_metal_cache_guard.h
|
||||
$(CC) $(CFLAGS) -I../Sources t_metal_cache_guard.c ../Sources/dm_metal_cache_guard.c -o $@
|
||||
test: $(TARGET) $(BINDING_TARGETS) t_native_art t_skill_aim t_joy_travel $(METAL_CACHE_TARGET)
|
||||
./$(METAL_CACHE_TARGET)
|
||||
./$(TARGET)
|
||||
./t_skill_aim
|
||||
./t_joy_travel
|
||||
./t_native_art
|
||||
python3 test_native_art_capture.py
|
||||
$(call fixture_test,t_native_binding)
|
||||
$(call fixture_test,t_game_bridge)
|
||||
./t_binding_freshness
|
||||
./t_portal_sequence
|
||||
./t_binding_group
|
||||
./t_native_hud_identity
|
||||
$(call fixture_test,t_native_hud_bridge)
|
||||
python3 test_portal_receipt.py
|
||||
python3 test_native_binding_seam.py
|
||||
python3 test_skill_aim_front.py
|
||||
python3 test_touch_receipt.py --source ../Sources/front_ios.m
|
||||
clean:
|
||||
rm -f $(TARGET) $(BINDING_TARGETS) t_native_art t_skill_aim t_joy_travel $(METAL_CACHE_TARGET)
|
||||
@@ -0,0 +1 @@
|
||||
!*.bin
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
# native_binding — test fixtures for skill binding parsing
|
||||
|
||||
中文:[README.zh-CN.md](README.zh-CN.md)
|
||||
|
||||
For unit tests only. The app does not read these two files at run time, and the tests do not modify them.
|
||||
|
||||
**The public repository does not ship these two fixtures**: they are two tables captured from the memory of the running game. Without them, the three tests below that read the fixtures are skipped automatically with a one-line notice, and the other tests run as usual. To run those three tests you have to capture the two tables from the running game yourself and put them in this directory under the file names below; the assertions in the tests are written against the contents of the snapshot described below, so with different contents the assertions have to be changed accordingly.
|
||||
|
||||
## Background
|
||||
|
||||
The skill buttons on the right need to show "which skill this button is bound to right now". In the memory of the running game this information is two tables, which the shell fetches read-only and then parses (`../../../Sources/dm_touch_game_bridge.c` does the fetching, and `dm_tg_parse` in `../../../Sources/dm_touch_game_state.c` does the parsing):
|
||||
|
||||
- **Button mapping table**: for each of the six gamepad buttons (B, A, Y, X, R, ZR), which normal skill slot and which alternate skill slot it corresponds to. The alternate slots are the set used while ZL is held.
|
||||
- **Binding table**: the skill ID bound in each skill slot; an empty slot is `0xFFFFFFFF`.
|
||||
|
||||
## Files
|
||||
|
||||
| File | Size | Contents |
|
||||
|---|---|---|
|
||||
| `mapping.bin` | 114 bytes | A snapshot of the button mapping table. Parsing uses only the first 72 bytes: 6 entries, each of 3 32-bit little-endian integers (logical button, normal slot, alternate slot) |
|
||||
| `bindings.bin` | 896 bytes | A snapshot of the binding table: 32 entries of 28 bytes each; the 32-bit little-endian integer at the start of each entry is the skill ID |
|
||||
|
||||
The contents of this snapshot, which the assertions in the tests are written against:
|
||||
|
||||
- Button mapping: B → normal slot 1 / alternate slot 7, A → 0 / 6, Y → 2 / 8, X → 3 / 9, R → 4 / 10, ZR → 5 / 11.
|
||||
- Bindings: slots 0, 2 and 7 of the first group have skills, the rest are empty; the second group, starting from entry 16, is entirely empty. Slot 7 is the town portal skill, so in the parse result the way to press town portal is ZL + B.
|
||||
|
||||
Checksums (SHA-256):
|
||||
|
||||
```
|
||||
b9777515f225f235ac1223dd04bf15db250f1240f893511737ceecf357367362 mapping.bin
|
||||
4d4f4cde5d08f35f9a988ac61aff54913499d32322ac95fa3ce7763c16a11262 bindings.bin
|
||||
```
|
||||
|
||||
## Who uses them
|
||||
|
||||
The `test` target of `dm/ios/tests/Makefile` passes these two files as arguments to three tests (when the files are absent, these three tests are skipped):
|
||||
|
||||
| Test | What it verifies with them |
|
||||
|---|---|
|
||||
| `t_native_binding` | Parsing: in the normal case it reads out the button mapping and the town portal button combination above; when the length is too short, a slot number is out of range, a button is duplicated, or the observed skill ID does not match, it rejects in every case |
|
||||
| `t_game_bridge` | Puts the two tables into a block of simulated game memory and verifies the whole path from reading memory to producing a snapshot: reading does not modify registers or the tables; no snapshot is produced when not in a game |
|
||||
| `t_native_hud_bridge` | Same as above, and additionally verifies that a snapshot is produced only after confirming that the call comes from the HUD of the current game, and that after switching to another game it has to be confirmed again |
|
||||
|
||||
To run: `make -C dm/ios/tests test`.
|
||||
@@ -0,0 +1,45 @@
|
||||
# native_binding — 技能绑定解析的测试夹具
|
||||
|
||||
English: [README.md](README.md)
|
||||
|
||||
只给单元测试用。App 运行时不读这两个文件,测试也不会改它们。
|
||||
|
||||
**公开仓库不带这两份夹具**:它们是从运行中的游戏内存抓下来的两张表。缺了它们,下面三个要读夹具的测试自动跳过并打印一行说明,其余测试照常。要跑这三个测试,得自己从运行中的游戏抓这两张表,照下面的文件名放到本目录;测试里的断言是按下面这份快照的内容写的,内容不同就要相应改断言。
|
||||
|
||||
## 背景
|
||||
|
||||
右侧技能钮上要显示「这个键现在绑着哪个技能」。这份信息在运行中的游戏内存里是两张表,外壳只读地取出来再解析(`../../../Sources/dm_touch_game_bridge.c` 负责取,`../../../Sources/dm_touch_game_state.c` 的 `dm_tg_parse` 负责解析):
|
||||
|
||||
- **键位表**:六个手柄键(B、A、Y、X、R、ZR)各对应哪个普通技能槽、哪个替代技能槽。替代槽是按住 ZL 时用的那一套。
|
||||
- **绑定表**:每个技能槽里绑着的技能编号,空槽是 `0xFFFFFFFF`。
|
||||
|
||||
## 文件
|
||||
|
||||
| 文件 | 大小 | 内容 |
|
||||
|---|---|---|
|
||||
| `mapping.bin` | 114 字节 | 键位表的一份快照。解析只用前 72 字节:6 项,每项 3 个 32 位小端整数(逻辑键、普通槽、替代槽) |
|
||||
| `bindings.bin` | 896 字节 | 绑定表的一份快照:32 项,每项 28 字节,每项开头的 32 位小端整数是技能编号 |
|
||||
|
||||
这份快照里的内容,测试里的断言按它写:
|
||||
|
||||
- 键位:B → 普通槽 1 / 替代槽 7,A → 0 / 6,Y → 2 / 8,X → 3 / 9,R → 4 / 10,ZR → 5 / 11。
|
||||
- 绑定:第一组的 0、2、7 号槽有技能,其余为空;从第 16 项起的第二组全空。7 号槽是回城技能,所以解析结果里回城的按法是 ZL + B。
|
||||
|
||||
校验值(SHA-256):
|
||||
|
||||
```
|
||||
b9777515f225f235ac1223dd04bf15db250f1240f893511737ceecf357367362 mapping.bin
|
||||
4d4f4cde5d08f35f9a988ac61aff54913499d32322ac95fa3ce7763c16a11262 bindings.bin
|
||||
```
|
||||
|
||||
## 谁在用
|
||||
|
||||
`dm/ios/tests/Makefile` 的 `test` 目标把这两个文件作为参数传给三个测试(文件不在时这三个测试跳过):
|
||||
|
||||
| 测试 | 用它验什么 |
|
||||
|---|---|
|
||||
| `t_native_binding` | 解析:正常情况读出上面的键位与回城按法;长度不够、槽号越界、键位重复、观察到的技能编号对不上时一律拒绝 |
|
||||
| `t_game_bridge` | 把两张表放进一块模拟的游戏内存,验从内存读取到产出快照的整条通路:读取不改寄存器、不改表;不在局内时不出快照 |
|
||||
| `t_native_hud_bridge` | 同上,另验要先确认调用来自当前这一局的 HUD 才出快照,换了一局要重新确认 |
|
||||
|
||||
运行:`make -C dm/ios/tests test`。
|
||||
@@ -0,0 +1,79 @@
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static int log_fd;
|
||||
static int stderr_copy;
|
||||
static int tee_pipe[2];
|
||||
|
||||
static void write_all(int fd, const char *p, size_t n) {
|
||||
while (n) {
|
||||
ssize_t w = write(fd, p, n);
|
||||
if (w > 0) { p += w; n -= (size_t)w; }
|
||||
else if (w < 0 && errno == EINTR) continue;
|
||||
else abort();
|
||||
}
|
||||
}
|
||||
|
||||
static void *tee_main(void *unused) {
|
||||
(void)unused;
|
||||
char buf[128], line[256];
|
||||
size_t used = 0;
|
||||
for (;;) {
|
||||
ssize_t n = read(tee_pipe[0], buf, sizeof buf);
|
||||
if (n == 0) break;
|
||||
if (n < 0 && errno == EINTR) continue;
|
||||
if (n < 0) abort();
|
||||
for (ssize_t i = 0; i < n; i++) {
|
||||
line[used++] = buf[i];
|
||||
if (buf[i] == '\n') {
|
||||
write_all(log_fd, line, used);
|
||||
if (fsync(log_fd)) abort();
|
||||
write_all(stderr_copy, line, used);
|
||||
used = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (used) {
|
||||
write_all(log_fd, line, used);
|
||||
if (fsync(log_fd)) abort();
|
||||
write_all(stderr_copy, line, used);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
char path[] = "dm/ios/tests/.log_tee_test.XXXXXX";
|
||||
int capture[2];
|
||||
pthread_t thread;
|
||||
char expected[] = "LOG one\nUIMSG two\n";
|
||||
char actual[sizeof expected] = {0};
|
||||
char console[sizeof expected] = {0};
|
||||
int fd;
|
||||
|
||||
log_fd = mkstemp(path);
|
||||
if (log_fd < 0 || pipe(tee_pipe) || pipe(capture)) return 1;
|
||||
stderr_copy = capture[1];
|
||||
if (pthread_create(&thread, NULL, tee_main, NULL)) return 1;
|
||||
if (dup2(tee_pipe[1], STDERR_FILENO) < 0) return 1;
|
||||
write_all(STDERR_FILENO, expected, sizeof expected - 1);
|
||||
close(tee_pipe[1]);
|
||||
close(STDERR_FILENO);
|
||||
if (pthread_join(thread, NULL)) return 1;
|
||||
close(capture[1]);
|
||||
if (read(capture[0], console, sizeof console - 1) != (ssize_t)(sizeof expected - 1)) return 1;
|
||||
if (memcmp(console, expected, sizeof expected - 1)) return 1;
|
||||
fd = open(path, O_RDONLY);
|
||||
if (fd < 0 || read(fd, actual + 0, sizeof actual - 1) != (ssize_t)(sizeof expected - 1)) return 1;
|
||||
lseek(fd, 0, SEEK_SET);
|
||||
memset(actual, 0, sizeof actual);
|
||||
if (read(fd, actual, sizeof actual - 1) != (ssize_t)(sizeof expected - 1)) return 1;
|
||||
if (memcmp(actual, expected, sizeof expected - 1)) return 1;
|
||||
unlink(path);
|
||||
puts("log tee: file lines and stderr lines match; fsync per line passed");
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
#include "dm_touch_game_state.h"
|
||||
#include "dm_touch_controls.h"
|
||||
#include "../../host/dm_input.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
uint64_t dm_tg_portal_mask(const dm_tg_snapshot *,uint64_t);
|
||||
#ifdef RED_BASELINE
|
||||
/* v1旧策略的测试替身:valid永久复用,故意不检查时间。 | Test double for the old v1 policy: valid is reused forever, deliberately not checking time. */
|
||||
uint64_t dm_tg_portal_mask(const dm_tg_snapshot *s,uint64_t n){(void)n;return s->valid?s->portal.buttons:0;}
|
||||
#endif
|
||||
static int checks;
|
||||
#define CHECK(x) do{checks++;if(!(x)){fprintf(stderr,"FAIL line=%d %s\n",__LINE__,#x);exit(1);}}while(0)
|
||||
static void press(dm_tc_state *c,int n,int t){dm_tc_begin(c,n,c->layout.target[t].x,c->layout.target[t].y); if(t>=DM_TC_MAIN && t<=DM_TC_SKILL4) dm_tc_tick(c,c->last_time_s+0.1); /* 已过点按 / 拖动的判定时间 | The tap / drag decision time has passed */}
|
||||
int main(void){
|
||||
dm_tg_snapshot s={.supported=1,.valid=1,.ready=1,.captured_ns=1000000000,.portal={.valid=1,.buttons=258}};
|
||||
CHECK(dm_tg_portal_mask(&s,1250000001)==0);
|
||||
CHECK(dm_tg_portal_mask(&s,1250000000)==258);CHECK(dm_tg_portal_mask(&s,1000000000)==258);
|
||||
CHECK(dm_tg_portal_mask(&s,999999999)==0);s.captured_ns=0;CHECK(dm_tg_portal_mask(&s,1)==0);
|
||||
s.captured_ns=1000000000;s.valid=0;CHECK(dm_tg_portal_mask(&s,1000000000)==0);
|
||||
s.valid=1;s.supported=0;CHECK(dm_tg_portal_mask(&s,1000000000)==0);
|
||||
s.supported=1;s.portal.valid=0;CHECK(dm_tg_portal_mask(&s,1000000000)==0);s.portal.valid=1;
|
||||
dm_tc_state c;dm_tc_init(&c,667,375);dm_tc_set_portal_button(&c,dm_tg_portal_mask(&s,1000000000));
|
||||
press(&c,0,DM_TC_PORTAL);press(&c,1,DM_TC_MAIN);dm_tc_begin(&c,2,90,275);dm_tc_move(&c,2,150,275);int32_t lx=c.lx;
|
||||
CHECK(c.buttons==257 && c.portal_pending && lx==32767);
|
||||
CHECK(dm_tc_portal_ack(&c,c.gesture_epoch,0,0));CHECK(c.buttons==259 && lx==32767);
|
||||
dm_tc_set_portal_button(&c,dm_tg_portal_mask(&s,1250000001));
|
||||
CHECK(!c.finger[0].active && c.finger[1].active && c.finger[2].active && c.buttons==1 && c.lx==lx);
|
||||
s.portal.buttons=257;dm_tc_set_portal_button(&c,dm_tg_portal_mask(&s,1000000000));
|
||||
CHECK(c.buttons==1 && c.lx==lx);press(&c,3,DM_TC_PORTAL);CHECK(c.buttons==257 && c.portal_pending);
|
||||
s.portal.buttons=264;dm_tc_set_portal_button(&c,dm_tg_portal_mask(&s,1000000000));CHECK(!c.finger[3].active && c.buttons==1 && c.lx==lx);
|
||||
printf("PASS synthetic host-clock freshness+held-map-change %d/%d checks\n",checks,checks);return 0;
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
#include "dm_touch_game_state.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#ifdef RED_BASELINE
|
||||
int dm_tg_group_observe(dm_tg_group *g,const dm_tg_snapshot *s,int game,uint64_t scene,uint64_t caller,uint64_t hud,int scope){(void)game;(void)scene;(void)caller;(void)hud;(void)scope;g->completed=*s;g->completed.ready=1;return 1;}
|
||||
#endif
|
||||
static int checks;
|
||||
#define CHECK(x) do{checks++;if(!(x)){fprintf(stderr,"FAIL line=%d %s\n",__LINE__,#x);exit(1);}}while(0)
|
||||
static int feed(dm_tg_group *g,dm_tg_snapshot *s,int arg,int game,int scope,uint64_t scene,uint64_t caller,uint64_t hud){s->getter_input_slot=arg;s->observed_index=s->selected_bank+arg;s->captured_ns++;return dm_tg_group_observe(g,s,game,scene,caller,hud,scope);}
|
||||
int main(void){
|
||||
dm_tg_snapshot s={.supported=1,.valid=1,.captured_ns=100,.portal={.valid=1,.buttons=258}};dm_tg_group g={0};
|
||||
CHECK(!feed(&g,&s,6,1,DM_TG_IDENTITY_SYNTHETIC,1,77,88));CHECK(!g.completed.ready && g.seen==1);
|
||||
for(int i=7;i<11;i++)CHECK(!feed(&g,&s,i,1,DM_TG_IDENTITY_SYNTHETIC,1,77,88));
|
||||
CHECK(feed(&g,&s,11,1,DM_TG_IDENTITY_SYNTHETIC,1,77,88));CHECK(g.completed.ready && g.completed.secondary_group==1 && g.completed.group_seen==63 && g.completed.group_started_ns==101);
|
||||
uint64_t identity=g.completed.binding_identity;CHECK(identity!=0);
|
||||
CHECK(!feed(&g,&s,6,1,DM_TG_IDENTITY_UNCONFIRMED,1,77,88));CHECK(!g.completed.ready);
|
||||
for(int i=0;i<6;i++)feed(&g,&s,i,1,DM_TG_IDENTITY_SYNTHETIC,1,77,88);CHECK(g.completed.ready && !g.completed.secondary_group);
|
||||
CHECK(!feed(&g,&s,6,1,DM_TG_IDENTITY_SYNTHETIC,1,77,88));CHECK(g.completed.ready && !g.completed.secondary_group); // 旧完整normal暂留,不能单alt伪ACK | the old complete normal is kept for now; a lone alt must not fake an ACK
|
||||
for(int i=0;i<6;i++)feed(&g,&s,i,1,DM_TG_IDENTITY_SYNTHETIC,1,77,88);
|
||||
CHECK(!g.completed.secondary_group); // normal/alt不混群 | normal/alt are not mixed into one group
|
||||
s.selected_bank=16;CHECK(!feed(&g,&s,7,1,DM_TG_IDENTITY_SYNTHETIC,1,77,88));CHECK(!g.completed.ready);
|
||||
s.selected_bank=0;for(int i=6;i<12;i++)feed(&g,&s,i,1,DM_TG_IDENTITY_SYNTHETIC,1,77,88);CHECK(g.completed.ready);
|
||||
s.raw_skill_id[3]++;CHECK(!feed(&g,&s,6,1,DM_TG_IDENTITY_SYNTHETIC,1,77,88));CHECK(!g.completed.ready);
|
||||
for(int i=7;i<12;i++)feed(&g,&s,i,1,DM_TG_IDENTITY_SYNTHETIC,1,77,88);CHECK(g.completed.ready && g.completed.binding_identity!=identity);
|
||||
CHECK(!feed(&g,&s,6,1,DM_TG_IDENTITY_SYNTHETIC,2,77,88));CHECK(!g.completed.ready);
|
||||
for(int i=7;i<12;i++)feed(&g,&s,i,1,DM_TG_IDENTITY_SYNTHETIC,2,77,88);CHECK(g.completed.ready && g.completed.scene_epoch==2);
|
||||
CHECK(!feed(&g,&s,6,0,DM_TG_IDENTITY_SYNTHETIC,2,77,88));CHECK(!g.completed.ready);
|
||||
for(int i=6;i<12;i++)feed(&g,&s,i,1,DM_TG_IDENTITY_SYNTHETIC,2,77,88);CHECK(g.completed.ready);
|
||||
CHECK(!feed(&g,&s,6,1,DM_TG_IDENTITY_SYNTHETIC,2,99,88));CHECK(!g.completed.ready);
|
||||
for(int i=7;i<12;i++)feed(&g,&s,i,1,DM_TG_IDENTITY_SYNTHETIC,2,99,88);CHECK(g.completed.ready);
|
||||
CHECK(!feed(&g,&s,6,1,DM_TG_IDENTITY_SYNTHETIC,2,99,0));CHECK(!g.completed.ready);
|
||||
for(int i=6;i<12;i++)feed(&g,&s,i,1,DM_TG_IDENTITY_SYNTHETIC,2,99,88);CHECK(g.completed.ready);
|
||||
uint64_t world_identity=g.completed.binding_identity;s.world_epoch=1;
|
||||
CHECK(!feed(&g,&s,6,1,DM_TG_IDENTITY_SYNTHETIC,2,99,88));CHECK(!g.completed.ready);
|
||||
for(int i=7;i<12;i++)feed(&g,&s,i,1,DM_TG_IDENTITY_SYNTHETIC,2,99,88);CHECK(g.completed.ready && g.completed.binding_identity!=world_identity);
|
||||
printf("PASS six-facet group+scope/scene/bank/map-ID identity %d/%d checks\n",checks,checks);return 0;
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
#include "dm_touch_game_state.h"
|
||||
#include "../../host/dm.h"
|
||||
#include "../../host/dm_input.h"
|
||||
#include <assert.h>
|
||||
module_t g_mod[MAX_MOD];int g_nmod;
|
||||
static int present,checks,identity_scope=DM_TG_IDENTITY_UNCONFIRMED;
|
||||
int dm_touch_game_test_identity(const uint64_t *regs,uint64_t *caller,uint64_t *hud) {(void)regs;*caller=77;*hud=88;return identity_scope;}
|
||||
static void (*hook)(const uint64_t *);
|
||||
int gate_obs_present(int id) {assert(id==6);return present;}
|
||||
void gate_obs_set(int id,void (*fn)(const uint64_t *)) {assert(id==6);hook=fn;}
|
||||
uint64_t now_ns(void) {return 123456;}
|
||||
#define CHECK(x) do {checks++;if(!(x)){fprintf(stderr,"FAIL line=%d %s\n",__LINE__,#x);return 1;}}while(0)
|
||||
#ifdef RED_BASELINE
|
||||
int dm_touch_game_attach(void){return 0;}
|
||||
int dm_touch_game_snapshot(dm_tg_snapshot *out){memset(out,0,sizeof(*out));return 0;}
|
||||
#endif
|
||||
int main(int argc,char **argv) {
|
||||
CHECK(argc==3);dm_tg_snapshot s;CHECK(dm_touch_game_attach()==0);CHECK(!dm_touch_game_snapshot(&s) && !s.supported);
|
||||
size_t size=0x2d5f0c0+32*28;unsigned char *mem=calloc(1,size);CHECK(mem!=NULL);
|
||||
g_mod[0].base=mem;g_mod[0].size=size;strcpy(g_mod[0].name,"main");g_nmod=1;present=1;
|
||||
CHECK(dm_touch_game_attach()==1);CHECK(hook!=NULL);CHECK(!dm_touch_game_snapshot(&s) && s.supported);
|
||||
FILE *f=fopen(argv[1],"rb");CHECK(f!=NULL);CHECK(fread(mem+0x2d13cbc,1,72,f)==72);fclose(f);
|
||||
f=fopen(argv[2],"rb");CHECK(f!=NULL);CHECK(fread(mem+0x2d5f0c0,1,896,f)==896);fclose(f);
|
||||
uint64_t regs[31]={0};regs[10]=(uint64_t)(mem+0x2d5f0c0);regs[8]=7*28;regs[19]=7;
|
||||
uint64_t saved[31];memcpy(saved,regs,sizeof regs);unsigned char table[896];memcpy(table,mem+0x2d5f0c0,896);
|
||||
hook(regs);CHECK(!memcmp(saved,regs,sizeof regs));CHECK(!memcmp(table,mem+0x2d5f0c0,896));
|
||||
CHECK(!dm_touch_game_snapshot(&s) && !s.valid && !s.ready);
|
||||
CHECK(!s.ready && s.identity_scope==DM_TG_IDENTITY_UNCONFIRMED);
|
||||
dm_touch_game_set_scene(1,3,1);identity_scope=DM_TG_IDENTITY_SYNTHETIC;
|
||||
regs[8]=6*28;regs[19]=6;hook(regs);CHECK(dm_touch_game_snapshot(&s) && !s.ready);
|
||||
for(int i=7;i<12;i++) {regs[8]=i*28;regs[19]=i;hook(regs);}
|
||||
CHECK(dm_touch_game_snapshot(&s) && s.ready && s.secondary_group && s.group_seen==63 && s.scene_epoch==3);
|
||||
s.portal.buttons=0;CHECK(dm_touch_game_snapshot(&s) && s.portal.buttons==258);
|
||||
regs[8]=16*28;regs[19]=0;hook(regs);CHECK(dm_touch_game_snapshot(&s) && s.selected_bank==16 && !s.portal.buttons);
|
||||
regs[8]=16*28;regs[19]=16;hook(regs);CHECK(dm_touch_game_snapshot(&s) && s.selected_bank==16 && !s.portal.buttons); // otherbank显式arg16反例 | counterexample: otherbank with explicit arg16
|
||||
regs[8]=23*28;regs[19]=7;hook(regs);CHECK(dm_touch_game_snapshot(&s) && s.selected_bank==16 && !s.portal.buttons);
|
||||
regs[8]=7*28;regs[19]=7;hook(regs);CHECK(dm_touch_game_snapshot(&s) && s.selected_bank==0 && s.portal.buttons==258);
|
||||
regs[8]=7*28;regs[19]=6;hook(regs);CHECK(dm_touch_game_snapshot(&s) && s.selected_bank==0 && s.portal.buttons==258); // offset-arg=1 IGNORE
|
||||
const uint64_t bad[]={1,12*28,15*28,28*28,UINT64_MAX};
|
||||
for(unsigned i=0;i<sizeof bad/sizeof *bad;i++){regs[8]=bad[i];hook(regs);CHECK(dm_touch_game_snapshot(&s) && s.supported && s.portal.buttons==258);}
|
||||
regs[8]=7*28;regs[19]=7;regs[10]++;hook(regs);CHECK(dm_touch_game_snapshot(&s) && s.portal.buttons==258);
|
||||
regs[10]--;regs[19]=6;hook(regs);CHECK(dm_touch_game_snapshot(&s) && s.portal.buttons==258);
|
||||
dm_touch_game_set_scene(0,4,1);CHECK(!dm_touch_game_snapshot(&s) && !s.ready && s.scene_epoch==4);
|
||||
regs[8]=7*28;regs[19]=7;hook(regs);CHECK(!dm_touch_game_snapshot(&s) && !s.ready);
|
||||
g_mod[0].size=size-1;CHECK(dm_touch_game_attach()==0);CHECK(!dm_touch_game_snapshot(&s) && s.supported);
|
||||
g_mod[0].size=size;strcpy(g_mod[0].name,"sdk");CHECK(dm_touch_game_attach()==0);
|
||||
free(mem);printf("PASS adapter synthetic ABI+read-only+negative %d/%d checks\n",checks,checks);return 0;
|
||||
}
|
||||
|
||||
int dm_swapskill_equipped(int32_t item) { (void)item; return 0; } /* 副手组技能(宿主 dm_actions.c):单测里没有穿着的物品 | Secondary weapon set skills (host dm_actions.c): there are no worn items in the unit test */
|
||||
@@ -0,0 +1,42 @@
|
||||
/* 移动摇杆:输入行程不跟大屏视觉放大走;iPad 屏幕底边归系统的那一条不起摇杆。期望值按公式手算:幅度 = (位移 − 6) / (60 − 6),满幅 32767。 | Movement stick: the input travel does not follow the visual scale-up on large screens; the strip at the iPad screen bottom edge that belongs to the system does not start the stick. Expected values are hand-computed from the formula: magnitude = (displacement − 6) / (60 − 6), full scale 32767. */
|
||||
#include "dm_touch_controls.h"
|
||||
#include "../../host/dm_input.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
static int checks;
|
||||
#define CHECK(x) do { ++checks; if (!(x)) { fprintf(stderr,"FAIL line=%d %s\n",__LINE__,#x); exit(1); } } while (0)
|
||||
static int push(dm_tc_state *s, float w, float h, float d) { /* 在底座圆心起手(底座固定),向右推 d 点,返回横轴输出 | start on the base center (the base is fixed), push d points to the right, return the horizontal axis output */
|
||||
dm_tc_init(s, w, h); float cx = s->layout.joy_x, cy = s->layout.joy_y; dm_tc_begin(s, 0, cx, cy); CHECK(s->joy_slot == 0);
|
||||
dm_tc_move(s, 0, cx + d, cy); return s->lx;
|
||||
}
|
||||
int main(void) {
|
||||
dm_tc_state s; dm_tc_set_tall_scale(1); /* 前端的口径:比手机高的画面控件按 高 / 440 放大(1366×768 → 1.745 倍) | The front end's convention: on displays taller than a phone, widgets are scaled up by height / 440 (1366×768 → 1.745×) */
|
||||
static const float size[][2] = {{956, 440}, {1194, 672}, {1366, 768}}; /* 手机、11 寸 iPad 的 16:9 视图、12.9 寸 iPad 的 16:9 视图 | Phone, the 16:9 view on the 11-inch iPad, the 16:9 view on the 12.9-inch iPad */
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
float w = size[i][0], h = size[i][1];
|
||||
CHECK(push(&s, w, h, 6) == 0); /* 死区 6 点 | Dead zone 6 points */
|
||||
CHECK(abs(push(&s, w, h, 20) - 8495) <= 1); /* 14 / 54 × 32767 = 8495.1 */
|
||||
CHECK(abs(push(&s, w, h, 33) - 16384) <= 1); /* 27 / 54 = 一半 | 27 / 54 = half */
|
||||
CHECK(push(&s, w, h, 60) == DM_STICK_MAX); /* 60 点满偏 | 60 points for full deflection */
|
||||
CHECK(push(&s, w, h, 105) == DM_STICK_MAX);
|
||||
CHECK(abs(push(&s, w, h, -20) + 8495) <= 1);
|
||||
}
|
||||
dm_tc_init(&s, 1366, 768); CHECK(s.layout.joy_radius > 104 && s.layout.joy_radius < 105); /* 画出来的底盘仍按视觉倍数:60 × 1.745 | The drawn base still follows the visual multiplier: 60 × 1.745 */
|
||||
|
||||
/* 底边那一条:手机(没设)照旧能在最底起摇杆 | Bottom-edge strip: a phone (not set) can still start the stick at the very bottom as before */
|
||||
dm_tc_init(&s, 956, 440); dm_tc_begin(&s, 0, 90, 425); CHECK(s.joy_slot == 0); dm_tc_cancel_all(&s); /* 圆心 90,340、可起手半径 90:(90,425) 在内 | center 90,340, grab radius 90: (90,425) is inside */
|
||||
/* iPad:底部 20 点里起手不当摇杆、松手不当点地 | iPad: a touch starting in the bottom 20 points is not treated as the stick, and its release is not treated as a ground tap */
|
||||
dm_tc_set_edge_bottom(20); dm_tc_init(&s, 1366, 768);
|
||||
dm_tc_begin(&s, 0, 100, 760); CHECK(s.joy_slot == DM_TC_NONE && s.finger[0].target == DM_TC_EDGE);
|
||||
dm_tc_move(&s, 0, 100, 700); CHECK(s.lx == 0 && s.ly == 0 && s.joy_slot == DM_TC_NONE); /* 划上去也不变成摇杆 | Swiping upward does not turn into the stick either */
|
||||
dm_tc_end(&s, 0); CHECK(s.world_tap_seq == 0 && s.buttons == 0);
|
||||
dm_tc_begin(&s, 0, 100, 762); dm_tc_end(&s, 0); CHECK(s.world_tap_seq == 0); /* 原地点一下也不当点地 | A tap in place is not treated as a ground tap either */
|
||||
dm_tc_begin(&s, 0, 150, 745); CHECK(s.joy_slot == 0); /* 这一条的上沿(768 − 20)不算在内 | The top edge of this strip (768 − 20) is not included */
|
||||
dm_tc_move(&s, 0, 160, 766); CHECK(s.joy_slot == 0 && s.lx > 0 && s.ly < 0); /* 已起手的摇杆拖进这一条照常持有 | A stick already started is still held as usual when dragged into this strip */
|
||||
dm_tc_begin(&s, 1, 200, 765); CHECK(s.joy_slot == 0 && s.finger[1].target == DM_TC_EDGE); /* 另一根手指落在这一条:不抢摇杆 | Another finger lands in this strip: it does not grab the stick */
|
||||
dm_tc_end(&s, 1); CHECK(s.joy_slot == 0 && s.lx > 0);
|
||||
dm_tc_end(&s, 0); CHECK(s.lx == 0 && s.ly == 0 && s.joy_slot == DM_TC_NONE);
|
||||
dm_tc_begin(&s, 0, 800, 760); CHECK(s.finger[0].target != DM_TC_EDGE); dm_tc_cancel_all(&s); /* 右半屏不受影响 | The right half of the screen is unaffected */
|
||||
dm_tc_set_edge_bottom(0);
|
||||
printf("JOY_TRAVEL OK %d 项\n", checks); return 0;
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
#include "../Sources/dm_metal_cache_guard.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static void expect(int condition, const char *label) {
|
||||
if (!condition) {
|
||||
fprintf(stderr, "FAIL: %s\n", label);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
static void make_directory(const char *path) {
|
||||
expect(!mkdir(path, 0755) || errno == EEXIST, path);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
char root_template[] = "./dm-metal-guard-XXXXXX";
|
||||
char *root = mkdtemp(root_template);
|
||||
char absolute_root[PATH_MAX];
|
||||
char path[PATH_MAX];
|
||||
expect(root != NULL, "mkdtemp");
|
||||
expect(realpath(root, absolute_root) != NULL, "realpath fixture");
|
||||
root = absolute_root;
|
||||
|
||||
snprintf(path, sizeof path, "%s/Library", root); make_directory(path);
|
||||
snprintf(path, sizeof path, "%s/Library/Caches", root); make_directory(path);
|
||||
snprintf(path, sizeof path, "%s/Library/Caches/com.apple.metal", root); make_directory(path);
|
||||
snprintf(path, sizeof path, "%s/tmp", root); make_directory(path);
|
||||
snprintf(path, sizeof path, "%s/Documents", root); make_directory(path);
|
||||
snprintf(path, sizeof path, "%s/Documents/romfs", root); make_directory(path);
|
||||
snprintf(path, sizeof path, "%s/Documents/romfs/file", root);
|
||||
FILE *file = fopen(path, "w"); expect(file != NULL, "fixture file"); fclose(file);
|
||||
|
||||
char metal[PATH_MAX], documents[PATH_MAX], romfs[PATH_MAX], parent[PATH_MAX], link_path[PATH_MAX];
|
||||
snprintf(metal, sizeof metal, "%s/Library/Caches/com.apple.metal", root);
|
||||
snprintf(documents, sizeof documents, "%s/Documents", root);
|
||||
snprintf(romfs, sizeof romfs, "%s/Documents/romfs", root);
|
||||
snprintf(parent, sizeof parent, "%s/..", root);
|
||||
snprintf(link_path, sizeof link_path, "%s/Library/Caches/metal-link", root);
|
||||
expect(!symlink(documents, link_path), "symlink fixture");
|
||||
|
||||
expect(dm_metal_cache_path_allowed(root, metal), "Caches/com.apple.metal allowed");
|
||||
expect(!dm_metal_cache_path_allowed(root, romfs), "Documents/romfs rejected");
|
||||
expect(!dm_metal_cache_path_allowed(root, documents), "Documents rejected");
|
||||
expect(!dm_metal_cache_path_allowed(root, root), "container root rejected");
|
||||
expect(!dm_metal_cache_path_allowed(root, parent), "parent component rejected");
|
||||
expect(!dm_metal_cache_path_allowed(root, link_path), "symlink to Documents rejected");
|
||||
char appsup[PATH_MAX]; // iOS RomFS 基底在 Library/Application Support/romfs | the iOS RomFS base is at Library/Application Support/romfs
|
||||
snprintf(appsup, sizeof appsup, "%s/Library/Application Support", root); make_directory(appsup);
|
||||
snprintf(appsup, sizeof appsup, "%s/Library/Application Support/romfs", root); make_directory(appsup);
|
||||
expect(!dm_metal_cache_path_allowed(root, appsup), "Application Support/romfs rejected");
|
||||
puts("metal cache guard: PASS (7 cases)");
|
||||
expect(!unlink(link_path), "remove fixture symlink");
|
||||
expect(!unlink(path), "remove fixture file");
|
||||
expect(!rmdir(romfs), "remove fixture romfs");
|
||||
expect(!rmdir(documents), "remove fixture Documents");
|
||||
expect(!rmdir(metal), "remove fixture metal");
|
||||
expect(!rmdir(appsup), "remove fixture appsup romfs");
|
||||
snprintf(path, sizeof path, "%s/Library/Application Support", root); expect(!rmdir(path), "remove fixture Application Support");
|
||||
snprintf(path, sizeof path, "%s/Library/Caches", root); expect(!rmdir(path), "remove fixture Caches");
|
||||
snprintf(path, sizeof path, "%s/Library", root); expect(!rmdir(path), "remove fixture Library");
|
||||
snprintf(path, sizeof path, "%s/tmp", root); expect(!rmdir(path), "remove fixture tmp");
|
||||
expect(!rmdir(root), "remove fixture container");
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
#include "dm_touch_native_art.h"
|
||||
#include "../../host/dm_input.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
static unsigned checks;
|
||||
#define CHECK(x) do { checks++; if(!(x)){fprintf(stderr,"FAIL line %d: %s\n",__LINE__,#x);return 1;} } while(0)
|
||||
int main(void) {
|
||||
dm_ta_glyph g;
|
||||
const uint32_t ids[]={0,115,219,220,359,395};
|
||||
const int classes[]={8,3,8,8,8,7},frames[]={2,26,18,18,18,46};
|
||||
for(unsigned i=0;i<6;i++) {
|
||||
g=dm_ta_skill(ids[i]);CHECK(g.status==DM_TA_GLYPH);CHECK(g.raw_skill_id==ids[i]);
|
||||
CHECK(g.atlas==classes[i]);CHECK(g.normal_frame==frames[i]);CHECK(g.pressed_frame==frames[i]+1);
|
||||
}
|
||||
CHECK(dm_ta_skill(UINT32_MAX).status==DM_TA_EMPTY);
|
||||
CHECK(dm_ta_skill(1000000).status==DM_TA_UNKNOWN);
|
||||
dm_ta_frame f;CHECK(dm_ta_frame_at(8,18,&f));CHECK(f.x==1224&&f.y==0&&f.width==65&&f.height==65);
|
||||
CHECK(dm_ta_frame_at(8,39,&f));CHECK(!dm_ta_frame_at(8,40,&f));CHECK(!dm_ta_frame_at(9,0,&f));CHECK(!dm_ta_frame_at(0,-1,&f));
|
||||
CHECK(dm_ta_frame_at(7,59,&f));CHECK(!dm_ta_frame_at(7,60,&f));
|
||||
dm_tg_snapshot s={0};s.supported=s.valid=s.ready=1;s.source=1;s.identity_scope=1;s.captured_ns=1000;s.selected_bank=0;
|
||||
const uint32_t logicals[]={0x1000,0x2000,0x4000,0x8000,0x200,0x800};
|
||||
for(int i=0;i<6;i++){s.mapping[i]=(dm_tg_mapping){logicals[i],(uint32_t)i,(uint32_t)(i+6)};s.raw_skill_id[i]=ids[i];}
|
||||
/* 按原runtime tuple而非数组顺序:A normal0/B1/X3/Y2/R4。 | By the original runtime tuple rather than array order: A normal0/B1/X3/Y2/R4. */
|
||||
s.mapping[0].normal=1;s.mapping[1].normal=0;
|
||||
const uint64_t buttons[]={DM_BTN_A,DM_BTN_B,DM_BTN_X,DM_BTN_Y,DM_BTN_R};
|
||||
const int slots[]={0,1,3,2,4};
|
||||
for(int i=0;i<5;i++){g=dm_ta_current(&s,buttons[i],1000);CHECK(g.status==DM_TA_GLYPH);CHECK(g.slot==slots[i]);CHECK(g.raw_skill_id==ids[slots[i]]);CHECK(g.effective_slot==slots[i]);}
|
||||
/* 银行16所复制的12 ID数组独立,不能退回银行0图。 | The 12-ID array copied by bank 16 is independent and must not fall back to the bank 0 image. */
|
||||
s.selected_bank=16;for(int i=0;i<12;i++)s.raw_skill_id[i]=UINT32_MAX;
|
||||
g=dm_ta_current(&s,DM_BTN_A,1000);CHECK(g.status==DM_TA_EMPTY);CHECK(g.slot==0&&g.effective_slot==16);
|
||||
s.raw_skill_id[0]=395;g=dm_ta_current(&s,DM_BTN_A,1000);CHECK(g.atlas==7&&g.normal_frame==46&&g.effective_slot==16);
|
||||
s.raw_skill_id[0]=1000000;CHECK(dm_ta_current(&s,DM_BTN_A,1000).status==DM_TA_UNKNOWN);
|
||||
s.raw_skill_id[0]=0;
|
||||
CHECK(dm_ta_current(&s,DM_BTN_A,1000+DM_TG_MAX_AGE_NS).status==DM_TA_GLYPH);
|
||||
CHECK(dm_ta_current(&s,DM_BTN_A,1001+DM_TG_MAX_AGE_NS).status==DM_TA_UNKNOWN);
|
||||
CHECK(dm_ta_current(&s,DM_BTN_A,999).status==DM_TA_UNKNOWN);
|
||||
s.ready=0;CHECK(dm_ta_current(&s,DM_BTN_A,1000).status==DM_TA_UNKNOWN);s.ready=1;
|
||||
s.valid=0;CHECK(dm_ta_current(&s,DM_BTN_A,1000).status==DM_TA_UNKNOWN);s.valid=1;
|
||||
s.supported=0;CHECK(dm_ta_current(&s,DM_BTN_A,1000).status==DM_TA_UNKNOWN);s.supported=1;
|
||||
s.source=0;CHECK(dm_ta_current(&s,DM_BTN_A,1000).status==DM_TA_UNKNOWN);s.source=1;
|
||||
s.identity_scope=2;CHECK(dm_ta_current(&s,DM_BTN_A,1000).status==DM_TA_UNKNOWN);s.identity_scope=1;
|
||||
s.captured_ns=0;CHECK(dm_ta_current(&s,DM_BTN_A,1000).status==DM_TA_UNKNOWN);s.captured_ns=1000;
|
||||
s.selected_bank=1;CHECK(dm_ta_current(&s,DM_BTN_A,1000).status==DM_TA_UNKNOWN);s.selected_bank=0;
|
||||
CHECK(dm_ta_current(&s,DM_BTN_A|DM_BTN_B,1000).status==DM_TA_UNKNOWN);
|
||||
printf("PASS native_art: %u/%u checks; official IDs6; tuple facets5; banks0/16; frame bounds; freshness/source/identity gates\n",checks,checks);return 0;
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
#include "dm_touch_game_state.h"
|
||||
#include "dm_touch_controls.h"
|
||||
#include "../../host/dm_input.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
static int checks;
|
||||
#define CHECK(x) do { ++checks; if(!(x)) { fprintf(stderr,"FAIL line=%d %s\n",__LINE__,#x); exit(1); } } while(0)
|
||||
#ifdef RED_BASELINE
|
||||
/* 测试专用缺失功能基线,不进入Sources。 | Test-only missing-feature baseline, does not go into Sources. */
|
||||
int dm_tg_parse(dm_tg_snapshot *o,const void *m,size_t ml,const void *b,size_t bl,int k,int input,int i,uint32_t id,uint64_t n) {(void)m;(void)ml;(void)b;(void)bl;(void)k;(void)input;(void)i;(void)id;(void)n;memset(o,0,sizeof(*o));return 0;}
|
||||
void dm_tc_set_portal_button(dm_tc_state *s,uint64_t b) {(void)s;(void)b;}
|
||||
#endif
|
||||
void dm_tc_set_portal_button(dm_tc_state *,uint64_t);
|
||||
static void put(unsigned char *p,uint32_t v) { for(int i=0;i<4;i++)p[i]=(unsigned char)(v>>(i*8)); }
|
||||
static void press(dm_tc_state *s,int n,int t) { dm_tc_begin(s,n,s->layout.target[t].x,s->layout.target[t].y); }
|
||||
int main(int argc,char **argv) {
|
||||
CHECK(argc==3); unsigned char map[114],table[896];
|
||||
FILE *f=fopen(argv[1],"rb"); CHECK(f!=NULL);CHECK(fread(map,1,sizeof map,f)==sizeof map);fclose(f);
|
||||
f=fopen(argv[2],"rb");CHECK(f!=NULL);CHECK(fread(table,1,sizeof table,f)==sizeof table);fclose(f);
|
||||
dm_tg_snapshot s;
|
||||
CHECK(dm_tg_parse(&s,map,sizeof map,table,12*28,0,(7-0),7,359,99));
|
||||
CHECK(s.valid && s.source==DM_TG_SOURCE_NATIVE_GETTER && s.selected_bank==0 && s.captured_ns==99);
|
||||
CHECK(s.mapping[0].logical==0x1000 && s.mapping[0].normal==1 && s.mapping[0].alt==7);
|
||||
CHECK(s.portal.valid && s.portal.slot==7 && s.portal.raw_skill_id==359 && s.portal.buttons==(DM_BTN_ZL|DM_BTN_B));
|
||||
unsigned char changed[896]; memcpy(changed,table,sizeof changed);
|
||||
put(changed+7*28,UINT32_MAX);put(changed+6*28,220);
|
||||
CHECK(dm_tg_parse(&s,map,72,changed,336,0,(6-0),6,220,100));CHECK(s.portal.buttons==(DM_BTN_ZL|DM_BTN_A));
|
||||
put(changed+6*28,UINT32_MAX);put(changed+5*28,219);
|
||||
CHECK(dm_tg_parse(&s,map,72,changed,336,0,(5-0),5,219,101));CHECK(s.portal.buttons==DM_BTN_ZR);
|
||||
put(changed+5*28,UINT32_MAX);
|
||||
CHECK(dm_tg_parse(&s,map,72,changed,336,0,(0-0),0,0,102));CHECK(s.valid && !s.portal.valid && s.portal.buttons==0);
|
||||
CHECK(dm_tg_parse(&s,map,72,table+16*28,336,16,(16-16),16,UINT32_MAX,103));CHECK(s.selected_bank==16 && !s.portal.valid);
|
||||
CHECK(!dm_tg_parse(&s,map,71,table,336,0,(7-0),7,359,1));CHECK(!s.valid && !s.portal.buttons);
|
||||
CHECK(!dm_tg_parse(&s,map,72,table,335,0,(7-0),7,359,1));
|
||||
CHECK(!dm_tg_parse(&s,map,72,table,336,0,(12-0),12,359,1));
|
||||
CHECK(!dm_tg_parse(&s,map,72,table,336,16,(7-16),7,359,1));
|
||||
CHECK(!dm_tg_parse(&s,map,72,table,336,0,(7-0),7,220,1));
|
||||
unsigned char badmap[72];memcpy(badmap,map,72);put(badmap+12,0x1000);
|
||||
CHECK(!dm_tg_parse(&s,badmap,72,table,336,0,(7-0),7,359,1));
|
||||
memcpy(badmap,map,72);put(badmap+16,1);CHECK(!dm_tg_parse(&s,badmap,72,table,336,0,(7-0),7,359,1));
|
||||
memcpy(badmap,map,72);put(badmap+20,7);CHECK(!dm_tg_parse(&s,badmap,72,table,336,0,(7-0),7,359,1));
|
||||
memcpy(badmap,map,72);put(badmap,0xDEAD);CHECK(!dm_tg_parse(&s,badmap,72,table,336,0,(7-0),7,359,1));
|
||||
const uint64_t facets[6]={DM_BTN_B,DM_BTN_A,DM_BTN_Y,DM_BTN_X,DM_BTN_R,DM_BTN_ZR};
|
||||
for(int alt=0;alt<2;alt++)for(int facet=0;facet<6;facet++) {
|
||||
memset(changed,255,sizeof changed);int slot=map[facet*12+(alt?8:4)];put(changed+slot*28,359);
|
||||
CHECK(dm_tg_parse(&s,map,72,changed,336,0,(slot-0),slot,359,104));
|
||||
CHECK(s.portal.buttons==(facets[facet]|(alt?DM_BTN_ZL:0)) && s.portal.slot==slot);
|
||||
}
|
||||
memset(changed,255,sizeof changed);put(changed,219);put(changed+7*28,359);
|
||||
CHECK(dm_tg_parse(&s,map,72,changed,336,0,(0-0),0,219,105));CHECK(s.portal.slot==7);
|
||||
put(changed+7*28,360);put(changed,UINT32_MAX);
|
||||
CHECK(dm_tg_parse(&s,map,72,changed,336,0,(7-0),7,360,106));CHECK(!s.portal.valid && !s.portal.buttons);
|
||||
dm_tc_state c;dm_tc_init(&c,667,375);dm_tc_set_portal_button(&c,DM_BTN_ZL|DM_BTN_B);
|
||||
press(&c,0,DM_TC_PORTAL);press(&c,1,DM_TC_MAIN);dm_tc_begin(&c,2,100,200);dm_tc_move(&c,2,150,200);
|
||||
CHECK(c.buttons==(DM_BTN_ZL|DM_BTN_A) && c.portal_pending);
|
||||
CHECK(dm_tc_portal_ack(&c,c.gesture_epoch,0,0));
|
||||
CHECK(c.buttons==(DM_BTN_ZL|DM_BTN_B|DM_BTN_A));int32_t lx=c.lx;
|
||||
dm_tc_set_portal_button(&c,DM_BTN_ZL|DM_BTN_B);CHECK(c.finger[0].active);
|
||||
dm_tc_set_portal_button(&c,DM_BTN_ZL|DM_BTN_A);
|
||||
CHECK(!c.finger[0].active && c.finger[1].active && c.finger[2].active && c.lx==lx && c.buttons==DM_BTN_A);
|
||||
dm_tc_resize(&c,812,375);CHECK(c.layout.target[DM_TC_PORTAL].button==(DM_BTN_ZL|DM_BTN_A));
|
||||
dm_tc_set_portal_button(&c,0);press(&c,0,DM_TC_PORTAL);CHECK(c.buttons==0 && c.joy_slot==-1);
|
||||
printf("PASS native binding fixture+negative+ownership %d/%d checks\n",checks,checks);return 0;
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
#include "dm_touch_game_state.h"
|
||||
#include "../../host/dm.h"
|
||||
#ifdef RED_BASELINE
|
||||
#define SCENE(g,s,w) dm_touch_game_set_scene(g,s)
|
||||
#define WORLD(s) 0
|
||||
#else
|
||||
#define SCENE(g,s,w) dm_touch_game_set_scene(g,s,w)
|
||||
#define WORLD(s) ((s).world_epoch)
|
||||
#endif
|
||||
module_t g_mod[MAX_MOD];int g_nmod;
|
||||
static void (*hook)(const uint64_t *);
|
||||
static int checks,clock_reads,x23_off; /* x23_off!=0:让到门时 x23 != x19(不是 HUD updater 那条调用) | x23_off!=0: make x23 != x19 on reaching the gate (not the HUD updater call path) */static uint64_t clock_ns=1000;
|
||||
int gate_obs_present(int id){return id==6;}
|
||||
void gate_obs_set(int id,void (*fn)(const uint64_t *)){if(id==6)hook=fn;}
|
||||
uint64_t now_ns(void){clock_reads++;return ++clock_ns;}
|
||||
#define CHECK(x) do{checks++;if(!(x)){fprintf(stderr,"FAIL line=%d %s\n",__LINE__,#x);exit(1);}}while(0)
|
||||
static void emit(uint64_t *regs,uint64_t *frame,unsigned char widget[7][0xc98],int slot,int arg,uint64_t caller){frame[1]=(uint64_t)widget[slot];frame[3]=caller;regs[19]=(uint64_t)arg;regs[23]=(uint64_t)arg+(uint64_t)x23_off;regs[8]=(uint64_t)arg*28;uint64_t before[31],stack_before[8];unsigned char widgets_before[7][0xc98];memcpy(before,regs,sizeof before);memcpy(stack_before,frame,sizeof stack_before);memcpy(widgets_before,widget,sizeof widgets_before);hook(regs);CHECK(!memcmp(before,regs,sizeof before) && !memcmp(stack_before,frame,sizeof stack_before) && !memcmp(widgets_before,widget,sizeof widgets_before));}
|
||||
int main(int argc,char **argv){
|
||||
CHECK(argc==3);size_t size=0x2d5f0c0+896;unsigned char *mem=calloc(1,size);CHECK(mem!=NULL);g_nmod=1;g_mod[0].base=mem;g_mod[0].size=size;strcpy(g_mod[0].name,"main");
|
||||
FILE *f=fopen(argv[1],"rb");CHECK(f!=NULL);CHECK(fread(mem+0x2d13cbc,1,72,f)==72);fclose(f);f=fopen(argv[2],"rb");CHECK(f!=NULL);CHECK(fread(mem+0x2d5f0c0,1,896,f)==896);fclose(f);
|
||||
unsigned char original_mapping[72],original_table[896];memcpy(original_mapping,mem+0x2d13cbc,72);memcpy(original_table,mem+0x2d5f0c0,896);
|
||||
unsigned char widget[7][0xc98]={{0}};for(uint32_t i=0;i<7;i++){uint32_t slot=i<6?i:5;memcpy(widget[i]+0xb18,&slot,4);}
|
||||
uint64_t regs[31]={0},frame[8]={0};regs[29]=(uint64_t)&frame[2];regs[10]=(uint64_t)(mem+0x2d5f0c0);uint64_t hud_lr=(uint64_t)mem+0x3e2f74;dm_tg_snapshot s,before;
|
||||
CHECK(dm_touch_game_attach() && hook!=NULL);SCENE(1,2,1);
|
||||
for(int i=0;i<6;i++)emit(regs,frame,widget,i,i,hud_lr);
|
||||
CHECK(!dm_touch_game_snapshot(&s) && !s.ready && clock_reads==0); // 首cohort不借第六体变ready。 | the first cohort does not borrow the sixth body to become ready.
|
||||
for(int i=0;i<6;i++)emit(regs,frame,widget,i,i,hud_lr);
|
||||
CHECK(dm_touch_game_snapshot(&s) && s.ready && s.identity_scope==DM_TG_IDENTITY_NATIVE && s.group_seen==63 && s.portal.buttons==258 && WORLD(s)==1);
|
||||
before=s;int reads=clock_reads;
|
||||
for(int i=0;i<12;i++)emit(regs,frame,widget,i%6,i,(uint64_t)mem+0x2fa1d0);
|
||||
CHECK(dm_touch_game_snapshot(&s) && !memcmp(&s,&before,sizeof s) && clock_reads==reads); // cache不撤、不续时。 | cache is not revoked and its time is not extended.
|
||||
x23_off=1;for(int i=0;i<6;i++)emit(regs,frame,widget,i,i+6,hud_lr);x23_off=0;
|
||||
CHECK(dm_touch_game_snapshot(&s) && !memcmp(&s,&before,sizeof s) && clock_reads==reads); // 前置筛:栈帧里的返回地址与控件都对、只有 x23 != x19,也当非 HUD 调用忽略——不切组、不续时。 | pre-filter: the return address in the stack frame and the widget are both right and only x23 != x19, still ignored as a non-HUD call - no set switch, no time extension.
|
||||
emit(regs,frame,widget,5,16,hud_lr);CHECK(dm_touch_game_snapshot(&s) && !memcmp(&s,&before,sizeof s));
|
||||
emit(regs,frame,widget,5,0,hud_lr);CHECK(dm_touch_game_snapshot(&s) && !memcmp(&s,&before,sizeof s));
|
||||
widget[5][0xc90]=1;emit(regs,frame,widget,5,11,hud_lr);widget[5][0xc90]=0;CHECK(dm_touch_game_snapshot(&s) && !memcmp(&s,&before,sizeof s));
|
||||
uint64_t fp=regs[29];regs[29]=1;emit(regs,frame,widget,5,11,hud_lr);regs[29]=fp;CHECK(dm_touch_game_snapshot(&s) && !memcmp(&s,&before,sizeof s));
|
||||
emit(regs,frame,widget,6,11,hud_lr);CHECK(dm_touch_game_snapshot(&s) && !memcmp(&s,&before,sizeof s));
|
||||
CHECK(dm_tg_portal_mask(&s,s.captured_ns+250000001)==0); // cache不能延长fresh窗口。 | cache must not extend the fresh window.
|
||||
for(int i=0;i<6;i++)emit(regs,frame,widget,i,i+6,hud_lr);
|
||||
CHECK(dm_touch_game_snapshot(&s) && s.ready && s.secondary_group && s.group_started_ns>before.captured_ns && s.hud_identity==before.hud_identity);
|
||||
uint64_t cohort=s.hud_identity;SCENE(0,3,1);emit(regs,frame,widget,6,11,hud_lr);CHECK(!dm_touch_game_snapshot(&s));
|
||||
SCENE(1,4,1);emit(regs,frame,widget,6,11,hud_lr);CHECK(!dm_touch_game_snapshot(&s)); // 菜单六体不追认/回game不重学。 | the six menu bodies are not retroactively accepted / returning to game does not relearn.
|
||||
for(int i=0;i<6;i++)emit(regs,frame,widget,i,i,hud_lr);CHECK(dm_touch_game_snapshot(&s) && s.ready && s.hud_identity==cohort);
|
||||
SCENE(0,5,2);for(int i=0;i<6;i++)emit(regs,frame,widget,i,i,hud_lr);CHECK(!dm_touch_game_snapshot(&s));
|
||||
SCENE(1,6,3);for(int i=0;i<6;i++)emit(regs,frame,widget,i,i,hud_lr);CHECK(!dm_touch_game_snapshot(&s));
|
||||
for(int i=0;i<6;i++)emit(regs,frame,widget,i,i,hud_lr);CHECK(dm_touch_game_snapshot(&s) && s.ready && WORLD(s)==3 && s.hud_identity!=cohort);
|
||||
CHECK(!memcmp(original_mapping,mem+0x2d13cbc,72) && !memcmp(original_table,mem+0x2d5f0c0,896));
|
||||
free(mem);printf("PASS production strong HUD Mach ABI -> group/ignore/world bridge %d/%d checks\n",checks,checks);return 0;
|
||||
}
|
||||
|
||||
int dm_swapskill_equipped(int32_t item) { (void)item; return 0; } /* 副手组技能(宿主 dm_actions.c):单测里没有穿着的物品 | Secondary weapon set skills (host dm_actions.c): there are no worn items in the unit test */
|
||||
@@ -0,0 +1,44 @@
|
||||
#include "dm_touch_game_identity.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#ifdef RED_BASELINE
|
||||
int dm_tg_hud_identity(dm_tg_hud_cohort *c,const uint64_t *r,uint64_t b,int g,uint64_t w,dm_tg_read_fn f,uint64_t *l,uint64_t *h){(void)c;(void)r;(void)b;(void)g;(void)w;(void)f;*l=*h=0;return 0;}
|
||||
void dm_tg_hud_reset(dm_tg_hud_cohort *c,uint64_t w){memset(c,0,sizeof(*c));c->world_epoch=w;}
|
||||
int dm_tg_vm_read(uint64_t a,void *o,size_t n){memcpy(o,(const void *)a,n);return 1;}
|
||||
#endif
|
||||
static int checks,readonly_calls;
|
||||
static int observed(dm_tg_hud_cohort *c,const uint64_t *r,uint64_t b,int game,uint64_t world,dm_tg_read_fn read_fn,uint64_t *caller,uint64_t *hud) {
|
||||
uint64_t before[31];memcpy(before,r,sizeof before);
|
||||
int result=dm_tg_hud_identity(c,r,b,game,world,read_fn,caller,hud);
|
||||
if(memcmp(before,r,sizeof before)){fprintf(stderr,"FAIL native resolver changed regs\n");exit(1);}++readonly_calls;return result;
|
||||
}
|
||||
#define dm_tg_hud_identity observed
|
||||
#define CHECK(x) do{checks++;if(!(x)){fprintf(stderr,"FAIL line=%d %s\n",__LINE__,#x);exit(1);}}while(0)
|
||||
static int failed_read(uint64_t a,void *o,size_t n){(void)a;(void)o;(void)n;return 0;}
|
||||
static void put32(unsigned char *p,uint32_t n){memcpy(p,&n,4);}
|
||||
int main(void){
|
||||
const uint64_t base=0x123000000;unsigned char widget[7][0xc98]={{0}};uint64_t frame[8]={0},regs[31]={0},caller=0,hud=0;
|
||||
regs[29]=(uint64_t)&frame[2];frame[3]=base+0x3e2f74;dm_tg_hud_cohort c;dm_tg_hud_reset(&c,1);
|
||||
for(int i=0;i<6;i++) {put32(widget[i]+0xb18,(uint32_t)i);frame[1]=(uint64_t)widget[i];regs[19]=(uint64_t)i;CHECK(dm_tg_hud_identity(&c,regs,base,1,1,dm_tg_vm_read,&caller,&hud)==0);}
|
||||
CHECK(c.confirmed && c.seen==63 && c.hud_identity!=0);uint64_t identity=c.hud_identity;
|
||||
for(int i=0;i<6;i++){frame[1]=(uint64_t)widget[i];regs[19]=(uint64_t)(i+6);CHECK(dm_tg_hud_identity(&c,regs,base,1,1,dm_tg_vm_read,&caller,&hud)==DM_TG_IDENTITY_NATIVE);CHECK(caller==base+0x3e2f74 && hud==identity);}
|
||||
unsigned char original[sizeof widget];memcpy(original,widget,sizeof widget);
|
||||
frame[3]=base+0x2fa1d0;for(int i=0;i<12;i++){regs[19]=(uint64_t)i;CHECK(dm_tg_hud_identity(&c,regs,base,1,1,dm_tg_vm_read,&caller,&hud)==0);}CHECK(c.hud_identity==identity && c.confirmed);
|
||||
frame[3]=base+0x3e2f74;regs[19]=16;CHECK(!dm_tg_hud_identity(&c,regs,base,1,1,dm_tg_vm_read,&caller,&hud));
|
||||
regs[19]=0;frame[1]=(uint64_t)widget[5];CHECK(!dm_tg_hud_identity(&c,regs,base,1,1,dm_tg_vm_read,&caller,&hud)); // widget enum5 versus arg0
|
||||
regs[19]=11;widget[5][0xc90]=1;CHECK(!dm_tg_hud_identity(&c,regs,base,1,1,dm_tg_vm_read,&caller,&hud));widget[5][0xc90]=0;
|
||||
CHECK(!dm_tg_hud_identity(&c,regs,base,1,1,failed_read,&caller,&hud));
|
||||
CHECK(!dm_tg_hud_identity(&c,regs,base,0,1,dm_tg_vm_read,&caller,&hud));CHECK(c.hud_identity==identity && c.confirmed);
|
||||
put32(widget[6]+0xb18,5);frame[1]=(uint64_t)widget[6];CHECK(!dm_tg_hud_identity(&c,regs,base,1,1,dm_tg_vm_read,&caller,&hud));CHECK(c.widget[5]==(uint64_t)widget[5] && c.hud_identity==identity);
|
||||
dm_tg_hud_reset(&c,2);CHECK(!c.confirmed && !c.seen);
|
||||
for(int i=0;i<6;i++){frame[1]=(uint64_t)widget[i];regs[19]=(uint64_t)i;CHECK(!dm_tg_hud_identity(&c,regs,base,0,2,dm_tg_vm_read,&caller,&hud));}CHECK(!c.seen && !c.confirmed);
|
||||
for(int i=0;i<6;i++){frame[1]=(uint64_t)widget[i];regs[19]=(uint64_t)i;CHECK(!dm_tg_hud_identity(&c,regs,base,1,2,dm_tg_vm_read,&caller,&hud));}CHECK(c.confirmed && c.hud_identity!=identity);
|
||||
frame[1]=(uint64_t)widget[5];regs[19]=5;CHECK(dm_tg_hud_identity(&c,regs,base,1,2,dm_tg_vm_read,&caller,&hud)==1);
|
||||
frame[1]=1;regs[19]=5;CHECK(!dm_tg_hud_identity(&c,regs,base,1,2,dm_tg_vm_read,&caller,&hud)); // 真Mach读取坏堆指针。 | a real Mach read of a bad heap pointer.
|
||||
dm_tg_hud_reset(&c,3);frame[1]=(uint64_t)widget[0];regs[19]=0;CHECK(!dm_tg_hud_identity(&c,regs,base,1,3,dm_tg_vm_read,&caller,&hud));
|
||||
put32(widget[0]+0xb18,1);regs[19]=1;CHECK(!dm_tg_hud_identity(&c,regs,base,1,3,dm_tg_vm_read,&caller,&hud));CHECK(c.seen==1 && !c.widget[1]);put32(widget[0]+0xb18,0);
|
||||
CHECK(!dm_tg_vm_read(1,&caller,8));CHECK(!dm_tg_vm_read(UINT64_MAX,&caller,8));
|
||||
CHECK(!memcmp(widget,original,6*sizeof widget[0])); // 原six widget无写入;第七是测试替身。 | no writes to the original six widgets; the seventh is a test double.
|
||||
printf("PASS native Mach FramePointer/HUD cohort/cache/world negative %d/%d checks; %d/%d calls regs read-only\n",checks,checks,readonly_calls,readonly_calls);return 0;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
#include "dm_touch_controls.h"
|
||||
#include "../../host/dm_input.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#ifdef RED_BASELINE
|
||||
/* v2测试替身:旧直接组合与缺失ACK。 | v2 test double: old direct combination and missing ACK. */
|
||||
static int dm_tc_portal_ack(dm_tc_state *s,uint64_t e,uint64_t b,uint64_t c){(void)s;(void)e;(void)b;(void)c;return 0;}
|
||||
static void dm_tc_set_portal_binding(dm_tc_state *s,uint64_t mask,uint64_t b,uint64_t c){(void)b;(void)c;dm_tc_set_portal_button(s,mask);}
|
||||
#define EPOCH(s) 0
|
||||
#else
|
||||
#define EPOCH(s) ((s).gesture_epoch)
|
||||
#endif
|
||||
static int checks;
|
||||
#define CHECK(x) do{checks++;if(!(x)){fprintf(stderr,"FAIL line=%d %s\n",__LINE__,#x);exit(1);}}while(0)
|
||||
static void press(dm_tc_state *s,int n,int target){dm_tc_begin(s,n,s->layout.target[target].x,s->layout.target[target].y); if(target>=DM_TC_MAIN && target<=DM_TC_SKILL4) dm_tc_tick(s,s->last_time_s+0.1); /* 主钮 / 技能钮按下后有判定时间(点按还是拖动),这里的「按下」= 已过判定时间 | After the main button / a skill button is pressed there is a decision time (tap or drag); here "pressed" = the decision time has passed */}
|
||||
int main(void){
|
||||
dm_tc_state s;dm_tc_init(&s,667,375);dm_tc_set_portal_binding(&s,258,77,3);press(&s,0,DM_TC_PORTAL);
|
||||
CHECK(s.buttons==256);uint64_t epoch=EPOCH(s);
|
||||
press(&s,1,DM_TC_MAIN);dm_tc_begin(&s,2,90,275);dm_tc_move(&s,2,150,275);CHECK(s.buttons==257 && s.lx==32767);
|
||||
CHECK(!dm_tc_portal_ack(&s,epoch+1,77,3));CHECK(!dm_tc_portal_ack(&s,epoch,78,3));CHECK(!dm_tc_portal_ack(&s,epoch,77,4));CHECK(s.buttons==257);
|
||||
press(&s,3,DM_TC_PORTAL);CHECK(EPOCH(s)==epoch && s.buttons==257);
|
||||
CHECK(dm_tc_portal_ack(&s,epoch,77,3));CHECK(s.buttons==259 && s.lx==32767);CHECK(!dm_tc_portal_ack(&s,epoch,77,3));
|
||||
press(&s,4,DM_TC_PORTAL);CHECK(EPOCH(s)==epoch && s.buttons==259);
|
||||
dm_tc_end(&s,0);CHECK(s.buttons==259 && s.lx==32767 && s.finger[3].active && s.finger[4].active && EPOCH(s)==epoch);
|
||||
dm_tc_end(&s,3);CHECK(s.buttons==259 && EPOCH(s)==epoch);dm_tc_end(&s,4);CHECK(s.buttons==1 && s.lx==32767);CHECK(!dm_tc_portal_ack(&s,epoch,77,3));
|
||||
press(&s,0,DM_TC_PORTAL);epoch=EPOCH(s);CHECK(s.buttons==257);dm_tc_set_portal_binding(&s,258,78,3);CHECK(s.buttons==1 && s.lx==32767);CHECK(!dm_tc_portal_ack(&s,epoch,77,3));
|
||||
press(&s,0,DM_TC_PORTAL);epoch=EPOCH(s);dm_tc_set_portal_binding(&s,258,78,4);CHECK(s.buttons==1);CHECK(!dm_tc_portal_ack(&s,epoch,78,3));
|
||||
press(&s,0,DM_TC_PORTAL);epoch=EPOCH(s);dm_tc_set_portal_button(&s,0);CHECK(s.buttons==1 && s.lx==32767);CHECK(!dm_tc_portal_ack(&s,epoch,78,4));
|
||||
dm_tc_set_portal_binding(&s,258,79,4);press(&s,0,DM_TC_PORTAL);epoch=EPOCH(s);dm_tc_end(&s,0);CHECK(s.buttons==1);CHECK(!dm_tc_portal_ack(&s,epoch,79,4));
|
||||
press(&s,0,DM_TC_PORTAL);epoch=EPOCH(s);dm_tc_cancel_all(&s);CHECK(s.buttons==0 && s.lx==0);CHECK(!dm_tc_portal_ack(&s,epoch,79,4));
|
||||
press(&s,0,DM_TC_PORTAL);epoch=EPOCH(s);dm_tc_resize(&s,812,375);CHECK(s.buttons==0);CHECK(!dm_tc_portal_ack(&s,epoch,79,4));
|
||||
dm_tc_set_portal_binding(&s,512,80,5);press(&s,0,DM_TC_PORTAL);CHECK(s.buttons==512);dm_tc_end(&s,0);CHECK(s.buttons==0);
|
||||
dm_tc_set_portal_binding(&s,258,81,6);press(&s,0,DM_TC_PORTAL);epoch=EPOCH(s);press(&s,1,DM_TC_PORTAL);
|
||||
CHECK(s.buttons==256 && EPOCH(s)==epoch);dm_tc_end(&s,0);CHECK(s.buttons==256 && EPOCH(s)==epoch);
|
||||
CHECK(dm_tc_portal_ack(&s,epoch,81,6));CHECK(s.buttons==258);dm_tc_end(&s,1);CHECK(s.buttons==0);CHECK(!dm_tc_portal_ack(&s,epoch,81,6));
|
||||
printf("PASS portal two-stage+epoch+end/cancel/identity/scene %d/%d checks\n",checks,checks);return 0;
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
#include "dm_touch_controls.h"
|
||||
#include "../../host/dm_input.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
static int checks;
|
||||
#define CHECK(x) do { ++checks; if (!(x)) { fprintf(stderr,"FAIL line=%d %s\n",__LINE__,#x); exit(1); } } while (0)
|
||||
static void begin(dm_tc_state *s,int n,int target) { dm_tc_begin(s,n,s->layout.target[target].x,s->layout.target[target].y); if(target>=DM_TC_MAIN && target<=DM_TC_SKILL4) dm_tc_tick(s,s->last_time_s+0.1); /* 主钮 / 技能钮按下后有判定时间(点按还是拖动),这里的「按下」= 已过判定时间 | After the main button / a skill button is pressed there is a decision time (tap or drag); here "pressed" = the decision time has passed */ }
|
||||
static void drag(dm_tc_state *s,int n,int target,float dx,float dy) { dm_tc_move(s,n,s->layout.target[target].x+dx,s->layout.target[target].y+dy); }
|
||||
int main(void) {
|
||||
dm_tc_state s; dm_tc_init(&s,667,375);
|
||||
CHECK(s.rx==0 && s.ry==0 && s.aim_slot==DM_TC_NONE && !s.navigation_mode && !s.map_cancel_active);
|
||||
begin(&s,0,DM_TC_MAIN); CHECK(s.buttons==DM_BTN_A && s.rx==0 && s.ry==0);
|
||||
drag(&s,0,DM_TC_MAIN,60,0); CHECK(s.rx==32767 && s.ry==0 && s.aim_slot==0);
|
||||
drag(&s,0,DM_TC_MAIN,0,60); CHECK(s.rx==0 && s.ry==-32767);
|
||||
drag(&s,0,DM_TC_MAIN,30,-30); CHECK(s.rx==16384 && s.ry==16384);
|
||||
drag(&s,0,DM_TC_MAIN,120,-120); CHECK(s.rx==32767 && s.ry==32767);
|
||||
drag(&s,0,DM_TC_MAIN,0,0); CHECK(s.rx==0 && s.ry==0 && s.aim_slot==0);
|
||||
dm_tc_begin(&s,1,90,275); dm_tc_move(&s,1,150,275);
|
||||
drag(&s,0,DM_TC_MAIN,60,0); CHECK(s.lx==32767 && s.ly==0 && s.rx==32767 && s.ry==0);
|
||||
/* 技能钮与主钮同一套:按下即键下、按住 = 持续施放,后拖动的那根手指定方向,松手键起、不发脉冲 | On-screen skill buttons use the same scheme as the main button: key down on press, hold = continuous cast, the finger that dragged later sets the direction, on release the key goes up, no pulse sent */
|
||||
begin(&s,2,DM_TC_SKILL1); CHECK(s.buttons==(DM_BTN_A|DM_BTN_B));
|
||||
drag(&s,2,DM_TC_SKILL1,0,60); CHECK(s.lx==32767 && s.rx==0 && s.ry==-32767 && s.aim_slot==2 && s.buttons==(DM_BTN_A|DM_BTN_B));
|
||||
dm_tc_tick(&s,s.last_time_s+0.1); dm_tc_end(&s,2); CHECK(s.buttons==DM_BTN_A && s.rx==32767 && s.ry==0 && s.aim_slot==0 && !s.pulse_button); /* 键已按住够久:松手键起,不补脉冲 | The key has been held long enough: on release the key goes up, no make-up pulse */
|
||||
begin(&s,2,DM_TC_MAIN);
|
||||
dm_tc_target map=s.layout.target[DM_TC_MAP];
|
||||
dm_tc_move(&s,2,map.x+map.r,map.y-map.r);
|
||||
CHECK(s.map_cancel_active && s.buttons==DM_BTN_A && s.rx==32767 && s.lx==32767);
|
||||
dm_tc_move(&s,2,map.x-map.r-1,map.y); CHECK(!s.map_cancel_active && s.buttons==DM_BTN_A && s.aim_slot==0);
|
||||
dm_tc_end(&s,0); CHECK(s.buttons==0 && s.rx==0 && s.ry==0 && s.aim_slot==DM_TC_NONE && s.lx==32767);
|
||||
drag(&s,2,DM_TC_MAIN,60,0); CHECK(s.buttons==0 && s.rx==0 && s.ry==0);
|
||||
dm_tc_end(&s,2); CHECK(!s.map_cancel_active);
|
||||
begin(&s,0,DM_TC_SKILL2); drag(&s,0,DM_TC_SKILL2,60,0);
|
||||
dm_tc_move(&s,0,map.x,map.y); CHECK(s.map_cancel_active && s.buttons==0 && s.rx==0 && s.ry==0 && s.lx==32767);
|
||||
dm_tc_end(&s,0); CHECK(!s.map_cancel_active && s.lx==32767 && s.buttons==0 && !s.pulse_button); /* 取消区松手不放 | Releasing in the cancel zone does not cast */
|
||||
begin(&s,0,DM_TC_MAIN); drag(&s,0,DM_TC_MAIN,60,0);
|
||||
dm_tc_set_navigation_mode(&s,1); CHECK(s.navigation_mode && s.buttons==0 && s.lx==0 && s.rx==0 && s.ry==0);
|
||||
begin(&s,0,DM_TC_MAIN); drag(&s,0,DM_TC_MAIN,60,0); CHECK(s.buttons==DM_BTN_A && s.rx==0 && s.ry==0);
|
||||
dm_tc_move(&s,0,map.x,map.y); CHECK(!s.map_cancel_active && s.buttons==DM_BTN_A);
|
||||
dm_tc_set_navigation_mode(&s,1); CHECK(s.buttons==DM_BTN_A); /* identical mode does not cancel */
|
||||
dm_tc_set_navigation_mode(&s,0); CHECK(!s.navigation_mode && s.buttons==0 && s.rx==0 && s.ry==0);
|
||||
begin(&s,0,DM_TC_SKILL3); drag(&s,0,DM_TC_SKILL3,-60,0); CHECK(s.buttons==DM_BTN_Y && s.rx==-32767 && s.ry==0); /* 按住技能钮拖动:键一直按着,朝拖动方向 | Hold an on-screen skill button and drag: the key stays down, facing the drag direction */
|
||||
dm_tc_move(&s,0,NAN,0); CHECK(s.buttons==DM_BTN_Y && s.rx==-32767); dm_tc_tick(&s,s.last_time_s+0.1); dm_tc_end(&s,0); CHECK(s.buttons==0 && s.rx==0 && s.ry==0 && !s.pulse_button); /* 坏坐标不动;松手键起 | Bad coordinates do nothing; on release the key goes up */
|
||||
dm_tc_cancel_all(&s); CHECK(s.buttons==0 && s.rx==0 && s.ry==0 && s.aim_slot==DM_TC_NONE && !s.map_cancel_active && !s.pulse_button);
|
||||
begin(&s,0,DM_TC_SKILL4); drag(&s,0,DM_TC_SKILL4,5,-5);
|
||||
CHECK(s.buttons==DM_BTN_R && s.rx==0 && s.ry==0); /* 拖动不过 10 点死区 = 点按:不给方向,原版自动选目标 | A drag that does not pass the 10-point dead zone = a tap: no direction given, the original game auto-selects the target */
|
||||
dm_tc_tick(&s,s.last_time_s+0.1); dm_tc_end(&s,0); CHECK(s.buttons==0);
|
||||
begin(&s,0,DM_TC_SKILL4); drag(&s,0,DM_TC_SKILL4,0,-60);
|
||||
dm_tc_resize(&s,333.5f,187.5f); CHECK(s.rx==0 && s.ry==0 && s.buttons==0 && s.aim_slot==DM_TC_NONE && !s.pulse_button);
|
||||
begin(&s,0,DM_TC_MAIN); drag(&s,0,DM_TC_MAIN,15,-15); CHECK(s.rx==16384 && s.ry==16384);
|
||||
dm_tc_enable_targets(&s,0); CHECK(s.rx==0 && s.ry==0 && s.buttons==0);
|
||||
dm_tc_enable_targets(&s,(1u<<DM_TC_COUNT)-1);
|
||||
const int non_skill[]={DM_TC_PORTAL,DM_TC_BELT1,DM_TC_MENU,DM_TC_MAP};
|
||||
for(unsigned i=0;i<sizeof(non_skill)/sizeof(*non_skill);i++) {
|
||||
begin(&s,0,non_skill[i]); drag(&s,0,non_skill[i],30,-30); CHECK(s.rx==0 && s.ry==0 && s.aim_slot==DM_TC_NONE); dm_tc_end(&s,0);
|
||||
}
|
||||
dm_tc_resize(&s,667,375); dm_tc_set_portal_binding(&s,DM_BTN_ZL|DM_BTN_B,77,3); begin(&s,3,DM_TC_PORTAL);
|
||||
begin(&s,0,DM_TC_MAIN); drag(&s,0,DM_TC_MAIN,60,0);
|
||||
CHECK(s.buttons==(DM_BTN_ZL|DM_BTN_A) && s.rx==32767);
|
||||
CHECK(dm_tc_portal_ack(&s,s.gesture_epoch,77,3)); CHECK(s.buttons==(DM_BTN_ZL|DM_BTN_B|DM_BTN_A) && s.rx==32767);
|
||||
dm_tc_end(&s,0); CHECK(s.buttons==(DM_BTN_ZL|DM_BTN_B) && s.rx==0); dm_tc_end(&s,3); CHECK(s.buttons==0);
|
||||
dm_tc_target main=s.layout.target[DM_TC_MAIN];
|
||||
dm_tc_begin(&s,0,main.x+10,main.y+10);
|
||||
dm_tc_move(&s,0,main.x+40,main.y-20); CHECK(s.rx==16384 && s.ry==16384);
|
||||
dm_tc_move(&s,0,map.x,map.y); CHECK(s.map_cancel_active);
|
||||
dm_tc_cancel_all(&s); CHECK(!s.map_cancel_active && s.rx==0 && s.ry==0 && s.aim_slot==DM_TC_NONE);
|
||||
{ /* 拖动定方向:技能钮按下后先等判定时间;拖过死区带着方向立刻键下;按住中改方向键不动(右轴跟着变,宿主每拍重取);点得太短补一个带方向的脉冲 | Drag to set direction: after an on-screen skill button is pressed, first wait for the decision time; dragging past the dead zone presses the key immediately with the direction; changing direction while holding leaves the key untouched (the right axis follows, the host re-reads it every tick); a tap that is too short gets one make-up pulse with the direction */
|
||||
dm_tc_state t; dm_tc_init(&t,667,375); dm_tc_target k=t.layout.target[DM_TC_SKILL2];
|
||||
dm_tc_tick(&t,1.00); dm_tc_begin_at(&t,0,k.x,k.y,1.00); CHECK(t.buttons==0); /* 刚按下:等判定 | Just pressed: waiting for the decision */
|
||||
dm_tc_move_at(&t,0,k.x+60,k.y,1.03); CHECK(t.buttons==DM_BTN_X && t.rx==32767 && t.ry==0); /* 0.03 秒就拖过死区:带着方向键下 | Dragged past the dead zone in just 0.03 seconds: key down carrying the direction */
|
||||
dm_tc_tick(&t,1.40); dm_tc_move_at(&t,0,k.x,k.y-60,1.40); CHECK(t.buttons==DM_BTN_X && t.rx==0 && t.ry==32767); /* 改成朝上:键一直按着,右轴是新方向 | Changed to upward: the key stays down, and the right axis is the new direction */
|
||||
dm_tc_end_at(&t,0,2.00); CHECK(t.buttons==0 && !t.pulse_button); /* 键按下过:松手键起,不发脉冲 | The key had been pressed: on release the key goes up, no pulse sent */
|
||||
dm_tc_tick(&t,3.00); dm_tc_begin_at(&t,0,k.x,k.y,3.00); dm_tc_end_at(&t,0,3.05); CHECK(t.pulse_button==DM_BTN_X && t.buttons==DM_BTN_X && t.rx==0); /* 点得比判定时间短、没拖:补一个不带方向的脉冲 | Tapped shorter than the decision time, no drag: send one make-up pulse with no direction */
|
||||
CHECK(dm_tc_pulse_end(&t,t.pulse_epoch) && t.buttons==0);
|
||||
dm_tc_tick(&t,4.00); dm_tc_begin_at(&t,0,k.x,k.y,4.00); dm_tc_tick(&t,4.10); CHECK(t.buttons==DM_BTN_X && t.rx==0); /* 没拖、过了判定时间:键下,不带方向 | No drag and the decision time has passed: key down, with no direction */
|
||||
dm_tc_end_at(&t,0,4.30); CHECK(t.buttons==0 && !t.pulse_button);
|
||||
dm_tc_target mn=t.layout.target[DM_TC_MAIN];
|
||||
dm_tc_tick(&t,5.00); dm_tc_begin_at(&t,0,mn.x,mn.y,5.00); CHECK(t.buttons==DM_BTN_A); dm_tc_end_at(&t,0,5.03); CHECK(t.buttons==0 && !t.pulse_button); /* 主钮:按下即键下,点按不等 | Main button: key down on press, a tap does not wait */
|
||||
dm_tc_tick(&t,6.00); dm_tc_begin_at(&t,0,k.x,k.y,6.00); dm_tc_tick(&t,6.09); CHECK(t.buttons==DM_BTN_X); dm_tc_end_at(&t,0,6.10); CHECK(t.pulse_button==DM_BTN_X && t.buttons==DM_BTN_X); /* 技能钮点 0.10 秒:键才按下 0.01 秒就松手 → 补成脉冲,不让游戏漏读 | On-screen skill button tapped for 0.10 seconds: released when the key had been down only 0.01 seconds → made up into a pulse so the game does not miss the read */
|
||||
CHECK(dm_tc_pulse_end(&t,t.pulse_epoch) && t.buttons==0);
|
||||
}
|
||||
{ /* 技能组切换:点一下进第二套。ZL 只在用技能时带(手指按着主钮 / 技能钮、技能脉冲在发),且先于技能键 0.17 秒;十字 / 腰带等不带;导航态不按;取消/改尺寸不丢模式 | Skill set switch: one tap enters the second set. ZL is held only while a skill is in use (a finger is on the main button / an on-screen skill button and the skill pulse is being sent), and leads the skill button key by 0.17 seconds; D-pad / belt etc. do not carry it; not pressed in navigation state; cancel/resize does not lose the mode */
|
||||
dm_tc_state t; dm_tc_init(&t,667,375); dm_tc_target w=t.layout.swap;
|
||||
CHECK(dm_tc_hit(&t.layout,w.x,w.y)==DM_TC_SWAP && t.skill_set==0);
|
||||
dm_tc_begin(&t,0,w.x,w.y); CHECK(t.skill_set==1 && t.buttons==0); dm_tc_end(&t,0); CHECK(t.buttons==0);
|
||||
dm_tc_target k=t.layout.target[DM_TC_SKILL3], mn=t.layout.target[DM_TC_MAIN], mu=t.layout.target[DM_TC_MENU];
|
||||
dm_tc_tick(&t,10.0); dm_tc_begin_at(&t,1,k.x,k.y,10.0); CHECK(t.buttons==DM_BTN_ZL); /* 刚按下技能钮:ZL 先下 | On-screen skill button just pressed: ZL goes down first */
|
||||
dm_tc_tick(&t,10.3); CHECK(t.buttons==(DM_BTN_ZL|DM_BTN_Y)); /* ZL 领先够了:技能键下,按住期间一直按着 | ZL has led long enough: the skill button key goes down and stays down for as long as the hold lasts */
|
||||
dm_tc_end_at(&t,1,10.4); CHECK(t.buttons==0 && t.pulse_button==0); /* 松手:一起放,不发脉冲 | Release: let go together, no pulse sent */
|
||||
dm_tc_tick(&t,11.0); dm_tc_begin_at(&t,1,k.x,k.y,11.0); dm_tc_end_at(&t,1,11.05); CHECK(t.buttons==DM_BTN_ZL && t.pulse_button==0); /* 点得太短:先只按 ZL | Tapped too briefly: press only ZL first */
|
||||
dm_tc_tick(&t,11.1); CHECK(t.buttons==DM_BTN_ZL); dm_tc_tick(&t,11.18); CHECK(t.buttons==(DM_BTN_ZL|DM_BTN_Y));
|
||||
dm_tc_pulse_end(&t,t.pulse_epoch); CHECK(t.buttons==0);
|
||||
dm_tc_tick(&t,12.0); dm_tc_begin_at(&t,1,mn.x,mn.y,12.0); CHECK(t.buttons==DM_BTN_ZL); /* 主钮:ZL 先下 | Main button: ZL goes down first */
|
||||
dm_tc_tick(&t,12.1); CHECK(t.buttons==DM_BTN_ZL); dm_tc_tick(&t,12.2); CHECK(t.buttons==(DM_BTN_ZL|DM_BTN_A)); /* 0.17 秒后 A 下,按住期间一直按着 | A goes down 0.17 seconds later and stays down for as long as the hold lasts */
|
||||
dm_tc_tick(&t,13.0); CHECK(t.buttons==(DM_BTN_ZL|DM_BTN_A)); dm_tc_end_at(&t,1,13.1); CHECK(t.buttons==0);
|
||||
dm_tc_begin_at(&t,1,mu.x,mu.y,14.0); CHECK(t.buttons==DM_BTN_PLUS); dm_tc_end_at(&t,1,14.1); CHECK(t.buttons==0); /* 十字:不带 ZL | D-pad: without ZL */
|
||||
{ dm_tc_target bl=t.layout.target[DM_TC_BELT1]; dm_tc_tick(&t,15.0); dm_tc_begin_at(&t,1,bl.x,bl.y,15.0); CHECK(t.buttons==0); dm_tc_end_at(&t,1,15.05); /* 腰带:松手即喝,不带 ZL(带了 = 喂佣兵) | belt: drink on release, without ZL (with it = feed mercenary) */
|
||||
dm_tc_tick(&t,15.05+0.01); CHECK(t.buttons==DM_BTN_LEFT); dm_tc_pulse_end(&t,t.pulse_epoch); CHECK(t.buttons==0); }
|
||||
dm_tc_cancel_all(&t); CHECK(t.skill_set==1 && t.buttons==0);
|
||||
dm_tc_resize(&t,812,375); CHECK(t.skill_set==1);
|
||||
dm_tc_set_navigation_mode(&t,1); begin(&t,0,DM_TC_MAIN); CHECK(t.buttons==DM_BTN_A); dm_tc_end(&t,0);
|
||||
dm_tc_begin(&t,0,t.layout.swap.x,t.layout.swap.y); CHECK(t.skill_set==1 && t.buttons==0); dm_tc_end(&t,0);
|
||||
dm_tc_set_navigation_mode(&t,0); w=t.layout.swap;
|
||||
dm_tc_begin(&t,0,w.x,w.y); dm_tc_end(&t,0); CHECK(t.skill_set==0 && t.buttons==0);
|
||||
}
|
||||
printf("PASS skill drag axes/ownership/map-lock/navigation/resize/Portal coexistence/skill-set swap %d/%d checks\n",checks,checks);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,552 @@
|
||||
#include "dm_touch_controls.h"
|
||||
#include "../../host/dm_input.h"
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static int checks, cases;
|
||||
#define CHECK(expr) do { ++checks; if (!(expr)) { fprintf(stderr, "FAIL %s:%d: %s\n", __FILE__, __LINE__, #expr); exit(1); } } while (0)
|
||||
#define NEAR(a,b,e) CHECK(fabs((double)(a)-(double)(b)) <= (e))
|
||||
#define RUN(f) do { int before = checks; f(); ++cases; printf("PASS %s (%d checks)\n", #f, checks-before); } while (0)
|
||||
|
||||
static const uint64_t keys[DM_TC_COUNT] = {
|
||||
DM_BTN_A, DM_BTN_B, DM_BTN_X, DM_BTN_Y, DM_BTN_R, 0, /* 回城钮不出按键:点下由宿主施放回城 | The town portal button emits no key: on tap the host casts town portal */
|
||||
DM_BTN_LEFT, DM_BTN_UP, DM_BTN_DOWN, DM_BTN_RIGHT, DM_BTN_PLUS, DM_BTN_MINUS
|
||||
};
|
||||
static void press(dm_tc_state *s, int slot, int target) {
|
||||
dm_tc_target t = s->layout.target[target];
|
||||
dm_tc_begin(s, slot, t.x, t.y);
|
||||
if (target >= DM_TC_MAIN && target <= DM_TC_SKILL4) dm_tc_tick(s, s->last_time_s + 0.1); /* 主钮 / 技能钮按下后有判定时间(点按还是拖动),这里的「按下」= 已过判定时间 | After the main button / a skill button is pressed there is a decision time (tap or drag); here "pressed" = the decision time has passed */
|
||||
}
|
||||
static int g_tall; /* 本文件里跟着 dm_tc_set_tall_scale 一起设 | Set together with dm_tc_set_tall_scale in this file */
|
||||
static void layout_at(float w, float h) {
|
||||
dm_tc_layout l; dm_tc_layout_make(&l, w, h);
|
||||
NEAR(l.width,w,0); NEAR(l.height,h,0);
|
||||
for (int i=0; i<DM_TC_COUNT; ++i) {
|
||||
dm_tc_target a=l.target[i];
|
||||
CHECK(a.r>0 && isfinite(a.r));
|
||||
CHECK(a.x-a.r>=0 && a.x+a.r<=w);
|
||||
CHECK(a.y-a.r>=0 && a.y+a.r<=h);
|
||||
CHECK(a.button==keys[i]);
|
||||
CHECK(dm_tc_hit(&l,a.x,a.y)==i);
|
||||
for (int j=i+1; j<DM_TC_COUNT; ++j) {
|
||||
dm_tc_target b=l.target[j];
|
||||
CHECK(hypotf(a.x-b.x,a.y-b.y)>a.r+b.r);
|
||||
}
|
||||
}
|
||||
float k = g_tall && h > 440 ? h/440 : 1; /* 缺省 1;前端开了大画面放大(g_tall)且画面比手机高(iPad 的 16:9 块)时技能钮按画面高度等比放大 | Default 1; when the front end has large-display scale-up on (g_tall) and the display is taller than a phone (the iPad 16:9 block), skill buttons scale up proportionally with display height */
|
||||
NEAR(l.target[DM_TC_MAIN].r,40*k,0.001);
|
||||
for (int i=DM_TC_SKILL1; i<=DM_TC_SKILL4; ++i) {
|
||||
NEAR(l.target[i].r,26*k,0.001);
|
||||
NEAR(hypotf(l.target[i].x-l.target[0].x,l.target[i].y-l.target[0].y),112*k,0.001);
|
||||
}
|
||||
/* 底部 UI v4 六格(第 0 格难度):腰带四列 → 第 1–4 格,功能入口 → 第 5 格;效果图 2868×1320 里格心 x = 1090 + 120×格号、y = 1241.5、
|
||||
格半宽 57,按屏高换算、以屏宽中线(效果图 1434)居中。
|
||||
Bottom UI v4 six cells (cell 0 is difficulty): the four belt columns → cells 1–4, function entry → cell 5; in the 2868×1320 mockup the cell center x = 1090 + 120 × cell number, y = 1241.5,
|
||||
cell half-width 57, converted by screen height and centered on the screen-width center line (mockup 1434). */
|
||||
const int order[5] = {DM_TC_BELT1, DM_TC_BELT2, DM_TC_BELT3, DM_TC_BELT4, DM_TC_MENU};
|
||||
float u = h/1320;
|
||||
for (int c=0; c<5; ++c) {
|
||||
dm_tc_target t=l.target[order[c]];
|
||||
NEAR(t.r,57*u,0.001);
|
||||
NEAR(t.y,1241.5*u,0.001);
|
||||
NEAR(t.x,w/2+(1090+120*(c+1)-1434)*u,0.01);
|
||||
}
|
||||
/* 回城钮(不在底栏):技能弧最上面那颗(技能四)正上方的圆钮,同半径、间距 12 | Town portal button (not in the bottom bar): the round button directly above the topmost one on the skill arc (skill four), same radius, gap 12 */
|
||||
{ dm_tc_target p=l.target[DM_TC_PORTAL], s4=l.target[DM_TC_SKILL4];
|
||||
NEAR(p.r,26*k,0.001); NEAR(p.x,s4.x,0.001); NEAR(p.y,s4.y-s4.r-12*k-p.r,0.001); }
|
||||
}
|
||||
/* 难度格:第 0 格 = 腰带第 1 格左邻一个格距;点开选择条,选第 8 格 → diff_request=8 并收起;选择期间不发任何按键 | Difficulty cell: cell 0 = one cell pitch to the left of belt cell 1; tap to open the selector strip, select cell 8 → diff_request=8 and collapse; no key is sent during selection */
|
||||
static void difficulty_picker(void) {
|
||||
dm_tc_state s; dm_tc_init(&s,956,440);
|
||||
dm_tc_layout *l=&s.layout; float pitch=440.0f*120/1320;
|
||||
NEAR(l->diff.x,l->target[DM_TC_BELT1].x-pitch,0.01); NEAR(l->diff.y,l->target[DM_TC_BELT1].y,0.01);
|
||||
NEAR(l->pick[7].x-l->pick[0].x,7*pitch,0.01); CHECK(l->pick[0].y+l->pick[0].r<l->diff.y-l->diff.r);
|
||||
NEAR((l->pick[3].x+l->pick[4].x)/2,l->width/2+(1390-1434)*440.0f/1320,0.01); /* 选择条中线 = 两球中线(效果图 1390) | Selector strip center line = the center line between the two orbs (mockup 1390) */
|
||||
dm_tc_begin(&s,0,l->diff.x,l->diff.y); CHECK(s.diff_open==1 && s.buttons==0); dm_tc_end(&s,0); CHECK(s.buttons==0);
|
||||
dm_tc_begin(&s,0,l->pick[7].x,l->pick[7].y); CHECK(s.diff_request==8 && s.diff_open==0 && s.buttons==0); dm_tc_end(&s,0);
|
||||
s.diff_request=0;
|
||||
dm_tc_begin(&s,0,l->diff.x,l->diff.y); dm_tc_end(&s,0); CHECK(s.diff_open==1);
|
||||
press(&s,0,DM_TC_BELT2); CHECK(s.diff_open==0 && s.diff_request==0 && s.buttons==0); dm_tc_end(&s,0); /* 点别处:收起并照常处理(腰带按下不再即喝,松手后等单双击,见 belt_tap) | Tap elsewhere: collapses and is handled as usual (a belt press no longer drinks immediately; it waits for single / double tap after release, see belt_tap) */
|
||||
dm_tc_begin(&s,0,l->diff.x,l->diff.y); dm_tc_end(&s,0); dm_tc_set_navigation_mode(&s,1); CHECK(s.diff_open==0);
|
||||
dm_tc_begin(&s,0,l->diff.x,l->diff.y); CHECK(s.diff_open==0); /* 导航模式(功能页)不理难度格 | Navigation mode (function page) ignores the difficulty cell */
|
||||
}
|
||||
static void layout_667(void) { layout_at(667,375); }
|
||||
static void layout_812(void) { layout_at(812,375); }
|
||||
static void layout_956(void) { layout_at(956,440); }
|
||||
static void layout_1024(void) { layout_at(1024,768); }
|
||||
static void layout_ipad169(void) { dm_tc_set_tall_scale(g_tall = 1); layout_at(1366,768); dm_tc_set_tall_scale(g_tall = 0); } /* 13 寸 iPad 上居中的 16:9 块:开了放大 | The centered 16:9 block on the 13-inch iPad: scale-up is on */
|
||||
static void layout_pixels(void) { layout_at(2868,1320); } /* Mac 宿主触屏用例通路把像素数当点数传:没开放大,主钮半径仍是 40、位置不变 | The Mac host touch-case path passes pixel counts as point counts: scale-up is not on, the main button radius is still 40 and its position is unchanged */
|
||||
static void small_layout(void) {
|
||||
dm_tc_layout l; dm_tc_layout_make(&l,333.5f,187.5f);
|
||||
NEAR(l.target[0].r,20,0.001); NEAR(l.joy_radius,30,0.001);
|
||||
for(int i=0;i<DM_TC_COUNT;i++) {
|
||||
CHECK(l.target[i].x>=l.target[i].r && l.target[i].x+l.target[i].r<=l.width);
|
||||
CHECK(l.target[i].y>=l.target[i].r && l.target[i].y+l.target[i].r<=l.height);
|
||||
for(int j=i+1;j<DM_TC_COUNT;j++) CHECK(hypotf(l.target[i].x-l.target[j].x,l.target[i].y-l.target[j].y)>l.target[i].r+l.target[j].r);
|
||||
}
|
||||
}
|
||||
static void hit_edges(void) {
|
||||
dm_tc_layout l; dm_tc_layout_make(&l,667,375);
|
||||
for(int i=0;i<DM_TC_COUNT;i++) {
|
||||
dm_tc_target t=l.target[i];
|
||||
CHECK(dm_tc_hit(&l,t.x+t.r,t.y)==i);
|
||||
CHECK(dm_tc_hit(&l,t.x+t.r+0.01f,t.y)==DM_TC_NONE);
|
||||
}
|
||||
CHECK(dm_tc_hit(&l,-1,50)==DM_TC_NONE);
|
||||
CHECK(dm_tc_hit(&l,800,50)==DM_TC_NONE);
|
||||
CHECK(dm_tc_hit(&l,NAN,50)==DM_TC_NONE);
|
||||
}
|
||||
static void key_hold_and_ownership(void) {
|
||||
dm_tc_state s; dm_tc_init(&s,667,375);
|
||||
for(int i=0;i<DM_TC_COUNT;i++) {
|
||||
if(i>=DM_TC_BELT1&&i<=DM_TC_BELT4) continue; /* 腰带格松手后等单双击,见 belt_single_double | A belt slot waits for single / double tap after release, see belt_single_double */
|
||||
int release=0; /* 技能钮与主钮同一套:按下即键下、松手键起(按住 = 持续施放) | Skill buttons use the same scheme as the main button: key down on press, key up on release (hold = continuous cast) */
|
||||
press(&s,0,i);
|
||||
CHECK(s.buttons==(release?0:keys[i]));
|
||||
dm_tc_move(&s,0,350,100); CHECK(s.buttons==(release?0:keys[i]));
|
||||
dm_tc_move(&s,0,s.layout.target[0].x,s.layout.target[0].y); CHECK(s.buttons==(release?0:keys[i]));
|
||||
dm_tc_tick(&s,s.last_time_s+0.1); dm_tc_end(&s,0); CHECK(s.buttons==(release?keys[i]:0));
|
||||
if(release) { CHECK(dm_tc_pulse_end(&s,s.pulse_epoch)); CHECK(s.buttons==0); }
|
||||
}
|
||||
}
|
||||
static void two_fingers_same_key(void) {
|
||||
dm_tc_state s; dm_tc_init(&s,667,375);
|
||||
press(&s,0,DM_TC_MAIN); press(&s,1,DM_TC_MAIN);
|
||||
CHECK(s.buttons==DM_BTN_A); dm_tc_end(&s,0); CHECK(s.buttons==DM_BTN_A);
|
||||
dm_tc_end(&s,1); CHECK(s.buttons==0);
|
||||
}
|
||||
static void joystick_deadzone(void) {
|
||||
/* 底座固定在静止位(667×375:圆心 90,275、半径 60):落在圆心上起手,原点 = 圆心 | the base is fixed at its rest position (667×375: center 90,275, radius 60): starting on the center, origin = center */
|
||||
dm_tc_state s; dm_tc_init(&s,667,375); dm_tc_begin(&s,0,90,275);
|
||||
CHECK(s.joy_slot==0); NEAR(s.joy_origin_x,90,0); NEAR(s.joy_origin_y,275,0);
|
||||
CHECK(s.lx==0 && s.ly==0);
|
||||
dm_tc_move(&s,0,96,275); CHECK(s.lx==0 && s.ly==0);
|
||||
dm_tc_move(&s,0,96.1f,275); CHECK(s.lx>0 && s.lx<100 && s.ly==0);
|
||||
dm_tc_move(&s,0,123,275); CHECK(abs(s.lx-16384)<=1 && s.ly==0);
|
||||
dm_tc_end(&s,0);
|
||||
/* 落在底座附近(离圆心不超过 1.5 倍半径 = 90 点):起摇杆,原点仍是圆心,一按下就按「手指相对圆心」出方向((150,275) 在圆心右 60 = 满偏) | landing near the base (no more than 1.5 × radius = 90 points from the center): the joystick starts, the origin is still the center, and from the moment of pressing the direction is "finger relative to the center" ((150,275) is 60 to the right of the center = full deflection) */
|
||||
dm_tc_begin(&s,0,150,275); CHECK(s.joy_slot==0); NEAR(s.joy_origin_x,90,0); NEAR(s.joy_origin_y,275,0); CHECK(s.lx==DM_STICK_MAX && s.ly==0);
|
||||
dm_tc_move(&s,0,600,275); CHECK(s.lx==DM_STICK_MAX && s.ly==0); NEAR(s.joy_origin_x,90,0); /* 拖到很远:照样识别,底座不动 | dragged very far: still recognized, the base does not move */
|
||||
dm_tc_move(&s,0,90,100); CHECK(s.lx==0 && s.ly==DM_STICK_MAX); NEAR(s.joy_origin_y,275,0);
|
||||
dm_tc_end(&s,0); CHECK(s.joy_slot==-1 && s.lx==0 && s.ly==0);
|
||||
dm_tc_begin(&s,0,90,365); CHECK(s.joy_slot==0); dm_tc_end(&s,0); /* 正下方 90 点:刚好在内 | 90 points straight down: just inside */
|
||||
dm_tc_begin(&s,0,181,275); CHECK(s.joy_slot==-1 && s.lx==0); dm_tc_end(&s,0); /* 右边 91 点:不起摇杆 | 91 points to the right: no joystick started */
|
||||
dm_tc_begin(&s,0,250,150); CHECK(s.joy_slot==-1 && s.lx==0 && s.ly==0); dm_tc_move(&s,0,300,150); CHECK(s.joy_slot==-1 && s.lx==0); dm_tc_end(&s,0); /* 左侧别处:不起摇杆,拖也不变成摇杆 | elsewhere on the left: no joystick started, and dragging does not turn into a joystick either */
|
||||
/* 拖远了的摇杆手指被系统取消,0.35 秒内在原处附近重新落下:接着当摇杆(原点仍是圆心);超时或离得远:不接 | a joystick finger dragged far away is cancelled by the system and lands again near the same spot within 0.35 seconds: it continues as the joystick (the origin is still the center); timed out or too far away: not picked up */
|
||||
dm_tc_begin_at(&s,0,90,275,50.0); dm_tc_move_at(&s,0,260,160,50.2); CHECK(s.lx>0 && s.ly>0); dm_tc_cancel_finger(&s,0); CHECK(s.joy_slot==-1 && s.lx==0);
|
||||
dm_tc_begin_at(&s,1,265,165,50.4); CHECK(s.joy_slot==1 && s.lx>0 && s.ly>0); NEAR(s.joy_origin_x,90,0); dm_tc_cancel_finger(&s,1);
|
||||
dm_tc_begin_at(&s,2,265,165,50.4+0.36); CHECK(s.joy_slot==-1); dm_tc_end_at(&s,2,51.5); /* 超过 0.35 秒 | more than 0.35 seconds */
|
||||
dm_tc_begin_at(&s,0,90,275,52.0); dm_tc_move_at(&s,0,260,160,52.2); dm_tc_cancel_finger(&s,0);
|
||||
dm_tc_begin_at(&s,1,265,300,52.3); CHECK(s.joy_slot==-1); dm_tc_end_at(&s,1,53.5); /* 离取消时的位置 140 点:不接 | 140 points from the position at cancellation: not picked up */
|
||||
}
|
||||
static void joystick_axes(void) {
|
||||
dm_tc_state s; dm_tc_init(&s,667,375); dm_tc_begin(&s,0,90,275); /* 圆心 90,275;下面各点 = 原用例整体平移 (−10, +75) | center 90,275; the points below = the original cases shifted as a whole by (−10, +75) */
|
||||
dm_tc_move(&s,0,150,275); CHECK(s.lx==DM_STICK_MAX && s.ly==0);
|
||||
dm_tc_move(&s,0,30,275); CHECK(s.lx==-DM_STICK_MAX && s.ly==0);
|
||||
dm_tc_move(&s,0,90,215); CHECK(s.lx==0 && s.ly==DM_STICK_MAX);
|
||||
dm_tc_move(&s,0,90,335); CHECK(s.lx==0 && s.ly==-DM_STICK_MAX);
|
||||
dm_tc_move(&s,0,690,275); CHECK(s.lx==DM_STICK_MAX && s.ly==0);
|
||||
dm_tc_move(&s,0,150,215); CHECK(abs(s.lx-14654)<=1 && abs(s.ly-29308)<=1); /* 手指 45°:斜向预修正后 (1,2)/√5 × 32767 = (14654, 29308),幅度不变 | Finger at 45°: after diagonal pre-correction (1,2)/√5 × 32767 = (14654, 29308), magnitude unchanged */
|
||||
dm_tc_move(&s,0,90+60*0.8660254f,275-30); CHECK(abs(s.lx-21451)<=2 && abs(s.ly-24769)<=2); /* 手指 30°:(cos30, 2 sin30)/√(0.75+1) × 32767 = (21451, 24769) | Finger at 30°: (cos30, 2 sin30)/√(0.75+1) × 32767 = (21451, 24769) */
|
||||
dm_tc_set_iso_fix(0); dm_tc_move(&s,0,150,215); CHECK(abs(s.lx-23170)<=1 && abs(s.ly-23170)<=1); dm_tc_set_iso_fix(1);
|
||||
dm_tc_end(&s,0); CHECK(s.joy_slot==-1 && s.lx==0 && s.ly==0);
|
||||
}
|
||||
static void joystick_plus_skills(void) {
|
||||
dm_tc_state s; dm_tc_init(&s,667,375); dm_tc_begin(&s,0,90,275); dm_tc_move(&s,0,150,275);
|
||||
for(int i=0;i<5;i++) press(&s,i+1,i);
|
||||
uint64_t all=keys[0]|keys[1]|keys[2]|keys[3]|keys[4];
|
||||
CHECK(s.buttons==all); CHECK(s.lx==DM_STICK_MAX); /* 主钮与四个技能钮:按着的键都按着(按住 = 持续施放) | Main button and the four skill buttons: every pressed key stays down (hold = continuous cast) */
|
||||
dm_tc_end(&s,3); CHECK(s.buttons==(all&~keys[2]) && s.lx==DM_STICK_MAX); /* 移动中松开一个:只有它的键起 | Release one while moving: only its key goes up */
|
||||
dm_tc_end(&s,0); CHECK(s.lx==0 && s.ly==0); CHECK(s.buttons==(all&~keys[2]));
|
||||
}
|
||||
static void no_auto_handoff(void) {
|
||||
dm_tc_state s; dm_tc_init(&s,667,375); dm_tc_begin(&s,0,90,275); dm_tc_begin(&s,1,150,295); /* 第二根手指也落在底座附近:摇杆已有主,它不接手 | a second finger also lands near the base: the joystick already has an owner, so it does not take over */
|
||||
dm_tc_end(&s,0); dm_tc_move(&s,1,210,295);
|
||||
CHECK(s.joy_slot==-1 && s.lx==0 && s.ly==0 && s.buttons==0);
|
||||
dm_tc_begin(&s,2,90,275); CHECK(s.joy_slot==2);
|
||||
}
|
||||
static void background_no_key(void) {
|
||||
dm_tc_state s; dm_tc_init(&s,667,375); dm_tc_begin(&s,0,400,100);
|
||||
CHECK(s.buttons==0 && s.joy_slot==-1);
|
||||
dm_tc_move(&s,0,s.layout.target[0].x,s.layout.target[0].y); CHECK(s.buttons==0);
|
||||
dm_tc_begin(&s,1,10,10); dm_tc_move(&s,1,100,200); CHECK(s.joy_slot==-1 && s.buttons==0);
|
||||
dm_tc_begin(&s,2,667*0.43f,200); CHECK(s.joy_slot==-1);
|
||||
dm_tc_begin(&s,3,100,375*0.25f); CHECK(s.joy_slot==-1);
|
||||
}
|
||||
static void circles_before_joystick(void) {
|
||||
dm_tc_state s; dm_tc_init(&s,667,375); press(&s,0,DM_TC_PORTAL);
|
||||
CHECK(s.buttons==0 && s.joy_slot==-1); CHECK(s.finger[0].target==DM_TC_PORTAL); /* 圆钮先于摇杆认领这根手指;回城钮自己不出按键 | Round buttons claim this finger before the stick does; the town portal button itself emits no key */
|
||||
}
|
||||
static void cancel_and_resize(void) {
|
||||
dm_tc_state s; dm_tc_init(&s,667,375); dm_tc_begin(&s,0,100,200); dm_tc_move(&s,0,160,200); press(&s,1,DM_TC_MAIN);
|
||||
dm_tc_cancel_all(&s); CHECK(s.buttons==0 && s.lx==0 && s.ly==0 && s.joy_slot==-1);
|
||||
for(int i=0;i<DM_TC_MAX_TOUCH;i++) CHECK(!s.finger[i].active);
|
||||
dm_tc_begin(&s,0,100,200); press(&s,1,DM_TC_MAIN); dm_tc_resize(&s,812,375);
|
||||
CHECK(s.buttons==0 && s.lx==0 && s.ly==0 && s.joy_slot==-1); NEAR(s.layout.width,812,0);
|
||||
for(int i=0;i<DM_TC_MAX_TOUCH;i++) CHECK(!s.finger[i].active);
|
||||
dm_tc_move(&s,1,s.layout.target[0].x,s.layout.target[0].y); CHECK(s.buttons==0);
|
||||
}
|
||||
static void invalid_slots_and_repeated_begin(void) {
|
||||
dm_tc_state s; dm_tc_init(&s,667,375);
|
||||
press(&s,-1,0); press(&s,DM_TC_MAX_TOUCH,0); dm_tc_move(&s,-1,1,1); dm_tc_end(&s,DM_TC_MAX_TOUCH);
|
||||
CHECK(s.buttons==0); dm_tc_begin(&s,0,NAN,10); CHECK(!s.finger[0].active);
|
||||
press(&s,0,DM_TC_MAIN); press(&s,0,DM_TC_SKILL1); CHECK(s.buttons==DM_BTN_A);
|
||||
dm_tc_move(&s,0,NAN,INFINITY); CHECK(s.buttons==DM_BTN_A);
|
||||
dm_tc_end(&s,0); CHECK(s.buttons==0);
|
||||
dm_tc_begin(&s,0,-1,200); dm_tc_begin(&s,1,100,500); CHECK(s.joy_slot==-1);
|
||||
}
|
||||
static void all_slots_hold(void) {
|
||||
dm_tc_state s; dm_tc_init(&s,667,375);
|
||||
for(int i=0;i<DM_TC_MAX_TOUCH;i++) press(&s,i,DM_TC_MAIN);
|
||||
for(int i=0;i<DM_TC_MAX_TOUCH-1;i++) { dm_tc_end(&s,i); CHECK(s.buttons==DM_BTN_A); }
|
||||
dm_tc_end(&s,DM_TC_MAX_TOUCH-1); CHECK(s.buttons==0);
|
||||
}
|
||||
static void enabled_targets(void) {
|
||||
dm_tc_state s; dm_tc_init(&s,667,375);
|
||||
CHECK(s.enabled_targets == ((1u<<DM_TC_COUNT)-1));
|
||||
dm_tc_begin(&s,0,100,200); dm_tc_move(&s,0,160,200); press(&s,1,DM_TC_MAIN);
|
||||
uint32_t ui = (1u<<DM_TC_MAIN)|(1u<<DM_TC_SKILL1)|(1u<<DM_TC_SKILL2)|
|
||||
(1u<<DM_TC_SKILL3)|(1u<<DM_TC_SKILL4)|(1u<<DM_TC_MENU);
|
||||
dm_tc_enable_targets(&s,ui);
|
||||
CHECK(s.enabled_targets==ui); CHECK(s.buttons==0 && s.lx==0 && s.ly==0 && s.joy_slot==-1);
|
||||
for(int i=0;i<DM_TC_COUNT;i++) {
|
||||
press(&s,0,i);
|
||||
CHECK(s.buttons==((ui&(1u<<i))?keys[i]:0));
|
||||
CHECK(s.joy_slot==-1); dm_tc_end(&s,0); dm_tc_pulse_end(&s,s.pulse_epoch);
|
||||
}
|
||||
press(&s,0,DM_TC_MAIN); dm_tc_enable_targets(&s,ui); CHECK(s.buttons==DM_BTN_A);
|
||||
dm_tc_enable_targets(&s,0); CHECK(s.buttons==0);
|
||||
press(&s,0,DM_TC_SKILL1); CHECK(s.buttons==0 && s.joy_slot==-1); /* 全禁用时点钮不出键、也不落进摇杆;重新启用后照常出键(原先用回城钮验,它 不出按键,换成技能一) | When everything is disabled, tapping a button emits no key and does not fall through to the stick either; after re-enabling, keys are emitted as usual (this used to be verified with the town portal button, which emits no key, so it was changed to skill one) */
|
||||
dm_tc_end(&s,0); dm_tc_enable_targets(&s,(1u<<DM_TC_COUNT)-1); press(&s,0,DM_TC_SKILL1); CHECK(s.buttons==DM_BTN_B);
|
||||
}
|
||||
static void ui_scene_messages(void) {
|
||||
dm_tc_scene scene={0};
|
||||
CHECK(dm_tc_navigation(&scene,"FrontEndNavigation","ToFrontEnd","")==1);
|
||||
CHECK(dm_tc_navigation(&scene,"PanelManager","OpenPanel","LoadScreenPanel")==1);
|
||||
CHECK(dm_tc_navigation(&scene,"PanelManager","UnloadPanel","LoadScreenPanel")==0);
|
||||
CHECK(dm_tc_navigation(&scene,"PanelManager","OpenPanel","PauseLayoutGarden")==1);
|
||||
CHECK(dm_tc_navigation(&scene,"PanelManager","ClosePanel","PauseLayoutGarden")==0);
|
||||
CHECK(dm_tc_navigation(&scene,"PanelManager","OpenPanel","AutoMap")==0);
|
||||
CHECK(dm_tc_navigation(&scene,"PanelManager","OpenExclusivePanel","BankExpansionLayout")==1);
|
||||
CHECK(dm_tc_navigation(&scene,"PanelManager","OpenPanel","PlayerInventoryExpansionLayout")==1);
|
||||
CHECK(dm_tc_navigation(&scene,"PanelManager","ClosePanel","BankExpansionLayout")==1);
|
||||
CHECK(dm_tc_navigation(&scene,"PanelManager","ClosePanel","PlayerInventoryExpansionLayout")==0);
|
||||
CHECK(dm_tc_navigation(&scene,"PanelManager","OpenPanel","HUDPanel")==0);
|
||||
CHECK(dm_tc_navigation(&scene,"PanelManager","OpenPanel","SkillsTreePanel")==1);
|
||||
CHECK(dm_tc_navigation(&scene,"PanelManager","UnloadAll","")==0);
|
||||
CHECK(dm_tc_navigation(&scene,"FrontEndNavigation","ToFrontEnd","")==1);
|
||||
}
|
||||
static void pointer_tap(void) {
|
||||
dm_tc_state s; dm_tc_init(&s,667,375); dm_tc_set_navigation_mode(&s,1);
|
||||
dm_tc_begin_at(&s,0,300,180,10.0); dm_tc_end_at(&s,0,10.2);
|
||||
CHECK(s.pointer_valid); NEAR(s.pointer_x,300,0.001); NEAR(s.pointer_y,180,0.001);
|
||||
CHECK(s.pulse_button==DM_BTN_A); CHECK(s.buttons==DM_BTN_A);
|
||||
}
|
||||
/* 物品区(前端松手前置 pointer_item):单击只移光标不发键;0.4 秒内同处再点 = 按住 A 0.6 秒;开着储藏箱时 = 按住 Y;隔久了再点仍是单击 | Item area (the front end sets pointer_item before release): a single tap only moves the cursor and sends no key; another tap at the same spot within 0.4 seconds = hold A for 0.6 seconds; with the stash open = hold Y; a tap after a long gap is still a single tap */
|
||||
/* 高级仓库的成叠格(命中类 8):单击只移光标;双击 = stack_take_seq 加一(取 1 件),不按住 Y、不计「使用」;开着箱子也一样;长按照物品区计 long_press_seq(宿主取 3 件) | Stack cells of the advanced stash (hit class 8): a single tap only moves the cursor; double tap = stack_take_seq plus one (take 1 item), no hold-Y and no "use" count; the same with the stash open; a long press counts long_press_seq as in the item area (the host takes 3 items) */
|
||||
static void pointer_stack_tap(void) {
|
||||
dm_tc_scene scene={0}; dm_tc_navigation(&scene,"PanelManager","UnloadAll",""); dm_tc_navigation(&scene,"PanelManager","OpenPanel","BankExpansionLayout"); dm_tc_set_panel_state(1);
|
||||
dm_tc_state s; dm_tc_init(&s,667,375); dm_tc_set_navigation_mode(&s,1); s.mouse_click_mode=1;
|
||||
dm_tc_begin_at(&s,0,104,91,10.0); dm_tc_pointer_item(&s,8); dm_tc_end_at(&s,0,10.1);
|
||||
CHECK(s.pointer_valid); NEAR(s.pointer_x,104,0.001); CHECK(s.stack_take_seq==0); CHECK(s.pulse_button==0);
|
||||
dm_tc_begin_at(&s,0,104,91,10.3); dm_tc_pointer_item(&s,8); dm_tc_end_at(&s,0,10.4);
|
||||
CHECK(s.stack_take_seq==1); CHECK(s.pulse_button==0); CHECK(s.use_seq==0); CHECK(s.buttons==0);
|
||||
dm_tc_begin_at(&s,0,104,91,12.0); dm_tc_pointer_item(&s,8); dm_tc_tick(&s,12.9); dm_tc_end_at(&s,0,12.9);
|
||||
CHECK(s.long_press_seq==1); CHECK(s.stack_take_seq==1);
|
||||
dm_tc_begin_at(&s,0,104,91,14.0); dm_tc_pointer_item(&s,8); dm_tc_move_at(&s,0,200,150,14.1); CHECK(s.finger[0].shop_drag); CHECK(s.pulse_button==0); CHECK(s.buttons==0); /* 从一叠上拖出:不拿起(不发键),松手由前端按落点取 1 件 | Dragging out from a stack: no pick up (no key sent), on release the front end takes 1 item according to the drop point */
|
||||
dm_tc_end_at(&s,0,14.5); CHECK(s.pulse_button==0); CHECK(s.stack_take_seq==1);
|
||||
dm_tc_navigation(&scene,"PanelManager","UnloadAll","");
|
||||
}
|
||||
static void pointer_item_tap(void) {
|
||||
dm_tc_scene scene={0}; dm_tc_navigation(&scene,"PanelManager","UnloadAll","");
|
||||
dm_tc_state s; dm_tc_init(&s,667,375); dm_tc_set_navigation_mode(&s,1);
|
||||
dm_tc_begin_at(&s,0,300,180,10.0); dm_tc_pointer_item(&s,1); dm_tc_end_at(&s,0,10.1);
|
||||
CHECK(s.pointer_valid); NEAR(s.pointer_x,300,0.001); NEAR(s.pointer_y,180,0.001); CHECK(s.pulse_button==0); CHECK(s.buttons==0);
|
||||
dm_tc_begin_at(&s,0,302,181,10.3); dm_tc_pointer_item(&s,1); dm_tc_end_at(&s,0,10.4);
|
||||
CHECK(s.pulse_button==0); CHECK(s.use_seq==1); /* 双击:不发按住 A,计一次交给宿主当场使用 | Double tap: does not send hold-A, counts once and hands it to the host to use on the spot */
|
||||
dm_tc_begin_at(&s,0,302,181,10.6); dm_tc_pointer_item(&s,1); dm_tc_end_at(&s,0,10.7); CHECK(s.pulse_button==0); /* 双击之后的第三下重新算单击 | The third tap after a double tap counts as a single tap again */
|
||||
dm_tc_begin_at(&s,0,302,181,12.0); dm_tc_pointer_item(&s,1); dm_tc_end_at(&s,0,12.1); CHECK(s.pulse_button==DM_BTN_ZL); CHECK(dm_tc_pulse_end(&s,s.pulse_epoch)); /* 隔 1.3 秒又点同一处:换一件比较(ZL) | Tapped the same spot again 1.3 seconds later: compare against another item (ZL) */
|
||||
dm_tc_begin_at(&s,0,400,181,12.2); dm_tc_pointer_item(&s,1); dm_tc_end_at(&s,0,12.3); CHECK(s.pulse_button==0); /* 换了位置:单击 | Position changed: single tap */
|
||||
dm_tc_navigation(&scene,"PanelManager","OpenPanel","BankExpansionLayout"); dm_tc_set_panel_state(1); /* 储藏箱开着 = 宿主读面板树设进来的位,不靠消息 | Stash open = a bit the host sets from reading the panel tree, not relying on messages */
|
||||
dm_tc_begin_at(&s,0,400,181,12.5); dm_tc_pointer_item(&s,1); dm_tc_end_at(&s,0,12.6);
|
||||
CHECK(s.pulse_button==DM_BTN_Y); NEAR(s.pulse_hold_s,0.6,0.001); dm_tc_pulse_end(&s,s.pulse_epoch);
|
||||
dm_tc_navigation(&scene,"PanelManager","ClosePanel","BankExpansionLayout"); dm_tc_set_panel_state(0);
|
||||
dm_tc_begin_at(&s,0,100,100,13.5); dm_tc_end_at(&s,0,13.6); CHECK(s.pulse_button==DM_BTN_A); NEAR(s.pulse_hold_s,0,0.001); /* 非物品区:照旧点 = A | Outside the item area: tap = A as before */
|
||||
dm_tc_pulse_end(&s,s.pulse_epoch); s.mouse_click_mode=1; /* 前端开了鼠标点击:非物品区点按不按 A,改记一次鼠标点击 | The front end turned on mouse click: a tap outside the item area does not press A, and one mouse click is recorded instead */
|
||||
dm_tc_begin_at(&s,0,120,90,14.5); dm_tc_end_at(&s,0,14.6); CHECK(s.pulse_button==0); CHECK(s.mouse_click_seq==1); NEAR(s.mouse_click_x,120,0.001); NEAR(s.mouse_click_y,90,0.001);
|
||||
dm_tc_begin_at(&s,0,300,180,15.5); dm_tc_pointer_item(&s,1); dm_tc_end_at(&s,0,15.6); CHECK(s.mouse_click_seq==1); CHECK(s.pulse_button==0); /* 物品区单击不算鼠标点击 | A single tap in the item area does not count as a mouse click */
|
||||
}
|
||||
/* 界面连续手势:鼠标点击模式下起手不在物品区 / 面板外、位移过 10 点阈值 → 按那一刻的方向定型(纵 1 = 滚动,横 2 = 滑块),定型后不变;
|
||||
不发任何键、不记鼠标点击(拖出去又拖回原处也不算点按);物品区起手照旧是拖放;面板外起手不定型;没开鼠标点击模式不定型
|
||||
UI continuous gesture: in mouse click mode, when the touch does not start in the item area / outside the panel and the displacement passes the 10-point threshold → the type is fixed by the direction at that moment (vertical 1 = scroll, horizontal 2 = slider), and does not change once fixed;
|
||||
no key is sent and no mouse click is recorded (dragging out and back to the original spot does not count as a tap either); a touch starting in the item area is drag-and-drop as before; a touch starting outside the panel fixes no type; with mouse click mode off no type is fixed */
|
||||
static void ui_drag_typing(void) {
|
||||
dm_tc_state s; dm_tc_init(&s,667,375); dm_tc_set_navigation_mode(&s,1); s.mouse_click_mode=1;
|
||||
dm_tc_begin_at(&s,0,300,200,1.0); dm_tc_move_at(&s,0,302,209,1.1); CHECK(s.finger[0].ui_drag==0); /* 位移 9.2 点:没过阈值 | Displacement 9.2 points: threshold not passed */
|
||||
dm_tc_move_at(&s,0,303,212,1.2); CHECK(s.finger[0].ui_drag==1); /* 过阈值,纵向为主 → 滚动 | Past the threshold, mainly vertical → scroll */
|
||||
dm_tc_move_at(&s,0,400,214,1.3); CHECK(s.finger[0].ui_drag==1); CHECK(s.buttons==0); CHECK(s.pulse_button==0); /* 之后横着走也不改型,不发键 | Moving sideways afterward does not change the type either, no key sent */
|
||||
dm_tc_move_at(&s,0,300,200,1.4); dm_tc_end_at(&s,0,1.45); CHECK(s.mouse_click_seq==0); CHECK(s.pulse_button==0); /* 拖回原处松手:不算点按 | Dragged back to the original spot and released: does not count as a tap */
|
||||
dm_tc_begin_at(&s,0,300,200,2.0); dm_tc_move_at(&s,0,312,204,2.1); CHECK(s.finger[0].ui_drag==2); /* 横向为主 → 滑块 | Mainly horizontal → slider */
|
||||
dm_tc_end_at(&s,0,2.2); CHECK(s.mouse_click_seq==0); CHECK(s.pulse_button==0);
|
||||
dm_tc_begin_at(&s,0,300,200,3.0); dm_tc_pointer_item(&s,1); dm_tc_move_at(&s,0,300,230,3.1); CHECK(s.finger[0].ui_drag==0); CHECK(s.finger[0].pointer_dragged); /* 物品区起手:照旧拖放 | Touch starting in the item area: drag-and-drop as before */
|
||||
dm_tc_pointer_release(&s,1); dm_tc_end_at(&s,0,3.2); if (s.pulse_button) dm_tc_pulse_end(&s,s.pulse_epoch);
|
||||
dm_tc_begin_at(&s,0,300,200,4.0); dm_tc_pointer_item(&s,3); dm_tc_move_at(&s,0,300,240,4.1); CHECK(s.finger[0].ui_drag==0); /* 面板外起手:不当滚动 | Touch starting outside the panel: not treated as a scroll */
|
||||
dm_tc_end_at(&s,0,4.2); if (s.pulse_button) dm_tc_pulse_end(&s,s.pulse_epoch);
|
||||
s.mouse_click_mode=0;
|
||||
dm_tc_begin_at(&s,0,300,200,5.0); dm_tc_move_at(&s,0,300,240,5.1); CHECK(s.finger[0].ui_drag==0); /* 没开鼠标点击模式(手柄光标拖放那条老路):不定型 | Mouse click mode not on (the old controller-cursor drag-and-drop path): no type is fixed */
|
||||
dm_tc_end_at(&s,0,5.2);
|
||||
}
|
||||
/* 拖放松手:落点是物品区 = 在落点按 A 放下;不是(拖到面板外)= 指针回起点、按 Y 丢弃(按住 0.15 秒) | Drag-and-drop release: the drop point is the item area = press A at the drop point to put down; it is not (dragged outside the panel) = the pointer returns to the start point and Y is pressed to discard (held 0.15 seconds) */
|
||||
/* 面板态:手指落在被禁用的目标上(底栏腰带格)照样当指针用——面板的按钮可能就在那下面 | Panel state: a finger landing on a disabled target (bottom bar belt slot) is still used as a pointer - the panel's button may be right under it */
|
||||
static void pointer_over_disabled_target(void) {
|
||||
dm_tc_state s; dm_tc_init(&s,667,375); s.mouse_click_mode=1; dm_tc_set_navigation_mode(&s,1); dm_tc_enable_targets(&s,dm_tc_nav_mask(1));
|
||||
const dm_tc_target *b=&s.layout.target[DM_TC_BELT1];
|
||||
dm_tc_begin_at(&s,0,b->x,b->y,10.0); CHECK(s.pointer_slot==0); dm_tc_end_at(&s,0,10.1); CHECK(s.mouse_click_seq==1); CHECK(s.buttons==0);
|
||||
}
|
||||
/* 游戏态点按 = 点世界:空处短按记一笔;按住拖动(摇杆)、点技能钮、面板态都不记。城里没目标时主按钮不发键 | Tap in game state = world tap: a short press on empty space records one; hold-and-drag (stick), tapping a skill button, and panel state do not record. The main button sends no key when there is no target in town */
|
||||
static void world_tap(void) {
|
||||
dm_tc_state s; dm_tc_init(&s,667,375); dm_tc_enable_targets(&s,(1u<<DM_TC_COUNT)-1);
|
||||
dm_tc_begin_at(&s,0,400,120,10.0); dm_tc_end_at(&s,0,10.1); CHECK(s.world_tap_seq==1); NEAR(s.world_tap_x,400,0.001); NEAR(s.world_tap_y,120,0.001);
|
||||
dm_tc_begin_at(&s,0,250,150,11.0); CHECK(s.joy_slot==-1); dm_tc_end_at(&s,0,11.1); CHECK(s.world_tap_seq==2); NEAR(s.world_tap_x,250,0.001); /* 左侧区域、底座以外点一下:点世界(不起摇杆) | a tap in the left area outside the base: world tap (no joystick started) */
|
||||
dm_tc_begin_at(&s,0,120,250,11.5); CHECK(s.joy_slot==0); dm_tc_end_at(&s,0,11.6); CHECK(s.world_tap_seq==2); /* 落在底座上点一下:是摇杆(一按就有方向),不兼作点世界 | a tap landing on the base: it is the joystick (direction as soon as pressed), and does not double as a world tap */
|
||||
dm_tc_begin_at(&s,0,120,250,12.0); dm_tc_move_at(&s,0,170,250,12.1); dm_tc_end_at(&s,0,12.2); CHECK(s.world_tap_seq==2); /* 拖了 = 摇杆 | Dragged = stick */
|
||||
dm_tc_begin_at(&s,0,400,120,13.0); dm_tc_end_at(&s,0,13.6); CHECK(s.world_tap_seq==2); /* 按了 0.6 秒:不算点按 | Held for 0.6 seconds: does not count as a tap */
|
||||
const dm_tc_target *m=&s.layout.target[DM_TC_MAIN];
|
||||
dm_tc_begin_at(&s,0,m->x,m->y,14.0); CHECK(s.buttons==m->button); dm_tc_end_at(&s,0,14.1); CHECK(s.world_tap_seq==2); /* 点主按钮:发键,不算点世界 | Tapping the main button: sends the key, does not count as a world tap */
|
||||
dm_tc_set_joy_block(&s,1); dm_tc_begin_at(&s,0,120,250,20.5); CHECK(s.joy_slot==-1 && s.lx==0 && s.ly==0); dm_tc_end_at(&s,0,20.6); CHECK(s.world_tap_seq==3); NEAR(s.world_tap_x,120,0.001); /* 讲话文字框单独开着:同一处点一下不起摇杆、没有方向,只当一次点击 | speech text box open on its own: a tap in the same place starts no stick and gives no direction, it is just one click */
|
||||
dm_tc_set_joy_block(&s,0); dm_tc_begin_at(&s,0,120,250,21.5); CHECK(s.joy_slot==0); dm_tc_end_at(&s,0,21.6); CHECK(s.world_tap_seq==3); /* 文字框关了:照旧是摇杆 | text box closed: stick as usual */
|
||||
dm_tc_set_navigation_mode(&s,1); dm_tc_begin_at(&s,0,400,120,16.0); dm_tc_end_at(&s,0,16.1); CHECK(s.world_tap_seq==3); /* 面板态不记 | Not recorded in panel state */
|
||||
}
|
||||
/* 面板外点按 = 按 B 到面板关掉为止:第一下在 tick 里发;面板还开着,0.3 秒后再发;面板关了就不再发;至多 3 下 | Tap outside the panel = press B until the panel closes: the first press is sent in tick; if the panel is still open, send again 0.3 seconds later; once the panel is closed no more are sent; at most 3 presses */
|
||||
static void pointer_outside_close(void) {
|
||||
dm_tc_state s; dm_tc_init(&s,667,375); s.mouse_click_mode=1; dm_tc_set_navigation_mode(&s,1);
|
||||
dm_tc_begin_at(&s,0,330,60,10.0); dm_tc_pointer_item(&s,3); dm_tc_end_at(&s,0,10.1); CHECK(s.pulse_button==0);
|
||||
dm_tc_tick(&s,10.12); CHECK(s.pulse_button==DM_BTN_B); CHECK(dm_tc_pulse_end(&s,s.pulse_epoch));
|
||||
dm_tc_tick(&s,10.2); CHECK(s.pulse_button==0); /* 不到 0.3 秒 | Less than 0.3 seconds */
|
||||
dm_tc_tick(&s,10.45); CHECK(s.pulse_button==DM_BTN_B); CHECK(dm_tc_pulse_end(&s,s.pulse_epoch)); /* 面板还开着:再按 | Panel still open: press again */
|
||||
dm_tc_set_navigation_mode(&s,0); dm_tc_tick(&s,10.8); CHECK(s.pulse_button==0); CHECK(s.close_left==0); /* 面板关了:停 | Panel closed: stop */ dm_tc_set_navigation_mode(&s,1); /* 第一下返回引出了确认框:后面不再按 | The first Back brought up a confirmation box: no more presses after that */
|
||||
dm_tc_begin_at(&s,0,330,60,20.0); dm_tc_pointer_item(&s,3); dm_tc_end_at(&s,0,20.1); dm_tc_tick(&s,20.12); CHECK(s.pulse_button==DM_BTN_B); CHECK(dm_tc_pulse_end(&s,s.pulse_epoch));
|
||||
{ dm_tc_scene sc={0}; dm_tc_navigation(&sc,"PanelManager","OpenPanel","ConfirmationModal"); }
|
||||
dm_tc_tick(&s,20.5); CHECK(s.pulse_button==0); CHECK(s.close_left==0);
|
||||
}
|
||||
static void scene_dialog_only(void) { /* 只开着 NPC 对话菜单 = 底栏十字可点的那个状态 | Only the NPC dialog menu is open = the state in which the bottom bar D-pad is tappable */
|
||||
dm_tc_scene sc={0};
|
||||
dm_tc_navigation(&sc,"PanelManager","UnloadPanel","LoadScreenPanel"); CHECK(!dm_tc_scene_dialog_only(&sc));
|
||||
CHECK(dm_tc_navigation(&sc,"PanelManager","OpenPanel","NpcDialogPanel")); CHECK(dm_tc_scene_dialog_only(&sc));
|
||||
dm_tc_navigation(&sc,"PanelManager","OpenPanel","NpcTradePanel"); CHECK(!dm_tc_scene_dialog_only(&sc));
|
||||
dm_tc_navigation(&sc,"PanelManager","ClosePanel","NpcTradePanel"); dm_tc_navigation(&sc,"PanelManager","ClosePanel","NpcDialogPanel"); CHECK(!dm_tc_scene_dialog_only(&sc));
|
||||
}
|
||||
static void pointer_drag_out(void) {
|
||||
dm_tc_state s; dm_tc_init(&s,667,375); dm_tc_set_navigation_mode(&s,1);
|
||||
dm_tc_begin_at(&s,0,300,180,10.0); dm_tc_move_at(&s,0,320,180,10.1); CHECK(s.pulse_button==DM_BTN_A); CHECK(dm_tc_pulse_end(&s,s.pulse_epoch));
|
||||
dm_tc_move_at(&s,0,20,300,10.5); dm_tc_pointer_release(&s,3); dm_tc_end_at(&s,0,10.6); /* 3 = 手指在面板外 | 3 = the finger is outside the panel */
|
||||
CHECK(s.pulse_button==DM_BTN_Y); NEAR(s.pulse_hold_s,0.15,0.001); NEAR(s.pointer_x,300,0.001); NEAR(s.pointer_y,180,0.001);
|
||||
CHECK(dm_tc_pulse_end(&s,s.pulse_epoch));
|
||||
dm_tc_begin_at(&s,0,300,180,11.0); dm_tc_move_at(&s,0,320,180,11.1); CHECK(dm_tc_pulse_end(&s,s.pulse_epoch));
|
||||
dm_tc_move_at(&s,0,340,200,11.5); dm_tc_end_at(&s,0,11.6); CHECK(s.pulse_button==DM_BTN_A); /* 没置位 = 缺省按物品区:照旧放下 | Not set = defaults to item area: put down as before */
|
||||
CHECK(dm_tc_pulse_end(&s,s.pulse_epoch));
|
||||
dm_tc_begin_at(&s,0,300,180,12.0); dm_tc_move_at(&s,0,320,180,12.1); CHECK(dm_tc_pulse_end(&s,s.pulse_epoch));
|
||||
dm_tc_move_at(&s,0,400,120,12.5); dm_tc_pointer_release(&s,4); dm_tc_end_at(&s,0,12.6); /* 4 = 抬起点不在物品区、手指点在:放在手指点 | 4 = the lift point is not in the item area but the finger point is: put down at the finger point */
|
||||
CHECK(s.pulse_button==DM_BTN_A); NEAR(s.pointer_x,400,0.001); NEAR(s.pointer_y,120,0.001); CHECK(dm_tc_pulse_end(&s,s.pulse_epoch));
|
||||
dm_tc_begin_at(&s,0,300,180,13.0); dm_tc_move_at(&s,0,320,180,13.1); CHECK(dm_tc_pulse_end(&s,s.pulse_epoch));
|
||||
dm_tc_move_at(&s,0,400,120,13.5); dm_tc_pointer_release(&s,0); dm_tc_end_at(&s,0,13.6); /* 0 = 面板里的空白处:放回原处,不丢 | 0 = blank area inside the panel: put back in place, not discarded */
|
||||
CHECK(s.pulse_button==DM_BTN_A); NEAR(s.pointer_x,300,0.001); NEAR(s.pointer_y,180,0.001);
|
||||
}
|
||||
static void pointer_drag(void) {
|
||||
dm_tc_state s; dm_tc_init(&s,667,375); dm_tc_set_navigation_mode(&s,1);
|
||||
dm_tc_begin_at(&s,0,300,180,10.0); dm_tc_move_at(&s,0,320,180,10.1);
|
||||
CHECK(s.pointer_valid); NEAR(s.pointer_x,300,0.001); NEAR(s.pointer_y,180,0.001);
|
||||
CHECK(s.pulse_button==DM_BTN_A); uint64_t first=s.pulse_epoch;
|
||||
CHECK(dm_tc_pulse_end(&s,first));
|
||||
dm_tc_move_at(&s,0,340,200,10.2);
|
||||
NEAR(s.pointer_x,340,0.001); NEAR(s.pointer_y,160,0.001);
|
||||
dm_tc_end_at(&s,0,10.3); NEAR(s.pointer_x,340,0.001); NEAR(s.pointer_y,160,0.001);
|
||||
CHECK(s.pulse_button==DM_BTN_A); CHECK(s.pulse_epoch!=first);
|
||||
}
|
||||
static void pointer_long(void) {
|
||||
dm_tc_state s; dm_tc_init(&s,667,375); dm_tc_set_navigation_mode(&s,1);
|
||||
dm_tc_begin_at(&s,0,300,180,10.0); dm_tc_tick(&s,10.5);
|
||||
CHECK(s.pointer_valid); NEAR(s.pointer_x,300,0.001); NEAR(s.pointer_y,180,0.001);
|
||||
CHECK(s.pulse_button==0); dm_tc_end_at(&s,0,10.6); CHECK(s.pulse_button==0);
|
||||
}
|
||||
static void pointer_shop_drag(void) { /* 从商人货架的货上起拖:不发「拿起」、光标留在货上;松手不发任何键、只计一次(买不买由前端按落点定) | Starting a drag on goods on the vendor shelf: no "pick up" is sent and the cursor stays on the goods; on release no key is sent, only one count is made (whether to buy is decided by the front end from the drop point) */
|
||||
dm_tc_state s; dm_tc_init(&s,667,375); s.mouse_click_mode=1; dm_tc_set_navigation_mode(&s,1);
|
||||
dm_tc_begin_at(&s,0,150,200,10.0); dm_tc_pointer_item(&s,7); CHECK(s.pointer_item==1); CHECK(s.pointer_shop==1);
|
||||
dm_tc_move_at(&s,0,300,220,10.3); CHECK(s.pulse_button==0); CHECK(s.finger[0].shop_drag); NEAR(s.pointer_x,2,0.001); NEAR(s.pointer_y,2,0.001); /* 光标挪到角上(收说明框),不跟手指 | The cursor moves to the corner (dismissing the tooltip) and does not follow the finger */
|
||||
dm_tc_move_at(&s,0,480,280,10.8); NEAR(s.pointer_x,2,0.001); NEAR(s.finger[0].aim_origin_x,150,0.001);
|
||||
dm_tc_end_at(&s,0,11.0); CHECK(s.pulse_button==0); CHECK(s.shop_drop_seq==1); CHECK(s.pointer_shop==0);
|
||||
dm_tc_begin_at(&s,0,150,200,12.0); dm_tc_pointer_item(&s,7); dm_tc_end_at(&s,0,12.1); CHECK(s.shop_drop_seq==1); /* 点货不买 | Tapping goods does not buy */
|
||||
}
|
||||
static void pointer_long_seq(void) { /* 物品区按住不动满长按时长、松手时计一次(前端据此调宿主「补充到腰带」);按住后又拖走的不计;别处的长按不计 | In the item area, holding still for the full long-press duration counts once on release (the front end calls the host's "refill to belt" based on this); holding and then dragging away does not count; long presses elsewhere do not count */
|
||||
dm_tc_state s; dm_tc_init(&s,667,375); s.mouse_click_mode=1; dm_tc_set_navigation_mode(&s,1);
|
||||
dm_tc_begin_at(&s,0,300,180,10.0); dm_tc_pointer_item(&s,1); dm_tc_tick(&s,10.6); CHECK(s.long_press_seq==0);
|
||||
dm_tc_end_at(&s,0,11.6); CHECK(s.long_press_seq==1); CHECK(s.pulse_button==0);
|
||||
dm_tc_begin_at(&s,0,300,180,12.0); dm_tc_pointer_item(&s,1); dm_tc_tick(&s,12.6); dm_tc_move_at(&s,0,360,220,12.8); dm_tc_end_at(&s,0,13.2); CHECK(s.long_press_seq==1);
|
||||
dm_tc_pulse_end(&s,s.pulse_epoch);
|
||||
dm_tc_begin_at(&s,0,300,180,14.0); dm_tc_pointer_item(&s,0); dm_tc_tick(&s,15.0); dm_tc_end_at(&s,0,15.1); CHECK(s.long_press_seq==1);
|
||||
}
|
||||
static void pointer_long_then_drag(void) { /* 按住停 0.5 秒再拖:照样拿起、松手放下 | Hold for 0.5 seconds and then drag: still picks up, and puts down on release */
|
||||
dm_tc_state s; dm_tc_init(&s,667,375); dm_tc_set_navigation_mode(&s,1);
|
||||
dm_tc_begin_at(&s,0,300,180,10.0); dm_tc_tick(&s,10.5); CHECK(s.pulse_button==0);
|
||||
dm_tc_move_at(&s,0,340,200,10.6); CHECK(s.pulse_button==DM_BTN_A); CHECK(dm_tc_pulse_end(&s,s.pulse_epoch));
|
||||
dm_tc_move_at(&s,0,400,240,11.0); dm_tc_end_at(&s,0,11.1); CHECK(s.pulse_button==DM_BTN_A);
|
||||
}
|
||||
static void pointer_control_hit(void) {
|
||||
dm_tc_state s; dm_tc_init(&s,667,375); dm_tc_set_navigation_mode(&s,1);
|
||||
press(&s,0,DM_TC_MAIN); CHECK(!s.pointer_valid); CHECK(s.buttons==DM_BTN_A);
|
||||
}
|
||||
static void pointer_game_mode(void) {
|
||||
dm_tc_state s; dm_tc_init(&s,667,375);
|
||||
dm_tc_begin_at(&s,0,300,180,10.0); dm_tc_move_at(&s,0,340,200,10.1);
|
||||
CHECK(!s.pointer_valid); CHECK(s.joy_slot==-1); dm_tc_end_at(&s,0,10.2); CHECK(!s.pointer_valid);
|
||||
}
|
||||
static void pointer_pulse_queue(void) {
|
||||
dm_tc_state s; dm_tc_init(&s,667,375); dm_tc_set_navigation_mode(&s,1);
|
||||
dm_tc_begin_at(&s,0,300,180,10.0); dm_tc_move_at(&s,0,320,180,10.1);
|
||||
// 「拿起」还没收手指就抬了:指针留在起点(游戏还没取走这下 A),「放下」只排着
|
||||
// The finger lifted before "pick up" was withdrawn: the pointer stays at the start point (the game has not yet taken this A), and "put down" is only queued
|
||||
dm_tc_end_at(&s,0,10.2); CHECK(s.pulse_button==DM_BTN_A); NEAR(s.pointer_x,300,0.001); NEAR(s.pointer_y,180,0.001); CHECK(!dm_tc_pulse_pending(&s));
|
||||
uint64_t first=s.pulse_epoch; CHECK(dm_tc_pulse_end(&s,first));
|
||||
// 收回后 A 松开、指针仍在起点,等前端 resume(中间留一次松开给游戏看)
|
||||
// After the withdrawal A is released and the pointer is still at the start point, waiting for the front end's resume (one release is left in between for the game to see)
|
||||
CHECK(s.pulse_button==0); CHECK(s.buttons==0); CHECK(dm_tc_pulse_pending(&s)); NEAR(s.pointer_y,180,0.001);
|
||||
CHECK(dm_tc_pulse_resume(&s)); CHECK(s.pulse_button==DM_BTN_A); CHECK(s.pulse_epoch!=first); NEAR(s.pointer_x,320,0.001); NEAR(s.pointer_y,140,0.001);
|
||||
CHECK(!dm_tc_pulse_resume(&s)); CHECK(dm_tc_pulse_end(&s,s.pulse_epoch)); CHECK(!dm_tc_pulse_pending(&s));
|
||||
}
|
||||
|
||||
/* 安全区内缩:956×440、左右各 62 点。期望手算:主键右沿 = 956−62 = 894 → 主键中心 x = 854(原 900,移 46);弧上四键与换组键同移 46;
|
||||
摇杆中心 x = 62+60 = 122(原 90);y 都不变。设回 0 后恢复原布局。
|
||||
Safe area inset: 956×440, 62 points on each of left and right. Expected values hand-computed: main button right edge = 956−62 = 894 → main button center x = 854 (was 900, moved 46); the four buttons on the arc and the set-switch button move the same 46;
|
||||
stick center x = 62+60 = 122 (was 90); all y unchanged. After setting back to 0 the original layout is restored. */
|
||||
static void safe_insets(void) {
|
||||
dm_tc_layout a, b; dm_tc_layout_make(&a, 956, 440);
|
||||
dm_tc_set_safe_insets(62, 62); dm_tc_layout_make(&b, 956, 440); dm_tc_set_safe_insets(0, 0);
|
||||
NEAR(a.target[DM_TC_MAIN].x, 900, 0.001); NEAR(b.target[DM_TC_MAIN].x, 854, 0.001); NEAR(b.target[DM_TC_MAIN].y, a.target[DM_TC_MAIN].y, 0.001);
|
||||
for (int i = DM_TC_SKILL1; i <= DM_TC_SKILL4; ++i) { NEAR(a.target[i].x - b.target[i].x, 46, 0.001); NEAR(a.target[i].y, b.target[i].y, 0.001); CHECK(b.target[i].x + b.target[i].r <= 894.001f); }
|
||||
NEAR(a.swap.x - b.swap.x, 46, 0.001); NEAR(a.joy_x, 90, 0.001); NEAR(b.joy_x, 122, 0.001); CHECK(b.joy_x - b.joy_radius >= 61.999f);
|
||||
dm_tc_layout c; dm_tc_layout_make(&c, 956, 440); NEAR(c.target[DM_TC_MAIN].x, 900, 0.001);
|
||||
}
|
||||
/* 换组键:956×440 下主键中心 (900,358),换组键在技能一正下方 (900−112, 358+52) = (788,410),半径 22;不与技能一(中心 (788,358) 半径 26)重叠、不出屏 | Set-switch button: at 956×440 the main button center is (900,358), the set-switch button is directly below skill one at (900−112, 358+52) = (788,410), radius 22; it does not overlap skill one (center (788,358), radius 26) and does not go off screen */
|
||||
static void swap_key(void) {
|
||||
dm_tc_layout l; dm_tc_layout_make(&l, 956, 440);
|
||||
NEAR(l.swap.x, 788, 0.001); NEAR(l.swap.y, 410, 0.001); NEAR(l.swap.r, 22, 0.001);
|
||||
CHECK(l.swap.y - l.swap.r >= l.target[DM_TC_SKILL1].y + l.target[DM_TC_SKILL1].r); CHECK(l.swap.y + l.swap.r <= 440);
|
||||
CHECK(dm_tc_hit(&l, 788, 410) == DM_TC_SWAP);
|
||||
}
|
||||
/* 腰带展开手势(956×440,u = 440/1320 = 1/3:腰带第 1 列格心 x = 478 + (1210−1434)/3 = 403.33、y = 1241.5/3 = 413.83)。
|
||||
(腰带一律松手后等过双击窗才喝。)只有 1 排:按下不发键、松手过窗 → 一个脉冲。4 排:按下不发键;松手没滑 → 过窗一个脉冲;上滑过 24 点 → 请求 1(展开)且不发键;下滑 → 请求 2。
|
||||
展开着:点上一排(y 高 165/3 = 55)同列 → 请求 0x100 | 1<<4 | 0,不发键;点世界别处 → 请求 2(收起)。
|
||||
Belt expand gesture (956×440, u = 440/1320 = 1/3: belt column 1 cell center x = 478 + (1210−1434)/3 = 403.33, y = 1241.5/3 = 413.83).
|
||||
(The belt always drinks only after release and once the double-tap window has passed.) Only 1 row: no key on press, release and window passed → one pulse. 4 rows: no key on press; release without sliding → one pulse after the window; slide up past 24 points → request 1 (expand) and no key; slide down → request 2.
|
||||
While expanded: tap the same column one row up (y higher by 165/3 = 55) → request 0x100 | 1<<4 | 0, no key; tap elsewhere in the world → request 2 (collapse). */
|
||||
static void belt_expand(void) {
|
||||
dm_tc_state s; dm_tc_init(&s, 956, 440); float bx = s.layout.target[DM_TC_BELT1].x, by = s.layout.target[DM_TC_BELT1].y;
|
||||
NEAR(bx, 403.333f, 0.01); NEAR(by, 413.833f, 0.01);
|
||||
dm_tc_begin_at(&s, 0, bx, by, 1.0); CHECK(s.buttons == 0); dm_tc_end_at(&s, 0, 1.05); CHECK(!s.belt_request); dm_tc_tick(&s, 1.05 + 0.01); CHECK(s.pulse_button == DM_BTN_LEFT); dm_tc_pulse_end(&s, s.pulse_epoch);
|
||||
s.belt_rows = 4; s.pulse_button = 0;
|
||||
dm_tc_begin_at(&s, 0, bx, by, 2.0); CHECK(s.buttons == 0); dm_tc_end_at(&s, 0, 2.05); dm_tc_tick(&s, 2.05 + 0.01); CHECK(s.pulse_button == DM_BTN_LEFT); CHECK(!s.belt_request); s.pulse_button = 0;
|
||||
dm_tc_begin_at(&s, 0, bx, by, 3.0); dm_tc_tick(&s, 3.4); CHECK(s.buttons == 0); dm_tc_end_at(&s, 0, 3.5); dm_tc_tick(&s, 3.5 + 0.01); CHECK(s.pulse_button == DM_BTN_LEFT); s.pulse_button = 0; /* 按住半秒不动:按住期间不发键,松手才喝 | Hold for half a second without moving: no key is sent while holding, drinks only on release */
|
||||
dm_tc_begin_at(&s, 0, bx, by, 4.0); dm_tc_move_at(&s, 0, bx, by - 30, 4.05); CHECK(s.belt_request == 0); CHECK(s.buttons == 0); dm_tc_end_at(&s, 0, 4.1); CHECK(s.belt_request == 1); CHECK(s.pulse_button == 0); s.belt_request = 0;
|
||||
dm_tc_begin_at(&s, 0, bx, by, 5.0); dm_tc_move_at(&s, 0, bx, by + 25, 5.05); dm_tc_end_at(&s, 0, 5.1); CHECK(s.belt_request == 2); CHECK(s.pulse_button == 0); s.belt_request = 0;
|
||||
dm_tc_begin_at(&s, 0, bx, by, 5.2); dm_tc_tick(&s, 5.4); dm_tc_move_at(&s, 0, bx, by - 30, 5.5); dm_tc_end_at(&s, 0, 5.55); CHECK(s.belt_request == 1); CHECK(s.pulse_button == 0); CHECK(s.buttons == 0); s.belt_request = 0; /* 按下停 0.2 秒再上滑:展开,不喝(实测撞到过) | Press, stay 0.2 seconds, then slide up: expands, does not drink (hit in actual testing) */
|
||||
dm_tc_begin_at(&s, 0, bx, by, 5.6); dm_tc_tick(&s, 5.8); dm_tc_move_at(&s, 0, bx, by + 36, 5.95); dm_tc_end_at(&s, 0, 5.95); CHECK(s.belt_request == 2); CHECK(s.pulse_button == 0); s.belt_request = 0; /* 0.35 秒慢慢下滑 36 点:收起,不喝(真机撞到过) | Slowly sliding down 36 points over 0.35 seconds: collapses, does not drink (hit on a real device) */
|
||||
dm_tc_begin_at(&s, 0, bx, by, 5.96); dm_tc_move_at(&s, 0, bx + 40, by, 5.97); dm_tc_end_at(&s, 0, 5.98); CHECK(!s.belt_request); CHECK(s.pulse_button == 0); /* 横着滑走:什么都不做 | Sliding away sideways: does nothing */
|
||||
CHECK(s.layout.target[DM_TC_BELT3].button == DM_BTN_DOWN && s.layout.target[DM_TC_BELT4].button == DM_BTN_RIGHT); /* 第 3 列 = 下、第 4 列 = 右(原版实测) | Column 3 = down, column 4 = right (measured in the original game) */
|
||||
s.belt_open = 1;
|
||||
dm_tc_begin_at(&s, 0, bx, by - 55.0f, 6.0); CHECK(s.buttons == 0); dm_tc_end_at(&s, 0, 6.05); dm_tc_tick(&s, 6.05 + 0.01); CHECK(s.belt_request == (0x100 | 1 << 4)); CHECK(s.pulse_button == 0); CHECK(s.world_tap_seq == 0); s.belt_request = 0;
|
||||
dm_tc_begin_at(&s, 0, bx + 40*3, by - (165.0f + 2*162.0f)/3, 7.0); dm_tc_end_at(&s, 0, 7.05); dm_tc_tick(&s, 7.05 + 0.01); CHECK(s.belt_request == (0x100 | 3 << 4 | 3)); s.belt_request = 0;
|
||||
dm_tc_begin_at(&s, 0, bx, by, 8.0); CHECK(!s.belt_request); dm_tc_end_at(&s, 0, 8.05); dm_tc_tick(&s, 8.05 + 0.01); CHECK(s.pulse_button == DM_BTN_LEFT); s.pulse_button = 0;
|
||||
CHECK(dm_tc_belt_outside(&s, 600, 150)); CHECK(!dm_tc_belt_outside(&s, bx, by)); CHECK(!dm_tc_belt_outside(&s, bx, by - 165.0f/3)); s.belt_open = 0; CHECK(!dm_tc_belt_outside(&s, 600, 150)); s.belt_open = 1;
|
||||
dm_tc_begin_at(&s, 0, 100, 250, 9.0); CHECK(s.belt_request == 2); CHECK(s.joy_slot == DM_TC_NONE); dm_tc_end_at(&s, 0, 9.05); CHECK(s.world_tap_seq == 0); CHECK(s.buttons == 0); /* 点别处(摇杆区):只收起,不成摇杆、不点世界 | Tap elsewhere (stick zone): only collapses, does not become the stick, does not tap the world */
|
||||
}
|
||||
/* 第二组里点得太短的技能等 ZL 领先再补发。等的时候点了多排腰带:腰带那下不许带 ZL(ZL + 腰带 = 喂佣兵)、
|
||||
不许被补发盖掉;腰带脉冲收回后 ZL 再领先满 DM_TC_ZL_LEAD_S 才补技能;全取消把等着的补发一起作废
|
||||
A skill tapped too briefly in the second set waits for ZL to lead before the make-up send. A multi-row belt is tapped while waiting: the belt tap must not carry ZL (ZL + belt = feed the mercenary) and
|
||||
must not be overwritten by the make-up send; after the belt pulse is withdrawn, ZL leads for a full DM_TC_ZL_LEAD_S again before the skill is made up; cancel-all voids the pending make-up send as well */
|
||||
static void deferred_skill_vs_belt(void) {
|
||||
/* 技能在等补发时点腰带:腰带那下排着,技能先按时补发(ZL 领先),等它收回后腰带再发、不带 ZL | tapping the belt while a skill awaits resend: the belt tap queues, the skill resends on time first (ZL leading), and after it is released the belt key is sent, without ZL */
|
||||
dm_tc_state s; dm_tc_init(&s, 667, 375); s.skill_set = 1; s.belt_rows = 4; s.last_time_s = 10.0;
|
||||
dm_tc_target k = s.layout.target[DM_TC_SKILL1], b = s.layout.target[DM_TC_BELT1];
|
||||
dm_tc_begin_at(&s, 0, k.x, k.y, 10.000); dm_tc_end_at(&s, 0, 10.050); CHECK(s.defer_button == k.button);
|
||||
dm_tc_begin_at(&s, 1, b.x, b.y, 10.080); dm_tc_end_at(&s, 1, 10.120);
|
||||
double skill = -1, belt = -1; int belt_zl = 0, zl_gap = 0; /* ZL 从技能松手(10.050)起就按着,补发前一直不断 | ZL is held from the skill release (10.050) onward, with no break until the make-up send */
|
||||
for (double t = 10.13; t < 11.0; t += 0.01) { dm_tc_tick(&s, t);
|
||||
if (skill < 0 && !(s.buttons & DM_BTN_ZL)) zl_gap = 1;
|
||||
if (s.pulse_button == k.button && skill < 0) { skill = t; dm_tc_tick(&s, t + 0.03); s.last_time_s = t + 0.03; CHECK(dm_tc_pulse_end(&s, s.pulse_epoch)); }
|
||||
else if (s.pulse_button == b.button && belt < 0) { belt = t; belt_zl = (s.buttons & DM_BTN_ZL) != 0; CHECK(dm_tc_pulse_end(&s, s.pulse_epoch)); } }
|
||||
CHECK(skill >= 10.000 + DM_TC_ZL_LEAD_S - 1e-9 && !zl_gap); /* 技能补发:ZL 领先够、中间不断 | Skill make-up send: ZL leads long enough, with no break in between */
|
||||
CHECK(belt > skill && belt >= 10.120 && !belt_zl); /* 腰带那下没丢、没被盖、不带 ZL(不变成喂佣兵) | The belt tap was not lost, not overwritten, and carries no ZL (does not turn into feeding the mercenary) */
|
||||
dm_tc_state c; dm_tc_init(&c, 667, 375); c.skill_set = 1; c.last_time_s = 20.0;
|
||||
dm_tc_begin_at(&c, 0, k.x, k.y, 20.000); dm_tc_end_at(&c, 0, 20.050); CHECK(c.defer_button);
|
||||
dm_tc_cancel_all(&c); dm_tc_tick(&c, 20.30); CHECK(c.defer_button == 0 && c.pulse_button == 0 && c.buttons == 0);
|
||||
}
|
||||
/* 手指一直按着第二组技能时点腰带:喝药那一脉冲期间不许有 ZL(ZL + 腰带键 = 喂佣兵)、也不许剩下不带 ZL 的技能键(= 放成第一组技能);
|
||||
脉冲收回后 ZL 先回来,技能键晚 DM_TC_ZL_LEAD_S 再回来。期望按规则手算
|
||||
Tapping the belt while a finger keeps holding a second-set skill: during the potion pulse there must be no ZL (ZL + belt key = feed the mercenary), nor a leftover skill key without ZL (= cast as the first-set skill);
|
||||
after the pulse is released ZL comes back first, and the skill key comes back DM_TC_ZL_LEAD_S later. Expectations computed by hand from the rule */
|
||||
static void held_skill2_vs_belt(void) {
|
||||
dm_tc_state s; dm_tc_init(&s, 667, 375); s.skill_set = 1; s.last_time_s = 30.0;
|
||||
dm_tc_target k = s.layout.target[DM_TC_SKILL1], b = s.layout.target[DM_TC_BELT1];
|
||||
dm_tc_begin_at(&s, 0, k.x, k.y, 30.000); for (double t = 30.01; t < 30.60; t += 0.01) dm_tc_tick(&s, t);
|
||||
CHECK((s.buttons & DM_BTN_ZL) && (s.buttons & k.button)); /* 按住半秒多:ZL + 技能键都在 | Held for a bit over half a second: ZL + the skill key are both present */
|
||||
dm_tc_begin_at(&s, 1, b.x, b.y, 30.600); dm_tc_end_at(&s, 1, 30.640);
|
||||
double belt = -1, back = -1, zl_back = -1, zl_off = -1; int bad_zl = 0, bad_key = 0;
|
||||
for (double t = 30.65; t < 31.60; t += 0.01) { dm_tc_tick(&s, t);
|
||||
if (belt < 0 && zl_off < 0 && !(s.buttons & DM_BTN_ZL)) { zl_off = t; CHECK(!(s.buttons & k.button)); } /* ZL 先松(技能键同时松),这时腰带键还没按 | ZL is released first (the skill key is released at the same time), and at this point the belt key is not pressed yet */
|
||||
if (s.pulse_button == b.button) { if (belt < 0) belt = t; if (s.buttons & DM_BTN_ZL) bad_zl = 1; if (s.buttons & k.button) bad_key = 1;
|
||||
if (t - belt > 0.025) { CHECK(dm_tc_pulse_end(&s, s.pulse_epoch)); dm_tc_tick(&s, t); } }
|
||||
else if (belt >= 0) { if (zl_back < 0 && (s.buttons & DM_BTN_ZL)) zl_back = t; if (back < 0 && (s.buttons & k.button)) { back = t; CHECK(s.buttons & DM_BTN_ZL); } } }
|
||||
CHECK(belt >= 30.640 && !bad_zl && !bad_key); /* 喝药脉冲发了、期间没有 ZL、没有技能键 | The potion pulse was sent, with no ZL and no skill key during it */
|
||||
CHECK(zl_off > 0 && belt - zl_off >= DM_TC_ZL_LEAD_S - 0.011); /* ZL 松开后空够一个领先时间腰带键才按(同一拍松 ZL + 按腰带键,游戏仍当 ZL 在) | the belt key is pressed only after a full lead time has gone by since ZL was released (releasing ZL + pressing the belt key in the same tick, the game still takes ZL as held) */
|
||||
CHECK(zl_back > belt && back - zl_back >= DM_TC_ZL_LEAD_S - 0.011); /* 收回后 ZL 先回、技能键晚一个领先时间回 | After the release ZL comes back first, and the skill key comes back one lead time later */
|
||||
dm_tc_end_at(&s, 0, 31.60);
|
||||
}
|
||||
/* 起手落在模态框外 / 被上层盖住(宿主判类 6)时,上下滑不起界面滚动手势;面板里其它地方(类 0)照旧起 | When the touch starts outside a modal box / covered by an upper layer (host hit class 6), sliding up or down does not start the UI scroll gesture; elsewhere in the panel (class 0) it starts as before */
|
||||
static void no_ui_drag_outside_modal(void) {
|
||||
for (int kind = 0; kind <= 6; kind += 6) {
|
||||
dm_tc_state s; dm_tc_init(&s, 667, 375); dm_tc_set_navigation_mode(&s, 1); s.mouse_click_mode = 1; s.last_time_s = 1.0;
|
||||
dm_tc_begin_at(&s, 0, 300, 100, 1.0); dm_tc_pointer_item(&s, kind);
|
||||
dm_tc_move_at(&s, 0, 300, 140, 1.05); dm_tc_move_at(&s, 0, 300, 200, 1.10);
|
||||
CHECK(s.finger[0].ui_drag == (kind == 6 ? 0 : 1));
|
||||
}
|
||||
}
|
||||
/* 腰带点一下 = 自己喝,松手那一刻就出腰带键(不带 ZL,第二组技能下也不带);不判双击:连点两下 = 两个腰带键脉冲,哪一下都不带 ZL(不喂雇佣兵)。
|
||||
展开后的上面几排按下就出 belt_request 0x1rc,点两下两次。期望按规则手算
|
||||
One tap on the belt = the player drinks; the belt key fires at the moment of release (without ZL, also under the second skill set); no double-tap detection: two quick taps = two belt key pulses, neither with ZL (no mercenary feeding).
|
||||
Upper rows when expanded send belt_request 0x1rc on press, two taps send two. Expected values are computed by hand from the rules */
|
||||
static void tap_belt(dm_tc_state *s, int slot, int target, double t0) {
|
||||
dm_tc_target t = s->layout.target[target]; dm_tc_begin_at(s, slot, t.x, t.y, t0); dm_tc_end_at(s, slot, t0 + 0.08);
|
||||
}
|
||||
static void belt_single_double(void) {
|
||||
for (int set = 0; set < 2; ++set) {
|
||||
dm_tc_state s; dm_tc_init(&s, 956, 440); s.skill_set = set; uint64_t k = s.layout.target[DM_TC_BELT2].button;
|
||||
/* 点一下:按着不出键,松手即出 | single tap: no key while held, key on release */
|
||||
double t = 10; dm_tc_tick(&s, t); dm_tc_begin_at(&s, 0, s.layout.target[DM_TC_BELT2].x, s.layout.target[DM_TC_BELT2].y, t); CHECK(s.buttons == 0);
|
||||
dm_tc_end_at(&s, 0, t + 0.08); CHECK(s.buttons == k); /* 不带 ZL | Without ZL */
|
||||
CHECK(dm_tc_pulse_end(&s, s.pulse_epoch)); CHECK(s.buttons == 0);
|
||||
/* 0.12 秒内连点两下,第一下的脉冲已收回:两个脉冲,都不带 ZL | two taps within 0.12 s, the first pulse already released: two pulses, neither with ZL */
|
||||
t = 20; dm_tc_tick(&s, t); tap_belt(&s, 0, DM_TC_BELT2, t); CHECK(s.buttons == k); unsigned e1 = s.pulse_epoch; CHECK(dm_tc_pulse_end(&s, e1));
|
||||
tap_belt(&s, 1, DM_TC_BELT2, t + 0.12); CHECK(s.buttons == k && s.pulse_epoch != e1); CHECK(dm_tc_pulse_end(&s, s.pulse_epoch)); CHECK(s.buttons == 0);
|
||||
/* 连点两下,第一下的脉冲还在发:第二下排着,收回后的下一拍补发,仍不带 ZL,一共两个 | two quick taps while the first pulse is still being sent: the second queues and is sent on the tick after release, still without ZL, two in total */
|
||||
t = 30; dm_tc_tick(&s, t); tap_belt(&s, 0, DM_TC_BELT2, t); e1 = s.pulse_epoch; tap_belt(&s, 1, DM_TC_BELT2, t + 0.10); CHECK(s.pulse_epoch == e1 && s.buttons == k);
|
||||
CHECK(dm_tc_pulse_end(&s, e1)); CHECK(s.buttons == 0); dm_tc_tick(&s, t + 0.20); CHECK(s.buttons == k && s.pulse_epoch != e1); CHECK(dm_tc_pulse_end(&s, s.pulse_epoch));
|
||||
dm_tc_tick(&s, t + 1.0); CHECK(s.buttons == 0 && !s.pulse_button); /* 不多喝 | no extra drink */
|
||||
/* 换一格 | switch to another slot */
|
||||
t = 40; dm_tc_tick(&s, t); tap_belt(&s, 0, DM_TC_BELT3, t); CHECK(s.buttons == s.layout.target[DM_TC_BELT3].button); dm_tc_pulse_end(&s, s.pulse_epoch);
|
||||
/* 展开的上面几排(第 1 排第 2 列):按下就请求,点两下请求两次 | upper rows when expanded (row 1, column 2): request on press, two taps make two requests */
|
||||
s.belt_rows = 3; s.belt_open = 1; float u = s.layout.height / 1320.0f, x = s.layout.target[DM_TC_BELT2].x, y = s.layout.target[DM_TC_BELT2].y - 165 * u;
|
||||
t = 60; dm_tc_tick(&s, t); dm_tc_begin_at(&s, 0, x, y, t); CHECK(s.belt_request == (0x100 | 1 << 4 | 1)); CHECK(s.buttons == 0); dm_tc_end_at(&s, 0, t + 0.08); s.belt_request = 0;
|
||||
dm_tc_begin_at(&s, 0, x, y, t + 0.2); CHECK(s.belt_request == (0x100 | 1 << 4 | 1)); CHECK(s.buttons == 0); dm_tc_end_at(&s, 0, t + 0.3); s.belt_request = 0;
|
||||
dm_tc_tick(&s, t + 1); CHECK(s.belt_request == 0);
|
||||
}
|
||||
}
|
||||
int main(void) {
|
||||
RUN(layout_667); RUN(layout_812); RUN(layout_956); RUN(layout_1024); RUN(layout_ipad169); RUN(layout_pixels); RUN(small_layout); RUN(difficulty_picker);
|
||||
RUN(hit_edges); RUN(key_hold_and_ownership); RUN(two_fingers_same_key); RUN(joystick_deadzone);
|
||||
RUN(joystick_axes); RUN(joystick_plus_skills); RUN(no_auto_handoff); RUN(background_no_key);
|
||||
RUN(circles_before_joystick); RUN(cancel_and_resize); RUN(deferred_skill_vs_belt); RUN(held_skill2_vs_belt); RUN(belt_single_double); RUN(no_ui_drag_outside_modal); RUN(invalid_slots_and_repeated_begin); RUN(all_slots_hold); RUN(enabled_targets); RUN(ui_scene_messages);
|
||||
RUN(pointer_tap); RUN(world_tap); RUN(pointer_outside_close); RUN(scene_dialog_only); RUN(pointer_item_tap); RUN(pointer_stack_tap); RUN(pointer_over_disabled_target); RUN(ui_drag_typing); RUN(pointer_drag_out); RUN(pointer_drag); RUN(pointer_long); RUN(pointer_long_then_drag); RUN(pointer_long_seq); RUN(pointer_shop_drag); RUN(pointer_control_hit); RUN(pointer_game_mode); RUN(pointer_pulse_queue); RUN(safe_insets); RUN(swap_key);
|
||||
RUN(belt_expand);
|
||||
printf("PASS %d/%d cases; %d/%d checks\n",cases,cases,checks,checks); return 0;
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
import importlib.util,unittest,os
|
||||
from pathlib import Path
|
||||
P=Path(os.environ.get('PAIR_SOURCE',str(Path(__file__).resolve().parents[1]/'tools/input_pair_check.py')))
|
||||
spec=importlib.util.spec_from_file_location('pair',P);pair=importlib.util.module_from_spec(spec);spec.loader.exec_module(pair)
|
||||
def state(lx=0):return dict(buttons=0,lx=lx,ly=0,rx=0,ry=0)
|
||||
def trace(axis=32767):
|
||||
ui=[];hid=[]
|
||||
for i,(phase,value) in enumerate([('began',0),('moved',axis),('ended',0)],1):
|
||||
n=i*100;v=state(value)
|
||||
ui.append(dict(stage='event',eventseq=i,mono_ns=n,source='uitouch',phase=phase,slot=0,touch='0x1',x=90+value/32767*60,y=200,touch_timestamp_s=42.125,mode='game',**v))
|
||||
ui.append(dict(stage='output',receiptseq=i,eventseq=i,event_first_seq=i,event_last_seq=i,mono_ns=n+10,publish_end_ns=n+20,source='uitouch',phase=phase,mode='game',**v))
|
||||
hid.append(dict(event='npad_return',read_start_ns=n+25,time_ns=n+30,sampling=i,id=32,style=2,attributes=1,script_mask=0,**v))
|
||||
return ui,hid
|
||||
class PairFixtureTests(unittest.TestCase):
|
||||
def case(self,f,status,reason=None):
|
||||
u,h=trace();f(u,h);g=pair.analyze(u,h,domain='synthetic')
|
||||
self.assertEqual(g['status'],status,g);self.assertFalse(g['physical_pass_claimed'],g)
|
||||
if reason:self.assertIn(reason,g['reasons'],g)
|
||||
def test_01_positive_right(self):self.case(lambda u,h:None,'protocol_pass')
|
||||
def test_02_positive_left(self):
|
||||
u,h=trace(-32767);g=pair.analyze(u,h);self.assertEqual(g['status'],'protocol_pass');self.assertFalse(g['physical_pass_claimed'])
|
||||
def test_03_release(self):
|
||||
u,h=trace();g=pair.analyze(u,h);self.assertEqual(g['status'],'protocol_pass');self.assertTrue(g['release_received'])
|
||||
def test_04_stale_equal(self):self.case(lambda u,h:h[1].update(read_start_ns=1,time_ns=2),'incomplete','missing_receipt')
|
||||
def test_05_invalid_controller_zero(self):self.case(lambda u,h:h[-1].update(id=99,style=0,attributes=0),'incomplete','invalid_controller')
|
||||
def test_06_non_touch_output(self):
|
||||
def f(u,h):
|
||||
u[:]=[dict(stage='output',receiptseq=1,eventseq=0,event_first_seq=0,event_last_seq=0,mono_ns=110,publish_end_ns=120,source='layout',phase='none',mode='game',**state(32767))]
|
||||
h[:]=[dict(event='npad_return',read_start_ns=125,time_ns=130,sampling=1,id=32,style=2,attributes=1,script_mask=0,**state(32767))]
|
||||
self.case(f,'incomplete','no_touch_pairs')
|
||||
def test_07_blank_no_receipt(self):self.case(lambda u,h:h.clear(),'incomplete','missing_receipt')
|
||||
def test_08_missing_release(self):self.case(lambda u,h:(u.__delitem__(slice(-2,None)),h.pop()),'incomplete','lifecycle_unclosed')
|
||||
def test_09_blank_activity_witness(self):
|
||||
u,h=trace(0);u[0]['blank']=True;h[1].update(sampling=26);h[2].update(sampling=27);g=pair.analyze(u,h);self.assertEqual(g['status'],'protocol_pass');self.assertTrue(g['blank_activity_received'])
|
||||
def test_10_script_confounded(self):self.case(lambda u,h:h[1].update(script_mask=33554432),'incomplete','script_confounded')
|
||||
def test_11_cap_reached(self):self.case(lambda u,h:h.append(dict(event='limit_reached',limit=1024)),'incomplete','limit_reached')
|
||||
def test_12_read_crosses_publish(self):self.case(lambda u,h:h[1].update(read_start_ns=215,time_ns=225),'incomplete','concurrent_undetermined')
|
||||
def test_13_stable_read_after_publish(self):self.case(lambda u,h:h[1].update(read_start_ns=230,time_ns=250),'protocol_pass')
|
||||
def test_14_duplicate_sampling(self):self.case(lambda u,h:h[1].update(sampling=1),'incomplete','sampling_not_forward')
|
||||
def test_15_fractional_integer(self):self.case(lambda u,h:h[1].update(lx=32767.9),'invalid_trace','bad_integer')
|
||||
def test_16_group_tail(self):self.case(lambda u,h:u[3].update(event_last_seq=1),'invalid_trace','event_group_not_closed')
|
||||
def test_17_no_dual_stream(self):
|
||||
u,h=trace();g=pair.analyze(u,None);self.assertEqual(g['status'],'pair_not_executed');self.assertFalse(g['physical_pass_claimed'])
|
||||
def test_18_state_mismatch(self):self.case(lambda u,h:h[1].update(lx=100),'incomplete','returned_state_mismatch')
|
||||
def test_19_device_domain_not_physical(self):
|
||||
u,h=trace();g=pair.analyze(u,h,domain='device');self.assertEqual(g['status'],'protocol_pass');self.assertFalse(g['physical_pass_claimed'])
|
||||
def test_20_slot_transition(self):self.case(lambda u,h:u[2].update(slot=1),'invalid_trace','slot_transition')
|
||||
def test_21_touch_timestamp_not_clock(self):
|
||||
u,h=trace();u[2]['touch_timestamp_s']=1e20;g=pair.analyze(u,h);self.assertEqual(g['status'],'protocol_pass')
|
||||
def test_22_release_not_neutral(self):
|
||||
def f(u,h):u[-1]['lx']=100;h[-1]['lx']=100
|
||||
self.case(f,'incomplete','release_not_neutral')
|
||||
def test_23_blank_unwanted_A(self):
|
||||
def f(u,h):u[0]['blank']=True;u[1]['buttons']=1;h[0]['buttons']=1
|
||||
self.case(f,'incomplete','blank_unwanted_A')
|
||||
def test_24_read_crosses_next_publish(self):self.case(lambda u,h:h[1].update(read_start_ns=250,time_ns=315),'incomplete','concurrent_undetermined')
|
||||
def test_25_unsigned_attribute_corruption(self):self.case(lambda u,h:h[1].update(attributes=-1),'invalid_trace','unsigned_range')
|
||||
def test_26_read_start_equals_publish_end(self):
|
||||
self.case(lambda u,h:h[1].update(read_start_ns=u[3]['publish_end_ns']),'incomplete','concurrent_undetermined')
|
||||
def test_27_matched_int32_overflow(self):
|
||||
def f(u,h):u[3]['lx']=2**31;h[1]['lx']=2**31
|
||||
self.case(f,'invalid_trace','int32_range')
|
||||
def binding_trace(self):
|
||||
u,h=trace();v=dict(buttons=256,lx=0,ly=0,rx=0,ry=0)
|
||||
u.insert(4,dict(stage='output',receiptseq=3,eventseq=2,event_first_seq=0,event_last_seq=2,mono_ns=260,publish_end_ns=270,source='bindings',phase='none',mode='game',**v))
|
||||
u[-1]['receiptseq']=4
|
||||
h.insert(2,dict(event='npad_return',read_start_ns=275,time_ns=280,sampling=3,id=32,style=2,attributes=1,script_mask=0,**v));h[-1]['sampling']=4
|
||||
return u,h
|
||||
def test_28_bindings_output_not_new_touch(self):
|
||||
u,h=self.binding_trace();g=pair.analyze(u,h)
|
||||
self.assertEqual(g['status'],'protocol_pass',g);self.assertEqual(g['touch_output_pairs'],3)
|
||||
self.assertEqual(g['pairs'][2]['attribution'],'output_only_not_new_touch')
|
||||
self.assertEqual(g['pairs'][2]['matched_sampling'],[3]);self.assertFalse(g['physical_pass_claimed'])
|
||||
def test_29_bindings_only_cannot_claim_touch(self):
|
||||
u,h=self.binding_trace();u=[u[4]];u[0].update(receiptseq=1,eventseq=0,event_first_seq=0,event_last_seq=0);h=[h[2]]
|
||||
g=pair.analyze(u,h);self.assertEqual(g['status'],'incomplete',g);self.assertIn('no_touch_pairs',g['reasons'])
|
||||
def test_30_bindings_cannot_be_touch_event(self):
|
||||
u,h=trace();u[0]['source']='bindings';g=pair.analyze(u,h)
|
||||
self.assertEqual(g['status'],'invalid_trace');self.assertIn('bad_event_source_phase',g['reasons'])
|
||||
def test_31_bindings_must_use_none_phase(self):
|
||||
u,h=self.binding_trace();u[4]['phase']='began';g=pair.analyze(u,h)
|
||||
self.assertEqual(g['status'],'invalid_trace');self.assertIn('bad_output_phase',g['reasons'])
|
||||
def test_32_unknown_program_source_still_rejected(self):
|
||||
u,h=self.binding_trace();u[4]['source']='unfrozen_future_source';g=pair.analyze(u,h)
|
||||
self.assertEqual(g['status'],'invalid_trace');self.assertIn('bad_source_or_mode',g['reasons'])
|
||||
def portal_trace(self,scope=2):
|
||||
base=dict(portal_request=7,portal_binding=8,portal_scene=9,portal_phase=1,portal_pending=1,modifier_publish_end_ns=120,feedback_group_start_ns=50,feedback_captured_ns=80,feedback_secondary=0,feedback_seen=63,feedback_identity_scope=scope)
|
||||
def ev(i,n,phase,buttons):return dict(stage='event',eventseq=i,mono_ns=n,source='uitouch',phase=phase,slot=0,touch='0x1',x=300,y=150,touch_timestamp_s=42,mode='game',**dict(state(),buttons=buttons))
|
||||
def out(i,e,n,phase,source,buttons,first,extra):return dict(stage='output',receiptseq=i,eventseq=e,event_first_seq=first,event_last_seq=e,mono_ns=n,publish_end_ns=n+10,source=source,phase=phase,mode='game',**dict(state(),buttons=buttons),**dict(base,**extra))
|
||||
u=[ev(1,100,'began',256),out(1,1,110,'began','uitouch',256,1,{}),out(2,1,200,'none','portal_sequence',258,0,dict(portal_phase=2,portal_pending=0,feedback_group_start_ns=150,feedback_captured_ns=180,feedback_secondary=1)),ev(2,300,'ended',0),out(3,2,310,'ended','uitouch',0,2,dict(portal_request=8,portal_phase=0,portal_pending=0,modifier_publish_end_ns=0))]
|
||||
h=[dict(event='npad_return',read_start_ns=n+15,time_ns=n+20,sampling=i,id=32,style=2,attributes=1,script_mask=0,**dict(state(),buttons=b))for i,n,b in [(1,110,256),(2,210,258),(3,310,0)]]
|
||||
return u,h
|
||||
def portal_case(self,change,status,reason,domain='synthetic'):
|
||||
u,h=self.portal_trace();change(u,h);g=pair.analyze(u,h,domain)
|
||||
self.assertEqual(g['status'],status,g);self.assertIn(reason,g['reasons'],g);self.assertFalse(g['physical_pass_claimed'])
|
||||
def test_33_portal_combo_actual_two_receipts(self):
|
||||
u,h=self.portal_trace();g=pair.analyze(u,h);self.assertEqual(g['status'],'protocol_pass',g)
|
||||
self.assertTrue(g['combo_received']);self.assertEqual(g['portal_combo_pairs'],1);self.assertEqual(g['touch_output_pairs'],2)
|
||||
self.assertEqual(g['pairs'][1]['attribution'],'output_only_not_new_touch');self.assertTrue(g['release_received']);self.assertFalse(g['physical_pass_claimed'])
|
||||
def test_34_portal_no_combo_read(self):self.portal_case(lambda u,h:h.pop(1),'incomplete','missing_combo_receipt')
|
||||
def test_35_portal_no_modifier_read(self):self.portal_case(lambda u,h:h.pop(0),'incomplete','missing_modifier_receipt')
|
||||
def test_36_portal_tied_combo_read(self):self.portal_case(lambda u,h:h[1].update(read_start_ns=210),'incomplete','concurrent_undetermined')
|
||||
def test_37_portal_old_group_start(self):self.portal_case(lambda u,h:u[2].update(feedback_group_start_ns=120),'invalid_trace','portal_feedback_time')
|
||||
def test_38_portal_future_feedback(self):self.portal_case(lambda u,h:u[2].update(feedback_captured_ns=200),'invalid_trace','portal_feedback_time')
|
||||
def test_39_portal_incomplete_group(self):self.portal_case(lambda u,h:u[2].update(feedback_seen=31),'invalid_trace','portal_feedback_identity')
|
||||
def test_40_portal_unknown_identity(self):self.portal_case(lambda u,h:u[2].update(feedback_identity_scope=0),'invalid_trace','portal_feedback_identity')
|
||||
def test_41_portal_synthetic_identity_device(self):self.portal_case(lambda u,h:None,'invalid_trace','synthetic_identity_on_device',domain='device')
|
||||
def test_42_portal_ack_after_release(self):
|
||||
def change(u,h):
|
||||
ack=u.pop(2);ack.update(mono_ns=400,publish_end_ns=410,receiptseq=3,eventseq=2,event_first_seq=0,event_last_seq=2);u[-1]['receiptseq']=2;u.append(ack)
|
||||
self.portal_case(change,'invalid_trace','portal_request_not_pending')
|
||||
def test_43_portal_binding_changed(self):self.portal_case(lambda u,h:u[2].update(portal_binding=10),'invalid_trace','portal_request_identity')
|
||||
def test_44_portal_scene_changed(self):self.portal_case(lambda u,h:u[2].update(portal_scene=10),'invalid_trace','portal_request_identity')
|
||||
def test_45_portal_request_changed(self):self.portal_case(lambda u,h:u[2].update(portal_request=10),'invalid_trace','portal_request_identity')
|
||||
def test_46_portal_duplicate_ack(self):
|
||||
def change(u,h):
|
||||
ack=dict(u[2],mono_ns=250,publish_end_ns=260,receiptseq=3);u.insert(3,ack);u[-1]['receiptseq']=4
|
||||
self.portal_case(change,'invalid_trace','portal_request_not_pending')
|
||||
def test_47_portal_source_is_not_event(self):self.portal_case(lambda u,h:u[0].update(source='portal_sequence'),'invalid_trace','bad_event_source_phase')
|
||||
def test_48_portal_field_fraction(self):self.portal_case(lambda u,h:u[2].update(portal_scene=9.5),'invalid_trace','bad_integer')
|
||||
def test_49_portal_field_negative(self):self.portal_case(lambda u,h:u[2].update(portal_binding=-1),'invalid_trace','portal_unsigned_range')
|
||||
def test_50_portal_missing_feedback_field(self):self.portal_case(lambda u,h:u[2].pop('feedback_captured_ns'),'invalid_trace','missing_fields:feedback_captured_ns')
|
||||
def test_51_portal_wrong_modifier_publication(self):self.portal_case(lambda u,h:u[1].update(modifier_publish_end_ns=121),'invalid_trace','portal_modifier_publication')
|
||||
def test_52_portal_not_ZL_prefix(self):self.portal_case(lambda u,h:u[1].update(buttons=2),'invalid_trace','portal_modifier_publication')
|
||||
def test_53_portal_no_action_edge(self):self.portal_case(lambda u,h:u[2].update(buttons=256),'invalid_trace','portal_action_edge')
|
||||
def test_54_portal_wrong_action_phase(self):self.portal_case(lambda u,h:u[2].update(portal_pending=1),'invalid_trace','portal_request_not_pending')
|
||||
def test_55_portal_navigation_ack(self):self.portal_case(lambda u,h:u[2].update(mode='navigation'),'invalid_trace','portal_request_not_pending')
|
||||
def test_56_portal_stale_feedback(self):self.portal_case(lambda u,h:u[2].update(mono_ns=250000181,publish_end_ns=250000191),'invalid_trace','portal_feedback_time')
|
||||
def test_57_portal_single_ui_still_not_executed(self):
|
||||
u,h=self.portal_trace();g=pair.analyze(u,None);self.assertEqual(g['status'],'pair_not_executed',g);self.assertFalse(g['combo_received'])
|
||||
def test_58_portal_native_identity_still_not_physical(self):
|
||||
u,h=self.portal_trace(scope=1);g=pair.analyze(u,h,domain='device');self.assertEqual(g['status'],'protocol_pass',g);self.assertTrue(g['combo_received']);self.assertFalse(g['physical_pass_claimed'])
|
||||
def test_59_portal_action_without_ack(self):
|
||||
def change(u,h):
|
||||
row=dict(u[1],receiptseq=2,event_first_seq=0,mono_ns=160,publish_end_ns=170,source='screenshot',phase='none',portal_phase=2,portal_pending=0,buttons=258);u.insert(2,row);u[3]['receiptseq']=3;u[-1]['receiptseq']=4
|
||||
self.portal_case(change,'invalid_trace','portal_action_without_ack')
|
||||
def test_60_portal_touch_cleared_before_ack(self):
|
||||
def change(u,h):
|
||||
row=dict(u[1],receiptseq=2,event_first_seq=0,mono_ns=160,publish_end_ns=170,source='layout',phase='none');u.insert(2,row);u[3]['receiptseq']=3;u[-1]['receiptseq']=4;u[-2]['slot']=-1
|
||||
self.portal_case(change,'invalid_trace','portal_touch_not_active')
|
||||
def test_61_portal_boolean_identity(self):self.portal_case(lambda u,h:u[2].update(portal_binding=True),'invalid_trace','boolean_not_integer')
|
||||
def test_62_portal_combo_drops_modifier(self):self.portal_case(lambda u,h:u[2].update(buttons=2),'invalid_trace','portal_action_edge')
|
||||
def test_63_portal_combo_ambiguous_edge(self):self.portal_case(lambda u,h:u[2].update(buttons=259),'invalid_trace','portal_action_edge')
|
||||
def test_64_modifier_read_after_feedback_is_not_causal(self):
|
||||
u,h=self.portal_trace();h[0].update(read_start_ns=185,time_ns=190);g=pair.analyze(u,h)
|
||||
self.assertEqual(g['status'],'incomplete',g);self.assertIn('modifier_not_before_feedback',g['reasons']);self.assertFalse(g['combo_received'])
|
||||
def test_65_modifier_read_equal_feedback_start_undetermined(self):
|
||||
u,h=self.portal_trace();h[0].update(read_start_ns=145,time_ns=150);g=pair.analyze(u,h)
|
||||
self.assertEqual(g['status'],'incomplete',g);self.assertIn('modifier_not_before_feedback',g['reasons']);self.assertFalse(g['combo_received'])
|
||||
def two_portal_requests(self,second):
|
||||
u,h=self.portal_trace();u2,h2=self.portal_trace()
|
||||
for row in u2:
|
||||
row['mono_ns']+=300;row['eventseq']+=2
|
||||
if row['stage']=='event':row['touch']='0x2'
|
||||
else:
|
||||
row['receiptseq']+=3;row['publish_end_ns']+=300;row['event_last_seq']+=2
|
||||
if row['event_first_seq']:row['event_first_seq']+=2
|
||||
row['portal_request']=second+(row['portal_phase']==0)
|
||||
for k in ['modifier_publish_end_ns','feedback_group_start_ns','feedback_captured_ns']:
|
||||
if row[k]:row[k]+=300
|
||||
for row in h2:row['read_start_ns']+=300;row['time_ns']+=300;row['sampling']+=3
|
||||
return u+u2,h+h2
|
||||
def test_66_two_requests_reuse_old_epoch_rejected(self):
|
||||
u,h=self.two_portal_requests(7);g=pair.analyze(u,h)
|
||||
self.assertEqual(g['status'],'invalid_trace',g);self.assertIn('portal_request_regression',g['reasons']);self.assertFalse(g['combo_received'])
|
||||
def test_67_two_requests_forward_epoch_valid(self):
|
||||
u,h=self.two_portal_requests(9);g=pair.analyze(u,h)
|
||||
self.assertEqual(g['status'],'protocol_pass',g);self.assertEqual(g['portal_combo_pairs'],2);self.assertTrue(g['combo_received']);self.assertFalse(g['physical_pass_claimed'])
|
||||
if __name__=='__main__':unittest.main()
|
||||
@@ -0,0 +1,40 @@
|
||||
#!/usr/bin/env python3
|
||||
"""素材采图契约与原素材哈希;不把synthetic snapshot当游戏身份。 | Asset capture contract and original asset hashes; a synthetic snapshot is not treated as game identity."""
|
||||
import argparse,hashlib,json,re
|
||||
from pathlib import Path
|
||||
import os; DM_ROOT = os.environ.get('DM_ROOT') or os.path.expanduser('~/dm-work') # 工作区根目录(游戏文件、产物、运行现场都在它下面) | Workspace root (game files, build outputs and run artifacts are all under it)
|
||||
IOS=Path(__file__).resolve().parent.parent
|
||||
sha=lambda p:hashlib.sha256(p.read_bytes()).hexdigest()
|
||||
try:
|
||||
# 这里原有一组「在 DmTouchOverlay.m 里找某段源码文字」的断言(底栏跳过宿主绘制、元数据字段、重画入口等),回城钮改版后对不上。
|
||||
# 它们守的是实现写法不是行为:底栏谁来画由回归整表的界面截图守,触摸到游戏的协议行为由本目录的 C 单测(t_native_binding / t_game_bridge / t_native_hud_bridge 等)守——删掉,不追着源码文字改。
|
||||
# 留下的是数据一致性:编进程序的三个哈希常量、清单、12 张贴图、两张技能表与实际文件一致。
|
||||
# There used to be a group of assertions here that "look for a piece of source text in DmTouchOverlay.m" (bottom bar skips host drawing, metadata fields, redraw entry, etc.), which no longer matched after the town portal button redesign.
|
||||
# They guarded how the implementation is written, not behavior: who draws the bottom bar is guarded by the UI screenshots of the full regression table, and the touch-to-game protocol behavior is guarded by the C unit tests in this directory (t_native_binding / t_game_bridge / t_native_hud_bridge etc.) - deleted, not chasing the source text with edits.
|
||||
# What remains is data consistency: the three hash constants compiled into the program, the manifest, the 12 textures and the two skill tables match the actual files.
|
||||
manifest=json.loads((IOS/'Sources/TouchArt/native_art_manifest.json').read_text())
|
||||
compiled=(IOS/'Sources/dm_touch_native_art.c').read_text()
|
||||
for name,target in [('dm_ta_manifest_sha',IOS/'Sources/TouchArt/native_art_manifest.json'),
|
||||
('dm_ta_geometry_sha',IOS/'docs/native_art_v1_geometry.json'),
|
||||
('dm_ta_binding_sha',IOS/'docs/touch_layout_spec_native_binding_v5.json')]:
|
||||
values=re.findall(r'\bconst\s+char\s+'+name+r'\s*\[\s*\]\s*=\s*"([^"\n]*)"\s*;',compiled)
|
||||
assert len(values)==1, f'{name} declaration must occur exactly once'
|
||||
assert values[0]==sha(target), f'{name} differs from actual file SHA256'
|
||||
assert manifest['geometry_sha256']==sha(IOS/'docs/native_art_v1_geometry.json')
|
||||
assert manifest['binding_protocol_sha256']==sha(IOS/'docs/touch_layout_spec_native_binding_v5.json')
|
||||
for a in manifest['assets']:
|
||||
assert sha(IOS/'Sources/TouchArt'/a['asset'])==a['derived_png_sha256']==a['decoded_png_sha256']
|
||||
assert a['pixel_format_code']==61 and len(a['official_sprite_md5'])==32 and len(a['official_sprite_sha256'])==64
|
||||
import os,sys
|
||||
romfs=os.environ.get('DM_ROMFS_SRC') or os.path.join(DM_ROOT, 'data/switch/3.3.94012/Update/RomFS') # 两张技能表不进仓库,从游戏文件现读核哈希 | the two skill tables are not kept in the repository; read fresh from the game files and verify the hashes
|
||||
if os.path.isfile(os.path.join(romfs,'data','build_manifest.psv')):
|
||||
sys.path.insert(0,str(IOS/'tools')); import romfs_art
|
||||
for table in manifest['official_tables']:
|
||||
raw=romfs_art.read(romfs,'global/excel/'+table['file'])
|
||||
assert hashlib.sha256(raw).hexdigest()==table['sha256']==table['official']['sha256']
|
||||
assert hashlib.md5(raw).hexdigest()==table['official']['ckey_md5']
|
||||
else: print('(这台机器没有游戏文件,跳过两张技能表的哈希核对)')
|
||||
assert len(manifest['assets'])==12
|
||||
print('PASS native_art_capture: 3/3 real C hash constants match actual files; geometry+binding hashes distinct; 12/12 decoded PNG hashes; 2/2 frozen official tables SHA+MD5')
|
||||
except AssertionError as e:
|
||||
print(f'FAIL: {e}');raise SystemExit(1)
|
||||
@@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env python3
|
||||
from pathlib import Path
|
||||
import hashlib,json
|
||||
root=Path(__file__).resolve().parents[1]
|
||||
# 这里原有 10 条「在 front_ios.m / DmTouchOverlay.m 里找某段源码文字」的断言(回城键绑定的刷新时机、字段名等),产品重构后对不上。
|
||||
# 它们守的协议行为现在由 C 单测 t_binding_freshness / t_portal_sequence / t_binding_group / t_native_binding 守,端到端由冒烟的触摸玩家路径和回归整表守——删掉。
|
||||
# 留下的是数据一致性:历版触屏布局规格文档冻结不动、现行版的哈希与编进程序的常量一致。
|
||||
# There used to be 10 assertions here that "look for a piece of source text in front_ios.m / DmTouchOverlay.m" (refresh timing of the town portal key binding, field names, etc.), which no longer matched after the product refactor.
|
||||
# The protocol behavior they guarded is now guarded by the C unit tests t_binding_freshness / t_portal_sequence / t_binding_group / t_native_binding, and end to end by the smoke test's touch player path and the full regression table - deleted.
|
||||
# What remains is data consistency: the touch layout spec documents of past versions stay frozen, and the current version's hash matches the constant compiled into the program.
|
||||
old=root/'docs/touch_layout_spec.json'
|
||||
assert hashlib.sha256(old.read_bytes()).hexdigest()=='38f3fed9acc16276ce278ae1b05ea7dad979e19cac53c447c4b73f014c3cb606'
|
||||
previous=root/'docs/touch_layout_spec_native_binding_v2.json'
|
||||
assert hashlib.sha256(previous.read_bytes()).hexdigest()=='2209cb320184d9ed58cd9fbee72dac734333773ff3332882405dba889749b13b'
|
||||
previous3=root/'docs/touch_layout_spec_native_binding_v3.json'
|
||||
assert hashlib.sha256(previous3.read_bytes()).hexdigest()=='c2921d0ef1bba260c30134603d4c2cbee50235483fa4b261e62069ef5cf9e3bb'
|
||||
previous4=root/'docs/touch_layout_spec_native_binding_v4.json'
|
||||
assert hashlib.sha256(previous4.read_bytes()).hexdigest()=='048ee8bfffa348d6a6829feb394ce723ad6acf892447d051eb7073b863a32d2f'
|
||||
new=root/'docs/touch_layout_spec_native_binding_v5.json'
|
||||
data=json.loads(new.read_text());assert data['profile_id']=='touch_native_binding_v5'
|
||||
assert hashlib.sha256(new.read_bytes()).hexdigest() in (root/'Sources/dm_touch_native_art.c').read_text()
|
||||
print('PASS frozen v1/v2/v3/v4 spec hashes; v5 profile/spec hash matches compiled constant')
|
||||
@@ -0,0 +1,19 @@
|
||||
from pathlib import Path
|
||||
import tempfile
|
||||
from test_touch_receipt import check_log
|
||||
base='[touch-receipt] stage=output receiptseq=1 eventseq=0 event_first_seq=0 event_last_seq=0 mono_ns=200 publish_end_ns=201 source=portal_sequence phase=none buttons=0x102 lx=0 ly=0 rx=0 ry=0 mode=game'
|
||||
checks=0
|
||||
with tempfile.TemporaryDirectory() as d:
|
||||
p=Path(d)/'receipt.log'
|
||||
p.write_text(base+'\n')
|
||||
try:check_log(p)
|
||||
except AssertionError:checks+=1
|
||||
else:raise AssertionError('portal_sequence must carry request/binding/scene/phase/pending/modifier timestamp')
|
||||
good=base+' portal_request=5 portal_binding=77 portal_scene=3 portal_phase=2 portal_pending=0 modifier_publish_end_ns=100 feedback_group_start_ns=110 feedback_captured_ns=180 feedback_secondary=1 feedback_seen=63 feedback_identity_scope=2'
|
||||
p.write_text(good+'\n');check_log(p);checks+=1
|
||||
for old,new in [('portal_request=5','portal_request=0'),('portal_pending=0','portal_pending=1'),('portal_phase=2','portal_phase=1'),('modifier_publish_end_ns=100 feedback_group_start_ns=110 feedback_captured_ns=180 feedback_secondary=1 feedback_seen=63 feedback_identity_scope=2','modifier_publish_end_ns=200'),('buttons=0x102','buttons=0x100'),('feedback_seen=63','feedback_seen=1'),('feedback_identity_scope=2','feedback_identity_scope=0'),('feedback_group_start_ns=110','feedback_group_start_ns=99')]:
|
||||
p.write_text(good.replace(old,new)+'\n')
|
||||
try:check_log(p)
|
||||
except AssertionError:checks+=1
|
||||
else:raise AssertionError('negative accepted: '+new)
|
||||
print(f'PASS portal_sequence receipt typed-phase/time/request negative {checks}/{checks} checks')
|
||||
@@ -0,0 +1,17 @@
|
||||
"""最小真实源接线约束;不声称UIImage/物理输入/原施法效果。 | Minimal real-source wiring constraints; makes no claim about UIImage / physical input / the original cast effect."""
|
||||
from pathlib import Path
|
||||
import argparse,hashlib,json
|
||||
p=argparse.ArgumentParser();p.add_argument('--ios-root',type=Path,default=Path(__file__).resolve().parents[1]);args=p.parse_args()
|
||||
ios=args.ios_root
|
||||
f=(ios/'Sources/front_ios.m').read_text()
|
||||
assert 'dm_input_set(_controls.buttons,_controls.lx,_controls.ly,_controls.rx,_controls.ry)' in f, 'front still drops right axis'
|
||||
assert f.count('rx=%d ry=%d')>=2, 'both UITouch and output must report actual right axes'
|
||||
assert f.count('_controls.lx,_controls.ly,_controls.rx,_controls.ry')>=3
|
||||
assert 'dm_tc_set_navigation_mode(&_controls,n)' in f, 'navigation must suppress combat aim'
|
||||
m=(ios/'Sources/DmTouchOverlay.m').read_text()
|
||||
assert '@"touch_native_binding_v5"' in m
|
||||
assert 's->map_cancel_active' in m and '@"right_aim"' in m
|
||||
d=ios/'docs/touch_layout_spec_native_binding_v5.json'
|
||||
assert json.loads(d.read_text())['profile_id']=='touch_native_binding_v5'
|
||||
assert hashlib.sha256(d.read_bytes()).hexdigest() in (ios/'Sources/dm_touch_native_art.c').read_text()
|
||||
print('PASS v5 source seam: full five-axis publish; real rx/ry receipts; navigation/cancel metadata; v5 spec SHA; runtime/phone UNRUN')
|
||||
@@ -0,0 +1,130 @@
|
||||
#!/usr/bin/env python3
|
||||
"""诊断收据契约:源接线检查及独立 transcript 判据,不把 STUB 当 HLE。 | Diagnostic receipt contract: source wiring checks and an independent transcript criterion, STUB is not treated as HLE."""
|
||||
import argparse
|
||||
import math
|
||||
import re
|
||||
from pathlib import Path
|
||||
|
||||
SOURCES = {'uitouch', 'navigation', 'layout', 'focus_cancel', 'screenshot', 'bindings', 'portal_sequence'}
|
||||
TOUCH_PHASES = {'began', 'moved', 'ended', 'cancelled'}
|
||||
|
||||
|
||||
def check_source(path):
|
||||
s = Path(path).read_text()
|
||||
assert '[touch-receipt]' in s, 'missing touch-receipt diagnostic records'
|
||||
assert 'getenv("DM_TOUCH_CONTROL_LOG")' in s, 'missing environment gate'
|
||||
assert '"cancelled"' in s, 'cancelled must not be mislabeled ended'
|
||||
for source in ('uitouch', 'layout', 'navigation', 'focus_cancel', 'screenshot', 'bindings', 'portal_sequence'):
|
||||
assert f'"{source}"' in s, f'missing source={source}'
|
||||
assert s.count('++_touchEventSeq') == 1, 'event sequence has one UIKit-only increment site'
|
||||
assert 'slot=-1' in s or 'int slot=-1' in s, 'unowned physical touch must remain observable'
|
||||
assert 'touch_timestamp_s=' in s and 'touch.timestamp' in s, 'missing original UITouch timestamp'
|
||||
assert 'event_first_seq=' in s and 'event_last_seq=' in s, 'missing publication event group'
|
||||
print('SOURCE PASS: env gate + 4 phases + 7 sources + UIKit-only eventseq + unowned physical point + raw timestamp + publication event group')
|
||||
|
||||
|
||||
def check_log(path):
|
||||
records = []
|
||||
for line in Path(path).read_text(errors='replace').splitlines():
|
||||
if '[touch-receipt]' not in line:
|
||||
continue
|
||||
pairs = dict(re.findall(r'(\w+)=([^\s]+)', line))
|
||||
records.append(pairs)
|
||||
assert records, 'missing touch-receipt diagnostic records'
|
||||
last_event = last_receipt = last_time = published_event = 0
|
||||
phases, sources = set(), set()
|
||||
pending_phases = []
|
||||
previous_publish_end = 0
|
||||
for r in records:
|
||||
for key in ('stage', 'eventseq', 'mono_ns', 'buttons', 'lx', 'ly', 'rx', 'ry', 'mode', 'source', 'phase'):
|
||||
assert key in r, f'missing {key}: {r}'
|
||||
assert r['source'] in SOURCES, f'unknown source={r["source"]}'
|
||||
assert r['phase'] in TOUCH_PHASES | {'none'}, f'unknown phase={r["phase"]}'
|
||||
event = int(r['eventseq'])
|
||||
mono = int(r['mono_ns'])
|
||||
assert mono >= last_time and mono > 0, 'nonmonotonic clock'
|
||||
assert mono >= previous_publish_end, 'record precedes previous publication end'
|
||||
last_time = mono
|
||||
if r['stage'] == 'event':
|
||||
assert event == last_event + 1, f'nonphysical or lost eventseq {last_event}->{event}'
|
||||
assert r['source'] == 'uitouch'
|
||||
assert r['phase'] in TOUCH_PHASES, 'event cannot use none phase'
|
||||
for key in ('slot', 'x', 'y', 'touch', 'touch_timestamp_s'):
|
||||
assert key in r
|
||||
assert math.isfinite(float(r['touch_timestamp_s'])) and float(r['touch_timestamp_s']) >= 0
|
||||
phases.add(r['phase'])
|
||||
pending_phases.append(r['phase'])
|
||||
last_event = event
|
||||
elif r['stage'] == 'output':
|
||||
assert event == last_event, f'program push changed eventseq {last_event}->{event}'
|
||||
for key in ('event_first_seq', 'event_last_seq'):
|
||||
assert key in r, f'missing publication {key}'
|
||||
first, last = int(r['event_first_seq']), int(r['event_last_seq'])
|
||||
assert last == event, 'publication group tail must match current eventseq'
|
||||
assert first == (published_event + 1 if event > published_event else 0), 'publication group must contain all and only newly received events'
|
||||
if first:
|
||||
assert r['source'] == 'uitouch', 'program source must not claim new physical events'
|
||||
assert all(phase == r['phase'] for phase in pending_phases), 'event group phase differs from output phase'
|
||||
pending_phases.clear()
|
||||
published_event = event
|
||||
receipt = int(r['receiptseq'])
|
||||
assert receipt == last_receipt + 1
|
||||
last_receipt = receipt
|
||||
previous_publish_end = int(r['publish_end_ns'])
|
||||
assert previous_publish_end >= mono, 'publication end precedes start'
|
||||
if r['source'] == 'portal_sequence':
|
||||
for key in ('portal_request','portal_binding','portal_scene','portal_phase','portal_pending','modifier_publish_end_ns','feedback_group_start_ns','feedback_captured_ns','feedback_secondary','feedback_seen','feedback_identity_scope'):
|
||||
assert key in r, f'missing portal_sequence {key}'
|
||||
assert all(int(r[key]) > 0 for key in ('portal_request','portal_binding','portal_scene'))
|
||||
assert int(r['portal_phase']) == 2 and int(r['portal_pending']) == 0
|
||||
assert 0 < int(r['modifier_publish_end_ns']) < mono, 'ACK must follow actual modifier publication'
|
||||
assert int(r['feedback_secondary']) == 1 and int(r['feedback_seen']) == 63
|
||||
assert int(r['feedback_identity_scope']) in {1, 2}, 'unconfirmed HUD identity cannot ACK'
|
||||
assert int(r['modifier_publish_end_ns']) < int(r['feedback_group_start_ns']) <= int(r['feedback_captured_ns']) <= mono
|
||||
mask = int(r['buttons'], 0)
|
||||
assert mask & 256 and mask & (1|2|4|8|128|512), 'ACK must publish modifier plus facet'
|
||||
sources.add(r['source'])
|
||||
assert (r['phase'] != 'none') == (r['source'] == 'uitouch')
|
||||
else:
|
||||
raise AssertionError(r)
|
||||
assert published_event == last_event, 'trailing physical events were not published'
|
||||
print(f'LOG PASS: records={len(records)} events={last_event} outputs={last_receipt} phases={",".join(sorted(phases))} sources={",".join(sorted(sources))}')
|
||||
return records, phases, sources
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
p = argparse.ArgumentParser()
|
||||
p.add_argument('--source')
|
||||
p.add_argument('--log')
|
||||
p.add_argument('--probe', action='store_true', help='要求确定性 FakeTouch 探针的13事件和全部取消来源')
|
||||
args = p.parse_args()
|
||||
try:
|
||||
if args.source:
|
||||
check_source(args.source)
|
||||
if args.log:
|
||||
records, phases, sources = check_log(args.log)
|
||||
if args.probe:
|
||||
assert phases == {'began', 'moved', 'ended', 'cancelled'}
|
||||
assert sources == {'uitouch', 'layout', 'navigation', 'focus_cancel', 'screenshot'}
|
||||
events = [r for r in records if r['stage'] == 'event']
|
||||
assert len(events) == 13, f'expected 13 independent probe events, got {len(events)}'
|
||||
assert [r['phase'] for r in events[:9]] == ['began','moved','moved','ended','began','cancelled','began','moved','ended']
|
||||
assert int(events[1]['lx']) == 32767, '60pt displacement must produce max left x'
|
||||
assert int(events[2]['slot']) == 0 and int(events[2]['lx']) == 0, 'navigation cancellation must keep physical slot but zero controls'
|
||||
assert int(events[7]['slot']) == -1 and float(events[7]['x']) == 147.0 and int(events[7]['lx']) == 0, 'focus cancellation must still record unowned physical point'
|
||||
assert int(events[8]['slot']) == -1 and events[8]['phase'] == 'ended'
|
||||
assert all(int(events[i]['buttons'], 0) == 0 for i in range(9))
|
||||
outputs = [r for r in records if r['stage'] == 'output']
|
||||
expected_sources = ['navigation', 'navigation', 'uitouch', 'uitouch', 'navigation',
|
||||
'uitouch', 'uitouch', 'navigation', 'uitouch', 'uitouch', 'uitouch',
|
||||
'focus_cancel', 'uitouch', 'uitouch', 'layout', 'screenshot', 'uitouch', 'uitouch']
|
||||
assert [r['source'] for r in outputs] == expected_sources, 'probe publication source order mismatch'
|
||||
groups = [(int(r['event_first_seq']), int(r['event_last_seq'])) for r in outputs if int(r['event_first_seq'])]
|
||||
assert groups == [(i, i) for i in range(1, 10)] + [(10, 11), (12, 13)], 'two-touch batches must publish both events'
|
||||
assert {int(r['slot']) for r in events[9:11]} == {0, 1}
|
||||
assert {int(r['slot']) for r in events[11:13]} == {0, 1}
|
||||
assert all(float(r['touch_timestamp_s']) == 42.125 for r in events), 'FakeTouch timestamp must stay unconverted'
|
||||
print('PROBE PASS: 13/13 events; 4/4 phases; 5/5 sources; navigation slot kept; focus point kept; cancel axis reset; 11/11 event groups; raw timestamp=42.125')
|
||||
except AssertionError as e:
|
||||
print(f'FAIL: {e}')
|
||||
raise SystemExit(1)
|
||||
Reference in New Issue
Block a user