Skip to content

Commit

Permalink
Refactoring away from math-rs
Browse files Browse the repository at this point in the history
  • Loading branch information
markusmoenig committed Dec 25, 2024
1 parent 76cfb42 commit 7289e1c
Show file tree
Hide file tree
Showing 58 changed files with 2,829 additions and 1,686 deletions.
1,765 changes: 1,590 additions & 175 deletions Cargo.lock

Large diffs are not rendered by default.

17 changes: 7 additions & 10 deletions creator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,15 @@ name = "eldiron"
path = "src/main.rs"

[dependencies]
theframework = { git = "https://github.com/markusmoenig/TheFramework", features = [
"ui",
"code",
], default-features = true }
# theframework = { path = "../../TheFramework", features = [
# "ui",
# "code",
# "winit_app",
# ], default-features = false }
# theframework = { git = "https://github.com/markusmoenig/TheFramework", features = [
# "ui",
# "code",
# "ui",
# ], default-features = true }
theframework = { path = "../../TheFramework", features = [
"ui",
"code",
"winit_app",
], default-features = true }
# theframework = { version = "0.1.20", features = [
# "ui",
# "code",
Expand All @@ -47,6 +42,8 @@ self_update = { version = "0.39.0", features = [
"compression-flate2",
] }
vek = { version = "0.17.1", default-features = true }
rusterix = { path = "../../rusterix" }
# rusterix = { git = "https://github.com/markusmoenig/Rusterix" }

[package.metadata.bundle]
name = "Eldiron"
Expand Down
70 changes: 35 additions & 35 deletions creator/src/brushes/disc.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::prelude::*;
use rayon::prelude::*;
// use rayon::prelude::*;

