Skip to content

Commit

Permalink
Upgrade to Flecs Core v4.0.3 (#208)
Browse files Browse the repository at this point in the history
[Rust] 

feat(iter): add fn targets to iterate targets for pair field

feat(observer_builder): observer flags

refact(world): get_ref take pairs

fix(module): module renaming not working in nested scenario's

feat(doc): add doc_uuid + refact(doc): remove get_ prefix

refactor(entity_view): add input assert validation to get_ref functions and correct assert in modified()

[C] 
+ core fixes of v4.0.3 see [Flecs change logs](https://github.com/SanderMertens/flecs/releases/tag/v4.0.3)
  • Loading branch information
Indra-db authored Nov 16, 2024
1 parent 0aeb130 commit 6ffa92e
Show file tree
Hide file tree
Showing 14 changed files with 1,360 additions and 317 deletions.
224 changes: 173 additions & 51 deletions flecs_ecs/src/addons/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ pub trait Doc<'a>: WorldProvider<'a> + Into<Entity> + Clone {
///
/// # See also
///
/// * [`World::get_doc_name()`]
/// * [`World::doc_name()`]
/// * C++ API: `doc::get_name()`
fn get_doc_name(&self) -> Option<String> {
self.world().get_doc_name_id(self.clone())
fn doc_name(&self) -> Option<String> {
self.world().doc_name_id(self.clone())
}

/// Get brief description for an entity.
Expand All @@ -50,10 +50,10 @@ pub trait Doc<'a>: WorldProvider<'a> + Into<Entity> + Clone {
///
/// # See also
///
/// * [`World::get_doc_brief()`]
/// * [`World::doc_brief()`]
/// * C++ API: `doc::get_brief()`
fn get_doc_brief(&self) -> Option<String> {
self.world().get_doc_brief_id(self.clone())
fn doc_brief(&self) -> Option<String> {
self.world().doc_brief_id(self.clone())
}

/// Get detailed description for an entity.
Expand All @@ -64,10 +64,10 @@ pub trait Doc<'a>: WorldProvider<'a> + Into<Entity> + Clone {
///
/// # See also
///
/// * [`World::get_doc_detail()`]
/// * [`World::doc_detail()`]
/// * C++ API: `doc::get_detail()`
fn get_doc_detail(&self) -> Option<String> {
self.world().get_doc_detail_id(self.clone())
fn doc_detail(&self) -> Option<String> {
self.world().doc_detail_id(self.clone())
}

/// Get link to external documentation for an entity.
Expand All @@ -78,10 +78,10 @@ pub trait Doc<'a>: WorldProvider<'a> + Into<Entity> + Clone {
///
/// # See also
///
/// * [`World::get_doc_link()`]
/// * [`World::doc_link()`]
/// * C++ API: `doc::get_link()`
fn get_doc_link(&self) -> Option<String> {
self.world().get_doc_link_id(self.clone())
fn doc_link(&self) -> Option<String> {
self.world().doc_link_id(self.clone())
}

/// Get color for an entity.
Expand All @@ -92,10 +92,28 @@ pub trait Doc<'a>: WorldProvider<'a> + Into<Entity> + Clone {
///
/// # See also
///
/// * [`World::get_doc_color()`]
/// * [`World::doc_color()`]
/// * C++ API: `doc::get_color()`
fn get_doc_color(&self) -> Option<String> {
self.world().get_doc_color_id(self.clone())
fn doc_color(&self) -> Option<String> {
self.world().doc_color_id(self.clone())
}

/// Get UUID for entity
///
/// # Returns
///
/// The UUID of the entity.
///
/// # See also
///
/// * [`World::doc_uuid_id()`]
/// * [`World::doc_uuid()`]
/// * [`Doc::set_doc_uuid()`]
/// * [`World::set_doc_uuid_id()`]
/// * [`World::set_doc_uuid()`]
/// * C++ API: `doc::get_uuid()`
fn doc_uuid(&self) -> Option<String> {
self.world().doc_uuid_id(self.clone())
}

//MARK: _setters
Expand Down Expand Up @@ -185,6 +203,26 @@ pub trait Doc<'a>: WorldProvider<'a> + Into<Entity> + Clone {
self.world().set_doc_color_id(self.clone(), color);
self
}

/// Set doc UUID.
/// This adds `(flecs.doc.Description, flecs.doc.Uuid)` to the entity.
///
/// # Arguments
///
/// * `uuid` - The UUID to add.
///
/// # See also
/// * [`World::set_doc_uuid_id()`]
/// * [`World::set_doc_uuid()`]
/// * [`World::doc_uuid()`]
/// * [`World::doc_uuid_id()`]
/// * [`Doc::doc_uuid()`]
/// * C++ API: `entity_builder::set_doc_uuid`
#[doc(alias = "entity_builder::set_doc_uuid")]
fn set_doc_uuid(&self, uuid: &str) -> &Self {
self.world().set_doc_uuid_id(self.clone(), uuid);
self
}
}

impl<'a, T> Doc<'a> for T where T: Into<Entity> + WorldProvider<'a> + Clone {}
Expand Down Expand Up @@ -215,13 +253,13 @@ impl World {
///
/// # See also
///
/// * [`Doc::get_doc_name()`]
/// * [`World::get_doc_name_id()`]
/// * [`Doc::doc_name()`]
/// * [`World::doc_name_id()`]
/// * C++ API: `doc::get_name()`
#[doc(alias = "doc::get_name")]
#[inline(always)]
pub fn get_doc_name<T: ComponentId>(&self) -> Option<String> {
self.get_doc_name_id(T::get_id(self))
pub fn doc_name<T: ComponentId>(&self) -> Option<String> {
self.doc_name_id(T::get_id(self))
}

/// Get human readable name for an entity.
Expand All @@ -236,12 +274,12 @@ impl World {
///
/// # See also
///
/// * [`Doc::get_doc_name()`]
/// * [`World::get_doc_name()`]
/// * [`Doc::doc_name()`]
/// * [`World::doc_name()`]
/// * C++ API: `world::get_doc_name()`
#[doc(alias = "doc::get_name")]
#[inline(always)]
pub fn get_doc_name_id(&self, entity: impl Into<Entity>) -> Option<String> {
pub fn doc_name_id(&self, entity: impl Into<Entity>) -> Option<String> {
let cstr = NonNull::new(
unsafe { sys::ecs_doc_get_name(self.world_ptr(), *entity.into()) } as *mut _,
)
Expand All @@ -261,13 +299,13 @@ impl World {
///
/// # See also
///
/// * [`Doc::get_doc_brief()`]
/// * [`World::get_doc_brief_id()`]
/// * [`Doc::doc_brief()`]
/// * [`World::doc_brief_id()`]
/// * C++ API: `doc::get_brief()`
#[doc(alias = "doc::get_brief")]
#[inline(always)]
pub fn get_doc_brief<T: ComponentId>(&self) -> Option<String> {
self.get_doc_brief_id(T::get_id(self))
pub fn doc_brief<T: ComponentId>(&self) -> Option<String> {
self.doc_brief_id(T::get_id(self))
}

/// Get brief description for an entity.
Expand All @@ -282,12 +320,12 @@ impl World {
///
/// # See also
///
/// * [`Doc::get_doc_brief()`]
/// * [`World::get_doc_brief()`]
/// * [`Doc::doc_brief()`]
/// * [`World::doc_brief()`]
/// * C++ API: `doc::get_brief`
#[doc(alias = "doc::get_brief")]
#[inline(always)]
pub fn get_doc_brief_id(&self, entity: impl Into<Entity>) -> Option<String> {
pub fn doc_brief_id(&self, entity: impl Into<Entity>) -> Option<String> {
let cstr = NonNull::new(
unsafe { sys::ecs_doc_get_brief(self.world_ptr(), *entity.into()) } as *mut _,
)
Expand All @@ -306,13 +344,13 @@ impl World {
///
/// # See also
///
/// * [`Doc::get_doc_detail()`]
/// * [`World::get_doc_detail_id()`]
/// * [`Doc::doc_detail()`]
/// * [`World::doc_detail_id()`]
/// * C++ API: `doc::get_detail()`
#[doc(alias = "doc::get_detail")]
#[inline(always)]
pub fn get_doc_detail<T: ComponentId>(&self) -> Option<String> {
self.get_doc_detail_id(T::get_id(self))
pub fn doc_detail<T: ComponentId>(&self) -> Option<String> {
self.doc_detail_id(T::get_id(self))
}

/// Get detailed description for an entity.
Expand All @@ -327,12 +365,12 @@ impl World {
///
/// # See also
///
/// * [`Doc::get_doc_detail()`]
/// * [`World::get_doc_detail()`]
/// * [`Doc::doc_detail()`]
/// * [`World::doc_detail()`]
/// * C++ API: `doc::get_detail`
#[doc(alias = "doc::get_detail")]
#[inline(always)]
pub fn get_doc_detail_id(&self, entity: impl Into<Entity>) -> Option<String> {
pub fn doc_detail_id(&self, entity: impl Into<Entity>) -> Option<String> {
let cstr = NonNull::new(
unsafe { sys::ecs_doc_get_detail(self.world_ptr(), *entity.into()) } as *mut _,
)
Expand All @@ -352,13 +390,13 @@ impl World {
///
/// # See also
///
/// * [`Doc::get_doc_link()`]
/// * [`World::get_doc_link_id()`]
/// * [`Doc::doc_link()`]
/// * [`World::doc_link_id()`]
/// * C++ API: `doc::get_link()`
#[doc(alias = "doc::get_link")]
#[inline(always)]
pub fn get_doc_link<T: ComponentId>(&self) -> Option<String> {
self.get_doc_link_id(T::get_id(self))
pub fn doc_link<T: ComponentId>(&self) -> Option<String> {
self.doc_link_id(T::get_id(self))
}

/// Get link to external documentation for an entity.
Expand All @@ -372,12 +410,12 @@ impl World {
///
/// # See also
///
/// * [`Doc::get_doc_link()`]
/// * [`World::get_doc_link()`]
/// * [`Doc::doc_link()`]
/// * [`World::doc_link()`]
/// * C++ API: `doc::get_link`
#[doc(alias = "doc::get_link")]
#[inline(always)]
pub fn get_doc_link_id(&self, entity: impl Into<Entity>) -> Option<String> {
pub fn doc_link_id(&self, entity: impl Into<Entity>) -> Option<String> {
let cstr = NonNull::new(
unsafe { sys::ecs_doc_get_link(self.world_ptr(), *entity.into()) } as *mut _,
)
Expand All @@ -396,13 +434,13 @@ impl World {
///
/// # See also
///
/// * [`Doc::get_doc_color()`]
/// * [`World::get_doc_color_id()`]
/// * [`Doc::doc_color()`]
/// * [`World::doc_color_id()`]
/// * C++ API: `doc::get_color()`
#[doc(alias = "doc::get_color")]
#[inline(always)]
pub fn get_doc_color<T: ComponentId>(&self) -> Option<String> {
self.get_doc_color_id(T::get_id(self))
pub fn doc_color<T: ComponentId>(&self) -> Option<String> {
self.doc_color_id(T::get_id(self))
}

/// Get color for an entity.
Expand All @@ -416,19 +454,55 @@ impl World {
///
/// # See also
///
/// * [`Doc::get_doc_color()`]
/// * [`World::get_doc_color()`]
/// * [`Doc::doc_color()`]
/// * [`World::doc_color()`]
/// * C++ API: `doc::get_color`
#[doc(alias = "doc::get_color")]
#[inline(always)]
pub fn get_doc_color_id(&self, entity: impl Into<Entity>) -> Option<String> {
pub fn doc_color_id(&self, entity: impl Into<Entity>) -> Option<String> {
let cstr = NonNull::new(
unsafe { sys::ecs_doc_get_color(self.world_ptr(), *entity.into()) } as *mut _,
)
.map(|s| unsafe { CStr::from_ptr(s.as_ptr()) });
cstr.and_then(|s| s.to_str().ok().map(|s| s.to_string()))
}

/// Get UUID for entity
///
/// # See Also
///
/// * [`World::doc_uuid()`]
/// * [`Doc::doc_uuid()`]
/// * [`World::set_doc_uuid_id()`]
/// * [`Doc::set_doc_uuid()`]
/// * C++ API: `doc::get_uuid`
#[doc(alias = "doc::get_uuid")]
pub fn doc_uuid_id(&self, entity: impl Into<Entity>) -> Option<String> {
let cstr = NonNull::new(
unsafe { sys::ecs_doc_get_uuid(self.world_ptr(), *entity.into()) } as *mut _,
)
.map(|s| unsafe { CStr::from_ptr(s.as_ptr()) });
cstr.and_then(|s| s.to_str().ok().map(|s| s.to_string()))
}

/// Get UUID for component
///
/// # Type Parameters
///
/// * `T` - The component.
///
/// # See Also
///
/// * [`World::doc_uuid_id()`]
/// * [`Doc::doc_uuid()`]
/// * [`World::set_doc_uuid_id()`]
/// * [`Doc::set_doc_uuid()`]
/// * C++ API: `doc::get_uuid`
#[doc(alias = "doc::get_uuid")]
pub fn doc_uuid<T: ComponentId>(&self) -> Option<String> {
self.doc_uuid_id(T::get_id(self))
}

//MARK: _World::setters

/// Add human-readable name to entity.
Expand Down Expand Up @@ -601,7 +675,7 @@ impl World {
unsafe { sys::ecs_doc_set_link(self.ptr_mut(), *entity.into(), link.as_ptr() as *const _) };
}

/// Add color to entity.
/// Add color to component.
///
/// UIs can use color as hint to improve visualizing entities.
///
Expand Down Expand Up @@ -646,6 +720,54 @@ impl World {
sys::ecs_doc_set_color(self.ptr_mut(), *entity.into(), color.as_ptr() as *const _);
};
}

/// Add UUID to entity.
/// This adds `(flecs.doc.Description, flecs.doc.Uuid)` to the entity.
///
/// # Arguments
///
/// * `entity` - The entity to which to add the UUID.
/// * `uuid` - The UUID to add.
///
/// # See also
///
/// * [`Doc::set_doc_uuid()`]
/// * [`World::set_doc_uuid()`]
/// * [`World::doc_uuid()`]
/// * [`World::doc_uuid_id()`]
/// * [`Doc::doc_uuid()`]
/// * C++ API: `entity_builder::set_doc_uuid`
#[doc(alias = "entity_builder::set_doc_uuid")]
pub fn set_doc_uuid_id(&self, entity: impl Into<Entity>, uuid: &str) {
let uuid = compact_str::format_compact!("{}\0", uuid);
unsafe {
sys::ecs_doc_set_uuid(self.ptr_mut(), *entity.into(), uuid.as_ptr() as *const _);
};
}

/// Add UUID to component
/// This adds `(flecs.doc.Description, flecs.doc.Uuid)` to the component
///
/// # Type Parameters
///
/// * `T` - The component.
///
/// # Arguments
///
/// * `uuid` - The UUID to add.
///
/// # See also
///
/// * [`World::set_doc_uuid_id()`]
/// * [`Doc::set_doc_uuid()`]
/// * [`World::doc_uuid()`]
/// * [`World::doc_uuid_id()`]
/// * [`Doc::doc_uuid()`]
/// * C++ API: `entity_builder::set_doc_uuid`
#[doc(alias = "entity_builder::set_doc_uuid")]
pub fn set_doc_uuid<T: ComponentId>(&self, uuid: &str) {
self.set_doc_uuid_id(T::get_id(self), uuid);
}
}

#[test]
Expand Down
Loading

0 comments on commit 6ffa92e

Please sign in to comment.