Rewrite VIP tools to not mutate context

This commit is contained in:
2026-03-29 22:37:46 -04:00
parent 8f6a6f86db
commit 341de60816
8 changed files with 187 additions and 191 deletions
+9 -12
View File
@@ -14,10 +14,10 @@ use num_traits::{FromPrimitive, ToPrimitive};
use crate::{
emulator::SimId,
images::{ImageBuffer, ImageParams, ImageProcessor, ImageRenderer, ImageTextureLoader},
images::{ImageBuffer, ImageParams, ImageRenderer, ImageTextureLoader},
memory::{MemoryClient, MemoryRef, MemoryView},
window::{
AppWindow, InitArgs,
AppWindow,
utils::{NumberEdit, UiExt as _},
},
};
@@ -26,7 +26,6 @@ use super::utils::{self, CellData, Object, shade};
pub struct WorldWindow {
sim_id: SimId,
loader: Arc<ImageTextureLoader>,
memory: Arc<MemoryClient>,
worlds: MemoryView,
bgmaps: MemoryView,
@@ -39,7 +38,7 @@ pub struct WorldWindow {
}
impl WorldWindow {
pub fn new(sim_id: SimId, memory: &Arc<MemoryClient>, images: &mut ImageProcessor) -> Self {
pub fn new(sim_id: SimId, memory: &Arc<MemoryClient>, images: &ImageTextureLoader) -> Self {
let initial_params = WorldParams {
index: 31,
generic_palette: false,
@@ -47,11 +46,9 @@ impl WorldWindow {
right_color: Color32::from_rgb(0x00, 0xc6, 0xf0),
};
let renderer = WorldRenderer::new(sim_id, memory);
let ([world], params) = images.add(renderer, initial_params);
let loader = ImageTextureLoader::new([("vip://world".into(), world)]);
let params = images.add(sim_id, renderer, initial_params);
Self {
sim_id,
loader: Arc::new(loader),
memory: memory.clone(),
worlds: memory.watch(sim_id, 0x0003d800, 0x400),
bgmaps: memory.watch(sim_id, 0x00020000, 0x20000),
@@ -426,7 +423,7 @@ impl WorldWindow {
}
fn show_world(&mut self, ui: &mut Ui) {
let image = Image::new("vip://world")
let image = Image::new(self.image_url("world"))
.fit_to_original_size(self.scale)
.texture_options(TextureOptions::NEAREST);
let res = ui.add(image);
@@ -523,10 +520,6 @@ impl AppWindow for WorldWindow {
.with_inner_size((640.0, 520.0))
}
fn on_init(&mut self, args: InitArgs) {
args.ctx.add_texture_loader(self.loader.clone());
}
fn show(&mut self, ui: &mut Ui) {
CentralPanel::default().show_inside(ui, |ui| {
ui.horizontal_top(|ui| {
@@ -779,6 +772,10 @@ impl WorldRenderer {
impl ImageRenderer<1> for WorldRenderer {
type Params = WorldParams;
fn names(&self) -> [&str; 1] {
["world"]
}
fn sizes(&self) -> [[usize; 2]; 1] {
[[384, 224]]
}