|
|
|
@@ -128,7 +128,7 @@ type Room struct {
|
|
|
|
|
EffectivePlayerCount int32
|
|
|
|
|
DismissalWaitGroup sync.WaitGroup
|
|
|
|
|
InputsBuffer *battle.RingBuffer // Indices are STRICTLY consecutive
|
|
|
|
|
InputsBufferLock sync.Mutex // Guards [InputsBuffer, LatestPlayerUpsyncedInputFrameId, LastAllConfirmedInputFrameId, LastAllConfirmedInputList, LastAllConfirmedInputFrameIdWithChange]
|
|
|
|
|
InputsBufferLock sync.Mutex // Guards [InputsBuffer, LatestPlayerUpsyncedInputFrameId, LastAllConfirmedInputFrameId, LastAllConfirmedInputList, LastAllConfirmedInputFrameIdWithChange, LastIndividuallyConfirmedInputList, player.LastReceivedInputFrameId]
|
|
|
|
|
RenderFrameBuffer *battle.RingBuffer // Indices are STRICTLY consecutive
|
|
|
|
|
LatestPlayerUpsyncedInputFrameId int32
|
|
|
|
|
LastAllConfirmedInputFrameId int32
|
|
|
|
@@ -148,7 +148,8 @@ type Room struct {
|
|
|
|
|
TmxPointsMap StrToVec2DListMap
|
|
|
|
|
TmxPolygonsMap StrToPolygon2DListMap
|
|
|
|
|
|
|
|
|
|
rdfIdToActuallyUsedInput map[int32]*pb.InputFrameDownsync
|
|
|
|
|
rdfIdToActuallyUsedInput map[int32]*pb.InputFrameDownsync
|
|
|
|
|
LastIndividuallyConfirmedInputList []uint64
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (pR *Room) updateScore() {
|
|
|
|
@@ -172,6 +173,7 @@ func (pR *Room) AddPlayerIfPossible(pPlayerFromDbInit *Player, session *websocke
|
|
|
|
|
pPlayerFromDbInit.AckingFrameId = -1
|
|
|
|
|
pPlayerFromDbInit.AckingInputFrameId = -1
|
|
|
|
|
pPlayerFromDbInit.LastSentInputFrameId = MAGIC_LAST_SENT_INPUT_FRAME_ID_NORMAL_ADDED
|
|
|
|
|
pPlayerFromDbInit.LastReceivedInputFrameId = MAGIC_LAST_SENT_INPUT_FRAME_ID_NORMAL_ADDED
|
|
|
|
|
pPlayerFromDbInit.BattleState = PlayerBattleStateIns.ADDED_PENDING_BATTLE_COLLIDER_ACK
|
|
|
|
|
|
|
|
|
|
pPlayerFromDbInit.ColliderRadius = DEFAULT_PLAYER_RADIUS // Hardcoded
|
|
|
|
@@ -740,6 +742,7 @@ func (pR *Room) OnDismissed() {
|
|
|
|
|
pR.RenderFrameBuffer = battle.NewRingBuffer(pR.RenderCacheSize)
|
|
|
|
|
pR.InputsBuffer = battle.NewRingBuffer((pR.RenderCacheSize >> 1) + 1)
|
|
|
|
|
pR.rdfIdToActuallyUsedInput = make(map[int32]*pb.InputFrameDownsync)
|
|
|
|
|
pR.LastIndividuallyConfirmedInputList = make([]uint64, pR.Capacity)
|
|
|
|
|
|
|
|
|
|
pR.LatestPlayerUpsyncedInputFrameId = -1
|
|
|
|
|
pR.LastAllConfirmedInputFrameId = -1
|
|
|
|
@@ -1033,18 +1036,10 @@ func (pR *Room) getOrPrefabInputFrameDownsync(inputFrameId int32) *battle.InputF
|
|
|
|
|
ConfirmedList: uint64(0),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
j2 := j - 1
|
|
|
|
|
tmp2 := pR.InputsBuffer.GetByFrameId(j2)
|
|
|
|
|
if nil != tmp2 {
|
|
|
|
|
prevInputFrameDownsync := tmp2.(*battle.InputFrameDownsync)
|
|
|
|
|
for i, _ := range currInputFrameDownsync.InputList {
|
|
|
|
|
currInputFrameDownsync.InputList[i] = prevInputFrameDownsync.InputList[i]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for i, _ := range currInputFrameDownsync.InputList {
|
|
|
|
|
// [WARNING] The use of "InputsBufferLock" guarantees that by now "inputFrameId >= pR.InputsBuffer.EdFrameId >= pR.LatestPlayerUpsyncedInputFrameId", thus it's safe to use "pR.LastIndividuallyConfirmedInputList" for prediction.
|
|
|
|
|
// Don't predict "btnA & btnB"!
|
|
|
|
|
currInputFrameDownsync.InputList[i] = (currInputFrameDownsync.InputList[i] & uint64(15))
|
|
|
|
|
currInputFrameDownsync.InputList[i] = (pR.LastIndividuallyConfirmedInputList[i] & uint64(15))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pR.InputsBuffer.Put(currInputFrameDownsync)
|
|
|
|
@@ -1066,8 +1061,8 @@ func (pR *Room) markConfirmationIfApplicable(inputFrameUpsyncBatch []*pb.InputFr
|
|
|
|
|
Logger.Debug(fmt.Sprintf("Omitting obsolete inputFrameUpsync#1: roomId=%v, playerId=%v, clientInputFrameId=%v, InputsBuffer=%v", pR.Id, playerId, clientInputFrameId, pR.InputsBufferString(false)))
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
if clientInputFrameId < pR.LastAllConfirmedInputFrameId {
|
|
|
|
|
Logger.Debug(fmt.Sprintf("Omitting obsolete inputFrameUpsync#2: roomId=%v, playerId=%v, clientInputFrameId=%v, InputsBuffer=%v", pR.Id, playerId, clientInputFrameId, pR.InputsBufferString(false)))
|
|
|
|
|
if clientInputFrameId < player.LastReceivedInputFrameId {
|
|
|
|
|
Logger.Debug(fmt.Sprintf("Omitting obsolete inputFrameUpsync#2: roomId=%v, playerId=%v, clientInputFrameId=%v, playerLastReceivedInputFrameId=%v, InputsBuffer=%v", pR.Id, playerId, clientInputFrameId, player.LastReceivedInputFrameId, pR.InputsBufferString(false)))
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
if clientInputFrameId > pR.InputsBuffer.EdFrameId {
|
|
|
|
@@ -1079,6 +1074,9 @@ func (pR *Room) markConfirmationIfApplicable(inputFrameUpsyncBatch []*pb.InputFr
|
|
|
|
|
targetInputFrameDownsync.InputList[player.JoinIndex-1] = inputFrameUpsync.Encoded
|
|
|
|
|
targetInputFrameDownsync.ConfirmedList |= uint64(1 << uint32(player.JoinIndex-1))
|
|
|
|
|
|
|
|
|
|
player.LastReceivedInputFrameId = clientInputFrameId
|
|
|
|
|
pR.LastIndividuallyConfirmedInputList[player.JoinIndex-1] = inputFrameUpsync.Encoded
|
|
|
|
|
|
|
|
|
|
if clientInputFrameId > pR.LatestPlayerUpsyncedInputFrameId {
|
|
|
|
|
pR.LatestPlayerUpsyncedInputFrameId = clientInputFrameId
|
|
|
|
|
}
|
|
|
|
|