Commit Graph

788 Commits

Author SHA1 Message Date
David Wendt db41bec91e Implement `MovieClipLoader`'s `addListener`, `removeListener`, and `broadcastMessage` methods.
Interestingly, this constitutes an implementation of `AsBroadcaster`. It appears Macromedia decided to implement event handling on `MovieClipLoader` in a very similar fashion to `AsBroadcaster`, down to invoking `broadcastMessage` and searching a `_listeners` property for listeners.
2020-02-22 00:01:12 -05:00
David Wendt b7d318a897 Implement `MovieClip.loadMovie`, `MovieClip.loadVariables`, and `MovieClip.unloadMovie`.
*De*implement the free function versions of the above, as well as their `Num` variants, since they don't actually exist as callables. Instead, the ActionScript compiler treats them as preprocessor functions that represent various forms of `ActionGetURL`/`ActionGetURL2`.
2020-02-21 23:59:13 -05:00
David Wendt 31b1364b82 Implement `unloadMovie` / `unloadMovieNum` 2020-02-21 23:58:00 -05:00
David Wendt b2b2a165fc Implement `loadVariables` and `loadVariablesNum`. 2020-02-21 23:58:00 -05:00
David Wendt c7539872f7 Add the ability to POST data from `fetch`, and allow methods that read AVM locals into form data to `GET` or `POST` them. 2020-02-21 23:58:00 -05:00
David Wendt 3fe6884c90 Refactor layer resolution into a separate function.
This function is part of `Avm1`, rather than a hypothetical `LayerManager`, because we're going to need to eventually construct layers differently for AVM2.
2020-02-21 23:57:59 -05:00
David Wendt ea28c2c4a2 Impl `loadMovie` / `loadMovieNum` (sans local variable support) 2020-02-21 23:57:59 -05:00
David Wendt 07637fe676 Replaced movies should start out playing. This fixes a regression from a previous rebase. 2020-02-21 23:57:58 -05:00
David Wendt 64b787b73f Implement `Collect` for `Loader`. (How did this compile without that?) 2020-02-21 23:57:58 -05:00
David Wendt d84e11ed40 Introduce a new top-level object, `LoadManager`, which is responsible for all asynchronous behavior in the program. Migrate the existing async impls to it. 2020-02-21 23:57:58 -05:00
David Wendt 2d7a4fef28 `Sound` methods that reference sounds by library export name should default to `_layer0`'s library if the `Sound` was created without a movie clip target. 2020-02-21 23:57:57 -05:00
David Wendt 6b78ec6e03 More thoroughly clean `MovieClip`s that have movies loaded into them. This does everything except wipe the object it's attached to - I need further testing to see how Flash handles that. 2020-02-21 23:57:57 -05:00
David Wendt 2a82d21966 Change the layer list from a static array to a `BTreeMap`.
Flash allows creating layers at any 31-bit height without issue, so this should support similar limitations.
2020-02-21 23:57:57 -05:00
David Wendt f4e4171ebe Make spawned futures falliable, and report those errors. 2020-02-21 23:57:56 -05:00
David Wendt 5ce499d11e Add separate libraries for each loaded movie. 2020-02-21 23:57:56 -05:00
David Wendt e0c0779bd0 Make sure to preload all loaded clips. 2020-02-21 23:57:55 -05:00
David Wendt 6da374c567 Implement loading movies into `_leveln` via `ActionGetUrl` 2020-02-21 23:57:55 -05:00
David Wendt ed799fd2b9 Split the player up into nine layers, each of which is a separate root movie clip. 2020-02-21 23:57:55 -05:00
David Wendt 8c9d290db7 Implement the MovieClip loading portion of `ActionGetURL2`. 2020-02-21 23:57:54 -05:00
David Wendt 5ed5876e9a Merge SWF data and version into a single structure. Refactor everything that interacts with it to use `SwfSlice`s. 2020-02-21 23:57:53 -05:00
David Wendt 250ec13c12 Implement LoadVariablesFlag.
This has some subtle problems: we cannot hold references to garbage-collected data in Futures, so we have to arrange for the AVM itself to forcibly root them for us. Then we get them back when our async code is ready to do something to the AVM.
2020-02-21 23:44:06 -05:00
David Wendt 55149b7b7e Reference count the Player and provide a weak reference in UpdateContext.
This allows the formation of `'static` futures that can still interact with a player. Async code will need to upgrade the weak reference in order to be able to interact with the player.
2020-02-21 23:44:06 -05:00
David Wendt 491d94c947 Pinbox all Futures.
Due to some strangeness with the way Rust implemented unsafe-to-move behavior, boxed futures are implicitly `Unpin`. Which is useless to us.

