xushiting 3 år sedan
förälder
incheckning
12364a72da

+ 5 - 0
src/main/java/com/fdkk/fdkkmeta/domain/po/ReplyPO.java

@@ -0,0 +1,5 @@
+package com.fdkk.fdkkmeta.domain.po;
+
+public class ReplyPO {
+
+}

+ 24 - 0
src/main/java/com/fdkk/fdkkmeta/domain/po/RotateRequestPO.java

@@ -0,0 +1,24 @@
+package com.fdkk.fdkkmeta.domain.po;
+
+import lombok.Data;
+import com.alibaba.fastjson.JSONObject;
+
+@Data
+public class RotateRequestPO {
+      		/*
+    		{
+    			"action_type":1014,
+    			"rotation_action":
+    			{
+    				"vertical_move":0,
+    				"horizontal_move":-0.020630372492836675
+    			},
+    			"trace_id":"b40a894e-cd59-4db5-8d75-a8466a0c9f15",
+    			"user_id":"0a3987974feb4"
+    		}
+    		*/
+    private int action_type = 1014;
+    private JSONObject rotation_action = new JSONObject();
+    private String trace_id = null;
+    private String user_id = null;
+}

+ 158 - 64
src/main/java/com/fdkk/fdkkmeta/grpcService/sceneGrpcServer.java

@@ -1,19 +1,15 @@
 package com.fdkk.fdkkmeta.grpcService;
 
-import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.util.ArrayUtil;
-import cn.hutool.core.util.ObjectUtil;
-import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.fdkk.fdkkmeta.config.MetaConfig;
 import com.fdkk.fdkkmeta.domain.dto.RouteDto;
 import com.fdkk.fdkkmeta.domain.entity.mysql.BreakpointsEntity;
-import com.fdkk.fdkkmeta.domain.entity.mysql.RotateFrameEntity;
-import com.fdkk.fdkkmeta.domain.entity.mysql.MoveFrameEntity;
 import com.fdkk.fdkkmeta.domain.entity.mysql.UserEntity;
 import com.fdkk.fdkkmeta.domain.po.AnglePO;
 import com.fdkk.fdkkmeta.domain.po.PointPO;
+import com.fdkk.fdkkmeta.domain.po.RotateRequestPO;
 import com.fdkk.fdkkmeta.grpc.*;
 import com.fdkk.fdkkmeta.redis.RedisCache;
 import com.fdkk.fdkkmeta.service.BreakpointsService;
@@ -22,15 +18,12 @@ import com.fdkk.fdkkmeta.service.RotateFrameService;
 import com.fdkk.fdkkmeta.service.UserService;
 import com.fdkk.fdkkmeta.util.ProtoJsonUtils;
 import com.fdkk.fdkkmeta.util.kesar.GetRoute;
-import com.google.protobuf.Message;
-import com.googlecode.protobuf.format.JsonFormat;
 import io.grpc.stub.StreamObserver;
 import lombok.extern.slf4j.Slf4j;
 import net.devh.boot.grpc.server.service.GrpcService;
 import org.springframework.beans.factory.annotation.Autowired;
 
 import java.io.File;
-import java.io.IOException;
 import java.util.List;
 
 /**
@@ -177,6 +170,7 @@ public class sceneGrpcServer extends SceneGrpcServiceGrpc.SceneGrpcServiceImplBa
     		String avatar_id = request.getAvatarId();
     		String room_id = request.getRoomId();
     		String app_id = request.getAppId();
+			Space player =request.getPlayer();
             //保存user
             UserEntity userEntity=new UserEntity();
 
@@ -186,22 +180,37 @@ public class sceneGrpcServer extends SceneGrpcServiceGrpc.SceneGrpcServiceImplBa
             userEntity.setNickName(nick_name);
             userEntity.setRoomId(room_id);
             userEntity.setSkinId(skin_id);
-            userEntity.setFrameId(1L);
-            userEntity.setBreakPointId(1L);
+			userEntity.setFrameId(1L);
+			userEntity.setBreakPointId(1L);
 			userEntity.setOnline(true);
-          //初始化的时候可以写死
+
+			Point playerPoint = player.getPosition();
+			AngleUe4 playerAngle = player.getAngle();
+			//初始化的时候可以写死
             AnglePO player_angle = new AnglePO();
-            player_angle.setPitch(0);
-            player_angle.setYaw(0);
-            player_angle.setRoll(0);
+            player_angle.setPitch(playerAngle.getPitch());
+            player_angle.setYaw(playerAngle.getYaw());
+            player_angle.setRoll(playerAngle.getRoll());
             userEntity.setPlayerAngle(player_angle);
+
+			PointPO player_position = new PointPO();
+			player_position.setX(Double.parseDouble(playerPoint.getX()));
+			player_position.setY(Double.parseDouble(playerPoint.getY()));
+			player_position.setZ(Double.parseDouble(playerPoint.getZ()));
+			userEntity.setPlayerPosition(player_position);
+
             userService.save(userEntity);
 			//todo 存入redis
-			// redisCache.set("updateFrameMetadata:"+userEntity.getUserId(),a.toJSONString());
+			//redisCache.set("updateFrameMetadata:"+userEntity.getUserId(),a.toJSONString());
 
+			NormalReply.Builder builder = NormalReply.newBuilder();
+			builder.setCode(1);
+			responseObserver.onNext(builder.build());
+			responseObserver.onCompleted();
 		}
     	catch(Exception e) {
     		e.printStackTrace();
+			//builder.setCode(0);
     	}
     }
 
@@ -220,12 +229,25 @@ public class sceneGrpcServer extends SceneGrpcServiceGrpc.SceneGrpcServiceImplBa
     			"user_id":"0a3987974feb4"
     		}
     		*/
