<commit_before>#include <stdlib.h>
#include <math.h>
#include <SDL.h>
#include "controller/keyboard.h"
#include "controller/joystick.h"
#include "controller/rec_controller.h"
#include "utils/log.h"
#include "utils/miscmath.h"
#include "game/utils/serial.h"
#include "resources/ids.h"
#include "resources/pilots.h"
#include "console/console.h"
#include "video/video.h"
#include "video/tcache.h"
#include "formats/rec.h"
#include "formats/error.h"
#include "game/game_state.h"
#include "game/common_defines.h"
#include "game/utils/settings.h"
#include "game/utils/ticktimer.h"
#include "game/protos/scene.h"
#include "game/protos/object.h"
#include "game/protos/intersect.h"
#include "game/scenes/intro.h"
#include "game/scenes/mainmenu.h"
#include "game/scenes/credits.h"
#include "game/scenes/cutscene.h"
#include "game/scenes/arena.h"
#include "game/scenes/mechlab.h"
#include "game/scenes/newsroom.h"
#include "game/scenes/melee.h"
#include "game/scenes/vs.h"
#include "game/scenes/scoreboard.h"
#include "game/scenes/openomf.h"

#define MS_PER_OMF_TICK 10
#define MS_PER_OMF_TICK_SLOWEST 60

enum {
    TICK_DYNAMIC = 0,
    TICK_STATIC,
};

void _setup_rec_controller(game_state *gs, int player_id, sd_rec_file *rec);

// How long the scene waits after order to move to another scene
// Used for crossfades
#define FRAME_WAIT_TICKS 30

typedef struct {
    int layer; ///< Object rendering layer
    int persistent; ///< 1 if the object should keep alive across scene boundaries
    int singleton; ///< 1 if object should be the only representative of its animation ID
    object *obj;
} render_obj;

