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

feat: Add InputManager #497

Merged
merged 79 commits into from
Sep 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
0abcd9c
feat:Support atlas #197
Jul 19, 2021
54710a3
Merge branch 'oasis-engine:dev/0.5' into dev/0.5
cptbtptpbcptdtptp Jul 19, 2021
464262b
feat:Support atlas #197
Jul 19, 2021
a6b83d5
Merge branch 'dev/0.5' of https://github.com/cptbtptpbcptdtptp/engine…
Jul 19, 2021
b0e396e
Merge branch 'oasis-engine:dev/0.5' into dev/0.5
cptbtptpbcptdtptp Jul 20, 2021
907b2f1
feat:Support atlas
Jul 21, 2021
8b9c8d6
feat:Support atlas
Jul 21, 2021
390d11a
feat:Support atlas
Jul 22, 2021
733d119
feat:Support atlas
Jul 22, 2021
c068a35
feat:Support atlas
Jul 22, 2021
6c50d6c
feat:Support atlas
Jul 30, 2021
d4e6820
feat:Support atlas
Jul 30, 2021
de5b981
feat:Support atlas
Aug 2, 2021
a074507
feat:Support atlas
cptbtptpbcptdtptp Aug 2, 2021
1d0a217
feat:Support atlas
cptbtptpbcptdtptp Aug 2, 2021
c9c6d7b
feat:Support atlas
cptbtptpbcptdtptp Aug 2, 2021
2978b44
feat:Support atlas
cptbtptpbcptdtptp Aug 2, 2021
485e550
feat:Support atlas
cptbtptpbcptdtptp Aug 2, 2021
e79604e
feat:Support atlas
cptbtptpbcptdtptp Aug 2, 2021
f1bfb2c
refactor: opt code
GuoLei1990 Aug 2, 2021
58c321a
Merge pull request #2 from GuoLei1990/Atlas
cptbtptpbcptdtptp Aug 2, 2021
97b0ea0
Merge branch 'oasis-engine:dev/0.5' into dev/0.5
cptbtptpbcptdtptp Aug 6, 2021
155933c
fix:opt atlas code
cptbtptpbcptdtptp Aug 6, 2021
c10c61c
fix:opt atlas code
cptbtptpbcptdtptp Aug 6, 2021
5e65294
fix:opt atlas code
cptbtptpbcptdtptp Aug 6, 2021
83ff1b5
fix:atlas support rotation
cptbtptpbcptdtptp Aug 10, 2021
1568df3
Merge branch 'dev/0.5' of https://github.com/oasis-engine/engine into…
cptbtptpbcptdtptp Aug 10, 2021
a91d5e9
fix:atlas support rotation
cptbtptpbcptdtptp Aug 10, 2021
0f60cac
fix:atlas support rotation
cptbtptpbcptdtptp Aug 10, 2021
066caf9
fix:Fixed sprite’s rect display error when packaged into an atlas and…
cptbtptpbcptdtptp Aug 15, 2021
4c4222d
fix:Fixed sprite’s rect display error when packaged into an atlas and…
cptbtptpbcptdtptp Aug 16, 2021
b65ffbf
Merge branch 'dev/0.5' of https://github.com/oasis-engine/engine into…
cptbtptpbcptdtptp Aug 16, 2021
1630680
fix:Fixed sprite’s rect display error when packaged into an atlas and…
cptbtptpbcptdtptp Aug 17, 2021
fb91468
fix:Fixed sprite’s rect display error when packaged into an atlas and…
cptbtptpbcptdtptp Aug 18, 2021
ae70757
fix:Fixed sprite’s rect display error when packaged into an atlas and…
cptbtptpbcptdtptp Aug 18, 2021
b59a9fe
fix:Fixed sprite’s rect display error when packaged into an atlas and…
cptbtptpbcptdtptp Aug 18, 2021
65478e7
fix:Fixed sprite’s rect display error when packaged into an atlas and…
cptbtptpbcptdtptp Aug 18, 2021
9e1631a
fix:Fixed sprite’s rect display error when packaged into an atlas and…
cptbtptpbcptdtptp Aug 18, 2021
5035233
fix:Fixed sprite’s rect display error when packaged into an atlas and…
cptbtptpbcptdtptp Aug 18, 2021
5d8c28f
Merge branch 'oasis-engine:dev/0.5' into dev/0.5
cptbtptpbcptdtptp Aug 18, 2021
c20f994
feat:Add the function of relative path loading
cptbtptpbcptdtptp Aug 18, 2021
2fa4145
Merge branch 'dev/0.5' of https://github.com/oasis-engine/engine into…
cptbtptpbcptdtptp Aug 26, 2021
6482632
feat:SpriteAtlas Adaptation Editor Workflow
cptbtptpbcptdtptp Aug 30, 2021
509125e
feat:SpriteAtlas Adaptation Editor Workflow
cptbtptpbcptdtptp Aug 30, 2021
18d25ca
feat:SpriteAtlas Adaptation Editor Workflow
cptbtptpbcptdtptp Aug 31, 2021
746815c
Merge branch 'dev/0.5' of https://github.com/oasis-engine/engine into…
cptbtptpbcptdtptp Aug 31, 2021
7f029a3
feat:SpriteAtlas Adaptation Editor Workflow
cptbtptpbcptdtptp Aug 31, 2021
aa86809
Merge branch 'dev/0.5' of https://github.com/oasis-engine/engine into…
cptbtptpbcptdtptp Sep 1, 2021
fe07a29
fix:code err
cptbtptpbcptdtptp Sep 1, 2021
945db6b
Merge branch 'dev/0.5' of https://github.com/oasis-engine/engine into…
cptbtptpbcptdtptp Sep 2, 2021
8324161
Merge branch 'dev/0.6' of https://github.com/oasis-engine/engine into…
cptbtptpbcptdtptp Sep 7, 2021
5a8ad2a
feat: Add InputManager.
cptbtptpbcptdtptp Sep 8, 2021
9ada64a
Merge branch 'oasis-engine:dev/0.6' into dev/0.6
cptbtptpbcptdtptp Sep 8, 2021
8965e6f
feat: Opt code.
cptbtptpbcptdtptp Sep 8, 2021
3594299
Merge branch 'dev/0.6' of https://github.com/cptbtptpbcptdtptp/engine…
cptbtptpbcptdtptp Sep 8, 2021
9139826
feat: Opt code.
cptbtptpbcptdtptp Sep 12, 2021
9995fa4
feat: Opt code.
cptbtptpbcptdtptp Sep 13, 2021
ab2b889
feat: Opt code.
cptbtptpbcptdtptp Sep 13, 2021
33af812
feat: Opt code.
cptbtptpbcptdtptp Sep 13, 2021
a6aefa9
feat: Opt code.
cptbtptpbcptdtptp Sep 13, 2021
5f1298e
feat: Opt code.
cptbtptpbcptdtptp Sep 14, 2021
82b2f24
feat: Opt code.
cptbtptpbcptdtptp Sep 14, 2021
a4868b2
feat: Opt code.
cptbtptpbcptdtptp Sep 14, 2021
0545e14
feat: Opt code.
cptbtptpbcptdtptp Sep 14, 2021
39691a9
feat: Opt code.
cptbtptpbcptdtptp Sep 14, 2021
4a20e9c
feat: Opt code.
cptbtptpbcptdtptp Sep 14, 2021
1b20034
feat: Opt code.
cptbtptpbcptdtptp Sep 15, 2021
b16910a
feat: Opt code.
cptbtptpbcptdtptp Sep 15, 2021
805d4d0
feat: Opt code.
cptbtptpbcptdtptp Sep 22, 2021
b4d099c
feat: Opt code.
cptbtptpbcptdtptp Sep 22, 2021
2190bb3
feat: Opt code.
cptbtptpbcptdtptp Sep 23, 2021
b06a809
feat: Opt code.
cptbtptpbcptdtptp Sep 23, 2021
18132ed
feat: Opt code.
cptbtptpbcptdtptp Sep 26, 2021
1816ac9
feat: Opt code.
cptbtptpbcptdtptp Sep 26, 2021
757d91d
feat: Opt code.
cptbtptpbcptdtptp Sep 26, 2021
66882b0
feat: Opt code.
cptbtptpbcptdtptp Sep 28, 2021
7ebef93
feat: Opt code.
cptbtptpbcptdtptp Sep 28, 2021
1efbd11
feat: Opt code.
cptbtptpbcptdtptp Sep 29, 2021
702579e
feat: Opt code.
cptbtptpbcptdtptp Sep 29, 2021
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
13 changes: 9 additions & 4 deletions packages/core/src/Engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { RenderState } from "./shader/state/RenderState";
import { Texture2D, TextureCubeFace, TextureCubeMap, TextureFormat } from "./texture";
import { ModelMesh, PrimitiveMesh } from "./mesh";
import { CompareFunction } from "./shader";
import { InputManager } from "./input/InputManager";
import { IPhysics } from "@oasis-engine/design";
import { PhysicsManager } from "./physics";