pub struct DiscBrush {
id: TheId,
Expand All @@ -23,41 +23,41 @@ impl Brush for DiscBrush {
str!("Disc")
}

fn distance(&self, p: Vec2f, pos: Vec2f, settings: &BrushSettings) -> f32 {
length(p - pos) - settings.size / 2.0
fn distance(&self, p: Vec2<f32>, pos: Vec2<f32>, settings: &BrushSettings) -> f32 {
(p - pos).magnitude() - settings.size / 2.0
}

fn preview(&self, buffer: &mut TheRGBABuffer) {
fn mix_color(a: &[u8; 4], b: &[u8; 4], v: f32) -> [u8; 4] {
[
(((1.0 - v) * (a[0] as f32 / 255.0) + b[0] as f32 / 255.0 * v) * 255.0) as u8,
(((1.0 - v) * (a[1] as f32 / 255.0) + b[1] as f32 / 255.0 * v) * 255.0) as u8,
(((1.0 - v) * (a[2] as f32 / 255.0) + b[2] as f32 / 255.0 * v) * 255.0) as u8,
(((1.0 - v) * (a[3] as f32 / 255.0) + b[3] as f32 / 255.0 * v) * 255.0) as u8,
]
}

let width = buffer.dim().width as usize;
let height = buffer.dim().height;

buffer
.pixels_mut()
.par_rchunks_exact_mut(width * 4)
.enumerate()
.for_each(|(j, line)| {
for (i, pixel) in line.chunks_exact_mut(4).enumerate() {
let i = j * width + i;

let x = (i % width) as f32;
let y = (i / width) as f32;

let p = vec2f(x / width as f32, y / height as f32);
let d = length(p - vec2f(0.5, 0.5)) - 0.4;
let t = smoothstep(-0.03, 0.0, d);

let color = [209, 209, 209, 255];
pixel.copy_from_slice(&mix_color(&color, &[81, 81, 81, 255], t));
}
});
fn preview(&self, _buffer: &mut TheRGBABuffer) {
// fn mix_color(a: &[u8; 4], b: &[u8; 4], v: f32) -> [u8; 4] {
// [
// (((1.0 - v) * (a[0] as f32 / 255.0) + b[0] as f32 / 255.0 * v) * 255.0) as u8,
// (((1.0 - v) * (a[1] as f32 / 255.0) + b[1] as f32 / 255.0 * v) * 255.0) as u8,
// (((1.0 - v) * (a[2] as f32 / 255.0) + b[2] as f32 / 255.0 * v) * 255.0) as u8,
// (((1.0 - v) * (a[3] as f32 / 255.0) + b[3] as f32 / 255.0 * v) * 255.0) as u8,
// ]
// }

// let width = buffer.dim().width as usize;
// let height = buffer.dim().height;

// buffer
// .pixels_mut()
// .par_rchunks_exact_mut(width * 4)
// .enumerate()
// .for_each(|(j, line)| {
// for (i, pixel) in line.chunks_exact_mut(4).enumerate() {
// let i = j * width + i;

// let x = (i % width) as f32;
// let y = (i / width) as f32;

// // let p = Vec2::new(x / width as f32, y / height as f32);
// // let d = length(p - Vec2::new(0.5, 0.5)) - 0.4;
// let t = 0.5; //smoothstep(-0.03, 0.0, d);

// let color = [209, 209, 209, 255];
// pixel.copy_from_slice(&mix_color(&color, &[81, 81, 81, 255], t));
// }
// });
}
}
2 changes: 1 addition & 1 deletion creator/src/brushes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub trait Brush: Send + Sync {
fn id(&self) -> TheId;
fn info(&self) -> String;

fn distance(&self, p: Vec2f, pos: Vec2f, settings: &BrushSettings) -> f32;
fn distance(&self, p: Vec2<f32>, pos: Vec2<f32>, settings: &BrushSettings) -> f32;

fn preview(&self, buffer: &mut TheRGBABuffer);
}
61 changes: 31 additions & 30 deletions creator/src/brushes/rect.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::prelude::*;
use rayon::prelude::*;
// use rayon::prelude::*;

pub struct RectBrush {
id: TheId,
Expand All @@ -23,41 +23,42 @@ impl Brush for RectBrush {
str!("Rectangle")
}

fn distance(&self, p: Vec2f, pos: Vec2f, settings: &BrushSettings) -> f32 {
sdf_box2d(p, pos, settings.size / 2.0, settings.size / 2.0)
fn distance(&self, _p: Vec2<f32>, _pos: Vec2<f32>, _settings: &BrushSettings) -> f32 {
//sdf_box2d(p, pos, settings.size / 2.0, settings.size / 2.0)
1.0
}

fn preview(&self, buffer: &mut TheRGBABuffer) {
fn mix_color(a: &[u8; 4], b: &[u8; 4], v: f32) -> [u8; 4] {
[
(((1.0 - v) * (a[0] as f32 / 255.0) + b[0] as f32 / 255.0 * v) * 255.0) as u8,
(((1.0 - v) * (a[1] as f32 / 255.0) + b[1] as f32 / 255.0 * v) * 255.0) as u8,
(((1.0 - v) * (a[2] as f32 / 255.0) + b[2] as f32 / 255.0 * v) * 255.0) as u8,
(((1.0 - v) * (a[3] as f32 / 255.0) + b[3] as f32 / 255.0 * v) * 255.0) as u8,
]
}
fn preview(&self, _buffer: &mut TheRGBABuffer) {
// fn mix_color(a: &[u8; 4], b: &[u8; 4], v: f32) -> [u8; 4] {
// [
// (((1.0 - v) * (a[0] as f32 / 255.0) + b[0] as f32 / 255.0 * v) * 255.0) as u8,
// (((1.0 - v) * (a[1] as f32 / 255.0) + b[1] as f32 / 255.0 * v) * 255.0) as u8,
// (((1.0 - v) * (a[2] as f32 / 255.0) + b[2] as f32 / 255.0 * v) * 255.0) as u8,
// (((1.0 - v) * (a[3] as f32 / 255.0) + b[3] as f32 / 255.0 * v) * 255.0) as u8,
// ]
// }

let width = buffer.dim().width as usize;
let height = buffer.dim().height;
// let width = buffer.dim().width as usize;
// let height = buffer.dim().height;

buffer
.pixels_mut()
.par_rchunks_exact_mut(width * 4)
.enumerate()
.for_each(|(j, line)| {
for (i, pixel) in line.chunks_exact_mut(4).enumerate() {
let i = j * width + i;
// buffer
// .pixels_mut()
// .par_rchunks_exact_mut(width * 4)
// .enumerate()
// .for_each(|(j, line)| {
// for (i, pixel) in line.chunks_exact_mut(4).enumerate() {
// let i = j * width + i;

let x = (i % width) as f32;
let y = (i / width) as f32;
// let x = (i % width) as f32;
// let y = (i / width) as f32;

let p = vec2f(x / width as f32, y / height as f32);
let d = sdf_box2d(p, vec2f(0.5, 0.5), 0.4, 0.4);
let t = smoothstep(-0.01, 0.0, d);
// let p = vec2f(x / width as f32, y / height as f32);
// let d = sdf_box2d(p, vec2f(0.5, 0.5), 0.4, 0.4);
// let t = smoothstep(-0.01, 0.0, d);

let color = [209, 209, 209, 255];
pixel.copy_from_slice(&mix_color(&color, &[81, 81, 81, 255], t));
}
});
// let color = [209, 209, 209, 255];
// pixel.copy_from_slice(&mix_color(&color, &[81, 81, 81, 255], t));
// }
// });
}
}
59 changes: 30 additions & 29 deletions creator/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ lazy_static! {
pub static ref TOOLLIST: Mutex<ToolList> = Mutex::new(ToolList::default());
pub static ref BRUSHLIST: Mutex<BrushList> = Mutex::new(BrushList::default());
pub static ref PANELS: Mutex<Panels> = Mutex::new(Panels::new());
pub static ref MODELEDITOR: Mutex<ModelEditor> = Mutex::new(ModelEditor::new());
// pub static ref MODELEDITOR: Mutex<ModelEditor> = Mutex::new(ModelEditor::new());
pub static ref MATERIALEDITOR: Mutex<MaterialEditor> = Mutex::new(MaterialEditor::new());
pub static ref TEXTEDITOR: Mutex<TextEditor> = Mutex::new(TextEditor::new());
pub static ref TEXTURES: Mutex<FxHashMap<Uuid, TheRGBATile>> = Mutex::new(FxHashMap::default());
pub static ref PALETTE: Mutex<ThePalette> = Mutex::new(ThePalette::default());
}
Expand Down Expand Up @@ -218,7 +219,7 @@ impl TheTrait for Editor {
edit_menu.add(TheContextMenuItem::new_with_accel(
str!("Paste"),
TheId::named("Paste"),
TheAccelerator::new(TheAcceleratorKey::CTRLCMD, 'p'),
TheAccelerator::new(TheAcceleratorKey::CTRLCMD, 'v'),
));
let mut view_menu = TheContextMenu::named(str!("View"));
view_menu.add(TheContextMenuItem::new_with_accel(
Expand Down Expand Up @@ -278,7 +279,7 @@ impl TheTrait for Editor {
let mut save_as_button = TheMenubarButton::new(TheId::named("Save As"));
save_as_button.set_icon_name("icon_role_save_as".to_string());
save_as_button.set_status_text("Save the current project to a new file.");
save_as_button.set_icon_offset(vec2i(2, -5));
save_as_button.set_icon_offset(Vec2::new(2, -5));

let mut undo_button = TheMenubarButton::new(TheId::named("Undo"));
undo_button.set_status_text("Undo the last action.");
Expand Down Expand Up @@ -314,11 +315,11 @@ impl TheTrait for Editor {
patreon_button.set_status_text("Visit my Patreon page.");
patreon_button.set_icon_name("patreon".to_string());
// patreon_button.set_fixed_size(vec2i(36, 36));
patreon_button.set_icon_offset(vec2i(-4, -2));
patreon_button.set_icon_offset(Vec2::new(-4, -2));

let mut hlayout = TheHLayout::new(TheId::named("Menu Layout"));
hlayout.set_background_color(None);
hlayout.set_margin(vec4i(10, 2, 10, 1));
hlayout.set_margin(Vec4::new(10, 2, 10, 1));
hlayout.add_widget(Box::new(logo_button));
hlayout.add_widget(Box::new(TheMenubarSeparator::new(TheId::empty())));
hlayout.add_widget(Box::new(open_button));
Expand Down Expand Up @@ -404,7 +405,7 @@ impl TheTrait for Editor {

let mut v_tool_list_layout = TheVLayout::new(TheId::named("Tool List Layout"));
v_tool_list_layout.limiter_mut().set_max_width(51);
v_tool_list_layout.set_margin(vec4i(2, 2, 2, 2));
v_tool_list_layout.set_margin(Vec4::new(2, 2, 2, 2));
v_tool_list_layout.set_padding(1);

TOOLLIST.lock().unwrap().set_active_editor(
Expand Down Expand Up @@ -746,16 +747,16 @@ impl TheTrait for Editor {
) {
redraw = true;
}
if MODELEDITOR.lock().unwrap().handle_event(
&event,
ui,
ctx,
&mut self.project,
&mut self.server,
&mut self.server_ctx,
) {
redraw = true;
}
// if MODELEDITOR.lock().unwrap().handle_event(
// &event,
// ui,
// ctx,
// &mut self.project,
// &mut self.server,
// &mut self.server_ctx,
// ) {
// redraw = true;
// }
if TILEMAPEDITOR.lock().unwrap().handle_event(
&event,
ui,
Expand Down Expand Up @@ -1003,7 +1004,7 @@ impl TheTrait for Editor {
);
init.insert_atom(
(2, 0),
TheCodeAtom::Value(TheValue::Position(vec3f(
TheCodeAtom::Value(TheValue::Position(Vec3::new(
location.x as f32,
0.0,
location.y as f32,
Expand Down Expand Up @@ -1105,7 +1106,7 @@ impl TheTrait for Editor {
);
init.insert_atom(
(2, 0),
TheCodeAtom::Value(TheValue::Position(vec3f(
TheCodeAtom::Value(TheValue::Position(Vec3::new(
location.x as f32,
0.0,
location.y as f32,
Expand Down Expand Up @@ -1231,16 +1232,16 @@ impl TheTrait for Editor {
self.project = project;

// Update geo_obj parameters if necessary
for r in &mut self.project.regions {
for geo_obj in r.geometry.values_mut() {
geo_obj.update_parameters();
// for r in &mut self.project.regions {
// for geo_obj in r.geometry.values_mut() {
// geo_obj.update_parameters();

r.regionfx.update_parameters();
}
// r.heightmap.material_mask.clear();
//
r.update_geometry_areas();
}
// r.regionfx.update_parameters();
// }
// // r.heightmap.material_mask.clear();
// //
// r.update_geometry_areas();
// }

// Update mat_obj parameters if necessary
for mat_obj in &mut self.project.materials.values_mut() {
Expand Down Expand Up @@ -1629,7 +1630,7 @@ impl TheTrait for Editor {
let height = 100;

let mut canvas = TheCanvas::new();
canvas.limiter_mut().set_max_size(vec2i(width, height));
canvas.limiter_mut().set_max_size(Vec2::new(width, height));

let mut hlayout: TheHLayout = TheHLayout::new(TheId::empty());
hlayout.limiter_mut().set_max_width(width);
Expand Down Expand Up @@ -1664,7 +1665,7 @@ impl TheTrait for Editor {
let height = 100;

let mut canvas = TheCanvas::new();
canvas.limiter_mut().set_max_size(vec2i(width, height));
canvas.limiter_mut().set_max_size(Vec2::new(width, height));

let mut hlayout: TheHLayout = TheHLayout::new(TheId::empty());
hlayout.limiter_mut().set_max_width(width);
Expand Down
12 changes: 6 additions & 6 deletions creator/src/externals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub fn set_server_externals() {
"Move".to_string(),
"Moves the character in the specified direction.".to_string(),
vec!["By".to_string()],
vec![TheValue::Float2(vec2f(0.0, 0.0))],
vec![TheValue::Float2(Vec2::new(0.0, 0.0))],
Some(TheValue::Bool(false)),
));

Expand Down Expand Up @@ -113,7 +113,7 @@ pub fn set_server_externals() {
"Applies an effect on the wall at the given position.".to_string(),
vec!["Position".to_string(), "FX".to_string()],
vec![
TheValue::Position(vec3f(0.0, 0.0, 0.0)),
TheValue::Position(Vec3::new(0.0, 0.0, 0.0)),
TheValue::TextList(
0,
vec![
Expand Down Expand Up @@ -184,8 +184,8 @@ pub fn set_client_externals() {
],
vec![
TheValue::Text("name".to_string()),
TheValue::Int2(vec2i(0, 0)),
TheValue::Int2(vec2i(100, 100)),
TheValue::Int2(Vec2::new(0, 0)),
TheValue::Int2(Vec2::new(100, 100)),
],
Some(TheValue::Image(TheRGBABuffer::default())),
));
Expand Down Expand Up @@ -222,7 +222,7 @@ pub fn set_client_externals() {
vec!["Image".to_string(), "Position".to_string()],
vec![
TheValue::Image(TheRGBABuffer::default()),
TheValue::Int2(vec2i(0, 0)),
TheValue::Int2(Vec2::new(0, 0)),
],
None,
));
Expand All @@ -241,7 +241,7 @@ pub fn set_client_externals() {
vec!["Image".to_string(), "Size".to_string()],
vec![
TheValue::Image(TheRGBABuffer::default()),
TheValue::Int2(vec2i(0, 0)),
TheValue::Int2(Vec2::new(0, 0)),
],
Some(TheValue::Image(TheRGBABuffer::default())),
));
Expand Down
Loading

0 comments on commit 7289e1c

Please sign in to comment.