// sc2k/sim/tile_queue.hpp — the simulation's shared tile-coordinate work queue. // // The original keeps one global 512-entry FIFO ring buffer used by every network flood-fill // (power, water, …). On overflow the enqueue advances the head, dropping the oldest entry. // This is a faithful model of that buffer. #pragma once #include #include namespace sc2k { namespace detail { struct TileQueue { explicit TileQueue(int dimension = 128) : capacity(dimension == 128 ? 512 : 4 * dimension * dimension + 1), qr(capacity), qc(capacity) {} int capacity; std::vector qr, qc; int head = 0, tail = 0; void clear() { head = tail = 0; } void push(int r, int c) { qr[tail] = r; qc[tail] = c; tail = (tail + 1) % capacity; if (head == tail) head = (head + 1) % capacity; // full → drop oldest (the original's enqueue rule) } bool empty() const { return head == tail; } void pop(int& r, int& c) { r = qr[head]; c = qc[head]; head = (head + 1) % capacity; } }; } // namespace detail } // namespace sc2k