Commit Graph

521 Commits

Author SHA1 Message Date
EmperorBale f8289b47d8
avm2: Implement call stack & stack traces (#7564)
* avm2: Implement call stack

* avm2: Class traits should have a special prefix

* avm2: Stack tracebacks should also contain error message

* avm2: Move method naming to Executable

* avm2: Handle getter and setter methods in tracebacks

* chore: Formatting

* chore: Add comments

* avm2: Make full_name write to a string, instead of creating a new one

* core: Make GcArena publicly accessible

* core: Add Deref impl for Either type

* desktop: Add AVM2 call stack to panic message

* avm2: Prefix native methods with a `/`

* chore: Appease clippy

* avm2: Check if method actually contains bytecode instead of unwrapping

* web: Add AVM2 stack trace to panic message

* chore: Formatting

* chore: Clippy

* avm2: Fix stack traces for free standing functions

* core: Remove global data from context

* core: Rename GcGlobalData to GcCallstack

* core: Introduce StaticCallstack, make GcArena private again

Co-authored-by: Adrian Wielgosik <4729533+adrian17@users.noreply.github.com>
2022-08-28 18:30:20 +02:00
= b7dcd26c38 core: Use Cow<str> for FullscreenError in UI backend, as it can't ever be anything else 2022-08-25 23:43:21 +02:00
= 0084991e58 web: Replaced generic error in audio with JsError, as it's the only one thrown 2022-08-25 23:43:21 +02:00
= 5b5ee7d448 core: Made audio backend use actual real error enums, and not box<error> 2022-08-25 23:43:21 +02:00
Aaron Hill 98c7f443ce core: Only store viewport dimensions in `RenderBackend`
Previously, the viewport height and width were stored in
both `Stage` and the `RenderBackend`. Any changes to the viewport
dimensions (e.g. due to window resizing) needed to be updated in both
places to keep our handling of the viewport consistent.

This PR adds a new `ViewportDimensions` type, which holds the
width, height, and scale factor. It is stored inside the
`RenderBackend` impl, and is retrieved using the newly added
method `RenderBackend.get_viewport_dimensions`. After a `Player`
has been constructed, any code that needes access to the viewport
dimensions will ultimate go through this method.

Unfortunately, `Stage` needs to use the viewport dimensions
in `build_matrices`. Therefore, any code modifying the viewport
dimensions should go through `player.set_viewport_dimensions`,
which ensures that the stage matrices are rebuilt after the render
backend is updated.
2022-08-22 13:44:30 -07:00
Adrian Wielgosik b18329c8fe web: Allow modifying player volume via JS 2022-08-20 11:53:42 -07:00
Mike Welsh 82cc097084 web: Bump audio buffer size to 4096
Avoid stuttering on some browser & hardware configurations.
2022-08-14 20:07:05 -07:00
relrelb d70697b4f3 web: Refactor `WebNavigatorBackend`
Store `base_url` as `Option<Url>` instead of `Option<String>`, so
we don't need to parse it on each URL resolve.
2022-08-14 17:49:05 -07:00
relrelb e42a6b62e6 core: Require `target` in `NavigatorBackend::navigate_to_url`
Make the `target` parameter just a `String` instead of an `Option<String>`.
`None` is not needed as it's totally equivalent to an empty string.
2022-08-06 11:20:03 +03:00
Daniel Jacobs ce95f01de3 web: Include uncompressed length of SWF in metadata 2022-08-03 09:17:24 +03:00
Mike Welsh ffb57467eb audio: Add `AudioBackend::position_resolution`
This returns the approximate interval that the audio backend
updates the sound position information. This is used for syncing
animation to embedded "stream" audio tracks, and fixes some
stuttering in cases where the syncing was being too strict.
2022-07-28 21:25:33 -07:00
Mike Welsh 9fb46c71ad web: Use `AudioBufferSourceNode` for web audio
On web:
 * Mix audio on the Rust side, piping to `AudioBufferSourceNode`.
 * Decode MP3 using `symphonia`.
2022-07-28 21:25:33 -07:00
relrelb f643048c1c core: Introduce `Request`
Which holds both a URL and what was `RequestOptions` formerly.
2022-07-09 09:43:42 +03:00
relrelb 65be2adc63 wgpu: Bump to `0.13.0`
Based on the work in #6717, plus additional adaptions mentioned in
https://github.com/gfx-rs/wgpu/blob/master/CHANGELOG.md#wgpu-013-2022-06-30,
and more not-mentioned but required changes.

Also bump `wasm-bindgen` to `0.2.81` (along with its helper crates), as
required by the new `wgpu` version.

Note that I don't fully understand some of the required changes, notably:
* `wgpu::PresentMode::Mailbox` no longer works on my machine (Windows 11) -
The `wgpu` documentation says that `wgpu::PresentMode::Fifo` is the
only guaranteed to be supported, so I switched over to it instead.
* `self.staging_belt.recall()` doesn't return a `Future` anymore -
I assume it became synchronous so I simply removed the `executor`
from there.
2022-07-02 16:44:37 -07:00
relrelb 9b9301fbaf chore: Appease clippy 2022-07-02 09:22:18 -07:00
relrelb 87ce0f56b7 core: Remove `NavigatorBackend::resolve_relative_url`
The resolved URL only used by `NavigatorBackend::fetch`. So simply
inline `NavigatorBackend::resolve_relative_url` into `NavigatorBackend::fetch`,
per implementation.
2022-05-07 09:06:53 -07:00
relrelb ea665d91f2 core: Introduce and use `Response::url` 2022-05-07 09:06:53 -07:00
relrelb 2517d8de4b core: Introduce struct `Response`
Currently it's a trivial wrapper around `Vec<u8>`, but more fields
will be added in the future (e.g. response URL, HTTP status code).
2022-05-07 09:06:53 -07:00
relrelb f6153ff7c1 chore: Appease clippy 2022-05-06 10:36:38 -07:00
Mike Welsh 1eb06908c8 core: Make PlayerBuilder::build infallible 2022-04-29 09:14:32 -07:00
Mike Welsh f48182ef3d core: Add various settings to PlayerBuilder 2022-04-29 09:14:32 -07:00
Mike Welsh e1e2b1008a core: Add PlayerBuilder 2022-04-29 09:14:32 -07:00
Mike Welsh 3305ac69c4 web: Support wmode parameter 2022-04-17 08:33:51 -07:00
Mike Welsh 8131a4f3cc web: Allow transparent stage 2022-04-17 08:33:51 -07:00
Mike Welsh 78e8578414 chore: Avoid error when using wgpu feature on web
Avoid compilation error when running clippy on the web package
without a `wasm32` arch.
2022-04-11 20:15:13 -07:00
relrelb 7497fb7008 core: Change `Player::set_root_movie` to accept a `SwfMovie`
Move the `Arc::new` to within the function.
2022-04-08 15:16:25 -07:00
relrelb 6d7edd1854 web: Use `Uint8Array::to_vec()` over `Uint8Array::copy_to()`
It's shorter and should be more efficient (allocates an uninitialized
buffer instead of a zeroed one).
2022-04-09 00:27:16 +03:00
Mike Welsh 755676c64e chore: Remove doc comments from extern blocks
Doc comments are ignored here and can generate warnings, so change
to regular comments.
2022-03-27 18:56:13 -07:00
relrelb ad944800be core: Perfer `Loader`'s `FetchError`
`NetworkError` and `NetworkUnavailable` were rarely used, and they
were very similar to `FetchError`.
2022-03-17 20:31:59 -07:00
relrelb 8a17d88c77 core: Remove `NavigatorBackend::time_since_launch`
`core` already depends on the `instant` crate which abstracts
`std::instant::Instant` and polyfills it on Web. Use it to replace
`NavigatorBackend::time_since_launch` in order to make `NavigatorBackend`
a little smaller and more simple.
2022-03-17 00:08:44 +02:00
relrelb 031126a1b8 core: Remove `LocaleBackend`
Previously there were 3 implementations of `LocaleBackend`:
`DesktopLocaleBackend`, `WebLocaleBackend` and `NullLocaleBackend`.

