Stardew Engine
Loading...
Searching...
No Matches
Atlas.c File Reference
#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 dependency graph for Atlas.c:

Data Structures

struct  AtlasSpriteFontData
 
struct  AtlasFont
 
struct  Atlas
 
struct  AtlasRect
 
struct  FreeSpaceRun
 

Macros

#define STB_IMAGE_WRITE_IMPLEMENTATION
 
#define ATLAS_SPRITE_BORDER_PXLS   1
 
#define MERGE_FREE_SPACES
 
#define ATLAS_HANDLE_BOUNDS_CHECK_NO_RETURN(atlas)
 
#define ATLAS_HANDLE_BOUNDS_CHECK(atlas, rVal)
 
#define FONT_HANDLE_BOUNDS_CHECK(hAtlas, hFont, rVal)
 

Functions

AtlasAqcuireAtlas ()
 
void At_SetCurrent (hAtlas atlas, DrawContext *pDC)
 
void At_Init ()
 
void At_BeginAtlas ()
 
hSprite At_AddSprite (const char *imgPath, int topLeftXPx, int topLeftYPx, int widthPx, int heightPx, const char *name)
 
float At_PixelsToPts (float val)
 
HFont At_AddFont (const struct FontAtlasAdditionSpec *pFontSpec)
 
int SortFunc (const void *a, const void *b)
 
 VECTOR (struct AtlasRect)
 
bool FitsInRect (const AtlasSprite *sprite, const struct AtlasRect *rect)
 
int FindFittingFreeSpace (const AtlasSprite *sprite, VECTOR(struct AtlasRect) freeSpace)
 
struct FreeSpaceRunFindRunInPrevRow (VECTOR(struct FreeSpaceRun) prevRow, struct FreeSpaceRun *pRun)
 
struct AtlasRectMergeFreeSpace (struct AtlasRect *pFreeSpace, struct Bitfield2D *pBF, int w, int h)
 
int FreeSpaceSortFunc (const void *a, const void *b)
 
void BlitAtlasSprite (u8 *dst, size_t dstWidthPx, AtlasSprite *pSprite)
 
void CopyNestedPositions (Atlas *pAtlasDest, AtlasSprite *spritesCopySrc, int spritesCopySrcSize)
 
size_t CountTotalSpritesInFonts (Atlas *pAtlas)
 
hAtlas At_EndAtlas (struct DrawContext *pDC)
 
hAtlas At_EndAtlasEx (struct DrawContext *pDC, struct EndAtlasOptions *pOptions)
 
void At_DestroyAtlas (hAtlas atlas, struct DrawContext *pDC)
 
hSprite At_FindSprite (const char *name, hAtlas atlas)
 
AtlasSpriteAt_GetSprite (hSprite sprite, hAtlas atlas)
 
hTexture At_GetAtlasTexture (hAtlas atlas)
 
hAtlas At_LoadAtlas (xmlNode *child0, DrawContext *pDC)
 
hAtlas At_LoadAtlasEx (xmlNode *child0, DrawContext *pDC, struct EndAtlasOptions *pOptions)
 
hSprite At_TilemapIndexToSprite (hAtlas atlas, TileIndex tileIndex)
 
void At_SerializeAtlas (struct BinarySerializer *pSerializer, hAtlas *atlas, struct DrawContext *pDC)
 
HFont Fo_FindFont (hAtlas hAtlas, const char *fontName, float sizePts)
 
float Fo_CharWidth (hAtlas hAtlas, HFont hFont, char c)
 
float Fo_CharHeight (hAtlas hAtlas, HFont hFont, char c)
 
float Fo_StringWidth (hAtlas hAtlas, HFont hFont, const char *stringVal)
 
float Fo_StringHeight (hAtlas hAtlas, HFont hFont, const char *stringVal)
 
AtlasSpriteFo_GetCharSprite (hAtlas hAtlas, HFont hFont, char c)
 
float Fo_GetMaxYBearing (hAtlas hAtlas, HFont hFont, const char *str)
 
bool Fo_TryGetCharBearing (hAtlas hAtlas, HFont hFont, char c, vec2 outBearing)
 
bool Fo_TryGetCharAdvance (hAtlas hAtlas, HFont hFont, char c, float *outAdvance)
 
void At_BeginTileset (int beginI)
 
void At_EndTileset (int endI)
 
struct AtlasAnimationAt_FindAnim (hAtlas atlas, const char *name)
 

Variables

FT_Library gFTLib
 

Macro Definition Documentation

◆ ATLAS_HANDLE_BOUNDS_CHECK

#define ATLAS_HANDLE_BOUNDS_CHECK (   atlas,
  rVal 
)
Value:
{\
bool bAtlasHandleBoundsValid = atlas < VectorSize(gAtlases) && atlas >= 0;\
if(!bAtlasHandleBoundsValid){\
Log_Error("function '%s' invalid bounds handle %i", __FUNCTION__, atlas);\
return rVal;\
}\
}
#define VectorSize(vector)
Definition DynArray.h:30

◆ ATLAS_HANDLE_BOUNDS_CHECK_NO_RETURN

#define ATLAS_HANDLE_BOUNDS_CHECK_NO_RETURN (   atlas)
Value:
{\
bool bAtlasHandleBoundsValid = atlas < VectorSize(gAtlases) && atlas >= 0;\
if(!bAtlasHandleBoundsValid){\
Log_Error("function '%s' invalid bounds handle %i", __FUNCTION__, atlas);\
return;\
}\
}\

◆ ATLAS_SPRITE_BORDER_PXLS

#define ATLAS_SPRITE_BORDER_PXLS   1

◆ FONT_HANDLE_BOUNDS_CHECK

#define FONT_HANDLE_BOUNDS_CHECK (   hAtlas,
  hFont,
  rVal 
)
Value:
{\
Atlas* pAtlas = &gAtlases[hAtlas];\
bool bAtlasHandleBoundsValid = hFont < VectorSize(pAtlas->fonts) && hFont >= 0;\
if(!bAtlasHandleBoundsValid){\
Log_Error("function '%s' invalid bounds font handle %i", __FUNCTION__, hFont);\
return rVal;\
}\
}
HGeneric hAtlas
Definition HandleDefs.h:14
Definition Atlas.c:44

◆ MERGE_FREE_SPACES

#define MERGE_FREE_SPACES

◆ STB_IMAGE_WRITE_IMPLEMENTATION

#define STB_IMAGE_WRITE_IMPLEMENTATION

Function Documentation

◆ AqcuireAtlas()

Atlas * AqcuireAtlas ( )

◆ At_AddFont()

HFont At_AddFont ( const struct FontAtlasAdditionSpec pFontSpec)

◆ At_AddSprite()

hSprite At_AddSprite ( const char *  imgPath,
int  topLeftXPx,
int  topLeftYPx,
int  widthPx,
int  heightPx,
const char *  name 
)

◆ At_BeginAtlas()

void At_BeginAtlas ( )

◆ At_BeginTileset()

void At_BeginTileset ( int  beginI)

◆ At_DestroyAtlas()

void At_DestroyAtlas ( hAtlas  atlas,
struct DrawContext pDC 
)

◆ At_EndAtlas()

hAtlas At_EndAtlas ( struct DrawContext pDC)

◆ At_EndAtlasEx()

hAtlas At_EndAtlasEx ( struct DrawContext pDC,
struct EndAtlasOptions pOptions 
)

◆ At_EndTileset()

void At_EndTileset ( int  endI)

◆ At_FindAnim()

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

◆ At_FindSprite()

hSprite At_FindSprite ( const char *  name,
hAtlas  atlas 
)

◆ At_GetAtlasTexture()

hTexture At_GetAtlasTexture ( hAtlas  atlas)

◆ At_GetSprite()

AtlasSprite * At_GetSprite ( hSprite  sprite,
hAtlas  atlas 
)

◆ At_Init()

void At_Init ( )

◆ At_LoadAtlas()

hAtlas At_LoadAtlas ( xmlNode child0,
DrawContext pDC 
)

◆ At_LoadAtlasEx()

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

◆ At_PixelsToPts()

float At_PixelsToPts ( float  val)

◆ At_SerializeAtlas()

void At_SerializeAtlas ( struct BinarySerializer pSerializer,
hAtlas atlas,
struct DrawContext pDC 
)
Parameters
pSerializerbinary serialzier to load or save
atlasIf 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

◆ At_SetCurrent()

void At_SetCurrent ( hAtlas  atlas,
DrawContext pDC 
)

◆ At_TilemapIndexToSprite()

hSprite At_TilemapIndexToSprite ( hAtlas  atlas,
TileIndex  tileIndex 
)

◆ BlitAtlasSprite()

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

◆ CopyNestedPositions()

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

◆ CountTotalSpritesInFonts()

size_t CountTotalSpritesInFonts ( Atlas pAtlas)

◆ FindFittingFreeSpace()

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

◆ FindRunInPrevRow()

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

◆ FitsInRect()

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

◆ Fo_CharHeight()

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

◆ Fo_CharWidth()

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

◆ Fo_FindFont()

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

◆ Fo_GetCharSprite()

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

◆ Fo_GetMaxYBearing()

float Fo_GetMaxYBearing ( hAtlas  hAtlas,
HFont  hFont,
const char *  str 
)

◆ Fo_StringHeight()

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

◆ Fo_StringWidth()

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

◆ Fo_TryGetCharAdvance()

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

◆ Fo_TryGetCharBearing()

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

◆ FreeSpaceSortFunc()

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

◆ MergeFreeSpace()

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

◆ SortFunc()

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

◆ VECTOR()

static VECTOR ( struct AtlasRect  )

Variable Documentation

◆ gFTLib

FT_Library gFTLib