File Atlas.c

FileList > core > Atlas.c

Go to the source code of this file

  • #include "Atlas.h"
  • #include "DynArray.h"
  • #include "ImageFileRegstry.h"
  • #include <string.h>
  • #include <stdlib.h>
  • #include "AssertLib.h"
  • #include <ft2build.h>
  • #include "stb/stb_image_write.h"
  • #include "DrawContext.h"
  • #include "SharedPtr.h"
  • #include "FloatingPointLib.h"
  • #include <libxml/parser.h>
  • #include <libxml/tree.h>
  • #include "BinarySerializer.h"
  • #include "BitField2D.h"
  • #include "StringKeyHashMap.h"
  • #include "Log.h"
  • #include "StardewString.h"
  • #include "cwalk.h"
  • #include "main.h"

Classes

Type Name
struct Atlas
struct AtlasFont
struct AtlasRect
struct AtlasSpriteFontData
struct FreeSpaceRun

Public Attributes

Type Name
FT_Library gFTLib

Public Static Attributes

Type Name
int gSpriteId = 1

Public Functions

Type Name
Atlas * AqcuireAtlas ()
HFont At_AddFont (const struct FontAtlasAdditionSpec * pFontSpec)
hSprite At_AddSprite (const char * imgPath, int topLeftXPx, int topRightYPx, int widthPx, int heightPx, const char * name, bool bMinimizeSpace)
Add a sprite to the atlas, cuts out the pixels for that specific sprite to be nested when At_EndAtlas is called.
void At_BeginAtlas ()
void At_BeginTileset (int beginI)
void At_DestroyAtlas (hAtlas atlas, struct DrawContext * pDC)
hAtlas At_EndAtlas (struct DrawContext * pDC)
hAtlas At_EndAtlasEx (struct DrawContext * pDC, struct EndAtlasOptions * pOptions)
void At_EndTileset (int endI)
struct AtlasAnimation * At_FindAnim (hAtlas atlas, const char * name)
hSprite At_FindSprite (const char * name, hAtlas atlas)
hTexture At_GetAtlasTexture (hAtlas atlas)
AtlasSprite * At_GetSprite (hSprite sprite, hAtlas atlas)
void At_Init ()
hAtlas At_LoadAtlas (xmlNode * child0, DrawContext * pDC)
hAtlas At_LoadAtlasEx (xmlNode * child0, DrawContext * pDC, struct EndAtlasOptions * pOptions)
TileIndex At_LookupNamedTile (hAtlas atlas, const char * name)
Look up the atlas's tileset index for a given name - this is different from sprite handle, it's the index you need to write to the tile layer array, convertable to a sprite with At_TilemapIndexToSprite.
float At_PixelsToPts (float val)
void At_SerializeAtlas (struct BinarySerializer * pSerializer, hAtlas * atlas, struct DrawContext * pDC)
void At_SetCurrent (hAtlas atlas, DrawContext * pDC)
hSprite At_TilemapIndexToSprite (hAtlas atlas, TileIndex tileIndex)
void BlitAtlasSprite (u8 * dst, size_t dstWidthPx, AtlasSprite * pSprite)
void CopyNestedPositions (Atlas * pAtlasDest, AtlasSprite * spritesCopySrc, int spritesCopySrcSize)
size_t CountTotalSpritesInFonts (Atlas * pAtlas)
int FindFittingFreeSpace (const AtlasSprite * sprite, VECTOR(struct AtlasRect) freeSpace)
struct FreeSpaceRun * FindRunInPrevRow (VECTOR(struct FreeSpaceRun) prevRow, struct FreeSpaceRun * pRun)
bool FitsInRect (const AtlasSprite * sprite, const struct AtlasRect * rect)
float Fo_CharHeight (hAtlas hAtlas, HFont hFont, char c)
float Fo_CharWidth (hAtlas hAtlas, HFont hFont, char c)
HFont Fo_FindFont (hAtlas hAtlas, const char * fontName, float sizePts)
AtlasSprite * Fo_GetCharSprite (hAtlas hAtlas, HFont hFont, char c)
float Fo_GetMaxYBearing (hAtlas hAtlas, HFont hFont, const char * str)
get the maximum y bearing value for a string:
float Fo_GetMinYBearing (hAtlas hAtlas, HFont hFont, const char * str)
get the minimum y bearing value for a string:
float Fo_StringHeight (hAtlas hAtlas, HFont hFont, const char * stringVal)
float Fo_StringHeightSingleLine (hAtlas hAtlas, HFont hFont, const char * stringVal)
float Fo_StringWidth (hAtlas hAtlas, HFont hFont, const char * stringVal)
bool Fo_TryGetCharAdvance (hAtlas hAtlas, HFont hFont, char c, float * outAdvance)
bool Fo_TryGetCharBearing (hAtlas hAtlas, HFont hFont, char c, vec2 outBearing)
int FreeSpaceSortFunc (const void * a, const void * b)
struct AtlasRect * MergeFreeSpace (struct AtlasRect * pFreeSpace, struct Bitfield2D * pBF, int w, int h)
int SortFunc (const void * a, const void * b)
VECTOR (struct AtlasRect)

