Exemple #1
0
		public Level(ChunkType chunkType)
		{
			_chunkType = chunkType;
			_generator = ChunkGeneratorFactory.Instance.GetGenerator(chunkType, CHUNK_WIDTH, CHUNK_HEIGHT, null);
			_chunks = new Chunk[LEVEL_HEIGHT, LEVEL_WIDTH];
			_ambientLightLevel = _generator.AmbientLightLevel;
		}
Exemple #2
0
 public Level(ChunkType chunkType)
 {
     _chunkType         = chunkType;
     _generator         = ChunkGeneratorFactory.Instance.GetGenerator(chunkType, CHUNK_WIDTH, CHUNK_HEIGHT, null);
     _chunks            = new Chunk[LEVEL_HEIGHT, LEVEL_WIDTH];
     _ambientLightLevel = _generator.AmbientLightLevel;
 }
 /// <summary> Constructor. </summary>
 /// <exception cref="ArgumentNullException"> Thrown when one or more required arguments are null. </exception>
 /// <param name="generator"> The chunk generator to use when a chunk has not yet been created. </param>
 public SimpleChunkLoader(IChunkGenerator generator)
 {
     if (generator == null)
     {
         throw new ArgumentNullException("generator");
     }
     _generator = generator;
 }
Exemple #4
0
 public WorldGenerator(World world, IChunkGenerator chunkGenerator, ChunkBuilder chunkBuilder, IEventManager eventManager, DiagnosticsService diagnosticsService)
 {
     _world              = world;
     _chunkGenerator     = chunkGenerator;
     _chunkBuilder       = chunkBuilder;
     _eventManager       = eventManager;
     _diagnosticsService = diagnosticsService;
 }
Exemple #5
0
 public Map(int grid, int viewDistance, IChunkGenerator generator, GameObjectGenerator gameObjectGenerator)
 {
     Chunks              = new Dictionary <Vector2, Chunk> ();
     Grid                = grid;
     ViewDistance        = viewDistance;
     Generator           = generator;
     GameObjectGenerator = gameObjectGenerator;
 }
        public LocalChunkProvider(Map map)
        {
            Map.Current = LocalMap = map;
            map.ChunkProvider = this;

            //ChunkGenerator = new SimplePerlinGenerator();
            //ChunkGenerator = new SolidChunkGenerator();
            ChunkGenerator = new SimpleTerrainGenerator();
        }
Exemple #7
0
        public void Render(IChunkGenerator generator, Chunk chunk, int floorId, int wallId)
        {
            generator.Fill(chunk, ChunkLayer.Floor, Bounds.Inflate(-1), floorId);
            generator.Fill(chunk, ChunkLayer.Blocking, Bounds.Inflate(-1), 0);

            generator.DrawVerticalLine(chunk, ChunkLayer.Blocking, Bounds.Top, Bounds.Bottom, Bounds.Left, wallId);
            generator.DrawVerticalLine(chunk, ChunkLayer.Blocking, Bounds.Top, Bounds.Bottom, Bounds.Right, wallId);

            generator.DrawHorizontalLine(chunk, ChunkLayer.Blocking, Bounds.Top, Bounds.Left, Bounds.Right, wallId);
            generator.DrawHorizontalLine(chunk, ChunkLayer.Blocking, Bounds.Bottom, Bounds.Left, Bounds.Right, wallId);
        }
Exemple #8
0
        public IChunkGenerator GetNewGenerator(string type, long seed)
        {
            IChunkGenerator generator = _World.Server.GetChunkGenerator(type);

            if (generator == null)
            {
                return(null);
            }

            generator.Init(_World, seed);

            return(generator);
        }
