-
Notifications
You must be signed in to change notification settings - Fork 0
/
ReplayInputManager.gd
69 lines (46 loc) · 1.89 KB
/
ReplayInputManager.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
extends "res://input_manager.gd"
signal replay_missing_input
var btnPressedBuffer=null
var btnHoldBuffer=null
var btnReleasedBuffer=null
var tick = 0
var mirrorDebugFlag = false
func setupInputs(_btnPressedBuffer,_btnHoldBuffer,_btnReleasedBuffer):
btnPressedBuffer=_btnPressedBuffer
btnHoldBuffer=_btnHoldBuffer
btnReleasedBuffer=_btnReleasedBuffer
func processInput(inputJustPressedBitMap,inputHoldingBitMap,inputReleasedBitMap):
#this will happen if a desyn issue occurs and the game should have ended (no more input to play)
if tick >= btnPressedBuffer.size():
emit_signal("replay_missing_input")
set_physics_process(false)
return
#upon investigation, replays on restart have a desyn where hitfreeze occured in restarted version of replay but not original...
#if tick == 200:
# pass
inputJustPressedBitMap=btnPressedBuffer[tick]
inputHoldingBitMap =btnHoldBuffer[tick]
inputReleasedBitMap =btnReleasedBuffer[tick]
tick = tick + 1
#this only used for debugging. one of iput managers wil lmirror raw input,
#while both received the same buttons. so if ever the players get out of synch, it's a game
#engine issue, not the AI input being processed incorrectly
if mirrorDebugFlag:
inputJustPressedBitMap = mirrorBtnInput(inputJustPressedBitMap)
inputHoldingBitMap = mirrorBtnInput(inputHoldingBitMap)
inputReleasedBitMap = mirrorBtnInput(inputReleasedBitMap)
.processInput(inputJustPressedBitMap,inputHoldingBitMap,inputReleasedBitMap)
func mirrorBtnInput(btnBitMap):
#left held?
if (btnBitMap & BTN_LEFT) == BTN_LEFT:
#clear the left bit in map
var tmp = btnBitMap^BTN_LEFT
#replace it with right
return tmp|BTN_RIGHT #assume can't hold left and right at same time
#right held?
if (btnBitMap & BTN_RIGHT) == BTN_RIGHT:
#clear the right bit in map
var tmp = btnBitMap^BTN_RIGHT
#replace it with right
return tmp|BTN_LEFT
return btnBitMap