test pc 3 years ago
parent
commit
49a82e0d01
2 changed files with 59 additions and 73 deletions
  1. 44 58
      src/move/move.service.ts
  2. 15 15
      src/scene/scene.service.ts

+ 44 - 58
src/move/move.service.ts

@@ -228,7 +228,7 @@ export class MoveService implements OnModuleInit {
       end_break_point_id +
       end_break_point_id +
       ':angle:' +
       ':angle:' +
       angleIndex;
       angleIndex;
-    //倒
+    //倒
     if (start_break_point_id > end_break_point_id) {
     if (start_break_point_id > end_break_point_id) {
       key =
       key =
         'moveframe:app_id:' +
         'moveframe:app_id:' +
@@ -239,12 +239,11 @@ export class MoveService implements OnModuleInit {
         start_break_point_id +
         start_break_point_id +
         ':angle:' +
         ':angle:' +
         angleIndex;
         angleIndex;
-      console.log('getMoveFrames:' + key);
+
       moveFramesRes = await this.cacheService.get(key);
       moveFramesRes = await this.cacheService.get(key);
       moveFrames = JSON.parse(moveFramesRes);
       moveFrames = JSON.parse(moveFramesRes);
       moveFrames = moveFrames.reverse();
       moveFrames = moveFrames.reverse();
     } else {
     } else {
-      console.log('getMoveFrames:' + key);
       moveFramesRes = await this.cacheService.get(key);
       moveFramesRes = await this.cacheService.get(key);
       moveFrames = JSON.parse(moveFramesRes);
       moveFrames = JSON.parse(moveFramesRes);
     }
     }
@@ -281,7 +280,8 @@ export class MoveService implements OnModuleInit {
       this.reply.traceIds = traceIds;
       this.reply.traceIds = traceIds;
       this.reply['newUserStates'][0].userId = userId;
       this.reply['newUserStates'][0].userId = userId;
       this.reply['actionResponses'][0].traceId = traceId;
       this.reply['actionResponses'][0].traceId = traceId;
-      const index = Math.floor((user.camera.angle.yaw + 1) / 45) % 8; //过渡需要
+      //const index = Math.floor((user.camera.angle.yaw + 1) / 45) % 8; //过渡需要
+      const index = this.getMoveIndex(user.camera.angle.yaw);
       for (let i = 0; i < path.length - 1; ++i) {
       for (let i = 0; i < path.length - 1; ++i) {
         let pathReplys = [];
         let pathReplys = [];
         const start_break_point_id = path[i];
         const start_break_point_id = path[i];
@@ -873,7 +873,7 @@ export class MoveService implements OnModuleInit {
     if (this.sendingFrameForJoystick) {
     if (this.sendingFrameForJoystick) {
       return null;
       return null;
     }
     }
-
+    
     const userId = actionRequest['user_id'];
     const userId = actionRequest['user_id'];
     const traceId = actionRequest['trace_id'];
     const traceId = actionRequest['trace_id'];
     const dir_action = actionRequest['dir_action'];
     const dir_action = actionRequest['dir_action'];
@@ -886,6 +886,10 @@ export class MoveService implements OnModuleInit {
     const closestDis = 80; //小于这个距离就跳到邻居呼吸点
     const closestDis = 80; //小于这个距离就跳到邻居呼吸点
     const distance = step * dir_action.speed_level;
     const distance = step * dir_action.speed_level;
     let angle = null;
     let angle = null;
+    if(dir_action.move_angle<0 || user.camera.angle.yaw<0){
+      debugger;
+    }
+
     let move_angle = dir_action.move_angle + user.camera.angle.yaw;
     let move_angle = dir_action.move_angle + user.camera.angle.yaw;
     move_angle = move_angle % 360;
     move_angle = move_angle % 360;
 
 
@@ -927,9 +931,10 @@ export class MoveService implements OnModuleInit {
     console.log('joystickjoystick:' + this.cameraInfos.length);
     console.log('joystickjoystick:' + this.cameraInfos.length);
 
 
     if (surroundPointIds.length == 1) {
     if (surroundPointIds.length == 1) {
-      console.log(
-        'joystick校验--->' + breakPointId + '-' + surroundPointIds[0],
-      );
+      // console.log(
+      //   'joystick校验--->' + breakPointId + '-' + surroundPointIds[0],
+      // );
+      console.log('handlejoysticktesttest:actionRequest-笔直'+new Date().getTime());
       return await this.moveDirect(
       return await this.moveDirect(
         playerPosition,
         playerPosition,
         closestDis,
         closestDis,
@@ -1026,6 +1031,7 @@ export class MoveService implements OnModuleInit {
         //   'joystick校验--->' + breakPointId + '-' + singleInfo.breakPointId,
         //   'joystick校验--->' + breakPointId + '-' + singleInfo.breakPointId,
         // );
         // );
         //console.log('handlejoysticktesttest校验0角度:'+_angle+','+move_angle)       //这个没办法,得换方案
         //console.log('handlejoysticktesttest校验0角度:'+_angle+','+move_angle)       //这个没办法,得换方案
+        console.log('handlejoysticktesttest:actionRequest-笔直'+new Date().getTime());
         return await this.moveDirect(
         return await this.moveDirect(
           playerPosition,
           playerPosition,
           closestDis,
           closestDis,
@@ -1037,9 +1043,10 @@ export class MoveService implements OnModuleInit {
           actionType,
           actionType,
         );
         );
       } else if (count == 1) {
       } else if (count == 1) {
-        console.log(
-          'joystick校验--->' + breakPointId + '-' + neighPoints[0].breakPointId,
-        );
+        // console.log(
+        //   'joystick校验--->' + breakPointId + '-' + neighPoints[0].breakPointId,
+        // );
+        console.log('handlejoysticktesttest:actionRequest-笔直'+new Date().getTime());
         return await this.moveDirect(
         return await this.moveDirect(
           playerPosition,
           playerPosition,
           closestDis,
           closestDis,
@@ -1055,6 +1062,7 @@ export class MoveService implements OnModuleInit {
           JSON.stringify(user.player.position),
           JSON.stringify(user.player.position),
         );
         );
         this.reply.actionResponses[0].actionType = actionType;
         this.reply.actionResponses[0].actionType = actionType;
+        console.log('handlejoysticktesttest:actionRequest-停止'+new Date().getTime());
         return this.reply;
         return this.reply;
       }
       }
     }
     }
@@ -1077,9 +1085,9 @@ export class MoveService implements OnModuleInit {
       } else {
       } else {
         chooseBreakPointId = neighPoints[0].breakPointId;
         chooseBreakPointId = neighPoints[0].breakPointId;
       }
       }
-      console.log(
-        'joystick镜头过渡--->' + breakPointId + '-' + chooseBreakPointId,
-      );
+      // console.log(
+      //   'joystick镜头过渡--->' + breakPointId + '-' + chooseBreakPointId,
+      // );
       //this.reply.moveOver = true;
       //this.reply.moveOver = true;
       return await this.moveCamera(
       return await this.moveCamera(
         breakPointId,
         breakPointId,
@@ -1119,6 +1127,7 @@ export class MoveService implements OnModuleInit {
       } else {
       } else {
         console.log('joystick自由--->不合并');
         console.log('joystick自由--->不合并');
       }
       }
+      console.log('handlejoysticktesttest:actionRequest-自由'+new Date().getTime());
       return this.reply;
       return this.reply;
     }
     }
     // }
     // }
@@ -1256,11 +1265,12 @@ export class MoveService implements OnModuleInit {
       const moveFramesRes = await this.cacheService.get(key);
       const moveFramesRes = await this.cacheService.get(key);
       const moveFrames = JSON.parse(moveFramesRes);
       const moveFrames = JSON.parse(moveFramesRes);
       */
       */
+      const index = this.getMoveIndex(user.camera.angle.yaw);
       const moveFrames = await this.getMoveFrames(
       const moveFrames = await this.getMoveFrames(
         appId,
         appId,
         breakPointId,
         breakPointId,
         chooseBreakPointId,
         chooseBreakPointId,
-        Math.floor(user.camera.angle.yaw / 45),
+        index,
       );
       );
       this.setCameraInfo(appId, moveFrames, breakPointId, chooseBreakPointId);
       this.setCameraInfo(appId, moveFrames, breakPointId, chooseBreakPointId);
 
 
@@ -1284,6 +1294,7 @@ export class MoveService implements OnModuleInit {
         this.reply.moveStart = true;
         this.reply.moveStart = true;
         this.sendingFrameForJoystick = true;
         this.sendingFrameForJoystick = true;
       }
       }
+      console.log('handlejoysticktesttest:actionRequest-镜头过渡'+new Date().getTime());
       return this.reply;
       return this.reply;
     }
     }
   }
   }
@@ -1345,7 +1356,7 @@ export class MoveService implements OnModuleInit {
 
 
   complementFrame(userId) {
   complementFrame(userId) {
     if (this.cameraInfos.length > 0) {
     if (this.cameraInfos.length > 0) {
-      //console.log('handlejoysticktesttest:complementFrame-1 继续'+new Date().getTime())
+      console.log('handlejoysticktesttest:complementFrame-1 继续'+new Date().getTime())
       const user = this.users[userId];
       const user = this.users[userId];
       const cameraInfo = this.cameraInfos.shift();
       const cameraInfo = this.cameraInfos.shift();
       this.reply.traceIds = [];
       this.reply.traceIds = [];
@@ -1383,55 +1394,15 @@ export class MoveService implements OnModuleInit {
       return this.reply;
       return this.reply;
     } else if (this.cameraInfos.length == 0) {
     } else if (this.cameraInfos.length == 0) {
       if (this.reply['newUserStates'][0].renderInfo.isMoving == 1) {
       if (this.reply['newUserStates'][0].renderInfo.isMoving == 1) {
-        //console.log('handlejoysticktesttest:complementFrame-2 停止1'+new Date().getTime())
+        console.log('handlejoysticktesttest:complementFrame-2 停止1'+new Date().getTime())
         return this.stopJoystick(userId);
         return this.stopJoystick(userId);
       } else {
       } else {
-        //console.log('handlejoysticktesttest:complementFrame-2 停止2'+new Date().getTime())
+        console.log('handlejoysticktesttest:complementFrame-2 停止2'+new Date().getTime())
         return null;
         return null;
       }
       }
     }
     }
   }
   }
 
 
-  complementFrames(userId) {
-    console.log(
-      'handlejoysticktesttest:complementFrames:' + this.cameraInfos.length,
-    );
-    const user = this.users[userId];
-    const replys = [];
-    while (this.cameraInfos.length > 0) {
-      const cameraInfo = this.cameraInfos.shift();
-      this.reply.traceIds = [];
-      this.reply['newUserStates'][0].userId = userId;
-      this.reply['actionResponses'][0].traceId = null;
-      this.reply['newUserStates'][0].playerState.player.angle.yaw =
-        user.player.angle.yaw;
-      this.reply['newUserStates'][0].playerState.player.position = JSON.parse(
-        JSON.stringify(user.player.position),
-      );
-      this.reply['newUserStates'][0].playerState.camera.angle = JSON.parse(
-        JSON.stringify(cameraInfo.camera_angle),
-      );
-      this.reply['newUserStates'][0].playerState.camera.position = JSON.parse(
-        JSON.stringify(cameraInfo.camera_position),
-      );
-
-      this.reply['newUserStates'][0].playerState.cameraCenter = JSON.parse(
-        JSON.stringify(user.player.position),
-      );
-      this.reply['newUserStates'][0].renderInfo.isMoving = 0;
-      this.reply['actionResponses'][0].traceId = null;
-
-      if (cameraInfo.mediaSrc) {
-        this.reply.mediaSrc = cameraInfo.mediaSrc;
-      }
-
-      this.sendingFrameForJoystick = true;
-      replys.push(this.reply);
-    }
-
-    return replys;
-  }
-
   stopJoystick(userId) {
   stopJoystick(userId) {
     console.log('handlejoysticktesttest:stopJoystick');
     console.log('handlejoysticktesttest:stopJoystick');
     this.reply.traceIds = [];
     this.reply.traceIds = [];
@@ -1717,4 +1688,19 @@ export class MoveService implements OnModuleInit {
 
 
     return inside;
     return inside;
   }
   }
+
+  getMoveIndex(angle){
+    if(angle<0){
+      angle = 360 + angle;
+    }
+
+    for(let i=0;i<8;++i){
+      if(angle<45*i+45/2){
+        return i;
+      }
+    }
+
+    //超过了337
+    return 0;
+  }
 }
 }

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

@@ -328,10 +328,10 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
             const stop = performance.now();
             const stop = performance.now();
             const inMillSeconds = stop - start;
             const inMillSeconds = stop - start;
             const rounded = Number(inMillSeconds).toFixed(3);
             const rounded = Number(inMillSeconds).toFixed(3);
-            this.logger.log(
-              `[timer]-rotate-入队列前: ${rounded}ms -->` +
-                JSON.stringify(stream),
-            );
+            // this.logger.log(
+            //   `[timer]-rotate-入队列前: ${rounded}ms -->` +
+            //     JSON.stringify(stream),
+            // );
 
 
             this.roQueue.next(stream);
             this.roQueue.next(stream);
           } else {
           } else {
@@ -364,7 +364,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
         async (frame: MovingLastUpdateType) => {
         async (frame: MovingLastUpdateType) => {
           //TODO 正在行走时,有新的reqest
           //TODO 正在行走时,有新的reqest
           if (frame) {
           if (frame) {
-            this.logger.log('行走每段最后一帧', JSON.stringify(frame));
+            //this.logger.log('行走每段最后一帧', JSON.stringify(frame));
             if (this.latestWalkingRequest && this.onMoving.value) {
             if (this.latestWalkingRequest && this.onMoving.value) {
               this.logger.log('stop-data-1', frame);
               this.logger.log('stop-data-1', frame);
               this.moveQueueSubscription.unsubscribe();
               this.moveQueueSubscription.unsubscribe();
@@ -526,7 +526,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
           const stop = performance.now();
           const stop = performance.now();
           const inMillSeconds = stop - start;
           const inMillSeconds = stop - start;
           const rounded = Number(inMillSeconds).toFixed(3);
           const rounded = Number(inMillSeconds).toFixed(3);
-          this.logger.log(`[timer]-move-入队列前:-->${rounded}ms`);
+          //this.logger.log(`[timer]-move-入队列前:-->${rounded}ms`);
 
 
           this.handleSeqMoving(seqs);
           this.handleSeqMoving(seqs);
         } else {
         } else {
@@ -709,18 +709,18 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
           this.moveService.users[this.user_id].breakPointId,
           this.moveService.users[this.user_id].breakPointId,
       );
       );
       // 有数据 [0]是rotate数据,[1-infinity]是walking数据
       // 有数据 [0]是rotate数据,[1-infinity]是walking数据
-      this.logger.log('joystickRes', JSON.stringify(joystickRes));
+      //this.logger.log('joystickRes', JSON.stringify(joystickRes));
 
 
       if (joystickRes) {
       if (joystickRes) {
         this.onJoysticking.next(true);
         this.onJoysticking.next(true);
-        console.log(
-          'handlejoysticktesttest:' +
-            joystickRes.mediaSrc +
-            ',相机坐标:' +
-            JSON.stringify(
-              joystickRes.newUserStates[0].playerState.player.position,
-            ),
-        );
+        // console.log(
+        //   'handlejoysticktesttest:' +
+        //     joystickRes.mediaSrc +
+        //     ',相机坐标:' +
+        //     JSON.stringify(
+        //       joystickRes.newUserStates[0].playerState.player.position,
+        //     ),
+        // );
         if (!this.onMoving.getValue()) {
         if (!this.onMoving.getValue()) {
           this.handlePushJoyStickSteam(joystickRes);
           this.handlePushJoyStickSteam(joystickRes);
         }
         }