The reason for this is a little counter-intuitive. Actually, the fact that Rust supports memory pinning at all is a little odd, because the core language explicitly requires all types be movable. To get around this, Pin requires that all !Unpin types be *born pinned*. This is because you can't re-pin an already unpinned value in memory.

Anyway, this necessitates this silly API change.
2020-02-21 23:44:05 -05:00
David Wendt 00d25a768c Extremely basic impl of fetch/spawn methods for getting data off the web 2020-02-21 23:44:05 -05:00
David Wendt 2137b9f1fd Migrate `set_frame_rate` into the core `AudioBackend` trait 2020-02-21 23:44:05 -05:00
David Wendt c1cf73ccb3 Add a public method to trigger a player update.
User-defined player updates are treated the same as if a stage frame had been run: queued actions are executed and garbage is collected.
2020-02-21 23:44:04 -05:00
Mike Welsh f80c188048 core: Stop stream sounds when a clip is removed 2020-02-21 19:24:45 -08:00
Mike Welsh 6b503ac053 avm1: Fix DefineFunction2 preload order when _parent is undefined
The order is misdocumented in SWF19 (and also miscompiled assuming
this incorrect order by the Flash IDE!).

`_global` gets preloaded before `_parent`.
2020-02-20 12:58:26 -08:00
Mike Welsh dc1f99e2ba tests: Add test for misdocumented DefineFunction2 register preload 2020-02-20 12:58:26 -08:00
Mike Welsh 10fb6c7c04 tests: Add define_function2_preload test 2020-02-19 23:22:33 -08:00
Mike Welsh 19d0bf64a9 avm1: Preload _parent directly from base clip
When `_parent` is preloaded  in a `DefineFunction2` action,
we previously resolve it on the scope chain. This could cause
double borrow panics as the parent object could already be
borrowed, and also this matches the behavior of the official Flash
player.

