targetj 1.1.3 → 1.1.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/build/App.js +37 -12
- package/build/ParticleExplode.js +10 -7
- package/build/ParticleRenderer.js +20 -27
- package/build/ParticleTModel.js +28 -15
- package/build/ScheduleUtil.js +161 -0
- package/build/TUtil.js +71 -155
- package/build/TargetManager.js +1 -1
- package/build/TargetParser.js +12 -3
- package/dist/targetjs.js +1 -1
- package/dist/targetjs.js.gz +0 -0
- package/package.json +1 -1
package/build/App.js
CHANGED
|
@@ -28,6 +28,7 @@ import { TModelUtil } from "./TModelUtil.js";
|
|
|
28
28
|
import "./ParticleTModel.js";
|
|
29
29
|
var tApp;
|
|
30
30
|
var queuedAppCalls = [];
|
|
31
|
+
var appStarting = false;
|
|
31
32
|
var AppFn = function AppFn() {
|
|
32
33
|
var my = {};
|
|
33
34
|
my.throttle = 0;
|
|
@@ -250,12 +251,10 @@ var App = function App(firstChild) {
|
|
|
250
251
|
}
|
|
251
252
|
var tmodel = firstChild instanceof TModel ? firstChild : TargetExecutor.createTModel("App", firstChild);
|
|
252
253
|
if (!((_tApp2 = tApp) !== null && _tApp2 !== void 0 && _tApp2.tRoot)) {
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
254
|
+
queuedAppCalls.push(tmodel);
|
|
255
|
+
if (document.readyState !== "loading") {
|
|
256
|
+
ensureRunning();
|
|
256
257
|
}
|
|
257
|
-
ensureRunning();
|
|
258
|
-
tApp.tRoot.addChild(tmodel);
|
|
259
258
|
return tmodel;
|
|
260
259
|
}
|
|
261
260
|
tApp.tRoot.addChild(tmodel);
|
|
@@ -400,13 +399,39 @@ var getDomTModelById = function getDomTModelById(id) {
|
|
|
400
399
|
if (typeof window !== "undefined") {
|
|
401
400
|
window.t = window.t || getTModelById;
|
|
402
401
|
}
|
|
403
|
-
var runApp = function
|
|
404
|
-
|
|
405
|
-
return
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
402
|
+
var runApp = /*#__PURE__*/function () {
|
|
403
|
+
var _ref8 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
|
|
404
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
405
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
406
|
+
case 0:
|
|
407
|
+
if (!(tApp || appStarting)) {
|
|
408
|
+
_context5.next = 2;
|
|
409
|
+
break;
|
|
410
|
+
}
|
|
411
|
+
return _context5.abrupt("return");
|
|
412
|
+
case 2:
|
|
413
|
+
appStarting = true;
|
|
414
|
+
_context5.prev = 3;
|
|
415
|
+
_context5.next = 6;
|
|
416
|
+
return TUtil.initWebGpu();
|
|
417
|
+
case 6:
|
|
418
|
+
tApp = AppFn();
|
|
419
|
+
_context5.next = 9;
|
|
420
|
+
return tApp.init().start();
|
|
421
|
+
case 9:
|
|
422
|
+
_context5.prev = 9;
|
|
423
|
+
appStarting = false;
|
|
424
|
+
return _context5.finish(9);
|
|
425
|
+
case 12:
|
|
426
|
+
case "end":
|
|
427
|
+
return _context5.stop();
|
|
428
|
+
}
|
|
429
|
+
}, _callee5, null, [[3,, 9, 12]]);
|
|
430
|
+
}));
|
|
431
|
+
return function runApp() {
|
|
432
|
+
return _ref8.apply(this, arguments);
|
|
433
|
+
};
|
|
434
|
+
}();
|
|
410
435
|
if (typeof document !== "undefined") {
|
|
411
436
|
if (document.readyState === "loading") {
|
|
412
437
|
document.addEventListener("DOMContentLoaded", runApp);
|
package/build/ParticleExplode.js
CHANGED
|
@@ -39,7 +39,8 @@ var ParticleExplode = /*#__PURE__*/function () {
|
|
|
39
39
|
return !(typeof color === 'string' && color.trim() !== '');
|
|
40
40
|
};
|
|
41
41
|
var target = (_tmodel$targets$key = tmodel.targets[key]) !== null && _tmodel$targets$key !== void 0 ? _tmodel$targets$key : {};
|
|
42
|
-
var
|
|
42
|
+
var requestedRenderer = (_target$renderer = target.renderer) !== null && _target$renderer !== void 0 ? _target$renderer : "gpu";
|
|
43
|
+
var renderer = requestedRenderer === "gpu" && !TUtil.webGpuAvailable ? "dom" : requestedRenderer;
|
|
43
44
|
if (renderer !== "gpu" && renderer !== "dom") {
|
|
44
45
|
throw new Error("Unsupported explodeChildren renderer: ".concat(renderer));
|
|
45
46
|
}
|
|
@@ -80,7 +81,12 @@ var ParticleExplode = /*#__PURE__*/function () {
|
|
|
80
81
|
fragments: []
|
|
81
82
|
};
|
|
82
83
|
var planned = [];
|
|
83
|
-
var maxFragments = 20000;
|
|
84
|
+
var maxFragments = renderer === "gpu" ? 20000 : 300;
|
|
85
|
+
var autoDomGrid = renderer === "dom" && requestedRenderer === "gpu" && requestedCount === undefined;
|
|
86
|
+
var domColumns = autoDomGrid ? Math.max(1, Math.min(maxFragments, Math.floor(Math.sqrt(maxFragments * uiWidth / uiHeight)))) : 0;
|
|
87
|
+
var domRows = autoDomGrid ? Math.max(1, Math.floor(maxFragments / domColumns)) : 0;
|
|
88
|
+
var domWidth = autoDomGrid ? Math.ceil(uiWidth / domColumns) : 0;
|
|
89
|
+
var domHeight = autoDomGrid ? Math.ceil(uiHeight / domRows) : 0;
|
|
84
90
|
var epsilon = 1e-7;
|
|
85
91
|
var nextX = 0;
|
|
86
92
|
var rowY = 0;
|
|
@@ -88,16 +94,13 @@ var ParticleExplode = /*#__PURE__*/function () {
|
|
|
88
94
|
while (requestedCount === undefined ? rowY < uiHeight - epsilon : planned.length < requestedCount) {
|
|
89
95
|
var _raw$width, _raw$height, _raw$isInFlow;
|
|
90
96
|
var index = planned.length;
|
|
91
|
-
if (index >= maxFragments) {
|
|
92
|
-
throw new RangeError("explodeChildren exceeded ".concat(maxFragments, " fragments. Specify instances or larger dimensions."));
|
|
93
|
-
}
|
|
94
97
|
var raw = valueFactory ? valueFactory.call(tmodel, index) : sharedDefinition !== null && sharedDefinition !== void 0 ? sharedDefinition : {};
|
|
95
98
|
if (!raw || _typeof(raw) !== "object" || Array.isArray(raw)) {
|
|
96
99
|
throw new TypeError("explodeChildren.value(".concat(index, ") must return a child definition object."));
|
|
97
100
|
}
|
|
98
101
|
var childDefinition = TUtil.cloneTargetDefinition(_objectSpread(_objectSpread({}, raw), {}, {
|
|
99
|
-
width: (_raw$width = raw.width) !== null && _raw$width !== void 0 ? _raw$width : 20,
|
|
100
|
-
height: (_raw$height = raw.height) !== null && _raw$height !== void 0 ? _raw$height : 20,
|
|
102
|
+
width: autoDomGrid ? domWidth : (_raw$width = raw.width) !== null && _raw$width !== void 0 ? _raw$width : 20,
|
|
103
|
+
height: autoDomGrid ? domHeight : (_raw$height = raw.height) !== null && _raw$height !== void 0 ? _raw$height : 20,
|
|
101
104
|
isInFlow: (_raw$isInFlow = raw.isInFlow) !== null && _raw$isInFlow !== void 0 ? _raw$isInFlow : false
|
|
102
105
|
}));
|
|
103
106
|
var requestedWidth = resolveDimension("width", childDefinition.width, index);
|
|
@@ -64,30 +64,29 @@ var ParticleRenderer = /*#__PURE__*/function () {
|
|
|
64
64
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
65
65
|
while (1) switch (_context.prev = _context.next) {
|
|
66
66
|
case 0:
|
|
67
|
-
if (!this.device) {
|
|
68
|
-
_context.next =
|
|
67
|
+
if (!(this.device && this.context && this.pipeline && this.bindGroup)) {
|
|
68
|
+
_context.next = 2;
|
|
69
69
|
break;
|
|
70
70
|
}
|
|
71
|
-
this.mountCanvasLayer();
|
|
72
|
-
|
|
73
|
-
case 3:
|
|
71
|
+
return _context.abrupt("return", this.mountCanvasLayer());
|
|
72
|
+
case 2:
|
|
74
73
|
if (this.tmodel.hasDom()) {
|
|
75
|
-
_context.next =
|
|
74
|
+
_context.next = 4;
|
|
76
75
|
break;
|
|
77
76
|
}
|
|
78
77
|
return _context.abrupt("return", false);
|
|
79
|
-
case
|
|
78
|
+
case 4:
|
|
80
79
|
if (!this.initializationPromise) {
|
|
81
80
|
this.initializationPromise = this.initialize().catch(function (error) {
|
|
82
81
|
_this.initializationPromise = undefined;
|
|
83
82
|
throw error;
|
|
84
83
|
});
|
|
85
84
|
}
|
|
86
|
-
_context.next =
|
|
85
|
+
_context.next = 7;
|
|
87
86
|
return this.initializationPromise;
|
|
87
|
+
case 7:
|
|
88
|
+
return _context.abrupt("return", !!(this.device && this.context && this.pipeline && this.bindGroup));
|
|
88
89
|
case 8:
|
|
89
|
-
return _context.abrupt("return", !!this.device);
|
|
90
|
-
case 9:
|
|
91
90
|
case "end":
|
|
92
91
|
return _context.stop();
|
|
93
92
|
}
|
|
@@ -106,40 +105,34 @@ var ParticleRenderer = /*#__PURE__*/function () {
|
|
|
106
105
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
107
106
|
while (1) switch (_context2.prev = _context2.next) {
|
|
108
107
|
case 0:
|
|
109
|
-
if (
|
|
108
|
+
if (TUtil.webGpuAvailable) {
|
|
110
109
|
_context2.next = 2;
|
|
111
110
|
break;
|
|
112
111
|
}
|
|
113
|
-
throw new Error("WebGPU is not
|
|
112
|
+
throw new Error("WebGPU is not available.");
|
|
114
113
|
case 2:
|
|
115
|
-
if (globalThis.GPUBufferUsage) {
|
|
116
|
-
_context2.next = 4;
|
|
117
|
-
break;
|
|
118
|
-
}
|
|
119
|
-
throw new Error("GPUBufferUsage is not available in this WebGPU environment.");
|
|
120
|
-
case 4:
|
|
121
114
|
this.createCanvas();
|
|
122
|
-
_context2.next =
|
|
115
|
+
_context2.next = 5;
|
|
123
116
|
return navigator.gpu.requestAdapter();
|
|
124
|
-
case
|
|
117
|
+
case 5:
|
|
125
118
|
adapter = _context2.sent;
|
|
126
119
|
if (adapter) {
|
|
127
|
-
_context2.next =
|
|
120
|
+
_context2.next = 8;
|
|
128
121
|
break;
|
|
129
122
|
}
|
|
130
123
|
throw new Error("Unable to obtain a WebGPU adapter.");
|
|
131
|
-
case
|
|
132
|
-
_context2.next =
|
|
124
|
+
case 8:
|
|
125
|
+
_context2.next = 10;
|
|
133
126
|
return adapter.requestDevice();
|
|
134
|
-
case
|
|
127
|
+
case 10:
|
|
135
128
|
this.device = _context2.sent;
|
|
136
129
|
this.context = this.canvas.getContext("webgpu");
|
|
137
130
|
if (this.context) {
|
|
138
|
-
_context2.next =
|
|
131
|
+
_context2.next = 14;
|
|
139
132
|
break;
|
|
140
133
|
}
|
|
141
134
|
throw new Error("Unable to obtain a WebGPU canvas context.");
|
|
142
|
-
case
|
|
135
|
+
case 14:
|
|
143
136
|
this.format = navigator.gpu.getPreferredCanvasFormat();
|
|
144
137
|
this.resizeCanvas();
|
|
145
138
|
this.context.configure({
|
|
@@ -151,7 +144,7 @@ var ParticleRenderer = /*#__PURE__*/function () {
|
|
|
151
144
|
this.createUniformBuffer();
|
|
152
145
|
this.createExplodeResources();
|
|
153
146
|
this.createPipeline();
|
|
154
|
-
case
|
|
147
|
+
case 20:
|
|
155
148
|
case "end":
|
|
156
149
|
return _context2.stop();
|
|
157
150
|
}
|
package/build/ParticleTModel.js
CHANGED
|
@@ -210,7 +210,7 @@ var ParticleTModel = /*#__PURE__*/function (_TModel) {
|
|
|
210
210
|
key: "syncParticleRendererNow",
|
|
211
211
|
value: function () {
|
|
212
212
|
var _syncParticleRendererNow = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
213
|
-
var key, targetName, transition, applied;
|
|
213
|
+
var ready, key, targetName, transition, applied;
|
|
214
214
|
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
215
215
|
while (1) switch (_context3.prev = _context3.next) {
|
|
216
216
|
case 0:
|
|
@@ -221,42 +221,52 @@ var ParticleTModel = /*#__PURE__*/function (_TModel) {
|
|
|
221
221
|
return _context3.abrupt("return", false);
|
|
222
222
|
case 2:
|
|
223
223
|
if (!this.childHandles.length) {
|
|
224
|
-
_context3.next =
|
|
224
|
+
_context3.next = 8;
|
|
225
225
|
break;
|
|
226
226
|
}
|
|
227
227
|
_context3.next = 5;
|
|
228
228
|
return this.particleRenderer.setParticles(this.childHandles);
|
|
229
229
|
case 5:
|
|
230
|
-
_context3.
|
|
230
|
+
_context3.t0 = _context3.sent;
|
|
231
|
+
_context3.next = 11;
|
|
231
232
|
break;
|
|
232
|
-
case
|
|
233
|
-
_context3.next =
|
|
233
|
+
case 8:
|
|
234
|
+
_context3.next = 10;
|
|
234
235
|
return this.particleRenderer.init();
|
|
235
|
-
case
|
|
236
|
+
case 10:
|
|
237
|
+
_context3.t0 = _context3.sent;
|
|
238
|
+
case 11:
|
|
239
|
+
ready = _context3.t0;
|
|
240
|
+
if (ready) {
|
|
241
|
+
_context3.next = 14;
|
|
242
|
+
break;
|
|
243
|
+
}
|
|
244
|
+
return _context3.abrupt("return", false);
|
|
245
|
+
case 14:
|
|
236
246
|
key = this.activeChildTransitionKey;
|
|
237
247
|
if (key) {
|
|
238
|
-
_context3.next =
|
|
248
|
+
_context3.next = 17;
|
|
239
249
|
break;
|
|
240
250
|
}
|
|
241
251
|
return _context3.abrupt("return", true);
|
|
242
|
-
case
|
|
252
|
+
case 17:
|
|
243
253
|
targetName = TargetUtil.getTargetName(key);
|
|
244
254
|
transition = this.childTransitions[targetName];
|
|
245
255
|
if (transition) {
|
|
246
|
-
_context3.next =
|
|
256
|
+
_context3.next = 21;
|
|
247
257
|
break;
|
|
248
258
|
}
|
|
249
259
|
return _context3.abrupt("return", true);
|
|
250
|
-
case
|
|
251
|
-
_context3.next =
|
|
260
|
+
case 21:
|
|
261
|
+
_context3.next = 23;
|
|
252
262
|
return this.particleRenderer.setTargetParticles(transition.values, transition.steps, transition.generation);
|
|
253
|
-
case
|
|
263
|
+
case 23:
|
|
254
264
|
applied = _context3.sent;
|
|
255
265
|
if (applied && this.childTransitions[targetName] === transition) {
|
|
256
266
|
this.handleSpecialTargetStep(key);
|
|
257
267
|
}
|
|
258
|
-
return _context3.abrupt("return",
|
|
259
|
-
case
|
|
268
|
+
return _context3.abrupt("return", applied);
|
|
269
|
+
case 26:
|
|
260
270
|
case "end":
|
|
261
271
|
return _context3.stop();
|
|
262
272
|
}
|
|
@@ -307,6 +317,9 @@ var ParticleTModel = /*#__PURE__*/function (_TModel) {
|
|
|
307
317
|
}, {
|
|
308
318
|
key: "getChildrenRenderer",
|
|
309
319
|
value: function getChildrenRenderer() {
|
|
320
|
+
if (!TUtil.webGpuAvailable) {
|
|
321
|
+
return "dom";
|
|
322
|
+
}
|
|
310
323
|
var target = this.targets[TargetUtil.currentTargetName];
|
|
311
324
|
return (target === null || target === void 0 ? void 0 : target.renderer) || "auto";
|
|
312
325
|
}
|
|
@@ -1579,7 +1592,7 @@ var ParticleTModel = /*#__PURE__*/function (_TModel) {
|
|
|
1579
1592
|
}]);
|
|
1580
1593
|
}(TModel);
|
|
1581
1594
|
function isParticleTModel(targets) {
|
|
1582
|
-
if (!targets) {
|
|
1595
|
+
if (!targets || !TUtil.webGpuAvailable) {
|
|
1583
1596
|
return false;
|
|
1584
1597
|
}
|
|
1585
1598
|
for (var _i14 = 0, _Object$entries7 = Object.entries(targets); _i14 < _Object$entries7.length; _i14++) {
|
package/build/ScheduleUtil.js
CHANGED
|
@@ -17,6 +17,7 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
|
|
|
17
17
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
18
18
|
import { TUtil } from "./TUtil.js";
|
|
19
19
|
import { getRunScheduler, getAnimationManager } from "./App.js";
|
|
20
|
+
import { TargetUtil } from "./TargetUtil.js";
|
|
20
21
|
|
|
21
22
|
/**
|
|
22
23
|
*
|
|
@@ -172,6 +173,166 @@ var ScheduleUtil = /*#__PURE__*/function () {
|
|
|
172
173
|
}
|
|
173
174
|
return false;
|
|
174
175
|
}
|
|
176
|
+
}, {
|
|
177
|
+
key: "advanceTargetByElapsed",
|
|
178
|
+
value: function advanceTargetByElapsed(tmodel, key) {
|
|
179
|
+
var _targetValue$valueLis2;
|
|
180
|
+
var targetValue = tmodel.targetValues[key];
|
|
181
|
+
if (!targetValue) {
|
|
182
|
+
return {
|
|
183
|
+
step: 0,
|
|
184
|
+
cycle: 0,
|
|
185
|
+
valuePointer: 1,
|
|
186
|
+
done: false
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
if (!TUtil.isDefined(targetValue.catchupAt)) {
|
|
190
|
+
var _targetValue$valueLis;
|
|
191
|
+
var step = tmodel.getTargetStep(key);
|
|
192
|
+
var valuePointer = (_targetValue$valueLis = targetValue.valueList) !== null && _targetValue$valueLis !== void 0 && _targetValue$valueLis.length ? tmodel.getValueListPointer(key) : 0;
|
|
193
|
+
return {
|
|
194
|
+
step: step,
|
|
195
|
+
cycle: tmodel.getTargetCycle(key),
|
|
196
|
+
valuePointer: valuePointer,
|
|
197
|
+
done: !TargetUtil.isTargetUpdating(tmodel, key)
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
var now = TUtil.now();
|
|
201
|
+
var elapsedMs = now - targetValue.catchupAt;
|
|
202
|
+
var progress = (_targetValue$valueLis2 = targetValue.valueList) !== null && _targetValue$valueLis2 !== void 0 && _targetValue$valueLis2.length ? ScheduleUtil.advanceValueListTargetByElapsed(tmodel, key, elapsedMs) : ScheduleUtil.advanceSimpleTargetByElapsed(tmodel, key, elapsedMs);
|
|
203
|
+
if (!progress.done) {
|
|
204
|
+
targetValue.catchupAt = now - progress.remainingMs;
|
|
205
|
+
}
|
|
206
|
+
return progress;
|
|
207
|
+
}
|
|
208
|
+
}, {
|
|
209
|
+
key: "advanceSimpleTargetByElapsed",
|
|
210
|
+
value: function advanceSimpleTargetByElapsed(tmodel, key, elapsedMs) {
|
|
211
|
+
var steps = tmodel.getTargetSteps(key);
|
|
212
|
+
var interval = tmodel.getTargetInterval(key) || 8;
|
|
213
|
+
var cycles = tmodel.getTargetCycles(key);
|
|
214
|
+
var step = tmodel.getTargetStep(key);
|
|
215
|
+
var cycle = tmodel.getTargetCycle(key);
|
|
216
|
+
var remainingMs = elapsedMs;
|
|
217
|
+
if (steps <= 0) {
|
|
218
|
+
return {
|
|
219
|
+
step: steps,
|
|
220
|
+
valuePointer: 0,
|
|
221
|
+
cycle: cycles,
|
|
222
|
+
done: true,
|
|
223
|
+
remainingMs: 0
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
while (remainingMs > 0 && cycle < cycles) {
|
|
227
|
+
var remainingSteps = Math.max(steps - step, 0);
|
|
228
|
+
var remainingSegmentMs = remainingSteps * interval;
|
|
229
|
+
if (remainingMs >= remainingSegmentMs) {
|
|
230
|
+
remainingMs -= remainingSegmentMs;
|
|
231
|
+
cycle++;
|
|
232
|
+
if (cycle >= cycles) {
|
|
233
|
+
return {
|
|
234
|
+
step: steps,
|
|
235
|
+
valuePointer: 0,
|
|
236
|
+
cycle: cycles,
|
|
237
|
+
done: true,
|
|
238
|
+
remainingMs: remainingMs
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
step = 0;
|
|
242
|
+
continue;
|
|
243
|
+
}
|
|
244
|
+
var advancedSteps = TUtil.limit(Math.floor(remainingMs / interval), 0, remainingSteps);
|
|
245
|
+
step += advancedSteps;
|
|
246
|
+
remainingMs -= advancedSteps * interval;
|
|
247
|
+
return {
|
|
248
|
+
step: step,
|
|
249
|
+
steps: steps,
|
|
250
|
+
valuePointer: 0,
|
|
251
|
+
cycle: cycle,
|
|
252
|
+
done: false,
|
|
253
|
+
remainingMs: remainingMs
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
return {
|
|
257
|
+
step: step,
|
|
258
|
+
steps: steps,
|
|
259
|
+
valuePointer: 0,
|
|
260
|
+
cycle: cycle,
|
|
261
|
+
done: cycle >= cycles,
|
|
262
|
+
remainingMs: remainingMs
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
}, {
|
|
266
|
+
key: "advanceValueListTargetByElapsed",
|
|
267
|
+
value: function advanceValueListTargetByElapsed(tmodel, key, elapsedMs) {
|
|
268
|
+
var targetValue = tmodel.targetValues[key];
|
|
269
|
+
var valueList = targetValue.valueList;
|
|
270
|
+
var stepList = targetValue.stepList || [1];
|
|
271
|
+
var intervalList = targetValue.intervalList || [targetValue.interval || 8];
|
|
272
|
+
var cycles = tmodel.getTargetCycles(key);
|
|
273
|
+
var cycle = tmodel.getTargetCycle(key);
|
|
274
|
+
var valuePointer = tmodel.getValueListPointer(key);
|
|
275
|
+
var step = tmodel.getTargetStep(key);
|
|
276
|
+
var remainingMs = elapsedMs;
|
|
277
|
+
while (cycle < cycles) {
|
|
278
|
+
while (remainingMs > 0 && valuePointer < valueList.length) {
|
|
279
|
+
var segmentSteps = stepList[(valuePointer - 1) % stepList.length];
|
|
280
|
+
var interval = intervalList[(valuePointer - 1) % intervalList.length] || 8;
|
|
281
|
+
step = TUtil.limit(step, 0, segmentSteps);
|
|
282
|
+
var remainingSteps = Math.max(segmentSteps - step, 0);
|
|
283
|
+
var remainingSegmentMs = remainingSteps * interval;
|
|
284
|
+
if (remainingMs >= remainingSegmentMs) {
|
|
285
|
+
remainingMs -= remainingSegmentMs;
|
|
286
|
+
valuePointer++;
|
|
287
|
+
step = 0;
|
|
288
|
+
continue;
|
|
289
|
+
}
|
|
290
|
+
var advancedSteps = TUtil.limit(Math.floor(remainingMs / interval), 0, remainingSteps);
|
|
291
|
+
step += advancedSteps;
|
|
292
|
+
remainingMs -= advancedSteps * interval;
|
|
293
|
+
return {
|
|
294
|
+
step: step,
|
|
295
|
+
steps: segmentSteps,
|
|
296
|
+
valuePointer: valuePointer,
|
|
297
|
+
cycle: cycle,
|
|
298
|
+
done: false,
|
|
299
|
+
remainingMs: remainingMs
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
if (valuePointer >= valueList.length) {
|
|
303
|
+
cycle++;
|
|
304
|
+
if (cycle >= cycles) {
|
|
305
|
+
var finalPointer = valueList.length;
|
|
306
|
+
var finalStepIndex = Math.max(0, valueList.length - 2);
|
|
307
|
+
var finalSteps = stepList[finalStepIndex % stepList.length];
|
|
308
|
+
return {
|
|
309
|
+
step: finalSteps,
|
|
310
|
+
steps: finalSteps,
|
|
311
|
+
valuePointer: finalPointer,
|
|
312
|
+
cycle: cycles,
|
|
313
|
+
done: true,
|
|
314
|
+
remainingMs: remainingMs
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
valuePointer = 1;
|
|
318
|
+
step = 0;
|
|
319
|
+
if (remainingMs <= 0) {
|
|
320
|
+
break;
|
|
321
|
+
}
|
|
322
|
+
continue;
|
|
323
|
+
}
|
|
324
|
+
break;
|
|
325
|
+
}
|
|
326
|
+
var currentSteps = stepList[(valuePointer - 1) % stepList.length];
|
|
327
|
+
return {
|
|
328
|
+
step: step,
|
|
329
|
+
steps: currentSteps,
|
|
330
|
+
valuePointer: valuePointer,
|
|
331
|
+
cycle: cycle,
|
|
332
|
+
remainingMs: remainingMs,
|
|
333
|
+
done: cycle >= cycles
|
|
334
|
+
};
|
|
335
|
+
}
|
|
175
336
|
}]);
|
|
176
337
|
}();
|
|
177
338
|
export { ScheduleUtil };
|