forked from StrafesNET/strafe-client
v3
This commit is contained in:
parent
b91d760eb7
commit
6662410037
82
src/body.rs
82
src/body.rs
@ -261,29 +261,20 @@ pub struct GameMechanicsState{
|
|||||||
pub spawn_id:u32,
|
pub spawn_id:u32,
|
||||||
//jump_counts:HashMap<u32,u32>,
|
//jump_counts:HashMap<u32,u32>,
|
||||||
}
|
}
|
||||||
|
impl std::default::Default for GameMechanicsState{
|
||||||
pub struct StageDescription{
|
fn default() -> Self {
|
||||||
pub start:u32,//start=model_id
|
Self{
|
||||||
pub spawns:Vec<u32>,//spawns[spawn_id]=model_id
|
spawn_id:0,
|
||||||
pub ordered_checkpoints:Vec<u32>,//ordered_checkpoints[checkpoint_id]=model_id
|
}
|
||||||
pub unordered_checkpoints:Vec<u32>,//unordered_checkpoints[checkpoint_id]=model_id
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct WorldState{
|
pub struct WorldState{}
|
||||||
//all models
|
|
||||||
pub models:Vec<ModelPhysics>,
|
|
||||||
|
|
||||||
pub stages:Vec<StageDescription>,
|
|
||||||
//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:glam::Vec3,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct StyleModifiers{
|
pub struct StyleModifiers{
|
||||||
pub keys_mask:u32,//keys which are unable to be activated
|
pub constrols_mask:u32,//constrols which are unable to be activated
|
||||||
pub keys_held:u32,//keys which must be active to be able to strafe
|
pub constrols_held:u32,//constrols which must be active to be able to strafe
|
||||||
pub mv:f32,
|
pub mv:f32,
|
||||||
pub walk:WalkState,
|
|
||||||
pub walkspeed:f32,
|
pub walkspeed:f32,
|
||||||
pub friction:f32,
|
pub friction:f32,
|
||||||
pub walk_accel:f32,
|
pub walk_accel:f32,
|
||||||
@ -292,11 +283,27 @@ pub struct StyleModifiers{
|
|||||||
pub strafe_tick_den:TIME,
|
pub strafe_tick_den:TIME,
|
||||||
pub hitbox_halfsize:glam::Vec3,
|
pub hitbox_halfsize:glam::Vec3,
|
||||||
}
|
}
|
||||||
|
impl std::default::Default for StyleModifiers{
|
||||||
|
fn default() -> Self {
|
||||||
|
Self{
|
||||||
|
constrols_mask: !0&!(CONTROL_MOVEUP|CONTROL_MOVEDOWN),
|
||||||
|
constrols_held: 0,
|
||||||
|
strafe_tick_num: 100,//100t
|
||||||
|
strafe_tick_den: 1_000_000_000,
|
||||||
|
gravity: glam::vec3(0.0,-100.0,0.0),
|
||||||
|
friction: 1.2,
|
||||||
|
walk_accel: 90.0,
|
||||||
|
mv: 2.7,
|
||||||
|
walkspeed: 18.0,
|
||||||
|
hitbox_halfsize: glam::vec3(1.0,2.5,1.0),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct PhysicsState{
|
pub struct PhysicsState{
|
||||||
pub time:TIME,
|
pub time:TIME,
|
||||||
pub body:Body,
|
pub body:Body,
|
||||||
pub world:WorldState,
|
pub world:WorldState,//currently there is only one state the world can be in
|
||||||
pub game:GameMechanicsState,
|
pub game:GameMechanicsState,
|
||||||
pub style:StyleModifiers,
|
pub style:StyleModifiers,
|
||||||
pub contacts:std::collections::HashSet::<RelativeCollision>,
|
pub contacts:std::collections::HashSet::<RelativeCollision>,
|
||||||
@ -305,7 +312,15 @@ pub struct PhysicsState{
|
|||||||
pub camera:Camera,
|
pub camera:Camera,
|
||||||
pub mouse_interpolation:MouseInterpolationState,
|
pub mouse_interpolation:MouseInterpolationState,
|
||||||
pub controls:u32,
|
pub controls:u32,
|
||||||
|
pub walk:WalkState,
|
||||||
pub grounded:bool,
|
pub grounded:bool,
|
||||||
|
//all models
|
||||||
|
pub models:Vec<ModelPhysics>,
|
||||||
|
|
||||||
|
pub stages:Vec<crate::model::StageDescription>,
|
||||||
|
//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:glam::Vec3,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug,Clone,Copy,Hash,Eq,PartialEq)]
|
#[derive(Debug,Clone,Copy,Hash,Eq,PartialEq)]
|
||||||
@ -417,11 +432,22 @@ impl Aabb {
|
|||||||
type TreyMeshFace = AabbFace;
|
type TreyMeshFace = AabbFace;
|
||||||
type TreyMesh = Aabb;
|
type TreyMesh = Aabb;
|
||||||
|
|
||||||
|
enum PhysicsCollisionAttributes{
|
||||||
|
Contact{//track whether you are contacting the object
|
||||||
|
contacting:crate::model::ContactingAttributes,
|
||||||
|
general:crate::model::GameMechanicAttributes,
|
||||||
|
},
|
||||||
|
Intersect{//track whether you are intersecting the object
|
||||||
|
intersecting:crate::model::IntersectingAttributes,
|
||||||
|
general:crate::model::GameMechanicAttributes,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
pub struct ModelPhysics {
|
pub struct ModelPhysics {
|
||||||
//A model is a thing that has a hitbox. can be represented by a list of TreyMesh-es
|
//A model is a thing that has a hitbox. can be represented by a list of TreyMesh-es
|
||||||
//in this iteration, all it needs is extents.
|
//in this iteration, all it needs is extents.
|
||||||
mesh: TreyMesh,
|
mesh: TreyMesh,
|
||||||
attributes:crate::model::CollisionAttributes,
|
attributes:PhysicsCollisionAttributes,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ModelPhysics {
|
impl ModelPhysics {
|
||||||
@ -550,7 +576,7 @@ impl PhysicsState {
|
|||||||
}
|
}
|
||||||
fn next_strafe_instruction(&self) -> Option<TimedInstruction<PhysicsInstruction>> {
|
fn next_strafe_instruction(&self) -> Option<TimedInstruction<PhysicsInstruction>> {
|
||||||
return Some(TimedInstruction{
|
return Some(TimedInstruction{
|
||||||
time:(self.time*self.strafe_tick_num/self.strafe_tick_den+1)*self.strafe_tick_den/self.strafe_tick_num,
|
time:(self.time*self.style.strafe_tick_num/self.style.strafe_tick_den+1)*self.style.strafe_tick_den/self.style.strafe_tick_num,
|
||||||
//only poll the physics if there is a before and after mouse event
|
//only poll the physics if there is a before and after mouse event
|
||||||
instruction:PhysicsInstruction::StrafeTick
|
instruction:PhysicsInstruction::StrafeTick
|
||||||
});
|
});
|
||||||
@ -600,7 +626,7 @@ impl PhysicsState {
|
|||||||
self.body.acceleration=a;
|
self.body.acceleration=a;
|
||||||
self.walk.state=WalkEnum::Reached;
|
self.walk.state=WalkEnum::Reached;
|
||||||
}else{
|
}else{
|
||||||
let accel=self.walk_accel.min(self.gravity.length()*self.friction);
|
let accel=self.style.walk_accel.min(self.style.gravity.length()*self.style.friction);
|
||||||
let time_delta=target_diff.length()/accel;
|
let time_delta=target_diff.length()/accel;
|
||||||
let mut a=target_diff/time_delta;
|
let mut a=target_diff/time_delta;
|
||||||
self.contact_constrain_acceleration(&mut a);
|
self.contact_constrain_acceleration(&mut a);
|
||||||
@ -629,7 +655,7 @@ impl PhysicsState {
|
|||||||
fn mesh(&self) -> TreyMesh {
|
fn mesh(&self) -> TreyMesh {
|
||||||
let mut aabb=Aabb::new();
|
let mut aabb=Aabb::new();
|
||||||
for vertex in Aabb::unit_vertices(){
|
for vertex in Aabb::unit_vertices(){
|
||||||
aabb.grow(self.body.position+self.hitbox_halfsize*vertex);
|
aabb.grow(self.body.position+self.style.hitbox_halfsize*vertex);
|
||||||
}
|
}
|
||||||
aabb
|
aabb
|
||||||
}
|
}
|
||||||
@ -973,7 +999,7 @@ impl crate::instruction::InstructionConsumer<PhysicsInstruction> for PhysicsStat
|
|||||||
},
|
},
|
||||||
PhysicsInstruction::CollisionEnd(c) => {
|
PhysicsInstruction::CollisionEnd(c) => {
|
||||||
self.contacts.remove(&c);//remove contact before calling contact_constrain_acceleration
|
self.contacts.remove(&c);//remove contact before calling contact_constrain_acceleration
|
||||||
let mut a=self.gravity;
|
let mut a=self.style.gravity;
|
||||||
self.contact_constrain_acceleration(&mut a);
|
self.contact_constrain_acceleration(&mut a);
|
||||||
self.body.acceleration=a;
|
self.body.acceleration=a;
|
||||||
//check ground
|
//check ground
|
||||||
@ -989,8 +1015,8 @@ impl crate::instruction::InstructionConsumer<PhysicsInstruction> for PhysicsStat
|
|||||||
let camera_mat=self.camera.simulate_move_rotation_y(self.mouse_interpolation.interpolated_position(self.time).x-self.mouse_interpolation.mouse0.x);
|
let camera_mat=self.camera.simulate_move_rotation_y(self.mouse_interpolation.interpolated_position(self.time).x-self.mouse_interpolation.mouse0.x);
|
||||||
let control_dir=camera_mat*get_control_dir(self.controls);
|
let control_dir=camera_mat*get_control_dir(self.controls);
|
||||||
let d=self.body.velocity.dot(control_dir);
|
let d=self.body.velocity.dot(control_dir);
|
||||||
if d<self.mv {
|
if d<self.style.mv {
|
||||||
let mut v=self.body.velocity+(self.mv-d)*control_dir;
|
let mut v=self.body.velocity+(self.style.mv-d)*control_dir;
|
||||||
self.contact_constrain_velocity(&mut v);
|
self.contact_constrain_velocity(&mut v);
|
||||||
self.body.velocity=v;
|
self.body.velocity=v;
|
||||||
}
|
}
|
||||||
@ -1036,7 +1062,7 @@ impl crate::instruction::InstructionConsumer<PhysicsInstruction> for PhysicsStat
|
|||||||
self.body.velocity=glam::Vec3::ZERO;
|
self.body.velocity=glam::Vec3::ZERO;
|
||||||
//manual clear //for c in self.contacts{process_instruction(CollisionEnd(c))}
|
//manual clear //for c in self.contacts{process_instruction(CollisionEnd(c))}
|
||||||
self.contacts.clear();
|
self.contacts.clear();
|
||||||
self.body.acceleration=self.gravity;
|
self.body.acceleration=self.style.gravity;
|
||||||
self.walk.state=WalkEnum::Reached;
|
self.walk.state=WalkEnum::Reached;
|
||||||
self.grounded=false;
|
self.grounded=false;
|
||||||
refresh_walk_target=false;
|
refresh_walk_target=false;
|
||||||
@ -1048,7 +1074,7 @@ impl crate::instruction::InstructionConsumer<PhysicsInstruction> for PhysicsStat
|
|||||||
if refresh_walk_target_velocity{
|
if refresh_walk_target_velocity{
|
||||||
let camera_mat=self.camera.simulate_move_rotation_y(self.mouse_interpolation.interpolated_position(self.time).x-self.mouse_interpolation.mouse0.x);
|
let camera_mat=self.camera.simulate_move_rotation_y(self.mouse_interpolation.interpolated_position(self.time).x-self.mouse_interpolation.mouse0.x);
|
||||||
let control_dir=camera_mat*get_control_dir(self.controls);
|
let control_dir=camera_mat*get_control_dir(self.controls);
|
||||||
self.walk.target_velocity=self.walkspeed*control_dir;
|
self.walk.target_velocity=self.style.walkspeed*control_dir;
|
||||||
}
|
}
|
||||||
self.refresh_walk_target();
|
self.refresh_walk_target();
|
||||||
}
|
}
|
||||||
|
12
src/main.rs
12
src/main.rs
@ -503,22 +503,16 @@ impl framework::Example for GraphicsData {
|
|||||||
spawn_point:glam::vec3(0.0,50.0,0.0),
|
spawn_point:glam::vec3(0.0,50.0,0.0),
|
||||||
body: body::Body::with_pva(glam::vec3(0.0,50.0,0.0),glam::vec3(0.0,0.0,0.0),glam::vec3(0.0,-100.0,0.0)),
|
body: body::Body::with_pva(glam::vec3(0.0,50.0,0.0),glam::vec3(0.0,0.0,0.0),glam::vec3(0.0,-100.0,0.0)),
|
||||||
time: 0,
|
time: 0,
|
||||||
tick: 0,
|
style:body::StyleModifiers::default(),
|
||||||
strafe_tick_num: 100,//100t
|
|
||||||
strafe_tick_den: 1_000_000_000,
|
|
||||||
gravity: glam::vec3(0.0,-100.0,0.0),
|
|
||||||
friction: 1.2,
|
|
||||||
walk_accel: 90.0,
|
|
||||||
mv: 2.7,
|
|
||||||
grounded: false,
|
grounded: false,
|
||||||
walkspeed: 18.0,
|
|
||||||
contacts: std::collections::HashSet::new(),
|
contacts: std::collections::HashSet::new(),
|
||||||
models: Vec::new(),
|
models: Vec::new(),
|
||||||
walk: body::WalkState::new(),
|
walk: body::WalkState::new(),
|
||||||
hitbox_halfsize: glam::vec3(1.0,2.5,1.0),
|
|
||||||
camera: body::Camera::from_offset(glam::vec3(0.0,4.5-2.5,0.0),(config.width as f32)/(config.height as f32)),
|
camera: body::Camera::from_offset(glam::vec3(0.0,4.5-2.5,0.0),(config.width as f32)/(config.height as f32)),
|
||||||
mouse_interpolation: body::MouseInterpolationState::new(),
|
mouse_interpolation: body::MouseInterpolationState::new(),
|
||||||
controls: 0,
|
controls: 0,
|
||||||
|
world:body::WorldState{},
|
||||||
|
game:body::GameMechanicsState::default(),
|
||||||
};
|
};
|
||||||
|
|
||||||
//load textures
|
//load textures
|
||||||
|
109
src/model.rs
109
src/model.rs
@ -65,36 +65,52 @@ pub struct IndexedModelInstances{
|
|||||||
//object_index for spawns, triggers etc?
|
//object_index for spawns, triggers etc?
|
||||||
pub spawn_point:glam::Vec3,
|
pub spawn_point:glam::Vec3,
|
||||||
}
|
}
|
||||||
|
//stage description referencing flattened ids is spooky, but the map loading is meant to be deterministic.
|
||||||
|
pub struct StageDescription{
|
||||||
|
pub start:u32,//start=model_id
|
||||||
|
pub spawns:Vec<u32>,//spawns[spawn_id]=model_id
|
||||||
|
pub ordered_checkpoints:Vec<u32>,//ordered_checkpoints[checkpoint_id]=model_id
|
||||||
|
pub unordered_checkpoints:Vec<u32>,//unordered_checkpoints[checkpoint_id]=model_id
|
||||||
|
}
|
||||||
|
|
||||||
//you have this effect while in contact
|
//you have this effect while in contact
|
||||||
struct ContactingSurf{}
|
#[derive(Clone)]
|
||||||
struct ContactingLadder{
|
pub struct ContactingSurf{}
|
||||||
sticky:bool
|
#[derive(Clone)]
|
||||||
|
pub struct ContactingLadder{
|
||||||
|
pub sticky:bool
|
||||||
}
|
}
|
||||||
//you have this effect while intersecting
|
//you have this effect while intersecting
|
||||||
struct IntersectingWater{
|
#[derive(Clone)]
|
||||||
viscosity:i64,
|
pub struct IntersectingWater{
|
||||||
density:i64,
|
pub viscosity:i64,
|
||||||
|
pub density:i64,
|
||||||
|
pub current:glam::Vec3,
|
||||||
}
|
}
|
||||||
struct IntersectingAccelerator{
|
#[derive(Clone)]
|
||||||
acceleration:glam::I64Vec3
|
pub struct IntersectingAccelerator{
|
||||||
|
pub acceleration:glam::Vec3
|
||||||
}
|
}
|
||||||
//All models can be given these attributes
|
//All models can be given these attributes
|
||||||
struct GameMechanicJumpLimit{
|
#[derive(Clone)]
|
||||||
count:u32,
|
pub struct GameMechanicJumpLimit{
|
||||||
|
pub count:u32,
|
||||||
}
|
}
|
||||||
struct GameMechanicBooster{
|
#[derive(Clone)]
|
||||||
velocity:glam::I64Vec3,
|
pub struct GameMechanicBooster{
|
||||||
|
pub velocity:glam::Vec3,
|
||||||
}
|
}
|
||||||
enum ZoneBehaviour{
|
#[derive(Clone)]
|
||||||
|
pub enum ZoneBehaviour{
|
||||||
//Start is indexed
|
//Start is indexed
|
||||||
//Checkpoints are indexed
|
//Checkpoints are indexed
|
||||||
Finish,
|
Finish,
|
||||||
Anitcheat,
|
Anitcheat,
|
||||||
}
|
}
|
||||||
struct GameMechanicZone{
|
#[derive(Clone)]
|
||||||
mode_id:u32,
|
pub struct GameMechanicZone{
|
||||||
behaviour:ZoneBehaviour
|
pub mode_id:u32,
|
||||||
|
pub behaviour:ZoneBehaviour,
|
||||||
}
|
}
|
||||||
// enum TrapCondition{
|
// enum TrapCondition{
|
||||||
// FasterThan(i64),
|
// FasterThan(i64),
|
||||||
@ -102,36 +118,45 @@ struct GameMechanicZone{
|
|||||||
// InRange(i64,i64),
|
// InRange(i64,i64),
|
||||||
// OutsideRange(i64,i64),
|
// OutsideRange(i64,i64),
|
||||||
// }
|
// }
|
||||||
enum StageElementBehaviour{
|
#[derive(Clone)]
|
||||||
SpawnAt,
|
pub enum StageElementBehaviour{
|
||||||
Trigger,
|
//Spawn,//The behaviour of stepping on a spawn setting the spawnid
|
||||||
Teleport,
|
SpawnAt,
|
||||||
Platform,
|
Trigger,
|
||||||
//Speedtrap(TrapCondition),//Acts as a trigger with a speed condition
|
Teleport,
|
||||||
|
Platform,
|
||||||
|
//Speedtrap(TrapCondition),//Acts as a trigger with a speed condition
|
||||||
}
|
}
|
||||||
struct GameMechanicStageElement{
|
#[derive(Clone)]
|
||||||
mode_id:u32,
|
pub struct GameMechanicStageElement{
|
||||||
stage_id:u32,//which spawn to send to
|
pub mode_id:u32,
|
||||||
force:bool,//allow setting to lower spawn id i.e. 7->3
|
pub stage_id:u32,//which spawn to send to
|
||||||
behaviour:StageElementBehaviour
|
pub force:bool,//allow setting to lower spawn id i.e. 7->3
|
||||||
|
pub behaviour:StageElementBehaviour
|
||||||
}
|
}
|
||||||
struct GameMechanicWormhole{//(position,angles)*=origin.transform.inverse()*destination.transform
|
#[derive(Clone)]
|
||||||
model_id:u32,
|
pub struct GameMechanicWormhole{//(position,angles)*=origin.transform.inverse()*destination.transform
|
||||||
|
pub model_id:u32,
|
||||||
}
|
}
|
||||||
struct GameMechanicAttributes{
|
#[derive(Default,Clone)]
|
||||||
jump_limit:Option<GameMechanicJumpLimit>,
|
pub struct GameMechanicAttributes{
|
||||||
booster:Option<GameMechanicBooster>,
|
pub jump_limit:Option<GameMechanicJumpLimit>,
|
||||||
zone:Option<GameMechanicZone>,
|
pub booster:Option<GameMechanicBooster>,
|
||||||
stage_element:Option<GameMechanicStageElement>,
|
pub zone:Option<GameMechanicZone>,
|
||||||
wormhole:Option<GameMechanicWormhole>,
|
pub stage_element:Option<GameMechanicStageElement>,
|
||||||
|
pub wormhole:Option<GameMechanicWormhole>,//stage_element and wormhole are in conflict
|
||||||
}
|
}
|
||||||
struct ContactingAttributes{
|
#[derive(Default,Clone)]
|
||||||
surf:Option<ContactingSurf>,
|
pub struct ContactingAttributes{
|
||||||
ladder:Option<ContactingLadder>,
|
pub elasticity:Option<u32>,//[1/2^32,1] 0=None (elasticity+1)/2^32
|
||||||
|
//friction?
|
||||||
|
pub surf:Option<ContactingSurf>,
|
||||||
|
pub ladder:Option<ContactingLadder>,
|
||||||
}
|
}
|
||||||
struct IntersectingAttibutes{
|
#[derive(Default,Clone)]
|
||||||
water:Option<IntersectingWater>,
|
pub struct IntersectingAttributes{
|
||||||
accelerator:Option<IntersectingAccelerator>,
|
pub water:Option<IntersectingWater>,
|
||||||
|
pub accelerator:Option<IntersectingAccelerator>,
|
||||||
}
|
}
|
||||||
//Spawn(u32) NO! spawns are indexed in the map header instead of marked with attibutes
|
//Spawn(u32) NO! spawns are indexed in the map header instead of marked with attibutes
|
||||||
pub enum CollisionAttributes{
|
pub enum CollisionAttributes{
|
||||||
@ -141,7 +166,7 @@ pub enum CollisionAttributes{
|
|||||||
general:GameMechanicAttributes,
|
general:GameMechanicAttributes,
|
||||||
},
|
},
|
||||||
Intersect{//track whether you are intersecting the object
|
Intersect{//track whether you are intersecting the object
|
||||||
intersecting:IntersectingAttibutes,
|
intersecting:IntersectingAttributes,
|
||||||
general:GameMechanicAttributes,
|
general:GameMechanicAttributes,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user