While `DesktopLocaleBackend`, `WebLocaleBackend` were identical,
`NullLocaleBackend` always returned a fixed date/time for tests
determinism.

Unify them in a single file, and use `cfg!(test)` and a new dedicated
`deterministic` feature to decide whether to mock date/time or not.
This should not cause any behavioral changes.
2022-03-16 19:57:53 +02:00
Mike Welsh 55da3cd7d0 chore: Add .cargo/config.toml for workspace-level lint config
Currently it is not directly possible to configure lints for the
entire workspace via TOML, which forced us to repeat `#![allow]`
blocks in each crate.

embark pointed out this workaround to configure lints at the
workspace level via RUSTFLAGS:

https://github.com/EmbarkStudios/rust-ecosystem/issues/22#issuecomment-947011395

Remove the common `#![allow]` blocks and switch to this method for
global lint config.

Temporarily allow `needless_borrow` lint, buggy pending this fix:
https://github.com/rust-lang/rust-clippy/pull/8355
2022-01-29 14:22:44 -08:00
TÖRÖK Attila db6731be2c web: Detect and log whether WebAssembly extensions are actually used 2022-01-12 11:29:16 -08:00
relrelb 82b4c6ef27 core: Support mouse buttons in `KeyCode`
Add `MouseLeft`, `MouseRight` and `MouseMiddle` to `KeyCode` for
AVM1's `Key.isDown()` function.
2022-01-10 01:18:49 -08:00
Mike Welsh bb3ef68499 web: Handle gaps in MP3 SoundStreamBlock tags 2022-01-07 13:23:53 -08:00
relrelb 07c5330456 core: Introduce `InputManager`
`InputManager` encapsulates the common logic that previously the
`UiBackend`s used to implement.
2021-12-15 14:20:30 -08:00
relrelb a4b2e38f4d web: Track `keys_down` by `KeyCode`
This makes `WebUiBackend::is_key_down` a simple one-line check.
2021-11-25 07:35:33 +02:00
Tal Hayon 7ed38850fd core: implement displayState for Stage in avm1/2 2021-11-11 16:20:05 -07:00
Mike Welsh 4141909bcb web: Support wgpu on web
Add wgpu feature to web build (disabled by default currently).
2021-10-24 17:20:19 -07:00
Mike Welsh 04d84a3386 web: Implement WebAudioBackend::get_sound_position 2021-10-16 22:53:25 -07:00
Mike Welsh bca31b2c51 audio: Grab Sound.position from audio backend
* Change `AudioBackend::get_sound_position` to return `f64` to
   match `AudioBackend::get_sound_duration`.
 * Wire up `AudioBackend::get_sound_position` to `Sound.position`.
 * Remove unimplmeneted warning from `Sound.position`.
