Real-time clock: Prototype Todos #105732

Open
opened 2023-03-13 15:32:56 +01:00 by Hans Goudey · 3 comments
Member

UI and operators for starting/stopping the real time clock

  • Add Play/Pause buttons in View3D somewhere (temporary)
  • Add a timer variable like Screen::animtimer. If it exists the realtime clock is running.
    Use the animtimer for both anim playback and realtime clock. Separate flag indicates which clocks as currently running.
  • Define necessary customdata for the timer (like ScreenAnimData)
  • ED_ functions for creating/destroying the timer and checking state (like ED_screen_animation_play, ED_screen_animation_playing)
  • Operators for starting/stopping (like SCREEN_OT_animation_play, SCREEN_OT_animation_cancel)
  • RNA for realtime clock state (like Screen.is_animation_playing)

Timer events and depsgraph trigger

  • Replace uses of animtimer which just check for running playback with a ED_screen function (except the 2 cases in sound and sequencer which directly access DNA, those need to check the active_clock flag).
  • Operator for updating on realtime clock events (like SCREEN_OT_animation_step). Keymap entry to invoke this operator through TIMER events. Does TIMER0 work here or do we need to use TIMER1, TIMER2, or add a new event type?
  • ED_ function to prepare depsgraph updates on realtime clock events (like ED_update_for_newframe).
  • Extend DEG_graph_time_tag_update with a time source type to distinguish between updates from animation and from the realtime clock.

Depsgraph nodes and relations

  • Introduce a new TimeSourceNode to depsgraph that can be distinguished from the current time source. Animated IDs, properties, etc. will keep their relation to the current time source ("animation source"?), while simulations can be moved gradually over to using the new realtime source.
## UI and operators for starting/stopping the real time clock - [x] Add Play/Pause buttons in View3D somewhere (temporary) - [x] ~~Add a timer variable like `Screen::animtimer`. If it exists the realtime clock is running.~~ Use the `animtimer` for both anim playback and realtime clock. Separate flag indicates which clocks as currently running. - [x] Define necessary customdata for the timer (like `ScreenAnimData`) - [x] `ED_` functions for creating/destroying the timer and checking state (like `ED_screen_animation_play`, `ED_screen_animation_playing`) - [x] Operators for starting/stopping (like `SCREEN_OT_animation_play`, `SCREEN_OT_animation_cancel`) - [x] RNA for realtime clock state (like `Screen.is_animation_playing`) ## Timer events and depsgraph trigger - [x] Replace uses of `animtimer` which just check for running playback with a ED_screen function (except the 2 cases in sound and sequencer which directly access DNA, those need to check the `active_clock` flag). - [x] Operator for updating on realtime clock events (like `SCREEN_OT_animation_step`). Keymap entry to invoke this operator through `TIMER` events. Does `TIMER0` work here or do we need to use `TIMER1`, `TIMER2`, or add a new event type? - [x] `ED_` function to prepare depsgraph updates on realtime clock events (like `ED_update_for_newframe`). - [x] Extend `DEG_graph_time_tag_update` with a time source type to distinguish between updates from animation and from the realtime clock. ## Depsgraph nodes and relations - [x] Introduce a new `TimeSourceNode` to depsgraph that can be distinguished from the current time source. Animated IDs, properties, etc. will keep their relation to the current time source ("animation source"?), while simulations can be moved gradually over to using the new realtime source.
Hans Goudey added the
Type
Design
label 2023-03-13 15:32:56 +01:00
Hans Goudey added this to the Nodes & Physics project 2023-03-13 15:32:57 +01:00
Lukas Tönne self-assigned this 2023-03-13 15:51:49 +01:00
Member

A problem i'm trying to solve:
The animation playback timer and the realtime clock timer should be "in phase" as much as possible to avoid very frequent depsgraph updates over tiny time steps.

Note that i'm not talking about tying the playback of the realtime clock to the timeline or vice versa, just the case where both animation and realtime clock are running simultaneously. In this situation the animation clock will use the RenderSettings fps value as usual, but could the realtime clock run at a different interval? (eek!)