Exemple #9
0
    public EntityStore(IChunkGenerator generator, string entityID)
    {
        UnityEngine.Debug.Log(Path.GetFullPath(entityID + ".index"));
        this.generator        = generator;
        this.hashToFileOffset = new StoredDictionary <string, int>(entityID + ".index");

        foreach (var pair in hashToFileOffset)
        {
            newChunkIndex = Math.Max(newChunkIndex, pair.Value + 1);
        }

        this.chunkStorer = new ChunkStorer(entityID + ".chunks");
    }
        public ServerChunkManager(
            TychaiaServer server, 
            IChunkOctreeFactory chunkOctreeFactory, 
            IChunkGenerator chunkGenerator,
            IChunkSizePolicy chunkSizePolicy)
        {
            this.m_Server = server;
            this.m_ChunkOctreeFactory = chunkOctreeFactory;
            this.m_ChunkGenerator = chunkGenerator;
            this.m_ChunkSizePolicy = chunkSizePolicy;
            this.m_RequestedChunks = new ConcurrentQueue<ChunkRequest>();

            this.m_ChunkGenerator.InputDisconnect();
        }
Exemple #11
0
 public void Generate(IChunkGenerator generator)
 {
     BlockType[,,] generatedBlocks = generator.Generate(ChunkPos);
     for (int x = 0; x < BlockSize; x++)
     {
         for (int y = 0; y < BlockSize; y++)
         {
             for (int z = 0; z < BlockSize; z++)
             {
                 blocks[x + 1, y + 1, z + 1] = generatedBlocks[x, y, z];
             }
         }
     }
 }
Exemple #12
0
    public void Start()
    {
        Random.InitState((int)DateTime.Now.Ticks);

        _isLastChunk = false;

        _roadChunks = new LinkedList <RoadChunkObject>();

        _position = _startPosition;

        _bunGenerator       = new ClassicBunGenerator(5, 10);
        _chunkGenerator     = new ClassicChunkGenerator(_bunGenerator, _chunkPrefabs, _roadChunks);
        _initChunkGenerator = new InitialChunkGenerator(_bunGenerator, _startChunkPrefab, _roadChunks);

        InstantiateFOVChunks();

        StartCoroutine(InstantiateNextChunk());
    }
Exemple #13
0
    protected override void Setup(out List <Point3D> blocks, out IChunkGenerator chunkGenerator, out string entityID)
    {
        chunkGenerator = new PlanetGenerator(planetScale, this);
        blocks         = new List <Point3D>();
        for (int x = -planetScale * 3; x < planetScale * 3; x++)
        {
            for (int y = -planetScale * 3; y < planetScale * 3; y++)
            {
                for (int z = -planetScale * 3; z < planetScale * 3; z++)
                {
                    int xOut = x >= planetScale || x < -planetScale ? 1 : 0;
                    int yOut = y >= planetScale || y < -planetScale ? 1 : 0;
                    int zOut = z >= planetScale || z < -planetScale ? 1 : 0;
                    if ((xOut + yOut + zOut) == 1)
                    {
                        blocks.Add(new Point3D(x, y, z));
                    }
                }
            }
        }

        entityID = gameObject.name;
    }
Exemple #14
0
        public bool Load()
        {
            EnsureDirectory();

            //Event
            WorldLoadEventArgs e = new WorldLoadEventArgs(this);
            Server.PluginManager.CallEvent(Event.WORLD_LOAD, e);
            if (e.EventCanceled) return false;
            //End Event

            _ChunkProvider = new ChunkProvider(this);
            Generator = _ChunkProvider.GetNewGenerator(GeneratorType.Custom, GetSeed());
            ChunkManager = new WorldChunkManager(this);
            PhysicsBlocks = new ConcurrentDictionary<int, BlockBasePhysics>();

            InitializeSpawn();
            InitializeThreads();
            InitializeWeather();
            return true;
        }
Exemple #15
0
        public bool Load()
        {
            EnsureDirectory();

            //Event
            WorldLoadEventArgs e = new WorldLoadEventArgs(this);
            Server.PluginManager.CallEvent(Event.WorldLoad, e);
            if (e.EventCanceled) return false;
            //End Event

            _chunkProvider = new ChunkProvider(this);
            _generator = _chunkProvider.GetNewGenerator(GeneratorType.Custom, GetSeed());
            PhysicsBlocks = new ConcurrentDictionary<int, BaseFallingPhysics>();

            InitializeSpawn();
            InitializeWeather();
            Running = true;
            return true;
        }
Exemple #16
0
 public void AddChunkGenerator(string name, IChunkGenerator generator)
 {
     _generators.Add(name, generator);
 }
