mirror of
https://github.com/Aurorastation/Aurora.3.git
synced 2026-07-19 03:49:10 +01:00
Improve asteroid generation performance
This commit is contained in:
@@ -19,4 +19,11 @@
|
||||
#define ROOM_TEMP_CHAR 4
|
||||
#define MONSTER_CHAR 5
|
||||
#define ARTIFACT_TURF_CHAR 6
|
||||
#define ARTIFACT_CHAR 7
|
||||
#define ARTIFACT_CHAR 7
|
||||
|
||||
#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;\
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.")
|
||||
|
||||
@@ -104,7 +104,8 @@
|
||||
|
||||
// Recurse until size is too small to subdivide.
|
||||
if(isize>3)
|
||||
if(!priority_process) sleep(-1)
|
||||
if(!priority_process)
|
||||
CHECK_TICK
|
||||
iteration++
|
||||
subdivide(iteration, x, y, hsize)
|
||||
subdivide(iteration, x+hsize, y, hsize)
|
||||
@@ -165,4 +166,4 @@
|
||||
else if(map[current_cell] < total)
|
||||
map[current_cell]-=cell_smooth_amt
|
||||
map[current_cell] = max(0,min(cell_range,map[current_cell]))
|
||||
map = next_map
|
||||
map = next_map
|
||||
|
||||
@@ -41,45 +41,45 @@
|
||||
var/tx = ((origin_x-1)+x)*chunk_size
|
||||
var/ty = ((origin_y-1)+y)*chunk_size
|
||||
|
||||
for (var/turf/theTurf in block(locate(tx, ty), locate(chunk_size, chunk_size)))
|
||||
var/turf/simulated/T = theTurf
|
||||
if(!istype(T) || !T.has_resources)
|
||||
continue
|
||||
if(!priority_process)
|
||||
sleep(-1)
|
||||
T.resources = list()
|
||||
T.resources["silicates"] = rand(3,5)
|
||||
T.resources["carbonaceous rock"] = rand(3,5)
|
||||
|
||||
var/current_cell = map[get_map_cell(x,y)]
|
||||
if(current_cell < rare_val) // Surface metals.
|
||||
T.resources["iron"] = rand(RESOURCE_HIGH_MIN, RESOURCE_HIGH_MAX)
|
||||
T.resources["gold"] = rand(RESOURCE_LOW_MIN, RESOURCE_LOW_MAX)
|
||||
T.resources["silver"] = rand(RESOURCE_LOW_MIN, RESOURCE_LOW_MAX)
|
||||
T.resources["uranium"] = rand(RESOURCE_LOW_MIN, RESOURCE_LOW_MAX)
|
||||
T.resources["diamond"] = 0
|
||||
T.resources["phoron"] = 0
|
||||
T.resources["osmium"] = 0
|
||||
T.resources["hydrogen"] = 0
|
||||
else if(current_cell < deep_val) // Rare metals.
|
||||
T.resources["gold"] = rand(RESOURCE_MID_MIN, RESOURCE_MID_MAX)
|
||||
T.resources["silver"] = rand(RESOURCE_MID_MIN, RESOURCE_MID_MAX)
|
||||
T.resources["uranium"] = rand(RESOURCE_MID_MIN, RESOURCE_MID_MAX)
|
||||
T.resources["phoron"] = rand(RESOURCE_MID_MIN, RESOURCE_MID_MAX)
|
||||
T.resources["osmium"] = rand(RESOURCE_MID_MIN, RESOURCE_MID_MAX)
|
||||
T.resources["hydrogen"] = 0
|
||||
T.resources["diamond"] = 0
|
||||
T.resources["iron"] = 0
|
||||
else // Deep metals.
|
||||
T.resources["uranium"] = rand(RESOURCE_LOW_MIN, RESOURCE_LOW_MAX)
|
||||
T.resources["diamond"] = rand(RESOURCE_LOW_MIN, RESOURCE_LOW_MAX)
|
||||
T.resources["phoron"] = rand(RESOURCE_HIGH_MIN, RESOURCE_HIGH_MAX)
|
||||
T.resources["osmium"] = rand(RESOURCE_HIGH_MIN, RESOURCE_HIGH_MAX)
|
||||
T.resources["hydrogen"] = rand(RESOURCE_MID_MIN, RESOURCE_MID_MAX)
|
||||
T.resources["iron"] = 0
|
||||
T.resources["gold"] = 0
|
||||
T.resources["silver"] = 0
|
||||
for(var/i=0,i<chunk_size,i++)
|
||||
for(var/j=0,j<chunk_size,j++)
|
||||
var/turf/simulated/T = locate(tx+j, ty+i, origin_z)
|
||||
if(!istype(T) || !T.has_resources)
|
||||
continue
|
||||
if(!priority_process)
|
||||
CHECK_TICK
|
||||
T.resources = list()
|
||||
T.resources["silicates"] = rand(3,5)
|
||||
T.resources["carbonaceous rock"] = rand(3,5)
|
||||
|
||||
var/current_cell = map[get_map_cell(x,y)]
|
||||
if(current_cell < rare_val) // Surface metals.
|
||||
T.resources["iron"] = rand(RESOURCE_HIGH_MIN, RESOURCE_HIGH_MAX)
|
||||
T.resources["gold"] = rand(RESOURCE_LOW_MIN, RESOURCE_LOW_MAX)
|
||||
T.resources["silver"] = rand(RESOURCE_LOW_MIN, RESOURCE_LOW_MAX)
|
||||
T.resources["uranium"] = rand(RESOURCE_LOW_MIN, RESOURCE_LOW_MAX)
|
||||
T.resources["diamond"] = 0
|
||||
T.resources["phoron"] = 0
|
||||
T.resources["osmium"] = 0
|
||||
T.resources["hydrogen"] = 0
|
||||
else if(current_cell < deep_val) // Rare metals.
|
||||
T.resources["gold"] = rand(RESOURCE_MID_MIN, RESOURCE_MID_MAX)
|
||||
T.resources["silver"] = rand(RESOURCE_MID_MIN, RESOURCE_MID_MAX)
|
||||
T.resources["uranium"] = rand(RESOURCE_MID_MIN, RESOURCE_MID_MAX)
|
||||
T.resources["phoron"] = rand(RESOURCE_MID_MIN, RESOURCE_MID_MAX)
|
||||
T.resources["osmium"] = rand(RESOURCE_MID_MIN, RESOURCE_MID_MAX)
|
||||
T.resources["hydrogen"] = 0
|
||||
T.resources["diamond"] = 0
|
||||
T.resources["iron"] = 0
|
||||
else // Deep metals.
|
||||
T.resources["uranium"] = rand(RESOURCE_LOW_MIN, RESOURCE_LOW_MAX)
|
||||
T.resources["diamond"] = rand(RESOURCE_LOW_MIN, RESOURCE_LOW_MAX)
|
||||
T.resources["phoron"] = rand(RESOURCE_HIGH_MIN, RESOURCE_HIGH_MAX)
|
||||
T.resources["osmium"] = rand(RESOURCE_HIGH_MIN, RESOURCE_HIGH_MAX)
|
||||
T.resources["hydrogen"] = rand(RESOURCE_MID_MIN, RESOURCE_MID_MAX)
|
||||
T.resources["iron"] = 0
|
||||
T.resources["gold"] = 0
|
||||
T.resources["silver"] = 0
|
||||
return
|
||||
|
||||
/datum/random_map/noise/ore/get_map_char(var/value)
|
||||
@@ -88,4 +88,4 @@
|
||||
else if(value < deep_val)
|
||||
return "R"
|
||||
else
|
||||
return "D"
|
||||
return "D"
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
#define ORE_COUNT 5000
|
||||
/*
|
||||
This module is used to generate the debris fields/distribution maps/procedural stations.
|
||||
*/
|
||||
|
||||
// Generates cave systems for the asteroid, and places ore tiles.
|
||||
var/global/list/random_maps = list()
|
||||
var/global/list/map_count = list()
|
||||
|
||||
@@ -58,7 +54,7 @@ var/global/list/map_count = list()
|
||||
|
||||
var/start_time = world.timeofday
|
||||
if(!do_not_announce) admin_notice("<span class='danger'>Generating [name].</span>", R_DEBUG)
|
||||
sleep(-1)
|
||||
CHECK_TICK
|
||||
|
||||
// Testing needed to see how reliable this is (asynchronous calls, called during worldgen), DM ref is not optimistic
|
||||
if(seed)
|
||||
@@ -160,7 +156,8 @@ var/global/list/map_count = list()
|
||||
|
||||
for(var/x = 1, x <= limit_x, x++)
|
||||
for(var/y = 1, y <= limit_y, y++)
|
||||
if(!priority_process) sleep(-1)
|
||||
if(!priority_process)
|
||||
CHECK_TICK
|
||||
apply_to_turf(x,y)
|
||||
|
||||
/datum/random_map/proc/apply_to_turf(var/x,var/y)
|
||||
|
||||
Reference in New Issue
Block a user