An unofficial collection of APIs used in FreeJam games and mods
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

entity_traits.rs 962B

1234567891011121314151617181920212223242526
  1. use std::io::{Read, Write};
  2. /// Standard trait for parsing Techblox game save data.
  3. pub trait Parsable {
  4. /// Process information from raw data.
  5. fn parse(reader: &mut dyn Read) -> std::io::Result<Self> where Self: Sized;
  6. /// Convert struct data back into raw bytes
  7. fn dump(&self, writer: &mut dyn Write) -> std::io::Result<usize>;
  8. }
  9. /// Entity descriptor containing serialized components.
  10. pub trait SerializedEntityDescriptor: Parsable {
  11. /// Count of entity components that this descriptor contains
  12. fn serialized_components() -> u8 where Self: Sized;
  13. /// Components that this entity is comprised of
  14. fn components<'a>(&'a self) -> Vec<&'a dyn SerializedEntityComponent>;
  15. }
  16. /// Serializable entity component.
  17. /// Components are the atomic unit of entities.
  18. pub trait SerializedEntityComponent: Parsable {
  19. /// Raw size of struct, in bytes.
  20. fn size() -> usize where Self: Sized {
  21. std::mem::size_of::<Self>()
  22. }
  23. }