+			RotateRequestPO rotateRequestPO = new RotateRequestPO();
+
     		int action_type = request.getActionType();
     		String trace_id = request.getTraceId();
     		String user_id = request.getUserId();
-    		RotationAction rotation_action = request.getRotationAction();
-    		double horizontal_move = rotation_action.getHorizontalMove();
+    		RotationAction rotationAction = request.getRotationAction();
+
+			JSONObject rotation_action = new JSONObject();
+			rotation_action.put("vertical_move",rotationAction.getVerticalMove());
+			rotation_action.put("horizontal_move",rotationAction.getHorizontalMove());
+
+			rotateRequestPO.setAction_type(action_type);
+			rotateRequestPO.setRotation_action(rotation_action);
+			rotateRequestPO.setTrace_id(trace_id);
+			rotateRequestPO.setUser_id(user_id);
 
+			//redisCache.setCacheObject("setCacheRequest:"+user_id,rotateRequestPO);
+
+			/*
     		//这三个变量从user表和rotateframe表里取
             UserEntity user = userService.findUserId(user_id);
 			Long breakPointId = user.getBreakPointId();
@@ -270,42 +292,110 @@ public class sceneGrpcServer extends SceneGrpcServiceGrpc.SceneGrpcServiceImplBa
             /// metaConfig.getVideoFramePath()
             log.info("VideoFramePath{}", metaConfig.getVideoFramePath());
 			NormalReply.Builder builder = NormalReply.newBuilder();
-//			for (int i = 0; i < 100; i++) {
-//				builder.addActionResponses(0);//这个要查查
-//			}
-
-			builder.addTraceIds(trace_id);
-			//builder.setVehicle(null);
-			builder.setVehicle("");
-			builder.addNewUserStates(userState);
-			builder.addActionResponses(0);//这个要查查
-			builder.addNewUserStates(userState);
-
-			builder.setVehicle("");
-			builder.setGetStateType(0);
-			builder.setCode(0);
-			builder.setMsg("OK");
-			builder.setFrameSrc(frameSrc); //从数据库中获取对应的路径
+			builder.setCode(1);
+//			builder.addTraceIds(trace_id);
+//			//builder.setVehicle(null);
+//			builder.setVehicle("");
+//			builder.addNewUserStates(userState);
+//			builder.addActionResponses(0);//这个要查查
+//			builder.addNewUserStates(userState);
+//
+//			builder.setVehicle("");
+//			builder.setGetStateType(0);
+//			builder.setCode(0);
+//			builder.setMsg("OK");
+//			builder.setFrameSrc(frameSrc); //从数据库中获取对应的路径
 	        responseObserver.onNext(builder.build());
 	        responseObserver.onCompleted();
+	        */
+			NormalReply.Builder builder = NormalReply.newBuilder();
+			builder.setCode(1);
+			responseObserver.onNext(builder.build());
+			responseObserver.onCompleted();
     	}
     	catch(Exception e) {
     		e.printStackTrace();
+			//builder.setCode(0);
     	}
     }
