浏览代码

Introduce Session._startMainLoop()

customisations
alemart 7 个月前
父节点
当前提交
49e59a8272
共有 1 个文件被更改,包括 29 次插入16 次删除
  1. 29
    16
      src/core/session.ts

+ 29
- 16
src/core/session.ts 查看文件

178
         else
178
         else
179
             this._viewport._init(() => Utils.resolution('sm', window.innerWidth / window.innerHeight), mode);
179
             this._viewport._init(() => Utils.resolution('sm', window.innerWidth / window.innerHeight), mode);
180
 
180
 
181
-        // setup the main loop
182
-        this._setupUpdateLoop();
183
-        this._setupRenderLoop();
184
-
185
         // setup the stats panel
181
         // setup the stats panel
186
         this._statsPanel = new StatsPanel(this._viewport);
182
         this._statsPanel = new StatsPanel(this._viewport);
187
         this._statsPanel.visible = stats;
183
         this._statsPanel.visible = stats;
188
 
184
 
189
         // done!
185
         // done!
190
         Session._count++;
186
         Session._count++;
191
-        Utils.log(`The ${mode} session is now active!`);
187
+        Utils.log(`The ${this._mode} session is now active!`);
192
     }
188
     }
193
 
189
 
194
     /**
190
     /**
330
 
326
 
331
         }).then(session => {
327
         }).then(session => {
332
 
328
 
333
-            // validate trackers
329
+            // validate the trackers
334
             if(trackers.length == 0)
330
             if(trackers.length == 0)
335
                 Utils.warning(`No trackers have been attached to the session!`);
331
                 Utils.warning(`No trackers have been attached to the session!`);
336
 
332
 
339
                     throw new IllegalArgumentError(`Found repeated trackers`);
335
                     throw new IllegalArgumentError(`Found repeated trackers`);
340
             }
336
             }
341
 
337
 
342
-            // attach trackers and return the session
338
+            // attach the trackers
343
             return Speedy.Promise.all(
339
             return Speedy.Promise.all(
344
                 trackers.map(tracker => session._attachTracker(tracker))
340
                 trackers.map(tracker => session._attachTracker(tracker))
345
-            ).then(() => session).catch(err => { throw err; });
341
+            ).then(() => session);
342
+
343
+        }).then(session => {
344
+
345
+            // start the main loop and return the session
346
+            session._startMainLoop();
347
+            return session;
346
 
348
 
347
         }).catch(err => {
349
         }).catch(err => {
348
 
350
 
502
     }
504
     }
503
 
505
 
504
     /**
506
     /**
507
+     * Start the main loop
508
+     */
509
+    private _startMainLoop(): void
510
+    {
511
+        this._setupUpdateLoop();
512
+        this._setupRenderLoop();
513
+
514
+        Utils.log('The main loop has been started!');
515
+    }
516
+
517
+    /**
505
      * Find the primary source of data (generally a camera stream)
518
      * Find the primary source of data (generally a camera stream)
506
      * @param sources
519
      * @param sources
507
      * @returns the primary source, or null if there isn't any
520
      * @returns the primary source, or null if there isn't any
597
     private _setupUpdateLoop(): void
610
     private _setupUpdateLoop(): void
598
     {
611
     {
599
         const scheduleNextFrame = () => {
612
         const scheduleNextFrame = () => {
600
-            if(this._active) {
601
-                if(Settings.powerPreference == 'high-performance')
602
-                    asap(repeat);
603
-                else
604
-                    window.requestAnimationFrame(repeat);
605
-            }
613
+            if(!this._active)
614
+                return;
615
+            else if(Settings.powerPreference == 'high-performance')
616
+                asap(repeat);
617
+            else
618
+                window.requestAnimationFrame(repeat);
606
         };
619
         };
607
         
620
         
608
         const update = () => {
621
         const update = () => {
675
 
688
 
676
             // skip frames
689
             // skip frames
677
             if(!enableFrameSkipping || !(skip = !skip))
690
             if(!enableFrameSkipping || !(skip = !skip))
678
-                this._render(timestamp, false);
691
+                this._render(timestamp);
679
                 //this._render(timestamp, !enableFrameSkipping && !highPerformance && (toggle = !toggle));
692
                 //this._render(timestamp, !enableFrameSkipping && !highPerformance && (toggle = !toggle));
680
 
693
 
681
             // repeat
694
             // repeat
691
      * @param time current time, in ms
704
      * @param time current time, in ms
692
      * @param skipUserMedia skip copying the pixels of the user media to the background canvas in order to reduce the processing load (video stream is probably at 30fps?)
705
      * @param skipUserMedia skip copying the pixels of the user media to the background canvas in order to reduce the processing load (video stream is probably at 30fps?)
693
      */
706
      */
694
-    private _render(time: DOMHighResTimeStamp, skipUserMedia: boolean): void
707
+    private _render(time: DOMHighResTimeStamp, skipUserMedia: boolean = false): void
695
     {
708
     {
696
         // is the session active?
709
         // is the session active?
697
         if(this._active) {
710
         if(this._active) {

正在加载...
取消
保存