11
This commit is contained in:
parent
8ba604b3b9
commit
0dc1413988
|
@ -194,8 +194,6 @@ func (l *DataTransferLogic) setConnPool(conn *websocket.Conn, userInfo *auth.Use
|
||||||
userId: userInfo.UserId,
|
userId: userInfo.UserId,
|
||||||
guestId: userInfo.GuestId,
|
guestId: userInfo.GuestId,
|
||||||
extendRenderProperty: extendRenderProperty{
|
extendRenderProperty: extendRenderProperty{
|
||||||
//renderImageTask: make(map[string]*renderTask),
|
|
||||||
//renderImageTaskCtlChan: make(chan renderImageControlChanItem, renderImageTaskCtlChanLen),
|
|
||||||
renderChan: make(chan []byte, renderChanLen),
|
renderChan: make(chan []byte, renderChanLen),
|
||||||
renderConsumeTickTime: 1, //默认1纳秒,后面需要根据不同用户不同触发速度
|
renderConsumeTickTime: 1, //默认1纳秒,后面需要根据不同用户不同触发速度
|
||||||
},
|
},
|
||||||
|
|
|
@ -19,8 +19,6 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
//每个websocket连接渲染任务调度队列长度默认值(添加任务/删除任务/修改任务属性)缓冲队列长度(该队列用于避免map并发读写冲突)
|
|
||||||
renderImageTaskCtlChanLen = 100
|
|
||||||
//每个websocket渲染任务缓冲队列长度默认值
|
//每个websocket渲染任务缓冲队列长度默认值
|
||||||
renderChanLen = 500
|
renderChanLen = 500
|
||||||
)
|
)
|
||||||
|
@ -31,29 +29,10 @@ type renderProcessor struct {
|
||||||
|
|
||||||
// 云渲染属性
|
// 云渲染属性
|
||||||
type extendRenderProperty struct {
|
type extendRenderProperty struct {
|
||||||
//renderImageTask map[string]*renderTask //需要渲染的图片任务 key是taskId val 是renderId
|
|
||||||
//renderImageTaskCtlChan chan renderImageControlChanItem //渲染任务新增/回调结果移除任务/更新渲染耗时属性的控制通道(由于任务map无法读写并发)
|
|
||||||
renderChan chan []byte //渲染消息入口的缓冲队列
|
renderChan chan []byte //渲染消息入口的缓冲队列
|
||||||
renderConsumeTickTime time.Duration //消费渲染消息时钟间隔(纳秒),用于后期控制不同类型用户渲染速度限制
|
renderConsumeTickTime time.Duration //消费渲染消息时钟间隔(纳秒),用于后期控制不同类型用户渲染速度限制
|
||||||
}
|
}
|
||||||
|
|
||||||
// 渲染任务新增移除的控制通道的数据
|
|
||||||
/*type renderImageControlChanItem struct {
|
|
||||||
option int // 0删除 1添加 2修改耗时属性
|
|
||||||
taskId string //map的key(必须传)
|
|
||||||
renderId string // map的val(增加任务时候传)
|
|
||||||
renderNotifyImageUrl string //渲染回调数据(删除任务时候传)
|
|
||||||
taskProperty renderTask //渲染任务的属性
|
|
||||||
}*/
|
|
||||||
|
|
||||||
// 渲染任务属性
|
|
||||||
/*type renderTask struct {
|
|
||||||
renderId string //渲染id(新增任务传)
|
|
||||||
unityRenderBeginTime int64 //发送给unity时间
|
|
||||||
unityRenderEndTime int64 //unity回调结果时间
|
|
||||||
uploadUnityRenderImageTakesTime int64 //上传unity渲染结果图时间
|
|
||||||
}*/
|
|
||||||
|
|
||||||
// 处理分发到这里的数据
|
// 处理分发到这里的数据
|
||||||
func (r *renderProcessor) allocationMessage(w *wsConnectItem, data []byte) {
|
func (r *renderProcessor) allocationMessage(w *wsConnectItem, data []byte) {
|
||||||
//logx.Info("收到渲染任务消息:", string(data))
|
//logx.Info("收到渲染任务消息:", string(data))
|
||||||
|
@ -128,21 +107,6 @@ func (w *wsConnectItem) renderImage(data []byte) {
|
||||||
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "该产品不可定制", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0)
|
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "该产品不可定制", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
//获取用户需要渲染logo
|
|
||||||
/*logoInfo, err := w.logic.svcCtx.Repositories.ImageHandle.LogoInfo(w.logic.ctx, &repositories.LogoInfoReq{
|
|
||||||
UserId: w.userId,
|
|
||||||
GuestId: w.guestId,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "获取用户logo素材错误", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0)
|
|
||||||
logx.Error(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if logoInfo == nil || logoInfo.LogoUrl == nil {
|
|
||||||
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "用户logo素材url是空的", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
renderImageData.RenderData.Logo = *logoInfo.LogoUrl*/
|
|
||||||
//用户id赋值
|
//用户id赋值
|
||||||
renderImageData.RenderData.UserId = w.userId
|
renderImageData.RenderData.UserId = w.userId
|
||||||
renderImageData.RenderData.GuestId = w.guestId
|
renderImageData.RenderData.GuestId = w.guestId
|
||||||
|
@ -253,9 +217,6 @@ func (w *wsConnectItem) renderImage(data []byte) {
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
//###########################################
|
|
||||||
//把需要渲染的图片任务加进去
|
|
||||||
//w.createRenderTask(taskId, renderImageData.RenderId)
|
|
||||||
//组装数据
|
//组装数据
|
||||||
if err = w.assembleRenderDataToUnity(taskId, combineImage, renderImageData, productTemplate, model3dInfo, element, productSize); err != nil {
|
if err = w.assembleRenderDataToUnity(taskId, combineImage, renderImageData, productTemplate, model3dInfo, element, productSize); err != nil {
|
||||||
logx.Error("组装数据失败:", err)
|
logx.Error("组装数据失败:", err)
|
||||||
|
@ -447,15 +408,12 @@ func (w *wsConnectItem) assembleRenderDataToUnity(taskId string, combineImage st
|
||||||
"render_data": sendData,
|
"render_data": sendData,
|
||||||
}
|
}
|
||||||
postDataBytes, _ := json.Marshal(postData)
|
postDataBytes, _ := json.Marshal(postData)
|
||||||
//unityRenderBeginTime := time.Now().UTC().UnixMilli()
|
|
||||||
_, err = curl.ApiCall(url, "POST", header, bytes.NewReader(postDataBytes), time.Second*10)
|
_, err = curl.ApiCall(url, "POST", header, bytes.NewReader(postDataBytes), time.Second*10)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.renderErrResponse(info.RenderId, info.RenderData.TemplateTag, taskId, "请求unity接口失败", info.RenderData.ProductId, w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productSize.Id, *productTemplate.ElementModelId)
|
w.renderErrResponse(info.RenderId, info.RenderData.TemplateTag, taskId, "请求unity接口失败", info.RenderData.ProductId, w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productSize.Id, *productTemplate.ElementModelId)
|
||||||
logx.Error("failed to send data to unity")
|
logx.Error("failed to send data to unity")
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
//记录发送到unity时间
|
|
||||||
//w.modifyRenderTaskProperty(taskId, renderTask{unityRenderBeginTime: unityRenderBeginTime})
|
|
||||||
//发送运行阶段消息
|
//发送运行阶段消息
|
||||||
w.sendRenderDataToUnityStepResponseMessage(info.RenderId)
|
w.sendRenderDataToUnityStepResponseMessage(info.RenderId)
|
||||||
logx.Info("发送到unity成功,刀版图:", combineImage /*, " 请求unity的数据:", string(postDataBytes)*/)
|
logx.Info("发送到unity成功,刀版图:", combineImage /*, " 请求unity的数据:", string(postDataBytes)*/)
|
||||||
|
@ -500,75 +458,6 @@ func (w *wsConnectItem) sendRenderResultData(data websocket_data.RenderImageRspM
|
||||||
w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_RENDER_IMAGE, data))
|
w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_RENDER_IMAGE, data))
|
||||||
}
|
}
|
||||||
|
|
||||||
/*// 增加渲染任务
|
|
||||||
func (w *wsConnectItem) createRenderTask(taskId, renderId string) {
|
|
||||||
if taskId == "" {
|
|
||||||
logx.Error("task_id不能为空")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if renderId == "" {
|
|
||||||
logx.Error("render_id不能为空")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
data := renderImageControlChanItem{
|
|
||||||
option: 1,
|
|
||||||
taskId: taskId,
|
|
||||||
renderId: renderId,
|
|
||||||
}
|
|
||||||
select {
|
|
||||||
case <-w.closeChan: //关闭
|
|
||||||
return
|
|
||||||
case w.extendRenderProperty.renderImageTaskCtlChan <- data:
|
|
||||||
return
|
|
||||||
case <-time.After(time.Second * 3):
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 渲染回调处理并删除渲染任务
|
|
||||||
func (w *wsConnectItem) deleteRenderTask(taskId, renderId, renderNotifyImageUrl string) {
|
|
||||||
if taskId == "" {
|
|
||||||
logx.Error("task_id不能为空")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
data := renderImageControlChanItem{
|
|
||||||
option: 0,
|
|
||||||
taskId: taskId,
|
|
||||||
renderId: renderId,
|
|
||||||
renderNotifyImageUrl: renderNotifyImageUrl,
|
|
||||||
}
|
|
||||||
select {
|
|
||||||
case <-w.closeChan: //关闭
|
|
||||||
return
|
|
||||||
case w.extendRenderProperty.renderImageTaskCtlChan <- data:
|
|
||||||
return
|
|
||||||
case <-time.After(time.Second * 3):
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 修改任务属性(只有耗时属性可以更新)
|
|
||||||
func (w *wsConnectItem) modifyRenderTaskProperty(taskId string, property renderTask) {
|
|
||||||
if taskId == "" {
|
|
||||||
logx.Error("task_id不能为空")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
//强制设为修改任务属性
|
|
||||||
data := renderImageControlChanItem{
|
|
||||||
option: 2,
|
|
||||||
taskId: taskId,
|
|
||||||
taskProperty: property,
|
|
||||||
}
|
|
||||||
select {
|
|
||||||
case <-w.closeChan: //关闭
|
|
||||||
return
|
|
||||||
case w.extendRenderProperty.renderImageTaskCtlChan <- data:
|
|
||||||
return
|
|
||||||
case <-time.After(time.Second * 3):
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
// 组装渲染任务id
|
// 组装渲染任务id
|
||||||
func (w *wsConnectItem) genRenderTaskId(combineImage string, renderImageData websocket_data.RenderImageReqMsg, model3dInfo *gmodel.FsProductModel3d, productTemplate *gmodel.FsProductTemplateV2, element *gmodel.FsProductTemplateElement) string {
|
func (w *wsConnectItem) genRenderTaskId(combineImage string, renderImageData websocket_data.RenderImageReqMsg, model3dInfo *gmodel.FsProductModel3d, productTemplate *gmodel.FsProductTemplateV2, element *gmodel.FsProductTemplateElement) string {
|
||||||
//生成任务id(需要把user_id,guest_id设为0)
|
//生成任务id(需要把user_id,guest_id设为0)
|
||||||
|
@ -595,78 +484,3 @@ func (w *wsConnectItem) genRenderTaskId(combineImage string, renderImageData web
|
||||||
}
|
}
|
||||||
return hash.JsonHashKey(hashMap)
|
return hash.JsonHashKey(hashMap)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理渲染任务的增加/删除/修改耗时属性(任务map不能读写并发,所以放在chan里面串行执行)
|
|
||||||
/*func (w *wsConnectItem) operationRenderTask() {
|
|
||||||
defer func() {
|
|
||||||
if err := recover(); err != nil {
|
|
||||||
logx.Error("operation render task panic:", err)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case <-w.closeChan:
|
|
||||||
return
|
|
||||||
case data := <-w.extendRenderProperty.renderImageTaskCtlChan:
|
|
||||||
switch data.option {
|
|
||||||
case 0: //渲染结果回调,删除任务
|
|
||||||
taskData, ok := w.extendRenderProperty.renderImageTask[data.taskId]
|
|
||||||
if !ok {
|
|
||||||
//发送到出口
|
|
||||||
w.sendRenderResultData(websocket_data.RenderImageRspMsg{
|
|
||||||
RenderId: data.renderId, //没有找到任务渲染id则用传进来的
|
|
||||||
Image: data.renderNotifyImageUrl,
|
|
||||||
RenderProcessTime: websocket_data.RenderProcessTime{
|
|
||||||
UnityRenderTakesTime: "unknown",
|
|
||||||
UploadUnityRenderImageTakesTime: "unknown",
|
|
||||||
},
|
|
||||||
})
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
//删除任务
|
|
||||||
delete(w.extendRenderProperty.renderImageTask, data.taskId)
|
|
||||||
//存在任务,则发送渲染结果给前端
|
|
||||||
UnityRenderTakesTime := "cache"
|
|
||||||
uploadUnityRenderImageTakesTime := "cache"
|
|
||||||
//unity渲染时间
|
|
||||||
if taskData.unityRenderBeginTime > 0 && taskData.unityRenderEndTime > 0 {
|
|
||||||
UnityRenderTakesTime = fmt.Sprintf("%dms", taskData.unityRenderEndTime-taskData.unityRenderBeginTime)
|
|
||||||
}
|
|
||||||
//上传unity渲染图耗时
|
|
||||||
if taskData.uploadUnityRenderImageTakesTime > 0 {
|
|
||||||
uploadUnityRenderImageTakesTime = fmt.Sprintf("%dms", taskData.uploadUnityRenderImageTakesTime)
|
|
||||||
}
|
|
||||||
//发送到出口
|
|
||||||
w.sendRenderResultData(websocket_data.RenderImageRspMsg{
|
|
||||||
RenderId: taskData.renderId,
|
|
||||||
Image: data.renderNotifyImageUrl,
|
|
||||||
RenderProcessTime: websocket_data.RenderProcessTime{
|
|
||||||
UnityRenderTakesTime: UnityRenderTakesTime,
|
|
||||||
UploadUnityRenderImageTakesTime: uploadUnityRenderImageTakesTime,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
case 1: //新增任务
|
|
||||||
w.extendRenderProperty.renderImageTask[data.taskId] = &renderTask{
|
|
||||||
renderId: data.renderId,
|
|
||||||
}
|
|
||||||
case 2: //修改任务属性
|
|
||||||
taskData, ok := w.extendRenderProperty.renderImageTask[data.taskId]
|
|
||||||
if !ok {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
//上传渲染结果图耗时
|
|
||||||
if data.taskProperty.uploadUnityRenderImageTakesTime != 0 {
|
|
||||||
taskData.uploadUnityRenderImageTakesTime = data.taskProperty.uploadUnityRenderImageTakesTime
|
|
||||||
}
|
|
||||||
//发送unity时间
|
|
||||||
if data.taskProperty.unityRenderBeginTime != 0 {
|
|
||||||
taskData.unityRenderBeginTime = data.taskProperty.unityRenderBeginTime
|
|
||||||
}
|
|
||||||
//收到unity返回的时间
|
|
||||||
if data.taskProperty.unityRenderEndTime != 0 {
|
|
||||||
taskData.unityRenderEndTime = data.taskProperty.unityRenderEndTime
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user