Skip to content

Commit

Permalink
Extract de-types to a crate (#718)
Browse files Browse the repository at this point in the history
`de_types` is designed to be used across various crates, not just the
game itself. It has smaller dependency tree (e.g. by Bevy sub-tree). As
a result, `de_map` no longer depends on `de_core` and thus Bevy.
  • Loading branch information
Indy2222 authored Sep 11, 2023
1 parent b1c208c commit 6fa88d4
Show file tree
Hide file tree
Showing 73 changed files with 491 additions and 371 deletions.
34 changes: 29 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ de_pathing = { path = "crates/pathing", version = "0.1.0-dev" }
de_signs = { path = "crates/signs", version = "0.1.0-dev" }
de_spawner = { path = "crates/spawner", version = "0.1.0-dev" }
de_terrain = { path = "crates/terrain", version = "0.1.0-dev" }
de_types = { path = "crates/types", version = "0.1.0-dev" }
de_uom = { path = "crates/uom", version = "0.1.0-dev" }

# Other
Expand Down
1 change: 1 addition & 0 deletions crates/behaviour/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ categories.workspace = true
de_core.workspace = true
de_objects.workspace = true
de_pathing.workspace = true
de_types.workspace = true

# Other
bevy.workspace = true
Expand Down
3 changes: 2 additions & 1 deletion crates/behaviour/src/chase.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use bevy::prelude::*;
use de_core::{gamestate::GameState, projection::ToFlat};
use de_core::gamestate::GameState;
use de_pathing::{PathQueryProps, PathTarget, UpdateEntityPathEvent};
use de_types::projection::ToFlat;

pub(crate) struct ChasePlugin;

Expand Down
3 changes: 2 additions & 1 deletion crates/camera/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ categories.workspace = true
[dependencies]
# DE
de_conf.workspace = true
de_uom.workspace = true
de_core.workspace = true
de_map.workspace = true
de_terrain.workspace = true
de_types.workspace = true
de_uom.workspace = true

# Other
bevy.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion crates/camera/src/camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ use de_core::{
cleanup::DespawnOnGameExit,
events::ResendEventPlugin,
gamestate::GameState,
projection::ToAltitude,
schedule::{InputSchedule, Movement, PreMovement},
state::AppState,
};
use de_map::size::MapBounds;
use de_terrain::{TerrainCollider, MAX_ELEVATION};
use de_types::projection::ToAltitude;
use de_uom::{InverseSecond, Metre, Quantity, Radian, Second};
use iyes_progress::prelude::*;
use parry3d::{math::Vector, query::Ray};
Expand Down
6 changes: 3 additions & 3 deletions crates/combat/src/attack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{cmp::Ordering, collections::BinaryHeap};

use bevy::prelude::*;
use de_behaviour::{ChaseSet, ChaseTarget, ChaseTargetEvent};
use de_core::{gamestate::GameState, objects::ObjectType};
use de_core::{gamestate::GameState, objects::ObjectTypeComponent};
use de_index::SpatialQuery;
use de_objects::{LaserCannon, SolidObjects};
use parry3d::query::Ray;
Expand Down Expand Up @@ -119,15 +119,15 @@ fn update_positions(
mut commands: Commands,
solids: SolidObjects,
mut cannons: Query<(Entity, &Transform, &LaserCannon, &mut Attacking)>,
targets: Query<(&Transform, &ObjectType)>,
targets: Query<(&Transform, &ObjectTypeComponent)>,
sightline: SpatialQuery<Entity>,
) {
for (attacker, transform, cannon, mut attacking) in cannons.iter_mut() {
match targets.get(attacking.enemy) {
Ok((enemy_transform, &target_type)) => {
attacking.muzzle = transform.translation + cannon.muzzle();

let enemy_aabb = solids.get(target_type).collider().aabb();
let enemy_aabb = solids.get(*target_type).collider().aabb();
let enemy_centroid = enemy_transform.translation + Vec3::from(enemy_aabb.center());
let direction = (enemy_centroid - attacking.muzzle)
.try_normalize()
Expand Down
1 change: 1 addition & 0 deletions crates/construction/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ de_objects.workspace = true
de_pathing.workspace = true
de_signs.workspace = true
de_spawner.workspace = true
de_types.workspace = true

# Other
ahash.workspace = true
Expand Down
31 changes: 20 additions & 11 deletions crates/construction/src/manufacturing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ use de_audio::spatial::{PlaySpatialAudioEvent, Sound};
use de_core::{
cleanup::DespawnOnGameExit,
gamestate::GameState,
objects::{Active, ActiveObjectType, ObjectType, UnitType, PLAYER_MAX_UNITS},
player::Player,
projection::{ToAltitude, ToFlat},
objects::{Active, ObjectTypeComponent},
player::PlayerComponent,
state::AppState,
};
use de_index::SpatialQuery;
Expand All @@ -18,6 +17,11 @@ use de_signs::{
LineLocation, UpdateLineEndEvent, UpdateLineLocationEvent, UpdatePoleLocationEvent,
};
use de_spawner::{ObjectCounter, SpawnBundle};
use de_types::{
objects::{ActiveObjectType, ObjectType, UnitType, PLAYER_MAX_UNITS},
player::Player,
projection::{ToAltitude, ToFlat},
};
use parry2d::bounding_volume::Aabb;
use parry3d::math::Isometry;

Expand Down Expand Up @@ -290,12 +294,12 @@ impl ProductionItem {
fn configure(
mut commands: Commands,
solids: SolidObjects,
new: Query<(Entity, &Transform, &ObjectType), Added<Active>>,
new: Query<(Entity, &Transform, &ObjectTypeComponent), Added<Active>>,
mut pole_events: EventWriter<UpdatePoleLocationEvent>,
mut line_events: EventWriter<UpdateLineLocationEvent>,
) {
for (entity, transform, &object_type) in new.iter() {
let solid = solids.get(object_type);
let solid = solids.get(*object_type);
if let Some(factory) = solid.factory() {
let start = transform.transform_point(factory.position().to_msl());
let local_aabb = solid.ichnography().local_aabb();
Expand Down Expand Up @@ -351,12 +355,12 @@ fn enqueue(
fn check_spawn_locations(
solids: SolidObjects,
space: SpatialQuery<Entity>,
mut factories: Query<(Entity, &ObjectType, &Transform, &mut AssemblyLine)>,
mut factories: Query<(Entity, &ObjectTypeComponent, &Transform, &mut AssemblyLine)>,
) {
for (entity, &object_type, transform, mut line) in factories.iter_mut() {
line.blocks_mut().spawn_location = match line.current() {
Some(unit_type) => {
let factory = solids.get(object_type).factory().unwrap();
let factory = solids.get(*object_type).factory().unwrap();
let collider = solids
.get(ObjectType::Active(ActiveObjectType::Unit(unit_type)))
.collider();
Expand All @@ -377,7 +381,7 @@ fn check_spawn_locations(
fn produce(
time: Res<Time>,
counter: Res<ObjectCounter>,
mut factories: Query<(Entity, &Player, &mut AssemblyLine)>,
mut factories: Query<(Entity, &PlayerComponent, &mut AssemblyLine)>,
mut deliver_events: EventWriter<DeliverEvent>,
) {
let mut counts: AHashMap<Player, u32> = AHashMap::from_iter(
Expand All @@ -387,7 +391,7 @@ fn produce(
);

for (factory, &player, mut assembly) in factories.iter_mut() {
let player_count = counts.entry(player).or_default();
let player_count = counts.entry(*player).or_default();

loop {
assembly.blocks_mut().map_capacity = *player_count >= PLAYER_MAX_UNITS;
Expand All @@ -407,7 +411,12 @@ fn deliver(
solids: SolidObjects,
mut deliver_events: EventReader<DeliverEvent>,
mut path_events: EventWriter<UpdateEntityPathEvent>,
factories: Query<(&Transform, &ObjectType, &Player, &DeliveryLocation)>,
factories: Query<(
&Transform,
&ObjectTypeComponent,
&PlayerComponent,
&DeliveryLocation,
)>,
mut play_audio: EventWriter<PlaySpatialAudioEvent>,
) {
for delivery in deliver_events.iter() {
Expand All @@ -421,7 +430,7 @@ fn deliver(
factories.get(delivery.factory()).unwrap();
let unit_object_type = ObjectType::Active(ActiveObjectType::Unit(delivery.unit()));

let factory = solids.get(factory_object_type).factory().unwrap();
let factory = solids.get(*factory_object_type).factory().unwrap();
debug_assert!(factory.products().contains(&delivery.unit()));
let spawn_point = transform.transform_point(factory.position().to_msl());

Expand Down
1 change: 1 addition & 0 deletions crates/controller/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ de_pathing.workspace = true
de_signs.workspace = true
de_spawner.workspace = true
de_terrain.workspace = true
de_types.workspace = true

# Other
ahash.workspace = true
Expand Down
Loading

0 comments on commit 6fa88d4

Please sign in to comment.