test pc 3 years ago
parent
commit
67cc7165fb
5 changed files with 179 additions and 206 deletions
  1. 20 0
      src/ShareData.ts
  2. 1 0
      src/get-router/get-router.service.ts
  3. 125 121
      src/move/move.service.ts
  4. 18 51
      src/rotate/rotate.service.ts
  5. 15 34
      src/scene/scene.service.ts

+ 20 - 0
src/ShareData.ts

@@ -0,0 +1,20 @@
+export default class ShareData{
+    public static users = [];
+    public static replys = [];
+
+    public set users(users:any){
+        this.users = users;
+    }
+
+    public get users():any{
+        return this.users;
+    }
+
+    public set replys(replys:any){
+        this.replys = replys;
+    }
+
+    public get replys():any{
+        return this.replys;
+    }
+}

+ 1 - 0
src/get-router/get-router.service.ts

@@ -221,6 +221,7 @@ export class GetRouterService implements OnModuleInit {
         return null;
       }
 
+      console.log('searchRoad2:'+startPointId);
       const startPoint = this.breakPointInfo[startPointId];
       if (startPoint.contact.indexOf(endPointId) > -1) {
         return [startPointId, endPointId];

+ 125 - 121
src/move/move.service.ts

@@ -5,6 +5,7 @@ import { join } from 'path';
 import { CacheService } from 'src/cache/cache.service';
 import { RotateService } from 'src/rotate/rotate.service';
 import configuration from 'src/config/configuration';
+// import ShareData from 'src/ShareData';
 
 // import * as  BreakPointIds from '../../ws/points-BreakPointId.json';
 // import { SceneService } from 'src/scene/scene.service';
@@ -12,6 +13,7 @@ import configuration from 'src/config/configuration';
 const MaxDelayTime = 80; //超过这个值就需要干预(操作杆)
 const MaxBufferCameraInfo = 3; //超过这个值就需要干预(操作杆)
 const MaxNet = 3;
+const MaxWalkCount = 20;
 
 const seqExeAsyncFn = (asyncFn) => {
   let runPromise = null;
@@ -45,6 +47,7 @@ export class MoveService implements OnModuleInit {
     Joystick: 15,
   };
   public users = this.rotateService.users;
+  //public users = ShareData.users;
 
   private reply = {
     traceIds: [],
@@ -95,7 +98,7 @@ export class MoveService implements OnModuleInit {
           renderType: 0,
           videoFrame: null,
           cameraStateType: 3,
-          isMoving: 1,
+          isMoving: 0,
           needIfr: 0,
           isVideo: 0,
           stillFrame: 0,
@@ -197,7 +200,10 @@ export class MoveService implements OnModuleInit {
         frameIndex: 0,
         horizontal_move: 0,
       },
-      moveInfo: {},
+      netQua:0,
+      walkState:0,
+      isMoving:0,
+      IDRCount:0,
       // traceIds: [],
       // actionResponses:[]
     };
@@ -271,7 +277,8 @@ export class MoveService implements OnModuleInit {
       );
       for (let i = 0; i < checkReplys.length; ++i) {
         checkReplys[i].actionResponses[0].actionType = actionType;
-        if (i == 0 || i == checkReplys.length - 1) {
+        //if (i == 0 || i == checkReplys.length - 1) {
+        if (i == 0) {
           checkReplys[i].isIDR = true;
         } else {
           checkReplys[i].isIDR = false;
@@ -408,7 +415,13 @@ export class MoveService implements OnModuleInit {
 
       reply['newUserStates'][0].playerState.camera.angle =
         moveFrame.camera_angle;
-      reply['newUserStates'][0].renderInfo.isMoving = 1;
+      if(user.walkState>MaxWalkCount){
+        reply['newUserStates'][0].renderInfo.isMoving = 2;
+      }
+      else{
+        reply['newUserStates'][0].renderInfo.isMoving = 1;
+      }
+      
       reply['actionResponses'][0].traceId = traceId;
 
       reply.mediaSrc =
@@ -423,6 +436,7 @@ export class MoveService implements OnModuleInit {
         '?m=' +
         new Date().getTime();
       if (startBreakPointId > endBreakPointId) {
+        //console.log('change move437:'+startBreakPointId+','+endBreakPointId)
         reply.mediaSrc =
           '/' +
           appId +
@@ -435,14 +449,10 @@ export class MoveService implements OnModuleInit {
           '?m=' +
           new Date().getTime();
       }
+      console.log('mediaSrc_1:'+reply.mediaSrc)
 
       reply.startBreakPointId = startBreakPointId;
       reply.endBreakPointId = endBreakPointId;
-      // if (i == moveFrames.length - 1) {
-      //   reply.isIDR = true;
-      // } else {
-      //   reply.isIDR = false;
-      // }
       reply.isIDR = false;
       replys.push(reply);
     }
@@ -452,7 +462,12 @@ export class MoveService implements OnModuleInit {
       const reply = JSON.parse(JSON.stringify(this.reply));
       reply.traceIds.push(traceId);
       reply['newUserStates'][0].userId = userId;
-      reply['newUserStates'][0].renderInfo.isMoving = 1;
+      if(user.walkState>MaxWalkCount){
+        reply['newUserStates'][0].renderInfo.isMoving = 2;
+      }
+      else{
+        reply['newUserStates'][0].renderInfo.isMoving = 1;
+      }
       if (!isFromUser) {
         reply['newUserStates'][0].playerState.player.position = {
           x:
@@ -506,6 +521,7 @@ export class MoveService implements OnModuleInit {
         new Date().getTime();
 
       if (startBreakPointId > endBreakPointId) {
+        console.log('change move526:'+startBreakPointId+','+endBreakPointId)
         reply.mediaSrc =
           '/' +
           appId +
@@ -518,11 +534,12 @@ export class MoveService implements OnModuleInit {
           '?m=' +
           new Date().getTime();
       }
+      console.log('mediaSrc_2:'+reply.mediaSrc)
       reply.startBreakPointId = startBreakPointId;
       reply.endBreakPointId = endBreakPointId;
       replys.push(reply);
     }
-    replys[replys.length - 1].isIDR = true;
+    //replys[replys.length - 1].isIDR = true;
     return replys;
   }
 
@@ -637,6 +654,7 @@ export class MoveService implements OnModuleInit {
     reply['newUserStates'][0].playerState.camera.angle = rotateData.cameraAngle;
     reply['newUserStates'][0].playerState.cameraCenter = breakPoint.position;
     reply['actionResponses'][0].traceId = traceId;
+    console.log('stop658:'+breakPointId+','+rotateData.directory)
     reply.mediaSrc =
       '/' +
       appId +
@@ -667,7 +685,10 @@ export class MoveService implements OnModuleInit {
       const breakPointId = user.breakPointId;
       const appId = user.appId;
       const replys = [];
-      const step = 0.4;
+      let step = 0.4;
+      if(user.walkState>MaxWalkCount){
+        step = 1.2;
+      }
       //const step = 1;
       const closestDis = 50; //小于这个距离就跳到邻居呼吸点
       const distance = step * dir_action.speed_level;
@@ -692,6 +713,8 @@ export class MoveService implements OnModuleInit {
         { x: 550, y: -300 },
       ];
 
+      //更新行走状态
+      ++user.walkState;
       //找到邻居点,判断user.player.position与邻居点的距离,如果距离小于closestDis,就要更新camera的position
       const breakPoint = this.breakPointInfo[breakPointId];
       const surroundPointIds = breakPoint.contact;
@@ -714,7 +737,13 @@ export class MoveService implements OnModuleInit {
       this.reply['newUserStates'][0].playerState.cameraCenter = JSON.parse(
         JSON.stringify(user.player.position),
       );
-      this.reply['newUserStates'][0].renderInfo.isMoving = 1;
+
+      if(user.walkState>MaxWalkCount){
+        this.reply['newUserStates'][0].renderInfo.isMoving = 2;
+      }
+      else{
+        this.reply['newUserStates'][0].renderInfo.isMoving = 1;
+      }
       this.reply['actionResponses'][0].traceId = traceId;
       this.reply.mediaSrc = null;
 
@@ -758,10 +787,9 @@ export class MoveService implements OnModuleInit {
           closestAngleNeighor = angle;
         }
       }
-
+      console.log('joystickjoystick:' + this.cameraInfos.length);
       //超出范围了
       if (this.getDistance(playerPosition, breakPoint.position) > closestDis) {
-        console.log('20220627test-joystick-moveCamera');
         return await this.moveCamera(
           breakPointId,
           closestNeighorId,
@@ -775,7 +803,6 @@ export class MoveService implements OnModuleInit {
         //超出区域
         if (!inside) {
           if (minAngleNeighorId != null) {
-            console.log('20220627test-joystick-moveDirect');
             return await this.moveDirect(
               playerPosition,
               closestDis,
@@ -797,17 +824,18 @@ export class MoveService implements OnModuleInit {
         );
         this.reply.actionResponses[0].actionType = actionType;
 
-        console.log('20220708_延时->' + time_delay);
+        console.log('20220719_延时->' + time_delay);
         // //网络延迟的情况下,就暂时不推流
-        if (time_delay && time_delay > MaxDelayTime) {
-          user.netQua = 0;
-        } else if (
+        if (
           time_delay &&
           time_delay < MaxDelayTime &&
           user.netQua < MaxNet
         ) {
           ++user.netQua;
         }
+        else if (time_delay && time_delay > MaxDelayTime) {
+          user.netQua = 0;
+        }  
 
         if (user.netQua < MaxNet) {
           if (user.lastJoyStickMediaSrc) {
@@ -817,9 +845,6 @@ export class MoveService implements OnModuleInit {
         }
         const cameraInfo = this.getCameraInfo();
         if (cameraInfo != null) {
-          console.log(
-            '20220627test-joystick-自由-合并,' + this.cameraInfos.length,
-          );
           this.reply['newUserStates'][0].playerState.camera.position =
             cameraInfo.camera_position;
           this.reply['newUserStates'][0].playerState.camera.angle =
@@ -829,21 +854,17 @@ export class MoveService implements OnModuleInit {
             this.reply.mediaSrc = cameraInfo.mediaSrc;
             this.reply.isIDR = cameraInfo.isIDR;
             user.lastJoyStickMediaSrc = true;
-            console.log('20220708_mediaSrc1:' + cameraInfo.mediaSrc);
           }
 
           user.camera.position = JSON.parse(
             JSON.stringify(cameraInfo.camera_position),
           );
-          // console.log(
-          //   'handlejoystick-angle->:自由并过渡更新user.angle' +
-          //     cameraInfo.camera_angle.yaw,
-          // );
+
           user.camera.angle.yaw = cameraInfo.camera_angle.yaw;
 
           this.sendingFrameForJoystick = true;
         } else {
-          console.log('20220627test-joystick-自由-不合并');
+
         }
         return this.reply;
       }
@@ -872,17 +893,13 @@ export class MoveService implements OnModuleInit {
       const closestDis = 80; //小于这个距离就跳到邻居呼吸点
       const distance = step * dir_action.speed_level;
       let angle = null;
-      // console.log(
-      //   'handlejoystick-angle->:dir_action.move_angle' + dir_action.move_angle,
-      // );
+
       if (user.camera.angle.yaw < 0) {
         user.camera.angle.yaw = 360 + user.camera.angle.yaw;
       }
       let move_angle = dir_action.move_angle + user.camera.angle.yaw;
       move_angle = move_angle % 360;
-      // console.log(
-      //   'handlejoystick-angle->:叠加后move_angle(也是user.angle)' + move_angle,
-      // );
+
       //TODO 临时增加断言
       const playerPosition: Point = { x: 0, y: 0, z: 0 };
       playerPosition.x =
@@ -894,10 +911,7 @@ export class MoveService implements OnModuleInit {
 
       // const offsetX = playerPosition.x - user.player.position.x;
       // const offsetY = playerPosition.y - user.player.position.y;
-      console.log(
-        'handlejoysticktesttest:actionRequest-playerPosition' +
-          JSON.stringify(playerPosition),
-      );
+
       //找到邻居点,判断user.player.position与邻居点的距离,如果距离小于closestDis,就要更新camera的position
       let chooseBreakPointId = null;
       const breakPoint = this.breakPointInfo[breakPointId];
@@ -920,7 +934,13 @@ export class MoveService implements OnModuleInit {
       this.reply['newUserStates'][0].playerState.cameraCenter = JSON.parse(
         JSON.stringify(breakPoint.position),
       );
-      this.reply['newUserStates'][0].renderInfo.isMoving = 1;
+
+      if(user.walkState>MaxWalkCount){
+        this.reply['newUserStates'][0].renderInfo.isMoving = 2;
+      }
+      else{
+        this.reply['newUserStates'][0].renderInfo.isMoving = 1;
+      }
       this.reply['actionResponses'][0].traceId = traceId;
       this.reply.mediaSrc = null;
 
@@ -1021,11 +1041,6 @@ export class MoveService implements OnModuleInit {
         );
       } else {
         if (singleInfo != null) {
-          // console.log(
-          //   'joystick校验--->' + breakPointId + '-' + singleInfo.breakPointId,
-          // );
-          //console.log('handlejoysticktesttest校验0角度:'+_angle+','+move_angle)       //这个没办法,得换方案
-          //console.log('handlejoysticktesttest:actionRequest-笔直'+new Date().getTime());
           return await this.moveDirect(
             playerPosition,
             closestDis,
@@ -1037,7 +1052,6 @@ export class MoveService implements OnModuleInit {
             actionType,
           );
         } else if (count == 1) {
-          //console.log('handlejoysticktesttest:actionRequest-笔直'+new Date().getTime());
           return await this.moveDirect(
             playerPosition,
             closestDis,
@@ -1052,7 +1066,6 @@ export class MoveService implements OnModuleInit {
           this.reply['newUserStates'][0].playerState.player.position =
             JSON.parse(JSON.stringify(user.player.position));
           this.reply.actionResponses[0].actionType = actionType;
-          //console.log('handlejoysticktesttest:actionRequest-停止'+new Date().getTime());
           return this.reply;
         }
       }
@@ -1068,24 +1081,6 @@ export class MoveService implements OnModuleInit {
           this.getDistance(playerPosition, breakPoint.position),
       );
       if (this.getDistance(playerPosition, breakPoint.position) > closestDis) {
-        // let offsetAngle1 = Math.abs(_angle - neighPoints[0].angle);
-        // if (neighPoints[0].angle == 0) {
-        //   offsetAngle1 = Math.min(offsetAngle1, Math.abs(_angle - 360));
-        // }
-
-        // let offsetAngle2 = Math.abs(_angle - neighPoints[1].angle);
-        // if (neighPoints[1].angle == 0) {
-        //   offsetAngle2 = Math.min(offsetAngle2, Math.abs(_angle - 360));
-        // }
-
-        // if (offsetAngle1 > offsetAngle2) {
-        //   chooseBreakPointId = neighPoints[1].breakPointId;
-        // } else {
-        //   chooseBreakPointId = neighPoints[0].breakPointId;
-        // }
-        // if (closestNeighorId == null) {
-        //   debugger;
-        // }
         chooseBreakPointId = closestNeighorId;
         return await this.moveCamera(
           breakPointId,
@@ -1116,17 +1111,13 @@ export class MoveService implements OnModuleInit {
           user.camera.position = JSON.parse(
             JSON.stringify(cameraInfo.camera_position),
           );
-          // console.log(
-          //   'handlejoystick-angle->:自由并过渡更新user.angle' +
-          //     cameraInfo.camera_angle.yaw,
-          // );
+
           user.camera.angle.yaw = cameraInfo.camera_angle.yaw;
 
           this.sendingFrameForJoystick = true;
         } else {
-          //console.log('joystick自由--->不合并');
         }
-        //console.log('handlejoysticktesttest:actionRequest-自由'+new Date().getTime());
+
         console.log(
           'handlejoysticktesttest:自由:' +
             this.reply.mediaSrc +
@@ -1159,10 +1150,7 @@ export class MoveService implements OnModuleInit {
       breakPoint.position,
       this.breakPointInfo[neighBreakPointId].position,
     );
-    // console.log('handlejoysticktesttest校验1线段:'+breakPointId+','+neighBreakPointId)
-    // console.log('handlejoysticktesttest校验2计算后的:'+JSON.stringify(player_Position))
-    // console.log('handlejoysticktesttest校验3人物变化前:'+JSON.stringify(user.player.position))
-    // console.log('handlejoysticktesttest校验4人物本应该的坐标:'+JSON.stringify(playerPosition))
+
     if (player_Position != null) {
       playerPosition.x = player_Position.x;
       playerPosition.y = player_Position.y;
@@ -1245,7 +1233,8 @@ export class MoveService implements OnModuleInit {
 
       for (let i = 0; i < checkReplys.length; ++i) {
         let isIDR = false;
-        if (i == 0 || i == checkReplys.length - 1) {
+        //if (i == 0 || i == checkReplys.length - 1) {
+        if (i == 0) {
           isIDR = true;
         }
         this.addCameraInfo(
@@ -1256,21 +1245,6 @@ export class MoveService implements OnModuleInit {
         );
       }
 
-      //replys.push(checkReplys);
-      //读redis里的数据,按照frame_index的大小排序
-      /*
-      const key =
-        'moveframe:app_id:' +
-        appId +
-        ':start_break_point_id:' +
-        breakPointId +
-        ':end_break_point_id:' +
-        chooseBreakPointId +
-        ':angle:' +
-        Math.floor(user.camera.angle.yaw / 45);
-      const moveFramesRes = await this.cacheService.get(key);
-      const moveFrames = JSON.parse(moveFramesRes);
-      */
       const index = this.getMoveIndex(user.camera.angle.yaw);
       const moveFrames = await this.getMoveFrames(
         appId,
@@ -1298,10 +1272,7 @@ export class MoveService implements OnModuleInit {
         user.camera.position = JSON.parse(
           JSON.stringify(cameraInfo.camera_position),
         );
-        // console.log(
-        //   'handlejoystick-angle->:刚刚过渡更新user.angle' +
-        //     cameraInfo.camera_angle.yaw,
-        // );
+
         user.camera.angle.yaw = cameraInfo.camera_angle.yaw;
 
         if (cameraInfo.mediaSrc) {
@@ -1310,7 +1281,7 @@ export class MoveService implements OnModuleInit {
         }
         this.sendingFrameForJoystick = true;
       }
-      //console.log('handlejoysticktesttest:actionRequest-镜头过渡'+new Date().getTime());
+
       console.log(
         'handlejoysticktesttest:actionRequest-镜头过渡:从' +
           breakPointId +
@@ -1324,17 +1295,28 @@ export class MoveService implements OnModuleInit {
   }
 
   setCameraInfo(appId, userId, moveFrames, startBreakPointId, endBreakPointId) {
-    // let moveInterval = 1;
-    // console.log('20220708_cameraInfos设置->'+this.cameraInfos.length);
-    // if(this.cameraInfos.length>MaxBufferCameraInfo){
-    //   moveInterval = 1;
-    // }
+    console.log('setCameraInfo前:'+this.cameraInfos.length);
     const user = this.users[userId];
-    let moveInterval = 2;
+    //let moveInterval = 2;
     let flag = false;
     for (let i = 0; i < moveFrames.length; ++i) {
-      if (user.netQua < MaxNet) {
-        if (i != 0 && i != moveFrames.length - 1 && i % moveInterval == 0) {
+      if(user.walkState > MaxWalkCount){
+        //网络差
+        if (user.netQua < MaxNet) {
+          if (i != 0 && i != moveFrames.length - 1 && i % 5 != 0) {
+            continue;
+          }
+        }
+        //网络正常
+        else{
+          if (i != 0 && i != moveFrames.length - 1 && i % 4 != 0) {
+            continue;
+          }
+        }
+      }
+      //网络差
+      else if (user.netQua < MaxNet) {
+        if (i != 0 && i != moveFrames.length - 1 && i % 2 == 0) {
           continue;
         }
       }
@@ -1357,6 +1339,7 @@ export class MoveService implements OnModuleInit {
         new Date().getTime();
 
       if (startBreakPointId > endBreakPointId) {
+        console.log('change move1341:'+startBreakPointId+','+endBreakPointId)
         moveFrames[i].mediaSrc =
           '/' +
           appId +
@@ -1372,17 +1355,30 @@ export class MoveService implements OnModuleInit {
           '?m=' +
           new Date().getTime();
       }
-      console.log('20220708_mediaSrc3:' + moveFrames[i].mediaSrc);
-      if (i == 0 || i == moveFrames.length - 1) {
+                                                                // if (i == 0 || i == moveFrames.length - 1) {
+                                                                //   moveFrames[i].isIDR = true;
+                                                                //   if (i == moveFrames.length - 1) {
+                                                                //     flag = true;
+                                                                //   }
+                                                                // } else {
+                                                                //   moveFrames[i].isIDR = false; }
+                  
+      
+      if(user.IDRCount % 10 == 0){
         moveFrames[i].isIDR = true;
-        if (i == moveFrames.length - 1) {
-          flag = true;
-        }
-      } else {
+        user.IDRCount = 0;
+      }    
+      else{
         moveFrames[i].isIDR = false;
       }
+      if (i == moveFrames.length - 1) {
+        flag = true;
+      }
+      ++user.IDRCount;                                         
       this.cameraInfos.push(moveFrames[i]);
+      console.log('mediaSrc_3:'+moveFrames[i].mediaSrc+',isIDR:'+moveFrames[i].isIDR)
     }
+    //最后一个元素跳过了,要补上
     if (!flag) {
       const cameraInfo = moveFrames[moveFrames.length - 1];
       cameraInfo.endBreakPointId = endBreakPointId;
@@ -1399,6 +1395,7 @@ export class MoveService implements OnModuleInit {
         new Date().getTime();
 
       if (startBreakPointId > endBreakPointId) {
+        console.log('change move1384:'+startBreakPointId+','+endBreakPointId)
         cameraInfo.mediaSrc =
           '/' +
           appId +
@@ -1411,10 +1408,16 @@ export class MoveService implements OnModuleInit {
           '?m=' +
           new Date().getTime();
       }
-      cameraInfo.isIDR = true;
+                                                                            //cameraInfo.isIDR = true;
+      if(user.IDRCount % 10 == 0){
+        cameraInfo.isIDR = true;
+        user.IDRCount = 0;
+      } 
+      ++user.IDRCount;
       this.cameraInfos.push(cameraInfo);
-      console.log('20220708_mediaSrc4:' + cameraInfo.mediaSrc);
+      console.log('mediaSrc_4:'+cameraInfo.mediaSrc+',isIDR:'+cameraInfo.isIDR)
     }
+    console.log('setCameraInfo后:'+this.cameraInfos.length);
   }
 
   addCameraInfo(cameraPosition, cameraAngle, mediaSrc, isIDR) {
@@ -1429,7 +1432,6 @@ export class MoveService implements OnModuleInit {
   getCameraInfo() {
     if (this.cameraInfos.length > 0) {
       const item = this.cameraInfos.shift();
-      console.log('20220708_cameraInfos取值->' + this.cameraInfos.length);
       return item;
     } else {
       return null;
@@ -1437,9 +1439,10 @@ export class MoveService implements OnModuleInit {
   }
 
   complementFrame(userId) {
+    const user = this.users[userId];
+    user.walkState = 0;
+    user.IDRCount = 0;
     if (this.cameraInfos.length > 0) {
-      console.log('20220627test-执行complementFrame,' + new Date().getTime());
-      const user = this.users[userId];
       const cameraInfo = this.cameraInfos.shift();
       this.reply.traceIds = [];
       this.reply['newUserStates'][0].userId = userId;
@@ -1475,11 +1478,9 @@ export class MoveService implements OnModuleInit {
       this.sendingFrameForJoystick = true;
       return this.reply;
     } else if (this.cameraInfos.length == 0) {
-      if (this.reply['newUserStates'][0].renderInfo.isMoving == 1) {
-        //console.log('handlejoysticktesttest:complementFrame-2 停止1'+new Date().getTime())
+      if (this.reply['newUserStates'][0].renderInfo.isMoving != 0) {
         return this.stopJoystick(userId);
       } else {
-        //console.log('handlejoysticktesttest:complementFrame-2 停止2'+new Date().getTime())
         return null;
       }
     }
@@ -1570,6 +1571,7 @@ export class MoveService implements OnModuleInit {
         '?m=' +
         new Date().getTime();
       if (startBreakPointId > endBreakPointId) {
+        console.log('change move1552:'+startBreakPointId+','+endBreakPointId)
         mediaSrc =
           '/' +
           appId +
@@ -1582,7 +1584,7 @@ export class MoveService implements OnModuleInit {
           '?m=' +
           new Date().getTime();
       }
-      console.log('20220708_mediaSrc2:' + mediaSrc);
+      console.log('mediaSrc_5:'+mediaSrc)
       this.cameraInfos.push({
         startBreakPointId: startBreakPointId,
         endBreakPointId: endBreakPointId,
@@ -1608,7 +1610,8 @@ export class MoveService implements OnModuleInit {
       '?m=' +
       new Date().getTime();
     if (startBreakPointId > endBreakPointId) {
-      frame.mediaSrc =
+      console.log('change move1591:'+startBreakPointId+','+endBreakPointId)
+      mediaSrc =
         '/' +
         appId +
         '/' +
@@ -1620,6 +1623,7 @@ export class MoveService implements OnModuleInit {
         '?m=' +
         new Date().getTime();
     }
+    console.log('mediaSrc_6:'+mediaSrc)
     this.cameraInfos.push({
       startBreakPointId: startBreakPointId,
       endBreakPointId: endBreakPointId,
@@ -1631,7 +1635,7 @@ export class MoveService implements OnModuleInit {
   }
 
   stopJoystick(userId) {
-    console.log('20220627test:stopJoystick');
+
     this.reply.traceIds = [];
     const user = this.users[userId];
     this.reply['newUserStates'][0].userId = userId;

+ 18 - 51
src/rotate/rotate.service.ts

@@ -2,6 +2,7 @@ import { Injectable, Logger } from '@nestjs/common';
 import { ConfigService } from '@nestjs/config';
 import { CacheService } from 'src/cache/cache.service';
 // import { SceneService } from 'src/scene/scene.service';
+// import ShareData from 'src/ShareData';
 
 const seqExeAsyncFn = (asyncFn) => {
   let runPromise = null;
@@ -34,8 +35,10 @@ export class RotateService {
     Rotation: 1014,
     Joystick: 15,
   };
+  // private users = ShareData.users;
+  // private replys = ShareData.replys;
   public users = {};
-  private replies = {};
+  private replys = {};
   private firstPoint = {
     player: {
       position: { x: -600.0, y: -250.0, z: 0.0 }, //position: { x: -560.0, y: 320.0, z: 0.0 }, //{ x: -800.0, y: 100.0, z: 0.0 },
@@ -89,8 +92,10 @@ export class RotateService {
         frameIndex: 0,
         horizontal_move: 0,
       },
-      moveInfo: {},
-      netQua: 3,
+      netQua:0,
+      walkState:0,
+      isMoving:0,
+      IDRCount:0,
       // traceIds: [],
       // actionResponses:[]
     };
@@ -204,14 +209,14 @@ export class RotateService {
     reply['newUserStates'][0].playerState.camera.position = JSON.parse(
       JSON.stringify(this.firstPoint.camera.position),
     );
-    this.replies[userId] = reply;
+    this.replys[userId] = reply;
     return reply;
   }
 
   //首帧
   getFirstStreamData(appId, userId) {
     const user = this.users[userId];
-    const reply = this.replies[userId];
+    const reply = this.replys[userId];
     reply.traceIds = [];
     reply['newUserStates'][0].userId = userId;
     reply['newUserStates'][0].playerState.player.position = JSON.parse(
@@ -244,7 +249,7 @@ export class RotateService {
       '?m=' +
       new Date().getTime();
     reply['newUserStates'][0].renderInfo.isMoving = 0;
-    this.replies[userId] = reply;
+    this.replys[userId] = reply;
     return reply;
   }
 
@@ -274,7 +279,7 @@ export class RotateService {
         this.actionRequestPool[userId].push(actionRequest);
       }
 
-      let reply = this.replies[userId];
+      let reply = this.replys[userId];
 
       const actionRequests = this.actionRequestPool[userId];
       const user = this.users[userId];
@@ -302,7 +307,7 @@ export class RotateService {
       if (Math.abs(hAngle) < 1) {
         user.rotateInfo.horizontal_move = horizontal_move;
         //user.traceIds = traceIds;
-        this.replies[userId] = reply;
+        this.replys[userId] = reply;
         return null;
       }
       reply = await this.rotateForAngle(userId, Math.floor(hAngle));
@@ -347,7 +352,7 @@ export class RotateService {
         } else if (user.camera.angle.yaw > 359) {
           user.camera.angle.yaw -= 360;
         }
-        const reply = JSON.parse(JSON.stringify(this.replies[userId]));
+        const reply = JSON.parse(JSON.stringify(this.replys[userId]));
         reply['newUserStates'][0]['userId'] = userId;
         //从redis里取
         //let key = user.appId + "-"+user.breakPointId+"-"+user.rotateInfo.frameIndex;
@@ -421,8 +426,8 @@ export class RotateService {
             value.fileName,
         );
         reply.breakPointId = user.breakPointId;
-        this.replies[userId].traceIds = [];
-        this.replies[userId].actionResponses = [];
+        this.replys[userId].traceIds = [];
+        this.replys[userId].actionResponses = [];
 
         user.rotateInfo.horizontal_move = 0;
         return resolve(reply);
@@ -547,7 +552,7 @@ export class RotateService {
 
   async echo(userId: string, isFirst: boolean) {
     const user = this.users[userId];
-    const reply = JSON.parse(JSON.stringify(this.replies[userId]));
+    const reply = JSON.parse(JSON.stringify(this.replys[userId]));
     reply['newUserStates'][0]['userId'] = userId;
     reply['newUserStates'][0]['playerState'].player.position =
       user.player.position;
@@ -574,41 +579,6 @@ export class RotateService {
       reply.breakPointId = user.breakPointId;
       return reply;
     } else {
-      /*
-      const key =
-        'rotateframe:app_id:' +
-        user.appId +
-        ':frame_index:' +
-        user.camera.angle.yaw +
-        ':break_point_id:' +
-        user.breakPointId;
-      const redisData = await this.cacheService.get(key);
-      if (redisData && redisData.length > 0) {
-        const value = redisData ? JSON.parse(redisData) : null;
-        reply.mediaSrc =
-          '/' +
-          user.appId +
-          '/' +
-          user.breakPointId +
-          '/' +
-          value.directory +
-          '/' +
-          value.fileName +
-          '?m=' +
-          new Date().getTime();
-        reply.breakPointId = user.breakPointId;
-        // console.log(
-        //   'joystick:->echo' +
-        //     'playerPosition:' +
-        //     JSON.stringify(
-        //       reply['newUserStates'][0].playerState.player.position,
-        //     ) +
-        //     ',cameraPosition:' +
-        //     JSON.stringify(
-        //       reply['newUserStates'][0].playerState.camera.position,
-        //     ),
-        // );
-        */
       let fileName = user.camera.angle.yaw + '.h264';
       if (fileName.length == 8) {
         fileName = '0' + fileName;
@@ -617,7 +587,7 @@ export class RotateService {
       } else if (fileName.length == 6) {
         fileName = '000' + fileName;
       }
-
+      reply['newUserStates'][0].renderInfo.isMoving = user.isMoving;
       reply.mediaSrc =
         '/' +
         user.appId +
@@ -633,9 +603,6 @@ export class RotateService {
         new Date().getTime();
       reply.breakPointId = user.breakPointId;
       return reply;
-      // } else {
-      //   this.logger.error('echo返回null', key);
-      //   return {};
     }
   }
 }

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

@@ -18,6 +18,7 @@ import { GetRouterService } from 'src/get-router/get-router.service';
 import { ConfigService } from '@nestjs/config';
 import { Logger } from 'winston';
 import { WINSTON_MODULE_PROVIDER } from 'nest-winston';
+// import ShareData from 'src/ShareData';
 // interface UserInfo {
 //   userId: string;
 //   roomId: string;
@@ -123,7 +124,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
   private hasJoystickFocusRepeat = false;
   private startSub: any;
 
-  public users = {};
+  //public users = ShareData.users;
 
   public sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));
 
@@ -281,9 +282,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
     // try {
     const rotateUnlock = this.firstRender && !this.globalOptLock;
     console.log('rotateUnlock条件--->' + rotateUnlock, this.globalOptLock);
-
     if (rotateUnlock && this._rotateCount > 2) {
-      console.log('20220627test:handleRotate');
       const start = performance.now();
       // 当move时处理 _rotateCount是移动端同时触发的问题,rotateStopThrottle是减少重复抖动stop的处理。
       this.holdSteam();
@@ -372,6 +371,9 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
       IDRflag,
       new Date().getTime(),
     );
+
+    const user = this.moveService.users[this.user_id];
+    user.isMoving = JSON.parse(stream.metaData)['newUserStates'][0].renderInfo.isMoving
     const res = await this.streamService.pushFrameToSteam(stream);
     if (res.done) {
       this.frameCnt.next(res.frame);
@@ -740,10 +742,6 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
           for (let i = 0; i <= walkingRes.length - 1; i++) {
             Array.from(walkingRes[i]).forEach(
               (item: StreamReplyType, index: number) => {
-                console.log(
-                  '20220628test:handleWalking->' +
-                    item['newUserStates'][0].renderInfo.isMoving,
-                );
                 //const IDRflag = index % 5 === 0 ? 1 : 3;
                 const IDRflag = item.isIDR ? 1 : 3;
                 const dir = this.isHeaderOrLast(
@@ -848,6 +846,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
     const hasMedia = joystickRes?.mediaSrc && joystickRes?.mediaSrc.length > 0;
 
     if (hasMedia) {
+      console.log('mediaSrc_7:'+joystickRes.mediaSrc);
       const src = joystickRes.mediaSrc.split('?')[0];
       const mediaSrc = this.configService.get('app.prefix') + src;
       // IDR flag设置为I帧
@@ -874,10 +873,9 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
       };
     }
 
-    console.log(
-      '20220627test-complementFrame 进行1' + '***' + streamData.frame,
-    );
-
+    const user = this.moveService.users[this.user_id];
+    user.isMoving = JSON.parse(streamData.metaData)['newUserStates'][0].renderInfo.isMoving;
+    console.log('handlePushJoyStickSteam:'+user.IDRCount+','+joystickRes.isIDR+','+joystickRes.traceIds);
     // 过滤新东西, 推完给回false
     this.moveService.sendingFrameForJoystick = true;
 
@@ -920,18 +918,11 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
           this.user_id,
         ) as StreamReplyType;
         if (complementFrame) {
-          console.log(
-            '20220627test-complementFrame 进行' +
-              complementFrame.mediaSrc +
-              '***' +
-              this.frameCnt.value,
-          );
           // 第二次或N次进入时如果有值直接重新进入流主程
           this.holdSteam();
           this.handlePushJoyStickSteamSeq(complementFrame);
           this.globalOptLock = true;
         } else {
-          console.log('20220627test-complementFrame 结束');
           // 第二次或N次无pool数据再次trigger handleJoystickStop
           this.hasJoystickFocusRepeat = false;
           this.testTimer = 0;
@@ -943,6 +934,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
         this.handleJoystickStop(hasPush);
       }
     } else {
+      debugger;
       console.error('joystick-流地址有误::', joystickRes.mediaSrc);
       this.logger.error('joystick-流地址有误::', joystickRes.mediaSrc);
       this.resumeStream();
@@ -955,14 +947,13 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
     // 最后一帧200ms
     clearTimeout(this._JoyStickingSteamTimeout);
     this._JoyStickingSteamTimeout = setTimeout(async () => {
-      console.log('20220627test-complementFrame handleJoystickStop 200ms之后');
       const user = this.moveService.users[this.user_id];
       await this.getSimplestCameraInfo(user.appId, this.user_id);
       const complementFrame = this.moveService.complementFrame(
         this.user_id,
       ) as StreamReplyType;
       // console.log('has-complementFrame', complementFrame);
-      console.log('gemer-test-complementFrame', complementFrame);
+      //console.log('gemer-test-complementFrame', complementFrame);
       if (complementFrame) {
         this.hasJoystickFocusRepeat = true;
         this.globalOptLock = true;
@@ -971,7 +962,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
         const start = performance.now();
         this.handlePushJoyStickSteamSeq(complementFrame);
         const stop = performance.now();
-        console.log('handlePushJoyStickSteam', this.testTimer);
+        //console.log('handlePushJoyStickSteam', this.testTimer);
         const inMillSeconds = stop - start;
         const rounded = Number(inMillSeconds).toFixed(3);
         console.log(`complementFrame调用时间---->${rounded}`);
@@ -1006,14 +997,6 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
 
       if (joystickRes) {
         this.onJoysticking.next(true);
-        // console.log(
-        //   'handlejoysticktesttest:' +
-        //     joystickRes.mediaSrc +
-        //     ',相机坐标:' +
-        //     JSON.stringify(
-        //       joystickRes.newUserStates[0].playerState.player.position,
-        //     ),
-        // );
         if (!this.onMoving.getValue()) {
           console.log('handlejoystick:data', JSON.stringify(joystickRes));
           this.handlePushJoyStickSteamSeq(joystickRes);
@@ -1069,11 +1052,6 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
     try {
       if (!this.isStopJointing) {
         const metaData: StreamReplyType = JSON.parse(stream.metaData);
-        // if (this.moveframeCnt === -1) {
-        //   this.moveframeCnt = this.frameCnt.getValue();
-        // }
-        // this.moveframeCnt += 1;
-        // this.latestBreakPointId = metaData.endBreakPointId;
         this.moveframeCnt = this.frameCnt.value + 1;
         const streamData: StreamFrameType = {
           frame: this.moveframeCnt,
@@ -1098,6 +1076,9 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
           '[media-move-lastMovingPointArray]',
           this.lastMovingPointArray?.length,
         );
+
+        const user = this.moveService.users[this.user_id];
+        user.isMoving = JSON.parse(streamData.metaData)['newUserStates'][0].renderInfo.isMoving;
         // 记录lastMoveStreamFrame给打断逻辑使用
         this.lastMoveStreamFrame.next(streamData);
         // this.lastMoveStreamFrameBk = streamData;