Not logged inGosu Forums
Forum back to libgosu.org Help Search Register Login
Up Topic Gosu / Gosu Showcase / Little Raycaster I Made :)
- - By JosephAustin Date 2016-11-05 03:30
I created a raycasting engine using pure Gosu. I originally had it in Ruby but the setPixel calls required to do floor and ceiling were much too slow, so it's in C++. Maybe when I have time again, I'll write bindings.

In Action: https://www.youtube.com/watch?v=DfSvatZGd-s
Don't judge, I slapped the art together fast in Gimp to get the point across. ;D

Here's the code:
https://github.com/JosephAustin/GosuRaycast

:) Hope someone has some fun with it.
Parent - - By jlnr (dev) Date 2016-11-06 10:57
Cool stuff! I like your fearless use of calling .subimage() just to create temporary image slices! I've never thought about that before, but performance-wise that's perfectly fine.

Are you aware of this ancient Ruby/Gosu raycaster? https://github.com/zenkalia/rubystein
It was originally written by the Phusion team as a parody of the Rails dev world (lots of in-jokes). To avoid setPixel they used the Wolf3D approach to draw vertical lines. So not W*H setPixel() calls, but W Image#draw calls.

I guess the next step would be a voxel engine :P
Parent - - By JosephAustin Date 2016-11-07 00:52
I didn't see that, actually! I would have probably referenced that instead. Either way, it was a fun thing to do and learn from. And I'm happy with my use of lambdas - if that were wrapped correctly for ruby you could use a block. Keeps the engine from caring about map formats!

.subimage() worked a heck of a lot faster than I expected it to. It appears to be a direct reference somehow, instead of a copy. As for .setPixel(), it's definitely a LOT faster in c++ than ruby. That's due to the sheer number of calls you have to do, I suspect, which have to 'cross the bridge' between the languages. Even 640x480 would be up to 300k calls, but it seems to be no problem when its done directly. I'm easily holding 60 fps at those kinds of resolutions.
Parent - - By jlnr (dev) Date 2016-11-07 09:07
subimage only uses one or two object allocations, and yes, it only references the texture data.

Looking at the C++ source again, I think that you also render walls line by line, right (vertically)? Then Rubystein probably uses the same logic as your raycaster, except they didn't even bother colouring the floor and ceiling - that's why it's fast enough in Ruby.

The old Gosu Showcase board has a screenshot: https://www.libgosu.org/cgi-bin/mwf/topic_show.pl?pid=557

I don't think that the interop between Ruby and C++ is the issue, after all many core Ruby methods (Array#each etc.) are written in C. It's probably the loop itself that's excruciatingly slow in Ruby.
Parent - By JosephAustin Date 2016-11-08 00:14
Oh, I see. Yes, I do it with lines. The floor/ceiling has to be drawn pixel by pixel. Wolfenstein didn't bother with that. That was more something doom did, but the lessons I referenced showed how it works so I went ahead and applied it.

My demo doesn't really show it off, but you can have multiple floor tiles and ceiling tiles, and can even have 'holes' in either. I started to take it further with pits and such, but that required rendering more walls above or below the current ones, which had a lot of speed problems.

It was fun to do :) Maybe i'll make a game in it sometime for the heck of it.
Up Topic Gosu / Gosu Showcase / Little Raycaster I Made :)

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill