plugins/include/bitbuffer.inc
author Scott Ehlert <ds@alliedmods.net>
Wed Feb 18 03:13:25 2009 -0600 (2009-02-18)
changeset 2587 3400f3d21adc
parent 2289 44045ead61cd
permissions -rw-r--r--
Ugh, fixed Linux build for real by removing stray underscores.
ds@1990
     1
/**
ds@1990
     2
 * vim: set ts=4 :
ds@1990
     3
 * =============================================================================
ds@1990
     4
 * SourceMod (C)2004-2008 AlliedModders LLC.  All rights reserved.
ds@1990
     5
 * =============================================================================
ds@1990
     6
 *
ds@1990
     7
 * This file is part of the SourceMod/SourcePawn SDK.
ds@1990
     8
 *
ds@1990
     9
 * This program is free software; you can redistribute it and/or modify it under
ds@1990
    10
 * the terms of the GNU General Public License, version 3.0, as published by the
ds@1990
    11
 * Free Software Foundation.
ds@1990
    12
 * 
ds@1990
    13
 * This program is distributed in the hope that it will be useful, but WITHOUT
ds@1990
    14
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
ds@1990
    15
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
ds@1990
    16
 * details.
ds@1990
    17
 *
ds@1990
    18
 * You should have received a copy of the GNU General Public License along with
ds@1990
    19
 * this program.  If not, see <http://www.gnu.org/licenses/>.
ds@1990
    20
 *
ds@1990
    21
 * As a special exception, AlliedModders LLC gives you permission to link the
ds@1990
    22
 * code of this program (as well as its derivative works) to "Half-Life 2," the
ds@1990
    23
 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
ds@1990
    24
 * by the Valve Corporation.  You must obey the GNU General Public License in
ds@1990
    25
 * all respects for all other code used.  Additionally, AlliedModders LLC grants
ds@1990
    26
 * this exception to all derivative works.  AlliedModders LLC defines further
ds@1990
    27
 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
ds@1990
    28
 * or <http://www.sourcemod.net/license.php>.
ds@1990
    29
 *
ds@1990
    30
 * Version: $Id$
ds@1990
    31
 */
ds@1990
    32
ds@1990
    33
#if defined _bitbuffer_included
ds@1990
    34
 #endinput
ds@1990
    35
#endif
ds@1990
    36
#define _bitbuffer_included
ds@1990
    37
ds@1990
    38
/** 
ds@1990
    39
 * Writes a single bit to a writable bitbuffer (bf_write).
ds@1990
    40
 *
ds@1990
    41
 * @param bf			bf_write handle to write to.
ds@1990
    42
 * @param bit			Bit to write (true for 1, false for 0).
ds@1990
    43
 * @noreturn
ds@1990
    44
 * @error				Invalid or incorrect Handle.
ds@1990
    45
 */
ds@1990
    46
native BfWriteBool(Handle:bf, bool:bit);
ds@1990
    47
 
ds@1990
    48
/**
ds@1990
    49
 * Writes a byte to a writable bitbuffer (bf_write).
ds@1990
    50
 *
ds@1990
    51
 * @param bf			bf_write handle to write to.
ds@1990
    52
 * @param byte			Byte to write (value will be written as 8bit).
ds@1990
    53
 * @noreturn
ds@1990
    54
 * @error				Invalid or incorrect Handle.
ds@1990
    55
 */
ds@1990
    56
native BfWriteByte(Handle:bf, byte);
ds@1990
    57
ds@1990
    58
/**
ds@1990
    59
 * Writes a byte to a writable bitbuffer (bf_write).
ds@1990
    60
 *
ds@1990
    61
 * @param bf			bf_write handle to write to.
ds@1990
    62
 * @param chr			Character to write.
ds@1990
    63
 * @noreturn
ds@1990
    64
 * @error				Invalid or incorrect Handle.
ds@1990
    65
 */
ds@1990
    66
native BfWriteChar(Handle:bf, chr);
ds@1990
    67
ds@1990
    68
/**
ds@1990
    69
 * Writes a 16bit integer to a writable bitbuffer (bf_write).
ds@1990
    70
 *
ds@1990
    71
 * @param bf			bf_write handle to write to.
ds@1990
    72
 * @param num			Integer to write (value will be written as 16bit).
ds@1990
    73
 * @noreturn
ds@1990
    74
 * @error				Invalid or incorrect Handle.
ds@1990
    75
 */
ds@1990
    76
native BfWriteShort(Handle:bf, num);
ds@1990
    77
ds@1990
    78
