Stardew Engine
Loading...
Searching...
No Matches
Network.h File Reference
#include "ThreadSafeQueue.h"
#include "SharedPtr.h"
#include <stdlib.h>
Include dependency graph for Network.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  NetworkQueueItem
 
struct  NetworkConnectionEvent
 
struct  HostInfo
 

Enumerations

enum  NetworkConnectionEventType { NCE_ClientConnected , NCE_ClientDisconnected }
 
enum  GameRole { GR_Singleplayer , GR_Client , GR_ClientServer }
 

Functions

void NW_Init ()
 
bool NW_DequeueData (struct NetworkQueueItem *pOut)
 
bool NW_DequeueConnectionEvent (struct NetworkConnectionEvent *pOut)
 
void NW_EnqueueData (struct NetworkQueueItem *pIn)
 
enum GameRole NW_GetRole ()
 

Detailed Description

  • game can be started with command line args to configure it as a server or a client (or singleplayer)

if server or client is chosen a thread is spawned to recieve date too and from the socket

  • it communicates with the game thread through 3 thread safe queues (named from the game threads perspective):
    • recieve data packets
    • transmit data packets
    • recieve connection events
  • A UDP based custom protocol using the netcode library to handle connecting and disconnecting:
    • data can be sent reliably or unreliably
    • packets larget than NETCODE_MAX_PACKET_SIZE + (a small header) are transmitted as multiple packets and only presented to the game thread when the full message is assembled
    • reliable packets should only be recieved by recipients game thread once
      • they'll be continually resent until reciept is acknowledged

This layer of the networking code ensures the game thread can transmit and recieve reliable and unreliable packets of any size and is informed when a client connects or they as a client is connected to the server or disconnected.

For the time being the game thread must create a shared pointer of the packet to be sent which the server thread will then free. For data received through the queue the game thread must call free() on it when done.

Some better memory usage arrangement needs to be come up with at some point.

Enumeration Type Documentation

◆ GameRole

enum GameRole
Enumerator
GR_Singleplayer 
GR_Client 
GR_ClientServer 

◆ NetworkConnectionEventType

Enumerator
NCE_ClientConnected 
NCE_ClientDisconnected 

Function Documentation

◆ NW_DequeueConnectionEvent()

bool NW_DequeueConnectionEvent ( struct NetworkConnectionEvent pOut)

◆ NW_DequeueData()

bool NW_DequeueData ( struct NetworkQueueItem pOut)

◆ NW_EnqueueData()

void NW_EnqueueData ( struct NetworkQueueItem pIn)

◆ NW_GetRole()

enum GameRole NW_GetRole ( )

◆ NW_Init()

void NW_Init ( )