Alambik Script Team
Alambik Staff

Registered: Feb 2002
Location:
Posts: 15 |
Somes hints to reduce time used by your machine to play an Alambik script
Often, your script is a loop :
do()
process_player()
process_shots()
process_enemies()
if (%live==0)
break()
endif()
loop()
The solution consist to introduce a time.wait(0.3), in example to give a regulate delay to your loop :
do()
process_player()
process_shots()
process_enemies()
if (%live==0)
break()
endif()
time.wait(0.3)
loop()
But, time wait will be always 0.3 seconds to restart your loop. So, Total time is between 0.3 and 0.3+execution time. To have a constant time, you have to measure your procedure's time and withdraw it to 0.3 :
do()
!begin=time.get()
process_player()
process_shots()
process_enemies()
if (%live==0)
break()
endif()
!end=time.get()
time.wait(0.3-(!end-begin))
loop()
There is a automatic instruction who can make this operation, it's time.wait() without parameters.
It allows to liberate necessary time to not exceed the value in sequence.refresh.set() :
// we choose to put 30 images per second
sequence.refresh.set(30)
do()
process_player()
process_shots()
process_enemies()
if (%live==0)
break()
endif()
// wait about 1/30 second maximun
time.wait()
loop()
There exists too lot of methods to reduce time machine used by Alambik :
"sequence.refresh.set" can define frame rate from object. By default, system define 70 images per second but in major cases this value is too big. It's advised to put a value between 20 and 50 according to need of application.
sequencerefresh.tv
screen.resolution.set (320,240)
@spr=sprite.load ("avo\dinosaur.spr")
sprite.play (@spr)
@track=track.create (TRACK_LOOP|TRACK_PINGPONG)
track.key.set (0)
track.key.position.set (0,CENTER)
track.key.set (4)
track.key.position.set (320-27,CENTER)
track.end ()
@sequence=sequence.play (@track,@spr,TRACK_KEEPALL)
sequence.refresh.set (50)
%data=sequence.refresh.get ()
text.display ("The refresh rate of the sequence is : " + STR (%data),CENTER,10)
text.display ("Press a key to change.",CENTER,350)
keyboard.wait ()
sequence.refresh.set (20)
%data=sequence.refresh.get ()
text.display ("The refresh rate of the sequence is : " + STR (%data),CENTER,10)
text.display (" Press a key to exit. ",CENTER,350)
keyboard.wait ()
script.stop ()
A last method consist to work in mask mode. There is an screen.mask() instruction who can accumulate screen modification and execute it only with screen.mask(off) instruction or screen.display() :
sequence.refresh.set(30)
do()
screen.mask(on)
process_player()
process_shots()
process_enemies()
if (%live==0)
break()
endif()
screen.mask(off)
time.wait()
loop()
OR
sequence.refresh.set(30)
screen.mask(on)
do()
process_player()
process_shots()
process_enemies()
if (%live==0)
break()
endif()
screen.display()
time.wait()
loop()
screen.mask(off)
Report this post to a moderator | IP: Logged
|