Skip to content

Commit 96774ce

Browse files
authored
Merge pull request #28 from MonkeFix/lunacys/repo-restructure
Repo restructure
2 parents 5ab9183 + 9200938 commit 96774ce

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+1080
-852
lines changed

.vscode/tasks.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,14 @@
1313
"isDefault": true
1414
},
1515
"args": [
16+
"--bin",
17+
"vs-rs",
1618
"--features",
1719
"bevy/dynamic_linking"
18-
]
20+
],
21+
"options": {
22+
"cwd": "./vs-rs/"
23+
}
1924
}
2025
]
2126
}

Cargo.lock

+58
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+12-18
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,16 @@
1-
[package]
2-
name = "vs-rs"
3-
version = "0.1.0"
4-
edition = "2021"
1+
[workspace]
2+
resolver = "2"
3+
members = [
4+
"common",
5+
"collisions",
6+
"movement",
7+
"vs-assets",
8+
"worldgen",
9+
"vs-rs"
10+
]
511

6-
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7-
8-
[dependencies]
9-
bevy = { version = "0.14" }
10-
rand = "0.8.5"
11-
serde_json = "1.0"
12-
serde = "1.0"
13-
num_enum = "0.7"
14-
bevy_framepace = "0.17"
15-
bevy-inspector-egui = { version = "0.25" }
16-
bevy_simple_tilemap = "0.15"
17-
tiled = "0.12"
18-
pathfinding = "4.9"
19-
thiserror = "1.0"
12+
[profile.release]
13+
lto = true
2014

2115
# Enable a small amount of optimization in debug mode
2216
[profile.dev]

collisions/Cargo.toml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[package]
2+
name = "collisions"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
"common" = { path = "../common" }
8+
"bevy" = { version = "0.14"}
9+
num_enum = "0.7"

src/collisions/colliders.rs renamed to collisions/src/colliders.rs

+12-19
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
#![allow(dead_code)]
2-
3-
use crate::movement::Position;
41
use bevy::prelude::*;
2+
use common::FRect;
3+
use common::Position;
54

