Exemplo n.º 1
0
    def ParseTextEntry(self, mb):
        # List of overridables
        mb.mem_funs('SetText').virtuality = 'virtual'
        mb.mem_funs('MoveCursor').virtuality = 'virtual'
        mb.mem_funs('SetDisabledBgColor').virtuality = 'virtual'
        mb.mem_funs('SetMultiline').virtuality = 'virtual'
        mb.mem_funs('SetVerticalScrollbar').virtuality = 'virtual'

        #
        mb.mem_funs('GetEditMenu').exclude(
        )  # Exclude for now, add back later when we found out call policies.

        mb.mem_funs('GetSelectedRange').add_transformation(
            FT.output('cx0'), FT.output('cx1'))
        mb.mem_funs('CursorToPixelSpace').add_transformation(
            FT.inout('cx'), FT.inout('cy'))
        mb.mem_funs('AddAnotherLine').add_transformation(
            FT.output('cx'), FT.output('cy'))
        mb.mem_funs('GetStartDrawIndex').add_transformation(
            FT.output('lineBreakIndexIndex'))

        charstrexcludetypes = [pointer_t(const_t(declarated_t(char_t())))]

        # Wrap GetText manual
        cls = mb.class_('TextEntry')
        cls.mem_funs('GetText').exclude()
        cls.add_wrapper_code(
            'boost::python::object GetText() {\r\n' + \
            '    const char *buf = (const char *)malloc( (GetTextLength()+1)*sizeof(char) );\r\n' + \
            '    TextEntry::GetText((char *)buf, GetTextLength()+1);\r\n' + \
            '    boost::python::object rv(buf);\r\n' + \
            '    delete buf;\r\n' + \
            '    return rv;\r\n' + \
            '}'
        )

        cls.add_registration_code(
            'def( \r\n' + \
            '    "GetText"\r\n' + \
            '    , (boost::python::object ( TextEntry_wrapper::* )())( &TextEntry_wrapper::GetText ) )'
        )

        cls.calldefs(
            name='SetText',
            function=calldef_withtypes(charstrexcludetypes)).exclude()
        cls.calldefs(
            name='InsertString',
            function=calldef_withtypes(charstrexcludetypes)).exclude()

        # RichText
        cls = mb.class_('RichText')
        cls.calldefs(
            name='SetText',
            function=calldef_withtypes(charstrexcludetypes)).exclude()
        cls.calldefs(
            name='InsertString',
            function=calldef_withtypes(charstrexcludetypes)).exclude()
        if self.settings.branch == 'swarm':
            mb.mem_funs('GetScrollBar').exclude()
Exemplo n.º 2
0
    def ParseTextEntry(self, mb):
        # List of overridables
        mb.mem_funs('SetText').virtuality = 'virtual'
        mb.mem_funs('MoveCursor').virtuality = 'virtual'
        mb.mem_funs('SetDisabledBgColor').virtuality = 'virtual'
        mb.mem_funs('SetMultiline').virtuality = 'virtual'
        mb.mem_funs('SetVerticalScrollbar').virtuality = 'virtual'

        #
        mb.mem_funs('GetEditMenu').exclude()        # Exclude for now, add back later when we found out call policies.
        
        mb.mem_funs( 'GetSelectedRange' ).add_transformation( FT.output('cx0'), FT.output('cx1') )   
        mb.mem_funs( 'CursorToPixelSpace' ).add_transformation( FT.inout('cx'), FT.inout('cy') ) 
        mb.mem_funs( 'AddAnotherLine' ).add_transformation( FT.output('cx'), FT.output('cy') ) 
        mb.mem_funs( 'GetStartDrawIndex' ).add_transformation( FT.output('lineBreakIndexIndex') )
        
        charstrexcludetypes = [pointer_t(const_t(declarated_t(char_t())))]
        
        # Wrap GetText manual
        cls = mb.class_('TextEntry')
        cls.mem_funs('GetText').exclude()
        cls.add_wrapper_code(
            'boost::python::object GetText() {\r\n' + \
            '    const char *buf = (const char *)malloc( (GetTextLength()+1)*sizeof(char) );\r\n' + \
            '    TextEntry::GetText((char *)buf, GetTextLength()+1);\r\n' + \
            '    boost::python::object rv(buf);\r\n' + \
            '    delete buf;\r\n' + \
            '    return rv;\r\n' + \
            '}'
        )
        
        cls.add_registration_code(
            'def( \r\n' + \
            '    "GetText"\r\n' + \
            '    , (boost::python::object ( TextEntry_wrapper::* )())( &TextEntry_wrapper::GetText ) )'
        )
        
        cls.calldefs(name='SetText', function=calldef_withtypes(charstrexcludetypes)).exclude()
        cls.calldefs(name='InsertString', function=calldef_withtypes(charstrexcludetypes)).exclude()

        # RichText
        cls = mb.class_('RichText')
        cls.calldefs(name='SetText', function=calldef_withtypes(charstrexcludetypes)).exclude()
        cls.calldefs(name='InsertString', function=calldef_withtypes(charstrexcludetypes)).exclude()
        if self.settings.branch == 'swarm':
            mb.mem_funs('GetScrollBar').exclude()
Exemplo n.º 3
0
 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)