Public Static Functions

Type Name
int Bottom (const struct AtlasRect * pRect)
void CalculateAtlasUVs (Atlas * pAtlas)
void CalculateSpriteUVs (AtlasSprite * pSprt, int atlasW, int atlasH)
size_t CountAvailableChars (struct AtlasFont * pFont)
void DeserializeAnimationsV1 (Atlas * pAtlas, struct BinarySerializer * pSerializer)
void DeserializeAtlasFontV1 (struct AtlasFont * pFont, struct BinarySerializer * pSerializer)
void DeserializeAtlasSpriteV1 (AtlasSprite * pSprite, struct BinarySerializer * pSerializer)
hAtlas DeserializeAtlasV1 (struct BinarySerializer * pSerializer, struct DrawContext * pDC)
void * FTBitmapToNestableBitmap (FT_Bitmap * pBmp)
void FaceDtor (void * pVal)
void FindMinimalSpriteBox (int inTLXPx, int inTLYPx, int inWPx, int inHPx, const struct ImageFile * pImgIn, int * pOutTLXPx, int * pOutTLYPx, int * pOutWPx, int * pOutHPx)
struct EndAtlasOptions * GetDefaultAtlasOptions ()
bool IsCharLoaded (struct AtlasFont * pFont, char c)
int Left (const struct AtlasRect * pRect)
void LoadAnimationFrames (xmlNode * child0, int * pOnChild)
void LoadAtlasFont (xmlNode * pChild)
hSprite LoadAtlasSprite (xmlNode * pChild, int onChild)
void LoadNamedTiles (xmlNode * child0, int * pOnChild)
void NestSprites (int * outW, int * outH, AtlasSprite * sortedSpritesTallestToShortest, int numSprites, struct EndAtlasOptions * pOptions)
int Right (const struct AtlasRect * pRect)
void SerializeAnimations (Atlas * pAtlas, struct BinarySerializer * pSerializer)
void SerializeAtlasFont (const struct AtlasFont * pFont, struct BinarySerializer * pSerializer)
void SerializeAtlasSprite (const AtlasSprite * pSprite, struct BinarySerializer * pSerializer)
int Top (const struct AtlasRect * pRect)
static VECTOR (Atlas)
void WriteFontSprites (Atlas * pAtlas, AtlasSprite * outFontSprites)

Macros

Type Name
define ATLAS_HANDLE_BOUNDS_CHECK (atlas, rVal) /* multi line expression */
define ATLAS_HANDLE_BOUNDS_CHECK_NO_RETURN (atlas) /* multi line expression */
define ATLAS_SPRITE_BORDER_PXLS 1
define FONT_HANDLE_BOUNDS_CHECK (hAtlas, hFont, rVal) /* multi line expression */
define MERGE_FREE_SPACES
define STB_IMAGE_WRITE_IMPLEMENTATION

