Cavestory Mod API
Classes
ImageBank.h File Reference
#include <CSMAPI_begincode.h>
#include <CSMAPI_endcode.h>

Go to the source code of this file.

Classes

struct  CSM_BANK_TILE
 Stores information about a specific tile. More...
 
struct  CSM_BANK_IMAGE
 Stores data about a banked image. More...
 
struct  CSM_BANK_RECT
 A more useful RECT struct. More...
 
struct  CSM_BANK_COLLISION_INFO
 A structure to hold all collision information. More...
 
CAVESTORY_MOD_API CSM_BANK_IMAGEsz_pFirstImageBank
 
CAVESTORY_MOD_API int CSM_ImageBank_Load (int iBankNo, int iEntryNo, CSM_BANK_IMAGE **pOut=NULL, const char *pInternalName=NULL, int iTileSizeW=16, int iTileSizeH=16, BOOL(*pSolidFunc)(Surface_Ids surf_id, int x, int y)=NULL, bool *bAlreadyExists=NULL)
 Load a banked image. More...
 
CAVESTORY_MOD_API Surface_Ids CSM_ImageBank_LoadAndGetSurfaceId (int iBankNo, int iEntryNo, CSM_BANK_IMAGE **pOut=NULL, const char *pInternalName=NULL, int iTileSizeW=16, int iTileSizeH=16, BOOL(*pSolidFunc)(Surface_Ids surf_id, int x, int y)=NULL)
 Load a banked image. More...
 
CAVESTORY_MOD_API void CSM_ImageBank_Free (CSM_BANK_IMAGE *pBank)
 Free a loaded bank image. More...
 
CAVESTORY_MOD_API void CSM_ImageBank_FreeAll ()
 Free all bank images.
 
CAVESTORY_MOD_API BOOL CSM_ImageBank_FindBySurfaceId (Surface_Ids iSurfId, CSM_BANK_IMAGE **pOut=NULL)
 Get a bank by its surface ID. More...
 
CAVESTORY_MOD_API void CSM_ImageBank_SetTileSize (CSM_BANK_IMAGE *pBank, int iTileW, int iTileH)
 Check if a pixel is solid. More...
 
CAVESTORY_MOD_API int CSM_ImageBank_GetTileIndex (CSM_BANK_IMAGE *pBank, int iTileX, int iTileY)
 Get the tile index of a bank at the given tile coordinates. More...
 
CAVESTORY_MOD_API int CSM_ImageBank_GetTileIndexByPixel (CSM_BANK_IMAGE *pBank, int iPixelX, int iPixelY)
 Get the tile index of a bank at the given pixel coordinates. More...
 
CAVESTORY_MOD_API BOOL CSM_ImageBank_ScanTile (CSM_BANK_IMAGE *pBank, int iTileIndex, bool bForce=false)
 Scan a tile for solid pixels. More...
 
CAVESTORY_MOD_API BOOL CSM_ImageBank_IsPixelSolid (CSM_BANK_IMAGE *pBank, int iTileIndex, int iX, int iY, float fAngle=0.f, int iCenterX=0, int iCenterY=0)
 Check if a pixel is solid. More...
 
CAVESTORY_MOD_API int CSM_ImageBank_GetFloorPosition (CSM_BANK_IMAGE *pBank, int iTileIndex, int iX, int iY, float fAngle=0.f, int iCenterX=0, int iCenterY=0, GUI_POINT debug_bank_sub_pos=GUI_POINT(0, 0))
 Scan down until we hit a solid pixel. More...
 
CAVESTORY_MOD_API int CSM_ImageBank_TestPixelCollision_MYCHAR (CSM_BANK_IMAGE *pBank, MYCHAR *pMC, int iTileIndex, GUI_POINT pBankPos, int(*pCollideFunc)(const CSM_BANK_COLLISION_INFO *pInfo), float fAngle=0.f, int iCenterX=0, int iCenterY=0, char iDebugLevel=0)
 Check if a pixel is overlapping a player character. More...
 
CAVESTORY_MOD_API BOOL CSM_ImageBank_TestPixelCollision_NPCHAR (CSM_BANK_IMAGE *pBank, NPCHAR *pNpc, int iTileIndex, GUI_POINT pBankPos, int(*pCollideFunc)(const CSM_BANK_COLLISION_INFO *pInfo), float fAngle=0.f, int iCenterX=0, int iCenterY=0, char iDebugLevel=0)
 Check if a pixel is overlapping an NPC. More...
 
CAVESTORY_MOD_API BOOL CSM_ImageBank_TestPixelCollision_BANK (CSM_BANK_IMAGE *pBank, CSM_BANK_IMAGE *pOther, int iTileIndex1, int iTileIndex2, GUI_POINT pBankPos1, GUI_POINT pBankPos2, void(*pCollideFunc)(const CSM_BANK_COLLISION_INFO *pInfo), float fAngle=0.f, int iCenterX=0, int iCenterY=0, char iDebugLevel=0)
 Check if a pixel is overlapping an NPC. More...
 

Function Documentation

◆ CSM_ImageBank_FindBySurfaceId()

CAVESTORY_MOD_API BOOL CSM_ImageBank_FindBySurfaceId ( Surface_Ids  iSurfId,
CSM_BANK_IMAGE **  pOut = NULL 
)

Get a bank by its surface ID.

Parameters
iSurfIdThe surface ID to match.
pOutA pointer to hold the result. Can be NULL.
Returns
Returns TRUE if the bank was found, FALSE otherwise.
See also
CSM_ImageBank_Free

◆ CSM_ImageBank_Free()

CAVESTORY_MOD_API void CSM_ImageBank_Free ( CSM_BANK_IMAGE pBank)

Free a loaded bank image.

Parameters
pBankThe bank object.
See also
CSM_ImageBank_Load

◆ CSM_ImageBank_GetFloorPosition()

CAVESTORY_MOD_API int CSM_ImageBank_GetFloorPosition ( CSM_BANK_IMAGE pBank,
int  iTileIndex,
int  iX,
int  iY,
float  fAngle = 0.f,
int  iCenterX = 0,
int  iCenterY = 0,
GUI_POINT  debug_bank_sub_pos = GUI_POINT(0, 0) 
)

Scan down until we hit a solid pixel.

Parameters
pBankThe bank object.
iXThe X position. This is not magnified & not sub-pixel. Must be relative to (0, 0).
iYThe Y position. This is not magnified & not sub-pixel. Must be relative to (0, 0).
fAngleThe angle, in degrees, to rotate this by.
iCenterXThe pivot X position.
iCenterYThe pivot Y position.
Returns
Returns the Y position of the best floor pixel (non-magnified & non-subpixel), -1 if none could be found.

◆ CSM_ImageBank_GetTileIndex()

CAVESTORY_MOD_API int CSM_ImageBank_GetTileIndex ( CSM_BANK_IMAGE pBank,
int  iTileX,
int  iTileY 
)

Get the tile index of a bank at the given tile coordinates.

Parameters
pBankThe bank object.
iTileXThe tile's X position.
iTileYThe tile's Y position.
Returns
Returns the tile's index.

◆ CSM_ImageBank_GetTileIndexByPixel()

CAVESTORY_MOD_API int CSM_ImageBank_GetTileIndexByPixel ( CSM_BANK_IMAGE pBank,
int  iPixelX,
int  iPixelY 
)

Get the tile index of a bank at the given pixel coordinates.

Parameters
pBankThe bank object.
iPixelXThe pixel's X position.
iPixelYThe pixel's Y position.
Returns
Returns the tile's index.

◆ CSM_ImageBank_IsPixelSolid()

CAVESTORY_MOD_API BOOL CSM_ImageBank_IsPixelSolid ( CSM_BANK_IMAGE pBank,
int  iTileIndex,
int  iX,
int  iY,
float  fAngle = 0.f,
int  iCenterX = 0,
int  iCenterY = 0 
)

Check if a pixel is solid.

Parameters
pBankThe bank object.
iXThe X position. This is not magnified & not sub-pixel. Must be relative to (0, 0).
iYThe Y position. This is not magnified & not sub-pixel. Must be relative to (0, 0).
fAngleThe angle, in degrees, to rotate this by.
iCenterXThe pivot X position.
iCenterYThe pivot Y position.
Returns
Returns TRUE if the pixel is solid, FALSE otherwise.

◆ CSM_ImageBank_Load()

CAVESTORY_MOD_API int CSM_ImageBank_Load ( int  iBankNo,
int  iEntryNo,
CSM_BANK_IMAGE **  pOut = NULL,
const char *  pInternalName = NULL,
int  iTileSizeW = 16,
int  iTileSizeH = 16,
BOOL(*)(Surface_Ids surf_id, int x, int y)  pSolidFunc = NULL,
bool *  bAlreadyExists = NULL 
)

Load a banked image.

The file location will be built as '<InternalModName>/<iBankNo>/<iEntryNo>.png'. For example, calling CSM_ImageBank_Load(1, 4, &pOut); will load 'mymod/0001/0004.png'.

Parameters
pInternalNameThe internal name of this bank image. Can be NULL.
iBankNoThe bank number.
iEntryNoThe image entry number.
pOutA pointer to hold the generated bank image object.
iTileSizeWThe initial tile width for this bank.
iTileSizeHThe initial tile height for this bank.
pSolidFuncPointer to a function that will determine if a pixel is solid or not. Can be NULL.
Returns
Returns 0 on success, non-zero on error.
See also
CSM_ImageBank_Free

◆ CSM_ImageBank_LoadAndGetSurfaceId()

CAVESTORY_MOD_API Surface_Ids CSM_ImageBank_LoadAndGetSurfaceId ( int  iBankNo,
int  iEntryNo,
CSM_BANK_IMAGE **  pOut = NULL,
const char *  pInternalName = NULL,
int  iTileSizeW = 16,
int  iTileSizeH = 16,
BOOL(*)(Surface_Ids surf_id, int x, int y)  pSolidFunc = NULL 
)

