1
0
Fork 0
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:
jugeeya 2023-09-11 21:14:22 -07:00 committed by GitHub
parent 427609ba8e
commit 267cb0c310
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 43 additions and 31 deletions

View file

@ -66,6 +66,7 @@ pub static OVERALL_FRAME_COUNTER: Lazy<usize> =
Lazy::new(|| frame_counter::register_counter(frame_counter::FrameCounterType::InGameNoReset)); Lazy::new(|| frame_counter::register_counter(frame_counter::FrameCounterType::InGameNoReset));
pub const NUM_LOGS: usize = 10; pub const NUM_LOGS: usize = 10;
pub static mut DRAW_LOG_BASE_IDX: Lazy<usize> = Lazy::new(|| 0);
#[derive(PartialEq, Eq, Debug, Copy, Clone)] #[derive(PartialEq, Eq, Debug, Copy, Clone)]
pub enum DirectionStrength { pub enum DirectionStrength {
@ -280,8 +281,6 @@ fn insert_in_front<T>(array: &mut [T], value: T) {
lazy_static! { lazy_static! {
pub static ref P1_INPUT_LOGS: Mutex<[InputLog; NUM_LOGS]> = pub static ref P1_INPUT_LOGS: Mutex<[InputLog; NUM_LOGS]> =
Mutex::new([InputLog::default(); 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( pub fn handle_final_input_mapping(
@ -332,6 +331,7 @@ pub fn handle_final_input_mapping(
// We should count this frame already // We should count this frame already
frame_counter::tick_idx(*PER_LOG_FRAME_COUNTER); frame_counter::tick_idx(*PER_LOG_FRAME_COUNTER);
insert_in_front(input_logs, potential_input_log); insert_in_front(input_logs, potential_input_log);
*DRAW_LOG_BASE_IDX = (*DRAW_LOG_BASE_IDX + 1) % NUM_LOGS;
} else if is_new_frame { } else if is_new_frame {
*latest_input_log = potential_input_log; *latest_input_log = potential_input_log;
latest_input_log.frames = std::cmp::min(current_frame, 99); latest_input_log.frames = std::cmp::min(current_frame, 99);
@ -339,7 +339,7 @@ pub fn handle_final_input_mapping(
} }
// Decrease TTL // 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 { if input_log.ttl > 0 && is_new_frame {
input_log.ttl -= 1; input_log.ttl -= 1;
} }

View file

@ -25,7 +25,7 @@ pub unsafe fn draw(root_pane: &Pane) {
let notification_idx = 0; let notification_idx = 0;
let queue = &mut ui::notifications::QUEUE; let queue = &mut ui::notifications::QUEUE;
let notification = queue.first(); let notification = queue.first_mut();
root_pane root_pane
.find_pane_by_name_recursive(display_parent_fmt!(notification_idx)) .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 notification = notification.unwrap();
let color = notification.color; let color = notification.color;
root_pane if !notification.has_drawn() {
.find_pane_by_name_recursive(display_header_fmt!(notification_idx)) notification.set_drawn();
.unwrap() root_pane
.as_textbox() .find_pane_by_name_recursive(display_header_fmt!(notification_idx))
.set_text_string(&notification.header); .unwrap()
.as_textbox()
.set_text_string(&notification.header);
let text = root_pane let text = root_pane
.find_pane_by_name_recursive(display_txt_fmt!(notification_idx)) .find_pane_by_name_recursive(display_txt_fmt!(notification_idx))
.unwrap() .unwrap()
.as_textbox(); .as_textbox();
text.set_text_string(&notification.message); text.set_text_string(&notification.message);
text.set_default_material_colors(); text.set_default_material_colors();
text.set_color(color.r, color.g, color.b, color.a); text.set_color(color.r, color.g, color.b, color.a);
}
let notification = queue.first_mut().unwrap();
let has_completed = notification.check_completed(); let has_completed = notification.check_completed();
if has_completed { if has_completed {
queue.remove(0); queue.remove(0);

View file

@ -7,7 +7,9 @@ use training_mod_consts::{InputDisplay, MENU};
use crate::{ use crate::{
common::{consts::status_display_name, menu::QUICK_MENU_ACTIVE}, common::{consts::status_display_name, menu::QUICK_MENU_ACTIVE},
training::{ 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}, ui::{fade_out, menu::VANILLA_MENU_ACTIVE},
}, },
}; };
@ -66,11 +68,13 @@ fn get_input_icons(log: &InputLog) -> VecDeque<(&str, ResColor)> {
icons 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 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(); .unwrap();
// Handle visibility and alpha
log_pane.set_visible( log_pane.set_visible(
!QUICK_MENU_ACTIVE && !VANILLA_MENU_ACTIVE && MENU.input_display != InputDisplay::None, !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; const FADE_FRAMES: u32 = 200;
fade_out(log_pane, log.ttl, FADE_FRAMES); fade_out(log_pane, log.ttl, FADE_FRAMES);
// Don't redraw // Handle positioning
if *log == *drawn_log { 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; return;
} else {
*drawn_log = *log;
} }
let icons = get_input_icons(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.set_visible(true);
(*icon_pane.material).set_black_res_color(*icon_color); (*icon_pane.material).set_black_res_color(*icon_color);
icon_pane.flags |= PaneFlag::IsGlobalMatrixDirty as u8;
} }
let frame_text = format!("{}", log.frames); let frame_text = format!("{}", log.frames);
@ -178,13 +183,8 @@ pub unsafe fn draw(root_pane: &Pane) {
return; return;
} }
let logs = &*logs_ptr; 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() { 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);
} }
} }

View file

@ -8,6 +8,7 @@ pub struct Notification {
pub message: String, pub message: String,
length: u32, length: u32,
pub color: ResColor, pub color: ResColor,
has_drawn: bool,
} }
impl Notification { impl Notification {
@ -17,9 +18,18 @@ impl Notification {
message, message,
length, length,
color, 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) { pub fn tick(&mut self) {
self.length -= 1; self.length -= 1;
} }