Public Attributes Documentation

variable gFTLib

FT_Library gFTLib;

Public Static Attributes Documentation

variable gSpriteId

int gSpriteId;

Public Functions Documentation

function AqcuireAtlas

Atlas * AqcuireAtlas () 

function At_AddFont

HFont At_AddFont (
    const struct FontAtlasAdditionSpec * pFontSpec
) 

function At_AddSprite

Add a sprite to the atlas, cuts out the pixels for that specific sprite to be nested when At_EndAtlas is called.

hSprite At_AddSprite (
    const char * imgPath,
    int topLeftXPx,
    int topRightYPx,
    int widthPx,
    int heightPx,
    const char * name,
    bool bMinimizeSpace
) 

Parameters:

  • imgPath path to img file
  • topLeftXPx sprite TL coords
  • topRightYPx sprite TR coords
  • widthPx "notional" width
  • heightPx "notional" height
  • name sprite name, for referencing when it's in the atlas
  • bMinimizeSpace find minimum rect to store the sprite, if false action dims == "notional" dims

Returns:


function At_BeginAtlas

void At_BeginAtlas () 

function At_BeginTileset

void At_BeginTileset (
    int beginI
) 

function At_DestroyAtlas

void At_DestroyAtlas (
    hAtlas atlas,
    struct DrawContext * pDC
) 

function At_EndAtlas

hAtlas At_EndAtlas (
    struct DrawContext * pDC
) 

function At_EndAtlasEx

hAtlas At_EndAtlasEx (
    struct DrawContext * pDC,
    struct EndAtlasOptions * pOptions
) 

function At_EndTileset

void At_EndTileset (
    int endI
) 

function At_FindAnim

struct AtlasAnimation * At_FindAnim (
    hAtlas atlas,
    const char * name
) 

function At_FindSprite

hSprite At_FindSprite (
    const char * name,
    hAtlas atlas
) 

function At_GetAtlasTexture

hTexture At_GetAtlasTexture (
    hAtlas atlas
) 

function At_GetSprite

AtlasSprite * At_GetSprite (
    hSprite sprite,
    hAtlas atlas
) 

function At_Init

void At_Init () 

function At_LoadAtlas

hAtlas At_LoadAtlas (
    xmlNode * child0,
    DrawContext * pDC
) 

function At_LoadAtlasEx

hAtlas At_LoadAtlasEx (
    xmlNode * child0,
    DrawContext * pDC,
    struct EndAtlasOptions * pOptions
) 

function At_LookupNamedTile

Look up the atlas's tileset index for a given name - this is different from sprite handle, it's the index you need to write to the tile layer array, convertable to a sprite with At_TilemapIndexToSprite.

TileIndex At_LookupNamedTile (
    hAtlas atlas,
    const char * name
) 

Parameters:

  • name

Returns:


function At_PixelsToPts

float At_PixelsToPts (
    float val
) 

function At_SerializeAtlas

void At_SerializeAtlas (
    struct BinarySerializer * pSerializer,
    hAtlas * atlas,
    struct DrawContext * pDC
) 

Parameters:

  • pSerializer binary serialzier to load or save
  • atlas If loading, point to an unititialized handle to output the new handle If saving point to the handle of the atlas you want to save
  • pDC

function At_SetCurrent

void At_SetCurrent (
    hAtlas atlas,
    DrawContext * pDC
) 

function At_TilemapIndexToSprite

hSprite At_TilemapIndexToSprite (
    hAtlas atlas,
    TileIndex tileIndex
) 

function BlitAtlasSprite

void BlitAtlasSprite (
    u8 * dst,
    size_t dstWidthPx,
    AtlasSprite * pSprite
) 

function CopyNestedPositions

void CopyNestedPositions (
    Atlas * pAtlasDest,
    AtlasSprite * spritesCopySrc,
    int spritesCopySrcSize
) 

function CountTotalSpritesInFonts

size_t CountTotalSpritesInFonts (
    Atlas * pAtlas
) 

function FindFittingFreeSpace

int FindFittingFreeSpace (
    const AtlasSprite * sprite,
    VECTOR(struct AtlasRect ) freeSpace
) 

function FindRunInPrevRow

struct FreeSpaceRun * FindRunInPrevRow (
    VECTOR(struct FreeSpaceRun ) prevRow,
    struct FreeSpaceRun * pRun
) 

function FitsInRect

bool FitsInRect (
    const AtlasSprite * sprite,
    const struct AtlasRect * rect
) 

function Fo_CharHeight

float Fo_CharHeight (
    hAtlas hAtlas,
    HFont hFont,
    char c
) 

function Fo_CharWidth

float Fo_CharWidth (
    hAtlas hAtlas,
    HFont hFont,
    char c
) 

function Fo_FindFont

HFont Fo_FindFont (
    hAtlas hAtlas,
    const char * fontName,
    float sizePts
) 

function Fo_GetCharSprite

AtlasSprite * Fo_GetCharSprite (
    hAtlas hAtlas,
    HFont hFont,
    char c
) 

function Fo_GetMaxYBearing

get the maximum y bearing value for a string:

float Fo_GetMaxYBearing (
    hAtlas hAtlas,
    HFont hFont,
    const char * str
) 
  • bearing is offset from pen position to bounding box edge

Parameters:

  • hAtlas
  • hFont
  • str

Returns:

max Y bearing


function Fo_GetMinYBearing

get the minimum y bearing value for a string:

float Fo_GetMinYBearing (
    hAtlas hAtlas,
    HFont hFont,
    const char * str
) 
  • bearing is offset from pen position to bounding box edge
  • used to position the string by its top left corner

Parameters:

  • hAtlas
  • hFont
  • str

Returns:

min Y bearing


function Fo_StringHeight

float Fo_StringHeight (
    hAtlas hAtlas,
    HFont hFont,
    const char * stringVal
) 

function Fo_StringHeightSingleLine

float Fo_StringHeightSingleLine (
    hAtlas hAtlas,
    HFont hFont,
    const char * stringVal
) 

function Fo_StringWidth

float Fo_StringWidth (
    hAtlas hAtlas,
    HFont hFont,
    const char * stringVal
) 

function Fo_TryGetCharAdvance

bool Fo_TryGetCharAdvance (
    hAtlas hAtlas,
    HFont hFont,
    char c,
    float * outAdvance
) 

function Fo_TryGetCharBearing

bool Fo_TryGetCharBearing (
    hAtlas hAtlas,
    HFont hFont,
    char c,
    vec2 outBearing
) 

function FreeSpaceSortFunc

int FreeSpaceSortFunc (
    const void * a,
    const void * b
) 

function MergeFreeSpace

struct AtlasRect * MergeFreeSpace (
    struct AtlasRect * pFreeSpace,
    struct Bitfield2D * pBF,
    int w,
    int h
) 

function SortFunc

int SortFunc (
    const void * a,
    const void * b
) 

function VECTOR

VECTOR (
    struct AtlasRect
) 

Public Static Functions Documentation

function Bottom

static int Bottom (
    const struct AtlasRect * pRect
) 

function CalculateAtlasUVs

static void CalculateAtlasUVs (
    Atlas * pAtlas
) 

function CalculateSpriteUVs

static void CalculateSpriteUVs (
    AtlasSprite * pSprt,
    int atlasW,
    int atlasH
) 

function CountAvailableChars

static size_t CountAvailableChars (
    struct AtlasFont * pFont
) 

function DeserializeAnimationsV1

static void DeserializeAnimationsV1 (
    Atlas * pAtlas,
    struct BinarySerializer * pSerializer
) 

function DeserializeAtlasFontV1

