Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reworks system and devices #9

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

JomerDev
Copy link

This PR reworks system so wrapping every device in Device is no longer needed.
Device is now a type of Rc<RefCell<dyn DynDevice>> where DynDevice is trait DynDevice: Any + 'static + Transmutable.
That way the Transmutable methods can be called on the new Device type, making it work very similarly to the old one.
It also allows access to any device added to a system by calling get_device or get_device_by_name on the system, with the type of the device as a generic. The generic is checked against the type id of the dyn DynDevice and will error out if they don't match, a cast to a different device by accident is not possible. This system is used in the deno projects core for a resource table whic is used extensively.
DynDevice is implemented for every type that implements Transmutable + 'static, so devices do not have to implement it manually.
Adding a new device to the system now returns a DeviceId which can be used to get access to the device again. If the id is unknown, devices can also be found through their set name (if they have one).

The event queue and debuggables list now both hold device ids instead of the device directly.
There is now a DeviceSettings struct which can be used when adding a device to a system. Methods like add_addressable_device, add_interruptable_device, add_peripheral still exists but use DeviceSettings internaly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant