[−][src]Trait weasel::space::SpaceRules
Rules to govern the space dimension in a game.
This rules are used to determine if an entity can occupy a given position and to keep a model containing all entities' positions.
Associated Types
type Position: Eq + Clone + Debug + Serialize + for<'a> Deserialize<'a>
See Position.
type SpaceSeed: Clone + Debug + Serialize + for<'a> Deserialize<'a>
See SpaceSeed.
type SpaceModel
See SpaceModel.
Required methods
fn generate_model(&self, seed: &Option<Self::SpaceSeed>) -> Self::SpaceModel
Generates a SpaceModel
starting from a SpaceSeed
.
Provided methods
fn check_move(
&self,
_model: &Self::SpaceModel,
_entity: Option<&dyn Entity<R>>,
_position: &Self::Position
) -> bool
&self,
_model: &Self::SpaceModel,
_entity: Option<&dyn Entity<R>>,
_position: &Self::Position
) -> bool
Checks if a given entity can move into a new position.
In the case entity is empty, it is assumed that position
will be the starting one of a
new entity.
The provided implementation accepts every move.
fn move_entity(
&self,
_model: &mut Self::SpaceModel,
_entity: Option<&dyn Entity<R>>,
_position: &Self::Position,
_metrics: &mut WriteMetrics<R>
)
&self,
_model: &mut Self::SpaceModel,
_entity: Option<&dyn Entity<R>>,
_position: &Self::Position,
_metrics: &mut WriteMetrics<R>
)
Moves an entity into a new position.
Position's correctness will be validated beforehand with check_move
.
In the case entity is empty, it is assumed that position
will be the starting one of a
new entity.
The provided implementation does nothing.
fn translate_entity(
&self,
_model: &Self::SpaceModel,
_new_model: &mut Self::SpaceModel,
_entity: &mut dyn Entity<R>,
_event_queue: &mut Option<EventQueue<R>>,
_metrics: &mut WriteMetrics<R>
)
&self,
_model: &Self::SpaceModel,
_new_model: &mut Self::SpaceModel,
_entity: &mut dyn Entity<R>,
_event_queue: &mut Option<EventQueue<R>>,
_metrics: &mut WriteMetrics<R>
)
Translate an entity from one space model to another one.
This method must apply the necessary changes to the entity's position and to the new model so that positions consistency is preserved.
The provided implementation does nothing.