static void DeserializeAtlasFontV1 (
    struct AtlasFont * pFont,
    struct BinarySerializer * pSerializer
) 

function DeserializeAtlasSpriteV1

static void DeserializeAtlasSpriteV1 (
    AtlasSprite * pSprite,
    struct BinarySerializer * pSerializer
) 

function DeserializeAtlasV1

static hAtlas DeserializeAtlasV1 (
    struct BinarySerializer * pSerializer,
    struct DrawContext * pDC
) 

function FTBitmapToNestableBitmap

static void * FTBitmapToNestableBitmap (
    FT_Bitmap * pBmp
) 

function FaceDtor

static void FaceDtor (
    void * pVal
) 

function FindMinimalSpriteBox

static void FindMinimalSpriteBox (
    int inTLXPx,
    int inTLYPx,
    int inWPx,
    int inHPx,
    const struct ImageFile * pImgIn,
    int * pOutTLXPx,
    int * pOutTLYPx,
    int * pOutWPx,
    int * pOutHPx
) 

function GetDefaultAtlasOptions

static struct EndAtlasOptions * GetDefaultAtlasOptions () 

function IsCharLoaded

static bool IsCharLoaded (
    struct AtlasFont * pFont,
    char c
) 

function Left

static int Left (
    const struct AtlasRect * pRect
) 

function LoadAnimationFrames

static void LoadAnimationFrames (
    xmlNode * child0,
    int * pOnChild
) 

function LoadAtlasFont

static void LoadAtlasFont (
    xmlNode * pChild
) 

function LoadAtlasSprite

static hSprite LoadAtlasSprite (
    xmlNode * pChild,
    int onChild
) 

function LoadNamedTiles

static void LoadNamedTiles (
    xmlNode * child0,
    int * pOnChild
) 

function NestSprites

static void NestSprites (
    int * outW,
    int * outH,
    AtlasSprite * sortedSpritesTallestToShortest,
    int numSprites,
    struct EndAtlasOptions * pOptions
) 

function Right

static int Right (
    const struct AtlasRect * pRect
) 

function SerializeAnimations

static void SerializeAnimations (
    Atlas * pAtlas,
    struct BinarySerializer * pSerializer
) 

function SerializeAtlasFont

static void SerializeAtlasFont (
    const struct AtlasFont * pFont,
    struct BinarySerializer * pSerializer
) 

function SerializeAtlasSprite

static void SerializeAtlasSprite (
    const AtlasSprite * pSprite,
    struct BinarySerializer * pSerializer
) 

function Top

static int Top (
    const struct AtlasRect * pRect
) 

function VECTOR

static static VECTOR (
    Atlas
) 

function WriteFontSprites

static void WriteFontSprites (
    Atlas * pAtlas,
    AtlasSprite * outFontSprites
) 

Macro Definition Documentation

define ATLAS_HANDLE_BOUNDS_CHECK

#define ATLAS_HANDLE_BOUNDS_CHECK (
    atlas,
    rVal
) `/* multi line expression */`

define ATLAS_HANDLE_BOUNDS_CHECK_NO_RETURN

#define ATLAS_HANDLE_BOUNDS_CHECK_NO_RETURN (
    atlas
) `/* multi line expression */`

define ATLAS_SPRITE_BORDER_PXLS

#define ATLAS_SPRITE_BORDER_PXLS `1`

define FONT_HANDLE_BOUNDS_CHECK

#define FONT_HANDLE_BOUNDS_CHECK (
    hAtlas,
    hFont,
    rVal
) `/* multi line expression */`

define MERGE_FREE_SPACES

#define MERGE_FREE_SPACES 

define STB_IMAGE_WRITE_IMPLEMENTATION

#define STB_IMAGE_WRITE_IMPLEMENTATION 


The documentation for this class was generated from the following file /home/runner/work/2DFarmingRPG/2DFarmingRPG/Stardew/engine/src/core/Atlas.c