#游戏引擎 #控制 #锻造 #简易 #失落 #构建 #聚焦

prime-derived

Forged in Lost Lands 是一个简单的 Rust 游戏引擎,专注于数据控制和易用性

8 个版本

0.3.21 2024年4月12日
0.3.2 2024年4月12日
0.2.3 2024年4月12日
0.1.0 2024年4月11日

#1800游戏开发


用于 ForgedInLostLands

MIT 许可证

36KB
885

Forged in Lost Lands

替代文本Forged in Lost Lands 是一个简单的 Rust 游戏引擎,专注于数据控制和易用性。它提供了一个简单的 API 来管理游戏对象、特性、事件和协程。

特性 数据控制:使用 Rust 强类型和数据所有模型轻松管理游戏数据。

虚幻流程:利用虚幻流程系统来管理游戏对象层次和行为。事件处理:通过命运裂隙处理游戏事件。线程管理:使用灵魂线程管理游戏逻辑和协程任务。ForgetTrait:设置将在每次更新中执行的特性行为。EonForge:包含与应用程序时间控制相关的所有内容。ArcaneWeft:提供一种方式,可以将逻辑分散到多个文件,就像插件系统一样。ForgedObject:每个需要更新特性的实体的核心。

简单使用:设计用于简单易用,并集成到您的 Rust 游戏项目中。

重要

此引擎默认没有渲染功能,您需要选择一个您喜欢的并与之一起使用!

安装

[dependencies]
forged-in-lost-lands = "0.3.3"

示例用法 rust

// Important imports
use prime_derived::{hierarchy_ethereal_flow, DestinyRiftArcaneScript, EtherealFlowArcaneScript};
use prime_forge::{
    arcane_weft::ArcaneWeft, forged_trait::ForgedTrait, lost_realm::LostRealm, soul_thread::{EssenceAspect, SoulThread, TemporalPause}
};

// Use of proc_macro for some internals and attribute macro for some hierarchical features. 
#[hierarchy_ethereal_flow]
struct Player {
    name: String,
    health: i32,
}

// Give behavior to your forged object
impl ForgedTrait for Player {
    fn start(&mut self, lost_realm: &mut LostRealm) {
        lost_realm.forge_new_object("Player", (Player::default(), Health::default())).unwrap();
    }

    fn update(&mut self, _lost_realm: &mut LostRealm, _dt: f32) {
        println!("Player Update");
    }
}

#[hierarchy_ethereal_flow]
pub struct Health {
    pub health: i32,
}

impl ForgedTrait for Health {
   
}

// Define some custom events to your game or application
#[derive(DestinyRiftArcaneScript, EtherealFlowArcaneScript)]
pub struct Collision(bool);


// Define plugins for a better organization
pub struct ArcaneWeftCreation;
impl ArcaneWeft for ArcaneWeftCreation{
    fn craft(self, lost_realm: &mut LostRealm) {
        lost_realm.add_destiny_rift_event(Collision(true));
        lost_realm.forge_new_object("Player", (Player::default(), Health::default())).unwrap();
        println!("Arcane Weft Creation")
    }
}

fn main() {
    use nalgebra_glm as glm;
    let lost_realm = LostRealm::new();
    let health = Health {
        health: 100,
        ..Default::default()
    };
    let player = Player {
        name: "Player".to_string(),
        health: 100,
        ..Default::default()
    };

    let f2 = lost_realm.forge_new_object("Forged1", (health,)).unwrap();
    let health = Health {
        health: 100,
        ..Default::default()
    };
    let f = lost_realm
        .forge_new_object("Forged", (player, health))
        .unwrap();
    f.transform.borrow_mut().position += glm::vec3(1.0, 0.0, 0.0);
    f2.transform.borrow_mut().position += glm::vec3(1.0, 0.0, 0.0);

    f.set_transform_parent(f2.transform.clone());
    f.transform.borrow_mut().update_self_and_children();

    let h = f.get_trait::<Health>().unwrap();
    let father = lost_realm.get_mut_parent_forged_object(h).unwrap();
    println!("Father: {:?}", father.name);

    let p = lost_realm.get_mut_trait_by_type::<Player>().unwrap();
    println!("Player: {:?}", p.name);
    let father = lost_realm.get_mut_parent_forged_object(p).unwrap();
    println!("Father: {:?}", father.name);

    let all_forged_object_by_health_traits = lost_realm.get_mut_all_forged_objects_by_trait::<Health>();
    for fo in all_forged_object_by_health_traits {
        println!("Forged Object: {:?}", fo.name);
        fo.name += "!";
    }

    let all_health_traits = lost_realm.get_mut_all_trait_by_type::<Health>();
    for health in all_health_traits {
        println!("Health: {:?}", health.health);
        health.health += 100;
    }

    let all_forged_object_by_health_traits = lost_realm.get_all_forged_objects_by_trait::<Health>();
    for fo in all_forged_object_by_health_traits {
        println!("Forged Object: {:?}", fo.name);
    }

    let all_health_traits = lost_realm.get_all_trait_by_type::<Health>();
    for health in all_health_traits {
        println!("Health: {:?}", health.health);
    }

    

    lost_realm.add_destiny_rift_event(Collision(true));
    let rs = lost_realm.consume_destiny_rift_event::<Collision>();
    if let Some(rs) = rs {
        println!("Collision: {:?}", rs.0);
    }
    let mut counter = 10;

    // Invoke coroutines
    lost_realm.add_soul_thread(SoulThread::new("Soul", move || {
        println!("Soul thread");
        counter -= 1;
        if counter == 0 {
            println!("Soul thread finished");
            return EssenceAspect::Finished;
        }
        return EssenceAspect::Yielded(TemporalPause {
            amount_in_seconds: 1.0,
        });
    }));

    lost_realm.arcane_weft_craft(ArcaneWeftCreation);

    // Get time related measures
    // need to pass current time to EonForge in update method
    let dt = lost_realm.get_delta_time();
    let time_since_start = lost_realm.get_time_elapsed();
    println!("Delta Time: {:?}", dt);
    println!("Time Since Start: {:?}", time_since_start);

    
    lost_realm.start();
    lost_realm.debug_update();
}

许可证 Forged in Lost Lands 采用 MIT 许可证。有关详细信息,请参阅 LICENSE。

依赖项

~4.5MB
~87K SLoC