3.8 Increasing execution speed

To increase the raw execution speed of your script, you can disable Hollywood's line hook using the DisableLineHook() and EnableLineHook() commands. This will improve your script's execution speed significantly in case lots of Hollywood code needs to be run to draw the next frame. Keep in mind, though, that you have to enable the line hook for every frame you draw or your window will become unresponsive. Here's what a speed-optimized implemention of the main loop could look like:

 
@REQUIRE "rebelsdl"

BeginDoubleBuffer(True)  ; set up a hardware double buffer

Repeat
    DisableLineHook() ; disable line hook while drawing the next frame
    p_DrawFrame()     ; draw the next frame here
    EnableLineHook()  ; enable line hook again
    Flip()            ; wait for vertical refresh, then flip buffers
    CheckEvent()      ; run event callbacks
Forever

Note that you'll only notice a speed difference here if p_DrawFrame() executes many lines of Hollywood code. If p_DrawFrame() only consists of 20 lines of code, you won't notice any difference. It's only noticeable with hundreds of code lines or long loops.

See the documentation of DisableLineHook() and EnableLineHook() in the Hollywood manual for more information.


Show TOC