Add comments and remove extra performance measure

Co-authored-by: Cole Lawrence <cole@colelawrence.com>
This commit is contained in:
vezwork 2022-08-04 12:04:10 -04:00 committed by Cole Lawrence
parent 62def1e883
commit fdf268ad43
5 changed files with 28 additions and 13 deletions

View file

@ -45,6 +45,9 @@ export default class Ticker {
/** /**
* Counts up for every tick executed. * Counts up for every tick executed.
* Internally, this is used to measure ticks per second. * Internally, this is used to measure ticks per second.
*
* This is "public" to TypeScript, because it's a tool for performance measurements.
* Consider this as experimental, and do not rely on it always being here in future releases.
*/ */
public __ticks = 0 public __ticks = 0

View file

@ -1,10 +1,14 @@
import {editable as e, SheetProvider} from '@theatre/r3f' import {editable as e, SheetProvider} from '@theatre/r3f'
import {Stars, TorusKnot} from '@react-three/drei' import {Stars, TorusKnot} from '@react-three/drei'
import {getProject} from '@theatre/core' import {getProject, onChange} from '@theatre/core'
import React from 'react' import React from 'react'
import {Canvas} from '@react-three/fiber' import {Canvas} from '@react-three/fiber'
function App() { function App() {
const sheet = getProject('Space').sheet('Scene')
onChange(sheet.sequence.pointer, (a) => {
console.log('gasp!!', a)
})
return ( return (
<div <div
onClick={() => { onClick={() => {
@ -20,7 +24,7 @@ function App() {
gl={{preserveDrawingBuffer: true}} gl={{preserveDrawingBuffer: true}}
frameloop="demand" frameloop="demand"
> >
<SheetProvider sheet={getProject('Space').sheet('Scene')}> <SheetProvider sheet={sheet}>
<ambientLight intensity={0.75} /> <ambientLight intensity={0.75} />
<e.group uniqueName="trefoil"> <e.group uniqueName="trefoil">
<TorusKnot scale={[1, 1, 1]} args={[1, 0.3, 128, 64]}> <TorusKnot scale={[1, 1, 1]} args={[1, 0.3, 128, 64]}>

View file

@ -37,7 +37,7 @@ studio.extend({
title: 'Example Icon', title: 'Example Icon',
svgSource: '👁‍🗨', svgSource: '👁‍🗨',
onClick: () => { onClick: () => {
console.log('hello') studio.createPane('example')
}, },
}, },
]) ])
@ -49,7 +49,16 @@ studio.extend({
} }
}, },
}, },
panes: [], panes: [
{
class: 'example',
mount: ({paneId, node}) => {
studio.ui.renderToolset('global', node)
return () => {}
},
},
],
}) })
studio.initialize() studio.initialize()

View file

@ -42,6 +42,7 @@ function Model({url}: {url: string}) {
) )
} }
// Initially, just copied from the shared/dom example
const textInterpolate = (left: string, right: string, progression: number) => { const textInterpolate = (left: string, right: string, progression: number) => {
if (!left || right.startsWith(left)) { if (!left || right.startsWith(left)) {
const length = Math.floor( const length = Math.floor(
@ -52,7 +53,7 @@ const textInterpolate = (left: string, right: string, progression: number) => {
return left return left
} }
const boxObjectConfig = { const allPropsObjectConfig = {
test: types.string('Typing', {interpolate: textInterpolate}), test: types.string('Typing', {interpolate: textInterpolate}),
testLiteral: types.stringLiteral('a', {a: 'Option A', b: 'Option B'}), testLiteral: types.stringLiteral('a', {a: 'Option A', b: 'Option B'}),
bool: types.boolean(false), bool: types.boolean(false),
@ -77,7 +78,8 @@ function App() {
const sheet = project.sheet('Scene') const sheet = project.sheet('Scene')
project.ready.then(() => sheet.sequence.play({iterationCount: Infinity})) project.ready.then(() => sheet.sequence.play({iterationCount: Infinity}))
sheet.object('everything', boxObjectConfig) const allPropsObj = sheet.object('All Props Tester', allPropsObjectConfig)
console.log('allPropsObj', allPropsObj)
return ( return (
<div <div

View file

@ -12,13 +12,9 @@ ReactDOM.render(<App />, document.getElementById('root'))
const raf = Ticker.raf const raf = Ticker.raf
setInterval(() => { // Show "ticks per second" information in performance measurements using the User Timing API
const id = Date.now().toString(36) + '-' // See https://developer.mozilla.org/en-US/docs/Web/API/User_Timing_API
performance.mark(id) // See https://web.dev/user-timings/
setTimeout(() => {
performance.measure('---', id)
}, 2000)
}, 2000)
setInterval(() => { setInterval(() => {
const start = { const start = {
ticks: raf.__ticks, ticks: raf.__ticks,
@ -29,6 +25,7 @@ setInterval(() => {
setTimeout(() => { setTimeout(() => {
const ticksPerSec = const ticksPerSec =
((raf.__ticks - start.ticks) * 1000) / (Date.now() - start.now) ((raf.__ticks - start.ticks) * 1000) / (Date.now() - start.now)
// This shows up in the performance tab of devtools if you record!
performance.measure( performance.measure(
`${ticksPerSec.toFixed(0)}t/1s - ${(ticksPerSec * 0.5).toFixed( `${ticksPerSec.toFixed(0)}t/1s - ${(ticksPerSec * 0.5).toFixed(
0, 0,