10 ms·
OpenTTD Compiled to WebAssembly
- danielvf 8y agoIt even runs on my IOS phone. Incredible!
- llukas 8y agoAny idea how battery usage of webassembly version vs native looks like? I'd assume that webassembly would consume more but maybe difference is not significant?
- astrodust 8y agoThe original Transport Tycoon Deluxe game was written in assembly so it could run quickly on modest hardware, like a 486 at 50MHz. OpenTTD isn't as efficient, but it's not that demanding either.
- llukas 8y agoNot interested how quick it runs. Just energy expended through native and webassembly.
- ShinTakuya 8y agoHow quick it runs to an extent is correlated to energy usage. I know it's not the same but for a single threaded low memory usage game the correlation would be close.
- astrodust 8y agoOn any given number of cores, sure. The original Transport Tycoon came about before multi-core systems and, as it was DOS based, even threads. Power consumption is a product of cycles plus memory read/write operations.
- Mirioron 8y agoIt runs on my old android phone too, but I don't think the game is actually playable. I couldn't move the camera around.
- kjeetgill 8y agoFor anyone else wondering OpenTTD is Open Transport Tycoon Deluxe.
- mjcohen 8y agoNever heard of that before. What occurred to me was "Test to Destruction".
- ncmncm 8y agoI wondered too. "OpenTTD is a business simulation game in which players try to earn money via transporting passengers and freight by road, rail, water and air. It is an open-source[2] remake and expansion of the 1995 Chris Sawyer video game Transport Tycoon Deluxe." https://en.m.wikipedia.org/wiki/OpenTTD https://en.m.wikipedia.org/wiki/OpenTTD
- keyle 8y agoIt was and is a fantastic game. I played it for many hours growing up. EDIT: the original, Transport Tycoon.
- jodrellblank 8y agoSee also https://old.reddit.com/r/openttd/ https://old.reddit.com/r/openttd/
- db48x 8y agoI'm surprised at how good the sound is; that's where I've had the most trouble.
- garaetjjte 8y agoIt's just uses Emscripten SDL2 for audio output. Here's build with MIDI music enabled: https://milek7.pl/openttd-wasm-music/ https://milek7.pl/openttd-wasm-music/
- Game_Ender 8y agoThe combination of C++ and OpenGL is really the ultimate in portability. A language supported on almost every platform by one if not more implementations (sometimes 3), coupled with probably the most widely supported graphics API. Of course you lose accessibility, and many platform API conveniences, but you get a more stable and performant platform to work with. In fact it's the platform that most web browser themselves are heavily based on. For another example just look at what Epic was able to do with Fortnite, one code base that literally runs everywhere. Magnum [0] is a favorite of mine for creating portable OpenGL C++ applications. It also has support for compiling to WebAssembly [1] and using WebGL2. 0 - https://magnum.graphics https://magnum.graphics 1 - https://magnum.graphics/showcase/picking/ https://magnum.graphics/showcase/picking/
- ianlevesque 8y agoWell, it was for a while: https://www.anandtech.com/show/12894/apple-deprecates-opengl-across-all-oses https://www.anandtech.com/show/12894/apple-deprecates-opengl...
- Game_Ender 8y agoYeah there is MoltenGL which will probably be open sourced eventually. The real future is Vulkan which is moving to replace OpenGL and for the Apple platforms there is MoltenVK [0] (Vulkan re-implemented on top of Apple's new Metal) which is open source. Magnum has an initial Vulkan backend [1], and many other engines have them or are building them as well. 0 - https://github.com/KhronosGroup/MoltenVK https://github.com/KhronosGroup/MoltenVK 1 - https://blog.magnum.graphics/announcements/2018.10/ https://blog.magnum.graphics/announcements/2018.10/
- ianlevesque 8y agoThat’s cool I didn’t realize MoltenVK was maintained by Khronos.
- AlphaSite 8y ago
- goddtriffin 8y agoMultiplayer functionality doesn't seem to be working for me. Is this just me, or an artifact of the compilation?
- db48x 8y agoThe browser doesn't provide the usual POSIX api for opening TCP connections. With some work you can write a shim library that implements it in terms of websockets, but it still can't connect to arbitrary hosts. Instead you have to run a proxy server for it to connect to.
- reubenmorais 8y agoCould you use WebRTC instead, for true P2P?
- db48x 8y agoYou still need a proxy server, unless the OpenTTD game browser supports WebRTC connections.
- jeremija 8y agoYeah, you'd need a proxy server (websockets) to establish WebRTC connections. Even after a WebRTC connection is established, you'd need a STUN or a TURN (coturn supports both) server to get around NATs. Pls somebody correct me if I'm wrong!
- tim-- 8y agoYou should only need a STUN or TURN server if you are attempting to connect to a machine that is behind a NAT. OpenTTD servers are usually on public IPs (similar to HTTP servers), so a STUN or TURN server should not be required. The biggest issue is that WebRTC connections do not allow you to send raw data over TCP or UDP[1]. That being said, it shouldn't be too difficult to just create a WebSocket server that translates between the native network protocol and HTTP WebSockets[2]. [1] https://developer.mozilla.org/en-US/docs/Web/API/RTCDataChannel [2] https://wiki.openttd.org/Network_Protocol
- codexon 8y agoI ran it for a few minutes and then it said: Uncaught RuntimeError: float unrepresentable in integer range at wasm-function[3502]:49 at wasm-function[6940]:395 at wasm-function[6939]:347 at wasm-function[3103]:334 at wasm-function[3284]:30 at wasm-function[4902]:3105 at wasm-function[4903]:654 at wasm-function[8083]:442 at wasm-function[8082]:3 at wasm-function[9782]:13
- antonvs 8y agoLooks like there's a bug in wasm-function.
- jplayer01 8y agoI'm not so sure.
- beefsack 8y agoYou can avoid that issue by using clamp mode when compiling: https://emscripten.org/docs/compiling/WebAssembly.html#trap-mode https://emscripten.org/docs/compiling/WebAssembly.html#trap-...
- garaetjjte 8y agoThanks, changed that setting.
- kwindla 8y agoPorting c/c++ codebases to WebAssembly is both super fun and frustrating. Network stuff, as mentioned in other comments, is futzy because of the limitations of running in a browser environment. A surprising amount of network code "works," in the sense that it compiles and runs translated to web sockets. (Great work from the WebAssembly and Emscripten community.) But, you know, web sockets. pthreads support landed in Chrome recently: https://developers.google.com/web/updates/2018/10/wasm-threads https://developers.google.com/web/updates/2018/10/wasm-threa... Pipes, select, and unix domain sockets aren't really supported (afaik).
- Simple_Guy 8y agoOne of the coolest things to do is go on one of the many multiplayer servers and see some of the super train systems that have been built. 16 lanes high speed rail connecting thousands of nodes.
- pjmlp 8y agoYep, go Flash. https://en.m.wikipedia.org/wiki/CrossBridge https://en.m.wikipedia.org/wiki/CrossBridge Everything old is new again.
- propelol 8y agoIt's not a fair comparison. Flash was a closed source non-standard technology.
- skrebbel 8y agoThat's not why most people hated it.
- dcbadacd 8y agoBut it's part of the reason. It was also notorious for it's security flaws.
- pjmlp 8y agoWebAssembly on its current state still doesn't prevent internal memory corruption, due to lack of bounds checking enforcement. Yes it does not escape the sandbox, however triggering stack corruption of local variables opens the door to explore changing the behaviour of function calls, while getting some goodies in the process. It remains to be seen how secure is WebAssembly at scale, when black hats start actually turning their sights into it.
- tracker1 8y agoGiven the runtime environment and limitations, I SERIOUSLY doubt WebAsm will be LESS secure than JavaScript's runtime in browsers itself.
- josefx 8y agoOne reason I liked flash: You could disable malicious ads with flashblock without breaking 90% of the internet. With the cancerous growth of JavaScript APIs embrancing and extending on all that made flash evil that is no longer possible.
- NietTim 8y agoThis is super cool, TTD always has a special place in my heart. Any technical explanation why level generation is so much quicker? Not even a loading screen
- benj111 8y agoTTD or Open TTD? TT on my 486 took time to generate a map, (TTD is basically the same code I believe). Open TTD when you've cranked up the map size takes time too. Perhaps you were playing TTD on a relatively powerful pc?
- Freak_NL 8y agoIt's a shame the online content functionality isn't working because of a missing zlib library. OpenTTD really has quite an active community of modders and asset creators. You want the trains from your home country? They are available, and probably up to date to the current year. Just download them from within the game, enable them, and start a new game.
- neiman 8y agoIt looks amazing, but for some reason it's not polished on my machine. There are many small bugs that don't exist in the native version. For example, when I scroll, the pointer stay frozen till I finish scrolling, and only then "jumps" to the new location. It makes a huge difference between enjoyment and suffering in games.
- adhambadr 8y agothis is really cool. Can't wait for GTA2
- LeanderK 8y agoMoving the cursor was really sluggish on Safari for the first two to five minutes and afterwards I didn't notice lag. Maybe it's some JIT-compiler warm-up phase?
- fs2 8y agoReally amazing!
- vortico 8y agoHasn't OpenTTD been ported to JS in 2015? https://epicport.com/en/ttd https://epicport.com/en/ttd Regardless, a WebAssembly port is perhaps more useful since improvements can be merged from upstream more easily.