Exemple #17
0
 public BiomeData(IChunkGenerator generator)
 {
     _chunkGenerator = generator;
 }
Exemple #18
0
		public void Render(IChunkGenerator generator, Chunk chunk, int floorId, int wallId)
		{
			generator.Fill(chunk, ChunkLayer.Floor, Bounds.Inflate(-1), floorId);
			generator.Fill(chunk, ChunkLayer.Blocking, Bounds.Inflate(-1), 0);

			generator.DrawVerticalLine(chunk, ChunkLayer.Blocking, Bounds.Top, Bounds.Bottom, Bounds.Left, wallId);
			generator.DrawVerticalLine(chunk, ChunkLayer.Blocking, Bounds.Top, Bounds.Bottom, Bounds.Right, wallId);

			generator.DrawHorizontalLine(chunk, ChunkLayer.Blocking, Bounds.Top, Bounds.Left, Bounds.Right, wallId);
			generator.DrawHorizontalLine(chunk, ChunkLayer.Blocking, Bounds.Bottom, Bounds.Left, Bounds.Right, wallId);
		}
Exemple #19
0
 public ChunkStore(IChunkGenerator generator, Material material, Transform parentTransform)
 {
     this.material        = material;
     this.parentTransform = parentTransform;
     this.generator       = generator;
 }
Exemple #20
0
        public TychaiaGameWorld(
            IAssetManagerProvider assetManagerProvider, 
            I3DRenderUtilities threedRenderUtilities, 
            IFilteredFeatures filteredFeatures, 
            IChunkOctreeFactory chunkOctreeFactory, 
            IIsometricCameraFactory isometricCameraFactory, 
            IChunkSizePolicy chunkSizePolicy, 
            IChunkManagerEntityFactory chunkManagerEntityFactory, 
            IProfiler profiler, 
            IConsole console, 
            ILevelAPI levelAPI /* temporary */, 
            IGameUIFactory gameUIFactory, 
            I2DRenderUtilities twodRenderUtilities,
            IClientNetworkAPI networkAPI,
            IEntityFactory entityFactory,
            IChunkConverter chunkConverter,
            IChunkCompressor chunkCompressor,
            IChunkGenerator chunkGenerator,
            ITerrainSurfaceCalculator terrainSurfaceCalculator,
            int uniqueClientIdentifier,
            Action cleanup,
            IViewportMode viewportMode)
        {
            this.m_3DRenderUtilities = threedRenderUtilities;
            this.m_FilteredFeatures = filteredFeatures;
            this.m_ChunkSizePolicy = chunkSizePolicy;
            this.m_Profiler = profiler;
            this.m_Console = console;
            this.m_2DRenderUtilities = twodRenderUtilities;
            this.m_NetworkAPI = networkAPI;
            this.m_EntityFactory = entityFactory;
            this.m_ChunkConverter = chunkConverter;
            this.m_ChunkCompressor = chunkCompressor;
            this.m_ChunkGenerator = chunkGenerator;
            this.m_TerrainSurfaceCalculator = terrainSurfaceCalculator;
            this.m_UniqueClientIdentifier = uniqueClientIdentifier;
            this.m_AssetManagerProvider = assetManagerProvider;
            this.m_Cleanup = cleanup;
            this.Level = levelAPI.NewLevel("test");
            this.m_ViewportMode = viewportMode;

            this.m_DefaultFontAsset = this.m_AssetManagerProvider.GetAssetManager().Get<FontAsset>("font.Default");

            this.ChunkOctree = chunkOctreeFactory.CreateChunkOctree<ClientChunk>();
            var chunk = new ClientChunk(0, 0, 0);
            this.IsometricCamera = isometricCameraFactory.CreateIsometricCamera(this.ChunkOctree, chunk);
            this.m_ChunkManagerEntity = chunkManagerEntityFactory.CreateChunkManagerEntity(this);

            this.m_InventoryUIEntity = gameUIFactory.CreateInventoryUIEntity();
            this.Entities = new List<IEntity> { this.m_ChunkManagerEntity, this.m_InventoryUIEntity };

            // TODO: Move this somewhere better.
            this.m_NetworkAPI.ListenForMessage(
                "player update",
                (client, data) =>
                {
                    var playerState = InMemorySerializer.Deserialize<PlayerServerEntity.PlayerServerState>(data);

                    // Lookup the player entity for this unique client ID if we have one.
                    var player =
                        this.Entities.OfType<PlayerEntity>()
                            .FirstOrDefault(x => x.RuntimeData.UniqueClientIdentifier == playerState.UniqueClientID);

                    if (player == null)
                    {
                        // Need to create a new player entity.
                        player =
                            this.m_EntityFactory.CreatePlayerEntity(
                                new Player { UniqueClientIdentifier = playerState.UniqueClientID });
                        this.Entities.Add(player);
                    }

                    player.X = playerState.X;
                    player.Y = playerState.Y;
                    player.Z = playerState.Z;
                });

            // TODO: Move this somewhere better.
            this.m_NetworkAPI.ListenForMessage(
                "player leave",
                (client, data) =>
                {
                    var playerState = InMemorySerializer.Deserialize<PlayerServerEntity.PlayerServerState>(data);

                    // Lookup the player entity for this unique client ID if we have one.
                    var player =
                        this.Entities.OfType<PlayerEntity>()
                            .FirstOrDefault(x => x.RuntimeData.UniqueClientIdentifier == playerState.UniqueClientID);

                    // If we have a player entity, remove it from the world.
                    if (player != null)
                    {
                        this.Entities.Remove(player);
                    }
                });

            // TODO: Move this somewhere better.
            this.m_NetworkAPI.ListenForMessage(
                "chunk available",
                (client, data) =>
                {
                    var dataChunk = this.m_ChunkCompressor.Decompress(data);

                    var clientChunk = this.ChunkOctree.Get(dataChunk.X, dataChunk.Y, dataChunk.Z);
                    if (clientChunk == null)
                    {
                        clientChunk = new ClientChunk(dataChunk.X, dataChunk.Y, dataChunk.Z);
                        this.ChunkOctree.Set(clientChunk);
                    }
                    else if (clientChunk.Generated)
                    {
                        // TODO: We already have this chunk.  The server shouldn't announce it to
                        // us because we've already had it sent before, but at the moment the server
                        // doesn't track this.  We just ignore it for now (so we don't recompute
                        // graphics data).
                        Console.WriteLine("Chunk is marked as generated, will not reload from server");
                        return;
                    }

                    this.m_ChunkConverter.FromChunk(dataChunk, clientChunk);

                    this.m_ChunkGenerator.Generate(clientChunk);
                });
        }
