Changeset - 79edbf0bebd7
[Not reviewed]
0 2 0
Christopher Esterhuyse - 5 years ago 2020-02-13 09:12:38
christopher.esterhuyse@gmail.com
bit business
2 files changed with 16 insertions and 0 deletions:
0 comments (0 inline, 0 general)
Cargo.toml
Show inline comments
 
[package]
 
name = "reowolf_rs"
 
version = "0.1.1"
 
authors = [
 
	"Christopher Esterhuyse <christopher.esterhuyse@gmail.com>",
 
	"Hans-Dieter Hiep <hdh@cwi.nl>"
 
]
 
edition = "2018"
 

	
 
[dependencies]
 
# hibitset = "0.6.2"
 

	
 
# runtime stuff
 
getrandom = "0.1.14" # tiny crate. used to guess controller-id
 
take_mut = "0.2.2"
 
maplit = "1.0.2" # convenience macros
 
indexmap = "1.3.0" # hashsets/hashmaps with efficient arbitrary element removal
 

	
 
# network stuff
 
integer-encoding = "1.0.7"
 
byteorder = "1.3.2"
 
mio = "0.6.21" # migrate to mio 0.7.0 when it stabilizes. It's much better.
 
mio-extras = "2.0.6"
 

	
 
# protocol stuff
 
id-arena = "2.2.1"
 
backtrace = "0.3"
 

	
 
[dev-dependencies]
 
test-generator = "0.3.0"
 
crossbeam-utils = "0.7.0"
 

	
 
[lib]
 
crate-type = ["cdylib"]
 

	
 
[features]
 
default = ["ffi"]
 
ffi = [] # no feature dependencies
 
\ No newline at end of file
src/runtime/ecs.rs
Show inline comments
 
@@ -137,51 +137,66 @@ impl<'a> NoneChunkIter<'a> {
 
    /// a set of bitsets. the u32s of each are in ascending order of significant digits
 
    /// i.e., &[0,1] means {1<<32, 0} while &[0,1] is identical to &[1] and means {1}.
 
    fn new(sets: &'a [&'a [u32]], max_bit: usize) -> Self {
 
        let sets = if sets.is_empty() { &[&[] as &[_]] } else { sets };
 
        Self { sets, next_chunk_index: 0, bits_to_go: max_bit }
 
    }
 
}
 
impl Iterator for NoneChunkIter<'_> {
 
    type Item = u32;
 
    fn next(&mut self) -> Option<u32> {
 
        let neutral = match self.bits_to_go {
 
            0 => None,
 
            x @ 1..=31 => Some(!0u32 >> (32 - x)),
 
            _ => Some(!0u32),
 
        };
 
        self.bits_to_go = self.bits_to_go.saturating_sub(32);
 

	
 
        let old_chunk_index = self.next_chunk_index;
 
        self.next_chunk_index += 1;
 

	
 
        self.sets.iter().fold(neutral, move |a, b| {
 
            let a = a?;
 
            let b = *b.get(old_chunk_index)?;
 
            Some(a & !b)
 
        })
 
    }
 
}
 

	
 
#[test]
 
fn test_bit_iter() {
 
    static SETS: &[&[u32]] = &[
 
        //
 
        &[0b101001, 0b101001],
 
        &[0b100001, 0b101001],
 
    ];
 
    let _ = BitChunkIter::new(AndChunkIter::new(SETS));
 
    let iter = BitChunkIter::new(NoneChunkIter::new(SETS, 9));
 
    let indices = iter.collect::<Vec<_>>();
 
    println!("indices {:?}", indices);
 
}
 

	
 
enum Entity {
 
    Payload(Payload),
 
    State(ProtocolS),
 
}
 

	
 
fn ecs() {
 
    let entities: Vec<Entity> = Default::default();
 
    // invariant: for all ChannelId c, assignments[(c, true)] & assignments[(c, false)] == 0;
 
    let assignments: HashMap<(ChannelId, bool), BitSet> = Default::default();
 
    // invariant: for all Keys k0 != k1, keys[k0] & keys[k1] == 0;
 
    let keys: HashMap<Key, BitSet> = Default::default();
 
    // invariant: for all Keys k, keys[k] & components == 0;
 
    let components: BitSet = Default::default();
 
    // invariant: to_run &!components = 0 i.e. to_run is a subset
 
    let to_run: BitSet = Default::default();
 

	
 
    // 1.
 
}
 

	
 
/*
 
needed operations:
 

	
 
1. insert a payload and overwrite / insert its predicate assignments
 
2. run all machines that
 
*/
0 comments (0 inline, 0 general)