A lot more work on WASM script execution
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2022-09-07 18:01:26 +02:00
parent f9761f61da
commit b1890681a1
102 changed files with 748 additions and 202 deletions

50
src/dynamic_data/choices.rs Normal file → Executable file
View File

@@ -1,4 +1,4 @@
use std::cmp::Ordering;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use parking_lot::RwLock;
@@ -20,7 +20,7 @@ struct CommonChoiceData {
random_value: u32,
/// Whether or not the choice has failed. A failed choice will stop running, and execute special
/// fail handling during turn execution.
has_failed: bool,
has_failed: AtomicBool,
/// The data we can use to retrieve scripts that are affecting this choice. This will be written
/// to once: when we need to initialize it. After that, this is only used to read. To prevent a
/// read while we're writing to it, this is a RwLock.
@@ -85,13 +85,13 @@ impl TurnChoice {
/// Gets whether or not the choice has failed. If we notice this when we execute the choice, we
/// will not execute it.
pub fn has_failed(&self) -> bool {
self.choice_data().has_failed
self.choice_data().has_failed.load(Ordering::SeqCst)
}
/// Fails the choice. This will prevent it from executing and run a specific fail handling during
/// execution. Note that this can not be undone.
pub fn fail(&mut self) {
self.choice_data_mut().has_failed = true
pub fn fail(&self) {
self.choice_data().has_failed.store(true, Ordering::SeqCst)
}
/// The random value of a turn choice gets set during the start of a choice, and is used for tie
@@ -188,7 +188,7 @@ impl MoveChoice {
user,
speed: 0,
random_value: 0,
has_failed: false,
has_failed: Default::default(),
script_source_data: Default::default(),
}),
}
@@ -259,7 +259,7 @@ impl ItemChoice {
user,
speed: 0,
random_value: 0,
has_failed: false,
has_failed: Default::default(),
script_source_data: Default::default(),
}),
}
@@ -297,7 +297,7 @@ impl SwitchChoice {
user,
speed: 0,
random_value: 0,
has_failed: false,
has_failed: Default::default(),
script_source_data: Default::default(),
}),
}
@@ -335,7 +335,7 @@ impl FleeChoice {
user,
speed: 0,
random_value: 0,
has_failed: false,
has_failed: Default::default(),
script_source_data: Default::default(),
}),
}
@@ -373,7 +373,7 @@ impl PassChoice {
user,
speed: 0,
random_value: 0,
has_failed: false,
has_failed: Default::default(),
script_source_data: Default::default(),
}),
}
@@ -405,68 +405,68 @@ impl PartialEq<Self> for TurnChoice {
impl Eq for TurnChoice {}
impl PartialOrd for TurnChoice {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.cmp(other))
}
}
impl Ord for TurnChoice {
fn cmp(&self, other: &Self) -> Ordering {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
match self {
TurnChoice::Move(data) => {
if let TurnChoice::Move(other_data) = other {
let priority_compare = data.priority.cmp(&other_data.priority);
if priority_compare != Ordering::Equal {
if priority_compare != std::cmp::Ordering::Equal {
return priority_compare;
}
let speed_compare = self.speed().cmp(&other.speed());
if speed_compare != Ordering::Equal {
if speed_compare != std::cmp::Ordering::Equal {
return speed_compare;
}
return self.random_value().cmp(&other.random_value());
}
Ordering::Greater
std::cmp::Ordering::Greater
}
TurnChoice::Item { .. } => {
if let TurnChoice::Move { .. } = other {
return Ordering::Less;
return std::cmp::Ordering::Less;
}
if let TurnChoice::Item { .. } = other {
let speed_compare = self.speed().cmp(&other.speed());
if speed_compare != Ordering::Equal {
if speed_compare != std::cmp::Ordering::Equal {
return speed_compare;
}
return self.random_value().cmp(&other.random_value());
}
Ordering::Greater
std::cmp::Ordering::Greater
}
TurnChoice::Switch { .. } => {
if let TurnChoice::Move { .. } = other {
return Ordering::Less;
return std::cmp::Ordering::Less;
}
if let TurnChoice::Item { .. } = other {
return Ordering::Less;
return std::cmp::Ordering::Less;
}
if let TurnChoice::Switch { .. } = other {
let speed_compare = self.speed().cmp(&other.speed());
if speed_compare != Ordering::Equal {
if speed_compare != std::cmp::Ordering::Equal {
return speed_compare;
}
return self.random_value().cmp(&other.random_value());
}
Ordering::Greater
std::cmp::Ordering::Greater
}
TurnChoice::Flee { .. } => {
if let TurnChoice::Flee { .. } = other {
let speed_compare = self.speed().cmp(&other.speed());
if speed_compare != Ordering::Equal {
if speed_compare != std::cmp::Ordering::Equal {
return speed_compare;
}
return self.random_value().cmp(&other.random_value());
}
Ordering::Less
std::cmp::Ordering::Less
}
TurnChoice::Pass(..) => Ordering::Less,
TurnChoice::Pass(..) => std::cmp::Ordering::Less,
}
}
}