jv8
pacman.zig
jv8 | pacman.zig | |
---|---|---|
1 | 4 | |
66 | 245 | |
- | - | |
- | 6.6 | |
over 8 years ago | 25 days ago | |
C++ | Zig | |
MIT License | MIT License |
Stars - the number of stars that a project has on GitHub. Growth - month over month growth in stars.
Activity is a relative number indicating how actively a project is being developed. Recent commits have higher weight than older ones.
For example, an activity of 9.0 indicates that a project is amongst the top 10% of the most actively developed projects that we are tracking.
jv8
-
Porting My JavaScript Game Engine to C for No Reason
I owe a lot of the most informative programming work I’ve done to Impact.
Impact was so ahead of its time. Proud to say I was one of the 3000 license owners. One of the best purchases I’ve ever made. The only game I’ve ever really properly finished was made in Impact.
I loved that the source code was part of the license, and even modified the engine and the editor to suit my needs.
I was so inspired that I worked on my own JS game engine (instead of finishing games - ha!) for years after. I never released it, but I learned a ton in the process and made a lot of fun mini web games with it.
I was also inspired by Impact’s native iOS support, but frustrated that it didn’t run on Android (at the time at least), so I fumbled my way through writing JVM bindings for V8 and implemented a subset of WebGL to run my game engine on Android without web views.[0] I made the repo for V8 bindings public and to my surprise it ended up being used in commercial software.
I won’t bore you with the startup I tried to bootstrap for selling access to private GitHub repos, which was inspired by Impact’s business model…
Anyway, it warms my heart and makes me laugh to see Impact getting an update for the “modern” web with a C port!
I’d say these are strange times for the web, but I can’t remember a time when things were anything but strange. Cheers!
[0]: https://github.com/namuol/jv8
pacman.zig
-
Porting My JavaScript Game Engine to C for No Reason
Yes, for instance this is mixed Zig/C project (the C part are the sokol headers for the platform-glue code):
https://floooh.github.io/pacman.zig/pacman.html
The Git repo is here:
https://github.com/floooh/pacman.zig
...in this specific project, the Emscripten SDK is used for the link step (while compilation is handled by the Zig compiler, both for the Zig and C sources).
The Emscripten linker enables the 'embedded Javascript' EM_JS magic used by the C headers, and it also does additional WASM optimizations via Binaryen, and creating the .html and .js shim file needed for running WASM in browsers.
-
Zig and WASM
For a somewhat more complete example which runs in browsers, check out my little pacman.zig toy project [0]. This is cheating a bit by using Emscripten toolchain as 'sysroot' (needed for the Emscripten headers), and the Emscripten linker to create the html+js+wasm output file, but the actual code is all compiled with the Zig compiler.
The interesting part is that the platform abstraction is provided by the sokol headers [1], with auto-generated Zig bindings [2]. It's interesting because the C headers use "Emscripten magic" (mainly embedding Javascript snippets in the C sources via the EM_JS() macro), and the Zig compiler is able to compile this (when it has access to the Emscripten headers).
It would be nice if the "Emscripten platform" could get the same type of cross-compilation support as the desktop platforms eventually, but apart from bundling the Emscripten headers, this would also require to implement some of the "Emscripten magic" in the linker step.
Maybe projects like WaJIC can help with this (this basically implements the "Emscripten magic" of embedding Javascript snippets in C/C++ source code, but without Emscripten (only the wasm-opt tool is needed AFAIK).
Anyway... it's a lot of fun to tinker around with this stuff in Zig, and watch how it's all taking shape :)
[0] https://github.com/floooh/pacman.zig
- Cross-platform build with 3rd-party libraries?
-
To Learn a New Language, Read Its Standard Library
My advice would be: to learn a new language, start writing some non-trivial projects in it (a few thousand lines of code or so). In some languages (like Python), the standard library is the actually important feature, in other languages (like C), it better to mostly ignore the stdlib. Example: I started learning Zig by writing a Pacman clone (https://github.com/floooh/pacman.zig) and a home computer emulator (https://github.com/floooh/kc85.zig), the Pacman clone doesn't use any Zig stdlib features at all, and the emulator only minimally for parsing command line args and loading data from files.
Zig's stdlib is much more useful than C's, but it's still entirely possible to write useful programs without it and instead focus on learning Zig's language features first.
But on the other extreme, the whole point why I learned Python was its "batteries included" standard library.
What are some alternatives?
Ejecta - A Fast, Open Source JavaScript, Canvas & Audio Implementation for iOS
libcxx - Project moved to: https://github.com/llvm/llvm-project
impact - HTML5 Game Engine
zig-wefx - WEFX is a simple graphics drawing package using Zig, WASM, and an HTML canvas.
high_impact - A 2d game engine written in C
SDL.zig - A shallow wrapper around SDL that provides object API and error handling
LittleJS - LittleJS is a fast HTML5 game engine with many features and no dependencies. 🚂 Choo-Choo!
minimal-zig-wasm-canvas - A minimal example showing how HTML5's canvas, wasm memory and zig can interact.
Dodgeballz - A mini game using Zig, WASM and JS
julia - The Julia Programming Language
kc85.zig - A KC85 emulator written in Zig
liwords - A site that allows people to play a crossword board game against each other