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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#![feature(associated_type_defaults)]

extern crate ioc;
#[macro_use] extern crate downcast;
//extern crate rustc_serialize;

mod primitives;
mod service;

mod store;
mod id_manager;
mod buffer;

mod idmgr_mode;
mod process;

mod simulation;

pub use primitives::*;

pub use service::*;
pub use store::*;
pub use id_manager::*;
pub use buffer::*;

pub use idmgr_mode::*;
pub use process::*;

pub use simulation::*;

pub mod prelude {
    pub use store::{
        StoreBase, ComponentStore, ComponentStoreIter, 
        EntityStore, EntityStoreIter, StoreWithDirtyState,
        _ComponentStore, _ComponentStoreIter, _EntityStoreIter, _StoreWithDirtyState,
    };
    pub use buffer::{
        BufferBase, EventBuffer, 
        _EventBuffer,
    };
    pub use id_manager::PrimaryIdManager;
}

pub mod macros;

// ++++++++++++++++++++ destroy_entity ++++++++++++++++++++

use std::fmt::Debug;

/// Safe abstraction for destroying a single entity. 
///
/// Returns `true` if successful, does nothing and returns `false` if `id` couldn't be 
/// validated.
pub fn destroy_entity<IdMgr, Key, StoBase: ?Sized>(
    ids: &mut IdMgr,
    stores: &mut ioc::ServiceWriteGuardMap<Key, StoBase>,
    id: IdMgr::Id,
) -> bool 
where
    Key: Debug + Ord, 
    IdMgr: PrimaryIdManager, 
    StoBase: StoreBase<Id = IdMgr::Id>,
{
    match ids.validate(id) {
        Some(v_id) => {
            for (_, store) in stores { 
                store.release_drop(v_id);
            }
        }
        None => return false
    }
    unsafe { ids.invalidate(id) }
}