Skip to content

Commit

Permalink
Improve first map server connect
Browse files Browse the repository at this point in the history
On first login the map server will send a command to change the map regardless, so we don't need to handle the map loading in the network event when we disconnect from the character server. We only initialize the player entity and interface in this case. We also don't use the position that the map server sends us in the MapServerLoginSuccessPacket. The ChangeMapPacket is our only signal that we use to first load the new map and then set the correct position. The three positions that we used before this PR lead to some desync in the first few seconds, since it seems, only the final position of the map change network event is the correct one.

We also now properly turn the screen black until we fully finished loading the map.

Later we should also do the loading asynchronously on map change and turn the screen black while loading.
  • Loading branch information
hasenbanck committed Dec 29, 2024
1 parent e34271c commit 72fca1d
Show file tree
Hide file tree
Showing 12 changed files with 646 additions and 574 deletions.
9 changes: 6 additions & 3 deletions korangar/src/graphics/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -861,9 +861,12 @@ impl GraphicsEngine {
.picker_render_pass_context
.create_pass(&mut picker_encoder, &engine_context.global_context, None);

engine_context
.picker_tile_drawer
.draw(&mut render_pass, instruction.map_picker_tile_vertex_buffer);
if let Some(map_picker_tile_vertex_buffer) = instruction.map_picker_tile_vertex_buffer.as_ref() {
engine_context
.picker_tile_drawer
.draw(&mut render_pass, map_picker_tile_vertex_buffer);
}

engine_context.picker_entity_drawer.draw(&mut render_pass, instruction.entities);
#[cfg(feature = "debug")]
{
Expand Down
73 changes: 70 additions & 3 deletions korangar/src/graphics/instruction.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::sync::Arc;

use cgmath::{Matrix4, Point3, Vector2, Vector3, Vector4};
use cgmath::{Matrix4, Point3, SquareMatrix, Vector2, Vector3, Vector4, Zero};
use korangar_util::Rectangle;
use ragnarok_packets::EntityId;
use wgpu::BlendFactor;
Expand Down Expand Up @@ -40,8 +40,8 @@ pub struct RenderInstruction<'a> {
pub point_shadow_entities: &'a [EntityInstruction],
pub effects: &'a [EffectInstruction],
pub water: Option<WaterInstruction<'a>>,
pub map_picker_tile_vertex_buffer: &'a Buffer<TileVertex>,
pub font_map_texture: &'a Texture,
pub map_picker_tile_vertex_buffer: Option<&'a Buffer<TileVertex>>,
pub font_map_texture: Option<&'a Texture>,
#[cfg(feature = "debug")]
pub render_settings: RenderSettings,
#[cfg(feature = "debug")]
Expand All @@ -54,6 +54,47 @@ pub struct RenderInstruction<'a> {
pub marker: &'a [MarkerInstruction],
}

impl Default for RenderInstruction<'static> {
fn default() -> Self {
Self {
clear_interface: true,
show_interface: false,
picker_position: ScreenPosition::default(),
uniforms: Uniforms::default(),
indicator: None,
interface: &[],
bottom_layer_rectangles: &[],
middle_layer_rectangles: &[],
top_layer_rectangles: &[],
directional_light_with_shadow: DirectionalShadowCasterInstruction::default(),
point_light_shadow_caster: &[],
point_light: &[],
model_batches: &[],
models: &mut [],
entities: &mut [],
directional_model_batches: &[],
directional_shadow_models: &[],
directional_shadow_entities: &[],
point_shadow_models: &[],
point_shadow_entities: &[],
effects: &[],
water: None,
map_picker_tile_vertex_buffer: None,
font_map_texture: None,
#[cfg(feature = "debug")]
render_settings: RenderSettings::default(),
#[cfg(feature = "debug")]
aabb: &[],
#[cfg(feature = "debug")]
circles: &[],
#[cfg(feature = "debug")]
rectangles: &[],
#[cfg(feature = "debug")]
marker: &[],
}
}
}

