MCPcopy Create free account
hub / github.com/clockworklabs/BitCraftPublic / build

Method build

BitCraftServer/packages/game/src/game/location_cache.rs:223–270  ·  view source on GitHub ↗
(ctx: &ReducerContext)

Source from the content-addressed store, hash-verified

221
222 pub fn build(ctx: &ReducerContext) {
223 let mut cache = LocationCache::new();
224 let mut terrain_cache = TerrainChunkCache::fetch(ctx);
225
226 let biomes_count = Biome::iter().count();
227 for _ in 0..biomes_count {
228 cache.biome_chunks.push(0.0);
229 }
230
231 // spawning points
232 for terrain_chunk in terrain_cache.iter_cached_values() {
233 for terrain_cell in terrain_chunk.local_iter(1) {
234 if terrain_cell.zoning_type == 1 && !terrain_cell.is_submerged() {
235 cache.spawn_locations.push(terrain_cell.coordinates().center_small_tile());
236 }
237 cache.region_max_x = std::cmp::max(terrain_cell.x, cache.region_max_x);
238 cache.region_max_z = std::cmp::max(terrain_cell.z, cache.region_max_z);
239 cache.region_min_x = std::cmp::min(terrain_cell.x, cache.region_min_x);
240 cache.region_min_z = std::cmp::min(terrain_cell.z, cache.region_min_z);
241 cache.biome_chunks[terrain_cell.biome() as usize] += 1.0;
242 }
243 }
244
245 // divide biome sizes by chunk size
246 for chunk_size in cache.biome_chunks.iter_mut() {
247 *chunk_size /= (TERRAIN_CHUNK_HEIGHT * TERRAIN_CHUNK_WIDTH) as f32;
248 }
249
250 cache.region_max_x += 1;
251 cache.region_max_z += 1;
252
253 log::info!("Starting location count {}", cache.spawn_locations.len());
254
255 if cache.region_max_x == 1 && cache.region_max_z == 1 {
256 log::info!("No world loaded, not building enemy spawn location cache.");
257 } else {
258 log::debug!("Started building enemy spawn location cache");
259 cache.build_enemy_spawn_locations(ctx, &mut terrain_cache);
260 log::debug!("Done building enemy spawn location cache");
261 }
262
263 cache.collect_traveler_ruins_ids(ctx);
264 cache.collect_all_ruins_ids(ctx);
265
266 if ctx.db.location_cache().try_insert(cache).is_err() {
267 log::error!("Failed to insert location cache");
268 }
269 }
270}

Callers

nothing calls this directly

Calls 11

iter_cached_valuesMethod · 0.80
local_iterMethod · 0.80
is_submergedMethod · 0.80
center_small_tileMethod · 0.80
collect_all_ruins_idsMethod · 0.80
location_cacheMethod · 0.80
countMethod · 0.45
coordinatesMethod · 0.45
biomeMethod · 0.45

Tested by

no test coverage detected