Commit Graph

1470 Commits

Author SHA1 Message Date
David Wendt 55734619f7 `GetUrl2` can accept a `DisplayObject` as target in `LoadTargetFlag` mode.
I have no idea what happens to non-MovieClip objects, or if I'm really supposed to `coerce_to_string` here.
2020-02-22 00:02:36 -05:00
David Wendt d49c0e9bf7 Rewrite some of the unload and cliploader tests to be more generous with load timing.
Loads in Flash Player, like all web technologies, are asynchronous tasks of some kind (probably a separate thread). They appear to operate on some kind of a delay. If I `trace` each frame out, like in the previous version of `mcl_loadclip`, you get a series of events that look like this:

1. Parent frame 1
2. Parent frame 2
3. Event: onLoadStart
4. Event: onLoadProgress
5. Event: onLoadComplete
6. Parent frame 3
7. Event: onLoadInit

If I run that version of the test on Ruffle, everything happens after frame 1. This is an artifact of how we're testing asynchronous behavior in Ruffle. In order to guarantee test determinism, we have a dummy implementation of `fetch` that does a blocking load, and we poll all futures every frame of execution. This means that there is a very specific order of execution with these tests, which is good for testing, but probably isn't 100% accurate.

Flash Player appears to delay all loads by at least one frame, even loads that are coming from disk which should load immediately. I don't know if this is intentional or not, so I don't want to implement a load delay just for the sake of making tests pass. Ergo, I'm loosening the tests to just test the ability to load and unload movies, and fire events from a loader.

Specifically:

1. `mcl_loadclip` no longer traces out frames of the parent timeline
2. `unloadmovie` et. all use a target movie that doesn't fail the test until 10 frames have passed.

If someone can find a movie network that breaks with fast loading, then I'll consider implementing explicit frame delays for async tasks. Otherwise, this is how we're testing this.
2020-02-22 00:01:22 -05:00
David Wendt 8ece2d1b31 Add another ignored test, this time measuring the timing of load events broadcasted by `MovieClipLoader`. We're loading too early, which is why this is ignored. 2020-02-22 00:01:20 -05:00
David Wendt b56c3b6aed Fire events directly onto `broadcastMessage` instead of the individual event handlers on the `MovieClipLoader`, so that listeners run correctly.
Also, this fixes a double-borrow for `onClipInit`.
2020-02-22 00:01:19 -05:00
David Wendt 89e5dd97f3 Implement `MovieClipLoader.loadClip` 2020-02-22 00:01:19 -05:00
David Wendt 162b6b70f8 Allow unloading a movie by sending `None` to `replace_with_movie`.
This also adjusts `MovieClip.unloadMovie` to do just that, instead of removing the clip from the display list. We also have to unload clips when loading new movies into them, since `unloadMovie` desugars to loading `""` as the URL.
2020-02-22 00:01:19 -05:00
David Wendt 8ef4a94672 Add new tests for `unloadMovie`, `unloadMovieNum`, and `MovieClip.unloadMovie`.
They currently fail in Ruffle, so they're ignored.
2020-02-22 00:01:18 -05:00
David Wendt cc5dff4254 Add a test for `MovieClip.loadMovie`. 2020-02-22 00:01:17 -05:00
David Wendt 82d305a0f5 Add test for `loadmovienum` 2020-02-22 00:01:16 -05:00
David Wendt a9621da47d Add tests for `loadMovie`.
This test also includes changes to the SWF testing environment to allow asynchronous movie loads to execute.
2020-02-22 00:01:15 -05:00
David Wendt a8545ee277 Implement `onLoadInit` by pulling `LoadManager` into all clip load events. 2020-02-22 00:01:14 -05:00
David Wendt 7ff885a0de Implement `MovieClipLoader` event broadcasts for `onLoadStart`, `onLoadProgress`, `onLoadComplete`, and `onLoadError`.
Note that we do not implement `onLoadInit` yet - this requires some ability to trigger an event when another movie clip loads.
2020-02-22 00:01:14 -05:00
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 8d83bbb864 Impl fetch for web 2020-02-21 23:44:05 -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 4ffc255365 docs: Update README
Add sponsor and update status text.
2020-02-19 23:19:59 -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