Change the filter to be unique instead of duplicated, not perf improvement
This commit is contained in:
parent
51bbf45b57
commit
897ea9983a
|
|
@ -27,6 +27,7 @@ Cargo.lock
|
|||
callgrind*
|
||||
cache.out
|
||||
tarpaulin-report.html
|
||||
.html
|
||||
*.bkp
|
||||
coverage/
|
||||
testdata/
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
//! handling of the whole crafting process when the times comes
|
||||
#![allow(dead_code)]
|
||||
|
||||
use std::{path::Path, rc::Rc};
|
||||
use std::{path::Path, sync::Arc};
|
||||
|
||||
use more_fields::FieldsAsSlice;
|
||||
use rusqlite::Connection;
|
||||
|
|
@ -148,9 +148,9 @@ where
|
|||
|
||||
/// Type alias represinting the inner function parameter
|
||||
// #![feature(trait_alias)]
|
||||
pub(super) type FilterFunctionType<T> = dyn Fn(&T, &T) -> bool;
|
||||
pub(super) type FilterFunctionType<T> = dyn Fn(&T, &T) -> bool + Send + Sync;
|
||||
/// Type alias representing a filter
|
||||
pub(super) type FilterType<T> = Box<Rc<FilterFunctionType<T>>>;
|
||||
pub(super) type FilterType<T> = Arc<FilterFunctionType<T>>;
|
||||
|
||||
#[derive(Clone)]
|
||||
/// A generic Filtering function
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
//! These impls are here to either prettify output, or allow for smoother implementation of other traits and inner workings
|
||||
|
||||
use crate::interfaces::FilterFunction;
|
||||
use std::{fmt::Debug, rc::Rc};
|
||||
use std::{fmt::Debug, sync::Arc};
|
||||
|
||||
impl<T> Debug for FilterFunction<T> {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
|
|
@ -14,7 +14,7 @@ impl<T> Debug for FilterFunction<T> {
|
|||
}
|
||||
impl<T> Default for FilterFunction<T> {
|
||||
fn default() -> Self {
|
||||
FilterFunction(Box::new(Rc::new(|_, _| true)))
|
||||
FilterFunction(Arc::new(|_, _| true))
|
||||
}
|
||||
}
|
||||
impl<T> PartialEq for FilterFunction<T> {
|
||||
|
|
@ -32,6 +32,8 @@ mod test {
|
|||
fn test_filter_weapons() {
|
||||
let _ = format!("{:?}", FilterFunction::<Equipement>::default());
|
||||
let r = FilterFunction::<Equipement>::new(&|_, _| false) == FilterFunction::default();
|
||||
|
||||
// const B: LazyLock<&'static dyn Fn(&InnerEquipementStats, &InnerEquipementStats) -> bool> =
|
||||
assert!(r);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,25 +8,23 @@
|
|||
//! Implementations to transform all Specialized equipement into a generic Equipement
|
||||
//! A specific implementation could be preferable, but this simplicity might allow for easier developpement
|
||||
|
||||
use comfy_table::{Table, modifiers::UTF8_ROUND_CORNERS};
|
||||
use std::fmt::Display;
|
||||
|
||||
use crate::interfaces::{FilterFunction, Reportable};
|
||||
|
||||
use super::{
|
||||
Equipement, InitialEquipementList,
|
||||
equipement_advanced_repr::RefinedEquipementList,
|
||||
equipement_structs::{
|
||||
EqFinishing, EqMaterial, EqNature, EqShape, InnerEquipementStats,
|
||||
filter_id_unique_and_right_category,
|
||||
EqFinishing, EqMaterial, EqNature, EqShape, FILTER_TRUE, FILTER_UNIQUE,
|
||||
FILTER_UNIQUE_AND_RIGHT_CATEGORY, InnerEquipementStats,
|
||||
},
|
||||
};
|
||||
use crate::interfaces::Reportable;
|
||||
use comfy_table::{Table, modifiers::UTF8_ROUND_CORNERS};
|
||||
use std::fmt::Display;
|
||||
|
||||
impl From<EqShape> for Equipement {
|
||||
fn from(val: EqShape) -> Self {
|
||||
Self {
|
||||
stats: val.stats,
|
||||
..Default::default()
|
||||
filter_function: FILTER_TRUE.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -35,7 +33,7 @@ impl From<EqMaterial> for Equipement {
|
|||
fn from(val: EqMaterial) -> Self {
|
||||
Self {
|
||||
stats: val.stats,
|
||||
filter_function: FilterFunction::new(filter_id_unique_and_right_category()),
|
||||
filter_function: FILTER_UNIQUE_AND_RIGHT_CATEGORY.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -45,7 +43,7 @@ impl From<EqNature> for Equipement {
|
|||
Self {
|
||||
stats: val.stats,
|
||||
// Checks that the nature is compatible with the previous iteration
|
||||
filter_function: FilterFunction::new(filter_id_unique_and_right_category()),
|
||||
filter_function: FILTER_UNIQUE_AND_RIGHT_CATEGORY.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -54,7 +52,7 @@ impl From<EqFinishing> for Equipement {
|
|||
fn from(val: EqFinishing) -> Self {
|
||||
Self {
|
||||
stats: val.stats,
|
||||
..Default::default()
|
||||
filter_function: FILTER_TRUE.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,18 +2,16 @@
|
|||
// File: weaponry/src/weaponry_structs/equipement_structs.rs
|
||||
//! Base equipement structures
|
||||
|
||||
use std::rc::Rc;
|
||||
|
||||
use crate::interfaces::{FilterFunction, FilterFunctionType};
|
||||
use more_fields::FieldsAsSlice;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::{
|
||||
DamageType, SpecialField,
|
||||
equipement_fields::{
|
||||
EquipementSerializedCategory, EquipementTargets, WeaponBaseShape, WeaponBaseSize,
|
||||
},
|
||||
};
|
||||
use crate::interfaces::{FilterFunction, FilterFunctionType};
|
||||
use more_fields::FieldsAsSlice;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::sync::{Arc, LazyLock};
|
||||
|
||||
/// The final equipement list
|
||||
///
|
||||
|
|
@ -70,9 +68,23 @@ impl<T> FilterFunction<T> {
|
|||
/// Generate and save a new filter,
|
||||
/// the use of a static reference allows for reuse of a generic filter
|
||||
pub fn new(filter: &'static FilterFunctionType<T>) -> Self {
|
||||
Self(Box::new(Rc::new(filter)))
|
||||
Self(Arc::new(filter))
|
||||
}
|
||||
}
|
||||
|
||||
/// Filter letting every instance being merged
|
||||
pub(crate) static FILTER_TRUE: LazyLock<FilterFunction<InnerEquipementStats>> =
|
||||
LazyLock::new(|| FilterFunction::<InnerEquipementStats>(Arc::new(|_, _| true)));
|
||||
/// Filter letting the merge happen iff the id is unique (not present in the previous element)
|
||||
/// and the category should allow the merge
|
||||
pub(crate) static FILTER_UNIQUE_AND_RIGHT_CATEGORY: LazyLock<FilterFunction<InnerEquipementStats>> =
|
||||
LazyLock::new(|| {
|
||||
FilterFunction::<InnerEquipementStats>(Arc::new(filter_id_unique_and_right_category()))
|
||||
});
|
||||
/// Filter letting the merge happen iff the id is unique (not present in the previous element)
|
||||
pub(crate) static FILTER_UNIQUE: LazyLock<FilterFunction<InnerEquipementStats>> =
|
||||
LazyLock::new(|| FilterFunction::<InnerEquipementStats>(Arc::new(filter_id_unique())));
|
||||
|
||||
/// The inner statistics of the equipement, used across all parts and final weapon
|
||||
#[allow(clippy::missing_docs_in_private_items, missing_docs)]
|
||||
#[derive(Clone, Default, FieldsAsSlice, Debug)]
|
||||
|
|
|
|||
|
|
@ -1,515 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>Ravenous Balancing</title>
|
||||
<script src="https://cdn.jsdelivr.net/npm/echarts@5.4.2/dist/echarts.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/echarts-gl@2.0.9/dist/echarts-gl.min.js"></script>
|
||||
<style> .container { display: flex; justify-content: center; align-items: center; } .item { margin: auto; } </style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="item" id="chart" style="width: 4000px; height: 2000px"></div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
var chart = echarts.init(document.getElementById('chart'), 'dark', { renderer: 'canvas' });
|
||||
var option = {
|
||||
"title": [
|
||||
{
|
||||
"text": "Damage for all cross-gen products (10 Elements)",
|
||||
"left": "center"
|
||||
}
|
||||
],
|
||||
"tooltip": {
|
||||
"trigger": "axis"
|
||||
},
|
||||
"legend": {
|
||||
"left": 10,
|
||||
"top": "middle",
|
||||
"orient": "vertical",
|
||||
"data": [
|
||||
{
|
||||
"name": "max_damage_per_attack"
|
||||
},
|
||||
{
|
||||
"name": "armor_break_per_attack"
|
||||
},
|
||||
{
|
||||
"name": "avg_damage_2a_safe"
|
||||
},
|
||||
{
|
||||
"name": "avg_damage_2a_huge_hit"
|
||||
},
|
||||
{
|
||||
"name": "variance"
|
||||
},
|
||||
{
|
||||
"name": "variance_pct"
|
||||
},
|
||||
{
|
||||
"name": "scenario_damage"
|
||||
},
|
||||
{
|
||||
"name": "defensive"
|
||||
},
|
||||
{
|
||||
"name": "earlygame_sustained_damage_per_turn"
|
||||
},
|
||||
{
|
||||
"name": "midgame_sustained_damage_per_turn"
|
||||
},
|
||||
{
|
||||
"name": "endgame_sustained_damage_per_turn"
|
||||
}
|
||||
]
|
||||
},
|
||||
"toolbox": {
|
||||
"feature": {
|
||||
"saveAsImage": {},
|
||||
"restore": {},
|
||||
"dataZoom": {
|
||||
"yAxisIndex": "none"
|
||||
}
|
||||
}
|
||||
},
|
||||
"grid": [
|
||||
{
|
||||
"containLabel": true
|
||||
}
|
||||
],
|
||||
"xAxis": [
|
||||
{
|
||||
"type": "category",
|
||||
"data": [
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
""
|
||||
]
|
||||
}
|
||||
],
|
||||
"yAxis": [
|
||||
{}
|
||||
],
|
||||
"dataZoom": [
|
||||
{
|
||||
"type": "inside",
|
||||
"start": 0.0,
|
||||
"end": 100.0
|
||||
},
|
||||
{
|
||||
"start": 0.0,
|
||||
"end": 100.0
|
||||
}
|
||||
],
|
||||
"series": [
|
||||
{
|
||||
"type": "line",
|
||||
"name": "max_damage_per_attack",
|
||||
"markPoint": {
|
||||
"data": [
|
||||
{
|
||||
"type": "max",
|
||||
"name": "Max"
|
||||
},
|
||||
{
|
||||
"type": "min",
|
||||
"name": "Min"
|
||||
}
|
||||
]
|
||||
},
|
||||
"markLine": {
|
||||
"data": [
|
||||
{
|
||||
"type": "average",
|
||||
"name": "Avg"
|
||||
}
|
||||
]
|
||||
},
|
||||
"data": [
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "line",
|
||||
"name": "armor_break_per_attack",
|
||||
"markPoint": {
|
||||
"data": [
|
||||
{
|
||||
"type": "max",
|
||||
"name": "Max"
|
||||
},
|
||||
{
|
||||
"type": "min",
|
||||
"name": "Min"
|
||||
}
|
||||
]
|
||||
},
|
||||
"markLine": {
|
||||
"data": [
|
||||
{
|
||||
"type": "average",
|
||||
"name": "Avg"
|
||||
}
|
||||
]
|
||||
},
|
||||
"data": [
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "line",
|
||||
"name": "avg_damage_2a_safe",
|
||||
"markPoint": {
|
||||
"data": [
|
||||
{
|
||||
"type": "max",
|
||||
"name": "Max"
|
||||
},
|
||||
{
|
||||
"type": "min",
|
||||
"name": "Min"
|
||||
}
|
||||
]
|
||||
},
|
||||
"markLine": {
|
||||
"data": [
|
||||
{
|
||||
"type": "average",
|
||||
"name": "Avg"
|
||||
}
|
||||
]
|
||||
},
|
||||
"data": [
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "line",
|
||||
"name": "avg_damage_2a_huge_hit",
|
||||
"markPoint": {
|
||||
"data": [
|
||||
{
|
||||
"type": "max",
|
||||
"name": "Max"
|
||||
},
|
||||
{
|
||||
"type": "min",
|
||||
"name": "Min"
|
||||
}
|
||||
]
|
||||
},
|
||||
"markLine": {
|
||||
"data": [
|
||||
{
|
||||
"type": "average",
|
||||
"name": "Avg"
|
||||
}
|
||||
]
|
||||
},
|
||||
"data": [
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "line",
|
||||
"name": "variance",
|
||||
"markPoint": {
|
||||
"data": [
|
||||
{
|
||||
"type": "max",
|
||||
"name": "Max"
|
||||
},
|
||||
{
|
||||
"type": "min",
|
||||
"name": "Min"
|
||||
}
|
||||
]
|
||||
},
|
||||
"markLine": {
|
||||
"data": [
|
||||
{
|
||||
"type": "average",
|
||||
"name": "Avg"
|
||||
}
|
||||
]
|
||||
},
|
||||
"data": [
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "line",
|
||||
"name": "variance_pct",
|
||||
"markPoint": {
|
||||
"data": [
|
||||
{
|
||||
"type": "max",
|
||||
"name": "Max"
|
||||
},
|
||||
{
|
||||
"type": "min",
|
||||
"name": "Min"
|
||||
}
|
||||
]
|
||||
},
|
||||
"markLine": {
|
||||
"data": [
|
||||
{
|
||||
"type": "average",
|
||||
"name": "Avg"
|
||||
}
|
||||
]
|
||||
},
|
||||
"data": [
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "line",
|
||||
"name": "scenario_damage",
|
||||
"markPoint": {
|
||||
"data": [
|
||||
{
|
||||
"type": "max",
|
||||
"name": "Max"
|
||||
},
|
||||
{
|
||||
"type": "min",
|
||||
"name": "Min"
|
||||
}
|
||||
]
|
||||
},
|
||||
"markLine": {
|
||||
"data": [
|
||||
{
|
||||
"type": "average",
|
||||
"name": "Avg"
|
||||
}
|
||||
]
|
||||
},
|
||||
"data": [
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "line",
|
||||
"name": "defensive",
|
||||
"markPoint": {
|
||||
"data": [
|
||||
{
|
||||
"type": "max",
|
||||
"name": "Max"
|
||||
},
|
||||
{
|
||||
"type": "min",
|
||||
"name": "Min"
|
||||
}
|
||||
]
|
||||
},
|
||||
"markLine": {
|
||||
"data": [
|
||||
{
|
||||
"type": "average",
|
||||
"name": "Avg"
|
||||
}
|
||||
]
|
||||
},
|
||||
"data": [
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "line",
|
||||
"name": "earlygame_sustained_damage_per_turn",
|
||||
"markPoint": {
|
||||
"data": [
|
||||
{
|
||||
"type": "max",
|
||||
"name": "Max"
|
||||
},
|
||||
{
|
||||
"type": "min",
|
||||
"name": "Min"
|
||||
}
|
||||
]
|
||||
},
|
||||
"markLine": {
|
||||
"data": [
|
||||
{
|
||||
"type": "average",
|
||||
"name": "Avg"
|
||||
}
|
||||
]
|
||||
},
|
||||
"data": [
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "line",
|
||||
"name": "midgame_sustained_damage_per_turn",
|
||||
"markPoint": {
|
||||
"data": [
|
||||
{
|
||||
"type": "max",
|
||||
"name": "Max"
|
||||
},
|
||||
{
|
||||
"type": "min",
|
||||
"name": "Min"
|
||||
}
|
||||
]
|
||||
},
|
||||
"markLine": {
|
||||
"data": [
|
||||
{
|
||||
"type": "average",
|
||||
"name": "Avg"
|
||||
}
|
||||
]
|
||||
},
|
||||
"data": [
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "line",
|
||||
"name": "endgame_sustained_damage_per_turn",
|
||||
"markPoint": {
|
||||
"data": [
|
||||
{
|
||||
"type": "max",
|
||||
"name": "Max"
|
||||
},
|
||||
{
|
||||
"type": "min",
|
||||
"name": "Min"
|
||||
}
|
||||
]
|
||||
},
|
||||
"markLine": {
|
||||
"data": [
|
||||
{
|
||||
"type": "average",
|
||||
"name": "Avg"
|
||||
}
|
||||
]
|
||||
},
|
||||
"data": [
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0
|
||||
]
|
||||
}
|
||||
]
|
||||
};
|
||||
chart.setOption(option);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Reference in New Issue