@@ -43,6 +43,7 @@ impl<'a> System<'a> for VelocitySystem {
4343 type SystemData = (
4444 WriteStorage < ' a , Pos > ,
4545 WriteStorage < ' a , Vel > ,
46+ ReadStorage < ' a , Vel_ > ,
4647 ReadStorage < ' a , Mass > ,
4748 ReadStorage < ' a , Collider > ,
4849 WriteStorage < ' a , Transform > ,
@@ -53,16 +54,17 @@ impl<'a> System<'a> for VelocitySystem {
5354 Read < ' a , DeltaTime > ,
5455 ) ;
5556
57+ #[ rustfmt:: skip]
5658 fn run (
5759 & mut self ,
58- ( mut pos, mut vel, mass, collider, mut transform, sub, terrain, entities, hierarchy, dt) : Self :: SystemData ,
60+ ( mut pos, mut vel, vel_ , mass, collider, mut transform, sub, terrain, entities, hierarchy, dt) : Self :: SystemData ,
5961 ) {
60- let reset_values: Vec < _ > = ( & collider, & vel, !& terrain, & pos, & mass, & entities)
62+ let reset_values: Vec < _ > = ( & collider, & vel, ( & vel_ ) . maybe ( ) , !& terrain, & pos, & mass, & entities)
6163 . par_join ( )
62- . map ( |( _col1, vel, _, _pos1, _mass, entity1) | {
64+ . map ( |( _col1, vel, vel_ , _, _pos1, _mass, entity1) | {
6365 let mut percent = -1.0 ;
6466 let mut ids = ( entity1. id ( ) , 0 ) ;
65- let v = vel. 0 * dt. 0 . as_secs_f32 ( ) ;
67+ let v = vel. 0 * dt. 0 . as_secs_f32 ( ) + vel_ . map ( |x| x . 0 ) . unwrap_or_else ( Vec2 :: zero ) ;
6668 for ( _, _, _pos2, entity2) in ( & collider, & terrain, & pos, & entities) . join ( ) {
6769 for e1 in hierarchy. children ( entity1) {
6870 for e2 in hierarchy. children ( entity2) {
@@ -81,6 +83,7 @@ impl<'a> System<'a> for VelocitySystem {
8183 }
8284 }
8385 }
86+ log:: debug!( "woop {:?}" , percent) ;
8487 if percent == -1.0 {
8588 ( ids. 0 , core:: u32:: MAX , v)
8689 } else {
@@ -121,10 +124,8 @@ impl<'a> System<'a> for GravitationSystem {
121124
122125 fn run ( & mut self , ( mut vel, mass, present, g, dt) : Self :: SystemData ) {
123126 let dt = dt. 0 . as_secs_f32 ( ) ;
124- if dt < 0.5 {
125- for ( vel, _, _) in ( & mut vel, & mass, & present) . join ( ) {
126- vel. 0 += g. 0 * dt;
127- }
127+ for ( vel, _, _) in ( & mut vel, & mass, & present) . join ( ) {
128+ vel. 0 += g. 0 * dt;
128129 }
129130 }
130131}
@@ -143,6 +144,7 @@ impl<'a> System<'a> for UpdateAnimationSystem {
143144 ReadStorage < ' a , Scale > ,
144145 WriteStorage < ' a , Pos > ,
145146 WriteStorage < ' a , Vel > ,
147+ WriteStorage < ' a , Vel_ > ,
146148 Entities < ' a > ,
147149 ReadExpect < ' a , Hierarchy < Parent > > ,
148150 Read < ' a , ElapsedTime > ,
@@ -164,19 +166,21 @@ impl<'a> System<'a> for UpdateAnimationSystem {
164166 scale,
165167 mut pos,
166168 mut vel,
169+ mut vel_,
167170 entities,
168171 hierarchy,
169172 elapsed,
170173 dt,
171174 ) : Self :: SystemData ,
172175 ) {
173176 let res = & mut * resources:: RESOURCE_TABLE . write ( ) ;
174- for ( mut animation, collider, scale, pos, vel, entity, _) in (
177+ for ( mut animation, collider, scale, pos, vel, mut vel__ , entity, _) in (
175178 & mut animations,
176179 & collider,
177180 & scale,
178181 & mut pos,
179182 & mut vel,
183+ & mut vel_,
180184 & entities,
181185 & present,
182186 )
@@ -268,6 +272,8 @@ impl<'a> System<'a> for UpdateAnimationSystem {
268272 if c ( dv) > 0.0 {
269273 let d = c ( old. pos + old. size ) - c ( new. pos + new. size ) ;
270274 u ( d, d < 0.0 )
275+ } else if c ( dv) == 0.0 {
276+ 0.0
271277 } else {
272278 let d = c ( old. pos - new. pos ) ;
273279 u ( d, d > 0.0 )
@@ -279,8 +285,8 @@ impl<'a> System<'a> for UpdateAnimationSystem {
279285 if x. is_finite ( ) && y. is_finite ( ) {
280286 let diff = Vec2 :: new ( x, y) ;
281287 pos. 0 += diff;
282- vel . 0 - = diff / dt . 0 . as_secs_f32 ( ) ;
283- log:: debug!( "x: {}, y: {}, vel: {:?}" , x, y, vel. 0 ) ;
288+ vel__ . 0 = diff;
289+ log:: debug!( "pos: {:?}, x: {}, y: {}, vel: {:?}" , pos . 0 , x, y, vel. 0 ) ;
284290 for e in hierarchy. children ( entity) {
285291 if let Some ( trans) = mat3. get_mut ( * e) {
286292 trans. mat3 *= Mat3 :: translation ( diff. x ( ) , diff. y ( ) ) ;
0 commit comments