Skip to content
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

New Animation API #157

Open
wants to merge 31 commits into
base: main
Choose a base branch
from
Open

New Animation API #157

wants to merge 31 commits into from

Conversation

lucasdinonolte
Copy link
Contributor

TL;DR

Adds a draw loop helper to mechanic core. This helper is exposed to design functions through the engine. The goal of this is to remove boilerplate from design functions.

Implements the changes explored and discussed in #156

What this does

Core

  • adds frameRate setting to mechanic instance (defaults to 60)
    • frameRate is passed to the webm writer and used to prepare a draw loop helper
  • adds defaultSettings file that is merged with user provided settings (mostly to create visibility for the default settings)
  • adds a singleton drawloop helper to mechanic core
    • whenever a new instance of mechanic is created the draw loop helper is configured with the frameRate setting
    • a singleton was chosen to be entirely sure we can reset the draw loop before reloading a function
  • adds registerFrameCallback and registerDoneCallback methods to mechanic core
    • these can be used by engines to register their onFrame and onDone methods
    • this is needed so common logic (like resetting the draw loop on Done) can be handled by core instead of being duplicated in every engine
    • imho this also streamlines the readbility of each engine a tiny bit
  • adds callbacksForEngine to mechanic core
    • this returns an object of callbacks (frame, done, drawLoop …) that an engine can pass to a function
    • the function takes an overwrite-argument to allow engines to overwrite callbacks if they need
    • engine p5 uses this to output an error if you try to use mechanic's draw loop

All engines

  • Refactor engines to work with the updated API (registerFrameCallback, registerDoneCallback and callbacksForEngine)
  • Refactor engines to expose frame, done and drawLoop to the design function directly, instead of on the mechanic object passed in
    • state and setState remain on mechanic to avoid namespace collisions with React
    • for consistency this is true for all engines

Engine Canvas

  • Add getCanvas helper to engine that provides the user with a density-aware preview canvas
    • this is just for preview, this does not implement different pixel densities on export to keep the scope of this PR limited
    • pixel Density for export should be implemented on another PR ([WIP] Choose pixel density for exports #144 did some exploration)
  • When using getCanvas a user no longer needs to pass canvas to done or frame
    • done and frame still accept a canvas to be passed to them, to keep it backwards compatible with functions creating their own canvas

Engine p5

  • Call sketch.frameRate with mechanic.settings.frameRate before starting rendering on the sketch

DSI Logo Maker

  • Refactor all functions to new API
    • Logo Animated SVG renders a bit stuttery, but this does not seem to be related to the changes. It's the same on main

Create-Mechanic

  • Refactor all function-templates and examples to new API

Discussion

I tried to keep this PR as concise as possible, but given it needs to touch almost all parts of mechanic it has become fairly large. I also tried to be expressive with code comments and added TODO labels where I feel unsure about a decision I've made. Looking forward to discussing this.

@netlify
Copy link

netlify bot commented Oct 18, 2022

Deploy Preview for dsi-logo-maker ready!

Name Link
🔨 Latest commit 057cb30
🔍 Latest deploy log https://app.netlify.com/sites/dsi-logo-maker/deploys/645cdc988f812f000891e1ff
😎 Deploy Preview https://deploy-preview-157--dsi-logo-maker.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

Copy link
Contributor

@fdoflorenzano fdoflorenzano left a comment

Choose a reason for hiding this comment

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

This is an initial set of comments. For now I just checked the core and engine changes, I'll leave the checking of the actual function updates for a bit later.

packages/core/src/mechanic-drawloop.js Outdated Show resolved Hide resolved
packages/core/src/mechanic-drawloop.js Outdated Show resolved Hide resolved
packages/core/src/mechanic-drawloop.js Outdated Show resolved Hide resolved
packages/core/src/mechanic-drawloop.js Outdated Show resolved Hide resolved
packages/core/src/mechanic-drawloop.js Outdated Show resolved Hide resolved
packages/core/src/mechanic.js Outdated Show resolved Hide resolved
packages/engine-canvas/index.js Outdated Show resolved Hide resolved
packages/core/src/mechanic.js Outdated Show resolved Hide resolved
packages/engine-canvas/index.js Outdated Show resolved Hide resolved
@lucasdinonolte
Copy link
Contributor Author

@fdoflorenzano thanks for the initial set of comments. I just addressed them. From my point of view this should now be ready for you to play with writing some design functions using the new API to see how it feels 😊

/cc @runemadsen

Copy link
Contributor

@fdoflorenzano fdoflorenzano left a comment

Choose a reason for hiding this comment

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

Thank you @lnolte ! Most comments are address, so yeah I also think it's a good point to check the actual functions. I'll try and do that tomorrow :)

packages/core/src/mechanic-drawloop.js Outdated Show resolved Hide resolved
packages/core/src/mechanic-drawloop.js Outdated Show resolved Hide resolved
Copy link
Contributor

@fdoflorenzano fdoflorenzano left a comment

Choose a reason for hiding this comment

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

Found something! (Will continue reviewing!)

packages/engine-canvas/prepare-canvas.js Show resolved Hide resolved
Copy link
Contributor

@fdoflorenzano fdoflorenzano left a comment

Choose a reason for hiding this comment

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

Checked all functions finally!

packages/core/src/mechanic-drawloop.js Outdated Show resolved Hide resolved
Copy link
Contributor

@fdoflorenzano fdoflorenzano left a comment

Choose a reason for hiding this comment

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

Let's wait for #169 into this first and then merge if @runemadsen also approves!

Copy link
Contributor

@runemadsen runemadsen left a comment

Choose a reason for hiding this comment

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

Yezzzz, let's get this sucker in!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants