fixed character z-ordering while moving
This commit is contained in:
parent
e8bb7306ac
commit
5cead3c282
@ -1,6 +1,8 @@
|
||||
local utils = require "lib.utils.utils"
|
||||
local pQueue = require "lib.utils.priority_queue"
|
||||
--- @class CharacterGrid : Grid
|
||||
--- @field __grid {string: Id|nil}
|
||||
--- @field yOrderQueue PriorityQueue<Character> очередь отрисовки сверху вниз
|
||||
local grid = setmetatable({}, require "lib.level.grid.base")
|
||||
grid.__index = grid
|
||||
|
||||
@ -21,13 +23,21 @@ function grid:add(id)
|
||||
end
|
||||
end
|
||||
|
||||
--- @param a Character
|
||||
--- @param b Character
|
||||
local function drawCmp(a, b)
|
||||
return a.logic.mapLogic.displayedPosition.y < b.logic.mapLogic.displayedPosition.y
|
||||
end
|
||||
|
||||
--- fills the grid with the actual data
|
||||
---
|
||||
--- should be called as early as possible during every tick
|
||||
function grid:reload()
|
||||
self:reset()
|
||||
self.yOrderQueue = pQueue.new(drawCmp)
|
||||
utils.each(Tree.level.characters, function(c)
|
||||
self:add(c.id)
|
||||
self.yOrderQueue:insert(c)
|
||||
end)
|
||||
end
|
||||
|
||||
|
||||
@ -39,9 +39,9 @@ end
|
||||
|
||||
function level:draw()
|
||||
self.tileGrid:draw()
|
||||
utils.each(self.characters, function(el)
|
||||
el:draw()
|
||||
end)
|
||||
while not self.characterGrid.yOrderQueue:is_empty() do -- по сути это сортировка кучей за n log n, но линейное
|
||||
self.characterGrid.yOrderQueue:pop():draw()
|
||||
end
|
||||
end
|
||||
|
||||
return {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user