#ifndef PLAYER_H
#define PLAYER_H
#include "platform.h"
#define QUEUE_SIZE 32
#define MAX_INPUTS 256
typedef enum {
EVENT_CHAR, // chars
EVENT_BUTTON, // named button press
EVENT_JOYSTICK, // joystick with x/y
EVENT_TEXT, // strings
EVENT_TOUCH, // screen interaction
EVENT_COMMAND // arbitrary command
} EventType;
typedef struct {
EventType type;
union {
char ch;
struct { char button; int pressed; } button;
struct { float x, y; } joystick;
struct { char text[64]; } typed;
struct { float x, y; int down; } touch;
struct { char name[32]; } command;
};
} Event;
typedef struct {
Event events[QUEUE_SIZE];
int head;
int tail;
mutex_t lock;
} EventQueue;
typedef struct {
char current[MAX_INPUTS];
char previous[MAX_INPUTS];
float joy_x, joy_y;
float touch_x, touch_y;
int touch_down;
} InputState;
typedef struct {
EventQueue queue;
InputState inputs;
char last_message[64];
SOCKET_TYPE sock;
int connected;
} Player;
void queue_init(EventQueue* q);
int queue_push(EventQueue* q, Event e);
int queue_pop(EventQueue* q, Event* e_out);
void queue_destroy(EventQueue* q);
Event parse_event(char msg[128]);
void print_event(int player_id, const Event* ev);
#endif