@rpgjs/common 3.0.0-beta.2 → 3.0.0-beta.5
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/lib/EventEmitter.d.ts +1 -0
- package/lib/EventEmitter.js +4 -0
- package/lib/EventEmitter.js.map +1 -1
- package/lib/Game.d.ts +5 -1
- package/lib/Game.js +32 -14
- package/lib/Game.js.map +1 -1
- package/lib/Hit.d.ts +9 -9
- package/lib/Input.d.ts +8 -8
- package/lib/Input.js +8 -8
- package/lib/Input.js.map +1 -1
- package/lib/Map.d.ts +221 -12
- package/lib/Map.js +234 -9
- package/lib/Map.js.map +1 -1
- package/lib/Player.d.ts +157 -26
- package/lib/Player.js +240 -127
- package/lib/Player.js.map +1 -1
- package/lib/Plugin.d.ts +5 -4
- package/lib/Plugin.js +3 -2
- package/lib/Plugin.js.map +1 -1
- package/lib/Scheduler.d.ts +14 -4
- package/lib/Scheduler.js +16 -6
- package/lib/Scheduler.js.map +1 -1
- package/lib/Shape.d.ts +88 -3
- package/lib/Shape.js +144 -4
- package/lib/Shape.js.map +1 -1
- package/lib/Utils.d.ts +11 -15
- package/lib/Utils.js +27 -49
- package/lib/Utils.js.map +1 -1
- package/lib/VirtualGrid.d.ts +27 -0
- package/lib/VirtualGrid.js +74 -0
- package/lib/VirtualGrid.js.map +1 -0
- package/lib/Worker.d.ts +7 -0
- package/lib/Worker.js +21 -0
- package/lib/Worker.js.map +1 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.js +4 -1
- package/lib/index.js.map +1 -1
- package/lib/transports/io.d.ts +6 -5
- package/lib/transports/io.js +14 -0
- package/lib/transports/io.js.map +1 -1
- package/lib/workers/move.d.ts +1 -0
- package/lib/workers/move.js +62 -0
- package/lib/workers/move.js.map +1 -0
- package/package.json +5 -3
package/lib/Scheduler.js
CHANGED
|
@@ -20,6 +20,12 @@ class Scheduler extends EventEmitter_1.EventEmitter {
|
|
|
20
20
|
*/
|
|
21
21
|
constructor(options) {
|
|
22
22
|
super();
|
|
23
|
+
this.options = options;
|
|
24
|
+
this.timestamp = 0;
|
|
25
|
+
this.lastTimestamp = 0;
|
|
26
|
+
this.deltaTime = 0;
|
|
27
|
+
this.deltaTimeInt = 0;
|
|
28
|
+
this.frame = 0;
|
|
23
29
|
this.options = Object.assign({
|
|
24
30
|
tick: null,
|
|
25
31
|
period: SIXTY_PER_SEC,
|
|
@@ -37,28 +43,32 @@ class Scheduler extends EventEmitter_1.EventEmitter {
|
|
|
37
43
|
if (currentTime > this.nextExecTime) {
|
|
38
44
|
this.delayCounter++;
|
|
39
45
|
this.callTick();
|
|
40
|
-
this.nextExecTime = currentTime + this.options.stepPeriod;
|
|
46
|
+
this.nextExecTime = currentTime + (this.options.stepPeriod || 0);
|
|
41
47
|
}
|
|
42
48
|
window.requestAnimationFrame(this.nextTickChecker.bind(this));
|
|
43
49
|
}
|
|
44
50
|
nextTick() {
|
|
45
|
-
|
|
46
|
-
|
|
51
|
+
const now = (new Date()).getTime();
|
|
52
|
+
this.deltaTime = now - this.timestamp;
|
|
53
|
+
this.frame++;
|
|
54
|
+
this.deltaTimeInt = Math.round(this.deltaTime / this.options.period);
|
|
55
|
+
this.timestamp = now;
|
|
56
|
+
if (this.timestamp > this.nextExecTime + this.options.period * LOOP_SLOW_THRESH) {
|
|
47
57
|
this.delayCounter++;
|
|
48
58
|
}
|
|
49
59
|
else
|
|
50
60
|
this.delayCounter = 0;
|
|
51
61
|
this.callTick();
|
|
52
|
-
this.nextExecTime =
|
|
62
|
+
this.nextExecTime = this.timestamp + this.options.period + this.requestedDelay;
|
|
53
63
|
this.requestedDelay = 0;
|
|
54
64
|
setTimeout(this.nextTick.bind(this), this.nextExecTime - (new Date()).getTime());
|
|
55
65
|
}
|
|
56
66
|
callTick() {
|
|
57
67
|
if (this.delayCounter >= LOOP_SLOW_COUNT) {
|
|
58
|
-
|
|
68
|
+
console.warn('[RPGJS] Warning, Event Loop is slow !');
|
|
59
69
|
this.delayCounter = 0;
|
|
60
70
|
}
|
|
61
|
-
this.options.tick();
|
|
71
|
+
this.options.tick(this.timestamp, this.deltaTime);
|
|
62
72
|
}
|
|
63
73
|
/**
|
|
64
74
|
* start the schedule
|
package/lib/Scheduler.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Scheduler.js","sourceRoot":"","sources":["../src/Scheduler.ts"],"names":[],"mappings":";;;AAAA,iDAA8C;AAE9C,MAAM,aAAa,GAAG,IAAI,GAAG,EAAE,CAAC;AAChC,MAAM,gBAAgB,GAAG,GAAG,CAAC;AAC7B,MAAM,eAAe,GAAG,EAAE,CAAC;AAE3B;;;GAGG;AACH,MAAa,SAAU,SAAQ,2BAAY;
|
|
1
|
+
{"version":3,"file":"Scheduler.js","sourceRoot":"","sources":["../src/Scheduler.ts"],"names":[],"mappings":";;;AAAA,iDAA8C;AAE9C,MAAM,aAAa,GAAG,IAAI,GAAG,EAAE,CAAC;AAChC,MAAM,gBAAgB,GAAG,GAAG,CAAC;AAC7B,MAAM,eAAe,GAAG,EAAE,CAAC;AAE3B;;;GAGG;AACH,MAAa,SAAU,SAAQ,2BAAY;IAWvC;;;;;;;OAOG;IACH,YAAoB,OAKnB;QACG,KAAK,EAAE,CAAA;QANS,YAAO,GAAP,OAAO,CAK1B;QAnBD,cAAS,GAAW,CAAC,CAAA;QACrB,kBAAa,GAAW,CAAC,CAAA;QACzB,cAAS,GAAW,CAAC,CAAA;QACrB,iBAAY,GAAW,CAAC,CAAA;QACxB,UAAK,GAAW,CAAC,CAAA;QAiBb,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC;YACzB,IAAI,EAAE,IAAI;YACV,MAAM,EAAE,aAAa;YACrB,KAAK,EAAE,aAAa,GAAG,CAAC;SAC3B,EAAE,OAAO,CAAC,CAAC;QACZ,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;QACzB,IAAI,CAAC,cAAc,GAAG,CAAC,CAAC;QACxB,IAAI,CAA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c,GAAG,CAAC,CAAC;QACxB,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,YAAY,GAAG,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;IACrF,CAAC;IAED,QAAQ;QACJ,IAAI,IAAI,CAAC,YAAY,IAAI,eAAe,EAAE;YACtC,OAAO,CAAC,IAAI,CAAC,uCAAuC,CAAC,CAAA;YACrD,IAAI,CAAC,YAAY,GAAG,CAAC,CAAC;SACzB;QACD,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;IACtD,CAAC;IAED;;;OAGG;IACH,KAAK;QACD,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QACrC,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,OAAO,MAAM,CAAC,qBAAqB,KAAK,UAAU;YAChF,MAAM,CAAC,qBAAqB,CAAC,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAClE,OAAO,IAAI,CAAC;IAChB,CAAC;IAED;;OAEG;IACH,SAAS;QACL,IAAI,CAAC,cAAc,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC;IAC9C,CAAC;IAED;;OAEG;IACH,SAAS;QACL,IAAI,CAAC,cAAc,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC;IAC9C,CAAC;CACJ;AAlGD,8BAkGC"}
|
package/lib/Shape.d.ts
CHANGED
|
@@ -1,23 +1,108 @@
|
|
|
1
1
|
import { RpgCommonPlayer } from './Player';
|
|
2
2
|
import { HitObject } from './Hit';
|
|
3
|
+
export declare enum ShapePositioning {
|
|
4
|
+
Default = "default",
|
|
5
|
+
Center = "center"
|
|
6
|
+
}
|
|
3
7
|
declare type ShapeObject = HitObject & {
|
|
4
8
|
onIn?(player: RpgCommonPlayer): any;
|
|
5
9
|
onOut?(player: RpgCommonPlayer): any;
|
|
10
|
+
fixEvent?: RpgCommonPlayer;
|
|
11
|
+
positioning?: ShapePositioning;
|
|
6
12
|
};
|
|
7
|
-
export declare class
|
|
8
|
-
|
|
9
|
-
|
|
13
|
+
export declare class RpgShape {
|
|
14
|
+
_hitbox: any;
|
|
15
|
+
private _properties;
|
|
10
16
|
type: string;
|
|
17
|
+
/**
|
|
18
|
+
* Get/Set name
|
|
19
|
+
* @title name
|
|
20
|
+
* @prop { string } name
|
|
21
|
+
* @memberof Shape
|
|
22
|
+
*/
|
|
11
23
|
name: string;
|
|
24
|
+
fixEvent?: RpgCommonPlayer;
|
|
12
25
|
private playersIn;
|
|
13
26
|
private onIn;
|
|
14
27
|
private onOut;
|
|
28
|
+
clientContainer: any;
|
|
29
|
+
/**
|
|
30
|
+
* Get/Set positioning
|
|
31
|
+
* @title positioning
|
|
32
|
+
* @prop { ShapePositioning } positioning
|
|
33
|
+
* @default default
|
|
34
|
+
* @memberof Shape
|
|
35
|
+
*/
|
|
36
|
+
positioning?: ShapePositioning;
|
|
15
37
|
constructor(obj: ShapeObject);
|
|
38
|
+
private setPos;
|
|
39
|
+
get hitbox(): any;
|
|
40
|
+
set hitbox(val: any);
|
|
41
|
+
/**
|
|
42
|
+
* Get/Set width
|
|
43
|
+
* @title width
|
|
44
|
+
* @prop { number } width
|
|
45
|
+
* @since 3.0.0-beta.5
|
|
46
|
+
* @memberof Shape
|
|
47
|
+
*/
|
|
48
|
+
get width(): number;
|
|
49
|
+
set width(val: number);
|
|
50
|
+
/**
|
|
51
|
+
* Get/Set height
|
|
52
|
+
* @title height
|
|
53
|
+
* @prop { number } height
|
|
54
|
+
* @since 3.0.0-beta.5
|
|
55
|
+
* @memberof Shape
|
|
56
|
+
*/
|
|
57
|
+
get height(): number;
|
|
58
|
+
set height(val: number);
|
|
59
|
+
/**
|
|
60
|
+
* Get/Set x
|
|
61
|
+
* @title x
|
|
62
|
+
* @prop { number } x
|
|
63
|
+
* @memberof Shape
|
|
64
|
+
*/
|
|
65
|
+
get x(): number;
|
|
66
|
+
set x(val: number);
|
|
67
|
+
/**
|
|
68
|
+
* Get/Set y
|
|
69
|
+
* @title y
|
|
70
|
+
* @prop { number } y
|
|
71
|
+
* @memberof Shape
|
|
72
|
+
*/
|
|
73
|
+
get y(): number;
|
|
74
|
+
set y(val: number);
|
|
75
|
+
/**
|
|
76
|
+
* Get/Set properties
|
|
77
|
+
|
|
78
|
+
* @title Properties
|
|
79
|
+
* @prop { object } Properties
|
|
80
|
+
* @memberof Shape
|
|
81
|
+
*/
|
|
82
|
+
get properties(): any;
|
|
83
|
+
set properties(val: any);
|
|
16
84
|
isEvent(): boolean;
|
|
17
85
|
set(obj: ShapeObject): void;
|
|
18
86
|
in(player: RpgCommonPlayer): boolean;
|
|
19
87
|
out(player: RpgCommonPlayer): boolean;
|
|
88
|
+
/**
|
|
89
|
+
* Whether the player is in this shape
|
|
90
|
+
*
|
|
91
|
+
* @title Player is in this shape ?
|
|
92
|
+
* @method shape.playerIsIn(player)
|
|
93
|
+
* @returns {boolean}
|
|
94
|
+
* @memberof Shape
|
|
95
|
+
*/
|
|
20
96
|
playerIsIn(player: RpgCommonPlayer): boolean;
|
|
21
97
|
isShapePosition(): boolean;
|
|
98
|
+
/**
|
|
99
|
+
* Recover the player with the shape. You must have used the `attachShape()` method on the player
|
|
100
|
+
*
|
|
101
|
+
* @title Get Player Owner
|
|
102
|
+
* @method shape.getPlayerOwner()
|
|
103
|
+
* @returns {RpgPlayer | undefined}
|
|
104
|
+
* @memberof Shape
|
|
105
|
+
*/
|
|
106
|
+
getPlayerOwner(): RpgCommonPlayer | undefined;
|
|
22
107
|
}
|
|
23
108
|
export {};
|
package/lib/Shape.js
CHANGED
|
@@ -1,21 +1,142 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.RpgShape = exports.ShapePositioning = void 0;
|
|
4
4
|
const Hit_1 = require("./Hit");
|
|
5
|
-
|
|
5
|
+
var ShapePositioning;
|
|
6
|
+
(function (ShapePositioning) {
|
|
7
|
+
ShapePositioning["Default"] = "default";
|
|
8
|
+
ShapePositioning["Center"] = "center";
|
|
9
|
+
})(ShapePositioning = exports.ShapePositioning || (exports.ShapePositioning = {}));
|
|
10
|
+
class RpgShape {
|
|
6
11
|
constructor(obj) {
|
|
7
|
-
this.
|
|
12
|
+
this._properties = {};
|
|
8
13
|
this.type = 'box';
|
|
14
|
+
/**
|
|
15
|
+
* Get/Set name
|
|
16
|
+
* @title name
|
|
17
|
+
* @prop { string } name
|
|
18
|
+
* @memberof Shape
|
|
19
|
+
*/
|
|
9
20
|
this.name = '';
|
|
10
21
|
this.playersIn = {};
|
|
22
|
+
this.clientContainer = null;
|
|
23
|
+
/**
|
|
24
|
+
* Get/Set positioning
|
|
25
|
+
* @title positioning
|
|
26
|
+
* @prop { ShapePositioning } positioning
|
|
27
|
+
* @default default
|
|
28
|
+
* @memberof Shape
|
|
29
|
+
*/
|
|
30
|
+
this.positioning = ShapePositioning.Default;
|
|
11
31
|
this.set(obj);
|
|
12
32
|
}
|
|
33
|
+
setPos(type, val) {
|
|
34
|
+
if (this.isShapePosition()) {
|
|
35
|
+
this.hitbox[type] = val;
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
this.hitbox.pos[type] = val;
|
|
39
|
+
}
|
|
40
|
+
if (this.clientContainer) {
|
|
41
|
+
if (type == 'w')
|
|
42
|
+
type = 'width';
|
|
43
|
+
else if (type == 'h')
|
|
44
|
+
type = 'height';
|
|
45
|
+
this.clientContainer[type] = val;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
get hitbox() {
|
|
49
|
+
if (this.fixEvent) {
|
|
50
|
+
this._hitbox.pos.x = this.fixEvent.position.x;
|
|
51
|
+
this._hitbox.pos.y = this.fixEvent.position.y;
|
|
52
|
+
switch (this.positioning) {
|
|
53
|
+
case ShapePositioning.Center:
|
|
54
|
+
this._hitbox.pos.x -= this._hitbox.w / 2 - this.fixEvent.hitbox.w / 2;
|
|
55
|
+
this._hitbox.pos.y -= this._hitbox.h / 2 - this.fixEvent.hitbox.h / 2;
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return this._hitbox;
|
|
60
|
+
}
|
|
61
|
+
set hitbox(val) {
|
|
62
|
+
this._hitbox = val;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Get/Set width
|
|
66
|
+
* @title width
|
|
67
|
+
* @prop { number } width
|
|
68
|
+
* @since 3.0.0-beta.5
|
|
69
|
+
* @memberof Shape
|
|
70
|
+
*/
|
|
71
|
+
get width() {
|
|
72
|
+
return this.hitbox.w || 0;
|
|
73
|
+
}
|
|
74
|
+
set width(val) {
|
|
75
|
+
this.setPos('w', val);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Get/Set height
|
|
79
|
+
* @title height
|
|
80
|
+
* @prop { number } height
|
|
81
|
+
* @since 3.0.0-beta.5
|
|
82
|
+
* @memberof Shape
|
|
83
|
+
*/
|
|
84
|
+
get height() {
|
|
85
|
+
return this.hitbox.h || 0;
|
|
86
|
+
}
|
|
87
|
+
set height(val) {
|
|
88
|
+
this.setPos('h', val);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Get/Set x
|
|
92
|
+
* @title x
|
|
93
|
+
* @prop { number } x
|
|
94
|
+
* @memberof Shape
|
|
95
|
+
*/
|
|
96
|
+
get x() {
|
|
97
|
+
return this.hitbox.x || this.hitbox.pos.x;
|
|
98
|
+
}
|
|
99
|
+
set x(val) {
|
|
100
|
+
this.setPos('x', val);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Get/Set y
|
|
104
|
+
* @title y
|
|
105
|
+
* @prop { number } y
|
|
106
|
+
* @memberof Shape
|
|
107
|
+
*/
|
|
108
|
+
get y() {
|
|
109
|
+
return this.hitbox.y || this.hitbox.pos.y;
|
|
110
|
+
}
|
|
111
|
+
set y(val) {
|
|
112
|
+
this.setPos('y', val);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Get/Set properties
|
|
116
|
+
|
|
117
|
+
* @title Properties
|
|
118
|
+
* @prop { object } Properties
|
|
119
|
+
* @memberof Shape
|
|
120
|
+
*/
|
|
121
|
+
get properties() {
|
|
122
|
+
if (this.fixEvent) {
|
|
123
|
+
return Object.assign({ z: this.fixEvent.position.z }, (this._properties || {}));
|
|
124
|
+
}
|
|
125
|
+
return this._properties;
|
|
126
|
+
}
|
|
127
|
+
set properties(val) {
|
|
128
|
+
this._properties = val;
|
|
129
|
+
}
|
|
13
130
|
isEvent() {
|
|
14
131
|
return this.type == 'event';
|
|
15
132
|
}
|
|
16
133
|
set(obj) {
|
|
17
134
|
const hit = Hit_1.Hit.getHitbox(obj);
|
|
18
135
|
Object.assign(this, hit);
|
|
136
|
+
this.x = obj.x || 0;
|
|
137
|
+
this.y = obj.y || 0;
|
|
138
|
+
this.positioning = obj.positioning;
|
|
139
|
+
this.fixEvent = obj.fixEvent;
|
|
19
140
|
}
|
|
20
141
|
in(player) {
|
|
21
142
|
if (!this.playerIsIn(player)) {
|
|
@@ -37,12 +158,31 @@ class Shape {
|
|
|
37
158
|
}
|
|
38
159
|
return false;
|
|
39
160
|
}
|
|
161
|
+
/**
|
|
162
|
+
* Whether the player is in this shape
|
|
163
|
+
*
|
|
164
|
+
* @title Player is in this shape ?
|
|
165
|
+
* @method shape.playerIsIn(player)
|
|
166
|
+
* @returns {boolean}
|
|
167
|
+
* @memberof Shape
|
|
168
|
+
*/
|
|
40
169
|
playerIsIn(player) {
|
|
41
170
|
return !!this.playersIn[player.id];
|
|
42
171
|
}
|
|
43
172
|
isShapePosition() {
|
|
44
173
|
return !this.hitbox.w;
|
|
45
174
|
}
|
|
175
|
+
/**
|
|
176
|
+
* Recover the player with the shape. You must have used the `attachShape()` method on the player
|
|
177
|
+
*
|
|
178
|
+
* @title Get Player Owner
|
|
179
|
+
* @method shape.getPlayerOwner()
|
|
180
|
+
* @returns {RpgPlayer | undefined}
|
|
181
|
+
* @memberof Shape
|
|
182
|
+
*/
|
|
183
|
+
getPlayerOwner() {
|
|
184
|
+
return this.fixEvent;
|
|
185
|
+
}
|
|
46
186
|
}
|
|
47
|
-
exports.
|
|
187
|
+
exports.RpgShape = RpgShape;
|
|
48
188
|
//# sourceMappingURL=Shape.js.map
|
package/lib/Shape.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Shape.js","sourceRoot":"","sources":["../src/Shape.ts"],"names":[],"mappings":";;;AACA,+BAAsC;
|
|
1
|
+
{"version":3,"file":"Shape.js","sourceRoot":"","sources":["../src/Shape.ts"],"names":[],"mappings":";;;AACA,+BAAsC;AAEtC,IAAY,gBAGX;AAHD,WAAY,gBAAgB;IACxB,uCAAmB,CAAA;IACnB,qCAAiB,CAAA;AACrB,CAAC,EAHW,gBAAgB,GAAhB,wBAAgB,KAAhB,wBAAgB,QAG3B;AASD,MAAa,QAAQ;IA2BjB,YAAY,GAAgB;QAzBpB,gBAAW,GAAQ,EAAE,CAAA;QAC7B,SAAI,GAAW,KAAK,CAAA;QACpB;;;;;UAKE;QACF,SAAI,GAAW,EAAE,CAAA;QAET,cAAS,GAEb,EAAE,CAAA;QAGN,oBAAe,GAAQ,IAAI,CAAA;QAC3B;;;;;;UAME;QACF,gBAAW,GAAsB,gBAAgB,CAAC,OAAO,CAAA;QAGrD,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;IACjB,CAAC;IAEO,MAAM,CAAC,IAAY,EAAE,GAAW;QACpC,IAAI,IAAI,CAAC,eAAe,EAAE,EAAE;YACxB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,GAAG,CAAA;SAC1B;aACI;YACD,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,GAA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MAAuB;QAC9B,OAAO,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;IACtC,CAAC;IAED,eAAe;QACX,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAA;IACzB,CAAC;IAEF;;;;;;;QAOI;IACH,cAAc;QACV,OAAO,IAAI,CAAC,QAAQ,CAAA;IACxB,CAAC;CACJ;AA5MD,4BA4MC"}
|
package/lib/Utils.d.ts
CHANGED
|
@@ -7,24 +7,18 @@ export declare function isArray(val: any): boolean;
|
|
|
7
7
|
export declare function isObject(val: any): boolean;
|
|
8
8
|
export declare function isString(val: any): boolean;
|
|
9
9
|
export declare function isInstanceOf(val: any, _class: any): boolean;
|
|
10
|
-
export declare function arrayUniq(array: any):
|
|
11
|
-
export declare function arrayFlat(array: any): any;
|
|
12
|
-
export declare function intersection([start1, end1]: [
|
|
10
|
+
export declare function arrayUniq(array: any[]): any[];
|
|
11
|
+
export declare function arrayFlat(array: any[]): any[];
|
|
12
|
+
export declare function intersection([start1, end1]: [number, number], [start2, end2]: [number, number]): boolean;
|
|
13
13
|
export declare function capitalize(s: any): string;
|
|
14
14
|
export declare function arrayEquals(a: any, b: any): any;
|
|
15
15
|
export declare function applyMixins(derivedCtor: any, baseCtors: any[]): void;
|
|
16
|
-
export declare function generateUID():
|
|
17
|
-
export declare function
|
|
18
|
-
|
|
19
|
-
x: number;
|
|
20
|
-
y: number;
|
|
21
|
-
};
|
|
22
|
-
dot_prod_grid: (x: any, y: any, vx: any, vy: any) => number;
|
|
23
|
-
smootherstep: (x: any) => number;
|
|
24
|
-
interp: (x: any, a: any, b: any) => any;
|
|
25
|
-
seed: () => void;
|
|
26
|
-
get: (x: any, y: any) => any;
|
|
16
|
+
export declare function generateUID(): string;
|
|
17
|
+
export declare function createConstructor(...propNames: any[]): {
|
|
18
|
+
new (...propValues: any[]): {};
|
|
27
19
|
};
|
|
20
|
+
export declare function sharedArrayBuffer(): any;
|
|
21
|
+
export declare function toRadians(angle: number): number;
|
|
28
22
|
declare const _default: {
|
|
29
23
|
random: typeof random;
|
|
30
24
|
isBrowser: typeof isBrowser;
|
|
@@ -41,7 +35,9 @@ declare const _default: {
|
|
|
41
35
|
intersection: typeof intersection;
|
|
42
36
|
applyMixins: typeof applyMixins;
|
|
43
37
|
capitalize: typeof capitalize;
|
|
44
|
-
|
|
38
|
+
sharedArrayBuffer: typeof sharedArrayBuffer;
|
|
45
39
|
generateUID: typeof generateUID;
|
|
40
|
+
createConstructor: typeof createConstructor;
|
|
41
|
+
toRadians: typeof toRadians;
|
|
46
42
|
};
|
|
47
43
|
export default _default;
|
package/lib/Utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.toRadians = exports.sharedArrayBuffer = exports.createConstructor = exports.generateUID = exports.applyMixins = exports.arrayEquals = exports.capitalize = exports.intersection = exports.arrayFlat = exports.arrayUniq = exports.isInstanceOf = exports.isString = exports.isObject = exports.isArray = exports.isPromise = exports.isClass = exports.isFunction = exports.isBrowser = exports.random = void 0;
|
|
4
4
|
function random(min, max) {
|
|
5
5
|
return Math.floor(Math.random() * (max - min + 1) + min);
|
|
6
6
|
}
|
|
@@ -80,55 +80,31 @@ function generateUID() {
|
|
|
80
80
|
return firstPart + secondPart;
|
|
81
81
|
}
|
|
82
82
|
exports.generateUID = generateUID;
|
|
83
|
-
function
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
dot_prod_grid: function (x, y, vx, vy) {
|
|
90
|
-
let g_vect;
|
|
91
|
-
let d_vect = { x: x - vx, y: y - vy };
|
|
92
|
-
if (this.gradients[`${vx},${vy}`]) {
|
|
93
|
-
g_vect = this.gradients[`${vx},${vy}`];
|
|
94
|
-
}
|
|
95
|
-
else {
|
|
96
|
-
g_vect = this.rand_vect();
|
|
97
|
-
this.gradients[`${vx},${vy}`] = g_vect;
|
|
98
|
-
}
|
|
99
|
-
return d_vect.x * g_vect.x + d_vect.y * g_vect.y;
|
|
100
|
-
},
|
|
101
|
-
smootherstep: function (x) {
|
|
102
|
-
return 6 * Math.pow(x, 5) - 15 * Math.pow(x, 4) + 10 * Math.pow(x, 3);
|
|
103
|
-
},
|
|
104
|
-
interp: function (x, a, b) {
|
|
105
|
-
return a + this.smootherstep(x) * (b - a);
|
|
106
|
-
},
|
|
107
|
-
seed: function () {
|
|
108
|
-
this.gradients = {};
|
|
109
|
-
this.memory = {};
|
|
110
|
-
},
|
|
111
|
-
get: function (x, y) {
|
|
112
|
-
if (this.memory.hasOwnProperty(`${x},${y}`))
|
|
113
|
-
return this.memory[`${x},${y}`];
|
|
114
|
-
let xf = Math.floor(x);
|
|
115
|
-
let yf = Math.floor(y);
|
|
116
|
-
//interpolate
|
|
117
|
-
let tl = this.dot_prod_grid(x, y, xf, yf);
|
|
118
|
-
let tr = this.dot_prod_grid(x, y, xf + 1, yf);
|
|
119
|
-
let bl = this.dot_prod_grid(x, y, xf, yf + 1);
|
|
120
|
-
let br = this.dot_prod_grid(x, y, xf + 1, yf + 1);
|
|
121
|
-
let xt = this.interp(x - xf, tl, tr);
|
|
122
|
-
let xb = this.interp(x - xf, bl, br);
|
|
123
|
-
let v = this.interp(y - yf, xt, xb);
|
|
124
|
-
this.memory[`${x},${y}`] = v;
|
|
125
|
-
return v;
|
|
83
|
+
function createConstructor(...propNames) {
|
|
84
|
+
return class {
|
|
85
|
+
constructor(...propValues) {
|
|
86
|
+
propNames.forEach((name, idx) => {
|
|
87
|
+
this[name] = propValues[idx];
|
|
88
|
+
});
|
|
126
89
|
}
|
|
127
90
|
};
|
|
128
|
-
perlin.seed();
|
|
129
|
-
return perlin;
|
|
130
91
|
}
|
|
131
|
-
exports.
|
|
92
|
+
exports.createConstructor = createConstructor;
|
|
93
|
+
function sharedArrayBuffer() {
|
|
94
|
+
let buffer;
|
|
95
|
+
if (typeof SharedArrayBuffer != 'undefined') {
|
|
96
|
+
buffer = SharedArrayBuffer;
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
buffer = ArrayBuffer;
|
|
100
|
+
}
|
|
101
|
+
return buffer;
|
|
102
|
+
}
|
|
103
|
+
exports.sharedArrayBuffer = sharedArrayBuffer;
|
|
104
|
+
function toRadians(angle) {
|
|
105
|
+
return angle * (Math.PI / 180);
|
|
106
|
+
}
|
|
107
|
+
exports.toRadians = toRadians;
|
|
132
108
|
exports.default = {
|
|
133
109
|
random,
|
|
134
110
|
isBrowser,
|
|
@@ -145,7 +121,9 @@ exports.default = {
|
|
|
145
121
|
intersection,
|
|
146
122
|
applyMixins,
|
|
147
123
|
capitalize,
|
|
148
|
-
|
|
149
|
-
generateUID
|
|
124
|
+
sharedArrayBuffer,
|
|
125
|
+
generateUID,
|
|
126
|
+
createConstructor,
|
|
127
|
+
toRadians
|
|
150
128
|
};
|
|
151
129
|
//# sourceMappingURL=Utils.js.map
|
package/lib/Utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Utils.js","sourceRoot":"","sources":["../src/Utils.ts"],"names":[],"mappings":";;;AAAA,SAAgB,MAAM,CAAC,GAAG,EAAE,GAAG;IAC3B,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,GAAG,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAA;AAC5D,CAAC;AAFD,wBAEC;AAED,SAAgB,SAAS;IACrB,OAAO,OAAO,MAAM,KAAK,WAAW,CAAA;AACxC,CAAC;AAFD,8BAEC;AAED,SAAgB,UAAU,CAAC,GAAG;IAC1B,OAAO,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,mBAAmB,CAAA;AACxD,CAAC;AAFD,gCAEC;AAED,SAAgB,OAAO,CAAC,IAAI;IACxB,OAAO,OAAO,IAAI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: number;
|
|
5
|
+
maxY: number;
|
|
6
|
+
};
|
|
7
|
+
export declare class VirtualGrid {
|
|
8
|
+
private nbCellWidth;
|
|
9
|
+
private cellWidth;
|
|
10
|
+
private cellHeight;
|
|
11
|
+
private cells;
|
|
12
|
+
private inverseCells;
|
|
13
|
+
constructor(nbCellWidth: number, cellWidth: number, cellHeight: number);
|
|
14
|
+
zoom(nbCell: number): VirtualGrid;
|
|
15
|
+
getCellIndex(x: number, y: number): number;
|
|
16
|
+
private getCells;
|
|
17
|
+
getObjectsByBox(box: Box): Set<string>;
|
|
18
|
+
getObjectsById(id: string): Set<string>;
|
|
19
|
+
clearObjectInCells(id: string): void;
|
|
20
|
+
insertInCells(id: string, box: {
|
|
21
|
+
minX: number;
|
|
22
|
+
minY: number;
|
|
23
|
+
maxX: number;
|
|
24
|
+
maxY: number;
|
|
25
|
+
}): void;
|
|
26
|
+
}
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VirtualGrid = void 0;
|
|
4
|
+
class VirtualGrid {
|
|
5
|
+
constructor(nbCellWidth, cellWidth, cellHeight) {
|
|
6
|
+
this.nbCellWidth = nbCellWidth;
|
|
7
|
+
this.cellWidth = cellWidth;
|
|
8
|
+
this.cellHeight = cellHeight;
|
|
9
|
+
this.cells = new Map();
|
|
10
|
+
this.inverseCells = new Map();
|
|
11
|
+
}
|
|
12
|
+
zoom(nbCell) {
|
|
13
|
+
this.nbCellWidth = Math.ceil(this.nbCellWidth / nbCell);
|
|
14
|
+
this.cellWidth *= nbCell;
|
|
15
|
+
this.cellHeight *= nbCell;
|
|
16
|
+
return this;
|
|
17
|
+
}
|
|
18
|
+
getCellIndex(x, y) {
|
|
19
|
+
return this.nbCellWidth * Math.floor(y / this.cellHeight) + Math.floor(x / this.cellWidth);
|
|
20
|
+
}
|
|
21
|
+
getCells(box, cb) {
|
|
22
|
+
const { minX, minY, maxX, maxY } = box;
|
|
23
|
+
const topLeft = this.getCellIndex(minX, minY);
|
|
24
|
+
const topRight = this.getCellIndex(maxX, minY);
|
|
25
|
+
const bottomLeft = this.getCellIndex(minX, maxY);
|
|
26
|
+
const nbLines = (bottomLeft - topLeft) / this.nbCellWidth + 1;
|
|
27
|
+
for (let j = 0; j < nbLines; j++) {
|
|
28
|
+
for (let i = topLeft; i <= topRight; i++) {
|
|
29
|
+
const index = i + (j * this.nbCellWidth);
|
|
30
|
+
cb(index);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
getObjectsByBox(box) {
|
|
35
|
+
let objects = [];
|
|
36
|
+
this.getCells(box, (index) => {
|
|
37
|
+
objects = [...objects, ...this.cells.get(index) || []];
|
|
38
|
+
});
|
|
39
|
+
return new Set(objects);
|
|
40
|
+
}
|
|
41
|
+
getObjectsById(id) {
|
|
42
|
+
let objects = [];
|
|
43
|
+
const cells = this.inverseCells.get(id);
|
|
44
|
+
cells === null || cells === void 0 ? void 0 : cells.forEach((index) => {
|
|
45
|
+
objects = [...objects, ...this.cells.get(index) || []];
|
|
46
|
+
});
|
|
47
|
+
return new Set(objects);
|
|
48
|
+
}
|
|
49
|
+
clearObjectInCells(id) {
|
|
50
|
+
var _a;
|
|
51
|
+
if (this.inverseCells.has(id)) {
|
|
52
|
+
(_a = this.inverseCells.get(id)) === null || _a === void 0 ? void 0 : _a.forEach((cellIndex) => {
|
|
53
|
+
var _a;
|
|
54
|
+
(_a = this.cells.get(cellIndex)) === null || _a === void 0 ? void 0 : _a.delete(id);
|
|
55
|
+
});
|
|
56
|
+
this.inverseCells.delete(id);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
insertInCells(id, box) {
|
|
60
|
+
this.clearObjectInCells(id);
|
|
61
|
+
const cells = new Set();
|
|
62
|
+
this.getCells(box, (index) => {
|
|
63
|
+
cells.add(index);
|
|
64
|
+
const memoryCells = this.cells.get(index);
|
|
65
|
+
if (!memoryCells) {
|
|
66
|
+
this.cells.set(index, new Set());
|
|
67
|
+
}
|
|
68
|
+
memoryCells === null || memoryCells === void 0 ? void 0 : memoryCells.add(id);
|
|
69
|
+
});
|
|
70
|
+
this.inverseCells.set(id, cells);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
exports.VirtualGrid = VirtualGrid;
|
|
74
|
+
//# sourceMappingURL=VirtualGrid.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VirtualGrid.js","sourceRoot":"","sources":["../src/VirtualGrid.ts"],"names":[],"mappings":";;;AAEA,MAAa,WAAW;IAIpB,YAAoB,WAAmB,EAAU,SAAiB,EAAU,UAAkB;QAA1E,gBAAW,GAAX,WAAW,CAAQ;QAAU,cAAS,GAAT,SAAS,CAAQ;QAAU,eAAU,GAAV,UAAU,CAAQ;QAHtF,UAAK,GAA6B,IAAI,GAAG,EAAE,CAAA;QAC3C,iBAAY,GAA6B,IAAI,GAAG,EAAE,CAAA;IAEuC,CAAC;IAElG,IAAI,CAAC,MAAc;QACf,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,CAAA;QACvD,IAAI,CAAC,SAAS,IAAI,MAAM,CAAA;QACxB,IAAI,CAAC,UAAU,IAAI,MAAM,CAAA;QACzB,OAAO,IAAI,CAAA;IACf,CAAC;IAED,YAAY,CAAC,CAAS,EAAE,CAAS;QAC7B,OAAO,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,CAAA;IAC9F,CAAC;IAEO,QAAQ,CAAC,GAAQ,EAAE,EAA2B;QAClD,MAAM,EACF,IAAI,EACJ,IAAI,EACJ,IAAI,EACJ,IAAI,EACP,GAAG,GAAG,CAAA;QACP,MAAM,OA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