add pkt_send_code + system changes
parent
3e4814222e
commit
94c49e770b
|
@ -2,6 +2,7 @@
|
||||||
#include "platform/system.h"
|
#include "platform/system.h"
|
||||||
#include "world/world_view.h"
|
#include "world/world_view.h"
|
||||||
#include "packets/pkt_send_keystate.h"
|
#include "packets/pkt_send_keystate.h"
|
||||||
|
#include "packets/pkt_send_code.h"
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
GAMEKIND_SINGLE,
|
GAMEKIND_SINGLE,
|
||||||
|
@ -25,6 +26,7 @@ void game_update();
|
||||||
void game_render();
|
void game_render();
|
||||||
void game_player_joined(uint64_t ent);
|
void game_player_joined(uint64_t ent);
|
||||||
void game_player_departed(uint64_t ent);
|
void game_player_departed(uint64_t ent);
|
||||||
|
void game_client_receive_code(pkt_send_code data);
|
||||||
|
|
||||||
// base methods called from games
|
// base methods called from games
|
||||||
void game_core_input();
|
void game_core_input();
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
|
@ -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);
|
||||||
|
|
|
@ -3,8 +3,6 @@
|
||||||
#include "world/world.h"
|
#include "world/world.h"
|
||||||
#include "core/game.h"
|
#include "core/game.h"
|
||||||
#include "world/entity_view.h"
|
#include "world/entity_view.h"
|
||||||
#include "core/camera.h"
|
|
||||||
#include "models/prefabs/player.h"
|
|
||||||
|
|
||||||
#include "models/components.h"
|
#include "models/components.h"
|
||||||
#include "systems/systems.h"
|
#include "systems/systems.h"
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include "packets/pkt_send_keystate.h"
|
#include "packets/pkt_send_keystate.h"
|
||||||
#include "packets/pkt_send_librg_update.h"
|
#include "packets/pkt_send_librg_update.h"
|
||||||
#include "packets/pkt_send_notif.h"
|
#include "packets/pkt_send_notif.h"
|
||||||
|
#include "packets/pkt_send_code.h"
|
||||||
#include "packets/pkt_switch_viewer.h"
|
#include "packets/pkt_switch_viewer.h"
|
||||||
|
|
||||||
#define PKT_HEADER_ELEMENTS 3
|
#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_SEND_BLOCKPOS, .handler = pkt_send_blockpos_handler},
|
||||||
{.id = MSG_ID_SWITCH_VIEWER, .handler = pkt_switch_viewer_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_NOTIFICATION, .handler = pkt_send_notification_handler},
|
||||||
|
{.id = MSG_ID_SEND_CODE, .handler = pkt_send_code_handler},
|
||||||
};
|
};
|
||||||
|
|
||||||
uint8_t pkt_buffer[PKT_BUFSIZ];
|
uint8_t pkt_buffer[PKT_BUFSIZ];
|
||||||
|
|
|
@ -11,6 +11,7 @@ typedef enum {
|
||||||
MSG_ID_SEND_BLOCKPOS,
|
MSG_ID_SEND_BLOCKPOS,
|
||||||
MSG_ID_SWITCH_VIEWER,
|
MSG_ID_SWITCH_VIEWER,
|
||||||
MSG_ID_SEND_NOTIFICATION,
|
MSG_ID_SEND_NOTIFICATION,
|
||||||
|
MSG_ID_SEND_CODE,
|
||||||
MSG_NEXT_FREE_ID,
|
MSG_NEXT_FREE_ID,
|
||||||
MAX_PACKETS = 256,
|
MAX_PACKETS = 256,
|
||||||
} pkt_messages;
|
} pkt_messages;
|
||||||
|
|
|
@ -53,6 +53,7 @@ void OnDead(ecs_iter_t *it) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pi) {
|
if (pi) {
|
||||||
|
*pi = (Input) { 0 };
|
||||||
pi->is_blocked = 1;
|
pi->is_blocked = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,3 +20,7 @@ void game_player_joined(uint64_t ent) {
|
||||||
void game_player_departed(uint64_t ent) {
|
void game_player_departed(uint64_t ent) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void game_client_receive_code(pkt_send_code data) {
|
||||||
|
|
||||||
|
}
|
|
@ -20,3 +20,7 @@ void game_player_joined(uint64_t ent) {
|
||||||
void game_player_departed(uint64_t ent) {
|
void game_player_departed(uint64_t ent) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void game_client_receive_code(pkt_send_code data) {
|
||||||
|
|
||||||
|
}
|
|
@ -58,3 +58,11 @@ void game_player_joined(uint64_t ent) {
|
||||||
void game_player_departed(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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
enum {
|
||||||
|
SURV_CODE_SHOW_NOTIF,
|
||||||
|
};
|
||||||
|
|
||||||
void game_setup_ecs();
|
void game_setup_ecs();
|
||||||
|
|
|
@ -84,5 +84,10 @@ void MobMeleeAtk(ecs_iter_t *it) {
|
||||||
void MobOnDead(ecs_iter_t *it) {
|
void MobOnDead(ecs_iter_t *it) {
|
||||||
for (int i = 0; i < it->count; i++) {
|
for (int i = 0; i < it->count; i++) {
|
||||||
entity_despawn(it->entities[i]);
|
entity_despawn(it->entities[i]);
|
||||||
|
|
||||||
|
pkt_code_send(0, 0, (pkt_send_code){
|
||||||
|
.code = SURV_CODE_SHOW_NOTIF,
|
||||||
|
.data = "mob died"
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue