If you are a child of the 90s, you certainly will remember Comanche: Maximum Overkill. The graphics were awesome and way ahead of its time. Remember, we didt have fancy 3D accelerated graph cards. With your Comanche you could fly over the landscape, diving towards the enemy. It was fun! Ive must have spend hundreds of hours playing with this.
It is surprising how little code is needed to reproduce this experience. In the article on my blog, well build the 3D world and will be able to fly, dive etc over the landscape with Xojo in less than 100 lines of code!
Nicely done! That is remarkable efficient coding Alain!
Under what license are you releasing your code? Would you mind if I used your routines it in the open source X3 project, that I’m working on? Will give credit to Alwaysbusy’s Corner.
Great stuff. Looking forward to play with the code
Just a quick one, not sure if it’s a focus thing on Windows, but I had to move the KeyDown code from the Canvas event to the keydown event of the Form, for the navigation to work.
I’ve coded it on Windows in RB2007R4. Maybe the form got the focus, not the canvas when you start up. Will post your solution on my blog in case someone else has this problem. thx
This is so awesome, great code! FYI, the OS X binary fails with a NOE here on OS X 10.9.4 - I haven’t had a chance to build from source or try the Windows version yet.
Thanks @Bill Gookin and @Gavin Smith Not being a mac man myself, I hadn’t tested it on OSX. Note that this is some old code I had laying around and a reader from reddit just pointed my back to the original coder (Sebastian Macke) who made it in javascript.
Alain this is pretty cool stuff and I am deeply Impressen how easy voxel algorithm is…
Runs perfect on Mac OS X here and I’ve found a snipped here in forum to speed up drawing of canvas a little bit and added this to the .Paint Event of the Canvas.
#pragma BackgroundTasks false
#if TargetMacOS
declare sub CGContextSaveGState lib "Cocoa" ( context as integer )
declare sub CGContextSetInterpolationQuality lib "Cocoa" ( context as integer, quality as integer )
declare Sub CGContextRestoreGState lib "Cocoa" ( context as integer )
dim CGContextRef as integer = g.handle( g.HandleTypeCGContextRef )
CGContextSaveGState CGContextRef
CGContextSetInterpolationQuality CGContextRef, 1
#endif
' draw the buffer to the canvas
if mBuffer <> nil then
g.DrawPicture mBuffer,0,0
end if
#if TargetMacOS
CGContextRestoreGState CGContextRef
#endif
#pragma BackgroundTasks true
I’ve also used the usual suspects of #pragma diectives (BackgroundTasks, Checks etc.) to speed this up a bit…
Have you tried drawing directly to the canvas, rather than caching it to a Picture object? This will give you a speed boost on the Mac, especially as the Mac OS is already double buffered?
If you must cache it on the Mac, then I would advise using CG commands directly and caching to a CGLayer, as this is lightning fast! CGLayers is how we managed to do animation at 245 fps in a full screen Retina ready application. But it does require using native CG as opposed to Xojo functions.
Yes there is plenty room for optimizations
When running compiled app I get a framerate around 10 fps…
Tonight (with my MacBook in bed) I’ve added two Timers, one for reading the cursor keys (Keyboard.AsyncKeyDown) every 100 ms and another one for updating the scene in order to add more functionality.
Cursor keys now sets a speed variable, and the Speed is indicated on HUD Screen. I wanted to add a collision detection next but hence… the time… it’s always the time… I am passing the baton to the next one…
Cool that people are looking into this! Indeed, there is a lot that can be done to speed this up, but the subject of the article was the algorithm in pure Xojo in 100 lines of code.
With some fiddling, a lot of the original game can be created now that the engine is here. When I find the time, I’m going to try to emulate the ‘swing’ the heli does when turning.
I’m going to check out your versions (Nice, the HUD is already working!) May I use some of the code to do a follow up article? Credits will be given.
Hi Alain you’re completly right and of course you may use the code. There’s nothing special about these few lines I added. And I am sure somebody (with more time) will improve it more.