荣耀彩票代理

IT技术互动交流平台

虚幻4蓝图虚拟机剖析

作者:风恋残雪  来源:IT165收集  发布日期:2016-11-14 20:23:52

前言

荣耀彩票代理ZHEILI,WOMENDASUANDUIXUHUAN4 ZHONGLANTUXUNIJIDESHIXIANZUOYIGEDAGAIDEJIANGJIE,RUGUODUIQITADEJIAOBENYUYANDESHIXIANYOUBIJIAOQINGCHUDERENSHI,LIJIEQILAIHUIRONGYIHENDUO,WOMENXIANHUIDUIXIANGGUANSHUYUJINXINGYIGEJIANDANDEJIESHAO,RANHOUHUIDUILANTUXUNIJIDESHIXIANZUOYIGEJIANGJIE。

术语

BIANCHENGYUYANYIBANFENWEIBIANYIYUYANHEJIESHIXINGYUYAN。

编译型语言

程序在执行之前需要一个专门的编译过程,把程序编译成 为机器语言的文件,运行时不需要重新翻译,直接使用编译的结果就行了。程序执行效率高,依赖编译器,跨平台性差些。如C、C++、Delphi等.

解释性语言

BIANXIEDECHENGXUBUJINXINGYUXIANBIANYI,YIWENBENFANGSHICUNCHUCHENGXUDAIMA。ZAIFABUCHENGXUSHI,KANQILAISHENGLEDAOBIANYIGONGXU。DANSHI,ZAIYUNXINGCHENGXUDESHIHOU,JIESHIXINGYUYANBIXUXIANJIESHIZAIYUNXING。

荣耀彩票代理RANERGUANYUJava、C#DENGSHIFOUWEIJIESHIXINGYUYANCUNZAIZHENGYI,YINWEITAMENZHULIUDESHIXIANBINGBUSHIZHIJIEJIESHIZHIXINGDE,ERSHIYEBIANYICHENGZIJIEMA,RANHOUZAIYUNXINGZAIjvmDENGXUNIJISHANGDE。

荣耀彩票代理UE4ZHONGLANTUDESHIXIANGENGXIANGSHIluaDESHIXIANFANGSHI,TABINGBUNENGDULIYUNXING,ERSHIZUOWEIYIZHONGQIANRUSUZHUYUYANDEYIZHONGKUOZHANJIAOBEN,luaKEYIZHIJIEJIESHIZHIXING,YEKEYIBIANYICHENGZIJIEMABINGBAOCUNDAOCIPANSHANG,XIACIDIAOYONGKEYIZHIJIEJIAZAIBIANYIHAODEZIJIEMAZHIXING。

什么是虚拟机

荣耀彩票代理XUNIJIZUICHUYOUBOPEIKE[a]YUGEDEBAODINGYIWEIYOUXIAODE、DULIDEZHENSHIJIQIDEFUBEN。DANGQIANBAOKUOGENRENHEZHENSHIJIQIWUGUANDEXUNIJI。XUNIJIGENJUTAMENDEYUNYONGHEYUZHIJIEJIQIDEXIANGGUANXINGFENWEILIANGDALEI。XITONGXUNIJI(RUVirtualBox)TIGONGYIGEKEYIYUNXINGWANZHENGCAOZUOXITONGDEWANZHENGXITONGPINGTAI。XIANGFANDE,CHENGXUXUNIJI(RUJava JVM)WEIYUNXINGDANGEJISUANJICHENGXUSHEJI,ZHEIYIWEITAZHICHIDANGEJINCHENG。XUNIJIDEYIGEBENZHITEDIANSHIYUNXINGZAIXUNIJISHANGDERUANJIANBEIJUXIANZAIXUNIJITIGONGDEZIYUANLI——TABUNENGCHAOCHUXUNISHIJIE。

荣耀彩票代理ERZHEILIWOMENZHUYAOGUANXINDESHICHENGXUXUNIJI,VMJIRANBEICHENGWEI'JIQI',YIBANRENWEISHURUSHIMANZUMOUZHONGZHILINGJIJIAGOU(instruction set architecture,ISA)DEZHILINGXULIE,ZHONGJIANZHUANHUANWEIMUBIAOISADEZHILINGXULIEBINGJIAYIZHIXING,SHUCHUWEICHENGXUDEZHIXINGJIEGUODE,JIUSHIVM。YUANYUMUBIAOISAKEYISHITONGYIZHONG,ZHEISHISUOWEIsame-ISA VM。

