Simplify input keystate send

isolation_bkp/dynres
Dominik Madarász 2021-11-01 15:32:46 +01:00
parent 8ab803bb5f
commit c45f95348a
6 changed files with 116 additions and 140 deletions

View File

@ -21,7 +21,6 @@
#include "packets/pkt_00_init.h" #include "packets/pkt_00_init.h"
#include "packets/pkt_01_welcome.h" #include "packets/pkt_01_welcome.h"
#include "packets/pkt_send_keystate.h"
static uint8_t game_mode; static uint8_t game_mode;
@ -225,19 +224,8 @@ void game_render() {
} }
} }
void game_action_send_keystate(float x, void game_action_send_keystate(game_keystate_data *data) {
float y, pkt_send_keystate_send(active_viewer->view_id, data);
float mx,
float my,
uint8_t use,
uint8_t sprint,
uint8_t ctrl,
uint8_t drop,
uint8_t selected_item,
uint8_t swap,
uint8_t swap_from,
uint8_t swap_to) {
pkt_send_keystate_send(active_viewer->view_id, x, y, mx, my, use, sprint, ctrl, drop, selected_item, swap, swap_from, swap_to);
} }
void game_request_close() { void game_request_close() {

View File

@ -1,6 +1,7 @@
#pragma once #pragma once
#include "system.h" #include "system.h"
#include "world_view.h" #include "world_view.h"
#include "packets/pkt_send_keystate.h"
typedef enum { typedef enum {
GAMEKIND_SINGLE, GAMEKIND_SINGLE,
@ -32,15 +33,4 @@ void game_world_view_active_entity_map(void (*map_proc)(uint64_t key, entity_vie
entity_view *game_world_view_active_get_entity(uint64_t ent_id); entity_view *game_world_view_active_get_entity(uint64_t ent_id);
//~ NOTE(zaklaus): viewer -> host actions //~ NOTE(zaklaus): viewer -> host actions
void game_action_send_keystate(float x, void game_action_send_keystate(game_keystate_data *data);
float y,
float mx,
float my,
uint8_t use,
uint8_t sprint,
uint8_t ctrl,
uint8_t drop,
uint8_t selected_item,
uint8_t swap,
uint8_t swap_from,
uint8_t swap_to);

View File

@ -0,0 +1 @@
#pragma once

View File

@ -24,20 +24,8 @@ pkt_desc pkt_send_keystate_desc[] = {
}; };
size_t pkt_send_keystate_send(uint16_t view_id, size_t pkt_send_keystate_send(uint16_t view_id,
float x, game_keystate_data *data) {
float y, return pkt_world_write(MSG_ID_SEND_KEYSTATE, pkt_send_keystate_encode(data), 1, view_id, NULL, 1);
float mx,
float my,
uint8_t use,
uint8_t sprint,
uint8_t ctrl,
uint8_t drop,
uint8_t selected_item,
uint8_t swap,
uint8_t swap_from,
uint8_t swap_to) {
pkt_send_keystate table = { .x = x, .y = y, .mx = mx, .my = my, .use = use, .sprint = sprint, .ctrl = ctrl, .drop = drop, .selected_item = selected_item, .swap = swap, .swap_from = swap_from, .swap_to = swap_to };
return pkt_world_write(MSG_ID_SEND_KEYSTATE, pkt_send_keystate_encode(&table), 1, view_id, NULL, 1);
} }
size_t pkt_send_keystate_encode(pkt_send_keystate *table) { size_t pkt_send_keystate_encode(pkt_send_keystate *table) {

View File

@ -17,19 +17,10 @@ typedef struct {
uint8_t swap_to; uint8_t swap_to;
} pkt_send_keystate; } pkt_send_keystate;
typedef pkt_send_keystate game_keystate_data;
size_t pkt_send_keystate_send(uint16_t view_id, size_t pkt_send_keystate_send(uint16_t view_id,
float x, game_keystate_data *data);
float y,
float mx,
float my,
uint8_t use,
uint8_t sprint,
uint8_t ctrl,
uint8_t drop,
uint8_t selected_item,
uint8_t swap,
uint8_t swap_from,
uint8_t swap_to);
size_t pkt_send_keystate_encode(pkt_send_keystate *table); size_t pkt_send_keystate_encode(pkt_send_keystate *table);
extern pkt_desc pkt_send_keystate_desc[]; extern pkt_desc pkt_send_keystate_desc[];

View File

@ -30,6 +30,8 @@ void platform_init() {
screenWidth = GetScreenWidth(); screenWidth = GetScreenWidth();
screenHeight = GetScreenHeight(); screenHeight = GetScreenHeight();
ToggleFullscreen();
renderer_init(); renderer_init();
} }
@ -88,7 +90,23 @@ void platform_input() {
y = -mouse_pos.y; y = -mouse_pos.y;
} }
game_action_send_keystate(x, y, mouse_pos.x, mouse_pos.y, use, sprint, ctrl, drop, inv_selected_item, inv_swap, inv_swap_from, inv_swap_to); game_keystate_data data = {
.x = x,
.y = y,
.mx = mouse_pos.x,
.my = mouse_pos.y,
.use = use,
.sprint = sprint,
.ctrl = ctrl,
.drop = drop,
.selected_item = inv_selected_item,
.swap = inv_swap,
.swap_from = inv_swap_from,
.swap_to = inv_swap_to,
};
game_action_send_keystate(&data);
} }
// NOTE(zaklaus): cycle through viewers // NOTE(zaklaus): cycle through viewers