News for hackers. Stuff that matters.
Re:Notch trying jsFiddle by antirez on Sunday December 02, 2012 @05:50PM (#4862910)
Awesome implementation, actually no advanced feature is used, this code could easily ported even to assembler in any device where you can set pixels in RGB format.

And indeed it is pretty impressive how fast the rendering happens given that the code operates at such lower level... Even selecting the color of every pixel requires non trivial work in the inner loop.

AWESOME code.

Re:Notch trying jsFiddle by jrogers65 on Monday December 03, 2012 @04:34AM (#4864649)
I would argue that this is terrible code. It's not using the appropriate tools (webGL), it's badly structured, uncommented and unmaintainable (seriously, why on earth would anyone name their variables zd, _zd and __zd?). The Minecraft source code is also of notoriously poor quality. I honestly don't understand how you came to your conclusion.
Re:Notch trying jsFiddle by mmcnickle on Monday December 03, 2012 @04:54AM (#4864704)
The code is a direct port of Minecraft4k[1], it's optimised for space considerations.

[1] https://twitter.com/notch/status/275329867984302081

Re:Notch trying jsFiddle by jrogers65 on Monday December 03, 2012 @05:16AM (#4864768)
But that directly backs up my argument. From the horses mouth:

"Code is awful due to the nature of the project"

Re:Notch trying jsFiddle by antirez on Monday December 03, 2012 @07:48AM (#4865144)
It's an handful amount of lines of code doing a world generation, texture map generation, and ray casting rendering with a few tricks like a simple lightning model that still looks good.

All this using nothing more than a frame buffer, so you could port this easily from a C64 to any other computer. This code contains a lot of knowledge VS use of pre-build APIs.

If a programmer reads this code and understands how every part works, he or she ends knowing a lot more about computer graphics than before.

Re:Notch trying jsFiddle by General_Mayhem on Monday December 03, 2012 @08:06AM (#4865199)
>This code contains a lot of knowledge VS use of pre-build APIs.

It contains a lot of general knowledge about 3D graphics, and absolutely 0 specific knowledge about the environment in which it's running. All he's accomplished by doing it this way is show off that he knows trig and prevent any of it from being hardware accelerated.

>If a programmer reads this code and understands how every part works

But he never will, because the code is illegible.

Re:Notch trying jsFiddle by antirez on Monday December 03, 2012 @08:45AM (#4865307)
I hope this simplified version helps. I removed texture mapping and camera rotation, plus simplified a few unusual constructs.

https://gist.github.com/4195130

Re:Notch trying jsFiddle by HyprMusic on Monday December 03, 2012 @08:59AM (#4865348)
JsFiddled version: http://jsfiddle.net/ter7G/
Re:Notch trying jsFiddle by Jare on Sunday December 02, 2012 @06:12PM (#4863000)
Indeed, writing straightforward code with no dynamic memory allocations, and simple and predictable types, lets the VM do wonders with optimization and JITting. Good stuff.
Re:Notch trying jsFiddle by WA on Sunday December 02, 2012 @05:55PM (#4862927)
I totally agree. You probably meant "code operates at such a _high_ level" :)

low level = close to hardware, high level = high abstraction, like JS

Re:Notch trying jsFiddle by antirez on Sunday December 02, 2012 @05:58PM (#4862942)
No I really mean low level :-)

Javascript is high level, but here notch is using it as a low level framebuffer.

Re:Notch trying jsFiddle by alexhaefner on Monday December 03, 2012 @01:28AM (#4864205)
I respectfully disagree with your use of low level, though I do understand your analogy about the pixelbuffer being like a frame buffer.

But he's actually using Javascript arrays which can get passed around inside a javascript VM, and do not have a set size. Not very "low level".

I spent a moment and changed the arrays to Float32Arrays which have set sizes and sit in memory without being fucked with by the VM and sped the demo up dramatically.

http://jsfiddle.net/uzMPU/2612/

Re:Notch trying jsFiddle by malkia on Monday December 03, 2012 @04:03AM (#4864576)
If possible the map array should be uint8_t, while texmap uint32_t
Re:Notch trying jsFiddle by look_lookatme on Monday December 03, 2012 @01:52AM (#4864262)
Side by side, this is amazingly smoother than the OP.
Re:Notch trying jsFiddle by philf on Monday December 03, 2012 @04:17AM (#4864610)
For me, the difference is only visible using Firefox. Chromium even renders the inefficient original version smoothly.
Re:Notch trying jsFiddle by mdonahoe on Tuesday December 04, 2012 @05:33AM (#4870264)
The magic of Just In Time compilation perhaps?
Re:Notch trying jsFiddle by Tloewald on Monday December 03, 2012 @08:25AM (#4865255)
Interesting -- this is slower on my iPad.
Re:Notch trying jsFiddle by experiment0 on Sunday December 02, 2012 @06:02PM (#4862958)
> And indeed it is pretty impressive how fast the rendering happens given that the code operates at such lower level.

Sorry if this is a stupid question, but wouldn't you normally expect low level code, whilst more time consuming to write, be faster or just as fast as higher level code.

For example, how C is used as a standard for fast code since it's so low level.

Re:Notch trying jsFiddle by antirez on Sunday December 02, 2012 @06:19PM (#4863022)
If you are using C, you can afford to compute everything at low level as Notch is doing in this example. And you can afford writing pixel by pixel into a frame buffer that is later rendered.

However if you use this approach in Javascript you get poor performances unfortunately. And indeed this demo requires fast computers to do what otherwise could be done in C with direct access to the video frame buffer with maybe 50 times slower computers.

Even C coders almost no longer try to do this low level things and let the graphic chip do a lot of the work when the goal is to produce a game.

So in Javascript instead you want to usually call a library that implements a 3D engine in a lower level language like C and with more direct hardware access.

But in this case, it makes sense to do all this in a low level way and in Javascript: it is just a demo that is full of interesting code and with an appealing visual output.

Re:Notch trying jsFiddle by shawnz on Sunday December 02, 2012 @06:35PM (#4863093)
Yes, but when you write in a high-level language like javascript without taking advantage of all of the high-level features like webgl (which are provided by the implementation and assumed to be fast), performance suffers.

In this case, Notch is writing code that doesn't necessitate the overhead of using JS. It could easily be rewritten as C and probably run faster that way. Not that it isn't interesting, of course.

Re:Notch trying jsFiddle by dudus on Sunday December 02, 2012 @06:19PM (#4863021)
You would expect low level code to be very fast in a low level language because it runs directly on metal. But on a high level language low level code get's translated into another code, so the code runs on the hardware is much more complicated. By using the high level features on Javascript actually leads to better optimized low level code.
Re:Notch trying jsFiddle by WA on Sunday December 02, 2012 @06:00PM (#4862951)
Ah ok, thanks for clarification
Re:Notch trying jsFiddle by ukjadoon on Sunday December 02, 2012 @05:54PM (#4862924)
If the creator of Redis approves this, it's definitely awesome! =)