gemercheung 3 tahun lalu
induk
melakukan
78d9551c4b
3 mengubah file dengan 60 tambahan dan 35 penghapusan
  1. 43 20
      src/move/move.service.ts
  2. 2 2
      src/rotate/rotate.service.ts
  3. 15 13
      src/scene/scene.service.ts

+ 43 - 20
src/move/move.service.ts

@@ -154,28 +154,47 @@ export class MoveService {
       const traceIds = [];
       traceIds.push(traceId);
 
+      debugger;
       //纠正,旋转传到缓存里
       const checkReplys = [];
       // console.log('矫正: ' + angle + ' 度');
-      for (let i = 0; i < angle; ++i) {
-        // console.warn('矫正一次:' + i);
-        const reply = await this.rotateService.rotateForAngle(userId, 1);
-        // console.warn(
-        //   '矫正:' + reply.newUserStates[0].playerState.camera.angle.yaw,
-        // );
-        reply.traceIds = [];
-        reply.traceIds.push(traceId);
-        const actionResponse = this.rotateService.createActionResponse(
-          actionType,
-          traceId,
-        );
-        reply.actionResponses = [];
-        reply.actionResponses.push(actionResponse);
-        checkReplys.push(reply);
+      if(angle>22){
+        for (let i = 0; i < angle; ++i) {
+          // console.warn('矫正一次:' + i);
+          const reply = await this.rotateService.rotateForAngle(userId, 1);
+          // console.warn(
+          //   '矫正:' + reply.newUserStates[0].playerState.camera.angle.yaw,
+          // );
+          reply.traceIds = [];
+          reply.traceIds.push(traceId);
+          const actionResponse = this.rotateService.createActionResponse(
+            actionType,
+            traceId,
+          );
+          reply.actionResponses = [];
+          reply.actionResponses.push(actionResponse);
+          checkReplys.push(reply);
+        }
+      }else{
+        for (let i = angle; i >-1; --i) {
+          // console.warn('矫正一次:' + i);
+          const reply = await this.rotateService.rotateForAngle(userId, -1);
+          // console.warn(
+          //   '矫正:' + reply.newUserStates[0].playerState.camera.angle.yaw,
+          // );
+          reply.traceIds = [];
+          reply.traceIds.push(traceId);
+          const actionResponse = this.rotateService.createActionResponse(
+            actionType,
+            traceId,
+          );
+          reply.actionResponses = [];
+          reply.actionResponses.push(actionResponse);
+          checkReplys.push(reply);
+        }
       }
       //replys['P' + user.breakPointId + 'T' + user.breakPointId] = checkReplys;
       replys.push(checkReplys);
-
       //过渡传到缓存里
       this.reply.traceIds = traceIds;
       this.reply['newUserStates'][0].userId = userId;
@@ -219,6 +238,7 @@ export class MoveService {
         );
         const endBreakPoint = JSON.parse(endBreakPointRes);
         pathReplys = this.createCacheReplys(
+          appId,
           moveFrames,
           traceId,
           userId,
@@ -242,6 +262,7 @@ export class MoveService {
   }
 
   createCacheReplys(
+    appId,
     moveFrames,
     traceId,
     userId,
@@ -294,7 +315,7 @@ export class MoveService {
 
       reply.mediaSrc =
         '/' +
-        '0000000001' +
+        appId +
         '/' +
         breakPointId +
         '/' +
@@ -419,7 +440,7 @@ export class MoveService {
     reply['actionResponses'][0].traceId = traceId;
     reply.mediaSrc =
       '/' +
-      '0000000001' +
+      appId +
       '/' +
       breakPointId +
       '/' +
@@ -443,7 +464,7 @@ export class MoveService {
       const breakPointId = user.breakPointId;
       const appId = user.appId;
       //只是移动人物
-      if (dir_action.speed_level < 7) {
+      if (dir_action.speed_level < 9) {
         user.player.angle.yaw = dir_action.move_angle;
         this.reply['newUserStates'][0]['userId'] = userId;
         this.reply['newUserStates'][0].playerState.player.position =
@@ -472,7 +493,7 @@ export class MoveService {
         const redisData = JSON.parse(redisDataRes);
         this.reply.mediaSrc =
           '/' +
-          '0000000001' +
+          appId +
           '/' +
           breakPointId +
           '/' +
@@ -481,6 +502,7 @@ export class MoveService {
           redisData.fileName +
           '?m=' +
           new Date().getTime();
+          console.log('人物旋转:'+user.player.angle.yaw);
         return this.reply;
       }
       //选择过渡
@@ -577,6 +599,7 @@ export class MoveService {
           const endBreakPoint = JSON.parse(endBreakPointRes);
 
           const pathReplys = this.createCacheReplys(
+            appId,
             moveFrames,
             traceId,
             userId,

+ 2 - 2
src/rotate/rotate.service.ts

@@ -286,7 +286,7 @@ export class RotateService {
       // debugger
       reply.mediaSrc =
         '/' +
-        '0000000001' +
+        user.appId +
         '/' +
         user.breakPointId +
         '/' +
@@ -445,7 +445,7 @@ export class RotateService {
       const value = redisData ? JSON.parse(redisData) : null;
       reply.mediaSrc =
         '/' +
-        '0000000001' +
+        user.appId +
         '/' +
         user.breakPointId +
         '/' +

+ 15 - 13
src/scene/scene.service.ts

@@ -56,7 +56,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
   private joystickSub: any;
 
   private streamServiceSub: any;
-  private roQueue: RxQueue = new DelayQueue(10);
+  private roQueue: RxQueue = new DelayQueue(40);
   private clickQueue: RxQueue = new DebounceQueue(500);
   private moveQueue: RxQueue = new DelayQueue(10);
   private joystickQueue: RxQueue = new DebounceQueue(500);
@@ -250,16 +250,16 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
         if (redisMeta && 'mediaSrc' in redisMeta) {
           const mediaSrc: string = redisMeta.mediaSrc || '';
           if (mediaSrc.length > 0) {
-            let src = mediaSrc.split('?')[0];
+            const src = mediaSrc.split('?')[0];
             // 临时本地替换路经
-            src = src.replace('/0000000001/', '');
+            // src = src.replace('/10086/', '');
             // 判断不是同一条源时才推出
             if (src.length > 0) {
               // console.log('不同源');
               // this.frameCnt += 1;
               this.holdSteam();
               this.lastRenderMedia = src;
-              const clipPath = join(__dirname, `../ws/video/${src}`);
+              const clipPath = join(__dirname, `../ws/${src}`);
               // console.log('src-clipPath', src, clipPath);
               delete redisMeta.mediaSrc;
 
@@ -396,24 +396,26 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
     this.onMoving.next(true);
     this.holdSteam();
 
-    seqs.forEach((frame: StreamReplyType) => {
+    seqs.forEach((frame: StreamReplyType, index:number) => {
       const mediaSrc = frame.mediaSrc;
-      let src = mediaSrc.split('?')[0];
+      const src = mediaSrc.split('?')[0];
       // 临时本地替换路经
-      src = src.replace('/0000000001/', '');
-      const clipPath = join(__dirname, `../ws/video/${src}`);
+      // src = src.replace('//', '');
+      const clipPath = join(__dirname, `../ws/${src}`);
       const type = frame.type?.length ? frame.type.slice() : 'move';
 
       console.log('type', frame.type);
       delete frame.mediaSrc;
       delete frame.type;
-
+      //TODO 
+      const random_boolean = Math.random() < 0.3;
+      // const random_index === 1 ? 3 : random_boolean ? 1 : 3;
       const stream: StreamFrameType = {
         frame: -1,
         clipPath: clipPath,
         metaData: JSON.stringify(frame),
         serverTime: this.mockserverTime,
-        DIR: 1,
+        DIR: 3,
         type: type,
       };
       this.moveQueue.next(stream);
@@ -635,10 +637,10 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
           if (redisData && 'mediaSrc' in redisData) {
             const mediaSrc: string = redisData.mediaSrc || '';
             if (mediaSrc.length > 0) {
-              let src = mediaSrc.split('?')[0];
+              const src = mediaSrc.split('?')[0];
               // 临时本地替换路经
-              src = src.replace('/0000000001/', '');
-              const clipPath = join(__dirname, `../ws/video/${src}`);
+              // src = src.replace('/10086/', '');
+              const clipPath = join(__dirname, `../ws/${src}`);
               delete redisData.mediaSrc;
               this.logger.log(
                 `user:${this.user_id}:first render stream` +