Stardew Engine
Loading...
Searching...
No Matches
Entities.h
Go to the documentation of this file.
1#ifndef ENTITIES_H
2#define ENTITIES_H
3
4#include "Game2DLayer.h"
5#include "DynArray.h"
6#include "DrawContext.h"
7#include "InputContext.h"
8#include "Physics2D.h"
9#include <box2d/box2d.h>
10#include <stdbool.h>
11
12struct Entity2D;
15
16typedef void (*Entity2DOnInitFn)(struct Entity2D* pEnt, struct GameFrameworkLayer* pLayer, DrawContext* pDrawCtx, InputContext* pInputCtx);
17typedef void (*Entity2DUpdateFn)(struct Entity2D* pEnt, struct GameFrameworkLayer* pLayer, float deltaT);
18typedef void (*Entity2DUpdatePostPhysicsFn)(struct Entity2D* pEnt, struct GameFrameworkLayer* pLayer, float deltaT);
19typedef void (*Entity2DDrawFn)(struct Entity2D* pEnt, struct GameFrameworkLayer* pLayer, struct Transform2D* pCam, VECTOR(Worldspace2DVert)* outVerts, VECTOR(VertIndexT)* outIndices, VertIndexT* pNextIndex);
20typedef void (*Entity2DInputFn)(struct Entity2D* pEnt, struct GameFrameworkLayer* pLayer, InputContext* context);
21typedef void (*Entity2DOnDestroyFn)(struct Entity2D* pEnt, struct GameFrameworkLayer* pLayer);
22typedef void (*Entity2DGetBoundingBoxFn)(struct Entity2D* pEnt, struct GameFrameworkLayer* pLayer, vec2 outTL, vec2 outBR);
23
25typedef float (*Entity2DGetPreDrawSortValueFn)(struct Entity2D* pEnt);
26
27
28typedef void(*EntityDeserializeFn)(struct BinarySerializer* bs, struct Entity2D* pOutEnt, struct GameLayer2DData* pData);
29typedef void(*EntitySerializeFn)(struct BinarySerializer* bs, struct Entity2D* pInEnt, struct GameLayer2DData* pData);
30
31
32typedef void(*RegisterGameEntitiesFn)(void);
33
34typedef void(*OnSensorShapeOverlapBeginFn)(struct GameFrameworkLayer* pLayer, HEntity2D hOverlappingEntity, HEntity2D thisSensorEntity);
35typedef void(*OnSensorShapeOverlapEndFn)(struct GameFrameworkLayer* pLayer, HEntity2D hOverlappingEntity, HEntity2D thisSensorEntity);
36
37typedef void(*PrintEntityInfoExtenderFn)(struct Entity2D* pInEnt);
38
44
46
47#define MAX_COMPONENTS 16
48
59
66
77
89
91{
92 char* content;
94 float fSizePts;
96 float r, g, b, a;
97 bool bDraw;
98};
99
113
132
141
142struct BinarySerializer;
143
147void Et2D_RegisterEntityType(u32 typeID, struct EntitySerializerPair* pair);
148
149void Et2D_Init(RegisterGameEntitiesFn registerGameEntities);
150
157
163
164
170
174typedef bool(*Entity2DIterator)(struct Entity2D* pEnt, int i, void* pUser);
175
176
178
179void Et2D_SerializeEntities(struct Entity2DCollection* pCollection, struct BinarySerializer* bs, struct GameLayer2DData* pData, int objectLayer);
180
181void Et2D_DeserializeCommon(struct BinarySerializer* bs, struct Entity2D* pOutEnt);
182void Et2D_SerializeCommon(struct BinarySerializer* bs, struct Entity2D* pInEnt);
183
186
188
246
250void Entity2DOnInit(struct Entity2D* pEnt, struct GameFrameworkLayer* pLayer, DrawContext* pDrawCtx, InputContext* pInputCtx);
251void Entity2DUpdate(struct Entity2D* pEnt, struct GameFrameworkLayer* pLayer, float deltaT);
252void Entity2DUpdatePostPhysics(struct Entity2D* pEnt, struct GameFrameworkLayer* pLayer, float deltaT);
253void Entity2DDraw(struct Entity2D* pEnt, struct GameFrameworkLayer* pLayer, struct Transform2D* pCam, VECTOR(Worldspace2DVert)* outVerts, VECTOR(VertIndexT)* outIndices, VertIndexT* pNextIndex);
254void Entity2DInput(struct Entity2D* pEnt, struct GameFrameworkLayer* pLayer, InputContext* context);
255void Entity2DOnDestroy(struct Entity2D* pEnt, struct GameFrameworkLayer* pLayer);
256void Entity2DGetBoundingBox(struct Entity2D* pEnt, struct GameFrameworkLayer* pLayer, vec2 outTL, vec2 outBR);
257float Entity2DGetSortVal(struct Entity2D* pEnt);
258
259void Et2D_PopulateCommonHandlers(struct Entity2D* pEnt);
260
261
262#endif
u32 VertIndexT
Definition DrawContext.h:52
void Et2D_DestroyCollection(struct Entity2DCollection *pCollection, struct GameFrameworkLayer *pLayer)
Definition Entities.c:28
void(* PrintEntityInfoExtenderFn)(struct Entity2D *pInEnt)
Definition Entities.h:37
bool(* Entity2DIterator)(struct Entity2D *pEnt, int i, void *pUser)
both serialize and deserialize
Definition Entities.h:174
struct Entity2D * Et2D_GetEntity(struct Entity2DCollection *pCollection, HEntity2D hEnt)
Definition Entities.c:421
void(* RegisterGameEntitiesFn)(void)
Definition Entities.h:32
void Et2D_PopulateCommonHandlers(struct Entity2D *pEnt)
Definition Entities.c:444
void(* Entity2DDrawFn)(struct Entity2D *pEnt, struct GameFrameworkLayer *pLayer, struct Transform2D *pCam, VECTOR(Worldspace2DVert) *outVerts, VECTOR(VertIndexT) *outIndices, VertIndexT *pNextIndex)
Definition Entities.h:19
void Et2D_DeserializeCommon(struct BinarySerializer *bs, struct Entity2D *pOutEnt)
Definition Entities.c:376
void(* OnSensorShapeOverlapEndFn)(struct GameFrameworkLayer *pLayer, HEntity2D hOverlappingEntity, HEntity2D thisSensorEntity)
Definition Entities.h:35
void Entity2DDraw(struct Entity2D *pEnt, struct GameFrameworkLayer *pLayer, struct Transform2D *pCam, VECTOR(Worldspace2DVert) *outVerts, VECTOR(VertIndexT) *outIndices, VertIndexT *pNextIndex)
Definition Entities.c:71
void(* Entity2DGetBoundingBoxFn)(struct Entity2D *pEnt, struct GameFrameworkLayer *pLayer, vec2 outTL, vec2 outBR)
Definition Entities.h:22
void Et2D_IterateEntities(struct Entity2DCollection *pCollection, Entity2DIterator itr, void *pUser)
Definition Entities.c:426
void Entity2DUpdate(struct Entity2D *pEnt, struct GameFrameworkLayer *pLayer, float deltaT)
Definition Entities.c:61
float Entity2DGetSortVal(struct Entity2D *pEnt)
Definition Entities.c:439
#define MAX_COMPONENTS
Definition Entities.h:47
void Entity2DUpdatePostPhysics(struct Entity2D *pEnt, struct GameFrameworkLayer *pLayer, float deltaT)
Definition Entities.c:66
EngineBuiltinEntityType
Definition Entities.h:134
@ EBET_Last
Definition Entities.h:139
@ EBET_StaticColliderPoly
Definition Entities.h:137
@ EBET_StaticColliderEllipse
Definition Entities.h:138
@ EBET_StaticColliderRect
Definition Entities.h:135
@ EBET_StaticColliderCircle
Definition Entities.h:136
void(* Entity2DOnInitFn)(struct Entity2D *pEnt, struct GameFrameworkLayer *pLayer, DrawContext *pDrawCtx, InputContext *pInputCtx)
Definition Entities.h:16
ComponentType
types built into the engine
Definition Entities.h:51
@ ETE_Sprite
Definition Entities.h:52
@ ETE_StaticCollider
Definition Entities.h:53
@ ETE_TextSprite
Definition Entities.h:55
@ ETE_Last
Definition Entities.h:57
@ ETE_SpriteAnimator
Definition Entities.h:56
@ ETE_DynamicCollider
Definition Entities.h:54
void Et2D_RegisterEntityType(u32 typeID, struct EntitySerializerPair *pair)
Games using the engine should call this to add types of entity to be serialized.
Definition Entities.c:368
void Et2D_SerializeCommon(struct BinarySerializer *bs, struct Entity2D *pInEnt)
Definition Entities.c:403
void Et2D_InitCollection(struct Entity2DCollection *pCollection)
Definition Entities.c:35
i32 EntityType
Definition Entities.h:45
float(* Entity2DGetPreDrawSortValueFn)(struct Entity2D *pEnt)
lower values drawn first
Definition Entities.h:25
void(* Entity2DInputFn)(struct Entity2D *pEnt, struct GameFrameworkLayer *pLayer, InputContext *context)
Definition Entities.h:20
HEntity2D Et2D_AddEntity(struct Entity2DCollection *pCollection, struct Entity2D *pEnt)
Definition Entities.c:198
void Et2D_DestroyEntity(struct GameFrameworkLayer *pLayer, struct Entity2DCollection *pCollection, HEntity2D hEnt)
Definition Entities.c:168
void(* EntitySerializeFn)(struct BinarySerializer *bs, struct Entity2D *pInEnt, struct GameLayer2DData *pData)
Definition Entities.h:29
void(* EntityDeserializeFn)(struct BinarySerializer *bs, struct Entity2D *pOutEnt, struct GameLayer2DData *pData)
Definition Entities.h:28
void Entity2DOnDestroy(struct Entity2D *pEnt, struct GameFrameworkLayer *pLayer)
Definition Entities.c:81
void Entity2DInput(struct Entity2D *pEnt, struct GameFrameworkLayer *pLayer, InputContext *context)
Definition Entities.c:76
void Et2D_Init(RegisterGameEntitiesFn registerGameEntities)
Definition Entities.c:145
void(* Entity2DUpdatePostPhysicsFn)(struct Entity2D *pEnt, struct GameFrameworkLayer *pLayer, float deltaT)
Definition Entities.h:18
void Entity2DOnInit(struct Entity2D *pEnt, struct GameFrameworkLayer *pLayer, DrawContext *pDrawCtx, InputContext *pInputCtx)
Default base implementations, override with own behavior and then call these at the end.
Definition Entities.c:47
void Et2D_SerializeEntities(struct Entity2DCollection *pCollection, struct BinarySerializer *bs, struct GameLayer2DData *pData, int objectLayer)
Definition Entities.c:356
void(* Entity2DUpdateFn)(struct Entity2D *pEnt, struct GameFrameworkLayer *pLayer, float deltaT)
Definition Entities.h:17
void Entity2DGetBoundingBox(struct Entity2D *pEnt, struct GameFrameworkLayer *pLayer, vec2 outTL, vec2 outBR)
Definition Entities.c:92
void Et2D_PrintEntitiesInfo(struct Entity2DCollection *pCollection)
Definition Entities.c:468
void(* Entity2DOnDestroyFn)(struct Entity2D *pEnt, struct GameFrameworkLayer *pLayer)
Definition Entities.h:21
void(* OnSensorShapeOverlapBeginFn)(struct GameFrameworkLayer *pLayer, HEntity2D hOverlappingEntity, HEntity2D thisSensorEntity)
Definition Entities.h:34
vec2 vec2 struct Entity2DCollection * pCollection
Definition EntityQuadTree.h:38
vec2 vec2 struct Entity2DCollection struct GameFrameworkLayer * pLayer
Definition EntityQuadTree.h:38
HGeneric H2DBody
Definition HandleDefs.h:42
HGeneric HEntity2DQuadtreeEntityRef
Definition HandleDefs.h:46
HGeneric HDynamicEntityListItem
Definition HandleDefs.h:48
HGeneric hSprite
Definition HandleDefs.h:17
HGeneric HEntity2D
Definition HandleDefs.h:38
i32 HGeneric
Definition HandleDefs.h:6
HGeneric HFont
Definition HandleDefs.h:28
HGeneric hAtlas
Definition HandleDefs.h:14
int32_t i32
Definition IntTypes.h:13
uint32_t u32
Definition IntTypes.h:12
#define VECTOR(a)
Definition WfGame.h:8
Definition Entities.h:101
struct Transform2D transform
Definition Entities.h:111
int onSprite
Definition Entities.h:106
hSprite * pSprites
Definition Entities.h:104
int numSprites
Definition Entities.h:105
float fps
Definition Entities.h:107
float timer
Definition Entities.h:103
const char * animationName
Definition Entities.h:102
bool bDraw
Definition Entities.h:110
bool bIsAnimating
Definition Entities.h:109
bool bRepeat
Definition Entities.h:108
Definition BinarySerializer.h:16
An entity component tagged union - there are a fixed number built into the engine.
Definition Entities.h:116
struct DynamicCollider dynamicCollider
Definition Entities.h:124
struct StaticCollider staticCollider
Definition Entities.h:122
union Component2D::@4 data
struct AnimatedSprite spriteAnimator
Definition Entities.h:128
struct TextSprite textSprite
Definition Entities.h:126
struct Sprite sprite
Definition Entities.h:120
enum ComponentType type
Definition Entities.h:117
Definition DrawContext.h:59
Definition Entities.h:79
OnSensorShapeOverlapBeginFn onSensorOverlapBegin
Definition Entities.h:86
bool bGenerateSensorEvents
If this is a non-sensor, does it generate sensor overlap events? Best for performance to only enable ...
Definition Entities.h:85
H2DBody id
Definition Entities.h:80
bool bIsSensor
Definition Entities.h:83
struct KinematicBodyOptions options
Definition Entities.h:82
struct PhysicsShape2D shape
Definition Entities.h:81
OnSensorShapeOverlapEndFn onSensorOverlapEnd
Definition Entities.h:87
Definition Entity2DCollection.h:30
Definition Entities.h:190
struct Transform2D transform
Definition Entities.h:202
union Entity2D::@5 user
Entity2DOnInitFn init
Definition Entities.h:192
bool bSerializeToDisk
do we serialize when the level is serialized?
Definition Entities.h:240
Entity2DUpdateFn update
Definition Entities.h:193
Entity2DOnDestroyFn onDestroy
Definition Entities.h:197
bool bSerializeToNetwork
Definition Entities.h:242
struct Component2D components[MAX_COMPONENTS]
Definition Entities.h:220
Entity2DGetPreDrawSortValueFn getSortPos
Definition Entities.h:199
HDynamicEntityListItem hDynamicListRef
reference to the entity in the dynamic entities list needed to remove it
Definition Entities.h:231
int networkID
Definition Entities.h:244
int inDrawLayer
Which object layer of the scene is it in? Effects the order they are drawn in.
Definition Entities.h:237
void * pData
data
Definition Entities.h:208
Entity2DGetBoundingBoxFn getBB
Definition Entities.h:198
HGeneric hData
Definition Entities.h:209
HEntity2D previousSibling
Definition Entities.h:217
HEntity2D thisEntity
just for convenience - this entities handle
Definition Entities.h:214
Entity2DDrawFn draw
Definition Entities.h:195
Entity2DUpdatePostPhysicsFn postPhys
Definition Entities.h:194
PrintEntityInfoExtenderFn printEntityInfo
Definition Entities.h:200
HEntity2D nextSibling
Definition Entities.h:216
int numComponents
Definition Entities.h:219
bool bKeepInDynamicList
keep in the dynamic list of brute force culled entities
Definition Entities.h:228
Entity2DInputFn input
Definition Entities.h:196
EntityType type
Definition Entities.h:203
HEntity2DQuadtreeEntityRef hQuadTreeRef
reference to the entity in the quad tree needed to remove it
Definition Entities.h:225
bool bKeepInQuadtree
Definition Entities.h:222
Definition Entities.h:40
EntityDeserializeFn deserialize
Definition Entities.h:41
EntitySerializeFn serialize
Definition Entities.h:42
Definition GameFramework.h:42
Definition Game2DLayer.h:92
Definition InputContext.h:137
Definition Physics2D.h:47
Definition Physics2D.h:36
Definition Entities.h:61
hSprite sprite
Definition Entities.h:62
bool bDraw
Definition Entities.h:64
struct Transform2D transform
Definition Entities.h:63
Definition Entities.h:68
bool bGenerateSensorEvents
If this is a non-sensor, does it generate sensor overlap events? Best for performance to only enable ...
Definition Entities.h:73
OnSensorShapeOverlapBeginFn onSensorOverlapBegin
Definition Entities.h:74
OnSensorShapeOverlapEndFn onSensorOverlapEnd
Definition Entities.h:75
H2DBody id
Definition Entities.h:69
bool bIsSensor
Definition Entities.h:71
struct PhysicsShape2D shape
Definition Entities.h:70
Definition Entities.h:91
bool bDraw
Definition Entities.h:97
float fSizePts
Definition Entities.h:94
char * content
Definition Entities.h:92
hAtlas atlas
Definition Entities.h:95
float r
Definition Entities.h:96
float a
Definition Entities.h:96
float b
Definition Entities.h:96
HFont font
Definition Entities.h:93
float g
Definition Entities.h:96
Definition Game2DLayer.h:54
Definition DrawContext.h:13