@ -40,12 +40,15 @@ constexpr std::array<std::pair<std::string_view, TasButton>, 20> text_to_tas_but
Tas : : Tas ( ) {
Tas : : Tas ( ) {
if ( ! Settings : : values . tas_enable ) {
if ( ! Settings : : values . tas_enable ) {
needs_reset = true ;
return ;
return ;
}
}
LoadTasFiles ( ) ;
LoadTasFiles ( ) ;
}
}
Tas : : ~ Tas ( ) = default ;
Tas : : ~ Tas ( ) {
Stop ( ) ;
} ;
void Tas : : LoadTasFiles ( ) {
void Tas : : LoadTasFiles ( ) {
script_length = 0 ;
script_length = 0 ;
@ -184,6 +187,9 @@ std::string Tas::ButtonsToString(u32 button) const {
void Tas : : UpdateThread ( ) {
void Tas : : UpdateThread ( ) {
if ( ! Settings : : values . tas_enable ) {
if ( ! Settings : : values . tas_enable ) {
if ( is_running ) {
Stop ( ) ;
}
return ;
return ;
}
}
@ -196,7 +202,11 @@ void Tas::UpdateThread() {
LoadTasFiles ( ) ;
LoadTasFiles ( ) ;
LOG_DEBUG ( Input , " tas_reset done " ) ;
LOG_DEBUG ( Input , " tas_reset done " ) ;
}
}
if ( is_running ) {
if ( ! is_running ) {
tas_data . fill ( { } ) ;
return ;
}
if ( current_command < script_length ) {
if ( current_command < script_length ) {
LOG_DEBUG ( Input , " Playing TAS {}/{} " , current_command , script_length ) ;
LOG_DEBUG ( Input , " Playing TAS {}/{} " , current_command , script_length ) ;
size_t frame = current_command + + ;
size_t frame = current_command + + ;
@ -222,9 +232,6 @@ void Tas::UpdateThread() {
SwapToStoredController ( ) ;
SwapToStoredController ( ) ;
}
}
}
}
} else {
tas_data . fill ( { } ) ;
}
LOG_DEBUG ( Input , " TAS inputs: {} " , DebugInputs ( tas_data ) ) ;
LOG_DEBUG ( Input , " TAS inputs: {} " , DebugInputs ( tas_data ) ) ;
}
}
@ -237,8 +244,8 @@ TasAnalog Tas::ReadCommandAxis(const std::string& line) const {
seglist . push_back ( segment ) ;
seglist . push_back ( segment ) ;
}
}
const float x = std : : stof ( seglist . at ( 0 ) ) / 32767.f ;
const float y = std : : stof ( seglist . at ( 1 ) ) / 32767.f ;
const float x = std : : stof ( seglist . at ( 0 ) ) / 32767.0 f ;
const float y = std : : stof ( seglist . at ( 1 ) ) / 32767.0 f ;
return { x , y } ;
return { x , y } ;
}
}
@ -293,14 +300,22 @@ std::string Tas::WriteCommandButtons(u32 data) const {
}
}
void Tas : : StartStop ( ) {
void Tas : : StartStop ( ) {
is_running = ! is_running ;
if ( ! Settings : : values . tas_enable ) {
return ;
}
if ( is_running ) {
if ( is_running ) {
SwapToTasController ( ) ;
Stop ( ) ;
} else {
} else {
SwapToStoredController ( ) ;
is_running = true ;
SwapToTasController ( ) ;
}
}
}
}
void Tas : : Stop ( ) {
is_running = false ;
SwapToStoredController ( ) ;
}
void Tas : : SwapToTasController ( ) {
void Tas : : SwapToTasController ( ) {
if ( ! Settings : : values . tas_swap_controllers ) {
if ( ! Settings : : values . tas_swap_controllers ) {
return ;
return ;
@ -315,7 +330,8 @@ void Tas::SwapToTasController() {
continue ;
continue ;
}
}
auto tas_param = Common : : ParamPackage { { " pad " , static_cast < u8 > ( index ) } } ;
Common : : ParamPackage tas_param ;
tas_param . Set ( " pad " , static_cast < u8 > ( index ) ) ;
auto button_mapping = GetButtonMappingForDevice ( tas_param ) ;
auto button_mapping = GetButtonMappingForDevice ( tas_param ) ;
auto analog_mapping = GetAnalogMappingForDevice ( tas_param ) ;
auto analog_mapping = GetAnalogMappingForDevice ( tas_param ) ;
auto & buttons = player . buttons ;
auto & buttons = player . buttons ;
@ -328,25 +344,33 @@ void Tas::SwapToTasController() {
analogs [ i ] = analog_mapping [ static_cast < Settings : : NativeAnalog : : Values > ( i ) ] . Serialize ( ) ;
analogs [ i ] = analog_mapping [ static_cast < Settings : : NativeAnalog : : Values > ( i ) ] . Serialize ( ) ;
}
}
}
}
is_old_input_saved = true ;
Settings : : values . is_device_reload_pending . store ( true ) ;
Settings : : values . is_device_reload_pending . store ( true ) ;
}
}
void Tas : : SwapToStoredController ( ) {
void Tas : : SwapToStoredController ( ) {
if ( ! Settings : : values . tas_swap_controllers ) {
if ( ! is_old_input_saved ) {
return ;
return ;
}
}
auto & players = Settings : : values . players . GetValue ( ) ;
auto & players = Settings : : values . players . GetValue ( ) ;
for ( std : : size_t index = 0 ; index < players . size ( ) ; index + + ) {
for ( std : : size_t index = 0 ; index < players . size ( ) ; index + + ) {
players [ index ] = player_mappings [ index ] ;
players [ index ] = player_mappings [ index ] ;
}
}
is_old_input_saved = false ;
Settings : : values . is_device_reload_pending . store ( true ) ;
Settings : : values . is_device_reload_pending . store ( true ) ;
}
}
void Tas : : Reset ( ) {
void Tas : : Reset ( ) {
if ( ! Settings : : values . tas_enable ) {
return ;
}
needs_reset = true ;
needs_reset = true ;
}
}
bool Tas : : Record ( ) {
bool Tas : : Record ( ) {
if ( ! Settings : : values . tas_enable ) {
return true ;
}
is_recording = ! is_recording ;
is_recording = ! is_recording ;
return is_recording ;
return is_recording ;
}
}