Move CDataPack from core to logic.
This commit is contained in:
parent
69984f472f
commit
67c8ee4ce3
@ -50,6 +50,7 @@ class IProviderCallbacks;
|
|||||||
class IExtensionSys;
|
class IExtensionSys;
|
||||||
class ITextParsers;
|
class ITextParsers;
|
||||||
class ILogger;
|
class ILogger;
|
||||||
|
class IDataPack;
|
||||||
|
|
||||||
struct sm_logic_t
|
struct sm_logic_t
|
||||||
{
|
{
|
||||||
@ -71,6 +72,8 @@ struct sm_logic_t
|
|||||||
bool (*DumpAdminCache)(const char *filename);
|
bool (*DumpAdminCache)(const char *filename);
|
||||||
void (*RegisterProfiler)(IProfilingTool *tool);
|
void (*RegisterProfiler)(IProfilingTool *tool);
|
||||||
void (*OnRootCommand)(const ICommandArgs *args);
|
void (*OnRootCommand)(const ICommandArgs *args);
|
||||||
|
IDataPack * (*CreateDataPack)();
|
||||||
|
void (*FreeDataPack)(IDataPack *pack);
|
||||||
IScriptManager *scripts;
|
IScriptManager *scripts;
|
||||||
IShareSys *sharesys;
|
IShareSys *sharesys;
|
||||||
IExtensionSys *extsys;
|
IExtensionSys *extsys;
|
||||||
|
@ -9,7 +9,6 @@ project.sources += [
|
|||||||
'sm_stringutil.cpp',
|
'sm_stringutil.cpp',
|
||||||
'MenuVoting.cpp',
|
'MenuVoting.cpp',
|
||||||
'smn_events.cpp',
|
'smn_events.cpp',
|
||||||
'CDataPack.cpp',
|
|
||||||
'frame_hooks.cpp',
|
'frame_hooks.cpp',
|
||||||
'smn_nextmap.cpp',
|
'smn_nextmap.cpp',
|
||||||
'sourcemm_api.cpp',
|
'sourcemm_api.cpp',
|
||||||
|
@ -79,6 +79,7 @@ binary.sources += [
|
|||||||
'sprintf.cpp',
|
'sprintf.cpp',
|
||||||
'LibrarySys.cpp',
|
'LibrarySys.cpp',
|
||||||
'RootConsoleMenu.cpp',
|
'RootConsoleMenu.cpp',
|
||||||
|
'CDataPack.cpp',
|
||||||
]
|
]
|
||||||
if builder.target_platform == 'windows':
|
if builder.target_platform == 'windows':
|
||||||
binary.sources += ['thread/WinThreads.cpp']
|
binary.sources += ['thread/WinThreads.cpp']
|
||||||
|
@ -32,6 +32,10 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "CDataPack.h"
|
#include "CDataPack.h"
|
||||||
|
#include <am-utility.h>
|
||||||
|
#include <am-vector.h>
|
||||||
|
|
||||||
|
using namespace ke;
|
||||||
|
|
||||||
#define DATAPACK_INITIAL_SIZE 64
|
#define DATAPACK_INITIAL_SIZE 64
|
||||||
|
|
||||||
@ -47,6 +51,25 @@ CDataPack::~CDataPack()
|
|||||||
free(m_pBase);
|
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()
|
void CDataPack::Initialize()
|
||||||
{
|
{
|
||||||
m_curptr = m_pBase;
|
m_curptr = m_pBase;
|
||||||
@ -331,4 +354,4 @@ cell_t CDataPack::ReadFunction() const
|
|||||||
cell_t val = *reinterpret_cast<cell_t *>(m_curptr);
|
cell_t val = *reinterpret_cast<cell_t *>(m_curptr);
|
||||||
m_curptr += sizeof(cell_t);
|
m_curptr += sizeof(cell_t);
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
@ -41,6 +41,9 @@ class CDataPack : public IDataPack
|
|||||||
public:
|
public:
|
||||||
CDataPack();
|
CDataPack();
|
||||||
~CDataPack();
|
~CDataPack();
|
||||||
|
|
||||||
|
static IDataPack *New();
|
||||||
|
static void Free(IDataPack *pack);
|
||||||
public: //IDataReader
|
public: //IDataReader
|
||||||
void Reset() const;
|
void Reset() const;
|
||||||
size_t GetPosition() const;
|
size_t GetPosition() const;
|
@ -54,6 +54,7 @@
|
|||||||
#include "sprintf.h"
|
#include "sprintf.h"
|
||||||
#include "LibrarySys.h"
|
#include "LibrarySys.h"
|
||||||
#include "RootConsoleMenu.h"
|
#include "RootConsoleMenu.h"
|
||||||
|
#include "CDataPack.h"
|
||||||
#include <bridge/include/BridgeAPI.h>
|
#include <bridge/include/BridgeAPI.h>
|
||||||
#include <bridge/include/IProviderCallbacks.h>
|
#include <bridge/include/IProviderCallbacks.h>
|
||||||
|
|
||||||
@ -158,6 +159,8 @@ static sm_logic_t logic =
|
|||||||
DumpAdminCache,
|
DumpAdminCache,
|
||||||
RegisterProfiler,
|
RegisterProfiler,
|
||||||
OnRootCommand,
|
OnRootCommand,
|
||||||
|
CDataPack::New,
|
||||||
|
CDataPack::Free,
|
||||||
&g_PluginSys,
|
&g_PluginSys,
|
||||||
&g_ShareSys,
|
&g_ShareSys,
|
||||||
&g_Extensions,
|
&g_Extensions,
|
||||||
|
@ -32,12 +32,7 @@
|
|||||||
#include "common_logic.h"
|
#include "common_logic.h"
|
||||||
#include <IHandleSys.h>
|
#include <IHandleSys.h>
|
||||||
#include <ISourceMod.h>
|
#include <ISourceMod.h>
|
||||||
|
#include "CDataPack.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"
|
|
||||||
|
|
||||||
HandleType_t g_DataPackType;
|
HandleType_t g_DataPackType;
|
||||||
|
|
||||||
@ -66,7 +61,7 @@ public:
|
|||||||
}
|
}
|
||||||
void OnHandleDestroy(HandleType_t type, void *object)
|
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)
|
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)
|
static cell_t smn_CreateDataPack(IPluginContext *pContext, const cell_t *params)
|
||||||
{
|
{
|
||||||
IDataPack *pDataPack = g_pSM->CreateDataPack();
|
IDataPack *pDataPack = CDataPack::New();
|
||||||
|
|
||||||
if (!pDataPack)
|
if (!pDataPack)
|
||||||
{
|
{
|
||||||
|
@ -515,16 +515,6 @@ void SourceModBase::ShutdownServices()
|
|||||||
pBase = pBase->m_pGlobalClassNext;
|
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();
|
sCoreProviderImpl.ShutdownHooks();
|
||||||
|
|
||||||
/* Notify! */
|
/* Notify! */
|
||||||
@ -624,26 +614,16 @@ unsigned int SourceModBase::GetGlobalTarget() const
|
|||||||
|
|
||||||
IDataPack *SourceModBase::CreateDataPack()
|
IDataPack *SourceModBase::CreateDataPack()
|
||||||
{
|
{
|
||||||
CDataPack *pack;
|
return logicore.CreateDataPack();
|
||||||
if (m_freepacks.empty())
|
|
||||||
{
|
|
||||||
pack = new CDataPack;
|
|
||||||
} else {
|
|
||||||
pack = m_freepacks.front();
|
|
||||||
m_freepacks.pop();
|
|
||||||
pack->Initialize();
|
|
||||||
}
|
|
||||||
return pack;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SourceModBase::FreeDataPack(IDataPack *pack)
|
void SourceModBase::FreeDataPack(IDataPack *pack)
|
||||||
{
|
{
|
||||||
m_freepacks.push(static_cast<CDataPack *>(pack));
|
logicore.FreeDataPack(pack);
|
||||||
}
|
}
|
||||||
|
|
||||||
Handle_t SourceModBase::GetDataPackHandleType(bool readonly)
|
Handle_t SourceModBase::GetDataPackHandleType(bool readonly)
|
||||||
{
|
{
|
||||||
//:TODO:
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,7 +36,6 @@
|
|||||||
#include <ISourceMod.h>
|
#include <ISourceMod.h>
|
||||||
#include <sh_stack.h>
|
#include <sh_stack.h>
|
||||||
#include <sh_vector.h>
|
#include <sh_vector.h>
|
||||||
#include "CDataPack.h"
|
|
||||||
|
|
||||||
using namespace SourceHook;
|
using namespace SourceHook;
|
||||||
|
|
||||||
@ -139,7 +138,6 @@ public: // ISourceMod
|
|||||||
private:
|
private:
|
||||||
void ShutdownServices();
|
void ShutdownServices();
|
||||||
private:
|
private:
|
||||||
CStack<CDataPack *> m_freepacks;
|
|
||||||
char m_SMBaseDir[PLATFORM_MAX_PATH];
|
char m_SMBaseDir[PLATFORM_MAX_PATH];
|
||||||
char m_SMRelDir[PLATFORM_MAX_PATH];
|
char m_SMRelDir[PLATFORM_MAX_PATH];
|
||||||
char m_ModDir[32];
|
char m_ModDir[32];
|
||||||
|
Loading…
Reference in New Issue
Block a user