Moved match on ItemUseKind to create durations to a function under ItemUseKind.

This commit is contained in:
Sam 2021-06-29 05:58:50 -05:00
parent 381c7121c6
commit f5533cdb92
5 changed files with 23 additions and 94 deletions

View File

@ -164,6 +164,24 @@ impl From<&ItemKind> for Option<ItemUseKind> {
}
}
impl ItemUseKind {
/// Returns (buildup, use, recover)
pub fn durations(&self) -> (Duration, Duration, Duration) {
match self {
Self::Consumable(ConsumableKind::Potion) => (
Duration::from_secs_f32(0.1),
Duration::from_secs_f32(1.1),
Duration::from_secs_f32(0.1),
),
Self::Consumable(ConsumableKind::Food) => (
Duration::from_secs_f32(1.0),
Duration::from_secs_f32(5.0),
Duration::from_secs_f32(0.5),
),
}
}
}
/// Used to control when the item is used in the state
enum UsePoint {
/// Between buildup and use

View File

@ -3,7 +3,7 @@ use crate::{
comp::{
biped_large, biped_small,
inventory::slot::{EquipSlot, Slot},
item::{ConsumableKind, Hands, ItemKind, Tool, ToolKind},
item::{Hands, ItemKind, Tool, ToolKind},
quadruped_low, quadruped_medium, quadruped_small,
skills::{Skill, SwimSkill},
theropod, Body, CharacterAbility, CharacterState, Density, InputAttr, InputKind,
@ -585,25 +585,13 @@ pub fn handle_manipulate_loadout(
.get(inv_slot)
.and_then(|item| Option::<ItemUseKind>::from(item.kind()).zip(Some(item)))
{
// (buildup, use, recover)
let durations = match item_kind {
ItemUseKind::Consumable(ConsumableKind::Potion) => (
Duration::from_secs_f32(0.1),
Duration::from_secs_f32(1.1),
Duration::from_secs_f32(0.1),
),
ItemUseKind::Consumable(ConsumableKind::Food) => (
Duration::from_secs_f32(1.0),
Duration::from_secs_f32(5.0),
Duration::from_secs_f32(0.5),
),
};
let (buildup_duration, use_duration, recover_duration) = item_kind.durations();
// If item returns a valid kind for item use, do into use item character state
update.character = CharacterState::UseItem(use_item::Data {
static_data: use_item::StaticData {
buildup_duration: durations.0,
use_duration: durations.1,
recover_duration: durations.2,
buildup_duration,
use_duration,
recover_duration,
inv_slot,
item_kind,
item_definition_id: item.item_definition_id().to_string(),

View File

@ -1,29 +0,0 @@
{
"traceEvents": [
{ "pid":1, "tid":1, "ts":1624490729402630.3, "dur":4148.4832763671875, "ph":"X", "name":"frame" },
{ "pid":1, "tid":1, "ts":1624490729402665, "dur":160.45570373535156, "ph":"X", "name":"shadow_pass" },
{ "pid":1, "tid":1, "ts":1624490729402665.8, "dur":149.25003051757813, "ph":"X", "name":"direcred_terrain_shadows" },
{ "pid":1, "tid":1, "ts":1624490729402815.5, "dur":9.5367431640625, "ph":"X", "name":"direcred_figure_shadows" },
{ "pid":1, "tid":1, "ts":1624490729402828, "dur":200.74844360351563, "ph":"X", "name":"point shadows" },
{ "pid":1, "tid":1, "ts":1624490729402845.8, "dur":18.835067749023438, "ph":"X", "name":"point shadow face-0 pass" },
{ "pid":1, "tid":1, "ts":1624490729402876.8, "dur":20.02716064453125, "ph":"X", "name":"point shadow face-1 pass" },
{ "pid":1, "tid":1, "ts":1624490729402908.8, "dur":21.219253540039063, "ph":"X", "name":"point shadow face-2 pass" },
{ "pid":1, "tid":1, "ts":1624490729402942.3, "dur":20.503997802734375, "ph":"X", "name":"point shadow face-3 pass" },
{ "pid":1, "tid":1, "ts":1624490729402975, "dur":18.358230590820313, "ph":"X", "name":"point shadow face-4 pass" },
{ "pid":1, "tid":1, "ts":1624490729403005.5, "dur":20.503997802734375, "ph":"X", "name":"point shadow face-5 pass" },
{ "pid":1, "tid":1, "ts":1624490729403062.5, "dur":2062.7975463867188, "ph":"X", "name":"first_pass" },
{ "pid":1, "tid":1, "ts":1624490729403063, "dur":51.021575927734375, "ph":"X", "name":"figures" },
{ "pid":1, "tid":1, "ts":1624490729403114.3, "dur":1763.3438110351563, "ph":"X", "name":"terrain" },
{ "pid":1, "tid":1, "ts":1624490729404879, "dur":56.02836608886719, "ph":"X", "name":"figures" },
{ "pid":1, "tid":1, "ts":1624490729404936, "dur":116.58668518066406, "ph":"X", "name":"lod_terrain" },
{ "pid":1, "tid":1, "ts":1624490729405053.5, "dur":0.2384185791015625, "ph":"X", "name":"skybox" },
{ "pid":1, "tid":1, "ts":1624490729405055, "dur":31.232833862304688, "ph":"X", "name":"sprites" },
{ "pid":1, "tid":1, "ts":1624490729405086.5, "dur":1.1920928955078125, "ph":"X", "name":"fluid" },
{ "pid":1, "tid":1, "ts":1624490729405088.5, "dur":34.809112548828125, "ph":"X", "name":"particles" },
{ "pid":1, "tid":1, "ts":1624490729405124.8, "dur":0.7152557373046875, "ph":"X", "name":"debug" },
{ "pid":1, "tid":1, "ts":1624490729405145.3, "dur":1360.6548309326172, "ph":"X", "name":"second_pass" },
{ "pid":1, "tid":1, "ts":1624490729406520, "dur":255.34629821777344, "ph":"X", "name":"third_pass" },
{ "pid":1, "tid":1, "ts":1624490729406520, "dur":229.12025451660156, "ph":"X", "name":"postprocess" },
{ "pid":1, "tid":1, "ts":1624490729406749.5, "dur":24.557113647460938, "ph":"X", "name":"ui" }
]
}

View File

@ -1,19 +0,0 @@
{
"traceEvents": [
{ "pid":1, "tid":1, "ts":1624496546983163, "dur":5097.150802612305, "ph":"X", "name":"frame" },
{ "pid":1, "tid":1, "ts":1624496546983189.5, "dur":2680.7785034179688, "ph":"X", "name":"first_pass" },
{ "pid":1, "tid":1, "ts":1624496546983190.8, "dur":49.591064453125, "ph":"X", "name":"figures" },
{ "pid":1, "tid":1, "ts":1624496546983241.5, "dur":371.69456481933594, "ph":"X", "name":"terrain" },
{ "pid":1, "tid":1, "ts":1624496546983614.3, "dur":0.7152557373046875, "ph":"X", "name":"figures" },
{ "pid":1, "tid":1, "ts":1624496546983615.3, "dur":335.45494079589844, "ph":"X", "name":"lod_terrain" },
{ "pid":1, "tid":1, "ts":1624496546983951.3, "dur":22.649765014648438, "ph":"X", "name":"skybox" },
{ "pid":1, "tid":1, "ts":1624496546983973.8, "dur":22.172927856445313, "ph":"X", "name":"sprites" },
{ "pid":1, "tid":1, "ts":1624496546983996, "dur":1871.347427368164, "ph":"X", "name":"fluid" },
{ "pid":1, "tid":1, "ts":1624496546985868, "dur":0, "ph":"X", "name":"particles" },
{ "pid":1, "tid":1, "ts":1624496546985869.5, "dur":0.7152557373046875, "ph":"X", "name":"debug" },
{ "pid":1, "tid":1, "ts":1624496546985886.3, "dur":2170.562744140625, "ph":"X", "name":"second_pass" },
{ "pid":1, "tid":1, "ts":1624496546988067.5, "dur":190.73486328125, "ph":"X", "name":"third_pass" },
{ "pid":1, "tid":1, "ts":1624496546988067.8, "dur":188.35067749023438, "ph":"X", "name":"postprocess" },
{ "pid":1, "tid":1, "ts":1624496546988255.8, "dur":1.6689300537109375, "ph":"X", "name":"ui" }
]
}

View File

@ -1,29 +0,0 @@
{
"traceEvents": [
{ "pid":1, "tid":1, "ts":1624499189977124.5, "dur":5191.564559936523, "ph":"X", "name":"frame" },
{ "pid":1, "tid":1, "ts":1624499189977170.8, "dur":362.396240234375, "ph":"X", "name":"shadow_pass" },
{ "pid":1, "tid":1, "ts":1624499189977171.8, "dur":352.3826599121094, "ph":"X", "name":"direcred_terrain_shadows" },
{ "pid":1, "tid":1, "ts":1624499189977524.8, "dur":7.8678131103515625, "ph":"X", "name":"direcred_figure_shadows" },
{ "pid":1, "tid":1, "ts":1624499189977535.5, "dur":323.29559326171875, "ph":"X", "name":"point shadows" },
{ "pid":1, "tid":1, "ts":1624499189977546.8, "dur":39.81590270996094, "ph":"X", "name":"point shadow face-0 pass" },
{ "pid":1, "tid":1, "ts":1624499189977605, "dur":44.58427429199219, "ph":"X", "name":"point shadow face-1 pass" },
{ "pid":1, "tid":1, "ts":1624499189977656, "dur":46.96846008300781, "ph":"X", "name":"point shadow face-2 pass" },
{ "pid":1, "tid":1, "ts":1624499189977711.3, "dur":43.15376281738281, "ph":"X", "name":"point shadow face-3 pass" },
{ "pid":1, "tid":1, "ts":1624499189977762.8, "dur":40.29273986816406, "ph":"X", "name":"point shadow face-4 pass" },
{ "pid":1, "tid":1, "ts":1624499189977809.5, "dur":46.96846008300781, "ph":"X", "name":"point shadow face-5 pass" },
{ "pid":1, "tid":1, "ts":1624499189977879.5, "dur":2310.2760314941406, "ph":"X", "name":"first_pass" },
{ "pid":1, "tid":1, "ts":1624499189977881.3, "dur":10.251998901367188, "ph":"X", "name":"figures" },
{ "pid":1, "tid":1, "ts":1624499189977892.5, "dur":1368.2842254638672, "ph":"X", "name":"terrain" },
{ "pid":1, "tid":1, "ts":1624499189979261.5, "dur":159.5020294189453, "ph":"X", "name":"figures" },
{ "pid":1, "tid":1, "ts":1624499189979421.5, "dur":728.607177734375, "ph":"X", "name":"lod_terrain" },
{ "pid":1, "tid":1, "ts":1624499189980150.5, "dur":18.596649169921875, "ph":"X", "name":"skybox" },
{ "pid":1, "tid":1, "ts":1624499189980170.5, "dur":0.476837158203125, "ph":"X", "name":"sprites" },
{ "pid":1, "tid":1, "ts":1624499189980171, "dur":1.1920928955078125, "ph":"X", "name":"fluid" },
{ "pid":1, "tid":1, "ts":1624499189980172.8, "dur":14.543533325195313, "ph":"X", "name":"particles" },
{ "pid":1, "tid":1, "ts":1624499189980188.5, "dur":0.476837158203125, "ph":"X", "name":"debug" },
{ "pid":1, "tid":1, "ts":1624499189980201.8, "dur":1928.3294677734375, "ph":"X", "name":"second_pass" },
{ "pid":1, "tid":1, "ts":1624499189982139.3, "dur":174.04556274414063, "ph":"X", "name":"third_pass" },
{ "pid":1, "tid":1, "ts":1624499189982140.3, "dur":171.18453979492188, "ph":"X", "name":"postprocess" },
{ "pid":1, "tid":1, "ts":1624499189982312.8, "dur":0.476837158203125, "ph":"X", "name":"ui" }
]
}