mirror of
https://github.com/jugeeya/UltimateTrainingModpack.git
synced 2024-11-24 02:44:17 +00:00
[Input Display] Remove stutters by using smart positioning; Frame drops from notifications (#631)
* [Input Display] Remove stutters by using smart positioning * Fixes to notifications
This commit is contained in:
parent
427609ba8e
commit
267cb0c310
4 changed files with 43 additions and 31 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;
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ pub unsafe fn draw(root_pane: &Pane) {
|
|||
let notification_idx = 0;
|
||||
|
||||
let queue = &mut ui::notifications::QUEUE;
|
||||
let notification = queue.first();
|
||||
let notification = queue.first_mut();
|
||||
|
||||
root_pane
|
||||
.find_pane_by_name_recursive(display_parent_fmt!(notification_idx))
|
||||
|
@ -38,21 +38,23 @@ pub unsafe fn draw(root_pane: &Pane) {
|
|||
let notification = notification.unwrap();
|
||||
let color = notification.color;
|
||||
|
||||
root_pane
|
||||
.find_pane_by_name_recursive(display_header_fmt!(notification_idx))
|
||||
.unwrap()
|
||||
.as_textbox()
|
||||
.set_text_string(¬ification.header);
|
||||
if !notification.has_drawn() {
|
||||
notification.set_drawn();
|
||||
root_pane
|
||||
.find_pane_by_name_recursive(display_header_fmt!(notification_idx))
|
||||
.unwrap()
|
||||
.as_textbox()
|
||||
.set_text_string(¬ification.header);
|
||||
|
||||
let text = root_pane
|
||||
.find_pane_by_name_recursive(display_txt_fmt!(notification_idx))
|
||||
.unwrap()
|
||||
.as_textbox();
|
||||
text.set_text_string(¬ification.message);
|
||||
text.set_default_material_colors();
|
||||
text.set_color(color.r, color.g, color.b, color.a);
|
||||
let text = root_pane
|
||||
.find_pane_by_name_recursive(display_txt_fmt!(notification_idx))
|
||||
.unwrap()
|
||||
.as_textbox();
|
||||
text.set_text_string(¬ification.message);
|
||||
text.set_default_material_colors();
|
||||
text.set_color(color.r, color.g, color.b, color.a);
|
||||
}
|
||||
|
||||
let notification = queue.first_mut().unwrap();
|
||||
let has_completed = notification.check_completed();
|
||||
if has_completed {
|
||||
queue.remove(0);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ pub struct Notification {
|
|||
pub message: String,
|
||||
length: u32,
|
||||
pub color: ResColor,
|
||||
has_drawn: bool,
|
||||
}
|
||||
|
||||
impl Notification {
|
||||
|
@ -17,9 +18,18 @@ impl Notification {
|
|||
message,
|
||||
length,
|
||||
color,
|
||||
has_drawn: false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_drawn(&mut self) {
|
||||
self.has_drawn = true;
|
||||
}
|
||||
|
||||
pub fn has_drawn(&mut self) -> bool {
|
||||
self.has_drawn
|
||||
}
|
||||
|
||||
pub fn tick(&mut self) {
|
||||
self.length -= 1;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue