예제 #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;
        }
예제 #2
0
        /// <summary>
        /// MAIN THREAD
        /// This function loads a sector and puts the resulting terrain mesh into a GameObject
        /// </summary>
        /// <param name="sectorID"></param>
        /// <returns></returns>
        public static GameObject buildTerrain(int sectorID)
        {
            GameObject   terrain = new GameObject("terrain" + sectorID);
            MeshFilter   mf      = (MeshFilter)terrain.AddComponent(typeof(MeshFilter));
            MeshRenderer mr      = (MeshRenderer)terrain.AddComponent(typeof(MeshRenderer));

            //MeshCollider mc = (MeshCollider)terrain.AddComponent(typeof(MeshCollider));

            //Load a facet sector
            UOReader.FacetSector sec = UOFacetManager.getSector(sectorID);

            //Set the data to a mesh
            Mesh mesh = new Mesh();

            UOFacetManager.facetSectorMesh m = UOFacetManager.buildTerrainMesh(sec);
            //Copy values from the specific class.... i tried using directly a mesh but didn't worked..
            mesh.vertices  = m.vertices;
            mesh.triangles = m.triangles;
            mesh.normals   = m.normals;
            mesh.uv        = m.uvs;
            int i = 0;

            mesh.subMeshCount = m.subMeshes.Values.Count;
            UOConsole.Fatal("terrain: {0} subMeshes", mesh.subMeshCount);
            foreach (uint k in m.subMeshes.Keys)
            {
                //UOConsole.Fatal(string.Format("idx {0} texture {1} count: {2}", i, k, m.subMeshes[k].Count));
                mesh.SetTriangles(m.subMeshes[k].ToArray(), i++);
            }

            mf.mesh      = mesh;
            mr.materials = m.materials.ToArray();

            float sq = Mathf.Sqrt(2.0f);

            terrain.transform.Rotate(0, 0, -45.0f);
            terrain.transform.localScale *= 1 / sq;
            terrain.transform.localScale /= 1.6525f;            //Moving from 100pixel based to 64pixel based
            return(terrain);
        }
예제 #3
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;
            }