Floodfill experimental improvement, lets hope it fixes crashes.

This commit is contained in:
SkyMarshal
2012-08-12 19:33:21 -07:00
parent 82ed4f809f
commit aea3eda738
2 changed files with 26 additions and 41 deletions

View File

@@ -8,49 +8,35 @@ proc/FloodFill(turf/start)
list list
open = list(start) open = list(start)
closed = list() closed = list()
doors = list()
while(open.len) while(open.len)
for(var/turf/T in open) var/turf/T = pick(open)
//Stop if there's a door, even if it's open. These are handled by indirect connection.
if(!T.HasDoor())
for(var/d in cardinal) for(var/d in cardinal)
var/turf/O = get_step(T,d) var/turf/O = get_step(T,d)
//Simple pass check.
if(istype(O) && !(O in open) && !(O in doors) && !(O in closed) && O.ZCanPass(T))
open += O
else
doors |= T
open -= T
continue
open -= T if(istype(O) && !(O in open) && !(O in closed) && O.ZCanPass(T))
closed += T
if(closed.len) if(!T.HasDoor())
for(var/turf/T in doors) open += O
var/force_connection = 1
var/turf/simulated/O = get_step(T,NORTH)
if(O in closed)
closed += T
continue
else if(T.ZCanPass(O) && istype(O))
force_connection = 0
O = get_step(T,WEST) else
if(O in closed) if(d == SOUTH || d == EAST)
closed += T //doors prefer connecting to zones to the north north or west
continue closed += O
else if(force_connection && T.ZCanPass(O) && istype(O))
force_connection = 0
if(force_connection) else
O = get_step(T,SOUTH) //see if we need to force an attempted connection
if(O in closed) //(there are no potentially viable zones to the north/west of the door)
closed += T var/turf/W = get_step(O, WEST)
else if((!T.ZCanPass(O) || !istype(O)) && get_step(T,EAST) in closed) var/turf/N = get_step(O, NORTH)
closed += T
if( (!istype(N) || !O.ZCanPass(N)) && (!istype(W) || !O.ZCanPass(W)) )
//If it cannot connect either to the north or west, connect it!
closed += O
open -= T
closed += T
return closed return closed

View File

@@ -88,7 +88,7 @@ turf
for(var/direction in cardinal) for(var/direction in cardinal)
var/turf/simulated/floor/target = get_step(src,direction) var/turf/simulated/floor/target = get_step(src,direction)
if(istype(target)) if(istype(target))
air_master.tiles_to_update.Add(target) air_master.tiles_to_update |= target
Del() Del()
if(active_hotspot) if(active_hotspot)
@@ -172,10 +172,9 @@ turf
if(air_check_directions&direction) //I can connect air in this direction if(air_check_directions&direction) //I can connect air in this direction
if(!CanPass(null, T, 0, 0)) //If either block air, we must look to see if the adjacent turfs need rebuilt. if(!CanPass(null, T, 0, 0)) //If either block air, we must look to see if the adjacent turfs need rebuilt.
if(T.zone && !T.zone.rebuild) if(T.zone && !T.zone.rebuild)
for(var/direction2 in cardinal - direction) //Check all other directions for air that might be connected. var/turf/simulated/NT = get_step(src, reverse_direction(direction))
var/turf/simulated/NT = get_step(src, direction2) if(istype(NT) && NT.zone && NT.zone == T.zone)
if(NT && NT.zone && NT.zone == T.zone && !NT.HasDoor()) T.zone.rebuild = 1
T.zone.rebuild = 1
else else
ZConnect(src,T) ZConnect(src,T)