Live data from Hacker News

Making a Game in Rust

michaelfairley.com

111–120 of 125 posts

Re: Making a Game in Rust

#111

Earlier quoted context omitted.

Dyon (from that link) looks very cool! I'd also like to add that JavaScript is another language used in this arena, and there is a crate with V8 bindings ( https://crates.io/crates/v8 ). Even Garry Newman (creator of Garry's mod) wrote that he believes JS would have been better than Lua for scripting: https://garry.tv/2014/08/16/i-fell-out-of-love-with-lua/

Yeah, Lua certainly has it quirks. However binding to JS is a huge endeavor. For instance that v8 crate doesn't easily expose a way to call Rust from JS which is trivial in Lua. Also the JS runtime is huge and the build system is complex. You can run Lua in ~400kb or less and LuaJIT tends to walk over any other jitted interpreted runtime.

While the performance definitely doesn't compare to LuaJIT, Duktape (http://duktape.org/) could be a good target for Rust bindings - it's fairly small and available as a single-header/implementation library.

Re: Making a Game in Rust

#112
post #59
post #52

Earlier quoted context omitted.

For simple pixel access and no primitives, https://github.com/emoon/rust_minifb is very compact and neat. Otherwise rust-sdl2 is batteries included, there may be more ceremony than html5 canvas but it's easy to hide behind a simple interface. It has many simple examples. But, like with C++, as long as the language doesn't come with a standard graphics library, I doubt the "official" books can really use graphics apps…

Easy to hide behind a simple interface if you already know the programming language. My suggestion is that someone perhaps should do just that so that beginners don't have to learn how to construct a simple interface at the same time as they are learning the language. The MiniFB code does seem to be a good starting point for this sort of thing.

Yeah, I was just echoing your comment that you provide a small library for HTML5 canvas-based teaching. If I was going to teach someone Rust, I would definitely do that, but of course I (the teacher) would need to know enough to build it in the first place.

I absolutely advocate using graphics and games as the hook to keep people interested in learning. [1] "The immediacy of many 8-bit computers was awesome. Instant boot to a graphics-ready command line and program editor. I was instantly hooked". And that's why, despite the really bad fit, I support the addition of a 2d std library to C++, and would do likewise for Go, Rust, etc.

[1] https://twitter.com/TheJare/status/860094027370291200

Re: Making a Game in Rust

#113
post #97

Earlier quoted context omitted.

If the type proved there could be no NaN, why would the check be needed?

0.0 is a finite number that yields NaN when divided by itself. The initial checking is not sufficient.

So check on construction, when doing operations with other unchecked floats, and when dividing. Any other operations that could produce a NaN?

Wait, are +-Inf considered unordered? Edit: Nope. inf == inf, so you should only have to worry about NaN. https://is.gd/Xi5jdr

Re: Making a Game in Rust

#114
post #47

Earlier quoted context omitted.

This tells me why I got downvotes, I replied to the wrong comment. The game wasn't written in rust, is was used in a texture and drawn on a wall.

The game that's the subject of the OP is written in Rust. The one in the Reddit thread linked elsewhere was only a texture.

But I think we can all agree that if we are programming a gun there should be an unsafe block.

Re: Making a Game in Rust

#115
post #102

that's a great twist on the snake game. does rust compile to wasm?

Yes, Rust can compile to WASM. https://hackernoon.com/compiling-rust-to-webassembly-guide-4...

I want to do an experiment with object oriented code that generates view code in wasm and keeps other code in the server.

Re: Making a Game in Rust

#116

Earlier quoted context omitted.

Yeah, Lua certainly has it quirks. However binding to JS is a huge endeavor. For instance that v8 crate doesn't easily expose a way to call Rust from JS which is trivial in Lua. Also the JS runtime is huge and the build system is complex. You can run Lua in ~400kb or less and LuaJIT tends to walk over any other jitted interpreted runtime.

While the performance definitely doesn't compare to LuaJIT, Duktape ( http://duktape.org/ ) could be a good target for Rust bindings - it's fairly small and available as a single-header/implementation library.

https://crates.io/crates/duktape

Re: Making a Game in Rust

#117
post #19

Earlier quoted context omitted.

While include_bytes is nice, xxd -i in a makefile is pretty workable solution in the scale of things.

Fair point, however I believe the OP made the game work for many different OSes, and I don't think xxd or Makefiles are the best when you have to deal with Windows (whereas Rust's include_bytes! provides a platform-independent solution). I had never heard of xxd until your comment though, so thank you very much!

Somehow I'm reminded of the old adage "UNIX is IDE for C"

Re: Making a Game in Rust

#118

Earlier quoted context omitted.

0.0 is a finite number that yields NaN when divided by itself. The initial checking is not sufficient.

So check on construction, when doing operations with other unchecked floats, and when dividing. Any other operations that could produce a NaN? Wait, are +-Inf considered unordered? Edit: Nope. inf == inf, so you should only have to worry about NaN. https://is.gd/Xi5jdr

If you want the full list: 0/0, ±inf/±inf, 0 x ±inf, ±inf x 0, inf + (-inf), (-inf) + inf, inf - inf, (-inf) - (-inf). This list is large enough to make NaN checking inefficient.

Re: Making a Game in Rust

#119
post #98

Earlier quoted context omitted.

Dyon (from that link) looks very cool! I'd also like to add that JavaScript is another language used in this arena, and there is a crate with V8 bindings ( https://crates.io/crates/v8 ). Even Garry Newman (creator of Garry's mod) wrote that he believes JS would have been better than Lua for scripting: https://garry.tv/2014/08/16/i-fell-out-of-love-with-lua/

Unfortunately, some of those syntax niceties the Garry's mod creator mentioned are things that have been identified as leading causes of bugs. ++ mutates a variable in place, has non-trivial pre/post behaviour (many junior devs don't understand it), and its brevity causes it to be used inline, which results in complex one liners. String concatenation using '+' is not considered to be a great feature in dynamically ty…

> String concatenation using '+' is not considered to be a great feature in dynamically typed languages.

Yes, one of the things Perl got very right, and yet it is still brought up by people as evidence of what makes Perl look like line noise (along with == vs eq, which is the same thing, even if the problem is less troublesome in that case).

> So it feels a little like Lua is being criticised for making some good calls.

All too often languages (and aspects of them) are criticized mistanely as being worse when all that is presented is how they are different. All too often we vilify the unusual just for being unusual.

Re: Making a Game in Rust

#120

Earlier quoted context omitted.

Go is a language that you can absolutely learn like that, and it's pretty amazing. (Python, too) Rust ... isn't. I love Rust, but you do need to put some dedicated time into learning it. We're hoping to improve this!

Whilst an easy start is nice, any language that you can pick up with no effort just means you're learning the same language + paradigm that you already know with a few differing features (in go's case CSP). Nothing wrong with that, CSP is awesome etc I'm not a rust dev (definitely interested in picking it up though), but heavily into clojure and learning haskell slowly on the side. I hear this complaint a lot from pe…

What Go borrowed from CSP - channels - is definitely awesome. But it was Go's interfaces that was the real game-changer for me. Very under-appreciated.
Post reply on HN