Example #1
0
        public ChunkWriter(ChunkManager chunkManager)
        {
            Ensure.NotNull(chunkManager, "chunkManager");

            _chunkManager = chunkManager;
            _scheduleService = ObjectContainer.Resolve<IScheduleService>();
        }
Example #2
0
        public ChunkWriter(ChunkManager chunkManager)
        {
            Ensure.NotNull(chunkManager, "chunkManager");

            _chunkManager = chunkManager;
            _scheduleService = ObjectContainer.Resolve<IScheduleService>();
            _flushTaskName = string.Format("{0}-FlushChunk", _chunkManager.Name);
        }
Example #3
0
        public void Load()
        {
            _chunkManager = new ChunkManager(this.GetType().Name, BrokerController.Instance.Setting.MessageChunkConfig);
            _chunkWriter = new ChunkWriter(_chunkManager);
            _chunkReader = new ChunkReader(_chunkManager, _chunkWriter);

            _chunkManager.Load(ReadMessage);
        }
Example #4
0
        public Queue(string topic, int queueId)
        {
            Topic = topic;
            QueueId = queueId;

            _jsonSerializer = ObjectContainer.Resolve<IJsonSerializer>();
            _chunkManager = new ChunkManager(string.Format("{0}-{1}", Topic, QueueId), BrokerController.Instance.Setting.QueueChunkConfig, Topic + @"\" + QueueId);
            _chunkWriter = new ChunkWriter(_chunkManager);
            _chunkReader = new ChunkReader(_chunkManager, _chunkWriter);
            _queueSettingFile = Path.Combine(_chunkManager.ChunkPath, QueueSettingFileName);
            _logger = ObjectContainer.Resolve<ILoggerFactory>().Create(this.GetType().FullName);
        }
Example #5
0
 void Start()
 {
     blockLibrary = GameObject.Find ("WorldGenerator").GetComponent<BlockLibrary> ();
     chunkManager = GameObject.Find ("WorldGenerator").GetComponent<ChunkManager> ();
     /*if (currentItem != null) {
         savedCurrentItem = Instantiate(currentItem);
         savedCurrentItem.SetParent(transform.Find ("arm left"));
         savedCurrentItem.localPosition = new Vector3(0f, -0.5f, 0);
         savedCurrentItem = currentItem;
     }*/
     UpdateBlocks ();
 }
Example #6
0
        protected DataBase(string db_name, ChunkManager.ChunkManager _cm, bool is_new_db)
        {
            local_am = new DSAccessManager(this);
            MemStorage = new DwarfDB.Stack.DataStorage(this);

            if (_cm != null)
                chunk_manager = _cm;
            else {
                chunk_manager = new DwarfDB.ChunkManager.ChunkManager();
            }
            Name = db_name;
            chunk_manager.Load(Name, is_new_db);
        }
Example #7
0
        public Queue(string topic, int queueId)
        {
            Topic = topic;
            QueueId = queueId;
            Key = new QueueKey(topic, queueId);

            _jsonSerializer = ObjectContainer.Resolve<IJsonSerializer>();
            _chunkManager = new ChunkManager("QueueChunk-" + Key.ToString(), BrokerController.Instance.Setting.QueueChunkConfig, BrokerController.Instance.Setting.IsMessageStoreMemoryMode, Topic + @"\" + QueueId);
            _chunkWriter = new ChunkWriter(_chunkManager);
            _chunkReader = new ChunkReader(_chunkManager, _chunkWriter);
            _queueSettingFile = Path.Combine(_chunkManager.ChunkPath, QueueSettingFileName);
            _logger = ObjectContainer.Resolve<ILoggerFactory>().Create(this.GetType().FullName);
        }
        public IEnumerable<Chunk> GetAllowDeleteChunks(ChunkManager chunkManager, long maxMessagePosition)
        {
            var chunks = new List<Chunk>();
            var allCompletedChunks = chunkManager
                .GetAllChunks()
                .Where(x => x.IsCompleted && CheckMessageConsumeOffset(x, maxMessagePosition))
                .OrderBy(x => x.ChunkHeader.ChunkNumber);

            foreach (var chunk in allCompletedChunks)
            {
                var lastWriteTime = new FileInfo(chunk.FileName).LastWriteTime;
                var storageHours = (DateTime.Now - lastWriteTime).TotalHours;
                if (storageHours >= MaxStorageHours)
                {
                    chunks.Add(chunk);
                }
            }

            return chunks;
        }
Example #9
0
 void Start()
 {
     blockLibrary = GameObject.Find ("WorldGenerator").GetComponent<BlockLibrary> ();
     chunkManager = GameObject.Find ("WorldGenerator").GetComponent<ChunkManager> ();
     transform.name = name;
     if (name == "Sapling") {
         chunkManager.DestroyDirectBlock (transform.position.x, transform.position.y, false);
         chunkManager.PlaceDirectBlock(transform.position.x, transform.position.y, blockLibrary.logBottom);
         chunkManager.PlaceDirectBlock(transform.position.x, transform.position.y + 1, blockLibrary.log);
         chunkManager.PlaceDirectBlock(transform.position.x, transform.position.y + 2, blockLibrary.log);
         chunkManager.PlaceDirectBlock(transform.position.x - 1, transform.position.y + 3, blockLibrary.leaves);
         chunkManager.PlaceDirectBlock(transform.position.x - 1, transform.position.y + 4, blockLibrary.leaves);
         chunkManager.PlaceDirectBlock(transform.position.x - 1, transform.position.y + 5, blockLibrary.leaves);
         chunkManager.PlaceDirectBlock(transform.position.x, transform.position.y + 3, blockLibrary.leaves);
         chunkManager.PlaceDirectBlock(transform.position.x, transform.position.y + 4, blockLibrary.leaves);
         chunkManager.PlaceDirectBlock(transform.position.x, transform.position.y + 5, blockLibrary.leaves);
         chunkManager.PlaceDirectBlock(transform.position.x + 1, transform.position.y + 3, blockLibrary.leaves);
         chunkManager.PlaceDirectBlock(transform.position.x + 1, transform.position.y + 4, blockLibrary.leaves);
         chunkManager.PlaceDirectBlock(transform.position.x + 1, transform.position.y + 5, blockLibrary.leaves);
     }
 }
Example #10
0
        public static void ResetLighting(BetaWorld world, ChunkManager cm, frmMace frmLogForm, int intTotalChunks)
        {
            int intChunksProcessed = 0;

            //this code is based on a substrate example
            //http://code.google.com/p/substrate-minecraft/source/browse/trunk/Substrate/SubstrateCS/Examples/Relight/Program.cs
            //see the <License Substrate.txt> file for copyright information
            foreach (ChunkRef chunk in cm)
            {
                chunk.Blocks.RebuildHeightMap();
                chunk.Blocks.ResetBlockLight();
                chunk.Blocks.ResetSkyLight();
                chunk.Blocks.RebuildBlockLight();
                chunk.Blocks.RebuildSkyLight();
                cm.Save();
                intChunksProcessed++;
                if (intChunksProcessed % 10 == 0)
                {
                    frmLogForm.UpdateProgress(58 + ((intChunksProcessed * (100 - 58)) / intTotalChunks));
                }
            }
        }
Example #11
0
        public static void Enable()
        {
            if (Enabled)
            {
                return;
            }
            Enabled = true;
            GameplayManager.AddHUDMessage("Observer mode enabled");
            PlayerShip.EnablePlayerLevelCollision(false);
            ChunkManager.ForceActivateAll();
            GameplayManager.m_use_segment_visibility = false;

            /*
             * GameManager.m_player_ship.m_player_died_due_to_timer = true;
             * GameManager.m_player_ship.m_dying = true;
             * GameManager.m_player_ship.m_dying_timer = 0f;
             * GameManager.m_player_ship.m_dying_explode_timer = 0f;
             */

            //NetworkManager.RemovePlayer(GameManager.m_player_ship.c_player);
            if (GameplayManager.IsMultiplayer)
            {
                GameManager.m_player_ship.c_player.Networkm_spectator = true;
                GameManager.m_local_player.Networkm_spectator         = true;
                GameManager.m_player_ship.c_player.m_spectator        = true;
                GameManager.m_local_player.m_spectator = true;
            }
            else
            {
                GameManager.m_local_player.SetCheaterFlag(true);
                foreach (var robot in RobotManager.m_master_robot_list)
                {
                    if (robot != null && !robot.gameObject.activeSelf)
                    {
                        robot.gameObject.SetActive(true);
                    }
                }
            }
        }
Example #12
0
 void Start()
 {
     blockLibrary   = GameObject.Find("WorldGenerator").GetComponent <BlockLibrary> ();
     chunkManager   = GameObject.Find("WorldGenerator").GetComponent <ChunkManager> ();
     transform.name = name;
     if (name == "Sapling")
     {
         chunkManager.DestroyDirectBlock(transform.position.x, transform.position.y, false);
         chunkManager.PlaceDirectBlock(transform.position.x, transform.position.y, blockLibrary.logBottom);
         chunkManager.PlaceDirectBlock(transform.position.x, transform.position.y + 1, blockLibrary.log);
         chunkManager.PlaceDirectBlock(transform.position.x, transform.position.y + 2, blockLibrary.log);
         chunkManager.PlaceDirectBlock(transform.position.x - 1, transform.position.y + 3, blockLibrary.leaves);
         chunkManager.PlaceDirectBlock(transform.position.x - 1, transform.position.y + 4, blockLibrary.leaves);
         chunkManager.PlaceDirectBlock(transform.position.x - 1, transform.position.y + 5, blockLibrary.leaves);
         chunkManager.PlaceDirectBlock(transform.position.x, transform.position.y + 3, blockLibrary.leaves);
         chunkManager.PlaceDirectBlock(transform.position.x, transform.position.y + 4, blockLibrary.leaves);
         chunkManager.PlaceDirectBlock(transform.position.x, transform.position.y + 5, blockLibrary.leaves);
         chunkManager.PlaceDirectBlock(transform.position.x + 1, transform.position.y + 3, blockLibrary.leaves);
         chunkManager.PlaceDirectBlock(transform.position.x + 1, transform.position.y + 4, blockLibrary.leaves);
         chunkManager.PlaceDirectBlock(transform.position.x + 1, transform.position.y + 5, blockLibrary.leaves);
     }
 }
Example #13
0
    // Start is called before the first frame update
    void Start()
    {
        Screen_Overlay = GameObject.Find("Overlay");
        Screen_Overlay.transform.gameObject.transform.localScale =
            new Vector3(2.0f, World.SEA_LEVEL, 1.0f);
        Screen_Overlay.GetComponent <MeshRenderer>().material.mainTextureScale =
            new Vector2(2.0f, World.SEA_LEVEL);

        level_manager = FindObjectOfType <LevelManager>();
        chunk_manager = level_manager.Chunk_Manager;

        // Locate body parts!
        head = GameObject.Find("Head");
        body = GameObject.Find("Body");

        // Lock cursor
        Cursor.lockState = CursorLockMode.Locked;

        player_rigidbody = GetComponent <Rigidbody>();
        Physics.gravity  = Vector3.zero;
        start_time       = Time.realtimeSinceStartup;
    }
        public IEnumerable<Chunk> GetAllowDeleteChunks(ChunkManager chunkManager, long maxMessagePosition)
        {
            var chunks = new List<Chunk>();
            var allCompletedChunks = chunkManager
                .GetAllChunks()
                .Where(x => x.IsCompleted && CheckMessageConsumeOffset(x, maxMessagePosition))
                .OrderBy(x => x.ChunkHeader.ChunkNumber)
                .ToList();

            var exceedCount = allCompletedChunks.Count - MaxChunkCount;
            if (exceedCount <= 0)
            {
                return chunks;
            }

            for (var i = 0; i < exceedCount; i++)
            {
                chunks.Add(allCompletedChunks[i]);
            }

            return chunks;
        }
    private void GenerateWorldFromFile(string fileName, Vector3Int dimensions, Material material, Vector3 center)
    {
        ChunkManager chunkManager = new ChunkManager();

        int testChunkCount = 1;

        // World dimensions correspond to the total number of blocks that exist in the world.
        int worldX = dimensions.X;
        int worldY = dimensions.Y;
        int worldZ = dimensions.Z;

        var chunkData = LidarDataTest.LoadCubeFile(fileName, testChunkCount, dimensions);

        int[,,] world = GetVoxelsFromChunk(chunkData[0], dimensions);

        Utils.TripleForLoop(worldX, worldY, worldZ, (x, y, z) => {
            ChunkIndex cIndex = ChunkIndex.ConvertWorldIndexToChunkIndex(new Vector3Int(x, y, z), ChunkSize);
            Chunk chunk;

            if (chunkManager.TryGetChunk(cIndex.chunkIndex, out chunk) == false)
            {
                chunk = new Chunk(
                    new GameObject(CreateStringRepresentation(cIndex.chunkIndex)),
                    new Vector3(cIndex.chunkIndex.X * ChunkSize, cIndex.chunkIndex.Y * ChunkSize, cIndex.chunkIndex.Z * ChunkSize) + center,
                    new Vector3Int(ChunkSize, ChunkSize, ChunkSize),
                    cIndex.chunkIndex,
                    material
                    );

                chunkManager.AddChunk(chunk);
            }

            chunk.AddVoxel(cIndex.blockIndex, world[x, y, z]);
        });

        chunkManager.GenerateAllChunks();

        // center += new Vector3(worldX, 0, 0);
    }
Example #16
0
        static List <TilePosition> PresetPath(GameUnit unit, Vector3Int posTarget)
        {
            var indexes = unit.PathFindObj.FindPath(ChunkUtil.GetDovvner(unit.CurrentPos), posTarget);

            // Debug.Log("Path = " + indexes);
            if (indexes == null)
            {
                var chunk = ChunkManager.GetChunkByNum(unit.ChunkNumber);
                chunk.ReindexTiles();
                return(null);
            }

            var lastOrDefault = unit.MovingPath.LastOrDefault();

            if (lastOrDefault != null && lastOrDefault.Index == posTarget)
            {
                return(null);
            }


            //Removing first point in some case
            if (unit.MovingPath.Count > 0 &&
                unit.MovingPath[0].Index != unit.CurrentPos &&
                indexes.Contains(unit.MovingPath[0].Index))
            {
                indexes = indexes.Where(t => t != ChunkUtil.GetDovvner(unit.CurrentPos)).ToList();
            }

            CancelOrders(unit);

            var path = (from ind in indexes
                        let pos3D = Util.Get3DPosByIndex(ind.x, ind.y, ind.z + 1)
                                    select new TilePosition(pos3D, ind)).ToList();

            unit.IsMoving   = true;
            unit.MovingPath = path;

            return(path);
        }
Example #17
0
        public static List <GameUnit> GetNearFriendUnits(int chunkNumber, GameEntity ent, Vector3Int pos)
        {
            var neighbourPoints = new Vector3Int[4];

            neighbourPoints[0] = new Vector3Int(pos.x + 1, pos.y, pos.z);
            neighbourPoints[1] = new Vector3Int(pos.x - 1, pos.y, pos.z);
            neighbourPoints[2] = new Vector3Int(pos.x, pos.y + 1, pos.z);
            neighbourPoints[3] = new Vector3Int(pos.x, pos.y - 1, pos.z);

            var chunk = ChunkManager.GetChunkByNum(chunkNumber);

            return((from point in neighbourPoints
                    where chunk.IsMapPos(point)
                    let index = ChunkUtil.GetIndex(chunkNumber, point)
                                where index > 0 && ChunkUtil.IsEntity(chunkNumber, point)
                                select chunk.GetGameObjectByIndex(point) as GameUnit
                                into obj
                                where obj != null
                                let entEnemy = obj.GetComponent <GameUnit>()
                                               where Equals(entEnemy.Owner, ent.Owner)
                                               select obj).ToList());
        }
Example #18
0
        public void PushNewChunkDetailsToUpperArea(Chunk chk)
        {
            Vector2i two = new Vector2i(chk.WorldPosition.X, chk.WorldPosition.Y);

            if (UpperAreas.TryGetValue(two, out BlockUpperArea bua))
            {
                for (int x = 0; x < Constants.CHUNK_WIDTH; x++)
                {
                    for (int y = 0; y < Constants.CHUNK_WIDTH; y++)
                    {
                        int ind = bua.BlockIndex(x, y);
                        if (bua.Blocks[ind].BasicMat == Material.AIR || bua.Blocks[ind].Height < (chk.WorldPosition.Z + 1) * Constants.CHUNK_WIDTH)
                        {
                            for (int z = Constants.CHUNK_WIDTH - 1; z >= 0; z--)
                            {
                                BlockInternal bi = chk.GetBlockAt(x, y, z);
                                if (bi.IsOpaque())
                                {
                                    bua.TryPush(x, y, z + chk.WorldPosition.Z * Constants.CHUNK_WIDTH, bi.Material);
                                    break;
                                }
                                else if (bi.Material.RendersAtAll())
                                {
                                    bua.TryPushTrans(x, y, z + chk.WorldPosition.Z * Constants.CHUNK_WIDTH, bi.Material);
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            int min = ChunkManager.GetMins(two.X, two.Y);

            if (min > chk.WorldPosition.Z)
            {
                ChunkManager.SetMins(two.X, two.Y, chk.WorldPosition.Z);
            }
        }
Example #19
0
        public KeyValuePair <byte[], byte[]> PushTopsToHigherSubsequent(Vector2i two, Vector2i two_lower, int z, byte[] lb, byte[] lbt)
        {
            Vector2i relPos;

            relPos.X = two_lower.X - two.X * HIGHER_DIV;
            relPos.Y = two_lower.Y - two.Y * HIGHER_DIV;
            KeyValuePair <byte[], byte[]> bses = ChunkManager.GetTopsHigher(two.X, two.Y, z);

            byte[] b  = bses.Key;
            byte[] bt = bses.Value;
            if (b == null)
            {
                b = new byte[Constants.CHUNK_WIDTH * Constants.CHUNK_WIDTH * 2];
            }
            if (bt == null)
            {
                bt = new byte[Constants.CHUNK_WIDTH * Constants.CHUNK_WIDTH * 2 * 4];
            }
            for (int x = 0; x < HIGHER_SIZE; x++)
            {
                for (int y = 0; y < HIGHER_SIZE; y++)
                {
                    int i1  = TopsHigherBlockIndex(x * 5, y * 5) * 2;
                    int ind = TopsHigherBlockIndex(x + relPos.X, y + relPos.Y) * 2;
                    b[ind]     = lb[i1];
                    b[ind + 1] = lb[i1 + 1];
                    ind       *= 4;
                    i1        *= 4;
                    for (int bz = 0; bz < 4; bz++)
                    {
                        bt[ind + bz * 2]     = lbt[i1 + bz * 2];
                        bt[ind + bz * 2 + 1] = lbt[i1 + bz * 2 + 1];
                    }
                }
            }
            ChunkManager.WriteTopsHigher(two.X, two.Y, z, b, bt);
            return(new KeyValuePair <byte[], byte[]>(b, bt));
        }
Example #20
0
        public KeyValuePair <byte[], byte[]> PushTopsToHigherStart(Vector2i two, Vector2i two_lower, BlockUpperArea bua)
        {
            Vector2i relPos;

            relPos.X = two_lower.X - two.X * HIGHER_DIV;
            relPos.Y = two_lower.Y - two.Y * HIGHER_DIV;
            KeyValuePair <byte[], byte[]> bses = ChunkManager.GetTopsHigher(two.X, two.Y, 1);

            byte[] b  = bses.Key;
            byte[] bt = bses.Value;
            if (b == null)
            {
                b = new byte[Constants.CHUNK_WIDTH * Constants.CHUNK_WIDTH * 2];
            }
            if (bt == null)
            {
                bt = new byte[Constants.CHUNK_WIDTH * Constants.CHUNK_WIDTH * 2 * 4];
            }
            for (int x = 0; x < HIGHER_SIZE; x++)
            {
                for (int y = 0; y < HIGHER_SIZE; y++)
                {
                    int      inder = bua.BlockIndex(x * 5, y * 5);
                    Material mat   = bua.Blocks[inder].BasicMat;
                    int      ind   = TopsHigherBlockIndex(x + relPos.X * HIGHER_SIZE, y + relPos.Y * HIGHER_SIZE);
                    Utilities.UshortToBytes((ushort)mat).CopyTo(b, ind * 2);
                    ind   *= 4;
                    inder *= 4;
                    for (int bz = 0; bz < 4; bz++)
                    {
                        mat = bua.BlocksTrans[inder + bz].BasicMat;
                        Utilities.UshortToBytes((ushort)mat).CopyTo(bt, (ind + bz) * 2);
                    }
                }
            }
            ChunkManager.WriteTopsHigher(two.X, two.Y, 1, b, bt);
            return(new KeyValuePair <byte[], byte[]>(b, bt));
        }
Example #21
0
    // Awake is called when the script instance is being loaded.
    void Awake()
    {
        player = GameObject.Find("Player");

        SaveData save_data = LoadGame("test_world14");

        if (save_data != null)
        {
            Physics.gravity           = Vector3.zero;
            Chunk_Manager             = new ChunkManager(save_data);
            player.transform.position = save_data.Player_Position + Vector3.up * 0.15f;
        }
        else
        {
            Chunk_Manager = new ChunkManager();
        }

        world = new World(this);

        // This instantiates the shared block material so other threads can access it
        // (As loading must be carried out in main thread)
        Material block_mat = TextureManager.Block_Material;
    }
Example #22
0
        protected override void Initialize()
        {
            //Create a new scene
            mainScene = new Scene();

            //Create a new camera to render the scene
            mainCamera        = new Camera(GraphicsDevice, MathHelper.ToRadians(70f), 0.1f, 1000, (float)graphics.PreferredBackBufferWidth / (float)graphics.PreferredBackBufferHeight);
            mainCamera.Parent = mainScene;
            coob           = new Cube("Cube", mainScene, GraphicsDevice);
            Terrain        = new ChunkManager(256, 256);
            Terrain.Parent = mainScene;

            mainCamera.Position = new Vector3(800, -50, 800);
            coob.Position       = new Vector3(800, -50, 800);

            Mouse.SetPosition(GraphicsDevice.Viewport.Width / 2, GraphicsDevice.Viewport.Height / 2);
            OriginalMouseState = Mouse.GetState();
            CurrentChunk       = Terrain.GetChunkFromPos(mainCamera.Position);
            ChunkCoords        = Terrain.GetChunkCoords(mainCamera.Position);
            LoadedChunks       = new LinkedList <Vector2>();

            base.Initialize();
        }
Example #23
0
    void Awake()
    {
        // Get all files from the specified mods directory
        string[] modPaths = Directory.GetFiles(modFolder);

        // Try to load all valid mods
        foreach (string mod in modPaths)
        {
            ModManager.LoadMod(mod);
        }

        // Set the scene containing the default chunk
        if (terrainObject != null)
        {
            ChunkManager.Initialize(new InfiniTerrain(terrainObject));
        }

        // Initialize the interface manager with the specified skin
        InterfaceManager.Initialize(defaultSkin);

        // Start generating engine ticks
        StartCoroutine(GenerateEngineTick());
    }
        public IEnumerable <Chunk> GetAllowDeleteChunks(ChunkManager chunkManager, long maxMessagePosition)
        {
            var chunks             = new List <Chunk>();
            var allCompletedChunks = chunkManager
                                     .GetAllChunks()
                                     .Where(x => x.IsCompleted && CheckMessageConsumeOffset(x, maxMessagePosition))
                                     .OrderBy(x => x.ChunkHeader.ChunkNumber)
                                     .ToList();

            var exceedCount = allCompletedChunks.Count - MaxChunkCount;

            if (exceedCount <= 0)
            {
                return(chunks);
            }

            for (var i = 0; i < exceedCount; i++)
            {
                chunks.Add(allCompletedChunks[i]);
            }

            return(chunks);
        }
Example #25
0
    private void Awake()
    {
        if (instance != this)
        {
            if (instance != null)
            {
                Destroy(instance);
            }
            instance = this;
        }

        chunks            = new GameObject[6900, 6900];
        bufferedChunkMods = new List <ChunkMod> [6900, 6900];

        for (int i = 0; i < 6900; i++)
        {
            for (int j = 0; j < 6900; j++)
            {
                chunks[i, j]            = null;
                bufferedChunkMods[i, j] = new List <ChunkMod>();
            }
        }
    }
Example #26
0
    public void Execute()
    {
        ChunkManager m = ChunkManager.manager;

        int   resolution = ChunkManager.manager.MAP_SIZE;
        float size       = ChunkManager.manager.baseDimension;
        float ratio      = size / resolution;
        float sizeRatio  = ChunkManager.manager.dimension / size;

        float[,] terrain_map = new float[resolution, resolution];

        for (int i = 0; i < resolution; i++)
        {
            float z = globalTileZ + i * ratio;
            for (int j = 0; j < resolution; j++)
            {
                float x = globalTileX + j * ratio;

                terrain_map[i, j] = m_mountainNoise.FractalNoise2D(x, z, m.octaves_ground, m.frequency_ground * sizeRatio, m.amplitude_ground, m.lacunarity_ground, m.persistence_ground) + 0.5f;
            }
        }
        chunk.SetHeights(terrain_map);
    }
Example #27
0
    void Awake()
    {
        viewCamera = Camera.main;

        chunkSizeMinusOne  = chunkSize - 1;
        viewDist           = Preferences.viewDist;
        instance           = this;
        existingChunks     = new Dictionary <Vector3Int, Chunk>();
        recyclableChunks   = new Queue <Chunk>();
        chunks             = new List <Chunk>();
        chunkMeshesToBuild = new Stack <Chunk>();
        for (int i = transform.childCount - 1; i >= 0; i--)
        {
            DestroyImmediate(transform.GetChild(i).gameObject);
        }
        chunksVisibleInViewDist = Mathf.RoundToInt(viewDist / (float)chunkSize);
        sqrViewDist             = viewDist * viewDist;
        minSqrViewDist          = (chunkSize + 1) * (chunkSize + 1);

        RenderSettings.fogEndDistance   = viewDist - (chunkSize * 1.5f);
        RenderSettings.fogStartDistance = viewDist - (chunkSize * 2.5f);
        firstLoad = true;
    }
Example #28
0
    private void OnPlacedBlock(PlacedBlock msg)
    {
        Point3 worldCoord = msg.worldCoord;
        Voxel  block      = ChunkManager.GetBlock(worldCoord);

        if (block == null)
        {
            block = ChunkManager
                    .AddChunk(worldCoord)
                    .AddBlock(worldCoord.ToLocalBlockCoord());
        }

        int hash = ChunkManager.GetHash(worldCoord.ToChunkCoord());

        block.SetBlockType(msg.type);

        // Get neighbours, pass to surface manager
        Voxel[] neighbours = GetNeighbours(worldCoord);

        // Lookup mesh name and rotation based on neighbours
        BlockInfo bi =
            SurfaceManager.GetSurface(
                SurfaceManager.GetID(neighbours));

        block.SetRotation(bi.rotation);

        for (int i = 0; i < neighbours.Length; i++)
        {
            if (neighbours[i] == null)
            {
                continue;
            }
            UpdateNeighbour(neighbours[i], worldCoord + checkSides[i]);
        }

        PlaceBlock(msg.worldCoord, hash, bi);
    }
Example #29
0
        public Chunk LoadChunk(Vector3i cpos)
        {
            Chunk chunk;

            if (LoadedChunks.TryGetValue(cpos, out chunk))
            {
                while (chunk.LoadSchedule != null)
                {
                    Thread.Sleep(1); // TODO: Handle loading a loading chunk more cleanly.
                }
                if (chunk.Flags.HasFlag(ChunkFlags.ISCUSTOM))
                {
                    chunk.Flags &= ~ChunkFlags.ISCUSTOM;
                    PopulateChunk(chunk, false);
                    chunk.AddToWorld();
                }
                if (chunk.Flags.HasFlag(ChunkFlags.POPULATING))
                {
                    LoadedChunks.Remove(cpos);
                    ChunkManager.ClearChunkDetails(cpos);
                    SysConsole.Output(OutputType.ERROR, "non-custom chunk was still loading when grabbed: " + chunk.WorldPosition);
                }
                else
                {
                    chunk.UnloadTimer = 0;
                    return(chunk);
                }
            }
            chunk               = new Chunk();
            chunk.Flags         = ChunkFlags.POPULATING;
            chunk.OwningRegion  = this;
            chunk.WorldPosition = cpos;
            LoadedChunks.Add(cpos, chunk);
            PopulateChunk(chunk, true);
            chunk.AddToWorld();
            return(chunk);
        }
Example #30
0
        public static GameEntity GetNearEnemy(GameEntity ent, int radius)
        {
            var chunkNumber     = ent.ChunkNumber;
            var chunk           = ChunkManager.GetChunkByNum(chunkNumber);
            var pos             = ent.CurrentPos;
            var neighbourPoints = new Vector3Int[8];

            for (var i = 0; i < radius; i++)
            {
                neighbourPoints[0] = new Vector3Int(pos.x + i, pos.y, pos.z);
                neighbourPoints[1] = new Vector3Int(pos.x - i, pos.y, pos.z);
                neighbourPoints[2] = new Vector3Int(pos.x, pos.y + i, pos.z);
                neighbourPoints[3] = new Vector3Int(pos.x, pos.y - i, pos.z);

                neighbourPoints[4] = new Vector3Int(pos.x + i, pos.y + i, pos.z);
                neighbourPoints[5] = new Vector3Int(pos.x - i, pos.y - i, pos.z);
                neighbourPoints[6] = new Vector3Int(pos.x - i, pos.y + i, pos.z);
                neighbourPoints[7] = new Vector3Int(pos.x + i, pos.y - i, pos.z);


                var enemy = (from point in neighbourPoints
                             where chunk.IsMapPos(point)
                             let index = ChunkUtil.GetIndex(chunkNumber, point)
                                         where index > 0 && ChunkUtil.IsEntity(chunkNumber, point)
                                         select chunk.GetGameObjectByIndex(point)
                                         into obj
                                         where obj != null
                                         select obj.GetComponent <GameEntity>()).FirstOrDefault(entEnemy =>
                                                                                                !Equals(entEnemy.Owner, ent.Owner));

                if (enemy != null)
                {
                    return(enemy);
                }
            }
            return(null);
        }
        public bool Initialize()
        {
            var gameFiles = ResolveOrCreate <IGameFiles>();

            if (!gameFiles.Initialize())
            {
                return(false);
            }
            coroutineManager = new();

            dbcManager = ResolveOrCreate <DbcManager>();
            SetMap(1);

            foreach (var store in dbcManager.Stores())
            {
                registry.RegisterInstance(store.Item1, store.Item2);
            }

            notificationsCenter = ResolveOrCreate <NotificationsCenter>();
            timeManager         = ResolveOrCreate <TimeManager>();
            screenSpaceSelector = ResolveOrCreate <ScreenSpaceSelector>();
            loadingManager      = ResolveOrCreate <LoadingManager>();
            textureManager      = ResolveOrCreate <WoWTextureManager>();
            meshManager         = ResolveOrCreate <WoWMeshManager>();
            mdxManager          = ResolveOrCreate <MdxManager>();
            wmoManager          = ResolveOrCreate <WmoManager>();
            worldManager        = ResolveOrCreate <WorldManager>();
            chunkManager        = ResolveOrCreate <ChunkManager>();
            cameraManager       = ResolveOrCreate <CameraManager>();
            lightingManager     = ResolveOrCreate <LightingManager>();
            areaTriggerManager  = ResolveOrCreate <AreaTriggerManager>();
            raycastSystem       = ResolveOrCreate <RaycastSystem>();
            moduleManager       = ResolveOrCreate <ModuleManager>();

            IsInitialized = true;
            return(true);
        }
Example #32
0
    public static void Update()
    {
        UnityEngine.Profiling.Profiler.BeginSample("ChunkChecker.Update");

        if (isRefreshing)
        {
            return;
        }

        Vector2Int curChunk = PlayerController.GetCurrentChunkPos();

        // if player moved to another chunk or render distance is changed, then try to refresh chunks data.
        if (lastChunk != curChunk || lastRenderDistance != SettingsPanel.RenderDistance)
        {
            isRefreshing       = true;
            tmpChunk           = curChunk;
            lastRenderDistance = SettingsPanel.RenderDistance;

            // only load chunks in render distance (if render distance is greater than 6, then load chunks in 6)
            // and unload chunks out of render distance
            List <Vector2Int> loadChunks   = NBTHelper.GetLoadChunks(curChunk);
            List <Vector2Int> unloadChunks = NBTHelper.GetUnloadChunks(curChunk, SettingsPanel.RenderDistance);
            Debug.Log(curChunk + "," + lastChunk + "," + loadChunks.Count + "," + unloadChunks.Count);

            if (loadChunks.Count > 0 || unloadChunks.Count > 0)
            {
                ChunkManager.ChunksEnterLeaveViewReq(loadChunks, unloadChunks);
            }
            else
            {
                FinishRefresh();
            }
        }

        UnityEngine.Profiling.Profiler.EndSample();
    }
Example #33
0
 void SetUpTiles(int[][][] mas)
 {
     for (var z = 0; z < ChunkManager.MaxGroundsLvls; z++)
     {
         for (var x = 0; x < MapSize; x++)
         {
             for (var y = 0; y < MapSize; y++)
             {
                 var index = mas[z][x][y];
                 if (index > 0)
                 {
                     var npc     = LuaNpcGetter.GetNpcById(index);
                     var npcName = LuaNpcGetter.GetNpcName(npc);
                     ChunkManager.InitObject(ChunkNumber, npcName, new Vector3Int(x, y, z),
                                             index, npc, PlayersManager.Empty);
                 }
                 else
                 {
                     IndexMas[z][x][y] = -1;
                 }
             }
         }
     }
 }
Example #34
0
        public void Init(ChunkManagerConfig eventDataChunkConfig, ChunkManagerConfig aggregateIndexChunkConfig, ChunkManagerConfig commandIndexChunkConfig)
        {
            _eventDataChunkManager = new ChunkManager("EventDataChunk", eventDataChunkConfig, false);
            _eventDataChunkWriter  = new ChunkWriter(_eventDataChunkManager);
            _eventDataChunkReader  = new ChunkReader(_eventDataChunkManager, _eventDataChunkWriter);

            _aggregateIndexChunkManager = new ChunkManager("AggregateIndexChunk", aggregateIndexChunkConfig, false);
            _aggregateIndexChunkWriter  = new ChunkWriter(_aggregateIndexChunkManager);
            _aggregateIndexChunkReader  = new ChunkReader(_aggregateIndexChunkManager, _aggregateIndexChunkWriter);

            _commandIndexChunkManager = new ChunkManager("CommandIndexChunk", commandIndexChunkConfig, false);
            _commandIndexChunkWriter  = new ChunkWriter(_commandIndexChunkManager);
            _commandIndexChunkReader  = new ChunkReader(_commandIndexChunkManager, _commandIndexChunkWriter);

            _eventDataChunkManager.Load(ReadEventStreamRecord);
            _aggregateIndexChunkManager.Load(ReadIndexRecord);
            _commandIndexChunkManager.Load(ReadIndexRecord);

            _eventDataChunkWriter.Open();
            _aggregateIndexChunkWriter.Open();
            _commandIndexChunkWriter.Open();

            LoadIndexData();
        }
Example #35
0
        public static bool Execute(UnitOrder order)
        {
            var ability = order.GetAbilityToCast();

            if (ability == null)
            {
                return(true);
            }
            var unit   = order.GetUnit();
            var target = ChunkManager.GetChunkByNum(unit.ChunkNumber).GetGameObjectByIndex(order.GetTo().Index);

            ability.CurrentCooldown = ability.GetCooldown();

            var succ = ability.OnSpellStart(unit, target as GameUnit);

            if (ability.PostCurrent >= 0)
            {
                ability.CurrentCooldown = ability.PostCurrent;
                ability.PostCurrent     = -1;
            }


            return(succ);
        }
    void Start()
    {
        //Set region size
        Region.regionXZ = regionXZ;
        Region.regionY  = regionY;
        unloaderQueue   = new BinaryHeap <RegionWatcher> ();
        StartCoroutine("UnloadRegions");
        //Start singleton managers
        WorldGeneration instance = WorldGeneration.Instance;

        Region.setWorld(this);
        regions = new Dictionary <string, Region> ();
//				for (int x = 0; x < initialRegions; x++) {
//						for (int y =0; y < initialRegions; y++) {
//								for (int z = 0; z < initialRegions; z++) {
//										createRegion (x, y, z, false);
//								}
//						}
//				}
        //Region centerRegion = getRegionAtIndex (1, 0, 1);
        Region centerRegion = createRegion(0, 0, 0, false);

        loadAllNeighbors(centerRegion, false);

        //Initialize Chunk Manager
        GameObject   chunkManagerGO = GameObject.Find("Chunk Manager") as GameObject;
        ChunkManager manager        = chunkManagerGO.GetComponent <ChunkManager> ();

        manager.createChunkPool();

        clientRenderer = gameObject.GetComponent("VoxelModifyTerrain") as VoxelModifyTerrain;
        clientRenderer.setStartRegion(centerRegion);


        InvokeRepeating("SaveToDiskEvent", 30f, 10f);
    }
Example #37
0
        private void OnRemoveSelected(Dictionary <Rectangle, Texture2D> selectedTiles)
        {
            // For each rectangle in selected tiles rectangle
            foreach (var rectangle in selectedTiles.Keys)
            {
                // Get the tile by selecting the start position of the rectangle
                Tile tile = ChunkManager.TileAtWorldPosition(rectangle.X, rectangle.Y);

                if (tile != null && tile.IsOccupied)
                {
                    if (tile.Flora != null)
                    {
                        _terrainManager.RemoveFlora(tile);
                    }
                    else if (tile.Wall != null)
                    {
                        _terrainManager.RemoveWall(tile);
                    }
                }
            }

            _selectingType  = SelectingAreaType.None;
            GameState.State = GameStateType.PLAYING;
        }
Example #38
0
        public static Vector3Int FindFreePosNearPos(int chunkNumber, Vector3Int pos, bool includeSecondLvl)
        {
            for (var i = 1; i < 100; i++)
            {
                var neighbourPoints = new Vector3Int[8];
                neighbourPoints[0] = new Vector3Int(pos.x + i, pos.y, pos.z);
                neighbourPoints[1] = new Vector3Int(pos.x - i, pos.y, pos.z);
                neighbourPoints[2] = new Vector3Int(pos.x, pos.y + i, pos.z);
                neighbourPoints[3] = new Vector3Int(pos.x, pos.y - i, pos.z);

                neighbourPoints[4] = new Vector3Int(pos.x + i, pos.y + i, pos.z);
                neighbourPoints[5] = new Vector3Int(pos.x - i, pos.y - i, pos.z);
                neighbourPoints[6] = new Vector3Int(pos.x - i, pos.y + i, pos.z);
                neighbourPoints[7] = new Vector3Int(pos.x + i, pos.y - i, pos.z);

                var chunk = ChunkManager.GetChunkByNum(chunkNumber);
                foreach (var point in neighbourPoints)
                {
                    if (chunk.IsMapPos(point) && !IsInvalidPoint(chunkNumber, point))
                    {
                        if (includeSecondLvl)
                        {
                            if (SecondaryGroundLvL.IsEmptyPos(chunkNumber, point))
                            {
                                return(point);
                            }
                        }
                        else
                        {
                            return(point);
                        }
                    }
                }
            }
            return(Vector3Int.zero);
        }
Example #39
0
        /// <summary>
        /// Called when a [selection is selected].
        /// </summary>
        /// <param name="selectedTiles">The selected tiles.</param>
        private void OnSelectionSelected(Dictionary <Rectangle, Texture2D> selectedTiles)
        {
            // If the name of the element that was passed through OnBuildWall is build wood/brick/stone
            if (_buildSelectionName == GameText.BuildMenu.BUILDWOODWALL || _buildSelectionName == GameText.BuildMenu.BUILDBRICKWALL || _buildSelectionName == GameText.BuildMenu.BUILDSTONEWALL)
            {
                // For each rectangle in selected tiles rectangle
                foreach (var rectangle in selectedTiles.Keys)
                {
                    // Get the tile by selecting the start position of the rectangle
                    Tile tile = ChunkManager.TileAtWorldPosition(rectangle.X, rectangle.Y);

                    if (tile != null)
                    {
                        Wall wall;
                        if (_buildSelectionName == GameText.BuildMenu.BUILDWOODWALL)
                        {
                            wall = new Wall(tile.Position, LinkedSpriteType.WoodWall);
                            _jobManager.CreateJob(wall, tile);
                        }
                        else if (_buildSelectionName == GameText.BuildMenu.BUILDBRICKWALL)
                        {
                            wall = new Wall(tile.Position, LinkedSpriteType.BrickWall);
                            _jobManager.CreateJob(wall, tile);
                        }
                        else if (_buildSelectionName == GameText.BuildMenu.BUILDSTONEWALL)
                        {
                            wall = new Wall(tile.Position, LinkedSpriteType.StoneWall);
                            _jobManager.CreateJob(wall, tile);
                        }
                    }
                }
            }

            _selectingType  = SelectingAreaType.None;
            GameState.State = GameStateType.PLAYING;
        }
Example #40
0
        public static GameObject TestScene(int seed, GameObject parent)
        {
            // Create the terrain, chunk manager and Chunks gameobject.
            var terrain = new HeightTerrain(seed);
            var manager = new ChunkManager();
            var Chunks  = new GameObject(parent, "Chunks", true, terrain, manager);

            VoxPos chunkPos = new VoxPos();
            Chunk  chunk;

            // Fill up the world with a grid of 4x4x4 chunks.
            // VoxPos chunkPos = new VoxPos();
            for (chunkPos.X = 0; chunkPos.X < 4; chunkPos.X++)
            {
                for (chunkPos.Z = 0; chunkPos.Z < 4; chunkPos.Z++)
                {
                    for (chunkPos.Y = 0; chunkPos.Y < 4; chunkPos.Y++)
                    {
                        new GameObject(Chunks, $"Chunk {chunkPos}", true, new Chunk(chunkPos, terrain, manager));
                    }
                }
            }
            return(Chunks);
        }
        protected override void Start()
        {
            if (mCM == null)
                mCM = ChunkManager.Get();
            if (mSWM == null)
                mSWM = StaticWallManager.Get();

            base.Start();
        }
Example #42
0
 void Awake()
 {
     worldGenerator = GameObject.Find ("WorldGenerator").transform;
     chunkManager = worldGenerator.GetComponent<ChunkManager> ();
     blockLibrary = worldGenerator.GetComponent<BlockLibrary> ();
     xPos = int.Parse (transform.position.x.ToString ());
     GenerateChunk ();
 }
Example #43
0
 /// <summary>
 /// Loads database from a filesystem
 /// </summary>
 /// <param name="db_name">DB name</param>
 /// <param name="_cm">Chunk manager</param>
 /// <returns></returns>
 public static DataBase LoadFrom(string db_name,
                                 ChunkManager.ChunkManager _cm)
 {
     var cpath = Config.Config.Instance.DataDirectory + db_name;
     if (Directory.Exists(cpath))
     {
         var db = new DataBase(db_name, _cm, false);
         db.DbPath = cpath;
         db.UpdateDataContainers();
         return db;
     }
     else {
         Errors.Messages.DisplayError("Can't find a directory: " + cpath, "DB loading", "Check DB name or path existance", DateTime.Now);
         return null;
     }
 }
Example #44
0
        /// <summary>
        /// Creates a new DB
        /// </summary>
        /// <param name="db_name"></param>
        /// <param name="_cm"></param>
        /// <returns></returns>
        public static DataBase Create(string db_name,
                                      ChunkManager.ChunkManager _cm = null)
        {
            var cpath = Config.Config.Instance.DataDirectory + db_name;

            if (!Directory.Exists(cpath))
                Directory.CreateDirectory(cpath);

            var new_db = new DataBase(db_name, _cm, true);

            CreateIndexesDw(db_name);
            new_db.chunk_manager.CreateChunk(new_db);
            new_db.DbPath = Config.Config.Instance.DataDirectory + db_name;

            return new_db;
        }
Example #45
0
        public int Load()
        {
            _chunkManager = new ChunkManager(this.GetType().Name, BrokerController.Instance.Setting.MessageChunkConfig);
            _chunkWriter = new ChunkWriter(_chunkManager);
            _chunkReader = new ChunkReader(_chunkManager, _chunkWriter);

            _chunkManager.Load(ReadMessage);

            return _chunkManager.GetAllChunks().Count;
        }
Example #46
0
 // Use this for initialization
 void Start()
 {
     cm = new ChunkManager();
 }
Example #47
0
        /// <summary>
        /// Creates the terrain that is immediately around the player's spawn point.
        /// If loading from a file, loads the existing terrain from a file.
        /// </summary>
        public void GenerateInitialChunks()
        {
            gameFile = null;

            bool fileExists = !string.IsNullOrEmpty(ExistingFile);

            // If we already have a file, we need to load all the chunks from it.
            // This is preliminary stuff that just makes sure the file exists and can be loaded.
            if (fileExists)
            {
                LoadingMessage = "Loading " + ExistingFile;
                gameFile = new GameFile(ExistingFile, true);
                Sky.TimeOfDay = gameFile.Data.Metadata.TimeOfDay;
                WorldOrigin = gameFile.Data.Metadata.WorldOrigin;
                WorldScale = gameFile.Data.Metadata.WorldScale;
                ChunkWidth = gameFile.Data.Metadata.ChunkWidth;
                ChunkHeight = gameFile.Data.Metadata.ChunkHeight;

                if (gameFile.Data.Metadata.OverworldFile != null && gameFile.Data.Metadata.OverworldFile != "flat")
                {
                    LoadingMessage = "Loading world " + gameFile.Data.Metadata.OverworldFile;
                    Overworld.Name = gameFile.Data.Metadata.OverworldFile;
                    DirectoryInfo worldDirectory =
                        Directory.CreateDirectory(DwarfGame.GetGameDirectory() + ProgramData.DirChar + "Worlds" +
                                                  ProgramData.DirChar + Overworld.Name);
                    OverworldFile overWorldFile =
                        new OverworldFile(
                            worldDirectory.FullName + ProgramData.DirChar + "world." + OverworldFile.CompressedExtension,
                            true);
                    Overworld.Map = overWorldFile.Data.CreateMap();
                    Overworld.Name = overWorldFile.Data.Name;
                    WorldWidth = Overworld.Map.GetLength(1);
                    WorldHeight = Overworld.Map.GetLength(0);
                }
                else
                {
                    LoadingMessage = "Generating flat world..";
                    Overworld.CreateUniformLand(Game.GraphicsDevice);
                }

                GameID = gameFile.Data.GameID;

            }
            else
            {
                GameID = Random.Next(0, 1024);
            }

            ChunkGenerator = new ChunkGenerator(VoxelLibrary, Seed, 0.02f, ChunkHeight/2.0f)
            {
                SeaLevel = SeaLevel
            };

            Vector3 globalOffset = new Vector3(WorldOrigin.X, 0, WorldOrigin.Y) * WorldScale;

            if(fileExists)
            {
                globalOffset /= WorldScale;
            }

            // If the file exists, we get the camera's pose from the file.
            // Otherwise, we set it to a pose above the center of the world (0, 0, 0)
            // facing down slightly.
            Camera = fileExists ? gameFile.Data.Camera :
                new OrbitCamera(0, 0, 10f, new Vector3(ChunkWidth, ChunkHeight - 1.0f, ChunkWidth) + globalOffset, new Vector3(0, 50, 0) + globalOffset, MathHelper.PiOver4, AspectRatio, 0.1f, GameSettings.Default.VertexCullDistance);

            Drawer3D.Camera = Camera;

            // Creates the terrain management system.
            ChunkManager = new ChunkManager(Content, (uint) ChunkWidth, (uint) ChunkHeight, (uint) ChunkWidth, Camera,
                GraphicsDevice, Tilesheet,
                TextureManager.GetTexture(ContentPaths.Terrain.terrain_illumination),
                TextureManager.GetTexture(ContentPaths.Gradients.sungradient),
                TextureManager.GetTexture(ContentPaths.Gradients.ambientgradient),
                TextureManager.GetTexture(ContentPaths.Gradients.torchgradient),
                ChunkGenerator, WorldSize.X, WorldSize.Y, WorldSize.Z);

            // Trying to determine the global offset from overworld coordinates (pixels in the overworld) to
            // voxel coordinates.
            globalOffset = ChunkManager.ChunkData.RoundToChunkCoords(globalOffset);
            globalOffset.X *= ChunkWidth;
            globalOffset.Y *= ChunkHeight;
            globalOffset.Z *= ChunkWidth;

            // If there's no file, we have to offset the camera relative to the global offset.
            if(!fileExists)
            {
                WorldOrigin = new Vector2(globalOffset.X, globalOffset.Z);
                Camera.Position = new Vector3(0, 10, 0) + globalOffset;
                Camera.Target = new Vector3(0, 10, 1) + globalOffset;
                Camera.Radius = 0.01f;
                Camera.Phi = -1.57f;
            }

            // If there's no file, we have to initialize the first chunk coordinate
            if(gameFile == null)
            {
                ChunkManager.GenerateInitialChunks(Camera, ChunkManager.ChunkData.GetChunkID(new Vector3(0, 0, 0) + globalOffset), ref LoadingMessage);
            }
            // Otherwise, we just load all the chunks from the file.
            else
            {
                LoadingMessage = "Loading Chunks from Game File";
                ChunkManager.ChunkData.LoadFromFile(gameFile, ref LoadingMessage);
            }

            // If there's no file, for some reason we modify the camera position...
            // TODO: Figure out why the camera keeps needing to be reset.
            if(!fileExists)
            {
                Camera.Radius = 0.01f;
                Camera.Phi = -1.57f / 4.0f;
                Camera.Theta = 0.0f;
            }

            // Finally, the chunk manager's threads are started to allow it to
            // dynamically rebuild terrain
            ChunkManager.RebuildList = new ConcurrentQueue<VoxelChunk>();
            ChunkManager.StartThreads();
        }
Example #48
0
        public void Load()
        {
            _bufferQueue = new BufferQueue<MessageLogRecord>("MessageBufferQueue", BrokerController.Instance.Setting.MessageWriteQueueThreshold, PersistMessages, _logger);
            _chunkManager = new ChunkManager("MessageChunk", BrokerController.Instance.Setting.MessageChunkConfig, BrokerController.Instance.Setting.IsMessageStoreMemoryMode);
            _chunkWriter = new ChunkWriter(_chunkManager);
            _chunkReader = new ChunkReader(_chunkManager, _chunkWriter);

            _chunkManager.Load(ReadMessage);
        }
Example #49
0
        /// <summary>
        /// Creates a flat, wooden balloon port for the balloon to land on, and Dwarves to sit on.
        /// </summary>
        /// <param name="roomDes">The player's BuildRoom designator (so that we can create a balloon port)</param>
        /// <param name="chunkManager">The terrain handler</param>
        /// <param name="x">The position of the center of the balloon port</param>
        /// <param name="z">The position of the center of the balloon port</param>
        /// <param name="size">The size of the (square) balloon port in voxels on a side</param>
        public void GenerateInitialBalloonPort(RoomBuilder roomDes, ChunkManager chunkManager, float x, float z, int size)
        {
            Vector3 pos = new Vector3(x, ChunkHeight - 1, z);

            // First, compute the maximum height of the terrain in a square window.
            int averageHeight = 0;
            int count = 0;
            for(int dx = -size; dx <= size; dx++)
            {
                for(int dz = -size; dz <= size; dz++)
                {
                    Vector3 worldPos = new Vector3(pos.X + dx, pos.Y, pos.Z + dz);
                    VoxelChunk chunk = chunkManager.ChunkData.GetVoxelChunkAtWorldLocation(worldPos);

                    if(chunk == null)
                    {
                        continue;
                    }

                    Vector3 gridPos = chunk.WorldToGrid(worldPos);
                    int h = chunk.GetFilledHeightOrWaterAt((int) gridPos.X + dx, (int) gridPos.Y, (int) gridPos.Z + dz);

                    if (h > 0)
                    {
                        averageHeight += h;
                        count++;
                    }
                }
            }

            averageHeight = (int) Math.Round(((float) averageHeight/(float) count));

            // Next, create the balloon port by deciding which voxels to fill.
            List<Voxel> designations = new List<Voxel>();
            for(int dx = -size; dx <= size; dx++)
            {
                for(int dz = -size; dz <= size; dz++)
                {
                    Vector3 worldPos = new Vector3(pos.X + dx, pos.Y, pos.Z + dz);
                    VoxelChunk chunk = chunkManager.ChunkData.GetVoxelChunkAtWorldLocation(worldPos);

                    if (chunk == null)
                    {
                        continue;
                    }

                    Vector3 gridPos = chunk.WorldToGrid(worldPos);
                    int h = chunk.GetFilledVoxelGridHeightAt((int) gridPos.X, (int) gridPos.Y, (int) gridPos.Z);

                    if(h == -1)
                    {
                        continue;
                    }

                    for (int y = averageHeight; y < h; y++)
                    {
                        Voxel v = chunk.MakeVoxel((int)gridPos.X, y, (int)gridPos.Z);
                        v.Type = VoxelLibrary.GetVoxelType(0);
                        chunk.Data.Water[v.Index].WaterLevel = 0;
                    }

                    if (averageHeight < h)
                    {
                        h = averageHeight;
                    }

                    // Fill from the top height down to the bottom.
                    for (int y = h - 1; y < averageHeight; y++)
                    {
                        Voxel v = chunk.MakeVoxel((int) gridPos.X, y, (int) gridPos.Z);
                        v.Type = VoxelLibrary.GetVoxelType("Scaffold");
                        chunk.Data.Water[v.Index].WaterLevel = 0;
                        v.Chunk = chunk;
                        v.Chunk.NotifyTotalRebuild(!v.IsInterior);

                        if (y == averageHeight - 1)
                        {
                            designations.Add(v);
                        }
                    }
                }
            }

            // Actually create the BuildRoom.
            BalloonPort toBuild = new BalloonPort(designations, chunkManager);
            BuildRoomOrder buildDes = new BuildRoomOrder(toBuild, roomDes.Faction);
            buildDes.Build();
            roomDes.DesignatedRooms.Add(toBuild);
        }
 public static void cleanup()
 {
     mWallTextures = null;
     mCM = null;
     mSWM = null;
 }