OnMobileSaved() public method

public OnMobileSaved ( int numberOfBytes ) : void
numberOfBytes int
return void
Esempio n. 1
0
        protected void SaveMobiles(SaveMetrics metrics)
        {
            Dictionary <Serial, Mobile> mobiles = World.Mobiles;

            GenericWriter idx;
            GenericWriter tdb;
            GenericWriter bin;

            if (UseSequentialWriters)
            {
                idx = new BinaryFileWriter(World.MobileIndexPath, false);
                tdb = new BinaryFileWriter(World.MobileTypesPath, false);
                bin = new BinaryFileWriter(World.MobileDataPath, true);
            }
            else
            {
                idx = new AsyncWriter(World.MobileIndexPath, false);
                tdb = new AsyncWriter(World.MobileTypesPath, false);
                bin = new AsyncWriter(World.MobileDataPath, true);
            }

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

            foreach (Mobile m in mobiles.Values)
            {
                long start = bin.Position;

                idx.Write(( int )m.m_TypeRef);
                idx.Write(( int )m.Serial);
                idx.Write(( long )start);

                m.Serialize(bin);

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

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

                m.FreeCache();
            }

            tdb.Write(( int )World.m_MobileTypes.Count);

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

            idx.Close();
            tdb.Close();
            bin.Close();
        }
Esempio n. 2
0
		protected void SaveMobiles( SaveMetrics metrics ) {
			Dictionary<Serial, Mobile> mobiles = World.Mobiles;

			GenericWriter idx;
			GenericWriter tdb;
			GenericWriter bin;

			if ( World.SaveType == World.SaveOption.Normal ) {
				idx = new BinaryFileWriter( World.MobileIndexPath, false );
				tdb = new BinaryFileWriter( World.MobileTypesPath, false );
				bin = new BinaryFileWriter( World.MobileDataPath, true );
			} else {
				idx = new AsyncWriter( World.MobileIndexPath, false );
				tdb = new AsyncWriter( World.MobileTypesPath, false );
				bin = new AsyncWriter( World.MobileDataPath, true );
			}

			idx.Write( ( int ) mobiles.Count );
			foreach ( Mobile m in mobiles.Values ) {
				long start = bin.Position;

				idx.Write( ( int ) m.m_TypeRef );
				idx.Write( ( int ) m.Serial );
				idx.Write( ( long ) start );

				m.Serialize( bin );

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

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

				m.FreeCache();
			}

			tdb.Write( ( int ) World.m_MobileTypes.Count );

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

			idx.Close();
			tdb.Close();
			bin.Close();
		}
Esempio n. 3
0
        private Task SaveMobiles()
        {
            //Start the blocking consumer; this runs in background.
            Task commitTask = StartCommitTask(_mobileThreadWriters, _mobileData, _mobileIndex);

            IEnumerable <Mobile> mobiles = World.Mobiles.Values;

            //Start the producer.
            Parallel.ForEach(
                mobiles,
                () => new QueuedMemoryWriter(),
                (mobile, state, writer) =>
            {
                long startPosition = writer.Position;

                mobile.Serialize(writer);

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

                writer.QueueForIndex(mobile, size);

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

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

                _mobileThreadWriters.Add(writer);
            });

            _mobileThreadWriters.CompleteAdding();
            //We only get here after the Parallel.ForEach completes.  Lets our task tell the consumer that we're done

            return(commitTask);
        }
Esempio n. 4
0
		protected void SaveMobiles(SaveMetrics metrics)
		{
			Dictionary<Serial, Mobile> mobiles = World.Mobiles;

			GenericWriter idx;
			GenericWriter tdb;
			GenericWriter bin;

			if (UseSequentialWriters)
			{
				idx = new BinaryFileWriter(World.MobileIndexPath, false);
				tdb = new BinaryFileWriter(World.MobileTypesPath, false);
				bin = new BinaryFileWriter(World.MobileDataPath, true);
			}
			else
			{
				idx = new AsyncWriter(World.MobileIndexPath, false);
				tdb = new AsyncWriter(World.MobileTypesPath, false);
				bin = new AsyncWriter(World.MobileDataPath, true);
			}

			idx.Write(mobiles.Count);

			foreach (Mobile m in mobiles.Values)
			{
				long start = bin.Position;

				idx.Write(m._TypeRef);
				idx.Write(m.Serial);
				idx.Write(start);

				m.Serialize(bin);

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

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

				m.FreeCache();
			}

			tdb.Write(World.m_MobileTypes.Count);

			foreach (Type t in World.m_MobileTypes)
			{
				tdb.Write(t.FullName);
			}

			idx.Close();
			tdb.Close();
			bin.Close();
		}
Esempio n. 5
0
        protected void SaveCores(SaveMetrics metrics)
        {
            Dictionary<CustomSerial, BaseCore> cores = World.Cores;

            GenericWriter indexWriter;
            GenericWriter typeWriter;
            GenericWriter dataWriter;

            if (this.UseSequentialWriters)
            {
                indexWriter = new BinaryFileWriter(World.CoreIndexPath, false);
                typeWriter = new BinaryFileWriter(World.CoreTypesPath, false);
                dataWriter = new BinaryFileWriter(World.CoresDataPath, true);
            }
            else
            {
                indexWriter = new AsyncWriter(World.CoreIndexPath, false);
                typeWriter = new AsyncWriter(World.CoreTypesPath, false);
                dataWriter = new AsyncWriter(World.CoresDataPath, true);
            }

            indexWriter.Write(cores.Count);

            foreach (BaseCore core in cores.Values)
            {
                long start = dataWriter.Position;

                indexWriter.Write(core._TypeID);
                indexWriter.Write((int)core.Serial);
                indexWriter.Write(start);

                core.Serialize(dataWriter);

                if (metrics != null)
                    metrics.OnMobileSaved((int)(dataWriter.Position - start));

                indexWriter.Write((int)(dataWriter.Position - start));
            }

            typeWriter.Write(World._CoreTypes.Count);

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

            indexWriter.Close();
            typeWriter.Close();
            dataWriter.Close();
        }