plugins/include/bitbuffer.inc
changeset 1952 b7aa2b626807
child 1990 de135d1f05b1
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/plugins/include/bitbuffer.inc	Sun Mar 30 07:00:22 2008 +0000
     1.3 @@ -0,0 +1,325 @@
     1.4 +/**
     1.5 + * vim: set ts=4 :
     1.6 + * =============================================================================
     1.7 + * SourceMod (C)2004-2008 AlliedModders LLC.  All rights reserved.
     1.8 + * =============================================================================
     1.9 + *
    1.10 + * This file is part of the SourceMod/SourcePawn SDK.
    1.11 + *
    1.12 + * This program is free software; you can redistribute it and/or modify it under
    1.13 + * the terms of the GNU General Public License, version 3.0, as published by the
    1.14 + * Free Software Foundation.
    1.15 + * 
    1.16 + * This program is distributed in the hope that it will be useful, but WITHOUT
    1.17 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    1.18 + * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    1.19 + * details.
    1.20 + *
    1.21 + * You should have received a copy of the GNU General Public License along with
    1.22 + * this program.  If not, see <http://www.gnu.org/licenses/>.
    1.23 + *
    1.24 + * As a special exception, AlliedModders LLC gives you permission to link the
    1.25 + * code of this program (as well as its derivative works) to "Half-Life 2," the
    1.26 + * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    1.27 + * by the Valve Corporation.  You must obey the GNU General Public License in
    1.28 + * all respects for all other code used.  Additionally, AlliedModders LLC grants
    1.29 + * this exception to all derivative works.  AlliedModders LLC defines further
    1.30 + * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    1.31 + * or <http://www.sourcemod.net/license.php>.
    1.32 + *
    1.33 + * Version: $Id$
    1.34 + */
    1.35 +
    1.36 +#if defined _bitbuffer_included
    1.37 + #endinput
    1.38 +#endif
    1.39 +#define _bitbuffer_included
    1.40 +
    1.41 +/** 
    1.42 + * Writes a single bit to a writable bitbuffer (bf_write).
    1.43 + *
    1.44 + * @param bf			bf_write handle to write to.
    1.45 + * @param bit			Bit to write (true for 1, false for 0).
    1.46 + * @noreturn
    1.47 + * @error				Invalid or incorrect Handle.
    1.48 + */
    1.49 +native BfWriteBool(Handle:bf, bool:bit);
    1.50 + 
    1.51 +/**
    1.52 + * Writes a byte to a writable bitbuffer (bf_write).
    1.53 + *
    1.54 + * @param bf			bf_write handle to write to.
    1.55 + * @param byte			Byte to write (value will be written as 8bit).
    1.56 + * @noreturn
    1.57 + * @error				Invalid or incorrect Handle.
    1.58 + */
    1.59 +native BfWriteByte(Handle:bf, byte);
    1.60 +
    1.61 +/**
    1.62 + * Writes a byte to a writable bitbuffer (bf_write).
    1.63 + *
    1.64 + * @param bf			bf_write handle to write to.
    1.65 + * @param chr			Character to write.
    1.66 + * @noreturn
    1.67 + * @error				Invalid or incorrect Handle.
    1.68 + */
    1.69 +native BfWriteChar(Handle:bf, chr);
    1.70 +
    1.71 +/**
    1.72 + * Writes a 16bit integer to a writable bitbuffer (bf_write).
    1.73 + *
    1.74 + * @param bf			bf_write handle to write to.
    1.75 + * @param num			Integer to write (value will be written as 16bit).
    1.76 + * @noreturn
    1.77 + * @error				Invalid or incorrect Handle.
    1.78 + */
    1.79 +native BfWriteShort(Handle:bf, num);
    1.80 +
    1.81 +/**
    1.82 + * Writes a 16bit unsigned integer to a writable bitbuffer (bf_write).
    1.83 + *
    1.84 + * @param bf			bf_write handle to write to.
    1.85 + * @param num			Integer to write (value will be written as 16bit).
    1.86 + * @noreturn
    1.87 + * @error				Invalid or incorrect Handle.
    1.88 + */
    1.89 +native BfWriteWord(Handle:bf, num);
    1.90 +
    1.91 +/**
    1.92 + * Writes a normal integer to a writable bitbuffer (bf_write).
    1.93 + *
    1.94 + * @param bf			bf_write handle to write to.
    1.95 + * @param num			Integer to write (value will be written as 32bit).
    1.96 + * @noreturn
    1.97 + * @error				Invalid or incorrect Handle.
    1.98 + */
    1.99 +native BfWriteNum(Handle:bf, num);
   1.100 +
   1.101 +/**
   1.102 + * Writes a floating point number to a writable bitbuffer (bf_write).
   1.103 + *
   1.104 + * @param bf			bf_write handle to write to.
   1.105 + * @param num			Number to write.
   1.106 + * @noreturn
   1.107 + * @error				Invalid or incorrect Handle.
   1.108 + */
   1.109 +native BfWriteFloat(Handle:bf, Float:num);
   1.110 +
   1.111 +/**
   1.112 + * Writes a string to a writable bitbuffer (bf_write).
   1.113 + *
   1.114 + * @param bf			bf_write handle to write to.
   1.115 + * @param string		Text string to write.
   1.116 + * @noreturn
   1.117 + * @error				Invalid or incorrect Handle.
   1.118 + */
   1.119 +native BfWriteString(Handle:bf, const String:string[]);
   1.120 +
   1.121 +/**
   1.122 + * Writes an entity to a writable bitbuffer (bf_write).
   1.123 + * @note This is a wrapper around BfWriteShort().
   1.124 + *
   1.125 + * @param bf			bf_write handle to write to.
   1.126 + * @param ent			Entity index to write.
   1.127 + * @noreturn
   1.128 + * @error				Invalid or incorrect Handle, or invalid entity.
   1.129 + */
   1.130 +native BfWriteEntity(Handle:bf, ent);
   1.131 +
   1.132 +/**
   1.133 + * Writes a bit angle to a writable bitbuffer (bf_write).
   1.134 + *
   1.135 + * @param bf			bf_write handle to write to.
   1.136 + * @param angle			Angle to write.
   1.137 + * @param numBits		Optional number of bits to use.
   1.138 + * @noreturn
   1.139 + * @error				Invalid or incorrect Handle.
   1.140 + */
   1.141 +native BfWriteAngle(Handle:bf, Float:angle, numBits=8);
   1.142 +
   1.143 +/**
   1.144 + * Writes a coordinate to a writable bitbuffer (bf_write).
   1.145 + *
   1.146 + * @param bf			bf_write handle to write to.
   1.147 + * @param coord			Coordinate to write.
   1.148 + * @noreturn
   1.149 + * @error				Invalid or incorrect Handle.
   1.150 + */
   1.151 +native BfWriteCoord(Handle:bf, Float:coord);
   1.152 +
   1.153 +/**
   1.154 + * Writes a 3D vector of coordinates to a writable bitbuffer (bf_write).
   1.155 + *
   1.156 + * @param bf			bf_write handle to write to.
   1.157 + * @param coord			Coordinate array to write.
   1.158 + * @noreturn
   1.159 + * @error				Invalid or incorrect Handle.
   1.160 + */
   1.161 +native BfWriteVecCoord(Handle:bf, Float:coord[3]);
   1.162 +
   1.163 +/**
   1.164 + * Writes a 3D normal vector to a writable bitbuffer (bf_write).
   1.165 + *
   1.166 + * @param bf			bf_write handle to write to.
   1.167 + * @param vec			Vector to write.
   1.168 + * @noreturn
   1.169 + * @error				Invalid or incorrect Handle.
   1.170 + */
   1.171 +native BfWriteVecNormal(Handle:bf, Float:vec[3]);
   1.172 +
   1.173 +/**
   1.174 + * Writes a 3D angle vector to a writable bitbuffer (bf_write).
   1.175 + *
   1.176 + * @param bf			bf_write handle to write to.
   1.177 + * @param angles		Angle vector to write.
   1.178 + * @noreturn
   1.179 + * @error				Invalid or incorrect Handle.
   1.180 + */
   1.181 +native BfWriteAngles(Handle:bf, Float:angles[3]);
   1.182 +
   1.183 +/** 
   1.184 + * Reads a single bit from a readable bitbuffer (bf_read).
   1.185 + *
   1.186 + * @param bf			bf_read handle to read from.
   1.187 + * @return				Bit value read.
   1.188 + * @error				Invalid or incorrect Handle.
   1.189 + */
   1.190 +native bool:BfReadBool(Handle:bf);
   1.191 +
   1.192 +/**
   1.193 + * Reads a byte from a readable bitbuffer (bf_read).
   1.194 + *
   1.195 + * @param bf			bf_read handle to read from.
   1.196 + * @return				Byte value read (read as 8bit).
   1.197 + * @error				Invalid or incorrect Handle.
   1.198 + */
   1.199 +native BfReadByte(Handle:bf);
   1.200 +
   1.201 +/**
   1.202 + * Reads a character from a readable bitbuffer (bf_read).
   1.203 + *
   1.204 + * @param bf			bf_read handle to read from.
   1.205 + * @return				Character value read.
   1.206 + * @error				Invalid or incorrect Handle.
   1.207 + */
   1.208 +native BfReadChar(Handle:bf);
   1.209 +
   1.210 +/**
   1.211 + * Reads a 16bit integer from a readable bitbuffer (bf_read).
   1.212 + *
   1.213 + * @param bf			bf_read handle to read from.
   1.214 + * @return				Integer value read (read as 16bit).
   1.215 + * @error				Invalid or incorrect Handle.
   1.216 + */
   1.217 +native BfReadShort(Handle:bf);
   1.218 +
   1.219 +/**
   1.220 + * Reads a 16bit unsigned integer from a readable bitbuffer (bf_read).
   1.221 + *
   1.222 + * @param bf			bf_read handle to read from.
   1.223 + * @return				Integer value read (read as 16bit).
   1.224 + * @error				Invalid or incorrect Handle.
   1.225 + */
   1.226 +native BfReadWord(Handle:bf);
   1.227 +
   1.228 +/**
   1.229 + * Reads a normal integer to a readable bitbuffer (bf_read).
   1.230 + *
   1.231 + * @param bf			bf_read handle to read from.
   1.232 + * @return				Integer value read (read as 32bit).
   1.233 + * @error				Invalid or incorrect Handle.
   1.234 + */
   1.235 +native BfReadNum(Handle:bf);
   1.236 +
   1.237 +/**
   1.238 + * Reads a floating point number from a readable bitbuffer (bf_read).
   1.239 + *
   1.240 + * @param bf			bf_read handle to read from.
   1.241 + * @return				Floating point value read.
   1.242 + * @error				Invalid or incorrect Handle.
   1.243 + */
   1.244 +native Float:BfReadFloat(Handle:bf);
   1.245 +
   1.246 +/**
   1.247 + * Reads a string from a readable bitbuffer (bf_read).
   1.248 + *
   1.249 + * @param bf			bf_read handle to read from.
   1.250 + * @param buffer		Destination string buffer.
   1.251 + * @param maxlength		Maximum length of output string buffer.
   1.252 + * @param line			If true the buffer will be copied until it reaches a '\n' or a null terminator.
   1.253 + * @return				Number of bytes written to the buffer.  If the bitbuffer stream overflowed, 
   1.254 + *						that is, had no terminator before the end of the stream, then a negative 
   1.255 + *						number will be returned equal to the number of characters written to the 
   1.256 + *						buffer minus 1.  The buffer will be null terminated regardless of the 
   1.257 + *						return value.
   1.258 + * @error				Invalid or incorrect Handle.
   1.259 + */
   1.260 +native BfReadString(Handle:bf, String:buffer[], maxlength, bool:line=false);
   1.261 +
   1.262 +/**
   1.263 + * Reads an entity from a readable bitbuffer (bf_read).
   1.264 + * @note This is a wrapper around BfReadShort().
   1.265 + *
   1.266 + * @param bf			bf_read handle to read from.
   1.267 + * @return				Entity index read.
   1.268 + * @error				Invalid or incorrect Handle.
   1.269 + */
   1.270 +native BfReadEntity(Handle:bf);
   1.271 +
   1.272 +/**
   1.273 + * Reads a bit angle from a readable bitbuffer (bf_read).
   1.274 + *
   1.275 + * @param bf			bf_read handle to read from.
   1.276 + * @param numBits		Optional number of bits to use.
   1.277 + * @return				Angle read.
   1.278 + * @error				Invalid or incorrect Handle.
   1.279 + */
   1.280 +native Float:BfReadAngle(Handle:bf, numBits=8);
   1.281 +
   1.282 +/**
   1.283 + * Reads a coordinate from a readable bitbuffer (bf_read).
   1.284 + *
   1.285 + * @param bf			bf_read handle to read from.
   1.286 + * @return				Coordinate read.
   1.287 + * @error				Invalid or incorrect Handle.
   1.288 + */
   1.289 +native Float:BfReadCoord(Handle:bf);
   1.290 +
   1.291 +/**
   1.292 + * Reads a 3D vector of coordinates from a readable bitbuffer (bf_read).
   1.293 + *
   1.294 + * @param bf			bf_read handle to read from.
   1.295 + * @param coord			Destination coordinate array.
   1.296 + * @noreturn
   1.297 + * @error				Invalid or incorrect Handle.
   1.298 + */
   1.299 +native BfReadVecCoord(Handle:bf, Float:coord[3]);
   1.300 +
   1.301 +/**
   1.302 + * Reads a 3D normal vector from a readable bitbuffer (bf_read).
   1.303 + *
   1.304 + * @param bf			bf_read handle to read from.
   1.305 + * @param vec			Destination vector array.
   1.306 + * @noreturn
   1.307 + * @error				Invalid or incorrect Handle.
   1.308 + */
   1.309 +native BfReadVecNormal(Handle:bf, Float:vec[3]);
   1.310 +
   1.311 +/**
   1.312 + * Reads a 3D angle vector from a readable bitbuffer (bf_read).
   1.313 + *
   1.314 + * @param bf			bf_read handle to read from.
   1.315 + * @param angles		Destination angle vector.
   1.316 + * @noreturn
   1.317 + * @error				Invalid or incorrect Handle.
   1.318 + */
   1.319 +native BfReadAngles(Handle:bf, Float:angles[3]);
   1.320 +
   1.321 +/**
   1.322 + * Returns the number of bytes left in a readable bitbuffer (bf_read).
   1.323 + *
   1.324 + * @param bf			bf_read handle to read from.
   1.325 + * @return				Number of bytes left unread.
   1.326 + * @error				Invalid or incorrect Handle.
   1.327 + */
   1.328 +native BfGetNumBytesLeft(Handle:bf);