Some code you may find useful.

BlitzMax Forums/BlitzMax Programming/Some code you may find useful.

sswift(Posted 2009) [#1]
App.bmx:



sswift(Posted 2009) [#2]
Mouse.bmx:



Rawinput.bmx:


Projectionamtrix.bmx:



sswift(Posted 2009) [#3]
App.bmx allows you to set up a game which runs at any resolution and can toggle between windowed and fullscreen mode. It also contains an enhanced runtimeerror function as well as image loading functions which buffer the images in video ram, provide error handling, and can update a loading screen.

Mouse.bmx replaces the standard mouse input functions. With it you can get absolute or relative mouse movement with auotmatic mouse recentering code, and on Win32 systems, you can get raw mouse movement which is unaffected by pointer ballistics and allows you to take full advantage of high definition mice, which the standard mouse input functions would treat as being 400dpi.


Who was John Galt?(Posted 2009) [#4]
Nice one, thanks Swifty.


sswift(Posted 2009) [#5]
Slight update to the mouse code to make it work when the resolution is lower than the virtual resolution, and work better when it's higher and you're in windowed mode.


Tachyon(Posted 2009) [#6]
Possible Community Framework submission?


BlitzSupport(Posted 2009) [#7]
Looks like some really good stuff (the projection/letterboxing is particularly interesting to me), thanks a lot.

(Can we assume it's to be treated as public domain code?)


sswift(Posted 2009) [#8]
(Can we assume it's to be treated as public domain code?)


Yep!


GfK(Posted 2009) [#9]
I just had a play with the projectionmatrix code. When using letterboxing with the code below, the "800x600" window is drawn at the left of the screen, not in the middle. Why?

Graphics 640,400 'equivalent of 1280x800 WS

ProjectionMatrix.SetScale(800,600)
ProjectionMatrix.SetLetterbox(800,600)


While Not KeyDown(key_escape)
	Cls
	SetColor 255,255,255
	DrawLine 0,0,799,0
	DrawLine 799,0,799,599
	DrawLine 799,599,0,599
	DrawLine 0,599,0,0
	ProjectionMatrix.drawLetterbox()
	Flip
Wend
End


[edit] Actually I can use the following at the start of my draw loop:
	SetOrigin ProjectionMatrix.centerx() - (projectionmatrix.width()/2),projectionmatrix.centery() - (projectionmatrix.height()/2)
I guess I could stick the result of those two calculations into a var to avoid recalculating it every time.
Then modify the drawLetterbox() function to reset the origin to 0,0. Two SetOrigin's per cycle isn't going to break the bank - clocked it at 76ms for one million iterations.

Would the RenderState.Pop/Push stuff do this? Code wouldn't compile so I commented it out.


sswift(Posted 2009) [#10]
You actually benchmarked that? :-)

But yes, that's exactly what you should do.

In regards to renderstate, here's the code for that:

Renderstate.bmx:




The purpouse of which is to allow the drawletterbox function (and any other functions you might wish to use it in) to alter properties like the current draw color and reset them back to their previous state. Ths includes the origin, so if you put a SetOrigin after the push operation in the drawletterbox function, then it will be reset for you to whatever it was originally when the function exits. I suppose that would make your code a little cleaner, but it wouldn't improve the performance. :-)


sswift(Posted 2009) [#11]
Here's something else you might find useful:

Savegames.bmx:




A realtively simple type which stores player names, scores, and current level, and the player that last played the game in a data file. If the data file doesn't exist, it recreates it.

Could use a function to find a good directory to save the data in on Vista so it can be shared between user accounts, but it works as is if you don't care about that.


Wiebo(Posted 2009) [#12]
nice. but why not in the code archives?


GfK(Posted 2009) [#13]
You actually benchmarked that? :-)
Sure. Its the only way to find out how fast (or not) something is. I didn't want to do it if there'd be a performance hit.


sswift(Posted 2009) [#14]
I never benchmark anything unless I actually notice it causing a speed hit.


nice. but why not in the code archives?



Cause it was a spur of the moment decision and I didn't feel like writing a ton of really good documentation? :-)

Also, as is, these types aren't plug and play, they have some references to my sprite system in them.


levelord(Posted 2009) [#15]
Really cool stuff, O' Swift One! Thanks so much for all the help!


Charrua(Posted 2010) [#16]
hi sswift
i used most of your code to handle multiple keyboards, instead of register mouse i register keyboards:

http://blitzbasic.com/Community/posts.php?topic=88832

thank's a lot

Juan