mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Simplify model cache key, fixes performance issue
This commit is contained in:
parent
84516afff1
commit
ad1bccfee0
@ -164,7 +164,7 @@ impl Scene {
|
|||||||
Body::Humanoid(body),
|
Body::Humanoid(body),
|
||||||
Some(equipment),
|
Some(equipment),
|
||||||
client.get_tick(),
|
client.get_tick(),
|
||||||
None,
|
CameraMode::default(),
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
.0;
|
.0;
|
||||||
|
@ -13,12 +13,7 @@ use hashbrown::HashMap;
|
|||||||
#[derive(PartialEq, Eq, Hash, Clone)]
|
#[derive(PartialEq, Eq, Hash, Clone)]
|
||||||
enum FigureKey {
|
enum FigureKey {
|
||||||
Simple(Body),
|
Simple(Body),
|
||||||
Complex(
|
Complex(Body, Option<Equipment>, CameraMode, Option<CharacterState>),
|
||||||
Body,
|
|
||||||
Option<Equipment>,
|
|
||||||
Option<CameraMode>,
|
|
||||||
Option<CharacterState>,
|
|
||||||
),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct FigureModelCache {
|
pub struct FigureModelCache {
|
||||||
@ -40,7 +35,7 @@ impl FigureModelCache {
|
|||||||
body: Body,
|
body: Body,
|
||||||
equipment: Option<&Equipment>,
|
equipment: Option<&Equipment>,
|
||||||
tick: u64,
|
tick: u64,
|
||||||
camera_mode: Option<CameraMode>,
|
camera_mode: CameraMode,
|
||||||
character_state: Option<&CharacterState>,
|
character_state: Option<&CharacterState>,
|
||||||
) -> &(Model<FigurePipeline>, SkeletonAttr) {
|
) -> &(Model<FigurePipeline>, SkeletonAttr) {
|
||||||
let key = if equipment.is_some() {
|
let key = if equipment.is_some() {
|
||||||
@ -67,7 +62,7 @@ impl FigureModelCache {
|
|||||||
HumHeadSpec::load_watched(&mut self.manifest_indicator);
|
HumHeadSpec::load_watched(&mut self.manifest_indicator);
|
||||||
let bone_meshes = match body {
|
let bone_meshes = match body {
|
||||||
Body::Humanoid(body) => [
|
Body::Humanoid(body) => [
|
||||||
match camera_mode.unwrap_or_default() {
|
match camera_mode {
|
||||||
CameraMode::ThirdPerson => {
|
CameraMode::ThirdPerson => {
|
||||||
Some(humanoid_head_spec.mesh_head(
|
Some(humanoid_head_spec.mesh_head(
|
||||||
body.race,
|
body.race,
|
||||||
@ -83,29 +78,29 @@ impl FigureModelCache {
|
|||||||
}
|
}
|
||||||
CameraMode::FirstPerson => None,
|
CameraMode::FirstPerson => None,
|
||||||
},
|
},
|
||||||
match camera_mode.unwrap_or_default() {
|
match camera_mode {
|
||||||
CameraMode::ThirdPerson => Some(mesh_chest(body.chest)),
|
CameraMode::ThirdPerson => Some(mesh_chest(body.chest)),
|
||||||
CameraMode::FirstPerson => None,
|
CameraMode::FirstPerson => None,
|
||||||
},
|
},
|
||||||
match camera_mode.unwrap_or_default() {
|
match camera_mode {
|
||||||
CameraMode::ThirdPerson => Some(mesh_belt(body.belt)),
|
CameraMode::ThirdPerson => Some(mesh_belt(body.belt)),
|
||||||
CameraMode::FirstPerson => None,
|
CameraMode::FirstPerson => None,
|
||||||
},
|
},
|
||||||
match camera_mode.unwrap_or_default() {
|
match camera_mode {
|
||||||
CameraMode::ThirdPerson => Some(mesh_pants(body.pants)),
|
CameraMode::ThirdPerson => Some(mesh_pants(body.pants)),
|
||||||
CameraMode::FirstPerson => None,
|
CameraMode::FirstPerson => None,
|
||||||
},
|
},
|
||||||
Some(mesh_left_hand(body.hand)),
|
Some(mesh_left_hand(body.hand)),
|
||||||
Some(mesh_right_hand(body.hand)),
|
Some(mesh_right_hand(body.hand)),
|
||||||
match camera_mode.unwrap_or_default() {
|
match camera_mode {
|
||||||
CameraMode::ThirdPerson => Some(mesh_left_foot(body.foot)),
|
CameraMode::ThirdPerson => Some(mesh_left_foot(body.foot)),
|
||||||
CameraMode::FirstPerson => None,
|
CameraMode::FirstPerson => None,
|
||||||
},
|
},
|
||||||
match camera_mode.unwrap_or_default() {
|
match camera_mode {
|
||||||
CameraMode::ThirdPerson => Some(mesh_right_foot(body.foot)),
|
CameraMode::ThirdPerson => Some(mesh_right_foot(body.foot)),
|
||||||
CameraMode::FirstPerson => None,
|
CameraMode::FirstPerson => None,
|
||||||
},
|
},
|
||||||
if camera_mode.unwrap_or_default() != CameraMode::FirstPerson
|
if camera_mode != CameraMode::FirstPerson
|
||||||
|| character_state
|
|| character_state
|
||||||
.map(|cs| {
|
.map(|cs| {
|
||||||
cs.action.is_attack()
|
cs.action.is_attack()
|
||||||
@ -118,13 +113,13 @@ impl FigureModelCache {
|
|||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
},
|
},
|
||||||
match camera_mode.unwrap_or_default() {
|
match camera_mode {
|
||||||
CameraMode::ThirdPerson => {
|
CameraMode::ThirdPerson => {
|
||||||
Some(mesh_left_shoulder(body.shoulder))
|
Some(mesh_left_shoulder(body.shoulder))
|
||||||
}
|
}
|
||||||
CameraMode::FirstPerson => None,
|
CameraMode::FirstPerson => None,
|
||||||
},
|
},
|
||||||
match camera_mode.unwrap_or_default() {
|
match camera_mode {
|
||||||
CameraMode::ThirdPerson => {
|
CameraMode::ThirdPerson => {
|
||||||
Some(mesh_right_shoulder(body.shoulder))
|
Some(mesh_right_shoulder(body.shoulder))
|
||||||
}
|
}
|
||||||
|
@ -121,7 +121,7 @@ impl FigureMgr {
|
|||||||
*body,
|
*body,
|
||||||
stats.map(|s| &s.equipment),
|
stats.map(|s| &s.equipment),
|
||||||
tick,
|
tick,
|
||||||
None,
|
CameraMode::default(),
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
.1;
|
.1;
|
||||||
@ -348,6 +348,11 @@ impl FigureMgr {
|
|||||||
|
|
||||||
let frustum = camera.frustum(client);
|
let frustum = camera.frustum(client);
|
||||||
|
|
||||||
|
let character_state_storage = client
|
||||||
|
.state()
|
||||||
|
.read_storage::<common::comp::CharacterState>();
|
||||||
|
let character_state = character_state_storage.get(client.entity());
|
||||||
|
|
||||||
for (entity, _, _, _, body, stats, _) in (
|
for (entity, _, _, _, body, stats, _) in (
|
||||||
&ecs.entities(),
|
&ecs.entities(),
|
||||||
&ecs.read_storage::<Pos>(),
|
&ecs.read_storage::<Pos>(),
|
||||||
@ -389,22 +394,19 @@ impl FigureMgr {
|
|||||||
.map(|state| (state.locals(), state.bone_consts())),
|
.map(|state| (state.locals(), state.bone_consts())),
|
||||||
} {
|
} {
|
||||||
// Don't render the player's body while in first person mode
|
// Don't render the player's body while in first person mode
|
||||||
let player_camera_mode = if client
|
// let has_body = client
|
||||||
.state()
|
// .state()
|
||||||
.read_storage::<common::comp::Body>()
|
// .read_storage::<common::comp::Body>()
|
||||||
.get(client.entity())
|
// .get(client.entity())
|
||||||
.is_some()
|
// .is_some();
|
||||||
&& entity == client.entity()
|
|
||||||
{
|
|
||||||
Some(camera.get_mode())
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
};
|
|
||||||
|
|
||||||
let character_state_storage = client
|
let is_player = entity == client.entity();
|
||||||
.state()
|
|
||||||
.read_storage::<common::comp::CharacterState>();
|
let player_camera_mode = if is_player {
|
||||||
let character_state = character_state_storage.get(client.entity());
|
camera.get_mode()
|
||||||
|
} else {
|
||||||
|
CameraMode::default()
|
||||||
|
};
|
||||||
|
|
||||||
let model = &self
|
let model = &self
|
||||||
.model_cache
|
.model_cache
|
||||||
@ -414,7 +416,7 @@ impl FigureMgr {
|
|||||||
stats.map(|s| &s.equipment),
|
stats.map(|s| &s.equipment),
|
||||||
tick,
|
tick,
|
||||||
player_camera_mode,
|
player_camera_mode,
|
||||||
character_state,
|
if is_player { character_state } else { None },
|
||||||
)
|
)
|
||||||
.0;
|
.0;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user