-
-
Notifications
You must be signed in to change notification settings - Fork 10
Replace clone-and-replace pool updates with deferred UpdateQueue system #30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: GwnDaan <[email protected]>
Co-authored-by: GwnDaan <[email protected]>
Co-authored-by: GwnDaan <[email protected]>
Co-authored-by: GwnDaan <[email protected]>
Co-authored-by: GwnDaan <[email protected]>
src/update_helpers.rs
Outdated
| fn queue_u8_update<F>(&self, object_id: ObjectId, field_name: &'static str, getter: F, new_value: u8) | ||
| where | ||
| F: Fn(&Object) -> Option<u8> + Send + 'static; | ||
|
|
||
| /// Queue an update for a u16 field (like width, height) | ||
| fn queue_u16_update<F>(&self, object_id: ObjectId, field_name: &'static str, getter: F, new_value: u16) | ||
| where | ||
| F: Fn(&Object) -> Option<u16> + Send + 'static; | ||
|
|
||
| /// Queue an update for a bool field (like selectable, enabled) | ||
| fn queue_bool_update<F>(&self, object_id: ObjectId, field_name: &'static str, getter: F, new_value: bool) | ||
| where | ||
| F: Fn(&Object) -> Option<bool> + Send + 'static; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like these. Lets make them the required format for updates. With the information in the parameters we can also describe the updates in text, implement that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made UpdateHelpers the required format. The helpers now return ParameterUpdate with descriptive metadata:
let desc = project.queue_u8_update(
object_id,
"background_colour",
old_value,
new_value,
|obj, val| { /* setter */ }
);
// Logs: "Object 1: background_colour changed from 0 to 255"Added typed helpers for u8, u16, bool, String, and u32 fields with automatic logging. Commit: cba4f28
src/update_queue_tests.rs
Outdated
| @@ -0,0 +1,214 @@ | |||
| //! Copyright 2024 - The Open-Agriculture Developers | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dont add files for tests. Only do the most important tests, and keep them in the same file as the target
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved the 3 most important tests to src/object_updates.rs and removed the separate test file. Tests now live with the target code they're testing. Commit: cba4f28
… tests inline Co-authored-by: GwnDaan <[email protected]>
src/object_configuring.rs
Outdated
| if ui.text_edit_singleline(&mut value).changed() { | ||
| // Queue the update using the new UpdateQueue system | ||
| design.queue_update(object_id, move |obj| { | ||
| if let Object::StringVariable(sv) = obj { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot we don't want to check for every update whether it is the right type, because where it is used we always know what type it is already. Can we do something clever to work around this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added type-specific helper methods that encapsulate the type check. Now call sites use queue_number_variable_update() or queue_string_variable_update() with closures operating directly on the concrete type - no if let needed at the call site:
design.queue_number_variable_update(
object_id,
"value",
old_value,
new_value,
|nv, val| {
nv.value = val; // Direct access to NumberVariable!
},
);The type check happens once in the helper method, not at every call site. Commit: a9630aa
… sites Co-authored-by: GwnDaan <[email protected]>
The current implementation clones the entire object pool on every parameter change, creating ~100KB undo entries and causing RefCell borrow conflicts when multiple UI elements need to update objects.
Implementation
Core (
object_updates.rs)ObjectUpdate: Closure wrapper targeting single object by IDUpdateQueue: RefCell-based queue collecting updates during frameupdate_pool()callStructured Update Helpers (
update_helpers.rs)ParameterUpdate: Metadata struct describing each update with object ID, field name, old/new valuesUpdateHelperstrait: Required format for all object updates with typed methods"Object 1: background_colour changed from 0 to 255"queue_number_variable_update()that work directly on concrete typesAPI (
editor_project.rs)Migration Path
get_mut_pool()NumberVariableandStringVariableResults
See
docs/UPDATE_QUEUE_QUICKSTART.mdfor usage patterns anddocs/UPDATE_QUEUE_MIGRATION.mdfor conversion guide.Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.