Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

experiment: explosions subsystem #6372

Merged
merged 12 commits into from
Feb 2, 2025
2 changes: 2 additions & 0 deletions code/__DEFINES/subsystems.dm
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
#define INIT_ORDER_NIGHTSHIFT -24
#define INIT_ORDER_GAME_EVENTS -26
#define INIT_ORDER_PATH -50
#define INIT_ORDER_EXPLOSIONS -69
#define INIT_ORDER_PERSISTENCE -95
#define INIT_ORDER_STATPANELS -98
#define INIT_ORDER_DEMO -99 // To avoid a bunch of changes related to initialization being written, do this last
Expand Down Expand Up @@ -139,6 +140,7 @@
#define FIRE_PRIORITY_CHAT 400
#define FIRE_PRIORITY_RUNECHAT 410 // I hate how high the fire priority on this is -aa
#define FIRE_PRIORITY_OVERLAYS 500
#define FIRE_PRIORITY_EXPLOSIONS 666
#define FIRE_PRIORITY_TIMER 700
#define FIRE_PRIORITY_SPEECH_CONTROLLER 900
#define FIRE_PRIORITY_DELAYED_VERBS 950
Expand Down
69 changes: 69 additions & 0 deletions code/__HELPERS/data_struct/priority_queue.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/priority_queue
var/list/priority_node/heap = list()

/priority_node
var/item
var/priority

/priority_node/New(item, priority)
. = ..()
src.item = item
src.priority = priority

/priority_queue/proc/enqueue(value, priority)
heap += list(new /priority_node(value, priority))
bubble_up(heap.len)

/priority_queue/proc/dequeue()
if (heap.len == 0)
return null

var/priority_node/top = heap[1]
var/bottom = heap[heap.len]
var/item = top.item
heap -= bottom
if(!heap.len)
qdel(top)
return item
heap[1] = bottom
bubble_down(1)
qdel(top)
return item

/priority_queue/proc/peek()
if (heap.len == 0)
return null
return heap[1].item

/priority_queue/proc/is_empty()
return heap.len == 0

/priority_queue/proc/bubble_up(index)
while(index > 1)
var/parent = round(index / 2)

if (heap[parent].priority < heap[index].priority)
break

swap(index, parent)
index = parent


/priority_queue/proc/bubble_down(index)
while(index * 2 <= heap.len)
var/child = index * 2

if (child + 1 <= heap.len && heap[child + 1].priority < heap[child].priority)
child++

if (heap[index].priority < heap[child].priority)
break

swap(index, child)
index = child


/priority_queue/proc/swap(a, b)
var/list/temp = heap[a]
heap[a] = heap[b]
heap[b] = temp
73 changes: 73 additions & 0 deletions code/__HELPERS/data_struct/queue.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Double linked list node
*/
/node
var/value
var/prev
var/next

/*
* Defining a queue based on a double linked list
*/
/queue
/// Link to the beginning of the list
var/node/head
/// Link to end of list
var/node/tail
/// Number of elements in queue
var/count = 0

/*
* Adding an element to the end of the queue
*/
/queue/proc/enqueue(value)
var/node/new_node = new
new_node.value = value

if (!tail)
head = new_node
tail = new_node
else
tail.next = new_node
new_node.prev = tail
tail = new_node
count++
/*
* Retrieving an element from the head of the queue
*/
/queue/proc/dequeue()
if (!head)
return null

var/value = head.value
var/node/old_head = head

head = head.next
if (head)
head.prev = null
else
tail = null
old_head.value = null
old_head.next = null
qdel(old_head)
count--
return value
/*
* Returns an element from the beginning of the queue without removing it
*/
/queue/proc/peek()
if (!head)
return null
return head.value

/*
* Checking if the queue is empty
*/
/queue/proc/is_empty()
return count == 0

/*
* Returns the number of elements in the queue
*/
/queue/proc/size()
return count
Loading