Cavestory Mod API
ImageBank.h
Go to the documentation of this file.
1 /*
2  Cavestory Multiplayer API
3  Copyright (C) 2021 Johnny Ledger
4 
5  This software is provided 'as-is', without any express or implied
6  warranty. In no event will the authors be held liable for any damages
7  arising from the use of this software.
8 
9  Permission is granted to anyone to use this software for any purpose,
10  including commercial applications, and to alter it and redistribute it
11  freely, subject to the following restrictions:
12 
13  1. The origin of this software must not be misrepresented; you must not
14  claim that you wrote the original software. If you use this software
15  in a product, an acknowledgment in the product documentation would be
16  appreciated but is not required.
17  2. Altered source versions must be plainly marked as such, and must not be
18  misrepresented as being the original software.
19  3. This notice may not be removed or altered from any source distribution.
20 */
21 
26 #ifndef CAVESTORY_MOD_API_H_
27 #error "Please include CavestoryModAPI.h before including sub-classes."
28 #endif
29 
30 #include <CSMAPI_begincode.h>
31 
32 #pragma once
33 
37 
38 //------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
39 
43 {
46  unsigned int* solid_pixel_list;
47 
50  unsigned char* solid_pixel_map;
51 
54  unsigned short solid_count;
55 
58  bool done;
59 };
60 
64 {
67  unsigned int file_name_crc;
68 
71  int bank_no;
72 
75  int entry_no;
76 
79  char* name;
80 
84 
88 
92 
96 
100 
104 
108 
111  BOOL(*solid_func)(Surface_Ids surf_id, int x, int y);
112 };
113 
117 {
120  int left;
121 
124  int top;
125 
128  int right;
129 
132  int bottom;
133 
136  int width;
137 
140  int height;
141 
144  int center_x;
145 
148  int center_y;
149 };
150 
154 {
158 
161  void* object;
162 
166 
170 
174 
178 
179  // METADATA //
180 
184 
188 
192 
196 
200 
204 };
205 
206 //------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
207 
223  int iBankNo,
224  int iEntryNo,
225  CSM_BANK_IMAGE** pOut = NULL,
226  const char* pInternalName = NULL,
227  int iTileSizeW = 16,
228  int iTileSizeH = 16,
229  BOOL(*pSolidFunc)(Surface_Ids surf_id, int x, int y) = NULL,
230  bool* bAlreadyExists = NULL
231 );
232 
248  int iBankNo,
249  int iEntryNo,
250  CSM_BANK_IMAGE** pOut = NULL,
251  const char* pInternalName = NULL,
252  int iTileSizeW = 16,
253  int iTileSizeH = 16,
254  BOOL(*pSolidFunc)(Surface_Ids surf_id, int x, int y) = NULL
255 );
256 
263  CSM_BANK_IMAGE* pBank
264 );
265 
269 );
270 
279  Surface_Ids iSurfId,
280  CSM_BANK_IMAGE** pOut = NULL
281 );
282 
283 //------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
284 
291  CSM_BANK_IMAGE* pBank,
292  int iTileW,
293  int iTileH
294 );
295 
304  CSM_BANK_IMAGE* pBank,
305  int iTileX,
306  int iTileY
307 );
308 
317  CSM_BANK_IMAGE* pBank,
318  int iPixelX,
319  int iPixelY
320 );
321 
322 //------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
323 
332  CSM_BANK_IMAGE* pBank,
333  int iTileIndex,
334  bool bForce = false
335 );
336 
337 //------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
338 
350  CSM_BANK_IMAGE* pBank,
351  int iTileIndex,
352  int iX,
353  int iY,
354  float fAngle = 0.f,
355  int iCenterX = 0,
356  int iCenterY = 0
357 );
358 
370  CSM_BANK_IMAGE* pBank,
371  int iTileIndex,
372  int iX,
373  int iY,
374  float fAngle = 0.f,
375  int iCenterX = 0,
376  int iCenterY = 0,
377  GUI_POINT debug_bank_sub_pos = GUI_POINT(0, 0)
378 );
379 
394  CSM_BANK_IMAGE* pBank,
395  MYCHAR* pMC,
396  int iTileIndex,
397  GUI_POINT pBankPos,
398  int(*pCollideFunc)(const CSM_BANK_COLLISION_INFO* pInfo),
399  float fAngle = 0.f,
400  int iCenterX = 0,
401  int iCenterY = 0,
402  char iDebugLevel = 0
403 );
404 
419  CSM_BANK_IMAGE* pBank,
420  NPCHAR* pNpc,
421  int iTileIndex,
422  GUI_POINT pBankPos,
423  int(*pCollideFunc)(const CSM_BANK_COLLISION_INFO* pInfo),
424  float fAngle = 0.f,
425  int iCenterX = 0,
426  int iCenterY = 0,
427  char iDebugLevel = 0
428 );
429 
446  CSM_BANK_IMAGE* pBank,
447  CSM_BANK_IMAGE* pOther,
448  int iTileIndex1,
449  int iTileIndex2,
450  GUI_POINT pBankPos1,
451  GUI_POINT pBankPos2,
452  void(*pCollideFunc)(const CSM_BANK_COLLISION_INFO* pInfo),
453  float fAngle = 0.f,
454  int iCenterX = 0,
455  int iCenterY = 0,
456  char iDebugLevel = 0
457 );
458 
459 //------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
460 
461 extern CAVESTORY_MOD_API CSM_BANK_IMAGE* sz_pFirstImageBank;
462 
463 #include <CSMAPI_endcode.h>
464 
466 ///
Surface_Ids
List of surface IDs.
Definition: CSMAPI_enums.h:714
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.
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.
CAVESTORY_MOD_API BOOL CSM_ImageBank_ScanTile(CSM_BANK_IMAGE *pBank, int iTileIndex, bool bForce=false)
Scan a tile for solid pixels.
CAVESTORY_MOD_API void CSM_ImageBank_SetTileSize(CSM_BANK_IMAGE *pBank, int iTileW, int iTileH)
Check if a pixel is solid.
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.
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.
CAVESTORY_MOD_API BOOL CSM_ImageBank_FindBySurfaceId(Surface_Ids iSurfId, CSM_BANK_IMAGE **pOut=NULL)
Get a bank by its surface ID.
CAVESTORY_MOD_API void CSM_ImageBank_FreeAll()
Free all bank images.
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.
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.
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.
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.
CAVESTORY_MOD_API void CSM_ImageBank_Free(CSM_BANK_IMAGE *pBank)
Free a loaded bank image.
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.
#define CAVESTORY_MOD_API
Exports / imports Cavestory Mod API functions & classes.
Definition: CSMAPI_begincode.h:30
A structure to hold all collision information.
Definition: ImageBank.h:154
CSM_BANK_IMAGE * bank
The bank being tested for.
Definition: ImageBank.h:157
GUI_POINT bank_hit_pixel_subpos
The global subpixel position of the pixel that was collided against.
Definition: ImageBank.h:183
GUI_POINT object_hit_pixel_subpos
The subpixel position of the object pixel that was collided against.
Definition: ImageBank.h:191
GUI_POINT map_tile_pos
The map tile position where the collision took place.
Definition: ImageBank.h:177
CSM_BANK_RECT object_subrect
The object's subpixel rect.
Definition: ImageBank.h:195
CSM_BANK_RECT bank_subrect
The object's subpixel rect.
Definition: ImageBank.h:187
void * object
The object being tested against.
Definition: ImageBank.h:161
int object_old_ym
Old object ym.
Definition: ImageBank.h:203
int tile_index_1
The tile index used for collision testing for object.
Definition: ImageBank.h:173
int object_old_xm
Old object xm.
Definition: ImageBank.h:199
int pass_count
The total number of collisions so far.
Definition: ImageBank.h:165
int tile_index_0
The tile index used for collision testing.
Definition: ImageBank.h:169
Stores data about a banked image.
Definition: ImageBank.h:64
CSM_BANK_IMAGE * next
The bank image.
Definition: ImageBank.h:107
CSM_BANK_TILE * tile_list
The tile list.
Definition: ImageBank.h:103
Surface_Ids surf_id
The surface ID.
Definition: ImageBank.h:99
GUI_POINT img_size
The image size.
Definition: ImageBank.h:83
unsigned int file_name_crc
Stores the file name's CRC.
Definition: ImageBank.h:67
int entry_no
The name of the image inside of the bank folder.
Definition: ImageBank.h:75
int tile_total_count
The total number of tiles in this image.
Definition: ImageBank.h:95
char * name
The internal name of this image.
Definition: ImageBank.h:79
BOOL(* solid_func)(Surface_Ids surf_id, int x, int y)
A function that will determine if a pixel is solid or not.
Definition: ImageBank.h:111
int bank_no
The folder index inside of the 'Images' folder.
Definition: ImageBank.h:71
GUI_POINT tile_count
The number of rows and columns this bank has.
Definition: ImageBank.h:91
GUI_POINT tile_size
The size of each tile in pixels.
Definition: ImageBank.h:87
A more useful RECT struct.
Definition: ImageBank.h:117
int top
...
Definition: ImageBank.h:124
int height
...
Definition: ImageBank.h:140
int width
...
Definition: ImageBank.h:136
int center_y
...
Definition: ImageBank.h:148
int right
...
Definition: ImageBank.h:128
int left
...
Definition: ImageBank.h:120
int bottom
...
Definition: ImageBank.h:132
int center_x
...
Definition: ImageBank.h:144
Stores information about a specific tile.
Definition: ImageBank.h:43
unsigned int * solid_pixel_list
An array of indices pointing towards specific solid pixels.
Definition: ImageBank.h:46
bool done
Done boolean.
Definition: ImageBank.h:58
unsigned char * solid_pixel_map
A bitmap for testing the solidity of pixels.
Definition: ImageBank.h:50
unsigned short solid_count
The number of solid pixels held in the solid_pixels array.
Definition: ImageBank.h:54
Manages points.
Definition: CSMAPI_types.h:546
Player character object.
Definition: CSMAPI_types.h:1470
NPC object.
Definition: CSMAPI_types.h:2021