bigger commits
This commit is contained in:
@@ -43,6 +43,21 @@ struct NetHit {
|
||||
glm::vec3 knockback = glm::vec3(0.0f); // added to the victim's velocity
|
||||
};
|
||||
|
||||
// A physics cube owned by the host. The host simulates every cube and streams their poses to the
|
||||
// clients, which only draw them. The host also decides when a cube despawns.
|
||||
struct NetCube {
|
||||
uint32_t id = 0;
|
||||
glm::vec3 position = glm::vec3(0.0f);
|
||||
glm::quat rotation = glm::quat(1.0f, 0.0f, 0.0f, 0.0f);
|
||||
};
|
||||
|
||||
// A client asking the host to spawn a cube. Re-sent a few times (UDP) and de-duplicated by the host.
|
||||
struct NetCubeRequest {
|
||||
uint8_t sender = 0; // filled in by the host
|
||||
uint32_t id = 0;
|
||||
glm::vec3 position = glm::vec3(0.0f);
|
||||
};
|
||||
|
||||
class Lan {
|
||||
public:
|
||||
enum class Mode { Off, Host, Client };
|
||||
@@ -65,8 +80,16 @@ public:
|
||||
// Drains all waiting packets and appends the other players' newest states to 'out'.
|
||||
// If 'blasts' is given, new (de-duplicated) shockwave blasts from other players are appended to it.
|
||||
// 'hits' gets damage aimed at us (de-duplicated).
|
||||
// 'spawns' (host only) gets cube spawn requests from clients; 'cubes' (client only) gets the
|
||||
// host's cube poses.
|
||||
void Receive(std::vector<NetUpdate>& out, std::vector<NetBlast>* blasts = nullptr,
|
||||
std::vector<NetHit>* hits = nullptr);
|
||||
std::vector<NetHit>* hits = nullptr, std::vector<NetCubeRequest>* spawns = nullptr,
|
||||
std::vector<NetCube>* cubes = nullptr);
|
||||
// Client: ask the host to spawn a cube at 'position'. Sent over the next few Send() calls.
|
||||
void SendCubeSpawn(const glm::vec3& position);
|
||||
// Host: stream cube poses to every client. Call once per frame; large sets go out in rotating
|
||||
// slices, so a cube is refreshed every few frames.
|
||||
void SendCubes(const std::vector<NetCube>& cubes);
|
||||
// Damage another player. 'target' is the id from their NetUpdate (the host is 0).
|
||||
void SendHit(uint8_t target, const NetHit& hit);
|
||||
// Tell the other players about a blast we caused. Sent over the next few Send() calls.
|
||||
|
||||
Reference in New Issue
Block a user