[Semi OT] Language for Game Development talk
bearophile via Digitalmars-d
digitalmars-d at puremagic.com
Fri Sep 19 17:52:04 PDT 2014
Max Klyga:
> https://www.youtube.com/watch?v=TH9VCN6UkyQ
I like the focus on correctness of the Rust language (but
currently Rust seems to ignore several kinds of correctness,
focusing only on two kinds), but I understand that the needs of
creating a modern browser (that is a long lived project, where
like in a kernel the correctness is very important, and the speed
of writing code is not important) are different from the needs of
creating a modern video game. So he chooses differently than Rust.
It's a long talk. He doesn't like exceptions, not GCs. Several of
the things he says are already present in D, but he is looking
for a language that is simpler than D.
He suggests code like this (the syntax is not so important) in
his new language:
--------------------------
struct Mesh {
Vector3 []! positions;
int []! indices; @joint positions
Vector2 []! uvs; @joint positions
}
mesh.positions.reserve(num_vertices);
mesh.indices.reserve(num_indices);
mesh.uvs.reserve(num_vertices);
--------------------------
"int []" seems like a D dynamic array, it contains the pointer to
the data and its length.
The "!" means the memory of this array is owned by the Mesh
stuct. So when the Mesh instantiation goes out of scope, all the
memory it owns gets deallocated.
The "@joint" annotation means that the memory of "indices" array
is allocated in the same chunk of memory used to allocate
"positions". The same happens for "uvs" array. So when you create
a Mesh you allocate only one chunk of memory for its owned
dynamic arrays.
"mesh.positions.reserve" allocates memory for the positions array
of the instance "mesh", but the compiler sees the (optional)
"@joint" annotation, and merges the three allocations into a
single one and then slices the memory for the three arrays (i
think the compiler raises a compilation error if it can't merge
them well).
He also likes an explicit simple syntax for nullable pointers. I
think the compiler enforces the presence of the null test for
nullable pointers (perhaps as in the Whiley language):
--------------------------
void do_something(Entity ?a) {
if (a) {
a.x = 0;
}
}
--------------------------
Bye,
bearophile
More information about the Digitalmars-d
mailing list