Render airship sprites in char select

This commit is contained in:
Joshua Barretto 2024-01-15 22:51:54 +00:00
parent d51b5c5bea
commit 751df7801f
4 changed files with 42 additions and 15 deletions

View File

@ -25,14 +25,12 @@ pub struct CharSelectionState {
impl CharSelectionState { impl CharSelectionState {
/// Create a new `CharSelectionState`. /// Create a new `CharSelectionState`.
pub fn new(global_state: &mut GlobalState, client: Rc<RefCell<Client>>) -> Self { pub fn new(global_state: &mut GlobalState, client: Rc<RefCell<Client>>) -> Self {
let sprite_render_state = let sprite_render_context = (global_state.lazy_init)(global_state.window.renderer_mut());
(global_state.lazy_init)(global_state.window.renderer_mut()).state;
let scene = Scene::new( let scene = Scene::new(
global_state.window.renderer_mut(), global_state.window.renderer_mut(),
&mut client.borrow_mut(), &mut client.borrow_mut(),
&global_state.settings, &global_state.settings,
sprite_render_state, sprite_render_context,
); );
let char_selection_ui = CharSelectionUi::new(global_state, &client.borrow()); let char_selection_ui = CharSelectionUi::new(global_state, &client.borrow());

View File

@ -7535,7 +7535,7 @@ impl FigureStateMeta {
pub struct FigureState<S, D = ()> { pub struct FigureState<S, D = ()> {
meta: FigureStateMeta, meta: FigureStateMeta,
skeleton: S, skeleton: S,
extra: D, pub extra: D,
} }
impl<S, D> Deref for FigureState<S, D> { impl<S, D> Deref for FigureState<S, D> {

View File

@ -1,13 +1,15 @@
use crate::{ use crate::{
render::{ render::{
create_skybox_mesh, Consts, FirstPassDrawer, GlobalModel, Globals, GlobalsBindGroup, Light, create_skybox_mesh, pipelines::terrain::BoundLocals as BoundTerrainLocals, AltIndices,
Model, PointLightMatrix, RainOcclusionLocals, Renderer, Shadow, ShadowLocals, SkyboxVertex, Consts, FirstPassDrawer, GlobalModel, Globals, GlobalsBindGroup, Light, Model,
PointLightMatrix, RainOcclusionLocals, Renderer, Shadow, ShadowLocals, SkyboxVertex,
SpriteGlobalsBindGroup,
}, },
scene::{ scene::{
camera::{self, Camera, CameraMode}, camera::{self, Camera, CameraMode},
figure::{FigureAtlas, FigureModelCache, FigureState, FigureUpdateCommonParameters}, figure::{FigureAtlas, FigureModelCache, FigureState, FigureUpdateCommonParameters},
terrain::SpriteRenderState, terrain::{SpriteRenderContext, SpriteRenderState},
CloudsLocals, Lod, PostProcessLocals, CloudsLocals, CullingMode, Lod, PostProcessLocals,
}, },
window::{Event, PressState}, window::{Event, PressState},
Settings, Settings,
@ -54,6 +56,7 @@ pub struct Scene {
figure_atlas: FigureAtlas, figure_atlas: FigureAtlas,
sprite_render_state: SpriteRenderState, sprite_render_state: SpriteRenderState,
sprite_globals: SpriteGlobalsBindGroup,
turning_camera: bool, turning_camera: bool,
@ -62,7 +65,7 @@ pub struct Scene {
char_model_cache: FigureModelCache<CharacterSkeleton>, char_model_cache: FigureModelCache<CharacterSkeleton>,
airship_pos: Vec3<f32>, airship_pos: Vec3<f32>,
airship_state: Option<FigureState<ShipSkeleton>>, airship_state: Option<FigureState<ShipSkeleton, BoundTerrainLocals>>,
airship_model_cache: FigureModelCache<ShipSkeleton>, airship_model_cache: FigureModelCache<ShipSkeleton>,
} }
@ -84,7 +87,7 @@ impl Scene {
renderer: &mut Renderer, renderer: &mut Renderer,
client: &mut Client, client: &mut Client,
settings: &Settings, settings: &Settings,
sprite_render_state: SpriteRenderState, sprite_render_context: SpriteRenderContext,
) -> Self { ) -> Self {
let start_angle = -90.0f32.to_radians(); let start_angle = -90.0f32.to_radians();
let resolution = renderer.resolution().map(|e| e as f32); let resolution = renderer.resolution().map(|e| e as f32);
@ -125,16 +128,21 @@ impl Scene {
client.set_lod_distance(settings.graphics.lod_distance); client.set_lod_distance(settings.graphics.lod_distance);
Self { Self {
data,
globals_bind_group, globals_bind_group,
skybox: Skybox { skybox: Skybox {
model: renderer.create_model(&create_skybox_mesh()).unwrap(), model: renderer.create_model(&create_skybox_mesh()).unwrap(),
}, },
lod,
map_bounds, map_bounds,
figure_atlas, figure_atlas,
sprite_render_state, sprite_render_state: sprite_render_context.state,
sprite_globals: renderer.bind_sprite_globals(
&data,
lod.get_data(),
&sprite_render_context.sprite_verts_buffer,
),
lod,
data,
camera, camera,
@ -433,6 +441,27 @@ impl Scene {
drop(figure_drawer); drop(figure_drawer);
let mut sprite_drawer = drawer.draw_sprites(
&self.sprite_globals,
&self.sprite_render_state.sprite_atlas_textures,
);
if let (Some(sprite_instances), Some(data)) = (
self.airship_model_cache
.get_sprites(ship::Body::DefaultAirship),
self.airship_state.as_ref().map(|s| &s.extra),
) {
sprite_drawer.draw(
data,
&sprite_instances[0],
&AltIndices {
deep_end: 0,
underground_end: 0,
},
CullingMode::None,
);
}
drop(sprite_drawer);
self.lod.render(drawer, Default::default()); self.lod.render(drawer, Default::default());
drawer.draw_skybox(&self.skybox.model); drawer.draw_skybox(&self.skybox.model);

View File

@ -541,7 +541,7 @@ pub struct SpriteRenderState {
#[derive(Clone)] #[derive(Clone)]
pub struct SpriteRenderContext { pub struct SpriteRenderContext {
pub state: SpriteRenderState, pub state: SpriteRenderState,
sprite_verts_buffer: Arc<SpriteVerts>, pub sprite_verts_buffer: Arc<SpriteVerts>,
} }
pub type SpriteRenderContextLazy = Box<dyn FnMut(&mut Renderer) -> SpriteRenderContext>; pub type SpriteRenderContextLazy = Box<dyn FnMut(&mut Renderer) -> SpriteRenderContext>;