mirror of
https://github.com/jhaizhou-ops/d2r-mobile
synced 2026-11-26 13:57:52 +08:00
The Custom page's "Vibrate on valuable drops" row did nothing on Android: dm_drophaptic.c picks a tier when a valuable item lands, but only the iOS front end took it. - touch_android.c: the per-frame input hook takes the pending tier before the touch lock and hands it to front_android_drop_haptic. - text_input_jni.c: a new job kind on the existing Java worker thread calls DmActivity.dropHaptic (optional lookup, like shareDiagnostics). It only queues, so the game thread never waits on Java. - DmActivity.dropHaptic: tier 1/2/3 -> predefined HEAVY_CLICK / CLICK / TICK, as media vibration, so the system's touch-feedback switch does not turn it off. - Manifest: VIBRATE (a normal permission, no prompt). - dm_drophaptic.c: header comment names the Android consumer (comment only). Redmi K50 Ultra, DM_TEST_GIVE drops of Ber / Ist / Pul: each logged its tier and dumpsys vibrator_manager shows HEAVY_CLICK / CLICK / TICK played for com.xiaoboluo.d2r with usage MEDIA. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
492 lines
33 KiB
C
492 lines
33 KiB
C
#include "touch_android.h"
|
||
#include "front_android.h"
|
||
#include "../ios/Sources/dm_touch_controls.h"
|
||
#include "../host/dm_input.h"
|
||
#include "../host/dm_cursor.h"
|
||
#include "../host/dm_actions.h"
|
||
#include "../host/dm_hud.h"
|
||
#include "../host/dm_custom.h"
|
||
#include "../host/dm_world.h"
|
||
#include "../host/dm_uiscreen.h"
|
||
#include "../ios/Sources/dm_touch_native_art.h"
|
||
#include <pthread.h>
|
||
#include <math.h>
|
||
#include <stdlib.h>
|
||
#include <string.h>
|
||
/* 待震的最高一档,取走即清(dm_drophaptic.c;宿主头文件里没有声明,iOS 也是就地声明)。
|
||
The highest pending vibration tier, cleared when taken (dm_drophaptic.c; no host header declares it, iOS declares it in place too). */
|
||
int dm_drop_haptic_take(void);
|
||
|
||
uint64_t now_ns(void);
|
||
void dm_uiscreen_set_panel(int panel);
|
||
void dm_tp_request(void);
|
||
/* 绑定观测桥未接入时不捏造技能绑定;基础键位仍走共用状态机。 | Do not fabricate skill bindings if the observation bridge is absent; basic keys still use the shared state machine. */
|
||
void dm_touch_game_set_scene(int game, uint64_t scene, uint64_t world) __attribute__((weak));
|
||
|
||
typedef struct { int phase, slot; float x, y; double time; } touch_event;
|
||
static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
|
||
static dm_tc_state tc;
|
||
static dm_tc_scene scene;
|
||
/* 面板栈读数(宿主 dm_cursor.c dm_hud_stack_msg,iOS / Mac 同一份):开着的非常驻面板数,只开着 NPC 对话菜单时 −1
|
||
Panel stack reading (host dm_cursor.c dm_hud_stack_msg, shared with iOS / Mac): open non-resident panels, −1 when only the NPC dialog menu is open */
|
||
int dm_hud_stack_msg(const char *act, const char *arg);
|
||
static int hud_blocked;
|
||
static touch_event queue[256];
|
||
static unsigned head, tail;
|
||
static int ready, focused = 1, cancel, resizing, ui_drag;
|
||
/* 窗口 dp(整屏,dm_android_touch_resize)与游戏视图矩形 dp(相对窗口左上角,dm_android_touch_view);width/height 是视图尺寸,也就是 dm_tc 的坐标空间。
|
||
没收到视图矩形时视图 = 整屏。 | Window dp (whole screen, dm_android_touch_resize) and the game view rectangle in dp (from the window's top-left corner,
|
||
dm_android_touch_view); width/height is the view size, i.e. dm_tc's coordinate space. The view is the whole window until a view rectangle arrives. */
|
||
static float width = 800, height = 375, win_w = 800, win_h = 375, vr_x, vr_y, vr_w = 800, vr_h = 375, safe_left, safe_right, safe_bottom;
|
||
static int tablet_layout, swap_above;
|
||
typedef struct { int kind; float x,y; double time; uint64_t key; } direct_gesture;
|
||
static direct_gesture direct[DM_TC_MAX_TOUCH];
|
||
static uint32_t selected_point;
|
||
static double stat_next, skill_add_at;
|
||
static unsigned map_world_seq;
|
||
static int map_world_pending;
|
||
static uint64_t epoch = 1, world = 1, pulse_epoch, pulse_sample, resume_sample;
|
||
static double pulse_hold_start;
|
||
static unsigned seen_world, seen_mouse, seen_tab, seen_use, seen_ident, seen_long, seen_item, seen_stack;
|
||
/* 前端页面(主菜单 / 选角 / 建角 / 读取画面,即不在局内),同 iOS front_ios.m frontendMode:不画控件,第一根手指直接当原生点击交给游戏界面
|
||
(dm_ui_touch → 鼠标消息,dm_cursor.c),纵向拖过 10 点改成滚动。只在装了触屏覆盖层(DM_ROMFS_OVERLAY)时这样:覆盖层把选角页换成键鼠版
|
||
(「开始」「创建新角色」靠点);没有覆盖层时前端是原版手柄页,仍走导航键。
|
||
Front-end pages (main menu / character select / creation / loading, i.e. not in a run), as iOS front_ios.m frontendMode: no controls are drawn, and
|
||
the first finger goes straight to the game UI as a native click (dm_ui_touch → mouse messages, dm_cursor.c); a vertical drag past 10 points scrolls.
|
||
Only with the touch overlay (DM_ROMFS_OVERLAY): it turns character select into the keyboard-and-mouse page ("Play", "Create New" are tapped);
|
||
without it the front end is the original controller page and keeps the navigation keys. */
|
||
static int frontend, fe_slot = -1, fe_drag;
|
||
static float fe_x0, fe_y0;
|
||
/* 面板态的五个虚拟手柄圆钮:缺省不给(同 iOS front_ios.m navigationMode:点按 / 双击 / 拖放 / 点页签 / 面板外点按已全部替代);DM_TOUCH_NAV_PAD=1 调试时叫回来
|
||
The five virtual pad buttons in panel state: off by default (as iOS front_ios.m navigationMode: tap / double tap / drag / tab tap / tap outside
|
||
the panel replace them all); DM_TOUCH_NAV_PAD=1 brings them back for debugging */
|
||
static int nav_pad(void) { static int v = -1; if (v < 0) { const char *e = getenv("DM_TOUCH_NAV_PAD"); v = e && e[0] == '1'; } return v; }
|
||
static int touch_overlay(void) { static int v = -1; if (v < 0) { const char *o = getenv("DM_ROMFS_OVERLAY"); v = o && *o; } return v; }
|
||
static void fe_end_locked(void) {
|
||
if (fe_slot >= 0) { if (fe_drag) dm_ui_drag_end(); else dm_ui_touch(3, 0, 0); }
|
||
fe_slot = -1; fe_drag = 0;
|
||
}
|
||
static void fe_event_locked(const touch_event *e) {
|
||
if (e->phase == 0 && fe_slot < 0) { fe_slot = e->slot; fe_x0 = e->x; fe_y0 = e->y; fe_drag = 0; }
|
||
if (e->slot != fe_slot) return;
|
||
float nx = e->x / width, ny = e->y / height, dy = fabsf(e->y - fe_y0);
|
||
if (e->phase == 1 && !fe_drag && dy > 10 && dy > fabsf(e->x - fe_x0) && dm_ui_fe_drag_ok()) {
|
||
fe_drag = 1; dm_ui_touch(3, 0, 0); dm_ui_drag_begin(1, fe_x0 / width, fe_y0 / height, 0);
|
||
}
|
||
if (fe_drag) { if (e->phase == 1) dm_ui_drag_move(nx, ny); else fe_end_locked(); return; }
|
||
if (e->phase == 3) { fe_end_locked(); return; }
|
||
dm_ui_touch(e->phase, nx, ny);
|
||
if (e->phase == 2) fe_slot = -1;
|
||
}
|
||
|
||
static void init_locked(void) {
|
||
if (ready) return;
|
||
dm_tc_set_tall_scale(tablet_layout);
|
||
dm_tc_init(&tc, width, height);
|
||
tc.mouse_click_mode = 1;
|
||
dm_tc_set_navigation_mode(&tc, 1);
|
||
dm_tc_enable_targets(&tc, dm_tc_nav_mask(nav_pad())); /* 开局读取期间也是面板态,同样不出圆钮 | loading at game start is panel state too, no buttons either */
|
||
ready = 1;
|
||
}
|
||
static void cancel_locked(void) {
|
||
dm_tc_cancel_all(&tc);
|
||
if (ui_drag) dm_ui_drag_end();
|
||
ui_drag = 0;
|
||
fe_end_locked();
|
||
pulse_epoch = pulse_sample = resume_sample = 0;
|
||
pulse_hold_start = 0;
|
||
memset(direct,0,sizeof direct); selected_point=0; stat_next=skill_add_at=0; map_world_pending=0;
|
||
dm_cursor_clear();
|
||
}
|
||
void dm_android_touch_resize(float w, float h, float l, float r, float b) {
|
||
if (!isfinite(w) || !isfinite(h) || w <= 0 || h <= 0) return;
|
||
pthread_mutex_lock(&lock);
|
||
/* w/h 仍是整屏窗口 dp(安全区也按整屏给);dm_tc 的坐标空间是游戏视图矩形,由 dm_android_touch_view 给。
|
||
w/h is still the whole window in dp (the safe area is given for the whole screen too); dm_tc's coordinate space is the game view
|
||
rectangle, which dm_android_touch_view provides. */
|
||
int whole = vr_w <= 0 || (vr_x == 0 && vr_y == 0 && vr_w == win_w && vr_h == win_h); /* 视图没给过 / 上一个是整屏 | no view yet / the last one was the whole window */
|
||
win_w = w; win_h = h; safe_left = fmaxf(0,l); safe_right = fmaxf(0,r); safe_bottom = fmaxf(0,b);
|
||
if (whole) { vr_x = vr_y = 0; vr_w = w; vr_h = h; }
|
||
/* 窗口变了、视图矩形还没跟上来:先夹进新窗口,UI 线程随后用 dm_android_touch_view 覆盖(头文件约定先 resize 再 view)。
|
||
The window changed and the view rectangle has not caught up yet: clamp it into the new window first; the UI thread overwrites it through
|
||
dm_android_touch_view right after (the header asks for resize before view). */
|
||
else { vr_x = fminf(fmaxf(vr_x,0),w); vr_y = fminf(fmaxf(vr_y,0),h); vr_w = fminf(vr_w,w-vr_x); vr_h = fminf(vr_h,h-vr_y);
|
||
if (vr_w <= 0 || vr_h <= 0) { vr_x = vr_y = 0; vr_w = w; vr_h = h; } }
|
||
width = vr_w; height = vr_h;
|
||
resizing = cancel = 1; head = tail = 0;
|
||
pthread_mutex_unlock(&lock);
|
||
}
|
||
void dm_android_touch_view(float x, float y, float w, float h) {
|
||
if (!isfinite(x) || !isfinite(y) || !isfinite(w) || !isfinite(h) || w <= 0 || h <= 0) return;
|
||
pthread_mutex_lock(&lock);
|
||
/* 游戏视图矩形(窗口 dp):界面、自绘 HUD / 控件与界面触点都在它里面。dm_tc 的坐标空间改成它,触点在入队前减原点(见 dm_android_touch_event)。
|
||
Game view rectangle in window dp: the UI, the custom-drawn HUD / controls and UI touch points all live inside it. dm_tc's coordinate space
|
||
becomes this rectangle, and touches have its origin subtracted before they are queued (see dm_android_touch_event). */
|
||
if (x != vr_x || y != vr_y || w != vr_w || h != vr_h) {
|
||
vr_x = x; vr_y = y; vr_w = w; vr_h = h; width = w; height = h;
|
||
resizing = cancel = 1; head = tail = 0;
|
||
}
|
||
pthread_mutex_unlock(&lock);
|
||
}
|
||
void dm_android_touch_tablet(int tablet) {
|
||
pthread_mutex_lock(&lock);
|
||
tablet_layout = !!tablet; resizing = cancel = 1;
|
||
pthread_mutex_unlock(&lock);
|
||
}
|
||
void dm_android_touch_focus(int active) {
|
||
pthread_mutex_lock(&lock);
|
||
focused = !!active; cancel = 1; head = tail = 0;
|
||
pthread_mutex_unlock(&lock);
|
||
}
|
||
void dm_android_touch_event(int phase, int slot, float x, float y) {
|
||
if (phase < 0 || phase > 3 || slot < 0 || slot >= DM_TC_MAX_TOUCH || !isfinite(x) || !isfinite(y)) return;
|
||
pthread_mutex_lock(&lock);
|
||
if (focused) {
|
||
/* 溢出只取消,绝不遗留按住的摇杆/按键。 | Overflow cancels instead of leaving a stick/key held. */
|
||
if (tail - head == 256) { cancel = 1; head = tail = 0; }
|
||
/* Java 给的是窗口 dp:减视图原点换成 dm_tc 的视图坐标;真全屏下 y 可为负(视图上方那条只有 3D 的区域,点怪 / 点地照常,界面与控件点不到)。
|
||
Java gives window dp: subtract the view origin to get dm_tc's view coordinates; in true fullscreen y may be negative -- the 3D-only
|
||
strip above the view, where tapping monsters / ground still works but the UI and controls cannot be hit. */
|
||
else { queue[tail++ % 256] = (touch_event){phase, slot, x - vr_x, y - vr_y, now_ns() / 1e9}; }
|
||
}
|
||
pthread_mutex_unlock(&lock);
|
||
}
|
||
void dm_android_touch_uimsg(const char *cat, const char *act, const char *arg) {
|
||
if (!cat || !act) return;
|
||
pthread_mutex_lock(&lock);
|
||
init_locked();
|
||
dm_tc_scene before = scene;
|
||
dm_tc_set_panel_state(dm_ui_panel_state());
|
||
if (!strcmp(cat, "PanelManager")) hud_blocked = dm_hud_stack_msg(act, arg ? arg : "");
|
||
int nav = dm_tc_navigation(&scene, cat, act, arg ? arg : "");
|
||
/* 同 iOS front_ios.m:局内只要面板栈里还开着非常驻面板就是面板态(不靠名单);再分出死亡弹窗(2)与只开着对话菜单(3)
|
||
As iOS front_ios.m: in game any open non-resident panel means panel state (not a name list); then split out the death dialog (2) and dialog menu only (3) */
|
||
if (scene.game && hud_blocked > 0) nav = 1;
|
||
nav = dm_tc_panel_mode(nav, &scene, hud_blocked);
|
||
if (before.game != scene.game || before.panels != scene.panels) {
|
||
++epoch; if (before.game != scene.game) ++world;
|
||
cancel_locked(); head = tail = 0;
|
||
}
|
||
int fe = !scene.game && touch_overlay();
|
||
if (fe != frontend) { cancel_locked(); head = tail = 0; frontend = fe; }
|
||
dm_tc_set_navigation_mode(&tc, nav);
|
||
dm_ui_map_hold(nav != 0); /* 同 iOS:面板开着全屏地图先让成小地图,关掉回到玩家要的那档 | as iOS: while a panel is open the full-screen map steps aside to the minimap, and after it closes it returns to what the player wants */
|
||
dm_tc_set_joy_block(&tc, !!(dm_ui_panel_state() & DM_PS_TEXT));
|
||
/* 游戏态不要右上地图键(同 iOS front_ios.m navigationMode:点右上角小地图本身就开全屏地图,见 direct_begin)
|
||
No top-right map key in game state (as iOS front_ios.m navigationMode: tapping the top-right minimap itself opens the full map, see direct_begin) */
|
||
/* 3 = 只开着 NPC 对话菜单:底栏十字可点(原版 + 键此时 = 关对话并开功能页),同 iOS | 3 = only the NPC dialog menu is open: the bar's cross is tappable, as iOS */
|
||
dm_tc_enable_targets(&tc, nav ? (dm_tc_nav_mask(nav_pad() && nav != 2 && !dm_tc_scene_dead()) | (nav == 3 ? 1u << DM_TC_MENU : 0u))
|
||
: (((1u << DM_TC_COUNT) - 1) & ~(1u << DM_TC_MAP)));
|
||
dm_uiscreen_set_panel(nav && !dm_tc_scene_dead() && !dm_tc_scene_dialog_only(&scene));
|
||
if (dm_touch_game_set_scene) dm_touch_game_set_scene(!nav, epoch, world);
|
||
pthread_mutex_unlock(&lock);
|
||
}
|
||
static void sync_host(void) {
|
||
dm_tc_set_panel_state(dm_ui_panel_state());
|
||
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 info; dm_hud_get(&info);
|
||
dm_tc_set_holding(&tc, info.valid && info.holding && !dm_ui_targeting());
|
||
tc.belt_rows = dm_belt_rows(&tc.belt_open);
|
||
}
|
||
/* 真全屏:世界那一侧按整窗算(front_ios.m world_rect / world_norm、touch_ohos.c 同款)。world_rect 给的是「整窗在视图坐标里的矩形」:
|
||
视图原点在窗口里是 (vr_x, vr_y),所以整窗左上角在视图坐标里是 (−vr_x, −vr_y)。局外(界面矩形就是整个画面)时世界与视图重合。
|
||
True fullscreen: the world side is computed on the whole window (as front_ios.m world_rect / world_norm and touch_ohos.c). world_rect returns
|
||
"the whole window as a rectangle in view coordinates": the view origin sits at (vr_x, vr_y) in the window, so the window's top-left corner is
|
||
(−vr_x, −vr_y) in view coordinates. Out of a run (the UI rectangle is the whole picture) the world and the view coincide. */
|
||
static void world_rect(float r[4]) {
|
||
int x, y, w, h, rw = 0, rh = 0;
|
||
r[0] = 0; r[1] = 0; r[2] = width; r[3] = height;
|
||
if (!front_android_full()) return;
|
||
dm_ui_rect(&x, &y, &w, &h);
|
||
if (dm_screen_real(&rw, &rh) && h > 0 && h < rh) { r[0] = -vr_x; r[1] = -vr_y; r[2] = win_w; r[3] = win_h; }
|
||
}
|
||
static void world_norm(float x, float y, float *nx, float *ny) { float r[4]; world_rect(r); *nx = (x - r[0]) / r[2]; *ny = (y - r[1]) / r[3]; }
|
||
static void requests(void) {
|
||
if (seen_tab != tc.tab_tap_seq) { seen_tab = tc.tab_tap_seq; dm_ui_tab_go(); }
|
||
if (seen_use != tc.use_seq) { seen_use = tc.use_seq; dm_ui_use_item(); }
|
||
if (seen_ident != tc.ident_seq) { seen_ident = tc.ident_seq; dm_ui_identify_hovered(); }
|
||
if (seen_long != tc.long_press_seq) { seen_long = tc.long_press_seq; dm_ui_long_press(); }
|
||
if (seen_item != tc.item_tap_seq) { seen_item = tc.item_tap_seq; dm_ui_item_tap(); }
|
||
if (seen_stack != tc.stack_take_seq) { seen_stack = tc.stack_take_seq; dm_stash_take(1); }
|
||
if (seen_world != tc.world_tap_seq) {
|
||
seen_world = tc.world_tap_seq;
|
||
/* nx,ny 仍是视图归一化(宿主 dm_ui_* 按界面矩形归一化),wx,wy 是出图画面归一化——真全屏下画面铺满整窗,靠它点世界。
|
||
nx,ny stay view-normalised (the host dm_ui_* paths normalise by the UI rectangle); wx,wy are picture-normalised -- in true fullscreen
|
||
the picture fills the whole window, and that is what tapping the world uses. */
|
||
float nx = tc.world_tap_x / width, ny = tc.world_tap_y / height, wx, wy;
|
||
world_norm(tc.world_tap_x, tc.world_tap_y, &wx, &wy);
|
||
dm_ui_world_tap(nx, ny, wx, wy);
|
||
}
|
||
if (seen_mouse != tc.mouse_click_seq) {
|
||
seen_mouse = tc.mouse_click_seq;
|
||
float nx = tc.mouse_click_x / width, ny = tc.mouse_click_y / height;
|
||
dm_ui_touch(0,nx,ny); dm_ui_touch(2,nx,ny);
|
||
}
|
||
if (tc.diff_request) { dm_hud_request_players(tc.diff_request); tc.diff_request = 0; }
|
||
if (tc.belt_request) {
|
||
int br = tc.belt_request; tc.belt_request = 0;
|
||
if (br == 1 || br == 2) dm_belt_expand(br == 1);
|
||
else dm_belt_use(br & 15, (br >> 4) & 15);
|
||
}
|
||
}
|
||
static void release_pointer(dm_tc_finger *f) {
|
||
float lift = DM_TC_POINTER_LIFT_PT * dm_tc_scale_for_size(width,height);
|
||
int kind = dm_ui_drop_at_now(f->x/width, (f->y-lift)/height, f->y/height);
|
||
float x,y;
|
||
if (f->shop_drag) {
|
||
if (kind == 11) dm_ui_stack_cube_at(f->aim_origin_x/width,f->aim_origin_y/height);
|
||
else if (kind == 5 && dm_ui_drop_bag()) {
|
||
if (tc.pointer_stack) dm_ui_stack_take_at(f->aim_origin_x/width,f->aim_origin_y/height);
|
||
else dm_ui_shop_buy_at(f->aim_origin_x/width,f->aim_origin_y/height);
|
||
}
|
||
tc.pointer_x = f->aim_origin_x; tc.pointer_y = f->aim_origin_y;
|
||
} else if ((kind == 5 && dm_ui_drop_point(&x,&y)) || (kind == 0 && dm_ui_origin_point(&x,&y))) dm_tc_pointer_release_at(&tc,x*width,y*height);
|
||
else { if (kind == 7) { dm_shop_sell_cursor(); kind = 0; } dm_tc_pointer_release(&tc,kind); }
|
||
}
|
||
/* 空技能位和小地图先截获,不发攻击、世界点击或摇杆输入。
|
||
Capture empty skill slots and minimap taps before emitting attack, world-tap or joystick input. */
|
||
static int direct_begin(const touch_event *e) {
|
||
if (tc.navigation_mode) return 0;
|
||
int target=dm_tc_hit(&tc.layout,e->x,e->y), kind=0; uint64_t key=0;
|
||
if (target>=DM_TC_MAIN && target<=DM_TC_SKILL4) {
|
||
dm_tg_snapshot snapshot; dm_touch_game_snapshot(&snapshot);
|
||
dm_ta_glyph g=dm_ta_current_set(&snapshot,tc.layout.target[target].button,now_ns(),tc.skill_set);
|
||
if (g.status==DM_TA_EMPTY) { kind=1; key=tc.layout.target[target].button|(tc.skill_set?DM_BTN_ZL:0); }
|
||
}
|
||
if (!kind && target==DM_TC_MAP) kind=2;
|
||
float r[4];
|
||
if (!kind && target<0 && dm_ui_minimap_rect(r)) {
|
||
float h=(r[3]-r[1])*height, band=h/4;
|
||
if (band<30) band=fminf(30,h*.4f);
|
||
if (e->x>=r[0]*width && e->x<=r[2]*width && e->y>=r[1]*height && e->y<=r[1]*height+band) kind=2;
|
||
}
|
||
if (!kind) return 0;
|
||
direct[e->slot]=(direct_gesture){kind,e->x,e->y,e->time,key}; return 1;
|
||
}
|
||
static int direct_event(const touch_event *e) {
|
||
direct_gesture *g=&direct[e->slot]; if (!g->kind) return 0;
|
||
if (hypotf(e->x-g->x,e->y-g->y)>14) g->kind=-1;
|
||
if (e->phase==2) {
|
||
if (!tc.navigation_mode && g->kind>0 && e->time-g->time<.6) {
|
||
if (g->kind==1) dm_ui_bind_begin(g->key);
|
||
else if (dm_ui_map_is_full()) dm_ui_map_full(0);
|
||
else if (g->kind==2) { float wx, wy; world_norm(e->x,e->y,&wx,&wy); map_world_seq=dm_world_tap(wx,wy); map_world_pending=1; }
|
||
}
|
||
memset(g,0,sizeof *g);
|
||
} else if (e->phase==3) memset(g,0,sizeof *g);
|
||
return 1;
|
||
}
|
||
static void point_tick(double now) {
|
||
if (tc.navigation_mode && !dm_ui_bind_active() && tc.pointer_slot>=0) {
|
||
dm_tc_finger *f=&tc.finger[tc.pointer_slot]; float nx=0,ny=0;
|
||
int hit=dm_ui_bind_skill_hit(&nx,&ny); uint32_t id=dm_ui_hit_id();
|
||
if (f->active && !f->pointer_dragged && !f->ui_drag && now-f->start_time_s>=.5 && hypotf(f->x-f->aim_origin_x,f->y-f->aim_origin_y)<=10*dm_tc_scale_for_size(width,height)) {
|
||
if (hit==2 && id>=1 && id<=4) {
|
||
if (!f->pointer_long) { f->pointer_long=1; stat_next=now; selected_point=id; tc.pointer_valid=1; tc.pointer_x=nx*width; tc.pointer_y=ny*height; }
|
||
if (now>=stat_next) { stat_next=now+.15; dm_stat_add((int)id-1,1); }
|
||
} else if (hit==1 && !f->pointer_long) dm_tc_pointer_press(&tc,nx*width,ny*height,DM_BTN_Y);
|
||
}
|
||
}
|
||
if (skill_add_at>0 && now>=skill_add_at) {
|
||
dm_points_info points; dm_points_get(&points);
|
||
if (points.tree_open && points.sel_skill>=0 && !dm_cursor_pending()) {
|
||
skill_add_at=0;
|
||
if (points.sel_block==0 || points.sel_block==5) dm_skill_add_selected();
|
||
} else if (now>skill_add_at+1 || !points.tree_open) skill_add_at=0;
|
||
}
|
||
}
|
||
void dm_android_touch_step(uint64_t guest_now, uint64_t *buttons, int32_t *lx, int32_t *ly, int32_t *rx, int32_t *ry) {
|
||
(void)guest_now;
|
||
/* 高价值掉落震动(#289,同 iOS front_ios.m tickTouchControls):每帧取走待震的最高一档交给 Java。放在拿触屏锁之前:
|
||
front_android_drop_haptic 只入队,不碰这把锁,手柄模式下也照样震。
|
||
Valuable-drop vibration (#289, as iOS front_ios.m tickTouchControls): every frame take the highest pending tier and hand it to
|
||
Java. It sits before the touch lock: front_android_drop_haptic only queues and never takes that lock, and it also vibrates in
|
||
controller mode. */
|
||
{ int tier = dm_drop_haptic_take(); if (tier) front_android_drop_haptic(tier); }
|
||
pthread_mutex_lock(&lock);
|
||
init_locked();
|
||
int next_swap = dm_custom_get("touch_swap_above");
|
||
if (next_swap != swap_above) { swap_above = next_swap; resizing = cancel = 1; }
|
||
if (cancel) { cancel_locked(); cancel = 0; }
|
||
if (resizing) {
|
||
/* 安全区只算落在游戏视图里的那部分(同 touch_ohos.c layout_view):视图上方那条 3D、视图外的边距都不挪控件。
|
||
Only the part of the safe area that falls inside the game view counts (as touch_ohos.c layout_view): the 3D strip above the view
|
||
and the margins outside it do not move the controls. */
|
||
float sl = fmaxf(0, safe_left - vr_x), sr = fmaxf(0, safe_right - (win_w - vr_x - vr_w)), sb = fmaxf(0, safe_bottom - (win_h - vr_y - vr_h));
|
||
/* 真全屏(视图矩形比整窗矮,界面是贴底的一条):游戏把右上角小地图与地名画到画面右边缘之外(实测尾部被裁),
|
||
给它们一份缺省右安全区让整块内移——宽屏上这块本来就摆得下,值保持 0,行为不变。
|
||
True fullscreen (the view rectangle is shorter than the window, the UI is a bottom strip): the game draws the top-right minimap
|
||
and the area name past the picture's right edge (measured: the tail is clipped), so give them a default right safe area to move
|
||
the block inward -- on wide screens the block already fits, the value stays 0 and nothing changes. */
|
||
dm_tc_set_tall_scale(tablet_layout); dm_tc_set_swap_above(swap_above);
|
||
dm_tc_set_safe_insets(sl,sr); dm_tc_set_edge_bottom(sb); dm_tc_set_safe_bottom(sb);
|
||
/* 安全区按视图高换算成 2160 高的布局单位(界面归一化也按视图)。 | Safe area becomes 2160-high layout units via the view height (UI normalisation is by the view too). */
|
||
dm_ui_safe_left((int)lroundf(sl * 2160 / height));
|
||
/* 真全屏(界面是贴底的一条)时游戏把右上角小地图与地名画到画面右缘之外(实测尾部被裁),给游戏那侧一份缺省右安全区让它
|
||
整块内移;触控布局按真实安全区走,不受影响。16:9 及以上时界面矩形就是整窗,游戏本来就摆得下,值保持 0。
|
||
True fullscreen (the UI is a bottom strip): the game draws the top-right minimap and area name past the picture's right edge
|
||
(measured: the tail is clipped), so give the game's side a default right safe area to move that block inward; the touch
|
||
layout keeps the real insets and is untouched. On 16:9 and wider the UI rectangle is the whole window and the value stays 0. */
|
||
int gui_sr = (int)lroundf(sr * 2160 / height);
|
||
if ((vr_y > 0.5f || vr_x > 0.5f) && gui_sr < (int)lroundf(0.07f * 2160)) gui_sr = (int)lroundf(0.07f * 2160);
|
||
dm_ui_safe_right(gui_sr);
|
||
dm_tc_resize(&tc,width,height); resizing = 0;
|
||
}
|
||
if (!focused) { pthread_mutex_unlock(&lock); return; }
|
||
sync_host();
|
||
if (map_world_pending) {
|
||
int result=dm_world_tap_result(map_world_seq);
|
||
if (result>=0) { map_world_pending=0; if (!result && !tc.navigation_mode) dm_ui_map_full(1); }
|
||
}
|
||
/* 本次取手柄前排队的触点整批在这里套用:按下与抬起落在同一批(点得比游戏两次取手柄的间隔还短、或游戏卡住没取输入)时,状态机算出的键在批末已经松开,
|
||
游戏一次也看不到——iOS 由前端异步调 dm_input_set,按下沿进 hle_hid.c 的 g_press_latch 锁存,这里同样:批内任何时刻按着过的键这次一并给出,下一次照实际值。
|
||
The touches queued before this controller read are applied here as one batch: when press and release land in the same batch (a tap shorter than the
|
||
interval between two reads, or the game stalling its input reads), the state machine's key is already up at the end of the batch and the game never
|
||
sees it. On iOS the front end calls dm_input_set asynchronously and the press edge is latched in hle_hid.c g_press_latch; likewise here, keys held at
|
||
any point in the batch are delivered with this read, and the next read reports the actual state. */
|
||
/* 批内锁存按手指归属;滑出取消只撤销该手指,保留其他手指的快按。
|
||
Attribute batch latches to each finger; slide cancellation revokes only that finger's quick tap. */
|
||
uint64_t latched[DM_TC_MAX_TOUCH] = {0};
|
||
while (head != tail) {
|
||
touch_event e = queue[head++ % 256];
|
||
if (frontend) { fe_event_locked(&e); continue; }
|
||
if (direct_event(&e) || (e.phase==0 && direct_begin(&e))) continue;
|
||
dm_tc_finger *f = &tc.finger[e.slot];
|
||
uint64_t before_buttons = tc.buttons;
|
||
int before_target = f->target;
|
||
int event_cancelled = 0;
|
||
if (e.phase == 0) latched[e.slot] = 0;
|
||
if (e.phase == 0) {
|
||
if (dm_tc_belt_outside(&tc,e.x,e.y)) { dm_belt_expand(0); continue; }
|
||
{ int dm_cam_mode(void), dm_cam_style(void); tc.cam_on = dm_cam_mode(); tc.cam_orbit = dm_cam_style() == 1; } /* 镜头实验:右半屏拖动看四周要知道档 | camera experiment: looking around on the right half needs the mode */
|
||
dm_tc_begin_at(&tc,e.slot,e.x,e.y,e.time);
|
||
if (!tc.navigation_mode && f->target == DM_TC_PORTAL) { dm_tc_cancel_finger(&tc,e.slot); dm_tp_request(); }
|
||
if (tc.navigation_mode && tc.pointer_slot == e.slot) dm_tc_pointer_item(&tc,dm_ui_item_at_now(e.x/width,e.y/height));
|
||
} else if (e.phase == 1 || e.phase == 2) {
|
||
dm_tc_move_at(&tc,e.slot,e.x,e.y,e.time);
|
||
if (tc.cam_pitch != 0 || tc.cam_yaw != 0) { void dm_cam_tilt(float); void dm_cam_turn(float); if (tc.cam_pitch != 0) dm_cam_tilt(tc.cam_pitch); if (tc.cam_yaw != 0) dm_cam_turn(tc.cam_yaw); tc.cam_pitch = tc.cam_yaw = 0; } /* 镜头实验:右半屏拖动看四周(dm_touch_controls.c) | camera experiment: drag on the right half to look around */
|
||
event_cancelled = f->aim_cancelled;
|
||
if (tc.navigation_mode && tc.pointer_slot == e.slot && f->ui_drag) {
|
||
if (!ui_drag) {
|
||
ui_drag = 1; dm_ui_drag_lift(DM_TC_POINTER_LIFT_PT*dm_tc_scale_for_size(width,height)/height);
|
||
dm_ui_drag_begin(f->ui_drag,f->aim_origin_x/width,f->aim_origin_y/height,44/height);
|
||
}
|
||
dm_ui_drag_move(e.x/width,e.y/height);
|
||
}
|
||
if (e.phase == 2) {
|
||
tc.tap_button=0; tc.tap_move=0;
|
||
if (tc.navigation_mode) {
|
||
float nx,ny;
|
||
int hit=dm_ui_bind_skill_hit(&nx,&ny);
|
||
if (!hit) selected_point=0;
|
||
else {
|
||
tc.tap_x=nx*width; tc.tap_y=ny*height;
|
||
if (hit==1 && dm_ui_bind_active()==2) tc.tap_button=DM_BTN_Y;
|
||
else if (!dm_ui_bind_active()) tc.tap_move=1;
|
||
}
|
||
}
|
||
if (tc.navigation_mode && tc.pointer_slot == e.slot && (f->pointer_dragged || f->shop_drag)) release_pointer(f);
|
||
if (ui_drag && tc.pointer_slot == e.slot) { dm_ui_drag_end(); ui_drag = 0; }
|
||
unsigned moved=tc.tap_move_seq;
|
||
dm_tc_end_at(&tc,e.slot,e.time);
|
||
if (moved!=tc.tap_move_seq) {
|
||
uint32_t id=dm_ui_hit_id();
|
||
if (id && id==selected_point) {
|
||
if (id<=4) dm_stat_add((int)id-1,1);
|
||
else skill_add_at=e.time+.3;
|
||
} else selected_point=id;
|
||
}
|
||
}
|
||
} else {
|
||
/* 系统取消物品拖动时回原位,不当作丢弃/购买。 | System cancellation returns dragged items; it never buys or discards. */
|
||
if (tc.pointer_slot == e.slot && f->pointer_dragged && !f->shop_drag) {
|
||
dm_tc_pointer_release(&tc,0); dm_tc_end_at(&tc,e.slot,e.time);
|
||
} else dm_tc_cancel_finger(&tc,e.slot);
|
||
if (ui_drag) { dm_ui_drag_end(); ui_drag = 0; }
|
||
}
|
||
int target = e.phase == 2 ? before_target : f->target;
|
||
if (e.phase == 3 || event_cancelled || f->aim_cancelled) latched[e.slot] = 0;
|
||
else {
|
||
latched[e.slot] |= tc.buttons & ~before_buttons;
|
||
if (target >= 0 && target < DM_TC_COUNT)
|
||
latched[e.slot] |= tc.buttons & (tc.layout.target[target].button | (tc.skill_set ? DM_BTN_ZL : 0));
|
||
}
|
||
requests();
|
||
}
|
||
double now = now_ns()/1e9;
|
||
/* 当期iOS:游戏内按住技能连续施放;换绑从技能树长按进入。
|
||
Current iOS: holding a gameplay skill keeps casting; rebinding starts by holding an icon in the skill tree. */
|
||
point_tick(now);
|
||
dm_tc_tick(&tc,now); requests();
|
||
uint64_t sample = dm_input_samples();
|
||
if (tc.pulse_button && pulse_epoch != tc.pulse_epoch) {
|
||
pulse_epoch = tc.pulse_epoch; pulse_sample = sample; pulse_hold_start = 0;
|
||
}
|
||
if (tc.pulse_button && !dm_cursor_pending()) {
|
||
if (!pulse_hold_start) pulse_hold_start = now;
|
||
if (sample - pulse_sample >= 4 && now - pulse_hold_start >= tc.pulse_hold_s) {
|
||
dm_tc_pulse_end(&tc,pulse_epoch); resume_sample = sample + 2;
|
||
}
|
||
}
|
||
if (!tc.pulse_button && dm_tc_pulse_pending(&tc) && resume_sample && sample >= resume_sample) { dm_tc_pulse_resume(&tc); resume_sample = 0; }
|
||
if (tc.pointer_valid) dm_cursor_set_screen(tc.pointer_x,tc.pointer_y,width,height); else dm_cursor_clear();
|
||
int active = 0; for (int i=0;i<DM_TC_MAX_TOUCH;++i) active |= tc.finger[i].active;
|
||
dm_ui_hand_idle(!active && !tc.pulse_button && !dm_tc_pulse_pending(&tc) && !dm_cursor_pending() && !dm_ui_touch_active());
|
||
*buttons |= tc.buttons;
|
||
for (int i=0;i<DM_TC_MAX_TOUCH;++i) *buttons |= latched[i];
|
||
if (!*lx && !*ly) { *lx = tc.lx; *ly = tc.ly; }
|
||
if (!*rx && !*ry) { *rx = tc.rx; *ry = tc.ry; }
|
||
pthread_mutex_unlock(&lock);
|
||
}
|
||
void dm_android_touch_layout(float out[DM_ANDROID_TOUCH_DRAW_FLOATS]) {
|
||
pthread_mutex_lock(&lock); init_locked();
|
||
memset(out,0,sizeof(float)*DM_ANDROID_TOUCH_DRAW_FLOATS);
|
||
out[0]=tc.layout.width; out[1]=tc.layout.height; out[2]=tc.navigation_mode; out[3]=tc.skill_set;
|
||
for (int i=0;i<23;++i) {
|
||
float *p = out+4+i*5;
|
||
dm_tc_target t = i<DM_TC_COUNT ? tc.layout.target[i] : i==13 ? tc.layout.swap : i>=15 ? tc.layout.pick[i-15] : tc.layout.diff;
|
||
if (i==12) {
|
||
p[0]=tc.joy_slot>=0?tc.joy_origin_x:tc.layout.joy_x; p[1]=tc.joy_slot>=0?tc.joy_origin_y:tc.layout.joy_y;
|
||
p[2]=tc.layout.joy_radius; p[3]=!tc.navigation_mode; p[4]=tc.joy_slot>=0;
|
||
} else {
|
||
p[0]=t.x; p[1]=t.y; p[2]=t.r;
|
||
p[3]=i<DM_TC_COUNT?!!(tc.enabled_targets&(1u<<i)):!tc.navigation_mode && (i<15 || tc.diff_open);
|
||
/* 快照包含松手后仍在发出的脉冲;查询只读,probe和onDraw连续读取不能消费高亮。
|
||
Include pulses that remain active after release; reads are non-consuming so probe/onDraw see the same highlight. */
|
||
p[4]=t.button && (tc.buttons&t.button)==t.button;
|
||
for (int j=0;j<DM_TC_MAX_TOUCH;++j) {
|
||
const dm_tc_finger *f=&tc.finger[j];
|
||
if (!f->active || f->aim_cancelled) continue;
|
||
if ((i<DM_TC_COUNT && f->target==i) || (i==13 && f->target==DM_TC_SWAP)) p[4]=1;
|
||
/* 难度格与腰带消费共用负target;还要命中当前圆,不能把所有选项一起点亮。
|
||
Difficulty and consumed belt touches share a negative target; hit-test this circle rather than lighting every choice. */
|
||
if (i>=14 && f->target==DM_TC_DIFF && hypotf(f->x-t.x,f->y-t.y)<=t.r) p[4]=1;
|
||
}
|
||
}
|
||
if (frontend) p[3]=0; /* 前端页面不画控件(见 frontend) | No controls drawn on front-end pages (see frontend) */
|
||
}
|
||
dm_tg_snapshot native; dm_touch_game_snapshot(&native);
|
||
for (int i=0;i<6;++i) {
|
||
float *p=out+DM_ANDROID_TOUCH_GLYPHS+i*8;
|
||
dm_ta_glyph g=i==5 ? dm_ta_skill(359) : dm_ta_current_set(&native,tc.layout.target[i].button,now_ns(),tc.skill_set);
|
||
dm_ta_frame frame;
|
||
p[0]=g.status; p[1]=g.atlas;
|
||
int held=out[4+i*5+4]!=0;
|
||
if (g.status==DM_TA_GLYPH && dm_ta_frame_at(g.atlas,held?g.pressed_frame:g.normal_frame,&frame)) {
|
||
p[2]=frame.x; p[3]=frame.y; p[4]=frame.width; p[5]=frame.height;
|
||
if (g.slot>=0) { int charges=0; p[6]=dm_swapskill_slot(g.slot,&charges); p[7]=charges; }
|
||
}
|
||
}
|
||
dm_hud_info h; dm_hud_get(&h);
|
||
float *hud=out+DM_ANDROID_TOUCH_HUD;
|
||
hud[0]=!frontend && dm_hud_bar_visible(&h,tc.navigation_mode && !dm_tc_scene_dialog_only(&scene),hud_blocked>0);
|
||
hud[1]=h.level; hud[2]=h.exp_permille;
|
||
for (int i=0;i<4;++i) hud[3+i]=h.belt[i];
|
||
hud[7]=h.players; hud[8]=h.hp; hud[9]=h.hp_max; hud[10]=h.mp; hud[11]=h.mp_max;
|
||
hud[12]=h.points; hud[13]=h.quest_unread; hud[14]=h.dead; hud[15]=tc.map_cancel_active;
|
||
hud[16]=tc.lx; hud[17]=tc.ly; /* 摇杆推量(−32767..32767),画摇杆头用,同 iOS DmTouchOverlay | stick deflection (−32767..32767) for drawing the thumb, as iOS DmTouchOverlay */
|
||
pthread_mutex_unlock(&lock);
|
||
}
|