Merge branch 'tr-bitbuf'

This commit is contained in:
David Anderson 2014-11-15 12:49:39 -08:00
commit 5e362ec169
7 changed files with 290 additions and 63 deletions

View File

@ -717,6 +717,39 @@ REGISTER_NATIVES(bitbufnatives)
{"BfReadVecNormal", smn_BfReadVecNormal},
{"BfReadAngles", smn_BfReadAngles},
{"BfGetNumBytesLeft", smn_BfGetNumBytesLeft},
// Transitional syntax support.
{"BfWrite.WriteBool", smn_BfWriteBool},
{"BfWrite.WriteByte", smn_BfWriteByte},
{"BfWrite.WriteChar", smn_BfWriteChar},
{"BfWrite.WriteShort", smn_BfWriteShort},
{"BfWrite.WriteWord", smn_BfWriteWord},
{"BfWrite.WriteNum", smn_BfWriteNum},
{"BfWrite.WriteFloat", smn_BfWriteFloat},
{"BfWrite.WriteString", smn_BfWriteString},
{"BfWrite.WriteEntity", smn_BfWriteEntity},
{"BfWrite.WriteAngle", smn_BfWriteAngle},
{"BfWrite.WriteCoord", smn_BfWriteCoord},
{"BfWrite.WriteVecCoord", smn_BfWriteVecCoord},
{"BfWrite.WriteVecNormal", smn_BfWriteVecNormal},
{"BfWrite.WriteAngles", smn_BfWriteAngles},
{"BfRead.ReadBool", smn_BfReadBool},
{"BfRead.ReadByte", smn_BfReadByte},
{"BfRead.ReadChar", smn_BfReadChar},
{"BfRead.ReadShort", smn_BfReadShort},
{"BfRead.ReadWord", smn_BfReadWord},
{"BfRead.ReadNum", smn_BfReadNum},
{"BfRead.ReadFloat", smn_BfReadFloat},
{"BfRead.ReadString", smn_BfReadString},
{"BfRead.ReadEntity", smn_BfReadEntity},
{"BfRead.ReadAngle", smn_BfReadAngle},
{"BfRead.ReadCoord", smn_BfReadCoord},
{"BfRead.ReadVecCoord", smn_BfReadVecCoord},
{"BfRead.ReadVecNormal", smn_BfReadVecNormal},
{"BfRead.ReadAngles", smn_BfReadAngles},
{"BfRead.BytesLeft.get", smn_BfGetNumBytesLeft},
{NULL, NULL}
};

View File

@ -64,13 +64,14 @@ PerformBlind(client, target, amount)
}
else
{
BfWriteShort(message, duration);
BfWriteShort(message, holdtime);
BfWriteShort(message, flags);
BfWriteByte(message, color[0]);
BfWriteByte(message, color[1]);
BfWriteByte(message, color[2]);
BfWriteByte(message, color[3]);
BfWrite bf = UserMessageToBfWrite(message);
bf.WriteShort(duration);
bf.WriteShort(holdtime);
bf.WriteShort(flags);
bf.WriteByte(color[0]);
bf.WriteByte(color[1]);
bf.WriteByte(color[2]);
bf.WriteByte(color[3]);
}
EndMessage();

View File

@ -69,13 +69,14 @@ KillDrug(client)
}
else
{
BfWriteShort(message, duration);
BfWriteShort(message, holdtime);
BfWriteShort(message, flags);
BfWriteByte(message, color[0]);
BfWriteByte(message, color[1]);
BfWriteByte(message, color[2]);
BfWriteByte(message, color[3]);
BfWrite bf = UserMessageToBfWrite(message);
bf.WriteShort(duration);
bf.WriteShort(holdtime);
bf.WriteShort(flags);
bf.WriteByte(color[0]);
bf.WriteByte(color[1]);
bf.WriteByte(color[2]);
bf.WriteByte(color[3]);
}
EndMessage();

View File

