Skip to content

Commit

Permalink
player's gamestate structure holds uint64_t z for their reconciliatio…
Browse files Browse the repository at this point in the history
…n or prediction tick. Server will pack tick and send it to each player's state
  • Loading branch information
irelia committed Jun 27, 2024
1 parent e4eec9c commit 04fb014
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
10 changes: 10 additions & 0 deletions client/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,22 @@ void on_recv(uv_udp_t* handle, ssize_t nread, const uv_buf_t* rcvbuf,
memcpy(&gstate, rcvbuf->base, sizeof(struct GamestateClient));
cvector_push_back(gamestates, gstate);
uint32_t t = kGetTick(gstate.players[0].x);

if(g_starttick == 0&&g_serverbasetick==0){
g_starttick = g_tick;
g_serverbasetick = t;
}
for(int n = 0; n < kMaxNumberOfPlayers;++n){
uint32_t id = kGetPlayerId(gstate.players[n].x);


//this is each client's predicted or reconciliation tick sent to the server during update
//this tick will be used to check the map or container of the [tick][position]
//If the player's predicted position with their tick matches the server position with tick
//then no reconciliation needs to be done

uint32_t predictedtick = kGetPredictionTick(gstate.players[n].z);
//printf("%u\n",predictedtick);
}
// printf("Got state\n");
// printf("%u\t%u\n",
Expand Down
2 changes: 1 addition & 1 deletion server/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ void GameUpdate(uv_udp_t* udphandle) {
g_servergamestate.tick);
kPackPlayerPosition(gstateclient.players[n].y,
player->player.position);

kPackPlayerPredictonTick(gstateclient.players[n].z,player->playertick);
if (player->player.position.x >= 2832.f) {
g_servergamestate.gamestarted = 0;
for (uint32_t n = 0; n < kMaxNumberOfPlayers; ++n) {
Expand Down
5 changes: 5 additions & 0 deletions shared/gameshared.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,18 @@ enum EFlappyPacketId {
#define kPackPlayerWinner(x,y)\
(x = ( (uint64_t)y << 48) | (uint16_t)kEFlappyPacketWinner )

#define kPackPlayerPredictonTick(x,y)\
(x = ( (uint64_t)y << 32 ))

#define kGetPlayerId(x) ( (x >> 48) & 0xFFFF )
#define kGetInput(x) ( (x >> 48) & 0xFFFF )
#define kGetTick(x) ( (x >> 16) & 0xFFFFFFFF )
#define kGetPacketId(x) ( x & 0xFFFF )
#define kGetPredictionTick(x) (x >> 32 &0xFFFFFFFF)
struct PlayerState {
uint64_t x;
uint64_t y;
uint64_t z;
};
struct GamestateClient {
struct PlayerState players[kMaxNumberOfPlayers];
Expand Down

0 comments on commit 04fb014

Please sign in to comment.