Skip to content

Commit 1324af9

Browse files
committed
refactor: move physics to pixel-game-lib
1 parent 620644c commit 1324af9

File tree

19 files changed

+38
-2387
lines changed

19 files changed

+38
-2387
lines changed

Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ bvh-arena = "1"
3232
raqote = { version = "0.8", default-features = false }
3333
bitvec = "1"
3434
line_drawing = "1"
35-
drawille = { version = "0.3.0", optional = true }
36-
spiral = "0.2.0"
37-
pixel-game-lib = "0.3.0"
38-
winit_input_helper = "0.14.1"
35+
drawille = { version = "0.3", optional = true }
36+
spiral = "0.2"
37+
pixel-game-lib = "0.3"
38+
winit_input_helper = "0.14"
3939

4040
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
4141
fastrand = "2"

src/debug.rs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,20 @@
11
use line_drawing::Bresenham;
2-
use pixel_game_lib::window::Key;
3-
use serde::Deserialize;
4-
use vek::{Extent2, Vec2};
5-
use winit_input_helper::WinitInputHelper;
6-
7-
use crate::{
8-
camera::Camera,
9-
graphics::Color,
2+
use pixel_game_lib::{
103
math::{Iso, Rotation},
11-
object::ObjectSettings,
124
physics::{
135
collision::{shape::Shape, CollisionResponse},
146
rigidbody::{RigidBodyBuilder, RigidBodyHandle},
157
Physics,
168
},
17-
projectile::Projectile,
18-
solid_shape::SolidShape,
19-
sprite::SpriteOffset,
20-
terrain::Terrain,
21-
SIZE,
9+
window::Key,
10+
};
11+
use serde::Deserialize;
12+
use vek::{Extent2, Vec2};
13+
use winit_input_helper::WinitInputHelper;
14+
15+
use crate::{
16+
camera::Camera, graphics::Color, object::ObjectSettings, projectile::Projectile,
17+
solid_shape::SolidShape, terrain::Terrain, SIZE,
2218
};
2319

2420
/// Asset paths.
@@ -164,7 +160,7 @@ impl DebugDraw {
164160
if let Some(mouse) = mouse {
165161
if self.screen == DebugScreen::SpawnCubes {
166162
if input.key_held(Key::Space) {
167-
self.physics.step(dt);
163+
self.physics.step(dt, &crate::settings().physics);
168164
}
169165

170166
if input.mouse_released(0) {

src/game.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
use assets_manager::{loader::TomlLoader, Asset};
2-
use pixel_game_lib::canvas::Canvas;
2+
use pixel_game_lib::{
3+
canvas::Canvas,
4+
physics::{Physics, PhysicsSettings},
5+
};
36
use serde::Deserialize;
47
use vek::Vec2;
58
use winit_input_helper::WinitInputHelper;
@@ -8,7 +11,6 @@ use winit_input_helper::WinitInputHelper;
811
use crate::debug::{DebugDraw, DebugSettings};
912
use crate::{
1013
camera::Camera,
11-
physics::{Physics, Settings as PhysicsSettings},
1214
projectile::Projectile,
1315
terrain::Settings as TerrainSettings,
1416
terrain::Terrain,
@@ -109,7 +111,7 @@ impl GameState {
109111
}
110112

111113
// Simulate the physics
112-
self.physics.step(dt);
114+
self.physics.step(dt, &settings.physics);
113115

114116
// Update all projectiles
115117
self.projectiles

src/gen/isoline.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use itertools::Itertools;
2+
use pixel_game_lib::physics::collision::shape::Shape;
23
use vek::{Extent2, Vec2};
34

4-
use crate::physics::collision::shape::Shape;
5-
65
use super::bitmap::Bitmap;
76

87
/// Isoline mesh from a bitmap that can be updated.

src/main.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ mod font;
66
mod game;
77
mod gen;
88
mod graphics;
9-
mod math;
109
mod object;
11-
mod physics;
1210
mod projectile;
1311
mod random;
1412
mod solid_shape;

src/math.rs

Lines changed: 0 additions & 250 deletions
This file was deleted.

src/object.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
use assets_manager::{loader::TomlLoader, AnyCache, Asset, BoxedError, Compound, SharedString};
2+
use pixel_game_lib::physics::{collision::shape::Shape, rigidbody::RigidBodyBuilder};
23
use serde::Deserialize;
34
use vek::{Extent2, Vec2};
45

5-
use crate::{
6-
physics::{collision::shape::Shape, rigidbody::RigidBodyBuilder},
7-
sprite::Sprite,
8-
};
6+
use crate::sprite::Sprite;
97

108
/// Loadable object with physics.
119
pub struct ObjectSettings {

0 commit comments

Comments
 (0)