+	public void echo(EchoRequest request, StreamObserver<EchoReply> responseObserver){
+
+		int action_type = request.getActionType();
+		String trace_id = request.getTraceId();
 
+		EchoReply.Builder builder = EchoReply.newBuilder();
+		builder.setActionType(action_type);
+		builder.setPointType(100);
+		builder.setExtra("");
+		builder.setTraceId(trace_id);
+		builder.setPacketId("");
+		//builder.setNps(nps);
+		builder.setPeopleNum(0);
+		builder.setZoneId("");
+		builder.setEchoMsg("");
+		builder.setReserveDetail(null);
+		//builder.setUserWithAvatarList();
+		//builder.setNewUserStates();
+		builder.setCode(0);
+		builder.setMsg("");
+
+		responseObserver.onNext(builder.build());
+		responseObserver.onCompleted();
+	}
+	public void usersState(RotateRequest request, StreamObserver<GetNewUserStateReply> responseObserver){
+
+		int action_type = request.getActionType();
+		String trace_id = request.getTraceId();
+		String user_id = request.getUserId();
+
+		//从数据库中取全部在线的user表
+		List<UserEntity> list =  userService.findUserOnline(true);
+
+		GetNewUserStateReply.Builder builder = GetNewUserStateReply.newBuilder();
+		builder.setActionType(action_type);
+		builder.setPointType(100);
+		builder.setExtra("");
+		builder.setTraceId(trace_id);
+		builder.setPacketId("");
+		//builder.setNps(nps);
+		builder.setPeopleNum(0);
+		builder.setZoneId("");
+		builder.setEchoMsg("");
+		builder.setReserveDetail(null);
+		//builder.setUserWithAvatarList();
+		if(list.size()>0){
+			for(int i=0;i<list.size();++i){
+				UserEntity user = list.get(i);
+				JSONObject userInfo = new JSONObject();
+			    userInfo.put("roomTypeId","");
+				userInfo.put("person",0);
+				userInfo.put("avatarId",user.getAvatarId());
+				userInfo.put("skinId",user.getSkinId());
+				userInfo.put("roomId",user.getRoomId());
+				userInfo.put("isHost",false);
+				userInfo.put("isFollowHost",false);
+							userInfo.put("skinDataVersion","");
+							
 
+			}
+		}
+										//builder.setNewUserStates();
+		builder.setCode(0);
+		builder.setMsg("");
+
+		responseObserver.onNext(builder.build());
+		responseObserver.onCompleted();
+	}
+	/*
     //返回的是角度矫正数据
     @Override
     public void moveStart(StartMoveRequest request, StreamObserver<MoveReply> responseObserver)   {
      	try {
-        	/*
-        	 * 1.从user表里获得当前人物所在的breakPoint_id
-        	 * 2.根据breakPoint_id,从breakpoints表里获得对应的起始坐标
-        	 * 3.根据request中的clicking_action里的clicking_point(目的地)以及当前起始坐标计算出路径
-        	 * 4.返回整个路径的一段
-        	 *
-        	 * */
+        	 // 1.从user表里获得当前人物所在的breakPoint_id
+        	 // 2.根据breakPoint_id,从breakpoints表里获得对应的起始坐标
+        	 // 3.根据request中的clicking_action里的clicking_point(目的地)以及当前起始坐标计算出路径
+        	 // 4.返回整个路径的一段
+
      		int action_type= request.getActionType();
      		ClickingAction clicking_action = request.getClickingAction();
      		Point end = clicking_action.getClickingPoint();
@@ -459,13 +549,11 @@ public class sceneGrpcServer extends SceneGrpcServiceGrpc.SceneGrpcServiceImplBa
     @Override
     public void moveProcess(MoveNextNeighborRequest request, StreamObserver<MoveReply> responseObserver)   {
      	try {
-        	/*
-        	 * 1.从user表里获得当前人物所在的breakPoint_id
-        	 * 2.根据breakPoint_id,从breakpoints表里获得对应的起始坐标
-        	 * 3.根据request中的clicking_action里的clicking_point(目的地)以及当前起始坐标计算出路径
-        	 * 4.返回整个路径的一段
-        	 *
-        	 * */
+        	 // 1.从user表里获得当前人物所在的breakPoint_id
+        	 // 2.根据breakPoint_id,从breakpoints表里获得对应的起始坐标
+        	 // 3.根据request中的clicking_action里的clicking_point(目的地)以及当前起始坐标计算出路径
+        	 // 4.返回整个路径的一段
+
      		String user_id = request.getUserId();
      		String trace_id = request.getTraceId();
      		boolean needNext = request.getNext();
@@ -546,6 +634,7 @@ public class sceneGrpcServer extends SceneGrpcServiceGrpc.SceneGrpcServiceImplBa
     		e.printStackTrace();
     	}
     }
