def write_wrappers(mb, module, huge_classes, header_files = [] ): """This function performs the actual work of writing the wrappers to disk""" #make sure that the protected and private member functions and #data aren't wrapped try: mb.calldefs( access_type_matcher_t( 'protected' ) ).exclude() except: pass try: mb.calldefs( access_type_matcher_t( 'private' ) ).exclude() except: pass #build a code creator - this must be done after the above, as #otherwise our modifications above won't take effect mb.build_code_creator( module_name="_%s" % module ) #get rid of the standard headers mb.code_creator.replace_included_headers( header_files ) #give each piece of code the GPL license header mb.code_creator.license = "// (C) Christopher Woods, GPL >= 2 License\n" #use local directory paths mb.code_creator.user_defined_directories.append(".") mb.split_module( ".", huge_classes )
def write_wrappers(mb, module, huge_classes, header_files=[], source_docs={}): """This function performs the actual work of writing the wrappers to disk""" #make sure that the protected and private member functions and #data aren't wrapped try: mb.calldefs(access_type_matcher_t('protected')).exclude() except: pass try: mb.calldefs(access_type_matcher_t('private')).exclude() except: pass #build a code creator - this must be done after the above, as #otherwise our modifications above won't take effect mb.build_code_creator(module_name="_%s" % module, doc_extractor=doxygen_doc_extractor(source_docs)) #get rid of the standard headers mb.code_creator.replace_included_headers(header_files) #give each piece of code the GPL license header mb.code_creator.license = "// (C) Christopher Woods, GPL >= 2 License\n" #use local directory paths mb.code_creator.user_defined_directories.append(".") mb.split_module(".", huge_classes)
def wrap_Image4DSimple(self): cls = self.mb.class_("Image4DSimple") cls.include() cls.member_functions( access_type_matcher_t( 'protected' ), allow_empty=True ).exclude() cls.variables( access_type_matcher_t( 'protected' ), allow_empty=True ).exclude() cls.member_function('getRawData').exclude() # raw pointer not useful in python cls.member_function('getRawDataAtChannel').exclude() # link errors cls.member_functions('loadImage').exclude() cls.member_function('saveImage').exclude() cls.member_function('createImage').exclude() cls.member_function('createBlankImage').exclude()
def Parse(self, mb): mb.decls().exclude() # CGameUIConVarRef mb.class_('CGameUIConVarRef').include() mb.free_function('ReadCurrentVideoConfig').include() # Sending gameui commands mb.enum('WINDOW_TYPE').include() mb.free_function('PyGameUICommand').include() # Temporary function mb.free_function('PyGameUICommand').rename('GameUICommand') mb.free_function('PyGameUIOpenWindow').include() # Temporary function mb.free_function('PyGameUIOpenWindow').rename('GameUIOpenWindow') mb.free_function('OpenGammaDialog').include() mb.free_function('GetMainMenu').include() mb.free_function('GetKeyboardLangIds').include() mb.free_function('GetCurrentKeyboardLangId').include() # Remove any protected function mb.calldefs(matchers.access_type_matcher_t('protected')).exclude()
def Parse(self, mb): # Exclude everything by default mb.decls().exclude() mb.class_('kbutton_t').include() if self.settings.branch == 'swarm': mb.class_('kbutton_t').mem_funs('GetPerUser').exclude() # Include input class cls = mb.class_('CInput') cls.include() cls.mem_funs().virtuality = 'not virtual' if self.settings.branch == 'swarm': #mb.mem_funs('FindKey').exclude() # FIXME mb.mem_funs('FindKey').call_policies = call_policies.return_value_policy( call_policies.reference_existing_object ) else: mb.mem_funs('FindKey').call_policies = call_policies.return_value_policy( call_policies.manage_new_object ) mb.mem_funs('GetUserCmd').call_policies = call_policies.return_value_policy( call_policies.reference_existing_object ) # Can't exclude due being abstract mb.mem_funs( 'CAM_OrthographicSize' ).add_transformation( FT.output('w'), FT.output('h') ) mb.add_declaration_code( "CInput *wrap_Input()\r\n{\r\n\treturn (CInput *)::input;\r\n}\r\n" ) mb.add_registration_code( 'bp::def( "input", wrap_Input, bp::return_value_policy<bp::reference_existing_object>() );' ) # ButtonCode. mb.enums('ButtonCode_t').include() # Remove any protected function mb.calldefs( matchers.access_type_matcher_t( 'protected' ) ).exclude()
def Parse(self, mb): mb.decls().exclude() # Material reference cls = mb.class_('CMaterialReference') cls.include() mb.global_ns.mem_opers('*').call_policies = call_policies.return_value_policy(call_policies.reference_existing_object) mb.global_ns.mem_opers().exclude() mb.global_ns.casting_operators().exclude() if self.isclient: # Glow Outline manager cls = mb.class_('CGlowObjectManager') cls.include() cls.mem_funs().virtuality = 'not virtual' cls.no_init = True mb.add_registration_code( "bp::scope().attr( \"glowobjectmanager\" ) = boost::ref(g_GlowObjectManager);" ) # A way for creating procedural materials in Python cls = mb.class_('PyProceduralTexture') cls.rename('ProceduralTexture') cls.include() mb.enum('ImageFormat').include() # Material lights cls = mb.class_('LightDesc_t') cls.include() # Remove any protected function mb.calldefs( matchers.access_type_matcher_t( 'protected' ) ).exclude()
def Parse(self, mb): mb.decls().exclude() # Material reference cls = mb.class_('CMaterialReference') cls.include() mb.global_ns.member_operators('*').call_policies = call_policies.return_value_policy(call_policies.reference_existing_object) mb.global_ns.member_operators().exclude() mb.global_ns.casting_operators().exclude() if self.isclient: # Glow Outline manager cls = mb.class_('CGlowObjectManager') cls.include() cls.member_functions().virtuality = 'not virtual' cls.no_init = True mb.add_registration_code( "bp::scope().attr( \"glowobjectmanager\" ) = boost::ref(g_GlowObjectManager);" ) # A way for creating procedural materials in Python cls = mb.class_('PyProceduralTexture') cls.rename('ProceduralTexture') cls.include() mb.enumeration('ImageFormat').include() # Material lights cls = mb.class_('LightDesc_t') cls.include() # Remove any protected function mb.calldefs( matchers.access_type_matcher_t( 'protected' ) ).exclude()
def Parse(self, mb): # Exclude everything by default mb.decls().exclude() # EngineSound access mb.class_('PyEngineSound').include() mb.class_('PyEngineSound').rename('EngineSound') # soundengine should follow after PyEngineSound! mb.class_('PyEngineSound').add_registration_code( "}bp::scope().attr( \"soundengine\" ) = boost::ref(pysoundengine);{", False ) # EmitSound_t cls = mb.class_('EmitSound_t') cls.rename('EmitSound') cls.include() cls.var('m_UtlVecSoundOrigin').exclude() cls.var('m_nChannel').rename('channel') cls.var('m_pSoundName').rename('soundname') cls.var('m_flVolume').rename('volume') cls.var('m_SoundLevel').rename('soundlevel') cls.var('m_nFlags').rename('flags') cls.var('m_nPitch').rename('pitch') cls.var('m_pOrigin').rename('origin') cls.var('m_flSoundTime').rename('soundtime') cls.var('m_pflSoundDuration').rename('soundduration') cls.var('m_bEmitCloseCaption').rename('emitclosecaption') cls.var('m_bWarnOnMissingCloseCaption').rename('warnonmissingclosecaption') cls.var('m_bWarnOnDirectWaveReference').rename('warnondirectwavereference') cls.var('m_nSpeakerEntity').rename('speakerentity') cls.var('m_UtlVecSoundOrigin').rename('utlvecsoundorigin') cls.var('m_hSoundScriptHandle').rename('soundscripthandle') # SoundEnvelope mb.class_('CSoundEnvelopeControllerHandle').include() mb.class_('CSoundEnvelopeControllerHandle').calldefs('CSoundEnvelopeControllerHandle').exclude() mb.class_('CSoundEnvelopeControllerHandle').rename('CSoundEnvelopeController') mb.class_('CSoundPatchHandle').include() mb.class_('CSoundPatchHandle').rename('CSoundPatch') mb.mem_funs('SoundCreate').call_policies = call_policies.return_value_policy( call_policies.return_by_value ) mb.vars('m_pSoundPatch').exclude() mb.class_('CSoundPatchHandle').calldefs('CSoundPatchHandle').exclude() # CSoundParameters mb.class_('CSoundParameters').include() # Enums mb.enums('soundcommands_t').include() mb.enums('soundcommands_t').rename('soundcommands') mb.enums('soundlevel_t').include() mb.enums('soundlevel_t').rename('soundlevel') # //-------------------------------------------------------------------------------------------------------------------------------- # Remove any protected function mb.calldefs( matchers.access_type_matcher_t( 'protected' ) ).exclude()
def Parse(self, mb): # Exclude everything by default mb.decls().exclude() self.ParseInterfaces(mb) self.ParseISurface(mb) self.ParseHUD(mb) self.ParseMisc(mb) # Remove any protected function mb.calldefs( matchers.access_type_matcher_t( 'protected' ) ).exclude() self.ApplyCommonRules(mb)
def Parse(self, mb): # Exclude everything by default mb.decls().exclude() self.ParseInterfaces(mb) self.ParseISurface(mb) self.ParseHUD(mb) self.ParseMisc(mb) # Remove any protected function mb.calldefs(matchers.access_type_matcher_t('protected')).exclude() self.ApplyCommonRules(mb)
def Parse(self, mb): # Exclude everything by default mb.decls().exclude() self.ParseInterfaces(mb) self.ParseISurface(mb) self.ParseHUD(mb) self.ParseMisc(mb) # Remove any protected function mb.calldefs(matchers.access_type_matcher_t('protected')).exclude() self.ApplyCommonRules(mb) mb.mem_funs('GetIMEWindow').include( ) # IInput, gets excluded by ApplyCommonRules
def Parse(self, mb): # Exclude everything by default mb.decls().exclude() self.ParseInterfaces(mb) self.ParseISurface(mb) self.ParseHUD(mb) self.ParseMisc(mb) # Remove any protected function mb.calldefs( matchers.access_type_matcher_t( 'protected' ) ).exclude() self.ApplyCommonRules(mb) mb.mem_funs('GetIMEWindow').include() # IInput, gets excluded by ApplyCommonRules
def Parse(self, mb): # Exclude everything by default mb.decls().exclude() mb.class_('kbutton_t').include() if self.settings.branch == 'swarm': mb.class_('kbutton_t').mem_funs('GetPerUser').exclude() # Include input class cls = mb.class_('CInput') cls.include() cls.mem_funs().virtuality = 'not virtual' if self.settings.branch == 'swarm': #mb.mem_funs('FindKey').exclude() # FIXME mb.mem_funs( 'FindKey').call_policies = call_policies.return_value_policy( call_policies.reference_existing_object) else: mb.mem_funs( 'FindKey').call_policies = call_policies.return_value_policy( call_policies.manage_new_object) mb.mem_funs( 'GetUserCmd').call_policies = call_policies.return_value_policy( call_policies.reference_existing_object ) # Can't exclude due being abstract mb.mem_funs('CAM_OrthographicSize').add_transformation( FT.output('w'), FT.output('h')) mb.add_declaration_code( "CInput *wrap_Input()\r\n{\r\n\treturn (CInput *)::input;\r\n}\r\n" ) mb.add_registration_code( 'bp::def( "input", wrap_Input, bp::return_value_policy<bp::reference_existing_object>() );' ) # ButtonCode. mb.enums('ButtonCode_t').include() # Remove any protected function mb.calldefs(matchers.access_type_matcher_t('protected')).exclude()
def Parse(self, mb): # Exclude everything, then add what we need mb.decls().exclude() mb.class_('CVProfile').include() mb.mem_funs('GetRoot').exclude() mb.mem_funs('FindNode').exclude() mb.mem_funs('GetBudgetGroupColor').exclude() mb.mem_funs('RegisterNumBudgetGroupsChangedCallBack').exclude() mb.mem_funs('FindOrCreateCounter').exclude() mb.mem_funs('GetCounterNameAndValue').exclude() if self.settings.branch == 'source2013': mb.mem_funs('GetCurrentNode').exclude() mb.vars('m_pNumBudgetGroupsChangedCallBack').exclude() mb.vars('m_pName').exclude() mb.vars('g_VProfCurrentProfile').include() mb.vars('g_VProfCurrentProfile').rename('vprofcurrentprofilee') # Remove any protected function mb.calldefs(matchers.access_type_matcher_t('protected')).exclude()
def Parse(self, mb): # Exclude everything, then add what we need mb.decls().exclude() mb.class_('CVProfile').include() mb.mem_funs('GetRoot').exclude() mb.mem_funs('FindNode').exclude() mb.mem_funs('GetBudgetGroupColor').exclude() mb.mem_funs('RegisterNumBudgetGroupsChangedCallBack').exclude() mb.mem_funs('FindOrCreateCounter').exclude() mb.mem_funs('GetCounterNameAndValue').exclude() if self.settings.branch == 'source2013': mb.mem_funs('GetCurrentNode').exclude() mb.vars('m_pNumBudgetGroupsChangedCallBack').exclude() mb.vars('m_pName').exclude() mb.vars('g_VProfCurrentProfile').include() mb.vars('g_VProfCurrentProfile').rename('vprofcurrentprofilee') # Remove any protected function mb.calldefs( matchers.access_type_matcher_t( 'protected' ) ).exclude()
def ParseMisc(self, mb): if self.isserver: # Sky camera mb.free_function("GetCurrentSkyCamera").include() mb.free_function("GetCurrentSkyCamera").call_policies = call_policies.return_value_policy( call_policies.return_by_value ) # CTakeDamageInfo cls = mb.class_("CTakeDamageInfo") cls.include() cls.calldefs(matchers.access_type_matcher_t("protected")).exclude() cls.mem_funs("GetInflictor").call_policies = call_policies.return_value_policy(call_policies.return_by_value) cls.mem_funs("GetWeapon").call_policies = call_policies.return_value_policy(call_policies.return_by_value) cls.mem_funs("GetAttacker").call_policies = call_policies.return_value_policy(call_policies.return_by_value) self.SetupProperty(cls, "attributes", "GetAttributes", "SetAttributes") cls = mb.class_("CMultiDamage") cls.include() cls.calldefs(matchers.access_type_matcher_t("protected")).exclude() cls.mem_funs("GetTarget").call_policies = call_policies.return_value_policy(call_policies.return_by_value) mb.free_functions("ClearMultiDamage").include() mb.free_functions("ApplyMultiDamage").include() mb.free_functions("AddMultiDamage").include() mb.free_functions("ImpulseScale").include() mb.free_functions("CalculateExplosiveDamageForce").include() mb.free_functions("CalculateBulletDamageForce").include() mb.free_functions("CalculateMeleeDamageForce").include() mb.free_functions("GuessDamageForce").include() # FireBulletsInfo_t cls = mb.class_("FireBulletsInfo_t") cls.include() cls.var("m_iShots").rename("shots") cls.var("m_vecSrc").rename("vecsrc") cls.var("m_vecDirShooting").rename("vecdirshooting") cls.var("m_vecSpread").rename("vecspread") cls.var("m_flDistance").rename("distance") cls.var("m_iAmmoType").rename("ammotype") cls.var("m_iTracerFreq").rename("tracerfreq") cls.var("m_nFlags").rename("flags") cls.var("m_flDamageForceScale").rename("damageforcescale") cls.var("m_pAttacker").rename("attacker") cls.var("m_pAdditionalIgnoreEnt").rename("additionalignoreent") cls.var("m_bPrimaryAttack").rename("primaryattack") cls.var("m_flDamage").rename("damage") cls.var("m_iPlayerDamage" if self.settings.branch == "source2013" else "m_flPlayerDamage").rename( "playerdamage" ) # CShotManipulator cls = mb.class_("CShotManipulator") cls.include() if self.isserver: # Bone follower cls = mb.class_("pyphysfollower_t") cls.include() cls.rename("physfollower") cls = mb.class_("PyBoneFollowerManager") cls.include() cls.rename("BoneFollowerManager") mb.free_function("GetAttachmentPositionInSpaceOfBone").include() # Ragdoll functions mb.free_function("CreateServerRagdoll").include() mb.free_function("CreateServerRagdoll").call_policies = call_policies.return_value_policy( call_policies.return_by_value ) if self.settings.branch == "swarm": mb.free_function("PyCreateServerRagdollAttached").include() mb.free_function("PyCreateServerRagdollAttached").rename("CreateServerRagdollAttached") mb.free_function("PyCreateServerRagdollAttached").call_policies = call_policies.return_value_policy( call_policies.return_by_value ) mb.free_function("DetachAttachedRagdoll").include() mb.free_function("DetachAttachedRagdollsForEntity").include() # Shared Props mb.class_("breakablepropparams_t").include() mb.free_functions("GetMassEquivalent").include() mb.free_functions("GetAutoMultiplayerPhysicsMode").include() mb.free_functions("PropBreakableCreateAll").include() mb.free_functions("PrecacheGibsForModel").include() # Enums mb.enums("MoveType_t").include() mb.enums("MoveCollide_t").include() mb.enums("SolidType_t").include() mb.enums("SolidFlags_t").include() mb.enums("Collision_Group_t").include() mb.enums("RenderMode_t").include() mb.enums("RenderFx_t").include() if self.isclient: mb.enums("ShadowType_t").include() mb.enums("RenderGroup_t").include() mb.enums("DataUpdateType_t").include() mb.enums("CollideType_t").include() mb.enums("ShouldTransmitState_t").include() mb.enums("OverrideType_t").include() else: mb.enums("EntityEvent_t").include() mb.enums("Class_T").include() mb.enums("_fieldtypes").include() mb.enums("USE_TYPE").include() mb.enums("Activity").include() # Anim event cls = mb.class_("animevent_t") cls.include() cls.add_wrapper_code( "static bp::object get_options(animevent_t const & inst){\r\n" + " return bp::object(inst.options);\r\n" + "}\r\n" ) cls.add_registration_code( 'add_property("options"\r\n' + " , bp::make_function( (bp::object (*)( ::animevent_t & ))(&animevent_t_wrapper::get_options) ) )\r\n" ) # Solid_t class mb.classes("solid_t").include() # Types/Contants if self.isserver: mb.add_registration_code('bp::scope().attr( "SOUND_NONE" ) = (int)SOUND_NONE;') mb.add_registration_code('bp::scope().attr( "SOUND_COMBAT" ) = (int)SOUND_COMBAT;') mb.add_registration_code('bp::scope().attr( "SOUND_WORLD" ) = (int)SOUND_WORLD;') mb.add_registration_code('bp::scope().attr( "SOUND_PLAYER" ) = (int)SOUND_PLAYER;') mb.add_registration_code('bp::scope().attr( "SOUND_DANGER" ) = (int)SOUND_DANGER;') mb.add_registration_code('bp::scope().attr( "SOUND_BULLET_IMPACT" ) = (int)SOUND_BULLET_IMPACT;') mb.add_registration_code('bp::scope().attr( "SOUND_CARCASS" ) = (int)SOUND_CARCASS;') mb.add_registration_code('bp::scope().attr( "SOUND_GARBAGE" ) = (int)SOUND_GARBAGE;') mb.add_registration_code('bp::scope().attr( "SOUND_THUMPER" ) = (int)SOUND_THUMPER;') mb.add_registration_code('bp::scope().attr( "SOUND_BUGBAIT" ) = (int)SOUND_BUGBAIT;') mb.add_registration_code('bp::scope().attr( "SOUND_PHYSICS_DANGER" ) = (int)SOUND_PHYSICS_DANGER;') mb.add_registration_code('bp::scope().attr( "SOUND_DANGER_SNIPERONLY" ) = (int)SOUND_DANGER_SNIPERONLY;') mb.add_registration_code('bp::scope().attr( "SOUND_MOVE_AWAY" ) = (int)SOUND_MOVE_AWAY;') mb.add_registration_code('bp::scope().attr( "SOUND_PLAYER_VEHICLE" ) = (int)SOUND_PLAYER_VEHICLE;') mb.add_registration_code('bp::scope().attr( "SOUND_READINESS_LOW" ) = (int)SOUND_READINESS_LOW;') mb.add_registration_code('bp::scope().attr( "SOUND_READINESS_MEDIUM" ) = (int)SOUND_READINESS_MEDIUM;') mb.add_registration_code('bp::scope().attr( "SOUND_READINESS_HIGH" ) = (int)SOUND_READINESS_HIGH;') mb.add_registration_code( 'bp::scope().attr( "SOUND_CONTEXT_FROM_SNIPER" ) = (int)SOUND_CONTEXT_FROM_SNIPER;' ) mb.add_registration_code('bp::scope().attr( "SOUND_CONTEXT_GUNFIRE" ) = (int)SOUND_CONTEXT_GUNFIRE;') mb.add_registration_code('bp::scope().attr( "SOUND_CONTEXT_MORTAR" ) = (int)SOUND_CONTEXT_MORTAR;') mb.add_registration_code( 'bp::scope().attr( "SOUND_CONTEXT_COMBINE_ONLY" ) = (int)SOUND_CONTEXT_COMBINE_ONLY;' ) mb.add_registration_code( 'bp::scope().attr( "SOUND_CONTEXT_REACT_TO_SOURCE" ) = (int)SOUND_CONTEXT_REACT_TO_SOURCE;' ) mb.add_registration_code('bp::scope().attr( "SOUND_CONTEXT_EXPLOSION" ) = (int)SOUND_CONTEXT_EXPLOSION;') mb.add_registration_code( 'bp::scope().attr( "SOUND_CONTEXT_EXCLUDE_COMBINE" ) = (int)SOUND_CONTEXT_EXCLUDE_COMBINE;' ) mb.add_registration_code( 'bp::scope().attr( "SOUND_CONTEXT_DANGER_APPROACH" ) = (int)SOUND_CONTEXT_DANGER_APPROACH;' ) mb.add_registration_code( 'bp::scope().attr( "SOUND_CONTEXT_ALLIES_ONLY" ) = (int)SOUND_CONTEXT_ALLIES_ONLY;' ) mb.add_registration_code( 'bp::scope().attr( "SOUND_CONTEXT_PLAYER_VEHICLE" ) = (int)SOUND_CONTEXT_PLAYER_VEHICLE;' ) mb.add_registration_code('bp::scope().attr( "ALL_CONTEXTS" ) = (int)ALL_CONTEXTS;') mb.add_registration_code('bp::scope().attr( "ALL_SCENTS" ) = (int)ALL_SCENTS;') mb.add_registration_code('bp::scope().attr( "ALL_SOUNDS" ) = (int)ALL_SOUNDS;') # Channels mb.add_registration_code( 'bp::scope().attr( "SOUNDENT_CHANNEL_UNSPECIFIED" ) = (int)SOUNDENT_CHANNEL_UNSPECIFIED;' ) mb.add_registration_code( 'bp::scope().attr( "SOUNDENT_CHANNEL_REPEATING" ) = (int)SOUNDENT_CHANNEL_REPEATING;' ) mb.add_registration_code( 'bp::scope().attr( "SOUNDENT_CHANNEL_REPEATED_DANGER" ) = (int)SOUNDENT_CHANNEL_REPEATED_DANGER;' ) mb.add_registration_code( 'bp::scope().attr( "SOUNDENT_CHANNEL_REPEATED_PHYSICS_DANGER" ) = (int)SOUNDENT_CHANNEL_REPEATED_PHYSICS_DANGER;' ) mb.add_registration_code('bp::scope().attr( "SOUNDENT_CHANNEL_WEAPON" ) = (int)SOUNDENT_CHANNEL_WEAPON;') mb.add_registration_code('bp::scope().attr( "SOUNDENT_CHANNEL_INJURY" ) = (int)SOUNDENT_CHANNEL_INJURY;') mb.add_registration_code( 'bp::scope().attr( "SOUNDENT_CHANNEL_BULLET_IMPACT" ) = (int)SOUNDENT_CHANNEL_BULLET_IMPACT;' ) mb.add_registration_code( 'bp::scope().attr( "SOUNDENT_CHANNEL_NPC_FOOTSTEP" ) = (int)SOUNDENT_CHANNEL_NPC_FOOTSTEP;' ) mb.add_registration_code( 'bp::scope().attr( "SOUNDENT_CHANNEL_SPOOKY_NOISE" ) = (int)SOUNDENT_CHANNEL_SPOOKY_NOISE;' ) mb.add_registration_code( 'bp::scope().attr( "SOUNDENT_CHANNEL_ZOMBINE_GRENADE" ) = (int)SOUNDENT_CHANNEL_ZOMBINE_GRENADE;' ) # Transmit state mb.add_registration_code('bp::scope().attr( "FL_EDICT_CHANGED" ) = (int)FL_EDICT_CHANGED;') mb.add_registration_code('bp::scope().attr( "FL_EDICT_FREE" ) = (int)FL_EDICT_FREE;') mb.add_registration_code('bp::scope().attr( "FL_EDICT_FULL" ) = (int)FL_EDICT_FULL;') mb.add_registration_code('bp::scope().attr( "FL_EDICT_FULLCHECK" ) = (int)FL_EDICT_FULLCHECK;') mb.add_registration_code('bp::scope().attr( "FL_EDICT_ALWAYS" ) = (int)FL_EDICT_ALWAYS;') mb.add_registration_code('bp::scope().attr( "FL_EDICT_DONTSEND" ) = (int)FL_EDICT_DONTSEND;') mb.add_registration_code('bp::scope().attr( "FL_EDICT_PVSCHECK" ) = (int)FL_EDICT_PVSCHECK;') mb.add_registration_code( 'bp::scope().attr( "FL_EDICT_PENDING_DORMANT_CHECK" ) = (int)FL_EDICT_PENDING_DORMANT_CHECK;' ) mb.add_registration_code( 'bp::scope().attr( "FL_EDICT_DIRTY_PVS_INFORMATION" ) = (int)FL_EDICT_DIRTY_PVS_INFORMATION;' ) mb.add_registration_code('bp::scope().attr( "FL_FULL_EDICT_CHANGED" ) = (int)FL_FULL_EDICT_CHANGED;')
def Parse(self, mb): # Exclude everything by default mb.decls().exclude() cls_name = 'CHL2WarsGameRules' if self.isServer else 'C_HL2WarsGameRules' cls = mb.class_(cls_name) cls.include() cls.mem_fun('ShouldCollide').virtuality = 'not virtual' cls.mem_fun('GetAmmoDamage').virtuality = 'not virtual' # Just modify the ammo table when needed... # Gamerules class if self.isServer: cls.mem_fun('GetIntermissionEndTime').exclude() cls.mem_fun('SetintermissionEndTime').exclude() cls.mem_fun('GetGameOver').exclude() cls.mem_fun('SetGameOver').exclude() cls.add_property( 'intermissionendtime' , cls.member_function( 'GetIntermissionEndTime' ) , cls.member_function( 'SetintermissionEndTime' ) ) cls.add_property( 'gameover' , cls.member_function( 'GetGameOver' ) , cls.member_function( 'SetGameOver' ) ) # Call policies mb.mem_funs('GetPlayerSpawnSpot').call_policies = call_policies.return_value_policy( call_policies.return_by_value ) mb.mem_funs('GetDeathScorer').call_policies = call_policies.return_value_policy( call_policies.return_by_value ) mb.mem_funs('VoiceCommand').call_policies = call_policies.return_value_policy( call_policies.return_by_value ) # .. cls.mem_funs('GetPySelf').exclude() cls.mem_fun('FrameUpdatePostEntityThink').exclude() cls.add_wrapper_code( 'virtual PyObject *GetPySelf() const { return boost::python::detail::wrapper_base_::get_owner(*this); }' ) # Exlude and replace cls.mem_fun('ClientConnected').exclude() cls.mem_fun('PyClientConnected').rename('ClientConnected') cls.mem_fun('ClientDisconnected').exclude() cls.mem_fun('PyClientDisconnected').exclude() cls.mem_fun('PyClientDisconnected').rename('ClientDisconnected') AddWrapReg( mb, 'CHL2WarsGameRules', GetTopDeclaration( mb, 'CHL2WarsGameRules', 'PyClientDisconnected' ), ['*client'] ) cls.mem_fun('ClientActive').exclude() AddWrapReg( mb, 'CHL2WarsGameRules', GetTopDeclaration( mb, 'CHL2WarsGameRules', 'ClientActive' ), ['*client'] ) cls.mem_fun('PlayerSpawn').exclude() cls.mem_fun('PlayerThink').exclude() cls.mem_fun('FPlayerCanRespawn').exclude() cls.mem_fun('FlPlayerSpawnTime').exclude() cls.mem_fun('GetPlayerSpawnSpot').exclude() cls.mem_fun('IsSpawnPointValid').exclude() AddWrapReg( mb, 'CHL2WarsGameRules', GetTopDeclaration( mb, 'CHL2WarsGameRules', 'PlayerSpawn' ), ['*player'] ) AddWrapReg( mb, 'CHL2WarsGameRules', GetTopDeclaration( mb, 'CHL2WarsGameRules', 'PlayerThink' ), ['*player'] ) AddWrapReg( mb, 'CHL2WarsGameRules', GetTopDeclaration( mb, 'CHL2WarsGameRules', 'FPlayerCanRespawn' ), ['*player'] ) AddWrapReg( mb, 'CHL2WarsGameRules', GetTopDeclaration( mb, 'CHL2WarsGameRules', 'FlPlayerSpawnTime' ), ['*player'] ) AddWrapReg( mb, 'CHL2WarsGameRules', GetTopDeclaration( mb, 'CHL2WarsGameRules', 'GetPlayerSpawnSpot' ), ['*player'] ) AddWrapReg( mb, 'CHL2WarsGameRules', GetTopDeclaration( mb, 'CHL2WarsGameRules', 'IsSpawnPointValid' ), ['*spot', '*player'] ) cls.mem_fun('ClientCommand').exclude() cls.mem_fun('ClientSettingsChanged').exclude() AddWrapReg( mb, 'CHL2WarsGameRules', GetTopDeclaration( mb, 'CHL2WarsGameRules', 'ClientCommand' ), ['*edict', 'args'] ) AddWrapReg( mb, 'CHL2WarsGameRules', GetTopDeclaration( mb, 'CHL2WarsGameRules', 'ClientSettingsChanged' ), ['*player'] ) cls.mem_fun('PlayerChangedOwnerNumber').exclude() AddWrapReg( mb, 'CHL2WarsGameRules', GetTopDeclaration( mb, 'CHL2WarsGameRules', 'PlayerChangedOwnerNumber' ), ['*player', 'oldownernumber', 'newownernumber'] ) # Excludes mb.mem_funs('VoiceCommand').exclude() else: cls.rename('CHL2WarsGameRules') # Temp excludes mb.mem_funs('GetEncryptionKey').exclude() mb.mem_funs('GetViewVectors').exclude() # Call policies mb.mem_funs('GetNextBestWeapon').call_policies = call_policies.return_value_policy( call_policies.return_by_value ) # Hide instance mb.vars('m_pyInstance').exclude() mb.free_function('PyGameRules').include() mb.free_function('PyGameRules').rename('GameRules') # Installing the gamerules mb.free_function('PyInstallGameRules').include() mb.free_function('PyInstallGameRules').rename('InstallGameRules') # CAmmoDef mb.class_('CAmmoDef').include() mb.class_('CAmmoDef').mem_fun('GetAmmoOfIndex').exclude() mb.class_('CAmmoDef').vars('m_AmmoType').exclude() mb.free_function('GetAmmoDef').include() mb.free_function('GetAmmoDef').call_policies = call_policies.return_value_policy( call_policies.reference_existing_object ) # Remove any protected function mb.calldefs( matchers.access_type_matcher_t( 'protected' ) ).exclude()
""" myextractor=doxygen_doc_extractor() if __name__ == '__main__': module_name = '_libsimpa' #1. creating module builder mb = module_builder.module_builder_t( files=[ os.path.abspath('../dummy.hpp') ] , gccxml_path=os.environ["GCCXML"] , encoding='iso-8859-1') #mb.namespace("core_mathlib").exclude() mb.calldefs( access_type_matcher_t( 'protected' ) ).exclude() mb.calldefs( access_type_matcher_t( 'private' ) ).exclude() # #################################################### # SCRIPT POUR ../input_output/bin.h mb.class_("t_pos").decl("operator float *").exclude() # #################################################### # SCRIPT POUR ../input_output/gabe/stdgabe.h mb.namespace("formatGABE").exclude() mb.namespace("formatGABE").decls("GABE_OBJECTTYPE").include() mb.decls( lambda decl: 'impl_' in decl.name ).exclude() io_gabe=mb.class_("Gabe_rw") io_gabe.mem_fun("size").alias="__len__" #transforme le parametre en valeur de retour des fonctions commencant par ReadCol io_gabe.decls(lambda decl: decl.name.startswith( 'ReadCol' )).add_transformation( FT.output(1) ) # ####################################################
def ParseImageClasses(self, mb): # IBorder cls = mb.class_('IBorder') cls.include() cls.mem_funs('ApplySchemeSettings').include() cls.mem_funs('Paint').virtuality = 'pure virtual' cls.mem_funs('ApplySchemeSettings').virtuality = 'pure virtual' # IImage cls = mb.class_('IImage') cls.include() cls.mem_funs( 'GetContentSize' ).add_transformation( FT.output('wide'), FT.output('tall') ) cls.mem_funs( 'GetSize' ).add_transformation( FT.output('wide'), FT.output('tall') ) cls.mem_funs('Paint').virtuality = 'pure virtual' # Image cls = mb.class_('Image') cls.include() #cls.mem_funs( matchers.access_type_matcher_t( 'protected' ) ).exclude() cls.no_init = True #cls.calldefs().virtuality = 'not virtual' cls.calldefs('Image').exclude() cls.mem_funs( 'Paint' ).exclude() cls.add_wrapper_code( 'virtual void Paint() {}' ) # Stub for wrapper class. Otherwise it will complain. cls.mem_funs( 'GetSize' ).add_transformation( FT.output('wide'), FT.output('tall') ) cls.mem_funs( 'GetContentSize' ).add_transformation( FT.output('wide'), FT.output('tall') ) # FIXME: Py++ is giving problems on some functions cls.mem_funs('SetPos').virtuality = 'not virtual' #cls.mem_funs('GetPos').virtuality = 'not virtual' #cls.mem_funs('GetSize').virtuality = 'not virtual' #cls.mem_funs('GetContentSize').virtuality = 'not virtual' cls.mem_funs('SetColor').virtuality = 'not virtual' cls.mem_funs('SetBkColor').virtuality = 'not virtual' cls.mem_funs('GetColor').virtuality = 'not virtual' cls.mem_funs('SetSize').virtuality = 'not virtual' cls.mem_funs('DrawSetColor').virtuality = 'not virtual' cls.mem_funs('DrawSetColor').virtuality = 'not virtual' cls.mem_funs('DrawFilledRect').virtuality = 'not virtual' cls.mem_funs('DrawOutlinedRect').virtuality = 'not virtual' cls.mem_funs('DrawLine').virtuality = 'not virtual' cls.mem_funs('DrawPolyLine').virtuality = 'not virtual' cls.mem_funs('DrawSetTextFont').virtuality = 'not virtual' cls.mem_funs('DrawSetTextColor').virtuality = 'not virtual' cls.mem_funs('DrawSetTextPos').virtuality = 'not virtual' cls.mem_funs('DrawPrintText').virtuality = 'not virtual' cls.mem_funs('DrawPrintText').virtuality = 'not virtual' cls.mem_funs('DrawPrintChar').virtuality = 'not virtual' cls.mem_funs('DrawPrintChar').virtuality = 'not virtual' cls.mem_funs('DrawSetTexture').virtuality = 'not virtual' cls.mem_funs('DrawTexturedRect').virtuality = 'not virtual' # TextImage cls = mb.class_('TextImage') cls.include() cls.calldefs().virtuality = 'not virtual' cls.mem_funs( matchers.access_type_matcher_t( 'protected' ) ).exclude() #cls.calldefs('SetText', calldef_withtypes([pointer_t(const_t(declarated_t(wchar_t())))])).exclude() cls.mem_funs( 'GetContentSize' ).add_transformation( FT.output('wide'), FT.output('tall') ) cls.mem_funs( 'GetDrawWidth' ).add_transformation( FT.output('width') ) cls.mem_funs( 'SizeText' ).exclude() # DECLARATION ONLY cls.mem_funs('GetText').exclude() cls.add_wrapper_code( 'boost::python::object GetText() {\r\n' + \ ' char buf[1025];\r\n' + \ ' TextImage::GetText(buf, 1025);\r\n' + \ ' return boost::python::object(buf);\r\n' + \ '}' ) cls.add_registration_code( 'def( \r\n' + \ ' "GetText"\r\n' + \ ' , (boost::python::object ( TextImage_wrapper::* )())( &TextImage_wrapper::GetText ) )' ) # BitmapImage cls = mb.class_('BitmapImage') cls.include() cls.calldefs().virtuality = 'not virtual' if self.settings.branch == 'source2013': cls.mem_fun('SetBitmap').exclude() #cls.mem_funs( matchers.access_type_matcher_t( 'protected' ) ).exclude() cls.calldefs('GetColor', calldef_withtypes([reference_t(declarated_t(int_t()))])).add_transformation(FT.output('r'), FT.output('g'), FT.output('b'), FT.output('a')) cls.mem_funs( 'GetSize' ).add_transformation( FT.output('wide'), FT.output('tall') ) # CAvatarImage cls = mb.class_('CAvatarImage') cls.include() cls.calldefs().virtuality = 'not virtual' cls.mem_funs( matchers.access_type_matcher_t( 'protected' ) ).exclude() cls.rename('AvatarImage') cls.mem_funs( 'GetSize' ).add_transformation( FT.output('wide'), FT.output('tall') ) cls.mem_funs( 'GetContentSize' ).add_transformation( FT.output('wide'), FT.output('tall') ) cls.mem_funs( 'InitFromRGBA' ).exclude() mb.enum('EAvatarSize').include()
def Parse(self, mb): # Exclude everything by default mb.decls().exclude() gamerules = [ ("CGameRules", "C_GameRules", True), ("CMultiplayRules", "C_MultiplayRules", True), ("CSingleplayRules", "C_SingleplayRules", True), ("CTeamplayRules", "C_TeamplayRules", False), ] if "HL2MP" in self.symbols: gamerules.append(("CHL2MPRules", "C_HL2MPRules", False)) if "HL2WARS_DLL" in self.symbols: gamerules.append(("CHL2WarsGameRules", "C_HL2WarsGameRules", False)) for gamerulename, clientgamerulename, baseonly in gamerules: cls_name = gamerulename if self.isserver else clientgamerulename cls = mb.class_(cls_name) cls.include() if not baseonly: # Used internally cls.mem_funs("GetPySelf", allow_empty=True).exclude() cls.add_wrapper_code( "virtual PyObject *GetPySelf() const { return boost::python::detail::wrapper_base_::get_owner(*this); }" ) else: cls.no_init = True # Always use server class name cls.rename(gamerulename) mb.mem_funs("ShouldCollide").virtuality = "not virtual" mb.mem_funs("GetAmmoDamage").virtuality = "not virtual" # Just modify the ammo table when needed... if self.isserver: if self.settings.branch == "source2013": mb.mem_fun("TacticalMissionManagerFactory").exclude() if self.settings.branch == "swarm": mb.mem_funs("DoFindClientInPVS").exclude() mb.mem_funs("IsTopDown").virtuality = "not virtual" mb.mem_funs("ForceSplitScreenPlayersOnToSameTeam").virtuality = "not virtual" # Excludes mb.mem_funs("VoiceCommand").exclude() # Remove virtuality from or include some unneeded functions (would just slow down things) mb.mem_funs("FrameUpdatePostEntityThink").virtuality = "not virtual" # Calls Think mb.mem_funs("EndGameFrame").virtuality = "not virtual" mb.mem_funs("FAllowFlashlight", lambda d: d.virtuality == "virtual").virtuality = "not virtual" if "HL2MP" in self.symbols: mb.mem_funs("GetHL2MPViewVectors").exclude() if self.isclient: mb.mem_funs("RestartGame").exclude() mb.mem_funs("CheckAllPlayersReady").exclude() mb.mem_funs("CheckRestartGame").exclude() mb.mem_funs("CleanUpMap").exclude() if "HL2WARS_DLL" in self.symbols: if self.isserver: cls.mem_fun("GetIntermissionEndTime").exclude() cls.mem_fun("SetintermissionEndTime").exclude() cls.mem_fun("GetGameOver").exclude() cls.mem_fun("SetGameOver").exclude() cls.add_property( "intermissionendtime", cls.member_function("GetIntermissionEndTime"), cls.member_function("SetintermissionEndTime"), ) cls.add_property("gameover", cls.member_function("GetGameOver"), cls.member_function("SetGameOver")) # Remove virtuality because not needed mb.mem_funs("Damage_IsTimeBased", lambda d: d.virtuality == "virtual").virtuality = "not virtual" mb.mem_funs("Damage_ShouldGibCorpse", lambda d: d.virtuality == "virtual").virtuality = "not virtual" mb.mem_funs("Damage_ShowOnHUD", lambda d: d.virtuality == "virtual").virtuality = "not virtual" mb.mem_funs("Damage_NoPhysicsForce", lambda d: d.virtuality == "virtual").virtuality = "not virtual" mb.mem_funs("Damage_ShouldNotBleed", lambda d: d.virtuality == "virtual").virtuality = "not virtual" mb.mem_funs("Damage_GetTimeBased", lambda d: d.virtuality == "virtual").virtuality = "not virtual" mb.mem_funs("Damage_GetShouldGibCorpse", lambda d: d.virtuality == "virtual").virtuality = "not virtual" mb.mem_funs("Damage_GetShowOnHud", lambda d: d.virtuality == "virtual").virtuality = "not virtual" mb.mem_funs("Damage_GetNoPhysicsForce", lambda d: d.virtuality == "virtual").virtuality = "not virtual" mb.mem_funs("Damage_GetShouldNotBleed", lambda d: d.virtuality == "virtual").virtuality = "not virtual" # Exlude and replace cls.mem_fun("ClientConnected").exclude() cls.mem_fun("PyClientConnected").rename("ClientConnected") cls.mem_fun("ClientDisconnected").exclude() cls.mem_fun("PyClientDisconnected").rename("ClientDisconnected") # Temp excludes mb.mem_funs("GetEncryptionKey").exclude() mb.mem_funs("GetViewVectors").exclude() # Call policies mb.mem_funs("GetNextBestWeapon").call_policies = call_policies.return_value_policy( call_policies.return_by_value ) # Rename PyGameRules to just GameRules mb.free_function("PyGameRules").include() mb.free_function("PyGameRules").rename("GameRules") # Installing the gamerules mb.free_function("PyInstallGameRules").include() mb.free_function("PyInstallGameRules").rename("InstallGameRules") # CAmmoDef cls = mb.class_("CAmmoDef") cls.include() cls.mem_fun("GetAmmoOfIndex").exclude() cls.var("m_AmmoType").exclude() cls.var("m_nAmmoIndex").rename("ammoindex") mb.free_function("GetAmmoDef").include() mb.free_function("GetAmmoDef").call_policies = call_policies.return_value_policy( call_policies.reference_existing_object ) # Remove any protected function mb.calldefs(matchers.access_type_matcher_t("protected")).exclude() # Finally apply common rules to all includes functions and classes, etc. self.ApplyCommonRules(mb)
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;" )
gccxml_path=r"../../third_party/gccxml-0.9/bin/gccxml.exe", working_directory=r"..", include_paths=[ u'../../third_party/boost_1_44_0', u'../../third_party/dxsdk-9.0c-sum04/include', '.' ], define_symbols=[ 'WIN32=1', 'NDEBUG=1', '_LIB=1', 'UNICODE=1', '_UNICODE=1', '_HAS_TR1=0', 'BOOST_RANGE_ENABLE_CONCEPT_ASSERT=0', 'BOOST_MPL_CFG_ASSERT_USE_RELATION_NAMES=1' ]) mb.BOOST_PYTHON_MAX_ARITY = 16 mb.namespace('xfx').include() mb.calldefs(access_type_matcher_t('protected')).exclude() mb.variables(access_type_matcher_t('protected')).exclude() mb.calldefs(access_type_matcher_t('private')).exclude() mb.variables(access_type_matcher_t('private')).exclude() mb.decls(lambda x: x.name.startswith('_')).exclude() mb.variables(type='::boost::shared_ptr<xfx::Var>').include() mb.decls(lambda x: x.name.startswith('_D3DTRANSFORMSTATETYPE')).include() mb.decls(lambda x: x.name.startswith('_D3DCUBEMAP_FACES')).include() mb.decls(lambda x: x.name.startswith('_D3DFORMAT')).include() mb.decls(lambda x: x.name.startswith('_D3DPRIMITIVETYPE')).include() mb.decls(lambda x: x.name.startswith('_D3DVIEWPORT')).include() mb.decls(lambda x: x.name.startswith('_D3DPRESENT_PARAMETERS')).include() mb.decls(lambda x: x.name.startswith('_D3DCMPFUNC')).include() mb.class_("ITexture").member_functions().exclude()
def generate_code(): # # Use GCCXML to create the controlling XML file. # If the cache file (../cache/*.xml) doesn't exist it gets created, otherwise it just gets loaded # NOTE: If you update the source library code you need to manually delete the cache .XML file # #parser_conf = parser.project_reader.file_configuration_t( start_with_declarations=environment.namespaces ) defined_symbols = [] undefine_symbols = [] xml_cached_fc = parser.create_cached_source_fc( os.path.join( environment.root_dir, "python_Cream.h" ) , environment.cache_file ) mb = module_builder.module_builder_t( [ xml_cached_fc ] , working_directory=environment.root_dir , include_paths=environment.include_dirs , define_symbols=defined_symbols , undefine_symbols=undefine_symbols , indexing_suite_version=2 ) # Register boost::tuples mb.add_registration_code( 'boost::python::register_tuple< boost::tuple<glite::ce::cream_client_api::soap_proxy::JobIdWrapper::RESULT, glite::ce::cream_client_api::soap_proxy::JobIdWrapper, std::string> >();' ); mb.add_registration_code( 'boost::python::register_tuple< boost::tuple<glite::ce::cream_client_api::soap_proxy::JobStatusWrapper::RESULT, glite::ce::cream_client_api::soap_proxy::JobStatusWrapper, std::string> >();' ); mb.add_registration_code( 'boost::python::register_tuple< boost::tuple<glite::ce::cream_client_api::soap_proxy::JobInfoWrapper::RESULT, glite::ce::cream_client_api::soap_proxy::JobInfoWrapper, std::string> >();' ); # Expose classes mb.classes( lambda cls: cls.name in environment.classes ).include() # Expose enumerations mb.enumerations( lambda cls: cls.name in environment.enumerations ).include() # Expose functions mb.free_funs( lambda fun: fun.name in environment.functions ).include() # Exclude all protected functions mb.calldefs( access_type_matcher_t( 'protected' ) ).exclude() # Exclude some functions # I think it's a quite new function (even not yet documented, so no idea which params are in/out) mb.class_( 'CreamProxyFactory' ).mem_fun( 'make_CreamProxy_QueryEvent' ).exclude() # Take care of call policies for some functions # CreamProxyFactory mb.class_( name='CreamProxyFactory' ).member_functions( lambda decl: decl.name.startswith( 'make_CreamProxy' ) ).call_policies = call_policies.return_value_policy( call_policies.manage_new_object ) # Translate exceptions for ex in environment.exception_classes: exception = mb.class_( ex ) exception.translate_exception_to_string( ex, 'exc.what()') # Function transformations # JobPropertyWrapper has protected operator= mb.class_( 'JobPropertyWrapper' ).noncopyable = True # Temporarily disable some warnings (messages showed by py++ below) # Well, don't you want to see what is going on? # mb.print_declarations() #def my_doc_extractor( decl ): # print decl.location.file_name + str( decl.location.line ) # return decl.location.file_name + str( decl.location.line ) # Creating code creator. After this step you should not modify/customize declarations. # Additionaly extract Doxygen like documentation #mb.build_code_creator( module_name='Cream', doc_extractor=doxygen.doxygen_doc_extractor() ) mb.build_code_creator( module_name='Cream' ) #mb.build_code_creator( module_name='Cream', doc_extractor=my_doc_extractor ) mb.code_creator.add_include( 'pyplusplus_converters/tuples.hpp' ) mb.code_creator.precompiled_header = 'boost/python.hpp' # It is common requirement in software world - each file should have license mb.code_creator.license = '// GPLv3 License' # I don't want absolute includes within code mb.code_creator.user_defined_directories.append( os.path.abspath('.') ) # Writing code to file. mb.write_module( "Cream.cpp" )
def Parse(self, mb): mb.decls().exclude() # Get item getitem_wrapper = 'static ::vec_t GetItem( %(cls_name)s const & inst, int i ) {\r\n' + \ ' if( i < 0 || i > %(nitems)s ) {\r\n' + \ ' PyErr_SetString(PyExc_IndexError, "Index out of range" );\r\n' + \ ' throw boost::python::error_already_set();\r\n' + \ ' }\r\n' + \ ' return inst[i];\r\n' + \ '}\r\n' getitem_reg = '%(cls_name)s_exposer.def( "__getitem__", &::%(cls_name)s_wrapper::GetItem );\r\n' # Set item setitem_wrapper = 'static void SetItem( %(cls_name)s & inst, int i, ::vec_t v ) {\r\n' + \ ' if( i < 0 || i > %(nitems)s ) {\r\n' + \ ' PyErr_SetString(PyExc_IndexError, "Index out of range" );\r\n' + \ ' throw boost::python::error_already_set();\r\n' + \ ' }\r\n' + \ ' inst[i] = v;\r\n' + \ '}\r\n' setitem_reg = '%(cls_name)s_exposer.def( "__setitem__", &::%(cls_name)s_wrapper::SetItem );\r\n' # String str_vmatrix_wrapper = 'static boost::python::object Str( VMatrix const & inst ) {\r\n' + \ ' return boost::python::object(VMatToString(inst));\r\n' + \ '}\r\n' str_reg = '%(cls_name)s_exposer.def( "__str__", &::%(cls_name)s_wrapper::Str );\r\n' # Classes cls = mb.class_('Vector') cls.include() cls.mem_opers('=').exclude() # Breaks debug mode and don't really need it cls.add_wrapper_code( getitem_wrapper % {'cls_name' : 'Vector', 'nitems' : '2' } ) cls.add_registration_code( getitem_reg % {'cls_name':'Vector'}, False) cls.add_wrapper_code( setitem_wrapper % {'cls_name' : 'Vector', 'nitems' : '2' } ) cls.add_registration_code( setitem_reg % {'cls_name':'Vector'}, False) cls = mb.class_('Vector2D') cls.include() cls.mem_opers('=').exclude() # Breaks debug mode and don't really need it cls.add_wrapper_code( getitem_wrapper % {'cls_name' : 'Vector2D', 'nitems' : '1' } ) cls.add_registration_code( getitem_reg % {'cls_name':'Vector2D'}, False) cls.add_wrapper_code( setitem_wrapper % {'cls_name' : 'Vector2D', 'nitems' : '1' } ) cls.add_registration_code( setitem_reg % {'cls_name':'Vector2D'}, False) cls = mb.class_('QAngle') cls.include() cls.mem_opers('=').exclude() # Breaks debug mode and don't really need it cls.add_wrapper_code( getitem_wrapper % {'cls_name' : 'QAngle', 'nitems' : '2' } ) cls.add_registration_code( getitem_reg % {'cls_name':'QAngle'}, False) cls.add_wrapper_code( setitem_wrapper % {'cls_name' : 'QAngle', 'nitems' : '2' } ) cls.add_registration_code( setitem_reg % {'cls_name':'QAngle'}, False) cls = mb.class_('Quaternion') cls.include() cls.mem_opers('=').exclude() # Breaks debug mode and don't really need it mb.free_function('QAngleToAngularImpulse').include() mb.free_function('AngularImpulseToQAngle').include() # Call policies mb.mem_funs('AsVector2D').call_policies = call_policies.return_internal_reference() # Transform functions that take pointers as arguments mb.free_functions('SolveInverseQuadraticMonotonic').add_transformation( FT.output('a'), FT.output('b'), FT.output('c') ) mb.free_functions('ComputeTrianglePlane').add_transformation( FT.output('intercept') ) mb.free_functions('CalcSqrDistAndClosestPointOnAABB').add_transformation( FT.output('distSqrOut') ) mb.free_functions('SolveInverseReciprocalQuadratic').add_transformation( FT.output('a'), FT.output('b'), FT.output('c') ) mb.free_functions('SolveQuadratic').add_transformation( FT.output('root1'), FT.output('root2') ) mb.free_functions('SolveInverseQuadratic').add_transformation( FT.output('a'), FT.output('b'), FT.output('c') ) mb.free_functions('QuaternionAxisAngle').add_transformation( FT.output('axis'), FT.output('angle') ) mb.free_functions('RotationDeltaAxisAngle').add_transformation( FT.output('deltaAxis'), FT.output('deltaAngle') ) # Compressed color mb.class_('ColorRGBExp32').include() # cplane_t mb.class_('cplane_t').include() mb.class_('cplane_t').var('pad').exclude() # matrix3x4_t mb.class_('matrix3x4_t').include() mb.class_('matrix3x4_t').mem_opers().exclude() # ----- # Add custom item access functions to the Vector class mb.global_ns.mem_opers('[]').exclude() mb.class_('Vector').add_registration_code( 'def( bp::init< const Vector & >(( bp::arg("vOther") )) )') mb.class_('QAngle').add_registration_code( 'def( bp::init< const QAngle & >(( bp::arg("vOther") )) )') # Vars mb.vars('vec3_origin').include() mb.vars('vec3_angle').include() mb.vars('vec3_invalid').include() mb.vars('nanmask').include() # Mathlib.h functions mb.free_function('RandomAngularImpulse').include() mb.free_functions('VectorMaximum').include() mb.free_functions('VectorMAInline').include() mb.free_functions('VectorMA').include() mb.free_functions('RoundInt').include() mb.free_functions('Q_log2').include() mb.free_functions('SinCos').include() mb.free_functions('TableCos').include() mb.free_functions('TableSin').include() if self.settings.branch == 'swarm': mb.free_functions('IsPowerOfTwo').include() mb.free_functions('SmallestPowerOfTwoGreaterOrEqual').include() mb.free_functions('LargestPowerOfTwoLessThanOrEqual').include() mb.free_functions('FloorDivMod').include() mb.free_functions('GreatestCommonDivisor').include() mb.free_functions('IsDenormal').include() mb.free_functions('MatrixVectors').include() mb.free_functions('VectorRotate').include() mb.free_functions('TransformAnglesToLocalSpace').include() mb.free_functions('MatrixInitialize').include() mb.free_functions('MatrixCopy').include() mb.free_functions('MatrixInvert').include() mb.free_functions('MatricesAreEqual').include() mb.free_functions('MatrixGetColumn').include() mb.free_functions('MatrixSetColumn').include() mb.free_functions('ConcatRotations').include() mb.free_functions('ConcatTransforms').include() mb.free_functions('MatrixMultiply').include() mb.free_function('QuaternionSlerp').include() mb.free_function('QuaternionSlerpNoAlign').include() mb.free_function('QuaternionBlend').include() mb.free_function('QuaternionBlendNoAlign').include() mb.free_function('QuaternionIdentityBlend').include() mb.free_function('QuaternionAngleDiff').include() mb.free_function('QuaternionScale').include() mb.free_function('QuaternionDotProduct').include() mb.free_function('QuaternionConjugate').include() mb.free_function('QuaternionInvert').include() mb.free_function('QuaternionNormalize').include() mb.free_function('QuaternionAdd').include() mb.free_function('QuaternionMult').include() mb.free_functions('QuaternionMatrix').include() mb.free_functions('QuaternionAngles').include() mb.free_functions('AngleQuaternion').include() mb.free_function('QuaternionAxisAngle').include() mb.free_function('AxisAngleQuaternion').include() mb.free_function('BasisToQuaternion').include() mb.free_function('MatrixQuaternion').include() mb.free_functions('MatrixRowDotProduct').include() mb.free_functions('MatrixColumnDotProduct').include() mb.free_functions('anglemod').include() mb.free_functions('RemapVal').include() mb.free_functions('RemapValClamped').include() mb.free_functions('Lerp').include() mb.free_functions('Sqr').include() mb.free_functions('FLerp').include() mb.free_functions('Sign').include() mb.free_functions('ClampArrayBounds').include() mb.free_functions('AngleVectors').include() mb.free_functions('AngleVectors').include() mb.free_functions('AngleVectorsTranspose').include() mb.free_functions('AngleMatrix').include() mb.free_functions('AngleMatrix').include() mb.free_functions('AngleIMatrix').include() mb.free_functions('VectorAngles').include() mb.free_functions('VectorMatrix').include() mb.free_functions('VectorVectors').include() mb.free_functions('SetIdentityMatrix').include() mb.free_functions('SetScaleMatrix').include() mb.free_functions('MatrixBuildRotationAboutAxis').include() mb.free_functions('MatrixTranspose').include() mb.free_functions('MatrixInverseTranspose').include() mb.free_functions('PositionMatrix').include() mb.free_functions('MatrixPosition').include() mb.free_functions('VectorRotate').include() mb.free_functions('VectorIRotate').include() mb.free_functions('MatrixAngles').include() mb.free_functions('VectorCompare').include() mb.free_functions('VectorTransform').include() mb.free_functions('VectorITransform').include() mb.free_functions('BoxOnPlaneSide').include() mb.free_functions('VectorFill').include() mb.free_functions('VectorNegate').include() mb.free_functions('VectorAvg').include() mb.free_functions('BoxOnPlaneSide2').include() mb.free_functions('ClearBounds').include() mb.free_functions('AddPointToBounds').include() mb.free_functions('BuildGammaTable').include() mb.free_functions('TexLightToLinear').include() mb.free_functions('LinearToTexture').include() mb.free_functions('LinearToScreenGamma').include() mb.free_functions('TextureToLinear').include() mb.free_functions('SolveQuadratic').include() mb.free_functions('SolveInverseQuadratic').include() mb.free_functions('SolveInverseQuadraticMonotonic').include() mb.free_functions('SolveInverseReciprocalQuadratic').include() mb.free_functions('VectorYawRotate').include() mb.free_functions('Bias').include() mb.free_functions('Gain').include() mb.free_functions('SmoothCurve').include() mb.free_functions('SmoothCurve_Tweak').include() mb.free_functions('ExponentialDecay').include() mb.free_functions('ExponentialDecay').include() mb.free_functions('ExponentialDecayIntegral').include() mb.free_functions('SimpleSpline').include() mb.free_functions('SimpleSplineRemapVal').include() mb.free_functions('SimpleSplineRemapValClamped').include() mb.free_functions('RoundFloatToInt').include() mb.free_functions('RoundFloatToByte').include() mb.free_functions('RoundFloatToUnsignedLong').include() mb.free_functions('IsIntegralValue').include() mb.free_functions('Float2Int').include() mb.free_functions('Floor2Int').include() mb.free_functions('FastFToC').include() mb.free_functions('ClampToMsec').include() mb.free_functions('Ceil2Int').include() mb.free_functions('GetBarycentricCoords2D').include() mb.free_functions('QuickBoxSphereTest').include() mb.free_functions('QuickBoxIntersectTest').include() mb.free_functions('GammaToLinearFullRange').include() mb.free_functions('LinearToGammaFullRange').include() mb.free_functions('GammaToLinear').include() mb.free_functions('LinearToGamma').include() mb.free_functions('SrgbGammaToLinear').include() mb.free_functions('SrgbLinearToGamma').include() mb.free_functions('X360GammaToLinear').include() mb.free_functions('X360LinearToGamma').include() mb.free_functions('SrgbGammaTo360Gamma').include() mb.free_functions('LinearToVertexLight').include() mb.free_functions('LinearToLightmap').include() mb.free_functions('ColorClamp').include() mb.free_functions('ColorClampTruncate').include() mb.free_functions('Catmull_Rom_Spline').include() mb.free_functions('Catmull_Rom_Spline_Tangent').include() mb.free_functions('Catmull_Rom_Spline_Integral').include() mb.free_functions('Catmull_Rom_Spline_Integral').include() mb.free_functions('Catmull_Rom_Spline_Normalize').include() mb.free_functions('Catmull_Rom_Spline_Integral_Normalize').include() mb.free_functions('Catmull_Rom_Spline_NormalizeX').include() mb.free_functions('Catmull_Rom_Spline_NormalizeX').include() mb.free_functions('Hermite_Spline').include() #mb.free_functions('Hermite_SplineBasis').include() mb.free_functions('Kochanek_Bartels_Spline').include() mb.free_functions('Kochanek_Bartels_Spline_NormalizeX').include() mb.free_functions('Cubic_Spline').include() mb.free_functions('Cubic_Spline_NormalizeX').include() mb.free_functions('BSpline').include() mb.free_functions('BSpline_NormalizeX').include() mb.free_functions('Parabolic_Spline').include() mb.free_functions('Parabolic_Spline_NormalizeX').include() mb.free_functions('QuinticInterpolatingPolynomial').include() #mb.free_functions('GetInterpolationData').include() mb.free_functions('RangeCompressor').include() mb.free_functions('CalcSqrDistanceToAABB').include() mb.free_functions('CalcClosestPointOnAABB').include() mb.free_functions('CalcSqrDistAndClosestPointOnAABB').include() mb.free_functions('CalcDistanceToAABB').include() #mb.free_functions('CalcLineToLineIntersectionSegment').include() # TODO mb.free_functions('Approach').include() mb.free_functions('ApproachAngle').include() mb.free_functions('AngleDiff').include() mb.free_functions('AngleDistance').include() mb.free_functions('AngleNormalize').include() mb.free_functions('AngleNormalizePositive').include() mb.free_functions('AnglesAreEqual').include() mb.free_functions('RotationDeltaAxisAngle').include() mb.free_functions('RotationDelta').include() mb.free_functions('ComputeTrianglePlane').include() mb.free_functions('PolyFromPlane').include() mb.free_functions('ClipPolyToPlane').include() mb.free_functions('ClipPolyToPlane_Precise').include() mb.free_functions('CalcTriangleTangentSpace').include() mb.free_functions('TransformAABB').include() mb.free_functions('ITransformAABB').include() mb.free_functions('RotateAABB').include() mb.free_functions('IRotateAABB').include() mb.free_functions('MatrixTransformPlane').include() mb.free_functions('MatrixITransformPlane').include() mb.free_functions('CeilPow2').include() mb.free_functions('FloorPow2').include() mb.free_functions('RGBtoHSV').include() mb.free_functions('HSVtoRGB').include() # Vector.h functions mb.free_functions('VectorClear').include() mb.free_functions('VectorCopy').include() mb.free_functions('VectorAdd').include() mb.free_functions('VectorSubtract').include() mb.free_functions('VectorMultiply').include() mb.free_functions('VectorDivide').include() mb.free_functions('VectorScale').include() mb.free_functions('VectorMA').include() mb.free_functions('VectorsAreEqual').include() mb.free_functions('ComputeClosestPoint').include() mb.free_functions('VectorAbs').include() mb.free_functions('VectorLength').include() mb.free_functions('DotProduct').include() mb.free_functions('CrossProduct').include() mb.free_functions('VectorMin').include() mb.free_functions('VectorMax').include() mb.free_functions('VectorLerp').include() mb.free_functions('RandomVector').include() mb.free_functions('QAnglesAreEqual').include() #mb.free_functions('QAngleToAngularImpulse').include() #mb.free_functions('AngularImpulseToQAngle').include() mb.free_functions('VectorNormalize').include() mb.free_functions('VectorNormalizeFast').include() # Vector2d.h functions mb.free_functions('Vector2DClear').include() mb.free_functions('Vector2DCopy').include() mb.free_functions('Vector2DAdd').include() mb.free_functions('Vector2DSubtract').include() mb.free_functions('Vector2DMultiply').include() mb.free_functions('Vector2DDivide').include() mb.free_functions('Vector2DMA').include() mb.free_functions('Vector2DMin').include() mb.free_functions('Vector2DMax').include() mb.free_functions('Vector2DLength').include() mb.free_functions('DotProduct2D').include() mb.free_functions('Vector2DLerp').include() mb.free_functions('Vector2DNormalize').include() mb.free_functions('ComputeClosestPoint2D').include() # QAngle functions mb.free_function('RandomAngle').include() # VMatrix cls = mb.class_('VMatrix') cls.include() cls.mem_opers('=').exclude() # Breaks debug mode and don't really need it cls.mem_opers('[]').exclude() cls.mem_funs('Base').exclude() cls.vars('m').exclude() cls.mem_fun('As3x4', matchers.calldef_matcher_t(return_type=reference_t(declarated_t(mb.class_('matrix3x4_t'))))).exclude() cls.mem_fun('GetTranslation', matchers.calldef_matcher_t(return_type=reference_t(declarated_t(mb.class_('Vector'))))).exclude() cls.add_wrapper_code( str_vmatrix_wrapper % {'cls_name':'VMatrix'} ) cls.add_registration_code( str_reg % {'cls_name':'VMatrix'}, False) mb.free_functions('MatrixSetIdentity').include() mb.free_functions('MatrixTranspose').include() mb.free_functions('MatrixCopy').include() mb.free_functions('MatrixMultiply').include() mb.free_functions('MatrixGetColumn').include() mb.free_functions('MatrixSetColumn').include() mb.free_functions('MatrixGetRow').include() mb.free_functions('MatrixSetRow').include() mb.free_functions('MatrixTranslate').include() mb.free_functions('MatrixBuildRotationAboutAxis').include() mb.free_functions('MatrixBuildRotateZ').include() mb.free_functions('MatrixRotate').include() mb.free_functions('MatrixFromAngles').include() mb.free_functions('MatrixToAngles').include() # Exclude if self.settings.branch not in ['swarm', 'source2013']: mb.vars('pfVectorNormalizeFast').exclude() mb.vars('pfVectorNormalize').exclude() mb.vars('pfInvRSquared').exclude() mb.vars('m_flMatVal').exclude() mb.vars('quat_identity').exclude() # <- Does not even exist except for a declaration? # Exclude some functions mb.mem_funs('Base').exclude() # Base gives a pointer to the address of the data. Not very python like. mb.free_functions( 'AllocTempVector' ).exclude() mb.class_('Vector2D').mem_funs('Cross').exclude() # Declaration only? mb.free_function('ConcatRotations').exclude() # Declaration only? # Remove any protected function mb.calldefs( matchers.access_type_matcher_t( 'protected' ) ).exclude() # Remove any function with "float *" values # A lot of functions have two versions (or more), of which one takes "float *" arguments vec_t = mb.typedef('vec_t') excludetypes = [ pointer_t(float_t()), pointer_t(const_t(float_t())), pointer_t(declarated_t(vec_t)), pointer_t(const_t(declarated_t(vec_t))), ] mb.calldefs( calldef_withtypes( excludetypes ) ).exclude() # Silent warnings of generating class wrappers mb.classes().disable_warnings( messages.W1027 ) # Include functions with "float *" parameter. For these functions we should transform the "float *" parameter mb.free_functions('CalcClosestPointOnLine2D').include() mb.free_functions('CalcClosestPointOnLine2D').add_transformation( FT.output('t') ) mb.free_functions('CalcDistanceToLine2D').include() mb.free_functions('CalcDistanceToLine2D').add_transformation( FT.output('t') ) mb.free_functions('CalcDistanceSqrToLine2D').include() mb.free_functions('CalcDistanceSqrToLine2D').add_transformation( FT.output('t') ) mb.free_functions('CalcClosestPointOnLineSegment2D').include() mb.free_functions('CalcClosestPointOnLineSegment2D').add_transformation( FT.output('t') ) mb.free_functions('CalcDistanceToLineSegment2D').include() mb.free_functions('CalcDistanceToLineSegment2D').add_transformation( FT.output('t') ) mb.free_functions('CalcDistanceSqrToLineSegment2D').include() mb.free_functions('CalcDistanceSqrToLineSegment2D').add_transformation( FT.output('t') ) mb.free_functions('CalcClosestPointOnLine').include() mb.free_functions('CalcClosestPointOnLine').add_transformation( FT.output('t') ) mb.free_functions('CalcDistanceToLine').include() mb.free_functions('CalcDistanceToLine').add_transformation( FT.output('t') ) mb.free_functions('CalcDistanceSqrToLine').include() mb.free_functions('CalcDistanceSqrToLine').add_transformation( FT.output('t') ) mb.free_functions('CalcClosestPointOnLineSegment').include() mb.free_functions('CalcClosestPointOnLineSegment').add_transformation( FT.output('t') ) mb.free_functions('CalcDistanceToLineSegment').include() mb.free_functions('CalcDistanceToLineSegment').add_transformation( FT.output('t') ) mb.free_functions('CalcDistanceSqrToLineSegment').include() mb.free_functions('CalcDistanceSqrToLineSegment').add_transformation( FT.output('t') )
def Parse(self, mb): # Exclude everything by default mb.decls().exclude() gamerules = [ ('CGameRules', 'C_GameRules', True), ('CMultiplayRules', 'C_MultiplayRules', True), ('CSingleplayRules', 'C_SingleplayRules', True), ('CTeamplayRules', 'C_TeamplayRules', False), ] if 'HL2MP' in self.symbols: gamerules.append(('CHL2MPRules', 'C_HL2MPRules', False)) for gamerulename, clientgamerulename, baseonly in gamerules: cls_name = gamerulename if self.isserver else clientgamerulename cls = mb.class_(cls_name) cls.include() if not baseonly: # Used internally cls.mem_funs('GetPySelf', allow_empty=True).exclude() cls.add_wrapper_code( 'virtual PyObject *GetPySelf() const { return boost::python::detail::wrapper_base_::get_owner(*this); }' ) else: cls.no_init = True # Always use server class name cls.rename(gamerulename) mb.mem_funs('ShouldCollide').virtuality = 'not virtual' mb.mem_funs( 'GetAmmoDamage' ).virtuality = 'not virtual' # Just modify the ammo table when needed... mb.mem_funs('NetworkStateChanged').exclude() if self.isserver: if self.settings.branch == 'source2013': mb.mem_fun('TacticalMissionManagerFactory').exclude() if self.settings.branch == 'swarm': mb.mem_funs('DoFindClientInPVS').exclude() mb.mem_funs('IsTopDown').virtuality = 'not virtual' mb.mem_funs('ForceSplitScreenPlayersOnToSameTeam' ).virtuality = 'not virtual' # Excludes mb.mem_funs('VoiceCommand').exclude() # Remove virtuality from or include some unneeded functions (would just slow down things) mb.mem_funs('FrameUpdatePostEntityThink' ).virtuality = 'not virtual' # Calls Think mb.mem_funs('EndGameFrame').virtuality = 'not virtual' mb.mem_funs( 'FAllowFlashlight', lambda d: d.virtuality == 'virtual').virtuality = 'not virtual' if 'HL2MP' in self.symbols: mb.mem_funs('GetHL2MPViewVectors').exclude() if self.isclient: mb.mem_funs('RestartGame').exclude() mb.mem_funs('CheckAllPlayersReady').exclude() mb.mem_funs('CheckRestartGame').exclude() mb.mem_funs('CleanUpMap').exclude() # Temp excludes mb.mem_funs('GetEncryptionKey').exclude() mb.mem_funs('GetViewVectors').exclude() # Call policies mb.mem_funs('GetNextBestWeapon' ).call_policies = call_policies.return_value_policy( call_policies.return_by_value) # Rename PyGameRules to just GameRules mb.free_function('PyGameRules').include() mb.free_function('PyGameRules').rename('GameRules') # Installing the gamerules mb.free_function('PyInstallGameRules').include() mb.free_function('PyInstallGameRules').rename('InstallGameRules') # CAmmoDef cls = mb.class_('CAmmoDef') cls.include() cls.mem_fun('GetAmmoOfIndex').exclude() cls.var('m_AmmoType').exclude() cls.var('m_nAmmoIndex').rename('ammoindex') mb.free_function('GetAmmoDef').include() mb.free_function( 'GetAmmoDef').call_policies = call_policies.return_value_policy( call_policies.reference_existing_object) # Remove any protected function mb.calldefs(matchers.access_type_matcher_t('protected')).exclude() # Finally apply common rules to all includes functions and classes, etc. self.ApplyCommonRules(mb)
def ParseMisc(self, mb): # CUserCmd, player commands cls = mb.class_('CUserCmd') cls.include() cls.calldefs().exclude() self.PythonfyVariables(cls) # Save/restore interfaces. Just empty. cls = mb.class_('IRestore') cls.include() cls.calldefs().exclude() cls = mb.class_('ISave') cls.include() cls.calldefs().exclude() if self.isserver: # Sky camera mb.free_function('GetCurrentSkyCamera').include() mb.free_function('GetCurrentSkyCamera').call_policies = call_policies.return_value_policy(call_policies.return_by_value) # CTakeDamageInfo cls = mb.class_('CTakeDamageInfo') cls.include() cls.calldefs( matchers.access_type_matcher_t( 'protected' ) ).exclude() cls.mem_funs('GetInflictor').call_policies = call_policies.return_value_policy(call_policies.return_by_value) cls.mem_funs('GetWeapon').call_policies = call_policies.return_value_policy(call_policies.return_by_value) cls.mem_funs('GetAttacker').call_policies = call_policies.return_value_policy(call_policies.return_by_value) cls = mb.class_('CMultiDamage') cls.include() cls.calldefs( matchers.access_type_matcher_t( 'protected' ) ).exclude() cls.mem_funs('GetTarget').call_policies = call_policies.return_value_policy(call_policies.return_by_value) mb.free_functions('ClearMultiDamage').include() mb.free_functions('ApplyMultiDamage').include() mb.free_functions('AddMultiDamage').include() mb.free_functions('ImpulseScale').include() mb.free_functions('CalculateExplosiveDamageForce').include() mb.free_functions('CalculateBulletDamageForce').include() mb.free_functions('CalculateMeleeDamageForce').include() mb.free_functions('GuessDamageForce').include() # FireBulletsInfo_t cls = mb.class_('FireBulletsInfo_t') cls.include() cls.var('m_iShots').rename('shots') cls.var('m_vecSrc').rename('vecsrc') cls.var('m_vecDirShooting').rename('vecdirshooting') cls.var('m_vecSpread').rename('vecspread') cls.var('m_flDistance').rename('distance') cls.var('m_iAmmoType').rename('ammotype') cls.var('m_iTracerFreq').rename('tracerfreq') cls.var('m_nFlags').rename('flags') cls.var('m_flDamageForceScale').rename('damageforcescale') cls.var('m_pAttacker').rename('attacker') cls.var('m_pAdditionalIgnoreEnt').rename('additionalignoreent') cls.var('m_bPrimaryAttack').rename('primaryattack') cls.var('m_flDamage').rename('damage') cls.var('m_iPlayerDamage' if self.settings.branch == 'source2013' else 'm_flPlayerDamage').rename('playerdamage') mb.enum('FireBulletsFlags_t').include() # CShotManipulator cls = mb.class_('CShotManipulator') cls.include() if self.isserver: # Bone follower cls = mb.class_('pyphysfollower_t') cls.include() cls.rename('physfollower') cls = mb.class_('PyBoneFollowerManager') cls.include() cls.rename('BoneFollowerManager') mb.free_function('GetAttachmentPositionInSpaceOfBone').include() # Ragdoll functions mb.free_function('CreateServerRagdoll').include() mb.free_function('CreateServerRagdoll').call_policies = call_policies.return_value_policy(call_policies.return_by_value) if self.settings.branch == 'swarm': mb.free_function('PyCreateServerRagdollAttached').include() mb.free_function('PyCreateServerRagdollAttached').rename('CreateServerRagdollAttached') mb.free_function('PyCreateServerRagdollAttached').call_policies = call_policies.return_value_policy(call_policies.return_by_value) mb.free_function('DetachAttachedRagdoll').include() mb.free_function('DetachAttachedRagdollsForEntity').include() # Shared Props mb.class_('breakablepropparams_t').include() mb.free_functions('GetMassEquivalent').include() mb.free_functions('GetAutoMultiplayerPhysicsMode').include() mb.free_functions('PropBreakableCreateAll').include() mb.free_functions('PrecacheGibsForModel').include() # Enums mb.enums('MoveType_t').include() mb.enums('SolidType_t').include() mb.enums('SolidFlags_t').include() mb.enums('Collision_Group_t').include() mb.enums('RenderMode_t').include() mb.enums('RenderFx_t').include() if self.isclient: mb.enums('ShadowType_t').include() mb.enums('RenderGroup_t').include() mb.enums('DataUpdateType_t').include() mb.enums('CollideType_t').include() mb.enums('ShouldTransmitState_t').include() mb.enums('OverrideType_t').include() else: mb.enums('EntityEvent_t').include() mb.enums('Class_T').include() mb.enums('_fieldtypes').include() mb.enums('USE_TYPE').include() mb.enums('Activity').include() # Anim event cls = mb.class_('animevent_t') cls.include() cls.add_wrapper_code( 'static bp::object get_options(animevent_t const & inst){\r\n' + \ ' return bp::object(inst.options);\r\n' + \ '}\r\n' ) cls.add_registration_code( 'add_property("options"\r\n' + \ " , bp::make_function( (bp::object (*)( ::animevent_t & ))(&animevent_t_wrapper::get_options) ) )\r\n" ) # Solid_t class mb.classes('solid_t').include() # Types/Contants if self.isserver: mb.add_registration_code( "bp::scope().attr( \"SOUND_NONE\" ) = (int)SOUND_NONE;" ) mb.add_registration_code( "bp::scope().attr( \"SOUND_COMBAT\" ) = (int)SOUND_COMBAT;" ) mb.add_registration_code( "bp::scope().attr( \"SOUND_WORLD\" ) = (int)SOUND_WORLD;" ) mb.add_registration_code( "bp::scope().attr( \"SOUND_PLAYER\" ) = (int)SOUND_PLAYER;" ) mb.add_registration_code( "bp::scope().attr( \"SOUND_DANGER\" ) = (int)SOUND_DANGER;" ) mb.add_registration_code( "bp::scope().attr( \"SOUND_BULLET_IMPACT\" ) = (int)SOUND_BULLET_IMPACT;" ) mb.add_registration_code( "bp::scope().attr( \"SOUND_CARCASS\" ) = (int)SOUND_CARCASS;" ) mb.add_registration_code( "bp::scope().attr( \"SOUND_GARBAGE\" ) = (int)SOUND_GARBAGE;" ) mb.add_registration_code( "bp::scope().attr( \"SOUND_THUMPER\" ) = (int)SOUND_THUMPER;" ) mb.add_registration_code( "bp::scope().attr( \"SOUND_BUGBAIT\" ) = (int)SOUND_BUGBAIT;" ) mb.add_registration_code( "bp::scope().attr( \"SOUND_PHYSICS_DANGER\" ) = (int)SOUND_PHYSICS_DANGER;" ) mb.add_registration_code( "bp::scope().attr( \"SOUND_DANGER_SNIPERONLY\" ) = (int)SOUND_DANGER_SNIPERONLY;" ) mb.add_registration_code( "bp::scope().attr( \"SOUND_MOVE_AWAY\" ) = (int)SOUND_MOVE_AWAY;" ) mb.add_registration_code( "bp::scope().attr( \"SOUND_PLAYER_VEHICLE\" ) = (int)SOUND_PLAYER_VEHICLE;" ) mb.add_registration_code( "bp::scope().attr( \"SOUND_READINESS_LOW\" ) = (int)SOUND_READINESS_LOW;" ) mb.add_registration_code( "bp::scope().attr( \"SOUND_READINESS_MEDIUM\" ) = (int)SOUND_READINESS_MEDIUM;" ) mb.add_registration_code( "bp::scope().attr( \"SOUND_READINESS_HIGH\" ) = (int)SOUND_READINESS_HIGH;" ) mb.add_registration_code( "bp::scope().attr( \"SOUND_CONTEXT_FROM_SNIPER\" ) = (int)SOUND_CONTEXT_FROM_SNIPER;" ) mb.add_registration_code( "bp::scope().attr( \"SOUND_CONTEXT_GUNFIRE\" ) = (int)SOUND_CONTEXT_GUNFIRE;" ) mb.add_registration_code( "bp::scope().attr( \"SOUND_CONTEXT_MORTAR\" ) = (int)SOUND_CONTEXT_MORTAR;" ) mb.add_registration_code( "bp::scope().attr( \"SOUND_CONTEXT_COMBINE_ONLY\" ) = (int)SOUND_CONTEXT_COMBINE_ONLY;" ) mb.add_registration_code( "bp::scope().attr( \"SOUND_CONTEXT_REACT_TO_SOURCE\" ) = (int)SOUND_CONTEXT_REACT_TO_SOURCE;" ) mb.add_registration_code( "bp::scope().attr( \"SOUND_CONTEXT_EXPLOSION\" ) = (int)SOUND_CONTEXT_EXPLOSION;" ) mb.add_registration_code( "bp::scope().attr( \"SOUND_CONTEXT_EXCLUDE_COMBINE\" ) = (int)SOUND_CONTEXT_EXCLUDE_COMBINE;" ) mb.add_registration_code( "bp::scope().attr( \"SOUND_CONTEXT_DANGER_APPROACH\" ) = (int)SOUND_CONTEXT_DANGER_APPROACH;" ) mb.add_registration_code( "bp::scope().attr( \"SOUND_CONTEXT_ALLIES_ONLY\" ) = (int)SOUND_CONTEXT_ALLIES_ONLY;" ) mb.add_registration_code( "bp::scope().attr( \"SOUND_CONTEXT_PLAYER_VEHICLE\" ) = (int)SOUND_CONTEXT_PLAYER_VEHICLE;" ) mb.add_registration_code( "bp::scope().attr( \"ALL_CONTEXTS\" ) = (int)ALL_CONTEXTS;" ) mb.add_registration_code( "bp::scope().attr( \"ALL_SCENTS\" ) = (int)ALL_SCENTS;" ) mb.add_registration_code( "bp::scope().attr( \"ALL_SOUNDS\" ) = (int)ALL_SOUNDS;" ) # Channels mb.add_registration_code( "bp::scope().attr( \"SOUNDENT_CHANNEL_UNSPECIFIED\" ) = (int)SOUNDENT_CHANNEL_UNSPECIFIED;" ) mb.add_registration_code( "bp::scope().attr( \"SOUNDENT_CHANNEL_REPEATING\" ) = (int)SOUNDENT_CHANNEL_REPEATING;" ) mb.add_registration_code( "bp::scope().attr( \"SOUNDENT_CHANNEL_REPEATED_DANGER\" ) = (int)SOUNDENT_CHANNEL_REPEATED_DANGER;" ) mb.add_registration_code( "bp::scope().attr( \"SOUNDENT_CHANNEL_REPEATED_PHYSICS_DANGER\" ) = (int)SOUNDENT_CHANNEL_REPEATED_PHYSICS_DANGER;" ) mb.add_registration_code( "bp::scope().attr( \"SOUNDENT_CHANNEL_WEAPON\" ) = (int)SOUNDENT_CHANNEL_WEAPON;" ) mb.add_registration_code( "bp::scope().attr( \"SOUNDENT_CHANNEL_INJURY\" ) = (int)SOUNDENT_CHANNEL_INJURY;" ) mb.add_registration_code( "bp::scope().attr( \"SOUNDENT_CHANNEL_BULLET_IMPACT\" ) = (int)SOUNDENT_CHANNEL_BULLET_IMPACT;" ) mb.add_registration_code( "bp::scope().attr( \"SOUNDENT_CHANNEL_NPC_FOOTSTEP\" ) = (int)SOUNDENT_CHANNEL_NPC_FOOTSTEP;" ) mb.add_registration_code( "bp::scope().attr( \"SOUNDENT_CHANNEL_SPOOKY_NOISE\" ) = (int)SOUNDENT_CHANNEL_SPOOKY_NOISE;" ) mb.add_registration_code( "bp::scope().attr( \"SOUNDENT_CHANNEL_ZOMBINE_GRENADE\" ) = (int)SOUNDENT_CHANNEL_ZOMBINE_GRENADE;" ) # Transmit state mb.add_registration_code( "bp::scope().attr( \"FL_EDICT_CHANGED\" ) = (int)FL_EDICT_CHANGED;" ) mb.add_registration_code( "bp::scope().attr( \"FL_EDICT_FREE\" ) = (int)FL_EDICT_FREE;" ) mb.add_registration_code( "bp::scope().attr( \"FL_EDICT_FULL\" ) = (int)FL_EDICT_FULL;" ) mb.add_registration_code( "bp::scope().attr( \"FL_EDICT_FULLCHECK\" ) = (int)FL_EDICT_FULLCHECK;" ) mb.add_registration_code( "bp::scope().attr( \"FL_EDICT_ALWAYS\" ) = (int)FL_EDICT_ALWAYS;" ) mb.add_registration_code( "bp::scope().attr( \"FL_EDICT_DONTSEND\" ) = (int)FL_EDICT_DONTSEND;" ) mb.add_registration_code( "bp::scope().attr( \"FL_EDICT_PVSCHECK\" ) = (int)FL_EDICT_PVSCHECK;" ) mb.add_registration_code( "bp::scope().attr( \"FL_EDICT_PENDING_DORMANT_CHECK\" ) = (int)FL_EDICT_PENDING_DORMANT_CHECK;" ) mb.add_registration_code( "bp::scope().attr( \"FL_EDICT_DIRTY_PVS_INFORMATION\" ) = (int)FL_EDICT_DIRTY_PVS_INFORMATION;" ) mb.add_registration_code( "bp::scope().attr( \"FL_FULL_EDICT_CHANGED\" ) = (int)FL_FULL_EDICT_CHANGED;" )
def ParseMisc(self, mb): # CUserCmd, player commands cls = mb.class_('CUserCmd') cls.include() cls.calldefs().exclude() self.PythonfyVariables(cls) # Save/restore interfaces. Just empty. cls = mb.class_('IRestore') cls.include() cls.calldefs().exclude() cls = mb.class_('ISave') cls.include() cls.calldefs().exclude() if self.isserver: # Sky camera mb.free_function('GetCurrentSkyCamera').include() mb.free_function( 'GetCurrentSkyCamera' ).call_policies = call_policies.return_value_policy( call_policies.return_by_value) # CTakeDamageInfo cls = mb.class_('CTakeDamageInfo') cls.include() cls.calldefs(matchers.access_type_matcher_t('protected')).exclude() cls.mem_funs( 'GetInflictor').call_policies = call_policies.return_value_policy( call_policies.return_by_value) cls.mem_funs( 'GetWeapon').call_policies = call_policies.return_value_policy( call_policies.return_by_value) cls.mem_funs( 'GetAttacker').call_policies = call_policies.return_value_policy( call_policies.return_by_value) self.SetupProperty(cls, 'attributes', 'GetAttributes', 'SetAttributes') self.SetupProperty(cls, 'forcefriendlyfire', 'IsForceFriendlyFire', 'SetForceFriendlyFire') cls = mb.class_('CMultiDamage') cls.include() cls.calldefs(matchers.access_type_matcher_t('protected')).exclude() cls.mem_funs( 'GetTarget').call_policies = call_policies.return_value_policy( call_policies.return_by_value) mb.free_functions('ClearMultiDamage').include() mb.free_functions('ApplyMultiDamage').include() mb.free_functions('AddMultiDamage').include() mb.free_functions('ImpulseScale').include() mb.free_functions('CalculateExplosiveDamageForce').include() mb.free_functions('CalculateBulletDamageForce').include() mb.free_functions('CalculateMeleeDamageForce').include() mb.free_functions('GuessDamageForce').include() # FireBulletsInfo_t cls = mb.class_('FireBulletsInfo_t') cls.include() cls.var('m_iShots').rename('shots') cls.var('m_vecSrc').rename('vecsrc') cls.var('m_vecDirShooting').rename('vecdirshooting') cls.var('m_vecSpread').rename('vecspread') cls.var('m_flDistance').rename('distance') cls.var('m_iAmmoType').rename('ammotype') cls.var('m_iTracerFreq').rename('tracerfreq') cls.var('m_nFlags').rename('flags') cls.var('m_flDamageForceScale').rename('damageforcescale') cls.var('m_pAttacker').rename('attacker') cls.var('m_pAdditionalIgnoreEnt').rename('additionalignoreent') cls.var('m_bPrimaryAttack').rename('primaryattack') cls.var('m_flDamage').rename('damage') cls.var('m_iPlayerDamage' if self.settings.branch == 'source2013' else 'm_flPlayerDamage').rename('playerdamage') cls.var('m_Attributes').rename('attributes') mb.enum('FireBulletsFlags_t').include() # CShotManipulator cls = mb.class_('CShotManipulator') cls.include() if self.isserver: # Bone follower cls = mb.class_('pyphysfollower_t') cls.include() cls.rename('physfollower') cls = mb.class_('PyBoneFollowerManager') cls.include() cls.rename('BoneFollowerManager') mb.free_function('GetAttachmentPositionInSpaceOfBone').include() # Ragdoll functions mb.free_function('CreateServerRagdoll').include() mb.free_function( 'CreateServerRagdoll' ).call_policies = call_policies.return_value_policy( call_policies.return_by_value) if self.settings.branch == 'swarm': mb.free_function('PyCreateServerRagdollAttached').include() mb.free_function('PyCreateServerRagdollAttached').rename( 'CreateServerRagdollAttached') mb.free_function( 'PyCreateServerRagdollAttached' ).call_policies = call_policies.return_value_policy( call_policies.return_by_value) mb.free_function('DetachAttachedRagdoll').include() mb.free_function('DetachAttachedRagdollsForEntity').include() # Shared Props mb.class_('breakablepropparams_t').include() mb.free_functions('GetMassEquivalent').include() mb.free_functions('GetAutoMultiplayerPhysicsMode').include() mb.free_functions('PropBreakableCreateAll').include() mb.free_functions('PrecacheGibsForModel').include() # Save/restore helpers for Python cls = mb.class_('PySaveHelper') cls.include() cls.no_init = True cls = mb.class_('PyRestoreHelper') cls.include() cls.no_init = True cls.mem_fun('SetActiveField').exclude() # Enums mb.enums('MoveType_t').include() mb.enums('MoveCollide_t').include() mb.enums('SolidType_t').include() mb.enums('SolidFlags_t').include() mb.enums('Collision_Group_t').include() mb.enums('RenderMode_t').include() mb.enums('RenderFx_t').include() if self.isclient: mb.enums('ShadowType_t').include() mb.enums('RenderGroup_t').include() mb.enums('DataUpdateType_t').include() mb.enums('CollideType_t').include() mb.enums('ShouldTransmitState_t').include() mb.enums('OverrideType_t').include() else: mb.enums('EntityEvent_t').include() mb.enums('Class_T').include() mb.enums('_fieldtypes').include() mb.enums('USE_TYPE').include() mb.enums('Activity').include() # Anim event cls = mb.class_('animevent_t') cls.include() cls.add_wrapper_code( 'static bp::object get_options(animevent_t const & inst){\r\n' + \ ' return bp::object(inst.options);\r\n' + \ '}\r\n' ) cls.add_registration_code( 'add_property("options"\r\n' + \ " , bp::make_function( (bp::object (*)( ::animevent_t & ))(&animevent_t_wrapper::get_options) ) )\r\n" ) # Solid_t class mb.classes('solid_t').include() # Types/Contants if self.isserver: mb.add_registration_code( "bp::scope().attr( \"SOUND_NONE\" ) = (int)SOUND_NONE;") mb.add_registration_code( "bp::scope().attr( \"SOUND_COMBAT\" ) = (int)SOUND_COMBAT;") mb.add_registration_code( "bp::scope().attr( \"SOUND_WORLD\" ) = (int)SOUND_WORLD;") mb.add_registration_code( "bp::scope().attr( \"SOUND_PLAYER\" ) = (int)SOUND_PLAYER;") mb.add_registration_code( "bp::scope().attr( \"SOUND_DANGER\" ) = (int)SOUND_DANGER;") mb.add_registration_code( "bp::scope().attr( \"SOUND_BULLET_IMPACT\" ) = (int)SOUND_BULLET_IMPACT;" ) mb.add_registration_code( "bp::scope().attr( \"SOUND_CARCASS\" ) = (int)SOUND_CARCASS;") mb.add_registration_code( "bp::scope().attr( \"SOUND_GARBAGE\" ) = (int)SOUND_GARBAGE;") mb.add_registration_code( "bp::scope().attr( \"SOUND_THUMPER\" ) = (int)SOUND_THUMPER;") mb.add_registration_code( "bp::scope().attr( \"SOUND_BUGBAIT\" ) = (int)SOUND_BUGBAIT;") mb.add_registration_code( "bp::scope().attr( \"SOUND_PHYSICS_DANGER\" ) = (int)SOUND_PHYSICS_DANGER;" ) mb.add_registration_code( "bp::scope().attr( \"SOUND_DANGER_SNIPERONLY\" ) = (int)SOUND_DANGER_SNIPERONLY;" ) mb.add_registration_code( "bp::scope().attr( \"SOUND_MOVE_AWAY\" ) = (int)SOUND_MOVE_AWAY;" ) mb.add_registration_code( "bp::scope().attr( \"SOUND_PLAYER_VEHICLE\" ) = (int)SOUND_PLAYER_VEHICLE;" ) mb.add_registration_code( "bp::scope().attr( \"SOUND_READINESS_LOW\" ) = (int)SOUND_READINESS_LOW;" ) mb.add_registration_code( "bp::scope().attr( \"SOUND_READINESS_MEDIUM\" ) = (int)SOUND_READINESS_MEDIUM;" ) mb.add_registration_code( "bp::scope().attr( \"SOUND_READINESS_HIGH\" ) = (int)SOUND_READINESS_HIGH;" ) mb.add_registration_code( "bp::scope().attr( \"SOUND_CONTEXT_FROM_SNIPER\" ) = (int)SOUND_CONTEXT_FROM_SNIPER;" ) mb.add_registration_code( "bp::scope().attr( \"SOUND_CONTEXT_GUNFIRE\" ) = (int)SOUND_CONTEXT_GUNFIRE;" ) mb.add_registration_code( "bp::scope().attr( \"SOUND_CONTEXT_MORTAR\" ) = (int)SOUND_CONTEXT_MORTAR;" ) mb.add_registration_code( "bp::scope().attr( \"SOUND_CONTEXT_COMBINE_ONLY\" ) = (int)SOUND_CONTEXT_COMBINE_ONLY;" ) mb.add_registration_code( "bp::scope().attr( \"SOUND_CONTEXT_REACT_TO_SOURCE\" ) = (int)SOUND_CONTEXT_REACT_TO_SOURCE;" ) mb.add_registration_code( "bp::scope().attr( \"SOUND_CONTEXT_EXPLOSION\" ) = (int)SOUND_CONTEXT_EXPLOSION;" ) mb.add_registration_code( "bp::scope().attr( \"SOUND_CONTEXT_EXCLUDE_COMBINE\" ) = (int)SOUND_CONTEXT_EXCLUDE_COMBINE;" ) mb.add_registration_code( "bp::scope().attr( \"SOUND_CONTEXT_DANGER_APPROACH\" ) = (int)SOUND_CONTEXT_DANGER_APPROACH;" ) mb.add_registration_code( "bp::scope().attr( \"SOUND_CONTEXT_ALLIES_ONLY\" ) = (int)SOUND_CONTEXT_ALLIES_ONLY;" ) mb.add_registration_code( "bp::scope().attr( \"SOUND_CONTEXT_PLAYER_VEHICLE\" ) = (int)SOUND_CONTEXT_PLAYER_VEHICLE;" ) mb.add_registration_code( "bp::scope().attr( \"ALL_CONTEXTS\" ) = (int)ALL_CONTEXTS;") mb.add_registration_code( "bp::scope().attr( \"ALL_SCENTS\" ) = (int)ALL_SCENTS;") mb.add_registration_code( "bp::scope().attr( \"ALL_SOUNDS\" ) = (int)ALL_SOUNDS;") # Channels mb.add_registration_code( "bp::scope().attr( \"SOUNDENT_CHANNEL_UNSPECIFIED\" ) = (int)SOUNDENT_CHANNEL_UNSPECIFIED;" ) mb.add_registration_code( "bp::scope().attr( \"SOUNDENT_CHANNEL_REPEATING\" ) = (int)SOUNDENT_CHANNEL_REPEATING;" ) mb.add_registration_code( "bp::scope().attr( \"SOUNDENT_CHANNEL_REPEATED_DANGER\" ) = (int)SOUNDENT_CHANNEL_REPEATED_DANGER;" ) mb.add_registration_code( "bp::scope().attr( \"SOUNDENT_CHANNEL_REPEATED_PHYSICS_DANGER\" ) = (int)SOUNDENT_CHANNEL_REPEATED_PHYSICS_DANGER;" ) mb.add_registration_code( "bp::scope().attr( \"SOUNDENT_CHANNEL_WEAPON\" ) = (int)SOUNDENT_CHANNEL_WEAPON;" ) mb.add_registration_code( "bp::scope().attr( \"SOUNDENT_CHANNEL_INJURY\" ) = (int)SOUNDENT_CHANNEL_INJURY;" ) mb.add_registration_code( "bp::scope().attr( \"SOUNDENT_CHANNEL_BULLET_IMPACT\" ) = (int)SOUNDENT_CHANNEL_BULLET_IMPACT;" ) mb.add_registration_code( "bp::scope().attr( \"SOUNDENT_CHANNEL_NPC_FOOTSTEP\" ) = (int)SOUNDENT_CHANNEL_NPC_FOOTSTEP;" ) mb.add_registration_code( "bp::scope().attr( \"SOUNDENT_CHANNEL_SPOOKY_NOISE\" ) = (int)SOUNDENT_CHANNEL_SPOOKY_NOISE;" ) mb.add_registration_code( "bp::scope().attr( \"SOUNDENT_CHANNEL_ZOMBINE_GRENADE\" ) = (int)SOUNDENT_CHANNEL_ZOMBINE_GRENADE;" ) # Transmit state mb.add_registration_code( "bp::scope().attr( \"FL_EDICT_CHANGED\" ) = (int)FL_EDICT_CHANGED;" ) mb.add_registration_code( "bp::scope().attr( \"FL_EDICT_FREE\" ) = (int)FL_EDICT_FREE;") mb.add_registration_code( "bp::scope().attr( \"FL_EDICT_FULL\" ) = (int)FL_EDICT_FULL;") mb.add_registration_code( "bp::scope().attr( \"FL_EDICT_FULLCHECK\" ) = (int)FL_EDICT_FULLCHECK;" ) mb.add_registration_code( "bp::scope().attr( \"FL_EDICT_ALWAYS\" ) = (int)FL_EDICT_ALWAYS;" ) mb.add_registration_code( "bp::scope().attr( \"FL_EDICT_DONTSEND\" ) = (int)FL_EDICT_DONTSEND;" ) mb.add_registration_code( "bp::scope().attr( \"FL_EDICT_PVSCHECK\" ) = (int)FL_EDICT_PVSCHECK;" ) mb.add_registration_code( "bp::scope().attr( \"FL_EDICT_PENDING_DORMANT_CHECK\" ) = (int)FL_EDICT_PENDING_DORMANT_CHECK;" ) mb.add_registration_code( "bp::scope().attr( \"FL_EDICT_DIRTY_PVS_INFORMATION\" ) = (int)FL_EDICT_DIRTY_PVS_INFORMATION;" ) mb.add_registration_code( "bp::scope().attr( \"FL_FULL_EDICT_CHANGED\" ) = (int)FL_FULL_EDICT_CHANGED;" )
def Parse(self, mb): # Exclude everything by default mb.decls().exclude() gamerules = [ ('CGameRules', 'C_GameRules', True), ('CMultiplayRules', 'C_MultiplayRules', True), ('CSingleplayRules', 'C_SingleplayRules', True), ('CTeamplayRules', 'C_TeamplayRules', False), ] if 'HL2MP' in self.symbols: gamerules.append(('CHL2MPRules', 'C_HL2MPRules', False)) for gamerulename, clientgamerulename, baseonly in gamerules: cls_name = gamerulename if self.isserver else clientgamerulename cls = mb.class_(cls_name) cls.include() if not baseonly: # Used internally cls.mem_funs('GetPySelf', allow_empty=True).exclude() cls.add_wrapper_code( 'virtual PyObject *GetPySelf() const { return boost::python::detail::wrapper_base_::get_owner(*this); }' ) else: cls.no_init = True # Always use server class name cls.rename(gamerulename) mb.mem_funs('ShouldCollide').virtuality = 'not virtual' mb.mem_funs('GetAmmoDamage').virtuality = 'not virtual' # Just modify the ammo table when needed... if self.isserver: if self.settings.branch == 'source2013': mb.mem_fun('TacticalMissionManagerFactory').exclude() if self.settings.branch == 'swarm': mb.mem_funs('DoFindClientInPVS').exclude() mb.mem_funs('IsTopDown').virtuality = 'not virtual' mb.mem_funs('ForceSplitScreenPlayersOnToSameTeam').virtuality = 'not virtual' # Excludes mb.mem_funs('VoiceCommand').exclude() # Remove virtuality from or include some unneeded functions (would just slow down things) mb.mem_funs('FrameUpdatePostEntityThink').virtuality = 'not virtual' # Calls Think mb.mem_funs('EndGameFrame').virtuality = 'not virtual' mb.mem_funs('FAllowFlashlight', lambda d: d.virtuality == 'virtual').virtuality = 'not virtual' if 'HL2MP' in self.symbols: mb.mem_funs('GetHL2MPViewVectors').exclude() if self.isclient: mb.mem_funs('RestartGame').exclude() mb.mem_funs('CheckAllPlayersReady').exclude() mb.mem_funs('CheckRestartGame').exclude() mb.mem_funs('CleanUpMap').exclude() # Temp excludes mb.mem_funs('GetEncryptionKey').exclude() mb.mem_funs('GetViewVectors').exclude() # Call policies mb.mem_funs('GetNextBestWeapon').call_policies = call_policies.return_value_policy(call_policies.return_by_value) # Rename PyGameRules to just GameRules mb.free_function('PyGameRules').include() mb.free_function('PyGameRules').rename('GameRules') # Installing the gamerules mb.free_function('PyInstallGameRules').include() mb.free_function('PyInstallGameRules').rename('InstallGameRules') # CAmmoDef cls = mb.class_('CAmmoDef') cls.include() cls.mem_fun('GetAmmoOfIndex').exclude() cls.var('m_AmmoType').exclude() cls.var('m_nAmmoIndex').rename('ammoindex') mb.free_function('GetAmmoDef').include() mb.free_function('GetAmmoDef').call_policies = call_policies.return_value_policy(call_policies.reference_existing_object) # Remove any protected function mb.calldefs( matchers.access_type_matcher_t('protected') ).exclude() # Finally apply common rules to all includes functions and classes, etc. self.ApplyCommonRules(mb)
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.mem_funs( 'SetText', lambda decl: HasArgType(decl, '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 ) )' ) """ cls.add_wrapper_code( '''virtual void GetTextSize( int & wide, int & tall ){ bp::override func_GetTextSize = this->get_override( "GetTextSize" ); if( func_GetTextSize.ptr() != Py_None ) try { func_GetTextSize( wide, tall ); } catch(bp::error_already_set &) { PyErr_Print(); this->vgui::TextImage::GetTextSize( wide, tall ); } else this->vgui::TextImage::GetTextSize( wide, tall ); } virtual boost::python::tuple default_GetTextSize() { int wide2; int tall2; vgui::TextImage::GetTextSize( wide2, tall2 ); return bp::make_tuple( wide2, tall2 ); }''' ) cls.add_registration_code( '''{ //::vgui::TextImage::GetTextSize typedef void ( TextImage_wrapper::*GetTextSize_function_type )() ; TextImage_exposer.def( "GetTextSize" , GetTextSize_function_type( &TextImage_wrapper::default_GetTextSize ) ); }''' , works_on_instance=False ) """ # BitmapImage cls = mb.class_('BitmapImage') cls.include() cls.calldefs().virtuality = 'not virtual' #cls.mem_funs( matchers.access_type_matcher_t( 'protected' ) ).exclude() cls.mem_funs( 'GetColor', lambda decl: HasArgType(decl, 'int') ).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()
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;" )
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'))