-
-
Notifications
You must be signed in to change notification settings - Fork 444
/
Copy pathlighting.dm
125 lines (105 loc) · 3.28 KB
/
lighting.dm
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
SUBSYSTEM_DEF(lighting)
name = "Lighting"
wait = 2
init_order = INIT_ORDER_LIGHTING
flags = SS_TICKER
var/static/list/sources_queue = list() // List of lighting sources queued for update.
var/static/list/corners_queue = list() // List of lighting corners queued for update.
var/static/list/objects_queue = list() // List of lighting objects queued for update.
var/static/list/current_sources = list()
#ifdef VISUALIZE_LIGHT_UPDATES
var/allow_duped_values = FALSE
var/allow_duped_corners = FALSE
#endif
loading_points = 6 SECONDS // Yogs -- loading times
/datum/controller/subsystem/lighting/stat_entry(msg)
msg = "L:[length(sources_queue)]|C:[length(corners_queue)]|O:[length(objects_queue)]"
return ..()
/datum/controller/subsystem/lighting/Initialize()
if(!initialized)
create_all_lighting_objects()
initialized = TRUE
fire(FALSE, TRUE)
return SS_INIT_SUCCESS
/datum/controller/subsystem/lighting/fire(resumed, init_tick_checks)
MC_SPLIT_TICK_INIT(3)
if(!init_tick_checks)
MC_SPLIT_TICK
if(!resumed)
current_sources = sources_queue
sources_queue = list()
// UPDATE SOURCE QUEUE
var/i = 0
var/list/queue = current_sources
while(i < length(queue)) //we don't use for loop here because i cannot be changed during an iteration
i += 1
var/datum/light_source/L = queue[i]
L.update_corners()
if(!QDELETED(L))
L.needs_update = LIGHTING_NO_UPDATE
else
i -= 1 // update_corners() has removed L from the list, move back so we don't overflow or skip the next element
// We unroll TICK_CHECK here so we can clear out the queue to ensure any removals/additions when sleeping don't fuck us
if(init_tick_checks)
if(!TICK_CHECK)
continue
queue.Cut(1, i + 1)
i = 0
stoplag()
else if(MC_TICK_CHECK)
break
if(i)
queue.Cut(1, i + 1)
i = 0
if(!init_tick_checks)
MC_SPLIT_TICK
// UPDATE CORNERS QUEUE
queue = corners_queue
while(i < length(queue)) //we don't use for loop here because i cannot be changed during an iteration
i += 1
var/datum/lighting_corner/C = queue[i]
C.needs_update = FALSE //update_objects() can call qdel if the corner is storing no data
C.update_objects()
// We unroll TICK_CHECK here so we can clear out the queue to ensure any removals/additions when sleeping don't fuck us
if(init_tick_checks)
if(!TICK_CHECK)
continue
queue.Cut(1, i + 1)
i = 0
stoplag()
else if(MC_TICK_CHECK)
break
if(i)
queue.Cut(1, i+1)
i = 0
if(!init_tick_checks)
MC_SPLIT_TICK
// UPDATE OBJECTS QUEUE
queue = objects_queue
while(i < length(queue)) //we don't use for loop here because i cannot be changed during an iteration
i += 1
var/datum/lighting_object/O = queue[i]
if(QDELETED(O))
continue
O.update()
O.needs_update = FALSE
// We unroll TICK_CHECK here so we can clear out the queue to ensure any removals/additions when sleeping don't fuck us
if(init_tick_checks)
if(!TICK_CHECK)
continue
queue.Cut(1, i + 1)
i = 0
stoplag()
else if(MC_TICK_CHECK)
break
if(i)
queue.Cut(1, i + 1)
/datum/controller/subsystem/lighting/Recover()
initialized = SSlighting.initialized
..()
///Yog metric tracking
/datum/controller/subsystem/lighting/get_metrics()
. = ..()
.["queue_sources"] = length(sources_queue)
.["queue_corners"] = length(corners_queue)
.["queue_objects"] = length(objects_queue)