public Region(VoxWorld w) { World = w; loc = Point.Zero; // Create Empty Region voxels = new Voxel[VOXEL_COUNT]; for(int i = 0; i < VOXEL_COUNT; i++) voxels[i] = Voxel.Empty; // Non-calculated Boundaries rBS = new RegionBoundaryState[4]; for(int i = 0; i < 4; i++) rBS[i] = new RegionBoundaryState(); // No Neighbors rNX = rPX = rNZ = rPZ = null; }
public Region(VoxWorld w) { World = w; loc = Point.Zero; // Create Empty Region voxels = new Voxel[VOXEL_COUNT]; for (int i = 0; i < VOXEL_COUNT; i++) { voxels[i] = Voxel.Empty; } // Non-calculated Boundaries rBS = new RegionBoundaryState[4]; for (int i = 0; i < 4; i++) { rBS[i] = new RegionBoundaryState(); } // No Neighbors rNX = rPX = rNZ = rPZ = null; }
public VoxState() { World = new VoxWorld(this); VWorkPool = new VoxWorkPool(); eQueue = new List<VEvent>(4); }
public abstract void LESave(VoxWorld world, int w, int h, DirectoryInfo dir);
public override void LESave(VoxWorld world, int w, int h, DirectoryInfo dir) { // Create File FileInfo fi = new FileInfo(dir.FullName + @"\env.dat"); BinaryWriter s = new BinaryWriter(fi.Create()); // Search Through Columns Vector3I loc = Vector3I.Zero; for(loc.Z = 0; loc.Z < h; loc.Z++) { for(loc.X = 0; loc.X < w; loc.X++) { loc.Y = 0; VoxLocation vl = new VoxLocation(loc); Region r = world.regions[vl.RegionIndex]; // Search Through The Region int type; for(; vl.VoxelLoc.Y < Region.HEIGHT; vl.VoxelLoc.Y++) { ushort id = r.voxels[vl.VoxelIndex].ID; if(id < minID || id > maxID) continue; // Write Team And Type type = id - minID; s.Write(type); s.Write(loc.X); s.Write(loc.Z); break; } } } s.Write(-1); // Flush And Close s.Flush(); s.BaseStream.Dispose(); }
void OnRegionRemoval(VoxWorld w, Region r) { lock(activeRegions) { activeRegions.Remove(r); } }
void OnRegionAddition(VoxWorld w, Region r) { lock(activeRegions) { activeRegions.Add(r); } }
public static ColumnResult GetColumn(VoxWorld vw, int x, int z, int w, int h, IVoxGridResolver vgr) { VoxLocation vl = new VoxLocation(new Vector3I(x, Region.HEIGHT - 1, z)); ColumnResult cr = new ColumnResult(); ushort id; // Get Height Information cr.Height = new RTSEngine.Data.HeightTile(); Region r = vw.regions[vl.RegionIndex]; int ramp; for(; vl.VoxelLoc.Y > 0; vl.VoxelLoc.Y--) { id = r.voxels[vl.VoxelIndex].ID; if(vgr.TryGetFlat(id)) { cr.Height.XNZN = vl.VoxelLoc.Y + 1; cr.Height.XPZN = vl.VoxelLoc.Y + 1; cr.Height.XNZP = vl.VoxelLoc.Y + 1; cr.Height.XPZP = vl.VoxelLoc.Y + 1; break; } else if(vgr.TryGetRamp(id, out ramp)) { switch(ramp) { case 0: cr.Height.XNZN = vl.VoxelLoc.Y + 1; cr.Height.XPZN = vl.VoxelLoc.Y + 0; cr.Height.XNZP = vl.VoxelLoc.Y + 1; cr.Height.XPZP = vl.VoxelLoc.Y + 0; break; case 1: cr.Height.XNZN = vl.VoxelLoc.Y + 0; cr.Height.XPZN = vl.VoxelLoc.Y + 1; cr.Height.XNZP = vl.VoxelLoc.Y + 0; cr.Height.XPZP = vl.VoxelLoc.Y + 1; break; case 2: cr.Height.XNZN = vl.VoxelLoc.Y + 1; cr.Height.XPZN = vl.VoxelLoc.Y + 1; cr.Height.XNZP = vl.VoxelLoc.Y + 0; cr.Height.XPZP = vl.VoxelLoc.Y + 0; break; case 3: cr.Height.XNZN = vl.VoxelLoc.Y + 0; cr.Height.XPZN = vl.VoxelLoc.Y + 0; cr.Height.XNZP = vl.VoxelLoc.Y + 1; cr.Height.XPZP = vl.VoxelLoc.Y + 1; break; } if(vl.VoxelLoc.Y > 0) vl.VoxelLoc.Y--; break; } } // Get Wall Information cr.Walls = 0x00; if(x == 0) { cr.Walls |= CollisionGrid.Direction.XN; } else { Point hi = vgr.HeightIndex(vw, x, z, 0); Point hin = vgr.HeightIndex(vw, x - 1, z, 1); if(hin != hi) cr.Walls |= CollisionGrid.Direction.XN; } if(x == w - 1) { cr.Walls |= CollisionGrid.Direction.XP; } else { Point hi = vgr.HeightIndex(vw, x, z, 1); Point hin = vgr.HeightIndex(vw, x + 1, z, 0); if(hin != hi) cr.Walls |= CollisionGrid.Direction.XP; } if(z == 0) { cr.Walls |= CollisionGrid.Direction.ZN; } else { Point hi = vgr.HeightIndex(vw, x, z, 2); Point hin = vgr.HeightIndex(vw, x, z - 1, 3); if(hin != hi) cr.Walls |= CollisionGrid.Direction.ZN; } if(z == h - 1) { cr.Walls |= CollisionGrid.Direction.ZP; } else { Point hi = vgr.HeightIndex(vw, x, z, 3); Point hin = vgr.HeightIndex(vw, x, z + 1, 2); if(hin != hi) cr.Walls |= CollisionGrid.Direction.ZP; } if((cr.Walls & CollisionGrid.Direction.XN) != 0 && (cr.Walls & CollisionGrid.Direction.ZN) != 0) cr.Walls |= CollisionGrid.Direction.XNZN; if((cr.Walls & CollisionGrid.Direction.XP) != 0 && (cr.Walls & CollisionGrid.Direction.ZN) != 0) cr.Walls |= CollisionGrid.Direction.XPZN; if((cr.Walls & CollisionGrid.Direction.XN) != 0 && (cr.Walls & CollisionGrid.Direction.ZP) != 0) cr.Walls |= CollisionGrid.Direction.XNZP; if((cr.Walls & CollisionGrid.Direction.XP) != 0 && (cr.Walls & CollisionGrid.Direction.ZP) != 0) cr.Walls |= CollisionGrid.Direction.XPZP; return cr; }
public static void ParseVoxels(VoxWorld vw, string file) { // Set Voxel Data byte[] data; using(var s = File.OpenRead(file)) { // Read How Much Data To Allocate var br = new BinaryReader(s); int l = br.ReadInt32(); // Decompress Data data = new byte[l]; var gs = new GZipStream(s, CompressionMode.Decompress); gs.Read(data, 0, data.Length); } // Convert Data int i = 0; int x = BitConverter.ToInt32(data, i); i += 4; int z = BitConverter.ToInt32(data, i); i += 4; Vector3I loc = Vector3I.Zero; Region rN; for(loc.Z = 0; loc.Z < z; loc.Z++) { for(loc.X = 0; loc.X < x; loc.X++) { loc.Y = 0; VoxLocation vl = new VoxLocation(loc); var r = vw.regions[vl.RegionIndex]; if(r == null) { // Check If The Region Needs To Be Loaded r = vw.TryCreateRegion(vl.RegionLoc.X, vl.RegionLoc.Y); int rx = vl.RegionLoc.X; int rz = vl.RegionLoc.Y; if(r == null) continue; // Look For Neighbors rN = vw.pager.Obtain(rx - 1, rz); if(rN != null) { r.rNX = rN; rN.rPX = r; } rN = vw.pager.Obtain(rx + 1, rz); if(rN != null) { r.rPX = rN; rN.rNX = r; } rN = vw.pager.Obtain(rx, rz - 1); if(rN != null) { r.rNZ = rN; rN.rPZ = r; } rN = vw.pager.Obtain(rx, rz + 1); if(rN != null) { r.rPZ = rN; rN.rNZ = r; } vw.regions[vl.RegionIndex] = r; } // Read Scenery while(true) { int scen = BitConverter.ToInt32(data, i); i += 4; if(scen == -1) break; int ri = BitConverter.ToInt32(data, i); i += 4; int vi = BitConverter.ToInt32(data, i); i += 4; vw.regions[ri].voxels[vi].ID = (ushort)(20 + scen); } int h = BitConverter.ToInt32(data, i); i += 4; int t = BitConverter.ToInt32(data, i); i += 4; switch(t) { case 0: // Terrain int terr = BitConverter.ToInt32(data, i) + 1; i += 4; for(vl.VoxelLoc.Y = 0; vl.VoxelLoc.Y <= h; vl.VoxelLoc.Y++) { r.SetVoxel(vl.VoxelLoc.X, vl.VoxelLoc.Y, vl.VoxelLoc.Z, (ushort)(terr + 10)); } if(h > 0) r.SetVoxel(vl.VoxelLoc.X, h, vl.VoxelLoc.Z, (ushort)(terr)); if(h > 1) r.SetVoxel(vl.VoxelLoc.X, h - 1, vl.VoxelLoc.Z, (ushort)(terr + 5)); break; case 1: // Ramp int ramp = BitConverter.ToInt32(data, i); i += 4; for(vl.VoxelLoc.Y = 0; vl.VoxelLoc.Y <= h; vl.VoxelLoc.Y++) { r.SetVoxel(vl.VoxelLoc.X, vl.VoxelLoc.Y, vl.VoxelLoc.Z, 11); } if(h > 0) r.SetVoxel(vl.VoxelLoc.X, h, vl.VoxelLoc.Z, (ushort)(ramp + 16)); if(h > 1) r.SetVoxel(vl.VoxelLoc.X, h - 1, vl.VoxelLoc.Z, 6); break; } r.NotifyFacesChanged(); } } for(int vi = 0; vi < 15; vi++) { var vd = vw.Atlas.Create(); vd.FaceType = new VoxFaceType(); vd.FaceType.SetAllTypes(0x00000001u); vd.FaceType.SetAllMasks(0xfffffffeu); } for(int vi = 0; vi < 4; vi++) { var vd = vw.Atlas.Create(); vd.FaceType = new VoxFaceType(); vd.FaceType.SetAllTypes(0x00000000u); vd.FaceType.Types[Voxel.FACE_PY] = 0xffffffffu; vd.FaceType.SetAllMasks(0xffffffffu); } for(int vi = 0; vi < 5; vi++) { var vd = vw.Atlas.Create(); vd.FaceType = new VoxFaceType(); vd.FaceType.SetAllTypes(0x00000001u); vd.FaceType.SetAllMasks(0xfffffffeu); } for(int vi = 0; vi < 5; vi++) { var vd = vw.Atlas.Create(); vd.FaceType = new VoxFaceType(); vd.FaceType.SetAllTypes(0x00000000u); vd.FaceType.Types[Voxel.FACE_PY] = 0xffffffffu; vd.FaceType.SetAllMasks(0xffffffffu); } }
public override void LESave(VoxWorld world, int w, int h, DirectoryInfo dir) { return; }
public override void LESave(VoxWorld world, int w, int h, DirectoryInfo dir) { // Create File FileInfo fi = new FileInfo(dir.FullName + @"\camera.dat"); BinaryWriter s = new BinaryWriter(fi.Create()); // Search Through Columns Vector3I loc = Vector3I.Zero; for(loc.Z = 0; loc.Z < h; loc.Z++) { for(loc.X = 0; loc.X < w; loc.X++) { loc.Y = 0; VoxLocation vl = new VoxLocation(loc); Region r = world.regions[vl.RegionIndex]; // Search Through The Region for(; vl.VoxelLoc.Y < Region.HEIGHT; vl.VoxelLoc.Y++) { ushort id = r.voxels[vl.VoxelIndex].ID; if(id == camID) { // Write Camera Position s.Write(loc.X); s.Write(vl.VoxelLoc.Y); s.Write(loc.Z); s.Flush(); s.BaseStream.Dispose(); return; } } } } // Flush And Close (No Data) s.Write(w / 2); s.Write((Grey.Vox.Region.HEIGHT * 3) / 4); s.Write(h / 2); s.Flush(); s.BaseStream.Dispose(); }