blockUtility as an object literal inside execute creates 11 objects,
one for the object, and 10 for the function closures. As a separate
object and allocated once, setting its sequencer and thread members,
block functions can share the same util object. Extract blockUtility to
cut down on allocations.
`handleReport` inside `src/engine/execute.js`'s `execute` method needs
to allocate a closure to be able to refer to the higher scoped
variables. `execute` is called frequently that this has a noticable
impact on memory allocation and later collection. Extract handleReport
and add arguments to prevent the allocation.
Testing with implicitly casted `value` and `value.then` is deoptimizing
isPromise, which deoptimizes execute. In this case deoptimizing means
that the JavaScript VM cannot compile the functions into a form that
can be run faster.
Remove indexOf tests for thread existence in doneThreads. Maintain a
list of null and thread objects mirroring the index position of threads
that are done in runtime.threads. Filter out null values after
filtering out done threads from runtime.threads.
This has a small side effect that threads that normally became DONE and
were added to doneThreads before being removed or restarted will not be
in doneThreads in this version. Restarted threads (_restartThread) do
not appear in this version but new copies will be in Runtime
this.threads supporting glow and monitor updates. Removed threads
(_removeThread) do not appear in this version if they are removed after
they were seen as DONE by the prior version. Threads removed before
they are seen as DONE do not appear in doneThreads in the prior or this
version.
Threads that are removed before normally becoming DONE do not appear in
doneThreads in either case. Threads that are restarted before the loop
checks if the thread is done do not appear in doneThreads in either
case.
Due to a typo (I believe) we were overwriting a horizontal hat block's
fields list when collecting hat block inputs. Now we collect inputs into
a temporary object in this case.
Dynamic menus are not yet supported for extension menus, though they are
part of the extension spec. This change provides more thorough feedback
if an extension tries to register an unsupported dynamic menu.
- Remove WeDo 2 extension from the runtime's default block packages list
- The WeDo 2.0 extension now calls its own `connect` method on startup
I also renamed `EXTENSION_NAME` to `EXTENSION_ID` for consistency with
the rest of the extension system.
This prevents generation of invalid XML due to characters like '<' or
'>' in fields' default values. Unfortunately the value comes back in its
escaped form, so there's still more work to be done.
The linter is correct that `devObject[func].call(devObject, args)` is unnecessary because it's equivalent to `devObject[func](args)`.
@tmickel probably either meant to allow passing an array of arguments to be applied, or to call the function with the provided argument. Since we probably want to be able to use multi-argument functions, use `apply` and fix the one place that uses `ioQuery` with an argument.
Problem:
When a clone is deleted, its thread is removed from the thread
list; but the index "i" in the execution for-loop will still +1,
making the next thread skipped.
Changes:
Added a flag "isKilled" on a thread;
Set the flag when a thread is removed from the thread list;
reduce the "i" counter if the thread of the current loop is removed.
the right quote is mission in blockToXML, and it will result in the following code execution errors
vm.on('workspaceUpdate', function (data) {
workspace.clear();
var dom = Blockly.Xml.textToDom(data.xml);
Blockly.Xml.domToWorkspace(dom, workspace);
});
* Add `getTargetIdForDrawableId` to translate between renderer picks and VM targets
* Add `startDrag` to stop sprite motion while dragging
* Add `stopDrag` to return sprite motion after dragging
And it starts to get a little less elegant :/
Wondering if this should not be handled better in another part of the
codebase?
We don't want to be duplicating existing code stepping functionality
locally at the end of the promise script really... What do you think?
The `allStacksAndOwnersDo` function in Scratch 2.0 runtime iterates
targets in reverse and projects sometimes rely on that for correct
initialization. If, for example, each sprite runs a "go back 999 layers"
or "go to front" block as its first action, the order of execution will
determine the ordering of the layers.
This change makes Scratch 3.0 match the Scratch 2.0 execution order.
This saves popping, destroying, recreating, and pushing the stack frame,
and then reassigning the warp mode attribute for every block to block
step in the execution.
Run-time Optimisation
The thread.stackFrames array is accessed all the time to retrieve the
'parent' stack frame. This is done using as index of [this.stack.length
- 1]. However, a lot of the time this evaluated to [-1]. Although this
results in null, which is fine, to get to this javascript actually
defers from a numeric array lookup to an object lookup using the string
"-1". This is roughly 100 times slower to compute and so a simple catch
for negative indexes is well worth the extra check.
When popping down the stack frame it is assumed that you keep using the
previous warp state rather than looking at the warp state of the level
you just popped out to. This causes the loss of screen updates if the
warping block was the last statement in a loop as the loop does not obey
it's 'non warp' status.
Changes include:
- Added missing JSDoc for items in `scratch3_pen.js` and `target.js`.
- Moved constants used by `Scratch3PenBlocks` into the class.
- Created a constant for minimum and maximum pen size.
- Added `util/clone.js` to host cloning functionality.
- Pen blocks now check for the renderer before trying to use it.
- The pen integration test covers all blocks, though `clear`, `stamp`,
and `pen down` will skip some of their functionality when there is no
renderer.
These blocks implement pen features as found in Scratch 2.0
Supporting changes include:
- `Target` is now an event emitter
- `RenderedTarget` now emits an event when it moves
- `Target` can now store arbitrary "extra" data, called "custom state"
in the code, using a `Target`'s `setCustomState` and `getCustomState`
methods. This is used to store per-target pen state without requiring
`Target` or `RenderedTarget` to know anything about the pen.
- `Cast` can now cast to an RGB color object.
- `Color` now has functions to convert between RGB and HSV, constants
for for black & white, and a `mixRgb` function to lerp between two
colors.
This allows costume data to reach listeners even when the sprite isn't the editing target.
Filter out non-editing target reports in the playground to match previous behavior.
These events signal when any threads are running or when all threads have stopped running. This maps to whether the green flag or the stop button should be illuminated in the GUI.
Use it before loading projects so targets don't accumulate when multiple projects are loaded on the same instance.
Move check to see if the clone is the original clone onto the block implementation so all clones can be removed.
Fixes#274
* Implement "go to" block
* Add a missing semicolon
My text editor doesn't automatically insert them and I'm not used to using
semicolons so much. :(
* Implement go-to-random
* Clean up the go-to-random code a bit
* Add rounding to _random_ picks
* Add scratch3_procedures and no-op for defnoreturn
* Add mutation adapter to parse mutations in CREATE/CHANGE events
* Add mutation-to-XML
* Update spec map for Blockly procedure names
* Placeholder for procedure special cases
* Basic stepping to procedures
* Remove extra case
* Validation for changeBlock
* Import lists and variables from SB2
* Switch to Variable and List objects
* Add Clone.lookupOrCreateVariable, Clone.getVariable, Clone.setVariable
* Add (get, set, change) variable blocks.
* Copy variables and lists on clone instantiation
* Move variable options closer to blocks
* Add list primitives
* Move variable and lists storage to `Target` instead of `Clone`
* Move _computeIndex to a Cast function
* Rename `getList` -> `getListAsString`
* Renames renames
* Remove extra check in Cast.isNaN
* Provide property to Clone to distinguish "original" clones
* Provide method to clone a clone's properties
* Don't report clones in the UI target list
* Add target info to Thread
* Allow hats to skip clones (for green flag)
* Green flag skips clones
* Implement "create clone" and hat
* Pass the runtime to sprites and clones (for start hats)
* Clone disposal; trigger hats after drawable initializes.
* Separate stop threads for target; fix handling of stop button
* Remove extraneous `skipClones` property
* Add global clone limit
* Don't allow a non-clone to delete itself.
* Rename `cloneClone` -> `makeClone`
* Variable updates in runtime.js
* Synchronous drawable initialization (until we put it back to promises)
* Strip out old script glowing in thread management
* Add new tracking mechanism for glowing scripts
* Track parents and use them to determine script glows
* Use top-block for a thread if there's nothing on the stack
* Remove `console.log`
* Add `Clone.prototype.getCostumeIndexByName`, keep in range
* Add basic costume primitives from Scratch 2.0
* Add costume getter block
* Add properties and methods for distinguishing stage and sprites-vs-clones
* Add backdrop-related looks blocks
* Fix up "switch to backdrop" to be working
* Costume/backdrop reporters are 1-indexed
* Fire "when backdrop switched" hats
* Cut cloning helpers for a separate PR
* Disable many blocks on the stage
* Refactor into _setCostumeOrBackdrop; implement switch backdrop and wait
* Fire hats even when backdrop unchanged
* Always add `next` to block representation
* Add `shadow` property to inputs, to maintain obscured shadows
* Create obscured shadows in SB2 import
* Add XML import of obscured shadows
* Alias SB2 shadow inputs to block inputs
* Add shadow to inputs on "delete inputs" test
* Add a small test to ensure obscured shadows are preserved
* Add more obscured shadow tests
* Key pressed hat
* Tabs -> Spaces
* Oops
* Edge activate
* Fix hat
Phew...
* I forgot to change it also here
:/ :/ :\
* Minor fixes for TravisCi
* Minor docs
* Line length