#ifndef GAME_INSTANCE_H
#define GAME_INSTANCE_H

#include <stdint.h>

#include "session/networking.h"
#include "session/game_session.h"

#include "shared/squeue.h"

#define MAX_LOCAL_PLAYERS 4
#define MAX_INPUTS_IN_QUEUE_PER_LOCAL_PLAYER 4

typedef struct {
    uint16_t player_id;
    SQueue input_queue;
} Locally_Controlled_Player;

typedef struct {
    Locally_Controlled_Player locally_controlled_players[MAX_LOCAL_PLAYERS];
    uint8_t amount_of_local_players;

    double simulation_accumulator;
    
    Game_Networking game_networking;
    Game_Session *game_session;
} Game_Instance;

void game_instance_init(Game_Instance *instance);
void game_instance_dispose(Game_Instance *instance);

bool game_instance_host_session(Game_Instance *instance, const Game_Session_Settings settings);
bool game_instance_join_session(Game_Instance *instance, const char *session_id);
void game_instance_stop_session(Game_Instance *instance);

void game_instance_clear_local_players(Game_Instance *instance);
bool game_instance_setup_local_player(Game_Instance *instance, uint16_t player_id);

bool game_instance_push_local_input(Game_Instance *instance, uint8_t local_player_index, Simulation_Game_Input input);
bool game_instance_pop_local_input(Game_Instance *instance, uint8_t local_player_index, Simulation_Game_Input *out_input);

#endif