Skip to content

Commit

Permalink
Rusterix integration WiP
Browse files Browse the repository at this point in the history
  • Loading branch information
markusmoenig committed Dec 17, 2024
1 parent 5b86330 commit 3fb05a6
Show file tree
Hide file tree
Showing 20 changed files with 232 additions and 969 deletions.
91 changes: 83 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion StarterProject.eldiron

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions creator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ self_update = { version = "0.39.0", features = [
"archive-tar",
"compression-flate2",
] }
vek = { version = "0.17.1", default-features = true }

[package.metadata.bundle]
name = "Eldiron"
Expand Down
4 changes: 4 additions & 0 deletions creator/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1511,6 +1511,10 @@ impl TheTrait for Editor {
{
self.server.update_region(region);
}
ctx.ui.send(TheEvent::Custom(
TheId::named("Update Minimap"),
TheValue::Empty,
));
} else if manager.context == UndoManagerContext::MaterialFX {
if id.name == "Undo" {
manager.undo(
Expand Down
3 changes: 2 additions & 1 deletion creator/src/mapeditor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use crate::editor::{CODEEDITOR, MAPRENDER, TILEDRAWER, UNDOMANAGER};
use crate::prelude::*;
use vek::Vec2;

#[derive(PartialEq, Clone, Copy, Debug)]
pub enum EditorDrawMode {
Expand Down Expand Up @@ -275,7 +276,7 @@ impl MapEditor {
region.map.grid_size += coord.y as f32;
region.map.grid_size = clamp(region.map.grid_size, 5.0, 100.0);
} else {
region.map.offset += Vec2f::new(-coord.x as f32, coord.y as f32);
region.map.offset += Vec2::new(-coord.x as f32, coord.y as f32);
}
region.editing_position_3d.x += coord.x as f32 / region.map.grid_size;
region.editing_position_3d.z += coord.y as f32 / region.map.grid_size;
Expand Down
39 changes: 38 additions & 1 deletion creator/src/materialeditor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ impl MaterialEditor {
// ui.set_node_canvas("Map NodeCanvas", node_canvas);
// }
if let Some(map) = project.get_map_mut(server_ctx) {
let prev = map.clone();

match server_ctx.curr_texture_mode {
MapTextureMode::Floor => {
for sector_id in &map.selected_sectors.clone() {
Expand All @@ -121,7 +123,27 @@ impl MaterialEditor {
}
}
}
MapTextureMode::Wall => {}
MapTextureMode::Wall => {
let mut linedef_ids = Vec::new();
for sector_id in &map.selected_sectors {
if let Some(sector) = map.find_sector(*sector_id) {
linedef_ids.extend(&sector.linedefs);
}
}

for linedef_id in &map.selected_linedefs {
if !linedef_ids.contains(linedef_id) {
linedef_ids.push(*linedef_id);
}
}

for linedef_id in linedef_ids {
if let Some(linedef) = map.find_linedef_mut(linedef_id) {
linedef.material = Some(index);
linedef.texture = None;
}
}
}
MapTextureMode::Ceiling => {
for sector_id in &map.selected_sectors.clone() {
if let Some(sector) = map.find_sector_mut(*sector_id) {
Expand All @@ -132,6 +154,21 @@ impl MaterialEditor {
}
_ => {}
}

let undo =
RegionUndoAtom::MapEdit(Box::new(prev), Box::new(map.clone()));

UNDOMANAGER.lock().unwrap().add_region_undo(
&server_ctx.curr_region,
undo,
ctx,
);

ctx.ui.send(TheEvent::Custom(
TheId::named("Update Minimap"),
TheValue::Empty,
));

self.set_material_selection(ui, ctx, project, server_ctx, Some(index));
}
}
Expand Down
5 changes: 2 additions & 3 deletions creator/src/minimap.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use shared::server::prelude::MapToolType;

use crate::editor::MAPRENDER;
use crate::prelude::*;
use vek::Vec2;

pub fn draw_minimap(orig_region: &Region, buffer: &mut TheRGBABuffer) {
// let background = *ui
Expand Down Expand Up @@ -45,7 +44,7 @@ pub fn draw_minimap(orig_region: &Region, buffer: &mut TheRGBABuffer) {
// Compute the offset to center the map
region.map.offset.x = -bbox_center_x * region.map.grid_size;
region.map.offset.y = bbox_center_y * region.map.grid_size;
region.map.camera_xz = Some(vec2f(
region.map.camera_xz = Some(Vec2::new(
region.editing_position_3d.x,
region.editing_position_3d.z,
));
Expand Down
12 changes: 7 additions & 5 deletions creator/src/tools/linedef.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::prelude::*;
use shared::server::prelude::MapToolType;
use vek::Vec2;
use MapEvent::*;
use ToolEvent::*;

Expand Down Expand Up @@ -268,7 +268,7 @@ impl Tool for LinedefTool {
}

if set_current_gid_pos {
map.curr_grid_pos = Some(grid_pos);
map.curr_grid_pos = Some(vek::Vec2::new(grid_pos.x, grid_pos.y));
}
}
}
Expand Down Expand Up @@ -362,8 +362,10 @@ impl Tool for LinedefTool {

*map = self.rectangle_undo_map.clone();
map.curr_grid_pos = None;
map.curr_rectangle =
Some((self.click_pos, vec2f(coord.x as f32, coord.y as f32)));
map.curr_rectangle = Some((
Vec2::new(self.click_pos.x, self.click_pos.y),
Vec2::new(coord.x as f32, coord.y as f32),
));

if ui.shift {
// Add
Expand Down Expand Up @@ -410,7 +412,7 @@ impl Tool for LinedefTool {
if let Some(render_view) = ui.get_render_view("PolyView") {
let dim = *render_view.dim();
if !self.rectangle_mode {
map.curr_mouse_pos = Some(vec2f(coord.x as f32, coord.y as f32));
map.curr_mouse_pos = Some(Vec2::new(coord.x as f32, coord.y as f32));
}
let mut hover = server_ctx.geometry_at(
vec2f(dim.width as f32, dim.height as f32),
Expand Down
9 changes: 5 additions & 4 deletions creator/src/tools/sector.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::prelude::*;
use shared::server::prelude::MapToolType;
use vek::Vec2;
use MapEvent::*;
use ToolEvent::*;

Expand Down Expand Up @@ -247,9 +247,10 @@ impl Tool for SectorTool {
selection.1 = vec![];

*map = self.rectangle_undo_map.clone();
map.curr_rectangle =
Some((self.click_pos, vec2f(coord.x as f32, coord.y as f32)));

map.curr_rectangle = Some((
Vec2::new(self.click_pos.x, self.click_pos.y),
Vec2::new(coord.x as f32, coord.y as f32),
));
if ui.shift {
// Add
map.add_to_selection(selection.0, selection.1, selection.2);
Expand Down
7 changes: 4 additions & 3 deletions creator/src/tools/selection.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::prelude::*;
use shared::server::prelude::MapToolType;
use MapEvent::*;
use ToolEvent::*;

Expand Down Expand Up @@ -317,8 +316,10 @@ impl Tool for SelectionTool {
let selection = server_ctx.geometry_in_rectangle(top_left, bottom_right, map);

*map = self.rectangle_undo_map.clone();
map.curr_rectangle =
Some((self.click_pos, vec2f(coord.x as f32, coord.y as f32)));
map.curr_rectangle = Some((
vek::Vec2::new(self.click_pos.x, self.click_pos.y),
vek::Vec2::new(coord.x as f32, coord.y as f32),
));

if ui.shift {
// Add
Expand Down
7 changes: 4 additions & 3 deletions creator/src/tools/vertex.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::prelude::*;
use shared::server::prelude::MapToolType;
use MapEvent::*;
use ToolEvent::*;

Expand Down Expand Up @@ -208,8 +207,10 @@ impl Tool for VertexTool {
selection.2 = vec![];

*map = self.rectangle_undo_map.clone();
map.curr_rectangle =
Some((self.click_pos, vec2f(coord.x as f32, coord.y as f32)));
map.curr_rectangle = Some((
vek::Vec2::new(self.click_pos.x, self.click_pos.y),
vek::Vec2::new(coord.x as f32, coord.y as f32),
));

if ui.shift {
// Add
Expand Down
3 changes: 3 additions & 0 deletions shared/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ noiselib = "0.2.3"
regex = "1"
num_cpus = "1.16.0"
half = { version = "2.4", features = ["serde"] }
# rusterix = "0.1.0"
#rusterix = { path = "../../rusterix" }
rusterix = { git = "https://github.com/markusmoenig/Rusterix" }

vek = { version = "0.17", default-features = false, features = ["rgba"] }
euc = { git = "https://github.com/zesterer/euc" }
Expand Down
Loading

0 comments on commit 3fb05a6

Please sign in to comment.