File Game2DLayerNetwork.h

FileList > engine > include > Game2DLayerNetwork.h

Go to the source code of this file

Networking layer specific to game 2d layer.

  • #include <stdbool.h>
  • #include "IntTypes.h"

Classes

Type Name
struct AdjustNetID_RPC
struct CreateEntity_RPC
struct DeleteEntity_RPC
struct TilemapEdit
struct UserGame2DRPC
An RPC implemented by a users game.

Public Types

Type Name
enum G2DPacketType
enum Game2DRPCType
typedef void(* PacketExtensionNoArgsFn
typedef void(* RPCMessageConstructorFn
callback to construct an rpc message of a given type, pRPCStruct is a struct containing relevant data to construct your rpc message
typedef void(* RPCMessageHandlerFn
callback to handle an RPC message, to be read from the binary serializer, passed Game2DLayerData* so the RPC can do stuff

Public Functions

Type Name
void G2D_DoRPC (struct GameFrameworkLayer * pLayer, struct GameLayer2DData * pData, u8 * pRPCData, int client)
do RPCs, call once a packet has been confirmed as a G2DPacket_RPC, call on both client and server
void G2D_Enqueue_RequestLevelData ()
TODO: should really be static to this file, probably.
void G2D_Enqueue_Worldstate_Packet (struct GameLayer2DData * pData, int clientI)
Enqueue a packet that will cause all entities with bSerializeInNetworkUpdate == true to be saved into a packet, the serializer context will be SCTX_NetworkUpdate.
void G2D_Extend_RequestLevelDataMessage (PacketExtensionNoArgsFn fn)
extend the packet that the client sends to request level data from the server. By default tile maps and serialized entities are included, this callback is called before this Game2DLayer managed level data is serialized - see WfNetwork.c
struct Entity2D * G2D_FindEntityWithNetID (struct Entity2DCollection * pCollection, int netID)
try to find the entity with a given net ID
bool G2D_IsClientConnected (int i)
call from the game thread if you're the server to determine if a client is connected
enum G2DPacketType G2D_ParsePacket (u8 * pPacket, u8 ** pOutBody, int * outHeaderSize)
enum Game2DRPCType G2D_ParseRPCPacket (u8 * packet, u8 ** pOutBody)
void G2D_PollNetworkQueueClient (struct GameFrameworkLayer * pLayer, float deltaT)
void G2D_PollNetworkQueueServer (struct GameFrameworkLayer * pLayer, float deltaT)
void G2D_RegisterUserRPC (struct UserGame2DRPC * rpc)
Register a user RPC, call once at startup, call in order your games rpc types appear in the enum.
void G2D_SendRPC (int client, enum Game2DRPCType type, void * pRPCData)
Send an RPC.

Public Types Documentation

enum G2DPacketType

enum G2DPacketType {
    G2DPacket_RequestLevelData,
    G2DPacket_LevelDataResponseData,
    G2DPacket_RPC,
    G2DPacket_WorldState
};

enum Game2DRPCType

enum Game2DRPCType {
    G2DRPC_CreateEntity,
    G2DRPC_DestroyEntity,
    G2DRPC_AdjustNetworkID,
    G2DRPC_LastEngineRPC
};

typedef PacketExtensionNoArgsFn

typedef void(* PacketExtensionNoArgsFn) (struct BinarySerializer *);

typedef RPCMessageConstructorFn

callback to construct an rpc message of a given type, pRPCStruct is a struct containing relevant data to construct your rpc message

typedef void(* RPCMessageConstructorFn) (struct BinarySerializer *pBS, void *pRPCStruct);

typedef RPCMessageHandlerFn

callback to handle an RPC message, to be read from the binary serializer, passed Game2DLayerData* so the RPC can do stuff

typedef void(* RPCMessageHandlerFn) (struct BinarySerializer *pBS, struct GameLayer2DData *pData, int client);

Public Functions Documentation

function G2D_DoRPC

do RPCs, call once a packet has been confirmed as a G2DPacket_RPC, call on both client and server

void G2D_DoRPC (
    struct GameFrameworkLayer * pLayer,
    struct GameLayer2DData * pData,
    u8 * pRPCData,
    int client
) 

Parameters:

  • pData
  • pRPCData
  • client the number of the client who has sent the RPC, or -1 if the server has sent it and you are a client

function G2D_Enqueue_RequestLevelData

TODO: should really be static to this file, probably.

void G2D_Enqueue_RequestLevelData () 

function G2D_Enqueue_Worldstate_Packet

Enqueue a packet that will cause all entities with bSerializeInNetworkUpdate == true to be saved into a packet, the serializer context will be SCTX_NetworkUpdate.

void G2D_Enqueue_Worldstate_Packet (
    struct GameLayer2DData * pData,
    int clientI
) 

Parameters:

  • pData The Game2dLayer
  • clientI The client index to send to - only relevant if you're the server

function G2D_Extend_RequestLevelDataMessage

extend the packet that the client sends to request level data from the server. By default tile maps and serialized entities are included, this callback is called before this Game2DLayer managed level data is serialized - see WfNetwork.c

void G2D_Extend_RequestLevelDataMessage (
    PacketExtensionNoArgsFn fn
) 

Parameters:

  • fn callback to call

function G2D_FindEntityWithNetID

try to find the entity with a given net ID

struct Entity2D * G2D_FindEntityWithNetID (
    struct Entity2DCollection * pCollection,
    int netID
) 

Parameters:

  • pCollection collection to search
  • netID netID to search for

Returns:

NULL if not found


function G2D_IsClientConnected

call from the game thread if you're the server to determine if a client is connected

bool G2D_IsClientConnected (
    int i
) 

Parameters:

  • i

Returns:


function G2D_ParsePacket

enum G2DPacketType G2D_ParsePacket (
    u8 * pPacket,
    u8 ** pOutBody,
    int * outHeaderSize
) 

function G2D_ParseRPCPacket

enum Game2DRPCType G2D_ParseRPCPacket (
    u8 * packet,
    u8 ** pOutBody
) 

Parameters:

  • packet
  • pOutBody

function G2D_PollNetworkQueueClient

void G2D_PollNetworkQueueClient (
    struct GameFrameworkLayer * pLayer,
    float deltaT
) 

function G2D_PollNetworkQueueServer

void G2D_PollNetworkQueueServer (
    struct GameFrameworkLayer * pLayer,
    float deltaT
) 

function G2D_RegisterUserRPC

Register a user RPC, call once at startup, call in order your games rpc types appear in the enum.

void G2D_RegisterUserRPC (
    struct UserGame2DRPC * rpc
) 

Parameters:

  • rpc

function G2D_SendRPC

Send an RPC.

void G2D_SendRPC (
    int client,
    enum Game2DRPCType type,
    void * pRPCData
) 

Parameters:

  • client client to send to - send -1 if you're a client yourself
  • type type of rpc to send
  • pRPCData a struct appropriate to construct the rpc message - see src


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