本文整理汇总了C#中BitStream.Write方法的典型用法代码示例。如果您正苦于以下问题:C# BitStream.Write方法的具体用法?C# BitStream.Write怎么用?C# BitStream.Write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BitStream
的用法示例。
在下文中一共展示了BitStream.Write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RequestWorld
private void RequestWorld(Packet packet)
{
ulong steamID = m_GUIDToSteamID[packet.GUID.G];
BitStream bs = new BitStream(null);
bs.Write((byte)MessageIDEnum.WORLD_DATA);
var handler = OnRequestWorld;
if (handler != null)
handler(steamID, bs);
SendMessage(bs, packet.GUID, PacketPriorityEnum.IMMEDIATE_PRIORITY, PacketReliabilityEnum.RELIABLE_ORDERED);
}
示例2: StateDataRequest
private void StateDataRequest(Packet packet)
{
ulong steamID = m_GUIDToSteamID[packet.GUID.G];
BitStream bs = new BitStream(null);
bs.Write((byte)MessageIDEnum.STATE_DATA);
MyRakNetSyncLayer.Static.SerializeStateData(steamID, bs);
var handler = OnRequestWorld;
if (handler != null)
handler(steamID, bs);
SendMessage(bs, packet.GUID, PacketPriorityEnum.IMMEDIATE_PRIORITY, PacketReliabilityEnum.RELIABLE_ORDERED);
}
示例3: GetString
public static string GetString(byte[] data)
{
int letters = data.Length * 8 / 5;
string base32_string = "";
BitStream b = new BitStream();
b.Write(data, 0, data.Length);
b.Seek(0, System.IO.SeekOrigin.Begin);
if (b.Length == 0) return("");
long output_length = b.Length;
Console.WriteLine("bits in bitstream:" + b.Length);
if (b.Length % 5 != 0)
{
Console.WriteLine("rest bits:" + (b.Length % 5));
output_length += (5 - (b.Length % 5));
}
Console.WriteLine("bits in output buffer(+padding):" + output_length);
byte[] output = new byte[output_length];
output.Initialize();
//output.Length
int ret = b.Read(output, 0, (int)b.Length);//will crash with buffers over 4gb ,or something else
//now we have an array of bits in output that will be converted to base32
//5 bit to 1 byte + zero padding conversion
//pad to correct length with zeros
long pos = 0;
while (pos < output.Length)
{
int value = 0;
/*
value += output[pos + 0] * 1;
value += output[pos + 1] * 2;
value += output[pos + 2] * 4;
value += output[pos + 3] * 8;
value += output[pos + 4] * 16;
*/
value += output[pos + 0] * 16;
value += output[pos + 1] * 8;
value += output[pos + 2] * 4;
value += output[pos + 3] * 2;
value += output[pos + 4] * 1;
base32_string += conversion_array[value];
pos += 5;
}
Console.WriteLine("pos:"+pos);
return (base32_string);
}
示例4: Serialize
public void Serialize(BitStream bs)
{
bs.Write(m_dirty);
if (m_dirty)
{
foreach (var mySyncedObject in m_syncedClass)
{
mySyncedObject.Serialize(bs);
}
foreach (var mySynced in m_syncedVariables)
{
mySynced.Serialize(bs);
}
m_dirty = false;
}
}
示例5: Serialize
public ReplicaReturnResult Serialize(ref bool sendTimestamp, BitStream outBitStream, uint lastSendTime, ref PacketPriority priority, ref PacketReliability reliability, uint currentTime, SystemAddress systemAddress, SWIGTYPE_p_unsigned_int flags)
{
if (lastSendTime == 0)
Console.Write("First call to Player::Serialize for {0}:{1}\n", systemAddress.binaryAddress, systemAddress.port);
outBitStream.Write(position);
outBitStream.Write(health);
return ReplicaReturnResult.REPLICA_PROCESSING_DONE;
}
示例6: SendClientConnected
private void SendClientConnected(ulong steamID, RakNetGUID exclude)
{
BitStream bs = new BitStream(null);
bs.Write((byte)MessageIDEnum.REMOTE_CLIENT_CONNECTED);
bs.Write((long)steamID);
BroadcastMessage(bs, PacketPriorityEnum.HIGH_PRIORITY, PacketReliabilityEnum.RELIABLE_ORDERED, 0, exclude);
}
示例7: Main
static void Main(string[] args)
{
RakPeerInterface rakClient = RakNetworkFactory.GetRakPeerInterface();
RakPeerInterface rakServer = RakNetworkFactory.GetRakPeerInterface();
quit = false;
string text;
rakClient.RegisterAsRemoteProcedureCall(typeof(Program).GetMethod("clientRPC"));
SocketDescriptor socketDescriptor = new SocketDescriptor(2000, string.Empty);
if (!rakServer.Startup(1, 30, new SocketDescriptor[] { socketDescriptor }, 1))
{
Console.Write("Start call failed!\n");
return;
}
rakServer.SetMaximumIncomingConnections(1);
socketDescriptor.port = 2100;
rakClient.Startup(1, 30, new SocketDescriptor[] { socketDescriptor }, 1);
if (!rakClient.Connect("127.0.0.1", 2000, string.Empty, 0))
{
Console.Write("Connect call failed\n");
return;
}
BitStream outgoingBitstream = new BitStream();
uint age;
Console.Write("A sample on how to use RakNet's bitstream class\n");
Console.Write("Difficulty: Beginner\n\n");
Console.Write("Enter your name.\n");
text = Console.ReadLine();
if (text.Equals(string.Empty))
text = "Unnamed!";
outgoingBitstream.Write(text);
Console.Write("Enter your age (numbers only).\n");
text = Console.ReadLine();
if (text.Equals(string.Empty))
age = 0;
else
age = uint.Parse(text);
outgoingBitstream.WriteCompressed(age);
Console.Write("Are you employed (y/n)?\n");
text = Console.ReadLine();
if (text == "y")
{
outgoingBitstream.Write(true);
// Read some data into a struct
EmploymentStruct employmentStruct;
Console.Write("What is your salary (enter a number only)?\n");
text = Console.ReadLine();
employmentStruct.salary = int.Parse(text);
Console.Write("How many years have you been employed (enter a number only)?\n");
text = Console.ReadLine();
employmentStruct.yearsEmployed = byte.Parse(text);
// We can write structs to a bitstream but this is not portable due to:
// 1. Different-endian CPUs
// 2. Different 'padding' of structs depending on compiler, etc
// The only safe way to send a struct is by using the BitStream
// to write out every single member which you want to send.
outgoingBitstream.Write(employmentStruct.salary);
outgoingBitstream.Write(employmentStruct.yearsEmployed);
// We're done writing to the struct
}
else
{
//Console.Write("Number of bits before [false]: %d\n",
//outgoingBitstream.GetNumberOfBitsUsed() );
outgoingBitstream.Write(false); // Writing a bool takes 1 bit
// We're done writing to the struct. Compare this to the example above - we wrote quite a bit less.
}
bool success = rakServer.RPC(typeof(Program).GetMethod("clientRPC"), outgoingBitstream, PacketPriority.HIGH_PRIORITY, PacketReliability.RELIABLE, 0, RakNetBindings.UNASSIGNED_SYSTEM_ADDRESS, true, 0, RakNetBindings.UNASSIGNED_NETWORK_ID, null);
if (!success)
Console.Write("RPC call failed\n");
while (!quit)
{
rakClient.DeallocatePacket(rakClient.Receive());
rakServer.DeallocatePacket(rakServer.Receive());
System.Threading.Thread.Sleep(30);
}
Console.Write("Press enter to quit\n");
Console.ReadLine();
rakClient.Shutdown(100, 0);
rakServer.Shutdown(100, 0);
// This is not necessary since on shutdown everything is unregistered. This is just here to show usage
rakClient.UnregisterAsRemoteProcedureCall(typeof(Program).GetMethod("clientRPC"));
RakNetworkFactory.DestroyRakPeerInterface(rakClient);
//.........这里部分代码省略.........
示例8: SendScopeChange
public ReplicaReturnResult SendScopeChange(bool inScope, BitStream outBitStream, uint currentTime, SystemAddress systemAddress, ref bool includeTimestamp)
{
if (inScope)
Console.Write("Sending scope change to true in Player\n");
else
Console.Write("Sending scope change to false in Player\n");
outBitStream.Write(inScope);
return ReplicaReturnResult.REPLICA_PROCESSING_DONE;
}
示例9: SendClientReady
private void SendClientReady()
{
BitStream bs = new BitStream(null);
bs.Write((byte)MessageIDEnum.CLIENT_READY);
SendMessageToServer(bs, PacketPriorityEnum.IMMEDIATE_PRIORITY, PacketReliabilityEnum.RELIABLE);
}
示例10: SendClientData
private void SendClientData(Packet packet)
{
BitStream bs = new BitStream(null);
bs.Write((byte)MessageIDEnum.CLIENT_DATA);
bs.Write((long)MySteamID);
bs.Write((int)Version);
SendMessageToServer(bs, PacketPriorityEnum.IMMEDIATE_PRIORITY, PacketReliabilityEnum.RELIABLE);
}
示例11: SerializeStateData
//TODO:SK: Split the message to allow clint to load the
internal void SerializeStateData(ulong steamID, BitStream bs)
{
bs.Write(m_stateData.Count);
foreach (var syncedObject in m_stateData.Values)
{
bs.WriteCompressed(syncedObject.TypeID);
bs.Write((long)syncedObject.EntityId);
syncedObject.SerializeDefault(bs);
}
}
示例12: SendChatMessageInternal
private void SendChatMessageInternal(ulong steamID, string message, RakNetGUID? exclude = null)
{
BitStream bs = new BitStream(null);
bs.Write((byte)MessageIDEnum.CHAT_MESSAGE);
bs.Write((long)steamID);
bs.WriteCompressed(message);
BroadcastMessage(bs, PacketPriorityEnum.IMMEDIATE_PRIORITY, PacketReliabilityEnum.RELIABLE_ORDERED, 0, exclude);
}
示例13: Destroy
public static void Destroy(ulong entityID)
{
Debug.Assert(Static != null);
Debug.Assert(Static.m_peer is MyRakNetServer);
Debug.Assert(Static.m_stateData.ContainsKey(entityID));
BitStream bs = new BitStream(null);
bs.Write((byte)MessageIDEnum.REPLICATION_DESTROY);
bs.Write((long)entityID);
Static.m_stateData.Remove(entityID);
((MyRakNetServer)Static.m_peer).BroadcastMessage(bs, PacketPriorityEnum.LOW_PRIORITY, PacketReliabilityEnum.RELIABLE, 0, RakNetGUID.UNASSIGNED_RAKNET_GUID);
}
示例14: Replicate
public static void Replicate(object obj, ulong entityID)
{
Debug.Assert(Static != null);
Debug.Assert(Static.m_peer is MyRakNetServer);
Debug.Assert(!Static.m_stateData.ContainsKey(entityID));
Debug.Assert(Static.m_idToType.Contains(obj.GetType()));
int typeID = Static.m_typeToId[obj.GetType()];
BitStream bs = new BitStream(null);
bs.Write((byte)MessageIDEnum.REPLICATION_CREATE);
bs.WriteCompressed(typeID); // TODO:SK better compression
bs.Write((long)entityID);
MySyncedClass syncedClass = GetSyncedClass(obj);
syncedClass.TypeID = typeID;
syncedClass.EntityId = entityID;
syncedClass.Serialize(bs);
RegisterSynced(syncedClass);
((MyRakNetServer)Static.m_peer).BroadcastMessage(bs, PacketPriorityEnum.LOW_PRIORITY, PacketReliabilityEnum.RELIABLE, 0, RakNetGUID.UNASSIGNED_RAKNET_GUID);
}
示例15: Sync
internal static void Sync(MySyncedClass mySyncedClass)
{
Debug.Assert(mySyncedClass.EntityId != 0);
Debug.Assert(Static != null);
Debug.Assert(Static.m_peer is MyRakNetServer);
BitStream bs = new BitStream(null);
bs.Write((byte)MessageIDEnum.SYNC_FIELD);
bs.Write((long)mySyncedClass.EntityId);
mySyncedClass.Serialize(bs);
// TODO:SK use UNRELIABLE_WITH_ACK_RECEIPT
((MyRakNetServer)Static.m_peer).BroadcastMessage(bs, PacketPriorityEnum.LOW_PRIORITY, PacketReliabilityEnum.UNRELIABLE, 0, RakNetGUID.UNASSIGNED_RAKNET_GUID);
}