OldSchool Library
Maps

Map functions in OSLib. More...

Data Structures

struct  OSL_MAP
 Structure representing a map. More...
 

Typedefs

typedef enum OSL_MAP_FLAGS OSL_MAP_FLAGS
 Enum representing internal map flags.
 

Enumerations

enum  OSL_MAP_FORMATS { OSL_MF_U16 = 1 , OSL_MF_U16_GBA = 2 }
 Enum representing the available map formats. More...
 
enum  OSL_MAP_FLAGS { OSL_MF_SIMPLE = 1 , OSL_MF_TILE1_TRANSPARENT = 2 }
 Enum representing internal map flags. More...
 

Functions

OSL_MAPoslCreateMap (OSL_IMAGE *img, void *map_data, int tileX, int tileY, int mapSizeX, int mapSizeY, int map_format)
 Creates a new map.
 
void oslDrawMap (OSL_MAP *m)
 Draws a map on the screen.
 
void oslDrawMapSimple (OSL_MAP *m)
 Draws a map using a simple method (deprecated).
 
void oslDeleteMap (OSL_MAP *m)
 Deletes a map.
 

Detailed Description

Map functions in OSLib.

Typedef Documentation

◆ OSL_MAP_FLAGS

Enum representing internal map flags.

These flags are used internally to define certain properties of the map, such as transparency and drawing methods.

Enumeration Type Documentation

◆ OSL_MAP_FORMATS

Enum representing the available map formats.

This enum defines the possible formats a map can have, such as 16-bit formats with different tile numbering schemes.

Enumerator
OSL_MF_U16 

16-bit format.

OSL_MF_U16_GBA 

16-bit, 10 bits for the tile number, 2 bits for mirroring. Palette is unsupported. addit1 holds the number of tile bits (default 10), and the next two bits are for mirroring (11 = horizontal, 12 = vertical).

◆ OSL_MAP_FLAGS

Enum representing internal map flags.

These flags are used internally to define certain properties of the map, such as transparency and drawing methods.

Enumerator
OSL_MF_SIMPLE 

Defines if the map is "simple" (oslDrawMapSimple). Currently unsupported, do not use.

OSL_MF_TILE1_TRANSPARENT 

Defines if the first tile is always transparent, regardless of its pattern.

Function Documentation

◆ oslCreateMap()

OSL_MAP * oslCreateMap ( OSL_IMAGE * img,
void * map_data,
int tileX,
int tileY,
int mapSizeX,
int mapSizeY,
int map_format )
extern

Creates a new map.

This function initializes a new map using the provided tileset image and raw map data. It sets up the map's dimensions and format, returning a pointer to the created OSL_MAP structure.

Parameters
imgPointer to the tileset image. The maximum size of images is 512x512 pixels. In the tileset image, tiles are arranged from left to right and top to bottom.
map_dataPointer to the raw binary map data. This is an array where each entry represents a tile number to be displayed.
tileXWidth of a tile in the tileset (in pixels).
tileYHeight of a tile in the tileset (in pixels).
mapSizeXWidth of the map (in tiles).
mapSizeYHeight of the map (in tiles).
map_formatFormat of the map, one of the OSL_MAP_FORMATS values.
Returns
Pointer to the created OSL_MAP structure, or NULL in case of error.

◆ oslDrawMap()

void oslDrawMap ( OSL_MAP * m)
extern

Draws a map on the screen.

This function renders the map on the screen using the properties defined in the OSL_MAP structure, such as scroll positions and tile sizes.

Parameters
mPointer to the OSL_MAP structure to be drawn.

◆ oslDrawMapSimple()

void oslDrawMapSimple ( OSL_MAP * m)
extern

Draws a map using a simple method (deprecated).

This function is provided for backward compatibility. It draws a map similarly to oslDrawMap, but is not recommended for use in new code.

Parameters
mPointer to the OSL_MAP structure to be drawn.
Deprecated
This function is deprecated and should not be used.

◆ oslDeleteMap()

void oslDeleteMap ( OSL_MAP * m)
extern

Deletes a map.

This function frees the resources associated with a map. Note that the raw map data passed to oslCreateMap is not freed by this function and must be managed separately by the user.

Parameters
mPointer to the OSL_MAP structure to be deleted.

Example:

unsigned short *mapData;
OSL_MAP *map;
// Allocate memory for map data
mapData = malloc(128 * 64 * sizeof(*mapData));
// Create a map with this data
map = oslCreateMap(anImage, mapData, 16, 16, 128, 64, OSL_MF_U16);
// Delete the map
// Free the map data
free(mapData);
void oslDeleteMap(OSL_MAP *m)
Deletes a map.
OSL_MAP * oslCreateMap(OSL_IMAGE *img, void *map_data, int tileX, int tileY, int mapSizeX, int mapSizeY, int map_format)
Creates a new map.
@ OSL_MF_U16
Definition map.h:52
Structure representing a map.
Definition map.h:29