void moveEntity(ent.EntityId id) { var(tx, entOpt) = m_db.checkout(id); using ( tx ) { if (!entOpt.HasValue) { return; } var ent = entOpt.ValueOr((ent.Entity)null); var physOpt = ent.com <ent.ComPhysics>(); physOpt.Match((phys) => { // TODO METRICS var scaledVel = Vec.Multiply(phys.vel, 1.0f / 60.0f); var newPos = Vec.Add(phys.pos, scaledVel); var newPosOpt = newPos.Value.Some(); var newPhys = phys.with(posOpt: newPosOpt); //var newComs = ent.m_coms.Replace( phys, newPhys ) //ent.with() }, () => { // TODO METRICS }); } }
void createRandomEntity() { // TODO Generalize spawn system { var comHealth = ent.ComHealth.create(m_healthOpt: 100.0f.Some()); var minPos = util.Vec.create(-200, -200, -200, 0); var maxPos = util.Vec.create(200, 200, 200, 0); var minVel = util.Vec.create(-1, -1, 0, 0); var maxVel = util.Vec.create(1, 1, 0, 0); var pos = util.Vec.randInBox(minPos, maxPos); var vel = util.Vec.randInBox(minVel, maxVel); var comPhysics = ent.ComPhysics.create(posOpt: pos.Some(), velOpt: vel.Some()); var nComs = ImmutableDictionary <Type, ent.Component> .Empty .Add(comHealth.GetType(), comHealth) .Add(comPhysics.GetType(), comPhysics); var ent1 = ent.Entity.create(m_comsOpt: nComs.Some()); //, m_nzOpt: nz.Some() ); ent.EntityId newId = ent1.id; using var tx = m_db.checkout(); tx.add(ent1); } }