Exemplo n.º 4
0
 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 Parse(self, mb):
        # Exclude everything by default
        mb.decls().exclude() 
        
        # POSIX compiler model_t fix ( ok to do? maybe find another fix )
        mb.add_declaration_code( '#ifdef POSIX\r\n' + \
                             'typedef struct model_t {};\r\n' + \
                             '#endif // POSIX\r\n'
                           )
                           
        # Filesystem functions
        mb.free_function('PyGetModPath').include()
        mb.free_function('PyGetModPath').rename('GetModPath')
        mb.free_function('PyAsyncFinishAllWrites').include()
        mb.free_function('PyAsyncFinishAllWrites').rename('AsyncFinishAllWrites')
        
        # Engine functions
        mb.free_function('GetLevelName').include()    
        
        # Time
        mb.free_function('Plat_FloatTime').include()
        mb.free_function('Plat_MSTime').include()
        
        # Precache functions
        mb.free_function('PrecacheMaterial').include()
        if self.settings.branch == 'swarm':
            mb.free_function('PrecacheEffect').include()
        
        # ConVar wrapper
        cls = mb.class_('PyConVar')
        cls.include()
        cls.rename('ConVar')
        cls.mem_funs().virtuality = 'not virtual'
        cls.mem_fun('Shutdown').exclude()
        
        mb.free_function('PyShutdownConVar').include()
        mb.free_function('PyShutdownConCommand').include()

        # Don't want to include ConVar, so add methods manually...
        # Can't this be done automatically in py++?
        cls.add_registration_code(
            '''def( 
            "AddFlags"
            , (void ( ::ConVar::* )( int ) )( &::ConVar::AddFlags )
            , ( bp::arg("flags") ) )''')
        cls.add_registration_code(
            '''def( 
            "GetBool"
            , (bool ( ::ConVar::* )(  ) const)( &::ConVar::GetBool ) )''')
        cls.add_registration_code(
            '''def( 
            "GetDefault"
            , (char const * ( ::ConVar::* )(  ) const)( &::ConVar::GetDefault ) )''')
        cls.add_registration_code(
            '''def( 
            "GetFloat"
            , (float ( ::ConVar::* )(  ) const)( &::ConVar::GetFloat ) )''')
        cls.add_registration_code(
            '''def( 
            "GetHelpText"
            , (char const * ( ::ConVar::* )(  ) const)( &::ConVar::GetHelpText ) )''')
        cls.add_registration_code(
            '''def( 
            "GetInt"
            , (int ( ::ConVar::* )(  ) const)( &::ConVar::GetInt ) )''')
        cls.add_registration_code(
            '''def( 
            "GetMax"
            , (bool ( ::ConVar::* )( float & ) const)( &::ConVar::GetMax )
            , ( bp::arg("maxVal") ) )''')
        cls.add_registration_code(
            '''def( 
            "GetMin"
            , (bool ( ::ConVar::* )( float & ) const)( &::ConVar::GetMin )
            , ( bp::arg("minVal") ) )''')
        cls.add_registration_code(
            '''def( 
            "GetName"
            , (char const * ( ::ConVar::* )(  ) const)( &::ConVar::GetName ) )''')
        cls.add_registration_code(
            '''def( 
            "GetString"
            , (char const * ( ::ConVar::* )(  ) const)( &::ConVar::GetString ) )''')
        cls.add_registration_code(
            '''def( 
            "IsCommand"
            , (bool ( ::ConVar::* )(  ) const)( &::ConVar::IsCommand ) )''')
        cls.add_registration_code(
            '''def( 
            "IsFlagSet"
            , (bool ( ::ConVar::* )( int ) const)( &::ConVar::IsFlagSet )
            , ( bp::arg("flag") ) )''')
        cls.add_registration_code(
            '''def( 
            "IsRegistered"
            , (bool ( ::ConVar::* )(  ) const)( &::ConVar::IsRegistered ) )''')
        cls.add_registration_code(
            '''def( 
            "Revert"
            , (void ( ::ConVar::* )(  ) )( &::ConVar::Revert ) )''')

        # ConVarRef
        mb.class_('ConVarRef').include()
        mb.mem_funs('GetLinkedConVar').exclude()
        
        # CCommand
        cls = mb.class_('CCommand')
        cls.include()
        cls.mem_funs('Tokenize').exclude()
        cls.mem_funs('ArgV').exclude()
        cls.mem_funs('DefaultBreakSet').exclude()
        
        cls.add_registration_code(
         '''def( 
            "__len__"
            , (int ( ::CCommand::* )(  ) const)( &::CCommand::ArgC ) )''')
        
        # PyConCommand
        cls = mb.class_('PyConCommand')
        cls.include()
        cls.rename('ConCommand')
        cls.var('m_pyCommandCallback').exclude()         # Must be excluded, or else things get broken without errors/warnings!
        cls.mem_funs('Dispatch').exclude()               # Must be excluded, or else things get broken without errors/warnings!
        cls.mem_funs('AutoCompleteSuggest').exclude()
        
        # Virtuality screws up ConCommand. 
        cls.mem_funs().virtuality = 'not virtual' 
        
        # Sending messages
        if self.isserver:
            mb.free_functions('PySendUserMessage').include()
            mb.free_functions('PySendUserMessage').rename('SendUserMessage')
            
        # filters
        mb.class_('IRecipientFilter').include()
        mb.class_('IRecipientFilter').mem_funs().virtuality = 'not virtual' 
        if self.isserver:
            mb.class_('CRecipientFilter').include()
            mb.class_('CRecipientFilter').mem_funs().virtuality = 'not virtual' 
        else:
            mb.class_('C_RecipientFilter').include()
            mb.class_('C_RecipientFilter').mem_funs().virtuality = 'not virtual' 
            
            mb.class_('CLocalPlayerFilter').include()
            #mb.class_('CLocalPlayerFilter').mem_funs().virtuality = 'not virtual' 
            
        # Shared filters
        mb.class_('CSingleUserRecipientFilter').include()
        mb.class_('CBroadcastRecipientFilter').include()
        mb.class_('CReliableBroadcastRecipientFilter').include()
        mb.class_('CPASFilter').include()
        mb.class_('CPASAttenuationFilter').include()
        mb.class_('CPVSFilter').include()
            
        # Gameevents
        mb.class_('PyGameEventListener').include()
        mb.class_('PyGameEventListener').rename('GameEventListener')
        mb.class_('PyGameEventListener').mem_fun('PyFireGameEvent').rename('FireGameEvent')
        mb.class_('PyGameEventListener').add_registration_code('def( "ListenForGameEvent", (void ( ::PyGameEventListener::* )( char const * ) )( &::PyGameEventListener::ListenForGameEvent ), bp::arg("name") ) ')
        mb.class_('PyGameEventListener').add_registration_code('def( "StopListeningForAllEvents", (void ( ::PyGameEventListener::* )() )( &::PyGameEventListener::StopListeningForAllEvents ) ) ')
        
        mb.class_('PyGameEvent').include()
        mb.class_('PyGameEvent').rename('GameEvent')
        mb.class_('PyGameEvent').mem_fun('Init').exclude()
        mb.class_('PyGameEvent').mem_fun('GetEvent').exclude()
        
        if self.isserver:
            mb.free_function('PyFireGameEvent').include()
            mb.free_function('PyFireGameEvent').rename('FireGameEvent')
        else:
            mb.free_function('PyFireGameEventClientSide').include()
            mb.free_function('PyFireGameEventClientSide').rename('FireGameEventClientSide')
                
        # Player info
        mb.class_('py_player_info_s').include()
        mb.class_('py_player_info_s').rename('PlayerInfo')
        
        # Get map header
        mb.free_function('PyGetMapHeader').include()
        mb.free_function('PyGetMapHeader').rename('GetMapHeader')
        if self.settings.branch == 'swarm':
            cls = mb.class_('BSPHeader_t')
        else:
            cls = mb.class_('dheader_t')
        cls.include()
        if self.settings.branch == 'swarm':
            cls.var('m_nVersion').rename('version')
        cls.var('mapRevision').rename('maprevision')
        
        mb.class_('lump_t').include()
        mb.mem_funs('GetBaseMap').exclude()
        mb.vars('m_DataMap').exclude()
        
        # Content mounting
        mb.free_function('PyAddSearchPath').include()
        mb.free_function('PyAddSearchPath').rename('AddSearchPath')
        mb.free_function('PyRemoveSearchPath').include()
        mb.free_function('PyRemoveSearchPath').rename('RemoveSearchPath')
        mb.free_function('PyGetSearchPath').include()
        mb.free_function('PyGetSearchPath').rename('GetSearchPath')
        
        mb.enum('SearchPathAdd_t').include()
        mb.enum('FilesystemMountRetval_t').include()
        
        # GameSystem
        mb.class_('CBaseGameSystem').include()
        mb.class_('CBaseGameSystemPerFrame').include()
        mb.class_('CAutoGameSystem').include()
        mb.class_('CAutoGameSystemPerFrame').include()
        mb.mem_funs('IsPerFrame').virtuality = 'not virtual' 
        mb.mem_funs('SafeRemoveIfDesired').virtuality = 'not virtual'
        mb.class_('CAutoGameSystem').rename('AutoGameSystem')
        mb.class_('CAutoGameSystemPerFrame').rename('AutoGameSystemPerFrame')
        
        cls = mb.class_('IGameSystem')
        cls.include()
        cls.mem_funs().virtuality = 'not virtual' 
        if self.isserver:
            cls.mem_funs('RunCommandPlayer').call_policies = call_policies.return_value_policy(call_policies.return_by_value) 
            cls.mem_funs('RunCommandUserCmd').call_policies = call_policies.return_value_policy(call_policies.return_by_value) 
            
        # Engine
        if self.isserver:
            cls = mb.class_('PyVEngineServer')
            cls.rename('VEngineServer')
            cls.include()
        else:
            cls = mb.class_('PyVEngineClient')
            cls.rename('VEngineClient')
            cls.include()
            cls.mem_funs('LoadModel').call_policies = call_policies.return_value_policy(call_policies.return_by_value) 
        mb.add_registration_code( "bp::scope().attr( \"engine\" ) = boost::ref(pyengine);" )   
        
        # Command line access
        cls = mb.class_('ICommandLine')
        cls.include()
        cls.mem_funs().virtuality = 'not virtual'
        
        if self.settings.branch == 'swarm':
            mb.free_function('CommandLine').include()
            mb.free_function('CommandLine').call_policies = call_policies.return_value_policy(call_policies.reference_existing_object)
        else:
            mb.free_function('CommandLine_Tier0').include()
            mb.free_function('CommandLine_Tier0').rename('CommandLine')
            mb.free_function('CommandLine_Tier0').call_policies = call_policies.return_value_policy(call_policies.reference_existing_object)
            
        # Accessing model info
        cls = mb.class_('PyVModelInfo')
        cls.rename('VModelInfo')
        cls.include()
        cls.mem_funs('GetModel').call_policies = call_policies.return_value_policy(call_policies.return_by_value) 
        cls.mem_funs('FindOrLoadModel').call_policies = call_policies.return_value_policy(call_policies.return_by_value) 
        mb.add_registration_code( "bp::scope().attr( \"modelinfo\" ) = boost::ref(pymodelinfo);" )   
        
        if self.isserver:
            mb.free_function('PyMapEntity_ParseAllEntities').include()
            mb.free_function('PyMapEntity_ParseAllEntities').rename('MapEntity_ParseAllEntities')
            
            cls = mb.class_('IMapEntityFilter')
            cls.include()
            cls.mem_fun('CreateNextEntity').call_policies = call_policies.return_value_policy(call_policies.return_by_value) 
            
            mb.class_('CMapEntityRef').include()
            mb.free_function('PyGetMapEntityRef').include()
            mb.free_function('PyGetMapEntityRef').rename('GetMapEntityRef')
            mb.free_function('PyGetMapEntityRefIteratorHead').include()
            mb.free_function('PyGetMapEntityRefIteratorHead').rename('GetMapEntityRefIteratorHead')
            mb.free_function('PyGetMapEntityRefIteratorNext').include()
            mb.free_function('PyGetMapEntityRefIteratorNext').rename('GetMapEntityRefIteratorNext')
            
            # Edicts
            cls = mb.class_('edict_t')
            cls.include()
            cls.mem_fun('GetCollideable').exclude()
            
            # Event queue
            mb.free_function('ServiceEventQueue').include()
            
            cls = mb.class_('CServerGameDLL')
            cls.include()
            cls.mem_funs().virtuality = 'not virtual'
            
            if self.settings.branch == 'swarm':
                cls.mem_fun('FindLaunchOptionByValue').call_policies = call_policies.return_value_policy(call_policies.return_by_value)
            if self.settings.branch == 'source2013':
                cls.mem_fun('GetServerGCLobby').exclude()
            cls.mem_fun('GetAllServerClasses').exclude()
            cls.mem_fun('GetStandardSendProxies').exclude()
            cls.mem_fun('SaveInit').exclude()
            
            mb.add_declaration_code('extern CServerGameDLL g_ServerGameDLL;')
            mb.add_registration_code("bp::scope().attr( \"servergamedll\" ) = boost::ref(g_ServerGameDLL);")
            
        if self.isclient:
            cls = mb.class_('CClientSteamContext')
            cls.include()
            cls.mem_fun('InstallCallback').exclude()
            cls.mem_fun('RemoveCallback').exclude()
            cls.mem_fun('Activate').exclude()
            cls.mem_fun('Shutdown').exclude()
            
            mb.free_function('ClientSteamContext').include()
            mb.free_function('ClientSteamContext').call_policies = call_policies.return_value_policy(call_policies.reference_existing_object)
            
        # model_t
        cls = mb.class_('wrap_model_t')
        cls.include()
        cls.rename('model_t')
        cls.calldefs('wrap_model_t').exclude()
        cls.no_init = True
        cls.vars('pModel').exclude()

        mb.add_registration_code( "ptr_model_t_to_wrap_model_t();" )
        mb.add_registration_code( "const_ptr_model_t_to_wrap_model_t();" )
        mb.add_registration_code( "wrap_model_t_to_model_t();" )
        
        # LUMPS
        mb.add_registration_code( "bp::scope().attr( \"LUMP_ENTITIES\" ) = (int)LUMP_ENTITIES;" )
        
        # Defines
        mb.add_registration_code( "bp::scope().attr( \"FCVAR_NONE\" ) = (int)FCVAR_NONE;" )
        
        mb.add_registration_code( "bp::scope().attr( \"FCVAR_UNREGISTERED\" ) = (int)FCVAR_UNREGISTERED;" )
        mb.add_registration_code( "bp::scope().attr( \"FCVAR_DEVELOPMENTONLY\" ) = (int)FCVAR_DEVELOPMENTONLY;" )
        mb.add_registration_code( "bp::scope().attr( \"FCVAR_GAMEDLL\" ) = (int)FCVAR_GAMEDLL;" )
        mb.add_registration_code( "bp::scope().attr( \"FCVAR_CLIENTDLL\" ) = (int)FCVAR_CLIENTDLL;" )
        mb.add_registration_code( "bp::scope().attr( \"FCVAR_HIDDEN\" ) = (int)FCVAR_HIDDEN;" )
        
        mb.add_registration_code( "bp::scope().attr( \"FCVAR_PROTECTED\" ) = (int)FCVAR_PROTECTED;" )
        mb.add_registration_code( "bp::scope().attr( \"FCVAR_SPONLY\" ) = (int)FCVAR_SPONLY;" )
        mb.add_registration_code( "bp::scope().attr( \"FCVAR_ARCHIVE\" ) = (int)FCVAR_ARCHIVE;" )
        mb.add_registration_code( "bp::scope().attr( \"FCVAR_NOTIFY\" ) = (int)FCVAR_NOTIFY;" )
        mb.add_registration_code( "bp::scope().attr( \"FCVAR_USERINFO\" ) = (int)FCVAR_USERINFO;" )
        mb.add_registration_code( "bp::scope().attr( \"FCVAR_CHEAT\" ) = (int)FCVAR_CHEAT;" )
        
        mb.add_registration_code( "bp::scope().attr( \"FCVAR_PRINTABLEONLY\" ) = (int)FCVAR_PRINTABLEONLY;" )
        mb.add_registration_code( "bp::scope().attr( \"FCVAR_UNLOGGED\" ) = (int)FCVAR_UNLOGGED;" )
        mb.add_registration_code( "bp::scope().attr( \"FCVAR_NEVER_AS_STRING\" ) = (int)FCVAR_NEVER_AS_STRING;" )
        
        mb.add_registration_code( "bp::scope().attr( \"FCVAR_REPLICATED\" ) = (int)FCVAR_REPLICATED;" )
        mb.add_registration_code( "bp::scope().attr( \"FCVAR_DEMO\" ) = (int)FCVAR_DEMO;" )
        mb.add_registration_code( "bp::scope().attr( \"FCVAR_DONTRECORD\" ) = (int)FCVAR_DONTRECORD;" )
        mb.add_registration_code( "bp::scope().attr( \"FCVAR_NOT_CONNECTED\" ) = (int)FCVAR_NOT_CONNECTED;" )
        mb.add_registration_code( "bp::scope().attr( \"FCVAR_ARCHIVE_XBOX\" ) = (int)FCVAR_ARCHIVE_XBOX;" )
        mb.add_registration_code( "bp::scope().attr( \"FCVAR_SERVER_CAN_EXECUTE\" ) = (int)FCVAR_SERVER_CAN_EXECUTE;" )
        mb.add_registration_code( "bp::scope().attr( \"FCVAR_SERVER_CANNOT_QUERY\" ) = (int)FCVAR_SERVER_CANNOT_QUERY;" )
        mb.add_registration_code( "bp::scope().attr( \"FCVAR_CLIENTCMD_CAN_EXECUTE\" ) = (int)FCVAR_CLIENTCMD_CAN_EXECUTE;" )
        
        # Excludes
        excludetypes = [
            pointer_t(declarated_t(mb.class_('CTeam' if self.isserver else 'C_Team'))),
        ]
        mb.calldefs( calldef_withtypes( excludetypes ) ).exclude()
