File Game2DLayerNetwork.c
FileList > engine > src > gameframework > layers > Game2D > Game2DLayerNetwork.c
Go to the source code of this file
#include <string.h>#include "Game2DLayerNetwork.h"#include "Log.h"#include "Network.h"#include "BinarySerializer.h"#include "AssertLib.h"#include "DynArray.h"#include "Entities.h"#include "Game2DLayer.h"#include "NetworkID.h"#include "GameFramework.h"#include <stdbool.h>
Classes
| Type | Name |
|---|---|
| struct | FindWithNetIdIteratorContext |
| struct | Game2DLayerWorldstatePacketHeader |
| struct | GameThreadClientConnection |
| struct | IsNetIdTakenIteratorContext |
| struct | StateUpdateItr_Ctx |
Public Static Attributes
| Type | Name |
|---|---|
| struct GameThreadClientConnection | gClientsConnections = { {.connected=false}, {.connected=false}, {.connected=false} } |
| struct NetworkQueueItem | gDequeueBuffer |
| PacketExtensionNoArgsFn | gExtendRequestLvlData = NULL |
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_SendRPC (int client, enum Game2DRPCType type, void * pRPCData) Send an RPC. |
| bool | IsNetIDTakenIterator (struct Entity2D * pEnt, int i, void * pUser) |
Public Static Functions
| Type | Name |
|---|---|
| void | ApplyStateUpdate (struct GameLayer2DData * pData, struct BinarySerializer * bs) |
| bool | FindWithNetIDIterator (struct Entity2D * pEnt, int i, void * pUser) |
| bool | G2D_IsNetIDTaken (int netID, struct Entity2DCollection * pCollection) |
| struct NetworkQueueItem * | GetLatestStateUpdate (VECTOR(struct NetworkQueueItem) dequeuedStateUpdates) |
| bool | StateUpdateItr (struct Entity2D * pEnt, int i, void * pUser) |
| static | VECTOR (struct UserGame2DRPC) |
Public Static Attributes Documentation
variable gClientsConnections
struct GameThreadClientConnection gClientsConnections[3];
variable gDequeueBuffer
struct NetworkQueueItem gDequeueBuffer[128];
variable gExtendRequestLvlData
PacketExtensionNoArgsFn gExtendRequestLvlData;
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:
pDatapRPCDataclientthe 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:
pDataThe Game2dLayerclientIThe 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:
fncallback 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:
pCollectioncollection to searchnetIDnetID 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:
packetpOutBody
function G2D_PollNetworkQueueClient
void G2D_PollNetworkQueueClient (
struct GameFrameworkLayer * pLayer,
float deltaT
)
function G2D_PollNetworkQueueServer
void G2D_PollNetworkQueueServer (
struct GameFrameworkLayer * pLayer,
float deltaT
)
function G2D_SendRPC
Send an RPC.
void G2D_SendRPC (
int client,
enum Game2DRPCType type,
void * pRPCData
)
Parameters:
clientclient to send to - send -1 if you're a client yourselftypetype of rpc to sendpRPCDataa struct appropriate to construct the rpc message - see src
function IsNetIDTakenIterator
bool IsNetIDTakenIterator (
struct Entity2D * pEnt,
int i,
void * pUser
)
Public Static Functions Documentation
function ApplyStateUpdate
static void ApplyStateUpdate (
struct GameLayer2DData * pData,
struct BinarySerializer * bs
)
function FindWithNetIDIterator
static bool FindWithNetIDIterator (
struct Entity2D * pEnt,
int i,
void * pUser
)
function G2D_IsNetIDTaken
static bool G2D_IsNetIDTaken (
int netID,
struct Entity2DCollection * pCollection
)
function GetLatestStateUpdate
static struct NetworkQueueItem * GetLatestStateUpdate (
VECTOR(struct NetworkQueueItem ) dequeuedStateUpdates
)
function StateUpdateItr
static bool StateUpdateItr (
struct Entity2D * pEnt,
int i,
void * pUser
)
function VECTOR
static static VECTOR (
struct UserGame2DRPC
)
The documentation for this class was generated from the following file /home/runner/work/2DFarmingRPG/2DFarmingRPG/Stardew/engine/src/gameframework/layers/Game2D/Game2DLayerNetwork.c