Skip to content

Far-Beyond-Pulsar/Dynasty

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dynasty 🏰

Crates.io Documentation License Build Status

Dynasty is a powerful inheritance system for Rust, designed specifically for game engines and complex application architectures. It provides a natural class-based inheritance model while maintaining Rust's safety guarantees and performance characteristics.

Features ✨

  • Safe Inheritance: Implement class hierarchies with compile-time safety guarantees
  • Runtime Type Information: Robust RTTI system for type checking and reflection
  • Smart Downcasting: Safe and ergonomic downcasting between types in the hierarchy
  • Reflection API: Optional reflection system for runtime introspection
  • Serialization Support: Optional integration with serde for serialization
  • Zero-Cost Abstractions: Most features compile away to zero overhead
  • Game Engine Ready: Designed for high-performance game development scenarios

Quick Start 🚀

Add Dynasty to your Cargo.toml:

[dependencies]
dynasty = "0.1.0"

Create your class hierarchy:

use dynasty::prelude::*;

// Define a base class
#[derive(Class, Debug)]
pub struct Entity {
    id: u64,
    name: String,
}

// Create a derived class
#[inherit(Entity)]
#[derive(Debug)]
pub struct Character {
    base: Entity,
    health: f32,
    level: u32,
}

// Multiple levels of inheritance
#[inherit(Character)]
#[derive(Debug)]
pub struct Player {
    base: Character,
    experience: u32,
}

fn main() {
    // Create instances
    let player = Player {
        base: Character {
            base: Entity {
                id: 1,
                name: "Hero".to_string(),
            },
            health: 100.0,
            level: 1,
        },
        experience: 0,
    };

    // Use safe downcasting
    let as_character: &Character = player.as_parent();
    println!("Character level: {}", as_character.level);
}

Advanced Features 🛠️

Reflection

Enable the reflection feature to access runtime type information:

[dependencies]
dynasty = { version = "0.1.0", features = ["reflection"] }
use dynasty::prelude::*;

#[derive(Class)]
struct Transform {
    position: (f32, f32, f32),
}

// Implement reflection
impl Reflect for Transform {
    fn get_field(&self, name: &str) -> Option<&dyn Any> {
        match name {
            "position" => Some(&self.position),
            _ => None,
        }
    }
    
    // TODO: implement other reflection methods
}

Serialization

Enable serialization support:

[dependencies]
dynasty = { version = "0.1.0", features = ["serialization"] }
use dynasty::prelude::*;
use serde::{Serialize, Deserialize};

#[derive(Class, Serialize, Deserialize)]
struct GameObject {
    id: u64,
    components: Vec<Box<dyn Component>>,
}

Project Structure 📁

Dynasty is organized as a workspace with two main crates:

  • dynasty: The core runtime library providing the inheritance system
  • dynasty-macros: Procedural macros for the derive and attribute implementations

Performance 🚄

Dynasty is designed with performance in mind:

  • Zero-cost abstractions for most features
  • Compile-time resolution of inheritance relationships
  • Minimal runtime overhead for type checking
  • Efficient virtual dispatch using Rust's trait system

Examples 📚

Check out these examples to see Dynasty in action:

Component System

use dynasty::prelude::*;

#[derive(Class)]
struct Component {
    enabled: bool,
}

#[inherit(Component)]
struct RigidBody {
    base: Component,
    mass: f32,
    velocity: (f32, f32, f32),
}

#[inherit(Component)]
struct MeshRenderer {
    base: Component,
    mesh: String,
    material: String,
}

Event System

use dynasty::prelude::*;

#[derive(Class)]
struct Event {
    timestamp: f64,
}

#[inherit(Event)]
struct CollisionEvent {
    base: Event,
    entity_a: u64,
    entity_b: u64,
    point: (f32, f32, f32),
}

Contributing 🤝

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

To get started:

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License 📝

Licensed under either of:

at your option.

Acknowledgments 🙏

  • Built with and for the Rust community
  • Special thanks to all contributors

Built with ❤️ by Tristan J. Poland

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Rust 100.0%