Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 22 additions & 20 deletions ck3-tiger/benches/criterion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{
fs,
path::{Path, PathBuf},
};
use tiger_lib::{Everything, ModFile};
use tiger_lib::{Everything, Fileset};

static CONFIG_PATH: &str = "../benches/ck3.toml";

Expand All @@ -22,48 +22,50 @@ struct Config {
sample_size: Option<usize>,
}

fn workspace_path(s: &str) -> PathBuf {
let p = PathBuf::from(s);
if p.is_relative() {
PathBuf::from("..").join(p)
} else {
p
}
}

fn bench_multiple(c: &mut Criterion) {
let content = fs::read_to_string(CONFIG_PATH).unwrap();
let config: Config = toml::from_str(&content).unwrap();
let mut modfile_paths = config.modfile_paths.iter().map(PathBuf::from).collect::<Vec<_>>();
let mut modfile_paths =
config.modfile_paths.iter().map(|p| workspace_path(p)).collect::<Vec<_>>();

if let Some(modfile_dir) = config.modfile_dir {
let modfile_dir = workspace_path(&modfile_dir);
let iter =
fs::read_dir(modfile_dir).unwrap().filter_map(|entry| entry.ok()).filter_map(|entry| {
entry.file_name().to_string_lossy().ends_with(".mod").then(|| entry.path())
});
modfile_paths.extend(iter);
}

let vanilla_dir = PathBuf::from(config.vanilla_dir);

let mut group = c.benchmark_group("benchmark");
group.sample_size(config.sample_size.unwrap_or(10));
for (index, modfile_path) in modfile_paths.iter().enumerate() {
let modfile = ModFile::read(modfile_path).unwrap();
group.bench_with_input(
BenchmarkId::new(
"mods",
format!("{}. {}", index + 1, modfile.display_name().unwrap_or_default()),
),
&modfile,
|b, modfile_ref| {
b.iter(|| bench_mod(&config.vanilla_dir, modfile_ref));
BenchmarkId::new("mods", format!("{}. {}", index + 1, modfile_path.display())),
modfile_path,
|b, modfile_path| {
b.iter(|| bench_mod(&vanilla_dir, modfile_path.clone()));
},
);
}

group.finish();
}

fn bench_mod(vanilla_dir: &str, modfile: &ModFile) {
let mut everything = Everything::new(
None,
Some(Path::new(vanilla_dir)),
None,
None,
&modfile.modpath(),
modfile.replace_paths(),
)
.unwrap();
fn bench_mod(vanilla_dir: &Path, modfile_path: PathBuf) {
let fileset = Fileset::builder(Some(vanilla_dir)).with_modfile(modfile_path).unwrap();
let mut everything = Everything::new(fileset, None, None, None).unwrap();
everything.load_all();
everything.validate_all();
everything.check_rivers();
Expand Down
16 changes: 4 additions & 12 deletions ck3-tiger/src/bin/scan-mod-ck3-tiger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ use std::fs::write;
use std::mem::forget;
use std::path::PathBuf;

use anyhow::{bail, Result};
use anyhow::Result;
use clap::Parser;
use serde_json::{json, to_string_pretty, Value};
use strum::IntoEnumIterator;

use tiger_lib::{Everything, FileKind, Game, Item, ModFile};
use tiger_lib::{Everything, FileKind, Fileset, Game, Item};

#[derive(Parser)]
struct Cli {
Expand All @@ -34,16 +34,8 @@ fn main() -> Result<()> {
if args.modpath.is_dir() {
args.modpath.push("descriptor.mod");
}
let modfile = ModFile::read(&args.modpath)?;
let modpath = modfile.modpath();
if !modpath.exists() {
eprintln!("Looking for mod in {}", modpath.display());
bail!("Cannot find mod directory. Please make sure the .mod file is correct.");
}
eprintln!("Using mod directory: {}", modpath.display());

let mut everything =
Everything::new(None, None, None, None, &modpath, modfile.replace_paths())?;
let fileset = Fileset::builder(None).with_modfile(args.modpath)?;
let mut everything = Everything::new(fileset, None, None, None)?;

everything.load_all();

Expand Down
1 change: 1 addition & 0 deletions src/block/comparator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pub enum Eq {
Question,
}

#[derive(Debug, Copy, Clone)]
pub struct UnknownComparatorError;

impl FromStr for Comparator {
Expand Down
7 changes: 4 additions & 3 deletions src/ck3/data/characters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::fmt::{Display, Formatter};
use std::path::PathBuf;
use std::str::FromStr;
use std::sync::atomic::Ordering;
use std::sync::Arc;

use atomic_enum::atomic_enum;

Expand All @@ -14,7 +15,7 @@ use crate::context::ScopeContext;
use crate::date::Date;
use crate::effect::{validate_effect, validate_effect_field};
use crate::everything::Everything;
use crate::fileset::{FileEntry, FileHandler};
use crate::files::{FileEntry, FileHandler};
use crate::helpers::{TigerHashMap, TigerHashSet};
use crate::item::Item;
use crate::lowercase::Lowercase;
Expand Down Expand Up @@ -255,15 +256,15 @@ impl FileHandler<Block> for Characters {
PathBuf::from("history/characters")
}

fn load_file(&self, entry: &FileEntry, parser: &ParserMemory) -> Option<Block> {
fn load_file(&self, entry: &Arc<FileEntry>, parser: &ParserMemory) -> Option<Block> {
if !entry.filename().to_string_lossy().ends_with(".txt") {
return None;
}

PdxFile::read(entry, parser)
}

fn handle_file(&mut self, _entry: &FileEntry, mut block: Block) {
fn handle_file(&mut self, _entry: &Arc<FileEntry>, mut block: Block) {
for (key, block) in block.drain_definitions_warn() {
self.load_item(key, block);
}
Expand Down
7 changes: 4 additions & 3 deletions src/ck3/data/doctrines.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use std::path::PathBuf;
use std::sync::Arc;

use crate::block::Block;
use crate::ck3::modif::ModifKinds;
use crate::ck3::validate::validate_traits;
use crate::context::ScopeContext;
use crate::desc::validate_desc;
use crate::everything::Everything;
use crate::fileset::{FileEntry, FileHandler};
use crate::files::{FileEntry, FileHandler};
use crate::helpers::{dup_error, TigerHashMap, TigerHashSet};
use crate::item::Item;
use crate::modif::validate_modifs;
Expand Down Expand Up @@ -105,15 +106,15 @@ impl FileHandler<Block> for Doctrines {
PathBuf::from("common/religion/doctrines")
}

fn load_file(&self, entry: &FileEntry, parser: &ParserMemory) -> Option<Block> {
fn load_file(&self, entry: &Arc<FileEntry>, parser: &ParserMemory) -> Option<Block> {
if !entry.filename().to_string_lossy().ends_with(".txt") {
return None;
}

PdxFile::read(entry, parser)
}

fn handle_file(&mut self, _entry: &FileEntry, mut block: Block) {
fn handle_file(&mut self, _entry: &Arc<FileEntry>, mut block: Block) {
for (key, block) in block.drain_definitions_warn() {
self.load_item(key, block);
}
Expand Down
7 changes: 4 additions & 3 deletions src/ck3/data/gameconcepts.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use std::path::PathBuf;
use std::sync::Arc;

use crate::block::Block;
use crate::everything::Everything;
use crate::fileset::{FileEntry, FileHandler};
use crate::files::{FileEntry, FileHandler};
use crate::helpers::{dup_error, TigerHashMap};
use crate::item::Item;
use crate::parse::ParserMemory;
Expand Down Expand Up @@ -47,15 +48,15 @@ impl FileHandler<Block> for GameConcepts {
PathBuf::from("common/game_concepts")
}

fn load_file(&self, entry: &FileEntry, parser: &ParserMemory) -> Option<Block> {
fn load_file(&self, entry: &Arc<FileEntry>, parser: &ParserMemory) -> Option<Block> {
if !entry.filename().to_string_lossy().ends_with(".txt") {
return None;
}

PdxFile::read(entry, parser)
}

fn handle_file(&mut self, _entry: &FileEntry, mut block: Block) {
fn handle_file(&mut self, _entry: &Arc<FileEntry>, mut block: Block) {
for (key, block) in block.drain_definitions_warn() {
self.load_item(key, block);
}
Expand Down
7 changes: 4 additions & 3 deletions src/ck3/data/interaction_cats.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use std::path::PathBuf;
use std::sync::Arc;

use crate::block::Block;
use crate::everything::Everything;
use crate::fileset::{FileEntry, FileHandler};
use crate::files::{FileEntry, FileHandler};
use crate::helpers::{dup_error, TigerHashMap};
use crate::item::Item;
use crate::parse::ParserMemory;
Expand Down Expand Up @@ -54,15 +55,15 @@ impl FileHandler<Block> for CharacterInteractionCategories {
PathBuf::from("common/character_interaction_categories")
}

fn load_file(&self, entry: &FileEntry, parser: &ParserMemory) -> Option<Block> {
fn load_file(&self, entry: &Arc<FileEntry>, parser: &ParserMemory) -> Option<Block> {
if !entry.filename().to_string_lossy().ends_with(".txt") {
return None;
}

PdxFile::read(entry, parser)
}

fn handle_file(&mut self, _entry: &FileEntry, mut block: Block) {
fn handle_file(&mut self, _entry: &Arc<FileEntry>, mut block: Block) {
for (key, block) in block.drain_definitions_warn() {
self.load_item(key, block);
}
Expand Down
7 changes: 4 additions & 3 deletions src/ck3/data/maa.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use std::path::PathBuf;
use std::sync::Arc;

use crate::block::Block;
use crate::ck3::validate::{validate_cost, validate_maa_stats};
use crate::context::ScopeContext;
use crate::everything::Everything;
use crate::fileset::{FileEntry, FileHandler};
use crate::files::{FileEntry, FileHandler};
use crate::helpers::{dup_error, TigerHashMap, TigerHashSet};
use crate::item::Item;
use crate::lowercase::Lowercase;
Expand Down Expand Up @@ -73,15 +74,15 @@ impl FileHandler<Block> for MenAtArmsTypes {
PathBuf::from("common/men_at_arms_types")
}

fn load_file(&self, entry: &FileEntry, parser: &ParserMemory) -> Option<Block> {
fn load_file(&self, entry: &Arc<FileEntry>, parser: &ParserMemory) -> Option<Block> {
if !entry.filename().to_string_lossy().ends_with(".txt") {
return None;
}

PdxFile::read(entry, parser)
}

fn handle_file(&mut self, _entry: &FileEntry, mut block: Block) {
fn handle_file(&mut self, _entry: &Arc<FileEntry>, mut block: Block) {
for (key, block) in block.drain_definitions_warn() {
self.load_item(key, block);
}
Expand Down
7 changes: 4 additions & 3 deletions src/ck3/data/prov_history.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use std::path::PathBuf;
use std::sync::Arc;

use crate::block::{Block, BV};
use crate::ck3::data::provinces::ProvId;
use crate::ck3::data::titles::Titles;
use crate::date::Date;
use crate::everything::Everything;
use crate::fileset::{FileEntry, FileHandler};
use crate::files::{FileEntry, FileHandler};
use crate::helpers::{dup_error, TigerHashMap};
use crate::item::Item;
use crate::parse::ParserMemory;
Expand Down Expand Up @@ -83,15 +84,15 @@ impl FileHandler<Block> for ProvinceHistories {
PathBuf::from("history/provinces")
}

fn load_file(&self, entry: &FileEntry, parser: &ParserMemory) -> Option<Block> {
fn load_file(&self, entry: &Arc<FileEntry>, parser: &ParserMemory) -> Option<Block> {
if !entry.filename().to_string_lossy().ends_with(".txt") {
return None;
}

PdxFile::read_detect_encoding(entry, parser)
}

fn handle_file(&mut self, _entry: &FileEntry, mut block: Block) {
fn handle_file(&mut self, _entry: &Arc<FileEntry>, mut block: Block) {
for (key, block) in block.drain_definitions_warn() {
if let Ok(id) = key.as_str().parse() {
self.load_item(id, key, block);
Expand Down
11 changes: 6 additions & 5 deletions src/ck3/data/prov_terrain.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use std::path::PathBuf;
use std::sync::Arc;

use crate::block::Block;
use crate::everything::Everything;
use crate::fileset::{FileEntry, FileHandler};
use crate::files::{FileEntry, FileHandler};
use crate::helpers::{dup_error, TigerHashMap};
use crate::item::Item;
use crate::parse::ParserMemory;
Expand Down Expand Up @@ -63,7 +64,7 @@ impl FileHandler<Block> for ProvinceTerrains {
PathBuf::from("common/province_terrain")
}

fn load_file(&self, entry: &FileEntry, parser: &ParserMemory) -> Option<Block> {
fn load_file(&self, entry: &Arc<FileEntry>, parser: &ParserMemory) -> Option<Block> {
if !entry.filename().to_string_lossy().ends_with("province_terrain.txt") {
// Omit _province_properties.txt
return None;
Expand All @@ -72,7 +73,7 @@ impl FileHandler<Block> for ProvinceTerrains {
PdxFile::read_detect_encoding(entry, parser)
}

fn handle_file(&mut self, _entry: &FileEntry, mut block: Block) {
fn handle_file(&mut self, _entry: &Arc<FileEntry>, mut block: Block) {
self.file_loc = Some(block.loc);
for (key, value) in block.drain_assignments_warn() {
if let Ok(id) = key.as_str().parse() {
Expand Down Expand Up @@ -140,15 +141,15 @@ impl FileHandler<Block> for ProvinceProperties {
PathBuf::from("common/province_terrain")
}

fn load_file(&self, entry: &FileEntry, parser: &ParserMemory) -> Option<Block> {
fn load_file(&self, entry: &Arc<FileEntry>, parser: &ParserMemory) -> Option<Block> {
if !entry.filename().to_string_lossy().ends_with("province_properties.txt") {
// Omit _province_terrain.txt
return None;
}
PdxFile::read_detect_encoding(entry, parser)
}

fn handle_file(&mut self, _entry: &FileEntry, mut block: Block) {
fn handle_file(&mut self, _entry: &Arc<FileEntry>, mut block: Block) {
for (key, block) in block.drain_definitions_warn() {
if let Ok(id) = key.as_str().parse() {
self.load_item(id, key, block);
Expand Down
Loading
Loading