int game_state_create(game_state *gs, engine_init_flags *init_flags) {
    gs->run = 1;
    gs->paused = 0;
    gs->tick = 0;
    gs->int_tick = 0;
    gs->role = ROLE_CLIENT;
    gs->next_requires_refresh = 0;
    gs->net_mode = init_flags->net_mode;
    gs->speed = settings_get()->gameplay.speed + 5;
    gs->init_flags = init_flags;
    vector_create(&gs->objects, sizeof(render_obj));

    // For screen shake
    gs->screen_shake_horizontal = 0;
    gs->screen_shake_vertical = 0;

    // For momentary game speed switches
    gs->speed_slowdown_previous = 0;
    gs->speed_slowdown_time = -1;

    // Used for crossfades
    gs->next_wait_ticks = 0;
    gs->this_wait_ticks = 0;

    // Set up players
    gs->sc = malloc(sizeof(scene));
    for(int i = 0; i < 2; i++) {
        gs->players[i] = malloc(sizeof(game_player));
        game_player_create(gs->players[i]);
    }

    reconfigure_controller(gs);
    int nscene;
    if (strlen(init_flags->rec_file) > 0 && init_flags->record == 0) {
        sd_rec_file rec;
        sd_rec_create(&rec);
        int ret = sd_rec_load(&rec, init_flags->rec_file);
        if(ret != SD_SUCCESS) {
            PERROR("Unable to load recording %s.", init_flags->rec_file);
            goto error_0;
        }

        // hardcode arena 0 for now, although the arena ID resides in field 'L' of the REC file
        nscene = SCENE_ARENA0;
        DEBUG("playing recording file %s", init_flags->rec_file);
        if(scene_create(gs->sc, gs, nscene)) {
            PERROR("Error while loading scene %d.", nscene);
            goto error_0;
        }

        // set the HAR colors, pilot, har type
        for(int i = 0; i < 2; i++) {
            gs->players[i]->colors[0] = rec.pilots[i].info.color_3;
            gs->players[i]->colors[1] = rec.pilots[i].info.color_2;
            gs->players[i]->colors[2] = rec.pilots[i].info.color_1;
            gs->players[i]->har_id = HAR_JAGUAR + rec.pilots[i].info.har_id;
            gs->players[i]->pilot_id = rec.pilots[i].info.pilot_id;
        }

        // XXX use playback controller once it exista
        _setup_rec_controller(gs, 0, &rec);
        _setup_rec_controller(gs, 1, &rec);
        if(arena_create(gs->sc)) {
            PERROR("Error while creating arena scene.");
            goto error_1;
        }
    } else {<commit_msg>game: Load arena specified in rec file<commit_after>#include <stdlib.h>
#include <math.h>
#include <SDL.h>
#include "controller/keyboard.h"
#include "controller/joystick.h"
#include "controller/rec_controller.h"
#include "utils/log.h"
#include "utils/miscmath.h"
#include "game/utils/serial.h"
#include "resources/ids.h"
#include "resources/pilots.h"
#include "console/console.h"
#include "video/video.h"
#include "video/tcache.h"
#include "formats/rec.h"
#include "formats/error.h"
#include "game/game_state.h"
#include "game/common_defines.h"
#include "game/utils/settings.h"
#include "game/utils/ticktimer.h"
#include "game/protos/scene.h"
#include "game/protos/object.h"
#include "game/protos/intersect.h"
#include "game/scenes/intro.h"
#include "game/scenes/mainmenu.h"
#include "game/scenes/credits.h"
#include "game/scenes/cutscene.h"
#include "game/scenes/arena.h"
#include "game/scenes/mechlab.h"
#include "game/scenes/newsroom.h"
#include "game/scenes/melee.h"
#include "game/scenes/vs.h"
#include "game/scenes/scoreboard.h"
#include "game/scenes/openomf.h"

#define MS_PER_OMF_TICK 10
#define MS_PER_OMF_TICK_SLOWEST 60

enum {
    TICK_DYNAMIC = 0,
    TICK_STATIC,
};

void _setup_rec_controller(game_state *gs, int player_id, sd_rec_file *rec);

// How long the scene waits after order to move to another scene
// Used for crossfades
#define FRAME_WAIT_TICKS 30

typedef struct {
    int layer; ///< Object rendering layer
    int persistent; ///< 1 if the object should keep alive across scene boundaries
    int singleton; ///< 1 if object should be the only representative of its animation ID
    object *obj;
} render_obj;

int game_state_create(game_state *gs, engine_init_flags *init_flags) {
    gs->run = 1;
    gs->paused = 0;
    gs->tick = 0;
    gs->int_tick = 0;
    gs->role = ROLE_CLIENT;
    gs->next_requires_refresh = 0;
    gs->net_mode = init_flags->net_mode;
    gs->speed = settings_get()->gameplay.speed + 5;
    gs->init_flags = init_flags;
    vector_create(&gs->objects, sizeof(render_obj));

    // For screen shake
    gs->screen_shake_horizontal = 0;
    gs->screen_shake_vertical = 0;

    // For momentary game speed switches
    gs->speed_slowdown_previous = 0;
    gs->speed_slowdown_time = -1;

    // Used for crossfades
    gs->next_wait_ticks = 0;
    gs->this_wait_ticks = 0;

    // Set up players
    gs->sc = malloc(sizeof(scene));
    for(int i = 0; i < 2; i++) {
        gs->players[i] = malloc(sizeof(game_player));
        game_player_create(gs->players[i]);
    }

    reconfigure_controller(gs);
    int nscene;
    if (strlen(init_flags->rec_file) > 0 && init_flags->record == 0) {
        sd_rec_file rec;
        sd_rec_create(&rec);
        int ret = sd_rec_load(&rec, init_flags->rec_file);
        if(ret != SD_SUCCESS) {
            PERROR("Unable to load recording %s.", init_flags->rec_file);
            goto error_0;
        }

        nscene = SCENE_ARENA0 + rec.arena_id;
        DEBUG("playing recording file %s", init_flags->rec_file);
        if(scene_create(gs->sc, gs, nscene)) {
            PERROR("Error while loading scene %d.", nscene);
            goto error_0;
        }

        // set the HAR colors, pilot, har type
        for(int i = 0; i < 2; i++) {
            gs->players[i]->colors[0] = rec.pilots[i].info.color_3;
            gs->players[i]->colors[1] = rec.pilots[i].info.color_2;
            gs->players[i]->colors[2] = rec.pilots[i].info.color_1;
            gs->players[i]->har_id = HAR_JAGUAR + rec.pilots[i].info.har_id;
            gs->players[i]->pilot_id = rec.pilots[i].info.pilot_id;
        }

        // XXX use playback controller once it exista
        _setup_rec_controller(gs, 0, &rec);
        _setup_rec_controller(gs, 1, &rec);
        if(arena_create(gs->sc)) {
            PERROR("Error while creating arena scene.");
            goto error_1;
        }
    } else {
{'fraction_non_alphanumeric': 0.14139606238813604, 'fraction_numerical': 0.010099718742009716, 'mean_word_length': 3.040805785123967, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 87, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1033312', 'n_tokens_mistral': 2952, 'n_tokens_neox': 2776, 'n_words': 606}