Skip to content

Commit f6927a4

Browse files
committed
good start
1 parent 88b9099 commit f6927a4

File tree

5 files changed

+37
-15
lines changed

5 files changed

+37
-15
lines changed

GekkoLib/include/backend.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ namespace Gekko {
103103

104104
bool CheckStatusActors();
105105

106-
void SendHealthCheck(Frame frame, u32 checksum);
106+
void SendSessionHealth(Frame frame, u32 checksum);
107107

108108
public:
109109
std::vector<std::unique_ptr<Player>> locals;
@@ -149,7 +149,9 @@ namespace Gekko {
149149

150150
void OnInputAck(NetAddress& addr, NetPacket& pkt);
151151

152-
void OnHealthCheck(NetAddress& addr, NetPacket& pkt);
152+
void OnSessionHealth(NetAddress& addr, NetPacket& pkt);
153+
154+
void OnNetworkHealth(NetAddress& addr, NetPacket& pkt);
153155

154156
private:
155157
const u32 MAX_PLAYER_SEND_SIZE = 32;

GekkoLib/include/net.h

+13-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ namespace Gekko {
3131
InputAck,
3232
SyncRequest,
3333
SyncResponse,
34-
HealthCheck,
34+
SessionHealth,
35+
NetworkHealth
3536
};
3637

3738
struct MsgHeader {
@@ -88,7 +89,17 @@ namespace Gekko {
8889
}
8990
};
9091

91-
struct HealthCheckMsg : MsgBody {
92+
struct SessionHealthMsg : MsgBody {
93+
Frame frame;
94+
u32 checksum;
95+
96+
template <typename Archive, typename Self>
97+
static void serialize(Archive& a, Self& s) {
98+
a(s.frame, s.checksum);
99+
}
100+
};
101+
102+
struct NetworkHealthMsg : MsgBody {
92103
Frame frame;
93104
u32 checksum;
94105

GekkoLib/src/backend.cpp

+18-9
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ namespace
1414
zpp::serializer::make_type<Gekko::SyncMsg, zpp::serializer::make_id("Gekko::SyncMsg")>,
1515
zpp::serializer::make_type<Gekko::InputMsg, zpp::serializer::make_id("Gekko::InputMsg")>,
1616
zpp::serializer::make_type<Gekko::InputAckMsg, zpp::serializer::make_id("Gekko::InputAckMsg")>,
17-
zpp::serializer::make_type<Gekko::HealthCheckMsg, zpp::serializer::make_id("Gekko::HealthCheckMsg")>
17+
zpp::serializer::make_type<Gekko::SessionHealthMsg, zpp::serializer::make_id("Gekko::SessionHealthMsg")>,
18+
zpp::serializer::make_type<Gekko::NetworkHealthMsg, zpp::serializer::make_id("Gekko::NetworkHealthMsg")>
1819
> _;
1920
}
2021

@@ -105,7 +106,7 @@ void Gekko::MessageSystem::SendPendingOutput(GekkoNetAdapter* host)
105106
SendDataToAll(pkt.get(), host, true);
106107
}
107108
}
108-
else if (pkt->pkt.header.type == HealthCheck) {
109+
else if (pkt->pkt.header.type == SessionHealth) {
109110
// send to remotes
110111
SendDataToAll(pkt.get(), host);
111112
// send to spectators
@@ -287,15 +288,15 @@ bool Gekko::MessageSystem::CheckStatusActors()
287288
return result == 0;
288289
}
289290

290-
void Gekko::MessageSystem::SendHealthCheck(Frame frame, u32 checksum)
291+
void Gekko::MessageSystem::SendSessionHealth(Frame frame, u32 checksum)
291292
{
292293
_pending_output.push(std::make_unique<NetData>());
293294
auto& message = _pending_output.back();
294295

295296
// the address and magic is set later so dont worry about it now
296-
message->pkt.header.type = HealthCheck;
297+
message->pkt.header.type = SessionHealth;
297298

298-
auto body = std::make_unique<HealthCheckMsg>();
299+
auto body = std::make_unique<SessionHealthMsg>();
299300
body->frame = frame;
300301
body->checksum = checksum;
301302

@@ -453,8 +454,11 @@ void Gekko::MessageSystem::ParsePacket(NetAddress& addr, NetPacket& pkt)
453454
case InputAck:
454455
OnInputAck(addr, pkt);
455456
return;
456-
case HealthCheck:
457-
OnHealthCheck(addr, pkt);
457+
case SessionHealth:
458+
OnSessionHealth(addr, pkt);
459+
return;
460+
case NetworkHealth:
461+
OnNetworkHealth(addr, pkt);
458462
return;
459463
default:
460464
printf("cannot process an unknown event!\n");
@@ -592,9 +596,9 @@ void Gekko::MessageSystem::OnInputAck(NetAddress& addr, NetPacket& pkt)
592596
}
593597
}
594598

595-
void Gekko::MessageSystem::OnHealthCheck(NetAddress& addr, NetPacket& pkt)
599+
void Gekko::MessageSystem::OnSessionHealth(NetAddress& addr, NetPacket& pkt)
596600
{
597-
auto body = (HealthCheckMsg*)pkt.body.get();
601+
auto body = (SessionHealthMsg*)pkt.body.get();
598602

599603
const Frame frame = body->frame;
600604
const u32 checksum = body->checksum;
@@ -616,6 +620,11 @@ void Gekko::MessageSystem::OnHealthCheck(NetAddress& addr, NetPacket& pkt)
616620
}
617621
}
618622

623+
void Gekko::MessageSystem::OnNetworkHealth(NetAddress& addr, NetPacket& pkt)
624+
{
625+
// TODO
626+
}
627+
619628
void Gekko::MessageSystem::AddPendingInput(bool spectator)
620629
{
621630
u64 now = TimeSinceEpoch();

GekkoLib/src/gekko.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ void Gekko::Session::SendHealthCheck()
282282

283283
_msg.local_health[confirmed] = sav->checksum;
284284

285-
_msg.SendHealthCheck(confirmed, sav->checksum);
285+
_msg.SendSessionHealth(confirmed, sav->checksum);
286286

287287
for (auto iter = _msg.local_health.begin();
288288
iter != _msg.local_health.end(); ) {

GekkoLib/src/gekkonet.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ static GekkoNetResult** asio_receive(int* length) {
110110
while (true) {
111111
const u32 len = (u32)_socket->receive_from(asio::buffer(_buffer), _remote, 0, _ec);
112112
if (_ec && _ec != asio::error::would_block) {
113-
std::cout << "receive failed: " << _ec.message() << std::endl;
113+
// std::cout << "receive failed: " << _ec.message() << std::endl;
114114
continue;
115115
}
116116
else if (!_ec) {

0 commit comments

Comments
 (0)