-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: initial version of the dogma-engine (#1)
This is heavily based (in fact, a near copy) of the demonstrator
- Loading branch information
Showing
15 changed files
with
1,137 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
name: Testing | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
testing: | ||
name: Testing | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Install Rust toolchain | ||
uses: actions-rust-lang/setup-rust-toolchain@v1 | ||
with: | ||
toolchain: stable | ||
|
||
- name: Install wasm-pack | ||
run: | | ||
cargo install wasm-pack | ||
- name: Build library | ||
run: | | ||
wasm-pack build --release --target web | ||
- name: Check coding style | ||
run: | | ||
cargo fmt --check |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/target/ | ||
__pycache__/ | ||
Cargo.lock | ||
/pkg/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
[package] | ||
name = "dogma-engine" | ||
version = "0.0.0-git" | ||
authors = ["Patric Stout <[email protected]>"] | ||
edition = "2021" | ||
|
||
[lib] | ||
crate-type = ["cdylib", "rlib"] | ||
|
||
[dependencies] | ||
console_error_panic_hook = "0.1" | ||
serde = { version = "1.0", features = ["derive"] } | ||
serde_repr = "0.1" | ||
serde-wasm-bindgen = "0.4" | ||
strum = "0.25" | ||
strum_macros = "0.25" | ||
wasm-bindgen = "0.2" | ||
|
||
[profile.release] | ||
opt-level = "s" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Copyright (c) 2023 TrueBrain | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# EVEShip.fit's Dogma Engine | ||
|
||
This library calculates accurately statistics of an EVE Online ship fit. | ||
|
||
The input are several data-files provided by EVE Online, together with a ship fit. | ||
The output are all the Dogma attributes, containing all the details of the ship. | ||
|
||
## Implementation | ||
|
||
This Dogma engine implements a multi-pass approach. | ||
|
||
- [pass 1](./src/calculate/pass_1.rs): collect all the Dogma attributes of the hull and modules. | ||
- [pass 2](./src/calculate/pass_2.rs): collect all the Dogma effects of the hull and modules. | ||
- [pass 3](./src/calculate/pass_3.rs): apply all the Dogma effects to the hull/modules, calculating the actual Dogma attribute values. | ||
- [pass 4](./src/calculate/pass_4.rs): augment the Dogma attributes with EVEShip.fit specific attributes. | ||
|
||
## EVEShip.fit's specific attributes | ||
|
||
`Pass 4` create Dogma attributes that do not exist in-game, but are calculated based on other Dogma attributes. | ||
To make rendering a fit easier, these are calculated by this library, and presented as new Dogma attributes. | ||
|
||
Their identifier is always a negative value, to visually separate them. | ||
|
||
- `-1`: align-time | ||
- `-2`: scan strength | ||
- `-3`: CPU usage | ||
- `-4`: PG usage | ||
|
||
## Integration | ||
|
||
### Javascript (WebAssembly) | ||
|
||
The primary goal of this library is to build a WebAssembly variant that can easily be used in the browser. | ||
This means that there is no need for a server-component, and everything can be calculated in the browser. | ||
|
||
This is done with [wasm-pack](https://rustwasm.github.io/wasm-pack/). | ||
|
||
To make sure that EVEShip.fit is as fast as possible, all data-files are read by Javascript, and made available to this library by callbacks. | ||
Transferring all data-files from Javascript to Rust is simply too expensive. | ||
|
||
In result, Javascript needs to have the following functions defined: | ||
|
||
- `get_dogma_attributes(type_id)` - To get a list of all Dogma attributes for a given item. | ||
- `get_dogma_attribute(attribute_id)` - To get all the details of a single Dogma attribute. | ||
- `get_dogma_effects(type_id)` - To get a list of all Dogma effects for a given item. | ||
- `get_dogma_effect(effect_id)` - To get all the details of a single Dogma effect. | ||
- `get_type_id(type_id)` - To get all the details of a single item. | ||
|
||
The returning value should be a Javascript object. | ||
The fields are defined in in [data_types.rs](./src/data_types.rs). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use serde::Serialize; | ||
use std::collections::BTreeMap; | ||
|
||
mod info; | ||
mod item; | ||
mod pass_1; | ||
mod pass_2; | ||
mod pass_3; | ||
mod pass_4; | ||
|
||
use info::Info; | ||
use item::Item; | ||
|
||
#[derive(Serialize, Debug)] | ||
pub struct Ship { | ||
pub hull: Item, | ||
pub items: Vec<Item>, | ||
|
||
#[serde(skip_serializing)] | ||
pub skills: Vec<Item>, | ||
#[serde(skip_serializing)] | ||
pub char: Item, | ||
#[serde(skip_serializing)] | ||
pub structure: Item, | ||
} | ||
|
||
impl Ship { | ||
pub fn new(ship_id: i32) -> Ship { | ||
Ship { | ||
hull: Item::new(ship_id), | ||
items: Vec::new(), | ||
skills: Vec::new(), | ||
char: Item::new(0), | ||
structure: Item::new(0), | ||
} | ||
} | ||
} | ||
|
||
trait Pass { | ||
fn pass(info: &Info, ship: &mut Ship); | ||
} | ||
|
||
pub fn calculate(ship_layout: &super::data_types::ShipLayout, skills: &BTreeMap<i32, i32>) -> Ship { | ||
let info = Info::new(ship_layout, skills); | ||
let mut ship = Ship::new(info.ship_layout.ship_id); | ||
|
||
pass_1::PassOne::pass(&info, &mut ship); | ||
pass_2::PassTwo::pass(&info, &mut ship); | ||
pass_3::PassThree::pass(&info, &mut ship); | ||
pass_4::PassFour::pass(&info, &mut ship); | ||
|
||
ship | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
use serde_wasm_bindgen; | ||
use std::collections::BTreeMap; | ||
use wasm_bindgen::prelude::*; | ||
|
||
use super::super::data_types; | ||
|
||
#[wasm_bindgen] | ||
extern "C" { | ||
#[wasm_bindgen(js_namespace = window)] | ||
fn get_dogma_attributes(type_id: i32) -> JsValue; | ||
|
||
#[wasm_bindgen(js_namespace = window)] | ||
fn get_dogma_attribute(attribute_id: i32) -> JsValue; | ||
|
||
#[wasm_bindgen(js_namespace = window)] | ||
fn get_dogma_effects(type_id: i32) -> JsValue; | ||
|
||
#[wasm_bindgen(js_namespace = window)] | ||
fn get_dogma_effect(effect_id: i32) -> JsValue; | ||
|
||
#[wasm_bindgen(js_namespace = window)] | ||
fn get_type_id(type_id: i32) -> JsValue; | ||
} | ||
|
||
pub struct Info<'a> { | ||
pub ship_layout: &'a data_types::ShipLayout, | ||
pub skills: &'a BTreeMap<i32, i32>, | ||
} | ||
|
||
impl Info<'_> { | ||
pub fn new<'a>( | ||
ship_layout: &'a data_types::ShipLayout, | ||
skills: &'a BTreeMap<i32, i32>, | ||
) -> Info<'a> { | ||
Info { | ||
ship_layout, | ||
skills, | ||
} | ||
} | ||
|
||
pub fn get_dogma_attributes(&self, type_id: i32) -> Vec<data_types::TypeDogmaAttribute> { | ||
let js = get_dogma_attributes(type_id); | ||
serde_wasm_bindgen::from_value(js).unwrap() | ||
} | ||
|
||
pub fn get_dogma_attribute(&self, attribute_id: i32) -> data_types::DogmaAttribute { | ||
let js = get_dogma_attribute(attribute_id); | ||
serde_wasm_bindgen::from_value(js).unwrap() | ||
} | ||
|
||
pub fn get_dogma_effects(&self, type_id: i32) -> Vec<data_types::TypeDogmaEffect> { | ||
let js = get_dogma_effects(type_id); | ||
serde_wasm_bindgen::from_value(js).unwrap() | ||
} | ||
|
||
pub fn get_dogma_effect(&self, effect_id: i32) -> data_types::DogmaEffect { | ||
let js = get_dogma_effect(effect_id); | ||
serde_wasm_bindgen::from_value(js).unwrap() | ||
} | ||
|
||
pub fn get_type_id(&self, type_id: i32) -> data_types::TypeId { | ||
let js = get_type_id(type_id); | ||
serde_wasm_bindgen::from_value(js).unwrap() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
use serde::Serialize; | ||
use std::collections::BTreeMap; | ||
use strum_macros::EnumIter; | ||
|
||
#[derive(Serialize, Debug, Copy, Clone, PartialEq, Eq)] | ||
pub enum EffectCategory { | ||
Passive, | ||
Active, | ||
Target, | ||
Area, | ||
Online, | ||
Overload, | ||
Dungeon, | ||
System, | ||
} | ||
|
||
#[derive(Serialize, Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, EnumIter)] | ||
pub enum EffectOperator { | ||
PreAssign, | ||
PreMul, | ||
PreDiv, | ||
ModAdd, | ||
ModSub, | ||
PostMul, | ||
PostDiv, | ||
PostPercent, | ||
PostAssignment, | ||
} | ||
|
||
#[derive(Serialize, Debug, Copy, Clone)] | ||
pub enum Object { | ||
Ship, | ||
Item(usize), | ||
Skill(usize), | ||
Char, | ||
Structure, | ||
} | ||
|
||
#[derive(Serialize, Debug)] | ||
pub struct Effect { | ||
pub operator: EffectOperator, | ||
pub penalty: bool, | ||
pub source: Object, | ||
pub source_category: EffectCategory, | ||
pub source_attribute_id: i32, | ||
} | ||
|
||
#[derive(Serialize, Debug)] | ||
pub struct Attribute { | ||
pub base_value: f32, | ||
pub value: Option<f32>, | ||
pub effects: Vec<Effect>, | ||
} | ||
|
||
#[derive(Serialize, Debug)] | ||
pub struct Item { | ||
pub type_id: i32, | ||
pub attributes: BTreeMap<i32, Attribute>, | ||
pub effects: Vec<i32>, | ||
} | ||
|
||
impl Attribute { | ||
pub fn new(value: f32) -> Attribute { | ||
Attribute { | ||
base_value: value, | ||
value: None, | ||
effects: Vec::new(), | ||
} | ||
} | ||
} | ||
|
||
impl Item { | ||
pub fn new(type_id: i32) -> Item { | ||
Item { | ||
type_id, | ||
attributes: BTreeMap::new(), | ||
effects: Vec::new(), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
use super::item::{Attribute, Item}; | ||
use super::{Info, Pass, Ship}; | ||
|
||
const ATTRIBUTE_MASS_ID: i32 = 4; | ||
const ATTRIBUTE_CAPACITY_ID: i32 = 38; | ||
const ATTRIBUTE_VOLUME_ID: i32 = 161; | ||
const ATTRIBUTE_RADIUS_ID: i32 = 162; | ||
const ATTRIBUTE_SKILL_LEVEL_ID: i32 = 280; | ||
|
||
pub struct PassOne {} | ||
|
||
impl Item { | ||
pub fn set_attribute(&mut self, attribute_id: i32, value: f32) { | ||
self.attributes.insert(attribute_id, Attribute::new(value)); | ||
} | ||
|
||
fn set_attributes(&mut self, info: &Info) { | ||
for dogma_attribute in info.get_dogma_attributes(self.type_id) { | ||
self.set_attribute(dogma_attribute.attributeID, dogma_attribute.value); | ||
} | ||
} | ||
} | ||
|
||
impl Pass for PassOne { | ||
fn pass(info: &Info, ship: &mut Ship) { | ||
ship.hull.set_attributes(info); | ||
|
||
/* Some attributes of ships come from the TypeID information. */ | ||
let type_id = info.get_type_id(info.ship_layout.ship_id); | ||
ship.hull | ||
.set_attribute(ATTRIBUTE_MASS_ID, type_id.mass.unwrap()); | ||
ship.hull | ||
.set_attribute(ATTRIBUTE_CAPACITY_ID, type_id.capacity.unwrap()); | ||
ship.hull | ||
.set_attribute(ATTRIBUTE_VOLUME_ID, type_id.volume.unwrap()); | ||
ship.hull | ||
.set_attribute(ATTRIBUTE_RADIUS_ID, type_id.radius.unwrap()); | ||
|
||
for (skill_id, skill_level) in info.skills { | ||
let mut skill = Item::new(*skill_id); | ||
|
||
skill.set_attributes(info); | ||
skill.set_attribute(ATTRIBUTE_SKILL_LEVEL_ID, *skill_level as f32); | ||
|
||
ship.skills.push(skill); | ||
} | ||
|
||
for item_id in &info.ship_layout.items { | ||
let mut item = Item::new(*item_id); | ||
|
||
item.set_attributes(info); | ||
|
||
ship.items.push(item); | ||
} | ||
} | ||
} |
Oops, something went wrong.