Compare commits

...

1 Commits

Author SHA1 Message Date
b4e1678b48 introduce lifetime of body 2026-01-27 10:35:32 -08:00
4 changed files with 18 additions and 13 deletions

View File

@@ -7,13 +7,14 @@ pub struct Body<T>{
pub time:Time<T>,
}
#[derive(Clone,Copy,Debug,Hash)]
pub struct Trajectory<T>{
pub struct Trajectory<'a,T>{
pub position:Planar64Vec3,
pub velocity:Planar64Vec3,
pub acceleration:Planar64Vec3,
pub time:Time<T>,
lifetime:core::marker::PhantomData<&'a Body<T>>,
}
impl<T> std::ops::Neg for Trajectory<T>{
impl<T> std::ops::Neg for Trajectory<'_,T>{
type Output=Self;
fn neg(self)->Self::Output{
Self{
@@ -21,17 +22,19 @@ impl<T> std::ops::Neg for Trajectory<T>{
velocity:-self.velocity,
acceleration:self.acceleration,
time:-self.time,
lifetime:core::marker::PhantomData,
}
}
}
impl<T:Copy> std::ops::Neg for &Trajectory<T>{
type Output=Trajectory<T>;
impl<'a,T:Copy> std::ops::Neg for &Trajectory<'a,T>{
type Output=Trajectory<'a,T>;
fn neg(self)->Self::Output{
Trajectory{
position:self.position,
velocity:-self.velocity,
acceleration:self.acceleration,
time:-self.time,
lifetime:core::marker::PhantomData,
}
}
}
@@ -47,22 +50,23 @@ impl<T> Body<T>
time,
}
}
pub const fn with_acceleration(self,acceleration:Planar64Vec3)->Trajectory<T>{
pub const fn with_acceleration<'a>(&'a self,acceleration:Planar64Vec3)->Trajectory<'a,T>{
let Body{
position,
velocity,
time,
}=self;
}=*self;
Trajectory{
position,
velocity,
acceleration,
time,
lifetime:core::marker::PhantomData,
}
}
}
impl<T> Trajectory<T>
impl<T> Trajectory<'_,T>
where Time<T>:Copy,
{
pub const ZERO:Self=Self::new(vec3::zero(),vec3::zero(),vec3::zero(),Time::ZERO);
@@ -72,9 +76,10 @@ impl<T> Trajectory<T>
velocity,
acceleration,
time,
lifetime:core::marker::PhantomData,
}
}
pub fn relative_to(&self,trj0:&Trajectory<T>,time:Time<T>)->Trajectory<T>{
pub fn relative_to(&self,trj0:&Self,time:Time<T>)->Self{
//(p0,v0,a0,t0)
//(p1,v1,a1,t1)
Trajectory::new(
@@ -185,7 +190,7 @@ impl<T> std::fmt::Display for Body<T>{
write!(f,"p({}) v({}) t({})",self.position,self.velocity,self.time)
}
}
impl<T> std::fmt::Display for Trajectory<T>{
impl<T> std::fmt::Display for Trajectory<'_,T>{
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
write!(f,"p({}) v({}) a({}) t({})",self.position,self.velocity,self.acceleration,self.time)
}

View File

@@ -5,7 +5,7 @@ use strafesnet_common::model::{self,MeshId,PolygonIter};
use strafesnet_common::integer::{self,vec3,Fixed,Planar64,Planar64Vec3,Ratio};
use strafesnet_common::physics::Time;
type Trajectory=crate::body::Trajectory<strafesnet_common::physics::TimeInner>;
type Trajectory<'a>=crate::body::Trajectory<'a,strafesnet_common::physics::TimeInner>;
struct AsRefHelper<T>(T);
impl<T> AsRef<T> for AsRefHelper<T>{

View File

@@ -15,7 +15,7 @@ pub use strafesnet_common::physics::{Time,TimeInner};
use gameplay::ModeState;
pub type Body=crate::body::Body<TimeInner>;
pub type Trajectory=crate::body::Trajectory<TimeInner>;
pub type Trajectory<'a>=crate::body::Trajectory<'a,TimeInner>;
type MouseState=strafesnet_common::mouse::MouseState<TimeInner>;
//external influence
@@ -909,7 +909,7 @@ impl PhysicsState{
pub const fn body(&self)->&Body{
&self.body
}
pub fn camera_trajectory(&self,data:&PhysicsData)->Trajectory{
pub fn camera_trajectory(&self,data:&PhysicsData)->Trajectory<'static>{
let acceleration=self.acceleration(data);
Trajectory::new(
self.body.position+self.style.camera_offset,

View File

@@ -57,7 +57,7 @@ pub enum SessionPlaybackInstruction{
}
pub struct FrameState{
pub trajectory:physics::Trajectory,
pub trajectory:physics::Trajectory<'static>,
pub camera:physics::PhysicsCamera,
pub time:PhysicsTime,
}