Fix typo, documention and others issues.

This commit is contained in:
Arkshine 2014-08-01 09:21:26 +02:00
parent 42fa547cb4
commit eabafd4eed
4 changed files with 24 additions and 25 deletions

View File

@ -147,8 +147,8 @@ void UTIL_ShowMenu(edict_t* pEntity, int slots, int time, char *menu, int mlen);
void UTIL_ClientSayText(edict_t *pEntity, int sender, char *msg); void UTIL_ClientSayText(edict_t *pEntity, int sender, char *msg);
void UTIL_TeamInfo(edict_t *pEntity, int playerIndex, const char *pszTeamName); void UTIL_TeamInfo(edict_t *pEntity, int playerIndex, const char *pszTeamName);
template <typename D> int UTIL_CheckValidChar(D *c); template <typename D> int UTIL_CheckValidChar(D *c);
template <typename D> unsigned int strncopy(D *dest, const char *src, size_t count); template <typename D, typename S> unsigned int strncopy(D *dest, const S *src, size_t count);
unsigned int UTIL_GetUTF8CharBytes(const char *stream); unsigned int UTIL_GetUTF8CharBytes(const char *stream);
unsigned int UTIL_ReplaceAll(char *subject, size_t maxlength, const char *search, const char *replace, bool caseSensitive); unsigned int UTIL_ReplaceAll(char *subject, size_t maxlength, const char *search, const char *replace, bool caseSensitive);
char *UTIL_ReplaceEx(char *subject, size_t maxLen, const char *search, size_t searchLen, const char *replace, size_t replaceLen, bool caseSensitive); char *UTIL_ReplaceEx(char *subject, size_t maxLen, const char *search, size_t searchLen, const char *replace, size_t replaceLen, bool caseSensitive);

View File

@ -48,7 +48,6 @@ static cell AMX_NATIVE_CALL ArrayCreate(AMX* amx, cell* params)
// params[2] (reserved) is how many elements to allocate // params[2] (reserved) is how many elements to allocate
// immediately when the list is created. // immediately when the list is created.
// this MUST be greater than 0!
int reserved = params[2]; int reserved = params[2];
if (cellsize <= 0) if (cellsize <= 0)
@ -56,11 +55,6 @@ static cell AMX_NATIVE_CALL ArrayCreate(AMX* amx, cell* params)
LogError(amx, AMX_ERR_NATIVE, "Invalid array size (%d)", cellsize); LogError(amx, AMX_ERR_NATIVE, "Invalid array size (%d)", cellsize);
return -1; return -1;
} }
if (reserved <= 0)
{
LogError(amx, AMX_ERR_NATIVE, "Invalid reserved size (%d)", reserved);
return -1;
}
// Scan through the vector list to see if any are NULL. // Scan through the vector list to see if any are NULL.
// NULL means the vector was previously destroyed. // NULL means the vector was previously destroyed.
@ -69,14 +63,23 @@ static cell AMX_NATIVE_CALL ArrayCreate(AMX* amx, cell* params)
if (VectorHolder[i]==NULL) if (VectorHolder[i]==NULL)
{ {
VectorHolder[i] = new CellArray(cellsize); VectorHolder[i] = new CellArray(cellsize);
//VectorHolder[i]->resize(reserved);
if (reserved > 0)
{
VectorHolder[i]->resize(reserved);
}
return i + 1; return i + 1;
} }
} }
// None are NULL, create a new vector // None are NULL, create a new vector
CellArray* NewVector = new CellArray(cellsize); CellArray* NewVector = new CellArray(cellsize);
//NewVector->resize(reserved);
if (reserved > 0)
{
NewVector->resize(reserved);
}
VectorHolder.append(NewVector); VectorHolder.append(NewVector);
@ -188,7 +191,7 @@ static cell AMX_NATIVE_CALL ArrayGetArray(AMX* amx, cell* params)
memcpy(addr, blk, sizeof(cell) * indexes); memcpy(addr, blk, sizeof(cell) * indexes);
return 1; return indexes;
} }
// native any:ArrayGetCell(Array:which, item, block = 0, bool:asChar = false); // native any:ArrayGetCell(Array:which, item, block = 0, bool:asChar = false);
@ -288,7 +291,7 @@ static cell AMX_NATIVE_CALL ArraySetArray(AMX* amx, cell* params)
memcpy(blk, addr, sizeof(cell) * indexes); memcpy(blk, addr, sizeof(cell) * indexes);
return 1; return indexes;
} }
// native ArraySetCell(Array:which, item, any:input, block = 0, bool:asChar = false); // native ArraySetCell(Array:which, item, any:input, block = 0, bool:asChar = false);
@ -425,15 +428,13 @@ static cell AMX_NATIVE_CALL ArrayPushString(AMX* amx, cell* params)
} }
cell *blk = vec->push(); cell *blk = vec->push();
cell *start = blk;
if (!blk) if (!blk)
{ {
LogError(amx, AMX_ERR_NATIVE, "Failed to grow array"); LogError(amx, AMX_ERR_NATIVE, "Failed to grow array");
return 0; return 0;
} }
memcpy(blk, get_amxaddr(amx, params[2]), sizeof(cell) * vec->blocksize()); strncopy(blk, get_amxaddr(amx, params[2]), vec->blocksize());
blk[vec->blocksize() - 1]= '\0';
return static_cast<cell>((vec->size() - 1)); return static_cast<cell>((vec->size() - 1));
} }
@ -634,7 +635,7 @@ static cell AMX_NATIVE_CALL ArraySwap(AMX* amx, cell* params)
return 0; return 0;
} }
vec->swap(params[2], params[3]); vec->swap(idx1, idx2);
return 1; return 1;
} }

View File

@ -514,11 +514,12 @@ unsigned int UTIL_ReplaceAll(char *subject, size_t maxlength, const char *search
return total; return total;
} }
template unsigned int strncopy<char>(char *, const char *src, size_t count); template unsigned int strncopy<char, char>(char *, const char *src, size_t count);
template unsigned int strncopy<cell>(cell *, const char *src, size_t count); template unsigned int strncopy<cell, char>(cell *, const char *src, size_t count);
template unsigned int strncopy<cell, cell>(cell *, const cell *src, size_t count);
template <typename D> template <typename D, typename S>
unsigned int strncopy(D *dest, const char *src, size_t count) unsigned int strncopy(D *dest, const S *src, size_t count)
{ {
if (!count) if (!count)
{ {

View File

@ -39,15 +39,13 @@ stock ByteCountToCells(size)
* It is very important that the cellsize you provide matches up with the buffer sizes * It is very important that the cellsize you provide matches up with the buffer sizes
* that you pass with subsequent Array{Get,Set,Push} calls. * that you pass with subsequent Array{Get,Set,Push} calls.
* *
* @note As per AMX Mod X 1.8.3, reserved parameter has no effect.
*
* @param cellsize How many cells each entry in the array is. * @param cellsize How many cells each entry in the array is.
* @param reserved How many blank entries are created immediately when the array is created. * @param reserved How many blank entries are created immediately when the array is created.
* These entries are not valid to read from until called with ArraySet. * These entries are not valid to read from until called with ArraySet.
* *
* @return Handle to the array. * @return Handle to the array.
*/ */
native Array:ArrayCreate(cellsize = 1, reserved = 32); native Array:ArrayCreate(cellsize = 1, reserved = 0);
/** /**
* Clones an array, returning a new handle with the same size and data. * Clones an array, returning a new handle with the same size and data.
@ -98,9 +96,9 @@ native bool:ArrayResize(Array:which, newsize);
* *
* @param which The array to retrieve the item from. * @param which The array to retrieve the item from.
* @param item The item to retrieve (zero-based). * @param item The item to retrieve (zero-based).
* @param output The output buffer to write.
* @param size If not set, assumes the buffer size is equal to the * @param size If not set, assumes the buffer size is equal to the
* cellsize. Otherwise, the size passed is used. * cellsize. Otherwise, the size passed is used.
* @param output The output buffer to write.
* *
* @return Number of cells copied. * @return Number of cells copied.
* @error Invalid handle or invalid index. * @error Invalid handle or invalid index.
@ -109,7 +107,6 @@ native ArrayGetArray(Array:which, item, any:output[], size = -1);
/** /**
* Returns a single cell of data from an array. * Returns a single cell of data from an array.
* Use this only with arrays that were created with a cellsize of 1!
* *
* @param which The array to retrieve the item from. * @param which The array to retrieve the item from.
* @param item The item to retrieve (zero-based). * @param item The item to retrieve (zero-based).