Exemplo n.º 6
0
    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()
Exemplo n.º 7
0
    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()
Exemplo n.º 8
0
    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()
Exemplo n.º 9
0
    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)
Exemplo n.º 10
0
    def Parse(self, mb):
        # Exclude everything by default
        mb.decls().exclude()

        # POSIX compiler model_t fix ( ok to do? maybe find another fix )
        mb.add_declaration_code( '#ifdef POSIX\r\n' + \
                             'typedef struct model_t {};\r\n' + \
                             '#endif // POSIX\r\n'
                           )

        # Filesystem functions
        mb.free_function('PyGetModPath').include()
        mb.free_function('PyGetModPath').rename('GetModPath')
        mb.free_function('PyAsyncFinishAllWrites').include()
        mb.free_function('PyAsyncFinishAllWrites').rename(
            'AsyncFinishAllWrites')

        # Engine functions
        mb.free_function('GetLevelName').include()

        # Downloadables
        if self.isserver:
            mb.free_function('AddToDownloadables').include()

        # Time
        mb.free_function('Plat_FloatTime').include()
        mb.free_function('Plat_MSTime').include()

        # Precache functions
        mb.free_function('PrecacheMaterial').include()

        # ConVar wrapper
        cls = mb.class_('PyConVar')
        cls.include()
        cls.rename('ConVar')
        cls.mem_funs().virtuality = 'not virtual'
        cls.mem_fun('Shutdown').exclude()

        mb.free_function('PyShutdownConVar').include()
        mb.free_function('PyShutdownConCommand').include()

        # Don't want to include ConVar, so add methods manually...
        # Can't this be done automatically in py++?
        cls.add_registration_code('''def( 
            "AddFlags"
            , (void ( ::ConVar::* )( int ) )( &::ConVar::AddFlags )
            , ( bp::arg("flags") ) )''')
        cls.add_registration_code('''def( 
            "GetBool"
            , (bool ( ::ConVar::* )(  ) const)( &::ConVar::GetBool ) )''')
        cls.add_registration_code('''def( 
            "GetDefault"
            , (char const * ( ::ConVar::* )(  ) const)( &::ConVar::GetDefault ) )'''
                                  )
        cls.add_registration_code('''def( 
            "GetFloat"
            , (float ( ::ConVar::* )(  ) const)( &::ConVar::GetFloat ) )''')
        cls.add_registration_code('''def( 
            "GetHelpText"
            , (char const * ( ::ConVar::* )(  ) const)( &::ConVar::GetHelpText ) )'''
                                  )
        cls.add_registration_code('''def( 
            "GetInt"
            , (int ( ::ConVar::* )(  ) const)( &::ConVar::GetInt ) )''')
        cls.add_registration_code('''def( 
            "GetMax"
            , (bool ( ::ConVar::* )( float & ) const)( &::ConVar::GetMax )
            , ( bp::arg("maxVal") ) )''')
        cls.add_registration_code('''def( 
            "GetMin"
            , (bool ( ::ConVar::* )( float & ) const)( &::ConVar::GetMin )
            , ( bp::arg("minVal") ) )''')
        cls.add_registration_code('''def( 
            "GetName"
            , (char const * ( ::ConVar::* )(  ) const)( &::ConVar::GetName ) )'''
                                  )
        cls.add_registration_code('''def( 
            "GetString"
            , (char const * ( ::ConVar::* )(  ) const)( &::ConVar::GetString ) )'''
                                  )
        cls.add_registration_code('''def( 
            "IsCommand"
            , (bool ( ::ConVar::* )(  ) const)( &::ConVar::IsCommand ) )''')
        cls.add_registration_code('''def( 
            "IsFlagSet"
            , (bool ( ::ConVar::* )( int ) const)( &::ConVar::IsFlagSet )
            , ( bp::arg("flag") ) )''')
        cls.add_registration_code('''def( 
            "IsRegistered"
            , (bool ( ::ConVar::* )(  ) const)( &::ConVar::IsRegistered ) )''')
        cls.add_registration_code('''def( 
            "Revert"
            , (void ( ::ConVar::* )(  ) )( &::ConVar::Revert ) )''')

        # ConVarRef
        mb.class_('ConVarRef').include()
        mb.mem_funs('GetLinkedConVar').exclude()

        # CCommand
        cls = mb.class_('CCommand')
        cls.include()
        cls.mem_funs('Tokenize').exclude()
        cls.mem_funs('ArgV').exclude()
        cls.mem_funs('DefaultBreakSet').exclude()

        cls.add_registration_code('''def( 
            "__len__"
            , (int ( ::CCommand::* )(  ) const)( &::CCommand::ArgC ) )''')

        # PyConCommand
        cls = mb.class_('PyConCommand')
        cls.include()
        cls.rename('ConCommand')
        cls.var('m_pyCommandCallback').exclude(
        )  # Must be excluded, or else things get broken without errors/warnings!
        cls.mem_funs('Dispatch').exclude(
        )  # Must be excluded, or else things get broken without errors/warnings!
        cls.mem_funs('AutoCompleteSuggest').exclude()

        # Virtuality screws up ConCommand.
        cls.mem_funs().virtuality = 'not virtual'

        # Sending messages
        if self.isserver:
            mb.free_functions('PySendUserMessage').include()
            mb.free_functions('PySendUserMessage').rename('SendUserMessage')

        # filters
        mb.class_('IRecipientFilter').include()
        mb.class_('IRecipientFilter').mem_funs().virtuality = 'not virtual'
        if self.isserver:
            mb.class_('CRecipientFilter').include()
            mb.class_('CRecipientFilter').mem_funs().virtuality = 'not virtual'
        else:
            mb.class_('C_RecipientFilter').include()
            mb.class_(
                'C_RecipientFilter').mem_funs().virtuality = 'not virtual'

            mb.class_('CLocalPlayerFilter').include()
            #mb.class_('CLocalPlayerFilter').mem_funs().virtuality = 'not virtual'

        # Shared filters
        mb.class_('CSingleUserRecipientFilter').include()
        mb.class_('CBroadcastRecipientFilter').include()
        mb.class_('CReliableBroadcastRecipientFilter').include()
        mb.class_('CPASFilter').include()
        mb.class_('CPASAttenuationFilter').include()
        mb.class_('CPVSFilter').include()

        # Gameevents
        mb.class_('PyGameEventListener').include()
        mb.class_('PyGameEventListener').rename('GameEventListener')
        mb.class_('PyGameEventListener').mem_fun('PyFireGameEvent').rename(
            'FireGameEvent')
        mb.class_('PyGameEventListener').add_registration_code(
            'def( "ListenForGameEvent", (void ( ::PyGameEventListener::* )( char const * ) )( &::PyGameEventListener::ListenForGameEvent ), bp::arg("name") ) '
        )
        mb.class_('PyGameEventListener').add_registration_code(
            'def( "StopListeningForAllEvents", (void ( ::PyGameEventListener::* )() )( &::PyGameEventListener::StopListeningForAllEvents ) ) '
        )

        mb.class_('PyGameEvent').include()
        mb.class_('PyGameEvent').rename('GameEvent')
        mb.class_('PyGameEvent').mem_fun('Init').exclude()
        mb.class_('PyGameEvent').mem_fun('GetEvent').exclude()

        if self.isserver:
            mb.free_function('PyFireGameEvent').include()
            mb.free_function('PyFireGameEvent').rename('FireGameEvent')
        else:
            mb.free_function('PyFireGameEventClientSide').include()
            mb.free_function('PyFireGameEventClientSide').rename(
                'FireGameEventClientSide')

        # Player info
        mb.class_('py_player_info_s').include()
        mb.class_('py_player_info_s').rename('PlayerInfo')

        # Get map header
        mb.free_function('PyGetMapHeader').include()
        mb.free_function('PyGetMapHeader').rename('GetMapHeader')
        if self.settings.branch == 'swarm':
            mb.class_('BSPHeader_t').include()
        else:
            mb.class_('dheader_t').include()
        mb.class_('lump_t').include()
        mb.mem_funs('GetBaseMap').exclude()
        mb.vars('m_DataMap').exclude()

        # Content mounting
        mb.free_function('PyAddSearchPath').include()
        mb.free_function('PyAddSearchPath').rename('AddSearchPath')
        mb.free_function('PyRemoveSearchPath').include()
        mb.free_function('PyRemoveSearchPath').rename('RemoveSearchPath')
        mb.free_function('PyGetSearchPath').include()
        mb.free_function('PyGetSearchPath').rename('GetSearchPath')
        mb.free_function('HasApp').include()
        mb.free_function('GetAppStatus').include()

        mb.enum('SearchPathAdd_t').include()
        mb.enum('FilesystemMountRetval_t').include()
        mb.enum('MountApps').include()
        mb.enum('AppStatus').include()

        # GameSystem
        mb.class_('CBaseGameSystem').include()
        mb.class_('CBaseGameSystemPerFrame').include()
        mb.class_('CAutoGameSystem').include()
        mb.class_('CAutoGameSystemPerFrame').include()
        mb.mem_funs('IsPerFrame').virtuality = 'not virtual'
        mb.mem_funs('SafeRemoveIfDesired').virtuality = 'not virtual'
        mb.class_('CAutoGameSystem').rename('AutoGameSystem')
        mb.class_('CAutoGameSystemPerFrame').rename('AutoGameSystemPerFrame')

        cls = mb.class_('IGameSystem')
        cls.include()
        cls.mem_funs().virtuality = 'not virtual'
        if self.isserver:
            cls.mem_funs('RunCommandPlayer'
                         ).call_policies = call_policies.return_value_policy(
                             call_policies.return_by_value)
            cls.mem_funs('RunCommandUserCmd'
                         ).call_policies = call_policies.return_value_policy(
                             call_policies.return_by_value)

        # Engine
        if self.isserver:
            cls = mb.class_('PyVEngineServer')
            cls.rename('VEngineServer')
            cls.include()
        else:
            cls = mb.class_('PyVEngineClient')
            cls.rename('VEngineClient')
            cls.include()
            cls.mem_funs(
                'LoadModel').call_policies = call_policies.return_value_policy(
                    call_policies.return_by_value)
        mb.add_registration_code(
            "bp::scope().attr( \"engine\" ) = boost::ref(pyengine);")

        # Command line access
        cls = mb.class_('ICommandLine')
        cls.include()
        cls.mem_funs().virtuality = 'not virtual'

        if self.settings.branch == 'swarm':
            mb.free_function('CommandLine').include()
            mb.free_function(
                'CommandLine'
            ).call_policies = call_policies.return_value_policy(
                call_policies.reference_existing_object)
        else:
            mb.free_function('CommandLine_Tier0').include()
            mb.free_function('CommandLine_Tier0').rename('CommandLine')
            mb.free_function(
                'CommandLine_Tier0'
            ).call_policies = call_policies.return_value_policy(
                call_policies.reference_existing_object)

        # Accessing model info
        cls = mb.class_('PyVModelInfo')
        cls.rename('VModelInfo')
        cls.include()
        cls.mem_funs(
            'GetModel').call_policies = call_policies.return_value_policy(
                call_policies.return_by_value)
        cls.mem_funs('FindOrLoadModel'
                     ).call_policies = call_policies.return_value_policy(
                         call_policies.return_by_value)
        mb.add_registration_code(
            "bp::scope().attr( \"modelinfo\" ) = boost::ref(pymodelinfo);")

        if self.isserver:
            mb.free_function('PyMapEntity_ParseAllEntities').include()
            mb.free_function('PyMapEntity_ParseAllEntities').rename(
                'MapEntity_ParseAllEntities')

            cls = mb.class_('IMapEntityFilter')
            cls.include()
            cls.mem_fun('CreateNextEntity'
                        ).call_policies = call_policies.return_value_policy(
                            call_policies.return_by_value)

            mb.class_('CMapEntityRef').include()
            mb.free_function('PyGetMapEntityRef').include()
            mb.free_function('PyGetMapEntityRef').rename('GetMapEntityRef')
            mb.free_function('PyGetMapEntityRefIteratorHead').include()
            mb.free_function('PyGetMapEntityRefIteratorHead').rename(
                'GetMapEntityRefIteratorHead')
            mb.free_function('PyGetMapEntityRefIteratorNext').include()
            mb.free_function('PyGetMapEntityRefIteratorNext').rename(
                'GetMapEntityRefIteratorNext')

            # Edicts
            cls = mb.class_('edict_t')
            cls.include()
            cls.mem_fun('GetCollideable').exclude()

            # Event queue
            mb.free_function('ServiceEventQueue').include()

            cls = mb.class_('CServerGameDLL')
            cls.include()
            cls.mem_funs().virtuality = 'not virtual'

            if self.settings.branch == 'swarm':
                cls.mem_fun(
                    'FindLaunchOptionByValue'
                ).call_policies = call_policies.return_value_policy(
                    call_policies.return_by_value)
            if self.settings.branch == 'source2013':
                cls.mem_fun('GetServerGCLobby').exclude()
            cls.mem_fun('GetAllServerClasses').exclude()
            cls.mem_fun('GetStandardSendProxies').exclude()
            cls.mem_fun('SaveInit').exclude()

            mb.add_declaration_code('extern CServerGameDLL g_ServerGameDLL;')
            mb.add_registration_code(
                "bp::scope().attr( \"servergamedll\" ) = boost::ref(g_ServerGameDLL);"
            )

        if self.isclient:
            cls = mb.class_('CClientSteamContext')
            cls.include()
            cls.mem_fun('InstallCallback').exclude()
            cls.mem_fun('RemoveCallback').exclude()
            cls.mem_fun('Activate').exclude()
            cls.mem_fun('Shutdown').exclude()

            mb.free_function('ClientSteamContext').include()
            mb.free_function(
                'ClientSteamContext'
            ).call_policies = call_policies.return_value_policy(
                call_policies.reference_existing_object)

        # model_t
        cls = mb.class_('wrap_model_t')
        cls.include()
        cls.rename('model_t')
        cls.calldefs('wrap_model_t').exclude()
        cls.no_init = True
        cls.vars('pModel').exclude()

        mb.add_registration_code("ptr_model_t_to_wrap_model_t();")
        mb.add_registration_code("const_ptr_model_t_to_wrap_model_t();")
        mb.add_registration_code("wrap_model_t_to_model_t();")

        # LUMPS
        mb.add_registration_code(
            "bp::scope().attr( \"LUMP_ENTITIES\" ) = (int)LUMP_ENTITIES;")

        # Defines
        mb.add_registration_code(
            "bp::scope().attr( \"FCVAR_NONE\" ) = (int)FCVAR_NONE;")

        mb.add_registration_code(
            "bp::scope().attr( \"FCVAR_UNREGISTERED\" ) = (int)FCVAR_UNREGISTERED;"
        )
        mb.add_registration_code(
            "bp::scope().attr( \"FCVAR_DEVELOPMENTONLY\" ) = (int)FCVAR_DEVELOPMENTONLY;"
        )
        mb.add_registration_code(
            "bp::scope().attr( \"FCVAR_GAMEDLL\" ) = (int)FCVAR_GAMEDLL;")
        mb.add_registration_code(
            "bp::scope().attr( \"FCVAR_CLIENTDLL\" ) = (int)FCVAR_CLIENTDLL;")
        mb.add_registration_code(
            "bp::scope().attr( \"FCVAR_HIDDEN\" ) = (int)FCVAR_HIDDEN;")

        mb.add_registration_code(
            "bp::scope().attr( \"FCVAR_PROTECTED\" ) = (int)FCVAR_PROTECTED;")
        mb.add_registration_code(
            "bp::scope().attr( \"FCVAR_SPONLY\" ) = (int)FCVAR_SPONLY;")
        mb.add_registration_code(
            "bp::scope().attr( \"FCVAR_ARCHIVE\" ) = (int)FCVAR_ARCHIVE;")
        mb.add_registration_code(
            "bp::scope().attr( \"FCVAR_NOTIFY\" ) = (int)FCVAR_NOTIFY;")
        mb.add_registration_code(
            "bp::scope().attr( \"FCVAR_USERINFO\" ) = (int)FCVAR_USERINFO;")
        mb.add_registration_code(
            "bp::scope().attr( \"FCVAR_CHEAT\" ) = (int)FCVAR_CHEAT;")

        mb.add_registration_code(
            "bp::scope().attr( \"FCVAR_PRINTABLEONLY\" ) = (int)FCVAR_PRINTABLEONLY;"
        )
        mb.add_registration_code(
            "bp::scope().attr( \"FCVAR_UNLOGGED\" ) = (int)FCVAR_UNLOGGED;")
        mb.add_registration_code(
            "bp::scope().attr( \"FCVAR_NEVER_AS_STRING\" ) = (int)FCVAR_NEVER_AS_STRING;"
        )

        mb.add_registration_code(
            "bp::scope().attr( \"FCVAR_REPLICATED\" ) = (int)FCVAR_REPLICATED;"
        )
        mb.add_registration_code(
            "bp::scope().attr( \"FCVAR_DEMO\" ) = (int)FCVAR_DEMO;")
        mb.add_registration_code(
            "bp::scope().attr( \"FCVAR_DONTRECORD\" ) = (int)FCVAR_DONTRECORD;"
        )
        mb.add_registration_code(
            "bp::scope().attr( \"FCVAR_NOT_CONNECTED\" ) = (int)FCVAR_NOT_CONNECTED;"
        )
        mb.add_registration_code(
            "bp::scope().attr( \"FCVAR_ARCHIVE_XBOX\" ) = (int)FCVAR_ARCHIVE_XBOX;"
        )
        mb.add_registration_code(
            "bp::scope().attr( \"FCVAR_SERVER_CAN_EXECUTE\" ) = (int)FCVAR_SERVER_CAN_EXECUTE;"
        )
        mb.add_registration_code(
            "bp::scope().attr( \"FCVAR_SERVER_CANNOT_QUERY\" ) = (int)FCVAR_SERVER_CANNOT_QUERY;"
        )
        mb.add_registration_code(
            "bp::scope().attr( \"FCVAR_CLIENTCMD_CAN_EXECUTE\" ) = (int)FCVAR_CLIENTCMD_CAN_EXECUTE;"
        )

        # Excludes
        excludetypes = [
            pointer_t(
                declarated_t(
                    mb.class_('CTeam' if self.isserver else 'C_Team'))),
        ]
        mb.calldefs(calldef_withtypes(excludetypes)).exclude()
