Raised This Month: $32 Target: $400
 8% 

New Module API


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
BAILOPAN
Join Date: Jan 2004
Old 05-03-2004 , 17:56   New Module API
Reply With Quote #1

(moving this post from Dev Forum now that 0.20 is further along)
The new module API by PM OnoTo is, for the most part, finished.
I'll write a little tutorial here on the changes, what it means for developers, what it means for the end user, and how to convert and/or write new modules. I'll eventually copy this post back into Module section.

What it means for End Users
Less memory leaks, better performance, more compatibility.

What it means for developers
Easier to make modules quickly. Unified SDK and interface.

The technical details
The new module API was originally a simple system of making it easier to forward AMX engine pointers back into modules, however, XAD started a discussion which led to "FakeMeta", PM's creation which routes module metamod calls back into metamod from the amxx core. FakeMeta eliminates many problems with AMX 0.9.8's module API and totally changes how modules are linked. Combined with the new "module config" format of creating modules, this makes modules easy to develop and much faster.

Furthermore, there is a new API for handling public forwards to remove per-module messiness or call lists. Lastly, there is an easier interface for real numbers that also adds 64bit compability.

The basics
If you look in CVS, there is now an SDK folder in the amxmodx directory. This contains "moduleconfig.h", "amxxmodule.cpp", and "amxxmodule.h". You must compile amxxmodule.cpp into your module - but you only should include "amxxmodule.h". Changing amxxmodule.* is not necessary. The current AMXx SDK version goes by the the CVS commits - the latest version is 0.2.3. Make sure to keep up to date.

The biggest difference is that to enable features, you simply uncomment preprocessor directives. For example, the AMX 0.9.8 API required this:

Code:
meta_api.cpp:
C_DLLEXPORT int AMX_Attach(pfnamx_engine_g* amxeng,pfnmodule_engine_g* meng) {
	if (!gpMetaGlobals)
		REPORT_ERROR( 1 , "[MODULE] Module is not attached to MetaMod\n");
	ADD_AMXNATIVES( &module_info , module_Natives);
	return 1;
}

exports.def:
EXPORTS
	GetEngineFunctions_Post @ 1 ; 
	GetEntityAPI2 @ 2 ; 
	GetEntityAPI2_Post @ 3 ; 
	GiveFnptrsToDll = GiveFnptrsToDll@8 @ 4 ; 
	GiveFnptrsToDll@8 @ 5 ; 
	AMX_Query @ 6 ;
et cetera... with the new API, you simply uncomment
Code:
#define FN_AMXX_ATTACH OnAmxxAttach
And add this to the source:
Code:
void OnAmxxAttach()
{
	MF_AddNatives(module_Natives);
}
Similarly, you no longer need to supply any .def file or metamod hooks. The 0.20 module API and FakeMeta will take care of this for you - simply uncomment the appropriate hook in moduleconfig.h.

You also no longer need to export metamod or amx engine pointers or module/plugin info, this is defined in moduleconfig.h.

The 0.20 API is also capable of detecting memory leaks in your module - if amxx_mm is compiled with MMGR support it will overload the new and delete operators and log statistics for you automatically.

Furthermore, it is now possible to register forwards instead of finding and executing them each time (or making an Amx Call List). To do this, hook the OnPluginsLoaded call in moduleconfig and register your forwards there.
Code:
int pfnTouchId = MF_RegisterForward("pfnTouch", ET_STOP, FP_CELL, FP_CELL, FP_DONE);
Then when I want to execute this forward:
Code:
MF_Execute(pfnTouchId, ENTINDEX(pToucher), ENTINDEX(pTouched).
Lastly, another important change is one for 64bit compatibility. This is a _must_ for converting floats to and from cells.
amx_ctof() is Cell to REAL
amx_ftoc() is REAL to Cell
That will also remove the old casting mess.

I hope this helps. If there's any questions be sure to post them in this thread, I will lock it once 0.20 comes out and then general discussion about it can take place. Since this is PM's brainchild, I'm sure he'll have things to correct here, to add/fix/comment on et cetera.

Eventually, the documentation will include a full list and explanation of the various forwards supplied from the core module API. For now, read the sources
(all modules except csstats are converted to the 0.20 api)
__________________
egg
BAILOPAN is offline
SidLuke
Senior Member
Join Date: Mar 2004
Location: Poland, Chrzanow
Old 05-03-2004 , 20:51   Re: New Module API
Reply With Quote #2

Quote:
Originally Posted by BAILOPAN
Code:
int pfnTouchId = MF_RegisterForward("pfnTouch", FP_CELL, FP_CELL);
Then when I want to execute this forward:
Code:
MF_Execute(pfnTouchId, ENTINDEX(pToucher), ENTINDEX(pTouched).
I was playing with it few hours later . I've got some problem with forwards.
Reading amxxmodule.h file MF_RegisterForward should looks like :
Code:
iFDamage = MF_RegisterForward("client_damage",ET_IGNORE,FP_CELL,FP_CELL,FP_CELL,FP_CELL,FP_CELL,FP_CELL,FP_DONE); 
// 6 params:att,vic,dmg,wpn,aim,ta // int all
forward function is called but there is something wrong with data

I do something wrong or maybe I've got old amxx_mm.dll file.
Could you post the latest amxx_mm.dll file ?
SidLuke is offline
Send a message via AIM to SidLuke Send a message via MSN to SidLuke
QwertyAccess
Veteran Member
Join Date: Feb 2004
Location: Enjiru Layer
Old 05-04-2004 , 04:47   Re: New Module API
Reply With Quote #3

Quote:
The 0.20 API is also capable of detecting memory leaks in your module - if amxx_mm is compiled with MMGR support it will overload the new and delete operators and log statistics for you automatically.
Yay
__________________
QwertyAccess is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 15:53.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode