public void TestRemoveInMiddle() { var b = new RenderingBlock(); Int3 u = new Int3(1, 2, 3); Int3 v = new Int3(4, 5, 6); Int3 w = new Int3(0, 0, 0); b.Set(u, Matrix4x4.identity); b.Set(v, Matrix4x4.identity); b.Set(w, Matrix4x4.identity); // u, v, w Assert.AreEqual(3, b.GetNumOccupied()); Assert.IsTrue(b.CheckInvariants()); b.Clear(v); // u, w Assert.AreEqual(2, b.GetNumOccupied()); Assert.IsTrue(b.CheckInvariants()); b.Set(v, Matrix4x4.identity); // u, w, v Assert.AreEqual(3, b.GetNumOccupied()); Assert.IsTrue(b.CheckInvariants()); b.Clear(u); // w, v Assert.AreEqual(2, b.GetNumOccupied()); Assert.IsTrue(b.CheckInvariants()); b.Set(u, Matrix4x4.identity); // w, v, u Assert.AreEqual(3, b.GetNumOccupied()); Assert.IsTrue(b.CheckInvariants()); b.Clear(u); b.Clear(v); b.Clear(w); Assert.AreEqual(0, b.GetNumOccupied()); Assert.IsTrue(b.CheckInvariants()); }
// TODO possible optimization: keep a pool of rendering blocks, so if we // fully clear a block, we don't just toss it to garbage or leave the // memory wasted. public void Clear(Int3 u) { Int3 blockNum = Int3.Floor(u / Lf); RenderingBlock block = null; if (!blocksTable.TryGetValue(blockNum, out block)) { return; } Int3 blockCell = u - (blockNum * L); Debug.Assert(blockCell.x >= 0); Debug.Assert(blockCell.x < L); Debug.Assert(blockCell.y >= 0); Debug.Assert(blockCell.y < L); Debug.Assert(blockCell.z >= 0); Debug.Assert(blockCell.z < L); block.Clear(blockCell); // TODO if a block is totally cleared, free it (back into a pool!) }