Exemplo n.º 11
0
    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)
Exemplo n.º 12
0
    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') )
        
Exemplo n.º 13
0
    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)
Exemplo n.º 14
0
    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

        # 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.mem_funs('As3x4').exclude()
        cls.mem_funs('GetTranslation').exclude()
        cls.vars('m').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'))
Exemplo n.º 15
0
    def ParseClient(self, mb):
        # Don't care
        mb.class_('CEffectData').mem_funs().exclude()
        mb.class_('CEffectData').vars('m_hEntity').exclude()
        
        # Registering new effects
        cls = mb.class_('PyClientEffectRegistration')
        cls.include()
        cls.rename('ClientEffectRegistration')
        cls.vars().exclude()
        
        # Functions to do some effects
        mb.free_functions('FX_AddQuad').include()
        
        # fx.h
        mb.free_functions('FX_RicochetSound').include()
        mb.free_functions('FX_AntlionImpact').include()
        mb.free_functions('FX_DebrisFlecks').include()
        mb.free_functions('FX_Tracer').include()
        mb.free_functions('FX_GunshipTracer').include()
        mb.free_functions('FX_StriderTracer').include()
        mb.free_functions('FX_HunterTracer').include()
        mb.free_functions('FX_PlayerTracer').include()
        #mb.free_functions('FX_BulletPass').include()
        mb.free_functions('FX_MetalSpark').include()
        mb.free_functions('FX_MetalScrape').include()
        mb.free_functions('FX_Sparks').include()
        mb.free_functions('FX_ElectricSpark').include()
        mb.free_functions('FX_BugBlood').include()
        mb.free_functions('FX_Blood').include()
        #mb.free_functions('FX_CreateImpactDust').include()
        mb.free_functions('FX_EnergySplash').include()
        mb.free_functions('FX_MicroExplosion').include()
        mb.free_functions('FX_Explosion').include()
        mb.free_functions('FX_ConcussiveExplosion').include()
        mb.free_functions('FX_DustImpact').include()
        mb.free_functions('FX_MuzzleEffect').include()
        mb.free_functions('FX_MuzzleEffectAttached').include()
        mb.free_functions('FX_StriderMuzzleEffect').include()
        mb.free_functions('FX_GunshipMuzzleEffect').include()
        mb.free_functions('FX_Smoke').include()
        mb.free_functions('FX_Dust').include()
        #mb.free_functions('FX_CreateGaussExplosion').include()
        mb.free_functions('FX_GaussTracer').include()
        mb.free_functions('FX_TracerSound').include()

        # Temp Ents
        cls = mb.class_('CTempEnts')
        cls.include()
        cls.mem_funs().virtuality = 'not virtual' 
        cls.calldefs(matchers.access_type_matcher_t( 'protected' ), allow_empty=True).exclude()
        cls.mem_fun('RicochetSprite').exclude() # Exclude because of model_t

        mb.add_registration_code( 'bp::scope().attr( "tempents" ) = boost::ref(tempents);' )
        
        # C_LocalTempEntity is not exposed and shouldn't be needed (deprecated)
        localtempentity = mb.class_('C_LocalTempEntity')
        excludetypes = [
            pointer_t(declarated_t(localtempentity)),
            pointer_t(const_t(declarated_t(localtempentity))),
        ]
        cls.calldefs(calldef_withtypes(excludetypes), allow_empty=True).exclude()
        
        # Add client effects class (you can only add mesh builders to it)
        cls = mb.class_('PyClientSideEffect')
        cls.include()
        cls.rename('ClientSideEffect')
        cls.mem_funs().virtuality = 'not virtual' 
        cls.mem_funs('AddToEffectList').exclude()
        cls.mem_funs('Draw').virtuality = 'virtual'
        
        mb.free_function('AddToClientEffectList').include()
        
        # Mesh builder
        cls = mb.class_('PyMeshVertex')
        cls.include()
        cls.rename('MeshVertex')
        
        cls.var('m_hEnt').exclude()
        cls.mem_funs('GetEnt').call_policies = call_policies.return_value_policy(call_policies.return_by_value)
        self.SetupProperty(cls, 'ent', 'GetEnt', 'SetEnt')
                         
        cls = mb.class_('PyMeshBuilder')
        cls.include()
        cls.rename('MeshBuilder')
        cls.mem_funs().virtuality = 'not virtual' 
        
        cls = mb.class_('PyMeshRallyLine')
        cls.include()
        cls.rename('MeshRallyLine')
        cls.mem_funs().virtuality = 'not virtual'
        cls.mem_funs('GetEnt1').call_policies = call_policies.return_value_policy(call_policies.return_by_value)
        cls.mem_funs('GetEnt2').call_policies = call_policies.return_value_policy(call_policies.return_by_value)
        self.SetupProperty(cls, 'ent1', 'GetEnt1', 'SetEnt1')
        self.SetupProperty(cls, 'ent2', 'GetEnt2', 'SetEnt2')
        
        mb.enum('MaterialPrimitiveType_t').include()
        
        # FX Envelope + strider fx
        cls = mb.class_('C_EnvelopeFX')
        cls.include()
        cls.mem_funs().virtuality = 'not virtual' 
        
        cls = mb.class_('C_StriderFX')
        cls.include()
        cls.mem_funs().virtuality = 'not virtual'
        
        # Constants
        mb.add_registration_code( "bp::scope().attr( \"FTENT_NONE\" ) = (int)FTENT_NONE;" )
        mb.add_registration_code( "bp::scope().attr( \"FTENT_SINEWAVE\" ) = (int)FTENT_SINEWAVE;" )
        mb.add_registration_code( "bp::scope().attr( \"FTENT_GRAVITY\" ) = (int)FTENT_GRAVITY;" )
        mb.add_registration_code( "bp::scope().attr( \"FTENT_ROTATE\" ) = (int)FTENT_ROTATE;" )
        mb.add_registration_code( "bp::scope().attr( \"FTENT_SLOWGRAVITY\" ) = (int)FTENT_SLOWGRAVITY;" )
        mb.add_registration_code( "bp::scope().attr( \"FTENT_SMOKETRAIL\" ) = (int)FTENT_SMOKETRAIL;" )
        mb.add_registration_code( "bp::scope().attr( \"FTENT_COLLIDEWORLD\" ) = (int)FTENT_COLLIDEWORLD;" )
        mb.add_registration_code( "bp::scope().attr( \"FTENT_FLICKER\" ) = (int)FTENT_FLICKER;" )
        mb.add_registration_code( "bp::scope().attr( \"FTENT_FADEOUT\" ) = (int)FTENT_FADEOUT;" )
        mb.add_registration_code( "bp::scope().attr( \"FTENT_SPRANIMATE\" ) = (int)FTENT_SPRANIMATE;" )
        mb.add_registration_code( "bp::scope().attr( \"FTENT_HITSOUND\" ) = (int)FTENT_HITSOUND;" )
        mb.add_registration_code( "bp::scope().attr( \"FTENT_SPIRAL\" ) = (int)FTENT_SPIRAL;" )
        mb.add_registration_code( "bp::scope().attr( \"FTENT_SPRCYCLE\" ) = (int)FTENT_SPRCYCLE;" )
        mb.add_registration_code( "bp::scope().attr( \"FTENT_COLLIDEALL\" ) = (int)FTENT_COLLIDEALL;" )
        mb.add_registration_code( "bp::scope().attr( \"FTENT_PERSIST\" ) = (int)FTENT_PERSIST;" )
        mb.add_registration_code( "bp::scope().attr( \"FTENT_COLLIDEKILL\" ) = (int)FTENT_COLLIDEKILL;" )
        mb.add_registration_code( "bp::scope().attr( \"FTENT_PLYRATTACHMENT\" ) = (int)FTENT_PLYRATTACHMENT;" )
        mb.add_registration_code( "bp::scope().attr( \"FTENT_SPRANIMATELOOP\" ) = (int)FTENT_SPRANIMATELOOP;" )
        mb.add_registration_code( "bp::scope().attr( \"FTENT_SMOKEGROWANDFADE\" ) = (int)FTENT_SMOKEGROWANDFADE;" )
        mb.add_registration_code( "bp::scope().attr( \"FTENT_ATTACHTOTARGET\" ) = (int)FTENT_ATTACHTOTARGET;" )
        mb.add_registration_code( "bp::scope().attr( \"FTENT_NOMODEL\" ) = (int)FTENT_NOMODEL;" )
        mb.add_registration_code( "bp::scope().attr( \"FTENT_CLIENTCUSTOM\" ) = (int)FTENT_CLIENTCUSTOM;" )
        mb.add_registration_code( "bp::scope().attr( \"FTENT_WINDBLOWN\" ) = (int)FTENT_WINDBLOWN;" )
        mb.add_registration_code( "bp::scope().attr( \"FTENT_NEVERDIE\" ) = (int)FTENT_NEVERDIE;" )
        mb.add_registration_code( "bp::scope().attr( \"FTENT_BEOCCLUDED\" ) = (int)FTENT_BEOCCLUDED;" )
        mb.add_registration_code( "bp::scope().attr( \"FTENT_CHANGERENDERONCOLLIDE\" ) = (int)FTENT_CHANGERENDERONCOLLIDE;" )
        mb.add_registration_code( "bp::scope().attr( \"FTENT_COLLISIONGROUP\" ) = (int)FTENT_COLLISIONGROUP;" )
        mb.add_registration_code( "bp::scope().attr( \"FTENT_ALIGNTOMOTION\" ) = (int)FTENT_ALIGNTOMOTION;" )
        mb.add_registration_code( "bp::scope().attr( \"FTENT_CLIENTSIDEPARTICLES\" ) = (int)FTENT_CLIENTSIDEPARTICLES;" )
        mb.add_registration_code( "bp::scope().attr( \"FTENT_USEFASTCOLLISIONS\" ) = (int)FTENT_USEFASTCOLLISIONS;" )