分类

XUNIJISHIXIANFENWEIJIYUJICUNQIDEXUNIJIHEJIYUZHANDEXUNIJI。

三地址指令

a = b + c;

RUGUOBATABIANCHENGZHEIZHONGXINGSHI:

荣耀彩票代理add a, b, c

荣耀彩票代理NEIKANQILAIJIUGENGXIANGJIQIZHILINGLE,DUIBA?ZHEIZHONGJIUSHISUOWEI'SANDIZHIZHILING'(3-address instruction),YIBANXINGSHIWEI:

op dest, src1, src2

XUDUOCAOZUODOUSHIERYUANYUNSUAN+FUZHI。SANDIZHIZHILINGZHENGHAOKEYIZHIDINGLIANGGEYUANHEYIGEMUBIAO,NENGFEICHANGLINGHUODEZHICHIERYUANCAOZUOYUFUZHIDEZUHE。ARMCHULIQIDEZHUYAOZHILINGJIJIUSHISANDIZHIXINGSHIDE。

二地址指令

a += b;

BIANCHENG:

add a, b

ZHEIJIUSHISUOWEI'ERDIZHIZHILING',YIBANXINGSHIWEI:

op dest, src

TAYAOZHICHIERYUANCAOZUO,JIUZHINENGBAQIZHONGYIGEYUANTONGSHIYEZUOWEIMUBIAO。SHANGMIANDEadd a, bZAIZHIXINGGUOHOU,JIUHUIPOHUAIaYUANYOUDEZHI,ERbDEZHIBAOCHIBUBIAN。x86XILIEDECHULIQIJIUSHIERDIZHIXINGSHIDE。

一地址指令

XIANRAN,ZHILINGJIKEYISHIRENYI'nDIZHI'DE,nSHUYUZIRANSHU。NEIMEYIDIZHIXINGSHIDEZHILINGJISHIZENYANGDENI?

XIANGXIANGYIXIAZHEIYANGYIZUZHILINGXULIE:

add 5

sub 3

ZHEIZHIZHIDINGLECAOZUODEYUAN,NEIMUBIAOSHISHENME?YIBANLAISHUO,ZHEIZHONGYUNSUANDEMUBIAOSHIBEICHENGWEI'LEIJIAQI'(accumulator)DEZHUANYONGJICUNQI,SUOYOUYUNSUANDOUKAOGENGXINLEIJIAQIDEZHUANGTAILAIWANCHENG。NEIMESHANGMIANLIANGTIAOZHILINGYONGCLAIXIEJIULEISI:

CDAIMA SHOUZANGDAIMA

acc += 5;

acc -= 3;

ZHIBUGUOaccSHI'YINZANG'DEMUBIAO。JIYULEIJIAQIDEJIAGOUJINLAIBIJIAOSHAOJIANLE,ZAIHENLAODEJIQISHANGFANRONGGUOYIDUANSHIJIAN。

零地址指令

荣耀彩票代理NEI'nDIZHI'DEnRUGUOSHI0DEHUANI?

KANZHEIYANGYIDUANJavaZIJIEMA:

Java bytecodeDAIMA SHOUZANGDAIMA

iconst_1

iconst_2

iadd

istore_0

ZHUYINEIGEiadd(BIAOSHIZHENGXINGJIAFA)ZHILINGBINGMEIYOURENHECANSHU。LIANYUANDOUWUFAZHIDINGLE,LINGDIZHIZHILINGYOUSHENMEYONG??

LINGDIZHIYIWEIZHEYUANYUMUBIAODOUSHIYINHANCANSHU,QISHIXIANYILAIYUYIZHONGCHANGJIANDESHUJUJIEGOU——MEICUO,JIUSHIZHAN。SHANGMIANDEiconst_1、iconst_2LIANGTIAOZHILING,FENBIEXIANGYIGEJIAOZUO'QIUZHIZHAN'(evaluation stack,YEJIAOZUOoperand stack'CAOZUOSHUZHAN'HUOZHEexpression stack'BIAODASHIZHAN')DEDIFANGYARUZHENGXINGCHANGLIANG1、2。iaddZHILINGZECONGQIUZHIZHANDINGDANCHU2GEZHI,JIANGZHIXIANGJIA,RANHOUBAJIEGUOYAHUIDAOZHANDING。istore_0ZHILINGCONGQIUZHIZHANDINGDANCHUYIGEZHI,BINGJIANGZHIBAOCUNDAOJUBUBIANLIANGQUDEDIYIGEWEIZHI(slot 0)。

