public ChunkModule(TrueCraftGame game) { Game = game; ChunkRenderer = new ChunkRenderer(Game.Client.World, Game, Game.BlockRepository); Game.Client.ChunkLoaded += (sender, e) => ChunkRenderer.Enqueue(e.Chunk); Game.Client.ChunkUnloaded += (sender, e) => UnloadChunk(e.Chunk); Game.Client.ChunkModified += (sender, e) => ChunkRenderer.Enqueue(e.Chunk, true); ChunkRenderer.MeshCompleted += MeshCompleted; ChunkRenderer.Start(); OpaqueEffect = new BasicEffect(Game.GraphicsDevice); OpaqueEffect.TextureEnabled = true; OpaqueEffect.Texture = Game.TextureMapper.GetTexture("terrain.png"); OpaqueEffect.FogEnabled = true; OpaqueEffect.FogStart = 512f; OpaqueEffect.FogEnd = 1000f; OpaqueEffect.FogColor = Color.CornflowerBlue.ToVector3(); OpaqueEffect.VertexColorEnabled = true; TransparentEffect = new AlphaTestEffect(Game.GraphicsDevice); TransparentEffect.AlphaFunction = CompareFunction.Greater; TransparentEffect.ReferenceAlpha = 127; TransparentEffect.Texture = Game.TextureMapper.GetTexture("terrain.png"); TransparentEffect.VertexColorEnabled = true; ChunkMeshes = new List <ChunkMesh>(); IncomingChunks = new ConcurrentBag <Mesh>(); ActiveMeshes = new HashSet <Coordinates2D>(); }
public Chunk(World world, Vector2Int coordination) { _world = world; _coordination = coordination; _nearbyChunks = new Chunk[8]; _chunkRenderer = new ChunkRenderer(this); _state = ChunkState.Unloaded; _tiles = new Tile[Length, Height, Length]; _entities = new LinkedList <Entity>(); _collidables = new LinkedList <ICollidable <Entity> >(); for (int i = 0; i < Length; i++) { for (int j = 0; j < Height; j++) { for (int k = 0; k < Length; k++) { _tiles[i, j, k] = new Tile(this, (ushort)(i | (j << 4) | (k << 12))); } } } }
public ChunkRenderer CreateChunkRenderer(Chunk c) { ChunkRenderer r = rendererPool.Get().SetUp(c); DrawEvent += r.Draw; return(r); }
public ChunkModule(TrueCraftGame game) { Game = game; ChunkRenderer = new ChunkRenderer(Game.Client.World, Game, Game.BlockRepository); Game.Client.ChunkLoaded += (sender, e) => ChunkRenderer.Enqueue(e.Chunk); Game.Client.ChunkUnloaded += (sender, e) => UnloadChunk(e.Chunk); Game.Client.ChunkModified += (sender, e) => ChunkRenderer.Enqueue(e.Chunk, true); ChunkRenderer.MeshCompleted += MeshCompleted; ChunkRenderer.Start(); OpaqueEffect = new BasicEffect(Game.GraphicsDevice); OpaqueEffect.TextureEnabled = true; OpaqueEffect.Texture = Game.TextureMapper.GetTexture("terrain.png"); OpaqueEffect.FogEnabled = true; OpaqueEffect.FogStart = 512f; OpaqueEffect.FogEnd = 1000f; OpaqueEffect.FogColor = Color.CornflowerBlue.ToVector3(); OpaqueEffect.VertexColorEnabled = true; TransparentEffect = new AlphaTestEffect(Game.GraphicsDevice); TransparentEffect.AlphaFunction = CompareFunction.Greater; TransparentEffect.ReferenceAlpha = 127; TransparentEffect.Texture = Game.TextureMapper.GetTexture("terrain.png"); TransparentEffect.VertexColorEnabled = true; ChunkMeshes = new List<ChunkMesh>(); IncomingChunks = new ConcurrentBag<Mesh>(); ActiveMeshes = new HashSet<Coordinates2D>(); }
public ChunkModule(TrueCraftGame game) { Game = game; ChunkRenderer = new ChunkRenderer(Game.Client.World, Game, Game.BlockRepository); Game.Client.ChunkLoaded += Game_Client_ChunkLoaded; Game.Client.ChunkUnloaded += (sender, e) => UnloadChunk(e.Chunk); Game.Client.ChunkModified += Game_Client_ChunkModified; Game.Client.BlockChanged += Game_Client_BlockChanged; ChunkRenderer.MeshCompleted += MeshCompleted; ChunkRenderer.Start(); WorldLighting = new WorldLighting(Game.Client.World.World, Game.BlockRepository); OpaqueEffect = new BasicEffect(Game.GraphicsDevice); OpaqueEffect.TextureEnabled = true; OpaqueEffect.Texture = Game.TextureMapper.GetTexture("terrain.png"); OpaqueEffect.FogEnabled = true; OpaqueEffect.FogStart = 0; OpaqueEffect.FogEnd = Game.Camera.Frustum.Far.D * 0.8f; OpaqueEffect.VertexColorEnabled = true; OpaqueEffect.LightingEnabled = true; TransparentEffect = new AlphaTestEffect(Game.GraphicsDevice); TransparentEffect.AlphaFunction = CompareFunction.Greater; TransparentEffect.ReferenceAlpha = 127; TransparentEffect.Texture = Game.TextureMapper.GetTexture("terrain.png"); TransparentEffect.VertexColorEnabled = true; OpaqueEffect.LightingEnabled = true; ChunkMeshes = new List<ChunkMesh>(); IncomingChunks = new ConcurrentBag<Mesh>(); ActiveMeshes = new HashSet<Coordinates2D>(); }
/// <summary> /// Initializes the VBO but does not modify graphics state /// </summary> public void Prerender(Structure structure, BlockAtlas blockAtlas) { _vbi.Reset(); for (var pass = 0; pass <= 1; pass++) { for (var x = X * 16; x < X * 16 + 16; x++) { for (var y = 0; y < 256; y++) { for (var z = Z * 16; z < Z * 16 + 16; z++) { if (!structure.Contains(x, y, z)) { continue; } var block = structure[x, y, z]; if (block == null) { continue; } var blockData = blockAtlas[block.Id]; if (blockData == null || blockData.Properties.Render == "none" || blockData.Textures.Count == 0) { continue; } ChunkRenderer.Render(structure, x, y, z, blockAtlas, _vbi, pass); } } } } }
public ChunkModule(TrueCraftGame game) { Game = game; ChunkRenderer = new ChunkRenderer(Game.Client.World, Game, Game.BlockRepository); Game.Client.ChunkLoaded += Game_Client_ChunkLoaded; Game.Client.ChunkUnloaded += (sender, e) => UnloadChunk(e.Chunk); Game.Client.ChunkModified += Game_Client_ChunkModified; Game.Client.BlockChanged += Game_Client_BlockChanged; ChunkRenderer.MeshCompleted += MeshCompleted; ChunkRenderer.Start(); WorldLighting = new WorldLighting(Game.Client.World.World, Game.BlockRepository); OpaqueEffect = new BasicEffect(Game.GraphicsDevice); OpaqueEffect.TextureEnabled = true; OpaqueEffect.Texture = Game.TextureMapper.GetTexture("terrain.png"); OpaqueEffect.FogEnabled = true; OpaqueEffect.FogStart = 0; OpaqueEffect.FogEnd = Game.Camera.Frustum.Far.D * 0.8f; OpaqueEffect.VertexColorEnabled = true; OpaqueEffect.LightingEnabled = true; TransparentEffect = new AlphaTestEffect(Game.GraphicsDevice); TransparentEffect.AlphaFunction = CompareFunction.Greater; TransparentEffect.ReferenceAlpha = 127; TransparentEffect.Texture = Game.TextureMapper.GetTexture("terrain.png"); TransparentEffect.VertexColorEnabled = true; OpaqueEffect.LightingEnabled = true; ChunkMeshes = new List <ChunkMesh>(); IncomingChunks = new ConcurrentBag <Mesh>(); ActiveMeshes = new HashSet <Coordinates2D>(); }
private void MapEventManager_OnChunkRenderDeactivated(ChunkRenderer renderer) { if (_activeChunks.Contains(renderer)) { Debug.Log($"Deactivate chunk {renderer.X}:{renderer.Z}"); _activeChunks.Remove(renderer); } }
public ChunkRenderer GetChunkRendererInstance() { if (chunkRenderer == null) { chunkRenderer = ChunkRenderer.CreateChunkRenderer(position, map, this); } return(chunkRenderer); }
public WorldManager(Viewport viewport, Level level) { Level = level; GeneratePlayer(); Camera = GameCore.Camera.CreateOrthographicCamera(viewport); _chunkRenderer = new ChunkRenderer(viewport); }
public override ChunkRenderer GetChunkRendererInstance() { if (null == chunkRenderer) { chunkRenderer = ChunkRendererImpl.GetInstance(); } return(chunkRenderer); }
public ChunkManager(World world) { this.world = world; this.renderer = new ChunkRenderer(this, world); //TODO convert generator from static class //worldGenerator = new PerlinWorldGenerator(); //worldGenerator.init(); //worldGenerator.setSeed(world.configSettings.Seed()); }
// Debug Purposes public void RegenerateAll() { foreach (Chunk c in Chunks.Values) { ChunkRenderer renderer = c.GetComponent <ChunkRenderer>(); // Procedural Generation & Mesh ProceduralGeneration.AsyncGenerateChunk(c, () => renderer.RegenerateMesh()); } }
public RasterizeWorker(Chunk chunk) { this.chunk = chunk; this.chunk.Working = true; mesh = new ChunkMesh(); renderer = new ChunkRenderer(); chunkView = new ChunkView(chunk); }
internal void UpdatePosition(ChunkRenderer chunk) { var pos = Data.GetVector(); pos -= new Vector3(chunk.Data.X * MapGenerationData.Instance.ChunkSize, 0, chunk.Data.Z * MapGenerationData.Instance.ChunkSize); pos -= new Vector3(0.5f, 0, 0.5f); transform.localPosition = pos; transform.eulerAngles = new Vector3(transform.eulerAngles.x, Data.Rotation, transform.eulerAngles.z); }
public ChunkRenderer GetFreeChunkRenderer() { if (chunkRenderersToReuse.Count > 0) { return(chunkRenderersToReuse.Dequeue()); } var r = ChunkRenderer.CreateNew(); return(r); }
public void DisposeChunkRenderer(ChunkRenderer c) { DrawEvent -= c.Draw; if (rendererPool.Add(c)) { c.CleanUp(); } else { c.Dispose(); } }
public Chunk(ChunkRenderer renderer, Vector3 position, byte sizeX = DefaultSize, byte sizeY = DefaultSize, byte sizeZ = DefaultSize) { Renderer = renderer; Position = position; SizeX = sizeX; SizeY = sizeY; SizeZ = sizeZ; TotalSize = sizeX * sizeY * sizeZ; Blocks = new BlockGrid(this); }
private void MapEventManager_OnChunkRenderActivated(ChunkRenderer renderer) { if (!_activeChunks.Contains(renderer)) { Debug.Log($"Activate chunk {renderer.X}:{renderer.Z}"); foreach (var structure in _chunkStructureLookup[renderer]) { SpawnStructure(structure); } _activeChunks.Add(renderer); } }
void CreateChunkRenderer(Vector3Int chunkPos, ChunkData chunkData) { Debug.Log("Creating chunk"); GameObject newChunk = new GameObject(chunkPos.ToString()); newChunk.gameObject.layer = LayerMask.NameToLayer("Blocks"); ChunkRenderer chunkRenderer = newChunk.AddComponent <ChunkRenderer>(); chunkRenderer.Initialize(chunkPos, chunkData); chunkRenderers.Add(chunkRenderer); chunkRendererMap.Add(chunkPos, chunkRenderer); }
private void CreateChunk(IntVector3 chunkPos) { Chunk chunk = voxelObject.LoadChunk(chunkPos); // Instantiate chunk renderer GameObject crObj = (GameObject)Instantiate(ChunkPrefab, (Vector3)voxelObject.PosHelper.ChunkToObjectPosition(chunk.ChunkPosition), Quaternion.identity); ChunkRenderer cr = crObj.GetComponent <ChunkRenderer>(); chunks.Add(cr); crObj.transform.parent = chunkContainer.transform; cr.SetChunk(chunk); }
private void Game_Client_ChunkLoaded(object sender, ChunkEventArgs e) { ChunkRenderer.Enqueue(e.Chunk); for (int i = 0; i < AdjacentCoordinates.Length; i++) { ReadOnlyChunk adjacent = Game.Client.World.GetChunk( AdjacentCoordinates[i] + e.Chunk.Coordinates); if (adjacent != null) { ChunkRenderer.Enqueue(adjacent); } } }
public Terrain(MasterRenderer renderer) { if (!GlobalNetwork.IsServer) { entRenderer = renderer.GetRenderer3D <EntityRenderer>(); chunkRenderer = renderer.GetRenderer3D <ChunkRenderer>(); MeshReadyChunks = new ConcurrentQueue <Chunk>(); } Chunks = new ConcurrentDictionary <IndexPosition, Chunk>(); AllChanges = new List <BlockChange>(); TrackChanges = GlobalNetwork.IsServer; }
// Use this for initialization void Start() { Chunk chunk = new Chunk(Vector3.zero * chunkSize, chunkSize); ChunkRenderer chunkRenderer = gameObject.GetComponent <ChunkRenderer>(); if (drawCombined) { chunkRenderer.DrawCombined(chunk, chunkSize, gameObject, cubeMaterial); } else { chunkRenderer.Draw(chunk, chunkSize, gameObject, cubeMaterial); } }
public static int GetBlockID(RaycastHit hit, bool adjacent = false) { ChunkRenderer chunk = hit.collider.GetComponent <ChunkRenderer>(); if (chunk == null) { return(0); } Vector3Int pos = GetBlockPos(hit, adjacent); return(chunk.chunkData.GetBlock(pos.x, pos.y, pos.z)); }
public void Load() { Tabs tabs = GameObject.Find("Phases").GetComponent <Tabs>(); tabs.activateAll(); EnviromentSaveAndLoadManager.getInstance().loadMap(); DetailsSaveAndLoadManager.getInstance().loadDetails(); TerraformSaveAndLoadManager.getInstance().loadMap(); ChunkRenderer.renderAll(); tabs.returnState(); }
protected override void Draw(GameTime gameTime) { lock (LockForStateValidationOutput) { base.Draw(gameTime); } // Indicate that we have drawn at least one frame. this.HasTicked = true; // Unload unused chunks from memory. ChunkProvider.DiscardUnneededChunks(); ChunkRenderer.DiscardUnusedChunks(); }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { base.Initialize(); this.Window.Title = "Tychaia"; this.IsMouseVisible = true; //this.IsFixedTimeStep = false; DeviceForStateValidationOutput = this.GraphicsDevice; ContextForStateValidationOutput = this.m_GameContext; RenderingBuffers.Initialize(this.m_GameContext); ChunkRenderer.Initialize(this.m_GameContext.Graphics.GraphicsDevice); ChunkProvider.Initialize(); this.Window.ClientSizeChanged += HandleClientSizeChanged; }
/** * Create a new GameObject with a ChunkRenderer component * and link it to the given chunk chunk. * Returns false if the chunk is empty. In that case * no visual chunk will be generated. */ bool MakePhysical(Chunk chunk) { if (!chunk.empty) { Vector3 newPos = new Vector3(chunk.pos.x, chunk.pos.y, chunk.pos.z); GameObject newRenderer = Instantiate(chunkPrefab, newPos, Quaternion.Euler(Vector3.zero)) as GameObject; ChunkRenderer renderer = newRenderer.GetComponent <ChunkRenderer>(); renderer.chunk = chunk; chunk.renderer = renderer; newRenderer.name = "Chunk (" + chunk.pos.x + ", " + chunk.pos.y + ", " + chunk.pos.z + ")"; newRenderer.transform.parent = gameObject.transform; return(true); } return(false); }
/** * Returns the block where the raycast hits. * Returns 0(air) if no block was found. */ public static int GetBlock(RaycastHit hit, bool adjacent = false) { ChunkRenderer renderer = hit.collider.GetComponent <ChunkRenderer>(); if (renderer == null) { return(0); } WorldPos pos = GetBlockPos(hit, adjacent); int block = renderer.chunk.world.GetBlock(pos.x, pos.y, pos.z); return(block); }
/** * Sets the block where the raycast hits and returns true. * Returns false if no block was found to be set. */ public static bool SetBlock(RaycastHit hit, int id, bool adjacent = false) { ChunkRenderer renderer = hit.collider.GetComponent <ChunkRenderer>(); if (renderer == null) { return(false); } WorldPos pos = GetBlockPos(hit, adjacent); renderer.chunk.world.SetBlock(pos.x, pos.y, pos.z, id); return(true); }
void RunSingleTest() { IBlockSource source = new TestSource(); MarchingPointDictionary blockData = new MarchingPointDictionary((64, 64, 64)); source.generateAll(blockData); ChunkRenderer chunk = Instantiate( chunkPrefab, Vector3.zero, Quaternion.identity ).GetComponent <ChunkRenderer>(); chunk.blockData = blockData; }
private void RenderChunk(Chunk chunk) { Counters.Instance.Increment("chunks in view range"); if (chunk == null || !ChunkRenderer.InsideViewFrustum(chunk)) return; Counters.Instance.Increment("chunks rendered"); // get chunkrenderer for this chunk (create new if it does not exist) object key = chunk.Position.Key; ChunkRenderer chunkRenderer; if (chunkRenderers.ContainsKey(key)) chunkRenderer = chunkRenderers[key]; else { chunkRenderer = new ChunkRenderer(chunk); chunkRenderers.Add(key, chunkRenderer); } forceCachedRendering |= chunkRenderer.Render(forceCachedRendering); if(chunkRenderer.HasPass2()) pass2ChunkRenderers.Add(chunkRenderer); }
protected override void Initialize() { Interfaces = new List<IGameInterface>(); SpriteBatch = new SpriteBatch(GraphicsDevice); base.Initialize(); // (calls LoadContent) ChunkConverter = new ChunkRenderer(this, Client.World.World.BlockRepository); Client.ChunkLoaded += (sender, e) => ChunkConverter.Enqueue(e.Chunk); //Client.ChunkModified += (sender, e) => ChunkConverter.Enqueue(e.Chunk, true); ChunkConverter.MeshCompleted += ChunkConverter_MeshGenerated; ChunkConverter.Start(); Client.PropertyChanged += HandleClientPropertyChanged; Client.Connect(EndPoint); var centerX = GraphicsDevice.Viewport.Width / 2; var centerY = GraphicsDevice.Viewport.Height / 2; Mouse.SetPosition(centerX, centerY); Camera = new Camera(GraphicsDevice.Viewport.AspectRatio, 70.0f, 0.25f, 1000.0f); UpdateCamera(); Window.ClientSizeChanged += (sender, e) => CreateRenderTarget(); MouseComponent.Move += OnMouseComponentMove; KeyboardComponent.KeyDown += OnKeyboardKeyDown; KeyboardComponent.KeyUp += OnKeyboardKeyUp; CreateRenderTarget(); }
// Use this for initialization void Start() { rend = GetComponent<ChunkRenderer>(); rend.chunk = chunk = new TerrainChunk(fill); }