Exemplo n.º 16
0
    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()
Exemplo n.º 17
0
    def ParseClient(self, mb):
        # Don't care
        mb.class_('CEffectData').mem_funs().exclude()
        mb.class_('CEffectData').vars('m_hEntity').exclude()
        
        # Registering new effects
        cls = mb.class_('PyClientEffectRegistration')
        cls.include()
        cls.rename('ClientEffectRegistration')
        cls.vars().exclude()
        
        # Functions to do some effects
        mb.free_functions('FX_AddQuad').include()
        
        # fx.h
        mb.free_functions('FX_RicochetSound').include()
        mb.free_functions('FX_AntlionImpact').include()
        mb.free_functions('FX_DebrisFlecks').include()
        mb.free_functions('FX_Tracer').include()
        mb.free_functions('FX_GunshipTracer').include()
        mb.free_functions('FX_StriderTracer').include()
        mb.free_functions('FX_HunterTracer').include()
        mb.free_functions('FX_PlayerTracer').include()
        #mb.free_functions('FX_BulletPass').include()
        mb.free_functions('FX_MetalSpark').include()
        mb.free_functions('FX_MetalScrape').include()
        mb.free_functions('FX_Sparks').include()
        mb.free_functions('FX_ElectricSpark').include()
        mb.free_functions('FX_BugBlood').include()
        mb.free_functions('FX_Blood').include()
        #mb.free_functions('FX_CreateImpactDust').include()
        mb.free_functions('FX_EnergySplash').include()
        mb.free_functions('FX_MicroExplosion').include()
        mb.free_functions('FX_Explosion').include()
        mb.free_functions('FX_ConcussiveExplosion').include()
        mb.free_functions('FX_DustImpact').include()
        mb.free_functions('FX_MuzzleEffect').include()
        mb.free_functions('FX_MuzzleEffectAttached').include()
        mb.free_functions('FX_StriderMuzzleEffect').include()
        mb.free_functions('FX_GunshipMuzzleEffect').include()
        mb.free_functions('FX_Smoke').include()
        mb.free_functions('FX_Dust').include()
        #mb.free_functions('FX_CreateGaussExplosion').include()
        mb.free_functions('FX_GaussTracer').include()
        mb.free_functions('FX_TracerSound').include()

        # Temp Ents
        cls = mb.class_('CTempEnts')
        cls.include()
        cls.mem_funs().virtuality = 'not virtual' 
        cls.calldefs(matchers.access_type_matcher_t( 'protected' ), allow_empty=True).exclude()
        cls.mem_fun('RicochetSprite').exclude() # Exclude because of model_t

        mb.add_registration_code( 'bp::scope().attr( "tempents" ) = boost::ref(tempents);' )
        
        # C_LocalTempEntity is not exposed and shouldn't be needed (deprecated)
        localtempentity = mb.class_('C_LocalTempEntity')
        excludetypes = [
            pointer_t(declarated_t(localtempentity)),
            pointer_t(const_t(declarated_t(localtempentity))),
        ]
        cls.calldefs(calldef_withtypes(excludetypes), allow_empty=True).exclude()
        
        # Add client effects class (you can only add mesh builders to it)
        cls = mb.class_('PyClientSideEffect')
        cls.include()
        cls.rename('ClientSideEffect')
        cls.mem_funs().virtuality = 'not virtual' 
        cls.mem_funs('AddToEffectList').exclude()
        cls.mem_funs('Draw').virtuality = 'virtual'
        
        mb.free_function('AddToClientEffectList').include()
        
        # Mesh builder
        cls = mb.class_('PyMeshVertex')
        cls.include()
        cls.rename('MeshVertex')
        
        cls.var('m_hEnt').exclude()
        cls.mem_funs('GetEnt').call_policies = call_policies.return_value_policy(call_policies.return_by_value)
        self.SetupProperty(cls, 'ent', 'GetEnt', 'SetEnt')
                         
        cls = mb.class_('PyMeshBuilder')
        cls.include()
        cls.rename('MeshBuilder')
        cls.mem_funs().virtuality = 'not virtual' 
        
        cls = mb.class_('PyMeshRallyLine')
        cls.include()
        cls.rename('MeshRallyLine')
        cls.mem_funs().virtuality = 'not virtual'
        cls.mem_funs('GetEnt1').call_policies = call_policies.return_value_policy(call_policies.return_by_value)
        cls.mem_funs('GetEnt2').call_policies = call_policies.return_value_policy(call_policies.return_by_value)
        self.SetupProperty(cls, 'ent1', 'GetEnt1', 'SetEnt1')
        self.SetupProperty(cls, 'ent2', 'GetEnt2', 'SetEnt2')
        
        mb.enum('MaterialPrimitiveType_t').include()
        
        # FX Envelope + strider fx
        cls = mb.class_('C_EnvelopeFX')
        cls.include()
        cls.mem_funs().virtuality = 'not virtual' 
        
        #cls = mb.class_('C_StriderFX')
        #cls.include()
        #cls.mem_funs().virtuality = 'not virtual' 
        
        # Constants
        mb.add_registration_code( "bp::scope().attr( \"FTENT_NONE\" ) = (int)FTENT_NONE;" )
        mb.add_registration_code( "bp::scope().attr( \"FTENT_SINEWAVE\" ) = (int)FTENT_SINEWAVE;" )
        mb.add_registration_code( "bp::scope().attr( \"FTENT_GRAVITY\" ) = (int)FTENT_GRAVITY;" )
        mb.add_registration_code( "bp::scope().attr( \"FTENT_ROTATE\" ) = (int)FTENT_ROTATE;" )
        mb.add_registration_code( "bp::scope().attr( \"FTENT_SLOWGRAVITY\" ) = (int)FTENT_SLOWGRAVITY;" )
        mb.add_registration_code( "bp::scope().attr( \"FTENT_SMOKETRAIL\" ) = (int)FTENT_SMOKETRAIL;" )
        mb.add_registration_code( "bp::scope().attr( \"FTENT_COLLIDEWORLD\" ) = (int)FTENT_COLLIDEWORLD;" )
        mb.add_registration_code( "bp::scope().attr( \"FTENT_FLICKER\" ) = (int)FTENT_FLICKER;" )
        mb.add_registration_code( "bp::scope().attr( \"FTENT_FADEOUT\" ) = (int)FTENT_FADEOUT;" )
        mb.add_registration_code( "bp::scope().attr( \"FTENT_SPRANIMATE\" ) = (int)FTENT_SPRANIMATE;" )
        mb.add_registration_code( "bp::scope().attr( \"FTENT_HITSOUND\" ) = (int)FTENT_HITSOUND;" )
        mb.add_registration_code( "bp::scope().attr( \"FTENT_SPIRAL\" ) = (int)FTENT_SPIRAL;" )
        mb.add_registration_code( "bp::scope().attr( \"FTENT_SPRCYCLE\" ) = (int)FTENT_SPRCYCLE;" )
        mb.add_registration_code( "bp::scope().attr( \"FTENT_COLLIDEALL\" ) = (int)FTENT_COLLIDEALL;" )
        mb.add_registration_code( "bp::scope().attr( \"FTENT_PERSIST\" ) = (int)FTENT_PERSIST;" )
        mb.add_registration_code( "bp::scope().attr( \"FTENT_COLLIDEKILL\" ) = (int)FTENT_COLLIDEKILL;" )
        mb.add_registration_code( "bp::scope().attr( \"FTENT_PLYRATTACHMENT\" ) = (int)FTENT_PLYRATTACHMENT;" )
        mb.add_registration_code( "bp::scope().attr( \"FTENT_SPRANIMATELOOP\" ) = (int)FTENT_SPRANIMATELOOP;" )
        mb.add_registration_code( "bp::scope().attr( \"FTENT_SMOKEGROWANDFADE\" ) = (int)FTENT_SMOKEGROWANDFADE;" )
        mb.add_registration_code( "bp::scope().attr( \"FTENT_ATTACHTOTARGET\" ) = (int)FTENT_ATTACHTOTARGET;" )
        mb.add_registration_code( "bp::scope().attr( \"FTENT_NOMODEL\" ) = (int)FTENT_NOMODEL;" )
        mb.add_registration_code( "bp::scope().attr( \"FTENT_CLIENTCUSTOM\" ) = (int)FTENT_CLIENTCUSTOM;" )
        mb.add_registration_code( "bp::scope().attr( \"FTENT_WINDBLOWN\" ) = (int)FTENT_WINDBLOWN;" )
        mb.add_registration_code( "bp::scope().attr( \"FTENT_NEVERDIE\" ) = (int)FTENT_NEVERDIE;" )
        mb.add_registration_code( "bp::scope().attr( \"FTENT_BEOCCLUDED\" ) = (int)FTENT_BEOCCLUDED;" )
        mb.add_registration_code( "bp::scope().attr( \"FTENT_CHANGERENDERONCOLLIDE\" ) = (int)FTENT_CHANGERENDERONCOLLIDE;" )
        mb.add_registration_code( "bp::scope().attr( \"FTENT_COLLISIONGROUP\" ) = (int)FTENT_COLLISIONGROUP;" )
        mb.add_registration_code( "bp::scope().attr( \"FTENT_ALIGNTOMOTION\" ) = (int)FTENT_ALIGNTOMOTION;" )
        mb.add_registration_code( "bp::scope().attr( \"FTENT_CLIENTSIDEPARTICLES\" ) = (int)FTENT_CLIENTSIDEPARTICLES;" )
        mb.add_registration_code( "bp::scope().attr( \"FTENT_USEFASTCOLLISIONS\" ) = (int)FTENT_USEFASTCOLLISIONS;" )
Exemplo n.º 18
0
    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()