-
-
Notifications
You must be signed in to change notification settings - Fork 444
/
Copy pathplane_master_group.dm
226 lines (185 loc) · 9.03 KB
/
plane_master_group.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
/// Datum that represents one "group" of plane masters
/// So all the main window planes would be in one, all the spyglass planes in another
/// Etc
/datum/plane_master_group
/// Our key in the group list on /datum/hud
/// Should be unique for any group of plane masters in the world
var/key
/// Our parent hud
var/datum/hud/our_hud
/// List in the form "[plane]" = object, the plane masters we own
var/list/atom/movable/screen/plane_master/plane_masters = list()
/// The visual offset we are currently using
var/active_offset = 0
/// What, if any, submap we render onto
var/map = ""
/// Controls the screen_loc that owned plane masters will use when generating relays. Due to a Byond bug, relays using the CENTER positional loc
/// Will be improperly offset
var/relay_loc = "CENTER"
/datum/plane_master_group/New(key, map = "")
. = ..()
src.key = key
src.map = map
build_plane_masters(0, SSmapping.max_plane_offset)
/datum/plane_master_group/Destroy()
set_hud(null)
QDEL_LIST_ASSOC_VAL(plane_masters)
return ..()
/datum/plane_master_group/proc/set_hud(datum/hud/new_hud)
if(new_hud == our_hud)
return
if(our_hud)
our_hud.master_groups -= key
hide_hud()
our_hud = new_hud
if(new_hud)
our_hud.master_groups[key] = src
show_hud()
transform_lower_turfs(our_hud, active_offset)
SEND_SIGNAL(src, COMSIG_GROUP_HUD_CHANGED, our_hud)
/// Display a plane master group to some viewer, so show all our planes to it
/datum/plane_master_group/proc/attach_to(datum/hud/viewing_hud)
if(viewing_hud.master_groups[key])
stack_trace("Hey brother, our key [key] is already in use by a plane master group on the passed in hud, belonging to [viewing_hud.mymob]. Ya fucked up, why are there dupes")
return
set_hud(viewing_hud)
our_hud.master_groups[key] = src
show_hud()
transform_lower_turfs(our_hud, active_offset)
/// Well, refresh our group, mostly useful for plane specific updates
/datum/plane_master_group/proc/refresh_hud()
hide_hud()
show_hud()
/// Fully regenerate our group, resetting our planes to their compile time values
/datum/plane_master_group/proc/rebuild_hud()
hide_hud()
rebuild_plane_masters()
show_hud()
transform_lower_turfs(our_hud, active_offset)
/// Regenerate our plane masters, this is useful if we don't have a mob but still want to rebuild. Such in the case of changing the screen_loc of relays
/datum/plane_master_group/proc/rebuild_plane_masters()
QDEL_LIST_ASSOC_VAL(plane_masters)
build_plane_masters(0, SSmapping.max_plane_offset)
/datum/plane_master_group/proc/hide_hud()
for(var/thing in plane_masters)
var/atom/movable/screen/plane_master/plane = plane_masters[thing]
plane.hide_from(our_hud.mymob)
/datum/plane_master_group/proc/show_hud()
for(var/thing in plane_masters)
var/atom/movable/screen/plane_master/plane = plane_masters[thing]
show_plane(plane)
/// This is mostly a proc so it can be overriden by popups, since they have unique behavior they want to do
/datum/plane_master_group/proc/show_plane(atom/movable/screen/plane_master/plane)
plane.show_to(our_hud.mymob)
/// Nice wrapper for the "[]"ing
/datum/plane_master_group/proc/get_plane(plane)
return plane_masters["[plane]"]
/// Returns a list of all the plane master types we want to create
/datum/plane_master_group/proc/get_plane_types()
return subtypesof(/atom/movable/screen/plane_master) - /atom/movable/screen/plane_master/rendering_plate
/// Actually generate our plane masters, in some offset range (where offset is the z layers to render to, because each "layer" in a multiz stack gets its own plane master cube)
/datum/plane_master_group/proc/build_plane_masters(starting_offset, ending_offset)
for(var/atom/movable/screen/plane_master/mytype as anything in get_plane_types())
for(var/plane_offset in starting_offset to ending_offset)
if(plane_offset != 0 && !initial(mytype.allows_offsetting))
continue
var/atom/movable/screen/plane_master/instance = new mytype(null, null, src, plane_offset)
plane_masters["[instance.plane]"] = instance
prep_plane_instance(instance)
/// Similarly, exists so subtypes can do unique behavior to planes on creation
/datum/plane_master_group/proc/prep_plane_instance(atom/movable/screen/plane_master/instance)
return
// It would be nice to setup parallaxing for stairs and things when doing this
// So they look nicer. if you can't it's all good, if you think you can sanely look at monster's work
// It's hard, and potentially expensive. be careful
/datum/plane_master_group/proc/transform_lower_turfs(datum/hud/source, new_offset, use_scale = TRUE)
// Check if this feature is disabled for the client, in which case don't use scale.
var/mob/our_mob = our_hud?.mymob
if(!our_mob?.client?.prefs?.read_preference(/datum/preference/toggle/multiz_parallax))
use_scale = FALSE
// No offset? piss off
if(!SSmapping.max_plane_offset)
return
active_offset = new_offset
// Each time we go "down" a visual z level, we'll reduce the scale by this amount
// Chosen because mothblocks liked it, didn't cause motion sickness while also giving a sense of height
var/scale_by = 0.965
if(!use_scale)
// This is a workaround for two things
// First of all, if a mob can see objects but not turfs, they will not be shown the holder objects we use for
// What I'd like to do is revert to images if this case throws, but image vis_contents is broken
// https://www.byond.com/forum/post/2821969
// If that's ever fixed, please just use that. thanks :)
scale_by = 1
var/list/offsets = list()
var/multiz_boundary = our_mob?.client?.prefs?.read_preference(/datum/preference/numeric/multiz_performance)
// We accept negatives so going down "zooms" away the drop above as it goes
for(var/offset in -SSmapping.max_plane_offset to SSmapping.max_plane_offset)
// Multiz boundaries disable transforms
if(multiz_boundary != MULTIZ_PERFORMANCE_DISABLE && (multiz_boundary < abs(offset)))
offsets += null
continue
// No transformations if we're landing ON you
if(offset == 0)
offsets += null
continue
var/scale = scale_by ** (offset)
var/matrix/multiz_shrink = matrix()
multiz_shrink.Scale(scale)
offsets += multiz_shrink
// So we can talk in 1 -> max_offset * 2 + 1, rather then -max_offset -> max_offset
var/offset_offset = SSmapping.max_plane_offset + 1
for(var/plane_key in plane_masters)
var/atom/movable/screen/plane_master/plane = plane_masters[plane_key]
if(!plane.allows_offsetting)
continue
var/visual_offset = plane.offset - new_offset
// Basically uh, if we're showing something down X amount of levels, or up any amount of levels
if(multiz_boundary != MULTIZ_PERFORMANCE_DISABLE && (visual_offset > multiz_boundary || visual_offset < 0))
plane.outside_bounds(our_mob)
else if(plane.is_outside_bounds)
plane.inside_bounds(our_mob)
if(!plane.multiz_scaled)
continue
if(plane.force_hidden || plane.is_outside_bounds || visual_offset < 0)
// We don't animate here because it should be invisble, but we do mark because it'll look nice
plane.transform = offsets[visual_offset + offset_offset]
continue
animate(plane, transform = offsets[visual_offset + offset_offset], 0.05 SECONDS, easing = LINEAR_EASING)
/// Holds plane masters for popups, like camera windows
/// Note: We do not scale this plane, even though we could
/// This is because it's annoying to get turfs to position inside it correctly
/// If you wanna try someday feel free, but I can't manage it
/datum/plane_master_group/popup
/// This is janky as hell but since something changed with CENTER positioning after build 1614 we have to switch to the bandaid LEFT,TOP positioning
/// using LEFT,TOP *at* or *before* 1614 will result in another broken offset for cameras
#define MAX_CLIENT_BUILD_WITH_WORKING_SECONDARY_MAPS 1614
/datum/plane_master_group/popup/attach_to(datum/hud/viewing_hud)
// If we're about to display this group to a mob who's client is more recent than the last known version with working CENTER, then we need to remake the relays
// with the correct screen_loc using the relay override
if(viewing_hud.mymob?.client?.byond_build > MAX_CLIENT_BUILD_WITH_WORKING_SECONDARY_MAPS)
relay_loc = "LEFT,TOP"
rebuild_plane_masters()
return ..()
#undef MAX_CLIENT_BUILD_WITH_WORKING_SECONDARY_MAPS
/datum/plane_master_group/popup/transform_lower_turfs(datum/hud/source, new_offset, use_scale = TRUE)
return ..(source, new_offset, FALSE)
/// Holds the main plane master
/datum/plane_master_group/main
/datum/plane_master_group/main/transform_lower_turfs(datum/hud/source, new_offset, use_scale = TRUE)
if(use_scale)
return ..(source, new_offset, source.should_use_scale())
return ..()
/// Hudless group. Exists for testing
/datum/plane_master_group/hudless
var/mob/our_mob
/datum/plane_master_group/hudless/Destroy()
. = ..()
our_mob = null
/datum/plane_master_group/hudless/hide_hud()
for(var/thing in plane_masters)
var/atom/movable/screen/plane_master/plane = plane_masters[thing]
plane.hide_from(our_mob)
/// This is mostly a proc so it can be overriden by popups, since they have unique behavior they want to do
/datum/plane_master_group/hudless/show_plane(atom/movable/screen/plane_master/plane)
plane.show_to(our_mob)