greatly optimized the process of mapping plugin natives from Core
--HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401388
This commit is contained in:
		
							parent
							
								
									08ae85bdb3
								
							
						
					
					
						commit
						f145178fc0
					
				@ -769,6 +769,7 @@ CPluginManager::CPluginManager()
 | 
				
			|||||||
	m_AllPluginsLoaded = false;
 | 
						m_AllPluginsLoaded = false;
 | 
				
			||||||
	m_MyIdent = NULL;
 | 
						m_MyIdent = NULL;
 | 
				
			||||||
	m_pNativeLookup = sm_trie_create();
 | 
						m_pNativeLookup = sm_trie_create();
 | 
				
			||||||
 | 
						m_pCoreNatives = sm_trie_create();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
CPluginManager::~CPluginManager()
 | 
					CPluginManager::~CPluginManager()
 | 
				
			||||||
@ -780,6 +781,7 @@ CPluginManager::~CPluginManager()
 | 
				
			|||||||
	 */
 | 
						 */
 | 
				
			||||||
	sm_trie_destroy(m_LoadLookup);
 | 
						sm_trie_destroy(m_LoadLookup);
 | 
				
			||||||
	sm_trie_destroy(m_pNativeLookup);
 | 
						sm_trie_destroy(m_pNativeLookup);
 | 
				
			||||||
 | 
						sm_trie_destroy(m_pCoreNatives);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	CStack<CPluginManager::CPluginIterator *>::iterator iter;
 | 
						CStack<CPluginManager::CPluginIterator *>::iterator iter;
 | 
				
			||||||
	for (iter=m_iters.begin(); iter!=m_iters.end(); iter++)
 | 
						for (iter=m_iters.begin(); iter!=m_iters.end(); iter++)
 | 
				
			||||||