荣耀彩票代理LINGDIZHIXINGSHIDEZHILINGJIYIBANJIUSHITONGGUO'JIYUZHANDEJIAGOU'LAISHIXIANDE。QINGYIDINGYAOZHUYI,ZHEIGEZHANSHIZHI'QIUZHIZHAN',ERBUSHIYUXITONGDIAOYONGZHAN(system call stack,HUOZHEJIUJIAOsystem stack)。QIANWANBIENONGHUNLE。YOUXIEXUNIJIBAQIUZHIZHANSHIXIANZAIXITONGDIAOYONGZHANSHANG,DANLIANGZHEGAINIANSHANGBUSHIYIGEDONGXI。

YOUYUZHILINGDEYUANYUMUBIAODOUSHIYINHANDE,LINGDIZHIZHILINGDE'MIDU'KEYIFEICHANGGAO——KEYIYONGGENGSHAOKONGJIANFANGXIAGENGDUOTIAOZHILING。YINCIZAIKONGJIANJINQUEDEHUANJINGZHONG,LINGDIZHIZHILINGSHIZHONGKEQUDESHEJI。DANLINGDIZHIZHILINGYAOWANCHENGYIJIANSHIQING,YIBANHUIBIERDIZHIHUOZHESANDIZHIZHILINGXUDUOGENGDUOTIAOZHILING。SHANGMIANJavaZIJIEMAZUODEJIAFA,RUGUOYONGx86ZHILINGLIANGTIAOJIUNENGWANCHENGLE:

mov eax, 1

add eax, 2

基于栈与基于寄存器结构的区别

