Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions editor/src/messages/broadcast/broadcast_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::messages::prelude::*;
#[derive(PartialEq, Eq, Clone, Debug, serde::Serialize, serde::Deserialize, Hash)]
#[impl_message(Message, BroadcastMessage, TriggerEvent)]
pub enum BroadcastEvent {
/// Triggered by requestAnimationFrame in JS
AnimationFrame,
CanvasTransformed,
ToolAbort,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::messages::input_mapper::utility_types::misc::FrameTimeInfo;
use crate::messages::portfolio::utility_types::KeyboardPlatformLayout;
use crate::messages::prelude::*;
use glam::DVec2;
use std::time::Duration;

pub struct InputPreprocessorMessageData {
pub keyboard_platform: KeyboardPlatformLayout,
Expand Down Expand Up @@ -97,6 +98,7 @@ impl MessageHandler<InputPreprocessorMessage, InputPreprocessorMessageData> for
InputPreprocessorMessage::CurrentTime { timestamp } => {
responses.add(AnimationMessage::SetTime(timestamp as f64));
self.time = timestamp;
self.frame_time.advance_timestamp(Duration::from_millis(timestamp));
}
InputPreprocessorMessage::WheelScroll { editor_mouse_state, modifier_keys } => {
self.update_states_of_modifier_keys(modifier_keys, keyboard_platform, responses);
Expand Down
6 changes: 6 additions & 0 deletions frontend/wasm/src/editor_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,12 @@ impl EditorHandle {
for message in editor.handle_message(AnimationMessage::IncrementFrameCounter) {
handle.send_frontend_message_to_js(message);
}

// Used by auto-panning, but this could possibly be refactored in the future, see:
// <https://github.com/GraphiteEditor/Graphite/pull/2562#discussion_r2041102786>
for message in editor.handle_message(BroadcastMessage::TriggerEvent(BroadcastEvent::AnimationFrame)) {
handle.send_frontend_message_to_js(message);
}
Comment on lines +158 to +160
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to dispatch both the broadcast event and the increment frame counter message from the CurrentTime input preprocessor message handler. Having these multiple invocations is not pretty. It also somewhat obfuscates that setting the current time now has a side effect (of changing the frame time).
I'm also wondering if it even makes sense to use the animation frame here at all for non render related editor timing. We could consider adding a LogicTick broadcast event which is triggered on a set interval timer and seperate this completely from animation related functionality

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also wondering if it even makes sense to use the animation frame here at all for non render related editor timing. We could consider adding a LogicTick broadcast event which is triggered on a set interval timer and seperate this completely from animation related functionality

(To be clear, that would be a separate discussion for a later PR, this one is just focused on un-breaking the functionality without refactoring or rearchitecting it.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean the code should work, I just don't like it, but I didn't like it before either so that is not a merge blocker

});
}

Expand Down
Loading