Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v3.8.5] Make dispatchImmediately variable be a const value which will help treeshaking. #17853

Open
wants to merge 1 commit into
base: v3.8.5
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions cocos/input/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/

import { EDITOR_NOT_IN_PREVIEW, NATIVE } from 'internal:constants';
import { AccelerometerInputSource, GamepadInputDevice, HMDInputDevice, HandheldInputDevice, HandleInputDevice, KeyboardInputSource, MouseInputSource, TouchInputSource } from 'pal/input';

Check warning on line 28 in cocos/input/input.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

This line has a length of 186. Maximum allowed is 150
import { touchManager } from '../../pal/input/touch-manager';
import { EventTarget, error, sys } from '../core';
import { Event, EventAcceleration, EventGamepad, EventHandle, EventHandheld, EventHMD, EventKeyboard, EventMouse, EventTouch, Touch } from './types';
Expand Down Expand Up @@ -99,6 +99,18 @@
[InputEventType.HANDHELD_POSE_INPUT]: (event: EventHandheld) => void,
}

/**
* @en Dispatch input event immediately.
* The input events are collocted to be dispatched in each main loop by default.
* If you need to recieve the input event immediately, please set this to true.
* NOTE: if set this to true, the input events are dispatched between each tick, the input event can't be optimized by engine.
*
* @zh 立即派发输入事件。
* 输入事件默认会被收集到每一帧主循环里派发,如果你需要立即接收到输入事件,请把该属性设为 true。
* 注意:如果设置为 true,则输入事件可能会在帧间触发,这样的输入事件是没办法被引擎优化的。
*/
const dispatchImmediately = !NATIVE;

/**
* @en
* This Input class manages all events of input. include: touch, mouse, accelerometer, gamepad, handle, hmd and keyboard.
Expand All @@ -121,18 +133,6 @@
*/
public static EventType = InputEventType;

/**
* @en Dispatch input event immediately.
* The input events are collocted to be dispatched in each main loop by default.
* If you need to recieve the input event immediately, please set this to true.
* NOTE: if set this to true, the input events are dispatched between each tick, the input event can't be optimized by engine.
*
* @zh 立即派发输入事件。
* 输入事件默认会被收集到每一帧主循环里派发,如果你需要立即接收到输入事件,请把该属性设为 true。
* 注意:如果设置为 true,则输入事件可能会在帧间触发,这样的输入事件是没办法被引擎优化的。
*/
private _dispatchImmediately$ = !NATIVE;

private _eventTarget$: EventTarget = new EventTarget();
private _touchInput$ = new TouchInputSource();
private _mouseInput$ = new MouseInputSource();
Expand Down Expand Up @@ -469,15 +469,15 @@
}

private _dispatchOrPushEvent$ (event: Event, eventList: Event[]): void {
if (this._dispatchImmediately$) {
if (dispatchImmediately) {
this._emitEvent$(event);
} else {
eventList.push(event);
}
}

private _dispatchOrPushEventTouch$ (eventTouch: EventTouch, touchEventList: EventTouch[]): void {
if (this._dispatchImmediately$) {
if (dispatchImmediately) {
const touches = eventTouch.getTouches();
const touchesLength = touches.length;
for (let i = 0; i < touchesLength; ++i) {
Expand All @@ -494,6 +494,7 @@
* @engineInternal
*/
public _frameDispatchEvents (): void {
if (dispatchImmediately) return;
const eventHMDList = this._eventHMDList$;
// TODO: culling event queue
for (let i = 0, length = eventHMDList.length; i < length; ++i) {
Expand Down Expand Up @@ -562,7 +563,7 @@

/**
* @en
* The singleton of the Input class, this singleton manages all events of input. include: touch, mouse, accelerometer, gamepad, handle, hmd and keyboard.

Check warning on line 566 in cocos/input/input.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

This line has a length of 153. Maximum allowed is 150
*
* @zh
* 输入类单例,该单例管理所有的输入事件,包括:触摸、鼠标、加速计、游戏手柄、6DOF手柄、头戴显示器 和 键盘。
Expand Down
Loading