Skip to content

Commit e5906d1

Browse files
committed
Get editor compiling, but without actual map rendering
1 parent 56c955c commit e5906d1

12 files changed

Lines changed: 415 additions & 506 deletions

File tree

Cargo.lock

Lines changed: 55 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ authors = ["Tad Hardesty <tad@platymuus.com>"]
1919
edition = "2021"
2020

2121
[profile.dev]
22-
opt-level = 2
22+
opt-level = 1
2323

2424
[profile.release]
2525
lto = true

crates/spaceman-dmm/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ path = "src/main.rs"
1212
dreammaker = { path = "../dreammaker" }
1313
dmm-tools = { path = "../dmm-tools", features = ["gfx_core"] }
1414
imgui = "0.12.0"
15-
imgui-sdl3-renderer = { git = "https://github.com/masonjmj/imgui-rs-sdl3-renderer" }
15+
imgui-sdl3 = "0.5.0"
1616
lodepng = "3.10.7"
1717
ndarray = "0.15.6"
1818
divrem = "1.0.0"
19-
sdl3 = "0.14.42"
19+
sdl3 = "0.16.4"
2020
serde = { version = "1.0.213", features = ["derive"] }
2121
toml = "0.5.11"
2222
petgraph = { version = "0.6.0", default-features = false }

crates/spaceman-dmm/src/config.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1+
use serde::{Deserialize, Serialize};
12
use std::path::{Path, PathBuf};
23
use std::{env, fs, io};
34

4-
use serde::{Deserialize, Serialize};
5-
65
#[derive(Serialize, Deserialize, Debug, Default)]
76
pub struct Config {
87
pub recent: Vec<PathBuf>,

crates/spaceman-dmm/src/dmi.rs

Lines changed: 65 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
//! Editor-environment specific DMI (texture) handling.
22
3+
use lodepng::{self, ColorType, Decoder, RGBA};
4+
use sdl3::gpu::{
5+
Device, Texture, TextureCreateInfo, TextureRegion, TextureTransferInfo, TextureUsage,
6+
TransferBufferUsage,
7+
};
38
use std::collections::hash_map::HashMap;
4-
use std::io;
9+
use std::io::{self, Write};
510
use std::path::{Path, PathBuf};
611
use std::sync::{Arc, RwLock};
712

8-
use lodepng::{self, ColorType, Decoder, RGBA};
9-
use sdl3::pixels::{PixelFormat, PixelFormatEnum};
10-
use sdl3::render::Texture;
11-
use sdl3::surface::Surface;
12-
13-
use crate::support::TextureCreator;
14-
1513
type Rect = (u32, u32, u32, u32);
1614

1715
pub use dreammaker::dmi::*;
@@ -25,8 +23,8 @@ pub struct IconCache {
2523
}
2624

2725
#[derive(Default)]
28-
pub struct TextureCache<'r> {
29-
textures: Vec<Option<Texture<'r>>>,
26+
pub struct TextureCache {
27+
textures: Vec<Option<Texture<'static>>>,
3028
}
3129

3230
#[derive(Default)]
@@ -86,17 +84,12 @@ impl IconCache {
8684
}*/
8785
}
8886

