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
|
InputBuffer = {
buffer = {},
max_size = 5,
push = function(self, action)
table.insert(self.buffer, 1, action)
if #self.buffer > self.max_size then
table.remove(self.buffer)
end
end,
consume = function(self, action_id)
for i=#self.buffer,1,-1 do
if self.buffer[i].action_id == action_id then
table.remove(self.buffer, i)
return true
end
end
return false
end
}
-- 使用示例
function on_input(self, action_id, action)
InputBuffer:push({ action_id = action_id, action = action })
end
function update(self)
if InputBuffer:consume(hash("jump")) then
self:perform_jump()
end
end
|