More removal of RwLocks and replace it with Atomics, to prevent locks.
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2022-06-18 14:17:29 +02:00
parent 59d7344729
commit c45c7538bf
15 changed files with 293 additions and 192 deletions

View File

@@ -68,14 +68,15 @@ impl<'own, 'library> Battle<'own, 'library> {
if self.has_ended() {
return Ok(());
}
let user = choice.user().read();
if !user.is_usable() {
return Ok(());
{
let user = choice.user().read();
if !user.is_usable() {
return Ok(());
}
if !user.is_on_battlefield() {
return Ok(());
}
}
if !user.is_on_battlefield() {
return Ok(());
}
if !self.can_use(&choice) {
return Ok(());
}
@@ -92,12 +93,13 @@ impl<'own, 'library> Battle<'own, 'library> {
fn execute_move_choice<'func>(&'func self, choice: &'func TurnChoice<'own, 'library>) -> PkmnResult<()> {
let choice = choice.get_move_turn_data();
let used_move = choice.used_move();
let move_data_lock = used_move.read();
let move_data = move_data_lock.move_data();
let mut move_name = move_data.name().clone();
script_hook!(change_move, choice, choice, &mut move_name);
let move_data = self.library().static_data().moves().get(&move_name).unwrap();
drop(move_data_lock);
let move_data = {
let move_data_lock = used_move;
let move_data = move_data_lock.move_data();
let mut move_name = move_data.name().clone();
script_hook!(change_move, choice, choice, &mut move_name);
self.library().static_data().moves().get(&move_name).unwrap()
};
// FIXME: also change the script on the choice if changed;
let target_type = move_data.target();
let targets = resolve_targets(choice.target_side(), choice.target_index(), target_type, self);
@@ -120,7 +122,7 @@ impl<'own, 'library> Battle<'own, 'library> {
if prevented {
return Ok(());
}
if !executing_move.chosen_move().write().try_use(1) {
if !executing_move.chosen_move().try_use(1) {
return Ok(());
}
self.event_hook().trigger(Event::MoveUse {