+	*/
 
     @Override
     public void getBreakPoint(BreakPointRequest request, StreamObserver<BreakPointReply> responseObserver)   {
@@ -620,7 +709,10 @@ public class sceneGrpcServer extends SceneGrpcServiceGrpc.SceneGrpcServiceImplBa
 			log.info("breakpointsEntity-getContact",breakpointsEntity.getContact());
 			//找到与角度move_angle最近的邻居点
      		//移动player,并且更新相机角度
-
+			NormalReply.Builder builder = NormalReply.newBuilder();
+			builder.setCode(1);
+			responseObserver.onNext(builder.build());
+			responseObserver.onCompleted();
     	}
     	catch(Exception e) {
     		e.printStackTrace();
@@ -638,32 +730,34 @@ public class sceneGrpcServer extends SceneGrpcServiceGrpc.SceneGrpcServiceImplBa
     	return userState;
     }
 
-    private State createPlayerState(Space player,Space camera,Point cameraCenter) {
+    private State createPlayerState(JSONObject userInfo) {
 		State.Builder builder = State.newBuilder();
-		builder.setRoomTypeId("");
+		builder.setRoomTypeId(userInfo.getString("roomTypeId"));
 		builder.setPerson(0);
-		builder.setAvatarId("");
-		builder.setSkinId("");
-		builder.setRoomId("");
+		builder.setAvatarId(userInfo.getString("avatarId"));
+		builder.setSkinId(userInfo.getString("skinId"));
+		builder.setRoomId(userInfo.getString("roomId"));
 		builder.setIsHost(false);
 		builder.setIsFollowHost(false);
-		builder.setSkinDataVersion("");
+		builder.setSkinDataVersion(userInfo.getString("skinDataVersion"));
 		builder.setAvatarComponents("");
-		builder.setNickName("");
+		builder.setNickName(userInfo.getString("nickName"));
 		builder.setMovingMode(0);
-		builder.setAttitude("");
+		builder.setAttitude("walk");
 		builder.setAreaName("");
-		builder.setPathName("");
-		builder.setPathId("");
+		builder.setPathName("thirdwalk");
+		builder.setPathId("thirdwalk");
 		builder.setAvatarSize(1);
-		builder.setExtra("");
+		if(userInfo.get("extra") != null){
+			builder.setExtra((Extra)userInfo.get("extra"));
+		}
 		builder.setPrioritySync(false);
-		builder.setPlayer(player);
-		if(camera != null){
-			builder.setCamera(camera);
+		builder.setPlayer((Space)userInfo.get("player"));
+		if(userInfo.get("camera") != null){
+			builder.setCamera((Space)userInfo.get("camera"));
 		}
-		if(cameraCenter!=null){
-			builder.setCameraCenter(cameraCenter);
+		if(userInfo.get("cameraCenter") != null){
+			builder.setCamera((Space)userInfo.get("cameraCenter"));
 		}
     	return builder.build();
     }

+ 1 - 0
src/main/java/com/fdkk/fdkkmeta/task/UpdateFrameMetaTask.java

@@ -33,6 +33,7 @@ public class UpdateFrameMetaTask {
        //使用并行流处理数据
        userOnline.parallelStream().forEach(
                userEntity -> {
+                   //UserEntity user = redisCache.getCacheObject("setCacheRequest:" + userEntity.getUserId());
 //                   redisCache.set("updateFrameMetadata:"+userEntity.getUserId(),a.toJSONString());
                }
        );

+ 8 - 4
src/main/proto/scene.proto

@@ -62,7 +62,7 @@ message SceneReply {
 /**********************************************************/
 // 正常出参对象
 message NormalReply {
-  string code=1;                                       //0/1   0表示没收到,1表示收到
+  int32 code=1;                                       //0/1   0表示没收到,1表示收到
 }
 
 /**********************************************************/
@@ -72,6 +72,9 @@ message Space {
    Point position=1;
    AngleUe4 angle=2;
 }
+message Extra{
+   bool removeWhenDisconnected=1;
+}
 
 message State {
    string roomTypeId=1;
@@ -90,7 +93,7 @@ message State {
    string pathName=14;
    string pathId=15;
    int32 avatarSize=16;
-   string extra=17;
+   Extra extra=17;
    bool prioritySync=18;
    Space player=19;
    Space camera=20;
@@ -138,15 +141,16 @@ message InitRequest {
   string avatar_id=4;
   string room_id=5;
   string app_id=6;
+  Space player=7;
 }
 /**********************************************************/
-message echoMsg{
+message EchoMsg{
   string echoMsg=1;
 }
 
 message EchoRequest{
   int32 action_type=1;   //1009
-  echoMsg echo_msg=2;
+  EchoMsg echo_msg=2;
   string trace_id=3;
   string user_id=4;
 }