Exemplo n.º 1
0
        public void GenerateInitialChunks(Point3 origin, ref string message)
        {
            float origBuildRadius = GenerateDistance;
            GenerateDistance = origBuildRadius * 2.0f;

            int i = 0;
            int iters = WorldSize.X * WorldSize.Y * WorldSize.Z;
            for (int dx = origin.X - WorldSize.X/2 + 1; dx < origin.X + WorldSize.X/2; dx++)
            {
                for (int dy = origin.Y - WorldSize.Y/2; dy <= origin.Y + WorldSize.Y/2; dy++)
                {
                    for (int dz = origin.Z - WorldSize.Z/2 + 1; dz < origin.Z + WorldSize.Z/2; dz++)
                    {
                        message = "Generating : " + (i + 1) + "/" + iters;
                        i++;

                        Point3 box = new Point3(dx, dy, dz);

                        if (!ChunkData.ChunkMap.ContainsKey(box))
                        {
                            Vector3 worldPos = new Vector3(box.X * ChunkData.ChunkSizeX, box.Y * ChunkData.ChunkSizeY, box.Z * ChunkData.ChunkSizeZ);
                            VoxelChunk chunk = ChunkGen.GenerateChunk(worldPos, (int)ChunkData.ChunkSizeX, (int)ChunkData.ChunkSizeY, (int)ChunkData.ChunkSizeZ, Components, Content, Graphics);
                            chunk.ShouldRebuild = true;
                            chunk.ShouldRecalculateLighting = true;
                            chunk.IsVisible = true;
                            chunk.ResetSunlight(0);
                            GeneratedChunks.Enqueue(chunk);
                            foreach (VoxelChunk chunk2 in GeneratedChunks)
                            {
                                if (!ChunkData.ChunkMap.ContainsKey(chunk2.ID))
                                {
                                    ChunkData.AddChunk(chunk2);
                                    RecalculateBounds();
                                }
                            }
                        }
                    }
                }
            }
            RecalculateBounds();
            message = "Generating Ores...";

            GenerateOres();

            message = "Fog of war...";
            ChunkData.Reveal(GeneratedChunks.First().MakeVoxel(0, (int)ChunkData.ChunkSizeY - 1, 0));

            UpdateRebuildList();
            GenerateDistance = origBuildRadius;

            while(GeneratedChunks.Count > 0)
            {
                VoxelChunk gen = null;
                if(!GeneratedChunks.TryDequeue(out gen))
                {
                    break;
                }
            }

            ChunkData.ChunkManager.CreateGraphics(ref message, ChunkData);
        }
Exemplo n.º 2
0
 public static bool IsInteriorPoint(Point3 gridPosition, VoxelChunk chunk)
 {
     return(chunk.IsInterior(gridPosition.X, gridPosition.Y, gridPosition.Z));
 }
