#ifndef GAME_SESSION_H
#define GAME_SESSION_H

#include <stdint.h>
#include <stdbool.h>

#include "shared/squeue.h"

#include "simulation/simulation_world.h"
#include "simulation/input.h"
#include "simulation/player.h"

typedef struct {
    bool active;

    SQueue input_queue;
    Simulation_Game_Input most_recent_input; // Exclusively used to make sure that the input-queue doesn't get filled with duplicated inputs.
} Game_Session_Player;

typedef struct {
    uint32_t seed;

    double tickrate;

    uint16_t level_width;
    uint16_t level_height;

    uint8_t max_players;

    // ..
} Game_Session_Settings;

typedef struct {
    bool is_singleplayer;
    bool is_host;

    Game_Session_Settings settings;

    Simulation_World simulation_world;
    double simulation_accumulator;

    Game_Session_Player *players;
    Game_Session_Player *players_prev;
    uint16_t local_player_index;

    // TODO: SS - Local + remote input-queue.
} Game_Session;

extern Game_Session *g_current_session;

void game_session_create(bool is_singleplayer, bool is_host, Game_Session_Settings settings);
void game_session_destroy();

void game_session_init_default_settings(bool is_singleplayer, Game_Session_Settings *out_settings);

void game_session_update(Game_Session *session, const double delta_time);

Game_Session_Player *game_session_get_local_player(Game_Session *session);

bool game_session_create_player(Game_Session *session, uint16_t *out_player_index);
void game_session_destroy_player(Game_Session *session, uint16_t player_index);

bool game_session_enqueue_player_input(Game_Session *session, uint16_t player_index, Simulation_Game_Input input);


#endif