2021-10-16 22:53:25 -07:00
Chris Midgley c5ad8e76ee
audio: Fail to create invalid ADPCM decoder 2021-10-13 23:12:32 -07:00
Tal Hayon 72a811ae2c web: support no trailing slash in base parameter 2021-09-12 16:02:29 -07:00
Chris Midgley 2abea5aeba
web: don't panic if failing to create an audio buffer 2021-09-11 15:48:30 -07:00
Daniel Jacobs 5ac9796ffd web: Support salign, quality, & scale embed/object attributes (part of #4258) 2021-09-08 16:25:47 -07:00
Tal Hayon e7bff63149 web: check array_buffer promise for failure 2021-09-07 16:59:01 -07:00
Tal Hayon 4625ca0e0b web: fix base param 2021-09-07 16:45:35 -07:00
David Wendt 116fb1f323 avm2: Impl `Sound.play`
This does not (yet) implement the third `SoundTransform` parameter on `play`.
2021-09-03 16:47:02 -06:00
David Wendt 3b6eea2a1d core: Report sound duration as `f64` and round down in AS1 2021-09-03 16:47:02 -06:00
David Wendt 89b411593f avm2: Impl `Sound.bytesTotal` 2021-09-03 16:47:02 -06:00
Daniel Jacobs 3982f3af98 web: Support menu embed/object attribute (part of #4258) 2021-08-28 14:56:35 +02:00
Tal Hayon 8cb5cf0252 web: Adds support for base embed/object attribute (Part of #4258) 2021-08-19 21:22:47 +02:00
relrelb ac3c198bda chore: Appease clippy 2021-08-18 08:01:57 +03:00
Adrian Wielgosik b940e7f00f Extension: Sidestep CORS issues by offering to load the SWF in a tab 2021-08-02 21:28:16 +02:00
relrelb 0fd1c05fd5 chore: Use into() in more places 2021-06-22 11:49:41 -07:00
relrelb f82faf9603 chore: Appease clippy 2021-06-05 10:16:00 -07:00
Mike Welsh 2b98c878f0 swf: Use Fixed in more places 2021-05-30 21:24:03 -07:00
Mike Welsh 22948789b8 web: Add MovieData.isActionScript3 and backgroundColor 2021-05-23 23:02:38 -07:00
Mike Welsh e1439f4105 swf: Add HeaderExt struct providing additional info
When reading an SWF, search for FileAttributes and
SetBackgroundColor and return this along with the header data
because it's useful (in particular, the AS3 flag).
2021-05-23 23:02:38 -07:00
Mike Welsh 61e20024e9 chore: Appease clippy 2021-05-22 20:28:31 -07:00
CUB3D cd1cde1708 avm1: Implement de/serialization of shared objects into Flash Player Lso format 2021-05-09 23:20:32 -07:00
Mike Welsh ba7fd1b2b9 chore: Appease clippy, bump url
Bump url and avoid `Url::into_string` deprecation warnings.
Fix `single_char_pattern` clippy lints.
2021-05-07 20:51:26 -07:00
Moulins 272841729e core: Replace SwfMovie's PropertyMap by a list of key-value pairs
PropertyMap is an AVM1-only concept, and shouldn't be used on cross-VM
types.
2021-05-03 13:47:14 -07:00
Mike Welsh dca97afdd7 chore: Remove puremp3 feature
Wasn't being used, remove the puremp3 dependency.
2021-05-02 19:31:01 -07:00
Mike Welsh 6cf8b660d5 web: Remove unwraps from Rust glue
* Remove all unwraps from web/lib.rs.
 * Add convenience methods for grabbing the Ruffle web instance.
   These methods also avoid panics/unwraps when borrowing
   `RefCell`/`Mutex`.
 * Use `warn_on_error` to avoid unwraps from web APIs.
2021-05-02 18:45:04 -07:00
Adrian Wielgosik 8ca22c1f02
core: Support for custom context menu items on movie root 2021-05-02 15:28:00 -07:00
Adrian Wielgosik a1737b5922 avm1: Respect menu.builtInItems, but on root clip only 2021-04-27 16:42:02 -07:00
Adrian Wielgosik ce4d66e0f4 avm1: support Stage.showMenu 2021-04-27 16:42:02 -07:00
Adrian Wielgosik 41a126885c web: Minimal context menu buttons for movie control 2021-04-27 16:42:02 -07:00
David Wendt 0c6584ca03 core: Store the viewport's scale factor on the stage 2021-04-26 01:15:42 -07:00
Mike Welsh d34b72cc47 web: Expose SWF metadata to JavaScript
Add `RufflePlayer.metadata` that exposes the SWF header fields to
JavaScript.

Add `RufflePlayer.readyState` and fire a `loadedmetadata` event
once the metadata is available, mimicking the HTML5 media APIs.
2021-04-23 16:58:24 -07:00
relrelb 79bcee07f5 audio: Properly round sound duration
Previously it was always rounded down. Change it to the nearest
integer.
2021-04-17 09:11:50 -07:00
EmperorBale e36ad2874b chore: Make error message more helpful 2021-04-06 16:01:34 -06:00
EmperorBale 51e2ebf492 web/desktop: Check the HTTP status of requests 2021-04-06 16:01:34 -06:00
David Wendt de1b0d4d0c core: Add support for an explicit loader URL (though nothing sets it yet) and expose it in `LoaderInfo`. 2021-04-05 16:18:37 -06:00
EmperorBale 760e8421ab
web: Fix URL sanitizing (fix #3444) 2021-03-20 23:02:57 -07:00
Tempy111 00e1f36984 core: Add missing support for Tab keycode 2021-02-27 16:44:39 -08:00
Mike Welsh 3099914374 chore: Appease clippy 2021-02-27 16:10:46 -08:00
Mike Welsh 2c53b4bed2 chore: Appease clippy 2021-02-19 02:47:39 -08:00
Ben Lubar ca5cf0553f web: Add maxExecutionDuration to Config (close #1773) 2021-02-16 20:31:40 -08:00
David Wendt 299790b592 video: Enable software video decoding on web and exporter. 2021-02-16 19:03:48 -08:00
David Wendt 80bceeacab core: Add `VideoBackend` to host video decoders 2021-02-16 19:03:48 -08:00
relrelb bb89391f3a chore: Avoid deprecated constants
The Rust documentation considers numeric constants prefixed with std::
as deprecated.
For example: https://doc.rust-lang.org/std/u16/constant.MAX.html.
2021-02-12 06:36:17 -08:00
Mike Welsh e5fb1f09e7 chore: Appease clippy
* #[derive(Collect)] should be before #[collect]
 * Replace redunant `&buf[..]` with `buf`
 * Changes most cases of UPPERCase to UpperCase
 * Allow upper_case_acronym on most SWF types, as they are from
   SWF spec/more annoying to change.
2021-02-12 06:32:42 -08:00
Mike Welsh 16bd7fade6 web: Use case-insensitive check for detecting javascript scheme 2021-02-08 03:41:16 -08:00
relrelb 074731e1a4 audio: Add Nellymoser support 2021-02-02 00:41:01 -08:00
Mike Welsh 07ab770d4c web: Fix panning of mono sounds (fix #3017) 2021-02-01 13:18:24 -08:00
Mads Marquart 1990e51639 avm2: Add UiBackend::display_unsupported_message
To allow displaying rich content when unsupported ActionScript 3 content is encountered.
2021-01-31 23:04:20 -08:00
Brian Gontowski 31dd2729e2 web: Add an onFSCommand callback into JavaScript 2021-01-31 18:03:31 -08:00
Toad06 b62ca3d589
web: Move `allowScriptAccess` to `BaseLoadOptions` 2021-01-30 16:59:58 -08:00
relrelb 7431cd9b10
core: Merge InputBackend into UiBackend 2021-01-30 16:36:45 -08:00
Mike Welsh 008f0f596c core: Clip event slices are from parent movie in PlaceObject
Since 19034b7, clip event scripts are returned as slices from the
SWF. This caused a panic when a movie was loaded into a clip,
because the loaded clip's `movie` would be used as the source for
clip events. However, clip events are placed by the parent's
PlaceObject tags, so the movie in this case should be the parent's
movie.

Fixes #2870.
2021-01-28 16:36:42 -08:00
Mads Marquart bb4240ad1f chore: Add a few comments about unsafe usage 2021-01-28 14:39:35 -08:00
Mike Welsh a4699a3ca5 audio: Sound transforms apply to stream sounds
This unifies the code path for event sounds and stream sounds.
Both `AudioBackend::start_stream` and `start_sound` return a
`SoundHandle`. `stop_stream` is removed (`stop_sound` can be
used for both cases).

Also removes references to `CharacterId` from the `AudioBackend`
(instead, an increasing ID is returned to identiy streams while
loading).
2021-01-27 15:25:04 -08:00
Mike Welsh 95ce2abf17 audio: Remove AudioBackend::stop_sounds_with_handle/is_sound_playing_with_handle 2021-01-27 15:25:04 -08:00
Mike Welsh da2dd3b36c core: Implement sound transforms and Sound.setPan 2021-01-27 15:25:04 -08:00
Mike Welsh 34f60b127a core: Add AudioManager to handle actively playing sounds
Add an AudioManager struct to handle this list of actively playing
sounds. This will maintain information for each sound instance,
such as the owning display object, AVM1 object, etc.

This will allow us to implement the awkward AVM1 Sound API in a
fairly backend-agnostic way.
2021-01-27 15:25:04 -08:00
Omar Shehata 218f1f1da5 web: Pause player when tab is inactive (close #347) 2021-01-26 22:34:43 -08:00
Mike Welsh 78f85d96f0 chore: Remove some debug spew 2021-01-21 18:22:42 -08:00
Adrian Wielgosik b69e17bf35
web: Allow customizing log level 2021-01-19 18:10:35 -08:00
Mike Welsh da1e2801a2 chore: Appease clippy 2021-01-18 21:23:50 -08:00
Toad06 5ed30303eb web: Remove event listeners when a Ruffle instance is destroyed 2021-01-14 13:06:37 -08:00
Mike Welsh 9bb36885bb web: Add backgroundColor option and support bgcolor attribute
Add `backgroundColor` setting to the config options, allowing
a user to override the background color of an SWF. The polyfill
will now look for the `bgcolor` HTML attribute on the embed
and fill in this setting appropriately.
2021-01-13 11:57:19 -08:00
Toad06 0d7f64aa67 web: Only run JS scripts when `allowScriptAccess` is true 2021-01-11 13:16:00 -08:00
Toad06 7480e836ec web: Changes from review 2021-01-11 13:16:00 -08:00
Toad06 0131665149 web: Fix clippy 2021-01-11 13:16:00 -08:00
Toad06 f48d5b424b web: Fixes and improvements in `navigate_to_url` 2021-01-11 13:16:00 -08:00
TÖRÖK Attila cce3a8199d web: Add a config option to disable the message about unsupported content 2021-01-10 16:02:23 -08:00
Mike Welsh 01aca9f861 web: Remove upgrade_to_https param from Ruffle::new
Grab it from the `config` directly instead of using an extra param.
2021-01-07 11:46:07 -08:00
Mike Welsh 8728804f28 web: Add letterbox config option 2021-01-07 11:46:07 -08:00
Mike Welsh e9da6a13f0 core: Add letterbox setting
Player::set_letterbox can be used to control the letterbox behavior.
 * Letterbox::Off => no letterbox (flash behavior)
 * Letterbox::Fullscreen => letterbox only in fullscreen (web default)
 * Letterbox::On => always letterbox (desktop default)
2021-01-07 11:46:07 -08:00
Mike Welsh e6614a8527 web: Avoid panic on fetching invalid URLs 2020-12-31 16:36:02 -08:00
Mike Welsh 972e743e34 web: Flush shared objects in unload intead of beforeunload
Fix part of #2092. A panic could occur if content navigated away
using getURL, which could trigger the shared object flush while
the frame was still executing. Move the flush to "unload" so that
it occurs after execution is complete.
2020-12-27 14:01:42 -08:00
Sam Morrow 38bdb8b39a web/desktop: Add basic dialog handling (closes #1978) 2020-12-23 19:08:18 -08:00
Mike Welsh 367404ddd8 core: SharedObjects are bucketed by domain
Key SharedObjects on the domain and path where the SWF is hosted,
and implement the localPath and secure parameters.

Fix #855.
2020-12-22 14:18:06 -08:00
Mike Welsh 739af3f8d7 web: Flush shared objects on page unload 2020-12-21 21:46:45 -08:00
Sam Morrow c4d7b24629 web: Fix cors issues with http (close ruffle-rs#1486) 2020-12-14 05:51:28 -08:00
Mike Welsh 7e35d4a4fc web: Ensure parent window/frame gets focus on click (fix #1704)
Call window.focus() on mouse down to ensure the player receives
subsequent key/mouse events when it is inside a frame.
2020-12-10 19:20:00 -08:00
Mike Welsh 3bafee63a6 web: Fix spurious keyUp events (fix #1886) 2020-12-08 21:12:59 -08:00
Mike Welsh b76d76d244 web: Properly handle multibyte characters in text input
We were checking for byte length == 1 instead of # of characters
to determine if a keyboard key was a single printable character.
Thanks to @JMcKiern for pointing this out.
2020-12-05 23:19:57 -08:00
Mike Welsh dafe7e5027 avm1: Implement Key.getAscii 2020-11-29 02:31:10 -08:00
Mike Welsh e655cf0c08 web: Add Ruffle::audio_context getter 2020-11-24 16:36:33 -08:00
Nathan Adams 5b5091b4b9 web: Rename copy_to_audio_buffer to copyToAudioBuffer 2020-11-24 16:36:33 -08:00
Nathan Adams 3ad4c0f392 web: Rename RufflePlayer.on_callback_available to
RufflePlayer.onCallbackAvailable
2020-11-24 16:36:33 -08:00
Nathan Adams 8abb8df299 web: core no longer uses webpack, but selfhosted still does 2020-11-24 16:36:33 -08:00
Nathan Adams 5ff7168fe9 web: Switched core package from javascript to typescript 2020-11-24 16:36:33 -08:00
Mike Welsh d13a95eafa web: Fail gracefully if LocalStorage is unavailable (fix #1590) 2020-11-19 22:51:02 -08:00
relrelb 9068322d24 web: Retain focus on fullscreen enter/exit
Previously, has_focus has been set to false upon window click, and
to true upon canvas click.
However, the canvas didn't receive click events when the context
menu was clicked, so fullscreen toggle led to focus loss.
Listening to player click events receives both canvas and context
menu clicks.
2020-11-18 17:50:12 -08:00
relrelb 2e0509694c docs: Miscellaneous spelling corrections 2020-11-12 13:34:05 -08:00
Mike Welsh 316bc4e920 chore: Appease clippy 2020-11-09 01:52:57 -08:00
Nathan Adams d7b94316c6 web: Always set the end point of audio clips - fixes #1304 2020-11-03 15:15:34 -08:00
Nathan Adams 32b57f15bc web: Fixed backspace and delete keys not registering in input fields 2020-11-02 11:43:10 -08:00
Mike Welsh ef4d75e7d9 web: Fix incorrect handle used in audio ended handler (fix #1405) 2020-10-27 19:54:46 -07:00
Mike Welsh 956f40a26f web: Use a Drop impl to ensure sounds are stopped 2020-10-25 20:41:20 -07:00
Mike Welsh 796805c31b web: Avoid bug in generational-arena (fix #1315)
An issue with Arena::clear allowed stale sound instance indices
to be remain valid, causing certain sounds to be removed when they
shouldn't (#1315). Workaround this issue by forcing Arena to bump
the generational index.
2020-10-25 20:41:20 -07:00
Mike Welsh 2172fef9bd web: Only fire mouse events for left clicks 2020-10-23 12:50:59 -07:00
Mike Welsh 827a80c837 web: Remove sound instances upon completion
Sounds were not being removed from the instance list when they
completed playing. This could also cause StartSound tags with
NoMultiple set to not play, because the previous sound was presumed
to be playing.

Fixes part of #1245.
2020-10-12 15:28:31 -07:00
Nathan Adams 627a1f90e1 web: Ignore any errors converting flashvars 2020-10-12 15:28:16 -07:00
Nathan Adams 6d9155477c core: Add flashvars support - #312 2020-10-12 15:28:16 -07:00
Mike Welsh 4034ef8d79 web: Use PanicInfo::to_string for displaying panic info
PanicInfo::payload wasn't giving anything useful (just resulted
in 'Unknown error') -- to_string displays all of the message,
payload, and location of the panic. Particularly the location
is helpful.
2020-10-11 00:51:00 -07:00
Sean-Thomas a9538f81d0 web: Renamed "prime_audio" and "suspend_audio"
Renamed "prime_audio" and "suspend_audio" to "play" and "pause" respectfully.
2020-09-29 11:05:23 -07:00
Sean-Thomas 6b54cc4311 web: Add pause method for web player
Adds a suspend_audio method to compliment prime_audio on WebAudioBackend, as well as logic in player.rs on the set_is_playing method to suspend audio when is_playing is set to false. Exposes pause method for the ruffle player in JavaScript with logic to display the play button when paused.
2020-09-29 11:05:23 -07:00
Mike Welsh 313b02d24f webgl: Fall back to canvas if not using hardware acceleration
Display WebGL driver info, detect whether hardware acceleration
is enabled, and fall back to the canvas backend in this case.
2020-09-25 01:22:21 -07:00
Luca Weiss d5cb396331 *: fix spelling mistakes 2020-09-19 16:17:58 -07:00
Nathan Adams e114282a4e web: Implement Show Error Details for panics 2020-09-13 15:20:44 -07:00
Nathan Adams 69d1e903fb web: Destroy shouldn't be able to throw exceptions 2020-09-13 15:20:44 -07:00
Nathan Adams 58cd1abcf2 web: Store RuffleInstances as a RefCell, so we don't lock it out from readers unless we actually need to 2020-09-13 15:20:44 -07:00
Nathan Adams 1d48073a05 web: Don't mutably lock INSTANCES if we don't need to, to allow greater odds of a successful reentry 2020-09-13 15:20:44 -07:00
Nathan Adams 95275898c7 web: If ruffle panics, inform all instances (if possible) and poison future instances 2020-09-13 15:20:44 -07:00
Nathan Adams 3ff399ca6b core: Trace only to the log backend, but have the default log backend trace to the log crate 2020-09-13 13:51:39 -07:00
Nathan Adams 4c6c8ee1f2 web: Add trace_observer to web api, which lets you capture trace output from a specific movie 2020-09-13 13:51:39 -07:00
Nathan Adams de009c7673 core: Add Log backend, for capturing trace output specific to a movie 2020-09-13 13:51:39 -07:00
Mike Welsh a18e80baf2 chore: Fix clippy lints 2020-09-07 12:18:41 -07:00
Nathan Adams 91cb597a79 web: Expose ExternalInterface callbacks on the player object, not the canvas 2020-09-03 18:17:44 -07:00
Nathan Adams 5880db43cd web: Respect allowScriptAccess, which defaults to false for streaming or 'sameDomain' for objects 2020-09-03 18:17:44 -07:00
Nathan Adams b5531a48d0 web: Allow reentrant ExternalInterface callbacks 2020-09-03 18:17:44 -07:00
Nathan Adams a49e8d8587 web: Implement two-way communication with ExternalInterface 2020-09-03 18:17:44 -07:00
Nathan Adams 43f5506418 web: Implement LocaleBackend for web 2020-09-02 17:12:31 -07:00
Nathan Adams 86eb6f2e50 avm1: Implement Date - #249 2020-09-02 17:12:31 -07:00
Nathan Adams cb2461920b core: HTTP request values need to preserve order 2020-08-28 11:53:32 -07:00
Mike Welsh cab1634624 web: Ensure Key.getCode is set on keyUp
Fixes sticking keys in #1046.
2020-08-26 15:16:46 -07:00
Mike Welsh eaff74f364 web: Wire up mouse wheel events 2020-08-23 13:38:59 -07:00
Mike Welsh cbd448522a chore: Allow unknown clippy lints
same_item_push was added on nightly, but is currently throwing
a false negative. I added an allow for it, but this causes a
warning on stable for an unknown lints, so allow unknown lints for
now.
2020-08-12 23:51:12 -07:00
Mike Welsh 6c89869210 chore: Fix clippy lints 2020-08-12 19:04:14 -07:00
David Wendt c926da8888 Refactor URL relativization into two utility methods that backends can provide base URLs and paths to. 2020-07-23 23:02:54 -04:00
David Wendt 7433bfe28f Add a `NavigatorBackend` method to resolve relative URLs. 2020-07-23 23:02:53 -04:00
David Wendt 4813942fe7 The player should always change the audio backend's framerate itself. 2020-07-23 23:02:52 -04:00
David Wendt f56d16a68d Separate player creation from root movie setup, and allow users of Ruffle to load in movies synchronously or asynchronously.
During the small period of time when a player is created but has no root movie, a temporary empty movie is installed with an assumed stage size and framerate of 550x400@12fps. This is Flash default for new projects, so it seemed appropriate. User ActionScript cannot see these values, and I'm not even sure JavaScript can, either.
2020-07-23 23:02:51 -04:00
David Wendt 6998dafdb9 Store an origin URL on every movie that is loaded. 2020-07-23 23:02:50 -04:00
Mike Welsh 8e97fdfe0c web: Fix WebAudioBackend::stop_sounds_with_handle (fix #752)
This would incorrectly stop all audio nodes whenever a Stop sound
event was encountered.
2020-06-25 23:04:47 -07:00
CUB3D 166cb60d89 chore: Clean up useage of unwrap 2020-06-24 01:46:07 +01:00
CUB3D 2538d430ff chore: Format 2020-06-24 01:46:07 +01:00
CUB3D 0644168f12 web: Scope entries in localStorage to the current url (#379) 2020-06-24 01:46:07 +01:00
CUB3D 711b202a56 web: Add storage backend based on LocalStorage 2020-06-24 01:46:07 +01:00
CUB3D 4e286b43ae chore: Format 2020-06-24 01:46:06 +01:00
CUB3D 752ffc5cca chore: Fix clippy lints and tests 2020-06-24 01:44:07 +01:00
Nathan Adams 59ccd75518 core: Rename loader::LoaderError to loader::Error 2020-06-20 15:02:00 -07:00
Nathan Adams 0f1eef9022 core: Introduce LoaderError to all Loader methods 2020-06-20 15:02:00 -07:00
Nathan Adams 5662b2d4d9 core: Make Value::coerce_to_string return a Cow<str>` 2020-06-19 12:48:28 -07:00
Mike Welsh 33cbc1fe2f web: Avoid panics on unimplemented audio codecs 2020-06-17 12:14:08 -07:00
Mike Welsh 83feeefeeb audio: Don't panic on unimplemented codecs
Remove `unimplemented` calls when encountring unsupported codecs
such as Nellymoser. Instead, return an Error that can be
gracefully handled.
2020-06-17 12:14:08 -07:00
CUB3D 54701f775e web: Add dummy set_clipboard impl 2020-06-09 22:41:11 +01:00
Nathan Adams 91b0b28aa8 web: Fixed Key.isDown(13) (enter key) detection on web 2020-06-04 13:41:10 -07:00
Mike Welsh 3a8c705e95 chore: Fix clippy lints 2020-05-30 03:47:12 -07:00
Nathan Adams b8e63045b2 web: Moved source of core into core/src, to prep for tests 2020-05-19 11:42:54 +02:00
Nathan Adams b6523324ed web: Move each web package into a packages/ directory 2020-05-19 11:42:53 +02:00
Mike Welsh d15a4ed994 web: Fallback to canvas render backend in more cases (fix #545) 2020-05-14 22:36:19 -07:00
Nathan Adams 51d9f3ef36 core: Change Player::new to take in a SwfMovie, not &[u8] 2020-05-04 16:07:38 -07:00
Mike Welsh 936b314569 web: Add features for enabling webgl/canvas backend 2020-05-02 10:39:40 -07:00
Mike Welsh fa5c09b0cd web: Add WebGL render backend 2020-05-02 10:38:18 -07:00
Mike Welsh f09bd8c079 core: Clean up tick/render loop
Don't call `render` from `Player::tick`; instead, require the
frontends to explicitly call `render` when they wish to redraw.
The frontend can query `Player::needs_render` to see if the stage
is dirty and needs a redraw. Update desktop and web to use this
new method.

This fits better with the newer winit event loop model, which
requires explicitly calling `request_redraw`, and should avoid
spurious renders.
2020-05-02 04:25:21 -07:00
Mike Welsh 87bf0f44c4 render: Move canvas renderer to separate subcrate 2020-04-29 23:26:41 -07:00
Mike Welsh 0921f18417 web: Avoid out-of-bounds slice from zero sample SoundStreamBlock 2020-04-27 07:49:59 -07:00
Mike Welsh 8aa12d181f render: Remove RenderBackend::draw_pause_overlay 2020-04-27 04:45:53 -07:00
Mike Welsh c94df5243e web: Add nicer play button 2020-04-27 04:45:53 -07:00
Mike Welsh ddfd84ecdd web: Stop playing sounds when an instance is destroyed 2020-04-13 04:57:10 -07:00
Mike Welsh 0c0d3dfd41 core: Add Navigator::time_since_launch to use for getTimer
Change `ActionGetTime` (`getTimer`) to use a new backend method.
This allows it to return updated times if it is called multiple
times in a single frame. This fixes hangs caused by games that use
busy-loop "frame limiter" code.
2020-03-28 22:28:07 -07:00
Mike Welsh 5591cec0f7 web: Fix #412, incorrect bitmap rendering when cached 2020-03-24 23:08:15 -07:00
Mike Welsh 26914d7b62 web: Fix off-center gradient rendering
Regression caused by 223edb9. Write twips value to SVG matrix.
Addresses some incorrect rendering in #437.
2020-03-16 02:44:32 -07:00
Mike Welsh cd334bcd3f web: Fix bitmap fills not using twips 2020-03-02 18:31:49 -08:00
Mike Welsh 223edb9bc1 core: Matrix translation is in twips 2020-02-26 12:47:47 -08:00
Mike Welsh c4c02260fb core: Implement keyUp event 2020-02-26 03:48:07 -08:00
Mike Welsh acd5f2c74f web: Fix invisible cursor 2020-02-26 01:47:08 -08:00
Mike Welsh 86ec2c6cb8 input: Add InputBackend::set_mouse_cursor. Change cursor on buttons
It doesn't feel like Flash without having the hand cursor display
when hovering over buttons. First pass at implementing this;
core communicates which mouse cursor to use via
`InputBackend::set_mouse_cursor`.

TODO: Hand cursor only displayed for Button display objects
currently. Movie clips should also display this when they are in
"button mode" (when a button mouse event is set on them in AVM1,
or `buttonMode` property in AVM2).
2020-02-25 02:50:26 -08: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 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 f4e4171ebe Make spawned futures falliable, and report those errors. 2020-02-21 23:57:56 -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
Mike Welsh 6b7966f3fc chore: Update comments in canvas mask rendering 2020-01-31 20:27:24 -08:00
Mike Welsh 3ab0d4ef80
web: Merge #352, improved performance on canvas
Shape-drawing performance improvements on the canvas backend.
2020-01-30 15:16:09 -08:00
Mike Welsh 087f15f28c web: Clear audio decoding buffer before each decode (fix #357) 2020-01-29 12:29:54 -08:00
David Wendt abedb1262a Make sure `DrawImage` commands get the image filter. 2020-01-29 14:19:19 -05:00
David Wendt 30fc56649b Clamp u8 values to the [0, 255] range. 2020-01-29 14:19:19 -05: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
David Wendt 746971e38a Avoid unnecessary calls to `set_attribute`/`set_filter`. 2020-01-29 14:19:18 -05:00
David Wendt 693537a294 Line widths and miter limits should be in pixels, not twips 2020-01-29 14:19:18 -05:00
David Wendt b611067bc5 First pass on a more-optimized render path that uses canvas draw commands directly rather than precompiling SVGs as images. 2020-01-29 14:19:18 -05:00
David Wendt 4ee60d9214 Make `swf_shape_to_svg` output the entire `ShapeData` list itself, and also it's not called that anymore. 2020-01-29 14:19:18 -05:00
David Wendt 70cdcb60a7 Break shape data up into a series of canvas commands, including direct fills and strokes. 2020-01-29 14:19:18 -05:00
Mike Welsh 1223de9e94 web: Draw masks with 100% alpha (fix #348) 2020-01-22 12:08:57 -08:00
Nathan Adams 4ad6ef8b83 core: Implemented Key.getCode() 2020-01-17 15:11:38 -08:00
Mike Welsh 881581eed5 web: Resize canvas when devicePixelRatio changes (fix #322) 2020-01-15 21:34:22 -08:00
Mike Welsh f983af3f65 web: Fix decoding of PCM sounds 2020-01-15 21:12:45 -08:00
Mike Welsh ad719ad586 web: Fix timing of sound envelopes
The endTime parameter of AudioParam.linearRampToValueAtTime is
on the global AudioContext's timeline, not local to the sound.
Adding the sound's start time to the parameter fixes sound
envelopes not playing back correctly.
2020-01-15 20:38:43 -08:00
Mike Welsh 12ee4c7432 web: Duplicate left channel when playing a mono sound with envelope (fix #323) 2020-01-15 20:36:05 -08:00
Mike Welsh b57c827e23 web: Use proper key code for Enter key 2020-01-14 16:18:42 -08:00
Mike Welsh 79745feef7 chore: Use percent-encoding 2.1.0 2020-01-13 11:07:30 -08:00
Mike Welsh f576a39760 web: Fix must_use warning on AudioContext::decode_audio_data
web-sys 0.3.34 added `must_use` to `Promise`. Add `let _ =` to
squlech this warning.
2020-01-06 13:01:39 -08:00
Mike Welsh 4bf29f677f avm1: Implement Sound.duration
Add AudioBackend::get_sound_duration.
2020-01-03 17:11:00 -08:00
Mike Welsh d0142f1d67 audio: Add AudioBackend::stop_sound 2020-01-03 17:11:00 -08:00
Mike Welsh 87158647d1 core: Implement keyPress button events 2019-12-24 03:06:03 -08:00
Mike Welsh 30983c5bab web: Use pointer events on web 2019-12-23 13:16:58 -08:00
Nathan Adams 9000451d58 core: Implemented Mouse.show() & Mouse.hide() 2019-12-22 14:33:46 -08:00
Mike Welsh c05b03dd06 web: Handle keydown/keyup and preventDefault if Ruffle has focus 2019-12-21 19:08:06 -08:00
David Wendt 69094b56b5 Add input support to the web backend. 2019-12-21 19:08:06 -08:00
Nathan Adams eedc4bbe24 core: Added Input backend, currently unimplemented, for polling user input 2019-12-21 19:08:06 -08:00
Mike Welsh 29754eace8 web: Avoid `copyToChannel` on Safari
`AudioBuffer.copyToChannel` does not work on Safari, so switch to
using `getChannelData` to fill the audio buffers.

Limitations in wasm-bindgen prevent us from actually modifying the
data returned by `getChannelData` on the Rust side, so import a JS
function to fill the audio buffer (js-src/ruffle-imports.js).
2019-12-03 23:05:42 -08:00
Nathan Adams 35d80a254b chore: Use new method of setting png color & depth 2019-11-25 10:39:01 +00:00
Mike Welsh e3d0d9031d core: Handle empty JPEGTables tags (fix #116) 2019-11-11 17:08:08 -05:00
Mike Welsh b343ba14a2 web: Implement event sound envelopes 2019-10-30 19:26:19 -07:00
Mike Welsh 158f2a6fa2 web: Use SeekSamples to account for MP3 encoder delay 2019-10-29 23:36:51 -07:00
Mike Welsh f9b23c6e0c web: Handle gaps between SoundStreamBlocks 2019-10-29 23:36:51 -07:00
Mike Welsh 1a7959b96d audio: Initial syncing of stream sound to MovieClip timeline 2019-10-29 23:36:51 -07:00
Mike Welsh f07dfb4eb6 web: Implement ADPCM stream sounds on web 2019-10-28 02:51:46 -07:00
Mike Welsh eaea6aaf20 audio: Fix audio for ADPCM stream sounds
When a stream sound uses ADPCM compression, the ADPCM header is
included in each SoundStreamBlock (as opposed to stream sounds
in the other formats). This header wasn't being parsed, resulting
in corrupted audio (see https://homestarrunner.com/main12.swf).
2019-10-28 02:51:46 -07:00
Mike Welsh 4aec120ffb core: Add Bitmap display object
Converts the Bitmap character to a proper display object. This can
be instantiated directly in a PlaceObject tag in SWFv9 movies,
compared to the previous versions which indirectly references
bitmaps from Shape tags.
2019-10-11 16:33:58 -07:00