def ParseEditablePanel(self, mb): focusnavgroup = mb.class_('FocusNavGroup') buildgroup = mb.class_('BuildGroup') excludetypes = [ pointer_t(const_t(declarated_t(focusnavgroup))), pointer_t(declarated_t(focusnavgroup)), reference_t(declarated_t(focusnavgroup)), pointer_t(const_t(declarated_t(buildgroup))), pointer_t(declarated_t(buildgroup)), reference_t(declarated_t(buildgroup)), ] mb.calldefs(calldef_withtypes(excludetypes), allow_empty=True).exclude() mb.mem_funs( 'GetDialogVariables' ).call_policies = call_policies.return_value_policy(call_policies.return_by_value)
def _get_setter_type(self): return declarations.free_function_type_t( return_type=declarations.void_t(), arguments_types=[ declarations.reference_t(self._get_class_inst_type()), self._get_exported_var_type() ])
def __init__( self, function ): sealed_fun_controller_t.__init__( self, function ) inst_arg_type = declarations.declarated_t( self.function.parent ) if self.function.has_const: inst_arg_type = declarations.const_t( inst_arg_type ) inst_arg_type = declarations.reference_t( inst_arg_type ) self.__inst_arg = declarations.argument_t( name=self.register_variable_name( 'inst' ) , decl_type=inst_arg_type )
def __init__( self, function ): sealed_fun_controller_t.__init__( self, function ) inst_arg_type = declarations.declarated_t( self.function.parent ) if self.function.has_const: inst_arg_type = declarations.const_t( inst_arg_type ) inst_arg_type = declarations.reference_t( inst_arg_type ) self.__inst_arg = declarations.argument_t( name=self.register_variable_name( 'inst' ) , type=inst_arg_type )
def customize(self, mb): mb.global_ns.exclude() mb.free_function('create_randome_rationals').include() xxx = mb.class_('XXX') xxx.include() xxx_ref = declarations.reference_t( declarations.const_t(declarations.declarated_t(xxx))) oper = mb.global_ns.free_operator('<<', arg_types=[None, xxx_ref]) oper.include() mb.class_('YYY').include() rational = mb.class_('rational<long>') rational.include() rational.alias = "pyrational" #Test query api. #artificial declarations come back #rational.operator( '=' ) #rational.operator( name='operator=' ) #rational.operator( symbol='=' ) rational.operators('=') rational.operators(name='operator=') rational.operators(symbol='=') #artificial declarations come back #rational.member_operator( '=' ) #rational.member_operator( name='operator=' ) #rational.member_operator( symbol='=' ) rational.member_operators('=') rational.member_operators(name='operator=') rational.member_operators(symbol='=') mb.global_ns.free_operators('<<') mb.global_ns.free_operators(name='operator<<') mb.global_ns.free_operators(symbol='<<') r_assign = rational.calldef('assign', recursive=False) r_assign.call_policies = call_policies.return_self() foperators = mb.free_operators( lambda decl: 'rational<long>' in decl.decl_string) foperators.include() bad_rational = mb.class_('bad_rational') bad_rational.include() mb.namespace('Geometry').include() mb.namespace('Geometry').class_('VecOfInts').exclude() mb.namespace('Geometry2').include()
def wrap_all_osg_referenced_noderive(self, namespace): # Identify all classes derived from osg::Referenced, # and set their boost::python held_type to "osg::ref_ptr<class>" osg = self.mb.namespace("osg") referenced = osg.class_("Referenced") referenced_derived = DerivedClasses(referenced) referenced_derived.include_module(namespace) copyop = osg.class_("CopyOp") # We are interested in constructors that take an argument of type "const osg::CopyOp&"" copyop_arg_t = declarations.reference_t(declarations.const_t(declarations.declarated_t(copyop))) for cls in referenced_derived: expose_nonoverridable_ref_ptr_class(cls) # These copy constructors consistently cause trouble for ctor in cls.constructors(arg_types=[None, copyop_arg_t], allow_empty=True): ctor.exclude()
def customize( self, mb ): mb.global_ns.exclude() mb.free_function( 'create_randome_rationals' ).include() xxx = mb.class_( 'XXX' ) xxx.include() xxx_ref = declarations.reference_t( declarations.const_t( declarations.declarated_t( xxx ) ) ) oper = mb.global_ns.free_operator( '<<', arg_types=[None, xxx_ref] ) oper.include() mb.class_( 'YYY' ).include() rational = mb.class_('rational<long>') rational.include() rational.alias = "pyrational" #Test query api. #artificial declarations come back #rational.operator( '=' ) #rational.operator( name='operator=' ) #rational.operator( symbol='=' ) rational.operators( '=' ) rational.operators( name='operator=' ) rational.operators( symbol='=' ) #artificial declarations come back #rational.member_operator( '=' ) #rational.member_operator( name='operator=' ) #rational.member_operator( symbol='=' ) rational.member_operators( '=' ) rational.member_operators( name='operator=' ) rational.member_operators( symbol='=' ) mb.global_ns.free_operators( '<<' ) mb.global_ns.free_operators( name='operator<<' ) mb.global_ns.free_operators( symbol='<<' ) r_assign = rational.calldef( 'assign', recursive=False ) r_assign.call_policies = call_policies.return_self() foperators = mb.free_operators( lambda decl: 'rational<long>' in decl.decl_string ) foperators.include() bad_rational = mb.class_('bad_rational' ) bad_rational.include() mb.namespace( 'Geometry' ).include() mb.namespace( 'Geometry' ).class_( 'VecOfInts' ).exclude() mb.namespace( 'Geometry2' ).include()
def wrap_all_osg_referenced_noderive(self, namespace): # Identify all classes derived from osg::Referenced, # and set their boost::python held_type to "osg::ref_ptr<class>" osg = self.mb.namespace("osg") referenced = osg.class_("Referenced") referenced_derived = DerivedClasses(referenced) referenced_derived.include_module(namespace) copyop = osg.class_("CopyOp") # We are interested in constructors that take an argument of type "const osg::CopyOp&"" copyop_arg_t = declarations.reference_t( declarations.const_t(declarations.declarated_t(copyop))) for cls in referenced_derived: expose_nonoverridable_ref_ptr_class(cls) # These copy constructors consistently cause trouble for ctor in cls.constructors(arg_types=[None, copyop_arg_t], allow_empty=True): ctor.exclude()
def wrap_one_call_policy(fn): rt = fn.return_type if fn.return_type.decl_string == "char const *": return # use default for strings if fn.return_type.decl_string == "char *": return # use default for strings elif fn.return_type.decl_string == "void *": return # use default for void pointers elif fn.return_type.decl_string == "::GLvoid const *": return # use default for void pointers parent_ref = declarations.reference_t(declarations.declarated_t(fn.parent)) if declarations.is_reference(rt): # Need type without reference for next type checks nonref_rt = rt.base if declarations.is_arithmetic(nonref_rt) or declarations.is_enum( nonref_rt): # returning const& double can cause compile trouble if return_internal_reference is used if declarations.is_const(nonref_rt): fn.call_policies = return_value_policy(copy_const_reference) return # int& might need to be copy_non_const_reference... else: fn.call_policies = return_value_policy( copy_non_const_reference) return # Const string references should be copied to python strings if declarations.is_std_string(nonref_rt) and declarations.is_const( nonref_rt): fn.call_policies = return_value_policy(copy_const_reference) return # Returning reference to this same class looks like return_self() [does this always work?] if declarations.is_same(parent_ref, rt): fn.call_policies = return_self() return elif declarations.is_pointer(rt): # Clone methods if re.search(r'^clone', fn.name): fn.call_policies = return_value_policy(reference_existing_object) return else: return # Everything else probably returns an internal reference fn.call_policies = return_internal_reference() return
def customize(self, mb): mb.global_ns.exclude() xxx = mb.class_("XXX") xxx.include() xxx_ref = declarations.reference_t(declarations.const_t(declarations.declarated_t(xxx))) oper = mb.global_ns.free_operator("<<", arg_types=[None, xxx_ref]) oper.include() mb.class_("YYY").include() rational = mb.class_("rational<long>") rational.include() rational.alias = "pyrational" # Test query api. # artificial declarations come back # rational.operator( '=' ) # rational.operator( name='operator=' ) # rational.operator( symbol='=' ) rational.operators("=") rational.operators(name="operator=") rational.operators(symbol="=") # artificial declarations come back # rational.member_operator( '=' ) # rational.member_operator( name='operator=' ) # rational.member_operator( symbol='=' ) rational.member_operators("=") rational.member_operators(name="operator=") rational.member_operators(symbol="=") mb.global_ns.free_operators("<<") mb.global_ns.free_operators(name="operator<<") mb.global_ns.free_operators(symbol="<<") r_assign = rational.calldef("assign", recursive=False) r_assign.call_policies = call_policies.return_self() foperators = mb.free_operators(lambda decl: "rational<long>" in decl.decl_string) foperators.include() bad_rational = mb.class_("bad_rational") bad_rational.include()
def wrap_one_call_policy(fn): rt = fn.return_type if fn.return_type.decl_string == "char const *": return # use default for strings if fn.return_type.decl_string == "char *": return # use default for strings elif fn.return_type.decl_string == "void *": return # use default for void pointers elif fn.return_type.decl_string == "::GLvoid const *": return # use default for void pointers parent_ref = declarations.reference_t(declarations.declarated_t(fn.parent)) if declarations.is_reference(rt): # Need type without reference for next type checks nonref_rt = rt.base if declarations.is_arithmetic(nonref_rt) or declarations.is_enum(nonref_rt): # returning const& double can cause compile trouble if return_internal_reference is used if declarations.is_const(nonref_rt): fn.call_policies = return_value_policy(copy_const_reference) return # int& might need to be copy_non_const_reference... else: fn.call_policies = return_value_policy(copy_non_const_reference) return # Const string references should be copied to python strings if declarations.is_std_string(nonref_rt) and declarations.is_const(nonref_rt): fn.call_policies = return_value_policy(copy_const_reference) return # Returning reference to this same class looks like return_self() [does this always work?] if declarations.is_same(parent_ref, rt): fn.call_policies = return_self() return elif declarations.is_pointer(rt): # Clone methods if re.search(r'^clone', fn.name): fn.call_policies = return_value_policy(reference_existing_object) return else: return # Everything else probably returns an internal reference fn.call_policies = return_internal_reference() return
def ParsePanels(self, mb): # Panels cls = mb.class_('DeadPanel') cls.include() cls.mem_funs('NonZero', allow_empty=True).rename('__nonzero__') cls.mem_funs('Bool', allow_empty=True).rename('__bool__') # For each panel sub class we take some default actions for cls_name in self.panel_cls_list: cls = mb.class_(cls_name) # Include everything by default cls.include() cls.no_init = False # Be selective about we need to override cls.mem_funs().virtuality = 'not virtual' #if cls_name not in ['AnimationController', 'Frame', 'ScrollBar', 'CBaseMinimap']: # cls.mem_funs( matchers.access_type_matcher_t( 'protected' ) ).exclude() # By default exclude any subclass. These classes are likely controlled intern by the panel if cls.classes(allow_empty=True): cls.classes().exclude() self.AddVGUIConverter(mb, cls_name, self.novguilib, containsabstract=False) # # Add custom wrappers for functions who take keyvalues as input if self.novguilib: # No access to source code, so need to add message stuff for python here. cls.add_wrapper_code('virtual void OnMessage(const KeyValues *params, VPANEL fromPanel) {\r\n' + ' if( Panel_DispatchMessage( m_PyMessageMap, params, fromPanel ) )\r\n' + ' return;\r\n' + ' Panel::OnMessage(params, fromPanel);\r\n' + '}\r\n' + \ '\r\n' + \ 'void RegMessageMethod( const char *message, boost::python::object method, int numParams=0, \r\n' + \ ' const char *nameFirstParam="", int typeFirstParam=DATATYPE_VOID, \r\n' + \ ' const char *nameSecondParam="", int typeSecondParam=DATATYPE_VOID ) { \r\n' + \ ' py_message_entry_t entry;\r\n' + \ ' entry.method = method;\r\n' + \ ' entry.numParams = numParams;\r\n' + \ ' entry.firstParamName = nameFirstParam;\r\n' + \ ' entry.firstParamSymbol = KeyValuesSystem()->GetSymbolForString(nameFirstParam);\r\n' + \ ' entry.firstParamType = typeFirstParam;\r\n' + \ ' entry.secondParamName = nameSecondParam;\r\n' + \ ' entry.secondParamSymbol = KeyValuesSystem()->GetSymbolForString(nameSecondParam);\r\n' + \ ' entry.secondParamType = typeSecondParam;\r\n' + \ '\r\n' + \ ' GetPyMessageMap().Insert(message, entry);\r\n' + \ '}\r\n' + \ 'virtual Panel *GetPanel() { return this; }\r\n' ) cls.add_registration_code('def( "RegMessageMethod", &'+cls_name+'_wrapper::RegMessageMethod\r\n' + \ ', ( bp::arg("message"), bp::arg("method"), bp::arg("numParams")=(int)(0), bp::arg("nameFirstParam")="", bp::arg("typeFirstParam")=int(::vgui::DATATYPE_VOID), bp::arg("nameSecondParam")="", bp::arg("typeSecondParam")=int(::vgui::DATATYPE_VOID) ))' ) # Add stubs cls.add_wrapper_code('virtual void EnableSBuffer( bool bUseBuffer ) { PyPanel::EnableSBuffer( bUseBuffer ); }') cls.add_registration_code('def( "EnableSBuffer", &%(cls_name)s_wrapper::EnableSBuffer, bp::arg("bUseBuffer") )' % {'cls_name' : cls_name}) cls.add_wrapper_code('virtual bool IsSBufferEnabled() { return PyPanel::IsSBufferEnabled(); }') cls.add_registration_code('def( "IsSBufferEnabled", &%(cls_name)s_wrapper::IsSBufferEnabled )' % {'cls_name' : cls_name}) cls.add_wrapper_code('virtual void FlushSBuffer() { PyPanel::FlushSBuffer(); }') cls.add_registration_code('def( "FlushSBuffer", &%(cls_name)s_wrapper::FlushSBuffer )' % {'cls_name' : cls_name}) cls.add_wrapper_code('virtual void SetFlushedByParent( bool bEnabled ) { PyPanel::SetFlushedByParent( bEnabled ); }') cls.add_registration_code('def( "SetFlushedByParent", &%(cls_name)s_wrapper::SetFlushedByParent, bp::arg("bEnabled") )' % {'cls_name' : cls_name}) # Tweak Panels # Used by converters + special method added in the wrapper # Don't include here if not self.novguilib: mb.mem_funs('GetPySelf').exclude() mb.mem_funs('PyDestroyPanel').exclude() # Exclude message stuff. Maybe look into wrapping this in a nice way mb.mem_funs( 'AddToMap' ).exclude() mb.mem_funs( 'ChainToMap' ).exclude() mb.mem_funs( 'GetMessageMap' ).exclude() mb.mem_funs( 'AddToAnimationMap' ).exclude() mb.mem_funs( 'ChainToAnimationMap' ).exclude() mb.mem_funs( 'GetAnimMap' ).exclude() mb.mem_funs( 'KB_AddToMap' ).exclude() mb.mem_funs( 'KB_ChainToMap' ).exclude() mb.mem_funs( 'KB_AddBoundKey' ).exclude() mb.mem_funs( 'GetKBMap' ).exclude() mb.mem_funs( lambda decl: 'GetVar_' in decl.name ).exclude() mb.classes( lambda decl: 'PanelMessageFunc_' in decl.name ).exclude() mb.classes( lambda decl: '_Register' in decl.name ).exclude() mb.classes( lambda decl: 'PanelAnimationVar_' in decl.name ).exclude() mb.vars( lambda decl: '_register' in decl.name ).exclude() mb.vars( lambda decl: 'm_Register' in decl.name ).exclude() # Don't need the following: menu = mb.class_('Menu') keybindindcontexthandle = mb.enum('KeyBindingContextHandle_t') excludetypes = [ pointer_t(const_t(declarated_t(menu))), pointer_t(declarated_t(menu)), reference_t(declarated_t(menu)), pointer_t(declarated_t(mb.class_('IPanelAnimationPropertyConverter'))), declarated_t(keybindindcontexthandle), ] mb.calldefs(calldef_withtypes(excludetypes), allow_empty=True).exclude()
def ParseImageClasses(self, mb): # IBorder cls = mb.class_('IBorder') cls.include() cls.mem_funs('ApplySchemeSettings').include() cls.mem_funs('Paint').virtuality = 'pure virtual' cls.mem_funs('ApplySchemeSettings').virtuality = 'pure virtual' # IImage cls = mb.class_('IImage') cls.include() cls.mem_funs( 'GetContentSize' ).add_transformation( FT.output('wide'), FT.output('tall') ) cls.mem_funs( 'GetSize' ).add_transformation( FT.output('wide'), FT.output('tall') ) cls.mem_funs('Paint').virtuality = 'pure virtual' # Image cls = mb.class_('Image') cls.include() #cls.mem_funs( matchers.access_type_matcher_t( 'protected' ) ).exclude() cls.no_init = True #cls.calldefs().virtuality = 'not virtual' cls.calldefs('Image').exclude() cls.mem_funs( 'Paint' ).exclude() cls.add_wrapper_code( 'virtual void Paint() {}' ) # Stub for wrapper class. Otherwise it will complain. cls.mem_funs( 'GetSize' ).add_transformation( FT.output('wide'), FT.output('tall') ) cls.mem_funs( 'GetContentSize' ).add_transformation( FT.output('wide'), FT.output('tall') ) # FIXME: Py++ is giving problems on some functions cls.mem_funs('SetPos').virtuality = 'not virtual' #cls.mem_funs('GetPos').virtuality = 'not virtual' #cls.mem_funs('GetSize').virtuality = 'not virtual' #cls.mem_funs('GetContentSize').virtuality = 'not virtual' cls.mem_funs('SetColor').virtuality = 'not virtual' cls.mem_funs('SetBkColor').virtuality = 'not virtual' cls.mem_funs('GetColor').virtuality = 'not virtual' cls.mem_funs('SetSize').virtuality = 'not virtual' cls.mem_funs('DrawSetColor').virtuality = 'not virtual' cls.mem_funs('DrawSetColor').virtuality = 'not virtual' cls.mem_funs('DrawFilledRect').virtuality = 'not virtual' cls.mem_funs('DrawOutlinedRect').virtuality = 'not virtual' cls.mem_funs('DrawLine').virtuality = 'not virtual' cls.mem_funs('DrawPolyLine').virtuality = 'not virtual' cls.mem_funs('DrawSetTextFont').virtuality = 'not virtual' cls.mem_funs('DrawSetTextColor').virtuality = 'not virtual' cls.mem_funs('DrawSetTextPos').virtuality = 'not virtual' cls.mem_funs('DrawPrintText').virtuality = 'not virtual' cls.mem_funs('DrawPrintText').virtuality = 'not virtual' cls.mem_funs('DrawPrintChar').virtuality = 'not virtual' cls.mem_funs('DrawPrintChar').virtuality = 'not virtual' cls.mem_funs('DrawSetTexture').virtuality = 'not virtual' cls.mem_funs('DrawTexturedRect').virtuality = 'not virtual' # TextImage cls = mb.class_('TextImage') cls.include() cls.calldefs().virtuality = 'not virtual' cls.mem_funs( matchers.access_type_matcher_t( 'protected' ) ).exclude() #cls.calldefs('SetText', calldef_withtypes([pointer_t(const_t(declarated_t(wchar_t())))])).exclude() cls.mem_funs( 'GetContentSize' ).add_transformation( FT.output('wide'), FT.output('tall') ) cls.mem_funs( 'GetDrawWidth' ).add_transformation( FT.output('width') ) cls.mem_funs( 'SizeText' ).exclude() # DECLARATION ONLY cls.mem_funs('GetText').exclude() cls.add_wrapper_code( 'boost::python::object GetText() {\r\n' + \ ' char buf[1025];\r\n' + \ ' TextImage::GetText(buf, 1025);\r\n' + \ ' return boost::python::object(buf);\r\n' + \ '}' ) cls.add_registration_code( 'def( \r\n' + \ ' "GetText"\r\n' + \ ' , (boost::python::object ( TextImage_wrapper::* )())( &TextImage_wrapper::GetText ) )' ) # BitmapImage cls = mb.class_('BitmapImage') cls.include() cls.calldefs().virtuality = 'not virtual' if self.settings.branch == 'source2013': cls.mem_fun('SetBitmap').exclude() #cls.mem_funs( matchers.access_type_matcher_t( 'protected' ) ).exclude() cls.calldefs('GetColor', calldef_withtypes([reference_t(declarated_t(int_t()))])).add_transformation(FT.output('r'), FT.output('g'), FT.output('b'), FT.output('a')) cls.mem_funs( 'GetSize' ).add_transformation( FT.output('wide'), FT.output('tall') ) # CAvatarImage cls = mb.class_('CAvatarImage') cls.include() cls.calldefs().virtuality = 'not virtual' cls.mem_funs( matchers.access_type_matcher_t( 'protected' ) ).exclude() cls.rename('AvatarImage') cls.mem_funs( 'GetSize' ).add_transformation( FT.output('wide'), FT.output('tall') ) cls.mem_funs( 'GetContentSize' ).add_transformation( FT.output('wide'), FT.output('tall') ) cls.mem_funs( 'InitFromRGBA' ).exclude() mb.enum('EAvatarSize').include()
def tt(type_): type_ = declarations.remove_reference(type_) type_ = declarations.remove_const(type_) return declarations.reference_t(type_)
def _get_class_inst_type(self, add_const): inst_arg_type = declarations.declarated_t(self.declaration.parent) if add_const: inst_arg_type = declarations.const_t(inst_arg_type) inst_arg_type = declarations.reference_t(inst_arg_type) return inst_arg_type
def Parse(self, mb): # Exclude everything by default mb.decls().exclude() # By default include all functions starting with "UTIL_". Rest we will do manually mb.free_functions(lambda decl: "UTIL_" in decl.name).include() mb.free_function("UTIL_GetModDir").exclude() # Exclude and replace mb.free_functions("UTIL_TraceLine").include() mb.free_functions("UTIL_TraceHull").include() mb.free_functions("UTIL_TraceEntity").include() mb.free_functions("UTIL_TraceRay").exclude() mb.free_functions("UTIL_PyTraceRay").rename("UTIL_TraceRay") mb.free_functions("UTIL_PyEntitiesInSphere").rename("UTIL_EntitiesInSphere") mb.free_functions("UTIL_PyEntitiesInBox").rename("UTIL_EntitiesInBox") mb.free_functions("UTIL_EntitiesAlongRay").exclude() mb.free_functions("UTIL_PyEntitiesAlongRay").rename("UTIL_EntitiesAlongRay") # Enums mb.enum("ShakeCommand_t").include() # Call policies mb.free_functions("UTIL_PlayerByIndex").call_policies = call_policies.return_value_policy( call_policies.return_by_value ) # Exclude # Don't care about the following functions mb.free_functions("UTIL_LoadFileForMe").exclude() mb.free_functions("UTIL_FreeFile").exclude() # Exclude for now mb.free_functions("UTIL_EntitiesInSphere").exclude() mb.free_functions("UTIL_EntitiesInBox").exclude() # Add mb.free_function("StandardFilterRules").include() mb.free_function("PassServerEntityFilter").include() # //-------------------------------------------------------------------------------------------------------------------------------- # Tracing cls = mb.class_("CBaseTrace") cls.include() cls = mb.class_("CGameTrace") cls.include() cls.rename("trace_t") cls.var("m_pEnt").rename("ent") cls.var("m_pEnt").getter_call_policies = call_policies.return_value_policy(call_policies.return_by_value) cls = mb.class_("PyRay_t") cls.include() cls.rename("Ray_t") cls.vars("m_Start").rename("start") cls.vars("m_Delta").rename("delta") cls.vars("m_StartOffset").rename("startoffset") cls.vars("m_Extents").rename("extents") cls.vars("m_IsRay").rename("isray") cls.vars("m_IsSwept").rename("isswept") # //-------------------------------------------------------------------------------------------------------------------------------- # Trace Filters # By default, it's not possible to override TraceFilter methods cls = mb.class_("ITraceFilter") cls.include() cls.calldefs().exclude() tracefilters = [ "CTraceFilter", "CTraceFilterEntitiesOnly", "CTraceFilterWorldOnly", "CTraceFilterWorldAndPropsOnly", "CTraceFilterHitAll", "CTraceFilterSimple", "CTraceFilterSkipTwoEntities", "CTraceFilterSimpleList", "CTraceFilterOnlyNPCsAndPlayer", "CTraceFilterNoNPCsOrPlayer", "CTraceFilterLOS", "CTraceFilterSkipClassname", "CTraceFilterSkipTwoClassnames", "CTraceFilterSimpleClassnameList", "CTraceFilterChain", "CPyTraceFilterSimple", "CTraceFilterOnlyUnitsAndPlayer", "CTraceFilterNoUnitsOrPlayer", "CTraceFilterIgnoreTeam", "CTraceFilterSkipFriendly", "CTraceFilterSkipEnemies", "CTraceFilterWars", "CWarsBulletsFilter", ] for clsname in tracefilters: self.SetupTraceFilter(mb, clsname) mb.class_("CTraceFilterSimple").rename("CTraceFilterSimpleInternal") mb.class_("CPyTraceFilterSimple").rename("CTraceFilterSimple") mb.mem_funs("GetPassEntity").call_policies = call_policies.return_value_policy(call_policies.return_by_value) mb.class_("csurface_t").include() # //-------------------------------------------------------------------------------------------------------------------------------- # Collision utils mb.free_functions("PyIntersectRayWithTriangle").include() mb.free_functions("PyIntersectRayWithTriangle").rename("IntersectRayWithTriangle") mb.free_functions("ComputeIntersectionBarycentricCoordinates").include() mb.free_functions("IntersectRayWithRay").include() mb.free_functions("IntersectRayWithSphere").include() mb.free_functions("IntersectInfiniteRayWithSphere").include() mb.free_functions("IsSphereIntersectingCone").include() mb.free_functions("IntersectRayWithPlane").include() mb.free_functions("IntersectRayWithAAPlane").include() mb.free_functions("IntersectRayWithBox").include() mb.class_("BoxTraceInfo_t").include() mb.free_functions("IntersectRayWithBox").include() mb.free_functions("IntersectRayWithOBB").include() mb.free_functions("IsSphereIntersectingSphere").include() if self.settings.branch != "swarm": # IsBoxIntersectingSphere gives a problem mb.free_functions("IsBoxIntersectingSphere").include() mb.free_functions("IsBoxIntersectingSphereExtents").include() mb.free_functions("IsRayIntersectingSphere").include() mb.free_functions("IsCircleIntersectingRectangle").include() mb.free_functions("IsOBBIntersectingOBB").include() mb.free_functions("IsPointInCone").include() mb.free_functions("IntersectTriangleWithPlaneBarycentric").include() mb.enum("QuadBarycentricRetval_t").include() mb.free_functions("PointInQuadToBarycentric").include() mb.free_functions("PointInQuadFromBarycentric").include() mb.free_functions("TexCoordInQuadFromBarycentric").include() mb.free_functions("ComputePointFromBarycentric").include() mb.free_functions("IsRayIntersectingOBB").include() mb.free_functions("ComputeSeparatingPlane").include() mb.free_functions("IsBoxIntersectingTriangle").include() # mb.free_functions('CalcClosestPointOnTriangle').include() mb.free_functions("OBBHasFullyContainedIntersectionWithQuad").include() mb.free_functions("RayHasFullyContainedIntersectionWithQuad").include() vectorcls = mb.class_("Vector") excludetypes = [ declarated_t(vectorcls), reference_t(declarated_t(vectorcls)), reference_t(const_t(declarated_t(vectorcls))), ] vectormatcher = calldef_withtypes(excludetypes) mb.free_functions("IsBoxIntersectingBox", vectormatcher).include() mb.free_functions("IsBoxIntersectingBoxExtents", vectormatcher).include() mb.free_functions("IsBoxIntersectingRay", vectormatcher).include() mb.free_functions("IsPointInBox", vectormatcher).include() # Prediction functions mb.free_function("GetSuppressHost").include() mb.free_function("GetSuppressHost").call_policies = call_policies.return_value_policy( call_policies.return_by_value ) if self.isserver: self.ParseServer(mb) else: self.ParseClient(mb) # Finally apply common rules to all includes functions and classes, etc. self.ApplyCommonRules(mb)
def wrapped_class_type(self): wrapped_cls_type = declarations.declarated_t(self.declaration.parent) if declarations.is_const(self.declaration.type): wrapped_cls_type = declarations.const_t(wrapped_cls_type) return declarations.reference_t(wrapped_cls_type)
def wrapped_class_type( self ): wrapped_cls_type = declarations.declarated_t( self.declaration.parent ) if declarations.is_const( self.declaration.type ): wrapped_cls_type = declarations.const_t( wrapped_cls_type ) return declarations.reference_t( wrapped_cls_type )
def Parse(self, mb): mb.decls().exclude() # Get item getitem_wrapper = 'static ::vec_t GetItem( %(cls_name)s const & inst, int i ) {\r\n' + \ ' if( i < 0 || i > %(nitems)s ) {\r\n' + \ ' PyErr_SetString(PyExc_IndexError, "Index out of range" );\r\n' + \ ' throw boost::python::error_already_set();\r\n' + \ ' }\r\n' + \ ' return inst[i];\r\n' + \ '}\r\n' getitem_reg = '%(cls_name)s_exposer.def( "__getitem__", &::%(cls_name)s_wrapper::GetItem );\r\n' # Set item setitem_wrapper = 'static void SetItem( %(cls_name)s & inst, int i, ::vec_t v ) {\r\n' + \ ' if( i < 0 || i > %(nitems)s ) {\r\n' + \ ' PyErr_SetString(PyExc_IndexError, "Index out of range" );\r\n' + \ ' throw boost::python::error_already_set();\r\n' + \ ' }\r\n' + \ ' inst[i] = v;\r\n' + \ '}\r\n' setitem_reg = '%(cls_name)s_exposer.def( "__setitem__", &::%(cls_name)s_wrapper::SetItem );\r\n' # String str_vmatrix_wrapper = 'static boost::python::object Str( VMatrix const & inst ) {\r\n' + \ ' return boost::python::object(VMatToString(inst));\r\n' + \ '}\r\n' str_reg = '%(cls_name)s_exposer.def( "__str__", &::%(cls_name)s_wrapper::Str );\r\n' # Classes cls = mb.class_('Vector') cls.include() cls.mem_opers( '=').exclude() # Breaks debug mode and don't really need it cls.add_wrapper_code(getitem_wrapper % { 'cls_name': 'Vector', 'nitems': '2' }) cls.add_registration_code(getitem_reg % {'cls_name': 'Vector'}, False) cls.add_wrapper_code(setitem_wrapper % { 'cls_name': 'Vector', 'nitems': '2' }) cls.add_registration_code(setitem_reg % {'cls_name': 'Vector'}, False) cls = mb.class_('Vector2D') cls.include() cls.mem_opers( '=').exclude() # Breaks debug mode and don't really need it cls.add_wrapper_code(getitem_wrapper % { 'cls_name': 'Vector2D', 'nitems': '1' }) cls.add_registration_code(getitem_reg % {'cls_name': 'Vector2D'}, False) cls.add_wrapper_code(setitem_wrapper % { 'cls_name': 'Vector2D', 'nitems': '1' }) cls.add_registration_code(setitem_reg % {'cls_name': 'Vector2D'}, False) cls = mb.class_('QAngle') cls.include() cls.mem_opers( '=').exclude() # Breaks debug mode and don't really need it cls.add_wrapper_code(getitem_wrapper % { 'cls_name': 'QAngle', 'nitems': '2' }) cls.add_registration_code(getitem_reg % {'cls_name': 'QAngle'}, False) cls.add_wrapper_code(setitem_wrapper % { 'cls_name': 'QAngle', 'nitems': '2' }) cls.add_registration_code(setitem_reg % {'cls_name': 'QAngle'}, False) cls = mb.class_('Quaternion') cls.include() cls.mem_opers( '=').exclude() # Breaks debug mode and don't really need it mb.free_function('QAngleToAngularImpulse').include() mb.free_function('AngularImpulseToQAngle').include() # Call policies mb.mem_funs( 'AsVector2D' ).call_policies = call_policies.return_internal_reference() # Transform functions that take pointers as arguments mb.free_functions('SolveInverseQuadraticMonotonic').add_transformation( FT.output('a'), FT.output('b'), FT.output('c')) mb.free_functions('ComputeTrianglePlane').add_transformation( FT.output('intercept')) mb.free_functions( 'CalcSqrDistAndClosestPointOnAABB').add_transformation( FT.output('distSqrOut')) mb.free_functions( 'SolveInverseReciprocalQuadratic').add_transformation( FT.output('a'), FT.output('b'), FT.output('c')) mb.free_functions('SolveQuadratic').add_transformation( FT.output('root1'), FT.output('root2')) mb.free_functions('SolveInverseQuadratic').add_transformation( FT.output('a'), FT.output('b'), FT.output('c')) mb.free_functions('QuaternionAxisAngle').add_transformation( FT.output('axis'), FT.output('angle')) mb.free_functions('RotationDeltaAxisAngle').add_transformation( FT.output('deltaAxis'), FT.output('deltaAngle')) # Compressed color mb.class_('ColorRGBExp32').include() # cplane_t mb.class_('cplane_t').include() mb.class_('cplane_t').var('pad').exclude() # matrix3x4_t mb.class_('matrix3x4_t').include() mb.class_('matrix3x4_t').mem_opers().exclude() # ----- # Add custom item access functions to the Vector class mb.global_ns.mem_opers('[]').exclude() mb.class_('Vector').add_registration_code( 'def( bp::init< const Vector & >(( bp::arg("vOther") )) )') mb.class_('QAngle').add_registration_code( 'def( bp::init< const QAngle & >(( bp::arg("vOther") )) )') # Vars mb.vars('vec3_origin').include() mb.vars('vec3_angle').include() mb.vars('vec3_invalid').include() mb.vars('nanmask').include() # Mathlib.h functions mb.free_function('RandomAngularImpulse').include() mb.free_functions('VectorMaximum').include() mb.free_functions('VectorMAInline').include() mb.free_functions('VectorMA').include() mb.free_functions('RoundInt').include() mb.free_functions('Q_log2').include() mb.free_functions('SinCos').include() mb.free_functions('TableCos').include() mb.free_functions('TableSin').include() if self.settings.branch == 'swarm': mb.free_functions('IsPowerOfTwo').include() mb.free_functions('SmallestPowerOfTwoGreaterOrEqual').include() mb.free_functions('LargestPowerOfTwoLessThanOrEqual').include() mb.free_functions('FloorDivMod').include() mb.free_functions('GreatestCommonDivisor').include() mb.free_functions('IsDenormal').include() mb.free_functions('MatrixVectors').include() mb.free_functions('VectorRotate').include() mb.free_functions('TransformAnglesToLocalSpace').include() mb.free_functions('MatrixInitialize').include() mb.free_functions('MatrixCopy').include() mb.free_functions('MatrixInvert').include() mb.free_functions('MatricesAreEqual').include() mb.free_functions('MatrixGetColumn').include() mb.free_functions('MatrixSetColumn').include() mb.free_functions('ConcatRotations').include() mb.free_functions('ConcatTransforms').include() mb.free_functions('MatrixMultiply').include() mb.free_function('QuaternionSlerp').include() mb.free_function('QuaternionSlerpNoAlign').include() mb.free_function('QuaternionBlend').include() mb.free_function('QuaternionBlendNoAlign').include() mb.free_function('QuaternionIdentityBlend').include() mb.free_function('QuaternionAngleDiff').include() mb.free_function('QuaternionScale').include() mb.free_function('QuaternionDotProduct').include() mb.free_function('QuaternionConjugate').include() mb.free_function('QuaternionInvert').include() mb.free_function('QuaternionNormalize').include() mb.free_function('QuaternionAdd').include() mb.free_function('QuaternionMult').include() mb.free_functions('QuaternionMatrix').include() mb.free_functions('QuaternionAngles').include() mb.free_functions('AngleQuaternion').include() mb.free_function('QuaternionAxisAngle').include() mb.free_function('AxisAngleQuaternion').include() mb.free_function('BasisToQuaternion').include() mb.free_function('MatrixQuaternion').include() mb.free_functions('MatrixRowDotProduct').include() mb.free_functions('MatrixColumnDotProduct').include() mb.free_functions('anglemod').include() mb.free_functions('RemapVal').include() mb.free_functions('RemapValClamped').include() mb.free_functions('Lerp').include() mb.free_functions('Sqr').include() mb.free_functions('FLerp').include() mb.free_functions('Sign').include() mb.free_functions('ClampArrayBounds').include() mb.free_functions('AngleVectors').include() mb.free_functions('AngleVectors').include() mb.free_functions('AngleVectorsTranspose').include() mb.free_functions('AngleMatrix').include() mb.free_functions('AngleMatrix').include() mb.free_functions('AngleIMatrix').include() mb.free_functions('VectorAngles').include() mb.free_functions('VectorMatrix').include() mb.free_functions('VectorVectors').include() mb.free_functions('SetIdentityMatrix').include() mb.free_functions('SetScaleMatrix').include() mb.free_functions('MatrixBuildRotationAboutAxis').include() mb.free_functions('MatrixTranspose').include() mb.free_functions('MatrixInverseTranspose').include() mb.free_functions('PositionMatrix').include() mb.free_functions('MatrixPosition').include() mb.free_functions('VectorRotate').include() mb.free_functions('VectorIRotate').include() mb.free_functions('MatrixAngles').include() mb.free_functions('VectorCompare').include() mb.free_functions('VectorTransform').include() mb.free_functions('VectorITransform').include() mb.free_functions('BoxOnPlaneSide').include() mb.free_functions('VectorFill').include() mb.free_functions('VectorNegate').include() mb.free_functions('VectorAvg').include() mb.free_functions('BoxOnPlaneSide2').include() mb.free_functions('ClearBounds').include() mb.free_functions('AddPointToBounds').include() mb.free_functions('BuildGammaTable').include() mb.free_functions('TexLightToLinear').include() mb.free_functions('LinearToTexture').include() mb.free_functions('LinearToScreenGamma').include() mb.free_functions('TextureToLinear').include() mb.free_functions('SolveQuadratic').include() mb.free_functions('SolveInverseQuadratic').include() mb.free_functions('SolveInverseQuadraticMonotonic').include() mb.free_functions('SolveInverseReciprocalQuadratic').include() mb.free_functions('VectorYawRotate').include() mb.free_functions('Bias').include() mb.free_functions('Gain').include() mb.free_functions('SmoothCurve').include() mb.free_functions('SmoothCurve_Tweak').include() mb.free_functions('ExponentialDecay').include() mb.free_functions('ExponentialDecay').include() mb.free_functions('ExponentialDecayIntegral').include() mb.free_functions('SimpleSpline').include() mb.free_functions('SimpleSplineRemapVal').include() mb.free_functions('SimpleSplineRemapValClamped').include() mb.free_functions('RoundFloatToInt').include() mb.free_functions('RoundFloatToByte').include() mb.free_functions('RoundFloatToUnsignedLong').include() mb.free_functions('IsIntegralValue').include() mb.free_functions('Float2Int').include() mb.free_functions('Floor2Int').include() mb.free_functions('FastFToC').include() mb.free_functions('ClampToMsec').include() mb.free_functions('Ceil2Int').include() mb.free_functions('GetBarycentricCoords2D').include() mb.free_functions('QuickBoxSphereTest').include() mb.free_functions('QuickBoxIntersectTest').include() mb.free_functions('GammaToLinearFullRange').include() mb.free_functions('LinearToGammaFullRange').include() mb.free_functions('GammaToLinear').include() mb.free_functions('LinearToGamma').include() mb.free_functions('SrgbGammaToLinear').include() mb.free_functions('SrgbLinearToGamma').include() mb.free_functions('X360GammaToLinear').include() mb.free_functions('X360LinearToGamma').include() mb.free_functions('SrgbGammaTo360Gamma').include() mb.free_functions('LinearToVertexLight').include() mb.free_functions('LinearToLightmap').include() mb.free_functions('ColorClamp').include() mb.free_functions('ColorClampTruncate').include() mb.free_functions('Catmull_Rom_Spline').include() mb.free_functions('Catmull_Rom_Spline_Tangent').include() mb.free_functions('Catmull_Rom_Spline_Integral').include() mb.free_functions('Catmull_Rom_Spline_Integral').include() mb.free_functions('Catmull_Rom_Spline_Normalize').include() mb.free_functions('Catmull_Rom_Spline_Integral_Normalize').include() mb.free_functions('Catmull_Rom_Spline_NormalizeX').include() mb.free_functions('Catmull_Rom_Spline_NormalizeX').include() mb.free_functions('Hermite_Spline').include() #mb.free_functions('Hermite_SplineBasis').include() mb.free_functions('Kochanek_Bartels_Spline').include() mb.free_functions('Kochanek_Bartels_Spline_NormalizeX').include() mb.free_functions('Cubic_Spline').include() mb.free_functions('Cubic_Spline_NormalizeX').include() mb.free_functions('BSpline').include() mb.free_functions('BSpline_NormalizeX').include() mb.free_functions('Parabolic_Spline').include() mb.free_functions('Parabolic_Spline_NormalizeX').include() mb.free_functions('QuinticInterpolatingPolynomial').include() #mb.free_functions('GetInterpolationData').include() mb.free_functions('RangeCompressor').include() mb.free_functions('CalcSqrDistanceToAABB').include() mb.free_functions('CalcClosestPointOnAABB').include() mb.free_functions('CalcSqrDistAndClosestPointOnAABB').include() mb.free_functions('CalcDistanceToAABB').include() #mb.free_functions('CalcLineToLineIntersectionSegment').include() # TODO mb.free_functions('Approach').include() mb.free_functions('ApproachAngle').include() mb.free_functions('AngleDiff').include() mb.free_functions('AngleDistance').include() mb.free_functions('AngleNormalize').include() mb.free_functions('AngleNormalizePositive').include() mb.free_functions('AnglesAreEqual').include() mb.free_functions('RotationDeltaAxisAngle').include() mb.free_functions('RotationDelta').include() mb.free_functions('ComputeTrianglePlane').include() mb.free_functions('PolyFromPlane').include() mb.free_functions('ClipPolyToPlane').include() mb.free_functions('ClipPolyToPlane_Precise').include() mb.free_functions('CalcTriangleTangentSpace').include() mb.free_functions('TransformAABB').include() mb.free_functions('ITransformAABB').include() mb.free_functions('RotateAABB').include() mb.free_functions('IRotateAABB').include() mb.free_functions('MatrixTransformPlane').include() mb.free_functions('MatrixITransformPlane').include() mb.free_functions('CeilPow2').include() mb.free_functions('FloorPow2').include() mb.free_functions('RGBtoHSV').include() mb.free_functions('HSVtoRGB').include() # Vector.h functions mb.free_functions('VectorClear').include() mb.free_functions('VectorCopy').include() mb.free_functions('VectorAdd').include() mb.free_functions('VectorSubtract').include() mb.free_functions('VectorMultiply').include() mb.free_functions('VectorDivide').include() mb.free_functions('VectorScale').include() mb.free_functions('VectorMA').include() mb.free_functions('VectorsAreEqual').include() mb.free_functions('ComputeClosestPoint').include() mb.free_functions('VectorAbs').include() mb.free_functions('VectorLength').include() mb.free_functions('DotProduct').include() mb.free_functions('CrossProduct').include() mb.free_functions('VectorMin').include() mb.free_functions('VectorMax').include() mb.free_functions('VectorLerp').include() mb.free_functions('RandomVector').include() mb.free_functions('QAnglesAreEqual').include() #mb.free_functions('QAngleToAngularImpulse').include() #mb.free_functions('AngularImpulseToQAngle').include() mb.free_functions('VectorNormalize').include() mb.free_functions('VectorNormalizeFast').include() # Vector2d.h functions mb.free_functions('Vector2DClear').include() mb.free_functions('Vector2DCopy').include() mb.free_functions('Vector2DAdd').include() mb.free_functions('Vector2DSubtract').include() mb.free_functions('Vector2DMultiply').include() mb.free_functions('Vector2DDivide').include() mb.free_functions('Vector2DMA').include() mb.free_functions('Vector2DMin').include() mb.free_functions('Vector2DMax').include() mb.free_functions('Vector2DLength').include() mb.free_functions('DotProduct2D').include() mb.free_functions('Vector2DLerp').include() mb.free_functions('Vector2DNormalize').include() mb.free_functions('ComputeClosestPoint2D').include() # QAngle functions mb.free_function('RandomAngle').include() # VMatrix cls = mb.class_('VMatrix') cls.include() cls.mem_opers( '=').exclude() # Breaks debug mode and don't really need it cls.mem_opers('[]').exclude() cls.mem_funs('Base').exclude() cls.vars('m').exclude() if self.settings.branch == 'swarm': cls.mem_fun( 'As3x4', matchers.calldef_matcher_t(return_type=reference_t( declarated_t(mb.class_('matrix3x4_t'))))).exclude() cls.mem_fun( 'GetTranslation', matchers.calldef_matcher_t(return_type=reference_t( declarated_t(mb.class_('Vector'))))).exclude() cls.add_wrapper_code(str_vmatrix_wrapper % {'cls_name': 'VMatrix'}) cls.add_registration_code(str_reg % {'cls_name': 'VMatrix'}, False) mb.free_functions('MatrixSetIdentity').include() mb.free_functions('MatrixTranspose').include() mb.free_functions('MatrixCopy').include() mb.free_functions('MatrixMultiply').include() mb.free_functions('MatrixGetColumn').include() mb.free_functions('MatrixSetColumn').include() mb.free_functions('MatrixGetRow').include() mb.free_functions('MatrixSetRow').include() mb.free_functions('MatrixTranslate').include() mb.free_functions('MatrixBuildRotationAboutAxis').include() mb.free_functions('MatrixBuildRotateZ').include() mb.free_functions('MatrixRotate').include() mb.free_functions('MatrixFromAngles').include() mb.free_functions('MatrixToAngles').include() # Exclude if self.settings.branch not in ['swarm', 'source2013']: mb.vars('pfVectorNormalizeFast').exclude() mb.vars('pfVectorNormalize').exclude() mb.vars('pfInvRSquared').exclude() mb.vars('m_flMatVal').exclude() mb.vars('quat_identity').exclude( ) # <- Does not even exist except for a declaration? # Exclude some functions mb.mem_funs('Base').exclude( ) # Base gives a pointer to the address of the data. Not very python like. mb.free_functions('AllocTempVector').exclude() mb.class_('Vector2D').mem_funs('Cross').exclude() # Declaration only? mb.free_function('ConcatRotations').exclude() # Declaration only? # Remove any protected function mb.calldefs(matchers.access_type_matcher_t('protected')).exclude() # Remove any function with "float *" values # A lot of functions have two versions (or more), of which one takes "float *" arguments vec_t = mb.typedef('vec_t') excludetypes = [ pointer_t(float_t()), pointer_t(const_t(float_t())), pointer_t(declarated_t(vec_t)), pointer_t(const_t(declarated_t(vec_t))), ] mb.calldefs(calldef_withtypes(excludetypes)).exclude() # Silent warnings of generating class wrappers mb.classes().disable_warnings(messages.W1027) # Include functions with "float *" parameter. For these functions we should transform the "float *" parameter mb.free_functions('CalcClosestPointOnLine2D').include() mb.free_functions('CalcClosestPointOnLine2D').add_transformation( FT.output('t')) mb.free_functions('CalcDistanceToLine2D').include() mb.free_functions('CalcDistanceToLine2D').add_transformation( FT.output('t')) mb.free_functions('CalcDistanceSqrToLine2D').include() mb.free_functions('CalcDistanceSqrToLine2D').add_transformation( FT.output('t')) mb.free_functions('CalcClosestPointOnLineSegment2D').include() mb.free_functions( 'CalcClosestPointOnLineSegment2D').add_transformation( FT.output('t')) mb.free_functions('CalcDistanceToLineSegment2D').include() mb.free_functions('CalcDistanceToLineSegment2D').add_transformation( FT.output('t')) mb.free_functions('CalcDistanceSqrToLineSegment2D').include() mb.free_functions('CalcDistanceSqrToLineSegment2D').add_transformation( FT.output('t')) mb.free_functions('CalcClosestPointOnLine').include() mb.free_functions('CalcClosestPointOnLine').add_transformation( FT.output('t')) mb.free_functions('CalcDistanceToLine').include() mb.free_functions('CalcDistanceToLine').add_transformation( FT.output('t')) mb.free_functions('CalcDistanceSqrToLine').include() mb.free_functions('CalcDistanceSqrToLine').add_transformation( FT.output('t')) mb.free_functions('CalcClosestPointOnLineSegment').include() mb.free_functions('CalcClosestPointOnLineSegment').add_transformation( FT.output('t')) mb.free_functions('CalcDistanceToLineSegment').include() mb.free_functions('CalcDistanceToLineSegment').add_transformation( FT.output('t')) mb.free_functions('CalcDistanceSqrToLineSegment').include() mb.free_functions('CalcDistanceSqrToLineSegment').add_transformation( FT.output('t'))
def Parse(self, mb): mb.decls().exclude() # Get item getitem_wrapper = 'static ::vec_t GetItem( %(cls_name)s const & inst, int i ) {\r\n' + \ ' if( i < 0 || i > %(nitems)s ) {\r\n' + \ ' PyErr_SetString(PyExc_IndexError, "Index out of range" );\r\n' + \ ' throw boost::python::error_already_set();\r\n' + \ ' }\r\n' + \ ' return inst[i];\r\n' + \ '}\r\n' getitem_reg = '%(cls_name)s_exposer.def( "__getitem__", &::%(cls_name)s_wrapper::GetItem );\r\n' # Set item setitem_wrapper = 'static void SetItem( %(cls_name)s & inst, int i, ::vec_t v ) {\r\n' + \ ' if( i < 0 || i > %(nitems)s ) {\r\n' + \ ' PyErr_SetString(PyExc_IndexError, "Index out of range" );\r\n' + \ ' throw boost::python::error_already_set();\r\n' + \ ' }\r\n' + \ ' inst[i] = v;\r\n' + \ '}\r\n' setitem_reg = '%(cls_name)s_exposer.def( "__setitem__", &::%(cls_name)s_wrapper::SetItem );\r\n' # String str_vmatrix_wrapper = 'static boost::python::object Str( VMatrix const & inst ) {\r\n' + \ ' return boost::python::object(VMatToString(inst));\r\n' + \ '}\r\n' str_reg = '%(cls_name)s_exposer.def( "__str__", &::%(cls_name)s_wrapper::Str );\r\n' # Classes cls = mb.class_('Vector') cls.include() cls.mem_opers('=').exclude() # Breaks debug mode and don't really need it cls.add_wrapper_code( getitem_wrapper % {'cls_name' : 'Vector', 'nitems' : '2' } ) cls.add_registration_code( getitem_reg % {'cls_name':'Vector'}, False) cls.add_wrapper_code( setitem_wrapper % {'cls_name' : 'Vector', 'nitems' : '2' } ) cls.add_registration_code( setitem_reg % {'cls_name':'Vector'}, False) cls = mb.class_('Vector2D') cls.include() cls.mem_opers('=').exclude() # Breaks debug mode and don't really need it cls.add_wrapper_code( getitem_wrapper % {'cls_name' : 'Vector2D', 'nitems' : '1' } ) cls.add_registration_code( getitem_reg % {'cls_name':'Vector2D'}, False) cls.add_wrapper_code( setitem_wrapper % {'cls_name' : 'Vector2D', 'nitems' : '1' } ) cls.add_registration_code( setitem_reg % {'cls_name':'Vector2D'}, False) cls = mb.class_('QAngle') cls.include() cls.mem_opers('=').exclude() # Breaks debug mode and don't really need it cls.add_wrapper_code( getitem_wrapper % {'cls_name' : 'QAngle', 'nitems' : '2' } ) cls.add_registration_code( getitem_reg % {'cls_name':'QAngle'}, False) cls.add_wrapper_code( setitem_wrapper % {'cls_name' : 'QAngle', 'nitems' : '2' } ) cls.add_registration_code( setitem_reg % {'cls_name':'QAngle'}, False) cls = mb.class_('Quaternion') cls.include() cls.mem_opers('=').exclude() # Breaks debug mode and don't really need it mb.free_function('QAngleToAngularImpulse').include() mb.free_function('AngularImpulseToQAngle').include() # Call policies mb.mem_funs('AsVector2D').call_policies = call_policies.return_internal_reference() # Transform functions that take pointers as arguments mb.free_functions('SolveInverseQuadraticMonotonic').add_transformation( FT.output('a'), FT.output('b'), FT.output('c') ) mb.free_functions('ComputeTrianglePlane').add_transformation( FT.output('intercept') ) mb.free_functions('CalcSqrDistAndClosestPointOnAABB').add_transformation( FT.output('distSqrOut') ) mb.free_functions('SolveInverseReciprocalQuadratic').add_transformation( FT.output('a'), FT.output('b'), FT.output('c') ) mb.free_functions('SolveQuadratic').add_transformation( FT.output('root1'), FT.output('root2') ) mb.free_functions('SolveInverseQuadratic').add_transformation( FT.output('a'), FT.output('b'), FT.output('c') ) mb.free_functions('QuaternionAxisAngle').add_transformation( FT.output('axis'), FT.output('angle') ) mb.free_functions('RotationDeltaAxisAngle').add_transformation( FT.output('deltaAxis'), FT.output('deltaAngle') ) # Compressed color mb.class_('ColorRGBExp32').include() # cplane_t mb.class_('cplane_t').include() mb.class_('cplane_t').var('pad').exclude() # matrix3x4_t mb.class_('matrix3x4_t').include() mb.class_('matrix3x4_t').mem_opers().exclude() # ----- # Add custom item access functions to the Vector class mb.global_ns.mem_opers('[]').exclude() mb.class_('Vector').add_registration_code( 'def( bp::init< const Vector & >(( bp::arg("vOther") )) )') mb.class_('QAngle').add_registration_code( 'def( bp::init< const QAngle & >(( bp::arg("vOther") )) )') # Vars mb.vars('vec3_origin').include() mb.vars('vec3_angle').include() mb.vars('vec3_invalid').include() mb.vars('nanmask').include() # Mathlib.h functions mb.free_function('RandomAngularImpulse').include() mb.free_functions('VectorMaximum').include() mb.free_functions('VectorMAInline').include() mb.free_functions('VectorMA').include() mb.free_functions('RoundInt').include() mb.free_functions('Q_log2').include() mb.free_functions('SinCos').include() mb.free_functions('TableCos').include() mb.free_functions('TableSin').include() if self.settings.branch == 'swarm': mb.free_functions('IsPowerOfTwo').include() mb.free_functions('SmallestPowerOfTwoGreaterOrEqual').include() mb.free_functions('LargestPowerOfTwoLessThanOrEqual').include() mb.free_functions('FloorDivMod').include() mb.free_functions('GreatestCommonDivisor').include() mb.free_functions('IsDenormal').include() mb.free_functions('MatrixVectors').include() mb.free_functions('VectorRotate').include() mb.free_functions('TransformAnglesToLocalSpace').include() mb.free_functions('MatrixInitialize').include() mb.free_functions('MatrixCopy').include() mb.free_functions('MatrixInvert').include() mb.free_functions('MatricesAreEqual').include() mb.free_functions('MatrixGetColumn').include() mb.free_functions('MatrixSetColumn').include() mb.free_functions('ConcatRotations').include() mb.free_functions('ConcatTransforms').include() mb.free_functions('MatrixMultiply').include() mb.free_function('QuaternionSlerp').include() mb.free_function('QuaternionSlerpNoAlign').include() mb.free_function('QuaternionBlend').include() mb.free_function('QuaternionBlendNoAlign').include() mb.free_function('QuaternionIdentityBlend').include() mb.free_function('QuaternionAngleDiff').include() mb.free_function('QuaternionScale').include() mb.free_function('QuaternionDotProduct').include() mb.free_function('QuaternionConjugate').include() mb.free_function('QuaternionInvert').include() mb.free_function('QuaternionNormalize').include() mb.free_function('QuaternionAdd').include() mb.free_function('QuaternionMult').include() mb.free_functions('QuaternionMatrix').include() mb.free_functions('QuaternionAngles').include() mb.free_functions('AngleQuaternion').include() mb.free_function('QuaternionAxisAngle').include() mb.free_function('AxisAngleQuaternion').include() mb.free_function('BasisToQuaternion').include() mb.free_function('MatrixQuaternion').include() mb.free_functions('MatrixRowDotProduct').include() mb.free_functions('MatrixColumnDotProduct').include() mb.free_functions('anglemod').include() mb.free_functions('RemapVal').include() mb.free_functions('RemapValClamped').include() mb.free_functions('Lerp').include() mb.free_functions('Sqr').include() mb.free_functions('FLerp').include() mb.free_functions('Sign').include() mb.free_functions('ClampArrayBounds').include() mb.free_functions('AngleVectors').include() mb.free_functions('AngleVectors').include() mb.free_functions('AngleVectorsTranspose').include() mb.free_functions('AngleMatrix').include() mb.free_functions('AngleMatrix').include() mb.free_functions('AngleIMatrix').include() mb.free_functions('VectorAngles').include() mb.free_functions('VectorMatrix').include() mb.free_functions('VectorVectors').include() mb.free_functions('SetIdentityMatrix').include() mb.free_functions('SetScaleMatrix').include() mb.free_functions('MatrixBuildRotationAboutAxis').include() mb.free_functions('MatrixTranspose').include() mb.free_functions('MatrixInverseTranspose').include() mb.free_functions('PositionMatrix').include() mb.free_functions('MatrixPosition').include() mb.free_functions('VectorRotate').include() mb.free_functions('VectorIRotate').include() mb.free_functions('MatrixAngles').include() mb.free_functions('VectorCompare').include() mb.free_functions('VectorTransform').include() mb.free_functions('VectorITransform').include() mb.free_functions('BoxOnPlaneSide').include() mb.free_functions('VectorFill').include() mb.free_functions('VectorNegate').include() mb.free_functions('VectorAvg').include() mb.free_functions('BoxOnPlaneSide2').include() mb.free_functions('ClearBounds').include() mb.free_functions('AddPointToBounds').include() mb.free_functions('BuildGammaTable').include() mb.free_functions('TexLightToLinear').include() mb.free_functions('LinearToTexture').include() mb.free_functions('LinearToScreenGamma').include() mb.free_functions('TextureToLinear').include() mb.free_functions('SolveQuadratic').include() mb.free_functions('SolveInverseQuadratic').include() mb.free_functions('SolveInverseQuadraticMonotonic').include() mb.free_functions('SolveInverseReciprocalQuadratic').include() mb.free_functions('VectorYawRotate').include() mb.free_functions('Bias').include() mb.free_functions('Gain').include() mb.free_functions('SmoothCurve').include() mb.free_functions('SmoothCurve_Tweak').include() mb.free_functions('ExponentialDecay').include() mb.free_functions('ExponentialDecay').include() mb.free_functions('ExponentialDecayIntegral').include() mb.free_functions('SimpleSpline').include() mb.free_functions('SimpleSplineRemapVal').include() mb.free_functions('SimpleSplineRemapValClamped').include() mb.free_functions('RoundFloatToInt').include() mb.free_functions('RoundFloatToByte').include() mb.free_functions('RoundFloatToUnsignedLong').include() mb.free_functions('IsIntegralValue').include() mb.free_functions('Float2Int').include() mb.free_functions('Floor2Int').include() mb.free_functions('FastFToC').include() mb.free_functions('ClampToMsec').include() mb.free_functions('Ceil2Int').include() mb.free_functions('GetBarycentricCoords2D').include() mb.free_functions('QuickBoxSphereTest').include() mb.free_functions('QuickBoxIntersectTest').include() mb.free_functions('GammaToLinearFullRange').include() mb.free_functions('LinearToGammaFullRange').include() mb.free_functions('GammaToLinear').include() mb.free_functions('LinearToGamma').include() mb.free_functions('SrgbGammaToLinear').include() mb.free_functions('SrgbLinearToGamma').include() mb.free_functions('X360GammaToLinear').include() mb.free_functions('X360LinearToGamma').include() mb.free_functions('SrgbGammaTo360Gamma').include() mb.free_functions('LinearToVertexLight').include() mb.free_functions('LinearToLightmap').include() mb.free_functions('ColorClamp').include() mb.free_functions('ColorClampTruncate').include() mb.free_functions('Catmull_Rom_Spline').include() mb.free_functions('Catmull_Rom_Spline_Tangent').include() mb.free_functions('Catmull_Rom_Spline_Integral').include() mb.free_functions('Catmull_Rom_Spline_Integral').include() mb.free_functions('Catmull_Rom_Spline_Normalize').include() mb.free_functions('Catmull_Rom_Spline_Integral_Normalize').include() mb.free_functions('Catmull_Rom_Spline_NormalizeX').include() mb.free_functions('Catmull_Rom_Spline_NormalizeX').include() mb.free_functions('Hermite_Spline').include() #mb.free_functions('Hermite_SplineBasis').include() mb.free_functions('Kochanek_Bartels_Spline').include() mb.free_functions('Kochanek_Bartels_Spline_NormalizeX').include() mb.free_functions('Cubic_Spline').include() mb.free_functions('Cubic_Spline_NormalizeX').include() mb.free_functions('BSpline').include() mb.free_functions('BSpline_NormalizeX').include() mb.free_functions('Parabolic_Spline').include() mb.free_functions('Parabolic_Spline_NormalizeX').include() mb.free_functions('QuinticInterpolatingPolynomial').include() #mb.free_functions('GetInterpolationData').include() mb.free_functions('RangeCompressor').include() mb.free_functions('CalcSqrDistanceToAABB').include() mb.free_functions('CalcClosestPointOnAABB').include() mb.free_functions('CalcSqrDistAndClosestPointOnAABB').include() mb.free_functions('CalcDistanceToAABB').include() #mb.free_functions('CalcLineToLineIntersectionSegment').include() # TODO mb.free_functions('Approach').include() mb.free_functions('ApproachAngle').include() mb.free_functions('AngleDiff').include() mb.free_functions('AngleDistance').include() mb.free_functions('AngleNormalize').include() mb.free_functions('AngleNormalizePositive').include() mb.free_functions('AnglesAreEqual').include() mb.free_functions('RotationDeltaAxisAngle').include() mb.free_functions('RotationDelta').include() mb.free_functions('ComputeTrianglePlane').include() mb.free_functions('PolyFromPlane').include() mb.free_functions('ClipPolyToPlane').include() mb.free_functions('ClipPolyToPlane_Precise').include() mb.free_functions('CalcTriangleTangentSpace').include() mb.free_functions('TransformAABB').include() mb.free_functions('ITransformAABB').include() mb.free_functions('RotateAABB').include() mb.free_functions('IRotateAABB').include() mb.free_functions('MatrixTransformPlane').include() mb.free_functions('MatrixITransformPlane').include() mb.free_functions('CeilPow2').include() mb.free_functions('FloorPow2').include() mb.free_functions('RGBtoHSV').include() mb.free_functions('HSVtoRGB').include() # Vector.h functions mb.free_functions('VectorClear').include() mb.free_functions('VectorCopy').include() mb.free_functions('VectorAdd').include() mb.free_functions('VectorSubtract').include() mb.free_functions('VectorMultiply').include() mb.free_functions('VectorDivide').include() mb.free_functions('VectorScale').include() mb.free_functions('VectorMA').include() mb.free_functions('VectorsAreEqual').include() mb.free_functions('ComputeClosestPoint').include() mb.free_functions('VectorAbs').include() mb.free_functions('VectorLength').include() mb.free_functions('DotProduct').include() mb.free_functions('CrossProduct').include() mb.free_functions('VectorMin').include() mb.free_functions('VectorMax').include() mb.free_functions('VectorLerp').include() mb.free_functions('RandomVector').include() mb.free_functions('QAnglesAreEqual').include() #mb.free_functions('QAngleToAngularImpulse').include() #mb.free_functions('AngularImpulseToQAngle').include() mb.free_functions('VectorNormalize').include() mb.free_functions('VectorNormalizeFast').include() # Vector2d.h functions mb.free_functions('Vector2DClear').include() mb.free_functions('Vector2DCopy').include() mb.free_functions('Vector2DAdd').include() mb.free_functions('Vector2DSubtract').include() mb.free_functions('Vector2DMultiply').include() mb.free_functions('Vector2DDivide').include() mb.free_functions('Vector2DMA').include() mb.free_functions('Vector2DMin').include() mb.free_functions('Vector2DMax').include() mb.free_functions('Vector2DLength').include() mb.free_functions('DotProduct2D').include() mb.free_functions('Vector2DLerp').include() mb.free_functions('Vector2DNormalize').include() mb.free_functions('ComputeClosestPoint2D').include() # QAngle functions mb.free_function('RandomAngle').include() # VMatrix cls = mb.class_('VMatrix') cls.include() cls.mem_opers('=').exclude() # Breaks debug mode and don't really need it cls.mem_opers('[]').exclude() cls.mem_funs('Base').exclude() cls.vars('m').exclude() cls.mem_fun('As3x4', matchers.calldef_matcher_t(return_type=reference_t(declarated_t(mb.class_('matrix3x4_t'))))).exclude() cls.mem_fun('GetTranslation', matchers.calldef_matcher_t(return_type=reference_t(declarated_t(mb.class_('Vector'))))).exclude() cls.add_wrapper_code( str_vmatrix_wrapper % {'cls_name':'VMatrix'} ) cls.add_registration_code( str_reg % {'cls_name':'VMatrix'}, False) mb.free_functions('MatrixSetIdentity').include() mb.free_functions('MatrixTranspose').include() mb.free_functions('MatrixCopy').include() mb.free_functions('MatrixMultiply').include() mb.free_functions('MatrixGetColumn').include() mb.free_functions('MatrixSetColumn').include() mb.free_functions('MatrixGetRow').include() mb.free_functions('MatrixSetRow').include() mb.free_functions('MatrixTranslate').include() mb.free_functions('MatrixBuildRotationAboutAxis').include() mb.free_functions('MatrixBuildRotateZ').include() mb.free_functions('MatrixRotate').include() mb.free_functions('MatrixFromAngles').include() mb.free_functions('MatrixToAngles').include() # Exclude if self.settings.branch not in ['swarm', 'source2013']: mb.vars('pfVectorNormalizeFast').exclude() mb.vars('pfVectorNormalize').exclude() mb.vars('pfInvRSquared').exclude() mb.vars('m_flMatVal').exclude() mb.vars('quat_identity').exclude() # <- Does not even exist except for a declaration? # Exclude some functions mb.mem_funs('Base').exclude() # Base gives a pointer to the address of the data. Not very python like. mb.free_functions( 'AllocTempVector' ).exclude() mb.class_('Vector2D').mem_funs('Cross').exclude() # Declaration only? mb.free_function('ConcatRotations').exclude() # Declaration only? # Remove any protected function mb.calldefs( matchers.access_type_matcher_t( 'protected' ) ).exclude() # Remove any function with "float *" values # A lot of functions have two versions (or more), of which one takes "float *" arguments vec_t = mb.typedef('vec_t') excludetypes = [ pointer_t(float_t()), pointer_t(const_t(float_t())), pointer_t(declarated_t(vec_t)), pointer_t(const_t(declarated_t(vec_t))), ] mb.calldefs( calldef_withtypes( excludetypes ) ).exclude() # Silent warnings of generating class wrappers mb.classes().disable_warnings( messages.W1027 ) # Include functions with "float *" parameter. For these functions we should transform the "float *" parameter mb.free_functions('CalcClosestPointOnLine2D').include() mb.free_functions('CalcClosestPointOnLine2D').add_transformation( FT.output('t') ) mb.free_functions('CalcDistanceToLine2D').include() mb.free_functions('CalcDistanceToLine2D').add_transformation( FT.output('t') ) mb.free_functions('CalcDistanceSqrToLine2D').include() mb.free_functions('CalcDistanceSqrToLine2D').add_transformation( FT.output('t') ) mb.free_functions('CalcClosestPointOnLineSegment2D').include() mb.free_functions('CalcClosestPointOnLineSegment2D').add_transformation( FT.output('t') ) mb.free_functions('CalcDistanceToLineSegment2D').include() mb.free_functions('CalcDistanceToLineSegment2D').add_transformation( FT.output('t') ) mb.free_functions('CalcDistanceSqrToLineSegment2D').include() mb.free_functions('CalcDistanceSqrToLineSegment2D').add_transformation( FT.output('t') ) mb.free_functions('CalcClosestPointOnLine').include() mb.free_functions('CalcClosestPointOnLine').add_transformation( FT.output('t') ) mb.free_functions('CalcDistanceToLine').include() mb.free_functions('CalcDistanceToLine').add_transformation( FT.output('t') ) mb.free_functions('CalcDistanceSqrToLine').include() mb.free_functions('CalcDistanceSqrToLine').add_transformation( FT.output('t') ) mb.free_functions('CalcClosestPointOnLineSegment').include() mb.free_functions('CalcClosestPointOnLineSegment').add_transformation( FT.output('t') ) mb.free_functions('CalcDistanceToLineSegment').include() mb.free_functions('CalcDistanceToLineSegment').add_transformation( FT.output('t') ) mb.free_functions('CalcDistanceSqrToLineSegment').include() mb.free_functions('CalcDistanceSqrToLineSegment').add_transformation( FT.output('t') )
def Parse(self, mb): # Exclude everything by default mb.decls().exclude() # By default include all functions starting with "UTIL_". Rest we will do manually mb.free_functions( lambda decl: 'UTIL_' in decl.name ).include() # Exclude and replace mb.free_functions('UTIL_TraceLine').include() mb.free_functions('UTIL_TraceHull').include() mb.free_functions('UTIL_TraceEntity').include() mb.free_functions('UTIL_TraceRay').exclude() mb.free_functions('UTIL_PyTraceRay').rename('UTIL_TraceRay') mb.free_functions('UTIL_PyEntitiesInSphere').rename('UTIL_EntitiesInSphere') mb.free_functions('UTIL_PyEntitiesInBox').rename('UTIL_EntitiesInBox') mb.free_functions('UTIL_EntitiesAlongRay').exclude() mb.free_functions('UTIL_PyEntitiesAlongRay').rename('UTIL_EntitiesAlongRay') # Enums mb.enum('ShakeCommand_t').include() # Call policies mb.free_functions('UTIL_PlayerByIndex').call_policies = call_policies.return_value_policy( call_policies.return_by_value ) # Exclude # Don't care about the following functions mb.free_functions('UTIL_LoadFileForMe').exclude() mb.free_functions('UTIL_FreeFile').exclude() # Exclude for now mb.free_functions('UTIL_EntitiesInSphere').exclude() mb.free_functions('UTIL_EntitiesInBox').exclude() # Add mb.free_function('StandardFilterRules').include() mb.free_function('PassServerEntityFilter').include() # //-------------------------------------------------------------------------------------------------------------------------------- # Tracing cls = mb.class_('CBaseTrace') cls.include() cls = mb.class_('CGameTrace') cls.include() cls.rename('trace_t') cls.var('m_pEnt').rename('ent') cls.var('m_pEnt').getter_call_policies = call_policies.return_value_policy(call_policies.return_by_value) cls = mb.class_('PyRay_t') cls.include() cls.rename('Ray_t') cls.vars('m_Start').rename('start') cls.vars('m_Delta').rename('delta') cls.vars('m_StartOffset').rename('startoffset') cls.vars('m_Extents').rename('extents') cls.vars('m_IsRay').rename('isray') cls.vars('m_IsSwept').rename('isswept') # //-------------------------------------------------------------------------------------------------------------------------------- # Trace Filters # By default, it's not possible to override TraceFilter methods cls = mb.class_('ITraceFilter') cls.include() cls.calldefs().exclude() tracefilters = [ 'CTraceFilter', 'CTraceFilterEntitiesOnly', 'CTraceFilterWorldOnly', 'CTraceFilterWorldAndPropsOnly', 'CTraceFilterHitAll', 'CTraceFilterSimple', 'CTraceFilterSkipTwoEntities', 'CTraceFilterSimpleList', 'CTraceFilterOnlyNPCsAndPlayer', 'CTraceFilterNoNPCsOrPlayer', 'CTraceFilterLOS', 'CTraceFilterSkipClassname', 'CTraceFilterSkipTwoClassnames', 'CTraceFilterSimpleClassnameList', 'CTraceFilterChain', 'CPyTraceFilterSimple', ] for clsname in tracefilters: self.SetupTraceFilter(mb, clsname) mb.class_('CTraceFilterSimple').rename('CTraceFilterSimpleInternal') mb.class_('CPyTraceFilterSimple').rename('CTraceFilterSimple') mb.mem_funs('GetPassEntity').call_policies = call_policies.return_value_policy(call_policies.return_by_value) mb.class_('csurface_t').include() # //-------------------------------------------------------------------------------------------------------------------------------- # Collision utils mb.free_functions('PyIntersectRayWithTriangle').include() mb.free_functions('PyIntersectRayWithTriangle').rename('IntersectRayWithTriangle') mb.free_functions('ComputeIntersectionBarycentricCoordinates').include() mb.free_functions('IntersectRayWithRay').include() mb.free_functions('IntersectRayWithSphere').include() mb.free_functions('IntersectInfiniteRayWithSphere').include() mb.free_functions('IsSphereIntersectingCone').include() mb.free_functions('IntersectRayWithPlane').include() mb.free_functions('IntersectRayWithAAPlane').include() mb.free_functions('IntersectRayWithBox').include() mb.class_('BoxTraceInfo_t').include() mb.free_functions('IntersectRayWithBox').include() mb.free_functions('IntersectRayWithOBB').include() mb.free_functions('IsSphereIntersectingSphere').include() if self.settings.branch != 'swarm': # IsBoxIntersectingSphere gives a problem mb.free_functions('IsBoxIntersectingSphere').include() mb.free_functions('IsBoxIntersectingSphereExtents').include() mb.free_functions('IsRayIntersectingSphere').include() mb.free_functions('IsCircleIntersectingRectangle').include() mb.free_functions('IsOBBIntersectingOBB').include() mb.free_functions('IsPointInCone').include() mb.free_functions('IntersectTriangleWithPlaneBarycentric').include() mb.enum('QuadBarycentricRetval_t').include() mb.free_functions('PointInQuadToBarycentric').include() mb.free_functions('PointInQuadFromBarycentric').include() mb.free_functions('TexCoordInQuadFromBarycentric').include() mb.free_functions('ComputePointFromBarycentric').include() mb.free_functions('IsRayIntersectingOBB').include() mb.free_functions('ComputeSeparatingPlane').include() mb.free_functions('IsBoxIntersectingTriangle').include() #mb.free_functions('CalcClosestPointOnTriangle').include() mb.free_functions('OBBHasFullyContainedIntersectionWithQuad').include() mb.free_functions('RayHasFullyContainedIntersectionWithQuad').include() vectorcls = mb.class_('Vector') excludetypes = [ declarated_t(vectorcls), reference_t(declarated_t(vectorcls)), reference_t(const_t(declarated_t(vectorcls))), ] vectormatcher = calldef_withtypes( excludetypes ) mb.free_functions('IsBoxIntersectingBox', vectormatcher).include() mb.free_functions('IsBoxIntersectingBoxExtents', vectormatcher).include() mb.free_functions('IsBoxIntersectingRay', vectormatcher).include() mb.free_functions('IsPointInBox', vectormatcher).include() # Prediction functions mb.free_function('GetSuppressHost').include() mb.free_function('GetSuppressHost').call_policies = call_policies.return_value_policy( call_policies.return_by_value ) if self.isserver: self.ParseServer(mb) else: self.ParseClient(mb) # Finally apply common rules to all includes functions and classes, etc. self.ApplyCommonRules(mb)
def __read_reference_type(self, attrs): return declarations.reference_t(attrs[XML_AN_TYPE])
def inst_arg_type( self, has_const ): inst_arg_type = declarations.declarated_t( self.declaration.parent ) if has_const: inst_arg_type = declarations.const_t(inst_arg_type) inst_arg_type = declarations.reference_t(inst_arg_type) return inst_arg_type
def _get_setter_type(self): return declarations.free_function_type_t( return_type=declarations.void_t() , arguments_types=[ declarations.reference_t( self._get_class_inst_type() ) , self._get_exported_var_type() ] )
def tt( type_ ): type_ = declarations.remove_reference( type_ ) type_ = declarations.remove_const( type_ ) return declarations.reference_t( type_ )
def inst_arg_type(self, has_const): inst_arg_type = declarations.declarated_t(self.declaration.parent) if has_const: inst_arg_type = declarations.const_t(inst_arg_type) inst_arg_type = declarations.reference_t(inst_arg_type) return inst_arg_type
def ParsePanels(self, mb): # Panels cls = mb.class_('DeadPanel') cls.include() cls.mem_funs('NonZero', allow_empty=True).rename('__nonzero__') cls.mem_funs('Bool', allow_empty=True).rename('__bool__') # For each panel sub class we take some default actions for cls_name in self.panel_cls_list: cls = mb.class_(cls_name) # Include everything by default cls.include() cls.no_init = False # Be selective about we need to override cls.mem_funs().virtuality = 'not virtual' cls.add_fake_base('PyPanel') wrapperpaint = self.GetWrapper( cls, 'Paint' ) wrapperpaintbackground = self.GetWrapper( cls, 'PaintBackground' ) wrapperinvalidatelayout = self.GetWrapper( cls, 'InvalidateLayout' ) cls.add_wrapper_code(r''' virtual void Paint( ) { if( !IsSBufferEnabled() || ShouldRecordSBuffer( m_PaintCallBuffer ) ) { PY_OVERRIDE_CHECK( %(cls_name)s, Paint ) PY_OVERRIDE_LOG( %(modulename)s, %(cls_name)s, Paint ) bp::override func_Paint = this->get_override( "Paint" ); if( func_Paint.ptr() != Py_None ) try { func_Paint( ); } catch(bp::error_already_set &) { PyErr_Print(); this->%(cls_name)s::Paint( ); } else this->%(cls_name)s::Paint( ); FinishRecordSBuffer( m_PaintCallBuffer ); } else if( IsSBufferEnabled() ) { DrawFromSBuffer( m_PaintCallBuffer ); } } void default_Paint( ) { %(cls_name)s::Paint( ); } virtual void PaintBackground( ) { if( !IsSBufferEnabled() || ShouldRecordSBuffer( m_PaintBackgroundCallBuffer ) ) { PY_OVERRIDE_CHECK( %(cls_name)s, PaintBackground ) PY_OVERRIDE_LOG( %(modulename)s, %(cls_name)s, PaintBackground ) bp::override func_PaintBackground = this->get_override( "PaintBackground" ); if( func_PaintBackground.ptr() != Py_None ) try { func_PaintBackground( ); } catch(bp::error_already_set &) { PyErr_Print(); this->%(pb_cls_name)s::PaintBackground( ); } else this->%(pb_cls_name)s::PaintBackground( ); FinishRecordSBuffer( m_PaintBackgroundCallBuffer ); } else if( IsSBufferEnabled() ) { DrawFromSBuffer( m_PaintBackgroundCallBuffer ); } } void default_PaintBackground( ) { %(pb_cls_name)s::PaintBackground( ); } virtual void InvalidateLayout( bool layoutNow=false, bool reloadScheme=false ) { FlushSBuffer(); PY_OVERRIDE_CHECK( %(cls_name)s, InvalidateLayout ) PY_OVERRIDE_LOG( %(modulename)s, %(cls_name)s, InvalidateLayout ) bp::override func_InvalidateLayout = this->get_override( "InvalidateLayout" ); if( func_InvalidateLayout.ptr() != Py_None ) try { func_InvalidateLayout( layoutNow, reloadScheme ); } catch(bp::error_already_set &) { PyErr_Print(); this->%(il_cls_name)s::InvalidateLayout( layoutNow, reloadScheme ); } else this->%(il_cls_name)s::InvalidateLayout( layoutNow, reloadScheme ); } void default_InvalidateLayout( bool layoutNow=false, bool reloadScheme=false ) { FlushSBuffer(); %(il_cls_name)s::InvalidateLayout( layoutNow, reloadScheme ); } ''' % { 'cls_name' : wrapperpaint.wrapped_class_identifier(), 'pb_cls_name' : wrapperpaintbackground.wrapped_class_identifier(), 'il_cls_name' : wrapperinvalidatelayout.wrapped_class_identifier(), 'modulename' : self.module_name, }) cls.add_registration_code(r''' { //::vgui::%(cls_name)s::Paint typedef void ( ::vgui::Panel::*Paint_function_type )( ) ; typedef void ( %(cls_name)s_wrapper::*default_Paint_function_type )( ) ; %(cls_name)s_exposer.def( "Paint" , Paint_function_type(&::vgui::Panel::Paint) , default_Paint_function_type(&%(cls_name)s_wrapper::default_Paint) ); } { //::vgui::%(cls_name)s::PaintBackground typedef void ( ::vgui::Panel::*PaintBackground_function_type )( ) ; typedef void ( %(cls_name)s_wrapper::*default_PaintBackground_function_type )( ) ; %(cls_name)s_exposer.def( "PaintBackground" , PaintBackground_function_type(&::vgui::Panel::PaintBackground) , default_PaintBackground_function_type(&%(cls_name)s_wrapper::default_PaintBackground) ); } { //::vgui::%(cls_name)s::InvalidateLayout typedef void ( ::vgui::Panel::*InvalidateLayout_function_type )( bool,bool ) ; typedef void ( %(cls_name)s_wrapper::*default_InvalidateLayout_function_type )( bool,bool ) ; %(cls_name)s_exposer.def( "InvalidateLayout" , InvalidateLayout_function_type(&::vgui::Panel::InvalidateLayout) , default_InvalidateLayout_function_type(&%(cls_name)s_wrapper::default_InvalidateLayout) , ( bp::arg("layoutNow")=(bool)(false), bp::arg("reloadScheme")=(bool)(false) ) ); } ''' % {'cls_name' : cls_name}, False) # By default exclude any subclass. These classes are likely controlled intern by the panel if cls.classes(allow_empty=True): cls.classes().exclude() self.AddVGUIConverter(mb, cls_name, self.novguilib, containsabstract=False) # # Add custom wrappers for functions who take keyvalues as input if self.novguilib: # No access to source code, so need to add message stuff for python here. cls.add_wrapper_code('virtual void OnMessage(const KeyValues *params, VPANEL fromPanel) {\r\n' + ' if( Panel_DispatchMessage( m_PyMessageMap, params, fromPanel ) )\r\n' + ' return;\r\n' + ' Panel::OnMessage(params, fromPanel);\r\n' + '}\r\n' + \ '\r\n' + \ 'void RegMessageMethod( const char *message, boost::python::object method, int numParams=0, \r\n' + \ ' const char *nameFirstParam="", int typeFirstParam=DATATYPE_VOID, \r\n' + \ ' const char *nameSecondParam="", int typeSecondParam=DATATYPE_VOID ) { \r\n' + \ ' py_message_entry_t entry;\r\n' + \ ' entry.method = method;\r\n' + \ ' entry.numParams = numParams;\r\n' + \ ' entry.firstParamName = nameFirstParam;\r\n' + \ ' entry.firstParamSymbol = KeyValuesSystem()->GetSymbolForString(nameFirstParam);\r\n' + \ ' entry.firstParamType = typeFirstParam;\r\n' + \ ' entry.secondParamName = nameSecondParam;\r\n' + \ ' entry.secondParamSymbol = KeyValuesSystem()->GetSymbolForString(nameSecondParam);\r\n' + \ ' entry.secondParamType = typeSecondParam;\r\n' + \ '\r\n' + \ ' GetPyMessageMap().Insert(message, entry);\r\n' + \ '}\r\n' + \ 'virtual Panel *GetPanel() { return this; }\r\n' ) cls.add_registration_code('def( "RegMessageMethod", &'+cls_name+'_wrapper::RegMessageMethod\r\n' + \ ', ( bp::arg("message"), bp::arg("method"), bp::arg("numParams")=(int)(0), bp::arg("nameFirstParam")="", bp::arg("typeFirstParam")=int(::vgui::DATATYPE_VOID), bp::arg("nameSecondParam")="", bp::arg("typeSecondParam")=int(::vgui::DATATYPE_VOID) ))' ) # Add stubs cls.add_wrapper_code('virtual void EnableSBuffer( bool bUseBuffer ) { PyPanel::EnableSBuffer( bUseBuffer ); }') cls.add_registration_code('def( "EnableSBuffer", &%(cls_name)s_wrapper::EnableSBuffer, bp::arg("bUseBuffer") )' % {'cls_name' : cls_name}) cls.add_wrapper_code('virtual bool IsSBufferEnabled() { return PyPanel::IsSBufferEnabled(); }') cls.add_registration_code('def( "IsSBufferEnabled", &%(cls_name)s_wrapper::IsSBufferEnabled )' % {'cls_name' : cls_name}) cls.add_wrapper_code('virtual void FlushSBuffer() { PyPanel::FlushSBuffer(); }') cls.add_registration_code('def( "FlushSBuffer", &%(cls_name)s_wrapper::FlushSBuffer )' % {'cls_name' : cls_name}) cls.add_wrapper_code('virtual void SetFlushedByParent( bool bEnabled ) { PyPanel::SetFlushedByParent( bEnabled ); }') cls.add_registration_code('def( "SetFlushedByParent", &%(cls_name)s_wrapper::SetFlushedByParent, bp::arg("bEnabled") )' % {'cls_name' : cls_name}) # Tweak Panels # Used by converters + special method added in the wrapper # Don't include here if not self.novguilib: mb.mem_funs('GetPySelf').exclude() mb.mem_funs('PyDestroyPanel').exclude() # Exclude message stuff. Maybe look into wrapping this in a nice way mb.mem_funs( 'AddToMap' ).exclude() mb.mem_funs( 'ChainToMap' ).exclude() mb.mem_funs( 'GetMessageMap' ).exclude() mb.mem_funs( 'AddToAnimationMap' ).exclude() mb.mem_funs( 'ChainToAnimationMap' ).exclude() mb.mem_funs( 'GetAnimMap' ).exclude() mb.mem_funs( 'KB_AddToMap' ).exclude() mb.mem_funs( 'KB_ChainToMap' ).exclude() mb.mem_funs( 'KB_AddBoundKey' ).exclude() mb.mem_funs( 'GetKBMap' ).exclude() mb.mem_funs( lambda decl: 'GetVar_' in decl.name ).exclude() mb.classes( lambda decl: 'PanelMessageFunc_' in decl.name ).exclude() mb.classes( lambda decl: '_Register' in decl.name ).exclude() mb.classes( lambda decl: 'PanelAnimationVar_' in decl.name ).exclude() mb.vars( lambda decl: '_register' in decl.name ).exclude() mb.vars( lambda decl: 'm_Register' in decl.name ).exclude() # Don't need the following: menu = mb.class_('Menu') keybindindcontexthandle = mb.enum('KeyBindingContextHandle_t') excludetypes = [ pointer_t(const_t(declarated_t(menu))), pointer_t(declarated_t(menu)), reference_t(declarated_t(menu)), pointer_t(declarated_t(mb.class_('IPanelAnimationPropertyConverter'))), declarated_t(keybindindcontexthandle), ] mb.calldefs(calldef_withtypes(excludetypes), allow_empty=True).exclude()