|
|
|
|
@@ -130,7 +130,7 @@ struct WalkState{
|
|
|
|
|
impl WalkEnum{
|
|
|
|
|
//args going crazy
|
|
|
|
|
//(walk_enum,body.acceleration)=with_target_velocity();
|
|
|
|
|
fn with_target_velocity(touching:&TouchingState,body:&Body,style:&StyleModifiers,models:&Vec<ModelPhysics>,mut velocity:Planar64Vec3,normal:&Planar64Vec3)->(WalkEnum,Planar64Vec3){
|
|
|
|
|
fn with_target_velocity(touching:&TouchingState,body:&Body,style:&StyleModifiers,models:&PhysicsModels,mut velocity:Planar64Vec3,normal:&Planar64Vec3)->(WalkEnum,Planar64Vec3){
|
|
|
|
|
touching.constrain_velocity(models,&mut velocity);
|
|
|
|
|
let mut target_diff=velocity-body.velocity;
|
|
|
|
|
//remove normal component
|
|
|
|
|
@@ -156,14 +156,14 @@ impl WalkEnum{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
impl WalkState{
|
|
|
|
|
fn ground(touching:&TouchingState,body:&Body,style:&StyleModifiers,models:&Vec<ModelPhysics>,mut velocity:Planar64Vec3)->(Self,Planar64Vec3){
|
|
|
|
|
fn ground(touching:&TouchingState,body:&Body,style:&StyleModifiers,models:&PhysicsModels,velocity:Planar64Vec3)->(Self,Planar64Vec3){
|
|
|
|
|
let (walk_enum,a)=WalkEnum::with_target_velocity(touching,body,style,models,velocity,&Planar64Vec3::Y);
|
|
|
|
|
(Self{
|
|
|
|
|
state:walk_enum,
|
|
|
|
|
normal:Planar64Vec3::Y,
|
|
|
|
|
},a)
|
|
|
|
|
}
|
|
|
|
|
fn ladder(touching:&TouchingState,body:&Body,style:&StyleModifiers,models:&Vec<ModelPhysics>,mut velocity:Planar64Vec3,normal:&Planar64Vec3)->(Self,Planar64Vec3){
|
|
|
|
|
fn ladder(touching:&TouchingState,body:&Body,style:&StyleModifiers,models:&PhysicsModels,velocity:Planar64Vec3,normal:&Planar64Vec3)->(Self,Planar64Vec3){
|
|
|
|
|
let (walk_enum,a)=WalkEnum::with_target_velocity(touching,body,style,models,velocity,normal);
|
|
|
|
|
(Self{
|
|
|
|
|
state:walk_enum,
|
|
|
|
|
@@ -172,7 +172,62 @@ impl WalkState{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct Modes{
|
|
|
|
|
modes:Vec<crate::model::ModeDescription>,
|
|
|
|
|
mode_from_mode_id:std::collections::HashMap::<u32,usize>,
|
|
|
|
|
}
|
|
|
|
|
impl Modes{
|
|
|
|
|
fn clear(&mut self){
|
|
|
|
|
self.modes.clear();
|
|
|
|
|
self.mode_from_mode_id.clear();
|
|
|
|
|
}
|
|
|
|
|
fn get_mode(&self,mode_id:u32)->Option<&crate::model::ModeDescription>{
|
|
|
|
|
self.modes.get(*self.mode_from_mode_id.get(&mode_id)?)
|
|
|
|
|
}
|
|
|
|
|
fn insert(&mut self,temp_map_mode_id:u32,mode:crate::model::ModeDescription){
|
|
|
|
|
let mode_id=self.modes.len();
|
|
|
|
|
self.mode_from_mode_id.insert(temp_map_mode_id,mode_id);
|
|
|
|
|
self.modes.push(mode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
impl Default for Modes{
|
|
|
|
|
fn default() -> Self {
|
|
|
|
|
Self{
|
|
|
|
|
modes:Vec::new(),
|
|
|
|
|
mode_from_mode_id:std::collections::HashMap::new(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct PhysicsModels{
|
|
|
|
|
models:Vec<ModelPhysics>,
|
|
|
|
|
model_id_from_wormhole_id:std::collections::HashMap::<u32,usize>,
|
|
|
|
|
}
|
|
|
|
|
impl PhysicsModels{
|
|
|
|
|
fn clear(&mut self){
|
|
|
|
|
self.models.clear();
|
|
|
|
|
self.model_id_from_wormhole_id.clear();
|
|
|
|
|
}
|
|
|
|
|
fn get(&self,i:usize)->Option<&ModelPhysics>{
|
|
|
|
|
self.models.get(i)
|
|
|
|
|
}
|
|
|
|
|
fn get_wormhole_model(&self,wormhole_id:u32)->Option<&ModelPhysics>{
|
|
|
|
|
self.models.get(*self.model_id_from_wormhole_id.get(&wormhole_id)?)
|
|
|
|
|
}
|
|
|
|
|
fn push(&mut self,model:ModelPhysics)->usize{
|
|
|
|
|
let model_id=self.models.len();
|
|
|
|
|
self.models.push(model);
|
|
|
|
|
model_id
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
impl Default for PhysicsModels{
|
|
|
|
|
fn default() -> Self {
|
|
|
|
|
Self{
|
|
|
|
|
models:Vec::new(),
|
|
|
|
|
model_id_from_wormhole_id:std::collections::HashMap::new(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
|
pub struct PhysicsCamera {
|
|
|
|
|
@@ -512,11 +567,10 @@ pub struct PhysicsState{
|
|
|
|
|
controls:u32,
|
|
|
|
|
move_state:MoveState,
|
|
|
|
|
//all models
|
|
|
|
|
models:Vec<ModelPhysics>,
|
|
|
|
|
models:PhysicsModels,
|
|
|
|
|
bvh:crate::bvh::BvhNode,
|
|
|
|
|
|
|
|
|
|
modes:Vec<crate::model::ModeDescription>,
|
|
|
|
|
mode_from_mode_id:std::collections::HashMap::<u32,usize>,
|
|
|
|
|
modes:Modes,
|
|
|
|
|
//the spawn point is where you spawn when you load into the map.
|
|
|
|
|
//This is not the same as Reset which teleports you to Spawn0
|
|
|
|
|
pub spawn_point:Planar64Vec3,
|
|
|
|
|
@@ -592,44 +646,44 @@ impl ModelPhysics {
|
|
|
|
|
//OR have a separate list from contacts for model intersection
|
|
|
|
|
#[derive(Debug,Clone,Eq,Hash,PartialEq)]
|
|
|
|
|
pub struct RelativeCollision {
|
|
|
|
|
face: TreyMeshFace,//just an id
|
|
|
|
|
model: u32,//using id to avoid lifetimes
|
|
|
|
|
face:TreyMeshFace,//just an id
|
|
|
|
|
model:usize,//using id to avoid lifetimes
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl RelativeCollision {
|
|
|
|
|
pub fn model<'a>(&self,models:&'a Vec<ModelPhysics>)->Option<&'a ModelPhysics>{
|
|
|
|
|
models.get(self.model as usize)
|
|
|
|
|
fn model<'a>(&self,models:&'a PhysicsModels)->Option<&'a ModelPhysics>{
|
|
|
|
|
models.get(self.model)
|
|
|
|
|
}
|
|
|
|
|
// pub fn mesh(&self,models:&Vec<ModelPhysics>) -> TreyMesh {
|
|
|
|
|
// return self.model(models).unwrap().face_mesh(self.face).clone()
|
|
|
|
|
// }
|
|
|
|
|
pub fn normal(&self,models:&Vec<ModelPhysics>) -> Planar64Vec3 {
|
|
|
|
|
fn normal(&self,models:&PhysicsModels) -> Planar64Vec3 {
|
|
|
|
|
return self.model(models).unwrap().face_normal(self.face)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct TouchingState{
|
|
|
|
|
contacts:std::collections::HashMap::<u32,RelativeCollision>,
|
|
|
|
|
intersects:std::collections::HashMap::<u32,RelativeCollision>,
|
|
|
|
|
contacts:std::collections::HashMap::<usize,RelativeCollision>,
|
|
|
|
|
intersects:std::collections::HashMap::<usize,RelativeCollision>,
|
|
|
|
|
}
|
|
|
|
|
impl TouchingState{
|
|
|
|
|
fn clear(&mut self){
|
|
|
|
|
self.contacts.clear();
|
|
|
|
|
self.intersects.clear();
|
|
|
|
|
}
|
|
|
|
|
fn insert_contact(&mut self,model_id:u32,collision:RelativeCollision)->Option<RelativeCollision>{
|
|
|
|
|
fn insert_contact(&mut self,model_id:usize,collision:RelativeCollision)->Option<RelativeCollision>{
|
|
|
|
|
self.contacts.insert(model_id,collision)
|
|
|
|
|
}
|
|
|
|
|
fn remove_contact(&mut self,model_id:u32)->Option<RelativeCollision>{
|
|
|
|
|
fn remove_contact(&mut self,model_id:usize)->Option<RelativeCollision>{
|
|
|
|
|
self.contacts.remove(&model_id)
|
|
|
|
|
}
|
|
|
|
|
fn insert_intersect(&mut self,model_id:u32,collision:RelativeCollision)->Option<RelativeCollision>{
|
|
|
|
|
fn insert_intersect(&mut self,model_id:usize,collision:RelativeCollision)->Option<RelativeCollision>{
|
|
|
|
|
self.intersects.insert(model_id,collision)
|
|
|
|
|
}
|
|
|
|
|
fn remove_intersect(&mut self,model_id:u32)->Option<RelativeCollision>{
|
|
|
|
|
fn remove_intersect(&mut self,model_id:usize)->Option<RelativeCollision>{
|
|
|
|
|
self.intersects.remove(&model_id)
|
|
|
|
|
}
|
|
|
|
|
fn constrain_velocity(&self,models:&Vec<ModelPhysics>,velocity:&mut Planar64Vec3){
|
|
|
|
|
fn constrain_velocity(&self,models:&PhysicsModels,velocity:&mut Planar64Vec3){
|
|
|
|
|
for (_,contact) in &self.contacts {
|
|
|
|
|
let n=contact.normal(models);
|
|
|
|
|
let d=velocity.dot(n);
|
|
|
|
|
@@ -638,7 +692,7 @@ impl TouchingState{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fn constrain_acceleration(&self,models:&Vec<ModelPhysics>,acceleration:&mut Planar64Vec3){
|
|
|
|
|
fn constrain_acceleration(&self,models:&PhysicsModels,acceleration:&mut Planar64Vec3){
|
|
|
|
|
for (_,contact) in &self.contacts {
|
|
|
|
|
let n=contact.normal(models);
|
|
|
|
|
let d=acceleration.dot(n);
|
|
|
|
|
@@ -694,7 +748,7 @@ impl Default for PhysicsState{
|
|
|
|
|
time: Time::ZERO,
|
|
|
|
|
style:StyleModifiers::default(),
|
|
|
|
|
touching:TouchingState::default(),
|
|
|
|
|
models: Vec::new(),
|
|
|
|
|
models:PhysicsModels::default(),
|
|
|
|
|
bvh:crate::bvh::BvhNode::default(),
|
|
|
|
|
move_state: MoveState::Air,
|
|
|
|
|
camera: PhysicsCamera::from_offset(Planar64Vec3::int(0,2,0)),//4.5-2.5=2
|
|
|
|
|
@@ -702,8 +756,7 @@ impl Default for PhysicsState{
|
|
|
|
|
controls: 0,
|
|
|
|
|
world:WorldState{},
|
|
|
|
|
game:GameMechanicsState::default(),
|
|
|
|
|
modes:Vec::new(),
|
|
|
|
|
mode_from_mode_id:std::collections::HashMap::new(),
|
|
|
|
|
modes:Modes::default(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -818,81 +871,70 @@ impl PhysicsState {
|
|
|
|
|
//make aabb and run vertices to get realistic bounds
|
|
|
|
|
for model_instance in &model.instances{
|
|
|
|
|
if let Some(model_physics)=ModelPhysics::from_model(model,model_instance){
|
|
|
|
|
let model_id=self.models.len() as u32;
|
|
|
|
|
self.models.push(model_physics);
|
|
|
|
|
let model_id=self.models.push(model_physics);
|
|
|
|
|
for attr in &model_instance.temp_indexing{
|
|
|
|
|
match attr{
|
|
|
|
|
crate::model::TempIndexedAttributes::Start{mode_id}=>starts.push((*mode_id,model_id)),
|
|
|
|
|
crate::model::TempIndexedAttributes::Spawn{mode_id,stage_id}=>spawns.push((*mode_id,model_id,*stage_id)),
|
|
|
|
|
crate::model::TempIndexedAttributes::OrderedCheckpoint{mode_id,checkpoint_id}=>ordered_checkpoints.push((*mode_id,model_id,*checkpoint_id)),
|
|
|
|
|
crate::model::TempIndexedAttributes::UnorderedCheckpoint{mode_id}=>unordered_checkpoints.push((*mode_id,model_id)),
|
|
|
|
|
crate::model::TempIndexedAttributes::Start(s)=>starts.push((model_id,s.clone())),
|
|
|
|
|
crate::model::TempIndexedAttributes::Spawn(s)=>spawns.push((model_id,s.clone())),
|
|
|
|
|
crate::model::TempIndexedAttributes::OrderedCheckpoint(s)=>ordered_checkpoints.push((model_id,s.clone())),
|
|
|
|
|
crate::model::TempIndexedAttributes::UnorderedCheckpoint(s)=>unordered_checkpoints.push((model_id,s.clone())),
|
|
|
|
|
crate::model::TempIndexedAttributes::Wormhole(s)=>{self.models.model_id_from_wormhole_id.insert(s.wormhole_id,model_id);},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
self.bvh=crate::bvh::generate_bvh(self.models.iter().map(|m|m.mesh().clone()).collect());
|
|
|
|
|
self.bvh=crate::bvh::generate_bvh(self.models.models.iter().map(|m|m.mesh().clone()).collect());
|
|
|
|
|
//I don't wanna write structs for temporary structures
|
|
|
|
|
//this code builds ModeDescriptions from the unsorted lists at the top of the function
|
|
|
|
|
starts.sort_by_key(|tup|tup.0);
|
|
|
|
|
let mut eshmep=std::collections::HashMap::new();
|
|
|
|
|
let mut modedatas:Vec<(u32,Vec<(u32,u32)>,Vec<(u32,u32)>,Vec<u32>)>=starts.into_iter().enumerate().map(|(i,tup)|{
|
|
|
|
|
eshmep.insert(tup.0,i);
|
|
|
|
|
(tup.1,Vec::new(),Vec::new(),Vec::new())
|
|
|
|
|
starts.sort_by_key(|tup|tup.1.mode_id);
|
|
|
|
|
let mut mode_id_from_map_mode_id=std::collections::HashMap::new();
|
|
|
|
|
let mut modedatas:Vec<(usize,Vec<(u32,usize)>,Vec<(u32,usize)>,Vec<usize>,u32)>=starts.into_iter().enumerate().map(|(i,(model_id,s))|{
|
|
|
|
|
mode_id_from_map_mode_id.insert(s.mode_id,i);
|
|
|
|
|
(model_id,Vec::new(),Vec::new(),Vec::new(),s.mode_id)
|
|
|
|
|
}).collect();
|
|
|
|
|
for tup in spawns{
|
|
|
|
|
if let Some(mode_id)=eshmep.get(&tup.0){
|
|
|
|
|
for (model_id,s) in spawns{
|
|
|
|
|
if let Some(mode_id)=mode_id_from_map_mode_id.get(&s.mode_id){
|
|
|
|
|
if let Some(modedata)=modedatas.get_mut(*mode_id){
|
|
|
|
|
modedata.1.push((tup.2,tup.1));
|
|
|
|
|
modedata.1.push((s.stage_id,model_id));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for tup in ordered_checkpoints{
|
|
|
|
|
if let Some(mode_id)=eshmep.get(&tup.0){
|
|
|
|
|
for (model_id,s) in ordered_checkpoints{
|
|
|
|
|
if let Some(mode_id)=mode_id_from_map_mode_id.get(&s.mode_id){
|
|
|
|
|
if let Some(modedata)=modedatas.get_mut(*mode_id){
|
|
|
|
|
modedata.2.push((tup.2,tup.1));
|
|
|
|
|
modedata.2.push((s.checkpoint_id,model_id));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for tup in unordered_checkpoints{
|
|
|
|
|
if let Some(mode_id)=eshmep.get(&tup.0){
|
|
|
|
|
for (model_id,s) in unordered_checkpoints{
|
|
|
|
|
if let Some(mode_id)=mode_id_from_map_mode_id.get(&s.mode_id){
|
|
|
|
|
if let Some(modedata)=modedatas.get_mut(*mode_id){
|
|
|
|
|
modedata.3.push(tup.1);
|
|
|
|
|
modedata.3.push(model_id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
let num_modes=self.modes.len();
|
|
|
|
|
for (mode_id,mode) in eshmep{
|
|
|
|
|
self.mode_from_mode_id.insert(mode_id,num_modes+mode);
|
|
|
|
|
}
|
|
|
|
|
self.modes.append(&mut modedatas.into_iter().map(|mut tup|{
|
|
|
|
|
for mut tup in modedatas.into_iter(){
|
|
|
|
|
tup.1.sort_by_key(|tup|tup.0);
|
|
|
|
|
tup.2.sort_by_key(|tup|tup.0);
|
|
|
|
|
let mut eshmep1=std::collections::HashMap::new();
|
|
|
|
|
let mut eshmep2=std::collections::HashMap::new();
|
|
|
|
|
crate::model::ModeDescription{
|
|
|
|
|
self.modes.insert(tup.4,crate::model::ModeDescription{
|
|
|
|
|
start:tup.0,
|
|
|
|
|
spawns:tup.1.into_iter().enumerate().map(|(i,tup)|{eshmep1.insert(tup.0,i);tup.1}).collect(),
|
|
|
|
|
ordered_checkpoints:tup.2.into_iter().enumerate().map(|(i,tup)|{eshmep2.insert(tup.0,i);tup.1}).collect(),
|
|
|
|
|
unordered_checkpoints:tup.3,
|
|
|
|
|
spawn_from_stage_id:eshmep1,
|
|
|
|
|
ordered_checkpoint_from_checkpoint_id:eshmep2,
|
|
|
|
|
}
|
|
|
|
|
}).collect());
|
|
|
|
|
println!("Physics Objects: {}",self.models.len());
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
println!("Physics Objects: {}",self.models.models.len());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn load_user_settings(&mut self,user_settings:&crate::settings::UserSettings){
|
|
|
|
|
self.camera.sensitivity=user_settings.calculate_sensitivity();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn get_mode(&self,mode_id:u32)->Option<&crate::model::ModeDescription>{
|
|
|
|
|
if let Some(&mode)=self.mode_from_mode_id.get(&mode_id){
|
|
|
|
|
self.modes.get(mode)
|
|
|
|
|
}else{
|
|
|
|
|
None
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//tickless gaming
|
|
|
|
|
pub fn run(&mut self, time_limit:Time){
|
|
|
|
|
//prepare is ommitted - everything is done via instructions.
|
|
|
|
|
@@ -924,7 +966,7 @@ impl PhysicsState {
|
|
|
|
|
|
|
|
|
|
fn next_strafe_instruction(&self) -> Option<TimedInstruction<PhysicsInstruction>> {
|
|
|
|
|
return Some(TimedInstruction{
|
|
|
|
|
time:Time::from_nanos(self.style.strafe_tick_rate.rhs_div_int(self.style.strafe_tick_rate.mul_int(self.time.nanos()+1)+1)),
|
|
|
|
|
time:Time::from_nanos(self.style.strafe_tick_rate.rhs_div_int(self.style.strafe_tick_rate.mul_int(self.time.nanos())+1)),
|
|
|
|
|
//only poll the physics if there is a before and after mouse event
|
|
|
|
|
instruction:PhysicsInstruction::StrafeTick
|
|
|
|
|
});
|
|
|
|
|
@@ -1149,9 +1191,9 @@ impl PhysicsState {
|
|
|
|
|
}
|
|
|
|
|
None
|
|
|
|
|
}
|
|
|
|
|
fn predict_collision_start(&self,time:Time,time_limit:Time,model_id:u32) -> Option<TimedInstruction<PhysicsInstruction>> {
|
|
|
|
|
fn predict_collision_start(&self,time:Time,time_limit:Time,model_id:usize) -> Option<TimedInstruction<PhysicsInstruction>> {
|
|
|
|
|
let mesh0=self.mesh();
|
|
|
|
|
let mesh1=self.models.get(model_id as usize).unwrap().mesh();
|
|
|
|
|
let mesh1=self.models.get(model_id).unwrap().mesh();
|
|
|
|
|
let (p,v,a,body_time)=(self.body.position,self.body.velocity,self.body.acceleration,self.body.time);
|
|
|
|
|
//find best t
|
|
|
|
|
let mut best_time=time_limit;
|
|
|
|
|
@@ -1256,12 +1298,12 @@ impl PhysicsState {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//generate instruction
|
|
|
|
|
if let Some(face) = best_face{
|
|
|
|
|
return Some(TimedInstruction {
|
|
|
|
|
if let Some(face)=best_face{
|
|
|
|
|
return Some(TimedInstruction{
|
|
|
|
|
time: best_time,
|
|
|
|
|
instruction: PhysicsInstruction::CollisionStart(RelativeCollision {
|
|
|
|
|
instruction:PhysicsInstruction::CollisionStart(RelativeCollision{
|
|
|
|
|
face,
|
|
|
|
|
model: model_id
|
|
|
|
|
model:model_id
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
@@ -1296,6 +1338,46 @@ impl crate::instruction::InstructionEmitter<PhysicsInstruction> for PhysicsState
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn teleport(body:&mut Body,touching:&mut TouchingState,style:&StyleModifiers,point:Planar64Vec3)->MoveState{
|
|
|
|
|
body.position=point;
|
|
|
|
|
//manual clear //for c in contacts{process_instruction(CollisionEnd(c))}
|
|
|
|
|
touching.clear();
|
|
|
|
|
body.acceleration=style.gravity;
|
|
|
|
|
MoveState::Air
|
|
|
|
|
//TODO: calculate contacts and determine the actual state
|
|
|
|
|
//touching.recalculate(body);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn run_teleport_behaviour(teleport_behaviour:&Option<crate::model::TeleportBehaviour>,game:&mut GameMechanicsState,models:&PhysicsModels,modes:&Modes,style:&StyleModifiers,touching:&mut TouchingState,body:&mut Body,model:&ModelPhysics)->Option<MoveState>{
|
|
|
|
|
match teleport_behaviour{
|
|
|
|
|
Some(crate::model::TeleportBehaviour::StageElement(stage_element))=>{
|
|
|
|
|
if stage_element.force||game.stage_id<stage_element.stage_id{
|
|
|
|
|
game.stage_id=stage_element.stage_id;
|
|
|
|
|
}
|
|
|
|
|
match &stage_element.behaviour{
|
|
|
|
|
crate::model::StageElementBehaviour::SpawnAt=>None,
|
|
|
|
|
crate::model::StageElementBehaviour::Trigger
|
|
|
|
|
|crate::model::StageElementBehaviour::Teleport=>{
|
|
|
|
|
//I guess this is correct behaviour when trying to teleport to a non-existent spawn but it's still weird
|
|
|
|
|
let model=models.get(*modes.get_mode(stage_element.mode_id)?.get_spawn_model_id(game.stage_id)? as usize)?;
|
|
|
|
|
let point=model.transform.transform_point3(Planar64Vec3::Y)+Planar64Vec3::Y*(style.hitbox_halfsize.y()+Planar64::ONE/16);
|
|
|
|
|
Some(teleport(body,touching,style,point))
|
|
|
|
|
},
|
|
|
|
|
crate::model::StageElementBehaviour::Platform=>None,
|
|
|
|
|
crate::model::StageElementBehaviour::JumpLimit(_)=>None,//TODO
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
Some(crate::model::TeleportBehaviour::Wormhole(wormhole))=>{
|
|
|
|
|
//telefart
|
|
|
|
|
let origin_model=model;
|
|
|
|
|
let destination_model=models.get_wormhole_model(wormhole.destination_model_id)?;
|
|
|
|
|
//ignore the transform for now
|
|
|
|
|
Some(teleport(body,touching,style,body.position-origin_model.transform.translation+destination_model.transform.translation))
|
|
|
|
|
}
|
|
|
|
|
None=>None,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl crate::instruction::InstructionConsumer<PhysicsInstruction> for PhysicsState {
|
|
|
|
|
fn process_instruction(&mut self, ins:TimedInstruction<PhysicsInstruction>) {
|
|
|
|
|
match &ins.instruction {
|
|
|
|
|
@@ -1349,37 +1431,8 @@ impl crate::instruction::InstructionConsumer<PhysicsInstruction> for PhysicsStat
|
|
|
|
|
}
|
|
|
|
|
//check ground
|
|
|
|
|
self.touching.insert_contact(c.model,c);
|
|
|
|
|
match &general.teleport_behaviour{
|
|
|
|
|
Some(crate::model::TeleportBehaviour::StageElement(stage_element))=>{
|
|
|
|
|
if stage_element.force||self.game.stage_id<stage_element.stage_id{
|
|
|
|
|
self.game.stage_id=stage_element.stage_id;
|
|
|
|
|
}
|
|
|
|
|
match &stage_element.behaviour{
|
|
|
|
|
crate::model::StageElementBehaviour::SpawnAt=>(),
|
|
|
|
|
crate::model::StageElementBehaviour::Trigger
|
|
|
|
|
|crate::model::StageElementBehaviour::Teleport=>{
|
|
|
|
|
//TODO make good
|
|
|
|
|
if let Some(mode)=self.get_mode(stage_element.mode_id){
|
|
|
|
|
if let Some(&spawn)=mode.get_spawn_model_id(self.game.stage_id){
|
|
|
|
|
if let Some(model)=self.models.get(spawn as usize){
|
|
|
|
|
self.body.position=model.transform.transform_point3(Planar64Vec3::Y)+Planar64Vec3::Y*(self.style.hitbox_halfsize.y()+Planar64::ONE/16);
|
|
|
|
|
//manual clear //for c in self.contacts{process_instruction(CollisionEnd(c))}
|
|
|
|
|
self.touching.clear();
|
|
|
|
|
self.body.acceleration=self.style.gravity;
|
|
|
|
|
self.move_state=MoveState::Air;//TODO: calculate contacts and determine the actual state
|
|
|
|
|
}else{println!("bad1");}
|
|
|
|
|
}else{println!("bad2");}
|
|
|
|
|
}else{println!("bad3");}
|
|
|
|
|
},
|
|
|
|
|
crate::model::StageElementBehaviour::Platform=>(),
|
|
|
|
|
crate::model::StageElementBehaviour::JumpLimit(_)=>(),//TODO
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
Some(crate::model::TeleportBehaviour::Wormhole(wormhole))=>{
|
|
|
|
|
//telefart
|
|
|
|
|
}
|
|
|
|
|
None=>(),
|
|
|
|
|
}
|
|
|
|
|
//I love making functions with 10 arguments to dodge the borrow checker
|
|
|
|
|
run_teleport_behaviour(&general.teleport_behaviour,&mut self.game,&self.models,&self.modes,&self.style,&mut self.touching,&mut self.body,model);
|
|
|
|
|
//flatten v
|
|
|
|
|
self.touching.constrain_velocity(&self.models,&mut v);
|
|
|
|
|
match &general.booster{
|
|
|
|
|
@@ -1395,25 +1448,13 @@ impl crate::instruction::InstructionConsumer<PhysicsInstruction> for PhysicsStat
|
|
|
|
|
}
|
|
|
|
|
match &general.trajectory{
|
|
|
|
|
Some(trajectory)=>{
|
|
|
|
|
println!("??? {:?}",trajectory);
|
|
|
|
|
match trajectory{
|
|
|
|
|
&crate::model::GameMechanicSetTrajectory::Height(height)=>{
|
|
|
|
|
//vg=sqrt(-2*gg*height)
|
|
|
|
|
println!("height booster h={}",height);
|
|
|
|
|
let vg=v.dot(self.style.gravity);
|
|
|
|
|
let gg=self.style.gravity.dot(self.style.gravity);
|
|
|
|
|
let hb=(gg.sqrt()*height*2).sqrt()*gg.sqrt();
|
|
|
|
|
println!("hb={} vg={}",hb,vg);
|
|
|
|
|
let b=self.style.gravity*((-hb-vg)/gg);
|
|
|
|
|
println!("bopo {}",b);
|
|
|
|
|
v+=b;
|
|
|
|
|
},
|
|
|
|
|
crate::model::GameMechanicSetTrajectory::AirTime(_) => todo!(),
|
|
|
|
|
crate::model::GameMechanicSetTrajectory::Height(_) => todo!(),
|
|
|
|
|
crate::model::GameMechanicSetTrajectory::TargetPointTime { target_point, time } => todo!(),
|
|
|
|
|
crate::model::GameMechanicSetTrajectory::TrajectoryTargetPoint { target_point, speed, trajectory_choice } => todo!(),
|
|
|
|
|
&crate::model::GameMechanicSetTrajectory::Velocity(velocity)=>v=velocity,
|
|
|
|
|
crate::model::GameMechanicSetTrajectory::AirTime(_)
|
|
|
|
|
|crate::model::GameMechanicSetTrajectory::TargetPointTime{target_point:_,time:_}
|
|
|
|
|
|crate::model::GameMechanicSetTrajectory::TrajectoryTargetPoint{target_point:_,speed:_,trajectory_choice:_}
|
|
|
|
|
|crate::model::GameMechanicSetTrajectory::DotVelocity{direction:_,dot:_}
|
|
|
|
|
=>(),
|
|
|
|
|
crate::model::GameMechanicSetTrajectory::DotVelocity { direction, dot } => todo!(),
|
|
|
|
|
}
|
|
|
|
|
self.touching.constrain_velocity(&self.models,&mut v);
|
|
|
|
|
},
|
|
|
|
|
@@ -1428,37 +1469,7 @@ impl crate::instruction::InstructionConsumer<PhysicsInstruction> for PhysicsStat
|
|
|
|
|
PhysicsCollisionAttributes::Intersect{intersecting,general}=>{
|
|
|
|
|
//I think that setting the velocity to 0 was preventing surface contacts from entering an infinite loop
|
|
|
|
|
self.touching.insert_intersect(c.model,c);
|
|
|
|
|
match &general.teleport_behaviour{
|
|
|
|
|
Some(crate::model::TeleportBehaviour::StageElement(stage_element))=>{
|
|
|
|
|
if stage_element.force||self.game.stage_id<stage_element.stage_id{
|
|
|
|
|
self.game.stage_id=stage_element.stage_id;
|
|
|
|
|
}
|
|
|
|
|
match &stage_element.behaviour{
|
|
|
|
|
crate::model::StageElementBehaviour::SpawnAt=>(),
|
|
|
|
|
crate::model::StageElementBehaviour::Trigger
|
|
|
|
|
|crate::model::StageElementBehaviour::Teleport=>{
|
|
|
|
|
//TODO make good
|
|
|
|
|
if let Some(mode)=self.get_mode(stage_element.mode_id){
|
|
|
|
|
if let Some(&spawn)=mode.get_spawn_model_id(self.game.stage_id){
|
|
|
|
|
if let Some(model)=self.models.get(spawn as usize){
|
|
|
|
|
self.body.position=model.transform.transform_point3(Planar64Vec3::Y)+Planar64Vec3::Y*(self.style.hitbox_halfsize.y()+Planar64::ONE/16);
|
|
|
|
|
//manual clear //for c in self.contacts{process_instruction(CollisionEnd(c))}
|
|
|
|
|
self.touching.clear();
|
|
|
|
|
self.body.acceleration=self.style.gravity;
|
|
|
|
|
self.move_state=MoveState::Air;//TODO: calculate contacts and determine the actual state
|
|
|
|
|
}else{println!("bad1");}
|
|
|
|
|
}else{println!("bad2");}
|
|
|
|
|
}else{println!("bad3");}
|
|
|
|
|
},
|
|
|
|
|
crate::model::StageElementBehaviour::Platform=>(),
|
|
|
|
|
crate::model::StageElementBehaviour::JumpLimit(_)=>(),//TODO
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
Some(crate::model::TeleportBehaviour::Wormhole(wormhole))=>{
|
|
|
|
|
//telefart
|
|
|
|
|
}
|
|
|
|
|
None=>(),
|
|
|
|
|
}
|
|
|
|
|
run_teleport_behaviour(&general.teleport_behaviour,&mut self.game,&self.models,&self.modes,&self.style,&mut self.touching,&mut self.body,model);
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|