public void SpawnCreatures()
    {
        Chunk spawnChunk = WorldChunkManager.instance.GetSpawnChunk();

        MultiThreader.DoThreaded(() => spawnChunk.data.TGetTile(new Vector2DInt(5, 5)), (Tile inTile) => Player.creatureManager.AddCreature(new Creature(inTile)));
        MultiThreader.DoThreaded(() => spawnChunk.data.TGetTile(new Vector2DInt(6, 5)), (Tile inTile) => Player.creatureManager.AddCreature(new Creature(inTile)));
    }
Exemple #2
0
    void Update()
    {
        _worldChunkManager.Update();

        Player.ManualUpdate();
        MultiThreader.ManualUpdate();

        if (Input.GetKeyDown(KeyCode.F))
        {
            Vector3     mouseWorldPosition  = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            Vector2DInt targetWorldPosition = new Vector2DInt((int)mouseWorldPosition.x, (int)mouseWorldPosition.z);

            WorldChunkManager.instance.PlaceFurniture(targetWorldPosition, new Furniture(new Vector2DInt(2, 2), targetWorldPosition));
        }
    }
Exemple #3
0
    public void LoadFromDisk(Vector2DInt inChunkPosition)
    {
        // Open chunk save file
        string chunkFilePath = Constants.Terrain.CHUNK_SAVE_FOLDER + "\\" + inChunkPosition.ToString() + ".chunk";

        using (FileStream stream = FileStreamExtensions.LoadAndWaitUntilLoaded(chunkFilePath, FileMode.Open))
            using (BinaryReader reader = new BinaryReader(stream))
            {
                // Create tile array
                int chunkSize = Constants.Terrain.CHUNK_SIZE;
                SetTiles(new Tile[chunkSize, chunkSize]);

                // Load all tiles from disk
                for (int y = 0; y < chunkSize; y++)
                {
                    for (int x = 0; x < chunkSize; x++)
                    {
                        Vector2DInt tileLocalPosition = new Vector2DInt(x, y);
                        Terrain     tileTerrain       = new Terrain((TerrainType)reader.ReadUInt16()); // Read: Terrain type

                        _tiles[x, y] = new Tile(tileLocalPosition, inChunkPosition, tileTerrain);
                    }
                }

                // Load and place all furnitures
                int numFurnitures = reader.ReadInt32();                                  // Read: Furniture count
                for (int i = 0; i < numFurnitures; i++)
                {
                    Furniture loadedFurniture = new Furniture(reader);                   // Read: Furniture

                    // TODO: Check if there's a furniture within the target area. If so, take that one and place it on itself.
                    WorldChunkManager.instance.PlaceFurniture(loadedFurniture.position, loadedFurniture);
                }

                // TODO: Load the queue of all the furnitures that should be replaced. The queue should just hold furniture type and position. Get the furniture at the saved position and save it on top of itself

                MultiThreader.InvokeOnMain(() => _dirtyFlags.Add(ChunkDirtyFlags.Terrain, ref _dirtyFlags));
            }
    }