本文整理汇总了C#中System.Buffer.Write方法的典型用法代码示例。如果您正苦于以下问题:C# Buffer.Write方法的具体用法?C# Buffer.Write怎么用?C# Buffer.Write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Buffer
的用法示例。
在下文中一共展示了Buffer.Write方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Save
// #############################################################################################
/// Function:<summary>
///
/// </summary>
///
/// In: <param name="_filename"></param>
///
// #############################################################################################
public void Save(string _filename)
{
Buffer buff = new Buffer(1024 * 1024 * 8);
unchecked
{
buff.Write((UInt32)4); // Map Version
buff.Write((UInt32)0); // spare space.
buff.Write((UInt32)0);
buff.Write((UInt32)0);
buff.Write((UInt32)0);
buff.Write((UInt32)0);
buff.Write((UInt32)0);
buff.Write((UInt32)0);
buff.Write((UInt32)0);
buff.Write((UInt16)Width);
buff.Write((UInt16)Height);
buff.Write((UInt16)Depth);
buff.Write((UInt16)0);
buff.Write((UInt16)LidBase);
buff.Write((UInt16)TileWidth);
buff.Write((UInt16)70);
buff.Write((UInt16)Pavement);
buff.Write((UInt16)16);
// in RAW mode, just copy the buffer
buff.Write((Byte)0); // set no compression
int sprite_count = 0;
for (int y = 0; y < Height; y++)
{
for (int x = 0; x < Width; x++)
{
// Write out block column
List<int> column = map[x + (y * Width)].column;
List<Sprite> sprites = map[x + (y * Width)].sprites;
int flags = 0;
if (sprites.Count != 0) flags |= 0x8000;
// Top bit set IF there are sprites in this column
buff.Write((UInt16)(column.Count | flags));
foreach (int i in column)
{
buff.Write(((UInt16)(i & 0xffff)));
buff.Write( ((Byte) ((i>>16)&0xff)) );
}
if (sprites.Count != 0)
{
// If we have sprites here, save them out...
buff.Write((UInt16)sprites.Count);
foreach (Sprite s in sprites)
{
buff.Write((UInt16) ((int)s.SpriteType & 0xffff) );
UInt32 pos = (UInt32)((s.x & 0xff) | ((s.y & 0xff) << 8) | ((s.z & 0xffff) << 16));
buff.Write((UInt32)pos);
buff.Write((UInt32)0);
sprite_count++;
}
}
}
}
Console.WriteLine("Sprites = " + sprite_count.ToString());
Console.WriteLine("BlockInfos = " + BlockInfo.Count.ToString());
// Write out number of block info structs we have
buff.Write((UInt32)BlockInfo.Count);
foreach (block_info info in BlockInfo)
{
for (int i = 0; i < 6; i++)
{
buff.Write((UInt16)info[i]);
}
// Do we need to save extended block info?
UInt32 f = 0;
if (info.Flags2 != 0 || info.Offsets1 != 0 || info.Offsets2 != 0 || info.Offsets3 != 0)
{
f = 0x80000000;
}
// Clear off the temp bit, and or in the extended flag
buff.Write(((UInt32)info.Flags1&0x7fffffff)|f);
if (f != 0)
{
buff.Write((UInt32)info.Flags2);
buff.Write((UInt32)info.Offsets1);
buff.Write((UInt32)info.Offsets2);
buff.Write((UInt32)info.Offsets3);
}
}
}
buff.Save(_filename);
}