Quake 3 engine in Rust
github.com
github.com
[1] http://static.rust-lang.org/doc/rust.html#type-parameters
[2] https://github.com/Jeaye/q3/blob/master/src/math/vec2.rs
[3] https://github.com/Jeaye/q3/blob/master/src/math/vec3.rs
[4] https://github.com/Jeaye/q3/blob/master/src/math/vec4.rs
C++ implements this in their templates because templates are rather more dumb than what a "proper" type system would do, because templates are essentially what C++ uses as a powerful macro system. A "Vec<3>" in C++ then is instantiated as a separate class/struct. A "Vector<Int>", if allowed to do it is separately compiled from a "Vector<Double>"[1] and this is what has given templates an uncanny power in C++ as a method of doing very powerful transformations of code, as used by libraries like Eigen to unroll very complex multiple-pass algorithms into a single fast loop. Very neat stuff.
I would be a little surprised, actually, to see Rust implement the same feature because the way C++ has done it is by a rather curious and roundabout[2] and it was just happenstance that made it one the first widely used implementations of dependent types. It's strange to think about, but templates are one way C++'s type system is more expressive than Haskell's. (Wow, that felt strange to write.)
The associated constant idea is kind of neat, but the implementation of associated constants wildly differs from associated functions[3] and I find it difficult to imagine the way they operate having anything, anything at all to do with one another.
If they do implement their associated constants proposal, it'd definitely be something worth following from a type systems perspective because, well, dependent types are one of those things that are curiously difficult to implement, and if they implement it as part of a general type system, it could even be undecidable[4].
[1] This may not be the case now, but it certainly was the case in the past. So this statement is only true to the extent of "very simple C++ compilers" and may not be true of more optimized compilation strategies. I'm not sure what the state of the art is here.
[2] And theoretically unsound, in that the macro/template language is be Turing complete. That's not really very desirable from the perspective of being able to share code or doing "compiler as a service" execution where someone could upload infinite loops or non-terminating templated types. http://ubietylab.net/ubigraph/content/Papers/pdf/CppTuring.p...
[3] In C#, they're called Extension Methods, and they're an instance of the compiler simply being smart enough to find functions that say they can work just like a method of a type, but only depend on an already public API. Extension methods are great because they let you turn regular C# generic types into Monads by adding implementations for Select, SelectMany, and so on and so forth. http://ericlippert.com/category/monads/
[4] Apologies for the link to wikipedia, but it's the most terse source on it that I can find. It should be noted that just because it's undecidable in some systems doesn't mean it's undecidable in all systems. Let us not make here the mistake of applying Gödel's Incompleteness Theorem to the reals. http://en.wikipedia.org/wiki/Type_system#Dependent_types
I'm actually leaning on the singleton types and type class machinery in ghc very very hard to write some numerical libraries with both a high level API and very strong code specialization guarantees.
A lot of the same stuff could be done with cpp Template programming, but I'd have to worry about a lot more code bloat, a much more inscrutable set of type error messages, and no hope of end users getting good type Inference.
There are a rich space of decidable type systems out there leverage some or all of dependent types. The work on idris is very exciting in my novice opinion.
http://smallcultfollowing.com/babysteps/blog/2013/04/02/asso...
You are right, those are great test cases for Rust.
The cross-product takes n-1 n-vectors are returns an n-vector (orthogonal to the n-1 inputs). The transformations are easy to generalize as affine or homogeneous transformations.
A nice features of Rust is that it has macros, so once it has dependent types creating these function with different signatures should be straight forward!
I'd hope that like C++, you would be able to add in any extra functions you'd need for specific dimensions.
Chapter 59: The Idea of BSP Trees
http://downloads.gamedev.net/pdf/gpbb/gpbb59.pdf
Chapter 60: Compiling BSP Trees
http://downloads.gamedev.net/pdf/gpbb/gpbb60.pdf
Chapter 62: One Story, Two Rules, and a BSP Renderer
And gamedev.net also has the book here: http://www.gamedev.net/page/resources/_/technical/graphics-p...
For the pure rendering side I'd say Real-Time Rendering (third edition) gives a good overview of techniques, but you'll want to look elsewhere if you want to see how those algorithms can be really optimised for a given API and GPU.
Anyway, great work so far! I am curious why you're doing BSP rendering if your goal is to have a destructible/voxelized-style world, since the two things are on opposite ends of the spectrum of mutability.
I wasn't around by the time Nebula 3 came to pass, I actually didn't realize there was a Nebula 3 until I did a google search to see if I could find any of my old nebula code.
The Rust compiler is in many different 'dialects' of Rust, since it's been around for so long. Parts of it haven't been touched in a while.
We're working on a general style guide here: https://github.com/mozilla/rust/wiki/Note-style-guide
Better than that would be a goftm like tool, that applies the style guide.
People (including me) love that about Go. (I've actually never read a negative comment about it and many possitives).
It puts an end to all issues with formatting, really.
I don't know how reusable the parse is -- it would make something like this even easier.
You can't figure out what a pretty printer should pretty print until the style is figured out.
My C++ style is identical to the first Draft ANSI C++ book I read. I've carried that style to Java and even to C (I hated pre-ISO K&R though mine looks now nearly identical to 1TBS). Heck, even when playing with Go, I used that style (gofmt be damned).
Now if Rust looked more like Python...
Not really. Go solves this with gofmt.
You might insist on your own style (as you say) but for most people it's a command line away to format it in the standard way, and all GitHub projects etc will be gofmt'ed anyway.
It may not be a "critical technical challenge" but if you are writing a new language there is really no excuse to not cement things like that down before it is too late.
If you don't they'll find something fundamental to be dissatisfied with. E.g., the lack of full TCO or a Turing complete type system.
I see how you would think so, but I lean in the opposite direction. If all programs in X language are written in the same style, you never have to pause to think about how to style something. This also means that you can quickly read other programs without being thrown by differences in style, and it's a great use-case for a tool that does the formatting for you. You can just write a quick example, run the formatting tool, and you won't have to pause next time. If you really can't afford the interruption, you can just skip formatting and run the formatting tool later-- though this is the sort of use-case that only occurs early in your relationship with the language.
There is a strong case for having one style: namely that now it becomes easy to understand aspects of a program at a glance (e.g. structure of flow, where you can gloss over for now, and where you have complexity) and also helps identify errors and on right away. Sometimes it's imperfect, but consistency is more important than "looks pretty".
Besides, if we're talking about the hacker mindset:
1) there are other languages
2) you can do amazingly complex and deep things with your brain, but you can't adapt to a style?
3) consistency and correctness is more important than "what I whimsically decide is neat looking today, no matter how many errors it is hiding".
And there would be no "forced" unless the reference implementation were to error when un-standard styles were used. I see absolutely nothing particularly "un-hackerish" about this. We standardize syntax and keywords, why not syntactical style?
You know what does seem hackerish though? Having tools that do mundane tasks (for example, formatting) for you so that you don't have to. Lisp, and lisp pretty-printers, also strike me as pretty hackerish.
Arguing about "using your own style" with regards to braces and such is not hacking, it's bike-shedding.
Sorry, but this thread smells of authoritarian people. I'm not really compatible with that.
Did you start this sub-thread saying: "Why do you want to force people to use your style? That's pretty much against the hacker mindset", ie telling us what hacking should mean to us?
To answer your question: no.
I merely restated what hacking means for everybody. Words have meanings built-in, individuals don't get to decide "what it means to them" and have that be accepted by other people (Else why even use the common word in the first place? Invent your own).
So, if hacking means "no standard syntax rules" to you (among other things of course), that doesn't mean squat to the general hacking population. Guido Van Rossum, for example, is as much a hacker as anybody, as are Python users, hacking in a language where indenting is enforced.
"Bike-shedding" is also well known, and is well known that syntax-style, brace wars and such fall under bike-shedding and/or yak shaving in Hacker culture, along with Emacs/Vi etc.
>Sorry, but this thread smells of authoritarian people.
Yes. Either that or people who couldn't give a flying duck for brace/common style wars, and have found by experience that not arguing about such things and having language standards make them more productive.
People that know that your "rebellion" and "creativity" have millions of interesting avenues to be exhibiting in the things you CREATE with your code, instead of in your brace style and such.
It's as if saying "I cannot be creative in this company/school" because they have a dress code. As if wearing some lame t-shirt or whatever makes one more creative.
$ cat > hello.rs
fn main() { core::io::println("Hello");
}
$ rustc hello.rs --pretty normal
fn main() {
core::io::println("Hello");
}EDIT: was there something wrong with what I wrote? This seems very simple for Quake 3 engine (based on my knowledge of 3D code and skimming the documentation). I've seen code is calling a lot into glfw and opengles libraries.
Potentially useful links:
http://www.valvesoftware.com/publications/2007/SIGGRAPH2007_...
http://www.gamedev.net/topic/491938-signed-distance-bitmap-f...
https://github.com/OpenGLInsights/OpenGLInsightsCode/tree/ma...
I got rustc 0.6 built and installed on my amd64 linux machine, but seems that this q3 codebase triggers some bug in the compiler ..
I found it interesting because it is a nice example of real, non-toy, code in rust. I presume others find it interesting because it is a good progress mark of rust.
A genuine desire to understand would have used different questions altogether.
Not really convinced. Even something like "In what ways is this interesting? Can you explain?" would be way more neutral than the current one.
If he was perplexed by something on the article he would ask more specific questions.
As it stands, it's identical to tons of other dismissive comments that follow every announcement. It wants to imply the author is "too technical" for this, e.g "hmm, a yet another 3D engine just done on some new language this time? who cares" or "why is this on top of HN".