@urso/core 0.7.79-dev → 0.7.81

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@urso/core",
3
- "version": "0.7.79-dev",
3
+ "version": "0.7.81",
4
4
  "description": "HTML5 game engine",
5
5
  "main": "build/js/index.js",
6
6
  "author": "Megbrimef",
@@ -100,8 +100,10 @@ window.Urso = {
100
100
  Objects: {
101
101
  BaseModel: require('../modules/objects/baseModel'),
102
102
  Cache: require('../modules/objects/cache'),
103
+ Config: require('../modules/objects/config'),
103
104
  Controller: require('../modules/objects/controller'),
104
105
  Find: require('../modules/objects/find'),
106
+ Pool: require('../modules/objects/pool'),
105
107
  PropertyAdapter: require('../modules/objects/propertyAdapter'),
106
108
  Proxy: require('../modules/objects/proxy'),
107
109
  Selector: require('../modules/objects/selector'),
@@ -0,0 +1,10 @@
1
+ class ModulesObjectsConfig {
2
+
3
+ constructor() {
4
+ this.singleton = true;
5
+ this.objectsToCache = []; //arrow of types. as example [Urso.types.objects.IMAGE, Urso.types.objects.SPINE]
6
+ };
7
+
8
+ }
9
+
10
+ module.exports = ModulesObjectsConfig;
@@ -0,0 +1,68 @@
1
+ class ModulesObjectsPool {
2
+
3
+ _objectsCache = {};
4
+ _objectsCounter = 0;
5
+
6
+ constructor() {
7
+ this.singleton = true;
8
+
9
+ this._objectsPool = new Urso.Game.Lib.ObjectPool(
10
+ this._constructorFunction.bind(this),
11
+ this._resetFunction.bind(this)
12
+ );
13
+ };
14
+
15
+ getElement(object, parent) {
16
+ const poolElement = this._objectsPool.getElement(object.assetKey, { object, parent });
17
+ this._objectsCounter++;
18
+ this._objectsCache[this._objectsCounter] = poolElement;
19
+
20
+
21
+ const newObject = poolElement.data;
22
+ newObject._poolCacheId = this._objectsCounter;
23
+
24
+ if (typeof object.x === 'number') newObject.x = object.x; else newObject.x = 0;
25
+ if (typeof object.y === 'number') newObject.y = object.y; else newObject.y = 0;
26
+ if (typeof object.angle === 'number') newObject.angle = object.angle; else newObject.angle = 0;
27
+ if (typeof object.anchorX === 'number') newObject.anchorX = object.anchorX; else newObject.anchorX = 0;
28
+ if (typeof object.anchorY === 'number') newObject.anchorY = object.anchorY; else newObject.anchorY = 0;
29
+ if (typeof object.visible === 'boolean') newObject.visible = object.visible; else newObject.visible = true;
30
+
31
+ if (object?.type === Urso.types.objects.SPINE)
32
+ newObject.setAnimationConfig(object.animation); //setup oncomplete
33
+
34
+ this.getInstance('Service').addChild(parent, newObject, true);
35
+ return newObject;
36
+ }
37
+
38
+ putElement(object, doNotRefreshStylesFlag) {
39
+ if (object._poolCacheId) {
40
+ this._objectsPool.putElement(this._objectsCache[object._poolCacheId]);
41
+ delete this._objectsCache[object._poolCacheId];
42
+ return;
43
+ }
44
+
45
+ console.error('ModulesObjectsPool something goes wrong: object must be in pool');
46
+ }
47
+
48
+ _constructorFunction(_, { object, parent }) {
49
+ return this.getInstance('Service').add(object, parent, true);
50
+ }
51
+
52
+ _resetFunction(object) {
53
+ if (object.parent)
54
+ this.getInstance('Service').removeChild(object.parent, object, true);
55
+
56
+ if (object?.type === Urso.types.objects.SPINE) {
57
+ object.setToSetupPose();
58
+ object.stop();
59
+ object.clearListeners();
60
+ object._baseObject.lastTime = null;
61
+ }
62
+
63
+ return object;
64
+ }
65
+
66
+ }
67
+
68
+ module.exports = ModulesObjectsPool;
@@ -62,7 +62,12 @@ class ModulesObjectsService {
62
62
  return this._world;
63
63
  }
64
64
 
65
- add(object, parent) {
65
+ add(object, parent, _ignorePool = false) {
66
+ const { objectsToCache } = this.getInstance('Config');
67
+
68
+ if (!_ignorePool && objectsToCache.includes(object.type))
69
+ return this.getInstance('Pool').getElement(object, parent);
70
+
66
71
  const world = this._checkWorld();
67
72
 
68
73
  if (!parent)
@@ -94,7 +99,7 @@ class ModulesObjectsService {
94
99
  break;
95
100
  case Urso.types.objects.EMITTERFX:
96
101
  model = this.getInstance('Models.EmitterFx', object);
97
- break;
102
+ break;
98
103
  case Urso.types.objects.HITAREA:
99
104
  model = this.getInstance('Models.HitArea', object);
100
105
  break;
@@ -181,6 +186,11 @@ class ModulesObjectsService {
181
186
  }
182
187
 
183
188
  destroy(object, doNotRefreshStylesFlag) {
189
+ const { objectsToCache } = this.getInstance('Config');
190
+
191
+ if (objectsToCache.includes(object.type))
192
+ return this.getInstance('Pool').putElement(object, doNotRefreshStylesFlag);
193
+
184
194
  if (object.parent)
185
195
  this.removeChild(object.parent, object, true);
186
196
 
@@ -191,7 +201,7 @@ class ModulesObjectsService {
191
201
  this.destroy(object.contents[0], true);
192
202
 
193
203
  object._customDestroy();
194
- object._baseObject && object._baseObject.destroy({children: true});
204
+ object._baseObject && object._baseObject.destroy({ children: true });
195
205
  this._removeFromCache(object);
196
206
  this.getInstance('Styles').removeFromCache(object);
197
207