Even when both clocks always use the same time step size, they might still be started individually and thus be out of phase. Then the depsgraph has to perform 2 updates over the course of 1 frame because both animation and realtime clock trigger it (albeit with different tagged objects based on dependencies).

The simplest solution would be use the same timer for both clocks. As a consequence there might be a delay of up to 1 frame when starting animation playback or the realtime clock because the timer might already be running, but i think that's acceptable.

A problem i'm trying to solve: The animation playback timer and the realtime clock timer should be "in phase" as much as possible to avoid very frequent depsgraph updates over tiny time steps. Note that i'm **not** talking about tying the playback of the realtime clock to the timeline or vice versa, just the case where both animation and realtime clock are running simultaneously. In this situation the animation clock will use the RenderSettings fps value as usual, but could the realtime clock run at a different interval? (eek!) <img src="/attachments/b3cabf66-9cc6-4f77-bd27-a975c138ba64" width="400"> Even when both clocks always use the same time step size, they might still be started individually and thus be out of phase. Then the depsgraph has to perform 2 updates over the course of 1 frame because both animation and realtime clock trigger it (albeit with different tagged objects based on dependencies). <img src="/attachments/9d2cb242-c0be-49c4-befc-677fb14ee43d" width="400"> The simplest solution would be use the same timer for both clocks. As a consequence there might be a delay of up to 1 frame when starting animation playback or the realtime clock because the timer might already be running, but i think that's acceptable. <img src="/attachments/b7c2c40a-fea0-4556-853b-bcf6d5a0cb78" width="400">
177 KiB
188 KiB
195 KiB
Jacques Lucke changed title from Simulation Nodes: Realtime clock documentation to Real-time clock: Prototype Todos 2023-03-27 15:19:09 +02:00
Member

Created a separate task for "locking" the realtime clock to the scene timeline: #106182

Created a separate task for "locking" the realtime clock to the scene timeline: #106182
Member

On the topic of calculating time steps (aka. "delta time") from absolute values:

The way simulations currently work is based on storing a last update time locally. The naming is different for each simulation system, but the principle is the same, for instance:

  • RigidBodyWorld::ltime
  • ParticleSystem::cfra
  • Cloth::last_frame

When the respective update function is called, each system will compute a time step based on the current scene time (scene.r.cfra, BKE_scene_ctime_get, etc.) and the difference dtime = new_time - old_time.

To get this working with as little change as possible i can store a "cfra" value for the realtime clock as well (somewhere in Scene). The current time in seconds can be calculated for the realtime clock just like the scene clock by multiplying with the current fps setting. It must be noted that the realtime clock's cfra is not a meaningful value by itself, it should only be used to calculate delta time (and possibly for randomization seeds if determinism is not a requirement).

There is a risk that changing fps settings could alter the absolute time such that simulations see a sudden jump of the time step, but it seems this would already be a problem with current simulations, so it's not a regression (simulations just need to reset when fps changes). Storing and integrating a float/double time value instead of a frame count might avoid this, but could lead to lower time accuracy the further the simulation progresses.

On the topic of calculating time steps (aka. "delta time") from absolute values: The way simulations currently work is based on storing a _last update time_ locally. The naming is different for each simulation system, but the principle is the same, for instance: * `RigidBodyWorld::ltime` * `ParticleSystem::cfra` * `Cloth::last_frame` When the respective update function is called, each system will compute a time step based on the current scene time (`scene.r.cfra`, `BKE_scene_ctime_get`, etc.) and the difference `dtime = new_time - old_time`. To get this working with as little change as possible i can store a "cfra" value for the realtime clock as well (somewhere in `Scene`). The current time in seconds can be calculated for the realtime clock just like the scene clock by multiplying with the current fps setting. It must be noted that the realtime clock's `cfra` is not a meaningful value by itself, it should only be used to calculate delta time (and possibly for randomization seeds if determinism is not a requirement). There is a risk that changing fps settings could alter the absolute time such that simulations see a sudden jump of the time step, but it seems this would already be a problem with current simulations, so it's not a regression (simulations just need to reset when fps changes). Storing and integrating a float/double time value instead of a frame count might avoid this, but could lead to lower time accuracy the further the simulation progresses.
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#105732
No description provided.