@mulsense/xnew 0.3.4 → 0.3.6

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.
@@ -21,7 +21,7 @@
21
21
  const root = {};
22
22
  xnew.context('xmatter.root', root);
23
23
  root.engine = engine !== null && engine !== void 0 ? engine : Matter.Engine.create();
24
- unit.on('update', () => {
24
+ unit.on('logicupdate', () => {
25
25
  Matter.Engine.update(root.engine);
26
26
  });
27
27
  }
@@ -18,7 +18,7 @@ function Root(unit, { engine }) {
18
18
  const root = {};
19
19
  xnew.context('xmatter.root', root);
20
20
  root.engine = engine !== null && engine !== void 0 ? engine : Matter.Engine.create();
21
- unit.on('update', () => {
21
+ unit.on('logicupdate', () => {
22
22
  Matter.Engine.update(root.engine);
23
23
  });
24
24
  }
@@ -51,20 +51,19 @@
51
51
  return (_a = xnew.context('xpixi.root')) === null || _a === void 0 ? void 0 : _a.canvas;
52
52
  },
53
53
  };
54
- function Root(self, { canvas }) {
54
+ function Root(unit, { canvas }) {
55
55
  const root = {};
56
56
  xnew.context('xpixi.root', root);
57
57
  root.canvas = canvas;
58
- const renderer = PIXI__namespace.autoDetectRenderer({
58
+ root.renderer = null;
59
+ xnew.promise(PIXI__namespace.autoDetectRenderer({
59
60
  width: canvas.width, height: canvas.height, view: canvas,
60
61
  antialias: true, backgroundAlpha: 0,
61
- });
62
- root.renderer = null;
63
- xnew.promise(renderer, false).then((renderer) => root.renderer = renderer);
62
+ })).then((renderer) => root.renderer = renderer);
64
63
  root.updates = [];
65
64
  root.scene = new PIXI__namespace.Container();
66
65
  xnew.context('xpixi.object', root.scene);
67
- self.on('update', () => {
66
+ unit.on('update', () => {
68
67
  root.updates.forEach((update) => {
69
68
  update();
70
69
  });
@@ -73,18 +72,18 @@
73
72
  }
74
73
  });
75
74
  }
76
- function Nest(self, { object }) {
75
+ function Nest(unit, { object }) {
77
76
  const parent = xnew.context('xpixi.object');
78
77
  xnew.context('xpixi.object', object);
79
78
  parent.addChild(object);
80
- self.on('finalize', () => {
79
+ unit.on('finalize', () => {
81
80
  parent.removeChild(object);
82
81
  });
83
82
  }
84
- function PreUpdate(self, callback) {
83
+ function PreUpdate(unit, callback) {
85
84
  const root = xnew.context('xpixi.root');
86
85
  root.updates.push(callback);
87
- self.on('finalize', () => {
86
+ unit.on('finalize', () => {
88
87
  root.updates = root.updates.filter((update) => update !== callback);
89
88
  });
90
89
  }
@@ -29,20 +29,19 @@ var xpixi = {
29
29
  return (_a = xnew.context('xpixi.root')) === null || _a === void 0 ? void 0 : _a.canvas;
30
30
  },
31
31
  };
32
- function Root(self, { canvas }) {
32
+ function Root(unit, { canvas }) {
33
33
  const root = {};
34
34
  xnew.context('xpixi.root', root);
35
35
  root.canvas = canvas;
36
- const renderer = PIXI.autoDetectRenderer({
36
+ root.renderer = null;
37
+ xnew.promise(PIXI.autoDetectRenderer({
37
38
  width: canvas.width, height: canvas.height, view: canvas,
38
39
  antialias: true, backgroundAlpha: 0,
39
- });
40
- root.renderer = null;
41
- xnew.promise(renderer, false).then((renderer) => root.renderer = renderer);
40
+ })).then((renderer) => root.renderer = renderer);
42
41
  root.updates = [];
43
42
  root.scene = new PIXI.Container();
44
43
  xnew.context('xpixi.object', root.scene);
45
- self.on('update', () => {
44
+ unit.on('update', () => {
46
45
  root.updates.forEach((update) => {
47
46
  update();
48
47
  });
@@ -51,18 +50,18 @@ function Root(self, { canvas }) {
51
50
  }
52
51
  });
53
52
  }
54
- function Nest(self, { object }) {
53
+ function Nest(unit, { object }) {
55
54
  const parent = xnew.context('xpixi.object');
56
55
  xnew.context('xpixi.object', object);
57
56
  parent.addChild(object);
58
- self.on('finalize', () => {
57
+ unit.on('finalize', () => {
59
58
  parent.removeChild(object);
60
59
  });
61
60
  }
62
- function PreUpdate(self, callback) {
61
+ function PreUpdate(unit, callback) {
63
62
  const root = xnew.context('xpixi.root');
64
63
  root.updates.push(callback);
65
- self.on('finalize', () => {
64
+ unit.on('finalize', () => {
66
65
  root.updates = root.updates.filter((update) => update !== callback);
67
66
  });
68
67
  }
@@ -1,5 +1,5 @@
1
1
  declare const _default: {
2
- initialize({ gravity, timestep }?: any): void;
2
+ initialize({ gravity }?: any): void;
3
3
  readonly world: any;
4
4
  };
5
5
 
@@ -5,27 +5,22 @@
5
5
  })(this, (function (xnew, RAPIER) { 'use strict';
6
6
 
7
7
  var xrapier2d = {
8
- initialize({ gravity = { x: 0.0, y: 9.81 }, timestep = null } = {}) {
9
- xnew.extend(Root, { gravity, timestep });
8
+ initialize({ gravity = { x: 0.0, y: 9.81 } } = {}) {
9
+ xnew.extend(Root, { gravity });
10
10
  },
11
11
  get world() {
12
12
  var _a;
13
13
  return (_a = xnew.context('xrapier2d.root')) === null || _a === void 0 ? void 0 : _a.world;
14
14
  },
15
15
  };
16
- function Root(self, { gravity, timestep }) {
16
+ function Root(self, { gravity }) {
17
17
  const root = {};
18
18
  xnew.context('xrapier2d.root', root);
19
19
  xnew.promise(RAPIER.init()).then(() => {
20
20
  root.world = new RAPIER.World(gravity);
21
- if (timestep !== null) {
22
- root.world.timestep = timestep;
23
- }
24
21
  });
25
- self.on('update', () => {
26
- if (root.world) {
27
- root.world.step();
28
- }
22
+ self.on('fixedupdate', () => {
23
+ root.world.step();
29
24
  });
30
25
  }
31
26
 
@@ -2,27 +2,22 @@ import xnew from '@mulsense/xnew';
2
2
  import RAPIER from '@dimforge/rapier2d-compat';
3
3
 
4
4
  var xrapier2d = {
5
- initialize({ gravity = { x: 0.0, y: 9.81 }, timestep = null } = {}) {
6
- xnew.extend(Root, { gravity, timestep });
5
+ initialize({ gravity = { x: 0.0, y: 9.81 } } = {}) {
6
+ xnew.extend(Root, { gravity });
7
7
  },
8
8
  get world() {
9
9
  var _a;
10
10
  return (_a = xnew.context('xrapier2d.root')) === null || _a === void 0 ? void 0 : _a.world;
11
11
  },
12
12
  };
13
- function Root(self, { gravity, timestep }) {
13
+ function Root(self, { gravity }) {
14
14
  const root = {};
15
15
  xnew.context('xrapier2d.root', root);
16
16
  xnew.promise(RAPIER.init()).then(() => {
17
17
  root.world = new RAPIER.World(gravity);
18
- if (timestep !== null) {
19
- root.world.timestep = timestep;
20
- }
21
18
  });
22
- self.on('update', () => {
23
- if (root.world) {
24
- root.world.step();
25
- }
19
+ self.on('fixedupdate', () => {
20
+ root.world.step();
26
21
  });
27
22
  }
28
23
 
@@ -1,5 +1,5 @@
1
1
  declare const _default: {
2
- initialize({ gravity, timestep }?: any): void;
2
+ initialize({ gravity }?: any): void;
3
3
  readonly world: any;
4
4
  };
5
5
 
@@ -5,27 +5,22 @@
5
5
  })(this, (function (xnew, RAPIER) { 'use strict';
6
6
 
7
7
  var xrapier3d = {
8
- initialize({ gravity = { x: 0.0, y: 9.81, z: 0.0 }, timestep = null } = {}) {
9
- xnew.extend(Root, { gravity, timestep });
8
+ initialize({ gravity = { x: 0.0, y: 9.81, z: 0.0 } } = {}) {
9
+ xnew.extend(Root, { gravity });
10
10
  },
11
11
  get world() {
12
12
  var _a;
13
13
  return (_a = xnew.context('xrapier3d.root')) === null || _a === void 0 ? void 0 : _a.world;
14
14
  },
15
15
  };
16
- function Root(self, { gravity, timestep }) {
16
+ function Root(self, { gravity }) {
17
17
  const root = {};
18
18
  xnew.context('xrapier3d.root', root);
19
19
  xnew.promise(RAPIER.init()).then(() => {
20
20
  root.world = new RAPIER.World(gravity);
21
- if (timestep !== null) {
22
- root.world.timestep = timestep;
23
- }
24
21
  });
25
- self.on('update', () => {
26
- if (root.world) {
27
- root.world.step();
28
- }
22
+ self.on('logicupdate', () => {
23
+ root.world.step();
29
24
  });
30
25
  }
31
26
 
@@ -2,27 +2,22 @@ import xnew from '@mulsense/xnew';
2
2
  import RAPIER from '@dimforge/rapier3d-compat';
3
3
 
4
4
  var xrapier3d = {
5
- initialize({ gravity = { x: 0.0, y: 9.81, z: 0.0 }, timestep = null } = {}) {
6
- xnew.extend(Root, { gravity, timestep });
5
+ initialize({ gravity = { x: 0.0, y: 9.81, z: 0.0 } } = {}) {
6
+ xnew.extend(Root, { gravity });
7
7
  },
8
8
  get world() {
9
9
  var _a;
10
10
  return (_a = xnew.context('xrapier3d.root')) === null || _a === void 0 ? void 0 : _a.world;
11
11
  },
12
12
  };
13
- function Root(self, { gravity, timestep }) {
13
+ function Root(self, { gravity }) {
14
14
  const root = {};
15
15
  xnew.context('xrapier3d.root', root);
16
16
  xnew.promise(RAPIER.init()).then(() => {
17
17
  root.world = new RAPIER.World(gravity);
18
- if (timestep !== null) {
19
- root.world.timestep = timestep;
20
- }
21
18
  });
22
- self.on('update', () => {
23
- if (root.world) {
24
- root.world.step();
25
- }
19
+ self.on('logicupdate', () => {
20
+ root.world.step();
26
21
  });
27
22
  }
28
23
 
@@ -64,12 +64,10 @@
64
64
  function Nest(unit, { object }) {
65
65
  const parent = xnew.context('xthree.object');
66
66
  xnew.context('xthree.object', object);
67
- if (parent) {
68
- parent === null || parent === void 0 ? void 0 : parent.add(object);
69
- unit.on('finalize', () => {
70
- parent === null || parent === void 0 ? void 0 : parent.remove(object);
71
- });
72
- }
67
+ parent.add(object);
68
+ unit.on('finalize', () => {
69
+ parent.remove(object);
70
+ });
73
71
  }
74
72
 
75
73
  return xthree;
@@ -42,12 +42,10 @@ function Root(unit, { canvas, camera }) {
42
42
  function Nest(unit, { object }) {
43
43
  const parent = xnew.context('xthree.object');
44
44
  xnew.context('xthree.object', object);
45
- if (parent) {
46
- parent === null || parent === void 0 ? void 0 : parent.add(object);
47
- unit.on('finalize', () => {
48
- parent === null || parent === void 0 ? void 0 : parent.remove(object);
49
- });
50
- }
45
+ parent.add(object);
46
+ unit.on('finalize', () => {
47
+ parent.remove(object);
48
+ });
51
49
  }
52
50
 
53
51
  export { xthree as default };
package/dist/xnew.d.ts CHANGED
@@ -81,6 +81,7 @@ declare class Unit {
81
81
  static start(unit: Unit): void;
82
82
  static stop(unit: Unit): void;
83
83
  static update(unit: Unit): void;
84
+ static logicupdate(unit: Unit): void;
84
85
  static root: Unit;
85
86
  static current: Unit;
86
87
  static ticker: Ticker;