gemercheung 3 gadi atpakaļ
vecāks
revīzija
acb5df2f97
4 mainītis faili ar 87 papildinājumiem un 75 dzēšanām
  1. 18 18
      config.yaml
  2. 17 14
      src/move/move.service.ts
  3. 16 14
      src/rotate/rotate.service.ts
  4. 36 29
      src/scene/scene.service.ts

+ 18 - 18
config.yaml

@@ -3,32 +3,32 @@ http:
   port: 6688
 
 
-grpc:
-  url: '221.4.210.172:23000'
 # grpc:
-#   url: '192.168.0.47:3000'
+#   url: '221.4.210.172:23000'
+grpc:
+  url: '192.168.0.200:3000'
+
+# redis:
+#   port: 26379
+#   host: '221.4.210.172' #远程调试需要设置bindip 为0.0.0.0 并且设置密码
+#   password: '' # 非远程不需要密码
+#   decode_responses: true
+#   db: 9
 
 redis:
-  port: 26379
-  host: '120.24.252.95' #远程调试需要设置bindip 为0.0.0.0 并且设置密码
-  password: 'sxz123321SxZ@' # 非远程不需要密码
+  port: 6379
+  host: '192.168.0.47' #远程调试需要设置bindip 为0.0.0.0 并且设置密码
+  password: '' # 非远程不需要密码
   decode_responses: true
   db: 9
 
 queueRedis:
-  port: 26379
-  host: '120.24.252.95' #远程调试需要设置bindip 为0.0.0.0 并且设置密码
-  password: 'sxz123321SxZ@' # 非远程不需要密码
+  port: 6379
+  host: 'localhost' #远程调试需要设置bindip 为0.0.0.0 并且设置密码
+  password: 'redis9394' # 非远程不需要密码
   decode_responses: true
   db: 14
 
-# redis:
-#   port: 6379
-#   host: '192.168.0.47' #远程调试需要设置bindip 为0.0.0.0 并且设置密码
-#   password: '' # 非远程不需要密码
-#   decode_responses: true
-#   db: 9
-
 stun:
   server: ['stun:172.18.156.41:3478', 'stun:120.24.252.95:3478']
   portRangeBegin: 52000
@@ -38,9 +38,9 @@ server:
   private_ip: 172.18.197.114
   public_ip: 120.24.252.95
 
-
+  
 # PRIVATE_IP=172.18.197.114
 # PUBLIC_IP=120.24.252.95
 # STUNS_SEVER="stun:172.18.156.41:3478,stun:120.24.252.95:3478"
 # GRPC_URL="192.168.0.48:3000"
-# REDIS_URL="redis://:192.168.0.47:6379/9"
+# REDIS_URL="redis://:192.168.0.47:6379/9"

+ 17 - 14
src/move/move.service.ts

