本文主要介紹ue4注冊(cè)表(如何注冊(cè)u(píng)e4引擎),下面一起看看ue4注冊(cè)表(如何注冊(cè)u(píng)e4引擎)相關(guān)資訊。
版本:4.26.2 ue4c項(xiàng)目名稱(chēng):myproject
在《宏generated_body做了什么?》,簡(jiǎn)單分析了generated_body宏添加到從uobject繼承的簡(jiǎn)單自定義類(lèi)中的內(nèi)容。
涉及的源文件有:objectmacros.h、myobject.h、myobject.generated.h、uobjectglobals.h
現(xiàn)在讓我們 讓我們分析uht生成的另一個(gè)文件:myobject.gen.cpp
涉及的附加源文件有:uobjectbase.h、uobjectbase.cpp、class.h、class.cpp、uobjectglobals.cpp。
什么?;s在myobject.gen.cpp?請(qǐng)先貼代碼,會(huì)添加一些中文注釋。
//版權(quán)epic games,inc .保留所有權(quán)利。/* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =生成的代碼從unrealheadertool導(dǎo)出。請(qǐng)勿手動(dòng)修改!編輯相應(yīng)的。改為件!= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */# include u object/generated cpp includes . h #包含 我的項(xiàng)目/公共/我的對(duì)象# ifdef _ msc _ v: 4883)# endifpragma _ disable _ deprecation _ warnings void emptylinkfunctionforgeneratedcodemyobject{ }//交叉模塊引用my project _ api uclass * z _ constructt _ uclass _ umy object _ no register;my project _ api uclass * z _ construct _ uclass _ umy object;coreu object _ api uclass * z _ construct _ uclass _ u object;uppackage * z _ construct _ uppackage _ _ script _ my project;// end cross模塊references void umyobject: :staticregisteretivesumyobject{ } uclass * z _ construct _ uclass _ umyobject _ no register{ return umyobject: :static class;} struct z _ construct _ uclass _ umy object _ statics { static u object *(* const dependent singletons[]);# if with _ metadata static const ue 4 codegen _ private ::metadatapairparam class _ metadata params[];# endif static const fcppclasstypeinfo static static cppclasstypeinfo;靜態(tài)常數(shù)ue 4 codegen _ private ::fclassparams class params;};u object *(* const z _ construct _ uclass _ umy object _ static s::dependentsingletons[])= {(u object *))z _ construct _ uclass _ u object,(u object *(*))z _ construct _ up package _ _ script _ my project,};# if with _ metadata const ue4 codegen _private : :metadatapairparam z _ construct _ uclass _ umy object _ static s: class _ metadata params[]= { { 藍(lán)圖類(lèi)型 , 真實(shí) }、{ 評(píng)論 , /* * \ n * n */ }、{ 包括路徑 , 我的對(duì)象}、{ modulerelativepath , public/my object . h }、{ objectinitializerconstructordeclared , },};# endif const fcppclasstypeinfostatic z _ construct _ uclass _ umy object _ static s: :isabstract,};// ue_array_count宏計(jì)算數(shù)組的大小// metadata_params簡(jiǎn)單宏拆分成兩個(gè)參數(shù),或者撤回第二個(gè)宏;根據(jù)是否定義了with_metadata宏;見(jiàn)const ue 4 codegen _ private : :fclassarams z _ construct _ uclass _ umy object _ static s:的定義。lass params = { umyobject::static class,nullptr,staticcppclasstypeinfo,dependentsingletons,nullptr,nullptr,ue _ array _ count(dependent singletons),0,0,0,0x001000a0u,metadata _ params(z _ construct _ uclass _ umyobject _ static s: : class _ metadata params,ue _ array _ count(z _ construct _ uclass _ umy object _ static s: : class _ metadata params))};//concerns-1 uclass * z _ construct _ uclass _ umy object{ static uclass * outer class = nullptr;如果(!outer class){ ue 4 codegen _ private : : constructuclass(outer class,z _ construct _ uclass _ umy object _ static s: : classparams);}返回outerclass}// implement_class(umyobject,1944586990);//宏展開(kāi)后的以下代碼//關(guān)注-2靜態(tài)tclasscompiledintereumyobject autoinitializeumyobject(text( umyobject ),sizeof (umyobject),1944586990);uclass * umyobject: :getprivatestaticclass{ static uclass * privatestaticclass = null;如果(!privatestaticclass){/*這可以用模板來(lái)處理,但是我們希望它是外部的,以避免代碼膨脹*/getprivatestaticclassbody(static package,(tchar *)text( umyobject )1((staticclassflags class _ deprecat: 0)、privatestaticclass、staticregisternativesumyobject、sizeof(umyobject)、align of(umyo object)、(eclassflags)umyobject:staticclassflags、umyobject:staticclasscastflags、umyobject:staticconfigname、(uclass: : classconstructortype)internalconstructormyobject、(internalconstructorumyobject}返回privatestaticclass}模板my project _ api uclass * staticclassumyobject{ return umyobject::static class;}//concern-3靜態(tài)fcompiledindefer z _ compiledindefer _ uclass _ umy object(z _ construct _ uclass _ umy object,umyobject: :static class,text( /script/my project ),文字( umyobject )、false、nullptr、nullptr、nullptr);// define_vtable_ptr_helper _ ctor(umy object);//下面這段宏展開(kāi)后的代碼是umyobject: :u object(fvtabl: super(helper){ };pragma _ enable _ ablation _ warnings # ifdef _ msc _ ver # pragma warning(pop)# endif上面的代碼中增加了三個(gè)關(guān)注注釋?zhuān)旅媸且稽c(diǎn)分析。
分析上面列出了myobject.gen.cpp文件的內(nèi)容。讓 下面我們來(lái)分析一下關(guān)注點(diǎn)。
fcompiledindefer類(lèi)是在uobjectbase.件中通過(guò)首先查看【關(guān)注-3】來(lái)定義的:
struct fcompiledindefer { fcompiledindefer(class uclass *(* in register),class uclass *(*instaticclass),const tchar* packagename,const tchar* name,bool bdynamic,const tchar * dynamic packagename = nullptr,const tchar * dynamic pathname = nullptr,void(* ininitsearchablevalues)(tmap fname)= nullptr){ if(bdynamic){ getconverteddynamic packagenametotypename。add(fname(dynamicpackagename),fname(name));} uobjectcompiledindefer(in register,instaticclass,name,packagename,bdynamic,dynamicpathname,ininitsearchablevalues);}};函數(shù)uobjectcompiledindefer(...)在構(gòu)造函數(shù)內(nèi)部直接調(diào)用;
因?yàn)閰?shù)bdynamic=false,所以在函數(shù)uobjectcompiledindefer(...)如下:
tarrayuclass *(*)deferredcompiledinregistration = getdeferredcompiledinregistration;checkslow(!deferredcompiledinregistration。包含(in register));deferredcompiledinregistration。add(in register);函數(shù)getdeferredcompilating registration定義如下:
static tarray class uclass *(*)getdeferredcompiledinregistration{ static tarray class uclass *(*)deferredcompiledinregistration;返回deferredcompiledinregistration;}內(nèi)部數(shù)組deferredcompiledinregistration也是一個(gè)靜態(tài)對(duì)象;
將參數(shù)inregister的函數(shù)指針添加到deferredcompiledinregistration數(shù)組中;
即函數(shù)z_construct_uclass_umyobject的地址將被添加到deferredcompiledinregistration數(shù)組中;
tclasscompiledindefer類(lèi):[concern-2]uobjectbase . 件中也定義了這個(gè)類(lèi);
類(lèi)似于fcompiledindefer
不同的是,靜態(tài)tclass compilating deferumyobject autoinitializeumyobject被添加到另一個(gè)靜態(tài)數(shù)組中;
我贏了。;這里就不贅述了;
函數(shù)uclass * z _ construct _ uclass _ umy object[focus-1]有什么好說(shuō)的?
根據(jù)以上分析,通過(guò)函數(shù)指針將該函數(shù)添加到靜態(tài)數(shù)組deferredcompil:
其返回值是一個(gè)uclass對(duì)象;內(nèi)部constructuclass函數(shù)的第二個(gè)參數(shù)是z _ constru _ uclass _ umyobject _ static s: :classparams,是代碼上半部分umy object類(lèi)信息收集的數(shù)據(jù)。函數(shù)ctuclass是在uobjectglobals . h/uobjectglobals . cpp文件中定義的;
結(jié)合《宏generated_body做了什么?》的分析,這里會(huì)得到一個(gè)調(diào)用棧:z _ construct _ uclass _ umyobject(...)-構(gòu)造uclass(...)-umyobject::staticclass。-umyobject::getprivatestaticclass-getprivatestaticclassbody(...)
而我們從getprivatestaticclass可以看到,一個(gè)自定義類(lèi)只會(huì)創(chuàng)建一個(gè)uclass對(duì)象;函數(shù)z_construct_uclass_umyobject只是注冊(cè)的,真正調(diào)用是在引擎初始化階段;總結(jié):上面列出了myobject.gen.cpp中的內(nèi)容;
并劃分了密鑰注冊(cè)機(jī)制;
在myobject.gen.cpp中,自定義類(lèi)的信息是通過(guò)靜態(tài)對(duì)象(在程序加載時(shí)創(chuàng)建,早于main函數(shù))的特性收集的:
通過(guò)靜態(tài)tclass computing deferumyobject autoinitializeumyobject對(duì)象收集名稱(chēng)、大小和唯一id。通過(guò)靜態(tài)fcompiledindefer z _ compiledindefer _ uclass _ umyobject對(duì)象注冊(cè)一個(gè)函數(shù),函數(shù)返回一個(gè)uclass對(duì)象,用來(lái)描述umy object類(lèi);需要反復(fù)指出的是,全類(lèi)型信息注冊(cè)的時(shí)機(jī)在程序加載階段,早于主函數(shù);
當(dāng)這里用于測(cè)試時(shí),它是一個(gè)簡(jiǎn)單的類(lèi),沒(méi)有方法和屬性;
但是自動(dòng)類(lèi)型注冊(cè)的一般機(jī)制是相同的。
結(jié)束
標(biāo)簽:
功能焦點(diǎn)
了解更多ue4注冊(cè)表(如何注冊(cè)u(píng)e4引擎)相關(guān)內(nèi)容請(qǐng)關(guān)注本站點(diǎn)。