use wpos_to_cpos

This commit is contained in:
Isse 2023-03-08 22:40:16 +01:00 committed by Joshua Barretto
parent 1a117f1331
commit 64bd11d34a
3 changed files with 6 additions and 13 deletions

View File

@ -1273,9 +1273,7 @@ fn handle_rtsim_chunk(
use crate::rtsim2::{ChunkStates, RtSim}; use crate::rtsim2::{ChunkStates, RtSim};
let pos = position(server, target, "target")?; let pos = position(server, target, "target")?;
let chunk_key = pos.0.xy().map2(TerrainChunkSize::RECT_SIZE, |e, sz: u32| { let chunk_key = pos.0.xy().as_::<i32>().wpos_to_cpos();
e as i32 / sz as i32
});
let rtsim = server.state.ecs().read_resource::<RtSim>(); let rtsim = server.state.ecs().read_resource::<RtSim>();
let data = rtsim.state().data(); let data = rtsim.state().data();

View File

@ -1,5 +1,5 @@
use crate::rtsim2::{event::OnBlockChange, ChunkStates}; use crate::rtsim2::{event::OnBlockChange, ChunkStates};
use common::{terrain::TerrainChunk, vol::RectRasterableVol}; use common::{terrain::{TerrainChunk, CoordinateConversions}, vol::RectRasterableVol};
use rtsim2::{RtState, Rule, RuleError}; use rtsim2::{RtState, Rule, RuleError};
pub struct DepleteResources; pub struct DepleteResources;
@ -10,8 +10,7 @@ impl Rule for DepleteResources {
let key = ctx let key = ctx
.event .event
.wpos .wpos
.xy() .xy().wpos_to_cpos();
.map2(TerrainChunk::RECT_SIZE, |e, sz| e.div_euclid(sz as i32));
if let Some(Some(chunk_state)) = ctx.state.resource_mut::<ChunkStates>().0.get(key) { if let Some(Some(chunk_state)) = ctx.state.resource_mut::<ChunkStates>().0.get(key) {
let mut chunk_res = ctx.state.data().nature.get_chunk_resources(key); let mut chunk_res = ctx.state.data().nature.get_chunk_resources(key);
// Remove resources // Remove resources

View File

@ -10,7 +10,7 @@ use common::{
rtsim::{RtSimController, RtSimEntity, RtSimVehicle}, rtsim::{RtSimController, RtSimEntity, RtSimVehicle},
slowjob::SlowJobPool, slowjob::SlowJobPool,
trade::{Good, SiteInformation}, trade::{Good, SiteInformation},
LoadoutBuilder, SkillSetBuilder, LoadoutBuilder, SkillSetBuilder, terrain::CoordinateConversions,
}; };
use common_ecs::{Job, Origin, Phase, System}; use common_ecs::{Job, Origin, Phase, System};
use rtsim2::data::{ use rtsim2::data::{
@ -216,9 +216,7 @@ impl<'a> System<'a> for Sys {
let data = &mut *rtsim.state.data_mut(); let data = &mut *rtsim.state.data_mut();
for (vehicle_id, vehicle) in data.npcs.vehicles.iter_mut() { for (vehicle_id, vehicle) in data.npcs.vehicles.iter_mut() {
let chunk = vehicle.wpos.xy().map2(TerrainChunk::RECT_SIZE, |e, sz| { let chunk = vehicle.wpos.xy().as_::<i32>().wpos_to_cpos();
(e as i32).div_euclid(sz as i32)
});
if matches!(vehicle.mode, SimulationMode::Simulated) if matches!(vehicle.mode, SimulationMode::Simulated)
&& chunk_states.0.get(chunk).map_or(false, |c| c.is_some()) && chunk_states.0.get(chunk).map_or(false, |c| c.is_some())
@ -277,9 +275,7 @@ impl<'a> System<'a> for Sys {
} }
for (npc_id, npc) in data.npcs.npcs.iter_mut() { for (npc_id, npc) in data.npcs.npcs.iter_mut() {
let chunk = npc.wpos.xy().map2(TerrainChunk::RECT_SIZE, |e, sz| { let chunk = npc.wpos.xy().as_::<i32>().wpos_to_cpos();
(e as i32).div_euclid(sz as i32)
});
// Load the NPC into the world if it's in a loaded chunk and is not already // Load the NPC into the world if it's in a loaded chunk and is not already
// loaded // loaded