@@ -149,9 +149,8 @@ export class MoveService {
 
       const appId = user.appId;
       const path = pathArray || [100, 101, 102]; //需要计算路径
-      const angle = user.camera.angle.yaw % 45; //纠正需要
-      const index = Math.round(user.camera.angle.yaw / 45); //过渡需要
-
+      const angle = user.camera.angle.yaw % 44; //纠正需要
+      console.log('矫正前-相机:'+user.camera.angle.yaw);
       const replys = {};
       const traceIds = [];
       traceIds.push(traceId);
@@ -182,7 +181,8 @@ export class MoveService {
       this.reply.traceIds = traceIds;
       this.reply['newUserStates'][0].userId = userId;
       this.reply['actionResponses'][0].traceId = traceId;
-
+      console.log('矫正后-相机:'+user.camera.angle.yaw);
+      const index = Math.round(user.camera.angle.yaw / 44); //过渡需要
       for (let i = 0; i < path.length - 1; ++i) {
         let pathReplys = [];
         const start_break_point_id = path[i];
@@ -440,6 +440,7 @@ export class MoveService {
       const userId = actionRequest['user_id'];
       const traceId = actionRequest['trace_id'];
       const dir_action = actionRequest['dir_action'];
+      const actionType = actionRequest['action_type'];
       const user = this.users[userId];
 
       const appId = user.appId;
@@ -513,18 +514,20 @@ export class MoveService {
           traceIds.push(traceId);
 
           const checkReplys = [];
-          angle = user.camera.angle.yaw % 45; //纠正需要
+          angle = user.camera.angle.yaw % 44; //纠正需要
           for (let i = 0; i < angle; ++i) {
-            //let reply = rotateService.rotateForAngle(userId,(angle+i)%359);
-            //reply.traceIds = [];
-            //reply.traceIds.push(traceId);
-            //let actionResponse = rotateService.createActionResponse(actionType,trace_id);
-            //reply.actionResponses = [];
-            //reply.actionResponses.push(actionResponse);
-            //checkReplys.push(reply);
+            const reply = await this.rotateService.rotateForAngle(userId, 1);
+            reply.traceIds = [];
+            reply.traceIds.push(traceId);
+            const actionResponse = this.rotateService.createActionResponse(
+              actionType,
+              traceId,
+            );
+            reply.actionResponses = [];
+            reply.actionResponses.push(actionResponse);
+            checkReplys.push(reply);
           }
           replys.push(checkReplys);
-
           //过渡
           //读redis里的数据,按照frame_index的大小排序
           const key =
@@ -535,7 +538,7 @@ export class MoveService {
             ':end_break_point_id:' +
             chooseBreakPointId +
             ':angle:' +
-            (user.camera.angle % 45);
+            (user.camera.angle % 44);
           const moveFramesRes = await this.cacheService.get(key);
           if (moveFramesRes == null) {
             return replys;

+ 16 - 14
src/rotate/rotate.service.ts

@@ -155,7 +155,7 @@ export class RotateService {
         this.actionRequestPool[userId].push(actionRequest);
       }
 
-      const reply = this.replies[userId];
+      let reply = this.replies[userId];
 
       const actionRequests = this.actionRequestPool[userId];
       const user = this.users[userId];
@@ -179,14 +179,15 @@ export class RotateService {
       }
 
       actionRequests.splice(0, sub);
-      const hAngle = horizontal_move * 60;
+      const hAngle = horizontal_move * 90;
       if (Math.abs(hAngle) < 1) {
         user.rotateInfo.horizontal_move = horizontal_move;
         //user.traceIds = traceIds;
         this.replies[userId] = reply;
         return null;
       }
-      return this.rotateForAngle(userId, hAngle);
+      reply = await this.rotateForAngle(userId, Math.floor(hAngle));
+      return reply;
       /*
       user.rotateInfo.frameIndex += Math.floor(hAngle);
       if (user.rotateInfo.frameIndex < 0) {
@@ -265,13 +266,13 @@ export class RotateService {
         ':break_point_id:' +
         user.breakPointId;
       // const value = null;
-      console.log('矫正:'+key);
+
       const redisData = await this.cacheService.get(key);
-      if (redisData && redisData.length > 0) {
-        const value = redisData ? JSON.parse(redisData) : null;
+      //if (redisData && redisData.length > 0) {
+        const value = JSON.parse(redisData); //redisData ? JSON.parse(redisData) : null;
         // console.log('rotate-service', value);
-        user.camera['position'] = value ? value.cameraPosition : '';
-        //user.camera['angle'] = value ? value.cameraAngle : '';
+        user.camera['position'] = value.cameraPosition;//value ? value.cameraPosition : '';
+        user.camera['angle'] = value.cameraAngle;//value ? value.cameraAngle : '';
 
         reply['newUserStates'][0]['playerState'].player.position =
           user.player.position;
@@ -280,9 +281,9 @@ export class RotateService {
 
         //this.reply['newUserStates'][0]['playerState'] .player
         reply['newUserStates'][0]['playerState'].camera.position =
-          user.camera['position'];
+        value.cameraPosition;
         reply['newUserStates'][0]['playerState'].camera.angle =
-          user.camera['angle'];
+        value.cameraAngle;
         reply['newUserStates'][0]['playerState'].cameraCenter =
           user.player.position;
         // debugger
@@ -302,11 +303,12 @@ export class RotateService {
         this.replies[userId].actionResponses = [];
 
         user.rotateInfo.horizontal_move = 0;
-
+  
         return reply;
-      } else {
-        return null;
-      }
+      //} 
+      // else {
+      //   return null;
+      // }
     } catch (error) {
       this.logger.error('rotateForAngle::function', error);
     }

+ 36 - 29
src/scene/scene.service.ts

@@ -278,7 +278,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
               DIR: random_boolean ? 1 : 3,
             };
             this.rotateQueue.add(stream, {
-              delay: 10,
+              delay: 5,
               jobId: `rotate:${this.user_id}:${this.frameCnt.getValue()}`,
               removeOnComplete: true,
             });
@@ -294,8 +294,11 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
     }
   }
 
-  joystick(request: JoystickRequest) {
-    return this.sceneGrpcService.joystick(request);
+  async joystick(request: JoystickRequest) {
+    console.log('JoystickRequest', request);
+    const res = await this.moveService.joystick(request);
+    console.log('res', res);
+    // return this.sceneGrpcService.joystick(request);
   }
 
   handleDataChanelOpen(channel: DataChannel): void {
@@ -337,6 +340,10 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
               const walk = msg;
               this.walking(walk);
               break;
+            case ActionType.joystick:
+              const JoystickRequest = msg as any as JoystickRequest;
+              this.joystick(JoystickRequest);
+              break;
             case ActionType.breathPoint:
               this.handleBreath(msg);
               break;
@@ -559,32 +566,32 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
       }
     });
   }
-  // handleRotateStream() {
-  //   this.roQueueSubscription = this.roQueue.subscribe(
-  //     async (stream: StreamFrameType) => {
-  //       this.rotateTimeStamp = Date.now();
-
-  //       stream.frame = this.rotateframeCnt;
-  //       console.log('[media]', stream.clipPath);
-  //       this.logger.log(
-  //         `roQueueSubscription:frame:${this.rotateframeCnt}  ` +
-  //         JSON.stringify(stream.metaData),
-  //       );
-  //       // await this.streamService.pushFrameToSteam(stream);
-  //       setTimeout(() => {
-  //         const now = Date.now();
-  //         if (now - this.rotateTimeStamp > this.rotatePeriod) {
-  //           console.log('rotate end');
-  //           // const next = this.rotateframeCnt + 1;
-  //           // this.resumeStream(next);
-  //           // this.rotateframeCnt = -1;
-  //           // this.onMoving = false;
-  //           // this.onRotating = false;
-  //         }
-  //       }, 300);
-  //     },
-  //   );
-  // }
+  handleRotateStream() {
+    this.roQueueSubscription = this.roQueue.subscribe(
+      async (stream: StreamFrameType) => {
+        this.rotateTimeStamp = Date.now();
+
+        stream.frame = this.rotateframeCnt;
+        console.log('[media]', stream.clipPath);
+        this.logger.log(
+          `roQueueSubscription:frame:${this.rotateframeCnt}  ` +
+          JSON.stringify(stream.metaData),
+        );
+        // await this.streamService.pushFrameToSteam(stream);
+        setTimeout(() => {
+          const now = Date.now();
+          if (now - this.rotateTimeStamp > this.rotatePeriod) {
+            console.log('rotate end');
+            // const next = this.rotateframeCnt + 1;
+            // this.resumeStream(next);
+            // this.rotateframeCnt = -1;
+            // this.onMoving = false;
+            // this.onRotating = false;
+          }
+        }, 300);
+      },
+    );
+  }
 
   cleanMoveSteam() {
     if (this.moveQueueSubscription) {