Synchronization

Macros

#define oslSetFrameskip(val)   (osl_frameskip = val)
 
#define oslSetMaxFrameskip(val)   (osl_maxFrameskip = val)
 
#define oslSetVSync(val)   (osl_vsyncEnabled = val)
 
#define oslSyncFrame()   oslSyncFrameEx(osl_frameskip,osl_maxFrameskip,osl_vsyncEnabled)
 

Functions

void oslEndFrame ()
 
int oslSyncFrameEx (int frameskip, int max_frameskip, int vsync)
 
void oslSetFramerate (int framerate)
 
void oslWaitVSync ()
 

Variables

int osl_quit
 

Detailed Description

Contains routines for synchronizing your game.

Macro Definition Documentation

#define oslSetFrameskip (   val)    (osl_frameskip = val)

Sets the current fix frameskipping value.

Parameters
val1 = enables auto frameskip 2 or more: enables fixed skipping (val-1 frames out of val are skipped)
#define oslSetMaxFrameskip (   val)    (osl_maxFrameskip = val)

Sets the maximum frameskip value. If you set a too high value, the game may become unusable when lagging, if you set a too low value, frameskip is no more useful.

#define oslSetVSync (   val)    (osl_vsyncEnabled = val)

Sets the VSync parameter.

Parameters
val0: Automatic VSync (enabled if the game is not lagging). 1: VSync always enabled. +4: If you add 4, with a frameskip > 1, synchronizes to the wanted framerate, e.g. 2 -> 30 fps (DON'T USE THIS ANYMORE) +0: Else, fixes the minimum frameskip (e.g. 2: the game will run at 60 fps, 30 images per second, that is one frame out of two is skipped) +8: Alternative synchronization method without VSync +16: Do not swap buffers. Handy if you want temporary to "disable double buffering".
#define oslSyncFrame ( )    oslSyncFrameEx(osl_frameskip,osl_maxFrameskip,osl_vsyncEnabled)

Synchronization. Call it to the end of a frame. A frame is one step when animating your game. The PSP LCD refreshes at 60 images per second (and thus, you'll have to generate 60 frames per second). This function uses the frameskip & vsync parameters defined above.

Returns
A boolean value indicating if you're in late.

Note: When you're indicated to be in late, you should skip the rendering to speed up things, else your game will slow down. Usually the whole render is surrounded by a "if (!skip)" block, and when skip is true, the render is completely skipped. Skip is the return value from oslSyncFrame.

Here is the structure of an automatically frameskipped program:

//This variable holds whether a frame should be skipped or not
int skip = 0;
//Enable frameskipping, 0 frame out of 1 is skipped by default (60 fps)
//But skip a maximum of 3 frames out of 4, else the game seems very laggy
//Our main loop
while(1) {
//If skip is 1, then we should skip rendering to speed up things
if (!skip) {
//Begin drawing
//We can now draw as much as we want
oslDrawFillRect(0, 0, 100, 100, RGBA(0, 0, 255, 128));
oslDrawString(0, 0, "Hello!");
//We have now finished with drawing
}
//End of a frame
//Synchronize to ensure the game runs at 60 fps
skip = oslSyncFrame();
}

Function Documentation

void oslEndFrame ( )

Call this function when a frame has ended, just before a call to oslSyncFrame or oslWaitVSync or anything. Important: If you are calling this function, you do not need to call oslAudioVSync anymore. Newer programs should always call oslEndFrame instead.

int oslSyncFrameEx ( int  frameskip,
int  max_frameskip,
int  vsync 
)

Same as oslSyncFrame but with all parameters set in one call. This method is a bit cleaner because the other one stores parameters in global variables and oslSyncFrame calls oslSyncFrameEx with them as arguments.

void oslSetFramerate ( int  framerate)
inline

Sets the framerate for oslSyncFrame(Ex). This can be any value from 1 to 60. For example, use 50 to simulate a PAL (european) game.

void oslWaitVSync ( )

Waits for the VSync (60 times per second), synchronizing your game. This is a simplier and less efficient method than oslSyncFrame.

Variable Documentation

int osl_quit

This variable is set to TRUE to indicate the application should exit (happens when the user pressed HOME and selected Yes). You should always keep an eye on this variable, clean up everything and then quit when this variable has become TRUE.