Further massive amounts of work
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
use crate::dynamic_data::script_handling::script::Script;
|
||||
use crate::dynamic_data::script_handling::script_set::ScriptSet;
|
||||
use std::sync::Weak;
|
||||
|
||||
pub mod script;
|
||||
pub mod script_set;
|
||||
pub mod volatile_scripts;
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! script_hook {
|
||||
@@ -24,20 +26,20 @@ pub trait ScriptSource {
|
||||
fn get_script_count(&self);
|
||||
}
|
||||
|
||||
pub enum ScriptWrapper<'a> {
|
||||
Script(&'a Box<dyn Script>),
|
||||
Set(&'a ScriptSet),
|
||||
pub enum ScriptWrapper {
|
||||
Script(Weak<Box<dyn Script>>),
|
||||
Set(Weak<ScriptSet>),
|
||||
}
|
||||
|
||||
pub struct ScriptAggregator<'a> {
|
||||
scripts: Vec<Option<ScriptWrapper<'a>>>,
|
||||
pub struct ScriptAggregator {
|
||||
scripts: Vec<Option<ScriptWrapper>>,
|
||||
size: i32,
|
||||
index: i32,
|
||||
set_index: i32,
|
||||
}
|
||||
|
||||
impl<'a> ScriptAggregator<'a> {
|
||||
pub fn new(scripts: Vec<Option<ScriptWrapper<'a>>>) -> Self {
|
||||
impl ScriptAggregator {
|
||||
pub fn new(scripts: Vec<Option<ScriptWrapper>>) -> Self {
|
||||
let len = scripts.len();
|
||||
Self {
|
||||
scripts,
|
||||
@@ -51,11 +53,13 @@ impl<'a> ScriptAggregator<'a> {
|
||||
if self.index != -1 {
|
||||
if let Some(wrapper) = &self.scripts[self.index as usize] {
|
||||
if let ScriptWrapper::Set(set) = wrapper {
|
||||
self.set_index += 1;
|
||||
if self.set_index as usize >= set.count() {
|
||||
self.set_index = -1;
|
||||
} else {
|
||||
return true;
|
||||
if let Some(set) = set.upgrade() {
|
||||
self.set_index += 1;
|
||||
if self.set_index as usize >= set.count() {
|
||||
self.set_index = -1;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -64,10 +68,16 @@ impl<'a> ScriptAggregator<'a> {
|
||||
for index in self.index..self.size {
|
||||
self.index = index;
|
||||
if let Some(wrapper) = &self.scripts[index as usize] {
|
||||
if let ScriptWrapper::Set(..) = wrapper {
|
||||
self.set_index = 0;
|
||||
if let ScriptWrapper::Set(s) = wrapper {
|
||||
if let Some(..) = s.upgrade() {
|
||||
self.set_index = 0;
|
||||
return true;
|
||||
}
|
||||
} else if let ScriptWrapper::Script(script) = wrapper {
|
||||
if let Some(..) = script.upgrade() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,8 +89,13 @@ impl<'a> ScriptAggregator<'a> {
|
||||
return None;
|
||||
}
|
||||
return match self.scripts[self.index as usize].as_ref().unwrap() {
|
||||
ScriptWrapper::Script(script) => Some(script),
|
||||
ScriptWrapper::Set(set) => Some(set.at(self.set_index as usize)),
|
||||
// We can make this unsafe as we know there is a strong reference. This is validated in
|
||||
// increment_to_next_value
|
||||
ScriptWrapper::Script(script) => unsafe { Some(&*script.as_ptr()) },
|
||||
ScriptWrapper::Set(set) => unsafe {
|
||||
let r = (&*set.as_ptr()).at(self.set_index as usize);
|
||||
Some(r.as_ref())
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user