Expand Down Expand Up @@ -65,6 +66,8 @@ export class Engine extends EventDispatcher {
_shaderProgramPools: ShaderProgramPool[] = [];
/** @internal */
_spriteMaskManager: SpriteMaskManager;
/** @internal */
_inputManager: InputManager;

protected _canvas: Canvas;
private _resourceManager: ResourceManager = new ResourceManager(this);
Expand Down Expand Up @@ -177,6 +180,8 @@ export class Engine extends EventDispatcher {
this._spriteDefaultMaterial = this._createSpriteMaterial();
this._spriteMaskDefaultMaterial = this._createSpriteMaskMaterial();

this._inputManager = new InputManager(this);

const whitePixel = new Uint8Array([255, 255, 255, 255]);

const whiteTexture2D = new Texture2D(this, 1, 1, TextureFormat.R8G8B8A8, false);
Expand Down Expand Up @@ -248,7 +253,10 @@ export class Engine extends EventDispatcher {
const scene = this._sceneManager._activeScene;
const componentsManager = this._componentsManager;
if (scene) {
scene._activeCameras.sort((camera1, camera2) => camera1.priority - camera2.priority);

componentsManager.callScriptOnStart();
this._inputManager._update();
if (this.physicsManager) {
componentsManager.callColliderOnUpdate();
this.physicsManager._update(deltaTime);
Expand Down Expand Up @@ -283,7 +291,7 @@ export class Engine extends EventDispatcher {
if (this._sceneManager) {
this._whiteTexture2D.destroy(true);
this._whiteTextureCube.destroy(true);

this._inputManager._destroy();
this.trigger(new Event("shutdown", this));
engineFeatureManager.callFeatureMethod(this, "shutdown", [this]);

Expand Down Expand Up @@ -339,9 +347,6 @@ export class Engine extends EventDispatcher {
scene._updateShaderData();

if (cameras.length > 0) {
// Sort on priority
//@ts-ignore
cameras.sort((camera1, camera2) => camera1.priority - camera2.priority);
for (let i = 0, l = cameras.length; i < l; i++) {
const camera = cameras[i];
const cameraEntity = camera.entity;
Expand Down
50 changes: 50 additions & 0 deletions packages/core/src/input/InputManager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { Engine } from "../Engine";
import { Pointer } from "./pointer/Pointer";
import { PointerManager } from "./pointer/PointerManager";

/**
* InputManager manages device input such as mouse, touch, keyboard, etc.
*/
export class InputManager {
private _pointerManager: PointerManager;

/**
* Pointer List.
*/
get pointers(): Readonly<Pointer[]> {
return this._pointerManager._pointers;
}

/**
* Whether to handle multi-pointer.
*/
get multiPointerEnabled(): boolean {
return this._pointerManager._multiPointerEnabled;
}

set multiPointerEnabled(enabled: boolean) {
this._pointerManager._multiPointerEnabled = enabled;
}

/**
* @internal
*/
constructor(engine: Engine) {
// @ts-ignore
this._pointerManager = new PointerManager(engine, engine.canvas._webCanvas);
}

/**
* @internal
*/
_update(): void {
this._pointerManager._update();
}

/**
* @internal
*/
_destroy(): void {
this._pointerManager._destroy();
}
}
13 changes: 13 additions & 0 deletions packages/core/src/input/enums/PointerPhase.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* The current phase of the pointer.
*/
export enum PointerPhase {
/** A Pointer pressed on the screen. */
Down,
/** A pointer moved on the screen. */
Move,
/** A pointer was lifted from the screen. */
Up,
/** The system cancelled tracking for the pointer. */
Leave
}
29 changes: 29 additions & 0 deletions packages/core/src/input/pointer/Pointer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Vector2 } from "@oasis-engine/math";
import { PointerPhase } from "../enums/PointerPhase";

/**
* Pointer.
*/
export class Pointer {
/**
* Unique id.
* @remark Start from 0.
*/
readonly id: number;
/** The phase of pointer. */
phase: PointerPhase = PointerPhase.Leave;
/** The position of the pointer in screen space pixel coordinates. */
position: Vector2 = new Vector2();

/** @internal */
_uniqueID: number;
/** @internal */
_needUpdate: boolean = true;

/**
* @internal
*/
constructor(id: number) {
this.id = id;
}
}
Loading