User:Psycommando/Macros reference: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
No edit summary
No edit summary
 
(7 intermediate revisions by the same user not shown)
Line 1: Line 1:
== Intro ==
== Intro ==


Prototype for a complete list of macros links(in the wiki) and infos. All Macros are listed in different categories, and divided in two basic groups, depending if they contain declaration code or contain definition code.
Prototype for a complete list of macros links(in the wiki) and infos. All Macros are listed in different categories, and divided in groups.
 


== Warning on macros ==
== Warning on macros ==
For those unfamiliar with macros, I must warn you that macros are <strong>EVIL</strong>. They are basically the equivalent of doing a search and replace at compile time, therefore never ever put an operation as a macro parameter!!! This page [http://www.parashift.com/c++-faq-lite/inline-functions.html#faq-9.5 C++ Faq Lite] describe most of the problem. Be sure to check evil# 1-2-3-4.
For those unfamiliar with macros, I must warn you that macros are <strong>EVIL</strong>. They are basically the equivalent of doing a search and replace at compile time, therefore never put an operation as a macro parameter, it will do the operations as many time as the parameter is used in the macro definition!!! This page [http://www.parashift.com/c++-faq-lite/inline-functions.html#faq-9.5 C++ Faq Lite] describe most of the problem. Be sure to check evil# 1-2-3-4.
 


== Data map ==
== Data map ==
Line 19: Line 17:
=== IMPLEMENT_NETWORKCLASS_ALIASED ===
=== IMPLEMENT_NETWORKCLASS_ALIASED ===


<ul>
 
<li>Declaration : ''IMPLEMENT_NETWORKCLASS_ALIASED(className, dataTable)'' </li>
*Call : IMPLEMENT_NETWORKCLASS_ALIASED( className, dataTable )
<li>Code : <i>From ..\game\shared\predictable_entity.h</i>
*Declaration : ''From ..\game\shared\predictable_entity.h''
<pre>
<pre>
#define IMPLEMENT_NETWORKCLASS_ALIASED(className, dataTable) \
#define IMPLEMENT_NETWORKCLASS_ALIASED(className, dataTable) \
IMPLEMENT_CLIENTCLASS( C_##className, dataTable, C##className )</pre>
IMPLEMENT_CLIENTCLASS( C_##className, dataTable, C##className )</pre>
</li>
<li>Description :
</li>
</ul>


*Description :
*Example :


== Misc ==
== Misc ==


=== Declaration : ===
=== STUB_WEAPON_CLASS ===


=== Definition :===
*Call : STUB_WEAPON_CLASS( entityName, className, baseClassName )
*Required Include : c_weapon__stubs.h
*Description : This macro is very simple, it writes a very basic client class for the specified weapon. Most of the weapon stub classes generated by this macro can be found in ''..\src\game\client\hl2\c_weapon__stubs_hl2.cpp'', but you should note that you can use this macro in any client-side .cpp file, of course you need to include "c_weapon__stubs.h".
*Macro Definition :
<source lang=cpp> #define STUB_WEAPON_CLASS( entityName, className, baseClassName ) \
class C_##className## : public baseClassName \
{ \
DECLARE_CLASS( C_##className##, baseClassName );                        \
        public:                                         \
DECLARE_PREDICTABLE(); \
DECLARE_CLIENTCLASS(); \
        C_##className() {};                                                    \
        private:                                                                        \
C_##className( const C_##className & ); \
}; \
STUB_WEAPON_CLASS_IMPLEMENT( entityName, C_##className ); \
IMPLEMENT_CLIENTCLASS_DT( C_##className, DT_##className, C##className ) \
END_RECV_TABLE() </source>
*Example : <source lang=cpp> STUB_WEAPON_CLASS( weapon_crowbar, WeaponCrowbar, C_BaseHLBludgeonWeapon ); </source>
 
 
=== REGISTER_GAMERULES_CLASS ===
*Call : REGISTER_GAMERULES_CLASS( className )
*Required Include : ..\src\game\shared\gamerules_register.h
*Description : Add a new gamerule class to the register?(...Need research...)
*Definition :  
<source lang=cpp> #define REGISTER_GAMERULES_CLASS( className ) \
void __CreateGameRules_##className() { new className; } \
static CGameRulesRegister __g_GameRulesRegister_##className( #className, __CreateGameRules_##className );
</source>
*Example :

Latest revision as of 18:31, 30 March 2010

Intro

Prototype for a complete list of macros links(in the wiki) and infos. All Macros are listed in different categories, and divided in groups.

Warning on macros

For those unfamiliar with macros, I must warn you that macros are EVIL. They are basically the equivalent of doing a search and replace at compile time, therefore never put an operation as a macro parameter, it will do the operations as many time as the parameter is used in the macro definition!!! This page C++ Faq Lite describe most of the problem. Be sure to check evil# 1-2-3-4.

Data map

Declaration :

Definition :

Network

IMPLEMENT_NETWORKCLASS_ALIASED

  • Call : IMPLEMENT_NETWORKCLASS_ALIASED( className, dataTable )
  • Declaration : From ..\game\shared\predictable_entity.h
#define IMPLEMENT_NETWORKCLASS_ALIASED(className, dataTable)			\
	IMPLEMENT_CLIENTCLASS( C_##className, dataTable, C##className )
  • Description :
  • Example :

Misc

STUB_WEAPON_CLASS

  • Call : STUB_WEAPON_CLASS( entityName, className, baseClassName )
  • Required Include : c_weapon__stubs.h
  • Description : This macro is very simple, it writes a very basic client class for the specified weapon. Most of the weapon stub classes generated by this macro can be found in ..\src\game\client\hl2\c_weapon__stubs_hl2.cpp, but you should note that you can use this macro in any client-side .cpp file, of course you need to include "c_weapon__stubs.h".
  • Macro Definition :
 #define STUB_WEAPON_CLASS( entityName, className, baseClassName )	\
	class C_##className## : public baseClassName					\
	{										\
		DECLARE_CLASS( C_##className##, baseClassName );                        \ 
        public:					                                        \
		DECLARE_PREDICTABLE();							\
		DECLARE_CLIENTCLASS();							\
	        C_##className() {};                                                     \ 
        private:                                                                        \
		C_##className( const C_##className & );					\
	};										\
	STUB_WEAPON_CLASS_IMPLEMENT( entityName, C_##className );		\
	IMPLEMENT_CLIENTCLASS_DT( C_##className, DT_##className, C##className )	\
	END_RECV_TABLE()
  • Example :
     STUB_WEAPON_CLASS( weapon_crowbar, WeaponCrowbar, C_BaseHLBludgeonWeapon );
    


REGISTER_GAMERULES_CLASS

  • Call : REGISTER_GAMERULES_CLASS( className )
  • Required Include : ..\src\game\shared\gamerules_register.h
  • Description : Add a new gamerule class to the register?(...Need research...)
  • Definition :
 #define REGISTER_GAMERULES_CLASS( className ) \
	void __CreateGameRules_##className() { new className; } \
	static CGameRulesRegister __g_GameRulesRegister_##className( #className, __CreateGameRules_##className );
  • Example :