Quick tips

BlitzMax Forums/BlitzMax Beginners Area/Quick tips

EOF(Posted 2004) [#1]
Flip an image by using negative values in SetScale:
SetScale -1,1  ' next drawn image is flipped horizontally
DrawImage character,23,40
Your turn ..


fredborg(Posted 2004) [#2]
Access parts of strings with slices. Beats using Left(),Right() and Mid():
t:String = "Hello"
Print Mid(t,4,2)
Print t[3..5]
Don't know how big your array is? No worries, you can step through it using length or with EachIn:
Local yo:Int[Rand(100)]

For j = 0 To yo.length-1
	yo[j] = j
Next

For j:Int = EachIn yo
	Print j
next



Hotcakes(Posted 2004) [#3]
For those new to Max coming from previous Blitz's, "Global"s are now much slower than "Local"s.

Technically speaking though, the reverse is true - Global's are slightly faster than in older versions of Blitz, but Locals are lightning fast now.


flying willy(Posted 2004) [#4]
Locals get pushed onto the CPU registers, while globals are always stored in system ram. You can still use globals, but I think you should design tight loops that use all-locals.

Another tip: render your objects in order of image for a mild speed boost (ie. all image A then all image B). Although this isn't essential at all.

LoadAnimImage currently splits the image strip into different textures: I think that it should use a single texture -if the programmer specifies- because sometimes people will be using large anim images.


Drago(Posted 2004) [#5]
some more info to do with globals, and consts

a global in a function.
function keeptrackofsomething()
   global tracker:int
  traker:+1
  print tracker
end function

is global to that function, ie if you call the function 5 times you will get
1
2
3
4
5
printed out.
but any code outside the function can't change that varible.

function coolfeature()
 const coolfactor = 1000
 print coolfactor
end function

coolfeature()
print coolfactor


this will result in the
1000 and 0 being printed.

this lets you have vars that are only constant to a function, not the whole code.

cool eh?


Shagwana(Posted 2004) [#6]
Where possible, replace SetRotation() and SetScale() with SetTransform() - will compile to less code and execute a tiny amount faster!


EOF(Posted 2004) [#7]
Do shorthand coding by using ':'
from   MyRedAlien.XPos=MyRedAlien.XPos+225
to     MyRedAlien.XPos:+225

For line continuation use '..'
DrawImageRect MyBigAlien.image,MyBigAlien.X,MyBigAlien.Y,..
              MyBigAlien.Width,MyBigAlien.Height

To reduce the headache of syncing your mods create a *.bat file in your main BlitMax folder which looks like this:
Credits: BotBuilder
cd bin
bmk syncmods -u MyUserName -p MYPASSWORD


Turn frame limting on/off by using bglsetswapinterval:
Credits: Dreamora
bglSetSwapInterval 0  'OFF
bglSetSwapInterval 1  'ON


Use 'Framework' and UPX for small *.exe sizes.
This example comes out at 16.5K (Win32) after the above treatments:
framework BRL.StandardIO
Print "Hello world"



EOF(Posted 2005) [#8]
EDIT: Added to BlitzWiki - Performance Tips


Faster plotting ..

This method will speed up rendering of starfields etc ...

Instead of:
For s:star=Eachin starlist
 Plot s.x,s.y
Next

Try this:
glDisable GL_TEXTURE_2D
glBegin GL_POINTS
For s:star=EachIn starlist
  glVertex2f s.x+0.5,s.y+0.5 
Next
glEnd
glEnable GL_TEXTURE_2D
(I managed to gain an extra 7000 plots per frame for instance!)

Give it a whirl:



fredborg(Posted 2005) [#9]
Ahh, never mind then...When jb changes his code I remove mine :D


EOF(Posted 2005) [#10]
(blunder corrected- thanks fb)

Not tested but I suspect DrawLine, DrawRect, etc can benefit from the same technique.


xlsior(Posted 2005) [#11]
JB: That certainly makes a difference!

On my computer:

Normal: 1944455
Faster: 2543586
Gain: 599131

That's a difference of 9985 plots per frame.


FBEpyon(Posted 2005) [#12]
I was trying to do the setscale trick and it doesn't work for me am i doing something wrong its being put in just like you had it. Also this image is a created image if that makes any diff