Improve asteroid generation performance

This commit is contained in:
Lohikar
2017-03-04 13:49:12 -06:00
parent 76a891930e
commit 4aeab0d6ce
8 changed files with 172 additions and 80 deletions

View File

@@ -1,11 +1,4 @@
#define CELL_ALIVE(VAL) ((VAL == cell_live_value) && (VAL != cell_dead_value))
#define GET_MAP_CELL(X,Y) ((((Y) - 1) * limit_x) + (X))
#define PREPARE_CELL(X,Y) \
tmp_cell = GET_MAP_CELL(X,Y);\
if (tmp_cell < 1 || tmp_cell > map.len) {\
tmp_cell = null;\
}
#define CELL_ALIVE(VAL) (VAL == cell_live_value)
#define KILL_CELL(CELL, NEXT_MAP) NEXT_MAP[CELL] = cell_dead_value;
#define REVIVE_CELL(CELL, NEXT_MAP) NEXT_MAP[CELL] = cell_live_value;
@@ -42,37 +35,39 @@
// the generator being totally bricked and useless. Fuck it. We're
// hardcoding this shit. Feel free to rewrite and PR a fix. ~ Z
PREPARE_CELL(x,y)
if (tmp_cell && CELL_ALIVE(map[tmp_cell]))
if (tmp_cell && CELL_ALIVE(map[tmp_cell]))
count++
PREPARE_CELL(x+1,y+1)
if (tmp_cell && CELL_ALIVE(map[tmp_cell]))
if (tmp_cell && CELL_ALIVE(map[tmp_cell]))
count++
PREPARE_CELL(x-1,y-1)
if (tmp_cell && CELL_ALIVE(map[tmp_cell]))
if (tmp_cell && CELL_ALIVE(map[tmp_cell]))
count++
PREPARE_CELL(x+1,y-1)
if (tmp_cell && CELL_ALIVE(map[tmp_cell]))
if (tmp_cell && CELL_ALIVE(map[tmp_cell]))
count++
PREPARE_CELL(x-1,y+1)
if (tmp_cell && CELL_ALIVE(map[tmp_cell]))
if (tmp_cell && CELL_ALIVE(map[tmp_cell]))
count++
PREPARE_CELL(x-1,y)
if (tmp_cell && CELL_ALIVE(map[tmp_cell]))
if (tmp_cell && CELL_ALIVE(map[tmp_cell]))
count++
PREPARE_CELL(x,y-1)
if (tmp_cell && CELL_ALIVE(map[tmp_cell]))
if (tmp_cell && CELL_ALIVE(map[tmp_cell]))
count++
PREPARE_CELL(x+1,y)
if (tmp_cell && CELL_ALIVE(map[tmp_cell]))
if (tmp_cell && CELL_ALIVE(map[tmp_cell]))
count++
PREPARE_CELL(x,y+1)
if (tmp_cell && CELL_ALIVE(map[tmp_cell]))
if (tmp_cell && CELL_ALIVE(map[tmp_cell]))
count++
if(count >= cell_threshold)
REVIVE_CELL(current_cell, next_map)
else
KILL_CELL(current_cell, next_map)
CHECK_TICK
map = next_map
/datum/random_map/automata/proc/revive_cell(var/target_cell, var/list/use_next_map, var/final_iter)
@@ -85,8 +80,5 @@
use_next_map = map
use_next_map[target_cell] = cell_dead_value
#undef CELL_ALIVE
#undef GET_MAP_CELL
#undef PREPARE_CELL
#undef KILL_CELL
#undef REVIVE_CELL
#undef REVIVE_CELL

View File

@@ -29,18 +29,73 @@
// Create ore turfs.
/datum/random_map/automata/cave_system/cleanup()
for (var/cell in map)
if (cell == cell_live_value)
ore_turfs += cell
var/tmp_cell
for (var/x = 1; x < limit_x; x++)
for (var/y = 1; y < limit_y; y++)
PREPARE_CELL(x, y)
if (tmp_cell && CELL_ALIVE(map[tmp_cell]))
ore_turfs += tmp_cell
game_log("ASGEN", "Found [ore_turfs.len] ore turfs.")
var/ore_count = round(map.len/20)
var/door_count = 0
var/empty_count = 0
while((ore_count>0) && (ore_turfs.len>0))
if(!priority_process) sleep(-1)
if(!priority_process)
CHECK_TICK
var/check_cell = pick(ore_turfs)
ore_turfs -= check_cell
if(prob(75))
map[check_cell] = DOOR_CHAR // Mineral block
door_count += 1
else
map[check_cell] = EMPTY_CHAR // Rare mineral block.
empty_count += 1
ore_count--
game_log("ASGEN", "Set [door_count] turfs to random minerals.")
game_log("ASGEN", "Set [empty_count] turfs to high-chance random minerals.")
return 1
/datum/random_map/automata/cave_system/apply_to_map()
if(!origin_x) origin_x = 1
if(!origin_y) origin_y = 1
if(!origin_z) origin_z = 1
var/tmp_cell
var/x
var/y
var/new_path
var/num_applied = 0
for (var/thing in block(locate(origin_x, origin_y, origin_z), locate(limit_x, limit_y, origin_z)))
var/turf/T = thing
new_path = null
if (!T || (target_turf_type && !istype(T, target_turf_type)))
continue
x = T.x
y = T.y
PREPARE_CELL(x,y)
if (!tmp_cell)
continue
switch (map[tmp_cell])
if(DOOR_CHAR)
new_path = mineral_sparse
if(EMPTY_CHAR)
new_path = mineral_rich
if(FLOOR_CHAR)
new_path = floor_type
if(WALL_CHAR)
new_path = wall_type
if (!new_path)
continue
num_applied += 1
new new_path(T)
CHECK_TICK
game_log("ASGEN", "Applied [num_applied] turfs.")