Add ICellArray and create/free in ISourceMod

Add an ICellArray interface to expose the adt_array CellArray class from
logic to core.
Add methods to ISourceMod to create and delete ICellArray instances in
logic.
This commit is contained in:
Peace-Maker
2016-08-21 21:32:23 +02:00
parent f3c454084a
commit 5b9ae5917b
10 changed files with 202 additions and 7 deletions
+15 -2
View File
@@ -34,10 +34,11 @@
#include <stdlib.h>
#include <string.h>
#include <ICellArray.h>
extern HandleType_t htCellArray;
class CellArray
class CellArray : public ICellArray
{
public:
CellArray(size_t blocksize) : m_Data(NULL), m_BlockSize(blocksize), m_AllocSize(0), m_Size(0)
@@ -49,6 +50,18 @@ public:
free(m_Data);
}
static ICellArray *New(size_t blocksize)
{
return new CellArray(blocksize);
}
static void Free(ICellArray *arr)
{
delete arr;
}
// ICellArray
public:
size_t size() const
{
return m_Size;
@@ -154,7 +167,7 @@ public:
return true;
}
CellArray *clone()
ICellArray *clone()
{
CellArray *array = new CellArray(m_BlockSize);
array->m_AllocSize = m_AllocSize;
+3
View File
@@ -56,6 +56,7 @@
#include "LibrarySys.h"
#include "RootConsoleMenu.h"
#include "CDataPack.h"
#include "CellArray.h"
#include <bridge/include/BridgeAPI.h>
#include <bridge/include/IProviderCallbacks.h>
@@ -147,6 +148,8 @@ static sm_logic_t logic =
RegisterProfiler,
CDataPack::New,
CDataPack::Free,
CellArray::New,
CellArray::Free,
&g_PluginSys,
&g_ShareSys,
&g_Extensions,
+1 -1
View File
@@ -502,7 +502,7 @@ static cell_t CloneArray(IPluginContext *pContext, const cell_t *params)
return pContext->ThrowNativeError("Invalid Handle %x (error: %d)", params[1], err);
}
CellArray *array = oldArray->clone();
ICellArray *array = oldArray->clone();
Handle_t hndl = handlesys->CreateHandle(htCellArray, array, pContext->GetIdentity(), g_pCoreIdent, NULL);
if (!hndl)
+2 -2
View File
@@ -321,7 +321,7 @@ public:
{
return strcmp((char *)str1, (char *)str2);
}
CellArray *UpdateMapList(CellArray *pUseArray, const char *name, int *pSerial, unsigned int flags)
ICellArray *UpdateMapList(ICellArray *pUseArray, const char *name, int *pSerial, unsigned int flags)
{
int change_serial;
CellArray *pNewArray = NULL;
@@ -594,7 +594,7 @@ static cell_t LoadMapList(IPluginContext *pContext, const cell_t *params)
char *str;
Handle_t hndl;
cell_t *addr, flags;
CellArray *pArray, *pNewArray;
ICellArray *pArray, *pNewArray;
hndl = params[1];
pContext->LocalToPhysAddr(params[2], &addr);
+10
View File
@@ -745,6 +745,16 @@ bool SourceModBase::IsMapRunning()
return g_OnMapStarted;
}
ICellArray *SourceModBase::CreateCellArray(size_t blocksize)
{
return logicore.CreateCellArray(blocksize);
}
void SourceModBase::FreeCellArray(ICellArray *arr)
{
logicore.FreeCellArray(arr);
}
class ConVarRegistrar :
public IConCommandBaseAccessor,
public SMGlobalClass
+2
View File
@@ -135,6 +135,8 @@ public: // ISourceMod
int GetPluginId();
int GetShApiVersion();
bool IsMapRunning();
ICellArray *CreateCellArray(size_t blocksize);
void FreeCellArray(ICellArray *arr);
private:
void ShutdownServices();
private: