gemercheung 3 years ago
parent
commit
e28aabb9dd

+ 10 - 4
src/get-router/get-router.service.ts

@@ -24,6 +24,7 @@ export class GetRouterService implements OnModuleInit {
   }
 
   searchRoad(appId, startPointId, clicking_point) {
+    console.log('进入2 - searchRoad');
     //表示终点
     let endPoint;
 
@@ -52,7 +53,7 @@ export class GetRouterService implements OnModuleInit {
     }
 
     if (minDis > 100) {
-      return [];
+      return null;
     }
 
     // const startPointRes = await this.cacheService.get(
@@ -92,7 +93,10 @@ export class GetRouterService implements OnModuleInit {
       //   G: currentPointInfo.G,
       // };
       closeList.push(currentPoint);
-
+      if (closeList.length > 10000) {
+        console.log('错误过渡路径:', closeList.length);
+        return null;
+      }
       //读redis里的数据
       // const breakPointRes = await this.cacheService.get(
       //   'breakpoints:app_id:' +
@@ -162,13 +166,15 @@ export class GetRouterService implements OnModuleInit {
         currentObj.contact.indexOf(startPointId) < 0
       );
     }
-    if (result.length > 50) {
+    if (result.length > 30) {
       console.log('错误过渡路径:' + result);
-      debugger;
+      // debugger;
+      return null;
     }
     result.unshift(currentObj.breakPointId);
     result.unshift(startPointId);
     console.log('过渡路径:' + result);
+    debugger;
     return result;
   }
 

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

@@ -24,7 +24,7 @@ export class RotateService {
       breakPointId: null,
       roomId: null,
       player: {
-        position: { x: 800.0, y: 300.0, z: 0.0 },
+        position: { x: -800.0, y: 100.0, z: 0.0 },
         angle: {
           pitch: 0,
           yaw: 0,
@@ -32,7 +32,7 @@ export class RotateService {
         },
       },
       camera: {
-        position: { x: 368.6542053222656, y: 323.94207763671875, z: 120.0 },
+        position: { x: -1139.3031005859375, y: 99.99999237060548, z: 120.0 },
         angle: {
           pitch: 0,
           yaw: 0,
@@ -50,7 +50,7 @@ export class RotateService {
 
     user.appId = app_id;
     user.userId = userId;
-    user.breakPointId = 10;
+    user.breakPointId = 93;
     this.users[userId] = user;
 
     const reply = {

+ 54 - 47
src/scene/scene.service.ts

@@ -59,8 +59,8 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
   private clickQueueSub: any;
 
   private streamServiceSub: any;
-  private roRequestQueue: RxQueue = new DelayQueue(20);
-  private roQueue: RxQueue = new DelayQueue(10);
+  private roRequestQueue: RxQueue = new DelayQueue(25);
+  private roQueue: RxQueue = new DelayQueue(6);
   private clickQueue: RxQueue = new DebounceQueue(500);
   private moveQueue: RxQueue = new DelayQueue(20);
   private joystickQueue: RxQueue = new DebounceQueue(500);
@@ -82,43 +82,43 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
   });
   public users = {};
 
-  initUsers(app_id, userId) {
-    const user = {
-      appId: null,
-      userId: null,
-      breakPointId: null,
-      roomId: null,
-      player: {
-        position: { x: -700, y: 0, z: 0 },
-        angle: {
-          pitch: 0,
-          yaw: 0,
-          roll: 0,
-        },
-      },
-      camera: {
-        position: { x: -1145, y: 0, z: 160 },
-        angle: {
-          pitch: 0,
-          yaw: 0,
-          roll: 0,
-        },
-      },
-      rotateInfo: {
-        frameIndex: 0,
-        horizontal_move: 0,
-        mediaSrc: null,
-      },
-      moveInfo: {},
-      // traceIds: [],
-      // actionResponses:[]
-    };
-
-    user.appId = app_id;
-    user.userId = userId;
-    user.breakPointId = 100;
-    this.users[userId] = user;
-  }
+  // initUsers(app_id, userId) {
+  //   const user = {
+  //     appId: null,
+  //     userId: null,
+  //     breakPointId: null,
+  //     roomId: null,
+  //     player: {
+  //       position: { x: -700, y: 0, z: 0 },
+  //       angle: {
+  //         pitch: 0,
+  //         yaw: 0,
+  //         roll: 0,
+  //       },
+  //     },
+  //     camera: {
+  //       position: { x: -1145, y: 0, z: 160 },
+  //       angle: {
+  //         pitch: 0,
+  //         yaw: 0,
+  //         roll: 0,
+  //       },
+  //     },
+  //     rotateInfo: {
+  //       frameIndex: 0,
+  //       horizontal_move: 0,
+  //       mediaSrc: null,
+  //     },
+  //     moveInfo: {},
+  //     // traceIds: [],
+  //     // actionResponses:[]
+  //   };
+
+  //   user.appId = app_id;
+  //   user.userId = userId;
+  //   user.breakPointId = 100;
+  //   this.users[userId] = user;
+  // }
 
   onModuleInit(): void {
     this.sceneGrpcService =
@@ -156,6 +156,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
 
   public resumeStream(): void {
     this.onMoving.next(false);
+    this.onRotating.next(false);
     this.isHoldingStream = false;
     this.moveframeCnt = -1;
     this.rotateframeCnt = -1;
@@ -328,11 +329,17 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
       // if (!this.clickQueueSub) {
       this.clickQueueSub = this.clickQueue.subscribe(async (request) => {
         const user = this.moveService.users[this.user_id];
+        console.log('进入1 - searchRoad');
         const path = await this.getRouterService.searchRoad(
           user.appId,
           user.breakPointId,
           req.clicking_action.clicking_point,
         );
+        if (!path) {
+          console.log('不存在--path', path);
+          this.resumeStream();
+          return;
+        }
         // debugger;
         const walkingRes = await this.moveService.move(path, request);
 
@@ -453,15 +460,15 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
       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;
+      //TODO IDR
+      const random_index = index === 0 ? 1 : 3;
+      console.log('move frame DIR %s', random_index);
       const stream: StreamFrameType = {
         frame: -1,
         clipPath: clipPath,
         metaData: JSON.stringify(frame),
         serverTime: this.mockserverTime,
-        DIR: 3,
+        DIR: random_index,
         type: type,
       };
       this.moveQueue.next(stream);
@@ -478,10 +485,10 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
       this.walkingSub.unsubscribe();
       this.walkingSub = null;
     }
-    if (this.clickQueueSub) {
-      this.clickQueueSub.unsubscribe();
-      this.clickQueueSub = null;
-    }
+    // if (this.clickQueueSub) {
+    //   this.clickQueueSub.unsubscribe();
+    //   this.clickQueueSub = null;
+    // }
   }
   handleMoveSteam() {
     this.moveQueueSubscription = this.moveQueue.subscribe(

+ 1 - 0
src/scene/stream/stream.service.ts

@@ -95,6 +95,7 @@ export class StreamService {
     return new Promise((resolve, reject) => {
       try {
         // console.log('process.env', process.env.node_env);
+        //TODO 开发替换path
         // const src = stream.clipPath.replace('/mnt/metaverse/scene', '');
         // const srcTmp = join(__dirname, `../ws/${src}`);
         // const clipPath = srcTmp;