/// <summary> /// Places the structure into the world. /// </summary> public void placeIntoWorld(World world, Position pos) { for (int x = 0; x < this.width; x++) { for (int y = 0; y < this.height; y++) { TileEntry entry = this.getEntry(x, y); Position pos1 = pos.add(x, y); if (entry == null) { world.setCell(pos1, null); } else { if (entry.buildable != null) { entry.buildable.placeIntoWorld(world, null, pos1, Rotation.fromEnum(entry.rotation)); } else if (entry.cell != null) { world.setCell(pos1, entry.cell); } } if (this.liftFog) { world.liftFog(pos1); } } } }
public void SaveBoard() { EditorControl ec = FindObjectOfType <EditorControl>(); if (!ec.isStartTile || !ec.isEndTile) { warningText.text = "Need to add a Start/End Tile"; warningText.gameObject.SetActive(true); return; } if (inputField.text == null) { warningText.text = "Need to Enter a Level Name"; warningText.gameObject.SetActive(true); return; } foreach (BoardTile bt in gameSU.tiles) { TileEntry newTile = new TileEntry(); newTile.tileType = bt.tileType; newTile.tileX = bt.coordinates.x; newTile.tileZ = bt.coordinates.z; newTile.tileRot = bt.rot; tileDB.list.Add(newTile); } SaveTiles(inputField.text); }
/// <summary> /// fetches a tilemap. this is simple; apparently only the screen size (shape) is a factor (not the tile size) /// </summary> public TileEntry[] FetchTilemap(int addr, ScreenSize size) { var blockDims = SizeInBlocksForBGSize(size); int blocksw = blockDims.Width; int blocksh = blockDims.Height; int width = blockDims.Width * 32; int height = blockDims.Height * 32; TileEntry[] buf = new TileEntry[width * height]; for (int by = 0; by < blocksh; by++) { for (int bx = 0; bx < blocksw; bx++) { for (int y = 0; y < 32; y++) { for (int x = 0; x < 32; x++) { int idx = (by * 32 + y) * width + bx * 32 + x; ushort entry = *(ushort *)(vram + addr); buf[idx].tilenum = (ushort)(entry & 0x3FF); buf[idx].palette = (byte)((entry >> 10) & 7); buf[idx].flags = (TileEntryFlags)((entry >> 13) & 7); buf[idx].address = addr; addr += 2; } } } } return(buf); }
// <summary> // Cancels the request for a tile by its URL. // </summary> public void Cancel(string url) { tileURLLookedFor = url; TileEntry entry = tilesToLoad.Find(tileURLMatchPredicate); if (entry != null) { #if DEBUG_LOG Debug.Log("DEBUG: TileDownloader.Cancel: remove download from schedule: " + url); #endif tilesToLoad.Remove(entry); return; } entry = tilesLoading.Find(tileURLMatchPredicate); if (entry != null) { #if DEBUG_LOG Debug.Log("DEBUG: TileDownloader.Cancel: stop downloading: " + url); #endif tilesLoading.Remove(entry); entry.StopDownload(); return; } #if DEBUG_LOG Debug.LogWarning("WARNING: TileDownloader.Cancel: url not scheduled to be downloaded nor downloading: " + url); #endif }
public void SaveTiles(string name, bool mix) { tileDB.list.Clear(); for (int i = 0; i < 25; i++) { GameObject go = GameObject.Find("Tile" + (i + 1).ToString()); TileEntry tl = new TileEntry(); tl.TileEntryLoad(i + 1, (TileType)Enum.Parse(typeof(TileType), go.tag), (int)go.transform.rotation.eulerAngles.z, Cuadrantes[i], go.transform.Find("Canvas").transform.Find("Text").GetComponent <Text>().text); tileDB.list.Add(tl); } if (mix) { for (int i = 25; i > 1; i--) { i--; int k = rng.Next(i + 1); int prevNum = tileDB.list[k].TileNumber; tileDB.list[k].TileNumber = tileDB.list[i].TileNumber; tileDB.list[i].TileNumber = prevNum; } } XmlSerializer serializer = new XmlSerializer(typeof(TileDatabase)); FileStream stream = new FileStream(Application.dataPath + "/ConfigFiles/" + name, FileMode.Create); serializer.Serialize(stream, tileDB); stream.Close(); }
private static bool tileURLMatchPredicate(TileEntry entry) { if (entry.url == tileURLLookedFor) { return(true); } return(false); }
/// <summary> /// Populates <paramref name="result"/> with the location data from the given <see cref="TileEntry"/> and <see cref="ShallowTileConfig"/> (instead of by trying to reference the original implementation) /// </summary> /// <param name="entry"></param> /// <param name="shallowTile"></param> /// <param name="result"></param> [Obsolete] public static void GetTransformFromShallow(this TileEntry entry, ShallowTileConfig shallowTile, out Transform3D result) { result = new Transform3D(); int x = entry.getLocation().x; int y = entry.getLocation().y; int w = entry.GetWidth(shallowTile); int h = entry.GetHeight(shallowTile); TudeySceneMetrics.getTileTransform(w, h, x, y, entry.elevation, entry.rotation, result); }
public Sprite Get(int id) { TileEntry entry = GetEntry(id); if (entry == null) { throw new KeyNotFoundException(id.ToString()); } return(entry.Sprite); }
public int Lookup(string spriteName) { TileEntry entry = GetEntry(spriteName); if (entry == null) { throw new KeyNotFoundException(spriteName); } return(entry.Id); }
public void LoadTiles(string name) { XmlSerializer serializer = new XmlSerializer(typeof(TileDatabase)); FileStream stream = new FileStream(Application.dataPath + "/ConfigFiles/" + name, FileMode.Open); tileDB = serializer.Deserialize(stream) as TileDatabase; stream.Close(); for (int i = 0; i < 25; i++) { GameObject go = GameObject.Find("Tile" + tileDB.list[i].TileNumber.ToString()); TileEntry tl = tileDB.list[tileDB.list.FindIndex(item => (item.TileNumber - 1 == i))]; go.transform.eulerAngles = (new Vector3(0, 0, tl.initialRotation)); go.tag = tl.tileType.ToString(); go.gameObject.GetComponent <SpriteRenderer>().sprite = sprites[(int)tl.tileType]; Text texto = go.transform.Find("Canvas").transform.Find("Text").GetComponent <Text>(); if (i == 0) { masterFont = texto; } //texto.text = tl.texto; texto.text = mateDB.list[i].Surname; // Vector3 positionVec = textPos[i]; Vector3 positionVec = textPos[tileDB.list[i].TileNumber - 1]; Cuadrantes[tileDB.list[i].TileNumber - 1] = tl.cuadrante; switch (tl.cuadrante) { case 1: positionVec.y += 0.3f; //positionVec.x += 0.25f; break; case 2: //positionVec.y += 0.25f; positionVec.x -= 0.3f; break; case 3: positionVec.y -= 0.3f; //positionVec.x -= 0.25f; break; case 4: //positionVec.y -= 0.25f; positionVec.x += 0.3f; break; } texto.transform.position = positionVec; texto.color = Color.black; texto.fontSize = 8; texto.font = masterFont.font; //texto.fontStyle = FontStyle.Bold; texto.transform.eulerAngles = new Vector3(0f, 0f, 45f); } tileDB.list.Clear(); }
public void Add(Sprite sprite) { if (sprite == null) throw new ArgumentNullException("sprite"); var entry = new TileEntry { Id = GenerateNewId(), Sprite = sprite }; m_tiles.Add(entry); }
private Tile MakeTileFromEntry(TileEntry entry) { GameObject tile = Instantiate(tilePrefab); tile.transform.SetParent(transform); Tile tileScript = tile.GetComponent <Tile>(); tileScript.AssignTileData(intToTileTypes[entry.tileType]); //tileScript.SetIndex(new Vector2(entry.xPosition, entry.yPosition)); tile.name = "Tile" + tileScript.Index; return(tileScript); }
public TileEntry GetTile(Color color) { if (colorToTileDictionary.ContainsKey(color)) { // retrieve tile and return TileEntry tile = colorToTileDictionary[color]; return(tile); } else { return(new TileEntry()); } }
private void DownloadNextTile() { TileEntry entry = tilesToLoad[0]; tilesToLoad.RemoveAt(0); tilesLoading.Add(entry); #if DEBUG_LOG Debug.Log("DEBUG: TileDownloader.DownloadNextTile: entry.url: " + entry.url); #endif entry.StartDownload(); }
private void InstantiateTiles(int current, Texture2D levelMap, GameObject tilemap) { // for each pixel in map for (int h = 0; h < levelMap.height; h++) { for (int w = 0; w < levelMap.width; w++) { // get pixel value Color color = levelMap.GetPixel(w, h); // get position of spawn // check if in dict if (colorToTileDictionary.ContainsKey(color)) { TileEntry tileEntry = colorToTileDictionary[color]; Vector3 position = getNextTilePosition(w, h, tileEntry.elevation); GameObject tile = null; switch (tileEntry.spawnType) { case SpawnType.Single: // set tile tile = tileEntry.prefabs[tileEntry.prefabs.Length - 1]; break; case SpawnType.Random: // chose random and set tile tile = tileEntry.prefabs[UnityEngine.Random.Range(0, tileEntry.prefabs.Length)]; break; default: tile = null; break; } if (tile == null) { Debug.Log("Tile was null at cell position (" + w + "," + h + ") ->"); Debug.Log(tileEntry); } // place tile in respective position Instantiate(tile, position, Quaternion.identity); } else { if (color != Color.white) { Debug.Log("Doesn't contain color -> " + color + " for current " + current); } } } } }
private void PlaceTiles(Texture2D levelMap, Vector2 startPosition) { // for each pixel in map for (int h = 0; h < levelMap.height; h++) { for (int w = 0; w < levelMap.width; w++) { // get pixel value Color color = levelMap.GetPixel(w, h); // get position of spawn // check if in dict if (colorToTileDictionary.ContainsKey(color)) { TileEntry tileEntry = colorToTileDictionary[color]; var tilemap = levelData.tilemaps[tileEntry.elevation]; if (tileEntry.elevation != 0) { Debug.Log(JsonUtility.ToJson(tileEntry, true)); } Vector3Int position = new Vector3Int(w + (int)startPosition.x, h + (int)startPosition.y, tileEntry.elevation); TileBase tile = null; switch (tileEntry.spawnType) { case SpawnType.Single: tile = tileEntry.tiles[tileEntry.tiles.Length - 1]; break; case SpawnType.Random: tile = tileEntry.tiles[UnityEngine.Random.Range(0, tileEntry.tiles.Length)]; break; default: tile = null; break; } if (tile == null) { Debug.Log("Tile was null at cell position (" + w + "," + h + ") ->"); Debug.Log(tileEntry); } // place tile in respective position tilemap.SetTile(position, tile); } else { Debug.Log("Doesn't contain color -> " + color); } } } }
public void Add(Sprite sprite) { if (sprite == null) { throw new ArgumentNullException("sprite"); } var entry = new TileEntry { Id = GenerateNewId(), Sprite = sprite }; m_tiles.Add(entry); }
public int Add (Sprite sprite) { if (sprite == null) throw new ArgumentNullException ("sprite"); TileEntry entry = new TileEntry { Id = GenerateNewId(), Sprite = sprite }; _tiles.Add (entry); return entry.Id; }
public TileEntry[] FetchMode7Tilemap() { TileEntry[] buf = new TileEntry[128 * 128]; for (int ty = 0, tidx = 0; ty < 128; ty++) { for (int tx = 0; tx < 128; tx++, tidx++) { int tileEntry = vram[tidx * 2]; buf[tidx].address = tidx * 2; buf[tidx].tilenum = (ushort)tileEntry; //palette and flags are ok defaulting to 0 } } return(buf); }
// <summary> // Gets a tile by its URL, the main texture of the material is assigned if successful. // </summary> public void Get(string url, Tile tile) { #if DEBUG_LOG Debug.Log("DEBUG: TileDownloader.Get: url: " + url); #endif tileURLLookedFor = url; if (tilesToLoad.Exists(tileURLMatchPredicate)) { #if DEBUG_LOG Debug.LogWarning("WARNING: TileDownloader.Get: already asked for url: " + url); #endif return; } if (tilesLoading.Exists(tileURLMatchPredicate)) { #if DEBUG_LOG Debug.LogWarning("WARNING: TileDownloader.Get: already downloading url: " + url); #endif return; } #if !UNITY_WEBPLAYER TileEntry cachedEntry = tiles.Find(tileURLMatchPredicate); if (cachedEntry == null) #endif { #if DEBUG_LOG Debug.Log("DEBUG: TileDownloader.Get: adding '" + url + "' to loading list"); #endif tilesToLoad.Add(new TileEntry(url, tile)); } #if !UNITY_WEBPLAYER else { #if DEBUG_LOG Debug.Log("DEBUG: TileDownloader.Get: adding '" + url + "' to loading list (cached)"); #endif cachedEntry.cached = true; cachedEntry.tile = tile; //cachedEntry.Complete = material; tilesToLoad.Add(cachedEntry); } #endif }
public void SetupCosmeticInformation(TileEntry data, DataTreeObject dataTreeParent) { if (dataTreeParent == null) { return; } // This method returns a property, but this is just a stock object (it was created this way in TudeySceneConfigBrancher) List <DataTreeObject> values = dataTreeParent.Properties[dataTreeParent.FindSimpleProperty("Entries")]; DataTreeObject prop = values.First(); DataTreeObject existingTileCtr = prop.FindSimpleProperty("Tiles"); if (existingTileCtr != null) { // Yes, there is a reason you call find twice. The implicit cast from property to object on existingTileCtr creates a new object // as such, casting it back for use in this lookup is a different key. existingTileCtr = prop.Properties[prop.FindSimpleProperty("Tiles")].FirstOrDefault(); } DataTreeObject tilesContainer = existingTileCtr ?? new DataTreeObject() { ImageKey = SilkImage.Tile }; if (existingTileCtr == null) { // We made a new one. Add it. prop.AddSimpleProperty("Tiles", tilesContainer); } DataTreeObject individualTileDataContainer = new DataTreeObject() { Text = data.tile.getName(), // ImageKey = SilkImage.Tile }; Coord location = data.getLocation(); //Transform3D trs = new Transform3D(new Vector3f(location.x, data.elevation, location.y), new Quaternion().fromAngleAxis((float)(data.rotation * Math.PI / 2), Vector3f.UNIT_Y), 1f); individualTileDataContainer.AddSimpleProperty("Elevation", data.elevation); individualTileDataContainer.AddSimpleProperty("Rotation (Deg)", data.rotation * 90); individualTileDataContainer.AddSimpleProperty("Coordinate", $"[{location.x}, {location.y}]", SilkImage.Matrix); individualTileDataContainer.AddSimpleProperty("Tile Reference", data.tile?.getName(), SilkImage.Reference); tilesContainer.AddSimpleProperty("Entry", individualTileDataContainer, SilkImage.Tile); }
// TODO: Test method public virtual void Paint(Vector2Int cellPosition) { TileEntry tileEntry; if (!tileEntriesDict.TryGetValue(cellPosition, out tileEntry) || tileEntry.spriteRenderer == null) { if (tileEntry != null && tileEntry.spriteRenderer == null) { tileEntriesDict.Remove(cellPosition); } tileEntry = new TileEntry(); tileEntry.cellPosition = cellPosition; tileEntry.worldPosition = GridBrush.ActiveTilemap.GetCellCenterWorld(cellPosition.ToVec3Int()); tileEntry.spriteRenderer = Instantiate(currentTileEntryType.spriteRenderer, tileEntry.worldPosition, default(Quaternion), GridBrush.ActiveTilemap.GetComponent <Transform>()); tileEntry.spriteRenderer.color = GridBrush.ActiveTilemap.color; tileEntriesDict.Add(cellPosition, tileEntry); } }
public virtual void SetCurrentTileEntry() { currentTileEntryType = null; for (int i = 0; i < tileEntryTypes.Length; i++) { if (tileEntryTypes[i].isCurrent) { if (currentTileEntryType == null) { currentTileEntryType = tileEntryTypes[i]; } else { tileEntryTypes[i].isCurrent = false; } } } }
/// <summary> /// Gets a tile by its URL, the main texture of the material is assigned if successful. /// </summary> /// <param name="url">URL.</param> /// <param name="tile">Tile.</param> public void Get(int x, int y, int zoom, string url, TileBehaviour tile) { if (tilesToLoad.Exists(t => t.url == url) || tilesLoading.Exists(t => t.url == url)) { return; } TileEntry cachedEntry = tiles.Find(t => t.url == url); if (cachedEntry == null) { tilesToLoad.Add(new TileEntry(x, y, zoom, url, tile)); } else { cachedEntry.tile = tile; tilesToLoad.Add(cachedEntry); } }
protected void Add(TileEntry entry, bool splitting) { // TODO: implement sorting AddCore(entry); if (splitting) { return; } _count++; BoxTile parent = Parent; while (parent != null) { parent.Count++; parent = parent.Parent; } }
public MapData GetEditedMapData() { List <TileEntry> entryList = new List <TileEntry>(); foreach (KeyValuePair <Vector2, Tile> tile in indexToTileDict) { //tile.Value.SetIndex(tile.Value.Index.x - minX, tile.Value.Index.y - minY); TileEntry entry = new TileEntry(); entry.xPosition = tile.Value.Index.x; entry.yPosition = tile.Value.Index.y; entry.tileType = (int)tile.Value.Type; entryList.Add(entry); } MapData md = new MapData(); md.tiles = entryList; return(md); }
internal void ConvertTile(Tile tile, List <TileEntry> entries, out ushort type) { var frame = new TileFrame(tile.frameX, tile.frameY); int frameID = frame.FrameID; if (converted.TryGetValue(frameID, out type)) { return; } TileInfo info = infos[frameID]; var entry = new TileEntry(TileLoader.GetTile(tile.type)) { name = info.name, modName = info.modName, frameImportant = info.frameX > -1, type = type = (ushort)entries.Count }; entries.Add(entry); converted.Add(frameID, type); }
public void Reset() { IBox box = _enum.SearchBox.Clone(); box.Max.X = box.Min.X; var entry = new TileEntry(box, null); _iPos = _elemList.BinarySearch(entry, _comparer); if (_iPos < 0) { _iPos = ~_iPos; } else { if (_excludeEqual) { _iPos++; while (_iPos < _nElems && _comparer.Compare(_elemList[_iPos], entry) == 0) { _iPos++; } } else { _iPos--; while (_iPos >= 0 && _comparer.Compare(_elemList[_iPos], entry) == 0) { _iPos--; } _iPos++; } } }
public AsyncInfo(TileEntry entry, FileStream fs) { this.entry = entry; this.fs = fs; }
private void DeleteCachedTile(TileEntry t) { cacheSize -= t.size; File.Delete(Application.temporaryCachePath + "/" + t.guid + ".png"); tiles.Remove(t); }
/// <summary> /// fetches a tilemap. this is simple; apparently only the screen size (shape) is a factor (not the tile size) /// </summary> public TileEntry[] FetchTilemap(int addr, ScreenSize size) { var blockDims = SizeInBlocksForBGSize(size); int blocksw = blockDims.Width; int blocksh = blockDims.Height; int width = blockDims.Width * 32; int height = blockDims.Height * 32; TileEntry[] buf = new TileEntry[width*height]; for (int by = 0; by < blocksh; by++) { for (int bx = 0; bx < blocksw; bx++) { for (int y = 0; y < 32; y++) { for (int x = 0; x < 32; x++) { int idx = (by * 32 + y) * width + bx * 32 + x; ushort entry = *(ushort*)(vram + addr); buf[idx].tilenum = (ushort)(entry & 0x3FF); buf[idx].palette = (byte)((entry >> 10) & 7); buf[idx].flags = (TileEntryFlags)((entry >> 13) & 7); buf[idx].address = addr; addr += 2; } } } } return buf; }
public TileEntry[] FetchMode7Tilemap() { TileEntry[] buf = new TileEntry[128*128]; for (int ty = 0, tidx = 0; ty < 128; ty++) { for (int tx = 0; tx < 128; tx++, tidx++) { int tileEntry = vram[tidx * 2]; buf[tidx].address = tidx * 2; buf[tidx].tilenum = (ushort)tileEntry; //palette and flags are ok defaulting to 0 } } return buf; }
/// <summary> /// returns a tilemap which might be resized into 8x8 physical tiles if the 16x16 logical tilesize is specified /// </summary> //TileEntry[] AdaptTilemap(TileEntry[] map8x8, int tilesWide, int tilesTall, int tilesize) //{ // if (tilesize == 8) return map8x8; // int numTiles = tilesWide * tilesTall; // var ret = new TileEntry[numTiles * 4]; // for(int y=0;y<tilesTall;y++) // { // for (int x = 0; x < tilesWide; x++) // { // int si = tilesWide * y + x; // int di = tilesHigh // for (int tx = 0; tx < 2; tx++) // { // for (int ty = 0; ty < 2; ty++) // { // } // } // } // } //} /// <summary> /// decodes a BG. youll still need to paletteize and colorize it. /// someone else has to take care of calculating the starting color from the mode and layer number. /// </summary> public void DecodeBG(int* screen, int stride, TileEntry[] map, int tiledataBaseAddr, ScreenSize size, int bpp, int tilesize, int paletteStart) { int ncolors = 1 << bpp; int[] tileBuf = new int[16*16]; var dims = SizeInTilesForBGSize(size); int count8x8 = tilesize / 8; int tileSizeBytes = 8 * bpp; int baseTileNum = tiledataBaseAddr / tileSizeBytes; int[] tileCache = _tileCache[bpp]; int tileCacheMask = tileCache.Length - 1; int screenWidth = dims.Width * count8x8 * 8; for (int mty = 0; mty < dims.Height; mty++) { for (int mtx = 0; mtx < dims.Width; mtx++) { for (int tx = 0; tx < count8x8; tx++) { for (int ty = 0; ty < count8x8; ty++) { int mapIndex = mty * dims.Width + mtx; var te = map[mapIndex]; int tileNum = te.tilenum + tx + ty * 16 + baseTileNum; int srcOfs = tileNum * 64; for (int i = 0, y = 0; y < 8; y++) { for (int x = 0; x < 8; x++, i++) { int px = x; int py = y; if ((te.flags & TileEntryFlags.Horz) != 0) px = 7 - x; if ((te.flags & TileEntryFlags.Vert) != 0) py = 7 - y; int dstX = (mtx * count8x8 + tx) * 8 + px; int dstY = (mty * count8x8 + ty) * 8 + py; int dstOfs = dstY * stride + dstX; int color = tileCache[srcOfs & tileCacheMask]; srcOfs++; if (color == 0 && usingUserBackColor) { } else { color += te.palette * ncolors; color += paletteStart; } screen[dstOfs] = color; } } } } } } }
private void DeleteCachedTile(TileEntry t) { cacheSize -= t.size; File.Delete(tilePath + "/" + t.guid + ".png"); tiles.Remove(t); }
/// <summary> /// returns a tilemap which might be resized into 8x8 physical tiles if the 16x16 logical tilesize is specified /// </summary> //TileEntry[] AdaptTilemap(TileEntry[] map8x8, int tilesWide, int tilesTall, int tilesize) //{ // if (tilesize == 8) return map8x8; // int numTiles = tilesWide * tilesTall; // var ret = new TileEntry[numTiles * 4]; // for(int y=0;y<tilesTall;y++) // { // for (int x = 0; x < tilesWide; x++) // { // int si = tilesWide * y + x; // int di = tilesHigh // for (int tx = 0; tx < 2; tx++) // { // for (int ty = 0; ty < 2; ty++) // { // } // } // } // } //} /// <summary> /// decodes a BG. youll still need to paletteize and colorize it. /// someone else has to take care of calculating the starting color from the mode and layer number. /// </summary> public void DecodeBG(int* screen, int stride, TileEntry[] map, int tiledataBaseAddr, ScreenSize size, int bpp, int tilesize, int paletteStart) { //emergency backstop. this can only happen if we're displaying an unavailable BG or other similar such value if (bpp == 0) return; int ncolors = 1 << bpp; int[] tileBuf = new int[16*16]; var dims = SizeInTilesForBGSize(size); int count8x8 = tilesize / 8; int tileSizeBytes = 8 * bpp; int baseTileNum = tiledataBaseAddr / tileSizeBytes; int[] tileCache = _tileCache[bpp]; int tileCacheMask = tileCache.Length - 1; int screenWidth = dims.Width * count8x8 * 8; for (int mty = 0; mty < dims.Height; mty++) { for (int mtx = 0; mtx < dims.Width; mtx++) { for (int tx = 0; tx < count8x8; tx++) { for (int ty = 0; ty < count8x8; ty++) { int mapIndex = mty * dims.Width + mtx; var te = map[mapIndex]; //apply metatile flipping int tnx = tx, tny = ty; if (tilesize == 16) { if ((te.flags & TileEntryFlags.Horz) != 0) tnx = 1 - tnx; if ((te.flags & TileEntryFlags.Vert) != 0) tny = 1 - tny; } int tileNum = te.tilenum + tnx + tny * 16 + baseTileNum; int srcOfs = tileNum * 64; for (int i = 0, y = 0; y < 8; y++) { for (int x = 0; x < 8; x++, i++) { int px = x; int py = y; if ((te.flags & TileEntryFlags.Horz) != 0) px = 7 - x; if ((te.flags & TileEntryFlags.Vert) != 0) py = 7 - y; int dstX = (mtx * count8x8 + tx) * 8 + px; int dstY = (mty * count8x8 + ty) * 8 + py; int dstOfs = dstY * stride + dstX; int color = tileCache[srcOfs & tileCacheMask]; srcOfs++; if (color == 0 && usingUserBackColor) { } else { color += te.palette * ncolors; color += paletteStart; } screen[dstOfs] = color; } } } } } } }
// <summary> // A method called when the job is done, successfully or not. // </summary> public void JobTerminationEvent(object job, JobEventArgs e) { #if DEBUG_LOG Debug.Log("DEBUG: TileDownloader.JobTerminationEvent: Tile download complete, but was it murdered? " + e.WasKilled); #endif TileEntry entry = e.Owner as TileEntry; tilesLoading.Remove(entry); #if !UNITY_WEBPLAYER if (e.WasKilled == false) { if (entry.error && entry.cached) { if (entry.cached) { #if DEBUG_LOG Debug.Log("DEBUG: TileDownloader.JobTerminationEvent: loading cached tile failed, trying to download it: " + entry.url); #endif // try downloading the tile again entry.cached = false; cacheSize -= entry.size; tiles.Remove(entry); } else { #if DEBUG_LOG Debug.Log("DEBUG: TileDownloader.JobTerminationEvent: downloading tile failed, trying to download it again: " + entry.url); #endif } Get(entry.url, entry.tile); return; } tileURLLookedFor = entry.url; TileEntry existingEntry = tiles.Find(tileURLMatchPredicate); if (existingEntry != null) { tiles.Remove(existingEntry); cacheSize -= existingEntry.size; } entry.timestamp = (DateTime.Now.ToLocalTime() - new DateTime(1970, 1, 1).ToLocalTime()).TotalSeconds; tiles.Add(entry); cacheSize += entry.size; // if the cache is full, erase the oldest entry // FIXME: find a better way to handle the cache (cf. iPhone Maps app) // FIXME: one aspect might be to erase tiles in batch, 10 or 20 at a time, a significant number anyway if (cacheSize > MaxCacheSize) { // beware the year 3000 bug :) double oldestTimestamp = (new DateTime(3000, 1, 1) - new DateTime(1970, 1, 1).ToLocalTime()).TotalSeconds; TileEntry entryToErase = null; foreach (TileEntry tile in tiles) { if (tile.timestamp < oldestTimestamp && tile != entry) { oldestTimestamp = tile.timestamp; entryToErase = tile; } } if (entryToErase == null) { #if DEBUG_LOG Debug.LogWarning("WARNING: TileDownloader.JobTerminationEvent: no cache entry to erase (should not happen)"); #endif return; } DeleteCachedTile(entryToErase); #if DEBUG_LOG Debug.Log("DEBUG: TileDownloader.JobTerminationEvent: erased from cache: " + entryToErase.url + " [" + entryToErase.guid + "]"); #endif } } #endif }
private static bool tileURLMatchPredicate(TileEntry entry) { if (entry.url == tileURLLookedFor) return true; return false; }
public void HandleEntry(FileInfo sourceFile, Entry entry, List <Model3D> modelCollection, DataTreeObject dataTreeParent = null, Transform3D globalTransform = null) { TileEntry tile = (TileEntry)entry; //Transform3D trs = new Transform3D(); //tile.getTransform(tile.getConfig(scene.getConfigManager()), trs); SetupCosmeticInformation(tile, dataTreeParent); // TODO: Some config references have SK data that I need. I need to do a hybrid of my shallow implementation on // top of the bootstrapper that loads the actual filtered game data so that I can grab everything. TileConfig[] tileCfgs = ConfigReferenceBootstrapper.ConfigReferences["tile"].OfType <TileConfig>().ToArray(); TileConfig tileCfg = tileCfgs.GetEntryByName(tile.tile.getName()); if (tileCfg == null) { XanLogger.WriteLine($"Unable to find data for tile [{tile.tile.getName()}]!"); return; } // First things first: Tiles are offset and in the wrong position. Fix it. SKAnimatorToolsProxy.IncrementEnd(); TileConfig.Original originalImpl; do { if (tileCfg == null) { XanLogger.WriteLine("ALERT: A tile was null!", color: System.Drawing.Color.Red); return; } if (tileCfg.getConfigManager() != null) { originalImpl = tileCfg.getOriginal(tileCfg.getConfigManager()); break; } else { if (tileCfg.implementation is TileConfig.Original original) { originalImpl = original; break; } else if (tileCfg.implementation is TileConfig.Derived derived) { tileCfg = tileCfgs.GetEntryByName(derived.tile.getName()); } else { originalImpl = null; break; } } } while (true); //tile.GetExportTransform(originalImpl, out Transform3D transform); // All transforms are relative to the center of the object. the origin of the actual models is in their lower-back-left bounds. // I need to add a flag to tell the exporter to move the geometry based on bounds center. Transform3D transform = new Transform3D(); tile.getTransform(originalImpl, transform); //transform.getTranslation().addLocal(new Vector3f(0, tile.elevation / 2, 0)); string relativeModelPath = originalImpl.model.getName(); XanLogger.WriteLine("Grabbing tile [" + tile.tile.getName() + "] at " + relativeModelPath, XanLogger.DEBUG); ConfigReferenceUtil.HandleConfigReference(sourceFile, originalImpl.model, modelCollection, dataTreeParent, globalTransform.compose(transform)); SKAnimatorToolsProxy.IncrementProgress(); }
public void AddTileTolerance(float tol, string tile) { TileEntry entry = new TileEntry(tile, tol); tileDict.Add(entry); }