
Quake 3 engine in Rust - luu
https://github.com/Jeaye/q3
======
onedognight
Does anyone know if type parameters in Rust can be integers so that you could
write vec<3> and get an optimized unrolled implementation of three dimensional
vectors without having to hard-code as in vec2, vec3 and vec4, etc?

[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>

~~~
AaronFriel
What you're actually asking for is dependent types, where instead of passing
in a type argument you're passing in a value you're asking to have lifted to
the type system.

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...](http://ubietylab.net/ubigraph/content/Papers/pdf/CppTuring.pdf)

[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>

~~~
carterschonwald
With ghc 7.4 onwards you can have that style of static dependent types very
easily, and it's even nicer still in ghc 7.6 onwards. That particular flavor
of dependent types is singleton 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.

------
Arjuna
If you are interested in reading further about BSP (Binary Space Partitioning)
[1], check out the following chapters from Michael Abrash's _Graphics
Programming Black Book_ :

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

<http://downloads.gamedev.net/pdf/gpbb/gpbb62.pdf>

[1] <https://en.wikipedia.org/wiki/Binary_space_partitioning>

~~~
zerr
Can someone comment whether if Abrash's Graphics Programming Black Book is
still actual today? There are some reviews on amazon, from 1999/2000
mentioning that it is outdated. I guess some percentage could be still actual,
of course. So I'm interested what percentage it is.

~~~
aardvark179
Some parts are still worth reading, but a lot of it is dealing with rendering
without any real acceleration. Some of the low level parts on optimisation may
still be worth reading, as are the BSP chapters, but you should read more
modern books on optimising code, and on spatial indexing schemes of various
types as well.

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.

------
georgemcbay
This is a great bit of nostalgia, not just for Quake 3 but because quite a
while back (2000-2001-ish) I wrote a Q3 BSP format renderer for the Nebula
Device open source engine, written in C++. Sadly the code seems to be somewhat
lost at this point. I don't have a local copy of it and some cursory searches
for it aren't finding much, I suspect it exists in some now-obsolete branch of
an SVN repo on SourceForge, but don't care enough to really go looking.
Surprisingly there is still a tripod page with screenshots:

<http://gmcbay.tripod.com/>

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.

~~~
BruceM
I miss the Nebula Device. Nebula3 was really shaping up into something great.

~~~
georgemcbay
Bruce Mitchener, I presume? I remember you from the days of hacking on Nebula!

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.

------
kayoone
This is more like a renderer for the BSP map format. Still awesome stuff
though, interesting to see how it progresses

~~~
kibwen
Ah, thanks. From the title I thought that someone had single-handedly re-
implemented all of Quake 3 in Rust, which seemed a bit implausible.

------
devinus
This is _very_ cool, but I wonder why people are already inventing different
indentation styles for Rust already. Guys, we _have_ the canonical way all
Rust code should look from the Rust compiler itself. Let's not all start using
disparate styles just because we can like C/C++.

~~~
pointyhatuk
Good point. Need a rustfmt like gofmt in go.

~~~
gloob
I, too, feel that perfectly uniform brace positioning is one of the critical
technical challenges facing any new language today. There is no longer any
excuse to get such an important and fundamental advance wrong.

~~~
jlgreco
Sarcasm?

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.

~~~
kybernetyk
Why do you want to force people to use your style? That's pretty much against
the hacker mindset.

~~~
coldtea
Hackers are about creating things.

Arguing about "using your own style" with regards to braces and such is not
hacking, it's bike-shedding.

~~~
kybernetyk
So suddenly you decide what hacking should mean to me?

Sorry, but this thread smells of authoritarian people. I'm not really
compatible with that.

~~~
coldtea
> _So suddenly you decide what hacking should mean to me?_

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.

------
Ygg2
So from what I gather this is basically a wrapper around some libraries that
renders a quake map, I've been browsing through and found very little code,
which seems implausible for a game of such complexity.

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.

~~~
ZoFreX
You are correct that it is very simple for a Quake 3 engine - the submission's
title is misleading. Calling it "basically a wrapper around some libraries" is
a bit harsh though. It's not like it's loading up
libloadandrenderaquake3map.so! From a quick glance at the code it implements
opening a .bsp file, representing it in memory, and rendering it with direct
OpenGL calls. This is pretty close to the metal, so to speak.

------
gpcz
It looks like pretty good progress! Are you going to be implementing the Quake
Virtual Machine (QVM) architecture so that your engine can run the Quake 3
game and its mods?

~~~
Jeaye
The goal is to create a Quake 3 like game, but with a destructible voxelized
world (Ace of Spades doesn't do it for me). As you can see, and as others have
commented, this is currently only a rough BSP renderer with almost-complete
TTF rendering. Q3 is the inspiration, but my goal is for this is to be a
different game.

~~~
Jayschwa
Any tips for rendering text? I'm doing a similar project for Quake 2 with
Julia[1]. I haven't tackled text yet, but I probably will need to soon.

[1]: <https://github.com/jayschwa/Quake2.jl>

~~~
georgemcbay
I highly recommend looking at signed distance maps for text rendering.
Relatively easy to implement and gives very good results even when drastically
scaling the text to different sizes.

Potentially useful links:

[http://www.valvesoftware.com/publications/2007/SIGGRAPH2007_...](http://www.valvesoftware.com/publications/2007/SIGGRAPH2007_AlphaTestedMagnification.pdf)

[http://www.gamedev.net/topic/491938-signed-distance-
bitmap-f...](http://www.gamedev.net/topic/491938-signed-distance-bitmap-font-
tool/)

[https://github.com/OpenGLInsights/OpenGLInsightsCode/tree/ma...](https://github.com/OpenGLInsights/OpenGLInsightsCode/tree/master/Chapter%2012%202D%20Shape%20Rendering%20by%20Distance%20Fields/demo)

------
primitur
Was anyone able to build this?

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 ..

------
38leinad
not 100% on topic, but as the author is doing his mod because he likes to have
a voxelized and fully destrutable word: I remember Red Faction. Is there any
in-depth review/interview on the technology they used at the time? Looked like
"simply" carving out destructed structures from a polygon model; But would be
interested in the details...

------
Maro
Why is this interesting?

~~~
sophacles
Why is this comment necessary? You don't have to read code or links if you
don't want to. This is even worse than the "how is this topic relevant to
_hacker_ news" style comment.

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.

~~~
perishabledave
The comment could be out of a genuine desire to understand what makes the code
interesting. The brevity makes it a bit ambiguous.

~~~
coldtea
No, the comment seems like the author being a jackass.

A genuine desire to understand would have used different questions altogether.

~~~
zerr
It is actually a pretty neutral and dry comment, which is not necessary a
"jackassness". Also, this is not a one-to-one conversation, other people read
these threads as well. So some of them, which are genuinely interested, could
benefit from detailed answers.

~~~
coldtea
> _It is actually a pretty neutral and dry comment, which is not necessary a
> "jackassness"._

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".

