Exemplo n.º 1
0
        protected void SaveMaps(SaveMetrics metrics)
        {
            Dictionary <Serial, BaseInstanceMap> maps = World.Maps;

            GenericWriter idx;
            GenericWriter tdb;
            GenericWriter bin;

            if (UseSequentialWriters)
            {
                idx = new BinaryFileWriter(World.MapIndexPath, false);
                tdb = new BinaryFileWriter(World.MapTypesPath, false);
                bin = new BinaryFileWriter(World.MapDataPath, true);
            }
            else
            {
                idx = new AsyncWriter(World.MapIndexPath, false);
                tdb = new AsyncWriter(World.MapTypesPath, false);
                bin = new AsyncWriter(World.MapDataPath, true);
            }

            idx.Write(( int )maps.Count);

            foreach (BaseInstanceMap map in maps.Values)
            {
                if (map.Decays)
                {
                    _decayMapQueue.Enqueue(map);
                }

                long start = bin.Position;

                idx.Write(( int )map.TypeReference);
                idx.Write(( int )map.Serial);
                idx.Write(( long )start);

                map.Serialize(bin);

                if (metrics != null)
                {
                    metrics.OnMapSaved(( int )(bin.Position - start));
                }

                idx.Write(( int )(bin.Position - start));
            }

            tdb.Write(( int )World.m_InstanceMapTypes.Count);
            for (int i = 0; i < World.m_InstanceMapTypes.Count; ++i)
            {
                tdb.Write(World.m_InstanceMapTypes[i].FullName);
            }

            idx.Close();
            tdb.Close();
            bin.Close();
        }
Exemplo n.º 2
0
        private Task SaveMaps()
        {
            //Start the blocking consumer; this runs in background.
            Task commitTask = StartCommitTask(_mapThreadWriters, _mapData, _mapIndex);

            IEnumerable <BaseInstanceMap> maps = World.Maps.Values;

            //Start the producer.
            Parallel.ForEach(maps, () => new QueuedMemoryWriter(),
                             (BaseInstanceMap map, ParallelLoopState state, QueuedMemoryWriter writer) =>
            {
                long startPosition = writer.Position;

                map.Serialize(writer);

                int size = (int)(writer.Position - startPosition);

                writer.QueueForIndex(map, size);

                if (map.Decays)
                {
                    _decayMapBag.Add(map);
                }

                if (_metrics != null)
                {
                    _metrics.OnMapSaved(size);
                }

                return(writer);
            },
                             (writer) =>
            {
                writer.Flush();

                _mapThreadWriters.Add(writer);
            });

            _mapThreadWriters.CompleteAdding();                 //We only get here after the Parallel.ForEach completes.  Lets our task

            return(commitTask);
        }
		protected void SaveMaps( SaveMetrics metrics )
		{
			Dictionary<Serial, BaseInstanceMap> maps = World.Maps;

			GenericWriter idx;
			GenericWriter tdb;
			GenericWriter bin;

			if (UseSequentialWriters)
			{
				idx = new BinaryFileWriter( World.MapIndexPath, false );
				tdb = new BinaryFileWriter( World.MapTypesPath, false );
				bin = new BinaryFileWriter( World.MapDataPath, true );
			}
			else
			{
				idx = new AsyncWriter( World.MapIndexPath, false );
				tdb = new AsyncWriter( World.MapTypesPath, false );
				bin = new AsyncWriter( World.MapDataPath, true );
			}

			idx.Write( ( int ) maps.Count );

			foreach ( BaseInstanceMap map in maps.Values )
			{
				if ( map.Decays )
					_decayMapQueue.Enqueue( map );

				long start = bin.Position;

				idx.Write( ( int ) map.TypeReference );
				idx.Write( ( int ) map.Serial );
				idx.Write( ( long ) start );

				map.Serialize( bin );

				if ( metrics != null )
					metrics.OnMapSaved( ( int ) ( bin.Position - start ) );

				idx.Write( ( int ) ( bin.Position - start ) );
			}

			tdb.Write( ( int ) World.m_InstanceMapTypes.Count );
			for ( int i = 0; i < World.m_InstanceMapTypes.Count; ++i )
				tdb.Write( World.m_InstanceMapTypes[i].FullName );

			idx.Close();
			tdb.Close();
			bin.Close();
		}