Create an early scripting engine #2

Merged
SeanOMik merged 42 commits from feature/early-scripting into main 2024-03-03 03:28:57 +00:00
2 changed files with 23 additions and 3 deletions
Showing only changes of commit 4a7cdfab80 - Show all commits

View File

@ -80,12 +80,13 @@ macro_rules! impl_fn_system_tuple {
fn execute_deferred(&mut self, world: NonNull<World>) -> anyhow::Result<()> { fn execute_deferred(&mut self, world: NonNull<World>) -> anyhow::Result<()> {
let state = self.arg_state.as_mut().expect("Somehow there was no state"); let state = self.arg_state.as_mut().expect("Somehow there was no state");
state.reverse();
$( $(
let arg_state_box = state.pop() let arg_state_box = state.pop()
.expect("Missing expected arg state"); .expect("Missing expected arg state");
let arg_state = *arg_state_box.downcast::<$name::State>() let arg_state = *arg_state_box.downcast::<$name::State>()
.unwrap(); .expect("Somehow the state cannot be downcasted from boxed Any");
$name::apply_deferred(arg_state, world); $name::apply_deferred(arg_state, world);
)+ )+

View File

@ -2,7 +2,7 @@ use std::{collections::{HashMap, VecDeque, HashSet}, ptr::NonNull};
use super::System; use super::System;
use crate::world::World; use crate::{world::World, CommandQueue, Commands};
#[derive(thiserror::Error, Debug)] #[derive(thiserror::Error, Debug)]
pub enum GraphExecutorError { pub enum GraphExecutorError {
@ -58,7 +58,7 @@ impl GraphExecutor {
} }
/// Executes the systems in the graph /// Executes the systems in the graph
pub fn execute(&mut self, world_ptr: NonNull<World>, stop_on_error: bool) -> Result<Vec<GraphExecutorError>, GraphExecutorError> { pub fn execute(&mut self, mut world_ptr: NonNull<World>, stop_on_error: bool) -> Result<Vec<GraphExecutorError>, GraphExecutorError> {
let mut stack = VecDeque::new(); let mut stack = VecDeque::new();
let mut visited = HashSet::new(); let mut visited = HashSet::new();
@ -91,6 +91,25 @@ impl GraphExecutor {
possible_errors.push(e); possible_errors.push(e);
unimplemented!("Cannot resume topological execution from error"); // TODO: resume topological execution from error unimplemented!("Cannot resume topological execution from error"); // TODO: resume topological execution from error
} }
let world = unsafe { world_ptr.as_mut() };
if let Some(mut queue) = world.try_get_resource_mut::<CommandQueue>() {
// Safety: Commands only borrows world.entities when adding commands
let world = unsafe { world_ptr.as_mut() };
let mut commands = Commands::new(&mut queue, world);
let world = unsafe { world_ptr.as_mut() };
if let Err(e) = commands.execute(world)
.map_err(|e| GraphExecutorError::Command(e)) {
if stop_on_error {
return Err(e);
}
possible_errors.push(e);
unimplemented!("Cannot resume topological execution from error"); // TODO: resume topological execution from error
}
}
} }
Ok(possible_errors) Ok(possible_errors)