<commit_before>package io.luna.game.model;

import io.luna.LunaContext;
import io.luna.game.model.mobile.MobileEntity;
import io.luna.game.model.mobile.MobileEntityList;
import io.luna.game.model.mobile.Npc;
import io.luna.game.model.mobile.Player;
import io.luna.game.model.region.RegionManager;
import io.luna.game.task.Task;
import io.luna.game.task.TaskManager;
import io.luna.net.session.GameSession;
import io.luna.net.session.SessionState;
import io.luna.util.StringUtils;

import java.util.Optional;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;

/**
 * Manages the various types in the {@code io.luna.game.model} package and subpackages.
 *
 * @author lare96 <http://github.org/lare96>
 */
public final class World {

    /**
     * The total amount of {@link Player}s that can be either logged in per game loop.
     */
    public static final int LOGIN_THRESHOLD = 50;

    /**
     * An instance of the {@link LunaContext}.
     */
    private final LunaContext context;

    /**
     * The list of {@link Player}s in the world.
     */
    private final MobileEntityList<Player> players = new MobileEntityList<>(2048);

    /**
     * The list of {@link Npc}s in the world.
     */
    private final MobileEntityList<Npc> npcs = new MobileEntityList<>(16384);

    /**
     * A {@link Queue} of {@link Player}s awaiting login.
     */
    private final Queue<Player> logins = new ConcurrentLinkedQueue<>();

    /**
     * A {@link Queue} of {@link Player}s awaiting logout.
     */
    private final Queue<Player> logouts = new ConcurrentLinkedQueue<>();

    /**
     * The {@link RegionManager} that manages region caching.
     */
    private final RegionManager regions = new RegionManager();

    /**
     * The {@link TaskManager} that manages cycle based tasks.
     */
    private final TaskManager tasks = new TaskManager();

    /**
     * The {@link WorldSynchronizer} that will perform updating for all {@link MobileEntity}s.
     */
    private final WorldSynchronizer synchronizer = new WorldSynchronizer(this);

    /**
     * Creates a new {@link World}.
     *
     * @param context An instance of the {@link LunaContext}.
     */
    public World(LunaContext context) {
        this.context = context;
    }

    /**
     * Schedules a {@link Task} using the underlying {@link TaskManager}.
     *
     * @param t The {@code Task} to schedule.
     */
    public void schedule(Task t) {
        tasks.schedule(t);
    }

    /**
     * Queues {@code player} to be logged in on the next game loop.
     *
     * @param player The {@link Player} to be logged in.
     */
    public void queueLogin(Player player) {
        GameSession session = player.getSession();

        if (session.getState() == SessionState.LOGGING_IN && !logins.contains(player)) {
            session.setState(SessionState.LOGIN_QUEUE);
            logins.add(player);
        }
    }

    /**
     * Dequeues the {@link Queue} of {@link Player}s awaiting login.
     */
    public void dequeueLogins() {
        for (int amount = 0; amount < LOGIN_THRESHOLD; amount++) {
            Player player = logins.poll();
            if (player == null) {
                break;
            }
            players.add(player);
        }
    }

    /**
     * Runs one iteration of the main game loop which includes processing {@link Task}s and synchronization.
     */
    public void runGameLoop() {
        tasks.runTaskIteration();

        synchronizer.preSynchronize();
        synchronizer.synchronize();
        synchronizer.postSynchronize();
    }

    /**
     * Queues {@code player} to be logged out on the next game loop.
     *
     * @param player The {@link Player} to be logged out.
     */
    public void queueLogout(Player player) {
        GameSession session = player.getSession();

        if (session.getState() == SessionState.LOGGED_IN && !logouts.contains(player)) {
            session.setState(SessionState.LOGOUT_QUEUE);<commit_msg>Removal of SessionState from the world<commit_after>package io.luna.game.model;

import io.luna.LunaContext;
import io.luna.game.model.mobile.MobileEntity;
import io.luna.game.model.mobile.MobileEntityList;
import io.luna.game.model.mobile.Npc;
import io.luna.game.model.mobile.Player;
import io.luna.game.model.region.RegionManager;
import io.luna.game.task.Task;
import io.luna.game.task.TaskManager;
import io.luna.util.StringUtils;

import java.util.Optional;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;

/**
 * Manages the various types in the {@code io.luna.game.model} package and subpackages.
 *
 * @author lare96 <http://github.org/lare96>
 */
public final class World {

    /**
     * The total amount of {@link Player}s that can be either logged in per game loop.
     */
    public static final int LOGIN_THRESHOLD = 50;

    /**
     * An instance of the {@link LunaContext}.
     */
    private final LunaContext context;

    /**
     * The list of {@link Player}s in the world.
     */
    private final MobileEntityList<Player> players = new MobileEntityList<>(2048);

    /**
     * The list of {@link Npc}s in the world.
     */
    private final MobileEntityList<Npc> npcs = new MobileEntityList<>(16384);

    /**
     * A {@link Queue} of {@link Player}s awaiting login.
     */
    private final Queue<Player> logins = new ConcurrentLinkedQueue<>();

    /**
     * A {@link Queue} of {@link Player}s awaiting logout.
     */
    private final Queue<Player> logouts = new ConcurrentLinkedQueue<>();

    /**
     * The {@link RegionManager} that manages region caching.
     */
    private final RegionManager regions = new RegionManager();

    /**
     * The {@link TaskManager} that manages cycle based tasks.
     */
    private final TaskManager tasks = new TaskManager();

    /**
     * The {@link WorldSynchronizer} that will perform updating for all {@link MobileEntity}s.
     */
    private final WorldSynchronizer synchronizer = new WorldSynchronizer(this);

    /**
     * Creates a new {@link World}.
     *
     * @param context An instance of the {@link LunaContext}.
     */
    public World(LunaContext context) {
        this.context = context;
    }

    /**
     * Schedules a {@link Task} using the underlying {@link TaskManager}.
     *
     * @param t The {@code Task} to schedule.
     */
    public void schedule(Task t) {
        tasks.schedule(t);
    }

    /**
     * Queues {@code player} to be logged in on the next game loop.
     *
     * @param player The {@link Player} to be logged in.
     */
    public void queueLogin(Player player) {
        if (player.getState() == EntityState.IDLE && !logins.contains(player)) {
            logins.add(player);
        }
    }

    /**
     * Dequeues the {@link Queue} of {@link Player}s awaiting login.
     */
    public void dequeueLogins() {
        for (int amount = 0; amount < LOGIN_THRESHOLD; amount++) {
            Player player = logins.poll();
            if (player == null) {
                break;
            }
            players.add(player);
        }
    }

    /**
     * Runs one iteration of the main game loop which includes processing {@link Task}s and synchronization.
     */
    public void runGameLoop() {
        tasks.runTaskIteration();

        synchronizer.preSynchronize();
        synchronizer.synchronize();
        synchronizer.postSynchronize();
    }

    /**
     * Queues {@code player} to be logged out on the next game loop.
     *
     * @param player The {@link Player} to be logged out.
     */
    public void queueLogout(Player player) {
        if (player.getState() == EntityState.ACTIVE && !logouts.contains(player)) {
{'fraction_non_alphanumeric': 0.11703511053315994, 'fraction_numerical': 0.004161248374512354, 'mean_word_length': 2.5215201465201464, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 21, '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': '4616318', 'n_tokens_mistral': 2295, 'n_tokens_neox': 2231, 'n_words': 660}