mirror of
https://github.com/jugeeya/UltimateTrainingModpack.git
synced 2024-11-28 04:44:06 +00:00
[Input Display] Remove stutters by using smart positioning
This commit is contained in:
parent
427609ba8e
commit
243bbf470d
2 changed files with 17 additions and 17 deletions
|
@ -66,6 +66,7 @@ pub static OVERALL_FRAME_COUNTER: Lazy<usize> =
|
|||
Lazy::new(|| frame_counter::register_counter(frame_counter::FrameCounterType::InGameNoReset));
|
||||
|
||||
pub const NUM_LOGS: usize = 10;
|
||||
pub static mut DRAW_LOG_BASE_IDX: Lazy<usize> = Lazy::new(|| 0);
|
||||
|
||||
#[derive(PartialEq, Eq, Debug, Copy, Clone)]
|
||||
pub enum DirectionStrength {
|
||||
|
@ -280,8 +281,6 @@ fn insert_in_front<T>(array: &mut [T], value: T) {
|
|||
lazy_static! {
|
||||
pub static ref P1_INPUT_LOGS: Mutex<[InputLog; NUM_LOGS]> =
|
||||
Mutex::new([InputLog::default(); NUM_LOGS]);
|
||||
pub static ref DRAWN_LOGS: Mutex<[InputLog; NUM_LOGS]> =
|
||||
Mutex::new([InputLog::default(); NUM_LOGS]);
|
||||
}
|
||||
|
||||
pub fn handle_final_input_mapping(
|
||||
|
@ -332,6 +331,7 @@ pub fn handle_final_input_mapping(
|
|||
// We should count this frame already
|
||||
frame_counter::tick_idx(*PER_LOG_FRAME_COUNTER);
|
||||
insert_in_front(input_logs, potential_input_log);
|
||||
*DRAW_LOG_BASE_IDX = (*DRAW_LOG_BASE_IDX + 1) % NUM_LOGS;
|
||||
} else if is_new_frame {
|
||||
*latest_input_log = potential_input_log;
|
||||
latest_input_log.frames = std::cmp::min(current_frame, 99);
|
||||
|
@ -339,7 +339,7 @@ pub fn handle_final_input_mapping(
|
|||
}
|
||||
|
||||
// Decrease TTL
|
||||
for input_log in input_logs.iter_mut().take(NUM_LOGS) {
|
||||
for input_log in input_logs.iter_mut() {
|
||||
if input_log.ttl > 0 && is_new_frame {
|
||||
input_log.ttl -= 1;
|
||||
}
|
||||
|
|
|
@ -7,7 +7,9 @@ use training_mod_consts::{InputDisplay, MENU};
|
|||
use crate::{
|
||||
common::{consts::status_display_name, menu::QUICK_MENU_ACTIVE},
|
||||
training::{
|
||||
input_log::{DirectionStrength, InputLog, DRAWN_LOGS, P1_INPUT_LOGS, WHITE, YELLOW},
|
||||
input_log::{
|
||||
DirectionStrength, InputLog, DRAW_LOG_BASE_IDX, NUM_LOGS, P1_INPUT_LOGS, WHITE, YELLOW,
|
||||
},
|
||||
ui::{fade_out, menu::VANILLA_MENU_ACTIVE},
|
||||
},
|
||||
};
|
||||
|
@ -66,11 +68,13 @@ fn get_input_icons(log: &InputLog) -> VecDeque<(&str, ResColor)> {
|
|||
icons
|
||||
}
|
||||
|
||||
unsafe fn draw_log(root_pane: &Pane, log_idx: usize, log: &InputLog, drawn_log: &mut InputLog) {
|
||||
unsafe fn draw_log(root_pane: &Pane, log_idx: usize, log: &InputLog) {
|
||||
let draw_log_idx = (log_idx + (NUM_LOGS - *DRAW_LOG_BASE_IDX)) % NUM_LOGS;
|
||||
let log_pane = root_pane
|
||||
.find_pane_by_name_recursive(log_parent_fmt!(log_idx))
|
||||
.find_pane_by_name_recursive(log_parent_fmt!(draw_log_idx))
|
||||
.unwrap();
|
||||
|
||||
// Handle visibility and alpha
|
||||
log_pane.set_visible(
|
||||
!QUICK_MENU_ACTIVE && !VANILLA_MENU_ACTIVE && MENU.input_display != InputDisplay::None,
|
||||
);
|
||||
|
@ -80,11 +84,13 @@ unsafe fn draw_log(root_pane: &Pane, log_idx: usize, log: &InputLog, drawn_log:
|
|||
const FADE_FRAMES: u32 = 200;
|
||||
fade_out(log_pane, log.ttl, FADE_FRAMES);
|
||||
|
||||
// Don't redraw
|
||||
if *log == *drawn_log {
|
||||
// Handle positioning
|
||||
log_pane.pos_y = -52.5 * log_idx as f32;
|
||||
log_pane.flags |= 1 << PaneFlag::IsGlobalMatrixDirty as u8;
|
||||
|
||||
// Only redraw first log!
|
||||
if log_idx != 0 {
|
||||
return;
|
||||
} else {
|
||||
*drawn_log = *log;
|
||||
}
|
||||
|
||||
let icons = get_input_icons(log);
|
||||
|
@ -150,7 +156,6 @@ unsafe fn draw_log(root_pane: &Pane, log_idx: usize, log: &InputLog, drawn_log:
|
|||
|
||||
icon_pane.set_visible(true);
|
||||
(*icon_pane.material).set_black_res_color(*icon_color);
|
||||
icon_pane.flags |= PaneFlag::IsGlobalMatrixDirty as u8;
|
||||
}
|
||||
|
||||
let frame_text = format!("{}", log.frames);
|
||||
|
@ -178,13 +183,8 @@ pub unsafe fn draw(root_pane: &Pane) {
|
|||
return;
|
||||
}
|
||||
let logs = &*logs_ptr;
|
||||
let drawn_logs_ptr = DRAWN_LOGS.data_ptr();
|
||||
if drawn_logs_ptr.is_null() {
|
||||
return;
|
||||
}
|
||||
let drawn_logs = &mut *drawn_logs_ptr;
|
||||
|
||||
for (log_idx, log) in logs.iter().enumerate() {
|
||||
draw_log(root_pane, log_idx, log, &mut drawn_logs[log_idx]);
|
||||
draw_log(root_pane, log_idx, log);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue