-
Notifications
You must be signed in to change notification settings - Fork 144
Expand file tree
/
Copy pathevent.rs
More file actions
42 lines (40 loc) · 1.12 KB
/
event.rs
File metadata and controls
42 lines (40 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use crate::context::{PluginContext, PluginPtr};
use crate::host_calls::component::{InsertComponentVisitor, SetComponentAction};
use anyhow::Context;
use feather_ecs::Entity;
use feather_plugin_host_macros::host_function;
use quill_common::HostComponent;
#[host_function]
pub fn entity_add_event(
cx: &PluginContext,
entity: u64,
event: u32,
bytes_ptr: PluginPtr<u8>,
bytes_len: u32,
) -> anyhow::Result<()> {
let entity = Entity::from_bits(entity);
let event = HostComponent::from_u32(event).context("invalid component")?;
let visitor = InsertComponentVisitor {
cx,
bytes_ptr,
bytes_len,
action: SetComponentAction::AddEntityEvent(entity),
};
event.visit(visitor)
}
#[host_function]
pub fn add_event(
cx: &PluginContext,
event: u32,
bytes_ptr: PluginPtr<u8>,
bytes_len: u32,
) -> anyhow::Result<()> {
let event = HostComponent::from_u32(event).context("invalid component")?;
let visitor = InsertComponentVisitor {
cx,
bytes_ptr,
bytes_len,
action: SetComponentAction::AddEvent,
};
event.visit(visitor)
}