65
use super::{
7-
circle_to_circle, rect_to_circle, rect_to_rect,
6+
shape_tests::*,
87
shapes::{ColliderShape, ColliderShapeType},
98
store::ALL_LAYERS,
109
ColliderId, CollisionResultRef, RaycastHit,
@@ -52,10 +51,10 @@ impl Collider {
5251
pub fn new(data: ColliderData, entity: Option<Entity>) -> Self {
5352
let bounds = match data.shape_type {
5453
ColliderShapeType::Circle { radius } => {
55-
super::Rect::new(0.0, 0.0, radius * 2.0, radius * 2.0)
54+
FRect::new(0.0, 0.0, radius * 2.0, radius * 2.0)
5655
}
57-
ColliderShapeType::Box { width, height } => super::Rect::new(0.0, 0.0, width, height),
58-
ColliderShapeType::None => super::Rect::new(0.0, 0.0, 0.0, 0.0),
56+
ColliderShapeType::Box { width, height } => FRect::new(0.0, 0.0, width, height),
57+
ColliderShapeType::None => FRect::new(0.0, 0.0, 0.0, 0.0),
5958
};
6059

6160
let mut shape = ColliderShape::new(data.shape_type);
@@ -78,7 +77,7 @@ impl Collider {
7877
self.shape.position + self.data.local_offset
7978
}
8079

81-
pub fn bounds(&self) -> super::Rect {
80+
pub fn bounds(&self) -> FRect {
8281
self.shape.bounds
8382
}
8483

@@ -240,20 +239,16 @@ impl Collider {
240239
pub fn recalc_bounds(&mut self) {
241240
match self.shape.shape_type {
242241
ColliderShapeType::Circle { radius } => {
243-
self.shape.bounds.x =
244-
self.shape.center.x + self.data.local_offset.x - radius;
245-
self.shape.bounds.y =
246-
self.shape.center.y + self.data.local_offset.y - radius;
242+
self.shape.bounds.x = self.shape.center.x + self.data.local_offset.x - radius;
243+
self.shape.bounds.y = self.shape.center.y + self.data.local_offset.y - radius;
247244
self.shape.bounds.width = radius * 2.0;
248245
self.shape.bounds.height = radius * 2.0;
249246
}
250247
ColliderShapeType::Box { width, height } => {
251248
let hw = width / 2.0;
252249
let hh = height / 2.0;
253-
self.shape.bounds.x =
254-
self.shape.position.x + self.data.local_offset.x - hw;
255-
self.shape.bounds.y =
256-
self.shape.position.y + self.data.local_offset.y - hh;
250+
self.shape.bounds.x = self.shape.position.x + self.data.local_offset.x - hw;
251+
self.shape.bounds.y = self.shape.position.y + self.data.local_offset.y - hh;
257252
self.shape.bounds.width = width;
258253
self.shape.bounds.height = height;
259254
}
@@ -299,8 +294,6 @@ impl Collider {
299294
}
300295

301296
fn needs_update(&self, position: &Position) -> bool {
302-
!self.is_registered
303-
|| self.shape.position != position.0
304-
|| self.shape.center != position.0
297+
!self.is_registered || self.shape.position != position.0 || self.shape.center != position.0
305298
}
306299
}

collisions/src/lib.rs

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
use bevy::prelude::*;
2+
use colliders::Collider;
3+
4+
pub mod colliders;
5+
pub mod plugin;
6+
pub mod prelude;
7+
pub mod shape_tests;
8+
pub mod shapes;
9+
mod spatial_hash;
10+
pub mod store;
11+
12+
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Reflect)]
13+
pub struct ColliderId(pub u32);
14+
15+
#[derive(Debug, Default, Clone, Copy)]
16+
pub struct CollisionResult {
17+
pub collider: Option<ColliderId>,
18+
pub normal: Vec2,
19+
pub min_translation: Vec2,
20+
pub point: Vec2,
21+
}
22+
23+
#[derive(Debug, Default, Clone, Copy)]
24+
pub struct CollisionResultRef<'a> {
25+
pub collider: Option<&'a Collider>,
26+
pub normal: Vec2,
27+
pub min_translation: Vec2,
28+
pub point: Vec2,
29+
}
30+
31+
impl CollisionResult {
32+
pub fn invert(&mut self) {
33+
self.normal.x = -self.normal.x;
34+
self.normal.y = -self.normal.y;
35+
36+
self.min_translation.x = -self.min_translation.x;
37+
self.min_translation.y = -self.min_translation.y;
38+
}
39+
40+
pub fn from_ref(result: &CollisionResultRef) -> Self {
41+
let collider = result.collider.map(|col| col.id);
42+
43+
Self {
44+
collider,
45+
normal: result.normal,
46+
min_translation: result.min_translation,
47+
point: result.point,
48+
}
49+
}
50+
}
51+
52+
impl<'a> CollisionResultRef<'a> {
53+
pub fn invert(&mut self) {
54+
self.normal.x = -self.normal.x;
55+
self.normal.y = -self.normal.y;
56+
57+
self.min_translation.x = -self.min_translation.x;
58+
self.min_translation.y = -self.min_translation.y;
59+
}
60+
}
61+
62+
#[derive(Debug, Default, Clone, Copy)]
63+
pub struct RaycastHit {
64+
pub collider: Option<ColliderId>,
65+
pub fraction: f32,
66+
pub distance: f32,
67+
pub point: Vec2,
68+
pub normal: Vec2,
69+
pub centroid: Vec2,
70+
}

src/collisions/plugin.rs renamed to collisions/src/plugin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#![allow(dead_code)]
22

33
use super::{colliders::ColliderData, store::ColliderStore, ColliderId};
4-
use crate::movement::Position;
54
use bevy::{ecs::system::EntityCommands, prelude::*};
5+
use common::Position;
66

77
#[derive(Component, Debug, Clone, Copy, PartialEq, Eq, Reflect, Hash)]
88
pub struct ColliderComponent {

collisions/src/prelude.rs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pub use super::{ColliderId, CollisionResult, CollisionResultRef};
2+
pub use crate::colliders::{Collider, ColliderData};
3+
pub use crate::plugin::{ColliderBundle, ColliderComponent, ColliderDespawnable};
4+
pub use crate::shapes::{ColliderShape, ColliderShapeType};
5+
pub use crate::store::{ColliderIdResolver, ColliderStore, ALL_LAYERS};

0 commit comments

Comments
 (0)