Simplify model cache key, fixes performance issue

This commit is contained in:
scott-c 2019-08-18 21:19:32 +08:00
parent bc1ccfc99b
commit 836525c33a
3 changed files with 31 additions and 34 deletions

View File

@ -164,7 +164,7 @@ impl Scene {
Body::Humanoid(body),
Some(equipment),
client.get_tick(),
None,
CameraMode::default(),
None,
)
.0;

View File

@ -13,12 +13,7 @@ use hashbrown::HashMap;
#[derive(PartialEq, Eq, Hash, Clone)]
enum FigureKey {
Simple(Body),
Complex(
Body,
Option<Equipment>,
Option<CameraMode>,
Option<CharacterState>,
),
Complex(Body, Option<Equipment>, CameraMode, Option<CharacterState>),
}
pub struct FigureModelCache {
@ -40,7 +35,7 @@ impl FigureModelCache {
body: Body,
equipment: Option<&Equipment>,
tick: u64,
camera_mode: Option<CameraMode>,
camera_mode: CameraMode,
character_state: Option<&CharacterState>,
) -> &(Model<FigurePipeline>, SkeletonAttr) {
let key = if equipment.is_some() {
@ -67,7 +62,7 @@ impl FigureModelCache {
HumHeadSpec::load_watched(&mut self.manifest_indicator);
let bone_meshes = match body {
Body::Humanoid(body) => [
match camera_mode.unwrap_or_default() {
match camera_mode {
CameraMode::ThirdPerson => {
Some(humanoid_head_spec.mesh_head(
body.race,
@ -83,29 +78,29 @@ impl FigureModelCache {
}
CameraMode::FirstPerson => None,
},
match camera_mode.unwrap_or_default() {
match camera_mode {
CameraMode::ThirdPerson => Some(mesh_chest(body.chest)),
CameraMode::FirstPerson => None,
},
match camera_mode.unwrap_or_default() {
match camera_mode {
CameraMode::ThirdPerson => Some(mesh_belt(body.belt)),
CameraMode::FirstPerson => None,
},
match camera_mode.unwrap_or_default() {
match camera_mode {
CameraMode::ThirdPerson => Some(mesh_pants(body.pants)),
CameraMode::FirstPerson => None,
},
Some(mesh_left_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::FirstPerson => None,
},
match camera_mode.unwrap_or_default() {
match camera_mode {
CameraMode::ThirdPerson => Some(mesh_right_foot(body.foot)),
CameraMode::FirstPerson => None,
},
if camera_mode.unwrap_or_default() != CameraMode::FirstPerson
if camera_mode != CameraMode::FirstPerson
|| character_state
.map(|cs| {
cs.action.is_attack()
@ -118,13 +113,13 @@ impl FigureModelCache {
} else {
None
},
match camera_mode.unwrap_or_default() {
match camera_mode {
CameraMode::ThirdPerson => {
Some(mesh_left_shoulder(body.shoulder))
}
CameraMode::FirstPerson => None,
},
match camera_mode.unwrap_or_default() {
match camera_mode {
CameraMode::ThirdPerson => {
Some(mesh_right_shoulder(body.shoulder))
}

View File

@ -121,7 +121,7 @@ impl FigureMgr {
*body,
stats.map(|s| &s.equipment),
tick,
None,
CameraMode::default(),
None,
)
.1;
@ -348,6 +348,11 @@ impl FigureMgr {
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 (
&ecs.entities(),
&ecs.read_storage::<Pos>(),
@ -389,22 +394,19 @@ impl FigureMgr {
.map(|state| (state.locals(), state.bone_consts())),
} {
// Don't render the player's body while in first person mode
let player_camera_mode = if client
.state()
.read_storage::<common::comp::Body>()
.get(client.entity())
.is_some()
&& entity == client.entity()
{
Some(camera.get_mode())
} else {
None
};
// let has_body = client
// .state()
// .read_storage::<common::comp::Body>()
// .get(client.entity())
// .is_some();
let character_state_storage = client
.state()
.read_storage::<common::comp::CharacterState>();
let character_state = character_state_storage.get(client.entity());
let is_player = entity == client.entity();
let player_camera_mode = if is_player {
camera.get_mode()
} else {
CameraMode::default()
};
let model = &self
.model_cache
@ -414,7 +416,7 @@ impl FigureMgr {
stats.map(|s| &s.equipment),
tick,
player_camera_mode,
character_state,
if is_player { character_state } else { None },
)
.0;