/**
ds@1990
    79
 * Writes a 16bit unsigned integer to a writable bitbuffer (bf_write).
ds@1990
    80
 *
ds@1990
    81
 * @param bf			bf_write handle to write to.
ds@1990
    82
 * @param num			Integer to write (value will be written as 16bit).
ds@1990
    83
 * @noreturn
ds@1990
    84
 * @error				Invalid or incorrect Handle.
ds@1990
    85
 */
ds@1990
    86
native BfWriteWord(Handle:bf, num);
ds@1990
    87
ds@1990
    88
/**
ds@1990
    89
 * Writes a normal integer to a writable bitbuffer (bf_write).
ds@1990
    90
 *
ds@1990
    91
 * @param bf			bf_write handle to write to.
ds@1990
    92
 * @param num			Integer to write (value will be written as 32bit).
ds@1990
    93
 * @noreturn
ds@1990
    94
 * @error				Invalid or incorrect Handle.
ds@1990
    95
 */
ds@1990
    96
native BfWriteNum(Handle:bf, num);
ds@1990
    97
ds@1990
    98
/**
ds@1990
    99
 * Writes a floating point number to a writable bitbuffer (bf_write).
ds@1990
   100
 *
ds@1990
   101
 * @param bf			bf_write handle to write to.
ds@1990
   102
 * @param num			Number to write.
ds@1990
   103
 * @noreturn
ds@1990
   104
 * @error				Invalid or incorrect Handle.
ds@1990
   105
 */
ds@1990
   106
native BfWriteFloat(Handle:bf, Float:num);
ds@1990
   107
ds@1990
   108
/**
ds@1990
   109
 * Writes a string to a writable bitbuffer (bf_write).
ds@1990
   110
 *
ds@1990
   111
 * @param bf			bf_write handle to write to.
ds@1990
   112
 * @param string		Text string to write.
ds@1990
   113
 * @noreturn
ds@1990
   114
 * @error				Invalid or incorrect Handle.
ds@1990
   115
 */
ds@1990
   116
native BfWriteString(Handle:bf, const String:string[]);
ds@1990
   117
ds@1990
   118
/**
ds@1990
   119
 * Writes an entity to a writable bitbuffer (bf_write).
ds@1990
   120
 * @note This is a wrapper around BfWriteShort().
ds@1990
   121
 *
ds@1990
   122
 * @param bf			bf_write handle to write to.
ds@1990
   123
 * @param ent			Entity index to write.
ds@1990
   124
 * @noreturn
ds@1990
   125
 * @error				Invalid or incorrect Handle, or invalid entity.
ds@1990
   126
 */
ds@1990
   127
native BfWriteEntity(Handle:bf, ent);
ds@1990
   128
ds@1990
   129
/**
ds@1990
   130
 * Writes a bit angle to a writable bitbuffer (bf_write).
ds@1990
   131
 *
ds@1990
   132
 * @param bf			bf_write handle to write to.
ds@1990
   133
 * @param angle			Angle to write.
ds@1990
   134
 * @param numBits		Optional number of bits to use.
ds@1990
   135
 * @noreturn
ds@1990
   136
 * @error				Invalid or incorrect Handle.
ds@1990
   137
 */
ds@1990
   138
native BfWriteAngle(Handle:bf, Float:angle, numBits=8);
ds@1990
   139
ds@1990
   140
/**
ds@1990
   141
 * Writes a coordinate to a writable bitbuffer (bf_write).
ds@1990
   142
 *
ds@1990
   143
 * @param bf			bf_write handle to write to.
ds@1990
   144
 * @param coord			Coordinate to write.
ds@1990
   145
 * @noreturn
ds@1990
   146
 * @error				Invalid or incorrect Handle.
ds@1990
   147
 */
ds@1990
   148
native BfWriteCoord(Handle:bf, Float:coord);
ds@1990
   149
ds@1990
   150
/**
ds@1990
   151
 * Writes a 3D vector of coordinates to a writable bitbuffer (bf_write).
ds@1990
   152
 *
ds@1990
   153
 * @param bf			bf_write handle to write to.
ds@1990
   154
 * @param coord			Coordinate array to write.
ds@1990
   155
 * @noreturn
ds@1990
   156
 * @error				Invalid or incorrect Handle.
ds@1990
   157
 */
ds@1990
   158
native BfWriteVecCoord(Handle:bf, Float:coord[3]);
ds@1990
   159
ds@1990
   160
