LockPalette()
Posted: Mon Aug 08, 2005 1:11 am
I've been playing with palettes and I noticed something strange. If I change all the colors of a palette, it can get slower, but if I change all the colors of a palette I'm not using, I can get the same effect faster.
note: my fps aren't that accurate, if someone wants to improve the code it would be great.
First example (using the same palette all the time):
Second (swaping between two palettes)
Then I wondered, it would be possible to lock a palette, so that it wouldn't update its colors whenever you use SetPaletteColor() with the current palette:
LockPalette(#Palette)
...do all changes
UnlockPalette()
It would be very useful.
note: my fps aren't that accurate, if someone wants to improve the code it would be great.
First example (using the same palette all the time):
Code: Select all
InitSprite()
InitPalette()
InitKeyboard()
OpenScreen(640,480,8,"")
CreateSprite(0,640,480)
StartDrawing(SpriteOutput(0))
For x=0 To 639
For y=0 To 479
Plot(x,y,Random(255))
Next y
Next x
StopDrawing()
CreatePalette(1)
CreatePalette(0)
DisplayPalette(0)
DisplaySprite(0,0,0):FlipBuffers():DisplaySprite(0,0,0)
Repeat
flow=(flow+1)&255
For n=0 To 255
SetPaletteColor(n,(flow+n)&255)
Next n
time=time+(ElapsedMilliseconds()-oldtime)
frame=frame+1
If time=>1000
framerate=frame:frame=0:time=0
EndIf
StartDrawing(ScreenOutput())
Locate(10,10):DrawText(Str(framerate))
StopDrawing()
ExamineKeyboard()
FlipBuffers()
oldtime=ElapsedMilliseconds()
Until KeyboardPushed(#pb_key_escape)
Code: Select all
initsprite()
initpalette()
initkeyboard()
openscreen(640,480,8,"")
createsprite(0,640,480)
startdrawing(spriteoutput(0))
for x=0 to 639
for y=0 to 479
plot(x,y,random(255))
next y
next x
stopdrawing()
createpalette(1)
createpalette(0)
displaypalette(0)
Displaysprite(0,0,0):flipbuffers():Displaysprite(0,0,0)
repeat
palette=(palette+1)&1
usepalette(palette)
flow=(flow+1)&255
for n=0 to 255
setpalettecolor(n,(flow+n)&255)
next n
displaypalette(palette)
time=time+(ElapsedMilliseconds()-oldtime)
frame=frame+1
If time=>1000
framerate=frame:frame=0:time=0
EndIf
StartDrawing(ScreenOutput())
Locate(10,10):DrawText(Str(framerate))
StopDrawing()
examinekeyboard()
flipbuffers()
oldtime=ElapsedMilliseconds()
until keyboardpushed(#pb_key_escape)
LockPalette(#Palette)
...do all changes
UnlockPalette()
It would be very useful.
