Skip to content

Commit a8b015b

Browse files
Merge minimap and ceiling image generation into one proc (#11845)
# About the pull request Merges minimap and ceiling image generation into one proc, to reduce the number of times we loop over each turf. # Explain why it's good for the game Reduces the number of times we loop over each turf (from twice per level to once per level), which will hopefully make minimap generation slightly faster. I also think the way it's written now is easier to read, but that's a personal opinion. # Testing Photographs and Procedure Ceiling overlay still works and can still be disabled. <details> <summary>Screenshots & Videos</summary> <img width="1057" height="1057" alt="image" src="https://github.com/user-attachments/assets/3ace698d-2b3d-40c7-ba05-a54dc16e5733" /> </details> # Changelog Should have no user-facing changes.
1 parent 310f256 commit a8b015b

1 file changed

Lines changed: 38 additions & 80 deletions

File tree

code/controllers/subsystem/minimap.dm

Lines changed: 38 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,9 @@ SUBSYSTEM_DEF(minimaps)
9696
minimaps_by_z["[level]"] = new /datum/hud_displays
9797
if(!is_mainship_level(level) && !is_ground_level(level) && !(SSmapping.level_trait(level, ZTRAIT_AWAY))) //todo: maybe move this around
9898
return
99+
var/datum/hud_displays/hud_data = minimaps_by_z["[level]"]
99100
var/icon/icon_gen = new('icons/ui_icons/minimap.dmi') //600x600 blank icon template for drawing on the map
101+
var/icon/ceiling_overlay = icon('icons/ui_icons/minimap.dmi')
100102
var/xmin = world.maxx
101103
var/ymin = world.maxy
102104
var/xmax = 1
@@ -105,57 +107,71 @@ SUBSYSTEM_DEF(minimaps)
105107
for(var/xval = 1 to world.maxx)
106108
for(var/yval = 1 to world.maxy) //Scan all the turfs and draw as needed
107109
var/turf/location = locate(xval,yval,level)
110+
if(istype(location, /turf/open/space))
111+
continue
108112
var/area/turfloc = location.loc
109113
var/base_color = location.minimap_color
114+
var/ceiling_color
115+
if(turfloc.ceiling >= CEILING_PROTECTION_TIER_4)
116+
ceiling_color = MINIMAP_CEILING_TIER_4
117+
else if(turfloc.ceiling >= CEILING_PROTECTION_TIER_3)
118+
ceiling_color = MINIMAP_CEILING_TIER_3
119+
else if(turfloc.ceiling >= CEILING_PROTECTION_TIER_2)
120+
ceiling_color = MINIMAP_CEILING_TIER_2
121+
else if(turfloc.ceiling >= CEILING_PROTECTION_TIER_1)
122+
ceiling_color = MINIMAP_CEILING_TIER_1
123+
else if(turfloc.ceiling >= CEILING_GLASS)
124+
ceiling_color = MINIMAP_CEILING_TIER_GLASS
110125

111126
if(location.density)
112127
if(!istype(location, /turf/closed/wall/almayer/outer)) // Ignore almayer border
113128
xmin = min(xmin, xval)
114129
ymin = min(ymin, yval)
115130
xmax = max(xmax, xval)
116131
ymax = max(ymax, yval)
117-
base_color = location.minimap_color
118-
else if(istype(location, /turf/open/space))
119-
continue
120132
else
121133
var/atom/movable/alttarget = (locate(/obj/structure/machinery/door) in location) || (locate(/obj/structure/fence) in location)
122134
if(alttarget)
123135
base_color = alttarget.minimap_color
124136
else if(turfloc.minimap_color)
125137
base_color = BlendRGB(location.minimap_color, turfloc.minimap_color, 0.5)
126-
else
127-
base_color = location.minimap_color
128-
129138

139+
xmin = min(xmin, xval)
140+
ymin = min(ymin, yval)
141+
xmax = max(xmax, xval)
142+
ymax = max(ymax, yval)
130143

131-
var/final_color = base_color
132-
133-
if(!istype(location, /turf/open/space))
134-
xmin = min(xmin, xval)
135-
ymin = min(ymin, yval)
136-
xmax = max(xmax, xval)
137-
ymax = max(ymax, yval)
144+
icon_gen.DrawBox(base_color, xval, yval)
145+
if(ceiling_color)
146+
ceiling_overlay.DrawBox(ceiling_color, xval, yval)
138147

139-
icon_gen.DrawBox(final_color, xval, yval)
140148
xmin = xmin * MINIMAP_SCALE - 1
141149
ymin = ymin * MINIMAP_SCALE - 1
142150
xmax = min(xmax * MINIMAP_SCALE, MINIMAP_PIXEL_SIZE)
143151
ymax = min(ymax * MINIMAP_SCALE, MINIMAP_PIXEL_SIZE)
144152

145153
icon_gen.Scale(icon_gen.Width() * MINIMAP_SCALE, icon_gen.Height() * MINIMAP_SCALE) //scale it up x2 to make it easer to see
146154
icon_gen.Crop(xmin, ymin, MINIMAP_PIXEL_SIZE + xmin - 1, MINIMAP_PIXEL_SIZE + ymin - 1) //then trim it down also cutting anything unused on the bottom left
155+
// ditto for the ceiling
156+
ceiling_overlay.Scale(ceiling_overlay.Width() * MINIMAP_SCALE, ceiling_overlay.Height() * MINIMAP_SCALE)
157+
ceiling_overlay.Crop(xmin, ymin, MINIMAP_PIXEL_SIZE + xmin - 1, MINIMAP_PIXEL_SIZE + ymin - 1)
147158

148159
// Determine and assign the offsets
149-
minimaps_by_z["[level]"].x_offset = floor((MINIMAP_PIXEL_SIZE - xmax - 1) / 2) - xmin
150-
minimaps_by_z["[level]"].y_offset = floor((MINIMAP_PIXEL_SIZE - ymax - 1) / 2) - ymin
151-
minimaps_by_z["[level]"].x_max = xmax
152-
minimaps_by_z["[level]"].y_max = ymax
160+
hud_data.x_offset = floor((MINIMAP_PIXEL_SIZE - xmax - 1) / 2) - xmin
161+
hud_data.y_offset = floor((MINIMAP_PIXEL_SIZE - ymax - 1) / 2) - ymin
162+
hud_data.x_max = xmax
163+
hud_data.y_max = ymax
153164

154165
// Center the map icon
155-
icon_gen.Shift(EAST, minimaps_by_z["[level]"].x_offset + xmin)
156-
icon_gen.Shift(NORTH, minimaps_by_z["[level]"].y_offset + ymin)
157-
minimaps_by_z["[level]"].hud_image = icon_gen //done making the image!
158-
pregenerate_ceiling_overlay(level)
166+
icon_gen.Shift(EAST, hud_data.x_offset + xmin)
167+
icon_gen.Shift(NORTH, hud_data.y_offset + ymin)
168+
169+
ceiling_overlay.Shift(EAST, hud_data.x_offset + xmin)
170+
ceiling_overlay.Shift(NORTH, hud_data.y_offset + ymin)
171+
172+
// Cache the overlay for all clients to use
173+
hud_data.hud_image = icon_gen //done making the image!
174+
hud_data.cached_ceiling_overlay = ceiling_overlay
159175

160176
//lateload icons
161177
if(!LAZYACCESS(earlyadds, "[level]"))
@@ -165,59 +181,6 @@ SUBSYSTEM_DEF(minimaps)
165181
callback.Invoke()
166182
LAZYREMOVE(earlyadds, "[level]")
167183

168-
/// Pre-generates ceiling protection overlay during minimap creation
169-
/datum/controller/subsystem/minimaps/proc/pregenerate_ceiling_overlay(z_level)
170-
var/datum/hud_displays/hud_data = minimaps_by_z["[z_level]"]
171-
if(!hud_data)
172-
return
173-
174-
var/icon/ceiling_overlay = icon('icons/ui_icons/minimap.dmi')
175-
var/xmin = world.maxx
176-
var/ymin = world.maxy
177-
var/xmax = 1
178-
var/ymax = 1
179-
180-
for(var/xval = 1, xval <= world.maxx, xval++)
181-
for(var/yval = 1, yval <= world.maxy, yval++)
182-
var/turf/turfloc = locate(xval, yval, z_level)
183-
var/area/turf_area = get_area(turfloc)
184-
if(!turf_area?.ceiling)
185-
continue
186-
187-
var/ceiling_color
188-
if(turf_area.ceiling >= CEILING_PROTECTION_TIER_4)
189-
ceiling_color = MINIMAP_CEILING_TIER_4
190-
else if(turf_area.ceiling >= CEILING_PROTECTION_TIER_3)
191-
ceiling_color = MINIMAP_CEILING_TIER_3
192-
else if(turf_area.ceiling >= CEILING_PROTECTION_TIER_2)
193-
ceiling_color = MINIMAP_CEILING_TIER_2
194-
else if(turf_area.ceiling >= CEILING_PROTECTION_TIER_1)
195-
ceiling_color = MINIMAP_CEILING_TIER_1
196-
else if(turf_area.ceiling >= CEILING_GLASS)
197-
ceiling_color = MINIMAP_CEILING_TIER_GLASS
198-
199-
if(ceiling_color)
200-
if(!istype(turfloc, /turf/open/space))
201-
xmin = min(xmin, xval)
202-
ymin = min(ymin, yval)
203-
xmax = max(xmax, xval)
204-
ymax = max(ymax, yval)
205-
ceiling_overlay.DrawBox(ceiling_color, xval, yval)
206-
207-
xmin = xmin * MINIMAP_SCALE - 1
208-
ymin = ymin * MINIMAP_SCALE - 1
209-
xmax = min(xmax * MINIMAP_SCALE, MINIMAP_PIXEL_SIZE)
210-
ymax = min(ymax * MINIMAP_SCALE, MINIMAP_PIXEL_SIZE)
211-
212-
ceiling_overlay.Scale(ceiling_overlay.Width() * MINIMAP_SCALE, ceiling_overlay.Height() * MINIMAP_SCALE)
213-
ceiling_overlay.Crop(xmin, ymin, MINIMAP_PIXEL_SIZE + xmin - 1, MINIMAP_PIXEL_SIZE + ymin - 1)
214-
215-
ceiling_overlay.Shift(EAST, hud_data.x_offset + xmin)
216-
ceiling_overlay.Shift(NORTH, hud_data.y_offset + ymin)
217-
218-
// Cache the overlay for all clients to use
219-
hud_data.cached_ceiling_overlay = ceiling_overlay
220-
221184
/// Creates ceiling protection overlay for a specific client and z-level
222185
/datum/controller/subsystem/minimaps/proc/create_ceiling_overlay(client/target_client, z_level)
223186
if(!target_client?.prefs?.show_minimap_ceiling_protection)
@@ -228,11 +191,6 @@ SUBSYSTEM_DEF(minimaps)
228191
return null
229192

230193
// Return cached overlay
231-
if(hud_data.cached_ceiling_overlay)
232-
return hud_data.cached_ceiling_overlay
233-
234-
// Pre-generation failed fallback, generate on demand
235-
pregenerate_ceiling_overlay(z_level)
236194
return hud_data.cached_ceiling_overlay
237195

238196
/datum/controller/subsystem/minimaps/proc/regenerate_minimap_for_z(z_level)

0 commit comments

Comments
 (0)