File Entities.h

FileList > engine > include > Entities.h

Go to the source code of this file

  • #include "Game2DLayer.h"
  • #include "DynArray.h"
  • #include "DrawContext.h"
  • #include "InputContext.h"
  • #include "Physics2D.h"
  • #include <box2d/box2d.h>
  • #include <stdbool.h>

Classes

Type Name
struct AnimatedSprite
struct Component2D
An entity component tagged union - there are a fixed number built into the engine.
struct DynamicCollider
struct Entity2D
struct EntitySerializerPair
struct Sprite
struct StaticCollider
struct TextSprite

Public Types

Type Name
enum ComponentType
types built into the engine
enum EngineBuiltinEntityType
typedef void(* Entity2DDrawFn
typedef void(* Entity2DGetBoundingBoxFn
typedef float(* Entity2DGetPreDrawSortValueFn
lower values drawn first
typedef void(* Entity2DInputFn
typedef bool(* Entity2DIterator
iterator function for Et2D_IterateEntities. Return true to continue iterating or false to break. pUser is value passed as pUser to Et2D_IterateEntities
typedef void(* Entity2DOnDestroyFn
typedef void(* Entity2DOnInitFn
typedef void(* Entity2DUpdateFn
typedef void(* Entity2DUpdatePostPhysicsFn
typedef void(* EntityDeserializeFn
typedef void(* EntitySerializeFn
typedef i32 EntityType
typedef void(* HandleEntityMessagefn
typedef void(* OnSensorShapeOverlapBeginFn
typedef void(* OnSensorShapeOverlapEndFn
typedef void(* PrintEntityInfoExtenderFn
typedef void(* RegisterGameEntitiesFn

Public Functions

Type Name
void Entity2DDraw (struct Entity2D * pEnt, struct GameFrameworkLayer * pLayer, struct Transform2D * pCam, VECTOR(Worldspace2DVert) * outVerts, VECTOR(VertIndexT) * outIndices, VertIndexT * pNextIndex)
void Entity2DGetBoundingBox (struct Entity2D * pEnt, struct GameFrameworkLayer * pLayer, vec2 outTL, vec2 outBR)
float Entity2DGetSortVal (struct Entity2D * pEnt)
void Entity2DInput (struct Entity2D * pEnt, struct GameFrameworkLayer * pLayer, InputContext * context)
void Entity2DOnDestroy (struct Entity2D * pEnt, struct GameFrameworkLayer * pLayer)
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.
void Entity2DUpdate (struct Entity2D * pEnt, struct GameFrameworkLayer * pLayer, float deltaT)
void Entity2DUpdatePostPhysics (struct Entity2D * pEnt, struct GameFrameworkLayer * pLayer, float deltaT)
HEntity2D Et2D_AddEntity (struct Entity2DCollection * pCollection, struct Entity2D * pEnt)
Add, but don't initialize, the entity. If you're the server, a new net ID will be assigned.
HEntity2D Et2D_AddEntityNoNewNetID (struct Entity2DCollection * pCollection, struct Entity2D * pEnt)
Add, but don't initialize, the entity. If you're the server, a new net ID won't be assigned.
void Et2D_DeserializeCommon (struct BinarySerializer * bs, struct Entity2D * pOutEnt)
void Et2D_DeserializeEntityV1Base (struct Entity2DCollection * pCollection, struct BinarySerializer * bs, struct GameLayer2DData * pData, int objectLayer, struct Entity2D * pOutEnt)
Deserialize an entity from the binary serializer using the version 1 method.
void Et2D_DestroyCollection (struct Entity2DCollection * pCollection, struct GameFrameworkLayer * pLayer)
void Et2D_DestroyEntity (struct GameFrameworkLayer * pLayer, struct Entity2DCollection * pCollection, HEntity2D hEnt)
void Et2D_DoEntityMessagesQueue (struct Entity2DCollection * pCollection, struct GameFrameworkLayer * pLayer)
Do the entity messages queue, iterate through the messages, call entities callbacks, and clear the queue.
struct Entity2D * Et2D_GetEntity (struct Entity2DCollection * pCollection, HEntity2D hEnt)
void Et2D_Init (RegisterGameEntitiesFn registerGameEntities)
void Et2D_InitCollection (struct Entity2DCollection * pCollection)
void Et2D_IterateEntities (struct Entity2DCollection * pCollection, Entity2DIterator itr, void * pUser)
A convenient helper to iterate through the entity collection.
void Et2D_PopulateCommonHandlers (struct Entity2D * pEnt)
void Et2D_PrintEntitiesInfo (struct Entity2DCollection * pCollection)
void Et2D_RegisterEntityType (u32 typeID, struct EntitySerializerPair * pair)
Games using the engine should call this to add types of entity to be serialized.
void Et2D_SendEntity2EntityMsg (struct Entity2DCollection * pCollection, struct EntityToEntityMessage * pMsg)
void Et2D_SerializeCommon (struct BinarySerializer * bs, struct Entity2D * pInEnt)
void Et2D_SerializeEntities (struct Entity2DCollection * pCollection, struct BinarySerializer * bs, struct GameLayer2DData * pData, int objectLayer)
void Et2D_SerializeEntityV1Base (struct Entity2D * pOn, struct BinarySerializer * bs, struct GameLayer2DData * pData)
Serialize a single entity.

Macros

Type Name
define MAX_COMPONENTS 16

Public Types Documentation

enum ComponentType

types built into the engine

enum ComponentType {
    ETE_Sprite,
    ETE_StaticCollider,
    ETE_DynamicCollider,
    ETE_TextSprite,
    ETE_SpriteAnimator,
    ETE_Last
};

enum EngineBuiltinEntityType

enum EngineBuiltinEntityType {
    EBET_StaticColliderRect,
    EBET_StaticColliderCircle,
    EBET_StaticColliderPoly,
    EBET_StaticColliderEllipse,
    EBET_Last
};

typedef Entity2DDrawFn

typedef void(* Entity2DDrawFn) (struct Entity2D *pEnt, struct GameFrameworkLayer *pLayer, struct Transform2D *pCam, VECTOR(Worldspace2DVert) *outVerts, VECTOR(VertIndexT) *outIndices, VertIndexT *pNextIndex);

typedef Entity2DGetBoundingBoxFn

typedef void(* Entity2DGetBoundingBoxFn) (struct Entity2D *pEnt, struct GameFrameworkLayer *pLayer, vec2 outTL, vec2 outBR);

typedef Entity2DGetPreDrawSortValueFn

lower values drawn first

typedef float(* Entity2DGetPreDrawSortValueFn) (struct Entity2D *pEnt);

typedef Entity2DInputFn

typedef void(* Entity2DInputFn) (struct Entity2D *pEnt, struct GameFrameworkLayer *pLayer, InputContext *context);

typedef Entity2DIterator

iterator function for Et2D_IterateEntities. Return true to continue iterating or false to break. pUser is value passed as pUser to Et2D_IterateEntities

typedef bool(* Entity2DIterator) (struct Entity2D *pEnt, int i, void *pUser);

typedef Entity2DOnDestroyFn

typedef void(* Entity2DOnDestroyFn) (struct Entity2D *pEnt, struct GameFrameworkLayer *pLayer);

typedef Entity2DOnInitFn

typedef void(* Entity2DOnInitFn) (struct Entity2D *pEnt, struct GameFrameworkLayer *pLayer, DrawContext *pDrawCtx, InputContext *pInputCtx);

typedef Entity2DUpdateFn

typedef void(* Entity2DUpdateFn) (struct Entity2D *pEnt, struct GameFrameworkLayer *pLayer, float deltaT);

typedef Entity2DUpdatePostPhysicsFn

typedef void(* Entity2DUpdatePostPhysicsFn) (struct Entity2D *pEnt, struct GameFrameworkLayer *pLayer, float deltaT);

typedef EntityDeserializeFn

typedef void(* EntityDeserializeFn) (struct BinarySerializer *bs, struct Entity2D *pOutEnt, struct GameLayer2DData *pData);

typedef EntitySerializeFn

typedef void(* EntitySerializeFn) (struct BinarySerializer *bs, struct Entity2D *pInEnt, struct GameLayer2DData *pData);

typedef EntityType

typedef i32 EntityType;

typedef HandleEntityMessagefn

typedef void(* HandleEntityMessagefn) (struct Entity2D *pEnt, struct Entity2D *pSender, struct EntityToEntityMessage *pMsg, struct GameFrameworkLayer *pLayer);

typedef OnSensorShapeOverlapBeginFn

typedef void(* OnSensorShapeOverlapBeginFn) (struct GameFrameworkLayer *pLayer, HEntity2D hOverlappingEntity, HEntity2D thisSensorEntity);

typedef OnSensorShapeOverlapEndFn

typedef void(* OnSensorShapeOverlapEndFn) (struct GameFrameworkLayer *pLayer, HEntity2D hOverlappingEntity, HEntity2D thisSensorEntity);

typedef PrintEntityInfoExtenderFn

typedef void(* PrintEntityInfoExtenderFn) (struct Entity2D *pInEnt);

typedef RegisterGameEntitiesFn

typedef void(* RegisterGameEntitiesFn) (void);

Public Functions Documentation

function Entity2DDraw

void Entity2DDraw (
    struct Entity2D * pEnt,
    struct GameFrameworkLayer * pLayer,
    struct Transform2D * pCam,
    VECTOR( Worldspace2DVert ) * outVerts,
    VECTOR(VertIndexT) * outIndices,
    VertIndexT * pNextIndex
) 

function Entity2DGetBoundingBox

void Entity2DGetBoundingBox (
    struct Entity2D * pEnt,
    struct GameFrameworkLayer * pLayer,
    vec2 outTL,
    vec2 outBR
) 

function Entity2DGetSortVal

float Entity2DGetSortVal (
    struct Entity2D * pEnt
) 

function Entity2DInput

void Entity2DInput (
    struct Entity2D * pEnt,
    struct GameFrameworkLayer * pLayer,
    InputContext * context
) 

function Entity2DOnDestroy

void Entity2DOnDestroy (
    struct Entity2D * pEnt,
    struct GameFrameworkLayer * pLayer
) 

function Entity2DOnInit

Default base implementations, override with own behavior and then call these at the end.

void Entity2DOnInit (
    struct Entity2D * pEnt,
    struct GameFrameworkLayer * pLayer,
    DrawContext * pDrawCtx,
    InputContext * pInputCtx
) 

function Entity2DUpdate

void Entity2DUpdate (
    struct Entity2D * pEnt,
    struct GameFrameworkLayer * pLayer,
    float deltaT
) 

function Entity2DUpdatePostPhysics

void Entity2DUpdatePostPhysics (
    struct Entity2D * pEnt,
    struct GameFrameworkLayer * pLayer,
    float deltaT
) 

function Et2D_AddEntity

Add, but don't initialize, the entity. If you're the server, a new net ID will be assigned.

HEntity2D Et2D_AddEntity (
    struct Entity2DCollection * pCollection,
    struct Entity2D * pEnt
) 

Parameters:

  • pCollection - collection to add to
  • pEnt - Entity to add
  • bOwned - Does this host own the entity or is it owned by another player on the network, no effect if single player

Returns:

Entity handle


function Et2D_AddEntityNoNewNetID

Add, but don't initialize, the entity. If you're the server, a new net ID won't be assigned.

HEntity2D Et2D_AddEntityNoNewNetID (
    struct Entity2DCollection * pCollection,
    struct Entity2D * pEnt
) 

Parameters:

  • pCollection - collection to add to
  • pEnt - Entity to add
  • bOwned - Does this host own the entity or is it owned by another player on the network, no effect if single player

Returns:

Entity handle


function Et2D_DeserializeCommon

void Et2D_DeserializeCommon (
    struct BinarySerializer * bs,
    struct Entity2D * pOutEnt
) 

function Et2D_DeserializeEntityV1Base

Deserialize an entity from the binary serializer using the version 1 method.

void Et2D_DeserializeEntityV1Base (
    struct Entity2DCollection * pCollection,
    struct BinarySerializer * bs,
    struct GameLayer2DData * pData,
    int objectLayer,
    struct Entity2D * pOutEnt
) 

Parameters:

  • pCollection
  • bs
  • pData game layer data
  • objectLayer object layer to set the entity to be in
  • pOutEnt entity to populate

function Et2D_DestroyCollection

void Et2D_DestroyCollection (
    struct Entity2DCollection * pCollection,
    struct GameFrameworkLayer * pLayer
) 

function Et2D_DestroyEntity

void Et2D_DestroyEntity (
    struct GameFrameworkLayer * pLayer,
    struct Entity2DCollection * pCollection,
    HEntity2D hEnt
) 

Parameters:

  • pLayer
  • pCollection
  • hEnt

function Et2D_DoEntityMessagesQueue

Do the entity messages queue, iterate through the messages, call entities callbacks, and clear the queue.

void Et2D_DoEntityMessagesQueue (
    struct Entity2DCollection * pCollection,
    struct GameFrameworkLayer * pLayer
) 

Parameters:

  • pCollection
  • pLayer

function Et2D_GetEntity

struct Entity2D * Et2D_GetEntity (
    struct Entity2DCollection * pCollection,
    HEntity2D hEnt
) 

Parameters:

  • pCollection
  • hEnt

Returns:

  • entity handle

function Et2D_Init

void Et2D_Init (
    RegisterGameEntitiesFn registerGameEntities
) 

function Et2D_InitCollection

void Et2D_InitCollection (
    struct Entity2DCollection * pCollection
) 

function Et2D_IterateEntities

A convenient helper to iterate through the entity collection.

void Et2D_IterateEntities (
    struct Entity2DCollection * pCollection,
    Entity2DIterator itr,
    void * pUser
) 

Parameters:

  • pCollection collection to iterate
  • itr iterator function ptr
  • pUser user data to pass to iterator fn

function Et2D_PopulateCommonHandlers

void Et2D_PopulateCommonHandlers (
    struct Entity2D * pEnt
) 

function Et2D_PrintEntitiesInfo

void Et2D_PrintEntitiesInfo (
    struct Entity2DCollection * pCollection
) 

function Et2D_RegisterEntityType

Games using the engine should call this to add types of entity to be serialized.

void Et2D_RegisterEntityType (
    u32 typeID,
    struct EntitySerializerPair * pair
) 

Parameters:

  • typeID Entity type
  • pair pair of functions to serialize and deserialize

function Et2D_SendEntity2EntityMsg

void Et2D_SendEntity2EntityMsg (
    struct Entity2DCollection * pCollection,
    struct EntityToEntityMessage * pMsg
) 

Parameters:

  • pCollection
  • pMsg

function Et2D_SerializeCommon

void Et2D_SerializeCommon (
    struct BinarySerializer * bs,
    struct Entity2D * pInEnt
) 

function Et2D_SerializeEntities

void Et2D_SerializeEntities (
    struct Entity2DCollection * pCollection,
    struct BinarySerializer * bs,
    struct GameLayer2DData * pData,
    int objectLayer
) 

function Et2D_SerializeEntityV1Base

Serialize a single entity.

void Et2D_SerializeEntityV1Base (
    struct Entity2D * pOn,
    struct BinarySerializer * bs,
    struct GameLayer2DData * pData
) 

Parameters:

  • pOn
  • bs
  • pData

Macro Definition Documentation

define MAX_COMPONENTS

#define MAX_COMPONENTS `16`


The documentation for this class was generated from the following file /home/runner/work/2DFarmingRPG/2DFarmingRPG/Stardew/engine/include/Entities.h