/**
ds@1990
   161
 * Writes a 3D normal vector to a writable bitbuffer (bf_write).
ds@1990
   162
 *
ds@1990
   163
 * @param bf			bf_write handle to write to.
ds@1990
   164
 * @param vec			Vector to write.
ds@1990
   165
 * @noreturn
ds@1990
   166
 * @error				Invalid or incorrect Handle.
ds@1990
   167
 */
ds@1990
   168
native BfWriteVecNormal(Handle:bf, Float:vec[3]);
ds@1990
   169
ds@1990
   170
/**
ds@1990
   171
 * Writes a 3D angle vector to a writable bitbuffer (bf_write).
ds@1990
   172
 *
ds@1990
   173
 * @param bf			bf_write handle to write to.
ds@1990
   174
 * @param angles		Angle vector to write.
ds@1990
   175
 * @noreturn
ds@1990
   176
 * @error				Invalid or incorrect Handle.
ds@1990
   177
 */
ds@1990
   178
native BfWriteAngles(Handle:bf, Float:angles[3]);
ds@1990
   179
ds@1990
   180
/** 
ds@1990
   181
 * Reads a single bit from a readable bitbuffer (bf_read).
ds@1990
   182
 *
ds@1990
   183
 * @param bf			bf_read handle to read from.
ds@1990
   184
 * @return				Bit value read.
ds@1990
   185
 * @error				Invalid or incorrect Handle.
ds@1990
   186
 */
ds@1990
   187
native bool:BfReadBool(Handle:bf);
ds@1990
   188
ds@1990
   189
/**
ds@1990
   190
 * Reads a byte from a readable bitbuffer (bf_read).
ds@1990
   191
 *
ds@1990
   192
 * @param bf			bf_read handle to read from.
ds@1990
   193
 * @return				Byte value read (read as 8bit).
ds@1990
   194
 * @error				Invalid or incorrect Handle.
ds@1990
   195
 */
ds@1990
   196
native BfReadByte(Handle:bf);
ds@1990
   197
ds@1990
   198
/**
ds@1990
   199
 * Reads a character from a readable bitbuffer (bf_read).
ds@1990
   200
 *
ds@1990
   201
 * @param bf			bf_read handle to read from.
ds@1990
   202
 * @return				Character value read.
ds@1990
   203
 * @error				Invalid or incorrect Handle.
ds@1990
   204
 */
ds@1990
   205
native BfReadChar(Handle:bf);
ds@1990
   206
ds@1990
   207
/**
ds@1990
   208
 * Reads a 16bit integer from a readable bitbuffer (bf_read).
ds@1990
   209
 *
ds@1990
   210
 * @param bf			bf_read handle to read from.
ds@1990
   211
 * @return				Integer value read (read as 16bit).
ds@1990
   212
 * @error				Invalid or incorrect Handle.
ds@1990
   213
 */
ds@1990
   214
native BfReadShort(Handle:bf);
ds@1990
   215
ds@1990
   216
/**
ds@1990
   217
 * Reads a 16bit unsigned integer from a readable bitbuffer (bf_read).
ds@1990
   218
 *
ds@1990
   219
 * @param bf			bf_read handle to read from.
ds@1990
   220
 * @return				Integer value read (read as 16bit).
ds@1990
   221
 * @error				Invalid or incorrect Handle.
ds@1990
   222
 */
ds@1990
   223
native BfReadWord(Handle:bf);
ds@1990
   224
ds@1990
   225
/**
ds@1990
   226
 * Reads a normal integer to a readable bitbuffer (bf_read).
ds@1990
   227
 *
ds@1990
   228
 * @param bf			bf_read handle to read from.
ds@1990
   229
 * @return				Integer value read (read as 32bit).
ds@1990
   230
 * @error				Invalid or incorrect Handle.
ds@1990
   231
 */
ds@1990
   232
native BfReadNum(Handle:bf);
ds@1990
   233
ds@1990
   234
/**
ds@1990
   235
 * Reads a floating point number from a readable bitbuffer (bf_read).
ds@1990
   236
 *
ds@1990
   237
 * @param bf			bf_read handle to read from.
ds@1990
   238
 * @return				Floating point value read.
ds@1990
   239
 * @error				Invalid or incorrect Handle.
ds@1990
   240
 */
ds@1990
   241
native Float:BfReadFloat(Handle:bf);
ds@1990
   242
ds@1990
   243
