| Crates.io | swordfish |
| lib.rs | swordfish |
| version | 0.1.9 |
| created_at | 2025-07-20 05:01:52.998505+00 |
| updated_at | 2025-07-26 10:23:56.806723+00 |
| description | Swordfish is a Data-Oriented Design (DOD) Logic Layer for large scale social based simulations / games. It's designed for fast query / discrete graphs processing performance and the ease of use. |
| homepage | |
| repository | https://github.com/dangkaz1109/SwordfishDOD |
| max_upload_size | |
| id | 1760805 |
| size | 20,905 |
Swordfish is a Data-Oriented Design (DOD) Logic Layer for large scale social based simulations / games. It's designed for fast query / discrete graphs processing performance and the ease of use.
query! and query_mut! macros, providing direct access to fields.Add the following to your Cargo.toml file:
[dependencies]
swordfish = "0.9.0" # Or the latest version
Use the create_table! macro to define your archetype.
use swordfish::{create_table, query, query_mut};
create_table!(
/// Represents a game entity with position and health.
EntityTable, //Define archetype name
position_x: f32,
position_y: f32,
health: i32
);
fn main() {
// ...
}
This will generate a struct named EntityTable with fields for position_x, position_y, and health, along with management methods.
use swordfish::{create_table, query, query_mut};
create_table!(
/// Represents a game entity with position and health.
EntityTable,
position_x: f32,
position_y: f32,
health: i32
);
fn main() {
let mut entities = EntityTable::new();
// ...
}
Use the insert method to add new entries to your table. It returns the id of the newly inserted entry.
use swordfish::{create_table, query, query_mut};
create_table!(
/// Represents a game entity with position and health.
EntityTable,
position_x: f32,
position_y: f32,
health: i32
);
fn main() {
let mut entities = EntityTable::new();
let entity_id_1 = entities.insert(10.0, 20.0, 100);
let entity_id_2 = entities.insert(5.0, 15.0, 75);
println!("Entity 1 ID: {}", entity_id_1); // Output: Entity 1 ID: 0
println!("Entity 2 ID: {}", entity_id_2); // Output: Entity 2 ID: 1
}
The query! macro allows you to iterate over your table's data, providing immutable references to the fields.
query!(entities, id, pos_x: position_x, pos_y: position_y, hp: health,
{
println!("Entity ID: {}, Pos: ({}, {}), Health: {}", id, pos_x, pos_y, hp);
}
);
The query_mut! macro is similar to query!, but it provides mutable references to the fields, allowing you to modify them within the loop.
query_mut!(entities, id, hp: health,
{
*hp -= 10;
}
);
You can mark entries for deletion using delete_by_id. Work safe ONLY in query_mut (or query) statement.
query_mut!(entities, id1, hp: health, {
entities.delete_by_id(id1);
});