add pkt_send_code + system changes

efd/v1
Dominik Madarász 2023-02-03 09:54:16 +01:00
parent 3e4814222e
commit 94c49e770b
12 changed files with 75 additions and 3 deletions

View File

@ -2,6 +2,7 @@
#include "platform/system.h"
#include "world/world_view.h"
#include "packets/pkt_send_keystate.h"
#include "packets/pkt_send_code.h"
typedef enum {
GAMEKIND_SINGLE,
@ -25,6 +26,7 @@ void game_update();
void game_render();
void game_player_joined(uint64_t ent);
void game_player_departed(uint64_t ent);
void game_client_receive_code(pkt_send_code data);
// base methods called from games
void game_core_input();

View File

@ -0,0 +1,28 @@
#include "packets/pkt_send_code.h"
#include "pkt/packet.h"
#include "world/world.h"
#include "core/game.h"
#include "world/entity_view.h"
#include "models/components.h"
#include "systems/systems.h"
pkt_desc pkt_send_code_desc[] = {
{ PKT_UINT(pkt_send_code, code) },
{ PKT_ARRAY(pkt_send_code, params) },
{ PKT_ARRAY(pkt_send_code, data) },
{ PKT_END },
};
size_t pkt_code_send(uint64_t peer_id, uint16_t view_id, pkt_send_code table) {
return pkt_world_write(MSG_ID_SEND_CODE, pkt_table_encode(pkt_send_code_desc, PKT_STRUCT_PTR(&table)), 1, view_id, (void*)peer_id, 0);
}
int32_t pkt_send_code_handler(pkt_header *header) {
pkt_send_code table = { 0 };
PKT_IF(pkt_msg_decode(header, pkt_send_code_desc, pkt_pack_desc_args(pkt_send_code_desc), PKT_STRUCT_PTR(&table)));
game_client_receive_code(table);
return 0;
}

View File

@ -0,0 +1,15 @@
#pragma once
#include "platform/system.h"
#include "pkt/packet_utils.h"
typedef struct {
uint64_t code;
uint32_t params[4];
char data[128];
} pkt_send_code;
size_t pkt_code_send(uint64_t peer_id, uint16_t view_id, pkt_send_code code_data);
extern pkt_desc pkt_send_code_desc[];
PKT_HANDLER_PROC(pkt_send_code_handler);

View File

@ -3,8 +3,6 @@
#include "world/world.h"
#include "core/game.h"
#include "world/entity_view.h"
#include "core/camera.h"
#include "models/prefabs/player.h"
#include "models/components.h"
#include "systems/systems.h"

View File

@ -9,6 +9,7 @@
#include "packets/pkt_send_keystate.h"
#include "packets/pkt_send_librg_update.h"
#include "packets/pkt_send_notif.h"
#include "packets/pkt_send_code.h"
#include "packets/pkt_switch_viewer.h"
#define PKT_HEADER_ELEMENTS 3
@ -21,6 +22,7 @@ pkt_handler pkt_handlers[] = {
{.id = MSG_ID_SEND_BLOCKPOS, .handler = pkt_send_blockpos_handler},
{.id = MSG_ID_SWITCH_VIEWER, .handler = pkt_switch_viewer_handler},
{.id = MSG_ID_SEND_NOTIFICATION, .handler = pkt_send_notification_handler},
{.id = MSG_ID_SEND_CODE, .handler = pkt_send_code_handler},
};
uint8_t pkt_buffer[PKT_BUFSIZ];

View File

@ -11,6 +11,7 @@ typedef enum {
MSG_ID_SEND_BLOCKPOS,
MSG_ID_SWITCH_VIEWER,
MSG_ID_SEND_NOTIFICATION,
MSG_ID_SEND_CODE,
MSG_NEXT_FREE_ID,
MAX_PACKETS = 256,
} pkt_messages;

View File

@ -53,6 +53,7 @@ void OnDead(ecs_iter_t *it) {
}
if (pi) {
*pi = (Input) { 0 };
pi->is_blocked = 1;
}
}

View File

@ -19,4 +19,8 @@ void game_player_joined(uint64_t ent) {
void game_player_departed(uint64_t ent) {
}
void game_client_receive_code(pkt_send_code data) {
}

View File

@ -19,4 +19,8 @@ void game_player_joined(uint64_t ent) {
void game_player_departed(uint64_t ent) {
}
void game_client_receive_code(pkt_send_code data) {
}

View File

@ -57,4 +57,12 @@ void game_player_joined(uint64_t ent) {
void game_player_departed(uint64_t ent) {
}
}
void game_client_receive_code(pkt_send_code data) {
switch (data.code) {
case SURV_CODE_SHOW_NOTIF: {
notification_push("TEST", data.data);
} break;
}
}

View File

@ -1,3 +1,7 @@
#pragma once
enum {
SURV_CODE_SHOW_NOTIF,
};
void game_setup_ecs();

View File

@ -84,5 +84,10 @@ void MobMeleeAtk(ecs_iter_t *it) {
void MobOnDead(ecs_iter_t *it) {
for (int i = 0; i < it->count; i++) {
entity_despawn(it->entities[i]);
pkt_code_send(0, 0, (pkt_send_code){
.code = SURV_CODE_SHOW_NOTIF,
.data = "mob died"
});
}
}