#[derive(Clone, Debug)]
pub struct Uniforms {
pub view_matrix: Matrix4<f32>,
Expand All @@ -66,6 +107,21 @@ pub struct Uniforms {
pub shadow_quality: ShadowQuality,
}

impl Default for Uniforms {
fn default() -> Self {
Self {
view_matrix: Matrix4::identity(),
projection_matrix: Matrix4::identity(),
camera_position: Vector4::zero(),
animation_timer: 0.0,
day_timer: 0.0,
ambient_light_color: Color::default(),
enhanced_lighting: false,
shadow_quality: ShadowQuality::Soft,
}
}
}

#[derive(Clone, Debug)]
pub struct WaterInstruction<'a> {
pub water_texture: &'a Texture,
Expand All @@ -86,6 +142,17 @@ pub struct DirectionalShadowCasterInstruction {
pub color: Color,
}

impl Default for DirectionalShadowCasterInstruction {
fn default() -> Self {
Self {
view_projection_matrix: Matrix4::identity(),
view_matrix: Matrix4::identity(),
direction: Vector3::zero(),
color: Color::default(),
}
}
}

/// Right now point shadows can't cast shadows of models that are not part of
/// the map.
#[derive(Clone, Debug)]
Expand Down
12 changes: 8 additions & 4 deletions korangar/src/graphics/passes/interface/rectangle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,10 @@ impl Prepare for InterfaceRectangleDrawer {
return;
}

let Some(font_map_texture) = instructions.font_map_texture else {
return;
};

self.instance_data.clear();

if self.bindless_support {
Expand Down Expand Up @@ -381,8 +385,8 @@ impl Prepare for InterfaceRectangleDrawer {
&self.bind_group_layout,
&self.instance_data_buffer,
&texture_views,
instructions.font_map_texture.get_texture_view(),
)
font_map_texture.get_texture_view(),
);
} else {
for instruction in instructions.interface.iter() {
match instruction {
Expand Down Expand Up @@ -481,8 +485,8 @@ impl Prepare for InterfaceRectangleDrawer {
device,
&self.bind_group_layout,
&self.instance_data_buffer,
instructions.font_map_texture.get_texture_view(),
)
font_map_texture.get_texture_view(),
);
}
}

Expand Down
4 changes: 3 additions & 1 deletion korangar/src/graphics/passes/postprocessing/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ impl Drawer<{ BindGroupCount::One }, { ColorAttachmentCount::One }, { DepthAttac

impl Prepare for PostProcessingBufferDrawer {
fn prepare(&mut self, device: &Device, instructions: &RenderInstruction) {
self.bind_group = Self::create_bind_group(device, &self.bind_group_layout, instructions.font_map_texture);
if let Some(font_map_texture) = instructions.font_map_texture {
self.bind_group = Self::create_bind_group(device, &self.bind_group_layout, font_map_texture);
}
}

fn upload(&mut self, _device: &Device, _staging_belt: &mut StagingBelt, _command_encoder: &mut CommandEncoder) {
Expand Down
9 changes: 6 additions & 3 deletions korangar/src/graphics/passes/postprocessing/rectangle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,10 @@ impl Prepare for PostProcessingRectangleDrawer {
return;
}

let Some(font_map_texture) = instructions.font_map_texture else {
return;
};

self.instance_data.clear();

if self.bindless_support {
Expand Down Expand Up @@ -409,7 +413,7 @@ impl Prepare for PostProcessingRectangleDrawer {
&self.bind_group_layout,
&self.instance_data_buffer,
&texture_views,
instructions.font_map_texture.get_texture_view(),
font_map_texture.get_texture_view(),
);
} else {
let mut offset = 0;
Expand Down Expand Up @@ -507,12 +511,11 @@ impl Prepare for PostProcessingRectangleDrawer {
}
}

self.instance_data_buffer.reserve(device, self.instance_data.len());
self.bind_group = Self::create_bind_group(
device,
&self.bind_group_layout,
&self.instance_data_buffer,
instructions.font_map_texture.get_texture_view(),
font_map_texture.get_texture_view(),
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion korangar/src/graphics/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ impl Display for ScreenSpaceAntiAliasing {
}

#[cfg(feature = "debug")]
#[derive(Copy, Clone, new)]
#[derive(Copy, Clone, Default, new)]
pub struct RenderSettings {
#[new(value = "true")]
pub show_frames_per_second: bool,
Expand Down
Loading

0 comments on commit 72fca1d

Please sign in to comment.