dialog WIP paths consolidation and rendering

This commit is contained in:
Jonas H
2026-03-28 10:34:19 +01:00
parent 4c3ebca96e
commit 11b31169b1
70 changed files with 2658 additions and 485 deletions

View File

@@ -7,17 +7,19 @@ use rapier3d::prelude::{ColliderBuilder, RigidBodyBuilder};
use crate::bundles::Bundle;
use crate::components::lights::spot::SpotlightComponent;
use crate::components::player_states::{
FallingState, IdleState, JumpingState, LeapingState, RollingState, WalkingState,
};
use crate::components::{
InputComponent, JumpComponent, MeshComponent, MovementComponent, PhysicsComponent,
};
use crate::entity::EntityHandle;
use crate::loaders::mesh::Mesh;
use crate::paths;
use crate::physics::PhysicsManager;
use crate::render::Pipeline;
use crate::state::StateMachine;
use crate::systems::player_states::{
PlayerFallingState, PlayerIdleState, PlayerJumpingState, PlayerWalkingState,
};
use crate::systems::player_states::{LEAP_DURATION, ROLL_DURATION};
use crate::world::{Transform, World};
pub struct PlayerBundle
@@ -47,28 +49,20 @@ impl Bundle for PlayerBundle
let rigidbody_handle = PhysicsManager::add_rigidbody(rigidbody);
let collider_handle = PhysicsManager::add_collider(collider, Some(rigidbody_handle));
let mesh = Mesh::load_mesh("meshes/player_mesh.glb")
let mesh = Mesh::load_mesh(&paths::meshes::player())
.map_err(|e| format!("missing player mesh: {}", e))?;
let falling_state = PlayerFallingState { entity };
let idle_state = PlayerIdleState { entity };
let walking_state = PlayerWalkingState {
entity,
enter_time_stamp: 0.0,
};
let jumping_state = PlayerJumpingState {
entity,
enter_time_stamp: 0.0,
};
let mut state_machine = StateMachine::new(Box::new(falling_state));
state_machine.add_state(walking_state);
state_machine.add_state(idle_state);
state_machine.add_state(jumping_state);
let mut state_machine = StateMachine::new::<FallingState>();
state_machine.register_state(|w: &mut World| &mut w.falling_states);
state_machine.register_state(|w: &mut World| &mut w.idle_states);
state_machine.register_state(|w: &mut World| &mut w.walking_states);
state_machine.register_state(|w: &mut World| &mut w.jumping_states);
state_machine.register_state(|w: &mut World| &mut w.leaping_states);
state_machine.register_state(|w: &mut World| &mut w.rolling_states);
let entity_id = entity;
state_machine.add_transition::<PlayerFallingState, PlayerIdleState>(move |world| {
state_machine.add_transition::<FallingState, IdleState>(move |world| {
let is_grounded = world
.movements
.with(entity_id, |m| m.movement_context.is_floored)
@@ -80,7 +74,7 @@ impl Bundle for PlayerBundle
is_grounded && !has_input
});
state_machine.add_transition::<PlayerFallingState, PlayerWalkingState>(move |world| {
state_machine.add_transition::<FallingState, WalkingState>(move |world| {
let is_grounded = world
.movements
.with(entity_id, |m| m.movement_context.is_floored)
@@ -92,7 +86,7 @@ impl Bundle for PlayerBundle
is_grounded && has_input
});
state_machine.add_transition::<PlayerIdleState, PlayerWalkingState>(move |world| {
state_machine.add_transition::<IdleState, WalkingState>(move |world| {
let is_grounded = world
.movements
.with(entity_id, |m| m.movement_context.is_floored)
@@ -104,7 +98,7 @@ impl Bundle for PlayerBundle
is_grounded && has_input
});
state_machine.add_transition::<PlayerWalkingState, PlayerIdleState>(move |world| {
state_machine.add_transition::<WalkingState, IdleState>(move |world| {
let is_grounded = world
.movements
.with(entity_id, |m| m.movement_context.is_floored)
@@ -116,23 +110,21 @@ impl Bundle for PlayerBundle
is_grounded && !has_input
});
state_machine.add_transition::<PlayerIdleState, PlayerFallingState>(move |world| {
let is_grounded = world
state_machine.add_transition::<IdleState, FallingState>(move |world| {
!world
.movements
.with(entity_id, |m| m.movement_context.is_floored)
.unwrap_or(false);
!is_grounded
.unwrap_or(false)
});
state_machine.add_transition::<PlayerWalkingState, PlayerFallingState>(move |world| {
let is_grounded = world
state_machine.add_transition::<WalkingState, FallingState>(move |world| {
!world
.movements
.with(entity_id, |m| m.movement_context.is_floored)
.unwrap_or(false);
!is_grounded
.unwrap_or(false)
});
state_machine.add_transition::<PlayerIdleState, PlayerJumpingState>(move |world| {
state_machine.add_transition::<IdleState, JumpingState>(move |world| {
let is_grounded = world
.movements
.with(entity_id, |m| m.movement_context.is_floored)
@@ -144,7 +136,7 @@ impl Bundle for PlayerBundle
is_grounded && jump_pressed
});
state_machine.add_transition::<PlayerWalkingState, PlayerJumpingState>(move |world| {
state_machine.add_transition::<WalkingState, JumpingState>(move |world| {
let is_grounded = world
.movements
.with(entity_id, |m| m.movement_context.is_floored)
@@ -156,15 +148,76 @@ impl Bundle for PlayerBundle
is_grounded && jump_pressed
});
state_machine.add_transition::<PlayerJumpingState, PlayerFallingState>(move |world| {
state_machine.add_transition::<JumpingState, FallingState>(move |world| {
let time = world
.jumping_states
.with(entity_id, |s| s.time_in_state)
.unwrap_or(0.0);
world
.jumps
.with(entity_id, |jump| {
jump.jump_context.duration >= jump.jump_duration
})
.with(entity_id, |j| time >= j.jump_duration)
.unwrap_or(true)
});
state_machine.add_transition::<IdleState, LeapingState>(move |world| {
world
.inputs
.with(entity_id, |i| i.roll_just_pressed)
.unwrap_or(false)
});
state_machine.add_transition::<WalkingState, LeapingState>(move |world| {
world
.inputs
.with(entity_id, |i| i.roll_just_pressed)
.unwrap_or(false)
});
state_machine.add_transition::<LeapingState, RollingState>(move |world| {
world
.leaping_states
.with(entity_id, |s| s.time_in_state >= LEAP_DURATION)
.unwrap_or(false)
});
state_machine.add_transition::<LeapingState, FallingState>(move |world| {
let leap_done = world
.leaping_states
.with(entity_id, |s| s.time_in_state >= LEAP_DURATION)
.unwrap_or(false);
let not_grounded = !world
.movements
.with(entity_id, |m| m.movement_context.is_floored)
.unwrap_or(true);
leap_done && not_grounded
});
state_machine.add_transition::<RollingState, IdleState>(move |world| {
let done = world
.rolling_states
.with(entity_id, |s| s.time_in_state >= ROLL_DURATION)
.unwrap_or(false);
let grounded = world
.movements
.with(entity_id, |m| m.movement_context.is_floored)
.unwrap_or(false);
done && grounded
});
state_machine.add_transition::<RollingState, FallingState>(move |world| {
let done = world
.rolling_states
.with(entity_id, |s| s.time_in_state >= ROLL_DURATION)
.unwrap_or(false);
let grounded = world
.movements
.with(entity_id, |m| m.movement_context.is_floored)
.unwrap_or(false);
done && !grounded
});
world.falling_states.insert(entity, FallingState::default());
world.transforms.insert(entity, spawn_transform);
world.movements.insert(entity, MovementComponent::new());
world.jumps.insert(entity, JumpComponent::default());