/**
ds@1990
   244
 * Reads a string from a readable bitbuffer (bf_read).
ds@1990
   245
 *
ds@1990
   246
 * @param bf			bf_read handle to read from.
ds@1990
   247
 * @param buffer		Destination string buffer.
ds@1990
   248
 * @param maxlength		Maximum length of output string buffer.
ds@1990
   249
 * @param line			If true the buffer will be copied until it reaches a '\n' or a null terminator.
ds@1990
   250
 * @return				Number of bytes written to the buffer.  If the bitbuffer stream overflowed, 
ds@1990
   251
 *						that is, had no terminator before the end of the stream, then a negative 
ds@1990
   252
 *						number will be returned equal to the number of characters written to the 
ds@1990
   253
 *						buffer minus 1.  The buffer will be null terminated regardless of the 
ds@1990
   254
 *						return value.
ds@1990
   255
 * @error				Invalid or incorrect Handle.
ds@1990
   256
 */
ds@1990
   257
native BfReadString(Handle:bf, String:buffer[], maxlength, bool:line=false);
ds@1990
   258
ds@1990
   259
/**
ds@1990
   260
 * Reads an entity from a readable bitbuffer (bf_read).
ds@1990
   261
 * @note This is a wrapper around BfReadShort().
ds@1990
   262
 *
ds@1990
   263
 * @param bf			bf_read handle to read from.
ds@1990
   264
 * @return				Entity index read.
ds@1990
   265
 * @error				Invalid or incorrect Handle.
ds@1990
   266
 */
ds@1990
   267
native BfReadEntity(Handle:bf);
ds@1990
   268
ds@1990
   269
/**
ds@1990
   270
 * Reads a bit angle from a readable bitbuffer (bf_read).
ds@1990
   271
 *
ds@1990
   272
 * @param bf			bf_read handle to read from.
ds@1990
   273
 * @param numBits		Optional number of bits to use.
ds@1990
   274
 * @return				Angle read.
ds@1990
   275
 * @error				Invalid or incorrect Handle.
ds@1990
   276
 */
ds@1990
   277
native Float:BfReadAngle(Handle:bf, numBits=8);
ds@1990
   278
ds@1990
   279
/**
ds@1990
   280
 * Reads a coordinate from a readable bitbuffer (bf_read).
ds@1990
   281
 *
ds@1990
   282
 * @param bf			bf_read handle to read from.
ds@1990
   283
 * @return				Coordinate read.
ds@1990
   284
 * @error				Invalid or incorrect Handle.
ds@1990
   285
 */
ds@1990
   286
native Float:BfReadCoord(Handle:bf);
ds@1990
   287
ds@1990
   288
/**
ds@1990
   289
 * Reads a 3D vector of coordinates from a readable bitbuffer (bf_read).
ds@1990
   290
 *
ds@1990
   291
 * @param bf			bf_read handle to read from.
ds@1990
   292
 * @param coord			Destination coordinate array.
ds@1990
   293
 * @noreturn
ds@1990
   294
 * @error				Invalid or incorrect Handle.
ds@1990
   295
 */
ds@1990
   296
native BfReadVecCoord(Handle:bf, Float:coord[3]);
ds@1990
   297
ds@1990
   298
/**
ds@1990
   299
 * Reads a 3D normal vector from a readable bitbuffer (bf_read).
ds@1990
   300
 *
ds@1990
   301
 * @param bf			bf_read handle to read from.
ds@1990
   302
 * @param vec			Destination vector array.
ds@1990
   303
 * @noreturn
ds@1990
   304
 * @error				Invalid or incorrect Handle.
ds@1990
   305
 */
ds@1990
   306
native BfReadVecNormal(Handle:bf, Float:vec[3]);
ds@1990
   307
ds@1990
   308
/**
ds@1990
   309
 * Reads a 3D angle vector from a readable bitbuffer (bf_read).
ds@1990
   310
 *
ds@1990
   311
 * @param bf			bf_read handle to read from.
ds@1990
   312
 * @param angles		Destination angle vector.
ds@1990
   313
 * @noreturn
ds@1990
   314
 * @error				Invalid or incorrect Handle.
ds@1990
   315
 */
ds@1990
   316
native BfReadAngles(Handle:bf, Float:angles[3]);
ds@1990
   317
ds@1990
   318
/**
ds@1990
   319
 * Returns the number of bytes left in a readable bitbuffer (bf_read).
ds@1990
   320
 *
ds@1990
   321
 * @param bf			bf_read handle to read from.
ds@1990
   322
 * @return				Number of bytes left unread.
ds@1990
   323
 * @error				Invalid or incorrect Handle.
ds@1990
   324
 */
ds@1990
   325
native BfGetNumBytesLeft(Handle:bf);