Porting My JavaScript Game Engine to C for No Reason

This page summarizes the projects mentioned and recommended in the original post on news.ycombinator.com

InfluxDB - Purpose built for real-time analytics at any scale.
InfluxDB Platform is powered by columnar analytics, optimized for cost-efficient storage, and built with open data standards.
www.influxdata.com
featured
SaaSHub - Software Alternatives and Reviews
SaaSHub helps you find the best software and product alternatives
www.saashub.com
featured
  • LittleJS

    LittleJS is a fast HTML5 game engine with many features and no dependencies. đźš‚ Choo-Choo!

    now rewrite it back to JS with https://github.com/KilledByAPixel/LittleJS

    j/k :D

  • InfluxDB

    Purpose built for real-time analytics at any scale. InfluxDB Platform is powered by columnar analytics, optimized for cost-efficient storage, and built with open data standards.

    InfluxDB logo
  • pacman.zig

    Simple Pacman clone written in Zig.

    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.

  • Ejecta

    A Fast, Open Source JavaScript, Canvas & Audio Implementation for iOS

    It does, but the main speedup comes from using WebGL instead of Canvas2D. Sadly, Canvas2D is still as slow as it ever was and I really wonder why.

    Years back I wrote a standalone Canvas2D implementation[1] that outperforms browsers by a lot. Sure, it's missing some features (e.g. text shadows), but I can't think of any reason for browser implementations needing to be _that_ slow.

    [1] https://github.com/phoboslab/Ejecta

  • impact

    HTML5 Game Engine

    The original JavaScript engine “Impact” from 2010 is at the end of its life; the C rewrite “high_impact” is new and will (potentially) be around for as long as we have C compilers and some graphics API.

    The JavaScript engine had a lot of workarounds for things that are not necessary anymore and some things that just don't work that well with modern browsers. From the top of my head:

    - nearest neighbor scaling for pixel graphics wasn't possible, so images are scaled at load time pixel by pixel[1]. Resizing the canvas after the initial load wasn't possible with this. Reading pixels from an image was a total shit show too, when Apple decided to internally double the Canvas2D resolution for their “retina” devices, yet still reporting the un-doubled resolution[2].

    - vendor prefixes EVERYWHERE. Remember those? Fun times. Impact had it's own mechanism to automatically resolve the canonical name[3]

    - JS had no classes, so classes are implemented using some trickery[4]

    - JS had no modules, so modules are implemented using some trickery[5]

    - WebAudio wasn't a thing, so Impact used which was never meant for low latency playback or multiple channels[6] and generally was extremely buggy[7]. WebAudio was supported in later Impact version, but it's hacked in there. WebAudioContext unlocking however is not implemented correctly, because back then most browsers didn't need unlocking and there was no "official" mechanism for it (the canonical way now is ctx.resume() in a click handler). Also, browser vendors couldn't get their shit together so Impact needed to handle loading sounds in different formats. Oh wait, Apple _still_ does not fully support Vorbis or Opus 14 years later.

    - WebGL wasn't a thing, so Impact used the Canvas2d API for rendering, which is _still_ magnitudes slower than WebGL.

    - Touch input wasn't standardized and mobile support in general was an afterthought.

    - I made some (in hindsight) weird choices like extending Number, Array and Object. Fun fact: Function.bind or Array.indexOf wasn't supported by all browsers, so Impact has polyfills for these.

    - Weltmeister (the editor) is a big piece of spaghetti, because I didn't know what I was doing.

    Of course all of these shortcomings are fixable. I actually have the source for “Impact2” doing all that with completely new editor and bells and whistles. It was very close to release but I just couldn't push it over the finish line. I felt bad about this for a long time. I guess high_impact is my attempt for redemption :]

    [1] https://github.com/phoboslab/Impact/blob/master/lib/impact/i...

    [2] https://phoboslab.org/log/2012/09/drawing-pixels-is-hard

    [3] https://github.com/phoboslab/Impact/blob/master/lib/impact/i...

    [4] https://github.com/phoboslab/Impact/blob/master/lib/impact/i...

    [5] https://github.com/phoboslab/Impact/blob/master/lib/impact/i...

    [6] https://phoboslab.org/log/2011/03/multiple-channels-for-html...

    [7] https://phoboslab.org/log/2011/03/the-state-of-html5-audio

  • high_impact

    A 2d game engine written in C

    > Except for SDL2, all libraries are bundled here (see the libs/ directory).

    https://github.com/phoboslab/high_impact#libraries-used

    yep. exactly why I dont use C anymore. the package management story is so bad/non existent, that the typical approach is to just vendor everything. no thanks.

  • jv8

    (No longer maintained) WebViews be damned. Run V8 directly on Android, in Java.

    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

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts

  • LittleJS is a fast HTML5 game engine with many features and no dependencies

    1 project | news.ycombinator.com | 19 Aug 2024
  • Undergrowth - A tale from O Monolith, The new album by Squid!

    1 project | /r/Games | 11 Jun 2023
  • Undergrowth - A story from O Monolith - The new album by Squid

    1 project | /r/playmygame | 11 Jun 2023
  • Most popular library to build games in javascript?

    1 project | /r/gamedev | 28 Dec 2022
  • GitHub - KilledByAPixel/LittleJS: The Tiny JavaScript Game Engine That Can!

    1 project | /r/javascript | 22 Dec 2022

Did you konow that JavaScript is
the 3rd most popular programming language
based on number of metions?