Example #1
0
        /// <summary>
        /// MAIN THREAD - Called each frame
        /// Given a position updates the current block and the surrounding ones
        /// - Get sectors IDs
        /// - Enqueue loading to LOADER
        /// - Updates visible blocks
        /// </summary>
        /// <param name="p"></param>
        public static void updateMap(Position p)
        {
            int currentSector = getSectorID(p.x, p.y);

            SectorsLoader.Enqueue(currentSector);

            /*	West	North
             *		  x
             *	South	East
             */

            int west  = getSectorID(p.x - UPDATE_RANGE, p.y - UPDATE_RANGE);
            int north = getSectorID(p.x + UPDATE_RANGE, p.y - UPDATE_RANGE);
            int east  = getSectorID(p.x + UPDATE_RANGE, p.y + UPDATE_RANGE);
            int south = getSectorID(p.x - UPDATE_RANGE, p.y + UPDATE_RANGE);

            //Updates sectors to load
            visibleMapIDX[0] = currentSector;
            if (currentSector != west)
            {
                SectorsLoader.Enqueue(west);
                visibleMapIDX[1] = west;
            }
            else
            {
                visibleMapIDX[1] = -1;                //Removes the block from the "toDraw" list
            }
            if (currentSector != north)
            {
                SectorsLoader.Enqueue(north);
                visibleMapIDX[2] = north;
            }
            else
            {
                visibleMapIDX[2] = -1;
            }
            if (currentSector != east)
            {
                SectorsLoader.Enqueue(east);
                visibleMapIDX[3] = east;
            }
            else
            {
                visibleMapIDX[3] = -1;
            }
            if (currentSector != south)
            {
                SectorsLoader.Enqueue(south);
                visibleMapIDX[4] = south;
            }
            else
            {
                visibleMapIDX[4] = -1;
            }

            /*graphicSector g = graphicSectors[currentSector];
             * if (g == null) {
             *      g = new graphicSector(currentSector);
             *      graphicSectors[currentSector] = g;
             * }
             * if (!g.fullLoaded) {
             *      g.loadObjects();
             * }*/


            //Updates all the blocks currently used - (to be drawn)
            for (int i = 0; i < 5; ++i)
            {
                if (visibleMapIDX[i] != -1)
                {
                    visibleMap[i] = graphicSectors[visibleMapIDX[i]];
                    if (visibleMap[i] == null)
                    {
                        visibleMap[i] = new graphicSector(visibleMapIDX[i]);
                        graphicSectors[visibleMapIDX[i]] = visibleMap[i];
                    }
                    if (!visibleMap[i].fullLoaded)
                    {
                        visibleMap[i].loadObjects(p);
                    }
                }
            }
            return;
        }
Example #2
0
            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);
            }
Example #3
0
		/// <summary>
		/// MAIN THREAD - Called each frame
		/// Given a position updates the current block and the surrounding ones
		/// - Get sectors IDs
		/// - Enqueue loading to LOADER
		/// - Updates visible blocks
		/// </summary>
		/// <param name="p"></param>
		public static void updateMap(Position p) {

			int currentSector = getSectorID(p.x, p.y);
			SectorsLoader.Enqueue(currentSector);

			/*	West	North
			 *		  x
			 *	South	East
			 */
			
			int west = getSectorID(p.x - UPDATE_RANGE, p.y - UPDATE_RANGE);
			int north = getSectorID(p.x + UPDATE_RANGE, p.y - UPDATE_RANGE);
			int east = getSectorID(p.x + UPDATE_RANGE, p.y + UPDATE_RANGE);
			int south = getSectorID(p.x - UPDATE_RANGE, p.y + UPDATE_RANGE);

			//Updates sectors to load
			visibleMapIDX[0] = currentSector;
			if (currentSector != west) {
				SectorsLoader.Enqueue(west);
				visibleMapIDX[1] = west;
			} else 
				visibleMapIDX[1] = -1;//Removes the block from the "toDraw" list
			if (currentSector != north) {
				SectorsLoader.Enqueue(north);
				visibleMapIDX[2] = north;
			} else
				visibleMapIDX[2] = -1;
			if (currentSector != east) {
				SectorsLoader.Enqueue(east);
				visibleMapIDX[3] = east;
			} else
				visibleMapIDX[3] = -1;
			if (currentSector != south) {
				SectorsLoader.Enqueue(south);
				visibleMapIDX[4] = south;
			} else
				visibleMapIDX[4] = -1;

			/*graphicSector g = graphicSectors[currentSector];
			if (g == null) {
				g = new graphicSector(currentSector);
				graphicSectors[currentSector] = g;
			}
			if (!g.fullLoaded) {
				g.loadObjects();
			}*/


			//Updates all the blocks currently used - (to be drawn)
			for (int i = 0; i < 5; ++i) {
				if (visibleMapIDX[i] != -1) {
					visibleMap[i] = graphicSectors[visibleMapIDX[i]];
					if (visibleMap[i] == null) {
						visibleMap[i] = new graphicSector(visibleMapIDX[i]);
						graphicSectors[visibleMapIDX[i]] = visibleMap[i];
					}
					if (!visibleMap[i].fullLoaded) {
						visibleMap[i].loadObjects(p);
					}
				}
			}
			return;
		}