Example #1
0
        public static VoxLocation? GetOuter(Ray camRay, VoxState state)
        {
            camRay.Position -= new Vector3(state.World.worldMin.X * Region.WIDTH, 0, state.World.worldMin.Y * Region.DEPTH);
            VRay vr = new VRay(camRay.Position, camRay.Direction);
            Vector3I loc = vr.GetNextLocation();

            // Check For World Intersect
            BoundingBox bb = new BoundingBox(Vector3.Zero, new Vector3(VoxWorld.WIDTH * Region.WIDTH, Region.HEIGHT, VoxWorld.DEPTH * Region.DEPTH));
            if(!camRay.Intersects(bb).HasValue) return null;

            // Move In World
            while(!IsInBounds(loc))
                loc = vr.GetNextLocation();

            // Move Through World
            VoxLocation pvl = new VoxLocation(loc);
            while(IsInBounds(loc)) {
                VoxLocation vl = new VoxLocation(loc);
                Region region = state.World.regions[vl.RegionIndex];
                if(region != null) {
                    ushort id = region.voxels[vl.VoxelIndex].ID;
                    if(id != 0) return pvl;
                }
                loc = vr.GetNextLocation();
                pvl = vl;
            }
            return null;
        }
Example #2
0
        public VoxWorld(VoxState s)
        {
            // Reference The State
            state = s;

            // Start With World Near The Center
            worldMin = new Point(-WIDTH / 2, -DEPTH / 2);

            // No Regions To Add Yet
            regions = new Region[REGION_COUNT];
            Array.Clear(regions, 0, REGION_COUNT);
            pager = new RegionPager();

            // Create An Empty Atlas
            Atlas = new VoxAtlas();
        }
Example #3
0
 public override void OnMouseClick(VoxState s, FreeCamera camera, Vector2 mPos, MouseButton button, Viewport vp)
 {
     List<VoxLocation> locs = new List<VoxLocation>();
     if(button == MouseButton.Left) {
         foreach(var r in GetRays(mPos, Vector2.One * 1, new Point(39, 39), camera, vp)) {
             VoxLocation? vl = VRayHelper.GetInner(r, s);
             if(vl.HasValue) locs.Add(vl.Value);
         }
         foreach(var loc in locs.Distinct())
             s.World.regions[loc.RegionIndex].RemoveVoxel(loc.VoxelLoc.X, loc.VoxelLoc.Y, loc.VoxelLoc.Z);
     }
     else if(button == MouseButton.Right) {
         foreach(var r in GetRays(mPos, Vector2.One * 1, new Point(39, 39), camera, vp)) {
             VoxLocation? vl = VRayHelper.GetOuter(r, s);
             if(vl.HasValue) locs.Add(vl.Value);
         }
         foreach(var loc in locs.Distinct())
             s.World.regions[loc.RegionIndex].AddVoxel(loc.VoxelLoc.X, loc.VoxelLoc.Y, loc.VoxelLoc.Z, CurVoxID);
     }
 }
Example #4
0
        public static VoxLocation? GetLevel(Ray camRay, VoxState state, int h)
        {
            camRay.Position -= new Vector3(state.World.worldMin.X * Region.WIDTH, 0, state.World.worldMin.Y * Region.DEPTH);
            VRay vr = new VRay(camRay.Position, camRay.Direction);
            Vector3I loc = vr.GetNextLocation();

            // Check For World Intersect
            BoundingBox bb = new BoundingBox(new Vector3(0, h - 1, 0), new Vector3(VoxWorld.WIDTH * Region.WIDTH, h, VoxWorld.DEPTH * Region.DEPTH));
            if(!camRay.Intersects(bb).HasValue) return null;

            // Move In World
            while(!IsInBounds(loc))
                loc = vr.GetNextLocation();

            // Move Through World
            while(IsInBounds(loc)) {
                VoxLocation vl = new VoxLocation(loc);
                Region region = state.World.regions[vl.RegionIndex];
                ushort id = region.voxels[vl.VoxelIndex].ID;
                if(loc.Y == h) return vl;
                loc = vr.GetNextLocation();
            }
            return null;
        }
Example #5
0
 public override void OnMouseClick(VoxState s, FreeCamera camera, Vector2 mPos, MouseButton button, Viewport vp)
 {
     Ray r = camera.GetViewRay(mPos, vp.Width, vp.Height);
     if(button == MouseButton.Left) {
         VoxLocation? vl = VRayHelper.GetInner(r, s);
         if(vl.HasValue) {
             var loc = vl.Value;
             s.World.regions[loc.RegionIndex].RemoveVoxel(loc.VoxelLoc.X, loc.VoxelLoc.Y, loc.VoxelLoc.Z);
         }
     }
     else if(button == MouseButton.Right) {
         VoxLocation? vl = VRayHelper.GetOuter(r, s);
         if(vl.HasValue) {
             var loc = vl.Value;
             s.World.regions[loc.RegionIndex].AddVoxel(loc.VoxelLoc.X, loc.VoxelLoc.Y, loc.VoxelLoc.Z, CurVoxID);
         }
     }
 }