Addresses #398.
2020-02-19 23:22:33 -08:00
Mike Welsh 8d7e58011e avm1: undefined coerces to "" in SWFv6 and below
Except in the AVM1 trace op, which will print out "undefined".
2020-02-19 10:47:43 -08:00
Mike Welsh dfde98da7d tests: Add tests for coercing undefined to string in SWF6 2020-02-19 10:47:43 -08:00
Mike Welsh 452ac84f0e tests: Uncomment Number.POSITIVE_INFINITY/Number.NEGATIVE_INFINITY tests 2020-02-18 10:17:55 -08:00
Mike Welsh c073afb077 avm1: Use proper value for Number.MIN_VALUE
This is the smallest positive number, not the most negative value.
This is actually the smallest positive subnormal f64, which Rust
does not provide a constant for. This is ~5e-324.
2020-02-18 10:17:55 -08:00
Mike Welsh 6bbe1dbab8 avm1: Match Flash when converting exotic numbers to string (fix #361)
Match Flash's more closely when converting number to string:
 * NAN -> NaN
 * inf -> Infinity
 * -inf -> -Infinity
 * Use exponential notation for very large/very small

This is a little bit of a cheat by using Rust's number-to-string
formatting for exponentials, and shoving a sign in front of the
exponent.
2020-02-18 10:17:55 -08:00
Mike Welsh 324dd1c5e4 tests: Add swf_tests_approx macro
Use this macro to test numeric calculations that might have some
variance using approx_eq.
2020-02-17 15:42:29 -08:00
Mike Welsh b6249cdb73 tests: Add localToGlobal/globalToLocal test 2020-02-17 15:42:29 -08:00
Mike Welsh 2af21d87e0 avm1: Implement MovieClip.localToGlobal/globalToLocal 2020-02-17 15:42:29 -08:00
Mike Welsh cd94486f7e desktop: Fix stream audio from prematurely ending (fix #222) 2020-02-14 20:32:25 -08:00
Mike Welsh 7c406732c7 audio: Ensure stream sounds stop upon goto/loop (fix #370) 2020-02-14 20:32:25 -08:00
Mike Welsh 9ad069e11a avm1: Improve display object property setters for weird values
Setting a property such as _x to undefined or null should have no
effect. This was working for v7+ SWFs because it would coerce to
NaN and we toss out NaNs. But on v6 and below, these coerce to 0
and would end up setting the property to 0.

Explicitly check for undefined/null and bail out. Fixes #380.

Also adjust the _visible setter, since this actually coerces to a
number (because of its legacy from SWFv4). For example,
_visible = "" should have no effect.
2020-02-14 15:34:14 -08:00
Mike Welsh 3a1a73ae11 tests: Add more tests for display object properties
Add more _x = weirdo value tests, and copy the test into a v6 SWF.
(because undefined etc. can coerce to 0 instead of NaN in SWFv6).
2020-02-14 15:34:14 -08:00
Mike Welsh 7d14b98f3b avm1: Ignore undefined values in Color.setTransform
If a property is not set on the object passed to Color.setTransform,
then that channel is left unmodified. This fixes invisible objects
in some games (fixes #369, addresses #380).

Also improve handling of wrapping/invalid values to better match the
behavior in the Flash Player (some work pending on #193).
2020-02-13 18:06:27 -08:00
Mike Welsh 21f117e7bc avm1: Add Value::coerce_to_i16 2020-02-13 18:06:27 -08:00
Mike Welsh 19df074a79 tests: Add more tests for AVM1 Color object
Include not defined values, wrapping values, invalid values.
2020-02-13 18:06:27 -08:00
David Wendt 18516c8eac Pre-strip HTML from HTML tags, rather than skipping them. 2020-02-03 19:32:05 -05:00
David Wendt 7d225f8b55 Fix overflow when shifting `u8`s 2020-02-03 14:46:36 -05:00
David Wendt 3d6b00c1e4 Impl the remaining text layout properties 2020-02-03 14:46:36 -05:00
David Wendt 517e7ce9ff Add word-wrap for `measure_text` and caching for word-wrap calculations 2020-02-03 14:46:36 -05:00
David Wendt 5e808c8cd6 Adjust the wordwrap machinery to work in break points (indicies where new lines start) so we can cache them later 2020-02-03 14:46:35 -05:00
David Wendt fb8664c818 Implement wordWrap and multiline rendering, poorly 2020-02-03 14:46:35 -05:00
David Wendt 7df8eb7674 Impl `is_multiline`'s effect of respecting newlines 2020-02-03 14:46:35 -05:00
David Wendt f95ec777de Also impl storage of the `wordWrap` flag 2020-02-03 14:46:34 -05:00
David Wendt 819757e2b6 Fix text measurement now that the underlying SWF tags are correctly parsed as `Twips`.
Transform coordinates are always in twips, so we have to convert pixels to twips when evaluating the font, and then convert back when measuring.
2020-02-03 14:46:34 -05:00
David Wendt 63b7d172f4 `TextRecord.height` is also in `Twips`.
Notably, the `Text` rendering code does not appear to actually work in pixel scale.
2020-02-03 14:46:34 -05:00
David Wendt fde7715fb8 `EditText.height` is in `Twips` 2020-02-03 14:46:33 -05:00
David Wendt 75022f36d2 Pull `TextFormat` into the `font` module.
Also, since there's a separate function for attaching virtual properties to an AVM1 `TextField` object, let's use that!
2020-02-03 14:46:33 -05:00
David Wendt 4b3660bf2c Impl get/set for `is_multiline`. 2020-02-03 14:46:32 -05:00
David Wendt c1ff1d94d5 Pull the `EditText.evaluateFont` method into `Font`.
`Text` itself doesn't use this method, but it probably could with some changes.
2020-02-03 14:46:32 -05:00
David Wendt 81b7958090 Impl `textWidth` / `textHeight`, although it currently only works well for single-line scenarios. 2020-02-03 14:46:32 -05:00
David Wendt 2181f0d0d0 Impl `getNewTextFormat`/`setNewTextFormat`.
These don't actually do anything yet, because we don't track text spans, nor do we actually use those text spans to alter rendering or text layout.
2020-02-03 14:46:30 -05:00
David Wendt db56217f20 `TextFormat` does *not* coerce `undefined` or `null`; instead those both become `null`. 2020-02-03 14:46:30 -05:00
David Wendt 8449d964ef Implement `TextFormat` as a property bag. 2020-02-03 14:46:29 -05:00
David Wendt 2b0600ab1a Impl `createTextField`. 2020-02-03 14:46:29 -05:00
Mike Welsh 2ff76775e0 core: Empty movie clips can not be used as a mask
When a movie clip or button is used as a mask, the masking will be
disabled if that object has no children; the maskee will be
completely visible. An empty movie clip inside an empty movie clip
successfully masks.

An EditText can also not be used as a masker (although it can be
wrapped inside a movie clip, and then the text successfully masks).

Add a `TDisplayObject::allow_mask` trait method that will
return whether the object can be used as a mask.

This fixes characters not being visible in Dad 'n' Me.
2020-02-01 01:15:31 -08:00
Mike Welsh 2e304a81ef core: Flag as transformed-by-script after swapDepths 2020-01-31 19:44:42 -08:00
Mike Welsh a55a378a73 avm1: Improve comments in MovieClip depth methods 2020-01-31 19:44:42 -08:00
Mike Welsh 4d1f7c4d4a tests: Add movieclip depth method tests 2020-01-31 19:44:42 -08:00
Mike Welsh a4e175a790 avm1: Implement MovieClip.getNextHighestDepth 2020-01-31 19:44:42 -08:00
Mike Welsh 4d12cd1566 avm1: Implement MovieClip.getDepth 2020-01-31 19:44:42 -08:00
Mike Welsh 9e337ede34 avm1: Implement MovieClip.swapDepths 2020-01-31 19:44:42 -08:00
dependabot-preview[bot] 2f98fd1a0e build(deps-dev): bump webpack-dev-server in /web/selfhosted
Bumps [webpack-dev-server](https://github.com/webpack/webpack-dev-server) from 3.10.1 to 3.10.2.
- [Release notes](https://github.com/webpack/webpack-dev-server/releases)
- [Changelog](https://github.com/webpack/webpack-dev-server/blob/master/CHANGELOG.md)
- [Commits](https://github.com/webpack/webpack-dev-server/compare/v3.10.1...v3.10.2)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-01-31 19:44:42 -08:00
Mike Welsh 0d91fb423e core: Goto only runs if frame is an integer 2020-01-30 15:17:01 -08:00
Mike Welsh c079cb3bca core: Don't run frame actions when seeking past end of timeline
If you goto past the final loaded frame of a timeline, for example,
with gotoAndStop(9999), this seeks to the final frame on the
timeline, but it doesn't run the actions on this frame.

MovieClip::goto_frame now will not run the final frame actions if
the target frame was not reached.
2020-01-30 15:17:01 -08:00
Mike Welsh 8aae07bbf3 core: Frame labels are case insensitive 2020-01-30 15:17:01 -08:00
Mike Welsh a835573f3c tests: Add test for global GotoFrame action 2020-01-30 15:17:01 -08:00
Mike Welsh 62467bb880 avm1: Handle invalid parameters in GotoFrame2
Use the same code path for the global GotoFrame2 action and
MovieClip.gotoAndX, which properly handles out-of-range and invalid
values like NaN.

Fixes Disorderly hanging on game start
(https://www.newgrounds.com/portal/view/121896)
2020-01-30 15:17:01 -08:00
David Wendt a57d0e12b3 Do not apply a color filter at all unless rendering a bitmap or gradient.
This significantly improves render times, as browsers appear to apply filters in the most general, inefficient way possible.
2020-01-29 14:19:18 -05:00
dependabot-preview[bot] dc8858505d build(deps): bump smallvec from 1.1.0 to 1.2.0
Bumps [smallvec](https://github.com/servo/rust-smallvec) from 1.1.0 to 1.2.0.
- [Release notes](https://github.com/servo/rust-smallvec/releases)
- [Commits](https://github.com/servo/rust-smallvec/compare/v1.1.0...v1.2.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-01-29 18:42:28 +00:00
Mike Welsh 003cc414aa core: Create clips in execution order during a goto
The list of goto commands is now a Vec that will already be in order
of creation. This ensures that subsequent ActionScript in these clips
runs in the correct order.
2020-01-28 04:15:08 -08:00
Mike Welsh 81a1c05682 tests: Add goto_execution_order2 regression test
Tests execution order of children added during a goto.
2020-01-28 04:15:08 -08:00
Mike Welsh 7532e89aff avm1: Use `resolve_target_display_object` in `Color`
Fixes the boss damage blinking in Alien Hominid. Target was a path
string.
2020-01-27 23:35:41 -08:00
Mike Welsh 69f19f03c4 avm1: Output trace warning for invalid SetTarget (fix #332) 2020-01-27 23:35:41 -08:00
Mike Welsh a0032b9aa1 avm1: Better handling of movie clip paths strings (fix #317)
Ops and functions that take a movie clip path in String form have
a very forgiving syntax. These include:
 * `SetTarget`
 * `CloneSprite`
 * `RemoveSprite`
 * `swapDepths`

This change adds `Avm1::resolve_target_display_object` to parse
these paths correctly, along with `target_paths` test to test a
wide variety of formats.

This also applies to `GetVariable`/`SetVariable`, which accept
target paths to variables and is used by some SWF4/5 content.
(fixes #324, #337).
2020-01-27 23:35:41 -08:00
Mike Welsh 2751b89d4e avm1: Root clip should not have a name
Previously we set the name of the root clip to `_level0`. Top-level
clips should actually have no name (`_root._name` returns `""`).

However, when constructing a dot path, `_level0` still gets inserted
by `DisplayObject::path` for the top-level, so that `trace(_root)`
still correctly prints `_level0`.

TODO: When `loadMovieNum` gets merged in, the proper level # needs
to be returned by `.DisplayObject::path`.
2020-01-27 23:35:41 -08:00
Mike Welsh 0446644742 tests: Add target_path test 2020-01-27 23:35:41 -08:00
David Wendt db51ec9e3c Implement a separate `Object` impl for functions that holds an `Executable`. 2020-01-27 21:57:32 -05:00
David Wendt 8eeb9a5c60 This technically isn't a test of `toString`, so remove stuff from the test that it relies upon. 2020-01-27 21:50:11 -05:00
David Wendt d217f51c6c Don't crash if `Function.prototype.call` is called without arguments. 2020-01-27 21:50:10 -05:00
David Wendt 0470b8d0a7 Add a test for `Function.call` and `Function.apply` 2020-01-27 21:50:10 -05:00
David Wendt 2c0d892154 Implement Function.call/apply 2020-01-27 21:50:09 -05:00
Mike Welsh 4b7bac706b avm1: ActionNewMethod supports auto-boxing values
This allows `new ("FOO".bar)()`, although there is probably no
good reason to do this. :-)
2020-01-21 18:24:49 -08:00
Mike Welsh 70bec9437f tests: Boolean() returns undefined 2020-01-21 18:24:49 -08:00
Mike Welsh d9e7a6a960 avm1: Implement Boolean class 2020-01-21 18:24:49 -08:00
Mike Welsh e71099edd5 tests: Add primitive_type_globals test 2020-01-21 18:24:49 -08:00
Mike Welsh 8263d13fd0 avm1: Implement Number class 2020-01-21 18:24:49 -08:00
Mike Welsh b49357e46f avm1: Boxing a value calls the object constructor 2020-01-21 18:24:49 -08:00
Mike Welsh ccf62979a1 avm1: Implement String methods 2020-01-21 18:24:49 -08:00
Mike Welsh 5f12ce78b6 tests: Add string method tests 2020-01-21 18:24:49 -08:00