second commit
This commit is contained in:
@@ -24,6 +24,25 @@ struct NetUpdate {
|
||||
NetState state;
|
||||
};
|
||||
|
||||
// A shockwave explosion. Every machine applies the launch to its own player, since remote
|
||||
// players are only puppets here. Blasts are re-sent a few times (UDP) and de-duplicated on receive.
|
||||
struct NetBlast {
|
||||
uint8_t sender = 0; // filled in by the host; ignored on send
|
||||
uint32_t id = 0; // filled in by SendBlast
|
||||
glm::vec3 center = glm::vec3(0.0f);
|
||||
float radius = 0.0f;
|
||||
float power = 0.0f;
|
||||
};
|
||||
|
||||
// Damage dealt to another player. Each machine owns its own player's health, so the shooter
|
||||
// aims locally and sends this to the victim, who applies it. Re-sent a few times and de-duplicated.
|
||||
struct NetHit {
|
||||
uint8_t sender = 0; // filled in by the host
|
||||
uint32_t id = 0; // filled in by SendHit
|
||||
int damage = 0;
|
||||
glm::vec3 knockback = glm::vec3(0.0f); // added to the victim's velocity
|
||||
};
|
||||
|
||||
class Lan {
|
||||
public:
|
||||
enum class Mode { Off, Host, Client };
|
||||
@@ -44,7 +63,14 @@ public:
|
||||
// Call once per frame with our own state.
|
||||
void Send(const NetState& state);
|
||||
// Drains all waiting packets and appends the other players' newest states to 'out'.
|
||||
void Receive(std::vector<NetUpdate>& 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).
|
||||
void Receive(std::vector<NetUpdate>& out, std::vector<NetBlast>* blasts = nullptr,
|
||||
std::vector<NetHit>* hits = nullptr);
|
||||
// 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.
|
||||
void SendBlast(const NetBlast& blast);
|
||||
|
||||
// Host: at least one player has joined. Client: the host has been heard from in the last 2 s.
|
||||
bool IsConnected() const;
|
||||
|
||||
Reference in New Issue
Block a user