3 JoeyLib Utility Functions
Scott Duensing edited this page 2019-10-17 19:26:29 -05:00

jlUtilByteSwap

juint16 jlUtilByteSwap(juint16 twoBytes);

Swaps the two bytes stored in twoBytes and returns them.

jlUtilDie

void jlUtilDie(const char *why);

Immediately and rudely terminates the application without attempting to shut anything down. If JOEY_DEBUG is defined, why will be recorded along with various memory statistics in a file named JLSTATS. This function does not return.

jlUtilIdle

void jlUtilIdle(void);

Some of the platforms supported by JoeyLib have "message queues" that need "pumped" for the operating system to process events. You MUST call jlUtilIdle occasionally any time your code is in a loop and you do not perform any keyboard reading. (The keyboard routines pump the queue for you.)

jlUtilIsOdd

bool jlUtilIsOdd(int x);

Fast even/odd macro. If x is odd, it returns true. If x is even, it returns false.

jlUtilMakePathname

char *jlUtilMakePathname(char *filename, char *extension);

Returns a temporary character array that consists of the game data directory name, target specific path specifier, the provided filename, and the extension concatenated into one string. DO NOT free the returned string! If you need to preserve the value returned, strdup it to another string.

jlUtilMustExit

bool jlUtilMustExit(void);

You MUST call jlUtilMustExit in any game loop that prevents your application from exiting. If jlUtilMustExit returns true your application MUST exit safely. This is used on platforms where operating system events may need to terminate your application.

jlUtilNibbleSwap

void jlUtilNibbleSwap(byte *mem, jint16 count, byte old, byte new);

Swaps all occurrences of the nibble old in the block of memory mem to new for count bytes. Useful for swapping colors on display surfaces.

jlUtilRandom

juint16 jlUtilRandom(void);

Returns a random unsigned 16 bit value that is consistent across target platforms.

jlUtilRandomSeedGet

juint32 jlUtilRandomSeedGet(void);

Returns the internal "seed" of the random number generator in its current state. Useful for saving the state of the random number generator.

jlUtilRandomSeedSet

void jlUtilRandomSeedSet(juint32 seed);

Specifies the internal "seed" to use for the next random number.

jlUtilShutdown

void jlUtilShutdown(void);

Cleanly shuts down JoeyLib. You should free any resources you have allocated before shutting down. If JOEY_DEBUG is defined, various memory statistics will be recorded in a file named JLSTATS. This function does not return.

jlUtilSleep

void jlUtilSleep(juint16 tenths);

Pauses program execution for tenths one-tenth seconds.

jlUtilStackPop

void *jlUtilStackPop(jlStackT stack);

Returns a pointer to the data on the top of the stack specified by stack. If the stack is empty, it returns NULL.

jlUtilStackPush

void jlUtilStackPush(jlStackT stack, void *data);

Pushes a pointer to data onto the stack specified by stack. The data is NOT copied. Only the pointer is kept on the stack.

jlUtilStartup

void jlUtilStartup(char *appName);

Starts up JoeyLib and initializes the library. appName is the name of your application and will be displayed in the title bar of the application window on platforms that support running applications in a window.

jlUtilTimer

juint16 jlUtilTimer(void);

Provides a "wall clock" timer that is consistent across platforms. The value returned increments (roughly) every 1/10th of a second. When it reaches JUINT16_MAX, it will roll over to zero.

jlUtilTimeSpan

juint16 jlUtilTimeSpan(juint16 past, juint16 current);

Returns the difference, in tenths of a second, between past and current (which are assumed to be values returned by jlUtilTimer). Handles zero rollover.