Proper error handling

This commit is contained in:
Michael Mikovsky
2025-07-30 14:39:41 -06:00
parent 309c94dec6
commit 6093c32245
6 changed files with 26 additions and 124 deletions
+3 -6
View File
@@ -1,5 +1,4 @@
local screen_size = {1920, 1080};
local screen_size = { 1920, 1080 };
local scale = 300;
local length_seconds = 10;
@@ -63,7 +62,7 @@ function renderLine(pos, line)
local p1r = rotatePoint(p1, { pos[1], pos[2], pos[3] });
local p2r = rotatePoint(p2, { pos[1], pos[2], pos[3] });
local p1s = Point((scale * p1r[1]) + (screen_size[1] / 2), (scale * p1r[2]) + (screen_size[2]/ 2))
local p1s = Point((scale * p1r[1]) + (screen_size[1] / 2), (scale * p1r[2]) + (screen_size[2] / 2))
local p2s = Point((scale * p2r[1]) + (screen_size[1] / 2), (scale * p2r[2]) + (screen_size[2] / 2))
return Line(p1s, p2s, Color(255, 255, 255), 2.0)
@@ -82,14 +81,12 @@ for i = 0, updates, 1 do
animate(Animation(
renderLine(pos, line),
renderLine(nextpos, line),
spf, EaseInOut()
spf, Linear()
))
end
pos = nextpos;
print(pos[1])
render(spf)
end
+4 -1
View File
@@ -3,6 +3,10 @@ config:set_background_color(Color(20, 20, 30))
config:set_fps(60)
config:set_num_layers(5)
-- test(function(i)
-- return i
-- end)
layer(0)
draw(Rect(Point(100, 100), Size(200, 150), Color(255, 100, 100, 255)))
layer(1)
@@ -23,7 +27,6 @@ animate(Animation(
layer(2)
animate(Animation(
CircleOutline(
Point(400.0, 300.0),
+17 -1
View File
@@ -57,8 +57,9 @@ impl LuaDecoder {
Self::add_func(&lua, &renderer, "draw", Self::draw)?;
Self::add_func(&lua, &renderer, "animate", Self::animate)?;
Self::add_func(&lua, &renderer, "render", Self::render)?;
// Self::add_func(&lua, &renderer, "test", Self::test)?;
lua.exec(std::io::read_to_string(file)?)?;
handle_lua_error(lua.exec(std::io::read_to_string(file)?))?;
Ok((
renderer.lock().unwrap().tasks.clone(),
@@ -99,4 +100,19 @@ impl LuaDecoder {
fn render(this: &Arc<Mutex<Self>>, duration: f64) {
this.lock().unwrap().tasks.push(Task::RenderScene(duration));
}
// fn test(this: &Arc<Mutex<Self>>, func: mlua::Function) {
// let a: i32 = func.call(()).unwrap();
// println!(" Got: {:?}", a);
// }
}
fn handle_lua_error(err: mlua::Result<()>) -> crate::Result<()> {
match err {
Ok(_) => Ok(()),
Err(err) => {
println!("{}", err);
Err("Error parsing file".into())
}
}
}
+2 -3
View File
@@ -22,8 +22,7 @@ impl LuaEnv {
Ok(())
}
pub fn exec(&self, script: String) -> crate::Result<()> {
self.lua.load(script).exec()?;
Ok(())
pub fn exec(&self, script: String) -> mlua::Result<()> {
self.lua.load(script).eval::<()>()
}
}
-112
View File
@@ -1,112 +0,0 @@
mod renderer;
use renderer::prelude::*;
// Add these to Cargo.toml:
// [dependencies]
// image = "0.24"
// imageproc = "0.23"
// gstreamer = "0.21"
// gstreamer-app = "0.21"
// Configuration struct for rendering settings
// Color representation
// Easing functions for animations
// Animation structure
// Drawable item that exists on a layer
// Scene represents a collection of drawables and animations for a duration
pub fn create_example_video() -> Vec<Task> {
vec![
Task::SetConfig(Config {
width: 800,
height: 600,
background_color: Color::new(20, 20, 30, 255),
fps: 30.0,
num_layers: 5,
}),
Task::MoveToLayer(0),
Task::Draw(Element::Rectangle(RectangleElement::new(
Point::new(100.0, 100.0),
Size::new(200.0, 150.0),
Color::new(255, 100, 100, 255),
true,
0.0,
))),
Task::MoveToLayer(1),
Task::Draw(Element::Circle(CircleElement::new(
Point::new(400.0, 300.0),
50.0,
Color::new(100, 255, 100, 255),
false,
3.0,
))),
Task::Draw(Element::Line(LineElement::new(
Point::new(50.0, 50.0),
Point::new(750.0, 550.0),
Color::new(255, 255, 100, 255),
5.0,
))),
Task::RenderScene(5.0),
Task::MoveToLayer(0),
Task::Animate(Animation::new(
Element::Rectangle(RectangleElement::new(
Point::new(100.0, 100.0),
Size::new(200.0, 150.0),
Color::new(255, 100, 100, 255),
true,
0.0,
)),
Element::Rectangle(RectangleElement::new(
Point::new(500.0, 350.0),
Size::new(100.0, 100.0),
Color::new(100, 100, 255, 255),
true,
0.0,
)),
3.0,
EasingFunction::EaseInOut,
)),
Task::MoveToLayer(2),
Task::Animate(Animation::new(
Element::Circle(CircleElement::new(
Point::new(400.0, 300.0),
50.0,
Color::new(100, 255, 100, 255),
false,
3.0,
)),
Element::Circle(CircleElement::new(
Point::new(200.0, 150.0),
100.0,
Color::new(255, 150, 50, 255),
true,
0.0,
)),
3.0,
EasingFunction::Bounce,
)),
Task::RenderScene(3.0),
]
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Example usage
let mut renderer = VideoRenderer::new();
let tasks = create_example_video();
renderer.process_tasks(tasks);
let info = renderer.export_info();
println!("Video Info: {:?}", info);
// Render the complete video
renderer.render_to_video("output.mp4")?;
Ok(())
}
-1
View File
@@ -1 +0,0 @@