@ -1,7 +1,7 @@
/**
* vim: set ts=4 :
* vim: set ts=4 sw=4 tw=99 noet :
* =============================================================================
* SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved.
* SourceMod (C)2004-2014 AlliedModders LLC. All rights reserved.
* =============================================================================
*
* This file is part of the SourceMod/SourcePawn SDK.
@ -35,85 +35,239 @@
#endif
#define _bitbuffer_included
methodmap BfWrite < Handle
{
// Writes a single bit to a writable bitbuffer (bf_write).
//
// @param bit Bit to write (true for 1, false for 0).
public native void WriteBool(bool bit);
// Writes a byte to a writable bitbuffer (bf_write).
//
// @param byte Byte to write (value will be written as 8bit).
public native void WriteByte(int byte);
// Writes a byte to a writable bitbuffer (bf_write).
//
// @param chr Character to write.
public native void WriteChar(int chr);
// Writes a 16bit integer to a writable bitbuffer (bf_write).
//
// @param num Integer to write (value will be written as 16bit).
public native void WriteShort(int num);
// Writes a 16bit unsigned integer to a writable bitbuffer (bf_write).
//
// @param num Integer to write (value will be written as 16bit).
public native void WriteWord(int num);
// Writes a normal integer to a writable bitbuffer (bf_write).
//
// @param num Integer to write (value will be written as 32bit).
public native void WriteNum(int num);
// Writes a floating point number to a writable bitbuffer (bf_write).
//
// @param num Number to write.
public native void WriteFloat(float num);
// Writes a string to a writable bitbuffer (bf_write).
//
// @param string Text string to write.
public native void WriteString(const char[] string);
// Writes an entity to a writable bitbuffer (bf_write).
//
// @param ent Entity index to write.
public native void WriteEntity(int ent);
// Writes a bit angle to a writable bitbuffer (bf_write).
//
// @param angle Angle to write.
// @param numBits Optional number of bits to use.
public native void WriteAngle(float angle, int numBits=8);
// Writes a coordinate to a writable bitbuffer (bf_write).
//
// @param coord Coordinate to write.
public native void WriteCoord(float coord);
// Writes a 3D vector of coordinates to a writable bitbuffer (bf_write).
//
// @param coord Coordinate array to write.
public native void WriteVecCoord(float coord[3]);
// Writes a 3D normal vector to a writable bitbuffer (bf_write).
//
// @param vec Vector to write.
public native void WriteVecNormal(float vec[3]);
// Writes a 3D angle vector to a writable bitbuffer (bf_write).
//
// @param angles Angle vector to write.
public native void WriteAngles(float angles[3]);
};
methodmap BfRead < Handle
{
// Reads a single bit from a readable bitbuffer (bf_read).
//
// @return Bit value read.
public native bool ReadBool();
// Reads a byte from a readable bitbuffer (bf_read).
//
// @return Byte value read (read as 8bit).
public native int ReadByte();
// Reads a character from a readable bitbuffer (bf_read).
//
// @return Character value read.
public native int ReadChar();
// Reads a 16bit integer from a readable bitbuffer (bf_read).
//
// @param bf bf_read handle to read from.
// @return Integer value read (read as 16bit).
public native int ReadShort();
// Reads a 16bit unsigned integer from a readable bitbuffer (bf_read).
//
// @param bf bf_read handle to read from.
// @return Integer value read (read as 16bit).
public native int ReadWord();
// Reads a normal integer to a readable bitbuffer (bf_read).
//
// @return Integer value read (read as 32bit).
public native int ReadNum();
// Reads a floating point number from a readable bitbuffer (bf_read).
//
// @return Floating point value read.
public native float ReadFloat();
// Reads a string from a readable bitbuffer (bf_read).
//
// @param buffer Destination string buffer.
// @param maxlength Maximum length of output string buffer.
// @param line If true the buffer will be copied until it reaches a '\n' or a null terminator.
// @return Number of bytes written to the buffer. If the bitbuffer stream overflowed,
// that is, had no terminator before the end of the stream, then a negative
// number will be returned equal to the number of characters written to the
// buffer minus 1. The buffer will be null terminated regardless of the
// return value.
public native int ReadString(char[] buffer, int maxlength, bool line=false);
// Reads an entity from a readable bitbuffer (bf_read).
//
// @return Entity index read.
public native int ReadEntity();
// Reads a bit angle from a readable bitbuffer (bf_read).
//
// @param numBits Optional number of bits to use.
// @return Angle read.
public native float ReadAngle(int numBits=8);
// Reads a coordinate from a readable bitbuffer (bf_read).
//
// @return Coordinate read.
public native float ReadCoord();
// Reads a 3D vector of coordinates from a readable bitbuffer (bf_read).
//
// @param coord Destination coordinate array.
public native void ReadVecCoord(float coord[3]);
// Reads a 3D normal vector from a readable bitbuffer (bf_read).
//
// @param vec Destination vector array.
public native void ReadVecNormal(float vec[3]);
// Reads a 3D angle vector from a readable bitbuffer (bf_read).
//
// @param angles Destination angle vector.
public native void ReadAngles(float angles[3]);
// Returns the number of bytes left in a readable bitbuffer (bf_read).
property int BytesLeft {
public native get();
}
};
/**
* Writes a single bit to a writable bitbuffer (bf_write).
*
* @param bf bf_write handle to write to.
* @param bit Bit to write (true for 1, false for 0).
* @noreturn
* @error Invalid or incorrect Handle.
*/
native BfWriteBool(Handle:bf, bool:bit);
native void BfWriteBool(Handle bf, bool bit);
/**
* Writes a byte to a writable bitbuffer (bf_write).
*
* @param bf bf_write handle to write to.
* @param byte Byte to write (value will be written as 8bit).
* @noreturn
* @error Invalid or incorrect Handle.
*/
native BfWriteByte(Handle:bf, byte);
native void BfWriteByte(Handle bf, int byte);
/**
* Writes a byte to a writable bitbuffer (bf_write).
*
* @param bf bf_write handle to write to.
* @param chr Character to write.
* @noreturn
* @error Invalid or incorrect Handle.
*/
native BfWriteChar(Handle:bf, chr);
native void BfWriteChar(Handle bf, int chr);
/**
* Writes a 16bit integer to a writable bitbuffer (bf_write).
*
* @param bf bf_write handle to write to.
* @param num Integer to write (value will be written as 16bit).
* @noreturn
* @error Invalid or incorrect Handle.
*/
native BfWriteShort(Handle:bf, num);
native void BfWriteShort(Handle bf, int num);
/**
* Writes a 16bit unsigned integer to a writable bitbuffer (bf_write).
*
* @param bf bf_write handle to write to.
* @param num Integer to write (value will be written as 16bit).
* @noreturn
* @error Invalid or incorrect Handle.
*/
native BfWriteWord(Handle:bf, num);
native void BfWriteWord(Handle bf, int num);
/**
* Writes a normal integer to a writable bitbuffer (bf_write).
*
* @param bf bf_write handle to write to.
* @param num Integer to write (value will be written as 32bit).
* @noreturn
* @error Invalid or incorrect Handle.
*/
native BfWriteNum(Handle:bf, num);
native void BfWriteNum(Handle bf, int num);
/**
* Writes a floating point number to a writable bitbuffer (bf_write).
*
* @param bf bf_write handle to write to.
* @param num Number to write.
* @noreturn
* @error Invalid or incorrect Handle.
*/
native BfWriteFloat(Handle:bf, Float:num);
native void BfWriteFloat(Handle bf, float num);
/**
* Writes a string to a writable bitbuffer (bf_write).
*
* @param bf bf_write handle to write to.
* @param string Text string to write.
* @noreturn
* @error Invalid or incorrect Handle.
*/
native BfWriteString(Handle:bf, const String:string[]);
native void BfWriteString(Handle bf, const char[] string);
/**
* Writes an entity to a writable bitbuffer (bf_write).
@ -121,10 +275,9 @@ native BfWriteString(Handle:bf, const String:string[]);
*
* @param bf bf_write handle to write to.
* @param ent Entity index to write.
* @noreturn
* @error Invalid or incorrect Handle, or invalid entity.
*/
native BfWriteEntity(Handle:bf, ent);
native void BfWriteEntity(Handle bf, int ent);
/**
* Writes a bit angle to a writable bitbuffer (bf_write).
@ -132,30 +285,27 @@ native BfWriteEntity(Handle:bf, ent);
* @param bf bf_write handle to write to.
* @param angle Angle to write.
* @param numBits Optional number of bits to use.
* @noreturn
* @error Invalid or incorrect Handle.
*/
native BfWriteAngle(Handle:bf, Float:angle, numBits=8);
native void BfWriteAngle(Handle bf, float angle, int numBits=8);
/**
* Writes a coordinate to a writable bitbuffer (bf_write).
*
* @param bf bf_write handle to write to.
* @param coord Coordinate to write.
* @noreturn
* @error Invalid or incorrect Handle.
*/
native BfWriteCoord(Handle:bf, Float:coord);
native void BfWriteCoord(Handle bf, float coord);
/**
* Writes a 3D vector of coordinates to a writable bitbuffer (bf_write).
*
* @param bf bf_write handle to write to.
* @param coord Coordinate array to write.
* @noreturn
* @error Invalid or incorrect Handle.
*/
native BfWriteVecCoord(Handle:bf, Float:coord[3]);
native void BfWriteVecCoord(Handle bf, float coord[3]);
/**
* Writes a 3D normal vector to a writable bitbuffer (bf_write).
@ -165,17 +315,16 @@ native BfWriteVecCoord(Handle:bf, Float:coord[3]);
* @noreturn
* @error Invalid or incorrect Handle.
*/
native BfWriteVecNormal(Handle:bf, Float:vec[3]);
native void BfWriteVecNormal(Handle bf, float vec[3]);
/**
* Writes a 3D angle vector to a writable bitbuffer (bf_write).
*
* @param bf bf_write handle to write to.
* @param angles Angle vector to write.
* @noreturn
* @error Invalid or incorrect Handle.
*/
native BfWriteAngles(Handle:bf, Float:angles[3]);
native void BfWriteAngles(Handle bf, float angles[3]);
/**
* Reads a single bit from a readable bitbuffer (bf_read).
@ -184,7 +333,7 @@ native BfWriteAngles(Handle:bf, Float:angles[3]);
* @return Bit value read.
* @error Invalid or incorrect Handle.
*/
native bool:BfReadBool(Handle:bf);
native bool BfReadBool(Handle bf);
/**
* Reads a byte from a readable bitbuffer (bf_read).
@ -193,7 +342,7 @@ native bool:BfReadBool(Handle:bf);
* @return Byte value read (read as 8bit).
* @error Invalid or incorrect Handle.
*/
native BfReadByte(Handle:bf);
native int BfReadByte(Handle bf);
/**
* Reads a character from a readable bitbuffer (bf_read).
@ -202,7 +351,7 @@ native BfReadByte(Handle:bf);
* @return Character value read.
* @error Invalid or incorrect Handle.
*/
native BfReadChar(Handle:bf);
native int BfReadChar(Handle bf);
/**
* Reads a 16bit integer from a readable bitbuffer (bf_read).
@ -211,7 +360,7 @@ native BfReadChar(Handle:bf);
* @return Integer value read (read as 16bit).
* @error Invalid or incorrect Handle.
*/
native BfReadShort(Handle:bf);
native int BfReadShort(Handle bf);
/**
* Reads a 16bit unsigned integer from a readable bitbuffer (bf_read).
@ -220,7 +369,7 @@ native BfReadShort(Handle:bf);
* @return Integer value read (read as 16bit).
* @error Invalid or incorrect Handle.
*/
native BfReadWord(Handle:bf);
native int BfReadWord(Handle bf);
/**
* Reads a normal integer to a readable bitbuffer (bf_read).
@ -229,7 +378,7 @@ native BfReadWord(Handle:bf);
* @return Integer value read (read as 32bit).
* @error Invalid or incorrect Handle.
*/
native BfReadNum(Handle:bf);
native int BfReadNum(Handle bf);
/**
* Reads a floating point number from a readable bitbuffer (bf_read).
@ -238,7 +387,7 @@ native BfReadNum(Handle:bf);
* @return Floating point value read.
* @error Invalid or incorrect Handle.
*/
native Float:BfReadFloat(Handle:bf);
native float BfReadFloat(Handle bf);
/**
* Reads a string from a readable bitbuffer (bf_read).
@ -254,7 +403,7 @@ native Float:BfReadFloat(Handle:bf);
* return value.
* @error Invalid or incorrect Handle.
*/
native BfReadString(Handle:bf, String:buffer[], maxlength, bool:line=false);
native int BfReadString(Handle bf, char[] buffer, int maxlength, bool line=false);
/**
* Reads an entity from a readable bitbuffer (bf_read).
@ -264,7 +413,7 @@ native BfReadString(Handle:bf, String:buffer[], maxlength, bool:line=false);
* @return Entity index read.
* @error Invalid or incorrect Handle.
*/
native BfReadEntity(Handle:bf);
native int BfReadEntity(Handle bf);
/**
* Reads a bit angle from a readable bitbuffer (bf_read).
@ -274,7 +423,7 @@ native BfReadEntity(Handle:bf);
* @return Angle read.
* @error Invalid or incorrect Handle.
*/
native Float:BfReadAngle(Handle:bf, numBits=8);
native float BfReadAngle(Handle bf, int numBits=8);
/**
* Reads a coordinate from a readable bitbuffer (bf_read).
@ -283,37 +432,34 @@ native Float:BfReadAngle(Handle:bf, numBits=8);
* @return Coordinate read.
* @error Invalid or incorrect Handle.
*/
native Float:BfReadCoord(Handle:bf);
native float BfReadCoord(Handle bf);
/**
* Reads a 3D vector of coordinates from a readable bitbuffer (bf_read).
*
* @param bf bf_read handle to read from.
* @param coord Destination coordinate array.
* @noreturn
* @error Invalid or incorrect Handle.
*/
native BfReadVecCoord(Handle:bf, Float:coord[3]);
native void BfReadVecCoord(Handle bf, float coord[3]);
/**
* Reads a 3D normal vector from a readable bitbuffer (bf_read).
*
* @param bf bf_read handle to read from.
* @param vec Destination vector array.
* @noreturn
* @error Invalid or incorrect Handle.
*/
native BfReadVecNormal(Handle:bf, Float:vec[3]);
native void BfReadVecNormal(Handle bf, float vec[3]);
/**
* Reads a 3D angle vector from a readable bitbuffer (bf_read).
*
* @param bf bf_read handle to read from.
* @param angles Destination angle vector.
* @noreturn
* @error Invalid or incorrect Handle.
*/
native BfReadAngles(Handle:bf, Float:angles[3]);
native void BfReadAngles(Handle bf, float angles[3]);
/**
* Returns the number of bytes left in a readable bitbuffer (bf_read).
@ -322,4 +468,4 @@ native BfReadAngles(Handle:bf, Float:angles[3]);
* @return Number of bytes left unread.
* @error Invalid or incorrect Handle.
*/
native BfGetNumBytesLeft(Handle:bf);
native int BfGetNumBytesLeft(Handle bf);

