public static void updateTickQueue(List<IScheduledTickHandler> ticks, Side side) { synchronized (ticks) { ticks.clear(); long tick = getCounter(side).incrementAndGet(); PriorityQueue<TickQueueElement> tickHandlers = getQueue(side); while (true) { if (tickHandlers.size()==0 || !tickHandlers.peek().scheduledNow(tick)) { break; } TickRegistry.TickQueueElement tickQueueElement = tickHandlers.poll(); tickQueueElement.update(tick); tickHandlers.offer(tickQueueElement); ticks.add(tickQueueElement.ticker); } } }
public TickQueueElement(IScheduledTickHandler ticker, long tickCounter) { this.ticker = ticker; update(tickCounter); }
public static void registerScheduledTickHandler(IScheduledTickHandler handler, Side side) { getQueue(side).add(new TickQueueElement(handler, getCounter(side).get())); }