fixed
amb1164, SM was crashing due to interface changes from valve (this change is just to make the build update using the latest sdk)
3 * =============================================================================
5 * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved.
6 * =============================================================================
8 * This program is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, version 3.0, as published by the
10 * Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * You should have received a copy of the GNU General Public License along with
18 * this program. If not, see <http://www.gnu.org/licenses/>.
20 * As a special exception, AlliedModders LLC gives you permission to link the
21 * code of this program (as well as its derivative works) to "Half-Life 2," the
22 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
23 * by the Valve Corporation. You must obey the GNU General Public License in
24 * all respects for all other code used. Additionally, AlliedModders LLC grants
25 * this exception to all derivative works. AlliedModders LLC defines further
26 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
27 * or <http://www.sourcemod.net/license.php>.
38 CellArray(size_t blocksize) : m_Data(NULL), m_BlockSize(blocksize), m_AllocSize(0), m_Size(0)
55 cell_t *arr = &m_Data[m_Size * m_BlockSize];
59 cell_t *at(size_t b) const
61 return &m_Data[b * m_BlockSize];
63 size_t blocksize() const
71 bool swap(size_t item1, size_t item2)
73 /* Make sure there is extra space available */
79 cell_t *pri = at(item1);
80 cell_t *alt = at(item2);
82 /* Get our temporary array 1 after the limit */
83 cell_t *temp = &m_Data[m_Size * m_BlockSize];
85 memcpy(temp, pri, sizeof(cell_t) * m_BlockSize);
86 memcpy(pri, alt, sizeof(cell_t) * m_BlockSize);
87 memcpy(alt, temp, sizeof(cell_t) * m_BlockSize);
91 void remove(size_t index)
93 /* If we're at the end, take the easy way out */
94 if (index == m_Size - 1)
100 /* Otherwise, it's time to move stuff! */
101 size_t remaining_indexes = (m_Size - 1) - index;
102 cell_t *src = at(index + 1);
103 cell_t *dest = at(index);
104 memmove(dest, src, sizeof(cell_t) * m_BlockSize * remaining_indexes);
108 cell_t *insert_at(size_t index)
110 /* Make sure it'll fit */
111 if (!GrowIfNeeded(1))
116 /* move everything up */
117 cell_t *src = at(index);
118 cell_t *dst = at(index + 1);
119 memmove(dst, src, sizeof(cell_t) * m_BlockSize * m_Size);
125 bool resize(size_t count)
133 if(!GrowIfNeeded(count - m_Size))
144 CellArray *array = new CellArray(m_BlockSize);
145 array->m_AllocSize = m_AllocSize;
146 array->m_Size = m_Size;
147 array->m_Data = (cell_t *)malloc(sizeof(cell_t) * m_BlockSize * m_AllocSize);
148 memcpy(array->m_Data, m_Data, sizeof(cell_t) * m_BlockSize * m_Size);
153 bool GrowIfNeeded(size_t count)
155 /* Shortcut out if we can store this */
156 if (m_Size + count <= m_AllocSize)
160 /* Set a base allocation size of 8 items */
165 /* If it's not enough, keep doubling */
166 while (m_Size + count > m_AllocSize)
170 /* finally, allocate the new block */
173 m_Data = (cell_t *)realloc(m_Data, sizeof(cell_t) * m_BlockSize * m_AllocSize);
175 m_Data = (cell_t *)malloc(sizeof(cell_t) * m_BlockSize * m_AllocSize);
177 return (m_Data != NULL);