89-
impl<'r> TextureCache<'r> {
90-
pub fn retrieve(
91-
&mut self,
92-
factory: &'r TextureCreator,
93-
icons: &IconCache,
94-
id: usize,
95-
) -> &Texture {
87+
impl TextureCache {
88+
pub fn retrieve(&mut self, device: &Device, icons: &IconCache, id: usize) -> &Texture {
9689
if id >= self.textures.len() {
9790
self.textures.resize_with(id + 1, Default::default);
9891
}
99-
self.textures[id].get_or_insert_with(|| load_texture(factory, &icons.get_icon(id).bitmap))
92+
self.textures[id].get_or_insert_with(|| load_texture(device, &icons.get_icon(id).bitmap))
10093
}
10194

10295
pub fn clear(&mut self) {
@@ -153,10 +146,7 @@ impl IconFile {
153146
}
154147
}
155148

156-
pub fn texture_from_bytes<'r>(
157-
factory: &'r TextureCreator,
158-
bytes: &[u8],
159-
) -> io::Result<Texture<'r>> {
149+
pub fn texture_from_bytes<'r>(device: &Device, bytes: &[u8]) -> io::Result<Texture<'r>> {
160150
let mut decoder = Decoder::new();
161151
decoder.info_raw_mut().colortype = ColorType::RGBA;
162152
decoder.info_raw_mut().set_bitdepth(8);
@@ -166,33 +156,59 @@ pub fn texture_from_bytes<'r>(
166156
Ok(_) => return Err(io::Error::new(io::ErrorKind::InvalidData, "not RGBA")),
167157
Err(e) => return Err(io::Error::new(io::ErrorKind::InvalidData, e)),
168158
};
169-
Ok(load_texture(factory, &bitmap))
159+
Ok(load_texture(device, &bitmap))
170160
}
171161

172-
pub fn load_texture<'r>(
173-
factory: &'r TextureCreator,
174-
bitmap: &lodepng::Bitmap<RGBA>,
175-
) -> Texture<'r> {
176-
let width = bitmap.width;
177-
let height = bitmap.height;
178-
179-
let mut surface = Surface::new(
180-
width as u32,
181-
height as u32,
182-
PixelFormat::from(PixelFormatEnum::RGBA8888),
183-
)
184-
.expect("Surface::new");
185-
surface.with_lock_mut(|dest| {
186-
let mut dest = dest.iter_mut();
187-
for pixel in &bitmap.buffer {
188-
*dest.next().unwrap() = pixel.r;
189-
*dest.next().unwrap() = pixel.g;
190-
*dest.next().unwrap() = pixel.b;
191-
*dest.next().unwrap() = pixel.a;
192-
}
193-
});
194-
195-
factory
196-
.create_texture_from_surface(surface)
197-
.expect("create_texture_from_surface")
162+
pub fn load_texture<'r>(device: &Device, bitmap: &lodepng::Bitmap<RGBA>) -> Texture<'static> {
163+
let width = bitmap.width as u32;
164+
let height = bitmap.height as u32;
165+
166+
let texture = device
167+
.create_texture(
168+
TextureCreateInfo::new()
169+
.with_type(sdl3::gpu::TextureType::_2D)
170+
.with_format(sdl3::gpu::TextureFormat::R8g8b8a8Unorm)
171+
.with_usage(TextureUsage::SAMPLER)
172+
.with_width(width)
173+
.with_height(height)
174+
.with_layer_count_or_depth(1)
175+
.with_num_levels(1),
176+
)
177+
.expect("create_texture");
178+
179+
let transfer_buffer = device
180+
.create_transfer_buffer()
181+
.with_usage(TransferBufferUsage::UPLOAD)
182+
.with_size(width * height * 4)
183+
.build()
184+
.expect("create_transfer_buffer");
185+
186+
let mut mem = transfer_buffer.map::<u8>(device, true);
187+
let mut dest = mem.mem_mut();
188+
for pixel in &bitmap.buffer {
189+
dest.write_all(&[pixel.a, pixel.b, pixel.g, pixel.r]);
190+
}
191+
mem.unmap();
192+
193+
let source = TextureTransferInfo::new()
194+
.with_transfer_buffer(&transfer_buffer)
195+
.with_offset(0);
196+
let destination = TextureRegion::new()
197+
.with_texture(&texture)
198+
.with_width(width)
199+
.with_height(height)
200+
.with_depth(1);
201+
202+
let command_buffer = device
203+
.acquire_command_buffer()
204+
.expect("acquire_command_buffer");
205+
let copy_pass = device
206+
.begin_copy_pass(&command_buffer)
207+
.expect("begin_copy_pass");
208+
209+
copy_pass.upload_to_gpu_texture(source, destination, false);
210+
device.end_copy_pass(copy_pass);
211+
command_buffer.submit().expect("CommandBuffer::submit");
212+
213+
texture
198214
}

crates/spaceman-dmm/src/edit_prefab.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{Environment, GREEN_TEXT, RED_TEXT};
1+
use crate::{Environment, GREEN, RED};
22
use dmm_tools::dmm::Prefab;
33
use imgui::*;
44

@@ -75,7 +75,7 @@ impl EditPrefab {
7575
}
7676
// TODO: red instead of green if invalid var
7777
{
78-
let style = ui.push_style_color(GREEN_TEXT[0].0, GREEN_TEXT[0].1);
78+
let style = ui.push_style_color(StyleColor::Text, GREEN);
7979
ui.text(&im_str!(" {}", name));
8080
style.pop();
8181
}
@@ -97,7 +97,7 @@ impl EditPrefab {
9797
if red_paths {
9898
ui.separator();
9999
{
100-
let style = ui.push_style_color(RED_TEXT[0].0, RED_TEXT[0].1);
100+
let style = ui.push_style_color(StyleColor::Text, RED);
101101
ui.text(&fab.path);
102102
style.pop();
103103
}
@@ -125,7 +125,7 @@ impl EditPrefab {
125125
let instance_value = self.fab.vars.get(name.as_str());
126126

127127
if instance_value.is_some() {
128-
let style = ui.push_style_color(GREEN_TEXT[0].0, GREEN_TEXT[0].1);
128+
let style = ui.push_style_color(StyleColor::Text, GREEN);
129129
ui.text(im_str!("{} {}", prefix, name));
130130
style.pop();
131131
} else {
@@ -143,7 +143,7 @@ impl EditPrefab {
143143
.and_then(|v| v.constant.as_ref());
144144
if let Some(c) = instance_value {
145145
ui.same_line_with_spacing(offset, 0.);
146-
let style = ui.push_style_color(GREEN_TEXT[0].0, GREEN_TEXT[0].1);
146+
let style = ui.push_style_color(StyleColor::Text, GREEN);
147147
ui.text(im_str!(" {} ", c));
148148
style.pop();
149149
if ui.is_item_hovered() {

crates/spaceman-dmm/src/history.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
//! Reified undo/redo history tree.
22
3-
use std::cell::Cell;
4-
53
use petgraph::graph::{Graph, NodeIndex};
64
use petgraph::visit::EdgeRef;
75
use petgraph::Direction;
6+
use std::cell::Cell;
87

98
pub struct History<T, E> {
109
current: T,

0 commit comments

Comments
 (0)