Example #6
0
 public override void OnMouseClick(VoxState s, FreeCamera camera, Vector2 mPos, MouseButton button, Viewport vp)
 {
     Ray r = camera.GetViewRay(mPos, vp.Width, vp.Height);
     if(button == MouseButton.Left) {
         VoxLocation? vl = VRayHelper.GetInner(r, s);
         if(vl.HasValue) {
             var loc = vl.Value;
             if(hasStart) {
                 Vector3I end = new Vector3I(
                     loc.RegionLoc.X * Region.WIDTH + loc.VoxelLoc.X,
                     loc.VoxelLoc.Y,
                     loc.RegionLoc.Y * Region.DEPTH + loc.VoxelLoc.Z
                     );
                 Vector3I min = new Vector3I(Math.Min(start.X, end.X), Math.Min(start.Y, end.Y), Math.Min(start.Z, end.Z));
                 Vector3I max = new Vector3I(Math.Max(start.X, end.X), Math.Max(start.Y, end.Y), Math.Max(start.Z, end.Z));
                 for(int ry = min.Y; ry <= max.Y; ry++) {
                     for(int rz = min.Z; rz <= max.Z; rz++) {
                         for(int rx = min.X; rx <= max.X; rx++) {
                             loc = new VoxLocation(new Vector3I(rx, ry, rz));
                             s.World.regions[loc.RegionIndex].RemoveVoxel(loc.VoxelLoc.X, loc.VoxelLoc.Y, loc.VoxelLoc.Z);
                         }
                     }
                 }
                 hasStart = false;
             }
             else {
                 start = new Vector3I(
                     loc.RegionLoc.X * Region.WIDTH + loc.VoxelLoc.X,
                     loc.VoxelLoc.Y,
                     loc.RegionLoc.Y * Region.DEPTH + loc.VoxelLoc.Z
                     );
                 hasStart = true;
             }
         }
     }
     else if(button == MouseButton.Right) {
         VoxLocation? vl = VRayHelper.GetOuter(r, s);
         if(vl.HasValue) {
             var loc = vl.Value;
             if(hasStart) {
                 Vector3I end = new Vector3I(
                     loc.RegionLoc.X * Region.WIDTH + loc.VoxelLoc.X,
                     loc.VoxelLoc.Y,
                     loc.RegionLoc.Y * Region.DEPTH + loc.VoxelLoc.Z
                     );
                 Vector3I min = new Vector3I(Math.Min(start.X, end.X), Math.Min(start.Y, end.Y), Math.Min(start.Z, end.Z));
                 Vector3I max = new Vector3I(Math.Max(start.X, end.X), Math.Max(start.Y, end.Y), Math.Max(start.Z, end.Z));
                 for(int ry = min.Y; ry <= max.Y; ry++) {
                     for(int rz = min.Z; rz <= max.Z; rz++) {
                         for(int rx = min.X; rx <= max.X; rx++) {
                             loc = new VoxLocation(new Vector3I(rx, ry, rz));
                             s.World.regions[loc.RegionIndex].AddVoxel(loc.VoxelLoc.X, loc.VoxelLoc.Y, loc.VoxelLoc.Z, CurVoxID);
                         }
                     }
                 }
                 hasStart = false;
             }
             else {
                 start = new Vector3I(
                     loc.RegionLoc.X * Region.WIDTH + loc.VoxelLoc.X,
                     loc.VoxelLoc.Y,
                     loc.RegionLoc.Y * Region.DEPTH + loc.VoxelLoc.Z
                     );
                 hasStart = true;
             }
         }
     }
 }
Example #7
0
 public abstract void OnMouseClick(VoxState s, FreeCamera camera, Vector2 mPos, MouseButton button, Viewport vp);
Example #8
0
        public GameState()
        {
            UUIDGenerator.SetUUID(0);
            EntityHashSet = new Dictionary<int, IEntity>();

            teams = new RTSTeam[MAX_PLAYERS];
            activeTeams = new IndexedTeam[0];
            Regions = new List<ImpactRegion>();

            // No Data Yet Available
            VoxState = new VoxState();
            VoxState.World.worldMin = Point.Zero;
            Scripts = new Dictionary<string, ReflectedScript>();
            grid = new LevelGrid();
            //grid.L0 = null;
            grid.L1 = null;
            grid.L2 = null;

            curFrame = 0;
            timePlayed = 0f;

            tbMemBuildings = new TimeBudget(BUILDING_MEMORIZATION_LATENCY);

            lckParticles = new object();
            particles = new List<Particle>();
            tmpParticles = new List<Particle>();
        }
Example #9
0
 public WorldManager(VoxState s)
 {
     state = s;
 }
Example #10
0
 public void Hook(VoxState state)
 {
     state.World.OnRegionAddition += OnRegionAddition;
     state.World.OnRegionDeletion += OnRegionRemoval;
 }