13次发布
0.3.52 | 2024年7月26日 |
---|---|
0.3.51 | 2024年7月26日 |
0.3.25 | 2024年4月12日 |
0.2.3 | 2024年4月11日 |
0.1.0 | 2024年4月11日 |
#619 in 游戏开发
347 每月下载量
40KB
829 行
Forged in Lost Lands
Forged in Lost Lands是一个简单的Rust游戏引擎,专注于数据控制和易用性。它提供了一个简单的API来管理游戏对象、特质、事件和协程。
特性 数据控制:使用Rust的强类型和数据所有权模型轻松管理游戏数据。
虚幻流程:利用虚幻流程系统来管理游戏对象层次和行为。事件处理:通过命运裂缝处理游戏事件。线程管理:使用灵魂线程来管理游戏逻辑和协程任务。ForgedTrait:为您的特质设置在每次更新中执行的行为。EonForge:包含与您的应用程序时间控制相关的一切。ArcaneWeft:提供一种方式来分离您的逻辑,类似于插件系统。ForgedObject:每个需要更新其特质的实体的核心。
简单使用:设计得简单易用,便于集成到您的Rust游戏项目中。
重要
此引擎默认不包含渲染功能,您需要选择一个您喜欢的并与之一起使用!
安装 要在Rust项目中使用Forged in Lost Lands,请简单地将以下行添加到您的Cargo.toml文件中
[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