View File

@ -201,6 +201,36 @@ public __ext_core_SetNTVOptional()
MarkNativeAsOptional("BfReadVecNormal");
MarkNativeAsOptional("BfReadAngles");
MarkNativeAsOptional("BfGetNumBytesLeft");
MarkNativeAsOptional("BfWrite.WriteBool");
MarkNativeAsOptional("BfWrite.WriteByte");
MarkNativeAsOptional("BfWrite.WriteChar");
MarkNativeAsOptional("BfWrite.WriteShort");
MarkNativeAsOptional("BfWrite.WriteWord");
MarkNativeAsOptional("BfWrite.WriteNum");
MarkNativeAsOptional("BfWrite.WriteFloat");
MarkNativeAsOptional("BfWrite.WriteString");
MarkNativeAsOptional("BfWrite.WriteEntity");
MarkNativeAsOptional("BfWrite.WriteAngle");
MarkNativeAsOptional("BfWrite.WriteCoord");
MarkNativeAsOptional("BfWrite.WriteVecCoord");
MarkNativeAsOptional("BfWrite.WriteVecNormal");
MarkNativeAsOptional("BfWrite.WriteAngles");
MarkNativeAsOptional("BfRead.ReadBool");
MarkNativeAsOptional("BfRead.ReadByte");
MarkNativeAsOptional("BfRead.ReadChar");
MarkNativeAsOptional("BfRead.ReadShort");
MarkNativeAsOptional("BfRead.ReadWord");
MarkNativeAsOptional("BfRead.ReadNum");
MarkNativeAsOptional("BfRead.ReadFloat");
MarkNativeAsOptional("BfRead.ReadString");
MarkNativeAsOptional("BfRead.ReadEntity");
MarkNativeAsOptional("BfRead.ReadAngle");
MarkNativeAsOptional("BfRead.ReadCoord");
MarkNativeAsOptional("BfRead.ReadVecCoord");
MarkNativeAsOptional("BfRead.ReadVecNormal");
MarkNativeAsOptional("BfRead.ReadAngles");
MarkNativeAsOptional("BfRead.GetNumBytesLeft");
MarkNativeAsOptional("PbReadInt");
MarkNativeAsOptional("PbReadFloat");

View File

@ -1,7 +1,7 @@
/**
* vim: set ts=4 :
* vim: set ts=4 sw=4 tw=99 noet :
* =============================================================================
* SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved.
* SourceMod (C)2004-2014 AlliedModders LLC. All rights reserved.
* =============================================================================
*
* This file is part of the SourceMod/SourcePawn SDK.

View File

@ -77,6 +77,22 @@ stock Protobuf UserMessageToProtobuf(Handle msg)
return Protobuf:msg;
}
// Make sure to only call this on writable buffers (eg from StartMessage).
stock BfWrite UserMessageToBfWrite(Handle msg)
{
if (GetUserMessageType() != UM_Protobuf)
return null;
return BfWrite:msg;
}
// Make sure to only call this on readable buffers (eg from a message hook).
stock BfWrite UserMessageToBfRead(Handle msg)
{
if (GetUserMessageType() != UM_Protobuf)
return null;
return BfRead:msg;
}
/**
* Returns the ID of a given message, or -1 on failure.
*