保存临时值的位置不同
  • 基于栈:将临时值保存在求值栈上。 基于寄存器:将临时值保存在寄存器中。 代码所占体积不同
    • 基于栈:代码紧凑,体积小,但所需要的代码条件多 基于寄存器:代码相对大些,但所需要的代码条件少

      荣耀彩票代理JIYUZHANZHONGDE'ZHAN'ZHIDESHI'QIUZHIZHAN',JVMZHONG'QIUZHIZHAN'BEICHENGWEI'CAOZUOSHUZHAN'。

      栈帧

      荣耀彩票代理ZHANZHENYEJIAOGUOCHENGHUODONGJILU,SHIBIANYIQIYONGLAISHIXIANGUOCHENG/HANSHUDIAOYONGDEYIZHONGSHUJUJIEGOU。CONGLUOJISHANGJIANG,ZHANZHENJIUSHIYIGEHANSHUZHIXINGDEHUANJING:HANSHUCANSHU、HANSHUDEJUBUBIANLIANG、HANSHUZHIXINGWANHOUFANHUIDAONALIDENGDENG。

      蓝图虚拟机的实现

      QIANMIANWOMENYIJINGJIANDANDEJIESHAOLEXUNIJIDEXIANGGUANSHUYU,JIEXIALAIWOMENLAIJUTIJIANGJIEXIAXUHUAN4ZHONGLANTUXUNIJIDESHIXIAN。

      字节码

      荣耀彩票代理XUNIJIDEZIJIEMAZAIScript.hWENJIANZHONG,ZHEILIWOMENBATAQUANBULIECHULAI,YINWEISHIZHUANYONGDEJIAOBENYUYAN,SUOYITALIMIANHUIYOUYIXIETESHUDEZIJIEMA,RUDAILIXIANGGUANDEDAIMA(EX_BindDelegate、EX_AddMulticastDelegate),DANGRANCHANGYONGDEYUJUYESHIYOUDE,BIRUFUZHI、WUTIAOJIANTIAOZHUANZHILING、TIAOJIANTIAOZHUANZHILING、switchDENG。

        1 //
        2 
        3 // Evaluatable expression item types.
        4 
        5 //
        6 
        7 enum EExprToken
        8 
        9 {
       10 
       11     // Variable references.
       12 
       13     EX_LocalVariable        = 0x00,    // A local variable.
       14 
       15     EX_InstanceVariable        = 0x01,    // An object variable.
       16 
       17     EX_DefaultVariable        = 0x02, // Default variable for a class context.
       18 
       19     //                        = 0x03,
       20 
       21     EX_Return                = 0x04,    // Return from function.
       22 
       23     //                        = 0x05,
       24 
       25     EX_Jump                    = 0x06,    // Goto a local address in code.
       26 
       27     EX_JumpIfNot            = 0x07,    // Goto if not expression.
       28 
       29     //                        = 0x08,
       30 
       31     EX_Assert                = 0x09,    // Assertion.
       32 
       33     //                        = 0x0A,
       34 
       35     EX_Nothing                = 0x0B,    // No operation.
       36 
       37     //                        = 0x0C,
       38 
       39     //                        = 0x0D,
       40 
       41     //                        = 0x0E,
       42 
       43     EX_Let                    = 0x0F,    // Assign an arbitrary size value to a variable.
       44 
       45     //                        = 0x10,
       46 
       47     //                        = 0x11,
       48 
       49     EX_ClassContext            = 0x12,    // Class default object context.
       50 
       51     EX_MetaCast = 0x13, // Metaclass cast.
       52 
       53     EX_LetBool                = 0x14, // Let boolean variable.
       54 
       55     EX_EndParmValue            = 0x15,    // end of default value for optional function parameter
       56 
       57     EX_EndFunctionParms        = 0x16,    // End of function call parameters.
       58 
       59     EX_Self                    = 0x17,    // Self object.
       60 
       61     EX_Skip                    = 0x18,    // Skippable expression.
       62 
       63     EX_Context                = 0x19,    // Call a function through an object context.
       64 
       65     EX_Context_FailSilent    = 0x1A, // Call a function through an object context (can fail silently if the context is NULL; only generated for functions that don't have output or return values).
       66 
       67     EX_VirtualFunction        = 0x1B,    // A function call with parameters.
       68 
       69     EX_FinalFunction        = 0x1C,    // A prebound function call with parameters.
       70 
       71     EX_IntConst                = 0x1D,    // Int constant.
       72 
       73     EX_FloatConst            = 0x1E,    // Floating point constant.
       74 
       75     EX_StringConst            = 0x1F,    // String constant.
       76 
       77     EX_ObjectConst         = 0x20,    // An object constant.
       78 
       79     EX_NameConst            = 0x21,    // A name constant.
       80 
       81     EX_RotationConst        = 0x22,    // A rotation constant.
       82 
       83     EX_VectorConst            = 0x23,    // A vector constant.
       84 
       85     EX_ByteConst            = 0x24,    // A byte constant.
       86 
       87     EX_IntZero                = 0x25,    // Zero.
       88 
       89     EX_IntOne                = 0x26,    // One.
       90 
       91     EX_True                    = 0x27,    // Bool True.
       92 
       93     EX_False                = 0x28,    // Bool False.
       94 
       95     EX_TextConst            = 0x29, // FText constant
       96 
       97     EX_NoObject                = 0x2A,    // NoObject.
       98 
       99     EX_TransformConst        = 0x2B, // A transform constant
      100 
      101     EX_IntConstByte            = 0x2C,    // Int constant that requires 1 byte.
      102 
      103     EX_NoInterface            = 0x2D, // A null interface (similar to EX_NoObject, but for interfaces)
      104 
      105     EX_DynamicCast            = 0x2E,    // Safe dynamic class casting.
      106 
      107     EX_StructConst            = 0x2F, // An arbitrary UStruct constant
      108 
      109     EX_EndStructConst        = 0x30, // End of UStruct constant
      110 
      111     EX_SetArray                = 0x31, // Set the value of arbitrary array
      112 
      113     EX_EndArray                = 0x32,
      114 
      115     //                        = 0x33,
      116 
      117     EX_UnicodeStringConst = 0x34, // Unicode string constant.
      118 
      119     EX_Int64Const            = 0x35,    // 64-bit integer constant.
      120 
      121     EX_UInt64Const            = 0x36,    // 64-bit unsigned integer constant.
      122 
      123     //                        = 0x37,
      124 
      125     EX_PrimitiveCast        = 0x38,    // A casting operator for primitives which reads the type as the subsequent byte
      126 
      127     //                        = 0x39,
      128 
      129     //                        = 0x3A,
      130 
      131     //                        = 0x3B,
      132 
      133     //                        = 0x3C,
      134 
      135     //                        = 0x3D,
      136 
      137     //                        = 0x3E,
      138 
      139     //                        = 0x3F,
      140 
      141     //                        = 0x40,
      142 
      143     //                        = 0x41,
      144 
      145     EX_StructMemberContext    = 0x42, // Context expression to address a property within a struct
      146 
      147     EX_LetMulticastDelegate    = 0x43, // Assignment to a multi-cast delegate
      148 
      149     EX_LetDelegate            = 0x44, // Assignment to a delegate
      150 
      151     //                        = 0x45,
      152 
      153     //                        = 0x46, // CST_ObjectToInterface
      154 
      155     //                        = 0x47, // CST_ObjectToBool
      156 
      157     EX_LocalOutVariable        = 0x48, // local out (pass by reference) function parameter
      158 
      159     //                        = 0x49, // CST_InterfaceToBool
      160 
      161     EX_DeprecatedOp4A        = 0x4A,
      162 
      163     EX_InstanceDelegate        = 0x4B,    // const reference to a delegate or normal function object
      164 
      165     EX_PushExecutionFlow    = 0x4C, // push an address on to the execution flow stack for future execution when a EX_PopExecutionFlow is executed. Execution continues on normally and doesn't change to the pushed address.
      166 
      167     EX_PopExecutionFlow        = 0x4D, // continue execution at the last address previously pushed onto the execution flow stack.
      168 
      169     EX_ComputedJump            = 0x4E,    // Goto a local address in code, specified by an integer value.
      170 
      171     EX_PopExecutionFlowIfNot = 0x4F, // continue execution at the last address previously pushed onto the execution flow stack, if the condition is not true.
      172 
      173     EX_Breakpoint            = 0x50, // Breakpoint. Only observed in the editor, otherwise it behaves like EX_Nothing.
      174 
      175     EX_InterfaceContext        = 0x51,    // Call a function through a native interface variable
      176 
      177     EX_ObjToInterfaceCast = 0x52,    // Converting an object reference to native interface variable
      178 
      179     EX_EndOfScript            = 0x53, // Last byte in script code
      180 
      181     EX_CrossInterfaceCast    = 0x54, // Converting an interface variable reference to native interface variable
      182 
      183     EX_InterfaceToObjCast = 0x55, // Converting an interface variable reference to an object
      184 
      185     //                        = 0x56,
      186 
      187     //                        = 0x57,
      188 
      189     //                        = 0x58,
      190 
      191     //                        = 0x59,
      192 
      193     EX_WireTracepoint        = 0x5A, // Trace point. Only observed in the editor, otherwise it behaves like EX_Nothing.
      194 
      195     EX_SkipOffsetConst        = 0x5B, // A CodeSizeSkipOffset constant
      196 
      197     EX_AddMulticastDelegate = 0x5C, // Adds a delegate to a multicast delegate's targets
      198 
      199     EX_ClearMulticastDelegate = 0x5D, // Clears all delegates in a multicast target
      200 
      201     EX_Tracepoint            = 0x5E, // Trace point. Only observed in the editor, otherwise it behaves like EX_Nothing.
      202 
      203     EX_LetObj                = 0x5F,    // assign to any object ref pointer
      204 
      205     EX_LetWeakObjPtr        = 0x60, // assign to a weak object pointer
      206 
      207     EX_BindDelegate            = 0x61, // bind object and name to delegate
      208 
      209     EX_RemoveMulticastDelegate = 0x62, // Remove a delegate from a multicast delegate's targets
      210 
      211     EX_CallMulticastDelegate = 0x63, // Call multicast delegate
      212 
      213     EX_LetValueOnPersistentFrame = 0x64,
      214 
      215     EX_ArrayConst            = 0x65,
      216 
      217     EX_EndArrayConst        = 0x66,
      218 
      219     EX_AssetConst            = 0x67,
      220 
      221     EX_CallMath                = 0x68, // static pure function from on local call space
      222 
      223     EX_SwitchValue            = 0x69,
      224 
      225     EX_InstrumentationEvent    = 0x6A, // Instrumentation event
      226 
      227     EX_ArrayGetByRef        = 0x6B,
      228 
      229     EX_Max                    = 0x100,
      230 
      231 };

      栈帧

      ZAIStack.hZHONGWOMENKEYIZHAODAOFFrameDEDINGYI,SUIRANTADINGYIDESHIYIGEJIEGOUTI,DANSHIZHIXINGDANGQIANDAIMADELUOJISHIFENGZHUANGZAIZHEILIMIANDE。XIAMIANRANGWOMENKANYIXIATADESHUJUCHENGYUAN:

       1   // Variables.
       2 
       3     UFunction* Node;
       4 
       5     UObject* Object;
       6 
       7     uint8* Code;
       8 
       9     uint8* Locals;
      10 
      11  
      12 
      13     UProperty* MostRecentProperty;
      14 
      15     uint8* MostRecentPropertyAddress;
      16 
      17  
      18 
      19     /** The execution flow stack for compiled Kismet code */
      20 
      21     FlowStackType FlowStack;
      22 
      23  
      24 
      25     /** Previous frame on the stack */
      26 
      27     FFrame* PreviousFrame;
      28 
      29  
      30 
      31     /** contains information on any out parameters */
      32 
      33     FOutParmRec* OutParms;
      34 
      35  
      36 
      37     /** If a class is compiled in then this is set to the property chain for compiled-in functions. In that case, we follow the links to setup the args instead of executing by code. */
      38 
      39     UField* PropertyChainForCompiledIn;
      40 
      41  
      42 
      43     /** Currently executed native function */
      44 
      45     UFunction* CurrentNativeFunction;
      46 
      47  
      48 
      49     bool bArrayContextFailed;

      WOMENKEYIKANDAO,TALIMIANBAOCUNLEDANGQIANZHIXINGDEJIAOBENHANSHU,ZHIXINGGAIJIAOBENDEUObject,DANGQIANDAIMADEZHIXINGWEIZHI,JUBUBIANLIANG,SHANGYIGEZHANZHEN,DIAOYONGFANHUIDECANSHU(BUSHIFANHUIZHI),DANGQIANZHIXINGDEYUANSHENGHANSHUDENG。ERDIAOYONGHANSHUDEFANHUIZHISHIFANGZAILEHANSHUDIAOYONGZHIQIANBAOCUN,DIAOYONGJIESHUHOUZAIHUIFU。DAZHIRUXIASUOSHI:

      1 uint8 * SaveCode = Stack.Code;
      2 
      3 // Call function
      4 
      5 ….
      6 
      7 Stack.Code = SaveCode

      XIAMIANWOMENLIECHUFFrameZHONGGENZHIXINGXIANGGUANDEZHONGYAOHANSHU:

        1     // Functions.
        2 
        3     COREUOBJECT_API void Step( UObject* Context, RESULT_DECL );
        4 
        5  
        6 
        7     /** Replacement for Step that uses an explicitly specified property to unpack arguments **/
        8 
        9     COREUOBJECT_API void StepExplicitProperty(void*const Result, UProperty* Property);
       10 
       11  
       12 
       13     /** Replacement for Step that checks the for byte code, and if none exists, then PropertyChainForCompiledIn is used. Also, makes an effort to verify that the params are in the correct order and the types are compatible. **/
       14 
       15     template<class TProperty>
       16 
       17     FORCEINLINE_DEBUGGABLE void StepCompiledIn(void*const Result);
       18 
       19  
       20 
       21     /** Replacement for Step that checks the for byte code, and if none exists, then PropertyChainForCompiledIn is used. Also, makes an effort to verify that the params are in the correct order and the types are compatible. **/
       22 
       23     template<class TProperty, typename TNativeType>
       24 
       25     FORCEINLINE_DEBUGGABLE TNativeType& StepCompiledInRef(void*const TemporaryBuffer);
       26 
       27  
       28 
       29     COREUOBJECT_API virtual void Serialize( const TCHAR* V, ELogVerbosity::Type Verbosity, const class FName& Category ) override;
       30 
       31     
       32 
       33     COREUOBJECT_API static void KismetExecutionMessage(const TCHAR* Message, ELogVerbosity::Type Verbosity, FName WarningId = FName());
       34 
       35  
       36 
       37     /** Returns the current script op code */
       38 
       39     const uint8 PeekCode() const { return *Code; }
       40 
       41  
       42 
       43     /** Skips over the number of op codes specified by NumOps */
       44 
       45     void SkipCode(const int32 NumOps) { Code += NumOps; }
       46 
       47  
       48 
       49     template<typename TNumericType>
       50 
       51     TNumericType ReadInt();
       52 
       53     float ReadFloat();
       54 
       55     FName ReadName();
       56 
       57     UObject* ReadObject();
       58 
       59     int32 ReadWord();
       60 
       61     UProperty* ReadProperty();
       62 
       63  
       64 
       65     /** May return null */
       66 
       67     UProperty* ReadPropertyUnchecked();
       68 
       69  
       70 
       71     /**
       72 
       73      * Reads a value from the bytestream, which represents the number of bytes to advance
       74 
       75      * the code pointer for certain expressions.
       76 
       77      *
       78 
       79      * @param    ExpressionField        receives a pointer to the field representing the expression; used by various execs
       80 
       81      *                                to drive VM logic
       82 
       83      */
       84 
       85     CodeSkipSizeType ReadCodeSkipCount();
       86 
       87  
       88 
       89     /**
       90 
       91      * Reads a value from the bytestream which represents the number of bytes that should be zero'd out if a NULL context
       92 
       93      * is encountered
       94 
       95      *
       96 
       97      * @param    ExpressionField        receives a pointer to the field representing the expression; used by various execs
       98 
       99      *                                to drive VM logic
      100 
      101      */
      102 
      103     VariableSizeType ReadVariableSize(UProperty** ExpressionField);

      荣耀彩票代理XIANGReadInt()、ReadFloat()、ReadObject()DENGZHEIXIEHANSHU,WOMENKANDAOTADEMINGZIJIUZHIDAOTASHIZUOSHENMEDE,JIUSHICONGDAIMAZHONGDUQUXIANGYINGDEint、float、UObjectDENG。ZHEILIWOMENZHUYAOSHUOXIAStep()HANSHU,TADEDAIMARUXIASUOSHI:

      1 void FFrame::Step(UObject *Context, RESULT_DECL)
      2 
      3 {
      4 
      5     int32 B = *Code++;
      6 
      7     (Context->*GNatives[B])(*this,RESULT_PARAM);
      8 
      9 }

      KEYIKANDAO,TADEZHUYAOZUOYONGJIUSHIQUCHUZHILING,RANHOUZAIYUANSHENGHANSHUSHUZUZHONGZHAODAODUIYINGDEHANSHUQUZHIXING。

      字节码对应函数

      QIANMIANWOMENLIECHULESUOYOUDEXUNIJIDESUOYOUZIJIEMA,NEIMEDUIYINGMEIGEZIJIEMAJUTIZHIXINGBUFENDEDAIMAZAINALINI,JUTIKEYIDAOScriptCore.cppZHONGCHAZHAODINGYI,WOMENKEYIKANDAOMEIGEZIJIEMADUIYINGDEYUANSHENGHANSHUDOUZAIGNativesHEGCastsLIMIAN:

      TAMENDESHENGMINGRUXIA:

      1 /** The type of a native function callable by script */
      2 
      3 typedef void (UObject::*Native)( FFrame& TheStack, RESULT_DECL );
      4 
      5 Native GCasts[];
      6 
      7 Native GNatives[EX_Max];

      荣耀彩票代理ZHEIYANGTADOUHUIDUIMEIYIGEYUANSHENGHANSHUDIAOYONGYIXIAZHUCEFANGFA,TONGGUOIMPLEMENT_VM_FUNCTIONHEIMPLEMENT_CAST_FUNCTIONHONGSHIXIAN。

      JUTIDAIMARUXIATUSUOSHI:

       1 #define IMPLEMENT_FUNCTION(cls,func) 
       2 
       3     static FNativeFunctionRegistrar cls##func##Registar(cls::StaticClass(),#func,(Native)&cls::func);
       4 
       5  
       6 
       7 #define IMPLEMENT_CAST_FUNCTION(cls, CastIndex, func) 
       8 
       9     IMPLEMENT_FUNCTION(cls, func); 
      10 
      11     static uint8 cls##func##CastTemp = GRegisterCast( CastIndex, (Native)&cls::func );
      12 
      13  
      14 
      15 #define IMPLEMENT_VM_FUNCTION(BytecodeIndex, func) 
      16 
      17     IMPLEMENT_FUNCTION(UObject, func) 
      18 
      19     static uint8 UObject##func##BytecodeTemp = GRegisterNative( BytecodeIndex, (Native)&UObject::func );

      KEYIKANDAO,TASHIDINGYILEYIGEQUANJUJINGTAIDUIXIANG,ZHEIYANGJIUHUIZAICHENGXUDEmainHANSHUZHIXINGQIANJIUYIJINGBAHANSHUFANGZAISHUZUZHONGDUIYINGDEWEIZHILE,ZHEIYANGZAIXUNIJIZHIXINGSHIJIUKEYIZHIJIEDIAOYONGDAODUIYINGDEYUANSHENGHANSHULE。

      执行流程

      荣耀彩票代理WOMENQIANMIANJIANGLANTUDESHIHOUJIANGGUOLANTURUHEGENC++JIAOHU,BAOKUOLANTUDIAOYONGC++DAIMA,YIJICONGC++DAIMADIAOYONGDAOLANTULIMIANQU。

      C++调用蓝图函数

       1 UFUNCTION(BlueprintImplementableEvent, Category = 'AReflectionStudyGameMode')
       2 
       3 void ImplementableFuncTest();
       4 
       5  
       6 
       7 void AReflectionStudyGameMode::ImplementableFuncTest()
       8 
       9 {
      10 
      11 ProcessEvent(FindFunctionChecked(REFLECTIONSTUDY_ImplementableFuncTest),NULL);
      12 
      13 }

      YINWEIWOMENZHEIGEHANSHUMEIYOUCANSHU,SUOYOUProcessEventZHONGCHUANLEYIGENULL,RUGUOSHIYOUCANSHUHEFANHUIZHIDENG,NEIMEUHTHUIZIDONGSHENGCHENGYIGEJIEGOUTIYONGYUCUNCHUCANSHUHEFANHUIZHIDENG,ZHEIYANGDANGZAIC++LIMIANDIAOYONGHANSHUSHI,JIUHUIQUZHAOREFLECTIONSTUDY_ImplementableFuncTestZHEIGEMINGZIDUIYINGDELANTUUFunction,RUGUOZHAODAONEIMEJIUHUIDIAOYONGProcessEventLAIZUOJINYIBUDECHULI。

      ProcessEvent流程

      蓝图调用C++函数

       1 UFUNCTION(BlueprintCallable, Category = 'AReflectionStudyGameMode')
       2 
       3 void CallableFuncTest();
       4 
       5  
       6 
       7 DECLARE_FUNCTION(execCallableFuncTest) 
       8 
       9 { 
      10 
      11 P_FINISH; 
      12 
      13 P_NATIVE_BEGIN; 
      14 
      15 this->CallableFuncTest(); 
      16 
      17 P_NATIVE_END; 
      18 
      19 }

      荣耀彩票代理RUGUOSHITONGGUOLANTUDIAOYONGDEC++HANSHU,NEIMEUHTHUISHENGCHENGRUSHANGDEDAIMA,BINGQIERUGUOYOUCANSHUDEHUA,HUIDIAOYONGP_GET_UBOOLDENGLAIHUOQUDUIYINGDECANSHU,RUGUOYOUFANHUIZHIDEHUAYEHUIJIANGFANHUIZHIFUZHI。

      总结

      至此,加上前面我们对蓝图编译的剖析,加上蓝图虚拟机的讲解,我们已经对蓝图的实现原理有一个比较深入的了解,本文并没有对蓝图的前身unrealscript进行详细的讲解。有了这个比较深入的认识后(如果想要有深刻的认识,必须自己去看代码),相信大家在设计蓝图时会更游刃有余。当然如果有错误的地方也请大家指正,欢迎大家踊跃讨论。接下来可能会把重心放到虚幻4渲染相关的模块上,包括渲染API跨平台相关,多线程渲染,渲染流程,以及渲染算法上面,可能中间也会穿插一些其他的模块(比如动画、AI等),欢迎大家持续关注,如果你有想提前了解的章节,也欢迎在下面留言,我可能会根据大家的留言来做优先级调整。

      参考文章

      http://www.usenix.org/legacy/events/vee05/full_papers/p153-yunhe.pdf http://rednaxelafx.iteye.com/blog/492667 http://www.zhihu.com/question/19608553 http://zh.wikipedia.org/wiki/%E8%99%9B%E6%93%AC%E6%A9%9F%E5%99%A8 Java Program in Action 莫枢

延伸阅读:

Tag标签:      
  • 专题推荐

About IT165 - 广告服务 - 隐私声明 - 版权申明 - 免责条款 - 网站地图 - 网友投稿 - 联系方式
本站内容来自于互联网,仅供用于网络技术学习,学习中请遵循相关法律法规