mirror of
https://github.com/genxium/DelayNoMore
synced 2024-12-26 11:48:56 +00:00
Simplified backend input prediction.
This commit is contained in:
parent
ab6a04693d
commit
24e980c17f
@ -128,7 +128,7 @@ type Room struct {
|
|||||||
EffectivePlayerCount int32
|
EffectivePlayerCount int32
|
||||||
DismissalWaitGroup sync.WaitGroup
|
DismissalWaitGroup sync.WaitGroup
|
||||||
InputsBuffer *battle.RingBuffer // Indices are STRICTLY consecutive
|
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
|
RenderFrameBuffer *battle.RingBuffer // Indices are STRICTLY consecutive
|
||||||
LatestPlayerUpsyncedInputFrameId int32
|
LatestPlayerUpsyncedInputFrameId int32
|
||||||
LastAllConfirmedInputFrameId int32
|
LastAllConfirmedInputFrameId int32
|
||||||
@ -149,6 +149,7 @@ type Room struct {
|
|||||||
TmxPolygonsMap StrToPolygon2DListMap
|
TmxPolygonsMap StrToPolygon2DListMap
|
||||||
|
|
||||||
rdfIdToActuallyUsedInput map[int32]*pb.InputFrameDownsync
|
rdfIdToActuallyUsedInput map[int32]*pb.InputFrameDownsync
|
||||||
|
LastIndividuallyConfirmedInputList []uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pR *Room) updateScore() {
|
func (pR *Room) updateScore() {
|
||||||
@ -741,6 +742,7 @@ func (pR *Room) OnDismissed() {
|
|||||||
pR.RenderFrameBuffer = battle.NewRingBuffer(pR.RenderCacheSize)
|
pR.RenderFrameBuffer = battle.NewRingBuffer(pR.RenderCacheSize)
|
||||||
pR.InputsBuffer = battle.NewRingBuffer((pR.RenderCacheSize >> 1) + 1)
|
pR.InputsBuffer = battle.NewRingBuffer((pR.RenderCacheSize >> 1) + 1)
|
||||||
pR.rdfIdToActuallyUsedInput = make(map[int32]*pb.InputFrameDownsync)
|
pR.rdfIdToActuallyUsedInput = make(map[int32]*pb.InputFrameDownsync)
|
||||||
|
pR.LastIndividuallyConfirmedInputList = make([]uint64, pR.Capacity)
|
||||||
|
|
||||||
pR.LatestPlayerUpsyncedInputFrameId = -1
|
pR.LatestPlayerUpsyncedInputFrameId = -1
|
||||||
pR.LastAllConfirmedInputFrameId = -1
|
pR.LastAllConfirmedInputFrameId = -1
|
||||||
@ -1035,17 +1037,9 @@ func (pR *Room) getOrPrefabInputFrameDownsync(inputFrameId int32) *battle.InputF
|
|||||||
}
|
}
|
||||||
|
|
||||||
for i, _ := range currInputFrameDownsync.InputList {
|
for i, _ := range currInputFrameDownsync.InputList {
|
||||||
j2 := pR.PlayersArr[i].LastReceivedInputFrameId
|
// [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.
|
||||||
if j2 < pR.InputsBuffer.StFrameId {
|
|
||||||
j2 = pR.InputsBuffer.StFrameId
|
|
||||||
}
|
|
||||||
tmp2 := pR.InputsBuffer.GetByFrameId(j2)
|
|
||||||
if nil != tmp2 {
|
|
||||||
prevInputFrameDownsync := tmp2.(*battle.InputFrameDownsync)
|
|
||||||
currInputFrameDownsync.InputList[i] = prevInputFrameDownsync.InputList[i]
|
|
||||||
}
|
|
||||||
// Don't predict "btnA & btnB"!
|
// 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)
|
pR.InputsBuffer.Put(currInputFrameDownsync)
|
||||||
@ -1081,6 +1075,7 @@ func (pR *Room) markConfirmationIfApplicable(inputFrameUpsyncBatch []*pb.InputFr
|
|||||||
targetInputFrameDownsync.ConfirmedList |= uint64(1 << uint32(player.JoinIndex-1))
|
targetInputFrameDownsync.ConfirmedList |= uint64(1 << uint32(player.JoinIndex-1))
|
||||||
|
|
||||||
player.LastReceivedInputFrameId = clientInputFrameId
|
player.LastReceivedInputFrameId = clientInputFrameId
|
||||||
|
pR.LastIndividuallyConfirmedInputList[player.JoinIndex-1] = inputFrameUpsync.Encoded
|
||||||
|
|
||||||
if clientInputFrameId > pR.LatestPlayerUpsyncedInputFrameId {
|
if clientInputFrameId > pR.LatestPlayerUpsyncedInputFrameId {
|
||||||
pR.LatestPlayerUpsyncedInputFrameId = clientInputFrameId
|
pR.LatestPlayerUpsyncedInputFrameId = clientInputFrameId
|
||||||
|
Loading…
Reference in New Issue
Block a user