Exemplo n.º 1
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>();
        }
Exemplo n.º 2
0
        private void CreateVoxWorld()
        {
            dVox  = new Dictionary <string, VoxData>();
            state = new VoxState();
            state.World.worldMin.X = 0;
            state.World.worldMin.Y = 0;
            CreateVoxTypes();

            voxContent = new ContentManager(game.Services);
            voxContent.RootDirectory = @"Content";
            renderer = new VoxelRenderer(game.Graphics, voxContent);
            renderer.Hook(state);
            renderer.LoadEffect(@"FX\VoxelLE");
            renderer.LoadVMap(@"LevelEditor\VoxMap.png");

            vManager = new WorldManager(state);
            for (int z = 0; z < VoxWorld.DEPTH; z++)
            {
                for (int x = 0; x < VoxWorld.WIDTH; x++)
                {
                    state.AddEvent(new VEWorldMod(state.World.worldMin.X + x, state.World.worldMin.Y + z, VEWMType.RegionAdd));
                }
            }
            state.VWorkPool.Start(2);
            state.World.OnRegionAddition += (w, r) => {
                if (r.loc.X == 0 && r.loc.Y == 0)
                {
                    r.AddVoxel(1, Region.HEIGHT - 2, 1, (ushort)0x06u);
                }
            };
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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();
        }
Exemplo n.º 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);
         }
     }
 }
Exemplo n.º 6
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 * 2, new Point(25, 25), camera, vp)) {
             VoxLocation? vl = VRayHelper.GetLevel(r, s, HEIGHT);
             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 * 2, new Point(25, 25), camera, vp)) {
             VoxLocation? vl = VRayHelper.GetLevel(r, s, HEIGHT);
             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);
     }
 }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
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;
             }
         }
     }
 }
Exemplo n.º 9
0
 public abstract void OnMouseClick(VoxState s, FreeCamera camera, Vector2 mPos, MouseButton button, Viewport vp);
Exemplo n.º 10
0
 public WorldManager(VoxState s)
 {
     state = s;
 }
Exemplo n.º 11
0
 public void Hook(VoxState state)
 {
     state.World.OnRegionAddition += OnRegionAddition;
     state.World.OnRegionDeletion += OnRegionRemoval;
 }