Exemplo n.º 3
0
        private void LoadFromFile()
        {
            SetLoadingMessage("Creating Sky...");
            Renderer.Sky = new SkyRenderer();

            #region Reading game file

            SetLoadingMessage("Loading " + Overworld.InstanceSettings.ExistingFile);

            var gameFile = SaveGame.LoadMetaFromDirectory(Overworld.InstanceSettings.ExistingFile);

            if (gameFile == null)
            {
                throw new InvalidOperationException("Game File does not exist.");
            }

            if (gameFile.Metadata.Version != Program.Version && !Program.CompatibleVersions.Contains(gameFile.Metadata.Version))
            {
                throw new InvalidOperationException(String.Format("Game file is from version {0}. Compatible versions are {1}.", gameFile.Metadata.Version,
                                                                  TextGenerator.GetListString(Program.CompatibleVersions)));
            }

            Renderer.Sky.TimeOfDay      = gameFile.Metadata.TimeOfDay;
            Renderer.PersistentSettings = gameFile.Metadata.RendererSettings;
            Time = gameFile.Metadata.Time;
            WorldSizeInChunks = new Point3(Overworld.InstanceSettings.Cell.Bounds.Width, Overworld.zLevels, Overworld.InstanceSettings.Cell.Bounds.Height);

            #endregion

            #region Initialize static data

            bool actionComplete = false;

            Game.DoLazyAction(new Action(() =>
            {
                Renderer.InstanceRenderer = new InstanceRenderer();

                Renderer.bloom = new BloomComponent(Game)
                {
                    Settings = BloomSettings.PresetSettings[5]
                };
                Renderer.bloom.Initialize();

                SoundManager.Content = Content;
                if (PlanService != null)
                {
                    PlanService.Restart();
                }

                MonsterSpawner = new MonsterSpawner(this);
                EntityFactory.Initialize(this);
            }), () => { actionComplete = true; return(true); });

            while (!actionComplete)
            {
                Thread.Sleep(10);
            }

            #endregion

            PlanService = new PlanService();

            SetLoadingMessage("Creating Liquids ...");

            #region liquids

            Renderer.WaterRenderer = new WaterRenderer(GraphicsDevice);

            #endregion

            #region Load Components

            // Create updateable systems.
            foreach (var updateSystemFactory in AssetManager.EnumerateModHooks(typeof(UpdateSystemFactoryAttribute), typeof(EngineModule), new Type[] { typeof(WorldManager) }))
            {
                UpdateSystems.Add(updateSystemFactory.Invoke(null, new Object[] { this }) as EngineModule);
            }

            ChunkManager = new ChunkManager(Content, this);
            Splasher     = new Splasher(ChunkManager);

            Renderer.ChunkRenderer = new ChunkRenderer(ChunkManager);

            SetLoadingMessage("Loading Terrain...");
            ChunkManager.LoadChunks(gameFile.LoadChunks(), ChunkManager);

            SetLoadingMessage("Loading Entities...");
            gameFile.LoadPlayData(Overworld.InstanceSettings.ExistingFile, this);

            PersistentData = gameFile.PlayData.PersistentData;

            Renderer.Camera = gameFile.PlayData.Camera;

            if (gameFile.PlayData.Stats != null)
            {
                Stats = gameFile.PlayData.Stats;
            }

            ComponentManager = new ComponentManager(gameFile.PlayData.Components, this);

            foreach (var component in gameFile.PlayData.Components.SaveableComponents)
            {
                if (!ComponentManager.HasComponent(component.GlobalID) &&
                    ComponentManager.HasComponent(component.Parent.GlobalID))
                {
                    // Logically impossible.
                    throw new InvalidOperationException("Component exists in save data but not in manager.");
                }
            }

            ConversationMemory = gameFile.PlayData.ConversationMemory;

            Factions = gameFile.PlayData.Factions;
            ComponentManager.World = this;

            Renderer.Sky.TimeOfDay = gameFile.Metadata.TimeOfDay;
            Time = gameFile.Metadata.Time;

            PlayerFaction = Factions.Factions["Player"];

            EventScheduler = new Events.Scheduler();

            TutorialManager = new Tutorial.TutorialManager();
            TutorialManager.SetFromSaveData(gameFile.PlayData.TutorialSaveData);

            Renderer.Camera.World = this;

            #endregion

            SetLoadingMessage("Creating Particles ...");
            Game.DoLazyAction(new Action(() => ParticleManager = new ParticleManager(ComponentManager)));

            SetLoadingMessage("Creating GameMaster ...");

            TaskManager       = new TaskManager();
            TaskManager.World = this;
            Time.NewDay      += (time) => PayEmployees();

            DwarfGame.LogSentryBreadcrumb("Loading", "Started new game with an existing file.");
            if (gameFile.PlayData.Tasks != null)
            {
                TaskManager       = gameFile.PlayData.Tasks;
                TaskManager.World = this;
            }

            if (PlayerFaction.Economy.Information == null)
            {
                throw new InvalidProgramException();
            }

            if (MathFunctions.RandEvent(0.01f))
            {
                SetLoadingMessage("Reticulating Splines...");
            }

            ChunkManager.StartThreads();
            SetLoadingMessage("Presimulating ...");
            ShowingWorld = false;
            OnLoadedEvent();
            Thread.Sleep(1000);

            ShowingWorld = true;

            SetLoadingMessage("Complete.");

            // GameFile is no longer needed.
            gameFile   = null;
            LoadStatus = LoadingStatus.Success;
        }