@gg-web-engine/core 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/2d/entities/controllers/entity-2d-positioning.animator.d.ts +16 -0
- package/dist/2d/entities/controllers/entity-2d-positioning.animator.js +26 -0
- package/dist/2d/entities/gg-2d-entity.d.ts +12 -6
- package/dist/2d/entities/gg-2d-entity.js +52 -20
- package/dist/2d/gg-2d-world.d.ts +3 -0
- package/dist/2d/gg-2d-world.js +11 -0
- package/dist/3d/controllers/car-keyboard.controller.d.ts +10 -10
- package/dist/3d/controllers/car-keyboard.controller.js +21 -20
- package/dist/3d/controllers/free-camera.controller.d.ts +8 -8
- package/dist/3d/entities/controllers/animators/camera-3d.animator.d.ts +17 -0
- package/dist/3d/entities/controllers/animators/camera-3d.animator.js +32 -0
- package/dist/3d/entities/controllers/animators/entity-3d-positioning.animator.d.ts +16 -0
- package/dist/3d/entities/controllers/animators/entity-3d-positioning.animator.js +26 -0
- package/dist/3d/entities/controllers/camera-3d.animator.d.ts +17 -0
- package/dist/3d/entities/controllers/camera-3d.animator.js +32 -0
- package/dist/3d/entities/controllers/entity-3d-positioning.animator.d.ts +16 -0
- package/dist/3d/entities/controllers/entity-3d-positioning.animator.js +26 -0
- package/dist/3d/entities/controllers/input/car-keyboard-handling.controller.d.ts +25 -0
- package/dist/3d/entities/controllers/input/car-keyboard-handling.controller.js +105 -0
- package/dist/3d/entities/controllers/input/free-camera.controller.d.ts +54 -0
- package/dist/3d/entities/controllers/input/free-camera.controller.js +102 -0
- package/dist/3d/entities/gg-3d-camera.entity.d.ts +2 -0
- package/dist/3d/entities/gg-3d-camera.entity.js +6 -0
- package/dist/3d/entities/gg-3d-entity.d.ts +7 -6
- package/dist/3d/entities/gg-3d-entity.js +21 -13
- package/dist/3d/entities/gg-3d-map-graph.entity.d.ts +10 -10
- package/dist/3d/entities/gg-3d-map-graph.entity.js +2 -3
- package/dist/3d/entities/gg-3d-raycast-vehicle.entity.d.ts +6 -5
- package/dist/3d/gg-3d-world.d.ts +3 -0
- package/dist/3d/gg-3d-world.js +12 -0
- package/dist/3d/inputs/car-keyboard.input.d.ts +25 -0
- package/dist/3d/inputs/car-keyboard.input.js +100 -0
- package/dist/3d/inputs/free-camera.input.d.ts +22 -0
- package/dist/3d/inputs/free-camera.input.js +80 -0
- package/dist/base/clock/clock.d.ts +25 -0
- package/dist/base/clock/clock.js +79 -0
- package/dist/base/clock/global-clock.d.ts +16 -0
- package/dist/base/clock/global-clock.js +36 -0
- package/dist/base/clock/i-clock.d.ts +7 -0
- package/dist/base/clock/i-clock.js +2 -0
- package/dist/base/clock/pausable-clock.d.ts +25 -0
- package/dist/base/clock/pausable-clock.js +79 -0
- package/dist/base/entities/base-gg-renderer.d.ts +3 -15
- package/dist/base/entities/base-gg-renderer.js +2 -30
- package/dist/base/entities/controllers/animation-mixer.d.ts +76 -0
- package/dist/base/entities/controllers/animation-mixer.js +143 -0
- package/dist/base/entities/gg-entity.d.ts +33 -1
- package/dist/base/entities/gg-entity.js +42 -1
- package/dist/base/entities/inline-controller.js +1 -7
- package/dist/base/entities/interfaces/i-tick-listener.d.ts +25 -1
- package/dist/base/entities/interfaces/i-tick-listener.js +17 -1
- package/dist/base/gg-viewport-manager.d.ts +4 -0
- package/dist/base/gg-world.d.ts +11 -6
- package/dist/base/gg-world.js +50 -31
- package/dist/base/inputs/direction.keyboard-input.d.ts +41 -0
- package/dist/base/inputs/direction.keyboard-input.js +85 -0
- package/dist/base/inputs/input.d.ts +50 -0
- package/dist/base/inputs/input.js +80 -0
- package/dist/base/inputs/keyboard.input.d.ts +45 -0
- package/dist/base/inputs/keyboard.input.js +130 -0
- package/dist/base/inputs/mouse.input.d.ts +57 -0
- package/dist/base/inputs/mouse.input.js +81 -0
- package/dist/base/math/matrix4.js +3 -3
- package/dist/base/math/point2.js +1 -1
- package/dist/base/math/point3.js +1 -1
- package/dist/base/math/quaternion.d.ts +83 -9
- package/dist/base/math/quaternion.js +93 -10
- package/dist/base/models/points.d.ts +9 -9
- package/dist/index.d.ts +13 -9
- package/dist/index.js +13 -9
- package/package.json +1 -1
- package/.prettierrc +0 -8
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Input } from '../../base/inputs/input';
|
|
2
|
+
import { MouseControllerOptions, MouseInput } from '../../base/inputs/mouse.input';
|
|
3
|
+
import { Gg3dCameraEntity } from '../entities/gg-3d-camera.entity';
|
|
4
|
+
import { KeyboardInput } from '../../base/inputs/keyboard.input';
|
|
5
|
+
import { DirectionKeyboardInput, DirectionKeyboardKeymap } from '../../base/inputs/direction.keyboard-input';
|
|
6
|
+
export declare type FreeCameraControllerOptions = {
|
|
7
|
+
keymap: DirectionKeyboardKeymap;
|
|
8
|
+
movementOptions: {
|
|
9
|
+
speed: number;
|
|
10
|
+
};
|
|
11
|
+
mouseOptions: MouseControllerOptions;
|
|
12
|
+
};
|
|
13
|
+
export declare class FreeCameraInput extends Input<[], [unlockPointer?: boolean]> {
|
|
14
|
+
protected readonly keyboard: KeyboardInput;
|
|
15
|
+
protected readonly camera: Gg3dCameraEntity;
|
|
16
|
+
protected readonly options: FreeCameraControllerOptions;
|
|
17
|
+
protected readonly mouseInput: MouseInput;
|
|
18
|
+
protected readonly directionsInput: DirectionKeyboardInput;
|
|
19
|
+
constructor(keyboard: KeyboardInput, camera: Gg3dCameraEntity, options?: FreeCameraControllerOptions);
|
|
20
|
+
protected startInternal(): Promise<void>;
|
|
21
|
+
protected stopInternal(unlockPointer?: boolean): Promise<void>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.FreeCameraInput = void 0;
|
|
13
|
+
const input_1 = require("../../base/inputs/input");
|
|
14
|
+
const rxjs_1 = require("rxjs");
|
|
15
|
+
const mouse_input_1 = require("../../base/inputs/mouse.input");
|
|
16
|
+
const point3_1 = require("../../base/math/point3");
|
|
17
|
+
const point2_1 = require("../../base/math/point2");
|
|
18
|
+
const quaternion_1 = require("../../base/math/quaternion");
|
|
19
|
+
const direction_keyboard_input_1 = require("../../base/inputs/direction.keyboard-input");
|
|
20
|
+
class FreeCameraInput extends input_1.Input {
|
|
21
|
+
constructor(keyboard, camera, options = {
|
|
22
|
+
keymap: 'wasd',
|
|
23
|
+
movementOptions: { speed: 0.5 },
|
|
24
|
+
mouseOptions: {},
|
|
25
|
+
}) {
|
|
26
|
+
super();
|
|
27
|
+
this.keyboard = keyboard;
|
|
28
|
+
this.camera = camera;
|
|
29
|
+
this.options = options;
|
|
30
|
+
this.mouseInput = new mouse_input_1.MouseInput(options.mouseOptions);
|
|
31
|
+
this.directionsInput = new direction_keyboard_input_1.DirectionKeyboardInput(keyboard, options.keymap);
|
|
32
|
+
}
|
|
33
|
+
startInternal() {
|
|
34
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
let controls = { direction: {}, rest: [] };
|
|
36
|
+
const keys = ['KeyE', 'KeyQ'];
|
|
37
|
+
if (this.camera.object3D.supportsFov) {
|
|
38
|
+
keys.push('KeyZ', 'KeyC');
|
|
39
|
+
}
|
|
40
|
+
this.directionsInput.output$.pipe((0, rxjs_1.takeUntil)(this.stop$)).subscribe(d => {
|
|
41
|
+
controls.direction = d;
|
|
42
|
+
});
|
|
43
|
+
(0, rxjs_1.combineLatest)(keys.map(c => this.keyboard.bind(c)))
|
|
44
|
+
.pipe((0, rxjs_1.takeUntil)(this.stop$))
|
|
45
|
+
.subscribe((d) => {
|
|
46
|
+
controls.rest = d;
|
|
47
|
+
});
|
|
48
|
+
let rotationDelta = { x: 0, y: 0 };
|
|
49
|
+
this.mouseInput.delta$.pipe((0, rxjs_1.takeUntil)(this.stop$)).subscribe(delta => {
|
|
50
|
+
rotationDelta = point2_1.Pnt2.add(rotationDelta, delta);
|
|
51
|
+
});
|
|
52
|
+
this.camera.tick$.pipe((0, rxjs_1.takeUntil)(this.stop$)).subscribe(() => {
|
|
53
|
+
let translateVector = { x: 0, y: 0, z: 0 };
|
|
54
|
+
const [u, d, zo, zi] = controls.rest;
|
|
55
|
+
if (controls.direction.upDown !== undefined)
|
|
56
|
+
translateVector.z = controls.direction.upDown ? -1 : 1;
|
|
57
|
+
if (controls.direction.leftRight !== undefined)
|
|
58
|
+
translateVector.x = controls.direction.leftRight ? -1 : 1;
|
|
59
|
+
if (u != d)
|
|
60
|
+
translateVector.y = d ? -1 : 1;
|
|
61
|
+
if (zo != zi)
|
|
62
|
+
this.camera.object3D.fov += zo ? 1 : -1;
|
|
63
|
+
this.camera.position = point3_1.Pnt3.add(this.camera.position, point3_1.Pnt3.rot(point3_1.Pnt3.scalarMult(point3_1.Pnt3.norm(translateVector), this.options.movementOptions.speed), this.camera.rotation));
|
|
64
|
+
if (rotationDelta.x != 0 || rotationDelta.y != 0) {
|
|
65
|
+
this.camera.rotation = quaternion_1.Qtrn.combineRotations(quaternion_1.Qtrn.fromAngle({ x: 0, y: 0, z: 1 }, -rotationDelta.x / 300), this.camera.rotation, quaternion_1.Qtrn.fromAngle({ x: 1, y: 0, z: 0 }, -rotationDelta.y / 300));
|
|
66
|
+
rotationDelta = { x: 0, y: 0 };
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
yield this.mouseInput.start();
|
|
70
|
+
yield this.directionsInput.start();
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
stopInternal(unlockPointer = true) {
|
|
74
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
75
|
+
yield this.mouseInput.stop(unlockPointer);
|
|
76
|
+
yield this.directionsInput.stop();
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
exports.FreeCameraInput = FreeCameraInput;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Observable } from 'rxjs';
|
|
2
|
+
import { GgGlobalClock } from './global-clock';
|
|
3
|
+
/**
|
|
4
|
+
* A class, providing ability to track time, fire ticks, provide time elapsed + tick delta with ability to suspend/resume it.
|
|
5
|
+
*/
|
|
6
|
+
export declare class Clock {
|
|
7
|
+
protected readonly parentClock: Clock | GgGlobalClock;
|
|
8
|
+
private tickSub;
|
|
9
|
+
private readonly _tick$;
|
|
10
|
+
get tick$(): Observable<[number, number]>;
|
|
11
|
+
get isRunning(): boolean;
|
|
12
|
+
get isPaused(): boolean;
|
|
13
|
+
get elapsedTime(): number;
|
|
14
|
+
private startedAt;
|
|
15
|
+
private oldRelativeTime;
|
|
16
|
+
private pausedAt;
|
|
17
|
+
constructor(autoStart?: boolean, parentClock?: Clock | GgGlobalClock);
|
|
18
|
+
createChildClock(autoStart: boolean): Clock;
|
|
19
|
+
start(): void;
|
|
20
|
+
stop(): void;
|
|
21
|
+
pause(): void;
|
|
22
|
+
resume(): void;
|
|
23
|
+
protected startListeningTicks(): void;
|
|
24
|
+
protected stopListeningTicks(): void;
|
|
25
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Clock = void 0;
|
|
4
|
+
const rxjs_1 = require("rxjs");
|
|
5
|
+
const operators_1 = require("rxjs/operators");
|
|
6
|
+
const global_clock_1 = require("./global-clock");
|
|
7
|
+
/**
|
|
8
|
+
* A class, providing ability to track time, fire ticks, provide time elapsed + tick delta with ability to suspend/resume it.
|
|
9
|
+
*/
|
|
10
|
+
class Clock {
|
|
11
|
+
constructor(autoStart = false, parentClock = global_clock_1.GgGlobalClock.instance) {
|
|
12
|
+
this.parentClock = parentClock;
|
|
13
|
+
this.tickSub = null;
|
|
14
|
+
this._tick$ = new rxjs_1.Subject();
|
|
15
|
+
// state
|
|
16
|
+
this.startedAt = -1;
|
|
17
|
+
this.oldRelativeTime = 0; // "elapsed", emitted on last tick
|
|
18
|
+
this.pausedAt = -1;
|
|
19
|
+
if (autoStart) {
|
|
20
|
+
this.start();
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
get tick$() {
|
|
24
|
+
return this._tick$.pipe((0, operators_1.map)(([oldTime, newTime]) => [newTime, newTime - oldTime]));
|
|
25
|
+
}
|
|
26
|
+
get isRunning() {
|
|
27
|
+
return !!this.tickSub;
|
|
28
|
+
}
|
|
29
|
+
get isPaused() {
|
|
30
|
+
return this.pausedAt !== -1;
|
|
31
|
+
}
|
|
32
|
+
get elapsedTime() {
|
|
33
|
+
if (this.isPaused) {
|
|
34
|
+
return this.pausedAt - this.startedAt;
|
|
35
|
+
}
|
|
36
|
+
return this.parentClock.elapsedTime - this.startedAt;
|
|
37
|
+
}
|
|
38
|
+
createChildClock(autoStart) {
|
|
39
|
+
return new Clock(autoStart, this);
|
|
40
|
+
}
|
|
41
|
+
start() {
|
|
42
|
+
if (this.isRunning) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
this.oldRelativeTime = 0;
|
|
46
|
+
this.startedAt = this.parentClock.elapsedTime;
|
|
47
|
+
this.startListeningTicks();
|
|
48
|
+
}
|
|
49
|
+
stop() {
|
|
50
|
+
this.stopListeningTicks();
|
|
51
|
+
this.startedAt = this.pausedAt = -1;
|
|
52
|
+
}
|
|
53
|
+
pause() {
|
|
54
|
+
this.stopListeningTicks();
|
|
55
|
+
this.pausedAt = this.parentClock.elapsedTime;
|
|
56
|
+
}
|
|
57
|
+
resume() {
|
|
58
|
+
if (this.isRunning || this.pausedAt == -1) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
this.startedAt += this.parentClock.elapsedTime - this.pausedAt;
|
|
62
|
+
this.pausedAt = -1;
|
|
63
|
+
this.startListeningTicks();
|
|
64
|
+
}
|
|
65
|
+
startListeningTicks() {
|
|
66
|
+
if (this.tickSub) {
|
|
67
|
+
throw new Error('Clock is already ticking!');
|
|
68
|
+
}
|
|
69
|
+
this.tickSub = this.parentClock.tick$
|
|
70
|
+
.pipe((0, operators_1.map)(([parentElapsed, _]) => [this.oldRelativeTime, parentElapsed - this.startedAt]), (0, operators_1.tap)(([_, cur]) => (this.oldRelativeTime = cur)))
|
|
71
|
+
.subscribe(this._tick$);
|
|
72
|
+
}
|
|
73
|
+
stopListeningTicks() {
|
|
74
|
+
var _a;
|
|
75
|
+
(_a = this.tickSub) === null || _a === void 0 ? void 0 : _a.unsubscribe();
|
|
76
|
+
this.tickSub = null;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
exports.Clock = Clock;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Observable } from 'rxjs';
|
|
2
|
+
import { PausableClock } from './pausable-clock';
|
|
3
|
+
import { IClock } from './i-clock';
|
|
4
|
+
/**
|
|
5
|
+
* A singleton class, providing ability to track time, fire ticks, provide time elapsed + tick delta.
|
|
6
|
+
* Starts as soon as accessed and counts time from 01/01/1970
|
|
7
|
+
*/
|
|
8
|
+
export declare class GgGlobalClock implements IClock {
|
|
9
|
+
private static _instance;
|
|
10
|
+
static get instance(): GgGlobalClock;
|
|
11
|
+
private readonly _tick$;
|
|
12
|
+
get tick$(): Observable<[number, number]>;
|
|
13
|
+
get elapsedTime(): number;
|
|
14
|
+
createChildClock(autoStart: boolean): PausableClock;
|
|
15
|
+
private constructor();
|
|
16
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GgGlobalClock = void 0;
|
|
4
|
+
const rxjs_1 = require("rxjs");
|
|
5
|
+
const operators_1 = require("rxjs/operators");
|
|
6
|
+
const pausable_clock_1 = require("./pausable-clock");
|
|
7
|
+
/**
|
|
8
|
+
* A singleton class, providing ability to track time, fire ticks, provide time elapsed + tick delta.
|
|
9
|
+
* Starts as soon as accessed and counts time from 01/01/1970
|
|
10
|
+
*/
|
|
11
|
+
class GgGlobalClock {
|
|
12
|
+
constructor() {
|
|
13
|
+
this._tick$ = new rxjs_1.Subject();
|
|
14
|
+
let oldRelativeTime = this.elapsedTime;
|
|
15
|
+
(0, rxjs_1.of)(undefined, rxjs_1.animationFrameScheduler)
|
|
16
|
+
.pipe((0, operators_1.repeat)())
|
|
17
|
+
.pipe((0, operators_1.map)(() => [oldRelativeTime, this.elapsedTime]), (0, operators_1.tap)(([_, cur]) => (oldRelativeTime = cur)))
|
|
18
|
+
.subscribe(this._tick$);
|
|
19
|
+
}
|
|
20
|
+
static get instance() {
|
|
21
|
+
if (!GgGlobalClock._instance) {
|
|
22
|
+
GgGlobalClock._instance = new GgGlobalClock();
|
|
23
|
+
}
|
|
24
|
+
return GgGlobalClock._instance;
|
|
25
|
+
}
|
|
26
|
+
get tick$() {
|
|
27
|
+
return this._tick$.pipe((0, operators_1.map)(([oldTime, newTime]) => [newTime, newTime - oldTime]));
|
|
28
|
+
}
|
|
29
|
+
get elapsedTime() {
|
|
30
|
+
return (typeof performance === 'undefined' ? Date : performance).now();
|
|
31
|
+
}
|
|
32
|
+
createChildClock(autoStart) {
|
|
33
|
+
return new pausable_clock_1.PausableClock(autoStart, this);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.GgGlobalClock = GgGlobalClock;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Observable } from 'rxjs';
|
|
2
|
+
import { IClock } from './i-clock';
|
|
3
|
+
/**
|
|
4
|
+
* A class, providing ability to track time, fire ticks, provide time elapsed + tick delta with ability to suspend/resume it.
|
|
5
|
+
*/
|
|
6
|
+
export declare class PausableClock implements IClock {
|
|
7
|
+
protected readonly parentClock: IClock;
|
|
8
|
+
private tickSub;
|
|
9
|
+
private readonly _tick$;
|
|
10
|
+
get tick$(): Observable<[number, number]>;
|
|
11
|
+
get isRunning(): boolean;
|
|
12
|
+
get isPaused(): boolean;
|
|
13
|
+
get elapsedTime(): number;
|
|
14
|
+
private startedAt;
|
|
15
|
+
private oldRelativeTime;
|
|
16
|
+
private pausedAt;
|
|
17
|
+
constructor(autoStart?: boolean, parentClock?: IClock);
|
|
18
|
+
createChildClock(autoStart: boolean): PausableClock;
|
|
19
|
+
start(): void;
|
|
20
|
+
stop(): void;
|
|
21
|
+
pause(): void;
|
|
22
|
+
resume(): void;
|
|
23
|
+
protected startListeningTicks(): void;
|
|
24
|
+
protected stopListeningTicks(): void;
|
|
25
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PausableClock = void 0;
|
|
4
|
+
const rxjs_1 = require("rxjs");
|
|
5
|
+
const operators_1 = require("rxjs/operators");
|
|
6
|
+
const global_clock_1 = require("./global-clock");
|
|
7
|
+
/**
|
|
8
|
+
* A class, providing ability to track time, fire ticks, provide time elapsed + tick delta with ability to suspend/resume it.
|
|
9
|
+
*/
|
|
10
|
+
class PausableClock {
|
|
11
|
+
constructor(autoStart = false, parentClock = global_clock_1.GgGlobalClock.instance) {
|
|
12
|
+
this.parentClock = parentClock;
|
|
13
|
+
this.tickSub = null;
|
|
14
|
+
this._tick$ = new rxjs_1.Subject();
|
|
15
|
+
// state
|
|
16
|
+
this.startedAt = -1;
|
|
17
|
+
this.oldRelativeTime = 0; // "elapsed", emitted on last tick
|
|
18
|
+
this.pausedAt = -1;
|
|
19
|
+
if (autoStart) {
|
|
20
|
+
this.start();
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
get tick$() {
|
|
24
|
+
return this._tick$.pipe((0, operators_1.map)(([oldTime, newTime]) => [newTime, newTime - oldTime]));
|
|
25
|
+
}
|
|
26
|
+
get isRunning() {
|
|
27
|
+
return !!this.tickSub;
|
|
28
|
+
}
|
|
29
|
+
get isPaused() {
|
|
30
|
+
return this.pausedAt !== -1;
|
|
31
|
+
}
|
|
32
|
+
get elapsedTime() {
|
|
33
|
+
if (this.isPaused) {
|
|
34
|
+
return this.pausedAt - this.startedAt;
|
|
35
|
+
}
|
|
36
|
+
return this.parentClock.elapsedTime - this.startedAt;
|
|
37
|
+
}
|
|
38
|
+
createChildClock(autoStart) {
|
|
39
|
+
return new PausableClock(autoStart, this);
|
|
40
|
+
}
|
|
41
|
+
start() {
|
|
42
|
+
if (this.isRunning) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
this.oldRelativeTime = 0;
|
|
46
|
+
this.startedAt = this.parentClock.elapsedTime;
|
|
47
|
+
this.startListeningTicks();
|
|
48
|
+
}
|
|
49
|
+
stop() {
|
|
50
|
+
this.stopListeningTicks();
|
|
51
|
+
this.startedAt = this.pausedAt = -1;
|
|
52
|
+
}
|
|
53
|
+
pause() {
|
|
54
|
+
this.stopListeningTicks();
|
|
55
|
+
this.pausedAt = this.parentClock.elapsedTime;
|
|
56
|
+
}
|
|
57
|
+
resume() {
|
|
58
|
+
if (this.isRunning || this.pausedAt == -1) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
this.startedAt += this.parentClock.elapsedTime - this.pausedAt;
|
|
62
|
+
this.pausedAt = -1;
|
|
63
|
+
this.startListeningTicks();
|
|
64
|
+
}
|
|
65
|
+
startListeningTicks() {
|
|
66
|
+
if (this.tickSub) {
|
|
67
|
+
throw new Error('Clock is already ticking!');
|
|
68
|
+
}
|
|
69
|
+
this.tickSub = this.parentClock.tick$
|
|
70
|
+
.pipe((0, operators_1.map)(([parentElapsed, _]) => [this.oldRelativeTime, parentElapsed - this.startedAt]), (0, operators_1.tap)(([_, cur]) => (this.oldRelativeTime = cur)))
|
|
71
|
+
.subscribe(this._tick$);
|
|
72
|
+
}
|
|
73
|
+
stopListeningTicks() {
|
|
74
|
+
var _a;
|
|
75
|
+
(_a = this.tickSub) === null || _a === void 0 ? void 0 : _a.unsubscribe();
|
|
76
|
+
this.tickSub = null;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
exports.PausableClock = PausableClock;
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Subject, Subscription } from 'rxjs';
|
|
3
|
-
import { GgEntity } from './gg-entity';
|
|
1
|
+
import { GgEntity, GGTickOrder } from './gg-entity';
|
|
4
2
|
import { Point2 } from '../models/points';
|
|
5
3
|
export declare type RendererOptions = {
|
|
6
4
|
transparent: boolean;
|
|
@@ -9,20 +7,10 @@ export declare type RendererOptions = {
|
|
|
9
7
|
forceResolution?: number;
|
|
10
8
|
antialias: boolean;
|
|
11
9
|
};
|
|
12
|
-
export declare abstract class BaseGgRenderer extends GgEntity
|
|
13
|
-
|
|
14
|
-
protected _singularRenderMethods: Map<number, Function>;
|
|
15
|
-
private initialized;
|
|
16
|
-
readonly tick$: Subject<[number, number]>;
|
|
17
|
-
readonly tickOrder = 1000;
|
|
18
|
-
protected tickListener: Subscription | null;
|
|
10
|
+
export declare abstract class BaseGgRenderer extends GgEntity {
|
|
11
|
+
readonly tickOrder = GGTickOrder.RENDERING;
|
|
19
12
|
readonly rendererOptions: RendererOptions;
|
|
20
13
|
protected constructor(canvas?: HTMLCanvasElement, options?: Partial<RendererOptions>);
|
|
21
|
-
get isActive(): boolean;
|
|
22
|
-
activate(): void;
|
|
23
|
-
deactivate(): void;
|
|
24
|
-
init(): void;
|
|
25
14
|
abstract render(): void;
|
|
26
15
|
abstract resize(newSize: Point2): void;
|
|
27
|
-
abstract dispose(): void;
|
|
28
16
|
}
|
|
@@ -1,49 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BaseGgRenderer = void 0;
|
|
4
|
-
const rxjs_1 = require("rxjs");
|
|
5
4
|
const gg_entity_1 = require("./gg-entity");
|
|
6
5
|
const gg_viewport_manager_1 = require("../gg-viewport-manager");
|
|
7
6
|
class BaseGgRenderer extends gg_entity_1.GgEntity {
|
|
8
7
|
constructor(canvas, options = {}) {
|
|
9
8
|
super();
|
|
10
|
-
this.
|
|
11
|
-
this.tickOrder = 1000;
|
|
12
|
-
this.tickListener = null;
|
|
9
|
+
this.tickOrder = gg_entity_1.GGTickOrder.RENDERING;
|
|
13
10
|
this.rendererOptions = Object.assign({ transparent: false, background: 0x000000, antialias: true }, (options || {}));
|
|
14
|
-
this._permanentRenderMethods = new Map();
|
|
15
|
-
this._singularRenderMethods = new Map();
|
|
16
|
-
this.tick$ = new rxjs_1.Subject();
|
|
17
11
|
if (canvas) {
|
|
18
12
|
setTimeout(() => {
|
|
19
13
|
gg_viewport_manager_1.GgViewportManager.instance.assignRendererToCanvas(this, canvas).then();
|
|
20
14
|
}, 0);
|
|
21
15
|
}
|
|
22
|
-
|
|
23
|
-
get isActive() {
|
|
24
|
-
return !!this.tickListener;
|
|
25
|
-
}
|
|
26
|
-
activate() {
|
|
27
|
-
if (this.isActive) {
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
if (!this.initialized) {
|
|
31
|
-
this.init();
|
|
32
|
-
}
|
|
33
|
-
this.tickListener = this.tick$.subscribe(() => {
|
|
16
|
+
this.tick$.subscribe(() => {
|
|
34
17
|
this.render();
|
|
35
18
|
});
|
|
36
19
|
}
|
|
37
|
-
deactivate() {
|
|
38
|
-
var _a;
|
|
39
|
-
if (!this.isActive) {
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
(_a = this.tickListener) === null || _a === void 0 ? void 0 : _a.unsubscribe();
|
|
43
|
-
this.tickListener = null;
|
|
44
|
-
}
|
|
45
|
-
init() {
|
|
46
|
-
this.initialized = true;
|
|
47
|
-
}
|
|
48
20
|
}
|
|
49
21
|
exports.BaseGgRenderer = BaseGgRenderer;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { GgEntity } from '../gg-entity';
|
|
2
|
+
import { Observable, Subject } from 'rxjs';
|
|
3
|
+
import { GgWorld } from '../../gg-world';
|
|
4
|
+
export declare type AnimationFunction<T> = (elapsed: number, delta: number) => T;
|
|
5
|
+
/**
|
|
6
|
+
* A class that performs property animations for a specific type `T` by using provided animation function.
|
|
7
|
+
* Supports smooth transition between animation function by interpolating between values over time.
|
|
8
|
+
* The current value of the animation can be subscribed to using the `subscribeToValue` property.
|
|
9
|
+
* The animation function can be changed with `transitAnimationFunction` or `transitFromStaticState`.
|
|
10
|
+
*/
|
|
11
|
+
export declare class AnimationMixer<T> extends GgEntity {
|
|
12
|
+
protected _animationFunction: AnimationFunction<T>;
|
|
13
|
+
protected _lerp: (a: T, b: T, t: number) => T;
|
|
14
|
+
readonly tickOrder: number;
|
|
15
|
+
/**
|
|
16
|
+
* A subject that emits the current value of the animation on every tick.
|
|
17
|
+
*/
|
|
18
|
+
protected readonly _value$: Subject<T>;
|
|
19
|
+
/**
|
|
20
|
+
* The current transition time reference `[elapsed, delta]` that interpolates between the old and new functions.
|
|
21
|
+
*/
|
|
22
|
+
private _currentTransitionK;
|
|
23
|
+
/**
|
|
24
|
+
* The current transition subscription, which is null if no transition is currently active.
|
|
25
|
+
*/
|
|
26
|
+
private _currentTransition;
|
|
27
|
+
/**
|
|
28
|
+
* A behavior subject that emits whether the animator is currently in a transition.
|
|
29
|
+
*/
|
|
30
|
+
private _isInTransition$;
|
|
31
|
+
/**
|
|
32
|
+
* Gets an observable of the current value of the animation.
|
|
33
|
+
*/
|
|
34
|
+
get value$(): Observable<T>;
|
|
35
|
+
/**
|
|
36
|
+
* Gets the current motion control function that determines the animation.
|
|
37
|
+
*/
|
|
38
|
+
get animationFunction(): AnimationFunction<T>;
|
|
39
|
+
/**
|
|
40
|
+
* Sets the current motion control function that determines the animation.
|
|
41
|
+
* @param value The new motion control function.
|
|
42
|
+
*/
|
|
43
|
+
set animationFunction(value: AnimationFunction<T>);
|
|
44
|
+
/**
|
|
45
|
+
* Gets a flag whether the animator is currently in a transition.
|
|
46
|
+
*/
|
|
47
|
+
get isInTransition(): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Gets an observable that emits whether the animator is currently in a transition.
|
|
50
|
+
*/
|
|
51
|
+
get isInTransition$(): Observable<boolean>;
|
|
52
|
+
protected get currentTransition(): ((a: [number, number]) => void) | null;
|
|
53
|
+
protected set currentTransition(value: ((a: [number, number]) => void) | null);
|
|
54
|
+
/**
|
|
55
|
+
* Creates a new `AnimationMixer` entity.
|
|
56
|
+
* @param _animationFunction The initial motion control function that determines the animation.
|
|
57
|
+
* @param _lerp The linear interpolation between two values of type `T`.
|
|
58
|
+
*/
|
|
59
|
+
constructor(_animationFunction: AnimationFunction<T>, _lerp?: (a: T, b: T, t: number) => T);
|
|
60
|
+
/**
|
|
61
|
+
* Set output to static value and smoothly transit to new control function
|
|
62
|
+
* @param newFunc a new function
|
|
63
|
+
* @param transitionDuration a duration, after which new function will be fully controlling the output
|
|
64
|
+
* @param easing an easing function for transition
|
|
65
|
+
*/
|
|
66
|
+
transitFromStaticState(state: T, newFunc: AnimationFunction<T>, transitionDuration: number, easing?: (t: number) => number): void;
|
|
67
|
+
/**
|
|
68
|
+
* Smoothly transit to new control function
|
|
69
|
+
* @param newFunc a new function
|
|
70
|
+
* @param transitionDuration a duration, after which new function will be fully controlling the output
|
|
71
|
+
* @param easing an easing function for transition
|
|
72
|
+
*/
|
|
73
|
+
transitAnimationFunction(newFunc: AnimationFunction<T>, transitionDuration: number, easing?: (t: number) => number): void;
|
|
74
|
+
onSpawned(world: GgWorld<any, any>): void;
|
|
75
|
+
dispose(): void;
|
|
76
|
+
}
|