Stories
Slash Boxes
Comments

SoylentNews is people

posted by n1 on Thursday June 05 2014, @05:39AM   Printer-friendly
from the still-seething-about-programming-languages dept.

From Boing Boing:

Hunter Loftis, who created the fractal terrain generation in 130 lines of Javascript engine, has done it again: a full-blown first-person shooter engine in 265 lines (source). He used a technique called ray casting, and goes into some detail about this choice and where this could go next.

More information can be found here.

Raycasting feels like cheating, and as a lazy programmer, I love it. You get the immersion of a 3D environment without many of the complexities of "real 3D" to slow you down. For example, raycasts run in constant time, so you can load up a massive world and it will just work, without optimization, as quickly as a tiny world.

Related Stories

Asking Permission: Running piWik To Get An Idea About Our Usage 83 comments
So, right now, I'm currently sitting with mrcoolbp and martyb in meatspace working out the finer points of incorporation, and the future needs of SoylentNews. One thing that has come up is we really don't have a great idea of our actual usage numbers are. Slashcode has decent internal numbers which give us some rough numbers, but they're only really valid for logged-in users (which bypass the varnish cache), and we're not 100% sure they're accurate anyway. According to slash, we're averaging approximately 50-60k page views per day (I've included the statistics email below), but it doesn't help us in knowing what AC usage look like. According to varnish, we average roughly 400-500k connections per day, but that number is inflated since we're not using keep-alive or HTTP pipelining as of yet.

Furthermore, since we don't log IP addresses in access.log, and IP's run through Slash are turned into IPIDs, its hard to get an idea of where our userbase is (the general feeling is the vast majority of us are based in the United States, but even then, that's more because our peak hours of traffic are between 4 and 10 PM EST). We've wanted to get a better idea of what our traffic and userbase are, so we're asking permission from the community to install piWik, and embed its javascript tag in the footer of each page, which will give us a wide berth of solid information to work from.
This discussion has been archived. No new comments can be posted.
Display Options Threshold/Breakthrough Mark All as Read Mark All as Unread
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
  • (Score: 3, Interesting) by c0lo on Thursday June 05 2014, @05:54AM

    by c0lo (156) Subscriber Badge on Thursday June 05 2014, @05:54AM (#51511) Journal
    Without optimized/ing structures [wikipedia.org], doesn't it scale with the number of objects in the "world"? So that "constant" is only the number of pixels you want to render, but otherwise is O(N)?
    --
    https://www.youtube.com/watch?v=aoFiw2jMy-0 https://soylentnews.org/~MichaelDavidCrawford
    • (Score: 1) by hendrikboom on Saturday June 07 2014, @08:46PM

      by hendrikboom (1125) Subscriber Badge on Saturday June 07 2014, @08:46PM (#52757) Homepage Journal

      Actually, its performance improves with object density. Rays that get stopped quickly on nearby objects don't have to be traced to the far hills.

      • (Score: 1) by hendrikboom on Saturday June 07 2014, @09:12PM

        by hendrikboom (1125) Subscriber Badge on Saturday June 07 2014, @09:12PM (#52765) Homepage Journal

        I guess there *is* an optimization data structure -- the terrain is modelled as a 2-D array, and all objects are aligned with grid lines. This limits the number of places it has to test to trace the ray. No fancy data structures like octrees, but the algorithm does rely on rays terminating early. A grid only sparsely populated with objects, and having to show object that are thousands of grid squares away would definitely slow it all down.

  • (Score: 2) by aristarchus on Thursday June 05 2014, @06:44AM

    by aristarchus (2645) on Thursday June 05 2014, @06:44AM (#51520) Journal

    But, it is still Javascript. Fail

    • (Score: 1) by Gremlin on Thursday June 05 2014, @08:00AM

      by Gremlin (2959) on Thursday June 05 2014, @08:00AM (#51541)

      I don't see the fail here? What he's done is pretty cool. Sure, Javascript may have limitations but you could take what he's done and re-write in a 'proper' language if you like.

      • (Score: 1) by Anonymous Coward on Thursday June 05 2014, @12:06PM

        by Anonymous Coward on Thursday June 05 2014, @12:06PM (#51618)

        He hasn't done anything but implement 20+ year old technology in Javascript. And why bother rewriting what he's done? Why not simply use the Wolfenstein 3-D engine instead?

    • (Score: 2) by tibman on Thursday June 05 2014, @06:04PM

      by tibman (134) Subscriber Badge on Thursday June 05 2014, @06:04PM (#51820)

      I think you'll find that javascript will become a much more important language in the next five years. It is replacing server-side languages.

      --
      SN won't survive on lurkers alone. Write comments.
  • (Score: 1) by larku on Thursday June 05 2014, @06:57AM

    by larku (4429) on Thursday June 05 2014, @06:57AM (#51526)

    So what's the catch?

    Are there some limitations with using this technique vs traditional 3D?

    • (Score: 4, Interesting) by Jaruzel on Thursday June 05 2014, @07:53AM

      by Jaruzel (812) on Thursday June 05 2014, @07:53AM (#51538) Homepage Journal

      Using his code directly, you are limited to only a 2D environment, there is no up/down movement/look (Think the original Wolfenstien 3D). To add movement and rendering in the third dimension, you'd need to significantly up the maths* quota in the code.

      Nonetheless, this is still a pretty good breakdown of how to do a simple '3D' environment. I've bookmarked it, as I've always fancied writing a dungeon crawler type game but the 3D maths* have always eluded me (I'd have to convert the JS code into a real language first, but the maths principles and the concept are the same).

      Now I think about it, Wolf3D and Doom probably used a very similar technique...

      -Jar

      *Maths not Math, as I'm British.

      --
      This is my opinion, there are many others, but this one is mine.
      • (Score: 2) by Marneus68 on Thursday June 05 2014, @08:06AM

        by Marneus68 (3572) on Thursday June 05 2014, @08:06AM (#51546) Homepage

        > Now I think about it, Wolf3D and Doom probably used a very similar technique...

        That's true, I made a longer list in my reply, but the list of games using this technique is quite long.

        > I've bookmarked it, as I've always fancied writing a dungeon crawler type game but the 3D maths* have always eluded me (I'd have to convert the JS code into a real language first, but the maths principles and the concept are the same).

        You read my mind my friend !

      • (Score: 0) by Anonymous Coward on Thursday June 05 2014, @11:12AM

        by Anonymous Coward on Thursday June 05 2014, @11:12AM (#51578)

        I'd have to convert the JS code into a real language first,

        I've written js raycasters before, I could have used C / SDL but it was something I did for fun. I think you'll find that javascript is quite real.

        • (Score: 2) by Jaruzel on Thursday June 05 2014, @11:56AM

          by Jaruzel (812) on Thursday June 05 2014, @11:56AM (#51608) Homepage Journal

          Yes, but I can't deploy a JS based game via Steam or Google Play though, can I ?

          Which is kinda what I meant. Plus writing extensive stuff in javascript is like pulling your teeth out via the back of your own skull.

          -Jar

          --
          This is my opinion, there are many others, but this one is mine.
    • (Score: 3, Interesting) by Marneus68 on Thursday June 05 2014, @08:02AM

      by Marneus68 (3572) on Thursday June 05 2014, @08:02AM (#51542) Homepage

      The main catch is that it's not really 3D, it's merely 2.5D (and not in the way that it's a platform game made with a 3D engine) much like Doom or Duke Nukem 3D. Basically, you can't have overlapping rooms without a lot of fiddling, and rendering 3D models will be a real pain. If you've played Wolfenstein 3D, Doom, Heretic, Hexen, Duke Nukem 3D of TES:Arena.

      And despite the claims of the dev, Daggerfall uses a real 3D engine.

    • (Score: 0) by Anonymous Coward on Thursday June 05 2014, @12:14PM

      by Anonymous Coward on Thursday June 05 2014, @12:14PM (#51622)

      The catch is that it's Javashit.

    • (Score: 0) by Anonymous Coward on Thursday June 05 2014, @01:19PM

      by Anonymous Coward on Thursday June 05 2014, @01:19PM (#51649)

      The catch is that it pegs a multicore i7 CPU to do nothing more advanced than what Wolfenstein 3-D did 22 years ago and could do it on a 386.

  • (Score: 0) by Anonymous Coward on Thursday June 05 2014, @09:16AM

    by Anonymous Coward on Thursday June 05 2014, @09:16AM (#51556)

    I think you'd be much better off browsing Shadertoy.com than looking at raycasting done in JS.

    • (Score: 3, Funny) by Jaruzel on Thursday June 05 2014, @10:18AM

      by Jaruzel (812) on Thursday June 05 2014, @10:18AM (#51569) Homepage Journal

      Shadertoy.com totally nuked my browser (Firefox), thanks for that :)

      --
      This is my opinion, there are many others, but this one is mine.
    • (Score: 0) by Anonymous Coward on Thursday June 05 2014, @11:00AM

      by Anonymous Coward on Thursday June 05 2014, @11:00AM (#51576)

      I just get a json parse error.

    • (Score: 1) by larku on Thursday June 05 2014, @11:26AM

      by larku (4429) on Thursday June 05 2014, @11:26AM (#51585)

      Shadertoy is really good for sharing and playing with shaders but what does that have to do with using raycasting to achieve a 3D like environment?

  • (Score: 3, Funny) by jimshatt on Thursday June 05 2014, @09:59AM

    by jimshatt (978) on Thursday June 05 2014, @09:59AM (#51563) Journal
    That's not a First Person Shooter, it's a First Person Stabber! I could find the stab key, but since there aren't any enemies that's not really a problem.
    • (Score: 2) by jimshatt on Thursday June 05 2014, @10:02AM

      by jimshatt (978) on Thursday June 05 2014, @10:02AM (#51565) Journal
      AAAARgh! I did use preview but because it warned my about the caps in my title (I used FPS instead of fps) I only concentrated on fixing that and didn't pay attention to the rest of my post. I meant "I couldn't find the stab key", of course.
  • (Score: 2) by chebucto on Thursday June 05 2014, @11:34AM

    by chebucto (36) on Thursday June 05 2014, @11:34AM (#51589) Journal

    I wrote a first-person shooter in _1 line of batch script_, and that was 20 years ago!

    • (Score: 0) by Anonymous Coward on Thursday June 05 2014, @12:32PM

      by Anonymous Coward on Thursday June 05 2014, @12:32PM (#51629)

      Did it simply launch Wolfenstein 3D?

      • (Score: 2) by chebucto on Thursday June 05 2014, @01:20PM

        by chebucto (36) on Thursday June 05 2014, @01:20PM (#51650) Journal

        Perhaps, but use of external libraries is good programming practice!

        On a more serious note, I paged through the linked JS and by my reading the author isn't using any libraries, so hats off to him :)

        • (Score: 0) by Anonymous Coward on Thursday June 05 2014, @01:26PM

          by Anonymous Coward on Thursday June 05 2014, @01:26PM (#51656)

          Using Canvas to render the scene.

  • (Score: 3, Interesting) by SpallsHurgenson on Thursday June 05 2014, @01:18PM

    by SpallsHurgenson (656) on Thursday June 05 2014, @01:18PM (#51648)

    This reminds me of .kkrieger [wikipedia.org], a first-person shooter written in 96KB; it was full 3D and the package included multiple levels, weapons, procedurally-generated textures and sounds.

    Still, a pseudo-3D game in 120 lines of code isn't anything to dismiss outright either; limited as the final product may be, it is still amazing in how much you can do with so little.

    • (Score: 0) by Anonymous Coward on Thursday June 05 2014, @01:22PM

      by Anonymous Coward on Thursday June 05 2014, @01:22PM (#51652)

      It's only 120 lines of code because the browser uses thousands of lines of code to actually implement the hard stuff for him.

      • (Score: 1) by kaganar on Thursday June 05 2014, @02:00PM

        by kaganar (605) on Thursday June 05 2014, @02:00PM (#51676)


        It's only 120 lines of code because the browser uses thousands of lines of code to actually implement the hard stuff for him.

        I used to think this way -- hated libraries because you had to stomp through mediocre documentation to get simple seeming things to work. Then I woke up one day, realized that I was saving hours if not days of time by not reinventing the incredibly mundane wheel of how to draw a dialog box or how to initialize OpenGL buffers. These tasks were so commonplace that they had literally been done thousands of times before, with scores of books and websites telling you how.

        Now I shop for the right library before I jump off the cliff into the oblivion of coding it all myself. Even better is when there's a near-standard library that already does it -- fantastic support, very likely to be right (compared to my own code which is far less tested), and features I didn't know I wanted.

        Are there downsides? Sure. Sometimes I feel more lost while debugging, other times I have to mind how I set up linking, and yes, I still have to look through documentation. But overall I get 3x the work done -- and that's just smart.

        • (Score: 2) by hubie on Thursday June 05 2014, @02:15PM

          by hubie (1068) Subscriber Badge on Thursday June 05 2014, @02:15PM (#51684) Journal

          You're absolutely right, but it is a bit tangential to the AC's comment. The article summary talks about a specific (and small) number of lines of code that is clearly meant to impress the reader; however, it is cheating to quote code line counts and rely on libraries, unless you count the lines of code in the libraries.

          • (Score: 2) by Angry Jesus on Thursday June 05 2014, @07:45PM

            by Angry Jesus (182) on Thursday June 05 2014, @07:45PM (#51869)

            However, even "hello world" relies on tens to hundreds of thousands of lines of OS code to work. It doesn't seem unreasonable to draw the line at, "how much code do I have to write myself?"

            • (Score: 2) by nukkel on Friday June 06 2014, @09:07PM

              by nukkel (168) on Friday June 06 2014, @09:07PM (#52405)

              Not when writing it to a parallel-port matrix printer using DOS assembly.

        • (Score: 0) by Anonymous Coward on Thursday June 05 2014, @03:00PM

          by Anonymous Coward on Thursday June 05 2014, @03:00PM (#51718)

          Where did I say that I hate libraries? Smells suspiciously of strawman. My point is his LOC statement is disingenuous. Now if he wrote all of the rendering code as well in the same lines of code that would be impressive, but he just implemented the easy part and then patted himself on the back.

  • (Score: 2) by tibman on Thursday June 05 2014, @06:08PM

    by tibman (134) Subscriber Badge on Thursday June 05 2014, @06:08PM (#51822)

    The small size is impressive but not the result. For something that looks impressive, take a look at threejs: http://threejs.org/ [threejs.org]

    --
    SN won't survive on lurkers alone. Write comments.
  • (Score: 2, Insightful) by arslan on Thursday June 05 2014, @10:41PM

    by arslan (3462) on Thursday June 05 2014, @10:41PM (#51944)

    What's with all the JS hate here in SN? Its not such a bad language, it has its quirks, but if you can get past that its pretty good. Its powerful enough that any moron can write unmanageable code with it, but that is no different than C or Java or Scala.

    The whole web is driven by it nowadays and frankly I'd rather have JS content than Flash, Java Applets or Silverlight.

    It is also evolving very rapidly as newer versions with features are being added. As for JS on the server side the jury is still out on that (for me at least), though that movement is still growing strong. Its a technology like anything else, although it had a pretty bad start and poorly named, propeller heads should look at it like any other tool. Given its significance for the web, I'd say its a pretty important tool.

    • (Score: 2) by c0lo on Friday June 06 2014, @12:13AM

      by c0lo (156) Subscriber Badge on Friday June 06 2014, @12:13AM (#51981) Journal

      As for JS on the server side the jury is still out on that (for me at least), though that movement is still growing strong

      If some can write high quality server-side [doctrine-project.org] frameworks [symfony.com] in PHP (I repeat: yes, PHP, no less), then it should be possible to do it in Java-/ECMA-script as well.
      (the links provided: essentially, they're Hibernate-like and Spring-like frameworks in PHP. Including the possible use of annotations)

      --
      https://www.youtube.com/watch?v=aoFiw2jMy-0 https://soylentnews.org/~MichaelDavidCrawford
    • (Score: 2) by tibman on Friday June 06 2014, @01:25PM

      by tibman (134) Subscriber Badge on Friday June 06 2014, @01:25PM (#52224)

      I'd say it's fairly normal. I'd go further and say that almost every dynamic language mentioned here will draw hate, that is just the way it is : /

      --
      SN won't survive on lurkers alone. Write comments.
  • (Score: 0) by Anonymous Coward on Friday June 06 2014, @04:39AM

    by Anonymous Coward on Friday June 06 2014, @04:39AM (#52070)

    265 lines in a HLL? Well, in that case, here's most FLOSS in one line shell:

    make

    You even get different programs depending on where and when you run that single LoC! Can I have an SN article now pls?

    I mean, what really matters is the resultant binary, time and space complexity of algorithms used, how many and what dependencies there are, and what platforms it runs on. FFS.