Move CDataPack from core to logic.
This commit is contained in:
parent
69984f472f
commit
67c8ee4ce3
@ -50,6 +50,7 @@ class IProviderCallbacks;
|
||||
class IExtensionSys;
|
||||
class ITextParsers;
|
||||
class ILogger;
|
||||
class IDataPack;
|
||||
|
||||
struct sm_logic_t
|
||||
{
|
||||
@ -71,6 +72,8 @@ struct sm_logic_t
|
||||
bool (*DumpAdminCache)(const char *filename);
|
||||
void (*RegisterProfiler)(IProfilingTool *tool);
|
||||
void (*OnRootCommand)(const ICommandArgs *args);
|
||||
IDataPack * (*CreateDataPack)();
|
||||
void (*FreeDataPack)(IDataPack *pack);
|
||||
IScriptManager *scripts;
|
||||
IShareSys *sharesys;
|
||||
IExtensionSys *extsys;
|
||||
|
@ -9,7 +9,6 @@ project.sources += [
|
||||
'sm_stringutil.cpp',
|
||||
'MenuVoting.cpp',
|
||||
'smn_events.cpp',
|
||||
'CDataPack.cpp',
|
||||
'frame_hooks.cpp',
|
||||
'smn_nextmap.cpp',
|
||||
'sourcemm_api.cpp',
|
||||
|
@ -79,6 +79,7 @@ binary.sources += [
|
||||
'sprintf.cpp',
|
||||
'LibrarySys.cpp',
|
||||
'RootConsoleMenu.cpp',
|
||||
'CDataPack.cpp',
|
||||
]
|
||||
if builder.target_platform == 'windows':
|
||||
binary.sources += ['thread/WinThreads.cpp']
|
||||
|
@ -32,6 +32,10 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "CDataPack.h"
|
||||
#include <am-utility.h>
|
||||
#include <am-vector.h>
|
||||
|
||||
using namespace ke;
|
||||
|
||||
#define DATAPACK_INITIAL_SIZE 64
|
||||
|
||||
@ -47,6 +51,25 @@ CDataPack::~CDataPack()
|
||||
free(m_pBase);
|
||||
}
|
||||
|
||||
static Vector<AutoPtr<CDataPack>> sDataPackCache;
|
||||
|
||||
IDataPack * CDataPack::New()
|
||||
{
|
||||
if (sDataPackCache.empty())
|
||||
return new CDataPack();
|
||||
|
||||
CDataPack *pack = sDataPackCache.back().take();
|
||||
sDataPackCache.pop();
|
||||
pack->Initialize();
|
||||
return pack;
|
||||
}
|
||||
|
||||
void
|
||||
CDataPack::Free(IDataPack *pack)
|
||||
{
|
||||
sDataPackCache.append(static_cast<CDataPack *>(pack));
|
||||
}
|
||||
|
||||
void CDataPack::Initialize()
|
||||
{
|
||||
m_curptr = m_pBase;
|
||||
@ -331,4 +354,4 @@ cell_t CDataPack::ReadFunction() const
|
||||
cell_t val = *reinterpret_cast<cell_t *>(m_curptr);
|
||||
m_curptr += sizeof(cell_t);
|
||||
return val;
|
||||
}
|
||||
}
|
@ -41,6 +41,9 @@ class CDataPack : public IDataPack
|
||||
public:
|
||||
CDataPack();
|
||||
~CDataPack();
|
||||
|
||||
static IDataPack *New();
|
||||
static void Free(IDataPack *pack);
|
||||
public: //IDataReader
|
||||
void Reset() const;
|
||||
size_t GetPosition() const;
|
@ -54,6 +54,7 @@
|
||||
#include "sprintf.h"
|
||||
#include "LibrarySys.h"
|
||||
#include "RootConsoleMenu.h"
|
||||
#include "CDataPack.h"
|
||||
#include <bridge/include/BridgeAPI.h>
|
||||
#include <bridge/include/IProviderCallbacks.h>
|
||||
|
||||
@ -158,6 +159,8 @@ static sm_logic_t logic =
|
||||
DumpAdminCache,
|
||||
RegisterProfiler,
|
||||
OnRootCommand,
|
||||
CDataPack::New,
|
||||
CDataPack::Free,
|
||||
&g_PluginSys,
|
||||
&g_ShareSys,
|
||||
&g_Extensions,
|
||||
|
@ -32,12 +32,7 @@
|
||||
#include "common_logic.h"
|
||||
#include <IHandleSys.h>
|
||||
#include <ISourceMod.h>
|
||||
|
||||
// This just in from the bucket o' hacks department.
|
||||
// One day, IDataPack will go away and CDataPack will be merged into this file.
|
||||
// This internal header is included directly to access GetCapacity,
|
||||
// which can not be added to the public interface due to ABI issues.
|
||||
#include "../CDataPack.h"
|
||||
#include "CDataPack.h"
|
||||
|
||||
HandleType_t g_DataPackType;
|
||||
|
||||
@ -66,7 +61,7 @@ public:
|
||||
}
|
||||
void OnHandleDestroy(HandleType_t type, void *object)
|
||||
{
|
||||
g_pSM->FreeDataPack(reinterpret_cast<IDataPack *>(object));
|
||||
CDataPack::Free(reinterpret_cast<IDataPack *>(object));
|
||||
}
|
||||
bool GetHandleApproxSize(HandleType_t type, void *object, unsigned int *pSize)
|
||||
{
|
||||
@ -78,7 +73,7 @@ public:
|
||||
|
||||
static cell_t smn_CreateDataPack(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
IDataPack *pDataPack = g_pSM->CreateDataPack();
|
||||
IDataPack *pDataPack = CDataPack::New();
|
||||
|
||||
if (!pDataPack)
|
||||
{
|
||||
|
@ -515,16 +515,6 @@ void SourceModBase::ShutdownServices()
|
||||
pBase = pBase->m_pGlobalClassNext;
|
||||
}
|
||||
|
||||
/* Delete all data packs */
|
||||
CStack<CDataPack *>::iterator iter;
|
||||
CDataPack *pd;
|
||||
for (iter=m_freepacks.begin(); iter!=m_freepacks.end(); iter++)
|
||||
{
|
||||
pd = (*iter);
|
||||
delete pd;
|
||||
}
|
||||
m_freepacks.popall();
|
||||
|
||||
sCoreProviderImpl.ShutdownHooks();
|
||||
|
||||
/* Notify! */
|
||||
@ -624,26 +614,16 @@ unsigned int SourceModBase::GetGlobalTarget() const
|
||||
|
||||
IDataPack *SourceModBase::CreateDataPack()
|
||||
{
|
||||
CDataPack *pack;
|
||||
if (m_freepacks.empty())
|
||||
{
|
||||
pack = new CDataPack;
|
||||
} else {
|
||||
pack = m_freepacks.front();
|
||||
m_freepacks.pop();
|
||||
pack->Initialize();
|
||||
}
|
||||
return pack;
|
||||
return logicore.CreateDataPack();
|
||||
}
|
||||
|
||||
void SourceModBase::FreeDataPack(IDataPack *pack)
|
||||
{
|
||||
m_freepacks.push(static_cast<CDataPack *>(pack));
|
||||
logicore.FreeDataPack(pack);
|
||||
}
|
||||
|
||||
Handle_t SourceModBase::GetDataPackHandleType(bool readonly)
|
||||
{
|
||||
//:TODO:
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,6 @@
|
||||
#include <ISourceMod.h>
|
||||
#include <sh_stack.h>
|
||||
#include <sh_vector.h>
|
||||
#include "CDataPack.h"
|
||||
|
||||
using namespace SourceHook;
|
||||
|
||||
@ -139,7 +138,6 @@ public: // ISourceMod
|
||||
private:
|
||||
void ShutdownServices();
|
||||
private:
|
||||
CStack<CDataPack *> m_freepacks;
|
||||
char m_SMBaseDir[PLATFORM_MAX_PATH];
|
||||
char m_SMRelDir[PLATFORM_MAX_PATH];
|
||||
char m_ModDir[32];
|
||||
|
Loading…
Reference in New Issue
Block a user