Exemplo n.º 1
0
        /// <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;
        }
Exemplo n.º 2
0
            /// <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;
            }