Mirror the iOS layout instead of nesting Android inside dm/host:
- dm/android/app GameActivity app (manifest, java, res, build_apk.sh)
- dm/android/Sources front_app.c, touch_app.c, front_headless.c
- dm/android/Makefile entry point (apk / lib / install / headless / tests);
rules in build.mk (was dm/host/Makefile.android),
run with dm/host as cwd; outputs in dm/android/build/
- dm/android/tests t_vk_perf
- dm/gfx/vulkan nvn_vk.c and friends, next to the Metal backend
Only include paths, build paths and docs change; no code changes.
The Mac / iOS source lists do not pick up gfx/vulkan.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
703 lines
53 KiB
C
703 lines
53 KiB
C
// Android 局内触屏操作层:front_ios.m 里 DmMetalView(手势 → 手势层 dm_touch_controls → 宿主)与 DmTouchOverlay(画操作层)的移植。
|
||
// 坐标一律用 dp(≈ UIKit 点):Java 传视图尺寸、安全边距与触点时已除以 density。
|
||
// 线程:触点、每帧 tick、绘制都在 Java 界面线程;界面消息(touch_ui_message)在客体线程,只写原子量,界面线程 tick 时取用
|
||
// (iOS 这里用 dispatch_async 切主线程)。绘制不直接碰 Canvas:C 产出一张绘制指令表(浮点数组 + 字符串表),Java 照表画。
|
||
// 没移植:秘境任务条、货架拖货跟手图、测试脚本触点、操作层截图。
|
||
// Android in-run touch layer: port of DmMetalView (gestures → gesture layer dm_touch_controls → host) and DmTouchOverlay (draws the layer) from front_ios.m.
|
||
// All coordinates are dp (≈ UIKit points): Java divides the view size, safe insets and touch points by density before passing them.
|
||
// Threads: touches, the per-frame tick and drawing all run on the Java UI thread; UI messages (touch_ui_message) arrive on the guest thread and only write
|
||
// atomics that the UI-thread tick picks up (iOS uses dispatch_async to the main thread here). Drawing does not touch a Canvas: C emits a draw list
|
||
// (float array + string table) that Java executes.
|
||
// Not ported: Rift objective bar, the shelf-drag ghost image, scripted test touches, overlay capture.
|
||
#include "../../host/dm.h"
|
||
#include "../../host/front.h"
|
||
#include "../../host/hle.h"
|
||
#include "../../host/dm_input.h"
|
||
#include "../../host/dm_cursor.h"
|
||
#include "../../host/dm_hud.h"
|
||
#include "../../host/dm_world.h"
|
||
#include "../../host/dm_uiscreen.h"
|
||
#include "../../host/dm_actions.h"
|
||
#include "../../host/dm_i18n.h"
|
||
#include "../../host/dm_custom.h"
|
||
#include "../../touch/dm_touch_controls.h"
|
||
#include "../../touch/dm_touch_game_state.h"
|
||
#include "../../touch/dm_touch_native_art.h"
|
||
#include <jni.h>
|
||
#include <math.h>
|
||
#include <stdatomic.h>
|
||
#include <string.h>
|
||
#include <time.h>
|
||
|
||
void dm_tp_request(void);
|
||
int dm_drop_haptic_take(void);
|
||
int dm_padmode_busy(void);
|
||
void dm_padmode_request(int pad);
|
||
uint32_t dm_padmode_rebuilds(void);
|
||
int dm_swapskill_slot(int, int *);
|
||
int dm_freetp_zr_free(int zl);
|
||
void dm_ui_key_pulse_alone(uint64_t, int);
|
||
void uimsg_subscribe(void (*)(const char *, const char *, const char *));
|
||
|
||
static double now_s(void) { struct timespec t; clock_gettime(CLOCK_MONOTONIC, &t); return t.tv_sec + t.tv_nsec * 1e-9; }
|
||
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
||
#define MAX(a, b) ((a) > (b) ? (a) : (b))
|
||
|
||
// ---- 客体线程 → 界面线程 | guest thread → UI thread ----
|
||
static _Atomic int g_touch_frontend = 1, g_touch_navigation = 1, g_hud_blocked, g_cover;
|
||
static _Atomic int g_nav_pub;
|
||
int dm_front_navigation(void) { return atomic_load(&g_nav_pub); } // 面板 / 读取画面 / 过场开着:手柄 ZR 只在游戏态接管 | a panel / loading screen / cutscene is open: the pad's ZR is taken over only in game state
|
||
int dm_touch_frontend(void) { return atomic_load(&g_touch_frontend); }
|
||
static void restart_cover_hook(int on) { atomic_store(&g_cover, on); } // 0 撤 / 1 黑屏 / 2 透明但吞触点 | 0 remove / 1 black / 2 transparent but swallows touches
|
||
|
||
// ---- 触摸记录:Android 指针 id 会复用,iOS 的 UITouch 身份换成记录下标 | touch records: Android pointer ids get reused, records stand in for UITouch identity ----
|
||
enum { NREC = 32 };
|
||
static struct { int used, pid, done; float x, y; } R[NREC];
|
||
static int pid_rec(int pid) { for (int i = 0; i < NREC; i++) if (R[i].used && !R[i].done && R[i].pid == pid) return i; return -1; }
|
||
|
||
// ---- DmMetalView 状态 | DmMetalView state ----
|
||
static dm_tc_state C;
|
||
static float W, H; // 视图尺寸(dp) | view size (dp)
|
||
static int g_slot[16]; // 手指槽 → 记录;-1 = 空 | finger slot → record; -1 = empty
|
||
static uint32_t g_swallow; // 手柄模式 / 切换中 / 遮罩下落下的手指(记录位图) | fingers that landed in pad mode / mid-switch / under the cover (record bitmap)
|
||
static int g_pad, g_fe = 1, g_nav = -1, g_blocked_applied, g_dialog_only, g_hud_blocked_v;
|
||
static int ui_finger = -1, map_t = -1, mapback_t = -1, bind_t = -1, pend_end = -1;
|
||
static float fe_ox, fe_oy, map_x0, map_y0, bind_x0, bind_y0; static int fe_drag, ui_drag_on;
|
||
static double map_t0, pend_time, pend_wall; static int pend_fire, final_asked;
|
||
static uint64_t bind_key; static uint32_t sel_id; static double stat_next, tip_until, add_at;
|
||
static unsigned map_world_seq; static int map_world_asked; static float map_wx, map_wy;
|
||
static int pulse_ticking; static uint64_t pulse_epoch, pulse_s0; static double pulse_t0, pulse_seen, pulse_free;
|
||
static unsigned item_seq, rel_seq; static int rel_asked, item_asked, item_kind;
|
||
static double labels_at; static int labels_done;
|
||
static dm_hud_info g_hud; static dm_tg_snapshot g_native;
|
||
static int g_dirty = 1, g_haptic;
|
||
|
||
static int slot_of_rec(int t) { for (int i = 0; i < 16; i++) if (g_slot[i] == t) return i; return -1; }
|
||
static int rec_referenced(int t) { return slot_of_rec(t) >= 0 || t == ui_finger || t == map_t || t == mapback_t || t == bind_t || t == pend_end || (g_swallow >> t & 1); }
|
||
static void gc_recs(void) { for (int i = 0; i < NREC; i++) if (R[i].used && R[i].done && !rec_referenced(i)) R[i].used = 0; }
|
||
|
||
static void push(void) {
|
||
dm_touch ts[16]; int n = 0;
|
||
if (W > 0 && H > 0) for (int i = 0; i < 16; i++) if (g_slot[i] >= 0) {
|
||
int t = g_slot[i]; ts[n++] = (dm_touch){(uint32_t)i, fminf(fmaxf(R[t].x / W, 0), .99999f), fminf(fmaxf(R[t].y / H, 0), .99999f)};
|
||
}
|
||
dm_touch_set(ts, n);
|
||
if (C.pointer_valid) dm_cursor_set_screen(C.pointer_x, C.pointer_y, W, H); else dm_cursor_clear();
|
||
dm_input_set(C.buttons, C.lx, C.ly, C.rx, C.ry);
|
||
if (C.belt_request) { int br = C.belt_request; C.belt_request = 0; if (br == 1 || br == 2) dm_belt_expand(br == 1); else dm_belt_use(br & 0xf, br >> 4 & 0xf); }
|
||
if (C.diff_request) { dm_hud_request_players(C.diff_request); C.diff_request = 0; }
|
||
g_dirty = 1;
|
||
}
|
||
static void cancel_controls(void) {
|
||
pend_end = -1; final_asked = 0;
|
||
for (int i = 0; i < 16; i++) g_slot[i] = -1;
|
||
dm_tc_cancel_all(&C); push();
|
||
if (ui_drag_on) { ui_drag_on = 0; dm_ui_drag_end(); }
|
||
map_t = mapback_t = bind_t = -1;
|
||
}
|
||
static void set_pad_mode(int pad) {
|
||
g_pad = pad;
|
||
if (pad) { tip_until = -2; dm_tc_cancel_all(&C); push(); }
|
||
g_dirty = 1;
|
||
}
|
||
static void set_frontend(int fe) {
|
||
g_fe = fe;
|
||
if (fe) { pend_end = -1; final_asked = 0; for (int i = 0; i < 16; i++) g_slot[i] = -1; dm_tc_cancel_all(&C); push(); }
|
||
g_dirty = 1;
|
||
}
|
||
static void hud_blocked(int n) { g_hud_blocked_v = n > 0; g_dialog_only = n < 0; dm_tc_set_joy_block(&C, n < 0); g_dirty = 1; }
|
||
static void navigation_mode(int n) {
|
||
if (g_nav == n) return;
|
||
dm_tc_set_navigation_mode(&C, n); g_nav = n; atomic_store(&g_nav_pub, n);
|
||
static int pad = -1; if (pad < 0) { const char *e = getenv("DM_TOUCH_NAV_PAD"); pad = e && e[0] == '1'; }
|
||
uint32_t mask = n ? (dm_tc_nav_mask(pad && n != 2) | (n == 3 ? 1u << DM_TC_MENU : 0)) : (((1u << DM_TC_COUNT) - 1) & ~(1u << DM_TC_MAP));
|
||
dm_tc_enable_targets(&C, mask); push();
|
||
// 进局后第一次回游戏态:替玩家按一次 L 打开物品名标签(同 iOS itemLabelsOn,1.5 秒后) | first return to game state: press L once for the player to turn item labels on (as iOS itemLabelsOn, after 1.5 s)
|
||
if (!n && !labels_done && !labels_at) { const char *e = getenv("DM_TOUCH_DEFAULTS"); if (!(e && !strcmp(e, "0"))) labels_at = now_s() + 1.5; }
|
||
if (n && dm_ui_map_is_full()) { dm_ui_map_full(0); LOG("前端:开了面板,全屏地图先收回小地图"); }
|
||
}
|
||
// 客体线程发布的状态落到界面线程 | apply the state published by the guest thread on the UI thread
|
||
static void apply_pending(void) {
|
||
int fe = atomic_load(&g_touch_frontend); if (fe != g_fe) set_frontend(fe);
|
||
int hb = atomic_load(&g_hud_blocked); if (hb != g_blocked_applied) { g_blocked_applied = hb; hud_blocked(hb); }
|
||
navigation_mode(atomic_load(&g_touch_navigation));
|
||
}
|
||
|
||
// ---- 界面消息(客体线程):同 iOS hud_stack_message / touch_ui_message | UI messages (guest thread): as iOS hud_stack_message / touch_ui_message ----
|
||
enum { HUD_STACK_MAX = 64 };
|
||
static struct { char name[64]; int open; } g_hud_stack[HUD_STACK_MAX];
|
||
static void hud_stack_message(const char *act, const char *arg) {
|
||
if (!strcmp(act, "UnloadPanel") && !strcmp(arg, "LoadScreenPanel")) {
|
||
for (int i = 0; i < HUD_STACK_MAX; i++)
|
||
if (!(g_hud_stack[i].open > 0 && strcmp(g_hud_stack[i].name, "LoadScreenPanel") && dm_ui_panel_shown(g_hud_stack[i].name))) memset(&g_hud_stack[i], 0, sizeof g_hud_stack[i]);
|
||
} else if (!strcmp(act, "UnloadAll")) memset(g_hud_stack, 0, sizeof g_hud_stack);
|
||
else {
|
||
int tog = !strcmp(act, "TogglePanel");
|
||
int open = !strcmp(act, "OpenPanel") || !strcmp(act, "OpenExclusivePanel"), close = !strcmp(act, "ClosePanel") || !strcmp(act, "UnloadPanel");
|
||
if (!open && !close && !tog) return;
|
||
if (dm_ui_panel_resident(arg)) return;
|
||
int slot = -1; for (int i = 0; i < HUD_STACK_MAX; i++) if (!strcmp(g_hud_stack[i].name, arg)) { slot = i; break; }
|
||
if (slot < 0) for (int i = 0; i < HUD_STACK_MAX; i++) if (!g_hud_stack[i].name[0]) { slot = i; snprintf(g_hud_stack[i].name, sizeof g_hud_stack[i].name, "%s", arg); break; }
|
||
if (slot < 0) return;
|
||
if (tog) { open = g_hud_stack[slot].open <= 0; close = !open; }
|
||
if (close && g_hud_stack[slot].open <= 0) return;
|
||
if (open && g_hud_stack[slot].open > 0) return;
|
||
g_hud_stack[slot].open = open ? 1 : 0;
|
||
fprintf(stderr, "[hud] 面板栈 %s %s → %d\n", act, arg, g_hud_stack[slot].open);
|
||
}
|
||
int n = 0, dlg = 0;
|
||
for (int i = 0; i < HUD_STACK_MAX; i++) {
|
||
if (!strcmp(g_hud_stack[i].name, "NpcDialogPanel") || !strcmp(g_hud_stack[i].name, "ScrollSpeechPanel")) dlg |= g_hud_stack[i].open > 0;
|
||
else n += g_hud_stack[i].open;
|
||
}
|
||
if (!n && dlg) n = -1;
|
||
atomic_store(&g_hud_blocked, n);
|
||
}
|
||
static void touch_ui_message(const char *cat, const char *act, const char *arg) {
|
||
if (!strcmp(cat, "PanelManager")) hud_stack_message(act, arg);
|
||
static dm_tc_scene scene; static uint64_t scene_epoch = 1, world_epoch = 1; static int prev_mode = 1;
|
||
dm_tc_scene before = scene;
|
||
dm_tc_set_panel_state(dm_ui_panel_state());
|
||
int mode = dm_tc_navigation(&scene, cat, act, arg);
|
||
if (scene.game && atomic_load(&g_hud_blocked) > 0) mode = 1;
|
||
if (before.game != scene.game) ++world_epoch;
|
||
{ static uint32_t rb0; uint32_t rb = dm_padmode_rebuilds(); if (rb != rb0) { rb0 = rb; ++world_epoch; } }
|
||
if (mode != prev_mode) ++scene_epoch;
|
||
prev_mode = mode;
|
||
dm_touch_game_set_scene(!mode, scene_epoch, world_epoch);
|
||
atomic_store(&g_touch_frontend, !scene.game);
|
||
int nmode = mode ? (dm_tc_scene_dead() ? 2 : dm_tc_scene_dialog_only(&scene) && atomic_load(&g_hud_blocked) <= 0 ? 3 : 1) : 0;
|
||
atomic_store(&g_touch_navigation, nmode);
|
||
dm_uiscreen_set_panel(nmode == 1);
|
||
}
|
||
// front_run 在客体线程开头调 | called by front_run at the start of the guest thread
|
||
void touch_app_guest_start(void) {
|
||
extern void (*g_dm_restart_cover_hook)(int); g_dm_restart_cover_hook = restart_cover_hook;
|
||
uimsg_subscribe(touch_ui_message);
|
||
dm_touch_game_live_check(1);
|
||
if (!dm_touch_game_attach()) LOG("【红】技能绑定读取没挂上(产物没有观测门 OBS_BINDING_GETTER,或 main 模块不符):技能键图标 / 回城键绑定不工作");
|
||
}
|
||
|
||
// ---- 手柄模式(iOS dm_gamepad.m 的 apply / set_mode,Android 只有一路合并后的手柄) | pad mode (iOS dm_gamepad.m apply / set_mode; Android has one merged pad) ----
|
||
static int g_need_center;
|
||
static void pad_set_mode(int pad) {
|
||
if (g_pad == pad) return;
|
||
dm_padmode_request(pad); LOG("手柄:%s", pad ? "手柄有输入 → 手柄模式" : "碰了屏幕 → 触屏模式");
|
||
set_pad_mode(pad);
|
||
}
|
||
static int stick_on(int was, int32_t x, int32_t y) { double m = hypot(x, y) / DM_STICK_MAX; return was ? m >= 0.15 : m >= 0.25; }
|
||
static uint64_t pad_b; static int32_t pad_ax[4];
|
||
static void pad_apply(void) {
|
||
uint64_t b = pad_b; int32_t ax[4] = {pad_ax[0], pad_ax[1], pad_ax[2], pad_ax[3]};
|
||
static int on[2]; static uint64_t prev_b;
|
||
on[0] = stick_on(on[0], ax[0], ax[1]); on[1] = stick_on(on[1], ax[2], ax[3]);
|
||
if (!on[0] && !on[1]) g_need_center = 0;
|
||
if ((b & ~prev_b) || ((on[0] || on[1]) && !g_need_center)) pad_set_mode(1);
|
||
prev_b = b;
|
||
if (!g_pad || !on[0]) ax[0] = ax[1] = 0;
|
||
if (!g_pad || !on[1]) ax[2] = ax[3] = 0;
|
||
{ static uint64_t prev; static int mine;
|
||
if ((b & DM_BTN_ZR) && !(prev & DM_BTN_ZR)) { mine = !dm_front_navigation() && dm_freetp_zr_free((b & DM_BTN_ZL) != 0); if (mine) { dm_tp_request(); LOG("手柄:ZR(这一格空着)→ 免费回城"); } }
|
||
prev = b; if (mine) b &= ~(uint64_t)DM_BTN_ZR; if (!(b & DM_BTN_ZR) && !(prev & DM_BTN_ZR)) mine = 0; }
|
||
dm_pad_set(b, ax[0], ax[1], ax[2], ax[3]);
|
||
}
|
||
void touch_app_pad(uint64_t b, int32_t lx, int32_t ly, int32_t rx, int32_t ry) { pad_b = b; pad_ax[0] = lx; pad_ax[1] = ly; pad_ax[2] = rx; pad_ax[3] = ry; pad_apply(); }
|
||
static void gamepad_touched(void) { if (g_pad) { g_need_center = 1; pad_set_mode(0); pad_apply(); } }
|
||
|
||
// ---- 手势 | gestures ----
|
||
static uint64_t skill_key_at(float x, float y, int *empty) {
|
||
int i = dm_tc_hit(&C.layout, x, y);
|
||
if (i >= DM_TC_SKILL1 && i <= DM_TC_SKILL4 && (C.enabled_targets & (1u << i))) {
|
||
const dm_tc_target *t = &C.layout.target[i];
|
||
dm_ta_glyph g = dm_ta_current_set(&g_native, t->button, now_ns(), C.skill_set); *empty = g.status == DM_TA_EMPTY;
|
||
return t->button | (C.skill_set ? DM_BTN_ZL : 0);
|
||
}
|
||
return 0;
|
||
}
|
||
static int in_minimap(float x, float y) {
|
||
float r[4]; if (g_nav || W <= 0 || !dm_ui_minimap_rect(r)) return 0;
|
||
if (dm_tc_hit(&C.layout, x, y) >= 0) return 0;
|
||
float x0 = r[0] * W, y0 = r[1] * H, w = (r[2] - r[0]) * W, h = (r[3] - r[1]) * H, band = h / 4; if (band < 30) band = MIN(30, h * 0.4f);
|
||
return x >= x0 && x < x0 + w && y >= y0 && y < y0 + band;
|
||
}
|
||
static void refresh_portal_binding(void) {
|
||
{ dm_hud_info h; dm_hud_get(&h); h.x = h.y = 0; if (memcmp(&h, &g_hud, sizeof h)) { g_hud = h; g_dirty = 1; } }
|
||
dm_tg_snapshot s = {0}; dm_touch_game_snapshot(&s);
|
||
if (memcmp(&s.raw_skill_id, &g_native.raw_skill_id, sizeof s.raw_skill_id) || memcmp(&s.mapping, &g_native.mapping, sizeof s.mapping) || s.valid != g_native.valid) g_dirty = 1;
|
||
g_native = s;
|
||
if (g_nav || !s.supported) return;
|
||
uint64_t mask = 0; // 回城键不跟原生绑定(同 iOS) | the portal key does not follow the native binding (as iOS)
|
||
if (C.layout.target[DM_TC_PORTAL].button != mask || C.portal_binding_identity != s.binding_identity || C.portal_scene_epoch != s.scene_epoch) {
|
||
dm_tc_set_portal_binding(&C, mask, s.binding_identity, s.scene_epoch); push();
|
||
}
|
||
}
|
||
static void bind_tap_sync(void) {
|
||
float nx = 0, ny = 0;
|
||
{ static int was; int st = dm_ui_bind_active(); if (st == 2 && was != 2 && W > 0) { C.pointer_valid = 1; C.pointer_x = 0.155f * W; C.pointer_y = 0.5f * H; } was = st; }
|
||
int hk = dm_ui_bind_skill_hit(&nx, &ny); C.tap_button = 0; C.tap_move = 0;
|
||
if (!hk) sel_id = 0;
|
||
if (hk) { C.tap_x = nx * W; C.tap_y = ny * H;
|
||
if (hk == 1 && dm_ui_bind_active() == 2) C.tap_button = DM_BTN_Y;
|
||
else if (!dm_ui_bind_active()) C.tap_move = 1; }
|
||
}
|
||
static void ui_touch(const int *ts, int n, int ph) {
|
||
if (W <= 0 || H <= 0) return;
|
||
for (int k = 0; k < n; k++) {
|
||
int t = ts[k];
|
||
if (ph == 0 && ui_finger < 0) { ui_finger = t; fe_ox = R[t].x; fe_oy = R[t].y; fe_drag = 0; }
|
||
if (t != ui_finger) continue;
|
||
float px = R[t].x, py = R[t].y, dy = fabsf(py - fe_oy);
|
||
if (ph == 1 && !fe_drag && !ui_drag_on && dy > 10 && dy > fabsf(px - fe_ox) && dm_ui_fe_drag_ok()) {
|
||
fe_drag = 1; ui_drag_on = 1; dm_ui_touch(3, 0, 0); dm_ui_drag_begin(1, fe_ox / W, fe_oy / H, 0);
|
||
}
|
||
if (fe_drag) { if (ph == 1) dm_ui_drag_move(px / W, py / H); else if (ph == 2) { fe_drag = 0; ui_drag_on = 0; dm_ui_drag_end(); ui_finger = -1; } continue; }
|
||
dm_ui_touch(ph, px / W, py / H);
|
||
if (ph == 2) ui_finger = -1;
|
||
}
|
||
}
|
||
static void pulse_tick(void);
|
||
static void arm_pulse_end(void) {
|
||
if (pulse_ticking || (!C.pulse_button && !dm_tc_pulse_pending(&C))) return;
|
||
pulse_ticking = 1; pulse_epoch = 0; pulse_tick();
|
||
}
|
||
static void touches_began(const int *ts, int n) {
|
||
{ int was = g_pad; gamepad_touched();
|
||
if (was || dm_padmode_busy() || atomic_load(&g_cover)) { for (int k = 0; k < n; k++) g_swallow |= 1u << ts[k]; if (was) LOG("前端:手柄模式下碰屏 → 只切回触屏模式,这一下不执行"); return; } }
|
||
if (g_fe) { ui_touch(ts, n, 0); return; }
|
||
refresh_portal_binding();
|
||
void finish_touches(const int *, int, int);
|
||
if (pend_end >= 0) { int pt = pend_end; pend_fire = 1; finish_touches(&pt, 1, 0); pend_fire = 0; pend_end = -1; final_asked = 0; }
|
||
double now = now_s();
|
||
for (int k = 0; k < n; k++) {
|
||
int t = ts[k]; float px = R[t].x, py = R[t].y;
|
||
{ int ex = 0; C.belt_rows = dm_belt_rows(&ex); C.belt_open = ex;
|
||
if (dm_tc_belt_outside(&C, px, py)) { dm_belt_expand(0); LOG("前端:腰带展开着点别处 (%.0f,%.0f) → 只收腰带", px, py); continue; } }
|
||
if (!g_nav && bind_t < 0 && !dm_ui_bind_active()) { int em = 0; uint64_t bk = skill_key_at(px, py, &em); if (bk && em) { bind_t = t; bind_key = bk; bind_x0 = px; bind_y0 = py; map_t0 = now; continue; } }
|
||
if (map_t < 0 && in_minimap(px, py)) { map_t = t; map_x0 = px; map_y0 = py; map_t0 = now; continue; }
|
||
for (int i = 0; i < 16; i++) if (g_slot[i] < 0) {
|
||
g_slot[i] = t; { int ex = 0; C.belt_rows = dm_belt_rows(&ex); C.belt_open = ex; } dm_tc_begin_at(&C, i, px, py, now);
|
||
if (!g_nav && C.finger[i].target == DM_TC_PORTAL) { dm_tp_request(); LOG("前端:点回城钮 → 免费回城"); }
|
||
if (!g_nav && mapback_t < 0 && C.finger[i].target == DM_TC_NONE && dm_ui_map_is_full()) { mapback_t = t; map_x0 = px; map_y0 = py; map_t0 = now; }
|
||
if (C.navigation_mode && C.pointer_slot == i && W > 0) item_seq = dm_ui_item_query(px / W, py / H);
|
||
item_asked = 1; item_kind = -1; // iOS 原样:这两句不在 if 里 | as on iOS: these two are outside the if
|
||
break;
|
||
}
|
||
}
|
||
push();
|
||
}
|
||
static void touches_moved(const int *ts0, int n0) {
|
||
int ts[NREC], n = 0; for (int k = 0; k < n0; k++) if (!(g_swallow >> ts0[k] & 1)) ts[n++] = ts0[k];
|
||
if (!n) return;
|
||
if (g_fe) { ui_touch(ts, n, 1); return; }
|
||
if (ui_finger >= 0) { int m = 0, hit = 0; for (int k = 0; k < n; k++) { if (ts[k] == ui_finger) hit = 1; else ts[m++] = ts[k]; }
|
||
if (hit) { int u = ui_finger; ui_touch(&u, 1, 1); n = m; if (!n) return; } }
|
||
double now = now_s(); float sc = dm_tc_scale_for_size(W, H);
|
||
for (int k = 0; k < n; k++) {
|
||
int t = ts[k], i = slot_of_rec(t); if (i < 0) continue;
|
||
float px = R[t].x, py = R[t].y;
|
||
dm_tc_move_at(&C, i, px, py, now);
|
||
if (C.navigation_mode && C.pointer_slot == i && C.finger[i].ui_drag && W > 0) { dm_tc_finger *f = &C.finger[i];
|
||
if (!ui_drag_on) { ui_drag_on = 1; dm_ui_drag_lift(DM_TC_POINTER_LIFT_PT * sc / H); dm_ui_drag_begin(f->ui_drag, f->aim_origin_x / W, f->aim_origin_y / H, 44.0f / H); }
|
||
dm_ui_drag_move(px / W, py / H); }
|
||
if (C.navigation_mode && C.pointer_slot == i && C.finger[i].pointer_dragged && W > 0) { rel_seq = dm_ui_drop_query(px / W, (py - DM_TC_POINTER_LIFT_PT * sc) / H, py / H); rel_asked = 1; }
|
||
}
|
||
push();
|
||
arm_pulse_end();
|
||
}
|
||
// cancelled:0 = 抬起,1 = 系统取消 | cancelled: 0 = lifted, 1 = cancelled by the system
|
||
void finish_touches(const int *ts0, int n0, int cancelled) {
|
||
int ts[NREC], n = 0;
|
||
for (int k = 0; k < n0; k++) { if (g_swallow >> ts0[k] & 1) g_swallow &= ~(1u << ts0[k]); else ts[n++] = ts0[k]; }
|
||
if (ui_finger >= 0) { int m = 0, hit = 0; for (int k = 0; k < n; k++) { if (ts[k] == ui_finger) hit = 1; else ts[m++] = ts[k]; }
|
||
if (hit) { int u = ui_finger; ui_touch(&u, 1, 2); n = m; } }
|
||
if (!n) return;
|
||
double now = now_s(); float sc = dm_tc_scale_for_size(W, H);
|
||
for (int k = 0; k < n; k++) {
|
||
int t = ts[k]; float px = R[t].x, py = R[t].y;
|
||
if (t == map_t) { map_t = -1;
|
||
if (!cancelled && !g_nav && hypotf(px - map_x0, py - map_y0) <= 14 && now - map_t0 < 0.6) {
|
||
if (dm_ui_map_is_full()) { dm_ui_map_full(0); LOG("前端:点小地图那一块 (%.0f,%.0f) → 回小地图", px, py); }
|
||
else if (W > 0) { map_world_seq = dm_world_tap(px / W, py / H); map_world_asked = 1; map_wx = px; map_wy = py; } }
|
||
continue; }
|
||
if (t == bind_t) { bind_t = -1;
|
||
if (!cancelled && !g_nav && hypotf(px - bind_x0, py - bind_y0) <= 14) { dm_ui_bind_begin(bind_key); LOG("前端:点空技能位 (%.0f,%.0f) → 给键 %#llx 选技能", px, py, (unsigned long long)bind_key); }
|
||
continue; }
|
||
if (t == mapback_t) { mapback_t = -1;
|
||
if (!cancelled && !g_nav && dm_ui_map_is_full() && hypotf(px - map_x0, py - map_y0) <= 14 && now - map_t0 < 0.6) { dm_ui_map_full(0); LOG("前端:全屏地图开着,点空处 (%.0f,%.0f) → 回小地图", px, py); } }
|
||
if (!pend_fire && pend_end < 0 && !cancelled && C.navigation_mode && C.pointer_slot >= 0 && g_slot[C.pointer_slot] == t && W > 0) {
|
||
dm_tc_finger *pf = &C.finger[C.pointer_slot]; int wait = 0;
|
||
if (item_asked && dm_ui_item_result(item_seq) < 0) wait = 1;
|
||
else if (pf->pointer_dragged) {
|
||
dm_tc_move_at(&C, C.pointer_slot, px, py, now);
|
||
rel_seq = dm_ui_drop_query(px / W, (py - DM_TC_POINTER_LIFT_PT * sc) / H, py / H); rel_asked = 1; final_asked = 1; wait = 1; }
|
||
if (wait) { pend_end = t; pend_time = now; pend_wall = now; continue; }
|
||
}
|
||
int i = slot_of_rec(t); if (i < 0) continue;
|
||
if (cancelled) { dm_tc_finger *cf = &C.finger[i]; int drag = C.navigation_mode && C.pointer_slot == i && (cf->pointer_dragged || cf->shop_drag);
|
||
if (ui_drag_on && C.pointer_slot == i) { ui_drag_on = 0; dm_ui_drag_end(); }
|
||
if (drag) { int shop = cf->shop_drag; if (!shop) dm_tc_pointer_release(&C, 0); dm_tc_end_at(&C, i, now); LOG("前端:拖动中被系统取消触摸 → %s", shop ? "不买不取" : "放回原处"); }
|
||
else dm_tc_cancel_finger(&C, i);
|
||
if (C.pointer_slot < 0) { rel_asked = 0; item_asked = 0; }
|
||
g_slot[i] = -1; continue; }
|
||
if (C.navigation_mode && C.pointer_slot == i && C.finger[i].shop_drag) {
|
||
int rk = rel_asked ? dm_ui_item_result(rel_seq) : 0; if (rk < 0) rk = dm_ui_drop_last();
|
||
if (rk == 5 && !dm_ui_drop_bag()) LOG("前端:%s拖出后松在背包格以外的物品区 → 不%s", item_kind == 8 ? "一叠" : "货架上的货", item_kind == 8 ? "取" : "买");
|
||
else if ((rk == 5 || rk == 11) && W > 0) { dm_tc_finger *sf = &C.finger[i]; float ax = sf->aim_origin_x / W, ay = sf->aim_origin_y / H;
|
||
if (rk == 11) { dm_ui_stack_cube_at(ax, ay); LOG("前端:高级仓库里的一叠拖到魔盒格上松手 → 1 件进魔盒"); }
|
||
else if (item_kind == 8) { dm_ui_stack_take_at(ax, ay); LOG("前端:高级仓库里的一叠拖到背包松手 → 取 1 件"); }
|
||
else { LOG("前端:货架上的货拖到背包松手 → 买"); dm_ui_shop_buy_at(ax, ay); }
|
||
C.pointer_x = sf->aim_origin_x; C.pointer_y = sf->aim_origin_y; }
|
||
} else if (C.navigation_mode && C.pointer_slot == i && C.finger[i].pointer_dragged && rel_asked) {
|
||
int rr = dm_ui_item_result(rel_seq); if (rr < 0) rr = dm_ui_drop_last(); if (rr < 0) rr = 0; float dx, dy;
|
||
if ((rr == 5 && dm_ui_drop_point(&dx, &dy)) || (rr == 0 && dm_ui_origin_point(&dx, &dy))) dm_tc_pointer_release_at(&C, dx * W, dy * H);
|
||
else { if (rr == 7) { dm_shop_sell_cursor(); rr = 0; } dm_tc_pointer_release(&C, rr < 0 ? 1 : rr); }
|
||
}
|
||
rel_asked = 0;
|
||
if (C.navigation_mode && C.pointer_slot == i && item_asked) { item_asked = 0; dm_tc_pointer_item(&C, dm_ui_item_result(item_seq)); bind_tap_sync(); }
|
||
unsigned wt = C.world_tap_seq, mc = C.mouse_click_seq, tt = C.tab_tap_seq, us = C.use_seq, ids = C.ident_seq, sts = C.stack_take_seq, lps = C.long_press_seq, its = C.item_tap_seq;
|
||
if (ui_drag_on && C.pointer_slot == i) { ui_drag_on = 0; dm_ui_drag_end(); }
|
||
int was_ptr = C.pointer_slot == i; unsigned tm = C.tap_move_seq;
|
||
dm_tc_end_at(&C, i, pend_fire ? pend_time : now); g_slot[i] = -1;
|
||
if (C.tap_move_seq != tm) { uint32_t hid = dm_ui_hit_id();
|
||
if (hid && hid == sel_id) { if (hid <= 4) { dm_stat_add((int)hid - 1, 1); LOG("前端:再点同一个「+」(属性 %u)→ 加 1 点", hid - 1); } else add_at = C.last_time_s + 0.3; }
|
||
else { sel_id = hid; LOG("前端:点加点类按钮 → 选中(标识 %#x)", hid); } }
|
||
if (C.tab_tap_seq != tt) dm_ui_tab_go();
|
||
if (C.long_press_seq != lps) dm_ui_long_press();
|
||
if (C.item_tap_seq != its) dm_ui_item_tap();
|
||
if (C.stack_take_seq != sts) { dm_stash_take(1); LOG("前端:双击高级仓库里的一叠 → 取 1 件"); }
|
||
if (C.ident_seq != ids) dm_ui_identify_hovered();
|
||
if (C.use_seq != us) dm_ui_use_item();
|
||
if (C.world_tap_seq != wt && W > 0) { float wx = C.world_tap_x / W, wy = C.world_tap_y / H; dm_ui_world_tap(wx, wy, wx, wy); }
|
||
if (was_ptr && C.navigation_mode) tip_until = C.tap_move_seq != tm ? -1 : C.last_time_s + (C.mouse_click_seq != mc ? 0.05 : 2.8);
|
||
if (C.mouse_click_seq != mc && W > 0) { float nx = C.mouse_click_x / W, ny = C.mouse_click_y / H; dm_ui_touch(0, nx, ny); dm_ui_touch(2, nx, ny); }
|
||
}
|
||
push();
|
||
arm_pulse_end();
|
||
}
|
||
// 松手施放的脉冲:游戏真取走了(输入采样数前进、光标不扣着)才收回;iOS 用 120 Hz 定时器,这里每帧 tick 一次
|
||
// Release-to-cast pulse: released only once the game has really taken it (input samples advanced, cursor not holding it); iOS uses a 120 Hz timer, here once per frame tick
|
||
static void pulse_tick(void) {
|
||
uint64_t n = dm_input_samples(); double now = now_s();
|
||
if (C.pulse_button) {
|
||
if (pulse_epoch != C.pulse_epoch) { pulse_epoch = C.pulse_epoch; pulse_s0 = n; pulse_t0 = now; pulse_seen = 0; pulse_free = 0; }
|
||
if (!pulse_seen && n > pulse_s0) pulse_seen = now;
|
||
if (pulse_seen && !pulse_free && !dm_cursor_pending()) pulse_free = now;
|
||
double hold = C.pulse_hold_s;
|
||
int taken = pulse_seen && now - pulse_seen >= 0.12 && n - pulse_s0 >= 3 && !dm_cursor_pending() && (hold <= 0 || (pulse_free && now - pulse_free >= hold));
|
||
if (taken || now - pulse_t0 > 2.0 + hold) {
|
||
if (!taken) LOG("[touch] 【红】脉冲 2 秒内游戏没取走(取了 %llu 次,扣着 %d 下),强制收回", (unsigned long long)(n - pulse_s0), dm_cursor_pending());
|
||
if (dm_tc_pulse_end(&C, pulse_epoch)) push();
|
||
pulse_s0 = n; pulse_t0 = now;
|
||
}
|
||
} else if (dm_tc_pulse_pending(&C)) {
|
||
if (n - pulse_s0 >= 2 || now - pulse_t0 > 0.5) { if (dm_tc_pulse_resume(&C)) push(); }
|
||
} else pulse_ticking = 0;
|
||
}
|
||
static void tick(double now) {
|
||
apply_pending();
|
||
int hide = g_fe || g_pad || dm_padmode_busy();
|
||
{ static int lh = -1; if (hide != lh) { lh = hide; g_dirty = 1; } }
|
||
{ int t = dm_drop_haptic_take(); if (t >= 1 && t <= 3) { g_haptic = t; LOG("掉落震动:前端震第 %d 档", t); } }
|
||
if (labels_at && now >= labels_at) { labels_at = 0; if (!g_nav && !labels_done) { labels_done = 1; dm_ui_key_pulse_alone(DM_BTN_L, 9); } }
|
||
dm_tc_set_tap_box(dm_ui_tap_box()); dm_tc_set_cur_stack(dm_ui_cur_stack_id()); dm_tc_set_hover_unid(dm_ui_hover_unid());
|
||
{ dm_hud_info hi; dm_hud_get(&hi); dm_tc_set_holding(&C, hi.valid && hi.holding && !dm_ui_targeting()); }
|
||
if (item_asked && C.navigation_mode && C.pointer_slot >= 0) { int ir = dm_ui_item_result(item_seq); if (ir >= 0) { item_asked = 0; item_kind = ir; dm_tc_pointer_item(&C, ir); } }
|
||
if (pend_end >= 0) {
|
||
int ready = !(item_asked && dm_ui_item_result(item_seq) < 0) && !(final_asked && dm_ui_item_result(rel_seq) < 0);
|
||
if (ready || now - pend_wall > 0.25) { int pt = pend_end;
|
||
pend_fire = 1; finish_touches(&pt, 1, 0); pend_fire = 0; pend_end = -1; final_asked = 0; }
|
||
}
|
||
bind_tap_sync();
|
||
float sc = dm_tc_scale_for_size(W, H);
|
||
if (C.navigation_mode && !dm_ui_bind_active() && !item_asked && C.pointer_slot >= 0 && C.pointer_slot < DM_TC_MAX_TOUCH) {
|
||
dm_tc_finger *f = &C.finger[C.pointer_slot]; float nx = 0, ny = 0; uint32_t hid = dm_ui_hit_id();
|
||
if (f->active && !f->pointer_dragged && !f->ui_drag && now - f->start_time_s >= 0.5 && hypotf(f->x - f->aim_origin_x, f->y - f->aim_origin_y) <= 10 * sc && dm_ui_bind_skill_hit(&nx, &ny) == 2 && hid >= 1 && hid <= 4) {
|
||
if (!f->pointer_long) { f->pointer_long = 1; stat_next = now; sel_id = hid; C.pointer_valid = 1; C.pointer_x = nx * W; C.pointer_y = ny * H; LOG("前端:按住「+」(属性 %u)→ 连续加点", hid - 1); }
|
||
if (now >= stat_next) { stat_next = now + 0.15; dm_stat_add((int)hid - 1, 1); } }
|
||
}
|
||
if (C.navigation_mode && !dm_ui_bind_active() && !item_asked && C.pointer_slot >= 0 && C.pointer_slot < DM_TC_MAX_TOUCH) {
|
||
dm_tc_finger *f = &C.finger[C.pointer_slot]; float nx = 0, ny = 0;
|
||
if (pend_end < 0 && f->active && !f->pointer_dragged && !f->pointer_long && now - f->start_time_s >= 0.5 && hypotf(f->x - f->aim_origin_x, f->y - f->aim_origin_y) <= 10 * sc && dm_ui_bind_skill_hit(&nx, &ny) == 1) {
|
||
dm_tc_pointer_press(&C, nx * W, ny * H, DM_BTN_Y); LOG("前端:技能树里长按技能 (%.0f,%.0f) → 开绑定框", nx * W, ny * H); }
|
||
}
|
||
if (map_world_asked) { int wr = dm_world_tap_result(map_world_seq);
|
||
if (wr >= 0) { map_world_asked = 0; if (wr == 0 && !g_nav) { dm_ui_map_full(1); LOG("前端:点小地图那一块 (%.0f,%.0f) → 全屏地图", map_wx, map_wy); }
|
||
else LOG("前端:点小地图那一块 (%.0f,%.0f) → 底下有世界目标(类 %d),交互、不切地图", map_wx, map_wy, wr); } }
|
||
if (add_at > 0 && now >= add_at) { dm_points_info pi; dm_points_get(&pi);
|
||
if (pi.tree_open && pi.sel_skill >= 0 && !dm_cursor_pending()) { add_at = 0; if (pi.sel_block == 0 || pi.sel_block == 5) dm_skill_add_selected(); else LOG("前端:再点同一个技能 → 不能加(原因 %d),不发", pi.sel_block); }
|
||
else if (now > add_at + 1.0 || !pi.tree_open) add_at = 0; }
|
||
if (!C.navigation_mode || g_pad) tip_until = -2;
|
||
else if (C.pointer_slot >= 0) tip_until = -1;
|
||
else if (tip_until == -2) { if (dm_ui_free_cursor()) tip_until = now + 0.3; }
|
||
else if (tip_until > 0 && now >= tip_until && !C.holding && !dm_ui_bind_active() && !dm_ui_touch_active() && !C.pulse_button && !dm_tc_pulse_pending(&C) && !dm_cursor_pending()) {
|
||
C.pointer_valid = 1; C.pointer_x = 0.02f * W; C.pointer_y = 0.5f * H; tip_until = 0; }
|
||
uint64_t tb = C.buttons;
|
||
dm_tc_tick(&C, now);
|
||
{ int fg = 0; for (int i = 0; i < DM_TC_MAX_TOUCH; i++) fg |= C.finger[i].active; dm_ui_hand_idle(!fg && !C.pulse_button && !dm_tc_pulse_pending(&C) && !dm_cursor_pending() && !dm_ui_touch_active()); }
|
||
if (C.buttons != tb && !C.pulse_button) push();
|
||
else if (C.belt_request && !C.pulse_button) push();
|
||
if (C.pulse_button && !pulse_ticking) { push(); arm_pulse_end(); }
|
||
if (C.pointer_valid) dm_cursor_set_screen(C.pointer_x, C.pointer_y, W, H);
|
||
else if (C.navigation_mode) dm_cursor_clear();
|
||
if (pulse_ticking) pulse_tick();
|
||
refresh_portal_binding();
|
||
{ static uint64_t lb; static int32_t llx, lly; if (C.buttons != lb || C.lx != llx || C.ly != lly) { lb = C.buttons; llx = C.lx; lly = C.ly; g_dirty = 1; } }
|
||
}
|
||
|
||
// ---- 绘制指令表(Java TouchOverlay 照表画;与 DmTouchOverlay.m drawRect 一一对应) | draw list (executed by Java TouchOverlay; mirrors DmTouchOverlay.m drawRect) ----
|
||
enum { OP_FILL_ELLIPSE = 1, OP_STROKE_ELLIPSE, OP_LINE, OP_ARC, OP_IMAGE, OP_TEXT, OP_FILL_RECT, OP_V4, OP_V4TEXT, OP_LABEL, OP_COVER };
|
||
// 三层:0 = HUD 主体,1 = 摇杆,2 = 小地图任务终点(draw_goals)。手指在摇杆上动时只有摇杆层变,主体层(GPU 缓存成一张纹理)不重画——
|
||
// 整层 HUD 每帧在 HWUI 里重画要占 GPU 6–11 ms,和游戏抢同一块 GPU,跑动中转向(手指一直在动)就掉帧
|
||
// Three layers: 0 = HUD body, 1 = joystick, 2 = minimap quest goals (draw_goals). While a finger moves on the stick only the joystick layer changes, and the body layer (cached on the GPU as one texture) is not redrawn --
|
||
// redrawing the whole HUD in HWUI every frame cost 6-11 ms of GPU, competing with the game for the same GPU, so turning while running (finger always moving) dropped frames
|
||
typedef struct { float ops[8192]; int n; char str[96][64]; int nstr; } op_list;
|
||
static op_list g_drawn[3], g_probe; static op_list *g_ol = &g_drawn[0];
|
||
static void op(int code, int n, const float *v) {
|
||
if (g_ol->n + n + 2 > (int)(sizeof g_ol->ops / sizeof *g_ol->ops)) return;
|
||
g_ol->ops[g_ol->n++] = (float)code; g_ol->ops[g_ol->n++] = (float)n; memcpy(&g_ol->ops[g_ol->n], v, n * sizeof *v); g_ol->n += n;
|
||
}
|
||
static float str(const char *s) {
|
||
for (int i = 0; i < g_ol->nstr; i++) if (!strcmp(g_ol->str[i], s)) return (float)i;
|
||
if (g_ol->nstr >= 96) return -1;
|
||
snprintf(g_ol->str[g_ol->nstr], sizeof g_ol->str[0], "%s", s); return (float)g_ol->nstr++;
|
||
}
|
||
static int same_list(const op_list *a, const op_list *b) {
|
||
if (a->n != b->n || a->nstr != b->nstr || memcmp(a->ops, b->ops, a->n * sizeof *a->ops)) return 0;
|
||
for (int i = 0; i < a->nstr; i++) if (strcmp(a->str[i], b->str[i])) return 0;
|
||
return 1;
|
||
}
|
||
#define OPV(code, ...) do { const float v_[] = {__VA_ARGS__}; op(code, (int)(sizeof v_ / sizeof *v_), v_); } while (0)
|
||
static void fill_ellipse(float x, float y, float w, float h, float r, float g, float b, float a) { OPV(OP_FILL_ELLIPSE, x, y, w, h, r, g, b, a); }
|
||
static void stroke_ellipse(float x, float y, float w, float h, float lw, float r, float g, float b, float a) { OPV(OP_STROKE_ELLIPSE, x, y, w, h, lw, r, g, b, a); }
|
||
static void caption(const char *s, float x, float y, float w, float h, float size, float alpha) { OPV(OP_TEXT, str(s), x, y, w, h, size, alpha); }
|
||
// 图:素材路径(备用路径,-1 无),裁切框(sw ≤ 0 = 整张),目标框,不透明度,混合(0 正常 / 1 灰度) | image: asset path (fallback path, -1 none), crop (sw ≤ 0 = whole), destination, alpha, blend (0 normal / 1 luminosity)
|
||
static void image(const char *a, const char *fb, float sx, float sy, float sw, float sh, float dx, float dy, float dw, float dh, float alpha, int blend) {
|
||
OPV(OP_IMAGE, str(a), fb ? str(fb) : -1, sx, sy, sw, sh, dx, dy, dw, dh, alpha, (float)blend);
|
||
}
|
||
static dm_ta_glyph shown_glyph(uint64_t button, uint64_t now, int set) {
|
||
dm_ta_glyph g = dm_ta_current_set(&g_native, button, now, set);
|
||
if (g.status == DM_TA_UNKNOWN && g_native.captured_ns && now > g_native.captured_ns && now - g_native.captured_ns > DM_TG_MAX_AGE_NS) g = dm_ta_current_set(&g_native, button, g_native.captured_ns, set);
|
||
return g;
|
||
}
|
||
// 技能图标的裁切框;0 = 没有 | skill icon crop rect; 0 = none
|
||
static int skill_frame(dm_ta_glyph g, int held, dm_ta_frame *f, char *path, char *sil, size_t n) {
|
||
if (g.status != DM_TA_GLYPH) return 0;
|
||
if (!dm_ta_frame_at(g.atlas, held ? g.pressed_frame : g.normal_frame, f)) return 0;
|
||
snprintf(path, n, "TouchArt/%s.png", dm_ta_atlases[g.atlas].asset); snprintf(sil, n, "hud_v4_ui/sil_%s.png", dm_ta_atlases[g.atlas].asset);
|
||
return 1;
|
||
}
|
||
#define DM_SKILL_IDLE_ALPHA .6f
|
||
static void draw_shell(float x, float y, float rr, int held) {
|
||
float lw = MAX(1.5f, rr * 0.075f), fr = held ? 1 : DM_SKILL_IDLE_ALPHA, d = rr * 2;
|
||
fill_ellipse(x - rr, y - rr, d, d, .086f, .067f, .047f, held ? .92f : .80f * fr);
|
||
stroke_ellipse(x - rr + lw / 2, y - rr + lw / 2, d - lw, d - lw, lw, .60f, .47f, .28f, held ? 1 : .9f * fr);
|
||
stroke_ellipse(x - rr + lw * 1.3f, y - rr + lw * 1.3f, d - lw * 2.6f, d - lw * 2.6f, lw * .5f, .12f, .09f, .05f, .9f * fr);
|
||
}
|
||
// 小地图任务终点(同 front_ios.m mapGoalSync;宿主 dm_world.c 找终点、dm_cursor.c 给地图几何):七个墓的真墓口 = 塔拉夏符号,其余 = 原版名牌 + 灰十字;
|
||
// 在地图可见范围外 = 只写名字,沿 玩家点 → 终点 的方向贴边(全屏地图让开右下技能区)。世界格 (x, y) 在 玩家点 + ((Δx−Δy)×1.6, (Δx+Δy)×0.8) × 每格像素。
|
||
// 画面 = 整个视图(Android 不留边)。面板开着不画;手柄模式照画(同 iOS)。素材 assets/mapgoal/(art_from_ipa.py 从 iOS 包取)
|
||
// Minimap quest goals (same as front_ios.m mapGoalSync; the host's dm_world.c finds the goals, dm_cursor.c gives the map geometry): the real tomb of the seven = the Tal Rasha symbol, others = the original nameplate + grey cross;
|
||
// outside the visible map range = name only, clamped to the edge along player point → goal (the fullscreen map avoids the bottom-right skill area). World cell (x, y) is at player point + ((Δx−Δy)×1.6, (Δx+Δy)×0.8) × pixels per cell.
|
||
// The picture = the whole view (no letterbox on Android). Not drawn while a panel is open; drawn in pad mode too (as on iOS). Art in assets/mapgoal/ (taken from the iOS bundle by art_from_ipa.py)
|
||
static void draw_goals(void) {
|
||
static int old = -1; if (old < 0) old = dm_custom_get("item_notes") != 0; // 旧译名开关重启生效 | the old-names switch takes effect on restart
|
||
dm_map_goal_view v; float cell = 0; int mode = dm_ui_map_geom(&cell), n = dm_map_goals(&v), rw = 0, rh = 0; dm_screen_real(&rw, &rh);
|
||
float mm[4]; int mini = dm_ui_minimap_rect(mm);
|
||
int show = mode && n > 0 && !g_nav && !g_fe && rw > 0 && cell > 0 && (mode == 2 || mini);
|
||
static int lm = -1, ln = -1, lc; int m2 = show ? mode : 0;
|
||
if ((m2 != lm || n != ln) && lc < 40) { lm = m2; ln = n; lc++; LOG("小地图终点:%s %d 个(地图 %d,每格 %.2f 像素 = %.2f dp)", show ? "画" : "不画", n, mode, cell, cell * W / (rw > 0 ? rw : 1)); }
|
||
if (!show) return;
|
||
if (n > 12) n = 12;
|
||
float c = cell * W / rw, lh = H * .0236f, sh = H * .085f * (mode == 1 ? .6f : 1), cw = lh * 1.4f, ch = cw * 18 / 34;
|
||
float ox, oy, ax0, ay0, ax1, ay1; // 玩家点,可见范围 | player point, visible area
|
||
if (mode == 2) { ox = v.sx * W; oy = v.sy * H; ax0 = W * .04f; ay0 = H * .06f; ax1 = ax0 + W * .92f; ay1 = ay0 + H * .72f; }
|
||
else { ax0 = mm[0] * W; ay0 = mm[1] * H; ax1 = mm[2] * W; ay1 = mm[3] * H; ox = (ax0 + ax1) / 2; oy = (ay0 + ay1) / 2;
|
||
float iw = (ax1 - ax0) * .06f, ih = (ay1 - ay0) * .08f; ax0 += iw; ax1 -= iw; ay0 += ih; ay1 -= ih; }
|
||
for (int i = 0; i < n; i++) {
|
||
int dx = v.x[i] - v.px, dy = v.y[i] - v.py; float px = ox + (dx - dy) * 1.6f * c, py = oy + (dx + dy) * .8f * c;
|
||
int skill = mode == 2 && px > W * .72f && py > H * .45f; // 全屏地图右下是技能区 | the bottom right of the fullscreen map is the skill area
|
||
int inside = px >= ax0 && px < ax1 && py >= ay0 && py < ay1 && !skill, art = v.art[i], sym = art >= 64;
|
||
char lab[48] = "", fb[48] = "", mark[48] = "";
|
||
if (inside && sym) snprintf(mark, sizeof mark, "mapgoal/sym_%d.png", art - 64);
|
||
else { int id = sym ? 0 : art; snprintf(fb, sizeof fb, "mapgoal/label_%d.png", id);
|
||
if (!dm_lang_zh()) snprintf(lab, sizeof lab, "mapgoal/label_%d_en.png", id); // 简中 / 繁体用中文名牌,其余 enUS;旧译名只跟简中 | zh uses the Chinese label, others enUS; old names only for zhCN
|
||
else if (old && dm_lang_index() == 8) snprintf(lab, sizeof lab, "mapgoal/label_%d_old.png", id);
|
||
else snprintf(lab, sizeof lab, "%s", fb);
|
||
if (inside) snprintf(mark, sizeof mark, "mapgoal/cross.png"); }
|
||
if (!inside) { // 画面外:收到可见范围边上,只写名字 | off-screen: clamp to the edge of the visible range, name only
|
||
float tx = px > ox ? (ax1 - ox) / (px - ox) : px < ox ? (ax0 - ox) / (px - ox) : 1e9f, ty = py > oy ? (ay1 - oy) / (py - oy) : py < oy ? (ay0 - oy) / (py - oy) : 1e9f, t = MIN(tx, ty);
|
||
px = ox + (px - ox) * t; py = oy + (py - oy) * t;
|
||
if (mode == 2 && px > W * .72f && py > H * .45f) py = H * .45f; }
|
||
if (lab[0]) OPV(OP_LABEL, str(lab), px, mark[0] ? py - ch / 2 - 2 - lh / 2 : py, lh, strcmp(lab, fb) ? str(fb) : -1);
|
||
if (mark[0]) { if (sym) OPV(OP_LABEL, str(mark), px, py, sh); else image(mark, NULL, 0, 0, 0, 0, px - cw / 2, py - ch / 2, cw, ch, 1, 0); }
|
||
}
|
||
}
|
||
static void draw_overlay(int part) {
|
||
g_ol->n = 0; g_ol->nstr = 0;
|
||
int cover = atomic_load(&g_cover);
|
||
if (cover == 1) { if (!part) OPV(OP_COVER, W, H); return; }
|
||
if (part == 2) { draw_goals(); return; }
|
||
if (g_fe || g_pad || dm_padmode_busy()) return;
|
||
const dm_tc_state *s = &C; const dm_tc_layout *l = &s->layout;
|
||
float k = l->joy_radius / 60; if (k <= 0) return;
|
||
if (part) {
|
||
if ((g_hud.valid && g_hud.dead) || s->navigation_mode) return;
|
||
int moving = s->joy_slot >= 0;
|
||
float ox = moving ? s->joy_origin_x : l->joy_x, oy = moving ? s->joy_origin_y : l->joy_y, radius = l->joy_radius;
|
||
stroke_ellipse(ox - radius, oy - radius, radius * 2, radius * 2, k, .66f, .53f, .32f, moving ? .32f : .12f);
|
||
float dx = s->lx / 32767.0f * radius, dy = -s->ly / 32767.0f * radius;
|
||
image("TouchArt/dm_touch_joy.png", NULL, 0, 0, 0, 0, ox + dx - 23 * k, oy + dy - 23 * k, 46 * k, 46 * k, moving ? .8f : .18f, 0);
|
||
if (moving && (s->lx || s->ly)) { float ang = atan2f(dy, dx); OPV(OP_ARC, ox, oy, radius + 3 * k, ang - (float)M_PI / 6, ang + (float)M_PI / 6, 2 * k, .66f, .53f, .32f, .7f); }
|
||
return;
|
||
}
|
||
int nav = g_nav != 0; uint64_t host_now = now_ns();
|
||
const char *labels[DM_TC_COUNT] = {"主技能", "技能一", "技能二", "技能三", "技能四", "回城", "药剂", "药剂", "药剂", "药剂", "功能", "地图"};
|
||
if (nav) { labels[0] = "确认/交换"; labels[1] = "返回"; labels[2] = "操作"; labels[3] = "绑定"; labels[4] = "下一页"; }
|
||
for (int i = 0; i < DM_TC_COUNT; i++) {
|
||
if (!(s->enabled_targets & (1u << i))) continue;
|
||
if (!nav && i > DM_TC_PORTAL && i <= DM_TC_MENU) continue;
|
||
const dm_tc_target *t = &l->target[i]; float bx = t->x - t->r, by = t->y - t->r, bw = t->r * 2;
|
||
int held = t->button != 0 && (s->buttons & t->button) == t->button;
|
||
if (i == DM_TC_PORTAL) for (int f = 0; f < DM_TC_MAX_TOUCH; f++) held |= s->finger[f].active && s->finger[f].target == DM_TC_PORTAL;
|
||
float opacity = held ? .6f : .28f;
|
||
if (!nav && i == DM_TC_MAP && s->map_cancel_active) { OPV(OP_FILL_RECT, bx, by, bw, bw, .55f, .05f, .04f, .36f); labels[i] = "取消"; }
|
||
int skill_key = !nav && (i <= DM_TC_SKILL4 || i == DM_TC_PORTAL);
|
||
if (skill_key) draw_shell(t->x, t->y, t->r, held);
|
||
else image("TouchArt/dm_native_circle.png", NULL, 0, 0, 0, 0, bx, by, bw, bw, opacity, 0);
|
||
int have_icon = 0, show_caption = 1, ss_kind = 0, ss_charges = 0; dm_ta_frame fr; char ip[96], sp[96]; float iw = 0, ih = 0;
|
||
if (!nav && i <= DM_TC_SKILL4) {
|
||
dm_ta_glyph g = shown_glyph(t->button, host_now, s->skill_set);
|
||
if (g.status != DM_TA_EMPTY && g.status != DM_TA_UNKNOWN) ss_kind = dm_swapskill_slot(g.slot, &ss_charges);
|
||
have_icon = skill_frame(g, held, &fr, ip, sp, sizeof ip);
|
||
show_caption = g.status != DM_TA_EMPTY && !have_icon;
|
||
} else if (!nav && i == DM_TC_PORTAL) have_icon = skill_frame(dm_ta_skill(359), held, &fr, ip, sp, sizeof ip);
|
||
else if (!nav && (i == DM_TC_MENU || i == DM_TC_MAP)) {
|
||
have_icon = 1; fr = (dm_ta_frame){held ? 36 : 0, 0, 36, 36};
|
||
snprintf(ip, sizeof ip, "TouchArt/%s", i == DM_TC_MAP ? "dm_native_map.png" : "dm_native_menu.png"); sp[0] = 0;
|
||
}
|
||
if (!nav && i == DM_TC_MAP && s->map_cancel_active) { have_icon = 0; show_caption = 1; }
|
||
if (have_icon) { iw = (float)fr.width; ih = (float)fr.height; }
|
||
if (skill_key && !have_icon && (!show_caption || i == DM_TC_MAIN)) { // 空格:十字 | empty slot: a cross
|
||
float a_ = t->r * .30f, w_ = MAX(1.5f, t->r * .085f), al = held ? 1 : .9f;
|
||
OPV(OP_LINE, t->x - a_, t->y, t->x + a_, t->y, w_, .60f, .47f, .28f, al);
|
||
OPV(OP_LINE, t->x, t->y - a_, t->x, t->y + a_, w_, .60f, .47f, .28f, al);
|
||
continue;
|
||
}
|
||
if (skill_key) {
|
||
int bare = have_icon, spent = (ss_kind & 2) && ss_charges <= 0;
|
||
if (have_icon) { float size = bw * (bare ? .64f : .56f), fit = size / MAX(iw, ih);
|
||
float rx_ = t->x - iw * fit / 2, ry_ = t->y - (bare ? 0 : t->r * .12f) - ih * fit / 2;
|
||
if (spent) { fill_ellipse(bx + t->r * .14f, by + t->r * .14f, bw - t->r * .28f, bw - t->r * .28f, .30f, .30f, .30f, 1);
|
||
image(sp, ip, fr.x, fr.y, fr.width, fr.height, rx_, ry_, iw * fit, ih * fit, .55f, 1);
|
||
fill_ellipse(bx, by, bw, bw, 0, 0, 0, .35f); }
|
||
else image(sp[0] ? sp : ip, sp[0] ? ip : NULL, fr.x, fr.y, fr.width, fr.height, rx_, ry_, iw * fit, ih * fit, held ? 1 : .92f, 0); }
|
||
if (ss_kind & 1) { float br = t->r * .30f, bx2 = t->x + t->r * .74f, by2 = t->y - t->r * .74f, in = MAX(1, br * .08f);
|
||
fill_ellipse(bx2 - br, by2 - br, br * 2, br * 2, .11f, .094f, .078f, .95f);
|
||
stroke_ellipse(bx2 - br + in, by2 - br + in, br * 2 - in * 2, br * 2 - in * 2, MAX(1, br * .14f), .63f, .50f, .27f, 1);
|
||
float ts = br * 1.15f; caption("Ⅱ", bx2 - br, by2 - ts * .62f, br * 2, ts * 1.4f, ts, 1); }
|
||
if (ss_kind & 2) { char cs[16]; snprintf(cs, sizeof cs, "%d", ss_charges < 0 ? 0 : ss_charges); float u = H / 1320.0f;
|
||
if (u > 0) OPV(OP_V4TEXT, str(cs), (t->x + t->r * .66f - W / 2) / u + 1434, (t->y + t->r * .42f) / u, 1); }
|
||
if (bare) continue;
|
||
char ln[48]; if (i == DM_TC_MAIN) snprintf(ln, sizeof ln, "hud_v4_ui/lbl_main.png"); else snprintf(ln, sizeof ln, "hud_v4_ui/lbl_f%d.png", i - DM_TC_SKILL1 + 1 + (s->skill_set ? 4 : 0));
|
||
OPV(OP_LABEL, str(ln), t->x, t->y + t->r * .50f, t->r * (i == DM_TC_MAIN ? .30f : .36f));
|
||
continue;
|
||
}
|
||
if (have_icon) { float size = bw * (i == DM_TC_MAIN ? .55f : .62f), fit = size / MAX(iw, ih);
|
||
image(ip, NULL, fr.x, fr.y, fr.width, fr.height, t->x - iw * fit / 2, t->y - ih * fit / 2, iw * fit, ih * fit, held ? 1 : .82f, 0); show_caption = 0; }
|
||
float ts = (i == DM_TC_MAIN ? 13 : 10) * k;
|
||
if (show_caption) caption(labels[i], bx, t->y - ts * .6f, bw, ts * 1.6f, ts, held ? 1 : .84f);
|
||
if (i >= DM_TC_BELT1 && i <= DM_TC_BELT4) { char d[4]; snprintf(d, sizeof d, "%d", i - DM_TC_BELT1 + 1); caption(d, t->x - 10 * k, t->y + 8 * k, 20 * k, 12 * k, 8 * k, .65f); }
|
||
}
|
||
if (!nav && l->swap.r > 0) {
|
||
int sheld = 0; for (int f = 0; f < DM_TC_MAX_TOUCH; f++) sheld |= s->finger[f].active && hypotf(s->finger[f].x - l->swap.x, s->finger[f].y - l->swap.y) <= l->swap.r;
|
||
draw_shell(l->swap.x, l->swap.y, l->swap.r, sheld);
|
||
float ts = 14 * k; caption(s->skill_set ? "Ⅱ" : "Ⅰ", l->swap.x - l->swap.r, l->swap.y - ts * .8f, l->swap.r * 2, ts * 1.6f, ts, 1);
|
||
}
|
||
if (g_hud.valid && g_hud.dead) return;
|
||
if (s->navigation_mode) return;
|
||
// 底部 UI v4:可见性在这里判,几何与字形 Java 按 hud_v4_ui/ui.json 画 | bottom UI v4: visibility decided here, geometry and glyphs drawn by Java from hud_v4_ui/ui.json
|
||
const dm_hud_info *h = &g_hud;
|
||
if (dm_hud_bar_visible(h, nav && !g_dialog_only, g_hud_blocked_v)) {
|
||
char life[64], mana[64], lv[48];
|
||
snprintf(life, sizeof life, dm_ui("dmHudLife"), h->hp, h->hp_max); snprintf(mana, sizeof mana, dm_ui("dmHudMana"), h->mp, h->mp_max);
|
||
snprintf(lv, sizeof lv, "Lv %d · %d%%", h->level, h->exp_permille / 10);
|
||
OPV(OP_V4, str(life), str(mana), str(lv), (s->buttons & DM_BTN_PLUS) ? 1 : 0, h->points > 0 ? 1 : 0, h->quest_unread ? 1 : 0, (float)h->exp_permille,
|
||
(float)h->belt[0], (float)h->belt[1], (float)h->belt[2], (float)h->belt[3], (float)h->players, s->diff_open ? 1 : 0);
|
||
}
|
||
}
|
||
|
||
// ---- JNI(GameActivity 界面线程) | JNI (GameActivity UI thread) ----
|
||
#define JNI(name) JNICALL Java_org_d2rmobile_app_GameActivity_##name
|
||
JNIEXPORT void JNI(nativeLayout)(JNIEnv *env, jclass cls, jfloat w, jfloat h, jfloat safe_l, jfloat safe_r) {
|
||
(void)env; (void)cls;
|
||
static int inited; static float sl = -1, sr = -1;
|
||
if (!inited) {
|
||
inited = 1; for (int i = 0; i < 16; i++) g_slot[i] = -1;
|
||
dm_tc_set_tall_scale(1); dm_tc_init(&C, w, h); C.mouse_click_mode = 1; W = w; H = h;
|
||
g_nav = -1; navigation_mode(atomic_load(&g_touch_navigation));
|
||
}
|
||
int safe_changed = safe_l != sl || safe_r != sr;
|
||
if (safe_changed) { sl = safe_l; sr = safe_r; dm_tc_set_safe_insets(safe_l, safe_r); }
|
||
dm_tc_set_edge_bottom(0);
|
||
if (h > 0) { dm_ui_safe_left((int)lroundf(safe_l / h * 2160)); dm_ui_safe_right((int)lroundf(safe_r / h * 2160)); }
|
||
if (safe_changed || C.layout.width != w || C.layout.height != h) { W = w; H = h; cancel_controls(); dm_tc_resize(&C, w, h); }
|
||
LOG("触屏:视图 %.0fx%.0f dp,安全边距 左 %.0f 右 %.0f", w, h, safe_l, safe_r);
|
||
g_dirty = 1;
|
||
}
|
||
// action:0 按下(pid 为新手指)/ 1 移动 / 2 抬起(pid)/ 3 取消(全部);pids / xs / ys 为这一刻全部手指(dp)
|
||
// action: 0 down (pid is the new finger) / 1 move / 2 up (pid) / 3 cancel (all); pids / xs / ys are all fingers at this moment (dp)
|
||
JNIEXPORT void JNI(nativeTouchEvent)(JNIEnv *env, jclass cls, jint action, jint pid, jintArray pids, jfloatArray xs, jfloatArray ys, jint n) {
|
||
(void)cls;
|
||
if (W <= 0) return;
|
||
jint id[NREC]; jfloat x[NREC], y[NREC]; if (n > NREC) n = NREC;
|
||
if (n > 0) { (*env)->GetIntArrayRegion(env, pids, 0, n, id); (*env)->GetFloatArrayRegion(env, xs, 0, n, x); (*env)->GetFloatArrayRegion(env, ys, 0, n, y); }
|
||
apply_pending();
|
||
int ts[NREC], m = 0;
|
||
for (int i = 0; i < n; i++) { int t = pid_rec(id[i]); if (t >= 0) { R[t].x = x[i]; R[t].y = y[i]; } }
|
||
if (action == 0) {
|
||
if (pid_rec(pid) >= 0) return;
|
||
int t = -1; for (int i = 0; i < NREC; i++) if (!R[i].used) { t = i; break; }
|
||
if (t < 0) { gc_recs(); return; }
|
||
R[t].used = 1; R[t].done = 0; R[t].pid = pid; R[t].x = R[t].y = 0;
|
||
for (int i = 0; i < n; i++) if (id[i] == pid) { R[t].x = x[i]; R[t].y = y[i]; }
|
||
ts[m++] = t; touches_began(ts, m);
|
||
} else if (action == 1) {
|
||
for (int i = 0; i < NREC; i++) if (R[i].used && !R[i].done) ts[m++] = i;
|
||
if (m) touches_moved(ts, m);
|
||
} else if (action == 2) {
|
||
int t = pid_rec(pid); if (t < 0) return;
|
||
R[t].done = 1; ts[m++] = t; finish_touches(ts, m, 0);
|
||
} else {
|
||
for (int i = 0; i < NREC; i++) if (R[i].used && !R[i].done) { R[i].done = 1; ts[m++] = i; }
|
||
if (m) finish_touches(ts, m, 1);
|
||
}
|
||
gc_recs();
|
||
}
|
||
// 每帧(Choreographer):返回位 0 / 1 / 2 = 主体层 / 摇杆层 / 终点层要重画,位 4–5 = 掉落震动档(1 重 / 2 中 / 3 轻),位 8–9 = 重开遮罩(1 黑屏 / 2 透明)
|
||
// Per frame (Choreographer): bits 0 / 1 / 2 = body / joystick / goals layer needs a redraw, bits 4–5 = drop haptic level (1 heavy / 2 medium / 3 light), bits 8–9 = restart cover (1 black / 2 transparent)
|
||
JNIEXPORT jint JNI(nativeTick)(JNIEnv *env, jclass cls) {
|
||
(void)env; (void)cls;
|
||
if (W <= 0) return 0;
|
||
tick(now_s());
|
||
static int lc; int cover = atomic_load(&g_cover); if (cover != lc) { lc = cover; g_dirty = 1; if (cover) cancel_controls(); }
|
||
// 位 0 / 1 = 主体层 / 摇杆层要重画:重算一遍指令表,和上次画出来的不同才算 | bits 0 / 1 = body / joystick layer needs a redraw: rebuild the draw list, and only count it if it differs from what was last drawn
|
||
int r = (g_haptic & 3) << 4 | (cover & 3) << 8;
|
||
if (g_dirty) for (int part = 0; part < 2; part++) { g_ol = &g_probe; draw_overlay(part); if (!same_list(&g_probe, &g_drawn[part])) r |= 1 << part; }
|
||
{ g_ol = &g_probe; draw_overlay(2); if (!same_list(&g_probe, &g_drawn[2])) r |= 4; } // 终点层跟着玩家走,每帧都比 | the goals layer follows the player, compared every frame
|
||
g_dirty = 0; g_haptic = 0;
|
||
return r;
|
||
}
|
||
// 返回 [float[] 指令, String[] 字符串表] | returns [float[] ops, String[] strings]
|
||
JNIEXPORT jobjectArray JNI(nativeDraw)(JNIEnv *env, jclass cls, jint part) {
|
||
(void)cls;
|
||
if (part < 0 || part > 2) part = 0;
|
||
g_ol = &g_drawn[part]; draw_overlay(part);
|
||
jfloatArray f = (*env)->NewFloatArray(env, g_ol->n); if (g_ol->n) (*env)->SetFloatArrayRegion(env, f, 0, g_ol->n, g_ol->ops);
|
||
jclass sc = (*env)->FindClass(env, "java/lang/String");
|
||
jobjectArray sa = (*env)->NewObjectArray(env, g_ol->nstr, sc, NULL);
|
||
for (int i = 0; i < g_ol->nstr; i++) { jstring js = (*env)->NewStringUTF(env, g_ol->str[i]); (*env)->SetObjectArrayElement(env, sa, i, js); (*env)->DeleteLocalRef(env, js); }
|
||
jobjectArray out = (*env)->NewObjectArray(env, 2, (*env)->FindClass(env, "java/lang/Object"), NULL);
|
||
(*env)->SetObjectArrayElement(env, out, 0, f); (*env)->SetObjectArrayElement(env, out, 1, sa);
|
||
return out;
|
||
}
|