Exemple #21
0
 public void Initialize()
 {
     _chunkGenerator = new CustomChunkGenerator();
     Server.AddChunkGenerator("Default", _chunkGenerator);
 }
Exemple #22
0
        internal bool Load()
        {
            EnsureDirectory();

            //Event
            WorldLoadEventArgs e = new WorldLoadEventArgs(this);
            Server.PluginManager.CallEvent(Event.WorldLoad, e);
            if (e.EventCanceled) return false;
            //End Event

            _chunkProvider = new ChunkProvider(this);
            _generator = _chunkProvider.GetNewGenerator("Default", GetSeed());
            PhysicsBlocks = new ConcurrentDictionary<int, BaseFallingPhysics>();

            if (_generator == null)
            {
                Logger.Log(LogLevel.Error,
                           "No ChunkGenerator found in the Plugins folder! Add the default one from CustomGenerator project and then restart the server.");
                return false;
            }

            InitializeSpawn();
            InitializeWeather();
            Running = true;
            return true;
        }
Exemple #23
0
 protected abstract void Setup(out List <Point3D> blocksToInit, out IChunkGenerator chunkGenerator, out string entityID);
 public void Initialize()
 {
     _chunkGenerator = new CustomChunkGenerator();
     Server.AddChunkGenerator("Default", _chunkGenerator);
 }
Exemple #25
0
 public WorldManager(IBlocksProvider blocksProvider, IChunkManager chunkManager, IChunkGenerator chunkGenerator)
 {
     _blocksProvider = blocksProvider;
     _chunkManager   = chunkManager;
     _chunkGenerator = chunkGenerator;
 }