Loading...
Searching...
No Matches
object.h
Go to the documentation of this file.
1
49#ifndef OPENSNES_OBJECT_H
50#define OPENSNES_OBJECT_H
51
52#include <snes/types.h>
53
54/*============================================================================
55 * Constants
56 *============================================================================*/
57
59#define OB_MAX 80
60
62#define OB_TYPE_MAX 64
63
65#define OB_SIZE 64
66
67/*============================================================================
68 * Object Structure (64 bytes, packed)
69 *============================================================================*/
70
113
114/*============================================================================
115 * Compile-time struct layout assertions
116 * Must match the .STRUCT t_objs in object.asm exactly.
117 *============================================================================*/
118
119_Static_assert(sizeof(t_objs) == 64, "t_objs must be 64 bytes");
120_Static_assert(__builtin_offsetof(t_objs, xpos) == 16, "xpos offset mismatch");
121_Static_assert(__builtin_offsetof(t_objs, ypos) == 19, "ypos offset mismatch");
122_Static_assert(__builtin_offsetof(t_objs, xvel) == 34, "xvel offset mismatch");
123_Static_assert(__builtin_offsetof(t_objs, yvel) == 36, "yvel offset mismatch");
124_Static_assert(__builtin_offsetof(t_objs, action) == 46, "action offset mismatch");
125_Static_assert(__builtin_offsetof(t_objs, type) == 4, "type offset mismatch");
126_Static_assert(__builtin_offsetof(t_objs, width) == 26, "width offset mismatch");
127_Static_assert(__builtin_offsetof(t_objs, height) == 28, "height offset mismatch");
128_Static_assert(__builtin_offsetof(t_objs, status) == 48, "status offset mismatch");
129_Static_assert(__builtin_offsetof(t_objs, onscreen) == 56, "onscreen offset mismatch");
130
131/*============================================================================
132 * Exported Variables
133 *============================================================================*/
134
135/* --- Bank $00 SLOT 1 (C-accessible, < $2000) --- */
136
144extern t_objs objWorkspace;
145
147extern u16 objptr;
148
150extern u8 objtokill;
151
153extern u16 objgetid;
154
155/* --- Bank $7E SLOT 2 (NOT C-accessible, ASM-only) --- */
156/* The actual object buffer array lives in Bank $7E:
157 * objbuffers[OB_MAX] — 80 x 64 = 5120 bytes
158 * objfctinit/upd/ref — function pointer tables (256 bytes each)
159 * Access these ONLY through the workspace pattern:
160 * objGetPointer(handle) copies objbuffers[N] → objWorkspace
161 * Engine functions copy objWorkspace → objbuffers[N] after callbacks
162 */
163
164/*============================================================================
165 * Functions
166 *============================================================================*/
167
174void objInitEngine(void);
175
182void objInitGravity(u16 objgravity, u16 objfriction);
183
192void objInitFunctions(u8 objtype, void *initfct, void *updfct, void *reffct);
193
206u16 objNew(u8 objtype, u16 x, u16 y);
207
216void objGetPointer(u16 objhandle);
217
223void objKill(u16 objhandle);
224
228void objKillAll(void);
229
238void objLoadObjects(u8 *sourceO);
239
247void objUpdateAll(void);
248
256void objRefreshAll(void);
257
269void objCollidMap(u16 objhandle);
270
279
287void objCollidMap1D(u16 objhandle);
288
298u16 objCollidObj(u16 objhandle1, u16 objhandle2);
299
311void objUpdateXY(u16 objindex);
312
313#endif /* OPENSNES_OBJECT_H */
static const s16 xpos[4]
X positions for the four sprites displayed in a horizontal row.
Definition main.c:54
signed short s16
16-bit signed integer (-32768 to 32767)
Definition types.h:49
unsigned short u16
16-bit unsigned integer (0 to 65535)
Definition types.h:52
unsigned char u8
8-bit unsigned integer (0 to 255)
Definition types.h:46
void objKillAll(void)
Kill all active objects.
void objCollidMapWithSlopes(u16 objhandle)
Check object collision with map tiles including slopes.
void objKill(u16 objhandle)
Kill an object.
u16 objNew(u8 objtype, u16 x, u16 y)
Create a new object.
void objCollidMap1D(u16 objhandle)
Check object collision with map (no gravity)
void objCollidMap(u16 objhandle)
Check object collision with map tiles.
void objInitEngine(void)
Initialize the object engine.
void objLoadObjects(u8 *sourceO)
Load objects from a data table.
void objGetPointer(u16 objhandle)
Get pointer to an object from its handle.
u16 objptr
Current object pointer (byte offset, for internal use)
void objInitGravity(u16 objgravity, u16 objfriction)
Set gravity and friction values.
u16 objgetid
Handle of the last object created by objNew()
u8 objtokill
Set to 1 inside a callback to kill the current object.
void objInitFunctions(u8 objtype, void *initfct, void *updfct, void *reffct)
Register callback functions for an object type.
void objUpdateAll(void)
Update all active objects.
u16 objCollidObj(u16 objhandle1, u16 objhandle2)
Test collision between two objects.
void objRefreshAll(void)
Refresh sprites for all on-screen objects.
void objUpdateXY(u16 objindex)
Update object position from velocity.
t_objs objWorkspace
Object workspace (Bank $00)
Game object data structure.
Definition object.h:77
u8 type
Definition object.h:80
u16 parentID
Definition object.h:107
u16 sprframe
Definition object.h:87
u8 sprflip
Definition object.h:85
u8 onscreen
Definition object.h:110
u8 tempo
Definition object.h:104
u8 sprrefresh
Definition object.h:109
s16 xvel
Definition object.h:96
u16 height
Definition object.h:93
s16 yvel
Definition object.h:97
u16 width
Definition object.h:92
u16 sprblk3216
Definition object.h:84
u16 tilebprop
Definition object.h:101
u16 yofs
Definition object.h:91
u8 hitpoints
Definition object.h:108
u16 tilesprop
Definition object.h:100
u8 nID
Definition object.h:81
u8 count
Definition object.h:105
u16 prev
Definition object.h:78
u8 status
Definition object.h:103
u8 sprpal
Definition object.h:86
u16 sprid3216
Definition object.h:83
u16 xmax
Definition object.h:95
u16 xofs
Definition object.h:90
u8 dir
Definition object.h:106
u16 tileabove
Definition object.h:99
u16 sprnum
Definition object.h:82
u16 tilestand
Definition object.h:98
u16 action
Definition object.h:102
u16 next
Definition object.h:79
u16 xmin
Definition object.h:94
OpenSNES Standard Types.