把Flash游戏发布到Web上 探讨下可行路径?

软件工程师、主攻高级编程语言虚拟机的设计与实现

11 👍 / 15 💬

问题描述

我们公司做的Flash游戏(http://ssjj.4399.com/) 目前想做一个WebGL版本

选择一 是用JavaScript重写 但是考虑到已经开发了4年 积累的内容也很多 投入会很大,并且后期长期需要配备两套人员. 暂时不考虑

选择二 把ActionScript 3写的程序自动转换成JavaScript
a) 看到目前已经有llvm-js的后端 考虑做一个ActionScript 3的LLVM前端 生成LLVM IR 再用JavaScript的LLVM后端 生成JavaScript
同时要用js开发相应的库去适配 ActionScript 3目前用到的底层接口
b) 也可以先用ActionScript 3的编译器生成AVM2的bytecode 再从bytecode转换成LLVM的bitcode
后面的事情跟a是一样的。(有现有从Java bytecode 到 bitcode的例子可以做参考)

选择三 把ActionScript 3转换成Haxe
剩下的Haxe+OpenFL就搞定了
这个方案最容易开始 我们会先拿这个做尝试 但依据过往经验 没啥东西是没有坑的 肯定也会遇到各种问题

个人偏向方案二 感觉长线会更扎实点。

补充: 对公司而言,这是一个长线的考虑,并不是非常迫在眉睫的需求

基于我目前的能力没办法做出更深入的判断,只能动手做才知道会怎么样。但尝试成本不低。
求问下各位有经验的大侠 少侠。你们会怎么选择。

尝试了两个知友推荐的方案
1. Layabox
直接打开我们现有的项目编译 报编译错误,并且没有详细的编译出错信息 还没办法判断
2. Shumway
目前还不具有可用性 不少Flash API是unimplemented状态 想拿来就用目前还不行。

除了选项一很可控之外,其它选项坑多也是必然的…

但还是来说说吧。

选择二,题主要试试Shumway不?它可以直接支持Flash(SWF文件)的运行/播放,除了Flash DRM不支持外,其它Flash的功能已经支持了许多,是最接近题主所想的选择二的现有实现。

Shumway

-

mozilla.github.io/shumw

介绍Shumway的幻灯片:

Bring Video Games to the Web Today: Shumway and asm.js

(更新:题主测了一下现在的Shumway,看来实现得还不够完善,还不能拿来就用。)

题主在评论里说:

R大是觉得方案二太过梦幻 不具有可操作性?

其实不是。是Shumway就是题主所想像的选择二,而且比题主所想的 a) 和 b) 都更成熟。

题主所想的方案,本质上是一个 [AOT编译器 + 配套的运行时支持] 的方案。

(AOT: Ahead-of-Time,事先编译)

Shumway的实现是一个 [解释器+JIT编译器 + 配套运行时支持] 的方案,跟题主想要的其实已经挺接近了——它只是现在的实现不把生成的JavaScript保存下来而已。Shumway的架构未来是可以改造为支持AOT编译的,那样就跟题主所想的方案没差区别了(除了没用LLVM之外)。

(事实上Shumway曾经有过一个AOT编译器的部分实现:

shumway/aot.ts

,或许以后啥时候会再复活吧)

Shumway是用JavaScript/TypeScript以及TypedArray、WebGL等标准的Web技术实现的。其主要组成有:

Big Picture · mozilla/shumway Wiki · GitHub

(留意图中的GFX组件:它负责实现Flash Player的核心渲染功能,目前有Canvas2D和WebGL两个后端可选择)

我是做编程语言实现的,所以Flash API啥的我并不太关心,最吸引我注意的还是Shumway中AVM2的实现。

Shumway的AVM2(ActionScript Virtual Machine 2)整个是用TypeScript实现的。

之前Shumway AVM2曾经实现过一个JIT编译器(

Bug 1133991 - Implement a baseline JIT compiler by tschneidereit

),但后来这AVM2和AVM1都经历了一次大重写(

Rewrite of most of the AVM2 component, the core of the AVM1 by tschneidereit

),把这个JIT编译器暂时干掉了。目前应该是还没把JIT编译器恢复过来,虽然文件还在——得等等了(

1157883 – Re-enable Shumway's baseline compiler

)。

关于Shumway的一点历史:

groups.google.com/d/msg
> Tried to check recompiled code, to check how to create and populate right
> a vector but noticed that at least in redux the method was interpreted.
>
Right now, the redux branch doesn't have support for a JIT compiler. We'll
port the baseline compiler over once everything else works, but the
optimizing JIT that's used on master won't make it over. We do however
think that we'll be able to get the baseline compiler optimized to a point
where script execution speed isn't the bottleneck for almost all or all
applications.

> Is it possible to do a full-aot and generate JavaScript versions all the
> methods of a swf offline? For what I have seen you are creating an
> intermediate ast and then using relooper to create functions with jumps per
> trait. So while no dynamic code loading is involved it should be possible.
>
The Relooper is what's used in the baseline compiler, yes. The intermediate
AST isn't really used though: that's part of the optimizing JIT.

Doing AOT compilation is something we're definitely interested in, and it
shouldn't be all that hard to implement. You're right about there not being
any real issues with doing that. We've talked about building a tool that'd
take a SWF and preprocess it into something that can be run without needing
an interpreter or JIT, and that has better startup performance. It's not
something we need for our initial use case, so it hasn't been a priority,
though.