Commit Graph

1445 Commits

Author SHA1 Message Date
Mike Welsh d8079ac04a core: Stub out MovieClip.getRect
Just defer to getBounds for now. TODO: getRect should return bounds
ignoring strokes, so in reality it is <= getBounds.
2020-02-24 14:12:48 -08:00
Mike Welsh 993c05cf19 core: Calculate bounds for each morphshape frame 2020-02-24 14:12:48 -08:00
Mike Welsh a5c08f2e59 avm1: Implement MovieClip.getBounds and clean up bounding box methods
Implements MovieClip.getBounds, and also reorganized the
DisplayObject AABB methods:

 * `self_bounds` calculates the inherent untransfomed bounds of
 the object without children. All `DisplayObject`s must implement
 this method. For example, `Bitmap` returns the size of bitmap.
 Composite objects like `MovieClip` return a null AABB because they
 are made up of only children.
 * `bounds` calculates the untransformed bounds including children.
 * `local_bounds` calculates the bounds relative to the object's
 parent.
 * `world_bounds` calculates the bounds in global stage space.
 * `bounds_with_transform` calculates a tight AABB for the object
 with a given transform, and is used to implement the above.
2020-02-24 14:12:48 -08:00
Mike Welsh 73a9a0e771 tests: Add test for MovieClip.getBounds 2020-02-24 14:12:48 -08:00
Mike Welsh 8018c88870
core: Merge #120, initial multiple movie support
Initial support for loading multiple movies:
 * `loadMovie`/`loadMovieNum`
 * `loadVariables`/`loadVariablesNum`
 * XML loading
Desktop currently only loads from the local file system.
2020-02-24 12:47:18 -08:00
Mike Welsh 8c486b7544 chore: Use free functions for movie_clip methods
Try to keep style more consistent by using functions for all MC
methods. Previous was a mix of closures and functions (we're still
a little bad with this elsewhere)
2020-02-24 11:17:40 -08:00
Mike Welsh f163afc5b4 core: Use collect to copy level pointers 2020-02-24 02:28:27 -08:00
Mike Welsh 5315d059b9 desktop: Fetch from local filesystem for now 2020-02-24 01:49:28 -08:00
Mike Welsh 1b08fb538d chore: Rename layer -> level
Unify mix of 'layer' and 'level' in the code, and it's probably
better to stick with Flash nomenclature.
2020-02-23 23:41:55 -08:00
David Wendt 05e5fbb69c For some reason, this color transform code broke on the moviefetch branch 2020-02-22 00:02:52 -05:00
David Wendt abc1d00276 Fix incorrect preload of `_root` in `DefineFunction2` function calls.
This is caused by the fact that `avm.root_object` references the *current* stack frame, not the one we are about to introduce. Ergo, we need to pull the base clip of the *new* stack frame and find it's root.

This particular behavior only crops up in situations where there can be multiple root objects, at least until we implement `_lockroot`.
2020-02-22 00:02:51 -05:00
David Wendt 766ded6dfd When replacing a movie clip with another movie, don't wipe out the entire display object base as that disassociates us from our parent, siblings, and most importantly, *layer depth*. 2020-02-22 00:02:51 -05:00
David Wendt e0b4a0f193 Top-level layers are referenced via their path (`_leveln`) rather than name - in fact, their name is always the empty string. 2020-02-22 00:02:51 -05:00
David Wendt 00f88f9e87 Use the depth to indicate which layer a particular root clip is, and then use that to calculate it's `_leveln` path. 2020-02-22 00:02:50 -05:00
David Wendt 8ef759d377 Top-level layers do not get an instance name of `_leveln`. 2020-02-22 00:02:50 -05:00
David Wendt 9adf0f43d7 Allow levels to be read as scope variables, and add a test for this. 2020-02-22 00:02:50 -05:00
David Wendt 5a7e530c91 Add a test for cross-movie `_root`.
This test does not pass yet. Other layers need to resolve as target paths in order for this to happen.
2020-02-22 00:02:48 -05:00
David Wendt aa6aba13dd Abolish `context.root` completely.
`_root` is calculated dynamically based on the clip the currently executing function was called in.

Other things that used `context.root` have been changed to either update all layers or just update layer 0, which is the former `context.root`.
2020-02-22 00:02:46 -05:00
David Wendt 88b10f21c4 Implement an async executor for desktop so that these methods don't immediately panic. 2020-02-22 00:02:46 -05:00
David Wendt 33d26b9149 Shorten `Pin<Box<dyn Future<Output=Result<T,E>> + 'static>>` into `OwnedFuture<T,E>`.
This is technically stricter on `fetch` impls, but right now we can't support non-`'static` futures at all.
2020-02-22 00:02:45 -05:00
David Wendt aab339880d Implement `XML.load()`, with tests.
Interestingly enough, very little actually has to be done inside the async process for XML. The async process basically just fetches data and fires an event handler when it's done. Everything else is handled via a system builtin, `XML.onData`.
2020-02-22 00:02:45 -05:00
David Wendt 538a5f05e5 Add tests for various forms of `loadVariables`.
Surprisingly enough these tests passed without any changes, somehow.
2020-02-22 00:02:43 -05:00
David Wendt c00ecccd1f Basic, stub implementation of `MovieClipLoader.getProgress`, plus test.
This implementation just returns the size of the current loaded movie. The test is also deliberately written to be loose on timings so that it likely won't see a partially loaded movie. (I don't want it to be a test of load events, so I just wait a few frames, rather than the correct way of waiting for `onLoadComplete`.)

Until we support streaming file loads, we can't faithfully support these properties. Still, it's better to have them, just in case.
2020-02-22 00:02:42 -05:00
David Wendt 3f7e3a9ed8 Implement `MovieClipLoader.unloadClip`, with tests. 2020-02-22 00:02:41 -05:00
David Wendt a132226da4 Run `onLoadInit` at the *end* of a frame, rather than before the movie clip's own actions.
This is technically better, but it may make more sense to trigger `ClipEvent::Load` at the start of the next frame instead. Furthermore, I don't know if other forms of load events should trigger on the next frame (or end of the current one) like this.
2020-02-22 00:02:39 -05:00
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