from Hacker News

Townscaper Running in the Browser

by krstffr on 12/1/21, 3:17 PM with 97 comments

  • by _Microft on 12/1/21, 3:35 PM

    There is also another game/toy by Oskar Stålberg in which you can build a teeny, tiny block of house(s) on a 5x5 grid. Very cute, especially with all the well decorated balconies.

    https://oskarstalberg.com/game/house/index.html

    The author is on Twitter and sometimes tweets about development of his games and the techniques involved.

    https://twitter.com/OskSta

  • by t8y on 12/1/21, 11:52 PM

    This uses the "wave function collapse" algorithm. Oskar Stalberg also made a great demo of how it works[0], but it might not make sense just from that. Martin Donald made a really nice youtube video on how it works[1]. The name "wave function collapse" can be off putting but it's pretty straightforward, and an algorithm that can come in handy for many uses both in game development and just general software development.

    I'm actually procrastinating on HN from working on a GPU parallelised version that can generate millions of positions every frame. In Townscaper you can actually see that the algorithm runs quite slow and lags behind the players input, there's just a bunch of animation to hide it. I'm hoping to eventually get a version that can run in log2(mapsize) time.

    [0]http://oskarstalberg.com/game/wave/wave.html [1]https://www.youtube.com/watch?v=2SuvO4Gi7uY

  • by raajg on 12/1/21, 5:08 PM

    Wow, the entire town is URL encoded!! Example: http://oskarstalberg.com/Townscaper/#IzpjOEQ0ejP2X9w-b--c-X-...
  • by aroman on 12/1/21, 5:05 PM

    It takes about 90 seconds to load for me, but once it does, it's buttery smooth on my M1 Pro. Unity's web story is still so bad for many reasons, but the initial load times are a huge one (~15MB of wasm for an empty scene last I checked). They were working on Project Tiny[0] to address exactly this, but they've now paused work on it indefinitely :( Someone please build tools to fix this!

    [0] https://unity.com/solutions/instant-games

  • by _Microft on 12/1/21, 3:40 PM

    Here is a third party tool that lets you explore your Townscaper creations from a first person view.

    https://meliharvey.github.io/threescaper/

  • by chriscjcj on 12/1/21, 9:29 PM

    Not sure why, but whenever I'm presented with something like this, I always seem to want to build the least functional, least utilitarian, most maddening and stupidest structure I can.

    http://oskarstalberg.com/Townscaper/#IzhCuCAJioFFB00CAajRAN2...

  • by bullen on 12/1/21, 6:15 PM

    Here is a speech about Townscaper:

    https://www.youtube.com/watch?v=APIdkBwwWJI

    at 1:12

  • by evilhackerdude on 12/1/21, 3:58 PM

    Interesting, according to Oskar it’s straight up exported from Unity for web:

    https://twitter.com/OskSta/status/1466063657582931974

  • by Toutouxc on 12/1/21, 5:56 PM

    What is missing from this demo compared to the full game? I thought that even the full game was this minimalistic.
  • by tdrdt on 12/1/21, 4:44 PM

    Here a very interesting talk by Oskar Stålberg where he explains how this works: https://youtu.be/1hqt8JkYRdI
  • by sktrdie on 12/1/21, 5:43 PM

    I feel like this is how the UX for developing software should be. Types and intellisense plus copilot somewhat bring us close to something like this. Where adding a new module somehow automatically adjust itself to the project instead of having to provide strict API interfaces. Just a thought.
  • by hoten on 12/2/21, 6:31 AM

    Works great on my Android phone in Chrome. Oddly there's a message on startup saying WebGL won't work on mobile.

    EDIT ah, it's unity's fault apparently. According to caniuse WebGL is golden for all mobile browsers. They should get with the times ;)

    One thing that the demo could improve on in the mobile department is that scrolling is too sensitive. Most attempts at tapping to modify the structure result in a totally random change of the camera.

  • by julius_deane on 12/1/21, 3:38 PM

    Full version is available in Steam.
  • by aquir on 12/2/21, 9:56 AM

    This is awesome! I went to the App Store and bought it after playing w/ it for a couple of minutes! Brings me joy
  • by kinduff on 12/1/21, 9:28 PM

    Just got blown away when I "turned off" the sun and the buildings started to turn on their lights.

    I'm a big fan of Oskar.

  • by atum47 on 12/1/21, 5:51 PM

    Yeah, this is super nice. I remember seeing all over twitter back then. At the time the articles were focusing on the wave function collapse, which I find awesome. Thank you for publishing it to the web so we could play with it.
  • by bobajeff on 12/1/21, 4:39 PM

    Impressive. Would be more impressive if it ran on mobile browser, though.

    Edit: Scratch that it does run. I got scared away by the message about webgl builds not being supported on Mobile.

  • by d0100 on 12/2/21, 1:02 PM

    If you want a easy to follow tutorial on doing something like this, I really enjoyed Eric's tutorial: https://www.youtube.com/watch?v=Pl72lxuBMWk&list=PLm9r3VWwsE...

    The tutorial was about the previous web-based Brick Block by Oscar

  • by typon on 12/1/21, 7:21 PM

    This is incredible. How the heck does the algorithm work so well? It manages to produce beautiful looking things no matter what I do
  • by zestyping on 12/2/21, 2:24 AM

    What determines which surfaces you can build on and which you can't? It seems random — I can keep clicking on an end wall to extend the building for a while, and then suddenly I can't anymore.
  • by marcoslozada on 12/1/21, 5:28 PM

    If you put some good audio headphones its amazing!
  • by braymundo on 12/1/21, 7:17 PM

    It runs perfectly for me on Chrome, but struggles on Safari (macOS, Monterey, MacBook Pro 2018). Does anyone know why?
  • by sagivo on 12/1/21, 8:33 PM

    Works pretty smoothly on my Android device running Firefox. Any details on how it was built?
  • by z3t4 on 12/1/21, 5:20 PM

    Cool demo, well polished. Now it only needs some gameplay! I could imagine a friendly MMO game where you trade resources with other sea villages.
  • by ChrisArchitect on 12/1/21, 10:18 PM

    Gorgeous.
  • by dusted on 12/1/21, 7:39 PM

    oh this is delightful!