group2 0.1.0
CSE 125 Group 2
Loading...
Searching...
No Matches
Client.hpp
Go to the documentation of this file.
1
3
4#pragma once
5
10
11#include <SDL3/SDL_stdinc.h>
12
13#include <SDL3_net/SDL_net.h>
14#include <entt/entt.hpp>
15#include <optional>
16
18class Client
19{
20public:
21 using LocalPlayerReadyFn = std::function<void(entt::entity localEntity)>;
22
27 bool init(const char* addr, Uint16 port);
28
30 void shutdown();
31
36 bool send(const void* data, uint32_t size);
37
38 bool sendInputSnapshot(const InputSnapshot& snap);
39
40 void onLocalPlayerReady(LocalPlayerReadyFn fn) { localPlayerReadyFn = std::move(fn); }
41
44 bool poll(Registry& registry);
45
46private:
47 MessageStream msgStream{nullptr};
48 NET_Address* serverAddr = nullptr;
49 std::optional<registry_serialization::Loader> registryLoader;
50 LocalPlayerReadyFn localPlayerReadyFn;
51 std::optional<entt::entity> localPlayerEntity;
52 bool localPlayerReadyNotified = false;
53};
Per-tick player input snapshot for networking and prediction.
Length-prefixed message framing layer over a TCP stream socket.
Shared ECS registry type alias for the game engine.
entt::registry Registry
Shared ECS registry type alias.
Definition Registry.hpp:11
TCP stream client — sends input to the server and receives state updates.
Definition Client.hpp:19
bool init(const char *addr, Uint16 port)
Create the TCP socket and connect to the server.
Definition Client.cpp:14
std::function< void(entt::entity localEntity)> LocalPlayerReadyFn
Definition Client.hpp:21
void onLocalPlayerReady(LocalPlayerReadyFn fn)
Definition Client.hpp:40
void shutdown()
Close the socket and release the resolved address.
Definition Client.cpp:41
bool sendInputSnapshot(const InputSnapshot &snap)
Definition Client.cpp:59
bool send(const void *data, uint32_t size)
Send a raw message to the server.
Definition Client.cpp:54
bool poll(Registry &registry)
Receive and process one pending message.
Definition Client.cpp:67
Length-prefixed framing layer over a TCP stream socket.
Definition MessageStream.hpp:19
One tick of player input, stamped with the tick it was sampled on.
Definition InputSnapshot.hpp:17