/// <summary> /// LOADER THREAD /// loads the sprites of a given sector to the faceSprites Dictionary /// </summary> /// <param name="sectorID"></param> public static void loadSprites(int sectorID) { int totalStatics = 0; //Just for info int totalStaticsSingle = 0; //Just for info UOReader.FacetSector fs = UOFacetManager.getSector(sectorID); for (int x = 0; x < fs.tiles.Length; ++x) { for (int y = 0; y < fs.tiles[x].Length; ++y) { if (fs.tiles[x][y].staticsCount <= 0) { continue; } for (int i = 0; i < fs.tiles[x][y].statics.Length; ++i) { facetStatic_t st = fs.tiles[x][y].statics[i]; if (!facetSprites.ContainsKey(st.graphic)) { facetSprites.Add(st.graphic, new UOStatic(st.graphic)); totalStaticsSingle++; } totalStatics++; } } } UOConsole.Debug("LOADER: instanced {0} statics, based on {1} uniques.", totalStatics, totalStaticsSingle); return; }
public static void loaderThread() { while (!isClosing) { if (_sectorsQueue.Count == 0) { UOConsole.Debug("LOADER: thread: waiting.."); sem.WaitOne(); //Halt the loader thread UOConsole.Debug("LOADER: thread: resuming.."); } int sector = _sectorsQueue.Dequeue(); UOConsole.Debug("LOADER: Loading {0}", sector); UOResources.UOFacetManager.loadSprites(sector); UOConsole.Debug("LOADER: Finished {0} - {1} left", sector, _sectorsQueue.Count); } }
public static void Enqueue(int sector) { //UOConsole.Debug("sector {0}", sector); if (alreadyKnown[sector]) { return; //TODO: Change after resource managing has been considered } alreadyKnown[sector] = true; if (!_sectorsQueue.Contains(sector)) { _sectorsQueue.Enqueue(sector); UOConsole.Debug("UPDATE: Queuing {0} ..", sector); if (_sectorsQueue.Count == 1) { sem.Release(); } } }
/// <summary> /// MAIN THREAD /// load the already cached sprites into GameObjects. /// This function ignores not-yet loaded sprites. /// </summary> public void loadObjects(Position p) { UOReader.FacetSector fs = UOFacetManager.getSector(sectorID); int worldY = (fs.sectorID % 64) * 64; int worldX = (fs.sectorID / 64) * 64; //Check if the block does not exit yet if (statics[fs.sectorID] == null) { statics[fs.sectorID] = new GameObject(fs.sectorID.ToString() + " statics"); statics[fs.sectorID].transform.parent = theMap.transform; terrains[fs.sectorID] = buildTerrain(fs.sectorID); terrains[fs.sectorID].transform.parent = theMap.transform; } bool needsAnotherRun = false; //Wheter the SectorLoader thread has not finished yet. for (int x = 0; x < fs.tiles.Length; ++x) { for (int y = 0; y < fs.tiles[x].Length; ++y) { if (Mathf.Abs(worldX + x - p.x) > UPDATE_RANGE || Mathf.Abs(worldY + y - p.y) > UPDATE_RANGE) { needsAnotherRun = true; continue; } if (fs.tiles[x][y].staticsCount <= 0) { continue; } if (goArray[x, y] == null) { goArray[x, y] = new GameObject[fs.tiles[x][y].statics.Length]; } for (int i = 0; i < fs.tiles[x][y].statics.Length; ++i) { facetStatic_t st = fs.tiles[x][y].statics[i]; if (facetSprites.ContainsKey(st.graphic)) { if (goArray[x, y][i] == null) { UOStatic si = facetSprites[st.graphic] as UOStatic; if (si == null) { facetSprites.Remove(st.graphic); UOConsole.Fatal("UPDATE: Removing {0} cause it's null", st.graphic); } goArray[x, y][i] = si.getDrawItem(x, y, st.z, worldX, worldY); goArray[x, y][i].transform.parent = statics[fs.sectorID].transform; } //Else we already have the tile loaded! } else { //We need another run needsAnotherRun = true; } } //End statics } //End y } //End x if (!needsAnotherRun) { fullLoaded = true; UOConsole.Debug("UPDATE: Finished loading {0}", sectorID); } return; }
private static void OnTimedEvent(object source, System.Timers.ElapsedEventArgs e) { graphicSector gs = (graphicSector)source; UOConsole.Debug("UPDATE: block {0} is being deallocated.. TODO", gs.sectorID); }
//This function should never return null public virtual GameObject getDrawItem(int x, int y, int z, int worldX, int worldY, int drawLayer) { if (resource == null) { return(new GameObject(tileart.id.ToString())); } float width, height; width = _imageOffset.Xend - _imageOffset.Xstart; height = _imageOffset.Yend; // _imageOffset.Ystart; bool flipped = false; //TEMP - to move at load if (width == 0) { string tow = "", tow2 = ""; for (int i = 0; i < tileart.textures[0].texturesCount; ++i) { tow += tileart.textures[0].texturesArray[i].unk6 + " "; tow2 += tileart.textures[0].texturesArray[i].unk7 + " "; } UOConsole.Debug("id {0}, width {1} height {2} unk6 {3} unk7 {4}", tileart.id, width, height, tow, tow2); width = height = 64; flipped = true; } drawSprite = Sprite.Create(resource.getTexture(), new Rect(_imageOffset.Xstart, resource.getTexture().height - _imageOffset.Yend, width, height), new Vector2(0, 0) ); float squareRoot = Mathf.Sqrt(2.0f); float realz = z * 6 / (UOEC_SIZE); x += worldX; y += worldY; float realx = (-y * 0.5f + x * 0.5f) - 0.5f + _drawOffsetX; float realy = (-y * 0.5f - x * 0.5f) - (flipped ? 0.5f : 1f) - _drawOffsetY + realz; GameObject toret = new GameObject(tileart.id.ToString()); //Create a visible object realx /= 1.6525f; //Moving from 100pixel based grid to 64pixel based realy /= 1.6525f; toret.transform.Translate(realx, realy, 0); if (flipped) { toret.transform.Rotate(0, 0, -45.0f); toret.transform.localScale /= squareRoot; } SpriteRenderer r = (SpriteRenderer)toret.AddComponent(typeof(SpriteRenderer)); r.sprite = drawSprite; r.sortingOrder = x + y + z /*- worldY - worldX*/ + drawLayer; return(toret); }