// Creates FireVFX on Load public override int OnLoad(CastCoord coord, ChunkLoader cl) { ushort? state = cl.chunks[coord.GetChunkPos()].metadata.GetState(coord.blockX, coord.blockY, coord.blockZ); Vector3 fireOffset; if (state == 0 || state == 4) { fireOffset = new Vector3(0.15f, 0f, 0f); } else if (state == 1 || state == 5) { fireOffset = new Vector3(0f, 0f, -0.15f); } else if (state == 2 || state == 6) { fireOffset = new Vector3(-0.15f, 0f, 0f); } else if (state == 3 || state == 7) { fireOffset = new Vector3(0f, 0f, 0.15f); } else { fireOffset = new Vector3(0f, 0f, 0f); } GameObject fire = GameObject.Instantiate(this.fireVFX, new Vector3(coord.GetChunkPos().x *Chunk.chunkWidth + coord.blockX, coord.blockY + 0.35f, coord.GetChunkPos().z *Chunk.chunkWidth + coord.blockZ) + fireOffset, Quaternion.identity); fire.name = BuildVFXName(coord.GetChunkPos(), coord.blockX, coord.blockY, coord.blockZ); this.vfx.Add(coord.GetChunkPos(), fire, active: true); ControlFire(coord.GetChunkPos(), coord.blockX, coord.blockY, coord.blockZ, state); return(1); }
void OnGUI() { LevelName = EditorGUILayout.TextField("Level Name", LevelName); addFileLine(); if (GUILayout.Button("Load Map")) { var info = new DirectoryInfo(filePath); var fileInfo = info.GetFiles("*.tmx"); int index = 0; Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); foreach (FileInfo file in fileInfo) { string chuckname = file.Name.Split(new char[] { '.' })[0]; GameObject chunkGameObject = new GameObject(chuckname); ChunkLoader loader = new ChunkLoader(chunkGameObject); loader.loadFromFile(file.FullName); makeGameObjectAsPrefab(chunkGameObject, chuckname); index++; UnityEngine.Debug.Log("Yo oli on fait " + chuckname); } UnityEngine.Debug.Log("Yo oli on a fini en " + stopWatch.ElapsedMilliseconds / 1000f + "s"); } }
// Handles the emittion of BUD to neighboring blocks public void EmitBlockUpdate(string type, int x, int y, int z, int tickOffset, ChunkLoader cl) { CastCoord thisPos = new CastCoord(new Vector3(x, y, z)); CastCoord[] neighbors = { thisPos.Add(1, 0, 0), thisPos.Add(-1, 0, 0), thisPos.Add(0, 1, 0), thisPos.Add(0, -1, 0), thisPos.Add(0, 0, 1), thisPos.Add(0, 0, -1) }; int[] facings = { 2, 0, 4, 5, 1, 3 }; int faceCounter = 0; foreach (CastCoord c in neighbors) { cl.budscheduler.ScheduleBUD(new BUDSignal(type, c.GetWorldX(), c.GetWorldY(), c.GetWorldZ(), thisPos.GetWorldX(), thisPos.GetWorldY(), thisPos.GetWorldZ(), facings[faceCounter]), tickOffset); faceCounter++; } }
private void createLoader(Vector2I position) { int half = (_properties.worldDimension - 1) / 2; // Create the loader object GameObject obj = new GameObject(); _loader = obj.AddComponent <ChunkLoader>(); _loader.setWorld(this); GameObject loadedPlayer = Resources.Load <GameObject>("Prefabs/" + PlayerPrefs.GetString("PlayerAsset", "Player")); if (loadedPlayer == null) { throw new System.Exception("Failed to find player prefab!"); } // Create the player instance _playerObj = GameObject.Instantiate(loadedPlayer); _playerObj.name = "Player"; obj.transform.parent = _playerObj.transform; // Set the position relative to the middle _loader.setPosition(position); }
// Destroys FireVFX public override int OnBreak(ChunkPos pos, int x, int y, int z, ChunkLoader cl) { string name = BuildVFXName(pos, x, y, z); this.vfx.Remove(pos, name); EraseMetadata(pos, x, y, z, cl); return(0); }
public override void LoadSection(BinaryReaderEx reader) { base.LoadSection(reader); this.baseChunk = ChunkLoader.LoadChunk(SectionType.sdrb, reader, null); this.Children = new List <INavigable>(); this.Children.Add(baseChunk); }
private static bool ConvertEntity(MemoryStream data, string outputPath, ChunkLookup chunkLookup, ChunkLoader chunkLoader) { // TODO(gibbed): implement me. return(false); }
// Fills toDestroy and Safe list // Returns true if all blocks in currentList are connected to a stem // Returns false if all blocks in currentList doesn't connect to a stem or connects to a to-be-destroyed block private int SearchWood(CastCoord init, ChunkLoader cl) { ushort blockCode; ushort state; GetAroundCoords(init, cl); // Filters only Leaf blocks for (int i = 0; i < currentList.Count; i++) { // If it's connected to a marked-to-destroy block if (toDestroy.Contains(currentList[i])) { return(1); } // If it's connected to a safe block if (safeList.Contains(currentList[i])) { return(0); } // If current block is found in initial direction if (validDirections.Contains(currentList[i])) { validDirections.Remove(currentList[i]); } // PANIC if there's too many blocks if (currentList.Count > this.maxAnalysed) { currentList.Clear(); return(2); } blockCode = cl.GetBlock(currentList[i]); state = cl.GetState(currentList[i]); // If it's a spreadable block if (blockCode == this.thisCode && state == 0) { GetAroundCoords(currentList[i], cl); } // Check if it's a root else if (cl.blockBook.CheckSolid(blockCode)) { return(0); } else { currentList.RemoveAt(i); i--; } } return(1); }
private static void Main(string[] args) { ChunkLoader.Initialize(); using (Game = new ParadoxCraftGame()) { Game.Factory.RequestChunk += ChunkLoader.RequestChunk; ChunkLoader.ProcessChunk += Game.Factory.ProcessChunk; Game.Run(); } }
public static int[,] generateChunkAsNumbers(int chunkOffset) { if (chunkLoader==null) chunkLoader=GameObject.Find("ChunkLoader").GetComponent<ChunkLoader>(); int[,] toReturn=new int[chunkLoader.CHUNK_WIDTH, chunkLoader.MAX_SKY_HEIGHT-chunkLoader.BEDROCK_LEVEL]; int surfaceLevel=toReturn.GetLength(1)/2; for (int x=0; x<toReturn.GetLength(0); x++) { generateLayer(x, surfaceLevel, 5, toReturn); } return toReturn; }
//Get references public void Start() { mm = transform.root.GetChild(5).GetComponent <MenuManager>(); mg = transform.root.GetChild(4).GetComponent <MapGenerator>(); pc = transform.root.GetChild(3).GetComponent <PlayerController>(); pi = transform.root.GetChild(3).GetComponent <Inventory>(); pa = transform.root.GetChild(3).GetComponent <Attributes>(); wm = transform.root.GetChild(2).GetComponent <WaypointManager>(); pcl = transform.root.GetChild(3).GetComponent <ChunkLoader>(); env = transform.root.GetChild(5).GetComponent <EnvironmentController>(); }
static void Main(string[] args) { Console.Title = "Generate CLI"; Log("Seed? "); var Seed = string.Empty; while (true) { var Key = Console.ReadKey(); if (Key.Key == ConsoleKey.Enter) { Console.WriteLine(); break; } else if (Key.Key == ConsoleKey.Backspace) { Console.Write(" "); if (Seed.Length != 0) { Seed = Seed.Substring(0, Seed.Length - 1); Console.Write("\b"); } continue; } Seed += Key.KeyChar; } Worker.Master = new Master(Seed.ASCIIBytes()); Constants.Load(); using (Window = new LoopWindow()) using (Renderer = new Renderer(Window)) using (Overlay = new Overlay(Renderer.Device, Renderer.AntiAliasedBackBuffer)) using (Chunks = new ChunkLoader()) using (Sun.Main = new Sun(Constants.SunSeed)) using (Skybox.Main = new Skybox(Constants.SkySeed)) using (var Loop = Window.Loop()) { KeyboardMouse.StartCapture(); Watch = new System.Diagnostics.Stopwatch(); Watch.Start(); while (!Close && Loop.NextFrame()) { Frame(); } } }
// Activates OnBreak event -> Emits normal BUD, emits special BUD to breadt-first search leaves public override int OnBreak(ChunkPos pos, int blockX, int blockY, int blockZ, ChunkLoader cl) { CastCoord thisCoord = new CastCoord(pos, blockX, blockY, blockZ); EmitBlockUpdate("break", thisCoord.GetWorldX(), thisCoord.GetWorldY(), thisCoord.GetWorldZ(), 0, cl); TreeCheck(thisCoord, cl); GetSurroundingLeaves(thisCoord, decayDistance, cl); RunLeavesRecursion(cl, thisCoord); return(0); }
public void unload(bool async) { if (reflectionProbe != null) { ReuseGameObjectHandler.putToRecycle(ReuseableGameObject.REFLECTION_PROBE, reflectionProbe.gameObject); reflectionProbe = null; } foreach (GameObject c in childs) { childList.Remove(c); ReuseGameObjectHandler.putToRecycle(ReuseableGameObject.CHUNK_CHILD, c); } ReuseGameObjectHandler.putToRecycle(ReuseableGameObject.CHUNK, chunkHolder); int x = (int)chunkLocation.getX() + GameManager.halfMaxChunkCount; int y = (int)chunkLocation.getY(); int z = (int)chunkLocation.getZ() + GameManager.halfMaxChunkCount; displayedChunks.Remove(this); GameManager.chunks[x, y, z] = null; Bounds b = new Bounds(); List <Entity> itemEntities = GameManager.getEntitiesByType(ReuseableGameObject.ITEM_ENTITY); b.min = getChunkStartLocation().getVector3(); b.max = getChunkStartLocation().getVector3() + new Vector3(GameManager.chunkSize, GameManager.chunkSize, GameManager.chunkSize); this.entities = new List <Item>(); foreach (Entity e in itemEntities.ToArray()) { if (b.Contains(e.getLocation().getVector3())) { e.remove(); entities.Add((Item)e); needSave = true; } } if (needSave || damagedBlocksIndexs.Count > 0) { string filePath = ChunkLoader.getChunkSaveFilePath(chunkLocation); if (async) { Scheduler.runTaskAsynchronously(() => { Serializer.serializeAndSave <Chunk>(this, filePath); }); } else { Serializer.serializeAndSave <Chunk>(this, filePath); } needSave = false; } //blocks = new Block[0, 0, 0]; }
private static bool ConvertTexture(MemoryStream data, string outputPath, ChunkLookup chunkLookup, ChunkLoader chunkLoader) { var textureHeader = TextureHeader.Read(data); if (textureHeader.Type != TextureType._2d) { return(false); } if (textureHeader.Unknown10 != 0 || (textureHeader.Flags != TextureFlags.None && textureHeader.Flags != TextureFlags.Unknown0 && textureHeader.Flags != (TextureFlags.Unknown0 | TextureFlags.Unknown3) && textureHeader.Flags != TextureFlags.Unknown5) || textureHeader.Unknown1C != 1) { throw new FormatException(); } SHA1 chunkSHA1; long size; if (chunkLookup.GetChunkSHA1(textureHeader.DataChunkId, out chunkSHA1, out size) == false) { throw new InvalidOperationException(); } var dataChunkInfo = chunkLookup.GetChunkVariant(chunkSHA1, size); if (dataChunkInfo == null) { throw new InvalidOperationException(); } byte[] dataBytes; using (var temp = new MemoryStream()) { chunkLoader.Load(dataChunkInfo, textureHeader.TotalSize, temp); temp.Position = 0; dataBytes = temp.GetBuffer(); } using (var output = File.Create(outputPath)) { DDSUtils.WriteFile(textureHeader, dataBytes, output); } return(true); }
//Save loaded chunks public static void SaveLoadedChunks(ChunkLoader loader, string worldName) { BinaryFormatter formatter = new BinaryFormatter(); Directory.CreateDirectory(Application.persistentDataPath + "/Saves/" + worldName); string path = Application.persistentDataPath + "/Saves/" + worldName + "/Chunks.SGSAVE"; FileStream stream = new FileStream(path, FileMode.Create); ChunkData data = new ChunkData(loader); formatter.Serialize(stream, data); stream.Close(); }
private void Awake() { CameraMover.singleton = this; this.main = Main.instance(); this.options = new Options(); this.buildOutline = GameObject.Instantiate(References.list.buildOutlinePrefab).GetComponent <BuildOutline>(); this.team = Team.getTeamFromEnum(this.objectTeam); this.selectedParty.setCameraMover(this); this.chunkLoader = new ChunkLoader(Map.instance(), this, 3); }
void Awake() { // First we check if there are any other instances conflicting if(Instance != null && Instance != this) { // If that is the case, we destroy other instances Destroy(gameObject); } // Here we save our singleton instance Instance = this; chunks = new Dictionary<Vector2, TerrainChunk>(); }
public ActorHost InjectPlayer(Player player) { var cache = ResourceManager.Instance.GetCacheForPlanet(player.Position.Planet); var loader = new ChunkLoader(cache, 14, player.Position.ChunkIndex); cache.EnsureLoaded(player.Position.ChunkIndex); cache.EnsureLoaded(player.Position.ChunkIndex + new Index3(0, 0, 1)); cache.EnsureLoaded(player.Position.ChunkIndex + new Index3(0, 0, -1)); var host = new ActorHost(player, loader); updateDomains[0].ActorHosts.Add(host); return(host); }
/// <summary> /// Initializes objects for data loading: BinaryLoader, ChunkLoader /// Loads initial chunks /// Connects chunkLoader and tilemap /// </summary> private void Start() { var binaryLoader = new BinaryLoader(); var itemBaseDictionary = binaryLoader.LoadItemBaseDicitionary(); tilemap = GetComponent <IsometricLayeredTilemap>(); chunkLoader = new ChunkLoader(376, 271, player); tilemap.RegisterItemBases(itemBaseDictionary); tilemap.RegisterChunkLoader(chunkLoader); chunkLoader.ReloadChunks(); }
public static Chunk ToRealChunk(int[,] chunkAsNumbers, int chunkOffset) { if (chunkLoader==null) chunkLoader=GameObject.Find("ChunkLoader").GetComponent<ChunkLoader>(); Block[,] blocks=new Block[chunkLoader.CHUNK_WIDTH, chunkLoader.MAX_SKY_HEIGHT-chunkLoader.BEDROCK_LEVEL]; for (int x=0; x<blocks.GetLength(0); x++) { for (int y=0; y<blocks.GetLength(1); y++) { Vector3 blockPosition=new Vector3(x+chunkLoader.CHUNK_WIDTH*chunkOffset, y+chunkLoader.BEDROCK_LEVEL, 0); blocks[x, y]=(Block)Instantiate(chunkLoader.blockPrefabs[chunkAsNumbers[x, y]], blockPosition, Quaternion.identity); } } Chunk toReturn=(Chunk)Instantiate(chunkLoader.chunkPrefab, new Vector3(0, 0, 0), Quaternion.identity); toReturn.setBlocks(blocks, chunkOffset); return toReturn; }
public static int[,] generateChunkAsNumbers(int chunkOffset) { if (chunkLoader == null) { chunkLoader = GameObject.Find("ChunkLoader").GetComponent <ChunkLoader>(); } int[,] toReturn = new int[chunkLoader.CHUNK_WIDTH, chunkLoader.MAX_SKY_HEIGHT - chunkLoader.BEDROCK_LEVEL]; int surfaceLevel = toReturn.GetLength(1) / 2; for (int x = 0; x < toReturn.GetLength(0); x++) { generateLayer(x, surfaceLevel, 5, toReturn); } return(toReturn); }
public void RefreshActiveStatus() { bool doActivate = WorldInfo.Instance.IsOverworld; if (ChunkLoader != null) { ChunkLoader.enabled = doActivate; if (doActivate) { ChunkLoader.DoSpawnChunks(); } } ChunkManagerInstance.enabled = doActivate; }
void Awake() { Instance = this; ToGetLoadedChunks = new Dictionary <ChunkData, int>(); LoadedChunks = new Dictionary <Vec2i, LoadedChunk2>(); LoadedRegions = new ChunkRegion[World.RegionCount, World.RegionCount]; ToUnloadChunks = new List <Vec2i>(); SubworldChunks = new Dictionary <Vec2i, LoadedChunk2>(); ThreadSafe = new Object(); ChunkLoader = GetComponent <ChunkLoader>(); }
public static Chunk getChunk(Vector vector) { int x = (int)vector.getX() + halfMaxChunkCount; int y = (int)vector.getY(); int z = (int)vector.getZ() + halfMaxChunkCount; Chunk chunk = chunks[x, y, z]; if (chunk == null) { //Debug.Log("creating new Chunk at " + x + ", " + y + ", " + z + " " + chunk); chunks[x, y, z] = ChunkLoader.loadChunk(vector); chunk = chunks[x, y, z]; } return(chunk); }
// Handles search of Wood Blocks private void RunWoodRecursion(ChunkLoader cl) { CastCoord current; int exitCode; currentList.Clear(); safeList.Clear(); toDestroy.Clear(); while (validDirections.Count > 0) { current = validDirections[0]; validDirections.RemoveAt(0); // If found to-destroy blocks exitCode = SearchWood(current, cl); // Safe if (exitCode == 0) { safeList.AddRange(currentList); currentList.Clear(); } // Invalid else if (exitCode == 1) { toDestroy.AddRange(currentList); currentList.Clear(); } // PANIC else { return; } } foreach (CastCoord aux in toDestroy) { cl.chunks[aux.GetChunkPos()].data.SetCell(aux.blockX, aux.blockY, aux.blockZ, 0); cl.chunks[aux.GetChunkPos()].metadata.Reset(aux.blockX, aux.blockY, aux.blockZ); EmitBlockUpdate("break", aux.GetWorldX(), aux.GetWorldY(), aux.GetWorldZ(), 0, cl); EmitBlockUpdate("decay", aux.GetWorldX(), aux.GetWorldY(), aux.GetWorldZ(), 0, cl); } }
// Returns a filled cache list full of surrounding coords private bool GetSurroundings(CastCoord init, int currentDistance, ChunkLoader cl) { // End if (currentDistance == 0) { return(false); } cache.Clear(); cache.Add(init.Add(0, 0, 1)); // North cache.Add(init.Add(0, 0, -1)); // South cache.Add(init.Add(1, 0, 0)); // East cache.Add(init.Add(-1, 0, 0)); // West cache.Add(init.Add(0, 1, 0)); // Up cache.Add(init.Add(0, -1, 0)); // Down // Filters only Leaf blocks foreach (CastCoord c in cache) { if (cl.GetBlock(c) == this.thisCode && cl.GetState(c) == 0) { // If is already in dict if (distances.ContainsKey(c)) { if (distances[c] > currentDistance) { distances[c] = currentDistance; openList.Add(c); } } else { distances.Add(c, currentDistance); openList.Add(c); } } if (cl.GetBlock(c) == this.assignedWoodCode && cl.GetState(c) == 0) { return(true); } } return(false); }
// Check if there's any wood block around this block private bool CheckWoodAround(CastCoord init, ChunkLoader cl) { cache.Clear(); cache.Add(init.Add(0, 0, 1)); // North cache.Add(init.Add(0, 0, -1)); // South cache.Add(init.Add(1, 0, 0)); // East cache.Add(init.Add(-1, 0, 0)); // West cache.Add(init.Add(0, 1, 0)); // Up cache.Add(init.Add(0, -1, 0)); // Down foreach (CastCoord c in cache) { if (cl.GetBlock(c) == this.thisCode && cl.GetState(c) == 0) { return(true); } } return(false); }
private static void AutoloadComponent(Mod mod) { if (mod.Code == null) { return; } foreach (Type component in mod.Code.GetTypes()) { if (component.IsSubclassOf(typeof(ModWorldGen))) { WorldGenLoader.RegisterWorldGenOption(component); } if (component.IsSubclassOf(typeof(ModChunk))) { ChunkLoader.RegisterModChunk(component); } } }
// Turns on and off Torch public override int OnInteract(ChunkPos pos, int blockX, int blockY, int blockZ, ChunkLoader cl) { ushort state = cl.chunks[pos].metadata.GetState(blockX, blockY, blockZ); if (state == ushort.MaxValue) { return(0); } else if (state >= 4) { cl.chunks[pos].metadata.AddToState(blockX, blockY, blockZ, -4); ControlFire(pos, blockX, blockY, blockZ, (ushort?)(state - 4)); } else if (state >= 0 && state < 4) { cl.chunks[pos].metadata.AddToState(blockX, blockY, blockZ, 4); ControlFire(pos, blockX, blockY, blockZ, (ushort?)(state + 4)); } return(4); }
// Does Search for invalid leaves private bool RunLeavesRecursion(ChunkLoader cl) { bool foundWood = false; while (openList.Count > 0 && !foundWood) { foundWood = GetSurroundings(openList[0], distances[openList[0]] - 1, cl); openList.RemoveAt(0); } distances.Clear(); if (foundWood) { return(true); } else { return(false); } }
// Does Search for invalid leaves private void RunLeavesRecursion(ChunkLoader cl, CastCoord init) { while (openList.Count > 0) { GetSurroundingLeaves(openList[0], distances[openList[0]] - 1, cl); openList.RemoveAt(0); } // Applies DECAY BUD to distant leaves foreach (CastCoord c in distances.Keys) { if (distances[c] == 0) { EmitBUDTo("decay", c.GetWorldX(), c.GetWorldY(), c.GetWorldZ(), 1, cl); } } // Applies DECAY BUD to around blocks if there's no wood around EmitDelayedBUD("decay", init.GetWorldX(), init.GetWorldY(), init.GetWorldZ(), 2, 15, cl); distances.Clear(); }
// Handles the emittion of BUD to neighboring blocks public void EmitBlockUpdate(string type, int x, int y, int z, int tickOffset, ChunkLoader cl) { CastCoord thisPos = GetCoordinates(x, y, z); CastCoord[] neighbors = { thisPos.Add(1, 0, 0), thisPos.Add(-1, 0, 0), thisPos.Add(0, 1, 0), thisPos.Add(0, -1, 0), thisPos.Add(0, 0, 1), thisPos.Add(0, 0, -1) }; int[] facings = { 2, 0, 4, 5, 1, 3 }; int blockCode; int faceCounter = 0; foreach (CastCoord c in neighbors) { // Ignores void updates if (c.blockY < 0 || c.blockY > Chunk.chunkDepth - 1) { continue; } blockCode = cl.chunks[c.GetChunkPos()].data.GetCell(c.blockX, c.blockY, c.blockZ); cachedBUD = new BUDSignal(type, c.GetWorldX(), c.GetWorldY(), c.GetWorldZ(), thisPos.GetWorldX(), thisPos.GetWorldY(), thisPos.GetWorldZ(), facings[faceCounter]); cl.budscheduler.ScheduleBUD(cachedBUD, tickOffset); faceCounter++; } }
void Start() { //Dictionaries cant be initialized in the inspector. So we initialize it here with the values given in inspector for the list terrainAreaButtonsByColor = new Dictionary<Color, TerrainAreaButton> (); foreach (GameObject button in terrainAreaButtons) { TerrainAreaButton component = button.GetComponent<TerrainAreaButton>(); terrainAreaButtonsByColor.Add(component.colorKey, component); } // Get references to managers TCM = TerrainCharacteristicsManager.Instance; CL = ChunkLoader.Instance; // Select the initial defaul area SetSelectedTerrainArea (Color.white, false); }
void Start() { chunkLoader=GameObject.Find("ChunkLoader").GetComponent<ChunkLoader>(); }
public ChunkLoader() { chunkloader = this; }