@ -1325,18 +1327,28 @@ bool CPluginManager::RunSecondPass(CPlugin *pPlugin, char *error, size_t maxleng
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void CPluginManager::AddCoreNativesToPlugin(CPlugin *pPlugin)
 | 
					void CPluginManager::AddCoreNativesToPlugin(CPlugin *pPlugin)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	List<sp_nativeinfo_t *>::iterator iter;
 | 
						IPluginContext *pContext = pPlugin->GetBaseContext();
 | 
				
			||||||
 | 
						sp_context_t *ctx = pContext->GetContext();
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	for (iter=m_natives.begin(); iter!=m_natives.end(); iter++)
 | 
					
 | 
				
			||||||
 | 
						uint32_t natives = pContext->GetNativesNum();
 | 
				
			||||||
 | 
						sp_native_t *native;
 | 
				
			||||||
 | 
						SPVM_NATIVE_FUNC pfn;
 | 
				
			||||||
 | 
						for (uint32_t i=0; i<natives; i++)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		sp_nativeinfo_t *natives = (*iter);
 | 
							if (pContext->GetNativeByIndex(i, &native) != SP_ERROR_NONE)
 | 
				
			||||||
		IPluginContext *ctx = pPlugin->GetBaseContext();
 | 
					 | 
				
			||||||
		unsigned int i=0;
 | 
					 | 
				
			||||||
		/* Attempt to bind every native! */
 | 
					 | 
				
			||||||
		while (natives[i].func != NULL)
 | 
					 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			ctx->BindNative(&natives[i++]);
 | 
								continue;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							if (native->status == SP_NATIVE_BOUND)
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								continue;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if (!sm_trie_retrieve(m_pCoreNatives, native->name, (void **)&pfn))
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								continue;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							pContext->BindNativeToIndex(i, pfn);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -1854,7 +1866,10 @@ void CPluginManager::OnHandleDestroy(HandleType_t type, void *object)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void CPluginManager::RegisterNativesFromCore(sp_nativeinfo_t *natives)
 | 
					void CPluginManager::RegisterNativesFromCore(sp_nativeinfo_t *natives)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	m_natives.push_back(natives);
 | 
						for (unsigned int i = 0; natives[i].func != NULL; i++)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							sm_trie_insert(m_pCoreNatives, natives[i].name, natives[i].func);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
IPlugin *CPluginManager::PluginFromHandle(Handle_t handle, HandleError *err)
 | 
					IPlugin *CPluginManager::PluginFromHandle(Handle_t handle, HandleError *err)
 | 
				
			||||||
 | 
				
			|||||||
@ -485,12 +485,12 @@ private:
 | 
				
			|||||||
private:
 | 
					private:
 | 
				
			||||||
	List<IPluginsListener *> m_listeners;
 | 
						List<IPluginsListener *> m_listeners;
 | 
				
			||||||
	List<CPlugin *> m_plugins;
 | 
						List<CPlugin *> m_plugins;
 | 
				
			||||||
	List<sp_nativeinfo_t *> m_natives;
 | 
					 | 
				
			||||||
	CStack<CPluginManager::CPluginIterator *> m_iters;
 | 
						CStack<CPluginManager::CPluginIterator *> m_iters;
 | 
				
			||||||
	CPluginInfoDatabase m_PluginInfo;
 | 
						CPluginInfoDatabase m_PluginInfo;
 | 
				
			||||||
	Trie *m_LoadLookup;
 | 
						Trie *m_LoadLookup;
 | 
				
			||||||
	bool m_AllPluginsLoaded;
 | 
						bool m_AllPluginsLoaded;
 | 
				
			||||||
	IdentityToken_t *m_MyIdent;
 | 
						IdentityToken_t *m_MyIdent;
 | 
				
			||||||
 | 
						Trie *m_pCoreNatives;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Dynamic native stuff */
 | 
						/* Dynamic native stuff */
 | 
				
			||||||
	List<FakeNative *> m_Natives;
 | 
						List<FakeNative *> m_Natives;
 | 
				
			||||||
 | 
				
			|||||||
@ -642,6 +642,22 @@ int BaseContext::BindNative(const sp_nativeinfo_t *native)
 | 
				
			|||||||
	return SP_ERROR_NONE;
 | 
						return SP_ERROR_NONE;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int BaseContext::BindNativeToIndex(uint32_t index, SPVM_NATIVE_FUNC native)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						int err;
 | 
				
			||||||
 | 
						sp_native_t *native;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if ((err = GetNativeByIndex(index, &native)) != SP_ERROR_NONE)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							return err;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						ctx->natives[index].pfn = native;
 | 
				
			||||||
 | 
						ctx->natives[index].status = SP_NATIVE_BOUND;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return SP_ERROR_NONE;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int BaseContext::BindNativeToAny(SPVM_NATIVE_FUNC native)
 | 
					int BaseContext::BindNativeToAny(SPVM_NATIVE_FUNC native)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	uint32_t nativesnum, i;
 | 
						uint32_t nativesnum, i;
 | 
				
			||||||
 | 
				
			|||||||
@ -89,6 +89,7 @@ namespace SourcePawn
 | 
				
			|||||||
		cell_t *GetNullRef(SP_NULL_TYPE type);
 | 
							cell_t *GetNullRef(SP_NULL_TYPE type);
 | 
				
			||||||
		int LocalToStringNULL(cell_t local_addr, char **addr);
 | 
							int LocalToStringNULL(cell_t local_addr, char **addr);
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
							int BindNativeToIndex(uint32_t index, SPVM_NATIVE_FUNC native);
 | 
				
			||||||
	public: //IPluginDebugInfo
 | 
						public: //IPluginDebugInfo
 | 
				
			||||||
		int LookupFile(ucell_t addr, const char **filename);
 | 
							int LookupFile(ucell_t addr, const char **filename);
 | 
				
			||||||
		int LookupFunction(ucell_t addr, const char **name);
 | 
							int LookupFunction(ucell_t addr, const char **name);
 | 
				
			||||||
 | 
				
			|||||||
@ -44,7 +44,7 @@
 | 
				
			|||||||
#define SOURCEPAWN_ENGINE_API_VERSION	1
 | 
					#define SOURCEPAWN_ENGINE_API_VERSION	1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/** SourcePawn VM API Version */
 | 
					/** SourcePawn VM API Version */
 | 
				
			||||||
#define SOURCEPAWN_VM_API_VERSION		4
 | 
					#define SOURCEPAWN_VM_API_VERSION		5
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if !defined SOURCEMOD_BUILD
 | 
					#if !defined SOURCEMOD_BUILD
 | 
				
			||||||
#define SOURCEMOD_BUILD
 | 
					#define SOURCEMOD_BUILD
 | 
				
			||||||
@ -591,6 +591,14 @@ namespace SourcePawn
 | 
				
			|||||||
		 */
 | 
							 */
 | 
				
			||||||
		virtual int LocalToStringNULL(cell_t local_addr, char **addr) =0;
 | 
							virtual int LocalToStringNULL(cell_t local_addr, char **addr) =0;
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							/**
 | 
				
			||||||
 | 
							 * @brief Binds a single native to a given native index.
 | 
				
			||||||
 | 
							 *
 | 
				
			||||||
 | 
							 * @param index			Index to bind at.
 | 
				
			||||||
 | 
							 * @param native		Native function to bind.
 | 
				
			||||||
 | 
							 */
 | 
				
			||||||
 | 
							virtual int BindNativeToIndex(uint32_t index, SPVM_NATIVE_FUNC native) =0;
 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user