Load a banked image.

The file location will be built as '<InternalModName>/<iBankNo>/<iEntryNo>.png'. For example, calling CSM_ImageBank_Load(1, 4, &pOut); will load 'mymod/0001/0004.png'.

Parameters
pInternalNameThe internal name of this bank image. Can be NULL.
iBankNoThe bank number.
iEntryNoThe image entry number.
pOutA pointer to hold the generated bank image object.
iTileSizeWThe initial tile width for this bank.
iTileSizeHThe initial tile height for this bank.
pSolidFuncPointer to a function that will determine if a pixel is solid or not. Can be NULL.
Returns
Returns the surface ID on success, SURFACE_ID_MAX on fail.
See also
CSM_ImageBank_Free

◆ CSM_ImageBank_ScanTile()

CAVESTORY_MOD_API BOOL CSM_ImageBank_ScanTile ( CSM_BANK_IMAGE pBank,
int  iTileIndex,
bool  bForce = false 
)

Scan a tile for solid pixels.

Parameters
pBankThe bank object.
iTileIndexThe tile index.
bForceForce this function to rescan the tile if it's already scanned.
Returns
Returns TRUE if the scan was successful / the tile was already scanned, otherwise returns FALSE on fail.

◆ CSM_ImageBank_SetTileSize()

CAVESTORY_MOD_API void CSM_ImageBank_SetTileSize ( CSM_BANK_IMAGE pBank,
int  iTileW,
int  iTileH 
)

Check if a pixel is solid.

Parameters
pBankThe bank object.
iXThe X position.
iYThe Y position.

◆ CSM_ImageBank_TestPixelCollision_BANK()

CAVESTORY_MOD_API BOOL CSM_ImageBank_TestPixelCollision_BANK ( CSM_BANK_IMAGE pBank,
CSM_BANK_IMAGE pOther,
int  iTileIndex1,
int  iTileIndex2,
GUI_POINT  pBankPos1,
GUI_POINT  pBankPos2,
void(*)(const CSM_BANK_COLLISION_INFO *pInfo)  pCollideFunc,
float  fAngle = 0.f,
int  iCenterX = 0,
int  iCenterY = 0,
char  iDebugLevel = 0 
)

Check if a pixel is overlapping an NPC.

Parameters
pBankThe bank object.
pOtherThe bank object being test against.
iTileIndex1The first bank's tile index.
iTileIndex2The second bank's tile index.
pBankPos1The first bank's subpixel position.
pBankPos2The second bank's subpixel position.
pCollideFuncThe function to be called when a collision is found.
fAngleThe angle, in degrees, to rotate this by.
iCenterXThe pivot X position.
iCenterYThe pivot Y position.
iDebugLevelThe debug level.
Returns
Returns TRUE if a collision was caught, FALSE otherwise.

◆ CSM_ImageBank_TestPixelCollision_MYCHAR()

CAVESTORY_MOD_API int CSM_ImageBank_TestPixelCollision_MYCHAR ( CSM_BANK_IMAGE pBank,
MYCHAR pMC,
int  iTileIndex,
GUI_POINT  pBankPos,
int(*)(const CSM_BANK_COLLISION_INFO *pInfo)  pCollideFunc,
float  fAngle = 0.f,
int  iCenterX = 0,
int  iCenterY = 0,
char  iDebugLevel = 0 
)

Check if a pixel is overlapping a player character.

Parameters
pBankThe bank object.
pMCThe player character to test against.
iTileIndexThe tile index.
pBankPosThe bank's subpixel position.
pCollideFuncThe function to be called when a collision is found. The return value for this callback should be the collision flags applied.
fAngleThe angle, in degrees, to rotate this by.
iCenterXThe pivot X position.
iCenterYThe pivot Y position.
iDebugLevelThe debug level.
Returns
Returns the collision flags that were applied during the collision check.

◆ CSM_ImageBank_TestPixelCollision_NPCHAR()

CAVESTORY_MOD_API BOOL CSM_ImageBank_TestPixelCollision_NPCHAR ( CSM_BANK_IMAGE pBank,
NPCHAR pNpc,
int  iTileIndex,
GUI_POINT  pBankPos,
int(*)(const CSM_BANK_COLLISION_INFO *pInfo)  pCollideFunc,
float  fAngle = 0.f,
int  iCenterX = 0,
int  iCenterY = 0,
char  iDebugLevel = 0 
)

Check if a pixel is overlapping an NPC.

Parameters
pBankThe bank object.
pNpcThe NPC object to test against.
iTileIndexThe tile index.
pBankPosThe bank's subpixel position.
pCollideFuncThe function to be called when a collision is found.
fAngleThe angle, in degrees, to rotate this by.
iCenterXThe pivot X position.
iCenterYThe pivot Y position.
iDebugLevelThe debug level.
Returns
Returns TRUE if a collision was caught, FALSE otherwise.