ecsnet
Loading...
Searching...
No Matches
network_cs.h
1#pragma once
2
3#include "network_architecture.h"
4#include "connection_manager.h"
5#include "protocol_handler.h"
6#include "ecs.h"
7#include "network_map.h"
8#include "networked_entity.h"
9#ifdef __cplusplus
10extern "C" {
11#endif
55
69static inline void network_cs_assign_network_id(network_cs_t* cs, entity_t e, interest_mask_t interest_groups) {
70 if (!cs || !cs->ecs) return;
71 // Only the server generates network IDs. The client leaves next_network_id at 0.
72 uint32_t nid = cs->next_network_id++;
73 networked_entity_t ne = { .network_id = nid, .interest_groups = interest_groups };
74 ecs_add_component(cs->ecs, e, COMPONENT_NETWORKED_ENTITY, &ne);
75}
76
87static inline void network_cs_set_peer_interest(network_cs_t* cs, const char* peer_id, interest_mask_t mask) {
88 if (!cs) return;
89 connection_manager_set_peer_interest(&cs->connection_manager, peer_id, mask);
90}
91
92// callbacks
93
101void on_packet_received_cs(void* user_data, peer_t* peer, const void* data, int len);
102
108void on_peer_connected_cs(void* user_data, peer_t* peer);
109
115void on_peer_disconnected_cs(void* user_data, peer_t* peer);
116
123ECSNET_API network_cs_t* network_cs_init(const network_architecture_config_t* config, ecs_t* ecs);
124
131ECSNET_API void network_cs_update(network_cs_t* network_cs, float dt);
132
137ECSNET_API void network_cs_destroy(network_cs_t* network_cs);
138
150ECSNET_API void network_cs_mark_entity_destroy(network_cs_t* cs, entity_t entity);
151
160ECSNET_API void network_cs_mark_network_id_destroy(network_cs_t* cs, uint32_t network_id);
161
162#ifdef __cplusplus
163}
164#endif
165
Defines the NetworkedEntity component used for network replication.
uint32_t interest_mask_t
Bitmask type for representing interest groups (up to 32 groups).
Definition networked_entity.h:22
Manages all active network connections (peers) for a client or server.
Definition connection_manager.h:74
Internal structure representing the ECS world state. This holds:
Definition ecs_internal.h:44
Structure for configuring the network architecture.
Definition network_architecture.h:24
Represents the client-server network architecture implementation. This struct contains the core compo...
Definition network_cs.h:18
protocol_handler_t protocol_handler
Definition network_cs.h:22
float sync_acc
Definition network_cs.h:23
connection_manager_t connection_manager
Definition network_cs.h:21
network_map_t network_map
Definition network_cs.h:30
ecs_t * ecs
Definition network_cs.h:19
uint32_t next_network_id
Definition network_cs.h:38
network_architecture_config_t config
Definition network_cs.h:20
uint32_t * pending_destroy_ids
Pending destroy list for server‑side entity removal.
Definition network_cs.h:51
Dynamic mapping structure from network IDs to local entity IDs. This map grows dynamically as new net...
Definition network_map.h:22
Component representing network identity and interest groups.
Definition networked_entity.h:31
Represents a connected network peer.
Definition connection_manager.h:45
The protocol handler structure. Manages the state for incoming and outgoing network packets,...
Definition protocol_handler.h:62