<commit_before>//! Main Playform client state code.

use cgmath::Point3;
use std::collections::HashMap;
use std::iter::range_inclusive;
use std::sync::Mutex;

use common::block_position::BlockPosition;
use common::communicate::ClientId;
use common::entity::EntityId;
use common::lod::LODIndex;
use common::surroundings_loader::SurroundingsLoader;
use common::terrain_block;
use common::terrain_block::TerrainBlock;

use terrain_buffers;

/// The distances at which LOD switches.
pub const LOD_THRESHOLDS: [i32; 3] = [2, 16, 32];

/// The main client state.
pub struct T {
  #[allow(missing_docs)]
  pub id: ClientId,
  #[allow(missing_docs)]
  pub player_id: EntityId,
  #[allow(missing_docs)]
  pub player_position: Mutex<Point3<f32>>,
  #[allow(missing_docs)]
  pub max_load_distance: i32,
  #[allow(missing_docs)]
  pub surroundings_loader: Mutex<SurroundingsLoader>,
  /// A record of all the blocks that have been loaded.
  pub loaded_blocks: Mutex<HashMap<BlockPosition, (TerrainBlock, LODIndex)>>,
  /// The number of terrain requests that are outstanding,
  pub outstanding_terrain_requests: Mutex<u32>,
}

#[allow(missing_docs)]
pub fn new(client_id: ClientId, player_id: EntityId, position: Point3<f32>) -> T {
  let mut load_distance = load_distance(terrain_buffers::POLYGON_BUDGET as i32);

  // TODO: Remove this once our RAM usage doesn't skyrocket with load distance.
  let max_load_distance = 80;
  if load_distance > max_load_distance {
    info!("load_distance {} capped at {}", load_distance, max_load_distance);
    load_distance = max_load_distance;
  } else {
    info!("load_distance {}", load_distance);
  }

  let surroundings_loader = {
    SurroundingsLoader::new(
      max_load_distance,<commit_msg>cleanups<commit_after>//! Main Playform client state code.

use cgmath::Point3;
use std::collections::HashMap;
use std::iter::range_inclusive;
use std::sync::Mutex;

use common::block_position::BlockPosition;
use common::communicate::ClientId;
use common::entity::EntityId;
use common::lod::LODIndex;
use common::surroundings_loader::SurroundingsLoader;
use common::terrain_block;
use common::terrain_block::TerrainBlock;

use terrain_buffers;

/// The distances at which LOD switches.
pub const LOD_THRESHOLDS: [i32; 3] = [2, 16, 32];

// TODO: Remove this once our RAM usage doesn't skyrocket with load distance.
const MAX_LOAD_DISTANCE: i32 = 80;

/// The main client state.
pub struct T {
  #[allow(missing_docs)]
  pub id: ClientId,
  #[allow(missing_docs)]
  pub player_id: EntityId,
  #[allow(missing_docs)]
  pub player_position: Mutex<Point3<f32>>,
  #[allow(missing_docs)]
  pub max_load_distance: i32,
  #[allow(missing_docs)]
  pub surroundings_loader: Mutex<SurroundingsLoader>,
  /// A record of all the blocks that have been loaded.
  pub loaded_blocks: Mutex<HashMap<BlockPosition, (TerrainBlock, LODIndex)>>,
  /// The number of terrain requests that are outstanding,
  pub outstanding_terrain_requests: Mutex<u32>,
}

#[allow(missing_docs)]
pub fn new(client_id: ClientId, player_id: EntityId, position: Point3<f32>) -> T {
  let mut load_distance = load_distance(terrain_buffers::POLYGON_BUDGET as i32);

  if load_distance > MAX_LOAD_DISTANCE {
    info!("load_distance {} capped at {}", load_distance, MAX_LOAD_DISTANCE);
    load_distance = MAX_LOAD_DISTANCE;
  } else {
    info!("load_distance {}", load_distance);
  }

  let surroundings_loader = {
    SurroundingsLoader::new(
      load_distance,
{'fraction_non_alphanumeric': 0.11967545638945233, 'fraction_numerical': 0.013909011880614315, 'mean_word_length': 5.6257197696737045, 'pattern_counts': {'":': 0, '<': 17, '<?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': '4366721', 'n_tokens_mistral': 1179, 'n_tokens_neox': 1147, 'n_words': 290}