using System; using System.Collections.Generic; using System.IO; namespace Substrate.Core { /// /// Provides a common interface for accessing Alpha-compatible chunk data. /// public interface IChunk { /// /// Gets the global X-coordinate of a chunk. /// int X { get; } /// /// Gets the global Z-coordinate of a chunk. /// int Z { get; } /// /// Gets access to an representing all block data of a chunk. /// AlphaBlockCollection Blocks { get; } /// /// Gets access to an representing all entity data of a chunk. /// EntityCollection Entities { get; } /// /// Gets or sets the flag indicating that the terrain generator has created terrain features. /// /// Terrain features include ores, water and lava sources, dungeons, trees, flowers, etc. bool IsTerrainPopulated { get; set; } /// /// Writes out the chunk's data to an output stream. /// /// A valid, open output stream. /// True if the chunk could be saved; false otherwise. bool Save (Stream outStream); } /// /// Provides a common interface to any object that acts as a physical or abstract chunk container. /// public interface IChunkContainer { /// /// Returns a global chunk X-coordinate, given a container-defined X-coordinate. /// /// An X-coordinate internally assigned to a by a . /// A corresponding global X-coordinate. /// This is largely intended for internal use. If an is assigned coordinates by an /// , the interpretation of those coordinates is ambiguous. This method ensures the coordinate /// returned is interpreted as a global coordinate. int ChunkGlobalX (int cx); /// /// Returns a global chunk Z-coordinate, given a container-defined Z-coordinate. /// /// A Z-coordinate internally assigned to a by a . /// A corresponding global Z-coordinate. /// This is largely intended for internal use. If an is assigned coordinates by an /// , the interpretation of those coordinates is ambiguous. This method ensures the coordinate /// returned is interpreted as a global coordinate. int ChunkGlobalZ (int cz); /// /// Returns a local chunk X-coordinate, given a container-defined X-coordinate. /// /// An X-coordinate internally assigned to a by a . /// A corresponding local X-coordinate. /// This is largely intended for internal use. If an is assigned coordinates by an /// , the interpretation of those coordinates is ambiguous. This method ensures the coordinate /// returned is interpreted as a local coordinate. int ChunkLocalX (int cx); /// /// Returns a local chunk Z-coordinate, given a container-defined Z-coordinate. /// /// A Z-coordinate internally assigned to a by a . /// A corresponding global X-coordinate. /// This is largely intended for internal use. If an is assigned coordinates by an /// , the interpretation of those coordinates is ambiguous. This method ensures the coordinate /// returned is interpreted as a local coordinate. int ChunkLocalZ (int cz); /// /// Gets an unwrapped object for the given container-local coordinates. /// /// The container-local X-coordinate of a chunk. /// The container-local Z-coordinate of a chunk. /// A for the given coordinates, or null if no chunk exists at those coordinates. Chunk GetChunk (int cx, int cz); /// /// Gets a binding a chunk to this container for the given container-local coordinates. /// /// The container-local X-coordinate of a chunk. /// The container-local Z-coordinate of a chunk. /// A for the given coordinates binding a to this container, or null if /// no chunk exists at the given coordinates. ChunkRef GetChunkRef (int cx, int cz); /// /// Creates an empty chunk at the given coordinates, if no chunk previously exists. /// /// The container-local X-coordinate of a chunk. /// The container-local Z-coordinate of a chunk. /// A for the newly created chunk if no previous chunk existed; a /// to the existing chunk otherwise. /// This method ensures that an empty/default chunk is written out to the underlying data store before returning. ChunkRef CreateChunk (int cx, int cz); /// /// Saves an unwrapped to the container at the given container-local coordinates. /// /// The container-local X-coordinate to save the chunk to. /// The container-local Z-coordinate to save the chunk to. /// The to save at the given coordinates. /// A binding to this container at the given location. /// The argument will be updated to reflect new global coordinates corresponding to /// the given location in this container. It is up to the developer to ensure that no competing /// has a handle to the argument, or an inconsistency could develop where the chunk held by the /// other is written to the underlying data store with invalid coordinates. /// The specification is designed to avoid this situation from occuring, but /// class hierarchy extensions could violate these safeguards. ChunkRef SetChunk (int cx, int cz, Chunk chunk); /// /// Checks if a chunk exists at the given container-local coordinates. /// /// The container-local X-coordinate of a chunk. /// The container-local Z-coordinate of a chunk. /// True if a chunk exists at the given coordinates; false otherwise. bool ChunkExists (int cx, int cz); /// /// Deletes a chunk at the given container-local coordinates if it exists. /// /// The container-local X-coordinate of a chunk. /// The container-local Z-coordinate of a chunk. /// True if a chunk existed and was deleted; false otherwise. bool DeleteChunk (int cx, int cz); /// /// Saves any chunks in the container that currently have unsaved changes. /// /// The number of chunks that were saved. /// If this container supports delegating out-of-bounds coordinates to other containers, then any chunk /// modified by an action on this container that was delegated to another container will not be saved. The foreign /// containers must be individually saved, but are guaranteed to know about the unsaved changes originating from /// an action in another container. int Save (); // TODO: Check that this doesn't violate borders /// bool SaveChunk (Chunk chunk); /// /// Checks if this container supports delegating an action on out-of-bounds coordinates to another container. /// /// If a container does not support this property, it is expected to throw /// for any action on out-of-bounds coordinates. bool CanDelegateCoordinates { get; } } /// /// Provides a common interface for chunk containers that provide global management. /// public interface IChunkManager : IChunkContainer, IEnumerable { } }