Add shadows, fix some animation jank, iterate on valid move indicator

main
Elijah C. Voigt 2 years ago
parent 5bf70e5980
commit 9f5856f86f

1397
Cargo.lock generated

File diff suppressed because it is too large Load Diff

BIN
assets/models/Martian Chess.glb (Stored with Git LFS)

Binary file not shown.

BIN
assets/models/shadow-example.gltf (Stored with Git LFS)

Binary file not shown.

@ -0,0 +1,31 @@
use bevy::prelude::*;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Startup, init)
.add_systems(Update, add_shadows)
.run();
}
fn init(
server: Res<AssetServer>,
mut commands: Commands,
) {
commands.spawn(SceneBundle {
scene: server.load("models/shadow-example.gltf#Scene0"),
..default()
});
}
fn add_shadows(
mut lights: Query<(Entity, &mut PointLight), Added<PointLight>>,
mut commands: Commands,
) {
lights.iter_mut().for_each(|(e, mut l)| {
l.shadows_enabled = true;
let config: bevy::pbr::CascadeShadowConfig = bevy::pbr::CascadeShadowConfigBuilder { ..default() }.into();
commands.entity(e).insert(config);
});
}

@ -148,7 +148,7 @@ fn control_volume(vol: Res<AudioVolume>, query: Query<&AudioSource>) {
}
fn set_intensity(
mut query: Query<(&mut AudioSource, &AudioEvent)>,
query: Query<(&AudioSource, &AudioEvent)>,
board: Res<game::Board>,
tweaks_file: Res<tweak::GameTweaks>,
tweaks: Res<Assets<Tweaks>>,
@ -171,9 +171,9 @@ fn set_intensity(
(intensity_ratio * intensity_range) + intensity_min
};
query.iter_mut()
query.iter()
.filter(|(_, event)| **event == AudioEvent::MainMusic)
.for_each(|(mut source, _)| {
.for_each(|(source, _)| {
info!("Setting music intensity to {:?}", value);
source.event_instance.set_parameter_by_name("Intensity", value, true).expect("Set intensity parameter");
});

@ -39,15 +39,15 @@ impl Plugin for Display3dPlugin {
switch_sides
.run_if(in_state(GameState::Play))
.run_if(state_changed::<game::TurnState>),
update_pieces.run_if(
resource_exists::<tweak::GameTweaks>.and_then(
update_pieces
.run_if(resource_exists::<tweak::GameTweaks>)
.run_if(
any_component_changed::<Piece>()
.or_else(any_component_changed::<Side>())
.or_else(any_component_changed::<BoardIndex>())
.or_else(any_component_removed::<Animating>())
.or_else(any_component_removed::<Captured>()),
),
),
set_board_model.run_if(any_component_added::<game::BoardComponent>()),
set_title_model.run_if(any_component_added::<TitleText>()),
set_valid_move_model.run_if(any_component_added::<game::ValidMove>()),
@ -65,14 +65,11 @@ impl Plugin for Display3dPlugin {
dissolve_animation.run_if(any_with_component::<Dissolving>),
capture_piece.run_if(any_with_component::<game::Captured>),
skip_animation
.run_if(just_pressed(KeyCode::Enter).or_else(just_pressed(MouseButton::Left)))
.run_if(in_state(GameState::Play)),
monitor_animations.run_if(in_state(GameState::Play)),
debug_lights
.run_if(any_component_added::<SpotLight>()
.or_else(any_component_added::<DirectionalLight>())
.or_else(any_component_added::<PointLight>())
)
.run_if(in_state(GameState::Play))
.run_if(just_pressed(KeyCode::Enter).or_else(just_pressed(MouseButton::Left))),
monitor_animations
.run_if(in_state(GameState::Play))
.run_if(any_component_changed::<AnimationPlayer>()),
),
)
.add_systems(
@ -94,6 +91,7 @@ impl Plugin for Display3dPlugin {
(
// Toggle hidden/visible 3d entities
manage_state_entities::<DisplayState>(),
fixup_shadows,
),
)
.add_systems(
@ -104,9 +102,13 @@ impl Plugin for Display3dPlugin {
opening_animation
.run_if(run_once())
.run_if(in_state(DisplayState::Display3d)),
fixup_shadows.after(update_pieces),
),
)
.add_systems(OnEnter(GameState::Title), intro_title_dissolve)
.add_systems(OnEnter(GameState::Title), (
intro_title_dissolve,
fixup_shadows,
))
.add_systems(OnExit(GameState::Title), outro_title_dissolve)
.add_systems(
Update,
@ -377,7 +379,6 @@ fn update_tweaks(
mut camera_settings: Query<(Entity, &mut Skybox, &mut EnvironmentMapLight), With<Display3d>>,
tweaks_file: Res<tweak::GameTweaks>,
tweaks: Res<Assets<Tweaks>>,
mut commands: Commands,
) {
if let Some(tweak) = tweaks.get(tweaks_file.handle.clone()) {
warn!("Updating tweaks!");
@ -593,9 +594,9 @@ fn update_pieces(
.count();
if animating > 0 {
debug!("Piece {:?} is animating. Skipping...", entity);
info!("Piece {:?} is animating. Skipping...", entity);
} else {
debug!("Checking piece object scene for {:?}", entity);
info!("Checking piece object scene for {:?}", entity);
// Find name of this piece's model scene
let scene_tweak_name: Option<String> = match (piece, side) {
@ -611,10 +612,10 @@ fn update_pieces(
let scene_handle = models.named_scenes.get(&scene_tweak_name.unwrap()).unwrap();
// Set scene model for this piece
if *scene != *scene_handle {
// if *scene != *scene_handle {
warn!("Updating scene for piece {:?}", entity);
*scene = scene_handle.clone();
}
// }
}
},
);
@ -1162,8 +1163,8 @@ fn monitor_animations(
});
// Set inactive entities to active
inactive.iter().for_each(|(entity, player)| {
if !player.is_finished() {
info!("Entity {:?} is playing, adding animating marker", entity);
if !player.is_finished() && *player.animation_clip() != Handle::<AnimationClip>::default() {
info!("Entity {:?} is playing {:?}, adding animating marker", entity, player.animation_clip());
commands.entity(entity).insert(Animating);
}
});
@ -1256,11 +1257,12 @@ fn dissolve_animation(
});
}
fn debug_lights(
mut spot_lights: Query<&mut SpotLight, Added<SpotLight>>,
mut point_lights: Query<&mut PointLight, Added<PointLight>>,
mut directional_lights: Query<&mut DirectionalLight, Added<DirectionalLight>>,
fn fixup_shadows(
mut spot_lights: Query<&mut SpotLight>,
mut point_lights: Query<&mut PointLight>,
mut directional_lights: Query<&mut DirectionalLight>,
) {
info!("Fixing up shadows");
spot_lights.iter_mut().for_each(|mut l| {
l.shadows_enabled = true;
});

Loading…
Cancel
Save