fix
This commit is contained in:
parent
48fb3ec4aa
commit
aa89a74c2b
|
@ -67,17 +67,17 @@ var (
|
|||
|
||||
// 每个连接的连接基本属性
|
||||
type wsConnectItem struct {
|
||||
conn *websocket.Conn //websocket的连接(基本属性)
|
||||
logic *DataTransferLogic //logic(基本属性,用于获取上下文,配置或者操作数据库)
|
||||
closeChan chan struct{} //ws连接关闭chan(基本属性)
|
||||
isClose bool //是否已经关闭(基本属性)
|
||||
uniqueId string //ws连接唯一标识(基本属性)
|
||||
inChan chan []byte //接受消息缓冲池(基本属性)
|
||||
outChan chan []byte //要发送回客户端的消息缓冲池(基本属性)
|
||||
mutex sync.Mutex //互斥锁(关闭连接方法中用)
|
||||
userId int64 //用户id(基本属性)
|
||||
guestId int64 //游客id(基本属性)
|
||||
renderProperty renderProperty //扩展云渲染属性(扩展属性)
|
||||
conn *websocket.Conn //websocket的连接(基本属性)
|
||||
logic *DataTransferLogic //logic(基本属性,用于获取上下文,配置或者操作数据库)
|
||||
closeChan chan struct{} //ws连接关闭chan(基本属性)
|
||||
isClose bool //是否已经关闭(基本属性)
|
||||
uniqueId string //ws连接唯一标识(基本属性)
|
||||
inChan chan []byte //接受消息缓冲池(基本属性)
|
||||
outChan chan []byte //要发送回客户端的消息缓冲池(基本属性)
|
||||
mutex sync.Mutex //互斥锁(基本属性)
|
||||
userId int64 //用户id(基本属性)
|
||||
guestId int64 //游客id(基本属性)
|
||||
extendRenderProperty extendRenderProperty //扩展云渲染属性(扩展属性)
|
||||
}
|
||||
|
||||
// 请求建立连接,升级websocket协议
|
||||
|
@ -148,7 +148,7 @@ func (l *DataTransferLogic) setConnPool(conn *websocket.Conn, userInfo auth.User
|
|||
outChan: make(chan []byte, 1000),
|
||||
userId: userInfo.UserId,
|
||||
guestId: userInfo.GuestId,
|
||||
renderProperty: renderProperty{
|
||||
extendRenderProperty: extendRenderProperty{
|
||||
renderImageTask: make(map[string]*renderTask),
|
||||
renderImageTaskCtlChan: make(chan renderImageControlChanItem, 500),
|
||||
renderChan: make(chan []byte, 500),
|
||||
|
|
|
@ -18,7 +18,7 @@ import (
|
|||
)
|
||||
|
||||
// 云渲染属性
|
||||
type renderProperty struct {
|
||||
type extendRenderProperty struct {
|
||||
renderImageTask map[string]*renderTask //需要渲染的图片任务 key是taskId val 是renderId
|
||||
renderImageTaskCtlChan chan renderImageControlChanItem //渲染任务新增/回调结果移除任务/更新渲染耗时属性的控制通道(由于任务map无法读写并发)
|
||||
renderChan chan []byte //渲染消息入口的缓冲队列
|
||||
|
@ -47,7 +47,7 @@ func (w *wsConnectItem) sendToRenderChan(data []byte) {
|
|||
select {
|
||||
case <-w.closeChan: //已经关闭
|
||||
return
|
||||
case w.renderProperty.renderChan <- data: //发入到缓冲池
|
||||
case w.extendRenderProperty.renderChan <- data: //发入到缓冲池
|
||||
return
|
||||
case <-time.After(time.Second * 3): //三秒没进入缓冲池就丢弃
|
||||
return
|
||||
|
@ -60,7 +60,7 @@ func (w *wsConnectItem) renderImage() {
|
|||
select {
|
||||
case <-w.closeChan: //已关闭
|
||||
return
|
||||
case data := <-w.renderProperty.renderChan:
|
||||
case data := <-w.extendRenderProperty.renderChan:
|
||||
w.consumeRenderCache(data)
|
||||
}
|
||||
}
|
||||
|
@ -359,7 +359,7 @@ func (w *wsConnectItem) createRenderTask(data renderImageControlChanItem) {
|
|||
select {
|
||||
case <-w.closeChan: //关闭
|
||||
return
|
||||
case w.renderProperty.renderImageTaskCtlChan <- data:
|
||||
case w.extendRenderProperty.renderImageTaskCtlChan <- data:
|
||||
return
|
||||
case <-time.After(time.Second * 3):
|
||||
return
|
||||
|
@ -373,7 +373,7 @@ func (w *wsConnectItem) deleteRenderTask(data renderImageControlChanItem) {
|
|||
select {
|
||||
case <-w.closeChan: //关闭
|
||||
return
|
||||
case w.renderProperty.renderImageTaskCtlChan <- data:
|
||||
case w.extendRenderProperty.renderImageTaskCtlChan <- data:
|
||||
return
|
||||
case <-time.After(time.Second * 3):
|
||||
return
|
||||
|
@ -391,7 +391,7 @@ func (w *wsConnectItem) modifyRenderTaskTimeConsuming(data renderImageControlCha
|
|||
select {
|
||||
case <-w.closeChan: //关闭
|
||||
return
|
||||
case w.renderProperty.renderImageTaskCtlChan <- data:
|
||||
case w.extendRenderProperty.renderImageTaskCtlChan <- data:
|
||||
return
|
||||
case <-time.After(time.Second * 3):
|
||||
return
|
||||
|
@ -409,11 +409,11 @@ func (w *wsConnectItem) operationRenderTask() {
|
|||
select {
|
||||
case <-w.closeChan:
|
||||
return
|
||||
case data := <-w.renderProperty.renderImageTaskCtlChan:
|
||||
case data := <-w.extendRenderProperty.renderImageTaskCtlChan:
|
||||
switch data.Option {
|
||||
case 0: //渲染结果回调,删除任务
|
||||
//存在任务,则发送渲染结果给前端
|
||||
if taskData, ok := w.renderProperty.renderImageTask[data.TaskId]; ok {
|
||||
if taskData, ok := w.extendRenderProperty.renderImageTask[data.TaskId]; ok {
|
||||
CombineTakesTime := ""
|
||||
UnityRenderTakesTime := ""
|
||||
if taskData.CombineBeginTime > 0 && taskData.CombineEndTime > 0 {
|
||||
|
@ -431,13 +431,13 @@ func (w *wsConnectItem) operationRenderTask() {
|
|||
}))
|
||||
}
|
||||
//删除任务
|
||||
delete(w.renderProperty.renderImageTask, data.TaskId)
|
||||
delete(w.extendRenderProperty.renderImageTask, data.TaskId)
|
||||
case 1: //新增任务
|
||||
w.renderProperty.renderImageTask[data.TaskId] = &renderTask{
|
||||
w.extendRenderProperty.renderImageTask[data.TaskId] = &renderTask{
|
||||
RenderId: data.RenderId,
|
||||
}
|
||||
case 2: //修改(耗时)属性
|
||||
if taskData, ok := w.renderProperty.renderImageTask[data.TaskId]; ok {
|
||||
if taskData, ok := w.extendRenderProperty.renderImageTask[data.TaskId]; ok {
|
||||
if data.TaskProperty.CombineBeginTime != 0 {
|
||||
taskData.CombineBeginTime = data.TaskProperty.CombineBeginTime
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user