Skip to content

bottle2/swf2c

Repository files navigation

swf2c

Usage instructions to come.

Do you want prints? A video? Boring! Check out this LIVE and ONLINE demo instead: https://www.newgrounds.com/projects/games/6419340/preview

The remainder of this document concerns development exclusively.

News

I post in this thread: https://www.newgrounds.com/bbs/topic/1540199/999

Supported backends

Windowing libraries:

Vector graphics libraries:

Vector graphics libraries to come next, because they are available in package managers:

Vector graphics libraries to come next, because they are so easy to build:

Vector graphics libraries to come next, because they are built-in:

  • Direct2D (is it still relevant?)

Other vector graphics libraries I don't care for now:

Mysterious vector graphics APIs:

Other windowing libraries I don't care for now:

Maybe a generic API will be provided too.

Libraries that WON'T be used:

  • SDL_gfx
    • I used it for my first prototype, but it is neither "fast" nor featureful (I have no proof tho)

Competitors

Project structure

The entire compiler is one Rust source code main.rs that when compiled and run, generates C code. Notice my code is terribly hideous, for the following two reasons: 1) I don't know how to program in Rust, and I won't learn it anytime soon; and 2) I'm an assiduous adept of eXtreme Go Horse (XGH) development methodology. Many times I considered employing some text templating library to ease my pain, but as my usage of the C preprocessor increased, it became pointless.

File main.c is one SDL2 program that makes use of the generated code to render an animation. It is my demo. It exercises the generated code.

The Makefile probably has bashisms. I don't care for now.

Performance

Compilation time is a major burden right now. See https://gcc.gnu.org/pipermail/gcc-help/2025-February/143981.html

Ideas:

  • Decrease amount of matrix transformations (but does it matter?)

Design decisions

Choice of C

I'm generating C because I know C and I like C. I don't which version of C I'm targeting yet, but because the generated code is so simple, it should be as low as possible e.g. C89 and work in broken compilers such as MSVC.

Maybe I could generate assembly instead. The choice of assembly needs to meet the following criteria:

  • The assembler must be available in every relevant development environment
  • It must generate machine code for every relevant game platform, complying to their ABI, including:
    • WebAssembly/JavaScript
  • It must have metaprogramming as powerful as my current use of the C preprocessor
  • It must be able to use symbols, types and macro definitions provided by library headers

I could also write an actual compiler, leveraring e.g. LLVM or GCC. But I don't even know how to start, so why bother?

Why not just read the SWF file as-is and embed some existing player into the game? This is a big deal, because the compiled object is enormous, while the original SWF is diminute, and the SWF format already takes into account low-power devices. This challenges the validity of my approach, because I don't even know if there are any gains or optimization opportunities when hardcoding everything in C. Currently my only defense is to argue about compressed sizes, such as when tranfering on networks.

Choice of SWF parser

I'm using Ruffle's SWF parser. I chose Rust because it is trendy and it will look good in my portfolio. There is no further rationale.

The following two libraries are written in Haxe:

The following projects also parse SWF:

Future directions

  • Clipping
  • Integration with physics engines such as Chipmunk2D
  • Support for sound
  • Some barebones action support (I don't know yet)
  • Distribute this compiler
    • Make available in package managers
    • Provide binaries for Windows users
    • Online frontend
    • Integration with IDEs such as Visual Studio
    • As a plugin for Unity, Unreal Engine, Godot etc.
  • Weird idea: bypass opaque pointers provided by libraries (I abhor opaque data structures)
  • Linear gradient fills
  • Radial gradient fills
  • Focal gradient fills
  • Texture fills
  • Stroke styles
  • Forced frame interpolation
    • Linear interpolation at first
    • Guess interpolation analyzing how objects transform
  • Shape morphing
  • Text
  • Non-seekable APIs (supposedly with a lower footprint)
  • Write tool and API manual
  • Create more compilers, such as svg2c or riv2c or... riv2swf
  • Be friendly with C++

External efforts:

  • Make more multimedia authoring tools export SWF
  • Turn SWF into a standardized open format
    • We could bump the version to e.g. 128 and upgrade from there
    • We could add new tags starting with code e.g. 500
    • Have a neutral agency in the likes of IANA to allocate tag codes
    • I saw this idea mentioned in Gnash wiki, something BackLash something

License

Not decided yet!

Contact

Get in touch preferably through Newgrounds: https://detergent1.newgrounds.com/

References

The Gnash wiki is a goldmine, but unfortunately it is offline and can only be browsed through Internet Archive.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages